Skip to content

Commit 8be9b48

Browse files
r3f components typing (#1008)
* /r3f components typing * type update * r3f type fixes, test cases * type fixes, formating and misc * type fixes, misc * Fix newline * eslint fixes * Fix remaining lint errors * Install eslint version * Fix lint command, fix lint issues * Remove unused import * using tsc to test type checking for r3f props, remove unnecessary packages * Restore TilesRenderer.test.ts * Fix lint errors * package lock update * Remove DS_STORE from ignore * spelling error * incorrect import paths * types/react install, remove skipLibCheck * lint fixes * rollback testing using jest, for switching to vitest in the next pr * lint, import fixes --------- Co-authored-by: Garrett Johnson <garrett.kjohnson@gmail.com>
1 parent c4664e0 commit 8be9b48

18 files changed

Lines changed: 6192 additions & 8809 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,5 @@ typings/
6262

6363
example/local-data
6464
example/dev-bundle
65+
66+
pnpm-lock.yaml

babel.config.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@
1111

1212
"node": "current"
1313

14-
}
15-
14+
},
15+
"modules": "auto"
1616
}
1717

18-
]
19-
18+
],
19+
"@babel/preset-react",
20+
"@babel/preset-typescript",
21+
"@babel/preset-modules"
22+
],
23+
"ignore": [
24+
"/node_modules/"
2025
]
21-
2226
}

jest.config.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
{
2-
"testPathIgnorePatterns": ["types"]
2+
"transformIgnorePatterns": [
3+
"/node_modules/"
4+
],
5+
"testPathIgnorePatterns": [
6+
"/node_modules/",
7+
"types"
8+
],
9+
"preset": "ts-jest",
10+
"testEnvironment": "node",
11+
"transform": {
12+
"^.+\\.js$": "babel-jest"
13+
}
314
}

package-lock.json

Lines changed: 5917 additions & 8790 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"scripts": {
3030
"start": "vite --config ./vite.config.js",
3131
"build-examples": "vite build --config ./vite.config.js",
32-
"lint": "eslint \"src/**/*.{js,jsx,ts}\" \"test/**/*.js\" \"example/*.{js,jsx}\" && tsc -p tsconfig.json --noEmit",
32+
"lint": "eslint \"src/**/*.{js,jsx,ts}\" \"test/**/*.{js,ts,tsx,jsx}\" \"example/*.{js,jsx}\" && tsc -p tsconfig.json --noEmit",
3333
"test": "tsc --project tsconfig.test.json && jest"
3434
},
3535
"repository": {
@@ -45,19 +45,26 @@
4545
"devDependencies": {
4646
"@babel/core": "^7.21.8",
4747
"@babel/preset-env": "^7.21.5",
48+
"@babel/preset-modules": "^0.1.6",
49+
"@babel/preset-react": "^7.26.3",
50+
"@babel/preset-typescript": "^7.26.0",
4851
"@react-three/drei": "^9.114.3",
4952
"@react-three/postprocessing": "^2.16.3",
5053
"@takram/three-atmosphere": "^0.10.3",
5154
"@takram/three-geospatial": "^0.1.0",
5255
"@takram/three-geospatial-effects": "^0.1.0",
5356
"@types/eslint": "^7.28.1",
57+
"@types/jest": "^27.5.2",
58+
"@types/react": "^18.3.12",
59+
"@types/react-dom": "^18.3.1",
5460
"@types/three": "^0.166.0",
5561
"@typescript-eslint/eslint-plugin": "^7.14.1",
5662
"@typescript-eslint/parser": "^7.14.1",
5763
"@vitejs/plugin-react": "^4.3.2",
58-
"babel-jest": "^29.5.0",
64+
"babel-jest": "^27.5.1",
5965
"cesium": "^1.97.0",
6066
"concurrently": "^6.2.1",
67+
"eslint": "^8.57.1",
6168
"eslint-config-mdcs": "^5.0.0",
6269
"eslint-plugin-jest": "^28.6.0",
6370
"eslint-plugin-react": "^7.37.1",
@@ -67,7 +74,8 @@
6774
"leva": "^0.9.35",
6875
"postprocessing": "^6.36.4",
6976
"three": "^0.170.0",
70-
"typescript": "^5.1.3",
77+
"ts-jest": "^27.1.5",
78+
"typescript": "^4.9.5",
7179
"vite": "^6.2.2"
7280
},
7381
"peerDependencies": {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import type { ForwardRefExoticComponent, RefAttributes } from 'react';
2+
import type { Camera, Object3D } from 'three';
3+
import type { EnvironmentControls as EnvironmentControlsImpl } from '../../three/controls/EnvironmentControls';
4+
import type { GlobeControls as GlobeControlsImpl } from '../../three/controls/GlobeControls';
5+
import type { TilesRenderer } from './TilesRenderer';
6+
7+
interface ControlsBaseProps {
8+
domElement?: HTMLCanvasElement | null;
9+
scene?: Object3D | null;
10+
camera?: Camera | null;
11+
tilesRenderer?: typeof TilesRenderer | null;
12+
}
13+
14+
type EnvironmentControlsProps = Partial<
15+
InstanceType<typeof EnvironmentControlsImpl>
16+
> &
17+
ControlsBaseProps;
18+
19+
type GlobeControlsProps = Partial<InstanceType<typeof GlobeControlsImpl>> &
20+
ControlsBaseProps;
21+
22+
export declare const EnvironmentControls: ForwardRefExoticComponent<
23+
EnvironmentControlsProps & RefAttributes<EnvironmentControlsImpl>
24+
>;
25+
26+
export declare const GlobeControls: ForwardRefExoticComponent<
27+
GlobeControlsProps & RefAttributes<GlobeControlsImpl>
28+
>;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Camera } from 'three';
2+
import { CameraTransitionManager } from '../../three/controls/CameraTransitionManager';
3+
4+
interface CameraTransitionProps {
5+
mode?: 'perspective' | 'orthographic';
6+
onBeforeToggle?: ( manager: CameraTransitionManager, targetCamera: Camera ) => void;
7+
perspectiveCamera?: Camera;
8+
orthographicCamera?: Camera;
9+
}
10+
11+
export declare const CameraTransition: React.ForwardRefExoticComponent<
12+
CameraTransitionProps & React.RefAttributes<CameraTransitionManager>
13+
>;

src/r3f/components/CameraTransition.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { forwardRef, useEffect, useMemo } from 'react';
22
import { useFrame, useThree } from '@react-three/fiber';
3-
import { CameraTransitionManager } from '3d-tiles-renderer';
3+
import { CameraTransitionManager } from '../../three/controls/CameraTransitionManager.js';
44
import { useDeepOptions } from '../utilities/useOptions.js';
55
import { useApplyRefs } from '../utilities/useApplyRefs.js';
66

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { ComponentPropsWithoutRef, ReactNode } from 'react';
2+
3+
export interface CanvasDOMOverlayProps extends ComponentPropsWithoutRef<'div'> {
4+
children?: ReactNode;
5+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type {
2+
ReactNode,
3+
ForwardRefExoticComponent,
4+
RefAttributes,
5+
} from 'react';
6+
import type { Group } from 'three';
7+
8+
interface CompassGizmoProps {
9+
children?: ReactNode;
10+
mode?: '3d' | '2d';
11+
visible?: boolean;
12+
scale?: number;
13+
margin?: number | [number, number];
14+
overrideRenderLoop?: boolean;
15+
}
16+
17+
export declare const CompassGizmo: ForwardRefExoticComponent<
18+
CompassGizmoProps & RefAttributes<Group>
19+
>;

0 commit comments

Comments
 (0)