Skip to content

Commit aacea16

Browse files
committed
feat: add accept reject redaction example
1 parent 02455b3 commit aacea16

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import type {
2+
AnnotationTooltipCallback,
3+
Instance,
4+
RedactionAnnotation,
5+
} from "@nutrient-sdk/viewer";
6+
import { baseOptions } from "../../shared/base-options";
7+
8+
let instance: Instance | null = null;
9+
10+
const getAllAnnotations = async () => {
11+
if (!instance)
12+
return window.NutrientViewer.Immutable.List<RedactionAnnotation>();
13+
14+
let annotationsList =
15+
window.NutrientViewer.Immutable.List<RedactionAnnotation>();
16+
17+
for (let i = 0; i < instance.totalPageCount; i++) {
18+
const anns = (await instance.getAnnotations(i)).filter(
19+
(a): a is RedactionAnnotation =>
20+
a instanceof window.NutrientViewer.Annotations.RedactionAnnotation,
21+
);
22+
annotationsList = annotationsList.concat(anns);
23+
}
24+
return annotationsList;
25+
};
26+
27+
const redactionAnnotationsHandlerCallback: AnnotationTooltipCallback = (
28+
annotation,
29+
) =>
30+
annotation instanceof window.NutrientViewer.Annotations.RedactionAnnotation
31+
? [
32+
{
33+
type: "custom",
34+
title: "Accept",
35+
id: "tooltip-accept-annotation",
36+
className: "TooltipItem-Duplication",
37+
onPress: async () => {
38+
if (!instance) return;
39+
40+
const allRedactionAnnotations = (await getAllAnnotations()).filter(
41+
(a) => a.id !== annotation.id,
42+
);
43+
44+
await instance.delete(allRedactionAnnotations);
45+
await instance.applyRedactions();
46+
await instance.create(allRedactionAnnotations);
47+
},
48+
},
49+
{
50+
type: "custom",
51+
title: "Reject",
52+
id: "tooltip-reject-annotation",
53+
className: "TooltipItem-Duplication",
54+
onPress: async () => {
55+
if (!instance) return;
56+
instance.delete(annotation);
57+
},
58+
},
59+
]
60+
: [];
61+
62+
window.NutrientViewer.load({
63+
...baseOptions,
64+
theme: window.NutrientViewer.Theme.DARK,
65+
enableAutomaticLinkExtraction: true,
66+
annotationTooltipCallback: redactionAnnotationsHandlerCallback,
67+
toolbarItems: [
68+
...window.NutrientViewer.defaultToolbarItems,
69+
{ type: "redact-rectangle" },
70+
{ type: "redact-text-highlighter" },
71+
],
72+
}).then((_instance) => {
73+
instance = _instance;
74+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
category: redaction
3+
title: Apply or Reject Redactions via Tooltip
4+
description: Adds custom tooltip options to accept or reject individual redaction annotations, allowing selective redaction of document content.
5+
keywords: [redaction, tooltip, accept, reject, annotations, custom-tooltip]
6+
---
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* Add your CSS here */
2+
.custom-toolbar-item {
3+
height: 100%;
4+
}

0 commit comments

Comments
 (0)