@onetype/framework 2.0.45 → 2.0.47

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 (32) hide show
  1. package/addons/core/assets/back/functions/import.js +3 -3
  2. package/addons/core/assets/back/items/html/css.js +2 -0
  3. package/addons/core/commands/core/addon.js +5 -0
  4. package/addons/core/commands/front/directives/run.js +1 -1
  5. package/addons/core/commands/front/directives/submit.js +1 -1
  6. package/addons/render/directives/front/items/self/100-if.js +25 -22
  7. package/addons/render/directives/front/items/self/1000-render.js +36 -33
  8. package/addons/render/directives/front/items/self/110-show.js +23 -20
  9. package/addons/render/directives/front/items/self/160-slot.js +33 -30
  10. package/addons/render/directives/front/items/self/200-for.js +71 -68
  11. package/addons/render/directives/front/items/self/2000-base.js +36 -33
  12. package/addons/render/directives/front/items/self/500-click-outside.js +37 -34
  13. package/addons/render/directives/front/items/self/500-events.js +1 -1
  14. package/addons/render/directives/front/items/self/500-mouse-enter.js +1 -1
  15. package/addons/render/directives/front/items/self/500-mouse-leave.js +1 -1
  16. package/addons/render/directives/front/items/self/650-fetch.js +150 -149
  17. package/addons/render/directives/front/items/self/660-form.js +217 -219
  18. package/addons/render/directives/front/items/self/700-text.js +42 -39
  19. package/addons/render/directives/front/items/self/750-html.js +38 -35
  20. package/addons/render/directives/front/items/self/750-node.js +1 -1
  21. package/addons/render/elements/front/items/directives/element.js +2 -2
  22. package/addons/render/pages/front/items/directives/change.js +1 -1
  23. package/addons/render/transforms/js/items/self/transform.js +1 -1
  24. package/lib/boot/load.js +105 -0
  25. package/lib/load.js +2 -1
  26. package/lib/src/classes/addon/classes/item/mixins/get.js +12 -1
  27. package/lib/src/classes/addon/classes/item/mixins/set.js +24 -2
  28. package/lib/src/classes/addon/mixins/items.js +48 -4
  29. package/lib/src/mixins/addons.js +27 -29
  30. package/lib/src/mixins/dependencies.js +24 -17
  31. package/package.json +1 -1
  32. package/lib/events.js +0 -106
@@ -1,188 +1,189 @@
1
- import directives from '#directives/addon.js';
2
-
3
- directives.ItemAdd({
4
- id: 'ot-fetch',
5
- icon: 'cloud_download',
6
- name: 'Fetch',
7
- description: 'Fetch data from URL or endpoint and bind to component data',
8
- category: 'data',
9
- trigger: 'node',
10
- order: 650,
11
- tag: 'ot-fetch',
12
- attributes: {
13
- 'get': ['string'],
14
- 'endpoint': ['string'],
15
- 'url': ['string'],
16
- 'bind': ['string'],
17
- 'params': ['string'],
18
- 'on-success': ['string'],
19
- 'on-error': ['string']
20
- },
21
- code: function(data, item, compile, node, identifier)
22
- {
23
- const config = {};
24
- const methods = {};
25
-
26
- methods.init = () =>
1
+ onetype.AddonReady('directives', function(directives)
2
+ {
3
+ directives.ItemAdd({
4
+ id: 'ot-fetch',
5
+ icon: 'cloud_download',
6
+ name: 'Fetch',
7
+ description: 'Fetch data from URL or endpoint and bind to component data',
8
+ category: 'data',
9
+ trigger: 'node',
10
+ order: 650,
11
+ tag: 'ot-fetch',
12
+ attributes: {
13
+ 'get': ['string'],
14
+ 'endpoint': ['string'],
15
+ 'url': ['string'],
16
+ 'bind': ['string'],
17
+ 'params': ['string'],
18
+ 'on-success': ['string'],
19
+ 'on-error': ['string']
20
+ },
21
+ code: function(data, item, compile, node, identifier)
27
22
  {
28
- methods.config();
23
+ const config = {};
24
+ const methods = {};
29
25
 
30
- if(methods.fetched())
26
+ methods.init = () =>
31
27
  {
32
- return;
33
- }
28
+ methods.config();
34
29
 
35
- methods.state();
36
- methods.execute();
37
- };
30
+ if(methods.fetched())
31
+ {
32
+ return;
33
+ }
38
34
 
39
- methods.config = () =>
40
- {
41
- const get = node.getAttribute('get');
42
-
43
- config.endpoint = get || node.getAttribute('endpoint') || node.getAttribute('url') || '';
44
- config.bind = node.getAttribute('bind') || 'fetch';
45
- config.onSuccess = node.getAttribute('on-success');
46
- config.onError = node.getAttribute('on-error');
47
- config.params = methods.parseParams();
48
- config.url = methods.buildUrl();
49
- config.html = node.innerHTML;
50
- };
51
-
52
- methods.parseParams = () =>
53
- {
54
- const paramsAttr = node.getAttribute('params');
35
+ methods.state();
36
+ methods.execute();
37
+ };
55
38
 
56
- if(!paramsAttr)
39
+ methods.config = () =>
57
40
  {
58
- return {};
59
- }
41
+ const get = node.getAttribute('get');
42
+
43
+ config.endpoint = get || node.getAttribute('endpoint') || node.getAttribute('url') || '';
44
+ config.bind = node.getAttribute('bind') || 'fetch';
45
+ config.onSuccess = node.getAttribute('on-success');
46
+ config.onError = node.getAttribute('on-error');
47
+ config.params = methods.parseParams();
48
+ config.url = methods.buildUrl();
49
+ config.html = node.innerHTML;
50
+ };
60
51
 
61
- try
62
- {
63
- return JSON.parse(paramsAttr);
64
- }
65
- catch(e)
52
+ methods.parseParams = () =>
66
53
  {
67
- return onetype.Function(paramsAttr, compile.data, false) || {};
68
- }
69
- };
54
+ const paramsAttr = node.getAttribute('params');
70
55
 
71
- methods.buildUrl = () =>
72
- {
73
- let url = config.endpoint;
56
+ if(!paramsAttr)
57
+ {
58
+ return {};
59
+ }
74
60
 
75
- if(!/^https?:\/\//.test(url))
76
- {
77
- url = url.startsWith('/') ? url : '/' + url;
78
- }
61
+ try
62
+ {
63
+ return JSON.parse(paramsAttr);
64
+ }
65
+ catch(e)
66
+ {
67
+ return onetype.Function(paramsAttr, compile.data, false) || {};
68
+ }
69
+ };
79
70
 
80
- if(Object.keys(config.params).length > 0)
71
+ methods.buildUrl = () =>
81
72
  {
82
- const query = Object.entries(config.params)
83
- .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
84
- .join('&');
73
+ let url = config.endpoint;
85
74
 
86
- url += (url.includes('?') ? '&' : '?') + query;
87
- }
75
+ if(!/^https?:\/\//.test(url))
76
+ {
77
+ url = url.startsWith('/') ? url : '/' + url;
78
+ }
88
79
 
89
- return url;
90
- };
80
+ if(Object.keys(config.params).length > 0)
81
+ {
82
+ const query = Object.entries(config.params)
83
+ .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
84
+ .join('&');
91
85
 
92
- methods.fetched = () =>
93
- {
94
- return compile.data[config.bind] && compile.data[config.bind].fetched;
95
- };
86
+ url += (url.includes('?') ? '&' : '?') + query;
87
+ }
96
88
 
97
- methods.state = () =>
98
- {
99
- compile.data[config.bind] = {
100
- response: null,
101
- error: null,
102
- loading: true,
103
- success: false,
104
- fetched: true
89
+ return url;
105
90
  };
106
91
 
107
- node.innerHTML = '';
108
- compile.children = false;
109
- };
92
+ methods.fetched = () =>
93
+ {
94
+ return compile.data[config.bind] && compile.data[config.bind].fetched;
95
+ };
110
96
 
111
- methods.execute = () =>
112
- {
113
- fetch(config.url)
114
- .then(methods.response)
115
- .then(methods.success)
116
- .catch(methods.error)
117
- .finally(methods.complete);
118
- };
119
-
120
- methods.response = (response) =>
121
- {
122
- if(!response.ok)
97
+ methods.state = () =>
123
98
  {
124
- throw onetype.Error(response.status, 'HTTP :status:.', {status: response.status});
125
- }
99
+ compile.data[config.bind] = {
100
+ response: null,
101
+ error: null,
102
+ loading: true,
103
+ success: false,
104
+ fetched: true
105
+ };
106
+
107
+ node.innerHTML = '';
108
+ compile.children = false;
109
+ };
126
110
 
127
- return response.json();
128
- };
111
+ methods.execute = () =>
112
+ {
113
+ fetch(config.url)
114
+ .then(methods.response)
115
+ .then(methods.success)
116
+ .catch(methods.error)
117
+ .finally(methods.complete);
118
+ };
129
119
 
130
- methods.success = (result) =>
131
- {
132
- const state = compile.data[config.bind];
120
+ methods.response = (response) =>
121
+ {
122
+ if(!response.ok)
123
+ {
124
+ throw onetype.Error(response.status, 'HTTP :status:.', {status: response.status});
125
+ }
133
126
 
134
- state.response = result.data !== undefined ? result.data : result;
135
- state.error = null;
136
- state.loading = false;
137
- state.success = true;
127
+ return response.json();
128
+ };
138
129
 
139
- if(config.onSuccess)
130
+ methods.success = (result) =>
140
131
  {
141
- const callback = onetype.Function(config.onSuccess, compile.data, false);
132
+ const state = compile.data[config.bind];
142
133
 
143
- if(typeof callback === 'function')
134
+ state.response = result.data !== undefined ? result.data : result;
135
+ state.error = null;
136
+ state.loading = false;
137
+ state.success = true;
138
+
139
+ if(config.onSuccess)
144
140
  {
145
- callback(state.response);
146
- }
147
- }
148
- };
141
+ const callback = onetype.Function(config.onSuccess, compile.data, false);
149
142
 
150
- methods.error = (err) =>
151
- {
152
- const state = compile.data[config.bind];
143
+ if(typeof callback === 'function')
144
+ {
145
+ callback(state.response);
146
+ }
147
+ }
148
+ };
153
149
 
154
- state.response = null;
155
- state.error = err.message;
156
- state.loading = false;
157
- state.success = false;
150
+ methods.error = (err) =>
151
+ {
152
+ const state = compile.data[config.bind];
158
153
 
159
- onetype.Error(500, 'Fetch error.', {bind: config.bind});
154
+ state.response = null;
155
+ state.error = err.message;
156
+ state.loading = false;
157
+ state.success = false;
160
158
 
161
- if(config.onError)
162
- {
163
- const callback = onetype.Function(config.onError, compile.data, false);
159
+ onetype.Error(500, 'Fetch error.', {bind: config.bind});
164
160
 
165
- if(typeof callback === 'function')
161
+ if(config.onError)
166
162
  {
167
- callback(err.message);
168
- }
169
- }
170
- };
163
+ const callback = onetype.Function(config.onError, compile.data, false);
171
164
 
172
- methods.complete = () =>
173
- {
174
- const compiled = item.Compile(config.html, compile.data);
175
- const fragment = document.createDocumentFragment();
165
+ if(typeof callback === 'function')
166
+ {
167
+ callback(err.message);
168
+ }
169
+ }
170
+ };
176
171
 
177
- while(compiled.element.firstChild)
172
+ methods.complete = () =>
178
173
  {
179
- fragment.appendChild(compiled.element.firstChild);
180
- }
174
+ const compiled = item.Compile(config.html, compile.data);
175
+ const fragment = document.createDocumentFragment();
176
+
177
+ while(compiled.element.firstChild)
178
+ {
179
+ fragment.appendChild(compiled.element.firstChild);
180
+ }
181
181
 
182
- node.replaceWith(fragment);
183
- compile.data.Update();
184
- };
182
+ node.replaceWith(fragment);
183
+ compile.data.Update();
184
+ };
185
185
 
186
- methods.init();
187
- }
188
- });
186
+ methods.init();
187
+ }
188
+ });
189
+ });