@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
@@ -915,131 +915,144 @@
915
915
  ModifierKey[ModifierKey["Meta"] = 3] = "Meta";
916
916
  })(exports.ModifierKey || (exports.ModifierKey = {}));
917
917
 
918
+ var eCapture = {
919
+ capture: true,
920
+ };
921
+ var ePassive = {
922
+ capture: true,
923
+ passive: true,
924
+ };
918
925
  var MouseEventHandler = /** @class */ (function () {
919
- function MouseEventHandler(properties) {
926
+ function MouseEventHandler(dependencies) {
920
927
  var _this = this;
921
- this.properties = properties;
928
+ this.dependencies = dependencies;
922
929
  this.keysDown = new Set();
923
- this.mouseOn = new Set();
924
930
  this.mouseOnChanged = new EventEmitterImpl();
925
931
  this.keysChanged = new EventEmitterImpl();
926
- this.onConditionsChanged = function () {
927
- _this.unhighlight();
928
- if (_this.areKeysDown() && _this.getMouseOn()) {
929
- _this.highlight();
932
+ this.highlight = function (el) {
933
+ if (_this.highlighted !== el) {
934
+ _this.unhighlight();
935
+ if (el) {
936
+ el._tolgee.preventClean = true;
937
+ el._tolgee.highlight();
938
+ _this.highlighted = el;
939
+ _this.mouseOnChanged.emit(el);
940
+ }
930
941
  }
931
942
  };
932
- this.highlight = function () {
933
- _this.getMouseOn()._tolgee.highlight();
934
- _this.highlighted = _this.getMouseOn();
935
- };
936
943
  this.unhighlight = function () {
937
944
  if (_this.highlighted) {
945
+ _this.highlighted._tolgee.preventClean = false;
938
946
  _this.highlighted._tolgee.unhighlight();
939
- _this.highlighted = null;
940
- }
941
- };
942
- this.onMouseOut = function (element) {
943
- element._tolgee.preventClean = false;
944
- _this.mouseOn.delete(element);
945
- _this.mouseOnChanged.emit(_this.getMouseOn());
946
- };
947
- this.onMouseOver = function (element) {
948
- _this.filterMouseOn();
949
- element._tolgee.preventClean = true;
950
- _this.mouseOn.delete(element); //to get in to last place
951
- _this.mouseOn.add(element);
952
- _this.mouseOnChanged.emit(_this.getMouseOn());
953
- };
954
- }
955
- MouseEventHandler.prototype.run = function () {
956
- if (typeof window !== 'undefined') {
957
- this.initKeyListener();
958
- return;
959
- }
960
- };
961
- MouseEventHandler.prototype.handle = function (element, onclick) {
962
- var _this = this;
963
- if (element._tolgee.listeningForHighlighting) {
964
- // eslint-disable-next-line no-console
965
- console.error('Element is already listening mouse events! This is probably bug in tolgee');
966
- return;
967
- }
968
- element._tolgee.listeningForHighlighting = true;
969
- this.initEventListeners(element, onclick);
970
- this.mouseOnChanged.subscribe(function () {
971
- if (_this.highlighted !== _this.getMouseOn()) {
972
- _this.onConditionsChanged();
973
- }
974
- });
975
- this.keysChanged.subscribe(function () {
976
- _this.onConditionsChanged();
977
- });
978
- };
979
- MouseEventHandler.prototype.initEventListeners = function (element, onclick) {
980
- var _this = this;
981
- var onMouseOver = function () { return _this.onMouseOver(element); };
982
- var onMouseOut = function () { return _this.onMouseOut(element); };
983
- var onClick = function (e) {
984
- if (_this.areKeysDown() && _this.highlighted === e.currentTarget) {
985
- e.stopPropagation();
986
- e.preventDefault();
987
- onclick(e);
947
+ _this.highlighted = undefined;
948
+ _this.mouseOnChanged.emit(_this.highlighted);
988
949
  }
989
950
  };
990
- element.addEventListener('mouseover', onMouseOver);
991
- element.addEventListener('click', onClick, { capture: true });
992
- var onMouseDownOrUp = function (e) {
951
+ this.blockEvents = function (e) {
993
952
  if (_this.areKeysDown()) {
994
953
  e.stopPropagation();
995
954
  e.preventDefault();
996
955
  }
997
956
  };
998
- element.addEventListener('mousedown', onMouseDownOrUp);
999
- element.addEventListener('mouseup', onMouseDownOrUp);
1000
- element.addEventListener('mouseout', onMouseOut);
1001
- element._tolgee.removeAllEventListeners = function () {
1002
- element.removeEventListener('mousedown', onMouseDownOrUp);
1003
- element.removeEventListener('mouseup', onMouseDownOrUp);
1004
- element.removeEventListener('mouseover', onMouseOver);
1005
- element.removeEventListener('click', onClick, { capture: true });
1006
- element.removeEventListener('mouseout', onMouseOut);
957
+ this.onMouseMove = function (e) {
958
+ _this.updateCursorPosition({ x: e.clientX, y: e.clientY });
1007
959
  };
1008
- };
1009
- MouseEventHandler.prototype.getMouseOn = function () {
1010
- var mouseOnArray = Array.from(this.mouseOn);
1011
- return mouseOnArray.length ? mouseOnArray[0] : undefined;
1012
- };
1013
- MouseEventHandler.prototype.initKeyListener = function () {
1014
- var _this = this;
1015
- window.addEventListener('blur', function () {
960
+ this.onBlur = function () {
1016
961
  _this.keysDown = new Set();
1017
962
  _this.keysChanged.emit(_this.areKeysDown());
1018
- });
1019
- window.addEventListener('keydown', function (e) {
963
+ _this.updateHighlight();
964
+ };
965
+ this.onKeyDown = function (e) {
1020
966
  var modifierKey = exports.ModifierKey[e.key];
1021
967
  if (modifierKey !== undefined) {
1022
968
  _this.keysDown.add(modifierKey);
1023
969
  _this.keysChanged.emit(_this.areKeysDown());
1024
970
  }
1025
- });
1026
- window.addEventListener('keyup', function (e) {
971
+ _this.updateHighlight();
972
+ };
973
+ this.onKeyUp = function (e) {
1027
974
  _this.keysDown.delete(exports.ModifierKey[e.key]);
1028
975
  _this.keysChanged.emit(_this.areKeysDown());
1029
- });
1030
- };
1031
- MouseEventHandler.prototype.filterMouseOn = function () {
1032
- var _this = this;
1033
- this.mouseOn.forEach(function (el) {
1034
- if (!document.contains(el)) {
1035
- _this.mouseOn.delete(el);
976
+ _this.updateHighlight();
977
+ };
978
+ this.onScroll = function () {
979
+ var _a;
980
+ (_a = _this.highlighted) === null || _a === void 0 ? void 0 : _a._tolgee.highlight();
981
+ };
982
+ this.onClick = function (e) {
983
+ _this.blockEvents(e);
984
+ if (_this.areKeysDown()) {
985
+ var element = _this.getClosestTolgeeElement(e.target);
986
+ if (element && element === _this.highlighted) {
987
+ _this.dependencies.translationHighlighter.translationEdit(e, element);
988
+ _this.unhighlight();
989
+ }
1036
990
  }
1037
- });
991
+ };
992
+ }
993
+ MouseEventHandler.prototype.run = function () {
994
+ if (typeof window !== 'undefined') {
995
+ this.initEventListeners();
996
+ }
997
+ };
998
+ MouseEventHandler.prototype.stop = function () {
999
+ if (typeof window !== 'undefined') {
1000
+ this.removeEventListeners();
1001
+ }
1002
+ };
1003
+ MouseEventHandler.prototype.updateHighlight = function () {
1004
+ var position = this.cursorPosition;
1005
+ var newHighlighted;
1006
+ if (position && this.areKeysDown()) {
1007
+ newHighlighted = this.getClosestTolgeeElement(document.elementFromPoint(position.x, position.y));
1008
+ }
1009
+ this.highlight(newHighlighted);
1010
+ };
1011
+ MouseEventHandler.prototype.updateCursorPosition = function (position) {
1012
+ this.cursorPosition = position;
1013
+ this.updateHighlight();
1014
+ };
1015
+ MouseEventHandler.prototype.initEventListeners = function () {
1016
+ window.addEventListener('blur', this.onBlur, eCapture);
1017
+ window.addEventListener('keydown', this.onKeyDown, eCapture);
1018
+ window.addEventListener('keyup', this.onKeyUp, eCapture);
1019
+ window.addEventListener('mousemove', this.onMouseMove, ePassive);
1020
+ window.addEventListener('scroll', this.onScroll, ePassive);
1021
+ window.addEventListener('click', this.onClick, eCapture);
1022
+ window.addEventListener('mouseenter', this.blockEvents, eCapture);
1023
+ window.addEventListener('mouseover', this.blockEvents, eCapture);
1024
+ window.addEventListener('mouseout', this.blockEvents, eCapture);
1025
+ window.addEventListener('mouseleave', this.blockEvents, eCapture);
1026
+ window.addEventListener('mousedown', this.blockEvents, eCapture);
1027
+ window.addEventListener('mouseup', this.blockEvents, eCapture);
1028
+ };
1029
+ MouseEventHandler.prototype.removeEventListeners = function () {
1030
+ window.removeEventListener('blur', this.onBlur, eCapture);
1031
+ window.removeEventListener('keydown', this.onKeyDown, eCapture);
1032
+ window.removeEventListener('keyup', this.onKeyUp, eCapture);
1033
+ window.removeEventListener('mousemove', this.onMouseMove, ePassive);
1034
+ window.removeEventListener('scroll', this.onScroll, ePassive);
1035
+ window.removeEventListener('click', this.onClick, eCapture);
1036
+ window.removeEventListener('mouseenter', this.blockEvents, eCapture);
1037
+ window.removeEventListener('mouseover', this.blockEvents, eCapture);
1038
+ window.removeEventListener('mouseout', this.blockEvents, eCapture);
1039
+ window.removeEventListener('mouseleave', this.blockEvents, eCapture);
1040
+ window.removeEventListener('mousedown', this.blockEvents, eCapture);
1041
+ window.removeEventListener('mouseup', this.blockEvents, eCapture);
1042
+ };
1043
+ MouseEventHandler.prototype.getClosestTolgeeElement = function (element) {
1044
+ if (element === null || element === void 0 ? void 0 : element._tolgee) {
1045
+ return element;
1046
+ }
1047
+ if (element === null || element === void 0 ? void 0 : element.parentElement) {
1048
+ return this.getClosestTolgeeElement(element.parentElement);
1049
+ }
1050
+ return undefined;
1038
1051
  };
1039
1052
  MouseEventHandler.prototype.areKeysDown = function () {
1040
1053
  var e_1, _a;
1041
1054
  try {
1042
- for (var _b = __values(this.properties.config.highlightKeys), _c = _b.next(); !_c.done; _c = _b.next()) {
1055
+ for (var _b = __values(this.dependencies.properties.config.highlightKeys), _c = _b.next(); !_c.done; _c = _b.next()) {
1043
1056
  var key = _c.value;
1044
1057
  if (!this.keysDown.has(key)) {
1045
1058
  return false;
@@ -1091,14 +1104,11 @@
1091
1104
  }); })), false); }, []);
1092
1105
  };
1093
1106
  TranslationHighlighter.prototype.listen = function (element) {
1094
- var _this = this;
1095
1107
  this.dependencies.highlightFunctionInitializer.initFunctions(element);
1096
- this.dependencies.mouseEventHandler.handle(element, function (e) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
1097
- switch (_a.label) {
1098
- case 0: return [4 /*yield*/, this.translationEdit(e, element)];
1099
- case 1: return [2 /*return*/, _a.sent()];
1100
- }
1101
- }); }); });
1108
+ // this.dependencies.mouseEventHandler.handle(
1109
+ // element,
1110
+ // async (e) => await this.translationEdit(e, element)
1111
+ // );
1102
1112
  };
1103
1113
  TranslationHighlighter.prototype.getRenderer = function () {
1104
1114
  return __awaiter(this, void 0, void 0, function () {
@@ -1401,9 +1411,6 @@
1401
1411
  };
1402
1412
  ElementRegistrar.prototype.cleanElement = function (element) {
1403
1413
  if (!element._tolgee.preventClean) {
1404
- if (typeof element._tolgee.removeAllEventListeners === 'function') {
1405
- element._tolgee.removeAllEventListeners();
1406
- }
1407
1414
  element.removeAttribute(TOLGEE_ATTRIBUTE_NAME);
1408
1415
  delete element._tolgee;
1409
1416
  this.registeredElements.delete(element);
@@ -1672,7 +1679,7 @@
1672
1679
  this.highlightKeys = [exports.ModifierKey.Alt];
1673
1680
  this.passToParent = ['option', 'optgroup'];
1674
1681
  this.restrictedElements = ['script', 'style'];
1675
- this.highlightColor = 'rgb(224 240 255)';
1682
+ this.highlightColor = 'rgb(255, 0, 0)';
1676
1683
  this.wrapperMode = 'text';
1677
1684
  /**
1678
1685
  * When true, fallback language will be preloaded on Tolgee.run
@@ -1773,7 +1780,7 @@
1773
1780
  this.handshake = function () {
1774
1781
  var sharedConfiguration = __assign(__assign({}, _this.properties), { config: __assign(__assign({}, _this.properties.config), {
1775
1782
  //remove properties, which cannot be sent by window.postMessage
1776
- staticData: undefined, targetElement: undefined, _targetElement: undefined, ui: undefined }), uiPresent: Boolean(_this.properties.config.ui), uiVersion: "4.5.0" });
1783
+ staticData: undefined, targetElement: undefined, _targetElement: undefined, ui: undefined }), uiPresent: Boolean(_this.properties.config.ui), uiVersion: "4.6.0-rc.03177a3.0" });
1777
1784
  var timer = null;
1778
1785
  var ping = function () {
1779
1786
  _this.messages.send('TOLGEE_READY', sharedConfiguration);
@@ -1873,6 +1880,7 @@
1873
1880
  return Messages;
1874
1881
  }());
1875
1882
 
1883
+ var BORDER_WIDTH = 5;
1876
1884
  var HighlightFunctionsInitializer = /** @class */ (function () {
1877
1885
  function HighlightFunctionsInitializer(properties) {
1878
1886
  this.properties = properties;
@@ -1884,13 +1892,34 @@
1884
1892
  HighlightFunctionsInitializer.prototype.initHighlightFunction = function (element) {
1885
1893
  var _this = this;
1886
1894
  element._tolgee.highlight = function () {
1887
- element._tolgee.initialBackgroundColor = element.style.backgroundColor;
1888
- element.style.backgroundColor = _this.properties.config.highlightColor;
1895
+ if (!element.isConnected) {
1896
+ return;
1897
+ }
1898
+ var highlightEl = element._tolgee.highlightEl;
1899
+ if (!highlightEl) {
1900
+ highlightEl = document.createElement('div');
1901
+ highlightEl.style.pointerEvents = 'none';
1902
+ highlightEl.style.border = "".concat(BORDER_WIDTH, "px solid ").concat(_this.properties.config.highlightColor);
1903
+ highlightEl.style.position = 'fixed';
1904
+ highlightEl.style.boxSizing = 'border-box';
1905
+ highlightEl.style.zIndex = String(Number.MAX_SAFE_INTEGER);
1906
+ highlightEl.style.contain = 'layout';
1907
+ element._tolgee.highlightEl = highlightEl;
1908
+ document.body.appendChild(highlightEl);
1909
+ }
1910
+ var shape = element.getBoundingClientRect();
1911
+ highlightEl.style.top = shape.top - BORDER_WIDTH + 'px';
1912
+ highlightEl.style.left = shape.left - BORDER_WIDTH + 'px';
1913
+ highlightEl.style.width = shape.width + 2 * BORDER_WIDTH + 'px';
1914
+ highlightEl.style.height = shape.height + 2 * BORDER_WIDTH + 'px';
1915
+ highlightEl.style.display = 'block';
1889
1916
  };
1890
1917
  };
1891
1918
  HighlightFunctionsInitializer.prototype.initUnhighlightFunction = function (element) {
1892
1919
  element._tolgee.unhighlight = function () {
1893
- element.style.backgroundColor = element._tolgee.initialBackgroundColor;
1920
+ var _a;
1921
+ (_a = element._tolgee.highlightEl) === null || _a === void 0 ? void 0 : _a.remove();
1922
+ element._tolgee.highlightEl = null;
1894
1923
  };
1895
1924
  };
1896
1925
  return HighlightFunctionsInitializer;
@@ -2914,7 +2943,7 @@
2914
2943
  this.properties = new Properties();
2915
2944
  this.eventService = new EventService();
2916
2945
  this.apiHttpService = new ApiHttpService(this.properties);
2917
- this.mouseEventHandler = new MouseEventHandler(this.properties);
2946
+ this.mouseEventHandler = new MouseEventHandler(this);
2918
2947
  this.moduleService = new ModuleService();
2919
2948
  this.coreService = new CoreService(this.properties, this.apiHttpService);
2920
2949
  this.screenshotService = new ScreenshotService(this.coreService, this.apiHttpService);
@@ -2931,6 +2960,7 @@
2931
2960
  this.stop = function () {
2932
2961
  _this.observer.stopObserving();
2933
2962
  _this.elementRegistrar.cleanAll();
2963
+ _this.mouseEventHandler.stop();
2934
2964
  NodeHelper.unmarkElementAsTargetElement(_this.properties.config.targetElement);
2935
2965
  };
2936
2966
  this.translationHighlighter.pluginManager = this.pluginManager;