Skip to content

Commit 6ce6cb3

Browse files
committed
feat(core): add outline viewer for share page (#8190)
1 parent daa9d9f commit 6ce6cb3

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

packages/frontend/core/src/components/blocksuite/outline-viewer/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const EditorOutlineViewer = ({
1111
}: {
1212
editor: AffineEditorContainer | null;
1313
show: boolean;
14-
openOutlinePanel: () => void;
14+
openOutlinePanel?: () => void;
1515
}) => {
1616
const outlineViewerRef = useRef<OutlineViewer | null>(null);
1717

@@ -34,7 +34,10 @@ export const EditorOutlineViewer = ({
3434
if (outlineViewerRef.current.editor !== editor) {
3535
outlineViewerRef.current.editor = editor;
3636
}
37-
if (outlineViewerRef.current.toggleOutlinePanel !== openOutlinePanel) {
37+
if (
38+
outlineViewerRef.current.toggleOutlinePanel !== openOutlinePanel &&
39+
openOutlinePanel
40+
) {
3841
outlineViewerRef.current.toggleOutlinePanel = openOutlinePanel;
3942
}
4043

packages/frontend/core/src/pages/workspace/share/share-page.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Scrollable } from '@affine/component';
22
import { AppFallback } from '@affine/core/components/affine/app-container';
3+
import { EditorOutlineViewer } from '@affine/core/components/blocksuite/outline-viewer';
34
import { PageDetailEditor } from '@affine/core/components/page-detail-editor';
45
import { SharePageNotFoundError } from '@affine/core/components/share-page-not-found-error';
56
import { AppContainer, MainContainer } from '@affine/core/components/workspace';
@@ -112,7 +113,8 @@ const SharePageInner = ({
112113
const [workspace, setWorkspace] = useState<Workspace | null>(null);
113114
const [page, setPage] = useState<Doc | null>(null);
114115
const [editor, setEditor] = useState<Editor | null>(null);
115-
const [_, setActiveBlocksuiteEditor] = useActiveBlocksuiteEditor();
116+
const [editorContainer, setActiveBlocksuiteEditor] =
117+
useActiveBlocksuiteEditor();
116118

117119
useEffect(() => {
118120
// create a workspace for share page
@@ -229,6 +231,10 @@ const SharePageInner = ({
229231
</Scrollable.Viewport>
230232
<Scrollable.Scrollbar />
231233
</Scrollable.Root>
234+
<EditorOutlineViewer
235+
editor={editorContainer}
236+
show={publishMode === 'page'}
237+
/>
232238
<SharePageFooter />
233239
</div>
234240
</div>

tests/affine-cloud/e2e/share-page.spec.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,57 @@ test('can enable share page', async ({ page, browser }) => {
6969
}
7070
});
7171

72+
test('share page should have toc', async ({ page, browser }) => {
73+
await page.reload();
74+
await waitForEditorLoad(page);
75+
await createLocalWorkspace(
76+
{
77+
name: 'test',
78+
},
79+
page
80+
);
81+
await enableCloudWorkspaceFromShareButton(page);
82+
const title = getBlockSuiteEditorTitle(page);
83+
await title.pressSequentially('TEST TITLE', {
84+
delay: 50,
85+
});
86+
await page.keyboard.press('Enter', { delay: 50 });
87+
88+
await page.keyboard.type('# Heading 1');
89+
await page.keyboard.press('Enter');
90+
await page.keyboard.type('# Heading 2');
91+
await page.keyboard.press('Enter');
92+
93+
// enable share page and copy page link
94+
await enableShare(page);
95+
await page.getByTestId('share-menu-copy-link-button').click();
96+
await page.getByTestId('share-link-menu-copy-page').click();
97+
98+
// check share page is accessible
99+
{
100+
const context = await browser.newContext();
101+
await skipOnboarding(context);
102+
const url: string = await page.evaluate(() =>
103+
navigator.clipboard.readText()
104+
);
105+
const page2 = await context.newPage();
106+
await page2.goto(url);
107+
await waitForEditorLoad(page2);
108+
109+
const tocIndicators = page2.locator(
110+
'affine-outline-viewer .outline-viewer-indicator'
111+
);
112+
await expect(tocIndicators).toHaveCount(3);
113+
await expect(tocIndicators.nth(0)).toBeVisible();
114+
await expect(tocIndicators.nth(1)).toBeVisible();
115+
await expect(tocIndicators.nth(2)).toBeVisible();
116+
117+
const viewer = page2.locator('affine-outline-viewer');
118+
await tocIndicators.first().hover({ force: true });
119+
await expect(viewer).toBeVisible();
120+
}
121+
});
122+
72123
test('share page with default edgeless', async ({ page, browser }) => {
73124
await page.reload();
74125
await waitForEditorLoad(page);

0 commit comments

Comments
 (0)