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.
@@ -4344,49 +4344,67 @@ class Path {
4344
4344
  let handlers = null;
4345
4345
  let nodeIds = [];
4346
4346
  let isLeafComponent = true;
4347
+ const crossComponent = (cidNum, vid) => {
4348
+ const comp = comps.getComponentForId(cidNum);
4349
+ let pushStep = true;
4350
+ if (handlers === null && (isLeafComponent || bubbles)) {
4351
+ handlers = findHandlers(comp, eventIds, vid, eventName);
4352
+ if (handlers === null) {
4353
+ if (isLeafComponent && stopOnNoEvent && !bubbles)
4354
+ return false;
4355
+ } else if (!isLeafComponent) {
4356
+ pathSteps.length = 0;
4357
+ pendingDyns.length = 0;
4358
+ pushStep = false;
4359
+ }
4360
+ }
4361
+ isLeafComponent = false;
4362
+ for (const dyn of pendingDyns)
4363
+ dyn.interiorCids.add(cidNum);
4364
+ if (pushStep) {
4365
+ const step = resolvePathStep(comp, nodeIds, vid);
4366
+ if (step) {
4367
+ step._originCid = cidNum;
4368
+ pathSteps.push(step);
4369
+ if (step instanceof DynStep) {
4370
+ step.interiorCids.add(cidNum);
4371
+ pendingDyns.push(step);
4372
+ }
4373
+ }
4374
+ }
4375
+ for (let i = pendingDyns.length - 1;i >= 0; i--)
4376
+ if (pendingDyns[i].producerCompId === cidNum)
4377
+ pendingDyns.splice(i, 1);
4378
+ eventIds = [];
4379
+ nodeIds = [];
4380
+ return true;
4381
+ };
4347
4382
  while (node && node !== rootNode && depth < maxDepth) {
4348
4383
  if (node?.dataset) {
4349
- const { nid, si, sk } = parseMetaComment(node.previousSibling);
4350
4384
  const { eid, cid, vid } = node.dataset;
4351
4385
  if (eid !== undefined)
4352
4386
  eventIds.push(eid);
4353
- if (cid !== undefined) {
4354
- const cidNum = +cid;
4355
- const comp = comps.getComponentForId(cidNum);
4356
- let pushStep = true;
4357
- if (handlers === null && (isLeafComponent || bubbles)) {
4358
- handlers = findHandlers(comp, eventIds, vid, eventName);
4359
- if (handlers === null) {
4360
- if (isLeafComponent && stopOnNoEvent && !bubbles)
4361
- return NO_EVENT_INFO;
4362
- } else if (!isLeafComponent) {
4363
- pathSteps.length = 0;
4364
- pendingDyns.length = 0;
4365
- pushStep = false;
4366
- }
4367
- }
4368
- isLeafComponent = false;
4369
- for (const dyn of pendingDyns)
4370
- dyn.interiorCids.add(cidNum);
4371
- if (pushStep) {
4372
- const step = resolvePathStep(comp, nodeIds, vid);
4373
- if (step) {
4374
- step._originCid = cidNum;
4375
- pathSteps.push(step);
4376
- if (step instanceof DynStep) {
4377
- step.interiorCids.add(cidNum);
4378
- pendingDyns.push(step);
4379
- }
4387
+ const metas = metaChain(node.previousSibling);
4388
+ let sawComp = false;
4389
+ for (let i = 0;i < metas.length; i++) {
4390
+ const m = metas[i];
4391
+ if (m.$ === "Comp") {
4392
+ sawComp = true;
4393
+ if (!crossComponent(m.cid, m.vid))
4394
+ return NO_EVENT_INFO;
4395
+ const outer = metas[i + 1];
4396
+ if (outer?.$ === "Each" && outer.nid === m.nid) {
4397
+ nodeIds.push({ nid: outer.nid, si: outer.si, sk: outer.sk });
4398
+ i += 1;
4399
+ } else {
4400
+ nodeIds.push({ nid: m.nid });
4380
4401
  }
4402
+ } else {
4403
+ nodeIds.push({ nid: m.nid, si: m.si, sk: m.sk });
4381
4404
  }
4382
- for (let i = pendingDyns.length - 1;i >= 0; i--)
4383
- if (pendingDyns[i].producerCompId === cidNum)
4384
- pendingDyns.splice(i, 1);
4385
- eventIds = [];
4386
- nodeIds = [];
4387
4405
  }
4388
- if (nid !== undefined)
4389
- nodeIds.push({ nid, si, sk });
4406
+ if (!sawComp && cid !== undefined && !crossComponent(+cid, vid))
4407
+ return NO_EVENT_INFO;
4390
4408
  }
4391
4409
  depth += 1;
4392
4410
  node = node.parentNode;
@@ -4400,18 +4418,17 @@ class Path {
4400
4418
  return Path.fromNodeAndEventName(target, type, rNode, maxDepth, comps, stopOnNoEvent);
4401
4419
  }
4402
4420
  }
4403
- function parseMetaComment(n) {
4404
- if (n?.nodeType === 8 && n.textContent[0] === "§") {
4405
- const m = parseMetaComment(n.previousSibling);
4406
- if (m !== EMPTY_META)
4407
- return m;
4421
+ function metaChain(n) {
4422
+ const out = [];
4423
+ while (n?.nodeType === 8 && n.textContent[0] === "§") {
4408
4424
  try {
4409
- return JSON.parse(n.textContent.slice(1, -1));
4425
+ out.push(JSON.parse(n.textContent.slice(1, -1)));
4410
4426
  } catch (err) {
4411
4427
  console.warn(err, n);
4412
4428
  }
4429
+ n = n.previousSibling;
4413
4430
  }
4414
- return EMPTY_META;
4431
+ return out;
4415
4432
  }
4416
4433
  function findHandlers(comp, eventIds, vid, eventName) {
4417
4434
  for (const eid of eventIds) {
@@ -4486,7 +4503,7 @@ class PathBuilder {
4486
4503
  return this.add(new SeqStep(name, key));
4487
4504
  }
4488
4505
  }
4489
- var NONE, BindStep, FieldStep, SeqStep, SeqAccessStep, EachBindStep, EachRenderItStep, DynStep, DynEachStep, EMPTY_META, NO_EVENT_INFO, BUBBLING_EVENTS;
4506
+ var NONE, BindStep, FieldStep, SeqStep, SeqAccessStep, EachBindStep, EachRenderItStep, DynStep, DynEachStep, NO_EVENT_INFO, BUBBLING_EVENTS;
4490
4507
  var init_path = __esm(() => {
4491
4508
  NONE = Symbol("NONE");
4492
4509
  BindStep = class BindStep extends Step {
@@ -4634,7 +4651,6 @@ var init_path = __esm(() => {
4634
4651
  return producerSteps.slice(0, -1).concat(new SeqStep(last.field, key));
4635
4652
  }
4636
4653
  };
4637
- EMPTY_META = {};
4638
4654
  NO_EVENT_INFO = [null, null];
4639
4655
  BUBBLING_EVENTS = new Set(["drop"]);
4640
4656
  });
@@ -5351,34 +5367,31 @@ var init_attribute = __esm(() => {
5351
5367
  });
5352
5368
 
5353
5369
  // src/vdom.js
5354
- function applyProperties(node, props, previous) {
5370
+ function applyProperties(node, props, _previous) {
5355
5371
  const namespaced = isNamespaced(node);
5356
- for (const propName in props) {
5357
- const propValue = props[propName];
5358
- if (propValue === undefined)
5359
- removeProperty(node, propName, previous);
5360
- else if (propName === "dangerouslySetInnerHTML")
5361
- node.innerHTML = propValue.__html ?? "";
5362
- else if (propName === "className")
5363
- node.setAttribute("class", propValue);
5364
- else if (namespaced || isHtmlAttribute(propName))
5365
- node.setAttribute(propName, propValue);
5372
+ for (const name in props)
5373
+ setProp2(node, name, props[name], namespaced);
5374
+ }
5375
+ function setProp2(node, name, value, namespaced) {
5376
+ if (name === "dangerouslySetInnerHTML") {
5377
+ if (value === undefined)
5378
+ node.replaceChildren();
5366
5379
  else
5367
- node[propName] = propValue;
5368
- }
5369
- }
5370
- function removeProperty(node, propName, previous) {
5371
- const previousValue = previous[propName];
5372
- if (propName === "dangerouslySetInnerHTML")
5373
- node.replaceChildren();
5374
- else if (propName === "className")
5375
- node.removeAttribute("class");
5376
- else if (propName === "htmlFor")
5377
- node.removeAttribute("for");
5378
- else if (isNamespaced(node) || typeof previousValue === "string" || isHtmlAttribute(propName))
5379
- node.removeAttribute(propName);
5380
+ node.innerHTML = value.__html ?? "";
5381
+ return;
5382
+ }
5383
+ if (typeof value === "function")
5384
+ return;
5385
+ if (!namespaced && !NEVER_ASSIGN.has(name) && name in node) {
5386
+ try {
5387
+ node[name] = value == null ? "" : value;
5388
+ return;
5389
+ } catch {}
5390
+ }
5391
+ if (value == null || value === false && name[4] !== "-")
5392
+ node.removeAttribute(name);
5380
5393
  else
5381
- node[propName] = null;
5394
+ node.setAttribute(name, value);
5382
5395
  }
5383
5396
 
5384
5397
  class VBase {
@@ -5548,22 +5561,12 @@ function h(tagName, properties, children, namespace) {
5548
5561
  if (properties) {
5549
5562
  for (const propName in properties) {
5550
5563
  const propVal = properties[propName];
5551
- switch (propName) {
5552
- case "key":
5553
- key = propVal;
5554
- break;
5555
- case "namespace":
5556
- namespace = namespace ?? propVal;
5557
- break;
5558
- case "class":
5559
- props.className = propVal;
5560
- break;
5561
- case "for":
5562
- props.htmlFor = propVal;
5563
- break;
5564
- default:
5565
- props[propName] = isHtmlAttribute(propName) ? String(propVal) : propVal;
5566
- }
5564
+ if (propName === "key")
5565
+ key = propVal;
5566
+ else if (propName === "namespace")
5567
+ namespace = namespace ?? propVal;
5568
+ else
5569
+ props[propName] = propVal;
5567
5570
  }
5568
5571
  }
5569
5572
  const c = tagName.charCodeAt(0);
@@ -5572,11 +5575,24 @@ function h(tagName, properties, children, namespace) {
5572
5575
  addChild(normalizedChildren, children);
5573
5576
  return new VNode2(tag, props, normalizedChildren, key, namespace);
5574
5577
  }
5575
- var isHtmlAttribute = (propName) => propName[4] === "-" && (propName[0] === "d" || propName[0] === "a"), HTML_NS = "http://www.w3.org/1999/xhtml", isNamespaced = (node) => {
5578
+ var HTML_NS = "http://www.w3.org/1999/xhtml", isNamespaced = (node) => {
5576
5579
  const ns = node.namespaceURI;
5577
5580
  return ns !== null && ns !== HTML_NS;
5578
- }, getKey = (child) => child instanceof VNode2 ? child.key : undefined, isIterable = (obj) => obj != null && typeof obj !== "string" && typeof obj[Symbol.iterator] === "function", VText, VComment, VFragment, VNode2;
5581
+ }, NEVER_ASSIGN, getKey = (child) => child instanceof VNode2 ? child.key : undefined, isIterable = (obj) => obj != null && typeof obj !== "string" && typeof obj[Symbol.iterator] === "function", VText, VComment, VFragment, VNode2;
5579
5582
  var init_vdom = __esm(() => {
5583
+ NEVER_ASSIGN = new Set([
5584
+ "width",
5585
+ "height",
5586
+ "href",
5587
+ "list",
5588
+ "form",
5589
+ "tabIndex",
5590
+ "download",
5591
+ "rowSpan",
5592
+ "colSpan",
5593
+ "role",
5594
+ "popover"
5595
+ ]);
5580
5596
  VText = class VText extends VBase {
5581
5597
  constructor(text) {
5582
5598
  super();
@@ -6177,6 +6193,7 @@ var init_anode = __esm(() => {
6177
6193
  super(nodeId, val);
6178
6194
  this.viewId = viewId;
6179
6195
  }
6196
+ setDataAttr(_key, _val) {}
6180
6197
  };
6181
6198
  RenderNode = class RenderNode extends RenderViewId {
6182
6199
  render(stack, rx) {
@@ -6249,6 +6266,7 @@ var init_anode = __esm(() => {
6249
6266
  render(stack, _rx) {
6250
6267
  return this.val.eval(stack);
6251
6268
  }
6269
+ setDataAttr(_key, _val) {}
6252
6270
  };
6253
6271
  RenderOnceNode = class RenderOnceNode extends BaseNode {
6254
6272
  constructor(node) {
@@ -8662,6 +8680,7 @@ function classifyBadValue(value) {
8662
8680
  function checkComponent(Comp, lx = new LintContext, { wellKnownExtras = EMPTY_SET2 } = {}) {
8663
8681
  return lx.push({ componentName: Comp.name }, () => {
8664
8682
  checkUnknownSpecKeys(lx, Comp, wellKnownExtras);
8683
+ checkFieldDeclarations(lx, Comp);
8665
8684
  const referencedAlters = new Set;
8666
8685
  const referencedInputs = new Set;
8667
8686
  const referencedDynamics = new Set;
@@ -9056,6 +9075,31 @@ function checkUnknownSpecKeys(lx, Comp, wellKnownExtras) {
9056
9075
  lx.warn(UNKNOWN_COMPONENT_SPEC_KEY, { key }, replaceNameSuggestion(key, candidates));
9057
9076
  }
9058
9077
  }
9078
+ function checkFieldDeclarations(lx, Comp) {
9079
+ const fields = Comp.Class?.getMetaClass?.().fields;
9080
+ if (!fields)
9081
+ return;
9082
+ for (const fieldName in fields) {
9083
+ const field = fields[fieldName];
9084
+ if (!Object.hasOwn(field, "args"))
9085
+ continue;
9086
+ if (typeof field.type !== "string") {
9087
+ lx.error(COMP_FIELD_BAD_SHAPE, {
9088
+ fieldName,
9089
+ kind: "component-not-string",
9090
+ got: typeof field.type,
9091
+ gotName: field.type?.name ?? null
9092
+ });
9093
+ }
9094
+ if (field.args == null || field.args.constructor !== Object) {
9095
+ lx.error(COMP_FIELD_BAD_SHAPE, {
9096
+ fieldName,
9097
+ kind: "args-not-object",
9098
+ got: field.args === null ? "null" : typeof field.args
9099
+ });
9100
+ }
9101
+ }
9102
+ }
9059
9103
  function checkUnreferencedAlterHandlers(lx, Comp, referencedAlters) {
9060
9104
  for (const name in Comp.alter) {
9061
9105
  if (!referencedAlters.has(name)) {
@@ -9106,7 +9150,7 @@ class LintContext {
9106
9150
  this.reports.push({ id, info, level, context: { ...this.frame }, suggestion });
9107
9151
  }
9108
9152
  }
9109
- var KNOWN_COMPONENT_SPEC_KEYS, EMPTY_SET2, KNOWN_DIRECTIVE_NAMES, ALT_HANDLER_NOT_DEFINED = "ALT_HANDLER_NOT_DEFINED", ALT_HANDLER_NOT_REFERENCED = "ALT_HANDLER_NOT_REFERENCED", DYN_VAL_NOT_DEFINED = "DYN_VAL_NOT_DEFINED", DYN_ALIAS_NOT_REFERENCED = "DYN_ALIAS_NOT_REFERENCED", RENDER_IT_OUTSIDE_OF_LOOP = "RENDER_IT_OUTSIDE_OF_LOOP", UNKNOWN_EVENT_MODIFIER = "UNKNOWN_EVENT_MODIFIER", UNKNOWN_HANDLER_ARG_NAME = "UNKNOWN_HANDLER_ARG_NAME", INPUT_HANDLER_NOT_IMPLEMENTED = "INPUT_HANDLER_NOT_IMPLEMENTED", INPUT_HANDLER_NOT_REFERENCED = "INPUT_HANDLER_NOT_REFERENCED", INPUT_HANDLER_METHOD_NOT_IMPLEMENTED = "INPUT_HANDLER_METHOD_NOT_IMPLEMENTED", INPUT_HANDLER_FOR_INPUT_HANDLER_METHOD = "INPUT_HANDLER_FOR_INPUT_HANDLER_METHOD", INPUT_HANDLER_METHOD_FOR_INPUT_HANDLER = "INPUT_HANDLER_METHOD_FOR_INPUT_HANDLER", FIELD_VAL_NOT_DEFINED = "FIELD_VAL_NOT_DEFINED", FIELD_VAL_IS_METHOD = "FIELD_VAL_IS_METHOD", METHOD_VAL_NOT_DEFINED = "METHOD_VAL_NOT_DEFINED", METHOD_VAL_IS_FIELD = "METHOD_VAL_IS_FIELD", DUPLICATE_ATTR_DEFINITION = "DUPLICATE_ATTR_DEFINITION", IF_NO_BRANCH_SET = "IF_NO_BRANCH_SET", UNKNOWN_REQUEST_NAME = "UNKNOWN_REQUEST_NAME", UNKNOWN_COMPONENT_NAME = "UNKNOWN_COMPONENT_NAME", UNKNOWN_MACRO_ARG = "UNKNOWN_MACRO_ARG", UNKNOWN_DIRECTIVE = "UNKNOWN_DIRECTIVE", UNKNOWN_X_OP = "UNKNOWN_X_OP", UNKNOWN_X_ATTR = "UNKNOWN_X_ATTR", MAYBE_DROP_AT_PREFIX = "MAYBE_DROP_AT_PREFIX", BAD_VALUE = "BAD_VALUE", UNSUPPORTED_EXPR_SYNTAX = "UNSUPPORTED_EXPR_SYNTAX", REDUNDANT_TEMPLATE_STRING = "REDUNDANT_TEMPLATE_STRING", PLACEHOLDERLESS_TEMPLATE_STRING = "PLACEHOLDERLESS_TEMPLATE_STRING", UNKNOWN_COMPONENT_SPEC_KEY = "UNKNOWN_COMPONENT_SPEC_KEY", PARSE_ISSUE_KIND_TO_LINT_ID, X_KNOWN_OP_NAMES, X_KNOWN_ATTR_NAMES, AT_PREFIX_HINT_KNOWN_BY_KIND, LEVEL_WARN2 = "warn", LEVEL_ERROR2 = "error", LEVEL_HINT = "hint", PARSE_ISSUE_KIND_TO_KNOWN_NAMES, UNSUPPORTED_EXPR_GUIDANCE, HTML_LINT_OPTS, NO_WRAPPERS, KNOWN_HANDLER_NAMES, NODE_KIND_TO_CTX, LintParseContext;
9153
+ var KNOWN_COMPONENT_SPEC_KEYS, EMPTY_SET2, KNOWN_DIRECTIVE_NAMES, ALT_HANDLER_NOT_DEFINED = "ALT_HANDLER_NOT_DEFINED", ALT_HANDLER_NOT_REFERENCED = "ALT_HANDLER_NOT_REFERENCED", DYN_VAL_NOT_DEFINED = "DYN_VAL_NOT_DEFINED", DYN_ALIAS_NOT_REFERENCED = "DYN_ALIAS_NOT_REFERENCED", RENDER_IT_OUTSIDE_OF_LOOP = "RENDER_IT_OUTSIDE_OF_LOOP", UNKNOWN_EVENT_MODIFIER = "UNKNOWN_EVENT_MODIFIER", UNKNOWN_HANDLER_ARG_NAME = "UNKNOWN_HANDLER_ARG_NAME", INPUT_HANDLER_NOT_IMPLEMENTED = "INPUT_HANDLER_NOT_IMPLEMENTED", INPUT_HANDLER_NOT_REFERENCED = "INPUT_HANDLER_NOT_REFERENCED", INPUT_HANDLER_METHOD_NOT_IMPLEMENTED = "INPUT_HANDLER_METHOD_NOT_IMPLEMENTED", INPUT_HANDLER_FOR_INPUT_HANDLER_METHOD = "INPUT_HANDLER_FOR_INPUT_HANDLER_METHOD", INPUT_HANDLER_METHOD_FOR_INPUT_HANDLER = "INPUT_HANDLER_METHOD_FOR_INPUT_HANDLER", FIELD_VAL_NOT_DEFINED = "FIELD_VAL_NOT_DEFINED", FIELD_VAL_IS_METHOD = "FIELD_VAL_IS_METHOD", METHOD_VAL_NOT_DEFINED = "METHOD_VAL_NOT_DEFINED", METHOD_VAL_IS_FIELD = "METHOD_VAL_IS_FIELD", DUPLICATE_ATTR_DEFINITION = "DUPLICATE_ATTR_DEFINITION", IF_NO_BRANCH_SET = "IF_NO_BRANCH_SET", UNKNOWN_REQUEST_NAME = "UNKNOWN_REQUEST_NAME", UNKNOWN_COMPONENT_NAME = "UNKNOWN_COMPONENT_NAME", UNKNOWN_MACRO_ARG = "UNKNOWN_MACRO_ARG", UNKNOWN_DIRECTIVE = "UNKNOWN_DIRECTIVE", UNKNOWN_X_OP = "UNKNOWN_X_OP", UNKNOWN_X_ATTR = "UNKNOWN_X_ATTR", MAYBE_DROP_AT_PREFIX = "MAYBE_DROP_AT_PREFIX", BAD_VALUE = "BAD_VALUE", UNSUPPORTED_EXPR_SYNTAX = "UNSUPPORTED_EXPR_SYNTAX", REDUNDANT_TEMPLATE_STRING = "REDUNDANT_TEMPLATE_STRING", PLACEHOLDERLESS_TEMPLATE_STRING = "PLACEHOLDERLESS_TEMPLATE_STRING", UNKNOWN_COMPONENT_SPEC_KEY = "UNKNOWN_COMPONENT_SPEC_KEY", COMP_FIELD_BAD_SHAPE = "COMP_FIELD_BAD_SHAPE", PARSE_ISSUE_KIND_TO_LINT_ID, X_KNOWN_OP_NAMES, X_KNOWN_ATTR_NAMES, AT_PREFIX_HINT_KNOWN_BY_KIND, LEVEL_WARN2 = "warn", LEVEL_ERROR2 = "error", LEVEL_HINT = "hint", PARSE_ISSUE_KIND_TO_KNOWN_NAMES, UNSUPPORTED_EXPR_GUIDANCE, HTML_LINT_OPTS, NO_WRAPPERS, KNOWN_HANDLER_NAMES, NODE_KIND_TO_CTX, LintParseContext;
9110
9154
  var init_lint_check = __esm(() => {
9111
9155
  init_anode();
9112
9156
  init_htmllinter();
@@ -9406,6 +9450,12 @@ var init_lint_rules = __esm(() => {
9406
9450
  level: "warn",
9407
9451
  group: "Component spec",
9408
9452
  summary: "`component({...})` has an unrecognized key; its value is ignored at runtime."
9453
+ },
9454
+ {
9455
+ code: COMP_FIELD_BAD_SHAPE,
9456
+ level: "error",
9457
+ group: "Component field declarations",
9458
+ summary: "`fields: { x: { component, args } }` shape is wrong: `component` must be a string and `args` must be a plain object."
9409
9459
  }
9410
9460
  ];
9411
9461
  });
@@ -14192,7 +14242,12 @@ class Renderer {
14192
14242
  if (cachedNode)
14193
14243
  return cachedNode;
14194
14244
  const view = viewName ? comp.getView(viewName) : stack.lookupBestView(comp.views, "main");
14195
- const meta = this._renderMetadata({ $: "Comp", nid: node?.nodeId ?? null });
14245
+ const meta = this._renderMetadata({
14246
+ $: "Comp",
14247
+ nid: node?.nodeId ?? null,
14248
+ cid: comp.id,
14249
+ vid: view.name
14250
+ });
14196
14251
  const dom = new VFragment([meta, this.renderView(view, stack)]);
14197
14252
  this.cache.set(cachePath, cacheKey, dom);
14198
14253
  return dom;