vaderjs 1.3.3-alpha-14 → 1.3.3-alpha-15
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 +1 -1
- package/runtime/vader.js +58 -59
- package/vader.js +8 -0
package/package.json
CHANGED
package/runtime/vader.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
window.params = {};
|
|
3
3
|
window.Vader = {
|
|
4
|
-
version: "1.3.
|
|
4
|
+
version: "1.3.3",
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
let errors = {
|
|
@@ -42,6 +42,12 @@ let invokes = []
|
|
|
42
42
|
let hasran = [];
|
|
43
43
|
let states = {};
|
|
44
44
|
let mounts = [];
|
|
45
|
+
/**
|
|
46
|
+
* @method strictMount
|
|
47
|
+
* @description This method allows you to call a function only when a component has been mounted
|
|
48
|
+
* @param {*} key
|
|
49
|
+
* @param {*} callback
|
|
50
|
+
*/
|
|
45
51
|
export const strictMount = (key, callback) => {
|
|
46
52
|
let interval = setInterval(() => {
|
|
47
53
|
if(mounts.find(mount => mount.key === key)
|
|
@@ -55,54 +61,11 @@ export const strictMount = (key, callback) => {
|
|
|
55
61
|
},0);
|
|
56
62
|
};
|
|
57
63
|
|
|
58
|
-
|
|
59
|
-
return event.detail.target
|
|
60
|
-
}
|
|
64
|
+
|
|
61
65
|
|
|
62
66
|
let components = {};
|
|
63
67
|
|
|
64
|
-
|
|
65
|
-
document.head.appendChild(style);
|
|
66
|
-
|
|
67
|
-
const parseStyles = async (styles, className = '') => {
|
|
68
|
-
let css = await fetch(styles).then((res) => res.text());
|
|
69
|
-
let classes = css.split("}");
|
|
70
|
-
let parsedClasses = {};
|
|
71
|
-
classes.forEach((cls) => {
|
|
72
|
-
|
|
73
|
-
let name = cls.split(".")[1];
|
|
74
|
-
let value = cls.split("{")[1]
|
|
75
|
-
let keys = value.split(";");
|
|
76
|
-
let newKeys = [];
|
|
77
|
-
keys.forEach((key) => {
|
|
78
|
-
if (key.includes(":")) {
|
|
79
|
-
let newKey = key.split(":")[0].trim();
|
|
80
|
-
let newValue = key.split(":")[1].trim();
|
|
81
|
-
newKeys.push(`${newKey}: "${newValue}"`);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
value = `{${newKeys.join(",")}}`;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
parsedClasses[name] = JSON.stringify(value);
|
|
88
|
-
});
|
|
89
|
-
return parsedClasses;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
export const stylis = {
|
|
94
|
-
/**
|
|
95
|
-
* @method create
|
|
96
|
-
* @param {*} styles
|
|
97
|
-
* @returns {Object} classes
|
|
98
|
-
* @description This method allows you to create css classes from an object
|
|
99
|
-
*/
|
|
100
|
-
create: async (/**@type {string} */ styles) => {
|
|
101
|
-
|
|
102
|
-
return await parseStyles(styles);
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
|
|
68
|
+
|
|
106
69
|
/**
|
|
107
70
|
* @method mem
|
|
108
71
|
* @param {Component} component
|
|
@@ -138,18 +101,7 @@ export const mem = (/**@type {Component}**/ component) => {
|
|
|
138
101
|
|
|
139
102
|
let functions = {};
|
|
140
103
|
|
|
141
|
-
|
|
142
|
-
let name = func.name;
|
|
143
|
-
|
|
144
|
-
window[name] = function (params) {
|
|
145
|
-
return func(params);
|
|
146
|
-
}
|
|
147
|
-
window[name] = window[name].bind(this);
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
return `${name}(${params})`;
|
|
151
|
-
|
|
152
|
-
};
|
|
104
|
+
|
|
153
105
|
|
|
154
106
|
/**
|
|
155
107
|
* Represents a component in the Vader framework.
|
|
@@ -163,15 +115,36 @@ export class Component {
|
|
|
163
115
|
this.key = null;
|
|
164
116
|
this.components = {};
|
|
165
117
|
this.mounted = false;
|
|
118
|
+
/**
|
|
119
|
+
* @private
|
|
120
|
+
*/
|
|
166
121
|
this.checkIFMounted();
|
|
167
122
|
this.currenthtml = null;
|
|
123
|
+
/**
|
|
124
|
+
* @private
|
|
125
|
+
*/
|
|
168
126
|
window.listeners = [];
|
|
127
|
+
/**
|
|
128
|
+
* @private
|
|
129
|
+
*/
|
|
169
130
|
this.functionMap = new Map();
|
|
131
|
+
/**
|
|
132
|
+
* @private
|
|
133
|
+
*/
|
|
170
134
|
this.freeMemoryFromFunctions();
|
|
135
|
+
/**
|
|
136
|
+
* @private
|
|
137
|
+
*/
|
|
171
138
|
this.memoizes = []
|
|
172
139
|
this.children = []
|
|
140
|
+
/**
|
|
141
|
+
* @property {Object} props - The component props.
|
|
142
|
+
*/
|
|
143
|
+
this.props = {}
|
|
173
144
|
}
|
|
174
|
-
|
|
145
|
+
/**
|
|
146
|
+
* @private
|
|
147
|
+
*/
|
|
175
148
|
createComponent(/**@type {Component}**/component, props, children) {
|
|
176
149
|
|
|
177
150
|
if (!component) {
|
|
@@ -191,6 +164,9 @@ export class Component {
|
|
|
191
164
|
this.children.push(comp)
|
|
192
165
|
return this.components[props.key]
|
|
193
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* @private
|
|
169
|
+
*/
|
|
194
170
|
memoize(/**@type {Component}**/component){
|
|
195
171
|
if(!component.key){
|
|
196
172
|
throw new Error('Component must have a static key')
|
|
@@ -211,6 +187,9 @@ export class Component {
|
|
|
211
187
|
|
|
212
188
|
return `<div key="${component.key}">${h}</div>`
|
|
213
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* @private
|
|
192
|
+
*/
|
|
214
193
|
parseStyle(styles){
|
|
215
194
|
let css = ''
|
|
216
195
|
Object.keys(styles).forEach((key) => {
|
|
@@ -220,6 +199,9 @@ export class Component {
|
|
|
220
199
|
})
|
|
221
200
|
return css
|
|
222
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* @private
|
|
204
|
+
*/
|
|
223
205
|
bindMount(){
|
|
224
206
|
mounts.push(this)
|
|
225
207
|
}
|
|
@@ -286,6 +268,7 @@ export class Component {
|
|
|
286
268
|
* @param {string} p - The parameter.
|
|
287
269
|
* @param {string} ref - The reference.
|
|
288
270
|
* @returns {string} - A valid inline JS function call.
|
|
271
|
+
* @private
|
|
289
272
|
*/
|
|
290
273
|
bind(funcData, d) {
|
|
291
274
|
|
|
@@ -341,6 +324,7 @@ export class Component {
|
|
|
341
324
|
* Calls a function with the specified parameters. and dispatches an event.
|
|
342
325
|
* @param {string} func - The function name.
|
|
343
326
|
* @param {...*} params - The function parameters.
|
|
327
|
+
* @private
|
|
344
328
|
*/
|
|
345
329
|
callFunction(func, isInlineJsx, ...params) {
|
|
346
330
|
if(!isInlineJsx && params[0] && params[0].detail){
|
|
@@ -358,6 +342,7 @@ export class Component {
|
|
|
358
342
|
* @param {string} params - The function parameters.
|
|
359
343
|
* @param {boolean} [isInlineJsx=false] - Indicates if the function is an inline JSX.
|
|
360
344
|
* @returns {string} - The function call.
|
|
345
|
+
* @private
|
|
361
346
|
*/
|
|
362
347
|
useFunction(func, params, isInlineJsx = false) {
|
|
363
348
|
const sanitizedFuncName = func.name.trim().replace(/\s+/g, '_');
|
|
@@ -529,6 +514,20 @@ export const useState = (initialState) => {
|
|
|
529
514
|
return [value, (newValue) => {}];
|
|
530
515
|
};
|
|
531
516
|
|
|
517
|
+
export const useRef = (initialState) => {
|
|
518
|
+
let value = initialState;
|
|
519
|
+
return {
|
|
520
|
+
/**
|
|
521
|
+
* @property {Bind} bind - Bind the current ref key to the element
|
|
522
|
+
*/
|
|
523
|
+
bind: key,
|
|
524
|
+
/**
|
|
525
|
+
* @property {Function} current - Get the current ref value - or the element with the ref key
|
|
526
|
+
*/
|
|
527
|
+
current: () => document.querySelector(`[ref="${key}"]`) || value,
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
532
531
|
const constants = {};
|
|
533
532
|
let constantCounter = 0;
|
|
534
533
|
|
package/vader.js
CHANGED
|
@@ -725,6 +725,14 @@ Vader.js v1.3.3
|
|
|
725
725
|
}
|
|
726
726
|
},
|
|
727
727
|
);
|
|
728
|
+
const watcher2 = watch( process.cwd() + '/src', { recursive: true }, (event, filename) => {
|
|
729
|
+
if (event == 'change'
|
|
730
|
+
&& !globalThis.isBuilding
|
|
731
|
+
) {
|
|
732
|
+
Build()
|
|
733
|
+
}
|
|
734
|
+
});
|
|
735
|
+
watcher2.on('error', (err) => console.log(err))
|
|
728
736
|
watcher.on('error', (err) => console.log(err))
|
|
729
737
|
|
|
730
738
|
break;
|