@radiantabyss/vue 3.3.18 → 3.3.20

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": "@radiantabyss/vue",
3
- "version": "3.3.18",
3
+ "version": "3.3.20",
4
4
  "author": "radiantabyss.com",
5
5
  "license": "ISC",
6
6
  "eslintConfig": {
package/src/Bootstrap.js CHANGED
@@ -1,53 +1,54 @@
1
- import Components from './Components.js';
2
- import Directives from './Directives.js';
3
- import Mixins from './Mixins.js';
4
- import Modals from './Modals.js';
5
-
6
- import Alert from './Alert.js';
7
- import Cookie from './Support/Cookie.js';
8
- import Confirm from './Confirm.js';
9
- import Gate from './Support/Gate.js';
10
- import Helpers from './Support/Helpers.js';
11
- import Invoke from './Invoke.js';
12
- import Item from './Support/Item.js';
13
- import Items from './Support/Items.js';
14
- import Modal from './Modal.js';
15
- import Request from './Request.js';
16
- import ReactiveStorage from './Support/ReactiveStorage.js';
17
- import Str from './Support/Str.js';
18
-
19
- import Store from './Store.js';
20
-
21
- export default async (app) => {
22
- //helpers
23
- for ( let key in Helpers ) {
24
- window[key] = Helpers[key];
25
- app.config.globalProperties[key] = Helpers[key];
26
- }
27
-
28
- await Components(app);
29
- await Directives(app);
30
- await Mixins(app);
31
- await Modals(app);
32
-
33
- window.Alert = Alert;
34
- window.Cookie = Cookie;
35
- window.Confirm = Confirm;
36
- window.Gate = Gate;
37
- window.Invoke = Invoke;
38
- window.Item = Item;
39
- window.Items = Items;
40
- window.Modal = Modal;
41
- window.Request = Request;
42
- window.ReactiveStorage = ReactiveStorage;
43
- window.Str = Str;
44
-
45
- //make usable inside template
46
- app.config.globalProperties.Item = Item;
47
- app.config.globalProperties.Items = Items;
48
- app.config.globalProperties.Gate = Gate;
49
- app.config.globalProperties.Modal = Modal;
50
- app.config.globalProperties.Str = Str;
51
-
52
- await Store(app);
53
- };
1
+ //must be imported first: eagerly loaded components reference Mixins.X at definition time
2
+ import Mixins from './Mixins.js';
3
+ import Components from './Components.js';
4
+ import Directives from './Directives.js';
5
+ import Modals from './Modals.js';
6
+
7
+ import Alert from './Alert.js';
8
+ import Cookie from './Support/Cookie.js';
9
+ import Confirm from './Confirm.js';
10
+ import Gate from './Support/Gate.js';
11
+ import Helpers from './Support/Helpers.js';
12
+ import Invoke from './Invoke.js';
13
+ import Item from './Support/Item.js';
14
+ import Items from './Support/Items.js';
15
+ import Modal from './Modal.js';
16
+ import Request from './Request.js';
17
+ import ReactiveStorage from './Support/ReactiveStorage.js';
18
+ import Str from './Support/Str.js';
19
+
20
+ import Store from './Store.js';
21
+
22
+ export default async (app) => {
23
+ //helpers
24
+ for ( let key in Helpers ) {
25
+ window[key] = Helpers[key];
26
+ app.config.globalProperties[key] = Helpers[key];
27
+ }
28
+
29
+ await Components(app);
30
+ await Directives(app);
31
+ await Mixins(app);
32
+ await Modals(app);
33
+
34
+ window.Alert = Alert;
35
+ window.Cookie = Cookie;
36
+ window.Confirm = Confirm;
37
+ window.Gate = Gate;
38
+ window.Invoke = Invoke;
39
+ window.Item = Item;
40
+ window.Items = Items;
41
+ window.Modal = Modal;
42
+ window.Request = Request;
43
+ window.ReactiveStorage = ReactiveStorage;
44
+ window.Str = Str;
45
+
46
+ //make usable inside template
47
+ app.config.globalProperties.Item = Item;
48
+ app.config.globalProperties.Items = Items;
49
+ app.config.globalProperties.Gate = Gate;
50
+ app.config.globalProperties.Modal = Modal;
51
+ app.config.globalProperties.Str = Str;
52
+
53
+ await Store(app);
54
+ };
package/src/Components.js CHANGED
@@ -1,44 +1,44 @@
1
- import Str from './Support/Str.js';
2
-
3
- let context_ra = import.meta.glob('/node_modules/@radiantabyss/vue-components/src/Components/**/*.vue');
4
- let context = import.meta.glob('@/Components/**/*.vue');
5
-
6
- function getComponentName(file) {
7
- let split = file.split('/');
8
- let name = split[split.length - 1].replace('.vue', '')
9
- .replace(/Component$/, '')
10
- .replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2')
11
- .toLowerCase();
12
-
13
- return Str.trim(name, '-');
14
- }
15
-
16
- export default async (app) => {
17
- //load app components
18
- let files = Object.keys(context);
19
- let components = [];
20
-
21
- for ( let i = 0; i < files.length; i++ ) {
22
- let component = getComponentName(files[i]);
23
- components.push(component);
24
-
25
- let module = await context[files[i]]();
26
- app.component(component, module.default);
27
- }
28
-
29
- //load ra vue components
30
- files = Object.keys(context_ra);
31
-
32
- for ( let i = 0; i < files.length; i++ ) {
33
- let component = getComponentName(files[i]);
34
-
35
- //enable component overloading. if component is already defined in app, continue
36
- if ( components.includes(component) ) {
37
- continue;
38
- }
39
-
40
- let module = await context_ra[files[i]]();
41
- components.push(component);
42
- app.component(component, module.default);
43
- }
44
- }
1
+ import Str from './Support/Str.js';
2
+
3
+ let context_ra = import.meta.glob('/node_modules/@radiantabyss/vue-components/src/Components/**/*.vue', { eager: true });
4
+ let context = import.meta.glob('@/Components/**/*.vue', { eager: true });
5
+
6
+ function getComponentName(file) {
7
+ let split = file.split('/');
8
+ let name = split[split.length - 1].replace('.vue', '')
9
+ .replace(/Component$/, '')
10
+ .replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2')
11
+ .toLowerCase();
12
+
13
+ return Str.trim(name, '-');
14
+ }
15
+
16
+ export default async (app) => {
17
+ //load app components
18
+ let files = Object.keys(context);
19
+ let components = [];
20
+
21
+ for ( let i = 0; i < files.length; i++ ) {
22
+ let component = getComponentName(files[i]);
23
+ components.push(component);
24
+
25
+ let module = context[files[i]];
26
+ app.component(component, module.default);
27
+ }
28
+
29
+ //load ra vue components
30
+ files = Object.keys(context_ra);
31
+
32
+ for ( let i = 0; i < files.length; i++ ) {
33
+ let component = getComponentName(files[i]);
34
+
35
+ //enable component overloading. if component is already defined in app, continue
36
+ if ( components.includes(component) ) {
37
+ continue;
38
+ }
39
+
40
+ let module = context_ra[files[i]];
41
+ components.push(component);
42
+ app.component(component, module.default);
43
+ }
44
+ }
package/src/Directives.js CHANGED
@@ -1,20 +1,20 @@
1
- import Str from './Support/Str.js';
2
-
3
- let context = import.meta.glob('/app/Directives/**/*.js');
4
-
5
- export default async (app) => {
6
- const files = Object.keys(context);
7
-
8
- for ( let i = 0; i < files.length; i++ ) {
9
- let split = files[i].split('/');
10
- let name = split[split.length - 1].replace('.js', '')
11
- .replace(/Directive$/, '')
12
- .replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2')
13
- .toLowerCase();
14
-
15
- name = Str.trim(name, '-');
16
-
17
- let module = await context[files[i]]();
18
- app.directive(name, module.default);
19
- }
20
- }
1
+ import Str from './Support/Str.js';
2
+
3
+ let context = import.meta.glob('/app/Directives/**/*.js', { eager: true });
4
+
5
+ export default async (app) => {
6
+ const files = Object.keys(context);
7
+
8
+ for ( let i = 0; i < files.length; i++ ) {
9
+ let split = files[i].split('/');
10
+ let name = split[split.length - 1].replace('.js', '')
11
+ .replace(/Directive$/, '')
12
+ .replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2')
13
+ .toLowerCase();
14
+
15
+ name = Str.trim(name, '-');
16
+
17
+ let module = context[files[i]];
18
+ app.directive(name, module.default);
19
+ }
20
+ }
package/src/Mixins.js CHANGED
@@ -1,16 +1,18 @@
1
- let Mixins = {};
2
- let context = import.meta.glob('/app/Mixins/**/*.js');
3
-
4
- export default async () => {
5
- const files = Object.keys(context);
6
-
7
- for ( let i = 0; i < files.length; i++ ) {
8
- let split = files[i].split('/');
9
- let name = split[split.length - 1].replace('.js', '')
10
- .replace(/Mixin$/, '');
11
-
12
- let module = await context[files[i]]();
13
- Mixins[name] = module.default;
14
- }
15
- window.Mixins = Mixins;
16
- }
1
+ let Mixins = {};
2
+ let context = import.meta.glob('/app/Mixins/**/*.js', { eager: true });
3
+
4
+ //populate at module evaluation so eagerly loaded components can use Mixins.X in their definition
5
+ const files = Object.keys(context);
6
+
7
+ for ( let i = 0; i < files.length; i++ ) {
8
+ let split = files[i].split('/');
9
+ let name = split[split.length - 1].replace('.js', '')
10
+ .replace(/Mixin$/, '');
11
+
12
+ Mixins[name] = context[files[i]].default;
13
+ }
14
+ window.Mixins = Mixins;
15
+
16
+ export default async () => {
17
+ window.Mixins = Mixins;
18
+ }
package/src/Modals.js CHANGED
@@ -1,19 +1,19 @@
1
- import Str from './Support/Str.js';
2
-
3
- let context = import.meta.glob('/app/Modals/**/*.vue');
4
-
5
- export default async (app) => {
6
- const files = Object.keys(context);
7
-
8
- for ( let i = 0; i < files.length; i++ ) {
9
- let split = files[i].split('/');
10
- let name = split[split.length - 1].replace('.vue', '')
11
- .replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2')
12
- .toLowerCase();
13
-
14
- name = Str.trim(name, '-');
15
-
16
- let module = await context[files[i]]();
17
- app.component(name, module.default);
18
- }
19
- }
1
+ import Str from './Support/Str.js';
2
+
3
+ let context = import.meta.glob('/app/Modals/**/*.vue', { eager: true });
4
+
5
+ export default async (app) => {
6
+ const files = Object.keys(context);
7
+
8
+ for ( let i = 0; i < files.length; i++ ) {
9
+ let split = files[i].split('/');
10
+ let name = split[split.length - 1].replace('.vue', '')
11
+ .replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2')
12
+ .toLowerCase();
13
+
14
+ name = Str.trim(name, '-');
15
+
16
+ let module = context[files[i]];
17
+ app.component(name, module.default);
18
+ }
19
+ }
package/src/Request.js CHANGED
@@ -1,311 +1,337 @@
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 = {};
4
-
5
- const formatErrors = function(response) {
6
- let errors = [];
7
- if ( response && response.errors ) {
8
- for ( let i in response.errors ) {
9
- if ( typeof response.errors[i] === 'object' ) {
10
- for (let j in response.errors[i]) {
11
- errors.push(response.errors[i][j]);
12
- }
13
- }
14
- else {
15
- errors.push(response.errors[i]);
16
- }
17
- }
18
- }
19
- else if ( response.statusText ) {
20
- errors.push(response.statusText);
21
- }
22
-
23
- return errors;
24
- };
25
-
26
- const serializeToURLEncoded = (obj, prefix) => {
27
- const str = [];
28
- for ( let p in obj ) {
29
- if ( obj.hasOwnProperty(p) ) {
30
- const key = prefix ? `${prefix}[${p}]` : p;
31
- const value = obj[p];
32
-
33
- if ( typeof value === "object" ) {
34
- str.push(serializeToURLEncoded(value, key));
35
- }
36
- else {
37
- str.push(encodeURIComponent(key) + "=" + encodeURIComponent(value));
38
- }
39
- }
40
- }
41
- return str.join("&");
42
- };
43
-
44
- const appendFormData = (formData, key, value) => {
45
- if ( value instanceof Blob ) {
46
- formData.append(key, value);
47
- }
48
- else if ( Array.isArray(value) ) {
49
- value.forEach((v) => formData.append(`${key}[]`, v));
50
- }
51
- else if ( typeof value === 'object' && value !== null ) {
52
- for ( let subKey in value ) {
53
- appendFormData(formData, `${key}[${subKey}]`, value[subKey]);
54
- }
55
- }
56
- else {
57
- formData.append(key, value);
58
- }
59
- };
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
-
91
- //recursively drop undefined values; null is dropped too, or sent as an empty string when null_as_empty
92
- //is set (form bodies can't carry null, and `key=` lets the backend read it as null to clear a field)
93
- const cleanPayload = (value, null_as_empty) => {
94
- const isDropped = (v) => v === undefined || (v === null && !null_as_empty);
95
-
96
- if ( value === null ) {
97
- return null_as_empty ? '' : value;
98
- }
99
-
100
- if ( Array.isArray(value) ) {
101
- return value.filter((v) => !isDropped(v)).map((v) => cleanPayload(v, null_as_empty));
102
- }
103
-
104
- if ( typeof value === 'object' && !(value instanceof Blob) ) {
105
- const cleaned = {};
106
- for ( let key in value ) {
107
- if ( isDropped(value[key]) ) {
108
- continue;
109
- }
110
-
111
- cleaned[key] = cleanPayload(value[key], null_as_empty);
112
- }
113
-
114
- return cleaned;
115
- }
116
-
117
- return value;
118
- };
119
-
120
- const request = function(method, edge, payload = {}, display_errors = false, base_url = null, auth_token = null, headers = {}, upload_progress = null) {
121
- return new Promise((resolve, reject) => {
122
- if ( !base_url ) {
123
- base_url = import.meta.env.VITE_BACK_URL;
124
- }
125
-
126
- if ( !auth_token ) {
127
- auth_token = localStorage.getItem('jwt_token');
128
- }
129
-
130
- if ( method == 'POST' ) {
131
- Alert.hide();
132
- }
133
-
134
- if ( !Object.keys(headers).length ) {
135
- headers = {
136
- 'Content-Type': 'application/x-www-form-urlencoded',
137
- };
138
- }
139
-
140
- let _button;
141
- if ( payload._button !== undefined ) {
142
- _button = payload._button;
143
- delete payload._button;
144
- }
145
-
146
- let _event;
147
- if ( payload._event !== undefined ) {
148
- _event = payload._event;
149
- _event.preventDefault();
150
-
151
- if ( _button === undefined ) {
152
- _button = _event.target;
153
- }
154
-
155
- delete payload._event;
156
- }
157
-
158
- if ( _button !== undefined ) {
159
- if ( _button.disabled ) {
160
- return;
161
- }
162
- _button.disabled = true;
163
- }
164
-
165
- let _cancel;
166
- if ( payload._cancel !== undefined ) {
167
- _cancel = new AbortController();
168
- delete payload._cancel;
169
-
170
- if ( current[edge] ) {
171
- try {
172
- current[edge].abort();
173
- }
174
- catch(e) {}
175
- }
176
-
177
- current[edge] = _cancel;
178
- }
179
-
180
- //drop undefined keys; GET drops null too, POST sends it as an empty value
181
- payload = cleanPayload(payload, method != 'GET');
182
-
183
- let data;
184
- let url = base_url + edge;
185
-
186
- if ( method == 'GET' ) {
187
- if ( get_params_format == 'php' ) {
188
- url += '?' + buildParams(payload);
189
- }
190
- else {
191
- url += '?' + new URLSearchParams(payload).toString();
192
- }
193
- }
194
- else if ( method == 'POST' ) {
195
- if ( headers['Content-Type'] == 'multipart/form-data' ) {
196
- data = new FormData();
197
-
198
- for ( let key in payload ) {
199
- appendFormData(data, key, payload[key]);
200
- }
201
-
202
- delete headers['Content-Type'];
203
- }
204
- else if ( headers['Content-Type'] == 'application/x-www-form-urlencoded' ) {
205
- data = serializeToURLEncoded(payload).replace(/\&+$/, '');
206
- }
207
- else {
208
- data = JSON.stringify(payload);
209
- headers['Content-Type'] = 'application/x-www-form-urlencoded';
210
- }
211
- }
212
-
213
- if ( auth_token ) {
214
- if ( typeof auth_token !== 'object' ) {
215
- auth_token = { jwt_token: auth_token };
216
- }
217
- for ( let key in auth_token ) {
218
- if ( auth_token[key] !== '' && auth_token[key] !== null ) {
219
- url += url.includes('?') ? '&' : '?';
220
- url += `${key}=${auth_token[key]}`;
221
- }
222
- }
223
- }
224
-
225
- let _button_html;
226
- if ( typeof _button !== 'undefined' ) {
227
- _button_html = _button.innerHTML;
228
-
229
- if ( payload._replace_html ) {
230
- _button.innerHTML = `<svg class="svg-request-spinner"><use xlink:href="/sprites.svg?v=${sprite_version}#request-spinner"></use></svg>`;
231
- }
232
- else {
233
- _button.innerHTML += `&nbsp;<svg class="svg-request-spinner"><use xlink:href="/sprites.svg?v=${sprite_version}#request-spinner"></use></svg>`;
234
- }
235
- }
236
-
237
- let options = { method, headers };
238
-
239
- if ( method != 'GET' ) {
240
- options.body = data;
241
- }
242
-
243
- if ( _cancel ) {
244
- options.signal = _cancel.signal;
245
- }
246
-
247
- fetch(url, options)
248
- .then(async (response) => {
249
- if ( _button !== undefined ) {
250
- _button.disabled = false;
251
- _button.innerHTML = _button_html;
252
- }
253
-
254
- delete current[edge];
255
-
256
- const response_data = await response.json();
257
-
258
- if ( edge.match(/\.json/) ) {
259
- return resolve(response_data);
260
- }
261
-
262
- if ( response.ok && response_data.success ) {
263
- return resolve(response_data.data);
264
- }
265
-
266
- const errors = formatErrors(response_data);
267
- if ( display_errors ) {
268
- Alert.error(errors.join('<br/>'), 7000);
269
- }
270
-
271
- reject(errors);
272
- })
273
- .catch((error) => {
274
- if ( error.name == 'AbortError' ) {
275
- return;
276
- }
277
-
278
- delete current[edge];
279
-
280
- let errors = [error.message];
281
-
282
- if ( display_errors ) {
283
- Alert.error(__('Internal Server Error. We\'re fixing the problem. Please retry in a couple of hours.'), 7000);
284
- }
285
-
286
- if ( _button !== undefined ) {
287
- _button.disabled = false;
288
- _button.innerHTML = _button_html;
289
- }
290
-
291
- reject(errors);
292
- });
293
- });
294
- };
295
-
296
- let self = {
297
- get(edge, payload = {}, display_errors = false, base_url = null, auth_token = null, headers = {}) {
298
- return request('GET', edge, payload, display_errors, base_url, auth_token, headers);
299
- },
300
-
301
- post(edge, payload = {}, display_errors = true, base_url = null, auth_token = null, headers = {}) {
302
- return request('POST', edge, payload, display_errors, base_url, auth_token, headers);
303
- },
304
-
305
- upload(edge, payload = {}, display_errors = true, upload_progress, base_url = null, auth_token = null, headers = {}) {
306
- headers['Content-Type'] = 'multipart/form-data';
307
- return request('POST', edge, payload, display_errors, base_url, auth_token, headers, upload_progress);
308
- },
309
- };
310
-
311
- export default self;
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 post_format = import.meta.env.VITE_POST_FORMAT || 'default';
4
+ let current = {};
5
+
6
+ //content type used for POST when the caller doesn't set one, picked by VITE_POST_FORMAT
7
+ const post_content_types = {
8
+ default: 'application/x-www-form-urlencoded',
9
+ form_data: 'multipart/form-data',
10
+ json: 'application/json',
11
+ };
12
+
13
+ const formatErrors = function(response) {
14
+ let errors = [];
15
+ if ( response && response.errors ) {
16
+ for ( let i in response.errors ) {
17
+ if ( typeof response.errors[i] === 'object' ) {
18
+ for (let j in response.errors[i]) {
19
+ errors.push(response.errors[i][j]);
20
+ }
21
+ }
22
+ else {
23
+ errors.push(response.errors[i]);
24
+ }
25
+ }
26
+ }
27
+ else if ( response.statusText ) {
28
+ errors.push(response.statusText);
29
+ }
30
+
31
+ return errors;
32
+ };
33
+
34
+ const serializeToURLEncoded = (obj, prefix) => {
35
+ const str = [];
36
+ for ( let p in obj ) {
37
+ if ( obj.hasOwnProperty(p) ) {
38
+ const key = prefix ? `${prefix}[${p}]` : p;
39
+ const value = obj[p];
40
+
41
+ if ( typeof value === "object" ) {
42
+ str.push(serializeToURLEncoded(value, key));
43
+ }
44
+ else {
45
+ str.push(encodeURIComponent(key) + "=" + encodeURIComponent(value));
46
+ }
47
+ }
48
+ }
49
+ return str.join("&");
50
+ };
51
+
52
+ const appendFormData = (formData, key, value) => {
53
+ if ( value instanceof Blob ) {
54
+ formData.append(key, value);
55
+ }
56
+ else if ( Array.isArray(value) ) {
57
+ value.forEach((v) => formData.append(`${key}[]`, v));
58
+ }
59
+ else if ( typeof value === 'object' && value !== null ) {
60
+ for ( let subKey in value ) {
61
+ appendFormData(formData, `${key}[${subKey}]`, value[subKey]);
62
+ }
63
+ }
64
+ else {
65
+ formData.append(key, value);
66
+ }
67
+ };
68
+
69
+ const buildParams = (obj, prefix = '', params = new URLSearchParams()) => {
70
+ Object.entries(obj).forEach(([key, value]) => {
71
+ const full_key = prefix ? `${prefix}[${key}]` : key;
72
+
73
+ if ( Array.isArray(value) ) {
74
+ if ( value.length ) {
75
+ value.forEach((v, i) => {
76
+ if (typeof v === 'object') {
77
+ buildParams(v, `${full_key}[${i}]`, params);
78
+ }
79
+ else {
80
+ params.append(`${full_key}[]`, v);
81
+ }
82
+ });
83
+ }
84
+ else {
85
+ params.append(full_key, value);
86
+ }
87
+ }
88
+ else if ( typeof value === 'object' && value !== null ) {
89
+ buildParams(value, full_key, params);
90
+ }
91
+ else {
92
+ params.append(full_key, value);
93
+ }
94
+ });
95
+
96
+ return params;
97
+ }
98
+
99
+ //recursively drop undefined values. nulls and empty arrays follow the `empty` mode:
100
+ //'drop' removes them, 'empty' sends them as an empty string (form bodies can't carry null or [],
101
+ //and `key=` lets the backend read it as null to clear a field), 'keep' leaves them as-is (json)
102
+ const cleanPayload = (value, empty) => {
103
+ if ( value === null ) {
104
+ if ( empty == 'keep' ) {
105
+ return null;
106
+ }
107
+
108
+ return empty == 'empty' ? '' : undefined;
109
+ }
110
+
111
+ if ( Array.isArray(value) ) {
112
+ const cleaned = value.map((v) => cleanPayload(v, empty)).filter((v) => v !== undefined);
113
+
114
+ if ( !cleaned.length && empty != 'keep' ) {
115
+ return empty == 'empty' ? '' : undefined;
116
+ }
117
+
118
+ return cleaned;
119
+ }
120
+
121
+ if ( typeof value === 'object' && !(value instanceof Blob) ) {
122
+ const cleaned = {};
123
+ for ( let key in value ) {
124
+ const v = cleanPayload(value[key], empty);
125
+
126
+ if ( v !== undefined ) {
127
+ cleaned[key] = v;
128
+ }
129
+ }
130
+
131
+ return cleaned;
132
+ }
133
+
134
+ return value;
135
+ };
136
+
137
+ const request = function(method, edge, payload = {}, display_errors = false, base_url = null, auth_token = null, headers = {}, upload_progress = null) {
138
+ return new Promise((resolve, reject) => {
139
+ if ( !base_url ) {
140
+ base_url = import.meta.env.VITE_BACK_URL;
141
+ }
142
+
143
+ if ( !auth_token ) {
144
+ auth_token = localStorage.getItem('jwt_token');
145
+ }
146
+
147
+ if ( method == 'POST' ) {
148
+ Alert.hide();
149
+ }
150
+
151
+ headers = { ...headers };
152
+
153
+ if ( method == 'POST' && !headers['Content-Type'] ) {
154
+ headers['Content-Type'] = post_content_types[post_format] || post_content_types.default;
155
+ }
156
+
157
+ let _button;
158
+ if ( payload._button !== undefined ) {
159
+ _button = payload._button;
160
+ delete payload._button;
161
+ }
162
+
163
+ let _event;
164
+ if ( payload._event !== undefined ) {
165
+ _event = payload._event;
166
+ _event.preventDefault();
167
+
168
+ if ( _button === undefined ) {
169
+ _button = _event.target;
170
+ }
171
+
172
+ delete payload._event;
173
+ }
174
+
175
+ if ( _button !== undefined ) {
176
+ if ( _button.disabled ) {
177
+ return;
178
+ }
179
+ _button.disabled = true;
180
+ }
181
+
182
+ let _cancel;
183
+ if ( payload._cancel !== undefined ) {
184
+ _cancel = new AbortController();
185
+ delete payload._cancel;
186
+
187
+ if ( current[edge] ) {
188
+ try {
189
+ current[edge].abort();
190
+ }
191
+ catch(e) {}
192
+ }
193
+
194
+ current[edge] = _cancel;
195
+ }
196
+
197
+ //drop undefined keys; nulls and empty arrays are dropped on GET, sent as empty values
198
+ //in form bodies and kept as-is in json
199
+ let empty = 'keep';
200
+ if ( method == 'GET' ) {
201
+ empty = 'drop';
202
+ }
203
+ else if ( ['multipart/form-data', 'application/x-www-form-urlencoded'].includes(headers['Content-Type']) ) {
204
+ empty = 'empty';
205
+ }
206
+
207
+ payload = cleanPayload(payload, empty);
208
+
209
+ let data;
210
+ let url = base_url + edge;
211
+
212
+ if ( method == 'GET' ) {
213
+ if ( get_params_format == 'php' ) {
214
+ url += '?' + buildParams(payload);
215
+ }
216
+ else {
217
+ url += '?' + new URLSearchParams(payload).toString();
218
+ }
219
+ }
220
+ else if ( method == 'POST' ) {
221
+ if ( headers['Content-Type'] == 'multipart/form-data' ) {
222
+ data = new FormData();
223
+
224
+ for ( let key in payload ) {
225
+ appendFormData(data, key, payload[key]);
226
+ }
227
+
228
+ delete headers['Content-Type'];
229
+ }
230
+ else if ( headers['Content-Type'] == 'application/x-www-form-urlencoded' ) {
231
+ data = serializeToURLEncoded(payload).replace(/\&+$/, '');
232
+ }
233
+ else {
234
+ data = JSON.stringify(payload);
235
+ headers['Content-Type'] = 'application/json';
236
+ }
237
+ }
238
+
239
+ if ( auth_token ) {
240
+ if ( typeof auth_token !== 'object' ) {
241
+ auth_token = { jwt_token: auth_token };
242
+ }
243
+ for ( let key in auth_token ) {
244
+ if ( auth_token[key] !== '' && auth_token[key] !== null ) {
245
+ url += url.includes('?') ? '&' : '?';
246
+ url += `${key}=${auth_token[key]}`;
247
+ }
248
+ }
249
+ }
250
+
251
+ let _button_html;
252
+ if ( typeof _button !== 'undefined' ) {
253
+ _button_html = _button.innerHTML;
254
+
255
+ if ( payload._replace_html ) {
256
+ _button.innerHTML = `<svg class="svg-request-spinner"><use xlink:href="/sprites.svg?v=${sprite_version}#request-spinner"></use></svg>`;
257
+ }
258
+ else {
259
+ _button.innerHTML += `&nbsp;<svg class="svg-request-spinner"><use xlink:href="/sprites.svg?v=${sprite_version}#request-spinner"></use></svg>`;
260
+ }
261
+ }
262
+
263
+ let options = { method, headers };
264
+
265
+ if ( method != 'GET' ) {
266
+ options.body = data;
267
+ }
268
+
269
+ if ( _cancel ) {
270
+ options.signal = _cancel.signal;
271
+ }
272
+
273
+ fetch(url, options)
274
+ .then(async (response) => {
275
+ if ( _button !== undefined ) {
276
+ _button.disabled = false;
277
+ _button.innerHTML = _button_html;
278
+ }
279
+
280
+ delete current[edge];
281
+
282
+ const response_data = await response.json();
283
+
284
+ if ( edge.match(/\.json/) ) {
285
+ return resolve(response_data);
286
+ }
287
+
288
+ if ( response.ok && response_data.success ) {
289
+ return resolve(response_data.data);
290
+ }
291
+
292
+ const errors = formatErrors(response_data);
293
+ if ( display_errors ) {
294
+ Alert.error(errors.join('<br/>'), 7000);
295
+ }
296
+
297
+ reject(errors);
298
+ })
299
+ .catch((error) => {
300
+ if ( error.name == 'AbortError' ) {
301
+ return;
302
+ }
303
+
304
+ delete current[edge];
305
+
306
+ let errors = [error.message];
307
+
308
+ if ( display_errors ) {
309
+ Alert.error(__('Internal Server Error. We\'re fixing the problem. Please retry in a couple of hours.'), 7000);
310
+ }
311
+
312
+ if ( _button !== undefined ) {
313
+ _button.disabled = false;
314
+ _button.innerHTML = _button_html;
315
+ }
316
+
317
+ reject(errors);
318
+ });
319
+ });
320
+ };
321
+
322
+ let self = {
323
+ get(edge, payload = {}, display_errors = false, base_url = null, auth_token = null, headers = {}) {
324
+ return request('GET', edge, payload, display_errors, base_url, auth_token, headers);
325
+ },
326
+
327
+ post(edge, payload = {}, display_errors = true, base_url = null, auth_token = null, headers = {}) {
328
+ return request('POST', edge, payload, display_errors, base_url, auth_token, headers);
329
+ },
330
+
331
+ upload(edge, payload = {}, display_errors = true, upload_progress, base_url = null, auth_token = null, headers = {}) {
332
+ headers['Content-Type'] = 'multipart/form-data';
333
+ return request('POST', edge, payload, display_errors, base_url, auth_token, headers, upload_progress);
334
+ },
335
+ };
336
+
337
+ export default self;
@@ -1,47 +1,47 @@
1
- let Actions = {};
2
- let context = import.meta.glob('/app/Domains/**/*.vue');
3
-
4
- const loadModules = async () => {
5
- const files = Object.keys(context);
6
-
7
- for ( let i = 0; i < files.length; i++ ) {
8
- let split = files[i].split('/');
9
- split.shift();
10
- let name = split[split.length - 1].replace('.vue', '');
11
- split.pop();
12
- split.pop();
13
- split.shift();
14
- split.shift();
15
-
16
- if ( !name.match(/Action$/) || name == 'Action' ) {
17
- continue;
18
- }
19
-
20
- let module = await context[files[i]]();
21
- setNamespace(Actions, name, split, module);
22
- }
23
- }
24
-
25
- function setNamespace(Actions, name, namespace, module) {
26
- if ( !namespace.length ) {
27
- Actions[name] = module.default;
28
- return;
29
- }
30
-
31
- let first = namespace[0].replace(/-/g, ' ').replace(/_/g, ' ').replace(/(^([a-zA-Z\p{M}]))|([ -][a-zA-Z\p{M}])/g,function(s) {
32
- return s.toUpperCase();
33
- }).replace(/ /g, '');
34
-
35
- namespace.shift();
36
-
37
- if ( !Actions[first] ) {
38
- Actions[first] = {};
39
- }
40
-
41
- setNamespace(Actions[first], name, namespace, module);
42
- }
43
-
44
- export default async () => {
45
- await loadModules();
46
- return Actions;
47
- }
1
+ let Actions = {};
2
+ let context = import.meta.glob('/app/Domains/**/*.vue', { eager: true });
3
+
4
+ const loadModules = async () => {
5
+ const files = Object.keys(context);
6
+
7
+ for ( let i = 0; i < files.length; i++ ) {
8
+ let split = files[i].split('/');
9
+ split.shift();
10
+ let name = split[split.length - 1].replace('.vue', '');
11
+ split.pop();
12
+ split.pop();
13
+ split.shift();
14
+ split.shift();
15
+
16
+ if ( !name.match(/Action$/) || name == 'Action' ) {
17
+ continue;
18
+ }
19
+
20
+ let module = context[files[i]];
21
+ setNamespace(Actions, name, split, module);
22
+ }
23
+ }
24
+
25
+ function setNamespace(Actions, name, namespace, module) {
26
+ if ( !namespace.length ) {
27
+ Actions[name] = module.default;
28
+ return;
29
+ }
30
+
31
+ let first = namespace[0].replace(/-/g, ' ').replace(/_/g, ' ').replace(/(^([a-zA-Z\p{M}]))|([ -][a-zA-Z\p{M}])/g,function(s) {
32
+ return s.toUpperCase();
33
+ }).replace(/ /g, '');
34
+
35
+ namespace.shift();
36
+
37
+ if ( !Actions[first] ) {
38
+ Actions[first] = {};
39
+ }
40
+
41
+ setNamespace(Actions[first], name, namespace, module);
42
+ }
43
+
44
+ export default async () => {
45
+ await loadModules();
46
+ return Actions;
47
+ }
@@ -1,41 +1,41 @@
1
- let Middleware = {};
2
- let context = import.meta.glob('/app/Http/Middleware/**/*.js');
3
-
4
- const loadModules = async () => {
5
- const files = Object.keys(context);
6
-
7
- for ( let i = 0; i < files.length; i++ ) {
8
- let split = files[i].split('/');
9
- let name = split[split.length - 1].replace('.js', '').replace('Middleware', '');
10
- let module = await context[files[i]]();
11
- Middleware[name] = module.default;
12
- }
13
- }
14
-
15
- let runMiddleware = async (to, from, i = 0) => {
16
- //reached end, then everything passed
17
- if ( i == to.meta.middleware.length ) {
18
- return;
19
- }
20
-
21
- //middleware doesnt exist
22
- if ( !Middleware[to.meta.middleware[i]] ) {
23
- throw new Error(`${to.meta.middleware[i]} Middleware not found.`);
24
- }
25
-
26
- //run middleware
27
- await Middleware[to.meta.middleware[i]](to, from);
28
- await runMiddleware(to, from, i + 1);
29
- }
30
-
31
- export default async () => {
32
- await loadModules();
33
-
34
- return async (to, from) => {
35
- if ( !to.meta || !to.meta.middleware ) {
36
- return;
37
- }
38
-
39
- return runMiddleware(to, from);
40
- };
41
- }
1
+ let Middleware = {};
2
+ let context = import.meta.glob('/app/Http/Middleware/**/*.js', { eager: true });
3
+
4
+ const loadModules = async () => {
5
+ const files = Object.keys(context);
6
+
7
+ for ( let i = 0; i < files.length; i++ ) {
8
+ let split = files[i].split('/');
9
+ let name = split[split.length - 1].replace('.js', '').replace('Middleware', '');
10
+ let module = context[files[i]];
11
+ Middleware[name] = module.default;
12
+ }
13
+ }
14
+
15
+ let runMiddleware = async (to, from, i = 0) => {
16
+ //reached end, then everything passed
17
+ if ( i == to.meta.middleware.length ) {
18
+ return;
19
+ }
20
+
21
+ //middleware doesnt exist
22
+ if ( !Middleware[to.meta.middleware[i]] ) {
23
+ throw new Error(`${to.meta.middleware[i]} Middleware not found.`);
24
+ }
25
+
26
+ //run middleware
27
+ await Middleware[to.meta.middleware[i]](to, from);
28
+ await runMiddleware(to, from, i + 1);
29
+ }
30
+
31
+ export default async () => {
32
+ await loadModules();
33
+
34
+ return async (to, from) => {
35
+ if ( !to.meta || !to.meta.middleware ) {
36
+ return;
37
+ }
38
+
39
+ return runMiddleware(to, from);
40
+ };
41
+ }
package/src/Store.js CHANGED
@@ -1,54 +1,54 @@
1
- import { createStore } from 'vuex';
2
-
3
- const Modules = {};
4
- let context = import.meta.glob('/app/Store/**/*.js');
5
-
6
- const loadModules = async () => {
7
- const files = Object.keys(context);
8
-
9
- for ( let i = 0; i < files.length; i++ ) {
10
- let split = files[i].split('/');
11
- split.shift();
12
- split.shift();
13
- split.shift();
14
-
15
- let name = split[split.length - 1].replace('.js', '');
16
- split.pop();
17
-
18
- let module = await context[files[i]]();
19
- setNamespace(Modules, name, split, module);
20
- }
21
- }
22
-
23
- function setNamespace(Modules, name, namespace, module) {
24
- if ( !namespace.length ) {
25
- Modules[name] = module.default;
26
- return;
27
- }
28
-
29
- let first = namespace[0].replace(/-/g, ' ').replace(/_/g, ' ').replace(/(^([a-zA-Z\p{M}]))|([ -][a-zA-Z\p{M}])/g,function(s) {
30
- return s.toUpperCase();
31
- }).replace(/ /g, '');
32
-
33
- namespace.shift();
34
-
35
- if ( !Modules[first] ) {
36
- Modules[first] = {
37
- namespaced: true,
38
- modules: {},
39
- };
40
- }
41
-
42
- setNamespace(Modules[first].modules, name, namespace, module);
43
- }
44
-
45
- export default async (app) => {
46
- await loadModules();
47
-
48
- const Store = createStore({
49
- modules: Modules,
50
- });
51
-
52
- window.Store = Store;
53
- app.use(Store);
54
- };
1
+ import { createStore } from 'vuex';
2
+
3
+ const Modules = {};
4
+ let context = import.meta.glob('/app/Store/**/*.js', { eager: true });
5
+
6
+ const loadModules = async () => {
7
+ const files = Object.keys(context);
8
+
9
+ for ( let i = 0; i < files.length; i++ ) {
10
+ let split = files[i].split('/');
11
+ split.shift();
12
+ split.shift();
13
+ split.shift();
14
+
15
+ let name = split[split.length - 1].replace('.js', '');
16
+ split.pop();
17
+
18
+ let module = context[files[i]];
19
+ setNamespace(Modules, name, split, module);
20
+ }
21
+ }
22
+
23
+ function setNamespace(Modules, name, namespace, module) {
24
+ if ( !namespace.length ) {
25
+ Modules[name] = module.default;
26
+ return;
27
+ }
28
+
29
+ let first = namespace[0].replace(/-/g, ' ').replace(/_/g, ' ').replace(/(^([a-zA-Z\p{M}]))|([ -][a-zA-Z\p{M}])/g,function(s) {
30
+ return s.toUpperCase();
31
+ }).replace(/ /g, '');
32
+
33
+ namespace.shift();
34
+
35
+ if ( !Modules[first] ) {
36
+ Modules[first] = {
37
+ namespaced: true,
38
+ modules: {},
39
+ };
40
+ }
41
+
42
+ setNamespace(Modules[first].modules, name, namespace, module);
43
+ }
44
+
45
+ export default async (app) => {
46
+ await loadModules();
47
+
48
+ const Store = createStore({
49
+ modules: Modules,
50
+ });
51
+
52
+ window.Store = Store;
53
+ app.use(Store);
54
+ };