|
|
|
|
@ -163,7 +163,7 @@ export default class ElementWrapper extends Wrapper {
|
|
|
|
|
) {
|
|
|
|
|
super(renderer, block, parent, node);
|
|
|
|
|
|
|
|
|
|
if (node.is_dynamic_element && block.type !== CHILD_DYNAMIC_ELEMENT_BLOCK) {
|
|
|
|
|
if ((node.display || node.is_dynamic_element) && block.type !== CHILD_DYNAMIC_ELEMENT_BLOCK) {
|
|
|
|
|
this.child_dynamic_element_block = block.child({
|
|
|
|
|
comment: create_debugging_comment(node, renderer.component),
|
|
|
|
|
name: renderer.component.get_unique_name('create_dynamic_element'),
|
|
|
|
|
@ -273,15 +273,15 @@ export default class ElementWrapper extends Wrapper {
|
|
|
|
|
(x`#nodes` as unknown) as Identifier
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const previous_tag = block.get_unique_name('previous_tag');
|
|
|
|
|
|
|
|
|
|
const tag = this.node.tag_expr.manipulate(block);
|
|
|
|
|
block.add_variable(previous_tag, tag);
|
|
|
|
|
|
|
|
|
|
if (this.renderer.options.dev) {
|
|
|
|
|
block.chunks.init.push(b`
|
|
|
|
|
${this.renderer.options.dev && b`@validate_dynamic_element(${tag});`}
|
|
|
|
|
${this.renderer.options.dev && this.node.children.length > 0 && b`@validate_void_dynamic_element(${tag});`}
|
|
|
|
|
let ${this.var} = ${tag} && ${this.child_dynamic_element_block.name}(#ctx);
|
|
|
|
|
@validate_dynamic_element(${tag});
|
|
|
|
|
@validate_void_dynamic_element(${tag});
|
|
|
|
|
`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
block.chunks.create.push(b`
|
|
|
|
|
if (${this.var}) ${this.var}.c();
|
|
|
|
|
@ -297,6 +297,14 @@ export default class ElementWrapper extends Wrapper {
|
|
|
|
|
if (${this.var}) ${this.var}.m(${parent_node || '#target'}, ${parent_node ? 'null' : '#anchor'});
|
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
if (this.node.display && tag.type === 'Literal') {
|
|
|
|
|
block.chunks.init.push(b`const ${this.var} = ${this.child_dynamic_element_block.name}(#ctx);`);
|
|
|
|
|
block.chunks.update.push(b`${this.var}.p(#ctx, #dirty);`);
|
|
|
|
|
} else {
|
|
|
|
|
const previous_tag = block.get_unique_name('previous_tag');
|
|
|
|
|
block.add_variable(previous_tag, tag);
|
|
|
|
|
block.chunks.init.push(b`let ${this.var} = ${tag} && ${this.child_dynamic_element_block.name}(#ctx);`);
|
|
|
|
|
|
|
|
|
|
const anchor = this.get_or_create_anchor(block, parent_node, parent_nodes);
|
|
|
|
|
const has_transitions = !!(this.node.intro || this.node.outro);
|
|
|
|
|
const not_equal = this.renderer.component.component_options.immutable ? x`@not_equal` : x`@safe_not_equal`;
|
|
|
|
|
@ -336,6 +344,9 @@ export default class ElementWrapper extends Wrapper {
|
|
|
|
|
}
|
|
|
|
|
${previous_tag} = ${tag};
|
|
|
|
|
`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.child_dynamic_element_block.has_intros) {
|
|
|
|
|
block.chunks.intro.push(b`@transition_in(${this.var});`);
|
|
|
|
|
@ -480,6 +491,7 @@ export default class ElementWrapper extends Wrapper {
|
|
|
|
|
this.add_animation(block);
|
|
|
|
|
this.add_classes(block);
|
|
|
|
|
this.add_styles(block);
|
|
|
|
|
this.add_display(block);
|
|
|
|
|
this.add_manual_style_scoping(block);
|
|
|
|
|
|
|
|
|
|
if (nodes && this.renderer.options.hydratable && !this.void) {
|
|
|
|
|
@ -1129,6 +1141,45 @@ export default class ElementWrapper extends Wrapper {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
add_display(block: Block) {
|
|
|
|
|
const display = this.node.display;
|
|
|
|
|
if (display === null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const snippet = display.expression.manipulate(block);
|
|
|
|
|
const dependencies = display.expression.dynamic_dependencies();
|
|
|
|
|
const has_dependancies = dependencies.length > 0;
|
|
|
|
|
|
|
|
|
|
const update_display = b`@set_display(${this.var}, ${snippet})`;
|
|
|
|
|
block.chunks.hydrate.push(update_display);
|
|
|
|
|
|
|
|
|
|
if (has_dependancies) {
|
|
|
|
|
const update_current = (this.node.intro || this.node.outro)
|
|
|
|
|
? x`#current = false`
|
|
|
|
|
: null;
|
|
|
|
|
|
|
|
|
|
const dirty = block.renderer.dirty(Array.from(dependencies));
|
|
|
|
|
block.chunks.update.push(b`
|
|
|
|
|
if (${dirty}) {
|
|
|
|
|
if (${snippet}) {
|
|
|
|
|
${update_current}
|
|
|
|
|
${update_display}
|
|
|
|
|
@transition_in(this, 1);
|
|
|
|
|
} else {
|
|
|
|
|
@group_outros();
|
|
|
|
|
@transition_out(this, 1, 0, () => {
|
|
|
|
|
${update_display}
|
|
|
|
|
});
|
|
|
|
|
@check_outros();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
add_manual_style_scoping(block) {
|
|
|
|
|
if (this.node.needs_manual_style_scoping) {
|
|
|
|
|
const updater = b`@toggle_class(${this.var}, "${this.node.component.stylesheet.id}", true);`;
|
|
|
|
|
|