-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
226 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/pdf-viewer/src/plugins/PDFContextMenuPlugin/PDFContextMenuPlugin.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { useContext, useEffect } from 'react'; | ||
import type { ContextMenuItemType } from '@orca-fe/pocket/es/context-menu'; | ||
import { useMemoizedFn } from 'ahooks'; | ||
import PDFViewerContext from '../../context'; | ||
|
||
type MenuItemType = ContextMenuItemType & { order?: number }; | ||
|
||
export interface PDFContextMenuPluginProps { | ||
menu?: MenuItemType[] | ((page: number) => MenuItemType[]); | ||
} | ||
|
||
const PDFContextMenuPlugin = (props: PDFContextMenuPluginProps) => { | ||
const { menu } = props; | ||
const collectMenu = useMemoizedFn((page: number) => (typeof menu === 'function' ? menu(page) : menu)); | ||
const { onMenuCollect, offMenuCollect } = useContext(PDFViewerContext); | ||
useEffect(() => { | ||
onMenuCollect(collectMenu); | ||
return () => { | ||
offMenuCollect(collectMenu); | ||
}; | ||
}); | ||
return null; | ||
}; | ||
|
||
export default PDFContextMenuPlugin; |
5 changes: 5 additions & 0 deletions
5
packages/pdf-viewer/src/plugins/PDFContextMenuPlugin/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import PDFContextMenuPlugin from './PDFContextMenuPlugin'; | ||
|
||
export default PDFContextMenuPlugin; | ||
|
||
export * from './PDFContextMenuPlugin'; |
31 changes: 31 additions & 0 deletions
31
packages/pdf-viewer/src/plugins/PDFContextPrintPlugin/PdfContextPrintPlugin.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React, { useContext } from 'react'; | ||
import printJS from 'print-js'; | ||
import PDFContextMenuPlugin from '../PDFContextMenuPlugin'; | ||
import PDFViewerContext from '../../context'; | ||
|
||
export interface PdfContextPrintPluginProps {} | ||
|
||
const PdfContextPrintPlugin = (props: PdfContextPrintPluginProps) => { | ||
const { pdfViewer } = useContext(PDFViewerContext); | ||
return ( | ||
<PDFContextMenuPlugin | ||
menu={[ | ||
{ | ||
key: 'print', | ||
text: '打印', | ||
onClick: async () => { | ||
const data = await pdfViewer.getPDFInstance()?.getData(); | ||
if (data) { | ||
const blob = new Blob([data.buffer], { type: 'application/pdf' }); | ||
const url = URL.createObjectURL(blob); | ||
printJS(url); | ||
URL.revokeObjectURL(url); | ||
} | ||
}, | ||
}, | ||
]} | ||
/> | ||
); | ||
}; | ||
|
||
export default PdfContextPrintPlugin; |
5 changes: 5 additions & 0 deletions
5
packages/pdf-viewer/src/plugins/PDFContextPrintPlugin/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import PdfContextPrintPlugin from './PdfContextPrintPlugin'; | ||
|
||
export default PdfContextPrintPlugin; | ||
|
||
export * from './PdfContextPrintPlugin'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { useMemorizedFn } from '@orca-fe/hooks'; | ||
import { useState } from 'react'; | ||
|
||
export default function useCollector<T>() { | ||
const [_this] = useState({ | ||
callbacks: [] as ((...args: any[]) => T[])[], | ||
}); | ||
|
||
const collect = useMemorizedFn((...args) => _this.callbacks.map(cb => cb(...args)).flat()); | ||
|
||
const on = useMemorizedFn((callback: (...args: any[]) => T[]) => { | ||
_this.callbacks.push(callback); | ||
}); | ||
|
||
const off = useMemorizedFn((callback: (...args: any[]) => T[]) => { | ||
_this.callbacks = _this.callbacks.filter(cb => cb !== callback); | ||
}); | ||
|
||
return { | ||
collect, | ||
on, | ||
off, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# @orca-fe/pocket | ||
|
||
## 3.3.0 | ||
|
||
### Minor Changes | ||
|
||
- feat: PDFViewer ContextMenu 插件 | ||
|
||
## 3.2.12 | ||
|
||
### Patch Changes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
3a68c87
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
orca-pocket-page – ./
orca-pocket-page.vercel.app
orca-pocket-page-orca-fe.vercel.app
orca.nicokam.work
orca-pocket-page-git-master-orca-fe.vercel.app