divhunt 2.0.9 → 2.0.11
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/addons/core/commands/back/functions/http/server.js +10 -10
- package/addons/core/commands/front/directives/run.js +6 -0
- package/addons/core/commands/front/directives/submit.js +26 -24
- package/addons/core/servers/back/http/item/functions/start.js +9 -9
- package/addons/render/assets/back/functions/import.js +1 -1
- package/addons/render/pages/{front/js/#register → core}/addon.js +4 -0
- package/addons/render/pages/core/load.js +3 -0
- package/addons/render/pages/front/items/directives/change.js +38 -0
- package/docs/architecture.md +2 -2
- package/docs/servers.md +54 -0
- package/examples/basic-front/back/assets.js +1 -0
- package/lib/src/divhunt.js +3 -0
- package/lib/src/mixins/cookie.js +73 -0
- package/package.json +3 -1
- package/test/front/test.js +31 -8
- package/test.js +1 -1
- package/addons/render/pages/front/js/items/commands/change.js +0 -41
- package/addons/render/pages/front/js/items/shortcuts/home.js +0 -9
- package/addons/render/pages/front/js/items/shortcuts/login.js +0 -9
- /package/addons/render/pages/front/{js/events → events}/click.js +0 -0
- /package/addons/render/pages/front/{js/events → events}/load.js +0 -0
- /package/addons/render/pages/front/{js/functions → functions}/change.js +0 -0
- /package/addons/render/pages/front/{js/functions → functions}/match.js +0 -0
- /package/addons/render/pages/front/{js/functions → functions}/open.js +0 -0
- /package/addons/render/pages/front/{js/item → item}/catch/add.js +0 -0
- /package/addons/render/pages/front/{js/item → item}/catch/remove.js +0 -0
- /package/addons/render/pages/front/{js/item → item}/functions/enter.js +0 -0
- /package/addons/render/pages/front/{js/item → item}/functions/leave.js +0 -0
- /package/addons/render/pages/front/{js/item → item}/functions/render.js +0 -0
- /package/addons/render/pages/front/{css → styles}/page.css +0 -0
|
@@ -25,8 +25,8 @@ commands.Fn('http.server', async function(port = 3000, callbacks = {})
|
|
|
25
25
|
|
|
26
26
|
if(!command || !command.Get('exposed'))
|
|
27
27
|
{
|
|
28
|
-
http.
|
|
29
|
-
http.
|
|
28
|
+
http.respond.code = 404;
|
|
29
|
+
http.respond.message = 'Command not found.';
|
|
30
30
|
|
|
31
31
|
callbacks['onResponse'] && callbacks['onResponse'](http);
|
|
32
32
|
return;
|
|
@@ -47,7 +47,7 @@ commands.Fn('http.server', async function(port = 3000, callbacks = {})
|
|
|
47
47
|
{
|
|
48
48
|
http.data.streaming = 1;
|
|
49
49
|
http.prevent = true;
|
|
50
|
-
http.
|
|
50
|
+
http.response.writeHead(200, {
|
|
51
51
|
'Content-Type': type.contentType,
|
|
52
52
|
'Transfer-Encoding': 'chunked'
|
|
53
53
|
});
|
|
@@ -58,7 +58,7 @@ commands.Fn('http.server', async function(port = 3000, callbacks = {})
|
|
|
58
58
|
if(http.data.streaming)
|
|
59
59
|
{
|
|
60
60
|
http.data.streaming++;
|
|
61
|
-
http.
|
|
61
|
+
http.response.write(type.formatter(chunk.data) + '\n');
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
callbacks['onChunk'] && callbacks['onChunk'](http, chunk);
|
|
@@ -68,16 +68,16 @@ commands.Fn('http.server', async function(port = 3000, callbacks = {})
|
|
|
68
68
|
{
|
|
69
69
|
if(http.data.streaming === 1)
|
|
70
70
|
{
|
|
71
|
-
http.
|
|
71
|
+
http.response.write(type.formatter(response.data) + '\n');
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
http.
|
|
74
|
+
http.response.end();
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
http.
|
|
78
|
-
http.
|
|
79
|
-
http.
|
|
80
|
-
http.
|
|
77
|
+
http.respond.type = command.Get('type');
|
|
78
|
+
http.respond.data = response.data;
|
|
79
|
+
http.respond.message = response.message;
|
|
80
|
+
http.respond.code = response.code;
|
|
81
81
|
|
|
82
82
|
callbacks['onResponse'] && callbacks['onResponse'](http);
|
|
83
83
|
},
|
|
@@ -18,6 +18,11 @@ directives.ItemAdd({
|
|
|
18
18
|
},
|
|
19
19
|
code: function(data, item, compile, node, identifier)
|
|
20
20
|
{
|
|
21
|
+
if(node.tagName.toLowerCase() !== 'dh-command')
|
|
22
|
+
{
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
21
26
|
const config = {};
|
|
22
27
|
const methods = {};
|
|
23
28
|
|
|
@@ -74,6 +79,7 @@ directives.ItemAdd({
|
|
|
74
79
|
}
|
|
75
80
|
finally
|
|
76
81
|
{
|
|
82
|
+
|
|
77
83
|
compile.data[config.bind] = state;
|
|
78
84
|
compile.data.Update();
|
|
79
85
|
}
|
|
@@ -26,20 +26,21 @@ directives.ItemAdd({
|
|
|
26
26
|
methods.init = () =>
|
|
27
27
|
{
|
|
28
28
|
methods.config();
|
|
29
|
+
methods.state();
|
|
30
|
+
methods.element();
|
|
31
|
+
methods.handler();
|
|
32
|
+
};
|
|
29
33
|
|
|
30
|
-
|
|
34
|
+
methods.state = () =>
|
|
35
|
+
{
|
|
36
|
+
if(!compile.data[config.bind])
|
|
31
37
|
{
|
|
32
|
-
|
|
38
|
+
compile.data[config.bind] = {
|
|
39
|
+
response: null,
|
|
40
|
+
error: null,
|
|
41
|
+
loading: false
|
|
42
|
+
};
|
|
33
43
|
}
|
|
34
|
-
|
|
35
|
-
compile.data[config.bind] = {
|
|
36
|
-
response: null,
|
|
37
|
-
error: null,
|
|
38
|
-
loading: false
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
methods.element();
|
|
42
|
-
methods.handler();
|
|
43
44
|
};
|
|
44
45
|
|
|
45
46
|
methods.config = () =>
|
|
@@ -85,15 +86,17 @@ directives.ItemAdd({
|
|
|
85
86
|
|
|
86
87
|
methods.submit = async () =>
|
|
87
88
|
{
|
|
88
|
-
|
|
89
|
+
compile.data[config.bind];
|
|
89
90
|
|
|
90
|
-
if(
|
|
91
|
+
if(compile.data[config.bind].loading)
|
|
91
92
|
{
|
|
92
93
|
return;
|
|
93
94
|
}
|
|
94
95
|
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
compile.data[config.bind].loading = true;
|
|
97
|
+
compile.data[config.bind].error = null;
|
|
98
|
+
|
|
99
|
+
console.log(compile.data[config.bind]);
|
|
97
100
|
|
|
98
101
|
compile.data.Update();
|
|
99
102
|
|
|
@@ -104,24 +107,23 @@ directives.ItemAdd({
|
|
|
104
107
|
? await commands.Fn('api', config.command, formData)
|
|
105
108
|
: await commands.Fn('run', config.command, formData);
|
|
106
109
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
+
compile.data[config.bind].response = result;
|
|
111
|
+
compile.data[config.bind].error = null;
|
|
112
|
+
compile.data[config.bind].loading = false;
|
|
110
113
|
|
|
111
114
|
config.reset && config.form.reset();
|
|
112
|
-
config.onSuccess && config.onSuccess(
|
|
115
|
+
config.onSuccess && config.onSuccess(compile.data[config.bind]);
|
|
113
116
|
}
|
|
114
117
|
catch(error)
|
|
115
118
|
{
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
+
compile.data[config.bind].response = null;
|
|
120
|
+
compile.data[config.bind].error = error.message;
|
|
121
|
+
compile.data[config.bind].loading = false;
|
|
119
122
|
|
|
120
|
-
config.onError && config.onError(
|
|
123
|
+
config.onError && config.onError(compile.data[config.bind]);
|
|
121
124
|
}
|
|
122
125
|
finally
|
|
123
126
|
{
|
|
124
|
-
compile.data[config.bind] = state;
|
|
125
127
|
compile.data.Update();
|
|
126
128
|
}
|
|
127
129
|
};
|
|
@@ -27,11 +27,11 @@ serversHTTP.Fn('item.start', function(item)
|
|
|
27
27
|
user: this.methods.user(request),
|
|
28
28
|
time: performance.now(),
|
|
29
29
|
error: null,
|
|
30
|
-
|
|
30
|
+
response,
|
|
31
31
|
streaming: false,
|
|
32
32
|
types: this.methods.types,
|
|
33
33
|
prevent: false,
|
|
34
|
-
|
|
34
|
+
respond: {
|
|
35
35
|
type: 'JSON',
|
|
36
36
|
data: null,
|
|
37
37
|
message: 'Request processed',
|
|
@@ -64,7 +64,7 @@ serversHTTP.Fn('item.start', function(item)
|
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
const type = http.types[http.
|
|
67
|
+
const type = http.types[http.respond.type] || http.types.JSON;
|
|
68
68
|
|
|
69
69
|
http.time = (performance.now() - http.time).toFixed(2);
|
|
70
70
|
|
|
@@ -83,14 +83,14 @@ serversHTTP.Fn('item.start', function(item)
|
|
|
83
83
|
return;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
const content = http.
|
|
87
|
-
data: http.
|
|
88
|
-
message: http.
|
|
89
|
-
code: http.
|
|
86
|
+
const content = http.respond.type === 'JSON' ? {
|
|
87
|
+
data: http.respond.data || {},
|
|
88
|
+
message: http.respond.message || 'No response message provided.',
|
|
89
|
+
code: http.respond.code,
|
|
90
90
|
time: http.time
|
|
91
|
-
} : http.
|
|
91
|
+
} : http.respond.data || '';
|
|
92
92
|
|
|
93
|
-
response.writeHead(http.
|
|
93
|
+
response.writeHead(http.respond.code, { 'Content-Type': type.contentType });
|
|
94
94
|
response.end(type.formatter(content));
|
|
95
95
|
|
|
96
96
|
item.Get('onComplete') && item.Get('onComplete')(http);
|
|
@@ -18,7 +18,7 @@ const map =
|
|
|
18
18
|
sources: { js: 'addons/modules/sources/front' },
|
|
19
19
|
directives: { js: 'addons/render/directives/front' },
|
|
20
20
|
transforms: { js: 'addons/render/transforms/front' },
|
|
21
|
-
pages: { js: 'addons/render/pages
|
|
21
|
+
pages: { js: 'addons/render/pages', css: 'addons/render/pages/front' },
|
|
22
22
|
elements: { js: 'addons/render/elements/front', css: 'addons/render/elements/front' },
|
|
23
23
|
float: { js: 'addons/float', css: 'addons/float' }
|
|
24
24
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import divhunt from '#framework/load.js';
|
|
2
|
+
|
|
1
3
|
const pages = divhunt.Addon('pages', (addon) =>
|
|
2
4
|
{
|
|
3
5
|
addon.Field('id', ['string']);
|
|
@@ -27,3 +29,5 @@ const pages = divhunt.Addon('pages', (addon) =>
|
|
|
27
29
|
addon.Field('element', ['object']);
|
|
28
30
|
addon.Field('404', ['boolean', false]);
|
|
29
31
|
});
|
|
32
|
+
|
|
33
|
+
export default pages;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
directives.ItemAdd({
|
|
2
|
+
id: 'dh-page',
|
|
3
|
+
icon: 'file',
|
|
4
|
+
name: 'Page',
|
|
5
|
+
description: 'Navigate to a page on render',
|
|
6
|
+
category: 'navigation',
|
|
7
|
+
trigger: 'node',
|
|
8
|
+
order: 666,
|
|
9
|
+
strict: false,
|
|
10
|
+
tag: 'dh-page',
|
|
11
|
+
attributes: {
|
|
12
|
+
'route': ['string', null, true],
|
|
13
|
+
'parameters': ['object', {}],
|
|
14
|
+
'history': ['boolean', true],
|
|
15
|
+
'timeout': ['number', 0]
|
|
16
|
+
},
|
|
17
|
+
code: function(data, item, compile, node, identifier)
|
|
18
|
+
{
|
|
19
|
+
const route = data['route'].value;
|
|
20
|
+
const parameters = data['parameters'].value;
|
|
21
|
+
const push = data['history'].value;
|
|
22
|
+
const timeout = data['timeout'].value;
|
|
23
|
+
|
|
24
|
+
const change = () =>
|
|
25
|
+
{
|
|
26
|
+
pages.Fn('change', route, parameters, { path: true, push });
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
if(timeout > 0)
|
|
30
|
+
{
|
|
31
|
+
setTimeout(change, timeout);
|
|
32
|
+
}
|
|
33
|
+
else
|
|
34
|
+
{
|
|
35
|
+
change();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
package/docs/architecture.md
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
## File structure
|
|
4
4
|
|
|
5
5
|
```
|
|
6
|
-
lib/ Core Divhunt class +
|
|
6
|
+
lib/ Core Divhunt class + 17 mixins
|
|
7
7
|
load.js Entry point — creates Divhunt instance, handles signals
|
|
8
8
|
src/
|
|
9
9
|
divhunt.js Main class (mixin-composed)
|
|
10
10
|
mixins/ Addons, Emitter, Middleware, Data, DOM, Route,
|
|
11
|
-
Function, Generate, Binaries, Helper, and more
|
|
11
|
+
Function, Generate, Binaries, Helper, Cookie, and more
|
|
12
12
|
classes/
|
|
13
13
|
addon/ DivhuntAddon + mixins (fields, items, functions, find, render, store)
|
|
14
14
|
classes/
|
package/docs/servers.md
CHANGED
|
@@ -20,6 +20,60 @@ commands.Fn('http.server', 3000, {
|
|
|
20
20
|
});
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
+
## HTTP object
|
|
24
|
+
|
|
25
|
+
Every request creates an `http` object passed to `onRequest` and command callbacks (via `this.http`):
|
|
26
|
+
|
|
27
|
+
| Property | Type | Description |
|
|
28
|
+
|---|---|---|
|
|
29
|
+
| `request` | IncomingMessage | Node.js request (headers, method, url) |
|
|
30
|
+
| `response` | ServerResponse | Node.js response (writeHead, setHeader, end) |
|
|
31
|
+
| `data` | object | Parsed request data (query params + body) |
|
|
32
|
+
| `url` | URL | Parsed request URL |
|
|
33
|
+
| `user` | object | `{ ip, agent, forwarded, referrer }` |
|
|
34
|
+
| `respond` | object | `{ type, data, message, code }` — response payload |
|
|
35
|
+
| `prevent` | boolean | Set `true` to skip automatic response |
|
|
36
|
+
|
|
37
|
+
## Cookies
|
|
38
|
+
|
|
39
|
+
Built-in cookie support via `divhunt.Cookie*` methods. Works on both front (browser) and back (server) — detected via `divhunt.environment`.
|
|
40
|
+
|
|
41
|
+
### Back (server)
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
// Read from request
|
|
45
|
+
const token = divhunt.CookieGet('token', this.http.request);
|
|
46
|
+
|
|
47
|
+
// Set on response (HttpOnly + Secure by default)
|
|
48
|
+
divhunt.CookieSet('token', value, {
|
|
49
|
+
path: '/',
|
|
50
|
+
maxAge: 86400,
|
|
51
|
+
sameSite: 'Strict'
|
|
52
|
+
}, this.http.response);
|
|
53
|
+
|
|
54
|
+
// Clear
|
|
55
|
+
divhunt.CookieClear('token', { path: '/' }, this.http.response);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Front (browser)
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
divhunt.CookieSet('theme', 'dark', { path: '/', maxAge: 86400 });
|
|
62
|
+
const theme = divhunt.CookieGet('theme');
|
|
63
|
+
divhunt.CookieClear('theme');
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Options
|
|
67
|
+
|
|
68
|
+
| Option | Back default | Front default | Description |
|
|
69
|
+
|---|---|---|---|
|
|
70
|
+
| `path` | — | — | Cookie path |
|
|
71
|
+
| `maxAge` | — | — | Lifetime in seconds |
|
|
72
|
+
| `domain` | — | — | Cookie domain |
|
|
73
|
+
| `httpOnly` | `true` | N/A | JS can't read the cookie |
|
|
74
|
+
| `secure` | `true` | `false` | HTTPS only |
|
|
75
|
+
| `sameSite` | — | — | `Strict`, `Lax`, or `None` |
|
|
76
|
+
|
|
23
77
|
## gRPC server
|
|
24
78
|
|
|
25
79
|
Bidirectional streaming with automatic reconnection and binary data transport.
|
package/lib/src/divhunt.js
CHANGED
|
@@ -17,11 +17,13 @@ import DivhuntRoute from './mixins/route.js';
|
|
|
17
17
|
import DivhuntError from './mixins/error.js';
|
|
18
18
|
import DivhuntCrypto from './mixins/crypto.js';
|
|
19
19
|
import DivhuntForm from './mixins/form.js';
|
|
20
|
+
import DivhuntCookie from './mixins/cookie.js';
|
|
20
21
|
|
|
21
22
|
class Divhunt
|
|
22
23
|
{
|
|
23
24
|
constructor()
|
|
24
25
|
{
|
|
26
|
+
this.environment = typeof window !== 'undefined' ? 'front' : 'back';
|
|
25
27
|
this.emitters = {};
|
|
26
28
|
this.middleware = {};
|
|
27
29
|
|
|
@@ -84,5 +86,6 @@ Object.assign(Divhunt.prototype, DivhuntRoute);
|
|
|
84
86
|
Object.assign(Divhunt.prototype, DivhuntError);
|
|
85
87
|
Object.assign(Divhunt.prototype, DivhuntCrypto);
|
|
86
88
|
Object.assign(Divhunt.prototype, DivhuntForm);
|
|
89
|
+
Object.assign(Divhunt.prototype, DivhuntCookie);
|
|
87
90
|
|
|
88
91
|
export default Divhunt;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
const DivhuntCookie =
|
|
2
|
+
{
|
|
3
|
+
CookieGet(name, request)
|
|
4
|
+
{
|
|
5
|
+
const header = this.environment === 'front' ? document.cookie : (request?.headers?.cookie || '');
|
|
6
|
+
const match = header.match(new RegExp('(?:^|;\\s*)' + name + '=([^;]*)'));
|
|
7
|
+
|
|
8
|
+
if(!match)
|
|
9
|
+
{
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return decodeURIComponent(match[1]);
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
CookieSet(name, value, options, response)
|
|
17
|
+
{
|
|
18
|
+
const parts = [encodeURIComponent(name) + '=' + encodeURIComponent(value)];
|
|
19
|
+
|
|
20
|
+
if(options?.path)
|
|
21
|
+
{
|
|
22
|
+
parts.push('Path=' + options.path);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if(options?.maxAge)
|
|
26
|
+
{
|
|
27
|
+
parts.push('Max-Age=' + options.maxAge);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if(options?.domain)
|
|
31
|
+
{
|
|
32
|
+
parts.push('Domain=' + options.domain);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if(options?.sameSite)
|
|
36
|
+
{
|
|
37
|
+
parts.push('SameSite=' + options.sameSite);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if(this.environment === 'front')
|
|
41
|
+
{
|
|
42
|
+
if(options?.secure)
|
|
43
|
+
{
|
|
44
|
+
parts.push('Secure');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
document.cookie = parts.join('; ');
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if(options?.httpOnly !== false)
|
|
52
|
+
{
|
|
53
|
+
parts.push('HttpOnly');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if(options?.secure !== false)
|
|
57
|
+
{
|
|
58
|
+
parts.push('Secure');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const existing = response.getHeader('Set-Cookie') || [];
|
|
62
|
+
const cookies = Array.isArray(existing) ? existing : [existing];
|
|
63
|
+
cookies.push(parts.join('; '));
|
|
64
|
+
response.setHeader('Set-Cookie', cookies);
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
CookieClear(name, options, response)
|
|
68
|
+
{
|
|
69
|
+
this.CookieSet(name, '', { path: options?.path || '/', maxAge: 0 }, response);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export default DivhuntCookie;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "divhunt",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.11",
|
|
4
4
|
"description": "Full-stack isomorphic JavaScript framework built from scratch. One addon abstraction powers databases, servers, commands, pages, directives, queues, and more.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/load.js",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"./commands": "./addons/core/commands/core/load.js",
|
|
17
17
|
"./queue": "./addons/core/queue/back/load.js",
|
|
18
18
|
"./assets": "./addons/render/assets/back/load.js",
|
|
19
|
+
"./pages": "./addons/render/pages/core/load.js",
|
|
19
20
|
"./html": "./addons/render/html/load.js",
|
|
20
21
|
"./tags": "./addons/render/tags/load.js",
|
|
21
22
|
"./sources": "./addons/modules/sources/back/load.js",
|
|
@@ -31,6 +32,7 @@
|
|
|
31
32
|
"#assets/*": "./addons/render/assets/back/*",
|
|
32
33
|
"#html/*": "./addons/render/html/*",
|
|
33
34
|
"#directives/*": "./addons/render/directives/*",
|
|
35
|
+
"#pages/*": "./addons/render/pages/*",
|
|
34
36
|
"#elements/*": "./addons/render/elements/*",
|
|
35
37
|
"#tags/*": "./addons/render/tags/*",
|
|
36
38
|
"#sources/*": "./addons/modules/sources/*",
|
package/test/front/test.js
CHANGED
|
@@ -11,20 +11,43 @@ pages.Item({
|
|
|
11
11
|
content: function()
|
|
12
12
|
{
|
|
13
13
|
return `
|
|
14
|
-
|
|
14
|
+
1
|
|
15
15
|
<h1>dh-command test</h1>
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
<dh-command-submit command="test" :api="true" bind="test" :data='{"name": "dejan"}'>
|
|
17
|
+
<input name="name" placeholder="Name"/>
|
|
18
|
+
<button type="submit">Send</button>
|
|
18
19
|
<p dh-if="test.loading">Loading...</p>
|
|
19
20
|
<p dh-if="test.error">Error: {{test.error}}</p>
|
|
20
|
-
<
|
|
21
|
-
</dh-command>
|
|
21
|
+
<div dh-if="test.response">dsas<dh-page route="/2"></dh-page></div>
|
|
22
|
+
</dh-command-submit>
|
|
23
|
+
`;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
22
27
|
|
|
23
|
-
|
|
28
|
+
|
|
29
|
+
pages.Item({
|
|
30
|
+
id: 'hom2e',
|
|
31
|
+
route: '/2',
|
|
32
|
+
title: 'dh-command test',
|
|
33
|
+
grid: {
|
|
34
|
+
template: '"content"',
|
|
35
|
+
columns: '1fr',
|
|
36
|
+
rows: '1fr'
|
|
37
|
+
},
|
|
38
|
+
areas: {
|
|
39
|
+
content: function()
|
|
40
|
+
{
|
|
41
|
+
return `
|
|
42
|
+
2
|
|
43
|
+
<h1>dh-command test</h1>
|
|
44
|
+
<dh-command-submit command="test" :api="true" bind="test" :data='{"name": "dejan"}'>
|
|
45
|
+
<input name="name" placeholder="Name"/>
|
|
46
|
+
<button type="submit">Send</button>
|
|
24
47
|
<p dh-if="test.loading">Loading...</p>
|
|
25
48
|
<p dh-if="test.error">Error: {{test.error}}</p>
|
|
26
|
-
<
|
|
27
|
-
</dh-command>
|
|
49
|
+
<div dh-if="test.response">dsas<dh-page route="/"></dh-page></div>
|
|
50
|
+
</dh-command-submit>
|
|
28
51
|
`;
|
|
29
52
|
}
|
|
30
53
|
}
|
package/test.js
CHANGED
|
@@ -5,6 +5,7 @@ const root = resolve(dirname(fileURLToPath(import.meta.url)));
|
|
|
5
5
|
|
|
6
6
|
import assets from './addons/render/assets/back/load.js';
|
|
7
7
|
import commands from './addons/core/commands/core/load.js';
|
|
8
|
+
import pages from './addons/render/pages/core/load.js';
|
|
8
9
|
import html from './addons/render/html/load.js';
|
|
9
10
|
|
|
10
11
|
assets.Fn('import', ['framework', 'directives', 'commands', 'pages']);
|
|
@@ -41,7 +42,6 @@ commands.Item({
|
|
|
41
42
|
}
|
|
42
43
|
});
|
|
43
44
|
|
|
44
|
-
|
|
45
45
|
commands.Fn('expose', 'commands:run', '/api/commands/run');
|
|
46
46
|
|
|
47
47
|
await commands.Fn('http.server', 3000, {
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
divhunt.AddonReady('commands', (commands) =>
|
|
2
|
-
{
|
|
3
|
-
commands.Item({
|
|
4
|
-
id: 'pages:change',
|
|
5
|
-
method: 'POST',
|
|
6
|
-
endpoint: '/api/pages/change',
|
|
7
|
-
exposed: true,
|
|
8
|
-
description: 'Navigate to a page by ID or path',
|
|
9
|
-
in: {
|
|
10
|
-
id: ['string', null],
|
|
11
|
-
path: ['string', null],
|
|
12
|
-
parameters: ['object', {}],
|
|
13
|
-
push: ['boolean', true]
|
|
14
|
-
},
|
|
15
|
-
out: {
|
|
16
|
-
id: ['string'],
|
|
17
|
-
parameters: ['object'],
|
|
18
|
-
url: ['string']
|
|
19
|
-
},
|
|
20
|
-
callback: async function(props)
|
|
21
|
-
{
|
|
22
|
-
if(!props.id && !props.path)
|
|
23
|
-
{
|
|
24
|
-
throw new Error('Either id or path is required.');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const target = props.path || props.id;
|
|
28
|
-
const result = await pages.Fn('change', target, props.parameters || {}, {
|
|
29
|
-
path: !!props.path,
|
|
30
|
-
push: props.push !== false
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
if(result.code !== 200)
|
|
34
|
-
{
|
|
35
|
-
throw new Error(result.message);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return result.data;
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|