canvu-react 0.4.13 → 0.4.15

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.
package/dist/react.js CHANGED
@@ -8043,6 +8043,7 @@ var VectorViewport = forwardRef(
8043
8043
  const wrapperRef = useRef(null);
8044
8044
  const interactionRootRef = useRef(null);
8045
8045
  const sceneContainerRef = useRef(null);
8046
+ const lastPointerScreenRef = useRef(null);
8046
8047
  const activeInteractionPointerIdRef = useRef(null);
8047
8048
  const activeInteractionPointerTargetRef = useRef(null);
8048
8049
  const activeInteractionTouchIdRef = useRef(null);
@@ -8769,6 +8770,24 @@ var VectorViewport = forwardRef(
8769
8770
  root.removeEventListener("pointerleave", leave);
8770
8771
  };
8771
8772
  }, [onWorldPointerMove]);
8773
+ useEffect(() => {
8774
+ const root = wrapperRef.current;
8775
+ if (!root) return;
8776
+ const record = (e) => {
8777
+ lastPointerScreenRef.current = { x: e.clientX, y: e.clientY };
8778
+ };
8779
+ const clear = () => {
8780
+ lastPointerScreenRef.current = null;
8781
+ };
8782
+ root.addEventListener("pointermove", record, { passive: true });
8783
+ root.addEventListener("pointerdown", record, { passive: true });
8784
+ root.addEventListener("pointerleave", clear);
8785
+ return () => {
8786
+ root.removeEventListener("pointermove", record);
8787
+ root.removeEventListener("pointerdown", record);
8788
+ root.removeEventListener("pointerleave", clear);
8789
+ };
8790
+ }, []);
8772
8791
  useEffect(() => {
8773
8792
  if (directRemoteStrokePreviewRef.current && placementPreview === null) {
8774
8793
  return;
@@ -9488,6 +9507,50 @@ var VectorViewport = forwardRef(
9488
9507
  },
9489
9508
  [screenToWorld, placeImageFilesAtWorld]
9490
9509
  );
9510
+ const handleWrapperPaste = useCallback(
9511
+ async (e) => {
9512
+ if (!interactiveRef.current || !onItemsChangeRef.current) return;
9513
+ const t = e.target;
9514
+ if (t instanceof HTMLTextAreaElement || t instanceof HTMLInputElement || t instanceof HTMLElement && t.isContentEditable) {
9515
+ return;
9516
+ }
9517
+ if (editingTextIdRef.current) return;
9518
+ const dt = e.clipboardData;
9519
+ if (!dt) return;
9520
+ const files = [];
9521
+ for (const file of Array.from(dt.files)) {
9522
+ if (file.type.startsWith("image/")) files.push(file);
9523
+ }
9524
+ if (files.length === 0) {
9525
+ for (const item of Array.from(dt.items)) {
9526
+ if (item.kind === "file" && item.type.startsWith("image/")) {
9527
+ const file = item.getAsFile();
9528
+ if (file) files.push(file);
9529
+ }
9530
+ }
9531
+ }
9532
+ if (files.length === 0) return;
9533
+ e.preventDefault();
9534
+ const last = lastPointerScreenRef.current;
9535
+ let target;
9536
+ if (last) {
9537
+ target = screenToWorld(last.x, last.y);
9538
+ } else {
9539
+ const el = sceneContainerRef.current;
9540
+ const cam = cameraRef.current;
9541
+ if (el && cam) {
9542
+ const rect = el.getBoundingClientRect();
9543
+ target = cam.screenToWorld(rect.width / 2, rect.height / 2);
9544
+ } else {
9545
+ target = { worldX: 0, worldY: 0 };
9546
+ }
9547
+ }
9548
+ await placeImageFilesAtWorld(files, target.worldX, target.worldY, {
9549
+ stackBelowExistingItems: false
9550
+ });
9551
+ },
9552
+ [screenToWorld, placeImageFilesAtWorld]
9553
+ );
9491
9554
  const handleOverlayDoubleClick = useCallback(
9492
9555
  (e) => {
9493
9556
  const cam = cameraRef.current;
@@ -10757,6 +10820,7 @@ var VectorViewport = forwardRef(
10757
10820
  "aria-label": ariaLabel,
10758
10821
  "aria-describedby": liveId,
10759
10822
  onKeyDown,
10823
+ onPaste: handleWrapperPaste,
10760
10824
  onDragOver: handleWrapperDragOver,
10761
10825
  onDrop: handleWrapperDrop,
10762
10826
  children: [