@inkbar/react 0.2.0 → 0.4.0
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.
- package/README.md +33 -10
- package/dist/index.d.mts +1516 -161
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1198 -44
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
---
|
|
22
22
|
|
|
23
|
-
Drop a PDF viewer into your React app and let people highlight text, leave notes with replies and review redactions. `@inkbar/react` gives you components and hooks to build your own toolbars, plus
|
|
23
|
+
Drop a PDF viewer into your React app and let people highlight text, leave notes with replies and review redactions. `@inkbar/react` gives you components and hooks to build your own toolbars, plus thread and suggestion popovers, all styled by `@inkbar/theme`.
|
|
24
24
|
|
|
25
25
|
Annotations are plain typed objects. Control them from your own state, or let Inkbar hold them with undo and redo.
|
|
26
26
|
|
|
@@ -30,7 +30,7 @@ Annotations are plain typed objects. Control them from your own state, or let In
|
|
|
30
30
|
pnpm add @inkbar/react @inkbar/core @inkbar/theme
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
React 19
|
|
33
|
+
React 19 and React DOM 19 are peer dependencies. Add the Vite plugin from `@inkbar/core/vite` so PDF.js can load its worker and fonts; the [`@inkbar/core` README](https://github.com/inkbar/inkbar/tree/main/packages/core#serving-pdfjs-assets) covers it. The package is marked `'use client'`, so a React Server Components app can import it from a server component.
|
|
34
34
|
|
|
35
35
|
## Usage
|
|
36
36
|
|
|
@@ -49,7 +49,7 @@ import {
|
|
|
49
49
|
InkPageCount,
|
|
50
50
|
InkNextPage,
|
|
51
51
|
InkZoomSelect,
|
|
52
|
-
|
|
52
|
+
InkThreadPopover,
|
|
53
53
|
InkSuggestionCard,
|
|
54
54
|
} from '@inkbar/react'
|
|
55
55
|
import type { Annotation } from '@inkbar/core'
|
|
@@ -72,6 +72,7 @@ export function Review({
|
|
|
72
72
|
onAnnotationsChange={setAnnotations}
|
|
73
73
|
>
|
|
74
74
|
<InkToolbar>
|
|
75
|
+
<InkToolButton tool="select-text" />
|
|
75
76
|
<InkToolButton tool="select" />
|
|
76
77
|
<InkToolButton tool="highlight" />
|
|
77
78
|
<InkToolButton tool="redact-area" />
|
|
@@ -88,7 +89,7 @@ export function Review({
|
|
|
88
89
|
<InkNextPage />
|
|
89
90
|
<InkZoomSelect />
|
|
90
91
|
</InkToolbar>
|
|
91
|
-
<
|
|
92
|
+
<InkThreadPopover />
|
|
92
93
|
<InkSuggestionCard />
|
|
93
94
|
</InkRoot>
|
|
94
95
|
)
|
|
@@ -140,19 +141,41 @@ Inside `InkRoot`, `useHistory()` returns the same object. Its `batch(fn)` runs `
|
|
|
140
141
|
|
|
141
142
|
`key` identifies the document. Reuse the same key when only the signed URL changes and the document is not reloaded.
|
|
142
143
|
|
|
143
|
-
##
|
|
144
|
+
## Thread popover
|
|
144
145
|
|
|
145
|
-
`
|
|
146
|
+
`InkThreadPopover` opens the comment thread of the activated note or text markup (a highlight, underline, strikeout or squiggly). A new note or highlight has no text yet, so the form first writes its own `contents` (labelled "Comment"); after that it adds replies. A highlight with a comment shows a small marker at its end. Replies show in the thread only; the page draws just the note or highlight they answer.
|
|
146
147
|
|
|
147
|
-
A root note with no text and no replies is removed when its popover closes, or when activation moves to another annotation, so abandoned notes do not stay on the page. Locked
|
|
148
|
+
A root note with no text and no replies is removed when its popover closes, or when activation moves to another annotation, so abandoned notes do not stay on the page. A highlight stays: the mark is the point. Locked annotations are never removed. If you add notes yourself (`add({ type: 'text', ... })`), give them `contents`, or they will be removed the first time someone opens and closes them.
|
|
149
|
+
|
|
150
|
+
The highlight tool leaves `contents` free for the comment. `doc.text(page)` returns the page's text items; match the markup's `quads` against them to get the marked text. `InkHighlightMenu` is a split button for the tool: it picks the markup kind and its colour.
|
|
151
|
+
|
|
152
|
+
## Signatures
|
|
153
|
+
|
|
154
|
+
`InkSignatureMenu` lists saved signatures, picks one for the `signature` tool, removes them, and opens `InkSignatureDialog` to draw, type or upload a new one. These are marks on the page, not cryptographic signatures. Pass `signatures` to `InkRoot` to keep them somewhere: `createLocalSignatureStore(key)` from `@inkbar/core` uses `localStorage`, and without it they last until reload. `signatureFonts` lists the handwriting fonts the Type tab offers; load them with `@font-face`. A placed signature keeps its aspect ratio when resized.
|
|
148
155
|
|
|
149
156
|
## Custom rendering
|
|
150
157
|
|
|
151
|
-
Slots are render props. `InkViewport` takes `loading`, `empty`, `error`, `renderAnnotation` and `renderPageError`; `
|
|
158
|
+
Slots are render props. `InkViewport` takes `loading`, `empty`, `error`, `renderAnnotation` and `renderPageError`; `InkThreadPopover` and `InkSuggestionCard` take a function as `children`; `InkToolButton` takes a node or a function of `{ active, label }`. The props each receives are typed as `AnnotationSlotProps`, `ThreadPopoverSlotProps` and `SuggestionCardSlotProps`, the same types the Vue package exports.
|
|
159
|
+
|
|
160
|
+
`InkRoot`, `InkToolbar`, `InkToolButton`, `InkUndo`, `InkRedo`, `InkPrevPage`, `InkNextPage`, `InkZoomIn` and `InkZoomOut` take `asChild` to render your own element in place of theirs, such as a button from your design system. Pass that element as the only child. The control keeps its behaviour and accessible name.
|
|
152
161
|
|
|
153
162
|
## Keyboard
|
|
154
163
|
|
|
155
|
-
The scroll
|
|
164
|
+
The scroll area takes focus. From there:
|
|
165
|
+
|
|
166
|
+
- With the `highlight` or `redact-area` tool active, `Enter` turns the text selection into a mark.
|
|
167
|
+
- With the `note` tool active, `Enter` places a note at the centre of the current page and opens it.
|
|
168
|
+
- With the `signature` tool active, `Enter` places the chosen signature at the centre of the current page.
|
|
169
|
+
|
|
170
|
+
On a focused annotation:
|
|
171
|
+
|
|
172
|
+
- `Enter` or `Space` selects and activates it. A note opens its thread and a suggested redaction its card; other types are only selected.
|
|
173
|
+
- `ArrowUp` and `ArrowDown` move to the previous or next annotation on the page.
|
|
174
|
+
- `Shift` + arrow moves it by 1 pt, or by 10 pt with `Alt` as well.
|
|
175
|
+
- `Ctrl` or `Cmd` + `Shift` + arrow resizes an area redaction, text box or shape.
|
|
176
|
+
- `Delete` or `Backspace` removes it.
|
|
177
|
+
|
|
178
|
+
The full table, with the zoom and page keys, is in the [`@inkbar/core` README](https://github.com/inkbar/inkbar/tree/main/packages/core#tools-and-keyboard).
|
|
156
179
|
|
|
157
180
|
## Styling
|
|
158
181
|
|
|
@@ -160,7 +183,7 @@ Components carry state on data attributes, for example `[data-annotation][data-s
|
|
|
160
183
|
|
|
161
184
|
## Hooks
|
|
162
185
|
|
|
163
|
-
`useDocument`, `useAnnotations`, `useTool`, `useSelection`, `useZoom`, `usePage`, `useHistory` and `useEmbedded` read the state of the nearest `InkRoot`. Build your own toolbar or side panel from them.
|
|
186
|
+
`useDocument`, `useAnnotations`, `useTool`, `useSelection`, `useZoom`, `usePage`, `useHistory` and `useEmbedded` read the state of the nearest `InkRoot`. Build your own toolbar or side panel from them. Tool options, such as the shape kind, last as long as `InkRoot`. The tool style that `useToolStyle` reads and sets (colours, line style, text style) belongs to the document: opening another one starts again from the theme's defaults.
|
|
164
187
|
|
|
165
188
|
## Licence
|
|
166
189
|
|