vueless 1.4.0 → 1.4.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vueless",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "Vue Styleless UI Component Library, powered by Tailwind CSS.",
5
5
  "author": "Johnny Grid <hello@vueless.com> (https://vueless.com)",
6
6
  "homepage": "https://vueless.com",
@@ -57,7 +57,7 @@
57
57
  "@vue/eslint-config-typescript": "^14.6.0",
58
58
  "@vue/test-utils": "^2.4.6",
59
59
  "@vue/tsconfig": "^0.7.0",
60
- "@vueless/storybook": "^1.4.10",
60
+ "@vueless/storybook": "^1.4.11",
61
61
  "eslint": "^9.32.0",
62
62
  "eslint-plugin-storybook": "^10.0.2",
63
63
  "eslint-plugin-vue": "^10.3.0",
@@ -1,6 +1,6 @@
1
1
  <script setup lang="ts">
2
- import { computed, useSlots, useTemplateRef } from "vue";
3
- import { RouterLink, useRoute, useRouter } from "vue-router";
2
+ import { computed, inject, useSlots, useTemplateRef } from "vue";
3
+ import { RouterLink, routerKey, routeLocationKey } from "vue-router";
4
4
 
5
5
  import { useUI } from "../composables/useUI";
6
6
  import { hasSlotContent } from "../utils/helper";
@@ -49,11 +49,12 @@ const emit = defineEmits([
49
49
  const slots = useSlots();
50
50
 
51
51
  const linkRef = useTemplateRef<HTMLLinkElement>("link");
52
- const route = useRoute();
53
- const router = useRouter();
52
+
53
+ const router = inject(routerKey, undefined);
54
+ const route = inject(routeLocationKey, undefined);
54
55
 
55
56
  const isPresentRoute = computed(() => {
56
- return typeof props.to === "string" || typeof props.to === "object";
57
+ return (typeof props.to === "string" || typeof props.to === "object") && router !== undefined;
57
58
  });
58
59
 
59
60
  const safeTo = computed(() => {
@@ -61,7 +62,7 @@ const safeTo = computed(() => {
61
62
  });
62
63
 
63
64
  const isActive = computed(() => {
64
- if (!isPresentRoute.value) return false;
65
+ if (!isPresentRoute.value || !router || !route) return false;
65
66
 
66
67
  try {
67
68
  const resolved = router.resolve(safeTo.value);
@@ -28,7 +28,7 @@ const emit = defineEmits([
28
28
  * Triggers on a dropdown option click.
29
29
  * @property {string} value
30
30
  */
31
- "clickOption",
31
+ "click-option",
32
32
 
33
33
  /**
34
34
  * Triggers when an option is selected.
@@ -51,7 +51,7 @@ const emit = defineEmits([
51
51
  * Triggers when the search value is changed.
52
52
  * @property {string} query
53
53
  */
54
- "searchChange",
54
+ "search-change",
55
55
 
56
56
  /**
57
57
  * Triggers when the search v-model updates.
@@ -128,13 +128,13 @@ const fullLabel = computed(() => {
128
128
  });
129
129
 
130
130
  function onSearchChange(query: string) {
131
- emit("searchChange", query);
131
+ emit("search-change", query);
132
132
  }
133
133
 
134
134
  function onClickOption(option: Option) {
135
135
  isClickingOption.value = true;
136
136
 
137
- emit("clickOption", option);
137
+ emit("click-option", option);
138
138
 
139
139
  if (props.closeOnSelect) {
140
140
  hide();
@@ -455,7 +455,7 @@ describe("UDropdown.vue", () => {
455
455
  expect(component.emitted("close")).toBeTruthy();
456
456
  });
457
457
 
458
- it("ClickOption – emits clickOption event when an option is clicked", async () => {
458
+ it("ClickOption – emits click-option event when an option is clicked", async () => {
459
459
  const component = mount(UDropdown, {
460
460
  props: {
461
461
  options: defaultOptions,
@@ -472,10 +472,10 @@ describe("UDropdown.vue", () => {
472
472
 
473
473
  await listbox.vm.$emit("click-option", defaultOptions[0]);
474
474
 
475
- expect(component.emitted("clickOption")).toBeTruthy();
475
+ expect(component.emitted("click-option")).toBeTruthy();
476
476
  });
477
477
 
478
- it("SearchChange – emits searchChange event when search value changes", async () => {
478
+ it("SearchChange – emits search-change event when search value changes", async () => {
479
479
  const component = mount(UDropdown, {
480
480
  props: {
481
481
  searchable: true,
@@ -493,8 +493,8 @@ describe("UDropdown.vue", () => {
493
493
 
494
494
  await listbox.vm.$emit("search-change", "test query");
495
495
 
496
- expect(component.emitted("searchChange")).toBeTruthy();
497
- expect(component.emitted("searchChange")![0][0]).toBe("test query");
496
+ expect(component.emitted("search-change")).toBeTruthy();
497
+ expect(component.emitted("search-change")![0][0]).toBe("test query");
498
498
  });
499
499
 
500
500
  it("Update:search – emits update:search event when search value updates", async () => {
@@ -27,7 +27,7 @@ const emit = defineEmits([
27
27
  * Triggers on a dropdown option click.
28
28
  * @property {string} value
29
29
  */
30
- "clickOption",
30
+ "click-option",
31
31
 
32
32
  /**
33
33
  * Triggers when an option is selected.
@@ -50,7 +50,7 @@ const emit = defineEmits([
50
50
  * Triggers when the search value is changed.
51
51
  * @property {string} query
52
52
  */
53
- "searchChange",
53
+ "search-change",
54
54
 
55
55
  /**
56
56
  * Triggers when the search v-model updates.
@@ -127,10 +127,10 @@ const { getDataTest, config, toggleBadgeAttrs, dropdownBadgeAttrs, toggleIconAtt
127
127
  :close-on-select="closeOnSelect"
128
128
  v-bind="dropdownBadgeAttrs"
129
129
  :data-test="dataTest"
130
- @click-option="(option) => emit('clickOption', option)"
130
+ @click-option="(option) => emit('click-option', option)"
131
131
  @update:model-value="(value) => emit('update:modelValue', value)"
132
132
  @update:search="(value) => emit('update:search', value)"
133
- @search-change="(query) => emit('searchChange', query)"
133
+ @search-change="(query) => emit('search-change', query)"
134
134
  @open="emit('open')"
135
135
  @close="emit('close')"
136
136
  >
@@ -630,7 +630,7 @@ describe("UDropdownBadge.vue", () => {
630
630
  expect(component.emitted("update:modelValue")?.[0]).toEqual([2]);
631
631
  });
632
632
 
633
- it("clickOption – emits clickOption event when an option is clicked", async () => {
633
+ it("click-option – emits click-option event when an option is clicked", async () => {
634
634
  const component = mount(UDropdownBadge, {
635
635
  props: {
636
636
  options: defaultOptions,
@@ -643,12 +643,12 @@ describe("UDropdownBadge.vue", () => {
643
643
  // Find the listbox component
644
644
  const listbox = component.findComponent(UListbox);
645
645
 
646
- // Simulate clicking an option by emitting clickOption from the listbox
647
- listbox.vm.$emit("clickOption", defaultOptions[1]);
646
+ // Simulate clicking an option by emitting click-option from the listbox
647
+ listbox.vm.$emit("click-option", defaultOptions[1]);
648
648
 
649
649
  // Check if the event was emitted with the correct value
650
- expect(component.emitted("clickOption")).toBeTruthy();
651
- expect(component.emitted("clickOption")?.[0]).toEqual([defaultOptions[1]]);
650
+ expect(component.emitted("click-option")).toBeTruthy();
651
+ expect(component.emitted("click-option")?.[0]).toEqual([defaultOptions[1]]);
652
652
  });
653
653
 
654
654
  it("Close – closes dropdown when clicking outside", async () => {
@@ -698,7 +698,7 @@ describe("UDropdownBadge.vue", () => {
698
698
  expect(component.emitted("close")).toBeTruthy();
699
699
  });
700
700
 
701
- it("SearchChange – emits searchChange event when search value changes", async () => {
701
+ it("SearchChange – emits search-change event when search value changes", async () => {
702
702
  const component = mount(UDropdownBadge, {
703
703
  props: {
704
704
  searchable: true,
@@ -710,10 +710,10 @@ describe("UDropdownBadge.vue", () => {
710
710
 
711
711
  const dropdown = component.findComponent({ name: "UDropdown" });
712
712
 
713
- dropdown.vm.$emit("searchChange", "test query");
713
+ dropdown.vm.$emit("search-change", "test query");
714
714
 
715
- expect(component.emitted("searchChange")).toBeTruthy();
716
- expect(component.emitted("searchChange")?.[0]).toEqual(["test query"]);
715
+ expect(component.emitted("search-change")).toBeTruthy();
716
+ expect(component.emitted("search-change")?.[0]).toEqual(["test query"]);
717
717
  });
718
718
 
719
719
  it("Update:search – emits update:search event when search value updates", async () => {
@@ -27,7 +27,7 @@ const emit = defineEmits([
27
27
  * Triggers on a dropdown option click.
28
28
  * @property {string} value
29
29
  */
30
- "clickOption",
30
+ "click-option",
31
31
 
32
32
  /**
33
33
  * Triggers when an option is selected.
@@ -50,7 +50,7 @@ const emit = defineEmits([
50
50
  * Triggers when the search value is changed.
51
51
  * @property {string} query
52
52
  */
53
- "searchChange",
53
+ "search-change",
54
54
 
55
55
  /**
56
56
  * Triggers when the search v-model updates.
@@ -126,10 +126,10 @@ const { getDataTest, config, toggleButtonAttrs, dropdownButtonAttrs, toggleIconA
126
126
  :close-on-select="closeOnSelect"
127
127
  v-bind="dropdownButtonAttrs"
128
128
  :data-test="dataTest"
129
- @click-option="(option) => emit('clickOption', option)"
129
+ @click-option="(option) => emit('click-option', option)"
130
130
  @update:model-value="(value) => emit('update:modelValue', value)"
131
131
  @update:search="(value) => emit('update:search', value)"
132
- @search-change="(query) => emit('searchChange', query)"
132
+ @search-change="(query) => emit('search-change', query)"
133
133
  @open="emit('open')"
134
134
  @close="emit('close')"
135
135
  >
@@ -652,7 +652,7 @@ describe("UDropdownButton.vue", () => {
652
652
  expect(component.emitted("update:modelValue")?.[0]).toEqual([2]);
653
653
  });
654
654
 
655
- it("clickOption – emits clickOption event when an option is clicked", async () => {
655
+ it("click-option – emits click-option event when an option is clicked", async () => {
656
656
  const component = mount(UDropdownButton, {
657
657
  props: {
658
658
  options: defaultOptions,
@@ -665,12 +665,12 @@ describe("UDropdownButton.vue", () => {
665
665
  // Find the listbox component
666
666
  const listbox = component.findComponent(UListbox);
667
667
 
668
- // Simulate clicking an option by emitting clickOption from the listbox
669
- listbox.vm.$emit("clickOption", defaultOptions[1]);
668
+ // Simulate clicking an option by emitting click-option from the listbox
669
+ listbox.vm.$emit("click-option", defaultOptions[1]);
670
670
 
671
671
  // Check if the event was emitted with the correct value
672
- expect(component.emitted("clickOption")).toBeTruthy();
673
- expect(component.emitted("clickOption")?.[0]).toEqual([defaultOptions[1]]);
672
+ expect(component.emitted("click-option")).toBeTruthy();
673
+ expect(component.emitted("click-option")?.[0]).toEqual([defaultOptions[1]]);
674
674
  });
675
675
 
676
676
  it("Close – closes dropdown when clicking outside", async () => {
@@ -720,7 +720,7 @@ describe("UDropdownButton.vue", () => {
720
720
  expect(component.emitted("close")).toBeTruthy();
721
721
  });
722
722
 
723
- it("SearchChange – emits searchChange event when search value changes", async () => {
723
+ it("SearchChange – emits search-change event when search value changes", async () => {
724
724
  const component = mount(UDropdownButton, {
725
725
  props: {
726
726
  searchable: true,
@@ -732,10 +732,10 @@ describe("UDropdownButton.vue", () => {
732
732
 
733
733
  const dropdown = component.findComponent({ name: "UDropdown" });
734
734
 
735
- dropdown.vm.$emit("searchChange", "test query");
735
+ dropdown.vm.$emit("search-change", "test query");
736
736
 
737
- expect(component.emitted("searchChange")).toBeTruthy();
738
- expect(component.emitted("searchChange")?.[0]).toEqual(["test query"]);
737
+ expect(component.emitted("search-change")).toBeTruthy();
738
+ expect(component.emitted("search-change")?.[0]).toEqual(["test query"]);
739
739
  });
740
740
 
741
741
  it("Update:search – emits update:search event when search value updates", async () => {
@@ -27,7 +27,7 @@ const emit = defineEmits([
27
27
  * Triggers on a dropdown option click.
28
28
  * @property {string} value
29
29
  */
30
- "clickOption",
30
+ "click-option",
31
31
 
32
32
  /**
33
33
  * Triggers when an option is selected.
@@ -50,7 +50,7 @@ const emit = defineEmits([
50
50
  * Triggers when the search value is changed.
51
51
  * @property {string} query
52
52
  */
53
- "searchChange",
53
+ "search-change",
54
54
 
55
55
  /**
56
56
  * Triggers when the search v-model updates.
@@ -130,10 +130,10 @@ const { config, getDataTest, dropdownLinkAttrs, toggleLinkAttrs, toggleIconAttrs
130
130
  :close-on-select="closeOnSelect"
131
131
  v-bind="dropdownLinkAttrs"
132
132
  :data-test="dataTest"
133
- @click-option="(option) => emit('clickOption', option)"
133
+ @click-option="(option) => emit('click-option', option)"
134
134
  @update:model-value="(value) => emit('update:modelValue', value)"
135
135
  @update:search="(value) => emit('update:search', value)"
136
- @search-change="(query) => emit('searchChange', query)"
136
+ @search-change="(query) => emit('search-change', query)"
137
137
  @open="emit('open')"
138
138
  @close="emit('close')"
139
139
  >
@@ -628,7 +628,7 @@ describe("UDropdownLink.vue", () => {
628
628
  expect(component.emitted("update:modelValue")?.[0]).toEqual([2]);
629
629
  });
630
630
 
631
- it("clickOption – emits clickOption event when an option is clicked", async () => {
631
+ it("click-option – emits click-option event when an option is clicked", async () => {
632
632
  const component = mount(UDropdownLink, {
633
633
  props: {
634
634
  options: defaultOptions,
@@ -641,14 +641,14 @@ describe("UDropdownLink.vue", () => {
641
641
  // Find the listbox component
642
642
  const listbox = component.findComponent(UListbox);
643
643
 
644
- // Simulate clicking an option by emitting clickOption from the listbox
644
+ // Simulate clicking an option by emitting click-option from the listbox
645
645
  const option = defaultOptions[1];
646
646
 
647
- listbox.vm.$emit("clickOption", option);
647
+ listbox.vm.$emit("click-option", option);
648
648
 
649
649
  // Check if the event was emitted with the correct value
650
- expect(component.emitted("clickOption")).toBeTruthy();
651
- expect(component.emitted("clickOption")?.[0]).toEqual([option]);
650
+ expect(component.emitted("click-option")).toBeTruthy();
651
+ expect(component.emitted("click-option")?.[0]).toEqual([option]);
652
652
  });
653
653
 
654
654
  it("Close – closes dropdown when clicking outside", async () => {
@@ -716,7 +716,7 @@ describe("UDropdownLink.vue", () => {
716
716
  expect(component.emitted("close")).toBeTruthy();
717
717
  });
718
718
 
719
- it("SearchChange – emits searchChange event when search value changes", async () => {
719
+ it("SearchChange – emits search-change event when search value changes", async () => {
720
720
  const component = mount(UDropdownLink, {
721
721
  props: {
722
722
  searchable: true,
@@ -728,10 +728,10 @@ describe("UDropdownLink.vue", () => {
728
728
 
729
729
  const dropdown = component.findComponent({ name: "UDropdown" });
730
730
 
731
- dropdown.vm.$emit("searchChange", "test query");
731
+ dropdown.vm.$emit("search-change", "test query");
732
732
 
733
- expect(component.emitted("searchChange")).toBeTruthy();
734
- expect(component.emitted("searchChange")?.[0]).toEqual(["test query"]);
733
+ expect(component.emitted("search-change")).toBeTruthy();
734
+ expect(component.emitted("search-change")?.[0]).toEqual(["test query"]);
735
735
  });
736
736
 
737
737
  it("Update:search – emits update:search event when search value updates", async () => {
@@ -45,18 +45,18 @@ const emit = defineEmits([
45
45
  /**
46
46
  * Triggers on click option.
47
47
  */
48
- "clickOption",
48
+ "click-option",
49
49
 
50
50
  /**
51
51
  * Triggers when the search input value changes.
52
52
  * @property {string} value
53
53
  */
54
- "searchChange",
54
+ "search-change",
55
55
 
56
56
  /**
57
57
  * Triggers when the search input loses focus.
58
58
  */
59
- "searchBlur",
59
+ "search-blur",
60
60
 
61
61
  /**
62
62
  * Triggers when the search v-model updates.
@@ -246,7 +246,7 @@ function onClickAddOption() {
246
246
  }
247
247
 
248
248
  function onSearchChange(value: string) {
249
- emit("searchChange", value);
249
+ emit("search-change", value);
250
250
  }
251
251
 
252
252
  function onKeydownUp() {
@@ -341,11 +341,11 @@ function onClickOption(rawOption: Option) {
341
341
  rawOption.onClick(option);
342
342
  }
343
343
 
344
- emit("clickOption", option);
344
+ emit("click-option", option);
345
345
  }
346
346
 
347
347
  function onInputSearchBlur(event: FocusEvent) {
348
- emit("searchBlur", event);
348
+ emit("search-blur", event);
349
349
  }
350
350
 
351
351
  defineExpose({
@@ -474,7 +474,7 @@ describe("UListbox.vue", () => {
474
474
  expect(options[0].text()).toBe(targetValue);
475
475
  });
476
476
 
477
- it("Search – emits searchChange event on input", async () => {
477
+ it("Search – emits search-change event on input", async () => {
478
478
  const targetValue = "test";
479
479
 
480
480
  const component = mount(UListbox, {
@@ -488,11 +488,11 @@ describe("UListbox.vue", () => {
488
488
 
489
489
  await searchInput.setValue(targetValue);
490
490
 
491
- expect(component.emitted("searchChange")).toBeTruthy();
492
- expect(component.emitted("searchChange")![0][0]).toBe(targetValue);
491
+ expect(component.emitted("search-change")).toBeTruthy();
492
+ expect(component.emitted("search-change")![0][0]).toBe(targetValue);
493
493
  });
494
494
 
495
- it("Search – emits searchBlur event on blur", async () => {
495
+ it("Search – emits search-blur event on blur", async () => {
496
496
  const component = mount(UListbox, {
497
497
  props: {
498
498
  searchable: true,
@@ -504,7 +504,7 @@ describe("UListbox.vue", () => {
504
504
 
505
505
  await searchInput.trigger("blur");
506
506
 
507
- expect(component.emitted("searchBlur")).toBeTruthy();
507
+ expect(component.emitted("search-blur")).toBeTruthy();
508
508
  });
509
509
 
510
510
  it("Keyboard Navigation – moves pointer down with arrow down", async () => {
@@ -719,8 +719,8 @@ describe("UListbox.vue", () => {
719
719
 
720
720
  await firstOption.trigger("click");
721
721
 
722
- expect(component.emitted("clickOption")).toBeTruthy();
723
- expect(component.emitted("clickOption")![0][0]).toEqual(defaultOptions[0]);
722
+ expect(component.emitted("click-option")).toBeTruthy();
723
+ expect(component.emitted("click-option")![0][0]).toEqual(defaultOptions[0]);
724
724
  });
725
725
 
726
726
  it("Search Change – emits when search input changes", async () => {
@@ -737,8 +737,8 @@ describe("UListbox.vue", () => {
737
737
 
738
738
  await searchInput.setValue("test");
739
739
 
740
- expect(component.emitted("searchChange")).toBeTruthy();
741
- expect(component.emitted("searchChange")![0][0]).toBe(expectedValue);
740
+ expect(component.emitted("search-change")).toBeTruthy();
741
+ expect(component.emitted("search-change")![0][0]).toBe(expectedValue);
742
742
  });
743
743
 
744
744
  it("Search Blur – emits when search input loses focus", async () => {
@@ -753,7 +753,7 @@ describe("UListbox.vue", () => {
753
753
 
754
754
  await searchInput.get("input").trigger("blur");
755
755
 
756
- expect(component.emitted("searchBlur")).toBeTruthy();
756
+ expect(component.emitted("search-blur")).toBeTruthy();
757
757
  });
758
758
  });
759
759
 
@@ -55,7 +55,7 @@ const emit = defineEmits([
55
55
  * Triggers when the search value is changed.
56
56
  * @property {string} query
57
57
  */
58
- "searchChange",
58
+ "search-change",
59
59
 
60
60
  /**
61
61
  * Triggers when the search v-model updates.
@@ -251,7 +251,7 @@ onMounted(() => {
251
251
  });
252
252
 
253
253
  function onSearchChange(query: string) {
254
- emit("searchChange", query);
254
+ emit("search-change", query);
255
255
  }
256
256
 
257
257
  function onSearchUpdate(query: string) {
@@ -848,8 +848,8 @@ describe("USelect.vue", () => {
848
848
 
849
849
  vi.advanceTimersByTime(300); // Simulate debounce delay
850
850
 
851
- expect(component.emitted("searchChange")).toBeDefined();
852
- expect(component.emitted("searchChange")![0][0]).toBe(testValue);
851
+ expect(component.emitted("search-change")).toBeDefined();
852
+ expect(component.emitted("search-change")![0][0]).toBe(testValue);
853
853
 
854
854
  vi.useRealTimers();
855
855
  });