ropav 0.1.6 → 0.1.7
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/README.md +6 -0
- package/dist/accordion.css +17 -17
- package/dist/accordion.js +123 -155
- package/dist/alert.css +18 -18
- package/dist/alert.js +10 -11
- package/dist/aria.js +14 -0
- package/dist/aspect-ratio.js +1 -1
- package/dist/attributes.js +9 -0
- package/dist/attributes2.js +29 -0
- package/dist/avatar.css +19 -19
- package/dist/avatar.js +9 -17
- package/dist/badge.css +16 -16
- package/dist/badge.js +5 -5
- package/dist/button-group.js +1 -1
- package/dist/button-link.js +4 -3
- package/dist/button.js +4 -3
- package/dist/button.scss_vue_type_style_index_0_src_true_lang.js +1 -1
- package/dist/card.js +1 -1
- package/dist/checkbox.css +32 -32
- package/dist/checkbox.js +22 -28
- package/dist/collapse.css +6 -6
- package/dist/collapse.js +7 -6
- package/dist/collectionNavigation.js +2 -99
- package/dist/color-input.css +19 -19
- package/dist/color-input.js +14 -13
- package/dist/color-picker.css +40 -40
- package/dist/color-picker.js +221 -200
- package/dist/color-picker2.js +1 -9
- package/dist/color-swatch.css +4 -4
- package/dist/color-swatch.js +6 -8
- package/dist/color.js +5 -10
- package/dist/componentColors.js +125 -84
- package/dist/componentRef.js +26 -0
- package/dist/components/accordion/accordionContext.d.ts +3 -0
- package/dist/components/accordion/accordionModel.d.ts +14 -0
- package/dist/components/accordion/index.d.ts +2 -1
- package/dist/components/accordion/index.js +1 -1
- package/dist/components/accordion/types.d.ts +1 -2
- package/dist/components/accordion/useAccordion.d.ts +2 -2
- package/dist/components/accordion/useAccordionItem.d.ts +2 -0
- package/dist/components/checkbox/useCheckbox.d.ts +1 -2
- package/dist/components/color-picker/index.js +2 -2
- package/dist/components/color-picker/types.d.ts +2 -2
- package/dist/components/color-picker/useColorPickerSaturation.d.ts +22 -0
- package/dist/components/color-picker/useColorPickerSlider.d.ts +20 -0
- package/dist/components/color-picker/useColorPickerValue.d.ts +1 -1
- package/dist/components/dialog/{dialog-core.d.ts → dialogContext.d.ts} +1 -5
- package/dist/components/dialog/useDialogContentInteractions.d.ts +18 -0
- package/dist/components/dialog/useDialogRootState.d.ts +19 -0
- package/dist/components/dropdown-menu/dropdown-menu-item-row.d.ts +1 -1
- package/dist/components/dropdown-menu/dropdown-menu-items.d.ts +1 -1
- package/dist/components/dropdown-menu/dropdown-menu-model.d.ts +8 -0
- package/dist/components/dropdown-menu/dropdown-menu-root.d.ts +2 -2
- package/dist/components/dropdown-menu/dropdown-menu-sub-trigger.d.ts +1 -1
- package/dist/components/dropdown-menu/dropdown-menu-sub.d.ts +1 -1
- package/dist/components/dropdown-menu/{dropdown-menu-primitive-core.d.ts → dropdownMenuContext.d.ts} +16 -18
- package/dist/components/dropdown-menu/dropdownMenuDataModel.d.ts +20 -0
- package/dist/components/dropdown-menu/dropdownMenuInteraction.d.ts +3 -0
- package/dist/components/dropdown-menu/dropdownMenuInteractionNavigation.d.ts +24 -0
- package/dist/components/dropdown-menu/dropdownMenuInteractionRegistry.d.ts +42 -0
- package/dist/components/dropdown-menu/dropdownMenuInteractionTypes.d.ts +85 -0
- package/dist/components/dropdown-menu/useDropdownMenu.d.ts +11 -11
- package/dist/components/dropdown-menu/useDropdownMenuContextTrigger.d.ts +9 -0
- package/dist/components/dropdown-menu/useDropdownMenuDataController.d.ts +34 -0
- package/dist/components/dropdown-menu/useDropdownMenuDataRegistration.d.ts +22 -0
- package/dist/components/dropdown-menu/useDropdownMenuHoverIntent.d.ts +6 -5
- package/dist/components/dropdown-menu/useDropdownMenuInteractionDismissal.d.ts +17 -0
- package/dist/components/dropdown-menu/useDropdownMenuInteractionKeyboard.d.ts +19 -0
- package/dist/components/dropdown-menu/useDropdownMenuPortalPosition.d.ts +0 -1
- package/dist/components/dropdown-menu/useDropdownMenuPresentation.d.ts +29 -0
- package/dist/components/dropdown-menu/useDropdownMenuPrimitiveContent.d.ts +2 -2
- package/dist/components/dropdown-menu/useDropdownMenuRenderItems.d.ts +1 -1
- package/dist/components/dropdown-menu/useDropdownMenuTargetBindings.d.ts +19 -0
- package/dist/components/floating/hoverDisclosureInteractionModel.d.ts +42 -0
- package/dist/components/floating/index.js +1 -1
- package/dist/components/floating/useFloatingPosition.d.ts +0 -1
- package/dist/components/floating/useHoverDisclosureInteractions.d.ts +32 -0
- package/dist/components/floating/useHoverDisclosureOpenState.d.ts +25 -0
- package/dist/components/floating/useHoverDisclosureTargetBinding.d.ts +27 -0
- package/dist/components/number-input/numberInputModel.d.ts +15 -0
- package/dist/components/number-input/useNumberInput.d.ts +3 -17
- package/dist/components/pagination/index.d.ts +1 -1
- package/dist/components/pagination/index.js +1 -1
- package/dist/components/pagination/paginationModel.d.ts +4 -0
- package/dist/components/pagination/types.d.ts +15 -0
- package/dist/components/pagination/usePagination.d.ts +3 -19
- package/dist/components/popover/usePopoverBindings.d.ts +16 -0
- package/dist/components/progress/progressModel.d.ts +8 -0
- package/dist/components/progress/useProgress.d.ts +0 -6
- package/dist/components/radio/useRadio.d.ts +1 -2
- package/dist/components/scroll-area/scroll-area.d.ts +1 -1
- package/dist/components/scroll-area/scrollAreaModel.d.ts +64 -0
- package/dist/components/scroll-area/useScrollArea.d.ts +70 -53
- package/dist/components/scroll-area/{useScrollAreaPresentation.d.ts → useScrollAreaAttributes.d.ts} +37 -17
- package/dist/components/scroll-area/useScrollAreaDerivedState.d.ts +8 -0
- package/dist/components/scroll-area/useScrollAreaMeasurement.d.ts +35 -0
- package/dist/components/scroll-area/useScrollAreaPointer.d.ts +10 -8
- package/dist/components/scroll-area/useScrollAreaVisibility.d.ts +15 -20
- package/dist/components/slider/rangeSliderModel.d.ts +41 -0
- package/dist/components/slider/{sliderCore.d.ts → sliderModel.d.ts} +0 -1
- package/dist/components/slider/useRangeSlider.d.ts +8 -16
- package/dist/components/slider/useRangeSliderValueState.d.ts +40 -0
- package/dist/components/slider/useSlider.d.ts +7 -13
- package/dist/components/slider/useSliderPointerPreview.d.ts +22 -0
- package/dist/components/slider/useSliderTooltipState.d.ts +40 -0
- package/dist/components/slider/useSliderValueState.d.ts +33 -0
- package/dist/components/teleport-provider/index.js +1 -1
- package/dist/components/teleport-provider/useTeleportTarget.d.ts +1 -2
- package/dist/components/toast/useToastLifecycle.d.ts +19 -0
- package/dist/components/tooltip/useTooltip.d.ts +1 -2
- package/dist/css.js +12 -0
- package/dist/dialog.js +226 -218
- package/dist/dropdown-menu.js +1458 -1097
- package/dist/events.js +59 -0
- package/dist/field.css +8 -8
- package/dist/field.js +13 -25
- package/dist/floating.js +548 -319
- package/dist/floatingOffset.js +11 -0
- package/dist/focus-trap.js +7 -5
- package/dist/focusNavigation.js +37 -0
- package/dist/icon-button.css +8 -8
- package/dist/icon-button.js +7 -6
- package/dist/index.js +6 -6
- package/dist/input.css +24 -24
- package/dist/input.js +19 -31
- package/dist/interactive.js +18 -0
- package/dist/modal.js +1 -1
- package/dist/number-input.css +18 -18
- package/dist/number-input.js +14 -12
- package/dist/number.js +22 -0
- package/dist/overlay.js +3 -2
- package/dist/pagination.css +28 -28
- package/dist/pagination.js +65 -63
- package/dist/pointer.js +9 -0
- package/dist/popover.css +34 -34
- package/dist/popover.js +85 -86
- package/dist/progress.js +10 -13
- package/dist/query.js +40 -0
- package/dist/radio.css +18 -18
- package/dist/radio.js +30 -36
- package/dist/rafScheduler.js +34 -0
- package/dist/scroll-area.css +28 -28
- package/dist/scroll-area.js +512 -516
- package/dist/select.css +45 -45
- package/dist/select.js +36 -44
- package/dist/slider.css +191 -191
- package/dist/slider.js +691 -618
- package/dist/styles-api.d.ts +0 -1
- package/dist/styles-api.js +1 -4
- package/dist/switch.css +17 -17
- package/dist/switch.js +14 -15
- package/dist/tabs.css +43 -43
- package/dist/tabs.js +29 -56
- package/dist/text.js +17 -0
- package/dist/textarea.css +26 -26
- package/dist/textarea.js +21 -32
- package/dist/toast.css +26 -26
- package/dist/toast.js +141 -118
- package/dist/tooltip.css +12 -12
- package/dist/tooltip.js +36 -40
- package/dist/useCollapse.js +8 -11
- package/dist/useControlState.js +3 -6
- package/dist/useFloatingPosition.js +140 -10
- package/dist/useOverlayZIndex.js +1 -5
- package/dist/useTeleportTarget.js +3 -14
- package/dist/useTypeahead.js +94 -0
- package/dist/utils/aria.d.ts +3 -0
- package/dist/utils/attributes.d.ts +2 -0
- package/dist/utils/bem.d.ts +3 -0
- package/dist/utils/collectionNavigation.d.ts +2 -0
- package/dist/utils/color.d.ts +7 -0
- package/dist/{components/color-picker/color-picker-utils.d.ts → utils/colorPicker.d.ts} +5 -4
- package/dist/utils/componentColors.d.ts +7 -0
- package/dist/utils/css.d.ts +3 -0
- package/dist/utils/dom/ancestry.d.ts +7 -0
- package/dist/utils/dom/attributes.d.ts +16 -0
- package/dist/utils/dom/componentRef.d.ts +4 -0
- package/dist/utils/dom/events.d.ts +5 -0
- package/dist/utils/dom/focusNavigation.d.ts +7 -0
- package/dist/utils/dom/interactive.d.ts +2 -0
- package/dist/utils/dom/pointer.d.ts +2 -0
- package/dist/utils/dom/query.d.ts +4 -0
- package/dist/utils/dom/scroll.d.ts +23 -0
- package/dist/utils/floatingOffset.d.ts +10 -0
- package/dist/utils/geometry.d.ts +14 -0
- package/dist/utils/indexPath.d.ts +6 -0
- package/dist/utils/number.d.ts +4 -0
- package/dist/utils/rafScheduler.d.ts +4 -0
- package/dist/utils/text.d.ts +2 -0
- package/docs/code-architecture.md +118 -0
- package/docs/public-floating-api.md +6 -5
- package/package.json +13 -12
- package/dist/components/dropdown-menu/dropdown-menu-outside.d.ts +0 -3
- package/dist/components/dropdown-menu/dropdown-menu-utils.d.ts +0 -21
- package/dist/components/dropdown-menu/useDropdownMenuDisclosure.d.ts +0 -36
- package/dist/components/dropdown-menu/useDropdownMenuDom.d.ts +0 -29
- package/dist/components/dropdown-menu/useDropdownMenuInteractions.d.ts +0 -52
- package/dist/components/dropdown-menu/useDropdownMenuNavigation.d.ts +0 -17
- package/dist/components/dropdown-menu/useDropdownSubmenus.d.ts +0 -18
- package/dist/components/scroll-area/scrollAreaCore.d.ts +0 -30
- package/dist/components/scroll-area/useScrollAreaControls.d.ts +0 -25
- package/dist/components/scroll-area/useScrollAreaMetrics.d.ts +0 -38
- /package/dist/components/alert/{useAlertColor.d.ts → alertColor.d.ts} +0 -0
- /package/dist/components/avatar/{useAvatarColor.d.ts → avatarColor.d.ts} +0 -0
- /package/dist/components/badge/{useBadgeColor.d.ts → badgeColor.d.ts} +0 -0
- /package/dist/components/button/{useButtonColor.d.ts → buttonColor.d.ts} +0 -0
- /package/dist/components/color-swatch/{useColorSwatchColor.d.ts → colorSwatchColor.d.ts} +0 -0
- /package/dist/components/toast/{useToastColor.d.ts → toastColor.d.ts} +0 -0
package/dist/dialog.js
CHANGED
|
@@ -1,38 +1,18 @@
|
|
|
1
1
|
import { t as useControllableValue } from "./useControllableValue.js";
|
|
2
|
+
import { n as toPresenceAttribute } from "./attributes.js";
|
|
3
|
+
import { i as querySelectorSafe } from "./query.js";
|
|
2
4
|
import { t as useRequiredInject } from "./useRequiredInject.js";
|
|
5
|
+
import { t as resolveHTMLElementRef } from "./componentRef.js";
|
|
6
|
+
import { t as createCancelableCustomEvent } from "./events.js";
|
|
3
7
|
import { i as useOverlayLayerBranch, n as useOverlayZIndex, r as useOverlayLayer } from "./useOverlayZIndex.js";
|
|
4
8
|
import { t as useFocusTrap } from "./useFocusTrap.js";
|
|
5
9
|
import { t as provideTeleportTarget } from "./useTeleportTarget.js";
|
|
6
10
|
import { VaporTeleport, applyVShow, computed, createComponent, createDynamicComponent, createIf, createSlot, defineVaporComponent, extend, isRef, mergeProps, nextTick, onBeforeUnmount, provide, ref, setTemplateRefBinding, shallowRef, unref, useAttrs, useId, watch } from "vue";
|
|
7
|
-
//#region src/components/dialog/
|
|
11
|
+
//#region src/components/dialog/dialogContext.ts
|
|
8
12
|
var dialogRootKey = Symbol("dialog-root");
|
|
9
13
|
function resolveDialogCloseReason(reason) {
|
|
10
14
|
return reason === "escape" || reason === "outside" || reason === "programmatic" ? reason : "programmatic";
|
|
11
15
|
}
|
|
12
|
-
function toDialogHTMLElement(value) {
|
|
13
|
-
if (typeof HTMLElement !== "undefined" && value instanceof HTMLElement) return value;
|
|
14
|
-
if (value == null || typeof Element !== "undefined" && value instanceof Element) return null;
|
|
15
|
-
const vdomElement = value.$el;
|
|
16
|
-
if (vdomElement instanceof HTMLElement) return vdomElement;
|
|
17
|
-
const vaporBlock = value.block;
|
|
18
|
-
return vaporBlock instanceof HTMLElement ? vaporBlock : null;
|
|
19
|
-
}
|
|
20
|
-
function resolveDialogHTMLElementRef(value, fallbackId, resolve) {
|
|
21
|
-
const element = toDialogHTMLElement(value) ?? (typeof document !== "undefined" ? document.getElementById(fallbackId) : null);
|
|
22
|
-
resolve(element);
|
|
23
|
-
if (element || !value) return;
|
|
24
|
-
nextTick(() => {
|
|
25
|
-
resolve(toDialogHTMLElement(value) ?? (typeof document !== "undefined" ? document.getElementById(fallbackId) : null));
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
function createDialogEvent(type, detail, originalEvent) {
|
|
29
|
-
const target = originalEvent.target;
|
|
30
|
-
return new (((typeof Node !== "undefined" && target instanceof Node ? target.ownerDocument?.defaultView : null)?.CustomEvent) ?? CustomEvent)(type, {
|
|
31
|
-
bubbles: false,
|
|
32
|
-
cancelable: true,
|
|
33
|
-
detail
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
16
|
//#endregion
|
|
37
17
|
//#region src/components/dialog/dialog-close.vue
|
|
38
18
|
var dialog_close_default = /* @__PURE__ */ defineVaporComponent({
|
|
@@ -58,7 +38,7 @@ var dialog_close_default = /* @__PURE__ */ defineVaporComponent({
|
|
|
58
38
|
type: props.as === "button" ? "button" : void 0,
|
|
59
39
|
disabled: props.as === "button" ? props.disabled || void 0 : void 0,
|
|
60
40
|
"aria-disabled": props.as === "button" ? void 0 : props.disabled || void 0,
|
|
61
|
-
"data-disabled": props.disabled
|
|
41
|
+
"data-disabled": toPresenceAttribute(props.disabled),
|
|
62
42
|
onClick
|
|
63
43
|
}));
|
|
64
44
|
return createDynamicComponent(() => __props.as, { $: [() => rootAttrs.value] }, extend(() => {
|
|
@@ -67,6 +47,94 @@ var dialog_close_default = /* @__PURE__ */ defineVaporComponent({
|
|
|
67
47
|
}
|
|
68
48
|
});
|
|
69
49
|
//#endregion
|
|
50
|
+
//#region src/components/dialog/useDialogContentInteractions.ts
|
|
51
|
+
function useDialogContentInteractions(root, props, events) {
|
|
52
|
+
const id = computed(() => props.id ?? root.contentId.value);
|
|
53
|
+
const focusTrapContainers = computed(() => {
|
|
54
|
+
const content = root.contentRef.value;
|
|
55
|
+
if (!content) return null;
|
|
56
|
+
return [content, ...root.layer.focusBranches.value];
|
|
57
|
+
});
|
|
58
|
+
let listenerDocument = null;
|
|
59
|
+
function resolveInitialFocus() {
|
|
60
|
+
const initialFocus = props.initialFocus;
|
|
61
|
+
const resolved = isRef(initialFocus) ? initialFocus.value : initialFocus;
|
|
62
|
+
if (typeof resolved !== "string") return resolved ?? void 0;
|
|
63
|
+
return querySelectorSafe(resolved, root.contentRef.value) ?? void 0;
|
|
64
|
+
}
|
|
65
|
+
const focusTrap = useFocusTrap(focusTrapContainers, {
|
|
66
|
+
...props.focusTrapOptions,
|
|
67
|
+
initialFocus: resolveInitialFocus,
|
|
68
|
+
fallbackFocus: () => root.contentRef.value,
|
|
69
|
+
returnFocusOnDeactivate: false,
|
|
70
|
+
escapeDeactivates: false,
|
|
71
|
+
allowOutsideClick: true,
|
|
72
|
+
preventScroll: true,
|
|
73
|
+
delayInitialFocus: props.focusTrapOptions.delayInitialFocus ?? false
|
|
74
|
+
});
|
|
75
|
+
function setElement(value) {
|
|
76
|
+
resolveHTMLElementRef(value, id.value, (element) => root.setContent(element, id.value));
|
|
77
|
+
}
|
|
78
|
+
function onDocumentKeydown(event) {
|
|
79
|
+
if (event.key !== "Escape" || event.defaultPrevented || !root.closeOnEscape.value || !root.layer.isTopLayer()) return;
|
|
80
|
+
const customEvent = createCancelableCustomEvent("dialog-escape-key-down", { originalEvent: event }, event);
|
|
81
|
+
events.escapeKeyDown(customEvent);
|
|
82
|
+
if (customEvent.defaultPrevented) return;
|
|
83
|
+
event.preventDefault();
|
|
84
|
+
root.close("escape");
|
|
85
|
+
}
|
|
86
|
+
function onDocumentPointerdown(event) {
|
|
87
|
+
if (event.defaultPrevented || !root.closeOnOutsideClick.value || !root.layer.isTopLayer() || root.layer.isInside(event)) return;
|
|
88
|
+
const customEvent = createCancelableCustomEvent("dialog-pointer-down-outside", { originalEvent: event }, event);
|
|
89
|
+
events.pointerDownOutside(customEvent);
|
|
90
|
+
events.interactOutside(customEvent);
|
|
91
|
+
if (!customEvent.defaultPrevented) root.close("outside");
|
|
92
|
+
}
|
|
93
|
+
function removeDocumentListeners() {
|
|
94
|
+
if (!listenerDocument) return;
|
|
95
|
+
listenerDocument.removeEventListener("keydown", onDocumentKeydown);
|
|
96
|
+
listenerDocument.removeEventListener("pointerdown", onDocumentPointerdown, true);
|
|
97
|
+
listenerDocument = null;
|
|
98
|
+
}
|
|
99
|
+
function addDocumentListeners(document) {
|
|
100
|
+
if (listenerDocument === document) return;
|
|
101
|
+
removeDocumentListeners();
|
|
102
|
+
document.addEventListener("keydown", onDocumentKeydown);
|
|
103
|
+
document.addEventListener("pointerdown", onDocumentPointerdown, true);
|
|
104
|
+
listenerDocument = document;
|
|
105
|
+
}
|
|
106
|
+
watch([
|
|
107
|
+
root.isOpen,
|
|
108
|
+
root.modal,
|
|
109
|
+
root.contentRef
|
|
110
|
+
], ([open, modal], _previous, onCleanup) => {
|
|
111
|
+
const content = root.contentRef.value;
|
|
112
|
+
if (!open || !content) {
|
|
113
|
+
focusTrap.deactivate({ returnFocus: false });
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
addDocumentListeners(content.ownerDocument);
|
|
117
|
+
if (modal) focusTrap.activate();
|
|
118
|
+
else focusTrap.deactivate({ returnFocus: false });
|
|
119
|
+
onCleanup(removeDocumentListeners);
|
|
120
|
+
}, {
|
|
121
|
+
flush: "post",
|
|
122
|
+
immediate: true
|
|
123
|
+
});
|
|
124
|
+
watch(id, (nextId) => {
|
|
125
|
+
root.setContent(root.contentRef.value, nextId);
|
|
126
|
+
}, { immediate: true });
|
|
127
|
+
onBeforeUnmount(() => {
|
|
128
|
+
removeDocumentListeners();
|
|
129
|
+
focusTrap.deactivate({ returnFocus: false });
|
|
130
|
+
root.setContent(null, id.value);
|
|
131
|
+
});
|
|
132
|
+
return {
|
|
133
|
+
id,
|
|
134
|
+
setElement
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
//#endregion
|
|
70
138
|
//#region src/components/dialog/dialog-content.vue
|
|
71
139
|
var dialog_content_default = /* @__PURE__ */ defineVaporComponent({
|
|
72
140
|
name: "RpDialogContent",
|
|
@@ -96,88 +164,17 @@ var dialog_content_default = /* @__PURE__ */ defineVaporComponent({
|
|
|
96
164
|
const emit = __emit;
|
|
97
165
|
const attrs = useAttrs();
|
|
98
166
|
const root = useRequiredInject(dialogRootKey, "RpDialogContent");
|
|
99
|
-
const id = computed(() => props.id ?? root.contentId.value);
|
|
100
167
|
const shouldRender = computed(() => props.forceMount || root.isOpen.value);
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
168
|
+
const { id, setElement } = useDialogContentInteractions(root, props, {
|
|
169
|
+
escapeKeyDown: (event) => emit("escapeKeyDown", event),
|
|
170
|
+
pointerDownOutside: (event) => emit("pointerDownOutside", event),
|
|
171
|
+
interactOutside: (event) => emit("interactOutside", event)
|
|
105
172
|
});
|
|
106
173
|
const ariaLabelledby = computed(() => {
|
|
107
174
|
if (props.ariaLabel) return void 0;
|
|
108
175
|
return props.ariaLabelledby ?? (root.titleIds.value.join(" ") || void 0);
|
|
109
176
|
});
|
|
110
177
|
const ariaDescribedby = computed(() => props.ariaDescribedby ?? (root.descriptionIds.value.join(" ") || void 0));
|
|
111
|
-
function resolveInitialFocus() {
|
|
112
|
-
const initialFocus = props.initialFocus;
|
|
113
|
-
const resolved = isRef(initialFocus) ? initialFocus.value : initialFocus;
|
|
114
|
-
if (typeof resolved !== "string") return resolved ?? void 0;
|
|
115
|
-
try {
|
|
116
|
-
return root.contentRef.value?.querySelector(resolved) ?? void 0;
|
|
117
|
-
} catch {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
const focusTrap = useFocusTrap(focusTrapContainers, {
|
|
122
|
-
...props.focusTrapOptions,
|
|
123
|
-
initialFocus: resolveInitialFocus,
|
|
124
|
-
fallbackFocus: () => root.contentRef.value,
|
|
125
|
-
returnFocusOnDeactivate: false,
|
|
126
|
-
escapeDeactivates: false,
|
|
127
|
-
allowOutsideClick: true,
|
|
128
|
-
preventScroll: true,
|
|
129
|
-
delayInitialFocus: props.focusTrapOptions.delayInitialFocus ?? false
|
|
130
|
-
});
|
|
131
|
-
function setElement(value) {
|
|
132
|
-
resolveDialogHTMLElementRef(value, id.value, (element) => root.setContent(element, id.value));
|
|
133
|
-
}
|
|
134
|
-
function onDocumentKeydown(event) {
|
|
135
|
-
if (event.key !== "Escape" || event.defaultPrevented || !root.closeOnEscape.value || !root.layer.isTopLayer()) return;
|
|
136
|
-
const customEvent = createDialogEvent("dialog-escape-key-down", { originalEvent: event }, event);
|
|
137
|
-
emit("escapeKeyDown", customEvent);
|
|
138
|
-
if (customEvent.defaultPrevented) return;
|
|
139
|
-
event.preventDefault();
|
|
140
|
-
root.close("escape");
|
|
141
|
-
}
|
|
142
|
-
function onDocumentPointerdown(event) {
|
|
143
|
-
if (event.defaultPrevented || !root.closeOnOutsideClick.value || !root.layer.isTopLayer() || root.layer.isInside(event)) return;
|
|
144
|
-
const customEvent = createDialogEvent("dialog-pointer-down-outside", { originalEvent: event }, event);
|
|
145
|
-
emit("pointerDownOutside", customEvent);
|
|
146
|
-
emit("interactOutside", customEvent);
|
|
147
|
-
if (!customEvent.defaultPrevented) root.close("outside");
|
|
148
|
-
}
|
|
149
|
-
function setDocumentListeners(active) {
|
|
150
|
-
const document = root.contentRef.value?.ownerDocument;
|
|
151
|
-
if (!document) return;
|
|
152
|
-
const method = active ? "addEventListener" : "removeEventListener";
|
|
153
|
-
document[method]("keydown", onDocumentKeydown);
|
|
154
|
-
document[method]("pointerdown", onDocumentPointerdown, true);
|
|
155
|
-
}
|
|
156
|
-
watch([
|
|
157
|
-
root.isOpen,
|
|
158
|
-
root.modal,
|
|
159
|
-
root.contentRef
|
|
160
|
-
], ([open, modal], _previous, onCleanup) => {
|
|
161
|
-
if (!open || !root.contentRef.value) {
|
|
162
|
-
focusTrap.deactivate({ returnFocus: false });
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
setDocumentListeners(true);
|
|
166
|
-
if (modal) focusTrap.activate();
|
|
167
|
-
else focusTrap.deactivate({ returnFocus: false });
|
|
168
|
-
onCleanup(() => setDocumentListeners(false));
|
|
169
|
-
}, {
|
|
170
|
-
flush: "post",
|
|
171
|
-
immediate: true
|
|
172
|
-
});
|
|
173
|
-
watch(id, (nextId) => {
|
|
174
|
-
root.setContent(root.contentRef.value, nextId);
|
|
175
|
-
}, { immediate: true });
|
|
176
|
-
onBeforeUnmount(() => {
|
|
177
|
-
setDocumentListeners(false);
|
|
178
|
-
focusTrap.deactivate({ returnFocus: false });
|
|
179
|
-
root.setContent(null, id.value);
|
|
180
|
-
});
|
|
181
178
|
const rootAttrs = computed(() => mergeProps(attrs, {
|
|
182
179
|
id: id.value,
|
|
183
180
|
role: props.role,
|
|
@@ -187,7 +184,7 @@ var dialog_content_default = /* @__PURE__ */ defineVaporComponent({
|
|
|
187
184
|
"aria-labelledby": ariaLabelledby.value,
|
|
188
185
|
"aria-describedby": ariaDescribedby.value,
|
|
189
186
|
"data-state": root.isOpen.value ? "open" : "closed",
|
|
190
|
-
"data-modal": root.modal.value
|
|
187
|
+
"data-modal": toPresenceAttribute(root.modal.value),
|
|
191
188
|
style: { zIndex: root.layer.zIndex.value }
|
|
192
189
|
}));
|
|
193
190
|
return createIf(() => shouldRender.value, () => {
|
|
@@ -198,7 +195,7 @@ var dialog_content_default = /* @__PURE__ */ defineVaporComponent({
|
|
|
198
195
|
});
|
|
199
196
|
}, { _: 8 }), 1);
|
|
200
197
|
applyVShow(n3, () => unref(root).isOpen.value);
|
|
201
|
-
setTemplateRefBinding(n3, () => setElement);
|
|
198
|
+
setTemplateRefBinding(n3, () => setElement, void 0, void 0, "setElement");
|
|
202
199
|
return n3;
|
|
203
200
|
});
|
|
204
201
|
}
|
|
@@ -259,7 +256,7 @@ var dialog_overlay_default = /* @__PURE__ */ defineVaporComponent({
|
|
|
259
256
|
style: { zIndex: root.layer.zIndex.value - 1 }
|
|
260
257
|
}));
|
|
261
258
|
function setElement(value) {
|
|
262
|
-
|
|
259
|
+
resolveHTMLElementRef(value, id.value, (resolved) => {
|
|
263
260
|
element.value = resolved;
|
|
264
261
|
});
|
|
265
262
|
}
|
|
@@ -290,8 +287,7 @@ var dialog_portal_default = /* @__PURE__ */ defineVaporComponent({
|
|
|
290
287
|
teleportTo: { default: void 0 }
|
|
291
288
|
},
|
|
292
289
|
setup(__props) {
|
|
293
|
-
const
|
|
294
|
-
const teleportTo = provideTeleportTarget(props, () => Boolean(props.teleport));
|
|
290
|
+
const teleportTo = provideTeleportTarget(__props);
|
|
295
291
|
return createComponent(VaporTeleport, {
|
|
296
292
|
to: () => unref(teleportTo),
|
|
297
293
|
disabled: () => !__props.teleport
|
|
@@ -301,6 +297,121 @@ var dialog_portal_default = /* @__PURE__ */ defineVaporComponent({
|
|
|
301
297
|
}
|
|
302
298
|
});
|
|
303
299
|
//#endregion
|
|
300
|
+
//#region src/components/dialog/useDialogRootState.ts
|
|
301
|
+
function registerId(target, id) {
|
|
302
|
+
target.value = [...target.value.filter((value) => value !== id), id];
|
|
303
|
+
return () => {
|
|
304
|
+
target.value = target.value.filter((value) => value !== id);
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
function useDialogRootState(props, events) {
|
|
308
|
+
const generatedId = useId();
|
|
309
|
+
const controllableOpen = useControllableValue({
|
|
310
|
+
modelValue: () => props.open,
|
|
311
|
+
defaultValue: () => props.defaultOpen,
|
|
312
|
+
onChange: events.openChange
|
|
313
|
+
});
|
|
314
|
+
const isOpen = controllableOpen.value;
|
|
315
|
+
const modal = computed(() => props.modal);
|
|
316
|
+
const closeOnEscape = computed(() => props.closeOnEscape);
|
|
317
|
+
const closeOnOutsideClick = computed(() => props.closeOnOutsideClick);
|
|
318
|
+
const preventScroll = computed(() => props.preventScroll);
|
|
319
|
+
const returnFocus = computed(() => props.returnFocus);
|
|
320
|
+
const triggerRef = ref(null);
|
|
321
|
+
const contentRef = ref(null);
|
|
322
|
+
const contentId = ref(`${generatedId}-dialog`);
|
|
323
|
+
const titleIds = shallowRef([]);
|
|
324
|
+
const descriptionIds = shallowRef([]);
|
|
325
|
+
let restoreFocusTo = null;
|
|
326
|
+
const layer = useOverlayLayer({
|
|
327
|
+
active: isOpen,
|
|
328
|
+
element: contentRef,
|
|
329
|
+
modal,
|
|
330
|
+
modalEffects: true,
|
|
331
|
+
preventScroll,
|
|
332
|
+
baseZIndex: useOverlayZIndex({
|
|
333
|
+
baseZIndex: () => props.baseZIndex,
|
|
334
|
+
defaultBaseZIndex: 1e3,
|
|
335
|
+
aboveParent: false
|
|
336
|
+
})
|
|
337
|
+
});
|
|
338
|
+
function setOpen(value) {
|
|
339
|
+
if (isOpen.value !== value) controllableOpen.setValue(value);
|
|
340
|
+
}
|
|
341
|
+
function rememberFocus() {
|
|
342
|
+
if (typeof document === "undefined" || restoreFocusTo) return;
|
|
343
|
+
const activeElement = document.activeElement;
|
|
344
|
+
restoreFocusTo = activeElement instanceof HTMLElement && activeElement !== document.body ? activeElement : triggerRef.value;
|
|
345
|
+
}
|
|
346
|
+
function restoreFocus() {
|
|
347
|
+
const target = restoreFocusTo ?? triggerRef.value;
|
|
348
|
+
restoreFocusTo = null;
|
|
349
|
+
if (!returnFocus.value) return;
|
|
350
|
+
nextTick(() => {
|
|
351
|
+
if (target?.isConnected) target.focus({ preventScroll: true });
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
function open() {
|
|
355
|
+
if (isOpen.value) return;
|
|
356
|
+
rememberFocus();
|
|
357
|
+
setOpen(true);
|
|
358
|
+
}
|
|
359
|
+
function close(reason = "programmatic") {
|
|
360
|
+
if (!isOpen.value) return;
|
|
361
|
+
setOpen(false);
|
|
362
|
+
events.close(resolveDialogCloseReason(reason));
|
|
363
|
+
}
|
|
364
|
+
function toggle() {
|
|
365
|
+
if (isOpen.value) close("programmatic");
|
|
366
|
+
else open();
|
|
367
|
+
}
|
|
368
|
+
function setTrigger(element) {
|
|
369
|
+
triggerRef.value = element;
|
|
370
|
+
}
|
|
371
|
+
function setContent(element, id) {
|
|
372
|
+
contentRef.value = element;
|
|
373
|
+
contentId.value = id;
|
|
374
|
+
}
|
|
375
|
+
const context = {
|
|
376
|
+
isOpen,
|
|
377
|
+
modal,
|
|
378
|
+
closeOnEscape,
|
|
379
|
+
closeOnOutsideClick,
|
|
380
|
+
returnFocus,
|
|
381
|
+
triggerRef,
|
|
382
|
+
contentRef,
|
|
383
|
+
contentId,
|
|
384
|
+
titleIds,
|
|
385
|
+
descriptionIds,
|
|
386
|
+
layer,
|
|
387
|
+
open,
|
|
388
|
+
close,
|
|
389
|
+
toggle,
|
|
390
|
+
setTrigger,
|
|
391
|
+
setContent,
|
|
392
|
+
registerTitle: (id) => registerId(titleIds, id),
|
|
393
|
+
registerDescription: (id) => registerId(descriptionIds, id)
|
|
394
|
+
};
|
|
395
|
+
const slotProps = computed(() => ({
|
|
396
|
+
isOpen: isOpen.value,
|
|
397
|
+
zIndex: layer.zIndex.value,
|
|
398
|
+
open,
|
|
399
|
+
close,
|
|
400
|
+
toggle
|
|
401
|
+
}));
|
|
402
|
+
watch(isOpen, (value, previous) => {
|
|
403
|
+
if (value && !previous) rememberFocus();
|
|
404
|
+
else if (!value && previous) restoreFocus();
|
|
405
|
+
}, { immediate: true });
|
|
406
|
+
onBeforeUnmount(() => {
|
|
407
|
+
if (isOpen.value) restoreFocus();
|
|
408
|
+
});
|
|
409
|
+
return {
|
|
410
|
+
context,
|
|
411
|
+
slotProps
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
//#endregion
|
|
304
415
|
//#region src/components/dialog/dialog-root.vue
|
|
305
416
|
var dialog_root_default = /* @__PURE__ */ defineVaporComponent({
|
|
306
417
|
name: "RpDialogRoot",
|
|
@@ -340,120 +451,17 @@ var dialog_root_default = /* @__PURE__ */ defineVaporComponent({
|
|
|
340
451
|
setup(__props, { expose: __expose, emit: __emit }) {
|
|
341
452
|
const props = __props;
|
|
342
453
|
const emit = __emit;
|
|
343
|
-
const
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
defaultValue: () => props.defaultOpen,
|
|
347
|
-
onChange: (value) => emit("update:open", value)
|
|
348
|
-
});
|
|
349
|
-
const isOpen = controllableOpen.value;
|
|
350
|
-
const modal = computed(() => props.modal);
|
|
351
|
-
const closeOnEscape = computed(() => props.closeOnEscape);
|
|
352
|
-
const closeOnOutsideClick = computed(() => props.closeOnOutsideClick);
|
|
353
|
-
const preventScroll = computed(() => props.preventScroll);
|
|
354
|
-
const returnFocus = computed(() => props.returnFocus);
|
|
355
|
-
const triggerRef = ref(null);
|
|
356
|
-
const contentRef = ref(null);
|
|
357
|
-
const contentId = ref(`${generatedId}-dialog`);
|
|
358
|
-
const titleIds = shallowRef([]);
|
|
359
|
-
const descriptionIds = shallowRef([]);
|
|
360
|
-
let restoreFocusTo = null;
|
|
361
|
-
const layer = useOverlayLayer({
|
|
362
|
-
active: isOpen,
|
|
363
|
-
element: contentRef,
|
|
364
|
-
modal,
|
|
365
|
-
modalEffects: true,
|
|
366
|
-
preventScroll,
|
|
367
|
-
baseZIndex: useOverlayZIndex({
|
|
368
|
-
baseZIndex: () => props.baseZIndex,
|
|
369
|
-
defaultBaseZIndex: 1e3,
|
|
370
|
-
aboveParent: false
|
|
371
|
-
})
|
|
372
|
-
});
|
|
373
|
-
function setOpen(value) {
|
|
374
|
-
if (isOpen.value !== value) controllableOpen.setValue(value);
|
|
375
|
-
}
|
|
376
|
-
function rememberFocus() {
|
|
377
|
-
if (typeof document === "undefined" || restoreFocusTo) return;
|
|
378
|
-
const activeElement = document.activeElement;
|
|
379
|
-
restoreFocusTo = activeElement instanceof HTMLElement && activeElement !== document.body ? activeElement : triggerRef.value;
|
|
380
|
-
}
|
|
381
|
-
function restoreFocus() {
|
|
382
|
-
const target = restoreFocusTo ?? triggerRef.value;
|
|
383
|
-
restoreFocusTo = null;
|
|
384
|
-
if (!returnFocus.value) return;
|
|
385
|
-
nextTick(() => {
|
|
386
|
-
if (target?.isConnected) target.focus({ preventScroll: true });
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
function open() {
|
|
390
|
-
if (isOpen.value) return;
|
|
391
|
-
rememberFocus();
|
|
392
|
-
setOpen(true);
|
|
393
|
-
}
|
|
394
|
-
function close(reason = "programmatic") {
|
|
395
|
-
if (!isOpen.value) return;
|
|
396
|
-
setOpen(false);
|
|
397
|
-
emit("close", resolveDialogCloseReason(reason));
|
|
398
|
-
}
|
|
399
|
-
function toggle() {
|
|
400
|
-
if (isOpen.value) close("programmatic");
|
|
401
|
-
else open();
|
|
402
|
-
}
|
|
403
|
-
function setTrigger(element) {
|
|
404
|
-
triggerRef.value = element;
|
|
405
|
-
}
|
|
406
|
-
function setContent(element, id) {
|
|
407
|
-
contentRef.value = element;
|
|
408
|
-
contentId.value = id;
|
|
409
|
-
}
|
|
410
|
-
function registerId(target, id) {
|
|
411
|
-
target.value = [...target.value.filter((value) => value !== id), id];
|
|
412
|
-
return () => {
|
|
413
|
-
target.value = target.value.filter((value) => value !== id);
|
|
414
|
-
};
|
|
415
|
-
}
|
|
416
|
-
const context = {
|
|
417
|
-
isOpen,
|
|
418
|
-
modal,
|
|
419
|
-
closeOnEscape,
|
|
420
|
-
closeOnOutsideClick,
|
|
421
|
-
returnFocus,
|
|
422
|
-
triggerRef,
|
|
423
|
-
contentRef,
|
|
424
|
-
contentId,
|
|
425
|
-
titleIds,
|
|
426
|
-
descriptionIds,
|
|
427
|
-
layer,
|
|
428
|
-
open,
|
|
429
|
-
close,
|
|
430
|
-
toggle,
|
|
431
|
-
setTrigger,
|
|
432
|
-
setContent,
|
|
433
|
-
registerTitle: (id) => registerId(titleIds, id),
|
|
434
|
-
registerDescription: (id) => registerId(descriptionIds, id)
|
|
435
|
-
};
|
|
436
|
-
const slotProps = computed(() => ({
|
|
437
|
-
isOpen: isOpen.value,
|
|
438
|
-
zIndex: layer.zIndex.value,
|
|
439
|
-
open,
|
|
440
|
-
close,
|
|
441
|
-
toggle
|
|
442
|
-
}));
|
|
443
|
-
watch(isOpen, (value, previous) => {
|
|
444
|
-
if (value && !previous) rememberFocus();
|
|
445
|
-
else if (!value && previous) restoreFocus();
|
|
446
|
-
}, { immediate: true });
|
|
447
|
-
onBeforeUnmount(() => {
|
|
448
|
-
if (isOpen.value) restoreFocus();
|
|
454
|
+
const { context, slotProps } = useDialogRootState(props, {
|
|
455
|
+
openChange: (open) => emit("update:open", open),
|
|
456
|
+
close: (reason) => emit("close", reason)
|
|
449
457
|
});
|
|
450
458
|
provide(dialogRootKey, context);
|
|
451
459
|
__expose({
|
|
452
|
-
open,
|
|
453
|
-
close,
|
|
454
|
-
toggle
|
|
460
|
+
open: context.open,
|
|
461
|
+
close: context.close,
|
|
462
|
+
toggle: context.toggle
|
|
455
463
|
});
|
|
456
|
-
return createSlot("default", { $: [() => slotProps
|
|
464
|
+
return createSlot("default", { $: [() => unref(slotProps)] });
|
|
457
465
|
}
|
|
458
466
|
});
|
|
459
467
|
//#endregion
|
|
@@ -505,7 +513,7 @@ var dialog_trigger_default = /* @__PURE__ */ defineVaporComponent({
|
|
|
505
513
|
const generatedId = `${useId()}-trigger`;
|
|
506
514
|
const id = computed(() => props.id ?? generatedId);
|
|
507
515
|
function setElement(value) {
|
|
508
|
-
|
|
516
|
+
resolveHTMLElementRef(value, id.value, root.setTrigger);
|
|
509
517
|
}
|
|
510
518
|
function onClick(event) {
|
|
511
519
|
if (event.defaultPrevented || props.disabled) return;
|
|
@@ -520,7 +528,7 @@ var dialog_trigger_default = /* @__PURE__ */ defineVaporComponent({
|
|
|
520
528
|
"aria-haspopup": "dialog",
|
|
521
529
|
"aria-disabled": props.as === "button" ? void 0 : props.disabled || void 0,
|
|
522
530
|
"data-state": root.isOpen.value ? "open" : "closed",
|
|
523
|
-
"data-disabled": props.disabled
|
|
531
|
+
"data-disabled": toPresenceAttribute(props.disabled),
|
|
524
532
|
onClick
|
|
525
533
|
}));
|
|
526
534
|
onBeforeUnmount(() => root.setTrigger(null));
|