Comparing version 5.6.0 to 5.6.1
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "5.6.0", | ||
"version": "5.6.1", | ||
"type": "module", | ||
@@ -8,0 +8,0 @@ "types": "./types/index.d.ts", |
@@ -294,3 +294,3 @@ /** @import { Expression, ExpressionStatement, Identifier, MemberExpression, ObjectExpression, Statement } from 'estree' */ | ||
? build_custom_element_attribute_update_assignment(node_id, attribute, context) | ||
: build_element_attribute_update_assignment(node, node_id, attribute, context); | ||
: build_element_attribute_update_assignment(node, node_id, attribute, attributes, context); | ||
if (is) is_attributes_reactive = true; | ||
@@ -523,6 +523,13 @@ } | ||
* @param {AST.Attribute} attribute | ||
* @param {Array<AST.Attribute | AST.SpreadAttribute>} attributes | ||
* @param {ComponentContext} context | ||
* @returns {boolean} | ||
*/ | ||
function build_element_attribute_update_assignment(element, node_id, attribute, context) { | ||
function build_element_attribute_update_assignment( | ||
element, | ||
node_id, | ||
attribute, | ||
attributes, | ||
context | ||
) { | ||
const state = context.state; | ||
@@ -570,2 +577,22 @@ const name = get_attribute_name(element, attribute); | ||
update = b.stmt(b.call('$.set_selected', node_id, value)); | ||
} else if ( | ||
// If we would just set the defaultValue property, it would override the value property, | ||
// because it is set in the template which implicitly means it's also setting the default value, | ||
// and if one updates the default value while the input is pristine it will also update the | ||
// current value, which is not what we want, which is why we need to do some extra work. | ||
name === 'defaultValue' && | ||
(attributes.some( | ||
(attr) => attr.type === 'Attribute' && attr.name === 'value' && is_text_attribute(attr) | ||
) || | ||
(element.name === 'textarea' && element.fragment.nodes.length > 0)) | ||
) { | ||
update = b.stmt(b.call('$.set_default_value', node_id, value)); | ||
} else if ( | ||
// See defaultValue comment | ||
name === 'defaultChecked' && | ||
attributes.some( | ||
(attr) => attr.type === 'Attribute' && attr.name === 'checked' && attr.value === true | ||
) | ||
) { | ||
update = b.stmt(b.call('$.set_default_checked', node_id, value)); | ||
} else if (is_dom_property(name)) { | ||
@@ -572,0 +599,0 @@ update = b.stmt(b.assignment('=', b.member(node_id, name), value)); |
@@ -107,2 +107,24 @@ import { DEV } from 'esm-env'; | ||
/** | ||
* Applies the default checked property without influencing the current checked property. | ||
* @param {HTMLInputElement} element | ||
* @param {boolean} checked | ||
*/ | ||
export function set_default_checked(element, checked) { | ||
const existing_value = element.checked; | ||
element.defaultChecked = checked; | ||
element.checked = existing_value; | ||
} | ||
/** | ||
* Applies the default value property without influencing the current value property. | ||
* @param {HTMLInputElement | HTMLTextAreaElement} element | ||
* @param {string} value | ||
*/ | ||
export function set_default_value(element, value) { | ||
const existing_value = element.value; | ||
element.defaultValue = value; | ||
element.value = existing_value; | ||
} | ||
/** | ||
* @param {Element} element | ||
@@ -109,0 +131,0 @@ * @param {string} attribute |
@@ -38,3 +38,5 @@ export { FILENAME, HMR, NAMESPACE_SVG } from '../../constants.js'; | ||
set_checked, | ||
set_selected | ||
set_selected, | ||
set_default_checked, | ||
set_default_value | ||
} from './dom/elements/attributes.js'; | ||
@@ -41,0 +43,0 @@ export { set_class, set_svg_class, set_mathml_class, toggle_class } from './dom/elements/class.js'; |
@@ -9,3 +9,3 @@ // generated during release, do not modify | ||
*/ | ||
export const VERSION = '5.6.0'; | ||
export const VERSION = '5.6.1'; | ||
export const PUBLIC_VERSION = '5'; |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2365468
52242