@tolgee/core 1.2.4 → 1.5.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.
Files changed (59) hide show
  1. package/dist/tolgee.cjs.js +558 -156
  2. package/dist/tolgee.cjs.js.map +1 -1
  3. package/dist/tolgee.cjs.min.js +1 -1
  4. package/dist/tolgee.cjs.min.js.map +1 -1
  5. package/dist/tolgee.umd.js +558 -156
  6. package/dist/tolgee.umd.js.map +1 -1
  7. package/dist/tolgee.umd.min.js +16 -0
  8. package/dist/tolgee.umd.min.js.map +1 -0
  9. package/lib/Constants/Global.d.ts +1 -0
  10. package/lib/Constants/Global.js +1 -0
  11. package/lib/Constants/Global.js.map +1 -1
  12. package/lib/DTOs/TranslationData.d.ts +2 -1
  13. package/lib/DTOs/TranslationData.js +2 -1
  14. package/lib/DTOs/TranslationData.js.map +1 -1
  15. package/lib/Tolgee.d.ts +6 -6
  16. package/lib/Tolgee.js +66 -33
  17. package/lib/Tolgee.js.map +1 -1
  18. package/lib/handlers/AbstractHandler.d.ts +2 -2
  19. package/lib/handlers/AbstractHandler.js.map +1 -1
  20. package/lib/handlers/CoreHandler.d.ts +3 -1
  21. package/lib/handlers/CoreHandler.js +5 -1
  22. package/lib/handlers/CoreHandler.js.map +1 -1
  23. package/lib/handlers/WrappedHandler.d.ts +13 -0
  24. package/lib/handlers/WrappedHandler.js +85 -0
  25. package/lib/handlers/WrappedHandler.js.map +1 -0
  26. package/lib/helpers/TextHelper.d.ts +1 -1
  27. package/lib/helpers/TextHelper.js +30 -10
  28. package/lib/helpers/TextHelper.js.map +1 -1
  29. package/lib/highlighter/HighlightFunctionsInitializer.d.ts +9 -0
  30. package/lib/highlighter/HighlightFunctionsInitializer.js +24 -0
  31. package/lib/highlighter/HighlightFunctionsInitializer.js.map +1 -0
  32. package/lib/highlighter/MouseEventHandler.js +2 -6
  33. package/lib/highlighter/MouseEventHandler.js.map +1 -1
  34. package/lib/highlighter/TranslationHighlighter.d.ts +7 -13
  35. package/lib/highlighter/TranslationHighlighter.js +24 -29
  36. package/lib/highlighter/TranslationHighlighter.js.map +1 -1
  37. package/lib/index.d.ts +3 -1
  38. package/lib/index.js +3 -1
  39. package/lib/index.js.map +1 -1
  40. package/lib/services/DependencyStore.d.ts +8 -0
  41. package/lib/services/DependencyStore.js +12 -3
  42. package/lib/services/DependencyStore.js.map +1 -1
  43. package/lib/services/ElementRegistrar.d.ts +4 -1
  44. package/lib/services/ElementRegistrar.js +49 -8
  45. package/lib/services/ElementRegistrar.js.map +1 -1
  46. package/lib/services/EventService.d.ts +2 -0
  47. package/lib/services/EventService.js +1 -0
  48. package/lib/services/EventService.js.map +1 -1
  49. package/lib/services/TextService.d.ts +5 -5
  50. package/lib/services/TextService.js +124 -40
  51. package/lib/services/TextService.js.map +1 -1
  52. package/lib/services/TranslationService.d.ts +4 -3
  53. package/lib/services/TranslationService.js +53 -25
  54. package/lib/services/TranslationService.js.map +1 -1
  55. package/lib/toolsManager/PluginManager.d.ts +18 -0
  56. package/lib/toolsManager/PluginManager.js +118 -0
  57. package/lib/toolsManager/PluginManager.js.map +1 -0
  58. package/lib/types.d.ts +20 -1
  59. package/package.json +2 -2
@@ -126,6 +126,7 @@
126
126
  var RESTRICTED_ASCENDANT_ATTRIBUTE = 'data-tolgee-restricted';
127
127
  var TOLGEE_ATTRIBUTE_NAME = '_tolgee';
128
128
  var TOLGEE_TARGET_ATTRIBUTE = '_tolgee-target';
129
+ var TOLGEE_WRAPPED_ONLY_DATA_ATTRIBUTE = 'data-tolgee-key-only';
129
130
 
130
131
  var NodeHelper = /** @class */ (function () {
131
132
  function NodeHelper() {
@@ -412,6 +413,7 @@
412
413
  this.TRANSLATION_CHANGED = new EventEmitterImpl();
413
414
  this.LANGUAGE_CHANGED = new EventEmitterImpl();
414
415
  this.LANGUAGE_LOADED = new EventEmitterImpl();
416
+ this.ELEMENT_REGISTERED = new EventEmitterImpl();
415
417
  }
416
418
  return EventService;
417
419
  }());
@@ -539,9 +541,10 @@
539
541
  }());
540
542
 
541
543
  var TranslationData = /** @class */ (function () {
542
- function TranslationData(key, translations) {
544
+ function TranslationData(key, translations, id) {
543
545
  this.key = key;
544
546
  this.translations = translations;
547
+ this.id = id;
545
548
  }
546
549
  return TranslationData;
547
550
  }());
@@ -552,16 +555,26 @@
552
555
  TextHelper.splitOnNonEscapedDelimiter = function (string, delimiter) {
553
556
  var result = [];
554
557
  var actual = '';
558
+ var escaped = false;
555
559
  for (var i = 0; i < string.length; i++) {
556
560
  var char = string[i];
557
- if (char === delimiter && !this.isCharEscaped(i, string)) {
558
- result.push(this.removeEscapes(actual));
561
+ if (char === '\\' && !escaped) {
562
+ escaped = true;
563
+ continue;
564
+ }
565
+ if (escaped) {
566
+ escaped = false;
567
+ actual += char;
568
+ continue;
569
+ }
570
+ if (char === delimiter) {
571
+ result.push(actual);
559
572
  actual = '';
560
573
  continue;
561
574
  }
562
- actual += string[i];
575
+ actual += char;
563
576
  }
564
- result.push(this.removeEscapes(actual));
577
+ result.push(actual);
565
578
  return result;
566
579
  };
567
580
  TextHelper.isCharEscaped = function (position, fullString) {
@@ -572,13 +585,23 @@
572
585
  }
573
586
  return escapeCharsCount % 2 == 1;
574
587
  };
575
- TextHelper.removeEscapes = function (text) {
576
- return text.replace(/\\?\\?/g, function (match) {
577
- if (match == '\\\\') {
578
- return '\\';
588
+ TextHelper.removeEscapes = function (string) {
589
+ var result = '';
590
+ var escaped = false;
591
+ for (var i = 0; i < string.length; i++) {
592
+ var char = string[i];
593
+ if (char === '\\' && !escaped) {
594
+ escaped = true;
595
+ continue;
579
596
  }
580
- return '';
581
- });
597
+ if (escaped) {
598
+ escaped = false;
599
+ result += char;
600
+ continue;
601
+ }
602
+ result += char;
603
+ }
604
+ return result;
582
605
  };
583
606
  return TextHelper;
584
607
  }());
@@ -595,59 +618,66 @@
595
618
  this.getTranslationsOfKey = function (key, languages) {
596
619
  if (languages === void 0) { languages = new Set([_this.properties.currentLanguage]); }
597
620
  return __awaiter(_this, void 0, void 0, function () {
598
- var languagesArray, languagesQuery, data, translationData_1, fetchedData, e_1, _a;
599
- var _b, _c, _d, _e, _f, _g;
600
- return __generator(this, function (_h) {
601
- switch (_h.label) {
621
+ var languagesArray, languagesQuery, data, translationData_1, firstItem, fetchedData, e_1, _a;
622
+ var _b, _c, _d, _e, _f;
623
+ return __generator(this, function (_g) {
624
+ switch (_g.label) {
602
625
  case 0:
603
626
  this.coreService.checkScope('translations.view');
604
- _h.label = 1;
627
+ _g.label = 1;
605
628
  case 1:
606
- _h.trys.push([1, 3, , 6]);
629
+ _g.trys.push([1, 3, , 7]);
607
630
  languagesArray = __spreadArray([], __read(languages));
608
631
  languagesQuery = languagesArray
609
632
  .map(function (l) { return "languages=" + l; })
610
633
  .join('&');
611
634
  return [4 /*yield*/, this.apiHttpService.fetchJson("v2/projects/translations?" + languagesQuery + "&filterKeyName=" + encodeURIComponent(key))];
612
635
  case 2:
613
- data = _h.sent();
636
+ data = _g.sent();
614
637
  translationData_1 = languagesArray.reduce(function (acc, curr) {
615
638
  var _a;
616
639
  return (__assign(__assign({}, acc), (_a = {}, _a[curr] = '', _a)));
617
640
  }, {});
618
- fetchedData = (_d = (_c = (_b = data._embedded) === null || _b === void 0 ? void 0 : _b.keys) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.translations;
641
+ firstItem = (_c = (_b = data._embedded) === null || _b === void 0 ? void 0 : _b.keys) === null || _c === void 0 ? void 0 : _c[0];
642
+ fetchedData = firstItem === null || firstItem === void 0 ? void 0 : firstItem.translations;
619
643
  if (fetchedData) {
620
- Object.entries((_g = (_f = (_e = data._embedded) === null || _e === void 0 ? void 0 : _e.keys) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.translations).forEach(function (_a) {
644
+ Object.entries((_f = (_e = (_d = data._embedded) === null || _d === void 0 ? void 0 : _d.keys) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.translations).forEach(function (_a) {
621
645
  var _b = __read(_a, 2), language = _b[0], translation = _b[1];
622
646
  return (translationData_1[language] = translation.text);
623
647
  });
624
648
  }
625
- return [2 /*return*/, new TranslationData(key, translationData_1)];
649
+ return [2 /*return*/, new TranslationData(key, translationData_1, firstItem === null || firstItem === void 0 ? void 0 : firstItem.keyId)];
626
650
  case 3:
627
- e_1 = _h.sent();
628
- if (!(e_1 instanceof ApiHttpError)) return [3 /*break*/, 5];
629
- if (!(e_1.response.status === 404)) return [3 /*break*/, 5];
630
- if (!(e_1.code === 'language_not_found')) return [3 /*break*/, 5];
651
+ e_1 = _g.sent();
652
+ if (!(e_1 instanceof ApiHttpError &&
653
+ e_1.response.status === 404 &&
654
+ e_1.code === 'language_not_found')) return [3 /*break*/, 5];
655
+ //only possible reason for this error is, that languages definition is changed, but the old value is stored in preferred languages
631
656
  _a = this.properties;
632
657
  return [4 /*yield*/, this.coreService.getLanguages()];
633
658
  case 4:
659
+ //only possible reason for this error is, that languages definition is changed, but the old value is stored in preferred languages
634
660
  _a.preferredLanguages =
635
- _h.sent();
661
+ _g.sent();
636
662
  // eslint-disable-next-line no-console
637
663
  console.error('Requested language not found, refreshing the page!');
638
664
  location.reload();
639
- return [2 /*return*/];
665
+ return [3 /*break*/, 6];
640
666
  case 5: throw e_1;
641
- case 6: return [2 /*return*/];
667
+ case 6: return [3 /*break*/, 7];
668
+ case 7: return [2 /*return*/];
642
669
  }
643
670
  });
644
671
  });
645
672
  };
646
673
  }
647
- TranslationService.translationByValue = function (message, key, orEmpty) {
674
+ TranslationService.translationByValue = function (message, key, orEmpty, defaultValue) {
648
675
  if (message) {
649
676
  return message;
650
677
  }
678
+ if (defaultValue) {
679
+ return defaultValue;
680
+ }
651
681
  if (orEmpty) {
652
682
  return '';
653
683
  }
@@ -690,7 +720,7 @@
690
720
  });
691
721
  });
692
722
  };
693
- TranslationService.prototype.getTranslation = function (key, lang, orEmpty) {
723
+ TranslationService.prototype.getTranslation = function (key, lang, orEmpty, defaultValue) {
694
724
  if (lang === void 0) { lang = this.properties.currentLanguage; }
695
725
  if (orEmpty === void 0) { orEmpty = false; }
696
726
  return __awaiter(this, void 0, void 0, function () {
@@ -712,21 +742,25 @@
712
742
  _a.sent();
713
743
  message = this.getFromCache(key, this.properties.config.fallbackLanguage);
714
744
  _a.label = 3;
715
- case 3: return [2 /*return*/, TranslationService.translationByValue(message, key, orEmpty)];
745
+ case 3: return [2 /*return*/, TranslationService.translationByValue(message, key, orEmpty, defaultValue)];
716
746
  }
717
747
  });
718
748
  });
719
749
  };
720
750
  TranslationService.prototype.setTranslations = function (translationData) {
721
751
  return __awaiter(this, void 0, void 0, function () {
752
+ var result;
722
753
  var _this = this;
723
754
  return __generator(this, function (_a) {
724
755
  switch (_a.label) {
725
756
  case 0:
726
757
  this.coreService.checkScope('translations.edit');
727
- return [4 /*yield*/, this.apiHttpService.post('v2/projects/translations', translationData)];
758
+ return [4 /*yield*/, this.apiHttpService.postJson('v2/projects/translations', {
759
+ key: translationData.key,
760
+ translations: translationData.translations,
761
+ })];
728
762
  case 1:
729
- _a.sent();
763
+ result = _a.sent();
730
764
  Object.keys(translationData.translations).forEach(function (lang) {
731
765
  if (_this.translationsCache.get(lang)) {
732
766
  // if the language is not loaded, then ignore the change
@@ -745,17 +779,34 @@
745
779
  }
746
780
  }
747
781
  });
748
- return [2 /*return*/];
782
+ return [2 /*return*/, result];
749
783
  }
750
784
  });
751
785
  });
752
786
  };
753
- TranslationService.prototype.getFromCacheOrFallback = function (key, lang, orEmpty) {
787
+ TranslationService.prototype.uploadScreenshot = function (key, data) {
788
+ return __awaiter(this, void 0, void 0, function () {
789
+ var formData, blob;
790
+ return __generator(this, function (_a) {
791
+ switch (_a.label) {
792
+ case 0:
793
+ this.coreService.checkScope('translations.edit');
794
+ formData = new FormData();
795
+ return [4 /*yield*/, fetch(data).then(function (r) { return r.blob(); })];
796
+ case 1:
797
+ blob = _a.sent();
798
+ formData.append('screenshot', blob);
799
+ return [2 /*return*/, this.apiHttpService.post("v2/projects/keys/" + key + "/screenshots", undefined, { headers: {}, body: formData })];
800
+ }
801
+ });
802
+ });
803
+ };
804
+ TranslationService.prototype.getFromCacheOrFallback = function (key, lang, orEmpty, defaultValue) {
754
805
  if (lang === void 0) { lang = this.properties.currentLanguage; }
755
806
  if (orEmpty === void 0) { orEmpty = false; }
756
807
  var message = this.getFromCache(key, lang) ||
757
808
  this.getFromCache(key, this.properties.config.fallbackLanguage);
758
- return TranslationService.translationByValue(message, key, orEmpty);
809
+ return TranslationService.translationByValue(message, key, orEmpty, defaultValue);
759
810
  };
760
811
  TranslationService.prototype.fetchTranslations = function (lang) {
761
812
  return __awaiter(this, void 0, void 0, function () {
@@ -3285,7 +3336,9 @@
3285
3336
  this.translationService = translationService;
3286
3337
  this.format = function (translation, params) {
3287
3338
  try {
3288
- return new IntlMessageFormat(translation, _this.properties.currentLanguage).format(params);
3339
+ return new IntlMessageFormat(translation, _this.properties.currentLanguage, undefined, {
3340
+ ignoreTag: true,
3341
+ }).format(params);
3289
3342
  }
3290
3343
  catch (e) {
3291
3344
  if (e.code === 'MISSING_VALUE') {
@@ -3312,7 +3365,90 @@
3312
3365
  return param;
3313
3366
  };
3314
3367
  }
3315
- TextService.prototype.translate = function (key, params, lang, orEmpty) {
3368
+ Object.defineProperty(TextService.prototype, "rawUnWrapRegex", {
3369
+ get: function () {
3370
+ var escapedPrefix = this.escapeForRegExp(this.properties.config.inputPrefix);
3371
+ var escapedSuffix = this.escapeForRegExp(this.properties.config.inputSuffix);
3372
+ return "(\\\\?)(" + escapedPrefix + "(.*?)" + escapedSuffix + ")";
3373
+ },
3374
+ enumerable: false,
3375
+ configurable: true
3376
+ });
3377
+ TextService.parseUnwrapped = function (unwrappedString) {
3378
+ var e_1, _a;
3379
+ var escaped = false;
3380
+ var actual = '';
3381
+ var paramName = '';
3382
+ var readingState = 'KEY';
3383
+ var result = {
3384
+ key: '',
3385
+ params: {},
3386
+ defaultValue: undefined,
3387
+ };
3388
+ try {
3389
+ for (var unwrappedString_1 = __values(unwrappedString), unwrappedString_1_1 = unwrappedString_1.next(); !unwrappedString_1_1.done; unwrappedString_1_1 = unwrappedString_1.next()) {
3390
+ var char = unwrappedString_1_1.value;
3391
+ if (char === '\\' && !escaped) {
3392
+ escaped = true;
3393
+ continue;
3394
+ }
3395
+ if (escaped) {
3396
+ escaped = false;
3397
+ actual += char;
3398
+ continue;
3399
+ }
3400
+ if (readingState === 'KEY' && char === ',') {
3401
+ readingState = 'DEFAULT_VALUE';
3402
+ result.key = actual;
3403
+ actual = '';
3404
+ continue;
3405
+ }
3406
+ if (readingState === 'KEY' && char === ':') {
3407
+ readingState = 'PARAM_NAME';
3408
+ result.key = actual;
3409
+ actual = '';
3410
+ continue;
3411
+ }
3412
+ if (readingState === 'DEFAULT_VALUE' && char === ':') {
3413
+ readingState = 'PARAM_NAME';
3414
+ result.defaultValue = actual;
3415
+ actual = '';
3416
+ continue;
3417
+ }
3418
+ if (readingState === 'PARAM_NAME' && char === ':') {
3419
+ readingState = 'PARAM_VALUE';
3420
+ paramName = actual;
3421
+ actual = '';
3422
+ continue;
3423
+ }
3424
+ if (readingState === 'PARAM_VALUE' && char === ',') {
3425
+ readingState = 'PARAM_NAME';
3426
+ result.params[paramName] = actual;
3427
+ actual = '';
3428
+ continue;
3429
+ }
3430
+ actual += char;
3431
+ }
3432
+ }
3433
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
3434
+ finally {
3435
+ try {
3436
+ if (unwrappedString_1_1 && !unwrappedString_1_1.done && (_a = unwrappedString_1.return)) _a.call(unwrappedString_1);
3437
+ }
3438
+ finally { if (e_1) throw e_1.error; }
3439
+ }
3440
+ if (readingState === 'KEY') {
3441
+ result.key = actual;
3442
+ }
3443
+ if (readingState === 'DEFAULT_VALUE') {
3444
+ result.defaultValue = actual;
3445
+ }
3446
+ if (readingState === 'PARAM_VALUE') {
3447
+ result.params[paramName] = actual;
3448
+ }
3449
+ return result;
3450
+ };
3451
+ TextService.prototype.translate = function (key, params, lang, orEmpty, defaultValue) {
3316
3452
  if (lang === void 0) { lang = this.properties.currentLanguage; }
3317
3453
  return __awaiter(this, void 0, void 0, function () {
3318
3454
  var _a;
@@ -3320,19 +3456,19 @@
3320
3456
  switch (_b.label) {
3321
3457
  case 0:
3322
3458
  _a = this.format;
3323
- return [4 /*yield*/, this.translationService.getTranslation(key, lang, orEmpty)];
3459
+ return [4 /*yield*/, this.translationService.getTranslation(key, lang, orEmpty, defaultValue)];
3324
3460
  case 1: return [2 /*return*/, _a.apply(this, [_b.sent(), params])];
3325
3461
  }
3326
3462
  });
3327
3463
  });
3328
3464
  };
3329
- TextService.prototype.instant = function (key, params, lang, orEmpty) {
3465
+ TextService.prototype.instant = function (key, params, lang, orEmpty, defaultValue) {
3330
3466
  if (lang === void 0) { lang = this.properties.currentLanguage; }
3331
- return this.format(this.translationService.getFromCacheOrFallback(key, lang, orEmpty), params);
3467
+ return this.format(this.translationService.getFromCacheOrFallback(key, lang, orEmpty, defaultValue), params);
3332
3468
  };
3333
3469
  TextService.prototype.replace = function (text) {
3334
3470
  return __awaiter(this, void 0, void 0, function () {
3335
- var matchRegexp, keysAndParams, matched, match, start, result, _a, fullMatch, pre, wrapped, unwrapped, index, input, translated, withoutEscapes;
3471
+ var matchRegexp, keysAndParams, matched, match, start, result, pre, _a, fullMatch, wrapped, unwrapped, index, input, translated;
3336
3472
  return __generator(this, function (_b) {
3337
3473
  switch (_b.label) {
3338
3474
  case 0:
@@ -3344,35 +3480,43 @@
3344
3480
  _b.label = 1;
3345
3481
  case 1:
3346
3482
  if (!((match = matchRegexp.exec(text)) !== null)) return [3 /*break*/, 3];
3347
- _a = __read(match, 4), fullMatch = _a[0], pre = _a[1], wrapped = _a[2], unwrapped = _a[3];
3483
+ pre = match[1];
3484
+ _a = __read(match, 4), fullMatch = _a[0], wrapped = _a[2], unwrapped = _a[3];
3348
3485
  index = match.index, input = match.input;
3349
3486
  result += input.substr(start, index - start);
3350
3487
  start = index + fullMatch.length;
3351
- if (pre === '\\' && !TextHelper.isCharEscaped(index, text)) {
3352
- result += wrapped;
3353
- return [3 /*break*/, 1];
3488
+ if (pre === '\\') {
3489
+ if (!TextHelper.isCharEscaped(index, text)) {
3490
+ result += wrapped;
3491
+ return [3 /*break*/, 1];
3492
+ }
3493
+ pre = '';
3354
3494
  }
3355
3495
  return [4 /*yield*/, this.getTranslatedWithMetadata(unwrapped)];
3356
3496
  case 2:
3357
3497
  translated = _b.sent();
3358
- keysAndParams.push({ key: translated.key, params: translated.params });
3498
+ keysAndParams.push({
3499
+ key: translated.key,
3500
+ params: translated.params,
3501
+ defaultValue: translated.defaultValue,
3502
+ });
3359
3503
  matched = true;
3360
3504
  result += pre + translated.translated;
3361
3505
  return [3 /*break*/, 1];
3362
3506
  case 3:
3363
3507
  result += text.substring(start);
3364
- withoutEscapes = TextHelper.removeEscapes(result);
3365
3508
  if (matched) {
3366
- return [2 /*return*/, { text: withoutEscapes, keys: keysAndParams }];
3509
+ return [2 /*return*/, { text: result, keys: keysAndParams }];
3367
3510
  }
3368
3511
  return [2 /*return*/, undefined];
3369
3512
  }
3370
3513
  });
3371
3514
  });
3372
3515
  };
3373
- TextService.prototype.wrap = function (key, params) {
3516
+ TextService.prototype.wrap = function (key, params, defaultValue) {
3374
3517
  var _this = this;
3375
3518
  if (params === void 0) { params = {}; }
3519
+ if (defaultValue === void 0) { defaultValue = undefined; }
3376
3520
  var paramString = Object.entries(params)
3377
3521
  .map(function (_a) {
3378
3522
  var _b = __read(_a, 2), name = _b[0], value = _b[1];
@@ -3380,44 +3524,24 @@
3380
3524
  })
3381
3525
  .join(',');
3382
3526
  paramString = paramString.length ? ":" + paramString : '';
3383
- return "" + this.properties.config.inputPrefix + this.escapeParam(key) + paramString + this.properties.config.inputSuffix;
3527
+ var defaultString = defaultValue !== undefined ? "," + this.escapeParam(defaultValue) : '';
3528
+ return "" + this.properties.config.inputPrefix + this.escapeParam(key) + defaultString + paramString + this.properties.config.inputSuffix;
3384
3529
  };
3385
3530
  TextService.prototype.getTranslatedWithMetadata = function (text) {
3386
3531
  return __awaiter(this, void 0, void 0, function () {
3387
- var _a, key, params, translated;
3532
+ var _a, key, params, defaultValue, translated;
3388
3533
  return __generator(this, function (_b) {
3389
3534
  switch (_b.label) {
3390
3535
  case 0:
3391
- _a = TextService.parseUnwrapped(text), key = _a.key, params = _a.params;
3392
- return [4 /*yield*/, this.translate(key, params, undefined, false)];
3536
+ _a = TextService.parseUnwrapped(text), key = _a.key, params = _a.params, defaultValue = _a.defaultValue;
3537
+ return [4 /*yield*/, this.translate(key, params, undefined, false, defaultValue)];
3393
3538
  case 1:
3394
3539
  translated = _b.sent();
3395
- return [2 /*return*/, { translated: translated, key: key, params: params }];
3540
+ return [2 /*return*/, { translated: translated, key: key, params: params, defaultValue: defaultValue }];
3396
3541
  }
3397
3542
  });
3398
3543
  });
3399
3544
  };
3400
- TextService.parseUnwrapped = function (unWrappedString) {
3401
- var strings = unWrappedString.match(/(?:[^\\,:\n]|\\.)+/g);
3402
- var result = {
3403
- key: TextHelper.removeEscapes(strings.shift()),
3404
- params: {},
3405
- };
3406
- while (strings.length) {
3407
- var _a = __read(strings.splice(0, 2), 2), name_1 = _a[0], value = _a[1];
3408
- result.params[name_1] = value;
3409
- }
3410
- return result;
3411
- };
3412
- Object.defineProperty(TextService.prototype, "rawUnWrapRegex", {
3413
- get: function () {
3414
- var escapedPrefix = this.escapeForRegExp(this.properties.config.inputPrefix);
3415
- var escapedSuffix = this.escapeForRegExp(this.properties.config.inputSuffix);
3416
- return "(\\\\?)(" + escapedPrefix + "(.*?)" + escapedSuffix + ")";
3417
- },
3418
- enumerable: false,
3419
- configurable: true
3420
- });
3421
3545
  return TextService;
3422
3546
  }());
3423
3547
 
@@ -3488,16 +3612,12 @@
3488
3612
  }
3489
3613
  };
3490
3614
  MouseEventHandler.prototype.highlight = function () {
3491
- this.highlightedInitialBackgroundColor =
3492
- this.getMouseOn().style.backgroundColor;
3493
- this.getMouseOn().style.backgroundColor =
3494
- this.properties.config.highlightColor;
3615
+ this.getMouseOn()._tolgee.highlight();
3495
3616
  this.highlighted = this.getMouseOn();
3496
3617
  };
3497
3618
  MouseEventHandler.prototype.unhighlight = function () {
3498
3619
  if (this.highlighted) {
3499
- this.highlighted.style.backgroundColor =
3500
- this.highlightedInitialBackgroundColor;
3620
+ this.highlighted._tolgee.unhighlight();
3501
3621
  this.highlighted = null;
3502
3622
  }
3503
3623
  };
@@ -3564,13 +3684,9 @@
3564
3684
  }());
3565
3685
 
3566
3686
  var TranslationHighlighter = /** @class */ (function () {
3567
- function TranslationHighlighter(service, properties, eventService, translationService, mouseEventHandler) {
3687
+ function TranslationHighlighter(dependencies) {
3568
3688
  var _this = this;
3569
- this.service = service;
3570
- this.properties = properties;
3571
- this.eventService = eventService;
3572
- this.translationService = translationService;
3573
- this.mouseEventHandler = mouseEventHandler;
3689
+ this.dependencies = dependencies;
3574
3690
  this.translationEdit = function (e, element) { return __awaiter(_this, void 0, void 0, function () {
3575
3691
  var key;
3576
3692
  return __generator(this, function (_a) {
@@ -3594,9 +3710,27 @@
3594
3710
  });
3595
3711
  }); };
3596
3712
  }
3713
+ Object.defineProperty(TranslationHighlighter.prototype, "renderer", {
3714
+ get: function () {
3715
+ if (this._renderer === undefined) {
3716
+ if (typeof this.dependencies.properties.config.ui === 'function') {
3717
+ this._renderer = new this.dependencies.properties.config.ui(this.dependencies);
3718
+ }
3719
+ }
3720
+ return this._renderer;
3721
+ },
3722
+ enumerable: false,
3723
+ configurable: true
3724
+ });
3725
+ TranslationHighlighter.getKeyOptions = function (node) {
3726
+ var nodes = Array.from(node._tolgee.nodes);
3727
+ var keys = nodes.reduce(function (acc, curr) { return __spreadArray(__spreadArray([], __read(acc)), __read(curr._tolgee.keys.map(function (k) { return k.key; }))); }, []);
3728
+ return new Set(keys);
3729
+ };
3597
3730
  TranslationHighlighter.prototype.listen = function (element) {
3598
3731
  var _this = this;
3599
- this.mouseEventHandler.handle(element, function (e) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
3732
+ this.dependencies.highlightFunctionInitializer.initFunctions(element);
3733
+ this.dependencies.mouseEventHandler.handle(element, function (e) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
3600
3734
  switch (_a.label) {
3601
3735
  case 0: return [4 /*yield*/, this.translationEdit(e, element)];
3602
3736
  case 1: return [2 /*return*/, _a.sent()];
@@ -3609,6 +3743,9 @@
3609
3743
  return __generator(this, function (_a) {
3610
3744
  switch (_a.label) {
3611
3745
  case 0:
3746
+ if (element._tolgee.wrappedWithElementOnlyKey) {
3747
+ return [2 /*return*/, element._tolgee.wrappedWithElementOnlyKey];
3748
+ }
3612
3749
  keys = TranslationHighlighter.getKeyOptions(element);
3613
3750
  if (!(keys.size > 1)) return [3 /*break*/, 2];
3614
3751
  return [4 /*yield*/, this.renderer.getKey({ keys: keys, openEvent: mouseEvent })];
@@ -3624,40 +3761,20 @@
3624
3761
  });
3625
3762
  });
3626
3763
  };
3627
- TranslationHighlighter.getKeyOptions = function (node) {
3628
- var nodes = Array.from(node._tolgee.nodes);
3629
- var keys = nodes.reduce(function (acc, curr) { return __spreadArray(__spreadArray([], __read(acc)), __read(curr._tolgee.keys.map(function (k) { return k.key; }))); }, []);
3630
- return new Set(keys);
3631
- };
3632
- Object.defineProperty(TranslationHighlighter.prototype, "renderer", {
3633
- get: function () {
3634
- if (this._renderer === undefined) {
3635
- if (typeof this.properties.config.ui === 'function') {
3636
- this._renderer = new this.properties.config.ui({
3637
- coreService: this.service,
3638
- properties: this.properties,
3639
- eventService: this.eventService,
3640
- translationService: this.translationService,
3641
- });
3642
- }
3643
- }
3644
- return this._renderer;
3645
- },
3646
- enumerable: false,
3647
- configurable: true
3648
- });
3649
3764
  return TranslationHighlighter;
3650
3765
  }());
3651
3766
 
3652
3767
  var ElementRegistrar = /** @class */ (function () {
3653
- function ElementRegistrar(properties, translationHighlighter) {
3768
+ function ElementRegistrar(properties, translationHighlighter, eventService) {
3654
3769
  this.properties = properties;
3655
3770
  this.translationHighlighter = translationHighlighter;
3771
+ this.eventService = eventService;
3656
3772
  this.registeredElements = new Set();
3657
3773
  }
3658
3774
  ElementRegistrar.prototype.register = function (element) {
3659
3775
  //ignore element with no active nodes
3660
- if (this.getActiveNodes(element).next().value === undefined) {
3776
+ if (this.getActiveNodes(element).next().value === undefined &&
3777
+ !element._tolgee.wrappedWithElementOnlyKey) {
3661
3778
  return;
3662
3779
  }
3663
3780
  if (this.properties.config.mode === 'development' &&
@@ -3665,6 +3782,7 @@
3665
3782
  this.translationHighlighter.listen(element);
3666
3783
  }
3667
3784
  this.registeredElements.add(element);
3785
+ this.eventService.ELEMENT_REGISTERED.emit(element);
3668
3786
  };
3669
3787
  ElementRegistrar.prototype.refreshAll = function () {
3670
3788
  var e_1, _a;
@@ -3672,7 +3790,8 @@
3672
3790
  for (var _b = __values(this.registeredElements), _c = _b.next(); !_c.done; _c = _b.next()) {
3673
3791
  var element = _c.value;
3674
3792
  this.cleanElementInactiveNodes(element);
3675
- if (element._tolgee.nodes.size === 0) {
3793
+ if (element._tolgee.nodes.size === 0 &&
3794
+ !element._tolgee.wrappedWithElementOnlyKey) {
3676
3795
  this.cleanElement(element);
3677
3796
  }
3678
3797
  }
@@ -3701,6 +3820,43 @@
3701
3820
  finally { if (e_2) throw e_2.error; }
3702
3821
  }
3703
3822
  };
3823
+ ElementRegistrar.prototype.findAllByKey = function (key) {
3824
+ var e_3, _a, e_4, _b;
3825
+ var result = [];
3826
+ try {
3827
+ for (var _c = __values(this.registeredElements), _d = _c.next(); !_d.done; _d = _c.next()) {
3828
+ var registeredElement = _d.value;
3829
+ if (registeredElement._tolgee.wrappedWithElementOnlyKey === key) {
3830
+ result.push(registeredElement);
3831
+ continue;
3832
+ }
3833
+ try {
3834
+ for (var _e = (e_4 = void 0, __values(registeredElement._tolgee.nodes)), _f = _e.next(); !_f.done; _f = _e.next()) {
3835
+ var node = _f.value;
3836
+ if (node._tolgee.keys.findIndex(function (keyWithParams) { return keyWithParams.key === key; }) > -1) {
3837
+ result.push(registeredElement);
3838
+ break;
3839
+ }
3840
+ }
3841
+ }
3842
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
3843
+ finally {
3844
+ try {
3845
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
3846
+ }
3847
+ finally { if (e_4) throw e_4.error; }
3848
+ }
3849
+ }
3850
+ }
3851
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
3852
+ finally {
3853
+ try {
3854
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
3855
+ }
3856
+ finally { if (e_3) throw e_3.error; }
3857
+ }
3858
+ return result;
3859
+ };
3704
3860
  ElementRegistrar.prototype.cleanElementInactiveNodes = function (element) {
3705
3861
  if (this.isElementActive(element)) {
3706
3862
  element._tolgee.nodes = new Set(this.getActiveNodes(element));
@@ -3716,8 +3872,8 @@
3716
3872
  this.registeredElements.delete(element);
3717
3873
  };
3718
3874
  ElementRegistrar.prototype.getActiveNodes = function (element) {
3719
- var _a, _b, node, e_3_1;
3720
- var e_3, _c;
3875
+ var _a, _b, node, e_5_1;
3876
+ var e_5, _c;
3721
3877
  return __generator(this, function (_d) {
3722
3878
  switch (_d.label) {
3723
3879
  case 0:
@@ -3737,14 +3893,14 @@
3737
3893
  return [3 /*break*/, 1];
3738
3894
  case 4: return [3 /*break*/, 7];
3739
3895
  case 5:
3740
- e_3_1 = _d.sent();
3741
- e_3 = { error: e_3_1 };
3896
+ e_5_1 = _d.sent();
3897
+ e_5 = { error: e_5_1 };
3742
3898
  return [3 /*break*/, 7];
3743
3899
  case 6:
3744
3900
  try {
3745
3901
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
3746
3902
  }
3747
- finally { if (e_3) throw e_3.error; }
3903
+ finally { if (e_5) throw e_5.error; }
3748
3904
  return [7 /*endfinally*/];
3749
3905
  case 7: return [2 /*return*/];
3750
3906
  }
@@ -3995,13 +4151,14 @@
3995
4151
  }(AbstractHandler));
3996
4152
 
3997
4153
  var CoreHandler = /** @class */ (function () {
3998
- function CoreHandler(service, textHandler, eventService, properties, attributeHandler, textService) {
4154
+ function CoreHandler(service, textHandler, eventService, properties, attributeHandler, textService, wrappedHandler) {
3999
4155
  this.service = service;
4000
4156
  this.textHandler = textHandler;
4001
4157
  this.eventService = eventService;
4002
4158
  this.properties = properties;
4003
4159
  this.attributeHandler = attributeHandler;
4004
4160
  this.textService = textService;
4161
+ this.wrappedHandler = wrappedHandler;
4005
4162
  eventService.LANGUAGE_CHANGED.subscribe(this.refresh.bind(this));
4006
4163
  eventService.TRANSLATION_CHANGED.subscribe(this.refresh.bind(this));
4007
4164
  }
@@ -4014,6 +4171,9 @@
4014
4171
  _a.sent();
4015
4172
  return [4 /*yield*/, this.textHandler.handle(target)];
4016
4173
  case 2:
4174
+ _a.sent();
4175
+ return [4 /*yield*/, this.wrappedHandler.handle(target)];
4176
+ case 3:
4017
4177
  _a.sent();
4018
4178
  return [2 /*return*/];
4019
4179
  }
@@ -4234,6 +4394,208 @@
4234
4394
  return CoreService;
4235
4395
  }());
4236
4396
 
4397
+ var WrappedHandler = /** @class */ (function (_super) {
4398
+ __extends(WrappedHandler, _super);
4399
+ function WrappedHandler(properties, translationHighlighter, textService, elementRegistrar) {
4400
+ var _this = _super.call(this, properties, textService, elementRegistrar, translationHighlighter) || this;
4401
+ _this.properties = properties;
4402
+ _this.translationHighlighter = translationHighlighter;
4403
+ _this.textService = textService;
4404
+ _this.elementRegistrar = elementRegistrar;
4405
+ return _this;
4406
+ }
4407
+ WrappedHandler.prototype.handle = function (node) {
4408
+ return __awaiter(this, void 0, void 0, function () {
4409
+ var xPath, nodes, filtered;
4410
+ var _this = this;
4411
+ return __generator(this, function (_a) {
4412
+ xPath = "./descendant-or-self::*[@" + TOLGEE_WRAPPED_ONLY_DATA_ATTRIBUTE + "]";
4413
+ nodes = NodeHelper.evaluate(xPath, node);
4414
+ filtered = this.filterRestricted(nodes);
4415
+ filtered.forEach(function (element) {
4416
+ var elementWithMeta = AbstractHandler.initParentElement(element);
4417
+ elementWithMeta._tolgee.wrappedWithElementOnlyKey = element.getAttribute(TOLGEE_WRAPPED_ONLY_DATA_ATTRIBUTE);
4418
+ _this.elementRegistrar.register(elementWithMeta);
4419
+ });
4420
+ return [2 /*return*/];
4421
+ });
4422
+ });
4423
+ };
4424
+ return WrappedHandler;
4425
+ }(AbstractHandler));
4426
+
4427
+ var PluginManager = /** @class */ (function () {
4428
+ function PluginManager(messages, properties, eventService, elementRegistrar) {
4429
+ var _this = this;
4430
+ this.messages = messages;
4431
+ this.properties = properties;
4432
+ this.eventService = eventService;
4433
+ this.elementRegistrar = elementRegistrar;
4434
+ this.handshakeSucceed = false;
4435
+ this.takeScreenshot = function () {
4436
+ return new Promise(function (resolve, reject) {
4437
+ try {
4438
+ _this.messages.send('TOLGEE_TAKE_SCREENSHOT');
4439
+ _this.messages.listen('TOLGEE_SCREENSHOT_TAKEN', function (data) {
4440
+ resolve(data);
4441
+ });
4442
+ }
4443
+ catch (e) {
4444
+ reject(e);
4445
+ }
4446
+ });
4447
+ };
4448
+ this.handshake = function () {
4449
+ var sharedConfiguration = __assign(__assign({}, _this.properties), { config: __assign(__assign({}, _this.properties.config), {
4450
+ //remove properties, which cannot be sent by window.postMessage
4451
+ staticData: undefined, targetElement: undefined, _targetElement: undefined, ui: undefined }) });
4452
+ _this.messages.send('TOLGEE_READY', sharedConfiguration);
4453
+ _this.messages.listen('TOLGEE_PLUGIN_READY', function () {
4454
+ _this.handshakeSucceed = true;
4455
+ _this.messages.send('TOLGEE_READY', sharedConfiguration);
4456
+ _this.initListeners();
4457
+ });
4458
+ };
4459
+ }
4460
+ PluginManager.prototype.run = function () {
4461
+ try {
4462
+ this.messages.startListening();
4463
+ this.handshake();
4464
+ this.initOnRegisterKeyEmit();
4465
+ }
4466
+ catch (e) {
4467
+ // eslint-disable-next-line no-console
4468
+ console.warn(e);
4469
+ // eslint-disable-next-line no-console
4470
+ console.warn('Can not start communication with browser plugin. Check waning above.');
4471
+ }
4472
+ };
4473
+ PluginManager.prototype.initOnRegisterKeyEmit = function () {
4474
+ var _this = this;
4475
+ this.eventService.ELEMENT_REGISTERED.subscribe(function (element) {
4476
+ element._tolgee.nodes.forEach(function (node) {
4477
+ node._tolgee.keys.forEach(function (key) { return _this.messages.send('NEW_KEY', key); });
4478
+ });
4479
+ });
4480
+ };
4481
+ PluginManager.prototype.stop = function () {
4482
+ this.messages.stopListening();
4483
+ };
4484
+ PluginManager.prototype.initListeners = function () {
4485
+ var _this = this;
4486
+ this.messages.listenPopup('HIGHLIGHT_KEY', function (key) {
4487
+ var e_1, _a;
4488
+ try {
4489
+ for (var _b = __values(_this.elementRegistrar.findAllByKey(key)), _c = _b.next(); !_c.done; _c = _b.next()) {
4490
+ var element = _c.value;
4491
+ element._tolgee.highlight();
4492
+ }
4493
+ }
4494
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
4495
+ finally {
4496
+ try {
4497
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
4498
+ }
4499
+ finally { if (e_1) throw e_1.error; }
4500
+ }
4501
+ });
4502
+ this.messages.listenPopup('UNHIGHLIGHT_KEY', function (key) {
4503
+ var e_2, _a;
4504
+ try {
4505
+ for (var _b = __values(_this.elementRegistrar.findAllByKey(key)), _c = _b.next(); !_c.done; _c = _b.next()) {
4506
+ var element = _c.value;
4507
+ element._tolgee.unhighlight();
4508
+ }
4509
+ }
4510
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
4511
+ finally {
4512
+ try {
4513
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
4514
+ }
4515
+ finally { if (e_2) throw e_2.error; }
4516
+ }
4517
+ });
4518
+ };
4519
+ return PluginManager;
4520
+ }());
4521
+
4522
+ var Messages = /** @class */ (function () {
4523
+ function Messages() {
4524
+ var _this = this;
4525
+ this.listeners = [];
4526
+ this.listenersPopup = [];
4527
+ this.startListening = function () {
4528
+ var receiveMessage = function (event) {
4529
+ if (event.source != window) {
4530
+ return;
4531
+ }
4532
+ _this.listeners.forEach(function (listener) {
4533
+ if (listener.type == event.data.type) {
4534
+ listener.callback(event.data.data);
4535
+ }
4536
+ });
4537
+ };
4538
+ window.addEventListener('message', receiveMessage, false);
4539
+ typeof _this._stopListening === 'function' && _this._stopListening();
4540
+ _this._stopListening = function () {
4541
+ window.removeEventListener('message', receiveMessage, false);
4542
+ };
4543
+ _this.startPopupListening();
4544
+ };
4545
+ this.startPopupListening = function () {
4546
+ _this.listen('POPUP_TO_LIB', function (data) {
4547
+ _this.listenersPopup.forEach(function (listener) {
4548
+ if (data.type == listener.type) {
4549
+ listener.callback(data.data);
4550
+ }
4551
+ });
4552
+ });
4553
+ };
4554
+ this.listenPopup = function (type, callback) {
4555
+ _this.listenersPopup.push({ type: type, callback: callback });
4556
+ };
4557
+ this.listen = function (type, callback) {
4558
+ _this.listeners.push({ type: type, callback: callback });
4559
+ };
4560
+ this.send = function (type, data) {
4561
+ try {
4562
+ window.postMessage({ type: type, data: data }, window.origin);
4563
+ }
4564
+ catch (e) {
4565
+ // eslint-disable-next-line no-console
4566
+ console.warn('Can not send message.', e);
4567
+ }
4568
+ };
4569
+ }
4570
+ Messages.prototype.stopListening = function () {
4571
+ this._stopListening();
4572
+ };
4573
+ return Messages;
4574
+ }());
4575
+
4576
+ var HighlightFunctionsInitializer = /** @class */ (function () {
4577
+ function HighlightFunctionsInitializer(properties) {
4578
+ this.properties = properties;
4579
+ }
4580
+ HighlightFunctionsInitializer.prototype.initFunctions = function (element) {
4581
+ this.initHighlightFunction(element);
4582
+ this.initUnhighlightFunction(element);
4583
+ };
4584
+ HighlightFunctionsInitializer.prototype.initHighlightFunction = function (element) {
4585
+ var _this = this;
4586
+ element._tolgee.highlight = function () {
4587
+ element._tolgee.initialBackgroundColor = element.style.backgroundColor;
4588
+ element.style.backgroundColor = _this.properties.config.highlightColor;
4589
+ };
4590
+ };
4591
+ HighlightFunctionsInitializer.prototype.initUnhighlightFunction = function (element) {
4592
+ element._tolgee.unhighlight = function () {
4593
+ element.style.backgroundColor = element._tolgee.initialBackgroundColor;
4594
+ };
4595
+ };
4596
+ return HighlightFunctionsInitializer;
4597
+ }());
4598
+
4237
4599
  var DependencyStore = /** @class */ (function () {
4238
4600
  function DependencyStore(config) {
4239
4601
  if (config === void 0) { config = new TolgeeConfig(); }
@@ -4244,14 +4606,19 @@
4244
4606
  this.coreService = new CoreService(this.properties, this.apiHttpService);
4245
4607
  this.translationService = new TranslationService(this.properties, this.coreService, this.apiHttpService, this.eventService);
4246
4608
  this.textService = new TextService(this.properties, this.translationService);
4247
- this.translationHighlighter = new TranslationHighlighter(this.coreService, this.properties, this.eventService, this.translationService, this.mouseEventHandler);
4248
- this.elementRegistrar = new ElementRegistrar(this.properties, this.translationHighlighter);
4609
+ this.highlightFunctionInitializer = new HighlightFunctionsInitializer(this.properties);
4610
+ this.translationHighlighter = new TranslationHighlighter(this);
4611
+ this.elementRegistrar = new ElementRegistrar(this.properties, this.translationHighlighter, this.eventService);
4249
4612
  this.textHandler = new TextHandler(this.properties, this.translationHighlighter, this.textService, this.elementRegistrar);
4250
4613
  this.attributeHandler = new AttributeHandler(this.properties, this.textService, this.elementRegistrar, this.translationHighlighter);
4251
- this.coreHandler = new CoreHandler(this.coreService, this.textHandler, this.eventService, this.properties, this.attributeHandler, this.textService);
4614
+ this.wrappedHandler = new WrappedHandler(this.properties, this.translationHighlighter, this.textService, this.elementRegistrar);
4615
+ this.coreHandler = new CoreHandler(this.coreService, this.textHandler, this.eventService, this.properties, this.attributeHandler, this.textService, this.wrappedHandler);
4252
4616
  this.observer = new Observer(this.properties, this.coreHandler, this.textHandler, this.attributeHandler, this.elementRegistrar);
4617
+ this.messages = new Messages();
4618
+ this.pluginManager = new PluginManager(this.messages, this.properties, this.eventService, this.elementRegistrar);
4253
4619
  this.properties.config = config;
4254
4620
  this.translationService.initStatic();
4621
+ this.translationHighlighter.pluginManager = this.pluginManager;
4255
4622
  }
4256
4623
  return DependencyStore;
4257
4624
  }());
@@ -4259,34 +4626,6 @@
4259
4626
  var Tolgee = /** @class */ (function () {
4260
4627
  function Tolgee(config) {
4261
4628
  var _this = this;
4262
- this.translate = function (key, params, noWrap) {
4263
- if (params === void 0) { params = {}; }
4264
- if (noWrap === void 0) { noWrap = false; }
4265
- return __awaiter(_this, void 0, void 0, function () {
4266
- return __generator(this, function (_a) {
4267
- switch (_a.label) {
4268
- case 0:
4269
- if (!(this.properties.config.mode === 'development' && !noWrap)) return [3 /*break*/, 3];
4270
- return [4 /*yield*/, this.loadScopes()];
4271
- case 1:
4272
- _a.sent();
4273
- return [4 /*yield*/, this.translationService.loadTranslations()];
4274
- case 2:
4275
- _a.sent();
4276
- return [2 /*return*/, this.dependencyStore.textService.wrap(key, params)];
4277
- case 3: return [2 /*return*/, this.dependencyStore.textService.translate(key, params)];
4278
- }
4279
- });
4280
- });
4281
- };
4282
- this.instant = function (key, params, noWrap, orEmpty) {
4283
- if (params === void 0) { params = {}; }
4284
- if (noWrap === void 0) { noWrap = false; }
4285
- if (_this.properties.config.mode === 'development' && !noWrap) {
4286
- return _this.dependencyStore.textService.wrap(key, params);
4287
- }
4288
- return _this.dependencyStore.textService.instant(key, params, undefined, orEmpty);
4289
- };
4290
4629
  this.stop = function () {
4291
4630
  _this.dependencyStore.observer.stopObserving();
4292
4631
  _this.dependencyStore.elementRegistrar.cleanAll();
@@ -4341,6 +4680,13 @@
4341
4680
  enumerable: false,
4342
4681
  configurable: true
4343
4682
  });
4683
+ Object.defineProperty(Tolgee.prototype, "onTranslationChange", {
4684
+ get: function () {
4685
+ return this.dependencyStore.eventService.TRANSLATION_CHANGED;
4686
+ },
4687
+ enumerable: false,
4688
+ configurable: true
4689
+ });
4344
4690
  Object.defineProperty(Tolgee.prototype, "onLangLoaded", {
4345
4691
  get: function () {
4346
4692
  return this.dependencyStore.eventService.LANGUAGE_LOADED;
@@ -4386,13 +4732,16 @@
4386
4732
  case 2: return [4 /*yield*/, this.translationService.loadTranslations()];
4387
4733
  case 3:
4388
4734
  _a.sent();
4389
- if (!this.properties.config.preloadFallback) return [3 /*break*/, 5];
4390
- return [4 /*yield*/, this.translationService.loadTranslations(this.properties.config.fallbackLanguage)];
4735
+ return [4 /*yield*/, this.dependencyStore.pluginManager.run()];
4391
4736
  case 4:
4392
4737
  _a.sent();
4393
- _a.label = 5;
4394
- case 5: return [4 /*yield*/, this.refresh()];
4395
- case 6:
4738
+ if (!this.properties.config.preloadFallback) return [3 /*break*/, 6];
4739
+ return [4 /*yield*/, this.translationService.loadTranslations(this.properties.config.fallbackLanguage)];
4740
+ case 5:
4741
+ _a.sent();
4742
+ _a.label = 6;
4743
+ case 6: return [4 /*yield*/, this.refresh()];
4744
+ case 7:
4396
4745
  _a.sent();
4397
4746
  if (this.properties.config.watch) {
4398
4747
  this.dependencyStore.observer.observe();
@@ -4409,6 +4758,57 @@
4409
4758
  });
4410
4759
  });
4411
4760
  };
4761
+ Tolgee.prototype.translate = function (keyOrProps, params, noWrap, defaultValue) {
4762
+ if (params === void 0) { params = {}; }
4763
+ if (noWrap === void 0) { noWrap = false; }
4764
+ if (defaultValue === void 0) { defaultValue = undefined; }
4765
+ return __awaiter(this, void 0, void 0, function () {
4766
+ var key, props;
4767
+ return __generator(this, function (_a) {
4768
+ switch (_a.label) {
4769
+ case 0:
4770
+ key = typeof keyOrProps === 'string' ? keyOrProps : keyOrProps.key;
4771
+ if (typeof keyOrProps === 'object') {
4772
+ props = keyOrProps;
4773
+ // if values are not provided in props object, get them from function
4774
+ // params defaults
4775
+ params = props.params !== undefined ? props.params : params;
4776
+ noWrap = props.noWrap !== undefined ? props.noWrap : noWrap;
4777
+ defaultValue =
4778
+ props.defaultValue !== undefined ? props.defaultValue : defaultValue;
4779
+ }
4780
+ if (!(this.properties.config.mode === 'development' && !noWrap)) return [3 /*break*/, 3];
4781
+ return [4 /*yield*/, this.loadScopes()];
4782
+ case 1:
4783
+ _a.sent();
4784
+ return [4 /*yield*/, this.translationService.loadTranslations()];
4785
+ case 2:
4786
+ _a.sent();
4787
+ return [2 /*return*/, this.dependencyStore.textService.wrap(key, params, defaultValue)];
4788
+ case 3: return [2 /*return*/, this.dependencyStore.textService.translate(key, params, undefined, undefined, defaultValue)];
4789
+ }
4790
+ });
4791
+ });
4792
+ };
4793
+ Tolgee.prototype.instant = function (keyOrProps, params, noWrap, orEmpty, defaultValue) {
4794
+ if (params === void 0) { params = {}; }
4795
+ if (noWrap === void 0) { noWrap = false; }
4796
+ var key = typeof keyOrProps === 'string' ? keyOrProps : keyOrProps.key;
4797
+ if (typeof keyOrProps === 'object') {
4798
+ var props = keyOrProps;
4799
+ // if values are not provided in props object, get them from function
4800
+ // params defaults
4801
+ params = props.params !== undefined ? props.params : params;
4802
+ noWrap = props.noWrap !== undefined ? props.noWrap : noWrap;
4803
+ defaultValue =
4804
+ props.defaultValue !== undefined ? props.defaultValue : defaultValue;
4805
+ orEmpty = props.orEmpty !== undefined ? props.orEmpty : orEmpty;
4806
+ }
4807
+ if (this.properties.config.mode === 'development' && !noWrap) {
4808
+ return this.dependencyStore.textService.wrap(key, params, defaultValue);
4809
+ }
4810
+ return this.dependencyStore.textService.instant(key, params, undefined, orEmpty, defaultValue);
4811
+ };
4412
4812
  Tolgee.prototype.loadScopes = function () {
4413
4813
  return __awaiter(this, void 0, void 0, function () {
4414
4814
  var _a;
@@ -4430,8 +4830,10 @@
4430
4830
  return Tolgee;
4431
4831
  }());
4432
4832
 
4833
+ exports.TOLGEE_WRAPPED_ONLY_DATA_ATTRIBUTE = TOLGEE_WRAPPED_ONLY_DATA_ATTRIBUTE;
4433
4834
  exports.Tolgee = Tolgee;
4434
4835
  exports.TolgeeConfig = TolgeeConfig;
4836
+ exports.TranslationData = TranslationData;
4435
4837
 
4436
4838
  Object.defineProperty(exports, '__esModule', { value: true });
4437
4839