|
|
|
@ -8,7 +8,6 @@ import handle_select_value_binding from './handle_select_value_binding';
|
|
|
|
import { regex_box_size } from '../../../../utils/patterns';
|
|
|
|
import { regex_box_size } from '../../../../utils/patterns';
|
|
|
|
/** */
|
|
|
|
/** */
|
|
|
|
export default class BindingWrapper {
|
|
|
|
export default class BindingWrapper {
|
|
|
|
|
|
|
|
|
|
|
|
/** @type {import('../../../nodes/Binding.js').default} */
|
|
|
|
/** @type {import('../../../nodes/Binding.js').default} */
|
|
|
|
node = undefined;
|
|
|
|
node = undefined;
|
|
|
|
|
|
|
|
|
|
|
|
@ -59,7 +58,13 @@ export default class BindingWrapper {
|
|
|
|
this.binding_group = get_binding_group(parent.renderer, this, block);
|
|
|
|
this.binding_group = get_binding_group(parent.renderer, this, block);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// view to model
|
|
|
|
// view to model
|
|
|
|
this.handler = get_event_handler(this, parent.renderer, block, this.object, this.node.raw_expression);
|
|
|
|
this.handler = get_event_handler(
|
|
|
|
|
|
|
|
this,
|
|
|
|
|
|
|
|
parent.renderer,
|
|
|
|
|
|
|
|
block,
|
|
|
|
|
|
|
|
this.object,
|
|
|
|
|
|
|
|
this.node.raw_expression
|
|
|
|
|
|
|
|
);
|
|
|
|
this.snippet = this.node.expression.manipulate(block);
|
|
|
|
this.snippet = this.node.expression.manipulate(block);
|
|
|
|
this.is_readonly = this.node.is_readonly;
|
|
|
|
this.is_readonly = this.node.is_readonly;
|
|
|
|
this.needs_lock = this.node.name === 'currentTime'; // TODO others?
|
|
|
|
this.needs_lock = this.node.name === 'currentTime'; // TODO others?
|
|
|
|
@ -86,13 +91,13 @@ export default class BindingWrapper {
|
|
|
|
this.node.expression.template_scope.dependencies_for_name
|
|
|
|
this.node.expression.template_scope.dependencies_for_name
|
|
|
|
.get(object)
|
|
|
|
.get(object)
|
|
|
|
.forEach((name) => dependencies.add(name));
|
|
|
|
.forEach((name) => dependencies.add(name));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
else {
|
|
|
|
|
|
|
|
dependencies.add(object);
|
|
|
|
dependencies.add(object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const result = new Set(dependencies);
|
|
|
|
const result = new Set(dependencies);
|
|
|
|
dependencies.forEach((dependency) => {
|
|
|
|
dependencies.forEach((dependency) => {
|
|
|
|
const indirect_dependencies = this.parent.renderer.component.indirect_dependencies.get(dependency);
|
|
|
|
const indirect_dependencies =
|
|
|
|
|
|
|
|
this.parent.renderer.component.indirect_dependencies.get(dependency);
|
|
|
|
if (indirect_dependencies) {
|
|
|
|
if (indirect_dependencies) {
|
|
|
|
indirect_dependencies.forEach((indirect_dependency) => {
|
|
|
|
indirect_dependencies.forEach((indirect_dependency) => {
|
|
|
|
result.add(indirect_dependency);
|
|
|
|
result.add(indirect_dependency);
|
|
|
|
@ -110,8 +115,7 @@ export default class BindingWrapper {
|
|
|
|
* @param {import('estree').Identifier} lock
|
|
|
|
* @param {import('estree').Identifier} lock
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
render(block, lock) {
|
|
|
|
render(block, lock) {
|
|
|
|
if (this.is_readonly)
|
|
|
|
if (this.is_readonly) return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
const { parent } = this;
|
|
|
|
const { parent } = this;
|
|
|
|
|
|
|
|
|
|
|
|
/** @type {any[]} */
|
|
|
|
/** @type {any[]} */
|
|
|
|
@ -128,16 +132,17 @@ export default class BindingWrapper {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (parent.node.name === 'input') {
|
|
|
|
if (parent.node.name === 'input') {
|
|
|
|
const type = parent.node.get_static_attribute_value('type');
|
|
|
|
const type = parent.node.get_static_attribute_value('type');
|
|
|
|
if (type === null ||
|
|
|
|
if (
|
|
|
|
|
|
|
|
type === null ||
|
|
|
|
type === '' ||
|
|
|
|
type === '' ||
|
|
|
|
type === 'text' ||
|
|
|
|
type === 'text' ||
|
|
|
|
type === 'email' ||
|
|
|
|
type === 'email' ||
|
|
|
|
type === 'password' ||
|
|
|
|
type === 'password' ||
|
|
|
|
type === 'search' ||
|
|
|
|
type === 'search' ||
|
|
|
|
type === 'url') {
|
|
|
|
type === 'url'
|
|
|
|
|
|
|
|
) {
|
|
|
|
update_conditions.push(x`${parent.var}.${this.node.name} !== ${this.snippet}`);
|
|
|
|
update_conditions.push(x`${parent.var}.${this.node.name} !== ${this.snippet}`);
|
|
|
|
}
|
|
|
|
} else if (type === 'number') {
|
|
|
|
else if (type === 'number') {
|
|
|
|
|
|
|
|
update_conditions.push(x`@to_number(${parent.var}.${this.node.name}) !== ${this.snippet}`);
|
|
|
|
update_conditions.push(x`@to_number(${parent.var}.${this.node.name}) !== ${this.snippet}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -149,8 +154,9 @@ export default class BindingWrapper {
|
|
|
|
case 'group': {
|
|
|
|
case 'group': {
|
|
|
|
block.renderer.add_to_context('$$binding_groups');
|
|
|
|
block.renderer.add_to_context('$$binding_groups');
|
|
|
|
this.binding_group.add_element(block, this.parent.var);
|
|
|
|
this.binding_group.add_element(block, this.parent.var);
|
|
|
|
if (( /** @type {import('../Element.js').default} */(this.parent)).has_dynamic_value) {
|
|
|
|
if (/** @type {import('../Element.js').default} */ (this.parent).has_dynamic_value) {
|
|
|
|
update_or_condition = ( /** @type {import('../Element.js').default} */(this.parent)).dynamic_value_condition;
|
|
|
|
update_or_condition = /** @type {import('../Element.js').default} */ (this.parent)
|
|
|
|
|
|
|
|
.dynamic_value_condition;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -193,15 +199,13 @@ export default class BindingWrapper {
|
|
|
|
if (update_dom) {
|
|
|
|
if (update_dom) {
|
|
|
|
if (update_conditions.length > 0) {
|
|
|
|
if (update_conditions.length > 0) {
|
|
|
|
let condition = update_conditions.reduce((lhs, rhs) => x`${lhs} && ${rhs}`);
|
|
|
|
let condition = update_conditions.reduce((lhs, rhs) => x`${lhs} && ${rhs}`);
|
|
|
|
if (update_or_condition)
|
|
|
|
if (update_or_condition) condition = x`${update_or_condition} || (${condition})`;
|
|
|
|
condition = x `${update_or_condition} || (${condition})`;
|
|
|
|
|
|
|
|
block.chunks.update.push(b`
|
|
|
|
block.chunks.update.push(b`
|
|
|
|
if (${condition}) {
|
|
|
|
if (${condition}) {
|
|
|
|
${update_dom}
|
|
|
|
${update_dom}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
else {
|
|
|
|
|
|
|
|
block.chunks.update.push(update_dom);
|
|
|
|
block.chunks.update.push(update_dom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -213,8 +217,7 @@ export default class BindingWrapper {
|
|
|
|
${mount_dom}
|
|
|
|
${mount_dom}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
else {
|
|
|
|
|
|
|
|
block.chunks.mount.push(mount_dom);
|
|
|
|
block.chunks.mount.push(mount_dom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -243,7 +246,8 @@ function get_dom_updater(element, binding, mounting) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (binding.node.name === 'group') {
|
|
|
|
if (binding.node.name === 'group') {
|
|
|
|
const type = node.get_static_attribute_value('type');
|
|
|
|
const type = node.get_static_attribute_value('type');
|
|
|
|
const condition = type === 'checkbox'
|
|
|
|
const condition =
|
|
|
|
|
|
|
|
type === 'checkbox'
|
|
|
|
? x`~(${binding.snippet} || []).indexOf(${element.var}.__value)`
|
|
|
|
? x`~(${binding.snippet} || []).indexOf(${element.var}.__value)`
|
|
|
|
: x`${element.var}.__value === ${binding.snippet}`;
|
|
|
|
: x`${element.var}.__value === ${binding.snippet}`;
|
|
|
|
return b`${element.var}.checked = ${condition};`;
|
|
|
|
return b`${element.var}.checked = ${condition};`;
|
|
|
|
@ -287,8 +291,7 @@ function get_binding_group(renderer, binding, block) {
|
|
|
|
if (context) {
|
|
|
|
if (context) {
|
|
|
|
key = context.object.name;
|
|
|
|
key = context.object.name;
|
|
|
|
name = context.property.name;
|
|
|
|
name = context.property.name;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
else {
|
|
|
|
|
|
|
|
key = dep;
|
|
|
|
key = dep;
|
|
|
|
name = dep;
|
|
|
|
name = dep;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -346,11 +349,18 @@ function get_binding_group(renderer, binding, block) {
|
|
|
|
type: 'ArrayExpression',
|
|
|
|
type: 'ArrayExpression',
|
|
|
|
elements: contexts.map((name) => block.renderer.reference(name))
|
|
|
|
elements: contexts.map((name) => block.renderer.reference(name))
|
|
|
|
};
|
|
|
|
};
|
|
|
|
block.chunks.init.push(b `${local_name} = @init_binding_group_dynamic(${binding_group}[${index}], ${indexes})`);
|
|
|
|
block.chunks.init.push(
|
|
|
|
block.chunks.update.push(b `if (${block.renderer.dirty(Array.from(list_dependencies))}) ${local_name}.u(${indexes})`);
|
|
|
|
b`${local_name} = @init_binding_group_dynamic(${binding_group}[${index}], ${indexes})`
|
|
|
|
}
|
|
|
|
);
|
|
|
|
else {
|
|
|
|
block.chunks.update.push(
|
|
|
|
block.chunks.init.push(b `${local_name} = @init_binding_group(${binding_group}[${index}])`);
|
|
|
|
b`if (${block.renderer.dirty(
|
|
|
|
|
|
|
|
Array.from(list_dependencies)
|
|
|
|
|
|
|
|
)}) ${local_name}.u(${indexes})`
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
block.chunks.init.push(
|
|
|
|
|
|
|
|
b`${local_name} = @init_binding_group(${binding_group}[${index}])`
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
block.chunks.hydrate.push(b`${local_name}.p(${elements.get(block)})`);
|
|
|
|
block.chunks.hydrate.push(b`${local_name}.p(${elements.get(block)})`);
|
|
|
|
block.chunks.destroy.push(b`${local_name}.r()`);
|
|
|
|
block.chunks.destroy.push(b`${local_name}.r()`);
|
|
|
|
@ -386,8 +396,7 @@ function get_event_handler(binding, renderer, block, name, lhs) {
|
|
|
|
if (store) {
|
|
|
|
if (store) {
|
|
|
|
set_store = b`${store}.set(${`$${store}`});`;
|
|
|
|
set_store = b`${store}.set(${`$${store}`});`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
else {
|
|
|
|
|
|
|
|
const object = get_object(lhs);
|
|
|
|
const object = get_object(lhs);
|
|
|
|
if (object.name[0] === '$') {
|
|
|
|
if (object.name[0] === '$') {
|
|
|
|
const store = object.name.slice(1);
|
|
|
|
const store = object.name.slice(1);
|
|
|
|
@ -449,7 +458,3 @@ function get_value_from_dom(_renderer, element, binding, contextual_dependencies
|
|
|
|
// everything else
|
|
|
|
// everything else
|
|
|
|
return x`this.${name}`;
|
|
|
|
return x`this.${name}`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|