|
|
|
@ -174,6 +174,8 @@ export default class ElementWrapper extends Wrapper {
|
|
|
|
child_dynamic_element_block?: Block = null;
|
|
|
|
child_dynamic_element_block?: Block = null;
|
|
|
|
child_dynamic_element?: ElementWrapper = null;
|
|
|
|
child_dynamic_element?: ElementWrapper = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
element_data_name = null;
|
|
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
constructor(
|
|
|
|
renderer: Renderer,
|
|
|
|
renderer: Renderer,
|
|
|
|
block: Block,
|
|
|
|
block: Block,
|
|
|
|
@ -287,6 +289,8 @@ export default class ElementWrapper extends Wrapper {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.fragment = new FragmentWrapper(renderer, block, node.children, this, strip_whitespace, next_sibling);
|
|
|
|
this.fragment = new FragmentWrapper(renderer, block, node.children, this, strip_whitespace, next_sibling);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.element_data_name = block.get_unique_name(`${this.var.name}_data`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
render(block: Block, parent_node: Identifier, parent_nodes: Identifier) {
|
|
|
|
render(block: Block, parent_node: Identifier, parent_nodes: Identifier) {
|
|
|
|
@ -516,7 +520,8 @@ export default class ElementWrapper extends Wrapper {
|
|
|
|
child.render(
|
|
|
|
child.render(
|
|
|
|
block,
|
|
|
|
block,
|
|
|
|
is_template ? x`${node}.content` : node,
|
|
|
|
is_template ? x`${node}.content` : node,
|
|
|
|
nodes
|
|
|
|
nodes,
|
|
|
|
|
|
|
|
{ element_data_name: this.element_data_name }
|
|
|
|
);
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -824,7 +829,6 @@ export default class ElementWrapper extends Wrapper {
|
|
|
|
|
|
|
|
|
|
|
|
add_spread_attributes(block: Block) {
|
|
|
|
add_spread_attributes(block: Block) {
|
|
|
|
const levels = block.get_unique_name(`${this.var.name}_levels`);
|
|
|
|
const levels = block.get_unique_name(`${this.var.name}_levels`);
|
|
|
|
const data = block.get_unique_name(`${this.var.name}_data`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const initial_props = [];
|
|
|
|
const initial_props = [];
|
|
|
|
const updates = [];
|
|
|
|
const updates = [];
|
|
|
|
@ -855,9 +859,9 @@ export default class ElementWrapper extends Wrapper {
|
|
|
|
block.chunks.init.push(b`
|
|
|
|
block.chunks.init.push(b`
|
|
|
|
let ${levels} = [${initial_props}];
|
|
|
|
let ${levels} = [${initial_props}];
|
|
|
|
|
|
|
|
|
|
|
|
let ${data} = {};
|
|
|
|
let ${this.element_data_name} = {};
|
|
|
|
for (let #i = 0; #i < ${levels}.length; #i += 1) {
|
|
|
|
for (let #i = 0; #i < ${levels}.length; #i += 1) {
|
|
|
|
${data} = @assign(${data}, ${levels}[#i]);
|
|
|
|
${this.element_data_name} = @assign(${this.element_data_name}, ${levels}[#i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
|
|
@ -868,13 +872,13 @@ export default class ElementWrapper extends Wrapper {
|
|
|
|
? x`@set_dynamic_element_data(${this.node.tag_expr.manipulate(block)})`
|
|
|
|
? x`@set_dynamic_element_data(${this.node.tag_expr.manipulate(block)})`
|
|
|
|
: x`@set_attributes`;
|
|
|
|
: x`@set_attributes`;
|
|
|
|
|
|
|
|
|
|
|
|
block.chunks.hydrate.push(
|
|
|
|
block.chunks.hydrate.unshift(
|
|
|
|
b`${fn}(${this.var}, ${data});`
|
|
|
|
b`${fn}(${this.var}, ${this.element_data_name});`
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (this.has_dynamic_attribute) {
|
|
|
|
if (this.has_dynamic_attribute) {
|
|
|
|
block.chunks.update.push(b`
|
|
|
|
block.chunks.update.unshift(b`
|
|
|
|
${fn}(${this.var}, ${data} = @get_spread_update(${levels}, [
|
|
|
|
${fn}(${this.var}, ${this.element_data_name} = @get_spread_update(${levels}, [
|
|
|
|
${updates}
|
|
|
|
${updates}
|
|
|
|
]));
|
|
|
|
]));
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
@ -890,23 +894,23 @@ export default class ElementWrapper extends Wrapper {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
block.chunks.mount.push(b`
|
|
|
|
block.chunks.mount.push(b`
|
|
|
|
'value' in ${data} && (${data}.multiple ? @select_options : @select_option)(${this.var}, ${data}.value);
|
|
|
|
'value' in ${this.element_data_name} && (${this.element_data_name}.multiple ? @select_options : @select_option)(${this.var}, ${this.element_data_name}.value);
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
|
|
block.chunks.update.push(b`
|
|
|
|
block.chunks.update.push(b`
|
|
|
|
if (${block.renderer.dirty(Array.from(dependencies))} && 'value' in ${data}) (${data}.multiple ? @select_options : @select_option)(${this.var}, ${data}.value);
|
|
|
|
if (${block.renderer.dirty(Array.from(dependencies))} && 'value' in ${this.element_data_name}) (${this.element_data_name}.multiple ? @select_options : @select_option)(${this.var}, ${this.element_data_name}.value);
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
} else if (this.node.name === 'input' && this.attributes.find(attr => attr.node.name === 'value')) {
|
|
|
|
} else if (this.node.name === 'input' && this.attributes.find(attr => attr.node.name === 'value')) {
|
|
|
|
const type = this.node.get_static_attribute_value('type');
|
|
|
|
const type = this.node.get_static_attribute_value('type');
|
|
|
|
if (type === null || type === '' || type === 'text' || type === 'email' || type === 'password') {
|
|
|
|
if (type === null || type === '' || type === 'text' || type === 'email' || type === 'password') {
|
|
|
|
block.chunks.mount.push(b`
|
|
|
|
block.chunks.mount.push(b`
|
|
|
|
if ('value' in ${data}) {
|
|
|
|
if ('value' in ${this.element_data_name}) {
|
|
|
|
${this.var}.value = ${data}.value;
|
|
|
|
${this.var}.value = ${this.element_data_name}.value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
block.chunks.update.push(b`
|
|
|
|
block.chunks.update.push(b`
|
|
|
|
if ('value' in ${data}) {
|
|
|
|
if ('value' in ${this.element_data_name}) {
|
|
|
|
${this.var}.value = ${data}.value;
|
|
|
|
${this.var}.value = ${this.element_data_name}.value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -1232,7 +1236,6 @@ export default class ElementWrapper extends Wrapper {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|