@radiantabyss/vue 3.3.10 → 3.3.12
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 +1 -1
- package/src/Request.js +78 -12
- package/src/Routing/Router.js +14 -3
- package/src/Support/Helpers.js +5 -0
package/package.json
CHANGED
package/src/Request.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
let sprite_version = import.meta.env.VITE_SPRITE_VERSION;
|
|
2
|
+
let get_params_format = import.meta.env.VITE_GET_PARAMS_FORMAT || 'php';
|
|
3
|
+
let current = {};
|
|
2
4
|
|
|
3
5
|
const formatErrors = function(response) {
|
|
4
6
|
let errors = [];
|
|
@@ -56,6 +58,36 @@ const appendFormData = (formData, key, value) => {
|
|
|
56
58
|
}
|
|
57
59
|
};
|
|
58
60
|
|
|
61
|
+
const buildParams = (obj, prefix = '', params = new URLSearchParams()) => {
|
|
62
|
+
Object.entries(obj).forEach(([key, value]) => {
|
|
63
|
+
const full_key = prefix ? `${prefix}[${key}]` : key;
|
|
64
|
+
|
|
65
|
+
if ( Array.isArray(value) ) {
|
|
66
|
+
if ( value.length ) {
|
|
67
|
+
value.forEach((v, i) => {
|
|
68
|
+
if (typeof v === 'object') {
|
|
69
|
+
buildParams(v, `${full_key}[${i}]`, params);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
params.append(`${full_key}[]`, v);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
params.append(full_key, value);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else if ( typeof value === 'object' && value !== null ) {
|
|
81
|
+
buildParams(value, full_key, params);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
params.append(full_key, value);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
return params;
|
|
89
|
+
}
|
|
90
|
+
|
|
59
91
|
const request = function(method, edge, payload = {}, display_errors = false, base_url = null, auth_token = null, headers = {}, upload_progress = null) {
|
|
60
92
|
return new Promise((resolve, reject) => {
|
|
61
93
|
if ( !base_url ) {
|
|
@@ -66,7 +98,7 @@ const request = function(method, edge, payload = {}, display_errors = false, bas
|
|
|
66
98
|
auth_token = localStorage.getItem('jwt_token');
|
|
67
99
|
}
|
|
68
100
|
|
|
69
|
-
if ( method
|
|
101
|
+
if ( method == 'POST' ) {
|
|
70
102
|
Alert.hide();
|
|
71
103
|
}
|
|
72
104
|
|
|
@@ -101,23 +133,43 @@ const request = function(method, edge, payload = {}, display_errors = false, bas
|
|
|
101
133
|
_button.disabled = true;
|
|
102
134
|
}
|
|
103
135
|
|
|
136
|
+
let _cancel;
|
|
137
|
+
if ( payload._cancel !== undefined ) {
|
|
138
|
+
_cancel = new AbortController();
|
|
139
|
+
delete payload._cancel;
|
|
140
|
+
|
|
141
|
+
if ( current[edge] ) {
|
|
142
|
+
try {
|
|
143
|
+
current[edge].abort();
|
|
144
|
+
}
|
|
145
|
+
catch(e) {}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
current[edge] = _cancel;
|
|
149
|
+
}
|
|
150
|
+
|
|
104
151
|
let data;
|
|
105
152
|
let url = base_url + edge;
|
|
106
153
|
|
|
107
|
-
if ( method
|
|
108
|
-
|
|
154
|
+
if ( method == 'GET' ) {
|
|
155
|
+
if ( get_params_format == 'php' ) {
|
|
156
|
+
url += '?' + buildParams(payload);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
url += '?' + new URLSearchParams(payload).toString();
|
|
160
|
+
}
|
|
109
161
|
}
|
|
110
|
-
else if ( method
|
|
111
|
-
if ( headers['Content-Type']
|
|
162
|
+
else if ( method == 'POST' ) {
|
|
163
|
+
if ( headers['Content-Type'] == 'multipart/form-data' ) {
|
|
112
164
|
data = new FormData();
|
|
113
165
|
|
|
114
|
-
for (let key in payload) {
|
|
166
|
+
for ( let key in payload ) {
|
|
115
167
|
appendFormData(data, key, payload[key]);
|
|
116
168
|
}
|
|
117
169
|
|
|
118
170
|
delete headers['Content-Type'];
|
|
119
171
|
}
|
|
120
|
-
else if ( headers['Content-Type']
|
|
172
|
+
else if ( headers['Content-Type'] == 'application/x-www-form-urlencoded' ) {
|
|
121
173
|
data = serializeToURLEncoded(payload).replace(/\&+$/, '');
|
|
122
174
|
}
|
|
123
175
|
else {
|
|
@@ -150,17 +202,25 @@ const request = function(method, edge, payload = {}, display_errors = false, bas
|
|
|
150
202
|
}
|
|
151
203
|
}
|
|
152
204
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
body
|
|
157
|
-
}
|
|
205
|
+
let options = { method, headers };
|
|
206
|
+
|
|
207
|
+
if ( method != 'GET' ) {
|
|
208
|
+
options.body = data;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if ( _cancel ) {
|
|
212
|
+
options.signal = _cancel.signal;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
fetch(url, options)
|
|
158
216
|
.then(async (response) => {
|
|
159
217
|
if ( _button !== undefined ) {
|
|
160
218
|
_button.disabled = false;
|
|
161
219
|
_button.innerHTML = _button_html;
|
|
162
220
|
}
|
|
163
221
|
|
|
222
|
+
delete current[edge];
|
|
223
|
+
|
|
164
224
|
const response_data = await response.json();
|
|
165
225
|
|
|
166
226
|
if ( edge.match(/\.json/) ) {
|
|
@@ -179,6 +239,12 @@ const request = function(method, edge, payload = {}, display_errors = false, bas
|
|
|
179
239
|
reject(errors);
|
|
180
240
|
})
|
|
181
241
|
.catch((error) => {
|
|
242
|
+
if ( error.name == 'AbortError' ) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
delete current[edge];
|
|
247
|
+
|
|
182
248
|
let errors = [error.message];
|
|
183
249
|
|
|
184
250
|
if ( display_errors ) {
|
package/src/Routing/Router.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { nextTick, watch } from 'vue';
|
|
2
|
-
import { createRouter, createWebHistory } from 'vue-router';
|
|
2
|
+
import { createRouter, createWebHistory, createWebHashHistory, createMemoryHistory } from 'vue-router';
|
|
3
3
|
import Str from './../Support/Str';
|
|
4
4
|
import Actions from './Actions';
|
|
5
5
|
import Middleware from './Middleware';
|
|
@@ -30,14 +30,25 @@ const loadModules = async () => {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
export default async () => {
|
|
33
|
+
export default async (history_mode = 'web') => {
|
|
34
34
|
let runMiddleware = await Middleware();
|
|
35
35
|
|
|
36
36
|
await loadModules();
|
|
37
37
|
|
|
38
|
+
let history;
|
|
39
|
+
if ( history_mode == 'web' ) {
|
|
40
|
+
history = createWebHistory();
|
|
41
|
+
}
|
|
42
|
+
else if ( history_mode == 'hash' ) {
|
|
43
|
+
history = createWebHashHistory();
|
|
44
|
+
}
|
|
45
|
+
else if ( history_mode == 'memory' ) {
|
|
46
|
+
history = createMemoryHistory();
|
|
47
|
+
}
|
|
48
|
+
|
|
38
49
|
//create router
|
|
39
50
|
const Router = createRouter({
|
|
40
|
-
history
|
|
51
|
+
history,
|
|
41
52
|
routes: [],
|
|
42
53
|
duplicateNavigationPolicy: 'reload',
|
|
43
54
|
scrollBehavior(to, from, scroll) {
|
package/src/Support/Helpers.js
CHANGED
|
@@ -27,6 +27,11 @@ let self = {
|
|
|
27
27
|
array_unique(arr) {
|
|
28
28
|
return [...new Set(arr)];
|
|
29
29
|
},
|
|
30
|
+
|
|
31
|
+
sprite(id, css_class = '') {
|
|
32
|
+
let url = import.meta.env.MODE == 'development' ? '/sprites.svg' : '';
|
|
33
|
+
return `<svg class="svg-${id} ${css_class}"><use xlink:href="${url}#${id}"></use></svg>`;
|
|
34
|
+
},
|
|
30
35
|
}
|
|
31
36
|
|
|
32
37
|
export default self;
|