dtable-ui-component 4.4.24 → 4.4.25-alpha2
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.
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
/**
|
|
10
|
+
* Detecting outside click on a react component is surprisingly hard.
|
|
11
|
+
* A general approach is to have a global click handler on the document
|
|
12
|
+
* which checks if the click target is inside the editor container or
|
|
13
|
+
* not using editorContainer.contains(e.target). This approach works well
|
|
14
|
+
* until portals are used for editors. Portals render children into a DOM
|
|
15
|
+
* node that exists outside the DOM hierarchy of the parent component so
|
|
16
|
+
* editorContainer.contains(e.target) does not work. Here are some examples
|
|
17
|
+
* of the DOM structure with different types of editors
|
|
18
|
+
*
|
|
19
|
+
*
|
|
20
|
+
* SimpleEditor for example Texbox (No Portals)
|
|
21
|
+
* <div react-data-grid>..<div>
|
|
22
|
+
* <div portal-created-by-the-grid-for-editors>
|
|
23
|
+
* <div editor-container>
|
|
24
|
+
* <div simple-editor>..</div>
|
|
25
|
+
* </div>
|
|
26
|
+
* <div>
|
|
27
|
+
*
|
|
28
|
+
* ComplexEditor for example Modals (using Portals)
|
|
29
|
+
* <div react-data-grid>..<div>
|
|
30
|
+
* <div portal-created-by-the-grid-for-editors>
|
|
31
|
+
* <div editor-container>
|
|
32
|
+
* // Nothing here
|
|
33
|
+
* </div>
|
|
34
|
+
* <div>
|
|
35
|
+
* <div portal-created-by-the-editor>
|
|
36
|
+
* <div complex-editor>..</div>
|
|
37
|
+
* </div>
|
|
38
|
+
*
|
|
39
|
+
*
|
|
40
|
+
* One approach to detect outside click is to use event bubbling through
|
|
41
|
+
* portals. An event fired from inside a portal will propagate to ancestors
|
|
42
|
+
* in the containing React tree, even if those elements are not ancestors
|
|
43
|
+
* in the DOM tree. This means a click handler can be attached on the document
|
|
44
|
+
* and on the editor container. The editor container can set a flag to notify
|
|
45
|
+
* that the click was inside the editor and the document click handler can use
|
|
46
|
+
* this flag to call onClickOutside. This approach however has a few caveats
|
|
47
|
+
* - Click handler on the document is set using document.addEventListener
|
|
48
|
+
* - Click handler on the editor container is set using onClick prop
|
|
49
|
+
*
|
|
50
|
+
* This means if a child component inside the editor calls e.stopPropagation
|
|
51
|
+
* then the click handler on the editor container will not be called whereas
|
|
52
|
+
* document click handler will be called.
|
|
53
|
+
* https://github.com/facebook/react/issues/12518
|
|
54
|
+
*
|
|
55
|
+
* To solve this issue onClickCapture event is used.
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
class ClickOutside extends _react.default.Component {
|
|
59
|
+
constructor() {
|
|
60
|
+
super(...arguments);
|
|
61
|
+
this.isClickedInside = false;
|
|
62
|
+
this.handleDocumentClick = e => {
|
|
63
|
+
if (this.isClickedInside) {
|
|
64
|
+
this.isClickedInside = false;
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
this.props.onClickOutside(e);
|
|
68
|
+
};
|
|
69
|
+
this.handleMouseDown = () => {
|
|
70
|
+
this.isClickedInside = true;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
componentDidMount() {
|
|
74
|
+
document.addEventListener('mousedown', this.handleDocumentClick);
|
|
75
|
+
}
|
|
76
|
+
componentWillUnmount() {
|
|
77
|
+
document.removeEventListener('mousedown', this.handleDocumentClick);
|
|
78
|
+
}
|
|
79
|
+
render() {
|
|
80
|
+
return /*#__PURE__*/_react.default.cloneElement(_react.default.Children.only(this.props.children), {
|
|
81
|
+
onMouseDownCapture: this.handleMouseDown
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
var _default = exports.default = ClickOutside;
|
|
@@ -10,7 +10,7 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
10
10
|
var _option = _interopRequireDefault(require("./option"));
|
|
11
11
|
var _DTableSearchInput = _interopRequireDefault(require("../DTableSearchInput"));
|
|
12
12
|
var _KeyCodes = _interopRequireDefault(require("./KeyCodes"));
|
|
13
|
-
var _ClickOutside = _interopRequireDefault(require("../
|
|
13
|
+
var _ClickOutside = _interopRequireDefault(require("../ClickOutside"));
|
|
14
14
|
require("./index.css");
|
|
15
15
|
const OPTION_HEIGHT = 32;
|
|
16
16
|
class SelectOptionGroup extends _react.Component {
|
package/lib/index.js
CHANGED
|
@@ -34,6 +34,12 @@ Object.defineProperty(exports, "CheckboxFormatter", {
|
|
|
34
34
|
return _CheckboxFormatter.default;
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
|
+
Object.defineProperty(exports, "ClickOutside", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function () {
|
|
40
|
+
return _ClickOutside.default;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
37
43
|
Object.defineProperty(exports, "CollaboratorEditor", {
|
|
38
44
|
enumerable: true,
|
|
39
45
|
get: function () {
|
|
@@ -430,4 +436,5 @@ var _DTableSearchInput = _interopRequireDefault(require("./DTableSearchInput"));
|
|
|
430
436
|
var _ModalPortal = _interopRequireDefault(require("./ModalPortal"));
|
|
431
437
|
var _RoleStatusEditor = _interopRequireDefault(require("./RoleStatusEditor"));
|
|
432
438
|
var _FieldDisplaySetting = _interopRequireDefault(require("./FieldDisplaySetting"));
|
|
433
|
-
var _DTableFiltersPopover = _interopRequireDefault(require("./DTableFiltersPopover"));
|
|
439
|
+
var _DTableFiltersPopover = _interopRequireDefault(require("./DTableFiltersPopover"));
|
|
440
|
+
var _ClickOutside = _interopRequireDefault(require("./ClickOutside"));
|
package/package.json
CHANGED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
class ClickOutside extends _react.default.Component {
|
|
10
|
-
constructor() {
|
|
11
|
-
super(...arguments);
|
|
12
|
-
this.isClickedInside = false;
|
|
13
|
-
this.handleDocumentClick = e => {
|
|
14
|
-
if (this.isClickedInside) {
|
|
15
|
-
this.isClickedInside = false;
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
this.props.onClickOutside && this.props.onClickOutside(e);
|
|
19
|
-
};
|
|
20
|
-
this.handleMouseDown = () => {
|
|
21
|
-
this.isClickedInside = true;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
componentDidMount() {
|
|
25
|
-
document.addEventListener('mousedown', this.handleDocumentClick);
|
|
26
|
-
}
|
|
27
|
-
componentWillUnmount() {
|
|
28
|
-
document.removeEventListener('mousedown', this.handleDocumentClick);
|
|
29
|
-
}
|
|
30
|
-
render() {
|
|
31
|
-
return /*#__PURE__*/_react.default.cloneElement(_react.default.Children.only(this.props.children), {
|
|
32
|
-
onMouseDownCapture: this.handleMouseDown
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.default = ClickOutside;
|