@viamrobotics/test-widgets 0.16.0 → 0.17.1

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.
Files changed (132) hide show
  1. package/dist/components/api-section.svelte +58 -50
  2. package/dist/components/api-section.svelte.d.ts +24 -11
  3. package/dist/components/content-rect.svelte +6 -0
  4. package/dist/components/content-rect.svelte.d.ts +1 -0
  5. package/dist/components/error.svelte +9 -0
  6. package/dist/components/error.svelte.d.ts +6 -0
  7. package/dist/components/index.d.ts +4 -2
  8. package/dist/components/index.js +4 -2
  9. package/dist/components/is-moving.svelte +26 -34
  10. package/dist/components/is-moving.svelte.d.ts +4 -5
  11. package/dist/components/progress.svelte +1 -0
  12. package/dist/components/queries.svelte +7 -0
  13. package/dist/components/queries.svelte.d.ts +4 -0
  14. package/dist/components/query.svelte +7 -0
  15. package/dist/components/query.svelte.d.ts +4 -0
  16. package/dist/components/section/index.d.ts +2 -0
  17. package/dist/components/section/index.js +2 -0
  18. package/dist/components/section/section-error-reporter.d.ts +8 -0
  19. package/dist/components/section/section-error-reporter.js +7 -0
  20. package/dist/components/section/section-error.svelte +36 -0
  21. package/dist/components/section/section-error.svelte.d.ts +9 -0
  22. package/dist/components/section/section-errors.svelte +132 -5
  23. package/dist/components/section/section.svelte +7 -1
  24. package/dist/components/section/section.svelte.d.ts +3 -0
  25. package/dist/components/section/use-section-errors.svelte.d.ts +1 -0
  26. package/dist/components/section/use-section-errors.svelte.js +11 -1
  27. package/dist/components/stop-button.svelte +1 -5
  28. package/dist/components/stop-button.svelte.d.ts +0 -1
  29. package/dist/components/stop.svelte +2 -2
  30. package/dist/components/widgets/arm/arm.svelte +24 -32
  31. package/dist/components/widgets/arm/get-joint-positions-widget.svelte +9 -8
  32. package/dist/components/widgets/arm/manual-mode-widget.svelte +13 -4
  33. package/dist/components/widgets/arm/manual-mode.svelte +1 -5
  34. package/dist/components/widgets/arm/manual-mode.svelte.d.ts +0 -1
  35. package/dist/components/widgets/arm/move-to-joint-positions-widget.svelte +10 -4
  36. package/dist/components/widgets/arm/move-to-joint-positions.svelte +1 -11
  37. package/dist/components/widgets/arm/move-to-joint-positions.svelte.d.ts +0 -1
  38. package/dist/components/widgets/arm/move-to-position-control.svelte +22 -18
  39. package/dist/components/widgets/arm/move-to-position.svelte +0 -4
  40. package/dist/components/widgets/arm/move-to-position.svelte.d.ts +0 -1
  41. package/dist/components/widgets/arm/quick-move-widget.svelte +10 -4
  42. package/dist/components/widgets/arm/quick-move.svelte +1 -4
  43. package/dist/components/widgets/arm/quick-move.svelte.d.ts +0 -1
  44. package/dist/components/widgets/audio-input/audio-input.svelte +76 -74
  45. package/dist/components/widgets/audio-input/get-properties-widget.svelte +15 -15
  46. package/dist/components/widgets/audio-output/audio-output.svelte +83 -81
  47. package/dist/components/widgets/audio-output/get-properties-widget.svelte +15 -15
  48. package/dist/components/widgets/base/base.svelte +70 -37
  49. package/dist/components/widgets/base/move-straight-widget.svelte +16 -4
  50. package/dist/components/widgets/base/quick-move-widget.svelte +25 -9
  51. package/dist/components/widgets/base/set-power-widget.svelte +20 -8
  52. package/dist/components/widgets/base/set-velocity-widget.svelte +20 -8
  53. package/dist/components/widgets/base/spin-widget.svelte +20 -8
  54. package/dist/components/widgets/board/read-write-pins.svelte +2 -2
  55. package/dist/components/widgets/button/push.svelte +2 -2
  56. package/dist/components/widgets/camera/camera.svelte +15 -23
  57. package/dist/components/widgets/camera/live-or-polling-video.svelte +12 -9
  58. package/dist/components/widgets/custom-control/__tests__/__fixtures__/with-sibling.svelte +10 -0
  59. package/dist/components/widgets/custom-control/control-frame.svelte +60 -0
  60. package/dist/components/widgets/custom-control/control-frame.svelte.d.ts +10 -0
  61. package/dist/components/widgets/custom-control/create-control-host.svelte.d.ts +19 -0
  62. package/dist/components/widgets/custom-control/create-control-host.svelte.js +28 -0
  63. package/dist/components/widgets/custom-control/custom-control.d.ts +35 -0
  64. package/dist/components/widgets/custom-control/custom-control.js +85 -0
  65. package/dist/components/widgets/custom-control/custom-control.svelte +45 -0
  66. package/dist/components/widgets/custom-control/custom-control.svelte.d.ts +14 -0
  67. package/dist/components/widgets/discovery/discovery.svelte +10 -15
  68. package/dist/components/widgets/encoder/encoder.svelte +20 -18
  69. package/dist/components/widgets/encoder/get-position-widget.svelte +18 -15
  70. package/dist/components/widgets/gantry/gantry.svelte +50 -74
  71. package/dist/components/widgets/gantry/get-position-widget.svelte +14 -13
  72. package/dist/components/widgets/gantry/home.svelte +21 -10
  73. package/dist/components/widgets/gantry/move-to-position-widget.svelte +2 -1
  74. package/dist/components/widgets/gantry/move-to-position.svelte +1 -4
  75. package/dist/components/widgets/gantry/move-to-position.svelte.d.ts +0 -1
  76. package/dist/components/widgets/gantry/quick-move-widget.svelte +2 -1
  77. package/dist/components/widgets/gantry/quick-move.svelte +1 -5
  78. package/dist/components/widgets/gantry/quick-move.svelte.d.ts +0 -1
  79. package/dist/components/widgets/generic/generic.svelte +7 -5
  80. package/dist/components/widgets/gripper/grab-widget.svelte +26 -0
  81. package/dist/components/widgets/gripper/grab-widget.svelte.d.ts +7 -0
  82. package/dist/components/widgets/gripper/grab.svelte +3 -19
  83. package/dist/components/widgets/gripper/grab.svelte.d.ts +1 -2
  84. package/dist/components/widgets/gripper/gripper.svelte +10 -12
  85. package/dist/components/widgets/gripper/is-holding-something.svelte +18 -19
  86. package/dist/components/widgets/gripper/open-widget.svelte +26 -0
  87. package/dist/components/widgets/gripper/open-widget.svelte.d.ts +7 -0
  88. package/dist/components/widgets/gripper/open.svelte +3 -19
  89. package/dist/components/widgets/gripper/open.svelte.d.ts +1 -2
  90. package/dist/components/widgets/input-controller/input-controller.svelte +7 -14
  91. package/dist/components/widgets/input-controller/webgamepad.svelte +2 -2
  92. package/dist/components/widgets/motion/motion.svelte +27 -35
  93. package/dist/components/widgets/motion/move-widget.svelte +32 -12
  94. package/dist/components/widgets/motion/move-widget.svelte.d.ts +6 -0
  95. package/dist/components/widgets/motion/move.svelte +1 -13
  96. package/dist/components/widgets/motion/move.svelte.d.ts +0 -1
  97. package/dist/components/widgets/motor/go-for-view.svelte +16 -8
  98. package/dist/components/widgets/motor/go-to-view.svelte +12 -4
  99. package/dist/components/widgets/motor/motor.svelte +88 -54
  100. package/dist/components/widgets/motor/quick-move-widget.svelte +16 -8
  101. package/dist/components/widgets/motor/set-power-widget.svelte +12 -4
  102. package/dist/components/widgets/motor/set-rpm-widget.svelte +12 -4
  103. package/dist/components/widgets/movement-sensor/get-accuracy-widget.svelte +7 -10
  104. package/dist/components/widgets/movement-sensor/get-compass-heading-widget.svelte +7 -10
  105. package/dist/components/widgets/movement-sensor/get-orientation-widget.svelte +7 -10
  106. package/dist/components/widgets/movement-sensor/get-position-widget.svelte +7 -10
  107. package/dist/components/widgets/movement-sensor/movement-sensor.svelte +55 -56
  108. package/dist/components/widgets/operations-and-sessions/operations-and-sessions.svelte +2 -1
  109. package/dist/components/widgets/power-sensor/get-current-widget.svelte +7 -10
  110. package/dist/components/widgets/power-sensor/get-power-widget.svelte +7 -10
  111. package/dist/components/widgets/power-sensor/get-voltage-widget.svelte +7 -10
  112. package/dist/components/widgets/power-sensor/power-sensor.svelte +26 -38
  113. package/dist/components/widgets/sensor/sensor.svelte +5 -10
  114. package/dist/components/widgets/servo/move-widget.svelte +2 -1
  115. package/dist/components/widgets/servo/move.svelte +1 -4
  116. package/dist/components/widgets/servo/move.svelte.d.ts +0 -1
  117. package/dist/components/widgets/servo/quick-move-widget.svelte +2 -1
  118. package/dist/components/widgets/servo/quick-move.svelte +1 -5
  119. package/dist/components/widgets/servo/quick-move.svelte.d.ts +0 -1
  120. package/dist/components/widgets/servo/servo.svelte +44 -33
  121. package/dist/components/widgets/slam/get-position-widget.svelte +7 -10
  122. package/dist/components/widgets/slam/move-on-map.svelte +6 -5
  123. package/dist/components/widgets/slam/move-on-map.svelte.d.ts +2 -1
  124. package/dist/components/widgets/slam/slam.svelte +64 -79
  125. package/dist/components/widgets/switch/position.svelte +2 -2
  126. package/package.json +3 -2
  127. package/dist/components/mutation-section.svelte +0 -75
  128. package/dist/components/mutation-section.svelte.d.ts +0 -18
  129. package/dist/components/mutation-view.svelte +0 -29
  130. package/dist/components/mutation-view.svelte.d.ts +0 -10
  131. package/dist/components/section-title.svelte +0 -65
  132. package/dist/components/section-title.svelte.d.ts +0 -15
@@ -0,0 +1,35 @@
1
+ import type { JsonValue } from '@viamrobotics/sdk';
2
+ /**
3
+ * The `doCommand` that asks a resource for its custom control artifact.
4
+ *
5
+ * @deprecated Transitional delivery path. A module declares its control per model in
6
+ * `meta.json` (`models[].custom_control`); serving the bytes over `doCommand` exists only until the
7
+ * machine or registry can serve the declared file. Do not build new integrations on it. Module
8
+ * authors keep their manifests and drop the handler when delivery moves.
9
+ */
10
+ export declare const CUSTOM_CONTROL_COMMAND = "get-custom-control";
11
+ export declare const CUSTOM_CONTROL_CSP: string;
12
+ export interface CustomControlArtifact {
13
+ html: string;
14
+ revision?: string;
15
+ /** The `custom_control` path the module declared for this model in its `meta.json`, when reported. */
16
+ path?: string;
17
+ }
18
+ interface DoCommandClient {
19
+ doCommand(command: Record<string, JsonValue>): Promise<JsonValue>;
20
+ }
21
+ /**
22
+ * Asks a resource for its custom control artifact over `doCommand` and validates the reply.
23
+ *
24
+ * @deprecated Bound to the transitional `doCommand` delivery path ({@link CUSTOM_CONTROL_COMMAND}).
25
+ * The `CustomControlArtifact` it returns is the shape every delivery path will produce; the
26
+ * function is replaced when the machine or registry can serve the manifest-declared file.
27
+ */
28
+ export declare const loadCustomControl: (client: DoCommandClient) => Promise<CustomControlArtifact>;
29
+ /**
30
+ * Returns the artifact with the host's Content Security Policy injected as the first child of
31
+ * `<head>`, creating the head when the artifact has none, so the policy applies before any other
32
+ * element parses. An artifact whose head already opens with this exact meta is returned unchanged.
33
+ */
34
+ export declare const prepareArtifact: (html: string) => string;
35
+ export {};
@@ -0,0 +1,85 @@
1
+ /**
2
+ * The `doCommand` that asks a resource for its custom control artifact.
3
+ *
4
+ * @deprecated Transitional delivery path. A module declares its control per model in
5
+ * `meta.json` (`models[].custom_control`); serving the bytes over `doCommand` exists only until the
6
+ * machine or registry can serve the declared file. Do not build new integrations on it. Module
7
+ * authors keep their manifests and drop the handler when delivery moves.
8
+ */
9
+ export const CUSTOM_CONTROL_COMMAND = 'get-custom-control';
10
+ // The policy the host injects into every custom control artifact before rendering it.
11
+ export const CUSTOM_CONTROL_CSP = [
12
+ "default-src 'none'",
13
+ "script-src 'unsafe-inline'",
14
+ "style-src 'unsafe-inline'",
15
+ 'img-src data: blob:',
16
+ 'media-src blob:',
17
+ 'font-src data:',
18
+ "connect-src 'none'",
19
+ "base-uri 'none'",
20
+ "form-action 'none'",
21
+ ].join('; ');
22
+ const CSP_META = `<meta http-equiv="Content-Security-Policy" content="${CUSTOM_CONTROL_CSP}">`;
23
+ // The artifact is untrusted, so the injection point has to be where the browser's parser sees a
24
+ // real tag. A DOM parser is off the table (it would have to serialize the artifact back), so this
25
+ // is a regex anchored at the start of the document that matches only tags written plainly enough
26
+ // that the browser cannot read them differently:
27
+ // - Only whitespace, comments, and a doctype may precede the tags. An unanchored `<head>` could sit
28
+ // inside a comment, script, or attribute value, where the meta would be inert text.
29
+ // - A comment must end at its first `-->` and may not use the early endings (`<!-->`, `--!>`) the
30
+ // browser also honors, since a tag after an early ending is real to the browser and not to us.
31
+ // - Whitespace is the five HTML characters, not JS `\s`, which also matches U+00A0 and friends.
32
+ // - A quoted attribute value may not contain `<` or `>`, so the first `>` always ends the tag.
33
+ // Anything stranger fails the match, and the meta then goes in a fresh head at the start.
34
+ const SPACE = String.raw `[\t\n\f\r ]`;
35
+ const COMMENT = String.raw `<!--(?!-?>)(?:(?!--!?>)[\s\S])*-->`;
36
+ const SKIPPED = String.raw `(?:${SPACE}|${COMMENT})*`;
37
+ const VALUE = String.raw `"[^"<>]*"|'[^'<>]*'|[^\t\n\f\r "'<>=\x60]+`;
38
+ const ATTRIBUTE = String.raw `${SPACE}+[^\t\n\f\r "'<>/=]+(?:${SPACE}*=${SPACE}*(?:${VALUE}))?`;
39
+ const openingTag = (name) => String.raw `<${name}(?:${ATTRIBUTE})*${SPACE}*>`;
40
+ const DOCUMENT_START = new RegExp(String.raw `^(${SKIPPED}(?:<!doctype[^>]*>${SKIPPED})?)(${openingTag('html')})?(${SKIPPED})(${openingTag('head')})?`, 'i');
41
+ /**
42
+ * Asks a resource for its custom control artifact over `doCommand` and validates the reply.
43
+ *
44
+ * @deprecated Bound to the transitional `doCommand` delivery path ({@link CUSTOM_CONTROL_COMMAND}).
45
+ * The `CustomControlArtifact` it returns is the shape every delivery path will produce; the
46
+ * function is replaced when the machine or registry can serve the manifest-declared file.
47
+ */
48
+ export const loadCustomControl = async (client) => {
49
+ const reply = await client.doCommand({ command: CUSTOM_CONTROL_COMMAND });
50
+ assertArtifact(reply);
51
+ const artifact = { html: reply.html };
52
+ if (reply.revision !== undefined)
53
+ artifact.revision = reply.revision;
54
+ if (reply.path !== undefined)
55
+ artifact.path = reply.path;
56
+ return artifact;
57
+ };
58
+ /**
59
+ * Returns the artifact with the host's Content Security Policy injected as the first child of
60
+ * `<head>`, creating the head when the artifact has none, so the policy applies before any other
61
+ * element parses. An artifact whose head already opens with this exact meta is returned unchanged.
62
+ */
63
+ export const prepareArtifact = (html) => {
64
+ const [, beforeTags = '', htmlTag = '', between = '', headTag = ''] = DOCUMENT_START.exec(html) ?? [];
65
+ if (headTag) {
66
+ const headEnd = beforeTags.length + htmlTag.length + between.length + headTag.length;
67
+ return html.startsWith(CSP_META, headEnd) ? html : insertAt(html, headEnd, CSP_META);
68
+ }
69
+ return insertAt(html, beforeTags.length + htmlTag.length, `<head>${CSP_META}</head>`);
70
+ };
71
+ const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
72
+ const assertArtifact = (value) => {
73
+ if (!isRecord(value))
74
+ throw new Error('Invalid custom control reply: expected an object');
75
+ if (typeof value.html !== 'string' || value.html.trim() === '') {
76
+ throw new Error('Invalid custom control reply: "html" must be a non-blank string');
77
+ }
78
+ if (value.revision !== undefined && typeof value.revision !== 'string') {
79
+ throw new Error('Invalid custom control reply: "revision" must be a string when present');
80
+ }
81
+ if (value.path !== undefined && typeof value.path !== 'string') {
82
+ throw new Error('Invalid custom control reply: "path" must be a string when present');
83
+ }
84
+ };
85
+ const insertAt = (html, index, inserted) => html.slice(0, index) + inserted + html.slice(index);
@@ -0,0 +1,45 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte'
3
+
4
+ import ErrorDisplay from '../../error.svelte'
5
+
6
+ import ControlFrame from './control-frame.svelte'
7
+
8
+ interface Props {
9
+ partID: string
10
+ resourceName: string
11
+ html: string
12
+ loading?: Snippet
13
+ error?: Snippet<[{ failure: Error; reset: () => void }]>
14
+ }
15
+
16
+ const { partID, resourceName, html, loading, error }: Props = $props()
17
+
18
+ const toError = (thrown: unknown) =>
19
+ thrown instanceof Error ? thrown : new Error(String(thrown))
20
+ </script>
21
+
22
+ {#key html}
23
+ <svelte:boundary>
24
+ <ControlFrame
25
+ {partID}
26
+ {resourceName}
27
+ {html}
28
+ {loading}
29
+ />
30
+
31
+ {#snippet failed(thrown, reset)}
32
+ {@const failure = toError(thrown)}
33
+ <div
34
+ role="alert"
35
+ class="bg-extralight flex min-h-40 w-full items-center justify-center p-4"
36
+ >
37
+ {#if error}
38
+ {@render error({ failure, reset })}
39
+ {:else}
40
+ <ErrorDisplay lastError={failure} />
41
+ {/if}
42
+ </div>
43
+ {/snippet}
44
+ </svelte:boundary>
45
+ {/key}
@@ -0,0 +1,14 @@
1
+ import type { Snippet } from 'svelte';
2
+ interface Props {
3
+ partID: string;
4
+ resourceName: string;
5
+ html: string;
6
+ loading?: Snippet;
7
+ error?: Snippet<[{
8
+ failure: Error;
9
+ reset: () => void;
10
+ }]>;
11
+ }
12
+ declare const CustomControl: import("svelte").Component<Props, {}, "">;
13
+ type CustomControl = ReturnType<typeof CustomControl>;
14
+ export default CustomControl;
@@ -9,7 +9,6 @@
9
9
 
10
10
  import ApiSection from '../../api-section.svelte'
11
11
  import ConnectionStatus from '../../connection-status.svelte'
12
- import Query from '../../query.svelte'
13
12
  import RefetchController from '../../refetch-controller.svelte'
14
13
  import {
15
14
  createRefetchIntervalStore,
@@ -135,23 +134,19 @@
135
134
  </div>
136
135
 
137
136
  <ApiSection
138
- title="DiscoverResources"
137
+ method="DiscoverResources"
139
138
  api={ResourceTriplets.Discovery}
139
+ queries={[discoveryQuery]}
140
140
  class="relative grow flex-col gap-4"
141
141
  >
142
- <Query
143
- query={discoveryQuery}
144
- class="h-6"
145
- >
146
- {#if discoveryQuery.data !== undefined}
147
- <ResourcesList
148
- data={discoveryQuery.data}
149
- {previews}
150
- {componentPreview}
151
- {onAddComponent}
152
- />
153
- {/if}
154
- </Query>
142
+ {#if discoveryQuery.data !== undefined}
143
+ <ResourcesList
144
+ data={discoveryQuery.data}
145
+ {previews}
146
+ {componentPreview}
147
+ {onAddComponent}
148
+ />
149
+ {/if}
155
150
  </ApiSection>
156
151
  {/snippet}
157
152
  </ConnectionStatus>
@@ -9,10 +9,9 @@
9
9
 
10
10
  import ApiSection from '../../api-section.svelte'
11
11
  import ConnectionStatus from '../../connection-status.svelte'
12
- import ErrorDisplay from '../../error.svelte'
13
- import Queries from '../../queries.svelte'
14
12
  import RefetchController from '../../refetch-controller.svelte'
15
13
  import { createRefetchIntervalStore } from '../../refetch-interval-store.svelte'
14
+ import { Section } from '../../section'
16
15
  import { ResourceTriplets } from '../../../resource-triplet'
17
16
 
18
17
  import { getEncoderPositionArgs } from './encoder-position-type'
@@ -65,30 +64,34 @@
65
64
  <div class="@container">
66
65
  <div class="grid w-full grid-cols-1 divide-y @lg:grid-cols-2 @lg:divide-x @lg:divide-y-0">
67
66
  <ApiSection
68
- title="GetPosition"
67
+ method="GetPosition"
69
68
  api={ResourceTriplets.Encoder}
70
- tooltip="Relative encoders return ticks since last zeroing. Absolute encoders return degrees."
69
+ queries={[propertiesQuery, positionQuery]}
71
70
  class="grow flex-col gap-3"
72
71
  >
73
- <Queries queries={[propertiesQuery, positionQuery]}>
74
- {#if positionQuery.data !== undefined}
75
- {@const [position, encoderPositionType] = positionQuery.data}
76
- <div class="font-roboto-mono flex flex-col gap-2 text-sm">
77
- <Position
78
- {position}
79
- {encoderPositionType}
80
- />
81
- </div>
82
- {/if}
83
- </Queries>
72
+ {#snippet tooltip()}
73
+ Relative encoders return ticks since last zeroing. Absolute encoders return degrees.
74
+ {/snippet}
75
+ {#if positionQuery.data !== undefined}
76
+ {@const [position, encoderPositionType] = positionQuery.data}
77
+ <div class="font-roboto-mono flex flex-col gap-2 text-sm">
78
+ <Position
79
+ {position}
80
+ {encoderPositionType}
81
+ />
82
+ </div>
83
+ {/if}
84
84
  </ApiSection>
85
85
 
86
86
  <ApiSection
87
87
  class="grow flex-col gap-4"
88
- title="ResetPosition"
88
+ method="ResetPosition"
89
89
  api={ResourceTriplets.Encoder}
90
- description="Set the current position as the new zero position"
90
+ mutations={[resetMutation]}
91
91
  >
92
+ {#snippet subheading()}
93
+ <Section.Text>Set the current position as the new zero position</Section.Text>
94
+ {/snippet}
92
95
  <Button
93
96
  icon="play-circle-outline"
94
97
  class="w-fit"
@@ -98,7 +101,6 @@
98
101
  >
99
102
  Execute
100
103
  </Button>
101
- <ErrorDisplay lastError={resetMutation.error} />
102
104
  </ApiSection>
103
105
  </div>
104
106
  </div>
@@ -3,7 +3,8 @@
3
3
  import { createResourceClient, createResourceQuery } from '@viamrobotics/svelte-sdk'
4
4
 
5
5
  import ApiSection from '../../api-section.svelte'
6
- import Queries from '../../queries.svelte'
6
+ import { Section } from '../../section'
7
+ import { ResourceTriplets } from '../../../resource-triplet'
7
8
 
8
9
  import { getEncoderPositionArgs } from './encoder-position-type'
9
10
  import Position from './position.svelte'
@@ -35,20 +36,22 @@
35
36
  </script>
36
37
 
37
38
  <ApiSection
38
- title="GetPosition"
39
- tooltip="Relative encoders return ticks since last zeroing. Absolute encoders return degrees."
40
- bottomText="Updates automatically"
39
+ method="GetPosition"
40
+ api={ResourceTriplets.Encoder}
41
+ queries={[propertiesQuery, positionQuery]}
41
42
  class="grow flex-col gap-4"
42
43
  >
43
- <Queries queries={[propertiesQuery, positionQuery]}>
44
- {#if positionQuery.data !== undefined}
45
- {@const [position, encoderPositionType] = positionQuery.data}
46
- <div class="font-roboto-mono flex flex-col gap-2 text-sm">
47
- <Position
48
- {position}
49
- {encoderPositionType}
50
- />
51
- </div>
52
- {/if}
53
- </Queries>
44
+ {#snippet tooltip()}
45
+ Relative encoders return ticks since last zeroing. Absolute encoders return degrees.
46
+ {/snippet}
47
+ {#if positionQuery.data !== undefined}
48
+ {@const [position, encoderPositionType] = positionQuery.data}
49
+ <div class="font-roboto-mono flex flex-col gap-2 text-sm">
50
+ <Position
51
+ {position}
52
+ {encoderPositionType}
53
+ />
54
+ </div>
55
+ {/if}
56
+ <Section.Text class="mt-auto">Updates automatically</Section.Text>
54
57
  </ApiSection>
@@ -6,12 +6,11 @@
6
6
  createResourceQuery,
7
7
  } from '@viamrobotics/svelte-sdk'
8
8
 
9
- import { apiDocsHref } from '../../../api-docs-href'
10
9
  import ApiSection from '../../api-section.svelte'
11
10
  import ConnectionStatus from '../../connection-status.svelte'
12
11
  import IsMoving from '../../is-moving.svelte'
13
- import Queries from '../../queries.svelte'
14
- import Query from '../../query.svelte'
12
+ import { Section } from '../../section'
13
+ import { useSectionErrors } from '../../section/use-section-errors.svelte'
15
14
  import StopButton from '../../stop-button.svelte'
16
15
  import { ResourceTriplets } from '../../../resource-triplet'
17
16
 
@@ -41,7 +40,10 @@
41
40
  const quickMoveMutation = createResourceMutation(client, 'moveToPosition')
42
41
  const stopMutation = createResourceMutation(client, 'stop')
43
42
 
44
- const positionHeadingID = $props.id()
43
+ const quickMoveErrors = useSectionErrors(() => ({
44
+ queries: [positionQuery],
45
+ mutations: [quickMoveMutation],
46
+ }))
45
47
  </script>
46
48
 
47
49
  <ConnectionStatus {partID}>
@@ -52,104 +54,78 @@
52
54
  <div class="flex flex-col divide-y @2xl:flex-row @2xl:divide-x @2xl:divide-y-0">
53
55
  <ApiSection
54
56
  class="grow flex-col gap-4"
55
- bottomText="Updates automatically"
56
- aria-labelledby={positionHeadingID}
57
+ method="GetPosition"
58
+ api={ResourceTriplets.Gantry}
59
+ queries={[positionQuery, lengthsQuery]}
57
60
  >
58
- <h3
59
- class="text-subtle-2 flex flex-row items-center gap-1 text-sm"
60
- id={positionHeadingID}
61
- >
62
- <a
63
- href={apiDocsHref(ResourceTriplets.Gantry, 'getPosition')}
64
- target="_blank"
65
- rel="noopener noreferrer external"
66
- class="decoration-gray-5 hover:decoration-default text-default font-mono font-semibold underline underline-offset-3"
67
- >
68
- GetPosition
69
- </a>
70
- and
71
- <a
72
- href={apiDocsHref(ResourceTriplets.Gantry, 'getLengths')}
73
- target="_blank"
74
- rel="noopener noreferrer external"
75
- class="decoration-gray-5 hover:decoration-default text-default font-mono font-semibold underline underline-offset-3"
76
- >
77
- GetLengths
78
- </a>
79
- </h3>
80
- <Queries queries={[positionQuery, lengthsQuery]}>
81
- {@const positions = positionQuery.data}
82
- {@const lengths = lengthsQuery.data ?? []}
83
- {#if positions !== undefined}
84
- <PositionAndLengths
85
- {positions}
86
- {lengths}
87
- />
88
- {/if}
89
- </Queries>
61
+ {@const positions = positionQuery.data}
62
+ {@const lengths = lengthsQuery.data ?? []}
63
+ {#if positions !== undefined}
64
+ <PositionAndLengths
65
+ {positions}
66
+ {lengths}
67
+ />
68
+ {/if}
69
+ <Section.Text class="mt-auto">Updates automatically</Section.Text>
90
70
  </ApiSection>
91
71
  <ApiSection
92
72
  class="grow flex-col gap-4"
93
- title="MoveToPosition"
73
+ method="MoveToPosition"
94
74
  api={ResourceTriplets.Gantry}
75
+ queries={[positionQuery]}
76
+ mutations={[moveMutation]}
95
77
  >
96
- <Query query={positionQuery}>
97
- {@const positions = positionQuery.data}
98
- {#if positions !== undefined}
99
- <MoveToPosition
100
- {positions}
101
- lastError={moveMutation.error}
102
- moveTo={(newPos: number[], speeds: number[]) => {
103
- moveMutation.mutate([newPos, speeds], {})
104
- }}
105
- />
106
- {/if}
107
- </Query>
78
+ {@const positions = positionQuery.data}
79
+ {#if positions !== undefined}
80
+ <MoveToPosition
81
+ {positions}
82
+ moveTo={(newPos: number[], speeds: number[]) => {
83
+ moveMutation.mutate([newPos, speeds], {})
84
+ }}
85
+ />
86
+ {/if}
108
87
  </ApiSection>
109
88
  <div class="flex grow flex-col divide-y">
110
- <ApiSection
89
+ <Section
90
+ errorReporter={quickMoveErrors}
111
91
  class="grow flex-col gap-4"
112
- title="Quick move"
113
- bottomText="Press a button to execute"
114
92
  >
115
- <Query
116
- query={positionQuery}
117
- class="h-6"
118
- >
93
+ <div class="flex flex-col gap-0.5">
94
+ <Section.Heading>
95
+ Quick move
96
+ {#snippet aside()}
97
+ <Section.Errors errors={quickMoveErrors.errors} />
98
+ {/snippet}
99
+ </Section.Heading>
100
+ </div>
101
+ <Section.Body isLoading={quickMoveErrors.isLoading}>
119
102
  {@const positions = positionQuery.data}
120
103
  {#if positions !== undefined}
121
104
  <QuickMove
122
105
  {positions}
123
- lastError={quickMoveMutation.error}
124
106
  moveTo={(newPos: number[], speeds: number[]) => {
125
107
  quickMoveMutation.mutate([newPos, speeds], {})
126
108
  }}
127
109
  />
128
110
  {/if}
129
- </Query>
130
- </ApiSection>
131
- <ApiSection
132
- class="grow flex-col gap-4"
133
- title="Home"
134
- api={ResourceTriplets.Gantry}
135
- description="Run the homing sequence"
136
- >
137
- <Home
138
- {partID}
139
- {resourceName}
140
- />
141
- </ApiSection>
111
+ <Section.Text class="mt-auto">Press a button to execute</Section.Text>
112
+ </Section.Body>
113
+ </Section>
114
+ <Home
115
+ {partID}
116
+ {resourceName}
117
+ />
142
118
  </div>
143
119
  </div>
144
120
  </div>
145
121
  <div class="flex flex-col divide-y @4xl:ml-auto @4xl:w-full @4xl:max-w-40">
146
122
  <ApiSection
147
123
  class="grow flex-col gap-4"
148
- title="Stop"
124
+ method="Stop"
149
125
  api={ResourceTriplets.Gantry}
126
+ mutations={[stopMutation]}
150
127
  >
151
128
  <StopButton
152
- error={stopMutation.error}
153
129
  onStop={() => {
154
130
  stopMutation.mutate([])
155
131
  }}
@@ -3,7 +3,8 @@
3
3
  import { createResourceClient, createResourceQuery } from '@viamrobotics/svelte-sdk'
4
4
 
5
5
  import ApiSection from '../../api-section.svelte'
6
- import Queries from '../../queries.svelte'
6
+ import { Section } from '../../section'
7
+ import { ResourceTriplets } from '../../../resource-triplet'
7
8
 
8
9
  import PositionAndLengths from './position-and-lengths.svelte'
9
10
 
@@ -26,18 +27,18 @@
26
27
  </script>
27
28
 
28
29
  <ApiSection
29
- title="GetPosition"
30
- bottomText="Updates automatically"
30
+ method="GetPosition"
31
+ api={ResourceTriplets.Gantry}
31
32
  class="grow flex-col gap-4"
33
+ queries={[positionQuery, lengthsQuery]}
32
34
  >
33
- <Queries queries={[positionQuery, lengthsQuery]}>
34
- {@const positions = positionQuery.data}
35
- {@const lengths = lengthsQuery.data ?? []}
36
- {#if positions !== undefined}
37
- <PositionAndLengths
38
- {positions}
39
- {lengths}
40
- />
41
- {/if}
42
- </Queries>
35
+ {@const positions = positionQuery.data}
36
+ {@const lengths = lengthsQuery.data ?? []}
37
+ {#if positions !== undefined}
38
+ <PositionAndLengths
39
+ {positions}
40
+ {lengths}
41
+ />
42
+ {/if}
43
+ <Section.Text class="mt-auto">Updates automatically</Section.Text>
43
44
  </ApiSection>
@@ -3,7 +3,9 @@
3
3
  import { GantryClient } from '@viamrobotics/sdk'
4
4
  import { createResourceClient, createResourceMutation } from '@viamrobotics/svelte-sdk'
5
5
 
6
- import ErrorDisplay from '../../error.svelte'
6
+ import ApiSection from '../../api-section.svelte'
7
+ import { Section } from '../../section'
8
+ import { ResourceTriplets } from '../../../resource-triplet'
7
9
 
8
10
  interface Props {
9
11
  partID: string
@@ -21,13 +23,22 @@
21
23
  const homeMutation = createResourceMutation(client, 'home')
22
24
  </script>
23
25
 
24
- <Button
25
- class="w-fit"
26
- icon="play-circle-outline"
27
- onclick={() => {
28
- homeMutation.mutate([], {})
29
- }}
26
+ <ApiSection
27
+ class="grow flex-col gap-4"
28
+ method="Home"
29
+ api={ResourceTriplets.Gantry}
30
+ mutations={[homeMutation]}
30
31
  >
31
- Execute
32
- </Button>
33
- <ErrorDisplay lastError={homeMutation.error} />
32
+ {#snippet subheading()}
33
+ <Section.Text>Run the homing sequence</Section.Text>
34
+ {/snippet}
35
+ <Button
36
+ class="w-fit"
37
+ icon="play-circle-outline"
38
+ onclick={() => {
39
+ homeMutation.mutate([], {})
40
+ }}
41
+ >
42
+ Execute
43
+ </Button>
44
+ </ApiSection>
@@ -7,6 +7,7 @@
7
7
  } from '@viamrobotics/svelte-sdk'
8
8
 
9
9
  import Query from '../../query.svelte'
10
+ import { Section } from '../../section'
10
11
 
11
12
  import MoveToPosition from './move-to-position.svelte'
12
13
 
@@ -34,10 +35,10 @@
34
35
  {#if positions !== undefined}
35
36
  <MoveToPosition
36
37
  {positions}
37
- lastError={moveMutation.error}
38
38
  moveTo={(newPos: number[], speeds: number[]) => {
39
39
  moveMutation.mutate([newPos, speeds], {})
40
40
  }}
41
41
  />
42
42
  {/if}
43
43
  </Query>
44
+ <Section.Error error={moveMutation.error} />
@@ -2,7 +2,6 @@
2
2
  import { Button, Icon, NumericInput, Tooltip } from '@viamrobotics/prime-core'
3
3
  import { isEqual, zip } from 'lodash-es'
4
4
 
5
- import ErrorDisplay from '../../error.svelte'
6
5
  import Table from '../../table.svelte'
7
6
  import { numberValueFromEvent } from '../../../event-handlers'
8
7
 
@@ -11,10 +10,9 @@
11
10
  interface Props {
12
11
  positions: number[]
13
12
  moveTo: (newPos: number[], speeds: number[]) => void
14
- lastError: Error | null
15
13
  }
16
14
 
17
- const { positions, moveTo, lastError }: Props = $props()
15
+ const { positions, moveTo }: Props = $props()
18
16
 
19
17
  let desiredSpeeds: number[] = $state([])
20
18
 
@@ -122,5 +120,4 @@
122
120
  >
123
121
  Execute
124
122
  </Button>
125
- <ErrorDisplay {lastError} />
126
123
  </div>
@@ -1,7 +1,6 @@
1
1
  interface Props {
2
2
  positions: number[];
3
3
  moveTo: (newPos: number[], speeds: number[]) => void;
4
- lastError: Error | null;
5
4
  }
6
5
  declare const MoveToPosition: import("svelte").Component<Props, {}, "">;
7
6
  type MoveToPosition = ReturnType<typeof MoveToPosition>;