|
|
@ -1,8 +1,8 @@
|
|
|
|
import attributeLookup from './lookup.js';
|
|
|
|
import attributeLookup from './lookup.js';
|
|
|
|
import addElementBinding from './addElementBinding';
|
|
|
|
import addElementBinding from './addElementBinding';
|
|
|
|
import deindent from '../../../../utils/deindent.js';
|
|
|
|
import deindent from '../../../../../utils/deindent.js';
|
|
|
|
import flattenReference from '../../../../utils/flattenReference.js';
|
|
|
|
import flattenReference from '../../../../../utils/flattenReference.js';
|
|
|
|
import getStaticAttributeValue from './binding/getStaticAttributeValue.js';
|
|
|
|
import getStaticAttributeValue from './getStaticAttributeValue.js';
|
|
|
|
|
|
|
|
|
|
|
|
export default function addElementAttributes ( generator, block, state, node, local ) {
|
|
|
|
export default function addElementAttributes ( generator, block, state, node, local ) {
|
|
|
|
node.attributes.forEach( attribute => {
|
|
|
|
node.attributes.forEach( attribute => {
|
|
|
@ -31,11 +31,11 @@ export default function addElementAttributes ( generator, block, state, node, lo
|
|
|
|
if ( attribute.value === true ) {
|
|
|
|
if ( attribute.value === true ) {
|
|
|
|
// attributes without values, e.g. <textarea readonly>
|
|
|
|
// attributes without values, e.g. <textarea readonly>
|
|
|
|
if ( propertyName ) {
|
|
|
|
if ( propertyName ) {
|
|
|
|
local.create.addLine(
|
|
|
|
block.builders.create.addLine(
|
|
|
|
`${state.parentNode}.${propertyName} = true;`
|
|
|
|
`${state.parentNode}.${propertyName} = true;`
|
|
|
|
);
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
local.create.addLine(
|
|
|
|
block.builders.create.addLine(
|
|
|
|
`${generator.helper( method )}( ${state.parentNode}, '${name}', true );`
|
|
|
|
`${generator.helper( method )}( ${state.parentNode}, '${name}', true );`
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -48,11 +48,11 @@ export default function addElementAttributes ( generator, block, state, node, lo
|
|
|
|
|
|
|
|
|
|
|
|
else if ( attribute.value.length === 0 ) {
|
|
|
|
else if ( attribute.value.length === 0 ) {
|
|
|
|
if ( propertyName ) {
|
|
|
|
if ( propertyName ) {
|
|
|
|
local.create.addLine(
|
|
|
|
block.builders.create.addLine(
|
|
|
|
`${state.parentNode}.${propertyName} = '';`
|
|
|
|
`${state.parentNode}.${propertyName} = '';`
|
|
|
|
);
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
local.create.addLine(
|
|
|
|
block.builders.create.addLine(
|
|
|
|
`${generator.helper( method )}( ${state.parentNode}, '${name}', '' );`
|
|
|
|
`${generator.helper( method )}( ${state.parentNode}, '${name}', '' );`
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -74,7 +74,7 @@ export default function addElementAttributes ( generator, block, state, node, lo
|
|
|
|
state.namespace = value.data;
|
|
|
|
state.namespace = value.data;
|
|
|
|
addAttribute = true;
|
|
|
|
addAttribute = true;
|
|
|
|
} else if ( propertyName ) {
|
|
|
|
} else if ( propertyName ) {
|
|
|
|
local.create.addLine(
|
|
|
|
block.builders.create.addLine(
|
|
|
|
`${state.parentNode}.${propertyName} = ${result};`
|
|
|
|
`${state.parentNode}.${propertyName} = ${result};`
|
|
|
|
);
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -82,7 +82,7 @@ export default function addElementAttributes ( generator, block, state, node, lo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( addAttribute ) {
|
|
|
|
if ( addAttribute ) {
|
|
|
|
local.create.addLine(
|
|
|
|
block.builders.create.addLine(
|
|
|
|
`${generator.helper( method )}( ${state.parentNode}, '${name}', ${result} );`
|
|
|
|
`${generator.helper( method )}( ${state.parentNode}, '${name}', ${result} );`
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -95,7 +95,7 @@ export default function addElementAttributes ( generator, block, state, node, lo
|
|
|
|
const { snippet } = generator.contextualise( block, value.expression );
|
|
|
|
const { snippet } = generator.contextualise( block, value.expression );
|
|
|
|
|
|
|
|
|
|
|
|
const last = `last_${state.parentNode}_${name.replace( /-/g, '_')}`;
|
|
|
|
const last = `last_${state.parentNode}_${name.replace( /-/g, '_')}`;
|
|
|
|
local.create.addLine( `var ${last} = ${snippet};` );
|
|
|
|
block.builders.create.addLine( `var ${last} = ${snippet};` );
|
|
|
|
|
|
|
|
|
|
|
|
let updater;
|
|
|
|
let updater;
|
|
|
|
if ( propertyName ) {
|
|
|
|
if ( propertyName ) {
|
|
|
@ -104,9 +104,9 @@ export default function addElementAttributes ( generator, block, state, node, lo
|
|
|
|
updater = `${generator.helper( method )}( ${state.parentNode}, '${name}', ${last} );`;
|
|
|
|
updater = `${generator.helper( method )}( ${state.parentNode}, '${name}', ${last} );`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
local.create.addLine( updater );
|
|
|
|
block.builders.create.addLine( updater );
|
|
|
|
|
|
|
|
|
|
|
|
local.update.addBlock( deindent`
|
|
|
|
block.builders.update.addBlock( deindent`
|
|
|
|
if ( ( ${block.tmp()} = ${snippet} ) !== ${last} ) {
|
|
|
|
if ( ( ${block.tmp()} = ${snippet} ) !== ${last} ) {
|
|
|
|
${last} = ${block.tmp()};
|
|
|
|
${last} = ${block.tmp()};
|
|
|
|
${updater}
|
|
|
|
${updater}
|
|
|
@ -136,15 +136,15 @@ export default function addElementAttributes ( generator, block, state, node, lo
|
|
|
|
updater = `${generator.helper( method )}( ${state.parentNode}, '${name}', ${value} );`;
|
|
|
|
updater = `${generator.helper( method )}( ${state.parentNode}, '${name}', ${value} );`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
local.create.addLine( updater );
|
|
|
|
block.builders.create.addLine( updater );
|
|
|
|
local.update.addLine( updater );
|
|
|
|
block.builders.update.addLine( updater );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( isIndirectlyBoundValue ) {
|
|
|
|
if ( isIndirectlyBoundValue ) {
|
|
|
|
const updateValue = `${state.parentNode}.value = ${state.parentNode}.__value;`;
|
|
|
|
const updateValue = `${state.parentNode}.value = ${state.parentNode}.__value;`;
|
|
|
|
|
|
|
|
|
|
|
|
local.create.addLine( updateValue );
|
|
|
|
block.builders.create.addLine( updateValue );
|
|
|
|
if ( dynamic ) local.update.addLine( updateValue );
|
|
|
|
if ( dynamic ) block.builders.update.addLine( updateValue );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -182,7 +182,7 @@ export default function addElementAttributes ( generator, block, state, node, lo
|
|
|
|
const handlerBody = ( declarations.length ? declarations.join( '\n' ) + '\n\n' : '' ) + `[✂${attribute.expression.start}-${attribute.expression.end}✂];`;
|
|
|
|
const handlerBody = ( declarations.length ? declarations.join( '\n' ) + '\n\n' : '' ) + `[✂${attribute.expression.start}-${attribute.expression.end}✂];`;
|
|
|
|
|
|
|
|
|
|
|
|
if ( generator.events.has( name ) ) {
|
|
|
|
if ( generator.events.has( name ) ) {
|
|
|
|
local.create.addBlock( deindent`
|
|
|
|
block.builders.create.addBlock( deindent`
|
|
|
|
var ${handlerName} = ${generator.alias( 'template' )}.events.${name}.call( ${block.component}, ${state.parentNode}, function ( event ) {
|
|
|
|
var ${handlerName} = ${generator.alias( 'template' )}.events.${name}.call( ${block.component}, ${state.parentNode}, function ( event ) {
|
|
|
|
${handlerBody}
|
|
|
|
${handlerBody}
|
|
|
|
}.bind( ${state.parentNode} ) );
|
|
|
|
}.bind( ${state.parentNode} ) );
|
|
|
@ -192,7 +192,7 @@ export default function addElementAttributes ( generator, block, state, node, lo
|
|
|
|
${handlerName}.teardown();
|
|
|
|
${handlerName}.teardown();
|
|
|
|
` );
|
|
|
|
` );
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
local.create.addBlock( deindent`
|
|
|
|
block.builders.create.addBlock( deindent`
|
|
|
|
function ${handlerName} ( event ) {
|
|
|
|
function ${handlerName} ( event ) {
|
|
|
|
${handlerBody}
|
|
|
|
${handlerBody}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -213,7 +213,7 @@ export default function addElementAttributes ( generator, block, state, node, lo
|
|
|
|
else if ( attribute.type === 'Ref' ) {
|
|
|
|
else if ( attribute.type === 'Ref' ) {
|
|
|
|
generator.usesRefs = true;
|
|
|
|
generator.usesRefs = true;
|
|
|
|
|
|
|
|
|
|
|
|
local.create.addLine(
|
|
|
|
block.builders.create.addLine(
|
|
|
|
`${block.component}.refs.${name} = ${state.parentNode};`
|
|
|
|
`${block.component}.refs.${name} = ${state.parentNode};`
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|