@atlaskit/editor-plugin-media
Version:
Media plugin for @atlaskit/editor-core
35 lines • 1.01 kB
JavaScript
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
export const currentMediaNodeWithPos = editorState => {
const {
doc,
selection,
schema
} = editorState;
if (!doc || !selection || !(selection instanceof NodeSelection) || selection.node.type !== schema.nodes.mediaSingle) {
return;
}
const pos = selection.$anchor.pos + 1;
const node = doc.nodeAt(pos);
if (!node || node.type !== schema.nodes.media) {
return;
}
return {
node,
pos
};
};
export const currentMediaNode = editorState => {
var _currentMediaNodeWith;
return (_currentMediaNodeWith = currentMediaNodeWithPos(editorState)) === null || _currentMediaNodeWith === void 0 ? void 0 : _currentMediaNodeWith.node;
};
export const currentMediaNodeBorderMark = editorState => {
const node = currentMediaNode(editorState);
if (!node) {
return;
}
const borderMark = node.marks.find(m => m.type.name === 'border');
if (!borderMark) {
return;
}
return borderMark.attrs;
};