tutuca 0.9.66 → 0.9.68

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.
@@ -8840,40 +8840,67 @@ class RequestHandler {
8840
8840
  }
8841
8841
 
8842
8842
  // src/vdom.js
8843
- var isHtmlAttribute = (propName) => propName[4] === "-" && (propName[0] === "d" || propName[0] === "a");
8844
8843
  var HTML_NS = "http://www.w3.org/1999/xhtml";
8844
+ var SVG_NS = "http://www.w3.org/2000/svg";
8845
+ var MATH_NS = "http://www.w3.org/1998/Math/MathML";
8845
8846
  var isNamespaced = (node) => {
8846
8847
  const ns = node.namespaceURI;
8847
8848
  return ns !== null && ns !== HTML_NS;
8848
8849
  };
8849
- function applyProperties(node, props, previous) {
8850
+ var isForeignObject = (tag) => tag.length === 13 && tag.toLowerCase() === "foreignobject";
8851
+ var effectiveNs = (vnode, opts) => vnode.namespace ?? opts.namespace ?? null;
8852
+ function childOpts(vnode, ns, opts) {
8853
+ const target = ns === SVG_NS && isForeignObject(vnode.tag) ? null : ns;
8854
+ return target === (opts.namespace ?? null) ? opts : { ...opts, namespace: target };
8855
+ }
8856
+ var NEVER_ASSIGN = new Set([
8857
+ "width",
8858
+ "height",
8859
+ "href",
8860
+ "list",
8861
+ "form",
8862
+ "tabIndex",
8863
+ "download",
8864
+ "rowSpan",
8865
+ "colSpan",
8866
+ "role",
8867
+ "popover"
8868
+ ]);
8869
+ function applyProperties(node, props) {
8850
8870
  const namespaced = isNamespaced(node);
8851
- for (const propName in props) {
8852
- const propValue = props[propName];
8853
- if (propValue === undefined)
8854
- removeProperty(node, propName, previous);
8855
- else if (propName === "dangerouslySetInnerHTML")
8856
- node.innerHTML = propValue.__html ?? "";
8857
- else if (propName === "className")
8858
- node.setAttribute("class", propValue);
8859
- else if (namespaced || isHtmlAttribute(propName))
8860
- node.setAttribute(propName, propValue);
8861
- else
8862
- node[propName] = propValue;
8863
- }
8864
- }
8865
- function removeProperty(node, propName, previous) {
8866
- const previousValue = previous[propName];
8867
- if (propName === "dangerouslySetInnerHTML")
8868
- node.replaceChildren();
8869
- else if (propName === "className")
8870
- node.removeAttribute("class");
8871
- else if (propName === "htmlFor")
8872
- node.removeAttribute("for");
8873
- else if (isNamespaced(node) || typeof previousValue === "string" || isHtmlAttribute(propName))
8874
- node.removeAttribute(propName);
8871
+ for (const name in props)
8872
+ setProp2(node, name, props[name], namespaced);
8873
+ }
8874
+ function setProp2(node, name, value, namespaced) {
8875
+ if (name === "dangerouslySetInnerHTML") {
8876
+ if (value === undefined)
8877
+ node.replaceChildren();
8878
+ else {
8879
+ const html = value.__html ?? "";
8880
+ if (html !== node.innerHTML)
8881
+ node.innerHTML = html;
8882
+ }
8883
+ return;
8884
+ }
8885
+ if (typeof value === "function")
8886
+ return;
8887
+ if (!namespaced && !NEVER_ASSIGN.has(name) && name in node) {
8888
+ try {
8889
+ node[name] = value == null ? "" : value;
8890
+ return;
8891
+ } catch {}
8892
+ }
8893
+ if (value == null || value === false && name[4] !== "-")
8894
+ node.removeAttribute(name);
8875
8895
  else
8876
- node[propName] = null;
8896
+ node.setAttribute(name, value);
8897
+ }
8898
+ function applyValueLast(node, value) {
8899
+ if (node.tagName === "PROGRESS" && (value == null || value === 0)) {
8900
+ node.removeAttribute("value");
8901
+ } else {
8902
+ setProp2(node, "value", value, isNamespaced(node));
8903
+ }
8877
8904
  }
8878
8905
 
8879
8906
  class VBase {
@@ -8993,15 +9020,23 @@ class VNode2 extends VBase {
8993
9020
  }
8994
9021
  toDom(opts) {
8995
9022
  const doc = opts.document;
8996
- const node = this.namespace === null ? doc.createElement(this.tag) : doc.createElementNS(this.namespace, this.tag);
8997
- if (this.tag === "SELECT" && "value" in this.attrs) {
8998
- const { value, ...rest } = this.attrs;
8999
- applyProperties(node, rest, {});
9000
- appendChildNodes(node, this.childs, opts);
9001
- applyProperties(node, { value }, {});
9023
+ const ns = effectiveNs(this, opts);
9024
+ const tag = ns !== null && this.tag === this.tag.toUpperCase() ? this.tag.toLowerCase() : this.tag;
9025
+ const attrs = this.attrs;
9026
+ const createOpts = attrs.is != null ? { is: attrs.is } : undefined;
9027
+ const node = ns === null ? doc.createElement(tag, createOpts) : doc.createElementNS(ns, tag, createOpts);
9028
+ const cOpts = childOpts(this, ns, opts);
9029
+ if ("value" in attrs || "checked" in attrs) {
9030
+ const { value, checked, ...rest } = attrs;
9031
+ applyProperties(node, rest);
9032
+ appendChildNodes(node, this.childs, cOpts);
9033
+ if (value !== undefined)
9034
+ applyValueLast(node, value);
9035
+ if (checked !== undefined)
9036
+ setProp2(node, "checked", checked, false);
9002
9037
  } else {
9003
- applyProperties(node, this.attrs, {});
9004
- appendChildNodes(node, this.childs, opts);
9038
+ applyProperties(node, attrs);
9039
+ appendChildNodes(node, this.childs, cOpts);
9005
9040
  }
9006
9041
  return node;
9007
9042
  }
@@ -9038,18 +9073,37 @@ function morphNode(domNode, source, target, opts) {
9038
9073
  }
9039
9074
  if (type3 === 1 && source.isSameKind(target)) {
9040
9075
  const propsDiff = diffProps(source.attrs, target.attrs);
9041
- const isSelect = source.tag === "SELECT";
9076
+ let pendingValue;
9077
+ let pendingChecked;
9078
+ let applyValue = false;
9079
+ let applyChecked = false;
9042
9080
  if (propsDiff) {
9043
- if (isSelect && "value" in propsDiff) {
9044
- const { value: _v, ...rest } = propsDiff;
9045
- applyProperties(domNode, rest, source.attrs);
9081
+ if ("value" in propsDiff || "checked" in propsDiff) {
9082
+ const { value, checked, ...rest } = propsDiff;
9083
+ applyProperties(domNode, rest);
9084
+ if ("value" in propsDiff) {
9085
+ pendingValue = value;
9086
+ applyValue = true;
9087
+ }
9088
+ if ("checked" in propsDiff) {
9089
+ pendingChecked = checked;
9090
+ applyChecked = true;
9091
+ }
9046
9092
  } else
9047
- applyProperties(domNode, propsDiff, source.attrs);
9093
+ applyProperties(domNode, propsDiff);
9094
+ }
9095
+ if (!target.attrs.dangerouslySetInnerHTML) {
9096
+ const ns = effectiveNs(target, opts);
9097
+ morphChildren(domNode, source.childs, target.childs, childOpts(target, ns, opts));
9098
+ }
9099
+ if (!applyValue && source.tag === "SELECT" && target.attrs.value !== undefined) {
9100
+ pendingValue = target.attrs.value;
9101
+ applyValue = true;
9048
9102
  }
9049
- if (!target.attrs.dangerouslySetInnerHTML)
9050
- morphChildren(domNode, source.childs, target.childs, opts);
9051
- if (isSelect && target.attrs.value !== undefined)
9052
- applyProperties(domNode, { value: target.attrs.value }, source.attrs);
9103
+ if (applyValue)
9104
+ applyValueLast(domNode, pendingValue);
9105
+ if (applyChecked)
9106
+ setProp2(domNode, "checked", pendingChecked, false);
9053
9107
  return domNode;
9054
9108
  }
9055
9109
  if (type3 === 11) {
@@ -9145,26 +9199,26 @@ function h(tagName, properties, children, namespace) {
9145
9199
  if (properties) {
9146
9200
  for (const propName in properties) {
9147
9201
  const propVal = properties[propName];
9148
- switch (propName) {
9149
- case "key":
9150
- key = propVal;
9151
- break;
9152
- case "namespace":
9153
- namespace = namespace ?? propVal;
9154
- break;
9155
- case "class":
9156
- props.className = propVal;
9157
- break;
9158
- case "for":
9159
- props.htmlFor = propVal;
9160
- break;
9161
- default:
9162
- props[propName] = isHtmlAttribute(propName) ? String(propVal) : propVal;
9163
- }
9202
+ if (propName === "key")
9203
+ key = propVal;
9204
+ else if (propName === "namespace")
9205
+ namespace = namespace ?? propVal;
9206
+ else
9207
+ props[propName] = propVal;
9208
+ }
9209
+ }
9210
+ if (namespace == null) {
9211
+ const lower = tagName.toLowerCase();
9212
+ if (lower === "svg") {
9213
+ namespace = SVG_NS;
9214
+ tagName = "svg";
9215
+ } else if (lower === "math") {
9216
+ namespace = MATH_NS;
9217
+ tagName = "math";
9164
9218
  }
9165
9219
  }
9166
9220
  const c = tagName.charCodeAt(0);
9167
- const tag = namespace == null && c >= 97 && c <= 122 ? tagName.toUpperCase() : tagName;
9221
+ const tag = namespace == null && c >= 97 && c <= 122 && tagName === tagName.toLowerCase() ? tagName.toUpperCase() : tagName;
9168
9222
  const normalizedChildren = [];
9169
9223
  addChild(normalizedChildren, children);
9170
9224
  return new VNode2(tag, props, normalizedChildren, key, namespace);
@@ -12275,6 +12329,7 @@ var UNSUPPORTED_EXPR_SYNTAX = "UNSUPPORTED_EXPR_SYNTAX";
12275
12329
  var REDUNDANT_TEMPLATE_STRING = "REDUNDANT_TEMPLATE_STRING";
12276
12330
  var PLACEHOLDERLESS_TEMPLATE_STRING = "PLACEHOLDERLESS_TEMPLATE_STRING";
12277
12331
  var UNKNOWN_COMPONENT_SPEC_KEY = "UNKNOWN_COMPONENT_SPEC_KEY";
12332
+ var COMP_FIELD_BAD_SHAPE = "COMP_FIELD_BAD_SHAPE";
12278
12333
  var PARSE_ISSUE_KIND_TO_LINT_ID = {
12279
12334
  "unknown-directive": UNKNOWN_DIRECTIVE,
12280
12335
  "unknown-x-op": UNKNOWN_X_OP,
@@ -12359,6 +12414,7 @@ var UNSUPPORTED_EXPR_GUIDANCE = {
12359
12414
  function checkComponent(Comp, lx = new LintContext, { wellKnownExtras = EMPTY_SET2 } = {}) {
12360
12415
  return lx.push({ componentName: Comp.name }, () => {
12361
12416
  checkUnknownSpecKeys(lx, Comp, wellKnownExtras);
12417
+ checkFieldDeclarations(lx, Comp);
12362
12418
  const referencedAlters = new Set;
12363
12419
  const referencedInputs = new Set;
12364
12420
  const referencedDynamics = new Set;
@@ -12787,6 +12843,31 @@ function checkUnknownSpecKeys(lx, Comp, wellKnownExtras) {
12787
12843
  lx.warn(UNKNOWN_COMPONENT_SPEC_KEY, { key }, replaceNameSuggestion(key, candidates));
12788
12844
  }
12789
12845
  }
12846
+ function checkFieldDeclarations(lx, Comp) {
12847
+ const fields = Comp.Class?.getMetaClass?.().fields;
12848
+ if (!fields)
12849
+ return;
12850
+ for (const fieldName in fields) {
12851
+ const field = fields[fieldName];
12852
+ if (!Object.hasOwn(field, "args"))
12853
+ continue;
12854
+ if (typeof field.type !== "string") {
12855
+ lx.error(COMP_FIELD_BAD_SHAPE, {
12856
+ fieldName,
12857
+ kind: "component-not-string",
12858
+ got: typeof field.type,
12859
+ gotName: field.type?.name ?? null
12860
+ });
12861
+ }
12862
+ if (field.args == null || field.args.constructor !== Object) {
12863
+ lx.error(COMP_FIELD_BAD_SHAPE, {
12864
+ fieldName,
12865
+ kind: "args-not-object",
12866
+ got: field.args === null ? "null" : typeof field.args
12867
+ });
12868
+ }
12869
+ }
12870
+ }
12790
12871
  function checkUnreferencedAlterHandlers(lx, Comp, referencedAlters) {
12791
12872
  for (const name in Comp.alter) {
12792
12873
  if (!referencedAlters.has(name)) {
@@ -15587,6 +15668,7 @@ export {
15587
15668
  ComponentList,
15588
15669
  ComponentDocs,
15589
15670
  Collection,
15671
+ COMP_FIELD_BAD_SHAPE,
15590
15672
  BAD_VALUE,
15591
15673
  ALT_HANDLER_NOT_REFERENCED,
15592
15674
  ALT_HANDLER_NOT_DEFINED