@sdxc/ui 0.0.0-pre.1
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.md +21 -0
- package/README.md +812 -0
- package/dist/animations/index.d.ts +12 -0
- package/dist/animations/index.js +12 -0
- package/dist/animations/keyframes.d.ts +162 -0
- package/dist/animations/keyframes.js +297 -0
- package/dist/animations/scroll.d.ts +154 -0
- package/dist/animations/scroll.js +228 -0
- package/dist/animations/tokens.d.ts +47 -0
- package/dist/animations/tokens.js +47 -0
- package/dist/animations/transitions.d.ts +143 -0
- package/dist/animations/transitions.js +147 -0
- package/dist/behaviors/announcer.d.ts +90 -0
- package/dist/behaviors/announcer.js +93 -0
- package/dist/behaviors/calendar-model.d.ts +218 -0
- package/dist/behaviors/calendar-model.js +376 -0
- package/dist/behaviors/drag-session.d.ts +119 -0
- package/dist/behaviors/drag-session.js +110 -0
- package/dist/behaviors/filter-model.d.ts +117 -0
- package/dist/behaviors/filter-model.js +185 -0
- package/dist/behaviors/index.d.ts +16 -0
- package/dist/behaviors/index.js +16 -0
- package/dist/behaviors/resize-session.d.ts +115 -0
- package/dist/behaviors/resize-session.js +157 -0
- package/dist/behaviors/scroll-follow-model.d.ts +180 -0
- package/dist/behaviors/scroll-follow-model.js +197 -0
- package/dist/behaviors/selection-model.d.ts +129 -0
- package/dist/behaviors/selection-model.js +259 -0
- package/dist/behaviors/toaster.d.ts +144 -0
- package/dist/behaviors/toaster.js +228 -0
- package/dist/components/accordion.d.ts +93 -0
- package/dist/components/accordion.js +165 -0
- package/dist/components/alert-dialog.d.ts +110 -0
- package/dist/components/alert-dialog.js +169 -0
- package/dist/components/alert.d.ts +109 -0
- package/dist/components/alert.js +160 -0
- package/dist/components/aspect-ratio.d.ts +44 -0
- package/dist/components/aspect-ratio.js +35 -0
- package/dist/components/attachment.d.ts +146 -0
- package/dist/components/attachment.js +320 -0
- package/dist/components/avatar.d.ts +118 -0
- package/dist/components/avatar.js +89 -0
- package/dist/components/badge.d.ts +66 -0
- package/dist/components/badge.js +129 -0
- package/dist/components/breadcrumbs.d.ts +67 -0
- package/dist/components/breadcrumbs.js +121 -0
- package/dist/components/bubble.d.ts +91 -0
- package/dist/components/bubble.js +216 -0
- package/dist/components/button.d.ts +78 -0
- package/dist/components/button.js +207 -0
- package/dist/components/calendar.d.ts +166 -0
- package/dist/components/calendar.js +320 -0
- package/dist/components/card.d.ts +82 -0
- package/dist/components/card.js +126 -0
- package/dist/components/carousel.d.ts +96 -0
- package/dist/components/carousel.js +214 -0
- package/dist/components/chart.d.ts +485 -0
- package/dist/components/chart.js +563 -0
- package/dist/components/checkbox-group.d.ts +58 -0
- package/dist/components/checkbox-group.js +53 -0
- package/dist/components/checkbox.d.ts +61 -0
- package/dist/components/checkbox.js +81 -0
- package/dist/components/color-area.d.ts +83 -0
- package/dist/components/color-area.js +251 -0
- package/dist/components/color-field.d.ts +128 -0
- package/dist/components/color-field.js +73 -0
- package/dist/components/color-picker.d.ts +132 -0
- package/dist/components/color-picker.js +183 -0
- package/dist/components/color-slider.d.ts +103 -0
- package/dist/components/color-slider.js +198 -0
- package/dist/components/color-swatch-picker.d.ts +106 -0
- package/dist/components/color-swatch-picker.js +75 -0
- package/dist/components/color-swatch.d.ts +57 -0
- package/dist/components/color-swatch.js +82 -0
- package/dist/components/color-wheel.d.ts +58 -0
- package/dist/components/color-wheel.js +160 -0
- package/dist/components/combobox.d.ts +73 -0
- package/dist/components/combobox.js +108 -0
- package/dist/components/command.d.ts +80 -0
- package/dist/components/command.js +151 -0
- package/dist/components/confirm.d.ts +124 -0
- package/dist/components/confirm.js +56 -0
- package/dist/components/context-menu.d.ts +108 -0
- package/dist/components/context-menu.js +200 -0
- package/dist/components/date-field.d.ts +110 -0
- package/dist/components/date-field.js +49 -0
- package/dist/components/date-picker.d.ts +136 -0
- package/dist/components/date-picker.js +155 -0
- package/dist/components/date-range-picker.d.ts +152 -0
- package/dist/components/date-range-picker.js +106 -0
- package/dist/components/description.d.ts +36 -0
- package/dist/components/description.js +21 -0
- package/dist/components/dialog.d.ts +97 -0
- package/dist/components/dialog.js +203 -0
- package/dist/components/disclosure.d.ts +85 -0
- package/dist/components/disclosure.js +180 -0
- package/dist/components/drawer.d.ts +82 -0
- package/dist/components/drawer.js +162 -0
- package/dist/components/drop-indicator.d.ts +43 -0
- package/dist/components/drop-indicator.js +47 -0
- package/dist/components/drop-zone.d.ts +73 -0
- package/dist/components/drop-zone.js +54 -0
- package/dist/components/empty.d.ts +89 -0
- package/dist/components/empty.js +129 -0
- package/dist/components/field-error.d.ts +41 -0
- package/dist/components/field-error.js +36 -0
- package/dist/components/file-trigger.d.ts +84 -0
- package/dist/components/file-trigger.js +169 -0
- package/dist/components/form.d.ts +118 -0
- package/dist/components/form.js +113 -0
- package/dist/components/grid-list.d.ts +112 -0
- package/dist/components/grid-list.js +220 -0
- package/dist/components/group.d.ts +45 -0
- package/dist/components/group.js +44 -0
- package/dist/components/header.d.ts +33 -0
- package/dist/components/header.js +29 -0
- package/dist/components/heading-scope.d.ts +83 -0
- package/dist/components/heading-scope.js +82 -0
- package/dist/components/heading.d.ts +50 -0
- package/dist/components/heading.js +31 -0
- package/dist/components/hover-card.d.ts +77 -0
- package/dist/components/hover-card.js +151 -0
- package/dist/components/image-placeholder.d.ts +105 -0
- package/dist/components/image-placeholder.js +212 -0
- package/dist/components/index.d.ts +109 -0
- package/dist/components/index.js +109 -0
- package/dist/components/input.d.ts +53 -0
- package/dist/components/input.js +76 -0
- package/dist/components/item.d.ts +97 -0
- package/dist/components/item.js +185 -0
- package/dist/components/keyboard.d.ts +33 -0
- package/dist/components/keyboard.js +20 -0
- package/dist/components/label.d.ts +38 -0
- package/dist/components/label.js +24 -0
- package/dist/components/link-button.d.ts +59 -0
- package/dist/components/link-button.js +174 -0
- package/dist/components/link.d.ts +43 -0
- package/dist/components/link.js +85 -0
- package/dist/components/listbox.d.ts +119 -0
- package/dist/components/listbox.js +114 -0
- package/dist/components/logo.d.ts +117 -0
- package/dist/components/logo.js +89 -0
- package/dist/components/marker.d.ts +82 -0
- package/dist/components/marker.js +163 -0
- package/dist/components/menu.d.ts +90 -0
- package/dist/components/menu.js +146 -0
- package/dist/components/menubar.d.ts +54 -0
- package/dist/components/menubar.js +118 -0
- package/dist/components/message-scroller.d.ts +109 -0
- package/dist/components/message-scroller.js +180 -0
- package/dist/components/message.d.ts +104 -0
- package/dist/components/message.js +200 -0
- package/dist/components/meter.d.ts +60 -0
- package/dist/components/meter.js +110 -0
- package/dist/components/modal.d.ts +71 -0
- package/dist/components/modal.js +120 -0
- package/dist/components/nav-link.d.ts +53 -0
- package/dist/components/nav-link.js +83 -0
- package/dist/components/navigation-menu.d.ts +150 -0
- package/dist/components/navigation-menu.js +381 -0
- package/dist/components/number-field.d.ts +76 -0
- package/dist/components/number-field.js +190 -0
- package/dist/components/otp-field.d.ts +68 -0
- package/dist/components/otp-field.js +46 -0
- package/dist/components/overlay-arrow.d.ts +51 -0
- package/dist/components/overlay-arrow.js +77 -0
- package/dist/components/pagination.d.ts +67 -0
- package/dist/components/pagination.js +164 -0
- package/dist/components/popover.d.ts +69 -0
- package/dist/components/popover.js +68 -0
- package/dist/components/progress-bar.d.ts +53 -0
- package/dist/components/progress-bar.js +90 -0
- package/dist/components/radio-group.d.ts +102 -0
- package/dist/components/radio-group.js +114 -0
- package/dist/components/range-calendar.d.ts +169 -0
- package/dist/components/range-calendar.js +216 -0
- package/dist/components/resizable.d.ts +98 -0
- package/dist/components/resizable.js +151 -0
- package/dist/components/scroll-area.d.ts +54 -0
- package/dist/components/scroll-area.js +89 -0
- package/dist/components/search-field.d.ts +55 -0
- package/dist/components/search-field.js +49 -0
- package/dist/components/section.d.ts +37 -0
- package/dist/components/section.js +22 -0
- package/dist/components/select.d.ts +96 -0
- package/dist/components/select.js +285 -0
- package/dist/components/selection-indicator.d.ts +47 -0
- package/dist/components/selection-indicator.js +50 -0
- package/dist/components/sentinel-row.d.ts +22 -0
- package/dist/components/sentinel-row.js +29 -0
- package/dist/components/separator.d.ts +35 -0
- package/dist/components/separator.js +48 -0
- package/dist/components/shared-element.d.ts +45 -0
- package/dist/components/shared-element.js +48 -0
- package/dist/components/sheet.d.ts +78 -0
- package/dist/components/sheet.js +167 -0
- package/dist/components/sidebar.d.ts +288 -0
- package/dist/components/sidebar.js +1068 -0
- package/dist/components/skeleton.d.ts +36 -0
- package/dist/components/skeleton.js +38 -0
- package/dist/components/slider.d.ts +102 -0
- package/dist/components/slider.js +179 -0
- package/dist/components/spinner.d.ts +55 -0
- package/dist/components/spinner.js +51 -0
- package/dist/components/switch.d.ts +47 -0
- package/dist/components/switch.js +82 -0
- package/dist/components/table.d.ts +139 -0
- package/dist/components/table.js +216 -0
- package/dist/components/tabs.d.ts +124 -0
- package/dist/components/tabs.js +246 -0
- package/dist/components/tag-group.d.ts +83 -0
- package/dist/components/tag-group.js +157 -0
- package/dist/components/text-field.d.ts +119 -0
- package/dist/components/text-field.js +51 -0
- package/dist/components/text.d.ts +34 -0
- package/dist/components/text.js +19 -0
- package/dist/components/textarea.d.ts +52 -0
- package/dist/components/textarea.js +82 -0
- package/dist/components/time-field.d.ts +110 -0
- package/dist/components/time-field.js +48 -0
- package/dist/components/toast.d.ts +149 -0
- package/dist/components/toast.js +365 -0
- package/dist/components/toggle-button.d.ts +115 -0
- package/dist/components/toggle-button.js +237 -0
- package/dist/components/toolbar.d.ts +47 -0
- package/dist/components/toolbar.js +54 -0
- package/dist/components/tooltip.d.ts +52 -0
- package/dist/components/tooltip.js +92 -0
- package/dist/components/tree.d.ts +123 -0
- package/dist/components/tree.js +239 -0
- package/dist/components/typeset.d.ts +53 -0
- package/dist/components/typeset.js +271 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/mixins/aria-checked.d.ts +42 -0
- package/dist/mixins/aria-checked.js +127 -0
- package/dist/mixins/attachment-trigger.d.ts +64 -0
- package/dist/mixins/attachment-trigger.js +190 -0
- package/dist/mixins/calendar-keys.d.ts +27 -0
- package/dist/mixins/calendar-keys.js +113 -0
- package/dist/mixins/carousel-controls.d.ts +30 -0
- package/dist/mixins/carousel-controls.js +222 -0
- package/dist/mixins/chart-tooltip.d.ts +118 -0
- package/dist/mixins/chart-tooltip.js +323 -0
- package/dist/mixins/clear-field.d.ts +60 -0
- package/dist/mixins/clear-field.js +100 -0
- package/dist/mixins/color-area-drag.d.ts +58 -0
- package/dist/mixins/color-area-drag.js +162 -0
- package/dist/mixins/color-channel-sync.d.ts +73 -0
- package/dist/mixins/color-channel-sync.js +169 -0
- package/dist/mixins/color-preview.d.ts +28 -0
- package/dist/mixins/color-preview.js +77 -0
- package/dist/mixins/color-wheel-drag.d.ts +58 -0
- package/dist/mixins/color-wheel-drag.js +139 -0
- package/dist/mixins/combobox-filter.d.ts +59 -0
- package/dist/mixins/combobox-filter.js +81 -0
- package/dist/mixins/command-filter.d.ts +55 -0
- package/dist/mixins/command-filter.js +121 -0
- package/dist/mixins/command-keys.d.ts +31 -0
- package/dist/mixins/command-keys.js +116 -0
- package/dist/mixins/context-menu.d.ts +24 -0
- package/dist/mixins/context-menu.js +64 -0
- package/dist/mixins/copy-to-clipboard.d.ts +64 -0
- package/dist/mixins/copy-to-clipboard.js +109 -0
- package/dist/mixins/dismiss.d.ts +77 -0
- package/dist/mixins/dismiss.js +151 -0
- package/dist/mixins/drag-reorder.d.ts +88 -0
- package/dist/mixins/drag-reorder.js +214 -0
- package/dist/mixins/drop-zone.d.ts +52 -0
- package/dist/mixins/drop-zone.js +132 -0
- package/dist/mixins/dual-range.d.ts +60 -0
- package/dist/mixins/dual-range.js +100 -0
- package/dist/mixins/grid-list-keys.d.ts +34 -0
- package/dist/mixins/grid-list-keys.js +260 -0
- package/dist/mixins/heading-level-fallback.d.ts +81 -0
- package/dist/mixins/heading-level-fallback.js +112 -0
- package/dist/mixins/hotkey.d.ts +26 -0
- package/dist/mixins/hotkey.js +132 -0
- package/dist/mixins/image-fallback.d.ts +57 -0
- package/dist/mixins/image-fallback.js +86 -0
- package/dist/mixins/index.d.ts +48 -0
- package/dist/mixins/index.js +48 -0
- package/dist/mixins/listbox-keys.d.ts +52 -0
- package/dist/mixins/listbox-keys.js +63 -0
- package/dist/mixins/long-press.d.ts +76 -0
- package/dist/mixins/long-press.js +130 -0
- package/dist/mixins/menu-keys.d.ts +40 -0
- package/dist/mixins/menu-keys.js +117 -0
- package/dist/mixins/menubar-keys.d.ts +59 -0
- package/dist/mixins/menubar-keys.js +230 -0
- package/dist/mixins/message-follow.d.ts +56 -0
- package/dist/mixins/message-follow.js +368 -0
- package/dist/mixins/otp-slots.d.ts +53 -0
- package/dist/mixins/otp-slots.js +175 -0
- package/dist/mixins/persist.d.ts +36 -0
- package/dist/mixins/persist.js +78 -0
- package/dist/mixins/press-toggle.d.ts +43 -0
- package/dist/mixins/press-toggle.js +61 -0
- package/dist/mixins/range-preview.d.ts +26 -0
- package/dist/mixins/range-preview.js +120 -0
- package/dist/mixins/resize-handle.d.ts +101 -0
- package/dist/mixins/resize-handle.js +288 -0
- package/dist/mixins/stepper.d.ts +81 -0
- package/dist/mixins/stepper.js +194 -0
- package/dist/mixins/tab-keys.d.ts +30 -0
- package/dist/mixins/tab-keys.js +63 -0
- package/dist/mixins/theme-toggle.d.ts +82 -0
- package/dist/mixins/theme-toggle.js +158 -0
- package/dist/mixins/track-host-node.d.ts +34 -0
- package/dist/mixins/track-host-node.js +42 -0
- package/dist/mixins/treeKeys.d.ts +57 -0
- package/dist/mixins/treeKeys.js +266 -0
- package/dist/mixins/validate.d.ts +65 -0
- package/dist/mixins/validate.js +139 -0
- package/dist/mixins/view-transition.d.ts +56 -0
- package/dist/mixins/view-transition.js +111 -0
- package/dist/styles/chart-palette.d.ts +34 -0
- package/dist/styles/chart-palette.js +27 -0
- package/dist/styles/field-stack-layout.d.ts +27 -0
- package/dist/styles/field-stack-layout.js +16 -0
- package/dist/styles/floating-surface.d.ts +32 -0
- package/dist/styles/floating-surface.js +30 -0
- package/dist/styles/graphic-host.d.ts +25 -0
- package/dist/styles/graphic-host.js +18 -0
- package/dist/styles/index.d.ts +20 -0
- package/dist/styles/index.js +20 -0
- package/dist/styles/interactive-transition.d.ts +32 -0
- package/dist/styles/interactive-transition.js +32 -0
- package/dist/styles/legend-toggle.d.ts +29 -0
- package/dist/styles/legend-toggle.js +24 -0
- package/dist/styles/output-caption-text.d.ts +22 -0
- package/dist/styles/output-caption-text.js +15 -0
- package/dist/styles/panel-chrome.d.ts +34 -0
- package/dist/styles/panel-chrome.js +26 -0
- package/dist/styles/range-thumb-appearance.d.ts +36 -0
- package/dist/styles/range-thumb-appearance.js +76 -0
- package/dist/styles/rtl-aware-gradient-direction.d.ts +28 -0
- package/dist/styles/rtl-aware-gradient-direction.js +28 -0
- package/dist/styles/semantic-color-panel.d.ts +35 -0
- package/dist/styles/semantic-color-panel.js +41 -0
- package/dist/utils/chart-marker-indices.d.ts +22 -0
- package/dist/utils/chart-marker-indices.js +45 -0
- package/dist/utils/chart-path.d.ts +86 -0
- package/dist/utils/chart-path.js +122 -0
- package/dist/utils/chart-scale.d.ts +182 -0
- package/dist/utils/chart-scale.js +221 -0
- package/dist/utils/color-math.d.ts +252 -0
- package/dist/utils/color-math.js +480 -0
- package/dist/utils/command-event.d.ts +24 -0
- package/dist/utils/command-event.js +26 -0
- package/dist/utils/css-styles.d.ts +21 -0
- package/dist/utils/css-styles.js +11 -0
- package/dist/utils/decorative-icon.d.ts +15 -0
- package/dist/utils/decorative-icon.js +15 -0
- package/dist/utils/disabled-selector.d.ts +22 -0
- package/dist/utils/disabled-selector.js +22 -0
- package/dist/utils/dispatch-change.d.ts +17 -0
- package/dist/utils/dispatch-change.js +19 -0
- package/dist/utils/field-parts.d.ts +26 -0
- package/dist/utils/field-parts.js +12 -0
- package/dist/utils/full-turn-radians.d.ts +16 -0
- package/dist/utils/full-turn-radians.js +16 -0
- package/dist/utils/geometry.d.ts +14 -0
- package/dist/utils/geometry.js +9 -0
- package/dist/utils/has-accessible-text.d.ts +19 -0
- package/dist/utils/has-accessible-text.js +30 -0
- package/dist/utils/hue-spectrum.d.ts +19 -0
- package/dist/utils/hue-spectrum.js +19 -0
- package/dist/utils/index.d.ts +35 -0
- package/dist/utils/index.js +35 -0
- package/dist/utils/is-new-primary-press.d.ts +29 -0
- package/dist/utils/is-new-primary-press.js +31 -0
- package/dist/utils/keyboard-nav.d.ts +64 -0
- package/dist/utils/keyboard-nav.js +79 -0
- package/dist/utils/merge-style.d.ts +33 -0
- package/dist/utils/merge-style.js +30 -0
- package/dist/utils/paired-range-inputs.d.ts +26 -0
- package/dist/utils/paired-range-inputs.js +29 -0
- package/dist/utils/placement.d.ts +18 -0
- package/dist/utils/placement.js +12 -0
- package/dist/utils/prefers-reduced-motion.d.ts +17 -0
- package/dist/utils/prefers-reduced-motion.js +19 -0
- package/dist/utils/resolve-field-wiring.d.ts +83 -0
- package/dist/utils/resolve-field-wiring.js +53 -0
- package/dist/utils/resolve-fill-percent.d.ts +28 -0
- package/dist/utils/resolve-fill-percent.js +34 -0
- package/dist/utils/round-precision.d.ts +22 -0
- package/dist/utils/round-precision.js +25 -0
- package/dist/utils/semantic-color-panel.d.ts +35 -0
- package/dist/utils/semantic-color-panel.js +28 -0
- package/dist/utils/semantic-color.d.ts +17 -0
- package/dist/utils/semantic-color.js +11 -0
- package/dist/utils/warn-if-no-accessible-name.d.ts +52 -0
- package/dist/utils/warn-if-no-accessible-name.js +55 -0
- package/dist/utils/write-cookie.d.ts +35 -0
- package/dist/utils/write-cookie.js +37 -0
- package/package.json +32 -0
- package/src/reset.css +223 -0
- package/src/theme.css +146 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flags an Avatar or Logo image the moment it fails to load by setting an
|
|
3
|
+
* attribute its own styling hides behind, revealing the fallback markup
|
|
4
|
+
* stacked beneath it; clears the attribute again once a later `src` loads
|
|
5
|
+
* successfully.
|
|
6
|
+
*
|
|
7
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
8
|
+
* @copyright Sergio Xalambrí 2026
|
|
9
|
+
*/
|
|
10
|
+
import { createElement, createMixin, on } from "remix/ui";
|
|
11
|
+
/**
|
|
12
|
+
* Attribute {@link imageFallback} sets on its host image once it fails to
|
|
13
|
+
* load, and removes once a later `src` loads successfully; the image's own
|
|
14
|
+
* `css()` styling hides itself behind this attribute to reveal its fallback.
|
|
15
|
+
*/
|
|
16
|
+
export const IMAGE_ERROR_ATTRIBUTE = "data-image-error";
|
|
17
|
+
/** DOM event type dispatched on a host image by {@link imageFallback} whenever loading it succeeds or fails. */
|
|
18
|
+
const IMAGE_FALLBACK_EVENT = "ui:image-fallback";
|
|
19
|
+
/**
|
|
20
|
+
* Dispatched on an Avatar or Logo image by {@link imageFallback} whenever
|
|
21
|
+
* loading it succeeds or fails, so a consumer can react without polling
|
|
22
|
+
* {@link IMAGE_ERROR_ATTRIBUTE} off the DOM itself.
|
|
23
|
+
*/
|
|
24
|
+
export class ImageFallbackEvent extends Event {
|
|
25
|
+
/** `true` once the image has failed to load and its fallback is now revealed, `false` once it loads successfully. */
|
|
26
|
+
fallback;
|
|
27
|
+
/**
|
|
28
|
+
* @param fallback Whether the image's fallback is now revealed.
|
|
29
|
+
*/
|
|
30
|
+
constructor(fallback) {
|
|
31
|
+
super(IMAGE_FALLBACK_EVENT, { bubbles: true });
|
|
32
|
+
this.fallback = fallback;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Sets or clears {@link IMAGE_ERROR_ATTRIBUTE} on an Avatar or Logo image
|
|
37
|
+
* on load, error, and mount — mount also checks `complete`/`naturalWidth`
|
|
38
|
+
* since an already-cached image never fires either event again.
|
|
39
|
+
*
|
|
40
|
+
* @returns A mixin descriptor for an Avatar or Logo image's `mix` prop.
|
|
41
|
+
* @example
|
|
42
|
+
* <div mix={[css({ position: "relative", display: "inline-grid" })]}>
|
|
43
|
+
* <span mix={[css({ gridArea: "1 / 1" })]}>{initials}</span>
|
|
44
|
+
* <img
|
|
45
|
+
* src={avatarUrl}
|
|
46
|
+
* alt={name}
|
|
47
|
+
* mix={[
|
|
48
|
+
* imageFallback(),
|
|
49
|
+
* css({ gridArea: "1 / 1", "&[data-image-error]": { display: "none" } }),
|
|
50
|
+
* ]}
|
|
51
|
+
* />
|
|
52
|
+
* </div>
|
|
53
|
+
*/
|
|
54
|
+
export const imageFallback = createMixin((handle) => {
|
|
55
|
+
let isFallback = false;
|
|
56
|
+
/** Sets or clears {@link IMAGE_ERROR_ATTRIBUTE} on `host` and reports the transition, unless it already matches `fallback`. */
|
|
57
|
+
function setFallback(host, fallback) {
|
|
58
|
+
if (fallback === isFallback)
|
|
59
|
+
return;
|
|
60
|
+
isFallback = fallback;
|
|
61
|
+
if (fallback)
|
|
62
|
+
host.setAttribute(IMAGE_ERROR_ATTRIBUTE, "");
|
|
63
|
+
else
|
|
64
|
+
host.removeAttribute(IMAGE_ERROR_ATTRIBUTE);
|
|
65
|
+
host.dispatchEvent(new ImageFallbackEvent(fallback));
|
|
66
|
+
}
|
|
67
|
+
handle.addEventListener("insert", (event) => {
|
|
68
|
+
let host = event.node;
|
|
69
|
+
if (host.src !== "" && host.complete && host.naturalWidth === 0) {
|
|
70
|
+
setFallback(host, true);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
handle.addEventListener("remove", () => {
|
|
74
|
+
isFallback = false;
|
|
75
|
+
});
|
|
76
|
+
return () => createElement(handle.element, {
|
|
77
|
+
mix: [
|
|
78
|
+
on("load", (event) => {
|
|
79
|
+
setFallback(event.currentTarget, false);
|
|
80
|
+
}),
|
|
81
|
+
on("error", (event) => {
|
|
82
|
+
setFallback(event.currentTarget, true);
|
|
83
|
+
}),
|
|
84
|
+
],
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Barrel for opt-in behavior mixins: `createMixin`-based building blocks,
|
|
3
|
+
* one module per behavior, that attach a `behaviors/` state model to a host
|
|
4
|
+
* element through the standard `mix` prop alongside `css()` and friends.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
export * from "./aria-checked.js";
|
|
10
|
+
export * from "./attachment-trigger.js";
|
|
11
|
+
export * from "./calendar-keys.js";
|
|
12
|
+
export * from "./carousel-controls.js";
|
|
13
|
+
export * from "./chart-tooltip.js";
|
|
14
|
+
export * from "./clear-field.js";
|
|
15
|
+
export * from "./color-area-drag.js";
|
|
16
|
+
export * from "./color-channel-sync.js";
|
|
17
|
+
export * from "./color-preview.js";
|
|
18
|
+
export * from "./color-wheel-drag.js";
|
|
19
|
+
export * from "./combobox-filter.js";
|
|
20
|
+
export * from "./command-filter.js";
|
|
21
|
+
export * from "./command-keys.js";
|
|
22
|
+
export * from "./context-menu.js";
|
|
23
|
+
export * from "./copy-to-clipboard.js";
|
|
24
|
+
export * from "./dismiss.js";
|
|
25
|
+
export * from "./drag-reorder.js";
|
|
26
|
+
export * from "./drop-zone.js";
|
|
27
|
+
export * from "./dual-range.js";
|
|
28
|
+
export * from "./grid-list-keys.js";
|
|
29
|
+
export * from "./heading-level-fallback.js";
|
|
30
|
+
export * from "./hotkey.js";
|
|
31
|
+
export * from "./image-fallback.js";
|
|
32
|
+
export * from "./listbox-keys.js";
|
|
33
|
+
export * from "./long-press.js";
|
|
34
|
+
export * from "./menu-keys.js";
|
|
35
|
+
export * from "./menubar-keys.js";
|
|
36
|
+
export * from "./message-follow.js";
|
|
37
|
+
export * from "./otp-slots.js";
|
|
38
|
+
export * from "./persist.js";
|
|
39
|
+
export * from "./press-toggle.js";
|
|
40
|
+
export * from "./range-preview.js";
|
|
41
|
+
export * from "./resize-handle.js";
|
|
42
|
+
export * from "./stepper.js";
|
|
43
|
+
export * from "./tab-keys.js";
|
|
44
|
+
export * from "./theme-toggle.js";
|
|
45
|
+
export * from "./track-host-node.js";
|
|
46
|
+
export * from "./treeKeys.js";
|
|
47
|
+
export * from "./validate.js";
|
|
48
|
+
export * from "./view-transition.js";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Barrel for opt-in behavior mixins: `createMixin`-based building blocks,
|
|
3
|
+
* one module per behavior, that attach a `behaviors/` state model to a host
|
|
4
|
+
* element through the standard `mix` prop alongside `css()` and friends.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
export * from "./aria-checked.js";
|
|
10
|
+
export * from "./attachment-trigger.js";
|
|
11
|
+
export * from "./calendar-keys.js";
|
|
12
|
+
export * from "./carousel-controls.js";
|
|
13
|
+
export * from "./chart-tooltip.js";
|
|
14
|
+
export * from "./clear-field.js";
|
|
15
|
+
export * from "./color-area-drag.js";
|
|
16
|
+
export * from "./color-channel-sync.js";
|
|
17
|
+
export * from "./color-preview.js";
|
|
18
|
+
export * from "./color-wheel-drag.js";
|
|
19
|
+
export * from "./combobox-filter.js";
|
|
20
|
+
export * from "./command-filter.js";
|
|
21
|
+
export * from "./command-keys.js";
|
|
22
|
+
export * from "./context-menu.js";
|
|
23
|
+
export * from "./copy-to-clipboard.js";
|
|
24
|
+
export * from "./dismiss.js";
|
|
25
|
+
export * from "./drag-reorder.js";
|
|
26
|
+
export * from "./drop-zone.js";
|
|
27
|
+
export * from "./dual-range.js";
|
|
28
|
+
export * from "./grid-list-keys.js";
|
|
29
|
+
export * from "./heading-level-fallback.js";
|
|
30
|
+
export * from "./hotkey.js";
|
|
31
|
+
export * from "./image-fallback.js";
|
|
32
|
+
export * from "./listbox-keys.js";
|
|
33
|
+
export * from "./long-press.js";
|
|
34
|
+
export * from "./menu-keys.js";
|
|
35
|
+
export * from "./menubar-keys.js";
|
|
36
|
+
export * from "./message-follow.js";
|
|
37
|
+
export * from "./otp-slots.js";
|
|
38
|
+
export * from "./persist.js";
|
|
39
|
+
export * from "./press-toggle.js";
|
|
40
|
+
export * from "./range-preview.js";
|
|
41
|
+
export * from "./resize-handle.js";
|
|
42
|
+
export * from "./stepper.js";
|
|
43
|
+
export * from "./tab-keys.js";
|
|
44
|
+
export * from "./theme-toggle.js";
|
|
45
|
+
export * from "./track-host-node.js";
|
|
46
|
+
export * from "./treeKeys.js";
|
|
47
|
+
export * from "./validate.js";
|
|
48
|
+
export * from "./view-transition.js";
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapts `remix/ui/listbox`'s ARIA listbox keyboard pattern onto a ListBox's
|
|
3
|
+
* option-list host, delegating arrow keys, `Home`/`End`, typeahead, and
|
|
4
|
+
* `Enter`/`Space` to `remix/ui/listbox`'s own `list()` primitive, and reports
|
|
5
|
+
* the shared context's selected value and active option as a typed event.
|
|
6
|
+
*
|
|
7
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
8
|
+
* @copyright Sergio Xalambrí 2026
|
|
9
|
+
*/
|
|
10
|
+
import type { MixinFactory } from "remix/ui";
|
|
11
|
+
import * as listbox from "remix/ui/listbox";
|
|
12
|
+
/** DOM event type dispatched by {@link listboxKeys} whenever the selected value or the active option changes. */
|
|
13
|
+
declare const LISTBOX_CHANGE_EVENT: "ui:listbox-change";
|
|
14
|
+
declare global {
|
|
15
|
+
interface HTMLElementEventMap {
|
|
16
|
+
[LISTBOX_CHANGE_EVENT]: ListboxChangeEvent;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Dispatched on a ListBox's option-list host by {@link listboxKeys}
|
|
21
|
+
* whenever the shared context's selected value or active option moves, so
|
|
22
|
+
* a consumer can react without reading that context directly.
|
|
23
|
+
*/
|
|
24
|
+
export declare class ListboxChangeEvent extends Event {
|
|
25
|
+
/** Value the listbox currently reports as selected, or `null` when nothing is selected. */
|
|
26
|
+
readonly value: listbox.ListboxValue;
|
|
27
|
+
/** Value of the option currently active for keyboard and pointer navigation, or `null` when none is active. */
|
|
28
|
+
readonly activeValue: listbox.ListboxValue;
|
|
29
|
+
/**
|
|
30
|
+
* @param init Snapshot of the listbox's selection state at dispatch time.
|
|
31
|
+
*/
|
|
32
|
+
constructor(init: {
|
|
33
|
+
value: listbox.ListboxValue;
|
|
34
|
+
activeValue: listbox.ListboxValue;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Turns a ListBox's option-list host into the ARIA listbox keyboard surface
|
|
39
|
+
* by delegating to `remix/ui/listbox`'s `list()` primitive. Use it inside an
|
|
40
|
+
* ancestor `listbox.Context` alongside a matching `option()` mixin.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* <listbox.Context value={value} activeValue={activeValue} onSelect={onSelect} onHighlight={onHighlight}>
|
|
44
|
+
* <div role="listbox" aria-label="Frameworks" mix={[listStyle, listboxKeys()]}>
|
|
45
|
+
* {frameworks.map((option) => (
|
|
46
|
+
* <div key={option.value} mix={[optionStyle, listbox.option(option)]}>{option.label}</div>
|
|
47
|
+
* ))}
|
|
48
|
+
* </div>
|
|
49
|
+
* </listbox.Context>
|
|
50
|
+
*/
|
|
51
|
+
export declare const listboxKeys: MixinFactory<HTMLElement>;
|
|
52
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapts `remix/ui/listbox`'s ARIA listbox keyboard pattern onto a ListBox's
|
|
3
|
+
* option-list host, delegating arrow keys, `Home`/`End`, typeahead, and
|
|
4
|
+
* `Enter`/`Space` to `remix/ui/listbox`'s own `list()` primitive, and reports
|
|
5
|
+
* the shared context's selected value and active option as a typed event.
|
|
6
|
+
*
|
|
7
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
8
|
+
* @copyright Sergio Xalambrí 2026
|
|
9
|
+
*/
|
|
10
|
+
import { createMixin } from "remix/ui";
|
|
11
|
+
import * as listbox from "remix/ui/listbox";
|
|
12
|
+
import { trackHostNode } from "./track-host-node.js";
|
|
13
|
+
/** DOM event type dispatched by {@link listboxKeys} whenever the selected value or the active option changes. */
|
|
14
|
+
const LISTBOX_CHANGE_EVENT = "ui:listbox-change";
|
|
15
|
+
/**
|
|
16
|
+
* Dispatched on a ListBox's option-list host by {@link listboxKeys}
|
|
17
|
+
* whenever the shared context's selected value or active option moves, so
|
|
18
|
+
* a consumer can react without reading that context directly.
|
|
19
|
+
*/
|
|
20
|
+
export class ListboxChangeEvent extends Event {
|
|
21
|
+
/** Value the listbox currently reports as selected, or `null` when nothing is selected. */
|
|
22
|
+
value;
|
|
23
|
+
/** Value of the option currently active for keyboard and pointer navigation, or `null` when none is active. */
|
|
24
|
+
activeValue;
|
|
25
|
+
/**
|
|
26
|
+
* @param init Snapshot of the listbox's selection state at dispatch time.
|
|
27
|
+
*/
|
|
28
|
+
constructor(init) {
|
|
29
|
+
super(LISTBOX_CHANGE_EVENT, { bubbles: true });
|
|
30
|
+
this.value = init.value;
|
|
31
|
+
this.activeValue = init.activeValue;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Turns a ListBox's option-list host into the ARIA listbox keyboard surface
|
|
36
|
+
* by delegating to `remix/ui/listbox`'s `list()` primitive. Use it inside an
|
|
37
|
+
* ancestor `listbox.Context` alongside a matching `option()` mixin.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* <listbox.Context value={value} activeValue={activeValue} onSelect={onSelect} onHighlight={onHighlight}>
|
|
41
|
+
* <div role="listbox" aria-label="Frameworks" mix={[listStyle, listboxKeys()]}>
|
|
42
|
+
* {frameworks.map((option) => (
|
|
43
|
+
* <div key={option.value} mix={[optionStyle, listbox.option(option)]}>{option.label}</div>
|
|
44
|
+
* ))}
|
|
45
|
+
* </div>
|
|
46
|
+
* </listbox.Context>
|
|
47
|
+
*/
|
|
48
|
+
export const listboxKeys = createMixin((handle) => {
|
|
49
|
+
let context = handle.context.get(listbox.Context);
|
|
50
|
+
let getHostNode = trackHostNode(handle);
|
|
51
|
+
let lastValue = context.value;
|
|
52
|
+
let lastActiveValue = context.activeValue;
|
|
53
|
+
return () => {
|
|
54
|
+
let value = context.value;
|
|
55
|
+
let activeValue = context.activeValue;
|
|
56
|
+
if (value !== lastValue || activeValue !== lastActiveValue) {
|
|
57
|
+
lastValue = value;
|
|
58
|
+
lastActiveValue = activeValue;
|
|
59
|
+
getHostNode()?.dispatchEvent(new ListboxChangeEvent({ value, activeValue }));
|
|
60
|
+
}
|
|
61
|
+
return listbox.list();
|
|
62
|
+
};
|
|
63
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic long-press detection for any host element: a `pointerdown` starts
|
|
3
|
+
* a timer, and once the pointer has held still for a configurable duration,
|
|
4
|
+
* the host dispatches a namespaced `ui:long-press` event carrying the
|
|
5
|
+
* pointer's position, so a consumer can anchor a menu, tooltip, or preview
|
|
6
|
+
* to the exact spot the press held.
|
|
7
|
+
*
|
|
8
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
9
|
+
* @copyright Sergio Xalambrí 2026
|
|
10
|
+
*/
|
|
11
|
+
import type { ElementProps, MixinFactory } from "remix/ui";
|
|
12
|
+
import type { AnchorPoint } from "remix/ui/anchor";
|
|
13
|
+
/** DOM event type dispatched on the host by {@link longPress} once a press holds still for the configured duration. */
|
|
14
|
+
declare const LONG_PRESS_EVENT: "ui:long-press";
|
|
15
|
+
declare global {
|
|
16
|
+
interface HTMLElementEventMap {
|
|
17
|
+
[LONG_PRESS_EVENT]: LongPressEvent;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Types associated with {@link longPress}: the options it accepts.
|
|
22
|
+
*/
|
|
23
|
+
export declare namespace LongPress {
|
|
24
|
+
/**
|
|
25
|
+
* Configuration accepted by {@link longPress}.
|
|
26
|
+
*/
|
|
27
|
+
interface Options {
|
|
28
|
+
/**
|
|
29
|
+
* Milliseconds the pointer must remain pressed, without drifting past
|
|
30
|
+
* the movement tolerance, before {@link LongPressEvent} fires. Defaults
|
|
31
|
+
* to 500.
|
|
32
|
+
*/
|
|
33
|
+
duration?: number;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Dispatched on a host by {@link longPress} once a pointer press has held
|
|
38
|
+
* its position for the configured duration, carrying that position as an
|
|
39
|
+
* `AnchorPoint` so a consumer can anchor a menu, tooltip, or preview to it.
|
|
40
|
+
*/
|
|
41
|
+
export declare class LongPressEvent extends Event {
|
|
42
|
+
/** Pointer position the press held, in viewport coordinates, ready to pass straight into `remix/ui/anchor`'s point-based anchoring. */
|
|
43
|
+
readonly point: AnchorPoint;
|
|
44
|
+
/**
|
|
45
|
+
* @param point Pointer position the press held.
|
|
46
|
+
*/
|
|
47
|
+
constructor(point: AnchorPoint);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Detects a long press on any host element: a primary-pointer `pointerdown`
|
|
51
|
+
* starts a timer, tracking only one press at a time, and dispatches
|
|
52
|
+
* {@link LongPressEvent} once the pointer holds still for the full duration.
|
|
53
|
+
*
|
|
54
|
+
* @param options Duration configuration; see {@link LongPress.Options}.
|
|
55
|
+
* Reset to an empty object when the mixin runtime passes its trailing
|
|
56
|
+
* current-props argument in its place.
|
|
57
|
+
* @returns A mixin descriptor for a host element's `mix` prop.
|
|
58
|
+
* @example
|
|
59
|
+
* <li
|
|
60
|
+
* id="row-1"
|
|
61
|
+
* mix={[
|
|
62
|
+
* longPress(),
|
|
63
|
+
* on("ui:long-press", (event) => {
|
|
64
|
+
* let menu = document.getElementById("row-1-menu");
|
|
65
|
+
* if (!menu) return;
|
|
66
|
+
* anchor(menu, event.point);
|
|
67
|
+
* menu.showPopover();
|
|
68
|
+
* }),
|
|
69
|
+
* ]}
|
|
70
|
+
* >
|
|
71
|
+
* Row 1
|
|
72
|
+
* </li>
|
|
73
|
+
* <div id="row-1-menu" popover="auto" role="menu">...</div>
|
|
74
|
+
*/
|
|
75
|
+
export declare const longPress: MixinFactory<HTMLElement, [options?: LongPress.Options], ElementProps>;
|
|
76
|
+
export {};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic long-press detection for any host element: a `pointerdown` starts
|
|
3
|
+
* a timer, and once the pointer has held still for a configurable duration,
|
|
4
|
+
* the host dispatches a namespaced `ui:long-press` event carrying the
|
|
5
|
+
* pointer's position, so a consumer can anchor a menu, tooltip, or preview
|
|
6
|
+
* to the exact spot the press held.
|
|
7
|
+
*
|
|
8
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
9
|
+
* @copyright Sergio Xalambrí 2026
|
|
10
|
+
*/
|
|
11
|
+
import { createElement, createMixin, on } from "remix/ui";
|
|
12
|
+
import { isNewPrimaryPress } from "../utils/is-new-primary-press.js";
|
|
13
|
+
/** Duration, in milliseconds, {@link longPress} holds the pointer for before dispatching, when {@link LongPress.Options.duration} is omitted. */
|
|
14
|
+
const DEFAULT_DURATION = 500;
|
|
15
|
+
/**
|
|
16
|
+
* Distance, in pixels, the pointer may drift from its `pointerdown` position
|
|
17
|
+
* before {@link longPress} clears the pending timer instead of letting it
|
|
18
|
+
* fire, tolerating the small, involuntary movement a held press carries.
|
|
19
|
+
*/
|
|
20
|
+
const MOVE_TOLERANCE = 10;
|
|
21
|
+
/** DOM event type dispatched on the host by {@link longPress} once a press holds still for the configured duration. */
|
|
22
|
+
const LONG_PRESS_EVENT = "ui:long-press";
|
|
23
|
+
/**
|
|
24
|
+
* Dispatched on a host by {@link longPress} once a pointer press has held
|
|
25
|
+
* its position for the configured duration, carrying that position as an
|
|
26
|
+
* `AnchorPoint` so a consumer can anchor a menu, tooltip, or preview to it.
|
|
27
|
+
*/
|
|
28
|
+
export class LongPressEvent extends Event {
|
|
29
|
+
/** Pointer position the press held, in viewport coordinates, ready to pass straight into `remix/ui/anchor`'s point-based anchoring. */
|
|
30
|
+
point;
|
|
31
|
+
/**
|
|
32
|
+
* @param point Pointer position the press held.
|
|
33
|
+
*/
|
|
34
|
+
constructor(point) {
|
|
35
|
+
super(LONG_PRESS_EVENT, { bubbles: true });
|
|
36
|
+
this.point = point;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Detects a long press on any host element: a primary-pointer `pointerdown`
|
|
41
|
+
* starts a timer, tracking only one press at a time, and dispatches
|
|
42
|
+
* {@link LongPressEvent} once the pointer holds still for the full duration.
|
|
43
|
+
*
|
|
44
|
+
* @param options Duration configuration; see {@link LongPress.Options}.
|
|
45
|
+
* Reset to an empty object when the mixin runtime passes its trailing
|
|
46
|
+
* current-props argument in its place.
|
|
47
|
+
* @returns A mixin descriptor for a host element's `mix` prop.
|
|
48
|
+
* @example
|
|
49
|
+
* <li
|
|
50
|
+
* id="row-1"
|
|
51
|
+
* mix={[
|
|
52
|
+
* longPress(),
|
|
53
|
+
* on("ui:long-press", (event) => {
|
|
54
|
+
* let menu = document.getElementById("row-1-menu");
|
|
55
|
+
* if (!menu) return;
|
|
56
|
+
* anchor(menu, event.point);
|
|
57
|
+
* menu.showPopover();
|
|
58
|
+
* }),
|
|
59
|
+
* ]}
|
|
60
|
+
* >
|
|
61
|
+
* Row 1
|
|
62
|
+
* </li>
|
|
63
|
+
* <div id="row-1-menu" popover="auto" role="menu">...</div>
|
|
64
|
+
*/
|
|
65
|
+
export const longPress = createMixin((handle) => {
|
|
66
|
+
let hostNode;
|
|
67
|
+
let timer;
|
|
68
|
+
let activePointerId;
|
|
69
|
+
let origin;
|
|
70
|
+
handle.addEventListener("insert", (event) => {
|
|
71
|
+
hostNode = event.node;
|
|
72
|
+
});
|
|
73
|
+
handle.addEventListener("remove", () => {
|
|
74
|
+
clearPending();
|
|
75
|
+
hostNode = undefined;
|
|
76
|
+
});
|
|
77
|
+
/** Clears the pending timer, if any, and forgets the tracked pointer and its origin. */
|
|
78
|
+
function clearPending() {
|
|
79
|
+
if (timer !== undefined) {
|
|
80
|
+
clearTimeout(timer);
|
|
81
|
+
timer = undefined;
|
|
82
|
+
}
|
|
83
|
+
activePointerId = undefined;
|
|
84
|
+
origin = undefined;
|
|
85
|
+
}
|
|
86
|
+
return (options = {}, props = options) => {
|
|
87
|
+
if (props === options) {
|
|
88
|
+
options = {};
|
|
89
|
+
}
|
|
90
|
+
let duration = options.duration ?? DEFAULT_DURATION;
|
|
91
|
+
return createElement(handle.element, {
|
|
92
|
+
mix: [
|
|
93
|
+
on("pointerdown", (event) => {
|
|
94
|
+
if (!isNewPrimaryPress(event, activePointerId))
|
|
95
|
+
return;
|
|
96
|
+
activePointerId = event.pointerId;
|
|
97
|
+
origin = { x: event.clientX, y: event.clientY };
|
|
98
|
+
timer = setTimeout(() => {
|
|
99
|
+
let point = origin;
|
|
100
|
+
clearPending();
|
|
101
|
+
if (point)
|
|
102
|
+
hostNode?.dispatchEvent(new LongPressEvent(point));
|
|
103
|
+
}, duration);
|
|
104
|
+
}),
|
|
105
|
+
on("pointermove", (event) => {
|
|
106
|
+
if (event.pointerId !== activePointerId || !origin)
|
|
107
|
+
return;
|
|
108
|
+
let distance = Math.hypot(event.clientX - origin.x, event.clientY - origin.y);
|
|
109
|
+
if (distance > MOVE_TOLERANCE)
|
|
110
|
+
clearPending();
|
|
111
|
+
}),
|
|
112
|
+
on("pointerup", (event) => {
|
|
113
|
+
if (event.pointerId !== activePointerId)
|
|
114
|
+
return;
|
|
115
|
+
clearPending();
|
|
116
|
+
}),
|
|
117
|
+
on("pointercancel", (event) => {
|
|
118
|
+
if (event.pointerId !== activePointerId)
|
|
119
|
+
return;
|
|
120
|
+
clearPending();
|
|
121
|
+
}),
|
|
122
|
+
on("pointerleave", (event) => {
|
|
123
|
+
if (event.pointerId !== activePointerId)
|
|
124
|
+
return;
|
|
125
|
+
clearPending();
|
|
126
|
+
}),
|
|
127
|
+
],
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why JS: the WAI-ARIA menu pattern requires roving tabindex, arrow-key
|
|
3
|
+
* navigation, Home/End, and typeahead, which HTML does not provide.
|
|
4
|
+
* No-JS baseline: the Menu surface still opens and closes via the Popover
|
|
5
|
+
* API and its items remain reachable in Tab order.
|
|
6
|
+
*
|
|
7
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
8
|
+
* @copyright Sergio Xalambrí 2026
|
|
9
|
+
*/
|
|
10
|
+
import type { ElementProps, MixinFactory } from "remix/ui";
|
|
11
|
+
/**
|
|
12
|
+
* Types associated with {@link menuKeys}.
|
|
13
|
+
*/
|
|
14
|
+
export declare namespace MenuKeys {
|
|
15
|
+
/**
|
|
16
|
+
* Configuration accepted by {@link menuKeys}.
|
|
17
|
+
*/
|
|
18
|
+
interface Options {
|
|
19
|
+
/**
|
|
20
|
+
* Selector, evaluated against the Menu surface's descendants, that
|
|
21
|
+
* identifies its menu items. Defaults to `[role^="menuitem"]`, matching
|
|
22
|
+
* the `menuitem`, `menuitemcheckbox`, and `menuitemradio` roles.
|
|
23
|
+
*/
|
|
24
|
+
itemSelector?: string;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Adapts the WAI-ARIA menu keyboard pattern — roving tabindex, arrow-key
|
|
29
|
+
* navigation, Home/End, and typeahead — onto a Menu surface's
|
|
30
|
+
* `[role^="menuitem"]` descendants; only manages focus, leaving activation to native semantics.
|
|
31
|
+
*
|
|
32
|
+
* @param options Item-selector override for non-standard markup.
|
|
33
|
+
* @returns A mixin descriptor for the Menu surface's `mix` prop.
|
|
34
|
+
* @example
|
|
35
|
+
* <Menu.List mix={menuKeys()}>
|
|
36
|
+
* <Menu.Item>Rename</Menu.Item>
|
|
37
|
+
* <Menu.Item>Delete</Menu.Item>
|
|
38
|
+
* </Menu.List>
|
|
39
|
+
*/
|
|
40
|
+
export declare const menuKeys: MixinFactory<HTMLElement, [options?: MenuKeys.Options], ElementProps>;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why JS: the WAI-ARIA menu pattern requires roving tabindex, arrow-key
|
|
3
|
+
* navigation, Home/End, and typeahead, which HTML does not provide.
|
|
4
|
+
* No-JS baseline: the Menu surface still opens and closes via the Popover
|
|
5
|
+
* API and its items remain reachable in Tab order.
|
|
6
|
+
*
|
|
7
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
8
|
+
* @copyright Sergio Xalambrí 2026
|
|
9
|
+
*/
|
|
10
|
+
import { createMixin, ref } from "remix/ui";
|
|
11
|
+
import { focusItem, isPrintableKey, labelFor, queryItems, setRovingTabindex, } from "../utils/keyboard-nav.js";
|
|
12
|
+
/** Selector matching a menu item's role, regardless of its checked state. */
|
|
13
|
+
const DEFAULT_ITEM_SELECTOR = '[role^="menuitem"]';
|
|
14
|
+
/** Idle time after the last keystroke before the typeahead buffer resets. */
|
|
15
|
+
const TYPEAHEAD_RESET_MS = 500;
|
|
16
|
+
/**
|
|
17
|
+
* Reports whether `event`'s closest `role="menu"` ancestor is `host`, so
|
|
18
|
+
* each menu surface — including a nested submenu reusing this same mixin —
|
|
19
|
+
* handles only the events that originate within its own boundary.
|
|
20
|
+
*/
|
|
21
|
+
function belongsToSurface(event, host) {
|
|
22
|
+
let target = event.target;
|
|
23
|
+
return target instanceof Element && target.closest('[role="menu"]') === host;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Index of the currently focused item within `items`, or `-1` when focus
|
|
27
|
+
* sits on the surface itself (or elsewhere) with no item yet active.
|
|
28
|
+
*/
|
|
29
|
+
function activeIndexOf(host, items) {
|
|
30
|
+
let active = host.ownerDocument.activeElement;
|
|
31
|
+
return active instanceof HTMLElement ? items.indexOf(active) : -1;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Adapts the WAI-ARIA menu keyboard pattern — roving tabindex, arrow-key
|
|
35
|
+
* navigation, Home/End, and typeahead — onto a Menu surface's
|
|
36
|
+
* `[role^="menuitem"]` descendants; only manages focus, leaving activation to native semantics.
|
|
37
|
+
*
|
|
38
|
+
* @param options Item-selector override for non-standard markup.
|
|
39
|
+
* @returns A mixin descriptor for the Menu surface's `mix` prop.
|
|
40
|
+
* @example
|
|
41
|
+
* <Menu.List mix={menuKeys()}>
|
|
42
|
+
* <Menu.Item>Rename</Menu.Item>
|
|
43
|
+
* <Menu.Item>Delete</Menu.Item>
|
|
44
|
+
* </Menu.List>
|
|
45
|
+
*/
|
|
46
|
+
export const menuKeys = createMixin((_handle) => {
|
|
47
|
+
let buffer = "";
|
|
48
|
+
let resetBufferId;
|
|
49
|
+
return (options = {}, props = options) => {
|
|
50
|
+
if (props === options)
|
|
51
|
+
options = {};
|
|
52
|
+
let selector = options.itemSelector ?? DEFAULT_ITEM_SELECTOR;
|
|
53
|
+
return ref((host, signal) => {
|
|
54
|
+
let initialItems = queryItems(host, selector);
|
|
55
|
+
if (initialItems.length > 0)
|
|
56
|
+
setRovingTabindex(initialItems, initialItems[0]);
|
|
57
|
+
host.addEventListener("focusin", (event) => {
|
|
58
|
+
if (!belongsToSurface(event, host))
|
|
59
|
+
return;
|
|
60
|
+
let target = event.target;
|
|
61
|
+
if (!(target instanceof HTMLElement))
|
|
62
|
+
return;
|
|
63
|
+
let items = queryItems(host, selector);
|
|
64
|
+
if (items.includes(target))
|
|
65
|
+
setRovingTabindex(items, target);
|
|
66
|
+
}, { signal });
|
|
67
|
+
host.addEventListener("keydown", (event) => {
|
|
68
|
+
if (!belongsToSurface(event, host))
|
|
69
|
+
return;
|
|
70
|
+
let items = queryItems(host, selector);
|
|
71
|
+
if (items.length === 0)
|
|
72
|
+
return;
|
|
73
|
+
let index = activeIndexOf(host, items);
|
|
74
|
+
switch (event.key) {
|
|
75
|
+
case "ArrowDown": {
|
|
76
|
+
event.preventDefault();
|
|
77
|
+
let next = index === -1 ? items[0] : items[index + 1];
|
|
78
|
+
if (next)
|
|
79
|
+
focusItem(items, next);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
case "ArrowUp": {
|
|
83
|
+
event.preventDefault();
|
|
84
|
+
let previous = index === -1 ? items[items.length - 1] : items[index - 1];
|
|
85
|
+
if (previous)
|
|
86
|
+
focusItem(items, previous);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
case "Home":
|
|
90
|
+
event.preventDefault();
|
|
91
|
+
focusItem(items, items[0]);
|
|
92
|
+
return;
|
|
93
|
+
case "End":
|
|
94
|
+
event.preventDefault();
|
|
95
|
+
focusItem(items, items[items.length - 1]);
|
|
96
|
+
return;
|
|
97
|
+
case "Backspace":
|
|
98
|
+
buffer = buffer.slice(0, -1);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (!isPrintableKey(event))
|
|
102
|
+
return;
|
|
103
|
+
clearTimeout(resetBufferId);
|
|
104
|
+
buffer += event.key.toLowerCase();
|
|
105
|
+
resetBufferId = setTimeout(() => {
|
|
106
|
+
buffer = "";
|
|
107
|
+
}, TYPEAHEAD_RESET_MS);
|
|
108
|
+
let start = index === -1 ? 0 : index + 1;
|
|
109
|
+
let searchOrder = [...items.slice(start), ...items.slice(0, start)];
|
|
110
|
+
let match = searchOrder.find((item) => labelFor(item).startsWith(buffer));
|
|
111
|
+
if (match)
|
|
112
|
+
focusItem(items, match);
|
|
113
|
+
}, { signal });
|
|
114
|
+
signal.addEventListener("abort", () => clearTimeout(resetBufferId));
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
});
|