@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,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless filtering model for search-as-you-type option lists such as a
|
|
3
|
+
* command palette. Owns the query string, the matched subset of options, and
|
|
4
|
+
* which match is active, dispatching a plain `"change"` event whenever any of
|
|
5
|
+
* the three moves so a DOM adapter re-renders from this single source.
|
|
6
|
+
*
|
|
7
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
8
|
+
* @copyright Sergio Xalambrí 2026
|
|
9
|
+
*/
|
|
10
|
+
import { TypedEventTarget } from "remix/ui";
|
|
11
|
+
/**
|
|
12
|
+
* Types associated with {@link FilterModel}: the option shape it filters
|
|
13
|
+
* over, its construction options, and the event it dispatches.
|
|
14
|
+
*/
|
|
15
|
+
export declare namespace FilterModel {
|
|
16
|
+
/**
|
|
17
|
+
* One filterable option. `id` is the stable key a consumer uses to
|
|
18
|
+
* correlate a rendered item with matched/active state; `value` and
|
|
19
|
+
* `keywords` are the text compared against the query.
|
|
20
|
+
*/
|
|
21
|
+
interface Option {
|
|
22
|
+
/** Stable identifier correlated with a rendered item. */
|
|
23
|
+
id: string;
|
|
24
|
+
/** Primary text compared against the query. */
|
|
25
|
+
value: string;
|
|
26
|
+
/** Additional search terms folded into matching alongside `value`. */
|
|
27
|
+
keywords?: readonly string[];
|
|
28
|
+
}
|
|
29
|
+
/** Construction options accepted by {@link FilterModel}. */
|
|
30
|
+
interface Init {
|
|
31
|
+
/** Initial option set the model filters over. Defaults to none. */
|
|
32
|
+
options?: Iterable<Option>;
|
|
33
|
+
/** Initial query string. Defaults to an empty string. */
|
|
34
|
+
query?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Overrides the default case-insensitive substring match against
|
|
37
|
+
* `value` and `keywords`.
|
|
38
|
+
*/
|
|
39
|
+
match?: (option: Option, query: string) => boolean;
|
|
40
|
+
}
|
|
41
|
+
/** Events dispatched by {@link FilterModel} as its state changes. */
|
|
42
|
+
interface EventMap {
|
|
43
|
+
/** Dispatched whenever the query, the matched set, or the active option changes. */
|
|
44
|
+
change: Event;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Owns the query, the matched option set, and the active match for a
|
|
49
|
+
* filterable list, dispatching `"change"` whenever any of the three moves, so
|
|
50
|
+
* a DOM adapter stays a thin layer forwarding input and reading state back.
|
|
51
|
+
*/
|
|
52
|
+
export declare class FilterModel extends TypedEventTarget<FilterModel.EventMap> {
|
|
53
|
+
#private;
|
|
54
|
+
/**
|
|
55
|
+
* @param init Initial options, query, and match override.
|
|
56
|
+
*/
|
|
57
|
+
constructor(init?: FilterModel.Init);
|
|
58
|
+
/** Current query string filtering the option set. */
|
|
59
|
+
get query(): string;
|
|
60
|
+
/** Full option set the model filters over, in the order last provided. */
|
|
61
|
+
get options(): readonly FilterModel.Option[];
|
|
62
|
+
/** Options whose value or keywords currently match the query, in their original order. */
|
|
63
|
+
get matches(): readonly FilterModel.Option[];
|
|
64
|
+
/** Id of the currently active match, or `null` when nothing is active. */
|
|
65
|
+
get activeId(): string | null;
|
|
66
|
+
/** The active match's full option, or `null` when nothing is active. */
|
|
67
|
+
get activeOption(): FilterModel.Option | null;
|
|
68
|
+
/** `true` when the current query has no matches. */
|
|
69
|
+
get isEmpty(): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Replaces the option set and recomputes matches against the current
|
|
72
|
+
* query, keeping the active option while it still matches and falling back
|
|
73
|
+
* to the first match otherwise. Always dispatches `"change"`.
|
|
74
|
+
*
|
|
75
|
+
* @param options The full replacement option set.
|
|
76
|
+
*/
|
|
77
|
+
setOptions(options: Iterable<FilterModel.Option>): void;
|
|
78
|
+
/**
|
|
79
|
+
* Updates the query and recomputes matches, keeping the active option
|
|
80
|
+
* while it still matches and falling back to the first match otherwise. A
|
|
81
|
+
* no-op when `query` equals the current query.
|
|
82
|
+
*
|
|
83
|
+
* @param query The new query string.
|
|
84
|
+
*/
|
|
85
|
+
setQuery(query: string): void;
|
|
86
|
+
/**
|
|
87
|
+
* Reports whether an option id is part of the current matched set.
|
|
88
|
+
*
|
|
89
|
+
* @param id Option id to test.
|
|
90
|
+
* @returns `true` when the option with that id currently matches the query.
|
|
91
|
+
*/
|
|
92
|
+
isMatch(id: string): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Sets the active option explicitly. An `id` outside the current matches
|
|
95
|
+
* is ignored, so the active option always stays a visible match.
|
|
96
|
+
* Dispatches `"change"` only when the active id actually changes.
|
|
97
|
+
*
|
|
98
|
+
* @param id Id of the option to activate, or `null` to clear activation.
|
|
99
|
+
*/
|
|
100
|
+
setActive(id: string | null): void;
|
|
101
|
+
/**
|
|
102
|
+
* Moves activation to the match after the current one, wrapping to the
|
|
103
|
+
* first match after the last. Activates the first match when nothing is
|
|
104
|
+
* currently active.
|
|
105
|
+
*/
|
|
106
|
+
moveNext(): void;
|
|
107
|
+
/**
|
|
108
|
+
* Moves activation to the match before the current one, wrapping to the
|
|
109
|
+
* last match before the first. Activates the last match when nothing is
|
|
110
|
+
* currently active.
|
|
111
|
+
*/
|
|
112
|
+
movePrevious(): void;
|
|
113
|
+
/** Activates the first match, or clears activation when there are no matches. */
|
|
114
|
+
moveFirst(): void;
|
|
115
|
+
/** Activates the last match, or clears activation when there are no matches. */
|
|
116
|
+
moveLast(): void;
|
|
117
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless filtering model for search-as-you-type option lists such as a
|
|
3
|
+
* command palette. Owns the query string, the matched subset of options, and
|
|
4
|
+
* which match is active, dispatching a plain `"change"` event whenever any of
|
|
5
|
+
* the three moves so a DOM adapter re-renders from this single source.
|
|
6
|
+
*
|
|
7
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
8
|
+
* @copyright Sergio Xalambrí 2026
|
|
9
|
+
*/
|
|
10
|
+
import { TypedEventTarget } from "remix/ui";
|
|
11
|
+
import { dispatchChange } from "../utils/dispatch-change.js";
|
|
12
|
+
const DEFAULT_QUERY = "";
|
|
13
|
+
/**
|
|
14
|
+
* Default matcher: a case-insensitive substring test against an option's
|
|
15
|
+
* `value` and, when present, its `keywords`. An empty query matches every
|
|
16
|
+
* option.
|
|
17
|
+
*
|
|
18
|
+
* @param option Option under test.
|
|
19
|
+
* @param query Current query string.
|
|
20
|
+
* @returns `true` when the option should be part of the matched set.
|
|
21
|
+
*/
|
|
22
|
+
function defaultMatch(option, query) {
|
|
23
|
+
let needle = query.trim().toLowerCase();
|
|
24
|
+
if (needle === "")
|
|
25
|
+
return true;
|
|
26
|
+
if (option.value.toLowerCase().includes(needle))
|
|
27
|
+
return true;
|
|
28
|
+
if (option.keywords === undefined)
|
|
29
|
+
return false;
|
|
30
|
+
for (let keyword of option.keywords) {
|
|
31
|
+
if (keyword.toLowerCase().includes(needle))
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Owns the query, the matched option set, and the active match for a
|
|
38
|
+
* filterable list, dispatching `"change"` whenever any of the three moves, so
|
|
39
|
+
* a DOM adapter stays a thin layer forwarding input and reading state back.
|
|
40
|
+
*/
|
|
41
|
+
export class FilterModel extends TypedEventTarget {
|
|
42
|
+
#options;
|
|
43
|
+
#query;
|
|
44
|
+
#matches;
|
|
45
|
+
#activeId;
|
|
46
|
+
#match;
|
|
47
|
+
/**
|
|
48
|
+
* @param init Initial options, query, and match override.
|
|
49
|
+
*/
|
|
50
|
+
constructor(init = {}) {
|
|
51
|
+
super();
|
|
52
|
+
this.#match = init.match ?? defaultMatch;
|
|
53
|
+
this.#query = init.query ?? DEFAULT_QUERY;
|
|
54
|
+
this.#options = init.options ? Array.from(init.options) : [];
|
|
55
|
+
this.#matches = this.#options.filter((option) => this.#match(option, this.#query));
|
|
56
|
+
this.#activeId = this.#matches[0]?.id ?? null;
|
|
57
|
+
}
|
|
58
|
+
/** Current query string filtering the option set. */
|
|
59
|
+
get query() {
|
|
60
|
+
return this.#query;
|
|
61
|
+
}
|
|
62
|
+
/** Full option set the model filters over, in the order last provided. */
|
|
63
|
+
get options() {
|
|
64
|
+
return this.#options;
|
|
65
|
+
}
|
|
66
|
+
/** Options whose value or keywords currently match the query, in their original order. */
|
|
67
|
+
get matches() {
|
|
68
|
+
return this.#matches;
|
|
69
|
+
}
|
|
70
|
+
/** Id of the currently active match, or `null` when nothing is active. */
|
|
71
|
+
get activeId() {
|
|
72
|
+
return this.#activeId;
|
|
73
|
+
}
|
|
74
|
+
/** The active match's full option, or `null` when nothing is active. */
|
|
75
|
+
get activeOption() {
|
|
76
|
+
return this.#matches.find((option) => option.id === this.#activeId) ?? null;
|
|
77
|
+
}
|
|
78
|
+
/** `true` when the current query has no matches. */
|
|
79
|
+
get isEmpty() {
|
|
80
|
+
return this.#matches.length === 0;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Replaces the option set and recomputes matches against the current
|
|
84
|
+
* query, keeping the active option while it still matches and falling back
|
|
85
|
+
* to the first match otherwise. Always dispatches `"change"`.
|
|
86
|
+
*
|
|
87
|
+
* @param options The full replacement option set.
|
|
88
|
+
*/
|
|
89
|
+
setOptions(options) {
|
|
90
|
+
this.#options = Array.from(options);
|
|
91
|
+
this.#recomputeMatches();
|
|
92
|
+
this.#activeId = this.#resolveActiveId();
|
|
93
|
+
dispatchChange(this);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Updates the query and recomputes matches, keeping the active option
|
|
97
|
+
* while it still matches and falling back to the first match otherwise. A
|
|
98
|
+
* no-op when `query` equals the current query.
|
|
99
|
+
*
|
|
100
|
+
* @param query The new query string.
|
|
101
|
+
*/
|
|
102
|
+
setQuery(query) {
|
|
103
|
+
if (query === this.#query)
|
|
104
|
+
return;
|
|
105
|
+
this.#query = query;
|
|
106
|
+
this.#recomputeMatches();
|
|
107
|
+
this.#activeId = this.#resolveActiveId();
|
|
108
|
+
dispatchChange(this);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Reports whether an option id is part of the current matched set.
|
|
112
|
+
*
|
|
113
|
+
* @param id Option id to test.
|
|
114
|
+
* @returns `true` when the option with that id currently matches the query.
|
|
115
|
+
*/
|
|
116
|
+
isMatch(id) {
|
|
117
|
+
return this.#matches.some((option) => option.id === id);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Sets the active option explicitly. An `id` outside the current matches
|
|
121
|
+
* is ignored, so the active option always stays a visible match.
|
|
122
|
+
* Dispatches `"change"` only when the active id actually changes.
|
|
123
|
+
*
|
|
124
|
+
* @param id Id of the option to activate, or `null` to clear activation.
|
|
125
|
+
*/
|
|
126
|
+
setActive(id) {
|
|
127
|
+
if (id !== null && !this.isMatch(id))
|
|
128
|
+
return;
|
|
129
|
+
this.#setActiveId(id);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Moves activation to the match after the current one, wrapping to the
|
|
133
|
+
* first match after the last. Activates the first match when nothing is
|
|
134
|
+
* currently active.
|
|
135
|
+
*/
|
|
136
|
+
moveNext() {
|
|
137
|
+
this.#moveBy(1);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Moves activation to the match before the current one, wrapping to the
|
|
141
|
+
* last match before the first. Activates the last match when nothing is
|
|
142
|
+
* currently active.
|
|
143
|
+
*/
|
|
144
|
+
movePrevious() {
|
|
145
|
+
this.#moveBy(-1);
|
|
146
|
+
}
|
|
147
|
+
/** Activates the first match, or clears activation when there are no matches. */
|
|
148
|
+
moveFirst() {
|
|
149
|
+
this.#setActiveId(this.#matches[0]?.id ?? null);
|
|
150
|
+
}
|
|
151
|
+
/** Activates the last match, or clears activation when there are no matches. */
|
|
152
|
+
moveLast() {
|
|
153
|
+
this.#setActiveId(this.#matches.at(-1)?.id ?? null);
|
|
154
|
+
}
|
|
155
|
+
#recomputeMatches() {
|
|
156
|
+
this.#matches = this.#options.filter((option) => this.#match(option, this.#query));
|
|
157
|
+
}
|
|
158
|
+
#resolveActiveId() {
|
|
159
|
+
if (this.#activeId !== null && this.isMatch(this.#activeId))
|
|
160
|
+
return this.#activeId;
|
|
161
|
+
return this.#matches[0]?.id ?? null;
|
|
162
|
+
}
|
|
163
|
+
#moveBy(delta) {
|
|
164
|
+
if (this.#matches.length === 0) {
|
|
165
|
+
this.#setActiveId(null);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
let index = this.#matches.findIndex((option) => option.id === this.#activeId);
|
|
169
|
+
let nextIndex = index === -1
|
|
170
|
+
? delta > 0
|
|
171
|
+
? 0
|
|
172
|
+
: this.#matches.length - 1
|
|
173
|
+
: (index + delta + this.#matches.length) % this.#matches.length;
|
|
174
|
+
let nextOption = this.#matches[nextIndex];
|
|
175
|
+
if (nextOption === undefined)
|
|
176
|
+
return;
|
|
177
|
+
this.#setActiveId(nextOption.id);
|
|
178
|
+
}
|
|
179
|
+
#setActiveId(id) {
|
|
180
|
+
if (id === this.#activeId)
|
|
181
|
+
return;
|
|
182
|
+
this.#activeId = id;
|
|
183
|
+
dispatchChange(this);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Barrel for headless behavior classes: `TypedEventTarget`-based state
|
|
3
|
+
* models that own interaction logic in script and stay decoupled from
|
|
4
|
+
* rendering, so components compose them independently.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
export * from "./announcer.js";
|
|
10
|
+
export * from "./calendar-model.js";
|
|
11
|
+
export * from "./drag-session.js";
|
|
12
|
+
export * from "./filter-model.js";
|
|
13
|
+
export * from "./resize-session.js";
|
|
14
|
+
export * from "./scroll-follow-model.js";
|
|
15
|
+
export * from "./selection-model.js";
|
|
16
|
+
export * from "./toaster.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Barrel for headless behavior classes: `TypedEventTarget`-based state
|
|
3
|
+
* models that own interaction logic in script and stay decoupled from
|
|
4
|
+
* rendering, so components compose them independently.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
export * from "./announcer.js";
|
|
10
|
+
export * from "./calendar-model.js";
|
|
11
|
+
export * from "./drag-session.js";
|
|
12
|
+
export * from "./filter-model.js";
|
|
13
|
+
export * from "./resize-session.js";
|
|
14
|
+
export * from "./scroll-follow-model.js";
|
|
15
|
+
export * from "./selection-model.js";
|
|
16
|
+
export * from "./toaster.js";
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless pointer-resize engine backing the `resizeHandle(axis)` mixin. Owns
|
|
3
|
+
* the active pointer session for a resizable panel group and solves min/max
|
|
4
|
+
* size constraints across every panel whenever the dragged boundary moves,
|
|
5
|
+
* so the mixin only has to forward pointer coordinates and read back sizes.
|
|
6
|
+
*
|
|
7
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
8
|
+
* @copyright Sergio Xalambrí 2026
|
|
9
|
+
*/
|
|
10
|
+
import { TypedEventTarget } from "remix/ui";
|
|
11
|
+
/**
|
|
12
|
+
* Types describing the panel group a `ResizeSession` operates over, and the
|
|
13
|
+
* events it dispatches.
|
|
14
|
+
*/
|
|
15
|
+
export declare namespace ResizeSession {
|
|
16
|
+
/**
|
|
17
|
+
* A panel as supplied to `start()`: its current size and, optionally, the
|
|
18
|
+
* size constraints the solver must respect. `size`, `min`, and `max` are
|
|
19
|
+
* all expressed as percentages of the panel group's main-axis size (0-100).
|
|
20
|
+
*/
|
|
21
|
+
interface PanelInput {
|
|
22
|
+
/** Stable identifier the consumer uses to map a resolved size back to its panel element. */
|
|
23
|
+
id: string;
|
|
24
|
+
/** Current size, as a percentage of the group's main-axis size. */
|
|
25
|
+
size: number;
|
|
26
|
+
/** Smallest percentage this panel may shrink to. Defaults to 0 when omitted. */
|
|
27
|
+
min?: number;
|
|
28
|
+
/** Largest percentage this panel may grow to. Defaults to 100 when omitted. */
|
|
29
|
+
max?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A panel's resolved state as read from an in-progress or finished session:
|
|
33
|
+
* `min` and `max` are always concrete, defaulted values.
|
|
34
|
+
*/
|
|
35
|
+
interface Panel {
|
|
36
|
+
/** Stable identifier, carried over unchanged from the matching `PanelInput`. */
|
|
37
|
+
id: string;
|
|
38
|
+
/** Current size, as a percentage of the group's main-axis size. */
|
|
39
|
+
size: number;
|
|
40
|
+
/** Smallest percentage this panel may shrink to. */
|
|
41
|
+
min: number;
|
|
42
|
+
/** Largest percentage this panel may grow to. */
|
|
43
|
+
max: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Snapshot passed to `start()`: the panel group's layout and constraints at
|
|
47
|
+
* the moment a pointer session begins on one of its handles.
|
|
48
|
+
*/
|
|
49
|
+
interface StartOptions {
|
|
50
|
+
/** Index of the handle being dragged; it sits between `panels[handleIndex]` and `panels[handleIndex + 1]`. */
|
|
51
|
+
handleIndex: number;
|
|
52
|
+
/** Every panel in the group, in visual order along the resize axis. */
|
|
53
|
+
panels: readonly PanelInput[];
|
|
54
|
+
/** Pointer coordinate along the resize axis (`clientX` for a horizontal group, `clientY` for a vertical one) at pointer-down. */
|
|
55
|
+
pointerPosition: number;
|
|
56
|
+
/** Size, in pixels, of the panel group measured along the resize axis — used to convert pixel pointer deltas into percentage units. */
|
|
57
|
+
groupSize: number;
|
|
58
|
+
}
|
|
59
|
+
/** Events a `ResizeSession` dispatches; read the `panels` getter for the state behind each one. */
|
|
60
|
+
interface Events {
|
|
61
|
+
/** Dispatched whenever constraint solving produces new panel sizes, from a pointer move or a cancelled session reverting. */
|
|
62
|
+
change: Event;
|
|
63
|
+
/** Dispatched once a session concludes, whether by `end()` or `cancel()`. */
|
|
64
|
+
end: Event;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Owns one resizable panel group's active pointer session. `move()` re-solves
|
|
69
|
+
* every panel's size from the constraints captured at `start()`, cascading
|
|
70
|
+
* into further panels so a drag only takes what the group can give up.
|
|
71
|
+
*/
|
|
72
|
+
export declare class ResizeSession extends TypedEventTarget<ResizeSession.Events> {
|
|
73
|
+
#private;
|
|
74
|
+
/** Whether a pointer session is in progress between `start()` and `end()`. */
|
|
75
|
+
get isActive(): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Index of the handle being dragged in the active session, or `null` when no session is active.
|
|
78
|
+
*/
|
|
79
|
+
get activeHandleIndex(): number | null;
|
|
80
|
+
/**
|
|
81
|
+
* Every panel's current resolved size and constraints, in group order.
|
|
82
|
+
* Returns a defensive copy on every read, so mutating the result never
|
|
83
|
+
* affects the session's own state.
|
|
84
|
+
*/
|
|
85
|
+
get panels(): readonly ResizeSession.Panel[];
|
|
86
|
+
/**
|
|
87
|
+
* Begins a pointer session on one handle of a panel group, capturing the
|
|
88
|
+
* panels' sizes and constraints as the baseline every subsequent `move()`
|
|
89
|
+
* in this session solves from.
|
|
90
|
+
*
|
|
91
|
+
* @param options Panel group snapshot and pointer-down position the session starts from.
|
|
92
|
+
* @throws {Error} When a session is already active; call `end()` or `cancel()` first.
|
|
93
|
+
* @throws {RangeError} When `panels` has fewer than two entries, or `handleIndex` has no adjacent panel pair.
|
|
94
|
+
*/
|
|
95
|
+
start(options: ResizeSession.StartOptions): void;
|
|
96
|
+
/**
|
|
97
|
+
* Re-solves every panel's size for the current pointer position and
|
|
98
|
+
* dispatches `change`. A no-op when no session is active, so a mixin can
|
|
99
|
+
* forward every `pointermove` without guarding on `isActive` itself.
|
|
100
|
+
*
|
|
101
|
+
* @param pointerPosition Current pointer coordinate along the resize axis.
|
|
102
|
+
*/
|
|
103
|
+
move(pointerPosition: number): void;
|
|
104
|
+
/**
|
|
105
|
+
* Concludes the active session, keeping the panels at their last solved
|
|
106
|
+
* sizes, and dispatches `end`. A no-op when no session is active.
|
|
107
|
+
*/
|
|
108
|
+
end(): void;
|
|
109
|
+
/**
|
|
110
|
+
* Aborts the active session, reverting every panel to the size it had when
|
|
111
|
+
* `start()` was called, then dispatches `change` (for the reverted sizes)
|
|
112
|
+
* followed by `end`. A no-op when no session is active.
|
|
113
|
+
*/
|
|
114
|
+
cancel(): void;
|
|
115
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless pointer-resize engine backing the `resizeHandle(axis)` mixin. Owns
|
|
3
|
+
* the active pointer session for a resizable panel group and solves min/max
|
|
4
|
+
* size constraints across every panel whenever the dragged boundary moves,
|
|
5
|
+
* so the mixin only has to forward pointer coordinates and read back sizes.
|
|
6
|
+
*
|
|
7
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
8
|
+
* @copyright Sergio Xalambrí 2026
|
|
9
|
+
*/
|
|
10
|
+
import { TypedEventTarget } from "remix/ui";
|
|
11
|
+
const DEFAULT_PANEL_MIN_SIZE = 0;
|
|
12
|
+
const DEFAULT_PANEL_MAX_SIZE = 100;
|
|
13
|
+
/**
|
|
14
|
+
* Owns one resizable panel group's active pointer session. `move()` re-solves
|
|
15
|
+
* every panel's size from the constraints captured at `start()`, cascading
|
|
16
|
+
* into further panels so a drag only takes what the group can give up.
|
|
17
|
+
*/
|
|
18
|
+
export class ResizeSession extends TypedEventTarget {
|
|
19
|
+
#panels = [];
|
|
20
|
+
#startPanels = [];
|
|
21
|
+
#handleIndex = -1;
|
|
22
|
+
#pointerStart = 0;
|
|
23
|
+
#groupSize = 0;
|
|
24
|
+
#active = false;
|
|
25
|
+
/** Whether a pointer session is in progress between `start()` and `end()`. */
|
|
26
|
+
get isActive() {
|
|
27
|
+
return this.#active;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Index of the handle being dragged in the active session, or `null` when no session is active.
|
|
31
|
+
*/
|
|
32
|
+
get activeHandleIndex() {
|
|
33
|
+
return this.#active ? this.#handleIndex : null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Every panel's current resolved size and constraints, in group order.
|
|
37
|
+
* Returns a defensive copy on every read, so mutating the result never
|
|
38
|
+
* affects the session's own state.
|
|
39
|
+
*/
|
|
40
|
+
get panels() {
|
|
41
|
+
return this.#panels.map((panel) => ({ ...panel }));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Begins a pointer session on one handle of a panel group, capturing the
|
|
45
|
+
* panels' sizes and constraints as the baseline every subsequent `move()`
|
|
46
|
+
* in this session solves from.
|
|
47
|
+
*
|
|
48
|
+
* @param options Panel group snapshot and pointer-down position the session starts from.
|
|
49
|
+
* @throws {Error} When a session is already active; call `end()` or `cancel()` first.
|
|
50
|
+
* @throws {RangeError} When `panels` has fewer than two entries, or `handleIndex` has no adjacent panel pair.
|
|
51
|
+
*/
|
|
52
|
+
start(options) {
|
|
53
|
+
if (this.#active) {
|
|
54
|
+
throw new Error("ResizeSession.start() was called while a session is already active; call end() or cancel() before starting another one.");
|
|
55
|
+
}
|
|
56
|
+
let { handleIndex, panels, pointerPosition, groupSize } = options;
|
|
57
|
+
if (panels.length < 2) {
|
|
58
|
+
throw new RangeError(`ResizeSession requires at least two panels to resize between, received ${panels.length}.`);
|
|
59
|
+
}
|
|
60
|
+
if (handleIndex < 0 || handleIndex > panels.length - 2) {
|
|
61
|
+
throw new RangeError(`handleIndex ${handleIndex} has no adjacent panel pair in a group of ${panels.length} panels.`);
|
|
62
|
+
}
|
|
63
|
+
this.#startPanels = panels.map((panel) => ({
|
|
64
|
+
id: panel.id,
|
|
65
|
+
size: panel.size,
|
|
66
|
+
min: panel.min ?? DEFAULT_PANEL_MIN_SIZE,
|
|
67
|
+
max: panel.max ?? DEFAULT_PANEL_MAX_SIZE,
|
|
68
|
+
}));
|
|
69
|
+
this.#panels = this.#startPanels.map((panel) => ({ ...panel }));
|
|
70
|
+
this.#handleIndex = handleIndex;
|
|
71
|
+
this.#pointerStart = pointerPosition;
|
|
72
|
+
this.#groupSize = groupSize;
|
|
73
|
+
this.#active = true;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Re-solves every panel's size for the current pointer position and
|
|
77
|
+
* dispatches `change`. A no-op when no session is active, so a mixin can
|
|
78
|
+
* forward every `pointermove` without guarding on `isActive` itself.
|
|
79
|
+
*
|
|
80
|
+
* @param pointerPosition Current pointer coordinate along the resize axis.
|
|
81
|
+
*/
|
|
82
|
+
move(pointerPosition) {
|
|
83
|
+
if (!this.#active)
|
|
84
|
+
return;
|
|
85
|
+
let pixelDelta = pointerPosition - this.#pointerStart;
|
|
86
|
+
let sizeDelta = this.#groupSize > 0 ? (pixelDelta / this.#groupSize) * 100 : 0;
|
|
87
|
+
this.#panels = this.#solve(sizeDelta);
|
|
88
|
+
this.dispatchEvent(new Event("change"));
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Concludes the active session, keeping the panels at their last solved
|
|
92
|
+
* sizes, and dispatches `end`. A no-op when no session is active.
|
|
93
|
+
*/
|
|
94
|
+
end() {
|
|
95
|
+
if (!this.#active)
|
|
96
|
+
return;
|
|
97
|
+
this.#active = false;
|
|
98
|
+
this.dispatchEvent(new Event("end"));
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Aborts the active session, reverting every panel to the size it had when
|
|
102
|
+
* `start()` was called, then dispatches `change` (for the reverted sizes)
|
|
103
|
+
* followed by `end`. A no-op when no session is active.
|
|
104
|
+
*/
|
|
105
|
+
cancel() {
|
|
106
|
+
if (!this.#active)
|
|
107
|
+
return;
|
|
108
|
+
this.#panels = this.#startPanels.map((panel) => ({ ...panel }));
|
|
109
|
+
this.#active = false;
|
|
110
|
+
this.dispatchEvent(new Event("change"));
|
|
111
|
+
this.dispatchEvent(new Event("end"));
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Solves fresh from the session's baseline each call, keeping repeated
|
|
115
|
+
* moves free of accumulated rounding drift. Growth is drawn from the
|
|
116
|
+
* nearest panels across the handle, clamped by headroom and donor supply.
|
|
117
|
+
*/
|
|
118
|
+
#solve(delta) {
|
|
119
|
+
let panels = this.#startPanels.map((panel) => ({ ...panel }));
|
|
120
|
+
if (delta === 0)
|
|
121
|
+
return panels;
|
|
122
|
+
let handleIndex = this.#handleIndex;
|
|
123
|
+
let growing = delta > 0;
|
|
124
|
+
let growIndex = growing ? handleIndex : handleIndex + 1;
|
|
125
|
+
let donorIndices = [];
|
|
126
|
+
if (growing) {
|
|
127
|
+
for (let index = handleIndex + 1; index < panels.length; index++)
|
|
128
|
+
donorIndices.push(index);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
for (let index = handleIndex; index >= 0; index--)
|
|
132
|
+
donorIndices.push(index);
|
|
133
|
+
}
|
|
134
|
+
let growPanel = panels[growIndex];
|
|
135
|
+
if (!growPanel)
|
|
136
|
+
return panels;
|
|
137
|
+
let growHeadroom = Math.max(growPanel.max - growPanel.size, 0);
|
|
138
|
+
let totalDonorAvailable = donorIndices.reduce((sum, index) => {
|
|
139
|
+
let panel = panels[index];
|
|
140
|
+
return panel ? sum + Math.max(panel.size - panel.min, 0) : sum;
|
|
141
|
+
}, 0);
|
|
142
|
+
let applied = Math.min(Math.abs(delta), growHeadroom, totalDonorAvailable);
|
|
143
|
+
growPanel.size += applied;
|
|
144
|
+
let remaining = applied;
|
|
145
|
+
for (let i = 0; i < donorIndices.length && remaining > 0; i++) {
|
|
146
|
+
let donorIndex = donorIndices[i];
|
|
147
|
+
let panel = donorIndex === undefined ? undefined : panels[donorIndex];
|
|
148
|
+
if (!panel)
|
|
149
|
+
continue;
|
|
150
|
+
let available = Math.max(panel.size - panel.min, 0);
|
|
151
|
+
let take = Math.min(available, remaining);
|
|
152
|
+
panel.size -= take;
|
|
153
|
+
remaining -= take;
|
|
154
|
+
}
|
|
155
|
+
return panels;
|
|
156
|
+
}
|
|
157
|
+
}
|