vueless 0.0.478-beta.13 → 0.0.478-beta.14

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": "0.0.478-beta.13",
3
+ "version": "0.0.478-beta.14",
4
4
  "license": "MIT",
5
5
  "description": "Vue Styleless UI Component Library, powered by Tailwind CSS.",
6
6
  "keywords": [
@@ -5,16 +5,16 @@
5
5
  </template>
6
6
 
7
7
  <script setup>
8
- import { computed, onBeforeUnmount, watch, ref, onMounted, onUnmounted, watchEffect } from "vue";
8
+ import { computed, onBeforeUnmount, watch, ref, onMounted, onUnmounted } from "vue";
9
9
 
10
10
  import { getDefault } from "../utils/utilUI.ts";
11
11
  import { isMobileApp } from "../utils/utilPlatform.ts";
12
12
  import { clamp, queue, getRequestWithoutQuery } from "./utilLoaderProgress.js";
13
13
  import { useLoaderProgress } from "./useLoaderProgress.js";
14
+ import useAttrs from "./useAttrs.js";
14
15
 
15
- import { ULoaderProgress, MAXIMUM, SPEED } from "./constants.js";
16
+ import { ULoaderProgress, MAXIMUM, SPEED, INFINITY_LOADING } from "./constants.js";
16
17
  import defaultConfig from "./config.js";
17
- import useAttrs from "./useAttrs.js";
18
18
 
19
19
  defineOptions({ inheritAttrs: false });
20
20
 
@@ -51,8 +51,14 @@ const progress = ref(0);
51
51
  const opacity = ref(1);
52
52
  const status = ref(null);
53
53
 
54
- const { requestQueue, removeRequestUrl, isLoading, loaderProgressOff, loaderProgressOn } =
55
- useLoaderProgress();
54
+ const {
55
+ requestQueue,
56
+ removeRequestUrl,
57
+ isLoading,
58
+ loaderProgressOff,
59
+ loaderProgressOn,
60
+ addRequestUrl,
61
+ } = useLoaderProgress();
56
62
  const { stripeAttrs } = useAttrs(props, { error, isMobileApp });
57
63
 
58
64
  const isStarted = computed(() => {
@@ -73,7 +79,6 @@ const resourceNamesArray = computed(() => {
73
79
  });
74
80
 
75
81
  watch(() => requestQueue.value.length, onChangeRequestsQueue);
76
- watch(isLoading, onChangeLoadingState);
77
82
 
78
83
  onMounted(() => {
79
84
  window.addEventListener("loaderProgressOn", setLoaderOnHandler);
@@ -93,16 +98,18 @@ onUnmounted(() => {
93
98
  window.removeEventListener("loaderProgressOff", setLoaderOffHandler);
94
99
  });
95
100
 
96
- watchEffect(() => {
97
- if (props.loading) {
98
- show.value = true;
99
- start();
100
-
101
- return;
102
- }
103
-
104
- done();
105
- });
101
+ watch(
102
+ () => props.loading,
103
+ () => {
104
+ if (props.loading) {
105
+ addRequestUrl(INFINITY_LOADING);
106
+ isLoading.value = true;
107
+ } else {
108
+ removeRequestUrl(INFINITY_LOADING);
109
+ }
110
+ },
111
+ { immediate: true },
112
+ );
106
113
 
107
114
  function setLoaderOnHandler(event) {
108
115
  loaderProgressOn(event.detail.resource);
@@ -112,39 +119,17 @@ function setLoaderOffHandler(event) {
112
119
  loaderProgressOff(event.detail.resource);
113
120
  }
114
121
 
115
- function onChangeLoadingState() {
116
- if (!props.resources && isStarted.value && show.value && !isLoading.value) {
117
- done();
118
- }
119
- }
120
-
121
122
  function onChangeRequestsQueue() {
122
- let isActiveRequests = false;
123
-
124
- if (props.resources) {
125
- resourceNamesArray.value.forEach((resource) => {
126
- if (!isActiveRequests) {
127
- const activeRequest = requestQueue.value.find((request) => request === resource);
128
-
129
- isActiveRequests = Boolean(activeRequest);
130
- }
123
+ const isActiveRequests =
124
+ requestQueue.value.includes(INFINITY_LOADING) ||
125
+ resourceNamesArray.value.some((resource) => {
126
+ return requestQueue.value.includes(resource);
131
127
  });
132
128
 
133
- if (isActiveRequests && !isStarted.value) {
134
- start();
135
- } else if (!isActiveRequests && isStarted.value && show.value && !props.loading) {
136
- done();
137
- }
138
- } else {
139
- resourceNamesArray.value.forEach((resource) => {
140
- const activeRequest = requestQueue.value.find((request) => request === resource);
141
-
142
- isActiveRequests = !activeRequest;
143
- });
144
-
145
- if (isLoading.value && isActiveRequests && !isStarted.value) {
146
- start();
147
- }
129
+ if (isActiveRequests && !isStarted.value && isLoading.value) {
130
+ start();
131
+ } else if (!isActiveRequests && isStarted.value && show.value) {
132
+ done();
148
133
  }
149
134
  }
150
135
 
@@ -6,3 +6,4 @@ export const ULoaderProgress = "ULoaderProgress";
6
6
 
7
7
  export const MAXIMUM = 99;
8
8
  export const SPEED = 150;
9
+ export const INFINITY_LOADING = "Infinity";
@@ -25,7 +25,6 @@ const DefaultTemplate = (args) => ({
25
25
  components: { ULoaderProgress, UButton, URow },
26
26
  setup() {
27
27
  const { loaderProgressOn, loaderProgressOff } = useLoaderProgress();
28
-
29
28
  const slots = getSlotNames(ULoaderProgress.__name);
30
29
 
31
30
  return { args, slots, loaderProgressOn, loaderProgressOff };
@@ -79,7 +78,7 @@ const EnumVariantTemplate = (args, { argTypes }) => ({
79
78
  });
80
79
 
81
80
  export const Default = DefaultTemplate.bind({});
82
- Default.args = {};
81
+ Default.args = { loading: false };
83
82
 
84
83
  export const Color = EnumVariantTemplate.bind({});
85
84
  Color.args = { enum: "color" };
@@ -1,6 +1,7 @@
1
1
  import { inject, readonly, ref } from "vue";
2
2
 
3
3
  import { getRequestWithoutQuery } from "./utilLoaderProgress.js";
4
+ import { INFINITY_LOADING } from "./constants.js";
4
5
 
5
6
  export const LoaderProgressSymbol = Symbol.for("vueless:loader-progress");
6
7
 
@@ -17,9 +18,7 @@ function loaderProgressOn(url) {
17
18
  }
18
19
 
19
20
  function loaderProgressOff(url) {
20
- requestQueue.value = url
21
- ? requestQueue.value.filter((item) => item !== getRequestWithoutQuery(url))
22
- : [];
21
+ removeRequestUrl(url);
23
22
 
24
23
  requestTimeout.value = setTimeout(() => {
25
24
  if (!requestQueue.value.length) {
@@ -29,9 +28,13 @@ function loaderProgressOff(url) {
29
28
  }
30
29
 
31
30
  function addRequestUrl(url) {
32
- Array.isArray(url)
33
- ? requestQueue.value.push(...url.map(getRequestWithoutQuery))
34
- : requestQueue.value.push(getRequestWithoutQuery(url));
31
+ if (Array.isArray(url)) {
32
+ requestQueue.value.push(...url.map(getRequestWithoutQuery));
33
+
34
+ return;
35
+ }
36
+
37
+ requestQueue.value.push(getRequestWithoutQuery(url));
35
38
  }
36
39
 
37
40
  function removeRequestUrl(url) {
@@ -41,12 +44,14 @@ function removeRequestUrl(url) {
41
44
  return;
42
45
  }
43
46
 
44
- requestQueue.value = requestQueue.value.filter((item) => item !== getRequestWithoutQuery(url));
47
+ requestQueue.value = requestQueue.value.filter(
48
+ (item) => item !== getRequestWithoutQuery(url) && item !== INFINITY_LOADING,
49
+ );
45
50
  }
46
51
 
47
52
  export function createLoaderProgress() {
48
53
  return {
49
- isLoading: readonly(isLoading),
54
+ isLoading: isLoading,
50
55
  requestQueue: readonly(requestQueue),
51
56
  loaderProgressOn,
52
57
  loaderProgressOff,
@@ -43,7 +43,7 @@ export function loaderProgressOff(resource) {
43
43
  }
44
44
 
45
45
  export function getRequestWithoutQuery(request) {
46
- const [requestWithoutQuery] = request.split("?");
46
+ const [requestWithoutQuery] = String(request).split("?");
47
47
 
48
48
  return requestWithoutQuery;
49
49
  }