malinajs 0.7.0-a15 → 0.7.0-a16

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 CHANGED
@@ -14,6 +14,7 @@
14
14
  * each-else
15
15
  * else-if
16
16
  * refactoring $onMount
17
+ * optional deep checking for passed props: prop={value} prop|deep={value}
17
18
 
18
19
  ## 0.6.x
19
20
 
package/malina.js CHANGED
@@ -647,8 +647,8 @@
647
647
  cloneNode = false;
648
648
  if(!node.raw) template = htmlEntitiesToText(template);
649
649
  } else {
650
- if(get_context().config.hideLabel) convert = '$runtime.$$htmlToFragmentClean';
651
- else convert = '$runtime.$$htmlToFragment';
650
+ if(get_context().config.hideLabel) convert = '$runtime.htmlToFragmentClean';
651
+ else convert = '$runtime.htmlToFragment';
652
652
  template = template.replace(/<!---->/g, '<>');
653
653
  }
654
654
  if(node.raw) {
@@ -672,14 +672,6 @@
672
672
 
673
673
  function compactDOM() {
674
674
  let data = this.DOM;
675
- const details = {
676
- node: [n => n.body],
677
- each: [n => n.body],
678
- slot: [n => n.body],
679
- fragment: [n => n.body],
680
- if: [n => n.body, n => n.bodyMain],
681
- await: [n => n.parts.main, n => n.parts.then, n => n.parts.catch]
682
- };
683
675
 
684
676
  function go(body, parentNode) {
685
677
  let i;
@@ -717,11 +709,28 @@
717
709
  }
718
710
  } else {
719
711
  if(node.type == 'node' && (node.name == 'pre' || node.name == 'textarea')) continue;
720
- let keys = details[node.type];
721
- keys && keys.forEach(k => {
722
- let body = k(node);
723
- if(body && body.length) go(body, node);
724
- });
712
+ switch(node.type) {
713
+ case 'node':
714
+ case 'slot':
715
+ case 'fragment':
716
+ if(node.body) go(node.body, node);
717
+ break
718
+ case 'each':
719
+ if(node.mainBlock) go(node.mainBlock, node);
720
+ if(node.elseBlock) go(node.elseBlock, node);
721
+ break
722
+ case 'await':
723
+ if(node.parts.main) go(node.parts.main, node);
724
+ if(node.parts.then) go(node.parts.then, node);
725
+ if(node.parts.catch) go(node.parts.catch, node);
726
+ break
727
+ case 'if':
728
+ node.parts.forEach(p => {
729
+ if(p.body) go(p.body, node);
730
+ });
731
+ if(node.elsePart) go(node.elsePart, node);
732
+ break
733
+ }
725
734
  }
726
735
  }
727
736
 
@@ -739,12 +748,12 @@
739
748
  let prev = getPrev();
740
749
  let next = getNext();
741
750
 
742
- if(next?.type == 'node' && ['br', 'div'].includes(next.name)) {
751
+ if(next?.type == 'node' && ['br', 'div', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'h7'].includes(next.name)) {
743
752
  body.splice(i, 1);
744
753
  continue;
745
754
  }
746
755
 
747
- if(prev?.type == 'node' && ['br', 'div'].includes(prev.name)) {
756
+ if(prev?.type == 'node' && ['br', 'div', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'h7'].includes(prev.name)) {
748
757
  body.splice(i, 1);
749
758
  continue;
750
759
  }
@@ -774,7 +783,7 @@
774
783
  body.splice(i, 1);
775
784
  continue;
776
785
  }
777
- if(parentNode.type == 'node' && parentNode.name == 'div') {
786
+ if(parentNode.type == 'node' && ['div', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'h7'].includes(parentNode.name)) {
778
787
  body.splice(i, 1);
779
788
  continue;
780
789
  }
@@ -1548,7 +1557,7 @@
1548
1557
  }, (ctx, n) => {
1549
1558
  if(this.inuse.apply) {
1550
1559
  if(this.config.immutable) ctx.write(true, `$watch(() => (${n.exp}), ${n.callback});`);
1551
- else ctx.write(true, `$watch(() => (${n.exp}), ${n.callback}, {cmp: $runtime.$$deepComparator(0)});`);
1560
+ else ctx.write(true, `$watch(() => (${n.exp}), ${n.callback}, {cmp: $runtime.deepComparator(0)});`);
1552
1561
  } else {
1553
1562
  ctx.write(true, `(${n.callback})(${n.exp});`);
1554
1563
  }
@@ -1565,7 +1574,7 @@
1565
1574
  exp: astring.generate(exp),
1566
1575
  callback
1567
1576
  }, (ctx, n) => {
1568
- if(this.inuse.apply) ctx.write(true, `$watch(() => ${n.exp}, ($args) => { (${n.callback}).apply(null, $args); }, {cmp: $runtime.$$deepComparator(1)});`);
1577
+ if(this.inuse.apply) ctx.write(true, `$watch(() => ${n.exp}, ($args) => { (${n.callback}).apply(null, $args); }, {cmp: $runtime.deepComparator(1)});`);
1569
1578
  else ctx.write(true, `(${n.callback}).apply(null, ${n.exp})`);
1570
1579
  }));
1571
1580
  } else throw 'Error';
@@ -1806,7 +1815,7 @@
1806
1815
  }));
1807
1816
 
1808
1817
  this.module.head.push(xNode('$emit', (ctx) => {
1809
- if(this.inuse.$emit) ctx.write(true, 'const $emit = $runtime.$makeEmitter($option);');
1818
+ if(this.inuse.$emit) ctx.write(true, 'const $emit = $runtime.makeEmitter($option);');
1810
1819
  }));
1811
1820
 
1812
1821
  if(this.config.autoSubscribe && !this.script.readOnly) {
@@ -1927,7 +1936,12 @@
1927
1936
  if(nodesForSingleBlock.length == 1) {
1928
1937
  let n = nodesForSingleBlock[0];
1929
1938
  if(n.type == 'node' && n.name.match(/^[A-Z]/)) {
1930
- let component = this.makeComponent(n);
1939
+ let component;
1940
+ try {
1941
+ component = this.makeComponent(n);
1942
+ } catch (e) {
1943
+ wrapException(e, n);
1944
+ }
1931
1945
  return {
1932
1946
  singleBlock: component.bind,
1933
1947
  reference: component.reference
@@ -4437,6 +4451,7 @@
4437
4451
  }
4438
4452
  } else cleanSelectorItems.push(s);
4439
4453
  }
4454
+ while(cleanSelectorItems.length && ['WhiteSpace', 'Combinator'].includes(cleanSelectorItems[0].type)) cleanSelectorItems.shift();
4440
4455
  while(cleanSelectorItems.length && ['WhiteSpace', 'Combinator'].includes(last(cleanSelectorItems).type)) cleanSelectorItems.pop();
4441
4456
  if(!cleanSelectorItems.length || globalBlock) { // fully global?
4442
4457
  assert(origin.length);
@@ -4746,7 +4761,7 @@
4746
4761
  this.require('$context');
4747
4762
 
4748
4763
  let reference = null;
4749
- let propsFn = [], propsSetter = [], $class = [], staticProps = true;
4764
+ let propsFn = [], propsSetter = [], $class = [], staticProps = true, deepChecking = false;
4750
4765
  let slotBlocks = [];
4751
4766
  let anchorBlocks = [];
4752
4767
 
@@ -4937,7 +4952,9 @@
4937
4952
  return;
4938
4953
  }
4939
4954
 
4940
- let { event, fn } = this.makeEventProp(prop);
4955
+ let { event, fn } = this.makeEventProp(prop, () => {
4956
+ throw new Error('$element is not available for component, use $event instead');
4957
+ });
4941
4958
 
4942
4959
  passEvent(event, xNode('passEvent', {
4943
4960
  fn
@@ -4970,6 +4987,7 @@
4970
4987
  if(ip.name == ip.value) propsFn.push(`${ip.name}`);
4971
4988
  else propsFn.push(`${ip.name}: ${ip.value}`);
4972
4989
  if(!ip.static) staticProps = false;
4990
+ if(ip.mod.deep) deepChecking = true;
4973
4991
  });
4974
4992
 
4975
4993
 
@@ -4985,10 +5003,14 @@
4985
5003
  forwardAllEvents,
4986
5004
  events,
4987
5005
  slots: slotBlocks.length ? slotBlocks : null,
4988
- anchors: anchorBlocks.length ? anchorBlocks : null
5006
+ anchors: anchorBlocks.length ? anchorBlocks : null,
5007
+ deepChecking
4989
5008
  }, (ctx, n) => {
4990
5009
  let comma = false;
4991
- ctx.write(`$runtime.callComponent($context, ${n.componentName}, {`);
5010
+
5011
+ if(this.inuse.apply && (n.$class.length || n.propsSetter.length || n.props.length && !n.staticProps)) {
5012
+ ctx.write(`$runtime.callComponentDyn(${n.componentName}, $context, {`);
5013
+ } else ctx.write(`$runtime.callComponent(${n.componentName}, $context, {`);
4992
5014
 
4993
5015
  if(n.props.length && (n.staticProps || !this.inuse.apply)) {
4994
5016
  ctx.write(`props: {${n.props.join(', ')}}`);
@@ -5066,8 +5088,8 @@
5066
5088
  other = '';
5067
5089
  ctx.write(',');
5068
5090
  if(n.props.length) ctx.write('\n', true);
5069
- if(this.config.immutable) ctx.write('$runtime.keyComparator');
5070
- else ctx.write('$runtime.$$compareDeep');
5091
+ if(n.deepChecking) ctx.write('$runtime.compareDeep');
5092
+ else ctx.write('$runtime.keyComparator');
5071
5093
  } else other += ', null';
5072
5094
 
5073
5095
  if(n.propsSetter.length && this.inuse.apply) {
@@ -5817,8 +5839,8 @@
5817
5839
  el: label.bindName(),
5818
5840
  exp
5819
5841
  }, (ctx, n) => {
5820
- if(this.inuse.apply) ctx.write(true, `$runtime.$$htmlBlock(${n.el}, () => (${n.exp}));`);
5821
- else ctx.write(true, `$runtime.$$htmlBlockStatic(${n.el}, ${n.exp});`);
5842
+ if(this.inuse.apply) ctx.write(true, `$runtime.htmlBlock(${n.el}, () => (${n.exp}));`);
5843
+ else ctx.write(true, `$runtime.htmlBlockStatic(${n.el}, ${n.exp});`);
5822
5844
  });
5823
5845
  }
5824
5846
 
@@ -5881,7 +5903,7 @@
5881
5903
  parts,
5882
5904
  keywords
5883
5905
  }, (ctx, n) => {
5884
- ctx.write(true, `$runtime.$$awaitBlock(${n.el}, () => [${n.keywords.join(', ')}], () => ${n.exp},`);
5906
+ ctx.write(true, `$runtime.awaitBlock(${n.el}, () => [${n.keywords.join(', ')}], () => ${n.exp},`);
5885
5907
  ctx.indent++;
5886
5908
  n.parts.forEach((part, index) => {
5887
5909
  if(index) ctx.write(', ');
@@ -5896,12 +5918,13 @@
5896
5918
  }
5897
5919
 
5898
5920
  function attachSlot(slotName, node) {
5899
- let props = [], staticProps = true;
5921
+ let props = [], staticProps = true, deepChecking = false;
5900
5922
 
5901
5923
  if(node.attributes && node.attributes.length) {
5902
5924
  node.attributes.forEach(prop => {
5903
5925
  let { name, value, ...ip } = this.inspectProp(prop);
5904
5926
  if(!ip.static) staticProps = false;
5927
+ if(ip.mod.deep) deepChecking = true;
5905
5928
  props.push(xNode('slot-prop', {
5906
5929
  name,
5907
5930
  value
@@ -5922,7 +5945,8 @@
5922
5945
  name: slotName,
5923
5946
  props,
5924
5947
  staticProps,
5925
- placeholder
5948
+ placeholder,
5949
+ deepChecking
5926
5950
  }, (ctx, n) => {
5927
5951
  let dynamicProps = this.inuse.apply && !n.staticProps;
5928
5952
 
@@ -5949,8 +5973,8 @@
5949
5973
 
5950
5974
  if(dynamicProps) {
5951
5975
  ctx.write(missed, ', ');
5952
- if(this.config.immutable) ctx.write('$runtime.keyComparator');
5953
- else ctx.write('$runtime.$$compareDeep');
5976
+ if(n.deepChecking) ctx.write('$runtime.compareDeep');
5977
+ else ctx.write('$runtime.keyComparator');
5954
5978
  }
5955
5979
  ctx.write(')');
5956
5980
  });
@@ -5983,6 +6007,11 @@
5983
6007
  });
5984
6008
  }
5985
6009
 
6010
+ if(external) {
6011
+ this.require('$component');
6012
+ if(props?.length) this.require('apply');
6013
+ }
6014
+
5986
6015
  return xNode('fragment', {
5987
6016
  $compile: [block.source],
5988
6017
  name,
@@ -6019,7 +6048,7 @@
6019
6048
  ctx.indent--;
6020
6049
  ctx.writeLine('}');
6021
6050
  }
6022
- if(n.external) ctx.writeLine(`$runtime.exportFragment('${n.name}', $fragment_${n.name});`);
6051
+ if(n.external) ctx.writeLine(`$runtime.exportFragment($component, '${n.name}', $fragment_${n.name});`);
6023
6052
  });
6024
6053
  }
6025
6054
 
@@ -6029,6 +6058,7 @@
6029
6058
  let events = [];
6030
6059
  let forwardAllEvents;
6031
6060
  let staticProps = true;
6061
+ let deepChecking = false;
6032
6062
 
6033
6063
  attributes.forEach(prop => {
6034
6064
  let name = prop.name;
@@ -6053,10 +6083,11 @@
6053
6083
  let ip = this.inspectProp(prop);
6054
6084
  props.push(ip);
6055
6085
  if(!ip.static) staticProps = false;
6086
+ if(ip.mod.deep) deepChecking = true;
6056
6087
  }
6057
6088
  });
6058
6089
 
6059
- return { props, events, forwardAllEvents, staticProps };
6090
+ return { props, events, forwardAllEvents, staticProps, deepChecking };
6060
6091
  }
6061
6092
 
6062
6093
 
@@ -6226,8 +6257,8 @@
6226
6257
  ctx.write('() => (');
6227
6258
  writeProps();
6228
6259
  ctx.write('), ');
6229
- if(this.config.immutable) ctx.write('$runtime.keyComparator');
6230
- else ctx.write('$runtime.$$compareDeep');
6260
+ if(n.deepChecking) ctx.write('$runtime.compareDeep');
6261
+ else ctx.write('$runtime.keyComparator');
6231
6262
  }
6232
6263
  }
6233
6264
 
@@ -6304,7 +6335,7 @@
6304
6335
  ctx.add(n.template);
6305
6336
  ctx.add(n.source);
6306
6337
  ctx.writeLine('let a=$parentElement.firstChild, b=$parentElement.lastChild;');
6307
- ctx.writeLine('$onDestroy(() => {$runtime.$$removeElements(a, b)});');
6338
+ ctx.writeLine('$onDestroy(() => {$runtime.removeElements(a, b)});');
6308
6339
  ctx.writeLine('document.head.appendChild($parentElement);');
6309
6340
  ctx.indent--;
6310
6341
  ctx.writeLine('}');
@@ -6315,14 +6346,18 @@
6315
6346
  }
6316
6347
 
6317
6348
  function inspectProp(prop) {
6318
- let { name, value } = prop;
6349
+ let { name, value } = prop, mod = {};
6319
6350
  if(name[0] == '{') {
6320
6351
  assert(!prop.value);
6321
6352
  value = name;
6322
6353
  name = unwrapExp(name);
6354
+ } else {
6355
+ const p = name.split('|');
6356
+ name = p[0];
6357
+ p.slice(1).forEach(n => mod[n] = true);
6323
6358
  }
6324
6359
 
6325
- assert(name.match(/^([\w$_][\w\d$_.\-]*)$/), `Wrong property: '${name}'`);
6360
+ assert(name.match(/^([\w$_][\w\d$_.\-|]*)$/), `Wrong property: '${name}'`);
6326
6361
  name = toCamelCase(name);
6327
6362
  if(name == 'class') name = '_class';
6328
6363
 
@@ -6361,7 +6396,7 @@
6361
6396
  statical = true;
6362
6397
  }
6363
6398
 
6364
- return { name, value, rawValue, static: statical };
6399
+ return { name, value, rawValue, static: statical, mod };
6365
6400
  }
6366
6401
 
6367
6402
  function attachPortal(node) {
@@ -6393,7 +6428,7 @@
6393
6428
  ctx.add(n.source);
6394
6429
  ctx.writeLine('let $$first = $parentElement.firstChild;');
6395
6430
  ctx.writeLine('let $$last = $parentElement.lastChild;');
6396
- ctx.writeLine(`$runtime.$onDestroy(() => $runtime.$$removeElements($$first, $$last));`);
6431
+ ctx.writeLine(`$runtime.$onDestroy(() => $runtime.removeElements($$first, $$last));`);
6397
6432
  ctx.writeLine(`$tick(() => ${label}.appendChild($parentElement));`);
6398
6433
  ctx.indent--;
6399
6434
  ctx.writeLine('}');
@@ -6545,7 +6580,7 @@
6545
6580
  return { event, fn, rootModifier };
6546
6581
  }
6547
6582
 
6548
- const version = '0.7.0-a15';
6583
+ const version = '0.7.0-a16';
6549
6584
 
6550
6585
 
6551
6586
  async function compile(source, config = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "malinajs",
3
- "version": "0.7.0-a15",
3
+ "version": "0.7.0-a16",
4
4
  "license": "MIT",
5
5
  "scripts": {
6
6
  "prepare": "npm run build",
package/runtime.js CHANGED
@@ -58,7 +58,7 @@ function addEvent(el, event, callback) {
58
58
  });
59
59
  }
60
60
 
61
- function $$removeItem(array, item) {
61
+ function removeItem(array, item) {
62
62
  let i = array.indexOf(item);
63
63
  if(i >= 0) array.splice(i, 1);
64
64
  }
@@ -77,20 +77,18 @@ const cd_component = cd => {
77
77
 
78
78
  const cd_new = () => new $ChangeDetector();
79
79
 
80
- const cd_attach2 = (parent, cd) => {
80
+ const cd_attach = (parent, cd) => {
81
81
  if(cd) {
82
82
  cd.parent = parent;
83
83
  parent.children.push(cd);
84
84
  }
85
85
  };
86
86
 
87
- const cd_attach = (cd) => cd_attach2(current_cd, cd);
88
-
89
- const cd_detach = cd => $$removeItem(cd.parent.children, cd);
87
+ const cd_detach = cd => removeItem(cd.parent.children, cd);
90
88
 
91
89
  const isArray = (a) => Array.isArray(a);
92
90
 
93
- const compareArray = (a, b) => {
91
+ const _compareArray = (a, b) => {
94
92
  let a0 = isArray(a);
95
93
  let a1 = isArray(b);
96
94
  if(a0 !== a1) return true;
@@ -103,15 +101,15 @@ const compareArray = (a, b) => {
103
101
  };
104
102
 
105
103
 
106
- function $$compareArray(w, value) {
107
- if(!compareArray(w.value, value)) return 0;
104
+ function compareArray(w, value) {
105
+ if(!_compareArray(w.value, value)) return 0;
108
106
  if(isArray(value)) w.value = value.slice();
109
107
  else w.value = value;
110
108
  w.cb(w.value);
111
109
  }
112
110
 
113
111
 
114
- const compareDeep = (a, b, lvl) => {
112
+ const _compareDeep = (a, b, lvl) => {
115
113
  if(lvl < 0 || !a || !b) return a !== b;
116
114
  if(a === b) return false;
117
115
  let o0 = isObject(a);
@@ -125,12 +123,12 @@ const compareDeep = (a, b, lvl) => {
125
123
  if(a0) {
126
124
  if(a.length !== b.length) return true;
127
125
  for(let i = 0; i < a.length; i++) {
128
- if(compareDeep(a[i], b[i], lvl - 1)) return true;
126
+ if(_compareDeep(a[i], b[i], lvl - 1)) return true;
129
127
  }
130
128
  } else {
131
129
  let set = {};
132
130
  for(let k in a) {
133
- if(compareDeep(a[k], b[k], lvl - 1)) return true;
131
+ if(_compareDeep(a[k], b[k], lvl - 1)) return true;
134
132
  set[k] = true;
135
133
  }
136
134
  for(let k in b) {
@@ -156,19 +154,16 @@ function cloneDeep(d, lvl) {
156
154
  return d;
157
155
  }
158
156
 
159
- const $$cloneDeep = function(d) {
160
- return cloneDeep(d, 10);
161
- };
162
157
 
163
- function $$deepComparator(depth) {
158
+ function deepComparator(depth) {
164
159
  return function(w, value) {
165
- let diff = compareDeep(w.value, value, depth);
160
+ let diff = _compareDeep(w.value, value, depth);
166
161
  diff && (w.value = cloneDeep(value, depth), !w.idle && w.cb(value));
167
162
  w.idle = false;
168
163
  };
169
164
  }
170
165
 
171
- const $$compareDeep = $$deepComparator(10);
166
+ const compareDeep = deepComparator(10);
172
167
 
173
168
 
174
169
  const keyComparator = (w, value) => {
@@ -232,7 +227,7 @@ const insertAfter = (label, node) => {
232
227
 
233
228
  const createTextNode = (text) => document.createTextNode(text);
234
229
 
235
- const $$htmlToFragment = (html, option) => {
230
+ const htmlToFragment = (html, option) => {
236
231
  let result = templatecache[html];
237
232
  if(!result) {
238
233
  let t = document.createElement('template');
@@ -245,7 +240,7 @@ const $$htmlToFragment = (html, option) => {
245
240
  return option & 1 ? result.cloneNode(true) : result;
246
241
  };
247
242
 
248
- const $$htmlToFragmentClean = (html, option) => {
243
+ const htmlToFragmentClean = (html, option) => {
249
244
  let result = templatecache[html];
250
245
  if(!result) {
251
246
  let t = document.createElement('template');
@@ -290,7 +285,7 @@ const iterNodes = (el, last, fn) => {
290
285
  };
291
286
 
292
287
 
293
- const $$removeElements = (el, last) => iterNodes(el, last, n => n.remove());
288
+ const removeElements = (el, last) => iterNodes(el, last, n => n.remove());
294
289
 
295
290
 
296
291
  function removeElementsBetween(el, stop) {
@@ -320,7 +315,7 @@ function $tick(fn) {
320
315
  }
321
316
 
322
317
 
323
- function $makeEmitter(option) {
318
+ function makeEmitter(option) {
324
319
  return (name, detail) => {
325
320
  let fn = option.events?.[name];
326
321
  if(!fn) return;
@@ -331,23 +326,6 @@ function $makeEmitter(option) {
331
326
  }
332
327
 
333
328
 
334
- function $$addEventForComponent(list, event, fn) {
335
- let prev = list[event];
336
- if(prev) {
337
- if(prev._list) prev._list.push(fn);
338
- else {
339
- function handler(e) {
340
- handler._list.forEach(fn => {
341
- fn(e);
342
- });
343
- }
344
- handler._list = [prev, fn];
345
- list[event] = handler;
346
- }
347
- } else list[event] = fn;
348
- }
349
-
350
-
351
329
  let current_component;
352
330
 
353
331
 
@@ -381,7 +359,7 @@ const makeComponent = (init) => {
381
359
  return ($option = {}) => {
382
360
  let prev_component = current_component,
383
361
  prev_cd = current_cd,
384
- $component = current_component = {$option};
362
+ $component = current_component = { $option };
385
363
  current_cd = null;
386
364
 
387
365
  try {
@@ -396,9 +374,16 @@ const makeComponent = (init) => {
396
374
  };
397
375
 
398
376
 
399
- const callComponent = (context, component, option = {}, propFn, cmp, setter, classFn) => {
377
+ const callComponent = (component, context, option = {}) => {
400
378
  option.context = { ...context };
401
- let $component, parentWatch, parentCD = current_cd;
379
+ let $component = safeCall(() => component(option));
380
+ if($component instanceof Node) $component = { $dom: $component };
381
+ return $component;
382
+ };
383
+
384
+
385
+ const callComponentDyn = (component, context, option = {}, propFn, cmp, setter, classFn) => {
386
+ let $component, parentWatch;
402
387
 
403
388
  if(propFn) {
404
389
  parentWatch = $watch(propFn, value => {
@@ -416,12 +401,13 @@ const callComponent = (context, component, option = {}, propFn, cmp, setter, cla
416
401
  }, { value: {}, cmp: keyComparator }));
417
402
  }
418
403
 
419
- $component = safeCall(() => component(option));
420
- if($component instanceof Node) $component = {$dom: $component};
404
+ $component = callComponent(component, context, option);
421
405
  if(setter && $component?.$exportedProps) {
422
- let w = new WatchObject($component.$exportedProps, value => {
406
+ let parentCD = current_cd, w = new WatchObject($component.$exportedProps, value => {
423
407
  setter(value);
424
408
  cd_component(parentCD).$apply();
409
+ $component.$push(parentWatch.fn());
410
+ $component.$apply();
425
411
  });
426
412
  Object.assign(w, { idle: true, cmp, value: parentWatch.value });
427
413
  $component.$cd.watchers.push(w);
@@ -448,7 +434,7 @@ const attachDynComponent = (label, exp, bind) => {
448
434
  $cd = current_cd = cd_new();
449
435
  try {
450
436
  $dom = bind(component).$dom;
451
- cd_attach2(parentCD, $cd);
437
+ cd_attach(parentCD, $cd);
452
438
  insertAfter(label, $dom);
453
439
  safeCallMount(current_mountList, destroyList);
454
440
  } finally {
@@ -549,7 +535,7 @@ const __bindActionSubscribe = (fn, handler, value) => {
549
535
  if(handler?.update && fn) {
550
536
  $watch(fn, args => {
551
537
  handler.update.apply(handler, args);
552
- }, { cmp: $$deepComparator(1), value: cloneDeep(value, 1) });
538
+ }, { cmp: deepComparator(1), value: cloneDeep(value, 1) });
553
539
  }
554
540
  };
555
541
 
@@ -608,9 +594,6 @@ const makeExternalProperty = (name, getter, setter) => {
608
594
  };
609
595
 
610
596
 
611
- const eachDefaultKey = (item, index, array) => isObject(array[0]) ? item : index;
612
-
613
-
614
597
  const attachAnchor = ($option, el, name) => {
615
598
  $option.anchor?.[name || 'default']?.(el);
616
599
  };
@@ -620,7 +603,7 @@ const makeAnchor = (fn) => {
620
603
  let parentCD = current_cd;
621
604
  return ($dom) => {
622
605
  let prev = current_cd, $cd = current_cd = cd_new();
623
- cd_attach2(parentCD, $cd);
606
+ cd_attach(parentCD, $cd);
624
607
  $onDestroy(() => cd_detach($cd));
625
608
  try {
626
609
  fn($dom);
@@ -680,16 +663,21 @@ const callExportedFragment = (childComponent, name, slot, events, props, cmp) =>
680
663
  };
681
664
 
682
665
 
683
- const exportFragment = (name, fn) => {
666
+ const exportFragment = (component, name, fn) => {
684
667
  let childCD = current_cd;
685
- let component = cd_component(childCD);
686
668
  if(!component.$exported) component.$exported = {};
687
669
  component.$exported[name] = (props, events, slot) => {
688
- let prev = current_cd, $cd = current_cd = cd_new();
689
- cd_attach2(childCD, $cd);
690
- $onDestroy(() => cd_detach($cd));
691
- let apply = cd_component(childCD).$apply;
692
- apply();
670
+ let prev = current_cd, apply;
671
+ if(childCD) {
672
+ let $cd = current_cd = cd_new();
673
+ cd_attach(childCD, $cd);
674
+ $onDestroy(() => cd_detach($cd));
675
+ apply = component.$apply;
676
+ apply();
677
+ } else {
678
+ current_cd = null;
679
+ }
680
+
693
681
  try {
694
682
  return [fn(props, events || {}, slot), apply];
695
683
  } finally {
@@ -726,7 +714,7 @@ const makeBlockBound = (fr, fn) => {
726
714
  let parentCD = current_cd;
727
715
  return () => {
728
716
  let $dom = fr.cloneNode(true), prev = current_cd, $cd = current_cd = cd_new();
729
- cd_attach2(parentCD, $cd);
717
+ cd_attach(parentCD, $cd);
730
718
  $onDestroy(() => cd_detach($cd));
731
719
  try {
732
720
  fn($dom);
@@ -809,7 +797,7 @@ const mount = (label, component, option) => {
809
797
  }
810
798
  app.destroy = () => {
811
799
  safeGroupCall(destroyList);
812
- $$removeElements(first, last);
800
+ removeElements(first, last);
813
801
  };
814
802
  return app;
815
803
  };
@@ -877,11 +865,11 @@ let create = (tag, html) => {
877
865
  return lastElement;
878
866
  };
879
867
 
880
- function $$htmlBlock(tag, fn) {
868
+ function htmlBlock(tag, fn) {
881
869
  let lastElement;
882
870
  let destroy = () => {
883
871
  if(!lastElement) return;
884
- $$removeElements(tag.nextSibling, lastElement);
872
+ removeElements(tag.nextSibling, lastElement);
885
873
  lastElement = null;
886
874
  };
887
875
  $watch(fn, (html) => {
@@ -890,7 +878,7 @@ function $$htmlBlock(tag, fn) {
890
878
  });
891
879
  }
892
880
 
893
- function $$htmlBlockStatic(tag, value) {
881
+ function htmlBlockStatic(tag, value) {
894
882
  create(tag, value);
895
883
  }
896
884
 
@@ -908,7 +896,7 @@ function ifBlock(label, fn, parts, parentLabel) {
908
896
  } finally {
909
897
  current_destroyList = current_mountList = current_cd = null;
910
898
  }
911
- cd_attach2(parentCD, $cd);
899
+ cd_attach(parentCD, $cd);
912
900
  if($dom.nodeType == 11) {
913
901
  first = $dom.firstChild;
914
902
  last = $dom.lastChild;
@@ -930,9 +918,9 @@ function ifBlock(label, fn, parts, parentLabel) {
930
918
  if(destroyResults.length) {
931
919
  let f = first, l = last;
932
920
  Promise.allSettled(destroyResults).then(() => {
933
- $$removeElements(f, l);
921
+ removeElements(f, l);
934
922
  });
935
- } else $$removeElements(first, last);
923
+ } else removeElements(first, last);
936
924
  first = last = null;
937
925
  destroyResults = null;
938
926
  }
@@ -949,7 +937,7 @@ function ifBlockReadOnly(label, fn, parts) {
949
937
  if(value != null) insertAfter(label, parts[value]());
950
938
  }
951
939
 
952
- function $$awaitBlock(label, relation, fn, build_main, build_then, build_catch) {
940
+ function awaitBlock(label, relation, fn, build_main, build_then, build_catch) {
953
941
  let parentCD = current_cd, first, last, $cd, promise, destroyList, status = 0;
954
942
  $onDestroy(() => safeGroupCall(destroyList));
955
943
 
@@ -962,7 +950,7 @@ function $$awaitBlock(label, relation, fn, build_main, build_then, build_catch)
962
950
  cd_detach($cd);
963
951
  $cd = null;
964
952
  }
965
- $$removeElements(first, last);
953
+ removeElements(first, last);
966
954
  first = last = null;
967
955
  }
968
956
 
@@ -978,7 +966,7 @@ function $$awaitBlock(label, relation, fn, build_main, build_then, build_catch)
978
966
  } finally {
979
967
  current_destroyList = current_mountList = current_cd = null;
980
968
  }
981
- cd_attach2(parentCD, $cd);
969
+ cd_attach(parentCD, $cd);
982
970
  if($dom.nodeType == 11) {
983
971
  first = $dom.firstChild;
984
972
  last = $dom.lastChild;
@@ -1007,6 +995,9 @@ function $$awaitBlock(label, relation, fn, build_main, build_then, build_catch)
1007
995
  }, { value: [], cmp: keyComparator });
1008
996
  }
1009
997
 
998
+ const eachDefaultKey = (item, index, array) => isObject(array[0]) ? item : index;
999
+
1000
+
1010
1001
  const makeEachBlock = (fr, fn) => {
1011
1002
  return (item, index) => {
1012
1003
  let $dom = fr.cloneNode(true);
@@ -1035,7 +1026,7 @@ const makeEachElseBlock = (fn) => {
1035
1026
  first = $dom.firstChild;
1036
1027
  last = $dom.lastChild;
1037
1028
  } else first = last = $dom;
1038
- cd_attach2(parentCD, $cd);
1029
+ cd_attach(parentCD, $cd);
1039
1030
  if(onlyChild) label.appendChild($dom);
1040
1031
  else attachBlock(label, $dom);
1041
1032
  safeCallMount(current_mountList, destroyList);
@@ -1044,7 +1035,7 @@ const makeEachElseBlock = (fn) => {
1044
1035
  }
1045
1036
 
1046
1037
  return () => {
1047
- $$removeElements(first, last);
1038
+ removeElements(first, last);
1048
1039
  cd_detach($cd);
1049
1040
  safeGroupCall(destroyList);
1050
1041
  };
@@ -1055,7 +1046,7 @@ const makeEachElseBlock = (fn) => {
1055
1046
  function $$eachBlock(label, onlyChild, fn, getKey, bind, buildElseBlock) {
1056
1047
  let parentCD = current_cd;
1057
1048
  let eachCD = cd_new();
1058
- cd_attach(eachCD);
1049
+ cd_attach(parentCD, eachCD);
1059
1050
 
1060
1051
  let mapping = new Map();
1061
1052
  let lastNode, vi = 0, p_promise = 0, p_destroy = 0, elseBlock;
@@ -1109,7 +1100,7 @@ function $$eachBlock(label, onlyChild, fn, getKey, bind, buildElseBlock) {
1109
1100
  Promise.allSettled(destroyResults).then(() => removedNodes.forEach(n => n.remove()));
1110
1101
  } else {
1111
1102
  if(onlyChild) label.textContent = '';
1112
- else $$removeElements(label.nextSibling, lastNode);
1103
+ else removeElements(label.nextSibling, lastNode);
1113
1104
  }
1114
1105
 
1115
1106
  destroyResults = null;
@@ -1187,7 +1178,7 @@ function $$eachBlock(label, onlyChild, fn, getKey, bind, buildElseBlock) {
1187
1178
  current_destroyList = current_mountList = current_cd = null;
1188
1179
  }
1189
1180
  ctx = { $cd, rebind };
1190
- cd_attach2(eachCD, $cd);
1181
+ cd_attach(eachCD, $cd);
1191
1182
  if($dom.nodeType == 11) {
1192
1183
  ctx.first = $dom.firstChild;
1193
1184
  ctx.last = $dom.lastChild;
@@ -1209,7 +1200,7 @@ function $$eachBlock(label, onlyChild, fn, getKey, bind, buildElseBlock) {
1209
1200
  if(!array.length && !elseBlock && buildElseBlock) {
1210
1201
  elseBlock = buildElseBlock(label, onlyChild, parentCD);
1211
1202
  }
1212
- }, { cmp: $$compareArray });
1203
+ }, { cmp: compareArray });
1213
1204
  }
1214
1205
 
1215
1206
  const invokeSlotBase = ($component, slotName, $context, props, placeholder) => {
@@ -1242,7 +1233,7 @@ const makeSlot = (fr, fn) => {
1242
1233
  let $dom = fr.cloneNode(true), prev = current_cd;
1243
1234
  if(parentCD) {
1244
1235
  let $cd = current_cd = cd_new();
1245
- cd_attach2(parentCD, $cd);
1236
+ cd_attach(parentCD, $cd);
1246
1237
  $onDestroy(() => cd_detach($cd));
1247
1238
  cd_component(parentCD).$apply();
1248
1239
  } else current_cd = null;
@@ -1254,4 +1245,4 @@ const makeSlot = (fr, fn) => {
1254
1245
  };
1255
1246
  };
1256
1247
 
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 };
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, getFinalLabel, htmlBlock, htmlBlockStatic, htmlToFragment, htmlToFragmentClean, ifBlock, ifBlockReadOnly, insertAfter, 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, removeElementsBetween, removeItem, setClassToElement, spreadAttributes, svgToFragment, unwrapProps };