blocksuite
blocksuite copied to clipboard
feat: add pdf support
New pdf block
pdf block can be rendered in both 'doc' and 'edgeless' modes, where it acts as a child of affine:note and affine:surface respectively.
type PDFProps = {
sourceId: string;
annotations: Boxed<Y.Map<unknown>>;
xywh: SerializedXYWH;
index: string;
};
export const PDFBlockSchema = defineBlockSchema({
flavour: 'affine:pdf',
props: (internalPrimitives): PDFProps => ({
annotations: internalPrimitives.Boxed(new Workspace.Y.Map()),
sourceId: '',
xywh: `[0,0,100,100]`,
index: 'a0',
}),
metadata: {
version: 1,
role: 'hub',
parent: ['affine:surface', 'affine:note'],
},
toModel() {
return new PDFBlockModel();
},
});
How to load pdf.js
The way of importing PDF.js is determined by the user. The user needs to call the setPDFModule method to tell the blocksuite how to load PDF.js and its plugins.
import { PDFService } from '@blocksuite/blocks';
import pdfWorkerSrc from 'pdfjs-dist/build/pdf.worker.min.mjs?url';
PDFService.setPDFModule([
() => import('pdfjs-dist'),
() => import('pdfjs-dist/web/pdf_viewer.mjs').then(m => m.TextLayerBuilder),
pdfWorkerSrc,
]);
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| blocksuite | ❌ Failed (Inspect) | Feb 28, 2024 3:11am | ||
| blocksuite-docs | ❌ Failed (Inspect) | Feb 28, 2024 3:11am |