@react-hive/honey-layout 18.0.0 → 18.1.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/contexts/HoneyLayoutContext.d.ts +35 -9
- package/dist/hooks/use-honey-overlay.d.ts +22 -20
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.dev.cjs +104 -29
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.mjs +6 -6
- package/dist/index.mjs.map +1 -1
- package/dist/providers/HoneyLayoutProvider.d.ts +25 -0
- package/dist/providers/hooks/use-honey-overlays.d.ts +11 -7
- package/package.json +1 -1
|
@@ -1,34 +1,60 @@
|
|
|
1
1
|
import type { HoneyTheme } from '@react-hive/honey-style';
|
|
2
2
|
import type { HoneyOverlayConfig, HoneyScreenState, HoneyOverlayId, HoneyActiveOverlay } from '../types';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Returns the current active overlay stack snapshot.
|
|
5
|
+
*
|
|
6
|
+
* The returned array keeps the same identity until the overlay stack changes, allowing it to
|
|
7
|
+
* be consumed safely by `useSyncExternalStore`. Consumers must not mutate the snapshot.
|
|
8
|
+
*
|
|
9
|
+
* @returns The active overlays in registration order.
|
|
10
|
+
*/
|
|
11
|
+
export type HoneyGetOverlaysSnapshot = () => readonly HoneyActiveOverlay[];
|
|
12
|
+
/**
|
|
13
|
+
* Subscribes to active overlay stack changes.
|
|
14
|
+
*
|
|
15
|
+
* @param subscriber - Callback invoked when a new overlay stack snapshot is available.
|
|
16
|
+
* @returns A cleanup function that removes the subscriber.
|
|
17
|
+
*/
|
|
18
|
+
export type HoneySubscribeOverlays = (subscriber: () => void) => () => void;
|
|
19
|
+
/**
|
|
20
|
+
* Unregisters a previously registered overlay.
|
|
21
|
+
*
|
|
22
|
+
* @param targetOverlayId - The ID of the overlay to unregister.
|
|
5
23
|
*/
|
|
6
24
|
export type HoneyUnregisterOverlay = (targetOverlayId: HoneyOverlayId) => void;
|
|
7
25
|
/**
|
|
8
|
-
*
|
|
26
|
+
* Registers a new active overlay.
|
|
9
27
|
*
|
|
10
|
-
* @param overlayConfig - Configuration
|
|
28
|
+
* @param overlayConfig - Configuration for the overlay.
|
|
29
|
+
* @returns The registered active overlay instance.
|
|
11
30
|
*/
|
|
12
31
|
export type HoneyRegisterOverlay = (overlayConfig: HoneyOverlayConfig) => HoneyActiveOverlay;
|
|
32
|
+
/**
|
|
33
|
+
* Values and overlay-store operations exposed by `HoneyLayoutProvider`.
|
|
34
|
+
*/
|
|
13
35
|
export interface HoneyLayoutContextValue {
|
|
14
36
|
/**
|
|
15
|
-
*
|
|
37
|
+
* The active Honey theme.
|
|
16
38
|
*/
|
|
17
39
|
theme: HoneyTheme;
|
|
18
40
|
/**
|
|
19
|
-
*
|
|
41
|
+
* The current responsive screen state.
|
|
20
42
|
*/
|
|
21
43
|
screenState: HoneyScreenState;
|
|
22
44
|
/**
|
|
23
|
-
*
|
|
45
|
+
* Returns the current overlay stack snapshot without subscribing the caller to changes.
|
|
46
|
+
*/
|
|
47
|
+
getOverlaysSnapshot: HoneyGetOverlaysSnapshot;
|
|
48
|
+
/**
|
|
49
|
+
* Subscribes a consumer to overlay stack changes without re-rendering the layout provider.
|
|
24
50
|
*/
|
|
25
|
-
|
|
51
|
+
subscribeOverlays: HoneySubscribeOverlays;
|
|
26
52
|
/**
|
|
27
|
-
*
|
|
53
|
+
* Registers an overlay and publishes a new overlay stack snapshot.
|
|
28
54
|
*/
|
|
29
55
|
registerOverlay: HoneyRegisterOverlay;
|
|
30
56
|
/**
|
|
31
|
-
*
|
|
57
|
+
* Unregisters an overlay and publishes a new snapshot when the overlay existed.
|
|
32
58
|
*/
|
|
33
59
|
unregisterOverlay: HoneyUnregisterOverlay;
|
|
34
60
|
}
|
|
@@ -1,49 +1,51 @@
|
|
|
1
|
-
import type { HoneyOverlayId, HoneyOverlayEventListenerHandler,
|
|
1
|
+
import type { HoneyOverlayId, HoneyOverlayEventListenerHandler, Nullable, HoneyActiveOverlay } from '../types';
|
|
2
2
|
interface UseHoneyOverlayOptions {
|
|
3
3
|
/**
|
|
4
4
|
* Whether the hook should resolve the overlay and attach event listeners.
|
|
5
5
|
*
|
|
6
|
-
* When `false`, the hook returns `null
|
|
6
|
+
* When `false`, the hook returns `null`, does not subscribe to overlay stack changes,
|
|
7
|
+
* and does not attach an overlay event listener.
|
|
7
8
|
*
|
|
8
9
|
* @default true
|
|
9
10
|
*/
|
|
10
11
|
enabled?: boolean;
|
|
11
12
|
/**
|
|
12
|
-
* Callback fired when the
|
|
13
|
+
* Callback fired when the target overlay receives a keyup event.
|
|
13
14
|
*
|
|
14
|
-
* The handler is
|
|
15
|
-
*
|
|
16
|
-
*
|
|
15
|
+
* The handler is attached only while the target overlay is active and the hook is enabled.
|
|
16
|
+
* It is automatically removed when the overlay or handler changes, the hook is disabled,
|
|
17
|
+
* or the component unmounts.
|
|
17
18
|
*/
|
|
18
19
|
onKeyUp?: HoneyOverlayEventListenerHandler;
|
|
19
20
|
}
|
|
20
21
|
/**
|
|
21
|
-
* Returns an active overlay by ID and optionally attaches
|
|
22
|
+
* Returns an active overlay by ID and optionally attaches a keyup event listener.
|
|
22
23
|
*
|
|
23
|
-
*
|
|
24
|
-
* It
|
|
24
|
+
* The hook reads the overlay through the external overlay store exposed by
|
|
25
|
+
* `HoneyLayoutProvider`. It subscribes to stack changes with `useSyncExternalStore`, but
|
|
26
|
+
* selects only the requested overlay. Consequently, unrelated overlay stack changes do not
|
|
27
|
+
* re-render the consuming component when the selected overlay instance remains unchanged.
|
|
25
28
|
*
|
|
26
29
|
* @param targetOverlayId - The ID of the active overlay to find.
|
|
27
|
-
* @param options - Optional configuration for resolving the overlay and
|
|
30
|
+
* @param options - Optional configuration for resolving the overlay and handling keyup events.
|
|
28
31
|
*
|
|
29
|
-
* @returns The matching active overlay
|
|
30
|
-
*
|
|
32
|
+
* @returns The matching active overlay, or `null` when the hook is disabled or the overlay is
|
|
33
|
+
* not currently registered.
|
|
31
34
|
*
|
|
32
35
|
* @remarks
|
|
33
|
-
* - The hook only
|
|
34
|
-
* - If `enabled` is `false`, the
|
|
35
|
-
* - If the overlay is
|
|
36
|
-
* -
|
|
37
|
-
* -
|
|
38
|
-
* or component lifecycle changes.
|
|
36
|
+
* - The hook resolves only overlays that are currently registered.
|
|
37
|
+
* - If `enabled` is `false`, the snapshot is `null` and no keyup listener is attached.
|
|
38
|
+
* - If the target overlay is registered or unregistered, the consuming component is updated.
|
|
39
|
+
* - Changes to unrelated overlays do not cause a re-render when the selected snapshot is equal.
|
|
40
|
+
* - The `onKeyUp` listener is automatically cleaned up when its dependencies change.
|
|
39
41
|
*
|
|
40
42
|
* @example
|
|
41
43
|
* ```tsx
|
|
42
44
|
* const overlay = useHoneyOverlay('my-overlay-id', {
|
|
43
45
|
* enabled: isOpen,
|
|
44
|
-
* onKeyUp:
|
|
46
|
+
* onKeyUp: keyCode => {
|
|
45
47
|
* if (keyCode === 'Escape') {
|
|
46
|
-
*
|
|
48
|
+
* closeOverlay();
|
|
47
49
|
* }
|
|
48
50
|
* },
|
|
49
51
|
* });
|