UNPKG

@atlaskit/editor-plugin-media

Version:

Media plugin for @atlaskit/editor-core

41 lines (40 loc) 1.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.currentMediaNodeWithPos = exports.currentMediaNodeBorderMark = exports.currentMediaNode = void 0; var _state = require("@atlaskit/editor-prosemirror/state"); var currentMediaNodeWithPos = exports.currentMediaNodeWithPos = function currentMediaNodeWithPos(editorState) { var doc = editorState.doc, selection = editorState.selection, schema = editorState.schema; if (!doc || !selection || !(selection instanceof _state.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 }; }; var currentMediaNode = exports.currentMediaNode = function currentMediaNode(editorState) { var _currentMediaNodeWith; return (_currentMediaNodeWith = currentMediaNodeWithPos(editorState)) === null || _currentMediaNodeWith === void 0 ? void 0 : _currentMediaNodeWith.node; }; var currentMediaNodeBorderMark = exports.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; };