From 4524617e38e575d5c06b2d2ab582ea15e57f5346 Mon Sep 17 00:00:00 2001 From: fantasticit Date: Tue, 3 Jan 2023 22:01:14 +0800 Subject: [PATCH] feat: support preview office file --- packages/client/src/components/icons/IconPDF.tsx | 14 ++++++++++++++ packages/client/src/components/icons/IconPPT.tsx | 15 +++++++++++++++ .../client/src/components/icons/IconSheet.tsx | 15 +++++++++++++++ packages/client/src/components/icons/IconWord.tsx | 14 ++++++++++++++ packages/client/src/components/icons/index.tsx | 2 ++ .../tiptap/core/wrappers/attachment/file-icon.tsx | 12 +++++++++++- .../wrappers/attachment/player/index.module.scss | 8 ++++++++ .../core/wrappers/attachment/player/index.tsx | 9 +++++++++ packages/client/src/tiptap/prose-utils/file.ts | 9 ++++++++- 9 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 packages/client/src/components/icons/IconPPT.tsx create mode 100644 packages/client/src/components/icons/IconSheet.tsx diff --git a/packages/client/src/components/icons/IconPDF.tsx b/packages/client/src/components/icons/IconPDF.tsx index b2e7b592..6c023d5e 100644 --- a/packages/client/src/components/icons/IconPDF.tsx +++ b/packages/client/src/components/icons/IconPDF.tsx @@ -35,3 +35,17 @@ export const IconPDF: React.FC<{ style?: React.CSSProperties }> = ({ style = {} /> ); }; + +export const IconFilePDF: React.FC<{ style?: React.CSSProperties }> = ({ style = {} }) => { + return ( + + + + + } + /> + ); +}; diff --git a/packages/client/src/components/icons/IconPPT.tsx b/packages/client/src/components/icons/IconPPT.tsx new file mode 100644 index 00000000..12f24c65 --- /dev/null +++ b/packages/client/src/components/icons/IconPPT.tsx @@ -0,0 +1,15 @@ +import { Icon } from '@douyinfe/semi-ui'; + +export const IconFilePPT: React.FC<{ style?: React.CSSProperties }> = ({ style = {} }) => { + return ( + + + + + } + /> + ); +}; diff --git a/packages/client/src/components/icons/IconSheet.tsx b/packages/client/src/components/icons/IconSheet.tsx new file mode 100644 index 00000000..68cea258 --- /dev/null +++ b/packages/client/src/components/icons/IconSheet.tsx @@ -0,0 +1,15 @@ +import { Icon } from '@douyinfe/semi-ui'; + +export const IconFileSheet: React.FC<{ style?: React.CSSProperties }> = ({ style = {} }) => { + return ( + + + + + } + /> + ); +}; diff --git a/packages/client/src/components/icons/IconWord.tsx b/packages/client/src/components/icons/IconWord.tsx index 3846fc95..5302652b 100644 --- a/packages/client/src/components/icons/IconWord.tsx +++ b/packages/client/src/components/icons/IconWord.tsx @@ -35,3 +35,17 @@ export const IconWord: React.FC<{ style?: React.CSSProperties }> = ({ style = {} /> ); }; + +export const IconFileWord: React.FC<{ style?: React.CSSProperties }> = ({ style = {} }) => { + return ( + + + + + } + /> + ); +}; diff --git a/packages/client/src/components/icons/index.tsx b/packages/client/src/components/icons/index.tsx index 220d4640..4c5cf48e 100644 --- a/packages/client/src/components/icons/index.tsx +++ b/packages/client/src/components/icons/index.tsx @@ -45,12 +45,14 @@ export * from './IconMindSide'; export * from './IconOrderedList'; export * from './IconOverview'; export * from './IconPDF'; +export * from './IconPPT'; export * from './IconQuote'; export * from './IconRight'; export * from './IconSearch'; export * from './IconSearchReplace'; export * from './IconSetting'; export * from './IconShare'; +export * from './IconSheet'; export * from './IconSplitCell'; export * from './IconStatus'; export * from './IconStructure'; diff --git a/packages/client/src/tiptap/core/wrappers/attachment/file-icon.tsx b/packages/client/src/tiptap/core/wrappers/attachment/file-icon.tsx index 28800f19..10878e51 100644 --- a/packages/client/src/tiptap/core/wrappers/attachment/file-icon.tsx +++ b/packages/client/src/tiptap/core/wrappers/attachment/file-icon.tsx @@ -1,4 +1,5 @@ import { IconFile, IconImage, IconSong, IconVideo } from '@douyinfe/semi-icons'; +import { IconFilePDF, IconFilePPT, IconFileSheet, IconFileWord } from 'components/icons'; import { normalizeFileType } from 'tiptap/prose-utils'; export const getFileTypeIcon = (fileType: string) => { @@ -18,7 +19,16 @@ export const getFileTypeIcon = (fileType: string) => { return ; case 'pdf': - return ; + return ; + + case 'word': + return ; + + case 'excel': + return ; + + case 'ppt': + return ; default: { const value: never = type; diff --git a/packages/client/src/tiptap/core/wrappers/attachment/player/index.module.scss b/packages/client/src/tiptap/core/wrappers/attachment/player/index.module.scss index c04d2a61..4bf48a96 100644 --- a/packages/client/src/tiptap/core/wrappers/attachment/player/index.module.scss +++ b/packages/client/src/tiptap/core/wrappers/attachment/player/index.module.scss @@ -10,3 +10,11 @@ height: 100%; } } + +.iframeWrapper { + width: 100%; + margin: auto; + overflow: auto; + border: 0; + outline: none; +} diff --git a/packages/client/src/tiptap/core/wrappers/attachment/player/index.tsx b/packages/client/src/tiptap/core/wrappers/attachment/player/index.tsx index cd8ea655..90d8727b 100644 --- a/packages/client/src/tiptap/core/wrappers/attachment/player/index.tsx +++ b/packages/client/src/tiptap/core/wrappers/attachment/player/index.tsx @@ -33,6 +33,15 @@ export const Player: React.FC = ({ url, fileType }) => { if (type === 'pdf') return ; + if (type === 'word' || type === 'excel' || type === 'ppt') { + return ( +