@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
@@ -1,68 +1,76 @@
1
1
  <script lang="ts">
2
2
  import type { Snippet } from 'svelte'
3
- import type { ClassValue, HTMLAttributes } from 'svelte/elements'
3
+ import type { HTMLAttributes } from 'svelte/elements'
4
4
 
5
5
  import type { ResourceTriplet } from '../resource-triplet'
6
6
 
7
- import Boundary from './boundary.svelte'
8
- import SectionTitle from './section-title.svelte'
7
+ import { Section } from './section'
8
+ import {
9
+ type SectionMutation,
10
+ type SectionQuery,
11
+ useSectionErrors,
12
+ } from './section/use-section-errors.svelte'
9
13
 
10
- interface Props extends HTMLAttributes<HTMLElement> {
11
- title?: string | undefined
12
- tooltip?: string | undefined
13
- description?: string | undefined
14
- bottomText?: string | undefined
15
- /** RDK API string; presence renders the title as a linked monospace method name */
16
- api?: ResourceTriplet | undefined
17
- class?: ClassValue
18
- children?: Snippet
19
- }
14
+ /**
15
+ * What the section reads or writes. At least one list is required, so every section's errors
16
+ * reach its indicator. Query errors are distinct per query, mutation errors per mutation.
17
+ */
18
+ type Sources =
19
+ | { queries: SectionQuery[]; mutations?: SectionMutation[] }
20
+ | { queries?: SectionQuery[]; mutations: SectionMutation[] }
21
+
22
+ type Props = HTMLAttributes<HTMLElement> &
23
+ Sources & {
24
+ /** RDK method name in PascalCase. */
25
+ method: string
26
+ api: ResourceTriplet
27
+ subheading?: Snippet
28
+ tooltip?: Snippet
29
+ /**
30
+ * @deprecated Exists only for the migration. Removed once every section passes it.
31
+ */
32
+ skeleton?: boolean
33
+ }
20
34
 
21
35
  const {
22
- title,
23
- tooltip,
24
- description,
25
- bottomText,
36
+ method,
26
37
  api,
27
- class: className = '',
38
+ queries = [],
39
+ mutations = [],
40
+ subheading,
41
+ tooltip,
42
+ skeleton = false,
28
43
  children,
29
44
  ...rest
30
45
  }: Props = $props()
31
46
 
32
- const headingID = $props.id()
47
+ const sectionErrors = useSectionErrors(() => ({ queries, mutations }))
33
48
  </script>
34
49
 
35
- <section
36
- class={['flex p-4', className]}
37
- aria-labelledby={title ? headingID : undefined}
50
+ <Section
51
+ errorReporter={sectionErrors}
38
52
  {...rest}
39
53
  >
40
- {#if title}
41
- <div class="flex flex-col gap-0.5">
42
- {#if api}
43
- <SectionTitle
44
- {title}
45
- {tooltip}
46
- {api}
47
- headingId={headingID}
48
- />
49
- {:else}
50
- <h3
51
- class="flex flex-row items-center gap-1 text-sm font-semibold"
52
- id={headingID}
53
- >
54
- {title}
55
- </h3>
56
- {/if}
57
- {#if description}
58
- <p class="text-subtle-2 text-xs">{description}</p>
59
- {/if}
60
- </div>
61
- {/if}
62
-
63
- <Boundary {children} />
54
+ <div class="flex flex-col gap-0.5">
55
+ <Section.Heading>
56
+ <Section.Method
57
+ {method}
58
+ {api}
59
+ />
60
+ {#snippet aside()}
61
+ <Section.Errors errors={sectionErrors.errors} />
62
+ {#if tooltip}
63
+ <Section.Tooltip>{@render tooltip()}</Section.Tooltip>
64
+ {/if}
65
+ {/snippet}
66
+ </Section.Heading>
67
+ {@render subheading?.()}
68
+ </div>
64
69
 
65
- {#if bottomText}
66
- <p class="text-subtle-2 mt-auto text-xs">{bottomText}</p>
67
- {/if}
68
- </section>
70
+ <Section.Body
71
+ isLoading={sectionErrors.isLoading}
72
+ {skeleton}
73
+ >
74
+ {@render children?.()}
75
+ </Section.Body>
76
+ </Section>
@@ -1,16 +1,29 @@
1
1
  import type { Snippet } from 'svelte';
2
- import type { ClassValue, HTMLAttributes } from 'svelte/elements';
2
+ import type { HTMLAttributes } from 'svelte/elements';
3
3
  import type { ResourceTriplet } from '../resource-triplet';
4
- interface Props extends HTMLAttributes<HTMLElement> {
5
- title?: string | undefined;
6
- tooltip?: string | undefined;
7
- description?: string | undefined;
8
- bottomText?: string | undefined;
9
- /** RDK API string; presence renders the title as a linked monospace method name */
10
- api?: ResourceTriplet | undefined;
11
- class?: ClassValue;
12
- children?: Snippet;
13
- }
4
+ import { type SectionMutation, type SectionQuery } from './section/use-section-errors.svelte';
5
+ /**
6
+ * What the section reads or writes. At least one list is required, so every section's errors
7
+ * reach its indicator. Query errors are distinct per query, mutation errors per mutation.
8
+ */
9
+ type Sources = {
10
+ queries: SectionQuery[];
11
+ mutations?: SectionMutation[];
12
+ } | {
13
+ queries?: SectionQuery[];
14
+ mutations: SectionMutation[];
15
+ };
16
+ type Props = HTMLAttributes<HTMLElement> & Sources & {
17
+ /** RDK method name in PascalCase. */
18
+ method: string;
19
+ api: ResourceTriplet;
20
+ subheading?: Snippet;
21
+ tooltip?: Snippet;
22
+ /**
23
+ * @deprecated Exists only for the migration. Removed once every section passes it.
24
+ */
25
+ skeleton?: boolean;
26
+ };
14
27
  declare const ApiSection: import("svelte").Component<Props, {}, "">;
15
28
  type ApiSection = ReturnType<typeof ApiSection>;
16
29
  export default ApiSection;
@@ -1,3 +1,9 @@
1
+ <!--
2
+ @component
3
+
4
+ @deprecated It sized the `Queries` wrapper and goes with it. A section sets its own layout class. Kept for the sectionless files until their resource PRs.
5
+ -->
6
+
1
7
  <script lang="ts">
2
8
  import type { Snippet } from 'svelte'
3
9
  import type { ClassValue } from 'svelte/elements'
@@ -5,6 +5,7 @@ interface Props {
5
5
  class?: ClassValue;
6
6
  children?: Snippet;
7
7
  }
8
+ /** @deprecated It sized the `Queries` wrapper and goes with it. A section sets its own layout class. Kept for the sectionless files until their resource PRs. */
8
9
  declare const ContentRect: import("svelte").Component<Props, {}, "">;
9
10
  type ContentRect = ReturnType<typeof ContentRect>;
10
11
  export default ContentRect;
@@ -1,3 +1,12 @@
1
+ <!--
2
+ @component
3
+
4
+ @deprecated Errors show in the section heading's indicator. Pass the mutation to `ApiSection` as
5
+ `mutations` or to a `Section` control's `useSectionErrors` call. In a form that cannot reach its
6
+ section, use `Section.Error`, which reports to the indicator and falls back to an inline line
7
+ outside a section. Kept for the sectionless files until their resource PRs.
8
+ -->
9
+
1
10
  <script lang="ts">
2
11
  import type { ClassValue } from 'svelte/elements'
3
12
 
@@ -4,6 +4,12 @@ interface Props {
4
4
  id?: string;
5
5
  class?: ClassValue;
6
6
  }
7
+ /**
8
+ * @deprecated Errors show in the section heading's indicator. Pass the mutation to `ApiSection` as
9
+ * `mutations` or to a `Section` control's `useSectionErrors` call. In a form that cannot reach its
10
+ * section, use `Section.Error`, which reports to the indicator and falls back to an inline line
11
+ * outside a section. Kept for the sectionless files until their resource PRs.
12
+ */
7
13
  declare const Error: import("svelte").Component<Props, {}, "">;
8
14
  type Error = ReturnType<typeof Error>;
9
15
  export default Error;
@@ -36,11 +36,11 @@ export { default as GantryHomeWidget } from './widgets/gantry/home.svelte';
36
36
  export { default as GantryMoveToPositionWidget } from './widgets/gantry/move-to-position-widget.svelte';
37
37
  export { default as GantryQuickMoveWidget } from './widgets/gantry/quick-move-widget.svelte';
38
38
  export { default as GenericWidget } from './widgets/generic/generic.svelte';
39
- export { default as GripperGrabWidget } from './widgets/gripper/grab.svelte';
39
+ export { default as GripperGrabWidget } from './widgets/gripper/grab-widget.svelte';
40
40
  export { default as GripperWidget } from './widgets/gripper/gripper.svelte';
41
41
  export { default as GripperIsHoldingSomethingWidget } from './widgets/gripper/is-holding-something.svelte';
42
42
  export { default as GripperIsMovingWidget } from './widgets/gripper/is-moving-widget.svelte';
43
- export { default as GripperOpenWidget } from './widgets/gripper/open.svelte';
43
+ export { default as GripperOpenWidget } from './widgets/gripper/open-widget.svelte';
44
44
  export { default as InputControllerWidget } from './widgets/input-controller/input-controller.svelte';
45
45
  export { default as MLModelServiceWidget } from './widgets/ml-model-service/ml-model-service.svelte';
46
46
  export { default as MotionServiceWidget } from './widgets/motion/motion.svelte';
@@ -79,3 +79,5 @@ export { default as VisionServiceWidget } from './widgets/vision-service/vision-
79
79
  export { default as RefetchController } from './refetch-controller.svelte';
80
80
  export { NavigationMap, NavigationTab, type NavigationTabType, type Shapes, type CapsuleGeometry, type SphereGeometry, type BoxGeometry, type Geometry, type Obstacle, type Path, } from './navigation-map';
81
81
  export { MapLibre, MapLibreMarker, CenterControls, FollowControls, NavigationControls, SatelliteControls, DirectionalMarker, LngLatInput, MapProviders, type MapProvider, GeoPose, Waypoint, useMapLibre, useMapLibreEvent, useMapLibreThreeRaycast, useMapLibreThreeRenderer, lngLatToMercator, mercatorToCartesian, lngLatToCartesian, cartesianToMercator, cartesianToLngLat, } from './maplibre';
82
+ export { default as CustomControlWidget } from './widgets/custom-control/custom-control.svelte';
83
+ export { CUSTOM_CONTROL_COMMAND, CUSTOM_CONTROL_CSP, type CustomControlArtifact, loadCustomControl, prepareArtifact, } from './widgets/custom-control/custom-control.ts';
@@ -35,11 +35,11 @@ export { default as GantryHomeWidget } from './widgets/gantry/home.svelte';
35
35
  export { default as GantryMoveToPositionWidget } from './widgets/gantry/move-to-position-widget.svelte';
36
36
  export { default as GantryQuickMoveWidget } from './widgets/gantry/quick-move-widget.svelte';
37
37
  export { default as GenericWidget } from './widgets/generic/generic.svelte';
38
- export { default as GripperGrabWidget } from './widgets/gripper/grab.svelte';
38
+ export { default as GripperGrabWidget } from './widgets/gripper/grab-widget.svelte';
39
39
  export { default as GripperWidget } from './widgets/gripper/gripper.svelte';
40
40
  export { default as GripperIsHoldingSomethingWidget } from './widgets/gripper/is-holding-something.svelte';
41
41
  export { default as GripperIsMovingWidget } from './widgets/gripper/is-moving-widget.svelte';
42
- export { default as GripperOpenWidget } from './widgets/gripper/open.svelte';
42
+ export { default as GripperOpenWidget } from './widgets/gripper/open-widget.svelte';
43
43
  export { default as InputControllerWidget } from './widgets/input-controller/input-controller.svelte';
44
44
  export { default as MLModelServiceWidget } from './widgets/ml-model-service/ml-model-service.svelte';
45
45
  export { default as MotionServiceWidget } from './widgets/motion/motion.svelte';
@@ -78,3 +78,5 @@ export { default as VisionServiceWidget } from './widgets/vision-service/vision-
78
78
  export { default as RefetchController } from './refetch-controller.svelte';
79
79
  export { NavigationMap, NavigationTab, } from './navigation-map';
80
80
  export { MapLibre, MapLibreMarker, CenterControls, FollowControls, NavigationControls, SatelliteControls, DirectionalMarker, LngLatInput, MapProviders, GeoPose, Waypoint, useMapLibre, useMapLibreEvent, useMapLibreThreeRaycast, useMapLibreThreeRenderer, lngLatToMercator, mercatorToCartesian, lngLatToCartesian, cartesianToMercator, cartesianToLngLat, } from './maplibre';
81
+ export { default as CustomControlWidget } from './widgets/custom-control/custom-control.svelte';
82
+ export { CUSTOM_CONTROL_COMMAND, CUSTOM_CONTROL_CSP, loadCustomControl, prepareArtifact, } from "./widgets/custom-control/custom-control.js";
@@ -1,48 +1,43 @@
1
1
  <script lang="ts">
2
- import type {
3
- Arm,
4
- ArmClient,
5
- Base,
6
- BaseClient,
7
- Gantry,
8
- GantryClient,
9
- Gripper,
10
- GripperClient,
11
- Motor,
12
- MotorClient,
13
- Servo,
14
- ServoClient,
15
- } from '@viamrobotics/sdk'
16
- import type { Snippet } from 'svelte'
2
+ import type * as SDK from '@viamrobotics/sdk'
3
+ import type { HTMLAttributes } from 'svelte/elements'
17
4
 
18
5
  import { createResourceClient, createResourceQuery } from '@viamrobotics/svelte-sdk'
19
6
 
20
7
  import type { ResourceTriplet } from '../resource-triplet'
21
8
 
22
9
  import ApiSection from './api-section.svelte'
23
- import Query from './query.svelte'
10
+ import { Section } from './section'
24
11
  import StatusPill from './status-pill.svelte'
25
12
 
26
13
  type Client =
27
- | typeof ArmClient
28
- | typeof BaseClient
29
- | typeof GantryClient
30
- | typeof GripperClient
31
- | typeof MotorClient
32
- | typeof ServoClient
14
+ | typeof SDK.ArmClient
15
+ | typeof SDK.BaseClient
16
+ | typeof SDK.GantryClient
17
+ | typeof SDK.GripperClient
18
+ | typeof SDK.MotorClient
19
+ | typeof SDK.ServoClient
33
20
 
34
- interface Props {
21
+ type Resource = SDK.Arm | SDK.Base | SDK.Gantry | SDK.Gripper | SDK.Motor | SDK.Servo
22
+
23
+ interface Props extends HTMLAttributes<HTMLElement> {
35
24
  client: Client
36
25
  partID: string
37
26
  resourceName: string
38
27
  api: ResourceTriplet
39
- children?: Snippet
40
28
  }
41
29
 
42
- const { client: clientClass, partID, resourceName, api, children }: Props = $props()
30
+ const {
31
+ client: clientClass,
32
+ partID,
33
+ resourceName,
34
+ api,
35
+ children,
36
+ class: className,
37
+ }: Props = $props()
43
38
 
44
39
  const client = $derived(
45
- createResourceClient<Arm | Base | Gantry | Gripper | Motor | Servo>(
40
+ createResourceClient<Resource>(
46
41
  clientClass,
47
42
  () => partID,
48
43
  () => resourceName
@@ -53,15 +48,12 @@
53
48
  </script>
54
49
 
55
50
  <ApiSection
56
- title="IsMoving"
51
+ class={['grow flex-col gap-4', className]}
52
+ method="IsMoving"
53
+ queries={[query]}
57
54
  {api}
58
- bottomText="Updates automatically"
59
- class="grow flex-col gap-4"
60
55
  >
61
- <Query {query}>
62
- <StatusPill isActive={query.data ?? false} />
63
- </Query>
64
-
65
- <!-- slot for additional actuation info Ex: Motor's IsPowered & GetPosition -->
56
+ <StatusPill isActive={query.data ?? false} />
66
57
  {@render children?.()}
58
+ <Section.Text class="mt-auto">Updates automatically</Section.Text>
67
59
  </ApiSection>
@@ -1,13 +1,12 @@
1
- import type { ArmClient, BaseClient, GantryClient, GripperClient, MotorClient, ServoClient } from '@viamrobotics/sdk';
2
- import type { Snippet } from 'svelte';
1
+ import type * as SDK from '@viamrobotics/sdk';
2
+ import type { HTMLAttributes } from 'svelte/elements';
3
3
  import type { ResourceTriplet } from '../resource-triplet';
4
- type Client = typeof ArmClient | typeof BaseClient | typeof GantryClient | typeof GripperClient | typeof MotorClient | typeof ServoClient;
5
- interface Props {
4
+ type Client = typeof SDK.ArmClient | typeof SDK.BaseClient | typeof SDK.GantryClient | typeof SDK.GripperClient | typeof SDK.MotorClient | typeof SDK.ServoClient;
5
+ interface Props extends HTMLAttributes<HTMLElement> {
6
6
  client: Client;
7
7
  partID: string;
8
8
  resourceName: string;
9
9
  api: ResourceTriplet;
10
- children?: Snippet;
11
10
  }
12
11
  declare const IsMoving: import("svelte").Component<Props, {}, "">;
13
12
  type IsMoving = ReturnType<typeof IsMoving>;
@@ -1,4 +1,5 @@
1
1
  <div
2
2
  role="progressbar"
3
+ aria-label="Loading"
3
4
  class="bg-medium h-full w-full animate-pulse"
4
5
  ></div>
@@ -1,3 +1,10 @@
1
+ <!--
2
+ @component
3
+
4
+ @deprecated A section owns its async state now. Pass the queries to `ApiSection` as `queries`, or to a
5
+ `Section` control's `useSectionErrors` call, and guard `query.data` in the children. Kept for the sectionless files until their resource PRs.
6
+ -->
7
+
1
8
  <script lang="ts">
2
9
  import type { QueryObserverResult } from '@tanstack/svelte-query'
3
10
  import type { Snippet } from 'svelte'
@@ -8,6 +8,10 @@ interface Props {
8
8
  data: unknown[];
9
9
  }]>;
10
10
  }
11
+ /**
12
+ * @deprecated A section owns its async state now. Pass the queries to `ApiSection` as `queries`, or to a
13
+ * `Section` control's `useSectionErrors` call, and guard `query.data` in the children. Kept for the sectionless files until their resource PRs.
14
+ */
11
15
  declare const Queries: import("svelte").Component<Props, {}, "">;
12
16
  type Queries = ReturnType<typeof Queries>;
13
17
  export default Queries;
@@ -1,3 +1,10 @@
1
+ <!--
2
+ @component
3
+
4
+ @deprecated A section owns its async state now. Pass the query to `ApiSection` as `queries`, or to a
5
+ `Section` control's `useSectionErrors` call, and guard `query.data` in the children. Kept for the sectionless files until their resource PRs.
6
+ -->
7
+
1
8
  <script lang="ts">
2
9
  import type { QueryObserverResult } from '@tanstack/svelte-query'
3
10
  import type { Snippet } from 'svelte'
@@ -6,6 +6,10 @@ interface Props {
6
6
  class?: ClassValue;
7
7
  children?: Snippet;
8
8
  }
9
+ /**
10
+ * @deprecated A section owns its async state now. Pass the query to `ApiSection` as `queries`, or to a
11
+ * `Section` control's `useSectionErrors` call, and guard `query.data` in the children. Kept for the sectionless files until their resource PRs.
12
+ */
9
13
  declare const Query: import("svelte").Component<Props, {}, "">;
10
14
  type Query = ReturnType<typeof Query>;
11
15
  export default Query;
@@ -1,4 +1,5 @@
1
1
  import SectionBody from './section-body.svelte';
2
+ import SectionError from './section-error.svelte';
2
3
  import SectionErrors from './section-errors.svelte';
3
4
  import SectionHeading from './section-heading.svelte';
4
5
  import SectionMethod from './section-method.svelte';
@@ -10,6 +11,7 @@ export { useSectionLoading } from './section-loading';
10
11
  export { dedupeErrors, useSectionErrors, type SectionMutation, type SectionQuery, type SectionSources, } from './use-section-errors.svelte';
11
12
  export declare const Section: typeof Root & {
12
13
  Body: typeof SectionBody;
14
+ Error: typeof SectionError;
13
15
  Errors: typeof SectionErrors;
14
16
  Heading: typeof SectionHeading;
15
17
  Method: typeof SectionMethod;
@@ -1,4 +1,5 @@
1
1
  import SectionBody from './section-body.svelte';
2
+ import SectionError from './section-error.svelte';
2
3
  import SectionErrors from './section-errors.svelte';
3
4
  import SectionHeading from './section-heading.svelte';
4
5
  import SectionMethod from './section-method.svelte';
@@ -10,6 +11,7 @@ export { useSectionLoading } from './section-loading';
10
11
  export { dedupeErrors, useSectionErrors, } from './use-section-errors.svelte';
11
12
  export const Section = Object.assign(Root, {
12
13
  Body: SectionBody,
14
+ Error: SectionError,
13
15
  Errors: SectionErrors,
14
16
  Heading: SectionHeading,
15
17
  Method: SectionMethod,
@@ -0,0 +1,8 @@
1
+ /** Lets a part inside a section add an error to the section's indicator. */
2
+ export interface SectionErrorReporter {
3
+ /** Adds the error `getError` returns to the section's errors. Returns a function that removes it. */
4
+ report: (getError: () => Error | null) => () => void;
5
+ }
6
+ export declare const provideSectionErrorReporter: (getReporter: () => SectionErrorReporter | undefined) => void;
7
+ /** The enclosing section's reporter, or undefined outside a section that shows errors. */
8
+ export declare const useSectionErrorReporter: () => (() => SectionErrorReporter | undefined) | undefined;
@@ -0,0 +1,7 @@
1
+ import { getContext, setContext } from 'svelte';
2
+ const SECTION_ERROR_REPORTER_KEY = Symbol('section-error-reporter');
3
+ export const provideSectionErrorReporter = (getReporter) => {
4
+ setContext(SECTION_ERROR_REPORTER_KEY, getReporter);
5
+ };
6
+ /** The enclosing section's reporter, or undefined outside a section that shows errors. */
7
+ export const useSectionErrorReporter = () => getContext(SECTION_ERROR_REPORTER_KEY);
@@ -0,0 +1,36 @@
1
+ <script lang="ts">
2
+ import type { ClassValue } from 'svelte/elements'
3
+
4
+ import { untrack } from 'svelte'
5
+
6
+ import ErrorDisplay from '../error.svelte'
7
+ import { useSectionErrorReporter } from './section-error-reporter'
8
+
9
+ interface Props {
10
+ error: Error | null | undefined
11
+ /** Classes for the inline line rendered outside a section. */
12
+ class?: ClassValue
13
+ }
14
+
15
+ const { error, class: className }: Props = $props()
16
+
17
+ const getReporter = useSectionErrorReporter()
18
+ const reporter = $derived(getReporter?.())
19
+
20
+ $effect(() => {
21
+ const current = reporter
22
+ // Registering writes the section's error set, so it must not subscribe this effect to it.
23
+ return untrack(() => current?.report(() => error ?? null))
24
+ })
25
+ </script>
26
+
27
+ <!--
28
+ Adds `error` to the enclosing section's indicator. Outside a section that shows errors, such as
29
+ a form rendered on its own, it falls back to an inline error line.
30
+ -->
31
+ {#if !reporter}
32
+ <ErrorDisplay
33
+ lastError={error}
34
+ class={className}
35
+ />
36
+ {/if}
@@ -0,0 +1,9 @@
1
+ import type { ClassValue } from 'svelte/elements';
2
+ interface Props {
3
+ error: Error | null | undefined;
4
+ /** Classes for the inline line rendered outside a section. */
5
+ class?: ClassValue;
6
+ }
7
+ declare const SectionError: import("svelte").Component<Props, {}, "">;
8
+ type SectionError = ReturnType<typeof SectionError>;
9
+ export default SectionError;