@atlaskit/editor-plugin-block-controls
Version:
Block controls plugin for @atlaskit/editor-core
38 lines (37 loc) • 1.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.refreshAnchorName = void 0;
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
var _decorationsAnchor = require("../../pm-plugins/decorations-anchor");
var _main = require("../../pm-plugins/main");
/**
* Checks for plugin state for latest anchorName based on the position, returns
* provided anchorName if available
*/
var refreshAnchorName = exports.refreshAnchorName = function refreshAnchorName(_ref) {
var getPos = _ref.getPos,
view = _ref.view,
anchorName = _ref.anchorName;
var newAnchorName = anchorName || '';
if ((0, _expValEquals.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 = _main.key.getState(view.state);
if (state !== null && state !== void 0 && state.decorations) {
var _node$nodeSize;
var nodeDecs = (0, _decorationsAnchor.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;
};