@react-three/fiber 8.7.0 → 8.7.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.
@@ -39,6 +39,7 @@ var threeTypes = /*#__PURE__*/Object.freeze({
39
39
 
40
40
  var _window$document, _window$navigator;
41
41
  const isOrthographicCamera = def => def && def.isOrthographicCamera;
42
+ const isRef = obj => obj && obj.hasOwnProperty('current');
42
43
  /**
43
44
  * An SSR-friendly useLayoutEffect.
44
45
  *
@@ -503,9 +504,7 @@ function removeInteractivity(store, object) {
503
504
  });
504
505
  }
505
506
  function createEvents(store) {
506
- const temp = new THREE__namespace.Vector3();
507
507
  /** Calculates delta */
508
-
509
508
  function calculateDistance(event) {
510
509
  const {
511
510
  internal
@@ -605,108 +604,113 @@ function createEvents(store) {
605
604
 
606
605
 
607
606
  function handleIntersects(intersections, event, delta, callback) {
608
- const {
609
- raycaster,
610
- pointer,
611
- camera,
612
- internal
613
- } = store.getState(); // If anything has been found, forward it to the event listeners
614
-
607
+ // If anything has been found, forward it to the event listeners
615
608
  if (intersections.length) {
616
- const unprojectedPoint = temp.set(pointer.x, pointer.y, 0).unproject(camera);
617
609
  const localState = {
618
610
  stopped: false
619
611
  };
620
612
 
621
613
  for (const hit of intersections) {
622
- const hasPointerCapture = id => {
623
- var _internal$capturedMap, _internal$capturedMap2;
614
+ const state = getRootState(hit.object);
624
615
 
625
- return (_internal$capturedMap = (_internal$capturedMap2 = internal.capturedMap.get(id)) == null ? void 0 : _internal$capturedMap2.has(hit.eventObject)) != null ? _internal$capturedMap : false;
626
- };
616
+ if (state) {
617
+ const {
618
+ raycaster,
619
+ pointer,
620
+ camera,
621
+ internal
622
+ } = state;
623
+ const unprojectedPoint = new THREE__namespace.Vector3(pointer.x, pointer.y, 0).unproject(camera);
627
624
 
628
- const setPointerCapture = id => {
629
- const captureData = {
630
- intersection: hit,
631
- target: event.target
625
+ const hasPointerCapture = id => {
626
+ var _internal$capturedMap, _internal$capturedMap2;
627
+
628
+ return (_internal$capturedMap = (_internal$capturedMap2 = internal.capturedMap.get(id)) == null ? void 0 : _internal$capturedMap2.has(hit.eventObject)) != null ? _internal$capturedMap : false;
632
629
  };
633
630
 
634
- if (internal.capturedMap.has(id)) {
635
- // if the pointerId was previously captured, we add the hit to the
636
- // event capturedMap.
637
- internal.capturedMap.get(id).set(hit.eventObject, captureData);
638
- } else {
639
- // if the pointerId was not previously captured, we create a map
640
- // containing the hitObject, and the hit. hitObject is used for
641
- // faster access.
642
- internal.capturedMap.set(id, new Map([[hit.eventObject, captureData]]));
643
- } // Call the original event now
644
- event.target.setPointerCapture(id);
645
- };
631
+ const setPointerCapture = id => {
632
+ const captureData = {
633
+ intersection: hit,
634
+ target: event.target
635
+ };
636
+
637
+ if (internal.capturedMap.has(id)) {
638
+ // if the pointerId was previously captured, we add the hit to the
639
+ // event capturedMap.
640
+ internal.capturedMap.get(id).set(hit.eventObject, captureData);
641
+ } else {
642
+ // if the pointerId was not previously captured, we create a map
643
+ // containing the hitObject, and the hit. hitObject is used for
644
+ // faster access.
645
+ internal.capturedMap.set(id, new Map([[hit.eventObject, captureData]]));
646
+ } // Call the original event now
647
+ event.target.setPointerCapture(id);
648
+ };
646
649
 
647
- const releasePointerCapture = id => {
648
- const captures = internal.capturedMap.get(id);
650
+ const releasePointerCapture = id => {
651
+ const captures = internal.capturedMap.get(id);
649
652
 
650
- if (captures) {
651
- releaseInternalPointerCapture(internal.capturedMap, hit.eventObject, captures, id);
652
- }
653
- }; // Add native event props
653
+ if (captures) {
654
+ releaseInternalPointerCapture(internal.capturedMap, hit.eventObject, captures, id);
655
+ }
656
+ }; // Add native event props
654
657
 
655
658
 
656
- let extractEventProps = {}; // This iterates over the event's properties including the inherited ones. Native PointerEvents have most of their props as getters which are inherited, but polyfilled PointerEvents have them all as their own properties (i.e. not inherited). We can't use Object.keys() or Object.entries() as they only return "own" properties; nor Object.getPrototypeOf(event) as that *doesn't* return "own" properties, only inherited ones.
659
+ let extractEventProps = {}; // This iterates over the event's properties including the inherited ones. Native PointerEvents have most of their props as getters which are inherited, but polyfilled PointerEvents have them all as their own properties (i.e. not inherited). We can't use Object.keys() or Object.entries() as they only return "own" properties; nor Object.getPrototypeOf(event) as that *doesn't* return "own" properties, only inherited ones.
657
660
 
658
- for (let prop in event) {
659
- let property = event[prop]; // Only copy over atomics, leave functions alone as these should be
660
- // called as event.nativeEvent.fn()
661
+ for (let prop in event) {
662
+ let property = event[prop]; // Only copy over atomics, leave functions alone as these should be
663
+ // called as event.nativeEvent.fn()
661
664
 
662
- if (typeof property !== 'function') extractEventProps[prop] = property;
663
- }
665
+ if (typeof property !== 'function') extractEventProps[prop] = property;
666
+ }
664
667
 
665
- let raycastEvent = { ...hit,
666
- ...extractEventProps,
667
- pointer,
668
- intersections,
669
- stopped: localState.stopped,
670
- delta,
671
- unprojectedPoint,
672
- ray: raycaster.ray,
673
- camera: camera,
674
- // Hijack stopPropagation, which just sets a flag
675
- stopPropagation: () => {
676
- // https://github.com/pmndrs/react-three-fiber/issues/596
677
- // Events are not allowed to stop propagation if the pointer has been captured
678
- const capturesForPointer = 'pointerId' in event && internal.capturedMap.get(event.pointerId); // We only authorize stopPropagation...
679
-
680
- if ( // ...if this pointer hasn't been captured
681
- !capturesForPointer || // ... or if the hit object is capturing the pointer
682
- capturesForPointer.has(hit.eventObject)) {
683
- raycastEvent.stopped = localState.stopped = true; // Propagation is stopped, remove all other hover records
684
- // An event handler is only allowed to flush other handlers if it is hovered itself
685
-
686
- if (internal.hovered.size && Array.from(internal.hovered.values()).find(i => i.eventObject === hit.eventObject)) {
687
- // Objects cannot flush out higher up objects that have already caught the event
688
- const higher = intersections.slice(0, intersections.indexOf(hit));
689
- cancelPointer([...higher, hit]);
668
+ let raycastEvent = { ...hit,
669
+ ...extractEventProps,
670
+ pointer,
671
+ intersections,
672
+ stopped: localState.stopped,
673
+ delta,
674
+ unprojectedPoint,
675
+ ray: raycaster.ray,
676
+ camera: camera,
677
+ // Hijack stopPropagation, which just sets a flag
678
+ stopPropagation: () => {
679
+ // https://github.com/pmndrs/react-three-fiber/issues/596
680
+ // Events are not allowed to stop propagation if the pointer has been captured
681
+ const capturesForPointer = 'pointerId' in event && internal.capturedMap.get(event.pointerId); // We only authorize stopPropagation...
682
+
683
+ if ( // ...if this pointer hasn't been captured
684
+ !capturesForPointer || // ... or if the hit object is capturing the pointer
685
+ capturesForPointer.has(hit.eventObject)) {
686
+ raycastEvent.stopped = localState.stopped = true; // Propagation is stopped, remove all other hover records
687
+ // An event handler is only allowed to flush other handlers if it is hovered itself
688
+
689
+ if (internal.hovered.size && Array.from(internal.hovered.values()).find(i => i.eventObject === hit.eventObject)) {
690
+ // Objects cannot flush out higher up objects that have already caught the event
691
+ const higher = intersections.slice(0, intersections.indexOf(hit));
692
+ cancelPointer([...higher, hit]);
693
+ }
690
694
  }
691
- }
692
- },
693
- // there should be a distinction between target and currentTarget
694
- target: {
695
- hasPointerCapture,
696
- setPointerCapture,
697
- releasePointerCapture
698
- },
699
- currentTarget: {
700
- hasPointerCapture,
701
- setPointerCapture,
702
- releasePointerCapture
703
- },
704
- nativeEvent: event
705
- }; // Call subscribers
706
-
707
- callback(raycastEvent); // Event bubbling may be interrupted by stopPropagation
708
-
709
- if (localState.stopped === true) break;
695
+ },
696
+ // there should be a distinction between target and currentTarget
697
+ target: {
698
+ hasPointerCapture,
699
+ setPointerCapture,
700
+ releasePointerCapture
701
+ },
702
+ currentTarget: {
703
+ hasPointerCapture,
704
+ setPointerCapture,
705
+ releasePointerCapture
706
+ },
707
+ nativeEvent: event
708
+ }; // Call subscribers
709
+
710
+ callback(raycastEvent); // Event bubbling may be interrupted by stopPropagation
711
+
712
+ if (localState.stopped === true) break;
713
+ }
710
714
  }
711
715
  }
712
716
 
@@ -2172,6 +2176,7 @@ exports.dispose = dispose;
2172
2176
  exports.extend = extend;
2173
2177
  exports.getRootState = getRootState;
2174
2178
  exports.invalidate = invalidate;
2179
+ exports.isRef = isRef;
2175
2180
  exports.reconciler = reconciler;
2176
2181
  exports.render = render;
2177
2182
  exports.roots = roots;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-b3d1f4d2.cjs.dev.js');
5
+ var index = require('./index-407f3d70.cjs.dev.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -187,7 +187,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
187
187
  onPointerMissed: (...args) => handlePointerMissed.current == null ? void 0 : handlePointerMissed.current(...args),
188
188
  onCreated: state => {
189
189
  // Connect to event source
190
- state.events.connect == null ? void 0 : state.events.connect(eventSource ? eventSource : divRef.current); // Set up compute function
190
+ state.events.connect == null ? void 0 : state.events.connect(eventSource ? index.isRef(eventSource) ? eventSource.current : eventSource : divRef.current); // Set up compute function
191
191
 
192
192
  if (eventPrefix) {
193
193
  state.setEvents({
@@ -218,7 +218,10 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
218
218
  }, []);
219
219
  React__namespace.useEffect(() => {
220
220
  if (canvas) return () => index.unmountComponentAtNode(canvas);
221
- }, [canvas]);
221
+ }, [canvas]); // When the event source is not this div, we need to set pointer-events to none
222
+ // Or else the canvas will block events from reaching the event source
223
+
224
+ const pointerEvents = eventSource ? 'none' : 'auto';
222
225
  return /*#__PURE__*/React__namespace.createElement("div", _extends({
223
226
  ref: divRef,
224
227
  style: {
@@ -226,6 +229,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
226
229
  width: '100%',
227
230
  height: '100%',
228
231
  overflow: 'hidden',
232
+ pointerEvents,
229
233
  ...style
230
234
  }
231
235
  }, props), /*#__PURE__*/React__namespace.createElement("div", {
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-846c69c6.cjs.prod.js');
5
+ var index = require('./index-5350eaac.cjs.prod.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -187,7 +187,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
187
187
  onPointerMissed: (...args) => handlePointerMissed.current == null ? void 0 : handlePointerMissed.current(...args),
188
188
  onCreated: state => {
189
189
  // Connect to event source
190
- state.events.connect == null ? void 0 : state.events.connect(eventSource ? eventSource : divRef.current); // Set up compute function
190
+ state.events.connect == null ? void 0 : state.events.connect(eventSource ? index.isRef(eventSource) ? eventSource.current : eventSource : divRef.current); // Set up compute function
191
191
 
192
192
  if (eventPrefix) {
193
193
  state.setEvents({
@@ -218,7 +218,10 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
218
218
  }, []);
219
219
  React__namespace.useEffect(() => {
220
220
  if (canvas) return () => index.unmountComponentAtNode(canvas);
221
- }, [canvas]);
221
+ }, [canvas]); // When the event source is not this div, we need to set pointer-events to none
222
+ // Or else the canvas will block events from reaching the event source
223
+
224
+ const pointerEvents = eventSource ? 'none' : 'auto';
222
225
  return /*#__PURE__*/React__namespace.createElement("div", _extends({
223
226
  ref: divRef,
224
227
  style: {
@@ -226,6 +229,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
226
229
  width: '100%',
227
230
  height: '100%',
228
231
  overflow: 'hidden',
232
+ pointerEvents,
229
233
  ...style
230
234
  }
231
235
  }, props), /*#__PURE__*/React__namespace.createElement("div", {
@@ -1,5 +1,5 @@
1
- import { c as createEvents, e as extend, u as useMutableCallback, a as createRoot, E as ErrorBoundary, B as Block, b as useIsomorphicLayoutEffect, d as unmountComponentAtNode } from './index-3b3bed95.esm.js';
2
- export { t as ReactThreeFiber, s as _roots, q as act, n as addAfterEffect, m as addEffect, o as addTail, l as advance, i as applyProps, f as context, c as createEvents, g as createPortal, a as createRoot, j as dispose, e as extend, p as getRootState, k as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, y as useFrame, z as useGraph, v as useInstanceHandle, A as useLoader, w as useStore, x as useThree } from './index-3b3bed95.esm.js';
1
+ import { c as createEvents, e as extend, u as useMutableCallback, a as createRoot, i as isRef, E as ErrorBoundary, B as Block, b as useIsomorphicLayoutEffect, d as unmountComponentAtNode } from './index-05f8627d.esm.js';
2
+ export { t as ReactThreeFiber, v as _roots, s 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, a as createRoot, k as dispose, e as extend, q as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, z as useFrame, A as useGraph, w as useInstanceHandle, C as useLoader, x as useStore, y as useThree } from './index-05f8627d.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';
@@ -160,7 +160,7 @@ const Canvas = /*#__PURE__*/React.forwardRef(function Canvas({
160
160
  onPointerMissed: (...args) => handlePointerMissed.current == null ? void 0 : handlePointerMissed.current(...args),
161
161
  onCreated: state => {
162
162
  // Connect to event source
163
- state.events.connect == null ? void 0 : state.events.connect(eventSource ? eventSource : divRef.current); // Set up compute function
163
+ state.events.connect == null ? void 0 : state.events.connect(eventSource ? isRef(eventSource) ? eventSource.current : eventSource : divRef.current); // Set up compute function
164
164
 
165
165
  if (eventPrefix) {
166
166
  state.setEvents({
@@ -191,7 +191,10 @@ const Canvas = /*#__PURE__*/React.forwardRef(function Canvas({
191
191
  }, []);
192
192
  React.useEffect(() => {
193
193
  if (canvas) return () => unmountComponentAtNode(canvas);
194
- }, [canvas]);
194
+ }, [canvas]); // When the event source is not this div, we need to set pointer-events to none
195
+ // Or else the canvas will block events from reaching the event source
196
+
197
+ const pointerEvents = eventSource ? 'none' : 'auto';
195
198
  return /*#__PURE__*/React.createElement("div", _extends({
196
199
  ref: divRef,
197
200
  style: {
@@ -199,6 +202,7 @@ const Canvas = /*#__PURE__*/React.forwardRef(function Canvas({
199
202
  width: '100%',
200
203
  height: '100%',
201
204
  overflow: 'hidden',
205
+ pointerEvents,
202
206
  ...style
203
207
  }
204
208
  }, props), /*#__PURE__*/React.createElement("div", {
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-b3d1f4d2.cjs.dev.js');
5
+ var index = require('../../dist/index-407f3d70.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-846c69c6.cjs.prod.js');
5
+ var index = require('../../dist/index-5350eaac.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 createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-3b3bed95.esm.js';
2
- export { t as ReactThreeFiber, s as _roots, q as act, n as addAfterEffect, m as addEffect, o as addTail, l as advance, i as applyProps, f as context, g as createPortal, a as createRoot, j as dispose, e as extend, p as getRootState, k as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, y as useFrame, z as useGraph, v as useInstanceHandle, A as useLoader, w as useStore, x as useThree } from '../../dist/index-3b3bed95.esm.js';
1
+ import { c as createEvents, e as extend, u as useMutableCallback, a as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-05f8627d.esm.js';
2
+ export { t as ReactThreeFiber, v as _roots, s as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, g as createPortal, a as createRoot, k as dispose, e as extend, q as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, z as useFrame, A as useGraph, w as useInstanceHandle, C as useLoader, x as useStore, y as useThree } from '../../dist/index-05f8627d.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/fiber",
3
- "version": "8.7.0",
3
+ "version": "8.7.3",
4
4
  "description": "A React renderer for Threejs",
5
5
  "keywords": [
6
6
  "react",