@atlaskit/editor-plugin-image-upload
Version:
Image upload plugin for @atlaskit/editor-core
28 lines • 950 B
JavaScript
import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
import { createExternalMediaNode } from '../ui/hooks/utils';
import { startUpload } from './actions';
import { stateKey } from './plugin-key';
export const insertExternalImage = options => (state, dispatch) => {
const pluginState = stateKey.getState(state);
if (!(pluginState !== null && pluginState !== void 0 && pluginState.enabled) || !options.src) {
return false;
}
const mediaNode = createExternalMediaNode(options.src, state.schema);
if (!mediaNode) {
return false;
}
if (dispatch) {
dispatch(safeInsert(mediaNode, state.selection.$to.pos)(state.tr).scrollIntoView());
}
return true;
};
export const startImageUpload = event => (state, dispatch) => {
const pluginState = stateKey.getState(state);
if (pluginState && !pluginState.enabled) {
return false;
}
if (dispatch) {
dispatch(startUpload(event)(state.tr));
}
return true;
};