slate-data-filter-plugin
Version:
onKeyDown handler which removes data that would othwise be inherited
27 lines (26 loc) • 869 B
JavaScript
/**
* filter out parent block data
* @param {Array} whitelist - propeties to be omitted from filter
*/
function FilterData(whitelist = []) {
return {
onKeyDown(event, change) {
if (event.keyCode === 13) {
const existingData = change.value.startBlock.get('data');
const filteredData = whitelist.reduce(
(initial, current) => {
if (existingData.has(current)) {
initial[current] = existingData.get(current);
return initial;
}
return initial;
}, {});
return change.splitBlock().setBlocks({
data: filteredData
});
}
return;
}
}
};
export default FilterData;