@jobber/hooks 2.9.0 → 2.9.2-CJS-to-ESM.14
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/index.js +15 -31
- package/dist/useAssert/index.js +1 -5
- package/dist/useAssert/useAssert.js +3 -10
- package/dist/useBool/index.js +1 -5
- package/dist/useBool/useBool.js +6 -10
- package/dist/useBool/useBool.test.js +9 -11
- package/dist/useBreakpoints/index.js +2 -20
- package/dist/useBreakpoints/mockViewportWidth/index.js +1 -17
- package/dist/useBreakpoints/mockViewportWidth/mockViewportWidth.js +2 -7
- package/dist/useBreakpoints/mockViewportWidth/mockViewportWidth.test.js +4 -6
- package/dist/useBreakpoints/useBreakpoints.js +9 -13
- package/dist/useBreakpoints/useBreakpoints.test.js +28 -30
- package/dist/useBreakpoints/useMediaQuery.js +4 -8
- package/dist/useCollectionQuery/index.js +1 -5
- package/dist/useCollectionQuery/mdxUtils.js +8 -12
- package/dist/useCollectionQuery/test-utilities/index.js +3 -19
- package/dist/useCollectionQuery/test-utilities/mocks.js +19 -30
- package/dist/useCollectionQuery/test-utilities/queries.js +4 -7
- package/dist/useCollectionQuery/test-utilities/utils.js +1 -5
- package/dist/useCollectionQuery/uniqueEdges.js +2 -7
- package/dist/useCollectionQuery/uniqueNodes.js +1 -5
- package/dist/useCollectionQuery/useCollectionQuery.js +27 -35
- package/dist/useCollectionQuery/useCollectionQuery.test.js +126 -128
- package/dist/useFocusTrap/index.js +1 -5
- package/dist/useFocusTrap/useFocusTrap.js +4 -8
- package/dist/useFocusTrap/useFocusTrap.test.js +26 -31
- package/dist/useFormState/index.js +1 -5
- package/dist/useFormState/useFormState.js +3 -7
- package/dist/useInView/index.js +1 -17
- package/dist/useInView/useInView.js +6 -10
- package/dist/useInView/useInView.test.js +12 -17
- package/dist/useIsMounted/index.js +1 -5
- package/dist/useIsMounted/useIsMounted.js +5 -9
- package/dist/useIsMounted/useIsMounted.test.js +4 -6
- package/dist/useLiveAnnounce/index.js +1 -5
- package/dist/useLiveAnnounce/useLiveAnnounce.js +4 -8
- package/dist/useLiveAnnounce/useLiveAnnounce.test.js +19 -24
- package/dist/useOnKeyDown/index.js +1 -5
- package/dist/useOnKeyDown/useOnKeyDown.js +3 -7
- package/dist/useOnKeyDown/useOnKeyDown.test.js +7 -12
- package/dist/usePasswordStrength/index.js +1 -5
- package/dist/usePasswordStrength/usePasswordStrength.js +4 -11
- package/dist/useRefocusOnActivator/index.js +1 -5
- package/dist/useRefocusOnActivator/useRefocusOnActivator.js +3 -7
- package/dist/useResizeObserver/index.js +1 -17
- package/dist/useResizeObserver/useResizeObserver.js +8 -15
- package/dist/useSafeLayoutEffect/index.js +1 -5
- package/dist/useSafeLayoutEffect/useSafeLayoutEffect.js +4 -7
- package/dist/useShowClear/index.js +1 -5
- package/dist/useShowClear/useShowClear.js +1 -5
- package/dist/useShowClear/useShowClear.test.js +5 -7
- package/package.json +4 -3
package/dist/useInView/index.js
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./useInView"), exports);
|
|
1
|
+
export * from "./useInView";
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const [isInView, setIsInView] = (0, react_1.useState)(false);
|
|
8
|
-
const handleIntersection = (0, react_1.useCallback)(entries => setIsInView(entries[0].isIntersecting), [setIsInView]);
|
|
9
|
-
(0, react_1.useEffect)(() => {
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
export function useInView() {
|
|
3
|
+
const ref = useRef(null);
|
|
4
|
+
const [isInView, setIsInView] = useState(false);
|
|
5
|
+
const handleIntersection = useCallback(entries => setIsInView(entries[0].isIntersecting), [setIsInView]);
|
|
6
|
+
useEffect(() => {
|
|
10
7
|
if (!window.IntersectionObserver)
|
|
11
8
|
return;
|
|
12
9
|
const observer = new IntersectionObserver(handleIntersection);
|
|
@@ -17,4 +14,3 @@ function useInView() {
|
|
|
17
14
|
}, [handleIntersection, ref.current]);
|
|
18
15
|
return [ref, isInView];
|
|
19
16
|
}
|
|
20
|
-
exports.useInView = useInView;
|
|
@@ -1,29 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const react_2 = require("@testing-library/react");
|
|
8
|
-
const jsdom_testing_mocks_1 = require("jsdom-testing-mocks");
|
|
9
|
-
const useInView_1 = require("./useInView");
|
|
10
|
-
(0, jsdom_testing_mocks_1.configMocks)({ act: react_2.act });
|
|
11
|
-
const observer = (0, jsdom_testing_mocks_1.mockIntersectionObserver)();
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { act, render, renderHook, screen } from "@testing-library/react";
|
|
3
|
+
import { configMocks, mockIntersectionObserver } from "jsdom-testing-mocks";
|
|
4
|
+
import { useInView } from "./useInView";
|
|
5
|
+
configMocks({ act });
|
|
6
|
+
const observer = mockIntersectionObserver();
|
|
12
7
|
describe("useInView", () => {
|
|
13
8
|
it("should return true when the target element is in view", () => {
|
|
14
|
-
const { result, rerender } =
|
|
9
|
+
const { result, rerender } = renderHook(() => useInView());
|
|
15
10
|
const [ref, isInView] = result.current;
|
|
16
|
-
|
|
11
|
+
render(React.createElement("button", { ref: ref }));
|
|
17
12
|
rerender();
|
|
18
13
|
expect(result.current[0].current).toBeInstanceOf(HTMLButtonElement);
|
|
19
|
-
observer.leaveNode(
|
|
14
|
+
observer.leaveNode(screen.getByRole("button"));
|
|
20
15
|
expect(isInView).toBe(false);
|
|
21
16
|
});
|
|
22
17
|
it("should return false when the target element is in view", () => {
|
|
23
|
-
const { result, rerender } =
|
|
24
|
-
|
|
18
|
+
const { result, rerender } = renderHook(() => useInView());
|
|
19
|
+
render(React.createElement("button", { ref: result.current[0] }));
|
|
25
20
|
rerender();
|
|
26
|
-
observer.enterNode(
|
|
21
|
+
observer.enterNode(screen.getByRole("button"));
|
|
27
22
|
expect(result.current[1]).toBe(true);
|
|
28
23
|
});
|
|
29
24
|
});
|
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useIsMounted = void 0;
|
|
4
|
-
var useIsMounted_1 = require("./useIsMounted");
|
|
5
|
-
Object.defineProperty(exports, "useIsMounted", { enumerable: true, get: function () { return useIsMounted_1.useIsMounted; } });
|
|
1
|
+
export { useIsMounted } from "./useIsMounted";
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.useIsMounted = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const useSafeLayoutEffect_1 = require("../useSafeLayoutEffect");
|
|
1
|
+
import { useRef } from "react";
|
|
2
|
+
import { useSafeLayoutEffect } from "../useSafeLayoutEffect";
|
|
6
3
|
/**
|
|
7
4
|
* Why does this work?
|
|
8
5
|
*
|
|
@@ -19,9 +16,9 @@ const useSafeLayoutEffect_1 = require("../useSafeLayoutEffect");
|
|
|
19
16
|
* When the component unmounts, it calls the cleanup function that sets `isMounted` to false.
|
|
20
17
|
* This `useLayoutEffect` hook will only be run once.
|
|
21
18
|
*/
|
|
22
|
-
function useIsMounted() {
|
|
23
|
-
const isMounted =
|
|
24
|
-
|
|
19
|
+
export function useIsMounted() {
|
|
20
|
+
const isMounted = useRef(false);
|
|
21
|
+
useSafeLayoutEffect(() => {
|
|
25
22
|
isMounted.current = true;
|
|
26
23
|
return () => {
|
|
27
24
|
isMounted.current = false;
|
|
@@ -29,4 +26,3 @@ function useIsMounted() {
|
|
|
29
26
|
}, []);
|
|
30
27
|
return isMounted;
|
|
31
28
|
}
|
|
32
|
-
exports.useIsMounted = useIsMounted;
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const react_hooks_1 = require("@testing-library/react-hooks");
|
|
4
|
-
const useIsMounted_1 = require("./useIsMounted");
|
|
1
|
+
import { renderHook } from "@testing-library/react-hooks";
|
|
2
|
+
import { useIsMounted } from "./useIsMounted";
|
|
5
3
|
it("should return true when the component is currently mounted", () => {
|
|
6
|
-
const { result } =
|
|
4
|
+
const { result } = renderHook(() => useIsMounted());
|
|
7
5
|
const isMounted = result.current;
|
|
8
6
|
expect(isMounted.current).toBe(true);
|
|
9
7
|
});
|
|
10
8
|
it("should return false when the component is unmounted", () => {
|
|
11
|
-
const { result, unmount } =
|
|
9
|
+
const { result, unmount } = renderHook(() => useIsMounted());
|
|
12
10
|
const isMounted = result.current;
|
|
13
11
|
unmount();
|
|
14
12
|
expect(isMounted.current).toBe(false);
|
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useLiveAnnounce = void 0;
|
|
4
|
-
var useLiveAnnounce_1 = require("./useLiveAnnounce");
|
|
5
|
-
Object.defineProperty(exports, "useLiveAnnounce", { enumerable: true, get: function () { return useLiveAnnounce_1.useLiveAnnounce; } });
|
|
1
|
+
export { useLiveAnnounce } from "./useLiveAnnounce";
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useLiveAnnounce = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
5
2
|
/**
|
|
6
3
|
* Announce a message on voice over whenever you do an action. This is
|
|
7
4
|
* especially helpful when you have an action that adds or deletes an element
|
|
8
5
|
* from the screen.
|
|
9
6
|
*/
|
|
10
|
-
function useLiveAnnounce() {
|
|
11
|
-
const [announcedMessage, setAnnouncedMessage] =
|
|
12
|
-
|
|
7
|
+
export function useLiveAnnounce() {
|
|
8
|
+
const [announcedMessage, setAnnouncedMessage] = useState("");
|
|
9
|
+
useEffect(() => {
|
|
13
10
|
let target;
|
|
14
11
|
if (announcedMessage) {
|
|
15
12
|
target = createAnnouncedElement();
|
|
@@ -23,7 +20,6 @@ function useLiveAnnounce() {
|
|
|
23
20
|
},
|
|
24
21
|
};
|
|
25
22
|
}
|
|
26
|
-
exports.useLiveAnnounce = useLiveAnnounce;
|
|
27
23
|
// eslint-disable-next-line max-statements
|
|
28
24
|
function createAnnouncedElement() {
|
|
29
25
|
const el = document.createElement("div");
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,30 +7,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const react_1 = __importDefault(require("react"));
|
|
16
|
-
const react_2 = require("@testing-library/react");
|
|
17
|
-
const _1 = require(".");
|
|
10
|
+
import React from "react";
|
|
11
|
+
import { act, render, screen, waitFor } from "@testing-library/react";
|
|
12
|
+
import { useLiveAnnounce } from ".";
|
|
18
13
|
function setupHook() {
|
|
19
14
|
const returnVal = {
|
|
20
15
|
liveAnnounce: jest.fn,
|
|
21
16
|
};
|
|
22
17
|
function TestComponent() {
|
|
23
|
-
Object.assign(returnVal,
|
|
24
|
-
return
|
|
18
|
+
Object.assign(returnVal, useLiveAnnounce());
|
|
19
|
+
return React.createElement(React.Fragment, null);
|
|
25
20
|
}
|
|
26
|
-
const { rerender } =
|
|
27
|
-
return Object.assign(Object.assign({}, returnVal), { rerenderComponent: () => rerender(
|
|
21
|
+
const { rerender } = render(React.createElement(TestComponent, null));
|
|
22
|
+
return Object.assign(Object.assign({}, returnVal), { rerenderComponent: () => rerender(React.createElement(TestComponent, null)) });
|
|
28
23
|
}
|
|
29
24
|
it("should render a div to announce", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
25
|
const { liveAnnounce } = setupHook();
|
|
31
26
|
const message = "Huzzah";
|
|
32
|
-
|
|
33
|
-
yield
|
|
34
|
-
const expectedElement =
|
|
27
|
+
act(() => liveAnnounce(message));
|
|
28
|
+
yield waitFor(() => {
|
|
29
|
+
const expectedElement = screen.queryByRole("status");
|
|
35
30
|
expect(expectedElement).toBeInTheDocument();
|
|
36
31
|
expect(expectedElement === null || expectedElement === void 0 ? void 0 : expectedElement.textContent).toBe(message);
|
|
37
32
|
expect(expectedElement).toHaveAttribute("role", "status");
|
|
@@ -41,20 +36,20 @@ it("should render a div to announce", () => __awaiter(void 0, void 0, void 0, fu
|
|
|
41
36
|
}));
|
|
42
37
|
it("should not render the announced div", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
38
|
setupHook();
|
|
44
|
-
expect(
|
|
39
|
+
expect(screen.queryByRole("status")).not.toBeInTheDocument();
|
|
45
40
|
}));
|
|
46
41
|
it("should only have 1 div to announce a message on a single instance of the hook", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
42
|
const { liveAnnounce } = setupHook();
|
|
48
43
|
const firstMessage = "I am first";
|
|
49
44
|
const secondMessage = "I am second";
|
|
50
|
-
|
|
51
|
-
yield
|
|
52
|
-
expect(
|
|
53
|
-
expect(
|
|
45
|
+
act(() => liveAnnounce(firstMessage));
|
|
46
|
+
yield waitFor(() => {
|
|
47
|
+
expect(screen.queryAllByRole("status")).toHaveLength(1);
|
|
48
|
+
expect(screen.getByRole("status").textContent).toBe(firstMessage);
|
|
54
49
|
});
|
|
55
|
-
|
|
56
|
-
yield
|
|
57
|
-
expect(
|
|
58
|
-
expect(
|
|
50
|
+
act(() => liveAnnounce(secondMessage));
|
|
51
|
+
yield waitFor(() => {
|
|
52
|
+
expect(screen.queryAllByRole("status")).toHaveLength(1);
|
|
53
|
+
expect(screen.getByRole("status").textContent).toBe(secondMessage);
|
|
59
54
|
});
|
|
60
55
|
}));
|
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useOnKeyDown = void 0;
|
|
4
|
-
var useOnKeyDown_1 = require("./useOnKeyDown");
|
|
5
|
-
Object.defineProperty(exports, "useOnKeyDown", { enumerable: true, get: function () { return useOnKeyDown_1.useOnKeyDown; } });
|
|
1
|
+
export { useOnKeyDown } from "./useOnKeyDown";
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
function useOnKeyDown(callback, keys) {
|
|
6
|
-
(0, react_1.useEffect)(() => {
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
export function useOnKeyDown(callback, keys) {
|
|
3
|
+
useEffect(() => {
|
|
7
4
|
window.addEventListener("keydown", handler);
|
|
8
5
|
return () => {
|
|
9
6
|
window.removeEventListener("keydown", handler);
|
|
@@ -32,4 +29,3 @@ function useOnKeyDown(callback, keys) {
|
|
|
32
29
|
}
|
|
33
30
|
}
|
|
34
31
|
}
|
|
35
|
-
exports.useOnKeyDown = useOnKeyDown;
|
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const react_1 = __importDefault(require("react"));
|
|
7
|
-
const react_2 = require("@testing-library/react");
|
|
8
|
-
const _1 = require(".");
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { fireEvent, render } from "@testing-library/react";
|
|
3
|
+
import { useOnKeyDown } from ".";
|
|
9
4
|
test("fires the method when the key is pressed", () => {
|
|
10
5
|
const keypressCallback = jest.fn();
|
|
11
|
-
const { container } =
|
|
6
|
+
const { container } = render(React.createElement(TestComponent, { callback: keypressCallback }));
|
|
12
7
|
expect(keypressCallback).toHaveBeenCalledTimes(0);
|
|
13
|
-
|
|
8
|
+
fireEvent(container, new KeyboardEvent("keydown", {
|
|
14
9
|
key: "Enter",
|
|
15
10
|
bubbles: true,
|
|
16
11
|
cancelable: false,
|
|
@@ -18,6 +13,6 @@ test("fires the method when the key is pressed", () => {
|
|
|
18
13
|
expect(keypressCallback).toHaveBeenCalledTimes(1);
|
|
19
14
|
});
|
|
20
15
|
function TestComponent({ callback }) {
|
|
21
|
-
|
|
22
|
-
return
|
|
16
|
+
useOnKeyDown(callback, "Enter");
|
|
17
|
+
return React.createElement(React.Fragment, null, "Look at me!");
|
|
23
18
|
}
|
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.usePasswordStrength = void 0;
|
|
4
|
-
var usePasswordStrength_1 = require("./usePasswordStrength");
|
|
5
|
-
Object.defineProperty(exports, "usePasswordStrength", { enumerable: true, get: function () { return usePasswordStrength_1.usePasswordStrength; } });
|
|
1
|
+
export { usePasswordStrength } from "./usePasswordStrength";
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.usePasswordStrength = void 0;
|
|
7
|
-
const react_1 = require("react");
|
|
8
|
-
const zxcvbn_1 = __importDefault(require("zxcvbn"));
|
|
9
|
-
function usePasswordStrength(password, dictionary) {
|
|
10
|
-
const { guesses, score, feedback: { warning, suggestions }, crack_times_display: { offline_fast_hashing_1e10_per_second: timeToCrack }, } = (0, react_1.useMemo)(() => (0, zxcvbn_1.default)(password, dictionary), [password, dictionary]);
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import calculateStrength from "zxcvbn";
|
|
3
|
+
export function usePasswordStrength(password, dictionary) {
|
|
4
|
+
const { guesses, score, feedback: { warning, suggestions }, crack_times_display: { offline_fast_hashing_1e10_per_second: timeToCrack }, } = useMemo(() => calculateStrength(password, dictionary), [password, dictionary]);
|
|
11
5
|
return {
|
|
12
6
|
guesses,
|
|
13
7
|
score,
|
|
@@ -16,4 +10,3 @@ function usePasswordStrength(password, dictionary) {
|
|
|
16
10
|
timeToCrack,
|
|
17
11
|
};
|
|
18
12
|
}
|
|
19
|
-
exports.usePasswordStrength = usePasswordStrength;
|
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useRefocusOnActivator = void 0;
|
|
4
|
-
var useRefocusOnActivator_1 = require("./useRefocusOnActivator");
|
|
5
|
-
Object.defineProperty(exports, "useRefocusOnActivator", { enumerable: true, get: function () { return useRefocusOnActivator_1.useRefocusOnActivator; } });
|
|
1
|
+
export { useRefocusOnActivator } from "./useRefocusOnActivator";
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useRefocusOnActivator = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
1
|
+
import { useEffect } from "react";
|
|
5
2
|
/**
|
|
6
3
|
* Brings back the focus to the element that opened an overlaid element once
|
|
7
4
|
* said overlaid element is dismissed.
|
|
8
5
|
*
|
|
9
6
|
* @param active - Determines if it should focus or not
|
|
10
7
|
*/
|
|
11
|
-
function useRefocusOnActivator(active) {
|
|
12
|
-
|
|
8
|
+
export function useRefocusOnActivator(active) {
|
|
9
|
+
useEffect(() => {
|
|
13
10
|
let activator;
|
|
14
11
|
if (active && !activator) {
|
|
15
12
|
activator = document.activeElement;
|
|
@@ -24,4 +21,3 @@ function useRefocusOnActivator(active) {
|
|
|
24
21
|
};
|
|
25
22
|
}, [active]);
|
|
26
23
|
}
|
|
27
|
-
exports.useRefocusOnActivator = useRefocusOnActivator;
|
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./useResizeObserver"), exports);
|
|
1
|
+
export * from "./useResizeObserver";
|
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.useResizeObserver = exports.Breakpoints = void 0;
|
|
7
|
-
const react_1 = require("react");
|
|
1
|
+
import { useMemo, useState } from "react";
|
|
8
2
|
// Importing the polyfilled version of ResizeObserver
|
|
9
3
|
// eslint-disable-next-line import/no-internal-modules
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
import useResizeObserverPackage from "use-resize-observer/polyfilled";
|
|
5
|
+
import throttle from "lodash/throttle";
|
|
6
|
+
export const Breakpoints = {
|
|
13
7
|
base: 640,
|
|
14
8
|
small: 500,
|
|
15
9
|
smaller: 265,
|
|
@@ -17,13 +11,13 @@ exports.Breakpoints = {
|
|
|
17
11
|
larger: 1024,
|
|
18
12
|
};
|
|
19
13
|
const wait = 100;
|
|
20
|
-
function useResizeObserver({ widths =
|
|
21
|
-
const [exactSize, setSize] =
|
|
14
|
+
export function useResizeObserver({ widths = Breakpoints, heights = Breakpoints, } = {}) {
|
|
15
|
+
const [exactSize, setSize] = useState({
|
|
22
16
|
width: undefined,
|
|
23
17
|
height: undefined,
|
|
24
18
|
});
|
|
25
|
-
const onResize =
|
|
26
|
-
const { ref } = (
|
|
19
|
+
const onResize = useMemo(() => throttle(setSize, wait), [wait]);
|
|
20
|
+
const { ref } = useResizeObserverPackage({
|
|
27
21
|
onResize,
|
|
28
22
|
});
|
|
29
23
|
const exactWidth = exactSize.width;
|
|
@@ -36,7 +30,6 @@ function useResizeObserver({ widths = exports.Breakpoints, heights = exports.Bre
|
|
|
36
30
|
};
|
|
37
31
|
return [ref, sizes];
|
|
38
32
|
}
|
|
39
|
-
exports.useResizeObserver = useResizeObserver;
|
|
40
33
|
/**
|
|
41
34
|
* To get the proper size we want to make sure that our value is greater
|
|
42
35
|
* then the comparable, but less then the next largest number in our
|
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useSafeLayoutEffect = void 0;
|
|
4
|
-
var useSafeLayoutEffect_1 = require("./useSafeLayoutEffect");
|
|
5
|
-
Object.defineProperty(exports, "useSafeLayoutEffect", { enumerable: true, get: function () { return useSafeLayoutEffect_1.useSafeLayoutEffect; } });
|
|
1
|
+
export { useSafeLayoutEffect } from "./useSafeLayoutEffect";
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
exports.useSafeLayoutEffect = (globalThis === null || globalThis === void 0 ? void 0 : globalThis.document)
|
|
6
|
-
? react_1.useLayoutEffect
|
|
7
|
-
: react_1.useEffect;
|
|
1
|
+
import { useEffect, useLayoutEffect } from "react";
|
|
2
|
+
export const useSafeLayoutEffect = (globalThis === null || globalThis === void 0 ? void 0 : globalThis.document)
|
|
3
|
+
? useLayoutEffect
|
|
4
|
+
: useEffect;
|
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useShowClear = void 0;
|
|
4
|
-
var useShowClear_1 = require("./useShowClear");
|
|
5
|
-
Object.defineProperty(exports, "useShowClear", { enumerable: true, get: function () { return useShowClear_1.useShowClear; } });
|
|
1
|
+
export { useShowClear } from "./useShowClear";
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useShowClear = void 0;
|
|
4
|
-
function useShowClear({ clearable, multiline, focused, hasValue, disabled = false, }) {
|
|
1
|
+
export function useShowClear({ clearable, multiline, focused, hasValue, disabled = false, }) {
|
|
5
2
|
if (multiline && clearable !== "never") {
|
|
6
3
|
throw new Error("Multiline inputs can not be clearable");
|
|
7
4
|
}
|
|
@@ -16,4 +13,3 @@ function useShowClear({ clearable, multiline, focused, hasValue, disabled = fals
|
|
|
16
13
|
return true;
|
|
17
14
|
}
|
|
18
15
|
}
|
|
19
|
-
exports.useShowClear = useShowClear;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const useShowClear_1 = require("./useShowClear");
|
|
1
|
+
import { useShowClear } from "./useShowClear";
|
|
4
2
|
describe("useShowClear", () => {
|
|
5
3
|
describe.each([
|
|
6
4
|
{
|
|
@@ -101,12 +99,12 @@ describe("useShowClear", () => {
|
|
|
101
99
|
},
|
|
102
100
|
])("%j", ({ clearable, hasValue, focused, multiline, disabled, expected, }) => {
|
|
103
101
|
it(`returns ${expected}`, () => {
|
|
104
|
-
expect(
|
|
102
|
+
expect(useShowClear({ clearable, multiline, focused, hasValue, disabled })).toEqual(expected);
|
|
105
103
|
});
|
|
106
104
|
});
|
|
107
105
|
it("throws an error if multiline is true and clearable isn't never", () => {
|
|
108
106
|
expect(() => {
|
|
109
|
-
|
|
107
|
+
useShowClear({
|
|
110
108
|
clearable: "always",
|
|
111
109
|
multiline: true,
|
|
112
110
|
focused: true,
|
|
@@ -115,7 +113,7 @@ describe("useShowClear", () => {
|
|
|
115
113
|
});
|
|
116
114
|
}).toThrow();
|
|
117
115
|
expect(() => {
|
|
118
|
-
|
|
116
|
+
useShowClear({
|
|
119
117
|
clearable: "while-editing",
|
|
120
118
|
multiline: true,
|
|
121
119
|
focused: true,
|
|
@@ -124,7 +122,7 @@ describe("useShowClear", () => {
|
|
|
124
122
|
});
|
|
125
123
|
}).toThrow();
|
|
126
124
|
expect(() => {
|
|
127
|
-
|
|
125
|
+
useShowClear({
|
|
128
126
|
clearable: "never",
|
|
129
127
|
multiline: true,
|
|
130
128
|
focused: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jobber/hooks",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "2.9.2-CJS-to-ESM.14+48bce0b8",
|
|
4
5
|
"license": "MIT",
|
|
5
6
|
"main": "./dist/index.js",
|
|
6
7
|
"types": "./dist/index.d.js",
|
|
@@ -20,7 +21,7 @@
|
|
|
20
21
|
],
|
|
21
22
|
"devDependencies": {
|
|
22
23
|
"@apollo/react-testing": "^4.0.0",
|
|
23
|
-
"@jobber/formatters": "
|
|
24
|
+
"@jobber/formatters": "^0.2.2",
|
|
24
25
|
"@testing-library/react": "^14.0.0",
|
|
25
26
|
"@testing-library/react-hooks": "^7.0.0",
|
|
26
27
|
"@testing-library/user-event": "^14.5.1",
|
|
@@ -44,5 +45,5 @@
|
|
|
44
45
|
"@apollo/client": "^3.0.0",
|
|
45
46
|
"react": "^18"
|
|
46
47
|
},
|
|
47
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "48bce0b8e3467fca2a9ef6ecea7c7a1d175a9e9c"
|
|
48
49
|
}
|