@cloudlet/toast 1.0.0-rc.3 → 1.0.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/CHANGELOG.md +42 -7
- package/README.md +5 -4
- package/dist/contracts/events.d.ts +1 -1
- package/dist/contracts/events.d.ts.map +1 -1
- package/dist/core/bridge.d.ts +5 -0
- package/dist/core/bridge.d.ts.map +1 -0
- package/dist/core/bridge.js +277 -0
- package/dist/core/bridge.js.map +1 -0
- package/dist/core/controller.d.ts +113 -3
- package/dist/core/controller.d.ts.map +1 -1
- package/dist/core/controller.js +416 -583
- package/dist/core/controller.js.map +1 -1
- package/dist/react/announcer.d.ts.map +1 -1
- package/dist/react/announcer.js +29 -23
- package/dist/react/announcer.js.map +1 -1
- package/dist/react/bindings.d.ts +9 -0
- package/dist/react/bindings.d.ts.map +1 -1
- package/dist/react/bindings.js +32 -69
- package/dist/react/bindings.js.map +1 -1
- package/dist/react/card.d.ts +1 -1
- package/dist/react/card.js.map +1 -1
- package/dist/react/generators.d.ts +2 -2
- package/dist/react/generators.js.map +1 -1
- package/dist/react/gestures.js.map +1 -1
- package/dist/react/host.d.ts.map +1 -1
- package/dist/react/host.js +1 -1
- package/dist/react/host.js.map +1 -1
- package/dist/react/motion.d.ts +3 -3
- package/dist/react/motion.js.map +1 -1
- package/dist/react/plan.d.ts +1 -1
- package/dist/react/plan.d.ts.map +1 -1
- package/dist/react/plan.js.map +1 -1
- package/dist/react/renderer.d.ts +7 -0
- package/dist/react/renderer.d.ts.map +1 -0
- package/dist/react/renderer.js +62 -0
- package/dist/react/renderer.js.map +1 -0
- package/dist/react.d.ts +4 -4
- package/dist/react.d.ts.map +1 -1
- package/package.json +4 -2
- package/src/contracts/events.ts +2 -1
- package/src/core/bridge.ts +280 -0
- package/src/core/controller.ts +83 -268
- package/src/react/announcer.ts +9 -0
- package/src/react/bindings.tsx +28 -72
- package/src/react/card.tsx +3 -3
- package/src/react/generators.ts +2 -2
- package/src/react/gestures.ts +1 -1
- package/src/react/host.tsx +10 -4
- package/src/react/motion.ts +4 -4
- package/src/react/plan.ts +2 -2
- package/src/react/renderer.tsx +77 -0
- package/src/react.ts +4 -4
package/src/react/host.tsx
CHANGED
|
@@ -269,7 +269,13 @@ function createHostRuntime(owner: Host) {
|
|
|
269
269
|
pathRef.current?.setAttribute('d', createRoundedRectPath(width, height, radius));
|
|
270
270
|
}
|
|
271
271
|
// The shadow token is a box-shadow: the SVG box follows the path's corners.
|
|
272
|
-
if (r.bg)
|
|
272
|
+
if (r.bg) {
|
|
273
|
+
r.bg.borderRadius = px(radius);
|
|
274
|
+
// Layout keeps the box at the top and a transform carries it to the bottom edge: a growing
|
|
275
|
+
// silhouette then moves no layout start point, so the morph is not counted as layout shift (CLS).
|
|
276
|
+
r.bg.top = '0px'; r.bg.bottom = 'auto';
|
|
277
|
+
r.bg.transform = `translateX(-50%) translateY(${px(top)})`;
|
|
278
|
+
}
|
|
273
279
|
if (r.clip) r.clip.clipPath = `path("${createRoundedRectPath(width, height, radius, (layout.width - width) / 2, top)}")`;
|
|
274
280
|
if (r.badge) {
|
|
275
281
|
const scale = still ? 1 : constants.badge.scale + (1 - constants.badge.scale) * frame.badge;
|
|
@@ -441,7 +447,7 @@ function createHostRuntime(owner: Host) {
|
|
|
441
447
|
if (plan.header && head) clones.header = inertClone(head);
|
|
442
448
|
const body = bodyElement();
|
|
443
449
|
// Rapid updates (progress text every 150 ms) must not restart the crossfade: within
|
|
444
|
-
// `bodyQuiet` of the previous update the new text lands in place
|
|
450
|
+
// `bodyQuiet` of the previous update the new text lands in place.
|
|
445
451
|
const now = motion?.now() ?? 0;
|
|
446
452
|
const rapid = plan.body && now - lastBodyUpdate < (motion?.constants.bodyQuiet ?? 0);
|
|
447
453
|
if (plan.body) lastBodyUpdate = now;
|
|
@@ -493,7 +499,7 @@ function createHostRuntime(owner: Host) {
|
|
|
493
499
|
else if (flung) motion.release('dragX', 0);
|
|
494
500
|
if (plan.presence === 'exit') motion.hide();
|
|
495
501
|
}
|
|
496
|
-
// An arrival keeps the shell
|
|
502
|
+
// An arrival keeps the shell: the title blur-swaps and the width springs to the new text.
|
|
497
503
|
if (plan.presence === 'enter' || plan.presence === 'replace') {
|
|
498
504
|
motion.enter(edge, reveal('presence'));
|
|
499
505
|
if (plan.presence === 'enter') {
|
|
@@ -857,7 +863,7 @@ function createHostRuntime(owner: Host) {
|
|
|
857
863
|
onClickCapture={event => {
|
|
858
864
|
const target = (event.target as Element).closest('button');
|
|
859
865
|
// A double click must not fire a one-shot action twice; close, the pill and the dots are
|
|
860
|
-
// repeatable on purpose (each click dismisses or shows another record
|
|
866
|
+
// repeatable on purpose (each click dismisses or shows another record).
|
|
861
867
|
const oneShot = !!target?.matches('[data-cloudlet-control="action"], [data-cloudlet-control="retry"], [data-cloudlet-control="cancel"]');
|
|
862
868
|
if (target && (repeating || (oneShot && event.detail > 1) || (activation && activation !== target))) { event.preventDefault(); event.stopPropagation(); }
|
|
863
869
|
activation = null;
|
package/src/react/motion.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { spring, tween as tweenGenerator } from './generators.js';
|
|
|
3
3
|
import type { Generator } from './generators.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Values
|
|
6
|
+
* Values tuned on the laboratory, the one place
|
|
7
7
|
* to tune them. Durations are milliseconds at `timeScale: 1`; offsets are CSS px.
|
|
8
8
|
*/
|
|
9
9
|
export const MOTION = {
|
|
@@ -33,7 +33,7 @@ export const MOTION = {
|
|
|
33
33
|
/** Reduced motion: every transition becomes an opacity change of this length; swipes are off. */
|
|
34
34
|
reduced: 80,
|
|
35
35
|
/**
|
|
36
|
-
* Swipes
|
|
36
|
+
* Swipes: the axis is decided after `intent` px; a release commits past
|
|
37
37
|
* `distance` of the swiped dimension, or after `minDistance` px with `velocity` px/ms
|
|
38
38
|
* towards the commit (a flick back cancels). Edges resist with the rubber-band
|
|
39
39
|
* coefficient; a trackpad swipe ends after `wheelIdle` ms without wheel events and commits
|
|
@@ -50,7 +50,7 @@ const tunable: CloudletMotionConstants = MOTION;
|
|
|
50
50
|
const positive = new Set(['stiffness', 'mass']);
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
|
-
* Resolves `ToasterMotion.overrides` (a debugging channel
|
|
53
|
+
* Resolves `ToasterMotion.overrides` (a debugging channel) onto the starting
|
|
54
54
|
* values. A field that is not a finite number in range (springs: stiffness and mass > 0,
|
|
55
55
|
* everything else ≥ 0) keeps its default; unknown keys are ignored.
|
|
56
56
|
*/
|
|
@@ -309,7 +309,7 @@ export function createShellMotion(options: ShellMotionOptions) {
|
|
|
309
309
|
enter(edge: -1 | 1, done?: () => void) {
|
|
310
310
|
request(time => {
|
|
311
311
|
jump('opacity', 0); jump('scale', m.enter.scale); jump('y', edge * m.enter.offset);
|
|
312
|
-
// The shell becomes opaque within `fade`; only scale and y follow the spring
|
|
312
|
+
// The shell becomes opaque within `fade`; only scale and y follow the spring.
|
|
313
313
|
to('opacity', 1, tween(m.enter.fade), time);
|
|
314
314
|
for (const key of ['scale', 'y'] as const) to(key, key === 'y' ? 0 : 1, enterSpring(), time);
|
|
315
315
|
after('presence', ['opacity', 'scale', 'y'], done);
|
package/src/react/plan.ts
CHANGED
|
@@ -14,7 +14,7 @@ export interface ShellView {
|
|
|
14
14
|
readonly total: number;
|
|
15
15
|
/** Tails behind the collapsed pill (0–2); none in the Island. */
|
|
16
16
|
readonly depth: number;
|
|
17
|
-
/** Missed notifications (overflow), part of the badge and the pill name
|
|
17
|
+
/** Missed notifications (overflow), part of the badge and the pill name. */
|
|
18
18
|
readonly missed: number;
|
|
19
19
|
/** Badge number: records in the stack plus missed ones; shown on the pill at ≥ 2 or with missed ones. */
|
|
20
20
|
readonly count: number;
|
|
@@ -79,7 +79,7 @@ export function planShell(previous: ShellView, next: ShellView): ShellPlan {
|
|
|
79
79
|
if (previous.open !== next.open) plan.morph = next.open ? 'open' : 'close';
|
|
80
80
|
if (before.handle !== after.handle) {
|
|
81
81
|
if (previous.open && next.open) {
|
|
82
|
-
// Only the body slides
|
|
82
|
+
// Only the body slides: the title and icon blur-swap in place.
|
|
83
83
|
plan.slide = next.index >= previous.index ? 1 : -1;
|
|
84
84
|
plan.header = headerKey(before) !== headerKey(after) || before.content.icon !== after.content.icon;
|
|
85
85
|
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { useEffect, useRef, useState, useSyncExternalStore } from 'react';
|
|
2
|
+
import type { ReactElement } from 'react';
|
|
3
|
+
import { createPortal } from 'react-dom';
|
|
4
|
+
import { getRendererBridge } from '../core/bridge.js';
|
|
5
|
+
import type { HostLease } from '../contracts/internal.js';
|
|
6
|
+
import type { ReactCloudletController, ToasterProps } from '../react.js';
|
|
7
|
+
import { Host } from './host.js';
|
|
8
|
+
|
|
9
|
+
// The renderer chunk: Toaster in bindings.tsx loads this module on the client once, after mount.
|
|
10
|
+
const subscribeMount = () => () => {};
|
|
11
|
+
const clientMounted = () => true;
|
|
12
|
+
const serverMounted = () => false;
|
|
13
|
+
|
|
14
|
+
interface Attachment {
|
|
15
|
+
readonly controller: ReactCloudletController;
|
|
16
|
+
readonly lease: HostLease;
|
|
17
|
+
readonly container: Element;
|
|
18
|
+
readonly document: Document;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function AttachedToaster({ controller, options }: { controller: ReactCloudletController; options: ToasterProps }): ReactElement | null {
|
|
22
|
+
// React supplies the server value during hydration, then the client value.
|
|
23
|
+
// The inert marker can therefore identify the owner document without a store
|
|
24
|
+
// or effect whose only purpose is an extra mounting render.
|
|
25
|
+
const mounted = useSyncExternalStore(subscribeMount, clientMounted, serverMounted);
|
|
26
|
+
const bridge = getRendererBridge(controller);
|
|
27
|
+
const snapshot = useSyncExternalStore(bridge.subscribe, bridge.getSnapshot, bridge.getServerSnapshot);
|
|
28
|
+
const marker = useRef<HTMLTemplateElement>(null);
|
|
29
|
+
const [attachment, setAttachment] = useState<Attachment | null>(null);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!mounted || !marker.current) return;
|
|
32
|
+
const ownerDocument = marker.current.ownerDocument;
|
|
33
|
+
let container: Element;
|
|
34
|
+
try {
|
|
35
|
+
const requested = typeof options.container === 'function' ? options.container() : options.container;
|
|
36
|
+
const candidate = requested ?? ownerDocument.body;
|
|
37
|
+
// nodeType/ownerDocument also work when the mounting React root is in another realm.
|
|
38
|
+
if (!candidate || candidate.nodeType !== 1 || candidate.ownerDocument !== ownerDocument
|
|
39
|
+
|| candidate.namespaceURI !== 'http://www.w3.org/1999/xhtml' || !candidate.isConnected
|
|
40
|
+
|| candidate.getRootNode().nodeType === 11) {
|
|
41
|
+
bridge.reportInvalidContainer('Toaster container must be a connected HTML Element in the mounting document, outside Shadow DOM');
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
container = candidate;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
bridge.reportInvalidContainer('Toaster container resolver failed', error);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const delay = options.attention?.delay;
|
|
50
|
+
let attached = bridge.attach(delay === undefined ? undefined : { attentionDelay: delay });
|
|
51
|
+
// An invalid delay must not suppress the host: fall back to the controller default and report it.
|
|
52
|
+
const invalidDelay = attached.status === 'rejected' && attached.reason === 'invalid-input';
|
|
53
|
+
if (invalidDelay) attached = bridge.attach();
|
|
54
|
+
if (attached.status !== 'attached') return;
|
|
55
|
+
if (invalidDelay) bridge.reportDiagnostic(attached.lease, { code: 'invalid-input', source: 'Toaster.attention',
|
|
56
|
+
message: 'attention.delay must be a finite nonnegative number of milliseconds' });
|
|
57
|
+
const current = { controller, lease: attached.lease, container, document: ownerDocument };
|
|
58
|
+
applyAutoDismiss(current.lease, false);
|
|
59
|
+
setAttachment(current);
|
|
60
|
+
return () => { bridge.detach(current.lease); };
|
|
61
|
+
// Container and attention delay are fixed for this attachment; changing them requires remount.
|
|
62
|
+
}, [controller, mounted]);
|
|
63
|
+
// Applied before the first presentation, then whenever the prop changes (which reports an invalid value once).
|
|
64
|
+
function applyAutoDismiss(lease: HostLease, report: boolean) {
|
|
65
|
+
const value = options.autoDismiss;
|
|
66
|
+
const valid = value === undefined || typeof value === 'boolean';
|
|
67
|
+
bridge.setAutoDismiss(lease, valid ? value : undefined);
|
|
68
|
+
if (!valid && report) bridge.reportDiagnostic(lease, { code: 'invalid-input', source: 'Toaster.autoDismiss',
|
|
69
|
+
message: 'autoDismiss must be a boolean' });
|
|
70
|
+
}
|
|
71
|
+
useEffect(() => { if (attachment) applyAutoDismiss(attachment.lease, true); }, [attachment, options.autoDismiss]);
|
|
72
|
+
|
|
73
|
+
if (!mounted) return null;
|
|
74
|
+
return <><template ref={marker} />{attachment?.controller === controller && !snapshot.disposed
|
|
75
|
+
? createPortal(<Host key={attachment.lease} bridge={bridge} lease={attachment.lease} snapshot={snapshot}
|
|
76
|
+
options={options} document={attachment.document} />, attachment.container) : null}</>;
|
|
77
|
+
}
|
package/src/react.ts
CHANGED
|
@@ -77,7 +77,7 @@ export interface ToasterAttention {
|
|
|
77
77
|
readonly delay?: number;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
/** A physical spring of
|
|
80
|
+
/** A physical spring of the motion system. */
|
|
81
81
|
export interface CloudletSpring {
|
|
82
82
|
readonly stiffness: number;
|
|
83
83
|
readonly damping: number;
|
|
@@ -91,7 +91,7 @@ export interface CloudletTimedSpring {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
/**
|
|
94
|
-
* The motion constants
|
|
94
|
+
* The motion constants: durations in ms at `timeScale: 1`, offsets and blur in CSS px.
|
|
95
95
|
* Reported by the laboratory's tuning panel; see `ToasterMotion.overrides`.
|
|
96
96
|
*/
|
|
97
97
|
export interface CloudletMotionConstants {
|
|
@@ -148,7 +148,7 @@ export interface ToasterMotion {
|
|
|
148
148
|
*/
|
|
149
149
|
readonly timeScale?: number;
|
|
150
150
|
/**
|
|
151
|
-
* Debugging and laboratory channel
|
|
151
|
+
* Debugging and laboratory channel: replaces the motion constants live, for
|
|
152
152
|
* transitions started after the change. A field that is not a finite number in range
|
|
153
153
|
* (stiffness and mass > 0, the rest ≥ 0) keeps its default. Not a styling API: the
|
|
154
154
|
* values may change between releases; do not ship overrides to production.
|
|
@@ -156,7 +156,7 @@ export interface ToasterMotion {
|
|
|
156
156
|
readonly overrides?: CloudletMotionOverrides;
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
/** Styling hooks of the renderer
|
|
159
|
+
/** Styling hooks of the renderer; see `ToasterProps.classNames`. */
|
|
160
160
|
export type CloudletPart = 'host' | 'stack' | 'pill' | 'tail' | 'badge' | 'island' | 'header' | 'icon' | 'title'
|
|
161
161
|
| 'close' | 'body' | 'description' | 'actions' | 'action' | 'indicator' | 'overflow';
|
|
162
162
|
|