@solidjs/web 2.0.0-beta.6 → 2.0.0-beta.8

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,9 +6,9 @@ var signals = require('@solidjs/signals');
6
6
  const DOMWithState = {
7
7
  INPUT: {
8
8
  value: 1,
9
- defaultValue: 1,
9
+ defaultValue: 2,
10
10
  checked: 1,
11
- defaultChecked: 1
11
+ defaultChecked: 2
12
12
  },
13
13
  SELECT: {
14
14
  value: 1
@@ -16,26 +16,21 @@ const DOMWithState = {
16
16
  OPTION: {
17
17
  value: 1,
18
18
  selected: 1,
19
- defaultSelected: 1
19
+ defaultSelected: 2
20
20
  },
21
21
  TEXTAREA: {
22
22
  value: 1,
23
- defaultValue: 1
23
+ defaultValue: 2
24
24
  },
25
25
  VIDEO: {
26
26
  muted: 1,
27
- defaultMuted: 1
27
+ defaultMuted: 2
28
28
  },
29
29
  AUDIO: {
30
30
  muted: 1,
31
- defaultMuted: 1
31
+ defaultMuted: 2
32
32
  }
33
33
  };
34
- for (const tagName in DOMWithState) {
35
- for (const propName in DOMWithState[tagName]) {
36
- DOMWithState[tagName]["prop:" + propName] = 1;
37
- }
38
- }
39
34
  const ChildProperties = /*#__PURE__*/new Set(["innerHTML", "textContent", "innerText", "children"]);
40
35
  const DelegatedEvents = /*#__PURE__*/new Set(["beforeinput", "click", "dblclick", "contextmenu", "focusin", "focusout", "input", "keydown", "keyup", "mousedown", "mousemove", "mouseout", "mouseover", "mouseup", "pointerdown", "pointermove", "pointerout", "pointerover", "pointerup", "touchend", "touchmove", "touchstart"]);
41
36
  const SVGElements = /*#__PURE__*/new Set([
@@ -54,10 +49,14 @@ const DOMElements = /*#__PURE__*/new Set(["html", "base", "head", "link", "meta"
54
49
  "webview",
55
50
  "isindex", "listing", "multicol", "nextid", "noindex", "search"]);
56
51
 
57
- const effect = (fn, effectFn, initial) => solidJs.createRenderEffect(fn, effectFn, initial, {
52
+ const transparentOptions = {
58
53
  transparent: true
59
- });
60
- const memo = (fn, transparent) => transparent ? fn.$r ? fn : signals.createMemo(() => fn(), undefined, {
54
+ };
55
+ const effect = (fn, effectFn, options) => solidJs.createRenderEffect(fn, effectFn, options ? {
56
+ transparent: true,
57
+ ...options
58
+ } : transparentOptions);
59
+ const memo = (fn, transparent) => transparent ? fn.$r ? fn : signals.createMemo(() => fn(), {
61
60
  transparent: true
62
61
  }) : solidJs.createMemo(() => fn());
63
62
 
@@ -123,16 +122,17 @@ function render$1(code, element, init, options = {}) {
123
122
  if (!element) {
124
123
  throw new Error("The `element` passed to `render(..., element)` doesn't exist. Make sure `element` exists in the document.");
125
124
  }
125
+ const renderRoot = getChildRoot(element);
126
126
  let disposer;
127
127
  solidJs.createRoot(dispose => {
128
128
  disposer = dispose;
129
- element === document ? solidJs.flatten(code) : insert(element, code(), element.firstChild ? null : undefined, init);
129
+ element === document ? solidJs.flatten(code) : insert(element, code(), renderRoot.firstChild ? null : undefined, init);
130
130
  }, {
131
131
  id: options.renderId
132
132
  });
133
133
  return () => {
134
134
  disposer();
135
- element.textContent = "";
135
+ renderRoot.textContent = "";
136
136
  };
137
137
  }
138
138
  function create(html, bypassGuard, flag) {
@@ -271,11 +271,12 @@ function ref(fn, element) {
271
271
  const resolved = solidJs.untrack(fn);
272
272
  solidJs.runWithOwner(null, () => applyRef(resolved, element));
273
273
  }
274
- function insert(parent, accessor, marker, initial) {
274
+ function insert(parent, accessor, marker, initial, options) {
275
+ const childRoot = getChildRoot(parent);
275
276
  const multi = marker !== undefined;
276
277
  if (multi && !initial) initial = [];
277
278
  if (isHydrating(parent)) {
278
- if (!multi && initial === undefined && parent) initial = [...parent.childNodes];
279
+ if (!multi && initial === undefined && parent) initial = [...childRoot.childNodes];
279
280
  if (Array.isArray(initial)) {
280
281
  let j = 0;
281
282
  for (let i = 0; i < initial.length; i++) {
@@ -291,10 +292,10 @@ function insert(parent, accessor, marker, initial) {
291
292
  accessor = memo(accessor, true);
292
293
  if (multi && initial.length === 0) {
293
294
  const placeholder = document.createTextNode("");
294
- parent.insertBefore(placeholder, marker);
295
+ childRoot.insertBefore(placeholder, marker);
295
296
  initial = [placeholder];
296
297
  }
297
- effect(prev => normalize(accessor, prev, multi), (value, current) => insertExpression(parent, value, current, marker), initial);
298
+ effect((prev = initial) => normalize(accessor, prev, multi), (value, current = initial) => insertExpression(parent, value, current, marker), options);
298
299
  }
299
300
  function assign(node, props, skipChildren, prevProps = {}, skipRef = false) {
300
301
  const nodeName = node.nodeName;
@@ -313,8 +314,24 @@ function assign(node, props, skipChildren, prevProps = {}, skipRef = false) {
313
314
  prevProps[prop] = assignProp(node, prop, props[prop], prevProps[prop], skipRef, nodeName);
314
315
  }
315
316
  }
317
+ function loadModuleAssets(mapping) {
318
+ const hy = globalThis._$HY;
319
+ if (!hy) return;
320
+ const pending = [];
321
+ for (const moduleUrl in mapping) {
322
+ if (hy.modules[moduleUrl]) continue;
323
+ const entryUrl = mapping[moduleUrl];
324
+ if (!hy.loading[moduleUrl]) {
325
+ hy.loading[moduleUrl] = import(entryUrl).then(mod => {
326
+ hy.modules[moduleUrl] = mod;
327
+ });
328
+ }
329
+ pending.push(hy.loading[moduleUrl]);
330
+ }
331
+ return pending.length ? Promise.all(pending).then(() => {}) : undefined;
332
+ }
316
333
  function hydrate$1(code, element, options = {}) {
317
- if (globalThis._$HY.done) return render$1(code, element, [...element.childNodes], options);
334
+ if (globalThis._$HY.done) return render$1(code, element, [...getChildRoot(element).childNodes], options);
318
335
  options.renderId ||= "";
319
336
  if (!globalThis._$HY.modules) globalThis._$HY.modules = {};
320
337
  if (!globalThis._$HY.loading) globalThis._$HY.loading = {};
@@ -323,6 +340,7 @@ function hydrate$1(code, element, options = {}) {
323
340
  solidJs.sharedConfig.load = id => globalThis._$HY.r[id];
324
341
  solidJs.sharedConfig.has = id => id in globalThis._$HY.r;
325
342
  solidJs.sharedConfig.gather = root => gatherHydratable(element, root);
343
+ solidJs.sharedConfig.loadModuleAssets = loadModuleAssets;
326
344
  solidJs.sharedConfig.cleanupFragment = id => {
327
345
  const tpl = document.getElementById("pl-" + id);
328
346
  if (tpl) {
@@ -351,9 +369,27 @@ function hydrate$1(code, element, options = {}) {
351
369
  }
352
370
  };
353
371
  }
372
+ const rootMapping = globalThis._$HY.r && globalThis._$HY.r["_assets"];
373
+ if (rootMapping && typeof rootMapping === "object") {
374
+ const p = loadModuleAssets(rootMapping);
375
+ if (p) {
376
+ gatherHydratable(element, options.renderId);
377
+ let disposer;
378
+ p.then(() => {
379
+ try {
380
+ disposer = render$1(code, element, [...getChildRoot(element).childNodes], options);
381
+ } finally {
382
+ solidJs.sharedConfig.hydrating = false;
383
+ }
384
+ }, () => {
385
+ solidJs.sharedConfig.hydrating = false;
386
+ });
387
+ return () => disposer && disposer();
388
+ }
389
+ }
354
390
  try {
355
391
  gatherHydratable(element, options.renderId);
356
- return render$1(code, element, [...element.childNodes], options);
392
+ return render$1(code, element, [...getChildRoot(element).childNodes], options);
357
393
  } finally {
358
394
  solidJs.sharedConfig.hydrating = false;
359
395
  }
@@ -402,7 +438,7 @@ function getNextMarker(start) {
402
438
  return [end, current];
403
439
  }
404
440
  function getFirstChild(node, expectedTag) {
405
- const child = node.firstChild;
441
+ const child = getChildRoot(node).firstChild;
406
442
  if (isHydrating() && expectedTag && child?.localName !== expectedTag) {
407
443
  const isMissing = !child || child.nodeType !== 1;
408
444
  console.warn("Hydration structure mismatch: expected <" + expectedTag + "> as first child of", node, "\n " + describeSiblings(node, child, expectedTag, isMissing));
@@ -412,20 +448,21 @@ function getFirstChild(node, expectedTag) {
412
448
  function getNextSibling(node, expectedTag) {
413
449
  const sibling = node.nextSibling;
414
450
  if (isHydrating() && expectedTag && sibling?.localName !== expectedTag) {
415
- const parent = node.parentElement;
451
+ const parent = node.parentNode;
416
452
  const isMissing = !sibling || sibling.nodeType !== 1;
417
453
  console.warn("Hydration structure mismatch: expected <" + expectedTag + "> after", node, "in", parent, "\n " + describeSiblings(parent, sibling, expectedTag, isMissing));
418
454
  }
419
455
  return sibling;
420
456
  }
421
457
  function describeSiblings(parent, mismatchChild, expectedTag, isMissing) {
458
+ if (!parent) return `<${expectedTag} \u2190 parent unavailable>`;
422
459
  const children = [];
423
- let child = parent.firstChild;
460
+ let child = getChildRoot(parent).firstChild;
424
461
  while (child) {
425
462
  if (child.nodeType === 1) children.push(child);
426
463
  child = child.nextSibling;
427
464
  }
428
- const pTag = parent.localName;
465
+ const pTag = parent.localName || "#fragment";
429
466
  if (isMissing) {
430
467
  const tags = children.map(c => `<${c.localName}>`).join("");
431
468
  return `<${pTag}>${tags}<${expectedTag} \u2190 missing></${pTag}>`;
@@ -470,6 +507,9 @@ function runHydrationEvents() {
470
507
  function isHydrating(node) {
471
508
  return solidJs.sharedConfig.hydrating && (!node || node.isConnected);
472
509
  }
510
+ function getChildRoot(node) {
511
+ return node && node.localName === "template" ? node.content : node;
512
+ }
473
513
  function toggleClassKey(node, key, value) {
474
514
  const classNames = key.trim().split(/\s+/);
475
515
  for (let i = 0, nameLen = classNames.length; i < nameLen; i++) node.classList.toggle(classNames[i], value);
@@ -491,7 +531,7 @@ function flattenClassList(list, result) {
491
531
  function assignProp(node, prop, value, prev, skipRef, nodeName) {
492
532
  if (prop === "style") return style(node, value, prev), value;
493
533
  if (prop === "class") return className(node, value, prev), value;
494
- if (value === prev && !DOMWithState[nodeName]?.[prop]) return prev;
534
+ if (value === prev && DOMWithState[nodeName]?.[prop] !== 1) return prev;
495
535
  if (prop === "ref") {
496
536
  if (!skipRef && value) ref(() => value, node);
497
537
  return value;
@@ -574,21 +614,22 @@ function eventHandler(e) {
574
614
  function insertExpression(parent, value, current, marker) {
575
615
  if (isHydrating(parent)) return;
576
616
  if (value === current) return;
617
+ const childRoot = getChildRoot(parent);
577
618
  const t = typeof value,
578
619
  multi = marker !== undefined;
579
620
  if (t === "string" || t === "number") {
580
621
  const tc = typeof current;
581
622
  if (tc === "string" || tc === "number") {
582
- parent.firstChild.data = value;
583
- } else parent.textContent = value;
623
+ childRoot.firstChild.data = value;
624
+ } else childRoot.textContent = value;
584
625
  } else if (value === undefined) {
585
626
  cleanChildren(parent, current, marker);
586
627
  } else if (value.nodeType) {
587
628
  if (Array.isArray(current)) {
588
629
  cleanChildren(parent, current, multi ? marker : null, value);
589
- } else if (current === undefined || !parent.firstChild) {
590
- parent.appendChild(value);
591
- } else parent.replaceChild(value, parent.firstChild);
630
+ } else if (current === undefined || !childRoot.firstChild) {
631
+ childRoot.appendChild(value);
632
+ } else childRoot.replaceChild(value, childRoot.firstChild);
592
633
  } else if (Array.isArray(value)) {
593
634
  const currentArray = current && Array.isArray(current);
594
635
  if (value.length === 0) {
@@ -596,7 +637,7 @@ function insertExpression(parent, value, current, marker) {
596
637
  } else if (currentArray) {
597
638
  if (current.length === 0) {
598
639
  appendNodes(parent, value, marker);
599
- } else reconcileArrays(parent, current, value);
640
+ } else reconcileArrays(childRoot, current, value);
600
641
  } else {
601
642
  current && cleanChildren(parent);
602
643
  appendNodes(parent, value);
@@ -621,9 +662,11 @@ function normalize(value, current, multi, doNotUnwrap) {
621
662
  return value;
622
663
  }
623
664
  function appendNodes(parent, array, marker = null) {
665
+ parent = getChildRoot(parent);
624
666
  for (let i = 0, len = array.length; i < len; i++) parent.insertBefore(array[i], marker);
625
667
  }
626
668
  function cleanChildren(parent, current, marker, replacement) {
669
+ parent = getChildRoot(parent);
627
670
  if (marker === undefined) return parent.textContent = "";
628
671
  if (current.length) {
629
672
  let inserted = false;
@@ -672,19 +715,38 @@ function ssrHydrationKey() {}
672
715
  function resolveSSRNode(node) {}
673
716
  function escape(html) {}
674
717
 
675
- function render(...args) {
676
- solidJs.enforceLoadingBoundary(true);
677
- const result = render$1(...args);
678
- solidJs.enforceLoadingBoundary(false);
679
- return result;
680
- }
681
718
  const isServer = false;
682
719
  const isDev = true;
683
- const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
684
- function createElement(tagName, isSVG = false, is = undefined) {
685
- return isSVG ? document.createElementNS(SVG_NAMESPACE, tagName) : document.createElement(tagName, {
686
- is
720
+ function render(code, element, init, options = {}) {
721
+ if (!element) {
722
+ throw new Error("The `element` passed to `render(..., element)` doesn't exist. Make sure `element` exists in the document.");
723
+ }
724
+ const renderRoot = element.localName === "template" ? element.content : element;
725
+ let disposer;
726
+ solidJs.createRoot(dispose => {
727
+ disposer = dispose;
728
+ if (element === document) {
729
+ solidJs.flatten(code);
730
+ return;
731
+ }
732
+ const marker = renderRoot.firstChild ? null : undefined;
733
+ solidJs.enforceLoadingBoundary(true);
734
+ try {
735
+ const tree = code();
736
+ insert(element, () => tree, marker, init, {
737
+ schedule: true
738
+ });
739
+ } finally {
740
+ solidJs.enforceLoadingBoundary(false);
741
+ }
742
+ }, {
743
+ id: options.renderId
687
744
  });
745
+ solidJs.flush();
746
+ return () => {
747
+ disposer();
748
+ renderRoot.textContent = "";
749
+ };
688
750
  }
689
751
  const hydrate = (...args) => {
690
752
  solidJs.enableHydration();
@@ -710,23 +772,6 @@ function Portal(props) {
710
772
  });
711
773
  return treeMarker;
712
774
  }
713
- function createElementProxy(el, marker) {
714
- return new Proxy(el, {
715
- get(target, prop) {
716
- if (prop === "appendChild" || prop === "insertBefore") {
717
- return (...args) => {
718
- Object.defineProperty(args[0], "_$host", {
719
- get: () => marker.parentNode,
720
- configurable: true
721
- });
722
- target[prop](...args);
723
- };
724
- }
725
- const value = Reflect.get(target, prop);
726
- return typeof value === "function" ? value.bind(target) : value;
727
- }
728
- });
729
- }
730
775
  function createDynamic(component, props) {
731
776
  const cached = solidJs.createMemo(component);
732
777
  return solidJs.createMemo(() => {
@@ -738,9 +783,8 @@ function createDynamic(component, props) {
738
783
  });
739
784
  return solidJs.untrack(() => component(props));
740
785
  case "string":
741
- const isSvg = SVGElements.has(component);
742
- const el = solidJs.sharedConfig.hydrating ? getNextElement() : createElement(component, isSvg, solidJs.untrack(() => props.is));
743
- spread(el, props, isSvg);
786
+ const el = solidJs.sharedConfig.hydrating ? getNextElement() : createElement(component, solidJs.untrack(() => props.is));
787
+ spread(el, props);
744
788
  return el;
745
789
  }
746
790
  });
@@ -749,6 +793,28 @@ function Dynamic(props) {
749
793
  const others = solidJs.omit(props, "component");
750
794
  return createDynamic(() => props.component, others);
751
795
  }
796
+ function createElement(tagName, is = undefined) {
797
+ return SVGElements.has(tagName) ? document.createElementNS(Namespaces.svg, tagName) : MathMLElements.has(tagName) ? document.createElementNS(Namespaces.mathml, tagName) : document.createElement(tagName, {
798
+ is
799
+ });
800
+ }
801
+ function createElementProxy(el, marker) {
802
+ return new Proxy(el, {
803
+ get(target, prop) {
804
+ if (prop === "appendChild" || prop === "insertBefore") {
805
+ return (...args) => {
806
+ Object.defineProperty(args[0], "_$host", {
807
+ get: () => marker.parentNode,
808
+ configurable: true
809
+ });
810
+ target[prop](...args);
811
+ };
812
+ }
813
+ const value = Reflect.get(target, prop);
814
+ return typeof value === "function" ? value.bind(target) : value;
815
+ }
816
+ });
817
+ }
752
818
 
753
819
  Object.defineProperty(exports, "Errored", {
754
820
  enumerable: true,
@@ -774,6 +840,10 @@ Object.defineProperty(exports, "NoHydration", {
774
840
  enumerable: true,
775
841
  get: function () { return solidJs.NoHydration; }
776
842
  });
843
+ Object.defineProperty(exports, "Repeat", {
844
+ enumerable: true,
845
+ get: function () { return solidJs.Repeat; }
846
+ });
777
847
  Object.defineProperty(exports, "Reveal", {
778
848
  enumerable: true,
779
849
  get: function () { return solidJs.Reveal; }