foldkit-mixins-ui 0.25.0 → 0.26.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/README.md +5 -4
- package/dist/button.d.ts +4 -3
- package/dist/button.d.ts.map +1 -1
- package/dist/button.js +16 -12
- package/dist/button.js.map +1 -1
- package/dist/datePickerView.d.ts +10 -10
- package/dist/recipes/disclosure.d.ts.map +1 -1
- package/dist/recipes/disclosure.js +3 -2
- package/dist/recipes/disclosure.js.map +1 -1
- package/dist/switch.d.ts.map +1 -1
- package/dist/switch.js +14 -2
- package/dist/switch.js.map +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -297,9 +297,10 @@ form, on Enter or a press: refuse the submit in `update` while it should not
|
|
|
297
297
|
go.
|
|
298
298
|
|
|
299
299
|
`attributes: { button?, icon? }` adds what another component hands a slot,
|
|
300
|
-
|
|
301
|
-
that button (`attributes: { button:
|
|
302
|
-
them
|
|
300
|
+
before the mixins resolve, as `PasswordInput.view`'s do: a Dialog's
|
|
301
|
+
`initialFocus`, so the dialog opens on that button (`attributes: { button:
|
|
302
|
+
dialog.initialFocus }`). A class among them joins the style's, and an event
|
|
303
|
+
or attribute a mixin owns is a conflict.
|
|
303
304
|
|
|
304
305
|
An `icon` (an `svg`) draws before the label in the `icon` slot, hidden from
|
|
305
306
|
assistive technology; `Recipes.Button({ variant: 'icon' })` shows the icon
|
|
@@ -562,7 +563,7 @@ adapter.
|
|
|
562
563
|
| Textarea | `textarea`, `label`, `description`, `count`, `frame`, `footer`, `meta` |
|
|
563
564
|
| Select | `select`, `label`, `description`. The native `<select>`; the recipe draws its own chevron and mutes a chosen placeholder. For icons, descriptions, groups or a check in the list, draw a Listbox as a custom select with `Listbox.parts` (below) |
|
|
564
565
|
| Checkbox | `checkbox`, `label`, `description`, `hiddenInput` |
|
|
565
|
-
| Switch | `button`, `label`, `description`, `hiddenInput`. `Switch.draggable(onToggle)` beside the style lets the thumb be dragged: it follows the pointer past 4px, and on release `onToggle` is sent for the side its middle is on (nothing when that is the side it began on); a click after a drag is swallowed, right to left mirrors it, and a disabled or read-only switch does not drag. Pass the `onToggle` the view was given |
|
|
566
|
+
| Switch | `button`, `label`, `description`, `hiddenInput`. `Switch.draggable(onToggle)` beside the style lets the thumb be dragged: it follows the pointer past 4px, and on release `onToggle` is sent for the side its middle is on (nothing when that is the side it began on); a click after a drag is swallowed, right to left mirrors it, and a disabled or read-only switch does not drag. The thumb is held where it was let go for 300ms or until `aria-checked` changes, so an `update` that refuses the toggle sends it back. Pass the `onToggle` the view was given |
|
|
566
567
|
| Fieldset | `fieldset`, `legend`, `description`. The recipe floats the legend into the group, so a box drawn round it holds the legend, and a disabled fieldset dims its legend and description beside the controls the browser disables. Recipe `variant`: `plain` (default, no box), `bordered`, `filled`; a boxed group pads its fields, and a control in it takes a corner concentric with the box's |
|
|
567
568
|
| Disclosure | `button`, `panel`. The recipe draws the button as a row with a chevron of its own (down shut, up once `data-open`) and the panel's box; draw the panel only while open, or through upstream's `animatePanel`, which keeps a shut panel inert and moves its height itself by an inline transition, which the recipe overrides with an important rule so the `motion` knob scales it and reduced motion snaps it. Recipe `variant`: `plain` (default), `bordered` (one box round the button and the panel, whose lower corners square onto the panel while open), `ghost` (filled under the pointer); `indicator`: `chevron` (default), `none` |
|
|
568
569
|
| Dialog | `dialog`, `backdrop`, `panel`, `title`, `description`, `initialFocus`, `closeButton`, and this package's `handle` (the Sheet's grabber, `aria-hidden`), `body`, `scroll`, `scrollBar`, `scrollThumb` and `footer`: draw `scroll` and its bar inside `body` and the answers in `footer`, and a body taller than the screen scrolls under the title while the footer stays (`Dialog.overlayBars` beside the style draws the overlay bar). `Dialog.keyboard` among the mixins of a dialog or sheet that holds a field measures the on-screen keyboard on the panel, and the recipes keep the panel above it (a Dialog shrinks, a bottom Sheet stands on it): iOS Safari and Chrome on Android otherwise leave it under the keys. An alert dialog is this one with `role: 'alertdialog'` in its context (`Dialog.toView(mixins, { h, role: 'alertdialog' }, draw)`), which puts `role="alertdialog"` on the `dialog` bundle; draw no close button, and drop the Messages `Dialog.isDismissal` names (Escape, the backdrop, the close button) in `update`, so only its own buttons, closing with `@foldkit/ui`'s `close`, answer it. `covered: true` in the context marks the panel `data-covered`, for a dialog another was opened from (draw the second inside the first's `dialog`, beside its panel), and the recipe steps it back; `attributes` adds to a bundle before the mixins resolve. Recipe `size`: `sm`, `md` (default), `lg`, `xl`, `full`; `title`: `shown` (default) or `hidden`, which leaves the heading to a screen reader alone (it still names the dialog, as `display: none` would not). The backdrop is the `overlay.scrim` token |
|
package/dist/button.d.ts
CHANGED
|
@@ -46,9 +46,10 @@ export interface ButtonView<Message> {
|
|
|
46
46
|
*/
|
|
47
47
|
readonly pressed?: boolean | undefined;
|
|
48
48
|
/**
|
|
49
|
-
* Attributes another component hands this button,
|
|
50
|
-
*
|
|
51
|
-
*
|
|
49
|
+
* Attributes another component hands this button, added to its Slot before
|
|
50
|
+
* the mixins resolve, as `PasswordInput.view`'s are: a Dialog's
|
|
51
|
+
* `initialFocus`, so the dialog opens on it. A class among them joins the
|
|
52
|
+
* recipe's, and an owned event or attribute among them is a conflict.
|
|
52
53
|
*/
|
|
53
54
|
readonly attributes?: { readonly [K in keyof typeof ButtonSlots]?: SlotAttributes<Message>; };
|
|
54
55
|
}
|
package/dist/button.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"button.d.ts","names":[],"sources":["../src/button.ts"],"mappings":";;;;;;;;;;qBAmBa,aAAW,MAAA;;;;;YAUZ,eAAe,WAAW,SACpC,iBAAiB,iBACV,aACP;;qBAIW,UAAW,OAAO,SAAO,YACxB,iBAAiB,UAAQ,QAC7B,UAAU,UAAQ,SACjB,eAAe,OAAO,aAC9B,eAAe;;qBAGL,SACV,SAAO,QACE,UAAU,UAAQ,SACjB,wBAAwB,UAAQ,OAClC,UAAU,eAAe,aAAa,UAAI,YAEtC,iBAAiB,aAAW;;;;;;iBAQ1B,WAAW;;;;;WAKjB;;WAEA,OAAO;;WAEP,QAAQ,kBAAkB;;WAE1B,SAAS,UAAU;;WAEnB;WACA;WACA;WACA,UAAU;;;;;WAKV
|
|
1
|
+
{"version":3,"file":"button.d.ts","names":[],"sources":["../src/button.ts"],"mappings":";;;;;;;;;;qBAmBa,aAAW,MAAA;;;;;YAUZ,eAAe,WAAW,SACpC,iBAAiB,iBACV,aACP;;qBAIW,UAAW,OAAO,SAAO,YACxB,iBAAiB,UAAQ,QAC7B,UAAU,UAAQ,SACjB,eAAe,OAAO,aAC9B,eAAe;;qBAGL,SACV,SAAO,QACE,UAAU,UAAQ,SACjB,wBAAwB,UAAQ,OAClC,UAAU,eAAe,aAAa,UAAI,YAEtC,iBAAiB,aAAW;;;;;;iBAQ1B,WAAW;;;;;WAKjB;;WAEA,OAAO;;WAEP,QAAQ,kBAAkB;;WAE1B,SAAS,UAAU;;WAEnB;WACA;WACA;WACA,UAAU;;;;;WAKV;;;;;;;WAOA,yBAAyB,kBAAkB,eAAe,eAAe;;qBAGvE,OAAQ,SAAO,SAAW,WAAW,UAAQ,GAAK,YAAY,aAAW"}
|
package/dist/button.js
CHANGED
|
@@ -29,18 +29,22 @@ const view = (options, h) => view$1({
|
|
|
29
29
|
...options.type === void 0 ? {} : { type: options.type },
|
|
30
30
|
...options.disabled === void 0 ? {} : { isDisabled: options.disabled },
|
|
31
31
|
...options.onClick === void 0 ? {} : { onClick: options.onClick },
|
|
32
|
-
toView:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
...options.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
32
|
+
toView: (attributes) => {
|
|
33
|
+
const base = [
|
|
34
|
+
...attributes.button,
|
|
35
|
+
...options.pressed === void 0 ? [] : [h.AriaPressed(String(options.pressed))],
|
|
36
|
+
...options.attributes?.button ?? []
|
|
37
|
+
];
|
|
38
|
+
const { button, icon } = resolveFor(ButtonSlots, [...options.style === void 0 ? [] : [options.style.mixin], ...options.mixins ?? []], {
|
|
39
|
+
input: options.input,
|
|
40
|
+
h
|
|
41
|
+
})({
|
|
42
|
+
...attributes,
|
|
43
|
+
button: base,
|
|
44
|
+
icon: options.attributes?.icon ?? []
|
|
45
|
+
});
|
|
46
|
+
return h.button(button, options.icon === void 0 ? [options.label] : [h.span([...icon, h.AriaHidden(true)], [options.icon]), options.label]);
|
|
47
|
+
}
|
|
44
48
|
}, h);
|
|
45
49
|
export { ButtonSlots, resolve, toView, view };
|
|
46
50
|
|
package/dist/button.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"button.js","names":["buttonView"],"sources":["../src/button.ts"],"sourcesContent":["import { view as buttonView, type ButtonAttributes } from '@foldkit/ui/button'\nimport {\n Attr,\n Capability,\n Event,\n Slot,\n Slots,\n type NamedStyle,\n type SlotAttributes,\n} from 'foldkit-mixins'\nimport type { Html, HtmlBuilder } from 'foldkit/html'\nimport { resolveFor, type MixinList, type ResolveContext, type Resolved } from './resolve.js'\n\n/**\n * The button publishes the button and the box its `icon` stands in. `click`\n * is owned by the base `OnClick` when the button is interactive, so a Behavior\n * that adds its own click handler is a conflict rather than a second silent\n * owner.\n */\nexport const ButtonSlots = Slots.define({\n button: Slot.make({\n capability: Capability.Interactive,\n events: [Event.Click],\n attributes: [Attr.Role, Attr.AriaDisabled, Attr.Disabled, Attr.AriaPressed],\n }),\n icon: Slot.make({ capability: Capability.Container }),\n})\n\n/** The button's bundles with the attached Mixins applied. */\nexport type ResolvedButton<Message> = Resolved<\n ButtonAttributes<Message>,\n typeof ButtonSlots,\n Message\n>\n\n/** Applies `mixins` to the button's bundles. */\nexport const resolve = <Input, Message>(\n attributes: ButtonAttributes<Message>,\n mixins: MixinList<Message>,\n context: ResolveContext<Input, Message>,\n): ResolvedButton<Message> => resolveFor(ButtonSlots, mixins, context)(attributes)\n\n/** The button's `toView`: `draw` receives its bundles with `mixins` applied. */\nexport const toView =\n <Message>(\n mixins: MixinList<Message>,\n context: ResolveContext<unknown, Message>,\n draw: (resolved: ResolvedButton<Message>) => Html,\n ) =>\n (attributes: ButtonAttributes<Message>): Html =>\n draw(resolve(attributes, mixins, context))\n\n/**\n * A button in one call: the label, a style for its slot, and the rest of\n * `@foldkit/ui`'s own config. `toView` stays for a button drawn as something\n * else (an `a`, a split control); this covers the common case.\n */\nexport interface ButtonView<Message> {\n /**\n * The button's text, and its accessible name. The recipe's `icon` variant\n * hides it from sight and draws the `icon` alone.\n */\n readonly label: string\n /** A drawing before the label (an `svg`), hidden from assistive technology. */\n readonly icon?: Html | undefined\n /** A style of `ButtonSlots`, for the button's own look. */\n readonly style?: NamedStyle<typeof ButtonSlots> | undefined\n /** Mixins beside the style, for state or behavior the style does not own. */\n readonly mixins?: MixinList<Message> | undefined\n /** What an input-driven Mixin reads; omit it when no attached Mixin reads one. */\n readonly input?: unknown\n readonly type?: 'button' | 'submit' | 'reset' | undefined\n readonly disabled?: boolean | undefined\n readonly onClick?: Message | undefined\n /**\n * Whether the button is on, as a toggle button: `aria-pressed`, and the\n * recipe's pressed look. Omit it for a button that is not a toggle.\n */\n readonly pressed?: boolean | undefined\n /**\n * Attributes another component hands this button,
|
|
1
|
+
{"version":3,"file":"button.js","names":["buttonView"],"sources":["../src/button.ts"],"sourcesContent":["import { view as buttonView, type ButtonAttributes } from '@foldkit/ui/button'\nimport {\n Attr,\n Capability,\n Event,\n Slot,\n Slots,\n type NamedStyle,\n type SlotAttributes,\n} from 'foldkit-mixins'\nimport type { Html, HtmlBuilder } from 'foldkit/html'\nimport { resolveFor, type MixinList, type ResolveContext, type Resolved } from './resolve.js'\n\n/**\n * The button publishes the button and the box its `icon` stands in. `click`\n * is owned by the base `OnClick` when the button is interactive, so a Behavior\n * that adds its own click handler is a conflict rather than a second silent\n * owner.\n */\nexport const ButtonSlots = Slots.define({\n button: Slot.make({\n capability: Capability.Interactive,\n events: [Event.Click],\n attributes: [Attr.Role, Attr.AriaDisabled, Attr.Disabled, Attr.AriaPressed],\n }),\n icon: Slot.make({ capability: Capability.Container }),\n})\n\n/** The button's bundles with the attached Mixins applied. */\nexport type ResolvedButton<Message> = Resolved<\n ButtonAttributes<Message>,\n typeof ButtonSlots,\n Message\n>\n\n/** Applies `mixins` to the button's bundles. */\nexport const resolve = <Input, Message>(\n attributes: ButtonAttributes<Message>,\n mixins: MixinList<Message>,\n context: ResolveContext<Input, Message>,\n): ResolvedButton<Message> => resolveFor(ButtonSlots, mixins, context)(attributes)\n\n/** The button's `toView`: `draw` receives its bundles with `mixins` applied. */\nexport const toView =\n <Message>(\n mixins: MixinList<Message>,\n context: ResolveContext<unknown, Message>,\n draw: (resolved: ResolvedButton<Message>) => Html,\n ) =>\n (attributes: ButtonAttributes<Message>): Html =>\n draw(resolve(attributes, mixins, context))\n\n/**\n * A button in one call: the label, a style for its slot, and the rest of\n * `@foldkit/ui`'s own config. `toView` stays for a button drawn as something\n * else (an `a`, a split control); this covers the common case.\n */\nexport interface ButtonView<Message> {\n /**\n * The button's text, and its accessible name. The recipe's `icon` variant\n * hides it from sight and draws the `icon` alone.\n */\n readonly label: string\n /** A drawing before the label (an `svg`), hidden from assistive technology. */\n readonly icon?: Html | undefined\n /** A style of `ButtonSlots`, for the button's own look. */\n readonly style?: NamedStyle<typeof ButtonSlots> | undefined\n /** Mixins beside the style, for state or behavior the style does not own. */\n readonly mixins?: MixinList<Message> | undefined\n /** What an input-driven Mixin reads; omit it when no attached Mixin reads one. */\n readonly input?: unknown\n readonly type?: 'button' | 'submit' | 'reset' | undefined\n readonly disabled?: boolean | undefined\n readonly onClick?: Message | undefined\n /**\n * Whether the button is on, as a toggle button: `aria-pressed`, and the\n * recipe's pressed look. Omit it for a button that is not a toggle.\n */\n readonly pressed?: boolean | undefined\n /**\n * Attributes another component hands this button, added to its Slot before\n * the mixins resolve, as `PasswordInput.view`'s are: a Dialog's\n * `initialFocus`, so the dialog opens on it. A class among them joins the\n * recipe's, and an owned event or attribute among them is a conflict.\n */\n readonly attributes?: { readonly [K in keyof typeof ButtonSlots]?: SlotAttributes<Message> }\n}\n\nexport const view = <Message>(options: ButtonView<Message>, h: HtmlBuilder<Message>): Html =>\n buttonView(\n {\n ...(options.type === undefined ? {} : { type: options.type }),\n ...(options.disabled === undefined ? {} : { isDisabled: options.disabled }),\n ...(options.onClick === undefined ? {} : { onClick: options.onClick }),\n toView: attributes => {\n const base: SlotAttributes<Message> = [\n ...attributes.button,\n ...(options.pressed === undefined ? [] : [h.AriaPressed(String(options.pressed))]),\n ...(options.attributes?.button ?? []),\n ]\n const { button, icon } = resolveFor(\n ButtonSlots,\n [\n ...(options.style === undefined ? [] : [options.style.mixin]),\n ...(options.mixins ?? []),\n ],\n { input: options.input, h },\n )({ ...attributes, button: base, icon: options.attributes?.icon ?? [] })\n return h.button(\n button,\n options.icon === undefined\n ? [options.label]\n : [h.span([...icon, h.AriaHidden(true)], [options.icon]), options.label],\n )\n },\n },\n h,\n )\n"],"mappings":";;;;;;;;;;AAmBA,MAAa,cAAc,MAAM,OAAO;CACtC,QAAQ,KAAK,KAAK;EAChB,YAAY,WAAW;EACvB,QAAQ,CAAC,MAAM,KAAK;EACpB,YAAY;GAAC,KAAK;GAAM,KAAK;GAAc,KAAK;GAAU,KAAK;EAAW;CAC5E,CAAC;CACD,MAAM,KAAK,KAAK,EAAE,YAAY,WAAW,UAAU,CAAC;AACtD,CAAC;;AAUD,MAAa,WACX,YACA,QACA,YAC4B,WAAW,aAAa,QAAQ,OAAO,CAAC,CAAC,UAAU;;AAGjF,MAAa,UAET,QACA,SACA,UAED,eACC,KAAK,QAAQ,YAAY,QAAQ,OAAO,CAAC;AAsC7C,MAAa,QAAiB,SAA8B,MAC1DA,OACE;CACE,GAAI,QAAQ,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,MAAM,QAAQ,KAAK;CAC3D,GAAI,QAAQ,aAAa,KAAA,IAAY,CAAC,IAAI,EAAE,YAAY,QAAQ,SAAS;CACzE,GAAI,QAAQ,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,QAAQ,QAAQ;CACpE,SAAQ,eAAc;EACpB,MAAM,OAAgC;GACpC,GAAG,WAAW;GACd,GAAI,QAAQ,YAAY,KAAA,IAAY,CAAC,IAAI,CAAC,EAAE,YAAY,OAAO,QAAQ,OAAO,CAAC,CAAC;GAChF,GAAI,QAAQ,YAAY,UAAU,CAAC;EACrC;EACA,MAAM,EAAE,QAAQ,SAAS,WACvB,aACA,CACE,GAAI,QAAQ,UAAU,KAAA,IAAY,CAAC,IAAI,CAAC,QAAQ,MAAM,KAAK,GAC3D,GAAI,QAAQ,UAAU,CAAC,CACzB,GACA;GAAE,OAAO,QAAQ;GAAO;EAAE,CAC5B,CAAC,CAAC;GAAE,GAAG;GAAY,QAAQ;GAAM,MAAM,QAAQ,YAAY,QAAQ,CAAC;EAAE,CAAC;EACvE,OAAO,EAAE,OACP,QACA,QAAQ,SAAS,KAAA,IACb,CAAC,QAAQ,KAAK,IACd,CAAC,EAAE,KAAK,CAAC,GAAG,MAAM,EAAE,WAAW,IAAI,CAAC,GAAG,CAAC,QAAQ,IAAI,CAAC,GAAG,QAAQ,KAAK,CAC3E;CACF;AACF,GACA,CACF"}
|
package/dist/datePickerView.d.ts
CHANGED
|
@@ -260,10 +260,10 @@ export declare const view: import("foldkit/submodel").View<{
|
|
|
260
260
|
};
|
|
261
261
|
}, {
|
|
262
262
|
readonly _tag: "Closed";
|
|
263
|
-
} | {
|
|
264
|
-
readonly _tag: "Opened";
|
|
265
263
|
} | {
|
|
266
264
|
readonly _tag: "Cleared";
|
|
265
|
+
} | {
|
|
266
|
+
readonly _tag: "Opened";
|
|
267
267
|
} | {
|
|
268
268
|
readonly _tag: "GotCalendarMessage";
|
|
269
269
|
readonly message: {
|
|
@@ -309,6 +309,10 @@ export declare const view: import("foldkit/submodel").View<{
|
|
|
309
309
|
} | {
|
|
310
310
|
readonly _tag: "GotPopoverMessage";
|
|
311
311
|
readonly message: {
|
|
312
|
+
readonly _tag: "ClickedButton";
|
|
313
|
+
} | {
|
|
314
|
+
readonly _tag: "CompletedFocusButton";
|
|
315
|
+
} | {
|
|
312
316
|
readonly _tag: "CompletedInertOthers";
|
|
313
317
|
} | {
|
|
314
318
|
readonly _tag: "CompletedLockScroll";
|
|
@@ -316,18 +320,14 @@ export declare const view: import("foldkit/submodel").View<{
|
|
|
316
320
|
readonly _tag: "CompletedRestoreInert";
|
|
317
321
|
} | {
|
|
318
322
|
readonly _tag: "CompletedUnlockScroll";
|
|
319
|
-
} | {
|
|
320
|
-
readonly _tag: "RequestedClose";
|
|
321
|
-
} | {
|
|
322
|
-
readonly _tag: "RequestedOpen";
|
|
323
|
-
} | {
|
|
324
|
-
readonly _tag: "ClickedButton";
|
|
325
|
-
} | {
|
|
326
|
-
readonly _tag: "CompletedFocusButton";
|
|
327
323
|
} | {
|
|
328
324
|
readonly _tag: "IgnoredMouseClick";
|
|
329
325
|
} | {
|
|
330
326
|
readonly _tag: "SuppressedSpaceScroll";
|
|
327
|
+
} | {
|
|
328
|
+
readonly _tag: "RequestedClose";
|
|
329
|
+
} | {
|
|
330
|
+
readonly _tag: "RequestedOpen";
|
|
331
331
|
} | {
|
|
332
332
|
readonly _tag: "BlurredPanel";
|
|
333
333
|
} | {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"disclosure.d.ts","names":[],"sources":["../../src/recipes/disclosure.ts"],"mappings":"A,
|
|
1
|
+
{"version":3,"file":"disclosure.d.ts","names":[],"sources":["../../src/recipes/disclosure.ts"],"mappings":"A,qBAqDa,qCAAU,oCAAA;;;;;IAsCjB;IACA;MACE,iCAAM;MASN,gCAAK;;IAWP;MACE,iCAAM;MAIN,gCAAK;;;;IAIP;MACE,iCAAM;;IAKR"}
|
|
@@ -13,7 +13,7 @@ import { component, controlHeight, disabled, focusRing, hover, ref, transition,
|
|
|
13
13
|
* inert and moves its height by an inline transition on a grid it draws
|
|
14
14
|
* round the panel, with no slot, class or attribute of its own. A recipe
|
|
15
15
|
* rule cannot beat an inline one, so `heightTravel` is an important global
|
|
16
|
-
* rule that finds that grid by the panel
|
|
16
|
+
* rule that finds that grid by the panel's class and sets its duration to
|
|
17
17
|
* a travel: the `motion` knob scales it and reduced motion snaps it.
|
|
18
18
|
*
|
|
19
19
|
* The axes:
|
|
@@ -26,7 +26,8 @@ import { component, controlHeight, disabled, focusRing, hover, ref, transition,
|
|
|
26
26
|
* its own icon.
|
|
27
27
|
*/
|
|
28
28
|
const open = "&[data-open]";
|
|
29
|
-
const
|
|
29
|
+
const panelClass = "fk-disclosure-panel";
|
|
30
|
+
const heightTravel = Style.compose(Style.class(panelClass), Style.global(`div[style*="grid-template-rows"]:has(>div>.${panelClass}){transition-duration:${travelled(ref.motion.fast)}!important}`));
|
|
30
31
|
const edge = `${ref.border.thin} solid ${ref.outline.default}`;
|
|
31
32
|
const Disclosure = Style.recipeFor(DisclosureSlots)({
|
|
32
33
|
base: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"disclosure.js","names":[],"sources":["../../src/recipes/disclosure.ts"],"sourcesContent":["/**\n * A disclosure: one button that shows and hides one panel, `@foldkit/ui`'s\n * Disclosure. The button is a row, and its chevron is drawn on the button\n * itself, since the disclosure has no slot for one: down while shut, up\n * once open (upstream's `data-open`). The panel's box is the recipe's;\n * whether it is drawn, and its height as it opens, are upstream's: draw the\n * panel only while open, or through `animatePanel`, which keeps a shut panel\n * inert and moves its height by an inline transition on a grid it draws\n * round the panel, with no slot, class or attribute of its own. A recipe\n * rule cannot beat an inline one, so `heightTravel` is an important global\n * rule that finds that grid by the panel
|
|
1
|
+
{"version":3,"file":"disclosure.js","names":[],"sources":["../../src/recipes/disclosure.ts"],"sourcesContent":["/**\n * A disclosure: one button that shows and hides one panel, `@foldkit/ui`'s\n * Disclosure. The button is a row, and its chevron is drawn on the button\n * itself, since the disclosure has no slot for one: down while shut, up\n * once open (upstream's `data-open`). The panel's box is the recipe's;\n * whether it is drawn, and its height as it opens, are upstream's: draw the\n * panel only while open, or through `animatePanel`, which keeps a shut panel\n * inert and moves its height by an inline transition on a grid it draws\n * round the panel, with no slot, class or attribute of its own. A recipe\n * rule cannot beat an inline one, so `heightTravel` is an important global\n * rule that finds that grid by the panel's class and sets its duration to\n * a travel: the `motion` knob scales it and reduced motion snaps it.\n *\n * The axes:\n *\n * - `variant`: `plain` (the default) flush with the page; `bordered` one box\n * round the button and the panel, the button's lower corners squaring\n * onto the panel while open; `ghost` a button that fills under the\n * pointer and nowhere else.\n * - `indicator`: `chevron` (the default), or `none` for a button that draws\n * its own icon.\n */\nimport { Style } from 'foldkit-mixins'\nimport { ladder, role } from 'foldkit-mixins/theme'\nimport { DisclosureSlots } from '../disclosure.js'\nimport {\n component,\n controlHeight,\n disabled,\n focusRing,\n hover,\n ref,\n transition,\n travelled,\n triggerChevron,\n unfilledHover,\n variant,\n} from './design.js'\n\nconst open = '&[data-open]'\n// Upstream writes `grid-template-rows 200ms ease-out` inline on the grid round\n// the panel, so only `!important` wins. The grid is found by this recipe's own\n// panel class, not by upstream's `-panel` id, which an application's grid\n// round a Tabs panel matches too.\nconst panelClass = 'fk-disclosure-panel'\nconst heightTravel = Style.compose(\n Style.class(panelClass),\n Style.global(\n `div[style*=\"grid-template-rows\"]:has(>div>.${panelClass}){transition-duration:${travelled(ref.motion.fast)}!important}`,\n ),\n)\nconst edge = `${ref.border.thin} solid ${ref.outline.default}`\n\nexport const Disclosure = Style.recipeFor(DisclosureSlots)({\n base: {\n button: component(\n Style.self({\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'space-between',\n gap: ladder('gap'),\n inlineSize: '100%',\n minBlockSize: controlHeight,\n paddingBlock: ladder('row-pad'),\n paddingInline: '0',\n border: '0',\n background: 'transparent',\n color: ref.text.default,\n font: 'inherit',\n fontWeight: ref.weight.medium,\n textAlign: 'start',\n cursor: 'pointer',\n ...transition('color, background-color'),\n }),\n hover({ color: ref.text.overt }),\n Style.nest(open, { color: ref.text.overt }),\n focusRing,\n disabled,\n ),\n panel: component(\n heightTravel,\n Style.self({\n paddingBlockEnd: ladder('row-pad'),\n paddingInline: '0',\n color: ref.text.muted,\n ...role('body'),\n }),\n ),\n },\n variants: {\n variant: {\n plain: {},\n bordered: {\n button: variant(\n Style.self({\n paddingInline: ladder('row-pad'),\n border: edge,\n borderRadius: ref.radius.lg,\n }),\n // Longhands, so the corners left round are the base's.\n Style.nest(open, { borderEndStartRadius: '0', borderEndEndRadius: '0' }),\n ),\n panel: variant(\n Style.self({\n paddingBlockStart: ladder('row-pad'),\n paddingInline: ladder('row-pad'),\n borderInline: edge,\n borderBlockEnd: edge,\n borderEndStartRadius: ref.radius.lg,\n borderEndEndRadius: ref.radius.lg,\n }),\n ),\n },\n ghost: {\n button: variant(\n Style.self({ paddingInline: ladder('row-pad'), borderRadius: ref.radius.md }),\n hover({ background: unfilledHover }),\n ),\n panel: variant(Style.self({ paddingInline: ladder('row-pad') })),\n },\n },\n indicator: {\n chevron: {\n button: variant(\n triggerChevron(open, '0.45em', '::after'),\n Style.nest('&::after', { color: ref.text.muted }),\n ),\n },\n none: {},\n },\n },\n defaults: { variant: 'plain', indicator: 'chevron' },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,MAAM,OAAO;AAKb,MAAM,aAAa;AACnB,MAAM,eAAe,MAAM,QACzB,MAAM,MAAM,UAAU,GACtB,MAAM,OACJ,8CAA8C,WAAW,wBAAwB,UAAU,IAAI,OAAO,IAAI,EAAE,YAC9G,CACF;AACA,MAAM,OAAO,GAAG,IAAI,OAAO,KAAK,SAAS,IAAI,QAAQ;AAErD,MAAa,aAAa,MAAM,UAAU,eAAe,CAAC,CAAC;CACzD,MAAM;EACJ,QAAQ,UACN,MAAM,KAAK;GACT,SAAS;GACT,YAAY;GACZ,gBAAgB;GAChB,KAAK,OAAO,KAAK;GACjB,YAAY;GACZ,cAAc;GACd,cAAc,OAAO,SAAS;GAC9B,eAA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AU;AACrD,CAAC"}
|
package/dist/switch.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"switch.d.ts","names":[],"sources":["../src/switch.ts"],"mappings":";;;;;qBAQa,aAAW,MAAA;;;;;;;YAkBZ,eAAe,WAAW,SACpC,iBAAiB,iBACV,aACP;;qBAIW,UAAW,OAAO,SAAO,YACxB,iBAAiB,UAAQ,QAC7B,UAAU,UAAQ,SACjB,eAAe,OAAO,aAC9B,eAAe;;qBAGL,SACV,SAAO,QACE,UAAU,UAAQ,SACjB,wBAAwB,UAAQ,OAClC,UAAU,eAAe,aAAa,UAAI,YAEtC,iBAAiB,aAAW;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"switch.d.ts","names":[],"sources":["../src/switch.ts"],"mappings":";;;;;qBAQa,aAAW,MAAA;;;;;;;YAkBZ,eAAe,WAAW,SACpC,iBAAiB,iBACV,aACP;;qBAIW,UAAW,OAAO,SAAO,YACxB,iBAAiB,UAAQ,QAC7B,UAAU,UAAQ,SACjB,eAAe,OAAO,aAC9B,eAAe;;qBAGL,SACV,SAAO,QACE,UAAU,UAAQ,SACjB,wBAAwB,UAAQ,OAClC,UAAU,eAAe,aAAa,UAAI,YAEtC,iBAAiB,aAAW;;;;;;;;;;qBA6J9B,YAAa,SAAO,WAAa,uBAAuB,qCAAO,WAAA"}
|
package/dist/switch.js
CHANGED
|
@@ -33,6 +33,12 @@ const toView = (mixins, context, draw) => (attributes) => draw(resolve(attribute
|
|
|
33
33
|
const DRAG_SLOP = 4;
|
|
34
34
|
/** How long, in milliseconds, after a drag's release its click is still swallowed. */
|
|
35
35
|
const CLICK_AFTER_DRAG = 100;
|
|
36
|
+
/**
|
|
37
|
+
* How long, in milliseconds, the thumb is held where it was let go for the
|
|
38
|
+
* Model's answer. An `update` that refuses the toggle never changes
|
|
39
|
+
* `aria-checked`, so nothing else would end the hold.
|
|
40
|
+
*/
|
|
41
|
+
const HOLD_FOR_ANSWER = 300;
|
|
36
42
|
const Dragged = Schema.TaggedStruct("SwitchDragged", { isChecked: Schema.Boolean });
|
|
37
43
|
/** The thumb's `translate` along the track from where it rests unchecked, in either direction. */
|
|
38
44
|
const placeOf = (element, sign) => {
|
|
@@ -57,7 +63,10 @@ const Drag = Mount.defineStream("SwitchDrag", {
|
|
|
57
63
|
let settle = Option.none();
|
|
58
64
|
let releasedAt = Number.NEGATIVE_INFINITY;
|
|
59
65
|
const rest = () => {
|
|
60
|
-
if (Option.isSome(settle))
|
|
66
|
+
if (Option.isSome(settle)) {
|
|
67
|
+
settle.value.observer.disconnect();
|
|
68
|
+
clearTimeout(settle.value.timer);
|
|
69
|
+
}
|
|
61
70
|
settle = Option.none();
|
|
62
71
|
element.removeAttribute("data-dragging");
|
|
63
72
|
styled.style.removeProperty("--_fk-switch-drag");
|
|
@@ -106,7 +115,10 @@ const Drag = Mount.defineStream("SwitchDrag", {
|
|
|
106
115
|
attributes: true,
|
|
107
116
|
attributeFilter: ["aria-checked"]
|
|
108
117
|
});
|
|
109
|
-
settle = Option.some(
|
|
118
|
+
settle = Option.some({
|
|
119
|
+
observer,
|
|
120
|
+
timer: window.setTimeout(rest, HOLD_FOR_ANSWER)
|
|
121
|
+
});
|
|
110
122
|
Queue.offerUnsafe(queue, Dragged.make({ isChecked }));
|
|
111
123
|
};
|
|
112
124
|
const during = [
|
package/dist/switch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"switch.js","names":[],"sources":["../src/switch.ts"],"sourcesContent":["import type { SwitchAttributes } from '@foldkit/ui/switch'\nimport { Effect, Option, Queue, Schema, Stream } from 'effect'\nimport * as Mount from 'foldkit/mount'\nimport { Attr, Behavior, Capability, Event, Slot, Slots } from 'foldkit-mixins'\nimport type { Html } from 'foldkit/html'\nimport { resolveFor, type MixinList, type ResolveContext, type Resolved } from './resolve.js'\n\n/** Mirrors the checkbox contract: both the control and its label own `click`. */\nexport const SwitchSlots = Slots.define({\n button: Slot.make({\n capability: Capability.Interactive,\n events: [Event.Click],\n attributes: [Attr.Role, Attr.AriaDisabled, Attr.Disabled, Attr.Value],\n }),\n label: Slot.make({\n capability: Capability.Container,\n events: [Event.Click],\n }),\n description: Slot.make({ capability: Capability.Container }),\n hiddenInput: Slot.make({\n capability: Capability.Base,\n attributes: [Attr.Value],\n }),\n})\n\n/** The switch's bundles with the attached Mixins applied. */\nexport type ResolvedSwitch<Message> = Resolved<\n SwitchAttributes<Message>,\n typeof SwitchSlots,\n Message\n>\n\n/** Applies `mixins` to the switch's bundles. */\nexport const resolve = <Input, Message>(\n attributes: SwitchAttributes<Message>,\n mixins: MixinList<Message>,\n context: ResolveContext<Input, Message>,\n): ResolvedSwitch<Message> => resolveFor(SwitchSlots, mixins, context)(attributes)\n\n/** The switch's `toView`: `draw` receives its bundles with `mixins` applied. */\nexport const toView =\n <Message>(\n mixins: MixinList<Message>,\n context: ResolveContext<unknown, Message>,\n draw: (resolved: ResolvedSwitch<Message>) => Html,\n ) =>\n (attributes: SwitchAttributes<Message>): Html =>\n draw(resolve(attributes, mixins, context))\n\n/** How far, in pixels, a press must move before it is a drag and no longer a click. */\nconst DRAG_SLOP = 4\n\n/** How long, in milliseconds, after a drag's release its click is still swallowed. */\nconst CLICK_AFTER_DRAG = 100\n\nconst Dragged = Schema.TaggedStruct('SwitchDragged', { isChecked: Schema.Boolean })\n\ntype Capturing = Element & { setPointerCapture?: (id: number) => void }\n\n/** The thumb's `translate` along the track from where it rests unchecked, in either direction. */\nconst placeOf = (element: Element, sign: 1 | -1): number => {\n const [x] = getComputedStyle(element, '::before').translate.split(' ')\n const px = Number.parseFloat(x ?? '')\n return Number.isNaN(px) ? 0 : sign * px\n}\n\n/**\n * Follows a press on the switch past `DRAG_SLOP`: the thumb tracks the\n * pointer, and on release it is on when its middle lies past the track's, so\n * a drag that ends on the side it began on reports nothing. The state and the\n * direction are read from the element as the press lands, since a Mount's\n * arguments are read once. The click the browser sends after such a drag is\n * swallowed, or it would toggle again.\n */\nconst Drag = Mount.defineStream('SwitchDrag', {\n messages: [Dragged],\n execute: ({ element }) =>\n Stream.callback<typeof Dragged.Type>(queue =>\n Effect.acquireRelease(\n Effect.sync(() => {\n const target = element as Capturing\n const styled = element as HTMLElement\n // The press being followed, with what ends it; only a press has listeners beyond `pointerdown`.\n let press = Option.none<{ readonly pointerId: number; readonly stop: () => void }>()\n let settle = Option.none<MutationObserver>()\n let releasedAt = Number.NEGATIVE_INFINITY\n const rest = () => {\n if (Option.isSome(settle)) settle.value.disconnect()\n settle = Option.none()\n element.removeAttribute('data-dragging')\n styled.style.removeProperty('--_fk-switch-drag')\n styled.style.removeProperty('touch-action')\n }\n const down = (event: Event) => {\n const pointer = event as PointerEvent\n const off =\n element.getAttribute('aria-disabled') === 'true' ||\n element.getAttribute('aria-readonly') === 'true' ||\n element.hasAttribute('disabled')\n if (off || pointer.button !== 0 || Option.isSome(press)) return\n rest()\n const sign = element.matches(':dir(rtl)') ? -1 : 1\n const thumb = Number.parseFloat(getComputedStyle(element, '::before').inlineSize)\n const from = placeOf(element, sign)\n // The thumb rests 2px in from each end of the track.\n const room = element.getBoundingClientRect().width - 4 - thumb\n let dragging = false\n let place = from\n const move = (moved: Event) => {\n const at = moved as PointerEvent\n if (at.pointerId !== pointer.pointerId) return\n const along = sign * (at.clientX - pointer.clientX)\n if (!dragging) {\n if (Math.abs(along) < DRAG_SLOP) return\n dragging = true\n try {\n target.setPointerCapture?.(pointer.pointerId)\n } catch {\n // Without capture the move still reports while over the element.\n }\n element.setAttribute('data-dragging', '')\n styled.style.setProperty('touch-action', 'pan-y')\n }\n place = Math.min(Math.max(from + along, 0), room)\n styled.style.setProperty('--_fk-switch-drag', `${sign * place}px`)\n }\n const end = (ended: Event) => {\n if ((ended as PointerEvent).pointerId !== pointer.pointerId) return\n stop()\n press = Option.none()\n if (!dragging) return\n releasedAt = ended.timeStamp\n const isChecked = place > room / 2\n const unchanged = isChecked === (element.getAttribute('aria-checked') === 'true')\n const cancelled = ended.type !== 'pointerup'\n if (cancelled || unchanged) {\n rest()\n return\n }\n // Held where it was let go until the Model's answer redraws the\n // switch, so the thumb does not slide back and forth.\n const observer = new MutationObserver(rest)\n observer.observe(element, { attributes: true, attributeFilter: ['aria-checked'] })\n settle = Option.some(observer)\n Queue.offerUnsafe(queue, Dragged.make({ isChecked }))\n }\n const during = [\n ['pointermove', move],\n ['pointerup', end],\n ['pointercancel', end],\n ['lostpointercapture', end],\n ] as const\n const stop = () => {\n for (const [type, listener] of during) element.removeEventListener(type, listener)\n }\n for (const [type, listener] of during) element.addEventListener(type, listener)\n press = Option.some({ pointerId: pointer.pointerId, stop })\n }\n const click = (event: Event) => {\n // The browser sends it right after the release, after the pointer\n // events: a timer set at the release ran before it.\n if (event.timeStamp - releasedAt > CLICK_AFTER_DRAG) return\n releasedAt = Number.NEGATIVE_INFINITY\n event.preventDefault()\n event.stopImmediatePropagation()\n }\n element.addEventListener('pointerdown', down)\n element.addEventListener('click', click, { capture: true })\n return () => {\n element.removeEventListener('pointerdown', down)\n element.removeEventListener('click', click, { capture: true })\n if (Option.isSome(press)) press.value.stop()\n rest()\n }\n }),\n stop => Effect.sync(stop),\n ),\n ),\n})\n\n/**\n * Lets the thumb be dragged: past the middle of the track on release, the\n * switch turns to the side it is on, sent as `onToggle`'s Message. The click\n * the browser sends after the drag is swallowed, so a drag sends that one\n * Message and never two. Not built in, as a Scene test must resolve every Mount with a\n * Message; pass it beside the style (`mixins: [style.mixin, Switch.draggable(onToggle)]`),\n * with the `onToggle` the view was given. A disabled or read-only switch\n * does not drag.\n */\nexport const draggable = <Message>(onToggle: (isChecked: boolean) => Message) =>\n Behavior.forSlots(SwitchSlots)<unknown, Message>(\n {\n button: Behavior.slot({\n requires: { capability: Capability.Interactive },\n mount: () => Mount.mapMessage(Drag(), fact => onToggle(fact.isChecked)),\n }),\n },\n { name: 'SwitchDrag' },\n ).mixin\n"],"mappings":";;;;;;AAQA,MAAa,cAAc,MAAM,OAAO;CACtC,QAAQ,KAAK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AW,KAAK,IAAG,SAAQ,SAAS,KAAK,SAAS,CAAC;AACxE,CAAC,EACH,GACA,EAAE,MAAM,aAAa,CACvB,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"switch.js","names":[],"sources":["../src/switch.ts"],"sourcesContent":["import type { SwitchAttributes } from '@foldkit/ui/switch'\nimport { Effect, Option, Queue, Schema, Stream } from 'effect'\nimport * as Mount from 'foldkit/mount'\nimport { Attr, Behavior, Capability, Event, Slot, Slots } from 'foldkit-mixins'\nimport type { Html } from 'foldkit/html'\nimport { resolveFor, type MixinList, type ResolveContext, type Resolved } from './resolve.js'\n\n/** Mirrors the checkbox contract: both the control and its label own `click`. */\nexport const SwitchSlots = Slots.define({\n button: Slot.make({\n capability: Capability.Interactive,\n events: [Event.Click],\n attributes: [Attr.Role, Attr.AriaDisabled, Attr.Disabled, Attr.Value],\n }),\n label: Slot.make({\n capability: Capability.Container,\n events: [Event.Click],\n }),\n description: Slot.make({ capability: Capability.Container }),\n hiddenInput: Slot.make({\n capability: Capability.Base,\n attributes: [Attr.Value],\n }),\n})\n\n/** The switch's bundles with the attached Mixins applied. */\nexport type ResolvedSwitch<Message> = Resolved<\n SwitchAttributes<Message>,\n typeof SwitchSlots,\n Message\n>\n\n/** Applies `mixins` to the switch's bundles. */\nexport const resolve = <Input, Message>(\n attributes: SwitchAttributes<Message>,\n mixins: MixinList<Message>,\n context: ResolveContext<Input, Message>,\n): ResolvedSwitch<Message> => resolveFor(SwitchSlots, mixins, context)(attributes)\n\n/** The switch's `toView`: `draw` receives its bundles with `mixins` applied. */\nexport const toView =\n <Message>(\n mixins: MixinList<Message>,\n context: ResolveContext<unknown, Message>,\n draw: (resolved: ResolvedSwitch<Message>) => Html,\n ) =>\n (attributes: SwitchAttributes<Message>): Html =>\n draw(resolve(attributes, mixins, context))\n\n/** How far, in pixels, a press must move before it is a drag and no longer a click. */\nconst DRAG_SLOP = 4\n\n/** How long, in milliseconds, after a drag's release its click is still swallowed. */\nconst CLICK_AFTER_DRAG = 100\n\n/**\n * How long, in milliseconds, the thumb is held where it was let go for the\n * Model's answer. An `update` that refuses the toggle never changes\n * `aria-checked`, so nothing else would end the hold.\n */\nconst HOLD_FOR_ANSWER = 300\n\nconst Dragged = Schema.TaggedStruct('SwitchDragged', { isChecked: Schema.Boolean })\n\ntype Capturing = Element & { setPointerCapture?: (id: number) => void }\n\n/** The thumb's `translate` along the track from where it rests unchecked, in either direction. */\nconst placeOf = (element: Element, sign: 1 | -1): number => {\n const [x] = getComputedStyle(element, '::before').translate.split(' ')\n const px = Number.parseFloat(x ?? '')\n return Number.isNaN(px) ? 0 : sign * px\n}\n\n/**\n * Follows a press on the switch past `DRAG_SLOP`: the thumb tracks the\n * pointer, and on release it is on when its middle lies past the track's, so\n * a drag that ends on the side it began on reports nothing. The state and the\n * direction are read from the element as the press lands, since a Mount's\n * arguments are read once. The click the browser sends after such a drag is\n * swallowed, or it would toggle again.\n */\nconst Drag = Mount.defineStream('SwitchDrag', {\n messages: [Dragged],\n execute: ({ element }) =>\n Stream.callback<typeof Dragged.Type>(queue =>\n Effect.acquireRelease(\n Effect.sync(() => {\n const target = element as Capturing\n const styled = element as HTMLElement\n // The press being followed, with what ends it; only a press has listeners beyond `pointerdown`.\n let press = Option.none<{ readonly pointerId: number; readonly stop: () => void }>()\n let settle = Option.none<{\n readonly observer: MutationObserver\n readonly timer: number\n }>()\n let releasedAt = Number.NEGATIVE_INFINITY\n const rest = () => {\n if (Option.isSome(settle)) {\n settle.value.observer.disconnect()\n clearTimeout(settle.value.timer)\n }\n settle = Option.none()\n element.removeAttribute('data-dragging')\n styled.style.removeProperty('--_fk-switch-drag')\n styled.style.removeProperty('touch-action')\n }\n const down = (event: Event) => {\n const pointer = event as PointerEvent\n const off =\n element.getAttribute('aria-disabled') === 'true' ||\n element.getAttribute('aria-readonly') === 'true' ||\n element.hasAttribute('disabled')\n if (off || pointer.button !== 0 || Option.isSome(press)) return\n rest()\n const sign = element.matches(':dir(rtl)') ? -1 : 1\n const thumb = Number.parseFloat(getComputedStyle(element, '::before').inlineSize)\n const from = placeOf(element, sign)\n // The thumb rests 2px in from each end of the track.\n const room = element.getBoundingClientRect().width - 4 - thumb\n let dragging = false\n let place = from\n const move = (moved: Event) => {\n const at = moved as PointerEvent\n if (at.pointerId !== pointer.pointerId) return\n const along = sign * (at.clientX - pointer.clientX)\n if (!dragging) {\n if (Math.abs(along) < DRAG_SLOP) return\n dragging = true\n try {\n target.setPointerCapture?.(pointer.pointerId)\n } catch {\n // Without capture the move still reports while over the element.\n }\n element.setAttribute('data-dragging', '')\n styled.style.setProperty('touch-action', 'pan-y')\n }\n place = Math.min(Math.max(from + along, 0), room)\n styled.style.setProperty('--_fk-switch-drag', `${sign * place}px`)\n }\n const end = (ended: Event) => {\n if ((ended as PointerEvent).pointerId !== pointer.pointerId) return\n stop()\n press = Option.none()\n if (!dragging) return\n releasedAt = ended.timeStamp\n const isChecked = place > room / 2\n const unchanged = isChecked === (element.getAttribute('aria-checked') === 'true')\n const cancelled = ended.type !== 'pointerup'\n if (cancelled || unchanged) {\n rest()\n return\n }\n // Held where it was let go until the Model's answer redraws the\n // switch, so the thumb does not slide back and forth; the timer\n // lets go of it when the answer leaves the switch as it was.\n const observer = new MutationObserver(rest)\n observer.observe(element, { attributes: true, attributeFilter: ['aria-checked'] })\n settle = Option.some({ observer, timer: window.setTimeout(rest, HOLD_FOR_ANSWER) })\n Queue.offerUnsafe(queue, Dragged.make({ isChecked }))\n }\n const during = [\n ['pointermove', move],\n ['pointerup', end],\n ['pointercancel', end],\n ['lostpointercapture', end],\n ] as const\n const stop = () => {\n for (const [type, listener] of during) element.removeEventListener(type, listener)\n }\n for (const [type, listener] of during) element.addEventListener(type, listener)\n press = Option.some({ pointerId: pointer.pointerId, stop })\n }\n const click = (event: Event) => {\n // The browser sends it right after the release, after the pointer\n // events: a timer set at the release ran before it.\n if (event.timeStamp - releasedAt > CLICK_AFTER_DRAG) return\n releasedAt = Number.NEGATIVE_INFINITY\n event.preventDefault()\n event.stopImmediatePropagation()\n }\n element.addEventListener('pointerdown', down)\n element.addEventListener('click', click, { capture: true })\n return () => {\n element.removeEventListener('pointerdown', down)\n element.removeEventListener('click', click, { capture: true })\n if (Option.isSome(press)) press.value.stop()\n rest()\n }\n }),\n stop => Effect.sync(stop),\n ),\n ),\n})\n\n/**\n * Lets the thumb be dragged: past the middle of the track on release, the\n * switch turns to the side it is on, sent as `onToggle`'s Message. The click\n * the browser sends after the drag is swallowed, so a drag sends that one\n * Message and never two. Not built in, as a Scene test must resolve every Mount with a\n * Message; pass it beside the style (`mixins: [style.mixin, Switch.draggable(onToggle)]`),\n * with the `onToggle` the view was given. A disabled or read-only switch\n * does not drag.\n */\nexport const draggable = <Message>(onToggle: (isChecked: boolean) => Message) =>\n Behavior.forSlots(SwitchSlots)<unknown, Message>(\n {\n button: Behavior.slot({\n requires: { capability: Capability.Interactive },\n mount: () => Mount.mapMessage(Drag(), fact => onToggle(fact.isChecked)),\n }),\n },\n { name: 'SwitchDrag' },\n ).mixin\n"],"mappings":";;;;;;AAQA,MAAa,cAAc,MAAM,OAAO;CACtC,QAAQ,KAAK,KAAK;EAChB,YAAY,WAAW;EACvB,QAAQ,CAAC,MAAM,KAAK;EACpB,YAAY;GAAC,KAAK;GAAM,KAAK;GAAc,KAAK;GAAU,KAAK;EAAK;CACtE,CAAC;CACD,OAAO,KAAK,KAAK;EACf,YAAY,WAAW;EACvB,QAAQ,CAAC,MAAM,KAAK;CACtB,CAAC;CACD,aAAa,KAAK,KAAK,EAAE,YAAY,WAAW,UAAU,CAAC;CAC3D,aAAa,KAAK,KAAK;EACrB,YAAY,WAAW;EACvB,YAAY,CAAC,KAAK,KAAK;CACzB,CAAC;AACH,CAAC;;AAUD,MAAa,WACX,YACA,QACA,YAC4B,WAAW,aAAa,QAAQ,OAAO,CAAC,CAAC,UAAU;;AAGjF,MAAa,UAET,QACA,SACA,UAED,eACC,KAAK,QAAQ,YAAY,QAAQ,OAAO,CAAC;;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,KAAK,MAAM,CAAC,MAAM,aAAa,QAAQ,QAAQ,oBAAoB,MAAM,QAAQ;GACnF;GACA,KAAK,MAAM,CAAC,MAAM,aAAa,QAAQ,QAAQ,iBAAiB,MAAM,QAAQ;GAC9E,QAAQ,OAAO,KAAK;IAAE,WAAW,QAAQ;IAAW;GAAK,CAAC;EAC5D;EACA,MAAM,SAAS,UAAiB;GAG9B,IAAI,MAAM,YAAY,aAAa,kBAAkB;GACrD,aAAa,OAAO;GACpB,MAAM,eAAe;GACrB,MAAM,yBAAyB;EACjC;EACA,QAAQ,iBAAiB,eAAe,IAAI;EAC5C,QAAQ,iBAAiB,SAAS,OAAO,EAAE,SAAS,KAAK,CAAC;EAC1D,aAAa;GACX,QAAQ,oBAAoB,eAAe,IAAI;GAC/C,QAAQ,oBAAoB,SAAS,OAAO,EAAE,SAAS,KAAK,CAAC;GAC7D,IAAI,OAAO,OAAO,KAAK,GAAG,MAAM,MAAM,KAAK;GAC3C,KAAK;EACP;CACF,CAAC,IACD,SAAQ,OAAO,KAAK,IAAI,CAC1B,CACF;AACJ,CAAC;;;;;;;;;;AAWD,MAAa,aAAsB,aACjC,SAAS,SAAS,WAAW,CAAC,CAC5B,EACE,QAAQ,SAAS,KAAK;CACpB,UAAU,EAAE,YAAY,WAAW,YAAY;CAC/C,aAAa,MAAM,WAAW,KAAK,IAAG,SAAQ,SAAS,KAAK,SAAS,CAAC;AACxE,CAAC,EACH,GACA,EAAE,MAAM,aAAa,CACvB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "foldkit-mixins-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"description": "Published slot contracts and mixin adapters for @foldkit/ui, built on foldkit-mixins.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"foldkit",
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
"@foldkit/ui": "^0.170.0",
|
|
46
46
|
"effect": "^4.1.0",
|
|
47
47
|
"foldkit": "^0.170.0",
|
|
48
|
-
"foldkit-
|
|
49
|
-
"foldkit-
|
|
50
|
-
"foldkit-primitives": "^0.
|
|
48
|
+
"foldkit-media": "^0.8.0",
|
|
49
|
+
"foldkit-mixins": "^0.25.0",
|
|
50
|
+
"foldkit-primitives": "^0.20.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@effect/platform-browser": "^4.1.1",
|
|
@@ -57,9 +57,9 @@
|
|
|
57
57
|
"jsqr": "^1.4.0",
|
|
58
58
|
"tsdown": "^0.23.1",
|
|
59
59
|
"typescript": "7.0.2",
|
|
60
|
-
"foldkit-
|
|
61
|
-
"foldkit-
|
|
62
|
-
"foldkit-
|
|
60
|
+
"foldkit-mixins": "0.25.0",
|
|
61
|
+
"foldkit-media": "0.8.0",
|
|
62
|
+
"foldkit-primitives": "0.20.0"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
65
|
"build": "node ../../scripts/declarations.mjs . && tsdown && node ../../scripts/declared-any.mjs .",
|