From 0ba07c3c38516e873a509b057719d31ad7576acb Mon Sep 17 00:00:00 2001 From: ilindaniel <25451549+ilindaniel@users.noreply.github.com> Date: Fri, 12 Jun 2026 12:47:42 +0500 Subject: [PATCH] feat: add fold/unfold collapsibles button to super editor toolbar --- .../Plugins/ToolbarPlugin/ToolbarPlugin.tsx | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/packages/web/src/javascripts/Components/SuperEditor/Plugins/ToolbarPlugin/ToolbarPlugin.tsx b/packages/web/src/javascripts/Components/SuperEditor/Plugins/ToolbarPlugin/ToolbarPlugin.tsx index feaeef85927..2a74c019720 100644 --- a/packages/web/src/javascripts/Components/SuperEditor/Plugins/ToolbarPlugin/ToolbarPlugin.tsx +++ b/packages/web/src/javascripts/Components/SuperEditor/Plugins/ToolbarPlugin/ToolbarPlugin.tsx @@ -24,6 +24,8 @@ import { $isTextNode, $getNodeByKey, TextNode, + $getRoot, + LexicalNode, } from 'lexical' import { mergeRegister, @@ -48,6 +50,7 @@ import { CenterAlignBlock, JustifyAlignBlock, LeftAlignBlock, RightAlignBlock } import { BulletedListBlock, ChecklistBlock, NumberedListBlock } from '../Blocks/List' import { CodeBlock } from '../Blocks/Code' import { CollapsibleBlock } from '../Blocks/Collapsible' +import { $isCollapsibleContainerNode } from '../CollapsiblePlugin/CollapsibleContainerNode' import { DividerBlock } from '../Blocks/Divider' import { H1Block, H2Block, H3Block } from '../Blocks/Headings' import { IndentBlock, OutdentBlock } from '../Blocks/IndentOutdent' @@ -243,6 +246,9 @@ const ToolbarPlugin = () => { const [isInsertMenuOpen, setIsInsertMenuOpen] = useState(false) const insertAnchorRef = useRef(null) + const [isCollapsibleMenuOpen, setIsCollapsibleMenuOpen] = useState(false) + const collapsibleAnchorRef = useRef(null) + const [canUndo, setCanUndo] = useState(false) const [canRedo, setCanRedo] = useState(false) @@ -434,6 +440,32 @@ const ToolbarPlugin = () => { }) }, [activeEditor]) + const setAllCollapsiblesOpen = useCallback( + (open: boolean) => { + activeEditor.update(() => { + const root = $getRoot() + const traverse = (node: LexicalNode) => { + if ($isCollapsibleContainerNode(node)) { + node.setOpen(open) + } + if ($isElementNode(node)) { + node.getChildren().forEach(traverse) + } + } + root.getChildren().forEach(traverse) + }) + }, + [activeEditor], + ) + + const foldAllCollapsibles = useCallback(() => { + setAllCollapsiblesOpen(false) + }, [setAllCollapsiblesOpen]) + + const unfoldAllCollapsibles = useCallback(() => { + setAllCollapsiblesOpen(true) + }, [setAllCollapsiblesOpen]) + useEffect(() => { if (isMobile) { return @@ -816,6 +848,17 @@ const ToolbarPlugin = () => { }} disabled={!hasNonCollapsedSelection} /> + { + setIsCollapsibleMenuOpen(!isCollapsibleMenuOpen) + }} + ref={collapsibleAnchorRef} + className={isCollapsibleMenuOpen ? 'md:bg-default' : ''} + > + + + {isMobile && (