Skip to content

Commit 92e6ae0

Browse files
committed
Update contentStateCallback documentation.
1 parent da49876 commit 92e6ae0

File tree

3 files changed

+76
-5
lines changed

3 files changed

+76
-5
lines changed

docs/components/CallToAction.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@ type StyledCallToActionVariants = VariantProps<typeof StyledCallToAction>;
88
interface CallToActionProps {
99
href: string;
1010
text: string;
11+
id?: HTMLElement["id"];
12+
target?: HTMLAnchorElement["target"];
1113
}
1214

1315
const CallToAction: React.FC<
1416
CallToActionProps & StyledCallToActionVariants
15-
> = ({ href, size, text }) => {
17+
> = ({ href, size, text, id, target }) => {
1618
return (
1719
<StyledCallToAction
1820
className="nx-bg-primary-400/10"
1921
href={href}
2022
size={size}
23+
id={id}
24+
target={target}
2125
>
2226
{text} <span></span>
2327
</StyledCallToAction>

pages/docs/viewer.mdx

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ import { Bleed } from "nextra-theme-docs";
88
import { Tabs, Tab } from "nextra/components";
99
import { Steps } from "nextra/components";
1010

11+
export const handleContentStateCallback = ({ encoded, json }) => {
12+
console.log({
13+
encoded, // base64 encoded JSON
14+
json, // raw JSON
15+
});
16+
};
17+
1118
# Viewer
1219

1320
A UI component that renders a multicanvas IIIF item viewer with pan-zoom support for `Image` via [OpenSeadragon](https://openseadragon.github.io/) and `Video` and `Sound` content resources using the [HTML video element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video).
@@ -147,6 +154,7 @@ const MyCustomViewer = () => {
147154
| `iiifContent` | `string` | Yes | |
148155
| `iiifContentSearchQuery` | [See Content Search](#content-search) | No | |
149156
| `canvasIdCallback` | `function` | No | |
157+
| `contentStateCallback` | [See IIIF Content State](#iiif-content-state) | No | |
150158
| `customDisplays` | [See Custom Displays](#custom-displays) | No | |
151159
| `customTheme` | `object` | No | |
152160
| `plugins` | [See Plugins](#plugins) | No | |
@@ -284,9 +292,56 @@ Clients may wish to use their own display components (for example a PDF Viewer,
284292
| `customDisplays.target.canvasId` | `string[]` | No | |
285293
| `customDisplays.target.paintingFormat` | `string[]` | No | |
286294

287-
### Content search
295+
### IIIF Content State
296+
297+
Clover supports IIIF Content State in multiple ways. This specifications allows you to render a provided state to the Viewer component, including the active canvas, a `xywh` or `t` selector, and body which might be textual content. The Clover Viewer can both provide the current state of a component and render a given state.
298+
299+
#### Content State Callback
300+
301+
You can use the `contentStateCallback` prop to receive the current content state as a base64 encoded JSON string and as raw JSON. Using this, you can provide a consuming application the view of the user. This could helpful for sharing or storing the state for later use by a user. To review this further, see [Content State](viewer/content-state).
302+
303+
<Tabs items={["Code", "Preview"]}>
304+
{/* prettier-ignore */}
305+
<Tab>
306+
```jsx
307+
const handleContentStateCallback = ({ encoded, json }) => {
308+
console.log({
309+
encoded, // base64 encoded JSON
310+
json, // raw JSON
311+
});
312+
};
313+
314+
<Viewer
315+
iiifContent="https://iiif.harvardartmuseums.org/manifests/object/299837"
316+
contentStateCallback={handleContentStateCallback}
317+
/>;
318+
```
319+
320+
</Tab>
321+
{/* prettier-ignore */}
322+
<Tab>
323+
**Note:** Inspect the page to track your console log.
324+
325+
<div style={{ position: "relative", height: "700px", zIndex: "0" }}>
326+
<Viewer
327+
iiifContent="https://iiif.harvardartmuseums.org/manifests/object/299837"
328+
contentStateCallback={handleContentStateCallback}
329+
options={{
330+
showTitle: false,
331+
informationPanel: {
332+
open: "false",
333+
renderAbout: false,
334+
renderToggle: false,
335+
}
336+
}}
337+
/>
338+
</div>
339+
</Tab>
340+
</Tabs>
288341

289-
Clover supports IIIF content search v2. In order to display content search in the information panel, add a content search service to the manifest.
342+
### IIIF Content Search
343+
344+
Clover supports IIIF Content Search v2. In order to display content search in the information panel, add a content search service to the manifest.
290345

291346
```json
292347
{
@@ -478,11 +533,13 @@ Additional CSS classes are made available on structural HTML elements in the Vie
478533
- [Ruby](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/ruby) (`<ruby/>`) and [Ruby Text](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/rt) (`<rt/>`)
479534

480535
- Several WebVTT-specific tags are processed in special ways:
536+
481537
- Voice Tags (e.g., `<v speaker>Caption</v>`) are wrapped in `<span title="speaker"/>` and can be styled using the CSS selector `.webvtt-cue span[title="speaker"]`
482538
- Class Tags (e.g., `<c.classToAdd>Caption</c>`) are wrapped in `<span class="classtoAdd"/>` and can be styled using the CSS selector `.webvtt-cue span.classToAdd`
483539
- Language Tags (e.g., `<lang.en-US>English Caption</lang>`) are handled the same as Class Tags - wrapped in `<span class="en-US"/>` and can be styled using the CSS selector `.webvtt-cue span.en-US`
484540

485541
- WebVTT CSS extensions (`STYLE` blocks and `::cue` pseudo-elements) are not supported
542+
486543
---
487544

488545
### Request Headers

pages/docs/viewer/content-state.mdx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,21 @@ This is a helper page to demonstrate the retrieving the current IIIF Content Sta
8686

8787
### Current Content State
8888

89-
This section displays the raw JSON and base64 encoded JSON of the IIIF Content State for this Viewer instance. <a href="#" id="content-state-preview">Preview</a> the current content state of the Viewer component, which
89+
This section displays the raw JSON and base64 encoded JSON of the IIIF Content State for this Viewer instance. Preview the current content state of the Viewer component, which
9090
includes information about the currently displayed canvas, zoom level, and other
9191
relevant details. This can be useful for debugging or for saving the state of
9292
the viewer.
9393

94+
<div style={{ marginTop: "1rem" }}>
95+
<CallToAction
96+
href="/docs/viewer"
97+
text="Preview Content State"
98+
size="small"
99+
id="content-state-preview"
100+
target="_blank"
101+
/>
102+
</div>
103+
94104
<div
95105
style={{
96106
display: "flex",
@@ -113,7 +123,7 @@ the viewer.
113123
fontSize: "0.833rem",
114124
resize: "none",
115125
}}
116-
placeholder='Enter any body text here to see how it is displayed in the viewer'
126+
placeholder='Enter any body text here to see how it is displayed in the viewer. Note that character lenghts longer than a few hundred characters may not display correctly in the viewer due to limitations in browser maxchar lengths.'
117127
></textarea>
118128
</div>
119129
<div style={{ width: "33.33%" }}>

0 commit comments

Comments
 (0)