@deephaven/golden-layout 0.43.0 → 0.44.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 (79) hide show
  1. package/css/goldenlayout-base.css +1 -1
  2. package/css/goldenlayout-base.css.map +1 -1
  3. package/css/goldenlayout-dark-theme.css +1 -1
  4. package/css/goldenlayout-dark-theme.css.map +1 -1
  5. package/dist/GoldenLayout.module.css +1 -0
  6. package/dist/GoldenLayout.module.css.map +1 -0
  7. package/dist/GoldenLayoutThemeExport.js +6 -0
  8. package/dist/GoldenLayoutThemeExport.js.map +1 -0
  9. package/dist/LayoutManager.js +1001 -0
  10. package/dist/LayoutManager.js.map +1 -0
  11. package/dist/base.js +16 -0
  12. package/dist/base.js.map +1 -0
  13. package/dist/config/Config.js +42 -0
  14. package/dist/config/Config.js.map +1 -0
  15. package/dist/config/ItemConfig.js +14 -0
  16. package/dist/config/ItemConfig.js.map +1 -0
  17. package/dist/config/index.js +3 -0
  18. package/dist/config/index.js.map +1 -0
  19. package/dist/container/ItemContainer.js +199 -0
  20. package/dist/container/ItemContainer.js.map +1 -0
  21. package/dist/container/index.js +3 -0
  22. package/dist/container/index.js.map +1 -0
  23. package/dist/controls/BrowserPopout.js +250 -0
  24. package/dist/controls/BrowserPopout.js.map +1 -0
  25. package/dist/controls/DragProxy.js +204 -0
  26. package/dist/controls/DragProxy.js.map +1 -0
  27. package/dist/controls/DragSource.js +52 -0
  28. package/dist/controls/DragSource.js.map +1 -0
  29. package/dist/controls/DragSourceFromEvent.js +71 -0
  30. package/dist/controls/DragSourceFromEvent.js.map +1 -0
  31. package/dist/controls/DropTargetIndicator.js +27 -0
  32. package/dist/controls/DropTargetIndicator.js.map +1 -0
  33. package/dist/controls/Header.js +736 -0
  34. package/dist/controls/Header.js.map +1 -0
  35. package/dist/controls/HeaderButton.js +22 -0
  36. package/dist/controls/HeaderButton.js.map +1 -0
  37. package/dist/controls/Splitter.js +49 -0
  38. package/dist/controls/Splitter.js.map +1 -0
  39. package/dist/controls/Tab.js +225 -0
  40. package/dist/controls/Tab.js.map +1 -0
  41. package/dist/controls/index.js +10 -0
  42. package/dist/controls/index.js.map +1 -0
  43. package/dist/declaration.d.js +2 -0
  44. package/dist/declaration.d.js.map +1 -0
  45. package/dist/errors/ConfigurationError.js +14 -0
  46. package/dist/errors/ConfigurationError.js.map +1 -0
  47. package/dist/errors/index.js +2 -0
  48. package/dist/errors/index.js.map +1 -0
  49. package/dist/index.js +11 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/items/AbstractContentItem.js +565 -0
  52. package/dist/items/AbstractContentItem.js.map +1 -0
  53. package/dist/items/Component.js +80 -0
  54. package/dist/items/Component.js.map +1 -0
  55. package/dist/items/Root.js +100 -0
  56. package/dist/items/Root.js.map +1 -0
  57. package/dist/items/RowOrColumn.js +488 -0
  58. package/dist/items/RowOrColumn.js.map +1 -0
  59. package/dist/items/Stack.js +479 -0
  60. package/dist/items/Stack.js.map +1 -0
  61. package/dist/items/index.js +8 -0
  62. package/dist/items/index.js.map +1 -0
  63. package/dist/utils/BubblingEvent.js +17 -0
  64. package/dist/utils/BubblingEvent.js.map +1 -0
  65. package/dist/utils/ConfigMinifier.js +147 -0
  66. package/dist/utils/ConfigMinifier.js.map +1 -0
  67. package/dist/utils/DragListener.js +125 -0
  68. package/dist/utils/DragListener.js.map +1 -0
  69. package/dist/utils/EventEmitter.js +117 -0
  70. package/dist/utils/EventEmitter.js.map +1 -0
  71. package/dist/utils/EventHub.js +108 -0
  72. package/dist/utils/EventHub.js.map +1 -0
  73. package/dist/utils/ReactComponentHandler.js +136 -0
  74. package/dist/utils/ReactComponentHandler.js.map +1 -0
  75. package/dist/utils/index.js +8 -0
  76. package/dist/utils/index.js.map +1 -0
  77. package/dist/utils/utils.js +65 -0
  78. package/dist/utils/utils.js.map +1 -0
  79. package/package.json +3 -3
@@ -0,0 +1,147 @@
1
+ /**
2
+ * Minifies and unminifies configs by replacing frequent keys
3
+ * and values with one letter substitutes. Config options must
4
+ * retain array position/index, add new options at the end.
5
+ */
6
+
7
+ var _keys = ['settings', 'hasHeaders', 'constrainDragToContainer', 'selectionEnabled', 'dimensions', 'borderWidth', 'minItemHeight', 'minItemWidth', 'headerHeight', 'dragProxyWidth', 'dragProxyHeight', 'labels', 'close', 'maximise', 'minimise', 'popout', 'content', 'componentName', 'componentState', 'id', 'width', 'type', 'height', 'isClosable', 'title', 'popoutWholeStack', 'openPopouts', 'parentId', 'activeItemIndex', 'reorderEnabled', 'borderGrabWidth'
8
+
9
+ //Maximum 36 entries, do not cross this line!
10
+ ];
11
+
12
+ var _values = [true, false, 'row', 'column', 'stack', 'component', 'close', 'maximise', 'minimise', 'open in new window'];
13
+
14
+ /**
15
+ * Takes a GoldenLayout configuration object and
16
+ * replaces its keys and values recursively with
17
+ * one letter counterparts
18
+ *
19
+ * @param config A GoldenLayout config object
20
+ *
21
+ * @returns minified config
22
+ */
23
+ export function minifyConfig(config) {
24
+ if (_keys.length > 36) {
25
+ throw new Error('Too many keys in config minifier map');
26
+ }
27
+ var min = {};
28
+ _nextLevel(config, min, '_min');
29
+ return min;
30
+ }
31
+
32
+ /**
33
+ * Takes a configuration Object that was previously minified
34
+ * using minifyConfig and returns its original version
35
+ *
36
+ * @param minifiedConfig
37
+ *
38
+ * @returns the original configuration
39
+ */
40
+ export function unminifyConfig(minifiedConfig) {
41
+ if (_keys.length > 36) {
42
+ throw new Error('Too many keys in config minifier map');
43
+ }
44
+ var orig = {};
45
+ _nextLevel(minifiedConfig, orig, '_max');
46
+ return orig;
47
+ }
48
+
49
+ /**
50
+ * Recursive function, called for every level of the config structure
51
+ *
52
+ * @param orig
53
+ * @param min
54
+ * @param translationFnName
55
+ */
56
+ function _nextLevel(from, to, translationFnName) {
57
+ var translationFn = translationFnName === '_min' ? _min : _max;
58
+ for (var key in from) {
59
+ /**
60
+ * In case something has extended Object prototypes
61
+ */
62
+ if (!from.hasOwnProperty(key)) continue;
63
+ var fromItem = Array.isArray(from) ? from[Number.parseInt(key, 10)] : from[key];
64
+ /**
65
+ * For Arrays and Objects, create a new Array/Object
66
+ * on the minified object and recurse into it
67
+ */
68
+ if (typeof fromItem === 'object' && fromItem != null) {
69
+ var toItem = fromItem instanceof Array ? [] : {};
70
+ if (Array.isArray(to)) {
71
+ to[Number.parseInt(key, 10)] = toItem;
72
+ } else {
73
+ var minKey = translationFn(key, _keys);
74
+ to[minKey] = toItem;
75
+ }
76
+ _nextLevel(fromItem, toItem, translationFnName);
77
+
78
+ /**
79
+ * For primitive values (Strings, Numbers, Boolean etc.)
80
+ * minify the value
81
+ */
82
+ } else {
83
+ var _toItem = translationFn(fromItem, _values);
84
+ if (Array.isArray(to)) {
85
+ to[Number.parseInt(key, 10)] = _toItem;
86
+ } else {
87
+ var _minKey = translationFn(key, _keys);
88
+ to[_minKey] = _toItem;
89
+ }
90
+ }
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Minifies value based on a dictionary
96
+ *
97
+ * @param value
98
+ * @param dictionary
99
+ *
100
+ * @returns The minified version
101
+ */
102
+ function _min(value, dictionary) {
103
+ /**
104
+ * If a value actually is a single character, prefix it
105
+ * with ___ to avoid mistaking it for a minification code
106
+ */
107
+ if (typeof value === 'string' && value.length === 1) {
108
+ return '___' + value;
109
+ }
110
+ var index = dictionary.indexOf(value);
111
+
112
+ /**
113
+ * value not found in the dictionary, return it unmodified
114
+ */
115
+ if (index === -1) {
116
+ return value;
117
+
118
+ /**
119
+ * value found in dictionary, return its base36 counterpart
120
+ */
121
+ } else {
122
+ return index.toString(36);
123
+ }
124
+ }
125
+ function _max(value, dictionary) {
126
+ /**
127
+ * value is a single character. Assume that it's a translation
128
+ * and return the original value from the dictionary
129
+ */
130
+ if (typeof value === 'string' && value.length === 1) {
131
+ return dictionary[parseInt(value, 36)];
132
+ }
133
+
134
+ /**
135
+ * value originally was a single character and was prefixed with ___
136
+ * to avoid mistaking it for a translation. Remove the prefix
137
+ * and return the original character
138
+ */
139
+ if (typeof value === 'string' && value.substr(0, 3) === '___') {
140
+ return value[3];
141
+ }
142
+ /**
143
+ * value was not minified
144
+ */
145
+ return value;
146
+ }
147
+ //# sourceMappingURL=ConfigMinifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigMinifier.js","names":["_keys","_values","minifyConfig","config","length","Error","min","_nextLevel","unminifyConfig","minifiedConfig","orig","from","to","translationFnName","translationFn","_min","_max","key","hasOwnProperty","fromItem","Array","isArray","Number","parseInt","toItem","minKey","value","dictionary","index","indexOf","toString","substr"],"sources":["../../src/utils/ConfigMinifier.ts"],"sourcesContent":["import type { Config } from '../config';\n\n/**\n * Minifies and unminifies configs by replacing frequent keys\n * and values with one letter substitutes. Config options must\n * retain array position/index, add new options at the end.\n */\n\nconst _keys = [\n 'settings',\n 'hasHeaders',\n 'constrainDragToContainer',\n 'selectionEnabled',\n 'dimensions',\n 'borderWidth',\n 'minItemHeight',\n 'minItemWidth',\n 'headerHeight',\n 'dragProxyWidth',\n 'dragProxyHeight',\n 'labels',\n 'close',\n 'maximise',\n 'minimise',\n 'popout',\n 'content',\n 'componentName',\n 'componentState',\n 'id',\n 'width',\n 'type',\n 'height',\n 'isClosable',\n 'title',\n 'popoutWholeStack',\n 'openPopouts',\n 'parentId',\n 'activeItemIndex',\n 'reorderEnabled',\n 'borderGrabWidth',\n\n //Maximum 36 entries, do not cross this line!\n];\n\nconst _values = [\n true,\n false,\n 'row',\n 'column',\n 'stack',\n 'component',\n 'close',\n 'maximise',\n 'minimise',\n 'open in new window',\n];\n\n/**\n * Takes a GoldenLayout configuration object and\n * replaces its keys and values recursively with\n * one letter counterparts\n *\n * @param config A GoldenLayout config object\n *\n * @returns minified config\n */\nexport function minifyConfig(config: Partial<Config>) {\n if (_keys.length > 36) {\n throw new Error('Too many keys in config minifier map');\n }\n\n const min = {};\n _nextLevel(config, min, '_min');\n return min;\n}\n\n/**\n * Takes a configuration Object that was previously minified\n * using minifyConfig and returns its original version\n *\n * @param minifiedConfig\n *\n * @returns the original configuration\n */\nexport function unminifyConfig(\n minifiedConfig: Record<string, unknown>\n): Config {\n if (_keys.length > 36) {\n throw new Error('Too many keys in config minifier map');\n }\n\n const orig = {};\n _nextLevel(minifiedConfig, orig, '_max');\n return orig as Config;\n}\n\n/**\n * Recursive function, called for every level of the config structure\n *\n * @param orig\n * @param min\n * @param translationFnName\n */\nfunction _nextLevel(\n from: unknown[] | Record<string, unknown>,\n to: unknown[] | Record<string, unknown>,\n translationFnName: '_min' | '_max'\n) {\n const translationFn = translationFnName === '_min' ? _min : _max;\n for (let key in from) {\n /**\n * In case something has extended Object prototypes\n */\n if (!from.hasOwnProperty(key)) continue;\n\n const fromItem = Array.isArray(from)\n ? from[Number.parseInt(key, 10)]\n : from[key];\n /**\n * For Arrays and Objects, create a new Array/Object\n * on the minified object and recurse into it\n */\n if (typeof fromItem === 'object' && fromItem != null) {\n const toItem = fromItem instanceof Array ? [] : {};\n\n if (Array.isArray(to)) {\n to[Number.parseInt(key, 10)] = toItem;\n } else {\n const minKey = translationFn(key, _keys);\n to[minKey] = toItem;\n }\n\n _nextLevel(\n fromItem as Record<string, unknown>,\n toItem,\n translationFnName\n );\n\n /**\n * For primitive values (Strings, Numbers, Boolean etc.)\n * minify the value\n */\n } else {\n const toItem = translationFn(fromItem, _values);\n\n if (Array.isArray(to)) {\n to[Number.parseInt(key, 10)] = toItem;\n } else {\n const minKey = translationFn(key, _keys);\n to[minKey] = toItem;\n }\n }\n }\n}\n\n/**\n * Minifies value based on a dictionary\n *\n * @param value\n * @param dictionary\n *\n * @returns The minified version\n */\nfunction _min<T>(value: T, dictionary: T[]): T | string {\n /**\n * If a value actually is a single character, prefix it\n * with ___ to avoid mistaking it for a minification code\n */\n if (typeof value === 'string' && value.length === 1) {\n return '___' + value;\n }\n\n var index = dictionary.indexOf(value);\n\n /**\n * value not found in the dictionary, return it unmodified\n */\n if (index === -1) {\n return value;\n\n /**\n * value found in dictionary, return its base36 counterpart\n */\n } else {\n return index.toString(36);\n }\n}\n\nfunction _max<T>(value: T, dictionary: T[]): T | string {\n /**\n * value is a single character. Assume that it's a translation\n * and return the original value from the dictionary\n */\n if (typeof value === 'string' && value.length === 1) {\n return dictionary[parseInt(value, 36)];\n }\n\n /**\n * value originally was a single character and was prefixed with ___\n * to avoid mistaking it for a translation. Remove the prefix\n * and return the original character\n */\n if (typeof value === 'string' && value.substr(0, 3) === '___') {\n return value[3];\n }\n /**\n * value was not minified\n */\n return value;\n}\n"],"mappings":"AAEA;AACA;AACA;AACA;AACA;;AAEA,IAAMA,KAAK,GAAG,CACZ,UAAU,EACV,YAAY,EACZ,0BAA0B,EAC1B,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,eAAe,EACf,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,QAAQ,EACR,OAAO,EACP,UAAU,EACV,UAAU,EACV,QAAQ,EACR,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,IAAI,EACJ,OAAO,EACP,MAAM,EACN,QAAQ,EACR,YAAY,EACZ,OAAO,EACP,kBAAkB,EAClB,aAAa,EACb,UAAU,EACV,iBAAiB,EACjB,gBAAgB,EAChB;;AAEA;AAAA,CACD;;AAED,IAAMC,OAAO,GAAG,CACd,IAAI,EACJ,KAAK,EACL,KAAK,EACL,QAAQ,EACR,OAAO,EACP,WAAW,EACX,OAAO,EACP,UAAU,EACV,UAAU,EACV,oBAAoB,CACrB;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,YAAY,CAACC,MAAuB,EAAE;EACpD,IAAIH,KAAK,CAACI,MAAM,GAAG,EAAE,EAAE;IACrB,MAAM,IAAIC,KAAK,CAAC,sCAAsC,CAAC;EACzD;EAEA,IAAMC,GAAG,GAAG,CAAC,CAAC;EACdC,UAAU,CAACJ,MAAM,EAAEG,GAAG,EAAE,MAAM,CAAC;EAC/B,OAAOA,GAAG;AACZ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;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AAE;IAC7D,OAAOL,KAAK,CAAC,CAAC,CAAC;EACjB;EACA;AACF;AACA;EACE,OAAOA,KAAK;AACd"}
@@ -0,0 +1,125 @@
1
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
3
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
4
+ import $ from 'jquery';
5
+ import EventEmitter from "./EventEmitter.js";
6
+ class DragListener extends EventEmitter {
7
+ /**
8
+ * The delay after which to start the drag in milliseconds
9
+ */
10
+
11
+ /**
12
+ * The distance the mouse needs to be moved to qualify as a drag
13
+ */
14
+ //TODO - works better with delay only
15
+
16
+ constructor(eElement) {
17
+ var _this$_eElement;
18
+ var destroyAfterMouseUp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
19
+ super();
20
+ _defineProperty(this, "_eElement", void 0);
21
+ _defineProperty(this, "_oDocument", void 0);
22
+ _defineProperty(this, "_eBody", void 0);
23
+ _defineProperty(this, "_destroyAfterMouseUp", void 0);
24
+ _defineProperty(this, "_nDelay", 400);
25
+ _defineProperty(this, "_timeout", void 0);
26
+ _defineProperty(this, "timeout", void 0);
27
+ _defineProperty(this, "_nDistance", 10);
28
+ _defineProperty(this, "_nX", 0);
29
+ _defineProperty(this, "_nY", 0);
30
+ _defineProperty(this, "_nOriginalX", 0);
31
+ _defineProperty(this, "_nOriginalY", 0);
32
+ _defineProperty(this, "_bDragging", false);
33
+ this._eElement = eElement;
34
+ this._oDocument = $(document);
35
+ this._eBody = $(document.body);
36
+ // used by drag sources, to destroy listener at the right time
37
+ this._destroyAfterMouseUp = destroyAfterMouseUp;
38
+ this.onMouseMove = this.onMouseMove.bind(this);
39
+ this.onMouseUp = this.onMouseUp.bind(this);
40
+ this.onMouseDown = this.onMouseDown.bind(this);
41
+ this._startDrag = this._startDrag.bind(this);
42
+
43
+ // https://github.com/microsoft/TypeScript/issues/48546
44
+ (_this$_eElement = this._eElement) === null || _this$_eElement === void 0 ? void 0 : _this$_eElement.on('mousedown', this.onMouseDown);
45
+ }
46
+ destroy() {
47
+ var _this$_eElement2, _this$_oDocument;
48
+ (_this$_eElement2 = this._eElement) === null || _this$_eElement2 === void 0 ? void 0 : _this$_eElement2.unbind('mousedown', this.onMouseDown);
49
+ (_this$_oDocument = this._oDocument) === null || _this$_oDocument === void 0 ? void 0 : _this$_oDocument.unbind('mouseup', this.onMouseUp);
50
+ this._eElement = undefined;
51
+ this._oDocument = undefined;
52
+ this._eBody = undefined;
53
+ clearTimeout(this._timeout);
54
+ this._timeout = undefined;
55
+ }
56
+ onMouseDown(oEvent) {
57
+ oEvent.preventDefault();
58
+ if (oEvent.button === 0) {
59
+ var _coordinates$x, _coordinates$y, _this$_oDocument2, _this$_oDocument3;
60
+ var coordinates = this._getCoordinates(oEvent);
61
+ this._nOriginalX = (_coordinates$x = coordinates.x) !== null && _coordinates$x !== void 0 ? _coordinates$x : 0;
62
+ this._nOriginalY = (_coordinates$y = coordinates.y) !== null && _coordinates$y !== void 0 ? _coordinates$y : 0;
63
+ (_this$_oDocument2 = this._oDocument) === null || _this$_oDocument2 === void 0 ? void 0 : _this$_oDocument2.on('mousemove', this.onMouseMove);
64
+ (_this$_oDocument3 = this._oDocument) === null || _this$_oDocument3 === void 0 ? void 0 : _this$_oDocument3.on('mouseup', this.onMouseUp);
65
+ this._timeout = window.setTimeout(this._startDrag, this._nDelay);
66
+ }
67
+ }
68
+ onMouseMove(oEvent) {
69
+ if (this._timeout != null) {
70
+ var _coordinates$x2, _coordinates$y2;
71
+ oEvent.preventDefault();
72
+ var coordinates = this._getCoordinates(oEvent);
73
+ this._nX = ((_coordinates$x2 = coordinates.x) !== null && _coordinates$x2 !== void 0 ? _coordinates$x2 : 0) - this._nOriginalX;
74
+ this._nY = ((_coordinates$y2 = coordinates.y) !== null && _coordinates$y2 !== void 0 ? _coordinates$y2 : 0) - this._nOriginalY;
75
+ if (this._bDragging === false) {
76
+ if (Math.abs(this._nX) > this._nDistance || Math.abs(this._nY) > this._nDistance) {
77
+ this._startDrag();
78
+ }
79
+ }
80
+ if (this._bDragging) {
81
+ this.emit('drag', this._nX, this._nY, oEvent);
82
+ }
83
+ }
84
+ }
85
+ onMouseUp(oEvent) {
86
+ if (this._timeout != null) {
87
+ var _this$_oDocument4, _this$_oDocument5, _this$_oDocument6, _this$_oDocument6$fin, _this$_eBody;
88
+ clearTimeout(this._timeout);
89
+ (_this$_oDocument4 = this._oDocument) === null || _this$_oDocument4 === void 0 ? void 0 : _this$_oDocument4.unbind('mousemove', this.onMouseMove);
90
+ (_this$_oDocument5 = this._oDocument) === null || _this$_oDocument5 === void 0 ? void 0 : _this$_oDocument5.unbind('mouseup', this.onMouseUp);
91
+ (_this$_oDocument6 = this._oDocument) === null || _this$_oDocument6 === void 0 ? void 0 : (_this$_oDocument6$fin = _this$_oDocument6.find('iframe')) === null || _this$_oDocument6$fin === void 0 ? void 0 : _this$_oDocument6$fin.css('pointer-events', '');
92
+ if (this._bDragging === true) {
93
+ this._bDragging = false;
94
+ this.emit('dragStop', oEvent, this._nOriginalX + this._nX);
95
+ }
96
+
97
+ // after dragStop, so that .lm_dragging is removed after size is processed
98
+ // and any overflow: hidden remains applied during the calculations
99
+ (_this$_eBody = this._eBody) === null || _this$_eBody === void 0 ? void 0 : _this$_eBody.removeClass('lm_dragging');
100
+ if (!(this._eElement instanceof Window)) {
101
+ var _this$_eElement3;
102
+ (_this$_eElement3 = this._eElement) === null || _this$_eElement3 === void 0 ? void 0 : _this$_eElement3.removeClass('lm_dragging');
103
+ }
104
+ if (this._destroyAfterMouseUp) this.destroy();
105
+ }
106
+ }
107
+ _startDrag() {
108
+ var _this$_eBody2, _this$_eElement4, _this$_oDocument7, _this$_oDocument7$fin;
109
+ window.clearTimeout(this._timeout);
110
+ this._bDragging = true;
111
+ (_this$_eBody2 = this._eBody) === null || _this$_eBody2 === void 0 ? void 0 : _this$_eBody2.addClass('lm_dragging');
112
+ (_this$_eElement4 = this._eElement) === null || _this$_eElement4 === void 0 ? void 0 : _this$_eElement4.addClass('lm_dragging');
113
+ (_this$_oDocument7 = this._oDocument) === null || _this$_oDocument7 === void 0 ? void 0 : (_this$_oDocument7$fin = _this$_oDocument7.find('iframe')) === null || _this$_oDocument7$fin === void 0 ? void 0 : _this$_oDocument7$fin.css('pointer-events', 'none');
114
+ this.emit('dragStart', this._nOriginalX, this._nOriginalY);
115
+ }
116
+ _getCoordinates(event) {
117
+ var _event$pageX, _event$pageY;
118
+ return {
119
+ x: (_event$pageX = event.pageX) !== null && _event$pageX !== void 0 ? _event$pageX : 0,
120
+ y: (_event$pageY = event.pageY) !== null && _event$pageY !== void 0 ? _event$pageY : 0
121
+ };
122
+ }
123
+ }
124
+ export default DragListener;
125
+ //# sourceMappingURL=DragListener.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DragListener.js","names":["$","EventEmitter","DragListener","constructor","eElement","destroyAfterMouseUp","_eElement","_oDocument","document","_eBody","body","_destroyAfterMouseUp","onMouseMove","bind","onMouseUp","onMouseDown","_startDrag","on","destroy","unbind","undefined","clearTimeout","_timeout","oEvent","preventDefault","button","coordinates","_getCoordinates","_nOriginalX","x","_nOriginalY","y","window","setTimeout","_nDelay","_nX","_nY","_bDragging","Math","abs","_nDistance","emit","find","css","removeClass","Window","addClass","event","pageX","pageY"],"sources":["../../src/utils/DragListener.ts"],"sourcesContent":["import $ from 'jquery';\nimport EventEmitter from './EventEmitter';\n\nexport type DragListenerEvent = Pick<\n JQuery.TriggeredEvent,\n 'button' | 'pageX' | 'pageY' | 'preventDefault'\n>;\n\nclass DragListener extends EventEmitter {\n private _eElement: JQuery<HTMLElement> | undefined;\n private _oDocument: JQuery<Document> | undefined;\n private _eBody: JQuery<HTMLElement> | undefined;\n\n private _destroyAfterMouseUp: boolean;\n\n /**\n * The delay after which to start the drag in milliseconds\n */\n private _nDelay = 400;\n\n private _timeout: number | undefined;\n public timeout: number | undefined;\n\n /**\n * The distance the mouse needs to be moved to qualify as a drag\n */\n private _nDistance = 10; //TODO - works better with delay only\n\n private _nX = 0;\n private _nY = 0;\n\n private _nOriginalX = 0;\n private _nOriginalY = 0;\n\n private _bDragging = false;\n\n constructor(eElement: JQuery<HTMLElement>, destroyAfterMouseUp = false) {\n super();\n\n this._eElement = eElement;\n this._oDocument = $(document);\n this._eBody = $(document.body);\n // used by drag sources, to destroy listener at the right time\n this._destroyAfterMouseUp = destroyAfterMouseUp;\n\n this.onMouseMove = this.onMouseMove.bind(this);\n this.onMouseUp = this.onMouseUp.bind(this);\n this.onMouseDown = this.onMouseDown.bind(this);\n this._startDrag = this._startDrag.bind(this);\n\n // https://github.com/microsoft/TypeScript/issues/48546\n this._eElement?.on('mousedown', this.onMouseDown);\n }\n\n destroy() {\n this._eElement?.unbind('mousedown', this.onMouseDown);\n this._oDocument?.unbind('mouseup', this.onMouseUp);\n\n this._eElement = undefined;\n this._oDocument = undefined;\n this._eBody = undefined;\n\n clearTimeout(this._timeout);\n this._timeout = undefined;\n }\n\n onMouseDown(oEvent: DragListenerEvent) {\n oEvent.preventDefault();\n\n if (oEvent.button === 0) {\n var coordinates = this._getCoordinates(oEvent);\n\n this._nOriginalX = coordinates.x ?? 0;\n this._nOriginalY = coordinates.y ?? 0;\n\n this._oDocument?.on('mousemove', this.onMouseMove);\n this._oDocument?.on('mouseup', this.onMouseUp);\n\n this._timeout = window.setTimeout(this._startDrag, this._nDelay);\n }\n }\n\n onMouseMove(oEvent: DragListenerEvent) {\n if (this._timeout != null) {\n oEvent.preventDefault();\n\n var coordinates = this._getCoordinates(oEvent);\n\n this._nX = (coordinates.x ?? 0) - this._nOriginalX;\n this._nY = (coordinates.y ?? 0) - this._nOriginalY;\n\n if (this._bDragging === false) {\n if (\n Math.abs(this._nX) > this._nDistance ||\n Math.abs(this._nY) > this._nDistance\n ) {\n this._startDrag();\n }\n }\n\n if (this._bDragging) {\n this.emit('drag', this._nX, this._nY, oEvent);\n }\n }\n }\n\n onMouseUp(oEvent: DragListenerEvent) {\n if (this._timeout != null) {\n clearTimeout(this._timeout);\n this._oDocument?.unbind('mousemove', this.onMouseMove);\n this._oDocument?.unbind('mouseup', this.onMouseUp);\n this._oDocument?.find('iframe')?.css('pointer-events', '');\n\n if (this._bDragging === true) {\n this._bDragging = false;\n this.emit('dragStop', oEvent, this._nOriginalX + this._nX);\n }\n\n // after dragStop, so that .lm_dragging is removed after size is processed\n // and any overflow: hidden remains applied during the calculations\n this._eBody?.removeClass('lm_dragging');\n if (!(this._eElement instanceof Window)) {\n this._eElement?.removeClass('lm_dragging');\n }\n\n if (this._destroyAfterMouseUp) this.destroy();\n }\n }\n\n _startDrag() {\n window.clearTimeout(this._timeout);\n this._bDragging = true;\n this._eBody?.addClass('lm_dragging');\n this._eElement?.addClass('lm_dragging');\n this._oDocument?.find('iframe')?.css('pointer-events', 'none');\n this.emit('dragStart', this._nOriginalX, this._nOriginalY);\n }\n\n _getCoordinates(event: DragListenerEvent) {\n return {\n x: event.pageX ?? 0,\n y: event.pageY ?? 0,\n };\n }\n}\n\nexport default DragListener;\n"],"mappings":";;;AAAA,OAAOA,CAAC,MAAM,QAAQ;AAAC,OAChBC,YAAY;AAOnB,MAAMC,YAAY,SAASD,YAAY,CAAC;EAOtC;AACF;AACA;;EAME;AACF;AACA;EAC2B;;EAUzBE,WAAW,CAACC,QAA6B,EAA+B;IAAA;IAAA,IAA7BC,mBAAmB,uEAAG,KAAK;IACpE,KAAK,EAAE;IAAC;IAAA;IAAA;IAAA;IAAA,iCAnBQ,GAAG;IAAA;IAAA;IAAA,oCAQA,EAAE;IAAA,6BAET,CAAC;IAAA,6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,CAAC,aAAa,CAAC;IACvC,yBAAI,CAACvC,UAAU,+EAAf,kBAAiBmC,IAAI,CAAC,QAAQ,CAAC,0DAA/B,sBAAiCC,GAAG,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAC9D,IAAI,CAACF,IAAI,CAAC,WAAW,EAAE,IAAI,CAACb,WAAW,EAAE,IAAI,CAACE,WAAW,CAAC;EAC5D;EAEAH,eAAe,CAACoB,KAAwB,EAAE;IAAA;IACxC,OAAO;MACLlB,CAAC,kBAAEkB,KAAK,CAACC,KAAK,uDAAI,CAAC;MACnBjB,CAAC,kBAAEgB,KAAK,CAACE,KAAK,uDAAI;IACpB,CAAC;EACH;AACF;AAEA,eAAe/C,YAAY"}
@@ -0,0 +1,117 @@
1
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
3
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
4
+ /**
5
+ * A generic and very fast EventEmitter
6
+ * implementation. On top of emitting the
7
+ * actual event it emits an
8
+ *
9
+ * EventEmitter.ALL_EVENT
10
+ *
11
+ * event for every event triggered. This allows
12
+ * to hook into it and proxy events forwards
13
+ *
14
+ * @constructor
15
+ */
16
+ class EventEmitter {
17
+ /**
18
+ * The name of the event that's triggered for every other event
19
+ *
20
+ * usage
21
+ *
22
+ * myEmitter.on( EventEmitter.ALL_EVENT, function( eventName, argsArray ){
23
+ * //do stuff
24
+ * });
25
+ */
26
+
27
+ constructor() {
28
+ _defineProperty(this, "_mSubscriptions", void 0);
29
+ _defineProperty(this, "off", this.unbind);
30
+ _defineProperty(this, "trigger", this.emit);
31
+ this._mSubscriptions = {};
32
+ this._mSubscriptions[EventEmitter.ALL_EVENT] = [];
33
+ }
34
+
35
+ /**
36
+ * Listen for events
37
+ *
38
+ * @param eventName The name of the event to listen to
39
+ * @param callback The callback to execute when the event occurs
40
+ * @param context The value of the this pointer within the callback function
41
+ */
42
+ on(eventName, callback, context) {
43
+ if (typeof callback !== 'function') {
44
+ throw new Error('Tried to listen to event ' + eventName + ' with non-function callback ' + callback);
45
+ }
46
+ if (!this._mSubscriptions[eventName]) {
47
+ this._mSubscriptions[eventName] = [];
48
+ }
49
+ this._mSubscriptions[eventName].push({
50
+ fn: callback,
51
+ ctx: context
52
+ });
53
+ }
54
+
55
+ /**
56
+ * Emit an event and notify listeners
57
+ *
58
+ * @param eventName The name of the event
59
+ * @param args additional arguments that will be passed to the listener
60
+ */
61
+ emit(eventName) {
62
+ var subs = this._mSubscriptions[eventName];
63
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
64
+ args[_key - 1] = arguments[_key];
65
+ }
66
+ if (subs) {
67
+ for (var i = 0; i < subs.length; i++) {
68
+ var ctx = subs[i].ctx || {};
69
+ try {
70
+ subs[i].fn.apply(ctx, args);
71
+ } catch (e) {
72
+ console.error('Error while emitting event:', e);
73
+ }
74
+ }
75
+ }
76
+ args.unshift(eventName);
77
+ var allEventSubs = this._mSubscriptions[EventEmitter.ALL_EVENT];
78
+ for (var _i = 0; _i < allEventSubs.length; _i++) {
79
+ var _ctx = allEventSubs[_i].ctx || {};
80
+ try {
81
+ allEventSubs[_i].fn.apply(_ctx, args);
82
+ } catch (e) {
83
+ console.error('Error while emitting event to allEventSubs:', e);
84
+ }
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Removes a listener for an event, or all listeners if no callback and context is provided.
90
+ *
91
+ * @param eventName The name of the event
92
+ * @param callback The previously registered callback method (optional)
93
+ * @param context The previously registered context (optional)
94
+ */
95
+ unbind(eventName, callback, context) {
96
+ if (!this._mSubscriptions[eventName]) {
97
+ throw new Error('No subscriptions to unsubscribe for event ' + eventName);
98
+ }
99
+ var bUnbound = false;
100
+ for (var i = 0; i < this._mSubscriptions[eventName].length; i++) {
101
+ if ((!callback || this._mSubscriptions[eventName][i].fn === callback) && (!context || context === this._mSubscriptions[eventName][i].ctx)) {
102
+ this._mSubscriptions[eventName].splice(i, 1);
103
+ bUnbound = true;
104
+ }
105
+ }
106
+ if (bUnbound === false) {
107
+ throw new Error('Nothing to unbind for ' + eventName);
108
+ }
109
+ }
110
+
111
+ /**
112
+ * Alias for unbind
113
+ */
114
+ }
115
+ _defineProperty(EventEmitter, "ALL_EVENT", '__all');
116
+ export default EventEmitter;
117
+ //# sourceMappingURL=EventEmitter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EventEmitter.js","names":["EventEmitter","constructor","unbind","emit","_mSubscriptions","ALL_EVENT","on","eventName","callback","context","Error","push","fn","ctx","subs","args","i","length","apply","e","console","error","unshift","allEventSubs","bUnbound","splice"],"sources":["../../src/utils/EventEmitter.ts"],"sourcesContent":["/**\n * A generic and very fast EventEmitter\n * implementation. On top of emitting the\n * actual event it emits an\n *\n * EventEmitter.ALL_EVENT\n *\n * event for every event triggered. This allows\n * to hook into it and proxy events forwards\n *\n * @constructor\n */\nclass EventEmitter {\n /**\n * The name of the event that's triggered for every other event\n *\n * usage\n *\n * myEmitter.on( EventEmitter.ALL_EVENT, function( eventName, argsArray ){\n * \t//do stuff\n * });\n */\n static ALL_EVENT = '__all';\n\n private _mSubscriptions: Record<string, { fn: Function; ctx?: unknown }[]>;\n\n constructor() {\n this._mSubscriptions = {};\n this._mSubscriptions[EventEmitter.ALL_EVENT] = [];\n }\n\n /**\n * Listen for events\n *\n * @param eventName The name of the event to listen to\n * @param callback The callback to execute when the event occurs\n * @param context The value of the this pointer within the callback function\n */\n on(eventName: string, callback: Function, context?: unknown): void {\n if (typeof callback !== 'function') {\n throw new Error(\n 'Tried to listen to event ' +\n eventName +\n ' with non-function callback ' +\n callback\n );\n }\n\n if (!this._mSubscriptions[eventName]) {\n this._mSubscriptions[eventName] = [];\n }\n\n this._mSubscriptions[eventName].push({ fn: callback, ctx: context });\n }\n\n /**\n * Emit an event and notify listeners\n *\n * @param eventName The name of the event\n * @param args additional arguments that will be passed to the listener\n */\n emit(eventName: string, ...args: unknown[]) {\n const subs = this._mSubscriptions[eventName];\n\n if (subs) {\n for (let i = 0; i < subs.length; i++) {\n const ctx = subs[i].ctx || {};\n try {\n subs[i].fn.apply(ctx, args);\n } catch (e) {\n console.error('Error while emitting event:', e);\n }\n }\n }\n\n args.unshift(eventName);\n\n const allEventSubs = this._mSubscriptions[EventEmitter.ALL_EVENT];\n\n for (let i = 0; i < allEventSubs.length; i++) {\n const ctx = allEventSubs[i].ctx || {};\n try {\n allEventSubs[i].fn.apply(ctx, args);\n } catch (e) {\n console.error('Error while emitting event to allEventSubs:', e);\n }\n }\n }\n\n /**\n * Removes a listener for an event, or all listeners if no callback and context is provided.\n *\n * @param eventName The name of the event\n * @param callback The previously registered callback method (optional)\n * @param context The previously registered context (optional)\n */\n unbind(eventName: string, callback?: Function, context?: unknown) {\n if (!this._mSubscriptions[eventName]) {\n throw new Error('No subscriptions to unsubscribe for event ' + eventName);\n }\n\n let bUnbound = false;\n\n for (let i = 0; i < this._mSubscriptions[eventName].length; i++) {\n if (\n (!callback || this._mSubscriptions[eventName][i].fn === callback) &&\n (!context || context === this._mSubscriptions[eventName][i].ctx)\n ) {\n this._mSubscriptions[eventName].splice(i, 1);\n bUnbound = true;\n }\n }\n\n if (bUnbound === false) {\n throw new Error('Nothing to unbind for ' + eventName);\n }\n }\n\n /**\n * Alias for unbind\n */\n off = this.unbind;\n\n /**\n * Alias for emit\n */\n trigger = this.emit;\n}\n\nexport default EventEmitter;\n"],"mappings":";;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,YAAY,CAAC;EACjB;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A,IAAI,CAACT,eAAe,CAACG,SAAS,CAAC,CAACkB,MAAM,CAACT,CAAC,EAAE,CAAC,CAAC;QAC5CQ,QAAQ,GAAG,IAAI;MACjB;IACF;IAEA,IAAIA,QAAQ,KAAK,KAAK,EAAE;MACtB,MAAM,IAAId,KAAK,CAAC,wBAAwB,GAAGH,SAAS,CAAC;IACvD;EACF;;EAEA;AACF;AACA;AAOA;AAAC,gBAnHKP,YAAY,eAUG,OAAO;AA2G5B,eAAeA,YAAY"}
@@ -0,0 +1,108 @@
1
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
3
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
4
+ import $ from 'jquery';
5
+ import EventEmitter from "./EventEmitter.js";
6
+ /**
7
+ * An EventEmitter singleton that propagates events
8
+ * across multiple windows. This is a little bit trickier since
9
+ * windows are allowed to open childWindows in their own right
10
+ *
11
+ * This means that we deal with a tree of windows. Hence the rules for event propagation are:
12
+ *
13
+ * - Propagate events from this layout to both parents and children
14
+ * - Propagate events from parent to this and children
15
+ * - Propagate events from children to the other children (but not the emitting one) and the parent
16
+ */
17
+ class EventHub extends EventEmitter {
18
+ constructor(layoutManager) {
19
+ super();
20
+ _defineProperty(this, "_layoutManager", void 0);
21
+ _defineProperty(this, "_dontPropagateToParent", void 0);
22
+ _defineProperty(this, "_childEventSource", void 0);
23
+ _defineProperty(this, "_boundOnEventFromChild", void 0);
24
+ this._layoutManager = layoutManager;
25
+ this._dontPropagateToParent = null;
26
+ this._childEventSource = null;
27
+ this.on(EventEmitter.ALL_EVENT, this._onEventFromThis.bind(this));
28
+ this._boundOnEventFromChild = this._onEventFromChild.bind(this);
29
+ $(window).on('gl_child_event', this._boundOnEventFromChild);
30
+ }
31
+
32
+ /**
33
+ * Called on every event emitted on this eventHub, regardles of origin.
34
+ */
35
+ _onEventFromThis() {
36
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
37
+ args[_key] = arguments[_key];
38
+ }
39
+ if (this._layoutManager.isSubWindow && args[0] !== this._dontPropagateToParent) {
40
+ this._propagateToParent(args);
41
+ }
42
+ this._propagateToChildren(args);
43
+
44
+ //Reset
45
+ this._dontPropagateToParent = null;
46
+ this._childEventSource = null;
47
+ }
48
+
49
+ /**
50
+ * Called by the parent layout.
51
+ *
52
+ * @param args Event name + arguments
53
+ */
54
+ _$onEventFromParent(args) {
55
+ this._dontPropagateToParent = args[0];
56
+ this.emit.apply(this, args);
57
+ }
58
+
59
+ /**
60
+ * Callback for child events raised on the window
61
+ *
62
+ * @param event
63
+ */
64
+ _onEventFromChild(event) {
65
+ this._childEventSource = event.originalEvent.__gl;
66
+ this.emit.apply(this, event.originalEvent.__glArgs);
67
+ }
68
+
69
+ /**
70
+ * Propagates the event to the parent by emitting
71
+ * it on the parent's DOM window
72
+ *
73
+ * @param args Event name + arguments
74
+ */
75
+ _propagateToParent(args) {
76
+ var _window$opener;
77
+ var eventName = 'gl_child_event';
78
+ var event = (_window$opener = window.opener) === null || _window$opener === void 0 ? void 0 : _window$opener.document.createEvent('HTMLEvents');
79
+ event.initEvent(eventName, true, true);
80
+ event.eventName = eventName;
81
+ event.__glArgs = args;
82
+ event.__gl = this._layoutManager;
83
+ window.opener.dispatchEvent(event);
84
+ }
85
+
86
+ /**
87
+ * Propagate events to children
88
+ *
89
+ * @param args Event name + arguments
90
+ */
91
+ _propagateToChildren(args) {
92
+ for (var i = 0; i < this._layoutManager.openPopouts.length; i++) {
93
+ var childGl = this._layoutManager.openPopouts[i].getGlInstance();
94
+ if (childGl && childGl !== this._childEventSource) {
95
+ childGl.eventHub._$onEventFromParent(args);
96
+ }
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Destroys the EventHub
102
+ */
103
+ destroy() {
104
+ $(window).off('gl_child_event', this._boundOnEventFromChild);
105
+ }
106
+ }
107
+ export default EventHub;
108
+ //# sourceMappingURL=EventHub.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EventHub.js","names":["$","EventEmitter","EventHub","constructor","layoutManager","_layoutManager","_dontPropagateToParent","_childEventSource","on","ALL_EVENT","_onEventFromThis","bind","_boundOnEventFromChild","_onEventFromChild","window","args","isSubWindow","_propagateToParent","_propagateToChildren","_$onEventFromParent","emit","apply","event","originalEvent","__gl","__glArgs","eventName","opener","document","createEvent","initEvent","dispatchEvent","i","openPopouts","length","childGl","getGlInstance","eventHub","destroy","off"],"sources":["../../src/utils/EventHub.ts"],"sourcesContent":["import $ from 'jquery';\nimport type LayoutManager from '../LayoutManager';\nimport EventEmitter from './EventEmitter';\n\ninterface GoldenLayoutEvent extends Event {\n __glArgs: [string, ...unknown[]];\n __gl: LayoutManager;\n}\n\n/**\n * An EventEmitter singleton that propagates events\n * across multiple windows. This is a little bit trickier since\n * windows are allowed to open childWindows in their own right\n *\n * This means that we deal with a tree of windows. Hence the rules for event propagation are:\n *\n * - Propagate events from this layout to both parents and children\n * - Propagate events from parent to this and children\n * - Propagate events from children to the other children (but not the emitting one) and the parent\n */\nclass EventHub extends EventEmitter {\n private _layoutManager: LayoutManager;\n\n private _dontPropagateToParent: string | null;\n\n private _childEventSource: LayoutManager | null;\n\n private _boundOnEventFromChild: (event: JQuery.TriggeredEvent) => void;\n\n constructor(layoutManager: LayoutManager) {\n super();\n this._layoutManager = layoutManager;\n this._dontPropagateToParent = null;\n this._childEventSource = null;\n this.on(EventEmitter.ALL_EVENT, this._onEventFromThis.bind(this));\n this._boundOnEventFromChild = this._onEventFromChild.bind(this);\n $(window).on('gl_child_event', this._boundOnEventFromChild);\n }\n\n /**\n * Called on every event emitted on this eventHub, regardles of origin.\n */\n private _onEventFromThis(...args: [string, ...unknown[]]) {\n if (\n this._layoutManager.isSubWindow &&\n args[0] !== this._dontPropagateToParent\n ) {\n this._propagateToParent(args);\n }\n this._propagateToChildren(args);\n\n //Reset\n this._dontPropagateToParent = null;\n this._childEventSource = null;\n }\n\n /**\n * Called by the parent layout.\n *\n * @param args Event name + arguments\n */\n private _$onEventFromParent(args: [string, ...unknown[]]) {\n this._dontPropagateToParent = args[0];\n this.emit.apply(this, args);\n }\n\n /**\n * Callback for child events raised on the window\n *\n * @param event\n */\n private _onEventFromChild(event: JQuery.TriggeredEvent) {\n this._childEventSource = (event.originalEvent as GoldenLayoutEvent).__gl;\n this.emit.apply(this, (event.originalEvent as GoldenLayoutEvent).__glArgs);\n }\n\n /**\n * Propagates the event to the parent by emitting\n * it on the parent's DOM window\n *\n * @param args Event name + arguments\n */\n private _propagateToParent(args: [string, ...unknown[]]) {\n const eventName = 'gl_child_event';\n\n const event = window.opener?.document.createEvent('HTMLEvents');\n event.initEvent(eventName, true, true);\n\n event.eventName = eventName;\n event.__glArgs = args;\n event.__gl = this._layoutManager;\n\n window.opener.dispatchEvent(event);\n }\n\n /**\n * Propagate events to children\n *\n * @param args Event name + arguments\n */\n private _propagateToChildren(args: [string, ...unknown[]]) {\n for (let i = 0; i < this._layoutManager.openPopouts.length; i++) {\n const childGl = this._layoutManager.openPopouts[i].getGlInstance();\n\n if (childGl && childGl !== this._childEventSource) {\n childGl.eventHub._$onEventFromParent(args);\n }\n }\n }\n\n /**\n * Destroys the EventHub\n */\n destroy() {\n $(window).off('gl_child_event', this._boundOnEventFromChild);\n }\n}\n\nexport default EventHub;\n"],"mappings":";;;AAAA,OAAOA,CAAC,MAAM,QAAQ;AAAC,OAEhBC,YAAY;AAOnB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,QAAQ,SAASD,YAAY,CAAC;EASlCE,WAAW,CAACC,aAA4B,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