Skip to content

Commit 35bbcb0

Browse files
authored
chore: outlines support toggle h1-h6 (AppFlowy-IO#72)
* chore: outlines support toggle h1-h6 * fix: add anchor point to outline content
1 parent c16a79d commit 35bbcb0

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/components/editor/components/blocks/outline/Outline.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ export const Outline = memo(
2626

2727
if (element) {
2828
void (async () => {
29+
const search = new URLSearchParams(window.location.search);
30+
31+
search.set('blockId', heading.blockId);
32+
33+
window.history.replaceState(null, '', `${window.location.pathname}?${search.toString()}`);
34+
2935
await smoothScrollIntoViewIfNeeded(element, {
3036
behavior: 'smooth',
3137
block: 'start',

src/components/editor/components/blocks/outline/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ export function extractHeadings (editor: ReactEditor, maxDepth: number): Heading
1111
function traverse (children: (Element | Text)[]) {
1212
for (const block of children) {
1313
if (Text.isText(block)) continue;
14-
if (block.type === BlockType.HeadingBlock && (block as HeadingNode).data?.level <= maxDepth) {
14+
// Include only heading and toggle list heading blocks
15+
if (([
16+
BlockType.HeadingBlock,
17+
BlockType.ToggleListBlock,
18+
].includes(block.type as BlockType)) && 'level' in (block as HeadingNode).data && (block as HeadingNode).data?.level <= maxDepth) {
1519
headings.push({
1620
...block,
1721
data: {

src/components/editor/components/blocks/toggle-list/ToggleList.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const ToggleList = memo(
4141
{...attributes}
4242
ref={ref}
4343
className={className}
44+
id={level ? `heading-${blockId}` : undefined}
4445
>
4546
{children}
4647
{!readOnly && !collapsed && node.children.slice(1).length === 0 &&

0 commit comments

Comments
 (0)