@foldkit/ui 0.112.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.
Files changed (201) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +67 -0
  3. package/dist/anchor.d.ts +38 -0
  4. package/dist/anchor.d.ts.map +1 -0
  5. package/dist/anchor.js +142 -0
  6. package/dist/animation/index.d.ts +49 -0
  7. package/dist/animation/index.d.ts.map +1 -0
  8. package/dist/animation/index.js +75 -0
  9. package/dist/animation/public.d.ts +3 -0
  10. package/dist/animation/public.d.ts.map +1 -0
  11. package/dist/animation/public.js +1 -0
  12. package/dist/animation/schema.d.ts +43 -0
  13. package/dist/animation/schema.d.ts.map +1 -0
  14. package/dist/animation/schema.js +41 -0
  15. package/dist/animation/update.d.ts +24 -0
  16. package/dist/animation/update.d.ts.map +1 -0
  17. package/dist/animation/update.js +67 -0
  18. package/dist/button/index.d.ts +17 -0
  19. package/dist/button/index.d.ts.map +1 -0
  20. package/dist/button/index.js +22 -0
  21. package/dist/button/public.d.ts +3 -0
  22. package/dist/button/public.d.ts.map +1 -0
  23. package/dist/button/public.js +1 -0
  24. package/dist/calendar/index.d.ts +462 -0
  25. package/dist/calendar/index.d.ts.map +1 -0
  26. package/dist/calendar/index.js +825 -0
  27. package/dist/calendar/public.d.ts +3 -0
  28. package/dist/calendar/public.d.ts.map +1 -0
  29. package/dist/calendar/public.js +1 -0
  30. package/dist/checkbox/index.d.ts +119 -0
  31. package/dist/checkbox/index.d.ts.map +1 -0
  32. package/dist/checkbox/index.js +111 -0
  33. package/dist/checkbox/public.d.ts +3 -0
  34. package/dist/checkbox/public.d.ts.map +1 -0
  35. package/dist/checkbox/public.js +1 -0
  36. package/dist/combobox/multi.d.ts +183 -0
  37. package/dist/combobox/multi.d.ts.map +1 -0
  38. package/dist/combobox/multi.js +81 -0
  39. package/dist/combobox/multiPublic.d.ts +3 -0
  40. package/dist/combobox/multiPublic.d.ts.map +1 -0
  41. package/dist/combobox/multiPublic.js +1 -0
  42. package/dist/combobox/public.d.ts +7 -0
  43. package/dist/combobox/public.d.ts.map +1 -0
  44. package/dist/combobox/public.js +3 -0
  45. package/dist/combobox/shared.d.ts +423 -0
  46. package/dist/combobox/shared.d.ts.map +1 -0
  47. package/dist/combobox/shared.js +708 -0
  48. package/dist/combobox/single.d.ts +198 -0
  49. package/dist/combobox/single.d.ts.map +1 -0
  50. package/dist/combobox/single.js +106 -0
  51. package/dist/datePicker/index.d.ts +457 -0
  52. package/dist/datePicker/index.d.ts.map +1 -0
  53. package/dist/datePicker/index.js +318 -0
  54. package/dist/datePicker/public.d.ts +3 -0
  55. package/dist/datePicker/public.d.ts.map +1 -0
  56. package/dist/datePicker/public.js +1 -0
  57. package/dist/dialog/index.d.ts +160 -0
  58. package/dist/dialog/index.d.ts.map +1 -0
  59. package/dist/dialog/index.js +211 -0
  60. package/dist/dialog/public.d.ts +3 -0
  61. package/dist/dialog/public.d.ts.map +1 -0
  62. package/dist/dialog/public.js +1 -0
  63. package/dist/disclosure/index.d.ts +110 -0
  64. package/dist/disclosure/index.d.ts.map +1 -0
  65. package/dist/disclosure/index.js +111 -0
  66. package/dist/disclosure/public.d.ts +3 -0
  67. package/dist/disclosure/public.d.ts.map +1 -0
  68. package/dist/disclosure/public.js +1 -0
  69. package/dist/dragAndDrop/index.d.ts +540 -0
  70. package/dist/dragAndDrop/index.d.ts.map +1 -0
  71. package/dist/dragAndDrop/index.js +535 -0
  72. package/dist/dragAndDrop/public.d.ts +3 -0
  73. package/dist/dragAndDrop/public.d.ts.map +1 -0
  74. package/dist/dragAndDrop/public.js +1 -0
  75. package/dist/fieldset/index.d.ts +21 -0
  76. package/dist/fieldset/index.d.ts.map +1 -0
  77. package/dist/fieldset/index.js +25 -0
  78. package/dist/fieldset/public.d.ts +3 -0
  79. package/dist/fieldset/public.d.ts.map +1 -0
  80. package/dist/fieldset/public.js +1 -0
  81. package/dist/fileDrop/index.d.ts +109 -0
  82. package/dist/fileDrop/index.d.ts.map +1 -0
  83. package/dist/fileDrop/index.js +127 -0
  84. package/dist/fileDrop/public.d.ts +3 -0
  85. package/dist/fileDrop/public.d.ts.map +1 -0
  86. package/dist/fileDrop/public.js +1 -0
  87. package/dist/group.d.ts +8 -0
  88. package/dist/group.d.ts.map +1 -0
  89. package/dist/group.js +13 -0
  90. package/dist/index.d.ts +25 -0
  91. package/dist/index.d.ts.map +1 -0
  92. package/dist/index.js +24 -0
  93. package/dist/input/index.d.ts +26 -0
  94. package/dist/input/index.d.ts.map +1 -0
  95. package/dist/input/index.js +43 -0
  96. package/dist/input/public.d.ts +3 -0
  97. package/dist/input/public.d.ts.map +1 -0
  98. package/dist/input/public.js +1 -0
  99. package/dist/internal/optionExtensions.d.ts +6 -0
  100. package/dist/internal/optionExtensions.d.ts.map +1 -0
  101. package/dist/internal/optionExtensions.js +2 -0
  102. package/dist/keyboard.d.ts +6 -0
  103. package/dist/keyboard.d.ts.map +1 -0
  104. package/dist/keyboard.js +9 -0
  105. package/dist/listbox/multi.d.ts +189 -0
  106. package/dist/listbox/multi.d.ts.map +1 -0
  107. package/dist/listbox/multi.js +65 -0
  108. package/dist/listbox/multiPublic.d.ts +3 -0
  109. package/dist/listbox/multiPublic.d.ts.map +1 -0
  110. package/dist/listbox/multiPublic.js +1 -0
  111. package/dist/listbox/public.d.ts +7 -0
  112. package/dist/listbox/public.d.ts.map +1 -0
  113. package/dist/listbox/public.js +3 -0
  114. package/dist/listbox/shared.d.ts +432 -0
  115. package/dist/listbox/shared.d.ts.map +1 -0
  116. package/dist/listbox/shared.js +670 -0
  117. package/dist/listbox/single.d.ts +207 -0
  118. package/dist/listbox/single.d.ts.map +1 -0
  119. package/dist/listbox/single.js +73 -0
  120. package/dist/menu/index.d.ts +368 -0
  121. package/dist/menu/index.d.ts.map +1 -0
  122. package/dist/menu/index.js +682 -0
  123. package/dist/menu/public.d.ts +4 -0
  124. package/dist/menu/public.d.ts.map +1 -0
  125. package/dist/menu/public.js +1 -0
  126. package/dist/popover/index.d.ts +267 -0
  127. package/dist/popover/index.d.ts.map +1 -0
  128. package/dist/popover/index.js +346 -0
  129. package/dist/popover/public.d.ts +4 -0
  130. package/dist/popover/public.d.ts.map +1 -0
  131. package/dist/popover/public.js +1 -0
  132. package/dist/radioGroup/index.d.ts +169 -0
  133. package/dist/radioGroup/index.d.ts.map +1 -0
  134. package/dist/radioGroup/index.js +197 -0
  135. package/dist/radioGroup/public.d.ts +3 -0
  136. package/dist/radioGroup/public.d.ts.map +1 -0
  137. package/dist/radioGroup/public.js +1 -0
  138. package/dist/select/index.d.ts +24 -0
  139. package/dist/select/index.d.ts.map +1 -0
  140. package/dist/select/index.js +40 -0
  141. package/dist/select/public.d.ts +3 -0
  142. package/dist/select/public.d.ts.map +1 -0
  143. package/dist/select/public.js +1 -0
  144. package/dist/slider/index.d.ts +318 -0
  145. package/dist/slider/index.d.ts.map +1 -0
  146. package/dist/slider/index.js +337 -0
  147. package/dist/slider/public.d.ts +3 -0
  148. package/dist/slider/public.d.ts.map +1 -0
  149. package/dist/slider/public.js +1 -0
  150. package/dist/switch/index.d.ts +99 -0
  151. package/dist/switch/index.d.ts.map +1 -0
  152. package/dist/switch/index.js +107 -0
  153. package/dist/switch/public.d.ts +3 -0
  154. package/dist/switch/public.d.ts.map +1 -0
  155. package/dist/switch/public.js +1 -0
  156. package/dist/tabs/index.d.ts +155 -0
  157. package/dist/tabs/index.d.ts.map +1 -0
  158. package/dist/tabs/index.js +185 -0
  159. package/dist/tabs/public.d.ts +3 -0
  160. package/dist/tabs/public.d.ts.map +1 -0
  161. package/dist/tabs/public.js +1 -0
  162. package/dist/test/apps/disabledButton.d.ts +38 -0
  163. package/dist/test/apps/disabledButton.d.ts.map +1 -0
  164. package/dist/test/apps/disabledButton.js +71 -0
  165. package/dist/textarea/index.d.ts +26 -0
  166. package/dist/textarea/index.d.ts.map +1 -0
  167. package/dist/textarea/index.js +44 -0
  168. package/dist/textarea/public.d.ts +3 -0
  169. package/dist/textarea/public.d.ts.map +1 -0
  170. package/dist/textarea/public.js +1 -0
  171. package/dist/toast/index.d.ts +608 -0
  172. package/dist/toast/index.d.ts.map +1 -0
  173. package/dist/toast/index.js +146 -0
  174. package/dist/toast/public.d.ts +4 -0
  175. package/dist/toast/public.d.ts.map +1 -0
  176. package/dist/toast/public.js +1 -0
  177. package/dist/toast/schema.d.ts +154 -0
  178. package/dist/toast/schema.d.ts.map +1 -0
  179. package/dist/toast/schema.js +93 -0
  180. package/dist/toast/update.d.ts +510 -0
  181. package/dist/toast/update.d.ts.map +1 -0
  182. package/dist/toast/update.js +225 -0
  183. package/dist/tooltip/index.d.ts +170 -0
  184. package/dist/tooltip/index.d.ts.map +1 -0
  185. package/dist/tooltip/index.js +253 -0
  186. package/dist/tooltip/public.d.ts +4 -0
  187. package/dist/tooltip/public.d.ts.map +1 -0
  188. package/dist/tooltip/public.js +1 -0
  189. package/dist/typeahead.d.ts +4 -0
  190. package/dist/typeahead.d.ts.map +1 -0
  191. package/dist/typeahead.js +14 -0
  192. package/dist/virtualList/index.d.ts +203 -0
  193. package/dist/virtualList/index.d.ts.map +1 -0
  194. package/dist/virtualList/index.js +392 -0
  195. package/dist/virtualList/public.d.ts +3 -0
  196. package/dist/virtualList/public.d.ts.map +1 -0
  197. package/dist/virtualList/public.js +1 -0
  198. package/dist/vitest-setup.d.ts +2 -0
  199. package/dist/vitest-setup.d.ts.map +1 -0
  200. package/dist/vitest-setup.js +2 -0
  201. package/package.json +161 -0
@@ -0,0 +1,146 @@
1
+ import { Match as M } from 'effect';
2
+ import { childAttributes, html, } from 'foldkit/html';
3
+ import { defineView } from 'foldkit/submodel';
4
+ import { Dismissed, DismissedAll, ElapsedDuration, GotAnimationMessage, HoveredEntry, LeftEntry, Position, Variant, } from './schema.js';
5
+ import { DismissAfter, makeRuntime } from './update.js';
6
+ export { Variant, Position, Dismissed, DismissedAll, ElapsedDuration, HoveredEntry, LeftEntry, GotAnimationMessage, DismissAfter, };
7
+ const variantToRole = (variant) => M.value(variant).pipe(M.withReturnType(), M.when('Info', () => 'status'), M.when('Success', () => 'status'), M.when('Warning', () => 'alert'), M.when('Error', () => 'alert'), M.exhaustive);
8
+ const positionToContainerStyle = (position) => {
9
+ const base = {
10
+ position: 'fixed',
11
+ display: 'flex',
12
+ gap: '8px',
13
+ padding: '16px',
14
+ margin: '0',
15
+ listStyle: 'none',
16
+ pointerEvents: 'none',
17
+ zIndex: '2147483600',
18
+ };
19
+ return M.value(position).pipe(M.withReturnType(), M.when('TopLeft', () => ({
20
+ ...base,
21
+ top: '0',
22
+ left: '0',
23
+ flexDirection: 'column-reverse',
24
+ })), M.when('TopCenter', () => ({
25
+ ...base,
26
+ top: '0',
27
+ left: '50%',
28
+ transform: 'translateX(-50%)',
29
+ flexDirection: 'column-reverse',
30
+ })), M.when('TopRight', () => ({
31
+ ...base,
32
+ top: '0',
33
+ right: '0',
34
+ flexDirection: 'column-reverse',
35
+ })), M.when('BottomLeft', () => ({
36
+ ...base,
37
+ bottom: '0',
38
+ left: '0',
39
+ flexDirection: 'column',
40
+ })), M.when('BottomCenter', () => ({
41
+ ...base,
42
+ bottom: '0',
43
+ left: '50%',
44
+ transform: 'translateX(-50%)',
45
+ flexDirection: 'column',
46
+ })), M.when('BottomRight', () => ({
47
+ ...base,
48
+ bottom: '0',
49
+ right: '0',
50
+ flexDirection: 'column',
51
+ })), M.exhaustive);
52
+ };
53
+ const DEFAULT_ARIA_LABEL = 'Notifications';
54
+ /** Factory that binds `Toast` to a user-provided payload schema. The
55
+ * returned module contains everything needed to wire a toast stack into an
56
+ * app: `Model`, `Message`, `Entry`, `Added`, `init`, `update`, `show` /
57
+ * `dismiss` / `dismissAll` helpers, and the headless `view`.
58
+ *
59
+ * The payload is whatever content shape the consumer supplies via Schema.
60
+ * The component never reads it. It flows through to `entryToView`. The
61
+ * component itself owns only lifecycle and a11y fields (id, variant,
62
+ * animation, dismiss timer, hover state).
63
+ *
64
+ * Consume the bound module's exports everywhere. `Toast.Model` in your app
65
+ * Model, `Toast.Message` in your parent Message union, `Toast.show` /
66
+ * `Toast.dismiss` in your update, `Toast.view` in your view. The top-level
67
+ * exports (`Variant`, `Position`, static message tags, `DismissAfter`) are
68
+ * payload-independent and safe to reference when you need them without a
69
+ * bound module, but the typical path is through the factory return.
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * const ToastPayload = S.Struct({
74
+ * bodyText: S.String,
75
+ * maybeLink: S.Option(S.Struct({
76
+ * href: S.String,
77
+ * text: S.String,
78
+ * })),
79
+ * })
80
+ * export const Toast = Toast.make(ToastPayload)
81
+ * ```
82
+ */
83
+ export const make = (payloadSchema) => {
84
+ const runtime = makeRuntime(payloadSchema);
85
+ /** Renders a headless toast stack. The `<ol>` container is always present
86
+ * in the DOM so screen readers can observe its `aria-live` region from
87
+ * page load. Each entry becomes an `<li>` keyed by its id, with
88
+ * animation data attributes (`data-enter`, `data-leave`,
89
+ * `data-transition`, `data-closed`) and `data-variant` reflecting the
90
+ * entry's variant. */
91
+ const view = defineView((model, viewInputs) => {
92
+ const h = html();
93
+ const { id, entries } = model;
94
+ const { position, entryToView, ariaLabel = DEFAULT_ARIA_LABEL, containerClassName, entryClassName, } = viewInputs;
95
+ const containerAttributes = [
96
+ h.Id(id),
97
+ h.Role('region'),
98
+ h.AriaLabel(ariaLabel),
99
+ h.AriaLive('polite'),
100
+ h.Style(positionToContainerStyle(position)),
101
+ ...(containerClassName ? [h.Class(containerClassName)] : []),
102
+ ];
103
+ const renderEntryItem = (entry) => {
104
+ const { transitionState } = entry.animation;
105
+ const animationAttributes = M.value(transitionState).pipe(M.when('EnterStart', () => [
106
+ h.DataAttribute('closed', ''),
107
+ h.DataAttribute('enter', ''),
108
+ h.DataAttribute('transition', ''),
109
+ ]), M.when('EnterAnimating', () => [
110
+ h.DataAttribute('enter', ''),
111
+ h.DataAttribute('transition', ''),
112
+ ]), M.when('LeaveStart', () => [
113
+ h.DataAttribute('leave', ''),
114
+ h.DataAttribute('transition', ''),
115
+ ]), M.when('LeaveAnimating', () => [
116
+ h.DataAttribute('closed', ''),
117
+ h.DataAttribute('leave', ''),
118
+ h.DataAttribute('transition', ''),
119
+ ]), M.orElse(() => []));
120
+ const itemAttributes = [
121
+ h.Id(entry.id),
122
+ h.Role(variantToRole(entry.variant)),
123
+ h.AriaAtomic(true),
124
+ h.DataAttribute('variant', entry.variant),
125
+ h.Style({ pointerEvents: 'auto' }),
126
+ h.OnMouseEnter(HoveredEntry({ entryId: entry.id })),
127
+ h.OnMouseLeave(LeftEntry({ entryId: entry.id })),
128
+ ...animationAttributes,
129
+ ...(entryClassName ? [h.Class(entryClassName)] : []),
130
+ ];
131
+ const handlers = {
132
+ dismiss: childAttributes([
133
+ h.OnClick(Dismissed({ entryId: entry.id })),
134
+ ]),
135
+ };
136
+ return h.keyed('li')(entry.id, itemAttributes, [
137
+ entryToView(entry, handlers),
138
+ ]);
139
+ };
140
+ return h.keyed('ol')(id, containerAttributes, entries.map(renderEntryItem));
141
+ });
142
+ return {
143
+ ...runtime,
144
+ view,
145
+ };
146
+ };
@@ -0,0 +1,4 @@
1
+ export { make, Variant, Position, Dismissed, DismissedAll, ElapsedDuration, HoveredEntry, LeftEntry, GotAnimationMessage, DismissAfter, } from './index.js';
2
+ export type { EntryHandlers } from './index.js';
3
+ export type { InitConfig, ShowInput } from './index.js';
4
+ //# sourceMappingURL=public.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../src/toast/public.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,SAAS,EACT,mBAAmB,EACnB,YAAY,GACb,MAAM,YAAY,CAAA;AAEnB,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC/C,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA"}
@@ -0,0 +1 @@
1
+ export { make, Variant, Position, Dismissed, DismissedAll, ElapsedDuration, HoveredEntry, LeftEntry, GotAnimationMessage, DismissAfter, } from './index.js';
@@ -0,0 +1,154 @@
1
+ import { Duration, Schema as S } from 'effect';
2
+ /** Semantic category of a toast. Drives the default ARIA role: `status` for
3
+ * `Info` / `Success`, `alert` for `Warning` / `Error`. Also surfaced as
4
+ * `data-variant` on each entry for per-variant CSS. This is the only
5
+ * content-adjacent field the component owns. The rest of the entry's
6
+ * content lives in the user-provided payload. */
7
+ export declare const Variant: S.Literals<readonly ["Info", "Success", "Warning", "Error"]>;
8
+ export type Variant = typeof Variant.Type;
9
+ /** Where the toast viewport is anchored on the screen and how entries stack. */
10
+ export declare const Position: S.Literals<readonly ["TopLeft", "TopCenter", "TopRight", "BottomLeft", "BottomCenter", "BottomRight"]>;
11
+ export type Position = typeof Position.Type;
12
+ /** Schema factory for a single toast entry. `payloadSchema` is user-provided
13
+ * and defines the shape of per-entry content, whatever the consumer wants
14
+ * to encode. The component itself owns only lifecycle + a11y fields: `id`,
15
+ * `variant` (for ARIA role), `animation`, `maybeDuration`,
16
+ * `pendingDismissVersion` (for cancellable auto-dismiss), and `isHovered`
17
+ * (for pause-on-hover). */
18
+ export declare const makeEntry: <A, I>(payloadSchema: S.Codec<A, I>) => S.Struct<{
19
+ readonly id: S.String;
20
+ readonly variant: S.Literals<readonly ["Info", "Success", "Warning", "Error"]>;
21
+ readonly animation: S.Struct<{
22
+ readonly id: S.String;
23
+ readonly isShowing: S.Boolean;
24
+ readonly transitionState: S.Literals<readonly ["Idle", "EnterStart", "EnterAnimating", "LeaveStart", "LeaveAnimating"]>;
25
+ }>;
26
+ readonly maybeDuration: S.Option<S.DurationFromMillis>;
27
+ readonly pendingDismissVersion: S.Number;
28
+ readonly isHovered: S.Boolean;
29
+ readonly payload: S.Codec<A, I, never, never>;
30
+ }>;
31
+ /** Schema factory for the toast container's state. `nextEntryKey` is a
32
+ * monotonic counter used to generate unique entry IDs purely from Model
33
+ * state. Thread the updated model through successive `show()` calls.
34
+ * Calling `show()` twice against the same pre-update model in the same tick
35
+ * will produce duplicate entry IDs. */
36
+ export declare const makeModel: <A, I>(payloadSchema: S.Codec<A, I>) => S.Struct<{
37
+ readonly id: S.String;
38
+ readonly defaultDuration: S.DurationFromMillis;
39
+ readonly entries: S.$Array<S.Struct<{
40
+ readonly id: S.String;
41
+ readonly variant: S.Literals<readonly ["Info", "Success", "Warning", "Error"]>;
42
+ readonly animation: S.Struct<{
43
+ readonly id: S.String;
44
+ readonly isShowing: S.Boolean;
45
+ readonly transitionState: S.Literals<readonly ["Idle", "EnterStart", "EnterAnimating", "LeaveStart", "LeaveAnimating"]>;
46
+ }>;
47
+ readonly maybeDuration: S.Option<S.DurationFromMillis>;
48
+ readonly pendingDismissVersion: S.Number;
49
+ readonly isHovered: S.Boolean;
50
+ readonly payload: S.Codec<A, I, never, never>;
51
+ }>>;
52
+ readonly nextEntryKey: S.Number;
53
+ }>;
54
+ /** Sent when an entry should begin dismissing. Starts the leave animation;
55
+ * the entry is removed from the stack when `TransitionedOut` fires. */
56
+ export declare const Dismissed: import("foldkit/schema").CallableTaggedStruct<"Dismissed", {
57
+ entryId: S.String;
58
+ }>;
59
+ /** Sent when every currently-visible entry should begin dismissing. */
60
+ export declare const DismissedAll: import("foldkit/schema").CallableTaggedStruct<"DismissedAll", {}>;
61
+ /** Sent when an entry's auto-dismiss timer fires. Carries a version echoed
62
+ * from the scheduling moment so stale timers (from hover or manual dismiss)
63
+ * are discarded. */
64
+ export declare const ElapsedDuration: import("foldkit/schema").CallableTaggedStruct<"ElapsedDuration", {
65
+ entryId: S.String;
66
+ version: S.Number;
67
+ }>;
68
+ /** Sent when the pointer enters an entry. Pauses the auto-dismiss timer by
69
+ * advancing the entry's version. */
70
+ export declare const HoveredEntry: import("foldkit/schema").CallableTaggedStruct<"HoveredEntry", {
71
+ entryId: S.String;
72
+ }>;
73
+ /** Sent when the pointer leaves an entry. Restarts the auto-dismiss timer
74
+ * with the entry's full duration. */
75
+ export declare const LeftEntry: import("foldkit/schema").CallableTaggedStruct<"LeftEntry", {
76
+ entryId: S.String;
77
+ }>;
78
+ /** Wraps a single entry's Animation submodel message for delegation. */
79
+ export declare const GotAnimationMessage: import("foldkit/schema").CallableTaggedStruct<"GotAnimationMessage", {
80
+ entryId: S.String;
81
+ message: S.Union<[import("foldkit/schema").CallableTaggedStruct<"Showed", {}>, import("foldkit/schema").CallableTaggedStruct<"Hid", {}>, import("foldkit/schema").CallableTaggedStruct<"AdvancedAnimationFrame", {}>, import("foldkit/schema").CallableTaggedStruct<"EndedAnimation", {}>]>;
82
+ }>;
83
+ export type Dismissed = typeof Dismissed.Type;
84
+ export type DismissedAll = typeof DismissedAll.Type;
85
+ export type ElapsedDuration = typeof ElapsedDuration.Type;
86
+ export type HoveredEntry = typeof HoveredEntry.Type;
87
+ export type LeftEntry = typeof LeftEntry.Type;
88
+ export type GotAnimationMessage = typeof GotAnimationMessage.Type;
89
+ /** Factory for the `Added` message, which carries a fully-constructed entry
90
+ * whose shape depends on the user-provided payload. */
91
+ export declare const makeAdded: <A, I>(payloadSchema: S.Codec<A, I>) => import("foldkit/schema").CallableTaggedStruct<"Added", {
92
+ entry: S.Struct<{
93
+ readonly id: S.String;
94
+ readonly variant: S.Literals<readonly ["Info", "Success", "Warning", "Error"]>;
95
+ readonly animation: S.Struct<{
96
+ readonly id: S.String;
97
+ readonly isShowing: S.Boolean;
98
+ readonly transitionState: S.Literals<readonly ["Idle", "EnterStart", "EnterAnimating", "LeaveStart", "LeaveAnimating"]>;
99
+ }>;
100
+ readonly maybeDuration: S.Option<S.DurationFromMillis>;
101
+ readonly pendingDismissVersion: S.Number;
102
+ readonly isHovered: S.Boolean;
103
+ readonly payload: S.Codec<A, I, never, never>;
104
+ }>;
105
+ }>;
106
+ /** Factory for the union of all messages the toast component can produce. */
107
+ export declare const makeMessage: <A, I>(payloadSchema: S.Codec<A, I>) => S.Union<readonly [import("foldkit/schema").CallableTaggedStruct<"Added", {
108
+ entry: S.Struct<{
109
+ readonly id: S.String;
110
+ readonly variant: S.Literals<readonly ["Info", "Success", "Warning", "Error"]>;
111
+ readonly animation: S.Struct<{
112
+ readonly id: S.String;
113
+ readonly isShowing: S.Boolean;
114
+ readonly transitionState: S.Literals<readonly ["Idle", "EnterStart", "EnterAnimating", "LeaveStart", "LeaveAnimating"]>;
115
+ }>;
116
+ readonly maybeDuration: S.Option<S.DurationFromMillis>;
117
+ readonly pendingDismissVersion: S.Number;
118
+ readonly isHovered: S.Boolean;
119
+ readonly payload: S.Codec<A, I, never, never>;
120
+ }>;
121
+ }>, import("foldkit/schema").CallableTaggedStruct<"Dismissed", {
122
+ entryId: S.String;
123
+ }>, import("foldkit/schema").CallableTaggedStruct<"DismissedAll", {}>, import("foldkit/schema").CallableTaggedStruct<"ElapsedDuration", {
124
+ entryId: S.String;
125
+ version: S.Number;
126
+ }>, import("foldkit/schema").CallableTaggedStruct<"HoveredEntry", {
127
+ entryId: S.String;
128
+ }>, import("foldkit/schema").CallableTaggedStruct<"LeftEntry", {
129
+ entryId: S.String;
130
+ }>, import("foldkit/schema").CallableTaggedStruct<"GotAnimationMessage", {
131
+ entryId: S.String;
132
+ message: S.Union<[import("foldkit/schema").CallableTaggedStruct<"Showed", {}>, import("foldkit/schema").CallableTaggedStruct<"Hid", {}>, import("foldkit/schema").CallableTaggedStruct<"AdvancedAnimationFrame", {}>, import("foldkit/schema").CallableTaggedStruct<"EndedAnimation", {}>]>;
133
+ }>]>;
134
+ /** Factory for `DismissedToast`, the OutMessage emitted once an entry has
135
+ * finished dismissing (leave-animation `TransitionedOut`). Carries the
136
+ * payload so consumers can lift the dismissal into a domain Message
137
+ * without looking the entry up from a stale model. */
138
+ export declare const makeDismissedToast: <A, I>(payloadSchema: S.Codec<A, I>) => import("foldkit/schema").CallableTaggedStruct<"DismissedToast", {
139
+ payload: S.Codec<A, I, never, never>;
140
+ }>;
141
+ /** Factory for the union of out-messages the toast component can produce. */
142
+ export declare const makeOutMessage: <A, I>(payloadSchema: S.Codec<A, I>) => S.Union<readonly [import("foldkit/schema").CallableTaggedStruct<"DismissedToast", {
143
+ payload: S.Codec<A, I, never, never>;
144
+ }>]>;
145
+ /** Configuration for creating a toast container model. `defaultDuration` is
146
+ * applied to any `show()` call that doesn't provide its own `duration` or
147
+ * pass `sticky: true`. Accepts any Effect Duration input; a bare number is
148
+ * interpreted as milliseconds. */
149
+ export type InitConfig = Readonly<{
150
+ id: string;
151
+ defaultDuration?: Duration.Input;
152
+ }>;
153
+ export declare const DEFAULT_DURATION: Duration.Duration;
154
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/toast/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,QAAQ,CAAA;AAU9C;;;;kDAIkD;AAClD,eAAO,MAAM,OAAO,8DAAsD,CAAA;AAC1E,MAAM,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC,IAAI,CAAA;AAIzC,gFAAgF;AAChF,eAAO,MAAM,QAAQ,wGAOnB,CAAA;AACF,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC,IAAI,CAAA;AAI3C;;;;;4BAK4B;AAC5B,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,CAAC,EAAE,eAAe,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;;;;;;;;;;;;EASxD,CAAA;AAIJ;;;;wCAIwC;AACxC,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,CAAC,EAAE,eAAe,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;;;;;;;;;;;;;;;;;EAMxD,CAAA;AAIJ;wEACwE;AACxE,eAAO,MAAM,SAAS;;EAAwC,CAAA;AAC9D,uEAAuE;AACvE,eAAO,MAAM,YAAY,mEAAoB,CAAA;AAC7C;;qBAEqB;AACrB,eAAO,MAAM,eAAe;;;EAG1B,CAAA;AACF;qCACqC;AACrC,eAAO,MAAM,YAAY;;EAA2C,CAAA;AACpE;sCACsC;AACtC,eAAO,MAAM,SAAS;;EAAwC,CAAA;AAC9D,wEAAwE;AACxE,eAAO,MAAM,mBAAmB;;;EAG9B,CAAA;AAEF,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC,IAAI,CAAA;AAC7C,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC,IAAI,CAAA;AACnD,MAAM,MAAM,eAAe,GAAG,OAAO,eAAe,CAAC,IAAI,CAAA;AACzD,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC,IAAI,CAAA;AACnD,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC,IAAI,CAAA;AAC7C,MAAM,MAAM,mBAAmB,GAAG,OAAO,mBAAmB,CAAC,IAAI,CAAA;AAEjE;wDACwD;AACxD,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,CAAC,EAAE,eAAe,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;;;;;;;;;;;;;;EACX,CAAA;AAEjD,6EAA6E;AAC7E,eAAO,MAAM,WAAW,GAAI,CAAC,EAAE,CAAC,EAAE,eAAe,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;IAS1D,CAAA;AAEJ;;;uDAGuD;AACvD,eAAO,MAAM,kBAAkB,GAAI,CAAC,EAAE,CAAC,EAAE,eAAe,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;;EACpB,CAAA;AAEjD,6EAA6E;AAC7E,eAAO,MAAM,cAAc,GAAI,CAAC,EAAE,CAAC,EAAE,eAAe,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;;IACnB,CAAA;AAI9C;;;mCAGmC;AACnC,MAAM,MAAM,UAAU,GAAG,QAAQ,CAAC;IAChC,EAAE,EAAE,MAAM,CAAA;IACV,eAAe,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAA;CACjC,CAAC,CAAA;AAEF,eAAO,MAAM,gBAAgB,mBAAsB,CAAA"}
@@ -0,0 +1,93 @@
1
+ import { Duration, Schema as S } from 'effect';
2
+ import { m } from 'foldkit/message';
3
+ import { Message as AnimationMessage, Model as AnimationModel, } from '../animation/schema.js';
4
+ // VARIANT
5
+ /** Semantic category of a toast. Drives the default ARIA role: `status` for
6
+ * `Info` / `Success`, `alert` for `Warning` / `Error`. Also surfaced as
7
+ * `data-variant` on each entry for per-variant CSS. This is the only
8
+ * content-adjacent field the component owns. The rest of the entry's
9
+ * content lives in the user-provided payload. */
10
+ export const Variant = S.Literals(['Info', 'Success', 'Warning', 'Error']);
11
+ // POSITION
12
+ /** Where the toast viewport is anchored on the screen and how entries stack. */
13
+ export const Position = S.Literals([
14
+ 'TopLeft',
15
+ 'TopCenter',
16
+ 'TopRight',
17
+ 'BottomLeft',
18
+ 'BottomCenter',
19
+ 'BottomRight',
20
+ ]);
21
+ // ENTRY
22
+ /** Schema factory for a single toast entry. `payloadSchema` is user-provided
23
+ * and defines the shape of per-entry content, whatever the consumer wants
24
+ * to encode. The component itself owns only lifecycle + a11y fields: `id`,
25
+ * `variant` (for ARIA role), `animation`, `maybeDuration`,
26
+ * `pendingDismissVersion` (for cancellable auto-dismiss), and `isHovered`
27
+ * (for pause-on-hover). */
28
+ export const makeEntry = (payloadSchema) => S.Struct({
29
+ id: S.String,
30
+ variant: Variant,
31
+ animation: AnimationModel,
32
+ maybeDuration: S.Option(S.DurationFromMillis),
33
+ pendingDismissVersion: S.Number,
34
+ isHovered: S.Boolean,
35
+ payload: payloadSchema,
36
+ });
37
+ // MODEL
38
+ /** Schema factory for the toast container's state. `nextEntryKey` is a
39
+ * monotonic counter used to generate unique entry IDs purely from Model
40
+ * state. Thread the updated model through successive `show()` calls.
41
+ * Calling `show()` twice against the same pre-update model in the same tick
42
+ * will produce duplicate entry IDs. */
43
+ export const makeModel = (payloadSchema) => S.Struct({
44
+ id: S.String,
45
+ defaultDuration: S.DurationFromMillis,
46
+ entries: S.Array(makeEntry(payloadSchema)),
47
+ nextEntryKey: S.Number,
48
+ });
49
+ // MESSAGE
50
+ /** Sent when an entry should begin dismissing. Starts the leave animation;
51
+ * the entry is removed from the stack when `TransitionedOut` fires. */
52
+ export const Dismissed = m('Dismissed', { entryId: S.String });
53
+ /** Sent when every currently-visible entry should begin dismissing. */
54
+ export const DismissedAll = m('DismissedAll');
55
+ /** Sent when an entry's auto-dismiss timer fires. Carries a version echoed
56
+ * from the scheduling moment so stale timers (from hover or manual dismiss)
57
+ * are discarded. */
58
+ export const ElapsedDuration = m('ElapsedDuration', {
59
+ entryId: S.String,
60
+ version: S.Number,
61
+ });
62
+ /** Sent when the pointer enters an entry. Pauses the auto-dismiss timer by
63
+ * advancing the entry's version. */
64
+ export const HoveredEntry = m('HoveredEntry', { entryId: S.String });
65
+ /** Sent when the pointer leaves an entry. Restarts the auto-dismiss timer
66
+ * with the entry's full duration. */
67
+ export const LeftEntry = m('LeftEntry', { entryId: S.String });
68
+ /** Wraps a single entry's Animation submodel message for delegation. */
69
+ export const GotAnimationMessage = m('GotAnimationMessage', {
70
+ entryId: S.String,
71
+ message: AnimationMessage,
72
+ });
73
+ /** Factory for the `Added` message, which carries a fully-constructed entry
74
+ * whose shape depends on the user-provided payload. */
75
+ export const makeAdded = (payloadSchema) => m('Added', { entry: makeEntry(payloadSchema) });
76
+ /** Factory for the union of all messages the toast component can produce. */
77
+ export const makeMessage = (payloadSchema) => S.Union([
78
+ makeAdded(payloadSchema),
79
+ Dismissed,
80
+ DismissedAll,
81
+ ElapsedDuration,
82
+ HoveredEntry,
83
+ LeftEntry,
84
+ GotAnimationMessage,
85
+ ]);
86
+ /** Factory for `DismissedToast`, the OutMessage emitted once an entry has
87
+ * finished dismissing (leave-animation `TransitionedOut`). Carries the
88
+ * payload so consumers can lift the dismissal into a domain Message
89
+ * without looking the entry up from a stale model. */
90
+ export const makeDismissedToast = (payloadSchema) => m('DismissedToast', { payload: payloadSchema });
91
+ /** Factory for the union of out-messages the toast component can produce. */
92
+ export const makeOutMessage = (payloadSchema) => S.Union([makeDismissedToast(payloadSchema)]);
93
+ export const DEFAULT_DURATION = Duration.seconds(4);