From f995f216bddc684673a8f8e23458b292302d8737 Mon Sep 17 00:00:00 2001 From: donteatfriedrice Date: Mon, 20 Jan 2025 15:44:07 +0000 Subject: [PATCH] fix(editor): inline latex editor should not be shown when doc is readonly (#9794) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [BS-2442](https://linear.app/affine-design/issue/BS-2442/只读时-inline-latex-node-点击不应该弹出-modal) --- .../presets/nodes/latex-node/latex-node.ts | 7 +++ tests/affine-cloud/e2e/share-page.spec.ts | 58 +++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/blocksuite/affine/components/src/rich-text/inline/presets/nodes/latex-node/latex-node.ts b/blocksuite/affine/components/src/rich-text/inline/presets/nodes/latex-node/latex-node.ts index 6f0feaf8b9..0812896bb4 100644 --- a/blocksuite/affine/components/src/rich-text/inline/presets/nodes/latex-node/latex-node.ts +++ b/blocksuite/affine/components/src/rich-text/inline/presets/nodes/latex-node/latex-node.ts @@ -161,6 +161,9 @@ export class AffineLatexNode extends SignalWatcher( this.disposables.addFromEvent(this, 'click', e => { e.preventDefault(); e.stopPropagation(); + if (this.readonly) { + return; + } this.toggleEditor(); }); @@ -212,6 +215,10 @@ export class AffineLatexNode extends SignalWatcher( ); } + get readonly() { + return this.std.store.readonly; + } + @property({ attribute: false }) accessor delta: DeltaInsert = { insert: ZERO_WIDTH_SPACE, diff --git a/tests/affine-cloud/e2e/share-page.spec.ts b/tests/affine-cloud/e2e/share-page.spec.ts index 7407605ae6..46a3b50727 100644 --- a/tests/affine-cloud/e2e/share-page.spec.ts +++ b/tests/affine-cloud/e2e/share-page.spec.ts @@ -347,3 +347,61 @@ test('Should show no permission page when the share page is not found', async ({ page.getByText('You do not have access or this content does not exist.') ).toBeVisible(); }); + +test('Inline latex modal should be not shown in shared mode when clicking', async ({ + page, + browser, +}) => { + await page.reload(); + await waitForEditorLoad(page); + await createLocalWorkspace( + { + name: 'test', + }, + page + ); + await enableCloudWorkspaceFromShareButton(page); + const title = getBlockSuiteEditorTitle(page); + await title.pressSequentially('TEST TITLE', { + delay: 50, + }); + await page.keyboard.press('Enter', { delay: 50 }); + + await page.keyboard.type('$$E=mc^2$$'); + await page.keyboard.press('Space'); + + // there should be a inline latex node + const latexLocator = page.locator('affine-latex-node'); + await expect(latexLocator).toBeVisible(); + + // click the latex node + // the latex editor should be shown when the doc can be editing + await latexLocator.click(); + const modalLocator = page.locator('.latex-editor-container'); + await expect(modalLocator).toBeVisible(); + + // enable share page and copy page link + await enableShare(page); + await page.getByTestId('share-menu-copy-link-button').click(); + await page.getByTestId('share-link-menu-copy-page').click(); + + // check share page is accessible + { + const context = await browser.newContext(); + await skipOnboarding(context); + const url: string = await page.evaluate(() => + navigator.clipboard.readText() + ); + const page2 = await context.newPage(); + await page2.goto(url); + await waitForEditorLoad(page2); + + // click the latex node + const latexLocator = page2.locator('affine-latex-node'); + await latexLocator.click(); + + // the latex editor should not be shown when the doc is readonly + const modalLocator = page2.locator('.latex-editor-container'); + await expect(modalLocator).not.toBeVisible(); + } +});