malinajs 0.7.2-a7 → 0.7.2-a8

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 (3) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/malina.js +49 -27
  3. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -16,6 +16,7 @@
16
16
  * refactoring $onMount
17
17
  * optional deep checking for passed props: prop={value} prop|deep={value}
18
18
  * keep-alive
19
+ * malina:self
19
20
 
20
21
  ## 0.6.x
21
22
 
package/malina.js CHANGED
@@ -2187,7 +2187,13 @@
2187
2187
  if(n.name == 'malina' && !option.malinaElement) {
2188
2188
  let b;
2189
2189
  if(n.elArg == 'portal') b = this.attachPortal(n);
2190
- else b = this.attachHead(n);
2190
+ else if(['window', 'body', 'head'].includes(n.elArg)) b = this.attachHead(n);
2191
+ else if(n.elArg == 'self') {
2192
+ this.glob.$$selfComponent.$value();
2193
+ const label = requireLabel();
2194
+ let component = this.makeComponent(n, {self: true});
2195
+ binds.push(insertComponent(component, label));
2196
+ } else throw 'Wrong tag';
2191
2197
  b && binds.push(b);
2192
2198
  return;
2193
2199
  }
@@ -2207,23 +2213,7 @@
2207
2213
  } else {
2208
2214
  const label = requireLabel();
2209
2215
  let component = this.makeComponent(n);
2210
- binds.push(xNode('insert-component', {
2211
- component: component.bind,
2212
- reference: component.reference,
2213
- label
2214
- }, (ctx, n) => {
2215
- if(n.reference) {
2216
- ctx.write(true, `${n.reference} = `);
2217
- ctx.add(n.component);
2218
- if(n.label.node) ctx.write(true, `$runtime.insertBlock(${n.label.name}, ${n.reference});`);
2219
- else ctx.write(true, `$runtime.addBlock(${n.label.name}, ${n.reference});`);
2220
- } else {
2221
- if(n.label.node) ctx.write(true, `$runtime.insertBlock(${n.label.name}, `);
2222
- else ctx.write(true, `$runtime.addBlock(${n.label.name}, `);
2223
- ctx.add(n.component);
2224
- ctx.write(');');
2225
- }
2226
- }));
2216
+ binds.push(insertComponent(component, label));
2227
2217
  }
2228
2218
  } else {
2229
2219
  if(isRoot) requireFragment = true;
@@ -2644,6 +2634,26 @@
2644
2634
  throw e;
2645
2635
  }
2646
2636
 
2637
+ function insertComponent(component, label) {
2638
+ return xNode('insert-component', {
2639
+ component: component.bind,
2640
+ reference: component.reference,
2641
+ label
2642
+ }, (ctx, n) => {
2643
+ if(n.reference) {
2644
+ ctx.write(true, `${n.reference} = `);
2645
+ ctx.add(n.component);
2646
+ if(n.label.node) ctx.write(true, `$runtime.insertBlock(${n.label.name}, ${n.reference});`);
2647
+ else ctx.write(true, `$runtime.addBlock(${n.label.name}, ${n.reference});`);
2648
+ } else {
2649
+ if(n.label.node) ctx.write(true, `$runtime.insertBlock(${n.label.name}, `);
2650
+ else ctx.write(true, `$runtime.addBlock(${n.label.name}, `);
2651
+ ctx.add(n.component);
2652
+ ctx.write(');');
2653
+ }
2654
+ })
2655
+ }
2656
+
2647
2657
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
2648
2658
 
2649
2659
  function createCommonjsModule(fn, basedir, module) {
@@ -4882,7 +4892,7 @@
4882
4892
  return result;
4883
4893
  };
4884
4894
 
4885
- function makeComponent(node) {
4895
+ function makeComponent(node, option={}) {
4886
4896
  let propList = node.attributes;
4887
4897
 
4888
4898
  this.require('$context');
@@ -4892,8 +4902,8 @@
4892
4902
  let slotBlocks = [];
4893
4903
  let anchorBlocks = [];
4894
4904
 
4895
- let componentName = node.name;
4896
- if(componentName != 'component' && this.config.autoimport) {
4905
+ let componentName = option.self ? '$$selfComponent' : node.name;
4906
+ if(componentName != 'component' && this.config.autoimport && !option.self) {
4897
4907
  let imported = this.script.autoimport[componentName] || this.script.importedNames.includes(componentName) ||
4898
4908
  this.script.rootVariables[componentName] || this.script.rootFunctions[componentName];
4899
4909
 
@@ -6750,7 +6760,7 @@
6750
6760
  });
6751
6761
  }
6752
6762
 
6753
- const version = '0.7.2-a7';
6763
+ const version = '0.7.2-a8';
6754
6764
 
6755
6765
 
6756
6766
  async function compile(source, config = {}) {
@@ -6805,7 +6815,8 @@
6805
6815
  rootCD: xNode('root-cd', false),
6806
6816
  apply: xNode('apply', false),
6807
6817
  componentFn: xNode('componentFn', false),
6808
- $onMount: xNode('$onMount', false)
6818
+ $onMount: xNode('$onMount', false),
6819
+ $$selfComponent: xNode('$$selfComponent', false)
6809
6820
  },
6810
6821
  require: function(...args) {
6811
6822
  for(let name of args) {
@@ -6902,10 +6913,21 @@
6902
6913
  $compile: [ctx.module.head, ctx.module.code, ctx.module.body, ctx.glob.rootCD],
6903
6914
  name: config.name,
6904
6915
  componentFn: ctx.glob.componentFn
6905
- }, (ctx, n) => {
6906
- if(config.exportDefault) ctx.write(true, 'export default ');
6907
- else ctx.write(true, `const ${n.name} = `);
6908
- ctx.add(n.componentFn);
6916
+ }, (ctx2, n) => {
6917
+ if(config.exportDefault) {
6918
+ if(ctx.glob.$$selfComponent.value) {
6919
+ ctx2.write(true, 'const $$selfComponent = ');
6920
+ ctx2.add(n.componentFn);
6921
+ ctx2.write(true, 'export default $$selfComponent;');
6922
+ } else {
6923
+ ctx2.write(true, 'export default ');
6924
+ ctx2.add(n.componentFn);
6925
+ }
6926
+ } else {
6927
+ assert(!ctx.glob.$$selfComponent.value, 'Not supported');
6928
+ ctx2.write(true, `const ${n.name} = `);
6929
+ ctx2.add(n.componentFn);
6930
+ }
6909
6931
  }));
6910
6932
 
6911
6933
  ctx.result = xBuild(result);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "malinajs",
3
- "version": "0.7.2-a7",
3
+ "version": "0.7.2-a8",
4
4
  "license": "MIT",
5
5
  "scripts": {
6
6
  "prepare": "npm run build",