I’m interested in ways to provide image resizing in Prosemirror.
As a quick hack I found out Firefox has image resizing in contenteditable that can be used semi-reliably through MutationObserver:
let observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.attributeName === "width" && mutation.target.tagName === "IMG") {
let state = view.editor.state;
// Image position and node
let {$from,node} = state.selection;
// Copy current image attributes
let newAttrs = Object.assign({}, node.attrs);
// Update image size
newAttrs.width = mutation.target.width;
// Create transform
let transform = state.tr.setNodeType($from.pos, node.type, newAttrs);
view.props.onAction(transform.action());
}
});
});
observer.observe(view.wrapper, {
attributes: true,
subtree: true,
characterData: true,
characterDataOldValue: true,
childList: true,
});
What are you guys using for image resizing?