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