@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,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapts the WAI-ARIA grid keyboard pattern onto a GridList's rows and
|
|
3
|
+
* action cells: one roving focus position moves with the arrow and
|
|
4
|
+
* Home/End keys, and Space/Shift/Ctrl drive selection through a
|
|
5
|
+
* `SelectionModel` instance.
|
|
6
|
+
*
|
|
7
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
8
|
+
* @copyright Sergio Xalambrí 2026
|
|
9
|
+
*/
|
|
10
|
+
import { createElement, createMixin, on } from "remix/ui";
|
|
11
|
+
import { DISABLED_SELECTOR } from "../utils/disabled-selector.js";
|
|
12
|
+
/**
|
|
13
|
+
* Attribute every GridList row exposes its {@link SelectionModel.Key} on;
|
|
14
|
+
* `gridListKeys()` correlates a row with the key `SelectionModel` tracks its
|
|
15
|
+
* selection under, and writes `aria-selected` back as the model changes.
|
|
16
|
+
*/
|
|
17
|
+
export const GRIDLIST_ROW_KEY_ATTRIBUTE = "data-rmx-key";
|
|
18
|
+
/** Selector matching a GridList row, by the same attribute contract {@link GRIDLIST_ROW_KEY_ATTRIBUTE} documents. */
|
|
19
|
+
const ROW_SELECTOR = `[${GRIDLIST_ROW_KEY_ATTRIBUTE}]`;
|
|
20
|
+
/** Selector matching one of a row's individually focusable action cells. */
|
|
21
|
+
const CELL_SELECTOR = '[role="gridcell"]';
|
|
22
|
+
/**
|
|
23
|
+
* Collects the grid's enabled rows beneath `host`, in document order.
|
|
24
|
+
* Queried fresh on every keystroke and focus change so navigation stays
|
|
25
|
+
* correct as rows are added, removed, or toggled disabled.
|
|
26
|
+
*/
|
|
27
|
+
function queryRows(host) {
|
|
28
|
+
let candidates = host.querySelectorAll(ROW_SELECTOR);
|
|
29
|
+
return Array.from(candidates).filter((row) => !row.matches(DISABLED_SELECTOR));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Collects `row`'s enabled action cells, in document order.
|
|
33
|
+
*/
|
|
34
|
+
function queryCells(row) {
|
|
35
|
+
let candidates = row.querySelectorAll(CELL_SELECTOR);
|
|
36
|
+
return Array.from(candidates).filter((cell) => !cell.matches(DISABLED_SELECTOR));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Reads the raw {@link GRIDLIST_ROW_KEY_ATTRIBUTE} value off `row`, ahead of
|
|
40
|
+
* resolving it back to the `SelectionModel.Key` it names.
|
|
41
|
+
*/
|
|
42
|
+
function rowKeyOf(row) {
|
|
43
|
+
return row.getAttribute(GRIDLIST_ROW_KEY_ATTRIBUTE) ?? "";
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Resolves a row's raw {@link GRIDLIST_ROW_KEY_ATTRIBUTE} string back to the
|
|
47
|
+
* `SelectionModel.Key` it names, matching by string equality so a model
|
|
48
|
+
* tracking numeric keys still correlates with the string-only DOM attribute.
|
|
49
|
+
*
|
|
50
|
+
* @returns The matching key, or the raw string itself when it matches no
|
|
51
|
+
* known key — for example, before the consumer has called `SelectionModel.setKeys`.
|
|
52
|
+
*/
|
|
53
|
+
function resolveKey(model, raw) {
|
|
54
|
+
for (let key of model.keys) {
|
|
55
|
+
if (String(key) === raw)
|
|
56
|
+
return key;
|
|
57
|
+
}
|
|
58
|
+
return raw;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Locates where a keydown or focus event originated within the grid: which
|
|
62
|
+
* row, and — when it came from one of that row's action cells rather than
|
|
63
|
+
* the row itself — which cell.
|
|
64
|
+
*
|
|
65
|
+
* @returns The origin position, or `null` when `target` isn't inside any of `rows`.
|
|
66
|
+
*/
|
|
67
|
+
function locate(rows, target) {
|
|
68
|
+
if (!(target instanceof Element))
|
|
69
|
+
return null;
|
|
70
|
+
let row = target.closest(ROW_SELECTOR);
|
|
71
|
+
if (row === null)
|
|
72
|
+
return null;
|
|
73
|
+
let rowIndex = rows.indexOf(row);
|
|
74
|
+
if (rowIndex === -1)
|
|
75
|
+
return null;
|
|
76
|
+
if (target === row)
|
|
77
|
+
return { rowIndex, cellIndex: null };
|
|
78
|
+
let cell = target.closest(CELL_SELECTOR);
|
|
79
|
+
if (cell === null || cell.closest(ROW_SELECTOR) !== row)
|
|
80
|
+
return { rowIndex, cellIndex: null };
|
|
81
|
+
let cellIndex = queryCells(row).indexOf(cell);
|
|
82
|
+
return { rowIndex, cellIndex: cellIndex === -1 ? null : cellIndex };
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Resolves a {@link Position} back to the actual row or cell element it
|
|
86
|
+
* names, so a raw event target several levels deep (an icon inside an
|
|
87
|
+
* action button) still maps onto one of the grid's real roving-focus stops.
|
|
88
|
+
*/
|
|
89
|
+
function stopAt(rows, position) {
|
|
90
|
+
let row = rows[position.rowIndex];
|
|
91
|
+
if (position.cellIndex === null)
|
|
92
|
+
return row;
|
|
93
|
+
return queryCells(row)[position.cellIndex] ?? row;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Every element the grid's roving tabindex currently spans: each row plus
|
|
97
|
+
* its own action cells.
|
|
98
|
+
*/
|
|
99
|
+
function allStops(rows) {
|
|
100
|
+
let stops = [];
|
|
101
|
+
for (let row of rows)
|
|
102
|
+
stops.push(row, ...queryCells(row));
|
|
103
|
+
return stops;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Assigns roving tabindex across the whole grid: `active` becomes the sole
|
|
107
|
+
* Tab-reachable stop (`tabIndex = 0`) and every other row and cell drops out
|
|
108
|
+
* of Tab order (`tabIndex = -1`).
|
|
109
|
+
*/
|
|
110
|
+
function setRovingTabindex(rows, active) {
|
|
111
|
+
for (let stop of allStops(rows))
|
|
112
|
+
stop.tabIndex = stop === active ? 0 : -1;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Moves roving tabindex and real DOM focus onto `target`, then scrolls it
|
|
116
|
+
* into view — necessary for a grid tall enough to scroll, or rendered with
|
|
117
|
+
* `content-visibility: auto`.
|
|
118
|
+
*/
|
|
119
|
+
function focusElement(rows, target) {
|
|
120
|
+
setRovingTabindex(rows, target);
|
|
121
|
+
target.focus();
|
|
122
|
+
target.scrollIntoView({ block: "nearest", inline: "nearest" });
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Mirrors `model`'s selected keys onto every row beneath `host` as
|
|
126
|
+
* `aria-selected`, using {@link GRIDLIST_ROW_KEY_ATTRIBUTE} to correlate each
|
|
127
|
+
* row with the key `model` tracks it under.
|
|
128
|
+
*/
|
|
129
|
+
function syncSelection(host, model) {
|
|
130
|
+
for (let row of host.querySelectorAll(ROW_SELECTOR)) {
|
|
131
|
+
let key = resolveKey(model, rowKeyOf(row));
|
|
132
|
+
row.setAttribute("aria-selected", String(model.isSelected(key)));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Adds ARIA grid keyboard navigation and selection to a GridList's rows and
|
|
137
|
+
* action cells, driving a `SelectionModel` and mirroring its `"change"`
|
|
138
|
+
* events back onto the rows as `aria-selected`.
|
|
139
|
+
*
|
|
140
|
+
* @param model Behavior class instance owning the grid's selected keys.
|
|
141
|
+
* @example
|
|
142
|
+
* let model = new SelectionModel({ keys: rows.map((row) => row.id) });
|
|
143
|
+
* <div role="grid" mix={[gridListKeys(model)]}>
|
|
144
|
+
* {rows.map((row) => (
|
|
145
|
+
* <div key={row.id} role="row" data-rmx-key={row.id} tabIndex={-1}>
|
|
146
|
+
* {row.label}
|
|
147
|
+
* <button role="gridcell" tabIndex={-1}>Remove</button>
|
|
148
|
+
* </div>
|
|
149
|
+
* ))}
|
|
150
|
+
* </div>
|
|
151
|
+
*/
|
|
152
|
+
export const gridListKeys = createMixin((handle) => {
|
|
153
|
+
let hostNode;
|
|
154
|
+
let boundModel;
|
|
155
|
+
handle.addEventListener("insert", (event) => {
|
|
156
|
+
hostNode = event.node;
|
|
157
|
+
let rows = queryRows(hostNode);
|
|
158
|
+
if (rows.length > 0)
|
|
159
|
+
setRovingTabindex(rows, rows[0]);
|
|
160
|
+
});
|
|
161
|
+
handle.addEventListener("remove", () => {
|
|
162
|
+
hostNode = undefined;
|
|
163
|
+
});
|
|
164
|
+
return (model) => {
|
|
165
|
+
if (boundModel !== model) {
|
|
166
|
+
boundModel = model;
|
|
167
|
+
model.addEventListener("change", () => {
|
|
168
|
+
if (hostNode !== undefined)
|
|
169
|
+
syncSelection(hostNode, model);
|
|
170
|
+
}, { signal: handle.signal });
|
|
171
|
+
}
|
|
172
|
+
return createElement(handle.element, {
|
|
173
|
+
mix: [
|
|
174
|
+
on("focusin", (event) => {
|
|
175
|
+
if (hostNode === undefined)
|
|
176
|
+
return;
|
|
177
|
+
let rows = queryRows(hostNode);
|
|
178
|
+
let position = locate(rows, event.target);
|
|
179
|
+
if (position === null)
|
|
180
|
+
return;
|
|
181
|
+
setRovingTabindex(rows, stopAt(rows, position));
|
|
182
|
+
}),
|
|
183
|
+
on("keydown", (event) => {
|
|
184
|
+
if (hostNode === undefined)
|
|
185
|
+
return;
|
|
186
|
+
let rows = queryRows(hostNode);
|
|
187
|
+
if (rows.length === 0)
|
|
188
|
+
return;
|
|
189
|
+
let position = locate(rows, event.target);
|
|
190
|
+
if (position === null)
|
|
191
|
+
return;
|
|
192
|
+
let { rowIndex, cellIndex } = position;
|
|
193
|
+
let row = rows[rowIndex];
|
|
194
|
+
switch (event.key) {
|
|
195
|
+
case "ArrowDown": {
|
|
196
|
+
let next = rows[rowIndex + 1];
|
|
197
|
+
if (!next)
|
|
198
|
+
return;
|
|
199
|
+
event.preventDefault();
|
|
200
|
+
focusElement(rows, next);
|
|
201
|
+
if (event.shiftKey)
|
|
202
|
+
model.selectRange(resolveKey(model, rowKeyOf(next)));
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
case "ArrowUp": {
|
|
206
|
+
let previous = rows[rowIndex - 1];
|
|
207
|
+
if (!previous)
|
|
208
|
+
return;
|
|
209
|
+
event.preventDefault();
|
|
210
|
+
focusElement(rows, previous);
|
|
211
|
+
if (event.shiftKey)
|
|
212
|
+
model.selectRange(resolveKey(model, rowKeyOf(previous)));
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
case "ArrowRight": {
|
|
216
|
+
let cells = queryCells(row);
|
|
217
|
+
if (cells.length === 0)
|
|
218
|
+
return;
|
|
219
|
+
event.preventDefault();
|
|
220
|
+
let nextIndex = cellIndex === null ? 0 : Math.min(cellIndex + 1, cells.length - 1);
|
|
221
|
+
focusElement(rows, cells[nextIndex]);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
case "ArrowLeft": {
|
|
225
|
+
if (cellIndex === null)
|
|
226
|
+
return;
|
|
227
|
+
event.preventDefault();
|
|
228
|
+
let cells = queryCells(row);
|
|
229
|
+
let destination = cellIndex === 0 ? row : cells[cellIndex - 1];
|
|
230
|
+
if (destination)
|
|
231
|
+
focusElement(rows, destination);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
case "Home":
|
|
235
|
+
event.preventDefault();
|
|
236
|
+
focusElement(rows, rows[0]);
|
|
237
|
+
return;
|
|
238
|
+
case "End":
|
|
239
|
+
event.preventDefault();
|
|
240
|
+
focusElement(rows, rows[rows.length - 1]);
|
|
241
|
+
return;
|
|
242
|
+
case " ":
|
|
243
|
+
if (cellIndex !== null)
|
|
244
|
+
return;
|
|
245
|
+
event.preventDefault();
|
|
246
|
+
model.toggle(resolveKey(model, rowKeyOf(row)));
|
|
247
|
+
return;
|
|
248
|
+
case "a":
|
|
249
|
+
case "A":
|
|
250
|
+
if (!(event.ctrlKey || event.metaKey))
|
|
251
|
+
return;
|
|
252
|
+
event.preventDefault();
|
|
253
|
+
model.selectAll();
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
}),
|
|
257
|
+
],
|
|
258
|
+
});
|
|
259
|
+
};
|
|
260
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why JS: recovering an ambient level across an independently-hydrated
|
|
3
|
+
* island requires reading the DOM, which pure components cannot do.
|
|
4
|
+
* No-JS baseline: the server-rendered tag, computed from the real ambient
|
|
5
|
+
* level during SSR, is already correct and is what stays on the page if
|
|
6
|
+
* this mixin never runs.
|
|
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 { HeadingLevel } from "../components/heading-scope.js";
|
|
13
|
+
/**
|
|
14
|
+
* Types associated with {@link headingLevelFallback}.
|
|
15
|
+
*/
|
|
16
|
+
export declare namespace HeadingLevelFallback {
|
|
17
|
+
/**
|
|
18
|
+
* Configuration accepted by {@link headingLevelFallback}.
|
|
19
|
+
*/
|
|
20
|
+
interface Options {
|
|
21
|
+
/**
|
|
22
|
+
* Called once, on attach, with the ancestor level clamped to the native
|
|
23
|
+
* `1`–`6` range. Never called when no ancestor carries
|
|
24
|
+
* {@link HEADING_LEVEL_ATTRIBUTE} or its value is unparsable.
|
|
25
|
+
*/
|
|
26
|
+
onLevel: (level: HeadingLevel) => void;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Safety net for an independently-hydrated island whose root didn't get its
|
|
31
|
+
* ambient level threaded in as a `level` prop. Detects the nearest
|
|
32
|
+
* ancestor's resolved level and reports it through `options.onLevel`.
|
|
33
|
+
*
|
|
34
|
+
* @param options Callback the recovered level is reported through; see {@link HeadingLevelFallback.Options}.
|
|
35
|
+
* @returns A mixin descriptor for an island's outermost `HeadingScope` or `Heading` root's `mix` prop.
|
|
36
|
+
* @example
|
|
37
|
+
* // An island whose root is a HeadingScope wrapping further content.
|
|
38
|
+
* function CommentsIsland(handle: Handle) {
|
|
39
|
+
* let level: HeadingLevel | undefined;
|
|
40
|
+
*
|
|
41
|
+
* return () => (
|
|
42
|
+
* <HeadingScope
|
|
43
|
+
* level={level}
|
|
44
|
+
* mix={[
|
|
45
|
+
* headingLevelFallback({
|
|
46
|
+
* onLevel(detected) {
|
|
47
|
+
* level = detected;
|
|
48
|
+
* handle.update();
|
|
49
|
+
* },
|
|
50
|
+
* }),
|
|
51
|
+
* ]}
|
|
52
|
+
* >
|
|
53
|
+
* <Heading>Comments</Heading>
|
|
54
|
+
* </HeadingScope>
|
|
55
|
+
* );
|
|
56
|
+
* }
|
|
57
|
+
* @example
|
|
58
|
+
* // An island whose root is a lone Heading.
|
|
59
|
+
* function SectionTitleIsland(handle: Handle) {
|
|
60
|
+
* let level: HeadingLevel | undefined;
|
|
61
|
+
*
|
|
62
|
+
* return () => (
|
|
63
|
+
* <Heading
|
|
64
|
+
* level={level}
|
|
65
|
+
* mix={[
|
|
66
|
+
* headingLevelFallback({
|
|
67
|
+
* onLevel(detected) {
|
|
68
|
+
* level = detected;
|
|
69
|
+
* handle.update();
|
|
70
|
+
* },
|
|
71
|
+
* }),
|
|
72
|
+
* ]}
|
|
73
|
+
* >
|
|
74
|
+
* Related articles
|
|
75
|
+
* </Heading>
|
|
76
|
+
* );
|
|
77
|
+
* }
|
|
78
|
+
*/
|
|
79
|
+
export declare const headingLevelFallback: MixinFactory<HTMLElement, [
|
|
80
|
+
options: HeadingLevelFallback.Options
|
|
81
|
+
], ElementProps>;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why JS: recovering an ambient level across an independently-hydrated
|
|
3
|
+
* island requires reading the DOM, which pure components cannot do.
|
|
4
|
+
* No-JS baseline: the server-rendered tag, computed from the real ambient
|
|
5
|
+
* level during SSR, is already correct and is what stays on the page if
|
|
6
|
+
* this mixin never runs.
|
|
7
|
+
*
|
|
8
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
9
|
+
* @copyright Sergio Xalambrí 2026
|
|
10
|
+
*/
|
|
11
|
+
import { createMixin, ref } from "remix/ui";
|
|
12
|
+
/**
|
|
13
|
+
* Attribute every resolved `HeadingScope` and `Heading` carries with its own
|
|
14
|
+
* resolved depth. {@link headingLevelFallback} reads it off the nearest
|
|
15
|
+
* ancestor to recover an ambient level it can't reach through context.
|
|
16
|
+
*/
|
|
17
|
+
const HEADING_LEVEL_ATTRIBUTE = "data-heading-level";
|
|
18
|
+
/** Shallowest semantic depth the native heading elements support; a reading below this clamps up to it. */
|
|
19
|
+
const MIN_LEVEL = 1;
|
|
20
|
+
/** Deepest semantic depth the native heading elements support; a reading past this clamps down to it. */
|
|
21
|
+
const MAX_LEVEL = 6;
|
|
22
|
+
/**
|
|
23
|
+
* Clamps `value` into the native `1`–`6` heading range.
|
|
24
|
+
*
|
|
25
|
+
* @param value Parsed integer to clamp.
|
|
26
|
+
* @returns `value` unchanged where it already sits in range, otherwise the nearest bound.
|
|
27
|
+
*/
|
|
28
|
+
function clampLevel(value) {
|
|
29
|
+
return Math.min(MAX_LEVEL, Math.max(MIN_LEVEL, value));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Reads the nearest ancestor's resolved heading level off the DOM, searching
|
|
33
|
+
* upward from `node`'s parent when `node` itself already carries
|
|
34
|
+
* {@link HEADING_LEVEL_ATTRIBUTE}, so it finds the scope wrapping `node`.
|
|
35
|
+
*
|
|
36
|
+
* @param node Element to search upward from.
|
|
37
|
+
* @returns The nearest ancestor's clamped level, or `undefined` where no
|
|
38
|
+
* ancestor carries the attribute at all, or where its value is missing or
|
|
39
|
+
* unparsable.
|
|
40
|
+
*/
|
|
41
|
+
function readAncestorLevel(node) {
|
|
42
|
+
let searchRoot = node.hasAttribute(HEADING_LEVEL_ATTRIBUTE) ? node.parentElement : node;
|
|
43
|
+
if (!searchRoot)
|
|
44
|
+
return undefined;
|
|
45
|
+
let ancestor = searchRoot.closest(`[${HEADING_LEVEL_ATTRIBUTE}]`);
|
|
46
|
+
if (!ancestor)
|
|
47
|
+
return undefined;
|
|
48
|
+
let raw = ancestor.getAttribute(HEADING_LEVEL_ATTRIBUTE);
|
|
49
|
+
if (raw === null)
|
|
50
|
+
return undefined;
|
|
51
|
+
let parsed = Number.parseInt(raw, 10);
|
|
52
|
+
if (Number.isNaN(parsed))
|
|
53
|
+
return undefined;
|
|
54
|
+
return clampLevel(parsed);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Safety net for an independently-hydrated island whose root didn't get its
|
|
58
|
+
* ambient level threaded in as a `level` prop. Detects the nearest
|
|
59
|
+
* ancestor's resolved level and reports it through `options.onLevel`.
|
|
60
|
+
*
|
|
61
|
+
* @param options Callback the recovered level is reported through; see {@link HeadingLevelFallback.Options}.
|
|
62
|
+
* @returns A mixin descriptor for an island's outermost `HeadingScope` or `Heading` root's `mix` prop.
|
|
63
|
+
* @example
|
|
64
|
+
* // An island whose root is a HeadingScope wrapping further content.
|
|
65
|
+
* function CommentsIsland(handle: Handle) {
|
|
66
|
+
* let level: HeadingLevel | undefined;
|
|
67
|
+
*
|
|
68
|
+
* return () => (
|
|
69
|
+
* <HeadingScope
|
|
70
|
+
* level={level}
|
|
71
|
+
* mix={[
|
|
72
|
+
* headingLevelFallback({
|
|
73
|
+
* onLevel(detected) {
|
|
74
|
+
* level = detected;
|
|
75
|
+
* handle.update();
|
|
76
|
+
* },
|
|
77
|
+
* }),
|
|
78
|
+
* ]}
|
|
79
|
+
* >
|
|
80
|
+
* <Heading>Comments</Heading>
|
|
81
|
+
* </HeadingScope>
|
|
82
|
+
* );
|
|
83
|
+
* }
|
|
84
|
+
* @example
|
|
85
|
+
* // An island whose root is a lone Heading.
|
|
86
|
+
* function SectionTitleIsland(handle: Handle) {
|
|
87
|
+
* let level: HeadingLevel | undefined;
|
|
88
|
+
*
|
|
89
|
+
* return () => (
|
|
90
|
+
* <Heading
|
|
91
|
+
* level={level}
|
|
92
|
+
* mix={[
|
|
93
|
+
* headingLevelFallback({
|
|
94
|
+
* onLevel(detected) {
|
|
95
|
+
* level = detected;
|
|
96
|
+
* handle.update();
|
|
97
|
+
* },
|
|
98
|
+
* }),
|
|
99
|
+
* ]}
|
|
100
|
+
* >
|
|
101
|
+
* Related articles
|
|
102
|
+
* </Heading>
|
|
103
|
+
* );
|
|
104
|
+
* }
|
|
105
|
+
*/
|
|
106
|
+
export const headingLevelFallback = createMixin((_handle) => {
|
|
107
|
+
return (options) => ref((host) => {
|
|
108
|
+
let level = readAncestorLevel(host);
|
|
109
|
+
if (level !== undefined)
|
|
110
|
+
options.onLevel(level);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global keyboard-shortcut mixin for a Command dialog or any dialog/popover
|
|
3
|
+
* host: opens the host when a key combination strikes anywhere in the
|
|
4
|
+
* document, and closes it again on the same combination while it's already
|
|
5
|
+
* open, adapting to whichever native open API the host exposes.
|
|
6
|
+
*
|
|
7
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
8
|
+
* @copyright Sergio Xalambrí 2026
|
|
9
|
+
*/
|
|
10
|
+
import type { MixinFactory } from "remix/ui";
|
|
11
|
+
/**
|
|
12
|
+
* Opens the host when `combo` is struck anywhere in the document while it's
|
|
13
|
+
* closed, and closes it again on the same combo while it's already open,
|
|
14
|
+
* driving the host's own native `<dialog>` or `[popover]` open state.
|
|
15
|
+
*
|
|
16
|
+
* @param combo Key combination that opens or closes the host, e.g. `"mod+k"`.
|
|
17
|
+
* @example
|
|
18
|
+
* <dialog id="command-palette" mix={[hotkey("mod+k")]}>
|
|
19
|
+
* <Command>...</Command>
|
|
20
|
+
* </dialog>
|
|
21
|
+
* @example
|
|
22
|
+
* <div id="quick-switcher" popover="manual" mix={[hotkey("mod+shift+k")]}>
|
|
23
|
+
* ...
|
|
24
|
+
* </div>
|
|
25
|
+
*/
|
|
26
|
+
export declare const hotkey: MixinFactory<HTMLElement, [combo: string]>;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global keyboard-shortcut mixin for a Command dialog or any dialog/popover
|
|
3
|
+
* host: opens the host when a key combination strikes anywhere in the
|
|
4
|
+
* document, and closes it again on the same combination while it's already
|
|
5
|
+
* open, adapting to whichever native open API the host exposes.
|
|
6
|
+
*
|
|
7
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
8
|
+
* @copyright Sergio Xalambrí 2026
|
|
9
|
+
*/
|
|
10
|
+
import { createMixin } from "remix/ui";
|
|
11
|
+
import { trackHostNode } from "./track-host-node.js";
|
|
12
|
+
/** Modifier token spellings {@link parseCombo} resolves to the platform's primary modifier, checked as `event.ctrlKey || event.metaKey`. */
|
|
13
|
+
const MOD_ALIASES = new Set(["mod", "ctrl", "control", "cmd", "command", "meta"]);
|
|
14
|
+
/** Modifier token spellings {@link parseCombo} resolves to `event.altKey`. */
|
|
15
|
+
const ALT_ALIASES = new Set(["alt", "option"]);
|
|
16
|
+
/** Modifier token spelling {@link parseCombo} resolves to `event.shiftKey`. */
|
|
17
|
+
const SHIFT_ALIAS = "shift";
|
|
18
|
+
/**
|
|
19
|
+
* Parses a `+`-joined combo string (`"mod+k"`, `"mod+shift+p"`) into the
|
|
20
|
+
* modifier flags and literal trigger key {@link matchesCombo} compares a
|
|
21
|
+
* `keydown` event against, matching tokens case-insensitively.
|
|
22
|
+
*
|
|
23
|
+
* @param combo Combo string as passed to {@link hotkey}.
|
|
24
|
+
* @returns The parsed modifier flags and trigger key.
|
|
25
|
+
*/
|
|
26
|
+
function parseCombo(combo) {
|
|
27
|
+
let tokens = combo
|
|
28
|
+
.split("+")
|
|
29
|
+
.map((token) => token.trim().toLowerCase())
|
|
30
|
+
.filter((token) => token.length > 0);
|
|
31
|
+
let key = tokens.at(-1) ?? "";
|
|
32
|
+
let modifiers = tokens.slice(0, -1);
|
|
33
|
+
if (key === "" && import.meta.env.DEV) {
|
|
34
|
+
console.warn(`hotkey(): "${combo}" has no trigger key and will never match.`);
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
key,
|
|
38
|
+
mod: modifiers.some((token) => MOD_ALIASES.has(token)),
|
|
39
|
+
alt: modifiers.some((token) => ALT_ALIASES.has(token)),
|
|
40
|
+
shift: modifiers.includes(SHIFT_ALIAS),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Reports whether `event` strikes exactly the key and modifier combination
|
|
45
|
+
* `combo` describes, requiring every modifier `combo` lists and none it
|
|
46
|
+
* doesn't, so a combo never fires on a superset chord.
|
|
47
|
+
*
|
|
48
|
+
* @param event `keydown` event observed on the document.
|
|
49
|
+
* @param combo Parsed combo to compare `event` against.
|
|
50
|
+
* @returns Whether `event` is an exact match for `combo`.
|
|
51
|
+
*/
|
|
52
|
+
function matchesCombo(event, combo) {
|
|
53
|
+
if (event.key.toLowerCase() !== combo.key)
|
|
54
|
+
return false;
|
|
55
|
+
if ((event.ctrlKey || event.metaKey) !== combo.mod)
|
|
56
|
+
return false;
|
|
57
|
+
if (event.altKey !== combo.alt)
|
|
58
|
+
return false;
|
|
59
|
+
if (event.shiftKey !== combo.shift)
|
|
60
|
+
return false;
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Reads `host`'s current native open state: `HTMLDialogElement.open` for a
|
|
65
|
+
* `<dialog>`, or the `:popover-open` pseudo-class for anything else.
|
|
66
|
+
*
|
|
67
|
+
* @param host Element {@link hotkey} is mixed onto.
|
|
68
|
+
* @returns Whether `host` is currently showing.
|
|
69
|
+
*/
|
|
70
|
+
function isOpen(host) {
|
|
71
|
+
if (host instanceof HTMLDialogElement)
|
|
72
|
+
return host.open;
|
|
73
|
+
return host.matches(":popover-open");
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Drives `host` to `open`, through whichever native API applies —
|
|
77
|
+
* `showModal()`/`close()` for a `<dialog>`, `showPopover()`/`hidePopover()`
|
|
78
|
+
* for an element carrying the `popover` attribute.
|
|
79
|
+
*
|
|
80
|
+
* @param host Element {@link hotkey} is mixed onto.
|
|
81
|
+
* @param open Target open state.
|
|
82
|
+
*/
|
|
83
|
+
function setOpen(host, open) {
|
|
84
|
+
if (host instanceof HTMLDialogElement) {
|
|
85
|
+
if (open)
|
|
86
|
+
host.showModal();
|
|
87
|
+
else
|
|
88
|
+
host.close();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (!host.hasAttribute("popover")) {
|
|
92
|
+
if (import.meta.env.DEV) {
|
|
93
|
+
console.warn(`hotkey(): host is neither a <dialog> nor a [popover] element, so it cannot be ${open ? "shown" : "hidden"}.`);
|
|
94
|
+
}
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (open)
|
|
98
|
+
host.showPopover();
|
|
99
|
+
else
|
|
100
|
+
host.hidePopover();
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Opens the host when `combo` is struck anywhere in the document while it's
|
|
104
|
+
* closed, and closes it again on the same combo while it's already open,
|
|
105
|
+
* driving the host's own native `<dialog>` or `[popover]` open state.
|
|
106
|
+
*
|
|
107
|
+
* @param combo Key combination that opens or closes the host, e.g. `"mod+k"`.
|
|
108
|
+
* @example
|
|
109
|
+
* <dialog id="command-palette" mix={[hotkey("mod+k")]}>
|
|
110
|
+
* <Command>...</Command>
|
|
111
|
+
* </dialog>
|
|
112
|
+
* @example
|
|
113
|
+
* <div id="quick-switcher" popover="manual" mix={[hotkey("mod+shift+k")]}>
|
|
114
|
+
* ...
|
|
115
|
+
* </div>
|
|
116
|
+
*/
|
|
117
|
+
export const hotkey = createMixin((handle) => {
|
|
118
|
+
let getHostNode = trackHostNode(handle);
|
|
119
|
+
let parsed;
|
|
120
|
+
document.addEventListener("keydown", (event) => {
|
|
121
|
+
let hostNode = getHostNode();
|
|
122
|
+
if (hostNode === undefined || parsed === undefined)
|
|
123
|
+
return;
|
|
124
|
+
if (event.repeat || !matchesCombo(event, parsed))
|
|
125
|
+
return;
|
|
126
|
+
event.preventDefault();
|
|
127
|
+
setOpen(hostNode, !isOpen(hostNode));
|
|
128
|
+
}, { signal: handle.signal });
|
|
129
|
+
return (combo) => {
|
|
130
|
+
parsed = parseCombo(combo);
|
|
131
|
+
};
|
|
132
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
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 type { MixinFactory } 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 declare 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
|
+
declare const IMAGE_FALLBACK_EVENT: "ui:image-fallback";
|
|
19
|
+
declare global {
|
|
20
|
+
interface HTMLElementEventMap {
|
|
21
|
+
[IMAGE_FALLBACK_EVENT]: ImageFallbackEvent;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Dispatched on an Avatar or Logo image by {@link imageFallback} whenever
|
|
26
|
+
* loading it succeeds or fails, so a consumer can react without polling
|
|
27
|
+
* {@link IMAGE_ERROR_ATTRIBUTE} off the DOM itself.
|
|
28
|
+
*/
|
|
29
|
+
export declare class ImageFallbackEvent extends Event {
|
|
30
|
+
/** `true` once the image has failed to load and its fallback is now revealed, `false` once it loads successfully. */
|
|
31
|
+
readonly fallback: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* @param fallback Whether the image's fallback is now revealed.
|
|
34
|
+
*/
|
|
35
|
+
constructor(fallback: boolean);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Sets or clears {@link IMAGE_ERROR_ATTRIBUTE} on an Avatar or Logo image
|
|
39
|
+
* on load, error, and mount — mount also checks `complete`/`naturalWidth`
|
|
40
|
+
* since an already-cached image never fires either event again.
|
|
41
|
+
*
|
|
42
|
+
* @returns A mixin descriptor for an Avatar or Logo image's `mix` prop.
|
|
43
|
+
* @example
|
|
44
|
+
* <div mix={[css({ position: "relative", display: "inline-grid" })]}>
|
|
45
|
+
* <span mix={[css({ gridArea: "1 / 1" })]}>{initials}</span>
|
|
46
|
+
* <img
|
|
47
|
+
* src={avatarUrl}
|
|
48
|
+
* alt={name}
|
|
49
|
+
* mix={[
|
|
50
|
+
* imageFallback(),
|
|
51
|
+
* css({ gridArea: "1 / 1", "&[data-image-error]": { display: "none" } }),
|
|
52
|
+
* ]}
|
|
53
|
+
* />
|
|
54
|
+
* </div>
|
|
55
|
+
*/
|
|
56
|
+
export declare const imageFallback: MixinFactory<HTMLImageElement>;
|
|
57
|
+
export {};
|