malinajs 0.7.2-a8 → 0.7.3
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 +161 -49
- package/package.json +3 -3
- package/plugins/sass.js +28 -10
- package/plugins/static-text.js +46 -0
- package/runtime.js +65 -7
- package/CHANGELOG.md +0 -77
package/malina.js
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
let prev = current_context;
|
|
20
20
|
try {
|
|
21
21
|
current_context = context;
|
|
22
|
-
fn();
|
|
22
|
+
return fn();
|
|
23
23
|
} finally {
|
|
24
24
|
current_context = prev;
|
|
25
25
|
}
|
|
@@ -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
|
|
|
@@ -763,8 +777,9 @@
|
|
|
763
777
|
if(prev && next) {
|
|
764
778
|
if(prev.type == 'node' && next.type == 'node') {
|
|
765
779
|
if(isTable(prev) && isTable(next) ||
|
|
766
|
-
|
|
767
|
-
|
|
780
|
+
prev.name == 'li' && next.name == 'li' ||
|
|
781
|
+
parentNode?.type == 'node' && parentNode?.name == 'select' && prev.name == 'option' && next.name == 'option' ||
|
|
782
|
+
prev.name == 'div' && next.name == 'div') {
|
|
768
783
|
body.splice(i, 1);
|
|
769
784
|
continue;
|
|
770
785
|
}
|
|
@@ -785,6 +800,10 @@
|
|
|
785
800
|
body.splice(i, 1);
|
|
786
801
|
continue;
|
|
787
802
|
}
|
|
803
|
+
if((p == 'option' || n == 'option') && (parentNode.type == 'node' && parentNode.name == 'select')) {
|
|
804
|
+
body.splice(i, 1);
|
|
805
|
+
continue;
|
|
806
|
+
}
|
|
788
807
|
if(parentNode.type == 'node' && ['div', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'h7'].includes(parentNode.name)) {
|
|
789
808
|
body.splice(i, 1);
|
|
790
809
|
continue;
|
|
@@ -836,6 +855,25 @@
|
|
|
836
855
|
go(data.body);
|
|
837
856
|
}
|
|
838
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
|
+
|
|
839
877
|
class Reader {
|
|
840
878
|
constructor(source) {
|
|
841
879
|
if(source instanceof Reader) return source;
|
|
@@ -1277,18 +1315,28 @@
|
|
|
1277
1315
|
assert(step == 0, 'Wrong expression: ' + source);
|
|
1278
1316
|
let staticText = null;
|
|
1279
1317
|
if(!parts.some(p => p.type == 'exp')) staticText = parts.map(p => p.type == 'text' ? p.value : '').join('');
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1318
|
+
|
|
1319
|
+
let pe = {
|
|
1320
|
+
parts,
|
|
1321
|
+
staticText,
|
|
1322
|
+
binding: parts.length == 1 && parts[0].type == 'exp' ? parts[0].value : null,
|
|
1323
|
+
getResult() {
|
|
1324
|
+
let result = [];
|
|
1325
|
+
this.parts.forEach(p => {
|
|
1326
|
+
if(p.type == 'js') return;
|
|
1327
|
+
if(p.type == 'exp') result.push(p);
|
|
1328
|
+
else {
|
|
1329
|
+
let l = last(result);
|
|
1330
|
+
if(l?.type == 'text') l.value += p.value;
|
|
1331
|
+
else result.push({ ...p });
|
|
1332
|
+
}
|
|
1333
|
+
});
|
|
1334
|
+
|
|
1335
|
+
return '`' + result.map(p => p.type == 'text' ? Q(p.value) : '${' + p.value + '}').join('') + '`';
|
|
1288
1336
|
}
|
|
1289
|
-
}
|
|
1290
|
-
result =
|
|
1291
|
-
return
|
|
1337
|
+
};
|
|
1338
|
+
pe.result = pe.getResult();
|
|
1339
|
+
return pe;
|
|
1292
1340
|
}
|
|
1293
1341
|
|
|
1294
1342
|
|
|
@@ -1374,7 +1422,7 @@
|
|
|
1374
1422
|
const value = raw.substring(1, raw.length - 1);
|
|
1375
1423
|
result.push({name, value, raw, content: r.sub(start)});
|
|
1376
1424
|
} else {
|
|
1377
|
-
const value = r.readIf(
|
|
1425
|
+
const value = r.readIf(/^[^\s<>]+/);
|
|
1378
1426
|
result.push({name, value, raw: value, content: r.sub(start)});
|
|
1379
1427
|
}
|
|
1380
1428
|
} else {
|
|
@@ -1852,6 +1900,34 @@
|
|
|
1852
1900
|
});
|
|
1853
1901
|
};
|
|
1854
1902
|
|
|
1903
|
+
function radioInput(node, el) {
|
|
1904
|
+
assert(node.name == 'input');
|
|
1905
|
+
const aType = node.attributes.find(a => a.name == 'type');
|
|
1906
|
+
if(!aType || aType.value != 'radio') return null;
|
|
1907
|
+
const aName = node.attributes.find(a => a.name == 'name');
|
|
1908
|
+
if(!aName.value.startsWith('{')) return null;
|
|
1909
|
+
const aValue = node.attributes.find(a => a.name == 'value');
|
|
1910
|
+
|
|
1911
|
+
aName._skip = true;
|
|
1912
|
+
aValue._skip = true;
|
|
1913
|
+
|
|
1914
|
+
const name = unwrapExp(aName.value);
|
|
1915
|
+
assert(detectExpressionType(name) == 'identifier', 'Wrong name for radio input');
|
|
1916
|
+
let value = aValue.value;
|
|
1917
|
+
if(value.match(/^\{.+\}$/)) value = unwrapExp(aValue.value);
|
|
1918
|
+
else value = '`' + value + '`';
|
|
1919
|
+
|
|
1920
|
+
this.require('apply');
|
|
1921
|
+
|
|
1922
|
+
return xNode('radioInput', {
|
|
1923
|
+
name,
|
|
1924
|
+
value,
|
|
1925
|
+
el: el.bindName()
|
|
1926
|
+
}, (ctx, n) => {
|
|
1927
|
+
ctx.write(true, `$runtime.radioButton(${n.el}, () => (${n.value}), () => (${n.name}), ($$) => {${n.name} = $$; $$apply();});`);
|
|
1928
|
+
});
|
|
1929
|
+
}
|
|
1930
|
+
|
|
1855
1931
|
function buildRuntime() {
|
|
1856
1932
|
this.module.head.push(xNode('$events', (ctx) => {
|
|
1857
1933
|
if(this.inuse.$events) ctx.write(true, 'const $events = $option.events || {};');
|
|
@@ -2147,7 +2223,8 @@
|
|
|
2147
2223
|
let bindText = xNode('bindText', {
|
|
2148
2224
|
$wait: ['apply'],
|
|
2149
2225
|
el: textNode.bindName(),
|
|
2150
|
-
exp: pe.result
|
|
2226
|
+
exp: pe.result,
|
|
2227
|
+
parsedExpression: pe
|
|
2151
2228
|
}, (ctx, n) => {
|
|
2152
2229
|
if(this.inuse.apply) {
|
|
2153
2230
|
ctx.writeLine(`$runtime.bindText(${n.el}, () => ${n.exp});`);
|
|
@@ -2275,8 +2352,15 @@
|
|
|
2275
2352
|
ctx.writeLine(`$runtime.spreadAttributes(${n.el}, () => ({${n.props.join(', ')}}));`);
|
|
2276
2353
|
}));
|
|
2277
2354
|
}
|
|
2355
|
+
|
|
2356
|
+
if(n.name == 'input') {
|
|
2357
|
+
const b = radioInput.call(this, n, el);
|
|
2358
|
+
b && binds.push(b);
|
|
2359
|
+
}
|
|
2360
|
+
|
|
2278
2361
|
let bindTail = [];
|
|
2279
2362
|
n.attributes.forEach(p => {
|
|
2363
|
+
if(p._skip) return;
|
|
2280
2364
|
let b = this.bindProp(p, n, el);
|
|
2281
2365
|
if(b) {
|
|
2282
2366
|
if(b.bind) binds.push(b.bind);
|
|
@@ -5400,7 +5484,7 @@
|
|
|
5400
5484
|
ctx.write(');');
|
|
5401
5485
|
})
|
|
5402
5486
|
};
|
|
5403
|
-
} else if(name == 'bind') {
|
|
5487
|
+
} else if(name == 'bind' && arg) {
|
|
5404
5488
|
if(this.script.readOnly) {
|
|
5405
5489
|
this.warning('script read-only conflicts with bind: ' + node.openTag);
|
|
5406
5490
|
return;
|
|
@@ -5428,18 +5512,34 @@
|
|
|
5428
5512
|
}
|
|
5429
5513
|
|
|
5430
5514
|
assert(['value', 'checked', 'valueAsNumber', 'valueAsDate', 'selectedIndex'].includes(attr), 'Not supported: ' + prop.content);
|
|
5431
|
-
assert(arg.length == 0);
|
|
5432
5515
|
assert(detectExpressionType(exp) == 'identifier', 'Wrong bind name: ' + prop.content);
|
|
5433
|
-
|
|
5516
|
+
assert(arg.length == 0);
|
|
5434
5517
|
this.detectDependency(exp);
|
|
5518
|
+
let argName = '$$a' + (this.uniqIndex++);
|
|
5435
5519
|
|
|
5436
|
-
|
|
5520
|
+
if(node.name == 'select' && attr == 'value') {
|
|
5521
|
+
return {
|
|
5522
|
+
bind: xNode('bindInput', {
|
|
5523
|
+
el: element.bindName(),
|
|
5524
|
+
exp,
|
|
5525
|
+
attr,
|
|
5526
|
+
argName
|
|
5527
|
+
}, (ctx, n) => {
|
|
5528
|
+
ctx.write(true, `$runtime.selectElement(${n.el}, () => ${n.exp}, ${n.argName} => {${n.exp} = ${n.argName}; $$apply();});`);
|
|
5529
|
+
})
|
|
5530
|
+
}
|
|
5531
|
+
}
|
|
5532
|
+
|
|
5533
|
+
if(attr == 'value' && ['number', 'range'].includes(inputType)) attr = 'valueAsNumber';
|
|
5437
5534
|
|
|
5438
5535
|
return {
|
|
5439
5536
|
bind: xNode('bindInput', {
|
|
5440
|
-
el: element.bindName()
|
|
5537
|
+
el: element.bindName(),
|
|
5538
|
+
exp,
|
|
5539
|
+
attr,
|
|
5540
|
+
argName
|
|
5441
5541
|
}, (ctx, n) => {
|
|
5442
|
-
ctx.
|
|
5542
|
+
ctx.write(true, `$runtime.bindInput(${n.el}, '${n.attr}', () => ${n.exp}, ${n.argName} => {${n.exp} = ${n.argName}; $$apply();});`);
|
|
5443
5543
|
})
|
|
5444
5544
|
};
|
|
5445
5545
|
} else if(name == 'style' && arg) {
|
|
@@ -5671,6 +5771,17 @@
|
|
|
5671
5771
|
|
|
5672
5772
|
if(node.spreading) return node.spreading.push(`${name}: ${exp}`);
|
|
5673
5773
|
|
|
5774
|
+
if(node.name == 'option' && name == 'value' && parsed.binding) {
|
|
5775
|
+
return {
|
|
5776
|
+
bind: xNode('bindOptionValue', {
|
|
5777
|
+
el: element.bindName(),
|
|
5778
|
+
value: parsed.binding
|
|
5779
|
+
}, (ctx, n) => {
|
|
5780
|
+
ctx.write(true, `$runtime.selectOption(${n.el}, () => (${n.value}));`);
|
|
5781
|
+
})
|
|
5782
|
+
}
|
|
5783
|
+
}
|
|
5784
|
+
|
|
5674
5785
|
const propList = {
|
|
5675
5786
|
hidden: true,
|
|
5676
5787
|
checked: true,
|
|
@@ -5679,6 +5790,7 @@
|
|
|
5679
5790
|
selected: true,
|
|
5680
5791
|
innerHTML: true,
|
|
5681
5792
|
innerText: true,
|
|
5793
|
+
multiple: node.name == 'select',
|
|
5682
5794
|
src: true,
|
|
5683
5795
|
readonly: 'readOnly'
|
|
5684
5796
|
};
|
|
@@ -5686,7 +5798,7 @@
|
|
|
5686
5798
|
let n = xNode('bindAttribute', {
|
|
5687
5799
|
$wait: ['apply'],
|
|
5688
5800
|
name,
|
|
5689
|
-
exp,
|
|
5801
|
+
exp: propList[name] && parsed.binding ? parsed.binding : exp,
|
|
5690
5802
|
hasElement,
|
|
5691
5803
|
el: element.bindName()
|
|
5692
5804
|
}, (ctx, data) => {
|
|
@@ -6760,7 +6872,7 @@
|
|
|
6760
6872
|
});
|
|
6761
6873
|
}
|
|
6762
6874
|
|
|
6763
|
-
const version = '0.7.2-
|
|
6875
|
+
const version = '0.7.2-a12';
|
|
6764
6876
|
|
|
6765
6877
|
|
|
6766
6878
|
async function compile(source, config = {}) {
|
|
@@ -6840,7 +6952,7 @@
|
|
|
6840
6952
|
parseHTML: function() {
|
|
6841
6953
|
this.DOM = parseHTML(this.source);
|
|
6842
6954
|
},
|
|
6843
|
-
compactDOM,
|
|
6955
|
+
compactDOM: config.compact == 'full' ? compactFull : compactDOM,
|
|
6844
6956
|
|
|
6845
6957
|
script: null,
|
|
6846
6958
|
scriptNodes: null,
|
|
@@ -6941,7 +7053,7 @@
|
|
|
6941
7053
|
async function hook(ctx, name) {
|
|
6942
7054
|
for(let i = 0; i < ctx.config.plugins.length; i++) {
|
|
6943
7055
|
const fn = ctx.config.plugins[i][name];
|
|
6944
|
-
if(fn) await fn(ctx);
|
|
7056
|
+
if(fn) await use_context(ctx, () => fn(ctx));
|
|
6945
7057
|
}
|
|
6946
7058
|
}
|
|
6947
7059
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "malinajs",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"prepare": "npm run build",
|
|
7
6
|
"build": "npm run build_runtime && rollup -c",
|
|
8
7
|
"build_runtime": "rollup -c ./rollup.config.runtime.js",
|
|
9
8
|
"build_app": "NODE_PATH=.. rollup -c rollup.config.app.js && uglifyjs ./example/public/app.js -o ./example/public/app.min.js -m -c",
|
|
@@ -39,6 +38,7 @@
|
|
|
39
38
|
"runtime.js",
|
|
40
39
|
"malina-rollup.js",
|
|
41
40
|
"malina-esbuild.js",
|
|
42
|
-
"plugins/sass.js"
|
|
41
|
+
"plugins/sass.js",
|
|
42
|
+
"plugins/static-text.js"
|
|
43
43
|
]
|
|
44
44
|
}
|
package/plugins/sass.js
CHANGED
|
@@ -8,17 +8,35 @@ module.exports = function sassPlugin() {
|
|
|
8
8
|
let type = node.attributes.filter(a => a.name == 'type' || a.name == 'lang')[0];
|
|
9
9
|
if(!type || type.value != 'sass' && type.value != 'scss') continue;
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
let sass;
|
|
12
|
+
try {
|
|
13
|
+
sass = require('sass');
|
|
14
|
+
} catch (e) {
|
|
15
|
+
if(e.code == 'MODULE_NOT_FOUND') sass = require('node-sass');
|
|
16
|
+
else throw e;
|
|
17
|
+
}
|
|
12
18
|
node.content = await (new Promise((resolve, reject) => {
|
|
13
|
-
sass.render
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
if(sass.render) {
|
|
20
|
+
sass.render({ // node-sass
|
|
21
|
+
file: ctx.config.path,
|
|
22
|
+
data: node.content,
|
|
23
|
+
indentedSyntax: type.value == 'sass'
|
|
24
|
+
}, function(e, result) {
|
|
25
|
+
if(e) return reject(e);
|
|
26
|
+
resolve(result.css.toString());
|
|
27
|
+
type.value = 'css';
|
|
28
|
+
});
|
|
29
|
+
} else {
|
|
30
|
+
sass.compileStringAsync(node.content, {
|
|
31
|
+
syntax: type.value == 'sass' ? 'indented' : 'scss',
|
|
32
|
+
url: 'file://' + ctx.config.path
|
|
33
|
+
}).then((r) => {
|
|
34
|
+
resolve(r.css);
|
|
35
|
+
}, (e) => {
|
|
36
|
+
console.error('SCSS Error', e);
|
|
37
|
+
reject(e);
|
|
38
|
+
})
|
|
39
|
+
}
|
|
22
40
|
}));
|
|
23
41
|
};
|
|
24
42
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
|
|
2
|
+
module.exports = function staticTextPlugin() {
|
|
3
|
+
/*
|
|
4
|
+
Build static text for text binding
|
|
5
|
+
Usage: {=variable}
|
|
6
|
+
*/
|
|
7
|
+
return {
|
|
8
|
+
name: 'static-text',
|
|
9
|
+
'build:before': (ctx) => {
|
|
10
|
+
const walk = (n) => {
|
|
11
|
+
if (!n) return;
|
|
12
|
+
|
|
13
|
+
// Modify AST-node
|
|
14
|
+
if (n.$type == 'bindText') {
|
|
15
|
+
let hasStatic, hasDynamic;
|
|
16
|
+
n.parsedExpression.parts.forEach(p => {
|
|
17
|
+
if(p.type == 'exp') {
|
|
18
|
+
if(p.value[0] == '=') {
|
|
19
|
+
p.value = p.value.substring(1);
|
|
20
|
+
hasStatic = true;
|
|
21
|
+
} else hasDynamic = true;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
if(hasStatic) n.exp = n.parsedExpression.getResult();
|
|
26
|
+
|
|
27
|
+
if(hasStatic && !hasDynamic) {
|
|
28
|
+
n.$handler = function (ctx, n) {
|
|
29
|
+
ctx.write(true, `${n.el}.textContent = ${n.exp};`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// traversal AST
|
|
35
|
+
if (Array.isArray(n)) n.forEach(walk);
|
|
36
|
+
else if (n.$type) {
|
|
37
|
+
for (let k in n) {
|
|
38
|
+
if (k[0] == '$') continue;
|
|
39
|
+
walk(n[k]);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
walk(ctx.module.body);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
};
|
package/runtime.js
CHANGED
|
@@ -28,10 +28,10 @@ const safeGroupCall = list => {
|
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
const safeGroupCall2 = (list, resultList) => {
|
|
31
|
+
const safeGroupCall2 = (list, resultList, onlyFunction) => {
|
|
32
32
|
list?.forEach(fn => {
|
|
33
33
|
let r = safeCall(fn);
|
|
34
|
-
r && resultList.push(r);
|
|
34
|
+
r && (!onlyFunction || isFunction(r)) && resultList.push(r);
|
|
35
35
|
});
|
|
36
36
|
};
|
|
37
37
|
|
|
@@ -895,7 +895,7 @@ function ifBlock(label, fn, parts, parentLabel) {
|
|
|
895
895
|
} else first = last = $dom;
|
|
896
896
|
if(parentLabel) label.appendChild($dom);
|
|
897
897
|
else label.parentNode.insertBefore($dom, label);
|
|
898
|
-
safeGroupCall2(mountList, destroyList);
|
|
898
|
+
safeGroupCall2(mountList, destroyList, 1);
|
|
899
899
|
}
|
|
900
900
|
|
|
901
901
|
function destroyBlock() {
|
|
@@ -969,7 +969,7 @@ function awaitBlock(label, parentLabel, relation, fn, build_main, build_then, bu
|
|
|
969
969
|
} else first = last = $dom;
|
|
970
970
|
if(parentLabel) label.appendChild($dom);
|
|
971
971
|
else label.parentNode.insertBefore($dom, label);
|
|
972
|
-
safeGroupCall2(mountList, destroyList);
|
|
972
|
+
safeGroupCall2(mountList, destroyList, 1);
|
|
973
973
|
cd_component(parentCD).$apply();
|
|
974
974
|
}
|
|
975
975
|
|
|
@@ -1026,7 +1026,7 @@ const makeEachElseBlock = (fn) => {
|
|
|
1026
1026
|
} else first = last = $dom;
|
|
1027
1027
|
cd_attach(parentCD, $cd);
|
|
1028
1028
|
parentNode.insertBefore($dom, mode ? null : label);
|
|
1029
|
-
safeGroupCall2(current_mountList, destroyList);
|
|
1029
|
+
safeGroupCall2(current_mountList, destroyList, 1);
|
|
1030
1030
|
} finally {
|
|
1031
1031
|
current_destroyList = current_mountList = current_cd = null;
|
|
1032
1032
|
}
|
|
@@ -1187,7 +1187,7 @@ function $$eachBlock(label, mode, fn, getKey, bind, buildElseBlock) {
|
|
|
1187
1187
|
} else ctx.first = ctx.last = $dom;
|
|
1188
1188
|
parentNode.insertBefore($dom, nextNode);
|
|
1189
1189
|
nextNode = ctx.first;
|
|
1190
|
-
safeGroupCall2(m, d);
|
|
1190
|
+
safeGroupCall2(m, d, 1);
|
|
1191
1191
|
if(d.length) {
|
|
1192
1192
|
ctx.d = d;
|
|
1193
1193
|
p_destroy = 1;
|
|
@@ -1285,4 +1285,62 @@ const keepAlive = (store, keyFn, builder) => {
|
|
|
1285
1285
|
}
|
|
1286
1286
|
};
|
|
1287
1287
|
|
|
1288
|
-
|
|
1288
|
+
const selectElement = (el, getter, setter) => {
|
|
1289
|
+
addEvent(el, 'change', () => {
|
|
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;
|
|
1297
|
+
});
|
|
1298
|
+
const update = () => {
|
|
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
|
+
}
|
|
1306
|
+
return;
|
|
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
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
el.selectedIndex = -1;
|
|
1317
|
+
};
|
|
1318
|
+
const w = $watch(getter, update);
|
|
1319
|
+
|
|
1320
|
+
let debounce = 0;
|
|
1321
|
+
el.$$update = () => {
|
|
1322
|
+
if(debounce) return;
|
|
1323
|
+
debounce = 1;
|
|
1324
|
+
$tick(() => {
|
|
1325
|
+
debounce = 0;
|
|
1326
|
+
update();
|
|
1327
|
+
});
|
|
1328
|
+
};
|
|
1329
|
+
};
|
|
1330
|
+
|
|
1331
|
+
const selectOption = (op, getter) => {
|
|
1332
|
+
op.$$value = getter;
|
|
1333
|
+
if(op.parentElement?.$$update) op.parentElement.$$update();
|
|
1334
|
+
else $tick(() => op.parentElement?.$$update?.());
|
|
1335
|
+
};
|
|
1336
|
+
|
|
1337
|
+
const radioButton = (el, getValue, getter, setter) => {
|
|
1338
|
+
let w = $watch(getter, (value) => {
|
|
1339
|
+
el.checked = getValue() === value;
|
|
1340
|
+
});
|
|
1341
|
+
addEvent(el, 'change', () => {
|
|
1342
|
+
if(el.checked) setter(w.value = getValue());
|
|
1343
|
+
});
|
|
1344
|
+
};
|
|
1345
|
+
|
|
1346
|
+
export { $$eachBlock, $context, $digest, $onDestroy, $onMount, $tick, $watch, WatchObject, __app_onerror, __bindActionSubscribe, addBlock, addClass, addEvent, addStyles, attachAnchor, attachBlock, attachDynComponent, autoSubscribe, awaitBlock, bindAction, bindAttribute, bindAttributeBase, bindClass, bindClassExp, bindInput, bindStyle, bindText, callComponent, callComponentDyn, callExportedFragment, cd_attach, cd_component, cd_detach, cd_new, cloneDeep, compareArray, compareDeep, configure, createTextNode, current_cd, current_component, current_destroyList, current_mountList, deepComparator, destroyResults, eachDefaultKey, exportFragment, fire, htmlBlock, htmlBlockStatic, htmlToFragment, htmlToFragmentClean, ifBlock, ifBlockReadOnly, insertAfter, insertBlock, invokeSlot, invokeSlotBase, isArray, isFunction, iterNodes, keepAlive, keyComparator, makeAnchor, makeApply, makeBlock, makeBlockBound, makeClassResolver, makeComponent, makeEachBlock, makeEachElseBlock, makeEachSingleBlock, makeEmitter, makeExternalProperty, makeRootEvent, makeSlot, mergeAllEvents, mergeEvents, mount, mountStatic, noop, prefixPush, radioButton, refer, removeElements, removeItem, selectElement, selectOption, setClassToElement, spreadAttributes, svgToFragment, unwrapProps };
|
package/CHANGELOG.md
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
## 0.7.x
|
|
3
|
-
* refactoring, optimization, fixes
|
|
4
|
-
* export function
|
|
5
|
-
* manual event delegation @click|root
|
|
6
|
-
* able to delay destroying block (for animations)
|
|
7
|
-
* be able to off autosubscribe for import: !no-autosubscribe
|
|
8
|
-
* destructuring array/object for each
|
|
9
|
-
* functions mount, mountStatic
|
|
10
|
-
* each, index variable is not included by default
|
|
11
|
-
* reference to element is removed on destroying
|
|
12
|
-
* config.useGroupReferencing
|
|
13
|
-
* action can return destroy function (not only object)
|
|
14
|
-
* each-else
|
|
15
|
-
* else-if
|
|
16
|
-
* refactoring $onMount
|
|
17
|
-
* optional deep checking for passed props: prop={value} prop|deep={value}
|
|
18
|
-
* keep-alive
|
|
19
|
-
* malina:self
|
|
20
|
-
|
|
21
|
-
## 0.6.x
|
|
22
|
-
|
|
23
|
-
* style's attribute "global"
|
|
24
|
-
* compound classes (handle mix of class and class directives)
|
|
25
|
-
* new passing class
|
|
26
|
-
* mark a class as external "$className"
|
|
27
|
-
* Deprecated: passing class from 0.5
|
|
28
|
-
* plugins
|
|
29
|
-
* esbuild-plugin (by AlexxNB)
|
|
30
|
-
* $context
|
|
31
|
-
* onError
|
|
32
|
-
* $onMount
|
|
33
|
-
* $onDestroy
|
|
34
|
-
* alias for import: malinajs -> malinajs/runtime.js
|
|
35
|
-
* alias @click -> @click={click}, @@click is forwarding
|
|
36
|
-
* local config "malina.config.js"
|
|
37
|
-
* plugin sass/scss
|
|
38
|
-
* key "auto" for each-block
|
|
39
|
-
* anchors for components
|
|
40
|
-
* style templates, e.g. style:color={color}, style:border-color="red", style:border="1px solid {color}"
|
|
41
|
-
* compile option "css"
|
|
42
|
-
* event modifier: stop, prevent
|
|
43
|
-
* script option "read-only"
|
|
44
|
-
* constant props - "export const prop;"
|
|
45
|
-
* compile option: debugLabel
|
|
46
|
-
* slot for fragment
|
|
47
|
-
* exported fragments (inverted slots)
|
|
48
|
-
* <malina:head>, <malina:body>, <malina:window>
|
|
49
|
-
* option: passClass
|
|
50
|
-
* option: immutable
|
|
51
|
-
* event modifiers: prevent, stop, ctrl, alt, shift, meta. key-events: enter, tab, esc, space, up, down, left, right, delete
|
|
52
|
-
* inline actions for text-node and elements
|
|
53
|
-
* portals: <malina:portal>
|
|
54
|
-
* autoimport
|
|
55
|
-
|
|
56
|
-
## 0.5.x
|
|
57
|
-
|
|
58
|
-
* input with type "range"/"number" - value as number
|
|
59
|
-
* improve reactive expression
|
|
60
|
-
* unwrap object in each
|
|
61
|
-
* dynamic component
|
|
62
|
-
* named slot
|
|
63
|
-
* fix for dynamic import
|
|
64
|
-
* option.onerror
|
|
65
|
-
* autosubscribe for imported objects
|
|
66
|
-
* compile time optinoption !no-check
|
|
67
|
-
* fragments
|
|
68
|
-
* event modifier: stopPropagation
|
|
69
|
-
* $props, $attributes, $restProps
|
|
70
|
-
* await-then-catch
|
|
71
|
-
* :global classes
|
|
72
|
-
* spreading props and objects {...obj}
|
|
73
|
-
* forwarding events, forward all @@
|
|
74
|
-
* onMount, onDestroy, $onDestroy
|
|
75
|
-
* shortcuts for bindings and actions
|
|
76
|
-
* scoped-css
|
|
77
|
-
* conrol directives: each, if
|