@artsy/palette 29.7.2 → 29.7.3
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/dist/utils/useFocusLock.js +16 -32
- package/dist/utils/useFocusLock.js.map +1 -1
- package/dist/utils/useFocusLock.story.d.ts +0 -1
- package/dist/utils/useFocusLock.story.js +1 -42
- package/dist/utils/useFocusLock.story.js.map +1 -1
- package/dist/utils/useMutationObserver.js +15 -14
- package/dist/utils/useMutationObserver.js.map +1 -1
- package/package.json +2 -3
|
@@ -11,8 +11,6 @@ var _useCursor2 = require("use-cursor");
|
|
|
11
11
|
|
|
12
12
|
var _useMutationObserver = require("./useMutationObserver");
|
|
13
13
|
|
|
14
|
-
var _tabbable = require("tabbable");
|
|
15
|
-
|
|
16
14
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
17
15
|
|
|
18
16
|
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."); }
|
|
@@ -25,15 +23,11 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
25
23
|
|
|
26
24
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
27
25
|
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
subtree: true,
|
|
31
|
-
attributeFilter: ["disabled"]
|
|
32
|
-
};
|
|
26
|
+
var FOCUSABLE_SELECTOR = ["a[href]:not([tabindex='-1'])", "area[href]:not([tabindex='-1'])", "input:not([disabled]):not([tabindex='-1'])", "select:not([disabled]):not([tabindex='-1'])", "textarea:not([disabled]):not([tabindex='-1'])", "button:not([disabled]):not([tabindex='-1'])", '[tabindex="0"]'].join(", ");
|
|
27
|
+
|
|
33
28
|
/**
|
|
34
29
|
* Locks focus within the given element
|
|
35
30
|
*/
|
|
36
|
-
|
|
37
31
|
var useFocusLock = function useFocusLock(_ref) {
|
|
38
32
|
var ref = _ref.ref,
|
|
39
33
|
_ref$active = _ref.active,
|
|
@@ -46,37 +40,27 @@ var useFocusLock = function useFocusLock(_ref) {
|
|
|
46
40
|
|
|
47
41
|
var updateFocusableEls = (0, _react.useCallback)(function () {
|
|
48
42
|
if (ref.current === null) return;
|
|
49
|
-
setFocusableEls(
|
|
43
|
+
setFocusableEls(Array.from(ref.current.querySelectorAll(FOCUSABLE_SELECTOR))); // When `active` changes that typically means our target ref
|
|
50
44
|
// is being inserted into the DOM, so we need to update the focusable elements.
|
|
51
45
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
52
46
|
}, [active]); // Set initial focusable elements on mount
|
|
53
47
|
|
|
54
|
-
(0, _react.useEffect)(
|
|
55
|
-
|
|
56
|
-
var timeout = setTimeout(function () {
|
|
57
|
-
updateFocusableEls();
|
|
58
|
-
}, 0);
|
|
59
|
-
return function () {
|
|
60
|
-
clearTimeout(timeout);
|
|
61
|
-
};
|
|
62
|
-
}, [updateFocusableEls]);
|
|
63
|
-
var skipUpdateFocusRef = (0, _react.useRef)(false);
|
|
64
|
-
var handleMutate = (0, _react.useCallback)(function (mutations) {
|
|
65
|
-
// Check to see if any of the mutations has either added or removed nodes
|
|
66
|
-
var hasMeaningfullyMutated = mutations.some(function (mutation) {
|
|
67
|
-
return mutation.addedNodes.length > 0 || mutation.removedNodes.length > 0 || mutation.attributeName === "disabled";
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
if (hasMeaningfullyMutated) {
|
|
71
|
-
skipUpdateFocusRef.current = true;
|
|
72
|
-
updateFocusableEls();
|
|
73
|
-
}
|
|
74
|
-
}, [updateFocusableEls]); // Detects when DOM changes and updates focusable elements
|
|
48
|
+
(0, _react.useEffect)(updateFocusableEls, [updateFocusableEls]);
|
|
49
|
+
var skipUpdateFocusRef = (0, _react.useRef)(false); // Detects when DOM changes and updates focusable elements
|
|
75
50
|
|
|
76
51
|
(0, _useMutationObserver.useMutationObserver)({
|
|
77
52
|
ref: ref,
|
|
78
|
-
onMutate:
|
|
79
|
-
|
|
53
|
+
onMutate: function onMutate(mutations) {
|
|
54
|
+
// Check to see if any of the mutations has either added or removed nodes
|
|
55
|
+
var hasMeaningfullyMutated = mutations.some(function (mutation) {
|
|
56
|
+
return mutation.addedNodes.length > 0 || mutation.removedNodes.length > 0;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
if (hasMeaningfullyMutated) {
|
|
60
|
+
skipUpdateFocusRef.current = true;
|
|
61
|
+
updateFocusableEls();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
80
64
|
});
|
|
81
65
|
|
|
82
66
|
var _useCursor = (0, _useCursor2.useCursor)({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/useFocusLock.ts"],"names":["
|
|
1
|
+
{"version":3,"sources":["../../src/utils/useFocusLock.ts"],"names":["FOCUSABLE_SELECTOR","join","useFocusLock","ref","active","focusableEls","setFocusableEls","updateFocusableEls","current","Array","from","querySelectorAll","skipUpdateFocusRef","onMutate","mutations","hasMeaningfullyMutated","some","mutation","addedNodes","length","removedNodes","max","focusableIndex","index","handlePrev","handleNext","setCursor","focus","handleKeydown","event","key","preventDefault","stopPropagation","shiftKey","focusedElPriorToOpen","document","activeElement","addEventListener","removeEventListener","handleClick","target","findIndex","node","handleFocusIn","focusableEl","stopImmediatePropagation"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;;;;;;;;;;;AAEA,IAAMA,kBAAkB,GAAG,CACzB,8BADyB,EAEzB,iCAFyB,EAGzB,4CAHyB,EAIzB,6CAJyB,EAKzB,+CALyB,EAMzB,6CANyB,EAOzB,gBAPyB,EAQzBC,IARyB,CAQpB,IARoB,CAA3B;;AAeA;AACA;AACA;AACO,IAAMC,YAAY,GAAG,SAAfA,YAAe,OAA0C;AAAA,MAAvCC,GAAuC,QAAvCA,GAAuC;AAAA,yBAAlCC,MAAkC;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AAEA,UAAIjB,KAAK,KAAK,CAAC,CAAf,EAAkB;AAElBG,MAAAA,SAAS,CAACH,KAAD,CAAT;AACD,KARD,CAFc,CAYd;;;AACA,QAAMoB,aAAa,GAAG,SAAhBA,aAAgB,CAACd,KAAD,EAAuB;AAC3C,UAAMN,KAAK,GAAGlB,YAAY,CAACoC,SAAb,CAAuB,UAACC,IAAD;AAAA,eAAUA,IAAI,KAAKb,KAAK,CAACW,MAAzB;AAAA,OAAvB,CAAd;AACA,UAAMI,WAAW,GAAGvC,YAAY,CAACiB,cAAD,CAAhC;;AAEA,UAAIC,KAAK,KAAK,CAAC,CAAX,IAAgB,CAAC,CAACqB,WAAtB,EAAmC;AACjCf,QAAAA,KAAK,CAACgB,wBAAN;AACAD,QAAAA,WAAW,CAACjB,KAAZ;AACA;AACD;AACF,KATD;;AAWAQ,IAAAA,QAAQ,CAACE,gBAAT,CAA0B,OAA1B,EAAmCE,WAAnC;AACAJ,IAAAA,QAAQ,CAACE,gBAAT,CAA0B,SAA1B,EAAqCM,aAArC;AACA,WAAO,YAAM;AACXR,MAAAA,QAAQ,CAACG,mBAAT,CAA6B,OAA7B,EAAsCC,WAAtC;AACAJ,MAAAA,QAAQ,CAACG,mBAAT,CAA6B,SAA7B,EAAwCK,aAAxC;AACD,KAHD;AAID,GA9BD,EA8BG,CAACtC,YAAD,EAAeiB,cAAf,EAA+BI,SAA/B,CA9BH;AA+BD,CAzHM","sourcesContent":["import React, { useCallback, useEffect, useRef, useState } from \"react\"\nimport { useCursor } from \"use-cursor\"\nimport { useMutationObserver } from \"./useMutationObserver\"\n\nconst FOCUSABLE_SELECTOR = [\n \"a[href]:not([tabindex='-1'])\",\n \"area[href]:not([tabindex='-1'])\",\n \"input:not([disabled]):not([tabindex='-1'])\",\n \"select:not([disabled]):not([tabindex='-1'])\",\n \"textarea:not([disabled]):not([tabindex='-1'])\",\n \"button:not([disabled]):not([tabindex='-1'])\",\n '[tabindex=\"0\"]',\n].join(\", \")\n\ninterface UseFocusLock {\n ref: React.MutableRefObject<HTMLElement | null>\n active?: boolean\n}\n\n/**\n * Locks focus within the given element\n */\nexport const useFocusLock = ({ ref, active = true }: UseFocusLock) => {\n const [focusableEls, setFocusableEls] = useState<HTMLElement[]>([])\n\n const updateFocusableEls = useCallback(() => {\n if (ref.current === null) return\n\n setFocusableEls(\n Array.from(ref.current.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR))\n )\n\n // When `active` changes that typically means our target ref\n // is being inserted into the DOM, so we need to update the focusable elements.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [active])\n\n // Set initial focusable elements on mount\n useEffect(updateFocusableEls, [updateFocusableEls])\n\n const skipUpdateFocusRef = useRef(false)\n\n // Detects when DOM changes and updates focusable elements\n useMutationObserver({\n ref,\n onMutate: (mutations) => {\n // Check to see if any of the mutations has either added or removed nodes\n const hasMeaningfullyMutated = mutations.some((mutation) => {\n return (\n mutation.addedNodes.length > 0 || mutation.removedNodes.length > 0\n )\n })\n\n if (hasMeaningfullyMutated) {\n skipUpdateFocusRef.current = true\n updateFocusableEls()\n }\n },\n })\n\n const {\n index: focusableIndex,\n handlePrev,\n handleNext,\n setCursor,\n } = useCursor({ max: focusableEls.length })\n\n // Moves focus when index changes\n useEffect(() => {\n if (!focusableEls.length) return\n\n // In order to avoid a loop when a focus might be the cause of a mutation,\n // we skip focusing the el.\n if (skipUpdateFocusRef.current) {\n skipUpdateFocusRef.current = false\n return\n }\n\n focusableEls[focusableIndex].focus()\n }, [focusableEls, focusableIndex])\n\n // Handle keyboard navigation\n useEffect(() => {\n const handleKeydown = (event: KeyboardEvent) => {\n if (!active) return\n\n switch (event.key) {\n case \"Tab\":\n // Lock focus within element\n event.preventDefault()\n event.stopPropagation()\n\n // Move focus up or down\n event.shiftKey ? handlePrev() : handleNext()\n break\n default:\n break\n }\n }\n\n const focusedElPriorToOpen = document.activeElement as HTMLElement\n\n document.addEventListener(\"keydown\", handleKeydown)\n\n return () => {\n // Return the focus\n focusedElPriorToOpen.focus()\n\n document.removeEventListener(\"keydown\", handleKeydown)\n }\n }, [active, handleNext, handlePrev])\n\n useEffect(() => {\n // Update the index when any focusable is clicked\n const handleClick = (event: MouseEvent) => {\n if (event.target !== document.activeElement) return\n\n const index = focusableEls.findIndex((node) => node === event.target)\n\n if (index === -1) return\n\n setCursor(index)\n }\n\n // If focus escapes the trap, pull it back in\n const handleFocusIn = (event: FocusEvent) => {\n const index = focusableEls.findIndex((node) => node === event.target)\n const focusableEl = focusableEls[focusableIndex]\n\n if (index === -1 && !!focusableEl) {\n event.stopImmediatePropagation()\n focusableEl.focus()\n return\n }\n }\n\n document.addEventListener(\"click\", handleClick)\n document.addEventListener(\"focusin\", handleFocusIn)\n return () => {\n document.removeEventListener(\"click\", handleClick)\n document.removeEventListener(\"focusin\", handleFocusIn)\n }\n }, [focusableEls, focusableIndex, setCursor])\n}\n"],"file":"useFocusLock.js"}
|
|
@@ -5,7 +5,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.default = exports.WithAutocompleteInput = exports.
|
|
8
|
+
exports.default = exports.WithAutocompleteInput = exports.Default = void 0;
|
|
9
9
|
|
|
10
10
|
var _react = _interopRequireWildcard(require("react"));
|
|
11
11
|
|
|
@@ -21,18 +21,6 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
21
21
|
|
|
22
22
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
23
23
|
|
|
24
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
25
|
-
|
|
26
|
-
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."); }
|
|
27
|
-
|
|
28
|
-
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); }
|
|
29
|
-
|
|
30
|
-
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; }
|
|
31
|
-
|
|
32
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
33
|
-
|
|
34
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
35
|
-
|
|
36
24
|
var _default = {
|
|
37
25
|
title: "Hooks/useFocusLock"
|
|
38
26
|
};
|
|
@@ -60,9 +48,6 @@ var Default = function Default() {
|
|
|
60
48
|
variant: "primaryGray",
|
|
61
49
|
tabIndex: -1
|
|
62
50
|
}, "Skipped"), /*#__PURE__*/_react.default.createElement(_Button.Button, {
|
|
63
|
-
variant: "primaryGray",
|
|
64
|
-
disabled: true
|
|
65
|
-
}, "Disabled"), /*#__PURE__*/_react.default.createElement(_Button.Button, {
|
|
66
51
|
variant: "primaryGray"
|
|
67
52
|
}, "Focusable")), /*#__PURE__*/_react.default.createElement(_Input.Input, {
|
|
68
53
|
placeholder: "Not focusable"
|
|
@@ -99,30 +84,4 @@ var WithAutocompleteInput = function WithAutocompleteInput() {
|
|
|
99
84
|
|
|
100
85
|
exports.WithAutocompleteInput = WithAutocompleteInput;
|
|
101
86
|
WithAutocompleteInput.displayName = "WithAutocompleteInput";
|
|
102
|
-
|
|
103
|
-
var DisableToEnable = function DisableToEnable() {
|
|
104
|
-
var _useState = (0, _react.useState)(""),
|
|
105
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
106
|
-
value = _useState2[0],
|
|
107
|
-
setValue = _useState2[1];
|
|
108
|
-
|
|
109
|
-
var ref = (0, _react.useRef)(null);
|
|
110
|
-
(0, _useFocusLock.useFocusLock)({
|
|
111
|
-
ref: ref
|
|
112
|
-
});
|
|
113
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
114
|
-
ref: ref
|
|
115
|
-
}, /*#__PURE__*/_react.default.createElement(_Input.Input, {
|
|
116
|
-
placeholder: "Value",
|
|
117
|
-
value: value,
|
|
118
|
-
onChange: function onChange(e) {
|
|
119
|
-
return setValue(e.target.value);
|
|
120
|
-
}
|
|
121
|
-
}), /*#__PURE__*/_react.default.createElement(_Button.Button, {
|
|
122
|
-
disabled: !value
|
|
123
|
-
}, "Submit"));
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
exports.DisableToEnable = DisableToEnable;
|
|
127
|
-
DisableToEnable.displayName = "DisableToEnable";
|
|
128
87
|
//# sourceMappingURL=useFocusLock.story.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/useFocusLock.story.tsx"],"names":["title","Default","ref","WithAutocompleteInput","text","value"
|
|
1
|
+
{"version":3,"sources":["../../src/utils/useFocusLock.story.tsx"],"names":["title","Default","ref","WithAutocompleteInput","text","value"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;;;;;eAEe;AACbA,EAAAA,KAAK,EAAE;AADM,C;;;AAIR,IAAMC,OAAO,GAAG,SAAVA,OAAU,GAAM;AAC3B,MAAMC,GAAG,GAAG,mBAA8B,IAA9B,CAAZ;AAEA,kCAAa;AAAEA,IAAAA,GAAG,EAAHA;AAAF,GAAb;AAEA,sBACE,yEACE,6BAAC,YAAD;AAAO,IAAA,WAAW,EAAC;AAAnB,IADF,eAEE;AAAK,IAAA,GAAG,EAAEA;AAAV,kBACE,6BAAC,YAAD;AAAO,IAAA,WAAW,EAAC;AAAnB,IADF,eAEE,6BAAC,YAAD;AAAO,IAAA,WAAW,EAAC;AAAnB,IAFF,eAGE;AAAG,IAAA,IAAI,EAAC,GAAR;AAAY,IAAA,QAAQ,EAAE,CAAC;AAAvB,eAHF,eAME;AAAG,IAAA,IAAI,EAAC;AAAR,iBANF,eAOE,6BAAC,cAAD;AAAQ,IAAA,OAAO,EAAC,aAAhB;AAA8B,IAAA,QAAQ,EAAE,CAAC;AAAzC,eAPF,eAUE,6BAAC,cAAD;AAAQ,IAAA,OAAO,EAAC;AAAhB,iBAVF,CAFF,eAcE,6BAAC,YAAD;AAAO,IAAA,WAAW,EAAC;AAAnB,IAdF,CADF;AAkBD,CAvBM;;;;AAyBA,IAAMC,qBAAqB,GAAG,SAAxBA,qBAAwB,GAAM;AACzC,MAAMD,GAAG,GAAG,mBAA8B,IAA9B,CAAZ;AAEA,kCAAa;AAAEA,IAAAA,GAAG,EAAHA;AAAF,GAAb;AAEA,sBACE;AAAK,IAAA,GAAG,EAAEA;AAAV,kBACE,6BAAC,YAAD;AAAO,IAAA,WAAW,EAAC;AAAnB,IADF,eAEE,6BAAC,YAAD;AAAO,IAAA,WAAW,EAAC;AAAnB,IAFF,eAGE,6BAAC,oCAAD;AACE,IAAA,WAAW,EAAC,WADd;AAEE,IAAA,OAAO,EAAE,CACP;AAAEE,MAAAA,IAAI,EAAE,KAAR;AAAeC,MAAAA,KAAK,EAAE;AAAtB,KADO,EAEP;AAAED,MAAAA,IAAI,EAAE,KAAR;AAAeC,MAAAA,KAAK,EAAE;AAAtB,KAFO,EAGP;AAAED,MAAAA,IAAI,EAAE,OAAR;AAAiBC,MAAAA,KAAK,EAAE;AAAxB,KAHO;AAFX,IAHF,CADF;AAcD,CAnBM;;;AAAMF,qB","sourcesContent":["import React, { useRef } from \"react\"\nimport { useFocusLock } from \"./useFocusLock\"\nimport { Input } from \"../elements/Input\"\nimport { Button } from \"../elements/Button\"\nimport { AutocompleteInput } from \"../elements/AutocompleteInput\"\n\nexport default {\n title: \"Hooks/useFocusLock\",\n}\n\nexport const Default = () => {\n const ref = useRef<HTMLDivElement | null>(null)\n\n useFocusLock({ ref })\n\n return (\n <>\n <Input placeholder=\"Not focusable\" />\n <div ref={ref}>\n <Input placeholder=\"Focusable\" />\n <Input placeholder=\"Focusable\" />\n <a href=\"#\" tabIndex={-1}>\n Skipped\n </a>\n <a href=\"#\">Focusable</a>\n <Button variant=\"primaryGray\" tabIndex={-1}>\n Skipped\n </Button>\n <Button variant=\"primaryGray\">Focusable</Button>\n </div>\n <Input placeholder=\"Not focusable\" />\n </>\n )\n}\n\nexport const WithAutocompleteInput = () => {\n const ref = useRef<HTMLDivElement | null>(null)\n\n useFocusLock({ ref })\n\n return (\n <div ref={ref}>\n <Input placeholder=\"Focusable\" />\n <Input placeholder=\"Focusable\" />\n <AutocompleteInput\n placeholder=\"Focusable\"\n options={[\n { text: \"One\", value: \"one\" },\n { text: \"Two\", value: \"two\" },\n { text: \"Three\", value: \"three\" },\n ]}\n />\n </div>\n )\n}\n"],"file":"useFocusLock.story.js"}
|
|
@@ -13,20 +13,18 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
|
|
|
13
13
|
|
|
14
14
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
15
15
|
|
|
16
|
-
var DEFAULT_OPTIONS = {
|
|
17
|
-
attributes: true,
|
|
18
|
-
characterData: true,
|
|
19
|
-
childList: true,
|
|
20
|
-
subtree: true
|
|
21
|
-
};
|
|
22
16
|
/**
|
|
23
17
|
* Accepts a ref and calls the `onMutate` callback when mutations are observed.
|
|
24
18
|
*/
|
|
25
|
-
|
|
26
19
|
var useMutationObserver = function useMutationObserver(_ref) {
|
|
27
20
|
var onMutate = _ref.onMutate,
|
|
28
21
|
_ref$options = _ref.options,
|
|
29
|
-
options = _ref$options === void 0 ?
|
|
22
|
+
options = _ref$options === void 0 ? {
|
|
23
|
+
attributes: true,
|
|
24
|
+
characterData: true,
|
|
25
|
+
childList: true,
|
|
26
|
+
subtree: true
|
|
27
|
+
} : _ref$options,
|
|
30
28
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
31
29
|
|
|
32
30
|
(0, _react.useEffect)(function () {
|
|
@@ -35,13 +33,16 @@ var useMutationObserver = function useMutationObserver(_ref) {
|
|
|
35
33
|
}
|
|
36
34
|
|
|
37
35
|
var el = "ref" in rest ? rest.ref.current : rest.element;
|
|
38
|
-
if (!el) return;
|
|
39
|
-
var observer = new MutationObserver(onMutate); // Start observing the target node for configured mutations
|
|
40
36
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
if (el) {
|
|
38
|
+
var observer = new MutationObserver(onMutate); // Start observing the target node for configured mutations
|
|
39
|
+
|
|
40
|
+
observer.observe(el, options);
|
|
41
|
+
return function () {
|
|
42
|
+
observer.disconnect();
|
|
43
|
+
};
|
|
44
|
+
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
45
|
+
|
|
45
46
|
}, [onMutate, options]);
|
|
46
47
|
};
|
|
47
48
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/useMutationObserver.ts"],"names":["
|
|
1
|
+
{"version":3,"sources":["../../src/utils/useMutationObserver.ts"],"names":["useMutationObserver","onMutate","options","attributes","characterData","childList","subtree","rest","MutationObserver","el","ref","current","element","observer","observe","disconnect"],"mappings":";;;;;;;AACA;;;;;;;;AAUA;AACA;AACA;AACO,IAAMA,mBAAmB,GAAG,SAAtBA,mBAAsB,OASR;AAAA,MARzBC,QAQyB,QARzBA,QAQyB;AAAA,0BAPzBC,OAOyB;AAAA,MAPzBA,OAOyB,6BAPf;AACRC,IAAAA,UAAU,EAAE,IADJ;AAERC,IAAAA,aAAa,EAAE,IAFP;AAGRC,IAAAA,SAAS,EAAE,IAHH;AAIRC,IAAAA,OAAO,EAAE;AAJD,GAOe;AAAA,MADtBC,IACsB;;AACzB,wBAAU,YAAM;AACd,QAAI,OAAOC,gBAAP,KAA4B,WAAhC,EAA6C;AAC3C;AACD;;AAED,QAAMC,EAAE,GAAG,SAASF,IAAT,GAAgBA,IAAI,CAACG,GAAL,CAASC,OAAzB,GAAmCJ,IAAI,CAACK,OAAnD;;AAEA,QAAIH,EAAJ,EAAQ;AACN,UAAMI,QAAQ,GAAG,IAAIL,gBAAJ,CAAqBP,QAArB,CAAjB,CADM,CAGN;;AACAY,MAAAA,QAAQ,CAACC,OAAT,CAAiBL,EAAjB,EAAqBP,OAArB;AAEA,aAAO,YAAM;AACXW,QAAAA,QAAQ,CAACE,UAAT;AACD,OAFD;AAGD,KAhBa,CAiBd;;AACD,GAlBD,EAkBG,CAACd,QAAD,EAAWC,OAAX,CAlBH;AAmBD,CA7BM","sourcesContent":["import type { MutableRefObject } from \"react\"\nimport { useEffect } from \"react\"\n\ntype UseMutationObserver = {\n onMutate: MutationCallback\n options?: MutationObserverInit\n} & (\n | { ref: MutableRefObject<HTMLElement | null> }\n | { element?: HTMLElement | null }\n)\n\n/**\n * Accepts a ref and calls the `onMutate` callback when mutations are observed.\n */\nexport const useMutationObserver = ({\n onMutate,\n options = {\n attributes: true,\n characterData: true,\n childList: true,\n subtree: true,\n },\n ...rest\n}: UseMutationObserver) => {\n useEffect(() => {\n if (typeof MutationObserver === \"undefined\") {\n return\n }\n\n const el = \"ref\" in rest ? rest.ref.current : rest.element\n\n if (el) {\n const observer = new MutationObserver(onMutate)\n\n // Start observing the target node for configured mutations\n observer.observe(el, options)\n\n return () => {\n observer.disconnect()\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [onMutate, options])\n}\n"],"file":"useMutationObserver.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@artsy/palette",
|
|
3
|
-
"version": "29.7.
|
|
3
|
+
"version": "29.7.3",
|
|
4
4
|
"description": "Design system library for react components",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -122,7 +122,6 @@
|
|
|
122
122
|
"react-lazy-load-image-component": "1.5.5",
|
|
123
123
|
"react-remove-scroll": "2.5.5",
|
|
124
124
|
"styled-system": "^5.1.5",
|
|
125
|
-
"tabbable": "^6.1.1",
|
|
126
125
|
"trunc-html": "^1.1.2",
|
|
127
126
|
"use-cursor": "^1.2.3",
|
|
128
127
|
"use-keyboard-list-navigation": "2.4.2"
|
|
@@ -175,5 +174,5 @@
|
|
|
175
174
|
"<rootDir>/www/"
|
|
176
175
|
]
|
|
177
176
|
},
|
|
178
|
-
"gitHead": "
|
|
177
|
+
"gitHead": "139d1470ce5bb982ea9dfb2c2e9bae7da43d6e8b"
|
|
179
178
|
}
|