@mason-api/javascript-sdk
Version:
Mason component rendering library
20 lines (19 loc) • 594 B
JavaScript
import _ from 'lodash';
import update from 'immutability-helper';
import { TREE } from '@mason-api/utils';
export default () => (node, config, configSubpath) => {
if (node.tag === 'button' && !_.isFunction(node.p.onclick) && node.p.type !== 'submit') {
const { data: { [configSubpath]: { tree } } } = config;
const ancestors = TREE.findNodeAncestors(tree, button.path);
if (_.some(ancestors, ['tag', 'form'])) {
return update(node, {
p: {
$merge: {
onclick: e => e.preventDefault(),
},
},
});
}
}
return node;
}