ropav 0.16.0 → 0.16.1

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.
@@ -5,7 +5,7 @@ import SliderRoot from "./slider-root.js";
5
5
  import SliderThumb from "./slider-thumb.js";
6
6
  import SliderTrack from "./slider-track.js";
7
7
  export { SliderRoot as Slider, SliderOutput, SliderTrack, SliderFill, SliderThumb, SliderMarks };
8
- export type { SliderRootProps as SliderProps, SliderOutputProps, SliderTrackProps, SliderFillProps, SliderThumbProps, SliderMarksProps, SliderSlotProps, SliderThumbSlotProps, } from "./slider.types.js";
8
+ export type { SliderRootProps as SliderProps, SliderOutputProps, SliderTrackProps, SliderFillProps, SliderThumbProps, SliderMarksProps, SliderSlotProps, SliderTrackSlotProps, SliderThumbSlotProps, SliderValue, } from "./slider.types.js";
9
9
  export type { SliderOrientation } from "../../composables/use-slider-state.js";
10
10
  export { sliderVariants } from "@ropav/styles";
11
11
  export type { SliderVariants } from "@ropav/styles";
@@ -1,9 +1,9 @@
1
- import type { SliderRootProps, SliderSlotProps } from "./slider.types.js";
2
- declare const __VLS_export: (__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>['props'], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, 'attrs' | 'emit' | 'slots'>>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>['expose'], __VLS_setup?: Promise<{
3
- props: import('vue').PublicProps & __VLS_PrettifyLocal<SliderRootProps & {
4
- onChange?: ((value: number | number[]) => any) | undefined;
5
- onChangeEnd?: ((value: number | number[]) => any) | undefined;
6
- "onUpdate:value"?: ((value: number | number[]) => any) | undefined;
1
+ import type { SliderRootProps, SliderSlotProps, SliderValue } from "./slider.types.js";
2
+ declare const __VLS_export: <V extends SliderValue = SliderValue>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>['props'], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, 'attrs' | 'emit' | 'slots'>>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>['expose'], __VLS_setup?: Promise<{
3
+ props: import('vue').PublicProps & __VLS_PrettifyLocal<SliderRootProps<V> & {
4
+ onChange?: ((value: V extends number ? number : number[]) => any) | undefined;
5
+ onChangeEnd?: ((value: V extends number ? number : number[]) => any) | undefined;
6
+ "onUpdate:value"?: ((value: V extends number ? number : number[]) => any) | undefined;
7
7
  }> & (typeof globalThis extends {
8
8
  __VLS_PROPS_FALLBACK: infer P;
9
9
  } ? P : {});
@@ -12,7 +12,7 @@ declare const __VLS_export: (__VLS_props: NonNullable<Awaited<typeof __VLS_setup
12
12
  slots: {
13
13
  default?: (props: SliderSlotProps) => unknown;
14
14
  };
15
- emit: ((evt: "change", value: number | number[]) => void) & ((evt: "changeEnd", value: number | number[]) => void) & ((evt: "update:value", value: number | number[]) => void);
15
+ emit: ((evt: "change", value: V extends number ? number : number[]) => void) & ((evt: "changeEnd", value: V extends number ? number : number[]) => void) & ((evt: "update:value", value: V extends number ? number : number[]) => void);
16
16
  }>) => import('vue').VNode & {
17
17
  __ctx?: NonNullable<Awaited<typeof __VLS_setup>>;
18
18
  };
@@ -40,7 +40,12 @@ var slider_root_vue_vue_type_script_setup_true_vapor_true_lang_default = /*@__PU
40
40
  const props = __props;
41
41
  const fieldset = useFieldsetContext();
42
42
  const fieldsetIsDisabled = computed(() => props.isDisabled ?? fieldset?.isDisabled.value);
43
+ /**
44
+ * Written out rather than named, so the API reference reads it. `V` is inferred from the value
45
+ * itself, which makes `:default-value="30"` the literal `30`; the events report any number.
46
+ */
43
47
  const emit = __emit;
48
+ /** What the events carry, for the casts below. */
44
49
  const sliderId = useId$1(() => props.id);
45
50
  const numberFormatter = useNumberFormatter(() => props.formatOptions);
46
51
  const state = useSliderState({
@@ -1,4 +1,4 @@
1
- import type { SliderSlotProps, SliderTrackProps } from "./slider.types.js";
1
+ import type { SliderTrackProps, SliderTrackSlotProps } from "./slider.types.js";
2
2
  declare const __VLS_export: (__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>['props'], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, 'attrs' | 'emit' | 'slots'>>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>['expose'], __VLS_setup?: Promise<{
3
3
  props: import('vue').PublicProps & __VLS_PrettifyLocal<SliderTrackProps> & (typeof globalThis extends {
4
4
  __VLS_PROPS_FALLBACK: infer P;
@@ -6,7 +6,7 @@ declare const __VLS_export: (__VLS_props: NonNullable<Awaited<typeof __VLS_setup
6
6
  expose: (exposed: {}) => void;
7
7
  attrs: any;
8
8
  slots: {
9
- default?: (props: SliderSlotProps) => unknown;
9
+ default?: (props: SliderTrackSlotProps) => unknown;
10
10
  };
11
11
  emit: {};
12
12
  }>) => import('vue').VNode & {
@@ -12,6 +12,11 @@ var slider_track_vue_vue_type_script_setup_true_vapor_true_lang_default = /*@__P
12
12
  const props = __props;
13
13
  const { setTrackEl, slider, slots, state } = useSliderContext();
14
14
  const { isHovered, onPointerenter, onPointerleave } = useInteractionStates({ isDisabled: () => state.isDisabled.value });
15
+ /** Leaving ends the hover state and the value the pointer was over, together. */
16
+ const onTrackPointerleave = () => {
17
+ onPointerleave();
18
+ slider.trackHandlers.onPointerleave();
19
+ };
15
20
  /** Where the filled part of the track starts and ends, as fractions of its length. */
16
21
  const offsets = computed(() => {
17
22
  const values = state.values.value;
@@ -52,13 +57,16 @@ var slider_track_vue_vue_type_script_setup_true_vapor_true_lang_default = /*@__P
52
57
  });
53
58
  setInsertionState(n1);
54
59
  createSlot("default", {
60
+ hoverPercent: () => unref(slider).hoverPercent.value,
61
+ hoverValue: () => unref(slider).hoverValue.value,
55
62
  isDisabled: () => unref(state).isDisabled.value,
56
63
  orientation: () => unref(state).orientation.value,
57
64
  values: () => unref(state).values.value
58
65
  });
59
66
  on(n1, "pointerdown", (e) => unref(slider).trackHandlers.onPointerdown(e));
60
67
  on(n1, "pointerenter", (e) => unref(onPointerenter)(e));
61
- on(n1, "pointerleave", (e) => unref(onPointerleave)(e));
68
+ on(n1, "pointerleave", onTrackPointerleave);
69
+ on(n1, "pointermove", (e) => unref(slider).trackHandlers.onPointermove(e));
62
70
  setTemplateRefBinding(n1, () => setTrackEl, void 0, "setTrackEl");
63
71
  return n1;
64
72
  }
@@ -1,10 +1,17 @@
1
1
  import type { SliderOrientation } from "../../composables/use-slider-state.js";
2
- export interface SliderRootProps {
2
+ /** A slider's value: a number for one thumb, an array for one thumb per entry. */
3
+ export type SliderValue = number | number[];
4
+ /**
5
+ * `V` is the shape the caller hands over, inferred from `value` or `defaultValue`, so `change`
6
+ * and `change-end` report a number to a caller who passed one and an array to one who passed an
7
+ * array.
8
+ */
9
+ export interface SliderRootProps<V extends SliderValue = SliderValue> {
3
10
  class?: string;
4
11
  /** Current value. A number drives one thumb, an array one thumb per entry. */
5
- value?: number | number[];
12
+ value?: V;
6
13
  /** Value while the slider is uncontrolled. */
7
- defaultValue?: number | number[];
14
+ defaultValue?: V;
8
15
  /** @default 0 */
9
16
  minValue?: number;
10
17
  /** @default 100 */
@@ -55,6 +62,21 @@ export interface SliderSlotProps {
55
62
  orientation: SliderOrientation;
56
63
  isDisabled: boolean;
57
64
  }
65
+ /** State the track hands to its slot. */
66
+ export interface SliderTrackSlotProps extends SliderSlotProps {
67
+ /**
68
+ * The value a press would set where a mouse or pen hovers over the track, snapped to the step,
69
+ * or `null` while none hovers or the slider is disabled. For a preview of what a press would
70
+ * do, such as a tooltip.
71
+ */
72
+ hoverValue: number | null;
73
+ /**
74
+ * Where `hoverValue` sits along the track, from 0 to 1, or `null` with it. A child of the track
75
+ * placed at this fraction of its width (its height, from the bottom, when vertical) sits where
76
+ * the thumb would land.
77
+ */
78
+ hoverPercent: number | null;
79
+ }
58
80
  /** State a thumb hands to its slot. */
59
81
  export interface SliderThumbSlotProps {
60
82
  isDragging: boolean;
@@ -142,15 +142,25 @@ var useInputOTP = (options) => {
142
142
  const reassert = () => {
143
143
  setFormValue(inputEl.value, value.value);
144
144
  };
145
- watch([inputEl, value], reassert, {
145
+ /** Bumped on every change reported, so the re-assert runs even when the owner keeps the value. */
146
+ const changeCount = shallowRef(0);
147
+ watch([
148
+ inputEl,
149
+ value,
150
+ changeCount
151
+ ], reassert, {
146
152
  flush: "post",
147
153
  immediate: true
148
154
  });
149
155
  const initialValue = value.value;
150
156
  useFormReset(inputEl, () => toValue(options.defaultValue) ?? initialValue, setState);
151
157
  const setValue = (next) => {
158
+ if (next === value.value) {
159
+ reassert();
160
+ return;
161
+ }
152
162
  setState(next);
153
- reassert();
163
+ changeCount.value++;
154
164
  };
155
165
  const badge = usePasswordManagerBadge({
156
166
  container: containerEl,
@@ -2,6 +2,7 @@ import { useMove } from "./use-move.js";
2
2
  import { useFormReset } from "./use-form-reset.js";
3
3
  import { setFormValue } from "../utils/form-value.js";
4
4
  import { clamp } from "../utils/number.js";
5
+ import { getTrackTravel } from "./use-slider.js";
5
6
  import { computed, nextTick, onScopeDispose, toValue, watch, watchEffect } from "vue";
6
7
  //#region src/composables/use-slider-thumb.ts
7
8
  /**
@@ -42,8 +43,7 @@ var useSliderThumb = (options) => {
42
43
  const { handlers: moveHandlers } = useMove({
43
44
  onMove: ({ deltaX, deltaY, pointerType, shiftKey }) => {
44
45
  if (!trackEl.value) return;
45
- const rect = trackEl.value.getBoundingClientRect();
46
- const size = isVertical.value ? rect.height : rect.width;
46
+ const { size } = getTrackTravel(trackEl.value, isVertical.value);
47
47
  if (currentPosition === null) currentPosition = state.getThumbPercent(index.value) * size;
48
48
  if (pointerType === "keyboard") {
49
49
  const stepSize = shiftKey ? state.pageSize.value : state.step.value;
@@ -2,7 +2,10 @@ import type { SliderState } from "./use-slider-state.js";
2
2
  import type { CSSProperties, ComputedRef, MaybeRefOrGetter, Ref } from "vue";
3
3
  export interface UseSliderOptions {
4
4
  state: SliderState;
5
- /** The track element. Its length is the distance a thumb can travel. */
5
+ /**
6
+ * The track element. Its length, less the spacers at either end, is the distance a thumb can
7
+ * travel.
8
+ */
6
9
  trackEl: Ref<HTMLElement | null>;
7
10
  /** The group's own id, and the stem every thumb id grows from. */
8
11
  id: MaybeRefOrGetter<string>;
@@ -26,13 +29,23 @@ export interface UseSliderReturn {
26
29
  /** For the root element: the thumbs are inputs, and the group is what names them together. */
27
30
  groupProps: ComputedRef<SliderGroupAttrs>;
28
31
  /**
29
- * The track accepts clicks and drags for the nearest thumb. Attach with `@pointerdown`, never
30
- * through `v-bind`: a vapor render re-attaches every `on*` key that arrived that way, which
31
- * drops the listener when the press itself is what re-rendered the element.
32
+ * The track accepts clicks and drags for the nearest thumb, and follows a hovering pointer.
33
+ * Attach each with its own `@pointer…` listener, never through `v-bind`: a vapor render
34
+ * re-attaches every `on*` key that arrived that way, which drops the listener when the press
35
+ * itself is what re-rendered the element.
32
36
  */
33
37
  trackHandlers: {
34
38
  onPointerdown: (event: PointerEvent) => void;
39
+ onPointermove: (event: PointerEvent) => void;
40
+ onPointerleave: () => void;
35
41
  };
42
+ /**
43
+ * The value a press would set where a mouse or pen hovers over the track, snapped to the step,
44
+ * or `null` while none hovers or the slider is disabled.
45
+ */
46
+ hoverValue: ComputedRef<number | null>;
47
+ /** Where `hoverValue` sits along the thumb's travel, from 0 to 1. */
48
+ hoverPercent: ComputedRef<number | null>;
36
49
  /** Inline styles the track needs whatever the stylesheet says. */
37
50
  trackStyle: CSSProperties;
38
51
  outputProps: ComputedRef<SliderOutputAttrs>;
@@ -44,6 +57,16 @@ export interface UseSliderReturn {
44
57
  /** Hand focus to the first thumb, for a click on the label. */
45
58
  focusFirstThumb: () => void;
46
59
  }
60
+ /**
61
+ * Where a thumb's travel starts on screen and how long it is. The track's end spacers are
62
+ * borders, and the thumb is positioned inside them, so the travel is the track's box less its
63
+ * borders rather than the box itself: measured against the whole box, a press would land the
64
+ * thumb off the pointer and a drag would trail it. A vertical travel starts at the bottom.
65
+ */
66
+ export declare const getTrackTravel: (track: HTMLElement, isVertical: boolean) => {
67
+ size: number;
68
+ start: number;
69
+ };
47
70
  /**
48
71
  * Labelling, the output element, and click-and-drag on the track.
49
72
  *
@@ -1,9 +1,33 @@
1
1
  import { setInteractionModality } from "./interaction-modality.js";
2
2
  import { useMove } from "./use-move.js";
3
3
  import { clamp } from "../utils/number.js";
4
- import { computed, onScopeDispose, toValue } from "vue";
4
+ import { computed, onScopeDispose, shallowRef, toValue } from "vue";
5
5
  //#region src/composables/use-slider.ts
6
6
  /**
7
+ * Where a thumb's travel starts on screen and how long it is. The track's end spacers are
8
+ * borders, and the thumb is positioned inside them, so the travel is the track's box less its
9
+ * borders rather than the box itself: measured against the whole box, a press would land the
10
+ * thumb off the pointer and a drag would trail it. A vertical travel starts at the bottom.
11
+ */
12
+ var getTrackTravel = (track, isVertical) => {
13
+ const rect = track.getBoundingClientRect();
14
+ const style = getComputedStyle(track);
15
+ if (isVertical) {
16
+ const top = Number.parseFloat(style.borderTopWidth) || 0;
17
+ const bottom = Number.parseFloat(style.borderBottomWidth) || 0;
18
+ return {
19
+ size: rect.height - top - bottom,
20
+ start: rect.bottom - bottom
21
+ };
22
+ }
23
+ const left = Number.parseFloat(style.borderLeftWidth) || 0;
24
+ const right = Number.parseFloat(style.borderRightWidth) || 0;
25
+ return {
26
+ size: rect.width - left - right,
27
+ start: rect.left + left
28
+ };
29
+ };
30
+ /**
7
31
  * Labelling, the output element, and click-and-drag on the track.
8
32
  *
9
33
  * Ported from React Aria's `useSlider`. The track is not decoration: pressing anywhere on it
@@ -33,16 +57,23 @@ var useSlider = (options) => {
33
57
  const ids = [toValue(options.labelId), toValue(options.ariaLabelledby)].filter(Boolean);
34
58
  return ids.length > 0 ? ids.join(" ") : void 0;
35
59
  });
60
+ /** Where a hovering mouse or pen is along the travel, from 0 to 1, unsnapped. */
61
+ const hoverPosition = shallowRef(null);
62
+ const hoverValue = computed(() => hoverPosition.value === null || state.isDisabled.value ? null : state.getPercentValue(hoverPosition.value));
36
63
  /** Index of the thumb the current press on the track is dragging. */
37
64
  let draggingIndex = null;
38
65
  /** Where that thumb sits along the track, in pixels, as the drag goes on. */
39
66
  let currentPosition = null;
40
67
  let currentPointerId;
41
68
  let detachRelease;
42
- const trackSize = () => {
43
- const rect = trackEl.value?.getBoundingClientRect();
44
- if (!rect) return 0;
45
- return isVertical.value ? rect.height : rect.width;
69
+ const measureTravel = () => trackEl.value ? getTrackTravel(trackEl.value, isVertical.value) : null;
70
+ const trackSize = () => measureTravel()?.size ?? 0;
71
+ /** How far along the travel a point on screen is, from 0 to 1. */
72
+ const percentAt = (clientX, clientY) => {
73
+ const travel = measureTravel();
74
+ if (!travel || travel.size <= 0) return 0;
75
+ const offset = isVertical.value ? travel.start - clientY : clientX - travel.start;
76
+ return clamp(offset / travel.size, 0, 1);
46
77
  };
47
78
  const { handlers: moveHandlers } = useMove({
48
79
  onMove: ({ deltaX, deltaY }) => {
@@ -83,11 +114,7 @@ var useSlider = (options) => {
83
114
  const onPointerdown = (event) => {
84
115
  if (event.pointerType === "mouse" && (event.button !== 0 || event.altKey || event.ctrlKey || event.metaKey)) return;
85
116
  if (!trackEl.value || state.isDisabled.value || state.values.value.some((_, index) => state.isThumbDragging(index))) return;
86
- const rect = trackEl.value.getBoundingClientRect();
87
- const size = isVertical.value ? rect.height : rect.width;
88
- const offset = isVertical.value ? event.clientY - rect.top : event.clientX - rect.left;
89
- const percent = isVertical.value ? 1 - offset / size : offset / size;
90
- const value = state.getPercentValue(percent);
117
+ const value = state.getPercentValue(percentAt(event.clientX, event.clientY));
91
118
  const index = closestThumb(value);
92
119
  if (index < 0 || !state.isThumbEditable(index)) {
93
120
  draggingIndex = null;
@@ -121,15 +148,25 @@ var useSlider = (options) => {
121
148
  id: toValue(options.id),
122
149
  role: "group"
123
150
  })),
151
+ hoverPercent: computed(() => hoverValue.value === null ? null : state.getValuePercent(hoverValue.value)),
152
+ hoverValue,
124
153
  labelledBy,
125
154
  outputProps: computed(() => ({
126
155
  "aria-live": "off",
127
156
  for: state.values.value.map((_, index) => getThumbId(index)).join(" ")
128
157
  })),
129
- trackHandlers: { onPointerdown: (event) => {
130
- onPointerdown(event);
131
- moveHandlers.onPointerdown(event);
132
- } },
158
+ trackHandlers: {
159
+ onPointerdown: (event) => {
160
+ onPointerdown(event);
161
+ moveHandlers.onPointerdown(event);
162
+ },
163
+ onPointerleave: () => {
164
+ hoverPosition.value = null;
165
+ },
166
+ onPointermove: (event) => {
167
+ hoverPosition.value = event.pointerType === "touch" ? null : percentAt(event.clientX, event.clientY);
168
+ }
169
+ },
133
170
  trackStyle: {
134
171
  position: "relative",
135
172
  touchAction: "none"
@@ -137,4 +174,4 @@ var useSlider = (options) => {
137
174
  };
138
175
  };
139
176
  //#endregion
140
- export { useSlider };
177
+ export { getTrackTravel, useSlider };
@@ -62,6 +62,8 @@ var useTextField = (options = {}) => {
62
62
  "errorMessage"
63
63
  ]
64
64
  });
65
+ /** Bumped on every change the field reports, so the re-assert runs even when the value stays. */
66
+ const changeCount = shallowRef(0);
65
67
  /** Whether a control has taken the value over, in which case the field writes nothing. */
66
68
  const isValueOwned = shallowRef(false);
67
69
  const setValueOwned = (owned) => {
@@ -82,14 +84,19 @@ var useTextField = (options = {}) => {
82
84
  watch([
83
85
  element,
84
86
  value,
85
- isValueOwned
87
+ isValueOwned,
88
+ changeCount
86
89
  ], reassert, {
87
90
  flush: "post",
88
91
  immediate: true
89
92
  });
90
93
  const setValue = (next) => {
94
+ if (next === value.value) {
95
+ reassert();
96
+ return;
97
+ }
91
98
  setState(next);
92
- reassert();
99
+ changeCount.value++;
93
100
  };
94
101
  const initialValue = value.value;
95
102
  if (!options.skipFormReset) useFormReset(element, () => toValue(options.defaultValue) ?? initialValue, setState, options.form);