@embedpdf/plugin-annotation 2.1.1 → 2.2.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.
@@ -1,4 +1,4 @@
1
- import { usePlugin, useCapability, useDocumentState } from "@embedpdf/core/preact";
1
+ import { usePlugin, useCapability, useDocumentPermissions, useDocumentState } from "@embedpdf/core/preact";
2
2
  import { AnnotationPlugin, initialDocumentState, patching, getAnnotationsByPageIndex, getSelectedAnnotationByPageIndex, isInk, isSquare, isCircle, isUnderline, isStrikeout, isSquiggly, isHighlight, isLine, isPolyline, isPolygon, isFreeText, isStamp } from "@embedpdf/plugin-annotation";
3
3
  export * from "@embedpdf/plugin-annotation";
4
4
  import { Fragment as Fragment$1 } from "preact";
@@ -58,7 +58,10 @@ function AnnotationContainer({
58
58
  }) {
59
59
  const [preview, setPreview] = useState(trackedAnnotation.object);
60
60
  const { provides: annotationCapability } = useAnnotationCapability();
61
+ const { canModifyAnnotations } = useDocumentPermissions(documentId);
61
62
  const gestureBaseRef = useRef(null);
63
+ const effectiveIsDraggable = canModifyAnnotations && isDraggable;
64
+ const effectiveIsResizable = canModifyAnnotations && isResizable;
62
65
  const annotationProvides = useMemo(
63
66
  () => annotationCapability ? annotationCapability.forDocument(documentId) : null,
64
67
  [annotationCapability, documentId]
@@ -120,7 +123,11 @@ function AnnotationContainer({
120
123
  },
121
124
  includeVertices: vertexConfig ? true : false
122
125
  });
123
- const doubleProps = useDoublePressProps(onDoubleClick);
126
+ const guardedOnDoubleClick = useMemo(() => {
127
+ if (!canModifyAnnotations || !onDoubleClick) return void 0;
128
+ return onDoubleClick;
129
+ }, [canModifyAnnotations, onDoubleClick]);
130
+ const doubleProps = useDoublePressProps(guardedOnDoubleClick);
124
131
  useEffect(() => {
125
132
  setPreview(trackedAnnotation.object);
126
133
  }, [trackedAnnotation.object]);
@@ -128,7 +135,7 @@ function AnnotationContainer({
128
135
  /* @__PURE__ */ jsxs(
129
136
  "div",
130
137
  {
131
- ...isDraggable && isSelected ? dragProps : {},
138
+ ...effectiveIsDraggable && isSelected ? dragProps : {},
132
139
  ...doubleProps,
133
140
  style: {
134
141
  position: "absolute",
@@ -140,7 +147,7 @@ function AnnotationContainer({
140
147
  outlineOffset: isSelected ? `${outlineOffset}px` : "0px",
141
148
  pointerEvents: isSelected ? "auto" : "none",
142
149
  touchAction: "none",
143
- cursor: isSelected && isDraggable ? "move" : "default",
150
+ cursor: isSelected && effectiveIsDraggable ? "move" : "default",
144
151
  zIndex,
145
152
  ...style
146
153
  },
@@ -164,7 +171,7 @@ function AnnotationContainer({
164
171
  }
165
172
  return childrenRender;
166
173
  })(),
167
- isSelected && isResizable && resize.map(
174
+ isSelected && effectiveIsResizable && resize.map(
168
175
  ({ key, ...hProps }) => (resizeUI == null ? void 0 : resizeUI.component) ? resizeUI.component({
169
176
  key,
170
177
  ...hProps,
@@ -178,7 +185,7 @@ function AnnotationContainer({
178
185
  key
179
186
  )
180
187
  ),
181
- isSelected && vertices.map(
188
+ isSelected && canModifyAnnotations && vertices.map(
182
189
  ({ key, ...vProps }) => (vertexUI == null ? void 0 : vertexUI.component) ? vertexUI.component({
183
190
  key,
184
191
  ...vProps,