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