@atlaskit/editor-plugin-block-controls
Version:
Block controls plugin for @atlaskit/editor-core
59 lines (54 loc) • 2.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getActiveBlockMarks = void 0;
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
/**
* Remove this when platform_editor_clean_up_widget_mark_logic is cleaned up.
*
* Returns list of block marks on schema that widgets are allowed to render inside
* Currently
* - indent
* - alignment
* @param state - The editor state
* @returns The block marks
* @example
* ```ts
* const marks = getBlockMarks(state);
* console.log(marks);
* // [indent, alignment]
* ```
*/
var getActiveBlockMarks = exports.getActiveBlockMarks = function getActiveBlockMarks(state, pos) {
var alignment = state.schema.marks.alignment;
var resolvedPos = state.doc.resolve(pos);
// find all active marks at the position
var marks = resolvedPos.marks();
var supportedMarks = marks.filter(function (mark) {
return mark.type === alignment;
});
/**
* Fix for widget positioning at alignment mark boundaries.
* When the previous node has alignment but the next node doesn't, we need to prevent
* the widget from inheriting alignment marks. This ensures the widget is positioned
* correctly at the boundary rather than being absorbed into the alignment wrapper.
*/
if (supportedMarks.length > 0 && (0, _expValEquals.expValEquals)('platform_editor_native_anchor_with_dnd', 'isEnabled', true)) {
var _resolvedPos$nodeAfte;
var nextNodeMarks = ((_resolvedPos$nodeAfte = resolvedPos.nodeAfter) === null || _resolvedPos$nodeAfte === void 0 ? void 0 : _resolvedPos$nodeAfte.marks.filter(function (mark) {
return mark.type === alignment;
})) || [];
// Compare alignment values to ensure they are the same
var alignmentValuesMatch = supportedMarks.length === nextNodeMarks.length && supportedMarks.some(function (mark) {
return nextNodeMarks.some(function (nextMark) {
return nextMark.eq(mark);
});
});
// previous node has alignment but next node does not have alignment or alignment values differ
if (nextNodeMarks.length === 0 || !alignmentValuesMatch) {
return [];
}
}
return supportedMarks;
};