@atlaskit/editor-plugin-media
Version:
Media plugin for @atlaskit/editor-core
46 lines (45 loc) • 1.94 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.currentMediaOrInlineNodeBorderMark = exports.currentMediaNode = exports.currentMediaInlineNodeWithPos = exports.currentMediaInlineNode = void 0;
var _mediaSingle = require("@atlaskit/editor-common/media-single");
var _state = require("@atlaskit/editor-prosemirror/state");
var currentMediaInlineNodeWithPos = exports.currentMediaInlineNodeWithPos = function currentMediaInlineNodeWithPos(editorState) {
var doc = editorState.doc,
selection = editorState.selection,
schema = editorState.schema;
if (!doc || !selection || !(selection instanceof _state.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
};
};
var currentMediaNode = exports.currentMediaNode = function currentMediaNode(editorState) {
var _currentMediaNodeWith;
return (_currentMediaNodeWith = (0, _mediaSingle.currentMediaNodeWithPos)(editorState)) === null || _currentMediaNodeWith === void 0 ? void 0 : _currentMediaNodeWith.node;
};
var currentMediaInlineNode = exports.currentMediaInlineNode = function currentMediaInlineNode(editorState) {
var _currentMediaInlineNo;
return (_currentMediaInlineNo = currentMediaInlineNodeWithPos(editorState)) === null || _currentMediaInlineNo === void 0 ? void 0 : _currentMediaInlineNo.node;
};
var currentMediaOrInlineNodeBorderMark = exports.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;
};