@quintoandar-tokko/hooks 1.2.308
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.
- package/LICENSE +21 -0
- package/lib/index.js +85 -0
- package/package.json +19 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 One Loop
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useToggle = exports.useOnClickOutside = exports.useFilterData = exports.isMouseOutTooltip = exports.isMouseOutParent = exports.isMouseOutJoin = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
10
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
11
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
12
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
13
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
14
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
15
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
16
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
17
|
+
var useToggle = exports.useToggle = function useToggle() {
|
|
18
|
+
var initialState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
19
|
+
var _useState = (0, _react.useState)(initialState),
|
|
20
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
21
|
+
state = _useState2[0],
|
|
22
|
+
setState = _useState2[1];
|
|
23
|
+
var toggle = (0, _react.useCallback)(function () {
|
|
24
|
+
return setState(function (state) {
|
|
25
|
+
return !state;
|
|
26
|
+
});
|
|
27
|
+
}, []);
|
|
28
|
+
return [state, toggle];
|
|
29
|
+
};
|
|
30
|
+
var useOnClickOutside = exports.useOnClickOutside = function useOnClickOutside(ref, handler) {
|
|
31
|
+
(0, _react.useEffect)(function () {
|
|
32
|
+
var listener = function listener(event) {
|
|
33
|
+
if (!ref.current || ref.current.contains(event.target)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
handler(event);
|
|
37
|
+
};
|
|
38
|
+
document.addEventListener('mousedown', listener);
|
|
39
|
+
document.addEventListener('touchstart', listener);
|
|
40
|
+
return function () {
|
|
41
|
+
document.removeEventListener('mousedown', listener);
|
|
42
|
+
document.removeEventListener('touchstart', listener);
|
|
43
|
+
};
|
|
44
|
+
}, [ref, handler]);
|
|
45
|
+
};
|
|
46
|
+
var useFilterData = exports.useFilterData = function useFilterData(data, key) {
|
|
47
|
+
var _useState3 = (0, _react.useState)(''),
|
|
48
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
49
|
+
value = _useState4[0],
|
|
50
|
+
setValue = _useState4[1];
|
|
51
|
+
var handleFilter = data.filter(function (data) {
|
|
52
|
+
return _lodash["default"].values(_lodash["default"].get(data, key, data)).some(function (val) {
|
|
53
|
+
return _lodash["default"].includes(val.toString().toLowerCase(), value.toLowerCase());
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
return [handleFilter, setValue];
|
|
57
|
+
};
|
|
58
|
+
var isMouseOutTooltip = exports.isMouseOutTooltip = function isMouseOutTooltip(e, tooltipId, parentId, placement) {
|
|
59
|
+
if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object' && document === undefined) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
var x = e.clientX;
|
|
63
|
+
var y = e.clientY;
|
|
64
|
+
var positionParent = document.getElementById(parentId).getBoundingClientRect();
|
|
65
|
+
var positionTooltip = document.getElementById(tooltipId).getBoundingClientRect();
|
|
66
|
+
return !(placement === 'right' && (x >= positionTooltip.right || y <= positionTooltip.top || y >= positionTooltip.bottom || x < positionTooltip.left && (y <= positionParent.top || y >= positionParent.bottom)) || placement === 'left' && (x <= positionTooltip.left || y <= positionTooltip.top || y >= positionTooltip.bottom || x > positionTooltip.right && (y <= positionParent.top || y >= positionParent.bottom)) || placement === 'bottom' && (y >= positionTooltip.bottom || x <= positionTooltip.left || x >= positionTooltip.right || y < positionTooltip.top && (x <= positionParent.left || x >= positionParent.right)) || placement === 'top' && (y <= positionTooltip.top || x <= positionTooltip.left || x >= positionTooltip.right || y > positionTooltip.bottom && (x <= positionParent.left || x >= positionParent.right)));
|
|
67
|
+
};
|
|
68
|
+
var isMouseOutJoin = exports.isMouseOutJoin = function isMouseOutJoin(e, joinId, placement) {
|
|
69
|
+
if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object' && document === undefined) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
var x = e.clientX;
|
|
73
|
+
var y = e.clientY;
|
|
74
|
+
var positionJoin = document.getElementById(joinId).getBoundingClientRect();
|
|
75
|
+
return !((placement === 'right' || placement === 'left') && (y <= positionJoin.top || y >= positionJoin.bottom - 1) || (placement === 'bottom' || placement === 'top') && (x <= positionJoin.left || x >= positionJoin.right));
|
|
76
|
+
};
|
|
77
|
+
var isMouseOutParent = exports.isMouseOutParent = function isMouseOutParent(e, parentId, placement) {
|
|
78
|
+
if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object' && document === undefined) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
var x = e.clientX;
|
|
82
|
+
var y = e.clientY;
|
|
83
|
+
var positionParent = document.getElementById(parentId).getBoundingClientRect();
|
|
84
|
+
return !(placement === 'right' && (x <= positionParent.left || y <= positionParent.top || y >= positionParent.bottom) || placement === 'bottom' && (y <= positionParent.top || x <= positionParent.left || x >= positionParent.right) || placement === 'left' && (x >= positionParent.right || y <= positionParent.top || y >= positionParent.bottom - 1) || placement === 'top' && (y >= positionParent.bottom || x <= positionParent.left || x >= positionParent.right));
|
|
85
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@quintoandar-tokko/hooks",
|
|
3
|
+
"version": "1.2.308",
|
|
4
|
+
"main": "lib/index.js",
|
|
5
|
+
"module": "src/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"lib"
|
|
8
|
+
],
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"lodash": "4.17.21"
|
|
11
|
+
},
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"react": "^16.8.0"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"gitHead": "d33e426a17c29e62c8ea591ae6afa96300d55ad9"
|
|
19
|
+
}
|