From 41d99e173d3b46c7b15598c3c956e43a93b23e30 Mon Sep 17 00:00:00 2001 From: Fangdun Tsai Date: Wed, 23 Oct 2024 02:25:14 +0800 Subject: [PATCH] feat: support opening in peek view --- package.json | 37 ++++---- packages/frontend/component/package.json | 2 + .../components/attachment-viewer/error.tsx | 7 +- .../components/attachment-viewer/index.tsx | 34 ++++--- .../attachment-viewer/styles.css.ts | 4 +- .../components/attachment-viewer/titlebar.tsx | 33 +++---- .../src/components/attachment-viewer/utils.ts | 40 ++++++++ .../pages/workspace/attachment/index.tsx | 71 ++++++++++++++- .../modules/peek-view/entities/peek-view.ts | 20 ++++ .../view/attachment-preview/index.tsx | 43 +++++++++ .../peek-view/view/peek-view-manager.tsx | 12 +++ yarn.lock | 91 ++++++++++++------- 12 files changed, 302 insertions(+), 92 deletions(-) create mode 100644 packages/frontend/component/src/components/attachment-viewer/utils.ts create mode 100644 packages/frontend/core/src/modules/peek-view/view/attachment-preview/index.tsx diff --git a/package.json b/package.json index 462040f4cf3c3..580e1898325e7 100644 --- a/package.json +++ b/package.json @@ -156,22 +156,25 @@ "@reforged/maker-appimage/@electron-forge/maker-base": "7.5.0", "macos-alias": "npm:@napi-rs/macos-alias@0.0.4", "fs-xattr": "npm:@napi-rs/xattr@latest", - "@blocksuite/affine": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/affine/all", - "@blocksuite/affine-block-embed": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/affine/block-embed", - "@blocksuite/affine-block-list": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/affine/block-list", - "@blocksuite/affine-block-paragraph": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/affine/block-paragraph", - "@blocksuite/affine-block-surface": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/affine/block-surface", - "@blocksuite/affine-components": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/affine/components", - "@blocksuite/data-view": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/affine/data-view", - "@blocksuite/affine-model": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/affine/model", - "@blocksuite/affine-shared": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/affine/shared", - "@blocksuite/affine-widget-scroll-anchoring": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/affine/widget-scroll-anchoring", - "@blocksuite/blocks": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/blocks", - "@blocksuite/block-std": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/framework/block-std", - "@blocksuite/global": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/framework/global", - "@blocksuite/inline": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/framework/inline", - "@blocksuite/store": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/framework/store", - "@blocksuite/sync": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/framework/sync", - "@blocksuite/presets": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/presets" + "@blocksuite/affine": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/affine/all", + "@blocksuite/affine-block-embed": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/affine/block-embed", + "@blocksuite/affine-block-list": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/affine/block-list", + "@blocksuite/affine-block-paragraph": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/affine/block-paragraph", + "@blocksuite/affine-block-surface": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/affine/block-surface", + "@blocksuite/affine-components": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/affine/components", + "@blocksuite/data-view": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/affine/data-view", + "@blocksuite/affine-model": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/affine/model", + "@blocksuite/affine-shared": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/affine/shared", + "@blocksuite/affine-widget-scroll-anchoring": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/affine/widget-scroll-anchoring", + "@blocksuite/blocks": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/blocks", + "@blocksuite/block-std": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/framework/block-std", + "@blocksuite/global": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/framework/global", + "@blocksuite/inline": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/framework/inline", + "@blocksuite/store": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/framework/store", + "@blocksuite/sync": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/framework/sync", + "@blocksuite/presets": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/presets", + "@toeverything/pdf-viewer": "portal:/Users/fundon/dev/toeverything/pdfium-builder/packages/pdf-viewer", + "@toeverything/pdf-viewer-types": "portal:/Users/fundon/dev/toeverything/pdfium-builder/packages/types", + "@toeverything/pdfium": "portal:/Users/fundon/dev/toeverything/pdfium-builder/packages/pdfium" } } diff --git a/packages/frontend/component/package.json b/packages/frontend/component/package.json index 548b71666705b..99ab4f8e8ea55 100644 --- a/packages/frontend/component/package.json +++ b/packages/frontend/component/package.json @@ -38,11 +38,13 @@ "@radix-ui/react-toast": "^1.1.5", "@radix-ui/react-tooltip": "^1.0.7", "@radix-ui/react-visually-hidden": "^1.1.0", + "@toeverything/pdf-viewer": "workspace:*", "@toeverything/theme": "^1.0.11", "@vanilla-extract/dynamic": "^2.1.0", "check-password-strength": "^2.0.10", "clsx": "^2.1.0", "dayjs": "^1.11.10", + "file-type": "^19.1.0", "jotai": "^2.8.0", "lit": "^3.1.2", "lodash-es": "^4.17.21", diff --git a/packages/frontend/component/src/components/attachment-viewer/error.tsx b/packages/frontend/component/src/components/attachment-viewer/error.tsx index 1a62a502a2f1e..0508e5ad68cb2 100644 --- a/packages/frontend/component/src/components/attachment-viewer/error.tsx +++ b/packages/frontend/component/src/components/attachment-viewer/error.tsx @@ -1,3 +1,4 @@ +import type { AttachmentBlockModel } from '@blocksuite/blocks'; import { ArrowDownBigIcon, PageIcon } from '@blocksuite/icons/rc'; import clsx from 'clsx'; import type { ReactElement } from 'react'; @@ -6,15 +7,17 @@ import { Button } from '../../ui/button'; import * as styles from './styles.css'; interface ErrorProps { + model: AttachmentBlockModel; + ext: string; isPDF: boolean; } -export const Error = (_: ErrorProps): ReactElement => { +export const Error = ({ ext }: ErrorProps): ReactElement => { return (

Unable to preview this file

-

.dmg file type not supported.

+

.{ext} file type not supported.