@artsy/palette 29.7.1 → 29.7.2
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 +32 -16
- package/dist/utils/useFocusLock.js.map +1 -1
- package/dist/utils/useFocusLock.story.d.ts +1 -0
- package/dist/utils/useFocusLock.story.js +42 -1
- package/dist/utils/useFocusLock.story.js.map +1 -1
- package/dist/utils/useMutationObserver.js +14 -15
- package/dist/utils/useMutationObserver.js.map +1 -1
- package/package.json +3 -2
|
@@ -11,6 +11,8 @@ var _useCursor2 = require("use-cursor");
|
|
|
11
11
|
|
|
12
12
|
var _useMutationObserver = require("./useMutationObserver");
|
|
13
13
|
|
|
14
|
+
var _tabbable = require("tabbable");
|
|
15
|
+
|
|
14
16
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
15
17
|
|
|
16
18
|
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."); }
|
|
@@ -23,11 +25,15 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
23
25
|
|
|
24
26
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
25
27
|
|
|
26
|
-
var
|
|
27
|
-
|
|
28
|
+
var MUTATION_OBSERVER_OPTIONS = {
|
|
29
|
+
attributes: true,
|
|
30
|
+
subtree: true,
|
|
31
|
+
attributeFilter: ["disabled"]
|
|
32
|
+
};
|
|
28
33
|
/**
|
|
29
34
|
* Locks focus within the given element
|
|
30
35
|
*/
|
|
36
|
+
|
|
31
37
|
var useFocusLock = function useFocusLock(_ref) {
|
|
32
38
|
var ref = _ref.ref,
|
|
33
39
|
_ref$active = _ref.active,
|
|
@@ -40,27 +46,37 @@ var useFocusLock = function useFocusLock(_ref) {
|
|
|
40
46
|
|
|
41
47
|
var updateFocusableEls = (0, _react.useCallback)(function () {
|
|
42
48
|
if (ref.current === null) return;
|
|
43
|
-
setFocusableEls(
|
|
49
|
+
setFocusableEls((0, _tabbable.tabbable)(ref.current)); // When `active` changes that typically means our target ref
|
|
44
50
|
// is being inserted into the DOM, so we need to update the focusable elements.
|
|
45
51
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
46
52
|
}, [active]); // Set initial focusable elements on mount
|
|
47
53
|
|
|
48
|
-
(0, _react.useEffect)(
|
|
49
|
-
|
|
54
|
+
(0, _react.useEffect)(function () {
|
|
55
|
+
// Wait for the next tick to ensure focusable elements are in the DOM
|
|
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
|
|
50
75
|
|
|
51
76
|
(0, _useMutationObserver.useMutationObserver)({
|
|
52
77
|
ref: ref,
|
|
53
|
-
onMutate:
|
|
54
|
-
|
|
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
|
-
}
|
|
78
|
+
onMutate: handleMutate,
|
|
79
|
+
options: MUTATION_OBSERVER_OPTIONS
|
|
64
80
|
});
|
|
65
81
|
|
|
66
82
|
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":["MUTATION_OBSERVER_OPTIONS","attributes","subtree","attributeFilter","useFocusLock","ref","active","focusableEls","setFocusableEls","updateFocusableEls","current","timeout","setTimeout","clearTimeout","skipUpdateFocusRef","handleMutate","mutations","hasMeaningfullyMutated","some","mutation","addedNodes","length","removedNodes","attributeName","onMutate","options","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;;AACA;;;;;;;;;;;;;;AASA,IAAMA,yBAAyB,GAAG;AAChCC,EAAAA,UAAU,EAAE,IADoB;AAEhCC,EAAAA,OAAO,EAAE,IAFuB;AAGhCC,EAAAA,eAAe,EAAE,CAAC,UAAD;AAHe,CAAlC;AAMA;AACA;AACA;;AACO,IAAMC,YAAY,GAAG,SAAfA,YAAe,OAA0C;AAAA,MAAvCC,GAAuC,QAAvCA,GAAuC;AAAA,yBAAlCC,MAAkC;AAAA,MAAlCA,MAAkC,4BAAzB,IAAyB;;AACpE,kBAAwC,qBAA6B,EAA7B,CAAxC;AAAA;AAAA,MAAOC,YAAP;AAAA,MAAqBC,eAArB;;AAEA,MAAMC,kBAAkB,GAAG,wBAAY,YAAM;AAC3C,QAAIJ,GAAG,CAACK,OAAJ,KA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AACC,IAAD;AAAA,eAAUA,IAAI,KAAKb,KAAK,CAACW,MAAzB;AAAA,OAAvB,CAAd;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,GAAGrB,YAAY,CAACuC,SAAb,CAAuB,UAACC,IAAD;AAAA,eAAUA,IAAI,KAAKb,KAAK,CAACW,MAAzB;AAAA,OAAvB,CAAd;AACA,UAAMI,WAAW,GAAG1C,YAAY,CAACoB,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,CAACzC,YAAD,EAAeoB,cAAf,EAA+BI,SAA/B,CA9BH;AA+BD,CAxIM","sourcesContent":["import React, { useCallback, useEffect, useRef, useState } from \"react\"\nimport { useCursor } from \"use-cursor\"\nimport { useMutationObserver } from \"./useMutationObserver\"\nimport { tabbable } from \"tabbable\"\n\ninterface UseFocusLock {\n ref: React.MutableRefObject<HTMLElement | null>\n active?: boolean\n}\n\ntype FocusableElement = HTMLElement | SVGElement\n\nconst MUTATION_OBSERVER_OPTIONS = {\n attributes: true,\n subtree: true,\n attributeFilter: [\"disabled\"],\n}\n\n/**\n * Locks focus within the given element\n */\nexport const useFocusLock = ({ ref, active = true }: UseFocusLock) => {\n const [focusableEls, setFocusableEls] = useState<FocusableElement[]>([])\n\n const updateFocusableEls = useCallback(() => {\n if (ref.current === null) return\n\n setFocusableEls(tabbable(ref.current))\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(() => {\n // Wait for the next tick to ensure focusable elements are in the DOM\n const timeout = setTimeout(() => {\n updateFocusableEls()\n }, 0)\n\n return () => {\n clearTimeout(timeout)\n }\n }, [updateFocusableEls])\n\n const skipUpdateFocusRef = useRef(false)\n\n const handleMutate = useCallback(\n (mutations: MutationRecord[]) => {\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 ||\n mutation.removedNodes.length > 0 ||\n mutation.attributeName === \"disabled\"\n )\n })\n\n if (hasMeaningfullyMutated) {\n skipUpdateFocusRef.current = true\n updateFocusableEls()\n }\n },\n [updateFocusableEls]\n )\n\n // Detects when DOM changes and updates focusable elements\n useMutationObserver({\n ref,\n onMutate: handleMutate,\n options: MUTATION_OBSERVER_OPTIONS,\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.Default = void 0;
|
|
8
|
+
exports.default = exports.WithAutocompleteInput = exports.DisableToEnable = exports.Default = void 0;
|
|
9
9
|
|
|
10
10
|
var _react = _interopRequireWildcard(require("react"));
|
|
11
11
|
|
|
@@ -21,6 +21,18 @@ 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
|
+
|
|
24
36
|
var _default = {
|
|
25
37
|
title: "Hooks/useFocusLock"
|
|
26
38
|
};
|
|
@@ -48,6 +60,9 @@ var Default = function Default() {
|
|
|
48
60
|
variant: "primaryGray",
|
|
49
61
|
tabIndex: -1
|
|
50
62
|
}, "Skipped"), /*#__PURE__*/_react.default.createElement(_Button.Button, {
|
|
63
|
+
variant: "primaryGray",
|
|
64
|
+
disabled: true
|
|
65
|
+
}, "Disabled"), /*#__PURE__*/_react.default.createElement(_Button.Button, {
|
|
51
66
|
variant: "primaryGray"
|
|
52
67
|
}, "Focusable")), /*#__PURE__*/_react.default.createElement(_Input.Input, {
|
|
53
68
|
placeholder: "Not focusable"
|
|
@@ -84,4 +99,30 @@ var WithAutocompleteInput = function WithAutocompleteInput() {
|
|
|
84
99
|
|
|
85
100
|
exports.WithAutocompleteInput = WithAutocompleteInput;
|
|
86
101
|
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";
|
|
87
128
|
//# sourceMappingURL=useFocusLock.story.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/useFocusLock.story.tsx"],"names":["title","Default","ref","WithAutocompleteInput","text","value"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA
|
|
1
|
+
{"version":3,"sources":["../../src/utils/useFocusLock.story.tsx"],"names":["title","Default","ref","WithAutocompleteInput","text","value","DisableToEnable","setValue","e","target"],"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;AAA8B,IAAA,QAAQ;AAAtC,gBAVF,eAaE,6BAAC,cAAD;AAAQ,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A;AAHZ,IADF,eAME,6BAAC,cAAD;AAAQ,IAAA,QAAQ,EAAE,CAACA;AAAnB,cANF,CADF;AAUD,CAjBM;;;AAAMC,e","sourcesContent":["import React, { useRef, useState } 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\" disabled>\n Disabled\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\nexport const DisableToEnable = () => {\n const [value, setValue] = useState(\"\")\n\n const ref = useRef<HTMLDivElement | null>(null)\n\n useFocusLock({ ref })\n\n return (\n <div ref={ref}>\n <Input\n placeholder=\"Value\"\n value={value}\n onChange={(e) => setValue(e.target.value)}\n />\n <Button disabled={!value}>Submit</Button>\n </div>\n )\n}\n"],"file":"useFocusLock.story.js"}
|
|
@@ -13,18 +13,20 @@ 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
|
+
};
|
|
16
22
|
/**
|
|
17
23
|
* Accepts a ref and calls the `onMutate` callback when mutations are observed.
|
|
18
24
|
*/
|
|
25
|
+
|
|
19
26
|
var useMutationObserver = function useMutationObserver(_ref) {
|
|
20
27
|
var onMutate = _ref.onMutate,
|
|
21
28
|
_ref$options = _ref.options,
|
|
22
|
-
options = _ref$options === void 0 ?
|
|
23
|
-
attributes: true,
|
|
24
|
-
characterData: true,
|
|
25
|
-
childList: true,
|
|
26
|
-
subtree: true
|
|
27
|
-
} : _ref$options,
|
|
29
|
+
options = _ref$options === void 0 ? DEFAULT_OPTIONS : _ref$options,
|
|
28
30
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
29
31
|
|
|
30
32
|
(0, _react.useEffect)(function () {
|
|
@@ -33,16 +35,13 @@ var useMutationObserver = function useMutationObserver(_ref) {
|
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
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
|
|
36
40
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return function () {
|
|
42
|
-
observer.disconnect();
|
|
43
|
-
};
|
|
44
|
-
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
45
|
-
|
|
41
|
+
observer.observe(el, options);
|
|
42
|
+
return function () {
|
|
43
|
+
observer.disconnect();
|
|
44
|
+
}; // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
46
45
|
}, [onMutate, options]);
|
|
47
46
|
};
|
|
48
47
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/useMutationObserver.ts"],"names":["
|
|
1
|
+
{"version":3,"sources":["../../src/utils/useMutationObserver.ts"],"names":["DEFAULT_OPTIONS","attributes","characterData","childList","subtree","useMutationObserver","onMutate","options","rest","MutationObserver","el","ref","current","element","observer","observe","disconnect"],"mappings":";;;;;;;AACA;;;;;;;;AAUA,IAAMA,eAAe,GAAG;AACtBC,EAAAA,UAAU,EAAE,IADU;AAEtBC,EAAAA,aAAa,EAAE,IAFO;AAGtBC,EAAAA,SAAS,EAAE,IAHW;AAItBC,EAAAA,OAAO,EAAE;AAJa,CAAxB;AAOA;AACA;AACA;;AACO,IAAMC,mBAAmB,GAAG,SAAtBA,mBAAsB,OAIR;AAAA,MAHzBC,QAGyB,QAHzBA,QAGyB;AAAA,0BAFzBC,OAEyB;AAAA,MAFzBA,OAEyB,6BAFfP,eAEe;AAAA,MADtBQ,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,QAAI,CAACH,EAAL,EAAS;AACT,QAAMI,QAAQ,GAAG,IAAIL,gBAAJ,CAAqBH,QAArB,CAAjB,CARc,CAUd;;AACAQ,IAAAA,QAAQ,CAACC,OAAT,CAAiBL,EAAjB,EAAqBH,OAArB;AAEA,WAAO,YAAM;AACXO,MAAAA,QAAQ,CAACE,UAAT;AACD,KAFD,CAbc,CAgBd;AACD,GAjBD,EAiBG,CAACV,QAAD,EAAWC,OAAX,CAjBH;AAkBD,CAvBM","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\nconst DEFAULT_OPTIONS = {\n attributes: true,\n characterData: true,\n childList: true,\n subtree: true,\n}\n\n/**\n * Accepts a ref and calls the `onMutate` callback when mutations are observed.\n */\nexport const useMutationObserver = ({\n onMutate,\n options = DEFAULT_OPTIONS,\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) return\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 // 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.2",
|
|
4
4
|
"description": "Design system library for react components",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -122,6 +122,7 @@
|
|
|
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",
|
|
125
126
|
"trunc-html": "^1.1.2",
|
|
126
127
|
"use-cursor": "^1.2.3",
|
|
127
128
|
"use-keyboard-list-navigation": "2.4.2"
|
|
@@ -174,5 +175,5 @@
|
|
|
174
175
|
"<rootDir>/www/"
|
|
175
176
|
]
|
|
176
177
|
},
|
|
177
|
-
"gitHead": "
|
|
178
|
+
"gitHead": "12d35a8d6495b473b6ccb0e65990d003d44c0b3b"
|
|
178
179
|
}
|