@sproutsocial/seeds-react-hooks 1.0.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.
- package/__flow__/index.flow.js +8 -0
- package/__flow__/index.js +3 -0
- package/__flow__/useInteractiveColor/useInteractiveColor.flow.js +3 -0
- package/__flow__/useMultiselect/useMultiselect.flow.js +17 -0
- package/__flow__/useMutationObserver/useMutationObserver.flow.js +19 -0
- package/__flow__/useSelect/useSelect.flow.js +10 -0
- package/__flow__/useTextContent/useTextContent.flow.js +21 -0
- package/__flow__/useWhyDidYouUpdate/useWhyDidYouUpdate.flow.js +3 -0
- package/commonjs/index.flow.js +71 -0
- package/commonjs/index.js +82 -0
- package/commonjs/index.js.flow +3 -0
- package/commonjs/useInteractiveColor/useInteractiveColor.flow.js +1 -0
- package/commonjs/useInteractiveColor/useInteractiveColor.js +32 -0
- package/commonjs/useMeasure/useMeasure.js +65 -0
- package/commonjs/useMultiselect/useMultiselect.flow.js +1 -0
- package/commonjs/useMultiselect/useMultiselect.js +77 -0
- package/commonjs/useMutationObserver/useMutationObserver.flow.js +1 -0
- package/commonjs/useMutationObserver/useMutationObserver.js +58 -0
- package/commonjs/useSelect/useSelect.flow.js +1 -0
- package/commonjs/useSelect/useSelect.js +38 -0
- package/commonjs/useTextContent/useTextContent.flow.js +25 -0
- package/commonjs/useTextContent/useTextContent.js +26 -0
- package/commonjs/useWhyDidYouUpdate/useWhyDidYouUpdate.flow.js +1 -0
- package/commonjs/useWhyDidYouUpdate/useWhyDidYouUpdate.js +46 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/useInteractiveColor/useInteractiveColor.d.ts +9 -0
- package/dist/types/useInteractiveColor/useInteractiveColor.d.ts.map +1 -0
- package/dist/types/useMeasure/useMeasure.d.ts +14 -0
- package/dist/types/useMeasure/useMeasure.d.ts.map +1 -0
- package/dist/types/useMultiselect/useMultiselect.d.ts +11 -0
- package/dist/types/useMultiselect/useMultiselect.d.ts.map +1 -0
- package/dist/types/useMutationObserver/useMutationObserver.d.ts +18 -0
- package/dist/types/useMutationObserver/useMutationObserver.d.ts.map +1 -0
- package/dist/types/useSelect/useSelect.d.ts +10 -0
- package/dist/types/useSelect/useSelect.d.ts.map +1 -0
- package/dist/types/useTextContent/useTextContent.d.ts +5 -0
- package/dist/types/useTextContent/useTextContent.d.ts.map +1 -0
- package/dist/types/useWhyDidYouUpdate/useWhyDidYouUpdate.d.ts +2 -0
- package/dist/types/useWhyDidYouUpdate/useWhyDidYouUpdate.d.ts.map +1 -0
- package/lib/index.flow.js +6 -0
- package/lib/index.js +7 -0
- package/lib/index.js.flow +3 -0
- package/lib/useInteractiveColor/useInteractiveColor.flow.js +0 -0
- package/lib/useInteractiveColor/useInteractiveColor.js +27 -0
- package/lib/useMeasure/useMeasure.js +59 -0
- package/lib/useMultiselect/useMultiselect.flow.js +0 -0
- package/lib/useMultiselect/useMultiselect.js +71 -0
- package/lib/useMutationObserver/useMutationObserver.flow.js +0 -0
- package/lib/useMutationObserver/useMutationObserver.js +51 -0
- package/lib/useSelect/useSelect.flow.js +0 -0
- package/lib/useSelect/useSelect.js +32 -0
- package/lib/useTextContent/useTextContent.flow.js +23 -0
- package/lib/useTextContent/useTextContent.js +20 -0
- package/lib/useWhyDidYouUpdate/useWhyDidYouUpdate.flow.js +0 -0
- package/lib/useWhyDidYouUpdate/useWhyDidYouUpdate.js +40 -0
- package/package.json +41 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
export * from "./useSelect/useSelect";
|
|
4
|
+
export * from "./useMultiselect/useMultiselect";
|
|
5
|
+
export * from "./useMutationObserver/useMutationObserver";
|
|
6
|
+
export * from "./useTextContent/useTextContent";
|
|
7
|
+
export * from "./useWhyDidYouUpdate/useWhyDidYouUpdate";
|
|
8
|
+
export * from "./useInteractiveColor/useInteractiveColor";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
type TypeMultiSelectProps<T: string> = {|
|
|
4
|
+
initialValue?: T[],
|
|
5
|
+
onChange?: (value: Array<string | T>) => any,
|
|
6
|
+
|};
|
|
7
|
+
declare var valueReducer: (state: Set<string>, action: {|
|
|
8
|
+
type: string
|
|
9
|
+
|} | {|
|
|
10
|
+
type: string,
|
|
11
|
+
value: string,
|
|
12
|
+
|}) => Set<string>;
|
|
13
|
+
declare export var useMultiselect: <T: string>(props?: TypeMultiSelectProps<T>) => {|
|
|
14
|
+
onChange: (newValue: string) => void,
|
|
15
|
+
onClear: () => void,
|
|
16
|
+
value: Array<string | T>,
|
|
17
|
+
|};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type TypeMutationObserverInitRequired = {|
|
|
2
|
+
childList: true
|
|
3
|
+
|} | {|
|
|
4
|
+
attributes: true
|
|
5
|
+
|} | {|
|
|
6
|
+
characterData: true
|
|
7
|
+
|};
|
|
8
|
+
type TypeMutationObserverInit = {
|
|
9
|
+
...TypeMutationObserverInitRequired,
|
|
10
|
+
subtree?: boolean,
|
|
11
|
+
attributeOldValue?: boolean,
|
|
12
|
+
characterDataOldValue?: boolean,
|
|
13
|
+
attributeFilter?: Array<string>,
|
|
14
|
+
...
|
|
15
|
+
};
|
|
16
|
+
type TypeMutationObserverCallback = (mutationList?: MutationRecord[], observer?: MutationObserver) => any;
|
|
17
|
+
declare var defaultCallback: TypeMutationObserverCallback;
|
|
18
|
+
declare export function useMutationObserver(targetNode: ?Node, config: TypeMutationObserverInit, callback?: TypeMutationObserverCallback): void | any;
|
|
19
|
+
declare export function useMutationObserverOnce(targetNode: ?Node, config: TypeMutationObserverInit, callback: TypeMutationObserverCallback): void | any;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
type TypeSingleSelectProps<T: string> = {|
|
|
4
|
+
initialValue?: T | "",
|
|
5
|
+
onChange?: (value: string | T) => any,
|
|
6
|
+
|};
|
|
7
|
+
declare export var useSelect: <T: string>(props?: TypeSingleSelectProps<T>) => {|
|
|
8
|
+
onChange: (newValue: string) => void,
|
|
9
|
+
value: T | string,
|
|
10
|
+
|};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import { useState, useCallback } from "react";
|
|
4
|
+
type ReturnType<F> = $PropertyType<$ObjMap<{
|
|
5
|
+
x: F,
|
|
6
|
+
...
|
|
7
|
+
}, <R>(f: (...any) => R) => R>, "x">;
|
|
8
|
+
const useTextContentClone = (initial: string) => {
|
|
9
|
+
const [textContent, setTextContent] = useState(initial);
|
|
10
|
+
const ref = useCallback((node: Node) => {
|
|
11
|
+
if (node !== null) {
|
|
12
|
+
setTextContent(node.textContent);
|
|
13
|
+
}
|
|
14
|
+
}, []);
|
|
15
|
+
ref.current = textContent;
|
|
16
|
+
return ref;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// Couldn't find a way to achieve this with flow type syntax - open to suggestions
|
|
20
|
+
// Tried https://github.com/facebook/flow/issues/2840#issuecomment-452934068 but it didn't work
|
|
21
|
+
declare export function useTextContent(initial: string): ReturnType<typeof useTextContentClone>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _useSelect = require("./useSelect/useSelect");
|
|
7
|
+
Object.keys(_useSelect).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _useSelect[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function get() {
|
|
13
|
+
return _useSelect[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _useMultiselect = require("./useMultiselect/useMultiselect");
|
|
18
|
+
Object.keys(_useMultiselect).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _useMultiselect[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function get() {
|
|
24
|
+
return _useMultiselect[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _useMutationObserver = require("./useMutationObserver/useMutationObserver");
|
|
29
|
+
Object.keys(_useMutationObserver).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _useMutationObserver[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function get() {
|
|
35
|
+
return _useMutationObserver[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
var _useTextContent = require("./useTextContent/useTextContent");
|
|
40
|
+
Object.keys(_useTextContent).forEach(function (key) {
|
|
41
|
+
if (key === "default" || key === "__esModule") return;
|
|
42
|
+
if (key in exports && exports[key] === _useTextContent[key]) return;
|
|
43
|
+
Object.defineProperty(exports, key, {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function get() {
|
|
46
|
+
return _useTextContent[key];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
var _useWhyDidYouUpdate = require("./useWhyDidYouUpdate/useWhyDidYouUpdate");
|
|
51
|
+
Object.keys(_useWhyDidYouUpdate).forEach(function (key) {
|
|
52
|
+
if (key === "default" || key === "__esModule") return;
|
|
53
|
+
if (key in exports && exports[key] === _useWhyDidYouUpdate[key]) return;
|
|
54
|
+
Object.defineProperty(exports, key, {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function get() {
|
|
57
|
+
return _useWhyDidYouUpdate[key];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
var _useInteractiveColor = require("./useInteractiveColor/useInteractiveColor");
|
|
62
|
+
Object.keys(_useInteractiveColor).forEach(function (key) {
|
|
63
|
+
if (key === "default" || key === "__esModule") return;
|
|
64
|
+
if (key in exports && exports[key] === _useInteractiveColor[key]) return;
|
|
65
|
+
Object.defineProperty(exports, key, {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
get: function get() {
|
|
68
|
+
return _useInteractiveColor[key];
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _useMeasure = require("./useMeasure/useMeasure");
|
|
7
|
+
Object.keys(_useMeasure).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _useMeasure[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function get() {
|
|
13
|
+
return _useMeasure[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _useSelect = require("./useSelect/useSelect");
|
|
18
|
+
Object.keys(_useSelect).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _useSelect[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function get() {
|
|
24
|
+
return _useSelect[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _useMultiselect = require("./useMultiselect/useMultiselect");
|
|
29
|
+
Object.keys(_useMultiselect).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _useMultiselect[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function get() {
|
|
35
|
+
return _useMultiselect[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
var _useMutationObserver = require("./useMutationObserver/useMutationObserver");
|
|
40
|
+
Object.keys(_useMutationObserver).forEach(function (key) {
|
|
41
|
+
if (key === "default" || key === "__esModule") return;
|
|
42
|
+
if (key in exports && exports[key] === _useMutationObserver[key]) return;
|
|
43
|
+
Object.defineProperty(exports, key, {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function get() {
|
|
46
|
+
return _useMutationObserver[key];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
var _useTextContent = require("./useTextContent/useTextContent");
|
|
51
|
+
Object.keys(_useTextContent).forEach(function (key) {
|
|
52
|
+
if (key === "default" || key === "__esModule") return;
|
|
53
|
+
if (key in exports && exports[key] === _useTextContent[key]) return;
|
|
54
|
+
Object.defineProperty(exports, key, {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function get() {
|
|
57
|
+
return _useTextContent[key];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
var _useWhyDidYouUpdate = require("./useWhyDidYouUpdate/useWhyDidYouUpdate");
|
|
62
|
+
Object.keys(_useWhyDidYouUpdate).forEach(function (key) {
|
|
63
|
+
if (key === "default" || key === "__esModule") return;
|
|
64
|
+
if (key in exports && exports[key] === _useWhyDidYouUpdate[key]) return;
|
|
65
|
+
Object.defineProperty(exports, key, {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
get: function get() {
|
|
68
|
+
return _useWhyDidYouUpdate[key];
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
var _useInteractiveColor = require("./useInteractiveColor/useInteractiveColor");
|
|
73
|
+
Object.keys(_useInteractiveColor).forEach(function (key) {
|
|
74
|
+
if (key === "default" || key === "__esModule") return;
|
|
75
|
+
if (key in exports && exports[key] === _useInteractiveColor[key]) return;
|
|
76
|
+
Object.defineProperty(exports, key, {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function get() {
|
|
79
|
+
return _useInteractiveColor[key];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useInteractiveColor = void 0;
|
|
7
|
+
var _polished = require("polished");
|
|
8
|
+
var _styledComponents = require("styled-components");
|
|
9
|
+
/**
|
|
10
|
+
* The useInteractiveColor hook has context of theme mode (light or dark)
|
|
11
|
+
* and can be used to lighten or darken a color dynamically
|
|
12
|
+
*
|
|
13
|
+
* note: colors are limited to our theme colors
|
|
14
|
+
*/
|
|
15
|
+
var useInteractiveColor = exports.useInteractiveColor = function useInteractiveColor(themeColor) {
|
|
16
|
+
// Throw error if used outside of a ThemeProvider (styled-components)
|
|
17
|
+
if (!(0, _styledComponents.useTheme)()) {
|
|
18
|
+
throw new Error("useInteractiveColor() must be used within a Styled Components ThemeProvider");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Get the current theme mode ie. 'light' or 'dark'
|
|
22
|
+
var theme = (0, _styledComponents.useTheme)();
|
|
23
|
+
var themeMode = theme.mode;
|
|
24
|
+
|
|
25
|
+
// If the theme mode is dark, return a lightened version of the themeValue
|
|
26
|
+
if (themeMode === "dark") {
|
|
27
|
+
return (0, _polished.lighten)(0.2, themeColor);
|
|
28
|
+
} else {
|
|
29
|
+
// If the theme mode is light, return a darkened version of the themeValue
|
|
30
|
+
return (0, _polished.darken)(0.2, themeColor);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useMeasure = useMeasure;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
9
|
+
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."); }
|
|
10
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
11
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
12
|
+
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; } }
|
|
13
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
14
|
+
var initialBounds = Object.freeze({
|
|
15
|
+
x: 0,
|
|
16
|
+
y: 0,
|
|
17
|
+
width: 0,
|
|
18
|
+
height: 0,
|
|
19
|
+
top: 0,
|
|
20
|
+
right: 0,
|
|
21
|
+
bottom: 0,
|
|
22
|
+
left: 0
|
|
23
|
+
});
|
|
24
|
+
function useMeasure(ref) {
|
|
25
|
+
var _useState = (0, _react.useState)(initialBounds),
|
|
26
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
27
|
+
bounds = _useState2[0],
|
|
28
|
+
setContentRect = _useState2[1];
|
|
29
|
+
(0, _react.useLayoutEffect)(function () {
|
|
30
|
+
var element = ref.current;
|
|
31
|
+
if (!element ||
|
|
32
|
+
// in non-browser environments (e.g. Jest tests) ResizeObserver is not defined
|
|
33
|
+
!("ResizeObserver" in window)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
var resizeObserver = new ResizeObserver(function (_ref) {
|
|
37
|
+
var _ref2 = _slicedToArray(_ref, 1),
|
|
38
|
+
entry = _ref2[0];
|
|
39
|
+
var _entry$contentRect = entry.contentRect,
|
|
40
|
+
x = _entry$contentRect.x,
|
|
41
|
+
y = _entry$contentRect.y,
|
|
42
|
+
width = _entry$contentRect.width,
|
|
43
|
+
height = _entry$contentRect.height,
|
|
44
|
+
top = _entry$contentRect.top,
|
|
45
|
+
right = _entry$contentRect.right,
|
|
46
|
+
bottom = _entry$contentRect.bottom,
|
|
47
|
+
left = _entry$contentRect.left;
|
|
48
|
+
setContentRect({
|
|
49
|
+
x: x,
|
|
50
|
+
y: y,
|
|
51
|
+
width: width,
|
|
52
|
+
height: height,
|
|
53
|
+
top: top,
|
|
54
|
+
right: right,
|
|
55
|
+
bottom: bottom,
|
|
56
|
+
left: left
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
resizeObserver.observe(ref.current);
|
|
60
|
+
return function () {
|
|
61
|
+
resizeObserver.disconnect();
|
|
62
|
+
};
|
|
63
|
+
}, [ref]);
|
|
64
|
+
return bounds;
|
|
65
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useMultiselect = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
9
|
+
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."); }
|
|
10
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
11
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
12
|
+
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; } }
|
|
13
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
14
|
+
var valueReducer = function valueReducer(state, action) {
|
|
15
|
+
var newState = new Set(state);
|
|
16
|
+
switch (action.type) {
|
|
17
|
+
case "reset":
|
|
18
|
+
{
|
|
19
|
+
return new Set();
|
|
20
|
+
}
|
|
21
|
+
case "toggle_item":
|
|
22
|
+
default:
|
|
23
|
+
{
|
|
24
|
+
if (action.value) {
|
|
25
|
+
if (newState.has(action.value)) {
|
|
26
|
+
newState.delete(action.value);
|
|
27
|
+
} else {
|
|
28
|
+
newState.add(action.value);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return newState;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var useMultiselect = exports.useMultiselect = function useMultiselect() {
|
|
36
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
37
|
+
initialValue: [],
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
39
|
+
onChange: function onChange() {}
|
|
40
|
+
},
|
|
41
|
+
_ref$initialValue = _ref.initialValue,
|
|
42
|
+
initialValue = _ref$initialValue === void 0 ? [] : _ref$initialValue,
|
|
43
|
+
_ref$onChange = _ref.onChange,
|
|
44
|
+
userOnChange = _ref$onChange === void 0 ? function () {} : _ref$onChange;
|
|
45
|
+
var _useReducer = (0, _react.useReducer)(valueReducer, new Set(initialValue)),
|
|
46
|
+
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
47
|
+
value = _useReducer2[0],
|
|
48
|
+
dispatch = _useReducer2[1];
|
|
49
|
+
var getArrayValue = function getArrayValue(value) {
|
|
50
|
+
return Array.from(value);
|
|
51
|
+
};
|
|
52
|
+
var onChange = (0, _react.useCallback)(function (newValue) {
|
|
53
|
+
dispatch({
|
|
54
|
+
type: "toggle_item",
|
|
55
|
+
value: newValue
|
|
56
|
+
});
|
|
57
|
+
}, [dispatch]);
|
|
58
|
+
var isFirstRun = (0, _react.useRef)(true);
|
|
59
|
+
(0, _react.useEffect)(function () {
|
|
60
|
+
if (isFirstRun.current) {
|
|
61
|
+
isFirstRun.current = false;
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
userOnChange(getArrayValue(value));
|
|
65
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
66
|
+
}, [userOnChange, value]);
|
|
67
|
+
var onClear = (0, _react.useCallback)(function () {
|
|
68
|
+
dispatch({
|
|
69
|
+
type: "reset"
|
|
70
|
+
});
|
|
71
|
+
}, [dispatch]);
|
|
72
|
+
return {
|
|
73
|
+
value: getArrayValue(value),
|
|
74
|
+
onChange: onChange,
|
|
75
|
+
onClear: onClear
|
|
76
|
+
};
|
|
77
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useMutationObserver = useMutationObserver;
|
|
7
|
+
exports.useMutationObserverOnce = useMutationObserverOnce;
|
|
8
|
+
var _seedsReactUtilities = require("@sproutsocial/seeds-react-utilities");
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
11
|
+
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."); }
|
|
12
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
13
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
14
|
+
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; } }
|
|
15
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
16
|
+
var defaultCallback = function defaultCallback(mutationList) {
|
|
17
|
+
return mutationList;
|
|
18
|
+
};
|
|
19
|
+
function useMutationObserver(targetNode, config) {
|
|
20
|
+
var callback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultCallback;
|
|
21
|
+
if (!(0, _seedsReactUtilities.canUseDOM)()) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
/* eslint-disable-next-line */
|
|
25
|
+
var _useState = (0, _react.useState)(undefined),
|
|
26
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
27
|
+
value = _useState2[0],
|
|
28
|
+
setValue = _useState2[1];
|
|
29
|
+
/* eslint-disable-next-line */
|
|
30
|
+
var observer = (0, _react.useMemo)(function () {
|
|
31
|
+
return new MutationObserver(function (mutationList, observer) {
|
|
32
|
+
var result = callback(mutationList, observer);
|
|
33
|
+
setValue(result);
|
|
34
|
+
});
|
|
35
|
+
}, [callback]);
|
|
36
|
+
/* eslint-disable-next-line */
|
|
37
|
+
(0, _react.useEffect)(function () {
|
|
38
|
+
if (targetNode) {
|
|
39
|
+
observer.observe(targetNode, config);
|
|
40
|
+
return function () {
|
|
41
|
+
observer.disconnect();
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}, [targetNode, config, observer]);
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
function useMutationObserverOnce(targetNode, config, callback) {
|
|
48
|
+
var _useState3 = (0, _react.useState)(true),
|
|
49
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
50
|
+
isObserving = _useState4[0],
|
|
51
|
+
setObserving = _useState4[1];
|
|
52
|
+
var node = isObserving ? targetNode : null;
|
|
53
|
+
var value = useMutationObserver(node, config, callback);
|
|
54
|
+
if (value !== undefined && isObserving) {
|
|
55
|
+
setObserving(false);
|
|
56
|
+
}
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useSelect = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
9
|
+
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."); }
|
|
10
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
11
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
12
|
+
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; } }
|
|
13
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
14
|
+
var useSelect = exports.useSelect = function useSelect() {
|
|
15
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
16
|
+
initialValue: "",
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
18
|
+
onChange: function onChange() {}
|
|
19
|
+
},
|
|
20
|
+
_ref$initialValue = _ref.initialValue,
|
|
21
|
+
initialValue = _ref$initialValue === void 0 ? "" : _ref$initialValue,
|
|
22
|
+
_ref$onChange = _ref.onChange,
|
|
23
|
+
userOnChange = _ref$onChange === void 0 ? function () {} : _ref$onChange;
|
|
24
|
+
var _useState = (0, _react.useState)(initialValue),
|
|
25
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
26
|
+
value = _useState2[0],
|
|
27
|
+
setValue = _useState2[1];
|
|
28
|
+
var onChange = (0, _react.useCallback)(function (newValue) {
|
|
29
|
+
if (newValue !== value) {
|
|
30
|
+
setValue(newValue);
|
|
31
|
+
userOnChange(newValue);
|
|
32
|
+
}
|
|
33
|
+
}, [userOnChange, value]);
|
|
34
|
+
return {
|
|
35
|
+
value: value,
|
|
36
|
+
onChange: onChange
|
|
37
|
+
};
|
|
38
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _react = require("react");
|
|
4
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
5
|
+
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."); }
|
|
6
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
7
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
8
|
+
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; } }
|
|
9
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
10
|
+
var useTextContentClone = function useTextContentClone(initial) {
|
|
11
|
+
var _useState = (0, _react.useState)(initial),
|
|
12
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
13
|
+
textContent = _useState2[0],
|
|
14
|
+
setTextContent = _useState2[1];
|
|
15
|
+
var ref = (0, _react.useCallback)(function (node) {
|
|
16
|
+
if (node !== null) {
|
|
17
|
+
setTextContent(node.textContent);
|
|
18
|
+
}
|
|
19
|
+
}, []);
|
|
20
|
+
ref.current = textContent;
|
|
21
|
+
return ref;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// Couldn't find a way to achieve this with flow type syntax - open to suggestions
|
|
25
|
+
// Tried https://github.com/facebook/flow/issues/2840#issuecomment-452934068 but it didn't work
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useTextContent = useTextContent;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
9
|
+
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."); }
|
|
10
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
11
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
12
|
+
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; } }
|
|
13
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
14
|
+
function useTextContent(initial) {
|
|
15
|
+
var _useState = (0, _react.useState)(initial),
|
|
16
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
17
|
+
textContent = _useState2[0],
|
|
18
|
+
setTextContent = _useState2[1];
|
|
19
|
+
var ref = (0, _react.useCallback)(function (node) {
|
|
20
|
+
if (node && node.textContent !== null) {
|
|
21
|
+
setTextContent(node.textContent);
|
|
22
|
+
}
|
|
23
|
+
}, []);
|
|
24
|
+
ref.current = textContent;
|
|
25
|
+
return ref;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useWhyDidYouUpdate = useWhyDidYouUpdate;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
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); }
|
|
9
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
10
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
11
|
+
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; }
|
|
12
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
13
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
14
|
+
function useWhyDidYouUpdate(name, props) {
|
|
15
|
+
// Get a mutable ref object where we can store props ...
|
|
16
|
+
// ... for comparison next time this hook runs.
|
|
17
|
+
var previousProps = (0, _react.useRef)({});
|
|
18
|
+
(0, _react.useEffect)(function () {
|
|
19
|
+
if (previousProps.current) {
|
|
20
|
+
// Get all keys from previous and current props
|
|
21
|
+
var allKeys = Object.keys(_objectSpread(_objectSpread({}, previousProps.current), props));
|
|
22
|
+
// Use this object to keep track of changed props
|
|
23
|
+
var changesObj = {};
|
|
24
|
+
// Iterate through keys
|
|
25
|
+
allKeys.forEach(function (key) {
|
|
26
|
+
// If previous is different from current
|
|
27
|
+
if (previousProps.current[key] !== props[key]) {
|
|
28
|
+
// Add to changesObj
|
|
29
|
+
changesObj[key] = {
|
|
30
|
+
from: previousProps.current[key],
|
|
31
|
+
to: props[key]
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// If changesObj not empty then output to console
|
|
37
|
+
if (Object.keys(changesObj).length) {
|
|
38
|
+
// eslint-disable-next-line no-console
|
|
39
|
+
console.log("[why-did-you-update]", name, changesObj);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Finally update previousProps with current props for next hook call
|
|
44
|
+
previousProps.current = props;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./useMeasure/useMeasure";
|
|
2
|
+
export * from "./useSelect/useSelect";
|
|
3
|
+
export * from "./useMultiselect/useMultiselect";
|
|
4
|
+
export * from "./useMutationObserver/useMutationObserver";
|
|
5
|
+
export * from "./useTextContent/useTextContent";
|
|
6
|
+
export * from "./useWhyDidYouUpdate/useWhyDidYouUpdate";
|
|
7
|
+
export * from "./useInteractiveColor/useInteractiveColor";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,iCAAiC,CAAC;AAChD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,iCAAiC,CAAC;AAChD,cAAc,yCAAyC,CAAC;AACxD,cAAc,2CAA2C,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The useInteractiveColor hook has context of theme mode (light or dark)
|
|
3
|
+
* and can be used to lighten or darken a color dynamically
|
|
4
|
+
*
|
|
5
|
+
* note: colors are limited to our theme colors
|
|
6
|
+
*/
|
|
7
|
+
declare const useInteractiveColor: (themeColor: string) => string;
|
|
8
|
+
export { useInteractiveColor };
|
|
9
|
+
//# sourceMappingURL=useInteractiveColor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useInteractiveColor.d.ts","sourceRoot":"","sources":["../../../src/useInteractiveColor/useInteractiveColor.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,QAAA,MAAM,mBAAmB,eAAgB,MAAM,KAAG,MAmBjD,CAAC;AAEF,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
interface DOMRectObject {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
top: number;
|
|
8
|
+
right: number;
|
|
9
|
+
bottom: number;
|
|
10
|
+
left: number;
|
|
11
|
+
}
|
|
12
|
+
export declare function useMeasure<TElement extends Element>(ref: RefObject<TElement>): Readonly<DOMRectObject>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=useMeasure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMeasure.d.ts","sourceRoot":"","sources":["../../../src/useMeasure/useMeasure.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAElE,UAAU,aAAa;IACrB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAYD,wBAAgB,UAAU,CAAC,QAAQ,SAAS,OAAO,EAAE,GAAG,EAAE,SAAS,CAAC,QAAQ,CAAC,2BAqC5E"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type TypeMultiSelectProps<T extends string> = {
|
|
2
|
+
initialValue?: T[];
|
|
3
|
+
onChange?: (value: Array<string | T>) => any;
|
|
4
|
+
};
|
|
5
|
+
export declare const useMultiselect: <T extends string>({ initialValue, onChange: userOnChange, }?: TypeMultiSelectProps<T>) => {
|
|
6
|
+
value: (string | T)[];
|
|
7
|
+
onChange: (newValue: string) => void;
|
|
8
|
+
onClear: () => void;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=useMultiselect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMultiselect.d.ts","sourceRoot":"","sources":["../../../src/useMultiselect/useMultiselect.ts"],"names":[],"mappings":"AAEA,KAAK,oBAAoB,CAAC,CAAC,SAAS,MAAM,IAAI;IAC5C,YAAY,CAAC,EAAE,CAAC,EAAE,CAAC;IAEnB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG,CAAC;CAC9C,CAAC;AAyBF,eAAO,MAAM,cAAc;;yBAiBZ,MAAM;;CAsBpB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type TypeMutationObserverInitRequired = {
|
|
2
|
+
childList: true;
|
|
3
|
+
} | {
|
|
4
|
+
attributes: true;
|
|
5
|
+
} | {
|
|
6
|
+
characterData: true;
|
|
7
|
+
};
|
|
8
|
+
type TypeMutationObserverInit = {
|
|
9
|
+
subtree?: boolean;
|
|
10
|
+
attributeOldValue?: boolean;
|
|
11
|
+
characterDataOldValue?: boolean;
|
|
12
|
+
attributeFilter?: Array<string>;
|
|
13
|
+
} & TypeMutationObserverInitRequired;
|
|
14
|
+
type TypeMutationObserverCallback = (mutationList?: MutationRecord[], observer?: MutationObserver) => any;
|
|
15
|
+
export declare function useMutationObserver(targetNode: Node | null, config: TypeMutationObserverInit, callback?: TypeMutationObserverCallback): undefined;
|
|
16
|
+
export declare function useMutationObserverOnce(targetNode: Node | null, config: TypeMutationObserverInit, callback: TypeMutationObserverCallback): undefined;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=useMutationObserver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMutationObserver.d.ts","sourceRoot":"","sources":["../../../src/useMutationObserver/useMutationObserver.ts"],"names":[],"mappings":"AAGA,KAAK,gCAAgC,GACjC;IACE,SAAS,EAAE,IAAI,CAAC;CACjB,GACD;IACE,UAAU,EAAE,IAAI,CAAC;CAClB,GACD;IACE,aAAa,EAAE,IAAI,CAAC;CACrB,CAAC;AAEN,KAAK,wBAAwB,GAAG;IAC9B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,eAAe,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACjC,GAAG,gCAAgC,CAAC;AAErC,KAAK,4BAA4B,GAAG,CAClC,YAAY,CAAC,EAAE,cAAc,EAAE,EAC/B,QAAQ,CAAC,EAAE,gBAAgB,KAExB,GAAG,CAAC;AAKT,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,IAAI,GAAG,IAAI,EACvB,MAAM,EAAE,wBAAwB,EAChC,QAAQ,GAAE,4BAA8C,aA2BzD;AAED,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,IAAI,GAAG,IAAI,EACvB,MAAM,EAAE,wBAAwB,EAChC,QAAQ,EAAE,4BAA4B,aASvC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type TypeSingleSelectProps<T extends string> = {
|
|
2
|
+
initialValue?: T | "";
|
|
3
|
+
onChange?: (value: string | T) => any;
|
|
4
|
+
};
|
|
5
|
+
export declare const useSelect: <T extends string>({ initialValue, onChange: userOnChange, }?: TypeSingleSelectProps<T>) => {
|
|
6
|
+
value: string | T;
|
|
7
|
+
onChange: (newValue: string) => void;
|
|
8
|
+
};
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=useSelect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSelect.d.ts","sourceRoot":"","sources":["../../../src/useSelect/useSelect.ts"],"names":[],"mappings":"AAEA,KAAK,qBAAqB,CAAC,CAAC,SAAS,MAAM,IAAI;IAC7C,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC;IAEtB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,KAAK,GAAG,CAAC;CACvC,CAAC;AAEF,eAAO,MAAM,SAAS;;yBAcP,MAAM;CAUpB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTextContent.d.ts","sourceRoot":"","sources":["../../../src/useTextContent/useTextContent.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC,GAAG;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAC3E,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,kBAW7C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useWhyDidYouUpdate.d.ts","sourceRoot":"","sources":["../../../src/useWhyDidYouUpdate/useWhyDidYouUpdate.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAiC7D"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from "./useSelect/useSelect";
|
|
2
|
+
export * from "./useMultiselect/useMultiselect";
|
|
3
|
+
export * from "./useMutationObserver/useMutationObserver";
|
|
4
|
+
export * from "./useTextContent/useTextContent";
|
|
5
|
+
export * from "./useWhyDidYouUpdate/useWhyDidYouUpdate";
|
|
6
|
+
export * from "./useInteractiveColor/useInteractiveColor";
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./useMeasure/useMeasure";
|
|
2
|
+
export * from "./useSelect/useSelect";
|
|
3
|
+
export * from "./useMultiselect/useMultiselect";
|
|
4
|
+
export * from "./useMutationObserver/useMutationObserver";
|
|
5
|
+
export * from "./useTextContent/useTextContent";
|
|
6
|
+
export * from "./useWhyDidYouUpdate/useWhyDidYouUpdate";
|
|
7
|
+
export * from "./useInteractiveColor/useInteractiveColor";
|
|
File without changes
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { darken, lighten } from "polished";
|
|
2
|
+
import { useTheme } from "styled-components";
|
|
3
|
+
/**
|
|
4
|
+
* The useInteractiveColor hook has context of theme mode (light or dark)
|
|
5
|
+
* and can be used to lighten or darken a color dynamically
|
|
6
|
+
*
|
|
7
|
+
* note: colors are limited to our theme colors
|
|
8
|
+
*/
|
|
9
|
+
var useInteractiveColor = function useInteractiveColor(themeColor) {
|
|
10
|
+
// Throw error if used outside of a ThemeProvider (styled-components)
|
|
11
|
+
if (!useTheme()) {
|
|
12
|
+
throw new Error("useInteractiveColor() must be used within a Styled Components ThemeProvider");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Get the current theme mode ie. 'light' or 'dark'
|
|
16
|
+
var theme = useTheme();
|
|
17
|
+
var themeMode = theme.mode;
|
|
18
|
+
|
|
19
|
+
// If the theme mode is dark, return a lightened version of the themeValue
|
|
20
|
+
if (themeMode === "dark") {
|
|
21
|
+
return lighten(0.2, themeColor);
|
|
22
|
+
} else {
|
|
23
|
+
// If the theme mode is light, return a darkened version of the themeValue
|
|
24
|
+
return darken(0.2, themeColor);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
export { useInteractiveColor };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
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."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
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; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { useState, useLayoutEffect } from "react";
|
|
8
|
+
var initialBounds = Object.freeze({
|
|
9
|
+
x: 0,
|
|
10
|
+
y: 0,
|
|
11
|
+
width: 0,
|
|
12
|
+
height: 0,
|
|
13
|
+
top: 0,
|
|
14
|
+
right: 0,
|
|
15
|
+
bottom: 0,
|
|
16
|
+
left: 0
|
|
17
|
+
});
|
|
18
|
+
export function useMeasure(ref) {
|
|
19
|
+
var _useState = useState(initialBounds),
|
|
20
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
21
|
+
bounds = _useState2[0],
|
|
22
|
+
setContentRect = _useState2[1];
|
|
23
|
+
useLayoutEffect(function () {
|
|
24
|
+
var element = ref.current;
|
|
25
|
+
if (!element ||
|
|
26
|
+
// in non-browser environments (e.g. Jest tests) ResizeObserver is not defined
|
|
27
|
+
!("ResizeObserver" in window)) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
var resizeObserver = new ResizeObserver(function (_ref) {
|
|
31
|
+
var _ref2 = _slicedToArray(_ref, 1),
|
|
32
|
+
entry = _ref2[0];
|
|
33
|
+
var _entry$contentRect = entry.contentRect,
|
|
34
|
+
x = _entry$contentRect.x,
|
|
35
|
+
y = _entry$contentRect.y,
|
|
36
|
+
width = _entry$contentRect.width,
|
|
37
|
+
height = _entry$contentRect.height,
|
|
38
|
+
top = _entry$contentRect.top,
|
|
39
|
+
right = _entry$contentRect.right,
|
|
40
|
+
bottom = _entry$contentRect.bottom,
|
|
41
|
+
left = _entry$contentRect.left;
|
|
42
|
+
setContentRect({
|
|
43
|
+
x: x,
|
|
44
|
+
y: y,
|
|
45
|
+
width: width,
|
|
46
|
+
height: height,
|
|
47
|
+
top: top,
|
|
48
|
+
right: right,
|
|
49
|
+
bottom: bottom,
|
|
50
|
+
left: left
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
resizeObserver.observe(ref.current);
|
|
54
|
+
return function () {
|
|
55
|
+
resizeObserver.disconnect();
|
|
56
|
+
};
|
|
57
|
+
}, [ref]);
|
|
58
|
+
return bounds;
|
|
59
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
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."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
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; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { useCallback, useEffect, useReducer, useRef } from "react";
|
|
8
|
+
var valueReducer = function valueReducer(state, action) {
|
|
9
|
+
var newState = new Set(state);
|
|
10
|
+
switch (action.type) {
|
|
11
|
+
case "reset":
|
|
12
|
+
{
|
|
13
|
+
return new Set();
|
|
14
|
+
}
|
|
15
|
+
case "toggle_item":
|
|
16
|
+
default:
|
|
17
|
+
{
|
|
18
|
+
if (action.value) {
|
|
19
|
+
if (newState.has(action.value)) {
|
|
20
|
+
newState.delete(action.value);
|
|
21
|
+
} else {
|
|
22
|
+
newState.add(action.value);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return newState;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
export var useMultiselect = function useMultiselect() {
|
|
30
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
31
|
+
initialValue: [],
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
33
|
+
onChange: function onChange() {}
|
|
34
|
+
},
|
|
35
|
+
_ref$initialValue = _ref.initialValue,
|
|
36
|
+
initialValue = _ref$initialValue === void 0 ? [] : _ref$initialValue,
|
|
37
|
+
_ref$onChange = _ref.onChange,
|
|
38
|
+
userOnChange = _ref$onChange === void 0 ? function () {} : _ref$onChange;
|
|
39
|
+
var _useReducer = useReducer(valueReducer, new Set(initialValue)),
|
|
40
|
+
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
41
|
+
value = _useReducer2[0],
|
|
42
|
+
dispatch = _useReducer2[1];
|
|
43
|
+
var getArrayValue = function getArrayValue(value) {
|
|
44
|
+
return Array.from(value);
|
|
45
|
+
};
|
|
46
|
+
var onChange = useCallback(function (newValue) {
|
|
47
|
+
dispatch({
|
|
48
|
+
type: "toggle_item",
|
|
49
|
+
value: newValue
|
|
50
|
+
});
|
|
51
|
+
}, [dispatch]);
|
|
52
|
+
var isFirstRun = useRef(true);
|
|
53
|
+
useEffect(function () {
|
|
54
|
+
if (isFirstRun.current) {
|
|
55
|
+
isFirstRun.current = false;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
userOnChange(getArrayValue(value));
|
|
59
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
60
|
+
}, [userOnChange, value]);
|
|
61
|
+
var onClear = useCallback(function () {
|
|
62
|
+
dispatch({
|
|
63
|
+
type: "reset"
|
|
64
|
+
});
|
|
65
|
+
}, [dispatch]);
|
|
66
|
+
return {
|
|
67
|
+
value: getArrayValue(value),
|
|
68
|
+
onChange: onChange,
|
|
69
|
+
onClear: onClear
|
|
70
|
+
};
|
|
71
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
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."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
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; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { canUseDOM } from "@sproutsocial/seeds-react-utilities";
|
|
8
|
+
import { useEffect, useMemo, useState } from "react";
|
|
9
|
+
var defaultCallback = function defaultCallback(mutationList) {
|
|
10
|
+
return mutationList;
|
|
11
|
+
};
|
|
12
|
+
export function useMutationObserver(targetNode, config) {
|
|
13
|
+
var callback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultCallback;
|
|
14
|
+
if (!canUseDOM()) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
/* eslint-disable-next-line */
|
|
18
|
+
var _useState = useState(undefined),
|
|
19
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
20
|
+
value = _useState2[0],
|
|
21
|
+
setValue = _useState2[1];
|
|
22
|
+
/* eslint-disable-next-line */
|
|
23
|
+
var observer = useMemo(function () {
|
|
24
|
+
return new MutationObserver(function (mutationList, observer) {
|
|
25
|
+
var result = callback(mutationList, observer);
|
|
26
|
+
setValue(result);
|
|
27
|
+
});
|
|
28
|
+
}, [callback]);
|
|
29
|
+
/* eslint-disable-next-line */
|
|
30
|
+
useEffect(function () {
|
|
31
|
+
if (targetNode) {
|
|
32
|
+
observer.observe(targetNode, config);
|
|
33
|
+
return function () {
|
|
34
|
+
observer.disconnect();
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}, [targetNode, config, observer]);
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
export function useMutationObserverOnce(targetNode, config, callback) {
|
|
41
|
+
var _useState3 = useState(true),
|
|
42
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
43
|
+
isObserving = _useState4[0],
|
|
44
|
+
setObserving = _useState4[1];
|
|
45
|
+
var node = isObserving ? targetNode : null;
|
|
46
|
+
var value = useMutationObserver(node, config, callback);
|
|
47
|
+
if (value !== undefined && isObserving) {
|
|
48
|
+
setObserving(false);
|
|
49
|
+
}
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
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."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
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; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { useState, useCallback } from "react";
|
|
8
|
+
export var useSelect = function useSelect() {
|
|
9
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
10
|
+
initialValue: "",
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
12
|
+
onChange: function onChange() {}
|
|
13
|
+
},
|
|
14
|
+
_ref$initialValue = _ref.initialValue,
|
|
15
|
+
initialValue = _ref$initialValue === void 0 ? "" : _ref$initialValue,
|
|
16
|
+
_ref$onChange = _ref.onChange,
|
|
17
|
+
userOnChange = _ref$onChange === void 0 ? function () {} : _ref$onChange;
|
|
18
|
+
var _useState = useState(initialValue),
|
|
19
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
20
|
+
value = _useState2[0],
|
|
21
|
+
setValue = _useState2[1];
|
|
22
|
+
var onChange = useCallback(function (newValue) {
|
|
23
|
+
if (newValue !== value) {
|
|
24
|
+
setValue(newValue);
|
|
25
|
+
userOnChange(newValue);
|
|
26
|
+
}
|
|
27
|
+
}, [userOnChange, value]);
|
|
28
|
+
return {
|
|
29
|
+
value: value,
|
|
30
|
+
onChange: onChange
|
|
31
|
+
};
|
|
32
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
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."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
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; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { useState, useCallback } from "react";
|
|
8
|
+
var useTextContentClone = function useTextContentClone(initial) {
|
|
9
|
+
var _useState = useState(initial),
|
|
10
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
11
|
+
textContent = _useState2[0],
|
|
12
|
+
setTextContent = _useState2[1];
|
|
13
|
+
var ref = useCallback(function (node) {
|
|
14
|
+
if (node !== null) {
|
|
15
|
+
setTextContent(node.textContent);
|
|
16
|
+
}
|
|
17
|
+
}, []);
|
|
18
|
+
ref.current = textContent;
|
|
19
|
+
return ref;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Couldn't find a way to achieve this with flow type syntax - open to suggestions
|
|
23
|
+
// Tried https://github.com/facebook/flow/issues/2840#issuecomment-452934068 but it didn't work
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
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."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
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; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { useCallback, useState } from "react";
|
|
8
|
+
export function useTextContent(initial) {
|
|
9
|
+
var _useState = useState(initial),
|
|
10
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
11
|
+
textContent = _useState2[0],
|
|
12
|
+
setTextContent = _useState2[1];
|
|
13
|
+
var ref = useCallback(function (node) {
|
|
14
|
+
if (node && node.textContent !== null) {
|
|
15
|
+
setTextContent(node.textContent);
|
|
16
|
+
}
|
|
17
|
+
}, []);
|
|
18
|
+
ref.current = textContent;
|
|
19
|
+
return ref;
|
|
20
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
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); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
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; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
import { useRef, useEffect } from "react";
|
|
8
|
+
export function useWhyDidYouUpdate(name, props) {
|
|
9
|
+
// Get a mutable ref object where we can store props ...
|
|
10
|
+
// ... for comparison next time this hook runs.
|
|
11
|
+
var previousProps = useRef({});
|
|
12
|
+
useEffect(function () {
|
|
13
|
+
if (previousProps.current) {
|
|
14
|
+
// Get all keys from previous and current props
|
|
15
|
+
var allKeys = Object.keys(_objectSpread(_objectSpread({}, previousProps.current), props));
|
|
16
|
+
// Use this object to keep track of changed props
|
|
17
|
+
var changesObj = {};
|
|
18
|
+
// Iterate through keys
|
|
19
|
+
allKeys.forEach(function (key) {
|
|
20
|
+
// If previous is different from current
|
|
21
|
+
if (previousProps.current[key] !== props[key]) {
|
|
22
|
+
// Add to changesObj
|
|
23
|
+
changesObj[key] = {
|
|
24
|
+
from: previousProps.current[key],
|
|
25
|
+
to: props[key]
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// If changesObj not empty then output to console
|
|
31
|
+
if (Object.keys(changesObj).length) {
|
|
32
|
+
// eslint-disable-next-line no-console
|
|
33
|
+
console.log("[why-did-you-update]", name, changesObj);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Finally update previousProps with current props for next hook call
|
|
38
|
+
previousProps.current = props;
|
|
39
|
+
});
|
|
40
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sproutsocial/seeds-react-hooks",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Seeds React Hooks",
|
|
5
|
+
"main": "commonjs/index.js",
|
|
6
|
+
"module": "lib/index.mjs",
|
|
7
|
+
"types": "dist/types/index.d.ts",
|
|
8
|
+
"author": "Sprout Social, Inc.",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"files": [
|
|
11
|
+
"__flow__",
|
|
12
|
+
"commonjs",
|
|
13
|
+
"dist",
|
|
14
|
+
"lib"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "yarn build:ts-declarations && tsx scripts/build.ts",
|
|
18
|
+
"build:ts-declarations": "tsc --project tsconfig.build.json && tsc-alias -p tsconfig.build.json"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@sproutsocial/seeds-react-utilities": "*",
|
|
22
|
+
"polished": "^3.4.1"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/styled-components": "^5.1.26",
|
|
26
|
+
"@sproutsocial/eslint-config-seeds": "*",
|
|
27
|
+
"@sproutsocial/seeds-build-flow": "*",
|
|
28
|
+
"@sproutsocial/seeds-react-theme": "*",
|
|
29
|
+
"flow-bin": "0.131.0",
|
|
30
|
+
"react": "^17.0.2",
|
|
31
|
+
"styled-components": "^5.2.3",
|
|
32
|
+
"typescript": "^5.1.6",
|
|
33
|
+
"tsx": "3.13.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"styled-components": "^5.2.3"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=18"
|
|
40
|
+
}
|
|
41
|
+
}
|