@pdfslick/react 1.1.3 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +46 -67
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  <br><br>
6
6
  <div align="center">
7
- View and Interact with PDFs in React and SolidJS apps
7
+ View and Interact with PDF documents in React apps
8
8
  <br><br>
9
9
 
10
10
  [Getting Started](https://pdfslick.dev/docs) | [Examples](https://pdfslick.dev/examples)
@@ -15,20 +15,10 @@ View and Interact with PDFs in React and SolidJS apps
15
15
  ---
16
16
  <br>
17
17
 
18
- PDFSlick is a library that enables viewing of and interaction with PDF documents in React and SolidJS apps.
18
+ PDFSlick for React is a library which enables viewing of and interaction with PDF documents in React apps.
19
19
  It's build on top of Mozilla's [PDF.js](https://github.com/mozilla/pdf.js), and utilises [Zustand](https://github.com/pmndrs/zustand) to provide a reactive store for the loaded documents.
20
20
 
21
- ## Motivation
22
-
23
- [PDF.js](https://github.com/mozilla/pdf.js) is an amazing piece of software. It is also a very stable and mature one — it powers the PDF viewer in Mozilla Firefox and it's been around since 2011. However, it's all Vanilla JavaScript, and when it comes to using it with libraries like React and SolidJS (although possible) it's a litte bit hard in terms of integrating it in these Component- and reactive-like environments. PDFSlick attempts to wrap all of that fascinating functionality into one that is easier to fit in React and SolidJS worlds — as components and a reactive store.
24
-
25
- ## Core Concepts
26
-
27
- The core of PDFSlick is within the `@pdfslick/core` package. It wraps `PDF.js`'s functionality and links it to the store. This `@pdfslick/core` package is the basis for the React and SolidJS packages, which additionally transform the store and make it suitable for the adequate library, as well as providing components for the PDF viewer and thumbnails.
28
-
29
- Depending on your needs, at this you might find it useful to continue with learning more about using PDFSlick with React and SolidJS respsectivelly. However, if really interested you can learn more about using PDFSlick's `@pdfslick/core` package with Vanilla JS apps and with libraries other than React and SolidJS in the sections below.
30
-
31
- ## Getting Started with React
21
+ ## Getting started with PDFSlick for React
32
22
 
33
23
  To get started with React run:
34
24
  ```shell
@@ -40,80 +30,69 @@ npm install @pdfslick/react
40
30
  You can start using PDFSlick with the `usePDFSlick()` hook, like with the following basic example:
41
31
  ```jsx
42
32
  import { usePDFSlick } from "@pdfslick/react";
43
- import PDFNavigation from "./PDFNavigation";
33
+ import PDFNavigation from "./yourcomponents/PDFNavigation";
44
34
 
35
+ //
36
+ // It is required to include PDFSlick's CSS styles once
37
+ // you can do it in your main `App.tsx` for example
38
+ //
45
39
  import "@pdfslick/react/dist/pdf_viewer.css";
46
40
 
47
- type PDFViewerAppProps = {
41
+ type PDFViewerComponentProps = {
48
42
  pdfFilePath: string;
49
43
  };
50
44
 
51
- const SimplePDFViewer = ({ pdfFilePath }: PDFViewerAppProps) => {
45
+ const PDFViewerComponent = ({ pdfFilePath }: PDFViewerComponent) => {
52
46
  const { viewerRef, usePDFSlickStore, PDFSlickViewer } = usePDFSlick(pdfFilePath, {
53
- singlePageViewer: true,
54
47
  scaleValue: "page-fit"
55
48
  });
56
49
 
50
+ /*
51
+ Access the store with `usePDFSlickStore()` hook — you can pass is
52
+ as a prop to other components (like with `<PDFNavigation />` below)
53
+ Toolbars, Sidebars, components which render thumbnails etc.
54
+ and use it as here to get and react on
55
+ PDF document's and viewer's properties and changes
56
+ */
57
+ const scale = usePDFSlickStore((s) => s.scale);
58
+ const numPages = usePDFSlickStore((s) => s.numPages);
59
+ const pageNumber = usePDFSlickStore((s) => s.pageNumber);
60
+
57
61
  return (
58
- <div className="absolute inset-0 bg-slate-200/70 pdfSlick">
59
- <div className="flex-1 relative h-full">
62
+ <div className="absolute inset-0 pdfSlick">
63
+ <div className="relative h-full">
60
64
  <PDFSlickViewer {...{ viewerRef, usePDFSlickStore }} />
61
- <PDFNavigation {...{ usePDFSlickStore }} />
62
- </div>
63
- </div>
64
- );
65
- };
66
-
67
- export default SimplePDFViewer;
68
- ```
69
-
70
- Provided with the PDF Document path and options object, the `usePDFSlick()` hook returns an object consisting (among the other things) of:
71
- - `PDFSlickViewer` — the PDF Viewer component used for viewing the PDF document
72
- - `viewerRef` — a `RefCallback` that is provided as a prop to the `<PDFSlickViewer />` component
73
- - `usePDFSlickStore` — a hook to the PDFSlick store
74
-
75
- <br><br>
76
- [Read more about using PDFSlick with React](https://pdfslick.dev/docs/react) | [Checkout the React Examples](./apps/web/examples)
77
65
 
78
- ## SolidJS
79
-
80
- To get started with PDFSlick for SolidJS React run:
81
- ```shell
82
- npm install @pdfslick/solid
83
- # yarn add @pdfslick/solid
84
- # pnpm add @pdfslick/solid
85
- ```
86
-
87
- You can start using PDFSlick with the `usePDFSlick()` hook, like with the following basic example:
88
- ```jsx
89
- import { Component, createSignal } from "solid-js";
90
- import { usePDFSlick } from "@pdfslick/solid";
91
-
92
- type PDFViewerAppProps = {
93
- pdfFilePath: string;
94
- };
95
-
96
- const PDFViewerApp: Component<PDFViewerAppProps> = ({ pdfFilePath }) => {
97
- const { viewerRef, pdfSlickStore: store, PDFSlickViewer } =
98
- usePDFSlick(pdfFilePath);
66
+ {/*
67
+ Pass PDFSlick's store to your custom components
68
+ */}
69
+ <PDFNavigation {...{ usePDFSlickStore }} />
99
70
 
100
- return (
101
- <div class="absolute inset-0 bg-slate-200/70 flex flex-col pdfSlick">
102
- <div class="flex-1 relative h-full">
103
- <PDFSlickViewer {...{ store, viewerRef }} />
71
+ {/*
72
+ PDFSlick's store values automatically update
73
+ */}
74
+ <div className="absolute w-full top-0 left-0">
75
+ <p>Current scale: {scale}</p>
76
+ <p>Current page number: {pageNumber}</p>
77
+ <p>Total number of pages: {numPages}</p>
78
+ </div>
104
79
  </div>
105
80
  </div>
106
81
  );
107
82
  };
108
83
 
109
- export default PDFViewerApp;
84
+ export default PDFViewerComponent;
110
85
  ```
111
86
 
112
- Provided with the PDF Document path and options object, the `usePDFSlick()` hook returns an object consisting (among the other things) of:
113
- - `PDFSlickViewer` the PDF Viewer component used for viewing the PDF document
114
- - `viewerRef` a `RefCallback` that is provided as a prop to the `<PDFSlickViewer />` component
115
- - `pdfSlickStore` the PDFSlick store
87
+ Provided with the PDF Document path and PDFSlick options object, the `usePDFSlick()` hook returns an object consisting (among the other things) of:
88
+ - `PDFSlickViewer` is the PDF Viewer component used for viewing the PDF document
89
+ - `viewerRef` is the `ref` callback that is provided as a prop to the `<PDFSlickViewer />` component
90
+ - `usePDFSlickStore` enables using PDFSlick store within your React components
116
91
 
117
- <br><br>
118
- [Read more about using PDFSlick with SolidJS](https://pdfslick.dev/docs/solid) | [Checkout the SolidJS Examples](./apps/solidweb/src/examples)
92
+ <br>
93
+
94
+ [More on using PDFSlick with React](https://pdfslick.dev/docs/react) | [Checkout the React Examples](./apps/web/examples)
119
95
 
96
+ ## Thanks
97
+ - [Vane Kosturanov](https://kosturanov.com/portfolio/logo-branding-design) for designing the logo
98
+ - [VS Code Icons](https://github.com/microsoft/vscode-codicons) for the icons used throughout the examples
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdfslick/react",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "source": "./index.tsx",
5
5
  "main": "dist/umd/index.js",
6
6
  "module": "dist/esm/index.js",