@wandelbots/wandelbots-js-react-components 2.58.0 → 2.59.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wandelbots/wandelbots-js-react-components",
3
- "version": "2.58.0",
3
+ "version": "2.59.0",
4
4
  "description": "React UI toolkit for building applications on top of the Wandelbots platform",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -146,7 +146,7 @@
146
146
  "mobx": "^6.13.6",
147
147
  "mobx-react-lite": "^4.1.0",
148
148
  "react-error-boundary": "^6.0.0",
149
- "react-i18next": "^15.5.2",
149
+ "react-i18next": "^16.5.4",
150
150
  "shiki": "^3.1.0"
151
151
  },
152
152
  "overrides": {
@@ -3,7 +3,7 @@ import type {
3
3
  DHParameter,
4
4
  MotionGroupStateResponse,
5
5
  } from "@wandelbots/nova-api/v1"
6
- import React, { useEffect, useRef } from "react"
6
+ import React, { useCallback, useEffect, useRef } from "react"
7
7
  import type { Group, Object3D } from "three"
8
8
  import { useAutorun } from "../utils/hooks"
9
9
  import { ValueInterpolator } from "../utils/interpolation"
@@ -68,11 +68,6 @@ export default function RobotAnimator({
68
68
  invalidate()
69
69
  }
70
70
 
71
- function updateJoints(newJointValues: number[]) {
72
- jointValues.current = newJointValues
73
- interpolatorRef.current?.setTarget(newJointValues)
74
- }
75
-
76
71
  function setRotation() {
77
72
  const updatedJointValues = interpolatorRef.current?.getCurrentValues() || []
78
73
 
@@ -90,13 +85,33 @@ export default function RobotAnimator({
90
85
  }
91
86
  }
92
87
 
93
- useAutorun(() => {
88
+ const updateJoints = useCallback(() => {
94
89
  const newJointValues =
95
90
  rapidlyChangingMotionState.state.joint_position.joints.filter(
96
91
  (item) => item !== undefined,
97
92
  )
98
93
 
99
- requestAnimationFrame(() => updateJoints(newJointValues))
94
+ requestAnimationFrame(() => {
95
+ jointValues.current = newJointValues
96
+ interpolatorRef.current?.setTarget(newJointValues)
97
+ })
98
+ }, [rapidlyChangingMotionState])
99
+
100
+ /**
101
+ * Fire an update joints call on every motion state change.
102
+ * requestAnimationFrame used to avoid blocking main thread
103
+ */
104
+ useEffect(() => {
105
+ updateJoints()
106
+ }, [rapidlyChangingMotionState, updateJoints])
107
+
108
+ /**
109
+ * As some consumer applications (eg. storybook) deliver
110
+ * mobx observable for rapidlyChangingMotionState, we need to
111
+ * register the watcher to get the newest value updates
112
+ */
113
+ useAutorun(() => {
114
+ updateJoints()
100
115
  })
101
116
 
102
117
  return <group ref={setGroupRef}>{children}</group>