@pallasoft/ps-core-components 2.24.0 → 2.25.0
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/esm/hooks/use-ps-exit-snapshot.js +7 -0
- package/dist/esm/hooks/use-ps-exit-transition.js +5 -2
- package/dist/esm/hooks/use-ps-restore-focus.js +16 -0
- package/dist/esm/hooks/use-ps-scroll-lock.js +9 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/services/ps-scroll-lock-service.js +23 -0
- package/dist/hooks/use-ps-exit-snapshot.d.ts +1 -0
- package/dist/hooks/use-ps-exit-snapshot.js +11 -0
- package/dist/hooks/use-ps-exit-transition.js +5 -2
- package/dist/hooks/use-ps-restore-focus.d.ts +1 -0
- package/dist/hooks/use-ps-restore-focus.js +20 -0
- package/dist/hooks/use-ps-scroll-lock.d.ts +1 -0
- package/dist/hooks/use-ps-scroll-lock.js +13 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/services/ps-scroll-lock-service.d.ts +5 -0
- package/dist/services/ps-scroll-lock-service.js +27 -0
- package/package.json +1 -1
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { usePsReducedMotion } from './use-ps-reduced-motion';
|
|
2
3
|
export const usePsExitTransition = (isOpen, durationMs = 180) => {
|
|
3
4
|
const [shouldRender, setShouldRender] = useState(isOpen);
|
|
4
5
|
const [isClosing, setIsClosing] = useState(false);
|
|
5
6
|
const timeoutRef = useRef();
|
|
6
7
|
const hasRenderedRef = useRef(isOpen);
|
|
8
|
+
const isReducedMotion = usePsReducedMotion();
|
|
9
|
+
const exitDurationMs = isReducedMotion ? 0 : durationMs;
|
|
7
10
|
useEffect(() => {
|
|
8
11
|
if (timeoutRef.current)
|
|
9
12
|
clearTimeout(timeoutRef.current);
|
|
@@ -18,12 +21,12 @@ export const usePsExitTransition = (isOpen, durationMs = 180) => {
|
|
|
18
21
|
timeoutRef.current = setTimeout(() => {
|
|
19
22
|
setShouldRender(false);
|
|
20
23
|
setIsClosing(false);
|
|
21
|
-
},
|
|
24
|
+
}, exitDurationMs);
|
|
22
25
|
return () => {
|
|
23
26
|
if (timeoutRef.current)
|
|
24
27
|
clearTimeout(timeoutRef.current);
|
|
25
28
|
};
|
|
26
|
-
}, [isOpen,
|
|
29
|
+
}, [isOpen, exitDurationMs]);
|
|
27
30
|
hasRenderedRef.current = shouldRender;
|
|
28
31
|
return { isClosing, shouldRender };
|
|
29
32
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
export const usePsRestoreFocus = (isActive) => {
|
|
3
|
+
const returnTargetRef = useRef(null);
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
if (!isActive)
|
|
6
|
+
return;
|
|
7
|
+
returnTargetRef.current =
|
|
8
|
+
document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
9
|
+
return () => {
|
|
10
|
+
const target = returnTargetRef.current;
|
|
11
|
+
returnTargetRef.current = null;
|
|
12
|
+
if (target && target.isConnected)
|
|
13
|
+
target.focus();
|
|
14
|
+
};
|
|
15
|
+
}, [isActive]);
|
|
16
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { PsScrollLockService } from '../services/ps-scroll-lock-service';
|
|
3
|
+
export const usePsScrollLock = (isLocked) => {
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
if (!isLocked)
|
|
6
|
+
return;
|
|
7
|
+
return PsScrollLockService.lock();
|
|
8
|
+
}, [isLocked]);
|
|
9
|
+
};
|
package/dist/esm/index.js
CHANGED
|
@@ -32,6 +32,7 @@ export * from './hooks/use-ps-published-height';
|
|
|
32
32
|
export * from './constants/ps-scaled-preview-config';
|
|
33
33
|
export * from './constants/ps-site-header-config';
|
|
34
34
|
export * from './components/ps-skeleton';
|
|
35
|
+
export * from './services/ps-scroll-lock-service';
|
|
35
36
|
export * from './services/ps-skeleton-class-service';
|
|
36
37
|
export * from './models/ps-skeleton-size';
|
|
37
38
|
export * from './constants/ps-skeleton-shape';
|
|
@@ -45,7 +46,10 @@ export * from './components/ps-spinner';
|
|
|
45
46
|
export * from './components/ps-theme-toggle';
|
|
46
47
|
export * from './components/ps-voice-orb';
|
|
47
48
|
export * from './hooks/use-ps-audio-spectrum';
|
|
49
|
+
export * from './hooks/use-ps-exit-snapshot';
|
|
48
50
|
export * from './hooks/use-ps-exit-transition';
|
|
51
|
+
export * from './hooks/use-ps-restore-focus';
|
|
52
|
+
export * from './hooks/use-ps-scroll-lock';
|
|
49
53
|
export * from './hooks/use-ps-hide-on-scroll';
|
|
50
54
|
export * from './hooks/use-ps-invisible-recaptcha';
|
|
51
55
|
export * from './contexts/ps-layer-context';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export class PsScrollLockService {
|
|
2
|
+
static lock() {
|
|
3
|
+
if (typeof document === 'undefined')
|
|
4
|
+
return () => undefined;
|
|
5
|
+
if (PsScrollLockService.count === 0) {
|
|
6
|
+
PsScrollLockService.previousOverflow = document.body.style.overflow;
|
|
7
|
+
document.body.style.overflow = 'hidden';
|
|
8
|
+
}
|
|
9
|
+
PsScrollLockService.count += 1;
|
|
10
|
+
let isReleased = false;
|
|
11
|
+
return () => {
|
|
12
|
+
if (isReleased)
|
|
13
|
+
return;
|
|
14
|
+
isReleased = true;
|
|
15
|
+
PsScrollLockService.count -= 1;
|
|
16
|
+
if (PsScrollLockService.count === 0) {
|
|
17
|
+
document.body.style.overflow = PsScrollLockService.previousOverflow;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
PsScrollLockService.count = 0;
|
|
23
|
+
PsScrollLockService.previousOverflow = '';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const usePsExitSnapshot: <T>(isOpen: boolean, value: T) => T;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.usePsExitSnapshot = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const usePsExitSnapshot = (isOpen, value) => {
|
|
6
|
+
const snapshotRef = (0, react_1.useRef)(value);
|
|
7
|
+
if (isOpen)
|
|
8
|
+
snapshotRef.current = value;
|
|
9
|
+
return snapshotRef.current;
|
|
10
|
+
};
|
|
11
|
+
exports.usePsExitSnapshot = usePsExitSnapshot;
|
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.usePsExitTransition = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
+
const use_ps_reduced_motion_1 = require("./use-ps-reduced-motion");
|
|
5
6
|
const usePsExitTransition = (isOpen, durationMs = 180) => {
|
|
6
7
|
const [shouldRender, setShouldRender] = (0, react_1.useState)(isOpen);
|
|
7
8
|
const [isClosing, setIsClosing] = (0, react_1.useState)(false);
|
|
8
9
|
const timeoutRef = (0, react_1.useRef)();
|
|
9
10
|
const hasRenderedRef = (0, react_1.useRef)(isOpen);
|
|
11
|
+
const isReducedMotion = (0, use_ps_reduced_motion_1.usePsReducedMotion)();
|
|
12
|
+
const exitDurationMs = isReducedMotion ? 0 : durationMs;
|
|
10
13
|
(0, react_1.useEffect)(() => {
|
|
11
14
|
if (timeoutRef.current)
|
|
12
15
|
clearTimeout(timeoutRef.current);
|
|
@@ -21,12 +24,12 @@ const usePsExitTransition = (isOpen, durationMs = 180) => {
|
|
|
21
24
|
timeoutRef.current = setTimeout(() => {
|
|
22
25
|
setShouldRender(false);
|
|
23
26
|
setIsClosing(false);
|
|
24
|
-
},
|
|
27
|
+
}, exitDurationMs);
|
|
25
28
|
return () => {
|
|
26
29
|
if (timeoutRef.current)
|
|
27
30
|
clearTimeout(timeoutRef.current);
|
|
28
31
|
};
|
|
29
|
-
}, [isOpen,
|
|
32
|
+
}, [isOpen, exitDurationMs]);
|
|
30
33
|
hasRenderedRef.current = shouldRender;
|
|
31
34
|
return { isClosing, shouldRender };
|
|
32
35
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const usePsRestoreFocus: (isActive: boolean) => void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.usePsRestoreFocus = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const usePsRestoreFocus = (isActive) => {
|
|
6
|
+
const returnTargetRef = (0, react_1.useRef)(null);
|
|
7
|
+
(0, react_1.useEffect)(() => {
|
|
8
|
+
if (!isActive)
|
|
9
|
+
return;
|
|
10
|
+
returnTargetRef.current =
|
|
11
|
+
document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
12
|
+
return () => {
|
|
13
|
+
const target = returnTargetRef.current;
|
|
14
|
+
returnTargetRef.current = null;
|
|
15
|
+
if (target && target.isConnected)
|
|
16
|
+
target.focus();
|
|
17
|
+
};
|
|
18
|
+
}, [isActive]);
|
|
19
|
+
};
|
|
20
|
+
exports.usePsRestoreFocus = usePsRestoreFocus;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const usePsScrollLock: (isLocked: boolean) => void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.usePsScrollLock = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const ps_scroll_lock_service_1 = require("../services/ps-scroll-lock-service");
|
|
6
|
+
const usePsScrollLock = (isLocked) => {
|
|
7
|
+
(0, react_1.useEffect)(() => {
|
|
8
|
+
if (!isLocked)
|
|
9
|
+
return;
|
|
10
|
+
return ps_scroll_lock_service_1.PsScrollLockService.lock();
|
|
11
|
+
}, [isLocked]);
|
|
12
|
+
};
|
|
13
|
+
exports.usePsScrollLock = usePsScrollLock;
|
package/dist/index.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ export * from './hooks/use-ps-published-height';
|
|
|
32
32
|
export * from './constants/ps-scaled-preview-config';
|
|
33
33
|
export * from './constants/ps-site-header-config';
|
|
34
34
|
export * from './components/ps-skeleton';
|
|
35
|
+
export * from './services/ps-scroll-lock-service';
|
|
35
36
|
export * from './services/ps-skeleton-class-service';
|
|
36
37
|
export * from './models/ps-skeleton-size';
|
|
37
38
|
export * from './constants/ps-skeleton-shape';
|
|
@@ -45,7 +46,10 @@ export * from './components/ps-spinner';
|
|
|
45
46
|
export * from './components/ps-theme-toggle';
|
|
46
47
|
export * from './components/ps-voice-orb';
|
|
47
48
|
export * from './hooks/use-ps-audio-spectrum';
|
|
49
|
+
export * from './hooks/use-ps-exit-snapshot';
|
|
48
50
|
export * from './hooks/use-ps-exit-transition';
|
|
51
|
+
export * from './hooks/use-ps-restore-focus';
|
|
52
|
+
export * from './hooks/use-ps-scroll-lock';
|
|
49
53
|
export * from './hooks/use-ps-hide-on-scroll';
|
|
50
54
|
export * from './hooks/use-ps-invisible-recaptcha';
|
|
51
55
|
export * from './contexts/ps-layer-context';
|
package/dist/index.js
CHANGED
|
@@ -48,6 +48,7 @@ __exportStar(require("./hooks/use-ps-published-height"), exports);
|
|
|
48
48
|
__exportStar(require("./constants/ps-scaled-preview-config"), exports);
|
|
49
49
|
__exportStar(require("./constants/ps-site-header-config"), exports);
|
|
50
50
|
__exportStar(require("./components/ps-skeleton"), exports);
|
|
51
|
+
__exportStar(require("./services/ps-scroll-lock-service"), exports);
|
|
51
52
|
__exportStar(require("./services/ps-skeleton-class-service"), exports);
|
|
52
53
|
__exportStar(require("./models/ps-skeleton-size"), exports);
|
|
53
54
|
__exportStar(require("./constants/ps-skeleton-shape"), exports);
|
|
@@ -61,7 +62,10 @@ __exportStar(require("./components/ps-spinner"), exports);
|
|
|
61
62
|
__exportStar(require("./components/ps-theme-toggle"), exports);
|
|
62
63
|
__exportStar(require("./components/ps-voice-orb"), exports);
|
|
63
64
|
__exportStar(require("./hooks/use-ps-audio-spectrum"), exports);
|
|
65
|
+
__exportStar(require("./hooks/use-ps-exit-snapshot"), exports);
|
|
64
66
|
__exportStar(require("./hooks/use-ps-exit-transition"), exports);
|
|
67
|
+
__exportStar(require("./hooks/use-ps-restore-focus"), exports);
|
|
68
|
+
__exportStar(require("./hooks/use-ps-scroll-lock"), exports);
|
|
65
69
|
__exportStar(require("./hooks/use-ps-hide-on-scroll"), exports);
|
|
66
70
|
__exportStar(require("./hooks/use-ps-invisible-recaptcha"), exports);
|
|
67
71
|
__exportStar(require("./contexts/ps-layer-context"), exports);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PsScrollLockService = void 0;
|
|
4
|
+
class PsScrollLockService {
|
|
5
|
+
static lock() {
|
|
6
|
+
if (typeof document === 'undefined')
|
|
7
|
+
return () => undefined;
|
|
8
|
+
if (PsScrollLockService.count === 0) {
|
|
9
|
+
PsScrollLockService.previousOverflow = document.body.style.overflow;
|
|
10
|
+
document.body.style.overflow = 'hidden';
|
|
11
|
+
}
|
|
12
|
+
PsScrollLockService.count += 1;
|
|
13
|
+
let isReleased = false;
|
|
14
|
+
return () => {
|
|
15
|
+
if (isReleased)
|
|
16
|
+
return;
|
|
17
|
+
isReleased = true;
|
|
18
|
+
PsScrollLockService.count -= 1;
|
|
19
|
+
if (PsScrollLockService.count === 0) {
|
|
20
|
+
document.body.style.overflow = PsScrollLockService.previousOverflow;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.PsScrollLockService = PsScrollLockService;
|
|
26
|
+
PsScrollLockService.count = 0;
|
|
27
|
+
PsScrollLockService.previousOverflow = '';
|