@arkitektio/bsx 6.5.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.
Files changed (52) hide show
  1. package/dist/ports/forms/ListSearchField.d.ts.map +1 -1
  2. package/dist/ports/forms/ListSearchField.js +4 -2
  3. package/dist/ports/forms/ListSearchField.js.map +1 -1
  4. package/dist/ports/forms/SearchField.d.ts.map +1 -1
  5. package/dist/ports/forms/SearchField.js +4 -2
  6. package/dist/ports/forms/SearchField.js.map +1 -1
  7. package/dist/ports/forms/StructurePickerControl.d.ts +16 -1
  8. package/dist/ports/forms/StructurePickerControl.d.ts.map +1 -1
  9. package/dist/ports/forms/StructurePickerControl.js +26 -3
  10. package/dist/ports/forms/StructurePickerControl.js.map +1 -1
  11. package/dist/ports/rekuest.d.ts +11 -6
  12. package/dist/ports/rekuest.d.ts.map +1 -1
  13. package/dist/ports/structure/Structure.d.ts.map +1 -1
  14. package/dist/ports/structure/Structure.js +7 -4
  15. package/dist/ports/structure/Structure.js.map +1 -1
  16. package/dist/ports/widgets/custom/ListSearchWidget.d.ts.map +1 -1
  17. package/dist/ports/widgets/custom/ListSearchWidget.js +3 -2
  18. package/dist/ports/widgets/custom/ListSearchWidget.js.map +1 -1
  19. package/dist/ports/widgets/custom/SearchWidget.d.ts.map +1 -1
  20. package/dist/ports/widgets/custom/SearchWidget.js +3 -2
  21. package/dist/ports/widgets/custom/SearchWidget.js.map +1 -1
  22. package/dist/ports/widgets/fallbacks/EnumWidget.d.ts.map +1 -1
  23. package/dist/ports/widgets/fallbacks/EnumWidget.js +5 -1
  24. package/dist/ports/widgets/fallbacks/EnumWidget.js.map +1 -1
  25. package/dist/renderer/bloks/scene/Model.d.ts.map +1 -1
  26. package/dist/renderer/bloks/scene/Model.js +16 -2
  27. package/dist/renderer/bloks/scene/Model.js.map +1 -1
  28. package/dist/vendor/core/ui/name.d.ts +30 -0
  29. package/dist/vendor/core/ui/name.d.ts.map +1 -0
  30. package/dist/vendor/core/ui/name.js +40 -0
  31. package/dist/vendor/core/ui/name.js.map +1 -0
  32. package/dist/vendor/core/ui/overflow-tooltip.d.ts +20 -0
  33. package/dist/vendor/core/ui/overflow-tooltip.d.ts.map +1 -0
  34. package/dist/vendor/core/ui/overflow-tooltip.js +27 -0
  35. package/dist/vendor/core/ui/overflow-tooltip.js.map +1 -0
  36. package/dist/vendor/core/ui/select.js +3 -3
  37. package/dist/vendor/core/ui/select.js.map +1 -1
  38. package/package.json +1 -1
  39. package/src/ports/forms/ListSearchField.tsx +12 -9
  40. package/src/ports/forms/SearchField.tsx +9 -3
  41. package/src/ports/forms/StructurePickerControl.test.tsx +29 -1
  42. package/src/ports/forms/StructurePickerControl.tsx +38 -4
  43. package/src/ports/rekuest.ts +7 -7
  44. package/src/ports/structure/Structure.tsx +14 -5
  45. package/src/ports/widgets/custom/ListSearchWidget.tsx +3 -2
  46. package/src/ports/widgets/custom/SearchWidget.tsx +3 -2
  47. package/src/ports/widgets/fallbacks/EnumWidget.test.tsx +89 -0
  48. package/src/ports/widgets/fallbacks/EnumWidget.tsx +38 -13
  49. package/src/renderer/bloks/scene/Model.tsx +15 -2
  50. package/src/vendor/core/ui/name.tsx +69 -0
  51. package/src/vendor/core/ui/overflow-tooltip.tsx +59 -0
  52. package/src/vendor/core/ui/select.tsx +3 -3
@@ -1,4 +1,5 @@
1
1
  import { CheckIcon } from "lucide-react";
2
+ import { Name } from "../../vendor/core/ui/name";
2
3
 
3
4
  import {
4
5
  Command,
@@ -19,6 +20,7 @@ import { cn, notEmpty } from "../../vendor/core/util/utils";
19
20
  import { useCallback, useEffect, useRef, useState } from "react";
20
21
  import { useFormContext } from "react-hook-form";
21
22
  import { Badge } from "../../vendor/core/ui/badge";
23
+ import { OverflowTooltip } from "../../vendor/core/ui/overflow-tooltip";
22
24
  import { type FieldProps } from "./types";
23
25
 
24
26
  export type Option = {
@@ -59,15 +61,16 @@ export const ListButtonLabel = (props: {
59
61
  };
60
62
 
61
63
  return (
62
- <div className="gap-2 flex flex-row p-1">
64
+ <div className="flex min-w-0 flex-row flex-wrap gap-2 p-1">
63
65
  {options.map((l, index) => (
64
- <Badge
65
- key={index}
66
- onClick={() => remove(l.value)}
67
- className="cursor-pointer px-1 py-1 bg-muted my-2"
68
- >
69
- {l.label}
70
- </Badge>
66
+ <OverflowTooltip key={index} content={l.label}>
67
+ <Badge
68
+ onClick={() => remove(l.value)}
69
+ className="cursor-pointer px-1 py-1 bg-muted my-2 max-w-full"
70
+ >
71
+ <Name>{l.label}</Name>
72
+ </Badge>
73
+ </OverflowTooltip>
71
74
  ))}
72
75
  {error}
73
76
  </div>
@@ -253,7 +256,7 @@ export const ListSearchField = ({
253
256
  setInputValue("");
254
257
  }}
255
258
  >
256
- {option.label}
259
+ <Name title={option.label}>{option.label}</Name>
257
260
  <CheckIcon
258
261
  className={cn(
259
262
  "ml-auto h-4 w-4",
@@ -1,4 +1,5 @@
1
1
  import { CheckIcon } from "lucide-react";
2
+ import { Name } from "../../vendor/core/ui/name";
2
3
 
3
4
  import {
4
5
  Command,
@@ -20,6 +21,7 @@ import {
20
21
  PopoverAnchor,
21
22
  PopoverContent,
22
23
  } from "../../vendor/core/ui/popover";
24
+ import { OverflowTooltip } from "../../vendor/core/ui/overflow-tooltip";
23
25
  import { useLatestRef } from "../../vendor/core/util/hooks/useLatestRef";
24
26
  import { cn, notEmpty } from "../../vendor/core/util/utils";
25
27
  import { useCallback, useEffect, useRef, useState } from "react";
@@ -64,8 +66,12 @@ export const ButtonLabel = (props: {
64
66
  }, [props.value, props.searchKey]);
65
67
 
66
68
  return (
67
- <div className="flex flex-row items-center">
68
- {option?.label && <div className="text-foreground">{option.label}</div>}
69
+ <div className="flex min-w-0 flex-row items-center">
70
+ {option?.label && (
71
+ <OverflowTooltip content={option.label}>
72
+ <Name className="text-foreground">{option.label}</Name>
73
+ </OverflowTooltip>
74
+ )}
69
75
  {error}
70
76
  </div>
71
77
  );
@@ -287,7 +293,7 @@ export const SearchField = ({
287
293
  setOpen(false);
288
294
  }}
289
295
  >
290
- {option.label}
296
+ <Name title={option.label}>{option.label}</Name>
291
297
  <CheckIcon
292
298
  className={cn(
293
299
  "ml-auto h-4 w-4",
@@ -27,7 +27,7 @@ vi.mock("../../vendor/core/ui/command", () => ({
27
27
  ),
28
28
  }));
29
29
 
30
- import { PICKER_PAGE_SIZE, StructurePickerControl, type PickerRequest, type PickerScope } from "./StructurePickerControl";
30
+ import { PICKER_PAGE_SIZE, StructurePickerControl, groupItems, type PickerRequest, type PickerScope } from "./StructurePickerControl";
31
31
 
32
32
  afterEach(cleanup);
33
33
 
@@ -109,3 +109,31 @@ describe("the structure picker control", () => {
109
109
  expect(load).toHaveBeenCalledTimes(1);
110
110
  });
111
111
  });
112
+
113
+ describe("groupItems", () => {
114
+ type Lens = { id: string; group?: string };
115
+ const groupOf = (lens: Lens) => lens.group;
116
+ const ids = (buckets: { group: string | undefined; items: Lens[] }[]) =>
117
+ buckets.map((bucket) => [bucket.group, bucket.items.map((lens) => lens.id)]);
118
+
119
+ it("is one headless bucket when nothing is grouped", () => {
120
+ expect(ids(groupItems([{ id: "1" }, { id: "2" }], groupOf))).toEqual([[undefined, ["1", "2"]]]);
121
+ expect(ids(groupItems([{ id: "1", group: "a" }]))).toEqual([[undefined, ["1"]]]);
122
+ expect(groupItems([], groupOf)).toEqual([]);
123
+ });
124
+
125
+ it("opens a group where it first appears and adds a later page to it", () => {
126
+ const page1 = [{ id: "1", group: "Series001" }, { id: "2", group: "Series002" }];
127
+ const page2 = [{ id: "3", group: "Series001" }, { id: "4", group: "Series003" }];
128
+ expect(ids(groupItems([...page1, ...page2], groupOf))).toEqual([
129
+ ["Series001", ["1", "3"]],
130
+ ["Series002", ["2"]],
131
+ ["Series003", ["4"]],
132
+ ]);
133
+ });
134
+
135
+ it("lists the ungrouped first, and a blank group is no group", () => {
136
+ const items = [{ id: "1", group: "a" }, { id: "2" }, { id: "3", group: " " }];
137
+ expect(ids(groupItems(items, groupOf))).toEqual([[undefined, ["2", "3"]], ["a", ["1"]]]);
138
+ });
139
+ });
@@ -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.length > 0 && (
274
- <CommandGroup>
275
- {items.map((item) => {
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…" : ""}
@@ -72,7 +72,7 @@ export const ReturnWidgetKind = {
72
72
  } as const;
73
73
  export type ReturnWidgetKind = (typeof ReturnWidgetKind)[keyof typeof ReturnWidgetKind];
74
74
 
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?: (
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 | (
76
76
  { __typename?: 'ChoiceAssignWidget' }
77
77
  & AssignWidget_ChoiceAssignWidget_Fragment
78
78
  ) | (
@@ -93,7 +93,7 @@ export type ArgChildPortDeepFragment = { __typename: 'ArgPort', kind: PortKind,
93
93
  ) | (
94
94
  { __typename?: 'StringAssignWidget' }
95
95
  & AssignWidget_StringAssignWidget_Fragment
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?: (
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 | (
97
97
  { __typename?: 'ChoiceAssignWidget' }
98
98
  & AssignWidget_ChoiceAssignWidget_Fragment
99
99
  ) | (
@@ -119,7 +119,7 @@ export type ArgChildPortDeepFragment = { __typename: 'ArgPort', kind: PortKind,
119
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<(
120
120
  { __typename?: 'ArgPort' }
121
121
  & ArgChildPortNestedFragment
122
- )> | null, widget?: (
122
+ )> | null, widget?: BlokAssignWidgetFragment | (
123
123
  { __typename?: 'ChoiceAssignWidget' }
124
124
  & AssignWidget_ChoiceAssignWidget_Fragment
125
125
  ) | (
@@ -157,7 +157,7 @@ export type ArgChildPortFragment = { __typename: 'ArgPort', kind: PortKind, key:
157
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<(
158
158
  { __typename?: 'ArgPort' }
159
159
  & ArgChildPortDeepFragment
160
- )> | 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 | (
161
161
  { __typename?: 'ChoiceAssignWidget' }
162
162
  & AssignWidget_ChoiceAssignWidget_Fragment
163
163
  ) | (
@@ -201,7 +201,7 @@ export type ArgPortFragment = { __typename: 'ArgPort', key: string, label?: stri
201
201
  ) | (
202
202
  { __typename?: 'MessageEffect' }
203
203
  & PortEffect_MessageEffect_Fragment
204
- )> | null, widget?: (
204
+ )> | null, widget?: BlokAssignWidgetFragment | (
205
205
  { __typename?: 'ChoiceAssignWidget' }
206
206
  & AssignWidget_ChoiceAssignWidget_Fragment
207
207
  ) | (
@@ -332,7 +332,7 @@ export type ChoiceReturnWidgetFragment = { __typename: 'ChoiceReturnWidget', kin
332
332
  export type CustomAssignWidgetFragment = { __typename: 'CustomAssignWidget', kind: AssignWidgetKind, followValue?: string | null, component: string, children?: any | null, dependencies?: Array<string> | null, props?: Array<(
333
333
  { __typename?: 'ComponentProp' }
334
334
  & BlokComponentPropFragment
335
- )> | null, fallback?: (
335
+ )> | null, fallback?: { __typename: 'BlokAssignWidget', kind: AssignWidgetKind } | (
336
336
  { __typename: 'ChoiceAssignWidget', kind: AssignWidgetKind }
337
337
  & ChoiceAssignWidgetFragment
338
338
  ) | { __typename: 'CustomAssignWidget', kind: AssignWidgetKind } | (
@@ -362,7 +362,7 @@ export type CustomReturnWidgetFragment = { __typename: 'CustomReturnWidget', kin
362
362
  & BlokComponentPropFragment
363
363
  )> | null };
364
364
 
365
- 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 };
366
366
 
367
367
  export type HideEffectFragment = (
368
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
- <span className="truncate">{option.label}</span>
46
+ <Name title={option.label}>{option.label}</Name>
46
47
  {option.description && (
47
- <span className="truncate text-xs text-muted-foreground">{option.description}</span>
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 renderChosen = (option: Option) => <span className="truncate">{option.label}</span>;
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
- <span className="max-w-40 truncate">{l.label}</span>
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",
@@ -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 && <span className="truncate">{option.label}</span>}
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",
@@ -0,0 +1,89 @@
1
+ // @vitest-environment jsdom
2
+ import { act, cleanup, fireEvent, render, screen } from "@testing-library/react";
3
+ import { FormProvider, useForm } from "react-hook-form";
4
+ import { afterEach, describe, expect, it, vi } from "vitest";
5
+
6
+ vi.mock("../../rekuest", () => ({ PortKind: { Enum: "ENUM" } }));
7
+
8
+ import type { InputWidgetProps } from "../../engine/types";
9
+ import { ChoicePortField } from "./EnumWidget";
10
+
11
+ const LONG = "A choice whose label is far too long for the column it sits in";
12
+
13
+ const portWith = (choices: { value: string; label: string; description?: string }[]) =>
14
+ ({ key: "mode", kind: "ENUM", label: "Mode", choices }) as unknown as InputWidgetProps["port"];
15
+
16
+ const Harness = ({ port, value }: { port: InputWidgetProps["port"]; value?: string }) => {
17
+ const form = useForm({ defaultValues: { mode: value } });
18
+ return (
19
+ <FormProvider {...form}>
20
+ <ChoicePortField port={port} widget={null as never} path={["mode"]} />
21
+ </FormProvider>
22
+ );
23
+ };
24
+
25
+ /** jsdom lays nothing out: say every marked text is (or is not) cut off. */
26
+ const cutOff = (yes: boolean) => {
27
+ vi.spyOn(HTMLElement.prototype, "scrollWidth", "get").mockImplementation(function (
28
+ this: HTMLElement,
29
+ ) {
30
+ return yes && this.hasAttribute("data-overflow-text") ? 200 : 0;
31
+ });
32
+ vi.spyOn(HTMLElement.prototype, "clientWidth", "get").mockReturnValue(0);
33
+ };
34
+
35
+ const tooltip = () => document.querySelector("[data-slot=tooltip-content]");
36
+
37
+ afterEach(() => {
38
+ cleanup();
39
+ vi.restoreAllMocks();
40
+ });
41
+
42
+ describe("ChoicePortField: segmented", () => {
43
+ const port = portWith([
44
+ { value: "a", label: LONG },
45
+ { value: "b", label: "Short", description: "What short does" },
46
+ ]);
47
+
48
+ it("shows no tooltip for a label that fits", () => {
49
+ cutOff(false);
50
+ render(<Harness port={port} />);
51
+ act(() => void fireEvent.focus(screen.getByRole("radio", { name: LONG })));
52
+ expect(tooltip()).toBeNull();
53
+ });
54
+
55
+ it("shows the whole label when it is cut off", () => {
56
+ cutOff(true);
57
+ render(<Harness port={port} />);
58
+ act(() => void fireEvent.focus(screen.getByRole("radio", { name: LONG })));
59
+ expect(tooltip()?.textContent).toContain(LONG);
60
+ });
61
+
62
+ it("always shows a choice's description, under its label", () => {
63
+ cutOff(false);
64
+ render(<Harness port={port} />);
65
+ act(() => void fireEvent.focus(screen.getByRole("radio", { name: "Short" })));
66
+ expect(tooltip()?.textContent).toContain("Short");
67
+ expect(tooltip()?.textContent).toContain("What short does");
68
+ });
69
+ });
70
+
71
+ describe("ChoicePortField: select", () => {
72
+ const port = portWith(
73
+ Array.from({ length: 6 }, (_, i) => ({ value: `v${i}`, label: i === 2 ? LONG : `Choice ${i}` })),
74
+ );
75
+
76
+ it("shows the chosen label when the trigger cuts it off", () => {
77
+ cutOff(true);
78
+ render(<Harness port={port} value="v2" />);
79
+ act(() => void fireEvent.focus(screen.getByRole("combobox")));
80
+ expect(tooltip()?.textContent).toContain(LONG);
81
+ });
82
+
83
+ it("shows nothing when the chosen label fits", () => {
84
+ cutOff(false);
85
+ render(<Harness port={port} value="v2" />);
86
+ act(() => void fireEvent.focus(screen.getByRole("combobox")));
87
+ expect(tooltip()).toBeNull();
88
+ });
89
+ });
@@ -1,4 +1,5 @@
1
1
  import { SearchField, type SearchOptions } from "../../forms/SearchField";
2
+ import { Name } from "../../../vendor/core/ui/name";
2
3
  import {
3
4
  choicePresentation,
4
5
  portDescription,
@@ -24,6 +25,7 @@ import {
24
25
  SelectValue,
25
26
  } from "../../../vendor/core/ui/select";
26
27
  import { ToggleGroup, ToggleGroupItem } from "../../../vendor/core/ui/toggle-group";
28
+ import { OVERFLOW_TEXT, OverflowTooltip } from "../../../vendor/core/ui/overflow-tooltip";
27
29
  import { notEmpty } from "../../../vendor/core/util/utils";
28
30
  import { X } from "lucide-react";
29
31
  import { useCallback, useMemo } from "react";
@@ -31,6 +33,14 @@ import { useFormContext } from "react-hook-form";
31
33
 
32
34
  type Choice = { value: string; label: string; description?: string | null };
33
35
 
36
+ /** What a cut-off choice shows on hover: its whole label, then its description. */
37
+ const ChoiceTip = ({ choice }: { choice: Choice }) => (
38
+ <div className="flex flex-col gap-0.5">
39
+ <span className="font-medium">{choice.label}</span>
40
+ {choice.description && <span className="opacity-80">{choice.description}</span>}
41
+ </div>
42
+ );
43
+
34
44
  /**
35
45
  * A port's `choices`, shown by how many there are: a few sit side by side,
36
46
  * a handful go in a dropdown, a long list is searched. The stored value is
@@ -102,29 +112,44 @@ export const ChoicePortField = (props: InputWidgetProps) => {
102
112
  className="w-full"
103
113
  >
104
114
  {choices.map((choice) => (
105
- <ToggleGroupItem
115
+ <OverflowTooltip
106
116
  key={choice.value}
107
- value={choice.value}
108
- title={choice.description ?? undefined}
109
- className="min-w-0 flex-1 px-2"
117
+ content={<ChoiceTip choice={choice} />}
118
+ always={!!choice.description}
110
119
  >
111
- <span className="truncate">{choice.label}</span>
112
- </ToggleGroupItem>
120
+ <ToggleGroupItem
121
+ value={choice.value}
122
+ aria-label={choice.label}
123
+ className="min-w-0 flex-1 px-2"
124
+ >
125
+ <Name>{choice.label}</Name>
126
+ </ToggleGroupItem>
127
+ </OverflowTooltip>
113
128
  ))}
114
129
  </ToggleGroup>
115
130
  </FormControl>
116
131
  ) : (
117
- <div className="flex items-center gap-1">
132
+ <div className="flex min-w-0 items-center gap-1">
118
133
  <Select value={value} onValueChange={field.onChange}>
119
- <FormControl>
120
- <SelectTrigger className="w-full min-w-0">
121
- <SelectValue placeholder={placeholder} />
122
- </SelectTrigger>
123
- </FormControl>
134
+ <OverflowTooltip
135
+ content={chosen ? <ChoiceTip choice={chosen} /> : placeholder}
136
+ >
137
+ <FormControl>
138
+ <SelectTrigger className="w-full min-w-0">
139
+ <SelectValue {...OVERFLOW_TEXT} placeholder={placeholder} />
140
+ </SelectTrigger>
141
+ </FormControl>
142
+ </OverflowTooltip>
124
143
  <SelectContent>
125
144
  {choices.map((choice) => (
126
145
  <SelectItem key={choice.value} value={choice.value}>
127
- {choice.label}
146
+ {/* Wraps in the list; cut off (with a tooltip) in the trigger. */}
147
+ <span
148
+ {...OVERFLOW_TEXT}
149
+ className="in-data-[slot=select-value]:min-w-0 in-data-[slot=select-value]:truncate"
150
+ >
151
+ {choice.label}
152
+ </span>
128
153
  </SelectItem>
129
154
  ))}
130
155
  </SelectContent>
@@ -60,8 +60,21 @@ const Placeholder = ({reason, source}: {reason: string; source?: BlokAssetSource
60
60
  const CLICK_SLOP_PX = 4;
61
61
 
62
62
  const HoverBox = ({node}: {node: THREE.Object3D}) => {
63
- const helper = React.useMemo(() => new THREE.BoxHelper(node, 0x38bdf8), [node]);
64
- useFrame(() => helper.update());
63
+ const helper = React.useMemo(() => {
64
+ const made = new THREE.BoxHelper(node, 0x38bdf8);
65
+ // Its corners are world coordinates already: it must not also take the pose of
66
+ // whatever it is mounted in (a placement in a space), so its own matrix undoes that.
67
+ made.matrixAutoUpdate = false;
68
+ return made;
69
+ }, [node]);
70
+ useFrame(() => {
71
+ helper.update();
72
+ const parent = helper.parent;
73
+ if (!parent) return;
74
+ parent.updateWorldMatrix(true, false);
75
+ helper.matrix.copy(parent.matrixWorld).invert();
76
+ helper.matrixWorldNeedsUpdate = true;
77
+ });
65
78
  React.useEffect(() => () => helper.dispose(), [helper]);
66
79
  return <primitive object={helper} />;
67
80
  };
@@ -0,0 +1,69 @@
1
+ import * as React from "react"
2
+
3
+ import { cn } from "../util/utils"
4
+
5
+ /** `.tiff`, `.ome.tiff`, `.tar.gz`: up to two short alphanumeric suffixes. */
6
+ const EXTENSION = /(?:\.[A-Za-z0-9]{1,5}){1,2}$/
7
+
8
+ /**
9
+ * Where a long name is cut so both ends stay readable: the tail is the last
10
+ * `keep` characters before the extension plus the extension, the head is the
11
+ * rest. A name too short to be worth cutting comes back whole, as the head.
12
+ */
13
+ export const splitName = (name: string, keep = 8): { head: string; tail: string } => {
14
+ const match = EXTENSION.exec(name)
15
+ // A dotfile (`.gitignore`) is all name, no extension.
16
+ const extension = match && match.index > 0 ? match[0] : ""
17
+ // By code point, so a surrogate pair is never cut in half.
18
+ const stem = Array.from(name.slice(0, name.length - extension.length))
19
+ if (keep <= 0 || stem.length <= keep * 2) return { head: name, tail: "" }
20
+ return {
21
+ head: stem.slice(0, stem.length - keep).join(""),
22
+ tail: stem.slice(stem.length - keep).join("") + extension,
23
+ }
24
+ }
25
+
26
+ /**
27
+ * A name that keeps its start AND its end when it does not fit: the head
28
+ * gives way with an ellipsis, the tail (the last characters and the
29
+ * extension) never shrinks. Plain CSS, nothing is measured. When the name
30
+ * fits it reads as ordinary text; copying copies it whole.
31
+ *
32
+ * The head carries `data-overflow-text`, so inside an `OverflowTooltip` the
33
+ * tooltip opens exactly when the name is cut; elsewhere pass `title`.
34
+ * Like `truncate`, it needs `min-w-0` on every flex ancestor up to the one
35
+ * with a real width.
36
+ */
37
+ function Name({
38
+ children,
39
+ keep,
40
+ inline = false,
41
+ className,
42
+ ...props
43
+ }: Omit<React.ComponentProps<"span">, "children"> & {
44
+ children: string
45
+ /** Characters kept before the extension (default 8). */
46
+ keep?: number
47
+ /** Sit in a line of text instead of filling the row. */
48
+ inline?: boolean
49
+ }) {
50
+ const { head, tail } = splitName(children, keep)
51
+ return (
52
+ <span
53
+ data-slot="name"
54
+ className={cn(
55
+ inline ? "inline-flex align-bottom" : "flex",
56
+ "min-w-0 max-w-full overflow-hidden",
57
+ className
58
+ )}
59
+ {...props}
60
+ >
61
+ <span data-overflow-text="" className="min-w-0 truncate whitespace-pre">
62
+ {head}
63
+ </span>
64
+ {tail && <span className="shrink-0 whitespace-pre">{tail}</span>}
65
+ </span>
66
+ )
67
+ }
68
+
69
+ export { Name }