ropav 0.1.5 → 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 +10 -0
- package/dist/accordion.css +17 -17
- package/dist/accordion.js +125 -154
- package/dist/alert.css +18 -18
- package/dist/alert.js +20 -20
- 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 +10 -18
- package/dist/badge.css +16 -16
- package/dist/badge.js +6 -6
- package/dist/base.css +18 -13
- package/dist/button-group.js +1 -1
- package/dist/button-link.js +13 -14
- package/dist/button.css +32 -27
- package/dist/button.js +13 -14
- package/dist/{useButtonColor.js → button.scss_vue_type_style_index_0_src_true_lang.js} +3 -2
- package/dist/card.js +1 -1
- package/dist/checkbox.css +32 -32
- package/dist/checkbox.js +23 -29
- package/dist/collapse.css +6 -6
- package/dist/collapse.js +8 -7
- package/dist/collectionNavigation.js +2 -99
- package/dist/color-input.css +19 -19
- package/dist/color-input.js +15 -14
- package/dist/color-picker.css +40 -40
- package/dist/color-picker.js +222 -202
- package/dist/color-picker2.js +1 -9
- package/dist/color-swatch.css +4 -4
- package/dist/color-swatch.js +7 -9
- package/dist/color.js +5 -10
- package/dist/componentColors.js +165 -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 +2 -3
- package/dist/components/color-input/color-input.d.ts +2 -2
- package/dist/components/color-input/useColorInput.d.ts +1 -1
- 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} +2 -6
- 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-content.d.ts +2 -2
- 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-content.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.d.ts +3 -3
- package/dist/components/dropdown-menu/{dropdown-menu-primitive-core.d.ts → dropdownMenuContext.d.ts} +17 -19
- 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/input/useInput.d.ts +1 -1
- package/dist/components/number-input/numberInputModel.d.ts +15 -0
- package/dist/components/number-input/useNumberInput.d.ts +4 -18
- 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 +1 -7
- package/dist/components/radio/useRadio.d.ts +3 -4
- 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/types.d.ts +4 -0
- package/dist/components/scroll-area/useScrollArea.d.ts +70 -52
- package/dist/components/scroll-area/{useScrollAreaPresentation.d.ts → useScrollAreaAttributes.d.ts} +37 -14
- 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/select/useSelect.d.ts +2 -1
- package/dist/components/select/useSelectNativeValue.d.ts +1 -7
- package/dist/components/slider/rangeSliderModel.d.ts +41 -0
- package/dist/components/slider/{sliderCore.d.ts → sliderModel.d.ts} +2 -2
- package/dist/components/slider/useRangeSlider.d.ts +9 -17
- package/dist/components/slider/useRangeSliderValueState.d.ts +40 -0
- package/dist/components/slider/useSlider.d.ts +8 -14
- 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/switch/useSwitch.d.ts +1 -1
- package/dist/components/teleport-provider/index.js +1 -1
- package/dist/components/teleport-provider/useTeleportTarget.d.ts +1 -2
- package/dist/components/textarea/useTextarea.d.ts +1 -1
- package/dist/components/toast/useToastLifecycle.d.ts +19 -0
- package/dist/components/tooltip/useTooltip.d.ts +1 -2
- package/dist/composables/index.d.ts +2 -0
- package/dist/composables/index.js +2 -0
- package/dist/composables/useControllableValue.d.ts +14 -0
- package/dist/css.js +12 -0
- package/dist/dialog.js +227 -216
- package/dist/dropdown-menu.js +1493 -1118
- package/dist/events.js +59 -0
- package/dist/field.css +8 -8
- package/dist/field.js +13 -25
- package/dist/floating.js +553 -312
- package/dist/floatingOffset.js +11 -0
- package/dist/focus-trap.js +7 -5
- package/dist/focusNavigation.js +37 -0
- package/dist/icon-button.css +12 -173
- package/dist/icon-button.js +8 -7
- package/dist/index.d.ts +5 -4
- package/dist/index.js +13 -11
- package/dist/input.css +24 -24
- package/dist/input.js +20 -32
- package/dist/interactive.js +18 -0
- package/dist/modal.js +11 -7
- package/dist/number-input.css +18 -18
- package/dist/number-input.js +15 -13
- package/dist/number.js +22 -0
- package/dist/overlay.js +3 -2
- package/dist/pagination.css +28 -28
- package/dist/pagination.js +67 -65
- package/dist/pointer.js +9 -0
- package/dist/popover.css +34 -34
- package/dist/popover.js +93 -91
- package/dist/progress.css +29 -21
- package/dist/progress.js +25 -21
- package/dist/query.js +40 -0
- package/dist/radio.css +18 -18
- package/dist/radio.js +31 -37
- package/dist/rafScheduler.js +34 -0
- package/dist/scroll-area.css +35 -26
- package/dist/scroll-area.js +553 -500
- package/dist/select.css +45 -45
- package/dist/select.js +70 -56
- package/dist/slider.css +191 -191
- package/dist/slider.js +695 -628
- 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 +15 -16
- package/dist/tabs.css +46 -46
- package/dist/tabs.js +51 -68
- package/dist/text.js +17 -0
- package/dist/textarea.css +26 -26
- package/dist/textarea.js +22 -33
- package/dist/toast.css +26 -26
- package/dist/toast.js +157 -129
- package/dist/tooltip.css +12 -12
- package/dist/tooltip.js +46 -47
- package/dist/useCollapse.js +19 -17
- package/dist/useControlState.js +4 -7
- package/dist/useControllableValue.js +8 -2
- package/dist/useFloatingPosition.js +122 -1128
- package/dist/useFormControl.js +3 -2
- package/dist/useOverlayZIndex.js +2 -6
- package/dist/useRequiredInject.js +1 -1
- 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-composables-api.md +52 -0
- package/docs/public-floating-api.md +6 -5
- package/package.json +54 -46
- package/src/styles/_mixins.scss +4 -0
- package/src/styles/_tokens.scss +12 -12
- package/src/styles/_variables.scss +1 -1
- package/dist/button-link.css +0 -167
- 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 -37
- 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 -25
- package/dist/components/scroll-area/useScrollAreaControls.d.ts +0 -25
- package/dist/components/scroll-area/useScrollAreaMetrics.d.ts +0 -35
- /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/{composables → internal/composables}/useOverlayLayer.d.ts +0 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { SliderProps, SliderTrackSlotProps } from './types.js';
|
|
2
|
+
export type SliderStateProps = Readonly<SliderProps & {
|
|
3
|
+
min: number;
|
|
4
|
+
max: number;
|
|
5
|
+
step: number | 'any';
|
|
6
|
+
tooltip: NonNullable<SliderProps['tooltip']>;
|
|
7
|
+
thumb: NonNullable<SliderProps['thumb']>;
|
|
8
|
+
orientation: NonNullable<SliderProps['orientation']>;
|
|
9
|
+
}>;
|
|
10
|
+
export declare function useSliderValueState(props: SliderStateProps, onChange: (value: number) => void): {
|
|
11
|
+
inputRef: import('vue').Ref<HTMLInputElement | null, HTMLInputElement | null>;
|
|
12
|
+
focus: (options?: FocusOptions) => void;
|
|
13
|
+
control: import('../../internal/composables/useControlState.js').ControlState;
|
|
14
|
+
bounds: import('vue').ComputedRef<import('./sliderModel.js').SliderBounds>;
|
|
15
|
+
nativeMin: import('vue').ComputedRef<number>;
|
|
16
|
+
nativeMax: import('vue').ComputedRef<number>;
|
|
17
|
+
nativeStep: import('vue').ComputedRef<number | "any">;
|
|
18
|
+
normalizedValue: import('vue').ComputedRef<number>;
|
|
19
|
+
valuePercent: import('vue').ComputedRef<number>;
|
|
20
|
+
formattedValue: import('vue').ComputedRef<string | number>;
|
|
21
|
+
ariaValueText: import('vue').ComputedRef<string | undefined>;
|
|
22
|
+
markItems: import('vue').ComputedRef<{
|
|
23
|
+
key: string;
|
|
24
|
+
value: number;
|
|
25
|
+
label: string | number | undefined;
|
|
26
|
+
hasLabel: boolean;
|
|
27
|
+
filled: boolean;
|
|
28
|
+
style: import('vue').CSSProperties;
|
|
29
|
+
}[]>;
|
|
30
|
+
hasMarkLabels: import('vue').ComputedRef<boolean>;
|
|
31
|
+
trackSlotProps: import('vue').ComputedRef<SliderTrackSlotProps>;
|
|
32
|
+
onInput: (event: Event) => void;
|
|
33
|
+
};
|
|
@@ -2,7 +2,7 @@ import { CSSProperties } from 'vue';
|
|
|
2
2
|
import { SwitchProps } from './types.js';
|
|
3
3
|
export declare function useSwitch(props: Readonly<SwitchProps>, emitUpdate: (value: boolean) => void, getValue?: () => boolean): {
|
|
4
4
|
inputRef: import('vue').Ref<HTMLInputElement | null, HTMLInputElement | null>;
|
|
5
|
-
control: import('../../composables/useControlState.js').ControlState;
|
|
5
|
+
control: import('../../internal/composables/useControlState.js').ControlState;
|
|
6
6
|
rootClass: import('vue').ComputedRef<string[]>;
|
|
7
7
|
rootStyle: import('vue').ComputedRef<CSSProperties | undefined>;
|
|
8
8
|
onChange: (e: Event) => void;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as useTeleportTarget } from "../../useTeleportTarget.js";
|
|
2
2
|
import { t as teleport_provider_default } from "../../teleport-provider.js";
|
|
3
3
|
export { teleport_provider_default as TeleportProvider, useTeleportTarget };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ComputedRef, MaybeRefOrGetter } from 'vue';
|
|
2
2
|
import { TeleportTarget, TeleportTargetValue } from '../floating/types.js';
|
|
3
3
|
import { TeleportProviderProps } from './types.js';
|
|
4
|
-
export declare function provideTeleportTarget(props: Readonly<TeleportProviderProps
|
|
4
|
+
export declare function provideTeleportTarget(props: Readonly<TeleportProviderProps>): ComputedRef<TeleportTargetValue>;
|
|
5
5
|
export declare function useTeleportTarget(target?: MaybeRefOrGetter<TeleportTarget | null | undefined>): ComputedRef<TeleportTargetValue>;
|
|
6
|
-
export declare function useTeleportPositioningKey(): ComputedRef<unknown>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TextareaProps } from './types.js';
|
|
2
2
|
export declare function useTextarea(props: Readonly<TextareaProps>, emitUpdate: (value: string) => void, getValue?: () => string): {
|
|
3
3
|
textareaRef: import('vue').Ref<HTMLTextAreaElement | null, HTMLTextAreaElement | null>;
|
|
4
|
-
control: import('../../composables/useControlState.js').ControlState;
|
|
4
|
+
control: import('../../internal/composables/useControlState.js').ControlState;
|
|
5
5
|
rootClass: import('vue').ComputedRef<string[]>;
|
|
6
6
|
nativeRows: import('vue').ComputedRef<number | undefined>;
|
|
7
7
|
onInput: (e: Event) => void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { MaybeRefOrGetter } from 'vue';
|
|
2
|
+
import { ToastCloseReason } from './types.js';
|
|
3
|
+
interface UseToastLifecycleOptions {
|
|
4
|
+
isOpen: MaybeRefOrGetter<boolean>;
|
|
5
|
+
duration: MaybeRefOrGetter<number>;
|
|
6
|
+
pauseOnHover: MaybeRefOrGetter<boolean>;
|
|
7
|
+
pauseOnFocus: MaybeRefOrGetter<boolean>;
|
|
8
|
+
requestClose: (reason: ToastCloseReason) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare function useToastLifecycle(options: Readonly<UseToastLifecycleOptions>): {
|
|
11
|
+
close: (reason: ToastCloseReason) => void;
|
|
12
|
+
rootEvents: {
|
|
13
|
+
onMouseenter: () => void;
|
|
14
|
+
onMouseleave: () => void;
|
|
15
|
+
onFocusin: () => void;
|
|
16
|
+
onFocusout: (event: FocusEvent) => void;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export {};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { CSSProperties } from 'vue';
|
|
2
|
-
import {
|
|
2
|
+
import { TooltipProps, TooltipTriggerProps } from './types.js';
|
|
3
3
|
type TooltipBehaviorProps = Omit<TooltipProps, 'classNames' | 'styles'>;
|
|
4
|
-
export declare function resolveTooltipOffsetStyle(offset: TooltipOffset | undefined): CSSProperties | undefined;
|
|
5
4
|
export declare function resolveTooltipColorStyleWithContrast(color: TooltipProps['color'], autoContrast: TooltipProps['autoContrast'], contrastColor?: TooltipProps['contrastColor']): CSSProperties | undefined;
|
|
6
5
|
export declare function useTooltip(props: Readonly<TooltipBehaviorProps>, emitOpenChange?: (open: boolean) => void): {
|
|
7
6
|
rootRef: import('vue').Ref<HTMLElement | null, HTMLElement | null>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ComputedRef } from 'vue';
|
|
2
|
+
export interface UseControllableValueOptions<T> {
|
|
3
|
+
modelValue: () => T | undefined;
|
|
4
|
+
defaultValue: () => T;
|
|
5
|
+
onChange: (value: T) => void;
|
|
6
|
+
}
|
|
7
|
+
export interface UseControllableValueReturn<T> {
|
|
8
|
+
initialValue: T;
|
|
9
|
+
isControlled: ComputedRef<boolean>;
|
|
10
|
+
value: ComputedRef<T>;
|
|
11
|
+
setValue: (value: T) => void;
|
|
12
|
+
resetValue: (value?: T) => void;
|
|
13
|
+
}
|
|
14
|
+
export declare function useControllableValue<T>(options: Readonly<UseControllableValueOptions<T>>): UseControllableValueReturn<T>;
|
package/dist/css.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/utils/css.ts
|
|
2
|
+
function toCssLength(value) {
|
|
3
|
+
if (typeof value === "number") return Number.isFinite(value) ? `${value}px` : void 0;
|
|
4
|
+
if (typeof value !== "string") return void 0;
|
|
5
|
+
return value.trim() || void 0;
|
|
6
|
+
}
|
|
7
|
+
function toPositiveCssLength(value) {
|
|
8
|
+
if (typeof value === "number" && value <= 0) return void 0;
|
|
9
|
+
return toCssLength(value);
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { toPositiveCssLength as n, toCssLength as t };
|
package/dist/dialog.js
CHANGED
|
@@ -1,37 +1,18 @@
|
|
|
1
|
+
import { t as useControllableValue } from "./useControllableValue.js";
|
|
2
|
+
import { n as toPresenceAttribute } from "./attributes.js";
|
|
3
|
+
import { i as querySelectorSafe } from "./query.js";
|
|
1
4
|
import { t as useRequiredInject } from "./useRequiredInject.js";
|
|
5
|
+
import { t as resolveHTMLElementRef } from "./componentRef.js";
|
|
6
|
+
import { t as createCancelableCustomEvent } from "./events.js";
|
|
2
7
|
import { i as useOverlayLayerBranch, n as useOverlayZIndex, r as useOverlayLayer } from "./useOverlayZIndex.js";
|
|
3
8
|
import { t as useFocusTrap } from "./useFocusTrap.js";
|
|
4
9
|
import { t as provideTeleportTarget } from "./useTeleportTarget.js";
|
|
5
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";
|
|
6
|
-
//#region src/components/dialog/
|
|
11
|
+
//#region src/components/dialog/dialogContext.ts
|
|
7
12
|
var dialogRootKey = Symbol("dialog-root");
|
|
8
13
|
function resolveDialogCloseReason(reason) {
|
|
9
14
|
return reason === "escape" || reason === "outside" || reason === "programmatic" ? reason : "programmatic";
|
|
10
15
|
}
|
|
11
|
-
function toDialogHTMLElement(value) {
|
|
12
|
-
if (typeof HTMLElement !== "undefined" && value instanceof HTMLElement) return value;
|
|
13
|
-
if (value == null || typeof Element !== "undefined" && value instanceof Element) return null;
|
|
14
|
-
const vdomElement = value.$el;
|
|
15
|
-
if (vdomElement instanceof HTMLElement) return vdomElement;
|
|
16
|
-
const vaporBlock = value.block;
|
|
17
|
-
return vaporBlock instanceof HTMLElement ? vaporBlock : null;
|
|
18
|
-
}
|
|
19
|
-
function resolveDialogHTMLElementRef(value, fallbackId, resolve) {
|
|
20
|
-
const element = toDialogHTMLElement(value) ?? (typeof document !== "undefined" ? document.getElementById(fallbackId) : null);
|
|
21
|
-
resolve(element);
|
|
22
|
-
if (element || !value) return;
|
|
23
|
-
nextTick(() => {
|
|
24
|
-
resolve(toDialogHTMLElement(value) ?? (typeof document !== "undefined" ? document.getElementById(fallbackId) : null));
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
function createDialogEvent(type, detail, originalEvent) {
|
|
28
|
-
const target = originalEvent.target;
|
|
29
|
-
return new (((typeof Node !== "undefined" && target instanceof Node ? target.ownerDocument?.defaultView : null)?.CustomEvent) ?? CustomEvent)(type, {
|
|
30
|
-
bubbles: false,
|
|
31
|
-
cancelable: true,
|
|
32
|
-
detail
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
16
|
//#endregion
|
|
36
17
|
//#region src/components/dialog/dialog-close.vue
|
|
37
18
|
var dialog_close_default = /* @__PURE__ */ defineVaporComponent({
|
|
@@ -57,7 +38,7 @@ var dialog_close_default = /* @__PURE__ */ defineVaporComponent({
|
|
|
57
38
|
type: props.as === "button" ? "button" : void 0,
|
|
58
39
|
disabled: props.as === "button" ? props.disabled || void 0 : void 0,
|
|
59
40
|
"aria-disabled": props.as === "button" ? void 0 : props.disabled || void 0,
|
|
60
|
-
"data-disabled": props.disabled
|
|
41
|
+
"data-disabled": toPresenceAttribute(props.disabled),
|
|
61
42
|
onClick
|
|
62
43
|
}));
|
|
63
44
|
return createDynamicComponent(() => __props.as, { $: [() => rootAttrs.value] }, extend(() => {
|
|
@@ -66,6 +47,94 @@ var dialog_close_default = /* @__PURE__ */ defineVaporComponent({
|
|
|
66
47
|
}
|
|
67
48
|
});
|
|
68
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
|
|
69
138
|
//#region src/components/dialog/dialog-content.vue
|
|
70
139
|
var dialog_content_default = /* @__PURE__ */ defineVaporComponent({
|
|
71
140
|
name: "RpDialogContent",
|
|
@@ -95,88 +164,17 @@ var dialog_content_default = /* @__PURE__ */ defineVaporComponent({
|
|
|
95
164
|
const emit = __emit;
|
|
96
165
|
const attrs = useAttrs();
|
|
97
166
|
const root = useRequiredInject(dialogRootKey, "RpDialogContent");
|
|
98
|
-
const id = computed(() => props.id ?? root.contentId.value);
|
|
99
167
|
const shouldRender = computed(() => props.forceMount || root.isOpen.value);
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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)
|
|
104
172
|
});
|
|
105
173
|
const ariaLabelledby = computed(() => {
|
|
106
174
|
if (props.ariaLabel) return void 0;
|
|
107
175
|
return props.ariaLabelledby ?? (root.titleIds.value.join(" ") || void 0);
|
|
108
176
|
});
|
|
109
177
|
const ariaDescribedby = computed(() => props.ariaDescribedby ?? (root.descriptionIds.value.join(" ") || void 0));
|
|
110
|
-
function resolveInitialFocus() {
|
|
111
|
-
const initialFocus = props.initialFocus;
|
|
112
|
-
const resolved = isRef(initialFocus) ? initialFocus.value : initialFocus;
|
|
113
|
-
if (typeof resolved !== "string") return resolved ?? void 0;
|
|
114
|
-
try {
|
|
115
|
-
return root.contentRef.value?.querySelector(resolved) ?? void 0;
|
|
116
|
-
} catch {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
const focusTrap = useFocusTrap(focusTrapContainers, {
|
|
121
|
-
...props.focusTrapOptions,
|
|
122
|
-
initialFocus: resolveInitialFocus,
|
|
123
|
-
fallbackFocus: () => root.contentRef.value,
|
|
124
|
-
returnFocusOnDeactivate: false,
|
|
125
|
-
escapeDeactivates: false,
|
|
126
|
-
allowOutsideClick: true,
|
|
127
|
-
preventScroll: true,
|
|
128
|
-
delayInitialFocus: props.focusTrapOptions.delayInitialFocus ?? false
|
|
129
|
-
});
|
|
130
|
-
function setElement(value) {
|
|
131
|
-
resolveDialogHTMLElementRef(value, id.value, (element) => root.setContent(element, id.value));
|
|
132
|
-
}
|
|
133
|
-
function onDocumentKeydown(event) {
|
|
134
|
-
if (event.key !== "Escape" || event.defaultPrevented || !root.closeOnEscape.value || !root.layer.isTopLayer()) return;
|
|
135
|
-
const customEvent = createDialogEvent("dialog-escape-key-down", { originalEvent: event }, event);
|
|
136
|
-
emit("escapeKeyDown", customEvent);
|
|
137
|
-
if (customEvent.defaultPrevented) return;
|
|
138
|
-
event.preventDefault();
|
|
139
|
-
root.close("escape");
|
|
140
|
-
}
|
|
141
|
-
function onDocumentPointerdown(event) {
|
|
142
|
-
if (event.defaultPrevented || !root.closeOnOutsideClick.value || !root.layer.isTopLayer() || root.layer.isInside(event)) return;
|
|
143
|
-
const customEvent = createDialogEvent("dialog-pointer-down-outside", { originalEvent: event }, event);
|
|
144
|
-
emit("pointerDownOutside", customEvent);
|
|
145
|
-
emit("interactOutside", customEvent);
|
|
146
|
-
if (!customEvent.defaultPrevented) root.close("outside");
|
|
147
|
-
}
|
|
148
|
-
function setDocumentListeners(active) {
|
|
149
|
-
const document = root.contentRef.value?.ownerDocument;
|
|
150
|
-
if (!document) return;
|
|
151
|
-
const method = active ? "addEventListener" : "removeEventListener";
|
|
152
|
-
document[method]("keydown", onDocumentKeydown);
|
|
153
|
-
document[method]("pointerdown", onDocumentPointerdown, true);
|
|
154
|
-
}
|
|
155
|
-
watch([
|
|
156
|
-
root.isOpen,
|
|
157
|
-
root.modal,
|
|
158
|
-
root.contentRef
|
|
159
|
-
], ([open, modal], _previous, onCleanup) => {
|
|
160
|
-
if (!open || !root.contentRef.value) {
|
|
161
|
-
focusTrap.deactivate({ returnFocus: false });
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
setDocumentListeners(true);
|
|
165
|
-
if (modal) focusTrap.activate();
|
|
166
|
-
else focusTrap.deactivate({ returnFocus: false });
|
|
167
|
-
onCleanup(() => setDocumentListeners(false));
|
|
168
|
-
}, {
|
|
169
|
-
flush: "post",
|
|
170
|
-
immediate: true
|
|
171
|
-
});
|
|
172
|
-
watch(id, (nextId) => {
|
|
173
|
-
root.setContent(root.contentRef.value, nextId);
|
|
174
|
-
}, { immediate: true });
|
|
175
|
-
onBeforeUnmount(() => {
|
|
176
|
-
setDocumentListeners(false);
|
|
177
|
-
focusTrap.deactivate({ returnFocus: false });
|
|
178
|
-
root.setContent(null, id.value);
|
|
179
|
-
});
|
|
180
178
|
const rootAttrs = computed(() => mergeProps(attrs, {
|
|
181
179
|
id: id.value,
|
|
182
180
|
role: props.role,
|
|
@@ -186,7 +184,7 @@ var dialog_content_default = /* @__PURE__ */ defineVaporComponent({
|
|
|
186
184
|
"aria-labelledby": ariaLabelledby.value,
|
|
187
185
|
"aria-describedby": ariaDescribedby.value,
|
|
188
186
|
"data-state": root.isOpen.value ? "open" : "closed",
|
|
189
|
-
"data-modal": root.modal.value
|
|
187
|
+
"data-modal": toPresenceAttribute(root.modal.value),
|
|
190
188
|
style: { zIndex: root.layer.zIndex.value }
|
|
191
189
|
}));
|
|
192
190
|
return createIf(() => shouldRender.value, () => {
|
|
@@ -197,7 +195,7 @@ var dialog_content_default = /* @__PURE__ */ defineVaporComponent({
|
|
|
197
195
|
});
|
|
198
196
|
}, { _: 8 }), 1);
|
|
199
197
|
applyVShow(n3, () => unref(root).isOpen.value);
|
|
200
|
-
setTemplateRefBinding(n3, () => setElement);
|
|
198
|
+
setTemplateRefBinding(n3, () => setElement, void 0, void 0, "setElement");
|
|
201
199
|
return n3;
|
|
202
200
|
});
|
|
203
201
|
}
|
|
@@ -258,7 +256,7 @@ var dialog_overlay_default = /* @__PURE__ */ defineVaporComponent({
|
|
|
258
256
|
style: { zIndex: root.layer.zIndex.value - 1 }
|
|
259
257
|
}));
|
|
260
258
|
function setElement(value) {
|
|
261
|
-
|
|
259
|
+
resolveHTMLElementRef(value, id.value, (resolved) => {
|
|
262
260
|
element.value = resolved;
|
|
263
261
|
});
|
|
264
262
|
}
|
|
@@ -289,8 +287,7 @@ var dialog_portal_default = /* @__PURE__ */ defineVaporComponent({
|
|
|
289
287
|
teleportTo: { default: void 0 }
|
|
290
288
|
},
|
|
291
289
|
setup(__props) {
|
|
292
|
-
const
|
|
293
|
-
const teleportTo = provideTeleportTarget(props, () => Boolean(props.teleport));
|
|
290
|
+
const teleportTo = provideTeleportTarget(__props);
|
|
294
291
|
return createComponent(VaporTeleport, {
|
|
295
292
|
to: () => unref(teleportTo),
|
|
296
293
|
disabled: () => !__props.teleport
|
|
@@ -300,6 +297,121 @@ var dialog_portal_default = /* @__PURE__ */ defineVaporComponent({
|
|
|
300
297
|
}
|
|
301
298
|
});
|
|
302
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
|
|
303
415
|
//#region src/components/dialog/dialog-root.vue
|
|
304
416
|
var dialog_root_default = /* @__PURE__ */ defineVaporComponent({
|
|
305
417
|
name: "RpDialogRoot",
|
|
@@ -339,118 +451,17 @@ var dialog_root_default = /* @__PURE__ */ defineVaporComponent({
|
|
|
339
451
|
setup(__props, { expose: __expose, emit: __emit }) {
|
|
340
452
|
const props = __props;
|
|
341
453
|
const emit = __emit;
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
const modal = computed(() => props.modal);
|
|
346
|
-
const closeOnEscape = computed(() => props.closeOnEscape);
|
|
347
|
-
const closeOnOutsideClick = computed(() => props.closeOnOutsideClick);
|
|
348
|
-
const preventScroll = computed(() => props.preventScroll);
|
|
349
|
-
const returnFocus = computed(() => props.returnFocus);
|
|
350
|
-
const triggerRef = ref(null);
|
|
351
|
-
const contentRef = ref(null);
|
|
352
|
-
const contentId = ref(`${generatedId}-dialog`);
|
|
353
|
-
const titleIds = shallowRef([]);
|
|
354
|
-
const descriptionIds = shallowRef([]);
|
|
355
|
-
let restoreFocusTo = null;
|
|
356
|
-
const layer = useOverlayLayer({
|
|
357
|
-
active: isOpen,
|
|
358
|
-
element: contentRef,
|
|
359
|
-
modal,
|
|
360
|
-
modalEffects: true,
|
|
361
|
-
preventScroll,
|
|
362
|
-
baseZIndex: useOverlayZIndex({
|
|
363
|
-
baseZIndex: () => props.baseZIndex,
|
|
364
|
-
defaultBaseZIndex: 1e3,
|
|
365
|
-
aboveParent: false
|
|
366
|
-
})
|
|
367
|
-
});
|
|
368
|
-
function setOpen(value) {
|
|
369
|
-
const previous = isOpen.value;
|
|
370
|
-
if (props.open === void 0) uncontrolledOpen.value = value;
|
|
371
|
-
if (previous !== value) emit("update:open", value);
|
|
372
|
-
}
|
|
373
|
-
function rememberFocus() {
|
|
374
|
-
if (typeof document === "undefined" || restoreFocusTo) return;
|
|
375
|
-
const activeElement = document.activeElement;
|
|
376
|
-
restoreFocusTo = activeElement instanceof HTMLElement && activeElement !== document.body ? activeElement : triggerRef.value;
|
|
377
|
-
}
|
|
378
|
-
function restoreFocus() {
|
|
379
|
-
const target = restoreFocusTo ?? triggerRef.value;
|
|
380
|
-
restoreFocusTo = null;
|
|
381
|
-
if (!returnFocus.value) return;
|
|
382
|
-
nextTick(() => {
|
|
383
|
-
if (target?.isConnected) target.focus({ preventScroll: true });
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
function open() {
|
|
387
|
-
if (isOpen.value) return;
|
|
388
|
-
rememberFocus();
|
|
389
|
-
setOpen(true);
|
|
390
|
-
}
|
|
391
|
-
function close(reason = "programmatic") {
|
|
392
|
-
if (!isOpen.value) return;
|
|
393
|
-
setOpen(false);
|
|
394
|
-
emit("close", resolveDialogCloseReason(reason));
|
|
395
|
-
}
|
|
396
|
-
function toggle() {
|
|
397
|
-
if (isOpen.value) close("programmatic");
|
|
398
|
-
else open();
|
|
399
|
-
}
|
|
400
|
-
function setTrigger(element) {
|
|
401
|
-
triggerRef.value = element;
|
|
402
|
-
}
|
|
403
|
-
function setContent(element, id) {
|
|
404
|
-
contentRef.value = element;
|
|
405
|
-
contentId.value = id;
|
|
406
|
-
}
|
|
407
|
-
function registerId(target, id) {
|
|
408
|
-
target.value = [...target.value.filter((value) => value !== id), id];
|
|
409
|
-
return () => {
|
|
410
|
-
target.value = target.value.filter((value) => value !== id);
|
|
411
|
-
};
|
|
412
|
-
}
|
|
413
|
-
const context = {
|
|
414
|
-
isOpen,
|
|
415
|
-
modal,
|
|
416
|
-
closeOnEscape,
|
|
417
|
-
closeOnOutsideClick,
|
|
418
|
-
returnFocus,
|
|
419
|
-
triggerRef,
|
|
420
|
-
contentRef,
|
|
421
|
-
contentId,
|
|
422
|
-
titleIds,
|
|
423
|
-
descriptionIds,
|
|
424
|
-
layer,
|
|
425
|
-
open,
|
|
426
|
-
close,
|
|
427
|
-
toggle,
|
|
428
|
-
setTrigger,
|
|
429
|
-
setContent,
|
|
430
|
-
registerTitle: (id) => registerId(titleIds, id),
|
|
431
|
-
registerDescription: (id) => registerId(descriptionIds, id)
|
|
432
|
-
};
|
|
433
|
-
const slotProps = computed(() => ({
|
|
434
|
-
isOpen: isOpen.value,
|
|
435
|
-
zIndex: layer.zIndex.value,
|
|
436
|
-
open,
|
|
437
|
-
close,
|
|
438
|
-
toggle
|
|
439
|
-
}));
|
|
440
|
-
watch(isOpen, (value, previous) => {
|
|
441
|
-
if (value && !previous) rememberFocus();
|
|
442
|
-
else if (!value && previous) restoreFocus();
|
|
443
|
-
}, { immediate: true });
|
|
444
|
-
onBeforeUnmount(() => {
|
|
445
|
-
if (isOpen.value) restoreFocus();
|
|
454
|
+
const { context, slotProps } = useDialogRootState(props, {
|
|
455
|
+
openChange: (open) => emit("update:open", open),
|
|
456
|
+
close: (reason) => emit("close", reason)
|
|
446
457
|
});
|
|
447
458
|
provide(dialogRootKey, context);
|
|
448
459
|
__expose({
|
|
449
|
-
open,
|
|
450
|
-
close,
|
|
451
|
-
toggle
|
|
460
|
+
open: context.open,
|
|
461
|
+
close: context.close,
|
|
462
|
+
toggle: context.toggle
|
|
452
463
|
});
|
|
453
|
-
return createSlot("default", { $: [() => slotProps
|
|
464
|
+
return createSlot("default", { $: [() => unref(slotProps)] });
|
|
454
465
|
}
|
|
455
466
|
});
|
|
456
467
|
//#endregion
|
|
@@ -502,7 +513,7 @@ var dialog_trigger_default = /* @__PURE__ */ defineVaporComponent({
|
|
|
502
513
|
const generatedId = `${useId()}-trigger`;
|
|
503
514
|
const id = computed(() => props.id ?? generatedId);
|
|
504
515
|
function setElement(value) {
|
|
505
|
-
|
|
516
|
+
resolveHTMLElementRef(value, id.value, root.setTrigger);
|
|
506
517
|
}
|
|
507
518
|
function onClick(event) {
|
|
508
519
|
if (event.defaultPrevented || props.disabled) return;
|
|
@@ -517,7 +528,7 @@ var dialog_trigger_default = /* @__PURE__ */ defineVaporComponent({
|
|
|
517
528
|
"aria-haspopup": "dialog",
|
|
518
529
|
"aria-disabled": props.as === "button" ? void 0 : props.disabled || void 0,
|
|
519
530
|
"data-state": root.isOpen.value ? "open" : "closed",
|
|
520
|
-
"data-disabled": props.disabled
|
|
531
|
+
"data-disabled": toPresenceAttribute(props.disabled),
|
|
521
532
|
onClick
|
|
522
533
|
}));
|
|
523
534
|
onBeforeUnmount(() => root.setTrigger(null));
|