malinajs 0.7.2-a1 → 0.7.2-a3
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 +134 -97
- package/package.json +1 -1
- package/runtime.js +96 -94
package/malina.js
CHANGED
|
@@ -290,6 +290,7 @@
|
|
|
290
290
|
|
|
291
291
|
this.isEmpty = function(n) {
|
|
292
292
|
if(n == null) return true;
|
|
293
|
+
if(n.$type == 'if:bind') return false;
|
|
293
294
|
assert(n.$done, 'Node is not built');
|
|
294
295
|
return !n.$result.some(r => {
|
|
295
296
|
if(typeof (r) == 'string') return true;
|
|
@@ -1245,6 +1246,9 @@
|
|
|
1245
1246
|
assert(parent.type === 'fragment', 'Fragment error: /fragment');
|
|
1246
1247
|
return;
|
|
1247
1248
|
} else throw 'Error binding: ' + bind.value;
|
|
1249
|
+
} else {
|
|
1250
|
+
addText(readBinding().raw);
|
|
1251
|
+
continue;
|
|
1248
1252
|
}
|
|
1249
1253
|
}
|
|
1250
1254
|
|
|
@@ -1807,8 +1811,13 @@
|
|
|
1807
1811
|
}
|
|
1808
1812
|
}));
|
|
1809
1813
|
|
|
1810
|
-
this.module.head.push(xNode('$context',
|
|
1811
|
-
|
|
1814
|
+
this.module.head.push(xNode('$context', {
|
|
1815
|
+
$hold: ['componentFn']
|
|
1816
|
+
}, (ctx) => {
|
|
1817
|
+
if(this.inuse.$context) {
|
|
1818
|
+
this.require('componentFn');
|
|
1819
|
+
ctx.write(true, 'const $context = $runtime.$context;');
|
|
1820
|
+
}
|
|
1812
1821
|
}));
|
|
1813
1822
|
|
|
1814
1823
|
this.module.top.push(xNode(this.glob.$onMount, {
|
|
@@ -1851,7 +1860,6 @@
|
|
|
1851
1860
|
|
|
1852
1861
|
let bb = this.buildBlock(this.DOM, {
|
|
1853
1862
|
inline: true,
|
|
1854
|
-
protectLastTag: true,
|
|
1855
1863
|
allowSingleBlock: true,
|
|
1856
1864
|
template: {
|
|
1857
1865
|
name: '$parentElement',
|
|
@@ -1938,7 +1946,6 @@
|
|
|
1938
1946
|
let binds = xNode('block');
|
|
1939
1947
|
let result = {};
|
|
1940
1948
|
let inuse = Object.assign({}, this.inuse);
|
|
1941
|
-
let lastTagDynamic = false;
|
|
1942
1949
|
|
|
1943
1950
|
if(!option.parentElement) option.parentElement = '$parentElement';
|
|
1944
1951
|
|
|
@@ -2021,26 +2028,51 @@
|
|
|
2021
2028
|
if(svg && !other) rootSVG = true;
|
|
2022
2029
|
}
|
|
2023
2030
|
|
|
2024
|
-
let
|
|
2031
|
+
let labelRequest;
|
|
2025
2032
|
|
|
2026
|
-
const
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2033
|
+
const requireLabel = (final, noParent) => {
|
|
2034
|
+
if(labelRequest) {
|
|
2035
|
+
if(labelRequest.final) {
|
|
2036
|
+
labelRequest.set(tpl.push(xNode('node:comment', { label: true, value: '' })));
|
|
2037
|
+
} else {
|
|
2038
|
+
if(final) labelRequest.final = true;
|
|
2039
|
+
if(noParent) labelRequest.noParent = true;
|
|
2040
|
+
return labelRequest;
|
|
2041
|
+
}
|
|
2035
2042
|
}
|
|
2036
|
-
|
|
2043
|
+
labelRequest = {
|
|
2044
|
+
name: null,
|
|
2045
|
+
node: null,
|
|
2046
|
+
final,
|
|
2047
|
+
noParent,
|
|
2048
|
+
set(n) {
|
|
2049
|
+
labelRequest.name = n.bindName();
|
|
2050
|
+
labelRequest.node = n;
|
|
2051
|
+
labelRequest = null;
|
|
2052
|
+
},
|
|
2053
|
+
resolve() {
|
|
2054
|
+
assert(!labelRequest.node);
|
|
2055
|
+
if(labelRequest.noParent) {
|
|
2056
|
+
labelRequest.set(tpl.push(xNode('node:comment', { label: true, value: '' })));
|
|
2057
|
+
} else if(isRoot) {
|
|
2058
|
+
assert(!tpl._boundName);
|
|
2059
|
+
labelRequest.name = tpl._boundName = option.parentElement;
|
|
2060
|
+
} else {
|
|
2061
|
+
labelRequest.name = tpl.bindName();
|
|
2062
|
+
}
|
|
2063
|
+
labelRequest = null;
|
|
2064
|
+
}
|
|
2065
|
+
};
|
|
2066
|
+
return labelRequest;
|
|
2037
2067
|
};
|
|
2038
2068
|
|
|
2039
2069
|
const bindNode = (n, nodeIndex) => {
|
|
2040
2070
|
if(n.type === 'text') {
|
|
2041
|
-
if(isRoot) lastTagDynamic = false;
|
|
2042
2071
|
let prev = tpl.getLast();
|
|
2043
|
-
if(prev?.$type == 'node:text' && prev._boundName) tpl.push(xNode('node:comment', { label: true }));
|
|
2072
|
+
// if(prev?.$type == 'node:text' && prev._boundName) tpl.push(xNode('node:comment', { label: true }));
|
|
2073
|
+
if(prev?.$type == 'node:text' && labelRequest) {
|
|
2074
|
+
labelRequest.set(tpl.push(xNode('node:comment', { label: true })));
|
|
2075
|
+
}
|
|
2044
2076
|
|
|
2045
2077
|
if(n.value.indexOf('{') >= 0) {
|
|
2046
2078
|
const pe = this.parseText(n.value);
|
|
@@ -2074,16 +2106,22 @@
|
|
|
2074
2106
|
}));
|
|
2075
2107
|
});
|
|
2076
2108
|
|
|
2077
|
-
|
|
2109
|
+
labelRequest?.set(textNode);
|
|
2078
2110
|
} else {
|
|
2079
|
-
|
|
2111
|
+
const textNode = tpl.push(n.value);
|
|
2112
|
+
labelRequest?.set(textNode);
|
|
2080
2113
|
}
|
|
2114
|
+
|
|
2081
2115
|
} else if(n.type === 'template') {
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2116
|
+
const templateNode = xNode('node', {
|
|
2117
|
+
openTag: n.openTag,
|
|
2118
|
+
content: n.content
|
|
2119
|
+
});
|
|
2120
|
+
templateNode.$handler = (ctx, n) => {
|
|
2121
|
+
ctx.write(n.openTag, n.content, '</template>');
|
|
2122
|
+
};
|
|
2123
|
+
tpl.push(templateNode);
|
|
2124
|
+
labelRequest?.set(templateNode);
|
|
2087
2125
|
} else if(n.type === 'node') {
|
|
2088
2126
|
if(n.name == 'malina' && !option.malinaElement) {
|
|
2089
2127
|
let b;
|
|
@@ -2092,29 +2130,31 @@
|
|
|
2092
2130
|
b && binds.push(b);
|
|
2093
2131
|
return;
|
|
2094
2132
|
}
|
|
2095
|
-
if(isRoot) lastTagDynamic = false;
|
|
2096
2133
|
if(n.name == 'component' || n.name.match(/^[A-Z]/)) {
|
|
2097
2134
|
if(n.name == 'component' || !n.elArg) {
|
|
2098
2135
|
// component
|
|
2099
2136
|
if(isRoot) requireFragment = true;
|
|
2100
|
-
let el = placeLabel(n.name);
|
|
2101
2137
|
|
|
2102
2138
|
if(n.name == 'component') {
|
|
2103
2139
|
// dyn-component
|
|
2104
|
-
|
|
2140
|
+
const label = requireLabel(true);
|
|
2141
|
+
binds.push(this.makeComponentDyn(n, label));
|
|
2105
2142
|
} else {
|
|
2143
|
+
const label = requireLabel();
|
|
2106
2144
|
let component = this.makeComponent(n);
|
|
2107
2145
|
binds.push(xNode('insert-component', {
|
|
2108
2146
|
component: component.bind,
|
|
2109
2147
|
reference: component.reference,
|
|
2110
|
-
|
|
2148
|
+
label
|
|
2111
2149
|
}, (ctx, n) => {
|
|
2112
2150
|
if(n.reference) {
|
|
2113
2151
|
ctx.write(true, `${n.reference} = `);
|
|
2114
2152
|
ctx.add(n.component);
|
|
2115
|
-
ctx.write(true, `$runtime.
|
|
2153
|
+
if(n.label.node) ctx.write(true, `$runtime.insertBlock(${n.label.name}, ${n.reference});`);
|
|
2154
|
+
else ctx.write(true, `$runtime.addBlock(${n.label.name}, ${n.reference});`);
|
|
2116
2155
|
} else {
|
|
2117
|
-
ctx.write(true, `$runtime.
|
|
2156
|
+
if(n.label.node) ctx.write(true, `$runtime.insertBlock(${n.label.name}, `);
|
|
2157
|
+
else ctx.write(true, `$runtime.addBlock(${n.label.name}, `);
|
|
2118
2158
|
ctx.add(n.component);
|
|
2119
2159
|
ctx.write(');');
|
|
2120
2160
|
}
|
|
@@ -2122,9 +2162,7 @@
|
|
|
2122
2162
|
}
|
|
2123
2163
|
} else {
|
|
2124
2164
|
if(isRoot) requireFragment = true;
|
|
2125
|
-
|
|
2126
|
-
let b = this.attchExportedFragment(n, el, n.name);
|
|
2127
|
-
b && binds.push(b);
|
|
2165
|
+
binds.push(this.attchExportedFragment(n, requireLabel(), n.name));
|
|
2128
2166
|
}
|
|
2129
2167
|
return;
|
|
2130
2168
|
}
|
|
@@ -2133,21 +2171,20 @@
|
|
|
2133
2171
|
let slotName = n.elArg;
|
|
2134
2172
|
if(!slotName) {
|
|
2135
2173
|
if(option.context == 'fragment') {
|
|
2136
|
-
|
|
2137
|
-
binds.push(this.attachFragmentSlot(el));
|
|
2174
|
+
binds.push(this.attachFragmentSlot(requireLabel()));
|
|
2138
2175
|
return;
|
|
2139
2176
|
} else slotName = 'default';
|
|
2140
2177
|
}
|
|
2141
2178
|
|
|
2142
|
-
let el = placeLabel(slotName);
|
|
2143
2179
|
let slot = this.attachSlot(slotName, n);
|
|
2144
2180
|
|
|
2145
2181
|
binds.push(xNode('attach-slot', {
|
|
2146
2182
|
$compile: [slot],
|
|
2147
|
-
|
|
2183
|
+
label: requireLabel(),
|
|
2148
2184
|
slot
|
|
2149
2185
|
}, (ctx, n) => {
|
|
2150
|
-
ctx.write(true, `$runtime.
|
|
2186
|
+
if(n.label.node) ctx.write(true, `$runtime.insertBlock(${n.label.name}, `);
|
|
2187
|
+
else ctx.write(true, `$runtime.addBlock(${n.label.name}, `);
|
|
2151
2188
|
ctx.add(n.slot);
|
|
2152
2189
|
ctx.write(');', true);
|
|
2153
2190
|
}));
|
|
@@ -2155,12 +2192,13 @@
|
|
|
2155
2192
|
}
|
|
2156
2193
|
if(n.name == 'fragment') {
|
|
2157
2194
|
assert(n.elArg, 'Fragment name is required');
|
|
2158
|
-
|
|
2195
|
+
if(isRoot) requireFragment = true;
|
|
2159
2196
|
binds.push(xNode('attach-fragment', {
|
|
2160
|
-
|
|
2197
|
+
label: requireLabel(),
|
|
2161
2198
|
fragment: this.attachFragment(n)
|
|
2162
2199
|
}, (ctx, n) => {
|
|
2163
|
-
ctx.write(true, `$runtime.
|
|
2200
|
+
if(n.label.node) ctx.write(true, `$runtime.insertBlock(${n.label.name}, `);
|
|
2201
|
+
else ctx.write(true, `$runtime.addBlock(${n.label.name}, `);
|
|
2164
2202
|
ctx.add(n.fragment);
|
|
2165
2203
|
ctx.write(')');
|
|
2166
2204
|
}));
|
|
@@ -2170,7 +2208,7 @@
|
|
|
2170
2208
|
let el = xNode('node', { name: n.name });
|
|
2171
2209
|
if(option.oneElement) el._boundName = option.oneElement;
|
|
2172
2210
|
tpl.push(el);
|
|
2173
|
-
|
|
2211
|
+
labelRequest?.set(el);
|
|
2174
2212
|
|
|
2175
2213
|
if(n.attributes.some(a => a.name.startsWith('{...'))) {
|
|
2176
2214
|
this.require('rootCD');
|
|
@@ -2217,9 +2255,8 @@
|
|
|
2217
2255
|
}
|
|
2218
2256
|
} else if(n.type === 'each') {
|
|
2219
2257
|
if(data.type == 'node' && data.body.length == 1) {
|
|
2220
|
-
lastStatic = null;
|
|
2221
2258
|
let eachBlock = this.makeEachBlock(n, {
|
|
2222
|
-
|
|
2259
|
+
label: tpl.bindName(),
|
|
2223
2260
|
onlyChild: true
|
|
2224
2261
|
});
|
|
2225
2262
|
binds.push(eachBlock.source);
|
|
@@ -2227,20 +2264,18 @@
|
|
|
2227
2264
|
} else {
|
|
2228
2265
|
if(isRoot) {
|
|
2229
2266
|
requireFragment = true;
|
|
2230
|
-
|
|
2267
|
+
if(!tpl.getLast()) tpl.push(xNode('node:comment', { label: true }));
|
|
2231
2268
|
}
|
|
2232
|
-
let
|
|
2233
|
-
let eachBlock = this.makeEachBlock(n, { elName: element.bindName() });
|
|
2269
|
+
let eachBlock = this.makeEachBlock(n, { label: requireLabel(true, isRoot) });
|
|
2234
2270
|
binds.push(eachBlock.source);
|
|
2235
2271
|
return;
|
|
2236
2272
|
}
|
|
2237
2273
|
} else if(n.type === 'if') {
|
|
2238
2274
|
if(isRoot) {
|
|
2239
2275
|
requireFragment = true;
|
|
2240
|
-
|
|
2276
|
+
if(!tpl.getLast()) tpl.push(xNode('node:comment', { label: true }));
|
|
2241
2277
|
}
|
|
2242
|
-
|
|
2243
|
-
else binds.push(this.makeifBlock(n, placeLabel(n.value)));
|
|
2278
|
+
binds.push(this.makeifBlock(n, requireLabel(true, isRoot)));
|
|
2244
2279
|
return;
|
|
2245
2280
|
} else if(n.type === 'systag') {
|
|
2246
2281
|
let r = n.value.match(/^@(\w+)\s+(.*)$/s);
|
|
@@ -2250,24 +2285,21 @@
|
|
|
2250
2285
|
if(name == 'html') {
|
|
2251
2286
|
if(isRoot) {
|
|
2252
2287
|
requireFragment = true;
|
|
2253
|
-
|
|
2288
|
+
if(!tpl.getLast()) tpl.push(xNode('node:comment', { label: true }));
|
|
2254
2289
|
}
|
|
2255
|
-
|
|
2256
|
-
binds.push(this.makeHtmlBlock(exp, el));
|
|
2290
|
+
binds.push(this.makeHtmlBlock(exp, requireLabel(true, true)));
|
|
2257
2291
|
return;
|
|
2258
2292
|
} else throw 'Wrong tag';
|
|
2259
2293
|
} else if(n.type === 'await') {
|
|
2260
2294
|
if(isRoot) {
|
|
2261
2295
|
requireFragment = true;
|
|
2262
|
-
|
|
2296
|
+
if(!tpl.getLast()) tpl.push(xNode('node:comment', { label: true }));
|
|
2263
2297
|
}
|
|
2264
|
-
|
|
2265
|
-
let r = this.makeAwaitBlock(n, el);
|
|
2266
|
-
r && binds.push(r);
|
|
2298
|
+
binds.push(this.makeAwaitBlock(n, requireLabel(true, isRoot)));
|
|
2267
2299
|
return;
|
|
2268
2300
|
} else if(n.type === 'comment') {
|
|
2269
|
-
|
|
2270
|
-
|
|
2301
|
+
const commentNode = tpl.push(n.content);
|
|
2302
|
+
labelRequest?.set(commentNode);
|
|
2271
2303
|
}
|
|
2272
2304
|
};
|
|
2273
2305
|
body.forEach((node, i) => {
|
|
@@ -2277,11 +2309,10 @@
|
|
|
2277
2309
|
wrapException(e, node);
|
|
2278
2310
|
}
|
|
2279
2311
|
});
|
|
2312
|
+
labelRequest?.resolve();
|
|
2280
2313
|
};
|
|
2314
|
+
|
|
2281
2315
|
go(data, true, rootTemplate);
|
|
2282
|
-
if(option.protectLastTag && lastTagDynamic) {
|
|
2283
|
-
rootTemplate.push(xNode('node:comment', { value: '' }));
|
|
2284
|
-
}
|
|
2285
2316
|
|
|
2286
2317
|
let innerBlock = null;
|
|
2287
2318
|
if(binds.body.length) {
|
|
@@ -2529,7 +2560,7 @@
|
|
|
2529
2560
|
if(n.type == 'text') e.details = n.value.trim();
|
|
2530
2561
|
else if(n.type == 'node') e.details = n.openTag.trim();
|
|
2531
2562
|
else if(n.type == 'each') e.details = n.value.trim();
|
|
2532
|
-
else if(n.type == 'if') e.details = n.value.trim();
|
|
2563
|
+
else if(n.type == 'if') e.details = n.parts?.[0]?.value.trim() || 'if-block';
|
|
2533
2564
|
}
|
|
2534
2565
|
throw e;
|
|
2535
2566
|
}
|
|
@@ -5128,7 +5159,7 @@
|
|
|
5128
5159
|
return { bind: result, reference };
|
|
5129
5160
|
}
|
|
5130
5161
|
|
|
5131
|
-
function makeComponentDyn(node,
|
|
5162
|
+
function makeComponentDyn(node, label) {
|
|
5132
5163
|
let dynamicComponent;
|
|
5133
5164
|
|
|
5134
5165
|
if(node.elArg) {
|
|
@@ -5150,15 +5181,16 @@
|
|
|
5150
5181
|
|
|
5151
5182
|
component.componentName = '$ComponentConstructor';
|
|
5152
5183
|
return xNode('dyn-component', {
|
|
5153
|
-
|
|
5184
|
+
label,
|
|
5154
5185
|
exp: dynamicComponent,
|
|
5155
5186
|
component,
|
|
5156
5187
|
reference
|
|
5157
5188
|
}, (ctx, n) => {
|
|
5158
|
-
ctx.write(true, `$runtime.attachDynComponent(${n.
|
|
5189
|
+
ctx.write(true, `$runtime.attachDynComponent(${n.label.name}, () => ${n.exp}, ($ComponentConstructor) => `);
|
|
5159
5190
|
if(n.reference) ctx.write(`${n.reference} = `);
|
|
5160
5191
|
ctx.add(n.component);
|
|
5161
|
-
ctx.write(')');
|
|
5192
|
+
if(n.label.node) ctx.write(')');
|
|
5193
|
+
else ctx.write(', true)');
|
|
5162
5194
|
});
|
|
5163
5195
|
}
|
|
5164
5196
|
|
|
@@ -5322,7 +5354,7 @@
|
|
|
5322
5354
|
})
|
|
5323
5355
|
};
|
|
5324
5356
|
} else if(name == 'style' && arg) {
|
|
5325
|
-
let styleName =
|
|
5357
|
+
let styleName = arg;
|
|
5326
5358
|
let exp;
|
|
5327
5359
|
if(prop.value) {
|
|
5328
5360
|
if(isExpression(prop.value)) {
|
|
@@ -5340,13 +5372,13 @@
|
|
|
5340
5372
|
name: styleName,
|
|
5341
5373
|
value: prop.value
|
|
5342
5374
|
}, (ctx, n) => {
|
|
5343
|
-
ctx.writeLine(`${n.el}.style.${n.name} = \`${Q(n.value)}\`;`);
|
|
5375
|
+
ctx.writeLine(`${n.el}.style.${toCamelCase(n.name)} = \`${Q(n.value)}\`;`);
|
|
5344
5376
|
})
|
|
5345
5377
|
};
|
|
5346
5378
|
}
|
|
5347
5379
|
}
|
|
5348
5380
|
} else {
|
|
5349
|
-
exp = styleName;
|
|
5381
|
+
exp = toCamelCase(styleName);
|
|
5350
5382
|
}
|
|
5351
5383
|
|
|
5352
5384
|
let hasElement = exp.includes('$element');
|
|
@@ -5363,7 +5395,7 @@
|
|
|
5363
5395
|
if(ctx.inuse.apply) {
|
|
5364
5396
|
ctx.writeLine(`$runtime.bindStyle(${n.el}, '${n.styleName}', () => (${n.exp}));`);
|
|
5365
5397
|
} else {
|
|
5366
|
-
ctx.writeLine(`${n.el}.style.${n.styleName} = ${n.exp};`);
|
|
5398
|
+
ctx.writeLine(`${n.el}.style.${toCamelCase(n.styleName)} = ${n.exp};`);
|
|
5367
5399
|
}
|
|
5368
5400
|
})]
|
|
5369
5401
|
})
|
|
@@ -5603,7 +5635,7 @@
|
|
|
5603
5635
|
}
|
|
5604
5636
|
}
|
|
5605
5637
|
|
|
5606
|
-
function makeifBlock(data,
|
|
5638
|
+
function makeifBlock(data, label) {
|
|
5607
5639
|
const getBlock = b => {
|
|
5608
5640
|
if(b.singleBlock) {
|
|
5609
5641
|
return xNode('make-block', {
|
|
@@ -5624,22 +5656,21 @@
|
|
|
5624
5656
|
this.detectDependency(exp);
|
|
5625
5657
|
parts.push({
|
|
5626
5658
|
exp,
|
|
5627
|
-
block: getBlock(this.buildBlock(part, {
|
|
5659
|
+
block: getBlock(this.buildBlock(part, { allowSingleBlock: true }))
|
|
5628
5660
|
});
|
|
5629
5661
|
});
|
|
5630
|
-
if(data.elsePart) elseBlock = getBlock(this.buildBlock({ body: data.elsePart }, {
|
|
5662
|
+
if(data.elsePart) elseBlock = getBlock(this.buildBlock({ body: data.elsePart }, { allowSingleBlock: true }));
|
|
5631
5663
|
|
|
5632
5664
|
return xNode('if:bind', {
|
|
5633
5665
|
$wait: ['apply'],
|
|
5634
|
-
|
|
5635
|
-
parentElement,
|
|
5666
|
+
label,
|
|
5636
5667
|
parts,
|
|
5637
5668
|
elseBlock
|
|
5638
5669
|
}, (ctx, n) => {
|
|
5639
5670
|
if(this.inuse.apply) {
|
|
5640
|
-
ctx.write(true, `$runtime.ifBlock(${n.
|
|
5671
|
+
ctx.write(true, `$runtime.ifBlock(${n.label.name}, `);
|
|
5641
5672
|
} else {
|
|
5642
|
-
ctx.write(true, `$runtime.ifBlockReadOnly(${n.
|
|
5673
|
+
ctx.write(true, `$runtime.ifBlockReadOnly(${n.label.name}, `);
|
|
5643
5674
|
}
|
|
5644
5675
|
|
|
5645
5676
|
if(n.parts.length == 1) {
|
|
@@ -5665,7 +5696,7 @@
|
|
|
5665
5696
|
|
|
5666
5697
|
ctx.indent--;
|
|
5667
5698
|
ctx.write(true);
|
|
5668
|
-
if(n.
|
|
5699
|
+
if(!n.label.node) ctx.write(', true');
|
|
5669
5700
|
ctx.write(');', true);
|
|
5670
5701
|
});
|
|
5671
5702
|
}
|
|
@@ -5783,7 +5814,6 @@
|
|
|
5783
5814
|
if(!nodeItems.length) nodeItems = [data.mainBlock[0]];
|
|
5784
5815
|
|
|
5785
5816
|
let itemBlock, block = this.buildBlock({ body: nodeItems }, {
|
|
5786
|
-
protectLastTag: true,
|
|
5787
5817
|
allowSingleBlock: !blockPrefix,
|
|
5788
5818
|
each: {
|
|
5789
5819
|
blockPrefix,
|
|
@@ -5817,7 +5847,6 @@
|
|
|
5817
5847
|
let elseBlock = null;
|
|
5818
5848
|
if(data.elseBlock) {
|
|
5819
5849
|
let block = this.buildBlock({ body: data.elseBlock }, {
|
|
5820
|
-
protectLastTag: true,
|
|
5821
5850
|
allowSingleBlock: false
|
|
5822
5851
|
});
|
|
5823
5852
|
elseBlock = block.block;
|
|
@@ -5826,9 +5855,15 @@
|
|
|
5826
5855
|
const source = xNode('each', {
|
|
5827
5856
|
keyFunction,
|
|
5828
5857
|
block: itemBlock,
|
|
5829
|
-
elseBlock
|
|
5858
|
+
elseBlock,
|
|
5859
|
+
label: option.label,
|
|
5860
|
+
onlyChild: option.onlyChild
|
|
5830
5861
|
}, (ctx, n) => {
|
|
5831
|
-
|
|
5862
|
+
let el = n.onlyChild ? n.label : n.label.name;
|
|
5863
|
+
let mode = 0;
|
|
5864
|
+
if(n.onlyChild) mode = 1;
|
|
5865
|
+
else if(!n.label.node) mode = 2;
|
|
5866
|
+
ctx.writeLine(`$runtime.$$eachBlock(${el}, ${mode}, () => (${arrayName}),`);
|
|
5832
5867
|
ctx.indent++;
|
|
5833
5868
|
ctx.write(true);
|
|
5834
5869
|
if(n.keyFunction === 'noop') ctx.write('$runtime.noop');
|
|
@@ -5853,15 +5888,15 @@
|
|
|
5853
5888
|
this.detectDependency(exp);
|
|
5854
5889
|
return xNode('block', {
|
|
5855
5890
|
$wait: ['apply'],
|
|
5856
|
-
|
|
5891
|
+
label,
|
|
5857
5892
|
exp
|
|
5858
5893
|
}, (ctx, n) => {
|
|
5859
|
-
if(this.inuse.apply) ctx.write(true, `$runtime.htmlBlock(${n.
|
|
5860
|
-
else ctx.write(true, `$runtime.htmlBlockStatic(${n.
|
|
5894
|
+
if(this.inuse.apply) ctx.write(true, `$runtime.htmlBlock(${n.label.name}, () => (${n.exp}));`);
|
|
5895
|
+
else ctx.write(true, `$runtime.htmlBlockStatic(${n.label.name}, ${n.exp});`);
|
|
5861
5896
|
});
|
|
5862
5897
|
}
|
|
5863
5898
|
|
|
5864
|
-
function makeAwaitBlock(node,
|
|
5899
|
+
function makeAwaitBlock(node, label) {
|
|
5865
5900
|
let valueForThen, exp;
|
|
5866
5901
|
|
|
5867
5902
|
let rx = node.value.match(/^#await\s+(.+)\s+then\s+(\S+)\s*$/s);
|
|
@@ -5881,7 +5916,7 @@
|
|
|
5881
5916
|
|
|
5882
5917
|
let parts = [null, null, null];
|
|
5883
5918
|
if(node.parts.main && node.parts.main.length) {
|
|
5884
|
-
parts[0] = this.buildBlock({ body: node.parts.main }
|
|
5919
|
+
parts[0] = this.buildBlock({ body: node.parts.main });
|
|
5885
5920
|
}
|
|
5886
5921
|
if(node.parts.then && node.parts.then.length) {
|
|
5887
5922
|
let args = [];
|
|
@@ -5895,7 +5930,7 @@
|
|
|
5895
5930
|
args.push(rx[1]);
|
|
5896
5931
|
}
|
|
5897
5932
|
}
|
|
5898
|
-
parts[1] = this.buildBlock({ body: node.parts.then }, {
|
|
5933
|
+
parts[1] = this.buildBlock({ body: node.parts.then }, { extraArguments: args });
|
|
5899
5934
|
}
|
|
5900
5935
|
if(node.parts.catch && node.parts.catch.length) {
|
|
5901
5936
|
let args = [];
|
|
@@ -5904,7 +5939,7 @@
|
|
|
5904
5939
|
assert(isSimpleName(rx[1]));
|
|
5905
5940
|
args.push(rx[1]);
|
|
5906
5941
|
}
|
|
5907
|
-
parts[2] = this.buildBlock({ body: node.parts.catch }, {
|
|
5942
|
+
parts[2] = this.buildBlock({ body: node.parts.catch }, { extraArguments: args });
|
|
5908
5943
|
}
|
|
5909
5944
|
|
|
5910
5945
|
if(this.script.readOnly) {
|
|
@@ -5915,12 +5950,12 @@
|
|
|
5915
5950
|
this.require('apply');
|
|
5916
5951
|
|
|
5917
5952
|
return xNode('await', {
|
|
5918
|
-
|
|
5953
|
+
label,
|
|
5919
5954
|
exp,
|
|
5920
5955
|
parts,
|
|
5921
5956
|
keywords
|
|
5922
5957
|
}, (ctx, n) => {
|
|
5923
|
-
ctx.write(true, `$runtime.awaitBlock(${n.
|
|
5958
|
+
ctx.write(true, `$runtime.awaitBlock(${n.label.name}, ${n.label.node ? 0 : 1}, () => [${n.keywords.join(', ')}], () => ${n.exp},`);
|
|
5924
5959
|
ctx.indent++;
|
|
5925
5960
|
n.parts.forEach((part, index) => {
|
|
5926
5961
|
if(index) ctx.write(', ');
|
|
@@ -6192,9 +6227,10 @@
|
|
|
6192
6227
|
|
|
6193
6228
|
function attachFragmentSlot(label) {
|
|
6194
6229
|
return xNode('fragment-slot', {
|
|
6195
|
-
|
|
6230
|
+
label
|
|
6196
6231
|
}, (ctx, n) => {
|
|
6197
|
-
ctx.write(true, `$runtime.
|
|
6232
|
+
if(n.label.node) ctx.write(true, `$runtime.insertBlock(${n.label.name}, $$fragmentSlot?.())`);
|
|
6233
|
+
else ctx.write(true, `$runtime.addBlock(${n.label.name}, $$fragmentSlot?.())`);
|
|
6198
6234
|
});
|
|
6199
6235
|
}
|
|
6200
6236
|
|
|
@@ -6203,7 +6239,7 @@
|
|
|
6203
6239
|
let data = {
|
|
6204
6240
|
name: node.elArg,
|
|
6205
6241
|
componentName,
|
|
6206
|
-
label
|
|
6242
|
+
label
|
|
6207
6243
|
};
|
|
6208
6244
|
|
|
6209
6245
|
let body = trimEmptyNodes(node.body || []);
|
|
@@ -6218,7 +6254,8 @@
|
|
|
6218
6254
|
data = { ...pa, ...data };
|
|
6219
6255
|
|
|
6220
6256
|
return xNode('attach-exported-fragment', data, (ctx, n) => {
|
|
6221
|
-
ctx.write(true, `$runtime.
|
|
6257
|
+
if(n.label.node) ctx.write(true, `$runtime.insertBlock(${n.label.name}, $runtime.callExportedFragment($instance_${n.componentName}, '${n.name}'`);
|
|
6258
|
+
else ctx.write(true, `$runtime.addBlock(${n.label.name}, $runtime.callExportedFragment($instance_${n.componentName}, '${n.name}'`);
|
|
6222
6259
|
ctx.indent++;
|
|
6223
6260
|
let missed = '';
|
|
6224
6261
|
|
|
@@ -6597,7 +6634,7 @@
|
|
|
6597
6634
|
return { event, fn, rootModifier };
|
|
6598
6635
|
}
|
|
6599
6636
|
|
|
6600
|
-
const version = '0.7.2-
|
|
6637
|
+
const version = '0.7.2-a3';
|
|
6601
6638
|
|
|
6602
6639
|
|
|
6603
6640
|
async function compile(source, config = {}) {
|
package/package.json
CHANGED
package/runtime.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
let current_destroyList, current_mountList, current_cd, destroyResults;
|
|
2
|
+
const $onDestroy = fn => fn && current_destroyList.push(fn);
|
|
3
|
+
const $onMount = fn => current_mountList.push(fn);
|
|
4
|
+
|
|
1
5
|
let __app_onerror = console.error;
|
|
2
6
|
|
|
3
7
|
const configure = (option) => {
|
|
@@ -24,17 +28,13 @@ const safeGroupCall = list => {
|
|
|
24
28
|
}
|
|
25
29
|
};
|
|
26
30
|
|
|
27
|
-
const
|
|
28
|
-
|
|
31
|
+
const safeGroupCall2 = (list, resultList) => {
|
|
32
|
+
list?.forEach(fn => {
|
|
29
33
|
let r = safeCall(fn);
|
|
30
|
-
r &&
|
|
34
|
+
r && resultList.push(r);
|
|
31
35
|
});
|
|
32
36
|
};
|
|
33
37
|
|
|
34
|
-
let current_destroyList, current_mountList, current_cd, destroyResults;
|
|
35
|
-
const $onDestroy = fn => fn && current_destroyList.push(fn);
|
|
36
|
-
const $onMount = fn => current_mountList.push(fn);
|
|
37
|
-
|
|
38
38
|
function WatchObject(fn, cb) {
|
|
39
39
|
this.fn = fn;
|
|
40
40
|
this.cb = cb;
|
|
@@ -288,25 +288,6 @@ const iterNodes = (el, last, fn) => {
|
|
|
288
288
|
const removeElements = (el, last) => iterNodes(el, last, n => n.remove());
|
|
289
289
|
|
|
290
290
|
|
|
291
|
-
function removeElementsBetween(el, stop) {
|
|
292
|
-
let next;
|
|
293
|
-
el = el.nextSibling;
|
|
294
|
-
while(el) {
|
|
295
|
-
next = el.nextSibling;
|
|
296
|
-
if(el == stop) break;
|
|
297
|
-
el.remove();
|
|
298
|
-
el = next;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
const getFinalLabel = n => {
|
|
303
|
-
if(n.nextSibling) return n.nextSibling;
|
|
304
|
-
let e = document.createTextNode('');
|
|
305
|
-
n.parentNode.appendChild(e);
|
|
306
|
-
return e;
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
|
|
310
291
|
const resolvedPromise = Promise.resolve();
|
|
311
292
|
|
|
312
293
|
function $tick(fn) {
|
|
@@ -326,7 +307,7 @@ function makeEmitter(option) {
|
|
|
326
307
|
}
|
|
327
308
|
|
|
328
309
|
|
|
329
|
-
let current_component;
|
|
310
|
+
let current_component, $context;
|
|
330
311
|
|
|
331
312
|
|
|
332
313
|
const makeApply = () => {
|
|
@@ -357,6 +338,7 @@ const makeApply = () => {
|
|
|
357
338
|
|
|
358
339
|
const makeComponent = (init) => {
|
|
359
340
|
return ($option = {}) => {
|
|
341
|
+
$context = $option.context || {};
|
|
360
342
|
let prev_component = current_component,
|
|
361
343
|
prev_cd = current_cd,
|
|
362
344
|
$component = current_component = { $option };
|
|
@@ -367,6 +349,7 @@ const makeComponent = (init) => {
|
|
|
367
349
|
} finally {
|
|
368
350
|
current_component = prev_component;
|
|
369
351
|
current_cd = prev_cd;
|
|
352
|
+
$context = null;
|
|
370
353
|
}
|
|
371
354
|
|
|
372
355
|
return $component;
|
|
@@ -417,34 +400,33 @@ const callComponentDyn = (component, context, option = {}, propFn, cmp, setter,
|
|
|
417
400
|
};
|
|
418
401
|
|
|
419
402
|
|
|
420
|
-
const attachDynComponent = (label, exp, bind) => {
|
|
403
|
+
const attachDynComponent = (label, exp, bind, parentLabel) => {
|
|
421
404
|
let parentCD = current_cd;
|
|
422
|
-
let
|
|
405
|
+
let destroyList, $cd, first;
|
|
423
406
|
const destroy = () => safeGroupCall(destroyList);
|
|
424
407
|
$onDestroy(destroy);
|
|
425
408
|
|
|
426
409
|
$watch(exp, (component) => {
|
|
427
410
|
destroy();
|
|
428
411
|
if($cd) cd_detach($cd);
|
|
429
|
-
if(
|
|
412
|
+
if(first) removeElements(first, parentLabel ? null : label.previousSibling);
|
|
430
413
|
|
|
431
414
|
if(component) {
|
|
432
415
|
destroyList = current_destroyList = [];
|
|
433
416
|
current_mountList = [];
|
|
434
417
|
$cd = current_cd = cd_new();
|
|
435
418
|
try {
|
|
436
|
-
$dom = bind(component).$dom;
|
|
419
|
+
const $dom = bind(component).$dom;
|
|
437
420
|
cd_attach(parentCD, $cd);
|
|
438
|
-
|
|
439
|
-
|
|
421
|
+
first = $dom.nodeType == 11 ? $dom.firstChild : $dom;
|
|
422
|
+
if(parentLabel) label.appendChild($dom);
|
|
423
|
+
else label.parentNode.insertBefore($dom, label);
|
|
424
|
+
safeGroupCall2(current_mountList, destroyList);
|
|
440
425
|
} finally {
|
|
441
426
|
current_destroyList = current_mountList = current_cd = null;
|
|
442
427
|
}
|
|
443
|
-
active = true;
|
|
444
428
|
} else {
|
|
445
|
-
$cd = null;
|
|
446
|
-
active = false;
|
|
447
|
-
destroyList = null;
|
|
429
|
+
$cd = first = destroyList = null;
|
|
448
430
|
}
|
|
449
431
|
});
|
|
450
432
|
};
|
|
@@ -647,7 +629,8 @@ const spreadAttributes = (el, fn) => {
|
|
|
647
629
|
|
|
648
630
|
|
|
649
631
|
const callExportedFragment = (childComponent, name, slot, events, props, cmp) => {
|
|
650
|
-
let push, $dom;
|
|
632
|
+
let push, $dom, fn = childComponent.$exported?.[name];
|
|
633
|
+
if(!fn) return;
|
|
651
634
|
if(cmp) {
|
|
652
635
|
let result;
|
|
653
636
|
let w = $watch(props, (value) => {
|
|
@@ -657,7 +640,6 @@ const callExportedFragment = (childComponent, name, slot, events, props, cmp) =>
|
|
|
657
640
|
fire(w);
|
|
658
641
|
props = () => result;
|
|
659
642
|
}
|
|
660
|
-
let fn = childComponent.$exported?.[name];
|
|
661
643
|
([$dom, push] = fn(props, events, slot));
|
|
662
644
|
return $dom;
|
|
663
645
|
};
|
|
@@ -731,6 +713,16 @@ const attachBlock = (label, $dom) => {
|
|
|
731
713
|
insertAfter(label, $dom.$dom || $dom);
|
|
732
714
|
};
|
|
733
715
|
|
|
716
|
+
const addBlock = (parent, $dom) => {
|
|
717
|
+
if(!$dom) return;
|
|
718
|
+
parent.appendChild($dom.$dom || $dom);
|
|
719
|
+
};
|
|
720
|
+
|
|
721
|
+
const insertBlock = (label, $dom) => {
|
|
722
|
+
if(!$dom) return;
|
|
723
|
+
label.parentNode.insertBefore($dom.$dom || $dom, label);
|
|
724
|
+
};
|
|
725
|
+
|
|
734
726
|
const mergeEvents = (...callbacks) => {
|
|
735
727
|
callbacks = callbacks.filter(i => i);
|
|
736
728
|
return (e) => callbacks.forEach(cb => cb(e));
|
|
@@ -791,7 +783,7 @@ const mount = (label, component, option) => {
|
|
|
791
783
|
last = $dom.lastChild;
|
|
792
784
|
} else first = last = $dom;
|
|
793
785
|
label.appendChild($dom);
|
|
794
|
-
|
|
786
|
+
safeGroupCall2(current_mountList, destroyList);
|
|
795
787
|
} finally {
|
|
796
788
|
current_destroyList = current_mountList = null;
|
|
797
789
|
}
|
|
@@ -860,21 +852,21 @@ let create = (tag, html) => {
|
|
|
860
852
|
t.innerHTML = html;
|
|
861
853
|
fr = t.content;
|
|
862
854
|
}
|
|
863
|
-
let
|
|
864
|
-
|
|
865
|
-
return
|
|
855
|
+
let firstElement = fr.firstChild;
|
|
856
|
+
tag.parentNode.insertBefore(fr, tag);
|
|
857
|
+
return firstElement;
|
|
866
858
|
};
|
|
867
859
|
|
|
868
860
|
function htmlBlock(tag, fn) {
|
|
869
|
-
let
|
|
861
|
+
let firstElement;
|
|
870
862
|
let destroy = () => {
|
|
871
|
-
if(!
|
|
872
|
-
removeElements(tag.
|
|
873
|
-
|
|
863
|
+
if(!firstElement) return;
|
|
864
|
+
removeElements(firstElement, tag.previousSibling);
|
|
865
|
+
firstElement = null;
|
|
874
866
|
};
|
|
875
867
|
$watch(fn, (html) => {
|
|
876
868
|
destroy();
|
|
877
|
-
if(html)
|
|
869
|
+
if(html) firstElement = create(tag, html);
|
|
878
870
|
});
|
|
879
871
|
}
|
|
880
872
|
|
|
@@ -884,7 +876,7 @@ function htmlBlockStatic(tag, value) {
|
|
|
884
876
|
|
|
885
877
|
function ifBlock(label, fn, parts, parentLabel) {
|
|
886
878
|
let first, last, $cd, destroyList, parentCD = current_cd;
|
|
887
|
-
$onDestroy(() =>
|
|
879
|
+
$onDestroy(() => safeGroupCall2(destroyList, destroyResults));
|
|
888
880
|
|
|
889
881
|
function createBlock(builder) {
|
|
890
882
|
let $dom;
|
|
@@ -902,14 +894,14 @@ function ifBlock(label, fn, parts, parentLabel) {
|
|
|
902
894
|
last = $dom.lastChild;
|
|
903
895
|
} else first = last = $dom;
|
|
904
896
|
if(parentLabel) label.appendChild($dom);
|
|
905
|
-
else
|
|
906
|
-
|
|
897
|
+
else label.parentNode.insertBefore($dom, label);
|
|
898
|
+
safeGroupCall2(mountList, destroyList);
|
|
907
899
|
}
|
|
908
900
|
|
|
909
901
|
function destroyBlock() {
|
|
910
902
|
if(!first) return;
|
|
911
903
|
destroyResults = [];
|
|
912
|
-
|
|
904
|
+
safeGroupCall2(destroyList, destroyResults);
|
|
913
905
|
destroyList.length = 0;
|
|
914
906
|
if($cd) {
|
|
915
907
|
cd_detach($cd);
|
|
@@ -932,12 +924,16 @@ function ifBlock(label, fn, parts, parentLabel) {
|
|
|
932
924
|
}
|
|
933
925
|
|
|
934
926
|
|
|
935
|
-
function ifBlockReadOnly(label, fn, parts) {
|
|
927
|
+
function ifBlockReadOnly(label, fn, parts, parentLabel) {
|
|
936
928
|
let value = fn();
|
|
937
|
-
if(value != null)
|
|
929
|
+
if(value != null) {
|
|
930
|
+
const $dom = parts[value]();
|
|
931
|
+
if(parentLabel) label.appendChild($dom);
|
|
932
|
+
else label.parentNode.insertBefore($dom, label);
|
|
933
|
+
}
|
|
938
934
|
}
|
|
939
935
|
|
|
940
|
-
function awaitBlock(label, relation, fn, build_main, build_then, build_catch) {
|
|
936
|
+
function awaitBlock(label, parentLabel, relation, fn, build_main, build_then, build_catch) {
|
|
941
937
|
let parentCD = current_cd, first, last, $cd, promise, destroyList, status = 0;
|
|
942
938
|
$onDestroy(() => safeGroupCall(destroyList));
|
|
943
939
|
|
|
@@ -971,8 +967,9 @@ function awaitBlock(label, relation, fn, build_main, build_then, build_catch) {
|
|
|
971
967
|
first = $dom.firstChild;
|
|
972
968
|
last = $dom.lastChild;
|
|
973
969
|
} else first = last = $dom;
|
|
974
|
-
|
|
975
|
-
|
|
970
|
+
if(parentLabel) label.appendChild($dom);
|
|
971
|
+
else label.parentNode.insertBefore($dom, label);
|
|
972
|
+
safeGroupCall2(mountList, destroyList);
|
|
976
973
|
cd_component(parentCD).$apply();
|
|
977
974
|
}
|
|
978
975
|
|
|
@@ -1015,11 +1012,12 @@ const makeEachSingleBlock = (fn) => {
|
|
|
1015
1012
|
|
|
1016
1013
|
|
|
1017
1014
|
const makeEachElseBlock = (fn) => {
|
|
1018
|
-
return (label,
|
|
1015
|
+
return (label, mode, parentCD) => {
|
|
1019
1016
|
let first, last;
|
|
1020
1017
|
let destroyList = current_destroyList = [];
|
|
1021
1018
|
let $cd = current_cd = cd_new();
|
|
1022
1019
|
current_mountList = [];
|
|
1020
|
+
const parentNode = mode ? label : label.parentNode;
|
|
1023
1021
|
try {
|
|
1024
1022
|
let $dom = fn();
|
|
1025
1023
|
if($dom.nodeType == 11) {
|
|
@@ -1027,32 +1025,41 @@ const makeEachElseBlock = (fn) => {
|
|
|
1027
1025
|
last = $dom.lastChild;
|
|
1028
1026
|
} else first = last = $dom;
|
|
1029
1027
|
cd_attach(parentCD, $cd);
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
safeCallMount(current_mountList, destroyList);
|
|
1028
|
+
parentNode.insertBefore($dom, mode ? null : label);
|
|
1029
|
+
safeGroupCall2(current_mountList, destroyList);
|
|
1033
1030
|
} finally {
|
|
1034
1031
|
current_destroyList = current_mountList = current_cd = null;
|
|
1035
1032
|
}
|
|
1036
1033
|
|
|
1037
1034
|
return () => {
|
|
1038
|
-
removeElements(first, last);
|
|
1039
1035
|
cd_detach($cd);
|
|
1040
|
-
|
|
1036
|
+
destroyResults = [];
|
|
1037
|
+
safeGroupCall2(destroyList, destroyResults);
|
|
1038
|
+
|
|
1039
|
+
if(destroyResults.length) {
|
|
1040
|
+
const f = first, l = last;
|
|
1041
|
+
iterNodes(f, l, n => n.$$removing = true);
|
|
1042
|
+
Promise.allSettled(destroyResults).then(() => iterNodes(f, l, n => n.remove()));
|
|
1043
|
+
} else {
|
|
1044
|
+
removeElements(first, last);
|
|
1045
|
+
}
|
|
1046
|
+
destroyResults = null;
|
|
1041
1047
|
};
|
|
1042
1048
|
};
|
|
1043
1049
|
};
|
|
1044
1050
|
|
|
1045
1051
|
|
|
1046
|
-
function $$eachBlock(label,
|
|
1052
|
+
function $$eachBlock(label, mode, fn, getKey, bind, buildElseBlock) {
|
|
1047
1053
|
let parentCD = current_cd;
|
|
1048
1054
|
let eachCD = cd_new();
|
|
1049
1055
|
cd_attach(parentCD, eachCD);
|
|
1050
1056
|
|
|
1051
1057
|
let mapping = new Map();
|
|
1052
|
-
let
|
|
1058
|
+
let firstNode, vi = 0, p_promise = 0, p_destroy = 0, elseBlock;
|
|
1059
|
+
const onlyChild = mode == 1;
|
|
1053
1060
|
|
|
1054
1061
|
const destroyAll = () => {
|
|
1055
|
-
p_destroy &&
|
|
1062
|
+
p_destroy && mapping.forEach(ctx => safeGroupCall2(ctx.d, destroyResults));
|
|
1056
1063
|
mapping.clear();
|
|
1057
1064
|
};
|
|
1058
1065
|
|
|
@@ -1065,14 +1072,7 @@ function $$eachBlock(label, onlyChild, fn, getKey, bind, buildElseBlock) {
|
|
|
1065
1072
|
else if(!isArray(array)) array = [];
|
|
1066
1073
|
|
|
1067
1074
|
let newMapping = new Map();
|
|
1068
|
-
let
|
|
1069
|
-
if(onlyChild) {
|
|
1070
|
-
prevNode = null;
|
|
1071
|
-
parentNode = label;
|
|
1072
|
-
} else {
|
|
1073
|
-
prevNode = label;
|
|
1074
|
-
parentNode = label.parentNode;
|
|
1075
|
-
}
|
|
1075
|
+
let parentNode = mode ? label : label.parentNode;
|
|
1076
1076
|
|
|
1077
1077
|
if(mapping.size) {
|
|
1078
1078
|
let ctx, count = 0;
|
|
@@ -1085,7 +1085,7 @@ function $$eachBlock(label, onlyChild, fn, getKey, bind, buildElseBlock) {
|
|
|
1085
1085
|
}
|
|
1086
1086
|
}
|
|
1087
1087
|
|
|
1088
|
-
if(!count &&
|
|
1088
|
+
if(!count && firstNode) {
|
|
1089
1089
|
destroyResults = [];
|
|
1090
1090
|
eachCD.children.length = 0;
|
|
1091
1091
|
destroyAll();
|
|
@@ -1093,14 +1093,14 @@ function $$eachBlock(label, onlyChild, fn, getKey, bind, buildElseBlock) {
|
|
|
1093
1093
|
if(destroyResults.length) {
|
|
1094
1094
|
p_promise = 1;
|
|
1095
1095
|
let removedNodes = [];
|
|
1096
|
-
iterNodes(onlyChild ?
|
|
1096
|
+
iterNodes(firstNode, onlyChild ? null : label.previousSibling, n => {
|
|
1097
1097
|
n.$$removing = true;
|
|
1098
1098
|
removedNodes.push(n);
|
|
1099
1099
|
});
|
|
1100
1100
|
Promise.allSettled(destroyResults).then(() => removedNodes.forEach(n => n.remove()));
|
|
1101
1101
|
} else {
|
|
1102
1102
|
if(onlyChild) label.textContent = '';
|
|
1103
|
-
else removeElements(label.
|
|
1103
|
+
else removeElements(firstNode, label.previousSibling);
|
|
1104
1104
|
}
|
|
1105
1105
|
|
|
1106
1106
|
destroyResults = null;
|
|
@@ -1113,7 +1113,7 @@ function $$eachBlock(label, onlyChild, fn, getKey, bind, buildElseBlock) {
|
|
|
1113
1113
|
ctx.$cd && eachCD.children.push(ctx.$cd);
|
|
1114
1114
|
return;
|
|
1115
1115
|
}
|
|
1116
|
-
|
|
1116
|
+
safeGroupCall2(ctx.d, destroyResults);
|
|
1117
1117
|
iterNodes(ctx.first, ctx.last, n => removedNodes.push(n));
|
|
1118
1118
|
});
|
|
1119
1119
|
|
|
@@ -1134,7 +1134,9 @@ function $$eachBlock(label, onlyChild, fn, getKey, bind, buildElseBlock) {
|
|
|
1134
1134
|
}
|
|
1135
1135
|
|
|
1136
1136
|
let i, item, next_ctx, ctx, nextEl, key;
|
|
1137
|
-
|
|
1137
|
+
let nextNode = mode ? null : label;
|
|
1138
|
+
i = array.length;
|
|
1139
|
+
while(i--) {
|
|
1138
1140
|
item = array[i];
|
|
1139
1141
|
key = getKey(item, i, array);
|
|
1140
1142
|
if(next_ctx) {
|
|
@@ -1142,31 +1144,31 @@ function $$eachBlock(label, onlyChild, fn, getKey, bind, buildElseBlock) {
|
|
|
1142
1144
|
next_ctx = null;
|
|
1143
1145
|
} else ctx = mapping.get(key);
|
|
1144
1146
|
if(ctx) {
|
|
1145
|
-
nextEl =
|
|
1146
|
-
if(p_promise) while(nextEl && nextEl.$$removing) nextEl = nextEl.
|
|
1147
|
-
if(nextEl != ctx.
|
|
1147
|
+
nextEl = nextNode ? nextNode.previousSibling : parentNode.lastChild;
|
|
1148
|
+
if(p_promise) while(nextEl && nextEl.$$removing) nextEl = nextEl.previousSibling;
|
|
1149
|
+
if(nextEl != ctx.last) {
|
|
1148
1150
|
let insert = true;
|
|
1149
1151
|
|
|
1150
|
-
if(ctx.first == ctx.last && (i
|
|
1151
|
-
next_ctx = mapping.get(getKey(array[i
|
|
1152
|
-
if(next_ctx &&
|
|
1153
|
-
parentNode.replaceChild(ctx.first,
|
|
1152
|
+
if(ctx.first == ctx.last && (i > 0) && nextEl) {
|
|
1153
|
+
next_ctx = mapping.get(getKey(array[i - 1], i - 1, array));
|
|
1154
|
+
if(next_ctx && nextEl.previousSibling === next_ctx.last) {
|
|
1155
|
+
parentNode.replaceChild(ctx.first, nextEl);
|
|
1154
1156
|
insert = false;
|
|
1155
1157
|
}
|
|
1156
1158
|
}
|
|
1157
1159
|
|
|
1158
1160
|
if(insert) {
|
|
1159
|
-
let insertBefore = prevNode?.nextSibling;
|
|
1160
1161
|
let next, el = ctx.first;
|
|
1161
1162
|
while(el) {
|
|
1162
1163
|
next = el.nextSibling;
|
|
1163
|
-
parentNode.insertBefore(el,
|
|
1164
|
+
parentNode.insertBefore(el, nextNode);
|
|
1164
1165
|
if(el == ctx.last) break;
|
|
1165
1166
|
el = next;
|
|
1166
1167
|
}
|
|
1167
1168
|
}
|
|
1168
1169
|
}
|
|
1169
1170
|
ctx.rebind?.(item, i);
|
|
1171
|
+
nextNode = ctx.first;
|
|
1170
1172
|
} else {
|
|
1171
1173
|
let $dom, rebind,
|
|
1172
1174
|
d = current_destroyList = [],
|
|
@@ -1183,22 +1185,22 @@ function $$eachBlock(label, onlyChild, fn, getKey, bind, buildElseBlock) {
|
|
|
1183
1185
|
ctx.first = $dom.firstChild;
|
|
1184
1186
|
ctx.last = $dom.lastChild;
|
|
1185
1187
|
} else ctx.first = ctx.last = $dom;
|
|
1186
|
-
parentNode.insertBefore($dom,
|
|
1187
|
-
|
|
1188
|
+
parentNode.insertBefore($dom, nextNode);
|
|
1189
|
+
nextNode = ctx.first;
|
|
1190
|
+
safeGroupCall2(m, d);
|
|
1188
1191
|
if(d.length) {
|
|
1189
1192
|
ctx.d = d;
|
|
1190
1193
|
p_destroy = 1;
|
|
1191
1194
|
}
|
|
1192
1195
|
}
|
|
1193
|
-
prevNode = ctx.last;
|
|
1194
1196
|
newMapping.set(key, ctx);
|
|
1195
1197
|
}
|
|
1196
|
-
|
|
1198
|
+
firstNode = nextNode;
|
|
1197
1199
|
mapping.clear();
|
|
1198
1200
|
mapping = newMapping;
|
|
1199
1201
|
|
|
1200
1202
|
if(!array.length && !elseBlock && buildElseBlock) {
|
|
1201
|
-
elseBlock = buildElseBlock(label,
|
|
1203
|
+
elseBlock = buildElseBlock(label, mode, parentCD);
|
|
1202
1204
|
}
|
|
1203
1205
|
}, { cmp: compareArray });
|
|
1204
1206
|
}
|
|
@@ -1245,4 +1247,4 @@ const makeSlot = (fr, fn) => {
|
|
|
1245
1247
|
};
|
|
1246
1248
|
};
|
|
1247
1249
|
|
|
1248
|
-
export { $$eachBlock, $digest, $onDestroy, $onMount, $tick, $watch, WatchObject, __app_onerror, __bindActionSubscribe, 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,
|
|
1250
|
+
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, keyComparator, makeAnchor, makeApply, makeBlock, makeBlockBound, makeClassResolver, makeComponent, makeEachBlock, makeEachElseBlock, makeEachSingleBlock, makeEmitter, makeExternalProperty, makeRootEvent, makeSlot, mergeAllEvents, mergeEvents, mount, mountStatic, noop, prefixPush, refer, removeElements, removeItem, setClassToElement, spreadAttributes, svgToFragment, unwrapProps };
|