@cloudlet/toast 0.0.0-stage → 1.0.0-rc.3
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 +236 -0
- package/LICENSE +21 -0
- package/README.md +64 -2
- package/THIRD_PARTY_NOTICES.md +149 -0
- package/dist/contracts/controller.d.ts +71 -0
- package/dist/contracts/controller.d.ts.map +1 -0
- package/dist/contracts/events.d.ts +72 -0
- package/dist/contracts/events.d.ts.map +1 -0
- package/dist/contracts/identity.d.ts +32 -0
- package/dist/contracts/identity.d.ts.map +1 -0
- package/dist/contracts/internal.d.ts +188 -0
- package/dist/contracts/internal.d.ts.map +1 -0
- package/dist/contracts/notifications.d.ts +101 -0
- package/dist/contracts/notifications.d.ts.map +1 -0
- package/dist/contracts/operations.d.ts +76 -0
- package/dist/contracts/operations.d.ts.map +1 -0
- package/dist/contracts/snapshots.d.ts +48 -0
- package/dist/contracts/snapshots.d.ts.map +1 -0
- package/dist/core/controller.d.ts +7 -0
- package/dist/core/controller.d.ts.map +1 -0
- package/dist/core/controller.js +954 -0
- package/dist/core/controller.js.map +1 -0
- package/dist/core/validation.d.ts +17 -0
- package/dist/core/validation.d.ts.map +1 -0
- package/dist/core/validation.js +298 -0
- package/dist/core/validation.js.map +1 -0
- package/dist/create-cloudlet.d.ts +5 -0
- package/dist/create-cloudlet.d.ts.map +1 -0
- package/dist/create-cloudlet.js +34 -0
- package/dist/create-cloudlet.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/react/announcer.d.ts +15 -0
- package/dist/react/announcer.d.ts.map +1 -0
- package/dist/react/announcer.js +134 -0
- package/dist/react/announcer.js.map +1 -0
- package/dist/react/bindings.d.ts +8 -0
- package/dist/react/bindings.d.ts.map +1 -0
- package/dist/react/bindings.js +84 -0
- package/dist/react/bindings.js.map +1 -0
- package/dist/react/card.d.ts +58 -0
- package/dist/react/card.d.ts.map +1 -0
- package/dist/react/card.js +300 -0
- package/dist/react/card.js.map +1 -0
- package/dist/react/generators.d.ts +46 -0
- package/dist/react/generators.d.ts.map +1 -0
- package/dist/react/generators.js +115 -0
- package/dist/react/generators.js.map +1 -0
- package/dist/react/gestures.d.ts +50 -0
- package/dist/react/gestures.d.ts.map +1 -0
- package/dist/react/gestures.js +239 -0
- package/dist/react/gestures.js.map +1 -0
- package/dist/react/host.d.ts +37 -0
- package/dist/react/host.d.ts.map +1 -0
- package/dist/react/host.js +816 -0
- package/dist/react/host.js.map +1 -0
- package/dist/react/motion.d.ts +206 -0
- package/dist/react/motion.d.ts.map +1 -0
- package/dist/react/motion.js +414 -0
- package/dist/react/motion.js.map +1 -0
- package/dist/react/plan.d.ts +45 -0
- package/dist/react/plan.d.ts.map +1 -0
- package/dist/react/plan.js +58 -0
- package/dist/react/plan.js.map +1 -0
- package/dist/react/shape.d.ts +7 -0
- package/dist/react/shape.d.ts.map +1 -0
- package/dist/react/shape.js +21 -0
- package/dist/react/shape.js.map +1 -0
- package/dist/react/viewport.d.ts +15 -0
- package/dist/react/viewport.d.ts.map +1 -0
- package/dist/react/viewport.js +16 -0
- package/dist/react/viewport.js.map +1 -0
- package/dist/react.d.ts +176 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +2 -0
- package/dist/styles.css +1 -0
- package/package.json +17 -4
- package/src/contracts/controller.ts +61 -0
- package/src/contracts/events.ts +47 -0
- package/src/contracts/identity.ts +27 -0
- package/src/contracts/internal.ts +150 -0
- package/src/contracts/notifications.ts +104 -0
- package/src/contracts/operations.ts +71 -0
- package/src/contracts/snapshots.ts +59 -0
- package/src/core/controller.ts +1038 -0
- package/src/core/validation.ts +290 -0
- package/src/create-cloudlet.ts +43 -0
- package/src/index.ts +34 -0
- package/src/react/announcer.ts +189 -0
- package/src/react/bindings.tsx +100 -0
- package/src/react/card.tsx +222 -0
- package/src/react/generators.ts +274 -0
- package/src/react/gestures.ts +296 -0
- package/src/react/host.tsx +947 -0
- package/src/react/motion.ts +484 -0
- package/src/react/plan.ts +101 -0
- package/src/react/shape.ts +33 -0
- package/src/react/viewport.ts +10 -0
- package/src/react.ts +190 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { ActionAttemptToken, InputIssue, NotificationHandle } from './identity.js';
|
|
2
|
+
|
|
3
|
+
export type NotificationKind = 'info' | 'success' | 'loading' | 'warning' | 'error';
|
|
4
|
+
export type Priority = 'normal' | 'high';
|
|
5
|
+
export type AnnouncementPriority = 'polite' | 'assertive' | 'off';
|
|
6
|
+
export type Duration = number | null;
|
|
7
|
+
/** Auto-open rule: `auto` opens for an action, a retryable operation or a description; `open` always; `stack` never. */
|
|
8
|
+
export type Attention = 'auto' | 'open' | 'stack';
|
|
9
|
+
|
|
10
|
+
/** Core treats Slot as opaque and never traverses or freezes its payload. */
|
|
11
|
+
export type Description<Slot = never> =
|
|
12
|
+
| { readonly kind: 'text'; readonly text: string }
|
|
13
|
+
| { readonly kind: 'rich'; readonly content: Slot; readonly announcement: string };
|
|
14
|
+
|
|
15
|
+
export type Progress =
|
|
16
|
+
| { readonly kind: 'indeterminate'; readonly label?: string }
|
|
17
|
+
| { readonly kind: 'determinate'; readonly value: number; readonly label?: string };
|
|
18
|
+
|
|
19
|
+
export interface ActionContext {
|
|
20
|
+
readonly handle: NotificationHandle;
|
|
21
|
+
readonly token: ActionAttemptToken;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface CommandAction {
|
|
25
|
+
readonly kind: 'command';
|
|
26
|
+
readonly label: string;
|
|
27
|
+
readonly run: (context: ActionContext) => unknown;
|
|
28
|
+
readonly errorMessage?: (error: unknown) => string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface NavigationAction {
|
|
32
|
+
readonly kind: 'link';
|
|
33
|
+
readonly label: string;
|
|
34
|
+
readonly href: string;
|
|
35
|
+
readonly target?: '_self' | '_blank' | '_parent' | '_top';
|
|
36
|
+
readonly rel?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type PrimaryAction = CommandAction | NavigationAction;
|
|
40
|
+
|
|
41
|
+
export interface NotificationContent<Slot = never> {
|
|
42
|
+
readonly title: string;
|
|
43
|
+
readonly description?: Description<Slot>;
|
|
44
|
+
readonly icon?: Slot;
|
|
45
|
+
readonly progress?: Progress;
|
|
46
|
+
readonly action?: PrimaryAction;
|
|
47
|
+
readonly announcementPriority?: AnnouncementPriority;
|
|
48
|
+
/** Omitted = policy default; null = persistent; number = readable milliseconds. */
|
|
49
|
+
readonly duration?: Duration;
|
|
50
|
+
/** Omitted = `auto`. */
|
|
51
|
+
readonly attention?: Attention;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type CloseReason =
|
|
55
|
+
| 'timeout'
|
|
56
|
+
| 'programmatic'
|
|
57
|
+
| 'close-button'
|
|
58
|
+
| 'swipe'
|
|
59
|
+
| 'action-success'
|
|
60
|
+
| 'navigation'
|
|
61
|
+
| 'clear'
|
|
62
|
+
| 'dispose';
|
|
63
|
+
|
|
64
|
+
export interface CloseNotice {
|
|
65
|
+
readonly handle: NotificationHandle;
|
|
66
|
+
readonly reason: CloseReason;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface NotificationSpec<Slot = never> extends NotificationContent<Slot> {
|
|
70
|
+
readonly id?: string;
|
|
71
|
+
readonly kind?: NotificationKind;
|
|
72
|
+
readonly priority?: Priority;
|
|
73
|
+
readonly dedupeKey?: string;
|
|
74
|
+
readonly onClose?: (notice: CloseNotice) => void;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Omitted preserves; null removes optional content. IDs/dedupe keys are immutable. */
|
|
78
|
+
export interface NotificationPatch<Slot = never> {
|
|
79
|
+
readonly title?: string;
|
|
80
|
+
readonly kind?: NotificationKind;
|
|
81
|
+
readonly description?: Description<Slot> | null;
|
|
82
|
+
readonly icon?: Slot | null;
|
|
83
|
+
readonly progress?: Progress | null;
|
|
84
|
+
readonly action?: PrimaryAction | null;
|
|
85
|
+
readonly priority?: Priority;
|
|
86
|
+
readonly announcementPriority?: AnnouncementPriority;
|
|
87
|
+
readonly duration?: Duration;
|
|
88
|
+
readonly attention?: Attention;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export type AdmissionRejection = 'disposed' | 'invalid-input' | 'id-conflict' | 'capacity';
|
|
92
|
+
|
|
93
|
+
export type AdmissionResult =
|
|
94
|
+
| { readonly status: 'created'; readonly handle: NotificationHandle }
|
|
95
|
+
| { readonly status: 'deduplicated'; readonly handle: NotificationHandle; readonly occurrences: number }
|
|
96
|
+
| { readonly status: 'rejected'; readonly reason: AdmissionRejection; readonly issues?: readonly InputIssue[] };
|
|
97
|
+
|
|
98
|
+
/** Track never participates in deduplication. */
|
|
99
|
+
export type OperationAdmissionResult = Exclude<AdmissionResult, { readonly status: 'deduplicated' }>;
|
|
100
|
+
|
|
101
|
+
export interface OverflowSnapshot {
|
|
102
|
+
readonly count: number;
|
|
103
|
+
readonly pending: boolean;
|
|
104
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { NotificationHandle, OperationAttemptToken, Unsubscribe } from './identity.js';
|
|
2
|
+
import type { NotificationContent, OperationAdmissionResult, Priority, CloseNotice } from './notifications.js';
|
|
3
|
+
|
|
4
|
+
/** Minimal abort port: native AbortSignal can implement it; core requires no DOM lib. */
|
|
5
|
+
export interface CancellationSignal {
|
|
6
|
+
readonly aborted: boolean;
|
|
7
|
+
readonly reason: unknown;
|
|
8
|
+
readonly throwIfAborted: () => void;
|
|
9
|
+
readonly addEventListener: (type: 'abort', listener: () => void, options?: { readonly once?: boolean }) => void;
|
|
10
|
+
readonly removeEventListener: (type: 'abort', listener: () => void) => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface OperationContext<Signal extends CancellationSignal = CancellationSignal> {
|
|
14
|
+
readonly signal: Signal;
|
|
15
|
+
readonly token: OperationAttemptToken;
|
|
16
|
+
readonly attempt: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type OperationFactory<T, Signal extends CancellationSignal = CancellationSignal> = (context: OperationContext<Signal>) => T | PromiseLike<T>;
|
|
20
|
+
export type OperationSource<T, Signal extends CancellationSignal = CancellationSignal> = PromiseLike<T> | OperationFactory<T, Signal>;
|
|
21
|
+
export type OperationStatus = 'pending' | 'fulfilled' | 'rejected' | 'cancelled';
|
|
22
|
+
|
|
23
|
+
export interface OperationSnapshot {
|
|
24
|
+
readonly token: OperationAttemptToken;
|
|
25
|
+
readonly attempt: number;
|
|
26
|
+
readonly status: OperationStatus;
|
|
27
|
+
readonly cancelRequested: boolean;
|
|
28
|
+
readonly canCancel: boolean;
|
|
29
|
+
readonly canRetry: boolean;
|
|
30
|
+
readonly notification: NotificationHandle | null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface TrackOptions<T, Slot = never, Signal extends CancellationSignal = CancellationSignal> {
|
|
34
|
+
readonly id?: string;
|
|
35
|
+
readonly priority?: Priority;
|
|
36
|
+
readonly pending: Omit<NotificationContent<Slot>, 'duration'> & { readonly duration?: never };
|
|
37
|
+
readonly success: NotificationContent<Slot> | ((value: T) => NotificationContent<Slot>);
|
|
38
|
+
readonly error: NotificationContent<Slot> | ((error: unknown) => NotificationContent<Slot>);
|
|
39
|
+
readonly cancelled?: NotificationContent<Slot> | ((reason: unknown) => NotificationContent<Slot>);
|
|
40
|
+
/** Optional cooperative cancellation for an already-created promise. */
|
|
41
|
+
readonly cancel?: (reason: unknown) => void;
|
|
42
|
+
readonly isCancellation?: (error: unknown, context: OperationContext<Signal>) => boolean;
|
|
43
|
+
readonly onClose?: (notice: CloseNotice) => void;
|
|
44
|
+
readonly dedupeKey?: never;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface OperationAttempt<T> {
|
|
48
|
+
readonly token: OperationAttemptToken;
|
|
49
|
+
readonly attempt: number;
|
|
50
|
+
/** Preserves the business value/rejection, including cancellation rejection. */
|
|
51
|
+
readonly result: Promise<T>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type AttemptStartResult<T> =
|
|
55
|
+
| { readonly status: 'started'; readonly attempt: OperationAttempt<T> }
|
|
56
|
+
| { readonly status: 'rejected'; readonly reason: 'disposed' | 'not-retryable' | 'already-pending' };
|
|
57
|
+
|
|
58
|
+
export type CancelResult =
|
|
59
|
+
| { readonly status: 'requested' }
|
|
60
|
+
| { readonly status: 'unchanged'; readonly reason: 'already-requested' | 'settled' }
|
|
61
|
+
| { readonly status: 'rejected'; readonly reason: 'disposed' | 'not-cancellable' };
|
|
62
|
+
|
|
63
|
+
export interface OperationHandle<T> extends OperationAttempt<T> {
|
|
64
|
+
/** Initial admission is immutable, independent of every attempt's result. */
|
|
65
|
+
readonly admission: OperationAdmissionResult;
|
|
66
|
+
readonly getSnapshot: () => OperationSnapshot;
|
|
67
|
+
readonly subscribe: (listener: () => void) => Unsubscribe;
|
|
68
|
+
readonly cancel: (reason?: unknown) => CancelResult;
|
|
69
|
+
readonly retry: () => AttemptStartResult<T>;
|
|
70
|
+
readonly restart: () => AttemptStartResult<T>;
|
|
71
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { ActionAttemptToken, ControllerIdentity, NotificationHandle } from './identity.js';
|
|
2
|
+
import type { NotificationContent, NotificationKind, OverflowSnapshot, Priority } from './notifications.js';
|
|
3
|
+
import type { OperationSnapshot } from './operations.js';
|
|
4
|
+
|
|
5
|
+
export type PauseReason =
|
|
6
|
+
| 'inactive'
|
|
7
|
+
| 'no-host'
|
|
8
|
+
| 'presentation-pending'
|
|
9
|
+
| 'hover'
|
|
10
|
+
| 'focus'
|
|
11
|
+
| 'gesture'
|
|
12
|
+
| 'action-pending'
|
|
13
|
+
| 'content-transition'
|
|
14
|
+
| 'island'
|
|
15
|
+
| 'document-hidden'
|
|
16
|
+
| 'window-blur';
|
|
17
|
+
|
|
18
|
+
export type ActionSnapshot =
|
|
19
|
+
| { readonly status: 'idle' }
|
|
20
|
+
| { readonly status: 'pending'; readonly token: ActionAttemptToken }
|
|
21
|
+
| { readonly status: 'failed'; readonly token: ActionAttemptToken; readonly message: string };
|
|
22
|
+
|
|
23
|
+
/** `current` is the one presented record: the top pill when collapsed, `island.current` when open. */
|
|
24
|
+
export type NotificationLocation = 'stack' | 'current';
|
|
25
|
+
|
|
26
|
+
export interface NotificationSnapshot<Slot = never> {
|
|
27
|
+
readonly handle: NotificationHandle;
|
|
28
|
+
readonly kind: NotificationKind;
|
|
29
|
+
readonly content: Readonly<NotificationContent<Slot>>;
|
|
30
|
+
readonly priority: Priority;
|
|
31
|
+
readonly occurrences: number;
|
|
32
|
+
readonly location: NotificationLocation;
|
|
33
|
+
readonly remainingMs: number | null;
|
|
34
|
+
readonly pauseReasons: readonly PauseReason[];
|
|
35
|
+
readonly operation: OperationSnapshot | null;
|
|
36
|
+
readonly action: ActionSnapshot;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type IslandReason = 'user' | 'attention';
|
|
40
|
+
|
|
41
|
+
export interface IslandSnapshot {
|
|
42
|
+
readonly open: boolean;
|
|
43
|
+
/** Null exactly when the Island is closed. */
|
|
44
|
+
readonly reason: IslandReason | null;
|
|
45
|
+
/** Null exactly when the Island is closed. */
|
|
46
|
+
readonly current: NotificationHandle | null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface ControllerSnapshot<Slot = never> {
|
|
50
|
+
readonly controller: ControllerIdentity | null;
|
|
51
|
+
readonly revision: number;
|
|
52
|
+
readonly disposed: boolean;
|
|
53
|
+
/** Admission order, oldest first. */
|
|
54
|
+
readonly notifications: readonly NotificationSnapshot<Slot>[];
|
|
55
|
+
/** The same records in presentation order: newest first, index 0 is the top pill. */
|
|
56
|
+
readonly stack: readonly NotificationHandle[];
|
|
57
|
+
readonly island: IslandSnapshot;
|
|
58
|
+
readonly overflow: OverflowSnapshot;
|
|
59
|
+
}
|