piral-hooks-utils 1.6.0-beta.7216 → 1.6.0-beta.7243
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/lib/contexts/PiletApiProvider.js +2 -5
- package/lib/contexts/PiletApiProvider.js.map +1 -1
- package/lib/contexts/index.js +1 -4
- package/lib/contexts/index.js.map +1 -1
- package/lib/hocs/index.js +1 -4
- package/lib/hocs/index.js.map +1 -1
- package/lib/hocs/withProvider.js +4 -8
- package/lib/hocs/withProvider.js.map +1 -1
- package/lib/hooks/afterVisible.js +6 -10
- package/lib/hooks/afterVisible.js.map +1 -1
- package/lib/hooks/asyncReplace.js +4 -8
- package/lib/hooks/asyncReplace.js.map +1 -1
- package/lib/hooks/index.js +7 -10
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/lockBodyScroll.js +3 -7
- package/lib/hooks/lockBodyScroll.js.map +1 -1
- package/lib/hooks/onClickOutside.js +3 -7
- package/lib/hooks/onClickOutside.js.map +1 -1
- package/lib/hooks/onScreenVisible.js +4 -8
- package/lib/hooks/onScreenVisible.js.map +1 -1
- package/lib/hooks/piletApi.js +4 -8
- package/lib/hooks/piletApi.js.map +1 -1
- package/lib/hooks/prompt.js +3 -7
- package/lib/hooks/prompt.js.map +1 -1
- package/lib/index.js +3 -6
- package/lib/index.js.map +1 -1
- package/package.json +7 -21
- package/esm/contexts/PiletApiProvider.d.ts +0 -2
- package/esm/contexts/PiletApiProvider.js +0 -3
- package/esm/contexts/PiletApiProvider.js.map +0 -1
- package/esm/contexts/index.d.ts +0 -1
- package/esm/contexts/index.js +0 -2
- package/esm/contexts/index.js.map +0 -1
- package/esm/hocs/index.d.ts +0 -1
- package/esm/hocs/index.js +0 -2
- package/esm/hocs/index.js.map +0 -1
- package/esm/hocs/withProvider.d.ts +0 -15
- package/esm/hocs/withProvider.js +0 -13
- package/esm/hocs/withProvider.js.map +0 -1
- package/esm/hooks/afterVisible.d.ts +0 -8
- package/esm/hooks/afterVisible.js +0 -26
- package/esm/hooks/afterVisible.js.map +0 -1
- package/esm/hooks/asyncReplace.d.ts +0 -7
- package/esm/hooks/asyncReplace.js +0 -21
- package/esm/hooks/asyncReplace.js.map +0 -1
- package/esm/hooks/index.d.ts +0 -7
- package/esm/hooks/index.js +0 -8
- package/esm/hooks/index.js.map +0 -1
- package/esm/hooks/lockBodyScroll.d.ts +0 -6
- package/esm/hooks/lockBodyScroll.js +0 -15
- package/esm/hooks/lockBodyScroll.js.map +0 -1
- package/esm/hooks/onClickOutside.d.ts +0 -8
- package/esm/hooks/onClickOutside.js +0 -23
- package/esm/hooks/onClickOutside.js.map +0 -1
- package/esm/hooks/onScreenVisible.d.ts +0 -11
- package/esm/hooks/onScreenVisible.js +0 -24
- package/esm/hooks/onScreenVisible.js.map +0 -1
- package/esm/hooks/piletApi.d.ts +0 -7
- package/esm/hooks/piletApi.js +0 -12
- package/esm/hooks/piletApi.js.map +0 -1
- package/esm/hooks/prompt.d.ts +0 -9
- package/esm/hooks/prompt.js +0 -28
- package/esm/hooks/prompt.js.map +0 -1
- package/esm/index.d.ts +0 -3
- package/esm/index.js +0 -4
- package/esm/index.js.map +0 -1
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.PiletApiProvider = void 0;
|
|
4
|
-
const React = require("react");
|
|
5
|
-
exports.PiletApiProvider = React.createContext(undefined);
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export const PiletApiProvider = React.createContext(undefined);
|
|
6
3
|
//# sourceMappingURL=PiletApiProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PiletApiProvider.js","sourceRoot":"","sources":["../../src/contexts/PiletApiProvider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PiletApiProvider.js","sourceRoot":"","sources":["../../src/contexts/PiletApiProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAC,aAAa,CAAM,SAAS,CAAC,CAAC"}
|
package/lib/contexts/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/contexts/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/contexts/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
|
package/lib/hocs/index.js
CHANGED
package/lib/hocs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hocs/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hocs/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
package/lib/hocs/withProvider.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.withPiletApi = void 0;
|
|
4
|
-
const React = require("react");
|
|
5
|
-
const contexts_1 = require("../contexts");
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { PiletApiProvider } from '../contexts';
|
|
6
3
|
/**
|
|
7
4
|
* Wraps the component in a Pilet API provider allowing to make use of
|
|
8
5
|
* the `usePilet` hook.
|
|
9
6
|
* @param Component The component that should be wrapped in a provider.
|
|
10
7
|
* @returns The wrapped component.
|
|
11
8
|
*/
|
|
12
|
-
function withPiletApi(Component) {
|
|
13
|
-
return (props) => (React.createElement(
|
|
9
|
+
export function withPiletApi(Component) {
|
|
10
|
+
return (props) => (React.createElement(PiletApiProvider.Provider, { value: props.piral },
|
|
14
11
|
React.createElement(Component, { ...props })));
|
|
15
12
|
}
|
|
16
|
-
exports.withPiletApi = withPiletApi;
|
|
17
13
|
//# sourceMappingURL=withProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withProvider.js","sourceRoot":"","sources":["../../src/hocs/withProvider.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"withProvider.js","sourceRoot":"","sources":["../../src/hocs/withProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAS/C;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAI,SAAsB;IACpD,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAChB,oBAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,CAAC,KAAK;QAC3C,oBAAC,SAAS,OAAK,KAAK,GAAI,CACE,CAC7B,CAAC;AACJ,CAAC"}
|
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useAfterVisible = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
1
|
+
import { useState, useEffect, useRef } from 'react';
|
|
5
2
|
/**
|
|
6
3
|
* A hook to indicate something was suddenly visible.
|
|
7
4
|
* @param time The time after which it should be triggered.
|
|
8
5
|
* @param cb The callback to use when the part was visible.
|
|
9
6
|
* @returns The reference to the element which should be watched.
|
|
10
7
|
*/
|
|
11
|
-
function useAfterVisible(time, cb) {
|
|
12
|
-
const ref =
|
|
13
|
-
const [intersecting, setIntersecting] =
|
|
14
|
-
|
|
8
|
+
export function useAfterVisible(time, cb) {
|
|
9
|
+
const ref = useRef(null);
|
|
10
|
+
const [intersecting, setIntersecting] = useState(false);
|
|
11
|
+
useEffect(() => {
|
|
15
12
|
const observer = new IntersectionObserver((ev) => {
|
|
16
13
|
setIntersecting(ev.some((m) => m.isIntersecting));
|
|
17
14
|
});
|
|
18
15
|
observer.observe(ref.current);
|
|
19
16
|
return () => observer.disconnect();
|
|
20
17
|
}, [ref.current]);
|
|
21
|
-
|
|
18
|
+
useEffect(() => {
|
|
22
19
|
if (intersecting) {
|
|
23
20
|
const tid = setTimeout(cb, time);
|
|
24
21
|
return () => clearTimeout(tid);
|
|
@@ -26,5 +23,4 @@ function useAfterVisible(time, cb) {
|
|
|
26
23
|
}, [intersecting, cb]);
|
|
27
24
|
return ref;
|
|
28
25
|
}
|
|
29
|
-
exports.useAfterVisible = useAfterVisible;
|
|
30
26
|
//# sourceMappingURL=afterVisible.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"afterVisible.js","sourceRoot":"","sources":["../../src/hooks/afterVisible.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"afterVisible.js","sourceRoot":"","sources":["../../src/hooks/afterVisible.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY,EAAE,EAAc;IAC1D,MAAM,GAAG,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IACzC,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAExD,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,QAAQ,GAAG,IAAI,oBAAoB,CAAC,CAAC,EAAE,EAAE,EAAE;YAC/C,eAAe,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;QACH,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC9B,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;IACrC,CAAC,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;IAElB,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,YAAY,EAAE;YAChB,MAAM,GAAG,GAAG,UAAU,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;YACjC,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;SAChC;IACH,CAAC,EAAE,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,CAAC;IAEvB,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useAsyncReplace = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
5
2
|
/**
|
|
6
3
|
* Gives a full async lifecycle in a hook.
|
|
7
4
|
* @param action The lazy loader.
|
|
8
5
|
* @param resolve The resolve function getting the result from the promise.
|
|
9
6
|
* @returns The current executing state, and the trigger to start the async operation.
|
|
10
7
|
*/
|
|
11
|
-
function useAsyncReplace(action, resolve = () => { }) {
|
|
12
|
-
const [executing, setExecuting] =
|
|
8
|
+
export function useAsyncReplace(action, resolve = () => { }) {
|
|
9
|
+
const [executing, setExecuting] = useState(false);
|
|
13
10
|
const error = executing instanceof Error ? executing : undefined;
|
|
14
|
-
|
|
11
|
+
useEffect(() => {
|
|
15
12
|
if (executing === true) {
|
|
16
13
|
let active = true;
|
|
17
14
|
action().then((result) => active && resolve(result), (err) => active && setExecuting(err));
|
|
@@ -21,5 +18,4 @@ function useAsyncReplace(action, resolve = () => { }) {
|
|
|
21
18
|
}, [executing]);
|
|
22
19
|
return [executing === true, () => setExecuting(true), error];
|
|
23
20
|
}
|
|
24
|
-
exports.useAsyncReplace = useAsyncReplace;
|
|
25
21
|
//# sourceMappingURL=asyncReplace.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asyncReplace.js","sourceRoot":"","sources":["../../src/hooks/asyncReplace.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"asyncReplace.js","sourceRoot":"","sources":["../../src/hooks/asyncReplace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAE5C;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAC7B,MAAwB,EACxB,UAA+B,GAAG,EAAE,GAAE,CAAC;IAEvC,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAkB,KAAK,CAAC,CAAC;IACnE,MAAM,KAAK,GAAG,SAAS,YAAY,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;IAEjE,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,SAAS,KAAK,IAAI,EAAE;YACtB,IAAI,MAAM,GAAG,IAAI,CAAC;YAElB,MAAM,EAAE,CAAC,IAAI,CACX,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,EACrC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,IAAI,YAAY,CAAC,GAAG,CAAC,CACrC,CAAC;YAEF,OAAO,GAAG,EAAE,CAAC,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC;SAC/B;QAED,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;IAClB,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhB,OAAO,CAAC,SAAS,KAAK,IAAI,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;AAC/D,CAAC"}
|
package/lib/hooks/index.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
tslib_1.__exportStar(require("./onScreenVisible"), exports);
|
|
9
|
-
tslib_1.__exportStar(require("./piletApi"), exports);
|
|
10
|
-
tslib_1.__exportStar(require("./prompt"), exports);
|
|
1
|
+
export * from './afterVisible';
|
|
2
|
+
export * from './asyncReplace';
|
|
3
|
+
export * from './lockBodyScroll';
|
|
4
|
+
export * from './onClickOutside';
|
|
5
|
+
export * from './onScreenVisible';
|
|
6
|
+
export * from './piletApi';
|
|
7
|
+
export * from './prompt';
|
|
11
8
|
//# sourceMappingURL=index.js.map
|
package/lib/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC"}
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useLockBodyScroll = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
1
|
+
import { useLayoutEffect } from 'react';
|
|
5
2
|
/**
|
|
6
3
|
* Hook that locks scrolling on the main document.
|
|
7
4
|
* Useful for preventing the standard scrolling in context of
|
|
8
5
|
* a modal dialog.
|
|
9
6
|
*/
|
|
10
|
-
function useLockBodyScroll() {
|
|
11
|
-
|
|
7
|
+
export function useLockBodyScroll() {
|
|
8
|
+
useLayoutEffect(() => {
|
|
12
9
|
document.body.style.overflow = 'hidden';
|
|
13
10
|
return () => {
|
|
14
11
|
document.body.style.overflow = 'visible';
|
|
15
12
|
};
|
|
16
13
|
}, []);
|
|
17
14
|
}
|
|
18
|
-
exports.useLockBodyScroll = useLockBodyScroll;
|
|
19
15
|
//# sourceMappingURL=lockBodyScroll.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lockBodyScroll.js","sourceRoot":"","sources":["../../src/hooks/lockBodyScroll.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lockBodyScroll.js","sourceRoot":"","sources":["../../src/hooks/lockBodyScroll.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAExC;;;;GAIG;AACH,MAAM,UAAU,iBAAiB;IAC/B,eAAe,CAAC,GAAG,EAAE;QACnB,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACxC,OAAO,GAAG,EAAE;YACV,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,SAAS,CAAC;QAC3C,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC"}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useOnClickOutside = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
1
|
+
import { useEffect } from 'react';
|
|
5
2
|
/**
|
|
6
3
|
* Hook that detects if a click outside the given reference
|
|
7
4
|
* has been performed.
|
|
8
5
|
* @param ref The reference to the element.
|
|
9
6
|
* @param handler The callback to invoke when an outside click happened.
|
|
10
7
|
*/
|
|
11
|
-
function useOnClickOutside(ref, handler) {
|
|
12
|
-
|
|
8
|
+
export function useOnClickOutside(ref, handler) {
|
|
9
|
+
useEffect(() => {
|
|
13
10
|
const listener = (event) => {
|
|
14
11
|
if (ref.current && !ref.current.contains(event.target)) {
|
|
15
12
|
handler(event);
|
|
@@ -23,5 +20,4 @@ function useOnClickOutside(ref, handler) {
|
|
|
23
20
|
};
|
|
24
21
|
}, [handler]);
|
|
25
22
|
}
|
|
26
|
-
exports.useOnClickOutside = useOnClickOutside;
|
|
27
23
|
//# sourceMappingURL=onClickOutside.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onClickOutside.js","sourceRoot":"","sources":["../../src/hooks/onClickOutside.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"onClickOutside.js","sourceRoot":"","sources":["../../src/hooks/onClickOutside.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAa,MAAM,OAAO,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAwB,GAAiB,EAAE,OAAoC;IAC9G,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,QAAQ,GAAG,CAAC,KAAiB,EAAE,EAAE;YACrC,IAAI,GAAG,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAc,CAAC,EAAE;gBAC9D,OAAO,CAAC,KAAK,CAAC,CAAC;aAChB;QACH,CAAC,CAAC;QAEF,QAAQ,CAAC,gBAAgB,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;QACjD,QAAQ,CAAC,gBAAgB,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QAElD,OAAO,GAAG,EAAE;YACV,QAAQ,CAAC,mBAAmB,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;YACpD,QAAQ,CAAC,mBAAmB,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QACvD,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;AAChB,CAAC"}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useOnScreenVisible = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
5
2
|
/**
|
|
6
3
|
* Hook that detects if a reference element within the main document is
|
|
7
4
|
* visible.
|
|
@@ -11,9 +8,9 @@ const react_1 = require("react");
|
|
|
11
8
|
* @param ref The reference element to be visible.
|
|
12
9
|
* @param rootMargin The tolerance level to the reference element.
|
|
13
10
|
*/
|
|
14
|
-
function useOnScreenVisible(ref, rootMargin = '0px') {
|
|
15
|
-
const [isIntersecting, setIntersecting] =
|
|
16
|
-
|
|
11
|
+
export function useOnScreenVisible(ref, rootMargin = '0px') {
|
|
12
|
+
const [isIntersecting, setIntersecting] = useState(false);
|
|
13
|
+
useEffect(() => {
|
|
17
14
|
const observer = new IntersectionObserver(([entry]) => setIntersecting(entry.isIntersecting), {
|
|
18
15
|
rootMargin,
|
|
19
16
|
});
|
|
@@ -24,5 +21,4 @@ function useOnScreenVisible(ref, rootMargin = '0px') {
|
|
|
24
21
|
}, []);
|
|
25
22
|
return isIntersecting;
|
|
26
23
|
}
|
|
27
|
-
exports.useOnScreenVisible = useOnScreenVisible;
|
|
28
24
|
//# sourceMappingURL=onScreenVisible.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onScreenVisible.js","sourceRoot":"","sources":["../../src/hooks/onScreenVisible.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"onScreenVisible.js","sourceRoot":"","sources":["../../src/hooks/onScreenVisible.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAa,MAAM,OAAO,CAAC;AAEvD;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAAwB,GAAiB,EAAE,UAAU,GAAG,KAAK;IAC7F,MAAM,CAAC,cAAc,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAE1D,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,QAAQ,GAAG,IAAI,oBAAoB,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE;YAC5F,UAAU;SACX,CAAC,CAAC;QAEH,IAAI,GAAG,CAAC,OAAO,EAAE;YACf,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;SAC/B;QAED,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,cAAc,CAAC;AACxB,CAAC"}
|
package/lib/hooks/piletApi.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.usePiletApi = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const contexts_1 = require("../contexts");
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { PiletApiProvider } from '../contexts';
|
|
6
3
|
/**
|
|
7
4
|
* Retrieves the Pilet API stored in the provider.
|
|
8
5
|
* The component must be somewhat wrapped in the
|
|
9
6
|
* PiletApiProvider, e.g., via withPiletApi wrapper.
|
|
10
7
|
* @returns The Pilet API for this component.
|
|
11
8
|
*/
|
|
12
|
-
function usePiletApi() {
|
|
13
|
-
return
|
|
9
|
+
export function usePiletApi() {
|
|
10
|
+
return useContext(PiletApiProvider);
|
|
14
11
|
}
|
|
15
|
-
exports.usePiletApi = usePiletApi;
|
|
16
12
|
//# sourceMappingURL=piletApi.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"piletApi.js","sourceRoot":"","sources":["../../src/hooks/piletApi.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"piletApi.js","sourceRoot":"","sources":["../../src/hooks/piletApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C;;;;;GAKG;AACH,MAAM,UAAU,WAAW;IACzB,OAAO,UAAU,CAAC,gBAAgB,CAAC,CAAC;AACtC,CAAC"}
|
package/lib/hooks/prompt.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.usePrompt = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
1
|
+
import { useEffect } from 'react';
|
|
5
2
|
/**
|
|
6
3
|
* Hook to notify the user in case of potential data loss when
|
|
7
4
|
* performing a page transition (internal or external).
|
|
@@ -9,8 +6,8 @@ const react_1 = require("react");
|
|
|
9
6
|
* @param history The history of the currently used router.
|
|
10
7
|
* @param message The message to display when the prompt is shown.
|
|
11
8
|
*/
|
|
12
|
-
function usePrompt(active, history, message, onTransition) {
|
|
13
|
-
|
|
9
|
+
export function usePrompt(active, history, message, onTransition) {
|
|
10
|
+
useEffect(() => {
|
|
14
11
|
if (active) {
|
|
15
12
|
const beforeUnload = (ev) => {
|
|
16
13
|
ev.returnValue = message;
|
|
@@ -28,5 +25,4 @@ function usePrompt(active, history, message, onTransition) {
|
|
|
28
25
|
return () => { };
|
|
29
26
|
}, [active, message]);
|
|
30
27
|
}
|
|
31
|
-
exports.usePrompt = usePrompt;
|
|
32
28
|
//# sourceMappingURL=prompt.js.map
|
package/lib/hooks/prompt.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/hooks/prompt.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/hooks/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGlC;;;;;;GAMG;AACF,MAAM,UAAU,SAAS,CACxB,MAAe,EACf,OAAgB,EAChB,OAAe,EACf,YAA2C;IAE3C,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,MAAM,EAAE;YACV,MAAM,YAAY,GAAG,CAAC,EAAqB,EAAE,EAAE;gBAC7C,EAAE,CAAC,WAAW,GAAG,OAAO,CAAC;gBACzB,OAAO,OAAO,CAAC;YACjB,CAAC,CAAC;YACF,MAAM,QAAQ,GAAG,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;YAC9D,MAAM,OAAO,GAAG,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAClD,MAAM,CAAC,gBAAgB,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;YACtD,OAAO,GAAG,EAAE;gBACV,QAAQ,IAAI,QAAQ,EAAE,CAAC;gBACvB,OAAO,IAAI,OAAO,EAAE,CAAC;gBACrB,MAAM,CAAC,mBAAmB,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;YAC3D,CAAC,CAAC;SACH;QAED,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;IAClB,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AACxB,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
tslib_1.__exportStar(require("./contexts"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./hooks"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./hocs"), exports);
|
|
1
|
+
export * from './contexts';
|
|
2
|
+
export * from './hooks';
|
|
3
|
+
export * from './hocs';
|
|
7
4
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-hooks-utils",
|
|
3
|
-
"version": "1.6.0-beta.
|
|
3
|
+
"version": "1.6.0-beta.7243",
|
|
4
4
|
"description": "Hooks and HOC for pilets and Piral instances.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"piral",
|
|
@@ -16,29 +16,16 @@
|
|
|
16
16
|
"author": "smapiot",
|
|
17
17
|
"homepage": "https://piral.io",
|
|
18
18
|
"license": "MIT",
|
|
19
|
-
"module": "
|
|
19
|
+
"module": "lib/index.js",
|
|
20
20
|
"main": "lib/index.js",
|
|
21
21
|
"typings": "lib/index.d.ts",
|
|
22
22
|
"exports": {
|
|
23
|
-
".":
|
|
24
|
-
|
|
25
|
-
"require": "./lib/index.js"
|
|
26
|
-
},
|
|
27
|
-
"./esm/": {
|
|
28
|
-
"import": "./esm/"
|
|
29
|
-
},
|
|
30
|
-
"./lib/": {
|
|
31
|
-
"require": "./lib/"
|
|
32
|
-
},
|
|
33
|
-
"./_/*": {
|
|
34
|
-
"import": "./esm/*.js",
|
|
35
|
-
"require": "./lib/*.js"
|
|
36
|
-
},
|
|
23
|
+
".": "./lib/index.js",
|
|
24
|
+
"./lib/": "./lib/",
|
|
37
25
|
"./package.json": "./package.json"
|
|
38
26
|
},
|
|
39
27
|
"sideEffects": false,
|
|
40
28
|
"files": [
|
|
41
|
-
"esm",
|
|
42
29
|
"lib",
|
|
43
30
|
"src"
|
|
44
31
|
],
|
|
@@ -51,11 +38,10 @@
|
|
|
51
38
|
},
|
|
52
39
|
"scripts": {
|
|
53
40
|
"cleanup": "rimraf esm lib",
|
|
54
|
-
"build": "yarn build:
|
|
55
|
-
"build:
|
|
56
|
-
"build:esnext": "tsc --project tsconfig.json --outDir esm --module esnext",
|
|
41
|
+
"build": "yarn build:esnext",
|
|
42
|
+
"build:esnext": "tsc --project tsconfig.json --outDir lib --module esnext",
|
|
57
43
|
"typedoc": "typedoc --json ../../../docs/types/piral-hooks-utils.json src --exclude \"src/**/*.test.*\"",
|
|
58
44
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
59
45
|
},
|
|
60
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "bbb6e4f78c61b6ef753099a5b378ad2708565ce3"
|
|
61
47
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PiletApiProvider.js","sourceRoot":"","sources":["../../src/contexts/PiletApiProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAC,aAAa,CAAM,SAAS,CAAC,CAAC"}
|
package/esm/contexts/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './PiletApiProvider';
|
package/esm/contexts/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/contexts/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
|
package/esm/hocs/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './withProvider';
|
package/esm/hocs/index.js
DELETED
package/esm/hocs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hocs/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
interface BaseComponentProps {
|
|
3
|
-
/**
|
|
4
|
-
* The currently used pilet API.
|
|
5
|
-
*/
|
|
6
|
-
piral: any;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Wraps the component in a Pilet API provider allowing to make use of
|
|
10
|
-
* the `usePilet` hook.
|
|
11
|
-
* @param Component The component that should be wrapped in a provider.
|
|
12
|
-
* @returns The wrapped component.
|
|
13
|
-
*/
|
|
14
|
-
export declare function withPiletApi<T>(Component: React.FC<T>): React.FC<T & BaseComponentProps>;
|
|
15
|
-
export {};
|
package/esm/hocs/withProvider.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { PiletApiProvider } from '../contexts';
|
|
3
|
-
/**
|
|
4
|
-
* Wraps the component in a Pilet API provider allowing to make use of
|
|
5
|
-
* the `usePilet` hook.
|
|
6
|
-
* @param Component The component that should be wrapped in a provider.
|
|
7
|
-
* @returns The wrapped component.
|
|
8
|
-
*/
|
|
9
|
-
export function withPiletApi(Component) {
|
|
10
|
-
return (props) => (React.createElement(PiletApiProvider.Provider, { value: props.piral },
|
|
11
|
-
React.createElement(Component, { ...props })));
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=withProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"withProvider.js","sourceRoot":"","sources":["../../src/hocs/withProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAS/C;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAI,SAAsB;IACpD,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAChB,oBAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,CAAC,KAAK;QAC3C,oBAAC,SAAS,OAAK,KAAK,GAAI,CACE,CAC7B,CAAC;AACJ,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
/**
|
|
3
|
-
* A hook to indicate something was suddenly visible.
|
|
4
|
-
* @param time The time after which it should be triggered.
|
|
5
|
-
* @param cb The callback to use when the part was visible.
|
|
6
|
-
* @returns The reference to the element which should be watched.
|
|
7
|
-
*/
|
|
8
|
-
export declare function useAfterVisible(time: number, cb: () => void): import("react").MutableRefObject<HTMLDivElement>;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect, useRef } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* A hook to indicate something was suddenly visible.
|
|
4
|
-
* @param time The time after which it should be triggered.
|
|
5
|
-
* @param cb The callback to use when the part was visible.
|
|
6
|
-
* @returns The reference to the element which should be watched.
|
|
7
|
-
*/
|
|
8
|
-
export function useAfterVisible(time, cb) {
|
|
9
|
-
const ref = useRef(null);
|
|
10
|
-
const [intersecting, setIntersecting] = useState(false);
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
const observer = new IntersectionObserver((ev) => {
|
|
13
|
-
setIntersecting(ev.some((m) => m.isIntersecting));
|
|
14
|
-
});
|
|
15
|
-
observer.observe(ref.current);
|
|
16
|
-
return () => observer.disconnect();
|
|
17
|
-
}, [ref.current]);
|
|
18
|
-
useEffect(() => {
|
|
19
|
-
if (intersecting) {
|
|
20
|
-
const tid = setTimeout(cb, time);
|
|
21
|
-
return () => clearTimeout(tid);
|
|
22
|
-
}
|
|
23
|
-
}, [intersecting, cb]);
|
|
24
|
-
return ref;
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=afterVisible.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"afterVisible.js","sourceRoot":"","sources":["../../src/hooks/afterVisible.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY,EAAE,EAAc;IAC1D,MAAM,GAAG,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IACzC,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAExD,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,QAAQ,GAAG,IAAI,oBAAoB,CAAC,CAAC,EAAE,EAAE,EAAE;YAC/C,eAAe,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;QACH,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC9B,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;IACrC,CAAC,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;IAElB,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,YAAY,EAAE;YAChB,MAAM,GAAG,GAAG,UAAU,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;YACjC,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;SAChC;IACH,CAAC,EAAE,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,CAAC;IAEvB,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Gives a full async lifecycle in a hook.
|
|
3
|
-
* @param action The lazy loader.
|
|
4
|
-
* @param resolve The resolve function getting the result from the promise.
|
|
5
|
-
* @returns The current executing state, and the trigger to start the async operation.
|
|
6
|
-
*/
|
|
7
|
-
export declare function useAsyncReplace<T = void>(action: () => Promise<T>, resolve?: (result: T) => void): [boolean, () => void, Error | undefined];
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Gives a full async lifecycle in a hook.
|
|
4
|
-
* @param action The lazy loader.
|
|
5
|
-
* @param resolve The resolve function getting the result from the promise.
|
|
6
|
-
* @returns The current executing state, and the trigger to start the async operation.
|
|
7
|
-
*/
|
|
8
|
-
export function useAsyncReplace(action, resolve = () => { }) {
|
|
9
|
-
const [executing, setExecuting] = useState(false);
|
|
10
|
-
const error = executing instanceof Error ? executing : undefined;
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
if (executing === true) {
|
|
13
|
-
let active = true;
|
|
14
|
-
action().then((result) => active && resolve(result), (err) => active && setExecuting(err));
|
|
15
|
-
return () => (active = false);
|
|
16
|
-
}
|
|
17
|
-
return () => { };
|
|
18
|
-
}, [executing]);
|
|
19
|
-
return [executing === true, () => setExecuting(true), error];
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=asyncReplace.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"asyncReplace.js","sourceRoot":"","sources":["../../src/hooks/asyncReplace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAE5C;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAC7B,MAAwB,EACxB,UAA+B,GAAG,EAAE,GAAE,CAAC;IAEvC,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAkB,KAAK,CAAC,CAAC;IACnE,MAAM,KAAK,GAAG,SAAS,YAAY,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;IAEjE,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,SAAS,KAAK,IAAI,EAAE;YACtB,IAAI,MAAM,GAAG,IAAI,CAAC;YAElB,MAAM,EAAE,CAAC,IAAI,CACX,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,EACrC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,IAAI,YAAY,CAAC,GAAG,CAAC,CACrC,CAAC;YAEF,OAAO,GAAG,EAAE,CAAC,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC;SAC/B;QAED,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;IAClB,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhB,OAAO,CAAC,SAAS,KAAK,IAAI,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;AAC/D,CAAC"}
|
package/esm/hooks/index.d.ts
DELETED
package/esm/hooks/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from './afterVisible';
|
|
2
|
-
export * from './asyncReplace';
|
|
3
|
-
export * from './lockBodyScroll';
|
|
4
|
-
export * from './onClickOutside';
|
|
5
|
-
export * from './onScreenVisible';
|
|
6
|
-
export * from './piletApi';
|
|
7
|
-
export * from './prompt';
|
|
8
|
-
//# sourceMappingURL=index.js.map
|
package/esm/hooks/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { useLayoutEffect } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Hook that locks scrolling on the main document.
|
|
4
|
-
* Useful for preventing the standard scrolling in context of
|
|
5
|
-
* a modal dialog.
|
|
6
|
-
*/
|
|
7
|
-
export function useLockBodyScroll() {
|
|
8
|
-
useLayoutEffect(() => {
|
|
9
|
-
document.body.style.overflow = 'hidden';
|
|
10
|
-
return () => {
|
|
11
|
-
document.body.style.overflow = 'visible';
|
|
12
|
-
};
|
|
13
|
-
}, []);
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=lockBodyScroll.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lockBodyScroll.js","sourceRoot":"","sources":["../../src/hooks/lockBodyScroll.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAExC;;;;GAIG;AACH,MAAM,UAAU,iBAAiB;IAC/B,eAAe,CAAC,GAAG,EAAE;QACnB,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACxC,OAAO,GAAG,EAAE;YACV,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,SAAS,CAAC;QAC3C,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { RefObject } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Hook that detects if a click outside the given reference
|
|
4
|
-
* has been performed.
|
|
5
|
-
* @param ref The reference to the element.
|
|
6
|
-
* @param handler The callback to invoke when an outside click happened.
|
|
7
|
-
*/
|
|
8
|
-
export declare function useOnClickOutside<T extends HTMLElement>(ref: RefObject<T>, handler: (event: MouseEvent) => void): void;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Hook that detects if a click outside the given reference
|
|
4
|
-
* has been performed.
|
|
5
|
-
* @param ref The reference to the element.
|
|
6
|
-
* @param handler The callback to invoke when an outside click happened.
|
|
7
|
-
*/
|
|
8
|
-
export function useOnClickOutside(ref, handler) {
|
|
9
|
-
useEffect(() => {
|
|
10
|
-
const listener = (event) => {
|
|
11
|
-
if (ref.current && !ref.current.contains(event.target)) {
|
|
12
|
-
handler(event);
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
document.addEventListener('mousedown', listener);
|
|
16
|
-
document.addEventListener('touchstart', listener);
|
|
17
|
-
return () => {
|
|
18
|
-
document.removeEventListener('mousedown', listener);
|
|
19
|
-
document.removeEventListener('touchstart', listener);
|
|
20
|
-
};
|
|
21
|
-
}, [handler]);
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=onClickOutside.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"onClickOutside.js","sourceRoot":"","sources":["../../src/hooks/onClickOutside.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAa,MAAM,OAAO,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAwB,GAAiB,EAAE,OAAoC;IAC9G,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,QAAQ,GAAG,CAAC,KAAiB,EAAE,EAAE;YACrC,IAAI,GAAG,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAc,CAAC,EAAE;gBAC9D,OAAO,CAAC,KAAK,CAAC,CAAC;aAChB;QACH,CAAC,CAAC;QAEF,QAAQ,CAAC,gBAAgB,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;QACjD,QAAQ,CAAC,gBAAgB,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QAElD,OAAO,GAAG,EAAE;YACV,QAAQ,CAAC,mBAAmB,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;YACpD,QAAQ,CAAC,mBAAmB,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QACvD,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;AAChB,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { RefObject } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Hook that detects if a reference element within the main document is
|
|
4
|
-
* visible.
|
|
5
|
-
* Useful for performing some animation or triggering certain actions (e.g.,
|
|
6
|
-
* loading data for infinity scrolling) when an element appears or is close
|
|
7
|
-
* to appear on screen.
|
|
8
|
-
* @param ref The reference element to be visible.
|
|
9
|
-
* @param rootMargin The tolerance level to the reference element.
|
|
10
|
-
*/
|
|
11
|
-
export declare function useOnScreenVisible<T extends HTMLElement>(ref: RefObject<T>, rootMargin?: string): boolean;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Hook that detects if a reference element within the main document is
|
|
4
|
-
* visible.
|
|
5
|
-
* Useful for performing some animation or triggering certain actions (e.g.,
|
|
6
|
-
* loading data for infinity scrolling) when an element appears or is close
|
|
7
|
-
* to appear on screen.
|
|
8
|
-
* @param ref The reference element to be visible.
|
|
9
|
-
* @param rootMargin The tolerance level to the reference element.
|
|
10
|
-
*/
|
|
11
|
-
export function useOnScreenVisible(ref, rootMargin = '0px') {
|
|
12
|
-
const [isIntersecting, setIntersecting] = useState(false);
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
const observer = new IntersectionObserver(([entry]) => setIntersecting(entry.isIntersecting), {
|
|
15
|
-
rootMargin,
|
|
16
|
-
});
|
|
17
|
-
if (ref.current) {
|
|
18
|
-
observer.observe(ref.current);
|
|
19
|
-
}
|
|
20
|
-
return () => observer.unobserve(ref.current);
|
|
21
|
-
}, []);
|
|
22
|
-
return isIntersecting;
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=onScreenVisible.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"onScreenVisible.js","sourceRoot":"","sources":["../../src/hooks/onScreenVisible.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAa,MAAM,OAAO,CAAC;AAEvD;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAAwB,GAAiB,EAAE,UAAU,GAAG,KAAK;IAC7F,MAAM,CAAC,cAAc,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAE1D,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,QAAQ,GAAG,IAAI,oBAAoB,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE;YAC5F,UAAU;SACX,CAAC,CAAC;QAEH,IAAI,GAAG,CAAC,OAAO,EAAE;YACf,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;SAC/B;QAED,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,cAAc,CAAC;AACxB,CAAC"}
|
package/esm/hooks/piletApi.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Retrieves the Pilet API stored in the provider.
|
|
3
|
-
* The component must be somewhat wrapped in the
|
|
4
|
-
* PiletApiProvider, e.g., via withPiletApi wrapper.
|
|
5
|
-
* @returns The Pilet API for this component.
|
|
6
|
-
*/
|
|
7
|
-
export declare function usePiletApi<TPiletApi = any>(): TPiletApi;
|
package/esm/hooks/piletApi.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { useContext } from 'react';
|
|
2
|
-
import { PiletApiProvider } from '../contexts';
|
|
3
|
-
/**
|
|
4
|
-
* Retrieves the Pilet API stored in the provider.
|
|
5
|
-
* The component must be somewhat wrapped in the
|
|
6
|
-
* PiletApiProvider, e.g., via withPiletApi wrapper.
|
|
7
|
-
* @returns The Pilet API for this component.
|
|
8
|
-
*/
|
|
9
|
-
export function usePiletApi() {
|
|
10
|
-
return useContext(PiletApiProvider);
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=piletApi.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"piletApi.js","sourceRoot":"","sources":["../../src/hooks/piletApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C;;;;;GAKG;AACH,MAAM,UAAU,WAAW;IACzB,OAAO,UAAU,CAAC,gBAAgB,CAAC,CAAC;AACtC,CAAC"}
|
package/esm/hooks/prompt.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { History, Location } from 'history';
|
|
2
|
-
/**
|
|
3
|
-
* Hook to notify the user in case of potential data loss when
|
|
4
|
-
* performing a page transition (internal or external).
|
|
5
|
-
* @param active True if the prompt should be shown, otherwise false.
|
|
6
|
-
* @param history The history of the currently used router.
|
|
7
|
-
* @param message The message to display when the prompt is shown.
|
|
8
|
-
*/
|
|
9
|
-
export declare function usePrompt(active: boolean, history: History, message: string, onTransition?: (location: Location) => void): void;
|
package/esm/hooks/prompt.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Hook to notify the user in case of potential data loss when
|
|
4
|
-
* performing a page transition (internal or external).
|
|
5
|
-
* @param active True if the prompt should be shown, otherwise false.
|
|
6
|
-
* @param history The history of the currently used router.
|
|
7
|
-
* @param message The message to display when the prompt is shown.
|
|
8
|
-
*/
|
|
9
|
-
export function usePrompt(active, history, message, onTransition) {
|
|
10
|
-
useEffect(() => {
|
|
11
|
-
if (active) {
|
|
12
|
-
const beforeUnload = (ev) => {
|
|
13
|
-
ev.returnValue = message;
|
|
14
|
-
return message;
|
|
15
|
-
};
|
|
16
|
-
const unlisten = onTransition && history.listen(onTransition);
|
|
17
|
-
const unblock = message && history.block(message);
|
|
18
|
-
window.addEventListener('beforeunload', beforeUnload);
|
|
19
|
-
return () => {
|
|
20
|
-
unlisten && unlisten();
|
|
21
|
-
unblock && unblock();
|
|
22
|
-
window.removeEventListener('beforeunload', beforeUnload);
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
return () => { };
|
|
26
|
-
}, [active, message]);
|
|
27
|
-
}
|
|
28
|
-
//# sourceMappingURL=prompt.js.map
|
package/esm/hooks/prompt.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/hooks/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGlC;;;;;;GAMG;AACF,MAAM,UAAU,SAAS,CACxB,MAAe,EACf,OAAgB,EAChB,OAAe,EACf,YAA2C;IAE3C,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,MAAM,EAAE;YACV,MAAM,YAAY,GAAG,CAAC,EAAqB,EAAE,EAAE;gBAC7C,EAAE,CAAC,WAAW,GAAG,OAAO,CAAC;gBACzB,OAAO,OAAO,CAAC;YACjB,CAAC,CAAC;YACF,MAAM,QAAQ,GAAG,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;YAC9D,MAAM,OAAO,GAAG,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAClD,MAAM,CAAC,gBAAgB,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;YACtD,OAAO,GAAG,EAAE;gBACV,QAAQ,IAAI,QAAQ,EAAE,CAAC;gBACvB,OAAO,IAAI,OAAO,EAAE,CAAC;gBACrB,MAAM,CAAC,mBAAmB,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;YAC3D,CAAC,CAAC;SACH;QAED,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;IAClB,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AACxB,CAAC"}
|
package/esm/index.d.ts
DELETED
package/esm/index.js
DELETED
package/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC"}
|