Skip to content

Commit e432460

Browse files
committed
fixup! ✨(frontend) exclude h4-h6 headings from table of contents
1 parent 2f94e12 commit e432460

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

src/frontend/apps/impress/src/features/docs/doc-editor/stores/useHeadingStore.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ export const useHeadingStore = create<UseHeadingStore>((set, get) => ({
2929
headings: [],
3030
setHeadings: (editor) => {
3131
const headingBlocks = editor?.document
32-
.filter((block) => block.type === 'heading')
32+
.filter(
33+
(block) =>
34+
block.type === 'heading' &&
35+
block.props.level >= 1 &&
36+
block.props.level <= 3,
37+
)
3338
.map((block) => ({
3439
...block,
3540
contentText: recursiveTextContent(

src/frontend/apps/impress/src/features/docs/doc-table-content/components/TableContent.tsx

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,13 @@ export const TableContent = () => {
1919
const { t } = useTranslation();
2020
const [isHover, setIsHover] = useState(false);
2121

22-
// Filter headings to only show h1, h2, h3 (levels 1-3)
23-
const filteredHeadings = headings?.filter(
24-
(heading) => heading.props.level >= 1 && heading.props.level <= 3,
25-
);
26-
2722
useEffect(() => {
2823
const handleScroll = () => {
29-
if (!filteredHeadings) {
24+
if (!headings) {
3025
return;
3126
}
3227

33-
for (const heading of filteredHeadings) {
28+
for (const heading of headings) {
3429
const elHeading = document.body.querySelector(
3530
`.bn-block-outer[data-id="${heading.id}"] [data-content-type="heading"]:first-child`,
3631
);
@@ -74,7 +69,7 @@ export const TableContent = () => {
7469
.getElementById(MAIN_LAYOUT_ID)
7570
?.removeEventListener('scroll', scrollFn);
7671
};
77-
}, [filteredHeadings, setHeadingIdHighlight]);
72+
}, [headings, setHeadingIdHighlight]);
7873

7974
const onOpen = () => {
8075
setIsHover(true);
@@ -93,13 +88,12 @@ export const TableContent = () => {
9388
setIsHover(false);
9489
};
9590

96-
const shouldHideTableContent =
91+
if (
9792
!editor ||
98-
!filteredHeadings ||
99-
filteredHeadings.length === 0 ||
100-
(filteredHeadings.length === 1 && !filteredHeadings[0].contentText);
101-
102-
if (shouldHideTableContent) {
93+
!headings ||
94+
headings.length === 0 ||
95+
(headings.length === 1 && !headings[0].contentText)
96+
) {
10397
return null;
10498
}
10599

@@ -168,7 +162,7 @@ export const TableContent = () => {
168162
overflow-y: auto;
169163
`}
170164
>
171-
{filteredHeadings?.map(
165+
{headings?.map(
172166
(heading) =>
173167
heading.contentText && (
174168
<Heading

0 commit comments

Comments
 (0)