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
|
@@ -5,16 +5,16 @@
|
|
|
5
5
|
</template>
|
|
6
6
|
|
|
7
7
|
<script setup>
|
|
8
|
-
import { computed, onBeforeUnmount, watch, ref, onMounted, onUnmounted
|
|
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 {
|
|
55
|
-
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
|
|
@@ -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
|
-
|
|
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
|
-
|
|
34
|
-
|
|
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(
|
|
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:
|
|
54
|
+
isLoading: isLoading,
|
|
50
55
|
requestQueue: readonly(requestQueue),
|
|
51
56
|
loaderProgressOn,
|
|
52
57
|
loaderProgressOff,
|