|
|
@ -1,5 +1,5 @@
|
|
|
|
import { namespace_svg } from '../../../../constants.js';
|
|
|
|
import { namespace_svg } from '../../../../constants.js';
|
|
|
|
import { hydrate_anchor, hydrate_start, hydrating } from '../hydration.js';
|
|
|
|
import { hydrating, set_hydrate_nodes } from '../hydration.js';
|
|
|
|
import { empty } from '../operations.js';
|
|
|
|
import { empty } from '../operations.js';
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
block,
|
|
|
|
block,
|
|
|
@ -37,7 +37,7 @@ function swap_block_dom(effect, from, to) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param {Comment} anchor
|
|
|
|
* @param {Comment | Element} node
|
|
|
|
* @param {() => string} get_tag
|
|
|
|
* @param {() => string} get_tag
|
|
|
|
* @param {boolean} is_svg
|
|
|
|
* @param {boolean} is_svg
|
|
|
|
* @param {undefined | ((element: Element, anchor: Node | null) => void)} render_fn,
|
|
|
|
* @param {undefined | ((element: Element, anchor: Node | null) => void)} render_fn,
|
|
|
@ -45,7 +45,7 @@ function swap_block_dom(effect, from, to) {
|
|
|
|
* @param {undefined | [number, number]} location
|
|
|
|
* @param {undefined | [number, number]} location
|
|
|
|
* @returns {void}
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export function element(anchor, get_tag, is_svg, render_fn, get_namespace, location) {
|
|
|
|
export function element(node, get_tag, is_svg, render_fn, get_namespace, location) {
|
|
|
|
const parent_effect = /** @type {import('#client').Effect} */ (current_effect);
|
|
|
|
const parent_effect = /** @type {import('#client').Effect} */ (current_effect);
|
|
|
|
const filename = DEV && location && current_component_context?.function.filename;
|
|
|
|
const filename = DEV && location && current_component_context?.function.filename;
|
|
|
|
|
|
|
|
|
|
|
@ -56,7 +56,9 @@ export function element(anchor, get_tag, is_svg, render_fn, get_namespace, locat
|
|
|
|
let current_tag;
|
|
|
|
let current_tag;
|
|
|
|
|
|
|
|
|
|
|
|
/** @type {null | Element} */
|
|
|
|
/** @type {null | Element} */
|
|
|
|
let element = null;
|
|
|
|
let element = hydrating && node.nodeType === 1 ? /** @type {Element} */ (node) : null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let anchor = /** @type {Comment} */ (hydrating && element ? element.nextSibling : node);
|
|
|
|
|
|
|
|
|
|
|
|
/** @type {import('#client').Effect | null} */
|
|
|
|
/** @type {import('#client').Effect | null} */
|
|
|
|
let effect;
|
|
|
|
let effect;
|
|
|
@ -75,6 +77,7 @@ export function element(anchor, get_tag, is_svg, render_fn, get_namespace, locat
|
|
|
|
: is_svg || next_tag === 'svg'
|
|
|
|
: is_svg || next_tag === 'svg'
|
|
|
|
? namespace_svg
|
|
|
|
? namespace_svg
|
|
|
|
: null;
|
|
|
|
: null;
|
|
|
|
|
|
|
|
|
|
|
|
// Assumption: Noone changes the namespace but not the tag (what would that even mean?)
|
|
|
|
// Assumption: Noone changes the namespace but not the tag (what would that even mean?)
|
|
|
|
if (next_tag === tag) return;
|
|
|
|
if (next_tag === tag) return;
|
|
|
|
|
|
|
|
|
|
|
@ -104,7 +107,7 @@ export function element(anchor, get_tag, is_svg, render_fn, get_namespace, locat
|
|
|
|
effect = branch(() => {
|
|
|
|
effect = branch(() => {
|
|
|
|
const prev_element = element;
|
|
|
|
const prev_element = element;
|
|
|
|
element = hydrating
|
|
|
|
element = hydrating
|
|
|
|
? /** @type {Element} */ (hydrate_start)
|
|
|
|
? /** @type {Element} */ (element)
|
|
|
|
: ns
|
|
|
|
: ns
|
|
|
|
? document.createElementNS(ns, next_tag)
|
|
|
|
? document.createElementNS(ns, next_tag)
|
|
|
|
: document.createElement(next_tag);
|
|
|
|
: document.createElement(next_tag);
|
|
|
@ -123,9 +126,13 @@ export function element(anchor, get_tag, is_svg, render_fn, get_namespace, locat
|
|
|
|
if (render_fn) {
|
|
|
|
if (render_fn) {
|
|
|
|
// If hydrating, use the existing ssr comment as the anchor so that the
|
|
|
|
// If hydrating, use the existing ssr comment as the anchor so that the
|
|
|
|
// inner open and close methods can pick up the existing nodes correctly
|
|
|
|
// inner open and close methods can pick up the existing nodes correctly
|
|
|
|
var child_anchor = hydrating
|
|
|
|
var child_anchor = hydrating ? element.lastChild : element.appendChild(empty());
|
|
|
|
? element.firstChild && hydrate_anchor(/** @type {Comment} */ (element.firstChild))
|
|
|
|
|
|
|
|
: element.appendChild(empty());
|
|
|
|
if (hydrating && child_anchor) {
|
|
|
|
|
|
|
|
set_hydrate_nodes(
|
|
|
|
|
|
|
|
/** @type {import('#client').TemplateNode[]} */ ([...element.childNodes]).slice(0, -1)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// `child_anchor` is undefined if this is a void element, but we still
|
|
|
|
// `child_anchor` is undefined if this is a void element, but we still
|
|
|
|
// need to call `render_fn` in order to run actions etc. If the element
|
|
|
|
// need to call `render_fn` in order to run actions etc. If the element
|
|
|
@ -136,12 +143,14 @@ export function element(anchor, get_tag, is_svg, render_fn, get_namespace, locat
|
|
|
|
|
|
|
|
|
|
|
|
anchor.before(element);
|
|
|
|
anchor.before(element);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!hydrating) {
|
|
|
|
if (prev_element) {
|
|
|
|
if (prev_element) {
|
|
|
|
swap_block_dom(parent_effect, prev_element, element);
|
|
|
|
swap_block_dom(parent_effect, prev_element, element);
|
|
|
|
prev_element.remove();
|
|
|
|
prev_element.remove();
|
|
|
|
} else if (!hydrating) {
|
|
|
|
} else {
|
|
|
|
push_template_node(element, parent_effect);
|
|
|
|
push_template_node(element, parent_effect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|