solid-js 1.2.3 → 1.3.0-beta.1

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/web.js CHANGED
@@ -199,60 +199,41 @@ function insert(parent, accessor, marker, initial) {
199
199
  createRenderEffect(current => insertExpression(parent, accessor(), current, marker), initial);
200
200
  }
201
201
  function assign(node, props, isSVG, skipChildren, prevProps = {}) {
202
- let isCE, isProp, isChildProp;
202
+ for (const prop in prevProps) {
203
+ if (!(prop in props)) {
204
+ if (prop === "children") continue;
205
+ assignProp(node, prop, null, prevProps[prop], isSVG);
206
+ }
207
+ }
203
208
  for (const prop in props) {
204
209
  if (prop === "children") {
205
210
  if (!skipChildren) insertExpression(node, props.children);
206
211
  continue;
207
212
  }
208
213
  const value = props[prop];
209
- if (value === prevProps[prop]) continue;
210
- if (prop === "style") {
211
- style(node, value, prevProps[prop]);
212
- } else if (prop === "classList") {
213
- classList(node, value, prevProps[prop]);
214
- } else if (prop === "ref") {
215
- value(node);
216
- } else if (prop.slice(0, 3) === "on:") {
217
- node.addEventListener(prop.slice(3), value);
218
- } else if (prop.slice(0, 10) === "oncapture:") {
219
- node.addEventListener(prop.slice(10), value, true);
220
- } else if (prop.slice(0, 2) === "on") {
221
- const name = prop.slice(2).toLowerCase();
222
- const delegate = DelegatedEvents.has(name);
223
- addEventListener(node, name, value, delegate);
224
- delegate && delegateEvents([name]);
225
- } else if ((isChildProp = ChildProperties.has(prop)) || !isSVG && (PropAliases[prop] || (isProp = Properties.has(prop))) || (isCE = node.nodeName.includes("-"))) {
226
- if (isCE && !isProp && !isChildProp) node[toPropertyName(prop)] = value;else node[PropAliases[prop] || prop] = value;
227
- } else {
228
- const ns = isSVG && prop.indexOf(":") > -1 && SVGNamespace[prop.split(":")[0]];
229
- if (ns) setAttributeNS(node, ns, prop, value);else setAttribute(node, Aliases[prop] || prop, value);
230
- }
231
- prevProps[prop] = value;
214
+ prevProps[prop] = assignProp(node, prop, value, prevProps[prop], isSVG);
232
215
  }
233
216
  }
234
217
  function hydrate(code, element) {
235
- sharedConfig.resources = globalThis._$HYDRATION.resources;
236
- sharedConfig.completed = globalThis._$HYDRATION.completed;
237
- sharedConfig.events = globalThis._$HYDRATION.events;
218
+ if (!globalThis._$HY.sync) {
219
+ let dispose;
220
+ globalThis._$HY.queue.push(() => dispose = hydrate(code, element));
221
+ return () => dispose();
222
+ }
223
+ sharedConfig.completed = globalThis._$HY.completed;
224
+ sharedConfig.events = globalThis._$HY.events;
225
+ sharedConfig.load = globalThis._$HY.load;
226
+ sharedConfig.gather = root => gatherHydratable(element, root);
227
+ sharedConfig.registry = new Map();
238
228
  sharedConfig.context = {
239
229
  id: "",
240
- count: 0,
241
- loadResource: globalThis._$HYDRATION.loadResource
230
+ count: 0
242
231
  };
243
- sharedConfig.registry = new Map();
244
232
  gatherHydratable(element);
245
233
  const dispose = render(code, element, [...element.childNodes]);
246
234
  sharedConfig.context = null;
247
235
  return dispose;
248
236
  }
249
- function gatherHydratable(element) {
250
- const templates = element.querySelectorAll(`*[data-hk]`);
251
- for (let i = 0; i < templates.length; i++) {
252
- const node = templates[i];
253
- sharedConfig.registry.set(node.getAttribute("data-hk"), node);
254
- }
255
- }
256
237
  function getNextElement(template) {
257
238
  let node, key;
258
239
  if (!sharedConfig.context || !(node = sharedConfig.registry.get(key = getHydrationKey()))) {
@@ -310,6 +291,30 @@ function toggleClassKey(node, key, value) {
310
291
  const classNames = key.trim().split(/\s+/);
311
292
  for (let i = 0, nameLen = classNames.length; i < nameLen; i++) node.classList.toggle(classNames[i], value);
312
293
  }
294
+ function assignProp(node, prop, value, prev, isSVG) {
295
+ let isCE, isProp, isChildProp;
296
+ if (prop === "style") return style(node, value, prev);
297
+ if (prop === "classList") return classList(node, value, prev);
298
+ if (value === prev) return prev;
299
+ if (prop === "ref") {
300
+ value(node);
301
+ } else if (prop.slice(0, 3) === "on:") {
302
+ node.addEventListener(prop.slice(3), value);
303
+ } else if (prop.slice(0, 10) === "oncapture:") {
304
+ node.addEventListener(prop.slice(10), value, true);
305
+ } else if (prop.slice(0, 2) === "on") {
306
+ const name = prop.slice(2).toLowerCase();
307
+ const delegate = DelegatedEvents.has(name);
308
+ addEventListener(node, name, value, delegate);
309
+ delegate && delegateEvents([name]);
310
+ } else if ((isChildProp = ChildProperties.has(prop)) || !isSVG && (PropAliases[prop] || (isProp = Properties.has(prop))) || (isCE = node.nodeName.includes("-"))) {
311
+ if (isCE && !isProp && !isChildProp) node[toPropertyName(prop)] = value;else node[PropAliases[prop] || prop] = value;
312
+ } else {
313
+ const ns = isSVG && prop.indexOf(":") > -1 && SVGNamespace[prop.split(":")[0]];
314
+ if (ns) setAttributeNS(node, ns, prop, value);else setAttribute(node, Aliases[prop] || prop, value);
315
+ }
316
+ return value;
317
+ }
313
318
  function eventHandler(e) {
314
319
  const key = `$$${e.type}`;
315
320
  let node = e.composedPath && e.composedPath()[0] || e.target;
@@ -322,7 +327,7 @@ function eventHandler(e) {
322
327
  Object.defineProperty(e, "currentTarget", {
323
328
  configurable: true,
324
329
  get() {
325
- return node;
330
+ return node || document;
326
331
  }
327
332
  });
328
333
  while (node !== null) {
@@ -377,7 +382,12 @@ function insertExpression(parent, value, current, marker, unwrapArray) {
377
382
  createRenderEffect(() => current = insertExpression(parent, array, current, marker, true));
378
383
  return () => current;
379
384
  }
380
- if (sharedConfig.context && current && current.length) return current;
385
+ if (sharedConfig.context && current && current.length) {
386
+ for (let i; i < array.length; i++) {
387
+ if (array[i].parentNode) return array;
388
+ }
389
+ return current;
390
+ }
381
391
  if (array.length === 0) {
382
392
  current = cleanChildren(parent, current, marker);
383
393
  if (multi) return current;
@@ -445,6 +455,14 @@ function cleanChildren(parent, current, marker, replacement) {
445
455
  } else parent.insertBefore(node, marker);
446
456
  return [node];
447
457
  }
458
+ function gatherHydratable(element, root) {
459
+ const templates = element.querySelectorAll(`*[data-hk]`);
460
+ for (let i = 0; i < templates.length; i++) {
461
+ const node = templates[i];
462
+ const key = node.getAttribute("data-hk");
463
+ if (!root || key.startsWith(root)) sharedConfig.registry.set(key, node);
464
+ }
465
+ }
448
466
  function getHydrationKey() {
449
467
  const hydrate = sharedConfig.context;
450
468
  return `${hydrate.id}${hydrate.count++}`;
@@ -528,4 +546,4 @@ function Dynamic(props) {
528
546
  });
529
547
  }
530
548
 
531
- export { Aliases, Assets, ChildProperties, DelegatedEvents, Dynamic, Assets as HydrationScript, NoHydration, Portal, PropAliases, Properties, SVGElements, SVGNamespace, addEventListener, assign, classList, clearDelegatedEvents, delegateEvents, dynamicProperty, escape, gatherHydratable, generateHydrationScript, getHydrationKey, getNextElement, getNextMarker, getNextMatch, hydrate, insert, isServer, memo, pipeToNodeWritable, pipeToWritable, render, renderToString, renderToStringAsync, resolveSSRNode, runHydrationEvents, setAttribute, setAttributeNS, spread, ssr, ssrBoolean, ssrClassList, ssrHydrationKey, ssrSpread, ssrStyle, style, template };
549
+ export { Aliases, Assets, ChildProperties, DelegatedEvents, Dynamic, Assets as HydrationScript, NoHydration, Portal, PropAliases, Properties, SVGElements, SVGNamespace, addEventListener, assign, classList, clearDelegatedEvents, delegateEvents, dynamicProperty, escape, generateHydrationScript, getHydrationKey, getNextElement, getNextMarker, getNextMatch, hydrate, insert, isServer, memo, pipeToNodeWritable, pipeToWritable, render, renderToString, renderToStringAsync, resolveSSRNode, runHydrationEvents, setAttribute, setAttributeNS, spread, ssr, ssrBoolean, ssrClassList, ssrHydrationKey, ssrSpread, ssrStyle, style, template };
@@ -46,7 +46,6 @@ export function mergeProps(...sources: unknown[]): unknown;
46
46
  export function dynamicProperty(props: unknown, key: string): unknown;
47
47
 
48
48
  export function hydrate(fn: () => JSX.Element, node: MountableElement): () => void;
49
- export function gatherHydratable(node: Element): void;
50
49
  export function getHydrationKey(): string;
51
50
  export function getNextElement(template?: HTMLTemplateElement): Element;
52
51
  export function getNextMatch(start: Node, elementName: string): Element;
@@ -1,3 +1,3 @@
1
- import { createRoot, createRenderEffect, createComponent, getOwner, sharedConfig, awaitSuspense } from "../..";
1
+ import { createRoot, createRenderEffect, createComponent, getOwner, sharedConfig } from "../..";
2
2
  declare function memo<T>(fn: () => T, equals: boolean): import("../..").Accessor<T>;
3
- export { getOwner, createComponent, createRoot as root, createRenderEffect as effect, memo, sharedConfig, awaitSuspense as asyncWrap };
3
+ export { getOwner, createComponent, createRoot as root, createRenderEffect as effect, memo, sharedConfig };