@atlaskit/editor-plugin-expand
Version:
Expand plugin for @atlaskit/editor-core
23 lines (21 loc) • 1.41 kB
JavaScript
import { isExpandCollapsed } from '@atlaskit/editor-common/expand';
import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
// from platform/packages/editor/editor-plugin-find-replace/src/ui/styles.ts
const darkModeSearchMatchClass = 'search-match-dark';
const searchMatchExpandTitleClass = 'search-match-expand-title';
const selectedSearchMatchClass = 'selected-search-match';
export const findSelectedParentExpandNode = state => {
const nestedOrParentExpand = findParentNodeOfType(state.schema.nodes.nestedExpand)(state.selection) || findParentNodeOfType(state.schema.nodes.expand)(state.selection);
// If it's nested expand, we should check if its parent expand is collapsed.
// If the parent expand is collapsed, the nested expand is not visible,
// so it could not be selected.
// In this case, we return the parent expand node instead of the nested expand node.
if ((nestedOrParentExpand === null || nestedOrParentExpand === void 0 ? void 0 : nestedOrParentExpand.node.type) === state.schema.nodes.nestedExpand) {
const parentExpand = findParentNodeOfType(state.schema.nodes.expand)(state.selection);
if (parentExpand && isExpandCollapsed(parentExpand.node)) {
return parentExpand;
}
}
return nestedOrParentExpand;
};
export const findReplaceExpandDecorations = [darkModeSearchMatchClass, searchMatchExpandTitleClass, selectedSearchMatchClass];