@eldrajs/ui 0.3.8 → 0.3.10
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 +5 -0
- package/LICENSE-country-flag-icons +1 -1
- package/README.md +93 -4
- package/dist/CountryFlag-DOa8lOHp.js +71 -0
- package/dist/{PhoneInput-CYGpERg4.js → PhoneInput-BVH32MEg.js} +8 -62
- package/dist/{VariantPicker-D_Gg80So.js → VariantPicker-CKDdeFmV.js} +2962 -2531
- package/dist/componentNames.d.ts +1 -1
- package/dist/components/autocomplete/Autocomplete.vue.d.ts +216 -0
- package/dist/components/autocomplete/types.d.ts +50 -0
- package/dist/components/button/Button.vue.d.ts +4 -4
- package/dist/components/card/ContentCard.vue.d.ts +1 -1
- package/dist/components/carousel/Carousel.vue.d.ts +1 -1
- package/dist/components/checkbox/Checkbox.vue.d.ts +3 -3
- package/dist/components/chip/Chip.vue.d.ts +3 -1
- package/dist/components/container/Container.vue.d.ts +1 -1
- package/dist/components/dialog/Dialog.vue.d.ts +2 -0
- package/dist/components/drawer/Drawer.vue.d.ts +5 -3
- package/dist/components/field-wrapper/FieldWrapper.vue.d.ts +1 -1
- package/dist/components/filter-panel/FilterGroup.vue.d.ts +2 -0
- package/dist/components/filter-panel/FilterPanel.vue.d.ts +6 -4
- package/dist/components/filter-panel/facets/ColourFacet.vue.d.ts +2 -0
- package/dist/components/filter-panel/facets/ListFacet.vue.d.ts +2 -0
- package/dist/components/filter-panel/facets/RangeFacet.vue.d.ts +3 -1
- package/dist/components/filter-panel/facets/SizeFacet.vue.d.ts +2 -0
- package/dist/components/filter-panel/facets/ToggleFacet.vue.d.ts +2 -0
- package/dist/components/form-layout/FormLayout.vue.d.ts +2 -2
- package/dist/components/image/Image.vue.d.ts +3 -3
- package/dist/components/input/Input.vue.d.ts +7 -7
- package/dist/components/lightbox/Lightbox.vue.d.ts +3 -1
- package/dist/components/nav-menu/NavMenu.vue.d.ts +5 -3
- package/dist/components/pagination/Pagination.vue.d.ts +4 -2
- package/dist/components/popover/Popover.vue.d.ts +3 -3
- package/dist/components/quantity-stepper/QuantityStepper.vue.d.ts +2 -2
- package/dist/components/radio/Radio.vue.d.ts +1 -1
- package/dist/components/range-slider/RangeSlider.vue.d.ts +3 -1
- package/dist/components/search-bar/SearchBar.vue.d.ts +5 -3
- package/dist/components/search-bar/SearchResultsPanel.vue.d.ts +1 -1
- package/dist/components/search-modal/SearchModal.vue.d.ts +4 -2
- package/dist/components/select/MultiSelect.vue.d.ts +13 -10
- package/dist/components/select/Select.vue.d.ts +13 -11
- package/dist/components/select/SelectPanel.vue.d.ts +1 -1
- package/dist/components/select/types.d.ts +7 -1
- package/dist/components/site-form/SiteForm.vue.d.ts +2 -0
- package/dist/components/skeleton/Skeleton.vue.d.ts +1 -1
- package/dist/components/switch/Switch.vue.d.ts +1 -1
- package/dist/components/textarea/Textarea.vue.d.ts +3 -3
- package/dist/components/toast/Toast.vue.d.ts +3 -1
- package/dist/components/toast/Toaster.vue.d.ts +2 -0
- package/dist/components/unit-input/UnitInput.vue.d.ts +6 -6
- package/dist/{phone/PhoneFlag.vue.d.ts → flag/CountryFlag.vue.d.ts} +3 -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.d.ts +2 -0
- package/dist/index.js +5 -4
- package/dist/messages/en-US.d.ts +4 -0
- package/dist/messages/is-IS.js +2 -0
- package/dist/phone/PhoneInput.vue.d.ts +8 -6
- package/dist/phone/index.d.ts +1 -1
- package/dist/phone/vee-validate.js +4 -4
- package/dist/phone.js +3 -1
- package/dist/resolver.d.ts +8 -2
- package/dist/resolver.js +14 -2
- package/dist/useEldraScope-BDbGzt7R.js +32 -0
- package/dist/{useFieldControl-D_b9SC9s.js → useFieldControl-CGH6GEWM.js} +2 -2
- package/dist/{useMessages-DQQPh1P_.js → useMessages-CYnyGVRG.js} +4 -0
- package/dist/{usePopover-4CQR2hB5.js → useOptionList-CPHHDvPF.js} +1477 -1506
- package/dist/vee-validate/FieldAutocomplete.vue.d.ts +20 -0
- package/dist/vee-validate/Form.vue.d.ts +2 -2
- package/dist/vee-validate/index.d.ts +3 -2
- package/dist/vee-validate/types.d.ts +4 -1
- package/dist/vee-validate/useFieldControl.d.ts +1 -1
- package/dist/vee-validate.js +73 -5
- package/dist/vue-i18n.js +1 -1
- package/package.json +6 -2
- package/dist/phone/flags.d.ts +0 -8
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
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";
|
|
2
3
|
import { extendTailwindMerge } from "tailwind-merge";
|
|
3
4
|
import { autoUpdate, flip, offset, shift, size, useFloating } from "@floating-ui/vue";
|
|
4
5
|
// src/utils/id.ts
|
|
@@ -47,36 +48,6 @@ function joinIds(...ids) {
|
|
|
47
48
|
}
|
|
48
49
|
return seen.size > 0 ? [...seen].join(" ") : void 0;
|
|
49
50
|
}
|
|
50
|
-
// src/composables/useEldraScope.ts
|
|
51
|
-
/** The injection key `provideEldraScope` provides under. */
|
|
52
|
-
var ELDRA_SCOPE_KEY = Symbol("eldra-scope");
|
|
53
|
-
/**
|
|
54
|
-
* Names a theming scope for every component of this package rendered below the caller (see the
|
|
55
|
-
* README, "Theming a subtree"). Call it in `setup()` of a wrapper or an app root.
|
|
56
|
-
*
|
|
57
|
-
* Each component then renders `data-eldra-scope="<name>"` on its root and on every part it
|
|
58
|
-
* teleports (panels, dialogs, toasts). The name is free; the consumer's own variable overrides
|
|
59
|
-
* target it (`[data-eldra-scope='studio'] { --eldra-color-primary: … }`). Without a provider the
|
|
60
|
-
* attribute is not rendered, so the output is unchanged.
|
|
61
|
-
*/
|
|
62
|
-
function provideEldraScope(name = "default") {
|
|
63
|
-
provide(ELDRA_SCOPE_KEY, name || "default");
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Internal: the theming hooks a component of this package binds. `scope` goes on every root,
|
|
67
|
-
* teleported root and kit-owned element sitting directly in a slot host, so a scope's variables
|
|
68
|
-
* reach it; it is `undefined` without a provider. `slotHost(...names)` is `data-eldra-slot`, on
|
|
69
|
-
* the element holding those slots, a hook for consumer CSS. It renders whenever one of the slots
|
|
70
|
-
* has content, provider or not, and never for a fallback, which is the kit's own markup.
|
|
71
|
-
*/
|
|
72
|
-
function useEldraScope() {
|
|
73
|
-
const scope = inject(ELDRA_SCOPE_KEY, void 0);
|
|
74
|
-
const slots = useSlots();
|
|
75
|
-
return {
|
|
76
|
-
scope,
|
|
77
|
-
slotHost: (...names) => names.some((name) => slots[name] !== void 0) ? "" : void 0
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
51
|
// src/composables/useControllableModel.ts
|
|
81
52
|
/**
|
|
82
53
|
* A model that works both ways round: controlled when the parent passes
|
|
@@ -312,174 +283,9 @@ var kitMerge = extendTailwindMerge({
|
|
|
312
283
|
function mergeClass(own, incoming) {
|
|
313
284
|
return kitMerge(normalizeClass([own, incoming]));
|
|
314
285
|
}
|
|
315
|
-
// src/components/icon/sizes.ts
|
|
316
|
-
/**
|
|
317
|
-
* The spec's sizes as Tailwind utilities. The theme's `--spacing` is 0.25rem,
|
|
318
|
-
* so `size-4`/`size-5`/`size-6`/`size-8` are exactly 1/1.25/1.5/2rem — no
|
|
319
|
-
* literal length appears here or in the built CSS.
|
|
320
|
-
*/
|
|
321
|
-
var ICON_SIZE_CLASS = {
|
|
322
|
-
sm: "eldra:size-4",
|
|
323
|
-
md: "eldra:size-5",
|
|
324
|
-
lg: "eldra:size-6",
|
|
325
|
-
xl: "eldra:size-8"
|
|
326
|
-
};
|
|
327
|
-
/** The spec's outline stroke weight. */
|
|
328
|
-
var ICON_STROKE_WIDTH = 1.75;
|
|
329
|
-
// src/components/spinner/Spinner.vue?vue&type=script&setup=true&lang.ts
|
|
330
|
-
var _hoisted_1$1 = [
|
|
331
|
-
"data-eldra-scope",
|
|
332
|
-
"role",
|
|
333
|
-
"aria-label",
|
|
334
|
-
"aria-hidden"
|
|
335
|
-
];
|
|
336
|
-
// src/components/spinner/Spinner.vue
|
|
337
|
-
var Spinner_default = /* @__PURE__ */ defineComponent({
|
|
338
|
-
inheritAttrs: false,
|
|
339
|
-
__name: "Spinner",
|
|
340
|
-
props: { label: { default: void 0 } },
|
|
341
|
-
setup(__props) {
|
|
342
|
-
const props = __props;
|
|
343
|
-
const eldra = useEldraScope();
|
|
344
|
-
const attrs = useAttrs();
|
|
345
|
-
const forwardedAttrs = computed(() => {
|
|
346
|
-
const { class: _class, ...rest } = attrs;
|
|
347
|
-
return rest;
|
|
348
|
-
});
|
|
349
|
-
const rootClass = computed(() => mergeClass("eldra:size-4.5 eldra:animate-eldra-spin eldra:motion-reduce:animate-eldra-pulse", attrs.class));
|
|
350
|
-
/** `""` names nothing, so it is decorative too. */
|
|
351
|
-
const named = computed(() => props.label !== void 0 && props.label !== "");
|
|
352
|
-
return (_ctx, _cache) => {
|
|
353
|
-
return openBlock(), createElementBlock("svg", mergeProps({
|
|
354
|
-
"data-eldra-ui": "",
|
|
355
|
-
"data-eldra-scope": unref(eldra).scope,
|
|
356
|
-
class: rootClass.value,
|
|
357
|
-
viewBox: "0 0 18 18",
|
|
358
|
-
fill: "none",
|
|
359
|
-
role: named.value ? "img" : void 0,
|
|
360
|
-
"aria-label": named.value ? __props.label : void 0,
|
|
361
|
-
"aria-hidden": named.value ? void 0 : "true",
|
|
362
|
-
focusable: "false"
|
|
363
|
-
}, forwardedAttrs.value), [..._cache[0] || (_cache[0] = [createElementVNode("circle", {
|
|
364
|
-
cx: "9",
|
|
365
|
-
cy: "9",
|
|
366
|
-
r: "8",
|
|
367
|
-
stroke: "currentColor",
|
|
368
|
-
"stroke-width": "2",
|
|
369
|
-
"stroke-opacity": "0.3"
|
|
370
|
-
}, null, -1), createElementVNode("path", {
|
|
371
|
-
d: "M17 9a8 8 0 0 0-8-8",
|
|
372
|
-
stroke: "currentColor",
|
|
373
|
-
"stroke-width": "2",
|
|
374
|
-
"stroke-linecap": "round"
|
|
375
|
-
}, null, -1)])], 16, _hoisted_1$1);
|
|
376
|
-
};
|
|
377
|
-
}
|
|
378
|
-
});
|
|
379
286
|
// src/components/field-wrapper/context.ts
|
|
380
287
|
/** The key a `FieldWrapper` provides its `FieldContext` on. */
|
|
381
288
|
var FIELD_KEY = Symbol("eldra-ui:field");
|
|
382
|
-
// src/composables/useLocale.ts
|
|
383
|
-
/**
|
|
384
|
-
* The number locale the components format with, as a provide/inject pair — the same shape as
|
|
385
|
-
* `useMessages`, and deliberately separate from it: the *strings* a component renders and the
|
|
386
|
-
* *locale its numbers are formatted in* are two different decisions, and a store that accepts the
|
|
387
|
-
* English defaults may still be an Icelandic shop.
|
|
388
|
-
*
|
|
389
|
-
* It is an ambient default, never an answer: every component that reads it also takes a `locale`
|
|
390
|
-
* prop, and the prop wins. With nothing provided the components format in `en-US`.
|
|
391
|
-
*/
|
|
392
|
-
var DEFAULT_UI_LOCALE = "en-US";
|
|
393
|
-
/**
|
|
394
|
-
* The injection key the locale provider writes to. Exported so an app can set the locale from
|
|
395
|
-
* outside a `setup()` scope — and so it can provide a **getter**, which is what makes a locale
|
|
396
|
-
* switch reactive without an effect that outlives a server request:
|
|
397
|
-
*
|
|
398
|
-
* ```ts
|
|
399
|
-
* import { LOCALE_KEY } from '@eldrajs/ui';
|
|
400
|
-
* app.provide(LOCALE_KEY, () => store.locale);
|
|
401
|
-
* ```
|
|
402
|
-
*/
|
|
403
|
-
var LOCALE_KEY = Symbol("eldra-ui-locale");
|
|
404
|
-
/**
|
|
405
|
-
* Set the number locale for this component and everything below it.
|
|
406
|
-
*
|
|
407
|
-
* Wraps Vue's `provide`, so it must be called during `setup()`. Use
|
|
408
|
-
* `app.provide(LOCALE_KEY, locale)` for the app-wide case.
|
|
409
|
-
*/
|
|
410
|
-
function provideEldraUiLocale(locale) {
|
|
411
|
-
provide(LOCALE_KEY, locale);
|
|
412
|
-
}
|
|
413
|
-
/**
|
|
414
|
-
* The locale a component should format numbers in: whatever an ancestor provided, else `en-US`.
|
|
415
|
-
* A ref or a getter is unwrapped on every read, so the value follows a locale switch.
|
|
416
|
-
*/
|
|
417
|
-
function useEldraUiLocale() {
|
|
418
|
-
const provided = inject(LOCALE_KEY, void 0);
|
|
419
|
-
return computed(() => toValue(provided) ?? "en-US");
|
|
420
|
-
}
|
|
421
|
-
/**
|
|
422
|
-
* The injection key the store currency is provided under (spec "Price" → Properties, `currency`
|
|
423
|
-
* row: "store currency") — the same provide/inject shape as `LOCALE_KEY` and deliberately separate
|
|
424
|
-
* from it: a store's number locale and its currency are two different decisions (an
|
|
425
|
-
* `en-US`-formatted store may still sell in `ISK`). It is an ambient default, never an answer:
|
|
426
|
-
* every component that reads it also takes a `currency` prop, and the prop wins. **With nothing
|
|
427
|
-
* provided there is no currency at all** — see `useEldraUiCurrency` for what the components then
|
|
428
|
-
* render, and why this pair has no default code.
|
|
429
|
-
*
|
|
430
|
-
* Exported so an app can set the currency from
|
|
431
|
-
* outside a `setup()` scope — and so it can provide a **getter**, which is what makes a currency
|
|
432
|
-
* switch reactive without an effect that outlives a server request:
|
|
433
|
-
*
|
|
434
|
-
* ```ts
|
|
435
|
-
* import { CURRENCY_KEY } from '@eldrajs/ui';
|
|
436
|
-
* app.provide(CURRENCY_KEY, () => store.currency);
|
|
437
|
-
* ```
|
|
438
|
-
*
|
|
439
|
-
* Providing `undefined` is meaningful and different from not providing at all: it says the store
|
|
440
|
-
* has **no** currency, which is the answer a platform that has not been told one must be able to
|
|
441
|
-
* give. Vue's `inject` consults `key in provides`, so the two cases stay distinguishable (see
|
|
442
|
-
* `useEldraUiCurrency`).
|
|
443
|
-
*/
|
|
444
|
-
var CURRENCY_KEY = Symbol("eldra-ui-currency");
|
|
445
|
-
/**
|
|
446
|
-
* Set the store currency for this component and everything below it.
|
|
447
|
-
*
|
|
448
|
-
* Wraps Vue's `provide`, so it must be called during `setup()`. Use
|
|
449
|
-
* `app.provide(CURRENCY_KEY, currency)` for the app-wide case.
|
|
450
|
-
*/
|
|
451
|
-
function provideEldraUiCurrency(currency) {
|
|
452
|
-
provide(CURRENCY_KEY, currency);
|
|
453
|
-
}
|
|
454
|
-
/**
|
|
455
|
-
* A value no provider can supply, so `inject`'s default tells "nobody provided a currency" apart
|
|
456
|
-
* from "a provider answered: this store has none". Vue's `inject` returns a provided `undefined`
|
|
457
|
-
* rather than the default (it tests `key in provides`), which is what makes the distinction real.
|
|
458
|
-
*/
|
|
459
|
-
var NO_CURRENCY_PROVIDER = Symbol("eldra-ui-currency-absent");
|
|
460
|
-
/**
|
|
461
|
-
* The currency a component should format money in: whatever an ancestor provided, else **nothing**.
|
|
462
|
-
* A ref or a getter is unwrapped on every read, so the value follows a currency switch.
|
|
463
|
-
*
|
|
464
|
-
* **There is no default code.** A component library installed by a shop of any kind cannot guess
|
|
465
|
-
* one: a `USD` fallback puts a dollar sign in front of krónur, and a wrong price is worse than an
|
|
466
|
-
* incomplete one. So `undefined` comes back whenever there is no currency to name, and a component
|
|
467
|
-
* reading it formats the amount as a plain number through the same `Intl` path, with no symbol and
|
|
468
|
-
* no code (`Price` does exactly that). The empty string is read as "no currency" too: it is not a
|
|
469
|
-
* code `Intl` accepts, and it was the only way to decline one while this composable still defaulted.
|
|
470
|
-
*
|
|
471
|
-
* Two ways to arrive at `undefined`, and only one of them is a mistake. A provider that supplies
|
|
472
|
-
* `undefined` (or `''`) has *answered* — this store has no currency — and nothing is logged. Having
|
|
473
|
-
* no provider at all is unwired, and warns once per session in dev.
|
|
474
|
-
*/
|
|
475
|
-
function useEldraUiCurrency() {
|
|
476
|
-
const provided = inject(CURRENCY_KEY, NO_CURRENCY_PROVIDER);
|
|
477
|
-
return computed(() => {
|
|
478
|
-
if (provided === NO_CURRENCY_PROVIDER) return;
|
|
479
|
-
const currency = toValue(provided);
|
|
480
|
-
return currency === void 0 || currency === "" ? void 0 : currency;
|
|
481
|
-
});
|
|
482
|
-
}
|
|
483
289
|
// src/components/input/classes.ts
|
|
484
290
|
/**
|
|
485
291
|
* The field recipes of the design spec's **Input**, in one place.
|
|
@@ -647,6 +453,20 @@ var FIELD_ACTION_ROOM_REM = {
|
|
|
647
453
|
md: 2.5,
|
|
648
454
|
lg: 2.5
|
|
649
455
|
};
|
|
456
|
+
// src/components/icon/sizes.ts
|
|
457
|
+
/**
|
|
458
|
+
* The spec's sizes as Tailwind utilities. The theme's `--spacing` is 0.25rem,
|
|
459
|
+
* so `size-4`/`size-5`/`size-6`/`size-8` are exactly 1/1.25/1.5/2rem — no
|
|
460
|
+
* literal length appears here or in the built CSS.
|
|
461
|
+
*/
|
|
462
|
+
var ICON_SIZE_CLASS = {
|
|
463
|
+
sm: "eldra:size-4",
|
|
464
|
+
md: "eldra:size-5",
|
|
465
|
+
lg: "eldra:size-6",
|
|
466
|
+
xl: "eldra:size-8"
|
|
467
|
+
};
|
|
468
|
+
/** The spec's outline stroke weight. */
|
|
469
|
+
var ICON_STROKE_WIDTH = 1.75;
|
|
650
470
|
// src/components/select/panelParts.ts
|
|
651
471
|
/**
|
|
652
472
|
* Every class the **panel** of a select draws, in one place, because `Select` and `MultiSelect`
|
|
@@ -835,1394 +655,1545 @@ function optionTickClass(selected) {
|
|
|
835
655
|
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)]";
|
|
836
656
|
/** The chosen value inside `TRIGGER_VALUE_STACK`, in the cell the placeholder copy shares. */
|
|
837
657
|
var TRIGGER_VALUE_CELL = "eldra:col-start-1 eldra:row-start-1";
|
|
838
|
-
// src/components/select/
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
"
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
loading: {
|
|
909
|
-
type: Boolean,
|
|
910
|
-
default: false
|
|
911
|
-
},
|
|
912
|
-
loadingText: { default: void 0 },
|
|
913
|
-
createOption: { default: void 0 },
|
|
914
|
-
createText: { default: void 0 },
|
|
915
|
-
panelStyle: { default: void 0 },
|
|
916
|
-
placement: { default: void 0 },
|
|
917
|
-
classes: { default: void 0 }
|
|
918
|
-
},
|
|
919
|
-
emits: [
|
|
920
|
-
"search",
|
|
921
|
-
"select",
|
|
922
|
-
"activate",
|
|
923
|
-
"keydown",
|
|
924
|
-
"scrollEnd"
|
|
925
|
-
],
|
|
926
|
-
setup(__props, { expose: __expose, emit: __emit }) {
|
|
927
|
-
const eldra = useEldraScope();
|
|
928
|
-
/**
|
|
929
|
-
* The popover a `Select` and a `MultiSelect` both open: the search field, the listbox with its
|
|
930
|
-
* groups and option rows, and the empty state — plus a `footer` slot, which only a multi-select
|
|
931
|
-
* fills.
|
|
932
|
-
*
|
|
933
|
-
* It exists so that the two controls share one panel rather than two copies of the same markup.
|
|
934
|
-
* Everything it knows is a prop: it owns no open/closed state, no query, no value, and no keyboard
|
|
935
|
-
* (that is `useListbox`). What it does own is the DOM the parents cannot: the panel element and
|
|
936
|
-
* the search input, both exposed so the parent can position the one and focus the other, and the
|
|
937
|
-
* pointer-press guard that keeps a press inside the panel from blurring the focused element.
|
|
938
|
-
*
|
|
939
|
-
* `multiple` is the one behavioural switch, and it is the spec's own: a multi-select's rows carry a
|
|
940
|
-
* checkbox instead of a trailing check mark, and its listbox is `aria-multiselectable="true"`.
|
|
941
|
-
*/
|
|
942
|
-
const props = __props;
|
|
943
|
-
const emit = __emit;
|
|
944
|
-
const root = ref(null);
|
|
945
|
-
const searchInput = ref(null);
|
|
946
|
-
__expose({
|
|
947
|
-
root,
|
|
948
|
-
searchInput
|
|
949
|
-
});
|
|
950
|
-
const isActive = (option) => props.activeValue === option.value;
|
|
951
|
-
const isSelected = (option) => props.selectedValues.includes(option.value);
|
|
952
|
-
const panelClasses = computed(() => panelClass(props.classes));
|
|
953
|
-
const searchClasses = computed(() => searchClass(props.classes));
|
|
954
|
-
const listboxClasses = computed(() => listboxClass(props.classes, props.hasOptions));
|
|
955
|
-
const optionHintClasses = computed(() => optionHintClass(props.classes));
|
|
956
|
-
const optionSwatchClasses = computed(() => optionSwatchClass(props.classes));
|
|
957
|
-
const optionIconClasses = computed(() => optionIconClass(props.classes));
|
|
958
|
-
const optionCheckClasses = computed(() => optionCheckClass(props.classes));
|
|
959
|
-
const emptyClasses = computed(() => emptyClass(props.classes));
|
|
960
|
-
const loadingClasses = computed(() => loadingClass(props.classes));
|
|
961
|
-
const createClasses = computed(() => props.createOption === void 0 ? "" : createOptionClass(props.classes, { active: isActive(props.createOption) }));
|
|
962
|
-
/** Within this many pixels of the end — two rows — the next render batch is asked for. */
|
|
963
|
-
function onListScroll(event) {
|
|
964
|
-
const list = event.currentTarget;
|
|
965
|
-
if (list.scrollHeight - list.scrollTop - list.clientHeight <= SCROLL_END_SLACK) emit("scrollEnd");
|
|
658
|
+
// src/components/select/useListbox.ts
|
|
659
|
+
/** Spec Select → Keyboard, open: "`PageDown` / `PageUp` | Move by 10." */
|
|
660
|
+
var PAGE = 10;
|
|
661
|
+
/** Spec Select → Keyboard, closed: "the buffer resets after 0.6s". */
|
|
662
|
+
var TYPEAHEAD_RESET_MS = 600;
|
|
663
|
+
/**
|
|
664
|
+
* Case- and diacritic-insensitive, so the spec's "'island' finds 'Ísland'" holds for type-ahead
|
|
665
|
+
* and for the search field alike. `NFD` splits a letter from its accent and the range drops the
|
|
666
|
+
* combining marks that are left.
|
|
667
|
+
*/
|
|
668
|
+
function normalizeText(text) {
|
|
669
|
+
return text.normalize("NFD").replaceAll(/[̀-ͯ]/g, "").toLowerCase();
|
|
670
|
+
}
|
|
671
|
+
/** A key that types a character, rather than a chord or a named key. */
|
|
672
|
+
function isPrintable(event) {
|
|
673
|
+
return event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey;
|
|
674
|
+
}
|
|
675
|
+
function clamp(value, min, max) {
|
|
676
|
+
return value < min ? min : value > max ? max : value;
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
679
|
+
* The keyboard and the active row of a listbox popup — everything in the design spec's Select →
|
|
680
|
+
* Keyboard tables that is not about *what* choosing a row does.
|
|
681
|
+
*
|
|
682
|
+
* It is separate from `Select.vue` on purpose. `MultiSelect` (the next component) has the same two
|
|
683
|
+
* keyboard tables with three differences — `Enter` toggles instead of choosing-and-closing,
|
|
684
|
+
* `Space` toggles, and the popup stays open — all of which are the caller's `select` callback and
|
|
685
|
+
* the caller's decision about closing. Everything else (arrow movement that skips disabled and
|
|
686
|
+
* filtered-out rows and stops at the ends, `PageUp`/`PageDown` by ten, `Home`/`End` unless a
|
|
687
|
+
* search field owns them, `Alt+ArrowUp`, `Escape` clearing a query before it closes, `Tab`
|
|
688
|
+
* closing without a choice, and type-ahead with a 0.6s buffer) is identical, and identical code
|
|
689
|
+
* that is written twice stops being identical.
|
|
690
|
+
*
|
|
691
|
+
* The composable owns no DOM. `aria-activedescendant` is `activeId`, which the caller binds to
|
|
692
|
+
* whichever element is focused — the trigger when there is no search field, the search field when
|
|
693
|
+
* there is — and scrolling the active row into view is the caller's, because only the caller knows
|
|
694
|
+
* which element a value maps to.
|
|
695
|
+
*
|
|
696
|
+
* ```ts
|
|
697
|
+
* const listbox = useListbox({
|
|
698
|
+
* options: () => visibleOptions.value,
|
|
699
|
+
* isOpen: () => open.value,
|
|
700
|
+
* searchable: () => searchable.value,
|
|
701
|
+
* optionId: (value) => `${id.value}-option-${value}`,
|
|
702
|
+
* open: (edge) => openPanel(edge),
|
|
703
|
+
* close: () => closePanel(),
|
|
704
|
+
* select: (option) => choose(option.value),
|
|
705
|
+
* });
|
|
706
|
+
* ```
|
|
707
|
+
*/
|
|
708
|
+
function useListbox(options) {
|
|
709
|
+
const activeValue = ref(void 0);
|
|
710
|
+
const activeId = computed(() => activeValue.value === void 0 ? void 0 : options.optionId(activeValue.value));
|
|
711
|
+
/** Only enabled rows are reachable: "Arrow keys skip it" (Select → Variants, Disabled option). */
|
|
712
|
+
const enabled = () => options.options().filter((option) => !option.disabled);
|
|
713
|
+
const setActive = (value) => {
|
|
714
|
+
activeValue.value = value;
|
|
715
|
+
};
|
|
716
|
+
const first = () => setActive(enabled()[0]?.value);
|
|
717
|
+
const last = () => setActive(enabled().at(-1)?.value);
|
|
718
|
+
const activateFrom = (value) => {
|
|
719
|
+
const rows = enabled();
|
|
720
|
+
const match = rows.find((option) => option.value === value);
|
|
721
|
+
setActive((match ?? rows[0])?.value);
|
|
722
|
+
};
|
|
723
|
+
const move = (step) => {
|
|
724
|
+
const rows = enabled();
|
|
725
|
+
if (rows.length === 0) {
|
|
726
|
+
setActive(void 0);
|
|
727
|
+
return;
|
|
966
728
|
}
|
|
967
|
-
const
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
});
|
|
972
|
-
const boxClass = (option) => optionBoxClass(props.classes, {
|
|
973
|
-
selected: isSelected(option),
|
|
974
|
-
disabled: option.disabled === true
|
|
975
|
-
});
|
|
976
|
-
/**
|
|
977
|
-
* Spec "Select" → Behaviour: "The active option is scrolled into view with a 0.25rem margin
|
|
978
|
-
* whenever it changes" — the margin is the row's own `scroll-my-1`.
|
|
979
|
-
*
|
|
980
|
-
* It lives here rather than in either parent because it is the one part of "the active row" that
|
|
981
|
-
* needs an element, and the panel is what has the elements. Both controls get it from one copy.
|
|
982
|
-
*/
|
|
983
|
-
function scrollActiveIntoView() {
|
|
984
|
-
const value = props.activeValue;
|
|
985
|
-
if (value === void 0 || typeof document === "undefined") return;
|
|
986
|
-
document.getElementById(props.optionId(value))?.scrollIntoView?.({ block: "nearest" });
|
|
729
|
+
const index = rows.findIndex((option) => option.value === activeValue.value);
|
|
730
|
+
if (index === -1) {
|
|
731
|
+
setActive((step > 0 ? rows[0] : rows.at(-1))?.value);
|
|
732
|
+
return;
|
|
987
733
|
}
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
734
|
+
setActive(rows[clamp(index + step, 0, rows.length - 1)]?.value);
|
|
735
|
+
};
|
|
736
|
+
const selectActive = () => {
|
|
737
|
+
const option = options.options().find((row) => row.value === activeValue.value);
|
|
738
|
+
if (option === void 0 || option.disabled === true) return;
|
|
739
|
+
options.select(option);
|
|
740
|
+
};
|
|
741
|
+
let buffer = "";
|
|
742
|
+
let timer;
|
|
743
|
+
const resetTypeahead = () => {
|
|
744
|
+
buffer = "";
|
|
745
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
746
|
+
timer = void 0;
|
|
747
|
+
};
|
|
748
|
+
onScopeDispose(resetTypeahead);
|
|
749
|
+
function typeahead(character, inclusive = false) {
|
|
750
|
+
buffer += character;
|
|
751
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
752
|
+
timer = setTimeout(resetTypeahead, TYPEAHEAD_RESET_MS);
|
|
753
|
+
const rows = enabled();
|
|
754
|
+
if (rows.length === 0) return;
|
|
755
|
+
const prefix = normalizeText(buffer);
|
|
756
|
+
const current = rows.findIndex((option) => option.value === activeValue.value);
|
|
757
|
+
const from = buffer.length === 1 && !inclusive ? current + 1 : Math.max(current, 0);
|
|
758
|
+
for (let step = 0; step < rows.length; step += 1) {
|
|
759
|
+
const option = rows[(from + step + rows.length) % rows.length];
|
|
760
|
+
if (option !== void 0 && normalizeText(option.label).startsWith(prefix)) {
|
|
761
|
+
setActive(option.value);
|
|
762
|
+
return;
|
|
763
|
+
}
|
|
992
764
|
}
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
765
|
+
}
|
|
766
|
+
function onClosedKeydown(event) {
|
|
767
|
+
switch (event.key) {
|
|
768
|
+
case "ArrowDown":
|
|
769
|
+
case "Enter":
|
|
770
|
+
case " ":
|
|
771
|
+
event.preventDefault();
|
|
772
|
+
options.open("start");
|
|
773
|
+
return;
|
|
774
|
+
case "ArrowUp":
|
|
775
|
+
event.preventDefault();
|
|
776
|
+
options.open(options.searchable() ? "start" : "end");
|
|
777
|
+
return;
|
|
778
|
+
case "Backspace":
|
|
779
|
+
case "Delete":
|
|
780
|
+
if (options.clear?.() === true) event.preventDefault();
|
|
781
|
+
return;
|
|
782
|
+
default:
|
|
783
|
+
if (!isPrintable(event)) return;
|
|
784
|
+
event.preventDefault();
|
|
785
|
+
options.open("start");
|
|
786
|
+
if (options.searchable()) options.startQuery?.(event.key);
|
|
787
|
+
else typeahead(event.key, true);
|
|
1001
788
|
}
|
|
1002
|
-
return (_ctx, _cache) => {
|
|
1003
|
-
return openBlock(), createElementBlock("div", {
|
|
1004
|
-
ref_key: "root",
|
|
1005
|
-
ref: root,
|
|
1006
|
-
"data-eldra-slot": unref(eldra).slotHost("footer"),
|
|
1007
|
-
id: __props.panelId,
|
|
1008
|
-
"data-eldra-ui": "",
|
|
1009
|
-
"data-eldra-scope": unref(eldra).scope,
|
|
1010
|
-
"data-part": "panel",
|
|
1011
|
-
"data-eldra-overlay-owner": __props.panelId,
|
|
1012
|
-
class: normalizeClass(panelClasses.value),
|
|
1013
|
-
style: normalizeStyle(__props.panelStyle),
|
|
1014
|
-
"data-placement": __props.placement,
|
|
1015
|
-
onMousedown: onPanelMouseDown
|
|
1016
|
-
}, [
|
|
1017
|
-
__props.searchable ? (openBlock(), createElementBlock("div", {
|
|
1018
|
-
key: 0,
|
|
1019
|
-
"data-eldra-scope": unref(eldra).scope,
|
|
1020
|
-
class: "eldra:relative eldra:shrink-0 eldra:border-b eldra:border-[color:var(--eldra-select-panel-border,var(--eldra-color-border))]"
|
|
1021
|
-
}, [_cache[3] || (_cache[3] = createElementVNode("svg", {
|
|
1022
|
-
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))]",
|
|
1023
|
-
viewBox: "0 0 24 24",
|
|
1024
|
-
fill: "none",
|
|
1025
|
-
stroke: "currentColor",
|
|
1026
|
-
"stroke-width": "1.75",
|
|
1027
|
-
"stroke-linecap": "round",
|
|
1028
|
-
"stroke-linejoin": "round",
|
|
1029
|
-
"aria-hidden": "true",
|
|
1030
|
-
focusable: "false"
|
|
1031
|
-
}, [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", {
|
|
1032
|
-
ref_key: "searchInput",
|
|
1033
|
-
ref: searchInput,
|
|
1034
|
-
"data-part": "search",
|
|
1035
|
-
type: "text",
|
|
1036
|
-
role: "combobox",
|
|
1037
|
-
class: normalizeClass(searchClasses.value),
|
|
1038
|
-
value: __props.query,
|
|
1039
|
-
placeholder: __props.searchPlaceholder,
|
|
1040
|
-
"aria-label": __props.searchPlaceholder,
|
|
1041
|
-
"aria-autocomplete": "list",
|
|
1042
|
-
"aria-expanded": "true",
|
|
1043
|
-
"aria-controls": __props.listboxId,
|
|
1044
|
-
"aria-activedescendant": __props.activeValue === void 0 ? void 0 : __props.optionId(__props.activeValue),
|
|
1045
|
-
autocomplete: "off",
|
|
1046
|
-
spellcheck: "false",
|
|
1047
|
-
onInput: onSearchInput,
|
|
1048
|
-
onKeydown: _cache[0] || (_cache[0] = ($event) => emit("keydown", $event))
|
|
1049
|
-
}, null, 42, _hoisted_3)], 8, _hoisted_2)) : createCommentVNode("", true),
|
|
1050
|
-
createElementVNode("div", {
|
|
1051
|
-
"data-eldra-scope": unref(eldra).scope,
|
|
1052
|
-
id: __props.listboxId,
|
|
1053
|
-
"data-part": "listbox",
|
|
1054
|
-
role: "listbox",
|
|
1055
|
-
class: normalizeClass(listboxClasses.value),
|
|
1056
|
-
"aria-multiselectable": __props.multiple ? "true" : void 0,
|
|
1057
|
-
"aria-labelledby": __props.labelledBy,
|
|
1058
|
-
"aria-label": __props.fallbackLabel,
|
|
1059
|
-
"aria-busy": __props.loading ? "true" : void 0,
|
|
1060
|
-
onScrollPassive: onListScroll
|
|
1061
|
-
}, [(openBlock(true), createElementBlock(Fragment, null, renderList(__props.sections, (section, sectionIndex) => {
|
|
1062
|
-
return openBlock(), createElementBlock("div", {
|
|
1063
|
-
key: section.key,
|
|
1064
|
-
"data-part": section.label ? "group" : void 0,
|
|
1065
|
-
role: section.label ? "group" : "presentation",
|
|
1066
|
-
class: normalizeClass(section.label ? unref(groupClass)(__props.classes, sectionIndex) : void 0),
|
|
1067
|
-
"aria-labelledby": section.labelId
|
|
1068
|
-
}, [section.label ? (openBlock(), createElementBlock("div", {
|
|
1069
|
-
key: 0,
|
|
1070
|
-
id: section.labelId,
|
|
1071
|
-
"data-part": "groupLabel",
|
|
1072
|
-
role: "presentation",
|
|
1073
|
-
class: normalizeClass(unref(groupLabelClass)(__props.classes, sectionIndex))
|
|
1074
|
-
}, toDisplayString(section.label), 11, _hoisted_6)) : createCommentVNode("", true), (openBlock(true), createElementBlock(Fragment, null, renderList(section.options, (option) => {
|
|
1075
|
-
return openBlock(), createElementBlock("div", {
|
|
1076
|
-
key: option.value,
|
|
1077
|
-
"data-eldra-slot": unref(eldra).slotHost("option", "optionContent"),
|
|
1078
|
-
id: __props.optionId(option.value),
|
|
1079
|
-
"data-part": "option",
|
|
1080
|
-
role: "option",
|
|
1081
|
-
class: normalizeClass(rowClass(option)),
|
|
1082
|
-
"aria-selected": isSelected(option) ? "true" : "false",
|
|
1083
|
-
"aria-disabled": option.disabled ? "true" : void 0,
|
|
1084
|
-
onClick: ($event) => emit("select", option),
|
|
1085
|
-
onMouseenter: ($event) => option.disabled ? void 0 : emit("activate", option.value)
|
|
1086
|
-
}, [renderSlot(_ctx.$slots, "option", {
|
|
1087
|
-
option,
|
|
1088
|
-
selected: isSelected(option),
|
|
1089
|
-
active: isActive(option)
|
|
1090
|
-
}, () => [
|
|
1091
|
-
__props.multiple ? (openBlock(), createElementBlock("span", {
|
|
1092
|
-
key: 0,
|
|
1093
|
-
"data-eldra-scope": unref(eldra).scope,
|
|
1094
|
-
"data-part": "optionCheck",
|
|
1095
|
-
class: normalizeClass(boxClass(option)),
|
|
1096
|
-
"aria-hidden": "true"
|
|
1097
|
-
}, [(openBlock(), createElementBlock("svg", {
|
|
1098
|
-
class: normalizeClass(unref(optionTickClass)(isSelected(option))),
|
|
1099
|
-
viewBox: "0 0 8 8",
|
|
1100
|
-
fill: "none",
|
|
1101
|
-
stroke: "currentColor",
|
|
1102
|
-
"stroke-width": "2",
|
|
1103
|
-
"stroke-linecap": "round",
|
|
1104
|
-
"stroke-linejoin": "round",
|
|
1105
|
-
"aria-hidden": "true",
|
|
1106
|
-
focusable: "false"
|
|
1107
|
-
}, [..._cache[4] || (_cache[4] = [createElementVNode("path", { d: "M1 4l2 2l4 -4" }, null, -1)])], 2))], 10, _hoisted_8)) : createCommentVNode("", true),
|
|
1108
|
-
renderSlot(_ctx.$slots, "optionContent", {
|
|
1109
|
-
option,
|
|
1110
|
-
selected: isSelected(option),
|
|
1111
|
-
active: isActive(option),
|
|
1112
|
-
match: __props.highlights.get(option.value) ?? null
|
|
1113
|
-
}, () => [
|
|
1114
|
-
option.swatch ? (openBlock(), createElementBlock("span", {
|
|
1115
|
-
key: 0,
|
|
1116
|
-
"data-part": "optionSwatch",
|
|
1117
|
-
class: normalizeClass(optionSwatchClasses.value),
|
|
1118
|
-
style: normalizeStyle({ backgroundColor: option.swatch }),
|
|
1119
|
-
"aria-hidden": "true"
|
|
1120
|
-
}, null, 6)) : option.icon ? (openBlock(), createBlock(resolveDynamicComponent(option.icon), {
|
|
1121
|
-
key: 1,
|
|
1122
|
-
"data-eldra-scope": unref(eldra).scope,
|
|
1123
|
-
"data-part": "optionIcon",
|
|
1124
|
-
class: normalizeClass(optionIconClasses.value),
|
|
1125
|
-
"stroke-width": unref(ICON_STROKE_WIDTH),
|
|
1126
|
-
"aria-hidden": "true",
|
|
1127
|
-
focusable: "false"
|
|
1128
|
-
}, null, 8, [
|
|
1129
|
-
"data-eldra-scope",
|
|
1130
|
-
"class",
|
|
1131
|
-
"stroke-width"
|
|
1132
|
-
])) : createCommentVNode("", true),
|
|
1133
|
-
createElementVNode("span", _hoisted_9, [createElementVNode("span", {
|
|
1134
|
-
"data-part": "optionLabel",
|
|
1135
|
-
class: normalizeClass(unref(optionLabelClass)(__props.classes))
|
|
1136
|
-
}, [__props.highlights.get(option.value) ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
|
|
1137
|
-
createTextVNode(toDisplayString(__props.highlights.get(option.value)?.before), 1),
|
|
1138
|
-
createElementVNode("span", _hoisted_10, toDisplayString(__props.highlights.get(option.value)?.match), 1),
|
|
1139
|
-
createTextVNode(toDisplayString(__props.highlights.get(option.value)?.after), 1)
|
|
1140
|
-
], 64)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [createTextVNode(toDisplayString(option.label), 1)], 64))], 2), option.hint ? (openBlock(), createElementBlock("span", {
|
|
1141
|
-
key: 0,
|
|
1142
|
-
"data-part": "optionHint",
|
|
1143
|
-
class: normalizeClass(optionHintClasses.value)
|
|
1144
|
-
}, toDisplayString(option.hint), 3)) : createCommentVNode("", true)]),
|
|
1145
|
-
option.meta ? (openBlock(), createElementBlock("span", {
|
|
1146
|
-
key: 2,
|
|
1147
|
-
"data-part": "optionMeta",
|
|
1148
|
-
class: normalizeClass(unref(optionMetaClass)(__props.classes, option))
|
|
1149
|
-
}, toDisplayString(option.meta), 3)) : createCommentVNode("", true)
|
|
1150
|
-
]),
|
|
1151
|
-
!__props.multiple && isSelected(option) ? (openBlock(), createElementBlock("svg", {
|
|
1152
|
-
key: 1,
|
|
1153
|
-
"data-eldra-scope": unref(eldra).scope,
|
|
1154
|
-
"data-part": "optionCheck",
|
|
1155
|
-
class: normalizeClass(optionCheckClasses.value),
|
|
1156
|
-
viewBox: "0 0 24 24",
|
|
1157
|
-
fill: "none",
|
|
1158
|
-
stroke: "currentColor",
|
|
1159
|
-
"stroke-width": "1.75",
|
|
1160
|
-
"stroke-linecap": "round",
|
|
1161
|
-
"stroke-linejoin": "round",
|
|
1162
|
-
"aria-hidden": "true",
|
|
1163
|
-
focusable: "false"
|
|
1164
|
-
}, [..._cache[5] || (_cache[5] = [createElementVNode("path", { d: "M5 12l5 5l10 -10" }, null, -1)])], 10, _hoisted_11)) : createCommentVNode("", true)
|
|
1165
|
-
])], 42, _hoisted_7);
|
|
1166
|
-
}), 128))], 10, _hoisted_5);
|
|
1167
|
-
}), 128)), __props.createOption ? (openBlock(), createElementBlock("div", {
|
|
1168
|
-
key: 0,
|
|
1169
|
-
role: "presentation",
|
|
1170
|
-
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)
|
|
1171
|
-
}, [createElementVNode("div", {
|
|
1172
|
-
id: __props.optionId(__props.createOption.value),
|
|
1173
|
-
"data-part": "createOption",
|
|
1174
|
-
role: "option",
|
|
1175
|
-
"aria-selected": "false",
|
|
1176
|
-
class: normalizeClass(createClasses.value),
|
|
1177
|
-
onClick: _cache[1] || (_cache[1] = ($event) => emit("select", __props.createOption)),
|
|
1178
|
-
onMouseenter: _cache[2] || (_cache[2] = ($event) => emit("activate", __props.createOption.value))
|
|
1179
|
-
}, [(openBlock(), createElementBlock("svg", {
|
|
1180
|
-
class: normalizeClass(optionIconClasses.value),
|
|
1181
|
-
viewBox: "0 0 24 24",
|
|
1182
|
-
fill: "none",
|
|
1183
|
-
stroke: "currentColor",
|
|
1184
|
-
"stroke-width": "1.75",
|
|
1185
|
-
"stroke-linecap": "round",
|
|
1186
|
-
"stroke-linejoin": "round",
|
|
1187
|
-
"aria-hidden": "true",
|
|
1188
|
-
focusable: "false"
|
|
1189
|
-
}, [..._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),
|
|
1190
|
-
__props.loading ? (openBlock(), createElementBlock("div", {
|
|
1191
|
-
key: 1,
|
|
1192
|
-
"data-eldra-slot": unref(eldra).slotHost("loading"),
|
|
1193
|
-
"data-eldra-scope": unref(eldra).scope,
|
|
1194
|
-
"data-part": "loading",
|
|
1195
|
-
role: "status",
|
|
1196
|
-
class: normalizeClass(loadingClasses.value)
|
|
1197
|
-
}, [createVNode(Spinner_default, { class: "eldra:size-4" }), renderSlot(_ctx.$slots, "loading", {}, () => [createTextVNode(toDisplayString(__props.loadingText), 1)])], 10, _hoisted_14)) : !__props.hasOptions ? (openBlock(), createElementBlock("div", {
|
|
1198
|
-
key: 2,
|
|
1199
|
-
"data-eldra-slot": unref(eldra).slotHost("empty"),
|
|
1200
|
-
"data-eldra-scope": unref(eldra).scope,
|
|
1201
|
-
"data-part": "empty",
|
|
1202
|
-
class: normalizeClass(emptyClasses.value)
|
|
1203
|
-
}, [renderSlot(_ctx.$slots, "empty", {}, () => [createTextVNode(toDisplayString(__props.emptyText), 1)])], 10, _hoisted_15)) : createCommentVNode("", true),
|
|
1204
|
-
renderSlot(_ctx.$slots, "footer")
|
|
1205
|
-
], 46, _hoisted_1);
|
|
1206
|
-
};
|
|
1207
789
|
}
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
790
|
+
function onOpenKeydown(event) {
|
|
791
|
+
switch (event.key) {
|
|
792
|
+
case "ArrowDown":
|
|
793
|
+
event.preventDefault();
|
|
794
|
+
move(1);
|
|
795
|
+
return;
|
|
796
|
+
case "ArrowUp":
|
|
797
|
+
event.preventDefault();
|
|
798
|
+
if (event.altKey) selectActive();
|
|
799
|
+
else move(-1);
|
|
800
|
+
return;
|
|
801
|
+
case "PageDown":
|
|
802
|
+
event.preventDefault();
|
|
803
|
+
move(PAGE);
|
|
804
|
+
return;
|
|
805
|
+
case "PageUp":
|
|
806
|
+
event.preventDefault();
|
|
807
|
+
move(-10);
|
|
808
|
+
return;
|
|
809
|
+
case "Home":
|
|
810
|
+
if (options.searchable()) return;
|
|
811
|
+
event.preventDefault();
|
|
812
|
+
first();
|
|
813
|
+
return;
|
|
814
|
+
case "End":
|
|
815
|
+
if (options.searchable()) return;
|
|
816
|
+
event.preventDefault();
|
|
817
|
+
last();
|
|
818
|
+
return;
|
|
819
|
+
case "Enter":
|
|
820
|
+
event.preventDefault();
|
|
821
|
+
selectActive();
|
|
822
|
+
return;
|
|
823
|
+
case " ":
|
|
824
|
+
if (options.searchable()) return;
|
|
825
|
+
event.preventDefault();
|
|
826
|
+
selectActive();
|
|
827
|
+
return;
|
|
828
|
+
case "Escape":
|
|
829
|
+
if (options.escape?.() !== true) return;
|
|
830
|
+
event.preventDefault();
|
|
831
|
+
event.stopPropagation();
|
|
832
|
+
return;
|
|
833
|
+
case "Tab":
|
|
834
|
+
options.close();
|
|
835
|
+
return;
|
|
836
|
+
default:
|
|
837
|
+
if (options.searchable() || !isPrintable(event)) return;
|
|
838
|
+
event.preventDefault();
|
|
839
|
+
typeahead(event.key);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
function onKeydown(event) {
|
|
843
|
+
if (event.defaultPrevented) return;
|
|
844
|
+
if (options.isOpen()) {
|
|
845
|
+
onOpenKeydown(event);
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
848
|
+
if (options.canOpen?.() === false) return;
|
|
849
|
+
onClosedKeydown(event);
|
|
850
|
+
}
|
|
851
|
+
return {
|
|
852
|
+
activeValue,
|
|
853
|
+
activeId,
|
|
854
|
+
setActive,
|
|
855
|
+
activateFrom,
|
|
856
|
+
first,
|
|
857
|
+
last,
|
|
858
|
+
move,
|
|
859
|
+
selectActive,
|
|
860
|
+
onKeydown,
|
|
861
|
+
resetTypeahead
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
// src/composables/useFloating.ts
|
|
865
|
+
/** What each of the spec's two named placements means to `@floating-ui/dom`. */
|
|
866
|
+
var RESOLVED = {
|
|
867
|
+
auto: {
|
|
868
|
+
placement: "bottom-start",
|
|
869
|
+
flip: true
|
|
870
|
+
},
|
|
871
|
+
above: {
|
|
872
|
+
placement: "top-start",
|
|
873
|
+
flip: false
|
|
874
|
+
},
|
|
875
|
+
bottom: {
|
|
876
|
+
placement: "bottom",
|
|
877
|
+
flip: true
|
|
878
|
+
},
|
|
879
|
+
"bottom-start": {
|
|
880
|
+
placement: "bottom-start",
|
|
881
|
+
flip: true
|
|
882
|
+
},
|
|
883
|
+
"bottom-end": {
|
|
884
|
+
placement: "bottom-end",
|
|
885
|
+
flip: true
|
|
886
|
+
},
|
|
887
|
+
top: {
|
|
888
|
+
placement: "top",
|
|
889
|
+
flip: true
|
|
890
|
+
},
|
|
891
|
+
"top-start": {
|
|
892
|
+
placement: "top-start",
|
|
893
|
+
flip: true
|
|
894
|
+
},
|
|
895
|
+
"top-end": {
|
|
896
|
+
placement: "top-end",
|
|
897
|
+
flip: true
|
|
898
|
+
},
|
|
899
|
+
left: {
|
|
900
|
+
placement: "left",
|
|
901
|
+
flip: true
|
|
902
|
+
},
|
|
903
|
+
"left-start": {
|
|
904
|
+
placement: "left-start",
|
|
905
|
+
flip: true
|
|
906
|
+
},
|
|
907
|
+
"left-end": {
|
|
908
|
+
placement: "left-end",
|
|
909
|
+
flip: true
|
|
910
|
+
},
|
|
911
|
+
right: {
|
|
912
|
+
placement: "right",
|
|
913
|
+
flip: true
|
|
914
|
+
},
|
|
915
|
+
"right-start": {
|
|
916
|
+
placement: "right-start",
|
|
917
|
+
flip: true
|
|
918
|
+
},
|
|
919
|
+
"right-end": {
|
|
920
|
+
placement: "right-end",
|
|
921
|
+
flip: true
|
|
922
|
+
}
|
|
923
|
+
};
|
|
924
|
+
/**
|
|
925
|
+
* Positions a floating panel against the element that opened it — the one piece of every popup in
|
|
926
|
+
* this package that has to measure the page.
|
|
927
|
+
*
|
|
928
|
+
* It is a thin wrap of `@floating-ui/vue`: `autoUpdate` keeps the position current while both
|
|
929
|
+
* elements are mounted (scrolling, resizing, an ancestor moving), `offset` sets the gap, `flip`
|
|
930
|
+
* turns the panel above the trigger when there is no room below, `shift` keeps it inside the
|
|
931
|
+
* viewport, and `size` measures the trigger for `matchWidth` (a floor on the panel's width — the
|
|
932
|
+
* spec lets a select's panel grow past its trigger up to its own `max-width` — or a floor and a
|
|
933
|
+
* ceiling under `'exact'`). What the wrap adds is the design spec's vocabulary (`auto` / `above`)
|
|
934
|
+
* and a plain style object rather than a transform, so a consumer writes `<div :style="styles">`
|
|
935
|
+
* and nothing else.
|
|
936
|
+
*
|
|
937
|
+
* `top` and `left` are used instead of the default `transform`, because a panel positioned by
|
|
938
|
+
* transform is blurry on fractional pixels and, more to the point, cannot then use `transform` for
|
|
939
|
+
* the spec's own open animation (fade + 0.25rem slide + a vertical scale from the top edge).
|
|
940
|
+
*
|
|
941
|
+
* ```ts
|
|
942
|
+
* const trigger = ref<HTMLElement | null>(null);
|
|
943
|
+
* const panel = ref<HTMLElement | null>(null);
|
|
944
|
+
* const { styles, placement } = useFloating(trigger, panel, { matchWidth: true });
|
|
945
|
+
* ```
|
|
946
|
+
*
|
|
947
|
+
* The reference may be a Floating UI **virtual element** (`{ getBoundingClientRect() }`), for a
|
|
948
|
+
* panel anchored to a caret or a pointer position rather than to a node; call `update()` after it
|
|
949
|
+
* moves, since nothing observes a virtual element's geometry.
|
|
950
|
+
*/
|
|
951
|
+
function useFloating$1(reference, floating, options = {}) {
|
|
952
|
+
const resolved = computed(() => RESOLVED[toValue(options.placement) ?? "auto"]);
|
|
953
|
+
const exactWidth = options.matchWidth === "exact";
|
|
954
|
+
const matchWidth = options.matchWidth === true || exactWidth;
|
|
955
|
+
const referenceWidth = ref(0);
|
|
956
|
+
const middleware = computed(() => {
|
|
957
|
+
const list = [offset(toValue(options.offset) ?? 4)];
|
|
958
|
+
if (options.flip ?? resolved.value.flip) list.push(flip());
|
|
959
|
+
list.push(shift({ padding: toValue(options.padding) ?? 8 }));
|
|
960
|
+
if (matchWidth) list.push(size({ apply({ rects }) {
|
|
961
|
+
referenceWidth.value = rects.reference.width;
|
|
962
|
+
} }));
|
|
963
|
+
return list;
|
|
964
|
+
});
|
|
965
|
+
const position = useFloating(reference, floating, {
|
|
966
|
+
placement: computed(() => resolved.value.placement),
|
|
967
|
+
strategy: options.strategy ?? "absolute",
|
|
968
|
+
transform: false,
|
|
969
|
+
middleware,
|
|
970
|
+
whileElementsMounted: autoUpdate
|
|
971
|
+
});
|
|
972
|
+
return {
|
|
973
|
+
styles: computed(() => {
|
|
974
|
+
const base = {
|
|
975
|
+
position: position.strategy.value,
|
|
976
|
+
left: `${position.x.value}px`,
|
|
977
|
+
top: `${position.y.value}px`
|
|
978
|
+
};
|
|
979
|
+
if (matchWidth) base.minWidth = `${referenceWidth.value}px`;
|
|
980
|
+
if (exactWidth) base.maxWidth = `${referenceWidth.value}px`;
|
|
981
|
+
return base;
|
|
982
|
+
}),
|
|
983
|
+
placement: computed(() => position.placement.value),
|
|
984
|
+
update: position.update
|
|
985
|
+
};
|
|
986
|
+
}
|
|
987
|
+
// src/composables/teleportTarget.ts
|
|
988
|
+
/**
|
|
989
|
+
* Whether an element is a dialog the browser has put in its **top layer**.
|
|
990
|
+
*
|
|
991
|
+
* `:modal` is the only way to ask: a `<dialog>` has the `open` attribute whether it was shown with
|
|
992
|
+
* `show()` (an ordinary in-flow element, which clips and stacks like any other) or with
|
|
993
|
+
* `showModal()` (top layer, above every z-index, with a backdrop), and nothing else in the DOM
|
|
994
|
+
* tells the two apart. Engines that do not implement `:modal` answer `false` here — happy-dom
|
|
995
|
+
* parses the selector and never matches it, jsdom does not implement `<dialog>` modality at all —
|
|
996
|
+
* which is what the caller's fallback is for.
|
|
997
|
+
*
|
|
998
|
+
* Wrapped in a `try`: a selector an engine cannot parse is a `SyntaxError`, not a `false`.
|
|
999
|
+
*/
|
|
1000
|
+
function isTopLayer(element) {
|
|
1001
|
+
try {
|
|
1002
|
+
return element.matches(":modal");
|
|
1003
|
+
} catch {
|
|
1004
|
+
return false;
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1214
1007
|
/**
|
|
1215
|
-
*
|
|
1216
|
-
*
|
|
1217
|
-
*
|
|
1008
|
+
* The `<dialog>` a popup anchored to `anchor` has to be teleported *into* rather than escape, or
|
|
1009
|
+
* `null` when there is none.
|
|
1010
|
+
*
|
|
1011
|
+
* A **modal** dialog is the one place `document.body` is the wrong target: the dialog is in the top
|
|
1012
|
+
* layer, so a popup on the body would be painted behind it and no `z-index` could raise it. So the
|
|
1013
|
+
* nearest open ancestor dialog that is actually in the top layer wins — which is not always the
|
|
1014
|
+
* nearest one, since a non-modal `<dialog open>` may sit inside a modal one.
|
|
1015
|
+
*
|
|
1016
|
+
* When **no** ancestor dialog claims the top layer, the nearest open one is still the answer. That
|
|
1017
|
+
* case is ambiguous — either they really are all non-modal, or the engine does not implement
|
|
1018
|
+
* `:modal` and cannot say — and the two mistakes are not equally bad. Teleporting into a dialog
|
|
1019
|
+
* that did not need it still escapes everything between the control and that dialog, and the
|
|
1020
|
+
* dialog is a box the popup had no business overflowing anyway; teleporting to `body` out of a
|
|
1021
|
+
* dialog that *was* modal puts the popup behind it, invisibly, which is the very bug this whole
|
|
1022
|
+
* mechanism exists to fix. There is no engine-independent probe to break the tie —
|
|
1023
|
+
* `CSS.supports('selector(:modal)')` answers `true` for nonsense in happy-dom — so the safe
|
|
1024
|
+
* mistake is the one taken. A non-modal `<dialog open>` is in any case close to hypothetical here:
|
|
1025
|
+
* the design spec's non-negotiable 2 opens every modal surface with `showModal()`, and says the
|
|
1026
|
+
* non-modal popups are not dialogs at all.
|
|
1218
1027
|
*/
|
|
1219
|
-
function
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
return event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey;
|
|
1225
|
-
}
|
|
1226
|
-
function clamp(value, min, max) {
|
|
1227
|
-
return value < min ? min : value > max ? max : value;
|
|
1028
|
+
function topLayerDialog(anchor) {
|
|
1029
|
+
const nearest = anchor.closest("dialog[open]");
|
|
1030
|
+
if (nearest === null) return null;
|
|
1031
|
+
for (let dialog = nearest; dialog !== null; dialog = dialog.parentElement?.closest("dialog[open]") ?? null) if (isTopLayer(dialog)) return dialog;
|
|
1032
|
+
return nearest;
|
|
1228
1033
|
}
|
|
1229
1034
|
/**
|
|
1230
|
-
*
|
|
1231
|
-
*
|
|
1232
|
-
*
|
|
1233
|
-
* It is separate from `Select.vue` on purpose. `MultiSelect` (the next component) has the same two
|
|
1234
|
-
* keyboard tables with three differences — `Enter` toggles instead of choosing-and-closing,
|
|
1235
|
-
* `Space` toggles, and the popup stays open — all of which are the caller's `select` callback and
|
|
1236
|
-
* the caller's decision about closing. Everything else (arrow movement that skips disabled and
|
|
1237
|
-
* filtered-out rows and stops at the ends, `PageUp`/`PageDown` by ten, `Home`/`End` unless a
|
|
1238
|
-
* search field owns them, `Alt+ArrowUp`, `Escape` clearing a query before it closes, `Tab`
|
|
1239
|
-
* closing without a choice, and type-ahead with a 0.6s buffer) is identical, and identical code
|
|
1240
|
-
* that is written twice stops being identical.
|
|
1035
|
+
* Where a teleported popup is rendered: `usePopover`'s and `Tooltip`'s shared answer to "escape
|
|
1036
|
+
* clipping and stacking, but not the browser's own top layer."
|
|
1241
1037
|
*
|
|
1242
|
-
*
|
|
1243
|
-
*
|
|
1244
|
-
*
|
|
1245
|
-
*
|
|
1038
|
+
* A panel (or bubble) rendered inside its own control is at the mercy of everything above it: an
|
|
1039
|
+
* ancestor with `overflow: hidden` (a card, a table cell, a carousel track) clips it, and any later
|
|
1040
|
+
* sibling that starts a stacking context (a sticky header with a `z-index`, a section with
|
|
1041
|
+
* `isolate`) paints over it however high its own `z-index` is. On `body` neither can happen — except
|
|
1042
|
+
* for a native `<dialog>` opened with `showModal()`, which renders in the top layer above every
|
|
1043
|
+
* `z-index` on the page, so a popup teleported to `body` out from under one would be invisible
|
|
1044
|
+
* behind it. `topLayerDialog` is the one exception that rule needs.
|
|
1246
1045
|
*
|
|
1247
1046
|
* ```ts
|
|
1248
|
-
* const
|
|
1249
|
-
*
|
|
1250
|
-
*
|
|
1251
|
-
* searchable: () => searchable.value,
|
|
1252
|
-
* optionId: (value) => `${id.value}-option-${value}`,
|
|
1253
|
-
* open: (edge) => openPanel(edge),
|
|
1254
|
-
* close: () => closePanel(),
|
|
1255
|
-
* select: (option) => choose(option.value),
|
|
1256
|
-
* });
|
|
1047
|
+
* const isOpen = ref(false);
|
|
1048
|
+
* const trigger = ref<HTMLElement | null>(null);
|
|
1049
|
+
* const { teleportTo, teleportDisabled } = useTeleportTarget({ trigger, teleport: true, isOpen });
|
|
1257
1050
|
* ```
|
|
1258
1051
|
*/
|
|
1259
|
-
function
|
|
1260
|
-
const
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
const
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
}
|
|
1280
|
-
const index = rows.findIndex((option) => option.value === activeValue.value);
|
|
1281
|
-
if (index === -1) {
|
|
1282
|
-
setActive((step > 0 ? rows[0] : rows.at(-1))?.value);
|
|
1283
|
-
return;
|
|
1284
|
-
}
|
|
1285
|
-
setActive(rows[clamp(index + step, 0, rows.length - 1)]?.value);
|
|
1286
|
-
};
|
|
1287
|
-
const selectActive = () => {
|
|
1288
|
-
const option = options.options().find((row) => row.value === activeValue.value);
|
|
1289
|
-
if (option === void 0 || option.disabled === true) return;
|
|
1290
|
-
options.select(option);
|
|
1291
|
-
};
|
|
1292
|
-
let buffer = "";
|
|
1293
|
-
let timer;
|
|
1294
|
-
const resetTypeahead = () => {
|
|
1295
|
-
buffer = "";
|
|
1296
|
-
if (timer !== void 0) clearTimeout(timer);
|
|
1297
|
-
timer = void 0;
|
|
1052
|
+
function useTeleportTarget(options) {
|
|
1053
|
+
const { trigger, teleport, isOpen } = options;
|
|
1054
|
+
/**
|
|
1055
|
+
* Only `true` after `onMounted`, which never runs on the server. Everything that reads the
|
|
1056
|
+
* document below is behind it.
|
|
1057
|
+
*/
|
|
1058
|
+
const isMounted = ref(false);
|
|
1059
|
+
onMounted(() => {
|
|
1060
|
+
isMounted.value = true;
|
|
1061
|
+
});
|
|
1062
|
+
const teleportDisabled = computed(() => teleport === false || !isMounted.value);
|
|
1063
|
+
return {
|
|
1064
|
+
teleportTo: computed(() => {
|
|
1065
|
+
if (!isMounted.value) return "body";
|
|
1066
|
+
if (typeof teleport === "string") return teleport;
|
|
1067
|
+
isOpen.value;
|
|
1068
|
+
const anchor = trigger.value;
|
|
1069
|
+
return (anchor === null ? null : topLayerDialog(anchor)) ?? document.body;
|
|
1070
|
+
}),
|
|
1071
|
+
teleportDisabled
|
|
1298
1072
|
};
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1073
|
+
}
|
|
1074
|
+
// src/composables/useOverlay.ts
|
|
1075
|
+
/**
|
|
1076
|
+
* Anything the platform lets a user reach with `Tab`, plus the elements a component has opted in
|
|
1077
|
+
* with a `tabindex`. `tabindex="-1"` is deliberately excluded: it is programmatically focusable,
|
|
1078
|
+
* not part of the sequence a keyboard user walks, and `focusFirst()` exists to put focus where a
|
|
1079
|
+
* user would have put it themselves.
|
|
1080
|
+
*/
|
|
1081
|
+
var FOCUSABLE$1 = "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^=\"-\"])";
|
|
1082
|
+
/**
|
|
1083
|
+
* Marks an element that belongs to an overlay whose content element has this `id`.
|
|
1084
|
+
*
|
|
1085
|
+
* Exported for `usePopover`, which has to find those elements rather than only recognise one it is
|
|
1086
|
+
* handed: a teleported panel's `Tab` walk runs through them (see its `tabRedirect` option).
|
|
1087
|
+
*/
|
|
1088
|
+
var OVERLAY_OWNER_ATTRIBUTE = "data-eldra-overlay-owner";
|
|
1089
|
+
var read = (setting, fallback) => setting === void 0 ? fallback : typeof setting === "function" ? setting() : setting;
|
|
1090
|
+
/**
|
|
1091
|
+
* The closing and focus rules shared by every **non-modal** popup in this package — the Select and
|
|
1092
|
+
* Multi-select panels, the Search bar's results panel, menus.
|
|
1093
|
+
*
|
|
1094
|
+
* Non-modal is the whole point. The design spec's non-negotiables put every *modal* surface in a
|
|
1095
|
+
* native `<dialog>` opened with `showModal()`, and say in the same breath that these popups are not
|
|
1096
|
+
* dialogs: "Non-modal popups (select panels, search results panel, mega-menus, tooltips) are **not**
|
|
1097
|
+
* dialogs." So there is no focus trap here and no `Tab` cycling — `Tab` simply moves on, and focus
|
|
1098
|
+
* landing outside is what closes the popup (WCAG 2.1.2: no keyboard trap). Everything this
|
|
1099
|
+
* composable does is close at the right moment and leave focus somewhere sensible.
|
|
1100
|
+
*
|
|
1101
|
+
* What it listens for, and only while `open` is `true`:
|
|
1102
|
+
*
|
|
1103
|
+
* - **A pointer press outside** (`pointerdown`, captured, so a handler inside the page that stops
|
|
1104
|
+
* propagation cannot hide the press from us). Inside is the trigger, the content, and anything
|
|
1105
|
+
* under an element carrying `data-eldra-overlay-owner="<the content's id>"` — which is how a
|
|
1106
|
+
* panel rendered through a `<Teleport>` still counts as part of the overlay. Closing this way
|
|
1107
|
+
* never moves focus: the user is pressing something else, and pulling focus back to the trigger
|
|
1108
|
+
* would take it off whatever they just pressed.
|
|
1109
|
+
* - **Focus leaving** (`focusout`). If the new focus owner is outside the overlay, the popup
|
|
1110
|
+
* closes and focus stays where the user sent it. If focus went *nowhere* (`relatedTarget` is
|
|
1111
|
+
* `null` — the content is about to be removed from under it), `returnFocus` puts it back on the
|
|
1112
|
+
* trigger rather than letting it fall to `<body>`.
|
|
1113
|
+
* - **`Escape`** (`keydown`, bubbling, so a component that wants the first go at `Escape` — the
|
|
1114
|
+
* Select clears its search query before it closes — can handle it and stop propagation). It
|
|
1115
|
+
* closes, returns focus to the trigger, and both `preventDefault()`s and stops propagation: a
|
|
1116
|
+
* popup inside a native `<dialog>` must consume the key, or the dialog closes behind it.
|
|
1117
|
+
*
|
|
1118
|
+
* Listeners go on `document` when the overlay opens and come off when it closes or the scope is
|
|
1119
|
+
* disposed, so a closed overlay costs nothing and an unmounted one leaves nothing behind. Nothing
|
|
1120
|
+
* touches the DOM during SSR.
|
|
1121
|
+
*
|
|
1122
|
+
* ```ts
|
|
1123
|
+
* const open = ref(false);
|
|
1124
|
+
* const trigger = ref<HTMLElement | null>(null);
|
|
1125
|
+
* const content = ref<HTMLElement | null>(null);
|
|
1126
|
+
* const overlay = useOverlay({ open, trigger, content, setOpen: (next) => (open.value = next) });
|
|
1127
|
+
* ```
|
|
1128
|
+
*/
|
|
1129
|
+
function useOverlay(options) {
|
|
1130
|
+
const { open, trigger, content, setOpen } = options;
|
|
1131
|
+
const closeOnOutsideClick = () => read(options.closeOnOutsideClick, true);
|
|
1132
|
+
const closeOnFocusOutside = () => read(options.closeOnFocusOutside, closeOnOutsideClick());
|
|
1133
|
+
const closeOnEscape = () => read(options.closeOnEscape, true);
|
|
1134
|
+
const returnFocus = () => read(options.returnFocus, true);
|
|
1135
|
+
const focusables = (from) => {
|
|
1136
|
+
const root = from === void 0 ? content.value : from;
|
|
1137
|
+
if (!root) return [];
|
|
1138
|
+
return [root, ...root.querySelectorAll(FOCUSABLE$1)].filter((element) => element.matches(FOCUSABLE$1) && element.tabIndex >= 0 && !element.hasAttribute("disabled") && element.getAttribute("aria-hidden") !== "true" && element.closest("[hidden]") === null);
|
|
1139
|
+
};
|
|
1140
|
+
const focusFirst = () => {
|
|
1141
|
+
focusables()[0]?.focus();
|
|
1142
|
+
};
|
|
1143
|
+
const close = () => setOpen(false);
|
|
1144
|
+
/**
|
|
1145
|
+
* A teleported part of the overlay is in the DOM somewhere else entirely, so containment says
|
|
1146
|
+
* nothing about it. It is claimed one of two ways, both followed transitively:
|
|
1147
|
+
*
|
|
1148
|
+
* - **An owner marker**: an ancestor carrying `data-eldra-overlay-owner` names the content's id —
|
|
1149
|
+
* or the id of any element that is itself inside this overlay, so a picker teleported out of a
|
|
1150
|
+
* panel can point at the field inside the panel it belongs to.
|
|
1151
|
+
* - **An open control inside the overlay**: an element with `aria-expanded="true"` inside this
|
|
1152
|
+
* overlay names, in `aria-controls`, an element in the node's popup — the owner-marked panel
|
|
1153
|
+
* that element sits in, or the element itself. That is a nested popup (a `Select` or another
|
|
1154
|
+
* `Popover` opened from this panel) whose own panel is teleported too.
|
|
1155
|
+
*
|
|
1156
|
+
* Walked by hand rather than through selectors so an id with a character CSS would have to
|
|
1157
|
+
* escape cannot break the check.
|
|
1158
|
+
*/
|
|
1159
|
+
const isInside = (node, visited = /* @__PURE__ */ new Set()) => {
|
|
1160
|
+
if (!(node instanceof Node) || visited.has(node)) return false;
|
|
1161
|
+
visited.add(node);
|
|
1162
|
+
if (trigger.value?.contains(node) === true) return true;
|
|
1163
|
+
if (content.value?.contains(node) === true) return true;
|
|
1164
|
+
const id = content.value?.id;
|
|
1165
|
+
if (id === void 0 || id === "" || typeof document === "undefined") return false;
|
|
1166
|
+
for (let element = node instanceof Element ? node : node.parentElement; element !== null; element = element.parentElement) {
|
|
1167
|
+
const owner = element.getAttribute(OVERLAY_OWNER_ATTRIBUTE);
|
|
1168
|
+
if (owner === id) return true;
|
|
1169
|
+
if (owner === null || owner === "") continue;
|
|
1170
|
+
const named = document.getElementById(owner);
|
|
1171
|
+
if (named !== null && !named.contains(element) && isInside(named, visited)) return true;
|
|
1391
1172
|
}
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1173
|
+
for (const control of document.querySelectorAll("[aria-controls]")) {
|
|
1174
|
+
if (control.getAttribute("aria-expanded") !== "true" || control.contains(node)) continue;
|
|
1175
|
+
for (const controlled of (control.getAttribute("aria-controls") ?? "").split(/\s+/)) {
|
|
1176
|
+
const target = controlled === "" ? null : document.getElementById(controlled);
|
|
1177
|
+
if (target === null) continue;
|
|
1178
|
+
const popup = target.closest(`[data-eldra-overlay-owner]`) ?? target;
|
|
1179
|
+
if (!popup.contains(node) || popup.contains(control)) continue;
|
|
1180
|
+
if (isInside(control, visited)) return true;
|
|
1181
|
+
}
|
|
1398
1182
|
}
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1183
|
+
return false;
|
|
1184
|
+
};
|
|
1185
|
+
const onPointerDown = (event) => {
|
|
1186
|
+
if (!open.value || !closeOnOutsideClick() || isInside(event.target)) return;
|
|
1187
|
+
close();
|
|
1188
|
+
};
|
|
1189
|
+
const onFocusOut = (event) => {
|
|
1190
|
+
if (!open.value || !closeOnFocusOutside()) return;
|
|
1191
|
+
if (!isInside(event.target)) return;
|
|
1192
|
+
const next = event.relatedTarget;
|
|
1193
|
+
if (isInside(next)) return;
|
|
1194
|
+
close();
|
|
1195
|
+
if (returnFocus() && next === null) trigger.value?.focus();
|
|
1196
|
+
};
|
|
1197
|
+
const onKeyDown = (event) => {
|
|
1198
|
+
if (!open.value || event.key !== "Escape" || !closeOnEscape()) return;
|
|
1199
|
+
event.preventDefault();
|
|
1200
|
+
event.stopPropagation();
|
|
1201
|
+
close();
|
|
1202
|
+
if (returnFocus()) trigger.value?.focus();
|
|
1203
|
+
};
|
|
1204
|
+
let listening = false;
|
|
1205
|
+
const attach = () => {
|
|
1206
|
+
if (listening || typeof document === "undefined") return;
|
|
1207
|
+
listening = true;
|
|
1208
|
+
document.addEventListener("pointerdown", onPointerDown, true);
|
|
1209
|
+
document.addEventListener("focusout", onFocusOut);
|
|
1210
|
+
document.addEventListener("keydown", onKeyDown);
|
|
1211
|
+
};
|
|
1212
|
+
const detach = () => {
|
|
1213
|
+
if (!listening) return;
|
|
1214
|
+
listening = false;
|
|
1215
|
+
document.removeEventListener("pointerdown", onPointerDown, true);
|
|
1216
|
+
document.removeEventListener("focusout", onFocusOut);
|
|
1217
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
1218
|
+
};
|
|
1219
|
+
watch(open, (isOpen) => isOpen ? attach() : detach(), { immediate: true });
|
|
1220
|
+
onScopeDispose(detach);
|
|
1402
1221
|
return {
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
first,
|
|
1408
|
-
last,
|
|
1409
|
-
move,
|
|
1410
|
-
selectActive,
|
|
1411
|
-
onKeydown,
|
|
1412
|
-
resetTypeahead
|
|
1222
|
+
close,
|
|
1223
|
+
focusFirst,
|
|
1224
|
+
focusables,
|
|
1225
|
+
isInside: (node) => isInside(node)
|
|
1413
1226
|
};
|
|
1414
1227
|
}
|
|
1415
|
-
// src/components/select/
|
|
1228
|
+
// src/components/select/openRegistry.ts
|
|
1416
1229
|
/**
|
|
1417
|
-
*
|
|
1230
|
+
* The open popups, outermost first. Without nesting it never holds more than one entry; a popup
|
|
1231
|
+
* opened from inside another's panel is stacked on it instead of closing it.
|
|
1232
|
+
*/
|
|
1233
|
+
var stack = [];
|
|
1234
|
+
/**
|
|
1235
|
+
* Claim the slot and close whatever held it — except the popups the new one is nested in.
|
|
1418
1236
|
*
|
|
1419
|
-
*
|
|
1420
|
-
*
|
|
1421
|
-
* string's own offsets, or the bold-and-underlined run would land on the wrong characters for any
|
|
1422
|
-
* label holding an accent. Hence the per-character walk: each original code point contributes zero
|
|
1423
|
-
* (a combining mark) or more normalised characters, and `positions` maps back.
|
|
1237
|
+
* The slot is reassigned *before* the previous popups are closed, so the `unregisterOpen` that
|
|
1238
|
+
* closing triggers sees a slot that is no longer its own and leaves the new owner alone.
|
|
1424
1239
|
*/
|
|
1425
|
-
function
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
const
|
|
1429
|
-
const
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
for (let step = 0; step < piece.length; step += 1) positions.push(index);
|
|
1434
|
-
normalized += piece;
|
|
1240
|
+
function registerOpen(close, options = {}) {
|
|
1241
|
+
if (stack.at(-1)?.close === close) return;
|
|
1242
|
+
const { anchor } = options;
|
|
1243
|
+
const kept = [];
|
|
1244
|
+
const closed = [];
|
|
1245
|
+
for (const entry of stack) {
|
|
1246
|
+
if (entry.close === close) continue;
|
|
1247
|
+
(anchor !== void 0 && anchor !== null && entry.contains?.(anchor) === true ? kept : closed).push(entry);
|
|
1435
1248
|
}
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1249
|
+
stack = [...kept, {
|
|
1250
|
+
close,
|
|
1251
|
+
contains: options.contains
|
|
1252
|
+
}];
|
|
1253
|
+
for (const entry of closed) entry.close();
|
|
1254
|
+
}
|
|
1255
|
+
/** Release the slot, if it is still this popup's. */
|
|
1256
|
+
function unregisterOpen(close) {
|
|
1257
|
+
stack = stack.filter((entry) => entry.close !== close);
|
|
1442
1258
|
}
|
|
1259
|
+
// src/components/select/usePopover.ts
|
|
1443
1260
|
/**
|
|
1444
|
-
*
|
|
1445
|
-
*
|
|
1446
|
-
*
|
|
1261
|
+
* The open/closed life of a **non-modal popup** anchored to a control: `Select`'s panel,
|
|
1262
|
+
* `MultiSelect`'s, and the `SearchBar`'s results panel.
|
|
1263
|
+
*
|
|
1264
|
+
* Every one of them needs the same six things, and before this composable the first two controls
|
|
1265
|
+
* held a line-identical copy of all of them:
|
|
1266
|
+
*
|
|
1267
|
+
* - **"Only one open at a time"** (`openRegistry`): opening claims a module-level slot and closes
|
|
1268
|
+
* whatever held it. The handle is stable per instance, so a late close cannot blank out the
|
|
1269
|
+
* popup that took its place.
|
|
1270
|
+
* - **Closing** (`useOverlay`): an outside pointer press, focus leaving, `Escape`. Non-modal, so
|
|
1271
|
+
* nothing is trapped and `Tab` always moves on.
|
|
1272
|
+
* - **Getting out of the way of the page** (`teleport`): the panel is rendered through a
|
|
1273
|
+
* `<Teleport>` to `body` — or to the modal `<dialog>` the trigger is in, which is the one place
|
|
1274
|
+
* `body` would be *behind* — and positioned with floating-ui's `fixed` strategy, so no ancestor's
|
|
1275
|
+
* `overflow: hidden` clips it and no later stacking context paints over it. `tabRedirect` puts a
|
|
1276
|
+
* panel that has real tab stops back into the `Tab` walk it left with its place in the DOM.
|
|
1277
|
+
* - **Positioning** (`useFloating`), plus the `--eldra-popover-origin` the entrance keyframes read,
|
|
1278
|
+
* so a panel that flips after floating-ui measures changes a custom property rather than its
|
|
1279
|
+
* `animation-name` (which would replay the entrance).
|
|
1280
|
+
* - **The open sequence**: open, make a row active, and — only when the call actually changed the
|
|
1281
|
+
* state — run `afterOpen` a tick later, which is where focus moves into the panel.
|
|
1282
|
+
* - **The label-forwarded-click latch**: a `<label for>` naming the trigger forwards its click to
|
|
1283
|
+
* it, and the spec is explicit that clicking a field's label focuses the control **without**
|
|
1284
|
+
* opening it. A forwarded click differs from a real one in that no pointer was pressed on the
|
|
1285
|
+
* trigger and its `detail` is 0. The latch is armed on `pointerdown` and released on the
|
|
1286
|
+
* `pointerup` or `pointercancel` that follows, wherever it lands: a press that ends off the
|
|
1287
|
+
* trigger (a drag, a cancelled touch) would otherwise leave the latch standing and arm the
|
|
1288
|
+
* *next* click. A programmatic `element.click()` has the same shape, so it is told apart by what
|
|
1289
|
+
* it is not (see `isProgrammaticClick`): not forwarded from a label clicked in the same task,
|
|
1290
|
+
* not trusted, and a `PointerEvent`, which is what `click()` dispatches.
|
|
1291
|
+
*
|
|
1292
|
+
* What stays with each control is what actually differs: which rows there are, what choosing one
|
|
1293
|
+
* does, and which element the popup is anchored to.
|
|
1447
1294
|
*/
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1295
|
+
/**
|
|
1296
|
+
* The control a `<label>` click is about to forward to, until the task that clicked it ends. A
|
|
1297
|
+
* label's activation behaviour fires its forwarded click synchronously after its own click's
|
|
1298
|
+
* dispatch, so a capture listener on `document` sees the label's click first. One listener for the
|
|
1299
|
+
* whole page, attached on first use in a browser.
|
|
1300
|
+
*/
|
|
1301
|
+
var forwardingTo = null;
|
|
1302
|
+
var labelWatcherAttached = false;
|
|
1303
|
+
function watchLabelClicks() {
|
|
1304
|
+
if (labelWatcherAttached || typeof document === "undefined") return;
|
|
1305
|
+
labelWatcherAttached = true;
|
|
1306
|
+
document.addEventListener("click", (event) => {
|
|
1307
|
+
const target = event.target;
|
|
1308
|
+
if (!(target instanceof Element)) return;
|
|
1309
|
+
const control = target.closest("label")?.control ?? null;
|
|
1310
|
+
if (!(control instanceof HTMLElement) || control.contains(target)) return;
|
|
1311
|
+
forwardingTo = control;
|
|
1312
|
+
setTimeout(() => {
|
|
1313
|
+
if (forwardingTo === control) forwardingTo = null;
|
|
1314
|
+
}, 0);
|
|
1315
|
+
}, true);
|
|
1467
1316
|
}
|
|
1468
1317
|
/**
|
|
1469
|
-
*
|
|
1470
|
-
*
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
* The list a select panel shows: filtering, grouping, match highlighting, the create row and the
|
|
1475
|
-
* render batch.
|
|
1476
|
-
*
|
|
1477
|
-
* Shared by `Select` and `MultiSelect`, which differ in what choosing a row *does* and in nothing
|
|
1478
|
-
* about which rows there are. No DOM; its one piece of state is how many rows are rendered.
|
|
1318
|
+
* Whether a click with no pointer press behind it came from code (`trigger.click()`) rather than a
|
|
1319
|
+
* `<label>` forwarding its own: not forwarded from a label clicked in this task, untrusted (a
|
|
1320
|
+
* user's label click forwards a trusted one), and a `PointerEvent`, which is what `click()`
|
|
1321
|
+
* dispatches. A bare `dispatchEvent(new MouseEvent('click'))` keeps counting as forwarded, as it
|
|
1322
|
+
* always has; so does every click in an engine whose `click()` still sends a `MouseEvent`.
|
|
1479
1323
|
*/
|
|
1480
|
-
function
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
const
|
|
1489
|
-
|
|
1490
|
-
const
|
|
1491
|
-
|
|
1492
|
-
const needle = normalizeText(trimmed);
|
|
1493
|
-
return options.options().filter((option) => matchRange(option.label, trimmed) !== null || option.keywords?.some((keyword) => normalizeText(keyword).includes(needle)) === true);
|
|
1494
|
-
});
|
|
1495
|
-
/** Every visible option in DOM order, before the render batch cuts it. */
|
|
1496
|
-
const orderedOptions = computed(() => groupOptions(visibleOptions.value, "panel", options.controlId()).flatMap((section) => section.options));
|
|
1497
|
-
const batchSize = () => {
|
|
1498
|
-
const size = options.renderBatch?.();
|
|
1499
|
-
return size === void 0 || !(size >= 1) ? Number.POSITIVE_INFINITY : Math.floor(size);
|
|
1500
|
-
};
|
|
1501
|
-
const rendered = ref(batchSize());
|
|
1502
|
-
const resetBatch = () => {
|
|
1503
|
-
rendered.value = batchSize();
|
|
1324
|
+
function isProgrammaticClick(event, trigger) {
|
|
1325
|
+
if (trigger !== null && forwardingTo !== null && trigger.contains(forwardingTo)) return false;
|
|
1326
|
+
return !event.isTrusted && typeof PointerEvent !== "undefined" && event instanceof PointerEvent;
|
|
1327
|
+
}
|
|
1328
|
+
function usePopover(options) {
|
|
1329
|
+
const { trigger, content } = options;
|
|
1330
|
+
watchLabelClicks();
|
|
1331
|
+
const canOpen = () => options.canOpen?.() !== false;
|
|
1332
|
+
const isOpen = ref(false);
|
|
1333
|
+
const isExclusive = () => {
|
|
1334
|
+
const setting = options.exclusive ?? true;
|
|
1335
|
+
return typeof setting === "function" ? setting() : setting;
|
|
1504
1336
|
};
|
|
1505
|
-
|
|
1506
|
-
|
|
1337
|
+
/** The `anchor`, when it is a real element rather than a virtual one. */
|
|
1338
|
+
const anchorElement = () => {
|
|
1339
|
+
const anchor = options.anchor?.value ?? null;
|
|
1340
|
+
return typeof HTMLElement !== "undefined" && anchor instanceof HTMLElement ? anchor : null;
|
|
1507
1341
|
};
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
if (
|
|
1512
|
-
|
|
1513
|
-
|
|
1342
|
+
/** The registry's handle on this popup. Stable, so the registry can tell ours from another's. */
|
|
1343
|
+
const closeFromRegistry = () => setOpen(false);
|
|
1344
|
+
function setOpen(next) {
|
|
1345
|
+
if (next === isOpen.value) return;
|
|
1346
|
+
if (next) {
|
|
1347
|
+
if (!canOpen()) return;
|
|
1348
|
+
isOpen.value = true;
|
|
1349
|
+
if (isExclusive()) registerOpen(closeFromRegistry, {
|
|
1350
|
+
anchor: trigger.value ?? anchorElement(),
|
|
1351
|
+
contains: (node) => overlay.isInside(node)
|
|
1352
|
+
});
|
|
1353
|
+
options.onOpen?.();
|
|
1354
|
+
return;
|
|
1355
|
+
}
|
|
1356
|
+
isOpen.value = false;
|
|
1357
|
+
unregisterOpen(closeFromRegistry);
|
|
1358
|
+
options.onClose?.();
|
|
1359
|
+
}
|
|
1360
|
+
const overlay = useOverlay({
|
|
1361
|
+
open: isOpen,
|
|
1362
|
+
trigger,
|
|
1363
|
+
content,
|
|
1364
|
+
setOpen: (next) => setOpen(next),
|
|
1365
|
+
closeOnOutsideClick: options.closeOnOutsideClick,
|
|
1366
|
+
closeOnFocusOutside: options.closeOnFocusOutside,
|
|
1367
|
+
closeOnEscape: options.closeOnEscape,
|
|
1368
|
+
returnFocus: options.returnFocus
|
|
1369
|
+
});
|
|
1370
|
+
const teleport = options.teleport ?? true;
|
|
1371
|
+
const { teleportTo, teleportDisabled } = useTeleportTarget({
|
|
1372
|
+
trigger: computed(() => trigger.value ?? anchorElement()),
|
|
1373
|
+
teleport,
|
|
1374
|
+
isOpen
|
|
1375
|
+
});
|
|
1376
|
+
const { styles: floatingStyles, placement, update } = useFloating$1(computed(() => options.anchor?.value ?? trigger.value), content, {
|
|
1377
|
+
placement: options.placement ?? "auto",
|
|
1378
|
+
offset: options.offset,
|
|
1379
|
+
padding: options.padding,
|
|
1380
|
+
matchWidth: options.matchWidth,
|
|
1381
|
+
strategy: teleport === false ? "absolute" : "fixed"
|
|
1382
|
+
});
|
|
1383
|
+
const wantsTabRedirect = () => {
|
|
1384
|
+
const setting = options.tabRedirect ?? false;
|
|
1385
|
+
return typeof setting === "function" ? setting() : setting;
|
|
1514
1386
|
};
|
|
1515
|
-
watch(trimmedQuery, resetBatch);
|
|
1516
|
-
watch(() => options.renderBatch?.(), resetBatch);
|
|
1517
|
-
const renderedOptions = computed(() => Number.isFinite(rendered.value) ? orderedOptions.value.slice(0, rendered.value) : orderedOptions.value);
|
|
1518
|
-
const sections = computed(() => groupOptions(renderedOptions.value, "panel", options.controlId()));
|
|
1519
|
-
const nativeSections = computed(() => groupOptions(options.options(), "native", options.controlId()));
|
|
1520
1387
|
/**
|
|
1521
|
-
*
|
|
1522
|
-
*
|
|
1523
|
-
*
|
|
1388
|
+
* Every tab stop of this overlay that is **not** in the panel, in document order — the trigger,
|
|
1389
|
+
* plus anything claiming the panel's id with `data-eldra-overlay-owner` (a multi-select's clear
|
|
1390
|
+
* button). These keep their natural place in the walk: the redirect happens at the **last** of
|
|
1391
|
+
* them, so `Tab` still passes each one on the way to the panel.
|
|
1392
|
+
*
|
|
1393
|
+
* The owner elements are found with a plain attribute-presence selector and filtered by value in
|
|
1394
|
+
* JavaScript, for the reason `useOverlay` walks the attribute by hand: an id is merchant-settable
|
|
1395
|
+
* through the `id` prop, and one holding a character CSS would need escaped must not break this.
|
|
1524
1396
|
*/
|
|
1525
|
-
|
|
1526
|
-
const
|
|
1527
|
-
if (
|
|
1528
|
-
const
|
|
1529
|
-
if (
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
}
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
flip: false
|
|
1570
|
-
},
|
|
1571
|
-
bottom: {
|
|
1572
|
-
placement: "bottom",
|
|
1573
|
-
flip: true
|
|
1574
|
-
},
|
|
1575
|
-
"bottom-start": {
|
|
1576
|
-
placement: "bottom-start",
|
|
1577
|
-
flip: true
|
|
1578
|
-
},
|
|
1579
|
-
"bottom-end": {
|
|
1580
|
-
placement: "bottom-end",
|
|
1581
|
-
flip: true
|
|
1582
|
-
},
|
|
1583
|
-
top: {
|
|
1584
|
-
placement: "top",
|
|
1585
|
-
flip: true
|
|
1586
|
-
},
|
|
1587
|
-
"top-start": {
|
|
1588
|
-
placement: "top-start",
|
|
1589
|
-
flip: true
|
|
1590
|
-
},
|
|
1591
|
-
"top-end": {
|
|
1592
|
-
placement: "top-end",
|
|
1593
|
-
flip: true
|
|
1594
|
-
},
|
|
1595
|
-
left: {
|
|
1596
|
-
placement: "left",
|
|
1597
|
-
flip: true
|
|
1598
|
-
},
|
|
1599
|
-
"left-start": {
|
|
1600
|
-
placement: "left-start",
|
|
1601
|
-
flip: true
|
|
1602
|
-
},
|
|
1603
|
-
"left-end": {
|
|
1604
|
-
placement: "left-end",
|
|
1605
|
-
flip: true
|
|
1606
|
-
},
|
|
1607
|
-
right: {
|
|
1608
|
-
placement: "right",
|
|
1609
|
-
flip: true
|
|
1610
|
-
},
|
|
1611
|
-
"right-start": {
|
|
1612
|
-
placement: "right-start",
|
|
1613
|
-
flip: true
|
|
1614
|
-
},
|
|
1615
|
-
"right-end": {
|
|
1616
|
-
placement: "right-end",
|
|
1617
|
-
flip: true
|
|
1397
|
+
function stopsBeforePanel(panel) {
|
|
1398
|
+
const roots = [];
|
|
1399
|
+
if (trigger.value !== null) roots.push(trigger.value);
|
|
1400
|
+
const id = panel.id;
|
|
1401
|
+
if (id !== "") for (const owner of document.querySelectorAll(`[${OVERLAY_OWNER_ATTRIBUTE}]`)) {
|
|
1402
|
+
if (owner.getAttribute("data-eldra-overlay-owner") !== id) continue;
|
|
1403
|
+
if (panel.contains(owner) || roots.includes(owner)) continue;
|
|
1404
|
+
roots.push(owner);
|
|
1405
|
+
}
|
|
1406
|
+
return roots.flatMap((root) => overlay.focusables(root)).sort((a, b) => (a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING) === 0 ? 1 : -1);
|
|
1407
|
+
}
|
|
1408
|
+
/**
|
|
1409
|
+
* The two boundary keystrokes of the walk described on the `tabRedirect` option: into the panel
|
|
1410
|
+
* from the last tab stop the control still holds, and back out of the panel's first row to that
|
|
1411
|
+
* same stop. Everything else about `Tab` is left to the browser, which is what keeps this a
|
|
1412
|
+
* redirect rather than a trap — including the steps *within* the control, so a multi-select's
|
|
1413
|
+
* clear button is passed on the way in and returned to on the way back.
|
|
1414
|
+
*
|
|
1415
|
+
* It listens in the **capture** phase, before the control's own `keydown` reaches its handler:
|
|
1416
|
+
* `useListbox`'s `Tab` case asks the caller to close (the `SearchBar` does), and a popup that has
|
|
1417
|
+
* already closed has nothing left to walk into. Propagation is stopped only on the two keystrokes
|
|
1418
|
+
* actually redirected, so every other `Tab` arrives at the control untouched.
|
|
1419
|
+
*/
|
|
1420
|
+
function onTabKeyDown(event) {
|
|
1421
|
+
if (event.key !== "Tab" || event.altKey || event.ctrlKey || event.metaKey) return;
|
|
1422
|
+
if (!isOpen.value || teleportDisabled.value || !wantsTabRedirect()) return;
|
|
1423
|
+
const panel = content.value;
|
|
1424
|
+
const active = document.activeElement;
|
|
1425
|
+
if (panel === null || active === null) return;
|
|
1426
|
+
const first = overlay.focusables()[0];
|
|
1427
|
+
if (first === void 0) return;
|
|
1428
|
+
const last = stopsBeforePanel(panel).at(-1);
|
|
1429
|
+
if (event.shiftKey) {
|
|
1430
|
+
if (active !== first) return;
|
|
1431
|
+
event.preventDefault();
|
|
1432
|
+
event.stopPropagation();
|
|
1433
|
+
(last ?? trigger.value)?.focus();
|
|
1434
|
+
return;
|
|
1435
|
+
}
|
|
1436
|
+
if (panel.contains(active) || !overlay.isInside(active)) return;
|
|
1437
|
+
if (last !== void 0 && active !== last) return;
|
|
1438
|
+
event.preventDefault();
|
|
1439
|
+
event.stopPropagation();
|
|
1440
|
+
first.focus();
|
|
1618
1441
|
}
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1442
|
+
const attachTabRedirect = () => {
|
|
1443
|
+
if (typeof document === "undefined") return;
|
|
1444
|
+
document.addEventListener("keydown", onTabKeyDown, true);
|
|
1445
|
+
};
|
|
1446
|
+
const detachTabRedirect = () => {
|
|
1447
|
+
if (typeof document === "undefined") return;
|
|
1448
|
+
document.removeEventListener("keydown", onTabKeyDown, true);
|
|
1449
|
+
};
|
|
1450
|
+
watch(isOpen, (open) => open ? attachTabRedirect() : detachTabRedirect(), { immediate: true });
|
|
1451
|
+
function open(activate) {
|
|
1452
|
+
if (!canOpen()) return;
|
|
1453
|
+
const wasOpen = isOpen.value;
|
|
1454
|
+
setOpen(true);
|
|
1455
|
+
if (!isOpen.value) return;
|
|
1456
|
+
activate?.(wasOpen);
|
|
1457
|
+
if (!wasOpen) options.afterOpen?.();
|
|
1458
|
+
}
|
|
1459
|
+
function close(returnFocus = true) {
|
|
1460
|
+
if (!isOpen.value) return;
|
|
1461
|
+
setOpen(false);
|
|
1462
|
+
if (returnFocus) trigger.value?.focus();
|
|
1463
|
+
}
|
|
1464
|
+
let pressedTrigger = false;
|
|
1465
|
+
function releaseTrigger(event) {
|
|
1466
|
+
detachTriggerRelease();
|
|
1467
|
+
const target = event.target;
|
|
1468
|
+
if (target instanceof Node && trigger.value?.contains(target) === true) return;
|
|
1469
|
+
pressedTrigger = false;
|
|
1470
|
+
}
|
|
1471
|
+
function detachTriggerRelease() {
|
|
1472
|
+
if (typeof document === "undefined") return;
|
|
1473
|
+
document.removeEventListener("pointerup", releaseTrigger, true);
|
|
1474
|
+
document.removeEventListener("pointercancel", releaseTrigger, true);
|
|
1475
|
+
}
|
|
1476
|
+
function onTriggerPointerDown() {
|
|
1477
|
+
pressedTrigger = true;
|
|
1478
|
+
if (typeof document === "undefined") return;
|
|
1479
|
+
document.addEventListener("pointerup", releaseTrigger, true);
|
|
1480
|
+
document.addEventListener("pointercancel", releaseTrigger, true);
|
|
1481
|
+
}
|
|
1482
|
+
function onTriggerClick(event) {
|
|
1483
|
+
const fromPointer = pressedTrigger || event.detail > 0 || isProgrammaticClick(event, trigger.value);
|
|
1484
|
+
pressedTrigger = false;
|
|
1485
|
+
if (!canOpen()) return;
|
|
1486
|
+
if (!fromPointer) {
|
|
1487
|
+
trigger.value?.focus();
|
|
1488
|
+
return;
|
|
1489
|
+
}
|
|
1490
|
+
if (isOpen.value) close();
|
|
1491
|
+
else options.openFromPointer?.();
|
|
1492
|
+
}
|
|
1493
|
+
onBeforeUnmount(() => {
|
|
1494
|
+
unregisterOpen(closeFromRegistry);
|
|
1495
|
+
detachTriggerRelease();
|
|
1496
|
+
detachTabRedirect();
|
|
1660
1497
|
});
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1498
|
+
/**
|
|
1499
|
+
* Which corner the panel grows from: the one it is anchored by, so the entrance reads as the
|
|
1500
|
+
* control opening out rather than as a box arriving from somewhere. A panel below the control
|
|
1501
|
+
* grows from `top left`, a flipped one from `bottom left`. A custom property rather than a second
|
|
1502
|
+
* animation class: see the composable's own comment above, and the keyframes in `tailwind.css`.
|
|
1503
|
+
*
|
|
1504
|
+
* Logical directions are deliberately not used. `transform-origin` takes physical keywords only
|
|
1505
|
+
* (`left`/`right`, never `inline-start`), and every panel in this package is `start`-aligned and
|
|
1506
|
+
* at least as wide as its control, so the horizontal half barely moves the result either way.
|
|
1507
|
+
*/
|
|
1508
|
+
const origin = computed(() => {
|
|
1509
|
+
if (placement.value.startsWith("top")) return "bottom left";
|
|
1510
|
+
if (placement.value.startsWith("left")) return "top right";
|
|
1511
|
+
return "top left";
|
|
1667
1512
|
});
|
|
1668
1513
|
return {
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1514
|
+
isOpen,
|
|
1515
|
+
setOpen,
|
|
1516
|
+
open,
|
|
1517
|
+
close,
|
|
1518
|
+
panelStyle: computed(() => ({
|
|
1519
|
+
...floatingStyles.value,
|
|
1520
|
+
"--eldra-popover-origin": origin.value
|
|
1521
|
+
})),
|
|
1522
|
+
placement,
|
|
1523
|
+
teleportTo,
|
|
1524
|
+
teleportDisabled,
|
|
1525
|
+
onTriggerPointerDown,
|
|
1526
|
+
onTriggerClick,
|
|
1527
|
+
focusFirst: overlay.focusFirst,
|
|
1528
|
+
isInside: overlay.isInside,
|
|
1529
|
+
update
|
|
1681
1530
|
};
|
|
1682
1531
|
}
|
|
1683
|
-
// src/
|
|
1532
|
+
// src/components/spinner/Spinner.vue?vue&type=script&setup=true&lang.ts
|
|
1533
|
+
var _hoisted_1$1 = [
|
|
1534
|
+
"data-eldra-scope",
|
|
1535
|
+
"role",
|
|
1536
|
+
"aria-label",
|
|
1537
|
+
"aria-hidden"
|
|
1538
|
+
];
|
|
1539
|
+
// src/components/spinner/Spinner.vue
|
|
1540
|
+
var Spinner_default = /* @__PURE__ */ defineComponent({
|
|
1541
|
+
inheritAttrs: false,
|
|
1542
|
+
__name: "Spinner",
|
|
1543
|
+
props: { label: { default: void 0 } },
|
|
1544
|
+
setup(__props) {
|
|
1545
|
+
const props = __props;
|
|
1546
|
+
const eldra = useEldraScope();
|
|
1547
|
+
const attrs = useAttrs();
|
|
1548
|
+
const forwardedAttrs = computed(() => {
|
|
1549
|
+
const { class: _class, ...rest } = attrs;
|
|
1550
|
+
return rest;
|
|
1551
|
+
});
|
|
1552
|
+
const rootClass = computed(() => mergeClass("eldra:size-4.5 eldra:animate-eldra-spin eldra:motion-reduce:animate-eldra-pulse", attrs.class));
|
|
1553
|
+
/** `""` names nothing, so it is decorative too. */
|
|
1554
|
+
const named = computed(() => props.label !== void 0 && props.label !== "");
|
|
1555
|
+
return (_ctx, _cache) => {
|
|
1556
|
+
return openBlock(), createElementBlock("svg", mergeProps({
|
|
1557
|
+
"data-eldra-ui": "",
|
|
1558
|
+
"data-eldra-scope": unref(eldra).scope,
|
|
1559
|
+
class: rootClass.value,
|
|
1560
|
+
viewBox: "0 0 18 18",
|
|
1561
|
+
fill: "none",
|
|
1562
|
+
role: named.value ? "img" : void 0,
|
|
1563
|
+
"aria-label": named.value ? __props.label : void 0,
|
|
1564
|
+
"aria-hidden": named.value ? void 0 : "true",
|
|
1565
|
+
focusable: "false"
|
|
1566
|
+
}, forwardedAttrs.value), [..._cache[0] || (_cache[0] = [createElementVNode("circle", {
|
|
1567
|
+
cx: "9",
|
|
1568
|
+
cy: "9",
|
|
1569
|
+
r: "8",
|
|
1570
|
+
stroke: "currentColor",
|
|
1571
|
+
"stroke-width": "2",
|
|
1572
|
+
"stroke-opacity": "0.3"
|
|
1573
|
+
}, null, -1), createElementVNode("path", {
|
|
1574
|
+
d: "M17 9a8 8 0 0 0-8-8",
|
|
1575
|
+
stroke: "currentColor",
|
|
1576
|
+
"stroke-width": "2",
|
|
1577
|
+
"stroke-linecap": "round"
|
|
1578
|
+
}, null, -1)])], 16, _hoisted_1$1);
|
|
1579
|
+
};
|
|
1580
|
+
}
|
|
1581
|
+
});
|
|
1582
|
+
// src/composables/useLocale.ts
|
|
1684
1583
|
/**
|
|
1685
|
-
*
|
|
1686
|
-
*
|
|
1687
|
-
*
|
|
1688
|
-
*
|
|
1689
|
-
* `showModal()` (top layer, above every z-index, with a backdrop), and nothing else in the DOM
|
|
1690
|
-
* tells the two apart. Engines that do not implement `:modal` answer `false` here — happy-dom
|
|
1691
|
-
* parses the selector and never matches it, jsdom does not implement `<dialog>` modality at all —
|
|
1692
|
-
* which is what the caller's fallback is for.
|
|
1584
|
+
* The number locale the components format with, as a provide/inject pair — the same shape as
|
|
1585
|
+
* `useMessages`, and deliberately separate from it: the *strings* a component renders and the
|
|
1586
|
+
* *locale its numbers are formatted in* are two different decisions, and a store that accepts the
|
|
1587
|
+
* English defaults may still be an Icelandic shop.
|
|
1693
1588
|
*
|
|
1694
|
-
*
|
|
1589
|
+
* It is an ambient default, never an answer: every component that reads it also takes a `locale`
|
|
1590
|
+
* prop, and the prop wins. With nothing provided the components format in `en-US`.
|
|
1695
1591
|
*/
|
|
1696
|
-
|
|
1697
|
-
try {
|
|
1698
|
-
return element.matches(":modal");
|
|
1699
|
-
} catch {
|
|
1700
|
-
return false;
|
|
1701
|
-
}
|
|
1702
|
-
}
|
|
1592
|
+
var DEFAULT_UI_LOCALE = "en-US";
|
|
1703
1593
|
/**
|
|
1704
|
-
* The
|
|
1705
|
-
* `
|
|
1594
|
+
* The injection key the locale provider writes to. Exported so an app can set the locale from
|
|
1595
|
+
* outside a `setup()` scope — and so it can provide a **getter**, which is what makes a locale
|
|
1596
|
+
* switch reactive without an effect that outlives a server request:
|
|
1706
1597
|
*
|
|
1707
|
-
*
|
|
1708
|
-
*
|
|
1709
|
-
*
|
|
1710
|
-
*
|
|
1598
|
+
* ```ts
|
|
1599
|
+
* import { LOCALE_KEY } from '@eldrajs/ui';
|
|
1600
|
+
* app.provide(LOCALE_KEY, () => store.locale);
|
|
1601
|
+
* ```
|
|
1602
|
+
*/
|
|
1603
|
+
var LOCALE_KEY = Symbol("eldra-ui-locale");
|
|
1604
|
+
/**
|
|
1605
|
+
* Set the number locale for this component and everything below it.
|
|
1711
1606
|
*
|
|
1712
|
-
*
|
|
1713
|
-
*
|
|
1714
|
-
* `:modal` and cannot say — and the two mistakes are not equally bad. Teleporting into a dialog
|
|
1715
|
-
* that did not need it still escapes everything between the control and that dialog, and the
|
|
1716
|
-
* dialog is a box the popup had no business overflowing anyway; teleporting to `body` out of a
|
|
1717
|
-
* dialog that *was* modal puts the popup behind it, invisibly, which is the very bug this whole
|
|
1718
|
-
* mechanism exists to fix. There is no engine-independent probe to break the tie —
|
|
1719
|
-
* `CSS.supports('selector(:modal)')` answers `true` for nonsense in happy-dom — so the safe
|
|
1720
|
-
* mistake is the one taken. A non-modal `<dialog open>` is in any case close to hypothetical here:
|
|
1721
|
-
* the design spec's non-negotiable 2 opens every modal surface with `showModal()`, and says the
|
|
1722
|
-
* non-modal popups are not dialogs at all.
|
|
1607
|
+
* Wraps Vue's `provide`, so it must be called during `setup()`. Use
|
|
1608
|
+
* `app.provide(LOCALE_KEY, locale)` for the app-wide case.
|
|
1723
1609
|
*/
|
|
1724
|
-
function
|
|
1725
|
-
|
|
1726
|
-
if (nearest === null) return null;
|
|
1727
|
-
for (let dialog = nearest; dialog !== null; dialog = dialog.parentElement?.closest("dialog[open]") ?? null) if (isTopLayer(dialog)) return dialog;
|
|
1728
|
-
return nearest;
|
|
1610
|
+
function provideEldraUiLocale(locale) {
|
|
1611
|
+
provide(LOCALE_KEY, locale);
|
|
1729
1612
|
}
|
|
1730
1613
|
/**
|
|
1731
|
-
*
|
|
1732
|
-
*
|
|
1614
|
+
* The locale a component should format numbers in: whatever an ancestor provided, else `en-US`.
|
|
1615
|
+
* A ref or a getter is unwrapped on every read, so the value follows a locale switch.
|
|
1616
|
+
*/
|
|
1617
|
+
function useEldraUiLocale() {
|
|
1618
|
+
const provided = inject(LOCALE_KEY, void 0);
|
|
1619
|
+
return computed(() => toValue(provided) ?? "en-US");
|
|
1620
|
+
}
|
|
1621
|
+
/**
|
|
1622
|
+
* The injection key the store currency is provided under (spec "Price" → Properties, `currency`
|
|
1623
|
+
* row: "store currency") — the same provide/inject shape as `LOCALE_KEY` and deliberately separate
|
|
1624
|
+
* from it: a store's number locale and its currency are two different decisions (an
|
|
1625
|
+
* `en-US`-formatted store may still sell in `ISK`). It is an ambient default, never an answer:
|
|
1626
|
+
* every component that reads it also takes a `currency` prop, and the prop wins. **With nothing
|
|
1627
|
+
* provided there is no currency at all** — see `useEldraUiCurrency` for what the components then
|
|
1628
|
+
* render, and why this pair has no default code.
|
|
1733
1629
|
*
|
|
1734
|
-
*
|
|
1735
|
-
*
|
|
1736
|
-
*
|
|
1737
|
-
* `isolate`) paints over it however high its own `z-index` is. On `body` neither can happen — except
|
|
1738
|
-
* for a native `<dialog>` opened with `showModal()`, which renders in the top layer above every
|
|
1739
|
-
* `z-index` on the page, so a popup teleported to `body` out from under one would be invisible
|
|
1740
|
-
* behind it. `topLayerDialog` is the one exception that rule needs.
|
|
1630
|
+
* Exported so an app can set the currency from
|
|
1631
|
+
* outside a `setup()` scope — and so it can provide a **getter**, which is what makes a currency
|
|
1632
|
+
* switch reactive without an effect that outlives a server request:
|
|
1741
1633
|
*
|
|
1742
1634
|
* ```ts
|
|
1743
|
-
*
|
|
1744
|
-
*
|
|
1745
|
-
* const { teleportTo, teleportDisabled } = useTeleportTarget({ trigger, teleport: true, isOpen });
|
|
1635
|
+
* import { CURRENCY_KEY } from '@eldrajs/ui';
|
|
1636
|
+
* app.provide(CURRENCY_KEY, () => store.currency);
|
|
1746
1637
|
* ```
|
|
1638
|
+
*
|
|
1639
|
+
* Providing `undefined` is meaningful and different from not providing at all: it says the store
|
|
1640
|
+
* has **no** currency, which is the answer a platform that has not been told one must be able to
|
|
1641
|
+
* give. Vue's `inject` consults `key in provides`, so the two cases stay distinguishable (see
|
|
1642
|
+
* `useEldraUiCurrency`).
|
|
1747
1643
|
*/
|
|
1748
|
-
|
|
1749
|
-
const { trigger, teleport, isOpen } = options;
|
|
1750
|
-
/**
|
|
1751
|
-
* Only `true` after `onMounted`, which never runs on the server. Everything that reads the
|
|
1752
|
-
* document below is behind it.
|
|
1753
|
-
*/
|
|
1754
|
-
const isMounted = ref(false);
|
|
1755
|
-
onMounted(() => {
|
|
1756
|
-
isMounted.value = true;
|
|
1757
|
-
});
|
|
1758
|
-
const teleportDisabled = computed(() => teleport === false || !isMounted.value);
|
|
1759
|
-
return {
|
|
1760
|
-
teleportTo: computed(() => {
|
|
1761
|
-
if (!isMounted.value) return "body";
|
|
1762
|
-
if (typeof teleport === "string") return teleport;
|
|
1763
|
-
isOpen.value;
|
|
1764
|
-
const anchor = trigger.value;
|
|
1765
|
-
return (anchor === null ? null : topLayerDialog(anchor)) ?? document.body;
|
|
1766
|
-
}),
|
|
1767
|
-
teleportDisabled
|
|
1768
|
-
};
|
|
1769
|
-
}
|
|
1770
|
-
// src/composables/useOverlay.ts
|
|
1644
|
+
var CURRENCY_KEY = Symbol("eldra-ui-currency");
|
|
1771
1645
|
/**
|
|
1772
|
-
*
|
|
1773
|
-
*
|
|
1774
|
-
*
|
|
1775
|
-
*
|
|
1646
|
+
* Set the store currency for this component and everything below it.
|
|
1647
|
+
*
|
|
1648
|
+
* Wraps Vue's `provide`, so it must be called during `setup()`. Use
|
|
1649
|
+
* `app.provide(CURRENCY_KEY, currency)` for the app-wide case.
|
|
1776
1650
|
*/
|
|
1777
|
-
|
|
1651
|
+
function provideEldraUiCurrency(currency) {
|
|
1652
|
+
provide(CURRENCY_KEY, currency);
|
|
1653
|
+
}
|
|
1778
1654
|
/**
|
|
1779
|
-
*
|
|
1780
|
-
*
|
|
1781
|
-
*
|
|
1782
|
-
* handed: a teleported panel's `Tab` walk runs through them (see its `tabRedirect` option).
|
|
1655
|
+
* A value no provider can supply, so `inject`'s default tells "nobody provided a currency" apart
|
|
1656
|
+
* from "a provider answered: this store has none". Vue's `inject` returns a provided `undefined`
|
|
1657
|
+
* rather than the default (it tests `key in provides`), which is what makes the distinction real.
|
|
1783
1658
|
*/
|
|
1784
|
-
var
|
|
1785
|
-
var read = (setting, fallback) => setting === void 0 ? fallback : typeof setting === "function" ? setting() : setting;
|
|
1659
|
+
var NO_CURRENCY_PROVIDER = Symbol("eldra-ui-currency-absent");
|
|
1786
1660
|
/**
|
|
1787
|
-
* The
|
|
1788
|
-
*
|
|
1789
|
-
*
|
|
1790
|
-
* Non-modal is the whole point. The design spec's non-negotiables put every *modal* surface in a
|
|
1791
|
-
* native `<dialog>` opened with `showModal()`, and say in the same breath that these popups are not
|
|
1792
|
-
* dialogs: "Non-modal popups (select panels, search results panel, mega-menus, tooltips) are **not**
|
|
1793
|
-
* dialogs." So there is no focus trap here and no `Tab` cycling — `Tab` simply moves on, and focus
|
|
1794
|
-
* landing outside is what closes the popup (WCAG 2.1.2: no keyboard trap). Everything this
|
|
1795
|
-
* composable does is close at the right moment and leave focus somewhere sensible.
|
|
1796
|
-
*
|
|
1797
|
-
* What it listens for, and only while `open` is `true`:
|
|
1798
|
-
*
|
|
1799
|
-
* - **A pointer press outside** (`pointerdown`, captured, so a handler inside the page that stops
|
|
1800
|
-
* propagation cannot hide the press from us). Inside is the trigger, the content, and anything
|
|
1801
|
-
* under an element carrying `data-eldra-overlay-owner="<the content's id>"` — which is how a
|
|
1802
|
-
* panel rendered through a `<Teleport>` still counts as part of the overlay. Closing this way
|
|
1803
|
-
* never moves focus: the user is pressing something else, and pulling focus back to the trigger
|
|
1804
|
-
* would take it off whatever they just pressed.
|
|
1805
|
-
* - **Focus leaving** (`focusout`). If the new focus owner is outside the overlay, the popup
|
|
1806
|
-
* closes and focus stays where the user sent it. If focus went *nowhere* (`relatedTarget` is
|
|
1807
|
-
* `null` — the content is about to be removed from under it), `returnFocus` puts it back on the
|
|
1808
|
-
* trigger rather than letting it fall to `<body>`.
|
|
1809
|
-
* - **`Escape`** (`keydown`, bubbling, so a component that wants the first go at `Escape` — the
|
|
1810
|
-
* Select clears its search query before it closes — can handle it and stop propagation). It
|
|
1811
|
-
* closes, returns focus to the trigger, and both `preventDefault()`s and stops propagation: a
|
|
1812
|
-
* popup inside a native `<dialog>` must consume the key, or the dialog closes behind it.
|
|
1661
|
+
* The currency a component should format money in: whatever an ancestor provided, else **nothing**.
|
|
1662
|
+
* A ref or a getter is unwrapped on every read, so the value follows a currency switch.
|
|
1813
1663
|
*
|
|
1814
|
-
*
|
|
1815
|
-
*
|
|
1816
|
-
*
|
|
1664
|
+
* **There is no default code.** A component library installed by a shop of any kind cannot guess
|
|
1665
|
+
* one: a `USD` fallback puts a dollar sign in front of krónur, and a wrong price is worse than an
|
|
1666
|
+
* incomplete one. So `undefined` comes back whenever there is no currency to name, and a component
|
|
1667
|
+
* reading it formats the amount as a plain number through the same `Intl` path, with no symbol and
|
|
1668
|
+
* no code (`Price` does exactly that). The empty string is read as "no currency" too: it is not a
|
|
1669
|
+
* code `Intl` accepts, and it was the only way to decline one while this composable still defaulted.
|
|
1817
1670
|
*
|
|
1818
|
-
*
|
|
1819
|
-
*
|
|
1820
|
-
*
|
|
1821
|
-
* const content = ref<HTMLElement | null>(null);
|
|
1822
|
-
* const overlay = useOverlay({ open, trigger, content, setOpen: (next) => (open.value = next) });
|
|
1823
|
-
* ```
|
|
1671
|
+
* Two ways to arrive at `undefined`, and only one of them is a mistake. A provider that supplies
|
|
1672
|
+
* `undefined` (or `''`) has *answered* — this store has no currency — and nothing is logged. Having
|
|
1673
|
+
* no provider at all is unwired, and warns once per session in dev.
|
|
1824
1674
|
*/
|
|
1825
|
-
function
|
|
1826
|
-
const
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1675
|
+
function useEldraUiCurrency() {
|
|
1676
|
+
const provided = inject(CURRENCY_KEY, NO_CURRENCY_PROVIDER);
|
|
1677
|
+
return computed(() => {
|
|
1678
|
+
if (provided === NO_CURRENCY_PROVIDER) return;
|
|
1679
|
+
const currency = toValue(provided);
|
|
1680
|
+
return currency === void 0 || currency === "" ? void 0 : currency;
|
|
1681
|
+
});
|
|
1682
|
+
}
|
|
1683
|
+
// src/components/select/SelectPanel.vue?vue&type=script&setup=true&lang.ts
|
|
1684
|
+
var _hoisted_1 = [
|
|
1685
|
+
"data-eldra-slot",
|
|
1686
|
+
"id",
|
|
1687
|
+
"data-eldra-scope",
|
|
1688
|
+
"data-eldra-overlay-owner",
|
|
1689
|
+
"data-placement"
|
|
1690
|
+
];
|
|
1691
|
+
var _hoisted_2 = ["data-eldra-scope"];
|
|
1692
|
+
var _hoisted_3 = [
|
|
1693
|
+
"value",
|
|
1694
|
+
"placeholder",
|
|
1695
|
+
"aria-label",
|
|
1696
|
+
"aria-controls",
|
|
1697
|
+
"aria-activedescendant"
|
|
1698
|
+
];
|
|
1699
|
+
var _hoisted_4 = [
|
|
1700
|
+
"data-eldra-scope",
|
|
1701
|
+
"id",
|
|
1702
|
+
"aria-multiselectable",
|
|
1703
|
+
"aria-labelledby",
|
|
1704
|
+
"aria-label",
|
|
1705
|
+
"aria-busy"
|
|
1706
|
+
];
|
|
1707
|
+
var _hoisted_5 = [
|
|
1708
|
+
"data-part",
|
|
1709
|
+
"role",
|
|
1710
|
+
"aria-labelledby"
|
|
1711
|
+
];
|
|
1712
|
+
var _hoisted_6 = ["id"];
|
|
1713
|
+
var _hoisted_7 = [
|
|
1714
|
+
"data-eldra-slot",
|
|
1715
|
+
"id",
|
|
1716
|
+
"aria-selected",
|
|
1717
|
+
"aria-disabled",
|
|
1718
|
+
"onClick",
|
|
1719
|
+
"onMouseenter"
|
|
1720
|
+
];
|
|
1721
|
+
var _hoisted_8 = ["data-eldra-scope"];
|
|
1722
|
+
var _hoisted_9 = { class: "eldra:min-w-0 eldra:flex-1" };
|
|
1723
|
+
var _hoisted_10 = { class: "eldra:eldra-select-match" };
|
|
1724
|
+
var _hoisted_11 = ["data-eldra-scope"];
|
|
1725
|
+
var _hoisted_12 = ["id"];
|
|
1726
|
+
var _hoisted_13 = { class: "eldra:min-w-0 eldra:flex-1 eldra:truncate" };
|
|
1727
|
+
var _hoisted_14 = ["data-eldra-slot", "data-eldra-scope"];
|
|
1728
|
+
var _hoisted_15 = ["data-eldra-slot", "data-eldra-scope"];
|
|
1729
|
+
var SCROLL_END_SLACK = 80;
|
|
1730
|
+
var FOCUSABLE = "input, button, a[href], textarea, select, [tabindex]:not([tabindex^=\"-\"])";
|
|
1731
|
+
// src/components/select/SelectPanel.vue
|
|
1732
|
+
var SelectPanel_default = /* @__PURE__ */ defineComponent({
|
|
1733
|
+
__name: "SelectPanel",
|
|
1734
|
+
props: {
|
|
1735
|
+
panelId: {},
|
|
1736
|
+
listboxId: {},
|
|
1737
|
+
sections: {},
|
|
1738
|
+
hasOptions: { type: Boolean },
|
|
1739
|
+
highlights: {},
|
|
1740
|
+
optionId: {},
|
|
1741
|
+
activeValue: { default: void 0 },
|
|
1742
|
+
selectedValues: {},
|
|
1743
|
+
searchable: { type: Boolean },
|
|
1744
|
+
query: {},
|
|
1745
|
+
searchPlaceholder: {},
|
|
1746
|
+
emptyText: {},
|
|
1747
|
+
labelledBy: { default: void 0 },
|
|
1748
|
+
fallbackLabel: { default: void 0 },
|
|
1749
|
+
multiple: {
|
|
1750
|
+
type: Boolean,
|
|
1751
|
+
default: false
|
|
1752
|
+
},
|
|
1753
|
+
loading: {
|
|
1754
|
+
type: Boolean,
|
|
1755
|
+
default: false
|
|
1756
|
+
},
|
|
1757
|
+
loadingText: { default: void 0 },
|
|
1758
|
+
createOption: { default: void 0 },
|
|
1759
|
+
createText: { default: void 0 },
|
|
1760
|
+
panelStyle: { default: void 0 },
|
|
1761
|
+
placement: { default: void 0 },
|
|
1762
|
+
classes: { default: void 0 }
|
|
1763
|
+
},
|
|
1764
|
+
emits: [
|
|
1765
|
+
"search",
|
|
1766
|
+
"select",
|
|
1767
|
+
"activate",
|
|
1768
|
+
"keydown",
|
|
1769
|
+
"scrollEnd"
|
|
1770
|
+
],
|
|
1771
|
+
setup(__props, { expose: __expose, emit: __emit }) {
|
|
1772
|
+
const eldra = useEldraScope();
|
|
1773
|
+
/**
|
|
1774
|
+
* The popover a `Select` and a `MultiSelect` both open: the search field, the listbox with its
|
|
1775
|
+
* groups and option rows, and the empty state — plus a `footer` slot, which only a multi-select
|
|
1776
|
+
* fills.
|
|
1777
|
+
*
|
|
1778
|
+
* It exists so that the two controls share one panel rather than two copies of the same markup.
|
|
1779
|
+
* Everything it knows is a prop: it owns no open/closed state, no query, no value, and no keyboard
|
|
1780
|
+
* (that is `useListbox`). What it does own is the DOM the parents cannot: the panel element and
|
|
1781
|
+
* the search input, both exposed so the parent can position the one and focus the other, and the
|
|
1782
|
+
* pointer-press guard that keeps a press inside the panel from blurring the focused element.
|
|
1783
|
+
*
|
|
1784
|
+
* `multiple` is the one behavioural switch, and it is the spec's own: a multi-select's rows carry a
|
|
1785
|
+
* checkbox instead of a trailing check mark, and its listbox is `aria-multiselectable="true"`.
|
|
1786
|
+
*/
|
|
1787
|
+
const props = __props;
|
|
1788
|
+
const emit = __emit;
|
|
1789
|
+
const root = ref(null);
|
|
1790
|
+
const searchInput = ref(null);
|
|
1791
|
+
__expose({
|
|
1792
|
+
root,
|
|
1793
|
+
searchInput
|
|
1794
|
+
});
|
|
1795
|
+
const isActive = (option) => props.activeValue === option.value;
|
|
1796
|
+
const isSelected = (option) => props.selectedValues.includes(option.value);
|
|
1797
|
+
const panelClasses = computed(() => panelClass(props.classes));
|
|
1798
|
+
const searchClasses = computed(() => searchClass(props.classes));
|
|
1799
|
+
const listboxClasses = computed(() => listboxClass(props.classes, props.hasOptions));
|
|
1800
|
+
const optionHintClasses = computed(() => optionHintClass(props.classes));
|
|
1801
|
+
const optionSwatchClasses = computed(() => optionSwatchClass(props.classes));
|
|
1802
|
+
const optionIconClasses = computed(() => optionIconClass(props.classes));
|
|
1803
|
+
const optionCheckClasses = computed(() => optionCheckClass(props.classes));
|
|
1804
|
+
const emptyClasses = computed(() => emptyClass(props.classes));
|
|
1805
|
+
const loadingClasses = computed(() => loadingClass(props.classes));
|
|
1806
|
+
const createClasses = computed(() => props.createOption === void 0 ? "" : createOptionClass(props.classes, { active: isActive(props.createOption) }));
|
|
1807
|
+
/** Within this many pixels of the end — two rows — the next render batch is asked for. */
|
|
1808
|
+
function onListScroll(event) {
|
|
1809
|
+
const list = event.currentTarget;
|
|
1810
|
+
if (list.scrollHeight - list.scrollTop - list.clientHeight <= SCROLL_END_SLACK) emit("scrollEnd");
|
|
1868
1811
|
}
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1812
|
+
const rowClass = (option) => optionClass(props.classes, option, {
|
|
1813
|
+
active: isActive(option),
|
|
1814
|
+
selected: isSelected(option),
|
|
1815
|
+
multiple: props.multiple
|
|
1816
|
+
});
|
|
1817
|
+
const boxClass = (option) => optionBoxClass(props.classes, {
|
|
1818
|
+
selected: isSelected(option),
|
|
1819
|
+
disabled: option.disabled === true
|
|
1820
|
+
});
|
|
1821
|
+
/**
|
|
1822
|
+
* Spec "Select" → Behaviour: "The active option is scrolled into view with a 0.25rem margin
|
|
1823
|
+
* whenever it changes" — the margin is the row's own `scroll-my-1`.
|
|
1824
|
+
*
|
|
1825
|
+
* It lives here rather than in either parent because it is the one part of "the active row" that
|
|
1826
|
+
* needs an element, and the panel is what has the elements. Both controls get it from one copy.
|
|
1827
|
+
*/
|
|
1828
|
+
function scrollActiveIntoView() {
|
|
1829
|
+
const value = props.activeValue;
|
|
1830
|
+
if (value === void 0 || typeof document === "undefined") return;
|
|
1831
|
+
document.getElementById(props.optionId(value))?.scrollIntoView?.({ block: "nearest" });
|
|
1878
1832
|
}
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1833
|
+
onMounted(scrollActiveIntoView);
|
|
1834
|
+
watch(() => props.activeValue, () => void nextTick(scrollActiveIntoView));
|
|
1835
|
+
function onSearchInput(event) {
|
|
1836
|
+
emit("search", event.target.value);
|
|
1837
|
+
}
|
|
1838
|
+
/**
|
|
1839
|
+
* Anything inside the panel that wants the pointer's default action: it takes focus, or places a
|
|
1840
|
+
* caret. The search field and — in a multi-select — the footer's Clear and Done buttons.
|
|
1841
|
+
*/
|
|
1842
|
+
function onPanelMouseDown(event) {
|
|
1843
|
+
const target = event.target;
|
|
1844
|
+
if (target instanceof Element && target.closest(FOCUSABLE) !== null) return;
|
|
1845
|
+
event.preventDefault();
|
|
1846
|
+
}
|
|
1847
|
+
return (_ctx, _cache) => {
|
|
1848
|
+
return openBlock(), createElementBlock("div", {
|
|
1849
|
+
ref_key: "root",
|
|
1850
|
+
ref: root,
|
|
1851
|
+
"data-eldra-slot": unref(eldra).slotHost("footer"),
|
|
1852
|
+
id: __props.panelId,
|
|
1853
|
+
"data-eldra-ui": "",
|
|
1854
|
+
"data-eldra-scope": unref(eldra).scope,
|
|
1855
|
+
"data-part": "panel",
|
|
1856
|
+
"data-eldra-overlay-owner": __props.panelId,
|
|
1857
|
+
class: normalizeClass(panelClasses.value),
|
|
1858
|
+
style: normalizeStyle(__props.panelStyle),
|
|
1859
|
+
"data-placement": __props.placement,
|
|
1860
|
+
onMousedown: onPanelMouseDown
|
|
1861
|
+
}, [
|
|
1862
|
+
__props.searchable ? (openBlock(), createElementBlock("div", {
|
|
1863
|
+
key: 0,
|
|
1864
|
+
"data-eldra-scope": unref(eldra).scope,
|
|
1865
|
+
class: "eldra:relative eldra:shrink-0 eldra:border-b eldra:border-[color:var(--eldra-select-panel-border,var(--eldra-color-border))]"
|
|
1866
|
+
}, [_cache[3] || (_cache[3] = createElementVNode("svg", {
|
|
1867
|
+
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))]",
|
|
1868
|
+
viewBox: "0 0 24 24",
|
|
1869
|
+
fill: "none",
|
|
1870
|
+
stroke: "currentColor",
|
|
1871
|
+
"stroke-width": "1.75",
|
|
1872
|
+
"stroke-linecap": "round",
|
|
1873
|
+
"stroke-linejoin": "round",
|
|
1874
|
+
"aria-hidden": "true",
|
|
1875
|
+
focusable: "false"
|
|
1876
|
+
}, [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", {
|
|
1877
|
+
ref_key: "searchInput",
|
|
1878
|
+
ref: searchInput,
|
|
1879
|
+
"data-part": "search",
|
|
1880
|
+
type: "text",
|
|
1881
|
+
role: "combobox",
|
|
1882
|
+
class: normalizeClass(searchClasses.value),
|
|
1883
|
+
value: __props.query,
|
|
1884
|
+
placeholder: __props.searchPlaceholder,
|
|
1885
|
+
"aria-label": __props.searchPlaceholder,
|
|
1886
|
+
"aria-autocomplete": "list",
|
|
1887
|
+
"aria-expanded": "true",
|
|
1888
|
+
"aria-controls": __props.listboxId,
|
|
1889
|
+
"aria-activedescendant": __props.activeValue === void 0 ? void 0 : __props.optionId(__props.activeValue),
|
|
1890
|
+
autocomplete: "off",
|
|
1891
|
+
spellcheck: "false",
|
|
1892
|
+
onInput: onSearchInput,
|
|
1893
|
+
onKeydown: _cache[0] || (_cache[0] = ($event) => emit("keydown", $event))
|
|
1894
|
+
}, null, 42, _hoisted_3)], 8, _hoisted_2)) : createCommentVNode("", true),
|
|
1895
|
+
createElementVNode("div", {
|
|
1896
|
+
"data-eldra-scope": unref(eldra).scope,
|
|
1897
|
+
id: __props.listboxId,
|
|
1898
|
+
"data-part": "listbox",
|
|
1899
|
+
role: "listbox",
|
|
1900
|
+
class: normalizeClass(listboxClasses.value),
|
|
1901
|
+
"aria-multiselectable": __props.multiple ? "true" : void 0,
|
|
1902
|
+
"aria-labelledby": __props.labelledBy,
|
|
1903
|
+
"aria-label": __props.fallbackLabel,
|
|
1904
|
+
"aria-busy": __props.loading ? "true" : void 0,
|
|
1905
|
+
onScrollPassive: onListScroll
|
|
1906
|
+
}, [(openBlock(true), createElementBlock(Fragment, null, renderList(__props.sections, (section, sectionIndex) => {
|
|
1907
|
+
return openBlock(), createElementBlock("div", {
|
|
1908
|
+
key: section.key,
|
|
1909
|
+
"data-part": section.label ? "group" : void 0,
|
|
1910
|
+
role: section.label ? "group" : "presentation",
|
|
1911
|
+
class: normalizeClass(section.label ? unref(groupClass)(__props.classes, sectionIndex) : void 0),
|
|
1912
|
+
"aria-labelledby": section.labelId
|
|
1913
|
+
}, [section.label ? (openBlock(), createElementBlock("div", {
|
|
1914
|
+
key: 0,
|
|
1915
|
+
id: section.labelId,
|
|
1916
|
+
"data-part": "groupLabel",
|
|
1917
|
+
role: "presentation",
|
|
1918
|
+
class: normalizeClass(unref(groupLabelClass)(__props.classes, sectionIndex))
|
|
1919
|
+
}, toDisplayString(section.label), 11, _hoisted_6)) : createCommentVNode("", true), (openBlock(true), createElementBlock(Fragment, null, renderList(section.options, (option) => {
|
|
1920
|
+
return openBlock(), createElementBlock("div", {
|
|
1921
|
+
key: option.value,
|
|
1922
|
+
"data-eldra-slot": unref(eldra).slotHost("option", "optionContent"),
|
|
1923
|
+
id: __props.optionId(option.value),
|
|
1924
|
+
"data-part": "option",
|
|
1925
|
+
role: "option",
|
|
1926
|
+
class: normalizeClass(rowClass(option)),
|
|
1927
|
+
"aria-selected": isSelected(option) ? "true" : "false",
|
|
1928
|
+
"aria-disabled": option.disabled ? "true" : void 0,
|
|
1929
|
+
onClick: ($event) => emit("select", option),
|
|
1930
|
+
onMouseenter: ($event) => option.disabled ? void 0 : emit("activate", option.value)
|
|
1931
|
+
}, [renderSlot(_ctx.$slots, "option", {
|
|
1932
|
+
option,
|
|
1933
|
+
selected: isSelected(option),
|
|
1934
|
+
active: isActive(option)
|
|
1935
|
+
}, () => [
|
|
1936
|
+
__props.multiple ? (openBlock(), createElementBlock("span", {
|
|
1937
|
+
key: 0,
|
|
1938
|
+
"data-eldra-scope": unref(eldra).scope,
|
|
1939
|
+
"data-part": "optionCheck",
|
|
1940
|
+
class: normalizeClass(boxClass(option)),
|
|
1941
|
+
"aria-hidden": "true"
|
|
1942
|
+
}, [(openBlock(), createElementBlock("svg", {
|
|
1943
|
+
class: normalizeClass(unref(optionTickClass)(isSelected(option))),
|
|
1944
|
+
viewBox: "0 0 8 8",
|
|
1945
|
+
fill: "none",
|
|
1946
|
+
stroke: "currentColor",
|
|
1947
|
+
"stroke-width": "2",
|
|
1948
|
+
"stroke-linecap": "round",
|
|
1949
|
+
"stroke-linejoin": "round",
|
|
1950
|
+
"aria-hidden": "true",
|
|
1951
|
+
focusable: "false"
|
|
1952
|
+
}, [..._cache[4] || (_cache[4] = [createElementVNode("path", { d: "M1 4l2 2l4 -4" }, null, -1)])], 2))], 10, _hoisted_8)) : createCommentVNode("", true),
|
|
1953
|
+
renderSlot(_ctx.$slots, "optionContent", {
|
|
1954
|
+
option,
|
|
1955
|
+
selected: isSelected(option),
|
|
1956
|
+
active: isActive(option),
|
|
1957
|
+
match: __props.highlights.get(option.value) ?? null
|
|
1958
|
+
}, () => [
|
|
1959
|
+
option.swatch ? (openBlock(), createElementBlock("span", {
|
|
1960
|
+
key: 0,
|
|
1961
|
+
"data-part": "optionSwatch",
|
|
1962
|
+
class: normalizeClass(optionSwatchClasses.value),
|
|
1963
|
+
style: normalizeStyle({ backgroundColor: option.swatch }),
|
|
1964
|
+
"aria-hidden": "true"
|
|
1965
|
+
}, null, 6)) : option.icon ? (openBlock(), createBlock(resolveDynamicComponent(option.icon), {
|
|
1966
|
+
key: 1,
|
|
1967
|
+
"data-eldra-scope": unref(eldra).scope,
|
|
1968
|
+
"data-part": "optionIcon",
|
|
1969
|
+
class: normalizeClass(optionIconClasses.value),
|
|
1970
|
+
"stroke-width": unref(ICON_STROKE_WIDTH),
|
|
1971
|
+
"aria-hidden": "true",
|
|
1972
|
+
focusable: "false"
|
|
1973
|
+
}, null, 8, [
|
|
1974
|
+
"data-eldra-scope",
|
|
1975
|
+
"class",
|
|
1976
|
+
"stroke-width"
|
|
1977
|
+
])) : createCommentVNode("", true),
|
|
1978
|
+
createElementVNode("span", _hoisted_9, [createElementVNode("span", {
|
|
1979
|
+
"data-part": "optionLabel",
|
|
1980
|
+
class: normalizeClass(unref(optionLabelClass)(__props.classes))
|
|
1981
|
+
}, [__props.highlights.get(option.value) ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
|
|
1982
|
+
createTextVNode(toDisplayString(__props.highlights.get(option.value)?.before), 1),
|
|
1983
|
+
createElementVNode("span", _hoisted_10, toDisplayString(__props.highlights.get(option.value)?.match), 1),
|
|
1984
|
+
createTextVNode(toDisplayString(__props.highlights.get(option.value)?.after), 1)
|
|
1985
|
+
], 64)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [createTextVNode(toDisplayString(option.label), 1)], 64))], 2), option.hint ? (openBlock(), createElementBlock("span", {
|
|
1986
|
+
key: 0,
|
|
1987
|
+
"data-part": "optionHint",
|
|
1988
|
+
class: normalizeClass(optionHintClasses.value)
|
|
1989
|
+
}, toDisplayString(option.hint), 3)) : createCommentVNode("", true)]),
|
|
1990
|
+
option.meta ? (openBlock(), createElementBlock("span", {
|
|
1991
|
+
key: 2,
|
|
1992
|
+
"data-part": "optionMeta",
|
|
1993
|
+
class: normalizeClass(unref(optionMetaClass)(__props.classes, option))
|
|
1994
|
+
}, toDisplayString(option.meta), 3)) : createCommentVNode("", true)
|
|
1995
|
+
]),
|
|
1996
|
+
!__props.multiple && isSelected(option) ? (openBlock(), createElementBlock("svg", {
|
|
1997
|
+
key: 1,
|
|
1998
|
+
"data-eldra-scope": unref(eldra).scope,
|
|
1999
|
+
"data-part": "optionCheck",
|
|
2000
|
+
class: normalizeClass(optionCheckClasses.value),
|
|
2001
|
+
viewBox: "0 0 24 24",
|
|
2002
|
+
fill: "none",
|
|
2003
|
+
stroke: "currentColor",
|
|
2004
|
+
"stroke-width": "1.75",
|
|
2005
|
+
"stroke-linecap": "round",
|
|
2006
|
+
"stroke-linejoin": "round",
|
|
2007
|
+
"aria-hidden": "true",
|
|
2008
|
+
focusable: "false"
|
|
2009
|
+
}, [..._cache[5] || (_cache[5] = [createElementVNode("path", { d: "M5 12l5 5l10 -10" }, null, -1)])], 10, _hoisted_11)) : createCommentVNode("", true)
|
|
2010
|
+
])], 42, _hoisted_7);
|
|
2011
|
+
}), 128))], 10, _hoisted_5);
|
|
2012
|
+
}), 128)), __props.createOption ? (openBlock(), createElementBlock("div", {
|
|
2013
|
+
key: 0,
|
|
2014
|
+
role: "presentation",
|
|
2015
|
+
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)
|
|
2016
|
+
}, [createElementVNode("div", {
|
|
2017
|
+
id: __props.optionId(__props.createOption.value),
|
|
2018
|
+
"data-part": "createOption",
|
|
2019
|
+
role: "option",
|
|
2020
|
+
"aria-selected": "false",
|
|
2021
|
+
class: normalizeClass(createClasses.value),
|
|
2022
|
+
onClick: _cache[1] || (_cache[1] = ($event) => emit("select", __props.createOption)),
|
|
2023
|
+
onMouseenter: _cache[2] || (_cache[2] = ($event) => emit("activate", __props.createOption.value))
|
|
2024
|
+
}, [(openBlock(), createElementBlock("svg", {
|
|
2025
|
+
class: normalizeClass(optionIconClasses.value),
|
|
2026
|
+
viewBox: "0 0 24 24",
|
|
2027
|
+
fill: "none",
|
|
2028
|
+
stroke: "currentColor",
|
|
2029
|
+
"stroke-width": "1.75",
|
|
2030
|
+
"stroke-linecap": "round",
|
|
2031
|
+
"stroke-linejoin": "round",
|
|
2032
|
+
"aria-hidden": "true",
|
|
2033
|
+
focusable: "false"
|
|
2034
|
+
}, [..._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),
|
|
2035
|
+
__props.loading ? (openBlock(), createElementBlock("div", {
|
|
2036
|
+
key: 1,
|
|
2037
|
+
"data-eldra-slot": unref(eldra).slotHost("loading"),
|
|
2038
|
+
"data-eldra-scope": unref(eldra).scope,
|
|
2039
|
+
"data-part": "loading",
|
|
2040
|
+
role: "status",
|
|
2041
|
+
class: normalizeClass(loadingClasses.value)
|
|
2042
|
+
}, [createVNode(Spinner_default, { class: "eldra:size-4" }), renderSlot(_ctx.$slots, "loading", {}, () => [createTextVNode(toDisplayString(__props.loadingText), 1)])], 10, _hoisted_14)) : !__props.hasOptions ? (openBlock(), createElementBlock("div", {
|
|
2043
|
+
key: 2,
|
|
2044
|
+
"data-eldra-slot": unref(eldra).slotHost("empty"),
|
|
2045
|
+
"data-eldra-scope": unref(eldra).scope,
|
|
2046
|
+
"data-part": "empty",
|
|
2047
|
+
class: normalizeClass(emptyClasses.value)
|
|
2048
|
+
}, [renderSlot(_ctx.$slots, "empty", {}, () => [createTextVNode(toDisplayString(__props.emptyText), 1)])], 10, _hoisted_15)) : createCommentVNode("", true),
|
|
2049
|
+
renderSlot(_ctx.$slots, "footer")
|
|
2050
|
+
], 46, _hoisted_1);
|
|
2051
|
+
};
|
|
1944
2052
|
}
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
contains: options.contains
|
|
1948
|
-
}];
|
|
1949
|
-
for (const entry of closed) entry.close();
|
|
1950
|
-
}
|
|
1951
|
-
/** Release the slot, if it is still this popup's. */
|
|
1952
|
-
function unregisterOpen(close) {
|
|
1953
|
-
stack = stack.filter((entry) => entry.close !== close);
|
|
1954
|
-
}
|
|
1955
|
-
// src/components/select/usePopover.ts
|
|
2053
|
+
});
|
|
2054
|
+
// src/components/select/useOptionList.ts
|
|
1956
2055
|
/**
|
|
1957
|
-
*
|
|
1958
|
-
* `MultiSelect`'s, and the `SearchBar`'s results panel.
|
|
1959
|
-
*
|
|
1960
|
-
* Every one of them needs the same six things, and before this composable the first two controls
|
|
1961
|
-
* held a line-identical copy of all of them:
|
|
1962
|
-
*
|
|
1963
|
-
* - **"Only one open at a time"** (`openRegistry`): opening claims a module-level slot and closes
|
|
1964
|
-
* whatever held it. The handle is stable per instance, so a late close cannot blank out the
|
|
1965
|
-
* popup that took its place.
|
|
1966
|
-
* - **Closing** (`useOverlay`): an outside pointer press, focus leaving, `Escape`. Non-modal, so
|
|
1967
|
-
* nothing is trapped and `Tab` always moves on.
|
|
1968
|
-
* - **Getting out of the way of the page** (`teleport`): the panel is rendered through a
|
|
1969
|
-
* `<Teleport>` to `body` — or to the modal `<dialog>` the trigger is in, which is the one place
|
|
1970
|
-
* `body` would be *behind* — and positioned with floating-ui's `fixed` strategy, so no ancestor's
|
|
1971
|
-
* `overflow: hidden` clips it and no later stacking context paints over it. `tabRedirect` puts a
|
|
1972
|
-
* panel that has real tab stops back into the `Tab` walk it left with its place in the DOM.
|
|
1973
|
-
* - **Positioning** (`useFloating`), plus the `--eldra-popover-origin` the entrance keyframes read,
|
|
1974
|
-
* so a panel that flips after floating-ui measures changes a custom property rather than its
|
|
1975
|
-
* `animation-name` (which would replay the entrance).
|
|
1976
|
-
* - **The open sequence**: open, make a row active, and — only when the call actually changed the
|
|
1977
|
-
* state — run `afterOpen` a tick later, which is where focus moves into the panel.
|
|
1978
|
-
* - **The label-forwarded-click latch**: a `<label for>` naming the trigger forwards its click to
|
|
1979
|
-
* it, and the spec is explicit that clicking a field's label focuses the control **without**
|
|
1980
|
-
* opening it. A forwarded click differs from a real one in that no pointer was pressed on the
|
|
1981
|
-
* trigger and its `detail` is 0. The latch is armed on `pointerdown` and released on the
|
|
1982
|
-
* `pointerup` or `pointercancel` that follows, wherever it lands: a press that ends off the
|
|
1983
|
-
* trigger (a drag, a cancelled touch) would otherwise leave the latch standing and arm the
|
|
1984
|
-
* *next* click. A programmatic `element.click()` has the same shape, so it is told apart by what
|
|
1985
|
-
* it is not (see `isProgrammaticClick`): not forwarded from a label clicked in the same task,
|
|
1986
|
-
* not trusted, and a `PointerEvent`, which is what `click()` dispatches.
|
|
2056
|
+
* Where a query matches inside a label, in **code points of the original string**.
|
|
1987
2057
|
*
|
|
1988
|
-
*
|
|
1989
|
-
*
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
*
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
}, 0);
|
|
2011
|
-
}, true);
|
|
2012
|
-
}
|
|
2013
|
-
/**
|
|
2014
|
-
* Whether a click with no pointer press behind it came from code (`trigger.click()`) rather than a
|
|
2015
|
-
* `<label>` forwarding its own: not forwarded from a label clicked in this task, untrusted (a
|
|
2016
|
-
* user's label click forwards a trusted one), and a `PointerEvent`, which is what `click()`
|
|
2017
|
-
* dispatches. A bare `dispatchEvent(new MouseEvent('click'))` keeps counting as forwarded, as it
|
|
2018
|
-
* always has; so does every click in an engine whose `click()` still sends a `MouseEvent`.
|
|
2019
|
-
*/
|
|
2020
|
-
function isProgrammaticClick(event, trigger) {
|
|
2021
|
-
if (trigger !== null && forwardingTo !== null && trigger.contains(forwardingTo)) return false;
|
|
2022
|
-
return !event.isTrusted && typeof PointerEvent !== "undefined" && event instanceof PointerEvent;
|
|
2023
|
-
}
|
|
2024
|
-
function usePopover(options) {
|
|
2025
|
-
const { trigger, content } = options;
|
|
2026
|
-
watchLabelClicks();
|
|
2027
|
-
const canOpen = () => options.canOpen?.() !== false;
|
|
2028
|
-
const isOpen = ref(false);
|
|
2029
|
-
const isExclusive = () => {
|
|
2030
|
-
const setting = options.exclusive ?? true;
|
|
2031
|
-
return typeof setting === "function" ? setting() : setting;
|
|
2032
|
-
};
|
|
2033
|
-
/** The `anchor`, when it is a real element rather than a virtual one. */
|
|
2034
|
-
const anchorElement = () => {
|
|
2035
|
-
const anchor = options.anchor?.value ?? null;
|
|
2036
|
-
return typeof HTMLElement !== "undefined" && anchor instanceof HTMLElement ? anchor : null;
|
|
2037
|
-
};
|
|
2038
|
-
/** The registry's handle on this popup. Stable, so the registry can tell ours from another's. */
|
|
2039
|
-
const closeFromRegistry = () => setOpen(false);
|
|
2040
|
-
function setOpen(next) {
|
|
2041
|
-
if (next === isOpen.value) return;
|
|
2042
|
-
if (next) {
|
|
2043
|
-
if (!canOpen()) return;
|
|
2044
|
-
isOpen.value = true;
|
|
2045
|
-
if (isExclusive()) registerOpen(closeFromRegistry, {
|
|
2046
|
-
anchor: trigger.value ?? anchorElement(),
|
|
2047
|
-
contains: (node) => overlay.isInside(node)
|
|
2048
|
-
});
|
|
2049
|
-
options.onOpen?.();
|
|
2050
|
-
return;
|
|
2051
|
-
}
|
|
2052
|
-
isOpen.value = false;
|
|
2053
|
-
unregisterOpen(closeFromRegistry);
|
|
2054
|
-
options.onClose?.();
|
|
2055
|
-
}
|
|
2056
|
-
const overlay = useOverlay({
|
|
2057
|
-
open: isOpen,
|
|
2058
|
-
trigger,
|
|
2059
|
-
content,
|
|
2060
|
-
setOpen: (next) => setOpen(next),
|
|
2061
|
-
closeOnOutsideClick: options.closeOnOutsideClick,
|
|
2062
|
-
closeOnFocusOutside: options.closeOnFocusOutside,
|
|
2063
|
-
closeOnEscape: options.closeOnEscape,
|
|
2064
|
-
returnFocus: options.returnFocus
|
|
2065
|
-
});
|
|
2066
|
-
const teleport = options.teleport ?? true;
|
|
2067
|
-
const { teleportTo, teleportDisabled } = useTeleportTarget({
|
|
2068
|
-
trigger: computed(() => trigger.value ?? anchorElement()),
|
|
2069
|
-
teleport,
|
|
2070
|
-
isOpen
|
|
2071
|
-
});
|
|
2072
|
-
const { styles: floatingStyles, placement, update } = useFloating$1(computed(() => options.anchor?.value ?? trigger.value), content, {
|
|
2073
|
-
placement: options.placement ?? "auto",
|
|
2074
|
-
offset: options.offset,
|
|
2075
|
-
padding: options.padding,
|
|
2076
|
-
matchWidth: options.matchWidth,
|
|
2077
|
-
strategy: teleport === false ? "absolute" : "fixed"
|
|
2078
|
-
});
|
|
2079
|
-
const wantsTabRedirect = () => {
|
|
2080
|
-
const setting = options.tabRedirect ?? false;
|
|
2081
|
-
return typeof setting === "function" ? setting() : setting;
|
|
2058
|
+
* Matching is case- and diacritic-insensitive (the spec's "'island' finds 'Ísland'"), so the
|
|
2059
|
+
* comparison happens on a normalised copy — and the match has to be reported back in the original
|
|
2060
|
+
* string's own offsets, or the bold-and-underlined run would land on the wrong characters for any
|
|
2061
|
+
* label holding an accent. Hence the per-character walk: each original code point contributes zero
|
|
2062
|
+
* (a combining mark) or more normalised characters, and `positions` maps back.
|
|
2063
|
+
*/
|
|
2064
|
+
function matchRange(label, rawQuery) {
|
|
2065
|
+
const needle = normalizeText(rawQuery);
|
|
2066
|
+
if (needle === "") return null;
|
|
2067
|
+
const characters = [...label];
|
|
2068
|
+
const positions = [];
|
|
2069
|
+
let normalized = "";
|
|
2070
|
+
for (const [index, character] of characters.entries()) {
|
|
2071
|
+
const piece = normalizeText(character);
|
|
2072
|
+
for (let step = 0; step < piece.length; step += 1) positions.push(index);
|
|
2073
|
+
normalized += piece;
|
|
2074
|
+
}
|
|
2075
|
+
const at = normalized.indexOf(needle);
|
|
2076
|
+
if (at === -1) return null;
|
|
2077
|
+
return {
|
|
2078
|
+
start: positions[at] ?? 0,
|
|
2079
|
+
end: (positions[at + needle.length - 1] ?? characters.length - 1) + 1
|
|
2082
2080
|
};
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
if (
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
if (panel.contains(owner) || roots.includes(owner)) continue;
|
|
2100
|
-
roots.push(owner);
|
|
2081
|
+
}
|
|
2082
|
+
/**
|
|
2083
|
+
* Options bucketed by `group`, in the order each group first appears — so a "Most used" group
|
|
2084
|
+
* written first stays first, which is exactly the spec's advice ("Put the 3 to 5 most likely
|
|
2085
|
+
* answers first"). Options with no `group` form an unlabelled section of their own.
|
|
2086
|
+
*/
|
|
2087
|
+
function groupOptions(list, idPrefix, controlId) {
|
|
2088
|
+
const order = [];
|
|
2089
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
2090
|
+
for (const option of list) {
|
|
2091
|
+
const key = option.group ?? "";
|
|
2092
|
+
let bucket = buckets.get(key);
|
|
2093
|
+
if (bucket === void 0) {
|
|
2094
|
+
bucket = [];
|
|
2095
|
+
buckets.set(key, bucket);
|
|
2096
|
+
order.push(key);
|
|
2101
2097
|
}
|
|
2102
|
-
|
|
2098
|
+
bucket.push(option);
|
|
2103
2099
|
}
|
|
2100
|
+
return order.map((key, index) => ({
|
|
2101
|
+
key: key === "" ? `${idPrefix}-plain-${index}` : `${idPrefix}-group-${key}`,
|
|
2102
|
+
label: key === "" ? void 0 : key,
|
|
2103
|
+
labelId: key === "" ? void 0 : `${controlId}-g${index}`,
|
|
2104
|
+
options: buckets.get(key) ?? []
|
|
2105
|
+
}));
|
|
2106
|
+
}
|
|
2107
|
+
/**
|
|
2108
|
+
* The value of the "Create “query”" row a `creatable` control appends. A control character no
|
|
2109
|
+
* merchant value holds, so it never collides with an option's own value.
|
|
2110
|
+
*/
|
|
2111
|
+
var CREATE_VALUE = "\0eldra-create";
|
|
2112
|
+
/**
|
|
2113
|
+
* The list a select panel shows: filtering, grouping, match highlighting, the create row and the
|
|
2114
|
+
* render batch.
|
|
2115
|
+
*
|
|
2116
|
+
* Shared by `Select` and `MultiSelect`, which differ in what choosing a row *does* and in nothing
|
|
2117
|
+
* about which rows there are. No DOM; its one piece of state is how many rows are rendered.
|
|
2118
|
+
*/
|
|
2119
|
+
function useOptionList(options) {
|
|
2120
|
+
const trimmedQuery = computed(() => options.searchable() ? options.query().trim() : "");
|
|
2121
|
+
const loading = computed(() => options.loading?.() === true);
|
|
2104
2122
|
/**
|
|
2105
|
-
* The
|
|
2106
|
-
*
|
|
2107
|
-
*
|
|
2108
|
-
* redirect rather than a trap — including the steps *within* the control, so a multi-select's
|
|
2109
|
-
* clear button is passed on the way in and returned to on the way back.
|
|
2110
|
-
*
|
|
2111
|
-
* It listens in the **capture** phase, before the control's own `keydown` reaches its handler:
|
|
2112
|
-
* `useListbox`'s `Tab` case asks the caller to close (the `SearchBar` does), and a popup that has
|
|
2113
|
-
* already closed has nothing left to walk into. Propagation is stopped only on the two keystrokes
|
|
2114
|
-
* actually redirected, so every other `Tab` arrives at the control untouched.
|
|
2123
|
+
* The options a query leaves, in the consumer's order. Not returned: every caller wants them
|
|
2124
|
+
* bucketed (`sections`) or in DOM order (`listOptions`), and a third view of the same list would
|
|
2125
|
+
* only be a way to disagree with those two.
|
|
2115
2126
|
*/
|
|
2116
|
-
|
|
2117
|
-
if (
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
const
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
event.stopPropagation();
|
|
2129
|
-
(last ?? trigger.value)?.focus();
|
|
2130
|
-
return;
|
|
2131
|
-
}
|
|
2132
|
-
if (panel.contains(active) || !overlay.isInside(active)) return;
|
|
2133
|
-
if (last !== void 0 && active !== last) return;
|
|
2134
|
-
event.preventDefault();
|
|
2135
|
-
event.stopPropagation();
|
|
2136
|
-
first.focus();
|
|
2137
|
-
}
|
|
2138
|
-
const attachTabRedirect = () => {
|
|
2139
|
-
if (typeof document === "undefined") return;
|
|
2140
|
-
document.addEventListener("keydown", onTabKeyDown, true);
|
|
2127
|
+
const visibleOptions = computed(() => {
|
|
2128
|
+
if (loading.value) return [];
|
|
2129
|
+
const trimmed = trimmedQuery.value;
|
|
2130
|
+
if (trimmed === "") return options.options();
|
|
2131
|
+
const needle = normalizeText(trimmed);
|
|
2132
|
+
return options.options().filter((option) => matchRange(option.label, trimmed) !== null || option.keywords?.some((keyword) => normalizeText(keyword).includes(needle)) === true);
|
|
2133
|
+
});
|
|
2134
|
+
/** Every visible option in DOM order, before the render batch cuts it. */
|
|
2135
|
+
const orderedOptions = computed(() => groupOptions(visibleOptions.value, "panel", options.controlId()).flatMap((section) => section.options));
|
|
2136
|
+
const batchSize = () => {
|
|
2137
|
+
const size = options.renderBatch?.();
|
|
2138
|
+
return size === void 0 || !(size >= 1) ? Number.POSITIVE_INFINITY : Math.floor(size);
|
|
2141
2139
|
};
|
|
2142
|
-
const
|
|
2143
|
-
|
|
2144
|
-
|
|
2140
|
+
const rendered = ref(batchSize());
|
|
2141
|
+
const resetBatch = () => {
|
|
2142
|
+
rendered.value = batchSize();
|
|
2145
2143
|
};
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
function releaseTrigger(event) {
|
|
2162
|
-
detachTriggerRelease();
|
|
2163
|
-
const target = event.target;
|
|
2164
|
-
if (target instanceof Node && trigger.value?.contains(target) === true) return;
|
|
2165
|
-
pressedTrigger = false;
|
|
2166
|
-
}
|
|
2167
|
-
function detachTriggerRelease() {
|
|
2168
|
-
if (typeof document === "undefined") return;
|
|
2169
|
-
document.removeEventListener("pointerup", releaseTrigger, true);
|
|
2170
|
-
document.removeEventListener("pointercancel", releaseTrigger, true);
|
|
2171
|
-
}
|
|
2172
|
-
function onTriggerPointerDown() {
|
|
2173
|
-
pressedTrigger = true;
|
|
2174
|
-
if (typeof document === "undefined") return;
|
|
2175
|
-
document.addEventListener("pointerup", releaseTrigger, true);
|
|
2176
|
-
document.addEventListener("pointercancel", releaseTrigger, true);
|
|
2177
|
-
}
|
|
2178
|
-
function onTriggerClick(event) {
|
|
2179
|
-
const fromPointer = pressedTrigger || event.detail > 0 || isProgrammaticClick(event, trigger.value);
|
|
2180
|
-
pressedTrigger = false;
|
|
2181
|
-
if (!canOpen()) return;
|
|
2182
|
-
if (!fromPointer) {
|
|
2183
|
-
trigger.value?.focus();
|
|
2184
|
-
return;
|
|
2185
|
-
}
|
|
2186
|
-
if (isOpen.value) close();
|
|
2187
|
-
else options.openFromPointer?.();
|
|
2188
|
-
}
|
|
2189
|
-
onBeforeUnmount(() => {
|
|
2190
|
-
unregisterOpen(closeFromRegistry);
|
|
2191
|
-
detachTriggerRelease();
|
|
2192
|
-
detachTabRedirect();
|
|
2193
|
-
});
|
|
2144
|
+
const renderMore = () => {
|
|
2145
|
+
if (rendered.value < orderedOptions.value.length) rendered.value += batchSize();
|
|
2146
|
+
};
|
|
2147
|
+
const reveal = (value) => {
|
|
2148
|
+
if (value === void 0 || !Number.isFinite(rendered.value)) return;
|
|
2149
|
+
const index = orderedOptions.value.findIndex((option) => option.value === value);
|
|
2150
|
+
if (index < rendered.value) return;
|
|
2151
|
+
const size = batchSize();
|
|
2152
|
+
rendered.value = Math.ceil((index + 1) / size) * size;
|
|
2153
|
+
};
|
|
2154
|
+
watch(trimmedQuery, resetBatch);
|
|
2155
|
+
watch(() => options.renderBatch?.(), resetBatch);
|
|
2156
|
+
const renderedOptions = computed(() => Number.isFinite(rendered.value) ? orderedOptions.value.slice(0, rendered.value) : orderedOptions.value);
|
|
2157
|
+
const sections = computed(() => groupOptions(renderedOptions.value, "panel", options.controlId()));
|
|
2158
|
+
const nativeSections = computed(() => groupOptions(options.options(), "native", options.controlId()));
|
|
2194
2159
|
/**
|
|
2195
|
-
*
|
|
2196
|
-
*
|
|
2197
|
-
*
|
|
2198
|
-
* animation class: see the composable's own comment above, and the keyframes in `tailwind.css`.
|
|
2199
|
-
*
|
|
2200
|
-
* Logical directions are deliberately not used. `transform-origin` takes physical keywords only
|
|
2201
|
-
* (`left`/`right`, never `inline-start`), and every panel in this package is `start`-aligned and
|
|
2202
|
-
* at least as wide as its control, so the horizontal half barely moves the result either way.
|
|
2160
|
+
* Spec-free addition: a query no option's label already equals can be offered as a new option.
|
|
2161
|
+
* Equal ignoring case and accents, the same comparison the search itself makes, so "Shirt" is
|
|
2162
|
+
* not offered beside an existing "shirt".
|
|
2203
2163
|
*/
|
|
2204
|
-
const
|
|
2205
|
-
|
|
2206
|
-
if (
|
|
2207
|
-
|
|
2164
|
+
const createOption = computed(() => {
|
|
2165
|
+
const trimmed = trimmedQuery.value;
|
|
2166
|
+
if (options.creatable?.() !== true || loading.value || trimmed === "") return void 0;
|
|
2167
|
+
const needle = normalizeText(trimmed);
|
|
2168
|
+
if (options.options().some((option) => normalizeText(option.label) === needle)) return;
|
|
2169
|
+
return {
|
|
2170
|
+
value: CREATE_VALUE,
|
|
2171
|
+
label: trimmed
|
|
2172
|
+
};
|
|
2208
2173
|
});
|
|
2174
|
+
const listOptions = computed(() => createOption.value === void 0 ? orderedOptions.value : [...orderedOptions.value, createOption.value]);
|
|
2209
2175
|
return {
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2176
|
+
sections,
|
|
2177
|
+
nativeSections,
|
|
2178
|
+
listOptions,
|
|
2179
|
+
hasOptions: computed(() => listOptions.value.length > 0),
|
|
2180
|
+
highlights: computed(() => {
|
|
2181
|
+
const trimmed = trimmedQuery.value;
|
|
2182
|
+
return new Map(renderedOptions.value.map((option) => {
|
|
2183
|
+
const range = trimmed === "" ? null : matchRange(option.label, trimmed);
|
|
2184
|
+
if (range === null) return [option.value, null];
|
|
2185
|
+
const characters = [...option.label];
|
|
2186
|
+
return [option.value, {
|
|
2187
|
+
before: characters.slice(0, range.start).join(""),
|
|
2188
|
+
match: characters.slice(range.start, range.end).join(""),
|
|
2189
|
+
after: characters.slice(range.end).join("")
|
|
2190
|
+
}];
|
|
2191
|
+
}));
|
|
2192
|
+
}),
|
|
2193
|
+
createOption,
|
|
2194
|
+
renderMore,
|
|
2195
|
+
reveal,
|
|
2196
|
+
resetBatch
|
|
2226
2197
|
};
|
|
2227
2198
|
}
|
|
2228
|
-
export {
|
|
2199
|
+
export { FIELD_KEY as $, ICON_STROKE_WIDTH as A, FIELD_LEADING_PAD as B, optionClass as C, optionSwatchClass as D, optionLabelClass as E, FIELD_CLEAR_BUTTON as F, FIELD_SEARCH_APPEARANCE as G, FIELD_PREFIX_PAD as H, FIELD_CLEAR_BUTTON_BOX as I, FIELD_SUFFIX_ROW_BASE as J, FIELD_SIZE as K, FIELD_CLEAR_SIZE as L, FIELD_ACTION_ROOM_REM as M, FIELD_BASE as N, panelClass as O, FIELD_BOX as P, fieldState as Q, FIELD_DISABLED as R, listboxClass as S, optionIconClass as T, FIELD_PREFIX_ROW as U, FIELD_LIVE as V, FIELD_RADIUS as W, FIELD_TRAILING_PAD as X, FIELD_TEXT as Y, FIELD_TRAILING_PAD_PAIR as Z, useFloating$1 as _, CURRENCY_KEY as a, TRIGGER_VALUE_CELL as b, provideEldraUiCurrency as c, useEldraUiLocale as d, mergeClass as et, Spinner_default as f, useTeleportTarget as g, topLayerDialog as h, SelectPanel_default as i, FIELD_ACTION_PAIR_SIZE as j, ICON_SIZE_CLASS as k, provideEldraUiLocale as l, useOverlay as m, matchRange as n, joinIds as nt, DEFAULT_UI_LOCALE as o, usePopover as p, FIELD_SUFFIX_ROW as q, useOptionList as r, useUiId as rt, LOCALE_KEY as s, CREATE_VALUE as t, useControllableModel as tt, useEldraUiCurrency as u, normalizeText as v, optionHintClass as w, TRIGGER_VALUE_STACK as x, useListbox as y, FIELD_LEADING_ICON as z };
|