vaderjs 1.3.3-alpha-18 → 1.3.3-alpha-19
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/index.html +1 -1
- package/runtime/router.js +3 -0
- package/runtime/vader.js +6 -18
- package/vader.js +70 -63
package/package.json
CHANGED
package/runtime/index.html
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>Vaderjs v1.3.3</title>
|
|
7
7
|
<meta name="description" content="Vader.js is a modern web framework for building web applications.">
|
|
8
|
-
<link rel="shortcut icon" href="https://raw.githubusercontent.com/Postr-Inc/Vader.js/
|
|
8
|
+
<link rel="shortcut icon" href="https://raw.githubusercontent.com/Postr-Inc/Vader.js/main/logo.png" type="image/x-icon">
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
|
11
11
|
<div id="root"></div>
|
package/runtime/router.js
CHANGED
package/runtime/vader.js
CHANGED
|
@@ -180,20 +180,7 @@ export class Component {
|
|
|
180
180
|
throw new Error('new components must have a key')
|
|
181
181
|
}
|
|
182
182
|
let comp = new component();
|
|
183
|
-
|
|
184
|
-
// some props are this.bind inside of "" so we need to handle that
|
|
185
|
-
let newFunc = props[key].match(/this.bind\((.*)\)/gs);
|
|
186
|
-
if (newFunc) {
|
|
187
|
-
newFunc = newFunc[0].replace(/this.bind\((.*)\)/gs, "$1");
|
|
188
|
-
newFunc = newFunc.split('`')[1]
|
|
189
|
-
props[key] = this.bind(newFunc, { jsx: true, params: props[key], ref: props.ref });
|
|
190
|
-
return
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
props[key] = props[key].toString().replace('"', '').replace("'", '').replace('${', '').replace('}', '')
|
|
196
|
-
});
|
|
183
|
+
|
|
197
184
|
comp['props'] = props;
|
|
198
185
|
comp.children = children;
|
|
199
186
|
comp.props.children = children.join('')
|
|
@@ -299,8 +286,9 @@ export class Component {
|
|
|
299
286
|
* @param {string} ref - The reference.
|
|
300
287
|
* @returns {string} - A valid inline JS function call.
|
|
301
288
|
*/
|
|
302
|
-
bind(funcData,
|
|
289
|
+
bind(funcData,jsx,ref, params) {
|
|
303
290
|
|
|
291
|
+
console.log(jsx)
|
|
304
292
|
const name = `func_${crypto ? crypto.getRandomValues(new Uint32Array(1))[0] : Math.random()}`;
|
|
305
293
|
|
|
306
294
|
var dynamicFunction = (params) => {
|
|
@@ -335,15 +323,15 @@ export class Component {
|
|
|
335
323
|
};
|
|
336
324
|
|
|
337
325
|
// Return a valid inline js function call
|
|
338
|
-
return
|
|
326
|
+
return jsx ? dynamicFunction : `
|
|
339
327
|
((event) => {
|
|
340
|
-
event.target.setAttribute('data-ref', '${
|
|
328
|
+
event.target.setAttribute('data-ref', '${ref}}');
|
|
341
329
|
let reference = event.target.getAttribute('data-ref');
|
|
342
330
|
event.target.eventData = event;
|
|
343
331
|
let domquery = queryRef(reference);
|
|
344
332
|
domquery.eventData = event;
|
|
345
333
|
domquery.eventData.detail.target = domquery;
|
|
346
|
-
call('${name}', {event:domquery.eventData}, '${
|
|
334
|
+
call('${name}', {event:domquery.eventData}, '${params}')
|
|
347
335
|
})(event)
|
|
348
336
|
`;
|
|
349
337
|
}
|
package/vader.js
CHANGED
|
@@ -25,18 +25,17 @@ function Compiler(func) {
|
|
|
25
25
|
let savedfuncnames = [];
|
|
26
26
|
let functions = string
|
|
27
27
|
.match(
|
|
28
|
-
/(?:const|let
|
|
28
|
+
/(?:const|let)\s*([a-zA-Z0-9_-]+)\s*=\s*function\s*\(([^)]*)\)|function\s*([a-zA-Z0-9_-]+)\s*\(([^)]*)\)/gs
|
|
29
29
|
)
|
|
30
30
|
?.map((match) => match.trim());
|
|
31
31
|
|
|
32
|
-
|
|
33
32
|
let functionNames = [];
|
|
34
33
|
|
|
35
34
|
if (functions) {
|
|
36
35
|
functions.forEach((func) => {
|
|
37
36
|
if (
|
|
38
37
|
!func.match(
|
|
39
|
-
/(?:const|let
|
|
38
|
+
/(?:const|let)\s*([a-zA-Z0-9_-]+)\s*=\s*function\s*\(([^)]*)\)|function\s*([a-zA-Z0-9_-]+)\s*\(([^)]*)\)/gs
|
|
40
39
|
)
|
|
41
40
|
) {
|
|
42
41
|
return;
|
|
@@ -73,6 +72,7 @@ function Compiler(func) {
|
|
|
73
72
|
let childs = [];
|
|
74
73
|
|
|
75
74
|
|
|
75
|
+
|
|
76
76
|
function extractAttributes(code) {
|
|
77
77
|
// Match elements with opening tags
|
|
78
78
|
const elementRegex = /<([a-zA-Z0-9_-]+)([^>]*)>/gs;
|
|
@@ -134,12 +134,11 @@ function Compiler(func) {
|
|
|
134
134
|
if (functionNames.length > 0) {
|
|
135
135
|
functionNames.forEach((name) => {
|
|
136
136
|
string.split("\n").forEach((line) => {
|
|
137
|
-
if (line.includes(name) && line.includes("function")
|
|
137
|
+
if (line.includes(name) && line.includes("function")) {
|
|
138
138
|
line = line.trim();
|
|
139
139
|
line = line.replace(/\s+/g, " ");
|
|
140
140
|
|
|
141
|
-
let ps =
|
|
142
|
-
|
|
141
|
+
let ps = line.split("(").slice(1).join("(").split(")")[0].trim();
|
|
143
142
|
|
|
144
143
|
// remove comments
|
|
145
144
|
ps = ps.match(/\/\*.*\*\//gs)
|
|
@@ -160,7 +159,6 @@ function Compiler(func) {
|
|
|
160
159
|
let params = hasParams
|
|
161
160
|
? line.split("(")[1].split(")")[0].trim()
|
|
162
161
|
: null;
|
|
163
|
-
|
|
164
162
|
|
|
165
163
|
if (
|
|
166
164
|
functionparams.length > 0 &&
|
|
@@ -187,9 +185,8 @@ function Compiler(func) {
|
|
|
187
185
|
} ${params || null}${isJSXComponent ? "" : ","} true ${isJSXComponent ? "" : ","
|
|
188
186
|
} '${ref}')`;
|
|
189
187
|
|
|
190
|
-
console.log(replacement)
|
|
191
188
|
newvalue = newvalue.replace(
|
|
192
|
-
|
|
189
|
+
hasParams ? `${name}(${params})` : name,
|
|
193
190
|
`this.callFunction(\${${replacement}}, ${isJSXComponent ? true : false
|
|
194
191
|
}, event,${params || null})`
|
|
195
192
|
);
|
|
@@ -224,8 +221,10 @@ function Compiler(func) {
|
|
|
224
221
|
|
|
225
222
|
newvalue = newvalue.split('\n').map(line => line.trim() ? line.trim() + ';' : line).join('\n');
|
|
226
223
|
|
|
227
|
-
|
|
228
|
-
|
|
224
|
+
|
|
225
|
+
let newatribute = `${attributeName}="\${this.bind(\`${newvalue}\`, ${isJSXComponent ? true : false}, '${ref}', ${params || null})}"`
|
|
226
|
+
|
|
227
|
+
|
|
229
228
|
attribute[attributeName] = {
|
|
230
229
|
old: old,
|
|
231
230
|
new: newatribute,
|
|
@@ -259,9 +258,7 @@ function Compiler(func) {
|
|
|
259
258
|
otherdata["ref"] = ref;
|
|
260
259
|
// since js is all in one line split it
|
|
261
260
|
newvalue = newvalue.split('\n').map(line => line.trim() ? line.trim() + ';' : line).join('\n');
|
|
262
|
-
|
|
263
|
-
let newattribute = `${attributeName}="\${this.bind(\`${newvalue}\` ${isJSXComponent ? "" : ","}${JSON.stringify(otherdata)} )}"`;
|
|
264
|
-
console.log(newattribute)
|
|
261
|
+
let newattribute = `${attributeName}="\${this.bind(\`${newvalue}\`, ${isJSXComponent ? true : false}, '${ref}', ${params || null})}"`
|
|
265
262
|
newattribute = newattribute.replace(/\s+/g, " ")
|
|
266
263
|
string = string.replace(old, newattribute);
|
|
267
264
|
}
|
|
@@ -330,18 +327,19 @@ function Compiler(func) {
|
|
|
330
327
|
value == "undefined" ? (value = '"') : (value = value);
|
|
331
328
|
key == 'style' ? value = `{this.parseStyle({${value.split('{{')[1].split('}}')[0]}})}` : null
|
|
332
329
|
|
|
333
|
-
|
|
334
|
-
|
|
330
|
+
|
|
331
|
+
value = `="\$${value}",`;
|
|
332
|
+
string = string.replaceAll(oldvalue, value);
|
|
335
333
|
|
|
336
334
|
} else if (value && value.includes("`")) {
|
|
337
335
|
value = value.replace("=", "");
|
|
338
336
|
|
|
339
|
-
value = `"\$${value}"
|
|
337
|
+
value = `"\$${value}",`;
|
|
340
338
|
string = string.replace(oldvalue, value);
|
|
341
339
|
|
|
342
340
|
}
|
|
343
341
|
} else if (value && value.new) {
|
|
344
|
-
let newvalue = value.new;
|
|
342
|
+
let newvalue = value.new + ",";
|
|
345
343
|
let old = value.old;
|
|
346
344
|
string = string.replace(old, newvalue);
|
|
347
345
|
}
|
|
@@ -477,8 +475,6 @@ function Compiler(func) {
|
|
|
477
475
|
return array;
|
|
478
476
|
};
|
|
479
477
|
|
|
480
|
-
string = string.replaceAll('vaderjs/client', './vader.js')
|
|
481
|
-
|
|
482
478
|
// capture <Component />, <Component></Component>, and <Component>content</Component>
|
|
483
479
|
|
|
484
480
|
// Example usage
|
|
@@ -498,29 +494,9 @@ function Compiler(func) {
|
|
|
498
494
|
let myChildrens = [];
|
|
499
495
|
|
|
500
496
|
let name = component.split("<")[1].split(">")[0].split(" ")[0].replace("/", "");
|
|
501
|
-
let props = component.split(`<${name}`)[1].split(">")[0].trim()
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
let props = {};
|
|
505
|
-
if (attributes) {
|
|
506
|
-
let propsMatch;
|
|
507
|
-
let regex = /([a-zA-Z0-9_-]+)(\s*=\s*("([^"\\]*(\\.[^"\\]*)*)"|'([^'\\]*(\\.[^'\\]*)*)'|\{(?:[^{}]|(?:\{(?:[^{}]|(?:\{[^{}]*\})*)*\})*)*\}|(?:\([^)]*\)|\{[^}]*\}|()=>\s*(?:\{[^}]*\})?)|\[[^\]]*\]))?/gs
|
|
508
|
-
while ((propsMatch = regex.exec(attributes)) !== null) {
|
|
509
|
-
let [, attributeName, attributeValue] = propsMatch;
|
|
510
|
-
console.log(attributeName, attributeValue)
|
|
511
|
-
attributeValue = attributeValue.replaceAll('="', '').replace("='", '')
|
|
512
|
-
if(attributeValue.startsWith("'")){
|
|
513
|
-
attributeValue = attributeValue.replace("'", '')
|
|
514
|
-
}
|
|
515
|
-
props[attributeName] = attributeValue || null;
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
return props;
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
|
|
497
|
+
let props = component.split(`<${name}`)[1].split(">")[0].trim()
|
|
498
|
+
console.log(props)
|
|
499
|
+
|
|
524
500
|
let savedname = name;
|
|
525
501
|
let children = props
|
|
526
502
|
? component
|
|
@@ -555,14 +531,35 @@ function Compiler(func) {
|
|
|
555
531
|
myChildrens.push(child.children);
|
|
556
532
|
}
|
|
557
533
|
});
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
props = props
|
|
539
|
+
.replaceAll("=", ":")
|
|
540
|
+
.replaceAll('"', "'")
|
|
541
|
+
//fix key:'value' to key:'value', only if value ="value"
|
|
542
|
+
|
|
543
|
+
.replaceAll(",,", ',')
|
|
544
|
+
.replaceAll("className", "class")
|
|
545
|
+
.replaceAll("classname", "class")
|
|
546
|
+
.replaceAll("'${", "")
|
|
547
|
+
.replaceAll("}'", "")
|
|
548
|
+
.split("$:")
|
|
549
|
+
.join("")
|
|
550
|
+
.replace('/', '')
|
|
551
|
+
// remove trailing ,
|
|
552
|
+
.replace(/,\s*$/, "")
|
|
553
|
+
props = props.replace(/:('[^']*'|"[^"]*")/g, ':$1,');
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
|
|
558
557
|
|
|
559
|
-
props = JSON.stringify(parseProps(props));
|
|
560
|
-
|
|
561
558
|
let replace = "";
|
|
562
559
|
replace = isChild
|
|
563
|
-
? `this.memoize(this.createComponent(${savedname.replaceAll('/', '')}, ${props}
|
|
560
|
+
? `this.memoize(this.createComponent(${savedname.replaceAll('/', '')}, ${props}, [${myChildrens.length > 0 ? myChildrens.join(",") : ""
|
|
564
561
|
}])),`
|
|
565
|
-
: `\${this.memoize(this.createComponent(${savedname.replaceAll('/', '')}, ${props}
|
|
562
|
+
: `\${this.memoize(this.createComponent(${savedname.replaceAll('/', '')}, {${props}}, [${myChildrens.length > 0 ? myChildrens.join(",") : ""
|
|
566
563
|
}]))}`;
|
|
567
564
|
|
|
568
565
|
body = body.replace(before, replace);
|
|
@@ -573,6 +570,7 @@ function Compiler(func) {
|
|
|
573
570
|
|
|
574
571
|
|
|
575
572
|
|
|
573
|
+
string = string.replaceAll('vaderjs/client', './vader.js')
|
|
576
574
|
string = string.replaceAll("<>", "`").replaceAll("</>", "`");
|
|
577
575
|
string = parseComponents(string);
|
|
578
576
|
|
|
@@ -633,10 +631,8 @@ async function Build() {
|
|
|
633
631
|
|
|
634
632
|
// Read and compile file content
|
|
635
633
|
let data = await fs.readFileSync(origin, "utf8");
|
|
636
|
-
data = Compiler(data);
|
|
637
|
-
|
|
638
|
-
// Write compiled content to the 'dist/pages' directory
|
|
639
|
-
console.log(`Compiling ${fileName} to ${obj.url}`)
|
|
634
|
+
data = Compiler(data);
|
|
635
|
+
|
|
640
636
|
await writer(process.cwd() + "/dist/pages/" + fileName, data);
|
|
641
637
|
|
|
642
638
|
// Generate routing logic
|
|
@@ -666,12 +662,13 @@ async function Build() {
|
|
|
666
662
|
absolute: true,
|
|
667
663
|
});
|
|
668
664
|
scannedVaderFiles.forEach(async (file) => {
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
}
|
|
673
|
-
|
|
665
|
+
file = file.replace(/\\/g, '/');
|
|
666
|
+
|
|
667
|
+
|
|
674
668
|
let name = file.split( '/node_modules/vaderjs/runtime/')[1]
|
|
669
|
+
if(file.includes('index.html') && fs.existsSync(process.cwd() + "/dist/" + name)){
|
|
670
|
+
return
|
|
671
|
+
}
|
|
675
672
|
let data = await reader(file)
|
|
676
673
|
bundleSize += fs.statSync(file).size;
|
|
677
674
|
await writer(process.cwd() + "/dist/" + name, data);
|
|
@@ -709,12 +706,18 @@ async function Build() {
|
|
|
709
706
|
})
|
|
710
707
|
|
|
711
708
|
if (!fs.existsSync(process.cwd() + "/dist/index.html")) {
|
|
709
|
+
|
|
712
710
|
scannedFiles.forEach(async (file) => {
|
|
713
711
|
file = file.split(process.cwd() + '/runtime/')[1]
|
|
714
712
|
|
|
715
713
|
if (file === "app.js") {
|
|
716
714
|
return
|
|
717
715
|
}
|
|
716
|
+
console.log(`Compiling ${file} to /dist/${file}`)
|
|
717
|
+
if(file.includes('index.html') && fs.existsSync(process.cwd() + "/runtime/" + file)){
|
|
718
|
+
console.log(`Compiling ${file} to /dist/${file}`)
|
|
719
|
+
return
|
|
720
|
+
}
|
|
718
721
|
bundleSize += fs.statSync(process.cwd() + "/runtime/" + file).size;
|
|
719
722
|
let data = await reader(process.cwd() + "/runtime/" + file)
|
|
720
723
|
await writer(process.cwd() + "/dist/" + file, data);
|
|
@@ -747,13 +750,17 @@ Vader.js v1.3.3
|
|
|
747
750
|
}
|
|
748
751
|
},
|
|
749
752
|
);
|
|
750
|
-
const watcher2 = watch(
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
) {
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
753
|
+
const watcher2 = watch(
|
|
754
|
+
process.cwd() + '/src',
|
|
755
|
+
{ recursive: true },
|
|
756
|
+
(event, filename) => {
|
|
757
|
+
if (event == 'change'
|
|
758
|
+
&& !globalThis.isBuilding
|
|
759
|
+
) {
|
|
760
|
+
Build()
|
|
761
|
+
}
|
|
762
|
+
},
|
|
763
|
+
);
|
|
757
764
|
watcher2.on('error', (err) => console.log(err))
|
|
758
765
|
watcher.on('error', (err) => console.log(err))
|
|
759
766
|
|