2022-03-16 18:33:53 +08:00
|
|
|
export const morphdomOptions = {
|
2021-03-20 21:10:15 +08:00
|
|
|
onBeforeElUpdated(from, to) {
|
|
|
|
// Keep element attributes starting with data-js-
|
|
|
|
// which we set on the client.
|
|
|
|
for (const attr of from.attributes) {
|
|
|
|
if (attr.name.startsWith("data-js-")) {
|
|
|
|
to.setAttribute(attr.name, attr.value);
|
|
|
|
}
|
2022-02-04 06:25:12 +08:00
|
|
|
|
|
|
|
if (attr.name === "data-keep-attribute") {
|
2022-02-04 07:37:46 +08:00
|
|
|
if (from.hasAttribute(attr.value)) {
|
|
|
|
to.setAttribute(attr.value, from.getAttribute(attr.value));
|
|
|
|
} else {
|
|
|
|
to.removeAttribute(attr.value);
|
|
|
|
}
|
2022-02-04 06:25:12 +08:00
|
|
|
}
|
2021-03-20 21:10:15 +08:00
|
|
|
}
|
|
|
|
},
|
2021-06-08 18:33:50 +08:00
|
|
|
|
|
|
|
onNodeAdded(node) {
|
|
|
|
// Mimic autofocus for dynamically inserted elements
|
|
|
|
if (node.nodeType === Node.ELEMENT_NODE && node.hasAttribute("autofocus")) {
|
|
|
|
node.focus();
|
|
|
|
|
|
|
|
if (node.setSelectionRange && node.value) {
|
|
|
|
const lastIndex = node.value.length;
|
|
|
|
node.setSelectionRange(lastIndex, lastIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2021-03-20 21:10:15 +08:00
|
|
|
};
|