malinajs 0.7.2-a10 → 0.7.2-a11

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/malina.js +12 -7
  2. package/package.json +1 -1
  3. package/runtime.js +21 -9
package/malina.js CHANGED
@@ -1293,7 +1293,12 @@
1293
1293
  }
1294
1294
  });
1295
1295
  result = '`' + result.map(p => p.type == 'text' ? Q(p.value) : '${' + p.value + '}').join('') + '`';
1296
- return { result, parts, staticText };
1296
+ return {
1297
+ result,
1298
+ parts,
1299
+ staticText,
1300
+ binding: parts.length == 1 && parts[0].type == 'exp' ? parts[0].value : null
1301
+ };
1297
1302
  }
1298
1303
 
1299
1304
 
@@ -1379,7 +1384,7 @@
1379
1384
  const value = raw.substring(1, raw.length - 1);
1380
1385
  result.push({name, value, raw, content: r.sub(start)});
1381
1386
  } else {
1382
- const value = r.readIf(/^\S+/);
1387
+ const value = r.readIf(/^[^\s<>]+/);
1383
1388
  result.push({name, value, raw: value, content: r.sub(start)});
1384
1389
  }
1385
1390
  } else {
@@ -5727,13 +5732,13 @@
5727
5732
 
5728
5733
  if(node.spreading) return node.spreading.push(`${name}: ${exp}`);
5729
5734
 
5730
- if(node.name == 'option' && name == 'value') {
5735
+ if(node.name == 'option' && name == 'value' && parsed.binding) {
5731
5736
  return {
5732
5737
  bind: xNode('bindOptionValue', {
5733
5738
  el: element.bindName(),
5734
- exp
5739
+ value: parsed.binding
5735
5740
  }, (ctx, n) => {
5736
- ctx.write(true, `$runtime.selectOption(${n.el}, () => (${n.exp}));`);
5741
+ ctx.write(true, `$runtime.selectOption(${n.el}, () => (${n.value}));`);
5737
5742
  })
5738
5743
  }
5739
5744
  }
@@ -5754,7 +5759,7 @@
5754
5759
  let n = xNode('bindAttribute', {
5755
5760
  $wait: ['apply'],
5756
5761
  name,
5757
- exp,
5762
+ exp: propList[name] && parsed.binding ? parsed.binding : exp,
5758
5763
  hasElement,
5759
5764
  el: element.bindName()
5760
5765
  }, (ctx, data) => {
@@ -6828,7 +6833,7 @@
6828
6833
  });
6829
6834
  }
6830
6835
 
6831
- const version = '0.7.2-a10';
6836
+ const version = '0.7.2-a11';
6832
6837
 
6833
6838
 
6834
6839
  async function compile(source, config = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "malinajs",
3
- "version": "0.7.2-a10",
3
+ "version": "0.7.2-a11",
4
4
  "license": "MIT",
5
5
  "scripts": {
6
6
  "prepare": "npm run build",
package/runtime.js CHANGED
@@ -1287,19 +1287,31 @@ const keepAlive = (store, keyFn, builder) => {
1287
1287
 
1288
1288
  const selectElement = (el, getter, setter) => {
1289
1289
  addEvent(el, 'change', () => {
1290
- let op = el.querySelector(':checked');
1291
- if(op?.$$value) {
1292
- let value = op.$$value();
1293
- setter(value);
1294
- w.value = value;
1295
- }
1290
+ let value = [];
1291
+ el.querySelectorAll(':checked').forEach(o => {
1292
+ value.push(o.$$value ? o.$$value() : o.value);
1293
+ });
1294
+ value = el.multiple ? value : value[0];
1295
+ setter(value);
1296
+ w.value = value;
1296
1297
  });
1297
1298
  const update = () => {
1298
- for(let op of el.options) {
1299
- if(op.$$value?.() === w.value) {
1300
- op.selected = true;
1299
+ let value = w.value;
1300
+ if(el.multiple) {
1301
+ if(isArray(value)) {
1302
+ for(let o of el.options) {
1303
+ const option_value = o.$$value ? o.$$value() : o.value;
1304
+ o.selected = value.indexOf(option_value) != -1;
1305
+ }
1301
1306
  return;
1302
1307
  }
1308
+ } else {
1309
+ for(let o of el.options) {
1310
+ if((o.$$value ? o.$$value() : o.value) === value) {
1311
+ o.selected = true;
1312
+ return;
1313
+ }
1314
+ }
1303
1315
  }
1304
1316
  el.selectedIndex = -1;
1305
1317
  };