malinajs 0.7.12 → 0.7.14

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.
Files changed (2) hide show
  1. package/malina.js +79 -46
  2. package/package.json +1 -1
package/malina.js CHANGED
@@ -21,7 +21,7 @@
21
21
  let prev = current_context;
22
22
  try {
23
23
  current_context = context;
24
- return fn();
24
+ return fn.call(context);
25
25
  } finally {
26
26
  current_context = prev;
27
27
  }
@@ -406,6 +406,18 @@
406
406
  xNode(data, handler)
407
407
  xNode(handler)
408
408
  xNode(xNode, data, handler)
409
+
410
+ $wait - wait for a node be processed
411
+ $hold - hold a node from processing
412
+
413
+ xNode('name', {
414
+ $wait: ['apply', 'rootCD', anotherNode],
415
+ $hold: ['apply', 'anotherNode']
416
+ }, (ctx, node) => {
417
+ this.inuse.apply // check if apply is used
418
+ this.inuse.rootCD // check if rootCD is used
419
+ node.$wait[0].value // check value of first node in $wait
420
+ })
409
421
  */
410
422
  if(_type instanceof xNode) {
411
423
  let n = _type;
@@ -598,14 +610,10 @@
598
610
  });
599
611
  }
600
612
 
601
- let className = {};
602
- node.class.forEach(sel => {
603
- if(sel.$selector) sel = get_context().css.resolve(sel);
604
- className[sel] = true;
605
- });
606
- className = Object.keys(className).join(' ');
607
- if(className) ctx.write(` class="${className}"`);
608
-
613
+ if (node.class.size) {
614
+ ctx.add(get_context().css.resolveAsNode(node.class, [' class="', '"']));
615
+ }
616
+
609
617
  if(node.children.length) {
610
618
  ctx.write('>');
611
619
  node.children.forEach(n => ctx.build(n));
@@ -2360,13 +2368,13 @@
2360
2368
  ctx.writeLine(`${elName}.setAttribute('${a.name}', \`${Q(a.value)}\`);`);
2361
2369
  });
2362
2370
  }));
2371
+
2363
2372
  binds.push(xNode('bindClasses', { el }, (ctx, n) => {
2364
2373
  let el = n.el;
2374
+ if (!el.class.size) return;
2365
2375
  let elName = el.bindName();
2366
- if(el.class.size) {
2367
- let className = Array.from(el.class.values()).join(' ');
2368
- ctx.writeLine(`${elName}.className += ' ${className}';`);
2369
- }
2376
+ ctx.add(this.css.resolveAsNode(el.class, [`${elName}.className += ' `, `';`]));
2377
+ ctx.write(true);
2370
2378
  }));
2371
2379
  }
2372
2380
  bindTail.forEach(b => binds.push(b));
@@ -4827,6 +4835,18 @@
4827
4835
  return sel.local;
4828
4836
  };
4829
4837
 
4838
+ self.resolveAsNode = function(classList, wrap) {
4839
+ return xNode('resolve-class', { classList, wrap }, (ctx, n) => {
4840
+ let className = {};
4841
+ n.classList.forEach(sel => {
4842
+ if(sel.$selector) sel = this.resolve(sel);
4843
+ className[sel] = true;
4844
+ });
4845
+ className = Object.keys(className).join(' ');
4846
+ if(className) ctx.write(`${n.wrap[0]}${className}${n.wrap[1]}`);
4847
+ });
4848
+ };
4849
+
4830
4850
  self.getContent = function() {
4831
4851
  removeBlocks.forEach(node => {
4832
4852
  let i = node.parent.children.indexOf(node);
@@ -5109,8 +5129,7 @@
5109
5129
  if(name[0] == '#') {
5110
5130
  assert(!value, 'Wrong ref');
5111
5131
  name = name.substring(1);
5112
- assert(isSimpleName(name), name);
5113
- this.checkRootName(name);
5132
+ assert(detectExpressionType(name) == 'identifier', name);
5114
5133
  reference = name;
5115
5134
  return;
5116
5135
  } else if(name[0] == ':' || name.startsWith('bind:')) {
@@ -6017,19 +6036,26 @@
6017
6036
  if(block.singleBlock) {
6018
6037
  itemBlock = xNode('each-component', {
6019
6038
  block: block.singleBlock,
6039
+ reference: block.reference,
6020
6040
  rebind,
6021
6041
  itemName,
6022
6042
  indexName
6023
6043
  }, (ctx, n) => {
6024
6044
  ctx.write(`$runtime.makeEachSingleBlock((${n.itemName}`);
6025
- if(n.indexName) ctx.write(`, ${n.indexName}`);
6045
+ if (n.indexName) ctx.write(`, ${n.indexName}`);
6026
6046
  ctx.write(') => [');
6027
6047
  ctx.indent++;
6028
6048
  ctx.write(true);
6029
- if(n.rebind) ctx.add(n.rebind);
6049
+ if (n.rebind) ctx.add(n.rebind);
6030
6050
  else ctx.write('null');
6031
6051
  ctx.write(',', true);
6032
- ctx.add(n.block);
6052
+ if (n.reference) {
6053
+ ctx.write(true, `(${n.reference} = `);
6054
+ ctx.add(n.block);
6055
+ ctx.write(')', true);
6056
+ } else {
6057
+ ctx.add(n.block);
6058
+ }
6033
6059
  ctx.indent--;
6034
6060
  ctx.write(true, '])');
6035
6061
  });
@@ -6458,13 +6484,20 @@
6458
6484
  ctx.add(n.slot.template);
6459
6485
  ctx.write(')');
6460
6486
  } else {
6461
- ctx.write('$runtime.makeBlockBound(');
6462
- ctx.add(n.slot.template);
6463
- ctx.write(', ($parentElement) => {', true);
6464
- ctx.indent++;
6465
- ctx.add(n.slot.source);
6466
- ctx.indent--;
6467
- ctx.write(true, '})');
6487
+ ctx.add(xNode('make-block', {
6488
+ $wait: ['apply'],
6489
+ template: n.slot.template,
6490
+ source: n.slot.source
6491
+ }, (ctx, n) => {
6492
+ if(this.inuse.apply) ctx.write('$runtime.makeBlockBound(');
6493
+ else ctx.write('$runtime.makeBlock(');
6494
+ ctx.add(n.template);
6495
+ ctx.write(', ($parentElement) => {', true);
6496
+ ctx.indent++;
6497
+ ctx.add(n.source);
6498
+ ctx.indent--;
6499
+ ctx.write(true, '})');
6500
+ }));
6468
6501
  }
6469
6502
  } else missed = ', null';
6470
6503
 
@@ -6854,7 +6887,7 @@
6854
6887
  });
6855
6888
  }
6856
6889
 
6857
- const version = '0.7.12';
6890
+ const version = '0.7.14';
6858
6891
 
6859
6892
 
6860
6893
  async function compile(source, config = {}) {
@@ -6958,7 +6991,7 @@
6958
6991
  }
6959
6992
  };
6960
6993
 
6961
- use_context(ctx, () => setup.call(ctx));
6994
+ use_context(ctx, setup);
6962
6995
 
6963
6996
  await hook(ctx, 'dom:before');
6964
6997
  ctx.parseHTML();
@@ -6985,7 +7018,7 @@
6985
7018
  await hook(ctx, 'js:before');
6986
7019
  ctx.js_parse();
6987
7020
  await hook(ctx, 'js');
6988
- use_context(ctx, () => ctx.js_transform());
7021
+ use_context(ctx, ctx.js_transform);
6989
7022
  await hook(ctx, 'js:after');
6990
7023
 
6991
7024
  await hook(ctx, 'css:before');
@@ -6994,38 +7027,38 @@
6994
7027
  await hook(ctx, 'css');
6995
7028
 
6996
7029
  await hook(ctx, 'runtime:before');
6997
- use_context(ctx, () => ctx.buildRuntime());
7030
+ use_context(ctx, ctx.buildRuntime);
6998
7031
  await hook(ctx, 'runtime');
6999
7032
 
7000
7033
  await hook(ctx, 'build:before');
7001
7034
 
7002
- use_context(ctx, () => {
7003
- const result = ctx.result = xNode('block');
7035
+ use_context(ctx, function() {
7036
+ const result = this.result = xNode('block');
7004
7037
  result.push('import * as $runtime from \'malinajs/runtime.js\';');
7005
7038
  result.push('import { $watch, $tick } from \'malinajs/runtime.js\';');
7006
- result.push(ctx.module.top);
7039
+ result.push(this.module.top);
7007
7040
  result.push(xNode('componentFn-wrapper', {
7008
- $compile: [ctx.module.head, ctx.module.code, ctx.module.body, ctx.glob.rootCD],
7041
+ $compile: [this.module.head, this.module.code, this.module.body, this.glob.rootCD],
7009
7042
  name: config.name,
7010
- componentFn: ctx.glob.componentFn
7011
- }, (ctx2, n) => {
7043
+ componentFn: this.glob.componentFn
7044
+ }, (ctx, n) => {
7012
7045
  if(config.exportDefault) {
7013
- if(ctx.glob.$$selfComponent.value) {
7014
- ctx2.write(true, 'const $$selfComponent = ');
7015
- ctx2.add(n.componentFn);
7016
- ctx2.write(true, 'export default $$selfComponent;');
7046
+ if(this.glob.$$selfComponent.value) {
7047
+ ctx.write(true, 'const $$selfComponent = ');
7048
+ ctx.add(n.componentFn);
7049
+ ctx.write(true, 'export default $$selfComponent;');
7017
7050
  } else {
7018
- ctx2.write(true, 'export default ');
7019
- ctx2.add(n.componentFn);
7051
+ ctx.write(true, 'export default ');
7052
+ ctx.add(n.componentFn);
7020
7053
  }
7021
7054
  } else {
7022
- assert(!ctx.glob.$$selfComponent.value, 'Not supported');
7023
- ctx2.write(true, `const ${n.name} = `);
7024
- ctx2.add(n.componentFn);
7055
+ assert(!this.glob.$$selfComponent.value, 'Not supported');
7056
+ ctx.write(true, `const ${n.name} = `);
7057
+ ctx.add(n.componentFn);
7025
7058
  }
7026
7059
  }));
7027
7060
 
7028
- ctx.result = xBuild(result);
7061
+ this.result = xBuild(result);
7029
7062
  });
7030
7063
 
7031
7064
  await hook(ctx, 'build');
@@ -7036,7 +7069,7 @@
7036
7069
  async function hook(ctx, name) {
7037
7070
  for(let i = 0; i < ctx.config.plugins.length; i++) {
7038
7071
  const fn = ctx.config.plugins[i][name];
7039
- if(fn) await use_context(ctx, () => fn(ctx));
7072
+ if(fn) await use_context(ctx, () => fn.call(ctx, ctx));
7040
7073
  }
7041
7074
  }
7042
7075
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "malinajs",
3
- "version": "0.7.12",
3
+ "version": "0.7.14",
4
4
  "license": "MIT",
5
5
  "scripts": {
6
6
  "build": "npm run build_runtime && rollup -c",