@tolgee/core 4.5.0 → 4.6.0-rc.03177a3.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.
Files changed (60) hide show
  1. package/dist/tolgee.cjs.js +139 -109
  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.esm.js +1 -1
  6. package/dist/tolgee.esm.js.map +1 -1
  7. package/dist/tolgee.umd.js +139 -109
  8. package/dist/tolgee.umd.js.map +1 -1
  9. package/dist/tolgee.umd.min.js +1 -1
  10. package/dist/tolgee.umd.min.js.map +1 -1
  11. package/lib/Constants/Global.d.ts +0 -0
  12. package/lib/Constants/ModifierKey.d.ts +0 -0
  13. package/lib/Errors/ApiHttpError.d.ts +0 -0
  14. package/lib/Observer.d.ts +0 -0
  15. package/lib/Properties.d.ts +0 -0
  16. package/lib/Tolgee.d.ts +0 -0
  17. package/lib/TolgeeConfig.d.ts +0 -0
  18. package/lib/helpers/NodeHelper.d.ts +0 -0
  19. package/lib/helpers/TextHelper.d.ts +0 -0
  20. package/lib/helpers/commonTypes.d.ts +0 -0
  21. package/lib/helpers/encoderPolyfill.d.ts +0 -0
  22. package/lib/helpers/secret.d.ts +0 -0
  23. package/lib/helpers/sleep.d.ts +0 -0
  24. package/lib/highlighter/HighlightFunctionsInitializer.d.ts +1 -0
  25. package/lib/highlighter/MouseEventHandler.d.ts +17 -13
  26. package/lib/highlighter/TranslationHighlighter.d.ts +1 -1
  27. package/lib/index.d.ts +0 -0
  28. package/lib/modules/IcuFormatter.d.ts +0 -0
  29. package/lib/modules/index.d.ts +0 -0
  30. package/lib/services/ApiHttpService.d.ts +0 -0
  31. package/lib/services/CoreService.d.ts +0 -0
  32. package/lib/services/DependencyService.d.ts +0 -0
  33. package/lib/services/ElementRegistrar.d.ts +0 -0
  34. package/lib/services/EventEmitter.d.ts +0 -0
  35. package/lib/services/EventService.d.ts +0 -0
  36. package/lib/services/ModuleService.d.ts +0 -0
  37. package/lib/services/ScreenshotService.d.ts +0 -0
  38. package/lib/services/Subscription.d.ts +0 -0
  39. package/lib/services/TextService.d.ts +0 -0
  40. package/lib/services/TranslationService.d.ts +0 -0
  41. package/lib/toolsManager/Messages.d.ts +0 -0
  42. package/lib/toolsManager/PluginManager.d.ts +0 -0
  43. package/lib/types/DTOs.d.ts +0 -0
  44. package/lib/types/apiSchema.generated.d.ts +0 -0
  45. package/lib/types.d.ts +1 -3
  46. package/lib/wrappers/AbstractWrapper.d.ts +0 -0
  47. package/lib/wrappers/NodeHandler.d.ts +0 -0
  48. package/lib/wrappers/WrappedHandler.d.ts +0 -0
  49. package/lib/wrappers/invisible/AttributeHandler.d.ts +0 -0
  50. package/lib/wrappers/invisible/Coder.d.ts +0 -0
  51. package/lib/wrappers/invisible/ContentHandler.d.ts +0 -0
  52. package/lib/wrappers/invisible/CoreHandler.d.ts +0 -0
  53. package/lib/wrappers/invisible/InvisibleWrapper.d.ts +0 -0
  54. package/lib/wrappers/invisible/ValueMemory.d.ts +0 -0
  55. package/lib/wrappers/text/AttributeHandler.d.ts +0 -0
  56. package/lib/wrappers/text/Coder.d.ts +0 -0
  57. package/lib/wrappers/text/ContentHandler.d.ts +0 -0
  58. package/lib/wrappers/text/CoreHandler.d.ts +0 -0
  59. package/lib/wrappers/text/TextWrapper.d.ts +0 -0
  60. package/package.json +5 -5
@@ -913,131 +913,144 @@ exports.ModifierKey = void 0;
913
913
  ModifierKey[ModifierKey["Meta"] = 3] = "Meta";
914
914
  })(exports.ModifierKey || (exports.ModifierKey = {}));
915
915
 
916
+ var eCapture = {
917
+ capture: true,
918
+ };
919
+ var ePassive = {
920
+ capture: true,
921
+ passive: true,
922
+ };
916
923
  var MouseEventHandler = /** @class */ (function () {
917
- function MouseEventHandler(properties) {
924
+ function MouseEventHandler(dependencies) {
918
925
  var _this = this;
919
- this.properties = properties;
926
+ this.dependencies = dependencies;
920
927
  this.keysDown = new Set();
921
- this.mouseOn = new Set();
922
928
  this.mouseOnChanged = new EventEmitterImpl();
923
929
  this.keysChanged = new EventEmitterImpl();
924
- this.onConditionsChanged = function () {
925
- _this.unhighlight();
926
- if (_this.areKeysDown() && _this.getMouseOn()) {
927
- _this.highlight();
930
+ this.highlight = function (el) {
931
+ if (_this.highlighted !== el) {
932
+ _this.unhighlight();
933
+ if (el) {
934
+ el._tolgee.preventClean = true;
935
+ el._tolgee.highlight();
936
+ _this.highlighted = el;
937
+ _this.mouseOnChanged.emit(el);
938
+ }
928
939
  }
929
940
  };
930
- this.highlight = function () {
931
- _this.getMouseOn()._tolgee.highlight();
932
- _this.highlighted = _this.getMouseOn();
933
- };
934
941
  this.unhighlight = function () {
935
942
  if (_this.highlighted) {
943
+ _this.highlighted._tolgee.preventClean = false;
936
944
  _this.highlighted._tolgee.unhighlight();
937
- _this.highlighted = null;
938
- }
939
- };
940
- this.onMouseOut = function (element) {
941
- element._tolgee.preventClean = false;
942
- _this.mouseOn.delete(element);
943
- _this.mouseOnChanged.emit(_this.getMouseOn());
944
- };
945
- this.onMouseOver = function (element) {
946
- _this.filterMouseOn();
947
- element._tolgee.preventClean = true;
948
- _this.mouseOn.delete(element); //to get in to last place
949
- _this.mouseOn.add(element);
950
- _this.mouseOnChanged.emit(_this.getMouseOn());
951
- };
952
- }
953
- MouseEventHandler.prototype.run = function () {
954
- if (typeof window !== 'undefined') {
955
- this.initKeyListener();
956
- return;
957
- }
958
- };
959
- MouseEventHandler.prototype.handle = function (element, onclick) {
960
- var _this = this;
961
- if (element._tolgee.listeningForHighlighting) {
962
- // eslint-disable-next-line no-console
963
- console.error('Element is already listening mouse events! This is probably bug in tolgee');
964
- return;
965
- }
966
- element._tolgee.listeningForHighlighting = true;
967
- this.initEventListeners(element, onclick);
968
- this.mouseOnChanged.subscribe(function () {
969
- if (_this.highlighted !== _this.getMouseOn()) {
970
- _this.onConditionsChanged();
971
- }
972
- });
973
- this.keysChanged.subscribe(function () {
974
- _this.onConditionsChanged();
975
- });
976
- };
977
- MouseEventHandler.prototype.initEventListeners = function (element, onclick) {
978
- var _this = this;
979
- var onMouseOver = function () { return _this.onMouseOver(element); };
980
- var onMouseOut = function () { return _this.onMouseOut(element); };
981
- var onClick = function (e) {
982
- if (_this.areKeysDown() && _this.highlighted === e.currentTarget) {
983
- e.stopPropagation();
984
- e.preventDefault();
985
- onclick(e);
945
+ _this.highlighted = undefined;
946
+ _this.mouseOnChanged.emit(_this.highlighted);
986
947
  }
987
948
  };
988
- element.addEventListener('mouseover', onMouseOver);
989
- element.addEventListener('click', onClick, { capture: true });
990
- var onMouseDownOrUp = function (e) {
949
+ this.blockEvents = function (e) {
991
950
  if (_this.areKeysDown()) {
992
951
  e.stopPropagation();
993
952
  e.preventDefault();
994
953
  }
995
954
  };
996
- element.addEventListener('mousedown', onMouseDownOrUp);
997
- element.addEventListener('mouseup', onMouseDownOrUp);
998
- element.addEventListener('mouseout', onMouseOut);
999
- element._tolgee.removeAllEventListeners = function () {
1000
- element.removeEventListener('mousedown', onMouseDownOrUp);
1001
- element.removeEventListener('mouseup', onMouseDownOrUp);
1002
- element.removeEventListener('mouseover', onMouseOver);
1003
- element.removeEventListener('click', onClick, { capture: true });
1004
- element.removeEventListener('mouseout', onMouseOut);
955
+ this.onMouseMove = function (e) {
956
+ _this.updateCursorPosition({ x: e.clientX, y: e.clientY });
1005
957
  };
1006
- };
1007
- MouseEventHandler.prototype.getMouseOn = function () {
1008
- var mouseOnArray = Array.from(this.mouseOn);
1009
- return mouseOnArray.length ? mouseOnArray[0] : undefined;
1010
- };
1011
- MouseEventHandler.prototype.initKeyListener = function () {
1012
- var _this = this;
1013
- window.addEventListener('blur', function () {
958
+ this.onBlur = function () {
1014
959
  _this.keysDown = new Set();
1015
960
  _this.keysChanged.emit(_this.areKeysDown());
1016
- });
1017
- window.addEventListener('keydown', function (e) {
961
+ _this.updateHighlight();
962
+ };
963
+ this.onKeyDown = function (e) {
1018
964
  var modifierKey = exports.ModifierKey[e.key];
1019
965
  if (modifierKey !== undefined) {
1020
966
  _this.keysDown.add(modifierKey);
1021
967
  _this.keysChanged.emit(_this.areKeysDown());
1022
968
  }
1023
- });
1024
- window.addEventListener('keyup', function (e) {
969
+ _this.updateHighlight();
970
+ };
971
+ this.onKeyUp = function (e) {
1025
972
  _this.keysDown.delete(exports.ModifierKey[e.key]);
1026
973
  _this.keysChanged.emit(_this.areKeysDown());
1027
- });
1028
- };
1029
- MouseEventHandler.prototype.filterMouseOn = function () {
1030
- var _this = this;
1031
- this.mouseOn.forEach(function (el) {
1032
- if (!document.contains(el)) {
1033
- _this.mouseOn.delete(el);
974
+ _this.updateHighlight();
975
+ };
976
+ this.onScroll = function () {
977
+ var _a;
978
+ (_a = _this.highlighted) === null || _a === void 0 ? void 0 : _a._tolgee.highlight();
979
+ };
980
+ this.onClick = function (e) {
981
+ _this.blockEvents(e);
982
+ if (_this.areKeysDown()) {
983
+ var element = _this.getClosestTolgeeElement(e.target);
984
+ if (element && element === _this.highlighted) {
985
+ _this.dependencies.translationHighlighter.translationEdit(e, element);
986
+ _this.unhighlight();
987
+ }
1034
988
  }
1035
- });
989
+ };
990
+ }
991
+ MouseEventHandler.prototype.run = function () {
992
+ if (typeof window !== 'undefined') {
993
+ this.initEventListeners();
994
+ }
995
+ };
996
+ MouseEventHandler.prototype.stop = function () {
997
+ if (typeof window !== 'undefined') {
998
+ this.removeEventListeners();
999
+ }
1000
+ };
1001
+ MouseEventHandler.prototype.updateHighlight = function () {
1002
+ var position = this.cursorPosition;
1003
+ var newHighlighted;
1004
+ if (position && this.areKeysDown()) {
1005
+ newHighlighted = this.getClosestTolgeeElement(document.elementFromPoint(position.x, position.y));
1006
+ }
1007
+ this.highlight(newHighlighted);
1008
+ };
1009
+ MouseEventHandler.prototype.updateCursorPosition = function (position) {
1010
+ this.cursorPosition = position;
1011
+ this.updateHighlight();
1012
+ };
1013
+ MouseEventHandler.prototype.initEventListeners = function () {
1014
+ window.addEventListener('blur', this.onBlur, eCapture);
1015
+ window.addEventListener('keydown', this.onKeyDown, eCapture);
1016
+ window.addEventListener('keyup', this.onKeyUp, eCapture);
1017
+ window.addEventListener('mousemove', this.onMouseMove, ePassive);
1018
+ window.addEventListener('scroll', this.onScroll, ePassive);
1019
+ window.addEventListener('click', this.onClick, eCapture);
1020
+ window.addEventListener('mouseenter', this.blockEvents, eCapture);
1021
+ window.addEventListener('mouseover', this.blockEvents, eCapture);
1022
+ window.addEventListener('mouseout', this.blockEvents, eCapture);
1023
+ window.addEventListener('mouseleave', this.blockEvents, eCapture);
1024
+ window.addEventListener('mousedown', this.blockEvents, eCapture);
1025
+ window.addEventListener('mouseup', this.blockEvents, eCapture);
1026
+ };
1027
+ MouseEventHandler.prototype.removeEventListeners = function () {
1028
+ window.removeEventListener('blur', this.onBlur, eCapture);
1029
+ window.removeEventListener('keydown', this.onKeyDown, eCapture);
1030
+ window.removeEventListener('keyup', this.onKeyUp, eCapture);
1031
+ window.removeEventListener('mousemove', this.onMouseMove, ePassive);
1032
+ window.removeEventListener('scroll', this.onScroll, ePassive);
1033
+ window.removeEventListener('click', this.onClick, eCapture);
1034
+ window.removeEventListener('mouseenter', this.blockEvents, eCapture);
1035
+ window.removeEventListener('mouseover', this.blockEvents, eCapture);
1036
+ window.removeEventListener('mouseout', this.blockEvents, eCapture);
1037
+ window.removeEventListener('mouseleave', this.blockEvents, eCapture);
1038
+ window.removeEventListener('mousedown', this.blockEvents, eCapture);
1039
+ window.removeEventListener('mouseup', this.blockEvents, eCapture);
1040
+ };
1041
+ MouseEventHandler.prototype.getClosestTolgeeElement = function (element) {
1042
+ if (element === null || element === void 0 ? void 0 : element._tolgee) {
1043
+ return element;
1044
+ }
1045
+ if (element === null || element === void 0 ? void 0 : element.parentElement) {
1046
+ return this.getClosestTolgeeElement(element.parentElement);
1047
+ }
1048
+ return undefined;
1036
1049
  };
1037
1050
  MouseEventHandler.prototype.areKeysDown = function () {
1038
1051
  var e_1, _a;
1039
1052
  try {
1040
- for (var _b = __values(this.properties.config.highlightKeys), _c = _b.next(); !_c.done; _c = _b.next()) {
1053
+ for (var _b = __values(this.dependencies.properties.config.highlightKeys), _c = _b.next(); !_c.done; _c = _b.next()) {
1041
1054
  var key = _c.value;
1042
1055
  if (!this.keysDown.has(key)) {
1043
1056
  return false;
@@ -1089,14 +1102,11 @@ var TranslationHighlighter = /** @class */ (function () {
1089
1102
  }); })), false); }, []);
1090
1103
  };
1091
1104
  TranslationHighlighter.prototype.listen = function (element) {
1092
- var _this = this;
1093
1105
  this.dependencies.highlightFunctionInitializer.initFunctions(element);
1094
- this.dependencies.mouseEventHandler.handle(element, function (e) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
1095
- switch (_a.label) {
1096
- case 0: return [4 /*yield*/, this.translationEdit(e, element)];
1097
- case 1: return [2 /*return*/, _a.sent()];
1098
- }
1099
- }); }); });
1106
+ // this.dependencies.mouseEventHandler.handle(
1107
+ // element,
1108
+ // async (e) => await this.translationEdit(e, element)
1109
+ // );
1100
1110
  };
1101
1111
  TranslationHighlighter.prototype.getRenderer = function () {
1102
1112
  return __awaiter(this, void 0, void 0, function () {
@@ -1399,9 +1409,6 @@ var ElementRegistrar = /** @class */ (function () {
1399
1409
  };
1400
1410
  ElementRegistrar.prototype.cleanElement = function (element) {
1401
1411
  if (!element._tolgee.preventClean) {
1402
- if (typeof element._tolgee.removeAllEventListeners === 'function') {
1403
- element._tolgee.removeAllEventListeners();
1404
- }
1405
1412
  element.removeAttribute(TOLGEE_ATTRIBUTE_NAME);
1406
1413
  delete element._tolgee;
1407
1414
  this.registeredElements.delete(element);
@@ -1670,7 +1677,7 @@ var TolgeeConfig = /** @class */ (function () {
1670
1677
  this.highlightKeys = [exports.ModifierKey.Alt];
1671
1678
  this.passToParent = ['option', 'optgroup'];
1672
1679
  this.restrictedElements = ['script', 'style'];
1673
- this.highlightColor = 'rgb(224 240 255)';
1680
+ this.highlightColor = 'rgb(255, 0, 0)';
1674
1681
  this.wrapperMode = 'text';
1675
1682
  /**
1676
1683
  * When true, fallback language will be preloaded on Tolgee.run
@@ -1771,7 +1778,7 @@ var PluginManager = /** @class */ (function () {
1771
1778
  this.handshake = function () {
1772
1779
  var sharedConfiguration = __assign(__assign({}, _this.properties), { config: __assign(__assign({}, _this.properties.config), {
1773
1780
  //remove properties, which cannot be sent by window.postMessage
1774
- staticData: undefined, targetElement: undefined, _targetElement: undefined, ui: undefined }), uiPresent: Boolean(_this.properties.config.ui), uiVersion: "4.5.0" });
1781
+ staticData: undefined, targetElement: undefined, _targetElement: undefined, ui: undefined }), uiPresent: Boolean(_this.properties.config.ui), uiVersion: "4.6.0-rc.03177a3.0" });
1775
1782
  var timer = null;
1776
1783
  var ping = function () {
1777
1784
  _this.messages.send('TOLGEE_READY', sharedConfiguration);
@@ -1871,6 +1878,7 @@ var Messages = /** @class */ (function () {
1871
1878
  return Messages;
1872
1879
  }());
1873
1880
 
1881
+ var BORDER_WIDTH = 5;
1874
1882
  var HighlightFunctionsInitializer = /** @class */ (function () {
1875
1883
  function HighlightFunctionsInitializer(properties) {
1876
1884
  this.properties = properties;
@@ -1882,13 +1890,34 @@ var HighlightFunctionsInitializer = /** @class */ (function () {
1882
1890
  HighlightFunctionsInitializer.prototype.initHighlightFunction = function (element) {
1883
1891
  var _this = this;
1884
1892
  element._tolgee.highlight = function () {
1885
- element._tolgee.initialBackgroundColor = element.style.backgroundColor;
1886
- element.style.backgroundColor = _this.properties.config.highlightColor;
1893
+ if (!element.isConnected) {
1894
+ return;
1895
+ }
1896
+ var highlightEl = element._tolgee.highlightEl;
1897
+ if (!highlightEl) {
1898
+ highlightEl = document.createElement('div');
1899
+ highlightEl.style.pointerEvents = 'none';
1900
+ highlightEl.style.border = "".concat(BORDER_WIDTH, "px solid ").concat(_this.properties.config.highlightColor);
1901
+ highlightEl.style.position = 'fixed';
1902
+ highlightEl.style.boxSizing = 'border-box';
1903
+ highlightEl.style.zIndex = String(Number.MAX_SAFE_INTEGER);
1904
+ highlightEl.style.contain = 'layout';
1905
+ element._tolgee.highlightEl = highlightEl;
1906
+ document.body.appendChild(highlightEl);
1907
+ }
1908
+ var shape = element.getBoundingClientRect();
1909
+ highlightEl.style.top = shape.top - BORDER_WIDTH + 'px';
1910
+ highlightEl.style.left = shape.left - BORDER_WIDTH + 'px';
1911
+ highlightEl.style.width = shape.width + 2 * BORDER_WIDTH + 'px';
1912
+ highlightEl.style.height = shape.height + 2 * BORDER_WIDTH + 'px';
1913
+ highlightEl.style.display = 'block';
1887
1914
  };
1888
1915
  };
1889
1916
  HighlightFunctionsInitializer.prototype.initUnhighlightFunction = function (element) {
1890
1917
  element._tolgee.unhighlight = function () {
1891
- element.style.backgroundColor = element._tolgee.initialBackgroundColor;
1918
+ var _a;
1919
+ (_a = element._tolgee.highlightEl) === null || _a === void 0 ? void 0 : _a.remove();
1920
+ element._tolgee.highlightEl = null;
1892
1921
  };
1893
1922
  };
1894
1923
  return HighlightFunctionsInitializer;
@@ -2912,7 +2941,7 @@ var DependencyService = /** @class */ (function () {
2912
2941
  this.properties = new Properties();
2913
2942
  this.eventService = new EventService();
2914
2943
  this.apiHttpService = new ApiHttpService(this.properties);
2915
- this.mouseEventHandler = new MouseEventHandler(this.properties);
2944
+ this.mouseEventHandler = new MouseEventHandler(this);
2916
2945
  this.moduleService = new ModuleService();
2917
2946
  this.coreService = new CoreService(this.properties, this.apiHttpService);
2918
2947
  this.screenshotService = new ScreenshotService(this.coreService, this.apiHttpService);
@@ -2929,6 +2958,7 @@ var DependencyService = /** @class */ (function () {
2929
2958
  this.stop = function () {
2930
2959
  _this.observer.stopObserving();
2931
2960
  _this.elementRegistrar.cleanAll();
2961
+ _this.mouseEventHandler.stop();
2932
2962
  NodeHelper.unmarkElementAsTargetElement(_this.properties.config.targetElement);
2933
2963
  };
2934
2964
  this.translationHighlighter.pluginManager = this.pluginManager;