@scalar/components 0.35.4 → 0.36.0
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/dist/components/ScalarButton/ScalarButton.vue_vue_type_script_setup_true_lang.js +8 -1
- package/dist/components/ScalarButton/ScalarButton.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/ScalarCard/ScalarCardHeader.vue.d.ts.map +1 -1
- package/dist/components/ScalarCard/ScalarCardHeader.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/components/ScalarCard/ScalarCardHeader.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/ScalarCodeBlock/ScalarCodeBlock.vue.d.ts +8 -0
- package/dist/components/ScalarCodeBlock/ScalarCodeBlock.vue.d.ts.map +1 -1
- package/dist/components/ScalarCodeBlock/ScalarCodeBlock.vue_vue_type_script_setup_true_lang.js +5 -1
- package/dist/components/ScalarCodeBlock/ScalarCodeBlock.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/ScalarCodeBlock/ScalarCodeBlockCopy.vue.d.ts.map +1 -1
- package/dist/components/ScalarCodeBlock/ScalarCodeBlockCopy.vue_vue_type_script_setup_true_lang.js +3 -4
- package/dist/components/ScalarCodeBlock/ScalarCodeBlockCopy.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/ScalarCodeBlock/constants.d.ts +2 -1
- package/dist/components/ScalarCodeBlock/constants.d.ts.map +1 -1
- package/dist/components/ScalarCodeBlock/constants.js +2 -1
- package/dist/components/ScalarCodeBlock/constants.js.map +1 -1
- package/dist/components/ScalarColorModeToggle/ScalarColorModeToggleIcon.vue_vue_type_script_setup_true_lang.js +8 -1
- package/dist/components/ScalarColorModeToggle/ScalarColorModeToggleIcon.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/ScalarCombobox/ScalarCombobox.vue_vue_type_script_setup_true_lang.js +5 -1
- package/dist/components/ScalarCombobox/ScalarCombobox.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/ScalarCombobox/ScalarComboboxMultiselect.vue_vue_type_script_setup_true_lang.js +5 -1
- package/dist/components/ScalarCombobox/ScalarComboboxMultiselect.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/ScalarCombobox/ScalarComboboxPopover.vue_vue_type_script_setup_true_lang.js +5 -1
- package/dist/components/ScalarCombobox/ScalarComboboxPopover.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/ScalarDialog/ScalarDialog.vue.d.ts +50 -0
- package/dist/components/ScalarDialog/ScalarDialog.vue.d.ts.map +1 -0
- package/dist/components/ScalarDialog/ScalarDialog.vue.js +6 -0
- package/dist/components/ScalarDialog/ScalarDialog.vue.js.map +1 -0
- package/dist/components/ScalarDialog/ScalarDialog.vue_vue_type_script_setup_true_lang.js +120 -0
- package/dist/components/ScalarDialog/ScalarDialog.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/ScalarDialog/index.d.ts +4 -0
- package/dist/components/ScalarDialog/index.d.ts.map +1 -0
- package/dist/components/ScalarDialog/index.js +1 -0
- package/dist/components/ScalarDialog/types.d.ts +15 -0
- package/dist/components/ScalarDialog/types.d.ts.map +1 -0
- package/dist/components/ScalarDialog/useBackdropClick.d.ts +46 -0
- package/dist/components/ScalarDialog/useBackdropClick.d.ts.map +1 -0
- package/dist/components/ScalarDialog/useBackdropClick.js +60 -0
- package/dist/components/ScalarDialog/useBackdropClick.js.map +1 -0
- package/dist/components/ScalarDialog/useScrollLock.d.ts +16 -0
- package/dist/components/ScalarDialog/useScrollLock.d.ts.map +1 -0
- package/dist/components/ScalarDialog/useScrollLock.js +70 -0
- package/dist/components/ScalarDialog/useScrollLock.js.map +1 -0
- package/dist/components/ScalarDropdown/ScalarDropdown.vue_vue_type_script_setup_true_lang.js +5 -1
- package/dist/components/ScalarDropdown/ScalarDropdown.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/ScalarDropdown/ScalarDropdownButton.vue_vue_type_script_setup_true_lang.js +8 -1
- package/dist/components/ScalarDropdown/ScalarDropdownButton.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/ScalarDropdown/ScalarDropdownMenu.vue_vue_type_script_setup_true_lang.js +5 -1
- package/dist/components/ScalarDropdown/ScalarDropdownMenu.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/ScalarFloating/ScalarFloating.vue_vue_type_script_setup_true_lang.js +5 -1
- package/dist/components/ScalarFloating/ScalarFloating.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/ScalarFloating/types.d.ts +3 -2
- package/dist/components/ScalarFloating/types.d.ts.map +1 -1
- package/dist/components/ScalarForm/ScalarFormError.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/components/ScalarForm/ScalarFormField.vue_vue_type_script_setup_true_lang.js +8 -1
- package/dist/components/ScalarForm/ScalarFormField.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/ScalarForm/ScalarFormInput.vue_vue_type_script_setup_true_lang.js +8 -1
- package/dist/components/ScalarForm/ScalarFormInput.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/ScalarForm/ScalarFormInputGroup.vue_vue_type_script_setup_true_lang.js +8 -1
- package/dist/components/ScalarForm/ScalarFormInputGroup.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/ScalarHeader/ScalarHeader.vue_vue_type_script_setup_true_lang.js +8 -1
- package/dist/components/ScalarHeader/ScalarHeader.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/ScalarHeader/ScalarHeaderButton.vue_vue_type_script_setup_true_lang.js +8 -1
- package/dist/components/ScalarHeader/ScalarHeaderButton.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/ScalarListbox/ScalarListbox.vue_vue_type_script_setup_true_lang.js +5 -1
- package/dist/components/ScalarListbox/ScalarListbox.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/ScalarMenu/ScalarMenuLink.vue_vue_type_script_setup_true_lang.js +8 -1
- package/dist/components/ScalarMenu/ScalarMenuLink.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/ScalarMenu/ScalarMenuProduct.vue_vue_type_script_setup_true_lang.js +8 -1
- package/dist/components/ScalarMenu/ScalarMenuProduct.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/ScalarPopover/ScalarPopover.vue_vue_type_script_setup_true_lang.js +5 -1
- package/dist/components/ScalarPopover/ScalarPopover.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/ScalarSidebar/ScalarSidebarButton.vue_vue_type_script_setup_true_lang.js +8 -1
- package/dist/components/ScalarSidebar/ScalarSidebarButton.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/ScalarSidebar/ScalarSidebarGroup.vue_vue_type_script_setup_true_lang.js +8 -1
- package/dist/components/ScalarSidebar/ScalarSidebarGroup.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/ScalarSidebar/ScalarSidebarGroupToggle.vue_vue_type_script_setup_true_lang.js +8 -1
- package/dist/components/ScalarSidebar/ScalarSidebarGroupToggle.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/ScalarSidebar/ScalarSidebarItem.vue_vue_type_script_setup_true_lang.js +5 -1
- package/dist/components/ScalarSidebar/ScalarSidebarItem.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/ScalarSidebar/ScalarSidebarItems.vue_vue_type_script_setup_true_lang.js +8 -1
- package/dist/components/ScalarSidebar/ScalarSidebarItems.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/ScalarSidebar/ScalarSidebarNestedItems.vue_vue_type_script_setup_true_lang.js +5 -1
- package/dist/components/ScalarSidebar/ScalarSidebarNestedItems.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/ScalarSidebar/ScalarSidebarSection.vue_vue_type_script_setup_true_lang.js +8 -1
- package/dist/components/ScalarSidebar/ScalarSidebarSection.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/ScalarVirtualCodeBlock/ScalarVirtualCodeBlock.vue.d.ts +4 -0
- package/dist/components/ScalarVirtualCodeBlock/ScalarVirtualCodeBlock.vue.d.ts.map +1 -1
- package/dist/components/ScalarVirtualCodeBlock/ScalarVirtualCodeBlock.vue_vue_type_script_setup_true_lang.js +6 -2
- package/dist/components/ScalarVirtualCodeBlock/ScalarVirtualCodeBlock.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/style.css +31 -4
- package/dist/vue-styles.css +1 -4
- package/package.json +20 -15
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import ScalarTeleportRoot_default from "../ScalarTeleport/ScalarTeleportRoot.vue.js";
|
|
2
|
+
import { useBackdropClick } from "./useBackdropClick.js";
|
|
3
|
+
import { useScrollLock } from "./useScrollLock.js";
|
|
4
|
+
import { cva, useBindCx } from "@scalar/use-hooks/useBindCx";
|
|
5
|
+
import { createBlock, createCommentVNode, createElementBlock, defineComponent, mergeModels, mergeProps, openBlock, ref, renderSlot, unref, useModel, watchPostEffect, withCtx, withKeys } from "vue";
|
|
6
|
+
var ScalarDialog_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
7
|
+
inheritAttrs: false,
|
|
8
|
+
__name: "ScalarDialog",
|
|
9
|
+
props: /*@__PURE__*/ mergeModels({ persist: {
|
|
10
|
+
type: Boolean,
|
|
11
|
+
default: false
|
|
12
|
+
} }, {
|
|
13
|
+
"open": {
|
|
14
|
+
type: Boolean,
|
|
15
|
+
default: false
|
|
16
|
+
},
|
|
17
|
+
"openModifiers": {}
|
|
18
|
+
}),
|
|
19
|
+
emits: /*@__PURE__*/ mergeModels(["close"], ["update:open"]),
|
|
20
|
+
setup(__props, { emit: __emit }) {
|
|
21
|
+
const emit = __emit;
|
|
22
|
+
/** Whether the dialog is open. Drives the native `showModal()` and `close()` calls. */
|
|
23
|
+
const open = useModel(__props, "open");
|
|
24
|
+
const dialog = cva({ base: [
|
|
25
|
+
"scalar-dialog m-auto rounded-lg border-0 p-3 shadow-lg",
|
|
26
|
+
"bg-b-1 text-c-1",
|
|
27
|
+
"backdrop:bg-backdrop dark:backdrop:bg-backdrop-dark",
|
|
28
|
+
"custom-scroll max-h-[85svh] w-[calc(100dvw-2rem)] max-w-md overflow-auto"
|
|
29
|
+
] });
|
|
30
|
+
const { cx } = useBindCx();
|
|
31
|
+
const dialogRef = ref(null);
|
|
32
|
+
const { lock, unlock } = useScrollLock();
|
|
33
|
+
/** Whether the dialog was open on the last run of the bridge, so `close` fires once per close. */
|
|
34
|
+
let wasOpen = false;
|
|
35
|
+
/**
|
|
36
|
+
* Puppet the native dialog from the reactive `open` model.
|
|
37
|
+
*
|
|
38
|
+
* `watchPostEffect` runs after the DOM updates, so the slotted content (and any
|
|
39
|
+
* `autofocus` target) is mounted before `showModal()` moves focus into it. The
|
|
40
|
+
* guards against `dialog.open` avoid the `InvalidStateError` the browser throws
|
|
41
|
+
* when `showModal()` is called on an already-open dialog.
|
|
42
|
+
*/
|
|
43
|
+
watchPostEffect(() => {
|
|
44
|
+
const element = dialogRef.value;
|
|
45
|
+
if (!element) return;
|
|
46
|
+
if (open.value) {
|
|
47
|
+
if (!element.open) element.showModal();
|
|
48
|
+
lock(element);
|
|
49
|
+
wasOpen = true;
|
|
50
|
+
} else {
|
|
51
|
+
if (element.open) element.close();
|
|
52
|
+
unlock();
|
|
53
|
+
if (wasOpen) emit("close");
|
|
54
|
+
wasOpen = false;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
/**
|
|
58
|
+
* Mirror native closes (a form submit, or the browser force-closing the dialog) back into the model.
|
|
59
|
+
*
|
|
60
|
+
* The `close` event is queued rather than fired synchronously, so when the dialog is closed and
|
|
61
|
+
* reopened in quick succession the event lands after it is open again. Ignoring it while the
|
|
62
|
+
* dialog is open keeps that stale event from closing it.
|
|
63
|
+
*/
|
|
64
|
+
const handleClose = () => {
|
|
65
|
+
if (dialogRef.value?.open) return;
|
|
66
|
+
open.value = false;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Close on Escape, unless something inside the dialog already handled it.
|
|
70
|
+
*
|
|
71
|
+
* Child widgets such as listboxes and comboboxes use Escape to close themselves and mark the event
|
|
72
|
+
* as handled, so the dialog leaves those alone. The same goes for Escape cancelling an IME
|
|
73
|
+
* composition, which should not also close the dialog. Stopping propagation means only the innermost of
|
|
74
|
+
* several nested dialogs closes. Preventing the default also stops a search input from clearing
|
|
75
|
+
* its value on the same keypress that dismisses the dialog.
|
|
76
|
+
*/
|
|
77
|
+
const handleEscape = (event) => {
|
|
78
|
+
if (event.defaultPrevented || event.isComposing) return;
|
|
79
|
+
event.preventDefault();
|
|
80
|
+
event.stopPropagation();
|
|
81
|
+
open.value = false;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Route other close requests, such as the Android back gesture, through the model.
|
|
85
|
+
*
|
|
86
|
+
* The browser would otherwise close the dialog itself. Going through `open` keeps every close on
|
|
87
|
+
* the same path, so the scroll lock is released and the contents unmount in step.
|
|
88
|
+
*/
|
|
89
|
+
const handleCancel = (event) => {
|
|
90
|
+
event.preventDefault();
|
|
91
|
+
open.value = false;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Close when the backdrop is clicked. The composable ignores text-selection drags
|
|
95
|
+
* and keyboard-activated controls; setting `open` to false lets the puppet bridge
|
|
96
|
+
* run the native `close()` so the flow matches Escape and programmatic closes.
|
|
97
|
+
*/
|
|
98
|
+
const { handlePointerDown, handleClick } = useBackdropClick(dialogRef, () => {
|
|
99
|
+
open.value = false;
|
|
100
|
+
});
|
|
101
|
+
return (_ctx, _cache) => {
|
|
102
|
+
return openBlock(), createElementBlock("dialog", mergeProps({
|
|
103
|
+
ref_key: "dialogRef",
|
|
104
|
+
ref: dialogRef
|
|
105
|
+
}, unref(cx)(unref(dialog)()), {
|
|
106
|
+
onCancel: handleCancel,
|
|
107
|
+
onClick: _cache[0] || (_cache[0] = (...args) => unref(handleClick) && unref(handleClick)(...args)),
|
|
108
|
+
onClose: handleClose,
|
|
109
|
+
onKeydown: withKeys(handleEscape, ["esc"]),
|
|
110
|
+
onPointerdown: _cache[1] || (_cache[1] = (...args) => unref(handlePointerDown) && unref(handlePointerDown)(...args))
|
|
111
|
+
}), [__props.persist || open.value ? (openBlock(), createBlock(unref(ScalarTeleportRoot_default), { key: 0 }, {
|
|
112
|
+
default: withCtx(() => [renderSlot(_ctx.$slots, "default")]),
|
|
113
|
+
_: 3
|
|
114
|
+
})) : createCommentVNode("", true)], 16);
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
export { ScalarDialog_vue_vue_type_script_setup_true_lang_default as default };
|
|
119
|
+
|
|
120
|
+
//# sourceMappingURL=ScalarDialog.vue_vue_type_script_setup_true_lang.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScalarDialog.vue_vue_type_script_setup_true_lang.js","names":["_useModel","_openBlock","_createElementBlock","_mergeProps","_unref","_withKeys","_createBlock","ScalarTeleportRoot","_withCtx","_renderSlot"],"sources":["../../../src/components/ScalarDialog/ScalarDialog.vue"],"sourcesContent":["<script lang=\"ts\">\n/**\n * Scalar Dialog\n *\n * A modal dialog built on the native `<dialog>` element. It calls `showModal()`\n * under the hood, so the dialog is promoted to the browser top layer (escaping\n * ancestor stacking, overflow, and transform contexts), traps and restores focus,\n * makes the rest of the page inert, and closes on Escape — all natively, with no\n * teleport. It also locks page scrolling while open, and gives popovers inside it a\n * teleport target within the dialog so they render above it rather than under the\n * top layer.\n *\n * Control it with `v-model:open` and compose the contents with the default slot.\n * Restyle or resize it by passing your own `class`; the defaults are intentionally\n * minimal so consumers compose rather than configure.\n *\n * Give the dialog an accessible name, ideally by pointing `aria-labelledby` at its\n * visible heading so screen readers announce the same title sighted users see.\n *\n * @example\n * <ScalarDialog v-model:open=\"open\">\n * <h2>Title</h2>\n * <p>Some content</p>\n * </ScalarDialog>\n */\nexport default {}\n</script>\n\n<script setup lang=\"ts\">\nimport { cva, useBindCx } from '@scalar/use-hooks/useBindCx'\nimport { ref, watchPostEffect } from 'vue'\n\nimport { ScalarTeleportRoot } from '../ScalarTeleport'\nimport type { ScalarDialogProps } from './types'\nimport { useBackdropClick } from './useBackdropClick'\nimport { useScrollLock } from './useScrollLock'\n\nconst { persist = false } = defineProps<ScalarDialogProps>()\n\nconst emit = defineEmits<{\n /** Emitted whenever the dialog closes, whether via Escape, a backdrop click, or `open` being set to false. */\n (e: 'close'): void\n}>()\n\ndefineSlots<{\n /** The dialog contents. Compose your own header, body, and footer here. */\n default(): unknown\n}>()\n\n/** Whether the dialog is open. Drives the native `showModal()` and `close()` calls. */\nconst open = defineModel<boolean>('open', { default: false })\n\nconst dialog = cva({\n base: [\n // Reset the native dialog chrome and center it within the top layer\n 'scalar-dialog m-auto rounded-lg border-0 p-3 shadow-lg',\n // Surface colors\n 'bg-b-1 text-c-1',\n // Theme the native ::backdrop via Tailwind's backdrop variant\n 'backdrop:bg-backdrop dark:backdrop:bg-backdrop-dark',\n // Constrain the size and let long content scroll\n 'custom-scroll max-h-[85svh] w-[calc(100dvw-2rem)] max-w-md overflow-auto',\n ],\n})\n\ndefineOptions({ inheritAttrs: false })\nconst { cx } = useBindCx()\n\nconst dialogRef = ref<HTMLDialogElement | null>(null)\n\nconst { lock, unlock } = useScrollLock()\n\n/** Whether the dialog was open on the last run of the bridge, so `close` fires once per close. */\nlet wasOpen = false\n\n/**\n * Puppet the native dialog from the reactive `open` model.\n *\n * `watchPostEffect` runs after the DOM updates, so the slotted content (and any\n * `autofocus` target) is mounted before `showModal()` moves focus into it. The\n * guards against `dialog.open` avoid the `InvalidStateError` the browser throws\n * when `showModal()` is called on an already-open dialog.\n */\nwatchPostEffect(() => {\n const element = dialogRef.value\n if (!element) {\n return\n }\n\n if (open.value) {\n if (!element.open) {\n element.showModal()\n }\n lock(element)\n wasOpen = true\n } else {\n if (element.open) {\n element.close()\n }\n unlock()\n // Emit here rather than from the native `close` event, which is queued and never\n // arrives if the dialog is reopened before it fires\n if (wasOpen) {\n emit('close')\n }\n wasOpen = false\n }\n})\n\n/**\n * Mirror native closes (a form submit, or the browser force-closing the dialog) back into the model.\n *\n * The `close` event is queued rather than fired synchronously, so when the dialog is closed and\n * reopened in quick succession the event lands after it is open again. Ignoring it while the\n * dialog is open keeps that stale event from closing it.\n */\nconst handleClose = (): void => {\n if (dialogRef.value?.open) {\n return\n }\n open.value = false\n}\n\n/**\n * Close on Escape, unless something inside the dialog already handled it.\n *\n * Child widgets such as listboxes and comboboxes use Escape to close themselves and mark the event\n * as handled, so the dialog leaves those alone. The same goes for Escape cancelling an IME\n * composition, which should not also close the dialog. Stopping propagation means only the innermost of\n * several nested dialogs closes. Preventing the default also stops a search input from clearing\n * its value on the same keypress that dismisses the dialog.\n */\nconst handleEscape = (event: KeyboardEvent): void => {\n if (event.defaultPrevented || event.isComposing) {\n return\n }\n event.preventDefault()\n event.stopPropagation()\n open.value = false\n}\n\n/**\n * Route other close requests, such as the Android back gesture, through the model.\n *\n * The browser would otherwise close the dialog itself. Going through `open` keeps every close on\n * the same path, so the scroll lock is released and the contents unmount in step.\n */\nconst handleCancel = (event: Event): void => {\n event.preventDefault()\n open.value = false\n}\n\n/**\n * Close when the backdrop is clicked. The composable ignores text-selection drags\n * and keyboard-activated controls; setting `open` to false lets the puppet bridge\n * run the native `close()` so the flow matches Escape and programmatic closes.\n */\nconst { handlePointerDown, handleClick } = useBackdropClick(dialogRef, () => {\n open.value = false\n})\n</script>\n\n<template>\n <dialog\n ref=\"dialogRef\"\n v-bind=\"cx(dialog())\"\n @cancel=\"handleCancel\"\n @click=\"handleClick\"\n @close=\"handleClose\"\n @keydown.esc=\"handleEscape\"\n @pointerdown=\"handlePointerDown\">\n <ScalarTeleportRoot v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MAAA,WAAA,KAAAA,MAAA,WAAA,CAAA,CAAA,GAAA,IAAA;IACP,SAAO;IACP,WAAOC,SAAM,cAAY,CAAA,KAAA,CAAA;IACzB,eAAW,OAAA,OAAA,OAAA,MAAE,GAAA,SAAAD,MAAA,iBAAA,KAAAA,MAAA,iBAAA,CAAA,CAAA,GAAA,IAAA;G,KACY,QAAA,WAAW,KAAA,SAArCH,UAAA,GAAAK,YAEqBF,MAAAG,0BAAA,GAAA,EAAA,KAAA,EAAA,GAAA;IADnB,SAAAC,cAAQ,CAARC,WAAQ,KAAA,QAAA,SAAA,C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarDialog/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAE5D,YAAY,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as ScalarDialog } from "./ScalarDialog.vue.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Props for the ScalarDialog component */
|
|
2
|
+
export type ScalarDialogProps = {
|
|
3
|
+
/**
|
|
4
|
+
* Keeps the dialog contents mounted while it is closed.
|
|
5
|
+
*
|
|
6
|
+
* By default the contents are torn down on close, so child components mount
|
|
7
|
+
* fresh on each open and their lifecycle hooks fire in step with the dialog's
|
|
8
|
+
* open state. Set this to keep the contents mounted and preserve their state
|
|
9
|
+
* across open and close.
|
|
10
|
+
*
|
|
11
|
+
* @default false
|
|
12
|
+
*/
|
|
13
|
+
persist?: boolean;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarDialog/types.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;;;;;;;OASG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Ref } from 'vue';
|
|
2
|
+
/** The pointer coordinates we compare against the dialog's box. */
|
|
3
|
+
type PointerPosition = Pick<MouseEvent, 'clientX' | 'clientY'>;
|
|
4
|
+
/** A rectangle we can test a pointer position against (a subset of `DOMRect`). */
|
|
5
|
+
type Box = Pick<DOMRect, 'top' | 'right' | 'bottom' | 'left'>;
|
|
6
|
+
/**
|
|
7
|
+
* Whether a pointer position falls outside a box.
|
|
8
|
+
*
|
|
9
|
+
* A native `<dialog>` renders its `::backdrop` as part of the dialog element, so a
|
|
10
|
+
* click on the backdrop targets the dialog itself. That is why `onClickOutside` (and
|
|
11
|
+
* any "is the event target inside my element" check) cannot detect a backdrop click —
|
|
12
|
+
* the target is the dialog. Comparing the pointer position against the dialog's box is
|
|
13
|
+
* the reliable way to tell a backdrop click from a click on the dialog surface. The box
|
|
14
|
+
* comes from `getBoundingClientRect()`, so it already includes padding and border: a
|
|
15
|
+
* click in the dialog's padding counts as inside and keeps the dialog open.
|
|
16
|
+
*/
|
|
17
|
+
export declare const isPointerOutsideBox: ({ clientX, clientY }: PointerPosition, { top, right, bottom, left }: Box) => boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Dismiss a native `<dialog>` when the backdrop is clicked.
|
|
20
|
+
*
|
|
21
|
+
* Returns `pointerdown` and `click` handlers to bind on the `<dialog>`. A click only
|
|
22
|
+
* counts as a backdrop dismissal when the pointer was both pressed and released on the
|
|
23
|
+
* backdrop, which avoids two failure modes a naive click-position check has:
|
|
24
|
+
*
|
|
25
|
+
* - **Text-selection drags** — pressing inside the dialog, dragging to select text, and
|
|
26
|
+
* releasing outside would otherwise fire a `click` with outside coordinates and close
|
|
27
|
+
* the dialog. Requiring the press to also be outside keeps it open.
|
|
28
|
+
* - **Keyboard-activated controls** — pressing Enter or Space on a focused button
|
|
29
|
+
* dispatches a synthetic `click` with `detail === 0` and coordinates of `(0, 0)`, which
|
|
30
|
+
* sit outside the centered dialog. Ignoring `detail === 0` clicks keeps the dialog open
|
|
31
|
+
* when a control inside it is used from the keyboard.
|
|
32
|
+
*
|
|
33
|
+
* Both events must also target the dialog itself. A backdrop click always does, while a
|
|
34
|
+
* click that bubbles up from a descendant does not, even when its position falls outside
|
|
35
|
+
* the box: a nested dialog's backdrop, a wider nested dialog, or a popover that overflows
|
|
36
|
+
* the dialog edge. Without that check those clicks would close the outer dialog too.
|
|
37
|
+
*
|
|
38
|
+
* @param dialogRef - Template ref to the native `<dialog>` element.
|
|
39
|
+
* @param onDismiss - Called when a genuine backdrop click is detected.
|
|
40
|
+
*/
|
|
41
|
+
export declare const useBackdropClick: (dialogRef: Ref<HTMLDialogElement | null>, onDismiss: () => void) => {
|
|
42
|
+
handlePointerDown: (event: PointerEvent) => void;
|
|
43
|
+
handleClick: (event: MouseEvent) => void;
|
|
44
|
+
};
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=useBackdropClick.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBackdropClick.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarDialog/useBackdropClick.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAE9B,mEAAmE;AACnE,KAAK,eAAe,GAAG,IAAI,CAAC,UAAU,EAAE,SAAS,GAAG,SAAS,CAAC,CAAA;AAE9D,kFAAkF;AAClF,KAAK,GAAG,GAAG,IAAI,CAAC,OAAO,EAAE,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC,CAAA;AAE7D;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,GAC9B,sBAAsB,eAAe,EACrC,8BAA8B,GAAG,KAChC,OAAiF,CAAA;AAMpF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,gBAAgB,GAC3B,WAAW,GAAG,CAAC,iBAAiB,GAAG,IAAI,CAAC,EACxC,WAAW,MAAM,IAAI,KACpB;IACD,iBAAiB,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAA;IAChD,WAAW,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAA;CA4BzC,CAAA"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// src/components/ScalarDialog/useBackdropClick.ts
|
|
2
|
+
/**
|
|
3
|
+
* Whether a pointer position falls outside a box.
|
|
4
|
+
*
|
|
5
|
+
* A native `<dialog>` renders its `::backdrop` as part of the dialog element, so a
|
|
6
|
+
* click on the backdrop targets the dialog itself. That is why `onClickOutside` (and
|
|
7
|
+
* any "is the event target inside my element" check) cannot detect a backdrop click —
|
|
8
|
+
* the target is the dialog. Comparing the pointer position against the dialog's box is
|
|
9
|
+
* the reliable way to tell a backdrop click from a click on the dialog surface. The box
|
|
10
|
+
* comes from `getBoundingClientRect()`, so it already includes padding and border: a
|
|
11
|
+
* click in the dialog's padding counts as inside and keeps the dialog open.
|
|
12
|
+
*/
|
|
13
|
+
var isPointerOutsideBox = ({ clientX, clientY }, { top, right, bottom, left }) => clientX < left || clientX > right || clientY < top || clientY > bottom;
|
|
14
|
+
/** Whether an event landed on this dialog's own backdrop, rather than bubbling up from inside it. */
|
|
15
|
+
var isOnBackdrop = (event, element) => event.target === event.currentTarget && isPointerOutsideBox(event, element.getBoundingClientRect());
|
|
16
|
+
/**
|
|
17
|
+
* Dismiss a native `<dialog>` when the backdrop is clicked.
|
|
18
|
+
*
|
|
19
|
+
* Returns `pointerdown` and `click` handlers to bind on the `<dialog>`. A click only
|
|
20
|
+
* counts as a backdrop dismissal when the pointer was both pressed and released on the
|
|
21
|
+
* backdrop, which avoids two failure modes a naive click-position check has:
|
|
22
|
+
*
|
|
23
|
+
* - **Text-selection drags** — pressing inside the dialog, dragging to select text, and
|
|
24
|
+
* releasing outside would otherwise fire a `click` with outside coordinates and close
|
|
25
|
+
* the dialog. Requiring the press to also be outside keeps it open.
|
|
26
|
+
* - **Keyboard-activated controls** — pressing Enter or Space on a focused button
|
|
27
|
+
* dispatches a synthetic `click` with `detail === 0` and coordinates of `(0, 0)`, which
|
|
28
|
+
* sit outside the centered dialog. Ignoring `detail === 0` clicks keeps the dialog open
|
|
29
|
+
* when a control inside it is used from the keyboard.
|
|
30
|
+
*
|
|
31
|
+
* Both events must also target the dialog itself. A backdrop click always does, while a
|
|
32
|
+
* click that bubbles up from a descendant does not, even when its position falls outside
|
|
33
|
+
* the box: a nested dialog's backdrop, a wider nested dialog, or a popover that overflows
|
|
34
|
+
* the dialog edge. Without that check those clicks would close the outer dialog too.
|
|
35
|
+
*
|
|
36
|
+
* @param dialogRef - Template ref to the native `<dialog>` element.
|
|
37
|
+
* @param onDismiss - Called when a genuine backdrop click is detected.
|
|
38
|
+
*/
|
|
39
|
+
var useBackdropClick = (dialogRef, onDismiss) => {
|
|
40
|
+
/** Whether the most recent primary press landed on the backdrop. */
|
|
41
|
+
let pressedOnBackdrop = false;
|
|
42
|
+
const handlePointerDown = (event) => {
|
|
43
|
+
const element = dialogRef.value;
|
|
44
|
+
pressedOnBackdrop = event.button === 0 && !!element && isOnBackdrop(event, element);
|
|
45
|
+
};
|
|
46
|
+
const handleClick = (event) => {
|
|
47
|
+
const element = dialogRef.value;
|
|
48
|
+
const pressed = pressedOnBackdrop;
|
|
49
|
+
pressedOnBackdrop = false;
|
|
50
|
+
if (!element || event.detail === 0) return;
|
|
51
|
+
if (pressed && isOnBackdrop(event, element)) onDismiss();
|
|
52
|
+
};
|
|
53
|
+
return {
|
|
54
|
+
handlePointerDown,
|
|
55
|
+
handleClick
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
export { isPointerOutsideBox, useBackdropClick };
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=useBackdropClick.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBackdropClick.js","names":[],"sources":["../../../src/components/ScalarDialog/useBackdropClick.ts"],"sourcesContent":["import type { Ref } from 'vue'\n\n/** The pointer coordinates we compare against the dialog's box. */\ntype PointerPosition = Pick<MouseEvent, 'clientX' | 'clientY'>\n\n/** A rectangle we can test a pointer position against (a subset of `DOMRect`). */\ntype Box = Pick<DOMRect, 'top' | 'right' | 'bottom' | 'left'>\n\n/**\n * Whether a pointer position falls outside a box.\n *\n * A native `<dialog>` renders its `::backdrop` as part of the dialog element, so a\n * click on the backdrop targets the dialog itself. That is why `onClickOutside` (and\n * any \"is the event target inside my element\" check) cannot detect a backdrop click —\n * the target is the dialog. Comparing the pointer position against the dialog's box is\n * the reliable way to tell a backdrop click from a click on the dialog surface. The box\n * comes from `getBoundingClientRect()`, so it already includes padding and border: a\n * click in the dialog's padding counts as inside and keeps the dialog open.\n */\nexport const isPointerOutsideBox = (\n { clientX, clientY }: PointerPosition,\n { top, right, bottom, left }: Box,\n): boolean => clientX < left || clientX > right || clientY < top || clientY > bottom\n\n/** Whether an event landed on this dialog's own backdrop, rather than bubbling up from inside it. */\nconst isOnBackdrop = (event: MouseEvent, element: HTMLDialogElement): boolean =>\n event.target === event.currentTarget && isPointerOutsideBox(event, element.getBoundingClientRect())\n\n/**\n * Dismiss a native `<dialog>` when the backdrop is clicked.\n *\n * Returns `pointerdown` and `click` handlers to bind on the `<dialog>`. A click only\n * counts as a backdrop dismissal when the pointer was both pressed and released on the\n * backdrop, which avoids two failure modes a naive click-position check has:\n *\n * - **Text-selection drags** — pressing inside the dialog, dragging to select text, and\n * releasing outside would otherwise fire a `click` with outside coordinates and close\n * the dialog. Requiring the press to also be outside keeps it open.\n * - **Keyboard-activated controls** — pressing Enter or Space on a focused button\n * dispatches a synthetic `click` with `detail === 0` and coordinates of `(0, 0)`, which\n * sit outside the centered dialog. Ignoring `detail === 0` clicks keeps the dialog open\n * when a control inside it is used from the keyboard.\n *\n * Both events must also target the dialog itself. A backdrop click always does, while a\n * click that bubbles up from a descendant does not, even when its position falls outside\n * the box: a nested dialog's backdrop, a wider nested dialog, or a popover that overflows\n * the dialog edge. Without that check those clicks would close the outer dialog too.\n *\n * @param dialogRef - Template ref to the native `<dialog>` element.\n * @param onDismiss - Called when a genuine backdrop click is detected.\n */\nexport const useBackdropClick = (\n dialogRef: Ref<HTMLDialogElement | null>,\n onDismiss: () => void,\n): {\n handlePointerDown: (event: PointerEvent) => void\n handleClick: (event: MouseEvent) => void\n} => {\n /** Whether the most recent primary press landed on the backdrop. */\n let pressedOnBackdrop = false\n\n const handlePointerDown = (event: PointerEvent): void => {\n const element = dialogRef.value\n // Only the primary (left) button can lead to a `click`, so ignore the rest.\n pressedOnBackdrop = event.button === 0 && !!element && isOnBackdrop(event, element)\n }\n\n const handleClick = (event: MouseEvent): void => {\n const element = dialogRef.value\n const pressed = pressedOnBackdrop\n // Reset for the next interaction before any early return.\n pressedOnBackdrop = false\n\n // Ignore keyboard-synthesized clicks: they report `detail === 0` and `(0, 0)`.\n if (!element || event.detail === 0) {\n return\n }\n\n if (pressed && isOnBackdrop(event, element)) {\n onDismiss()\n }\n }\n\n return { handlePointerDown, handleClick }\n}\n"],"mappings":";;;;;;;;;;;;AAmBA,IAAa,uBACX,EAAE,SAAS,WACX,EAAE,KAAK,OAAO,QAAQ,WACV,UAAU,QAAQ,UAAU,SAAS,UAAU,OAAO,UAAU;;AAG9E,IAAM,gBAAgB,OAAmB,YACvC,MAAM,WAAW,MAAM,iBAAiB,oBAAoB,OAAO,QAAQ,sBAAsB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;AAyBpG,IAAa,oBACX,WACA,cAIG;;CAEH,IAAI,oBAAoB;CAExB,MAAM,qBAAqB,UAA8B;EACvD,MAAM,UAAU,UAAU;EAE1B,oBAAoB,MAAM,WAAW,KAAK,CAAC,CAAC,WAAW,aAAa,OAAO,OAAO;CACpF;CAEA,MAAM,eAAe,UAA4B;EAC/C,MAAM,UAAU,UAAU;EAC1B,MAAM,UAAU;EAEhB,oBAAoB;EAGpB,IAAI,CAAC,WAAW,MAAM,WAAW,GAC/B;EAGF,IAAI,WAAW,aAAa,OAAO,OAAO,GACxC,UAAU;CAEd;CAEA,OAAO;EAAE;EAAmB;CAAY;AAC1C"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lock scrolling on the document behind a modal.
|
|
3
|
+
*
|
|
4
|
+
* A native `<dialog>` makes the page inert but does not stop it scrolling, so a wheel or touch
|
|
5
|
+
* gesture over the backdrop would scroll the content underneath. This sets `overflow: hidden` on
|
|
6
|
+
* the document element and pads it by the scrollbar width, so the page does not shift sideways when
|
|
7
|
+
* its scrollbar disappears. The lock is released automatically when the calling scope is disposed.
|
|
8
|
+
*
|
|
9
|
+
* @returns `lock` to take the lock for a given element's document and `unlock` to release it.
|
|
10
|
+
* Both are idempotent, so calling either twice in a row is safe.
|
|
11
|
+
*/
|
|
12
|
+
export declare const useScrollLock: () => {
|
|
13
|
+
lock: (element: Element) => void;
|
|
14
|
+
unlock: () => void;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=useScrollLock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useScrollLock.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarDialog/useScrollLock.ts"],"names":[],"mappings":"AAoBA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,QAAO;IAC/B,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;IAChC,MAAM,EAAE,MAAM,IAAI,CAAA;CA0DnB,CAAA"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { onScopeDispose } from "vue";
|
|
2
|
+
// src/components/ScalarDialog/useScrollLock.ts
|
|
3
|
+
/**
|
|
4
|
+
* Active locks, keyed by the root element they lock.
|
|
5
|
+
*
|
|
6
|
+
* Keyed per root rather than global because a dialog inside an iframe locks that iframe's own
|
|
7
|
+
* document. A dialog in a shadow root shares its host's document, so it locks the page. The count lets nested and stacked dialogs share one lock, so closing the inner dialog
|
|
8
|
+
* does not unlock the page while the outer one is still open.
|
|
9
|
+
*/
|
|
10
|
+
var locks = /* @__PURE__ */ new WeakMap();
|
|
11
|
+
/**
|
|
12
|
+
* Lock scrolling on the document behind a modal.
|
|
13
|
+
*
|
|
14
|
+
* A native `<dialog>` makes the page inert but does not stop it scrolling, so a wheel or touch
|
|
15
|
+
* gesture over the backdrop would scroll the content underneath. This sets `overflow: hidden` on
|
|
16
|
+
* the document element and pads it by the scrollbar width, so the page does not shift sideways when
|
|
17
|
+
* its scrollbar disappears. The lock is released automatically when the calling scope is disposed.
|
|
18
|
+
*
|
|
19
|
+
* @returns `lock` to take the lock for a given element's document and `unlock` to release it.
|
|
20
|
+
* Both are idempotent, so calling either twice in a row is safe.
|
|
21
|
+
*/
|
|
22
|
+
var useScrollLock = () => {
|
|
23
|
+
/** The root this instance currently holds a lock on, if any. */
|
|
24
|
+
let lockedRoot;
|
|
25
|
+
const lock = (element) => {
|
|
26
|
+
if (lockedRoot) return;
|
|
27
|
+
const root = element.ownerDocument.documentElement;
|
|
28
|
+
const view = element.ownerDocument.defaultView;
|
|
29
|
+
lockedRoot = root;
|
|
30
|
+
const existing = locks.get(root);
|
|
31
|
+
if (existing) {
|
|
32
|
+
existing.count++;
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const scrollbarWidth = view ? view.innerWidth - root.clientWidth : 0;
|
|
36
|
+
const paddingRight = view ? Number.parseFloat(view.getComputedStyle(root).paddingRight) || 0 : 0;
|
|
37
|
+
locks.set(root, {
|
|
38
|
+
count: 1,
|
|
39
|
+
overflow: root.style.getPropertyValue("overflow"),
|
|
40
|
+
overflowPriority: root.style.getPropertyPriority("overflow"),
|
|
41
|
+
paddingRight: root.style.getPropertyValue("padding-right"),
|
|
42
|
+
paddingRightPriority: root.style.getPropertyPriority("padding-right")
|
|
43
|
+
});
|
|
44
|
+
root.style.setProperty("overflow", "hidden");
|
|
45
|
+
if (scrollbarWidth > 0) root.style.setProperty("padding-right", `${paddingRight + scrollbarWidth}px`);
|
|
46
|
+
};
|
|
47
|
+
const unlock = () => {
|
|
48
|
+
const root = lockedRoot;
|
|
49
|
+
if (!root) return;
|
|
50
|
+
lockedRoot = void 0;
|
|
51
|
+
const saved = locks.get(root);
|
|
52
|
+
if (!saved || --saved.count > 0) return;
|
|
53
|
+
locks.delete(root);
|
|
54
|
+
restore(root, "overflow", saved.overflow, saved.overflowPriority);
|
|
55
|
+
restore(root, "padding-right", saved.paddingRight, saved.paddingRightPriority);
|
|
56
|
+
};
|
|
57
|
+
onScopeDispose(unlock);
|
|
58
|
+
return {
|
|
59
|
+
lock,
|
|
60
|
+
unlock
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
/** Put an inline style back the way it was, removing it if it was not set before. */
|
|
64
|
+
var restore = (element, property, value, priority) => {
|
|
65
|
+
if (value) element.style.setProperty(property, value, priority);
|
|
66
|
+
else element.style.removeProperty(property);
|
|
67
|
+
};
|
|
68
|
+
export { useScrollLock };
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=useScrollLock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useScrollLock.js","names":[],"sources":["../../../src/components/ScalarDialog/useScrollLock.ts"],"sourcesContent":["import { onScopeDispose } from 'vue'\n\n/** The inline styles a lock overrides, saved so the last release can put them back. */\ntype SavedStyles = {\n count: number\n overflow: string\n overflowPriority: string\n paddingRight: string\n paddingRightPriority: string\n}\n\n/**\n * Active locks, keyed by the root element they lock.\n *\n * Keyed per root rather than global because a dialog inside an iframe locks that iframe's own\n * document. A dialog in a shadow root shares its host's document, so it locks the page. The count lets nested and stacked dialogs share one lock, so closing the inner dialog\n * does not unlock the page while the outer one is still open.\n */\nconst locks = new WeakMap<HTMLElement, SavedStyles>()\n\n/**\n * Lock scrolling on the document behind a modal.\n *\n * A native `<dialog>` makes the page inert but does not stop it scrolling, so a wheel or touch\n * gesture over the backdrop would scroll the content underneath. This sets `overflow: hidden` on\n * the document element and pads it by the scrollbar width, so the page does not shift sideways when\n * its scrollbar disappears. The lock is released automatically when the calling scope is disposed.\n *\n * @returns `lock` to take the lock for a given element's document and `unlock` to release it.\n * Both are idempotent, so calling either twice in a row is safe.\n */\nexport const useScrollLock = (): {\n lock: (element: Element) => void\n unlock: () => void\n} => {\n /** The root this instance currently holds a lock on, if any. */\n let lockedRoot: HTMLElement | undefined\n\n const lock = (element: Element): void => {\n if (lockedRoot) {\n return\n }\n\n const root = element.ownerDocument.documentElement\n const view = element.ownerDocument.defaultView\n lockedRoot = root\n\n const existing = locks.get(root)\n if (existing) {\n existing.count++\n return\n }\n\n // Measure before hiding the overflow, since hiding it is what removes the scrollbar\n const scrollbarWidth = view ? view.innerWidth - root.clientWidth : 0\n const paddingRight = view ? Number.parseFloat(view.getComputedStyle(root).paddingRight) || 0 : 0\n\n locks.set(root, {\n count: 1,\n overflow: root.style.getPropertyValue('overflow'),\n overflowPriority: root.style.getPropertyPriority('overflow'),\n paddingRight: root.style.getPropertyValue('padding-right'),\n paddingRightPriority: root.style.getPropertyPriority('padding-right'),\n })\n\n root.style.setProperty('overflow', 'hidden')\n if (scrollbarWidth > 0) {\n root.style.setProperty('padding-right', `${paddingRight + scrollbarWidth}px`)\n }\n }\n\n const unlock = (): void => {\n const root = lockedRoot\n if (!root) {\n return\n }\n lockedRoot = undefined\n\n const saved = locks.get(root)\n if (!saved || --saved.count > 0) {\n return\n }\n locks.delete(root)\n\n restore(root, 'overflow', saved.overflow, saved.overflowPriority)\n restore(root, 'padding-right', saved.paddingRight, saved.paddingRightPriority)\n }\n\n onScopeDispose(unlock)\n\n return { lock, unlock }\n}\n\n/** Put an inline style back the way it was, removing it if it was not set before. */\nconst restore = (element: HTMLElement, property: string, value: string, priority: string): void => {\n if (value) {\n element.style.setProperty(property, value, priority)\n } else {\n element.style.removeProperty(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;MAEnD,QAAQ,MAAM,eAAe,QAAQ;AAEzC"}
|
package/dist/components/ScalarDropdown/ScalarDropdown.vue_vue_type_script_setup_true_lang.js
CHANGED
|
@@ -22,7 +22,11 @@ var ScalarDropdown_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
|
|
|
22
22
|
Function
|
|
23
23
|
] },
|
|
24
24
|
resize: { type: Boolean },
|
|
25
|
-
target: {
|
|
25
|
+
target: { type: [
|
|
26
|
+
String,
|
|
27
|
+
Object,
|
|
28
|
+
Function
|
|
29
|
+
] },
|
|
26
30
|
middleware: {},
|
|
27
31
|
teleport: { type: [Boolean, String] }
|
|
28
32
|
}, {
|
package/dist/components/ScalarDropdown/ScalarDropdown.vue_vue_type_script_setup_true_lang.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScalarDropdown.vue_vue_type_script_setup_true_lang.js","names":["$props","_useModel","_openBlock","_createBlock","_unref","ScalarFloating","_mergeProps","_withCtx","_renderSlot","_createVNode","ScalarDropdownMenu","_createElementVNode","_withModifiers","_withKeys"],"sources":["../../../src/components/ScalarDropdown/ScalarDropdown.vue"],"sourcesContent":["<script lang=\"ts\">\n/**\n * Scalar dropdown component\n *\n * @example\n * <ScalarDropdown>\n * <ScalarButton>Click Me</ScalarButton>\n * <template #items>\n * <ScalarDropdownItem>Item 1</ScalarDropdownItem>\n * <ScalarDropdownItem>Item 2</ScalarDropdownItem>\n * </template>\n * </ScalarDropdown>\n */\nexport default {}\n</script>\n<script setup lang=\"ts\">\nimport { useBindCx } from '@scalar/use-hooks/useBindCx'\nimport { onClickOutside } from '@vueuse/core'\nimport { computed, nextTick, ref, useId, watch } from 'vue'\n\nimport { ScalarFloating, type ScalarFloatingOptions } from '../ScalarFloating'\nimport ScalarDropdownMenu from './ScalarDropdownMenu.vue'\nimport { useDropdown } from './useDropdown'\n\ndefineProps<ScalarFloatingOptions>()\n\ndefineSlots<{\n /** The reference element for the element in the #floating slot */\n default?(props: {\n /** Whether or not the dropdown is open */\n open: boolean\n }): unknown\n /** The list of dropdown items */\n items?(props: {\n /** Whether or not the dropdown is open */\n open: boolean\n }): unknown\n}>()\n\ntype ScalarFloatingType = InstanceType<typeof ScalarFloating>\nconst floatingRef = ref<ScalarFloatingType>()\n\nconst menuRef = ref<HTMLUListElement>()\n\n/** Whether or not the dropdown is open */\nconst open = defineModel<boolean>('open', { default: false })\n\nconst { active } = useDropdown()\n\nconst fallbackTargetId = useId()\nconst targetId = ref<string>(fallbackTargetId)\nconst menuId = useId()\n\n/** Handle click events on the target */\nasync function handleTargetClick() {\n open.value = !open.value\n await nextTick()\n // Floating UI has not positioned the menu yet, so let focus land without scrolling to it\n if (open.value) menuRef.value?.focus({ preventScroll: true })\n}\n\n/** Handle keydown events on the target */\nasync function handleTargetKeydown(event: KeyboardEvent) {\n // Only handle the keys that are relevant to the dropdown\n if (['ArrowDown', 'ArrowUp', ' ', 'Enter'].includes(event.key))\n event.preventDefault()\n else return\n\n // Open the dropdown if it's not open\n if (!open.value) open.value = true\n\n // Move the active item if the key is an arrow key or space or enter\n await nextTick()\n\n // Focus the menu, without scrolling to it before Floating UI has positioned it\n menuRef.value?.focus({ preventScroll: true })\n\n // Move the active item if the key is an arrow key or space or enter\n if (['ArrowDown', ' ', 'Enter'].includes(event.key)) moveActive(1)\n else if (event.key === 'ArrowUp') moveActive(-1)\n}\n\n/** Watch the target reference for changes */\nwatch(\n () => floatingRef.value?.targetRef,\n (newTarget, oldTarget) => {\n if (newTarget) {\n // Create an id for the target if it doesn't have one\n if (newTarget.id) targetId.value = newTarget.id\n else {\n targetId.value = fallbackTargetId\n newTarget.setAttribute('id', targetId.value)\n }\n // Set the aria attributes\n newTarget.setAttribute('aria-haspopup', 'menu')\n newTarget.setAttribute('aria-expanded', `${open.value}`)\n if (open.value) newTarget.setAttribute('aria-controls', menuId)\n // Add the event listeners\n newTarget.addEventListener('click', handleTargetClick)\n newTarget.addEventListener('keydown', handleTargetKeydown)\n }\n if (oldTarget && oldTarget !== newTarget) {\n // Remove the id if it's using the fallback id\n if (oldTarget.id === fallbackTargetId) oldTarget.removeAttribute('id')\n // Remove the aria attributes\n oldTarget.removeAttribute('aria-controls')\n oldTarget.removeAttribute('aria-haspopup')\n oldTarget.removeAttribute('aria-expanded')\n // Remove the event listeners\n oldTarget.removeEventListener('click', handleTargetClick)\n oldTarget.removeEventListener('keydown', handleTargetKeydown)\n }\n },\n { immediate: true },\n)\n\n/** Watch the open state for changes */\nwatch(\n open,\n (o) => {\n const target = floatingRef.value?.targetRef\n if (!target) return\n // Update the aria-expanded attribute on the target\n target.setAttribute('aria-expanded', `${o}`)\n if (o) target.setAttribute('aria-controls', menuId)\n else target.removeAttribute('aria-controls')\n },\n { immediate: true },\n)\n\nasync function handleClose() {\n // Move focus back to the target\n floatingRef.value?.targetRef?.focus()\n // Close the dropdown\n open.value = false\n}\n\nfunction handleSelected() {\n if (!active.value || !menuRef.value) return\n\n const button = menuRef.value.querySelector<HTMLElement>(\n `#${active.value}[role=\"menuitem\"]:not([aria-disabled=\"true\"])`,\n )\n\n if (!button) return\n\n button.click()\n\n handleClose()\n}\n\n/** Move the active item in the dropdown */\nfunction moveActive(dir: 1 | -1) {\n if (!open.value || !menuRef.value) return\n\n // Get all menu items, filtering out disabled ones\n const list = Array.from(\n menuRef.value.querySelectorAll<HTMLElement>(\n '[role=\"menuitem\"]:not([aria-disabled=\"true\"])',\n ),\n )\n\n if (list.length === 0) return\n\n // Find the current active item's index\n const activeIdx = list.findIndex((item) => item.id === active.value)\n\n if (activeIdx === -1) {\n // If there is no active item, activate the first or last item\n const targetItem = list[dir > 0 ? 0 : list.length - 1]\n if (targetItem?.id) active.value = targetItem.id\n return\n }\n\n // Calculate next index and exit if it's out of bounds\n const nextIdx = activeIdx + dir\n\n if (nextIdx < 0 || nextIdx > list.length - 1) {\n return\n }\n\n const nextItem = list[nextIdx]\n\n if (nextItem?.id) active.value = nextItem.id\n}\n\n/** Close the dropdown if the user clicks outside of the menu and button */\nonClickOutside(menuRef, handleClose, {\n ignore: [computed(() => floatingRef.value?.targetRef)],\n})\n\ndefineOptions({ inheritAttrs: false })\nconst { cx } = useBindCx()\n</script>\n<template>\n <ScalarFloating\n ref=\"floatingRef\"\n v-bind=\"$props\"\n :placement=\"placement ?? 'bottom-start'\">\n <slot :open />\n <template\n v-if=\"open\"\n #floating=\"{ width }\">\n <!-- Background container -->\n <ScalarDropdownMenu\n :style=\"{ width }\"\n v-bind=\"cx('max-h-[inherit] max-w-[inherit]')\">\n <template #menu>\n <div\n :id=\"menuId\"\n ref=\"menuRef\"\n :aria-activedescendant=\"active\"\n :aria-labelledby=\"targetId\"\n class=\"flex flex-col p-0.75 outline-none\"\n role=\"menu\"\n tabindex=\"-1\"\n @click.stop=\"handleClose\"\n @keydown.down.prevent.stop=\"moveActive(1)\"\n @keydown.enter.prevent.stop=\"handleSelected\"\n @keydown.escape.prevent.stop=\"handleClose\"\n @keydown.space.prevent.stop=\"handleSelected\"\n @keydown.tab.prevent.stop=\"handleClose\"\n @keydown.up.prevent.stop=\"moveActive(-1)\">\n <slot\n name=\"items\"\n :open />\n </div>\n </template>\n </ScalarDropdownMenu>\n </template>\n </ScalarFloating>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwCA,MAAM,cAAc,IAAwB;EAE5C,MAAM,UAAU,IAAsB;;EAGtC,MAAM,OAAOC,SAAoB,SAAC,MAA0B;EAE5D,MAAM,EAAE,WAAW,YAAY;EAE/B,MAAM,mBAAmB,MAAM;EAC/B,MAAM,WAAW,IAAY,gBAAgB;EAC7C,MAAM,SAAS,MAAM;;EAGrB,eAAe,oBAAoB;GACjC,KAAK,QAAQ,CAAC,KAAK;GACnB,MAAM,SAAS;GAEf,IAAI,KAAK,OAAO,QAAQ,OAAO,MAAM,EAAE,eAAe,KAAK,CAAC;EAC9D;;EAGA,eAAe,oBAAoB,OAAsB;GAEvD,IAAI;IAAC;IAAa;IAAW;IAA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A,EAAA,CAAE,CAAA,iCAAA,CAAA,GAAA;KACC,MAAIG,cAmBP,CAlBNI,mBAkBM,OAAA;MAjBH,IAAIP,MAAA,MAAA;MACD,SAAA;MAAJ,KAAI;MACH,yBAAuBA,MAAA,MAAA;MACvB,mBAAiB,SAAA;MAClB,OAAM;MACN,MAAK;MACL,UAAS;MACR,SAAKQ,cAAO,aAAW,CAAA,MAAA,CAAA;MACvB,WAAO;OAAoB,OAAA,OAAA,OAAA,KAAAC,SAAAD,eAAA,WAAA,WAAU,CAAA,GAAA,CAAA,WAAA,MAAA,CAAA,GAAA,CAAA,MAAA,CAAA;OACTC,SAAAD,cAAA,gBAAc,CAAA,WAAA,MAAA,CAAA,GAAA,CAAA,OAAA,CAAA;OACbC,SAAAD,cAAA,aAAW,CAAA,WAAA,MAAA,CAAA,GAAA,CAAA,QAAA,CAAA;OACZC,SAAAD,cAAA,gBAAc,CAAA,WAAA,MAAA,CAAA,GAAA,CAAA,OAAA,CAAA;OAChBC,SAAAD,cAAA,aAAW,CAAA,WAAA,MAAA,CAAA,GAAA,CAAA,KAAA,CAAA;OACZ,OAAA,OAAA,OAAA,KAAAC,SAAAD,eAAA,WAAA,WAAU,EAAA,GAAA,CAAA,WAAA,MAAA,CAAA,GAAA,CAAA,IAAA,CAAA;;K,IACpCJ,WAEU,KAAA,QAAA,SAAA,EAAP,MAAA,KAAA,MAAI,CAAA,C"}
|
|
1
|
+
{"version":3,"file":"ScalarDropdown.vue_vue_type_script_setup_true_lang.js","names":["$props","_useModel","_openBlock","_createBlock","_unref","ScalarFloating","_mergeProps","_withCtx","_renderSlot","_createVNode","ScalarDropdownMenu","_createElementVNode","_withModifiers","_withKeys"],"sources":["../../../src/components/ScalarDropdown/ScalarDropdown.vue"],"sourcesContent":["<script lang=\"ts\">\n/**\n * Scalar dropdown component\n *\n * @example\n * <ScalarDropdown>\n * <ScalarButton>Click Me</ScalarButton>\n * <template #items>\n * <ScalarDropdownItem>Item 1</ScalarDropdownItem>\n * <ScalarDropdownItem>Item 2</ScalarDropdownItem>\n * </template>\n * </ScalarDropdown>\n */\nexport default {}\n</script>\n<script setup lang=\"ts\">\nimport { useBindCx } from '@scalar/use-hooks/useBindCx'\nimport { onClickOutside } from '@vueuse/core'\nimport { computed, nextTick, ref, useId, watch } from 'vue'\n\nimport { ScalarFloating, type ScalarFloatingOptions } from '../ScalarFloating'\nimport ScalarDropdownMenu from './ScalarDropdownMenu.vue'\nimport { useDropdown } from './useDropdown'\n\ndefineProps<ScalarFloatingOptions>()\n\ndefineSlots<{\n /** The reference element for the element in the #floating slot */\n default?(props: {\n /** Whether or not the dropdown is open */\n open: boolean\n }): unknown\n /** The list of dropdown items */\n items?(props: {\n /** Whether or not the dropdown is open */\n open: boolean\n }): unknown\n}>()\n\ntype ScalarFloatingType = InstanceType<typeof ScalarFloating>\nconst floatingRef = ref<ScalarFloatingType>()\n\nconst menuRef = ref<HTMLUListElement>()\n\n/** Whether or not the dropdown is open */\nconst open = defineModel<boolean>('open', { default: false })\n\nconst { active } = useDropdown()\n\nconst fallbackTargetId = useId()\nconst targetId = ref<string>(fallbackTargetId)\nconst menuId = useId()\n\n/** Handle click events on the target */\nasync function handleTargetClick() {\n open.value = !open.value\n await nextTick()\n // Floating UI has not positioned the menu yet, so let focus land without scrolling to it\n if (open.value) menuRef.value?.focus({ preventScroll: true })\n}\n\n/** Handle keydown events on the target */\nasync function handleTargetKeydown(event: KeyboardEvent) {\n // Only handle the keys that are relevant to the dropdown\n if (['ArrowDown', 'ArrowUp', ' ', 'Enter'].includes(event.key))\n event.preventDefault()\n else return\n\n // Open the dropdown if it's not open\n if (!open.value) open.value = true\n\n // Move the active item if the key is an arrow key or space or enter\n await nextTick()\n\n // Focus the menu, without scrolling to it before Floating UI has positioned it\n menuRef.value?.focus({ preventScroll: true })\n\n // Move the active item if the key is an arrow key or space or enter\n if (['ArrowDown', ' ', 'Enter'].includes(event.key)) moveActive(1)\n else if (event.key === 'ArrowUp') moveActive(-1)\n}\n\n/** Watch the target reference for changes */\nwatch(\n () => floatingRef.value?.targetRef,\n (newTarget, oldTarget) => {\n if (newTarget) {\n // Create an id for the target if it doesn't have one\n if (newTarget.id) targetId.value = newTarget.id\n else {\n targetId.value = fallbackTargetId\n newTarget.setAttribute('id', targetId.value)\n }\n // Set the aria attributes\n newTarget.setAttribute('aria-haspopup', 'menu')\n newTarget.setAttribute('aria-expanded', `${open.value}`)\n if (open.value) newTarget.setAttribute('aria-controls', menuId)\n // Add the event listeners\n newTarget.addEventListener('click', handleTargetClick)\n newTarget.addEventListener('keydown', handleTargetKeydown)\n }\n if (oldTarget && oldTarget !== newTarget) {\n // Remove the id if it's using the fallback id\n if (oldTarget.id === fallbackTargetId) oldTarget.removeAttribute('id')\n // Remove the aria attributes\n oldTarget.removeAttribute('aria-controls')\n oldTarget.removeAttribute('aria-haspopup')\n oldTarget.removeAttribute('aria-expanded')\n // Remove the event listeners\n oldTarget.removeEventListener('click', handleTargetClick)\n oldTarget.removeEventListener('keydown', handleTargetKeydown)\n }\n },\n { immediate: true },\n)\n\n/** Watch the open state for changes */\nwatch(\n open,\n (o) => {\n const target = floatingRef.value?.targetRef\n if (!target) return\n // Update the aria-expanded attribute on the target\n target.setAttribute('aria-expanded', `${o}`)\n if (o) target.setAttribute('aria-controls', menuId)\n else target.removeAttribute('aria-controls')\n },\n { immediate: true },\n)\n\nasync function handleClose() {\n // Move focus back to the target\n floatingRef.value?.targetRef?.focus()\n // Close the dropdown\n open.value = false\n}\n\nfunction handleSelected() {\n if (!active.value || !menuRef.value) return\n\n const button = menuRef.value.querySelector<HTMLElement>(\n `#${active.value}[role=\"menuitem\"]:not([aria-disabled=\"true\"])`,\n )\n\n if (!button) return\n\n button.click()\n\n handleClose()\n}\n\n/** Move the active item in the dropdown */\nfunction moveActive(dir: 1 | -1) {\n if (!open.value || !menuRef.value) return\n\n // Get all menu items, filtering out disabled ones\n const list = Array.from(\n menuRef.value.querySelectorAll<HTMLElement>(\n '[role=\"menuitem\"]:not([aria-disabled=\"true\"])',\n ),\n )\n\n if (list.length === 0) return\n\n // Find the current active item's index\n const activeIdx = list.findIndex((item) => item.id === active.value)\n\n if (activeIdx === -1) {\n // If there is no active item, activate the first or last item\n const targetItem = list[dir > 0 ? 0 : list.length - 1]\n if (targetItem?.id) active.value = targetItem.id\n return\n }\n\n // Calculate next index and exit if it's out of bounds\n const nextIdx = activeIdx + dir\n\n if (nextIdx < 0 || nextIdx > list.length - 1) {\n return\n }\n\n const nextItem = list[nextIdx]\n\n if (nextItem?.id) active.value = nextItem.id\n}\n\n/** Close the dropdown if the user clicks outside of the menu and button */\nonClickOutside(menuRef, handleClose, {\n ignore: [computed(() => floatingRef.value?.targetRef)],\n})\n\ndefineOptions({ inheritAttrs: false })\nconst { cx } = useBindCx()\n</script>\n<template>\n <ScalarFloating\n ref=\"floatingRef\"\n v-bind=\"$props\"\n :placement=\"placement ?? 'bottom-start'\">\n <slot :open />\n <template\n v-if=\"open\"\n #floating=\"{ width }\">\n <!-- Background container -->\n <ScalarDropdownMenu\n :style=\"{ width }\"\n v-bind=\"cx('max-h-[inherit] max-w-[inherit]')\">\n <template #menu>\n <div\n :id=\"menuId\"\n ref=\"menuRef\"\n :aria-activedescendant=\"active\"\n :aria-labelledby=\"targetId\"\n class=\"flex flex-col p-0.75 outline-none\"\n role=\"menu\"\n tabindex=\"-1\"\n @click.stop=\"handleClose\"\n @keydown.down.prevent.stop=\"moveActive(1)\"\n @keydown.enter.prevent.stop=\"handleSelected\"\n @keydown.escape.prevent.stop=\"handleClose\"\n @keydown.space.prevent.stop=\"handleSelected\"\n @keydown.tab.prevent.stop=\"handleClose\"\n @keydown.up.prevent.stop=\"moveActive(-1)\">\n <slot\n name=\"items\"\n :open />\n </div>\n </template>\n </ScalarDropdownMenu>\n </template>\n </ScalarFloating>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwCA,MAAM,cAAc,IAAwB;EAE5C,MAAM,UAAU,I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AAI,CAAA,C"}
|
package/dist/components/ScalarDropdown/ScalarDropdownButton.vue_vue_type_script_setup_true_lang.js
CHANGED
|
@@ -3,7 +3,14 @@ import { createBlock, defineComponent, normalizeClass, openBlock, renderSlot, re
|
|
|
3
3
|
var ScalarDropdownButton_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
4
4
|
__name: "ScalarDropdownButton",
|
|
5
5
|
props: {
|
|
6
|
-
is: {
|
|
6
|
+
is: {
|
|
7
|
+
type: [
|
|
8
|
+
String,
|
|
9
|
+
Object,
|
|
10
|
+
Function
|
|
11
|
+
],
|
|
12
|
+
default: "button"
|
|
13
|
+
},
|
|
7
14
|
active: { type: Boolean },
|
|
8
15
|
disabled: { type: Boolean }
|
|
9
16
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScalarDropdownButton.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createBlock","_resolveDynamicComponent","_normalizeClass","_unref","_withCtx","_renderSlot"],"sources":["../../../src/components/ScalarDropdown/ScalarDropdownButton.vue"],"sourcesContent":["<script lang=\"ts\">\n/**\n * Scalar dropdown button base component\n *\n * Provide a styled button for the ScalarDropdown or similar\n *\n * This is used internally by the ScalarDropdownItem component\n *\n * If you're looking to add items to a dropdown menu you\n * probably want the ScalarDropdownItem component\n *\n * @example\n * <ScalarDropdownButton @click=\"handleClick\">\n * Label\n * </ScalarDropdownButton>\n */\nexport default {}\n</script>\n<script setup lang=\"ts\">\nimport { cva, cx } from '@scalar/use-hooks/useBindCx'\nimport type { Component } from 'vue'\n\nconst { is = 'button' } = defineProps<{\n is?: string | Component\n active?: boolean\n disabled?: boolean\n}>()\n\nconst variants = cva({\n base: [\n // Layout\n 'block h-8 min-w-0 gap-1.5 rounded-md px-2.5 py-1.5 text-left',\n // Text / background style\n 'truncate no-underline text-sm text-c-1',\n // Interaction — hover:bg-b-2 handles mouse, highlighted:bg-b-2 handles\n // Radix keyboard navigation and mouse-hover within Radix menu items\n 'cursor-pointer hover:bg-b-2 highlighted:bg-b-2',\n ],\n variants: {\n disabled: { true: 'pointer-events-none text-c-3' },\n active: { true: '' },\n },\n compoundVariants: [{ disabled: false, active: true, class: 'bg-b-2' }],\n})\n</script>\n<template>\n <component\n :is=\"is\"\n :aria-disabled=\"disabled\"\n class=\"item\"\n :class=\"cx('scalar-dropdown-item', variants({ active, disabled }))\"\n :type=\"is === 'button' ? 'button' : undefined\">\n <slot />\n </component>\n</template>\n<style scoped>\n.dark-mode .scalar-dropdown-item:hover,\n.dark-mode .scalar-dropdown-item[data-highlighted] {\n filter: brightness(1.1);\n}\n</style>\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ScalarDropdownButton.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createBlock","_resolveDynamicComponent","_normalizeClass","_unref","_withCtx","_renderSlot"],"sources":["../../../src/components/ScalarDropdown/ScalarDropdownButton.vue"],"sourcesContent":["<script lang=\"ts\">\n/**\n * Scalar dropdown button base component\n *\n * Provide a styled button for the ScalarDropdown or similar\n *\n * This is used internally by the ScalarDropdownItem component\n *\n * If you're looking to add items to a dropdown menu you\n * probably want the ScalarDropdownItem component\n *\n * @example\n * <ScalarDropdownButton @click=\"handleClick\">\n * Label\n * </ScalarDropdownButton>\n */\nexport default {}\n</script>\n<script setup lang=\"ts\">\nimport { cva, cx } from '@scalar/use-hooks/useBindCx'\nimport type { Component } from 'vue'\n\nconst { is = 'button' } = defineProps<{\n is?: string | Component\n active?: boolean\n disabled?: boolean\n}>()\n\nconst variants = cva({\n base: [\n // Layout\n 'block h-8 min-w-0 gap-1.5 rounded-md px-2.5 py-1.5 text-left',\n // Text / background style\n 'truncate no-underline text-sm text-c-1',\n // Interaction — hover:bg-b-2 handles mouse, highlighted:bg-b-2 handles\n // Radix keyboard navigation and mouse-hover within Radix menu items\n 'cursor-pointer hover:bg-b-2 highlighted:bg-b-2',\n ],\n variants: {\n disabled: { true: 'pointer-events-none text-c-3' },\n active: { true: '' },\n },\n compoundVariants: [{ disabled: false, active: true, class: 'bg-b-2' }],\n})\n</script>\n<template>\n <component\n :is=\"is\"\n :aria-disabled=\"disabled\"\n class=\"item\"\n :class=\"cx('scalar-dropdown-item', variants({ active, disabled }))\"\n :type=\"is === 'button' ? 'button' : undefined\">\n <slot />\n </component>\n</template>\n<style scoped>\n.dark-mode .scalar-dropdown-item:hover,\n.dark-mode .scalar-dropdown-item[data-highlighted] {\n filter: brightness(1.1);\n}\n</style>\n"],"mappings":";;;;;;;;;;;;;;;;;EA4BA,MAAM,WAAW,IAAI;GACnB,MAAM;IAEJ;IAEA;IAGA;GACF;GACA,UAAU;IACR,UAAU,EAAE,MAAM,+BAA+B;IACjD,QAAQ,EAAE,MAAM,GAAG;GACrB;GACA,kBAAkB,CAAC;IAAE,UAAU;IAAO,QAAQ;IAAM,OAAO;GAAS,CAAC;EACvE,CAAC;;GAGC,OAAAA,UAAA,GAAAC,YAOYC,wBANL,QAAA,EAAE,GAAA;IACN,iBAAe,QAAA;IAChB,OAAKC,eAAA,CAAC,QACEC,MAAA,EAAA,CAAE,CAAA,wBAAyBA,MAAA,QAAA,CAAQ,CAAA;KAAA,QAAG,QAAA;KAAM,UAAE,QAAA;IAAQ,CAAA,CAAA,CAAA,CAAA;IAC7D,MAAM,QAAA,OAAE,WAAA,WAA2B,KAAA;;IACpC,SAAAC,cAAQ,CAARC,WAAQ,KAAA,QAAA,WAAA,CAAA,GAAA,KAAA,GAAA,IAAA,C"}
|
package/dist/components/ScalarDropdown/ScalarDropdownMenu.vue_vue_type_script_setup_true_lang.js
CHANGED
|
@@ -6,7 +6,11 @@ var _hoisted_2 = { class: "flex flex-col p-0.75" };
|
|
|
6
6
|
var ScalarDropdownMenu_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
7
7
|
inheritAttrs: false,
|
|
8
8
|
__name: "ScalarDropdownMenu",
|
|
9
|
-
props: { is: {
|
|
9
|
+
props: { is: { type: [
|
|
10
|
+
String,
|
|
11
|
+
Object,
|
|
12
|
+
Function
|
|
13
|
+
] } },
|
|
10
14
|
setup(__props) {
|
|
11
15
|
const { cx } = useBindCx();
|
|
12
16
|
return (_ctx, _cache) => {
|
package/dist/components/ScalarDropdown/ScalarDropdownMenu.vue_vue_type_script_setup_true_lang.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScalarDropdownMenu.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createBlock","_resolveDynamicComponent","_normalizeProps","_guardReactiveProps","_unref","_withCtx","_createElementVNode","_renderSlot"],"sources":["../../../src/components/ScalarDropdown/ScalarDropdownMenu.vue"],"sourcesContent":["<script lang=\"ts\">\n/**\n * Scalar dropdown menu component\n *\n * Provides a scrollable container for dropdown items\n * This is used internally by the ScalarDropdown component\n *\n * If you're looking to create a dropdown menu with a trigger\n * button you probably want the ScalarDropdown component\n *\n * @example\n * <ScalarDropdownMenu>\n * <ScalarDropdownItem>Item 1</ScalarDropdownItem>\n * <ScalarDropdownItem>Item 2</ScalarDropdownItem>\n * </ScalarDropdownMenu>\n */\nexport default {}\n</script>\n<script setup lang=\"ts\">\nimport { useBindCx } from '@scalar/use-hooks/useBindCx'\nimport { type Component } from 'vue'\n\ndefineProps<{\n /** The component to render */\n is?: string | Component\n}>()\n\ndefineSlots<{\n /** The menu contents */\n default?(): unknown\n /** Overrides the normal menu list element */\n menu?(): unknown\n}>()\n\ndefineOptions({ inheritAttrs: false })\nconst { cx } = useBindCx()\n</script>\n<template>\n <!-- Background container -->\n <component\n :is=\"is ?? 'div'\"\n v-bind=\"\n cx(\n 'relative flex w-56 rounded-xl bg-b-1 dark:bg-b-1.5 shadow-md inset-shadow-border',\n )\n \">\n <!-- Scroll container -->\n <div class=\"custom-scroll min-h-0 flex-1 rounded-[inherit]\">\n <!-- Menu items -->\n <slot name=\"menu\">\n <div class=\"flex flex-col p-0.75\">\n <slot />\n </div>\n </slot>\n </div>\n </component>\n</template>\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ScalarDropdownMenu.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createBlock","_resolveDynamicComponent","_normalizeProps","_guardReactiveProps","_unref","_withCtx","_createElementVNode","_renderSlot"],"sources":["../../../src/components/ScalarDropdown/ScalarDropdownMenu.vue"],"sourcesContent":["<script lang=\"ts\">\n/**\n * Scalar dropdown menu component\n *\n * Provides a scrollable container for dropdown items\n * This is used internally by the ScalarDropdown component\n *\n * If you're looking to create a dropdown menu with a trigger\n * button you probably want the ScalarDropdown component\n *\n * @example\n * <ScalarDropdownMenu>\n * <ScalarDropdownItem>Item 1</ScalarDropdownItem>\n * <ScalarDropdownItem>Item 2</ScalarDropdownItem>\n * </ScalarDropdownMenu>\n */\nexport default {}\n</script>\n<script setup lang=\"ts\">\nimport { useBindCx } from '@scalar/use-hooks/useBindCx'\nimport { type Component } from 'vue'\n\ndefineProps<{\n /** The component to render */\n is?: string | Component\n}>()\n\ndefineSlots<{\n /** The menu contents */\n default?(): unknown\n /** Overrides the normal menu list element */\n menu?(): unknown\n}>()\n\ndefineOptions({ inheritAttrs: false })\nconst { cx } = useBindCx()\n</script>\n<template>\n <!-- Background container -->\n <component\n :is=\"is ?? 'div'\"\n v-bind=\"\n cx(\n 'relative flex w-56 rounded-xl bg-b-1 dark:bg-b-1.5 shadow-md inset-shadow-border',\n )\n \">\n <!-- Scroll container -->\n <div class=\"custom-scroll min-h-0 flex-1 rounded-[inherit]\">\n <!-- Menu items -->\n <slot name=\"menu\">\n <div class=\"flex flex-col p-0.75\">\n <slot />\n </div>\n </slot>\n </div>\n </component>\n</template>\n"],"mappings":";;;;;;;;;;;;;;EAmCA,MAAM,EAAE,OAAO,UAAU;;GAIvB,OAAAA,UAAA,GAAAC,YAgBYC,wBAfL,QAAA,MAAE,KAAA,GAAAC,eAAAC,mBACQC,MAAA,EAAA,CAAE,C;IAMjB,SAAAC,cAOM,CAPNC,mBAOM,OAPN,YAOM,CALJC,WAIO,KAAA,QAAA,QAAA,CAAA,SAAA,CAHLD,mBAEM,OAFN,YAEM,CADJC,WAAQ,KAAA,QAAA,SAAA,C"}
|
package/dist/components/ScalarFloating/ScalarFloating.vue_vue_type_script_setup_true_lang.js
CHANGED
|
@@ -20,7 +20,11 @@ var ScalarFloating_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
|
|
|
20
20
|
type: Boolean,
|
|
21
21
|
default: false
|
|
22
22
|
},
|
|
23
|
-
target: {
|
|
23
|
+
target: { type: [
|
|
24
|
+
String,
|
|
25
|
+
Object,
|
|
26
|
+
Function
|
|
27
|
+
] },
|
|
24
28
|
middleware: { default: () => [] },
|
|
25
29
|
teleport: { type: [Boolean, String] }
|
|
26
30
|
},
|
package/dist/components/ScalarFloating/ScalarFloating.vue_vue_type_script_setup_true_lang.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScalarFloating.vue_vue_type_script_setup_true_lang.js","names":["$slots","offsetMiddleware","_openBlock","_createElementVNode","_normalizeClass","_renderSlot","_createBlock","_unref","ScalarTeleport","_withCtx","_normalizeStyle"],"sources":["../../../src/components/ScalarFloating/ScalarFloating.vue"],"sourcesContent":["<script lang=\"ts\">\n/**\n * Scalar Floating component\n *\n * Positions a floating element relative to a reference element\n * using Floating UI. Handles placement, offset, flipping, and resizing.\n *\n * @example\n * <ScalarFloating placement=\"bottom\">\n * <button>Reference</button>\n * <template #floating>Floating content</template>\n * </ScalarFloating>\n */\nexport default {}\n</script>\n<script setup lang=\"ts\">\nimport { getSideAxis } from '@floating-ui/utils'\nimport {\n autoUpdate,\n flip,\n offset as offsetMiddleware,\n shift,\n size,\n useFloating,\n type MiddlewareData,\n} from '@floating-ui/vue'\nimport { computed, nextTick, ref, type Ref } from 'vue'\n\nimport { ScalarTeleport } from '../ScalarTeleport'\nimport type { FloatingOptions } from './types'\nimport { useResizeWithTarget } from './useResizeWithTarget'\n\nconst {\n placement,\n offset = 5,\n resize = false,\n middleware = [],\n target,\n teleport,\n} = defineProps<FloatingOptions>()\n\ndefineSlots<{\n /** The reference element for the element in the #floating slot */\n default(): unknown\n /** The floating element */\n floating?(props: {\n /** The width of the reference element if `resize` is true and placement is on the y axis */\n width?: string\n /** The height of the reference element if `resize` is true and placement is on the x axis */\n height?: string\n /** The middleware data return by Floating UI */\n data?: MiddlewareData\n }): unknown\n}>()\n\ndefineOptions({ inheritAttrs: false })\n\nconst floatingRef: Ref<HTMLElement | null> = ref(null)\nconst wrapperRef: Ref<HTMLElement | null> = ref(null)\n\nconst targetRef = computed<HTMLElement | undefined>(() => {\n if (typeof window !== 'undefined' && wrapperRef.value) {\n // If target is a string (id), try to find it in the document\n if (typeof target === 'string') {\n const t = document.getElementById(target)\n if (t) {\n return t\n }\n console.warn(`ScalarFloating: Target with id=\"${target}\" not found`)\n }\n // If target is an HTMLElement, return it\n else if (target instanceof HTMLElement) {\n return target\n }\n // Fallback to div wrapper if no child element is provided\n const firstChild = wrapperRef.value.children?.[0]\n if (firstChild instanceof HTMLElement) {\n return firstChild\n }\n return wrapperRef.value\n }\n // Return undefined if nothing is found\n return undefined\n})\n\nconst targetSize = useResizeWithTarget(targetRef, {\n enabled: computed(() => resize),\n})\n\nconst targetWidth = computed(() =>\n getSideAxis(placement ?? 'bottom') === 'y'\n ? targetSize.width.value\n : undefined,\n)\n\nconst targetHeight = computed(() =>\n getSideAxis(placement ?? 'bottom') === 'x'\n ? targetSize.height.value\n : undefined,\n)\n\n/**\n * Starts Floating UI's `autoUpdate` one tick after both elements exist.\n *\n * `useFloating` attaches `autoUpdate` from a synchronous watch the moment the\n * template refs resolve, and `autoUpdate` positions the element right away.\n * Template refs resolve in the post-render phase of a flush, so that first\n * `computePosition` reads layout while the same flush is still mounting other\n * components: every floating element mounted together (for example the closed\n * listboxes of a schema with many compositions) forces its own style recalc and\n * layout on a tree that was dirtied again in between. Waiting for `nextTick`\n * runs every first positioning back-to-back once the flush has settled, so the\n * browser recalculates the tree once for all of them. The tick resolves before\n * the next paint, so an element that mounts open is positioned in the same task.\n */\nconst deferredAutoUpdate: typeof autoUpdate = (\n reference,\n floating,\n update,\n options,\n) => {\n let cleanup: (() => void) | undefined\n let disposed = false\n\n void nextTick(() => {\n if (!disposed) {\n cleanup = autoUpdate(reference, floating, update, options)\n }\n })\n\n return () => {\n disposed = true\n cleanup?.()\n }\n}\n\nconst { floatingStyles, middlewareData } = useFloating(targetRef, floatingRef, {\n placement: computed(() => placement ?? 'bottom'),\n whileElementsMounted: deferredAutoUpdate,\n middleware: computed(() => [\n offsetMiddleware(offset),\n flip({ padding: 48 }),\n shift({ padding: 8 }),\n size({\n apply({ availableWidth, availableHeight, elements }) {\n // Assign the max width and height to the floating element\n // @see https://floating-ui.com/docs/size\n Object.assign(elements.floating.style, {\n maxWidth: `${Math.max(0, availableWidth) - 16}px`,\n maxHeight: `${Math.max(0, availableHeight) - 16}px`,\n })\n },\n }),\n ...middleware,\n ]),\n})\n\ndefineExpose({\n /** The resolved target element */\n targetRef,\n})\n</script>\n<template>\n <div\n ref=\"wrapperRef\"\n :class=\"{ contents: !!$slots.default }\">\n <slot />\n </div>\n <ScalarTeleport\n v-if=\"$slots.floating\"\n :disabled=\"!teleport\"\n :to=\"typeof teleport === 'string' ? teleport : undefined\">\n <div\n ref=\"floatingRef\"\n class=\"z-context relative\"\n :style=\"floatingStyles\">\n <slot\n :data=\"middlewareData\"\n :height=\"targetHeight\"\n name=\"floating\"\n :width=\"targetWidth\" />\n </div>\n </ScalarTeleport>\n</template>\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ScalarFloating.vue_vue_type_script_setup_true_lang.js","names":["$slots","offsetMiddleware","_openBlock","_createElementVNode","_normalizeClass","_renderSlot","_createBlock","_unref","ScalarTeleport","_withCtx","_normalizeStyle"],"sources":["../../../src/components/ScalarFloating/ScalarFloating.vue"],"sourcesContent":["<script lang=\"ts\">\n/**\n * Scalar Floating component\n *\n * Positions a floating element relative to a reference element\n * using Floating UI. Handles placement, offset, flipping, and resizing.\n *\n * @example\n * <ScalarFloating placement=\"bottom\">\n * <button>Reference</button>\n * <template #floating>Floating content</template>\n * </ScalarFloating>\n */\nexport default {}\n</script>\n<script setup lang=\"ts\">\nimport { getSideAxis } from '@floating-ui/utils'\nimport {\n autoUpdate,\n flip,\n offset as offsetMiddleware,\n shift,\n size,\n useFloating,\n type MiddlewareData,\n} from '@floating-ui/vue'\nimport { computed, nextTick, ref, type Ref } from 'vue'\n\nimport { ScalarTeleport } from '../ScalarTeleport'\nimport type { FloatingOptions } from './types'\nimport { useResizeWithTarget } from './useResizeWithTarget'\n\nconst {\n placement,\n offset = 5,\n resize = false,\n middleware = [],\n target,\n teleport,\n} = defineProps<FloatingOptions>()\n\ndefineSlots<{\n /** The reference element for the element in the #floating slot */\n default(): unknown\n /** The floating element */\n floating?(props: {\n /** The width of the reference element if `resize` is true and placement is on the y axis */\n width?: string\n /** The height of the reference element if `resize` is true and placement is on the x axis */\n height?: string\n /** The middleware data return by Floating UI */\n data?: MiddlewareData\n }): unknown\n}>()\n\ndefineOptions({ inheritAttrs: false })\n\nconst floatingRef: Ref<HTMLElement | null> = ref(null)\nconst wrapperRef: Ref<HTMLElement | null> = ref(null)\n\nconst targetRef = computed<HTMLElement | undefined>(() => {\n if (typeof window !== 'undefined' && wrapperRef.value) {\n // If target is a string (id), try to find it in the document\n if (typeof target === 'string') {\n const t = document.getElementById(target)\n if (t) {\n return t\n }\n console.warn(`ScalarFloating: Target with id=\"${target}\" not found`)\n }\n // If target is an HTMLElement, return it\n else if (target instanceof HTMLElement) {\n return target\n }\n // Fallback to div wrapper if no child element is provided\n const firstChild = wrapperRef.value.children?.[0]\n if (firstChild instanceof HTMLElement) {\n return firstChild\n }\n return wrapperRef.value\n }\n // Return undefined if nothing is found\n return undefined\n})\n\nconst targetSize = useResizeWithTarget(targetRef, {\n enabled: computed(() => resize),\n})\n\nconst targetWidth = computed(() =>\n getSideAxis(placement ?? 'bottom') === 'y'\n ? targetSize.width.value\n : undefined,\n)\n\nconst targetHeight = computed(() =>\n getSideAxis(placement ?? 'bottom') === 'x'\n ? targetSize.height.value\n : undefined,\n)\n\n/**\n * Starts Floating UI's `autoUpdate` one tick after both elements exist.\n *\n * `useFloating` attaches `autoUpdate` from a synchronous watch the moment the\n * template refs resolve, and `autoUpdate` positions the element right away.\n * Template refs resolve in the post-render phase of a flush, so that first\n * `computePosition` reads layout while the same flush is still mounting other\n * components: every floating element mounted together (for example the closed\n * listboxes of a schema with many compositions) forces its own style recalc and\n * layout on a tree that was dirtied again in between. Waiting for `nextTick`\n * runs every first positioning back-to-back once the flush has settled, so the\n * browser recalculates the tree once for all of them. The tick resolves before\n * the next paint, so an element that mounts open is positioned in the same task.\n */\nconst deferredAutoUpdate: typeof autoUpdate = (\n reference,\n floating,\n update,\n options,\n) => {\n let cleanup: (() => void) | undefined\n let disposed = false\n\n void nextTick(() => {\n if (!disposed) {\n cleanup = autoUpdate(reference, floating, update, options)\n }\n })\n\n return () => {\n disposed = true\n cleanup?.()\n }\n}\n\nconst { floatingStyles, middlewareData } = useFloating(targetRef, floatingRef, {\n placement: computed(() => placement ?? 'bottom'),\n whileElementsMounted: deferredAutoUpdate,\n middleware: computed(() => [\n offsetMiddleware(offset),\n flip({ padding: 48 }),\n shift({ padding: 8 }),\n size({\n apply({ availableWidth, availableHeight, elements }) {\n // Assign the max width and height to the floating element\n // @see https://floating-ui.com/docs/size\n Object.assign(elements.floating.style, {\n maxWidth: `${Math.max(0, availableWidth) - 16}px`,\n maxHeight: `${Math.max(0, availableHeight) - 16}px`,\n })\n },\n }),\n ...middleware,\n ]),\n})\n\ndefineExpose({\n /** The resolved target element */\n targetRef,\n})\n</script>\n<template>\n <div\n ref=\"wrapperRef\"\n :class=\"{ contents: !!$slots.default }\">\n <slot />\n </div>\n <ScalarTeleport\n v-if=\"$slots.floating\"\n :disabled=\"!teleport\"\n :to=\"typeof teleport === 'string' ? teleport : undefined\">\n <div\n ref=\"floatingRef\"\n class=\"z-context relative\"\n :style=\"floatingStyles\">\n <slot\n :data=\"middlewareData\"\n :height=\"targetHeight\"\n name=\"floating\"\n :width=\"targetWidth\" />\n </div>\n </ScalarTeleport>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyDA,MAAM,cAAuC,IAAI,IAAI;EACrD,MAAM,aAAsC,IAAI,IAAI;EAEpD,MAAM,YAAY,eAAwC;GACxD,IAAI,OAAO,WAAW,eAAe,WAAW,OAAO;IAErD,IAAI,OAAO,QAAA,WAAW,UAAU;KAC9B,MAAM,IAAI,SAAS,eAAe,QAAA,MAAM;KACxC,IAAI,GACF,OAAO;KAET,QAAQ,KAAK,mCAAmC,QAAA,OAAO,YAAY;IACrE,OAEK,IAAI,QAAA,kBAAkB,aACzB,OAAO,QAAA;IAGT,MAAM,aAAa,WAAW,MAAM,WAAW;IAC/C,IAAI,sBAAsB,aACxB,OAAO;IAET,OAAO,WAAW;GACpB;EAGF,CAAC;EAED,MAAM,aAAa,oBAAoB,WAAW,EAChD,SAAS,eAAe,QAAA,MAAM,EAChC,CAAC;EAED,MAAM,cAAc,eAClB,YAAY,QAAA,aAAa,QAAQ,MAAM,MACnC,WAAW,MAAM,QACjB,KAAA,CACN;EAEA,MAAM,eAAe,eACnB,YAAY,QAAA,aAAa,QAAQ,MAAM,MACnC,WAAW,OAAO,QAClB,KAAA,CACN;;;;;;;;;;;;;;;EAgBA,MAAM,sBACJ,WACA,UACA,QACA,YACG;GACH,IAAI;GACJ,IAAI,WAAW;GAEf,eAAoB;IAClB,IAAI,CAAC,UACH,UAAU,WAAW,WAAW,UAAU,QAAQ,OAAO;GAE7D,CAAC;GAED,aAAa;IACX,WAAW;IACX,UAAU;GACZ;EACF;EAEA,MAAM,EAAE,gBAAgB,mBAAmB,YAAY,WAAW,aAAa;GAC7E,WAAW,eAAe,QAAA,aAAa,QAAQ;GAC/C,sBAAsB;GACtB,YAAY,eAAe;IACzBC,OAAiB,QAAA,MAAM;IACvB,KAAK,EAAE,SAAS,GAAG,CAAC;IACpB,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,KAAK,EACH,MAAM,EAAE,gBAAgB,iBAAiB,YAAY;KAGnD,OAAO,OAAO,SAAS,SAAS,OAAO;MACrC,UAAU,GAAG,KAAK,IAAI,GAAG,cAAc,IAAI,GAAG;MAC9C,WAAW,GAAG,KAAK,IAAI,GAAG,eAAe,IAAI,GAAG;KAClD,CAAC;IACH,EACF,CAAC;IACD,GAAG,QAAA;GACL,CAAC;EACH,CAAC;EAED,SAAa;;AAEX,UACF,CAAC;;G,wDAGCE,mBAIM,OAAA;IAHA,SAAA;IAAJ,KAAI;IACH,OAAKC,eAAA,EAAA,UAAA,CAAA,CAAgBJ,KAAAA,OAAO,QAAO,CAAA;G,IACpCK,WAAQ,KAAA,QAAA,SAAA,C,OAGFL,KAAAA,OAAO,YADfE,UAAA,GAAAI,YAciBC,MAAAC,sBAAA,GAAA;;IAZd,UAAQ,CAAG,QAAA;IACX,IAAE,OAAS,QAAA,aAAQ,WAAgB,QAAA,WAAW,KAAA;;IAC/C,SAAAC,cASM,CATNN,mBASM,OAAA;KARA,SAAA;KAAJ,KAAI;KACJ,OAAM;KACL,OAAKO,eAAEH,MAAA,cAAA,CAAc;I,IACtBF,WAIyB,KAAA,QAAA,YAAA;KAHtB,MAAME,MAAA,cAAA;KACN,QAAQ,aAAA;KAER,OAAO,YAAA"}
|
|
@@ -27,9 +27,10 @@ export type FloatingOptions = {
|
|
|
27
27
|
* Override the target, useful if we are not passing a button
|
|
28
28
|
* into the slot but is controlled from an external button
|
|
29
29
|
*
|
|
30
|
-
* Can be a string id or a reference to an element
|
|
30
|
+
* Can be a string id or a reference to an element.
|
|
31
|
+
* Keep string explicit so Vue includes it in production prop validation.
|
|
31
32
|
*/
|
|
32
|
-
target?: MaybeRefOrGetter<HTMLElement | string>;
|
|
33
|
+
target?: string | MaybeRefOrGetter<HTMLElement | string>;
|
|
33
34
|
/**
|
|
34
35
|
* Floating UI Middleware to be passed to Floating UI
|
|
35
36
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarFloating/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AACzF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,KAAK,CAAA;AAE3C,iDAAiD;AACjD,MAAM,MAAM,eAAe,GAAG;IAC5B;;;;;OAKG;IACH,SAAS,CAAC,EAAE,IAAI,GAAG,gBAAgB,CAAA;IACnC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,aAAa,CAAA;IACtB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarFloating/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AACzF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,KAAK,CAAA;AAE3C,iDAAiD;AACjD,MAAM,MAAM,eAAe,GAAG;IAC5B;;;;;OAKG;IACH,SAAS,CAAC,EAAE,IAAI,GAAG,gBAAgB,CAAA;IACnC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,aAAa,CAAA;IACtB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAAC,WAAW,GAAG,MAAM,CAAC,CAAA;IACxD;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,EAAE,UAAU,EAAE,CAAA;IACzB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;CAC5B,CAAA"}
|