canvu-react 0.3.38 → 0.3.39

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
@@ -6463,6 +6463,18 @@ var SvgVectorRenderer = class {
6463
6463
  }
6464
6464
  };
6465
6465
 
6466
+ // src/scene/link-item.ts
6467
+ var LINK_PLUGIN_KEY = "canvuLink";
6468
+ var isCanvuLinkData = (value) => {
6469
+ if (!value || typeof value !== "object") return false;
6470
+ const candidate = value;
6471
+ return typeof candidate.href === "string" && candidate.href.length > 0;
6472
+ };
6473
+ function getLinkData(item) {
6474
+ const entry = item.pluginData?.[LINK_PLUGIN_KEY];
6475
+ return isCanvuLinkData(entry) ? entry : null;
6476
+ }
6477
+
6466
6478
  // src/scene/scene.ts
6467
6479
  var VectorScene = class {
6468
6480
  items = [];
@@ -7639,6 +7651,7 @@ var VectorViewport = react.forwardRef(
7639
7651
  selectedIds: selectedIdsProp,
7640
7652
  onSelectionChange,
7641
7653
  onItemsChange: consumerOnItemsChange,
7654
+ onActivateLink,
7642
7655
  onWorldPointerDown: consumerOnWorldPointerDown,
7643
7656
  toolbar,
7644
7657
  navMenu,
@@ -7819,6 +7832,8 @@ var VectorViewport = react.forwardRef(
7819
7832
  const itemsRef = react.useRef(items);
7820
7833
  const onWorldPointerDownRef = react.useRef(onWorldPointerDown);
7821
7834
  const onItemsChangeRef = react.useRef(onItemsChange);
7835
+ const onActivateLinkRef = react.useRef(onActivateLink);
7836
+ onActivateLinkRef.current = onActivateLink;
7822
7837
  const assetStoreRef = react.useRef(assetStore);
7823
7838
  assetStoreRef.current = assetStore;
7824
7839
  const customPlacementRef = react.useRef(customPlacement);
@@ -9094,13 +9109,27 @@ var VectorViewport = react.forwardRef(
9094
9109
  );
9095
9110
  const handleOverlayDoubleClick = react.useCallback(
9096
9111
  (e) => {
9097
- if (!interactiveRef.current || !onItemsChangeRef.current) return;
9098
- if (toolIdRef.current !== "select") return;
9099
- e.preventDefault();
9100
9112
  const cam = cameraRef.current;
9101
9113
  if (!cam) return;
9102
9114
  const { worldX, worldY } = screenToWorld(e.clientX, e.clientY);
9103
9115
  const lineHitWorld = 10 / cam.zoom;
9116
+ const linkHit = hitTestWorldPoint(resolvedItemsRef.current, worldX, worldY, {
9117
+ lineHitWorld,
9118
+ ignoreLocked: false
9119
+ });
9120
+ const link = linkHit ? getLinkData(linkHit) : null;
9121
+ if (linkHit && link) {
9122
+ e.preventDefault();
9123
+ if (onActivateLinkRef.current) {
9124
+ onActivateLinkRef.current({ link, item: linkHit });
9125
+ } else if (typeof window !== "undefined" && typeof window.open === "function") {
9126
+ window.open(link.href, "_blank", "noopener,noreferrer");
9127
+ }
9128
+ return;
9129
+ }
9130
+ if (!interactiveRef.current || !onItemsChangeRef.current) return;
9131
+ if (toolIdRef.current !== "select") return;
9132
+ e.preventDefault();
9104
9133
  const hit = hitTestWorldPoint(resolvedItemsRef.current, worldX, worldY, {
9105
9134
  lineHitWorld,
9106
9135
  ignoreLocked: true