@sproutsocial/seeds-react-hooks 1.0.0 → 2.0.1

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 (61) hide show
  1. package/dist/index.d.mts +66 -0
  2. package/dist/index.d.ts +66 -0
  3. package/dist/index.js +17 -0
  4. package/dist/index.mjs +8 -0
  5. package/package.json +10 -15
  6. package/__flow__/index.flow.js +0 -8
  7. package/__flow__/index.js +0 -3
  8. package/__flow__/useInteractiveColor/useInteractiveColor.flow.js +0 -3
  9. package/__flow__/useMultiselect/useMultiselect.flow.js +0 -17
  10. package/__flow__/useMutationObserver/useMutationObserver.flow.js +0 -19
  11. package/__flow__/useSelect/useSelect.flow.js +0 -10
  12. package/__flow__/useTextContent/useTextContent.flow.js +0 -21
  13. package/__flow__/useWhyDidYouUpdate/useWhyDidYouUpdate.flow.js +0 -3
  14. package/commonjs/index.flow.js +0 -71
  15. package/commonjs/index.js +0 -82
  16. package/commonjs/index.js.flow +0 -3
  17. package/commonjs/useInteractiveColor/useInteractiveColor.flow.js +0 -1
  18. package/commonjs/useInteractiveColor/useInteractiveColor.js +0 -32
  19. package/commonjs/useMeasure/useMeasure.js +0 -65
  20. package/commonjs/useMultiselect/useMultiselect.flow.js +0 -1
  21. package/commonjs/useMultiselect/useMultiselect.js +0 -77
  22. package/commonjs/useMutationObserver/useMutationObserver.flow.js +0 -1
  23. package/commonjs/useMutationObserver/useMutationObserver.js +0 -58
  24. package/commonjs/useSelect/useSelect.flow.js +0 -1
  25. package/commonjs/useSelect/useSelect.js +0 -38
  26. package/commonjs/useTextContent/useTextContent.flow.js +0 -25
  27. package/commonjs/useTextContent/useTextContent.js +0 -26
  28. package/commonjs/useWhyDidYouUpdate/useWhyDidYouUpdate.flow.js +0 -1
  29. package/commonjs/useWhyDidYouUpdate/useWhyDidYouUpdate.js +0 -46
  30. package/dist/types/index.d.ts +0 -8
  31. package/dist/types/index.d.ts.map +0 -1
  32. package/dist/types/useInteractiveColor/useInteractiveColor.d.ts +0 -9
  33. package/dist/types/useInteractiveColor/useInteractiveColor.d.ts.map +0 -1
  34. package/dist/types/useMeasure/useMeasure.d.ts +0 -14
  35. package/dist/types/useMeasure/useMeasure.d.ts.map +0 -1
  36. package/dist/types/useMultiselect/useMultiselect.d.ts +0 -11
  37. package/dist/types/useMultiselect/useMultiselect.d.ts.map +0 -1
  38. package/dist/types/useMutationObserver/useMutationObserver.d.ts +0 -18
  39. package/dist/types/useMutationObserver/useMutationObserver.d.ts.map +0 -1
  40. package/dist/types/useSelect/useSelect.d.ts +0 -10
  41. package/dist/types/useSelect/useSelect.d.ts.map +0 -1
  42. package/dist/types/useTextContent/useTextContent.d.ts +0 -5
  43. package/dist/types/useTextContent/useTextContent.d.ts.map +0 -1
  44. package/dist/types/useWhyDidYouUpdate/useWhyDidYouUpdate.d.ts +0 -2
  45. package/dist/types/useWhyDidYouUpdate/useWhyDidYouUpdate.d.ts.map +0 -1
  46. package/lib/index.flow.js +0 -6
  47. package/lib/index.js +0 -7
  48. package/lib/index.js.flow +0 -3
  49. package/lib/useInteractiveColor/useInteractiveColor.flow.js +0 -0
  50. package/lib/useInteractiveColor/useInteractiveColor.js +0 -27
  51. package/lib/useMeasure/useMeasure.js +0 -59
  52. package/lib/useMultiselect/useMultiselect.flow.js +0 -0
  53. package/lib/useMultiselect/useMultiselect.js +0 -71
  54. package/lib/useMutationObserver/useMutationObserver.flow.js +0 -0
  55. package/lib/useMutationObserver/useMutationObserver.js +0 -51
  56. package/lib/useSelect/useSelect.flow.js +0 -0
  57. package/lib/useSelect/useSelect.js +0 -32
  58. package/lib/useTextContent/useTextContent.flow.js +0 -23
  59. package/lib/useTextContent/useTextContent.js +0 -20
  60. package/lib/useWhyDidYouUpdate/useWhyDidYouUpdate.flow.js +0 -0
  61. package/lib/useWhyDidYouUpdate/useWhyDidYouUpdate.js +0 -40
@@ -1,58 +0,0 @@
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
- }
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,38 +0,0 @@
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
- };
@@ -1,25 +0,0 @@
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
@@ -1,26 +0,0 @@
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
- }
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,46 +0,0 @@
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
- }
@@ -1,8 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,9 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,14 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,11 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,18 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,10 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,5 +0,0 @@
1
- export type textContentRef = ((node: Node) => void) & {
2
- current?: string;
3
- };
4
- export declare function useTextContent(initial: string): textContentRef;
5
- //# sourceMappingURL=useTextContent.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,2 +0,0 @@
1
- export declare function useWhyDidYouUpdate(name: string, props: object): void;
2
- //# sourceMappingURL=useWhyDidYouUpdate.d.ts.map
@@ -1 +0,0 @@
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"}
package/lib/index.flow.js DELETED
@@ -1,6 +0,0 @@
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 DELETED
@@ -1,7 +0,0 @@
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";
package/lib/index.js.flow DELETED
@@ -1,3 +0,0 @@
1
- // @flow
2
- export * from '../__flow__';
3
-
@@ -1,27 +0,0 @@
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 };
@@ -1,59 +0,0 @@
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
@@ -1,71 +0,0 @@
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
- };
@@ -1,51 +0,0 @@
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
@@ -1,32 +0,0 @@
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
- };