@react-three/fiber 8.13.0 → 8.13.1
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/CHANGELOG.md +6 -0
- package/dist/declarations/src/core/index.d.ts +2 -3
- package/dist/declarations/src/core/store.d.ts +1 -2
- package/dist/{index-22ee0173.esm.js → index-13b06ff5.esm.js} +25 -69
- package/dist/{index-ed22818c.cjs.prod.js → index-948f4806.cjs.prod.js} +25 -69
- package/dist/{index-f4b96a62.cjs.dev.js → index-a0deb08b.cjs.dev.js} +25 -69
- package/dist/react-three-fiber.cjs.dev.js +1 -1
- package/dist/react-three-fiber.cjs.prod.js +1 -1
- package/dist/react-three-fiber.esm.js +2 -2
- package/native/dist/react-three-fiber-native.cjs.dev.js +1 -1
- package/native/dist/react-three-fiber-native.cjs.prod.js +1 -1
- package/native/dist/react-three-fiber-native.esm.js +2 -2
- package/package.json +1 -1
- package/readme.md +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,7 @@ import * as THREE from 'three';
|
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import { UseBoundStore } from 'zustand';
|
|
6
6
|
import * as ReactThreeFiber from '../three-types';
|
|
7
|
-
import { Renderer, context, RootState, Size, Dpr, Performance
|
|
7
|
+
import { Renderer, context, RootState, Size, Dpr, Performance } from './store';
|
|
8
8
|
import { extend, Root } from './renderer';
|
|
9
9
|
import { addEffect, addAfterEffect, addTail, flushGlobalEffects } from './loop';
|
|
10
10
|
import { EventManager, ComputeFunction } from './events';
|
|
@@ -43,14 +43,13 @@ export declare type ReconcilerRoot<TCanvas extends Canvas> = {
|
|
|
43
43
|
declare function createRoot<TCanvas extends Canvas>(canvas: TCanvas): ReconcilerRoot<TCanvas>;
|
|
44
44
|
declare function render<TCanvas extends Canvas>(children: React.ReactNode, canvas: TCanvas, config: RenderProps<TCanvas>): UseBoundStore<RootState>;
|
|
45
45
|
declare function unmountComponentAtNode<TCanvas extends Canvas>(canvas: TCanvas, callback?: (canvas: TCanvas) => void): void;
|
|
46
|
-
export declare type InjectState = Partial<Omit<RootState,
|
|
46
|
+
export declare type InjectState = Partial<Omit<RootState, 'events'> & {
|
|
47
47
|
events?: {
|
|
48
48
|
enabled?: boolean;
|
|
49
49
|
priority?: number;
|
|
50
50
|
compute?: ComputeFunction;
|
|
51
51
|
connected?: any;
|
|
52
52
|
};
|
|
53
|
-
size?: Size;
|
|
54
53
|
}>;
|
|
55
54
|
declare function createPortal(children: React.ReactNode, container: THREE.Object3D, state?: InjectState): JSX.Element;
|
|
56
55
|
declare const act: any;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
/// <reference types="webxr" />
|
|
1
2
|
import * as THREE from 'three';
|
|
2
3
|
import * as React from 'react';
|
|
3
4
|
import { GetState, SetState, StoreApi, UseBoundStore } from 'zustand';
|
|
4
5
|
import { DomEvent, EventManager, PointerCaptureTarget, ThreeEvent } from './events';
|
|
5
6
|
import { Camera } from './utils';
|
|
6
|
-
export declare const privateKeys: readonly ["set", "get", "setSize", "setFrameloop", "setDpr", "events", "invalidate", "advance", "size", "viewport"];
|
|
7
|
-
export declare type PrivateKeys = typeof privateKeys[number];
|
|
8
7
|
export interface Intersection extends THREE.Intersection {
|
|
9
8
|
eventObject: THREE.Object3D;
|
|
10
9
|
}
|
|
@@ -150,13 +150,7 @@ function createRenderer(_roots, _getEventPriority) {
|
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
// Remove references
|
|
153
|
-
|
|
154
|
-
delete child.__r3f.root;
|
|
155
|
-
delete child.__r3f.objects;
|
|
156
|
-
delete child.__r3f.handlers;
|
|
157
|
-
delete child.__r3f.memoizedProps;
|
|
158
|
-
if (!isPrimitive) delete child.__r3f;
|
|
159
|
-
}
|
|
153
|
+
delete child.__r3f;
|
|
160
154
|
|
|
161
155
|
// Dispose item whenever the reconciler feels like it
|
|
162
156
|
if (shouldDispose && child.dispose && child.type !== 'Scene') {
|
|
@@ -1206,8 +1200,6 @@ function createEvents(store) {
|
|
|
1206
1200
|
};
|
|
1207
1201
|
}
|
|
1208
1202
|
|
|
1209
|
-
// Keys that shouldn't be copied between R3F stores
|
|
1210
|
-
const privateKeys = ['set', 'get', 'setSize', 'setFrameloop', 'setDpr', 'events', 'invalidate', 'advance', 'size', 'viewport'];
|
|
1211
1203
|
const isRenderer = def => !!(def != null && def.render);
|
|
1212
1204
|
const context = /*#__PURE__*/React.createContext(null);
|
|
1213
1205
|
const createStore = (invalidate, advance) => {
|
|
@@ -2037,7 +2029,6 @@ function unmountComponentAtNode(canvas, callback) {
|
|
|
2037
2029
|
}
|
|
2038
2030
|
function createPortal(children, container, state) {
|
|
2039
2031
|
return /*#__PURE__*/React.createElement(Portal, {
|
|
2040
|
-
key: container.uuid,
|
|
2041
2032
|
children: children,
|
|
2042
2033
|
container: container,
|
|
2043
2034
|
state: state
|
|
@@ -2061,26 +2052,9 @@ function Portal({
|
|
|
2061
2052
|
const previousRoot = useStore();
|
|
2062
2053
|
const [raycaster] = React.useState(() => new THREE.Raycaster());
|
|
2063
2054
|
const [pointer] = React.useState(() => new THREE.Vector2());
|
|
2064
|
-
const inject =
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
}; // all prev state props
|
|
2068
|
-
|
|
2069
|
-
// Only the fields of "rootState" that do not differ from injectState
|
|
2070
|
-
// Some props should be off-limits
|
|
2071
|
-
// Otherwise filter out the props that are different and let the inject layer take precedence
|
|
2072
|
-
Object.keys(rootState).forEach(key => {
|
|
2073
|
-
if (
|
|
2074
|
-
// Some props should be off-limits
|
|
2075
|
-
privateKeys.includes(key) ||
|
|
2076
|
-
// Otherwise filter out the props that are different and let the inject layer take precedence
|
|
2077
|
-
// Unless the inject layer props is undefined, then we keep the root layer
|
|
2078
|
-
rootState[key] !== injectState[key] && injectState[key]) {
|
|
2079
|
-
delete intersect[key];
|
|
2080
|
-
}
|
|
2081
|
-
});
|
|
2082
|
-
let viewport = undefined;
|
|
2083
|
-
if (injectState && size) {
|
|
2055
|
+
const inject = useMutableCallback((rootState, injectState) => {
|
|
2056
|
+
let viewport;
|
|
2057
|
+
if (injectState.camera && size) {
|
|
2084
2058
|
const camera = injectState.camera;
|
|
2085
2059
|
// Calculate the override viewport, if present
|
|
2086
2060
|
viewport = rootState.viewport.getCurrentViewport(camera, new THREE.Vector3(), size);
|
|
@@ -2089,7 +2063,9 @@ function Portal({
|
|
|
2089
2063
|
}
|
|
2090
2064
|
return {
|
|
2091
2065
|
// The intersect consists of the previous root state
|
|
2092
|
-
...
|
|
2066
|
+
...rootState,
|
|
2067
|
+
get: injectState.get,
|
|
2068
|
+
set: injectState.set,
|
|
2093
2069
|
// Portals have their own scene, which forms the root, a raycaster and a pointer
|
|
2094
2070
|
scene: container,
|
|
2095
2071
|
raycaster,
|
|
@@ -2100,7 +2076,7 @@ function Portal({
|
|
|
2100
2076
|
// Events, size and viewport can be overridden by the inject layer
|
|
2101
2077
|
events: {
|
|
2102
2078
|
...rootState.events,
|
|
2103
|
-
...
|
|
2079
|
+
...injectState.events,
|
|
2104
2080
|
...events
|
|
2105
2081
|
},
|
|
2106
2082
|
size: {
|
|
@@ -2111,53 +2087,33 @@ function Portal({
|
|
|
2111
2087
|
...rootState.viewport,
|
|
2112
2088
|
...viewport
|
|
2113
2089
|
},
|
|
2114
|
-
...rest
|
|
2115
|
-
};
|
|
2116
|
-
}, [state]);
|
|
2117
|
-
const [usePortalStore] = React.useState(() => {
|
|
2118
|
-
// Create a mirrored store, based on the previous root with a few overrides ...
|
|
2119
|
-
const previousState = previousRoot.getState();
|
|
2120
|
-
const store = create((set, get) => ({
|
|
2121
|
-
...previousState,
|
|
2122
|
-
scene: container,
|
|
2123
|
-
raycaster,
|
|
2124
|
-
pointer,
|
|
2125
|
-
mouse: pointer,
|
|
2126
|
-
previousRoot,
|
|
2127
|
-
events: {
|
|
2128
|
-
...previousState.events,
|
|
2129
|
-
...events
|
|
2130
|
-
},
|
|
2131
|
-
size: {
|
|
2132
|
-
...previousState.size,
|
|
2133
|
-
...size
|
|
2134
|
-
},
|
|
2135
|
-
...rest,
|
|
2136
|
-
// Set and get refer to this root-state
|
|
2137
|
-
set,
|
|
2138
|
-
get,
|
|
2139
2090
|
// Layers are allowed to override events
|
|
2140
|
-
setEvents: events => set(state => ({
|
|
2091
|
+
setEvents: events => injectState.set(state => ({
|
|
2141
2092
|
...state,
|
|
2142
2093
|
events: {
|
|
2143
2094
|
...state.events,
|
|
2144
2095
|
...events
|
|
2145
2096
|
}
|
|
2146
2097
|
}))
|
|
2147
|
-
}
|
|
2148
|
-
return store;
|
|
2098
|
+
};
|
|
2149
2099
|
});
|
|
2150
|
-
React.
|
|
2100
|
+
const usePortalStore = React.useMemo(() => {
|
|
2101
|
+
const store = create((set, get) => ({
|
|
2102
|
+
...rest,
|
|
2103
|
+
set,
|
|
2104
|
+
get
|
|
2105
|
+
}));
|
|
2106
|
+
|
|
2151
2107
|
// Subscribe to previous root-state and copy changes over to the mirrored portal-state
|
|
2152
|
-
const
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
}, []);
|
|
2108
|
+
const onMutate = prev => store.setState(state => inject.current(prev, state));
|
|
2109
|
+
onMutate(previousRoot.getState());
|
|
2110
|
+
previousRoot.subscribe(onMutate);
|
|
2111
|
+
return store;
|
|
2112
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2113
|
+
}, [previousRoot, container]);
|
|
2158
2114
|
React.useEffect(() => {
|
|
2159
|
-
|
|
2160
|
-
}, [
|
|
2115
|
+
return () => usePortalStore.destroy();
|
|
2116
|
+
}, [usePortalStore]);
|
|
2161
2117
|
return /*#__PURE__*/React.createElement(React.Fragment, null, reconciler.createPortal( /*#__PURE__*/React.createElement(context.Provider, {
|
|
2162
2118
|
value: usePortalStore
|
|
2163
2119
|
}, children), usePortalStore, null));
|
|
@@ -177,13 +177,7 @@ function createRenderer(_roots, _getEventPriority) {
|
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
// Remove references
|
|
180
|
-
|
|
181
|
-
delete child.__r3f.root;
|
|
182
|
-
delete child.__r3f.objects;
|
|
183
|
-
delete child.__r3f.handlers;
|
|
184
|
-
delete child.__r3f.memoizedProps;
|
|
185
|
-
if (!isPrimitive) delete child.__r3f;
|
|
186
|
-
}
|
|
180
|
+
delete child.__r3f;
|
|
187
181
|
|
|
188
182
|
// Dispose item whenever the reconciler feels like it
|
|
189
183
|
if (shouldDispose && child.dispose && child.type !== 'Scene') {
|
|
@@ -1233,8 +1227,6 @@ function createEvents(store) {
|
|
|
1233
1227
|
};
|
|
1234
1228
|
}
|
|
1235
1229
|
|
|
1236
|
-
// Keys that shouldn't be copied between R3F stores
|
|
1237
|
-
const privateKeys = ['set', 'get', 'setSize', 'setFrameloop', 'setDpr', 'events', 'invalidate', 'advance', 'size', 'viewport'];
|
|
1238
1230
|
const isRenderer = def => !!(def != null && def.render);
|
|
1239
1231
|
const context = /*#__PURE__*/React__namespace.createContext(null);
|
|
1240
1232
|
const createStore = (invalidate, advance) => {
|
|
@@ -2064,7 +2056,6 @@ function unmountComponentAtNode(canvas, callback) {
|
|
|
2064
2056
|
}
|
|
2065
2057
|
function createPortal(children, container, state) {
|
|
2066
2058
|
return /*#__PURE__*/React__namespace.createElement(Portal, {
|
|
2067
|
-
key: container.uuid,
|
|
2068
2059
|
children: children,
|
|
2069
2060
|
container: container,
|
|
2070
2061
|
state: state
|
|
@@ -2088,26 +2079,9 @@ function Portal({
|
|
|
2088
2079
|
const previousRoot = useStore();
|
|
2089
2080
|
const [raycaster] = React__namespace.useState(() => new THREE__namespace.Raycaster());
|
|
2090
2081
|
const [pointer] = React__namespace.useState(() => new THREE__namespace.Vector2());
|
|
2091
|
-
const inject =
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
}; // all prev state props
|
|
2095
|
-
|
|
2096
|
-
// Only the fields of "rootState" that do not differ from injectState
|
|
2097
|
-
// Some props should be off-limits
|
|
2098
|
-
// Otherwise filter out the props that are different and let the inject layer take precedence
|
|
2099
|
-
Object.keys(rootState).forEach(key => {
|
|
2100
|
-
if (
|
|
2101
|
-
// Some props should be off-limits
|
|
2102
|
-
privateKeys.includes(key) ||
|
|
2103
|
-
// Otherwise filter out the props that are different and let the inject layer take precedence
|
|
2104
|
-
// Unless the inject layer props is undefined, then we keep the root layer
|
|
2105
|
-
rootState[key] !== injectState[key] && injectState[key]) {
|
|
2106
|
-
delete intersect[key];
|
|
2107
|
-
}
|
|
2108
|
-
});
|
|
2109
|
-
let viewport = undefined;
|
|
2110
|
-
if (injectState && size) {
|
|
2082
|
+
const inject = useMutableCallback((rootState, injectState) => {
|
|
2083
|
+
let viewport;
|
|
2084
|
+
if (injectState.camera && size) {
|
|
2111
2085
|
const camera = injectState.camera;
|
|
2112
2086
|
// Calculate the override viewport, if present
|
|
2113
2087
|
viewport = rootState.viewport.getCurrentViewport(camera, new THREE__namespace.Vector3(), size);
|
|
@@ -2116,7 +2090,9 @@ function Portal({
|
|
|
2116
2090
|
}
|
|
2117
2091
|
return {
|
|
2118
2092
|
// The intersect consists of the previous root state
|
|
2119
|
-
...
|
|
2093
|
+
...rootState,
|
|
2094
|
+
get: injectState.get,
|
|
2095
|
+
set: injectState.set,
|
|
2120
2096
|
// Portals have their own scene, which forms the root, a raycaster and a pointer
|
|
2121
2097
|
scene: container,
|
|
2122
2098
|
raycaster,
|
|
@@ -2127,7 +2103,7 @@ function Portal({
|
|
|
2127
2103
|
// Events, size and viewport can be overridden by the inject layer
|
|
2128
2104
|
events: {
|
|
2129
2105
|
...rootState.events,
|
|
2130
|
-
...
|
|
2106
|
+
...injectState.events,
|
|
2131
2107
|
...events
|
|
2132
2108
|
},
|
|
2133
2109
|
size: {
|
|
@@ -2138,53 +2114,33 @@ function Portal({
|
|
|
2138
2114
|
...rootState.viewport,
|
|
2139
2115
|
...viewport
|
|
2140
2116
|
},
|
|
2141
|
-
...rest
|
|
2142
|
-
};
|
|
2143
|
-
}, [state]);
|
|
2144
|
-
const [usePortalStore] = React__namespace.useState(() => {
|
|
2145
|
-
// Create a mirrored store, based on the previous root with a few overrides ...
|
|
2146
|
-
const previousState = previousRoot.getState();
|
|
2147
|
-
const store = create__default["default"]((set, get) => ({
|
|
2148
|
-
...previousState,
|
|
2149
|
-
scene: container,
|
|
2150
|
-
raycaster,
|
|
2151
|
-
pointer,
|
|
2152
|
-
mouse: pointer,
|
|
2153
|
-
previousRoot,
|
|
2154
|
-
events: {
|
|
2155
|
-
...previousState.events,
|
|
2156
|
-
...events
|
|
2157
|
-
},
|
|
2158
|
-
size: {
|
|
2159
|
-
...previousState.size,
|
|
2160
|
-
...size
|
|
2161
|
-
},
|
|
2162
|
-
...rest,
|
|
2163
|
-
// Set and get refer to this root-state
|
|
2164
|
-
set,
|
|
2165
|
-
get,
|
|
2166
2117
|
// Layers are allowed to override events
|
|
2167
|
-
setEvents: events => set(state => ({
|
|
2118
|
+
setEvents: events => injectState.set(state => ({
|
|
2168
2119
|
...state,
|
|
2169
2120
|
events: {
|
|
2170
2121
|
...state.events,
|
|
2171
2122
|
...events
|
|
2172
2123
|
}
|
|
2173
2124
|
}))
|
|
2174
|
-
}
|
|
2175
|
-
return store;
|
|
2125
|
+
};
|
|
2176
2126
|
});
|
|
2177
|
-
React__namespace.
|
|
2127
|
+
const usePortalStore = React__namespace.useMemo(() => {
|
|
2128
|
+
const store = create__default["default"]((set, get) => ({
|
|
2129
|
+
...rest,
|
|
2130
|
+
set,
|
|
2131
|
+
get
|
|
2132
|
+
}));
|
|
2133
|
+
|
|
2178
2134
|
// Subscribe to previous root-state and copy changes over to the mirrored portal-state
|
|
2179
|
-
const
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
}, []);
|
|
2135
|
+
const onMutate = prev => store.setState(state => inject.current(prev, state));
|
|
2136
|
+
onMutate(previousRoot.getState());
|
|
2137
|
+
previousRoot.subscribe(onMutate);
|
|
2138
|
+
return store;
|
|
2139
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2140
|
+
}, [previousRoot, container]);
|
|
2185
2141
|
React__namespace.useEffect(() => {
|
|
2186
|
-
|
|
2187
|
-
}, [
|
|
2142
|
+
return () => usePortalStore.destroy();
|
|
2143
|
+
}, [usePortalStore]);
|
|
2188
2144
|
return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, reconciler.createPortal( /*#__PURE__*/React__namespace.createElement(context.Provider, {
|
|
2189
2145
|
value: usePortalStore
|
|
2190
2146
|
}, children), usePortalStore, null));
|
|
@@ -177,13 +177,7 @@ function createRenderer(_roots, _getEventPriority) {
|
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
// Remove references
|
|
180
|
-
|
|
181
|
-
delete child.__r3f.root;
|
|
182
|
-
delete child.__r3f.objects;
|
|
183
|
-
delete child.__r3f.handlers;
|
|
184
|
-
delete child.__r3f.memoizedProps;
|
|
185
|
-
if (!isPrimitive) delete child.__r3f;
|
|
186
|
-
}
|
|
180
|
+
delete child.__r3f;
|
|
187
181
|
|
|
188
182
|
// Dispose item whenever the reconciler feels like it
|
|
189
183
|
if (shouldDispose && child.dispose && child.type !== 'Scene') {
|
|
@@ -1233,8 +1227,6 @@ function createEvents(store) {
|
|
|
1233
1227
|
};
|
|
1234
1228
|
}
|
|
1235
1229
|
|
|
1236
|
-
// Keys that shouldn't be copied between R3F stores
|
|
1237
|
-
const privateKeys = ['set', 'get', 'setSize', 'setFrameloop', 'setDpr', 'events', 'invalidate', 'advance', 'size', 'viewport'];
|
|
1238
1230
|
const isRenderer = def => !!(def != null && def.render);
|
|
1239
1231
|
const context = /*#__PURE__*/React__namespace.createContext(null);
|
|
1240
1232
|
const createStore = (invalidate, advance) => {
|
|
@@ -2064,7 +2056,6 @@ function unmountComponentAtNode(canvas, callback) {
|
|
|
2064
2056
|
}
|
|
2065
2057
|
function createPortal(children, container, state) {
|
|
2066
2058
|
return /*#__PURE__*/React__namespace.createElement(Portal, {
|
|
2067
|
-
key: container.uuid,
|
|
2068
2059
|
children: children,
|
|
2069
2060
|
container: container,
|
|
2070
2061
|
state: state
|
|
@@ -2088,26 +2079,9 @@ function Portal({
|
|
|
2088
2079
|
const previousRoot = useStore();
|
|
2089
2080
|
const [raycaster] = React__namespace.useState(() => new THREE__namespace.Raycaster());
|
|
2090
2081
|
const [pointer] = React__namespace.useState(() => new THREE__namespace.Vector2());
|
|
2091
|
-
const inject =
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
}; // all prev state props
|
|
2095
|
-
|
|
2096
|
-
// Only the fields of "rootState" that do not differ from injectState
|
|
2097
|
-
// Some props should be off-limits
|
|
2098
|
-
// Otherwise filter out the props that are different and let the inject layer take precedence
|
|
2099
|
-
Object.keys(rootState).forEach(key => {
|
|
2100
|
-
if (
|
|
2101
|
-
// Some props should be off-limits
|
|
2102
|
-
privateKeys.includes(key) ||
|
|
2103
|
-
// Otherwise filter out the props that are different and let the inject layer take precedence
|
|
2104
|
-
// Unless the inject layer props is undefined, then we keep the root layer
|
|
2105
|
-
rootState[key] !== injectState[key] && injectState[key]) {
|
|
2106
|
-
delete intersect[key];
|
|
2107
|
-
}
|
|
2108
|
-
});
|
|
2109
|
-
let viewport = undefined;
|
|
2110
|
-
if (injectState && size) {
|
|
2082
|
+
const inject = useMutableCallback((rootState, injectState) => {
|
|
2083
|
+
let viewport;
|
|
2084
|
+
if (injectState.camera && size) {
|
|
2111
2085
|
const camera = injectState.camera;
|
|
2112
2086
|
// Calculate the override viewport, if present
|
|
2113
2087
|
viewport = rootState.viewport.getCurrentViewport(camera, new THREE__namespace.Vector3(), size);
|
|
@@ -2116,7 +2090,9 @@ function Portal({
|
|
|
2116
2090
|
}
|
|
2117
2091
|
return {
|
|
2118
2092
|
// The intersect consists of the previous root state
|
|
2119
|
-
...
|
|
2093
|
+
...rootState,
|
|
2094
|
+
get: injectState.get,
|
|
2095
|
+
set: injectState.set,
|
|
2120
2096
|
// Portals have their own scene, which forms the root, a raycaster and a pointer
|
|
2121
2097
|
scene: container,
|
|
2122
2098
|
raycaster,
|
|
@@ -2127,7 +2103,7 @@ function Portal({
|
|
|
2127
2103
|
// Events, size and viewport can be overridden by the inject layer
|
|
2128
2104
|
events: {
|
|
2129
2105
|
...rootState.events,
|
|
2130
|
-
...
|
|
2106
|
+
...injectState.events,
|
|
2131
2107
|
...events
|
|
2132
2108
|
},
|
|
2133
2109
|
size: {
|
|
@@ -2138,53 +2114,33 @@ function Portal({
|
|
|
2138
2114
|
...rootState.viewport,
|
|
2139
2115
|
...viewport
|
|
2140
2116
|
},
|
|
2141
|
-
...rest
|
|
2142
|
-
};
|
|
2143
|
-
}, [state]);
|
|
2144
|
-
const [usePortalStore] = React__namespace.useState(() => {
|
|
2145
|
-
// Create a mirrored store, based on the previous root with a few overrides ...
|
|
2146
|
-
const previousState = previousRoot.getState();
|
|
2147
|
-
const store = create__default["default"]((set, get) => ({
|
|
2148
|
-
...previousState,
|
|
2149
|
-
scene: container,
|
|
2150
|
-
raycaster,
|
|
2151
|
-
pointer,
|
|
2152
|
-
mouse: pointer,
|
|
2153
|
-
previousRoot,
|
|
2154
|
-
events: {
|
|
2155
|
-
...previousState.events,
|
|
2156
|
-
...events
|
|
2157
|
-
},
|
|
2158
|
-
size: {
|
|
2159
|
-
...previousState.size,
|
|
2160
|
-
...size
|
|
2161
|
-
},
|
|
2162
|
-
...rest,
|
|
2163
|
-
// Set and get refer to this root-state
|
|
2164
|
-
set,
|
|
2165
|
-
get,
|
|
2166
2117
|
// Layers are allowed to override events
|
|
2167
|
-
setEvents: events => set(state => ({
|
|
2118
|
+
setEvents: events => injectState.set(state => ({
|
|
2168
2119
|
...state,
|
|
2169
2120
|
events: {
|
|
2170
2121
|
...state.events,
|
|
2171
2122
|
...events
|
|
2172
2123
|
}
|
|
2173
2124
|
}))
|
|
2174
|
-
}
|
|
2175
|
-
return store;
|
|
2125
|
+
};
|
|
2176
2126
|
});
|
|
2177
|
-
React__namespace.
|
|
2127
|
+
const usePortalStore = React__namespace.useMemo(() => {
|
|
2128
|
+
const store = create__default["default"]((set, get) => ({
|
|
2129
|
+
...rest,
|
|
2130
|
+
set,
|
|
2131
|
+
get
|
|
2132
|
+
}));
|
|
2133
|
+
|
|
2178
2134
|
// Subscribe to previous root-state and copy changes over to the mirrored portal-state
|
|
2179
|
-
const
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
}, []);
|
|
2135
|
+
const onMutate = prev => store.setState(state => inject.current(prev, state));
|
|
2136
|
+
onMutate(previousRoot.getState());
|
|
2137
|
+
previousRoot.subscribe(onMutate);
|
|
2138
|
+
return store;
|
|
2139
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2140
|
+
}, [previousRoot, container]);
|
|
2185
2141
|
React__namespace.useEffect(() => {
|
|
2186
|
-
|
|
2187
|
-
}, [
|
|
2142
|
+
return () => usePortalStore.destroy();
|
|
2143
|
+
}, [usePortalStore]);
|
|
2188
2144
|
return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, reconciler.createPortal( /*#__PURE__*/React__namespace.createElement(context.Provider, {
|
|
2189
2145
|
value: usePortalStore
|
|
2190
2146
|
}, children), usePortalStore, null));
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('./index-
|
|
5
|
+
var index = require('./index-a0deb08b.cjs.dev.js');
|
|
6
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var THREE = require('three');
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('./index-
|
|
5
|
+
var index = require('./index-948f4806.cjs.prod.js');
|
|
6
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var THREE = require('three');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as createEvents, e as extend, u as useMutableCallback, a as useIsomorphicLayoutEffect, b as createRoot, i as isRef, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from './index-
|
|
2
|
-
export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, A as useFrame, C as useGraph, x as useInstanceHandle, D as useLoader, y as useStore, z as useThree } from './index-
|
|
1
|
+
import { c as createEvents, e as extend, u as useMutableCallback, a as useIsomorphicLayoutEffect, b as createRoot, i as isRef, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from './index-13b06ff5.esm.js';
|
|
2
|
+
export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, A as useFrame, C as useGraph, x as useInstanceHandle, D as useLoader, y as useStore, z as useThree } from './index-13b06ff5.esm.js';
|
|
3
3
|
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import * as THREE from 'three';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('../../dist/index-
|
|
5
|
+
var index = require('../../dist/index-a0deb08b.cjs.dev.js');
|
|
6
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var THREE = require('three');
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('../../dist/index-
|
|
5
|
+
var index = require('../../dist/index-948f4806.cjs.prod.js');
|
|
6
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var THREE = require('three');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as createEvents, e as extend, u as useMutableCallback, b as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-
|
|
2
|
-
export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, A as useFrame, C as useGraph, x as useInstanceHandle, D as useLoader, y as useStore, z as useThree } from '../../dist/index-
|
|
1
|
+
import { c as createEvents, e as extend, u as useMutableCallback, b as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-13b06ff5.esm.js';
|
|
2
|
+
export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, A as useFrame, C as useGraph, x as useInstanceHandle, D as useLoader, y as useStore, z as useThree } from '../../dist/index-13b06ff5.esm.js';
|
|
3
3
|
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import * as THREE from 'three';
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -201,7 +201,7 @@ Visit [docs.pmnd.rs](https://docs.pmnd.rs/react-three-fiber)
|
|
|
201
201
|
|
|
202
202
|
# Fundamentals
|
|
203
203
|
|
|
204
|
-
You need to be versed in both React and Threejs before rushing into this. If you are unsure about React consult the official [React docs](https://
|
|
204
|
+
You need to be versed in both React and Threejs before rushing into this. If you are unsure about React consult the official [React docs](https://react.dev/learn), especially [the section about hooks](https://react.dev/reference/react). As for Threejs, make sure you at least glance over the following links:
|
|
205
205
|
|
|
206
206
|
1. Make sure you have a [basic grasp of Threejs](https://threejs.org/docs/index.html#manual/en/introduction/Creating-a-scene). Keep that site open.
|
|
207
207
|
2. When you know what a scene is, a camera, mesh, geometry, material, fork the [demo above](https://github.com/pmndrs/react-three-fiber#what-does-it-look-like).
|