@solidjs/web 2.0.0-beta.5 → 2.0.0-beta.7

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/dev.cjs CHANGED
@@ -6,23 +6,29 @@ var signals = require('@solidjs/signals');
6
6
  const DOMWithState = {
7
7
  INPUT: {
8
8
  value: 1,
9
- checked: 1
9
+ defaultValue: 2,
10
+ checked: 1,
11
+ defaultChecked: 2
10
12
  },
11
13
  SELECT: {
12
14
  value: 1
13
15
  },
14
16
  OPTION: {
15
17
  value: 1,
16
- selected: 1
18
+ selected: 1,
19
+ defaultSelected: 2
17
20
  },
18
21
  TEXTAREA: {
19
- value: 1
22
+ value: 1,
23
+ defaultValue: 2
20
24
  },
21
25
  VIDEO: {
22
- muted: 1
26
+ muted: 1,
27
+ defaultMuted: 2
23
28
  },
24
29
  AUDIO: {
25
- muted: 1
30
+ muted: 1,
31
+ defaultMuted: 2
26
32
  }
27
33
  };
28
34
  const ChildProperties = /*#__PURE__*/new Set(["innerHTML", "textContent", "innerText", "children"]);
@@ -33,7 +39,9 @@ const SVGElements = /*#__PURE__*/new Set([
33
39
  "svg", "switch", "symbol", "text", "textPath",
34
40
  "tref", "tspan", "use", "view", "vkern"]);
35
41
  const MathMLElements = /*#__PURE__*/new Set(["annotation", "annotation-xml", "maction", "math", "menclose", "merror", "mfenced", "mfrac", "mi", "mmultiscripts", "mn", "mo", "mover", "mpadded", "mphantom", "mprescripts", "mroot", "mrow", "ms", "mspace", "msqrt", "mstyle", "msub", "msubsup", "msup", "mtable", "mtd", "mtext", "mtr", "munder", "munderover", "semantics"]);
36
- const SVGNamespace = {
42
+ const Namespaces = {
43
+ svg: "http://www.w3.org/2000/svg",
44
+ mathml: "http://www.w3.org/1998/Math/MathML",
37
45
  xlink: "http://www.w3.org/1999/xlink",
38
46
  xml: "http://www.w3.org/XML/1998/namespace"
39
47
  };
@@ -41,10 +49,10 @@ const DOMElements = /*#__PURE__*/new Set(["html", "base", "head", "link", "meta"
41
49
  "webview",
42
50
  "isindex", "listing", "multicol", "nextid", "noindex", "search"]);
43
51
 
44
- const effect = (fn, effectFn, initial) => solidJs.createRenderEffect(fn, effectFn, initial, {
52
+ const effect = (fn, effectFn) => solidJs.createRenderEffect(fn, effectFn, {
45
53
  transparent: true
46
54
  });
47
- const memo = (fn, transparent) => transparent ? fn.$r ? fn : signals.createMemo(() => fn(), undefined, {
55
+ const memo = (fn, transparent) => transparent ? fn.$r ? fn : signals.createMemo(() => fn(), {
48
56
  transparent: true
49
57
  }) : solidJs.createMemo(() => fn());
50
58
 
@@ -110,16 +118,17 @@ function render$1(code, element, init, options = {}) {
110
118
  if (!element) {
111
119
  throw new Error("The `element` passed to `render(..., element)` doesn't exist. Make sure `element` exists in the document.");
112
120
  }
121
+ const renderRoot = getChildRoot(element);
113
122
  let disposer;
114
123
  solidJs.createRoot(dispose => {
115
124
  disposer = dispose;
116
- element === document ? solidJs.flatten(code) : insert(element, code(), element.firstChild ? null : undefined, init);
125
+ element === document ? solidJs.flatten(code) : insert(element, code(), renderRoot.firstChild ? null : undefined, init);
117
126
  }, {
118
127
  id: options.renderId
119
128
  });
120
129
  return () => {
121
130
  disposer();
122
- element.textContent = "";
131
+ renderRoot.textContent = "";
123
132
  };
124
133
  }
125
134
  function create(html, bypassGuard, flag) {
@@ -259,10 +268,11 @@ function ref(fn, element) {
259
268
  solidJs.runWithOwner(null, () => applyRef(resolved, element));
260
269
  }
261
270
  function insert(parent, accessor, marker, initial) {
271
+ const childRoot = getChildRoot(parent);
262
272
  const multi = marker !== undefined;
263
273
  if (multi && !initial) initial = [];
264
274
  if (isHydrating(parent)) {
265
- if (!multi && initial === undefined && parent) initial = [...parent.childNodes];
275
+ if (!multi && initial === undefined && parent) initial = [...childRoot.childNodes];
266
276
  if (Array.isArray(initial)) {
267
277
  let j = 0;
268
278
  for (let i = 0; i < initial.length; i++) {
@@ -278,10 +288,10 @@ function insert(parent, accessor, marker, initial) {
278
288
  accessor = memo(accessor, true);
279
289
  if (multi && initial.length === 0) {
280
290
  const placeholder = document.createTextNode("");
281
- parent.insertBefore(placeholder, marker);
291
+ childRoot.insertBefore(placeholder, marker);
282
292
  initial = [placeholder];
283
293
  }
284
- effect(prev => normalize(accessor, prev, multi), (value, current) => insertExpression(parent, value, current, marker), initial);
294
+ effect((prev = initial) => normalize(accessor, prev, multi), (value, current = initial) => insertExpression(parent, value, current, marker));
285
295
  }
286
296
  function assign(node, props, skipChildren, prevProps = {}, skipRef = false) {
287
297
  const nodeName = node.nodeName;
@@ -289,19 +299,35 @@ function assign(node, props, skipChildren, prevProps = {}, skipRef = false) {
289
299
  for (const prop in prevProps) {
290
300
  if (!(prop in props)) {
291
301
  if (prop === "children") continue;
292
- prevProps[prop] = assignProp(node, prop, null, prevProps[prop], skipRef, nodeName, prevProps);
302
+ prevProps[prop] = assignProp(node, prop, null, prevProps[prop], skipRef, nodeName);
293
303
  }
294
304
  }
295
305
  for (const prop in props) {
296
306
  if (prop === "children") {
297
- if (!skipChildren) insertExpression(node, props.children);
307
+ if (!skipChildren) insertExpression(node, normalize(props.children, undefined, false));
298
308
  continue;
299
309
  }
300
- prevProps[prop] = assignProp(node, prop, props[prop], prevProps[prop], skipRef, nodeName, props);
310
+ prevProps[prop] = assignProp(node, prop, props[prop], prevProps[prop], skipRef, nodeName);
311
+ }
312
+ }
313
+ function loadModuleAssets(mapping) {
314
+ const hy = globalThis._$HY;
315
+ if (!hy) return;
316
+ const pending = [];
317
+ for (const moduleUrl in mapping) {
318
+ if (hy.modules[moduleUrl]) continue;
319
+ const entryUrl = mapping[moduleUrl];
320
+ if (!hy.loading[moduleUrl]) {
321
+ hy.loading[moduleUrl] = import(entryUrl).then(mod => {
322
+ hy.modules[moduleUrl] = mod;
323
+ });
324
+ }
325
+ pending.push(hy.loading[moduleUrl]);
301
326
  }
327
+ return pending.length ? Promise.all(pending).then(() => {}) : undefined;
302
328
  }
303
329
  function hydrate$1(code, element, options = {}) {
304
- if (globalThis._$HY.done) return render$1(code, element, [...element.childNodes], options);
330
+ if (globalThis._$HY.done) return render$1(code, element, [...getChildRoot(element).childNodes], options);
305
331
  options.renderId ||= "";
306
332
  if (!globalThis._$HY.modules) globalThis._$HY.modules = {};
307
333
  if (!globalThis._$HY.loading) globalThis._$HY.loading = {};
@@ -310,6 +336,7 @@ function hydrate$1(code, element, options = {}) {
310
336
  solidJs.sharedConfig.load = id => globalThis._$HY.r[id];
311
337
  solidJs.sharedConfig.has = id => id in globalThis._$HY.r;
312
338
  solidJs.sharedConfig.gather = root => gatherHydratable(element, root);
339
+ solidJs.sharedConfig.loadModuleAssets = loadModuleAssets;
313
340
  solidJs.sharedConfig.cleanupFragment = id => {
314
341
  const tpl = document.getElementById("pl-" + id);
315
342
  if (tpl) {
@@ -338,9 +365,27 @@ function hydrate$1(code, element, options = {}) {
338
365
  }
339
366
  };
340
367
  }
368
+ const rootMapping = globalThis._$HY.r && globalThis._$HY.r["_assets"];
369
+ if (rootMapping && typeof rootMapping === "object") {
370
+ const p = loadModuleAssets(rootMapping);
371
+ if (p) {
372
+ gatherHydratable(element, options.renderId);
373
+ let disposer;
374
+ p.then(() => {
375
+ try {
376
+ disposer = render$1(code, element, [...getChildRoot(element).childNodes], options);
377
+ } finally {
378
+ solidJs.sharedConfig.hydrating = false;
379
+ }
380
+ }, () => {
381
+ solidJs.sharedConfig.hydrating = false;
382
+ });
383
+ return () => disposer && disposer();
384
+ }
385
+ }
341
386
  try {
342
387
  gatherHydratable(element, options.renderId);
343
- return render$1(code, element, [...element.childNodes], options);
388
+ return render$1(code, element, [...getChildRoot(element).childNodes], options);
344
389
  } finally {
345
390
  solidJs.sharedConfig.hydrating = false;
346
391
  }
@@ -389,7 +434,7 @@ function getNextMarker(start) {
389
434
  return [end, current];
390
435
  }
391
436
  function getFirstChild(node, expectedTag) {
392
- const child = node.firstChild;
437
+ const child = getChildRoot(node).firstChild;
393
438
  if (isHydrating() && expectedTag && child?.localName !== expectedTag) {
394
439
  const isMissing = !child || child.nodeType !== 1;
395
440
  console.warn("Hydration structure mismatch: expected <" + expectedTag + "> as first child of", node, "\n " + describeSiblings(node, child, expectedTag, isMissing));
@@ -399,20 +444,21 @@ function getFirstChild(node, expectedTag) {
399
444
  function getNextSibling(node, expectedTag) {
400
445
  const sibling = node.nextSibling;
401
446
  if (isHydrating() && expectedTag && sibling?.localName !== expectedTag) {
402
- const parent = node.parentElement;
447
+ const parent = node.parentNode;
403
448
  const isMissing = !sibling || sibling.nodeType !== 1;
404
449
  console.warn("Hydration structure mismatch: expected <" + expectedTag + "> after", node, "in", parent, "\n " + describeSiblings(parent, sibling, expectedTag, isMissing));
405
450
  }
406
451
  return sibling;
407
452
  }
408
453
  function describeSiblings(parent, mismatchChild, expectedTag, isMissing) {
454
+ if (!parent) return `<${expectedTag} \u2190 parent unavailable>`;
409
455
  const children = [];
410
- let child = parent.firstChild;
456
+ let child = getChildRoot(parent).firstChild;
411
457
  while (child) {
412
458
  if (child.nodeType === 1) children.push(child);
413
459
  child = child.nextSibling;
414
460
  }
415
- const pTag = parent.localName;
461
+ const pTag = parent.localName || "#fragment";
416
462
  if (isMissing) {
417
463
  const tags = children.map(c => `<${c.localName}>`).join("");
418
464
  return `<${pTag}>${tags}<${expectedTag} \u2190 missing></${pTag}>`;
@@ -457,6 +503,9 @@ function runHydrationEvents() {
457
503
  function isHydrating(node) {
458
504
  return solidJs.sharedConfig.hydrating && (!node || node.isConnected);
459
505
  }
506
+ function getChildRoot(node) {
507
+ return node && node.localName === "template" ? node.content : node;
508
+ }
460
509
  function toggleClassKey(node, key, value) {
461
510
  const classNames = key.trim().split(/\s+/);
462
511
  for (let i = 0, nameLen = classNames.length; i < nameLen; i++) node.classList.toggle(classNames[i], value);
@@ -475,10 +524,10 @@ function flattenClassList(list, result) {
475
524
  if (Array.isArray(item)) flattenClassList(item, result);else if (typeof item === "object" && item != null) Object.assign(result, item);else if (item || item === 0) result[item] = true;
476
525
  }
477
526
  }
478
- function assignProp(node, prop, value, prev, skipRef, nodeName, props) {
527
+ function assignProp(node, prop, value, prev, skipRef, nodeName) {
479
528
  if (prop === "style") return style(node, value, prev), value;
480
529
  if (prop === "class") return className(node, value, prev), value;
481
- if (value === prev && !DOMWithState[nodeName]?.[prop]) return prev;
530
+ if (value === prev && DOMWithState[nodeName]?.[prop] !== 1) return prev;
482
531
  if (prop === "ref") {
483
532
  if (!skipRef && value) ref(() => value, node);
484
533
  return value;
@@ -488,7 +537,7 @@ function assignProp(node, prop, value, prev, skipRef, nodeName, props) {
488
537
  const e = prop.slice(3);
489
538
  prev && node.removeEventListener(e, prev, typeof prev !== "function" && prev);
490
539
  value && node.addEventListener(e, value, typeof value !== "function" && value);
491
- } else if (prop.slice(0, 2) === "on") {
540
+ } else if (!hasNamespace && prop.slice(0, 2) === "on") {
492
541
  const name = prop.slice(2).toLowerCase();
493
542
  const delegate = DelegatedEvents.has(name);
494
543
  if (!delegate && prev) {
@@ -499,11 +548,11 @@ function assignProp(node, prop, value, prev, skipRef, nodeName, props) {
499
548
  addEventListener(node, name, value, delegate);
500
549
  delegate && delegateEvents([name]);
501
550
  }
502
- } else if (hasNamespace && prop.slice(0, 5) === "prop:" || ChildProperties.has(prop) || DOMWithState[nodeName]?.[prop] && !("prop:" + prop in props)) {
551
+ } else if (hasNamespace && prop.slice(0, 5) === "prop:" || ChildProperties.has(prop) || DOMWithState[nodeName]?.[prop]) {
503
552
  if (hasNamespace) prop = prop.slice(5);else if (isHydrating(node)) return value;
504
553
  if (prop === "value" && nodeName === "SELECT") queueMicrotask(() => node.value = value) || (node.value = value);else node[prop] = value;
505
554
  } else {
506
- const ns = hasNamespace && SVGNamespace[prop.split(":")[0]];
555
+ const ns = hasNamespace && Namespaces[prop.split(":")[0]];
507
556
  if (ns) setAttributeNS(node, ns, prop, value);else setAttribute(node, prop, value);
508
557
  }
509
558
  return value;
@@ -561,21 +610,22 @@ function eventHandler(e) {
561
610
  function insertExpression(parent, value, current, marker) {
562
611
  if (isHydrating(parent)) return;
563
612
  if (value === current) return;
613
+ const childRoot = getChildRoot(parent);
564
614
  const t = typeof value,
565
615
  multi = marker !== undefined;
566
616
  if (t === "string" || t === "number") {
567
617
  const tc = typeof current;
568
618
  if (tc === "string" || tc === "number") {
569
- parent.firstChild.data = value;
570
- } else parent.textContent = value;
619
+ childRoot.firstChild.data = value;
620
+ } else childRoot.textContent = value;
571
621
  } else if (value === undefined) {
572
622
  cleanChildren(parent, current, marker);
573
623
  } else if (value.nodeType) {
574
624
  if (Array.isArray(current)) {
575
625
  cleanChildren(parent, current, multi ? marker : null, value);
576
- } else if (current === undefined || !parent.firstChild) {
577
- parent.appendChild(value);
578
- } else parent.replaceChild(value, parent.firstChild);
626
+ } else if (current === undefined || !childRoot.firstChild) {
627
+ childRoot.appendChild(value);
628
+ } else childRoot.replaceChild(value, childRoot.firstChild);
579
629
  } else if (Array.isArray(value)) {
580
630
  const currentArray = current && Array.isArray(current);
581
631
  if (value.length === 0) {
@@ -583,7 +633,7 @@ function insertExpression(parent, value, current, marker) {
583
633
  } else if (currentArray) {
584
634
  if (current.length === 0) {
585
635
  appendNodes(parent, value, marker);
586
- } else reconcileArrays(parent, current, value);
636
+ } else reconcileArrays(childRoot, current, value);
587
637
  } else {
588
638
  current && cleanChildren(parent);
589
639
  appendNodes(parent, value);
@@ -608,9 +658,11 @@ function normalize(value, current, multi, doNotUnwrap) {
608
658
  return value;
609
659
  }
610
660
  function appendNodes(parent, array, marker = null) {
661
+ parent = getChildRoot(parent);
611
662
  for (let i = 0, len = array.length; i < len; i++) parent.insertBefore(array[i], marker);
612
663
  }
613
664
  function cleanChildren(parent, current, marker, replacement) {
665
+ parent = getChildRoot(parent);
614
666
  if (marker === undefined) return parent.textContent = "";
615
667
  if (current.length) {
616
668
  let inserted = false;
@@ -667,9 +719,8 @@ function render(...args) {
667
719
  }
668
720
  const isServer = false;
669
721
  const isDev = true;
670
- const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
671
- function createElement(tagName, isSVG = false, is = undefined) {
672
- return isSVG ? document.createElementNS(SVG_NAMESPACE, tagName) : document.createElement(tagName, {
722
+ function createElement(tagName, is = undefined) {
723
+ return SVGElements.has(tagName) ? document.createElementNS(Namespaces.svg, tagName) : MathMLElements.has(tagName) ? document.createElementNS(Namespaces.mathml, tagName) : document.createElement(tagName, {
673
724
  is
674
725
  });
675
726
  }
@@ -725,9 +776,8 @@ function createDynamic(component, props) {
725
776
  });
726
777
  return solidJs.untrack(() => component(props));
727
778
  case "string":
728
- const isSvg = SVGElements.has(component);
729
- const el = solidJs.sharedConfig.hydrating ? getNextElement() : createElement(component, isSvg, solidJs.untrack(() => props.is));
730
- spread(el, props, isSvg);
779
+ const el = solidJs.sharedConfig.hydrating ? getNextElement() : createElement(component, solidJs.untrack(() => props.is));
780
+ spread(el, props);
731
781
  return el;
732
782
  }
733
783
  });
@@ -761,6 +811,14 @@ Object.defineProperty(exports, "NoHydration", {
761
811
  enumerable: true,
762
812
  get: function () { return solidJs.NoHydration; }
763
813
  });
814
+ Object.defineProperty(exports, "Repeat", {
815
+ enumerable: true,
816
+ get: function () { return solidJs.Repeat; }
817
+ });
818
+ Object.defineProperty(exports, "Reveal", {
819
+ enumerable: true,
820
+ get: function () { return solidJs.Reveal; }
821
+ });
764
822
  Object.defineProperty(exports, "Show", {
765
823
  enumerable: true,
766
824
  get: function () { return solidJs.Show; }
@@ -793,10 +851,10 @@ exports.DelegatedEvents = DelegatedEvents;
793
851
  exports.Dynamic = Dynamic;
794
852
  exports.HydrationScript = voidFn;
795
853
  exports.MathMLElements = MathMLElements;
854
+ exports.Namespaces = Namespaces;
796
855
  exports.Portal = Portal;
797
856
  exports.RequestContext = RequestContext;
798
857
  exports.SVGElements = SVGElements;
799
- exports.SVGNamespace = SVGNamespace;
800
858
  exports.addEventListener = addEventListener;
801
859
  exports.applyRef = applyRef;
802
860
  exports.assign = assign;