vueless 0.0.531 → 0.0.533

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.
Files changed (78) hide show
  1. package/package.json +1 -1
  2. package/types.ts +18 -0
  3. package/ui.container-group/types.ts +0 -1
  4. package/ui.image-avatar/UAvatar.vue +51 -115
  5. package/ui.image-avatar/storybook/Docs.mdx +2 -2
  6. package/ui.image-avatar/storybook/{stories.js → stories.ts} +13 -5
  7. package/ui.image-avatar/types.ts +71 -0
  8. package/ui.image-avatar/useAttrs.ts +18 -0
  9. package/ui.image-icon/UIcon.vue +28 -113
  10. package/ui.image-icon/storybook/Docs.mdx +1 -1
  11. package/ui.image-icon/storybook/{stories.js → stories.ts} +13 -5
  12. package/ui.image-icon/types.ts +83 -0
  13. package/ui.image-icon/useAttrs.ts +18 -0
  14. package/ui.loader/ULoader.vue +21 -41
  15. package/ui.loader/storybook/Docs.mdx +2 -2
  16. package/ui.loader/storybook/{stories.js → stories.ts} +15 -7
  17. package/ui.loader/types.ts +47 -0
  18. package/ui.loader/{useAttrs.js → useAttrs.ts} +6 -3
  19. package/ui.loader-overlay/ULoaderOverlay.vue +23 -35
  20. package/ui.loader-overlay/storybook/Docs.mdx +2 -2
  21. package/ui.loader-overlay/storybook/{stories.js → stories.ts} +22 -7
  22. package/ui.loader-overlay/types.ts +42 -0
  23. package/ui.loader-overlay/{useAttrs.js → useAttrs.ts} +5 -2
  24. package/ui.loader-overlay/useLoaderOverlay.ts +42 -0
  25. package/ui.loader-overlay/{utilLoaderOverlay.js → utilLoaderOverlay.ts} +2 -2
  26. package/ui.loader-progress/ULoaderProgress.vue +34 -49
  27. package/ui.loader-progress/{config.js → config.ts} +1 -0
  28. package/ui.loader-progress/storybook/Docs.mdx +2 -2
  29. package/ui.loader-progress/storybook/{stories.js → stories.ts} +24 -7
  30. package/ui.loader-progress/types.ts +46 -0
  31. package/ui.loader-progress/useAttrs.ts +36 -0
  32. package/ui.loader-progress/useLoaderProgress.ts +81 -0
  33. package/ui.loader-progress/utilLoaderProgress.ts +49 -0
  34. package/ui.navigation-pagination/UPagination.vue +141 -262
  35. package/ui.navigation-pagination/storybook/Docs.mdx +2 -2
  36. package/ui.navigation-pagination/storybook/{stories.js → stories.ts} +11 -4
  37. package/ui.navigation-pagination/types.ts +85 -0
  38. package/ui.navigation-pagination/{useAttrs.js → useAttrs.ts} +5 -2
  39. package/ui.navigation-progress/StepperProgress.vue +26 -47
  40. package/ui.navigation-progress/UProgress.vue +60 -118
  41. package/ui.navigation-progress/{config.js → config.ts} +1 -0
  42. package/ui.navigation-progress/storybook/Docs.mdx +2 -2
  43. package/ui.navigation-progress/storybook/{stories.js → stories.ts} +19 -7
  44. package/ui.navigation-progress/types.ts +93 -0
  45. package/ui.navigation-progress/{useAttrs.js → useAttrs.ts} +6 -3
  46. package/ui.navigation-tab/UTab.vue +18 -54
  47. package/ui.navigation-tab/storybook/Docs.mdx +2 -2
  48. package/ui.navigation-tab/storybook/{stories.js → stories.ts} +10 -5
  49. package/ui.navigation-tab/types.ts +30 -0
  50. package/ui.navigation-tab/{useAttrs.js → useAttrs.ts} +15 -3
  51. package/ui.navigation-tabs/UTabs.vue +29 -78
  52. package/ui.navigation-tabs/storybook/Docs.mdx +2 -2
  53. package/ui.navigation-tabs/storybook/{stories.js → stories.ts} +13 -5
  54. package/ui.navigation-tabs/types.ts +37 -0
  55. package/ui.navigation-tabs/useAttrs.ts +18 -0
  56. package/web-types.json +200 -84
  57. package/ui.image-avatar/useAttrs.js +0 -15
  58. package/ui.image-icon/useAttrs.js +0 -15
  59. package/ui.loader-overlay/useLoaderOverlay.js +0 -25
  60. package/ui.loader-progress/useAttrs.js +0 -15
  61. package/ui.loader-progress/useLoaderProgress.js +0 -65
  62. package/ui.loader-progress/utilLoaderProgress.js +0 -49
  63. package/ui.navigation-tabs/useAttrs.js +0 -15
  64. /package/ui.image-avatar/{config.js → config.ts} +0 -0
  65. /package/ui.image-avatar/{constants.js → constants.ts} +0 -0
  66. /package/ui.image-icon/{constants.js → constants.ts} +0 -0
  67. /package/ui.loader/{config.js → config.ts} +0 -0
  68. /package/ui.loader/{constants.js → constants.ts} +0 -0
  69. /package/ui.loader-overlay/{config.js → config.ts} +0 -0
  70. /package/ui.loader-overlay/{constants.js → constants.ts} +0 -0
  71. /package/ui.loader-progress/{constants.js → constants.ts} +0 -0
  72. /package/ui.navigation-pagination/{config.js → config.ts} +0 -0
  73. /package/ui.navigation-pagination/{constants.js → constants.ts} +0 -0
  74. /package/ui.navigation-progress/{constants.js → constants.ts} +0 -0
  75. /package/ui.navigation-tab/{config.js → config.ts} +0 -0
  76. /package/ui.navigation-tab/{constants.js → constants.ts} +0 -0
  77. /package/ui.navigation-tabs/{config.js → config.ts} +0 -0
  78. /package/ui.navigation-tabs/{constants.js → constants.ts} +0 -0
@@ -1,55 +1,29 @@
1
- <template>
2
- <Transition :css="false" @before-enter="beforeEnter" @enter="enter" @after-enter="afterEnter">
3
- <div v-if="show" v-bind="stripeAttrs" :style="barStyle" />
4
- </Transition>
5
- </template>
6
-
7
- <script setup>
1
+ <script lang="ts" setup>
8
2
  import { computed, onBeforeUnmount, watch, ref, onMounted, onUnmounted } from "vue";
9
3
 
10
4
  import { getDefault } from "../utils/ui.ts";
11
5
  import { isMobileApp } from "../utils/platform.ts";
12
- import { clamp, queue, getRequestWithoutQuery } from "./utilLoaderProgress.js";
13
- import { useLoaderProgress } from "./useLoaderProgress.js";
14
- import useAttrs from "./useAttrs.js";
6
+ import { clamp, queue, getRequestWithoutQuery } from "./utilLoaderProgress.ts";
7
+ import { useLoaderProgress } from "./useLoaderProgress.ts";
8
+ import useAttrs from "./useAttrs.ts";
15
9
 
16
- import { ULoaderProgress, MAXIMUM, SPEED, INFINITY_LOADING } from "./constants.js";
17
- import defaultConfig from "./config.js";
10
+ import { ULoaderProgress, MAXIMUM, SPEED, INFINITY_LOADING } from "./constants.ts";
11
+ import defaultConfig from "./config.ts";
18
12
 
19
- defineOptions({ inheritAttrs: false });
20
-
21
- const props = defineProps({
22
- /**
23
- * Loader stripe color.
24
- * @values brand, grayscale, gray, red, orange, amber, yellow, lime, green, emerald, teal, cyan, sky, blue, indigo, violet, purple, fuchsia, pink, rose, white
25
- */
26
- color: {
27
- type: String,
28
- default: getDefault(defaultConfig, ULoaderProgress).color,
29
- },
13
+ import type { ULoaderProgressProps } from "./types.ts";
30
14
 
31
- /**
32
- * API resource names (endpoint URIs).
33
- */
34
- resources: {
35
- type: [String, Array],
36
- default: "",
37
- },
15
+ defineOptions({ inheritAttrs: false });
38
16
 
39
- /**
40
- * Loader state (shown / hidden).
41
- */
42
- loading: {
43
- type: Boolean,
44
- default: getDefault(defaultConfig, ULoaderProgress).loading,
45
- },
17
+ const props = withDefaults(defineProps<ULoaderProgressProps>(), {
18
+ color: getDefault<ULoaderProgressProps>(defaultConfig, ULoaderProgress).color,
19
+ loading: getDefault<ULoaderProgressProps>(defaultConfig, ULoaderProgress).loading,
46
20
  });
47
21
 
48
22
  const error = ref(false);
49
23
  const show = ref(false);
50
24
  const progress = ref(0);
51
25
  const opacity = ref(1);
52
- const status = ref(null);
26
+ const status = ref<number | null>(null);
53
27
 
54
28
  const {
55
29
  requestQueue,
@@ -59,7 +33,8 @@ const {
59
33
  loaderProgressOn,
60
34
  addRequestUrl,
61
35
  } = useLoaderProgress();
62
- const { stripeAttrs } = useAttrs(props, { error, isMobileApp });
36
+
37
+ const { stripeAttrs } = useAttrs(props, { isMobileApp });
63
38
 
64
39
  const isStarted = computed(() => {
65
40
  return typeof status.value === "number";
@@ -73,6 +48,10 @@ const barStyle = computed(() => {
73
48
  });
74
49
 
75
50
  const resourceNamesArray = computed(() => {
51
+ if (!props.resources) {
52
+ return [];
53
+ }
54
+
76
55
  return Array.isArray(props.resources)
77
56
  ? props.resources.map(getRequestWithoutQuery)
78
57
  : [getRequestWithoutQuery(props.resources)];
@@ -81,8 +60,8 @@ const resourceNamesArray = computed(() => {
81
60
  watch(() => requestQueue.value.length, onChangeRequestsQueue);
82
61
 
83
62
  onMounted(() => {
84
- window.addEventListener("loaderProgressOn", setLoaderOnHandler);
85
- window.addEventListener("loaderProgressOff", setLoaderOffHandler);
63
+ window.addEventListener("loaderProgressOn", setLoaderOnHandler as EventListener);
64
+ window.addEventListener("loaderProgressOff", setLoaderOffHandler as EventListener);
86
65
 
87
66
  if (props.resources) {
88
67
  onChangeRequestsQueue();
@@ -94,8 +73,8 @@ onBeforeUnmount(() => {
94
73
  });
95
74
 
96
75
  onUnmounted(() => {
97
- window.removeEventListener("loaderProgressOn", setLoaderOnHandler);
98
- window.removeEventListener("loaderProgressOff", setLoaderOffHandler);
76
+ window.removeEventListener("loaderProgressOn", setLoaderOnHandler as EventListener);
77
+ window.removeEventListener("loaderProgressOff", setLoaderOffHandler as EventListener);
99
78
  });
100
79
 
101
80
  watch(
@@ -111,11 +90,11 @@ watch(
111
90
  { immediate: true },
112
91
  );
113
92
 
114
- function setLoaderOnHandler(event) {
93
+ function setLoaderOnHandler(event: CustomEvent<{ resource: string }>) {
115
94
  loaderProgressOn(event.detail.resource);
116
95
  }
117
96
 
118
- function setLoaderOffHandler(event) {
97
+ function setLoaderOffHandler(event: CustomEvent<{ resource: string }>) {
119
98
  loaderProgressOff(event.detail.resource);
120
99
  }
121
100
 
@@ -138,7 +117,7 @@ function beforeEnter() {
138
117
  progress.value = 0;
139
118
  }
140
119
 
141
- function enter(el, done) {
120
+ function enter(el: Element, done: () => void) {
142
121
  opacity.value = 1;
143
122
  done();
144
123
  }
@@ -172,7 +151,7 @@ function start() {
172
151
  }
173
152
  }
174
153
 
175
- function set(amount) {
154
+ function set(amount: number) {
176
155
  let currentProgress;
177
156
 
178
157
  if (isStarted.value) {
@@ -201,7 +180,7 @@ function set(amount) {
201
180
  });
202
181
  }
203
182
 
204
- function increase(amount) {
183
+ function increase(amount?: number) {
205
184
  const currentProgress = progress.value;
206
185
 
207
186
  if (currentProgress < 100 && typeof amount !== "number") {
@@ -220,10 +199,16 @@ function increase(amount) {
220
199
  }
221
200
  }
222
201
 
223
- set(clamp(currentProgress + amount, 0, MAXIMUM));
202
+ set(clamp(currentProgress + (amount || 0), 0, MAXIMUM));
224
203
  }
225
204
 
226
205
  function done() {
227
206
  set(100);
228
207
  }
229
208
  </script>
209
+
210
+ <template>
211
+ <Transition :css="false" @before-enter="beforeEnter" @enter="enter" @after-enter="afterEnter">
212
+ <div v-if="show" v-bind="stripeAttrs" :style="barStyle" />
213
+ </Transition>
214
+ </template>
@@ -11,6 +11,7 @@ export default /*tw*/ {
11
11
  },
12
12
  },
13
13
  },
14
+ stripeMobile: "",
14
15
  defaults: {
15
16
  color: "brand",
16
17
  loading: false,
@@ -1,8 +1,8 @@
1
1
  import { Meta, Title, Subtitle, Description, Primary, Controls, Stories, Source, Markdown } from "@storybook/blocks";
2
2
  import { getSource } from "../../utils/storybook.ts";
3
3
 
4
- import * as stories from "./stories.js";
5
- import defaultConfig from "../config.js?raw"
4
+ import * as stories from "./stories.ts";
5
+ import defaultConfig from "../config.ts?raw"
6
6
 
7
7
  <Meta of={stories} />
8
8
  <Title of={stories} />
@@ -6,8 +6,16 @@ import URow from "../../ui.container-row/URow.vue";
6
6
  import UCol from "../../ui.container-col/UCol.vue";
7
7
  import UBadge from "../../ui.text-badge/UBadge.vue";
8
8
 
9
- import { useLoaderProgress } from "../useLoaderProgress.js";
10
- import { loaderProgressOff, loaderProgressOn } from "../utilLoaderProgress.js";
9
+ import { useLoaderProgress } from "../useLoaderProgress.ts";
10
+ import { loaderProgressOff, loaderProgressOn } from "../utilLoaderProgress.ts";
11
+
12
+ import type { Meta, StoryFn } from "@storybook/vue3";
13
+ import type { ULoaderProgressProps } from "../types.ts";
14
+
15
+ interface ULoaderProgressArgs extends ULoaderProgressProps {
16
+ slotTemplate?: string;
17
+ enum: "color";
18
+ }
11
19
 
12
20
  /**
13
21
  * The `ULoaderProgress` component. | [View on GitHub](https://github.com/vuelessjs/vueless/tree/main/src/ui.loader-progress)
@@ -19,12 +27,18 @@ export default {
19
27
  argTypes: {
20
28
  ...getArgTypes(ULoaderProgress.__name),
21
29
  },
22
- };
30
+ } as Meta;
23
31
 
24
- const DefaultTemplate = (args) => ({
32
+ const DefaultTemplate: StoryFn<ULoaderProgressArgs> = (args: ULoaderProgressArgs) => ({
25
33
  components: { ULoaderProgress, UButton, URow },
26
34
  setup() {
27
- const { loaderProgressOn, loaderProgressOff } = useLoaderProgress();
35
+ const loaderProgress = useLoaderProgress();
36
+
37
+ if (!loaderProgress) {
38
+ throw new Error("LoaderProgress is not provided. Ensure it is properly injected.");
39
+ }
40
+
41
+ const { loaderProgressOn, loaderProgressOff } = loaderProgress;
28
42
  const slots = getSlotNames(ULoaderProgress.__name);
29
43
 
30
44
  return { args, slots, loaderProgressOn, loaderProgressOff };
@@ -39,14 +53,17 @@ const DefaultTemplate = (args) => ({
39
53
  `,
40
54
  });
41
55
 
42
- const EnumVariantTemplate = (args, { argTypes }) => ({
56
+ const EnumVariantTemplate: StoryFn<ULoaderProgressArgs> = (
57
+ args: ULoaderProgressArgs,
58
+ { argTypes },
59
+ ) => ({
43
60
  components: { ULoaderProgress, UButton, UCol, URow, UBadge },
44
61
  setup() {
45
62
  return {
46
63
  args,
47
64
  loaderProgressOff,
48
65
  loaderProgressOn,
49
- options: argTypes[args.enum].options,
66
+ options: argTypes?.[args.enum]?.options,
50
67
  };
51
68
  },
52
69
  template: `
@@ -0,0 +1,46 @@
1
+ import defaultConfig from "./config.ts";
2
+
3
+ export type Config = Partial<typeof defaultConfig>;
4
+
5
+ export interface ULoaderProgressProps {
6
+ /**
7
+ * Loader stripe color.
8
+ */
9
+ color?:
10
+ | "brand"
11
+ | "grayscale"
12
+ | "gray"
13
+ | "red"
14
+ | "orange"
15
+ | "amber"
16
+ | "yellow"
17
+ | "lime"
18
+ | "green"
19
+ | "emerald"
20
+ | "teal"
21
+ | "cyan"
22
+ | "sky"
23
+ | "blue"
24
+ | "indigo"
25
+ | "violet"
26
+ | "purple"
27
+ | "fuchsia"
28
+ | "pink"
29
+ | "rose"
30
+ | "white";
31
+
32
+ /**
33
+ * API resource names (endpoint URIs).
34
+ */
35
+ resources?: string | string[];
36
+
37
+ /**
38
+ * Loader state (shown / hidden).
39
+ */
40
+ loading?: boolean;
41
+
42
+ /**
43
+ * Component config object.
44
+ */
45
+ config?: Partial<typeof defaultConfig>;
46
+ }
@@ -0,0 +1,36 @@
1
+ import { computed } from "vue";
2
+ import useUI from "../composables/useUI.ts";
3
+
4
+ import defaultConfig from "./config.ts";
5
+
6
+ import type { UseAttrs } from "../types.ts";
7
+ import type { ULoaderProgressProps, Config } from "./types.ts";
8
+
9
+ type ComponentState = {
10
+ isMobileApp: boolean;
11
+ };
12
+
13
+ export default function useAttrs(
14
+ props: ULoaderProgressProps,
15
+ { isMobileApp }: ComponentState,
16
+ ): UseAttrs<Config> {
17
+ const { config, getKeysAttrs, getExtendingKeysClasses, hasSlotContent } = useUI<Config>(
18
+ defaultConfig,
19
+ () => props.config,
20
+ );
21
+
22
+ const extendingKeys = ["stripeMobile"];
23
+ const extendingKeysClasses = getExtendingKeysClasses(extendingKeys);
24
+
25
+ const keysAttrs = getKeysAttrs({}, extendingKeys, {
26
+ stripe: {
27
+ extend: computed(() => [isMobileApp && extendingKeysClasses.linkWithChild.value]),
28
+ },
29
+ });
30
+
31
+ return {
32
+ config,
33
+ ...keysAttrs,
34
+ hasSlotContent,
35
+ };
36
+ }
@@ -0,0 +1,81 @@
1
+ import { inject, readonly, ref } from "vue";
2
+
3
+ import type { Ref } from "vue";
4
+
5
+ import { getRequestWithoutQuery } from "./utilLoaderProgress.ts";
6
+ import { INFINITY_LOADING } from "./constants.ts";
7
+
8
+ export const LoaderProgressSymbol = Symbol.for("vueless:loader-progress");
9
+
10
+ type LoaderProgress = {
11
+ isLoading: Ref<boolean>;
12
+ requestQueue: Readonly<Ref<readonly string[]>>;
13
+ loaderProgressOn: (url: string | string[]) => void;
14
+ loaderProgressOff: (url: string | string[]) => void;
15
+ addRequestUrl: (url: string | string[]) => void;
16
+ removeRequestUrl: (url: string | string[]) => void;
17
+ };
18
+
19
+ const isLoading = ref(false);
20
+ const requestQueue = ref<string[]>([]);
21
+ const requestTimeout = ref<number | undefined>(undefined);
22
+
23
+ function loaderProgressOn(url: string | string[]): void {
24
+ addRequestUrl(url);
25
+ isLoading.value = true;
26
+
27
+ if (requestTimeout.value !== undefined) {
28
+ clearTimeout(requestTimeout.value);
29
+ }
30
+ }
31
+
32
+ function loaderProgressOff(url: string | string[]): void {
33
+ removeRequestUrl(url);
34
+
35
+ requestTimeout.value = window.setTimeout(() => {
36
+ if (!requestQueue.value.length) {
37
+ isLoading.value = false;
38
+ }
39
+ }, 50);
40
+ }
41
+
42
+ function addRequestUrl(url: string | string[]): void {
43
+ if (Array.isArray(url)) {
44
+ requestQueue.value.push(...url.map(getRequestWithoutQuery));
45
+ } else {
46
+ requestQueue.value.push(getRequestWithoutQuery(url));
47
+ }
48
+ }
49
+
50
+ function removeRequestUrl(url: string | string[]): void {
51
+ if (Array.isArray(url)) {
52
+ url.map(getRequestWithoutQuery).forEach(removeRequestUrl);
53
+ } else {
54
+ requestQueue.value = requestQueue.value.filter(
55
+ (item) => item !== getRequestWithoutQuery(url) && item !== INFINITY_LOADING,
56
+ );
57
+ }
58
+ }
59
+
60
+ export function createLoaderProgress(): LoaderProgress {
61
+ return {
62
+ isLoading,
63
+ requestQueue: readonly(requestQueue),
64
+ loaderProgressOn,
65
+ loaderProgressOff,
66
+ addRequestUrl,
67
+ removeRequestUrl,
68
+ };
69
+ }
70
+
71
+ export function useLoaderProgress(): LoaderProgress {
72
+ const loaderProgress = inject<LoaderProgress>(LoaderProgressSymbol);
73
+
74
+ if (!loaderProgress) {
75
+ throw new Error(
76
+ "LoaderProgress not provided. Ensure you are using `provide` with `LoaderProgressSymbol`.",
77
+ );
78
+ }
79
+
80
+ return loaderProgress;
81
+ }
@@ -0,0 +1,49 @@
1
+ export function clamp(n: number, min: number, max: number): number {
2
+ if (n < min) {
3
+ return min;
4
+ }
5
+
6
+ if (n > max) {
7
+ return max;
8
+ }
9
+
10
+ return n;
11
+ }
12
+
13
+ export const queue = (() => {
14
+ const pending: ((next: () => void) => void)[] = [];
15
+
16
+ function next(): void {
17
+ const fn = pending.shift();
18
+
19
+ if (fn) {
20
+ fn(next);
21
+ }
22
+ }
23
+
24
+ return (fn: (next: () => void) => void): void => {
25
+ pending.push(fn);
26
+
27
+ if (pending.length === 1) {
28
+ next();
29
+ }
30
+ };
31
+ })();
32
+
33
+ export function loaderProgressOn(resource: string): void {
34
+ const loaderProgressOnEvent = new CustomEvent("loaderProgressOn", { detail: { resource } });
35
+
36
+ window.dispatchEvent(loaderProgressOnEvent);
37
+ }
38
+
39
+ export function loaderProgressOff(resource: string): void {
40
+ const loaderProgressOffEvent = new CustomEvent("loaderProgressOff", { detail: { resource } });
41
+
42
+ window.dispatchEvent(loaderProgressOffEvent);
43
+ }
44
+
45
+ export function getRequestWithoutQuery(request: string | URL): string {
46
+ const [requestWithoutQuery] = String(request).split("?");
47
+
48
+ return requestWithoutQuery;
49
+ }