@tolgee/core 3.2.0 → 3.3.0-prerelease-7dd4060.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1090,37 +1090,38 @@
1090
1090
  }); }); });
1091
1091
  };
1092
1092
  TranslationHighlighter.prototype.getRenderer = function () {
1093
+ var _a;
1093
1094
  return __awaiter(this, void 0, void 0, function () {
1094
1095
  var possibleProviders, possibleProviders_1, possibleProviders_1_1, possibleProvider, constructorProvider, constructor, constructor, e_2_1;
1095
- var e_2, _a;
1096
- return __generator(this, function (_b) {
1097
- switch (_b.label) {
1096
+ var e_2, _b;
1097
+ return __generator(this, function (_c) {
1098
+ switch (_c.label) {
1098
1099
  case 0:
1099
1100
  if (!(this._renderer === undefined)) return [3 /*break*/, 11];
1100
1101
  possibleProviders = [
1101
1102
  this.dependencies.properties.config.ui,
1102
- window['@tolgee/ui'],
1103
+ (_a = window['@tolgee/ui']) === null || _a === void 0 ? void 0 : _a.UI,
1103
1104
  ];
1104
- _b.label = 1;
1105
+ _c.label = 1;
1105
1106
  case 1:
1106
- _b.trys.push([1, 8, 9, 10]);
1107
+ _c.trys.push([1, 8, 9, 10]);
1107
1108
  possibleProviders_1 = __values(possibleProviders), possibleProviders_1_1 = possibleProviders_1.next();
1108
- _b.label = 2;
1109
+ _c.label = 2;
1109
1110
  case 2:
1110
1111
  if (!!possibleProviders_1_1.done) return [3 /*break*/, 7];
1111
1112
  possibleProvider = possibleProviders_1_1.value;
1112
1113
  if (!(typeof possibleProvider === 'function')) return [3 /*break*/, 6];
1113
- _b.label = 3;
1114
+ _c.label = 3;
1114
1115
  case 3:
1115
- _b.trys.push([3, 5, , 6]);
1116
+ _c.trys.push([3, 5, , 6]);
1116
1117
  constructorProvider = possibleProvider;
1117
1118
  return [4 /*yield*/, constructorProvider()];
1118
1119
  case 4:
1119
- constructor = _b.sent();
1120
+ constructor = _c.sent();
1120
1121
  this._renderer = new constructor(this.dependencies);
1121
1122
  return [3 /*break*/, 6];
1122
1123
  case 5:
1123
- _b.sent();
1124
+ _c.sent();
1124
1125
  constructor = possibleProvider;
1125
1126
  this._renderer = new constructor(this.dependencies);
1126
1127
  return [3 /*break*/, 6];
@@ -1129,12 +1130,12 @@
1129
1130
  return [3 /*break*/, 2];
1130
1131
  case 7: return [3 /*break*/, 10];
1131
1132
  case 8:
1132
- e_2_1 = _b.sent();
1133
+ e_2_1 = _c.sent();
1133
1134
  e_2 = { error: e_2_1 };
1134
1135
  return [3 /*break*/, 10];
1135
1136
  case 9:
1136
1137
  try {
1137
- if (possibleProviders_1_1 && !possibleProviders_1_1.done && (_a = possibleProviders_1.return)) _a.call(possibleProviders_1);
1138
+ if (possibleProviders_1_1 && !possibleProviders_1_1.done && (_b = possibleProviders_1.return)) _b.call(possibleProviders_1);
1138
1139
  }
1139
1140
  finally { if (e_2) throw e_2.error; }
1140
1141
  return [7 /*endfinally*/];
@@ -1144,7 +1145,7 @@
1144
1145
  console.warn('Tolgee UI is not provided. To translate interactively provide tolgee ui constructor to "ui" configuration property. ' +
1145
1146
  'To disable highlighting use production mode.');
1146
1147
  }
1147
- _b.label = 11;
1148
+ _c.label = 11;
1148
1149
  case 11: return [2 /*return*/, this._renderer];
1149
1150
  }
1150
1151
  });
@@ -1614,6 +1615,8 @@
1614
1615
  return CoreService;
1615
1616
  }());
1616
1617
 
1618
+ var API_KEY_LOCAL_STORAGE = '__tolgee_apiKey';
1619
+ var API_URL_LOCAL_STORAGE = '__tolgee_apiUrl';
1617
1620
  var DEFAULT_TARGET_ELEMENT_SUPPLIER = function () {
1618
1621
  if (typeof document !== 'undefined') {
1619
1622
  return document.body;
@@ -1621,7 +1624,6 @@
1621
1624
  };
1622
1625
  var TolgeeConfig = /** @class */ (function () {
1623
1626
  function TolgeeConfig(config) {
1624
- this.apiUrl = 'https://app.tolgee.io';
1625
1627
  this.inputPrefix = '%-%tolgee:';
1626
1628
  this.inputSuffix = '%-%';
1627
1629
  this.defaultLanguage = 'en';
@@ -1663,6 +1665,12 @@
1663
1665
  },
1664
1666
  });
1665
1667
  Object.assign(this, config || {});
1668
+ if (typeof sessionStorage !== 'undefined') {
1669
+ this.apiUrl =
1670
+ sessionStorage.getItem(API_URL_LOCAL_STORAGE) || this.apiUrl;
1671
+ this.apiKey =
1672
+ sessionStorage.getItem(API_KEY_LOCAL_STORAGE) || this.apiKey;
1673
+ }
1666
1674
  if (this._targetElement === undefined) {
1667
1675
  this._targetElement = DEFAULT_TARGET_ELEMENT_SUPPLIER();
1668
1676
  }
@@ -1728,7 +1736,7 @@
1728
1736
  this.handshake = function () {
1729
1737
  var sharedConfiguration = __assign(__assign({}, _this.properties), { config: __assign(__assign({}, _this.properties.config), {
1730
1738
  //remove properties, which cannot be sent by window.postMessage
1731
- staticData: undefined, targetElement: undefined, _targetElement: undefined, ui: undefined }) });
1739
+ staticData: undefined, targetElement: undefined, _targetElement: undefined, ui: undefined }), uiPresent: Boolean(_this.properties.config.ui), uiVersion: "3.3.0-prerelease-7dd4060.0" });
1732
1740
  var timer = null;
1733
1741
  var ping = function () {
1734
1742
  _this.messages.send('TOLGEE_READY', sharedConfiguration);
@@ -3043,28 +3051,40 @@
3043
3051
  };
3044
3052
  Tolgee.prototype.run = function () {
3045
3053
  return __awaiter(this, void 0, void 0, function () {
3054
+ var e_1;
3046
3055
  return __generator(this, function (_a) {
3047
3056
  switch (_a.label) {
3048
3057
  case 0:
3049
3058
  this.dependencyService.run();
3050
- if (!(this.properties.config.mode === 'development')) return [3 /*break*/, 2];
3051
- return [4 /*yield*/, this.coreService.loadApiKeyDetails()];
3059
+ if (!(this.properties.config.mode === 'development')) return [3 /*break*/, 4];
3060
+ _a.label = 1;
3052
3061
  case 1:
3062
+ _a.trys.push([1, 3, , 4]);
3063
+ return [4 /*yield*/, this.coreService.loadApiKeyDetails()];
3064
+ case 2:
3053
3065
  _a.sent();
3054
- _a.label = 2;
3055
- case 2: return [4 /*yield*/, this.dependencyService.translationService.loadTranslations()];
3066
+ return [3 /*break*/, 4];
3056
3067
  case 3:
3068
+ e_1 = _a.sent();
3069
+ // eslint-disable-next-line no-console
3070
+ console.error("Couldn't connect to tolgee");
3071
+ // eslint-disable-next-line no-console
3072
+ console.error(e_1);
3073
+ this.properties.config.mode = 'production';
3074
+ return [3 /*break*/, 4];
3075
+ case 4: return [4 /*yield*/, this.dependencyService.translationService.loadTranslations()];
3076
+ case 5:
3057
3077
  _a.sent();
3058
3078
  return [4 /*yield*/, this.dependencyService.pluginManager.run()];
3059
- case 4:
3079
+ case 6:
3060
3080
  _a.sent();
3061
- if (!this.properties.config.preloadFallback) return [3 /*break*/, 6];
3081
+ if (!this.properties.config.preloadFallback) return [3 /*break*/, 8];
3062
3082
  return [4 /*yield*/, this.dependencyService.translationService.loadTranslations(this.properties.config.fallbackLanguage)];
3063
- case 5:
3064
- _a.sent();
3065
- _a.label = 6;
3066
- case 6: return [4 /*yield*/, this.refresh()];
3067
3083
  case 7:
3084
+ _a.sent();
3085
+ _a.label = 8;
3086
+ case 8: return [4 /*yield*/, this.refresh()];
3087
+ case 9:
3068
3088
  _a.sent();
3069
3089
  if (this.properties.config.watch) {
3070
3090
  this.dependencyService.observer.observe();