malinajs 0.7.0-a12 → 0.7.0-a15
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/CHANGELOG.md +2 -0
- package/malina.js +55 -39
- package/package.json +3 -3
- package/runtime.js +74 -65
package/CHANGELOG.md
CHANGED
package/malina.js
CHANGED
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
function detectExpressionType(name) {
|
|
73
73
|
if(isSimpleName(name)) return 'identifier';
|
|
74
74
|
|
|
75
|
-
let ast = acorn.parse(name, { allowReturnOutsideFunction: true });
|
|
75
|
+
let ast = acorn.parse(name, { allowReturnOutsideFunction: true, ecmaVersion: 'latest' });
|
|
76
76
|
|
|
77
77
|
function checkIdentificator(body) {
|
|
78
78
|
if(body.length != 1) return;
|
|
@@ -139,7 +139,7 @@
|
|
|
139
139
|
|
|
140
140
|
|
|
141
141
|
const extractKeywords = (exp) => {
|
|
142
|
-
let ast = acorn.parse(exp, { sourceType: 'module', ecmaVersion: 12 });
|
|
142
|
+
let ast = acorn.parse(exp, { sourceType: 'module', ecmaVersion: 12, ecmaVersion: 'latest' });
|
|
143
143
|
|
|
144
144
|
const keys = new Set();
|
|
145
145
|
const rec = (n) => {
|
|
@@ -180,9 +180,9 @@
|
|
|
180
180
|
};
|
|
181
181
|
|
|
182
182
|
|
|
183
|
-
const replaceKeyword = (exp, fn) => {
|
|
183
|
+
const replaceKeyword = (exp, fn, option) => {
|
|
184
184
|
let changed = false;
|
|
185
|
-
let r = parseJS(exp).transform((n, pk) => {
|
|
185
|
+
let r = parseJS(exp, option).transform((n, pk) => {
|
|
186
186
|
if(n.type != 'Identifier') return;
|
|
187
187
|
if(pk == 'property' || pk == 'params') return;
|
|
188
188
|
let name = fn(n.name);
|
|
@@ -195,9 +195,10 @@
|
|
|
195
195
|
};
|
|
196
196
|
|
|
197
197
|
|
|
198
|
-
const parseJS = (exp) => {
|
|
198
|
+
const parseJS = (exp, option) => {
|
|
199
199
|
let self = {};
|
|
200
|
-
self.ast = acorn.
|
|
200
|
+
if(option === true) self.ast = acorn.parse(exp, { ecmaVersion: 'latest' });
|
|
201
|
+
else self.ast = acorn.parseExpressionAt(exp, 0, { ecmaVersion: 'latest' });
|
|
201
202
|
|
|
202
203
|
self.transform = function(fn) {
|
|
203
204
|
const rec = (n, pk) => {
|
|
@@ -932,6 +933,22 @@
|
|
|
932
933
|
const readScript = (tag) => {
|
|
933
934
|
let endTag = `</${tag}>`;
|
|
934
935
|
let q, a, p, start = index;
|
|
936
|
+
|
|
937
|
+
const readRegExp = () => {
|
|
938
|
+
while(true) {
|
|
939
|
+
p = a;
|
|
940
|
+
a = readNext();
|
|
941
|
+
if(q) {
|
|
942
|
+
if(a != q) continue;
|
|
943
|
+
if(p == '\\') continue;
|
|
944
|
+
q = null;
|
|
945
|
+
continue;
|
|
946
|
+
}
|
|
947
|
+
if(a == '[' && p != '\\') q = ']';
|
|
948
|
+
if(a == '/' && p != '\\') return;
|
|
949
|
+
}
|
|
950
|
+
};
|
|
951
|
+
|
|
935
952
|
while(true) {
|
|
936
953
|
p = a;
|
|
937
954
|
a = readNext();
|
|
@@ -945,6 +962,10 @@
|
|
|
945
962
|
q = a;
|
|
946
963
|
continue;
|
|
947
964
|
}
|
|
965
|
+
if(a == '/') {
|
|
966
|
+
readRegExp();
|
|
967
|
+
continue;
|
|
968
|
+
}
|
|
948
969
|
if(a == '<') {
|
|
949
970
|
if(source.substring(index - 1, index + endTag.length - 1) == endTag) {
|
|
950
971
|
let end = index - 1;
|
|
@@ -1040,7 +1061,7 @@
|
|
|
1040
1061
|
|
|
1041
1062
|
while(index < source.length) {
|
|
1042
1063
|
let a = source[index];
|
|
1043
|
-
if(a === '<' && source[index+1].match(/\S/)) {
|
|
1064
|
+
if(a === '<' && source[index + 1].match(/\S/)) {
|
|
1044
1065
|
flushText();
|
|
1045
1066
|
|
|
1046
1067
|
if(source.substring(index, index + 4) === '<!--') {
|
|
@@ -1155,7 +1176,7 @@
|
|
|
1155
1176
|
let tag = {
|
|
1156
1177
|
type: 'await',
|
|
1157
1178
|
value: bind.value,
|
|
1158
|
-
parts: {main: []}
|
|
1179
|
+
parts: { main: [] }
|
|
1159
1180
|
};
|
|
1160
1181
|
push(tag);
|
|
1161
1182
|
go(tag, n => tag.parts.main.push(n));
|
|
@@ -1315,7 +1336,7 @@
|
|
|
1315
1336
|
if(isBlockComment) return;
|
|
1316
1337
|
this.script.comments.push({ start, end, value });
|
|
1317
1338
|
};
|
|
1318
|
-
this.script.ast = acorn.parse(source, { sourceType: 'module', ecmaVersion:
|
|
1339
|
+
this.script.ast = acorn.parse(source, { sourceType: 'module', ecmaVersion: 'latest', onComment });
|
|
1319
1340
|
|
|
1320
1341
|
if(source.includes('$props')) this.require('$props');
|
|
1321
1342
|
if(source.includes('$attributes')) this.require('$attributes');
|
|
@@ -1642,8 +1663,8 @@
|
|
|
1642
1663
|
ctx.write(true, `let {${pa}, ...$attributes} = $props;`);
|
|
1643
1664
|
|
|
1644
1665
|
if(!this.script.readOnly && !n.constantProps) {
|
|
1645
|
-
ctx.write(true, `$runtime.current_component
|
|
1646
|
-
ctx.write(true, `$runtime.current_component
|
|
1666
|
+
ctx.write(true, `$runtime.current_component.$push = ($$props) => ({${n.props.map(p => p.name + '=' + p.name).join(', ')}, ...$attributes} = $props = $$props);`);
|
|
1667
|
+
ctx.write(true, `$runtime.current_component.$exportedProps = () => ({${n.props.map(p => p.name).join(', ')}});`);
|
|
1647
1668
|
}
|
|
1648
1669
|
} else if(this.inuse.$props) {
|
|
1649
1670
|
let pa = n.props.map(p => {
|
|
@@ -1653,8 +1674,8 @@
|
|
|
1653
1674
|
ctx.write(true, `let {${pa}} = $props;`);
|
|
1654
1675
|
|
|
1655
1676
|
if(!this.script.readOnly && !n.constantProps) {
|
|
1656
|
-
ctx.write(true, `$runtime.current_component
|
|
1657
|
-
ctx.write(true, `$runtime.current_component
|
|
1677
|
+
ctx.write(true, `$runtime.current_component.$push = ($$props) => ({${n.props.map(p => p.name + '=' + p.name).join(', ')}} = $props = $$props);`);
|
|
1678
|
+
ctx.write(true, `$runtime.current_component.$exportedProps = () => ({${n.props.map(p => p.name).join(', ')}});`);
|
|
1658
1679
|
}
|
|
1659
1680
|
}
|
|
1660
1681
|
}));
|
|
@@ -1664,13 +1685,13 @@
|
|
|
1664
1685
|
this.module.head.push(xNode('no-props', ctx => {
|
|
1665
1686
|
if(this.inuse.$props && this.inuse.$attributes) {
|
|
1666
1687
|
ctx.write(true, 'let $props = $option.props || {}, $attributes = $props;');
|
|
1667
|
-
if(!this.script.readOnly) ctx.write(true, '$runtime.current_component
|
|
1688
|
+
if(!this.script.readOnly) ctx.write(true, '$runtime.current_component.$push = ($$props) => $props = $attributes = $$props;');
|
|
1668
1689
|
} else if(this.inuse.$props) {
|
|
1669
1690
|
ctx.write(true, 'let $props = $option.props || {};');
|
|
1670
|
-
if(!this.script.readOnly) ctx.write(true, '$runtime.current_component
|
|
1691
|
+
if(!this.script.readOnly) ctx.write(true, '$runtime.current_component.$push = ($$props) => $props = $$props;');
|
|
1671
1692
|
} else if(this.inuse.$attributes) {
|
|
1672
1693
|
ctx.write(true, 'let $attributes = $option.props || {};');
|
|
1673
|
-
if(!this.script.readOnly) ctx.write(true, '$runtime.current_component
|
|
1694
|
+
if(!this.script.readOnly) ctx.write(true, '$runtime.current_component.$push = ($$props) => $attributes = $$props;');
|
|
1674
1695
|
}
|
|
1675
1696
|
}));
|
|
1676
1697
|
|
|
@@ -1760,22 +1781,13 @@
|
|
|
1760
1781
|
}
|
|
1761
1782
|
}));
|
|
1762
1783
|
|
|
1763
|
-
this.module.head.push(xNode('$context', {
|
|
1764
|
-
$
|
|
1765
|
-
}, (ctx) => {
|
|
1766
|
-
if(this.inuse.$context) {
|
|
1767
|
-
this.require('componentFn');
|
|
1768
|
-
ctx.write(true, 'const $context = $runtime.$context;');
|
|
1769
|
-
}
|
|
1784
|
+
this.module.head.push(xNode('$context', (ctx) => {
|
|
1785
|
+
if(this.inuse.$context) ctx.write(true, 'const $context = $option.context || {};');
|
|
1770
1786
|
}));
|
|
1771
1787
|
|
|
1772
1788
|
this.module.top.push(xNode(this.glob.$onMount, {
|
|
1773
|
-
$hold: ['componentFn']
|
|
1774
1789
|
}, (ctx, n) => {
|
|
1775
|
-
if(n.value) {
|
|
1776
|
-
this.require('componentFn');
|
|
1777
|
-
ctx.write(true, `import { $onMount } from 'malinajs/runtime.js';`);
|
|
1778
|
-
}
|
|
1790
|
+
if(n.value) ctx.write(true, `import { $onMount } from 'malinajs/runtime.js';`);
|
|
1779
1791
|
}));
|
|
1780
1792
|
|
|
1781
1793
|
this.module.top.push(xNode('$onDestroy', (ctx) => {
|
|
@@ -2026,7 +2038,7 @@
|
|
|
2026
2038
|
if(!exp.endsWith(';')) exp += ';';
|
|
2027
2039
|
binds.push(xNode('block', {
|
|
2028
2040
|
body: [
|
|
2029
|
-
replaceKeyword(exp, (name) => name == '$element' ? textNode.bindName() : null)
|
|
2041
|
+
replaceKeyword(exp, (name) => name == '$element' ? textNode.bindName() : null, true)
|
|
2030
2042
|
]
|
|
2031
2043
|
}));
|
|
2032
2044
|
});
|
|
@@ -2257,7 +2269,7 @@
|
|
|
2257
2269
|
|
|
2258
2270
|
if(node.children?.length) {
|
|
2259
2271
|
let i = node.children.length - 1;
|
|
2260
|
-
for(;i >= 0;i--) {
|
|
2272
|
+
for(;i >= 0; i--) {
|
|
2261
2273
|
let n = node.children[i];
|
|
2262
2274
|
|
|
2263
2275
|
if(mark(n)) {
|
|
@@ -2379,14 +2391,17 @@
|
|
|
2379
2391
|
}
|
|
2380
2392
|
} else {
|
|
2381
2393
|
if(n._boundName) {
|
|
2382
|
-
ctx.write(true, `let ${n._boundName} = ${base._boundName}`);
|
|
2394
|
+
if(base) ctx.write(true, `let ${n._boundName} = ${base._boundName}`);
|
|
2395
|
+
else ctx.write(true, `let ${n._boundName} = ${path.join('.')}.firstChild`);
|
|
2383
2396
|
while(shift--) ctx.write('.nextSibling');
|
|
2384
2397
|
ctx.write(';');
|
|
2385
2398
|
walk(n, [n._boundName]);
|
|
2386
2399
|
base = n;
|
|
2387
2400
|
shift = 0;
|
|
2388
2401
|
} else if(n._innerBinding) {
|
|
2389
|
-
let npath
|
|
2402
|
+
let npath;
|
|
2403
|
+
if(base) npath = [base._boundName];
|
|
2404
|
+
else npath = [...path, 'firstChild'];
|
|
2390
2405
|
while(shift--) npath.push('nextSibling');
|
|
2391
2406
|
walk(n, npath);
|
|
2392
2407
|
shift = 0;
|
|
@@ -4961,6 +4976,7 @@
|
|
|
4961
4976
|
if(Object.keys(events).length == 0) events = null;
|
|
4962
4977
|
|
|
4963
4978
|
let result = xNode('component', {
|
|
4979
|
+
$wait: ['apply'],
|
|
4964
4980
|
componentName,
|
|
4965
4981
|
staticProps,
|
|
4966
4982
|
props: propsFn,
|
|
@@ -4974,7 +4990,7 @@
|
|
|
4974
4990
|
let comma = false;
|
|
4975
4991
|
ctx.write(`$runtime.callComponent($context, ${n.componentName}, {`);
|
|
4976
4992
|
|
|
4977
|
-
if(n.props.length && n.staticProps) {
|
|
4993
|
+
if(n.props.length && (n.staticProps || !this.inuse.apply)) {
|
|
4978
4994
|
ctx.write(`props: {${n.props.join(', ')}}`);
|
|
4979
4995
|
comma = true;
|
|
4980
4996
|
n.props = [];
|
|
@@ -5045,7 +5061,7 @@
|
|
|
5045
5061
|
if(n.props.length) ctx.write(',\n', true, `() => ({${n.props.join(', ')}})`);
|
|
5046
5062
|
else other = ', null';
|
|
5047
5063
|
|
|
5048
|
-
if(
|
|
5064
|
+
if(this.inuse.apply && n.props.length) {
|
|
5049
5065
|
if(other) ctx.write(other);
|
|
5050
5066
|
other = '';
|
|
5051
5067
|
ctx.write(',');
|
|
@@ -5054,7 +5070,7 @@
|
|
|
5054
5070
|
else ctx.write('$runtime.$$compareDeep');
|
|
5055
5071
|
} else other += ', null';
|
|
5056
5072
|
|
|
5057
|
-
if(n.propsSetter.length) {
|
|
5073
|
+
if(n.propsSetter.length && this.inuse.apply) {
|
|
5058
5074
|
if(other) ctx.write(other);
|
|
5059
5075
|
other = '';
|
|
5060
5076
|
ctx.write(',\n', true, `($$_value) => ({${n.propsSetter.join(', ')}} = $$_value)`);
|
|
@@ -5118,7 +5134,7 @@
|
|
|
5118
5134
|
return {
|
|
5119
5135
|
bind: xNode('block', {
|
|
5120
5136
|
body: [
|
|
5121
|
-
replaceKeyword(exp, (name) => name == '$element' ? element.bindName() : null)
|
|
5137
|
+
replaceKeyword(exp, (name) => name == '$element' ? element.bindName() : null, true)
|
|
5122
5138
|
]
|
|
5123
5139
|
})
|
|
5124
5140
|
};
|
|
@@ -5601,7 +5617,7 @@
|
|
|
5601
5617
|
ctx.write(true, `}`);
|
|
5602
5618
|
}
|
|
5603
5619
|
ctx.write(`, [`);
|
|
5604
|
-
n.elseBlock && n.parts.push({block: n.elseBlock});
|
|
5620
|
+
n.elseBlock && n.parts.push({ block: n.elseBlock });
|
|
5605
5621
|
n.parts.forEach((p, i) => {
|
|
5606
5622
|
if(i) ctx.write(', ');
|
|
5607
5623
|
ctx.add(p.block);
|
|
@@ -6430,7 +6446,7 @@
|
|
|
6430
6446
|
exp = unwrapExp(prop.value);
|
|
6431
6447
|
exp = replaceKeyword(exp, (name) => {
|
|
6432
6448
|
if(name == '$element') return requireElement();
|
|
6433
|
-
});
|
|
6449
|
+
}, true);
|
|
6434
6450
|
} else if(!handler) handler = event;
|
|
6435
6451
|
|
|
6436
6452
|
this.detectDependency(exp || handler);
|
|
@@ -6529,7 +6545,7 @@
|
|
|
6529
6545
|
return { event, fn, rootModifier };
|
|
6530
6546
|
}
|
|
6531
6547
|
|
|
6532
|
-
const version = '0.7.0-
|
|
6548
|
+
const version = '0.7.0-a15';
|
|
6533
6549
|
|
|
6534
6550
|
|
|
6535
6551
|
async function compile(source, config = {}) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "malinajs",
|
|
3
|
-
"version": "0.7.0-
|
|
3
|
+
"version": "0.7.0-a15",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prepare": "npm run build",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"fix": "npx standardx --fix ./src/"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"acorn": "^7.
|
|
20
|
-
"astring": "^1.8.
|
|
19
|
+
"acorn": "^8.7.1",
|
|
20
|
+
"astring": "^1.8.3",
|
|
21
21
|
"css-tree": "^1.0.0-alpha.39"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
package/runtime.js
CHANGED
|
@@ -18,14 +18,22 @@ const safeCall = fn => {
|
|
|
18
18
|
|
|
19
19
|
const safeGroupCall = list => {
|
|
20
20
|
try {
|
|
21
|
-
list
|
|
21
|
+
list?.forEach(fn => fn?.());
|
|
22
22
|
} catch (e) {
|
|
23
23
|
__app_onerror(e);
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
const safeCallMount = (mountList, destroyList) => {
|
|
28
|
+
mountList.forEach(fn => {
|
|
29
|
+
let r = safeCall(fn);
|
|
30
|
+
r && destroyList.push(r);
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
let current_destroyList, current_mountList, current_cd, destroyResults;
|
|
28
35
|
const $onDestroy = fn => fn && current_destroyList.push(fn);
|
|
36
|
+
const $onMount = fn => current_mountList.push(fn);
|
|
29
37
|
|
|
30
38
|
function WatchObject(fn, cb) {
|
|
31
39
|
this.fn = fn;
|
|
@@ -340,8 +348,7 @@ function $$addEventForComponent(list, event, fn) {
|
|
|
340
348
|
}
|
|
341
349
|
|
|
342
350
|
|
|
343
|
-
let current_component
|
|
344
|
-
const $onMount = fn => current_component._m.push(fn);
|
|
351
|
+
let current_component;
|
|
345
352
|
|
|
346
353
|
|
|
347
354
|
const makeApply = () => {
|
|
@@ -363,8 +370,8 @@ const makeApply = () => {
|
|
|
363
370
|
return r;
|
|
364
371
|
};
|
|
365
372
|
|
|
366
|
-
current_component
|
|
367
|
-
current_component
|
|
373
|
+
current_component.$apply = apply;
|
|
374
|
+
current_component.$push = apply;
|
|
368
375
|
apply();
|
|
369
376
|
return apply;
|
|
370
377
|
};
|
|
@@ -372,26 +379,18 @@ const makeApply = () => {
|
|
|
372
379
|
|
|
373
380
|
const makeComponent = (init) => {
|
|
374
381
|
return ($option = {}) => {
|
|
375
|
-
$context = $option.context || {};
|
|
376
382
|
let prev_component = current_component,
|
|
377
383
|
prev_cd = current_cd,
|
|
378
|
-
$component = current_component = {
|
|
379
|
-
$option,
|
|
380
|
-
context: $context,
|
|
381
|
-
exported: {},
|
|
382
|
-
_m: []
|
|
383
|
-
};
|
|
384
|
+
$component = current_component = {$option};
|
|
384
385
|
current_cd = null;
|
|
385
386
|
|
|
386
387
|
try {
|
|
387
388
|
$component.$dom = init($option);
|
|
388
389
|
} finally {
|
|
389
390
|
current_component = prev_component;
|
|
390
|
-
$context = null;
|
|
391
391
|
current_cd = prev_cd;
|
|
392
392
|
}
|
|
393
393
|
|
|
394
|
-
$component._m.forEach(fn => $onDestroy(safeCall(fn)));
|
|
395
394
|
return $component;
|
|
396
395
|
};
|
|
397
396
|
};
|
|
@@ -402,32 +401,27 @@ const callComponent = (context, component, option = {}, propFn, cmp, setter, cla
|
|
|
402
401
|
let $component, parentWatch, parentCD = current_cd;
|
|
403
402
|
|
|
404
403
|
if(propFn) {
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
}
|
|
412
|
-
}, { value: {}, cmp });
|
|
413
|
-
fire(parentWatch);
|
|
414
|
-
} else option.props = propFn();
|
|
404
|
+
parentWatch = $watch(propFn, value => {
|
|
405
|
+
$component.$push?.(value);
|
|
406
|
+
$component.$apply?.();
|
|
407
|
+
}, { value: {}, idle: true, cmp });
|
|
408
|
+
fire(parentWatch);
|
|
409
|
+
option.props = parentWatch.value;
|
|
415
410
|
}
|
|
416
411
|
|
|
417
412
|
if(classFn) {
|
|
418
413
|
fire($watch(classFn, value => {
|
|
419
414
|
option.$class = value;
|
|
420
|
-
$component
|
|
415
|
+
$component?.$apply?.();
|
|
421
416
|
}, { value: {}, cmp: keyComparator }));
|
|
422
417
|
}
|
|
423
418
|
|
|
424
419
|
$component = safeCall(() => component(option));
|
|
425
|
-
if(
|
|
426
|
-
|
|
420
|
+
if($component instanceof Node) $component = {$dom: $component};
|
|
421
|
+
if(setter && $component?.$exportedProps) {
|
|
422
|
+
let w = new WatchObject($component.$exportedProps, value => {
|
|
427
423
|
setter(value);
|
|
428
|
-
cd_component(parentCD)
|
|
429
|
-
option.props = parentWatch.fn();
|
|
430
|
-
$component.push();
|
|
424
|
+
cd_component(parentCD).$apply();
|
|
431
425
|
});
|
|
432
426
|
Object.assign(w, { idle: true, cmp, value: parentWatch.value });
|
|
433
427
|
$component.$cd.watchers.push(w);
|
|
@@ -440,7 +434,7 @@ const callComponent = (context, component, option = {}, propFn, cmp, setter, cla
|
|
|
440
434
|
const attachDynComponent = (label, exp, bind) => {
|
|
441
435
|
let parentCD = current_cd;
|
|
442
436
|
let active, destroyList, $cd, $dom, finalLabel = getFinalLabel(label);
|
|
443
|
-
const destroy = () =>
|
|
437
|
+
const destroy = () => safeGroupCall(destroyList);
|
|
444
438
|
$onDestroy(destroy);
|
|
445
439
|
|
|
446
440
|
$watch(exp, (component) => {
|
|
@@ -450,15 +444,16 @@ const attachDynComponent = (label, exp, bind) => {
|
|
|
450
444
|
|
|
451
445
|
if(component) {
|
|
452
446
|
destroyList = current_destroyList = [];
|
|
447
|
+
current_mountList = [];
|
|
453
448
|
$cd = current_cd = cd_new();
|
|
454
449
|
try {
|
|
455
450
|
$dom = bind(component).$dom;
|
|
451
|
+
cd_attach2(parentCD, $cd);
|
|
452
|
+
insertAfter(label, $dom);
|
|
453
|
+
safeCallMount(current_mountList, destroyList);
|
|
456
454
|
} finally {
|
|
457
|
-
current_destroyList = null;
|
|
458
|
-
current_cd = null;
|
|
455
|
+
current_destroyList = current_mountList = current_cd = null;
|
|
459
456
|
}
|
|
460
|
-
cd_attach2(parentCD, $cd);
|
|
461
|
-
insertAfter(label, $dom);
|
|
462
457
|
active = true;
|
|
463
458
|
} else {
|
|
464
459
|
$cd = null;
|
|
@@ -472,7 +467,7 @@ const attachDynComponent = (label, exp, bind) => {
|
|
|
472
467
|
const autoSubscribe = (...list) => {
|
|
473
468
|
list.forEach(i => {
|
|
474
469
|
if(isFunction(i.subscribe)) {
|
|
475
|
-
let unsub = i.subscribe(current_component
|
|
470
|
+
let unsub = i.subscribe(current_component.$apply);
|
|
476
471
|
if(isFunction(unsub)) $onDestroy(unsub);
|
|
477
472
|
}
|
|
478
473
|
});
|
|
@@ -545,7 +540,7 @@ const bindAction = (element, action, fn, subscribe) => {
|
|
|
545
540
|
else {
|
|
546
541
|
$onDestroy(handler?.destroy);
|
|
547
542
|
subscribe?.(fn, handler, value);
|
|
548
|
-
handler?.init && $
|
|
543
|
+
handler?.init && $onMount(handler.init);
|
|
549
544
|
}
|
|
550
545
|
};
|
|
551
546
|
|
|
@@ -608,7 +603,7 @@ const makeExternalProperty = (name, getter, setter) => {
|
|
|
608
603
|
let $component = current_component;
|
|
609
604
|
Object.defineProperty($component, name, {
|
|
610
605
|
get: getter,
|
|
611
|
-
set: v => { setter(v); $component
|
|
606
|
+
set: v => { setter(v); $component.$apply(); }
|
|
612
607
|
});
|
|
613
608
|
};
|
|
614
609
|
|
|
@@ -679,7 +674,7 @@ const callExportedFragment = (childComponent, name, slot, events, props, cmp) =>
|
|
|
679
674
|
fire(w);
|
|
680
675
|
props = () => result;
|
|
681
676
|
}
|
|
682
|
-
let fn = childComponent
|
|
677
|
+
let fn = childComponent.$exported?.[name];
|
|
683
678
|
([$dom, push] = fn(props, events, slot));
|
|
684
679
|
return $dom;
|
|
685
680
|
};
|
|
@@ -687,11 +682,13 @@ const callExportedFragment = (childComponent, name, slot, events, props, cmp) =>
|
|
|
687
682
|
|
|
688
683
|
const exportFragment = (name, fn) => {
|
|
689
684
|
let childCD = current_cd;
|
|
690
|
-
|
|
685
|
+
let component = cd_component(childCD);
|
|
686
|
+
if(!component.$exported) component.$exported = {};
|
|
687
|
+
component.$exported[name] = (props, events, slot) => {
|
|
691
688
|
let prev = current_cd, $cd = current_cd = cd_new();
|
|
692
689
|
cd_attach2(childCD, $cd);
|
|
693
690
|
$onDestroy(() => cd_detach($cd));
|
|
694
|
-
let apply = cd_component(childCD)
|
|
691
|
+
let apply = cd_component(childCD).$apply;
|
|
695
692
|
apply();
|
|
696
693
|
try {
|
|
697
694
|
return [fn(props, events || {}, slot), apply];
|
|
@@ -796,6 +793,7 @@ const makeRootEvent = (root) => {
|
|
|
796
793
|
|
|
797
794
|
const mount = (label, component, option) => {
|
|
798
795
|
let app, first, last, destroyList = current_destroyList = [];
|
|
796
|
+
current_mountList = [];
|
|
799
797
|
try {
|
|
800
798
|
app = component(option);
|
|
801
799
|
let $dom = app.$dom;
|
|
@@ -805,8 +803,9 @@ const mount = (label, component, option) => {
|
|
|
805
803
|
last = $dom.lastChild;
|
|
806
804
|
} else first = last = $dom;
|
|
807
805
|
label.appendChild($dom);
|
|
806
|
+
safeCallMount(current_mountList, destroyList);
|
|
808
807
|
} finally {
|
|
809
|
-
current_destroyList = null;
|
|
808
|
+
current_destroyList = current_mountList = null;
|
|
810
809
|
}
|
|
811
810
|
app.destroy = () => {
|
|
812
811
|
safeGroupCall(destroyList);
|
|
@@ -817,12 +816,14 @@ const mount = (label, component, option) => {
|
|
|
817
816
|
|
|
818
817
|
const mountStatic = (label, component, option) => {
|
|
819
818
|
current_destroyList = [];
|
|
819
|
+
current_mountList = [];
|
|
820
820
|
try {
|
|
821
821
|
let app = component(option);
|
|
822
822
|
label.appendChild(app.$dom);
|
|
823
|
+
safeGroupCall(current_mountList);
|
|
823
824
|
return app;
|
|
824
825
|
} finally {
|
|
825
|
-
current_destroyList = null;
|
|
826
|
+
current_destroyList = current_mountList = null;
|
|
826
827
|
}
|
|
827
828
|
};
|
|
828
829
|
|
|
@@ -900,12 +901,12 @@ function ifBlock(label, fn, parts, parentLabel) {
|
|
|
900
901
|
function createBlock(builder) {
|
|
901
902
|
let $dom;
|
|
902
903
|
destroyList = current_destroyList = [];
|
|
904
|
+
let mountList = current_mountList = [];
|
|
903
905
|
$cd = current_cd = cd_new();
|
|
904
906
|
try {
|
|
905
907
|
$dom = builder();
|
|
906
908
|
} finally {
|
|
907
|
-
current_destroyList = null;
|
|
908
|
-
current_cd = null;
|
|
909
|
+
current_destroyList = current_mountList = current_cd = null;
|
|
909
910
|
}
|
|
910
911
|
cd_attach2(parentCD, $cd);
|
|
911
912
|
if($dom.nodeType == 11) {
|
|
@@ -914,6 +915,7 @@ function ifBlock(label, fn, parts, parentLabel) {
|
|
|
914
915
|
} else first = last = $dom;
|
|
915
916
|
if(parentLabel) label.appendChild($dom);
|
|
916
917
|
else insertAfter(label, $dom);
|
|
918
|
+
safeCallMount(mountList, destroyList);
|
|
917
919
|
}
|
|
918
920
|
|
|
919
921
|
function destroyBlock() {
|
|
@@ -970,12 +972,11 @@ function $$awaitBlock(label, relation, fn, build_main, build_then, build_catch)
|
|
|
970
972
|
if(!builder) return;
|
|
971
973
|
destroyList = current_destroyList = [];
|
|
972
974
|
$cd = current_cd = cd_new();
|
|
973
|
-
let $dom;
|
|
975
|
+
let $dom, mountList = current_mountList = [];
|
|
974
976
|
try {
|
|
975
977
|
$dom = builder(value);
|
|
976
978
|
} finally {
|
|
977
|
-
current_destroyList = null;
|
|
978
|
-
current_cd = null;
|
|
979
|
+
current_destroyList = current_mountList = current_cd = null;
|
|
979
980
|
}
|
|
980
981
|
cd_attach2(parentCD, $cd);
|
|
981
982
|
if($dom.nodeType == 11) {
|
|
@@ -983,7 +984,8 @@ function $$awaitBlock(label, relation, fn, build_main, build_then, build_catch)
|
|
|
983
984
|
last = $dom.lastChild;
|
|
984
985
|
} else first = last = $dom;
|
|
985
986
|
insertAfter(label, $dom);
|
|
986
|
-
|
|
987
|
+
safeCallMount(mountList, destroyList);
|
|
988
|
+
cd_component(parentCD).$apply();
|
|
987
989
|
}
|
|
988
990
|
|
|
989
991
|
$watch(relation, () => {
|
|
@@ -1026,6 +1028,7 @@ const makeEachElseBlock = (fn) => {
|
|
|
1026
1028
|
let first, last;
|
|
1027
1029
|
let destroyList = current_destroyList = [];
|
|
1028
1030
|
let $cd = current_cd = cd_new();
|
|
1031
|
+
current_mountList = [];
|
|
1029
1032
|
try {
|
|
1030
1033
|
let $dom = fn();
|
|
1031
1034
|
if($dom.nodeType == 11) {
|
|
@@ -1035,17 +1038,17 @@ const makeEachElseBlock = (fn) => {
|
|
|
1035
1038
|
cd_attach2(parentCD, $cd);
|
|
1036
1039
|
if(onlyChild) label.appendChild($dom);
|
|
1037
1040
|
else attachBlock(label, $dom);
|
|
1041
|
+
safeCallMount(current_mountList, destroyList);
|
|
1038
1042
|
} finally {
|
|
1039
|
-
current_destroyList = null;
|
|
1040
|
-
current_cd = null;
|
|
1043
|
+
current_destroyList = current_mountList = current_cd = null;
|
|
1041
1044
|
}
|
|
1042
1045
|
|
|
1043
1046
|
return () => {
|
|
1044
1047
|
$$removeElements(first, last);
|
|
1045
1048
|
cd_detach($cd);
|
|
1046
1049
|
safeGroupCall(destroyList);
|
|
1047
|
-
}
|
|
1048
|
-
}
|
|
1050
|
+
};
|
|
1051
|
+
};
|
|
1049
1052
|
};
|
|
1050
1053
|
|
|
1051
1054
|
|
|
@@ -1119,7 +1122,7 @@ function $$eachBlock(label, onlyChild, fn, getKey, bind, buildElseBlock) {
|
|
|
1119
1122
|
ctx.$cd && eachCD.children.push(ctx.$cd);
|
|
1120
1123
|
return;
|
|
1121
1124
|
}
|
|
1122
|
-
|
|
1125
|
+
safeGroupCall(ctx.d);
|
|
1123
1126
|
iterNodes(ctx.first, ctx.last, n => removedNodes.push(n));
|
|
1124
1127
|
});
|
|
1125
1128
|
|
|
@@ -1176,22 +1179,25 @@ function $$eachBlock(label, onlyChild, fn, getKey, bind, buildElseBlock) {
|
|
|
1176
1179
|
} else {
|
|
1177
1180
|
let $dom, rebind,
|
|
1178
1181
|
d = current_destroyList = [],
|
|
1182
|
+
m = current_mountList = [],
|
|
1179
1183
|
$cd = current_cd = cd_new();
|
|
1180
1184
|
try {
|
|
1181
1185
|
([$dom, rebind] = bind(item, i));
|
|
1182
1186
|
} finally {
|
|
1183
|
-
current_destroyList = null;
|
|
1184
|
-
current_cd = null;
|
|
1187
|
+
current_destroyList = current_mountList = current_cd = null;
|
|
1185
1188
|
}
|
|
1186
|
-
|
|
1187
|
-
else d = null;
|
|
1188
|
-
ctx = { $cd, d, rebind };
|
|
1189
|
+
ctx = { $cd, rebind };
|
|
1189
1190
|
cd_attach2(eachCD, $cd);
|
|
1190
1191
|
if($dom.nodeType == 11) {
|
|
1191
1192
|
ctx.first = $dom.firstChild;
|
|
1192
1193
|
ctx.last = $dom.lastChild;
|
|
1193
1194
|
} else ctx.first = ctx.last = $dom;
|
|
1194
1195
|
parentNode.insertBefore($dom, prevNode?.nextSibling);
|
|
1196
|
+
safeCallMount(m, d);
|
|
1197
|
+
if(d.length) {
|
|
1198
|
+
ctx.d = d;
|
|
1199
|
+
p_destroy = 1;
|
|
1200
|
+
}
|
|
1195
1201
|
}
|
|
1196
1202
|
prevNode = ctx.last;
|
|
1197
1203
|
newMapping.set(key, ctx);
|
|
@@ -1233,10 +1239,13 @@ const invokeSlot = ($component, slotName, $context, propsFn, placeholder, cmp) =
|
|
|
1233
1239
|
const makeSlot = (fr, fn) => {
|
|
1234
1240
|
let parentCD = current_cd;
|
|
1235
1241
|
return (callerComponent, $context, props) => {
|
|
1236
|
-
let $dom = fr.cloneNode(true), prev = current_cd
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1242
|
+
let $dom = fr.cloneNode(true), prev = current_cd;
|
|
1243
|
+
if(parentCD) {
|
|
1244
|
+
let $cd = current_cd = cd_new();
|
|
1245
|
+
cd_attach2(parentCD, $cd);
|
|
1246
|
+
$onDestroy(() => cd_detach($cd));
|
|
1247
|
+
cd_component(parentCD).$apply();
|
|
1248
|
+
} else current_cd = null;
|
|
1240
1249
|
try {
|
|
1241
1250
|
return { $dom, push: fn($dom, $context, callerComponent, props) };
|
|
1242
1251
|
} finally {
|
|
@@ -1245,4 +1254,4 @@ const makeSlot = (fr, fn) => {
|
|
|
1245
1254
|
};
|
|
1246
1255
|
};
|
|
1247
1256
|
|
|
1248
|
-
export { $$addEventForComponent, $$awaitBlock, $$cloneDeep, $$compareArray, $$compareDeep, $$deepComparator, $$eachBlock, $$htmlBlock, $$htmlBlockStatic, $$htmlToFragment, $$htmlToFragmentClean, $$removeElements, $$removeItem, $
|
|
1257
|
+
export { $$addEventForComponent, $$awaitBlock, $$cloneDeep, $$compareArray, $$compareDeep, $$deepComparator, $$eachBlock, $$htmlBlock, $$htmlBlockStatic, $$htmlToFragment, $$htmlToFragmentClean, $$removeElements, $$removeItem, $digest, $makeEmitter, $onDestroy, $onMount, $tick, $watch, WatchObject, __app_onerror, __bindActionSubscribe, addClass, addEvent, addStyles, attachAnchor, attachBlock, attachDynComponent, autoSubscribe, bindAction, bindAttribute, bindAttributeBase, bindClass, bindClassExp, bindInput, bindStyle, bindText, callComponent, callExportedFragment, cd_attach, cd_attach2, cd_component, cd_detach, cd_new, cloneDeep, configure, createTextNode, current_cd, current_component, current_destroyList, current_mountList, destroyResults, eachDefaultKey, exportFragment, fire, getFinalLabel, ifBlock, ifBlockReadOnly, insertAfter, invokeSlot, invokeSlotBase, isArray, isFunction, iterNodes, keyComparator, makeAnchor, makeApply, makeBlock, makeBlockBound, makeClassResolver, makeComponent, makeEachBlock, makeEachElseBlock, makeEachSingleBlock, makeExternalProperty, makeRootEvent, makeSlot, mergeAllEvents, mergeEvents, mount, mountStatic, noop, prefixPush, refer, removeElementsBetween, setClassToElement, spreadAttributes, svgToFragment, unwrapProps };
|