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