Skip to content

Commit b37acf3

Browse files
committed
💄(frontend) improve ui table of contents
- keep correctly the text on the left side - improve accuracy highlightment heading when scrolling - display full heading text when text transform is applied - fix typo
1 parent 5bd78b8 commit b37acf3

File tree

5 files changed

+47
-27
lines changed

5 files changed

+47
-27
lines changed

src/frontend/apps/e2e/__tests__/app-impress/doc-table-content.spec.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test.describe('Doc Table Content', () => {
2020
await page.getByLabel('Open the document options').click();
2121
await page
2222
.getByRole('button', {
23-
name: 'Table of content',
23+
name: 'Table of contents',
2424
})
2525
.click();
2626

@@ -30,6 +30,8 @@ test.describe('Doc Table Content', () => {
3030
await editor.locator('.bn-block-outer').last().fill('/');
3131
await page.getByText('Heading 1').click();
3232
await page.keyboard.type('Hello World');
33+
await editor.getByText('Hello').dblclick();
34+
await page.getByRole('button', { name: 'Strike' }).click();
3335

3436
await page.locator('.bn-block-outer').last().click();
3537

@@ -40,7 +42,7 @@ test.describe('Doc Table Content', () => {
4042

4143
await editor.locator('.bn-block-outer').last().fill('/');
4244
await page.getByText('Heading 2').click();
43-
await page.keyboard.type('Super World');
45+
await page.keyboard.type('Super World', { delay: 100 });
4446

4547
await page.locator('.bn-block-outer').last().click();
4648

@@ -58,15 +60,15 @@ test.describe('Doc Table Content', () => {
5860
const another = panel.getByText('Another World');
5961

6062
await expect(hello).toBeVisible();
61-
await expect(hello).toHaveCSS('font-size', '19.2px');
63+
await expect(hello).toHaveCSS('font-size', /19/);
6264
await expect(hello).toHaveAttribute('aria-selected', 'true');
6365

6466
await expect(superW).toBeVisible();
65-
await expect(superW).toHaveCSS('font-size', '16px');
67+
await expect(superW).toHaveCSS('font-size', /16/);
6668
await expect(superW).toHaveAttribute('aria-selected', 'false');
6769

6870
await expect(another).toBeVisible();
69-
await expect(another).toHaveCSS('font-size', '12.8px');
71+
await expect(another).toHaveCSS('font-size', /12/);
7072
await expect(another).toHaveAttribute('aria-selected', 'false');
7173

7274
await hello.click();

src/frontend/apps/impress/src/components/Panel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ export const Panel = ({
3636
$width="100%"
3737
$maxWidth="20rem"
3838
$position="sticky"
39-
$maxHeight="96vh"
39+
$maxHeight="99vh"
4040
$height="100%"
4141
$css={`
42-
top: 2vh;
42+
top: 0vh;
4343
transition: ${transition};
4444
${
4545
!isOpen &&

src/frontend/apps/impress/src/features/docs/doc-header/components/DocToolBox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export const DocToolBox = ({ doc }: DocToolBoxProps) => {
9191
icon={<span className="material-icons">summarize</span>}
9292
size="small"
9393
>
94-
<Text $theme="primary">{t('Table of content')}</Text>
94+
<Text $theme="primary">{t('Table of contents')}</Text>
9595
</Button>
9696
<Button
9797
onClick={() => {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export const Heading = ({
4646
block: 'start',
4747
});
4848
}}
49+
$css="text-align: left;"
4950
>
5051
<Text
5152
$theme="primary"

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

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,28 @@ import { useDocTableContentStore } from '../stores';
1010

1111
import { Heading } from './Heading';
1212

13+
const recursiveTextContent = (content: HeadingBlock['content']): string => {
14+
if (!content) {
15+
return '';
16+
}
17+
18+
return content.reduce((acc, content) => {
19+
if (content.type === 'text') {
20+
return acc + content.text;
21+
} else if (content.type === 'link') {
22+
return acc + recursiveTextContent(content.content);
23+
}
24+
25+
return acc;
26+
}, '');
27+
};
28+
1329
type HeadingBlock = {
1430
id: string;
1531
type: string;
1632
text: string;
1733
content: HeadingBlock[];
34+
contentText: string;
1835
props: {
1936
level: number;
2037
};
@@ -31,9 +48,14 @@ export const TableContent = ({ doc }: TableContentProps) => {
3148
const editor = docsStore?.[doc.id]?.editor;
3249
const headingFiltering = useCallback(
3350
() =>
34-
editor?.document.filter(
35-
(block) => block.type === 'heading',
36-
) as unknown as HeadingBlock[],
51+
editor?.document
52+
.filter((block) => block.type === 'heading')
53+
.map((block) => ({
54+
...block,
55+
contentText: recursiveTextContent(
56+
block.content as unknown as HeadingBlock['content'],
57+
),
58+
})) as unknown as HeadingBlock[],
3759
[editor?.document],
3860
);
3961

@@ -71,7 +93,7 @@ export const TableContent = ({ doc }: TableContentProps) => {
7193

7294
for (const heading of headings) {
7395
const elHeading = document.body.querySelector(
74-
`.bn-block-outer[data-id="${heading.id}"]`,
96+
`.bn-block-outer[data-id="${heading.id}"] [data-content-type="heading"]:first-child`,
7597
);
7698

7799
if (!elHeading) {
@@ -121,21 +143,16 @@ export const TableContent = ({ doc }: TableContentProps) => {
121143
<Panel setIsPanelOpen={setClosePanel}>
122144
<Box $padding="small" $maxHeight="95%">
123145
<Box $overflow="auto">
124-
{headings?.map((heading) => {
125-
const content = heading.content?.[0];
126-
const text = content?.type === 'text' ? content.text : '';
127-
128-
return (
129-
<Heading
130-
editor={editor}
131-
headingId={heading.id}
132-
level={heading.props.level}
133-
text={text}
134-
key={heading.id}
135-
isHighlight={headingIdHighlight === heading.id}
136-
/>
137-
);
138-
})}
146+
{headings?.map((heading) => (
147+
<Heading
148+
editor={editor}
149+
headingId={heading.id}
150+
level={heading.props.level}
151+
text={heading.contentText}
152+
key={heading.id}
153+
isHighlight={headingIdHighlight === heading.id}
154+
/>
155+
))}
139156
</Box>
140157
<Box
141158
$height="1px"

0 commit comments

Comments
 (0)