2021-03-20 21:10:15 +08:00
|
|
|
const callbacks = {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
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
|
|
|
};
|
|
|
|
|
|
|
|
export default callbacks;
|