@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,23 +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
- 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
@@ -1,20 +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, 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
@@ -1,40 +0,0 @@
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
- }