@eldrajs/ui 0.3.7 → 0.3.9
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/CHANGELOG.md +6 -0
- package/LICENSE-country-flag-icons +25 -0
- package/README.md +274 -66
- package/dist/CountryFlag-DOa8lOHp.js +71 -0
- package/dist/PhoneInput-CX83wgD0.js +695 -0
- package/dist/{VariantPicker-Cr_AkX47.js → VariantPicker-BqLbiONX.js} +122 -2302
- package/dist/components/chip/Chip.vue.d.ts +9 -0
- package/dist/components/dialog/Dialog.vue.d.ts +9 -0
- package/dist/components/drawer/Drawer.vue.d.ts +9 -0
- package/dist/components/filter-panel/FilterGroup.vue.d.ts +9 -0
- package/dist/components/filter-panel/FilterPanel.vue.d.ts +9 -0
- package/dist/components/filter-panel/facets/ColourFacet.vue.d.ts +9 -0
- package/dist/components/filter-panel/facets/ListFacet.vue.d.ts +9 -0
- package/dist/components/filter-panel/facets/RangeFacet.vue.d.ts +9 -0
- package/dist/components/filter-panel/facets/SizeFacet.vue.d.ts +9 -0
- package/dist/components/filter-panel/facets/ToggleFacet.vue.d.ts +9 -0
- package/dist/components/lightbox/Lightbox.vue.d.ts +9 -0
- package/dist/components/nav-menu/NavMenu.vue.d.ts +9 -0
- package/dist/components/pagination/Pagination.vue.d.ts +9 -0
- package/dist/components/range-slider/RangeSlider.vue.d.ts +9 -0
- package/dist/components/search-bar/SearchBar.vue.d.ts +9 -0
- package/dist/components/search-modal/SearchModal.vue.d.ts +9 -0
- package/dist/components/select/MultiSelect.vue.d.ts +10 -0
- package/dist/components/select/Select.vue.d.ts +9 -0
- package/dist/components/select/types.d.ts +7 -1
- package/dist/components/site-form/SiteForm.vue.d.ts +9 -0
- package/dist/components/toast/Toast.vue.d.ts +9 -0
- package/dist/components/toast/Toaster.vue.d.ts +9 -0
- package/dist/components.css +64 -0
- package/dist/flag/CountryFlag.vue.d.ts +9 -0
- package/dist/flag/flags.d.ts +8 -0
- package/dist/flag/index.d.ts +9 -0
- package/dist/flag.js +1 -0
- package/dist/index.js +4 -2
- package/dist/messages/en-US.d.ts +21 -0
- package/dist/messages/is-IS.js +10 -1
- package/dist/phone/PhoneInput.vue.d.ts +221 -0
- package/dist/phone/caret.d.ts +14 -0
- package/dist/phone/examples.d.ts +2 -0
- package/dist/phone/index.d.ts +13 -0
- package/dist/phone/phone.d.ts +62 -0
- package/dist/phone/phoneFlagData.d.ts +2 -0
- package/dist/phone/rule.d.ts +22 -0
- package/dist/phone/types.d.ts +63 -0
- package/dist/phone/vee-validate/FieldPhoneInput.vue.d.ts +24 -0
- package/dist/phone/vee-validate/index.d.ts +3 -0
- package/dist/phone/vee-validate/types.d.ts +3 -0
- package/dist/phone/vee-validate.js +96 -0
- package/dist/phone.js +3 -0
- package/dist/phoneFlagData-D9dDT2uC.js +261 -0
- package/dist/resolver.d.ts +15 -2
- package/dist/resolver.js +26 -4
- package/dist/style.css +64 -0
- package/dist/useEldraScope-BDbGzt7R.js +32 -0
- package/dist/useFieldControl-D1j54YON.js +273 -0
- package/dist/{useMessages-DOHGfip_.js → useMessages-CkhrRmu7.js} +22 -1
- package/dist/usePopover-ECHpsSRF.js +2199 -0
- package/dist/utilities.css +37 -0
- package/dist/vee-validate.js +7 -273
- package/dist/vue-i18n.js +4 -1
- package/package.json +23 -2
|
@@ -0,0 +1,2199 @@
|
|
|
1
|
+
import { r as useEldraScope } from "./useEldraScope-BDbGzt7R.js";
|
|
2
|
+
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, inject, mergeProps, nextTick, normalizeClass, normalizeStyle, onBeforeUnmount, onMounted, onScopeDispose, openBlock, provide, ref, renderList, renderSlot, resolveDynamicComponent, toDisplayString, toValue, unref, useAttrs, useId, watch } from "vue";
|
|
3
|
+
import { extendTailwindMerge } from "tailwind-merge";
|
|
4
|
+
import { autoUpdate, flip, offset, shift, size, useFloating } from "@floating-ui/vue";
|
|
5
|
+
// src/utils/id.ts
|
|
6
|
+
/**
|
|
7
|
+
* A stable, SSR-safe id for a component part, or the caller's own id when it
|
|
8
|
+
* gave one.
|
|
9
|
+
*
|
|
10
|
+
* Built on Vue's `useId()` (Vue 3.5+), so the server and the client produce the
|
|
11
|
+
* same value and `aria-describedby`/`for` wiring does not break on hydration.
|
|
12
|
+
* Must be called during `setup()`, like every other Vue composable.
|
|
13
|
+
*/
|
|
14
|
+
function useUiId(prefix, explicit) {
|
|
15
|
+
const generated = useId();
|
|
16
|
+
return computed(() => toValue(explicit) ?? `eldra-${prefix}-${generated}`);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Compose an `aria-describedby` (or `aria-labelledby`) value from ids that may
|
|
20
|
+
* be absent.
|
|
21
|
+
*
|
|
22
|
+
* One rule, everywhere in this package: **a control's own ids come first, then
|
|
23
|
+
* whatever the field context adds.** `aria-describedby` is read in document
|
|
24
|
+
* order of the listed ids, so the control's own error, counter or description is
|
|
25
|
+
* what a screen reader hears first, and the wrapper's help text follows. Nothing
|
|
26
|
+
* ever *replaces* the context — a `describedBy` prop adds to it, so
|
|
27
|
+
* `<FieldWrapper error="…"><Input described-by="x"/></FieldWrapper>` still
|
|
28
|
+
* describes the error.
|
|
29
|
+
*
|
|
30
|
+
* Duplicates are dropped (the same id listed twice is announced twice), and an
|
|
31
|
+
* empty result is `undefined` rather than `""`, so the attribute is omitted
|
|
32
|
+
* instead of rendered empty.
|
|
33
|
+
*
|
|
34
|
+
* **Deduplication is per id, not per argument.** Every argument here is itself an
|
|
35
|
+
* `aria-describedby` value, so it may already hold several space-separated ids —
|
|
36
|
+
* a `FieldWrapper`'s context contributes its error, help and counter ids as one
|
|
37
|
+
* string, and a consumer's `describedBy` prop may do the same. Comparing whole
|
|
38
|
+
* arguments would only have caught the case where two of them were byte-identical,
|
|
39
|
+
* and `joinIds('a b', 'b c')` would have announced `b` twice. Each argument is
|
|
40
|
+
* split on whitespace and the ids are deduplicated individually, first occurrence
|
|
41
|
+
* winning, so the order the rule promises is preserved.
|
|
42
|
+
*/
|
|
43
|
+
function joinIds(...ids) {
|
|
44
|
+
const seen = /* @__PURE__ */ new Set();
|
|
45
|
+
for (const value of ids) {
|
|
46
|
+
if (typeof value !== "string") continue;
|
|
47
|
+
for (const id of value.split(/\s+/)) if (id.length > 0) seen.add(id);
|
|
48
|
+
}
|
|
49
|
+
return seen.size > 0 ? [...seen].join(" ") : void 0;
|
|
50
|
+
}
|
|
51
|
+
// src/composables/useControllableModel.ts
|
|
52
|
+
/**
|
|
53
|
+
* A model that works both ways round: controlled when the parent passes
|
|
54
|
+
* `modelValue`, self-managing when it does not.
|
|
55
|
+
*
|
|
56
|
+
* Every stateful component in this package uses it, so a consumer can drop a
|
|
57
|
+
* `Select` in with no `v-model` and still get a working control, while a
|
|
58
|
+
* consumer that does bind `v-model` stays the single source of truth — writes
|
|
59
|
+
* are emitted and never applied locally, so a parent that refuses a value
|
|
60
|
+
* actually refuses it.
|
|
61
|
+
*
|
|
62
|
+
* `fallback` supplies the uncontrolled starting value and is called once.
|
|
63
|
+
*/
|
|
64
|
+
function useControllableModel(props, emit, fallback) {
|
|
65
|
+
const internal = ref(props.modelValue === void 0 ? fallback() : props.modelValue);
|
|
66
|
+
watch(() => props.modelValue, (value) => {
|
|
67
|
+
if (value !== void 0) internal.value = value;
|
|
68
|
+
});
|
|
69
|
+
return computed({
|
|
70
|
+
get: () => props.modelValue === void 0 ? internal.value : props.modelValue,
|
|
71
|
+
set: (value) => {
|
|
72
|
+
if (props.modelValue === void 0) internal.value = value;
|
|
73
|
+
emit("update:modelValue", value);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
var kitMerge = extendTailwindMerge({
|
|
78
|
+
extend: {
|
|
79
|
+
theme: {
|
|
80
|
+
shadow: ["float"],
|
|
81
|
+
container: [
|
|
82
|
+
"narrow",
|
|
83
|
+
"content",
|
|
84
|
+
"wide",
|
|
85
|
+
"tablet",
|
|
86
|
+
"two-col"
|
|
87
|
+
]
|
|
88
|
+
},
|
|
89
|
+
classGroups: {
|
|
90
|
+
"font-size": [{ text: [
|
|
91
|
+
"display",
|
|
92
|
+
"h1",
|
|
93
|
+
"h2",
|
|
94
|
+
"h3",
|
|
95
|
+
"h4",
|
|
96
|
+
"body-lg",
|
|
97
|
+
"body",
|
|
98
|
+
"body-sm",
|
|
99
|
+
"caption",
|
|
100
|
+
"overline",
|
|
101
|
+
"label",
|
|
102
|
+
"code",
|
|
103
|
+
"button-sm",
|
|
104
|
+
"button-md",
|
|
105
|
+
"button-lg",
|
|
106
|
+
"control-sm",
|
|
107
|
+
"control",
|
|
108
|
+
"control-lg",
|
|
109
|
+
"control-mobile",
|
|
110
|
+
"counter",
|
|
111
|
+
"field-note",
|
|
112
|
+
"card-title",
|
|
113
|
+
"switch-label",
|
|
114
|
+
"switch-description",
|
|
115
|
+
"select-group",
|
|
116
|
+
"select-option",
|
|
117
|
+
"select-pill",
|
|
118
|
+
"stepper-value",
|
|
119
|
+
"stepper-value-sm",
|
|
120
|
+
"search-meta",
|
|
121
|
+
"search-title",
|
|
122
|
+
"search-kbd",
|
|
123
|
+
"variant-legend",
|
|
124
|
+
"variant-pill",
|
|
125
|
+
"logo-wordmark",
|
|
126
|
+
"badge",
|
|
127
|
+
"stock-status",
|
|
128
|
+
"price-sm",
|
|
129
|
+
"price-lg",
|
|
130
|
+
"price-current",
|
|
131
|
+
"price-secondary",
|
|
132
|
+
"price-unit",
|
|
133
|
+
"avatar-initials-sm",
|
|
134
|
+
"avatar-initials-md",
|
|
135
|
+
"avatar-initials-lg",
|
|
136
|
+
"avatar-initials-xl",
|
|
137
|
+
"empty-state-title",
|
|
138
|
+
"filter-trigger",
|
|
139
|
+
"filter-subheading",
|
|
140
|
+
"filter-tile-count",
|
|
141
|
+
"content-card-title",
|
|
142
|
+
"content-card-excerpt",
|
|
143
|
+
"dialog-title",
|
|
144
|
+
"accordion-title",
|
|
145
|
+
"drawer-title",
|
|
146
|
+
"tooltip",
|
|
147
|
+
"toast-title",
|
|
148
|
+
"search-modal-field",
|
|
149
|
+
"search-modal-foot",
|
|
150
|
+
"search-modal-kbd"
|
|
151
|
+
] }],
|
|
152
|
+
h: [
|
|
153
|
+
"control-h",
|
|
154
|
+
"control-h-sm",
|
|
155
|
+
"control-h-lg",
|
|
156
|
+
"eldra-range-track",
|
|
157
|
+
"eldra-skeleton-title",
|
|
158
|
+
"eldra-skeleton-box"
|
|
159
|
+
],
|
|
160
|
+
"min-h": [
|
|
161
|
+
"eldra-range-rail",
|
|
162
|
+
"eldra-drawer-header-height",
|
|
163
|
+
"eldra-nav-menu-drawer-row"
|
|
164
|
+
],
|
|
165
|
+
px: [
|
|
166
|
+
"eldra-range-gutter",
|
|
167
|
+
"eldra-range-gutter-thumb",
|
|
168
|
+
"eldra-drawer-gutter"
|
|
169
|
+
],
|
|
170
|
+
w: [
|
|
171
|
+
"eldra-dialog-width",
|
|
172
|
+
"eldra-dialog-width-sm",
|
|
173
|
+
"eldra-drawer-width",
|
|
174
|
+
"eldra-toast-width",
|
|
175
|
+
"eldra-search-modal-width"
|
|
176
|
+
],
|
|
177
|
+
size: [
|
|
178
|
+
"eldra-avatar-icon-sm",
|
|
179
|
+
"eldra-avatar-icon-md",
|
|
180
|
+
"eldra-avatar-icon-lg",
|
|
181
|
+
"eldra-avatar-icon-xl"
|
|
182
|
+
],
|
|
183
|
+
"target-min": ["target-min"],
|
|
184
|
+
"target-touch": ["target-touch"],
|
|
185
|
+
"eldra-scrollbar-hide": ["eldra-scrollbar-hide"],
|
|
186
|
+
transition: ["eldra-transition-colors"],
|
|
187
|
+
"border-w": [
|
|
188
|
+
"eldra-field-border",
|
|
189
|
+
"eldra-button-border",
|
|
190
|
+
"eldra-checkbox-border",
|
|
191
|
+
"eldra-checkbox-border-invalid",
|
|
192
|
+
"eldra-radio-card-border",
|
|
193
|
+
"eldra-switch-track-border",
|
|
194
|
+
"eldra-variant-pill-border",
|
|
195
|
+
"eldra-variant-swatch-ring",
|
|
196
|
+
"eldra-variant-swatch-edge",
|
|
197
|
+
"eldra-filter-swatch-ring",
|
|
198
|
+
"eldra-editor-placeholder-border"
|
|
199
|
+
],
|
|
200
|
+
"eldra-field-invalid": ["eldra-field-invalid"],
|
|
201
|
+
"eldra-radio-card-selected": ["eldra-radio-card-selected"],
|
|
202
|
+
"eldra-switch-thumb-offset": ["eldra-switch-thumb-offset"],
|
|
203
|
+
"eldra-dialog-fullscreen": ["eldra-dialog-fullscreen"],
|
|
204
|
+
"eldra-drawer-motion": ["eldra-drawer-motion"],
|
|
205
|
+
"eldra-drawer-sheet": ["eldra-drawer-sheet"],
|
|
206
|
+
"max-h": [
|
|
207
|
+
"eldra-select-panel-height",
|
|
208
|
+
"eldra-search-panel-height",
|
|
209
|
+
"eldra-dialog-max-height",
|
|
210
|
+
"eldra-search-modal-max-height",
|
|
211
|
+
"eldra-drawer-sheet-height"
|
|
212
|
+
],
|
|
213
|
+
m: ["eldra-search-modal-position"],
|
|
214
|
+
"max-w": [
|
|
215
|
+
"eldra-select-panel-width",
|
|
216
|
+
"eldra-container-narrow",
|
|
217
|
+
"eldra-container-content",
|
|
218
|
+
"eldra-container-wide"
|
|
219
|
+
],
|
|
220
|
+
"eldra-select-match": ["eldra-select-match"],
|
|
221
|
+
"eldra-select-swatch": ["eldra-select-swatch"],
|
|
222
|
+
"eldra-select-option-active": ["eldra-select-option-active"],
|
|
223
|
+
"eldra-select-option-selected": ["eldra-select-option-selected"],
|
|
224
|
+
"eldra-variant-pill-selected-line": ["eldra-variant-pill-selected-line"],
|
|
225
|
+
"eldra-focus": ["eldra-focus", "eldra-focus-inset"],
|
|
226
|
+
"eldra-focus-always": ["eldra-focus-always", "eldra-focus-inset-always"],
|
|
227
|
+
"eldra-focus-proxy": ["eldra-focus-proxy"],
|
|
228
|
+
"eldra-focus-open": ["eldra-focus-open"],
|
|
229
|
+
"eldra-focus-has-open": ["eldra-focus-has-open"],
|
|
230
|
+
"eldra-phone-flag": ["eldra-phone-flag"],
|
|
231
|
+
rounded: ["eldra-link-radius", "eldra-select-check-radius"],
|
|
232
|
+
duration: [
|
|
233
|
+
"duration-fast",
|
|
234
|
+
"duration-base",
|
|
235
|
+
"duration-slow"
|
|
236
|
+
],
|
|
237
|
+
opacity: ["eldra-revalidating"],
|
|
238
|
+
"eldra-skeleton": ["eldra-skeleton"],
|
|
239
|
+
"eldra-skeleton-text": ["eldra-skeleton-text"],
|
|
240
|
+
"eldra-rating-half": ["eldra-rating-half"],
|
|
241
|
+
"eldra-image-placeholder-hatch": ["eldra-image-placeholder-hatch"],
|
|
242
|
+
"eldra-tooltip-arrow": ["eldra-tooltip-arrow"],
|
|
243
|
+
z: [
|
|
244
|
+
"z-sticky",
|
|
245
|
+
"z-popover",
|
|
246
|
+
"z-drawer",
|
|
247
|
+
"z-dialog",
|
|
248
|
+
"z-toast"
|
|
249
|
+
],
|
|
250
|
+
"eldra-accordion-chevron": ["eldra-accordion-chevron"],
|
|
251
|
+
"eldra-accordion-panel": ["eldra-accordion-panel"],
|
|
252
|
+
"eldra-carousel-slide": ["eldra-carousel-slide"],
|
|
253
|
+
"eldra-carousel-track": ["eldra-carousel-track"],
|
|
254
|
+
"eldra-carousel-dot": ["eldra-carousel-dot"],
|
|
255
|
+
"eldra-range-thumb": ["eldra-range-thumb"],
|
|
256
|
+
"eldra-filter-swatch-edge": ["eldra-filter-swatch-edge"],
|
|
257
|
+
"eldra-filter-histogram-bar": ["eldra-filter-histogram-bar"],
|
|
258
|
+
pt: ["eldra-nav-menu-panel", "eldra-drawer-header-top"],
|
|
259
|
+
"grid-cols": ["eldra-nav-menu-columns"],
|
|
260
|
+
"eldra-nav-menu-dropdown": ["eldra-nav-menu-dropdown"],
|
|
261
|
+
ps: ["eldra-nav-menu-drawer-nest"],
|
|
262
|
+
pb: [
|
|
263
|
+
"eldra-drawer-header-bottom",
|
|
264
|
+
"eldra-drawer-body-bottom",
|
|
265
|
+
"eldra-drawer-footer-bottom"
|
|
266
|
+
],
|
|
267
|
+
animate: [
|
|
268
|
+
"animate-eldra-spin",
|
|
269
|
+
"animate-eldra-pulse",
|
|
270
|
+
"animate-eldra-popover-in",
|
|
271
|
+
"animate-eldra-dialog-in",
|
|
272
|
+
"animate-eldra-dialog-in-reduced",
|
|
273
|
+
"animate-eldra-drawer-in-right",
|
|
274
|
+
"animate-eldra-drawer-in-left",
|
|
275
|
+
"animate-eldra-toast-in",
|
|
276
|
+
"animate-eldra-lightbox-in"
|
|
277
|
+
]
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
prefix: "eldra"
|
|
281
|
+
});
|
|
282
|
+
/** The component's own classes with `incoming` (a parent component's) merged over them. */
|
|
283
|
+
function mergeClass(own, incoming) {
|
|
284
|
+
return kitMerge(normalizeClass([own, incoming]));
|
|
285
|
+
}
|
|
286
|
+
// src/components/icon/sizes.ts
|
|
287
|
+
/**
|
|
288
|
+
* The spec's sizes as Tailwind utilities. The theme's `--spacing` is 0.25rem,
|
|
289
|
+
* so `size-4`/`size-5`/`size-6`/`size-8` are exactly 1/1.25/1.5/2rem — no
|
|
290
|
+
* literal length appears here or in the built CSS.
|
|
291
|
+
*/
|
|
292
|
+
var ICON_SIZE_CLASS = {
|
|
293
|
+
sm: "eldra:size-4",
|
|
294
|
+
md: "eldra:size-5",
|
|
295
|
+
lg: "eldra:size-6",
|
|
296
|
+
xl: "eldra:size-8"
|
|
297
|
+
};
|
|
298
|
+
/** The spec's outline stroke weight. */
|
|
299
|
+
var ICON_STROKE_WIDTH = 1.75;
|
|
300
|
+
// src/components/spinner/Spinner.vue?vue&type=script&setup=true&lang.ts
|
|
301
|
+
var _hoisted_1$1 = [
|
|
302
|
+
"data-eldra-scope",
|
|
303
|
+
"role",
|
|
304
|
+
"aria-label",
|
|
305
|
+
"aria-hidden"
|
|
306
|
+
];
|
|
307
|
+
// src/components/spinner/Spinner.vue
|
|
308
|
+
var Spinner_default = /* @__PURE__ */ defineComponent({
|
|
309
|
+
inheritAttrs: false,
|
|
310
|
+
__name: "Spinner",
|
|
311
|
+
props: { label: { default: void 0 } },
|
|
312
|
+
setup(__props) {
|
|
313
|
+
const props = __props;
|
|
314
|
+
const eldra = useEldraScope();
|
|
315
|
+
const attrs = useAttrs();
|
|
316
|
+
const forwardedAttrs = computed(() => {
|
|
317
|
+
const { class: _class, ...rest } = attrs;
|
|
318
|
+
return rest;
|
|
319
|
+
});
|
|
320
|
+
const rootClass = computed(() => mergeClass("eldra:size-4.5 eldra:animate-eldra-spin eldra:motion-reduce:animate-eldra-pulse", attrs.class));
|
|
321
|
+
/** `""` names nothing, so it is decorative too. */
|
|
322
|
+
const named = computed(() => props.label !== void 0 && props.label !== "");
|
|
323
|
+
return (_ctx, _cache) => {
|
|
324
|
+
return openBlock(), createElementBlock("svg", mergeProps({
|
|
325
|
+
"data-eldra-ui": "",
|
|
326
|
+
"data-eldra-scope": unref(eldra).scope,
|
|
327
|
+
class: rootClass.value,
|
|
328
|
+
viewBox: "0 0 18 18",
|
|
329
|
+
fill: "none",
|
|
330
|
+
role: named.value ? "img" : void 0,
|
|
331
|
+
"aria-label": named.value ? __props.label : void 0,
|
|
332
|
+
"aria-hidden": named.value ? void 0 : "true",
|
|
333
|
+
focusable: "false"
|
|
334
|
+
}, forwardedAttrs.value), [..._cache[0] || (_cache[0] = [createElementVNode("circle", {
|
|
335
|
+
cx: "9",
|
|
336
|
+
cy: "9",
|
|
337
|
+
r: "8",
|
|
338
|
+
stroke: "currentColor",
|
|
339
|
+
"stroke-width": "2",
|
|
340
|
+
"stroke-opacity": "0.3"
|
|
341
|
+
}, null, -1), createElementVNode("path", {
|
|
342
|
+
d: "M17 9a8 8 0 0 0-8-8",
|
|
343
|
+
stroke: "currentColor",
|
|
344
|
+
"stroke-width": "2",
|
|
345
|
+
"stroke-linecap": "round"
|
|
346
|
+
}, null, -1)])], 16, _hoisted_1$1);
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
// src/components/field-wrapper/context.ts
|
|
351
|
+
/** The key a `FieldWrapper` provides its `FieldContext` on. */
|
|
352
|
+
var FIELD_KEY = Symbol("eldra-ui:field");
|
|
353
|
+
// src/composables/useLocale.ts
|
|
354
|
+
/**
|
|
355
|
+
* The number locale the components format with, as a provide/inject pair — the same shape as
|
|
356
|
+
* `useMessages`, and deliberately separate from it: the *strings* a component renders and the
|
|
357
|
+
* *locale its numbers are formatted in* are two different decisions, and a store that accepts the
|
|
358
|
+
* English defaults may still be an Icelandic shop.
|
|
359
|
+
*
|
|
360
|
+
* It is an ambient default, never an answer: every component that reads it also takes a `locale`
|
|
361
|
+
* prop, and the prop wins. With nothing provided the components format in `en-US`.
|
|
362
|
+
*/
|
|
363
|
+
var DEFAULT_UI_LOCALE = "en-US";
|
|
364
|
+
/**
|
|
365
|
+
* The injection key the locale provider writes to. Exported so an app can set the locale from
|
|
366
|
+
* outside a `setup()` scope — and so it can provide a **getter**, which is what makes a locale
|
|
367
|
+
* switch reactive without an effect that outlives a server request:
|
|
368
|
+
*
|
|
369
|
+
* ```ts
|
|
370
|
+
* import { LOCALE_KEY } from '@eldrajs/ui';
|
|
371
|
+
* app.provide(LOCALE_KEY, () => store.locale);
|
|
372
|
+
* ```
|
|
373
|
+
*/
|
|
374
|
+
var LOCALE_KEY = Symbol("eldra-ui-locale");
|
|
375
|
+
/**
|
|
376
|
+
* Set the number locale for this component and everything below it.
|
|
377
|
+
*
|
|
378
|
+
* Wraps Vue's `provide`, so it must be called during `setup()`. Use
|
|
379
|
+
* `app.provide(LOCALE_KEY, locale)` for the app-wide case.
|
|
380
|
+
*/
|
|
381
|
+
function provideEldraUiLocale(locale) {
|
|
382
|
+
provide(LOCALE_KEY, locale);
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* The locale a component should format numbers in: whatever an ancestor provided, else `en-US`.
|
|
386
|
+
* A ref or a getter is unwrapped on every read, so the value follows a locale switch.
|
|
387
|
+
*/
|
|
388
|
+
function useEldraUiLocale() {
|
|
389
|
+
const provided = inject(LOCALE_KEY, void 0);
|
|
390
|
+
return computed(() => toValue(provided) ?? "en-US");
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* The injection key the store currency is provided under (spec "Price" → Properties, `currency`
|
|
394
|
+
* row: "store currency") — the same provide/inject shape as `LOCALE_KEY` and deliberately separate
|
|
395
|
+
* from it: a store's number locale and its currency are two different decisions (an
|
|
396
|
+
* `en-US`-formatted store may still sell in `ISK`). It is an ambient default, never an answer:
|
|
397
|
+
* every component that reads it also takes a `currency` prop, and the prop wins. **With nothing
|
|
398
|
+
* provided there is no currency at all** — see `useEldraUiCurrency` for what the components then
|
|
399
|
+
* render, and why this pair has no default code.
|
|
400
|
+
*
|
|
401
|
+
* Exported so an app can set the currency from
|
|
402
|
+
* outside a `setup()` scope — and so it can provide a **getter**, which is what makes a currency
|
|
403
|
+
* switch reactive without an effect that outlives a server request:
|
|
404
|
+
*
|
|
405
|
+
* ```ts
|
|
406
|
+
* import { CURRENCY_KEY } from '@eldrajs/ui';
|
|
407
|
+
* app.provide(CURRENCY_KEY, () => store.currency);
|
|
408
|
+
* ```
|
|
409
|
+
*
|
|
410
|
+
* Providing `undefined` is meaningful and different from not providing at all: it says the store
|
|
411
|
+
* has **no** currency, which is the answer a platform that has not been told one must be able to
|
|
412
|
+
* give. Vue's `inject` consults `key in provides`, so the two cases stay distinguishable (see
|
|
413
|
+
* `useEldraUiCurrency`).
|
|
414
|
+
*/
|
|
415
|
+
var CURRENCY_KEY = Symbol("eldra-ui-currency");
|
|
416
|
+
/**
|
|
417
|
+
* Set the store currency for this component and everything below it.
|
|
418
|
+
*
|
|
419
|
+
* Wraps Vue's `provide`, so it must be called during `setup()`. Use
|
|
420
|
+
* `app.provide(CURRENCY_KEY, currency)` for the app-wide case.
|
|
421
|
+
*/
|
|
422
|
+
function provideEldraUiCurrency(currency) {
|
|
423
|
+
provide(CURRENCY_KEY, currency);
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* A value no provider can supply, so `inject`'s default tells "nobody provided a currency" apart
|
|
427
|
+
* from "a provider answered: this store has none". Vue's `inject` returns a provided `undefined`
|
|
428
|
+
* rather than the default (it tests `key in provides`), which is what makes the distinction real.
|
|
429
|
+
*/
|
|
430
|
+
var NO_CURRENCY_PROVIDER = Symbol("eldra-ui-currency-absent");
|
|
431
|
+
/**
|
|
432
|
+
* The currency a component should format money in: whatever an ancestor provided, else **nothing**.
|
|
433
|
+
* A ref or a getter is unwrapped on every read, so the value follows a currency switch.
|
|
434
|
+
*
|
|
435
|
+
* **There is no default code.** A component library installed by a shop of any kind cannot guess
|
|
436
|
+
* one: a `USD` fallback puts a dollar sign in front of krónur, and a wrong price is worse than an
|
|
437
|
+
* incomplete one. So `undefined` comes back whenever there is no currency to name, and a component
|
|
438
|
+
* reading it formats the amount as a plain number through the same `Intl` path, with no symbol and
|
|
439
|
+
* no code (`Price` does exactly that). The empty string is read as "no currency" too: it is not a
|
|
440
|
+
* code `Intl` accepts, and it was the only way to decline one while this composable still defaulted.
|
|
441
|
+
*
|
|
442
|
+
* Two ways to arrive at `undefined`, and only one of them is a mistake. A provider that supplies
|
|
443
|
+
* `undefined` (or `''`) has *answered* — this store has no currency — and nothing is logged. Having
|
|
444
|
+
* no provider at all is unwired, and warns once per session in dev.
|
|
445
|
+
*/
|
|
446
|
+
function useEldraUiCurrency() {
|
|
447
|
+
const provided = inject(CURRENCY_KEY, NO_CURRENCY_PROVIDER);
|
|
448
|
+
return computed(() => {
|
|
449
|
+
if (provided === NO_CURRENCY_PROVIDER) return;
|
|
450
|
+
const currency = toValue(provided);
|
|
451
|
+
return currency === void 0 || currency === "" ? void 0 : currency;
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
// src/components/input/classes.ts
|
|
455
|
+
/**
|
|
456
|
+
* The field recipes of the design spec's **Input**, in one place.
|
|
457
|
+
*
|
|
458
|
+
* `Input` is the spec's field box, and two other controls draw the same box: `SearchBar`'s search
|
|
459
|
+
* field ("Search bar" → Sizes says it *is* an input) and `UnitInput` (so `CurrencyInput` too).
|
|
460
|
+
* `SearchBar` used to carry a
|
|
461
|
+
* hand-copied duplicate of these strings, and the copy drifted — the operator's report was that
|
|
462
|
+
* the search field "does not behave like the regular input fields", which was exactly that: the
|
|
463
|
+
* copy had lost the radius variable and the mobile type-size rule, so the field rounded and
|
|
464
|
+
* resized differently from every `Input` beside it.
|
|
465
|
+
*
|
|
466
|
+
* So the recipes live here and the three components import them. What a component may add is its
|
|
467
|
+
* own **delta** — a pill radius, a different padding for an icon it draws itself — never a second
|
|
468
|
+
* copy of the box.
|
|
469
|
+
*
|
|
470
|
+
* Nothing here is exported from the package: a consumer restyles through `class`, `classes`, tokens and
|
|
471
|
+
* the per-component CSS variables (see the README's Customisation section), not by importing our
|
|
472
|
+
* class strings, which are not a stable API.
|
|
473
|
+
*/
|
|
474
|
+
/**
|
|
475
|
+
* The shared box (spec "Input" → Anatomy, Sizes, States). The `<input>` *is* the field box — the
|
|
476
|
+
* anatomy calls it "the native `<input>`, full width" — so the border, the radius and the one
|
|
477
|
+
* focus ring all live on it, and any leading or trailing decoration is absolutely positioned over
|
|
478
|
+
* the padding the sizes reserve for it.
|
|
479
|
+
*
|
|
480
|
+
* `eldra-focus-always` is the text-field rule from the focus-ring foundation: the ring shows on
|
|
481
|
+
* *any* focus, pointer included, "because a caret alone is easy to miss". There is deliberately no
|
|
482
|
+
* `transition-*`/`duration-*` utility beside it — `eldra-focus` owns this element's transition
|
|
483
|
+
* list, including the `duration-fast` border-colour change the spec's Behaviour section asks for.
|
|
484
|
+
* See `src/styles/tailwind.css` and `src/__tests__/focus-transition.spec.ts`.
|
|
485
|
+
*/
|
|
486
|
+
var FIELD_BOX = "eldra:block eldra:w-full eldra:min-w-0 eldra:eldra-field-border eldra:placeholder:text-muted eldra:eldra-focus eldra:eldra-focus-always";
|
|
487
|
+
/** The box's radius, apart so a field with a radius of its own (`SearchBar`'s pill) takes one. */
|
|
488
|
+
var FIELD_RADIUS = "eldra:rounded-[var(--eldra-input-radius,var(--eldra-radius-md))]";
|
|
489
|
+
var FIELD_BASE = `${FIELD_BOX} ${FIELD_RADIUS}`;
|
|
490
|
+
/**
|
|
491
|
+
* The type style per size (spec "Input" → Sizes). Its own constant because `SearchBar`'s two sizes
|
|
492
|
+
* take exactly these rules while its paddings are its own — the `max-md:text-control-mobile`
|
|
493
|
+
* override in particular, which is a *viewport* rule (so iOS never zooms into a focused field) and
|
|
494
|
+
* is the half that had gone missing from the copy.
|
|
495
|
+
*/
|
|
496
|
+
var FIELD_TEXT = {
|
|
497
|
+
sm: "eldra:text-control-sm",
|
|
498
|
+
md: "eldra:text-control eldra:max-md:text-control-mobile",
|
|
499
|
+
lg: "eldra:text-control-lg"
|
|
500
|
+
};
|
|
501
|
+
/**
|
|
502
|
+
* Sizes (spec "Input" → Sizes). `--spacing` is 0.25rem, so `py-0.75`/`px-2.25` are the spec's
|
|
503
|
+
* 0.1875/0.5625rem, `py-1.75`/`px-2.75` its 0.4375/0.6875rem and `py-2.75` its 0.6875rem.
|
|
504
|
+
* The 1.5rem line comes from the `text-control*` utilities, so the value sits on the spec's line
|
|
505
|
+
* inside the spec's box at every size.
|
|
506
|
+
*/
|
|
507
|
+
var FIELD_SIZE = {
|
|
508
|
+
sm: `eldra:control-h-sm eldra:py-0.75 eldra:px-2.25 ${FIELD_TEXT.sm}`,
|
|
509
|
+
md: `eldra:control-h eldra:py-1.75 eldra:px-2.75 ${FIELD_TEXT.md}`,
|
|
510
|
+
lg: `eldra:control-h-lg eldra:py-2.75 eldra:px-2.75 ${FIELD_TEXT.lg}`
|
|
511
|
+
};
|
|
512
|
+
/**
|
|
513
|
+
* Room for the decorations (spec "Input" → Sizes, md row): "With a leading icon, the start padding
|
|
514
|
+
* is 2.25rem. With a trailing action, the end padding is 2.5rem." The leading icon is 1.125rem at
|
|
515
|
+
* every size, so its 2.25rem applies to all three; the trailing action is 2rem square, which does
|
|
516
|
+
* not fit a 2rem sm box, so sm uses a 1.5rem button (still the 2.5.8 target minimum) and 2rem of
|
|
517
|
+
* end padding to match.
|
|
518
|
+
*/
|
|
519
|
+
var FIELD_LEADING_PAD = "eldra:ps-9";
|
|
520
|
+
var FIELD_TRAILING_PAD = {
|
|
521
|
+
sm: "eldra:pe-8",
|
|
522
|
+
md: "eldra:pe-10",
|
|
523
|
+
lg: "eldra:pe-10"
|
|
524
|
+
};
|
|
525
|
+
var FIELD_CLEAR_SIZE = {
|
|
526
|
+
sm: "eldra:size-6",
|
|
527
|
+
md: "eldra:size-8",
|
|
528
|
+
lg: "eldra:size-8"
|
|
529
|
+
};
|
|
530
|
+
/**
|
|
531
|
+
* Two trailing actions (operator report, 2026-09-25; recorded under Deviations in the README): a
|
|
532
|
+
* `UnitInput`/`CurrencyInput` with `clearable` and a drag handle both on showed `$1,234,567.89 ×
|
|
533
|
+
* ↕` — each action a full 2rem square around a 1.125rem icon, `gap-1` between them, so the two
|
|
534
|
+
* icons ended up roughly 1.1rem apart, far wider than any other icon pair in the library (the
|
|
535
|
+
* private library's own handle sits `px-0` beside the clear button, no gap at all).
|
|
536
|
+
*
|
|
537
|
+
* A single action keeps `FIELD_TRAILING_PAD`/`FIELD_CLEAR_SIZE` unchanged (`Input`'s and
|
|
538
|
+
* `SearchBar`'s only ever have one, and their rendered classes must not change). With two, the row
|
|
539
|
+
* itself carries no gap (`FIELD_SUFFIX_ROW` below), each action shrinks to `w-6` (1.5rem — still
|
|
540
|
+
* the WCAG 2.5.8 24px minimum) at the row's own height, and the control's end padding grows to fit
|
|
541
|
+
* both of them plus the row's own 0.25rem inset from the edge.
|
|
542
|
+
*/
|
|
543
|
+
var FIELD_TRAILING_PAD_PAIR = {
|
|
544
|
+
sm: "eldra:pe-14",
|
|
545
|
+
md: "eldra:pe-14",
|
|
546
|
+
lg: "eldra:pe-14"
|
|
547
|
+
};
|
|
548
|
+
var FIELD_ACTION_PAIR_SIZE = {
|
|
549
|
+
sm: "eldra:w-6 eldra:h-6",
|
|
550
|
+
md: "eldra:w-6 eldra:h-8",
|
|
551
|
+
lg: "eldra:w-6 eldra:h-8"
|
|
552
|
+
};
|
|
553
|
+
/**
|
|
554
|
+
* States (spec "Input" → States). Disabled and read-only replace the live colours outright rather
|
|
555
|
+
* than layering over them, so a `:hover` rule can never win back a live boundary on a dead field.
|
|
556
|
+
* The error row's second 1px line is the ring's own outline at rest (`eldra-field-invalid`, on the
|
|
557
|
+
* control beside this recipe). Each recipe carries the
|
|
558
|
+
* fill, the text colour and the boundary, so a field renders exactly one of each: `fieldState`
|
|
559
|
+
* picks the one recipe a field is in.
|
|
560
|
+
*/
|
|
561
|
+
var FIELD_LIVE_FILL = "eldra:bg-background eldra:text-text";
|
|
562
|
+
var FIELD_READONLY_FILL = "eldra:bg-surface eldra:text-text";
|
|
563
|
+
var FIELD_LIVE = `${FIELD_LIVE_FILL} eldra:border-border-strong eldra:hover:border-text eldra:focus:border-text`;
|
|
564
|
+
/** The error boundary alone; `fieldState` pairs it with the live or the read-only fill. */
|
|
565
|
+
var FIELD_INVALID = "eldra:border-danger eldra:hover:border-danger eldra:focus:border-danger";
|
|
566
|
+
var FIELD_DISABLED = "eldra:bg-surface-strong eldra:border-border eldra:border-dashed eldra:text-muted eldra:cursor-not-allowed";
|
|
567
|
+
var FIELD_READONLY = `${FIELD_READONLY_FILL} eldra:border-border`;
|
|
568
|
+
/** The one state recipe a field box is in. `invalid` is the shown error, never set while disabled. */
|
|
569
|
+
function fieldState(state) {
|
|
570
|
+
if (state.disabled) return FIELD_DISABLED;
|
|
571
|
+
if (state.readonly) return state.invalid ? `${FIELD_READONLY_FILL} ${FIELD_INVALID}` : FIELD_READONLY;
|
|
572
|
+
return state.invalid ? `${FIELD_LIVE_FILL} ${FIELD_INVALID}` : FIELD_LIVE;
|
|
573
|
+
}
|
|
574
|
+
/** Spec "Input" → Variants, `search`: "The browser's own clear button is hidden." */
|
|
575
|
+
var FIELD_SEARCH_APPEARANCE = "eldra:[&::-webkit-search-cancel-button]:appearance-none eldra:[&::-webkit-search-decoration]:appearance-none";
|
|
576
|
+
/**
|
|
577
|
+
* A ghost icon button at the field's end edge (spec "Input" → Anatomy): square, `muted`, the ring.
|
|
578
|
+
* `cursor-pointer` (operator report, 2026-09-25; recorded under Deviations in the README): Tailwind
|
|
579
|
+
* v4's preflight sets `button { cursor: default }`, so without it every clear button in the
|
|
580
|
+
* package — `Input`'s, `SearchBar`'s and `UnitInput`'s (`CurrencyInput` wraps the last) — showed
|
|
581
|
+
* the default arrow rather than a pointer.
|
|
582
|
+
*/
|
|
583
|
+
var FIELD_CLEAR_BUTTON_BOX = "eldra:shrink-0 eldra:items-center eldra:justify-center eldra:text-muted eldra:hover:text-text eldra:cursor-pointer eldra:hover:bg-[color-mix(in_oklab,var(--eldra-color-text),transparent_94%)] eldra:eldra-focus";
|
|
584
|
+
/** The whole button. A field that shows or rounds it its own way takes `FIELD_CLEAR_BUTTON_BOX`. */
|
|
585
|
+
var FIELD_CLEAR_BUTTON = `eldra:inline-flex ${FIELD_CLEAR_BUTTON_BOX} eldra:rounded-[var(--eldra-radius-sm)]`;
|
|
586
|
+
/** 1.125rem, `muted`, 0.6875rem from the start edge, and out of the pointer's way. */
|
|
587
|
+
var FIELD_LEADING_ICON = "eldra:absolute eldra:start-2.75 eldra:inset-y-0 eldra:my-auto eldra:flex eldra:h-4.5 eldra:w-4.5 eldra:items-center eldra:justify-center eldra:text-muted eldra:pointer-events-none";
|
|
588
|
+
/**
|
|
589
|
+
* The end-edge area, 0.25rem from the edge (spec "Input" → Anatomy, "Trailing action"). The clear
|
|
590
|
+
* button and the `suffix` slot share it, so a field that has both keeps them on one row in reading
|
|
591
|
+
* order — which is also the tab order the Keyboard table asks for: the input first, the clear
|
|
592
|
+
* button next.
|
|
593
|
+
*
|
|
594
|
+
* `gap-1` is the shared default: `Input`'s own doc comment documents `clearable`/`type="search"`
|
|
595
|
+
* plus a populated `suffix` slot as first-class ("the clear button and the `suffix` slot share it,
|
|
596
|
+
* so a field with both keeps them on one row"), and this constant is `Input`'s and `SearchBar`'s
|
|
597
|
+
* row too — dropping the gap here would silently change `Input`'s rendered output for that
|
|
598
|
+
* combination, which an early review caught. Only `UnitInput`'s two-action pair (see
|
|
599
|
+
* `FIELD_TRAILING_PAD_PAIR` above) wants flush icons, and it builds its row from
|
|
600
|
+
* `FIELD_SUFFIX_ROW_BASE` with `gap-0` rather than changing the shared default.
|
|
601
|
+
*/
|
|
602
|
+
var FIELD_SUFFIX_ROW_BASE = "eldra:absolute eldra:end-1 eldra:inset-y-0 eldra:my-auto eldra:flex eldra:items-center";
|
|
603
|
+
var FIELD_SUFFIX_ROW = `${FIELD_SUFFIX_ROW_BASE} eldra:gap-1`;
|
|
604
|
+
/**
|
|
605
|
+
* The start-edge mirror of `FIELD_SUFFIX_ROW`, for the `prefix` slot: interactive content (a
|
|
606
|
+
* calendar button) 0.25rem from the start edge, so unlike `FIELD_LEADING_ICON` it keeps the pointer.
|
|
607
|
+
*/
|
|
608
|
+
var FIELD_PREFIX_ROW = "eldra:absolute eldra:start-1 eldra:inset-y-0 eldra:my-auto eldra:flex eldra:items-center eldra:gap-1";
|
|
609
|
+
/** The start padding a `prefix` row reserves: the trailing action's room, mirrored. */
|
|
610
|
+
var FIELD_PREFIX_PAD = {
|
|
611
|
+
sm: "eldra:ps-8",
|
|
612
|
+
md: "eldra:ps-10",
|
|
613
|
+
lg: "eldra:ps-10"
|
|
614
|
+
};
|
|
615
|
+
/** `FIELD_TRAILING_PAD`/`FIELD_PREFIX_PAD` in rem, for `useAdornmentRoom`'s comparison. */
|
|
616
|
+
var FIELD_ACTION_ROOM_REM = {
|
|
617
|
+
sm: 2,
|
|
618
|
+
md: 2.5,
|
|
619
|
+
lg: 2.5
|
|
620
|
+
};
|
|
621
|
+
// src/components/select/panelParts.ts
|
|
622
|
+
/**
|
|
623
|
+
* Every class the **panel** of a select draws, in one place, because `Select` and `MultiSelect`
|
|
624
|
+
* draw the same panel. They are plain functions rather than computeds so that both `SelectPanel`
|
|
625
|
+
* (which renders the panel) and a trigger (which reuses an option's swatch and icon for the chosen
|
|
626
|
+
* option's mark) can call them.
|
|
627
|
+
*
|
|
628
|
+
* Each returns a Vue class value with the consumer's per-part classes appended last.
|
|
629
|
+
*/
|
|
630
|
+
/**
|
|
631
|
+
* The popover (spec "Select" → Sizes, Popover row). Not a dialog: it is a non-modal popup
|
|
632
|
+
* (non-negotiable 2), positioned by `useFloating` against the trigger.
|
|
633
|
+
*
|
|
634
|
+
* It is **teleported** — to `body`, or to the open `<dialog>` the control sits in — so that no
|
|
635
|
+
* ancestor's `overflow: hidden` clips it and no later stacking context paints over it. `absolute`
|
|
636
|
+
* stays in the class list because it is what a `teleport: false` panel needs; the inline
|
|
637
|
+
* `position` `useFloating` writes (`fixed` once teleported) is on the element itself and wins
|
|
638
|
+
* over it either way. `z-popover` puts it over the sticky header, `overflow-hidden` keeps the
|
|
639
|
+
* search field's top corners on the popover's radius, and the list — not the panel — is what
|
|
640
|
+
* scrolls.
|
|
641
|
+
*
|
|
642
|
+
* Because the panel leaves the control's subtree, a consumer's `classes`/`data-part` styling still
|
|
643
|
+
* reaches it (both are on the element), but a **descendant selector rooted above the control does
|
|
644
|
+
* not**, and neither do custom properties set on a wrapper: set `--eldra-*` overrides on `:root`
|
|
645
|
+
* (or on the teleport target), which is what the README's Customisation section already asks for.
|
|
646
|
+
*/
|
|
647
|
+
function panelClass(classes) {
|
|
648
|
+
return [
|
|
649
|
+
"eldra:absolute eldra:z-popover eldra:flex eldra:flex-col eldra:overflow-hidden",
|
|
650
|
+
"eldra:eldra-select-panel-height eldra:eldra-select-panel-width",
|
|
651
|
+
"eldra:rounded-md eldra:border eldra:shadow-md",
|
|
652
|
+
"eldra:border-[color:var(--eldra-select-panel-border,var(--eldra-color-border))]",
|
|
653
|
+
"eldra:bg-[color:var(--eldra-select-panel-background,var(--eldra-color-background))]",
|
|
654
|
+
"eldra:text-[color:var(--eldra-select-panel-text)]",
|
|
655
|
+
"eldra:animate-eldra-popover-in",
|
|
656
|
+
classes?.panel
|
|
657
|
+
];
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* Spec "Select" → Sizes, Search field: 2.5rem tall, text from 2.125rem. No focus ring (a README
|
|
661
|
+
* Deviation): focus sits here whenever the panel is open, so the caret and the active row show it.
|
|
662
|
+
*/
|
|
663
|
+
function searchClass(classes) {
|
|
664
|
+
return [
|
|
665
|
+
"eldra:control-h eldra:w-full eldra:min-w-0 eldra:rounded-t-md eldra:bg-transparent eldra:ps-8.5 eldra:pe-3",
|
|
666
|
+
"eldra:text-control-sm eldra:max-md:text-control-mobile",
|
|
667
|
+
"eldra:text-[color:var(--eldra-select-panel-text,var(--eldra-color-text))]",
|
|
668
|
+
"eldra:placeholder:text-[color:var(--eldra-select-panel-muted,var(--eldra-color-muted))]",
|
|
669
|
+
"eldra:outline-none",
|
|
670
|
+
classes?.search
|
|
671
|
+
];
|
|
672
|
+
}
|
|
673
|
+
function listboxClass(classes, hasOptions) {
|
|
674
|
+
return [
|
|
675
|
+
"eldra:overflow-y-auto eldra:overscroll-contain",
|
|
676
|
+
hasOptions ? "eldra:min-h-0 eldra:flex-1 eldra:p-1" : "eldra:h-0",
|
|
677
|
+
classes?.listbox
|
|
678
|
+
];
|
|
679
|
+
}
|
|
680
|
+
/** Spec: "Every group after the first gets a 1px `border` hairline and 0.25rem gap above it." */
|
|
681
|
+
function groupClass(classes, index) {
|
|
682
|
+
return [index > 0 && "eldra:mt-1 eldra:border-t eldra:border-[color:var(--eldra-select-panel-border,var(--eldra-color-border))]", classes?.group];
|
|
683
|
+
}
|
|
684
|
+
function groupLabelClass(classes, index) {
|
|
685
|
+
return [
|
|
686
|
+
"eldra:text-select-group eldra:px-2 eldra:pb-1",
|
|
687
|
+
"eldra:text-[color:var(--eldra-select-panel-muted,var(--eldra-color-muted))]",
|
|
688
|
+
index > 0 ? "eldra:pt-2.5" : "eldra:pt-2",
|
|
689
|
+
classes?.groupLabel
|
|
690
|
+
];
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* Spec "Select" → Sizes, Option row, and → States for active / selected / disabled.
|
|
694
|
+
*
|
|
695
|
+
* `multiple` is the one difference the spec draws between the two controls' rows: a multi-select's
|
|
696
|
+
* selection is carried by the filled box, so its label is "weight 500 (not 600)" (spec
|
|
697
|
+
* "Multi-select" → States, Option selected).
|
|
698
|
+
*/
|
|
699
|
+
function optionClass(classes, option, state) {
|
|
700
|
+
return [
|
|
701
|
+
"eldra:flex eldra:min-h-9 eldra:scroll-my-1 eldra:items-center eldra:gap-2 eldra:rounded-sm eldra:px-2 eldra:py-1.5 eldra:text-select-option",
|
|
702
|
+
state.active && "eldra:bg-[color:var(--eldra-select-panel-active,var(--eldra-color-surface-strong))] eldra:eldra-select-option-active",
|
|
703
|
+
state.selected && (state.multiple ? "eldra:font-medium" : "eldra:font-semibold"),
|
|
704
|
+
state.selected && "eldra:eldra-select-option-selected",
|
|
705
|
+
option.disabled === true ? "eldra:text-[color:var(--eldra-select-panel-muted,var(--eldra-color-muted))] eldra:cursor-not-allowed" : "eldra:text-[color:var(--eldra-select-panel-text,var(--eldra-color-text))] eldra:cursor-pointer",
|
|
706
|
+
classes?.option
|
|
707
|
+
];
|
|
708
|
+
}
|
|
709
|
+
/** A disabled row reads as disabled through the row's `muted` text and cursor, like `Checkbox`. */
|
|
710
|
+
function optionLabelClass(classes) {
|
|
711
|
+
return ["eldra:block", classes?.optionLabel];
|
|
712
|
+
}
|
|
713
|
+
function optionHintClass(classes) {
|
|
714
|
+
return ["eldra:text-caption eldra:block eldra:text-[color:var(--eldra-select-panel-muted,var(--eldra-color-muted))]", classes?.optionHint];
|
|
715
|
+
}
|
|
716
|
+
var META_TONE = {
|
|
717
|
+
warning: "eldra:text-warning eldra:font-semibold",
|
|
718
|
+
danger: "eldra:text-danger eldra:font-semibold"
|
|
719
|
+
};
|
|
720
|
+
function optionMetaClass(classes, option) {
|
|
721
|
+
return [
|
|
722
|
+
"eldra:ms-3 eldra:shrink-0 eldra:text-caption eldra:tabular-nums",
|
|
723
|
+
option.metaTone === void 0 ? "eldra:text-[color:var(--eldra-select-panel-muted,var(--eldra-color-muted))]" : META_TONE[option.metaTone],
|
|
724
|
+
classes?.optionMeta
|
|
725
|
+
];
|
|
726
|
+
}
|
|
727
|
+
function optionSwatchClass(classes) {
|
|
728
|
+
return ["eldra:size-4 eldra:shrink-0 eldra:rounded-full eldra:eldra-select-swatch", classes?.optionSwatch];
|
|
729
|
+
}
|
|
730
|
+
function optionIconClass(classes) {
|
|
731
|
+
return ["eldra:size-4.5 eldra:shrink-0", classes?.optionIcon];
|
|
732
|
+
}
|
|
733
|
+
/** Spec "Select" → States, Option selected: "check mark in `text` (never colour alone)". */
|
|
734
|
+
function optionCheckClass(classes) {
|
|
735
|
+
return ["eldra:size-4.5 eldra:shrink-0 eldra:text-[color:var(--eldra-select-panel-check,var(--eldra-color-text))]", classes?.optionCheck];
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* A multi-select option's checkbox (spec "Multi-select" → Sizes, "Checkbox in option"): "1rem
|
|
739
|
+
* square, 1.5px `border-strong`, 0.25rem radius, `background` fill. Checked: `primary` fill and
|
|
740
|
+
* border with a `primary-contrast` tick."
|
|
741
|
+
*
|
|
742
|
+
* It is the `optionCheck` part — the same part a single select's check mark is — so "the mark that
|
|
743
|
+
* says this row is chosen" is one styling hook in both controls. The border width is `Checkbox`'s
|
|
744
|
+
* own `eldra-checkbox-border`, so a consumer that has restyled their checkboxes' boundary has
|
|
745
|
+
* restyled these; the radius is the spec's smaller 0.25rem, on its own variable.
|
|
746
|
+
*/
|
|
747
|
+
function optionBoxClass(classes, state) {
|
|
748
|
+
return [
|
|
749
|
+
"eldra:relative eldra:inline-flex eldra:size-4 eldra:shrink-0 eldra:items-center eldra:justify-center",
|
|
750
|
+
"eldra:eldra-checkbox-border eldra:eldra-select-check-radius",
|
|
751
|
+
"eldra:transition-colors eldra:duration-fast eldra:ease-out",
|
|
752
|
+
state.selected && state.disabled ? "eldra:bg-muted eldra:border-muted" : state.selected ? "eldra:bg-[color:var(--eldra-select-panel-check,var(--eldra-color-primary))] eldra:border-[color:var(--eldra-select-panel-check,var(--eldra-color-primary))]" : state.disabled ? "eldra:bg-surface-strong eldra:border-border eldra:border-dashed" : "eldra:bg-[color:var(--eldra-select-panel-background,var(--eldra-color-background))] eldra:border-[color:var(--eldra-select-panel-check-border,var(--eldra-color-border-strong))]",
|
|
753
|
+
classes?.optionCheck
|
|
754
|
+
];
|
|
755
|
+
}
|
|
756
|
+
/** Spec "Select" → Sizes, Empty state: "0.875rem, `muted`, centred, padding 1rem 0.75rem". */
|
|
757
|
+
function emptyClass(classes) {
|
|
758
|
+
return ["eldra:px-3 eldra:py-4 eldra:text-center eldra:text-body-sm eldra:text-[color:var(--eldra-select-panel-muted,var(--eldra-color-muted))]", classes?.empty];
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
* The loading row: the empty state's box, with the shared spinner before its text. It stands in
|
|
762
|
+
* for the list and the empty state while a `loading` control's options are being fetched.
|
|
763
|
+
*/
|
|
764
|
+
function loadingClass(classes) {
|
|
765
|
+
return ["eldra:flex eldra:items-center eldra:justify-center eldra:gap-2 eldra:px-3 eldra:py-4 eldra:text-body-sm eldra:text-[color:var(--eldra-select-panel-muted,var(--eldra-color-muted))]", classes?.loading];
|
|
766
|
+
}
|
|
767
|
+
/**
|
|
768
|
+
* The "Create “query”" row of a `creatable` control: an option row's own box and active fill, with
|
|
769
|
+
* a `plus` where a row draws its mark. After other rows it sits under a group's hairline (drawn
|
|
770
|
+
* by `SelectPanel`), so it reads as an action rather than one more match.
|
|
771
|
+
*/
|
|
772
|
+
function createOptionClass(classes, state) {
|
|
773
|
+
return [
|
|
774
|
+
"eldra:flex eldra:min-h-9 eldra:scroll-my-1 eldra:items-center eldra:gap-2 eldra:rounded-sm eldra:px-2 eldra:py-1.5 eldra:text-select-option",
|
|
775
|
+
"eldra:text-[color:var(--eldra-select-panel-text,var(--eldra-color-text))] eldra:cursor-pointer",
|
|
776
|
+
state.active && "eldra:bg-[color:var(--eldra-select-panel-active,var(--eldra-color-surface-strong))] eldra:eldra-select-option-active",
|
|
777
|
+
classes?.createOption
|
|
778
|
+
];
|
|
779
|
+
}
|
|
780
|
+
/**
|
|
781
|
+
* The tick inside that box (spec "Multi-select" → Sizes: "a `primary-contrast` tick (0.25 × 0.5rem,
|
|
782
|
+
* 2px stroke)").
|
|
783
|
+
*
|
|
784
|
+
* The svg is drawn 0.5rem square — `size-2` on the 0.25rem spacing step — over an 8 × 8 viewBox,
|
|
785
|
+
* so one viewBox unit is one pixel of the drawn mark and `stroke-width="2"` is the spec's 2px.
|
|
786
|
+
* (The same relationship `Checkbox` has at its own larger size; a 10-unit viewBox squeezed into
|
|
787
|
+
* 0.5rem would render that same `2` as 1.6px.) The mark is Tabler's check at 3 : 2 — 0.5 × 0.375rem
|
|
788
|
+
* of ink rather than the spec's literal 0.5 × 0.25rem, which read flat (see `Checkbox.vue`).
|
|
789
|
+
*
|
|
790
|
+
* It is always rendered and scaled from 0, rather than added and removed, so it can grow in over
|
|
791
|
+
* `duration-fast` the way `Checkbox`'s does.
|
|
792
|
+
*/
|
|
793
|
+
function optionTickClass(selected) {
|
|
794
|
+
return [
|
|
795
|
+
"eldra:text-[color:var(--eldra-select-panel-check-contrast,var(--eldra-color-primary-contrast))]",
|
|
796
|
+
"eldra:pointer-events-none eldra:size-2 eldra:transition-transform eldra:duration-fast eldra:ease-out",
|
|
797
|
+
selected ? "eldra:scale-100" : "eldra:scale-0"
|
|
798
|
+
];
|
|
799
|
+
}
|
|
800
|
+
/**
|
|
801
|
+
* The cell a trigger stacks its chosen value in, with an invisible copy of the placeholder
|
|
802
|
+
* (`data-placeholder`, drawn by `::after`) in the same grid cell: a content-sized trigger keeps at
|
|
803
|
+
* least its placeholder's width once a value is chosen, as a native input keeps its width. The copy
|
|
804
|
+
* is generated content under `visibility: hidden`, so it adds no text and no accessible name.
|
|
805
|
+
*/
|
|
806
|
+
var TRIGGER_VALUE_STACK = "eldra:relative eldra:grid eldra:min-w-0 eldra:flex-1 eldra:grid-cols-[minmax(0,1fr)] eldra:items-center eldra:after:invisible eldra:after:col-start-1 eldra:after:row-start-1 eldra:after:truncate eldra:after:content-[attr(data-placeholder)]";
|
|
807
|
+
/** The chosen value inside `TRIGGER_VALUE_STACK`, in the cell the placeholder copy shares. */
|
|
808
|
+
var TRIGGER_VALUE_CELL = "eldra:col-start-1 eldra:row-start-1";
|
|
809
|
+
// src/components/select/SelectPanel.vue?vue&type=script&setup=true&lang.ts
|
|
810
|
+
var _hoisted_1 = [
|
|
811
|
+
"data-eldra-slot",
|
|
812
|
+
"id",
|
|
813
|
+
"data-eldra-scope",
|
|
814
|
+
"data-eldra-overlay-owner",
|
|
815
|
+
"data-placement"
|
|
816
|
+
];
|
|
817
|
+
var _hoisted_2 = ["data-eldra-scope"];
|
|
818
|
+
var _hoisted_3 = [
|
|
819
|
+
"value",
|
|
820
|
+
"placeholder",
|
|
821
|
+
"aria-label",
|
|
822
|
+
"aria-controls",
|
|
823
|
+
"aria-activedescendant"
|
|
824
|
+
];
|
|
825
|
+
var _hoisted_4 = [
|
|
826
|
+
"data-eldra-scope",
|
|
827
|
+
"id",
|
|
828
|
+
"aria-multiselectable",
|
|
829
|
+
"aria-labelledby",
|
|
830
|
+
"aria-label",
|
|
831
|
+
"aria-busy"
|
|
832
|
+
];
|
|
833
|
+
var _hoisted_5 = [
|
|
834
|
+
"data-part",
|
|
835
|
+
"role",
|
|
836
|
+
"aria-labelledby"
|
|
837
|
+
];
|
|
838
|
+
var _hoisted_6 = ["id"];
|
|
839
|
+
var _hoisted_7 = [
|
|
840
|
+
"data-eldra-slot",
|
|
841
|
+
"id",
|
|
842
|
+
"aria-selected",
|
|
843
|
+
"aria-disabled",
|
|
844
|
+
"onClick",
|
|
845
|
+
"onMouseenter"
|
|
846
|
+
];
|
|
847
|
+
var _hoisted_8 = ["data-eldra-scope"];
|
|
848
|
+
var _hoisted_9 = { class: "eldra:min-w-0 eldra:flex-1" };
|
|
849
|
+
var _hoisted_10 = { class: "eldra:eldra-select-match" };
|
|
850
|
+
var _hoisted_11 = ["data-eldra-scope"];
|
|
851
|
+
var _hoisted_12 = ["id"];
|
|
852
|
+
var _hoisted_13 = { class: "eldra:min-w-0 eldra:flex-1 eldra:truncate" };
|
|
853
|
+
var _hoisted_14 = ["data-eldra-slot", "data-eldra-scope"];
|
|
854
|
+
var _hoisted_15 = ["data-eldra-slot", "data-eldra-scope"];
|
|
855
|
+
var SCROLL_END_SLACK = 80;
|
|
856
|
+
var FOCUSABLE$1 = "input, button, a[href], textarea, select, [tabindex]:not([tabindex^=\"-\"])";
|
|
857
|
+
// src/components/select/SelectPanel.vue
|
|
858
|
+
var SelectPanel_default = /* @__PURE__ */ defineComponent({
|
|
859
|
+
__name: "SelectPanel",
|
|
860
|
+
props: {
|
|
861
|
+
panelId: {},
|
|
862
|
+
listboxId: {},
|
|
863
|
+
sections: {},
|
|
864
|
+
hasOptions: { type: Boolean },
|
|
865
|
+
highlights: {},
|
|
866
|
+
optionId: {},
|
|
867
|
+
activeValue: { default: void 0 },
|
|
868
|
+
selectedValues: {},
|
|
869
|
+
searchable: { type: Boolean },
|
|
870
|
+
query: {},
|
|
871
|
+
searchPlaceholder: {},
|
|
872
|
+
emptyText: {},
|
|
873
|
+
labelledBy: { default: void 0 },
|
|
874
|
+
fallbackLabel: { default: void 0 },
|
|
875
|
+
multiple: {
|
|
876
|
+
type: Boolean,
|
|
877
|
+
default: false
|
|
878
|
+
},
|
|
879
|
+
loading: {
|
|
880
|
+
type: Boolean,
|
|
881
|
+
default: false
|
|
882
|
+
},
|
|
883
|
+
loadingText: { default: void 0 },
|
|
884
|
+
createOption: { default: void 0 },
|
|
885
|
+
createText: { default: void 0 },
|
|
886
|
+
panelStyle: { default: void 0 },
|
|
887
|
+
placement: { default: void 0 },
|
|
888
|
+
classes: { default: void 0 }
|
|
889
|
+
},
|
|
890
|
+
emits: [
|
|
891
|
+
"search",
|
|
892
|
+
"select",
|
|
893
|
+
"activate",
|
|
894
|
+
"keydown",
|
|
895
|
+
"scrollEnd"
|
|
896
|
+
],
|
|
897
|
+
setup(__props, { expose: __expose, emit: __emit }) {
|
|
898
|
+
const eldra = useEldraScope();
|
|
899
|
+
/**
|
|
900
|
+
* The popover a `Select` and a `MultiSelect` both open: the search field, the listbox with its
|
|
901
|
+
* groups and option rows, and the empty state — plus a `footer` slot, which only a multi-select
|
|
902
|
+
* fills.
|
|
903
|
+
*
|
|
904
|
+
* It exists so that the two controls share one panel rather than two copies of the same markup.
|
|
905
|
+
* Everything it knows is a prop: it owns no open/closed state, no query, no value, and no keyboard
|
|
906
|
+
* (that is `useListbox`). What it does own is the DOM the parents cannot: the panel element and
|
|
907
|
+
* the search input, both exposed so the parent can position the one and focus the other, and the
|
|
908
|
+
* pointer-press guard that keeps a press inside the panel from blurring the focused element.
|
|
909
|
+
*
|
|
910
|
+
* `multiple` is the one behavioural switch, and it is the spec's own: a multi-select's rows carry a
|
|
911
|
+
* checkbox instead of a trailing check mark, and its listbox is `aria-multiselectable="true"`.
|
|
912
|
+
*/
|
|
913
|
+
const props = __props;
|
|
914
|
+
const emit = __emit;
|
|
915
|
+
const root = ref(null);
|
|
916
|
+
const searchInput = ref(null);
|
|
917
|
+
__expose({
|
|
918
|
+
root,
|
|
919
|
+
searchInput
|
|
920
|
+
});
|
|
921
|
+
const isActive = (option) => props.activeValue === option.value;
|
|
922
|
+
const isSelected = (option) => props.selectedValues.includes(option.value);
|
|
923
|
+
const panelClasses = computed(() => panelClass(props.classes));
|
|
924
|
+
const searchClasses = computed(() => searchClass(props.classes));
|
|
925
|
+
const listboxClasses = computed(() => listboxClass(props.classes, props.hasOptions));
|
|
926
|
+
const optionHintClasses = computed(() => optionHintClass(props.classes));
|
|
927
|
+
const optionSwatchClasses = computed(() => optionSwatchClass(props.classes));
|
|
928
|
+
const optionIconClasses = computed(() => optionIconClass(props.classes));
|
|
929
|
+
const optionCheckClasses = computed(() => optionCheckClass(props.classes));
|
|
930
|
+
const emptyClasses = computed(() => emptyClass(props.classes));
|
|
931
|
+
const loadingClasses = computed(() => loadingClass(props.classes));
|
|
932
|
+
const createClasses = computed(() => props.createOption === void 0 ? "" : createOptionClass(props.classes, { active: isActive(props.createOption) }));
|
|
933
|
+
/** Within this many pixels of the end — two rows — the next render batch is asked for. */
|
|
934
|
+
function onListScroll(event) {
|
|
935
|
+
const list = event.currentTarget;
|
|
936
|
+
if (list.scrollHeight - list.scrollTop - list.clientHeight <= SCROLL_END_SLACK) emit("scrollEnd");
|
|
937
|
+
}
|
|
938
|
+
const rowClass = (option) => optionClass(props.classes, option, {
|
|
939
|
+
active: isActive(option),
|
|
940
|
+
selected: isSelected(option),
|
|
941
|
+
multiple: props.multiple
|
|
942
|
+
});
|
|
943
|
+
const boxClass = (option) => optionBoxClass(props.classes, {
|
|
944
|
+
selected: isSelected(option),
|
|
945
|
+
disabled: option.disabled === true
|
|
946
|
+
});
|
|
947
|
+
/**
|
|
948
|
+
* Spec "Select" → Behaviour: "The active option is scrolled into view with a 0.25rem margin
|
|
949
|
+
* whenever it changes" — the margin is the row's own `scroll-my-1`.
|
|
950
|
+
*
|
|
951
|
+
* It lives here rather than in either parent because it is the one part of "the active row" that
|
|
952
|
+
* needs an element, and the panel is what has the elements. Both controls get it from one copy.
|
|
953
|
+
*/
|
|
954
|
+
function scrollActiveIntoView() {
|
|
955
|
+
const value = props.activeValue;
|
|
956
|
+
if (value === void 0 || typeof document === "undefined") return;
|
|
957
|
+
document.getElementById(props.optionId(value))?.scrollIntoView?.({ block: "nearest" });
|
|
958
|
+
}
|
|
959
|
+
onMounted(scrollActiveIntoView);
|
|
960
|
+
watch(() => props.activeValue, () => void nextTick(scrollActiveIntoView));
|
|
961
|
+
function onSearchInput(event) {
|
|
962
|
+
emit("search", event.target.value);
|
|
963
|
+
}
|
|
964
|
+
/**
|
|
965
|
+
* Anything inside the panel that wants the pointer's default action: it takes focus, or places a
|
|
966
|
+
* caret. The search field and — in a multi-select — the footer's Clear and Done buttons.
|
|
967
|
+
*/
|
|
968
|
+
function onPanelMouseDown(event) {
|
|
969
|
+
const target = event.target;
|
|
970
|
+
if (target instanceof Element && target.closest(FOCUSABLE$1) !== null) return;
|
|
971
|
+
event.preventDefault();
|
|
972
|
+
}
|
|
973
|
+
return (_ctx, _cache) => {
|
|
974
|
+
return openBlock(), createElementBlock("div", {
|
|
975
|
+
ref_key: "root",
|
|
976
|
+
ref: root,
|
|
977
|
+
"data-eldra-slot": unref(eldra).slotHost("footer"),
|
|
978
|
+
id: __props.panelId,
|
|
979
|
+
"data-eldra-ui": "",
|
|
980
|
+
"data-eldra-scope": unref(eldra).scope,
|
|
981
|
+
"data-part": "panel",
|
|
982
|
+
"data-eldra-overlay-owner": __props.panelId,
|
|
983
|
+
class: normalizeClass(panelClasses.value),
|
|
984
|
+
style: normalizeStyle(__props.panelStyle),
|
|
985
|
+
"data-placement": __props.placement,
|
|
986
|
+
onMousedown: onPanelMouseDown
|
|
987
|
+
}, [
|
|
988
|
+
__props.searchable ? (openBlock(), createElementBlock("div", {
|
|
989
|
+
key: 0,
|
|
990
|
+
"data-eldra-scope": unref(eldra).scope,
|
|
991
|
+
class: "eldra:relative eldra:shrink-0 eldra:border-b eldra:border-[color:var(--eldra-select-panel-border,var(--eldra-color-border))]"
|
|
992
|
+
}, [_cache[3] || (_cache[3] = createElementVNode("svg", {
|
|
993
|
+
class: "eldra:pointer-events-none eldra:absolute eldra:inset-y-0 eldra:start-2.5 eldra:my-auto eldra:size-4 eldra:text-[color:var(--eldra-select-panel-muted,var(--eldra-color-muted))]",
|
|
994
|
+
viewBox: "0 0 24 24",
|
|
995
|
+
fill: "none",
|
|
996
|
+
stroke: "currentColor",
|
|
997
|
+
"stroke-width": "1.75",
|
|
998
|
+
"stroke-linecap": "round",
|
|
999
|
+
"stroke-linejoin": "round",
|
|
1000
|
+
"aria-hidden": "true",
|
|
1001
|
+
focusable: "false"
|
|
1002
|
+
}, [createElementVNode("path", { d: "M10 10m-7 0a7 7 0 1 0 14 0a7 7 0 1 0 -14 0" }), createElementVNode("path", { d: "M21 21l-6 -6" })], -1)), createElementVNode("input", {
|
|
1003
|
+
ref_key: "searchInput",
|
|
1004
|
+
ref: searchInput,
|
|
1005
|
+
"data-part": "search",
|
|
1006
|
+
type: "text",
|
|
1007
|
+
role: "combobox",
|
|
1008
|
+
class: normalizeClass(searchClasses.value),
|
|
1009
|
+
value: __props.query,
|
|
1010
|
+
placeholder: __props.searchPlaceholder,
|
|
1011
|
+
"aria-label": __props.searchPlaceholder,
|
|
1012
|
+
"aria-autocomplete": "list",
|
|
1013
|
+
"aria-expanded": "true",
|
|
1014
|
+
"aria-controls": __props.listboxId,
|
|
1015
|
+
"aria-activedescendant": __props.activeValue === void 0 ? void 0 : __props.optionId(__props.activeValue),
|
|
1016
|
+
autocomplete: "off",
|
|
1017
|
+
spellcheck: "false",
|
|
1018
|
+
onInput: onSearchInput,
|
|
1019
|
+
onKeydown: _cache[0] || (_cache[0] = ($event) => emit("keydown", $event))
|
|
1020
|
+
}, null, 42, _hoisted_3)], 8, _hoisted_2)) : createCommentVNode("", true),
|
|
1021
|
+
createElementVNode("div", {
|
|
1022
|
+
"data-eldra-scope": unref(eldra).scope,
|
|
1023
|
+
id: __props.listboxId,
|
|
1024
|
+
"data-part": "listbox",
|
|
1025
|
+
role: "listbox",
|
|
1026
|
+
class: normalizeClass(listboxClasses.value),
|
|
1027
|
+
"aria-multiselectable": __props.multiple ? "true" : void 0,
|
|
1028
|
+
"aria-labelledby": __props.labelledBy,
|
|
1029
|
+
"aria-label": __props.fallbackLabel,
|
|
1030
|
+
"aria-busy": __props.loading ? "true" : void 0,
|
|
1031
|
+
onScrollPassive: onListScroll
|
|
1032
|
+
}, [(openBlock(true), createElementBlock(Fragment, null, renderList(__props.sections, (section, sectionIndex) => {
|
|
1033
|
+
return openBlock(), createElementBlock("div", {
|
|
1034
|
+
key: section.key,
|
|
1035
|
+
"data-part": section.label ? "group" : void 0,
|
|
1036
|
+
role: section.label ? "group" : "presentation",
|
|
1037
|
+
class: normalizeClass(section.label ? unref(groupClass)(__props.classes, sectionIndex) : void 0),
|
|
1038
|
+
"aria-labelledby": section.labelId
|
|
1039
|
+
}, [section.label ? (openBlock(), createElementBlock("div", {
|
|
1040
|
+
key: 0,
|
|
1041
|
+
id: section.labelId,
|
|
1042
|
+
"data-part": "groupLabel",
|
|
1043
|
+
role: "presentation",
|
|
1044
|
+
class: normalizeClass(unref(groupLabelClass)(__props.classes, sectionIndex))
|
|
1045
|
+
}, toDisplayString(section.label), 11, _hoisted_6)) : createCommentVNode("", true), (openBlock(true), createElementBlock(Fragment, null, renderList(section.options, (option) => {
|
|
1046
|
+
return openBlock(), createElementBlock("div", {
|
|
1047
|
+
key: option.value,
|
|
1048
|
+
"data-eldra-slot": unref(eldra).slotHost("option", "optionContent"),
|
|
1049
|
+
id: __props.optionId(option.value),
|
|
1050
|
+
"data-part": "option",
|
|
1051
|
+
role: "option",
|
|
1052
|
+
class: normalizeClass(rowClass(option)),
|
|
1053
|
+
"aria-selected": isSelected(option) ? "true" : "false",
|
|
1054
|
+
"aria-disabled": option.disabled ? "true" : void 0,
|
|
1055
|
+
onClick: ($event) => emit("select", option),
|
|
1056
|
+
onMouseenter: ($event) => option.disabled ? void 0 : emit("activate", option.value)
|
|
1057
|
+
}, [renderSlot(_ctx.$slots, "option", {
|
|
1058
|
+
option,
|
|
1059
|
+
selected: isSelected(option),
|
|
1060
|
+
active: isActive(option)
|
|
1061
|
+
}, () => [
|
|
1062
|
+
__props.multiple ? (openBlock(), createElementBlock("span", {
|
|
1063
|
+
key: 0,
|
|
1064
|
+
"data-eldra-scope": unref(eldra).scope,
|
|
1065
|
+
"data-part": "optionCheck",
|
|
1066
|
+
class: normalizeClass(boxClass(option)),
|
|
1067
|
+
"aria-hidden": "true"
|
|
1068
|
+
}, [(openBlock(), createElementBlock("svg", {
|
|
1069
|
+
class: normalizeClass(unref(optionTickClass)(isSelected(option))),
|
|
1070
|
+
viewBox: "0 0 8 8",
|
|
1071
|
+
fill: "none",
|
|
1072
|
+
stroke: "currentColor",
|
|
1073
|
+
"stroke-width": "2",
|
|
1074
|
+
"stroke-linecap": "round",
|
|
1075
|
+
"stroke-linejoin": "round",
|
|
1076
|
+
"aria-hidden": "true",
|
|
1077
|
+
focusable: "false"
|
|
1078
|
+
}, [..._cache[4] || (_cache[4] = [createElementVNode("path", { d: "M1 4l2 2l4 -4" }, null, -1)])], 2))], 10, _hoisted_8)) : createCommentVNode("", true),
|
|
1079
|
+
renderSlot(_ctx.$slots, "optionContent", {
|
|
1080
|
+
option,
|
|
1081
|
+
selected: isSelected(option),
|
|
1082
|
+
active: isActive(option),
|
|
1083
|
+
match: __props.highlights.get(option.value) ?? null
|
|
1084
|
+
}, () => [
|
|
1085
|
+
option.swatch ? (openBlock(), createElementBlock("span", {
|
|
1086
|
+
key: 0,
|
|
1087
|
+
"data-part": "optionSwatch",
|
|
1088
|
+
class: normalizeClass(optionSwatchClasses.value),
|
|
1089
|
+
style: normalizeStyle({ backgroundColor: option.swatch }),
|
|
1090
|
+
"aria-hidden": "true"
|
|
1091
|
+
}, null, 6)) : option.icon ? (openBlock(), createBlock(resolveDynamicComponent(option.icon), {
|
|
1092
|
+
key: 1,
|
|
1093
|
+
"data-eldra-scope": unref(eldra).scope,
|
|
1094
|
+
"data-part": "optionIcon",
|
|
1095
|
+
class: normalizeClass(optionIconClasses.value),
|
|
1096
|
+
"stroke-width": unref(ICON_STROKE_WIDTH),
|
|
1097
|
+
"aria-hidden": "true",
|
|
1098
|
+
focusable: "false"
|
|
1099
|
+
}, null, 8, [
|
|
1100
|
+
"data-eldra-scope",
|
|
1101
|
+
"class",
|
|
1102
|
+
"stroke-width"
|
|
1103
|
+
])) : createCommentVNode("", true),
|
|
1104
|
+
createElementVNode("span", _hoisted_9, [createElementVNode("span", {
|
|
1105
|
+
"data-part": "optionLabel",
|
|
1106
|
+
class: normalizeClass(unref(optionLabelClass)(__props.classes))
|
|
1107
|
+
}, [__props.highlights.get(option.value) ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
|
|
1108
|
+
createTextVNode(toDisplayString(__props.highlights.get(option.value)?.before), 1),
|
|
1109
|
+
createElementVNode("span", _hoisted_10, toDisplayString(__props.highlights.get(option.value)?.match), 1),
|
|
1110
|
+
createTextVNode(toDisplayString(__props.highlights.get(option.value)?.after), 1)
|
|
1111
|
+
], 64)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [createTextVNode(toDisplayString(option.label), 1)], 64))], 2), option.hint ? (openBlock(), createElementBlock("span", {
|
|
1112
|
+
key: 0,
|
|
1113
|
+
"data-part": "optionHint",
|
|
1114
|
+
class: normalizeClass(optionHintClasses.value)
|
|
1115
|
+
}, toDisplayString(option.hint), 3)) : createCommentVNode("", true)]),
|
|
1116
|
+
option.meta ? (openBlock(), createElementBlock("span", {
|
|
1117
|
+
key: 2,
|
|
1118
|
+
"data-part": "optionMeta",
|
|
1119
|
+
class: normalizeClass(unref(optionMetaClass)(__props.classes, option))
|
|
1120
|
+
}, toDisplayString(option.meta), 3)) : createCommentVNode("", true)
|
|
1121
|
+
]),
|
|
1122
|
+
!__props.multiple && isSelected(option) ? (openBlock(), createElementBlock("svg", {
|
|
1123
|
+
key: 1,
|
|
1124
|
+
"data-eldra-scope": unref(eldra).scope,
|
|
1125
|
+
"data-part": "optionCheck",
|
|
1126
|
+
class: normalizeClass(optionCheckClasses.value),
|
|
1127
|
+
viewBox: "0 0 24 24",
|
|
1128
|
+
fill: "none",
|
|
1129
|
+
stroke: "currentColor",
|
|
1130
|
+
"stroke-width": "1.75",
|
|
1131
|
+
"stroke-linecap": "round",
|
|
1132
|
+
"stroke-linejoin": "round",
|
|
1133
|
+
"aria-hidden": "true",
|
|
1134
|
+
focusable: "false"
|
|
1135
|
+
}, [..._cache[5] || (_cache[5] = [createElementVNode("path", { d: "M5 12l5 5l10 -10" }, null, -1)])], 10, _hoisted_11)) : createCommentVNode("", true)
|
|
1136
|
+
])], 42, _hoisted_7);
|
|
1137
|
+
}), 128))], 10, _hoisted_5);
|
|
1138
|
+
}), 128)), __props.createOption ? (openBlock(), createElementBlock("div", {
|
|
1139
|
+
key: 0,
|
|
1140
|
+
role: "presentation",
|
|
1141
|
+
class: normalizeClass(__props.sections.length > 0 ? "eldra:mt-1 eldra:border-t eldra:border-[color:var(--eldra-select-panel-border,var(--eldra-color-border))] eldra:pt-1" : void 0)
|
|
1142
|
+
}, [createElementVNode("div", {
|
|
1143
|
+
id: __props.optionId(__props.createOption.value),
|
|
1144
|
+
"data-part": "createOption",
|
|
1145
|
+
role: "option",
|
|
1146
|
+
"aria-selected": "false",
|
|
1147
|
+
class: normalizeClass(createClasses.value),
|
|
1148
|
+
onClick: _cache[1] || (_cache[1] = ($event) => emit("select", __props.createOption)),
|
|
1149
|
+
onMouseenter: _cache[2] || (_cache[2] = ($event) => emit("activate", __props.createOption.value))
|
|
1150
|
+
}, [(openBlock(), createElementBlock("svg", {
|
|
1151
|
+
class: normalizeClass(optionIconClasses.value),
|
|
1152
|
+
viewBox: "0 0 24 24",
|
|
1153
|
+
fill: "none",
|
|
1154
|
+
stroke: "currentColor",
|
|
1155
|
+
"stroke-width": "1.75",
|
|
1156
|
+
"stroke-linecap": "round",
|
|
1157
|
+
"stroke-linejoin": "round",
|
|
1158
|
+
"aria-hidden": "true",
|
|
1159
|
+
focusable: "false"
|
|
1160
|
+
}, [..._cache[6] || (_cache[6] = [createElementVNode("path", { d: "M12 5l0 14" }, null, -1), createElementVNode("path", { d: "M5 12l14 0" }, null, -1)])], 2)), createElementVNode("span", _hoisted_13, toDisplayString(__props.createText), 1)], 42, _hoisted_12)], 2)) : createCommentVNode("", true)], 42, _hoisted_4),
|
|
1161
|
+
__props.loading ? (openBlock(), createElementBlock("div", {
|
|
1162
|
+
key: 1,
|
|
1163
|
+
"data-eldra-slot": unref(eldra).slotHost("loading"),
|
|
1164
|
+
"data-eldra-scope": unref(eldra).scope,
|
|
1165
|
+
"data-part": "loading",
|
|
1166
|
+
role: "status",
|
|
1167
|
+
class: normalizeClass(loadingClasses.value)
|
|
1168
|
+
}, [createVNode(Spinner_default, { class: "eldra:size-4" }), renderSlot(_ctx.$slots, "loading", {}, () => [createTextVNode(toDisplayString(__props.loadingText), 1)])], 10, _hoisted_14)) : !__props.hasOptions ? (openBlock(), createElementBlock("div", {
|
|
1169
|
+
key: 2,
|
|
1170
|
+
"data-eldra-slot": unref(eldra).slotHost("empty"),
|
|
1171
|
+
"data-eldra-scope": unref(eldra).scope,
|
|
1172
|
+
"data-part": "empty",
|
|
1173
|
+
class: normalizeClass(emptyClasses.value)
|
|
1174
|
+
}, [renderSlot(_ctx.$slots, "empty", {}, () => [createTextVNode(toDisplayString(__props.emptyText), 1)])], 10, _hoisted_15)) : createCommentVNode("", true),
|
|
1175
|
+
renderSlot(_ctx.$slots, "footer")
|
|
1176
|
+
], 46, _hoisted_1);
|
|
1177
|
+
};
|
|
1178
|
+
}
|
|
1179
|
+
});
|
|
1180
|
+
// src/components/select/useListbox.ts
|
|
1181
|
+
/** Spec Select → Keyboard, open: "`PageDown` / `PageUp` | Move by 10." */
|
|
1182
|
+
var PAGE = 10;
|
|
1183
|
+
/** Spec Select → Keyboard, closed: "the buffer resets after 0.6s". */
|
|
1184
|
+
var TYPEAHEAD_RESET_MS = 600;
|
|
1185
|
+
/**
|
|
1186
|
+
* Case- and diacritic-insensitive, so the spec's "'island' finds 'Ísland'" holds for type-ahead
|
|
1187
|
+
* and for the search field alike. `NFD` splits a letter from its accent and the range drops the
|
|
1188
|
+
* combining marks that are left.
|
|
1189
|
+
*/
|
|
1190
|
+
function normalizeText(text) {
|
|
1191
|
+
return text.normalize("NFD").replaceAll(/[̀-ͯ]/g, "").toLowerCase();
|
|
1192
|
+
}
|
|
1193
|
+
/** A key that types a character, rather than a chord or a named key. */
|
|
1194
|
+
function isPrintable(event) {
|
|
1195
|
+
return event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey;
|
|
1196
|
+
}
|
|
1197
|
+
function clamp(value, min, max) {
|
|
1198
|
+
return value < min ? min : value > max ? max : value;
|
|
1199
|
+
}
|
|
1200
|
+
/**
|
|
1201
|
+
* The keyboard and the active row of a listbox popup — everything in the design spec's Select →
|
|
1202
|
+
* Keyboard tables that is not about *what* choosing a row does.
|
|
1203
|
+
*
|
|
1204
|
+
* It is separate from `Select.vue` on purpose. `MultiSelect` (the next component) has the same two
|
|
1205
|
+
* keyboard tables with three differences — `Enter` toggles instead of choosing-and-closing,
|
|
1206
|
+
* `Space` toggles, and the popup stays open — all of which are the caller's `select` callback and
|
|
1207
|
+
* the caller's decision about closing. Everything else (arrow movement that skips disabled and
|
|
1208
|
+
* filtered-out rows and stops at the ends, `PageUp`/`PageDown` by ten, `Home`/`End` unless a
|
|
1209
|
+
* search field owns them, `Alt+ArrowUp`, `Escape` clearing a query before it closes, `Tab`
|
|
1210
|
+
* closing without a choice, and type-ahead with a 0.6s buffer) is identical, and identical code
|
|
1211
|
+
* that is written twice stops being identical.
|
|
1212
|
+
*
|
|
1213
|
+
* The composable owns no DOM. `aria-activedescendant` is `activeId`, which the caller binds to
|
|
1214
|
+
* whichever element is focused — the trigger when there is no search field, the search field when
|
|
1215
|
+
* there is — and scrolling the active row into view is the caller's, because only the caller knows
|
|
1216
|
+
* which element a value maps to.
|
|
1217
|
+
*
|
|
1218
|
+
* ```ts
|
|
1219
|
+
* const listbox = useListbox({
|
|
1220
|
+
* options: () => visibleOptions.value,
|
|
1221
|
+
* isOpen: () => open.value,
|
|
1222
|
+
* searchable: () => searchable.value,
|
|
1223
|
+
* optionId: (value) => `${id.value}-option-${value}`,
|
|
1224
|
+
* open: (edge) => openPanel(edge),
|
|
1225
|
+
* close: () => closePanel(),
|
|
1226
|
+
* select: (option) => choose(option.value),
|
|
1227
|
+
* });
|
|
1228
|
+
* ```
|
|
1229
|
+
*/
|
|
1230
|
+
function useListbox(options) {
|
|
1231
|
+
const activeValue = ref(void 0);
|
|
1232
|
+
const activeId = computed(() => activeValue.value === void 0 ? void 0 : options.optionId(activeValue.value));
|
|
1233
|
+
/** Only enabled rows are reachable: "Arrow keys skip it" (Select → Variants, Disabled option). */
|
|
1234
|
+
const enabled = () => options.options().filter((option) => !option.disabled);
|
|
1235
|
+
const setActive = (value) => {
|
|
1236
|
+
activeValue.value = value;
|
|
1237
|
+
};
|
|
1238
|
+
const first = () => setActive(enabled()[0]?.value);
|
|
1239
|
+
const last = () => setActive(enabled().at(-1)?.value);
|
|
1240
|
+
const activateFrom = (value) => {
|
|
1241
|
+
const rows = enabled();
|
|
1242
|
+
const match = rows.find((option) => option.value === value);
|
|
1243
|
+
setActive((match ?? rows[0])?.value);
|
|
1244
|
+
};
|
|
1245
|
+
const move = (step) => {
|
|
1246
|
+
const rows = enabled();
|
|
1247
|
+
if (rows.length === 0) {
|
|
1248
|
+
setActive(void 0);
|
|
1249
|
+
return;
|
|
1250
|
+
}
|
|
1251
|
+
const index = rows.findIndex((option) => option.value === activeValue.value);
|
|
1252
|
+
if (index === -1) {
|
|
1253
|
+
setActive((step > 0 ? rows[0] : rows.at(-1))?.value);
|
|
1254
|
+
return;
|
|
1255
|
+
}
|
|
1256
|
+
setActive(rows[clamp(index + step, 0, rows.length - 1)]?.value);
|
|
1257
|
+
};
|
|
1258
|
+
const selectActive = () => {
|
|
1259
|
+
const option = options.options().find((row) => row.value === activeValue.value);
|
|
1260
|
+
if (option === void 0 || option.disabled === true) return;
|
|
1261
|
+
options.select(option);
|
|
1262
|
+
};
|
|
1263
|
+
let buffer = "";
|
|
1264
|
+
let timer;
|
|
1265
|
+
const resetTypeahead = () => {
|
|
1266
|
+
buffer = "";
|
|
1267
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
1268
|
+
timer = void 0;
|
|
1269
|
+
};
|
|
1270
|
+
onScopeDispose(resetTypeahead);
|
|
1271
|
+
function typeahead(character, inclusive = false) {
|
|
1272
|
+
buffer += character;
|
|
1273
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
1274
|
+
timer = setTimeout(resetTypeahead, TYPEAHEAD_RESET_MS);
|
|
1275
|
+
const rows = enabled();
|
|
1276
|
+
if (rows.length === 0) return;
|
|
1277
|
+
const prefix = normalizeText(buffer);
|
|
1278
|
+
const current = rows.findIndex((option) => option.value === activeValue.value);
|
|
1279
|
+
const from = buffer.length === 1 && !inclusive ? current + 1 : Math.max(current, 0);
|
|
1280
|
+
for (let step = 0; step < rows.length; step += 1) {
|
|
1281
|
+
const option = rows[(from + step + rows.length) % rows.length];
|
|
1282
|
+
if (option !== void 0 && normalizeText(option.label).startsWith(prefix)) {
|
|
1283
|
+
setActive(option.value);
|
|
1284
|
+
return;
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
function onClosedKeydown(event) {
|
|
1289
|
+
switch (event.key) {
|
|
1290
|
+
case "ArrowDown":
|
|
1291
|
+
case "Enter":
|
|
1292
|
+
case " ":
|
|
1293
|
+
event.preventDefault();
|
|
1294
|
+
options.open("start");
|
|
1295
|
+
return;
|
|
1296
|
+
case "ArrowUp":
|
|
1297
|
+
event.preventDefault();
|
|
1298
|
+
options.open(options.searchable() ? "start" : "end");
|
|
1299
|
+
return;
|
|
1300
|
+
case "Backspace":
|
|
1301
|
+
case "Delete":
|
|
1302
|
+
if (options.clear?.() === true) event.preventDefault();
|
|
1303
|
+
return;
|
|
1304
|
+
default:
|
|
1305
|
+
if (!isPrintable(event)) return;
|
|
1306
|
+
event.preventDefault();
|
|
1307
|
+
options.open("start");
|
|
1308
|
+
if (options.searchable()) options.startQuery?.(event.key);
|
|
1309
|
+
else typeahead(event.key, true);
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
function onOpenKeydown(event) {
|
|
1313
|
+
switch (event.key) {
|
|
1314
|
+
case "ArrowDown":
|
|
1315
|
+
event.preventDefault();
|
|
1316
|
+
move(1);
|
|
1317
|
+
return;
|
|
1318
|
+
case "ArrowUp":
|
|
1319
|
+
event.preventDefault();
|
|
1320
|
+
if (event.altKey) selectActive();
|
|
1321
|
+
else move(-1);
|
|
1322
|
+
return;
|
|
1323
|
+
case "PageDown":
|
|
1324
|
+
event.preventDefault();
|
|
1325
|
+
move(PAGE);
|
|
1326
|
+
return;
|
|
1327
|
+
case "PageUp":
|
|
1328
|
+
event.preventDefault();
|
|
1329
|
+
move(-10);
|
|
1330
|
+
return;
|
|
1331
|
+
case "Home":
|
|
1332
|
+
if (options.searchable()) return;
|
|
1333
|
+
event.preventDefault();
|
|
1334
|
+
first();
|
|
1335
|
+
return;
|
|
1336
|
+
case "End":
|
|
1337
|
+
if (options.searchable()) return;
|
|
1338
|
+
event.preventDefault();
|
|
1339
|
+
last();
|
|
1340
|
+
return;
|
|
1341
|
+
case "Enter":
|
|
1342
|
+
event.preventDefault();
|
|
1343
|
+
selectActive();
|
|
1344
|
+
return;
|
|
1345
|
+
case " ":
|
|
1346
|
+
if (options.searchable()) return;
|
|
1347
|
+
event.preventDefault();
|
|
1348
|
+
selectActive();
|
|
1349
|
+
return;
|
|
1350
|
+
case "Escape":
|
|
1351
|
+
if (options.escape?.() !== true) return;
|
|
1352
|
+
event.preventDefault();
|
|
1353
|
+
event.stopPropagation();
|
|
1354
|
+
return;
|
|
1355
|
+
case "Tab":
|
|
1356
|
+
options.close();
|
|
1357
|
+
return;
|
|
1358
|
+
default:
|
|
1359
|
+
if (options.searchable() || !isPrintable(event)) return;
|
|
1360
|
+
event.preventDefault();
|
|
1361
|
+
typeahead(event.key);
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
function onKeydown(event) {
|
|
1365
|
+
if (event.defaultPrevented) return;
|
|
1366
|
+
if (options.isOpen()) {
|
|
1367
|
+
onOpenKeydown(event);
|
|
1368
|
+
return;
|
|
1369
|
+
}
|
|
1370
|
+
if (options.canOpen?.() === false) return;
|
|
1371
|
+
onClosedKeydown(event);
|
|
1372
|
+
}
|
|
1373
|
+
return {
|
|
1374
|
+
activeValue,
|
|
1375
|
+
activeId,
|
|
1376
|
+
setActive,
|
|
1377
|
+
activateFrom,
|
|
1378
|
+
first,
|
|
1379
|
+
last,
|
|
1380
|
+
move,
|
|
1381
|
+
selectActive,
|
|
1382
|
+
onKeydown,
|
|
1383
|
+
resetTypeahead
|
|
1384
|
+
};
|
|
1385
|
+
}
|
|
1386
|
+
// src/components/select/useOptionList.ts
|
|
1387
|
+
/**
|
|
1388
|
+
* Where a query matches inside a label, in **code points of the original string**.
|
|
1389
|
+
*
|
|
1390
|
+
* Matching is case- and diacritic-insensitive (the spec's "'island' finds 'Ísland'"), so the
|
|
1391
|
+
* comparison happens on a normalised copy — and the match has to be reported back in the original
|
|
1392
|
+
* string's own offsets, or the bold-and-underlined run would land on the wrong characters for any
|
|
1393
|
+
* label holding an accent. Hence the per-character walk: each original code point contributes zero
|
|
1394
|
+
* (a combining mark) or more normalised characters, and `positions` maps back.
|
|
1395
|
+
*/
|
|
1396
|
+
function matchRange(label, rawQuery) {
|
|
1397
|
+
const needle = normalizeText(rawQuery);
|
|
1398
|
+
if (needle === "") return null;
|
|
1399
|
+
const characters = [...label];
|
|
1400
|
+
const positions = [];
|
|
1401
|
+
let normalized = "";
|
|
1402
|
+
for (const [index, character] of characters.entries()) {
|
|
1403
|
+
const piece = normalizeText(character);
|
|
1404
|
+
for (let step = 0; step < piece.length; step += 1) positions.push(index);
|
|
1405
|
+
normalized += piece;
|
|
1406
|
+
}
|
|
1407
|
+
const at = normalized.indexOf(needle);
|
|
1408
|
+
if (at === -1) return null;
|
|
1409
|
+
return {
|
|
1410
|
+
start: positions[at] ?? 0,
|
|
1411
|
+
end: (positions[at + needle.length - 1] ?? characters.length - 1) + 1
|
|
1412
|
+
};
|
|
1413
|
+
}
|
|
1414
|
+
/**
|
|
1415
|
+
* Options bucketed by `group`, in the order each group first appears — so a "Most used" group
|
|
1416
|
+
* written first stays first, which is exactly the spec's advice ("Put the 3 to 5 most likely
|
|
1417
|
+
* answers first"). Options with no `group` form an unlabelled section of their own.
|
|
1418
|
+
*/
|
|
1419
|
+
function groupOptions(list, idPrefix, controlId) {
|
|
1420
|
+
const order = [];
|
|
1421
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
1422
|
+
for (const option of list) {
|
|
1423
|
+
const key = option.group ?? "";
|
|
1424
|
+
let bucket = buckets.get(key);
|
|
1425
|
+
if (bucket === void 0) {
|
|
1426
|
+
bucket = [];
|
|
1427
|
+
buckets.set(key, bucket);
|
|
1428
|
+
order.push(key);
|
|
1429
|
+
}
|
|
1430
|
+
bucket.push(option);
|
|
1431
|
+
}
|
|
1432
|
+
return order.map((key, index) => ({
|
|
1433
|
+
key: key === "" ? `${idPrefix}-plain-${index}` : `${idPrefix}-group-${key}`,
|
|
1434
|
+
label: key === "" ? void 0 : key,
|
|
1435
|
+
labelId: key === "" ? void 0 : `${controlId}-g${index}`,
|
|
1436
|
+
options: buckets.get(key) ?? []
|
|
1437
|
+
}));
|
|
1438
|
+
}
|
|
1439
|
+
/**
|
|
1440
|
+
* The value of the "Create “query”" row a `creatable` control appends. A control character no
|
|
1441
|
+
* merchant value holds, so it never collides with an option's own value.
|
|
1442
|
+
*/
|
|
1443
|
+
var CREATE_VALUE = "\0eldra-create";
|
|
1444
|
+
/**
|
|
1445
|
+
* The list a select panel shows: filtering, grouping, match highlighting, the create row and the
|
|
1446
|
+
* render batch.
|
|
1447
|
+
*
|
|
1448
|
+
* Shared by `Select` and `MultiSelect`, which differ in what choosing a row *does* and in nothing
|
|
1449
|
+
* about which rows there are. No DOM; its one piece of state is how many rows are rendered.
|
|
1450
|
+
*/
|
|
1451
|
+
function useOptionList(options) {
|
|
1452
|
+
const trimmedQuery = computed(() => options.searchable() ? options.query().trim() : "");
|
|
1453
|
+
const loading = computed(() => options.loading?.() === true);
|
|
1454
|
+
/**
|
|
1455
|
+
* The options a query leaves, in the consumer's order. Not returned: every caller wants them
|
|
1456
|
+
* bucketed (`sections`) or in DOM order (`listOptions`), and a third view of the same list would
|
|
1457
|
+
* only be a way to disagree with those two.
|
|
1458
|
+
*/
|
|
1459
|
+
const visibleOptions = computed(() => {
|
|
1460
|
+
if (loading.value) return [];
|
|
1461
|
+
const trimmed = trimmedQuery.value;
|
|
1462
|
+
if (trimmed === "") return options.options();
|
|
1463
|
+
const needle = normalizeText(trimmed);
|
|
1464
|
+
return options.options().filter((option) => matchRange(option.label, trimmed) !== null || option.keywords?.some((keyword) => normalizeText(keyword).includes(needle)) === true);
|
|
1465
|
+
});
|
|
1466
|
+
/** Every visible option in DOM order, before the render batch cuts it. */
|
|
1467
|
+
const orderedOptions = computed(() => groupOptions(visibleOptions.value, "panel", options.controlId()).flatMap((section) => section.options));
|
|
1468
|
+
const batchSize = () => {
|
|
1469
|
+
const size = options.renderBatch?.();
|
|
1470
|
+
return size === void 0 || !(size >= 1) ? Number.POSITIVE_INFINITY : Math.floor(size);
|
|
1471
|
+
};
|
|
1472
|
+
const rendered = ref(batchSize());
|
|
1473
|
+
const resetBatch = () => {
|
|
1474
|
+
rendered.value = batchSize();
|
|
1475
|
+
};
|
|
1476
|
+
const renderMore = () => {
|
|
1477
|
+
if (rendered.value < orderedOptions.value.length) rendered.value += batchSize();
|
|
1478
|
+
};
|
|
1479
|
+
const reveal = (value) => {
|
|
1480
|
+
if (value === void 0 || !Number.isFinite(rendered.value)) return;
|
|
1481
|
+
const index = orderedOptions.value.findIndex((option) => option.value === value);
|
|
1482
|
+
if (index < rendered.value) return;
|
|
1483
|
+
const size = batchSize();
|
|
1484
|
+
rendered.value = Math.ceil((index + 1) / size) * size;
|
|
1485
|
+
};
|
|
1486
|
+
watch(trimmedQuery, resetBatch);
|
|
1487
|
+
watch(() => options.renderBatch?.(), resetBatch);
|
|
1488
|
+
const renderedOptions = computed(() => Number.isFinite(rendered.value) ? orderedOptions.value.slice(0, rendered.value) : orderedOptions.value);
|
|
1489
|
+
const sections = computed(() => groupOptions(renderedOptions.value, "panel", options.controlId()));
|
|
1490
|
+
const nativeSections = computed(() => groupOptions(options.options(), "native", options.controlId()));
|
|
1491
|
+
/**
|
|
1492
|
+
* Spec-free addition: a query no option's label already equals can be offered as a new option.
|
|
1493
|
+
* Equal ignoring case and accents, the same comparison the search itself makes, so "Shirt" is
|
|
1494
|
+
* not offered beside an existing "shirt".
|
|
1495
|
+
*/
|
|
1496
|
+
const createOption = computed(() => {
|
|
1497
|
+
const trimmed = trimmedQuery.value;
|
|
1498
|
+
if (options.creatable?.() !== true || loading.value || trimmed === "") return void 0;
|
|
1499
|
+
const needle = normalizeText(trimmed);
|
|
1500
|
+
if (options.options().some((option) => normalizeText(option.label) === needle)) return;
|
|
1501
|
+
return {
|
|
1502
|
+
value: CREATE_VALUE,
|
|
1503
|
+
label: trimmed
|
|
1504
|
+
};
|
|
1505
|
+
});
|
|
1506
|
+
const listOptions = computed(() => createOption.value === void 0 ? orderedOptions.value : [...orderedOptions.value, createOption.value]);
|
|
1507
|
+
return {
|
|
1508
|
+
sections,
|
|
1509
|
+
nativeSections,
|
|
1510
|
+
listOptions,
|
|
1511
|
+
hasOptions: computed(() => listOptions.value.length > 0),
|
|
1512
|
+
highlights: computed(() => {
|
|
1513
|
+
const trimmed = trimmedQuery.value;
|
|
1514
|
+
return new Map(renderedOptions.value.map((option) => {
|
|
1515
|
+
const range = trimmed === "" ? null : matchRange(option.label, trimmed);
|
|
1516
|
+
if (range === null) return [option.value, null];
|
|
1517
|
+
const characters = [...option.label];
|
|
1518
|
+
return [option.value, {
|
|
1519
|
+
before: characters.slice(0, range.start).join(""),
|
|
1520
|
+
match: characters.slice(range.start, range.end).join(""),
|
|
1521
|
+
after: characters.slice(range.end).join("")
|
|
1522
|
+
}];
|
|
1523
|
+
}));
|
|
1524
|
+
}),
|
|
1525
|
+
createOption,
|
|
1526
|
+
renderMore,
|
|
1527
|
+
reveal,
|
|
1528
|
+
resetBatch
|
|
1529
|
+
};
|
|
1530
|
+
}
|
|
1531
|
+
// src/composables/useFloating.ts
|
|
1532
|
+
/** What each of the spec's two named placements means to `@floating-ui/dom`. */
|
|
1533
|
+
var RESOLVED = {
|
|
1534
|
+
auto: {
|
|
1535
|
+
placement: "bottom-start",
|
|
1536
|
+
flip: true
|
|
1537
|
+
},
|
|
1538
|
+
above: {
|
|
1539
|
+
placement: "top-start",
|
|
1540
|
+
flip: false
|
|
1541
|
+
},
|
|
1542
|
+
bottom: {
|
|
1543
|
+
placement: "bottom",
|
|
1544
|
+
flip: true
|
|
1545
|
+
},
|
|
1546
|
+
"bottom-start": {
|
|
1547
|
+
placement: "bottom-start",
|
|
1548
|
+
flip: true
|
|
1549
|
+
},
|
|
1550
|
+
"bottom-end": {
|
|
1551
|
+
placement: "bottom-end",
|
|
1552
|
+
flip: true
|
|
1553
|
+
},
|
|
1554
|
+
top: {
|
|
1555
|
+
placement: "top",
|
|
1556
|
+
flip: true
|
|
1557
|
+
},
|
|
1558
|
+
"top-start": {
|
|
1559
|
+
placement: "top-start",
|
|
1560
|
+
flip: true
|
|
1561
|
+
},
|
|
1562
|
+
"top-end": {
|
|
1563
|
+
placement: "top-end",
|
|
1564
|
+
flip: true
|
|
1565
|
+
},
|
|
1566
|
+
left: {
|
|
1567
|
+
placement: "left",
|
|
1568
|
+
flip: true
|
|
1569
|
+
},
|
|
1570
|
+
"left-start": {
|
|
1571
|
+
placement: "left-start",
|
|
1572
|
+
flip: true
|
|
1573
|
+
},
|
|
1574
|
+
"left-end": {
|
|
1575
|
+
placement: "left-end",
|
|
1576
|
+
flip: true
|
|
1577
|
+
},
|
|
1578
|
+
right: {
|
|
1579
|
+
placement: "right",
|
|
1580
|
+
flip: true
|
|
1581
|
+
},
|
|
1582
|
+
"right-start": {
|
|
1583
|
+
placement: "right-start",
|
|
1584
|
+
flip: true
|
|
1585
|
+
},
|
|
1586
|
+
"right-end": {
|
|
1587
|
+
placement: "right-end",
|
|
1588
|
+
flip: true
|
|
1589
|
+
}
|
|
1590
|
+
};
|
|
1591
|
+
/**
|
|
1592
|
+
* Positions a floating panel against the element that opened it — the one piece of every popup in
|
|
1593
|
+
* this package that has to measure the page.
|
|
1594
|
+
*
|
|
1595
|
+
* It is a thin wrap of `@floating-ui/vue`: `autoUpdate` keeps the position current while both
|
|
1596
|
+
* elements are mounted (scrolling, resizing, an ancestor moving), `offset` sets the gap, `flip`
|
|
1597
|
+
* turns the panel above the trigger when there is no room below, `shift` keeps it inside the
|
|
1598
|
+
* viewport, and `size` measures the trigger for `matchWidth` (a floor on the panel's width — the
|
|
1599
|
+
* spec lets a select's panel grow past its trigger up to its own `max-width` — or a floor and a
|
|
1600
|
+
* ceiling under `'exact'`). What the wrap adds is the design spec's vocabulary (`auto` / `above`)
|
|
1601
|
+
* and a plain style object rather than a transform, so a consumer writes `<div :style="styles">`
|
|
1602
|
+
* and nothing else.
|
|
1603
|
+
*
|
|
1604
|
+
* `top` and `left` are used instead of the default `transform`, because a panel positioned by
|
|
1605
|
+
* transform is blurry on fractional pixels and, more to the point, cannot then use `transform` for
|
|
1606
|
+
* the spec's own open animation (fade + 0.25rem slide + a vertical scale from the top edge).
|
|
1607
|
+
*
|
|
1608
|
+
* ```ts
|
|
1609
|
+
* const trigger = ref<HTMLElement | null>(null);
|
|
1610
|
+
* const panel = ref<HTMLElement | null>(null);
|
|
1611
|
+
* const { styles, placement } = useFloating(trigger, panel, { matchWidth: true });
|
|
1612
|
+
* ```
|
|
1613
|
+
*
|
|
1614
|
+
* The reference may be a Floating UI **virtual element** (`{ getBoundingClientRect() }`), for a
|
|
1615
|
+
* panel anchored to a caret or a pointer position rather than to a node; call `update()` after it
|
|
1616
|
+
* moves, since nothing observes a virtual element's geometry.
|
|
1617
|
+
*/
|
|
1618
|
+
function useFloating$1(reference, floating, options = {}) {
|
|
1619
|
+
const resolved = computed(() => RESOLVED[toValue(options.placement) ?? "auto"]);
|
|
1620
|
+
const exactWidth = options.matchWidth === "exact";
|
|
1621
|
+
const matchWidth = options.matchWidth === true || exactWidth;
|
|
1622
|
+
const referenceWidth = ref(0);
|
|
1623
|
+
const middleware = computed(() => {
|
|
1624
|
+
const list = [offset(toValue(options.offset) ?? 4)];
|
|
1625
|
+
if (options.flip ?? resolved.value.flip) list.push(flip());
|
|
1626
|
+
list.push(shift({ padding: toValue(options.padding) ?? 8 }));
|
|
1627
|
+
if (matchWidth) list.push(size({ apply({ rects }) {
|
|
1628
|
+
referenceWidth.value = rects.reference.width;
|
|
1629
|
+
} }));
|
|
1630
|
+
return list;
|
|
1631
|
+
});
|
|
1632
|
+
const position = useFloating(reference, floating, {
|
|
1633
|
+
placement: computed(() => resolved.value.placement),
|
|
1634
|
+
strategy: options.strategy ?? "absolute",
|
|
1635
|
+
transform: false,
|
|
1636
|
+
middleware,
|
|
1637
|
+
whileElementsMounted: autoUpdate
|
|
1638
|
+
});
|
|
1639
|
+
return {
|
|
1640
|
+
styles: computed(() => {
|
|
1641
|
+
const base = {
|
|
1642
|
+
position: position.strategy.value,
|
|
1643
|
+
left: `${position.x.value}px`,
|
|
1644
|
+
top: `${position.y.value}px`
|
|
1645
|
+
};
|
|
1646
|
+
if (matchWidth) base.minWidth = `${referenceWidth.value}px`;
|
|
1647
|
+
if (exactWidth) base.maxWidth = `${referenceWidth.value}px`;
|
|
1648
|
+
return base;
|
|
1649
|
+
}),
|
|
1650
|
+
placement: computed(() => position.placement.value),
|
|
1651
|
+
update: position.update
|
|
1652
|
+
};
|
|
1653
|
+
}
|
|
1654
|
+
// src/composables/teleportTarget.ts
|
|
1655
|
+
/**
|
|
1656
|
+
* Whether an element is a dialog the browser has put in its **top layer**.
|
|
1657
|
+
*
|
|
1658
|
+
* `:modal` is the only way to ask: a `<dialog>` has the `open` attribute whether it was shown with
|
|
1659
|
+
* `show()` (an ordinary in-flow element, which clips and stacks like any other) or with
|
|
1660
|
+
* `showModal()` (top layer, above every z-index, with a backdrop), and nothing else in the DOM
|
|
1661
|
+
* tells the two apart. Engines that do not implement `:modal` answer `false` here — happy-dom
|
|
1662
|
+
* parses the selector and never matches it, jsdom does not implement `<dialog>` modality at all —
|
|
1663
|
+
* which is what the caller's fallback is for.
|
|
1664
|
+
*
|
|
1665
|
+
* Wrapped in a `try`: a selector an engine cannot parse is a `SyntaxError`, not a `false`.
|
|
1666
|
+
*/
|
|
1667
|
+
function isTopLayer(element) {
|
|
1668
|
+
try {
|
|
1669
|
+
return element.matches(":modal");
|
|
1670
|
+
} catch {
|
|
1671
|
+
return false;
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
/**
|
|
1675
|
+
* The `<dialog>` a popup anchored to `anchor` has to be teleported *into* rather than escape, or
|
|
1676
|
+
* `null` when there is none.
|
|
1677
|
+
*
|
|
1678
|
+
* A **modal** dialog is the one place `document.body` is the wrong target: the dialog is in the top
|
|
1679
|
+
* layer, so a popup on the body would be painted behind it and no `z-index` could raise it. So the
|
|
1680
|
+
* nearest open ancestor dialog that is actually in the top layer wins — which is not always the
|
|
1681
|
+
* nearest one, since a non-modal `<dialog open>` may sit inside a modal one.
|
|
1682
|
+
*
|
|
1683
|
+
* When **no** ancestor dialog claims the top layer, the nearest open one is still the answer. That
|
|
1684
|
+
* case is ambiguous — either they really are all non-modal, or the engine does not implement
|
|
1685
|
+
* `:modal` and cannot say — and the two mistakes are not equally bad. Teleporting into a dialog
|
|
1686
|
+
* that did not need it still escapes everything between the control and that dialog, and the
|
|
1687
|
+
* dialog is a box the popup had no business overflowing anyway; teleporting to `body` out of a
|
|
1688
|
+
* dialog that *was* modal puts the popup behind it, invisibly, which is the very bug this whole
|
|
1689
|
+
* mechanism exists to fix. There is no engine-independent probe to break the tie —
|
|
1690
|
+
* `CSS.supports('selector(:modal)')` answers `true` for nonsense in happy-dom — so the safe
|
|
1691
|
+
* mistake is the one taken. A non-modal `<dialog open>` is in any case close to hypothetical here:
|
|
1692
|
+
* the design spec's non-negotiable 2 opens every modal surface with `showModal()`, and says the
|
|
1693
|
+
* non-modal popups are not dialogs at all.
|
|
1694
|
+
*/
|
|
1695
|
+
function topLayerDialog(anchor) {
|
|
1696
|
+
const nearest = anchor.closest("dialog[open]");
|
|
1697
|
+
if (nearest === null) return null;
|
|
1698
|
+
for (let dialog = nearest; dialog !== null; dialog = dialog.parentElement?.closest("dialog[open]") ?? null) if (isTopLayer(dialog)) return dialog;
|
|
1699
|
+
return nearest;
|
|
1700
|
+
}
|
|
1701
|
+
/**
|
|
1702
|
+
* Where a teleported popup is rendered: `usePopover`'s and `Tooltip`'s shared answer to "escape
|
|
1703
|
+
* clipping and stacking, but not the browser's own top layer."
|
|
1704
|
+
*
|
|
1705
|
+
* A panel (or bubble) rendered inside its own control is at the mercy of everything above it: an
|
|
1706
|
+
* ancestor with `overflow: hidden` (a card, a table cell, a carousel track) clips it, and any later
|
|
1707
|
+
* sibling that starts a stacking context (a sticky header with a `z-index`, a section with
|
|
1708
|
+
* `isolate`) paints over it however high its own `z-index` is. On `body` neither can happen — except
|
|
1709
|
+
* for a native `<dialog>` opened with `showModal()`, which renders in the top layer above every
|
|
1710
|
+
* `z-index` on the page, so a popup teleported to `body` out from under one would be invisible
|
|
1711
|
+
* behind it. `topLayerDialog` is the one exception that rule needs.
|
|
1712
|
+
*
|
|
1713
|
+
* ```ts
|
|
1714
|
+
* const isOpen = ref(false);
|
|
1715
|
+
* const trigger = ref<HTMLElement | null>(null);
|
|
1716
|
+
* const { teleportTo, teleportDisabled } = useTeleportTarget({ trigger, teleport: true, isOpen });
|
|
1717
|
+
* ```
|
|
1718
|
+
*/
|
|
1719
|
+
function useTeleportTarget(options) {
|
|
1720
|
+
const { trigger, teleport, isOpen } = options;
|
|
1721
|
+
/**
|
|
1722
|
+
* Only `true` after `onMounted`, which never runs on the server. Everything that reads the
|
|
1723
|
+
* document below is behind it.
|
|
1724
|
+
*/
|
|
1725
|
+
const isMounted = ref(false);
|
|
1726
|
+
onMounted(() => {
|
|
1727
|
+
isMounted.value = true;
|
|
1728
|
+
});
|
|
1729
|
+
const teleportDisabled = computed(() => teleport === false || !isMounted.value);
|
|
1730
|
+
return {
|
|
1731
|
+
teleportTo: computed(() => {
|
|
1732
|
+
if (!isMounted.value) return "body";
|
|
1733
|
+
if (typeof teleport === "string") return teleport;
|
|
1734
|
+
isOpen.value;
|
|
1735
|
+
const anchor = trigger.value;
|
|
1736
|
+
return (anchor === null ? null : topLayerDialog(anchor)) ?? document.body;
|
|
1737
|
+
}),
|
|
1738
|
+
teleportDisabled
|
|
1739
|
+
};
|
|
1740
|
+
}
|
|
1741
|
+
// src/composables/useOverlay.ts
|
|
1742
|
+
/**
|
|
1743
|
+
* Anything the platform lets a user reach with `Tab`, plus the elements a component has opted in
|
|
1744
|
+
* with a `tabindex`. `tabindex="-1"` is deliberately excluded: it is programmatically focusable,
|
|
1745
|
+
* not part of the sequence a keyboard user walks, and `focusFirst()` exists to put focus where a
|
|
1746
|
+
* user would have put it themselves.
|
|
1747
|
+
*/
|
|
1748
|
+
var FOCUSABLE = "a[href], area[href], button, input, select, textarea, details > summary:first-of-type, iframe, audio[controls], video[controls], [contenteditable]:not([contenteditable=\"false\"]), [tabindex]:not([tabindex^=\"-\"])";
|
|
1749
|
+
/**
|
|
1750
|
+
* Marks an element that belongs to an overlay whose content element has this `id`.
|
|
1751
|
+
*
|
|
1752
|
+
* Exported for `usePopover`, which has to find those elements rather than only recognise one it is
|
|
1753
|
+
* handed: a teleported panel's `Tab` walk runs through them (see its `tabRedirect` option).
|
|
1754
|
+
*/
|
|
1755
|
+
var OVERLAY_OWNER_ATTRIBUTE = "data-eldra-overlay-owner";
|
|
1756
|
+
var read = (setting, fallback) => setting === void 0 ? fallback : typeof setting === "function" ? setting() : setting;
|
|
1757
|
+
/**
|
|
1758
|
+
* The closing and focus rules shared by every **non-modal** popup in this package — the Select and
|
|
1759
|
+
* Multi-select panels, the Search bar's results panel, menus.
|
|
1760
|
+
*
|
|
1761
|
+
* Non-modal is the whole point. The design spec's non-negotiables put every *modal* surface in a
|
|
1762
|
+
* native `<dialog>` opened with `showModal()`, and say in the same breath that these popups are not
|
|
1763
|
+
* dialogs: "Non-modal popups (select panels, search results panel, mega-menus, tooltips) are **not**
|
|
1764
|
+
* dialogs." So there is no focus trap here and no `Tab` cycling — `Tab` simply moves on, and focus
|
|
1765
|
+
* landing outside is what closes the popup (WCAG 2.1.2: no keyboard trap). Everything this
|
|
1766
|
+
* composable does is close at the right moment and leave focus somewhere sensible.
|
|
1767
|
+
*
|
|
1768
|
+
* What it listens for, and only while `open` is `true`:
|
|
1769
|
+
*
|
|
1770
|
+
* - **A pointer press outside** (`pointerdown`, captured, so a handler inside the page that stops
|
|
1771
|
+
* propagation cannot hide the press from us). Inside is the trigger, the content, and anything
|
|
1772
|
+
* under an element carrying `data-eldra-overlay-owner="<the content's id>"` — which is how a
|
|
1773
|
+
* panel rendered through a `<Teleport>` still counts as part of the overlay. Closing this way
|
|
1774
|
+
* never moves focus: the user is pressing something else, and pulling focus back to the trigger
|
|
1775
|
+
* would take it off whatever they just pressed.
|
|
1776
|
+
* - **Focus leaving** (`focusout`). If the new focus owner is outside the overlay, the popup
|
|
1777
|
+
* closes and focus stays where the user sent it. If focus went *nowhere* (`relatedTarget` is
|
|
1778
|
+
* `null` — the content is about to be removed from under it), `returnFocus` puts it back on the
|
|
1779
|
+
* trigger rather than letting it fall to `<body>`.
|
|
1780
|
+
* - **`Escape`** (`keydown`, bubbling, so a component that wants the first go at `Escape` — the
|
|
1781
|
+
* Select clears its search query before it closes — can handle it and stop propagation). It
|
|
1782
|
+
* closes, returns focus to the trigger, and both `preventDefault()`s and stops propagation: a
|
|
1783
|
+
* popup inside a native `<dialog>` must consume the key, or the dialog closes behind it.
|
|
1784
|
+
*
|
|
1785
|
+
* Listeners go on `document` when the overlay opens and come off when it closes or the scope is
|
|
1786
|
+
* disposed, so a closed overlay costs nothing and an unmounted one leaves nothing behind. Nothing
|
|
1787
|
+
* touches the DOM during SSR.
|
|
1788
|
+
*
|
|
1789
|
+
* ```ts
|
|
1790
|
+
* const open = ref(false);
|
|
1791
|
+
* const trigger = ref<HTMLElement | null>(null);
|
|
1792
|
+
* const content = ref<HTMLElement | null>(null);
|
|
1793
|
+
* const overlay = useOverlay({ open, trigger, content, setOpen: (next) => (open.value = next) });
|
|
1794
|
+
* ```
|
|
1795
|
+
*/
|
|
1796
|
+
function useOverlay(options) {
|
|
1797
|
+
const { open, trigger, content, setOpen } = options;
|
|
1798
|
+
const closeOnOutsideClick = () => read(options.closeOnOutsideClick, true);
|
|
1799
|
+
const closeOnFocusOutside = () => read(options.closeOnFocusOutside, closeOnOutsideClick());
|
|
1800
|
+
const closeOnEscape = () => read(options.closeOnEscape, true);
|
|
1801
|
+
const returnFocus = () => read(options.returnFocus, true);
|
|
1802
|
+
const focusables = (from) => {
|
|
1803
|
+
const root = from === void 0 ? content.value : from;
|
|
1804
|
+
if (!root) return [];
|
|
1805
|
+
return [root, ...root.querySelectorAll(FOCUSABLE)].filter((element) => element.matches(FOCUSABLE) && element.tabIndex >= 0 && !element.hasAttribute("disabled") && element.getAttribute("aria-hidden") !== "true" && element.closest("[hidden]") === null);
|
|
1806
|
+
};
|
|
1807
|
+
const focusFirst = () => {
|
|
1808
|
+
focusables()[0]?.focus();
|
|
1809
|
+
};
|
|
1810
|
+
const close = () => setOpen(false);
|
|
1811
|
+
/**
|
|
1812
|
+
* A teleported part of the overlay is in the DOM somewhere else entirely, so containment says
|
|
1813
|
+
* nothing about it. It is claimed one of two ways, both followed transitively:
|
|
1814
|
+
*
|
|
1815
|
+
* - **An owner marker**: an ancestor carrying `data-eldra-overlay-owner` names the content's id —
|
|
1816
|
+
* or the id of any element that is itself inside this overlay, so a picker teleported out of a
|
|
1817
|
+
* panel can point at the field inside the panel it belongs to.
|
|
1818
|
+
* - **An open control inside the overlay**: an element with `aria-expanded="true"` inside this
|
|
1819
|
+
* overlay names, in `aria-controls`, an element in the node's popup — the owner-marked panel
|
|
1820
|
+
* that element sits in, or the element itself. That is a nested popup (a `Select` or another
|
|
1821
|
+
* `Popover` opened from this panel) whose own panel is teleported too.
|
|
1822
|
+
*
|
|
1823
|
+
* Walked by hand rather than through selectors so an id with a character CSS would have to
|
|
1824
|
+
* escape cannot break the check.
|
|
1825
|
+
*/
|
|
1826
|
+
const isInside = (node, visited = /* @__PURE__ */ new Set()) => {
|
|
1827
|
+
if (!(node instanceof Node) || visited.has(node)) return false;
|
|
1828
|
+
visited.add(node);
|
|
1829
|
+
if (trigger.value?.contains(node) === true) return true;
|
|
1830
|
+
if (content.value?.contains(node) === true) return true;
|
|
1831
|
+
const id = content.value?.id;
|
|
1832
|
+
if (id === void 0 || id === "" || typeof document === "undefined") return false;
|
|
1833
|
+
for (let element = node instanceof Element ? node : node.parentElement; element !== null; element = element.parentElement) {
|
|
1834
|
+
const owner = element.getAttribute(OVERLAY_OWNER_ATTRIBUTE);
|
|
1835
|
+
if (owner === id) return true;
|
|
1836
|
+
if (owner === null || owner === "") continue;
|
|
1837
|
+
const named = document.getElementById(owner);
|
|
1838
|
+
if (named !== null && !named.contains(element) && isInside(named, visited)) return true;
|
|
1839
|
+
}
|
|
1840
|
+
for (const control of document.querySelectorAll("[aria-controls]")) {
|
|
1841
|
+
if (control.getAttribute("aria-expanded") !== "true" || control.contains(node)) continue;
|
|
1842
|
+
for (const controlled of (control.getAttribute("aria-controls") ?? "").split(/\s+/)) {
|
|
1843
|
+
const target = controlled === "" ? null : document.getElementById(controlled);
|
|
1844
|
+
if (target === null) continue;
|
|
1845
|
+
const popup = target.closest(`[data-eldra-overlay-owner]`) ?? target;
|
|
1846
|
+
if (!popup.contains(node) || popup.contains(control)) continue;
|
|
1847
|
+
if (isInside(control, visited)) return true;
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
return false;
|
|
1851
|
+
};
|
|
1852
|
+
const onPointerDown = (event) => {
|
|
1853
|
+
if (!open.value || !closeOnOutsideClick() || isInside(event.target)) return;
|
|
1854
|
+
close();
|
|
1855
|
+
};
|
|
1856
|
+
const onFocusOut = (event) => {
|
|
1857
|
+
if (!open.value || !closeOnFocusOutside()) return;
|
|
1858
|
+
if (!isInside(event.target)) return;
|
|
1859
|
+
const next = event.relatedTarget;
|
|
1860
|
+
if (isInside(next)) return;
|
|
1861
|
+
close();
|
|
1862
|
+
if (returnFocus() && next === null) trigger.value?.focus();
|
|
1863
|
+
};
|
|
1864
|
+
const onKeyDown = (event) => {
|
|
1865
|
+
if (!open.value || event.key !== "Escape" || !closeOnEscape()) return;
|
|
1866
|
+
event.preventDefault();
|
|
1867
|
+
event.stopPropagation();
|
|
1868
|
+
close();
|
|
1869
|
+
if (returnFocus()) trigger.value?.focus();
|
|
1870
|
+
};
|
|
1871
|
+
let listening = false;
|
|
1872
|
+
const attach = () => {
|
|
1873
|
+
if (listening || typeof document === "undefined") return;
|
|
1874
|
+
listening = true;
|
|
1875
|
+
document.addEventListener("pointerdown", onPointerDown, true);
|
|
1876
|
+
document.addEventListener("focusout", onFocusOut);
|
|
1877
|
+
document.addEventListener("keydown", onKeyDown);
|
|
1878
|
+
};
|
|
1879
|
+
const detach = () => {
|
|
1880
|
+
if (!listening) return;
|
|
1881
|
+
listening = false;
|
|
1882
|
+
document.removeEventListener("pointerdown", onPointerDown, true);
|
|
1883
|
+
document.removeEventListener("focusout", onFocusOut);
|
|
1884
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
1885
|
+
};
|
|
1886
|
+
watch(open, (isOpen) => isOpen ? attach() : detach(), { immediate: true });
|
|
1887
|
+
onScopeDispose(detach);
|
|
1888
|
+
return {
|
|
1889
|
+
close,
|
|
1890
|
+
focusFirst,
|
|
1891
|
+
focusables,
|
|
1892
|
+
isInside: (node) => isInside(node)
|
|
1893
|
+
};
|
|
1894
|
+
}
|
|
1895
|
+
// src/components/select/openRegistry.ts
|
|
1896
|
+
/**
|
|
1897
|
+
* The open popups, outermost first. Without nesting it never holds more than one entry; a popup
|
|
1898
|
+
* opened from inside another's panel is stacked on it instead of closing it.
|
|
1899
|
+
*/
|
|
1900
|
+
var stack = [];
|
|
1901
|
+
/**
|
|
1902
|
+
* Claim the slot and close whatever held it — except the popups the new one is nested in.
|
|
1903
|
+
*
|
|
1904
|
+
* The slot is reassigned *before* the previous popups are closed, so the `unregisterOpen` that
|
|
1905
|
+
* closing triggers sees a slot that is no longer its own and leaves the new owner alone.
|
|
1906
|
+
*/
|
|
1907
|
+
function registerOpen(close, options = {}) {
|
|
1908
|
+
if (stack.at(-1)?.close === close) return;
|
|
1909
|
+
const { anchor } = options;
|
|
1910
|
+
const kept = [];
|
|
1911
|
+
const closed = [];
|
|
1912
|
+
for (const entry of stack) {
|
|
1913
|
+
if (entry.close === close) continue;
|
|
1914
|
+
(anchor !== void 0 && anchor !== null && entry.contains?.(anchor) === true ? kept : closed).push(entry);
|
|
1915
|
+
}
|
|
1916
|
+
stack = [...kept, {
|
|
1917
|
+
close,
|
|
1918
|
+
contains: options.contains
|
|
1919
|
+
}];
|
|
1920
|
+
for (const entry of closed) entry.close();
|
|
1921
|
+
}
|
|
1922
|
+
/** Release the slot, if it is still this popup's. */
|
|
1923
|
+
function unregisterOpen(close) {
|
|
1924
|
+
stack = stack.filter((entry) => entry.close !== close);
|
|
1925
|
+
}
|
|
1926
|
+
// src/components/select/usePopover.ts
|
|
1927
|
+
/**
|
|
1928
|
+
* The open/closed life of a **non-modal popup** anchored to a control: `Select`'s panel,
|
|
1929
|
+
* `MultiSelect`'s, and the `SearchBar`'s results panel.
|
|
1930
|
+
*
|
|
1931
|
+
* Every one of them needs the same six things, and before this composable the first two controls
|
|
1932
|
+
* held a line-identical copy of all of them:
|
|
1933
|
+
*
|
|
1934
|
+
* - **"Only one open at a time"** (`openRegistry`): opening claims a module-level slot and closes
|
|
1935
|
+
* whatever held it. The handle is stable per instance, so a late close cannot blank out the
|
|
1936
|
+
* popup that took its place.
|
|
1937
|
+
* - **Closing** (`useOverlay`): an outside pointer press, focus leaving, `Escape`. Non-modal, so
|
|
1938
|
+
* nothing is trapped and `Tab` always moves on.
|
|
1939
|
+
* - **Getting out of the way of the page** (`teleport`): the panel is rendered through a
|
|
1940
|
+
* `<Teleport>` to `body` — or to the modal `<dialog>` the trigger is in, which is the one place
|
|
1941
|
+
* `body` would be *behind* — and positioned with floating-ui's `fixed` strategy, so no ancestor's
|
|
1942
|
+
* `overflow: hidden` clips it and no later stacking context paints over it. `tabRedirect` puts a
|
|
1943
|
+
* panel that has real tab stops back into the `Tab` walk it left with its place in the DOM.
|
|
1944
|
+
* - **Positioning** (`useFloating`), plus the `--eldra-popover-origin` the entrance keyframes read,
|
|
1945
|
+
* so a panel that flips after floating-ui measures changes a custom property rather than its
|
|
1946
|
+
* `animation-name` (which would replay the entrance).
|
|
1947
|
+
* - **The open sequence**: open, make a row active, and — only when the call actually changed the
|
|
1948
|
+
* state — run `afterOpen` a tick later, which is where focus moves into the panel.
|
|
1949
|
+
* - **The label-forwarded-click latch**: a `<label for>` naming the trigger forwards its click to
|
|
1950
|
+
* it, and the spec is explicit that clicking a field's label focuses the control **without**
|
|
1951
|
+
* opening it. A forwarded click differs from a real one in that no pointer was pressed on the
|
|
1952
|
+
* trigger and its `detail` is 0. The latch is armed on `pointerdown` and released on the
|
|
1953
|
+
* `pointerup` or `pointercancel` that follows, wherever it lands: a press that ends off the
|
|
1954
|
+
* trigger (a drag, a cancelled touch) would otherwise leave the latch standing and arm the
|
|
1955
|
+
* *next* click. A programmatic `element.click()` has the same shape, so it is told apart by what
|
|
1956
|
+
* it is not (see `isProgrammaticClick`): not forwarded from a label clicked in the same task,
|
|
1957
|
+
* not trusted, and a `PointerEvent`, which is what `click()` dispatches.
|
|
1958
|
+
*
|
|
1959
|
+
* What stays with each control is what actually differs: which rows there are, what choosing one
|
|
1960
|
+
* does, and which element the popup is anchored to.
|
|
1961
|
+
*/
|
|
1962
|
+
/**
|
|
1963
|
+
* The control a `<label>` click is about to forward to, until the task that clicked it ends. A
|
|
1964
|
+
* label's activation behaviour fires its forwarded click synchronously after its own click's
|
|
1965
|
+
* dispatch, so a capture listener on `document` sees the label's click first. One listener for the
|
|
1966
|
+
* whole page, attached on first use in a browser.
|
|
1967
|
+
*/
|
|
1968
|
+
var forwardingTo = null;
|
|
1969
|
+
var labelWatcherAttached = false;
|
|
1970
|
+
function watchLabelClicks() {
|
|
1971
|
+
if (labelWatcherAttached || typeof document === "undefined") return;
|
|
1972
|
+
labelWatcherAttached = true;
|
|
1973
|
+
document.addEventListener("click", (event) => {
|
|
1974
|
+
const target = event.target;
|
|
1975
|
+
if (!(target instanceof Element)) return;
|
|
1976
|
+
const control = target.closest("label")?.control ?? null;
|
|
1977
|
+
if (!(control instanceof HTMLElement) || control.contains(target)) return;
|
|
1978
|
+
forwardingTo = control;
|
|
1979
|
+
setTimeout(() => {
|
|
1980
|
+
if (forwardingTo === control) forwardingTo = null;
|
|
1981
|
+
}, 0);
|
|
1982
|
+
}, true);
|
|
1983
|
+
}
|
|
1984
|
+
/**
|
|
1985
|
+
* Whether a click with no pointer press behind it came from code (`trigger.click()`) rather than a
|
|
1986
|
+
* `<label>` forwarding its own: not forwarded from a label clicked in this task, untrusted (a
|
|
1987
|
+
* user's label click forwards a trusted one), and a `PointerEvent`, which is what `click()`
|
|
1988
|
+
* dispatches. A bare `dispatchEvent(new MouseEvent('click'))` keeps counting as forwarded, as it
|
|
1989
|
+
* always has; so does every click in an engine whose `click()` still sends a `MouseEvent`.
|
|
1990
|
+
*/
|
|
1991
|
+
function isProgrammaticClick(event, trigger) {
|
|
1992
|
+
if (trigger !== null && forwardingTo !== null && trigger.contains(forwardingTo)) return false;
|
|
1993
|
+
return !event.isTrusted && typeof PointerEvent !== "undefined" && event instanceof PointerEvent;
|
|
1994
|
+
}
|
|
1995
|
+
function usePopover(options) {
|
|
1996
|
+
const { trigger, content } = options;
|
|
1997
|
+
watchLabelClicks();
|
|
1998
|
+
const canOpen = () => options.canOpen?.() !== false;
|
|
1999
|
+
const isOpen = ref(false);
|
|
2000
|
+
const isExclusive = () => {
|
|
2001
|
+
const setting = options.exclusive ?? true;
|
|
2002
|
+
return typeof setting === "function" ? setting() : setting;
|
|
2003
|
+
};
|
|
2004
|
+
/** The `anchor`, when it is a real element rather than a virtual one. */
|
|
2005
|
+
const anchorElement = () => {
|
|
2006
|
+
const anchor = options.anchor?.value ?? null;
|
|
2007
|
+
return typeof HTMLElement !== "undefined" && anchor instanceof HTMLElement ? anchor : null;
|
|
2008
|
+
};
|
|
2009
|
+
/** The registry's handle on this popup. Stable, so the registry can tell ours from another's. */
|
|
2010
|
+
const closeFromRegistry = () => setOpen(false);
|
|
2011
|
+
function setOpen(next) {
|
|
2012
|
+
if (next === isOpen.value) return;
|
|
2013
|
+
if (next) {
|
|
2014
|
+
if (!canOpen()) return;
|
|
2015
|
+
isOpen.value = true;
|
|
2016
|
+
if (isExclusive()) registerOpen(closeFromRegistry, {
|
|
2017
|
+
anchor: trigger.value ?? anchorElement(),
|
|
2018
|
+
contains: (node) => overlay.isInside(node)
|
|
2019
|
+
});
|
|
2020
|
+
options.onOpen?.();
|
|
2021
|
+
return;
|
|
2022
|
+
}
|
|
2023
|
+
isOpen.value = false;
|
|
2024
|
+
unregisterOpen(closeFromRegistry);
|
|
2025
|
+
options.onClose?.();
|
|
2026
|
+
}
|
|
2027
|
+
const overlay = useOverlay({
|
|
2028
|
+
open: isOpen,
|
|
2029
|
+
trigger,
|
|
2030
|
+
content,
|
|
2031
|
+
setOpen: (next) => setOpen(next),
|
|
2032
|
+
closeOnOutsideClick: options.closeOnOutsideClick,
|
|
2033
|
+
closeOnFocusOutside: options.closeOnFocusOutside,
|
|
2034
|
+
closeOnEscape: options.closeOnEscape,
|
|
2035
|
+
returnFocus: options.returnFocus
|
|
2036
|
+
});
|
|
2037
|
+
const teleport = options.teleport ?? true;
|
|
2038
|
+
const { teleportTo, teleportDisabled } = useTeleportTarget({
|
|
2039
|
+
trigger: computed(() => trigger.value ?? anchorElement()),
|
|
2040
|
+
teleport,
|
|
2041
|
+
isOpen
|
|
2042
|
+
});
|
|
2043
|
+
const { styles: floatingStyles, placement, update } = useFloating$1(computed(() => options.anchor?.value ?? trigger.value), content, {
|
|
2044
|
+
placement: options.placement ?? "auto",
|
|
2045
|
+
offset: options.offset,
|
|
2046
|
+
padding: options.padding,
|
|
2047
|
+
matchWidth: options.matchWidth,
|
|
2048
|
+
strategy: teleport === false ? "absolute" : "fixed"
|
|
2049
|
+
});
|
|
2050
|
+
const wantsTabRedirect = () => {
|
|
2051
|
+
const setting = options.tabRedirect ?? false;
|
|
2052
|
+
return typeof setting === "function" ? setting() : setting;
|
|
2053
|
+
};
|
|
2054
|
+
/**
|
|
2055
|
+
* Every tab stop of this overlay that is **not** in the panel, in document order — the trigger,
|
|
2056
|
+
* plus anything claiming the panel's id with `data-eldra-overlay-owner` (a multi-select's clear
|
|
2057
|
+
* button). These keep their natural place in the walk: the redirect happens at the **last** of
|
|
2058
|
+
* them, so `Tab` still passes each one on the way to the panel.
|
|
2059
|
+
*
|
|
2060
|
+
* The owner elements are found with a plain attribute-presence selector and filtered by value in
|
|
2061
|
+
* JavaScript, for the reason `useOverlay` walks the attribute by hand: an id is merchant-settable
|
|
2062
|
+
* through the `id` prop, and one holding a character CSS would need escaped must not break this.
|
|
2063
|
+
*/
|
|
2064
|
+
function stopsBeforePanel(panel) {
|
|
2065
|
+
const roots = [];
|
|
2066
|
+
if (trigger.value !== null) roots.push(trigger.value);
|
|
2067
|
+
const id = panel.id;
|
|
2068
|
+
if (id !== "") for (const owner of document.querySelectorAll(`[${OVERLAY_OWNER_ATTRIBUTE}]`)) {
|
|
2069
|
+
if (owner.getAttribute("data-eldra-overlay-owner") !== id) continue;
|
|
2070
|
+
if (panel.contains(owner) || roots.includes(owner)) continue;
|
|
2071
|
+
roots.push(owner);
|
|
2072
|
+
}
|
|
2073
|
+
return roots.flatMap((root) => overlay.focusables(root)).sort((a, b) => (a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING) === 0 ? 1 : -1);
|
|
2074
|
+
}
|
|
2075
|
+
/**
|
|
2076
|
+
* The two boundary keystrokes of the walk described on the `tabRedirect` option: into the panel
|
|
2077
|
+
* from the last tab stop the control still holds, and back out of the panel's first row to that
|
|
2078
|
+
* same stop. Everything else about `Tab` is left to the browser, which is what keeps this a
|
|
2079
|
+
* redirect rather than a trap — including the steps *within* the control, so a multi-select's
|
|
2080
|
+
* clear button is passed on the way in and returned to on the way back.
|
|
2081
|
+
*
|
|
2082
|
+
* It listens in the **capture** phase, before the control's own `keydown` reaches its handler:
|
|
2083
|
+
* `useListbox`'s `Tab` case asks the caller to close (the `SearchBar` does), and a popup that has
|
|
2084
|
+
* already closed has nothing left to walk into. Propagation is stopped only on the two keystrokes
|
|
2085
|
+
* actually redirected, so every other `Tab` arrives at the control untouched.
|
|
2086
|
+
*/
|
|
2087
|
+
function onTabKeyDown(event) {
|
|
2088
|
+
if (event.key !== "Tab" || event.altKey || event.ctrlKey || event.metaKey) return;
|
|
2089
|
+
if (!isOpen.value || teleportDisabled.value || !wantsTabRedirect()) return;
|
|
2090
|
+
const panel = content.value;
|
|
2091
|
+
const active = document.activeElement;
|
|
2092
|
+
if (panel === null || active === null) return;
|
|
2093
|
+
const first = overlay.focusables()[0];
|
|
2094
|
+
if (first === void 0) return;
|
|
2095
|
+
const last = stopsBeforePanel(panel).at(-1);
|
|
2096
|
+
if (event.shiftKey) {
|
|
2097
|
+
if (active !== first) return;
|
|
2098
|
+
event.preventDefault();
|
|
2099
|
+
event.stopPropagation();
|
|
2100
|
+
(last ?? trigger.value)?.focus();
|
|
2101
|
+
return;
|
|
2102
|
+
}
|
|
2103
|
+
if (panel.contains(active) || !overlay.isInside(active)) return;
|
|
2104
|
+
if (last !== void 0 && active !== last) return;
|
|
2105
|
+
event.preventDefault();
|
|
2106
|
+
event.stopPropagation();
|
|
2107
|
+
first.focus();
|
|
2108
|
+
}
|
|
2109
|
+
const attachTabRedirect = () => {
|
|
2110
|
+
if (typeof document === "undefined") return;
|
|
2111
|
+
document.addEventListener("keydown", onTabKeyDown, true);
|
|
2112
|
+
};
|
|
2113
|
+
const detachTabRedirect = () => {
|
|
2114
|
+
if (typeof document === "undefined") return;
|
|
2115
|
+
document.removeEventListener("keydown", onTabKeyDown, true);
|
|
2116
|
+
};
|
|
2117
|
+
watch(isOpen, (open) => open ? attachTabRedirect() : detachTabRedirect(), { immediate: true });
|
|
2118
|
+
function open(activate) {
|
|
2119
|
+
if (!canOpen()) return;
|
|
2120
|
+
const wasOpen = isOpen.value;
|
|
2121
|
+
setOpen(true);
|
|
2122
|
+
if (!isOpen.value) return;
|
|
2123
|
+
activate?.(wasOpen);
|
|
2124
|
+
if (!wasOpen) options.afterOpen?.();
|
|
2125
|
+
}
|
|
2126
|
+
function close(returnFocus = true) {
|
|
2127
|
+
if (!isOpen.value) return;
|
|
2128
|
+
setOpen(false);
|
|
2129
|
+
if (returnFocus) trigger.value?.focus();
|
|
2130
|
+
}
|
|
2131
|
+
let pressedTrigger = false;
|
|
2132
|
+
function releaseTrigger(event) {
|
|
2133
|
+
detachTriggerRelease();
|
|
2134
|
+
const target = event.target;
|
|
2135
|
+
if (target instanceof Node && trigger.value?.contains(target) === true) return;
|
|
2136
|
+
pressedTrigger = false;
|
|
2137
|
+
}
|
|
2138
|
+
function detachTriggerRelease() {
|
|
2139
|
+
if (typeof document === "undefined") return;
|
|
2140
|
+
document.removeEventListener("pointerup", releaseTrigger, true);
|
|
2141
|
+
document.removeEventListener("pointercancel", releaseTrigger, true);
|
|
2142
|
+
}
|
|
2143
|
+
function onTriggerPointerDown() {
|
|
2144
|
+
pressedTrigger = true;
|
|
2145
|
+
if (typeof document === "undefined") return;
|
|
2146
|
+
document.addEventListener("pointerup", releaseTrigger, true);
|
|
2147
|
+
document.addEventListener("pointercancel", releaseTrigger, true);
|
|
2148
|
+
}
|
|
2149
|
+
function onTriggerClick(event) {
|
|
2150
|
+
const fromPointer = pressedTrigger || event.detail > 0 || isProgrammaticClick(event, trigger.value);
|
|
2151
|
+
pressedTrigger = false;
|
|
2152
|
+
if (!canOpen()) return;
|
|
2153
|
+
if (!fromPointer) {
|
|
2154
|
+
trigger.value?.focus();
|
|
2155
|
+
return;
|
|
2156
|
+
}
|
|
2157
|
+
if (isOpen.value) close();
|
|
2158
|
+
else options.openFromPointer?.();
|
|
2159
|
+
}
|
|
2160
|
+
onBeforeUnmount(() => {
|
|
2161
|
+
unregisterOpen(closeFromRegistry);
|
|
2162
|
+
detachTriggerRelease();
|
|
2163
|
+
detachTabRedirect();
|
|
2164
|
+
});
|
|
2165
|
+
/**
|
|
2166
|
+
* Which corner the panel grows from: the one it is anchored by, so the entrance reads as the
|
|
2167
|
+
* control opening out rather than as a box arriving from somewhere. A panel below the control
|
|
2168
|
+
* grows from `top left`, a flipped one from `bottom left`. A custom property rather than a second
|
|
2169
|
+
* animation class: see the composable's own comment above, and the keyframes in `tailwind.css`.
|
|
2170
|
+
*
|
|
2171
|
+
* Logical directions are deliberately not used. `transform-origin` takes physical keywords only
|
|
2172
|
+
* (`left`/`right`, never `inline-start`), and every panel in this package is `start`-aligned and
|
|
2173
|
+
* at least as wide as its control, so the horizontal half barely moves the result either way.
|
|
2174
|
+
*/
|
|
2175
|
+
const origin = computed(() => {
|
|
2176
|
+
if (placement.value.startsWith("top")) return "bottom left";
|
|
2177
|
+
if (placement.value.startsWith("left")) return "top right";
|
|
2178
|
+
return "top left";
|
|
2179
|
+
});
|
|
2180
|
+
return {
|
|
2181
|
+
isOpen,
|
|
2182
|
+
setOpen,
|
|
2183
|
+
open,
|
|
2184
|
+
close,
|
|
2185
|
+
panelStyle: computed(() => ({
|
|
2186
|
+
...floatingStyles.value,
|
|
2187
|
+
"--eldra-popover-origin": origin.value
|
|
2188
|
+
})),
|
|
2189
|
+
placement,
|
|
2190
|
+
teleportTo,
|
|
2191
|
+
teleportDisabled,
|
|
2192
|
+
onTriggerPointerDown,
|
|
2193
|
+
onTriggerClick,
|
|
2194
|
+
focusFirst: overlay.focusFirst,
|
|
2195
|
+
isInside: overlay.isInside,
|
|
2196
|
+
update
|
|
2197
|
+
};
|
|
2198
|
+
}
|
|
2199
|
+
export { FIELD_SEARCH_APPEARANCE as A, LOCALE_KEY as B, FIELD_DISABLED as C, FIELD_PREFIX_PAD as D, FIELD_LIVE as E, FIELD_TRAILING_PAD as F, FIELD_KEY as G, provideEldraUiLocale as H, FIELD_TRAILING_PAD_PAIR as I, ICON_STROKE_WIDTH as J, Spinner_default as K, fieldState as L, FIELD_SUFFIX_ROW as M, FIELD_SUFFIX_ROW_BASE as N, FIELD_PREFIX_ROW as O, FIELD_TEXT as P, useUiId as Q, CURRENCY_KEY as R, FIELD_CLEAR_SIZE as S, FIELD_LEADING_PAD as T, useEldraUiCurrency as U, provideEldraUiCurrency as V, useEldraUiLocale as W, useControllableModel as X, mergeClass as Y, joinIds as Z, FIELD_ACTION_ROOM_REM as _, useFloating$1 as a, FIELD_CLEAR_BUTTON as b, useOptionList as c, SelectPanel_default as d, TRIGGER_VALUE_CELL as f, FIELD_ACTION_PAIR_SIZE as g, optionSwatchClass as h, useTeleportTarget as i, FIELD_SIZE as j, FIELD_RADIUS as k, normalizeText as l, optionIconClass as m, useOverlay as n, CREATE_VALUE as o, TRIGGER_VALUE_STACK as p, ICON_SIZE_CLASS as q, topLayerDialog as r, matchRange as s, usePopover as t, useListbox as u, FIELD_BASE as v, FIELD_LEADING_ICON as w, FIELD_CLEAR_BUTTON_BOX as x, FIELD_BOX as y, DEFAULT_UI_LOCALE as z };
|