@inkbar/react 0.1.1 → 0.3.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 +49 -7
- package/dist/index.d.mts +140 -106
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +190 -112
- 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
|
|
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 note 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
|
|
|
@@ -39,7 +39,16 @@ import { useState } from 'react'
|
|
|
39
39
|
import {
|
|
40
40
|
InkRoot,
|
|
41
41
|
InkViewport,
|
|
42
|
-
|
|
42
|
+
InkToolbar,
|
|
43
|
+
InkToolButton,
|
|
44
|
+
InkToolbarSeparator,
|
|
45
|
+
InkUndo,
|
|
46
|
+
InkRedo,
|
|
47
|
+
InkPrevPage,
|
|
48
|
+
InkPageInput,
|
|
49
|
+
InkPageCount,
|
|
50
|
+
InkNextPage,
|
|
51
|
+
InkZoomSelect,
|
|
43
52
|
InkNotePopover,
|
|
44
53
|
InkSuggestionCard,
|
|
45
54
|
} from '@inkbar/react'
|
|
@@ -62,8 +71,24 @@ export function Review({
|
|
|
62
71
|
annotations={annotations}
|
|
63
72
|
onAnnotationsChange={setAnnotations}
|
|
64
73
|
>
|
|
65
|
-
<
|
|
74
|
+
<InkToolbar>
|
|
75
|
+
<InkToolButton tool="view" />
|
|
76
|
+
<InkToolButton tool="select" />
|
|
77
|
+
<InkToolButton tool="highlight" />
|
|
78
|
+
<InkToolButton tool="redact-area" />
|
|
79
|
+
<InkToolButton tool="note" />
|
|
80
|
+
<InkToolbarSeparator />
|
|
81
|
+
<InkUndo />
|
|
82
|
+
<InkRedo />
|
|
83
|
+
</InkToolbar>
|
|
66
84
|
<InkViewport />
|
|
85
|
+
<InkToolbar label="Page and zoom">
|
|
86
|
+
<InkPrevPage />
|
|
87
|
+
<InkPageInput />
|
|
88
|
+
<InkPageCount />
|
|
89
|
+
<InkNextPage />
|
|
90
|
+
<InkZoomSelect />
|
|
91
|
+
</InkToolbar>
|
|
67
92
|
<InkNotePopover />
|
|
68
93
|
<InkSuggestionCard />
|
|
69
94
|
</InkRoot>
|
|
@@ -71,6 +96,8 @@ export function Review({
|
|
|
71
96
|
}
|
|
72
97
|
```
|
|
73
98
|
|
|
99
|
+
Each control is a separate component, so put them in any order or leave some out. Buttons show icons from `@inkbar/icons`. Pass your own as `children` to replace one, and use `InkIcon` to put the same icons on your own buttons.
|
|
100
|
+
|
|
74
101
|
`annotations` with `onAnnotationsChange` makes your list the source of truth. Leave them off and Inkbar keeps the state itself, with undo and redo.
|
|
75
102
|
|
|
76
103
|
## Controlled mode
|
|
@@ -118,19 +145,34 @@ Inside `InkRoot`, `useHistory()` returns the same object. Its `batch(fn)` runs `
|
|
|
118
145
|
|
|
119
146
|
`InkNotePopover` opens the thread of the activated note. A new note has no text yet, so the form first writes the note's own text (labelled "Comment"); after that it adds replies.
|
|
120
147
|
|
|
121
|
-
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 notes are never removed. If you add notes yourself (`add({ type: '
|
|
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. Locked notes 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.
|
|
122
149
|
|
|
123
150
|
## Custom rendering
|
|
124
151
|
|
|
125
152
|
Slots are render props. `InkViewport` takes `loading`, `empty`, `error`, `renderAnnotation` and `renderPageError`; `InkNotePopover` 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`, `NotePopoverSlotProps` and `SuggestionCardSlotProps`, the same types the Vue package exports.
|
|
126
153
|
|
|
154
|
+
`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.
|
|
155
|
+
|
|
127
156
|
## Keyboard
|
|
128
157
|
|
|
129
|
-
The scroll
|
|
158
|
+
The scroll area takes focus. From there:
|
|
159
|
+
|
|
160
|
+
- With the `highlight` or `redact-area` tool active, `Enter` turns the text selection into a mark.
|
|
161
|
+
- With the `note` tool active, `Enter` places a note at the centre of the current page and opens it.
|
|
162
|
+
|
|
163
|
+
On a focused annotation:
|
|
164
|
+
|
|
165
|
+
- `Enter` or `Space` selects and activates it. A note opens its thread and a suggested redaction its card; other types are only selected.
|
|
166
|
+
- `ArrowUp` and `ArrowDown` move to the previous or next annotation on the page.
|
|
167
|
+
- `Shift` + arrow moves it by 1 pt, or by 10 pt with `Alt` as well.
|
|
168
|
+
- `Ctrl` or `Cmd` + `Shift` + arrow resizes an area redaction, text box or shape.
|
|
169
|
+
- `Delete` or `Backspace` removes it.
|
|
170
|
+
|
|
171
|
+
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).
|
|
130
172
|
|
|
131
173
|
## Styling
|
|
132
174
|
|
|
133
|
-
Components carry state on data attributes, for example `[data-annotation][data-state="selected"]` and `[data-tool="highlight"][data-state="on"]`. `@inkbar/theme` gives a default look. Your own CSS overrides it without `!important`. `InkRoot`, `InkViewport`, `
|
|
175
|
+
Components carry state on data attributes, for example `[data-annotation][data-state="selected"]` and `[data-tool="highlight"][data-state="on"]`. `@inkbar/theme` gives a default look. Your own CSS overrides it without `!important`. `InkRoot`, `InkViewport`, `InkToolbar` and the toolbar controls accept `className`.
|
|
134
176
|
|
|
135
177
|
## Hooks
|
|
136
178
|
|