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