@jobber/hooks 2.0.3-pre.51 → 2.0.3-pre1.52
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.d.ts +10 -10
- package/dist/index.js +11 -26
- package/dist/useAssert/index.d.ts +1 -1
- package/dist/useAssert/index.js +1 -5
- package/dist/useAssert/useAssert.js +3 -10
- package/dist/useCollectionQuery/index.d.ts +1 -1
- package/dist/useCollectionQuery/index.js +1 -5
- package/dist/useCollectionQuery/mdxUtils.d.ts +2 -3
- package/dist/useCollectionQuery/mdxUtils.js +8 -12
- package/dist/useCollectionQuery/test-utilities/index.d.ts +3 -3
- package/dist/useCollectionQuery/test-utilities/index.js +3 -19
- package/dist/useCollectionQuery/test-utilities/mocks.d.ts +1 -1
- package/dist/useCollectionQuery/test-utilities/mocks.js +19 -30
- package/dist/useCollectionQuery/test-utilities/queries.d.ts +3 -3
- package/dist/useCollectionQuery/test-utilities/queries.js +4 -7
- package/dist/useCollectionQuery/test-utilities/utils.js +1 -5
- package/dist/useCollectionQuery/uniqueEdges.d.ts +1 -1
- package/dist/useCollectionQuery/uniqueEdges.js +2 -7
- package/dist/useCollectionQuery/uniqueNodes.js +1 -5
- package/dist/useCollectionQuery/useCollectionQuery.d.ts +2 -2
- package/dist/useCollectionQuery/useCollectionQuery.js +26 -31
- package/dist/useCollectionQuery/useCollectionQuery.test.js +119 -119
- package/dist/useFocusTrap/index.d.ts +1 -1
- 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.d.ts +1 -1
- package/dist/useFormState/index.js +1 -5
- package/dist/useFormState/useFormState.js +3 -7
- package/dist/useIsMounted/index.d.ts +1 -1
- package/dist/useIsMounted/index.js +1 -5
- package/dist/useIsMounted/useIsMounted.js +4 -8
- package/dist/useIsMounted/useIsMounted.test.js +4 -6
- package/dist/useLiveAnnounce/index.d.ts +1 -1
- 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.d.ts +1 -1
- package/dist/useOnKeyDown/index.js +1 -5
- package/dist/useOnKeyDown/useOnKeyDown.js +3 -10
- package/dist/useOnKeyDown/useOnKeyDown.test.js +7 -12
- package/dist/usePasswordStrength/index.d.ts +1 -1
- package/dist/usePasswordStrength/index.js +1 -5
- package/dist/usePasswordStrength/usePasswordStrength.js +4 -11
- package/dist/useRefocusOnActivator/index.d.ts +1 -1
- package/dist/useRefocusOnActivator/index.js +1 -5
- package/dist/useRefocusOnActivator/useRefocusOnActivator.js +3 -7
- package/dist/useResizeObserver/index.d.ts +1 -1
- package/dist/useResizeObserver/index.js +1 -17
- package/dist/useResizeObserver/useResizeObserver.d.ts +1 -2
- package/dist/useResizeObserver/useResizeObserver.js +8 -15
- package/package.json +3 -6
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useIsMounted = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
1
|
+
import { useLayoutEffect, useRef } from "react";
|
|
5
2
|
/**
|
|
6
3
|
* Why does this work?
|
|
7
4
|
*
|
|
@@ -18,9 +15,9 @@ const react_1 = require("react");
|
|
|
18
15
|
* When the component unmounts, it calls the cleanup function that sets `isMounted` to false.
|
|
19
16
|
* This `useLayoutEffect` hook will only be run once.
|
|
20
17
|
*/
|
|
21
|
-
function useIsMounted() {
|
|
22
|
-
const isMounted =
|
|
23
|
-
|
|
18
|
+
export function useIsMounted() {
|
|
19
|
+
const isMounted = useRef(false);
|
|
20
|
+
useLayoutEffect(() => {
|
|
24
21
|
isMounted.current = true;
|
|
25
22
|
return () => {
|
|
26
23
|
isMounted.current = false;
|
|
@@ -28,4 +25,3 @@ function useIsMounted() {
|
|
|
28
25
|
}, []);
|
|
29
26
|
return isMounted;
|
|
30
27
|
}
|
|
31
|
-
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.js";
|
|
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 +1 @@
|
|
|
1
|
-
export { useLiveAnnounce } from "./useLiveAnnounce";
|
|
1
|
+
export { useLiveAnnounce } from "./useLiveAnnounce.js";
|
|
@@ -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.js";
|
|
@@ -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 "./index.js";
|
|
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 +1 @@
|
|
|
1
|
-
export { useOnKeyDown } from "./useOnKeyDown";
|
|
1
|
+
export { useOnKeyDown } from "./useOnKeyDown.js";
|
|
@@ -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.js";
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
"use
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.useOnKeyDown = void 0;
|
|
7
|
-
const event_listener_1 = __importDefault(require("@use-it/event-listener"));
|
|
8
|
-
function useOnKeyDown(callback, keys) {
|
|
9
|
-
(0, event_listener_1.default)("keydown", handler);
|
|
1
|
+
import useEventListener from "@use-it/event-listener";
|
|
2
|
+
export function useOnKeyDown(callback, keys) {
|
|
3
|
+
useEventListener("keydown", handler);
|
|
10
4
|
function handler(event) {
|
|
11
5
|
const keyboardEvent = event;
|
|
12
6
|
if (typeof keys === "string" && keyboardEvent.key === keys) {
|
|
@@ -30,4 +24,3 @@ function useOnKeyDown(callback, keys) {
|
|
|
30
24
|
}
|
|
31
25
|
}
|
|
32
26
|
}
|
|
33
|
-
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 "./index.js";
|
|
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 +1 @@
|
|
|
1
|
-
export { usePasswordStrength } from "./usePasswordStrength";
|
|
1
|
+
export { usePasswordStrength } from "./usePasswordStrength.js";
|
|
@@ -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.js";
|
|
@@ -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 +1 @@
|
|
|
1
|
-
export { useRefocusOnActivator } from "./useRefocusOnActivator";
|
|
1
|
+
export { useRefocusOnActivator } from "./useRefocusOnActivator.js";
|
|
@@ -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.js";
|
|
@@ -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 +1 @@
|
|
|
1
|
-
export * from "./useResizeObserver";
|
|
1
|
+
export * from "./useResizeObserver.js";
|
|
@@ -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.js";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
export declare const Breakpoints: {
|
|
3
2
|
base: number;
|
|
4
3
|
small: number;
|
|
@@ -10,7 +9,7 @@ interface ResizeObserverProps {
|
|
|
10
9
|
widths?: object;
|
|
11
10
|
heights?: object;
|
|
12
11
|
}
|
|
13
|
-
export declare function useResizeObserver<T extends HTMLElement>({ widths, heights, }?: ResizeObserverProps): readonly [
|
|
12
|
+
export declare function useResizeObserver<T extends HTMLElement>({ widths, heights, }?: ResizeObserverProps): readonly [any, {
|
|
14
13
|
width: number | undefined;
|
|
15
14
|
height: number | undefined;
|
|
16
15
|
exactWidth: number | undefined;
|
|
@@ -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";
|
|
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
|
package/package.json
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jobber/hooks",
|
|
3
|
-
"version": "2.0.3-
|
|
3
|
+
"version": "2.0.3-pre1.52+dbd7fd38",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./dist/index.js",
|
|
9
|
-
"
|
|
10
|
-
"default": "./dist/*",
|
|
11
|
-
"types": "./dist/*.d.ts"
|
|
12
|
-
}
|
|
9
|
+
"./useIsMounted": "./dist/useIsMounted/index.js"
|
|
13
10
|
},
|
|
14
11
|
"scripts": {
|
|
15
12
|
"build": "tsc --project . --skipLibCheck",
|
|
@@ -45,5 +42,5 @@
|
|
|
45
42
|
"@apollo/client": "^3.7.10",
|
|
46
43
|
"react": "^18"
|
|
47
44
|
},
|
|
48
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "dbd7fd38ad63a18455a86f1b5faf72559d3009e1"
|
|
49
46
|
}
|