@wandelbots/wandelbots-js-react-components 2.41.0-pr.feature-seperate-timer.383.ed84a08 → 2.41.0-pr.feature-seperate-timer.383.20b279f

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.41.0-pr.feature-seperate-timer.383.ed84a08",
3
+ "version": "2.41.0-pr.feature-seperate-timer.383.20b279f",
4
4
  "description": "React UI toolkit for building applications on top of the Wandelbots platform",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -1,113 +1,25 @@
1
- import { Button, Stack, Typography } from "@mui/material"
1
+ import { Stack } from "@mui/material"
2
2
  import { poseToWandelscriptString } from "@wandelbots/nova-js"
3
- import type {
4
- ConnectedMotionGroup,
5
- MotionGroupStateResponse,
6
- MotionStreamConnection,
7
- } from "@wandelbots/nova-js/v1"
3
+ import type { TcpPose } from "@wandelbots/nova-js/v1"
8
4
  import { observer } from "mobx-react-lite"
9
- import { useRef, useState } from "react"
10
5
  import { externalizeComponent } from "../../externalizeComponent"
11
6
  import { CopyableText } from "../CopyableText"
12
- import { useAutorun } from "../utils/hooks"
13
7
 
14
8
  export type PoseCartesianValuesProps = {
15
- /** Either a MotionStreamConnection or ConnectedMotionGroup */
16
- motionStream?: MotionStreamConnection
17
- connectedMotionGroup?: ConnectedMotionGroup
18
- showCopyButton?: boolean
9
+ pose: TcpPose
19
10
  }
20
11
 
21
12
  export const PoseCartesianValues = externalizeComponent(
22
- observer(
23
- ({
24
- motionStream,
25
- connectedMotionGroup,
26
- showCopyButton = false,
27
- }: PoseCartesianValuesProps) => {
28
- const poseHolderRef = useRef<HTMLDivElement>(null)
29
- const [copyMessage, setCopyMessage] = useState("")
30
-
31
- if (!motionStream && !connectedMotionGroup) {
32
- throw new Error(
33
- "PoseCartesianValues requires either motionStream or connectedMotionGroup prop",
34
- )
35
- }
36
-
37
- function getCurrentPoseString() {
38
- let tcpPose: MotionGroupStateResponse["tcp_pose"] | undefined
39
- if (motionStream) {
40
- tcpPose = motionStream.rapidlyChangingMotionState.tcp_pose
41
- } else if (connectedMotionGroup) {
42
- tcpPose = connectedMotionGroup.rapidlyChangingMotionState.tcp_pose
43
- }
44
- if (!tcpPose) return ""
45
- return poseToWandelscriptString(tcpPose)
46
- }
47
-
48
- const handleCopy = async () => {
49
- try {
50
- await navigator.clipboard.writeText(getCurrentPoseString())
51
- setCopyMessage("Copied!")
52
- setTimeout(() => setCopyMessage(""), 2000)
53
- } catch {
54
- setCopyMessage("Copy failed")
55
- setTimeout(() => setCopyMessage(""), 2000)
56
- }
57
- }
58
-
59
- useAutorun(() => {
60
- if (!poseHolderRef.current) {
61
- return
62
- }
63
-
64
- let tcpPose: MotionGroupStateResponse["tcp_pose"] | undefined
65
- if (motionStream) {
66
- tcpPose = motionStream.rapidlyChangingMotionState.tcp_pose
67
- } else if (connectedMotionGroup) {
68
- tcpPose = connectedMotionGroup.rapidlyChangingMotionState.tcp_pose
69
- }
70
-
71
- if (!tcpPose) return
72
-
73
- const newPoseContent = poseToWandelscriptString(tcpPose)
74
-
75
- requestAnimationFrame(() => {
76
- if (
77
- poseHolderRef.current &&
78
- poseHolderRef.current.textContent !== newPoseContent
79
- ) {
80
- poseHolderRef.current.textContent = newPoseContent
81
- }
82
- })
83
- })
84
-
85
- return (
86
- <Stack
87
- direction="row"
88
- alignItems="center"
89
- spacing={1}
90
- sx={{ flexGrow: 1, minWidth: 0, overflow: "hidden" }}
91
- >
92
- <CopyableText value={getCurrentPoseString()} ref={poseHolderRef} />
93
- {showCopyButton && (
94
- <Button
95
- variant="contained"
96
- color="secondary"
97
- size="small"
98
- onClick={handleCopy}
99
- sx={{ flexShrink: 0 }}
100
- >
101
- Copy
102
- </Button>
103
- )}
104
- {copyMessage && (
105
- <Typography variant="caption" color="success.main">
106
- {copyMessage}
107
- </Typography>
108
- )}
109
- </Stack>
110
- )
111
- },
112
- ),
13
+ observer(({ pose }: PoseCartesianValuesProps) => {
14
+ return (
15
+ <Stack
16
+ alignItems="left"
17
+ spacing={2}
18
+ sx={{ flexGrow: 1, minWidth: 0, overflow: "hidden" }}
19
+ data-testid="pose-cartesian-values"
20
+ >
21
+ <CopyableText value={poseToWandelscriptString(pose)} />
22
+ </Stack>
23
+ )
24
+ }),
113
25
  )
@@ -1,118 +1,25 @@
1
- import { Button, Stack, Typography } from "@mui/material"
2
- import type {
3
- ConnectedMotionGroup,
4
- MotionStreamConnection,
5
- } from "@wandelbots/nova-js/v1"
1
+ import { Stack } from "@mui/material"
6
2
  import { observer } from "mobx-react-lite"
7
- import { useRef, useState } from "react"
8
3
  import { externalizeComponent } from "../../externalizeComponent"
9
4
  import { CopyableText } from "../CopyableText"
10
- import { useAutorun } from "../utils/hooks"
11
5
 
12
6
  export type PoseJointValuesProps = {
13
- /** Either a MotionStreamConnection or ConnectedMotionGroup */
14
- motionStream?: MotionStreamConnection
15
- connectedMotionGroup?: ConnectedMotionGroup
16
- showCopyButton?: boolean
7
+ pose: number[]
17
8
  }
18
9
 
19
10
  export const PoseJointValues = externalizeComponent(
20
- observer(
21
- ({
22
- motionStream,
23
- connectedMotionGroup,
24
- showCopyButton = false,
25
- }: PoseJointValuesProps) => {
26
- const poseHolderRef = useRef<HTMLDivElement>(null)
27
- const [copyMessage, setCopyMessage] = useState("")
28
-
29
- if (!motionStream && !connectedMotionGroup) {
30
- throw new Error(
31
- "PoseJointValues requires either motionStream or connectedMotionGroup prop",
32
- )
33
- }
34
-
35
- function getCurrentPoseString() {
36
- let joints: number[]
37
- if (motionStream) {
38
- joints =
39
- motionStream.rapidlyChangingMotionState.state.joint_position.joints
40
- } else if (connectedMotionGroup) {
41
- joints =
42
- connectedMotionGroup.rapidlyChangingMotionState.state.joint_position
43
- .joints
44
- } else {
45
- return ""
46
- }
47
- return `[${joints.map((j: number) => parseFloat(j.toFixed(4))).join(", ")}]`
48
- }
49
-
50
- const handleCopy = async () => {
51
- try {
52
- await navigator.clipboard.writeText(getCurrentPoseString())
53
- setCopyMessage("Copied!")
54
- setTimeout(() => setCopyMessage(""), 2000)
55
- } catch {
56
- setCopyMessage("Copy failed")
57
- setTimeout(() => setCopyMessage(""), 2000)
58
- }
59
- }
60
-
61
- useAutorun(() => {
62
- if (!poseHolderRef.current) {
63
- return
64
- }
65
-
66
- let joints: number[]
67
- if (motionStream) {
68
- joints =
69
- motionStream.rapidlyChangingMotionState.state.joint_position.joints
70
- } else if (connectedMotionGroup) {
71
- joints =
72
- connectedMotionGroup.rapidlyChangingMotionState.state.joint_position
73
- .joints
74
- } else {
75
- return
76
- }
77
-
78
- const newPoseContent = `[${joints.map((j: number) => parseFloat(j.toFixed(4))).join(", ")}]`
79
-
80
- requestAnimationFrame(() => {
81
- if (
82
- poseHolderRef.current &&
83
- poseHolderRef.current.textContent !== newPoseContent
84
- ) {
85
- poseHolderRef.current.textContent = newPoseContent
86
- }
87
- })
88
- })
89
-
90
- return (
91
- <Stack
92
- direction="row"
93
- alignItems="center"
94
- spacing={1}
95
- sx={{ flexGrow: 1, minWidth: 0, overflow: "hidden" }}
96
- >
97
- <CopyableText value={getCurrentPoseString()} ref={poseHolderRef} />
98
- {showCopyButton && (
99
- <Button
100
- variant="contained"
101
- color="secondary"
102
- size="small"
103
- onClick={handleCopy}
104
- sx={{ flexShrink: 0 }}
105
- >
106
- Copy
107
- </Button>
108
- )}
109
- {copyMessage && (
110
- <Typography variant="caption" color="success.main">
111
- {copyMessage}
112
- </Typography>
113
- )}
114
- </Stack>
115
- )
116
- },
117
- ),
11
+ observer(({ pose }: PoseJointValuesProps) => {
12
+ const poseString = `[${pose.map((j: number) => parseFloat(j.toFixed(4))).join(", ")}]`
13
+
14
+ return (
15
+ <Stack
16
+ alignItems="left"
17
+ spacing={2}
18
+ sx={{ flexGrow: 1, minWidth: 0, overflow: "hidden" }}
19
+ data-testid="pose-joint-values"
20
+ >
21
+ <CopyableText value={poseString} />
22
+ </Stack>
23
+ )
24
+ }),
118
25
  )