@atlaskit/editor-plugin-block-controls
Version:
Block controls plugin for @atlaskit/editor-core
33 lines • 1.19 kB
JavaScript
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 const refreshAnchorName = ({
getPos,
view,
anchorName
}) => {
let newAnchorName = anchorName || '';
if (expValEquals('platform_editor_native_anchor_with_dnd', 'isEnabled', true)) {
return newAnchorName;
}
const pos = getPos();
if (anchorName || pos === undefined) {
return newAnchorName;
}
const node = view.state.doc.nodeAt(pos);
const state = key.getState(view.state);
if (state !== null && state !== void 0 && state.decorations) {
var _node$nodeSize;
const 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));
const nodeDec = nodeDecs.at(0);
if (!nodeDec) {
return newAnchorName;
}
newAnchorName = nodeDec.spec.anchorName;
}
return newAnchorName;
};