@arkitektio/bsx 6.4.0 → 6.6.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.
- package/dist/bsx/references.d.ts +2 -0
- package/dist/bsx/references.d.ts.map +1 -1
- package/dist/bsx/references.js +28 -2
- package/dist/bsx/references.js.map +1 -1
- package/dist/ports/engine/defaultRegistry.d.ts.map +1 -1
- package/dist/ports/engine/defaultRegistry.js +2 -0
- package/dist/ports/engine/defaultRegistry.js.map +1 -1
- package/dist/ports/forms/ListSearchField.d.ts.map +1 -1
- package/dist/ports/forms/ListSearchField.js +4 -2
- package/dist/ports/forms/ListSearchField.js.map +1 -1
- package/dist/ports/forms/SearchField.d.ts.map +1 -1
- package/dist/ports/forms/SearchField.js +4 -2
- package/dist/ports/forms/SearchField.js.map +1 -1
- package/dist/ports/forms/StructurePickerControl.d.ts +16 -1
- package/dist/ports/forms/StructurePickerControl.d.ts.map +1 -1
- package/dist/ports/forms/StructurePickerControl.js +26 -3
- package/dist/ports/forms/StructurePickerControl.js.map +1 -1
- package/dist/ports/host.d.ts +6 -0
- package/dist/ports/host.d.ts.map +1 -1
- package/dist/ports/host.js.map +1 -1
- package/dist/ports/rekuest.d.ts +25 -7
- package/dist/ports/rekuest.d.ts.map +1 -1
- package/dist/ports/rekuest.js +1 -0
- package/dist/ports/rekuest.js.map +1 -1
- package/dist/ports/structure/Structure.d.ts.map +1 -1
- package/dist/ports/structure/Structure.js +7 -4
- package/dist/ports/structure/Structure.js.map +1 -1
- package/dist/ports/widgets/custom/ListSearchWidget.d.ts.map +1 -1
- package/dist/ports/widgets/custom/ListSearchWidget.js +3 -2
- package/dist/ports/widgets/custom/ListSearchWidget.js.map +1 -1
- package/dist/ports/widgets/custom/PortBlokWidget.d.ts +30 -0
- package/dist/ports/widgets/custom/PortBlokWidget.d.ts.map +1 -0
- package/dist/ports/widgets/custom/PortBlokWidget.js +210 -0
- package/dist/ports/widgets/custom/PortBlokWidget.js.map +1 -0
- package/dist/ports/widgets/custom/SearchWidget.d.ts.map +1 -1
- package/dist/ports/widgets/custom/SearchWidget.js +3 -2
- package/dist/ports/widgets/custom/SearchWidget.js.map +1 -1
- package/dist/ports/widgets/fallbacks/EnumWidget.d.ts.map +1 -1
- package/dist/ports/widgets/fallbacks/EnumWidget.js +5 -1
- package/dist/ports/widgets/fallbacks/EnumWidget.js.map +1 -1
- package/dist/ports.d.ts +2 -0
- package/dist/ports.d.ts.map +1 -1
- package/dist/ports.js +4 -0
- package/dist/ports.js.map +1 -1
- package/dist/renderer/BlokRenderer.d.ts +4 -1
- package/dist/renderer/BlokRenderer.d.ts.map +1 -1
- package/dist/renderer/BlokRenderer.js +5 -1
- package/dist/renderer/BlokRenderer.js.map +1 -1
- package/dist/renderer/bloks/control.d.ts +5 -0
- package/dist/renderer/bloks/control.d.ts.map +1 -1
- package/dist/renderer/bloks/control.js +28 -1
- package/dist/renderer/bloks/control.js.map +1 -1
- package/dist/renderer/bloks/port/host.d.ts +32 -0
- package/dist/renderer/bloks/port/host.d.ts.map +1 -0
- package/dist/renderer/bloks/port/host.js +14 -0
- package/dist/renderer/bloks/port/host.js.map +1 -0
- package/dist/renderer/bloks/scene/Model.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/Model.js +16 -2
- package/dist/renderer/bloks/scene/Model.js.map +1 -1
- package/dist/renderer/runtime/context.d.ts +2 -0
- package/dist/renderer/runtime/context.d.ts.map +1 -1
- package/dist/renderer/runtime/context.js +4 -0
- package/dist/renderer/runtime/context.js.map +1 -1
- package/dist/renderer/runtime/hooks.d.ts.map +1 -1
- package/dist/renderer/runtime/hooks.js +1 -0
- package/dist/renderer/runtime/hooks.js.map +1 -1
- package/dist/renderer/runtime/resolution.d.ts +3 -0
- package/dist/renderer/runtime/resolution.d.ts.map +1 -1
- package/dist/renderer/runtime/resolution.js +17 -1
- package/dist/renderer/runtime/resolution.js.map +1 -1
- package/dist/renderer/runtime/types.d.ts +6 -0
- package/dist/renderer/runtime/types.d.ts.map +1 -1
- package/dist/renderer/runtime/types.js.map +1 -1
- package/dist/spec/bsx_v2.json +1285 -181
- package/dist/spec/catalogs/base@4.json +95 -2
- package/dist/spec/catalogs/base@4.json.js +95 -2
- package/dist/spec/vocabulary.d.ts +5 -1
- package/dist/spec/vocabulary.d.ts.map +1 -1
- package/dist/spec/vocabulary.js +4 -1
- package/dist/spec/vocabulary.js.map +1 -1
- package/dist/spec/vocabulary.json +44 -10
- package/dist/spec/vocabulary.json.js +44 -10
- package/dist/vendor/core/ui/name.d.ts +30 -0
- package/dist/vendor/core/ui/name.d.ts.map +1 -0
- package/dist/vendor/core/ui/name.js +40 -0
- package/dist/vendor/core/ui/name.js.map +1 -0
- package/dist/vendor/core/ui/overflow-tooltip.d.ts +20 -0
- package/dist/vendor/core/ui/overflow-tooltip.d.ts.map +1 -0
- package/dist/vendor/core/ui/overflow-tooltip.js +27 -0
- package/dist/vendor/core/ui/overflow-tooltip.js.map +1 -0
- package/dist/vendor/core/ui/select.js +3 -3
- package/dist/vendor/core/ui/select.js.map +1 -1
- package/package.json +1 -1
- package/src/bsx/references.test.ts +1 -1
- package/src/bsx/references.ts +28 -2
- package/src/ports/engine/defaultRegistry.tsx +2 -0
- package/src/ports/forms/ListSearchField.tsx +12 -9
- package/src/ports/forms/SearchField.tsx +9 -3
- package/src/ports/forms/StructurePickerControl.test.tsx +29 -1
- package/src/ports/forms/StructurePickerControl.tsx +38 -4
- package/src/ports/host.tsx +6 -0
- package/src/ports/rekuest.ts +14 -8
- package/src/ports/structure/Structure.tsx +14 -5
- package/src/ports/widgets/custom/ListSearchWidget.tsx +3 -2
- package/src/ports/widgets/custom/PortBlokWidget.test.tsx +88 -0
- package/src/ports/widgets/custom/PortBlokWidget.tsx +268 -0
- package/src/ports/widgets/custom/SearchWidget.tsx +3 -2
- package/src/ports/widgets/fallbacks/EnumWidget.test.tsx +89 -0
- package/src/ports/widgets/fallbacks/EnumWidget.tsx +38 -13
- package/src/ports.ts +4 -0
- package/src/renderer/BlokRenderer.tsx +9 -0
- package/src/renderer/bloks/control.tsx +47 -1
- package/src/renderer/bloks/port/host.tsx +46 -0
- package/src/renderer/bloks/scene/Model.tsx +15 -2
- package/src/renderer/runtime/context.tsx +6 -0
- package/src/renderer/runtime/hooks.ts +1 -0
- package/src/renderer/runtime/resolution.ts +16 -1
- package/src/renderer/runtime/types.ts +6 -0
- package/src/spec/bsx_v2.json +1285 -181
- package/src/spec/catalogs/base@4.json +95 -2
- package/src/spec/spec.test.ts +7 -3
- package/src/spec/vocabulary.json +44 -10
- package/src/spec/vocabulary.ts +9 -2
- package/src/vendor/core/ui/name.tsx +69 -0
- package/src/vendor/core/ui/overflow-tooltip.tsx +59 -0
- package/src/vendor/core/ui/select.tsx +3 -3
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
CommandItem,
|
|
9
9
|
CommandList,
|
|
10
10
|
} from "../../vendor/core/ui/command";
|
|
11
|
+
import { Name } from "../../vendor/core/ui/name";
|
|
11
12
|
import { Popover, PopoverContent, PopoverTrigger } from "../../vendor/core/ui/popover";
|
|
12
13
|
import { useDebouncedCallback } from "../../vendor/core/util/hooks/useDebouncedCallback";
|
|
13
14
|
import { useLatestRef } from "../../vendor/core/util/hooks/useLatestRef";
|
|
@@ -45,6 +46,12 @@ export type StructurePickerControlProps<T> = {
|
|
|
45
46
|
renderRow: (item: T) => ReactNode;
|
|
46
47
|
/** The chosen one, in the closed field: one line. */
|
|
47
48
|
renderValue: (item: T) => ReactNode;
|
|
49
|
+
/**
|
|
50
|
+
* What a candidate belongs to (a lens' dataset), said once as a heading over
|
|
51
|
+
* every candidate sharing it rather than on each row. Candidates without one
|
|
52
|
+
* are listed first, under no heading.
|
|
53
|
+
*/
|
|
54
|
+
groupOf?: (item: T) => string | undefined;
|
|
48
55
|
/** What the list is fixed to, shown so an empty list explains itself. */
|
|
49
56
|
requires?: readonly DescriptorConstraint[];
|
|
50
57
|
scope?: PickerScope;
|
|
@@ -55,6 +62,29 @@ export type StructurePickerControlProps<T> = {
|
|
|
55
62
|
className?: string;
|
|
56
63
|
};
|
|
57
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Candidates by what they belong to, in the order each group first appears:
|
|
67
|
+
* a group a later page returns to is added to, never opened a second time.
|
|
68
|
+
* The ungrouped come first, whenever they arrive.
|
|
69
|
+
*/
|
|
70
|
+
export const groupItems = <T,>(
|
|
71
|
+
items: readonly T[],
|
|
72
|
+
groupOf?: (item: T) => string | undefined,
|
|
73
|
+
): { group: string | undefined; items: T[] }[] => {
|
|
74
|
+
const ungrouped: T[] = [];
|
|
75
|
+
const groups = new Map<string, T[]>();
|
|
76
|
+
for (const item of items) {
|
|
77
|
+
const group = groupOf?.(item)?.trim();
|
|
78
|
+
if (!group) ungrouped.push(item);
|
|
79
|
+
else if (groups.has(group)) groups.get(group)!.push(item);
|
|
80
|
+
else groups.set(group, [item]);
|
|
81
|
+
}
|
|
82
|
+
return [
|
|
83
|
+
...(ungrouped.length > 0 ? [{ group: undefined, items: ungrouped }] : []),
|
|
84
|
+
...Array.from(groups, ([group, members]) => ({ group, items: members })),
|
|
85
|
+
];
|
|
86
|
+
};
|
|
87
|
+
|
|
58
88
|
/** The chosen object in the closed field, resolved by id. Mounted per id (`key`), so it starts out loading. */
|
|
59
89
|
const Chosen = <T,>({
|
|
60
90
|
id,
|
|
@@ -101,6 +131,7 @@ export const StructurePickerControl = <T,>({
|
|
|
101
131
|
keyOf,
|
|
102
132
|
renderRow,
|
|
103
133
|
renderValue,
|
|
134
|
+
groupOf,
|
|
104
135
|
requires,
|
|
105
136
|
scope,
|
|
106
137
|
paged = true,
|
|
@@ -270,9 +301,12 @@ export const StructurePickerControl = <T,>({
|
|
|
270
301
|
)}
|
|
271
302
|
</div>
|
|
272
303
|
)}
|
|
273
|
-
{items.
|
|
274
|
-
<CommandGroup
|
|
275
|
-
{
|
|
304
|
+
{groupItems(items, groupOf).map((bucket) => (
|
|
305
|
+
<CommandGroup
|
|
306
|
+
key={bucket.group ?? ""}
|
|
307
|
+
heading={bucket.group ? <Name title={bucket.group}>{bucket.group}</Name> : undefined}
|
|
308
|
+
>
|
|
309
|
+
{bucket.items.map((item) => {
|
|
276
310
|
const id = keyOf(item);
|
|
277
311
|
return (
|
|
278
312
|
<CommandItem
|
|
@@ -291,7 +325,7 @@ export const StructurePickerControl = <T,>({
|
|
|
291
325
|
);
|
|
292
326
|
})}
|
|
293
327
|
</CommandGroup>
|
|
294
|
-
)}
|
|
328
|
+
))}
|
|
295
329
|
{hasMore && (
|
|
296
330
|
<div ref={sentinelRef} className="flex items-center justify-center py-2 text-xs text-muted-foreground">
|
|
297
331
|
{loadingMore ? "Loading more…" : ""}
|
package/src/ports/host.tsx
CHANGED
|
@@ -57,6 +57,12 @@ export type PortHost = {
|
|
|
57
57
|
StructureDisplay: React.ComponentType<StructureDisplayProps>;
|
|
58
58
|
StructureViewer: React.ComponentType<StructureViewerProps>;
|
|
59
59
|
useReportError: () => (error: unknown, title?: string) => void;
|
|
60
|
+
/**
|
|
61
|
+
* Draws a port's own blok (a BLOK widget) with what this app knows beyond the form: the agents
|
|
62
|
+
* a run would get (`self`, `deps.<key>`) and the services its queries ask. Left out, a port
|
|
63
|
+
* blok is drawn with neither: its dependencies read unbound and its queries do not run.
|
|
64
|
+
*/
|
|
65
|
+
PortBlokRenderer?: React.ComponentType<import('./widgets/custom/PortBlokWidget').PortBlokRendererProps>;
|
|
60
66
|
};
|
|
61
67
|
|
|
62
68
|
const notConnected: ServiceQuery = async () => {
|
package/src/ports/rekuest.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
/** The kind of assign widget. */
|
|
7
7
|
export const AssignWidgetKind = {
|
|
8
|
+
Blok: 'BLOK',
|
|
8
9
|
Choice: 'CHOICE',
|
|
9
10
|
Custom: 'CUSTOM',
|
|
10
11
|
Proxy: 'PROXY',
|
|
@@ -71,7 +72,7 @@ export const ReturnWidgetKind = {
|
|
|
71
72
|
} as const;
|
|
72
73
|
export type ReturnWidgetKind = (typeof ReturnWidgetKind)[keyof typeof ReturnWidgetKind];
|
|
73
74
|
|
|
74
|
-
export type ArgChildPortDeepFragment = { __typename: 'ArgPort', kind: PortKind, key: string, label?: string | null, identifier?: any | null, referenceUnit?: string | null, proposedUnits?: Array<string> | null, dimension?: string | null, description?: string | null, nullable: boolean, default?: any | null, requires?: Array<{ __typename?: 'Requires', key: string, operator: DescriptorOperator, value?: any | null }> | null, choices?: Array<{ __typename?: 'Choice', value: any, label: string, description?: string | null }> | null, widget?: (
|
|
75
|
+
export type ArgChildPortDeepFragment = { __typename: 'ArgPort', kind: PortKind, key: string, label?: string | null, identifier?: any | null, referenceUnit?: string | null, proposedUnits?: Array<string> | null, dimension?: string | null, description?: string | null, nullable: boolean, default?: any | null, requires?: Array<{ __typename?: 'Requires', key: string, operator: DescriptorOperator, value?: any | null }> | null, choices?: Array<{ __typename?: 'Choice', value: any, label: string, description?: string | null }> | null, widget?: BlokAssignWidgetFragment | (
|
|
75
76
|
{ __typename?: 'ChoiceAssignWidget' }
|
|
76
77
|
& AssignWidget_ChoiceAssignWidget_Fragment
|
|
77
78
|
) | (
|
|
@@ -92,7 +93,7 @@ export type ArgChildPortDeepFragment = { __typename: 'ArgPort', kind: PortKind,
|
|
|
92
93
|
) | (
|
|
93
94
|
{ __typename?: 'StringAssignWidget' }
|
|
94
95
|
& AssignWidget_StringAssignWidget_Fragment
|
|
95
|
-
) | null, children?: Array<{ __typename: 'ArgPort', kind: PortKind, key: string, identifier?: any | null, nullable: boolean, requires?: Array<{ __typename?: 'Requires', key: string, operator: DescriptorOperator, value?: any | null }> | null, widget?: (
|
|
96
|
+
) | null, children?: Array<{ __typename: 'ArgPort', kind: PortKind, key: string, identifier?: any | null, nullable: boolean, requires?: Array<{ __typename?: 'Requires', key: string, operator: DescriptorOperator, value?: any | null }> | null, widget?: BlokAssignWidgetFragment | (
|
|
96
97
|
{ __typename?: 'ChoiceAssignWidget' }
|
|
97
98
|
& AssignWidget_ChoiceAssignWidget_Fragment
|
|
98
99
|
) | (
|
|
@@ -118,7 +119,7 @@ export type ArgChildPortDeepFragment = { __typename: 'ArgPort', kind: PortKind,
|
|
|
118
119
|
export type ArgChildPortFragment = { __typename: 'ArgPort', kind: PortKind, key: string, label?: string | null, identifier?: any | null, referenceUnit?: string | null, proposedUnits?: Array<string> | null, dimension?: string | null, nullable: boolean, description?: string | null, default?: any | null, requires?: Array<{ __typename?: 'Requires', key: string, operator: DescriptorOperator, value?: any | null }> | null, children?: Array<(
|
|
119
120
|
{ __typename?: 'ArgPort' }
|
|
120
121
|
& ArgChildPortNestedFragment
|
|
121
|
-
)> | null, widget?: (
|
|
122
|
+
)> | null, widget?: BlokAssignWidgetFragment | (
|
|
122
123
|
{ __typename?: 'ChoiceAssignWidget' }
|
|
123
124
|
& AssignWidget_ChoiceAssignWidget_Fragment
|
|
124
125
|
) | (
|
|
@@ -156,7 +157,7 @@ export type ArgChildPortFragment = { __typename: 'ArgPort', kind: PortKind, key:
|
|
|
156
157
|
export type ArgChildPortNestedFragment = { __typename: 'ArgPort', kind: PortKind, key: string, label?: string | null, identifier?: any | null, referenceUnit?: string | null, proposedUnits?: Array<string> | null, dimension?: string | null, description?: string | null, nullable: boolean, default?: any | null, requires?: Array<{ __typename?: 'Requires', key: string, operator: DescriptorOperator, value?: any | null }> | null, children?: Array<(
|
|
157
158
|
{ __typename?: 'ArgPort' }
|
|
158
159
|
& ArgChildPortDeepFragment
|
|
159
|
-
)> | null, choices?: Array<{ __typename?: 'Choice', value: any, label: string, description?: string | null }> | null, widget?: (
|
|
160
|
+
)> | null, choices?: Array<{ __typename?: 'Choice', value: any, label: string, description?: string | null }> | null, widget?: BlokAssignWidgetFragment | (
|
|
160
161
|
{ __typename?: 'ChoiceAssignWidget' }
|
|
161
162
|
& AssignWidget_ChoiceAssignWidget_Fragment
|
|
162
163
|
) | (
|
|
@@ -200,7 +201,7 @@ export type ArgPortFragment = { __typename: 'ArgPort', key: string, label?: stri
|
|
|
200
201
|
) | (
|
|
201
202
|
{ __typename?: 'MessageEffect' }
|
|
202
203
|
& PortEffect_MessageEffect_Fragment
|
|
203
|
-
)> | null, widget?: (
|
|
204
|
+
)> | null, widget?: BlokAssignWidgetFragment | (
|
|
204
205
|
{ __typename?: 'ChoiceAssignWidget' }
|
|
205
206
|
& AssignWidget_ChoiceAssignWidget_Fragment
|
|
206
207
|
) | (
|
|
@@ -229,7 +230,12 @@ export type ArgPortFragment = { __typename: 'ArgPort', key: string, label?: stri
|
|
|
229
230
|
& ValidatorFragment
|
|
230
231
|
)> | null, requires?: Array<{ __typename?: 'Requires', key: string, operator: DescriptorOperator, value?: any | null }> | null };
|
|
231
232
|
|
|
232
|
-
|
|
233
|
+
/** A port blok as the port's widget: BSX (`<Blok kind="port">`) the form draws where the port's control would be. */
|
|
234
|
+
export type BlokAssignWidgetFragment = { __typename: 'BlokAssignWidget', kind: AssignWidgetKind, followValue?: string | null, source: string, vocab: number, fallback?: (
|
|
235
|
+
{ __typename: string, kind: AssignWidgetKind }
|
|
236
|
+
) | null };
|
|
237
|
+
|
|
238
|
+
export type AssignWidgetFragment = BlokAssignWidgetFragment | AssignWidget_ChoiceAssignWidget_Fragment | AssignWidget_CustomAssignWidget_Fragment | AssignWidget_ProxyWidget_Fragment | AssignWidget_SearchAssignWidget_Fragment | AssignWidget_SliderAssignWidget_Fragment | AssignWidget_StateChoiceAssignWidget_Fragment | AssignWidget_StringAssignWidget_Fragment;
|
|
233
239
|
|
|
234
240
|
type AssignWidget_ChoiceAssignWidget_Fragment = (
|
|
235
241
|
{ __typename: 'ChoiceAssignWidget', kind: AssignWidgetKind }
|
|
@@ -326,7 +332,7 @@ export type ChoiceReturnWidgetFragment = { __typename: 'ChoiceReturnWidget', kin
|
|
|
326
332
|
export type CustomAssignWidgetFragment = { __typename: 'CustomAssignWidget', kind: AssignWidgetKind, followValue?: string | null, component: string, children?: any | null, dependencies?: Array<string> | null, props?: Array<(
|
|
327
333
|
{ __typename?: 'ComponentProp' }
|
|
328
334
|
& BlokComponentPropFragment
|
|
329
|
-
)> | null, fallback?: (
|
|
335
|
+
)> | null, fallback?: { __typename: 'BlokAssignWidget', kind: AssignWidgetKind } | (
|
|
330
336
|
{ __typename: 'ChoiceAssignWidget', kind: AssignWidgetKind }
|
|
331
337
|
& ChoiceAssignWidgetFragment
|
|
332
338
|
) | { __typename: 'CustomAssignWidget', kind: AssignWidgetKind } | (
|
|
@@ -356,7 +362,7 @@ export type CustomReturnWidgetFragment = { __typename: 'CustomReturnWidget', kin
|
|
|
356
362
|
& BlokComponentPropFragment
|
|
357
363
|
)> | null };
|
|
358
364
|
|
|
359
|
-
export type FilterPortFragment = { __typename: 'ArgPort', kind: PortKind, key: string, identifier?: any | null, description?: string | null, nullable: boolean, widget?: { __typename?: 'ChoiceAssignWidget' } | { __typename?: 'CustomAssignWidget' } | { __typename?: 'ProxyWidget' } | { __typename?: 'SearchAssignWidget', query: string } | { __typename?: 'SliderAssignWidget' } | { __typename?: 'StateChoiceAssignWidget' } | { __typename?: 'StringAssignWidget' } | null };
|
|
365
|
+
export type FilterPortFragment = { __typename: 'ArgPort', kind: PortKind, key: string, identifier?: any | null, description?: string | null, nullable: boolean, widget?: { __typename?: 'BlokAssignWidget' } | { __typename?: 'ChoiceAssignWidget' } | { __typename?: 'CustomAssignWidget' } | { __typename?: 'ProxyWidget' } | { __typename?: 'SearchAssignWidget', query: string } | { __typename?: 'SliderAssignWidget' } | { __typename?: 'StateChoiceAssignWidget' } | { __typename?: 'StringAssignWidget' } | null };
|
|
360
366
|
|
|
361
367
|
export type HideEffectFragment = (
|
|
362
368
|
{ __typename: 'HideEffect', fade: boolean }
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import {Name} from '../../vendor/core/ui/name';
|
|
2
3
|
import {structureCatalog} from '../../catalogs';
|
|
3
4
|
import {StructurePickerControl, type PickerRequest} from '../forms/StructurePickerControl';
|
|
4
5
|
import {portHost} from '../host';
|
|
@@ -36,20 +37,26 @@ const Notice = ({children, className}: {children: React.ReactNode; className?: s
|
|
|
36
37
|
);
|
|
37
38
|
|
|
38
39
|
/** One candidate, as a search answers it. */
|
|
39
|
-
type Option = {value: string; label: string; description?: string};
|
|
40
|
+
type Option = {value: string; label: string; description?: string; group?: string};
|
|
40
41
|
|
|
41
42
|
const keyOf = (option: Option) => option.value;
|
|
42
43
|
|
|
43
44
|
const renderOption = (option: Option) => (
|
|
44
45
|
<div className="flex min-w-0 flex-col">
|
|
45
|
-
<
|
|
46
|
+
<Name title={option.label}>{option.label}</Name>
|
|
46
47
|
{option.description && (
|
|
47
|
-
<
|
|
48
|
+
<Name title={option.description} className="text-xs text-muted-foreground">
|
|
49
|
+
{option.description}
|
|
50
|
+
</Name>
|
|
48
51
|
)}
|
|
49
52
|
</div>
|
|
50
53
|
);
|
|
51
54
|
|
|
52
|
-
const
|
|
55
|
+
const groupOf = (option: Option) => option.group;
|
|
56
|
+
|
|
57
|
+
const renderChosen = (option: Option) => (
|
|
58
|
+
<Name title={option.group ? `${option.label} (${option.group})` : option.label}>{option.label}</Name>
|
|
59
|
+
);
|
|
53
60
|
|
|
54
61
|
/**
|
|
55
62
|
* The variables a picker's query is handed by the picker itself: what the
|
|
@@ -71,13 +78,14 @@ const asVariable = (raw: unknown): unknown => {
|
|
|
71
78
|
const asOptions = (raw: unknown): Option[] =>
|
|
72
79
|
(Array.isArray(raw) ? raw : []).flatMap(entry => {
|
|
73
80
|
if (!entry || typeof entry !== 'object') return [];
|
|
74
|
-
const {value, label, description} = entry as Record<string, unknown>;
|
|
81
|
+
const {value, label, description, group} = entry as Record<string, unknown>;
|
|
75
82
|
if (value == null) return [];
|
|
76
83
|
return [
|
|
77
84
|
{
|
|
78
85
|
value: String(value),
|
|
79
86
|
label: typeof label === 'string' && label ? label : String(value),
|
|
80
87
|
description: typeof description === 'string' && description ? description : undefined,
|
|
88
|
+
group: typeof group === 'string' && group ? group : undefined,
|
|
81
89
|
},
|
|
82
90
|
];
|
|
83
91
|
});
|
|
@@ -200,6 +208,7 @@ const StructurePickerRender: BlokRender<(typeof structureCatalog.components)['St
|
|
|
200
208
|
keyOf={keyOf}
|
|
201
209
|
renderRow={renderOption}
|
|
202
210
|
renderValue={renderChosen}
|
|
211
|
+
groupOf={groupOf}
|
|
203
212
|
requires={
|
|
204
213
|
(queried ? declared.includes('requires') : sourceHonoursRequires) ? port?.requires : undefined
|
|
205
214
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { portDescription, portLabel } from "../../engine/portPresentation";
|
|
2
|
+
import { Name } from "../../../vendor/core/ui/name";
|
|
2
3
|
import {
|
|
3
4
|
PAGE_SIZE,
|
|
4
5
|
queryDeclaresPagination,
|
|
@@ -96,7 +97,7 @@ export const ListButtonLabel = (props: {
|
|
|
96
97
|
title="Remove"
|
|
97
98
|
className="group/chip cursor-pointer pr-1.5"
|
|
98
99
|
>
|
|
99
|
-
<
|
|
100
|
+
<Name className="max-w-40" title={`Remove ${l.label}`}>{l.label}</Name>
|
|
100
101
|
<X className="text-muted-foreground transition-colors group-hover/chip:text-foreground" />
|
|
101
102
|
</Badge>
|
|
102
103
|
))}
|
|
@@ -414,7 +415,7 @@ export const ListSearchWidget = (
|
|
|
414
415
|
}
|
|
415
416
|
}}
|
|
416
417
|
>
|
|
417
|
-
{option.label}
|
|
418
|
+
<Name title={option.label}>{option.label}</Name>
|
|
418
419
|
<CheckIcon
|
|
419
420
|
className={cn(
|
|
420
421
|
"ml-auto h-4 w-4",
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import {cleanup, fireEvent, render, screen} from '@testing-library/react';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import {useForm, type FieldValues, type UseFormReturn} from 'react-hook-form';
|
|
5
|
+
import {afterEach, describe, expect, it} from 'vitest';
|
|
6
|
+
|
|
7
|
+
import BlokRenderer from '../../../renderer/BlokRenderer';
|
|
8
|
+
import {testCatalog} from '../../../renderer/bloks/testing';
|
|
9
|
+
import {Form} from '../../../vendor/core/ui/form';
|
|
10
|
+
import {createWidgetRegistry} from '../../engine/defaultRegistry';
|
|
11
|
+
import type {ArgPort} from '../../engine/types';
|
|
12
|
+
import {WidgetRegistryContext, type WidgetRegistryContextType} from '../../engine/WidgetsContext';
|
|
13
|
+
import {configurePortHost} from '../../host';
|
|
14
|
+
import {AssignWidgetKind, PortKind, type BlokAssignWidgetFragment} from '../../rekuest';
|
|
15
|
+
import {argsRead, PortBlokWidget, type PortBlokRendererProps} from './PortBlokWidget';
|
|
16
|
+
import {parseBsx} from '../../../bsx/parse';
|
|
17
|
+
|
|
18
|
+
afterEach(cleanup);
|
|
19
|
+
|
|
20
|
+
const SOURCE = `<Blok kind="port" context="panel">
|
|
21
|
+
<Input bind={port.value} placeholder="exposure" />
|
|
22
|
+
<p>{args.limit}</p>
|
|
23
|
+
<Button onClick={port.set(args.limit)}>Longest</Button>
|
|
24
|
+
<Button onClick={port.reset()}>Back</Button>
|
|
25
|
+
</Blok>`;
|
|
26
|
+
|
|
27
|
+
const port = {__typename: 'ArgPort', key: 'exposure', label: 'Exposure', kind: PortKind.Float, nullable: false, description: 'How long the shutter stays open'} as unknown as ArgPort;
|
|
28
|
+
const widget = (source: string): BlokAssignWidgetFragment => ({__typename: 'BlokAssignWidget', kind: AssignWidgetKind.Blok, source, vocab: 2, fallback: null});
|
|
29
|
+
|
|
30
|
+
/** The renderer an app provides: here with the test catalog, and no agents. */
|
|
31
|
+
const TestRenderer = ({tree, data, writePort, children}: PortBlokRendererProps) => (
|
|
32
|
+
<BlokRenderer uiComponents={[tree]} initialState={data} catalog={testCatalog()} writePort={writePort} chrome="none" sizing="intrinsic">
|
|
33
|
+
{children}
|
|
34
|
+
</BlokRenderer>
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const Harness = ({source, held}: {source: string; held: {form?: UseFormReturn}}) => {
|
|
38
|
+
const form = useForm<FieldValues>({defaultValues: {exposure: 5, limit: 9, gain: 1}});
|
|
39
|
+
held.form = form;
|
|
40
|
+
const registry = React.useMemo(() => createWidgetRegistry() as unknown as WidgetRegistryContextType['registry'], []);
|
|
41
|
+
return (
|
|
42
|
+
<WidgetRegistryContext.Provider value={{registry, setRegistry: () => undefined}}>
|
|
43
|
+
<Form {...form}>
|
|
44
|
+
<PortBlokWidget port={port} widget={widget(source)} path={['exposure']} />
|
|
45
|
+
</Form>
|
|
46
|
+
</WidgetRegistryContext.Provider>
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
describe('a port blok as a field of the form', () => {
|
|
51
|
+
it('reads only the arguments its tree names', () => {
|
|
52
|
+
expect(argsRead(parseBsx(SOURCE).tree)).toEqual(['limit']);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('shows the port and the form, and writes the value of its port and nothing else', () => {
|
|
56
|
+
configurePortHost({PortBlokRenderer: TestRenderer});
|
|
57
|
+
const held: {form?: UseFormReturn} = {};
|
|
58
|
+
render(<Harness source={SOURCE} held={held} />);
|
|
59
|
+
|
|
60
|
+
// The form draws its own label and description around a blok that places none.
|
|
61
|
+
expect(screen.getByText('Exposure')).toBeTruthy();
|
|
62
|
+
expect(screen.getByText('How long the shutter stays open')).toBeTruthy();
|
|
63
|
+
const input = screen.getByPlaceholderText('exposure') as HTMLInputElement;
|
|
64
|
+
expect(input.value).toBe('5');
|
|
65
|
+
expect(screen.getByText('9')).toBeTruthy();
|
|
66
|
+
|
|
67
|
+
// A bound control writes the field, which the form then marks dirty.
|
|
68
|
+
fireEvent.change(input, {target: {value: '7'}});
|
|
69
|
+
expect(held.form?.getValues('exposure')).toBe('7');
|
|
70
|
+
expect(held.form?.getFieldState('exposure').isDirty).toBe(true);
|
|
71
|
+
expect(held.form?.getValues('limit')).toBe(9);
|
|
72
|
+
|
|
73
|
+
// port.set writes it from a callback; port.reset puts back what the form opened with.
|
|
74
|
+
fireEvent.click(screen.getByText('Longest'));
|
|
75
|
+
expect(held.form?.getValues('exposure')).toBe(9);
|
|
76
|
+
fireEvent.click(screen.getByText('Back'));
|
|
77
|
+
expect(held.form?.getValues('exposure')).toBe(5);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('falls back to the port’s own control where the source is no port blok', () => {
|
|
81
|
+
configurePortHost({PortBlokRenderer: TestRenderer});
|
|
82
|
+
const held: {form?: UseFormReturn} = {};
|
|
83
|
+
render(<Harness source={'<Blok kind="agent" context="panel"><Card /></Blok>'} held={held} />);
|
|
84
|
+
|
|
85
|
+
expect(screen.queryByPlaceholderText('exposure')).toBeNull();
|
|
86
|
+
expect(screen.getByText('Exposure')).toBeTruthy();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { parseBsxSafe } from "../../../bsx/parse";
|
|
2
|
+
import BlokRenderer from "../../../renderer/BlokRenderer";
|
|
3
|
+
import { appBlokCatalog } from "../../../renderer/catalog";
|
|
4
|
+
import {
|
|
5
|
+
BlokPortPartsProvider,
|
|
6
|
+
type BlokPortOperation,
|
|
7
|
+
type BlokPortParts,
|
|
8
|
+
} from "../../../renderer/bloks/port/host";
|
|
9
|
+
import { splitPathSegments, useBlokRuntimeStoreApi, type BlokComponentNode } from "../../../renderer/runtime";
|
|
10
|
+
import {
|
|
11
|
+
FormDescription,
|
|
12
|
+
FormField,
|
|
13
|
+
FormItem,
|
|
14
|
+
FormLabel,
|
|
15
|
+
FormMessage,
|
|
16
|
+
} from "../../../vendor/core/ui/form";
|
|
17
|
+
import { portHost } from "../../host";
|
|
18
|
+
import { portDescription, portLabel } from "../../engine/portPresentation";
|
|
19
|
+
import { usePortsRoot } from "../../engine/PortsRootContext";
|
|
20
|
+
import { type InputWidgetProps } from "../../engine/types";
|
|
21
|
+
import { pathToName, recursiveExtract, recursiveSet } from "../../engine/utils";
|
|
22
|
+
import { useWidgetRegistry } from "../../engine/WidgetsContext";
|
|
23
|
+
import { type AssignWidgetFragment, type BlokAssignWidgetFragment } from "../../rekuest";
|
|
24
|
+
import * as React from "react";
|
|
25
|
+
import { useController, useFormContext, useWatch } from "react-hook-form";
|
|
26
|
+
|
|
27
|
+
/** The root a port blok reads its port under, and the field of it a control writes. */
|
|
28
|
+
const PORT_ROOT = "port";
|
|
29
|
+
const PORT_VALUE = "value";
|
|
30
|
+
const ARGS_ROOT = "args";
|
|
31
|
+
|
|
32
|
+
/** What a host that knows a run's agents is handed to draw a port blok with (`PortHost.PortBlokRenderer`). */
|
|
33
|
+
export type PortBlokRendererProps = {
|
|
34
|
+
/** The blok: one `<Blok kind="port">`, as its source parsed. */
|
|
35
|
+
tree: BlokComponentNode;
|
|
36
|
+
/** `port` (the port record) and `args` (the form's other arguments the blok reads). */
|
|
37
|
+
data: Record<string, unknown>;
|
|
38
|
+
/** `port.set(...)`, `port.clear()`, `port.reset()`, `port.touch()`. */
|
|
39
|
+
writePort: (operation: BlokPortOperation, value?: unknown) => unknown;
|
|
40
|
+
/** Hands what the blok wrote to `port.value` over to the form; render it inside the renderer. */
|
|
41
|
+
children: React.ReactNode;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** A port blok drawn with no agents and no service: `deps` are unbound, queries do not run. */
|
|
45
|
+
export const DefaultPortBlokRenderer = ({ tree, data, writePort, children }: PortBlokRendererProps) => (
|
|
46
|
+
<BlokRenderer uiComponents={[tree]} initialState={data} catalog={appBlokCatalog()} writePort={writePort} chrome="none" sizing="intrinsic">
|
|
47
|
+
{children}
|
|
48
|
+
</BlokRenderer>
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
/** The `args.<key>` a tree reads, so the form is watched for exactly those fields. */
|
|
52
|
+
export const argsRead = (tree: BlokComponentNode): string[] => {
|
|
53
|
+
const keys = new Set<string>();
|
|
54
|
+
const read = (path: unknown) => {
|
|
55
|
+
if (typeof path !== "string") return;
|
|
56
|
+
const [root, key] = path.split(".");
|
|
57
|
+
if (root === ARGS_ROOT && key) keys.add(key);
|
|
58
|
+
};
|
|
59
|
+
const walkArgument = (argument: unknown) => {
|
|
60
|
+
if (argument === null || typeof argument !== "object") return;
|
|
61
|
+
const entry = argument as Record<string, unknown>;
|
|
62
|
+
read(entry.value_path);
|
|
63
|
+
for (const call of [entry.util_call, entry.agent_call]) {
|
|
64
|
+
const nested = (call as { arguments?: unknown[] } | null | undefined)?.arguments;
|
|
65
|
+
if (Array.isArray(nested)) nested.forEach(walkArgument);
|
|
66
|
+
}
|
|
67
|
+
for (const list of [entry.value_list, entry.value_dict]) if (Array.isArray(list)) list.forEach(walkArgument);
|
|
68
|
+
};
|
|
69
|
+
const walk = (node: BlokComponentNode) => {
|
|
70
|
+
for (const prop of node.props ?? []) {
|
|
71
|
+
const entry = prop as unknown as Record<string, unknown>;
|
|
72
|
+
read((entry.dynamic_value as { path?: unknown } | null | undefined)?.path);
|
|
73
|
+
for (const call of [entry.util_call, entry.agent_call]) {
|
|
74
|
+
const nested = (call as { arguments?: unknown[] } | null | undefined)?.arguments;
|
|
75
|
+
if (Array.isArray(nested)) nested.forEach(walkArgument);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
(node.children ?? []).forEach(walk);
|
|
79
|
+
};
|
|
80
|
+
walk(tree);
|
|
81
|
+
return [...keys].sort();
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Inside the renderer: what a control wrote to `port.value` is handed to the form, which owns
|
|
86
|
+
* the value, and taken back out of the blok's runtime (the form's own update is what it shows).
|
|
87
|
+
*/
|
|
88
|
+
const PortValueHandover = ({ onValue }: { onValue: (next: unknown) => void }) => {
|
|
89
|
+
const store = useBlokRuntimeStoreApi();
|
|
90
|
+
const onValueRef = React.useRef(onValue);
|
|
91
|
+
React.useEffect(() => {
|
|
92
|
+
onValueRef.current = onValue;
|
|
93
|
+
});
|
|
94
|
+
React.useEffect(() => {
|
|
95
|
+
let handingOver = false;
|
|
96
|
+
return store.subscribe(state => {
|
|
97
|
+
if (handingOver) return;
|
|
98
|
+
const written = Object.keys(state.runtimePathValues).filter(path => {
|
|
99
|
+
const [root, field] = splitPathSegments(path);
|
|
100
|
+
return root === PORT_ROOT && field === PORT_VALUE;
|
|
101
|
+
});
|
|
102
|
+
if (written.length === 0) return;
|
|
103
|
+
const port = (state.dataModel as Record<string, unknown> | undefined)?.[PORT_ROOT] as Record<string, unknown> | undefined;
|
|
104
|
+
const next = port?.[PORT_VALUE];
|
|
105
|
+
handingOver = true;
|
|
106
|
+
try {
|
|
107
|
+
written.forEach(path => store.getState().clearRuntimeValue(path));
|
|
108
|
+
} finally {
|
|
109
|
+
handingOver = false;
|
|
110
|
+
}
|
|
111
|
+
onValueRef.current(next);
|
|
112
|
+
});
|
|
113
|
+
}, [store]);
|
|
114
|
+
return null;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
type PortBlokFieldProps = InputWidgetProps<BlokAssignWidgetFragment> & {
|
|
118
|
+
tree: BlokComponentNode;
|
|
119
|
+
/** The port as the form draws it without its blok: what `<control />` places. */
|
|
120
|
+
control: React.ReactNode;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* A port blok as a field of the form. The form owns everything about the field: its value, whether
|
|
125
|
+
* it was touched or changed, what is wrong with it. The blok is shown that as `port`, writes the
|
|
126
|
+
* value through `bind={port.value}` or `port.set(...)`, and places the form's own label,
|
|
127
|
+
* description and message where it wants them; what it does not place, the form draws around it.
|
|
128
|
+
*/
|
|
129
|
+
const PortBlokField = ({ port, widget, path, options, tree, control }: PortBlokFieldProps) => {
|
|
130
|
+
const form = useFormContext();
|
|
131
|
+
const portsRoot = usePortsRoot();
|
|
132
|
+
const name = pathToName(path);
|
|
133
|
+
const { field, fieldState } = useController({ control: form.control, name });
|
|
134
|
+
|
|
135
|
+
// Only the arguments the blok reads are watched: another field changing redraws nothing here.
|
|
136
|
+
const read = React.useMemo(() => argsRead(tree), [tree]);
|
|
137
|
+
const readKey = read.join("\n");
|
|
138
|
+
const names = React.useMemo(
|
|
139
|
+
() => (readKey ? readKey.split("\n") : []).map(key => pathToName([...portsRoot, key])),
|
|
140
|
+
[readKey, portsRoot],
|
|
141
|
+
);
|
|
142
|
+
const watched = useWatch({ control: form.control, name: names }) as unknown[];
|
|
143
|
+
|
|
144
|
+
const editable = options?.disable !== true && field.disabled !== true;
|
|
145
|
+
const value = recursiveExtract(field.value, port);
|
|
146
|
+
const snapshot = JSON.stringify([value, watched, fieldState.error?.message ?? null, fieldState.isTouched, fieldState.isDirty, editable]);
|
|
147
|
+
const data = React.useMemo(
|
|
148
|
+
() => ({
|
|
149
|
+
[ARGS_ROOT]: Object.fromEntries(read.map((key, index) => [key, watched[index] ?? null])),
|
|
150
|
+
[PORT_ROOT]: {
|
|
151
|
+
value: value ?? null,
|
|
152
|
+
key: port.key,
|
|
153
|
+
label: portLabel(port),
|
|
154
|
+
description: port.description ?? null,
|
|
155
|
+
kind: port.kind,
|
|
156
|
+
identifier: port.identifier ?? null,
|
|
157
|
+
nullable: port.nullable === true,
|
|
158
|
+
default: port.default ?? null,
|
|
159
|
+
choices: port.choices ?? [],
|
|
160
|
+
unit: (port as { referenceUnit?: string | null }).referenceUnit ?? null,
|
|
161
|
+
editable,
|
|
162
|
+
error: fieldState.error?.message ?? null,
|
|
163
|
+
invalid: fieldState.invalid,
|
|
164
|
+
touched: fieldState.isTouched,
|
|
165
|
+
dirty: fieldState.isDirty,
|
|
166
|
+
},
|
|
167
|
+
}),
|
|
168
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
169
|
+
[snapshot, port, readKey],
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
const setValue = React.useCallback(
|
|
173
|
+
(next: unknown) => {
|
|
174
|
+
if (!editable) return;
|
|
175
|
+
// A cleared value is "not given", which the form says with undefined.
|
|
176
|
+
field.onChange(next === null || next === undefined ? undefined : recursiveSet(next, port));
|
|
177
|
+
},
|
|
178
|
+
[editable, field, port],
|
|
179
|
+
);
|
|
180
|
+
const writePort = React.useCallback(
|
|
181
|
+
(operation: BlokPortOperation, next?: unknown) => {
|
|
182
|
+
if (operation === "touch") return field.onBlur();
|
|
183
|
+
if (!editable) return undefined;
|
|
184
|
+
if (operation === "reset") return form.resetField(name);
|
|
185
|
+
return setValue(operation === "clear" ? null : next);
|
|
186
|
+
},
|
|
187
|
+
[editable, field, form, name, setValue],
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
// What the blok places of the form's own parts it draws; the rest is drawn around it.
|
|
191
|
+
const placed = React.useMemo(() => {
|
|
192
|
+
const names = new Set<string>();
|
|
193
|
+
const walk = (node: BlokComponentNode) => {
|
|
194
|
+
names.add(node.component);
|
|
195
|
+
(node.children ?? []).forEach(walk);
|
|
196
|
+
};
|
|
197
|
+
walk(tree);
|
|
198
|
+
return names;
|
|
199
|
+
}, [tree]);
|
|
200
|
+
const widgetRegistry = useWidgetRegistry().registry;
|
|
201
|
+
const parts = React.useMemo<BlokPortParts>(
|
|
202
|
+
() => ({
|
|
203
|
+
renderLabel: () => <FormLabel>{portLabel(port)}</FormLabel>,
|
|
204
|
+
renderDescription: () => (port.description ? <FormDescription>{portDescription(port, widget)}</FormDescription> : null),
|
|
205
|
+
renderMessage: () => <FormMessage />,
|
|
206
|
+
renderControl: () => control,
|
|
207
|
+
renderField: (key: string) => {
|
|
208
|
+
const child = (port.children ?? []).find(candidate => candidate?.key === key);
|
|
209
|
+
if (!child) return null;
|
|
210
|
+
const Child = widgetRegistry.getInputWidgetForPort(child as typeof port);
|
|
211
|
+
return <Child port={child as typeof port} widget={(child as typeof port).widget as AssignWidgetFragment} path={[...path, key]} options={options} />;
|
|
212
|
+
},
|
|
213
|
+
}),
|
|
214
|
+
[port, widget, control, widgetRegistry, path, options],
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
const Renderer = portHost().PortBlokRenderer ?? DefaultPortBlokRenderer;
|
|
218
|
+
|
|
219
|
+
return (
|
|
220
|
+
<FormField
|
|
221
|
+
control={form.control}
|
|
222
|
+
name={name}
|
|
223
|
+
render={() => (
|
|
224
|
+
<FormItem className="flex flex-col">
|
|
225
|
+
{!placed.has("label") && <FormLabel>{portLabel(port)}</FormLabel>}
|
|
226
|
+
<BlokPortPartsProvider value={parts}>
|
|
227
|
+
<Renderer tree={tree} data={data} writePort={writePort}>
|
|
228
|
+
<PortValueHandover onValue={setValue} />
|
|
229
|
+
</Renderer>
|
|
230
|
+
</BlokPortPartsProvider>
|
|
231
|
+
{!placed.has("description") && port.description && <FormDescription>{portDescription(port, widget)}</FormDescription>}
|
|
232
|
+
{!placed.has("message") && <FormMessage />}
|
|
233
|
+
</FormItem>
|
|
234
|
+
)}
|
|
235
|
+
/>
|
|
236
|
+
);
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* A BLOK assign widget: the port's own blok, written in BSX (`<Blok kind="port">`), drawn where
|
|
241
|
+
* the port's control would be.
|
|
242
|
+
*
|
|
243
|
+
* Where it cannot be drawn (its source does not parse here, or is no port blok), the port
|
|
244
|
+
* degrades the way the server intends: through the widget's `fallback` when one is given, else
|
|
245
|
+
* through what the port would get without a widget. Either way the port stays editable.
|
|
246
|
+
*/
|
|
247
|
+
export const PortBlokWidget = (props: InputWidgetProps<BlokAssignWidgetFragment>) => {
|
|
248
|
+
const { registry } = useWidgetRegistry();
|
|
249
|
+
const fallback = (props.widget?.fallback ?? null) as AssignWidgetFragment | null;
|
|
250
|
+
|
|
251
|
+
const { port, Widget } = React.useMemo(() => {
|
|
252
|
+
const port = { ...props.port, widget: fallback } as typeof props.port;
|
|
253
|
+
return { port, Widget: registry.getInputWidgetForPort(port) };
|
|
254
|
+
}, [props.port, fallback, registry]);
|
|
255
|
+
const plain = <Widget {...props} port={port} widget={fallback as AssignWidgetFragment} />;
|
|
256
|
+
|
|
257
|
+
const source = props.widget?.source;
|
|
258
|
+
const tree = React.useMemo(() => {
|
|
259
|
+
if (!source) return null;
|
|
260
|
+
const parsed = parseBsxSafe(source);
|
|
261
|
+
if (!parsed.ok) return null;
|
|
262
|
+
const kind = (parsed.tree.props ?? []).find(prop => prop.key === "kind")?.static_value;
|
|
263
|
+
return parsed.tree.component === "Blok" && kind === PORT_ROOT ? parsed.tree : null;
|
|
264
|
+
}, [source]);
|
|
265
|
+
if (tree === null) return plain;
|
|
266
|
+
|
|
267
|
+
return <PortBlokField {...props} tree={tree} control={plain} />;
|
|
268
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { portDescription, portLabel } from "../../engine/portPresentation";
|
|
2
|
+
import { Name } from "../../../vendor/core/ui/name";
|
|
2
3
|
import { Badge } from "../../../vendor/core/ui/badge";
|
|
3
4
|
import { type SearchAssignWidgetFragment } from "../../rekuest";
|
|
4
5
|
import useWidgetDependencies from "../../engine/useWidgetDependencies";
|
|
@@ -88,7 +89,7 @@ export const ButtonLabel = (props: {
|
|
|
88
89
|
{loading && !option && !error && (
|
|
89
90
|
<span className="h-3 w-24 animate-pulse rounded-full bg-muted-foreground/20" />
|
|
90
91
|
)}
|
|
91
|
-
{option?.label && <
|
|
92
|
+
{option?.label && <Name title={option.label}>{option.label}</Name>}
|
|
92
93
|
{error && (
|
|
93
94
|
<span className="flex items-center gap-1 text-xs text-destructive shrink-0">
|
|
94
95
|
<AlertCircle className="h-3 w-3 shrink-0" />
|
|
@@ -395,7 +396,7 @@ export const SearchWidget = (
|
|
|
395
396
|
setOpen(false);
|
|
396
397
|
}}
|
|
397
398
|
>
|
|
398
|
-
{option.label}
|
|
399
|
+
<Name title={option.label}>{option.label}</Name>
|
|
399
400
|
<CheckIcon
|
|
400
401
|
className={cn(
|
|
401
402
|
"ml-auto h-4 w-4",
|