@arkitektio/bsx 6.5.0 → 6.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) 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/AsyncBoundary.d.ts.map +1 -1
  29. package/dist/vendor/core/ui/AsyncBoundary.js +1 -1
  30. package/dist/vendor/core/ui/AsyncBoundary.js.map +1 -1
  31. package/dist/vendor/core/ui/button.d.ts +1 -1
  32. package/dist/vendor/core/ui/button.d.ts.map +1 -1
  33. package/dist/vendor/core/ui/button.js +10 -2
  34. package/dist/vendor/core/ui/button.js.map +1 -1
  35. package/dist/vendor/core/ui/markdown.d.ts.map +1 -1
  36. package/dist/vendor/core/ui/markdown.js +1 -1
  37. package/dist/vendor/core/ui/markdown.js.map +1 -1
  38. package/dist/vendor/core/ui/name.d.ts +30 -0
  39. package/dist/vendor/core/ui/name.d.ts.map +1 -0
  40. package/dist/vendor/core/ui/name.js +40 -0
  41. package/dist/vendor/core/ui/name.js.map +1 -0
  42. package/dist/vendor/core/ui/overflow-tooltip.d.ts +20 -0
  43. package/dist/vendor/core/ui/overflow-tooltip.d.ts.map +1 -0
  44. package/dist/vendor/core/ui/overflow-tooltip.js +27 -0
  45. package/dist/vendor/core/ui/overflow-tooltip.js.map +1 -0
  46. package/dist/vendor/core/ui/select.js +3 -3
  47. package/dist/vendor/core/ui/select.js.map +1 -1
  48. package/dist/vendor/core/ui/tooltip.d.ts +1 -1
  49. package/dist/vendor/core/ui/tooltip.d.ts.map +1 -1
  50. package/dist/vendor/core/ui/tooltip.js +5 -2
  51. package/dist/vendor/core/ui/tooltip.js.map +1 -1
  52. package/package.json +1 -1
  53. package/src/ports/forms/ListSearchField.tsx +12 -9
  54. package/src/ports/forms/SearchField.tsx +9 -3
  55. package/src/ports/forms/StructurePickerControl.test.tsx +29 -1
  56. package/src/ports/forms/StructurePickerControl.tsx +38 -4
  57. package/src/ports/rekuest.ts +7 -7
  58. package/src/ports/structure/Structure.tsx +14 -5
  59. package/src/ports/widgets/custom/ListSearchWidget.tsx +3 -2
  60. package/src/ports/widgets/custom/SearchWidget.tsx +3 -2
  61. package/src/ports/widgets/fallbacks/EnumWidget.test.tsx +89 -0
  62. package/src/ports/widgets/fallbacks/EnumWidget.tsx +38 -13
  63. package/src/renderer/bloks/buttonsInForms.test.tsx +70 -0
  64. package/src/renderer/bloks/scene/Model.tsx +15 -2
  65. package/src/vendor/core/ui/AsyncBoundary.tsx +1 -0
  66. package/src/vendor/core/ui/button.tsx +5 -0
  67. package/src/vendor/core/ui/markdown.tsx +1 -0
  68. package/src/vendor/core/ui/name.tsx +69 -0
  69. package/src/vendor/core/ui/overflow-tooltip.tsx +59 -0
  70. package/src/vendor/core/ui/select.tsx +3 -3
  71. package/src/vendor/core/ui/tooltip.tsx +5 -1
@@ -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>
@@ -0,0 +1,70 @@
1
+ // @vitest-environment jsdom
2
+ import {act, cleanup, fireEvent, render} from '@testing-library/react';
3
+ import * as React from 'react';
4
+ import {afterEach, describe, expect, it, vi} from 'vitest';
5
+
6
+ import {parseBsx} from '../../bsx/parse';
7
+ import {Button} from '../../vendor/core/ui/button';
8
+ import BlokRenderer from '../BlokRenderer';
9
+ import {testCatalog} from './testing';
10
+
11
+ afterEach(cleanup);
12
+
13
+ // Every component of the catalog that draws a button, opened where it opens, so the buttons
14
+ // of its content are drawn too: the overlays render into the body, not into the form.
15
+ const SOURCE = `<Blok kind="agent" context="panel">
16
+ <Button label="Plain" />
17
+ <Button label="Acting" onClick={ui.copy("x")} />
18
+ <Toggle label="Toggle" />
19
+ <ToggleGroup><ToggleGroupItem value="a" label="A" /><ToggleGroupItem value="b" label="B" /></ToggleGroup>
20
+ <Checkbox label="Check" />
21
+ <Switch label="Switch" />
22
+ <RadioGroup><RadioGroupItem value="a" label="A" /></RadioGroup>
23
+ <Tabs defaultValue="one"><TabsList><TabsTrigger value="one" label="One" /><TabsTrigger value="two" label="Two" /></TabsList><TabsContent value="one"><Text>one</Text></TabsContent></Tabs>
24
+ <Collapsible defaultOpen><CollapsibleTrigger label="More" /><CollapsibleContent><Button label="Inside" /></CollapsibleContent></Collapsible>
25
+ <Accordion defaultValue="a"><AccordionItem value="a"><AccordionTrigger label="Section" /><AccordionContent><Text>a</Text></AccordionContent></AccordionItem></Accordion>
26
+ <Tooltip><TooltipTrigger label="Hover" /><TooltipContent><Text>tip</Text></TooltipContent></Tooltip>
27
+ <Popover defaultOpen><PopoverTrigger label="Pop" /><PopoverContent><Button label="In popover" /></PopoverContent></Popover>
28
+ <Dialog defaultOpen><DialogTrigger label="Open" /><DialogContent><DialogClose label="Close" /><Button label="In dialog" /></DialogContent></Dialog>
29
+ <DropdownMenu><DropdownMenuTrigger label="Menu" /><DropdownMenuContent><DropdownMenuItem label="Item" /></DropdownMenuContent></DropdownMenu>
30
+ <Select><SelectTrigger placeholder="Pick" /><SelectContent><SelectItem value="a" label="A" /></SelectContent></Select>
31
+ <DatePicker />
32
+ <Combobox options={[{value: "a", label: "A"}]} />
33
+ <Calendar />
34
+ </Blok>`;
35
+
36
+ describe('a blok drawn inside a form', () => {
37
+ it('submits nothing: every button it draws is a button, not the form’s submit', async () => {
38
+ const submitted = vi.fn((event: React.FormEvent) => event.preventDefault());
39
+ render(
40
+ <form onSubmit={submitted}>
41
+ <BlokRenderer uiComponents={[parseBsx(SOURCE).tree]} catalog={testCatalog()} chrome="none" sizing="intrinsic" />
42
+ </form>,
43
+ );
44
+ await act(async () => {});
45
+
46
+ const buttons = Array.from(document.body.querySelectorAll('button'));
47
+ expect(buttons.length).toBeGreaterThan(20);
48
+ // jsdom says "submit" for a button that does not say what it is, as a browser does.
49
+ const submitting = buttons.filter(button => button.type !== 'button').map(button => button.outerHTML.slice(0, 120));
50
+ expect(submitting).toEqual([]);
51
+
52
+ // And clicking them, the way someone filling in the form would, submits nothing.
53
+ for (const button of buttons) {
54
+ if (button.isConnected && !button.disabled) fireEvent.click(button);
55
+ }
56
+ await act(async () => {});
57
+ expect(submitted).not.toHaveBeenCalled();
58
+ });
59
+
60
+ it('keeps a submit that says it is one', () => {
61
+ const submitted = vi.fn((event: React.FormEvent) => event.preventDefault());
62
+ const {getByText} = render(
63
+ <form onSubmit={submitted}>
64
+ <Button type="submit">Send</Button>
65
+ </form>,
66
+ );
67
+ fireEvent.click(getByText('Send'));
68
+ expect(submitted).toHaveBeenCalledOnce();
69
+ });
70
+ });
@@ -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
  };
@@ -58,6 +58,7 @@ const DefaultErrorFallback = ({ error, reset }: { error: Error; reset: () => voi
58
58
  <h3 style={{ marginTop: 0 }}>Something went wrong</h3>
59
59
  <p>{error.message}</p>
60
60
  <button
61
+ type="button"
61
62
  onClick={reset}
62
63
  style={{ padding: '0.5rem 1rem', cursor: 'pointer', backgroundColor: '#b91c1c', color: 'white', border: 'none', borderRadius: '4px' }}
63
64
  >
@@ -61,12 +61,17 @@ function Button({
61
61
  alwaysShow: _alwaysShow,
62
62
  priority: _priority,
63
63
  collapse: _collapse,
64
+ type,
64
65
  ...props
65
66
  }: ButtonProps) {
66
67
  const Comp = asChild ? Slot.Root : "button"
67
68
 
68
69
  return (
69
70
  <Comp
71
+ // A button is a button, not a form's submit: these are drawn inside forms (an action's
72
+ // ports, a blok in one) and only ever act through their onClick. One that submits says
73
+ // so (`type="submit"`). A child it is merged onto (asChild, a link say) keeps its own.
74
+ type={asChild ? type : (type ?? "button")}
70
75
  data-slot="button"
71
76
  data-variant={variant}
72
77
  data-size={size}
@@ -21,6 +21,7 @@ export function CodeBlock({ language, content }: CodeBlockProps) {
21
21
  <div className="flex items-center justify-between px-4 py-1.5 border-b border-border/10 bg-zinc-900 dark:bg-zinc-950/40 text-[10px] font-mono text-zinc-400 select-none">
22
22
  <span>{language || "text"}</span>
23
23
  <button
24
+ type="button"
24
25
  onClick={handleCopy}
25
26
  className="flex items-center gap-1.5 px-2 py-0.5 rounded hover:bg-zinc-800 hover:text-zinc-200 transition-colors cursor-pointer"
26
27
  >
@@ -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 }
@@ -0,0 +1,59 @@
1
+ import * as React from "react"
2
+
3
+ import { cn } from "../util/utils"
4
+ import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip"
5
+
6
+ /** Mark the text an `OverflowTooltip` watches: it opens when this is cut off. */
7
+ export const OVERFLOW_TEXT = { "data-overflow-text": "" } as const
8
+
9
+ const isCutOff = (el: Element) =>
10
+ el.scrollWidth > el.clientWidth + 1 || el.scrollHeight > el.clientHeight + 1
11
+
12
+ const hasOverflow = (root: Element | null) => {
13
+ if (!root) return false
14
+ if (root.matches("[data-overflow-text]") && isCutOff(root)) return true
15
+ return Array.from(root.querySelectorAll("[data-overflow-text]")).some(isCutOff)
16
+ }
17
+
18
+ /**
19
+ * A tooltip for text that may not fit: it opens only when an element marked
20
+ * with `OVERFLOW_TEXT` inside the trigger is cut off, or always when `always`
21
+ * (say, a description the trigger has no room for). The trigger is the child.
22
+ */
23
+ function OverflowTooltip({
24
+ content,
25
+ always = false,
26
+ side,
27
+ className,
28
+ children,
29
+ }: {
30
+ content: React.ReactNode
31
+ always?: boolean
32
+ side?: React.ComponentProps<typeof TooltipContent>["side"]
33
+ className?: string
34
+ children: React.ReactElement
35
+ }) {
36
+ const triggerRef = React.useRef<HTMLButtonElement>(null)
37
+ const [open, setOpen] = React.useState(false)
38
+
39
+ const onOpenChange = React.useCallback(
40
+ (next: boolean) => setOpen(next && (always || hasOverflow(triggerRef.current))),
41
+ [always]
42
+ )
43
+
44
+ return (
45
+ <Tooltip open={open} onOpenChange={onOpenChange}>
46
+ <TooltipTrigger asChild ref={triggerRef}>
47
+ {children}
48
+ </TooltipTrigger>
49
+ <TooltipContent
50
+ side={side}
51
+ className={cn("whitespace-normal break-words", className)}
52
+ >
53
+ {content}
54
+ </TooltipContent>
55
+ </Tooltip>
56
+ )
57
+ }
58
+
59
+ export { OverflowTooltip }
@@ -43,7 +43,7 @@ function SelectTrigger({
43
43
  data-slot="select-trigger"
44
44
  data-size={size}
45
45
  className={cn(
46
- "border-input data-[placeholder]:text-muted-foreground bg-input/20 dark:bg-input/30 dark:hover:bg-input/50 focus-visible:border-ring focus-visible:ring-ring/30 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 gap-1.5 rounded-md border px-2 py-1.5 text-xs/relaxed transition-colors focus-visible:ring-[2px] aria-invalid:ring-[2px] data-[size=default]:h-7 data-[size=sm]:h-6 *:data-[slot=select-value]:flex *:data-[slot=select-value]:gap-1.5 [&_svg:not([class*='size-'])]:size-3.5 flex w-fit items-center justify-between whitespace-nowrap outline-none disabled:cursor-not-allowed disabled:opacity-50 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center [&_svg]:pointer-events-none [&_svg]:shrink-0",
46
+ "border-input data-[placeholder]:text-muted-foreground bg-input/20 dark:bg-input/30 dark:hover:bg-input/50 focus-visible:border-ring focus-visible:ring-ring/30 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 gap-1.5 rounded-md border px-2 py-1.5 text-xs/relaxed transition-colors focus-visible:ring-[2px] aria-invalid:ring-[2px] data-[size=default]:h-7 data-[size=sm]:h-6 *:data-[slot=select-value]:flex *:data-[slot=select-value]:gap-1.5 [&_svg:not([class*='size-'])]:size-3.5 flex w-fit items-center justify-between whitespace-nowrap outline-none disabled:cursor-not-allowed disabled:opacity-50 *:data-[slot=select-value]:min-w-0 *:data-[slot=select-value]:overflow-hidden *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center [&_svg]:pointer-events-none [&_svg]:shrink-0",
47
47
  className
48
48
  )}
49
49
  {...props}
@@ -68,7 +68,7 @@ function SelectContent({
68
68
  <SelectPrimitive.Portal>
69
69
  <SelectPrimitive.Content
70
70
  data-slot="select-content"
71
- className={cn(chromeZoom, "bg-popover text-popover-foreground data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 ring-foreground/10 min-w-32 rounded-lg shadow-md ring-1 duration-100 relative z-50 max-h-(--radix-select-content-available-height) origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto", position === "popper" && "data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1", className)}
71
+ className={cn(chromeZoom, "bg-popover text-popover-foreground data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 ring-foreground/10 min-w-32 max-w-(--radix-select-content-available-width) rounded-lg shadow-md ring-1 duration-100 relative z-50 max-h-(--radix-select-content-available-height) origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto", position === "popper" && "data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1", className)}
72
72
  position={position}
73
73
  align={align}
74
74
  {...props}
@@ -111,7 +111,7 @@ function SelectItem({
111
111
  <SelectPrimitive.Item
112
112
  data-slot="select-item"
113
113
  className={cn(
114
- "focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground min-h-7 gap-2 rounded-md px-2 py-1 text-xs/relaxed [&_svg:not([class*='size-'])]:size-3.5 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2 relative flex w-full cursor-default items-center outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
114
+ "focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground min-h-7 gap-2 rounded-md py-1 pl-2 pr-8 break-words text-xs/relaxed [&_svg:not([class*='size-'])]:size-3.5 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2 relative flex w-full cursor-default items-center outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
115
115
  className
116
116
  )}
117
117
  {...props}
@@ -30,9 +30,13 @@ function Tooltip({
30
30
 
31
31
  function TooltipTrigger({
32
32
  asChild,
33
+ type,
33
34
  ...props
34
35
  }: React.ComponentProps<typeof TooltipPrimitive.Trigger>) {
35
- return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" asChild={resolveTriggerAsChild(asChild, props.children)} {...props} />
36
+ const merged = resolveTriggerAsChild(asChild, props.children)
37
+ // Radix draws the trigger as a bare <button>, a form's submit by default: inside a form,
38
+ // hovering is all it is for. On a child it is merged onto, the child says what it is.
39
+ return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" asChild={merged} type={merged ? type : (type ?? "button")} {...props} />
36
40
  }
37
41
 
38
42
  function TooltipContent({