@arkitektio/bsx 2.3.0 → 4.0.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.
Files changed (84) hide show
  1. package/dist/bsx/language.d.ts.map +1 -1
  2. package/dist/bsx/language.js +4 -3
  3. package/dist/bsx/language.js.map +1 -1
  4. package/dist/bsx/references.d.ts +4 -2
  5. package/dist/bsx/references.d.ts.map +1 -1
  6. package/dist/bsx/references.js +34 -6
  7. package/dist/bsx/references.js.map +1 -1
  8. package/dist/catalogs/index.d.ts +27 -14
  9. package/dist/catalogs/index.d.ts.map +1 -1
  10. package/dist/catalogs/parts/index.d.ts +16 -3
  11. package/dist/catalogs/parts/index.d.ts.map +1 -1
  12. package/dist/catalogs/parts/run.d.ts +44 -4
  13. package/dist/catalogs/parts/run.d.ts.map +1 -1
  14. package/dist/catalogs/parts/run.js +33 -19
  15. package/dist/catalogs/parts/run.js.map +1 -1
  16. package/dist/catalogs/parts/scene.js +7 -7
  17. package/dist/catalogs/parts/scene.js.map +1 -1
  18. package/dist/catalogs/scene.d.ts +27 -14
  19. package/dist/catalogs/scene.d.ts.map +1 -1
  20. package/dist/catalogs/scene.js +3 -3
  21. package/dist/catalogs/scene.js.map +1 -1
  22. package/dist/ports.d.ts +0 -1
  23. package/dist/ports.d.ts.map +1 -1
  24. package/dist/ports.js +1 -2
  25. package/dist/ports.js.map +1 -1
  26. package/dist/renderer/bloks/run/components.d.ts +15 -2
  27. package/dist/renderer/bloks/run/components.d.ts.map +1 -1
  28. package/dist/renderer/bloks/run/components.js +114 -43
  29. package/dist/renderer/bloks/run/components.js.map +1 -1
  30. package/dist/renderer/bloks/run/host.d.ts +27 -8
  31. package/dist/renderer/bloks/run/host.d.ts.map +1 -1
  32. package/dist/renderer/bloks/run/host.js +8 -4
  33. package/dist/renderer/bloks/run/host.js.map +1 -1
  34. package/dist/renderer/bloks/run/index.d.ts +1 -1
  35. package/dist/renderer/bloks/run/index.d.ts.map +1 -1
  36. package/dist/renderer/bloks/run/index.js +1 -1
  37. package/dist/renderer/bloks/run/index.js.map +1 -1
  38. package/dist/renderer/bloks/run/math.d.ts +3 -20
  39. package/dist/renderer/bloks/run/math.d.ts.map +1 -1
  40. package/dist/renderer/bloks/run/math.js +4 -15
  41. package/dist/renderer/bloks/run/math.js.map +1 -1
  42. package/dist/renderer/bloks/scene/Scene.d.ts +16 -2
  43. package/dist/renderer/bloks/scene/Scene.d.ts.map +1 -1
  44. package/dist/renderer/bloks/scene/Scene.js +11 -3
  45. package/dist/renderer/bloks/scene/Scene.js.map +1 -1
  46. package/dist/scene.js +2 -2
  47. package/dist/scene.js.map +1 -1
  48. package/dist/spec/bsx_v2.json +277 -62
  49. package/dist/spec/catalogs/scene@1.json +93 -41
  50. package/dist/spec/catalogs/scene@1.json.js +93 -41
  51. package/dist/spec/catalogs.js +1 -1
  52. package/dist/spec/catalogs.js.map +1 -1
  53. package/dist/spec/vocabulary.d.ts +1 -1
  54. package/dist/spec/vocabulary.d.ts.map +1 -1
  55. package/dist/spec/vocabulary.js +1 -1
  56. package/dist/spec/vocabulary.js.map +1 -1
  57. package/dist/spec/vocabulary.json +4 -4
  58. package/dist/spec/vocabulary.json.js +4 -4
  59. package/package.json +1 -6
  60. package/src/bsx/language.test.ts +1 -0
  61. package/src/bsx/language.ts +4 -3
  62. package/src/bsx/references.ts +42 -7
  63. package/src/catalogs/parts/run.ts +39 -19
  64. package/src/catalogs/parts/scene.ts +7 -7
  65. package/src/catalogs/scene.ts +3 -3
  66. package/src/ports.ts +1 -2
  67. package/src/renderer/bloks/run/components.tsx +227 -103
  68. package/src/renderer/bloks/run/host.tsx +38 -12
  69. package/src/renderer/bloks/run/index.ts +1 -1
  70. package/src/renderer/bloks/run/math.test.ts +1 -24
  71. package/src/renderer/bloks/run/math.ts +5 -33
  72. package/src/renderer/bloks/run/run.test.tsx +44 -38
  73. package/src/renderer/bloks/scene/Scene.tsx +22 -4
  74. package/src/scene.ts +2 -2
  75. package/src/spec/bsx_v2.json +277 -62
  76. package/src/spec/catalogs/scene@1.json +93 -41
  77. package/src/spec/catalogs.ts +1 -1
  78. package/src/spec/vocabulary.json +4 -4
  79. package/src/spec/vocabulary.ts +2 -2
  80. package/dist/ports/engine/ActionDescription.d.ts +0 -27
  81. package/dist/ports/engine/ActionDescription.d.ts.map +0 -1
  82. package/dist/ports/engine/ActionDescription.js +0 -61
  83. package/dist/ports/engine/ActionDescription.js.map +0 -1
  84. package/src/ports/engine/ActionDescription.tsx +0 -78
@@ -27,14 +27,17 @@ const arm: BlokRunAgent = {id: 'a1', name: 'Arm'};
27
27
  const scope: BlokRunAgent = {id: 'a3', name: 'Scope'};
28
28
  const binding: Record<string, BlokRunAgent[]> = {robot: [arm], frame: [scope]};
29
29
  const run: BlokRunHost = {agentsFor: key => binding[key] ?? [], renderAsk: () => null};
30
- /** The arm stands 1 m along x; the scope is not placed in this space, or 3 m along x. */
31
- const spaceOf = (scopePlaced: boolean): BlokSpaceHost => ({
32
- placementOf: id =>
33
- id === 'a1'
34
- ? fromMatrix4(new THREE.Matrix4().setPosition(1, 0, 2))
35
- : id === 'a3' && scopePlaced
36
- ? fromMatrix4(new THREE.Matrix4().setPosition(3, 0, 0))
37
- : null,
30
+
31
+ /** Where the room keeps the arm: someone moved it to 5 m along x; nobody moved it unless `armKept`. */
32
+ const KEPT_ARM = fromMatrix4(new THREE.Matrix4().setPosition(5, 0, 0));
33
+
34
+ /** The rooms the host keeps, and what it was asked to draw. */
35
+ const spaceOf = (armKept: boolean, drawn: Array<[string, string | null]>): BlokSpaceHost => ({
36
+ useRoom: () => ({poseOf: id => (armKept && id === 'a1' ? KEPT_ARM : null)}),
37
+ renderAgent: (agentId, blok) => {
38
+ drawn.push([agentId, blok]);
39
+ return <group name={`agent-scene:${agentId}`} />;
40
+ },
38
41
  });
39
42
 
40
43
  /** The arm's model, as its own scene blok would have loaded it: one mesh. */
@@ -56,15 +59,17 @@ const armModel = (): ModelContextValue => {
56
59
 
57
60
  const prop = (key: string, value: unknown) => ({key, static_value: value});
58
61
 
59
- const overlay = [
62
+ /** The arm declared 1 m along x and 2 m along z; the scope 3 m along x, drawn with a named scene blok. */
63
+ const room = [
60
64
  {
61
65
  id: 'root',
62
- component: 'Overlay',
66
+ component: 'Space',
67
+ props: [prop('room', 'room:test-lab')],
63
68
  children: [
64
69
  {
65
70
  id: 'robot',
66
- component: 'Anchor',
67
- props: [prop('dep', 'robot')],
71
+ component: 'Placed',
72
+ props: [prop('dep', 'robot'), prop('matrix', fromMatrix4(new THREE.Matrix4().setPosition(1, 0, 2)))],
68
73
  children: [
69
74
  {id: 'glow', component: 'Glow', props: [prop('on', true), prop('color', '#ff0000')]},
70
75
  {id: 'card', component: 'Popout', props: [prop('open', true), prop('title', 'Arm card')]},
@@ -72,48 +77,48 @@ const overlay = [
72
77
  },
73
78
  {
74
79
  id: 'frame',
75
- component: 'Anchor',
76
- props: [prop('dep', 'frame')],
77
- children: [{id: 'ask', component: 'Popout', props: [prop('open', true), prop('title', 'Scope card')]}],
80
+ component: 'Placed',
81
+ props: [prop('dep', 'frame'), prop('blok', 'scope-3d'), prop('matrix', fromMatrix4(new THREE.Matrix4().setPosition(3, 0, 0)))],
78
82
  },
83
+ {id: 'gone', component: 'Placed', props: [prop('dep', 'opentrons')]},
79
84
  {id: 'route', component: 'Route', props: [prop('through', ['robot', 'frame']), {key: 'progress', dynamic_value: {path: 'task.progress'}}]},
80
85
  ],
81
86
  },
82
87
  ];
83
88
 
84
- const mount = async (owned?: ModelContextValue, scopePlaced = false) => {
89
+ const mount = async ({owned, armKept = false}: {owned?: ModelContextValue; armKept?: boolean} = {}) => {
85
90
  const store = createSceneStore();
86
91
  if (owned) store.getState().setOwnedModel('a1', 'device', owned);
92
+ const drawn: Array<[string, string | null]> = [];
87
93
  const root = createRoot(document.createElement('canvas'));
88
94
  await root.configure({gl: renderer, frameloop: 'never', size: {width: 100, height: 100, top: 0, left: 0}});
89
95
  let state!: ReturnType<typeof root.render>;
90
96
  await act(async () => {
91
97
  state = root.render(
92
98
  <BlokRunHostProvider value={run}>
93
- <BlokSpaceHostProvider value={spaceOf(scopePlaced)}>
99
+ <BlokSpaceHostProvider value={spaceOf(armKept, drawn)}>
94
100
  <SceneStoreProvider value={store}>
95
101
  <BlokSceneEmbedProvider value>
96
- <BlokRenderer catalog={testCatalog()} embedded uiComponents={overlay} initialState={{task: {progress: 50}}} />
102
+ <BlokRenderer catalog={testCatalog()} embedded uiComponents={room} initialState={{task: {progress: 50}}} />
97
103
  </BlokSceneEmbedProvider>
98
104
  </SceneStoreProvider>
99
105
  </BlokSpaceHostProvider>
100
106
  </BlokRunHostProvider>,
101
107
  );
102
108
  });
103
- return {store, scene: state.getState().scene, unmount: () => root.unmount()};
109
+ return {store, drawn, scene: state.getState().scene, unmount: () => root.unmount()};
104
110
  };
105
111
 
106
112
  let unmount: (() => void) | undefined;
107
113
  afterEach(() => unmount?.());
108
114
 
109
- describe('an overlay drawn into a space', () => {
110
- it('stands an Anchor where its agent is placed, and a Glow without a node lights the device it anchors', async () => {
115
+ describe('a space placing the run\'s dependencies', () => {
116
+ it('stands a Placed where it says while nobody moved it, and a Glow without a node lights the device', async () => {
111
117
  const model = armModel();
112
- const mounted = await mount(model);
118
+ const mounted = await mount({owned: model});
113
119
  unmount = mounted.unmount;
114
120
 
115
- const anchor = mounted.scene.getObjectByName('at:a1');
116
- expect(anchor?.position.toArray()).toEqual([1, 0, 2]);
121
+ expect(mounted.scene.getObjectByName('placed:robot:a1')?.position.toArray()).toEqual([1, 0, 2]);
117
122
  // The glow works on the model the device's scene blok loaded, not on a copy.
118
123
  const mesh = model.instance.root.children[0] as THREE.Mesh;
119
124
  const lit = mesh.material as THREE.MeshStandardMaterial;
@@ -121,40 +126,41 @@ describe('an overlay drawn into a space', () => {
121
126
  expect(lit.emissive.getHexString()).toBe('ff0000');
122
127
  });
123
128
 
124
- it('sends an agent the space does not place to the side tray, its cards with it', async () => {
129
+ it('stands a device where the room keeps it, over what its Placed says', async () => {
130
+ const mounted = await mount({armKept: true});
131
+ unmount = mounted.unmount;
132
+
133
+ expect(mounted.scene.getObjectByName('placed:robot:a1')?.position.toArray()).toEqual([5, 0, 0]);
134
+ });
135
+
136
+ it('draws each agent with its own scene blok inside its placement: the default, or the one named', async () => {
125
137
  const mounted = await mount();
126
138
  unmount = mounted.unmount;
127
139
 
128
- const overlays = [...mounted.store.getState().overlays.values()];
129
- const panels = overlays.filter(card => card.mode === 'panel').map(card => card.title);
130
- const popouts = overlays.filter(card => card.mode === 'popout').map(card => card.title);
131
- expect(panels).toEqual(expect.arrayContaining(['Scope', 'Scope card']));
132
- expect(popouts).toEqual(['Arm card']);
133
- expect(mounted.scene.getObjectByName('at:a3')).toBeUndefined();
140
+ expect(mounted.drawn).toEqual(expect.arrayContaining([['a1', null], ['a3', 'scope-3d']]));
141
+ expect(mounted.scene.getObjectByName('agent-scene:a3')?.parent?.name).toBe('placed:frame:a3');
134
142
  });
135
143
 
136
- it('anchors a card at the stand-in while the device has no model in the scene', async () => {
144
+ it('anchors a card at the placement while the device has no model in the scene', async () => {
137
145
  const mounted = await mount();
138
146
  unmount = mounted.unmount;
139
147
 
140
148
  const card = [...mounted.store.getState().overlays.values()].find(overlay => overlay.title === 'Arm card');
141
- expect(card?.anchor()).toBe(mounted.scene.getObjectByName('at:a1'));
149
+ expect(card?.anchor()).toBe(mounted.scene.getObjectByName('placed:robot:a1'));
142
150
  });
143
151
 
144
- it('draws no route through fewer than two placed agents, and says so', async () => {
152
+ it('says so when the run has no agent for a dependency', async () => {
145
153
  const mounted = await mount();
146
154
  unmount = mounted.unmount;
147
155
 
148
- expect(mounted.scene.getObjectByName('route')).toBeUndefined();
149
- expect([...mounted.store.getState().notices.values()].map(notice => notice.title)).toContain('A route with nowhere to go');
156
+ expect([...mounted.store.getState().notices.values()].map(notice => notice.title)).toContain('Nothing is bound to "opentrons"');
150
157
  });
151
158
 
152
159
  it('draws a route through the placed agents, its head where the run is', async () => {
153
- const mounted = await mount(undefined, true);
160
+ const mounted = await mount();
154
161
  unmount = mounted.unmount;
155
162
 
156
163
  const route = mounted.scene.getObjectByName('route');
157
- expect([...mounted.store.getState().notices.values()]).toEqual([]);
158
164
  expect(route).toBeDefined();
159
165
  const head = route?.children.find(child => (child as THREE.Mesh).isMesh && (child as THREE.Mesh).geometry.type === 'SphereGeometry');
160
166
  // Half way from (1, 0, 2) to (3, 0, 0), over the floor.
@@ -24,7 +24,7 @@ import {
24
24
  type BlokRender,
25
25
  type BlokRenderArgs,
26
26
  } from '../../runtime';
27
- import type {sceneContracts} from '../../../catalogs/parts/scene';
27
+ import {sceneSchema, type sceneContracts} from '../../../catalogs/parts/scene';
28
28
  import {
29
29
  createSceneStore,
30
30
  SceneStoreProvider,
@@ -808,8 +808,21 @@ const SceneChildren = ({component, buildChild}: Pick<SceneRenderArgs, 'component
808
808
  </>
809
809
  );
810
810
 
811
- const StandaloneScene = ({component, schema, buildChild}: SceneRenderArgs) => {
812
- const blok = useBlok(component, schema);
811
+ export type SceneFrameProps = Pick<SceneRenderArgs, 'component' | 'buildChild'> & {
812
+ /** HTML over the canvas (beside the scene's own controls). */
813
+ overlay?: React.ReactNode;
814
+ /** What the scene holds; the component's children when left out. */
815
+ children?: React.ReactNode;
816
+ };
817
+
818
+ /**
819
+ * A scene with a canvas of its own, sized and kept as a `Scene` asks: its
820
+ * camera, grid, height and (with `persist`) the viewer's camera on this device.
821
+ * A `Space` is one too, with its room around what it holds. The props are read
822
+ * through the scene schema, which every such root extends.
823
+ */
824
+ export const SceneFrame = ({component, buildChild, overlay, children}: SceneFrameProps) => {
825
+ const blok = useBlok(component, sceneSchema);
813
826
  const camera = useValue(blok.camera) ?? 'iso';
814
827
  const grid = useValue(blok.grid) ?? true;
815
828
  const declaredHeight = useValue(blok.height);
@@ -840,12 +853,17 @@ const StandaloneScene = ({component, schema, buildChild}: SceneRenderArgs) => {
840
853
  frameRef={frameRef}
841
854
  className={fill ? 'relative w-full overflow-hidden' : 'relative w-full overflow-hidden rounded-xl bg-muted/20'}
842
855
  style={{height}}
856
+ overlay={overlay}
843
857
  >
844
- <SceneChildren component={component} buildChild={buildChild} />
858
+ {children ?? <SceneChildren component={component} buildChild={buildChild} />}
845
859
  </SceneSurface>
846
860
  );
847
861
  };
848
862
 
863
+ const StandaloneScene = ({component, buildChild}: SceneRenderArgs) => (
864
+ <SceneFrame component={component} buildChild={buildChild} />
865
+ );
866
+
849
867
  export const SceneRender: BlokRender<Contracts['Scene']> = args =>
850
868
  // Inside a scene that is already open, this one only adds what it holds:
851
869
  // the camera, grid and size are the surrounding scene's.
package/src/scene.ts CHANGED
@@ -12,7 +12,6 @@ const renders = {...sceneRenders, ...runRenders};
12
12
 
13
13
  /** scene@1, drawn with three. */
14
14
  export const threeScene = implementBlokCatalog(sceneCatalog, {
15
- Anchor: renders.Anchor,
16
15
  Animate: renders.Animate,
17
16
  Attach: renders.Attach,
18
17
  Beam: renders.Beam,
@@ -20,12 +19,13 @@ export const threeScene = implementBlokCatalog(sceneCatalog, {
20
19
  Model: renders.Model,
21
20
  Move: renders.Move,
22
21
  OnClick: renders.OnClick,
23
- Overlay: renders.Overlay,
22
+ Placed: renders.Placed,
24
23
  Popout: renders.Popout,
25
24
  Robot: renders.Robot,
26
25
  Rotate: renders.Rotate,
27
26
  Route: renders.Route,
28
27
  Scene: renders.Scene,
28
+ Space: renders.Space,
29
29
  Tint: renders.Tint,
30
30
  Transform: renders.Transform,
31
31
  Visible: renders.Visible,