prosemirror-resizable-view
v3.0.0
Published
A ProseMirror node view that make your node resizable
Downloads
147,577
Readme
prosemirror-resizable-view
A ProseMirror node view that make your node resizable
Installation
# yarn
yarn add prosemirror-resizable-view
# pnpm
pnpm add prosemirror-resizable-view
# npm
npm install prosemirror-resizable-view
Usage
The following code creates an resizable image node view.
import { ResizableNodeView } from 'prosemirror-resizable-view';
const createInnerImage = ({ node }: { node: ProsemirrorNode }) => {
const inner = document.createElement('img');
inner.setAttribute('src', node.attrs.src);
inner.style.width = '100%';
inner.style.minWidth = '50px';
inner.style.objectFit = 'contain'; // maintain image's aspect ratio
return inner;
};
/**
* ResizableImageView is a NodeView for image. You can resize the image by
* dragging the handle over the image.
*/
export class ResizableImageView extends ResizableNodeView implements NodeView {
constructor(node: ProsemirrorNode, view: EditorView, getPos: () => number) {
super({ node, view, getPos, createElement: createInnerImage });
}
}