@wandelbots/wandelbots-js-react-components 2.41.0-pr.feature-seperate-timer.383.35a3a58 → 2.41.0-pr.feature-seperate-timer.383.4d0d430

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