UNPKG

@atlaskit/editor-plugin-block-controls

Version:

Block controls plugin for @atlaskit/editor-core

32 lines 1.26 kB
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals'; import { findNodeDecs } from '../../pm-plugins/decorations-anchor'; import { key } from '../../pm-plugins/main'; /** * Checks for plugin state for latest anchorName based on the position, returns * provided anchorName if available */ export var refreshAnchorName = function refreshAnchorName(_ref) { var getPos = _ref.getPos, view = _ref.view, anchorName = _ref.anchorName; var newAnchorName = anchorName || ''; if (expValEquals('platform_editor_native_anchor_with_dnd', 'isEnabled', true)) { return newAnchorName; } var pos = getPos(); if (anchorName || pos === undefined) { return newAnchorName; } var node = view.state.doc.nodeAt(pos); var state = key.getState(view.state); if (state !== null && state !== void 0 && state.decorations) { var _node$nodeSize; var nodeDecs = findNodeDecs(view.state, state.decorations, pos, pos + ((_node$nodeSize = node === null || node === void 0 ? void 0 : node.nodeSize) !== null && _node$nodeSize !== void 0 ? _node$nodeSize : 0)); var nodeDec = nodeDecs.at(0); if (!nodeDec) { return newAnchorName; } newAnchorName = nodeDec.spec.anchorName; } return newAnchorName; };