@cocorof/graphier 1.4.1 → 1.4.3

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/index.d.ts CHANGED
@@ -174,6 +174,19 @@ export declare type LinkEventHandler = (link: GraphLink) => void;
174
174
 
175
175
  export declare const minimal: ThemeConfig;
176
176
 
177
+ export declare interface NavigationConfig {
178
+ /** What left-drag does (default: "rotate" in 3D, "pan" in 2D) */
179
+ leftButton?: "rotate" | "pan";
180
+ /** What right-drag does (default: "pan" in 3D, "rotate" in 2D) */
181
+ rightButton?: "rotate" | "pan";
182
+ /**
183
+ * Keyboard scheme — "pan": arrows/WASD pan + z/x zoom; "fly": thrust
184
+ * flight; "orbit": orbit around target; "off": disabled.
185
+ * (default: cameraMode in 3D, "pan" in 2D)
186
+ */
187
+ keyboard?: "fly" | "orbit" | "pan" | "off";
188
+ }
189
+
177
190
  export declare const neon: ThemeConfig;
178
191
 
179
192
  export declare const NetworkGraph3D: ForwardRefExoticComponent<NetworkGraph3DProps & RefAttributes<NetworkGraph3DRef>>;
@@ -341,6 +354,12 @@ export declare interface RendererConfig {
341
354
  * - "orbit": z/x zoom, arrow keys orbit around target
342
355
  */
343
356
  cameraMode?: "fly" | "orbit";
357
+ /**
358
+ * Pointer/keyboard navigation overrides. Defaults depend on layout
359
+ * dimensionality — 3D: left=rotate, right=pan, keyboard=cameraMode;
360
+ * 2D: left=pan, right=rotate, keyboard="pan".
361
+ */
362
+ navigation?: NavigationConfig;
344
363
  }
345
364
 
346
365
  export declare interface ResolvedTheme {
package/dist/index.js CHANGED
@@ -2213,6 +2213,14 @@ function createScene(container, backgroundColor, style, rendererConfig) {
2213
2213
  renderer.toneMappingExposure = 1.2;
2214
2214
  const canvas = renderer.domElement;
2215
2215
  canvas.style.setProperty("display", "block", "important");
2216
+ canvas.draggable = false;
2217
+ canvas.style.userSelect = "none";
2218
+ canvas.style.setProperty("-webkit-user-drag", "none");
2219
+ canvas.style.touchAction = "none";
2220
+ const onDragStart = (e) => e.preventDefault();
2221
+ canvas.addEventListener("dragstart", onDragStart);
2222
+ const onSelectStart = (e) => e.preventDefault();
2223
+ canvas.addEventListener("selectstart", onSelectStart);
2216
2224
  container.appendChild(canvas);
2217
2225
  const controls = new OrbitControls(camera, canvas);
2218
2226
  controls.enableDamping = true;
@@ -2250,7 +2258,11 @@ function createScene(container, backgroundColor, style, rendererConfig) {
2250
2258
  controls.target.addScaledVector(_wheelDir, moveAmount);
2251
2259
  };
2252
2260
  canvas.addEventListener("wheel", onWheel, { passive: false });
2253
- const scrollCleanup = () => canvas.removeEventListener("wheel", onWheel);
2261
+ const scrollCleanup = () => {
2262
+ canvas.removeEventListener("wheel", onWheel);
2263
+ canvas.removeEventListener("dragstart", onDragStart);
2264
+ canvas.removeEventListener("selectstart", onSelectStart);
2265
+ };
2254
2266
  return {
2255
2267
  scene,
2256
2268
  camera,
@@ -2266,34 +2278,38 @@ function createScene(container, backgroundColor, style, rendererConfig) {
2266
2278
  flags
2267
2279
  };
2268
2280
  }
2269
- function applyCameraMode2D(state, is2D) {
2281
+ const MOUSE_ACTION = {
2282
+ rotate: THREE.MOUSE.ROTATE,
2283
+ pan: THREE.MOUSE.PAN
2284
+ };
2285
+ function applyNavigationMode(state, is2D, nav) {
2270
2286
  const { controls, camera, keyboard } = state;
2271
2287
  state.flags.is2D = is2D;
2272
- controls.enableRotate = true;
2288
+ const left = (nav == null ? void 0 : nav.leftButton) ?? (is2D ? "pan" : "rotate");
2289
+ const right = (nav == null ? void 0 : nav.rightButton) ?? (is2D ? "rotate" : "pan");
2290
+ controls.mouseButtons = {
2291
+ LEFT: MOUSE_ACTION[left],
2292
+ MIDDLE: THREE.MOUSE.DOLLY,
2293
+ RIGHT: MOUSE_ACTION[right]
2294
+ };
2295
+ controls.enableRotate = left === "rotate" || right === "rotate";
2296
+ controls.touches = left === "pan" ? { ONE: THREE.TOUCH.PAN, TWO: THREE.TOUCH.DOLLY_PAN } : { ONE: THREE.TOUCH.ROTATE, TWO: THREE.TOUCH.DOLLY_PAN };
2273
2297
  controls.enableZoom = is2D;
2274
2298
  controls.screenSpacePanning = is2D;
2275
- keyboard.setEnabled(true);
2276
- keyboard.setMode(is2D ? "pan" : state.flags.keyboardMode3D);
2299
+ const kb = (nav == null ? void 0 : nav.keyboard) ?? (is2D ? "pan" : state.flags.keyboardMode3D);
2300
+ if (kb === "off") {
2301
+ keyboard.setEnabled(false);
2302
+ } else {
2303
+ keyboard.setEnabled(true);
2304
+ keyboard.setMode(kb);
2305
+ }
2277
2306
  if (is2D) {
2278
- controls.mouseButtons = {
2279
- LEFT: THREE.MOUSE.PAN,
2280
- MIDDLE: THREE.MOUSE.DOLLY,
2281
- RIGHT: THREE.MOUSE.ROTATE
2282
- };
2283
- controls.touches = { ONE: THREE.TOUCH.PAN, TWO: THREE.TOUCH.DOLLY_PAN };
2284
2307
  const t = controls.target;
2285
2308
  const dist = Math.max(camera.position.distanceTo(t), 50);
2286
2309
  t.z = 0;
2287
2310
  camera.up.set(0, 1, 0);
2288
2311
  camera.position.set(t.x, t.y, dist);
2289
2312
  camera.lookAt(t);
2290
- } else {
2291
- controls.mouseButtons = {
2292
- LEFT: THREE.MOUSE.ROTATE,
2293
- MIDDLE: THREE.MOUSE.DOLLY,
2294
- RIGHT: THREE.MOUSE.PAN
2295
- };
2296
- controls.touches = { ONE: THREE.TOUCH.ROTATE, TWO: THREE.TOUCH.DOLLY_PAN };
2297
2313
  }
2298
2314
  controls.update();
2299
2315
  }
@@ -3500,10 +3516,11 @@ function NetworkGraph3DInner(props, ref) {
3500
3516
  );
3501
3517
  }
3502
3518
  }, [visibleSet, linkVisibility, mergedData]);
3519
+ const navKey = JSON.stringify((rendererProp == null ? void 0 : rendererProp.navigation) ?? null);
3503
3520
  useEffect(() => {
3504
3521
  const s = sceneRef.current;
3505
- if (s) applyCameraMode2D(s, is2D);
3506
- }, [is2D]);
3522
+ if (s) applyNavigationMode(s, is2D, rendererProp == null ? void 0 : rendererProp.navigation);
3523
+ }, [is2D, navKey]);
3507
3524
  useEffect(() => {
3508
3525
  const gObj = graphObjRef.current;
3509
3526
  const sceneState = sceneRef.current;
@@ -3755,11 +3772,12 @@ function NetworkGraph3DInner(props, ref) {
3755
3772
  const s = sceneRef.current;
3756
3773
  if (!s) return null;
3757
3774
  const cam = s.camera;
3758
- const dist = Math.abs(cam.position.z);
3775
+ const t = s.controls.target;
3776
+ const dist = Math.max(cam.position.distanceTo(t), 1);
3759
3777
  const halfH = Math.tan(cam.fov * Math.PI / 360) * dist;
3760
3778
  return {
3761
- cx: cam.position.x,
3762
- cy: cam.position.y,
3779
+ cx: t.x,
3780
+ cy: t.y,
3763
3781
  halfW: halfH * cam.aspect,
3764
3782
  halfH
3765
3783
  };
@@ -3780,7 +3798,14 @@ function NetworkGraph3DInner(props, ref) {
3780
3798
  {
3781
3799
  ref: containerRef,
3782
3800
  tabIndex: -1,
3783
- style: { width: "100%", height: "100%", outline: "none" }
3801
+ style: {
3802
+ width: "100%",
3803
+ height: "100%",
3804
+ outline: "none",
3805
+ userSelect: "none",
3806
+ WebkitUserSelect: "none"
3807
+ },
3808
+ onDragStart: (e) => e.preventDefault()
3784
3809
  }
3785
3810
  );
3786
3811
  }