solid-js 1.7.0-beta.0 → 1.7.0-beta.2

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/web/dist/dev.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createRoot, createRenderEffect, sharedConfig, untrack, enableHydration, createSignal, onCleanup, splitProps, createMemo, $DEVCOMP } from 'solid-js';
1
+ import { createRoot, untrack, createRenderEffect, sharedConfig, enableHydration, createMemo, createSignal, onMount, onCleanup, splitProps, $DEVCOMP } from 'solid-js';
2
2
  export { ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, createComponent, createRenderEffect as effect, getOwner, createMemo as memo, mergeProps, untrack } from 'solid-js';
3
3
 
4
4
  const booleans = ["allowfullscreen", "async", "autofocus", "autoplay", "checked", "controls", "default", "disabled", "formnovalidate", "hidden", "indeterminate", "ismap", "loop", "multiple", "muted", "nomodule", "novalidate", "open", "playsinline", "readonly", "required", "reversed", "seamless", "selected"];
@@ -10,12 +10,33 @@ const Aliases = /*#__PURE__*/Object.assign(Object.create(null), {
10
10
  });
11
11
  const PropAliases = /*#__PURE__*/Object.assign(Object.create(null), {
12
12
  class: "className",
13
- formnovalidate: "formNoValidate",
14
- ismap: "isMap",
15
- nomodule: "noModule",
16
- playsinline: "playsInline",
17
- readonly: "readOnly"
13
+ formnovalidate: {
14
+ $: "formNoValidate",
15
+ BUTTON: 1,
16
+ INPUT: 1
17
+ },
18
+ ismap: {
19
+ $: "isMap",
20
+ IMG: 1
21
+ },
22
+ nomodule: {
23
+ $: "noModule",
24
+ SCRIPT: 1
25
+ },
26
+ playsinline: {
27
+ $: "playsInline",
28
+ VIDEO: 1
29
+ },
30
+ readonly: {
31
+ $: "readOnly",
32
+ INPUT: 1,
33
+ TEXTAREA: 1
34
+ }
18
35
  });
36
+ function getPropAlias(prop, tagName) {
37
+ const a = PropAliases[prop];
38
+ return typeof a === "object" ? a[tagName] ? a["$"] : undefined : a;
39
+ }
19
40
  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"]);
20
41
  const SVGElements = /*#__PURE__*/new Set([
21
42
  "altGlyph", "altGlyphDef", "altGlyphItem", "animate", "animateColor", "animateMotion", "animateTransform", "circle", "clipPath", "color-profile", "cursor", "defs", "desc", "ellipse", "feBlend", "feColorMatrix", "feComponentTransfer", "feComposite", "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap", "feDistantLight", "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",
@@ -97,13 +118,14 @@ function render(code, element, init, options = {}) {
97
118
  element.textContent = "";
98
119
  };
99
120
  }
100
- function template(html, check, isSVG) {
101
- const t = document.createElement("template");
102
- t.innerHTML = html;
103
- if (check && t.innerHTML.split("<").length - 1 !== check) throw `The browser resolved template HTML does not match JSX input:\n${t.innerHTML}\n\n${html}. Is your HTML properly formed?`;
104
- let node = t.content.firstChild;
105
- if (isSVG) node = node.firstChild;
106
- return node;
121
+ function template(html, isSVG, isCE) {
122
+ let node;
123
+ const create = () => {
124
+ const t = document.createElement("template");
125
+ t.innerHTML = html;
126
+ return isSVG ? t.content.firstChild.firstChild : t.content.firstChild;
127
+ };
128
+ return isCE ? () => (node || (node = create())).cloneNode(true) : () => untrack(() => document.importNode(node || (node = create()), true));
107
129
  }
108
130
  function delegateEvents(eventNames, document = window.document) {
109
131
  const e = document[$$EVENTS] || (document[$$EVENTS] = new Set());
@@ -248,7 +270,7 @@ function getNextElement(template) {
248
270
  if (!sharedConfig.context || !(node = sharedConfig.registry.get(key = getHydrationKey()))) {
249
271
  if (sharedConfig.context) console.warn("Unable to find DOM nodes for hydration key:", key);
250
272
  if (!template) throw new Error("Unrecoverable Hydration Mismatch. No template for key: " + key);
251
- return template.cloneNode(true);
273
+ return template();
252
274
  }
253
275
  if (sharedConfig.completed) sharedConfig.completed.add(node);
254
276
  sharedConfig.registry.delete(key);
@@ -303,7 +325,7 @@ function toggleClassKey(node, key, value) {
303
325
  for (let i = 0, nameLen = classNames.length; i < nameLen; i++) node.classList.toggle(classNames[i], value);
304
326
  }
305
327
  function assignProp(node, prop, value, prev, isSVG, skipRef) {
306
- let isCE, isProp, isChildProp;
328
+ let isCE, isProp, isChildProp, propAlias, forceProp;
307
329
  if (prop === "style") return style(node, value, prev);
308
330
  if (prop === "classList") return classList(node, value, prev);
309
331
  if (value === prev) return prev;
@@ -328,8 +350,14 @@ function assignProp(node, prop, value, prev, isSVG, skipRef) {
328
350
  addEventListener(node, name, value, delegate);
329
351
  delegate && delegateEvents([name]);
330
352
  }
331
- } else if ((isChildProp = ChildProperties.has(prop)) || !isSVG && (PropAliases[prop] || (isProp = Properties.has(prop))) || (isCE = node.nodeName.includes("-"))) {
332
- if (prop === "class" || prop === "className") className(node, value);else if (isCE && !isProp && !isChildProp) node[toPropertyName(prop)] = value;else node[PropAliases[prop] || prop] = value;
353
+ } else if (prop.slice(0, 5) === "attr:") {
354
+ setAttribute(node, prop.slice(5), value);
355
+ } else if ((forceProp = prop.slice(0, 5) === "prop:") || (isChildProp = ChildProperties.has(prop)) || !isSVG && ((propAlias = getPropAlias(prop, node.tagName)) || (isProp = Properties.has(prop))) || (isCE = node.nodeName.includes("-"))) {
356
+ if (forceProp) {
357
+ prop = prop.slice(5);
358
+ isProp = true;
359
+ }
360
+ if (prop === "class" || prop === "className") className(node, value);else if (isCE && !isProp && !isChildProp) node[toPropertyName(prop)] = value;else node[propAlias || prop] = value;
333
361
  } else {
334
362
  const ns = isSVG && prop.indexOf(":") > -1 && SVGNamespace[prop.split(":")[0]];
335
363
  if (ns) setAttributeNS(node, ns, prop, value);else setAttribute(node, Aliases[prop] || prop, value);
@@ -351,17 +379,7 @@ function eventHandler(e) {
351
379
  return node || document;
352
380
  }
353
381
  });
354
- if (sharedConfig.registry && !sharedConfig.done) {
355
- sharedConfig.done = true;
356
- document.querySelectorAll("[id^=pl-]").forEach(elem => {
357
- while (elem && elem.nodeType !== 8 && elem.nodeValue !== "pl-" + e) {
358
- let x = elem.nextSibling;
359
- elem.remove();
360
- elem = x;
361
- }
362
- elem && elem.remove();
363
- });
364
- }
382
+ if (sharedConfig.registry && !sharedConfig.done) sharedConfig.done = _$HY.done = true;
365
383
  while (node) {
366
384
  const handler = node[key];
367
385
  if (handler && !node.disabled) {
@@ -373,7 +391,15 @@ function eventHandler(e) {
373
391
  }
374
392
  }
375
393
  function insertExpression(parent, value, current, marker, unwrapArray) {
376
- if (sharedConfig.context && !current) current = [...parent.childNodes];
394
+ if (sharedConfig.context) {
395
+ !current && (current = [...parent.childNodes]);
396
+ let cleaned = [];
397
+ for (let i = 0; i < current.length; i++) {
398
+ const node = current[i];
399
+ if (node.nodeType === 8 && node.data === "!") node.remove();else cleaned.push(node);
400
+ }
401
+ current = cleaned;
402
+ }
377
403
  while (typeof current === "function") current = current();
378
404
  if (value === current) return current;
379
405
  const t = typeof value,
@@ -459,7 +485,8 @@ function normalizeIncomingArray(normalized, array, current, unwrap) {
459
485
  }
460
486
  } else {
461
487
  const value = String(item);
462
- if (prev && prev.nodeType === 3 && prev.data === value) {
488
+ if (prev && prev.nodeType === 3) {
489
+ prev.data = value;
463
490
  normalized.push(prev);
464
491
  } else normalized.push(document.createTextNode(value));
465
492
  }
@@ -528,6 +555,7 @@ function escape(html) {}
528
555
  function ssrSpread(props, isSVG, skipChildren) {}
529
556
 
530
557
  const isServer = false;
558
+ const isDev = true;
531
559
  const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
532
560
  function createElement(tagName, isSVG = false) {
533
561
  return isSVG ? document.createElementNS(SVG_NAMESPACE, tagName) : document.createElement(tagName);
@@ -541,37 +569,41 @@ function Portal(props) {
541
569
  useShadow
542
570
  } = props,
543
571
  marker = document.createTextNode(""),
544
- mount = props.mount || document.body;
572
+ mount = () => props.mount || document.body,
573
+ content = createMemo(renderPortal());
545
574
  function renderPortal() {
546
575
  if (sharedConfig.context) {
547
576
  const [s, set] = createSignal(false);
548
- queueMicrotask(() => set(true));
577
+ onMount(() => set(true));
549
578
  return () => s() && props.children;
550
579
  } else return () => props.children;
551
580
  }
552
- if (mount instanceof HTMLHeadElement) {
553
- const [clean, setClean] = createSignal(false);
554
- const cleanup = () => setClean(true);
555
- createRoot(dispose => insert(mount, () => !clean() ? renderPortal()() : dispose(), null));
556
- onCleanup(() => {
557
- if (sharedConfig.context) queueMicrotask(cleanup);else cleanup();
558
- });
559
- } else {
560
- const container = createElement(props.isSVG ? "g" : "div", props.isSVG),
561
- renderRoot = useShadow && container.attachShadow ? container.attachShadow({
562
- mode: "open"
563
- }) : container;
564
- Object.defineProperty(container, "_$host", {
565
- get() {
566
- return marker.parentNode;
567
- },
568
- configurable: true
569
- });
570
- insert(renderRoot, renderPortal());
571
- mount.appendChild(container);
572
- props.ref && props.ref(container);
573
- onCleanup(() => mount.removeChild(container));
574
- }
581
+ createRenderEffect(() => {
582
+ const el = mount();
583
+ if (el instanceof HTMLHeadElement) {
584
+ const [clean, setClean] = createSignal(false);
585
+ const cleanup = () => setClean(true);
586
+ createRoot(dispose => insert(el, () => !clean() ? content() : dispose(), null));
587
+ onCleanup(() => {
588
+ if (sharedConfig.context) queueMicrotask(cleanup);else cleanup();
589
+ });
590
+ } else {
591
+ const container = createElement(props.isSVG ? "g" : "div", props.isSVG),
592
+ renderRoot = useShadow && container.attachShadow ? container.attachShadow({
593
+ mode: "open"
594
+ }) : container;
595
+ Object.defineProperty(container, "_$host", {
596
+ get() {
597
+ return marker.parentNode;
598
+ },
599
+ configurable: true
600
+ });
601
+ insert(renderRoot, content);
602
+ el.appendChild(container);
603
+ props.ref && props.ref(container);
604
+ onCleanup(() => el.removeChild(container));
605
+ }
606
+ });
575
607
  return marker;
576
608
  }
577
609
  function Dynamic(props) {
@@ -594,4 +626,4 @@ function Dynamic(props) {
594
626
  });
595
627
  }
596
628
 
597
- export { Aliases, voidFn as Assets, ChildProperties, DOMElements, DelegatedEvents, Dynamic, Hydration, voidFn as HydrationScript, NoHydration, Portal, PropAliases, Properties, SVGElements, SVGNamespace, addEventListener, assign, classList, className, clearDelegatedEvents, delegateEvents, dynamicProperty, escape, voidFn as generateHydrationScript, voidFn as getAssets, getHydrationKey, getNextElement, getNextMarker, getNextMatch, hydrate, innerHTML, insert, isServer, render, renderToStream, renderToString, renderToStringAsync, resolveSSRNode, runHydrationEvents, setAttribute, setAttributeNS, spread, ssr, ssrAttribute, ssrClassList, ssrElement, ssrHydrationKey, ssrSpread, ssrStyle, style, template, use, voidFn as useAssets };
629
+ export { Aliases, voidFn as Assets, ChildProperties, DOMElements, DelegatedEvents, Dynamic, Hydration, voidFn as HydrationScript, NoHydration, Portal, Properties, SVGElements, SVGNamespace, addEventListener, assign, classList, className, clearDelegatedEvents, delegateEvents, dynamicProperty, escape, voidFn as generateHydrationScript, voidFn as getAssets, getHydrationKey, getNextElement, getNextMarker, getNextMatch, getPropAlias, hydrate, innerHTML, insert, isDev, isServer, render, renderToStream, renderToString, renderToStringAsync, resolveSSRNode, runHydrationEvents, setAttribute, setAttributeNS, spread, ssr, ssrAttribute, ssrClassList, ssrElement, ssrHydrationKey, ssrSpread, ssrStyle, style, template, use, voidFn as useAssets };