locize 3.3.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +74 -36
- package/dist/cjs/{processLegacy.js → _processLegacy.js} +1 -2
- package/dist/cjs/{startStandalone.js → _startStandalone.js} +2 -2
- package/dist/cjs/api/handleCommitKeys.js +7 -0
- package/dist/cjs/api/handleEditKey.js +1 -1
- package/dist/cjs/api/handleIsLocizeEnabled.js +2 -2
- package/dist/cjs/api/handleRequestPopupChanges.js +11 -0
- package/dist/cjs/api/handleSendMatchedUninstrumented.js +26 -0
- package/dist/cjs/api/postMessage.js +32 -45
- package/dist/cjs/implementations/dummyImplementation.js +35 -0
- package/dist/cjs/implementations/i18nextImplementation.js +94 -0
- package/dist/cjs/index.d.ts +9 -16
- package/dist/cjs/index.js +4 -9
- package/dist/cjs/locizePlugin.js +6 -90
- package/dist/cjs/observer.js +1 -0
- package/dist/cjs/parser.js +100 -14
- package/dist/cjs/process.js +37 -5
- package/dist/cjs/store.js +1 -0
- package/dist/cjs/ui/elements/highlightBox.js +13 -0
- package/dist/cjs/ui/elements/icons.js +1 -17
- package/dist/cjs/ui/elements/popup.js +3 -3
- package/dist/cjs/ui/elements/ribbonBox.js +3 -6
- package/dist/cjs/ui/highlightNode.js +28 -77
- package/dist/cjs/ui/popup.js +10 -0
- package/dist/cjs/ui/utils.js +18 -0
- package/dist/cjs/uninstrumentedStore.js +18 -2
- package/dist/cjs/utils.js +54 -0
- package/dist/cjs/vars.js +5 -2
- package/dist/esm/{processLegacy.js → _processLegacy.js} +1 -2
- package/dist/esm/{startStandalone.js → _startStandalone.js} +1 -1
- package/dist/esm/api/handleCommitKeys.js +7 -0
- package/dist/esm/api/handleEditKey.js +1 -1
- package/dist/esm/api/handleIsLocizeEnabled.js +2 -2
- package/dist/esm/api/handleRequestPopupChanges.js +11 -0
- package/dist/esm/api/handleSendMatchedUninstrumented.js +20 -0
- package/dist/esm/api/postMessage.js +33 -44
- package/dist/esm/implementations/dummyImplementation.js +31 -0
- package/dist/esm/implementations/i18nextImplementation.js +85 -0
- package/dist/esm/index.d.ts +9 -16
- package/dist/esm/index.js +5 -8
- package/dist/esm/locizePlugin.js +5 -85
- package/dist/esm/observer.js +1 -0
- package/dist/esm/parser.js +101 -16
- package/dist/esm/process.js +38 -6
- package/dist/esm/store.js +1 -0
- package/dist/esm/ui/elements/highlightBox.js +9 -0
- package/dist/esm/ui/elements/icons.js +2 -16
- package/dist/esm/ui/elements/popup.js +3 -3
- package/dist/esm/ui/elements/ribbonBox.js +4 -7
- package/dist/esm/ui/highlightNode.js +28 -78
- package/dist/esm/ui/popup.js +10 -0
- package/dist/esm/ui/utils.js +18 -1
- package/dist/esm/uninstrumentedStore.js +18 -2
- package/dist/esm/utils.js +53 -1
- package/dist/esm/vars.js +5 -3
- package/dist/umd/locize.js +726 -496
- package/dist/umd/locize.min.js +1 -1
- package/index.d.ts +9 -16
- package/locize.js +726 -496
- package/locize.min.js +1 -1
- package/package.json +1 -1
- package/src/_startStandalone.js +22 -0
- package/src/api/handleCommitKeys.js +9 -0
- package/src/api/handleEditKey.js +5 -11
- package/src/api/handleIsLocizeEnabled.js +7 -2
- package/src/api/handleRequestPopupChanges.js +27 -0
- package/src/api/handleSendMatchedUninstrumented.js +38 -0
- package/src/api/index.js +1 -4
- package/src/api/postMessage.js +37 -53
- package/src/implementations/dummyImplementation.js +29 -0
- package/src/implementations/i18nextImplementation.js +114 -0
- package/src/implementations/index.js +2 -0
- package/src/index.js +8 -7
- package/src/locizePlugin.js +51 -28
- package/src/observer.js +1 -0
- package/src/parser.js +207 -19
- package/src/process.js +52 -5
- package/src/startStandalone.js +4 -17
- package/src/store.js +2 -0
- package/src/ui/elements/highlightBox.js +17 -0
- package/src/ui/elements/popup.js +4 -4
- package/src/ui/elements/ribbonBox.js +12 -8
- package/src/ui/highlightNode.js +102 -71
- package/src/ui/popup.js +33 -5
- package/src/ui/utils.js +28 -1
- package/src/uninstrumentedStore.js +18 -2
- package/src/utils.js +72 -5
- package/src/vars.js +6 -4
- package/dist/cjs/api/handleTurnOff.js +0 -8
- package/dist/cjs/api/handleTurnOn.js +0 -8
- package/dist/esm/api/handleTurnOff.js +0 -6
- package/dist/esm/api/handleTurnOn.js +0 -6
- /package/src/{processLegacy.js → _processLegacy.js} +0 -0
- /package/src/api/{handleTurnOff.js → _handleTurnOff.js} +0 -0
- /package/src/api/{handleTurnOn.js → _handleTurnOn.js} +0 -0
package/locize.js
CHANGED
|
@@ -45,6 +45,37 @@
|
|
|
45
45
|
return obj;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
function _arrayLikeToArray(arr, len) {
|
|
49
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
50
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
51
|
+
return arr2;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function _arrayWithoutHoles(arr) {
|
|
55
|
+
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function _iterableToArray(iter) {
|
|
59
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
63
|
+
if (!o) return;
|
|
64
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
65
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
66
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
67
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
68
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function _nonIterableSpread() {
|
|
72
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function _toConsumableArray(arr) {
|
|
76
|
+
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
77
|
+
}
|
|
78
|
+
|
|
48
79
|
var INVISIBLE_CHARACTERS = ["\u200B", "\u200C"];
|
|
49
80
|
var INVISIBLE_REGEX = RegExp("([".concat(INVISIBLE_CHARACTERS.join(''), "]{9})+"), 'gu');
|
|
50
81
|
var TEMPLATE_MINIMUM_LENGTH = '{"k":"a"}'.length;
|
|
@@ -198,9 +229,11 @@
|
|
|
198
229
|
};
|
|
199
230
|
|
|
200
231
|
var validAttributes = ['placeholder', 'title', 'alt'];
|
|
232
|
+
var ignoreElements = ['SCRIPT'];
|
|
201
233
|
var colors = {
|
|
202
|
-
highlight: '#
|
|
203
|
-
warning: '#e67a00'
|
|
234
|
+
highlight: '#1976d2',
|
|
235
|
+
warning: '#e67a00',
|
|
236
|
+
gray: '#ccc'
|
|
204
237
|
};
|
|
205
238
|
var getIframeUrl = function getIframeUrl() {
|
|
206
239
|
var _prc$env;
|
|
@@ -221,6 +254,274 @@
|
|
|
221
254
|
|
|
222
255
|
function ownKeys$7(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
223
256
|
function _objectSpread$7(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$7(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$7(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
257
|
+
var data$1 = {};
|
|
258
|
+
function clean$1() {
|
|
259
|
+
Object.values(data$1).forEach(function (item) {
|
|
260
|
+
if (!document.body.contains(item.node)) {
|
|
261
|
+
resetHighlight(item.id, item.node);
|
|
262
|
+
delete data$1[item.id];
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
function save$1(id, type, node, txt) {
|
|
267
|
+
if (!id || !type || !node) return;
|
|
268
|
+
if (!data$1[id]) {
|
|
269
|
+
data$1[id] = {
|
|
270
|
+
id: id,
|
|
271
|
+
node: node
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
data$1[id].keys = _objectSpread$7(_objectSpread$7({}, data$1[id].keys), {}, _defineProperty({}, "".concat(type), {
|
|
275
|
+
value: txt,
|
|
276
|
+
eleUniqueID: id,
|
|
277
|
+
textType: type
|
|
278
|
+
}));
|
|
279
|
+
}
|
|
280
|
+
function remove(id, node) {
|
|
281
|
+
resetHighlight(id, node);
|
|
282
|
+
delete data$1[id];
|
|
283
|
+
}
|
|
284
|
+
function removeKey(id, key, node) {
|
|
285
|
+
var item = get$1(id);
|
|
286
|
+
if (!item) return;
|
|
287
|
+
delete item.keys["".concat(key)];
|
|
288
|
+
if (!Object.keys(item.keys).length) remove(id, node);
|
|
289
|
+
}
|
|
290
|
+
function get$1(id) {
|
|
291
|
+
return data$1[id];
|
|
292
|
+
}
|
|
293
|
+
var uninstrumentedStore = {
|
|
294
|
+
save: save$1,
|
|
295
|
+
remove: remove,
|
|
296
|
+
removeKey: removeKey,
|
|
297
|
+
clean: clean$1,
|
|
298
|
+
get: get$1,
|
|
299
|
+
data: data$1
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
function _arrayWithHoles(arr) {
|
|
303
|
+
if (Array.isArray(arr)) return arr;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function _iterableToArrayLimit(r, l) {
|
|
307
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
308
|
+
if (null != t) {
|
|
309
|
+
var e,
|
|
310
|
+
n,
|
|
311
|
+
i,
|
|
312
|
+
u,
|
|
313
|
+
a = [],
|
|
314
|
+
f = !0,
|
|
315
|
+
o = !1;
|
|
316
|
+
try {
|
|
317
|
+
if (i = (t = t.call(r)).next, 0 === l) {
|
|
318
|
+
if (Object(t) !== t) return;
|
|
319
|
+
f = !1;
|
|
320
|
+
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
321
|
+
} catch (r) {
|
|
322
|
+
o = !0, n = r;
|
|
323
|
+
} finally {
|
|
324
|
+
try {
|
|
325
|
+
if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return;
|
|
326
|
+
} finally {
|
|
327
|
+
if (o) throw n;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return a;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function _nonIterableRest() {
|
|
335
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function _slicedToArray(arr, i) {
|
|
339
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function debounce(func, wait, immediate) {
|
|
343
|
+
var timeout;
|
|
344
|
+
return function () {
|
|
345
|
+
var context = this;
|
|
346
|
+
var args = arguments;
|
|
347
|
+
var later = function later() {
|
|
348
|
+
timeout = null;
|
|
349
|
+
if (!immediate) func.apply(context, args);
|
|
350
|
+
};
|
|
351
|
+
var callNow = immediate && !timeout;
|
|
352
|
+
clearTimeout(timeout);
|
|
353
|
+
timeout = setTimeout(later, wait);
|
|
354
|
+
if (callNow) func.apply(context, args);
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
function isWindow(obj) {
|
|
358
|
+
return obj != null && obj === obj.window;
|
|
359
|
+
}
|
|
360
|
+
function getWindow$1(elem) {
|
|
361
|
+
return isWindow(elem) ? elem : elem.nodeType === 9 && elem.defaultView;
|
|
362
|
+
}
|
|
363
|
+
function offset$1(elem) {
|
|
364
|
+
var box = {
|
|
365
|
+
top: 0,
|
|
366
|
+
left: 0,
|
|
367
|
+
right: 0,
|
|
368
|
+
bottom: 0
|
|
369
|
+
};
|
|
370
|
+
var doc = elem && elem.ownerDocument;
|
|
371
|
+
var docElem = doc && doc.documentElement;
|
|
372
|
+
if (!docElem) return box;
|
|
373
|
+
if (_typeof(elem.getBoundingClientRect) !== ("undefined" )) {
|
|
374
|
+
box = elem.getBoundingClientRect();
|
|
375
|
+
}
|
|
376
|
+
var win = getWindow$1(doc);
|
|
377
|
+
var top = box.top + win.pageYOffset - docElem.clientTop;
|
|
378
|
+
var left = box.left + win.pageXOffset - docElem.clientLeft;
|
|
379
|
+
return {
|
|
380
|
+
top: top,
|
|
381
|
+
left: left,
|
|
382
|
+
right: left + (box.right - box.left),
|
|
383
|
+
bottom: top + (box.bottom - box.top)
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
function getClickedElement(e) {
|
|
387
|
+
if (e.srcElement && e.srcElement.nodeType === 1 && (e.srcElement.nodeName === 'BUTTON' || e.srcElement.nodeName === 'INPUT')) {
|
|
388
|
+
if (e.srcElement.getAttribute && e.srcElement.getAttribute('ignorelocizeeditor') === '') {
|
|
389
|
+
return null;
|
|
390
|
+
}
|
|
391
|
+
return e.srcElement;
|
|
392
|
+
}
|
|
393
|
+
var el;
|
|
394
|
+
if (e.originalEvent && e.originalEvent.explicitOriginalTarget) {
|
|
395
|
+
el = e.originalEvent.explicitOriginalTarget;
|
|
396
|
+
} else {
|
|
397
|
+
var parent = e.srcElement;
|
|
398
|
+
if (parent.getAttribute && parent.getAttribute('ignorelocizeeditor') === '') return null;
|
|
399
|
+
var left = e.pageX;
|
|
400
|
+
var top = e.pageY;
|
|
401
|
+
var topStartsAt = 0;
|
|
402
|
+
var topBreaksAt;
|
|
403
|
+
for (var i = 0; i < parent.childNodes.length; i++) {
|
|
404
|
+
var n = parent.childNodes[i];
|
|
405
|
+
var nOffset = offset$1(n);
|
|
406
|
+
if (n.nodeType === 1 && nOffset.bottom < top) topStartsAt = i + 1;
|
|
407
|
+
if (!topBreaksAt && nOffset.top + (n.clientHeight || 0) > top) topBreaksAt = i;
|
|
408
|
+
}
|
|
409
|
+
if (topStartsAt + 1 > parent.childNodes.length) topStartsAt = parent.childNodes.length - 1;
|
|
410
|
+
if (!topBreaksAt) topBreaksAt = parent.childNodes.length;
|
|
411
|
+
for (var y = topStartsAt; y < topBreaksAt; y++) {
|
|
412
|
+
var _n = parent.childNodes[y];
|
|
413
|
+
var _nOffset = offset$1(_n);
|
|
414
|
+
if (_nOffset.left > left) {
|
|
415
|
+
break;
|
|
416
|
+
}
|
|
417
|
+
if (_n && _n.nodeType !== 8) el = _n;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
return el;
|
|
421
|
+
}
|
|
422
|
+
function getElementText(el) {
|
|
423
|
+
var str = el.textContent || el.text && el.text.innerText || el.placeholder;
|
|
424
|
+
if (typeof str !== 'string') return;
|
|
425
|
+
return str.replace(/\n +/g, '').trim();
|
|
426
|
+
}
|
|
427
|
+
function getAttribute(el, name) {
|
|
428
|
+
return el && el.getAttribute && el.getAttribute(name);
|
|
429
|
+
}
|
|
430
|
+
function getElementI18nKey(el) {
|
|
431
|
+
var key = getAttribute(el, 'data-i18n');
|
|
432
|
+
if (key) return key;
|
|
433
|
+
if (el.nodeType === window.Node.TEXT_NODE && el.parentElement) {
|
|
434
|
+
return getElementI18nKey(el.parentElement);
|
|
435
|
+
}
|
|
436
|
+
return undefined;
|
|
437
|
+
}
|
|
438
|
+
function parseAttrFromKey(key) {
|
|
439
|
+
var attr = 'text';
|
|
440
|
+
if (key.indexOf('[') == 0) {
|
|
441
|
+
var parts = key.split(']');
|
|
442
|
+
key = parts[1];
|
|
443
|
+
attr = parts[0].substr(1, parts[0].length - 1);
|
|
444
|
+
}
|
|
445
|
+
var newKey = key.indexOf(';') == key.length - 1 ? key.substr(0, key.length - 2) : key;
|
|
446
|
+
return [newKey, attr];
|
|
447
|
+
}
|
|
448
|
+
function getI18nMetaFromNode(el) {
|
|
449
|
+
var hasNamespacePrependToKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
450
|
+
var key = getElementI18nKey(el);
|
|
451
|
+
var ns = getElementNamespace(el);
|
|
452
|
+
var allKeys = {};
|
|
453
|
+
if (key && key.indexOf(';') >= 0) {
|
|
454
|
+
var keys = key.split(';');
|
|
455
|
+
for (var ix = 0, l_ix = keys.length; ix < l_ix; ix++) {
|
|
456
|
+
if (keys[ix] != '') {
|
|
457
|
+
var _parseAttrFromKey = parseAttrFromKey(keys[ix]),
|
|
458
|
+
_parseAttrFromKey2 = _slicedToArray(_parseAttrFromKey, 2),
|
|
459
|
+
usedKey = _parseAttrFromKey2[0],
|
|
460
|
+
attr = _parseAttrFromKey2[1];
|
|
461
|
+
allKeys[attr] = usedKey;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
} else if (key) {
|
|
465
|
+
var _parseAttrFromKey3 = parseAttrFromKey(key),
|
|
466
|
+
_parseAttrFromKey4 = _slicedToArray(_parseAttrFromKey3, 2),
|
|
467
|
+
_usedKey = _parseAttrFromKey4[0],
|
|
468
|
+
_attr = _parseAttrFromKey4[1];
|
|
469
|
+
allKeys[_attr] = _usedKey;
|
|
470
|
+
}
|
|
471
|
+
if (Object.keys(allKeys).length < 1) return null;
|
|
472
|
+
var res = Object.keys(allKeys).reduce(function (mem, attr) {
|
|
473
|
+
var key = allKeys[attr];
|
|
474
|
+
var usedNS = ns;
|
|
475
|
+
var usedKey = key;
|
|
476
|
+
if (hasNamespacePrependToKey && key.indexOf(':') > -1) {
|
|
477
|
+
var parts = key.split(':');
|
|
478
|
+
usedKey = parts[1];
|
|
479
|
+
usedNS = parts[0];
|
|
480
|
+
}
|
|
481
|
+
mem[attr] = {
|
|
482
|
+
key: usedKey,
|
|
483
|
+
ns: usedNS
|
|
484
|
+
};
|
|
485
|
+
return mem;
|
|
486
|
+
}, {});
|
|
487
|
+
return res;
|
|
488
|
+
}
|
|
489
|
+
function getElementNamespace(el) {
|
|
490
|
+
var found;
|
|
491
|
+
var find = function find(ele) {
|
|
492
|
+
var opts = getAttribute(ele, 'i18next-options');
|
|
493
|
+
if (!opts) opts = getAttribute(ele, 'data-i18next-options');
|
|
494
|
+
if (!opts) opts = getAttribute(ele, 'i18n-options');
|
|
495
|
+
if (!opts) opts = getAttribute(ele, 'data-i18n-options');
|
|
496
|
+
if (opts) {
|
|
497
|
+
var jsonData = {};
|
|
498
|
+
try {
|
|
499
|
+
jsonData = JSON.parse(opts);
|
|
500
|
+
} catch (e) {}
|
|
501
|
+
if (jsonData.ns) found = jsonData.ns;
|
|
502
|
+
}
|
|
503
|
+
if (!found) found = getAttribute(ele, 'i18next-ns');
|
|
504
|
+
if (!found) found = getAttribute(ele, 'data-i18next-ns');
|
|
505
|
+
if (!found) found = getAttribute(ele, 'i18n-ns');
|
|
506
|
+
if (!found) found = getAttribute(ele, 'data-i18n-ns');
|
|
507
|
+
if (!found && ele.parentElement) find(ele.parentElement);
|
|
508
|
+
};
|
|
509
|
+
find(el);
|
|
510
|
+
return found;
|
|
511
|
+
}
|
|
512
|
+
function getQsParameterByName(name, url) {
|
|
513
|
+
if (typeof window === 'undefined') return null;
|
|
514
|
+
if (!url) url = window.location.href.toLowerCase();
|
|
515
|
+
name = name.replace(/[\[\]]/g, '\\$&');
|
|
516
|
+
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)');
|
|
517
|
+
var results = regex.exec(url);
|
|
518
|
+
if (!results) return null;
|
|
519
|
+
if (!results[2]) return '';
|
|
520
|
+
return decodeURIComponent(results[2].replace(/\+/g, ' '));
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
function ownKeys$6(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
524
|
+
function _objectSpread$6(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$6(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$6(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
224
525
|
var legacyEventMapping = {
|
|
225
526
|
committed: 'commitKeys'
|
|
226
527
|
};
|
|
@@ -231,27 +532,18 @@
|
|
|
231
532
|
function addLocizeSavedHandler(handler) {
|
|
232
533
|
api.locizeSavedHandler = handler;
|
|
233
534
|
}
|
|
234
|
-
function turnOn() {
|
|
235
|
-
api.scriptTurnedOff = false;
|
|
236
|
-
api.turnOn();
|
|
237
|
-
return api.scriptTurnedOff;
|
|
238
|
-
}
|
|
239
|
-
function turnOff() {
|
|
240
|
-
api.turnOff();
|
|
241
|
-
api.scriptTurnedOff = true;
|
|
242
|
-
return api.scriptTurnedOff;
|
|
243
|
-
}
|
|
244
535
|
function setEditorLng(lng) {
|
|
245
536
|
api.sendCurrentTargetLanguage(lng);
|
|
246
537
|
}
|
|
247
538
|
var pendingMsgs = [];
|
|
539
|
+
var allowedActionsBeforeInit = ['locizeIsEnabled', 'requestInitialize'];
|
|
248
540
|
function sendMessage(action, payload) {
|
|
249
541
|
if (!api.source) {
|
|
250
542
|
var _document$getElementB;
|
|
251
543
|
api.source = (_document$getElementB = document.getElementById('i18next-editor-iframe')) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.contentWindow;
|
|
252
544
|
}
|
|
253
545
|
if (!api.origin) api.origin = getIframeUrl();
|
|
254
|
-
if (!api.source || !api.source.postMessage) {
|
|
546
|
+
if (!api.source || !api.source.postMessage || !api.initialized && allowedActionsBeforeInit.indexOf(action) < 0) {
|
|
255
547
|
pendingMsgs.push({
|
|
256
548
|
action: action,
|
|
257
549
|
payload: payload
|
|
@@ -259,13 +551,13 @@
|
|
|
259
551
|
return;
|
|
260
552
|
}
|
|
261
553
|
if (api.legacy) {
|
|
262
|
-
api.source.postMessage(_objectSpread$
|
|
554
|
+
api.source.postMessage(_objectSpread$6({
|
|
263
555
|
message: action
|
|
264
556
|
}, payload), api.origin);
|
|
265
557
|
} else {
|
|
266
558
|
api.source.postMessage({
|
|
267
559
|
sender: 'i18next-editor',
|
|
268
|
-
senderAPIVersion: '
|
|
560
|
+
senderAPIVersion: 'v2',
|
|
269
561
|
action: action,
|
|
270
562
|
message: action,
|
|
271
563
|
payload: payload
|
|
@@ -279,6 +571,22 @@
|
|
|
279
571
|
sendMessage(action, payload);
|
|
280
572
|
});
|
|
281
573
|
}
|
|
574
|
+
var sendCurrentParsedContentDebounced = function sendCurrentParsedContentDebounced() {
|
|
575
|
+
sendMessage('sendCurrentParsedContent', {
|
|
576
|
+
content: Object.values(store.data).map(function (item) {
|
|
577
|
+
return {
|
|
578
|
+
id: item.id,
|
|
579
|
+
keys: item.keys
|
|
580
|
+
};
|
|
581
|
+
}),
|
|
582
|
+
uninstrumented: Object.values(uninstrumentedStore.data).map(function (item) {
|
|
583
|
+
return {
|
|
584
|
+
id: item.id,
|
|
585
|
+
keys: item.keys
|
|
586
|
+
};
|
|
587
|
+
})
|
|
588
|
+
});
|
|
589
|
+
};
|
|
282
590
|
var handlers = {};
|
|
283
591
|
var repeat = 5;
|
|
284
592
|
var api = {
|
|
@@ -296,7 +604,7 @@
|
|
|
296
604
|
clearInterval(api.initInterval);
|
|
297
605
|
delete api.initInterval;
|
|
298
606
|
}
|
|
299
|
-
},
|
|
607
|
+
}, 2000);
|
|
300
608
|
},
|
|
301
609
|
selectKey: function selectKey(meta) {
|
|
302
610
|
sendMessage('selectKey', meta);
|
|
@@ -304,45 +612,25 @@
|
|
|
304
612
|
confirmResourceBundle: function confirmResourceBundle(payload) {
|
|
305
613
|
sendMessage('confirmResourceBundle', payload);
|
|
306
614
|
},
|
|
307
|
-
sendCurrentParsedContent:
|
|
308
|
-
sendMessage('sendCurrentParsedContent', {
|
|
309
|
-
content: Object.values(store.data).map(function (item) {
|
|
310
|
-
return {
|
|
311
|
-
id: item.id,
|
|
312
|
-
keys: item.keys
|
|
313
|
-
};
|
|
314
|
-
})
|
|
315
|
-
});
|
|
316
|
-
},
|
|
615
|
+
sendCurrentParsedContent: debounce(sendCurrentParsedContentDebounced, 500),
|
|
317
616
|
sendCurrentTargetLanguage: function sendCurrentTargetLanguage(lng) {
|
|
318
617
|
sendMessage('sendCurrentTargetLanguage', {
|
|
319
618
|
targetLng: lng || api.i18n.getLng()
|
|
320
619
|
});
|
|
321
620
|
},
|
|
621
|
+
sendHrefchanged: function sendHrefchanged(href) {
|
|
622
|
+
sendMessage('hrefChanged', {
|
|
623
|
+
href: href
|
|
624
|
+
});
|
|
625
|
+
},
|
|
322
626
|
addHandler: function addHandler(action, fc) {
|
|
323
627
|
if (!handlers[action]) handlers[action] = [];
|
|
324
628
|
handlers[action].push(fc);
|
|
325
629
|
},
|
|
326
|
-
sendLocizeIsEnabled: function sendLocizeIsEnabled() {
|
|
327
|
-
sendMessage('locizeIsEnabled', {
|
|
630
|
+
sendLocizeIsEnabled: function sendLocizeIsEnabled(payload) {
|
|
631
|
+
sendMessage('locizeIsEnabled', _objectSpread$6(_objectSpread$6({}, payload), {}, {
|
|
328
632
|
enabled: true
|
|
329
|
-
});
|
|
330
|
-
},
|
|
331
|
-
turnOn: function turnOn() {
|
|
332
|
-
if (api.scriptTurnedOff) return sendMessage('forcedOff');
|
|
333
|
-
if (!api.clickInterceptionEnabled) {
|
|
334
|
-
window.document.body.addEventListener('click', api.clickHandler, true);
|
|
335
|
-
}
|
|
336
|
-
api.clickInterceptionEnabled = true;
|
|
337
|
-
sendMessage('turnedOn');
|
|
338
|
-
},
|
|
339
|
-
turnOff: function turnOff() {
|
|
340
|
-
if (api.scriptTurnedOff) return sendMessage('forcedOff');
|
|
341
|
-
if (api.clickInterceptionEnabled) {
|
|
342
|
-
window.document.body.removeEventListener('click', api.clickHandler, true);
|
|
343
|
-
}
|
|
344
|
-
api.clickInterceptionEnabled = false;
|
|
345
|
-
sendMessage('turnedOff');
|
|
633
|
+
}));
|
|
346
634
|
},
|
|
347
635
|
onAddedKey: function onAddedKey(lng, ns, key, value) {
|
|
348
636
|
var msg = {
|
|
@@ -370,7 +658,7 @@
|
|
|
370
658
|
}
|
|
371
659
|
} else if (sender === 'i18next-editor-frame' && handlers[action]) {
|
|
372
660
|
handlers[action].forEach(function (fc) {
|
|
373
|
-
fc(payload);
|
|
661
|
+
fc(payload, e);
|
|
374
662
|
});
|
|
375
663
|
}
|
|
376
664
|
});
|
|
@@ -379,7 +667,7 @@
|
|
|
379
667
|
function setValueOnNode(meta, value) {
|
|
380
668
|
var item = store.get(meta.eleUniqueID);
|
|
381
669
|
if (!item || !item.keys[meta.textType]) return;
|
|
382
|
-
var txtWithHiddenMeta = wrap(value, item.subliminal);
|
|
670
|
+
var txtWithHiddenMeta = item.subliminal ? wrap(value, item.subliminal) : value;
|
|
383
671
|
if (meta.textType === 'text') {
|
|
384
672
|
item.node.textContent = txtWithHiddenMeta;
|
|
385
673
|
} else if (meta.textType.indexOf('attr:') === 0) {
|
|
@@ -418,16 +706,16 @@
|
|
|
418
706
|
}
|
|
419
707
|
}
|
|
420
708
|
}
|
|
421
|
-
function handler$
|
|
709
|
+
function handler$8(payload) {
|
|
422
710
|
var meta = payload.meta,
|
|
423
711
|
value = payload.value;
|
|
424
712
|
if (meta && value !== undefined) {
|
|
425
713
|
setValueOnNode(meta, value);
|
|
426
714
|
}
|
|
427
715
|
}
|
|
428
|
-
api.addHandler('editKey', handler$
|
|
716
|
+
api.addHandler('editKey', handler$8);
|
|
429
717
|
|
|
430
|
-
function handler$
|
|
718
|
+
function handler$7(payload) {
|
|
431
719
|
var meta = payload.meta,
|
|
432
720
|
value = payload.value,
|
|
433
721
|
lng = payload.lng;
|
|
@@ -438,40 +726,9 @@
|
|
|
438
726
|
api.i18n.triggerRerender();
|
|
439
727
|
}
|
|
440
728
|
}
|
|
441
|
-
api.addHandler('commitKey', handler$
|
|
442
|
-
|
|
443
|
-
function _arrayLikeToArray(arr, len) {
|
|
444
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
445
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
446
|
-
return arr2;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
function _arrayWithoutHoles(arr) {
|
|
450
|
-
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
function _iterableToArray(iter) {
|
|
454
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
458
|
-
if (!o) return;
|
|
459
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
460
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
461
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
462
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
463
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
464
|
-
}
|
|
729
|
+
api.addHandler('commitKey', handler$7);
|
|
465
730
|
|
|
466
|
-
function
|
|
467
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
function _toConsumableArray(arr) {
|
|
471
|
-
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
function handler$7(payload) {
|
|
731
|
+
function handler$6(payload) {
|
|
475
732
|
var updated = payload.updated;
|
|
476
733
|
updated.forEach(function (item) {
|
|
477
734
|
var lng = item.lng,
|
|
@@ -487,6 +744,12 @@
|
|
|
487
744
|
});
|
|
488
745
|
}
|
|
489
746
|
api.i18n.setResource(lng, ns, key, data.value);
|
|
747
|
+
if (metas) {
|
|
748
|
+
Object.values(metas).forEach(function (m) {
|
|
749
|
+
var sItem = store.get(m.eleUniqueID);
|
|
750
|
+
recalcSelectedHighlight(sItem, sItem.node, sItem.keys);
|
|
751
|
+
});
|
|
752
|
+
}
|
|
490
753
|
});
|
|
491
754
|
Object.values(store.data).forEach(function (item) {
|
|
492
755
|
if (item.originalChildNodes) {
|
|
@@ -498,47 +761,16 @@
|
|
|
498
761
|
if (api.locizeSavedHandler) api.locizeSavedHandler(payload);
|
|
499
762
|
if (window.locizeSavedHandler) window.locizeSavedHandler(payload);
|
|
500
763
|
}
|
|
501
|
-
api.addHandler('commitKeys', handler$
|
|
764
|
+
api.addHandler('commitKeys', handler$6);
|
|
502
765
|
|
|
503
|
-
function handler$
|
|
766
|
+
function handler$5(payload) {
|
|
504
767
|
api.initialized = true;
|
|
505
768
|
clearInterval(api.initInterval);
|
|
506
769
|
delete api.initInterval;
|
|
507
770
|
api.sendCurrentParsedContent();
|
|
508
771
|
api.sendCurrentTargetLanguage();
|
|
509
772
|
}
|
|
510
|
-
api.addHandler('confirmInitialized', handler$
|
|
511
|
-
|
|
512
|
-
function ownKeys$6(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
513
|
-
function _objectSpread$6(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$6(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$6(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
514
|
-
var data$1 = {};
|
|
515
|
-
function clean$1() {
|
|
516
|
-
Object.values(data$1).forEach(function (item) {
|
|
517
|
-
if (!document.body.contains(item.node)) {
|
|
518
|
-
resetHighlight(item.id, item.node);
|
|
519
|
-
delete data$1[item.id];
|
|
520
|
-
}
|
|
521
|
-
});
|
|
522
|
-
}
|
|
523
|
-
function save$1(id, type, node) {
|
|
524
|
-
if (!id || !type || !node) return;
|
|
525
|
-
if (!data$1[id]) {
|
|
526
|
-
data$1[id] = {
|
|
527
|
-
id: id,
|
|
528
|
-
node: node
|
|
529
|
-
};
|
|
530
|
-
}
|
|
531
|
-
data$1[id].keys = _objectSpread$6(_objectSpread$6({}, data$1[id].keys), {}, _defineProperty({}, "".concat(type), 'uninstrumented'));
|
|
532
|
-
}
|
|
533
|
-
function get$1(id) {
|
|
534
|
-
return data$1[id];
|
|
535
|
-
}
|
|
536
|
-
var uninstrumentedStore = {
|
|
537
|
-
save: save$1,
|
|
538
|
-
clean: clean$1,
|
|
539
|
-
get: get$1,
|
|
540
|
-
data: data$1
|
|
541
|
-
};
|
|
773
|
+
api.addHandler('confirmInitialized', handler$5);
|
|
542
774
|
|
|
543
775
|
function isInViewport(el) {
|
|
544
776
|
var rect = el.getBoundingClientRect();
|
|
@@ -576,135 +808,22 @@
|
|
|
576
808
|
hypot = Math.pow(Math.pow(distX, 2) + Math.pow(distY, 2), 1 / 2);
|
|
577
809
|
return Math.floor(hypot);
|
|
578
810
|
}
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
if (callNow) func.apply(context, args);
|
|
593
|
-
};
|
|
594
|
-
}
|
|
595
|
-
function isWindow(obj) {
|
|
596
|
-
return obj != null && obj === obj.window;
|
|
597
|
-
}
|
|
598
|
-
function getWindow$1(elem) {
|
|
599
|
-
return isWindow(elem) ? elem : elem.nodeType === 9 && elem.defaultView;
|
|
600
|
-
}
|
|
601
|
-
function offset$1(elem) {
|
|
602
|
-
var box = {
|
|
603
|
-
top: 0,
|
|
604
|
-
left: 0,
|
|
605
|
-
right: 0,
|
|
606
|
-
bottom: 0
|
|
607
|
-
};
|
|
608
|
-
var doc = elem && elem.ownerDocument;
|
|
609
|
-
var docElem = doc && doc.documentElement;
|
|
610
|
-
if (!docElem) return box;
|
|
611
|
-
if (_typeof(elem.getBoundingClientRect) !== ("undefined" )) {
|
|
612
|
-
box = elem.getBoundingClientRect();
|
|
613
|
-
}
|
|
614
|
-
var win = getWindow$1(doc);
|
|
615
|
-
var top = box.top + win.pageYOffset - docElem.clientTop;
|
|
616
|
-
var left = box.left + win.pageXOffset - docElem.clientLeft;
|
|
617
|
-
return {
|
|
618
|
-
top: top,
|
|
619
|
-
left: left,
|
|
620
|
-
right: left + (box.right - box.left),
|
|
621
|
-
bottom: top + (box.bottom - box.top)
|
|
622
|
-
};
|
|
623
|
-
}
|
|
624
|
-
function getClickedElement(e) {
|
|
625
|
-
if (e.srcElement && e.srcElement.nodeType === 1 && (e.srcElement.nodeName === 'BUTTON' || e.srcElement.nodeName === 'INPUT')) {
|
|
626
|
-
if (e.srcElement.getAttribute && e.srcElement.getAttribute('ignorelocizeeditor') === '') {
|
|
627
|
-
return null;
|
|
628
|
-
}
|
|
629
|
-
return e.srcElement;
|
|
630
|
-
}
|
|
631
|
-
var el;
|
|
632
|
-
if (e.originalEvent && e.originalEvent.explicitOriginalTarget) {
|
|
633
|
-
el = e.originalEvent.explicitOriginalTarget;
|
|
634
|
-
} else {
|
|
635
|
-
var parent = e.srcElement;
|
|
636
|
-
if (parent.getAttribute && parent.getAttribute('ignorelocizeeditor') === '') return null;
|
|
637
|
-
var left = e.pageX;
|
|
638
|
-
var top = e.pageY;
|
|
639
|
-
var topStartsAt = 0;
|
|
640
|
-
var topBreaksAt;
|
|
641
|
-
for (var i = 0; i < parent.childNodes.length; i++) {
|
|
642
|
-
var n = parent.childNodes[i];
|
|
643
|
-
var nOffset = offset$1(n);
|
|
644
|
-
if (n.nodeType === 1 && nOffset.bottom < top) topStartsAt = i + 1;
|
|
645
|
-
if (!topBreaksAt && nOffset.top + (n.clientHeight || 0) > top) topBreaksAt = i;
|
|
646
|
-
}
|
|
647
|
-
if (topStartsAt + 1 > parent.childNodes.length) topStartsAt = parent.childNodes.length - 1;
|
|
648
|
-
if (!topBreaksAt) topBreaksAt = parent.childNodes.length;
|
|
649
|
-
for (var y = topStartsAt; y < topBreaksAt; y++) {
|
|
650
|
-
var _n = parent.childNodes[y];
|
|
651
|
-
var _nOffset = offset$1(_n);
|
|
652
|
-
if (_nOffset.left > left) {
|
|
653
|
-
break;
|
|
654
|
-
}
|
|
655
|
-
if (_n && _n.nodeType !== 8) el = _n;
|
|
811
|
+
function getOptimizedBoundingRectEle(node) {
|
|
812
|
+
var refEle = node;
|
|
813
|
+
if (node.childNodes.length === 1) {
|
|
814
|
+
var childNode = node.childNodes[0];
|
|
815
|
+
if (childNode && childNode.nodeName === '#text') {
|
|
816
|
+
var range = document.createRange();
|
|
817
|
+
range.selectNode(childNode);
|
|
818
|
+
var rect = range.getBoundingClientRect();
|
|
819
|
+
refEle = {
|
|
820
|
+
getBoundingClientRect: function getBoundingClientRect() {
|
|
821
|
+
return rect;
|
|
822
|
+
}
|
|
823
|
+
};
|
|
656
824
|
}
|
|
657
825
|
}
|
|
658
|
-
return
|
|
659
|
-
}
|
|
660
|
-
function getElementText(el) {
|
|
661
|
-
var str = el.textContent || el.text && el.text.innerText || el.placeholder;
|
|
662
|
-
if (typeof str !== 'string') return;
|
|
663
|
-
return str.replace(/\n +/g, '').trim();
|
|
664
|
-
}
|
|
665
|
-
function getAttribute(el, name) {
|
|
666
|
-
return el && el.getAttribute && el.getAttribute(name);
|
|
667
|
-
}
|
|
668
|
-
function getElementI18nKey(el) {
|
|
669
|
-
var key = getAttribute(el, 'data-i18n');
|
|
670
|
-
if (key) return key;
|
|
671
|
-
if (el.nodeType === window.Node.TEXT_NODE && el.parentElement) {
|
|
672
|
-
return getElementI18nKey(el.parentElement);
|
|
673
|
-
}
|
|
674
|
-
return undefined;
|
|
675
|
-
}
|
|
676
|
-
function getElementNamespace(el) {
|
|
677
|
-
var found;
|
|
678
|
-
var find = function find(ele) {
|
|
679
|
-
var opts = getAttribute(ele, 'i18next-options');
|
|
680
|
-
if (!opts) opts = getAttribute(ele, 'data-i18next-options');
|
|
681
|
-
if (!opts) opts = getAttribute(ele, 'i18n-options');
|
|
682
|
-
if (!opts) opts = getAttribute(ele, 'data-i18n-options');
|
|
683
|
-
if (opts) {
|
|
684
|
-
var jsonData = {};
|
|
685
|
-
try {
|
|
686
|
-
jsonData = JSON.parse(opts);
|
|
687
|
-
} catch (e) {}
|
|
688
|
-
if (jsonData.ns) found = jsonData.ns;
|
|
689
|
-
}
|
|
690
|
-
if (!found) found = getAttribute(ele, 'i18next-ns');
|
|
691
|
-
if (!found) found = getAttribute(ele, 'data-i18next-ns');
|
|
692
|
-
if (!found) found = getAttribute(ele, 'i18n-ns');
|
|
693
|
-
if (!found) found = getAttribute(ele, 'data-i18n-ns');
|
|
694
|
-
if (!found && ele.parentElement) find(ele.parentElement);
|
|
695
|
-
};
|
|
696
|
-
find(el);
|
|
697
|
-
return found;
|
|
698
|
-
}
|
|
699
|
-
function getQsParameterByName(name, url) {
|
|
700
|
-
if (typeof window === 'undefined') return null;
|
|
701
|
-
if (!url) url = window.location.href.toLowerCase();
|
|
702
|
-
name = name.replace(/[\[\]]/g, '\\$&');
|
|
703
|
-
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)');
|
|
704
|
-
var results = regex.exec(url);
|
|
705
|
-
if (!results) return null;
|
|
706
|
-
if (!results[2]) return '';
|
|
707
|
-
return decodeURIComponent(results[2].replace(/\+/g, ' '));
|
|
826
|
+
return refEle;
|
|
708
827
|
}
|
|
709
828
|
|
|
710
829
|
var debouncedUpdateDistance = debounce(function (e, observer) {
|
|
@@ -746,7 +865,7 @@
|
|
|
746
865
|
var editIconUrl = URL.createObjectURL(new Blob([iconEdit], {
|
|
747
866
|
type: 'image/svg+xml'
|
|
748
867
|
}));
|
|
749
|
-
|
|
868
|
+
URL.createObjectURL(new Blob([i18nextIcon], {
|
|
750
869
|
type: 'image/svg+xml'
|
|
751
870
|
}));
|
|
752
871
|
var minimizeIconUrl = URL.createObjectURL(new Blob([minimizeIcon], {
|
|
@@ -762,18 +881,6 @@
|
|
|
762
881
|
image.style.width = '15px';
|
|
763
882
|
return image;
|
|
764
883
|
}
|
|
765
|
-
function RibbonLogo() {
|
|
766
|
-
var circleSize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '18px';
|
|
767
|
-
var logoSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '15px';
|
|
768
|
-
var ribbon = document.createElement('div');
|
|
769
|
-
ribbon.setAttribute('data-i18next-editor-element', 'true');
|
|
770
|
-
ribbon.style = "display: inline-flex; align-items: center; justify-content: center; width: ".concat(circleSize, "; height: ").concat(circleSize, "; box-shadow: inset 0 0 5px ").concat(colors.highlight, "; border: 2px solid ").concat(colors.highlight, "; border-radius: 50%");
|
|
771
|
-
var image = document.createElement('img');
|
|
772
|
-
image.src = i18nextIconUrl;
|
|
773
|
-
image.style.width = logoSize;
|
|
774
|
-
ribbon.appendChild(image);
|
|
775
|
-
return ribbon;
|
|
776
|
-
}
|
|
777
884
|
|
|
778
885
|
if (sheet) {
|
|
779
886
|
sheet.insertRule("@keyframes i18next-editor-animate-top { \n from {\n top: calc(100vh + 600px); \n left: calc(100vw + 300px);\n opacity: 0;\n }\n to {\n top: var(--i18next-editor-popup-position-top);\n left: var(--i18next-editor-popup-position-left);\n opacity: 1;\n }\n }");
|
|
@@ -786,7 +893,7 @@
|
|
|
786
893
|
function Ribbon(popupEle, onMaximize) {
|
|
787
894
|
var ribbon = document.createElement('div');
|
|
788
895
|
ribbon.setAttribute('data-i18next-editor-element', 'true');
|
|
789
|
-
ribbon.style = "\n cursor: pointer;\n position: fixed;\n bottom: 25px;\n right: 25px;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 50px;\n height: 50px;\n background-color: rgba(249, 249, 249, 0.2);\n backdrop-filter: blur(3px);\n box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);\n border-radius: 50
|
|
896
|
+
ribbon.style = "\n cursor: pointer;\n position: fixed;\n bottom: 25px;\n right: 25px;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 50px;\n height: 50px;\n background-color: rgba(249, 249, 249, 0.2);\n backdrop-filter: blur(3px);\n box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);\n border-radius: 50%;\n ";
|
|
790
897
|
ribbon.onclick = function () {
|
|
791
898
|
onMaximize();
|
|
792
899
|
};
|
|
@@ -815,7 +922,7 @@
|
|
|
815
922
|
var popup = document.createElement('div');
|
|
816
923
|
popup.setAttribute('id', popupId);
|
|
817
924
|
popup.classList.add('i18next-editor-popup');
|
|
818
|
-
popup.style = "\n z-index: 9;\n background-color: transparent;\n border: 1px solid rgba(200, 200, 200, 0.9);\n box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);\n border-radius: 3px;\n --i18next-editor-popup-height: 200px;\n height: var(--i18next-editor-popup-height);\n min-height: 150px;\n min-width: 300px;\n --i18next-editor-popup-width: 400px;\n width: var(--i18next-editor-popup-width);\n max-height:
|
|
925
|
+
popup.style = "\n z-index: 9;\n background-color: transparent;\n border: 1px solid rgba(200, 200, 200, 0.9);\n box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);\n border-radius: 3px;\n --i18next-editor-popup-height: 200px;\n height: var(--i18next-editor-popup-height);\n min-height: 150px;\n min-width: 300px;\n --i18next-editor-popup-width: 400px;\n width: var(--i18next-editor-popup-width);\n max-height: 800px;\n max-width: 1000px;\n\n position: fixed;\n --i18next-editor-popup-position-top: calc(100vh - var(--i18next-editor-popup-height) - 10px);\n top: calc(100vh - var(--i18next-editor-popup-height) - 10px);\n --i18next-editor-popup-position-left: calc(100vw - var(--i18next-editor-popup-width) - 10px);\n left: calc(100vw - var(--i18next-editor-popup-width) - 10px);\n\n overflow: visible;\n ";
|
|
819
926
|
popup.setAttribute('data-i18next-editor-element', 'true');
|
|
820
927
|
var header = document.createElement('div');
|
|
821
928
|
header.classList.add('i18next-editor-popup-header');
|
|
@@ -835,7 +942,7 @@
|
|
|
835
942
|
var iframe = document.createElement('iframe');
|
|
836
943
|
iframe.setAttribute('id', 'i18next-editor-iframe');
|
|
837
944
|
iframe.setAttribute('data-i18next-editor-element', 'true');
|
|
838
|
-
iframe.style = "\n z-index: 100;\n width: 100%;\n height: calc(100% -
|
|
945
|
+
iframe.style = "\n z-index: 100;\n width: 100%;\n height: calc(100% - 32px);\n border: none;\n background: #fff;\n ";
|
|
839
946
|
iframe.setAttribute('src', url);
|
|
840
947
|
iframe.addEventListener('load', cb);
|
|
841
948
|
popup.appendChild(iframe);
|
|
@@ -847,10 +954,19 @@
|
|
|
847
954
|
return popup;
|
|
848
955
|
}
|
|
849
956
|
|
|
850
|
-
function handler$
|
|
957
|
+
function handler$4(payload) {
|
|
851
958
|
var containerStyle = payload.containerStyle;
|
|
852
959
|
if (containerStyle) {
|
|
853
960
|
var popup = document.getElementById(popupId);
|
|
961
|
+
if (!popup) return;
|
|
962
|
+
var storedPos = localStorage.getItem('locize_popup_pos');
|
|
963
|
+
if (storedPos) storedPos = JSON.parse(storedPos);
|
|
964
|
+
var storedSize = localStorage.getItem('locize_popup_size');
|
|
965
|
+
if (storedSize) storedSize = JSON.parse(storedSize);
|
|
966
|
+
if (storedSize && storedSize.height && storedSize.width) {
|
|
967
|
+
containerStyle.height = storedSize.height + 'px';
|
|
968
|
+
containerStyle.width = storedSize.width + 'px';
|
|
969
|
+
}
|
|
854
970
|
if (containerStyle.height) {
|
|
855
971
|
var diff = "calc(".concat(containerStyle.height, " - ").concat(popup.style.height, ")");
|
|
856
972
|
popup.style.setProperty('top', "calc(".concat(popup.style.top, " - ").concat(diff, ")"));
|
|
@@ -861,9 +977,11 @@
|
|
|
861
977
|
popup.style.setProperty('left', "calc(".concat(popup.style.left, " - ").concat(_diff, ")"));
|
|
862
978
|
popup.style.setProperty('width', containerStyle.width);
|
|
863
979
|
}
|
|
980
|
+
if (storedPos && storedPos.top && storedPos.top < window.innerHeight - containerStyle.height.replace('px', '')) popup.style.setProperty('top', storedPos.top + 'px');
|
|
981
|
+
if (storedPos && storedPos.left && storedPos.left < window.innerWidth - containerStyle.width.replace('px', '')) popup.style.setProperty('left', storedPos.left + 'px');
|
|
864
982
|
}
|
|
865
983
|
}
|
|
866
|
-
api.addHandler('requestPopupChanges', handler$
|
|
984
|
+
api.addHandler('requestPopupChanges', handler$4);
|
|
867
985
|
|
|
868
986
|
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
869
987
|
if (source == null) return {};
|
|
@@ -897,7 +1015,7 @@
|
|
|
897
1015
|
var _excluded = ["lng", "ns"];
|
|
898
1016
|
function ownKeys$5(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
899
1017
|
function _objectSpread$5(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$5(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$5(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
900
|
-
function handler$
|
|
1018
|
+
function handler$3(payload) {
|
|
901
1019
|
var lng = payload.lng,
|
|
902
1020
|
ns = payload.ns,
|
|
903
1021
|
rest = _objectWithoutProperties(payload, _excluded);
|
|
@@ -909,10 +1027,10 @@
|
|
|
909
1027
|
}, rest));
|
|
910
1028
|
});
|
|
911
1029
|
}
|
|
912
|
-
api.addHandler('requestResourceBundle', handler$
|
|
1030
|
+
api.addHandler('requestResourceBundle', handler$3);
|
|
913
1031
|
|
|
914
1032
|
var previousMatches = [];
|
|
915
|
-
function handler$
|
|
1033
|
+
function handler$2(payload) {
|
|
916
1034
|
var keys = payload.keys;
|
|
917
1035
|
var matchingItems = [];
|
|
918
1036
|
Object.values(store.data).forEach(function (item) {
|
|
@@ -931,32 +1049,37 @@
|
|
|
931
1049
|
});
|
|
932
1050
|
previousMatches = matchingItems;
|
|
933
1051
|
}
|
|
934
|
-
api.addHandler('selectedKeys', handler$
|
|
1052
|
+
api.addHandler('selectedKeys', handler$2);
|
|
935
1053
|
|
|
936
|
-
function handler$
|
|
1054
|
+
function handler$1(payload, e) {
|
|
937
1055
|
api.source = e.source;
|
|
938
1056
|
api.origin = e.origin;
|
|
939
|
-
api.
|
|
940
|
-
api.
|
|
941
|
-
}
|
|
942
|
-
api.addHandler('isLocizeEnabled', handler$
|
|
943
|
-
|
|
944
|
-
function handler
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
1057
|
+
api.sendLocizeIsEnabled(payload);
|
|
1058
|
+
api.requestInitialize(api.config);
|
|
1059
|
+
}
|
|
1060
|
+
api.addHandler('isLocizeEnabled', handler$1);
|
|
1061
|
+
|
|
1062
|
+
function handler(payload) {
|
|
1063
|
+
if (!payload.length) return;
|
|
1064
|
+
payload.forEach(function (item) {
|
|
1065
|
+
var uni = uninstrumentedStore.get(item.eleUniqueID);
|
|
1066
|
+
store.save(item.eleUniqueID, undefined, item.textType, extractNodeMeta(item.eleUniqueID, item.textType, _defineProperty({}, "".concat(item.textType), {
|
|
1067
|
+
ns: item.ns,
|
|
1068
|
+
key: item.key
|
|
1069
|
+
}), item.value), uni === null || uni === void 0 ? void 0 : uni.node);
|
|
1070
|
+
delete uni.keys["".concat(item.textType)];
|
|
1071
|
+
if (!Object.keys(uni.keys).length) uninstrumentedStore.remove(item.eleUniqueID, uni.node);
|
|
1072
|
+
});
|
|
1073
|
+
api.sendCurrentParsedContent();
|
|
951
1074
|
}
|
|
952
|
-
api.addHandler('
|
|
1075
|
+
api.addHandler('sendMatchedUninstrumented', handler);
|
|
953
1076
|
|
|
954
1077
|
if (sheet) {
|
|
955
|
-
sheet.insertRule('.i18next-editor-button:hover { background-color: rgba(
|
|
1078
|
+
sheet.insertRule('.i18next-editor-button:hover { background-color: rgba(21, 65, 154, 1) !important; }');
|
|
956
1079
|
}
|
|
957
1080
|
function RibbonButton(text, attrTitle, onClick) {
|
|
958
1081
|
var btn = document.createElement('button');
|
|
959
|
-
btn.style = 'font-family: Arial; position: relative; backdrop-filter: blur(3px); cursor: pointer; padding: 2px 10px 2px 20px; font-size: 15px; font-weight: 300; text-transform: uppercase; color: #fff; background-color: rgba(
|
|
1082
|
+
btn.style = 'font-family: Arial; position: relative; backdrop-filter: blur(3px); cursor: pointer; padding: 2px 10px 2px 20px; font-size: 15px; font-weight: 300; text-transform: uppercase; color: #fff; background-color: rgba(25, 118, 210, 0.8); border: none; border-radius: 12px; z-index: 99999;';
|
|
960
1083
|
btn.classList.add('i18next-editor-button');
|
|
961
1084
|
btn.setAttribute('data-i18next-editor-element', 'true');
|
|
962
1085
|
btn.setAttribute('title', attrTitle);
|
|
@@ -978,8 +1101,6 @@
|
|
|
978
1101
|
var arrow = document.createElement('div');
|
|
979
1102
|
arrow.style = "\n position: absolute;\n width: 0;\n height: 0;\n border-top-width: 7px;\n border-bottom-width: 7px;\n border-left-width: 10px;\n border-right-width: 10px;\n border-style: solid;\n border-color: transparent ".concat(colors.highlight, " transparent\n transparent;\n ");
|
|
980
1103
|
box.appendChild(arrow);
|
|
981
|
-
var logo = RibbonLogo();
|
|
982
|
-
box.appendChild(logo);
|
|
983
1104
|
var btnbox = document.createElement('div');
|
|
984
1105
|
btnbox.style = 'display: flex; flex-direction: column; align-items: flex-start; margin-left: 2px; margin-top: 1px';
|
|
985
1106
|
Object.keys(keys).forEach(function (k) {
|
|
@@ -997,6 +1118,14 @@
|
|
|
997
1118
|
};
|
|
998
1119
|
}
|
|
999
1120
|
|
|
1121
|
+
function HighlightBox(ele, borderColor, shadowColor) {
|
|
1122
|
+
var rect = ele.getBoundingClientRect();
|
|
1123
|
+
var box = document.createElement('div');
|
|
1124
|
+
box.style = "position: absolute; top: ".concat(rect.top - 2 + window.scrollY, "px; left: ").concat(rect.left - 2 + window.scrollX, "px; height: ").concat(rect.height + 4, "px; width: ").concat(rect.width + 4, "px; border: 1px solid ").concat(borderColor, "; border-radius: 2px; ").concat(shadowColor ? "box-shadow: 0 0 20px 0 ".concat(shadowColor, ";") : '');
|
|
1125
|
+
box.setAttribute('data-i18next-editor-element', 'true');
|
|
1126
|
+
return box;
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1000
1129
|
const min = Math.min;
|
|
1001
1130
|
const max = Math.max;
|
|
1002
1131
|
const round = Math.round;
|
|
@@ -2239,50 +2368,21 @@
|
|
|
2239
2368
|
});
|
|
2240
2369
|
};
|
|
2241
2370
|
|
|
2242
|
-
var eleToOutline = ['DIV', 'P', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'OL', 'UL', 'ADDRESS', 'BLOCKQUOTE', 'DL', 'PRE'];
|
|
2243
|
-
var overriddenStyles = ['outline', 'border-radius', 'outline-offset', 'filter'];
|
|
2244
|
-
var originalStyles = {};
|
|
2245
2371
|
var selected = {};
|
|
2246
2372
|
function highlight(item, node, keys) {
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
if (!
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
}, {});
|
|
2254
|
-
}
|
|
2255
|
-
if (eleToOutline.includes(node.nodeName)) {
|
|
2256
|
-
node.style.outline = "".concat(colors.highlight, " solid 1px");
|
|
2257
|
-
node.style.setProperty('border-radius', '1px');
|
|
2258
|
-
node.style.setProperty('outline-offset', '2px');
|
|
2259
|
-
node.style.filter = 'brightness(110%)';
|
|
2260
|
-
} else {
|
|
2261
|
-
node.style.outline = "".concat(colors.highlight, " solid 1px");
|
|
2262
|
-
node.style.setProperty('border-radius', '1px');
|
|
2263
|
-
node.style.setProperty('outline-offset', '1px');
|
|
2264
|
-
node.style.filter = 'brightness(110%)';
|
|
2373
|
+
item.id;
|
|
2374
|
+
var rectEle = getOptimizedBoundingRectEle(node);
|
|
2375
|
+
if (!item.highlightBox) {
|
|
2376
|
+
var box = HighlightBox(rectEle, colors.highlight);
|
|
2377
|
+
document.body.appendChild(box);
|
|
2378
|
+
item.highlightBox = box;
|
|
2265
2379
|
}
|
|
2266
2380
|
if (!item.ribbonBox) {
|
|
2267
2381
|
var _RibbonBox = RibbonBox(keys),
|
|
2268
2382
|
actions = _RibbonBox.box,
|
|
2269
2383
|
arrowEle = _RibbonBox.arrow;
|
|
2270
2384
|
document.body.appendChild(actions);
|
|
2271
|
-
|
|
2272
|
-
if (node.childNodes.length === 1) {
|
|
2273
|
-
var childNode = node.childNodes[0];
|
|
2274
|
-
if (childNode && childNode.nodeName === '#text') {
|
|
2275
|
-
var range = document.createRange();
|
|
2276
|
-
range.selectNode(childNode);
|
|
2277
|
-
var rect = range.getBoundingClientRect();
|
|
2278
|
-
refEle = {
|
|
2279
|
-
getBoundingClientRect: function getBoundingClientRect() {
|
|
2280
|
-
return rect;
|
|
2281
|
-
}
|
|
2282
|
-
};
|
|
2283
|
-
}
|
|
2284
|
-
}
|
|
2285
|
-
computePosition(refEle, actions, {
|
|
2385
|
+
computePosition(rectEle, actions, {
|
|
2286
2386
|
placement: 'right',
|
|
2287
2387
|
middleware: [flip({
|
|
2288
2388
|
fallbackPlacements: ['left', 'bottom']
|
|
@@ -2329,58 +2429,35 @@
|
|
|
2329
2429
|
function highlightUninstrumented(item, node, keys) {
|
|
2330
2430
|
var id = item.id;
|
|
2331
2431
|
if (selected[id]) return;
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
}
|
|
2338
|
-
if (eleToOutline.includes(node.nodeName)) {
|
|
2339
|
-
node.style.outline = "".concat(colors.warning, " solid 1px");
|
|
2340
|
-
node.style.setProperty('border-radius', '1px');
|
|
2341
|
-
node.style.setProperty('outline-offset', '2px');
|
|
2342
|
-
node.style.filter = 'brightness(110%)';
|
|
2343
|
-
} else {
|
|
2344
|
-
node.style.outline = "".concat(colors.warning, " solid 1px");
|
|
2345
|
-
node.style.setProperty('border-radius', '1px');
|
|
2346
|
-
node.style.setProperty('outline-offset', '1px');
|
|
2347
|
-
node.style.filter = 'brightness(110%)';
|
|
2348
|
-
}
|
|
2349
|
-
}
|
|
2350
|
-
function selectedHighlight(item, node, keys) {
|
|
2351
|
-
var id = item.id;
|
|
2352
|
-
if (!originalStyles[id]) {
|
|
2353
|
-
originalStyles[id] = overriddenStyles.reduce(function (mem, s) {
|
|
2354
|
-
mem[s] = node.style[s];
|
|
2355
|
-
return mem;
|
|
2356
|
-
}, {});
|
|
2357
|
-
}
|
|
2358
|
-
if (eleToOutline.includes(node.nodeName)) {
|
|
2359
|
-
node.style.outline = "".concat(colors.highlight, " solid 1px");
|
|
2360
|
-
node.style.setProperty('border-radius', '1px');
|
|
2361
|
-
node.style.setProperty('outline-offset', '2px');
|
|
2362
|
-
node.style.filter = "brightness(110%) drop-shadow(0px 0px 2px ".concat(colors.highlight, " )");
|
|
2363
|
-
} else {
|
|
2364
|
-
node.style.outline = "".concat(colors.highlight, " solid 1px");
|
|
2365
|
-
node.style.setProperty('border-radius', '1px');
|
|
2366
|
-
node.style.setProperty('outline-offset', '1px');
|
|
2367
|
-
node.style.filter = "brightness(110%) drop-shadow(0px 0px 2px ".concat(colors.highlight, " )");
|
|
2432
|
+
var rectEle = getOptimizedBoundingRectEle(node);
|
|
2433
|
+
if (!item.highlightBox) {
|
|
2434
|
+
var box = HighlightBox(rectEle, colors.warning);
|
|
2435
|
+
document.body.appendChild(box);
|
|
2436
|
+
item.highlightBox = box;
|
|
2368
2437
|
}
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2438
|
+
}
|
|
2439
|
+
function selectedHighlight(item, node, keys) {
|
|
2440
|
+
var id = item.id;
|
|
2441
|
+
var rectEle = getOptimizedBoundingRectEle(node);
|
|
2442
|
+
if (!item.highlightBox) {
|
|
2443
|
+
var box = HighlightBox(rectEle, colors.highlight, colors.gray);
|
|
2444
|
+
document.body.appendChild(box);
|
|
2445
|
+
item.highlightBox = box;
|
|
2372
2446
|
}
|
|
2373
2447
|
selected[id] = true;
|
|
2374
2448
|
}
|
|
2449
|
+
function recalcSelectedHighlight(item, node, keys) {
|
|
2450
|
+
if (!selected[item.id]) return;
|
|
2451
|
+
resetHighlight(item, node, keys, false);
|
|
2452
|
+
selectedHighlight(item, node);
|
|
2453
|
+
}
|
|
2375
2454
|
function resetHighlight(item, node, keys) {
|
|
2376
2455
|
var ignoreSelected = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
|
|
2377
2456
|
var id = item.id;
|
|
2378
2457
|
if (ignoreSelected && selected[id]) return;
|
|
2379
|
-
if (
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
});
|
|
2383
|
-
delete originalStyles[id];
|
|
2458
|
+
if (item.highlightBox) {
|
|
2459
|
+
document.body.removeChild(item.highlightBox);
|
|
2460
|
+
delete item.highlightBox;
|
|
2384
2461
|
}
|
|
2385
2462
|
if (item.ribbonBox) {
|
|
2386
2463
|
document.body.removeChild(item.ribbonBox);
|
|
@@ -2409,6 +2486,7 @@
|
|
|
2409
2486
|
subliminal: subliminal
|
|
2410
2487
|
};
|
|
2411
2488
|
}
|
|
2489
|
+
if (subliminal) data[id].subliminal = subliminal;
|
|
2412
2490
|
data[id].keys = _objectSpread$4(_objectSpread$4({}, data[id].keys), {}, _defineProperty({}, "".concat(type), meta));
|
|
2413
2491
|
if (children) {
|
|
2414
2492
|
data[id].children = _objectSpread$4(_objectSpread$4({}, data[id].children), {}, _defineProperty({}, "".concat(type, "-").concat(children.map(function (c) {
|
|
@@ -2467,35 +2545,84 @@
|
|
|
2467
2545
|
function walk(node, func) {
|
|
2468
2546
|
if (node.dataset && node.dataset.i18nextEditorElement === 'true') return;
|
|
2469
2547
|
func(node);
|
|
2548
|
+
var instr = store.get(node.uniqueID);
|
|
2549
|
+
var uninstr = uninstrumentedStore.get(node.uniqueID);
|
|
2550
|
+
if (instr || uninstr) {
|
|
2551
|
+
var _node$parentElement;
|
|
2552
|
+
var id = (_node$parentElement = node.parentElement) === null || _node$parentElement === void 0 ? void 0 : _node$parentElement.uniqueID;
|
|
2553
|
+
uninstrumentedStore.remove(id, node.parentElement);
|
|
2554
|
+
}
|
|
2470
2555
|
var children = node.childNodes;
|
|
2471
|
-
for (var
|
|
2472
|
-
walk(children[
|
|
2556
|
+
for (var _i = 0; _i < children.length; _i++) {
|
|
2557
|
+
walk(children[_i], func);
|
|
2473
2558
|
}
|
|
2474
2559
|
}
|
|
2475
|
-
function
|
|
2476
|
-
var _i18n, _i18n2;
|
|
2560
|
+
function extractHiddenMeta(id, type, meta, children) {
|
|
2561
|
+
var _i18n, _i18n2, _i18n3;
|
|
2477
2562
|
var invisibleMeta = meta.invisibleMeta,
|
|
2478
2563
|
text = meta.text;
|
|
2479
2564
|
if (!invisibleMeta || !invisibleMeta.key || !invisibleMeta.ns) return;
|
|
2480
|
-
if (!currentSourceLng) currentSourceLng =
|
|
2565
|
+
if (!currentSourceLng) currentSourceLng = i18n.getSourceLng();
|
|
2481
2566
|
return _objectSpread$3(_objectSpread$3({
|
|
2482
2567
|
eleUniqueID: id,
|
|
2483
2568
|
textType: type,
|
|
2484
|
-
children: children ? children.map(function (c) {
|
|
2569
|
+
children: children && children.map ? children.map(function (c) {
|
|
2485
2570
|
return c.childIndex;
|
|
2486
2571
|
}).join(',') : null,
|
|
2487
2572
|
qualifiedKey: "".concat(invisibleMeta.ns, ":").concat(invisibleMeta.key)
|
|
2488
2573
|
}, invisibleMeta), {}, {
|
|
2489
2574
|
extractedText: text,
|
|
2490
|
-
i18nTargetLng: (
|
|
2575
|
+
i18nTargetLng: (_i18n = i18n) === null || _i18n === void 0 ? void 0 : _i18n.getLng(),
|
|
2491
2576
|
i18nSourceLng: currentSourceLng,
|
|
2492
|
-
i18nRawText: _defineProperty(_defineProperty({}, "".concat(invisibleMeta.lng), invisibleMeta.source === 'translation' && i18n ? i18n.getResource(invisibleMeta.lng, invisibleMeta.ns, invisibleMeta.key) : null), "".concat(currentSourceLng), invisibleMeta.source === 'translation' && i18n ? i18n.getResource(currentSourceLng, invisibleMeta.ns, invisibleMeta.key) : null)
|
|
2577
|
+
i18nRawText: _defineProperty(_defineProperty({}, "".concat(invisibleMeta.lng), invisibleMeta.source === 'translation' && i18n ? (_i18n2 = i18n) === null || _i18n2 === void 0 ? void 0 : _i18n2.getResource(invisibleMeta.lng, invisibleMeta.ns, invisibleMeta.key) : null), "".concat(currentSourceLng), invisibleMeta.source === 'translation' && i18n ? (_i18n3 = i18n) === null || _i18n3 === void 0 ? void 0 : _i18n3.getResource(currentSourceLng, invisibleMeta.ns, invisibleMeta.key) : null)
|
|
2493
2578
|
});
|
|
2494
2579
|
}
|
|
2580
|
+
function extractNodeMeta(id, type) {
|
|
2581
|
+
var _i18n4, _i18n5, _i18n6, _i18n7, _i18n8;
|
|
2582
|
+
var nodeMeta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
2583
|
+
var text = arguments.length > 3 ? arguments[3] : undefined;
|
|
2584
|
+
var children = arguments.length > 4 ? arguments[4] : undefined;
|
|
2585
|
+
var meta = nodeMeta[type];
|
|
2586
|
+
if (!meta) return;
|
|
2587
|
+
if (!currentSourceLng) currentSourceLng = i18n.getSourceLng();
|
|
2588
|
+
var i18nTargetLng = i18n.getLng();
|
|
2589
|
+
return {
|
|
2590
|
+
eleUniqueID: id,
|
|
2591
|
+
textType: type,
|
|
2592
|
+
children: children && children.map ? children.map(function (c) {
|
|
2593
|
+
return c.childIndex;
|
|
2594
|
+
}).join(',') : null,
|
|
2595
|
+
qualifiedKey: meta.key && (meta.ns || (_i18n4 = i18n) !== null && _i18n4 !== void 0 && _i18n4.getDefaultNS()) ? "".concat(meta.ns || ((_i18n5 = i18n) === null || _i18n5 === void 0 ? void 0 : _i18n5.getDefaultNS()), ":").concat(meta.key) : null,
|
|
2596
|
+
key: meta.key,
|
|
2597
|
+
ns: meta.ns || ((_i18n6 = i18n) === null || _i18n6 === void 0 ? void 0 : _i18n6.getDefaultNS()),
|
|
2598
|
+
extractedText: text,
|
|
2599
|
+
i18nTargetLng: i18nTargetLng,
|
|
2600
|
+
i18nSourceLng: currentSourceLng,
|
|
2601
|
+
i18nRawText: _defineProperty(_defineProperty({}, "".concat(i18nTargetLng), i18n && meta.ns && meta.key ? ((_i18n7 = i18n) === null || _i18n7 === void 0 ? void 0 : _i18n7.getResource(i18nTargetLng, meta.ns, meta.key)) || text : text), "".concat(currentSourceLng), i18n && meta.ns && meta.key ? (_i18n8 = i18n) === null || _i18n8 === void 0 ? void 0 : _i18n8.getResource(currentSourceLng, meta.ns, meta.key) : null)
|
|
2602
|
+
};
|
|
2603
|
+
}
|
|
2495
2604
|
function containsOnlySpaces(str) {
|
|
2496
2605
|
return /^\s*$/.test(str);
|
|
2497
2606
|
}
|
|
2607
|
+
function storeIfQualifiedKey(id, subliminal, type, nodeI18nMeta, node, children, txt) {
|
|
2608
|
+
var stored = store.get(id);
|
|
2609
|
+
var storedMeta = stored && stored.keys["".concat(type)] || {};
|
|
2610
|
+
var typeMeta = nodeI18nMeta["".concat(type)] || {};
|
|
2611
|
+
if (!typeMeta.key && storedMeta.key) typeMeta.key = storedMeta.key;
|
|
2612
|
+
if (!typeMeta.ns && storedMeta.ns) typeMeta.ns = storedMeta.ns;
|
|
2613
|
+
nodeI18nMeta["".concat(type)] = typeMeta;
|
|
2614
|
+
var meta = extractNodeMeta(id, type, nodeI18nMeta, txt, children);
|
|
2615
|
+
if (meta.qualifiedKey) {
|
|
2616
|
+
store.save(id, null, type, meta, node, children);
|
|
2617
|
+
uninstrumentedStore.removeKey(i, type, node);
|
|
2618
|
+
} else {
|
|
2619
|
+
uninstrumentedStore.save(id, type, node, txt);
|
|
2620
|
+
}
|
|
2621
|
+
}
|
|
2498
2622
|
function handleNode(node) {
|
|
2623
|
+
if (ignoreElements.indexOf(node.nodeName) > -1) return;
|
|
2624
|
+
var nodeI18nMeta = getI18nMetaFromNode(node);
|
|
2625
|
+
var usedSubliminalForText = false;
|
|
2499
2626
|
if (node.childNodes && !ignoreMergedEleUniqueIds.includes(node.uniqueID)) {
|
|
2500
2627
|
var merge = [];
|
|
2501
2628
|
node.childNodes.forEach(function (child, i) {
|
|
@@ -2511,9 +2638,11 @@
|
|
|
2511
2638
|
if (containsOnlySpaces(txt)) return;
|
|
2512
2639
|
var hasHiddenMeta = containsHiddenMeta(txt);
|
|
2513
2640
|
var hasHiddenStartMarker = containsHiddenStartMarker(txt);
|
|
2641
|
+
if (hasHiddenMeta) usedSubliminalForText = true;
|
|
2514
2642
|
if (hasHiddenStartMarker && hasHiddenMeta) {
|
|
2515
2643
|
var meta = unwrap(txt);
|
|
2516
|
-
|
|
2644
|
+
uninstrumentedStore.remove(node.uniqueID, node);
|
|
2645
|
+
store.save(node.uniqueID, meta.invisibleMeta, 'text', extractHiddenMeta(node.uniqueID, 'text', meta), node);
|
|
2517
2646
|
} else if (hasHiddenStartMarker) {
|
|
2518
2647
|
merge.push({
|
|
2519
2648
|
childIndex: i,
|
|
@@ -2535,21 +2664,54 @@
|
|
|
2535
2664
|
var _meta = unwrap(merge.reduce(function (mem, item) {
|
|
2536
2665
|
return mem + item.text;
|
|
2537
2666
|
}, ''));
|
|
2538
|
-
|
|
2667
|
+
uninstrumentedStore.removeKey(node.uniqueID, 'html', node, txt);
|
|
2668
|
+
store.save(node.uniqueID, _meta.invisibleMeta, 'html', extractHiddenMeta(node.uniqueID, 'html', _meta, merge), node, merge);
|
|
2539
2669
|
merge = [];
|
|
2540
|
-
} else if (txt) {
|
|
2541
|
-
uninstrumentedStore.save(node.uniqueID, 'text', node);
|
|
2542
2670
|
}
|
|
2543
2671
|
});
|
|
2672
|
+
if (!usedSubliminalForText) {
|
|
2673
|
+
node.childNodes.forEach(function (child, i) {
|
|
2674
|
+
if (merge.length && child.nodeName !== '#text') {
|
|
2675
|
+
ignoreMergedEleUniqueIds.push(child.uniqueID);
|
|
2676
|
+
}
|
|
2677
|
+
var txt = child.textContent;
|
|
2678
|
+
if (nodeI18nMeta && nodeI18nMeta['html'] && i < node.childNodes.length - 1) {
|
|
2679
|
+
merge.push({
|
|
2680
|
+
childIndex: i,
|
|
2681
|
+
child: child,
|
|
2682
|
+
text: txt
|
|
2683
|
+
});
|
|
2684
|
+
} else if (nodeI18nMeta && nodeI18nMeta['html'] && i === node.childNodes.length - 1) {
|
|
2685
|
+
merge.push({
|
|
2686
|
+
childIndex: i,
|
|
2687
|
+
child: child,
|
|
2688
|
+
text: txt
|
|
2689
|
+
});
|
|
2690
|
+
storeIfQualifiedKey(node.uniqueID, null, 'html', nodeI18nMeta, node, merge, node.innerHTML);
|
|
2691
|
+
merge = [];
|
|
2692
|
+
} else if (txt) {
|
|
2693
|
+
if (nodeI18nMeta && nodeI18nMeta['text']) {
|
|
2694
|
+
storeIfQualifiedKey(node.uniqueID, null, 'text', nodeI18nMeta, node, undefined, txt);
|
|
2695
|
+
} else if (child.nodeName === '#text' && !containsOnlySpaces(txt)) {
|
|
2696
|
+
uninstrumentedStore.save(node.uniqueID, 'text', node, txt);
|
|
2697
|
+
}
|
|
2698
|
+
}
|
|
2699
|
+
});
|
|
2700
|
+
}
|
|
2544
2701
|
}
|
|
2545
2702
|
if (!node.getAttribute) return;
|
|
2546
2703
|
validAttributes.forEach(function (attr) {
|
|
2547
2704
|
var txt = node.getAttribute(attr);
|
|
2548
2705
|
if (containsHiddenMeta(txt)) {
|
|
2549
2706
|
var meta = unwrap(txt);
|
|
2550
|
-
|
|
2707
|
+
uninstrumentedStore.removeKey(node.uniqueID, attr, node);
|
|
2708
|
+
store.save(node.uniqueID, meta.invisibleMeta, attr, extractHiddenMeta(node.uniqueID, "".concat(attr), meta), node);
|
|
2551
2709
|
} else if (txt) {
|
|
2552
|
-
|
|
2710
|
+
if (nodeI18nMeta && nodeI18nMeta[attr]) {
|
|
2711
|
+
storeIfQualifiedKey(node.uniqueID, null, attr, nodeI18nMeta, node, undefined, txt);
|
|
2712
|
+
} else {
|
|
2713
|
+
uninstrumentedStore.save(node.uniqueID, attr, node, txt);
|
|
2714
|
+
}
|
|
2553
2715
|
}
|
|
2554
2716
|
});
|
|
2555
2717
|
}
|
|
@@ -2653,6 +2815,7 @@
|
|
|
2653
2815
|
characterData: true,
|
|
2654
2816
|
subtree: true
|
|
2655
2817
|
};
|
|
2818
|
+
handle([ele]);
|
|
2656
2819
|
observer.observe(ele, observerConfig);
|
|
2657
2820
|
},
|
|
2658
2821
|
skipNext: function skipNext() {
|
|
@@ -2708,6 +2871,11 @@
|
|
|
2708
2871
|
function closeDragElement() {
|
|
2709
2872
|
startMouseTracking();
|
|
2710
2873
|
if (overlay) overlay.style.display = 'none';
|
|
2874
|
+
var ele = document.getElementById('i18next-editor-popup');
|
|
2875
|
+
localStorage.setItem('locize_popup_pos', JSON.stringify({
|
|
2876
|
+
top: parseInt(document.defaultView.getComputedStyle(ele).top, 10),
|
|
2877
|
+
left: parseInt(document.defaultView.getComputedStyle(ele).left, 10)
|
|
2878
|
+
}));
|
|
2711
2879
|
document.onmouseup = null;
|
|
2712
2880
|
document.onmousemove = null;
|
|
2713
2881
|
}
|
|
@@ -2761,6 +2929,11 @@
|
|
|
2761
2929
|
function stopDrag() {
|
|
2762
2930
|
startMouseTracking();
|
|
2763
2931
|
if (overlay) overlay.style.display = 'none';
|
|
2932
|
+
var ele = document.getElementById('i18next-editor-popup');
|
|
2933
|
+
localStorage.setItem('locize_popup_size', JSON.stringify({
|
|
2934
|
+
width: parseInt(document.defaultView.getComputedStyle(ele).width, 10),
|
|
2935
|
+
height: parseInt(document.defaultView.getComputedStyle(ele).height, 10)
|
|
2936
|
+
}));
|
|
2764
2937
|
document.documentElement.removeEventListener('mousemove', doDrag, false);
|
|
2765
2938
|
document.documentElement.removeEventListener('mouseup', stopDrag, false);
|
|
2766
2939
|
}
|
|
@@ -2768,9 +2941,130 @@
|
|
|
2768
2941
|
|
|
2769
2942
|
function ownKeys$2(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
2770
2943
|
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
2944
|
+
function getImplementation$1(i18n) {
|
|
2945
|
+
var impl = {
|
|
2946
|
+
getResource: function getResource(lng, ns, key) {
|
|
2947
|
+
return i18n.getResource && i18n.getResource(lng, ns, key);
|
|
2948
|
+
},
|
|
2949
|
+
setResource: function setResource(lng, ns, key, value) {
|
|
2950
|
+
return i18n.addResource(lng, ns, key, value, {
|
|
2951
|
+
silent: true
|
|
2952
|
+
});
|
|
2953
|
+
},
|
|
2954
|
+
getResourceBundle: function getResourceBundle(lng, ns, cb) {
|
|
2955
|
+
i18n.loadNamespaces(ns, function () {
|
|
2956
|
+
cb(i18n.getResourceBundle(lng, ns));
|
|
2957
|
+
});
|
|
2958
|
+
},
|
|
2959
|
+
getDefaultNS: function getDefaultNS() {
|
|
2960
|
+
return i18n.options.defaultNS;
|
|
2961
|
+
},
|
|
2962
|
+
getLng: function getLng() {
|
|
2963
|
+
return i18n.resolvedLanguage || i18n.languages && i18n.languages[0] || i18n.options.lng;
|
|
2964
|
+
},
|
|
2965
|
+
getSourceLng: function getSourceLng() {
|
|
2966
|
+
var fallback = i18n.options.fallbackLng;
|
|
2967
|
+
if (typeof fallback === 'string') return fallback;
|
|
2968
|
+
if (Array.isArray(fallback)) return fallback[fallback.length - 1];
|
|
2969
|
+
if (fallback && fallback["default"]) {
|
|
2970
|
+
if (typeof fallback["default"] === 'string') return fallback;
|
|
2971
|
+
if (Array.isArray(fallback["default"])) return fallback["default"][fallback["default"].length - 1];
|
|
2972
|
+
}
|
|
2973
|
+
if (typeof fallback === 'function') {
|
|
2974
|
+
var res = fallback(i18n.resolvedLanguage);
|
|
2975
|
+
if (typeof res === 'string') return res;
|
|
2976
|
+
if (Array.isArray(res)) return res[res.length - 1];
|
|
2977
|
+
}
|
|
2978
|
+
return 'dev';
|
|
2979
|
+
},
|
|
2980
|
+
getLocizeDetails: function getLocizeDetails() {
|
|
2981
|
+
var backendName;
|
|
2982
|
+
if (i18n.services.backendConnector.backend && i18n.services.backendConnector.backend.options && i18n.services.backendConnector.backend.options.loadPath && i18n.services.backendConnector.backend.options.loadPath.indexOf('.locize.') > 0) {
|
|
2983
|
+
backendName = 'I18nextLocizeBackend';
|
|
2984
|
+
} else {
|
|
2985
|
+
backendName = i18n.services.backendConnector.backend ? i18n.services.backendConnector.backend.constructor.name : 'options.resources';
|
|
2986
|
+
}
|
|
2987
|
+
var opts = {
|
|
2988
|
+
backendName: backendName,
|
|
2989
|
+
sourceLng: impl.getSourceLng(),
|
|
2990
|
+
i18nFormat: i18n.options.compatibilityJSON === 'v3' ? 'i18next_v3' : 'i18next_v4',
|
|
2991
|
+
i18nFramework: 'i18next',
|
|
2992
|
+
isLocizify: i18n.options.isLocizify,
|
|
2993
|
+
defaultNS: i18n.options.defaultNS,
|
|
2994
|
+
targetLngs: _toConsumableArray(new Set([].concat(i18n.options.preload, i18n.options.supportedLngs, [impl.getLng()]))).filter(function (l) {
|
|
2995
|
+
return l !== 'cimode' && l !== false && l !== 'false' && l !== undefined && l !== impl.getSourceLng();
|
|
2996
|
+
}),
|
|
2997
|
+
ns: _toConsumableArray(new Set([].concat(i18n.options.ns, i18n.options.fallbackNS, i18n.options.defaultNS))).filter(function (n) {
|
|
2998
|
+
return n !== false && n !== 'false';
|
|
2999
|
+
})
|
|
3000
|
+
};
|
|
3001
|
+
if (!i18n.options.backend && !i18n.options.editor) return opts;
|
|
3002
|
+
var pickFrom = i18n.options.editor || i18n.options.backend;
|
|
3003
|
+
return _objectSpread$2(_objectSpread$2({}, opts), {}, {
|
|
3004
|
+
projectId: pickFrom.projectId,
|
|
3005
|
+
version: pickFrom.version
|
|
3006
|
+
});
|
|
3007
|
+
},
|
|
3008
|
+
bindLanguageChange: function bindLanguageChange(cb) {
|
|
3009
|
+
i18n.on('languageChanged', cb);
|
|
3010
|
+
},
|
|
3011
|
+
bindMissingKeyHandler: function bindMissingKeyHandler(cb) {
|
|
3012
|
+
i18n.options.missingKeyHandler = function (lng, ns, k, val, isUpdate, opts) {
|
|
3013
|
+
if (!isUpdate) cb(lng, ns, k, val);
|
|
3014
|
+
};
|
|
3015
|
+
},
|
|
3016
|
+
triggerRerender: function triggerRerender() {
|
|
3017
|
+
i18n.emit('editorSaved');
|
|
3018
|
+
}
|
|
3019
|
+
};
|
|
3020
|
+
return impl;
|
|
3021
|
+
}
|
|
3022
|
+
|
|
3023
|
+
function getImplementation() {
|
|
3024
|
+
var impl = {
|
|
3025
|
+
getResource: function getResource(lng, ns, key) {
|
|
3026
|
+
return {};
|
|
3027
|
+
},
|
|
3028
|
+
setResource: function setResource(lng, ns, key, value) {
|
|
3029
|
+
return;
|
|
3030
|
+
},
|
|
3031
|
+
getResourceBundle: function getResourceBundle(lng, ns, cb) {
|
|
3032
|
+
cb({});
|
|
3033
|
+
},
|
|
3034
|
+
getDefaultNS: function getDefaultNS() {
|
|
3035
|
+
return;
|
|
3036
|
+
},
|
|
3037
|
+
getLng: function getLng() {
|
|
3038
|
+
return;
|
|
3039
|
+
},
|
|
3040
|
+
getSourceLng: function getSourceLng() {
|
|
3041
|
+
return;
|
|
3042
|
+
},
|
|
3043
|
+
getLocizeDetails: function getLocizeDetails() {
|
|
3044
|
+
return {};
|
|
3045
|
+
},
|
|
3046
|
+
bindLanguageChange: function bindLanguageChange(cb) {},
|
|
3047
|
+
bindMissingKeyHandler: function bindMissingKeyHandler(cb) {},
|
|
3048
|
+
triggerRerender: function triggerRerender() {}
|
|
3049
|
+
};
|
|
3050
|
+
return impl;
|
|
3051
|
+
}
|
|
3052
|
+
|
|
3053
|
+
function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3054
|
+
function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
3055
|
+
var dummyImplementation = getImplementation();
|
|
3056
|
+
var isInIframe = typeof window !== 'undefined';
|
|
3057
|
+
try {
|
|
3058
|
+
isInIframe = self !== top;
|
|
3059
|
+
} catch (e) {}
|
|
2771
3060
|
function start() {
|
|
2772
|
-
var implementation = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] :
|
|
3061
|
+
var implementation = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : dummyImplementation;
|
|
3062
|
+
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
3063
|
+
show: false,
|
|
3064
|
+
qsProp: 'incontext'
|
|
3065
|
+
};
|
|
2773
3066
|
if (typeof document === 'undefined') return;
|
|
3067
|
+
var showInContext = opt.show || getQsParameterByName(opt.qsProp) === 'true';
|
|
2774
3068
|
var scriptEle = document.getElementById('locize');
|
|
2775
3069
|
var config = {};
|
|
2776
3070
|
['projectId', 'version'].forEach(function (attr) {
|
|
@@ -2780,13 +3074,15 @@
|
|
|
2780
3074
|
if (value === 'false') value = false;
|
|
2781
3075
|
if (value !== undefined && value !== null) config[attr] = value;
|
|
2782
3076
|
});
|
|
2783
|
-
config = _objectSpread$
|
|
3077
|
+
config = _objectSpread$1(_objectSpread$1(_objectSpread$1({}, implementation.getLocizeDetails()), config), opt);
|
|
3078
|
+
api.config = config;
|
|
2784
3079
|
api.init(implementation);
|
|
2785
3080
|
setImplementation(implementation);
|
|
2786
3081
|
implementation === null || implementation === void 0 || implementation.bindLanguageChange(function (lng) {
|
|
2787
3082
|
api.sendCurrentTargetLanguage(implementation.getLng());
|
|
2788
3083
|
});
|
|
2789
3084
|
function continueToStart() {
|
|
3085
|
+
if (!isInIframe && !showInContext) return;
|
|
2790
3086
|
var observer = createObserver(document.body, function (eles) {
|
|
2791
3087
|
eles.forEach(function (ele) {
|
|
2792
3088
|
parseTree(ele);
|
|
@@ -2795,13 +3091,31 @@
|
|
|
2795
3091
|
});
|
|
2796
3092
|
observer.start();
|
|
2797
3093
|
startMouseTracking(observer);
|
|
2798
|
-
if (!document.getElementById(popupId)) {
|
|
3094
|
+
if (!isInIframe && !document.getElementById(popupId)) {
|
|
2799
3095
|
document.body.append(Popup(getIframeUrl(), function () {
|
|
2800
3096
|
api.requestInitialize(config);
|
|
2801
3097
|
}));
|
|
2802
3098
|
initDragElement();
|
|
2803
3099
|
initResizeElement();
|
|
2804
3100
|
}
|
|
3101
|
+
if (typeof window !== 'undefined') {
|
|
3102
|
+
var oldHref = window.document.location.href;
|
|
3103
|
+
api.sendHrefchanged(oldHref);
|
|
3104
|
+
var bodyList = window.document.querySelector('body');
|
|
3105
|
+
var _observer = new window.MutationObserver(function (mutations) {
|
|
3106
|
+
mutations.forEach(function (mutation) {
|
|
3107
|
+
if (oldHref !== window.document.location.href) {
|
|
3108
|
+
oldHref = window.document.location.href;
|
|
3109
|
+
api.sendHrefchanged(oldHref);
|
|
3110
|
+
}
|
|
3111
|
+
});
|
|
3112
|
+
});
|
|
3113
|
+
var _config = {
|
|
3114
|
+
childList: true,
|
|
3115
|
+
subtree: true
|
|
3116
|
+
};
|
|
3117
|
+
_observer.observe(bodyList, _config);
|
|
3118
|
+
}
|
|
2805
3119
|
}
|
|
2806
3120
|
if (document.body) return continueToStart();
|
|
2807
3121
|
window.addEventListener('load', function () {
|
|
@@ -2809,6 +3123,34 @@
|
|
|
2809
3123
|
});
|
|
2810
3124
|
}
|
|
2811
3125
|
|
|
3126
|
+
function configurePostProcessor(i18next, options) {
|
|
3127
|
+
i18next.use(SubliminalPostProcessor);
|
|
3128
|
+
if (typeof options.postProcess === 'string') {
|
|
3129
|
+
options.postProcess = [options.postProcess, 'subliminal'];
|
|
3130
|
+
} else if (Array.isArray(options.postProcess)) {
|
|
3131
|
+
options.postProcess.push('subliminal');
|
|
3132
|
+
} else {
|
|
3133
|
+
options.postProcess = 'subliminal';
|
|
3134
|
+
}
|
|
3135
|
+
options.postProcessPassResolved = true;
|
|
3136
|
+
}
|
|
3137
|
+
var i18next;
|
|
3138
|
+
var locizeEditorPlugin = function locizeEditorPlugin() {
|
|
3139
|
+
var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
3140
|
+
opt.qsProp = opt.qsProp || 'incontext';
|
|
3141
|
+
return {
|
|
3142
|
+
type: '3rdParty',
|
|
3143
|
+
init: function init(i18n) {
|
|
3144
|
+
var options = i18n.options;
|
|
3145
|
+
i18next = i18n;
|
|
3146
|
+
var impl = getImplementation$1(i18n);
|
|
3147
|
+
configurePostProcessor(i18next, options);
|
|
3148
|
+
start(impl, opt);
|
|
3149
|
+
}
|
|
3150
|
+
};
|
|
3151
|
+
};
|
|
3152
|
+
var locizePlugin = locizeEditorPlugin();
|
|
3153
|
+
|
|
2812
3154
|
function createClickHandler(cb) {
|
|
2813
3155
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2814
3156
|
var handler = function handler(e) {
|
|
@@ -2856,8 +3198,8 @@
|
|
|
2856
3198
|
return handler;
|
|
2857
3199
|
}
|
|
2858
3200
|
|
|
2859
|
-
function ownKeys
|
|
2860
|
-
function _objectSpread
|
|
3201
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3202
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
2861
3203
|
function startLegacy() {
|
|
2862
3204
|
var implementation = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2863
3205
|
if (typeof document === 'undefined') return;
|
|
@@ -2870,7 +3212,7 @@
|
|
|
2870
3212
|
if (value === 'false') value = false;
|
|
2871
3213
|
if (value !== undefined && value !== null) config[attr] = value;
|
|
2872
3214
|
});
|
|
2873
|
-
config = _objectSpread
|
|
3215
|
+
config = _objectSpread(_objectSpread({}, implementation.getLocizeDetails()), config);
|
|
2874
3216
|
api.init(implementation, createClickHandler(function (payload) {
|
|
2875
3217
|
sendMessage('clickedElement', {
|
|
2876
3218
|
payload: payload
|
|
@@ -2913,114 +3255,6 @@
|
|
|
2913
3255
|
});
|
|
2914
3256
|
}
|
|
2915
3257
|
|
|
2916
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
2917
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
2918
|
-
var isInIframe = typeof window !== 'undefined';
|
|
2919
|
-
try {
|
|
2920
|
-
isInIframe = self !== top;
|
|
2921
|
-
} catch (e) {}
|
|
2922
|
-
function configurePostProcessor(i18next, options) {
|
|
2923
|
-
i18next.use(SubliminalPostProcessor);
|
|
2924
|
-
if (typeof options.postProcess === 'string') {
|
|
2925
|
-
options.postProcess = [options.postProcess, 'subliminal'];
|
|
2926
|
-
} else if (Array.isArray(options.postProcess)) {
|
|
2927
|
-
options.postProcess.push('subliminal');
|
|
2928
|
-
} else {
|
|
2929
|
-
options.postProcess = 'subliminal';
|
|
2930
|
-
}
|
|
2931
|
-
options.postProcessPassResolved = true;
|
|
2932
|
-
}
|
|
2933
|
-
function getImplementation(i18n) {
|
|
2934
|
-
var impl = {
|
|
2935
|
-
getResource: function getResource(lng, ns, key) {
|
|
2936
|
-
return i18n.getResource(lng, ns, key);
|
|
2937
|
-
},
|
|
2938
|
-
setResource: function setResource(lng, ns, key, value) {
|
|
2939
|
-
return i18n.addResource(lng, ns, key, value, {
|
|
2940
|
-
silent: true
|
|
2941
|
-
});
|
|
2942
|
-
},
|
|
2943
|
-
getResourceBundle: function getResourceBundle(lng, ns, cb) {
|
|
2944
|
-
i18n.loadNamespaces(ns, function () {
|
|
2945
|
-
cb(i18n.getResourceBundle(lng, ns));
|
|
2946
|
-
});
|
|
2947
|
-
},
|
|
2948
|
-
getLng: function getLng() {
|
|
2949
|
-
return i18n.resolvedLanguage || i18n.languages[0];
|
|
2950
|
-
},
|
|
2951
|
-
getSourceLng: function getSourceLng() {
|
|
2952
|
-
var fallback = i18n.options.fallbackLng;
|
|
2953
|
-
if (typeof fallback === 'string') return fallback;
|
|
2954
|
-
if (Array.isArray(fallback)) return fallback[fallback.length - 1];
|
|
2955
|
-
if (fallback && fallback["default"]) {
|
|
2956
|
-
if (typeof fallback["default"] === 'string') return fallback;
|
|
2957
|
-
if (Array.isArray(fallback["default"])) return fallback["default"][fallback["default"].length - 1];
|
|
2958
|
-
}
|
|
2959
|
-
if (typeof fallback === 'function') {
|
|
2960
|
-
var res = fallback(i18n.resolvedLanguage);
|
|
2961
|
-
if (typeof res === 'string') return res;
|
|
2962
|
-
if (Array.isArray(res)) return res[res.length - 1];
|
|
2963
|
-
}
|
|
2964
|
-
return 'dev';
|
|
2965
|
-
},
|
|
2966
|
-
getLocizeDetails: function getLocizeDetails() {
|
|
2967
|
-
var backendName;
|
|
2968
|
-
if (i18n.services.backendConnector.backend && i18n.services.backendConnector.backend.options && i18n.services.backendConnector.backend.options.loadPath && i18n.services.backendConnector.backend.options.loadPath.indexOf('.locize.') > 0) {
|
|
2969
|
-
backendName = 'I18NextLocizeBackend';
|
|
2970
|
-
} else {
|
|
2971
|
-
backendName = i18n.services.backendConnector.backend ? i18n.services.backendConnector.backend.constructor.name : 'options.resources';
|
|
2972
|
-
}
|
|
2973
|
-
var opts = {
|
|
2974
|
-
backendName: backendName,
|
|
2975
|
-
sourceLng: impl.getSourceLng(),
|
|
2976
|
-
i18nFormat: i18n.options.compatibilityJSON === 'v3' ? 'i18next_v3' : 'i18next_v4',
|
|
2977
|
-
i18nFramework: 'i18next',
|
|
2978
|
-
isLocizify: i18n.options.isLocizify,
|
|
2979
|
-
defaultNS: i18n.options.defaultNS
|
|
2980
|
-
};
|
|
2981
|
-
if (!i18n.options.backend && !i18n.options.editor) return opts;
|
|
2982
|
-
var pickFrom = i18n.options.backend || i18n.options.editor;
|
|
2983
|
-
return _objectSpread(_objectSpread({}, opts), {}, {
|
|
2984
|
-
projectId: pickFrom.projectId,
|
|
2985
|
-
version: pickFrom.version
|
|
2986
|
-
});
|
|
2987
|
-
},
|
|
2988
|
-
bindLanguageChange: function bindLanguageChange(cb) {
|
|
2989
|
-
i18n.on('languageChanged', cb);
|
|
2990
|
-
},
|
|
2991
|
-
bindMissingKeyHandler: function bindMissingKeyHandler(cb) {
|
|
2992
|
-
i18n.options.missingKeyHandler = function (lng, ns, k, val, isUpdate, opts) {
|
|
2993
|
-
if (!isUpdate) cb(lng, ns, k, val);
|
|
2994
|
-
};
|
|
2995
|
-
},
|
|
2996
|
-
triggerRerender: function triggerRerender() {
|
|
2997
|
-
i18n.emit('editorSaved');
|
|
2998
|
-
}
|
|
2999
|
-
};
|
|
3000
|
-
return impl;
|
|
3001
|
-
}
|
|
3002
|
-
var i18next;
|
|
3003
|
-
var locizeEditorPlugin = function locizeEditorPlugin() {
|
|
3004
|
-
var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
3005
|
-
opt.qsProp = opt.qsProp || 'incontext';
|
|
3006
|
-
return {
|
|
3007
|
-
type: '3rdParty',
|
|
3008
|
-
init: function init(i18n) {
|
|
3009
|
-
var options = i18n.options;
|
|
3010
|
-
i18next = i18n;
|
|
3011
|
-
var showInContext = opt.show || getQsParameterByName(opt.qsProp) === 'true';
|
|
3012
|
-
if (!isInIframe && showInContext) configurePostProcessor(i18next, options);
|
|
3013
|
-
var impl = getImplementation(i18n);
|
|
3014
|
-
if (!isInIframe && showInContext) {
|
|
3015
|
-
start(impl);
|
|
3016
|
-
} else if (isInIframe) {
|
|
3017
|
-
startLegacy(impl);
|
|
3018
|
-
}
|
|
3019
|
-
}
|
|
3020
|
-
};
|
|
3021
|
-
};
|
|
3022
|
-
var locizePlugin = locizeEditorPlugin();
|
|
3023
|
-
|
|
3024
3258
|
function startStandalone() {
|
|
3025
3259
|
startLegacy({
|
|
3026
3260
|
getLocizeDetails: function getLocizeDetails() {
|
|
@@ -3048,8 +3282,6 @@
|
|
|
3048
3282
|
addLocizeSavedHandler: addLocizeSavedHandler,
|
|
3049
3283
|
locizePlugin: locizePlugin,
|
|
3050
3284
|
locizeEditorPlugin: locizeEditorPlugin,
|
|
3051
|
-
turnOn: turnOn,
|
|
3052
|
-
turnOff: turnOff,
|
|
3053
3285
|
setEditorLng: setEditorLng,
|
|
3054
3286
|
startStandalone: startStandalone
|
|
3055
3287
|
};
|
|
@@ -3062,8 +3294,6 @@
|
|
|
3062
3294
|
exports.locizePlugin = locizePlugin;
|
|
3063
3295
|
exports.setEditorLng = setEditorLng;
|
|
3064
3296
|
exports.startStandalone = startStandalone;
|
|
3065
|
-
exports.turnOff = turnOff;
|
|
3066
|
-
exports.turnOn = turnOn;
|
|
3067
3297
|
exports.unwrap = unwrap;
|
|
3068
3298
|
exports.wrap = wrap;
|
|
3069
3299
|
|