@embedpdf/plugin-annotation 2.9.0 → 2.9.1

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.
@@ -404,7 +404,7 @@ function AnnotationContainer({
404
404
  ...blendMode && { mixBlendMode: blendMode },
405
405
  ...style
406
406
  },
407
- children: /* @__PURE__ */ jsxs("div", { style: { ...innerDivBaseStyle, pointerEvents: "none" }, children: [
407
+ children: /* @__PURE__ */ jsxs("div", { style: { ...innerDivBaseStyle, pointerEvents: isEditing ? "auto" : "none" }, children: [
408
408
  (() => {
409
409
  const childrenRender = typeof children === "function" ? children(childObject, { appearanceActive: apActive }) : children;
410
410
  const customRender = customAnnotationRenderer == null ? void 0 : customAnnotationRenderer({
@@ -579,7 +579,7 @@ function AnnotationContainer({
579
579
  ...innerDivBaseStyle,
580
580
  outline: showOutline ? `${outlineWidth}px ${outlineStyle} ${outlineColor}` : "none",
581
581
  outlineOffset: showOutline ? `${outlineOff}px` : "0px",
582
- pointerEvents: isSelected && !isMultiSelected ? "auto" : "none",
582
+ pointerEvents: isSelected && !isMultiSelected && !isEditing ? "auto" : "none",
583
583
  touchAction: "none",
584
584
  cursor: isSelected && effectiveIsDraggable ? "move" : "default"
585
585
  },
@@ -2080,15 +2080,20 @@ function FreeText({
2080
2080
  const annotationProvides = (annotationCapability == null ? void 0 : annotationCapability.forDocument(documentId)) ?? null;
2081
2081
  const [isIOS, setIsIOS] = useState(false);
2082
2082
  useEffect(() => {
2083
+ var _a;
2083
2084
  if (isEditing && editorRef.current) {
2084
2085
  editingRef.current = true;
2085
2086
  const editor = editorRef.current;
2086
2087
  editor.focus();
2088
+ const tool = annotationProvides == null ? void 0 : annotationProvides.findToolForAnnotation(annotation.object);
2089
+ const isDefaultContent = ((_a = tool == null ? void 0 : tool.defaults) == null ? void 0 : _a.contents) != null && annotation.object.contents === tool.defaults.contents;
2087
2090
  const selection = window.getSelection();
2088
2091
  if (selection) {
2089
2092
  const range = document.createRange();
2090
2093
  range.selectNodeContents(editor);
2091
- range.collapse(false);
2094
+ if (!isDefaultContent) {
2095
+ range.collapse(false);
2096
+ }
2092
2097
  selection.removeAllRanges();
2093
2098
  selection.addRange(range);
2094
2099
  }
@@ -2109,7 +2114,7 @@ function FreeText({
2109
2114
  if (!annotationProvides) return;
2110
2115
  if (!editorRef.current) return;
2111
2116
  annotationProvides.updateAnnotation(pageIndex, annotation.object.id, {
2112
- contents: editorRef.current.innerText
2117
+ contents: editorRef.current.innerText.replace(/\u00A0/g, " ")
2113
2118
  });
2114
2119
  };
2115
2120
  const computedFontPx = annotation.object.fontSize * scale;
@@ -2930,6 +2935,14 @@ function Annotations(annotationsProps) {
2930
2935
  });
2931
2936
  }
2932
2937
  }, [annotationProvides, pageIndex]);
2938
+ useEffect(() => {
2939
+ if (!annotationProvides) return;
2940
+ return annotationProvides.onAnnotationEvent((event) => {
2941
+ if (event.type === "create" && event.editAfterCreate) {
2942
+ setEditingId(event.annotation.id);
2943
+ }
2944
+ });
2945
+ }, [annotationProvides]);
2933
2946
  useEffect(() => {
2934
2947
  if (!annotationProvides) return;
2935
2948
  if (prevScaleRef.current !== scale) {
@@ -2949,12 +2962,15 @@ function Annotations(annotationsProps) {
2949
2962
  () => ({
2950
2963
  onPointerDown: (_, pe) => {
2951
2964
  if (pe.target === pe.currentTarget && annotationProvides) {
2965
+ if (editingId && annotations.some((a) => a.object.id === editingId)) {
2966
+ pe.stopImmediatePropagation();
2967
+ }
2952
2968
  annotationProvides.deselectAnnotation();
2953
2969
  setEditingId(null);
2954
2970
  }
2955
2971
  }
2956
2972
  }),
2957
- [annotationProvides]
2973
+ [annotationProvides, editingId, annotations]
2958
2974
  );
2959
2975
  const handleClick = useCallback(
2960
2976
  (e, annotation) => {