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.cjs CHANGED
@@ -8050,6 +8050,7 @@ var VectorViewport = react.forwardRef(
8050
8050
  const wrapperRef = react.useRef(null);
8051
8051
  const interactionRootRef = react.useRef(null);
8052
8052
  const sceneContainerRef = react.useRef(null);
8053
+ const lastPointerScreenRef = react.useRef(null);
8053
8054
  const activeInteractionPointerIdRef = react.useRef(null);
8054
8055
  const activeInteractionPointerTargetRef = react.useRef(null);
8055
8056
  const activeInteractionTouchIdRef = react.useRef(null);
@@ -8776,6 +8777,24 @@ var VectorViewport = react.forwardRef(
8776
8777
  root.removeEventListener("pointerleave", leave);
8777
8778
  };
8778
8779
  }, [onWorldPointerMove]);
8780
+ react.useEffect(() => {
8781
+ const root = wrapperRef.current;
8782
+ if (!root) return;
8783
+ const record = (e) => {
8784
+ lastPointerScreenRef.current = { x: e.clientX, y: e.clientY };
8785
+ };
8786
+ const clear = () => {
8787
+ lastPointerScreenRef.current = null;
8788
+ };
8789
+ root.addEventListener("pointermove", record, { passive: true });
8790
+ root.addEventListener("pointerdown", record, { passive: true });
8791
+ root.addEventListener("pointerleave", clear);
8792
+ return () => {
8793
+ root.removeEventListener("pointermove", record);
8794
+ root.removeEventListener("pointerdown", record);
8795
+ root.removeEventListener("pointerleave", clear);
8796
+ };
8797
+ }, []);
8779
8798
  react.useEffect(() => {
8780
8799
  if (directRemoteStrokePreviewRef.current && placementPreview === null) {
8781
8800
  return;
@@ -9495,6 +9514,50 @@ var VectorViewport = react.forwardRef(
9495
9514
  },
9496
9515
  [screenToWorld, placeImageFilesAtWorld]
9497
9516
  );
9517
+ const handleWrapperPaste = react.useCallback(
9518
+ async (e) => {
9519
+ if (!interactiveRef.current || !onItemsChangeRef.current) return;
9520
+ const t = e.target;
9521
+ if (t instanceof HTMLTextAreaElement || t instanceof HTMLInputElement || t instanceof HTMLElement && t.isContentEditable) {
9522
+ return;
9523
+ }
9524
+ if (editingTextIdRef.current) return;
9525
+ const dt = e.clipboardData;
9526
+ if (!dt) return;
9527
+ const files = [];
9528
+ for (const file of Array.from(dt.files)) {
9529
+ if (file.type.startsWith("image/")) files.push(file);
9530
+ }
9531
+ if (files.length === 0) {
9532
+ for (const item of Array.from(dt.items)) {
9533
+ if (item.kind === "file" && item.type.startsWith("image/")) {
9534
+ const file = item.getAsFile();
9535
+ if (file) files.push(file);
9536
+ }
9537
+ }
9538
+ }
9539
+ if (files.length === 0) return;
9540
+ e.preventDefault();
9541
+ const last = lastPointerScreenRef.current;
9542
+ let target;
9543
+ if (last) {
9544
+ target = screenToWorld(last.x, last.y);
9545
+ } else {
9546
+ const el = sceneContainerRef.current;
9547
+ const cam = cameraRef.current;
9548
+ if (el && cam) {
9549
+ const rect = el.getBoundingClientRect();
9550
+ target = cam.screenToWorld(rect.width / 2, rect.height / 2);
9551
+ } else {
9552
+ target = { worldX: 0, worldY: 0 };
9553
+ }
9554
+ }
9555
+ await placeImageFilesAtWorld(files, target.worldX, target.worldY, {
9556
+ stackBelowExistingItems: false
9557
+ });
9558
+ },
9559
+ [screenToWorld, placeImageFilesAtWorld]
9560
+ );
9498
9561
  const handleOverlayDoubleClick = react.useCallback(
9499
9562
  (e) => {
9500
9563
  const cam = cameraRef.current;
@@ -10764,6 +10827,7 @@ var VectorViewport = react.forwardRef(
10764
10827
  "aria-label": ariaLabel,
10765
10828
  "aria-describedby": liveId,
10766
10829
  onKeyDown,
10830
+ onPaste: handleWrapperPaste,
10767
10831
  onDragOver: handleWrapperDragOver,
10768
10832
  onDrop: handleWrapperDrop,
10769
10833
  children: [