@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.
- package/LICENSE +21 -0
- package/README.md +67 -0
- package/dist/anchor.d.ts +38 -0
- package/dist/anchor.d.ts.map +1 -0
- package/dist/anchor.js +142 -0
- package/dist/animation/index.d.ts +49 -0
- package/dist/animation/index.d.ts.map +1 -0
- package/dist/animation/index.js +75 -0
- package/dist/animation/public.d.ts +3 -0
- package/dist/animation/public.d.ts.map +1 -0
- package/dist/animation/public.js +1 -0
- package/dist/animation/schema.d.ts +43 -0
- package/dist/animation/schema.d.ts.map +1 -0
- package/dist/animation/schema.js +41 -0
- package/dist/animation/update.d.ts +24 -0
- package/dist/animation/update.d.ts.map +1 -0
- package/dist/animation/update.js +67 -0
- package/dist/button/index.d.ts +17 -0
- package/dist/button/index.d.ts.map +1 -0
- package/dist/button/index.js +22 -0
- package/dist/button/public.d.ts +3 -0
- package/dist/button/public.d.ts.map +1 -0
- package/dist/button/public.js +1 -0
- package/dist/calendar/index.d.ts +462 -0
- package/dist/calendar/index.d.ts.map +1 -0
- package/dist/calendar/index.js +825 -0
- package/dist/calendar/public.d.ts +3 -0
- package/dist/calendar/public.d.ts.map +1 -0
- package/dist/calendar/public.js +1 -0
- package/dist/checkbox/index.d.ts +119 -0
- package/dist/checkbox/index.d.ts.map +1 -0
- package/dist/checkbox/index.js +111 -0
- package/dist/checkbox/public.d.ts +3 -0
- package/dist/checkbox/public.d.ts.map +1 -0
- package/dist/checkbox/public.js +1 -0
- package/dist/combobox/multi.d.ts +183 -0
- package/dist/combobox/multi.d.ts.map +1 -0
- package/dist/combobox/multi.js +81 -0
- package/dist/combobox/multiPublic.d.ts +3 -0
- package/dist/combobox/multiPublic.d.ts.map +1 -0
- package/dist/combobox/multiPublic.js +1 -0
- package/dist/combobox/public.d.ts +7 -0
- package/dist/combobox/public.d.ts.map +1 -0
- package/dist/combobox/public.js +3 -0
- package/dist/combobox/shared.d.ts +423 -0
- package/dist/combobox/shared.d.ts.map +1 -0
- package/dist/combobox/shared.js +708 -0
- package/dist/combobox/single.d.ts +198 -0
- package/dist/combobox/single.d.ts.map +1 -0
- package/dist/combobox/single.js +106 -0
- package/dist/datePicker/index.d.ts +457 -0
- package/dist/datePicker/index.d.ts.map +1 -0
- package/dist/datePicker/index.js +318 -0
- package/dist/datePicker/public.d.ts +3 -0
- package/dist/datePicker/public.d.ts.map +1 -0
- package/dist/datePicker/public.js +1 -0
- package/dist/dialog/index.d.ts +160 -0
- package/dist/dialog/index.d.ts.map +1 -0
- package/dist/dialog/index.js +211 -0
- package/dist/dialog/public.d.ts +3 -0
- package/dist/dialog/public.d.ts.map +1 -0
- package/dist/dialog/public.js +1 -0
- package/dist/disclosure/index.d.ts +110 -0
- package/dist/disclosure/index.d.ts.map +1 -0
- package/dist/disclosure/index.js +111 -0
- package/dist/disclosure/public.d.ts +3 -0
- package/dist/disclosure/public.d.ts.map +1 -0
- package/dist/disclosure/public.js +1 -0
- package/dist/dragAndDrop/index.d.ts +540 -0
- package/dist/dragAndDrop/index.d.ts.map +1 -0
- package/dist/dragAndDrop/index.js +535 -0
- package/dist/dragAndDrop/public.d.ts +3 -0
- package/dist/dragAndDrop/public.d.ts.map +1 -0
- package/dist/dragAndDrop/public.js +1 -0
- package/dist/fieldset/index.d.ts +21 -0
- package/dist/fieldset/index.d.ts.map +1 -0
- package/dist/fieldset/index.js +25 -0
- package/dist/fieldset/public.d.ts +3 -0
- package/dist/fieldset/public.d.ts.map +1 -0
- package/dist/fieldset/public.js +1 -0
- package/dist/fileDrop/index.d.ts +109 -0
- package/dist/fileDrop/index.d.ts.map +1 -0
- package/dist/fileDrop/index.js +127 -0
- package/dist/fileDrop/public.d.ts +3 -0
- package/dist/fileDrop/public.d.ts.map +1 -0
- package/dist/fileDrop/public.js +1 -0
- package/dist/group.d.ts +8 -0
- package/dist/group.d.ts.map +1 -0
- package/dist/group.js +13 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/input/index.d.ts +26 -0
- package/dist/input/index.d.ts.map +1 -0
- package/dist/input/index.js +43 -0
- package/dist/input/public.d.ts +3 -0
- package/dist/input/public.d.ts.map +1 -0
- package/dist/input/public.js +1 -0
- package/dist/internal/optionExtensions.d.ts +6 -0
- package/dist/internal/optionExtensions.d.ts.map +1 -0
- package/dist/internal/optionExtensions.js +2 -0
- package/dist/keyboard.d.ts +6 -0
- package/dist/keyboard.d.ts.map +1 -0
- package/dist/keyboard.js +9 -0
- package/dist/listbox/multi.d.ts +189 -0
- package/dist/listbox/multi.d.ts.map +1 -0
- package/dist/listbox/multi.js +65 -0
- package/dist/listbox/multiPublic.d.ts +3 -0
- package/dist/listbox/multiPublic.d.ts.map +1 -0
- package/dist/listbox/multiPublic.js +1 -0
- package/dist/listbox/public.d.ts +7 -0
- package/dist/listbox/public.d.ts.map +1 -0
- package/dist/listbox/public.js +3 -0
- package/dist/listbox/shared.d.ts +432 -0
- package/dist/listbox/shared.d.ts.map +1 -0
- package/dist/listbox/shared.js +670 -0
- package/dist/listbox/single.d.ts +207 -0
- package/dist/listbox/single.d.ts.map +1 -0
- package/dist/listbox/single.js +73 -0
- package/dist/menu/index.d.ts +368 -0
- package/dist/menu/index.d.ts.map +1 -0
- package/dist/menu/index.js +682 -0
- package/dist/menu/public.d.ts +4 -0
- package/dist/menu/public.d.ts.map +1 -0
- package/dist/menu/public.js +1 -0
- package/dist/popover/index.d.ts +267 -0
- package/dist/popover/index.d.ts.map +1 -0
- package/dist/popover/index.js +346 -0
- package/dist/popover/public.d.ts +4 -0
- package/dist/popover/public.d.ts.map +1 -0
- package/dist/popover/public.js +1 -0
- package/dist/radioGroup/index.d.ts +169 -0
- package/dist/radioGroup/index.d.ts.map +1 -0
- package/dist/radioGroup/index.js +197 -0
- package/dist/radioGroup/public.d.ts +3 -0
- package/dist/radioGroup/public.d.ts.map +1 -0
- package/dist/radioGroup/public.js +1 -0
- package/dist/select/index.d.ts +24 -0
- package/dist/select/index.d.ts.map +1 -0
- package/dist/select/index.js +40 -0
- package/dist/select/public.d.ts +3 -0
- package/dist/select/public.d.ts.map +1 -0
- package/dist/select/public.js +1 -0
- package/dist/slider/index.d.ts +318 -0
- package/dist/slider/index.d.ts.map +1 -0
- package/dist/slider/index.js +337 -0
- package/dist/slider/public.d.ts +3 -0
- package/dist/slider/public.d.ts.map +1 -0
- package/dist/slider/public.js +1 -0
- package/dist/switch/index.d.ts +99 -0
- package/dist/switch/index.d.ts.map +1 -0
- package/dist/switch/index.js +107 -0
- package/dist/switch/public.d.ts +3 -0
- package/dist/switch/public.d.ts.map +1 -0
- package/dist/switch/public.js +1 -0
- package/dist/tabs/index.d.ts +155 -0
- package/dist/tabs/index.d.ts.map +1 -0
- package/dist/tabs/index.js +185 -0
- package/dist/tabs/public.d.ts +3 -0
- package/dist/tabs/public.d.ts.map +1 -0
- package/dist/tabs/public.js +1 -0
- package/dist/test/apps/disabledButton.d.ts +38 -0
- package/dist/test/apps/disabledButton.d.ts.map +1 -0
- package/dist/test/apps/disabledButton.js +71 -0
- package/dist/textarea/index.d.ts +26 -0
- package/dist/textarea/index.d.ts.map +1 -0
- package/dist/textarea/index.js +44 -0
- package/dist/textarea/public.d.ts +3 -0
- package/dist/textarea/public.d.ts.map +1 -0
- package/dist/textarea/public.js +1 -0
- package/dist/toast/index.d.ts +608 -0
- package/dist/toast/index.d.ts.map +1 -0
- package/dist/toast/index.js +146 -0
- package/dist/toast/public.d.ts +4 -0
- package/dist/toast/public.d.ts.map +1 -0
- package/dist/toast/public.js +1 -0
- package/dist/toast/schema.d.ts +154 -0
- package/dist/toast/schema.d.ts.map +1 -0
- package/dist/toast/schema.js +93 -0
- package/dist/toast/update.d.ts +510 -0
- package/dist/toast/update.d.ts.map +1 -0
- package/dist/toast/update.js +225 -0
- package/dist/tooltip/index.d.ts +170 -0
- package/dist/tooltip/index.d.ts.map +1 -0
- package/dist/tooltip/index.js +253 -0
- package/dist/tooltip/public.d.ts +4 -0
- package/dist/tooltip/public.d.ts.map +1 -0
- package/dist/tooltip/public.js +1 -0
- package/dist/typeahead.d.ts +4 -0
- package/dist/typeahead.d.ts.map +1 -0
- package/dist/typeahead.js +14 -0
- package/dist/virtualList/index.d.ts +203 -0
- package/dist/virtualList/index.d.ts.map +1 -0
- package/dist/virtualList/index.js +392 -0
- package/dist/virtualList/public.d.ts +3 -0
- package/dist/virtualList/public.d.ts.map +1 -0
- package/dist/virtualList/public.js +1 -0
- package/dist/vitest-setup.d.ts +2 -0
- package/dist/vitest-setup.d.ts.map +1 -0
- package/dist/vitest-setup.js +2 -0
- package/package.json +161 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { Effect, Match as M, Option, Schema as S } from 'effect';
|
|
2
|
+
import * as Command from 'foldkit/command';
|
|
3
|
+
import * as Dom from 'foldkit/dom';
|
|
4
|
+
import { childAttributes, html, } from 'foldkit/html';
|
|
5
|
+
import { m } from 'foldkit/message';
|
|
6
|
+
import { evo } from 'foldkit/struct';
|
|
7
|
+
import { defineView } from 'foldkit/submodel';
|
|
8
|
+
// NOTE: Animation imports are split across schema + update to avoid a circular
|
|
9
|
+
// dependency: animation → html → runtime → devtools → dialog → animation.
|
|
10
|
+
// The barrel (../animation) imports from html, which starts the cycle.
|
|
11
|
+
import { Hid as AnimationHid, Message as AnimationMessage, Model as AnimationModel, Showed as AnimationShowed, init as animationInit, } from '../animation/schema.js';
|
|
12
|
+
import { defaultLeaveCommand as animationDefaultLeaveCommand, update as animationUpdate, } from '../animation/update.js';
|
|
13
|
+
// MODEL
|
|
14
|
+
/** Schema for the dialog component's state, tracking its unique ID, open/closed status, animation support, and animation lifecycle phase. */
|
|
15
|
+
export const Model = S.Struct({
|
|
16
|
+
id: S.String,
|
|
17
|
+
isOpen: S.Boolean,
|
|
18
|
+
isAnimated: S.Boolean,
|
|
19
|
+
animation: AnimationModel,
|
|
20
|
+
maybeFocusSelector: S.Option(S.String),
|
|
21
|
+
});
|
|
22
|
+
// MESSAGE
|
|
23
|
+
/** Sent when the dialog should open. Triggers the ShowDialog command. */
|
|
24
|
+
export const RequestedOpen = m('RequestedOpen');
|
|
25
|
+
/** Sent when the dialog should close (Escape key, backdrop click, or programmatic). */
|
|
26
|
+
export const RequestedClose = m('RequestedClose');
|
|
27
|
+
/** Sent when the show-dialog command completes. */
|
|
28
|
+
export const CompletedShowDialog = m('CompletedShowDialog');
|
|
29
|
+
/** Sent when the close-dialog command completes. */
|
|
30
|
+
export const CompletedCloseDialog = m('CompletedCloseDialog');
|
|
31
|
+
/** Wraps an Animation submodel message for delegation. */
|
|
32
|
+
export const GotAnimationMessage = m('GotAnimationMessage', {
|
|
33
|
+
message: AnimationMessage,
|
|
34
|
+
});
|
|
35
|
+
/** Union of all messages the dialog component can produce. */
|
|
36
|
+
export const Message = S.Union([
|
|
37
|
+
RequestedOpen,
|
|
38
|
+
RequestedClose,
|
|
39
|
+
CompletedShowDialog,
|
|
40
|
+
CompletedCloseDialog,
|
|
41
|
+
GotAnimationMessage,
|
|
42
|
+
]);
|
|
43
|
+
// OUT MESSAGE
|
|
44
|
+
/** Sent once the dialog has transitioned to open. Fires after `update`
|
|
45
|
+
* has processed `RequestedOpen` and `isOpen` reflects the new state.
|
|
46
|
+
* Programmatic `Dialog.open` on an already-open model is a no-op that
|
|
47
|
+
* does not re-emit. */
|
|
48
|
+
export const Opened = m('Opened');
|
|
49
|
+
/** Sent once the dialog has transitioned to closed. Programmatic
|
|
50
|
+
* `Dialog.close` on an already-closed model is a no-op that does not
|
|
51
|
+
* re-emit; calling close while a leave animation is in progress is
|
|
52
|
+
* also a no-op. */
|
|
53
|
+
export const Closed = m('Closed');
|
|
54
|
+
/** Union of out-messages the dialog component can produce. */
|
|
55
|
+
export const OutMessage = S.Union([Opened, Closed]);
|
|
56
|
+
/** Creates an initial dialog model from a config. Defaults to closed and non-animated. */
|
|
57
|
+
export const init = (config) => ({
|
|
58
|
+
id: config.id,
|
|
59
|
+
isOpen: config.isOpen ?? false,
|
|
60
|
+
isAnimated: config.isAnimated ?? false,
|
|
61
|
+
animation: animationInit({
|
|
62
|
+
id: `${config.id}-panel`,
|
|
63
|
+
...(config.isOpen !== undefined ? { isShowing: config.isOpen } : {}),
|
|
64
|
+
}),
|
|
65
|
+
maybeFocusSelector: Option.fromNullishOr(config.focusSelector),
|
|
66
|
+
});
|
|
67
|
+
// UPDATE
|
|
68
|
+
const dialogSelector = (id) => `#${id}`;
|
|
69
|
+
const withUpdateReturn = M.withReturnType();
|
|
70
|
+
/** Locks page scroll and opens the native dialog element with `show()`. */
|
|
71
|
+
export const ShowDialog = Command.define('ShowDialog', { id: S.String, maybeFocusSelector: S.Option(S.String) }, CompletedShowDialog)(({ id, maybeFocusSelector }) => Dom.lockScroll.pipe(Effect.andThen(() => Dom.showModal(dialogSelector(id), Option.match(maybeFocusSelector, {
|
|
72
|
+
onNone: () => undefined,
|
|
73
|
+
onSome: focusSelector => ({ focusSelector }),
|
|
74
|
+
}))), Effect.ignore, Effect.as(CompletedShowDialog())));
|
|
75
|
+
/** Calls `close()` on the native dialog element and unlocks page scroll. */
|
|
76
|
+
export const CloseDialog = Command.define('CloseDialog', { id: S.String }, CompletedCloseDialog)(({ id }) => Dom.closeModal(dialogSelector(id)).pipe(Effect.andThen(() => Dom.unlockScroll), Effect.ignore, Effect.as(CompletedCloseDialog())));
|
|
77
|
+
const wrapAnimationMessage = (message) => GotAnimationMessage({ message });
|
|
78
|
+
const delegateToAnimation = (model, animationMessage) => {
|
|
79
|
+
const [nextAnimation, animationCommands, maybeOutMessage] = animationUpdate(model.animation, animationMessage);
|
|
80
|
+
const mappedCommands = Command.mapMessages(animationCommands, wrapAnimationMessage);
|
|
81
|
+
const additionalCommands = Option.match(maybeOutMessage, {
|
|
82
|
+
onNone: () => [],
|
|
83
|
+
onSome: M.type().pipe(M.tagsExhaustive({
|
|
84
|
+
StartedLeaveAnimating: () => [
|
|
85
|
+
Command.mapMessage(animationDefaultLeaveCommand(nextAnimation), wrapAnimationMessage),
|
|
86
|
+
],
|
|
87
|
+
TransitionedOut: () => [CloseDialog({ id: model.id })],
|
|
88
|
+
})),
|
|
89
|
+
});
|
|
90
|
+
return [
|
|
91
|
+
evo(model, { animation: () => nextAnimation }),
|
|
92
|
+
[...mappedCommands, ...additionalCommands],
|
|
93
|
+
Option.none(),
|
|
94
|
+
];
|
|
95
|
+
};
|
|
96
|
+
/** Processes a dialog message and returns the next model and commands. */
|
|
97
|
+
export const update = (model, message) => M.value(message).pipe(withUpdateReturn, M.tagsExhaustive({
|
|
98
|
+
RequestedOpen: () => {
|
|
99
|
+
const wasClosed = !model.isOpen;
|
|
100
|
+
const maybeShow = Option.liftPredicate(ShowDialog({
|
|
101
|
+
id: model.id,
|
|
102
|
+
maybeFocusSelector: model.maybeFocusSelector,
|
|
103
|
+
}), () => wasClosed);
|
|
104
|
+
const maybeOutMessage = wasClosed
|
|
105
|
+
? Option.some(Opened())
|
|
106
|
+
: Option.none();
|
|
107
|
+
if (model.isAnimated) {
|
|
108
|
+
const [nextModel, animationCommands] = delegateToAnimation(model, AnimationShowed());
|
|
109
|
+
return [
|
|
110
|
+
evo(nextModel, { isOpen: () => true }),
|
|
111
|
+
[...Option.toArray(maybeShow), ...animationCommands],
|
|
112
|
+
maybeOutMessage,
|
|
113
|
+
];
|
|
114
|
+
}
|
|
115
|
+
return [
|
|
116
|
+
evo(model, { isOpen: () => true }),
|
|
117
|
+
Option.toArray(maybeShow),
|
|
118
|
+
maybeOutMessage,
|
|
119
|
+
];
|
|
120
|
+
},
|
|
121
|
+
RequestedClose: () => {
|
|
122
|
+
const { transitionState } = model.animation;
|
|
123
|
+
const isLeaving = transitionState === 'LeaveStart' ||
|
|
124
|
+
transitionState === 'LeaveAnimating';
|
|
125
|
+
if (isLeaving) {
|
|
126
|
+
return [model, [], Option.none()];
|
|
127
|
+
}
|
|
128
|
+
const wasOpen = model.isOpen;
|
|
129
|
+
const maybeOutMessage = wasOpen ? Option.some(Closed()) : Option.none();
|
|
130
|
+
if (model.isAnimated) {
|
|
131
|
+
const [nextModel, animationCommands] = delegateToAnimation(evo(model, { isOpen: () => false }), AnimationHid());
|
|
132
|
+
return [nextModel, animationCommands, maybeOutMessage];
|
|
133
|
+
}
|
|
134
|
+
const maybeClose = Option.liftPredicate(CloseDialog({ id: model.id }), () => wasOpen);
|
|
135
|
+
return [
|
|
136
|
+
evo(model, { isOpen: () => false }),
|
|
137
|
+
Option.toArray(maybeClose),
|
|
138
|
+
maybeOutMessage,
|
|
139
|
+
];
|
|
140
|
+
},
|
|
141
|
+
GotAnimationMessage: ({ message: animationMessage }) => delegateToAnimation(model, animationMessage),
|
|
142
|
+
CompletedShowDialog: () => [model, [], Option.none()],
|
|
143
|
+
CompletedCloseDialog: () => [model, [], Option.none()],
|
|
144
|
+
}));
|
|
145
|
+
/** Programmatically opens the dialog. */
|
|
146
|
+
export const open = (model) => update(model, RequestedOpen());
|
|
147
|
+
/** Programmatically closes the dialog. */
|
|
148
|
+
export const close = (model) => update(model, RequestedClose());
|
|
149
|
+
// VIEW
|
|
150
|
+
/** Returns the ID used for `aria-labelledby` on the dialog. Apply this to your title element. */
|
|
151
|
+
export const titleId = (model) => `${model.id}-title`;
|
|
152
|
+
/** Returns the ID used for `aria-describedby` on the dialog. Apply this to your description element. */
|
|
153
|
+
export const descriptionId = (model) => `${model.id}-description`;
|
|
154
|
+
/** Renders a headless dialog component backed by the native `<dialog>`
|
|
155
|
+
* element opened with `show()`. */
|
|
156
|
+
export const view = defineView((model, viewInputs) => {
|
|
157
|
+
const h = html();
|
|
158
|
+
const { id, isOpen, animation: { transitionState }, } = model;
|
|
159
|
+
const { toView } = viewInputs;
|
|
160
|
+
const isLeaving = transitionState === 'LeaveStart' || transitionState === 'LeaveAnimating';
|
|
161
|
+
const isVisible = isOpen || isLeaving;
|
|
162
|
+
const animationAttributes = M.value(transitionState).pipe(M.when('EnterStart', () => [
|
|
163
|
+
h.DataAttribute('closed', ''),
|
|
164
|
+
h.DataAttribute('enter', ''),
|
|
165
|
+
h.DataAttribute('transition', ''),
|
|
166
|
+
]), M.when('EnterAnimating', () => [
|
|
167
|
+
h.DataAttribute('enter', ''),
|
|
168
|
+
h.DataAttribute('transition', ''),
|
|
169
|
+
]), M.when('LeaveStart', () => [
|
|
170
|
+
h.DataAttribute('leave', ''),
|
|
171
|
+
h.DataAttribute('transition', ''),
|
|
172
|
+
]), M.when('LeaveAnimating', () => [
|
|
173
|
+
h.DataAttribute('closed', ''),
|
|
174
|
+
h.DataAttribute('leave', ''),
|
|
175
|
+
h.DataAttribute('transition', ''),
|
|
176
|
+
]), M.orElse(() => []));
|
|
177
|
+
const dialogAttributes = [
|
|
178
|
+
h.Id(id),
|
|
179
|
+
h.AriaLabelledBy(`${id}-title`),
|
|
180
|
+
h.AriaDescribedBy(`${id}-description`),
|
|
181
|
+
h.OnCancel(RequestedClose()),
|
|
182
|
+
h.Open(isVisible),
|
|
183
|
+
h.Style({
|
|
184
|
+
width: '100%',
|
|
185
|
+
height: '100%',
|
|
186
|
+
maxWidth: '100%',
|
|
187
|
+
maxHeight: '100%',
|
|
188
|
+
padding: '0',
|
|
189
|
+
border: 'none',
|
|
190
|
+
background: 'transparent',
|
|
191
|
+
...(isVisible
|
|
192
|
+
? { position: 'fixed', inset: '0', zIndex: '2147483600' }
|
|
193
|
+
: {}),
|
|
194
|
+
}),
|
|
195
|
+
...(isVisible ? [h.DataAttribute('open', '')] : []),
|
|
196
|
+
];
|
|
197
|
+
const backdropAttributes = [
|
|
198
|
+
h.Style({ minHeight: '100vh' }),
|
|
199
|
+
...animationAttributes,
|
|
200
|
+
...(isLeaving ? [] : [h.OnClick(RequestedClose())]),
|
|
201
|
+
];
|
|
202
|
+
const panelAttributes = [h.Id(`${id}-panel`), ...animationAttributes];
|
|
203
|
+
const closeButtonAttributes = isLeaving ? [] : [h.OnClick(RequestedClose())];
|
|
204
|
+
return toView({
|
|
205
|
+
dialog: childAttributes(dialogAttributes),
|
|
206
|
+
backdrop: childAttributes(backdropAttributes),
|
|
207
|
+
panel: childAttributes(panelAttributes),
|
|
208
|
+
closeButton: childAttributes(closeButtonAttributes),
|
|
209
|
+
isVisible,
|
|
210
|
+
});
|
|
211
|
+
});
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { init, update, open, close, view, titleId, descriptionId, Model, Message, OutMessage, Opened, Closed, RequestedOpen, RequestedClose, CompletedShowDialog, CompletedCloseDialog, GotAnimationMessage, ShowDialog, CloseDialog, } from './index.js';
|
|
2
|
+
export type { InitConfig, ViewInputs, RenderInfo } from './index.js';
|
|
3
|
+
//# sourceMappingURL=public.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../src/dialog/public.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,MAAM,EACN,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,OAAO,EACP,aAAa,EACb,KAAK,EACL,OAAO,EACP,UAAU,EACV,MAAM,EACN,MAAM,EACN,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,UAAU,EACV,WAAW,GACZ,MAAM,YAAY,CAAA;AAEnB,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { init, update, open, close, view, titleId, descriptionId, Model, Message, OutMessage, Opened, Closed, RequestedOpen, RequestedClose, CompletedShowDialog, CompletedCloseDialog, GotAnimationMessage, ShowDialog, CloseDialog, } from './index.js';
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Effect, Option, Schema as S } from 'effect';
|
|
2
|
+
import * as Command from 'foldkit/command';
|
|
3
|
+
import { type ChildAttribute, type Html } from 'foldkit/html';
|
|
4
|
+
import { type Reflect } from 'foldkit/submodel';
|
|
5
|
+
/** Schema for the disclosure component's state, tracking its unique ID and open/closed status. */
|
|
6
|
+
export declare const Model: S.Struct<{
|
|
7
|
+
readonly id: S.String;
|
|
8
|
+
readonly isOpen: S.Boolean;
|
|
9
|
+
}>;
|
|
10
|
+
export type Model = typeof Model.Type;
|
|
11
|
+
/** Sent when the disclosure button is clicked. Toggles the open/closed state. */
|
|
12
|
+
export declare const Toggled: import("foldkit/schema").CallableTaggedStruct<"Toggled", {}>;
|
|
13
|
+
/** Sent to explicitly close the disclosure, regardless of its current state. */
|
|
14
|
+
export declare const Closed: import("foldkit/schema").CallableTaggedStruct<"Closed", {}>;
|
|
15
|
+
/** Sent when the focus-button command completes after closing. */
|
|
16
|
+
export declare const CompletedFocusButton: import("foldkit/schema").CallableTaggedStruct<"CompletedFocusButton", {}>;
|
|
17
|
+
/** Union of all messages the disclosure component can produce. */
|
|
18
|
+
export declare const Message: S.Union<[
|
|
19
|
+
typeof Toggled,
|
|
20
|
+
typeof Closed,
|
|
21
|
+
typeof CompletedFocusButton
|
|
22
|
+
]>;
|
|
23
|
+
export type Toggled = typeof Toggled.Type;
|
|
24
|
+
export type Closed = typeof Closed.Type;
|
|
25
|
+
export type CompletedFocusButton = typeof CompletedFocusButton.Type;
|
|
26
|
+
export type Message = typeof Message.Type;
|
|
27
|
+
/** Sent to the parent each time the disclosure toggles. The new open state is available on the next model snapshot; this OutMessage signals only that the transition happened. Consumers typically use this for analytics, lazy content loading, or saving open/closed state to a store. */
|
|
28
|
+
export declare const ToggledOpenState: import("foldkit/schema").CallableTaggedStruct<"ToggledOpenState", {
|
|
29
|
+
isOpen: S.Boolean;
|
|
30
|
+
}>;
|
|
31
|
+
export declare const OutMessage: S.Union<readonly [import("foldkit/schema").CallableTaggedStruct<"ToggledOpenState", {
|
|
32
|
+
isOpen: S.Boolean;
|
|
33
|
+
}>]>;
|
|
34
|
+
export type OutMessage = typeof OutMessage.Type;
|
|
35
|
+
export type ToggledOpenState = typeof ToggledOpenState.Type;
|
|
36
|
+
/** Configuration for creating a disclosure model with `init`. */
|
|
37
|
+
export type InitConfig = Readonly<{
|
|
38
|
+
id: string;
|
|
39
|
+
isOpen?: boolean;
|
|
40
|
+
}>;
|
|
41
|
+
/** Creates an initial disclosure model from a config. Defaults to closed. */
|
|
42
|
+
export declare const init: (config: InitConfig) => Model;
|
|
43
|
+
/** Moves focus to the disclosure's toggle button. */
|
|
44
|
+
export declare const FocusButton: Command.CommandDefinitionWithArgs<"FocusButton", {
|
|
45
|
+
id: S.String;
|
|
46
|
+
}, Effect.Effect<{
|
|
47
|
+
readonly _tag: "CompletedFocusButton";
|
|
48
|
+
}, never, never>>;
|
|
49
|
+
type UpdateReturn = readonly [
|
|
50
|
+
Model,
|
|
51
|
+
ReadonlyArray<Command.Command<Message>>,
|
|
52
|
+
Option.Option<OutMessage>
|
|
53
|
+
];
|
|
54
|
+
/** Processes a disclosure message and returns the next model, commands, and optional OutMessage. */
|
|
55
|
+
export declare const update: (model: Model, message: Message) => UpdateReturn;
|
|
56
|
+
/** Programmatically toggles the disclosure, updating the model and returning
|
|
57
|
+
* focus commands plus a `ToggledOpenState` OutMessage. */
|
|
58
|
+
export declare const toggle: (model: Model) => UpdateReturn;
|
|
59
|
+
/** Programmatically closes the disclosure, updating the model and returning
|
|
60
|
+
* focus commands plus a `ToggledOpenState` OutMessage when it was open. */
|
|
61
|
+
export declare const close: (model: Model) => UpdateReturn;
|
|
62
|
+
/** Reflects an externally-sourced open state onto the model without
|
|
63
|
+
* emitting an OutMessage or running the focus command. Use this to mirror
|
|
64
|
+
* external truth (restored storage, a deep link) onto the disclosure.
|
|
65
|
+
* Contrast with `toggle`/`close`, which represent user or programmatic
|
|
66
|
+
* *choices* and emit `ToggledOpenState`. Returns the model directly
|
|
67
|
+
* because it produces no commands and no OutMessage. */
|
|
68
|
+
export declare const reflectOpenState: Reflect<Model, boolean>;
|
|
69
|
+
/** Attribute groups the disclosure component provides to the consumer's
|
|
70
|
+
* `toView` callback. The consumer composes the button + panel layout
|
|
71
|
+
* themselves using these bundles. */
|
|
72
|
+
export type DisclosureAttributes = Readonly<{
|
|
73
|
+
button: ReadonlyArray<ChildAttribute>;
|
|
74
|
+
panel: ReadonlyArray<ChildAttribute>;
|
|
75
|
+
}>;
|
|
76
|
+
/** Per-render view inputs passed to `view` via `h.submodel`'s `viewInputs` field.
|
|
77
|
+
*
|
|
78
|
+
* - `toView`: receives the disclosure's `button` and `panel` attribute
|
|
79
|
+
* bundles and returns the composed layout. The consumer reads
|
|
80
|
+
* `isOpen` from their parent model when they need to render
|
|
81
|
+
* conditionally on it.
|
|
82
|
+
* - `isDisabled`: when true, the button is not clickable, gets
|
|
83
|
+
* `aria-disabled` and a `data-disabled` attribute. */
|
|
84
|
+
export type ViewInputs = Readonly<{
|
|
85
|
+
toView: (attributes: DisclosureAttributes) => Html;
|
|
86
|
+
isDisabled?: boolean;
|
|
87
|
+
}>;
|
|
88
|
+
/** Renders a headless disclosure component with accessible ARIA
|
|
89
|
+
* attributes and keyboard support. The consumer composes the layout
|
|
90
|
+
* through the `toView` slot, spreading the published `button` and
|
|
91
|
+
* `panel` attribute bundles onto their own elements.
|
|
92
|
+
*
|
|
93
|
+
* Designed to be embedded via `h.submodel`. The consumer reacts to
|
|
94
|
+
* toggle events by pattern-matching the `ToggledOpenState` OutMessage
|
|
95
|
+
* from the third element of `update`'s return tuple. */
|
|
96
|
+
export declare const view: import("foldkit/submodel").View<{
|
|
97
|
+
readonly id: string;
|
|
98
|
+
readonly isOpen: boolean;
|
|
99
|
+
}, {
|
|
100
|
+
readonly _tag: "CompletedFocusButton";
|
|
101
|
+
} | {
|
|
102
|
+
readonly _tag: "Closed";
|
|
103
|
+
} | {
|
|
104
|
+
readonly _tag: "Toggled";
|
|
105
|
+
}, Readonly<{
|
|
106
|
+
toView: (attributes: DisclosureAttributes) => Html;
|
|
107
|
+
isDisabled?: boolean;
|
|
108
|
+
}>>;
|
|
109
|
+
export {};
|
|
110
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|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I;iBACrC,OAAO;GAkDrB,CAAA"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { Effect, Function, Match as M, Option, Schema as S } from 'effect';
|
|
2
|
+
import * as Command from 'foldkit/command';
|
|
3
|
+
import * as Dom from 'foldkit/dom';
|
|
4
|
+
import { childAttributes, html, } from 'foldkit/html';
|
|
5
|
+
import { m } from 'foldkit/message';
|
|
6
|
+
import { evo } from 'foldkit/struct';
|
|
7
|
+
import { defineView } from 'foldkit/submodel';
|
|
8
|
+
// MODEL
|
|
9
|
+
/** Schema for the disclosure component's state, tracking its unique ID and open/closed status. */
|
|
10
|
+
export const Model = S.Struct({
|
|
11
|
+
id: S.String,
|
|
12
|
+
isOpen: S.Boolean,
|
|
13
|
+
});
|
|
14
|
+
// MESSAGE
|
|
15
|
+
/** Sent when the disclosure button is clicked. Toggles the open/closed state. */
|
|
16
|
+
export const Toggled = m('Toggled');
|
|
17
|
+
/** Sent to explicitly close the disclosure, regardless of its current state. */
|
|
18
|
+
export const Closed = m('Closed');
|
|
19
|
+
/** Sent when the focus-button command completes after closing. */
|
|
20
|
+
export const CompletedFocusButton = m('CompletedFocusButton');
|
|
21
|
+
/** Union of all messages the disclosure component can produce. */
|
|
22
|
+
export const Message = S.Union([Toggled, Closed, CompletedFocusButton]);
|
|
23
|
+
// OUT MESSAGE
|
|
24
|
+
/** Sent to the parent each time the disclosure toggles. The new open state is available on the next model snapshot; this OutMessage signals only that the transition happened. Consumers typically use this for analytics, lazy content loading, or saving open/closed state to a store. */
|
|
25
|
+
export const ToggledOpenState = m('ToggledOpenState', { isOpen: S.Boolean });
|
|
26
|
+
export const OutMessage = S.Union([ToggledOpenState]);
|
|
27
|
+
/** Creates an initial disclosure model from a config. Defaults to closed. */
|
|
28
|
+
export const init = (config) => ({
|
|
29
|
+
id: config.id,
|
|
30
|
+
isOpen: config.isOpen ?? false,
|
|
31
|
+
});
|
|
32
|
+
// UPDATE
|
|
33
|
+
const buttonId = (id) => `${id}-button`;
|
|
34
|
+
const buttonSelector = (id) => `#${CSS.escape(buttonId(id))}`;
|
|
35
|
+
const panelId = (id) => `${id}-panel`;
|
|
36
|
+
/** Moves focus to the disclosure's toggle button. */
|
|
37
|
+
export const FocusButton = Command.define('FocusButton', { id: S.String }, CompletedFocusButton)(({ id }) => Dom.focus(buttonSelector(id)).pipe(Effect.ignore, Effect.as(CompletedFocusButton())));
|
|
38
|
+
const withUpdateReturn = M.withReturnType();
|
|
39
|
+
/** Processes a disclosure message and returns the next model, commands, and optional OutMessage. */
|
|
40
|
+
export const update = (model, message) => M.value(message).pipe(withUpdateReturn, M.tagsExhaustive({
|
|
41
|
+
Toggled: () => {
|
|
42
|
+
const nextIsOpen = !model.isOpen;
|
|
43
|
+
const maybeFocus = Option.liftPredicate(FocusButton({ id: model.id }), () => model.isOpen);
|
|
44
|
+
return [
|
|
45
|
+
evo(model, { isOpen: () => nextIsOpen }),
|
|
46
|
+
Option.toArray(maybeFocus),
|
|
47
|
+
Option.some(ToggledOpenState({ isOpen: nextIsOpen })),
|
|
48
|
+
];
|
|
49
|
+
},
|
|
50
|
+
Closed: () => {
|
|
51
|
+
if (!model.isOpen) {
|
|
52
|
+
return [model, [], Option.none()];
|
|
53
|
+
}
|
|
54
|
+
const maybeFocus = Option.liftPredicate(FocusButton({ id: model.id }), () => model.isOpen);
|
|
55
|
+
return [
|
|
56
|
+
evo(model, { isOpen: () => false }),
|
|
57
|
+
Option.toArray(maybeFocus),
|
|
58
|
+
Option.some(ToggledOpenState({ isOpen: false })),
|
|
59
|
+
];
|
|
60
|
+
},
|
|
61
|
+
CompletedFocusButton: () => [model, [], Option.none()],
|
|
62
|
+
}));
|
|
63
|
+
/** Programmatically toggles the disclosure, updating the model and returning
|
|
64
|
+
* focus commands plus a `ToggledOpenState` OutMessage. */
|
|
65
|
+
export const toggle = (model) => update(model, Toggled());
|
|
66
|
+
/** Programmatically closes the disclosure, updating the model and returning
|
|
67
|
+
* focus commands plus a `ToggledOpenState` OutMessage when it was open. */
|
|
68
|
+
export const close = (model) => update(model, Closed());
|
|
69
|
+
/** Reflects an externally-sourced open state onto the model without
|
|
70
|
+
* emitting an OutMessage or running the focus command. Use this to mirror
|
|
71
|
+
* external truth (restored storage, a deep link) onto the disclosure.
|
|
72
|
+
* Contrast with `toggle`/`close`, which represent user or programmatic
|
|
73
|
+
* *choices* and emit `ToggledOpenState`. Returns the model directly
|
|
74
|
+
* because it produces no commands and no OutMessage. */
|
|
75
|
+
export const reflectOpenState = Function.dual(2, (model, isOpen) => evo(model, { isOpen: () => isOpen }));
|
|
76
|
+
/** Renders a headless disclosure component with accessible ARIA
|
|
77
|
+
* attributes and keyboard support. The consumer composes the layout
|
|
78
|
+
* through the `toView` slot, spreading the published `button` and
|
|
79
|
+
* `panel` attribute bundles onto their own elements.
|
|
80
|
+
*
|
|
81
|
+
* Designed to be embedded via `h.submodel`. The consumer reacts to
|
|
82
|
+
* toggle events by pattern-matching the `ToggledOpenState` OutMessage
|
|
83
|
+
* from the third element of `update`'s return tuple. */
|
|
84
|
+
export const view = defineView((model, viewInputs) => {
|
|
85
|
+
const h = html();
|
|
86
|
+
const { id, isOpen } = model;
|
|
87
|
+
const { toView, isDisabled = false } = viewInputs;
|
|
88
|
+
const handleKeyDown = (key) => M.value(key).pipe(M.whenOr('Enter', ' ', () => Option.some(Toggled())), M.orElse(() => Option.none()));
|
|
89
|
+
const disabledAttributes = isDisabled
|
|
90
|
+
? [h.AriaDisabled(true), h.DataAttribute('disabled', '')]
|
|
91
|
+
: [];
|
|
92
|
+
const buttonAttributes = [
|
|
93
|
+
h.Id(buttonId(id)),
|
|
94
|
+
h.AriaExpanded(isOpen),
|
|
95
|
+
h.AriaControls(panelId(id)),
|
|
96
|
+
h.Tabindex(0),
|
|
97
|
+
...(isOpen ? [h.DataAttribute('open', '')] : []),
|
|
98
|
+
...disabledAttributes,
|
|
99
|
+
...(isDisabled
|
|
100
|
+
? []
|
|
101
|
+
: [h.OnClick(Toggled()), h.OnKeyDownPreventDefault(handleKeyDown)]),
|
|
102
|
+
];
|
|
103
|
+
const panelAttributes = [
|
|
104
|
+
h.Id(panelId(id)),
|
|
105
|
+
...(isOpen ? [h.DataAttribute('open', '')] : []),
|
|
106
|
+
];
|
|
107
|
+
return toView({
|
|
108
|
+
button: childAttributes(buttonAttributes),
|
|
109
|
+
panel: childAttributes(panelAttributes),
|
|
110
|
+
});
|
|
111
|
+
});
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { init, update, toggle, close, reflectOpenState, view, Model, Message, OutMessage, ToggledOpenState, Closed, CompletedFocusButton, FocusButton, } from './index.js';
|
|
2
|
+
export type { InitConfig, ViewInputs, DisclosureAttributes, Toggled, } from './index.js';
|
|
3
|
+
//# sourceMappingURL=public.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../src/disclosure/public.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,MAAM,EACN,MAAM,EACN,KAAK,EACL,gBAAgB,EAChB,IAAI,EACJ,KAAK,EACL,OAAO,EACP,UAAU,EACV,gBAAgB,EAChB,MAAM,EACN,oBAAoB,EACpB,WAAW,GACZ,MAAM,YAAY,CAAA;AAEnB,YAAY,EACV,UAAU,EACV,UAAU,EACV,oBAAoB,EACpB,OAAO,GACR,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { init, update, toggle, close, reflectOpenState, view, Model, Message, OutMessage, ToggledOpenState, Closed, CompletedFocusButton, FocusButton, } from './index.js';
|