malinajs 0.7.2-a10 → 0.7.2-a12
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/malina.js +69 -31
- package/package.json +1 -1
- package/runtime.js +21 -9
package/malina.js
CHANGED
|
@@ -671,6 +671,42 @@
|
|
|
671
671
|
}
|
|
672
672
|
};
|
|
673
673
|
|
|
674
|
+
const walk = (node, fn) => {
|
|
675
|
+
switch(node.type) {
|
|
676
|
+
case 'node':
|
|
677
|
+
case 'slot':
|
|
678
|
+
case 'block':
|
|
679
|
+
case 'fragment':
|
|
680
|
+
case 'root':
|
|
681
|
+
if(node.body) fn(node.body, node);
|
|
682
|
+
break
|
|
683
|
+
case 'each':
|
|
684
|
+
if(node.mainBlock) fn(node.mainBlock, node);
|
|
685
|
+
if(node.elseBlock) fn(node.elseBlock, node);
|
|
686
|
+
break
|
|
687
|
+
case 'await':
|
|
688
|
+
if(node.parts.main) fn(node.parts.main, node);
|
|
689
|
+
if(node.parts.then) fn(node.parts.then, node);
|
|
690
|
+
if(node.parts.catch) fn(node.parts.catch, node);
|
|
691
|
+
break
|
|
692
|
+
case 'if':
|
|
693
|
+
node.parts.forEach(p => {
|
|
694
|
+
if(p.body) fn(p.body, node);
|
|
695
|
+
});
|
|
696
|
+
if(node.elsePart) fn(node.elsePart, node);
|
|
697
|
+
break
|
|
698
|
+
case 'text':
|
|
699
|
+
case 'comment':
|
|
700
|
+
case 'script':
|
|
701
|
+
case 'style':
|
|
702
|
+
case 'systag':
|
|
703
|
+
case 'template':
|
|
704
|
+
break
|
|
705
|
+
default:
|
|
706
|
+
throw `Not implemented: ${node.type}`;
|
|
707
|
+
}
|
|
708
|
+
};
|
|
709
|
+
|
|
674
710
|
function compactDOM() {
|
|
675
711
|
let data = this.DOM;
|
|
676
712
|
|
|
@@ -710,29 +746,7 @@
|
|
|
710
746
|
}
|
|
711
747
|
} else {
|
|
712
748
|
if(node.type == 'node' && (node.name == 'pre' || node.name == 'textarea')) continue;
|
|
713
|
-
|
|
714
|
-
case 'node':
|
|
715
|
-
case 'slot':
|
|
716
|
-
case 'block':
|
|
717
|
-
case 'fragment':
|
|
718
|
-
if(node.body) go(node.body, node);
|
|
719
|
-
break
|
|
720
|
-
case 'each':
|
|
721
|
-
if(node.mainBlock) go(node.mainBlock, node);
|
|
722
|
-
if(node.elseBlock) go(node.elseBlock, node);
|
|
723
|
-
break
|
|
724
|
-
case 'await':
|
|
725
|
-
if(node.parts.main) go(node.parts.main, node);
|
|
726
|
-
if(node.parts.then) go(node.parts.then, node);
|
|
727
|
-
if(node.parts.catch) go(node.parts.catch, node);
|
|
728
|
-
break
|
|
729
|
-
case 'if':
|
|
730
|
-
node.parts.forEach(p => {
|
|
731
|
-
if(p.body) go(p.body, node);
|
|
732
|
-
});
|
|
733
|
-
if(node.elsePart) go(node.elsePart, node);
|
|
734
|
-
break
|
|
735
|
-
}
|
|
749
|
+
walk(node, go);
|
|
736
750
|
}
|
|
737
751
|
}
|
|
738
752
|
|
|
@@ -841,6 +855,25 @@
|
|
|
841
855
|
go(data.body);
|
|
842
856
|
}
|
|
843
857
|
|
|
858
|
+
function compactFull() {
|
|
859
|
+
const go = (body) => {
|
|
860
|
+
let i = 0;
|
|
861
|
+
while (i < body.length) {
|
|
862
|
+
let n = body[i];
|
|
863
|
+
if(n.type == 'text') {
|
|
864
|
+
n.value = n.value.trim();
|
|
865
|
+
if(!n.value) {
|
|
866
|
+
body.splice(i, 1);
|
|
867
|
+
continue;
|
|
868
|
+
}
|
|
869
|
+
} else walk(n, go);
|
|
870
|
+
i++;
|
|
871
|
+
}
|
|
872
|
+
};
|
|
873
|
+
|
|
874
|
+
walk(this.DOM, go);
|
|
875
|
+
}
|
|
876
|
+
|
|
844
877
|
class Reader {
|
|
845
878
|
constructor(source) {
|
|
846
879
|
if(source instanceof Reader) return source;
|
|
@@ -1293,7 +1326,12 @@
|
|
|
1293
1326
|
}
|
|
1294
1327
|
});
|
|
1295
1328
|
result = '`' + result.map(p => p.type == 'text' ? Q(p.value) : '${' + p.value + '}').join('') + '`';
|
|
1296
|
-
return {
|
|
1329
|
+
return {
|
|
1330
|
+
result,
|
|
1331
|
+
parts,
|
|
1332
|
+
staticText,
|
|
1333
|
+
binding: parts.length == 1 && parts[0].type == 'exp' ? parts[0].value : null
|
|
1334
|
+
};
|
|
1297
1335
|
}
|
|
1298
1336
|
|
|
1299
1337
|
|
|
@@ -1379,7 +1417,7 @@
|
|
|
1379
1417
|
const value = raw.substring(1, raw.length - 1);
|
|
1380
1418
|
result.push({name, value, raw, content: r.sub(start)});
|
|
1381
1419
|
} else {
|
|
1382
|
-
const value = r.readIf(
|
|
1420
|
+
const value = r.readIf(/^[^\s<>]+/);
|
|
1383
1421
|
result.push({name, value, raw: value, content: r.sub(start)});
|
|
1384
1422
|
}
|
|
1385
1423
|
} else {
|
|
@@ -5727,13 +5765,13 @@
|
|
|
5727
5765
|
|
|
5728
5766
|
if(node.spreading) return node.spreading.push(`${name}: ${exp}`);
|
|
5729
5767
|
|
|
5730
|
-
if(node.name == 'option' && name == 'value') {
|
|
5768
|
+
if(node.name == 'option' && name == 'value' && parsed.binding) {
|
|
5731
5769
|
return {
|
|
5732
5770
|
bind: xNode('bindOptionValue', {
|
|
5733
5771
|
el: element.bindName(),
|
|
5734
|
-
|
|
5772
|
+
value: parsed.binding
|
|
5735
5773
|
}, (ctx, n) => {
|
|
5736
|
-
ctx.write(true, `$runtime.selectOption(${n.el}, () => (${n.
|
|
5774
|
+
ctx.write(true, `$runtime.selectOption(${n.el}, () => (${n.value}));`);
|
|
5737
5775
|
})
|
|
5738
5776
|
}
|
|
5739
5777
|
}
|
|
@@ -5754,7 +5792,7 @@
|
|
|
5754
5792
|
let n = xNode('bindAttribute', {
|
|
5755
5793
|
$wait: ['apply'],
|
|
5756
5794
|
name,
|
|
5757
|
-
exp,
|
|
5795
|
+
exp: propList[name] && parsed.binding ? parsed.binding : exp,
|
|
5758
5796
|
hasElement,
|
|
5759
5797
|
el: element.bindName()
|
|
5760
5798
|
}, (ctx, data) => {
|
|
@@ -6828,7 +6866,7 @@
|
|
|
6828
6866
|
});
|
|
6829
6867
|
}
|
|
6830
6868
|
|
|
6831
|
-
const version = '0.7.2-
|
|
6869
|
+
const version = '0.7.2-a12';
|
|
6832
6870
|
|
|
6833
6871
|
|
|
6834
6872
|
async function compile(source, config = {}) {
|
|
@@ -6908,7 +6946,7 @@
|
|
|
6908
6946
|
parseHTML: function() {
|
|
6909
6947
|
this.DOM = parseHTML(this.source);
|
|
6910
6948
|
},
|
|
6911
|
-
compactDOM,
|
|
6949
|
+
compactDOM: config.compact == 'full' ? compactFull : compactDOM,
|
|
6912
6950
|
|
|
6913
6951
|
script: null,
|
|
6914
6952
|
scriptNodes: null,
|
package/package.json
CHANGED
package/runtime.js
CHANGED
|
@@ -1287,19 +1287,31 @@ const keepAlive = (store, keyFn, builder) => {
|
|
|
1287
1287
|
|
|
1288
1288
|
const selectElement = (el, getter, setter) => {
|
|
1289
1289
|
addEvent(el, 'change', () => {
|
|
1290
|
-
let
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1290
|
+
let value = [];
|
|
1291
|
+
el.querySelectorAll(':checked').forEach(o => {
|
|
1292
|
+
value.push(o.$$value ? o.$$value() : o.value);
|
|
1293
|
+
});
|
|
1294
|
+
value = el.multiple ? value : value[0];
|
|
1295
|
+
setter(value);
|
|
1296
|
+
w.value = value;
|
|
1296
1297
|
});
|
|
1297
1298
|
const update = () => {
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1299
|
+
let value = w.value;
|
|
1300
|
+
if(el.multiple) {
|
|
1301
|
+
if(isArray(value)) {
|
|
1302
|
+
for(let o of el.options) {
|
|
1303
|
+
const option_value = o.$$value ? o.$$value() : o.value;
|
|
1304
|
+
o.selected = value.indexOf(option_value) != -1;
|
|
1305
|
+
}
|
|
1301
1306
|
return;
|
|
1302
1307
|
}
|
|
1308
|
+
} else {
|
|
1309
|
+
for(let o of el.options) {
|
|
1310
|
+
if((o.$$value ? o.$$value() : o.value) === value) {
|
|
1311
|
+
o.selected = true;
|
|
1312
|
+
return;
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1303
1315
|
}
|
|
1304
1316
|
el.selectedIndex = -1;
|
|
1305
1317
|
};
|