vueless 0.0.583 → 0.0.585

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.
@@ -1,10 +1,10 @@
1
1
  import { computed, onBeforeUnmount, onMounted, toValue, watch } from "vue";
2
2
  import { isSSR } from "../utils/helper.ts";
3
3
 
4
- import type { TemplateRefElement } from "../types.ts";
4
+ import type { MaybeRef } from "vue";
5
5
 
6
6
  export function useMutationObserver(
7
- target: TemplateRefElement,
7
+ target: MaybeRef<Element | Element[] | null>,
8
8
  callback: MutationCallback,
9
9
  config = { childList: true, attributes: true, characterData: true },
10
10
  ) {
@@ -1,12 +1,11 @@
1
- import type { DirectiveBinding } from "vue";
2
- import type { TemplateRefElement } from "../../types.ts";
1
+ import type { DirectiveBinding, MaybeRef } from "vue";
3
2
 
4
3
  export type RemoveEvents = () => void;
5
4
  export type ClickCallback = (event: MouseEvent) => void;
6
5
 
7
6
  export interface ClickOutsideOptions {
8
7
  capture?: boolean;
9
- ignore?: TemplateRefElement[];
8
+ ignore?: MaybeRef<Element | Element[] | null>[];
10
9
  }
11
10
 
12
11
  export interface DirectiveBindingCallback extends DirectiveBinding {
@@ -10,6 +10,10 @@ import type {
10
10
  DirectiveBindingOptions,
11
11
  } from "./types.ts";
12
12
 
13
+ function isElement(element: EventTarget | null) {
14
+ return element instanceof HTMLElement || element instanceof SVGElement;
15
+ }
16
+
13
17
  function clickOutside(
14
18
  target: MaybeRef<HTMLElement | null>,
15
19
  handler: ClickCallback,
@@ -21,9 +25,9 @@ function clickOutside(
21
25
  const el = unref(target);
22
26
 
23
27
  function onClick(event: MouseEvent) {
24
- if (!(event.target instanceof HTMLElement)) return;
28
+ if (!isElement(event.target)) return;
25
29
 
26
- const targetElements = event.composedPath().filter((element) => element instanceof HTMLElement);
30
+ const targetElements = event.composedPath().filter((element) => isElement(element));
27
31
 
28
32
  if (
29
33
  !el ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vueless",
3
- "version": "0.0.583",
3
+ "version": "0.0.585",
4
4
  "license": "MIT",
5
5
  "description": "Vue Styleless UI Component Library, powered by Tailwind CSS.",
6
6
  "keywords": [
package/types.ts CHANGED
@@ -55,12 +55,10 @@ import UInputFileConfig from "./ui.form-input-file/config.ts";
55
55
  import UInputMoneyConfig from "./ui.form-input-money/config.ts";
56
56
  import UDataListConfig from "./ui.data-list/config.ts";
57
57
 
58
- import type { ComputedRef, MaybeRef, Ref, ComponentInternalInstance } from "vue";
58
+ import type { ComputedRef, Ref, ComponentInternalInstance } from "vue";
59
59
  import type { Props } from "tippy.js";
60
60
  import type { LocaleOptions } from "./adatper.locale/vueless.ts";
61
61
 
62
- export type TemplateRefElement = MaybeRef<HTMLElement | HTMLElement[] | null>;
63
-
64
62
  export enum ColorMode {
65
63
  Dark = "dark",
66
64
  Light = "light",
@@ -42,10 +42,12 @@ import defaultConfig from "./config.ts";
42
42
  import type { UCalendarProps, DateValue, RangeDate, Locale, Config } from "./types.ts";
43
43
  import type { ComputedRef, Ref } from "vue";
44
44
  import type { DateLocale } from "./utilFormatting.ts";
45
+ import type { ComponentExposed } from "../types.ts";
45
46
 
46
47
  import DayView from "./UCalendarDayView.vue";
47
48
  import MonthView from "./UCalendarMonthView.vue";
48
49
  import YearView from "./UCalendarYearView.vue";
50
+ import { nextTick } from "process";
49
51
 
50
52
  type DefaultLocale = typeof defaultConfig.i18n;
51
53
 
@@ -97,6 +99,7 @@ const wrapperRef = useTemplateRef<HTMLDivElement>("wrapper");
97
99
  const hoursRef = useTemplateRef<HTMLInputElement>("hours-input");
98
100
  const minutesRef = useTemplateRef<HTMLInputElement>("minutes-input");
99
101
  const secondsRef = useTemplateRef<HTMLInputElement>("seconds-input");
102
+ const okButton = useTemplateRef<ComponentExposed<typeof UButton>>("ok-button");
100
103
 
101
104
  const activeDate: Ref<Date | null> = ref(null);
102
105
  const activeMonth: Ref<Date | null> = ref(null);
@@ -319,13 +322,13 @@ watch(
319
322
  watch(
320
323
  selectedDate,
321
324
  () => {
322
- if (selectedDate.value && isTimepickerEnabled.value && isInputRefs.value && props.timepicker) {
323
- hoursRef.value!.value = String(selectedDate.value.getHours()).padStart(2, "0");
324
- minutesRef.value!.value = String(selectedDate.value.getMinutes()).padStart(2, "0");
325
- secondsRef.value!.value = String(selectedDate.value.getSeconds()).padStart(2, "0");
326
-
327
- emit("userDateChange", userFormattedDate.value);
328
- }
325
+ nextTick(() => {
326
+ if (selectedDate.value && isTimepickerEnabled.value && isInputRefs.value) {
327
+ hoursRef.value!.value = String(selectedDate.value.getHours()).padStart(2, "0");
328
+ minutesRef.value!.value = String(selectedDate.value.getMinutes()).padStart(2, "0");
329
+ secondsRef.value!.value = String(selectedDate.value.getSeconds()).padStart(2, "0");
330
+ }
331
+ });
329
332
 
330
333
  if (selectedDate.value) {
331
334
  emit("userDateChange", userFormattedDate.value);
@@ -557,6 +560,24 @@ function onClickSubmit() {
557
560
  emit("submit");
558
561
  }
559
562
 
563
+ function onClickTimeInput(event: MouseEvent) {
564
+ const input = event.target as HTMLInputElement;
565
+
566
+ selectTimeInput(input);
567
+ }
568
+
569
+ function onFocusTimeInput(event: FocusEvent) {
570
+ const input = event.target as HTMLInputElement;
571
+
572
+ selectTimeInput(input);
573
+ }
574
+
575
+ function selectTimeInput(input: HTMLInputElement) {
576
+ const value = input.value;
577
+
578
+ input.setSelectionRange(0, value.length, "backward");
579
+ }
580
+
560
581
  function onTimeInput(event: InputEvent, type: InputType) {
561
582
  const input = event.target as HTMLInputElement;
562
583
  const value = input.value;
@@ -586,22 +607,38 @@ function onTimeInput(event: InputEvent, type: InputType) {
586
607
 
587
608
  if (event.data !== null && !isNumeric(event.data)) {
588
609
  if (isHours) {
589
- input.value = String(lastValidHourValue);
610
+ input.value = String(lastValidHourValue).padStart(2, "0");
590
611
  }
591
612
 
592
613
  if (isMinutes) {
593
- input.value = String(lastValidMinuteValue);
614
+ input.value = String(lastValidMinuteValue).padStart(2, "0");
594
615
  }
595
616
 
596
617
  if (isSeconds) {
597
- input.value = String(lastValidSecondValue);
618
+ input.value = String(lastValidSecondValue).padStart(2, "0");
598
619
  }
599
620
 
600
621
  return;
601
622
  }
602
623
 
603
624
  if (numericValue > maxValue || numericValue < minValue) {
604
- input.value = "0".padStart(2, "0");
625
+ if (isHours && minutesRef.value) {
626
+ input.value = String(lastValidHourValue).padStart(2, "0");
627
+
628
+ minutesRef.value.focus();
629
+ }
630
+
631
+ if (isMinutes && secondsRef.value) {
632
+ input.value = String(lastValidMinuteValue).padStart(2, "0");
633
+
634
+ secondsRef.value.focus();
635
+ }
636
+
637
+ if (isSeconds && okButton.value) {
638
+ input.value = String(lastValidSecondValue).padStart(2, "0");
639
+
640
+ okButton.value.buttonRef?.focus();
641
+ }
605
642
 
606
643
  return;
607
644
  }
@@ -759,6 +796,8 @@ const {
759
796
  type="text"
760
797
  v-bind="timepickerInputHoursAttrs"
761
798
  @input.prevent="onTimeInput($event as InputEvent, InputType.Hours)"
799
+ @click.prevent="onClickTimeInput"
800
+ @focus.prevent="onFocusTimeInput"
762
801
  @keydown="onTimeKeydown"
763
802
  />
764
803
  &#8282;
@@ -768,6 +807,8 @@ const {
768
807
  type="text"
769
808
  v-bind="timepickerInputMinutesAttrs"
770
809
  @input.prevent="onTimeInput($event as InputEvent, InputType.Minutes)"
810
+ @click.prevent="onClickTimeInput"
811
+ @focus.prevent="onFocusTimeInput"
771
812
  @keydown="onTimeKeydown"
772
813
  />
773
814
  &#8282;
@@ -777,11 +818,14 @@ const {
777
818
  type="text"
778
819
  v-bind="timepickerInputSecondsAttrs"
779
820
  @input.prevent="onTimeInput($event as InputEvent, InputType.Seconds)"
821
+ @click.prevent="onClickTimeInput"
822
+ @focus.prevent="onFocusTimeInput"
780
823
  @keydown="onTimeKeydown"
781
824
  />
782
825
  </div>
783
826
 
784
827
  <UButton
828
+ ref="ok-button"
785
829
  variant="thirdary"
786
830
  size="sm"
787
831
  filled
@@ -131,7 +131,10 @@ function onSubmit() {
131
131
 
132
132
  function onInput() {
133
133
  nextTick(() => {
134
- deactivate();
134
+ if (!props.timepicker) {
135
+ deactivate();
136
+ }
137
+
135
138
  emit("input", localValue.value);
136
139
  });
137
140
  }
package/web-types.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "framework": "vue",
3
3
  "name": "vueless",
4
- "version": "0.0.583",
4
+ "version": "0.0.585",
5
5
  "contributions": {
6
6
  "html": {
7
7
  "description-markup": "markdown",