@radiantabyss/vue 3.3.19 → 4.0.0
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 +31 -28
- package/src/Bootstrap.js +60 -53
- package/src/Components.js +44 -44
- package/src/Directives.js +20 -20
- package/src/Invoke.js +89 -89
- package/src/Mixins.js +18 -16
- package/src/Modals.js +19 -19
- package/src/Routing/Actions.js +47 -47
- package/src/Routing/Middleware.js +41 -41
- package/src/Routing/Route.js +77 -77
- package/src/Routing/RouteCrud.js +15 -15
- package/src/Routing/Router.js +115 -115
- package/src/Store.js +54 -54
- package/src/Support/Helpers.js +0 -25
- package/src/Support/Item.js +0 -67
- package/src/Support/Items.js +0 -363
- package/src/Support/Str.js +0 -382
|
@@ -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 =
|
|
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/Routing/Route.js
CHANGED
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
import Str from '
|
|
2
|
-
|
|
3
|
-
let group_middleware = null;
|
|
4
|
-
|
|
5
|
-
function addRoute(path, action, middleware, name, throw_error) {
|
|
6
|
-
if ( !action ) {
|
|
7
|
-
throw `Action missing for ${path}`;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
//format path
|
|
11
|
-
path = path.replace(/\{([\s\S]+?)\}/g, ':$1');
|
|
12
|
-
|
|
13
|
-
//get action
|
|
14
|
-
action = action.replace(/\\/g, '.').replace(/\//g, '.');
|
|
15
|
-
let split = action.split('.');
|
|
16
|
-
let namespace = split.slice(0, -1);
|
|
17
|
-
let action_name = name || split[split.length - 1];
|
|
18
|
-
let domain = namespace.length ? Str.slug(namespace[0]) : '';
|
|
19
|
-
|
|
20
|
-
if ( namespace.length ) {
|
|
21
|
-
action_name = namespace.join('/') + '/' + action_name;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
let component;
|
|
25
|
-
try {
|
|
26
|
-
component = getAction(Actions, split[split.length - 1], namespace, action_name);
|
|
27
|
-
}
|
|
28
|
-
catch(e) {
|
|
29
|
-
if ( throw_error ) {
|
|
30
|
-
throw `Action ${action_name} doesn't exist.`;
|
|
31
|
-
}
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
RouteFiles[__route_file].push({
|
|
36
|
-
name: action_name,
|
|
37
|
-
component,
|
|
38
|
-
path,
|
|
39
|
-
meta: {
|
|
40
|
-
domain,
|
|
41
|
-
middleware,
|
|
42
|
-
settings: component.settings ? component.settings : {},
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function getAction(Actions, name, namespace, action_name) {
|
|
48
|
-
if ( !namespace.length ) {
|
|
49
|
-
let action = Actions[name];
|
|
50
|
-
|
|
51
|
-
action.name = action_name.replace(/\\/g, '.');
|
|
52
|
-
return action;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
let first = namespace[0];
|
|
56
|
-
namespace.shift();
|
|
57
|
-
|
|
58
|
-
return getAction(Actions[first], name, namespace, action_name);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
let self = {
|
|
62
|
-
get(path, action, middleware = [], name = '', throw_error = true) {
|
|
63
|
-
if ( group_middleware ) {
|
|
64
|
-
middleware = middleware.concat(group_middleware);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
addRoute(path, action, middleware, name, throw_error);
|
|
68
|
-
},
|
|
69
|
-
|
|
70
|
-
group(middleware, callback) {
|
|
71
|
-
group_middleware = middleware;
|
|
72
|
-
callback();
|
|
73
|
-
group_middleware = null;
|
|
74
|
-
},
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export default self;
|
|
1
|
+
import Str from '@radiantabyss/support/src/Str.js';
|
|
2
|
+
|
|
3
|
+
let group_middleware = null;
|
|
4
|
+
|
|
5
|
+
function addRoute(path, action, middleware, name, throw_error) {
|
|
6
|
+
if ( !action ) {
|
|
7
|
+
throw `Action missing for ${path}`;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
//format path
|
|
11
|
+
path = path.replace(/\{([\s\S]+?)\}/g, ':$1');
|
|
12
|
+
|
|
13
|
+
//get action
|
|
14
|
+
action = action.replace(/\\/g, '.').replace(/\//g, '.');
|
|
15
|
+
let split = action.split('.');
|
|
16
|
+
let namespace = split.slice(0, -1);
|
|
17
|
+
let action_name = name || split[split.length - 1];
|
|
18
|
+
let domain = namespace.length ? Str.slug(namespace[0]) : '';
|
|
19
|
+
|
|
20
|
+
if ( namespace.length ) {
|
|
21
|
+
action_name = namespace.join('/') + '/' + action_name;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let component;
|
|
25
|
+
try {
|
|
26
|
+
component = getAction(Actions, split[split.length - 1], namespace, action_name);
|
|
27
|
+
}
|
|
28
|
+
catch(e) {
|
|
29
|
+
if ( throw_error ) {
|
|
30
|
+
throw `Action ${action_name} doesn't exist.`;
|
|
31
|
+
}
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
RouteFiles[__route_file].push({
|
|
36
|
+
name: action_name,
|
|
37
|
+
component,
|
|
38
|
+
path,
|
|
39
|
+
meta: {
|
|
40
|
+
domain,
|
|
41
|
+
middleware,
|
|
42
|
+
settings: component.settings ? component.settings : {},
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function getAction(Actions, name, namespace, action_name) {
|
|
48
|
+
if ( !namespace.length ) {
|
|
49
|
+
let action = Actions[name];
|
|
50
|
+
|
|
51
|
+
action.name = action_name.replace(/\\/g, '.');
|
|
52
|
+
return action;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let first = namespace[0];
|
|
56
|
+
namespace.shift();
|
|
57
|
+
|
|
58
|
+
return getAction(Actions[first], name, namespace, action_name);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let self = {
|
|
62
|
+
get(path, action, middleware = [], name = '', throw_error = true) {
|
|
63
|
+
if ( group_middleware ) {
|
|
64
|
+
middleware = middleware.concat(group_middleware);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
addRoute(path, action, middleware, name, throw_error);
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
group(middleware, callback) {
|
|
71
|
+
group_middleware = middleware;
|
|
72
|
+
callback();
|
|
73
|
+
group_middleware = null;
|
|
74
|
+
},
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export default self;
|
package/src/Routing/RouteCrud.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import Str from '
|
|
2
|
-
|
|
3
|
-
let self = {
|
|
4
|
-
run(domain) {
|
|
5
|
-
domain = domain.replace(/\\/g, '.').replace(/\//g, '.');
|
|
6
|
-
let prefix = Str.kebab(domain).replace(/\./g, '/');
|
|
7
|
-
|
|
8
|
-
Route.get(`/${prefix}`, `${domain}.ListAction`, [], '', false);
|
|
9
|
-
Route.get(`/${prefix}/new/{id?}`, `${domain}.NewAction`, [], '', false);
|
|
10
|
-
Route.get(`/${prefix}/edit/{id}`, `${domain}.EditAction`, [], '', false);
|
|
11
|
-
Route.get(`/${prefix}/single/{id}`, `${domain}.SingleAction`, [], '', false);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default self;
|
|
1
|
+
import Str from '@radiantabyss/support/src/Str.js';
|
|
2
|
+
|
|
3
|
+
let self = {
|
|
4
|
+
run(domain) {
|
|
5
|
+
domain = domain.replace(/\\/g, '.').replace(/\//g, '.');
|
|
6
|
+
let prefix = Str.kebab(domain).replace(/\./g, '/');
|
|
7
|
+
|
|
8
|
+
Route.get(`/${prefix}`, `${domain}.ListAction`, [], '', false);
|
|
9
|
+
Route.get(`/${prefix}/new/{id?}`, `${domain}.NewAction`, [], '', false);
|
|
10
|
+
Route.get(`/${prefix}/edit/{id}`, `${domain}.EditAction`, [], '', false);
|
|
11
|
+
Route.get(`/${prefix}/single/{id}`, `${domain}.SingleAction`, [], '', false);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default self;
|
package/src/Routing/Router.js
CHANGED
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
import { nextTick, watch } from 'vue';
|
|
2
|
-
import { createRouter, createWebHistory, createWebHashHistory, createMemoryHistory } from 'vue-router';
|
|
3
|
-
import Str from '
|
|
4
|
-
import Actions from './Actions.js';
|
|
5
|
-
import Middleware from './Middleware.js';
|
|
6
|
-
import RouteFiles from './RouteFiles.js';
|
|
7
|
-
import Route from './Route.js';
|
|
8
|
-
import RouteCrud from './RouteCrud.js';
|
|
9
|
-
|
|
10
|
-
window.RouteFiles = RouteFiles;
|
|
11
|
-
window.Route = Route;
|
|
12
|
-
window.RouteCrud = RouteCrud;
|
|
13
|
-
|
|
14
|
-
//load route files
|
|
15
|
-
let context = import.meta.glob('/app/Routes/**/*.js');
|
|
16
|
-
|
|
17
|
-
const loadModules = async () => {
|
|
18
|
-
window.Actions = await Actions();
|
|
19
|
-
const files = Object.keys(context);
|
|
20
|
-
|
|
21
|
-
for ( let i = 0; i < files.length; i++ ) {
|
|
22
|
-
let file = files[i].replace('/app/Routes/', '').replace(/\.js$/, '');
|
|
23
|
-
window.__route_file = file;
|
|
24
|
-
|
|
25
|
-
if ( !RouteFiles[__route_file] ) {
|
|
26
|
-
RouteFiles[__route_file] = [];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
await context[files[i]]();
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export default async (history_mode = 'web') => {
|
|
34
|
-
let runMiddleware = await Middleware();
|
|
35
|
-
|
|
36
|
-
await loadModules();
|
|
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
|
-
|
|
49
|
-
//create router
|
|
50
|
-
const Router = createRouter({
|
|
51
|
-
history,
|
|
52
|
-
routes: [],
|
|
53
|
-
duplicateNavigationPolicy: 'reload',
|
|
54
|
-
scrollBehavior(to, from, scroll) {
|
|
55
|
-
if ( (to.meta.settings && to.meta.settings.disable_scroll)
|
|
56
|
-
|| (from.name == to.name && (!to.meta.settings || !to.meta.settings.force_scroll)) ) {
|
|
57
|
-
return scroll;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return {
|
|
61
|
-
x: 0,
|
|
62
|
-
y: 0
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
//run middleware
|
|
68
|
-
Router.beforeEach(async (to, from, next) => {
|
|
69
|
-
try {
|
|
70
|
-
await runMiddleware(to, from);
|
|
71
|
-
next();
|
|
72
|
-
}
|
|
73
|
-
catch(redirect) {
|
|
74
|
-
if ( redirect === false || to.path == redirect ) {
|
|
75
|
-
return next();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
next({path: redirect});
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
Router.afterEach((to, from) => {
|
|
83
|
-
//save previous route
|
|
84
|
-
localStorage.setItem('_previous_route', from.fullPath != '/' ? from.fullPath : '');
|
|
85
|
-
|
|
86
|
-
//change document title
|
|
87
|
-
let title = to.name.replace(/\//g, ' / ').replace(/Action$/, '');
|
|
88
|
-
if ( to.meta.settings.title ) {
|
|
89
|
-
if ( typeof to.meta.settings.title == 'function' ) {
|
|
90
|
-
nextTick(async () => {
|
|
91
|
-
let instance = to.matched[to.matched.length - 1]?.instances?.default;
|
|
92
|
-
if ( !instance ) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
watch(
|
|
97
|
-
() => ({ ...instance.$data }),
|
|
98
|
-
async () => {
|
|
99
|
-
document.title = await to.meta.settings.title.call(instance);
|
|
100
|
-
},
|
|
101
|
-
{ deep: true }
|
|
102
|
-
);
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
document.title = to.meta.settings.title;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
document.title = `${title} :: ${import.meta.env.VITE_NAME}`;
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
return { Router, RouteFiles };
|
|
115
|
-
};
|
|
1
|
+
import { nextTick, watch } from 'vue';
|
|
2
|
+
import { createRouter, createWebHistory, createWebHashHistory, createMemoryHistory } from 'vue-router';
|
|
3
|
+
import Str from '@radiantabyss/support/src/Str.js';
|
|
4
|
+
import Actions from './Actions.js';
|
|
5
|
+
import Middleware from './Middleware.js';
|
|
6
|
+
import RouteFiles from './RouteFiles.js';
|
|
7
|
+
import Route from './Route.js';
|
|
8
|
+
import RouteCrud from './RouteCrud.js';
|
|
9
|
+
|
|
10
|
+
window.RouteFiles = RouteFiles;
|
|
11
|
+
window.Route = Route;
|
|
12
|
+
window.RouteCrud = RouteCrud;
|
|
13
|
+
|
|
14
|
+
//load route files
|
|
15
|
+
let context = import.meta.glob('/app/Routes/**/*.js');
|
|
16
|
+
|
|
17
|
+
const loadModules = async () => {
|
|
18
|
+
window.Actions = await Actions();
|
|
19
|
+
const files = Object.keys(context);
|
|
20
|
+
|
|
21
|
+
for ( let i = 0; i < files.length; i++ ) {
|
|
22
|
+
let file = files[i].replace('/app/Routes/', '').replace(/\.js$/, '');
|
|
23
|
+
window.__route_file = file;
|
|
24
|
+
|
|
25
|
+
if ( !RouteFiles[__route_file] ) {
|
|
26
|
+
RouteFiles[__route_file] = [];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
await context[files[i]]();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default async (history_mode = 'web') => {
|
|
34
|
+
let runMiddleware = await Middleware();
|
|
35
|
+
|
|
36
|
+
await loadModules();
|
|
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
|
+
|
|
49
|
+
//create router
|
|
50
|
+
const Router = createRouter({
|
|
51
|
+
history,
|
|
52
|
+
routes: [],
|
|
53
|
+
duplicateNavigationPolicy: 'reload',
|
|
54
|
+
scrollBehavior(to, from, scroll) {
|
|
55
|
+
if ( (to.meta.settings && to.meta.settings.disable_scroll)
|
|
56
|
+
|| (from.name == to.name && (!to.meta.settings || !to.meta.settings.force_scroll)) ) {
|
|
57
|
+
return scroll;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
x: 0,
|
|
62
|
+
y: 0
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
//run middleware
|
|
68
|
+
Router.beforeEach(async (to, from, next) => {
|
|
69
|
+
try {
|
|
70
|
+
await runMiddleware(to, from);
|
|
71
|
+
next();
|
|
72
|
+
}
|
|
73
|
+
catch(redirect) {
|
|
74
|
+
if ( redirect === false || to.path == redirect ) {
|
|
75
|
+
return next();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
next({path: redirect});
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
Router.afterEach((to, from) => {
|
|
83
|
+
//save previous route
|
|
84
|
+
localStorage.setItem('_previous_route', from.fullPath != '/' ? from.fullPath : '');
|
|
85
|
+
|
|
86
|
+
//change document title
|
|
87
|
+
let title = to.name.replace(/\//g, ' / ').replace(/Action$/, '');
|
|
88
|
+
if ( to.meta.settings.title ) {
|
|
89
|
+
if ( typeof to.meta.settings.title == 'function' ) {
|
|
90
|
+
nextTick(async () => {
|
|
91
|
+
let instance = to.matched[to.matched.length - 1]?.instances?.default;
|
|
92
|
+
if ( !instance ) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
watch(
|
|
97
|
+
() => ({ ...instance.$data }),
|
|
98
|
+
async () => {
|
|
99
|
+
document.title = await to.meta.settings.title.call(instance);
|
|
100
|
+
},
|
|
101
|
+
{ deep: true }
|
|
102
|
+
);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
document.title = to.meta.settings.title;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
document.title = `${title} :: ${import.meta.env.VITE_NAME}`;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
return { Router, RouteFiles };
|
|
115
|
+
};
|
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 =
|
|
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
|
+
};
|
package/src/Support/Helpers.js
CHANGED
|
@@ -1,29 +1,4 @@
|
|
|
1
1
|
let self = {
|
|
2
|
-
dmp(text) {
|
|
3
|
-
// eslint-disable-next-line
|
|
4
|
-
console.log(text);
|
|
5
|
-
},
|
|
6
|
-
|
|
7
|
-
handleEmpty(items) {
|
|
8
|
-
if ( items === false ) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if ( items === null ) {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if ( Array.isArray(items) && !items.length ) {
|
|
17
|
-
return [];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if ( !Array.isArray(items) && !Object.keys(items).length ) {
|
|
21
|
-
return {};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return true;
|
|
25
|
-
},
|
|
26
|
-
|
|
27
2
|
array_unique(arr) {
|
|
28
3
|
return [...new Set(arr)];
|
|
29
4
|
},
|