@react-three/fiber 7.0.21 → 7.0.25

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.
@@ -41,7 +41,8 @@ const is = {
41
41
  function makeId(event) {
42
42
  return (event.eventObject || event.object).uuid + '/' + event.index + event.instanceId;
43
43
  }
44
- /** Release pointer captures.
44
+ /**
45
+ * Release pointer captures.
45
46
  * This is called by releasePointerCapture in the API, and when an object is removed.
46
47
  */
47
48
 
@@ -328,13 +329,16 @@ function createEvents(store) {
328
329
 
329
330
  case 'onLostPointerCapture':
330
331
  return event => {
331
- if ('pointerId' in event) {
332
+ const {
333
+ internal
334
+ } = store.getState();
335
+
336
+ if ('pointerId' in event && !internal.capturedMap.has(event.pointerId)) {
332
337
  // If the object event interface had onLostPointerCapture, we'd call it here on every
333
338
  // object that's getting removed.
334
- store.getState().internal.capturedMap.delete(event.pointerId);
339
+ internal.capturedMap.delete(event.pointerId);
340
+ cancelPointer([]);
335
341
  }
336
-
337
- cancelPointer([]);
338
342
  };
339
343
  } // Any other pointer goes here ...
340
344
 
@@ -403,12 +407,17 @@ function createEvents(store) {
403
407
  if (handler) {
404
408
  // Forward all events back to their respective handlers with the exception of click events,
405
409
  // which must use the initial target
406
- if (name !== 'onClick' && name !== 'onContextMenu' && name !== 'onDoubleClick' || internal.initialHits.includes(eventObject)) {
410
+ if (!isClickEvent || internal.initialHits.includes(eventObject)) {
407
411
  // Missed events have to come first
408
412
  pointerMissed(event, internal.interaction.filter(object => !internal.initialHits.includes(object))); // Now call the handler
409
413
 
410
414
  handler(data);
411
415
  }
416
+ } else {
417
+ // Trigger onPointerMissed on all elements that have pointer over/out handlers, but not click and weren't hit
418
+ if (isClickEvent && internal.initialHits.includes(eventObject)) {
419
+ pointerMissed(event, internal.interaction.filter(object => !internal.initialHits.includes(object)));
420
+ }
412
421
  }
413
422
  }
414
423
  });
@@ -546,6 +555,8 @@ function createRenderer(roots) {
546
555
 
547
556
  if (instance.__r3f) instance.__r3f.memoizedProps = memoized;
548
557
  changes.forEach(([key, value, isEvent, keys]) => {
558
+ var _rootState$gl;
559
+
549
560
  let currentInstance = instance;
550
561
  let targetProp = currentInstance[key]; // Revolve dashed props
551
562
 
@@ -576,8 +587,9 @@ function createRenderer(roots) {
576
587
 
577
588
  if (defaultClassCall.dispose) defaultClassCall.dispose(); // instance does not have constructor, just set it to 0
578
589
  } else value = 0;
579
- } // Deal with pointer events ...
590
+ }
580
591
 
592
+ const isLinear = (rootState == null ? void 0 : (_rootState$gl = rootState.gl) == null ? void 0 : _rootState$gl.outputEncoding) === THREE.LinearEncoding; // Deal with pointer events ...
581
593
 
582
594
  if (isEvent) {
583
595
  if (value) localState.handlers[key] = value;else delete localState.handlers[key];
@@ -598,20 +610,20 @@ function createRenderer(roots) {
598
610
  else targetProp.set(value); // Auto-convert sRGB colors, for now ...
599
611
  // https://github.com/pmndrs/react-three-fiber/issues/344
600
612
 
601
- if (!rootState.linear && isColor) targetProp.convertSRGBToLinear();
613
+ if (!isLinear && isColor) targetProp.convertSRGBToLinear();
602
614
  } // Else, just overwrite the value
603
615
 
604
616
  } else {
605
617
  currentInstance[key] = value; // Auto-convert sRGB textures, for now ...
606
618
  // https://github.com/pmndrs/react-three-fiber/issues/344
607
619
 
608
- if (!rootState.linear && currentInstance[key] instanceof THREE.Texture) currentInstance[key].encoding = THREE.sRGBEncoding;
620
+ if (!isLinear && currentInstance[key] instanceof THREE.Texture) currentInstance[key].encoding = THREE.sRGBEncoding;
609
621
  }
610
622
 
611
623
  invalidateInstance(instance);
612
624
  });
613
625
 
614
- if (rootState.internal && instance.raycast && prevHandlers !== localState.eventCount) {
626
+ if (localState.parent && rootState.internal && instance.raycast && prevHandlers !== localState.eventCount) {
615
627
  // Pre-emptively remove the instance from the interaction manager
616
628
  const index = rootState.internal.interaction.indexOf(instance);
617
629
  if (index > -1) rootState.internal.interaction.splice(index, 1); // Add the instance to the interaction manager only when it has handlers
@@ -664,7 +676,9 @@ function createRenderer(roots) {
664
676
  });
665
677
  } else {
666
678
  const target = catalogue[name] || THREE[name];
667
- if (!target) throw `${name} is not part of the THREE namespace! Did you forget to extend? See: https://github.com/pmndrs/react-three-fiber/blob/master/markdown/api.md#using-3rd-party-objects-declaratively`; // Instanciate new object, link it to the root
679
+ if (!target) throw `${name} is not part of the THREE namespace! Did you forget to extend? See: https://github.com/pmndrs/react-three-fiber/blob/master/markdown/api.md#using-3rd-party-objects-declaratively`; // Throw if an object or literal was passed for args
680
+
681
+ if (!Array.isArray(args)) throw 'The args prop must be an array!'; // Instanciate new object, link it to the root
668
682
  // Append memoized props with args so it's not forgotten
669
683
 
670
684
  instance = prepare(new target(...args), {
@@ -797,7 +811,7 @@ function createRenderer(roots) {
797
811
  parentInstance[child.attachArray] = parentInstance[child.attachArray].filter(x => x !== child);
798
812
  } else if (child.attachObject) {
799
813
  delete parentInstance[child.attachObject[0]][child.attachObject[1]];
800
- } else if (child.attach && !is.fun(child.attach)) {
814
+ } else if (child.attach && !is.fun(child.attach) && parentInstance[child.attach] === child) {
801
815
  parentInstance[child.attach] = null;
802
816
  } else if (is.arr(child.attachFns)) {
803
817
  const [, detachFn] = child.attachFns;
@@ -880,10 +894,13 @@ function createRenderer(roots) {
880
894
 
881
895
  instance.__r3f.objects = [];
882
896
  removeChild(parent, instance);
883
- appendChild(parent, newInstance) // This evil hack switches the react-internal fiber node
884
- // https://github.com/facebook/react/issues/14983
885
- // https://github.com/facebook/react/pull/15021
886
- ;
897
+ appendChild(parent, newInstance); // Re-bind event handlers
898
+
899
+ if (newInstance.raycast && newInstance.__r3f.eventCount) {
900
+ const rootState = newInstance.__r3f.root.getState();
901
+
902
+ rootState.internal.interaction.push(newInstance);
903
+ } // This evil hack switches the react-internal fiber node
887
904
  [fiber, fiber.alternate].forEach(fiber => {
888
905
  if (fiber !== null) {
889
906
  fiber.stateNode = newInstance;
@@ -938,12 +955,24 @@ function createRenderer(roots) {
938
955
  args: argsOld = [],
939
956
  children: cO,
940
957
  ...restOld
941
- } = oldProps; // If it has new props or arguments, then it needs to be re-instanciated
958
+ } = oldProps; // Throw if an object or literal was passed for args
959
+
960
+ if (!Array.isArray(argsNew)) throw 'The args prop must be an array!'; // If it has new props or arguments, then it needs to be re-instanciated
942
961
 
943
962
  if (argsNew.some((value, index) => value !== argsOld[index])) return [true]; // Create a diff-set, flag if there are any changes
944
963
 
945
964
  const diff = diffProps(instance, restNew, restOld, true);
946
- if (diff.changes.length) return [false, diff]; // Otherwise do not touch the instance
965
+ if (diff.changes.length) return [false, diff]; // If instance was never attached, attach it
966
+
967
+ if (instance.attach && typeof instance.attach !== 'function') {
968
+ const localState = instance.__r3f;
969
+ const parent = localState.parent;
970
+
971
+ if (parent && parent[instance.attach] !== instance) {
972
+ appendChild(parent, instance);
973
+ }
974
+ } // Otherwise do not touch the instance
975
+
947
976
 
948
977
  return null;
949
978
  }
@@ -988,11 +1017,24 @@ function createRenderer(roots) {
988
1017
 
989
1018
  createTextInstance() {},
990
1019
 
991
- finalizeInitialChildren() {
992
- return false;
1020
+ finalizeInitialChildren(instance) {
1021
+ var _instance$__r3f7;
1022
+
1023
+ // https://github.com/facebook/react/issues/20271
1024
+ // Returning true will trigger commitMount
1025
+ const localState = (_instance$__r3f7 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f7 : {};
1026
+ return !!localState.handlers;
993
1027
  },
994
1028
 
995
- commitMount() {// noop
1029
+ commitMount(instance)
1030
+ /*, type, props*/
1031
+ {
1032
+ var _instance$__r3f8;
1033
+
1034
+ // https://github.com/facebook/react/issues/20271
1035
+ // This will make sure events are only added once to the central container
1036
+ const localState = (_instance$__r3f8 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f8 : {};
1037
+ if (instance.raycast && localState.handlers && localState.eventCount) instance.__r3f.root.getState().internal.interaction.push(instance);
996
1038
  },
997
1039
 
998
1040
  shouldDeprioritizeSubtree() {
@@ -1199,6 +1241,9 @@ const createStore = (applyProps, invalidate, advance, props) => {
1199
1241
  dpr: calculateDpr(dpr)
1200
1242
  }
1201
1243
  })),
1244
+ setFrameloop: (frameloop = 'always') => set(() => ({
1245
+ frameloop
1246
+ })),
1202
1247
  events: {
1203
1248
  connected: false
1204
1249
  },
@@ -1207,7 +1252,7 @@ const createStore = (applyProps, invalidate, advance, props) => {
1207
1252
  priority: 0,
1208
1253
  frames: 0,
1209
1254
  lastProps: props,
1210
- lastEvent: /*#__PURE__*/React.createRef(null),
1255
+ lastEvent: /*#__PURE__*/React.createRef(),
1211
1256
  interaction: [],
1212
1257
  hovered: new Map(),
1213
1258
  subscribers: [],
@@ -1263,7 +1308,7 @@ const createStore = (applyProps, invalidate, advance, props) => {
1263
1308
  if (size !== oldSize || viewport.dpr !== oldDpr) {
1264
1309
  // https://github.com/pmndrs/react-three-fiber/issues/92
1265
1310
  // Do not mess with the camera if it belongs to the user
1266
- if (!(internal.lastProps.camera instanceof THREE.Camera)) {
1311
+ if (!camera.manual && !(internal.lastProps.camera instanceof THREE.Camera)) {
1267
1312
  if (isOrthographicCamera(camera)) {
1268
1313
  camera.left = size.width / -2;
1269
1314
  camera.right = size.width / 2;
@@ -1688,7 +1733,9 @@ function render(element, canvas, {
1688
1733
  // Check pixelratio
1689
1734
  if (props.dpr !== undefined && !is.equ(state.viewport.dpr, calculateDpr(props.dpr))) state.setDpr(props.dpr); // Check size
1690
1735
 
1691
- if (state.size.width !== size.width || state.size.height !== size.height) state.setSize(size.width, size.height); // For some props we want to reset the entire root
1736
+ if (state.size.width !== size.width || state.size.height !== size.height) state.setSize(size.width, size.height); // Check frameloop
1737
+
1738
+ if (state.frameloop !== props.frameloop) state.setFrameloop(props.frameloop); // For some props we want to reset the entire root
1692
1739
  // Changes to the color-space
1693
1740
 
1694
1741
  const linearChanged = props.linear !== state.internal.lastProps.linear;
@@ -1 +1,11 @@
1
- export * from "../../dist/declarations/src/native";
1
+ // are you seeing an error that a default export doesn't exist but your source file has a default export?
2
+ // you should run `yarn` or `yarn preconstruct dev` if preconstruct dev isn't in your postinstall hook
3
+
4
+ // curious why you need to?
5
+ // this file exists so that you can import from the entrypoint normally
6
+ // except that it points to your source file and you don't need to run build constantly
7
+ // which means we need to re-export all of the modules from your source file
8
+ // and since export * doesn't include default exports, we need to read your source file
9
+ // to check for a default export and re-export it if it exists
10
+ // it's not ideal, but it works pretty well ¯\_(ツ)_/¯
11
+ export * from "../../src/native";
@@ -1,7 +1,16 @@
1
- 'use strict';
1
+ "use strict";
2
+ // this file might look strange and you might be wondering what it's for
3
+ // it's lets you import your source files by importing this entrypoint
4
+ // as you would import it if it was built with preconstruct build
5
+ // this file is slightly different to some others though
6
+ // it has a require hook which compiles your code with Babel
7
+ // this means that you don't have to set up @babel/register or anything like that
8
+ // but you can still require this module and it'll be compiled
2
9
 
3
- if (process.env.NODE_ENV === "production") {
4
- module.exports = require("./react-three-fiber-native.cjs.prod.js");
5
- } else {
6
- module.exports = require("./react-three-fiber-native.cjs.dev.js");
7
- }
10
+ // this bit of code imports the require hook and registers it
11
+ let unregister = require("../../../../node_modules/@preconstruct/hook").___internalHook(typeof __dirname === 'undefined' ? undefined : __dirname, "../../../..", "../..");
12
+
13
+ // this re-exports the source file
14
+ module.exports = require("../../src/native.tsx");
15
+
16
+ unregister();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/fiber",
3
- "version": "7.0.21",
3
+ "version": "7.0.25",
4
4
  "description": "A React renderer for Threejs",
5
5
  "keywords": [
6
6
  "react",
@@ -12,7 +12,8 @@
12
12
  "author": "Paul Henschel (https://github.com/drcmda)",
13
13
  "license": "MIT",
14
14
  "maintainers": [
15
- "Josh Ellis (https://github.com/joshuaellis)"
15
+ "Josh Ellis (https://github.com/joshuaellis)",
16
+ "Cody Bennett (https://github.com/codyjasonbennett)"
16
17
  ],
17
18
  "bugs": {
18
19
  "url": "https://github.com/pmndrs/react-three-fiber/issues"
@@ -54,7 +55,7 @@
54
55
  "peerDependencies": {
55
56
  "react": ">=17.0",
56
57
  "react-dom": ">=17.0",
57
- "three": ">=0.126"
58
+ "three": ">=0.133"
58
59
  },
59
60
  "peerDependenciesMeta": {
60
61
  "react-dom": {