@jobber/hooks 2.9.2-CJS-to-ESM.19 → 2.9.2-CJS-to-ESM.25
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/README.mdx +4 -0
- package/dist/index.cjs +806 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js.map +1 -0
- package/dist/useAssert/index.cjs +53 -0
- package/dist/useAssert/index.cjs.map +1 -0
- package/dist/useAssert/index.js.map +1 -0
- package/dist/useBool/index.cjs +40 -0
- package/dist/useBool/index.cjs.map +1 -0
- package/dist/useBool/index.js.map +1 -0
- package/dist/useBreakpoints/index.cjs +138 -0
- package/dist/useBreakpoints/index.cjs.map +1 -0
- package/dist/useBreakpoints/index.js.map +1 -0
- package/dist/useCollectionQuery/index.cjs +389 -0
- package/dist/useCollectionQuery/index.cjs.map +1 -0
- package/dist/useCollectionQuery/index.js.map +1 -0
- package/dist/useFocusTrap/index.cjs +84 -0
- package/dist/useFocusTrap/index.cjs.map +1 -0
- package/dist/useFocusTrap/index.js.map +1 -0
- package/dist/useInView/index.cjs +51 -0
- package/dist/useInView/index.cjs.map +1 -0
- package/dist/useInView/index.js.map +1 -0
- package/dist/useIsMounted/index.cjs +49 -0
- package/dist/useIsMounted/index.cjs.map +1 -0
- package/dist/useIsMounted/index.js.map +1 -0
- package/dist/useLiveAnnounce/index.cjs +64 -0
- package/dist/useLiveAnnounce/index.cjs.map +1 -0
- package/dist/useLiveAnnounce/index.js.map +1 -0
- package/dist/useOnKeyDown/index.cjs +62 -0
- package/dist/useOnKeyDown/index.cjs.map +1 -0
- package/dist/useOnKeyDown/index.js.map +1 -0
- package/dist/usePasswordStrength/index.cjs +62 -0
- package/dist/usePasswordStrength/index.cjs.map +1 -0
- package/dist/usePasswordStrength/index.js.map +1 -0
- package/dist/useRefocusOnActivator/index.cjs +49 -0
- package/dist/useRefocusOnActivator/index.cjs.map +1 -0
- package/dist/useRefocusOnActivator/index.js.map +1 -0
- package/dist/useResizeObserver/index.cjs +84 -0
- package/dist/useResizeObserver/index.cjs.map +1 -0
- package/dist/useResizeObserver/index.js.map +1 -0
- package/dist/useSafeLayoutEffect/index.cjs +34 -0
- package/dist/useSafeLayoutEffect/index.cjs.map +1 -0
- package/dist/useSafeLayoutEffect/index.js.map +1 -0
- package/dist/useShowClear/index.cjs +52 -0
- package/dist/useShowClear/index.cjs.map +1 -0
- package/dist/useShowClear/index.js.map +1 -0
- package/package.json +22 -18
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/useIsMounted/index.ts
|
|
21
|
+
var useIsMounted_exports = {};
|
|
22
|
+
__export(useIsMounted_exports, {
|
|
23
|
+
useIsMounted: () => useIsMounted
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(useIsMounted_exports);
|
|
26
|
+
|
|
27
|
+
// src/useIsMounted/useIsMounted.ts
|
|
28
|
+
var import_react2 = require("react");
|
|
29
|
+
|
|
30
|
+
// src/useSafeLayoutEffect/useSafeLayoutEffect.ts
|
|
31
|
+
var import_react = require("react");
|
|
32
|
+
var useSafeLayoutEffect = (globalThis == null ? void 0 : globalThis.document) ? import_react.useLayoutEffect : import_react.useEffect;
|
|
33
|
+
|
|
34
|
+
// src/useIsMounted/useIsMounted.ts
|
|
35
|
+
function useIsMounted() {
|
|
36
|
+
const isMounted = (0, import_react2.useRef)(false);
|
|
37
|
+
useSafeLayoutEffect(() => {
|
|
38
|
+
isMounted.current = true;
|
|
39
|
+
return () => {
|
|
40
|
+
isMounted.current = false;
|
|
41
|
+
};
|
|
42
|
+
}, []);
|
|
43
|
+
return isMounted;
|
|
44
|
+
}
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
useIsMounted
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/useIsMounted/index.ts","../../src/useIsMounted/useIsMounted.ts","../../src/useSafeLayoutEffect/useSafeLayoutEffect.ts"],"sourcesContent":["export { useIsMounted } from \"./useIsMounted\";\n","import { useRef } from \"react\";\nimport { useSafeLayoutEffect } from \"../useSafeLayoutEffect\";\n\n/**\n * Why does this work?\n *\n * The following is from the react docs:\n * [The return function from `useLayoutEffect`] is the optional cleanup mechanism for effects.\n * Every effect may return a function that cleans up after it.\n *\n * When exactly does React clean up an effect? React performs the cleanup when the component unmounts.\n * The cleanup for useLayoutEffect is called after component unmounts and before before browser painting\n * the screen\n *\n * What does that mean for us? When this hook is initially loaded, we then trigger a `useLayoutEffect` that\n * sets the isMounted to true right after the component is mounted.\n * When the component unmounts, it calls the cleanup function that sets `isMounted` to false.\n * This `useLayoutEffect` hook will only be run once.\n */\nexport function useIsMounted(): { current: boolean } {\n const isMounted = useRef(false);\n\n useSafeLayoutEffect(() => {\n isMounted.current = true;\n\n return () => {\n isMounted.current = false;\n };\n }, []);\n\n return isMounted;\n}\n","import { useEffect, useLayoutEffect } from \"react\";\n\nexport const useSafeLayoutEffect = globalThis?.document\n ? useLayoutEffect\n : useEffect;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBAAuB;;;ACAvB,mBAA2C;AAEpC,IAAM,uBAAsB,yCAAY,YAC3C,+BACA;;;ADeG,SAAS,eAAqC;AACnD,QAAM,gBAAY,sBAAO,KAAK;AAE9B,sBAAoB,MAAM;AACxB,cAAU,UAAU;AAEpB,WAAO,MAAM;AACX,gBAAU,UAAU;AAAA,IACtB;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;","names":["import_react"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/useIsMounted/useIsMounted.ts","../../src/useSafeLayoutEffect/useSafeLayoutEffect.ts"],"sourcesContent":["import { useRef } from \"react\";\nimport { useSafeLayoutEffect } from \"../useSafeLayoutEffect\";\n\n/**\n * Why does this work?\n *\n * The following is from the react docs:\n * [The return function from `useLayoutEffect`] is the optional cleanup mechanism for effects.\n * Every effect may return a function that cleans up after it.\n *\n * When exactly does React clean up an effect? React performs the cleanup when the component unmounts.\n * The cleanup for useLayoutEffect is called after component unmounts and before before browser painting\n * the screen\n *\n * What does that mean for us? When this hook is initially loaded, we then trigger a `useLayoutEffect` that\n * sets the isMounted to true right after the component is mounted.\n * When the component unmounts, it calls the cleanup function that sets `isMounted` to false.\n * This `useLayoutEffect` hook will only be run once.\n */\nexport function useIsMounted(): { current: boolean } {\n const isMounted = useRef(false);\n\n useSafeLayoutEffect(() => {\n isMounted.current = true;\n\n return () => {\n isMounted.current = false;\n };\n }, []);\n\n return isMounted;\n}\n","import { useEffect, useLayoutEffect } from \"react\";\n\nexport const useSafeLayoutEffect = globalThis?.document\n ? useLayoutEffect\n : useEffect;\n"],"mappings":";AAAA,SAAS,cAAc;;;ACAvB,SAAS,WAAW,uBAAuB;AAEpC,IAAM,uBAAsB,yCAAY,YAC3C,kBACA;;;ADeG,SAAS,eAAqC;AACnD,QAAM,YAAY,OAAO,KAAK;AAE9B,sBAAoB,MAAM;AACxB,cAAU,UAAU;AAEpB,WAAO,MAAM;AACX,gBAAU,UAAU;AAAA,IACtB;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/useLiveAnnounce/index.ts
|
|
21
|
+
var useLiveAnnounce_exports = {};
|
|
22
|
+
__export(useLiveAnnounce_exports, {
|
|
23
|
+
useLiveAnnounce: () => useLiveAnnounce
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(useLiveAnnounce_exports);
|
|
26
|
+
|
|
27
|
+
// src/useLiveAnnounce/useLiveAnnounce.tsx
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
function useLiveAnnounce() {
|
|
30
|
+
const [announcedMessage, setAnnouncedMessage] = (0, import_react.useState)("");
|
|
31
|
+
(0, import_react.useEffect)(() => {
|
|
32
|
+
let target;
|
|
33
|
+
if (announcedMessage) {
|
|
34
|
+
target = createAnnouncedElement();
|
|
35
|
+
setTimeout(() => target.append(announcedMessage), 100);
|
|
36
|
+
}
|
|
37
|
+
return () => target == null ? void 0 : target.remove();
|
|
38
|
+
}, [announcedMessage]);
|
|
39
|
+
return {
|
|
40
|
+
liveAnnounce: (message) => {
|
|
41
|
+
setAnnouncedMessage(message);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function createAnnouncedElement() {
|
|
46
|
+
const el = document.createElement("div");
|
|
47
|
+
el.style.position = "absolute";
|
|
48
|
+
el.style.width = "1px";
|
|
49
|
+
el.style.height = "1px";
|
|
50
|
+
el.style.overflow = "hidden";
|
|
51
|
+
el.style.clipPath = " inset(100%)";
|
|
52
|
+
el.style.whiteSpace = " nowrap";
|
|
53
|
+
el.style.top = "0";
|
|
54
|
+
el.setAttribute("role", "status");
|
|
55
|
+
el.setAttribute("aria-atomic", "true");
|
|
56
|
+
el.setAttribute("aria-live", "assertive");
|
|
57
|
+
document.body.appendChild(el);
|
|
58
|
+
return el;
|
|
59
|
+
}
|
|
60
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
+
0 && (module.exports = {
|
|
62
|
+
useLiveAnnounce
|
|
63
|
+
});
|
|
64
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/useLiveAnnounce/index.ts","../../src/useLiveAnnounce/useLiveAnnounce.tsx"],"sourcesContent":["export { useLiveAnnounce } from \"./useLiveAnnounce\";\n","import { useEffect, useState } from \"react\";\n\n/**\n * Announce a message on voice over whenever you do an action. This is\n * especially helpful when you have an action that adds or deletes an element\n * from the screen.\n */\nexport function useLiveAnnounce() {\n const [announcedMessage, setAnnouncedMessage] = useState(\"\");\n\n useEffect(() => {\n let target: HTMLElement;\n\n if (announcedMessage) {\n target = createAnnouncedElement();\n setTimeout(() => target.append(announcedMessage), 100);\n }\n\n return () => target?.remove();\n }, [announcedMessage]);\n\n return {\n liveAnnounce: (message: string) => {\n setAnnouncedMessage(message);\n },\n };\n}\n\n// eslint-disable-next-line max-statements\nfunction createAnnouncedElement() {\n const el = document.createElement(\"div\");\n\n el.style.position = \"absolute\";\n el.style.width = \"1px\";\n el.style.height = \"1px\";\n el.style.overflow = \"hidden\";\n el.style.clipPath = \" inset(100%)\";\n el.style.whiteSpace = \" nowrap\";\n el.style.top = \"0\";\n el.setAttribute(\"role\", \"status\");\n el.setAttribute(\"aria-atomic\", \"true\");\n el.setAttribute(\"aria-live\", \"assertive\");\n\n document.body.appendChild(el);\n\n return el;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAoC;AAO7B,SAAS,kBAAkB;AAChC,QAAM,CAAC,kBAAkB,mBAAmB,QAAI,uBAAS,EAAE;AAE3D,8BAAU,MAAM;AACd,QAAI;AAEJ,QAAI,kBAAkB;AACpB,eAAS,uBAAuB;AAChC,iBAAW,MAAM,OAAO,OAAO,gBAAgB,GAAG,GAAG;AAAA,IACvD;AAEA,WAAO,MAAM,iCAAQ;AAAA,EACvB,GAAG,CAAC,gBAAgB,CAAC;AAErB,SAAO;AAAA,IACL,cAAc,CAAC,YAAoB;AACjC,0BAAoB,OAAO;AAAA,IAC7B;AAAA,EACF;AACF;AAGA,SAAS,yBAAyB;AAChC,QAAM,KAAK,SAAS,cAAc,KAAK;AAEvC,KAAG,MAAM,WAAW;AACpB,KAAG,MAAM,QAAQ;AACjB,KAAG,MAAM,SAAS;AAClB,KAAG,MAAM,WAAW;AACpB,KAAG,MAAM,WAAW;AACpB,KAAG,MAAM,aAAa;AACtB,KAAG,MAAM,MAAM;AACf,KAAG,aAAa,QAAQ,QAAQ;AAChC,KAAG,aAAa,eAAe,MAAM;AACrC,KAAG,aAAa,aAAa,WAAW;AAExC,WAAS,KAAK,YAAY,EAAE;AAE5B,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/useLiveAnnounce/useLiveAnnounce.tsx"],"sourcesContent":["import { useEffect, useState } from \"react\";\n\n/**\n * Announce a message on voice over whenever you do an action. This is\n * especially helpful when you have an action that adds or deletes an element\n * from the screen.\n */\nexport function useLiveAnnounce() {\n const [announcedMessage, setAnnouncedMessage] = useState(\"\");\n\n useEffect(() => {\n let target: HTMLElement;\n\n if (announcedMessage) {\n target = createAnnouncedElement();\n setTimeout(() => target.append(announcedMessage), 100);\n }\n\n return () => target?.remove();\n }, [announcedMessage]);\n\n return {\n liveAnnounce: (message: string) => {\n setAnnouncedMessage(message);\n },\n };\n}\n\n// eslint-disable-next-line max-statements\nfunction createAnnouncedElement() {\n const el = document.createElement(\"div\");\n\n el.style.position = \"absolute\";\n el.style.width = \"1px\";\n el.style.height = \"1px\";\n el.style.overflow = \"hidden\";\n el.style.clipPath = \" inset(100%)\";\n el.style.whiteSpace = \" nowrap\";\n el.style.top = \"0\";\n el.setAttribute(\"role\", \"status\");\n el.setAttribute(\"aria-atomic\", \"true\");\n el.setAttribute(\"aria-live\", \"assertive\");\n\n document.body.appendChild(el);\n\n return el;\n}\n"],"mappings":";AAAA,SAAS,WAAW,gBAAgB;AAO7B,SAAS,kBAAkB;AAChC,QAAM,CAAC,kBAAkB,mBAAmB,IAAI,SAAS,EAAE;AAE3D,YAAU,MAAM;AACd,QAAI;AAEJ,QAAI,kBAAkB;AACpB,eAAS,uBAAuB;AAChC,iBAAW,MAAM,OAAO,OAAO,gBAAgB,GAAG,GAAG;AAAA,IACvD;AAEA,WAAO,MAAM,iCAAQ;AAAA,EACvB,GAAG,CAAC,gBAAgB,CAAC;AAErB,SAAO;AAAA,IACL,cAAc,CAAC,YAAoB;AACjC,0BAAoB,OAAO;AAAA,IAC7B;AAAA,EACF;AACF;AAGA,SAAS,yBAAyB;AAChC,QAAM,KAAK,SAAS,cAAc,KAAK;AAEvC,KAAG,MAAM,WAAW;AACpB,KAAG,MAAM,QAAQ;AACjB,KAAG,MAAM,SAAS;AAClB,KAAG,MAAM,WAAW;AACpB,KAAG,MAAM,WAAW;AACpB,KAAG,MAAM,aAAa;AACtB,KAAG,MAAM,MAAM;AACf,KAAG,aAAa,QAAQ,QAAQ;AAChC,KAAG,aAAa,eAAe,MAAM;AACrC,KAAG,aAAa,aAAa,WAAW;AAExC,WAAS,KAAK,YAAY,EAAE;AAE5B,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/useOnKeyDown/index.ts
|
|
21
|
+
var useOnKeyDown_exports = {};
|
|
22
|
+
__export(useOnKeyDown_exports, {
|
|
23
|
+
useOnKeyDown: () => useOnKeyDown
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(useOnKeyDown_exports);
|
|
26
|
+
|
|
27
|
+
// src/useOnKeyDown/useOnKeyDown.ts
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
function useOnKeyDown(callback, keys) {
|
|
30
|
+
(0, import_react.useEffect)(() => {
|
|
31
|
+
window.addEventListener("keydown", handler);
|
|
32
|
+
return () => {
|
|
33
|
+
window.removeEventListener("keydown", handler);
|
|
34
|
+
};
|
|
35
|
+
}, [handler]);
|
|
36
|
+
function handler(event) {
|
|
37
|
+
const keyboardEvent = event;
|
|
38
|
+
if (typeof keys === "string" && keyboardEvent.key === keys) {
|
|
39
|
+
callback(event);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (Array.isArray(keys) && keys.some((item) => {
|
|
43
|
+
if (typeof item === "string")
|
|
44
|
+
return keyboardEvent.key === item;
|
|
45
|
+
return Object.keys(item).every(
|
|
46
|
+
(index) => keyboardEvent[index] === item[index]
|
|
47
|
+
);
|
|
48
|
+
})) {
|
|
49
|
+
callback(event);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (!Array.isArray(keys) && typeof keys !== "string" && Object.keys(keys).every((index) => keyboardEvent[index] === keys[index])) {
|
|
53
|
+
callback(event);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
59
|
+
0 && (module.exports = {
|
|
60
|
+
useOnKeyDown
|
|
61
|
+
});
|
|
62
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/useOnKeyDown/index.ts","../../src/useOnKeyDown/useOnKeyDown.ts"],"sourcesContent":["export { useOnKeyDown } from \"./useOnKeyDown\";\n","import { useEffect } from \"react\";\nimport { XOR } from \"ts-xor\";\n\ntype SimpleKeyComparator = KeyboardEvent[\"key\"];\n\ninterface VerboseKeyComparator {\n readonly key: SimpleKeyComparator;\n readonly shiftKey?: boolean;\n readonly ctrlKey?: boolean;\n readonly altKey?: boolean;\n readonly metaKey?: boolean;\n readonly [index: string]: boolean | string | undefined;\n}\n\ntype KeyComparator = XOR<VerboseKeyComparator, SimpleKeyComparator>;\n\nexport function useOnKeyDown(\n callback: (event: KeyboardEvent) => void,\n keys: KeyComparator[] | KeyComparator,\n) {\n useEffect(() => {\n window.addEventListener(\"keydown\", handler);\n\n return () => {\n window.removeEventListener(\"keydown\", handler);\n };\n }, [handler]);\n\n function handler(event: KeyboardEvent) {\n const keyboardEvent = event as unknown as VerboseKeyComparator;\n\n if (typeof keys === \"string\" && keyboardEvent.key === keys) {\n callback(event);\n\n return;\n }\n\n if (\n Array.isArray(keys) &&\n keys.some(item => {\n if (typeof item === \"string\") return keyboardEvent.key === item;\n\n return Object.keys(item).every(\n index => keyboardEvent[index] === item[index],\n );\n })\n ) {\n callback(event);\n\n return;\n }\n\n if (\n !Array.isArray(keys) &&\n typeof keys !== \"string\" &&\n Object.keys(keys).every(index => keyboardEvent[index] === keys[index])\n ) {\n callback(event);\n\n return;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA0B;AAgBnB,SAAS,aACd,UACA,MACA;AACA,8BAAU,MAAM;AACd,WAAO,iBAAiB,WAAW,OAAO;AAE1C,WAAO,MAAM;AACX,aAAO,oBAAoB,WAAW,OAAO;AAAA,IAC/C;AAAA,EACF,GAAG,CAAC,OAAO,CAAC;AAEZ,WAAS,QAAQ,OAAsB;AACrC,UAAM,gBAAgB;AAEtB,QAAI,OAAO,SAAS,YAAY,cAAc,QAAQ,MAAM;AAC1D,eAAS,KAAK;AAEd;AAAA,IACF;AAEA,QACE,MAAM,QAAQ,IAAI,KAClB,KAAK,KAAK,UAAQ;AAChB,UAAI,OAAO,SAAS;AAAU,eAAO,cAAc,QAAQ;AAE3D,aAAO,OAAO,KAAK,IAAI,EAAE;AAAA,QACvB,WAAS,cAAc,KAAK,MAAM,KAAK,KAAK;AAAA,MAC9C;AAAA,IACF,CAAC,GACD;AACA,eAAS,KAAK;AAEd;AAAA,IACF;AAEA,QACE,CAAC,MAAM,QAAQ,IAAI,KACnB,OAAO,SAAS,YAChB,OAAO,KAAK,IAAI,EAAE,MAAM,WAAS,cAAc,KAAK,MAAM,KAAK,KAAK,CAAC,GACrE;AACA,eAAS,KAAK;AAEd;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/useOnKeyDown/useOnKeyDown.ts"],"sourcesContent":["import { useEffect } from \"react\";\nimport { XOR } from \"ts-xor\";\n\ntype SimpleKeyComparator = KeyboardEvent[\"key\"];\n\ninterface VerboseKeyComparator {\n readonly key: SimpleKeyComparator;\n readonly shiftKey?: boolean;\n readonly ctrlKey?: boolean;\n readonly altKey?: boolean;\n readonly metaKey?: boolean;\n readonly [index: string]: boolean | string | undefined;\n}\n\ntype KeyComparator = XOR<VerboseKeyComparator, SimpleKeyComparator>;\n\nexport function useOnKeyDown(\n callback: (event: KeyboardEvent) => void,\n keys: KeyComparator[] | KeyComparator,\n) {\n useEffect(() => {\n window.addEventListener(\"keydown\", handler);\n\n return () => {\n window.removeEventListener(\"keydown\", handler);\n };\n }, [handler]);\n\n function handler(event: KeyboardEvent) {\n const keyboardEvent = event as unknown as VerboseKeyComparator;\n\n if (typeof keys === \"string\" && keyboardEvent.key === keys) {\n callback(event);\n\n return;\n }\n\n if (\n Array.isArray(keys) &&\n keys.some(item => {\n if (typeof item === \"string\") return keyboardEvent.key === item;\n\n return Object.keys(item).every(\n index => keyboardEvent[index] === item[index],\n );\n })\n ) {\n callback(event);\n\n return;\n }\n\n if (\n !Array.isArray(keys) &&\n typeof keys !== \"string\" &&\n Object.keys(keys).every(index => keyboardEvent[index] === keys[index])\n ) {\n callback(event);\n\n return;\n }\n }\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAgBnB,SAAS,aACd,UACA,MACA;AACA,YAAU,MAAM;AACd,WAAO,iBAAiB,WAAW,OAAO;AAE1C,WAAO,MAAM;AACX,aAAO,oBAAoB,WAAW,OAAO;AAAA,IAC/C;AAAA,EACF,GAAG,CAAC,OAAO,CAAC;AAEZ,WAAS,QAAQ,OAAsB;AACrC,UAAM,gBAAgB;AAEtB,QAAI,OAAO,SAAS,YAAY,cAAc,QAAQ,MAAM;AAC1D,eAAS,KAAK;AAEd;AAAA,IACF;AAEA,QACE,MAAM,QAAQ,IAAI,KAClB,KAAK,KAAK,UAAQ;AAChB,UAAI,OAAO,SAAS;AAAU,eAAO,cAAc,QAAQ;AAE3D,aAAO,OAAO,KAAK,IAAI,EAAE;AAAA,QACvB,WAAS,cAAc,KAAK,MAAM,KAAK,KAAK;AAAA,MAC9C;AAAA,IACF,CAAC,GACD;AACA,eAAS,KAAK;AAEd;AAAA,IACF;AAEA,QACE,CAAC,MAAM,QAAQ,IAAI,KACnB,OAAO,SAAS,YAChB,OAAO,KAAK,IAAI,EAAE,MAAM,WAAS,cAAc,KAAK,MAAM,KAAK,KAAK,CAAC,GACrE;AACA,eAAS,KAAK;AAEd;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/usePasswordStrength/index.ts
|
|
31
|
+
var usePasswordStrength_exports = {};
|
|
32
|
+
__export(usePasswordStrength_exports, {
|
|
33
|
+
usePasswordStrength: () => usePasswordStrength
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(usePasswordStrength_exports);
|
|
36
|
+
|
|
37
|
+
// src/usePasswordStrength/usePasswordStrength.ts
|
|
38
|
+
var import_react = require("react");
|
|
39
|
+
var import_zxcvbn = __toESM(require("zxcvbn"), 1);
|
|
40
|
+
function usePasswordStrength(password, dictionary) {
|
|
41
|
+
const {
|
|
42
|
+
guesses,
|
|
43
|
+
score,
|
|
44
|
+
feedback: { warning, suggestions },
|
|
45
|
+
crack_times_display: { offline_fast_hashing_1e10_per_second: timeToCrack }
|
|
46
|
+
} = (0, import_react.useMemo)(
|
|
47
|
+
() => (0, import_zxcvbn.default)(password, dictionary),
|
|
48
|
+
[password, dictionary]
|
|
49
|
+
);
|
|
50
|
+
return {
|
|
51
|
+
guesses,
|
|
52
|
+
score,
|
|
53
|
+
warning,
|
|
54
|
+
suggestions,
|
|
55
|
+
timeToCrack
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
59
|
+
0 && (module.exports = {
|
|
60
|
+
usePasswordStrength
|
|
61
|
+
});
|
|
62
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/usePasswordStrength/index.ts","../../src/usePasswordStrength/usePasswordStrength.ts"],"sourcesContent":["export { usePasswordStrength } from \"./usePasswordStrength\";\n","import { useMemo } from \"react\";\nimport calculateStrength from \"zxcvbn\";\n\nexport function usePasswordStrength(password: string, dictionary?: string[]) {\n const {\n guesses,\n score,\n feedback: { warning, suggestions },\n crack_times_display: { offline_fast_hashing_1e10_per_second: timeToCrack },\n } = useMemo(\n () => calculateStrength(password, dictionary),\n [password, dictionary],\n );\n\n return {\n guesses,\n score,\n warning,\n suggestions,\n timeToCrack,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAwB;AACxB,oBAA8B;AAEvB,SAAS,oBAAoB,UAAkB,YAAuB;AAC3E,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,UAAU,EAAE,SAAS,YAAY;AAAA,IACjC,qBAAqB,EAAE,sCAAsC,YAAY;AAAA,EAC3E,QAAI;AAAA,IACF,UAAM,cAAAA,SAAkB,UAAU,UAAU;AAAA,IAC5C,CAAC,UAAU,UAAU;AAAA,EACvB;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["calculateStrength"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/usePasswordStrength/usePasswordStrength.ts"],"sourcesContent":["import { useMemo } from \"react\";\nimport calculateStrength from \"zxcvbn\";\n\nexport function usePasswordStrength(password: string, dictionary?: string[]) {\n const {\n guesses,\n score,\n feedback: { warning, suggestions },\n crack_times_display: { offline_fast_hashing_1e10_per_second: timeToCrack },\n } = useMemo(\n () => calculateStrength(password, dictionary),\n [password, dictionary],\n );\n\n return {\n guesses,\n score,\n warning,\n suggestions,\n timeToCrack,\n };\n}\n"],"mappings":";AAAA,SAAS,eAAe;AACxB,OAAO,uBAAuB;AAEvB,SAAS,oBAAoB,UAAkB,YAAuB;AAC3E,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,UAAU,EAAE,SAAS,YAAY;AAAA,IACjC,qBAAqB,EAAE,sCAAsC,YAAY;AAAA,EAC3E,IAAI;AAAA,IACF,MAAM,kBAAkB,UAAU,UAAU;AAAA,IAC5C,CAAC,UAAU,UAAU;AAAA,EACvB;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/useRefocusOnActivator/index.ts
|
|
21
|
+
var useRefocusOnActivator_exports = {};
|
|
22
|
+
__export(useRefocusOnActivator_exports, {
|
|
23
|
+
useRefocusOnActivator: () => useRefocusOnActivator
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(useRefocusOnActivator_exports);
|
|
26
|
+
|
|
27
|
+
// src/useRefocusOnActivator/useRefocusOnActivator.ts
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
function useRefocusOnActivator(active) {
|
|
30
|
+
(0, import_react.useEffect)(() => {
|
|
31
|
+
let activator;
|
|
32
|
+
if (active && !activator) {
|
|
33
|
+
activator = document.activeElement;
|
|
34
|
+
}
|
|
35
|
+
return () => {
|
|
36
|
+
if (active) {
|
|
37
|
+
if (activator instanceof HTMLElement) {
|
|
38
|
+
activator.focus();
|
|
39
|
+
}
|
|
40
|
+
activator = void 0;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}, [active]);
|
|
44
|
+
}
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
useRefocusOnActivator
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/useRefocusOnActivator/index.ts","../../src/useRefocusOnActivator/useRefocusOnActivator.ts"],"sourcesContent":["export { useRefocusOnActivator } from \"./useRefocusOnActivator\";\n","import { useEffect } from \"react\";\n\n/**\n * Brings back the focus to the element that opened an overlaid element once\n * said overlaid element is dismissed.\n *\n * @param active - Determines if it should focus or not\n */\nexport function useRefocusOnActivator(active: boolean) {\n useEffect(() => {\n let activator: Element | null | undefined;\n\n if (active && !activator) {\n activator = document.activeElement;\n }\n\n return () => {\n if (active) {\n if (activator instanceof HTMLElement) {\n activator.focus();\n }\n activator = undefined;\n }\n };\n }, [active]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA0B;AAQnB,SAAS,sBAAsB,QAAiB;AACrD,8BAAU,MAAM;AACd,QAAI;AAEJ,QAAI,UAAU,CAAC,WAAW;AACxB,kBAAY,SAAS;AAAA,IACvB;AAEA,WAAO,MAAM;AACX,UAAI,QAAQ;AACV,YAAI,qBAAqB,aAAa;AACpC,oBAAU,MAAM;AAAA,QAClB;AACA,oBAAY;AAAA,MACd;AAAA,IACF;AAAA,EACF,GAAG,CAAC,MAAM,CAAC;AACb;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/useRefocusOnActivator/useRefocusOnActivator.ts"],"sourcesContent":["import { useEffect } from \"react\";\n\n/**\n * Brings back the focus to the element that opened an overlaid element once\n * said overlaid element is dismissed.\n *\n * @param active - Determines if it should focus or not\n */\nexport function useRefocusOnActivator(active: boolean) {\n useEffect(() => {\n let activator: Element | null | undefined;\n\n if (active && !activator) {\n activator = document.activeElement;\n }\n\n return () => {\n if (active) {\n if (activator instanceof HTMLElement) {\n activator.focus();\n }\n activator = undefined;\n }\n };\n }, [active]);\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAQnB,SAAS,sBAAsB,QAAiB;AACrD,YAAU,MAAM;AACd,QAAI;AAEJ,QAAI,UAAU,CAAC,WAAW;AACxB,kBAAY,SAAS;AAAA,IACvB;AAEA,WAAO,MAAM;AACX,UAAI,QAAQ;AACV,YAAI,qBAAqB,aAAa;AACpC,oBAAU,MAAM;AAAA,QAClB;AACA,oBAAY;AAAA,MACd;AAAA,IACF;AAAA,EACF,GAAG,CAAC,MAAM,CAAC;AACb;","names":[]}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/useResizeObserver/index.ts
|
|
31
|
+
var useResizeObserver_exports = {};
|
|
32
|
+
__export(useResizeObserver_exports, {
|
|
33
|
+
Breakpoints: () => Breakpoints,
|
|
34
|
+
useResizeObserver: () => useResizeObserver
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(useResizeObserver_exports);
|
|
37
|
+
|
|
38
|
+
// src/useResizeObserver/useResizeObserver.ts
|
|
39
|
+
var import_react = require("react");
|
|
40
|
+
var import_polyfilled = __toESM(require("use-resize-observer/polyfilled"), 1);
|
|
41
|
+
var import_lodash = require("lodash");
|
|
42
|
+
var Breakpoints = {
|
|
43
|
+
base: 640,
|
|
44
|
+
small: 500,
|
|
45
|
+
smaller: 265,
|
|
46
|
+
large: 750,
|
|
47
|
+
larger: 1024
|
|
48
|
+
};
|
|
49
|
+
var wait = 100;
|
|
50
|
+
function useResizeObserver({
|
|
51
|
+
widths = Breakpoints,
|
|
52
|
+
heights = Breakpoints
|
|
53
|
+
} = {}) {
|
|
54
|
+
const [exactSize, setSize] = (0, import_react.useState)({
|
|
55
|
+
width: void 0,
|
|
56
|
+
height: void 0
|
|
57
|
+
});
|
|
58
|
+
const onResize = (0, import_react.useMemo)(() => (0, import_lodash.throttle)(setSize, wait), [wait]);
|
|
59
|
+
const { ref } = (0, import_polyfilled.default)({
|
|
60
|
+
onResize
|
|
61
|
+
});
|
|
62
|
+
const exactWidth = exactSize.width;
|
|
63
|
+
const exactHeight = exactSize.height;
|
|
64
|
+
const sizes = {
|
|
65
|
+
width: getSize(widths, exactSize.width),
|
|
66
|
+
height: getSize(heights, exactSize.height),
|
|
67
|
+
exactWidth,
|
|
68
|
+
exactHeight
|
|
69
|
+
};
|
|
70
|
+
return [ref, sizes];
|
|
71
|
+
}
|
|
72
|
+
function getSize(sizes, comparable) {
|
|
73
|
+
if (!comparable || !sizes) {
|
|
74
|
+
return void 0;
|
|
75
|
+
}
|
|
76
|
+
const sortedSizes = Object.values(sizes).sort((a, b) => a - b).reverse();
|
|
77
|
+
return sortedSizes.find((value) => value <= comparable) || sortedSizes[sortedSizes.length - 1];
|
|
78
|
+
}
|
|
79
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
80
|
+
0 && (module.exports = {
|
|
81
|
+
Breakpoints,
|
|
82
|
+
useResizeObserver
|
|
83
|
+
});
|
|
84
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/useResizeObserver/index.ts","../../src/useResizeObserver/useResizeObserver.ts"],"sourcesContent":["export * from \"./useResizeObserver\";\n","import { useMemo, useState } from \"react\";\n// Importing the polyfilled version of ResizeObserver\n// eslint-disable-next-line import/no-internal-modules\nimport useResizeObserverPackage from \"use-resize-observer/polyfilled\";\nimport { throttle } from \"lodash\";\n\nexport const Breakpoints = {\n base: 640,\n small: 500,\n smaller: 265,\n large: 750,\n larger: 1024,\n};\n\ninterface ObservedSize {\n width: number | undefined;\n height: number | undefined;\n}\n\ninterface ResizeObserverProps {\n widths?: object;\n heights?: object;\n}\n\nconst wait = 100;\n\nexport function useResizeObserver<T extends HTMLElement>({\n widths = Breakpoints,\n heights = Breakpoints,\n}: ResizeObserverProps = {}) {\n const [exactSize, setSize] = useState<ObservedSize>({\n width: undefined,\n height: undefined,\n });\n const onResize = useMemo(() => throttle(setSize, wait), [wait]);\n const { ref } = useResizeObserverPackage<T>({\n onResize,\n });\n\n const exactWidth = exactSize.width;\n const exactHeight = exactSize.height;\n\n const sizes = {\n width: getSize(widths, exactSize.width),\n height: getSize(heights, exactSize.height),\n exactWidth,\n exactHeight,\n };\n\n return [ref, sizes] as const;\n}\n\n/**\n * To get the proper size we want to make sure that our value is greater\n * then the comparable, but less then the next largest number in our\n * object.\n */\nfunction getSize(\n sizes: object,\n comparable: number | undefined,\n): number | undefined {\n if (!comparable || !sizes) {\n return undefined;\n }\n\n /**\n * Sort the values of our object so that we know they are in proper\n * order to be compared by\n */\n const sortedSizes = Object.values(sizes)\n .sort((a, b) => a - b)\n .reverse();\n\n return (\n sortedSizes.find(value => value <= comparable) ||\n sortedSizes[sortedSizes.length - 1]\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAkC;AAGlC,wBAAqC;AACrC,oBAAyB;AAElB,IAAM,cAAc;AAAA,EACzB,MAAM;AAAA,EACN,OAAO;AAAA,EACP,SAAS;AAAA,EACT,OAAO;AAAA,EACP,QAAQ;AACV;AAYA,IAAM,OAAO;AAEN,SAAS,kBAAyC;AAAA,EACvD,SAAS;AAAA,EACT,UAAU;AACZ,IAAyB,CAAC,GAAG;AAC3B,QAAM,CAAC,WAAW,OAAO,QAAI,uBAAuB;AAAA,IAClD,OAAO;AAAA,IACP,QAAQ;AAAA,EACV,CAAC;AACD,QAAM,eAAW,sBAAQ,UAAM,wBAAS,SAAS,IAAI,GAAG,CAAC,IAAI,CAAC;AAC9D,QAAM,EAAE,IAAI,QAAI,kBAAAA,SAA4B;AAAA,IAC1C;AAAA,EACF,CAAC;AAED,QAAM,aAAa,UAAU;AAC7B,QAAM,cAAc,UAAU;AAE9B,QAAM,QAAQ;AAAA,IACZ,OAAO,QAAQ,QAAQ,UAAU,KAAK;AAAA,IACtC,QAAQ,QAAQ,SAAS,UAAU,MAAM;AAAA,IACzC;AAAA,IACA;AAAA,EACF;AAEA,SAAO,CAAC,KAAK,KAAK;AACpB;AAOA,SAAS,QACP,OACA,YACoB;AACpB,MAAI,CAAC,cAAc,CAAC,OAAO;AACzB,WAAO;AAAA,EACT;AAMA,QAAM,cAAc,OAAO,OAAO,KAAK,EACpC,KAAK,CAAC,GAAG,MAAM,IAAI,CAAC,EACpB,QAAQ;AAEX,SACE,YAAY,KAAK,WAAS,SAAS,UAAU,KAC7C,YAAY,YAAY,SAAS,CAAC;AAEtC;","names":["useResizeObserverPackage"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/useResizeObserver/useResizeObserver.ts"],"sourcesContent":["import { useMemo, useState } from \"react\";\n// Importing the polyfilled version of ResizeObserver\n// eslint-disable-next-line import/no-internal-modules\nimport useResizeObserverPackage from \"use-resize-observer/polyfilled\";\nimport { throttle } from \"lodash\";\n\nexport const Breakpoints = {\n base: 640,\n small: 500,\n smaller: 265,\n large: 750,\n larger: 1024,\n};\n\ninterface ObservedSize {\n width: number | undefined;\n height: number | undefined;\n}\n\ninterface ResizeObserverProps {\n widths?: object;\n heights?: object;\n}\n\nconst wait = 100;\n\nexport function useResizeObserver<T extends HTMLElement>({\n widths = Breakpoints,\n heights = Breakpoints,\n}: ResizeObserverProps = {}) {\n const [exactSize, setSize] = useState<ObservedSize>({\n width: undefined,\n height: undefined,\n });\n const onResize = useMemo(() => throttle(setSize, wait), [wait]);\n const { ref } = useResizeObserverPackage<T>({\n onResize,\n });\n\n const exactWidth = exactSize.width;\n const exactHeight = exactSize.height;\n\n const sizes = {\n width: getSize(widths, exactSize.width),\n height: getSize(heights, exactSize.height),\n exactWidth,\n exactHeight,\n };\n\n return [ref, sizes] as const;\n}\n\n/**\n * To get the proper size we want to make sure that our value is greater\n * then the comparable, but less then the next largest number in our\n * object.\n */\nfunction getSize(\n sizes: object,\n comparable: number | undefined,\n): number | undefined {\n if (!comparable || !sizes) {\n return undefined;\n }\n\n /**\n * Sort the values of our object so that we know they are in proper\n * order to be compared by\n */\n const sortedSizes = Object.values(sizes)\n .sort((a, b) => a - b)\n .reverse();\n\n return (\n sortedSizes.find(value => value <= comparable) ||\n sortedSizes[sortedSizes.length - 1]\n );\n}\n"],"mappings":";AAAA,SAAS,SAAS,gBAAgB;AAGlC,OAAO,8BAA8B;AACrC,SAAS,gBAAgB;AAElB,IAAM,cAAc;AAAA,EACzB,MAAM;AAAA,EACN,OAAO;AAAA,EACP,SAAS;AAAA,EACT,OAAO;AAAA,EACP,QAAQ;AACV;AAYA,IAAM,OAAO;AAEN,SAAS,kBAAyC;AAAA,EACvD,SAAS;AAAA,EACT,UAAU;AACZ,IAAyB,CAAC,GAAG;AAC3B,QAAM,CAAC,WAAW,OAAO,IAAI,SAAuB;AAAA,IAClD,OAAO;AAAA,IACP,QAAQ;AAAA,EACV,CAAC;AACD,QAAM,WAAW,QAAQ,MAAM,SAAS,SAAS,IAAI,GAAG,CAAC,IAAI,CAAC;AAC9D,QAAM,EAAE,IAAI,IAAI,yBAA4B;AAAA,IAC1C;AAAA,EACF,CAAC;AAED,QAAM,aAAa,UAAU;AAC7B,QAAM,cAAc,UAAU;AAE9B,QAAM,QAAQ;AAAA,IACZ,OAAO,QAAQ,QAAQ,UAAU,KAAK;AAAA,IACtC,QAAQ,QAAQ,SAAS,UAAU,MAAM;AAAA,IACzC;AAAA,IACA;AAAA,EACF;AAEA,SAAO,CAAC,KAAK,KAAK;AACpB;AAOA,SAAS,QACP,OACA,YACoB;AACpB,MAAI,CAAC,cAAc,CAAC,OAAO;AACzB,WAAO;AAAA,EACT;AAMA,QAAM,cAAc,OAAO,OAAO,KAAK,EACpC,KAAK,CAAC,GAAG,MAAM,IAAI,CAAC,EACpB,QAAQ;AAEX,SACE,YAAY,KAAK,WAAS,SAAS,UAAU,KAC7C,YAAY,YAAY,SAAS,CAAC;AAEtC;","names":[]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/useSafeLayoutEffect/index.ts
|
|
21
|
+
var useSafeLayoutEffect_exports = {};
|
|
22
|
+
__export(useSafeLayoutEffect_exports, {
|
|
23
|
+
useSafeLayoutEffect: () => useSafeLayoutEffect
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(useSafeLayoutEffect_exports);
|
|
26
|
+
|
|
27
|
+
// src/useSafeLayoutEffect/useSafeLayoutEffect.ts
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
var useSafeLayoutEffect = (globalThis == null ? void 0 : globalThis.document) ? import_react.useLayoutEffect : import_react.useEffect;
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
useSafeLayoutEffect
|
|
33
|
+
});
|
|
34
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/useSafeLayoutEffect/index.ts","../../src/useSafeLayoutEffect/useSafeLayoutEffect.ts"],"sourcesContent":["export { useSafeLayoutEffect } from \"./useSafeLayoutEffect\";\n","import { useEffect, useLayoutEffect } from \"react\";\n\nexport const useSafeLayoutEffect = globalThis?.document\n ? useLayoutEffect\n : useEffect;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA2C;AAEpC,IAAM,uBAAsB,yCAAY,YAC3C,+BACA;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/useSafeLayoutEffect/useSafeLayoutEffect.ts"],"sourcesContent":["import { useEffect, useLayoutEffect } from \"react\";\n\nexport const useSafeLayoutEffect = globalThis?.document\n ? useLayoutEffect\n : useEffect;\n"],"mappings":";AAAA,SAAS,WAAW,uBAAuB;AAEpC,IAAM,uBAAsB,yCAAY,YAC3C,kBACA;","names":[]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/useShowClear/index.ts
|
|
21
|
+
var useShowClear_exports = {};
|
|
22
|
+
__export(useShowClear_exports, {
|
|
23
|
+
useShowClear: () => useShowClear
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(useShowClear_exports);
|
|
26
|
+
|
|
27
|
+
// src/useShowClear/useShowClear.ts
|
|
28
|
+
function useShowClear({
|
|
29
|
+
clearable,
|
|
30
|
+
multiline,
|
|
31
|
+
focused,
|
|
32
|
+
hasValue,
|
|
33
|
+
disabled = false
|
|
34
|
+
}) {
|
|
35
|
+
if (multiline && clearable !== "never") {
|
|
36
|
+
throw new Error("Multiline inputs can not be clearable");
|
|
37
|
+
}
|
|
38
|
+
if (!hasValue || clearable === "never" || disabled) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
switch (clearable) {
|
|
42
|
+
case "while-editing":
|
|
43
|
+
return focused;
|
|
44
|
+
case "always":
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
+
0 && (module.exports = {
|
|
50
|
+
useShowClear
|
|
51
|
+
});
|
|
52
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/useShowClear/index.ts","../../src/useShowClear/useShowClear.ts"],"sourcesContent":["export { useShowClear, Clearable } from \"./useShowClear\";\n","export type Clearable = \"never\" | \"while-editing\" | \"always\";\n\ninterface UseShowClearParameters {\n clearable: Clearable;\n multiline: boolean;\n focused: boolean;\n hasValue: boolean;\n disabled?: boolean;\n}\n\nexport function useShowClear({\n clearable,\n multiline,\n focused,\n hasValue,\n disabled = false,\n}: UseShowClearParameters): boolean | undefined {\n if (multiline && clearable !== \"never\") {\n throw new Error(\"Multiline inputs can not be clearable\");\n }\n\n // Do not show if there is no value\n if (!hasValue || clearable === \"never\" || disabled) {\n return false;\n }\n\n switch (clearable) {\n case \"while-editing\":\n return focused;\n case \"always\":\n return true;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACUO,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AACb,GAAgD;AAC9C,MAAI,aAAa,cAAc,SAAS;AACtC,UAAM,IAAI,MAAM,uCAAuC;AAAA,EACzD;AAGA,MAAI,CAAC,YAAY,cAAc,WAAW,UAAU;AAClD,WAAO;AAAA,EACT;AAEA,UAAQ,WAAW;AAAA,IACjB,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,EACX;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/useShowClear/useShowClear.ts"],"sourcesContent":["export type Clearable = \"never\" | \"while-editing\" | \"always\";\n\ninterface UseShowClearParameters {\n clearable: Clearable;\n multiline: boolean;\n focused: boolean;\n hasValue: boolean;\n disabled?: boolean;\n}\n\nexport function useShowClear({\n clearable,\n multiline,\n focused,\n hasValue,\n disabled = false,\n}: UseShowClearParameters): boolean | undefined {\n if (multiline && clearable !== \"never\") {\n throw new Error(\"Multiline inputs can not be clearable\");\n }\n\n // Do not show if there is no value\n if (!hasValue || clearable === \"never\" || disabled) {\n return false;\n }\n\n switch (clearable) {\n case \"while-editing\":\n return focused;\n case \"always\":\n return true;\n }\n}\n"],"mappings":";AAUO,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AACb,GAAgD;AAC9C,MAAI,aAAa,cAAc,SAAS;AACtC,UAAM,IAAI,MAAM,uCAAuC;AAAA,EACzD;AAGA,MAAI,CAAC,YAAY,cAAc,WAAW,UAAU;AAClD,WAAO;AAAA,EACT;AAEA,UAAQ,WAAW;AAAA,IACjB,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,EACX;AACF;","names":[]}
|