@solidjs/web 2.0.0-beta.14 → 2.0.0-beta.16

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
@@ -32,6 +32,7 @@ const DOMWithState = {
32
32
  };
33
33
  const ChildProperties = /*#__PURE__*/new Set(["innerHTML", "textContent", "innerText", "children"]);
34
34
  const $$SLOT = /*#__PURE__*/Symbol("slot");
35
+ const $$HOST = /*#__PURE__*/Symbol("host");
35
36
  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"]);
36
37
  const SVGElements = /*#__PURE__*/new Set([
37
38
  "altGlyph", "altGlyphDef", "altGlyphItem", "animate", "animateColor", "animateMotion", "animateTransform", "circle", "clipPath", "color-profile", "cursor", "defs", "desc", "ellipse", "feBlend", "feColorMatrix", "feComponentTransfer", "feComposite", "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap", "feDistantLight", "feDropShadow", "feFlood", "feFuncA", "feFuncB", "feFuncG", "feFuncR", "feGaussianBlur", "feImage", "feMerge", "feMergeNode", "feMorphology", "feOffset", "fePointLight", "feSpecularLighting", "feSpotLight", "feTile", "feTurbulence", "filter", "font", "font-face", "font-face-format", "font-face-name", "font-face-src", "font-face-uri", "foreignObject", "g", "glyph", "glyphRef", "hkern", "image", "line", "linearGradient", "marker", "mask", "metadata", "missing-glyph", "mpath", "path", "pattern", "polygon", "polyline", "radialGradient", "rect",
@@ -59,9 +60,9 @@ const syncOptions = {
59
60
  sync: true
60
61
  };
61
62
  const effect = (fn, effectFn, options) => solidJs.createRenderEffect(fn, effectFn, options ? {
62
- transparent: true,
63
63
  sync: true,
64
- ...options
64
+ ...options,
65
+ transparent: !options.scope
65
66
  } : transparentOptions);
66
67
  const memo = fn => solidJs.createMemo(() => fn(), syncOptions);
67
68
 
@@ -334,20 +335,41 @@ function addEvent(node, name, handler, delegate) {
334
335
  }
335
336
  function style(node, value, prev) {
336
337
  if (!value) {
337
- if (prev) setAttribute(node, "style");
338
+ if (prev || node._$styles) {
339
+ setAttribute(node, "style");
340
+ node._$styles = undefined;
341
+ }
338
342
  return;
339
343
  }
340
344
  const nodeStyle = node.style;
341
- if (typeof value === "string") return nodeStyle.cssText = value;
342
- typeof prev === "string" && (nodeStyle.cssText = prev = undefined);
343
- prev || (prev = {});
345
+ if (typeof value === "string") {
346
+ node._$styles = undefined;
347
+ return nodeStyle.cssText = value;
348
+ }
349
+ if (typeof prev === "string") {
350
+ nodeStyle.cssText = "";
351
+ prev = undefined;
352
+ }
353
+ let applied = node._$styles;
354
+ if (!applied) {
355
+ applied = node._$styles = prev ? {
356
+ ...prev
357
+ } : {};
358
+ }
344
359
  let v, s;
360
+ for (s in applied) {
361
+ if (value[s] == null) {
362
+ nodeStyle.removeProperty(s);
363
+ delete applied[s];
364
+ }
365
+ }
345
366
  for (s in value) {
346
367
  v = value[s];
347
- if (v !== prev[s]) nodeStyle.setProperty(s, v);
348
- delete prev[s];
368
+ if (v != null && v !== applied[s]) {
369
+ nodeStyle.setProperty(s, v);
370
+ applied[s] = v;
371
+ }
349
372
  }
350
- for (s in prev) value[s] == null && nodeStyle.removeProperty(s);
351
373
  }
352
374
  function setStyleProperty(node, name, value) {
353
375
  value != null ? node.style.setProperty(name, value) : node.style.removeProperty(name);
@@ -386,22 +408,36 @@ function ref(fn, element) {
386
408
  const resolved = solidJs.untrack(fn);
387
409
  solidJs.runWithOwner(null, () => applyRef(resolved, element));
388
410
  }
411
+ function scope(fn) {
412
+ fn.$s = true;
413
+ return fn;
414
+ }
415
+ const SCOPE_OPTIONS = {
416
+ scope: true
417
+ };
418
+ function stripTextSeparators(nodes) {
419
+ let j = 0;
420
+ for (let i = 0; i < nodes.length; i++) {
421
+ if (nodes[i].nodeType === 8 && nodes[i].nodeValue === "!$") nodes[i].remove();else nodes[j++] = nodes[i];
422
+ }
423
+ nodes.length = j;
424
+ return nodes;
425
+ }
389
426
  function insert(parent, accessor, marker, initial, options) {
390
427
  const multi = marker !== undefined;
428
+ const host = options && options.host;
391
429
  if (multi && !initial) initial = [];
392
430
  if (isHydrating(parent)) {
393
431
  if (!multi && initial === undefined && parent) initial = [...parent.childNodes];
394
- if (Array.isArray(initial)) {
395
- let j = 0;
396
- for (let i = 0; i < initial.length; i++) {
397
- if (initial[i].nodeType === 8 && initial[i].nodeValue === "!$") initial[i].remove();else initial[j++] = initial[i];
398
- }
399
- initial.length = j;
400
- }
432
+ if (Array.isArray(initial)) stripTextSeparators(initial);
401
433
  }
402
434
  if (typeof accessor !== "function") {
403
435
  accessor = normalize(accessor, initial, multi, true);
404
- if (typeof accessor !== "function") return insertExpression(parent, accessor, initial, marker);
436
+ if (typeof accessor !== "function") {
437
+ insertExpression(parent, accessor, initial, marker);
438
+ host && tagHost(accessor, host);
439
+ return;
440
+ }
405
441
  }
406
442
  if (multi && initial.length === 0) {
407
443
  const placeholder = document.createTextNode("");
@@ -409,12 +445,37 @@ function insert(parent, accessor, marker, initial, options) {
409
445
  initial = [placeholder];
410
446
  }
411
447
  let current = initial;
448
+ function reclaimSwappedRegion() {
449
+ if (!solidJs.sharedConfig.hydrating || !current || !parent.isConnected) return;
450
+ const first = Array.isArray(current) ? current[0] : current;
451
+ if (!first || !first.nodeType || first.isConnected) return;
452
+ let nodes;
453
+ if (marker) {
454
+ nodes = [];
455
+ let node = marker.previousSibling,
456
+ depth = 0;
457
+ while (node) {
458
+ if (node.nodeType === 8) {
459
+ const v = node.nodeValue;
460
+ if (v === "/") depth++;else if (v === "$") {
461
+ if (depth === 0) break;
462
+ depth--;
463
+ }
464
+ }
465
+ nodes.unshift(node);
466
+ node = node.previousSibling;
467
+ }
468
+ } else nodes = [...parent.childNodes];
469
+ current = stripTextSeparators(nodes);
470
+ }
412
471
  effect(prev => {
472
+ reclaimSwappedRegion();
413
473
  const value = normalize(accessor(), current, multi, true);
414
474
  if (typeof value !== "function") return value;
415
- effect(() => normalize(value, current, multi), inner => {
475
+ effect(() => (reclaimSwappedRegion(), normalize(value, current, multi)), inner => {
416
476
  insertExpression(parent, inner, current, marker);
417
477
  current = inner;
478
+ host && tagHost(current, host);
418
479
  }, prev !== undefined && !(options && options.schedule) ? {
419
480
  ...options,
420
481
  schedule: true
@@ -424,7 +485,12 @@ function insert(parent, accessor, marker, initial, options) {
424
485
  if (value === INNER_OWNED) return;
425
486
  insertExpression(parent, value, current, marker);
426
487
  current = value;
427
- }, options);
488
+ host && tagHost(current, host);
489
+ },
490
+ accessor.$s ? options ? {
491
+ ...options,
492
+ scope: true
493
+ } : SCOPE_OPTIONS : options);
428
494
  }
429
495
  function assign(node, props, skipChildren, prevProps = {}, skipRef = false) {
430
496
  const nodeName = node.nodeName;
@@ -453,6 +519,9 @@ function loadModuleAssets(mapping) {
453
519
  if (!hy.loading[moduleUrl]) {
454
520
  hy.loading[moduleUrl] = import(entryUrl).then(mod => {
455
521
  hy.modules[moduleUrl] = mod;
522
+ }, err => {
523
+ delete hy.loading[moduleUrl];
524
+ throw err;
456
525
  });
457
526
  }
458
527
  pending.push(hy.loading[moduleUrl]);
@@ -510,8 +579,11 @@ function hydrate$1(code, element, options = {}) {
510
579
  } finally {
511
580
  solidJs.sharedConfig.hydrating = false;
512
581
  }
513
- }, () => {
582
+ }, err => {
583
+ console.error("Hydration module preload failed, falling back to client render:", err);
514
584
  solidJs.sharedConfig.hydrating = false;
585
+ solidJs.sharedConfig.registry = undefined;
586
+ disposer = render$1(code, element, [...element.childNodes], options);
515
587
  });
516
588
  return () => disposer && disposer();
517
589
  }
@@ -623,17 +695,32 @@ function runHydrationEvents() {
623
695
  const [el, e] = events[0];
624
696
  if (!completed.has(el)) return;
625
697
  events.shift();
626
- let match;
698
+ let matchContainer, matchState, matchDistance, matches;
627
699
  for (const [container, state] of delegatedContainers) {
628
700
  if (!state.handlers.has(e.type)) continue;
629
701
  const entry = findOwner(e.target, state);
630
- if (entry && (!match || entry.distance < match.distance)) match = {
631
- container,
632
- state,
633
- distance: entry.distance
634
- };
702
+ if (!entry) continue;
703
+ if (matchContainer) {
704
+ if (!matches) matches = [{
705
+ container: matchContainer,
706
+ state: matchState,
707
+ distance: matchDistance
708
+ }];
709
+ matches.push({
710
+ container,
711
+ state,
712
+ distance: entry.distance
713
+ });
714
+ } else {
715
+ matchContainer = container;
716
+ matchState = state;
717
+ matchDistance = entry.distance;
718
+ }
635
719
  }
636
- if (match) eventHandler(e, match.container, match.state);
720
+ if (matches) {
721
+ matches.sort((a, b) => a.distance - b.distance);
722
+ for (let i = 0; i < matches.length; i++) eventHandler(e, matches[i].container, matches[i].state);
723
+ } else if (matchContainer) eventHandler(e, matchContainer, matchState);
637
724
  }
638
725
  if (solidJs.sharedConfig.done) {
639
726
  solidJs.sharedConfig.events = _$HY.events = null;
@@ -704,11 +791,16 @@ function eventHandler(e, container, state) {
704
791
  if (solidJs.sharedConfig.registry && solidJs.sharedConfig.events) {
705
792
  if (solidJs.sharedConfig.events.find(([el, ev]) => ev === e)) return;
706
793
  }
707
- if (e[$$EVENT_OWNER]) return;
794
+ const prev = e[$$EVENT_OWNER];
795
+ let resumeNode;
796
+ if (prev) {
797
+ if (prev === true || prev === container || !container.contains(prev)) return;
798
+ resumeNode = prev;
799
+ }
708
800
  const owner = state && (state.owners.size === 1 && state.owners.has(container) ? container : findOwner(e.target, state)?.owner);
709
801
  if (state && !owner) return;
710
802
  e[$$EVENT_OWNER] = owner || true;
711
- let node = e.target;
803
+ let node = resumeNode || e.target;
712
804
  const key = `$$${e.type}`;
713
805
  const oriTarget = e.target;
714
806
  const boundary = owner || container || e.currentTarget;
@@ -738,7 +830,10 @@ function eventHandler(e, container, state) {
738
830
  return node || boundary || document;
739
831
  }
740
832
  });
741
- if (e.composedPath) {
833
+ if (resumeNode) {
834
+ if (resumeNode === e.target) node = resumeNode._$host || resumeNode.parentNode || resumeNode.host;
835
+ if (node && node !== boundary) walkUpTree();
836
+ } else if (e.composedPath) {
742
837
  const path = e.composedPath();
743
838
  if (path.length) {
744
839
  retarget(path[0]);
@@ -813,6 +908,17 @@ function normalize(value, current, multi, doNotUnwrap) {
813
908
  }
814
909
  return value;
815
910
  }
911
+ function tagHost(value, host) {
912
+ if (Array.isArray(value)) {
913
+ for (let i = 0, len = value.length; i < len; i++) tagHost(value[i], host);
914
+ } else if (value && value.nodeType && value[$$HOST] !== host) {
915
+ value[$$HOST] = host;
916
+ Object.defineProperty(value, "_$host", {
917
+ get: host,
918
+ configurable: true
919
+ });
920
+ }
921
+ }
816
922
  function appendNodes(parent, array, marker = null) {
817
923
  for (let i = 0, len = array.length; i < len; i++) {
818
924
  const n = array[i];
@@ -897,21 +1003,33 @@ function Portal(props) {
897
1003
  const treeMarker = document.createTextNode(""),
898
1004
  startMarker = document.createTextNode(""),
899
1005
  endMarker = document.createTextNode(""),
900
- mount = () => createElementProxy(props.mount || document.body, treeMarker),
1006
+ mount = () => props.mount || document.body,
901
1007
  content = solidJs.createMemo(() => [startMarker, props.children]);
902
- solidJs.createRenderEffect(() => [mount(), content()], ([m, c]) => {
1008
+ solidJs.createRenderEffect(
1009
+ () => [mount(), content(), solidJs.getOwner()], ([, c, owner]) => {
1010
+ const m = solidJs.untrack(mount);
903
1011
  m.appendChild(endMarker);
904
- insert(m, c, endMarker);
1012
+ const dispose = solidJs.runWithOwner(owner, () => solidJs.createRoot(d => {
1013
+ insert(m, c, endMarker, undefined, {
1014
+ host: () => treeMarker.parentNode
1015
+ });
1016
+ return d;
1017
+ }));
905
1018
  return () => {
1019
+ dispose();
906
1020
  let c = startMarker;
907
- while (c && c !== endMarker) {
1021
+ while (c) {
908
1022
  const n = c.nextSibling;
909
1023
  m.removeChild(c);
1024
+ if (c === endMarker) break;
910
1025
  c = n;
911
1026
  }
912
1027
  };
1028
+ }, {
1029
+ schedule: true
913
1030
  });
914
- solidJs.createEffect(mount, m => {
1031
+ solidJs.createEffect(mount, () => {
1032
+ const m = solidJs.untrack(mount);
915
1033
  const ownerRoot = getDelegatedRoot(treeMarker);
916
1034
  if (!ownerRoot || ownerRoot.contains(m)) return;
917
1035
  registerDelegatedContainer(m, ownerRoot);
@@ -949,23 +1067,6 @@ function createElement(tagName, is = undefined) {
949
1067
  is
950
1068
  });
951
1069
  }
952
- function createElementProxy(el, marker) {
953
- return new Proxy(el, {
954
- get(target, prop) {
955
- if (prop === "appendChild" || prop === "insertBefore") {
956
- return (...args) => {
957
- Object.defineProperty(args[0], "_$host", {
958
- get: () => marker.parentNode,
959
- configurable: true
960
- });
961
- target[prop](...args);
962
- };
963
- }
964
- const value = Reflect.get(target, prop);
965
- return typeof value === "function" ? value.bind(target) : value;
966
- }
967
- });
968
- }
969
1070
 
970
1071
  Object.defineProperty(exports, "Errored", {
971
1072
  enumerable: true,
@@ -1067,6 +1168,7 @@ exports.renderToString = renderToString;
1067
1168
  exports.renderToStringAsync = renderToStringAsync;
1068
1169
  exports.resolveSSRNode = resolveSSRNode;
1069
1170
  exports.runHydrationEvents = runHydrationEvents;
1171
+ exports.scope = scope;
1070
1172
  exports.setAttribute = setAttribute;
1071
1173
  exports.setAttributeNS = setAttributeNS;
1072
1174
  exports.setProperty = setProperty;