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