UNPKG

@atlaskit/editor-plugin-media

Version:

Media plugin for @atlaskit/editor-core

35 lines 1.16 kB
import { NodeSelection } from '@atlaskit/editor-prosemirror/state'; export var currentMediaNodeWithPos = function currentMediaNodeWithPos(editorState) { var doc = editorState.doc, selection = editorState.selection, schema = editorState.schema; if (!doc || !selection || !(selection instanceof NodeSelection) || selection.node.type !== schema.nodes.mediaSingle) { return; } var pos = selection.$anchor.pos + 1; var node = doc.nodeAt(pos); if (!node || node.type !== schema.nodes.media) { 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 currentMediaNodeBorderMark = function currentMediaNodeBorderMark(editorState) { var node = currentMediaNode(editorState); if (!node) { return; } var borderMark = node.marks.find(function (m) { return m.type.name === 'border'; }); if (!borderMark) { return; } return borderMark.attrs; };