tutuca 0.9.65 → 0.9.67

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/dist/tutuca.js CHANGED
@@ -4640,49 +4640,67 @@ class Path {
4640
4640
  let handlers = null;
4641
4641
  let nodeIds = [];
4642
4642
  let isLeafComponent = true;
4643
+ const crossComponent = (cidNum, vid) => {
4644
+ const comp = comps.getComponentForId(cidNum);
4645
+ let pushStep = true;
4646
+ if (handlers === null && (isLeafComponent || bubbles)) {
4647
+ handlers = findHandlers(comp, eventIds, vid, eventName);
4648
+ if (handlers === null) {
4649
+ if (isLeafComponent && stopOnNoEvent && !bubbles)
4650
+ return false;
4651
+ } else if (!isLeafComponent) {
4652
+ pathSteps.length = 0;
4653
+ pendingDyns.length = 0;
4654
+ pushStep = false;
4655
+ }
4656
+ }
4657
+ isLeafComponent = false;
4658
+ for (const dyn of pendingDyns)
4659
+ dyn.interiorCids.add(cidNum);
4660
+ if (pushStep) {
4661
+ const step = resolvePathStep(comp, nodeIds, vid);
4662
+ if (step) {
4663
+ step._originCid = cidNum;
4664
+ pathSteps.push(step);
4665
+ if (step instanceof DynStep) {
4666
+ step.interiorCids.add(cidNum);
4667
+ pendingDyns.push(step);
4668
+ }
4669
+ }
4670
+ }
4671
+ for (let i = pendingDyns.length - 1;i >= 0; i--)
4672
+ if (pendingDyns[i].producerCompId === cidNum)
4673
+ pendingDyns.splice(i, 1);
4674
+ eventIds = [];
4675
+ nodeIds = [];
4676
+ return true;
4677
+ };
4643
4678
  while (node && node !== rootNode && depth < maxDepth) {
4644
4679
  if (node?.dataset) {
4645
- const { nid, si, sk } = parseMetaComment(node.previousSibling);
4646
4680
  const { eid, cid, vid } = node.dataset;
4647
4681
  if (eid !== undefined)
4648
4682
  eventIds.push(eid);
4649
- if (cid !== undefined) {
4650
- const cidNum = +cid;
4651
- const comp = comps.getComponentForId(cidNum);
4652
- let pushStep = true;
4653
- if (handlers === null && (isLeafComponent || bubbles)) {
4654
- handlers = findHandlers(comp, eventIds, vid, eventName);
4655
- if (handlers === null) {
4656
- if (isLeafComponent && stopOnNoEvent && !bubbles)
4657
- return NO_EVENT_INFO;
4658
- } else if (!isLeafComponent) {
4659
- pathSteps.length = 0;
4660
- pendingDyns.length = 0;
4661
- pushStep = false;
4662
- }
4663
- }
4664
- isLeafComponent = false;
4665
- for (const dyn of pendingDyns)
4666
- dyn.interiorCids.add(cidNum);
4667
- if (pushStep) {
4668
- const step = resolvePathStep(comp, nodeIds, vid);
4669
- if (step) {
4670
- step._originCid = cidNum;
4671
- pathSteps.push(step);
4672
- if (step instanceof DynStep) {
4673
- step.interiorCids.add(cidNum);
4674
- pendingDyns.push(step);
4675
- }
4683
+ const metas = metaChain(node.previousSibling);
4684
+ let sawComp = false;
4685
+ for (let i = 0;i < metas.length; i++) {
4686
+ const m = metas[i];
4687
+ if (m.$ === "Comp") {
4688
+ sawComp = true;
4689
+ if (!crossComponent(m.cid, m.vid))
4690
+ return NO_EVENT_INFO;
4691
+ const outer = metas[i + 1];
4692
+ if (outer?.$ === "Each" && outer.nid === m.nid) {
4693
+ nodeIds.push({ nid: outer.nid, si: outer.si, sk: outer.sk });
4694
+ i += 1;
4695
+ } else {
4696
+ nodeIds.push({ nid: m.nid });
4676
4697
  }
4698
+ } else {
4699
+ nodeIds.push({ nid: m.nid, si: m.si, sk: m.sk });
4677
4700
  }
4678
- for (let i = pendingDyns.length - 1;i >= 0; i--)
4679
- if (pendingDyns[i].producerCompId === cidNum)
4680
- pendingDyns.splice(i, 1);
4681
- eventIds = [];
4682
- nodeIds = [];
4683
4701
  }
4684
- if (nid !== undefined)
4685
- nodeIds.push({ nid, si, sk });
4702
+ if (!sawComp && cid !== undefined && !crossComponent(+cid, vid))
4703
+ return NO_EVENT_INFO;
4686
4704
  }
4687
4705
  depth += 1;
4688
4706
  node = node.parentNode;
@@ -4696,19 +4714,17 @@ class Path {
4696
4714
  return Path.fromNodeAndEventName(target, type, rNode, maxDepth, comps, stopOnNoEvent);
4697
4715
  }
4698
4716
  }
4699
- var EMPTY_META = {};
4700
- function parseMetaComment(n) {
4701
- if (n?.nodeType === 8 && n.textContent[0] === "§") {
4702
- const m = parseMetaComment(n.previousSibling);
4703
- if (m !== EMPTY_META)
4704
- return m;
4717
+ function metaChain(n) {
4718
+ const out = [];
4719
+ while (n?.nodeType === 8 && n.textContent[0] === "§") {
4705
4720
  try {
4706
- return JSON.parse(n.textContent.slice(1, -1));
4721
+ out.push(JSON.parse(n.textContent.slice(1, -1)));
4707
4722
  } catch (err) {
4708
4723
  console.warn(err, n);
4709
4724
  }
4725
+ n = n.previousSibling;
4710
4726
  }
4711
- return EMPTY_META;
4727
+ return out;
4712
4728
  }
4713
4729
  function findHandlers(comp, eventIds, vid, eventName) {
4714
4730
  for (const eid of eventIds) {
@@ -5529,40 +5545,49 @@ class RequestHandler {
5529
5545
  }
5530
5546
 
5531
5547
  // src/vdom.js
5532
- var isHtmlAttribute = (propName) => propName[4] === "-" && (propName[0] === "d" || propName[0] === "a");
5533
5548
  var HTML_NS = "http://www.w3.org/1999/xhtml";
5534
5549
  var isNamespaced = (node) => {
5535
5550
  const ns = node.namespaceURI;
5536
5551
  return ns !== null && ns !== HTML_NS;
5537
5552
  };
5538
- function applyProperties(node, props, previous) {
5553
+ var NEVER_ASSIGN = new Set([
5554
+ "width",
5555
+ "height",
5556
+ "href",
5557
+ "list",
5558
+ "form",
5559
+ "tabIndex",
5560
+ "download",
5561
+ "rowSpan",
5562
+ "colSpan",
5563
+ "role",
5564
+ "popover"
5565
+ ]);
5566
+ function applyProperties(node, props, _previous) {
5539
5567
  const namespaced = isNamespaced(node);
5540
- for (const propName in props) {
5541
- const propValue = props[propName];
5542
- if (propValue === undefined)
5543
- removeProperty(node, propName, previous);
5544
- else if (propName === "dangerouslySetInnerHTML")
5545
- node.innerHTML = propValue.__html ?? "";
5546
- else if (propName === "className")
5547
- node.setAttribute("class", propValue);
5548
- else if (namespaced || isHtmlAttribute(propName))
5549
- node.setAttribute(propName, propValue);
5568
+ for (const name in props)
5569
+ setProp2(node, name, props[name], namespaced);
5570
+ }
5571
+ function setProp2(node, name, value, namespaced) {
5572
+ if (name === "dangerouslySetInnerHTML") {
5573
+ if (value === undefined)
5574
+ node.replaceChildren();
5550
5575
  else
5551
- node[propName] = propValue;
5552
- }
5553
- }
5554
- function removeProperty(node, propName, previous) {
5555
- const previousValue = previous[propName];
5556
- if (propName === "dangerouslySetInnerHTML")
5557
- node.replaceChildren();
5558
- else if (propName === "className")
5559
- node.removeAttribute("class");
5560
- else if (propName === "htmlFor")
5561
- node.removeAttribute("for");
5562
- else if (isNamespaced(node) || typeof previousValue === "string" || isHtmlAttribute(propName))
5563
- node.removeAttribute(propName);
5576
+ node.innerHTML = value.__html ?? "";
5577
+ return;
5578
+ }
5579
+ if (typeof value === "function")
5580
+ return;
5581
+ if (!namespaced && !NEVER_ASSIGN.has(name) && name in node) {
5582
+ try {
5583
+ node[name] = value == null ? "" : value;
5584
+ return;
5585
+ } catch {}
5586
+ }
5587
+ if (value == null || value === false && name[4] !== "-")
5588
+ node.removeAttribute(name);
5564
5589
  else
5565
- node[propName] = null;
5590
+ node.setAttribute(name, value);
5566
5591
  }
5567
5592
 
5568
5593
  class VBase {
@@ -5834,22 +5859,12 @@ function h(tagName, properties, children, namespace) {
5834
5859
  if (properties) {
5835
5860
  for (const propName in properties) {
5836
5861
  const propVal = properties[propName];
5837
- switch (propName) {
5838
- case "key":
5839
- key = propVal;
5840
- break;
5841
- case "namespace":
5842
- namespace = namespace ?? propVal;
5843
- break;
5844
- case "class":
5845
- props.className = propVal;
5846
- break;
5847
- case "for":
5848
- props.htmlFor = propVal;
5849
- break;
5850
- default:
5851
- props[propName] = isHtmlAttribute(propName) ? String(propVal) : propVal;
5852
- }
5862
+ if (propName === "key")
5863
+ key = propVal;
5864
+ else if (propName === "namespace")
5865
+ namespace = namespace ?? propVal;
5866
+ else
5867
+ props[propName] = propVal;
5853
5868
  }
5854
5869
  }
5855
5870
  const c = tagName.charCodeAt(0);
@@ -6204,6 +6219,7 @@ class RenderViewId extends ANode {
6204
6219
  super(nodeId, val);
6205
6220
  this.viewId = viewId;
6206
6221
  }
6222
+ setDataAttr(_key, _val) {}
6207
6223
  }
6208
6224
 
6209
6225
  class RenderNode extends RenderViewId {
@@ -6280,6 +6296,7 @@ class RenderTextNode extends ANode {
6280
6296
  render(stack, _rx) {
6281
6297
  return this.val.eval(stack);
6282
6298
  }
6299
+ setDataAttr(_key, _val) {}
6283
6300
  }
6284
6301
 
6285
6302
  class RenderOnceNode extends BaseNode {
@@ -7649,7 +7666,12 @@ class Renderer {
7649
7666
  if (cachedNode)
7650
7667
  return cachedNode;
7651
7668
  const view = viewName ? comp.getView(viewName) : stack.lookupBestView(comp.views, "main");
7652
- const meta = this._renderMetadata({ $: "Comp", nid: node?.nodeId ?? null });
7669
+ const meta = this._renderMetadata({
7670
+ $: "Comp",
7671
+ nid: node?.nodeId ?? null,
7672
+ cid: comp.id,
7673
+ vid: view.name
7674
+ });
7653
7675
  const dom = new VFragment([meta, this.renderView(view, stack)]);
7654
7676
  this.cache.set(cachePath, cacheKey, dom);
7655
7677
  return dom;
@@ -8133,6 +8155,10 @@ function check(_app) {
8133
8155
  async function test(_opts) {
8134
8156
  return null;
8135
8157
  }
8158
+ function collectIterBindings() {
8159
+ console.warn("collectIterBindings is a no-op in the core tutuca build; use the tutuca-dev build for a functional implementation");
8160
+ return [];
8161
+ }
8136
8162
  function tutuca(nodeOrSelector) {
8137
8163
  const rootNode = typeof nodeOrSelector === "string" ? document.querySelector(nodeOrSelector) : nodeOrSelector;
8138
8164
  const comps = new Components;
@@ -8183,6 +8209,7 @@ export {
8183
8209
  fromJS,
8184
8210
  css,
8185
8211
  component,
8212
+ collectIterBindings,
8186
8213
  check,
8187
8214
  Stack,
8188
8215
  Set2 as Set,