@40rty/ams-ui 0.5.19 → 0.5.21
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.
|
@@ -3602,10 +3602,10 @@ function useClaimEntryPoint(active) {
|
|
|
3602
3602
|
return () => claim(-1);
|
|
3603
3603
|
}, [claim, active]);
|
|
3604
3604
|
}
|
|
3605
|
-
function
|
|
3605
|
+
function useViewportPresence(ref, opts) {
|
|
3606
3606
|
const enter = opts !== void 0 && opts.enter !== void 0 ? opts.enter : 0.9;
|
|
3607
3607
|
const exit = opts !== void 0 && opts.exit !== void 0 ? opts.exit : 0.25;
|
|
3608
|
-
const [
|
|
3608
|
+
const [presence, setPresence] = React21.useState({ onScreen: true, inView: true });
|
|
3609
3609
|
React21.useEffect(() => {
|
|
3610
3610
|
const el = ref.current;
|
|
3611
3611
|
if (el === null || typeof IntersectionObserver === "undefined") return;
|
|
@@ -3614,14 +3614,21 @@ function useOnScreen(ref, opts) {
|
|
|
3614
3614
|
const entry = entries[entries.length - 1];
|
|
3615
3615
|
if (entry === void 0) return;
|
|
3616
3616
|
const ratio = entry.intersectionRatio;
|
|
3617
|
-
|
|
3617
|
+
setPresence((prev) => {
|
|
3618
|
+
const onScreen = prev.onScreen ? ratio > exit : ratio >= enter;
|
|
3619
|
+
const inView = ratio > 0;
|
|
3620
|
+
return onScreen === prev.onScreen && inView === prev.inView ? prev : { onScreen, inView };
|
|
3621
|
+
});
|
|
3618
3622
|
},
|
|
3619
3623
|
{ threshold: [0, exit, enter, 1] }
|
|
3620
3624
|
);
|
|
3621
3625
|
observer.observe(el);
|
|
3622
3626
|
return () => observer.disconnect();
|
|
3623
3627
|
}, [ref, enter, exit]);
|
|
3624
|
-
return
|
|
3628
|
+
return presence;
|
|
3629
|
+
}
|
|
3630
|
+
function useOnScreen(ref, opts) {
|
|
3631
|
+
return useViewportPresence(ref, opts).onScreen;
|
|
3625
3632
|
}
|
|
3626
3633
|
function useFocusWithin(ref) {
|
|
3627
3634
|
const [focused, setFocused] = React21.useState(false);
|
|
@@ -3643,9 +3650,9 @@ function useFocusWithin(ref) {
|
|
|
3643
3650
|
return focused;
|
|
3644
3651
|
}
|
|
3645
3652
|
function useEntryPoint(ref, showing) {
|
|
3646
|
-
const onScreen =
|
|
3653
|
+
const { onScreen, inView } = useViewportPresence(ref);
|
|
3647
3654
|
const focused = useFocusWithin(ref);
|
|
3648
|
-
useClaimEntryPoint(showing && (onScreen || focused));
|
|
3655
|
+
useClaimEntryPoint(showing && (onScreen || focused && inView));
|
|
3649
3656
|
}
|
|
3650
3657
|
|
|
3651
3658
|
// src/shell/mobile/use-island-fold-scroll.ts
|
package/dist/conversation.js
CHANGED
package/dist/shell.js
CHANGED
|
@@ -93,23 +93,7 @@ export declare function useEntryPointClaimed(): boolean;
|
|
|
93
93
|
* component can call it unconditionally without knowing where it is mounted.
|
|
94
94
|
*/
|
|
95
95
|
export declare function useClaimEntryPoint(active: boolean): void;
|
|
96
|
-
/**
|
|
97
|
-
* Is this element actually ON SCREEN — with hysteresis, so a boundary does not
|
|
98
|
-
* flicker.
|
|
99
|
-
*
|
|
100
|
-
* The hero's prompt box claims the entry point, and the claim has to end when
|
|
101
|
-
* the box scrolls away: a visitor reading down the page has left the box
|
|
102
|
-
* behind, and with the island still withheld they have no way to ask anything
|
|
103
|
-
* without scrolling back up to find one. "Is the box still on screen" is
|
|
104
|
-
* exactly the question, and an `IntersectionObserver` answers it without
|
|
105
|
-
* anyone plumbing scroll offsets around.
|
|
106
|
-
*
|
|
107
|
-
* TWO thresholds, not one. At a single threshold the boundary is a knife edge:
|
|
108
|
-
* a visitor who parks the page with the box half off screen gets the island
|
|
109
|
-
* mounting and unmounting under every small correction of their thumb. It
|
|
110
|
-
* takes `exit` visibility to give up the claim and the much stricter `enter`
|
|
111
|
-
* to take it back, so the two states overlap and neither can chatter.
|
|
112
|
-
*/
|
|
96
|
+
/** On screen, with hysteresis — see `useViewportPresence`. */
|
|
113
97
|
export declare function useOnScreen(ref: React.RefObject<HTMLElement | null>, opts?: {
|
|
114
98
|
enter?: number;
|
|
115
99
|
exit?: number;
|
|
@@ -121,13 +105,19 @@ export declare function useFocusWithin(ref: React.RefObject<HTMLElement | null>)
|
|
|
121
105
|
/**
|
|
122
106
|
* THE one call for ANY brand component with its own ask box — a hero, a
|
|
123
107
|
* banner, a block mid-page, anything: pass the box (or its field) and whether
|
|
124
|
-
* the component is showing it. While the box is showing AND either on screen
|
|
125
|
-
* or focused, it is the entry point, and the
|
|
126
|
-
* page composer stand aside.
|
|
127
|
-
*
|
|
128
|
-
* Focus is
|
|
129
|
-
* fold, under the visibility threshold, while the
|
|
130
|
-
* second box rising under the one they are using is
|
|
131
|
-
* claim exists to prevent.
|
|
108
|
+
* the component is showing it. While the box is showing AND either on screen,
|
|
109
|
+
* or focused with some of it still in view, it is the entry point, and the
|
|
110
|
+
* phone's island and the shell's page composer stand aside.
|
|
111
|
+
*
|
|
112
|
+
* Focus is a reason only while the box is still in view. On a short screen the
|
|
113
|
+
* box can sit partly below the fold, under the visibility threshold, while the
|
|
114
|
+
* visitor is typing in it; a second box rising under the one they are using is
|
|
115
|
+
* the exact collision the claim exists to prevent.
|
|
116
|
+
*
|
|
117
|
+
* But focus is not attention. A desktop hero autofocuses its field on mount,
|
|
118
|
+
* and scrolling never blurs it — so a claim that honoured focus alone held for
|
|
119
|
+
* as long as the visitor never clicked anything else, and a visitor who
|
|
120
|
+
* scrolled down the home page was left with no box to ask from at all. A box
|
|
121
|
+
* scrolled wholly out of view is not the one anybody is using, focused or not.
|
|
132
122
|
*/
|
|
133
123
|
export declare function useEntryPoint(ref: React.RefObject<HTMLElement | null>, showing: boolean): void;
|
package/package.json
CHANGED
|
@@ -76,12 +76,12 @@
|
|
|
76
76
|
"zod": "^3.23.0"
|
|
77
77
|
},
|
|
78
78
|
"peerDependencies": {
|
|
79
|
-
"@40rty/ams-sdk": "0.5.
|
|
79
|
+
"@40rty/ams-sdk": "0.5.21",
|
|
80
80
|
"lucide-react": ">=0.400.0",
|
|
81
81
|
"react": ">=18.0.0",
|
|
82
82
|
"react-dom": ">=18.0.0"
|
|
83
83
|
},
|
|
84
|
-
"version": "0.5.
|
|
84
|
+
"version": "0.5.21",
|
|
85
85
|
"homepage": "https://docs.40rty.ai",
|
|
86
86
|
"license": "UNLICENSED",
|
|
87
87
|
"engines": {
|