@atlaskit/editor-plugin-expand
Version:
Expand plugin for @atlaskit/editor-core
47 lines (45 loc) • 1.97 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.toggleExpandRange = exports.TOGGLE_EXPAND_RANGE_META_KEY = void 0;
var _expand = require("@atlaskit/editor-common/expand");
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
var TOGGLE_EXPAND_RANGE_META_KEY = exports.TOGGLE_EXPAND_RANGE_META_KEY = 'toggleExpandRange';
var toggleExpandRange = exports.toggleExpandRange = function toggleExpandRange(from, to) {
var open = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
return function (_ref) {
var tr = _ref.tr;
var _tr$doc$type$schema$n = tr.doc.type.schema.nodes,
expand = _tr$doc$type$schema$n.expand,
nestedExpand = _tr$doc$type$schema$n.nestedExpand;
var fromClamped = from && from >= 0 ? from : 0;
var toClamped = to && to <= tr.doc.content.size ? to : tr.doc.content.size;
var positions = [];
tr.doc.nodesBetween(fromClamped, toClamped, function (node, pos) {
if ([expand, nestedExpand].includes(node.type)) {
_expand.expandedState.set(node, open);
positions.push(pos);
}
});
if ((0, _platformFeatureFlags.fg)('platform_editor_show_diff_scroll_navigation')) {
if (positions.length === 0) {
// No expand nodes found in the range — nothing to dispatch.
return null;
}
// Set meta so the expand PM plugin can add node decorations.
// This ensures ExpandNodeView.update() receives the decoration and visually
// opens or closes the expand, even when the experiment below is disabled.
tr.setMeta(TOGGLE_EXPAND_RANGE_META_KEY, {
positions: positions,
open: open
});
return tr;
}
if ((0, _expValEquals.expValEquals)('platform_editor_aifc_expand_collapses_oncreate_fix', 'isEnabled', true)) {
return tr;
}
return null;
};
};