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