@react-three/drei 9.38.1 → 9.39.0

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/README.md CHANGED
@@ -392,13 +392,14 @@ function Foo(props) {
392
392
  // Will move between 0-1-0 for the selected range
393
393
  const d = data.curve(1 / 3, 1 / 3)
394
394
  // Same as above, but with a margin of 0.1 on both ends
395
- const d = data.curve(1 / 3, 1 / 3, 0.1)
395
+ const e = data.curve(1 / 3, 1 / 3, 0.1)
396
396
  // Returns true if the offset is in range and false if it isn't
397
- const e = data.visible(2 / 3, 1 / 3)
397
+ const f = data.visible(2 / 3, 1 / 3)
398
398
  // The visible function can also receive a margin
399
- const f = data.visible(2 / 3, 1 / 3, 0.1)
399
+ const g = data.visible(2 / 3, 1 / 3, 0.1)
400
400
  })
401
401
  return <mesh ref={ref} {...props} />
402
+ }
402
403
  ```
403
404
 
404
405
  #### PresentationControls
@@ -436,11 +437,11 @@ Semi-OrbitControls with spring-physics, polar zoom and snap-back, for presentati
436
437
  A rudimentary keyboard controller which distributes your defined data-model to the `useKeyboard` hook. It's a rather simple way to get started with keyboard input.
437
438
 
438
439
  ```tsx
439
- type KeyboardControlsState = { [key: string]: boolean }
440
+ type KeyboardControlsState<T extends string = string> = { [K in T]: boolean }
440
441
 
441
- type KeyboardControlsEntry = {
442
+ type KeyboardControlsEntry<T extends string = string> = {
442
443
  /** Name of the action */
443
- name: string
444
+ name: T
444
445
  /** The keys that define it, you can use either event.key, or event.code */
445
446
  keys: string[]
446
447
  /** If the event receives the keyup event, true by default */
@@ -461,33 +462,40 @@ type KeyboardControlsProps = {
461
462
 
462
463
  You start by wrapping your app, or scene, into `<KeyboardControls>`.
463
464
 
464
- ```jsx
465
+ ```tsx
466
+ enum Controls {
467
+ forward = 'forward',
468
+ back = 'back',
469
+ left = 'left',
470
+ right = 'right',
471
+ jump = 'jump',
472
+ }
465
473
  function App() {
474
+ const map = useMemo<KeyboardControlsEntry<Controls>>(()=>[
475
+ { name: Controls.forward, keys: ['ArrowUp', 'w', 'W'] },
476
+ { name: Controls.back, keys: ['ArrowDown', 's', 'S'] },
477
+ { name: Controls.left, keys: ['ArrowLeft', 'a', 'A'] },
478
+ { name: Controls.right, keys: ['ArrowRight', 'd', 'D'] },
479
+ { name: Controls.jump, keys: ['Space'] },
480
+ ], [])
466
481
  return (
467
- <KeyboardControls
468
- map={[
469
- { name: 'forward', keys: ['ArrowUp', 'w', 'W'] },
470
- { name: 'backward', keys: ['ArrowDown', 's', 'S'] },
471
- { name: 'leftward', keys: ['ArrowLeft', 'a', 'A'] },
472
- { name: 'rightward', keys: ['ArrowRight', 'd', 'D'] },
473
- { name: 'jump', keys: ['Space'] },
474
- ]}>
482
+ <KeyboardControls map={map}>
475
483
  <App />
476
484
  </KeyboardControls>
477
485
  ```
478
486
 
479
487
  You can either respond to input reactively, it uses zustand (with the `subscribeWithSelector` middleware) so all the rules apply:
480
488
 
481
- ```jsx
489
+ ```tsx
482
490
  function Foo() {
483
- const pressed = useKeyboardControls(state => forward)
491
+ const forwardPressed = useKeyboardControls<Controls>(state => state.forward)
484
492
  ```
485
493
 
486
494
  Or transiently, either by `subscribe`, which is a function which returns a function to unsubscribe, so you can pair it with useEffect for cleanup, or `get`, which fetches fresh state non-reactively.
487
495
 
488
- ```jsx
496
+ ```tsx
489
497
  function Foo() {
490
- const [sub, get] = useKeyboardControls()
498
+ const [sub, get] = useKeyboardControls<Controls>()
491
499
 
492
500
  useEffect(() => {
493
501
  return sub(
@@ -500,7 +508,7 @@ function Foo() {
500
508
 
501
509
  useFrame(() => {
502
510
  // Fetch fresh data from store
503
- const pressed = get().backward
511
+ const pressed = get().back
504
512
  })
505
513
  }
506
514
  ```
@@ -2398,7 +2406,7 @@ Now refer to it with the `useMask` hook and the same id, your content will now b
2398
2406
  const stencil = useMask(1)
2399
2407
  return (
2400
2408
  <mesh>
2401
- <torusKnotGeoometry />
2409
+ <torusKnotGeometry />
2402
2410
  <meshStandardMaterial {...stencil} />
2403
2411
  ```
2404
2412
 
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { Line2 } from 'three/examples/jsm/lines/Line2';
2
+ import { Line2 } from 'three-stdlib';
3
3
  import { LineProps } from './Line';
4
4
  export declare const CatmullRomLine: React.ForwardRefExoticComponent<Omit<LineProps, "ref"> & {
5
5
  closed?: boolean | undefined;
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { Vector3 } from 'three';
3
- import { Line2 } from 'three/examples/jsm/lines/Line2';
3
+ import { Line2 } from 'three-stdlib';
4
4
  import { LineProps } from './Line';
5
5
  export declare const CubicBezierLine: React.ForwardRefExoticComponent<Omit<LineProps, "ref" | "points"> & {
6
6
  start: Vector3 | [number, number, number];
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { Vector3 } from 'three';
3
- import { Line2 } from 'three/examples/jsm/lines/Line2';
3
+ import { Line2 } from 'three-stdlib';
4
4
  import { LineProps } from './Line';
5
5
  import { Object3DNode } from '@react-three/fiber';
6
6
  declare type Line2Props = Object3DNode<Line2, typeof Line2> & {
@@ -7,11 +7,11 @@ export declare type TransformControlsProps = ReactThreeFiber.Object3DNode<Transf
7
7
  enabled?: boolean;
8
8
  axis?: string | null;
9
9
  domElement?: HTMLElement;
10
- mode?: string;
10
+ mode?: 'translate' | 'rotate' | 'scale';
11
11
  translationSnap?: number | null;
12
12
  rotationSnap?: number | null;
13
13
  scaleSnap?: number | null;
14
- space?: string;
14
+ space?: 'world' | 'local';
15
15
  size?: number;
16
16
  showX?: boolean;
17
17
  showY?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/drei",
3
- "version": "9.38.1",
3
+ "version": "9.39.0",
4
4
  "private": false,
5
5
  "description": "useful add-ons for react-three-fiber",
6
6
  "keywords": [
@@ -1,10 +1,10 @@
1
1
  import * as React from 'react';
2
- import { StateSelector } from 'zustand';
3
- declare type KeyboardControlsState = {
4
- [key: string]: boolean;
2
+ import { GetState, StateSelector, Subscribe } from 'zustand';
3
+ declare type KeyboardControlsState<T extends string = string> = {
4
+ [K in T]: boolean;
5
5
  };
6
- declare type KeyboardControlsEntry = {
7
- name: string;
6
+ export declare type KeyboardControlsEntry<T extends string = string> = {
7
+ name: T;
8
8
  keys: string[];
9
9
  up?: boolean;
10
10
  };
@@ -15,5 +15,9 @@ declare type KeyboardControlsProps = {
15
15
  domElement?: HTMLElement;
16
16
  };
17
17
  export declare function KeyboardControls({ map, children, onChange, domElement }: KeyboardControlsProps): JSX.Element;
18
- export declare function useKeyboardControls(sel?: StateSelector<KeyboardControlsState, any>): any;
18
+ export declare function useKeyboardControls<T extends string = string, U = any>(): [
19
+ Subscribe<KeyboardControlsState<T>>,
20
+ GetState<KeyboardControlsState<T>>
21
+ ];
22
+ export declare function useKeyboardControls<T extends string = string, U = any>(sel: StateSelector<KeyboardControlsState<T>, U>): U;
19
23
  export {};