divhunt 2.0.9 → 2.0.10

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.
Files changed (24) hide show
  1. package/addons/core/commands/front/directives/run.js +6 -0
  2. package/addons/core/commands/front/directives/submit.js +26 -24
  3. package/addons/render/assets/back/functions/import.js +1 -1
  4. package/addons/render/pages/{front/js/#register → core}/addon.js +4 -0
  5. package/addons/render/pages/core/load.js +3 -0
  6. package/addons/render/pages/front/items/directives/change.js +38 -0
  7. package/examples/basic-front/back/assets.js +1 -0
  8. package/package.json +3 -1
  9. package/test/front/test.js +31 -8
  10. package/test.js +1 -0
  11. package/addons/render/pages/front/js/items/commands/change.js +0 -41
  12. package/addons/render/pages/front/js/items/shortcuts/home.js +0 -9
  13. package/addons/render/pages/front/js/items/shortcuts/login.js +0 -9
  14. /package/addons/render/pages/front/{js/events → events}/click.js +0 -0
  15. /package/addons/render/pages/front/{js/events → events}/load.js +0 -0
  16. /package/addons/render/pages/front/{js/functions → functions}/change.js +0 -0
  17. /package/addons/render/pages/front/{js/functions → functions}/match.js +0 -0
  18. /package/addons/render/pages/front/{js/functions → functions}/open.js +0 -0
  19. /package/addons/render/pages/front/{js/item → item}/catch/add.js +0 -0
  20. /package/addons/render/pages/front/{js/item → item}/catch/remove.js +0 -0
  21. /package/addons/render/pages/front/{js/item → item}/functions/enter.js +0 -0
  22. /package/addons/render/pages/front/{js/item → item}/functions/leave.js +0 -0
  23. /package/addons/render/pages/front/{js/item → item}/functions/render.js +0 -0
  24. /package/addons/render/pages/front/{css → styles}/page.css +0 -0
@@ -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
- if(compile.data[config.bind] !== undefined)
34
+ methods.state = () =>
35
+ {
36
+ if(!compile.data[config.bind])
31
37
  {
32
- return;
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
- const state = compile.data[config.bind];
89
+ compile.data[config.bind];
89
90
 
90
- if(state.loading)
91
+ if(compile.data[config.bind].loading)
91
92
  {
92
93
  return;
93
94
  }
94
95
 
95
- state.loading = true;
96
- state.error = null;
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
- state.response = result;
108
- state.error = null;
109
- state.loading = false;
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(state);
115
+ config.onSuccess && config.onSuccess(compile.data[config.bind]);
113
116
  }
114
117
  catch(error)
115
118
  {
116
- state.response = null;
117
- state.error = error.message;
118
- state.loading = false;
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(state);
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
  };
@@ -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/front', css: 'addons/render/pages/front' },
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,3 @@
1
+ import pages from './addon.js';
2
+
3
+ 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
+ });
@@ -1,4 +1,5 @@
1
1
  import assets from 'divhunt/assets';
2
+ import 'divhunt/pages';
2
3
 
3
4
  import { dirname, resolve } from 'path';
4
5
  import { fileURLToPath } from 'url';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "divhunt",
3
- "version": "2.0.9",
3
+ "version": "2.0.10",
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/*",
@@ -11,20 +11,43 @@ pages.Item({
11
11
  content: function()
12
12
  {
13
13
  return `
14
- {{ name }}
14
+ 1
15
15
  <h1>dh-command test</h1>
16
-
17
- <dh-command command="test" :api="true" bind="test2" :data='{"name": "dejan"}'>
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
- <p dh-if="test.response">{{test.response.message}}</p>
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
- <dh-command command="test" :api="true" bind="test" :data='{"name": "dejan"}'>
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
- <p dh-if="test.response">{{test.response.message}}</p>
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']);
@@ -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
- });
@@ -1,9 +0,0 @@
1
- divhunt.AddonReady('shortcuts', (shortcuts) =>
2
- {
3
- shortcuts.Item({
4
- id: 'pages:home',
5
- key: 'meta+1',
6
- description: 'Navigate to home page',
7
- command: { id: 'pages:change', path: '/' }
8
- });
9
- });
@@ -1,9 +0,0 @@
1
- divhunt.AddonReady('shortcuts', (shortcuts) =>
2
- {
3
- shortcuts.Item({
4
- id: 'pages:login',
5
- key: 'meta+2',
6
- description: 'Navigate to login page',
7
- command: { id: 'pages:change', path: '/login' }
8
- });
9
- });