@terreno/ui 57.7.0 → 57.9.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 (186) hide show
  1. package/dist/AreaChart.d.ts +1 -1
  2. package/dist/AreaChart.d.ts.map +1 -1
  3. package/dist/AreaChart.js +70 -22
  4. package/dist/AreaChart.js.map +1 -1
  5. package/dist/Avatar.js +2 -2
  6. package/dist/Avatar.js.map +1 -1
  7. package/dist/BarChart.d.ts.map +1 -1
  8. package/dist/BarChart.js +55 -13
  9. package/dist/BarChart.js.map +1 -1
  10. package/dist/Button.js +2 -2
  11. package/dist/Button.js.map +1 -1
  12. package/dist/ChartCard.d.ts +5 -0
  13. package/dist/ChartCard.d.ts.map +1 -0
  14. package/dist/ChartCard.js +18 -0
  15. package/dist/ChartCard.js.map +1 -0
  16. package/dist/Common.d.ts +128 -5
  17. package/dist/Common.d.ts.map +1 -1
  18. package/dist/Common.js.map +1 -1
  19. package/dist/DashboardGrid.d.ts +6 -2
  20. package/dist/DashboardGrid.d.ts.map +1 -1
  21. package/dist/DashboardGrid.js +43 -10
  22. package/dist/DashboardGrid.js.map +1 -1
  23. package/dist/DateTimeActionSheet.js +2 -2
  24. package/dist/DateTimeActionSheet.js.map +1 -1
  25. package/dist/DateTimeField.js +3 -3
  26. package/dist/DateTimeField.js.map +1 -1
  27. package/dist/DonutChart.d.ts.map +1 -1
  28. package/dist/DonutChart.js +20 -10
  29. package/dist/DonutChart.js.map +1 -1
  30. package/dist/DropdownMenuItem.d.ts +16 -0
  31. package/dist/DropdownMenuItem.d.ts.map +1 -0
  32. package/dist/DropdownMenuItem.js +11 -0
  33. package/dist/DropdownMenuItem.js.map +1 -0
  34. package/dist/DropdownPanel.d.ts.map +1 -1
  35. package/dist/DropdownPanel.js +1 -1
  36. package/dist/DropdownPanel.js.map +1 -1
  37. package/dist/FilePickerButton.d.ts.map +1 -1
  38. package/dist/FilePickerButton.js +70 -10
  39. package/dist/FilePickerButton.js.map +1 -1
  40. package/dist/GPTChat.d.ts.map +1 -1
  41. package/dist/GPTChat.js +103 -14
  42. package/dist/GPTChat.js.map +1 -1
  43. package/dist/HeightField.js +2 -2
  44. package/dist/HeightField.js.map +1 -1
  45. package/dist/IconButton.d.ts.map +1 -1
  46. package/dist/IconButton.js +9 -6
  47. package/dist/IconButton.js.map +1 -1
  48. package/dist/LineChart.d.ts +1 -1
  49. package/dist/LineChart.d.ts.map +1 -1
  50. package/dist/LineChart.js +62 -21
  51. package/dist/LineChart.js.map +1 -1
  52. package/dist/MediaQuery.d.ts +10 -0
  53. package/dist/MediaQuery.d.ts.map +1 -1
  54. package/dist/MediaQuery.js +13 -1
  55. package/dist/MediaQuery.js.map +1 -1
  56. package/dist/MultiselectField.js +2 -2
  57. package/dist/MultiselectField.js.map +1 -1
  58. package/dist/RadioField.js +2 -2
  59. package/dist/RadioField.js.map +1 -1
  60. package/dist/Scorecard.d.ts +5 -0
  61. package/dist/Scorecard.d.ts.map +1 -0
  62. package/dist/Scorecard.js +11 -0
  63. package/dist/Scorecard.js.map +1 -0
  64. package/dist/SparklineChart.d.ts +5 -0
  65. package/dist/SparklineChart.d.ts.map +1 -0
  66. package/dist/SparklineChart.js +35 -0
  67. package/dist/SparklineChart.js.map +1 -0
  68. package/dist/SplitPage.d.ts +1 -1
  69. package/dist/SplitPage.d.ts.map +1 -1
  70. package/dist/SplitPage.js +126 -21
  71. package/dist/SplitPage.js.map +1 -1
  72. package/dist/TextField.d.ts.map +1 -1
  73. package/dist/TextField.js +12 -4
  74. package/dist/TextField.js.map +1 -1
  75. package/dist/ToastNotifications.d.ts.map +1 -1
  76. package/dist/ToastNotifications.js +29 -6
  77. package/dist/ToastNotifications.js.map +1 -1
  78. package/dist/UnifiedAddressAutoComplete.js +2 -2
  79. package/dist/UnifiedAddressAutoComplete.js.map +1 -1
  80. package/dist/WebDropdownMenu.d.ts +2 -1
  81. package/dist/WebDropdownMenu.d.ts.map +1 -1
  82. package/dist/WebDropdownMenu.js +2 -6
  83. package/dist/WebDropdownMenu.js.map +1 -1
  84. package/dist/charts/ChartFacadeContainer.d.ts +10 -0
  85. package/dist/charts/ChartFacadeContainer.d.ts.map +1 -0
  86. package/dist/charts/ChartFacadeContainer.js +10 -0
  87. package/dist/charts/ChartFacadeContainer.js.map +1 -0
  88. package/dist/charts/ChartFrame.d.ts +4 -0
  89. package/dist/charts/ChartFrame.d.ts.map +1 -1
  90. package/dist/charts/ChartFrame.js +4 -2
  91. package/dist/charts/ChartFrame.js.map +1 -1
  92. package/dist/charts/layout.d.ts +9 -2
  93. package/dist/charts/layout.d.ts.map +1 -1
  94. package/dist/charts/layout.js +28 -6
  95. package/dist/charts/layout.js.map +1 -1
  96. package/dist/charts/scales.d.ts +3 -1
  97. package/dist/charts/scales.d.ts.map +1 -1
  98. package/dist/charts/scales.js +7 -7
  99. package/dist/charts/scales.js.map +1 -1
  100. package/dist/charts/series.d.ts +15 -0
  101. package/dist/charts/series.d.ts.map +1 -0
  102. package/dist/charts/series.js +19 -0
  103. package/dist/charts/series.js.map +1 -0
  104. package/dist/charts/types/chartTypes.d.ts +7 -0
  105. package/dist/charts/types/chartTypes.d.ts.map +1 -1
  106. package/dist/dashboardGridLayout.d.ts +6 -0
  107. package/dist/dashboardGridLayout.d.ts.map +1 -1
  108. package/dist/dashboardGridLayout.js +19 -3
  109. package/dist/dashboardGridLayout.js.map +1 -1
  110. package/dist/fieldElements/FieldTitle.js +2 -2
  111. package/dist/fieldElements/FieldTitle.js.map +1 -1
  112. package/dist/index.d.ts +4 -1
  113. package/dist/index.d.ts.map +1 -1
  114. package/dist/index.js +1 -1
  115. package/dist/index.js.map +1 -1
  116. package/dist/lazyBoundaries/heavyOptionalExports.d.ts +9 -0
  117. package/dist/lazyBoundaries/heavyOptionalExports.d.ts.map +1 -1
  118. package/dist/lazyBoundaries/heavyOptionalExports.js +6 -0
  119. package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -1
  120. package/dist/resolveDocumentBodyPortalTarget.d.ts +7 -0
  121. package/dist/resolveDocumentBodyPortalTarget.d.ts.map +1 -0
  122. package/dist/resolveDocumentBodyPortalTarget.js +12 -0
  123. package/dist/resolveDocumentBodyPortalTarget.js.map +1 -0
  124. package/package.json +1 -1
  125. package/src/AIRequestExplorer.test.tsx +2 -2
  126. package/src/AreaChart.test.tsx +81 -0
  127. package/src/AreaChart.tsx +171 -62
  128. package/src/Avatar.tsx +2 -2
  129. package/src/BarChart.test.tsx +119 -0
  130. package/src/BarChart.tsx +94 -20
  131. package/src/Button.test.tsx +7 -7
  132. package/src/Button.tsx +2 -2
  133. package/src/ChartCard.test.tsx +79 -0
  134. package/src/ChartCard.tsx +80 -0
  135. package/src/Common.ts +119 -2
  136. package/src/DashboardGrid.test.tsx +98 -1
  137. package/src/DashboardGrid.tsx +71 -20
  138. package/src/DateTimeActionSheet.tsx +4 -4
  139. package/src/DateTimeField.test.tsx +5 -4
  140. package/src/DateTimeField.tsx +3 -3
  141. package/src/DonutChart.test.tsx +73 -0
  142. package/src/DonutChart.tsx +87 -14
  143. package/src/DropdownMenuItem.tsx +48 -0
  144. package/src/DropdownPanel.test.tsx +12 -0
  145. package/src/DropdownPanel.tsx +8 -1
  146. package/src/FilePickerButton.test.tsx +60 -6
  147. package/src/FilePickerButton.tsx +116 -28
  148. package/src/GPTChat.test.tsx +133 -6
  149. package/src/GPTChat.tsx +196 -38
  150. package/src/HeightField.tsx +2 -2
  151. package/src/IconButton.test.tsx +63 -0
  152. package/src/IconButton.tsx +10 -5
  153. package/src/LineChart.test.tsx +104 -0
  154. package/src/LineChart.tsx +154 -58
  155. package/src/MediaQuery.ts +14 -1
  156. package/src/MultiselectField.tsx +2 -2
  157. package/src/RadioField.tsx +2 -2
  158. package/src/Scorecard.test.tsx +65 -0
  159. package/src/Scorecard.tsx +45 -0
  160. package/src/SparklineChart.test.tsx +69 -0
  161. package/src/SparklineChart.tsx +85 -0
  162. package/src/SplitPage.test.tsx +449 -11
  163. package/src/SplitPage.tsx +255 -21
  164. package/src/TextField.test.tsx +16 -0
  165. package/src/TextField.tsx +13 -3
  166. package/src/ToastNotifications.tsx +33 -6
  167. package/src/ToastNotifications.webModal.test.tsx +285 -0
  168. package/src/UnifiedAddressAutoComplete.test.tsx +4 -4
  169. package/src/UnifiedAddressAutoComplete.tsx +2 -2
  170. package/src/WebDropdownMenu.tsx +3 -7
  171. package/src/__snapshots__/DropdownPanel.test.tsx.snap +3 -1
  172. package/src/bunSetup.ts +3 -1
  173. package/src/charts/ChartFacadeContainer.tsx +35 -0
  174. package/src/charts/ChartFrame.tsx +39 -1
  175. package/src/charts/layout.test.ts +22 -1
  176. package/src/charts/layout.ts +37 -4
  177. package/src/charts/scales.test.ts +33 -0
  178. package/src/charts/scales.ts +10 -6
  179. package/src/charts/series.ts +43 -0
  180. package/src/charts/types/chartTypes.ts +8 -0
  181. package/src/dashboardGridLayout.test.ts +59 -1
  182. package/src/dashboardGridLayout.ts +30 -3
  183. package/src/fieldElements/FieldTitle.tsx +2 -2
  184. package/src/index.tsx +6 -0
  185. package/src/lazyBoundaries/heavyOptionalExports.tsx +21 -0
  186. package/src/resolveDocumentBodyPortalTarget.ts +11 -0
@@ -1,6 +1,7 @@
1
1
  import {afterAll, afterEach, describe, it, mock} from "bun:test";
2
2
  import {act, fireEvent, render, waitFor} from "@testing-library/react-native";
3
3
  import {assert} from "chai";
4
+ import {setImageAsync, setStringAsync} from "expo-clipboard";
4
5
  import React from "react";
5
6
  import {Platform, Pressable, ScrollView} from "react-native";
6
7
 
@@ -11,8 +12,8 @@ import {Text} from "./Text";
11
12
  import {ThemeProvider} from "./Theme";
12
13
  import {renderWithTheme} from "./test-utils";
13
14
 
14
- const setStringAsync = mock(async (_text: string) => {});
15
- mock.module("expo-clipboard", () => ({setStringAsync}));
15
+ const mockedSetImageAsync = setImageAsync as unknown as ReturnType<typeof mock>;
16
+ const mockedSetStringAsync = setStringAsync as unknown as ReturnType<typeof mock>;
16
17
 
17
18
  const pickedDocument = {mimeType: "text/plain", name: "notes.txt", uri: "file:///notes.txt"};
18
19
  mock.module("expo-document-picker", () => ({
@@ -91,6 +92,7 @@ describe("GPTChat", () => {
91
92
 
92
93
  await press(getByLabelText("Select chat: First chat"));
93
94
  await press(getByTestId("gpt-new-chat-button"));
95
+ await press(getByTestId("gpt-history-menu-h2"));
94
96
  await press(getByTestId("gpt-delete-history-h2"));
95
97
 
96
98
  assert.deepEqual(onSelectHistory.mock.calls, [["h1"]]);
@@ -102,6 +104,7 @@ describe("GPTChat", () => {
102
104
  const onUpdateTitle = mock((_id: string, _title: string) => {});
103
105
  const {getByTestId} = renderChat({onUpdateTitle});
104
106
 
107
+ await press(getByTestId("gpt-history-menu-h1"));
105
108
  await press(getByTestId("gpt-rename-history-h1"));
106
109
  fireEvent.changeText(getByTestId("gpt-rename-input-h1"), "Renamed");
107
110
  await press(getByTestId("gpt-rename-save-h1"));
@@ -113,6 +116,7 @@ describe("GPTChat", () => {
113
116
  const onUpdateTitle = mock((_id: string, _title: string) => {});
114
117
  const {getByTestId} = renderChat({onUpdateTitle});
115
118
 
119
+ await press(getByTestId("gpt-history-menu-h2"));
116
120
  await press(getByTestId("gpt-rename-history-h2"));
117
121
  fireEvent.changeText(getByTestId("gpt-rename-input-h2"), " ");
118
122
  fireEvent(getByTestId("gpt-rename-input-h2"), "blur");
@@ -120,10 +124,31 @@ describe("GPTChat", () => {
120
124
  assert.equal(onUpdateTitle.mock.calls.length, 0);
121
125
  });
122
126
 
123
- it("hides the rename button when renaming is not supported", () => {
124
- const {queryByTestId} = renderChat();
127
+ it("hides the rename action when renaming is not supported", async () => {
128
+ const {getByTestId, queryByTestId} = renderChat();
129
+
130
+ await press(getByTestId("gpt-history-menu-h1"));
125
131
 
126
132
  assert.isNull(queryByTestId("gpt-rename-history-h1"));
133
+ assert.isOk(getByTestId("gpt-delete-history-h1"));
134
+ });
135
+
136
+ it("keeps rename and delete inside a per-row overflow menu", async () => {
137
+ const {getByTestId, queryByTestId} = renderChat({onUpdateTitle: () => {}});
138
+
139
+ assert.isOk(getByTestId("gpt-history-menu-h1"));
140
+ assert.isNull(queryByTestId("gpt-rename-history-h1"));
141
+ assert.isNull(queryByTestId("gpt-delete-history-h1"));
142
+
143
+ await press(getByTestId("gpt-history-menu-h1"));
144
+
145
+ assert.isOk(getByTestId("gpt-rename-history-h1"));
146
+ assert.isOk(getByTestId("gpt-delete-history-h1"));
147
+
148
+ await press(getByTestId("gpt-rename-history-h1"));
149
+
150
+ assert.isNull(queryByTestId("gpt-delete-history-h1"));
151
+ assert.isOk(getByTestId("gpt-rename-input-h1"));
127
152
  });
128
153
 
129
154
  it("renders a model selector only when models and a change handler are given", () => {
@@ -562,7 +587,7 @@ describe("GPTChat", () => {
562
587
  });
563
588
 
564
589
  it("copies an assistant message to the clipboard", async () => {
565
- setStringAsync.mockClear();
590
+ mockedSetStringAsync.mockClear();
566
591
  const {getByTestId} = renderChat({
567
592
  currentMessages: [{content: "Copy me", role: "assistant"}],
568
593
  });
@@ -571,7 +596,63 @@ describe("GPTChat", () => {
571
596
  fireEvent.press(getByTestId("gpt-copy-msg-0"));
572
597
  });
573
598
 
574
- assert.deepEqual(setStringAsync.mock.calls, [["Copy me"]]);
599
+ assert.deepEqual(mockedSetStringAsync.mock.calls, [["Copy me"]]);
600
+ });
601
+
602
+ it("copies the image, not placeholder text, for an image-only reply", async () => {
603
+ mockedSetStringAsync.mockClear();
604
+ mockedSetImageAsync.mockClear();
605
+ const {getByTestId} = renderChat({
606
+ currentMessages: [
607
+ {
608
+ content: "",
609
+ contentParts: [{mimeType: "image/png", type: "image", url: "data:image/png;base64,AAAA"}],
610
+ role: "assistant",
611
+ },
612
+ ],
613
+ });
614
+
615
+ await press(getByTestId("gpt-copy-msg-0"));
616
+
617
+ assert.deepEqual(mockedSetImageAsync.mock.calls, [["AAAA"]]);
618
+ assert.equal(mockedSetStringAsync.mock.calls.length, 0);
619
+ });
620
+
621
+ it("offers a copy-image action on generated images", async () => {
622
+ mockedSetImageAsync.mockClear();
623
+ const {getByTestId} = renderChat({
624
+ currentMessages: [
625
+ {
626
+ content: "Here you go",
627
+ contentParts: [{mimeType: "image/png", type: "image", url: "data:image/png;base64,BBBB"}],
628
+ role: "assistant",
629
+ },
630
+ ],
631
+ });
632
+
633
+ await press(getByTestId("gpt-copy-image"));
634
+
635
+ assert.deepEqual(mockedSetImageAsync.mock.calls, [["BBBB"]]);
636
+ });
637
+
638
+ it("grows the composer up to a maximum height and resets after sending", async () => {
639
+ const {getByTestId} = renderChat();
640
+ const input = getByTestId("gpt-input");
641
+ fireEvent.changeText(input, "Long pasted notes");
642
+
643
+ fireEvent(input, "contentSizeChange", {nativeEvent: {contentSize: {height: 120, width: 100}}});
644
+ const grownStyle = [getByTestId("gpt-input").props.style].flat(Infinity);
645
+ assert.isTrue(grownStyle.some((style) => style?.height === 120));
646
+
647
+ fireEvent(getByTestId("gpt-input"), "contentSizeChange", {
648
+ nativeEvent: {contentSize: {height: 900, width: 100}},
649
+ });
650
+ const cappedStyle = [getByTestId("gpt-input").props.style].flat(Infinity);
651
+ assert.isTrue(cappedStyle.some((style) => style?.height === 200));
652
+
653
+ await press(getByTestId("gpt-submit"));
654
+ const resetStyle = [getByTestId("gpt-input").props.style].flat(Infinity);
655
+ assert.isTrue(resetStyle.some((style) => style?.height === 40));
575
656
  });
576
657
 
577
658
  it("disables input and the attachment picker while streaming", () => {
@@ -619,6 +700,51 @@ describe("GPTChat", () => {
619
700
  assert.isNull(queryByText("Scroll to bottom"));
620
701
  });
621
702
 
703
+ it("never shows scroll to bottom in an empty chat", async () => {
704
+ const {getByTestId, queryByText, UNSAFE_getByType} = renderChat({currentMessages: []});
705
+
706
+ fireEvent(getByTestId("gpt-viewport"), "layout", {
707
+ nativeEvent: {layout: {height: 200, width: 100, x: 0, y: 0}},
708
+ });
709
+ fireEvent(getByTestId("gpt-messages"), "layout", {
710
+ nativeEvent: {layout: {height: 600, width: 100, x: 0, y: 0}},
711
+ });
712
+ await act(async () => {
713
+ fireEvent.scroll(UNSAFE_getByType(ScrollView), {
714
+ nativeEvent: {contentOffset: {x: 0, y: 0}},
715
+ });
716
+ });
717
+
718
+ assert.isNull(queryByText("Scroll to bottom"));
719
+ });
720
+
721
+ it("hides scroll to bottom once the content fits the viewport", async () => {
722
+ const {getByTestId, getByText, queryByText, UNSAFE_getByType} = renderChat({
723
+ currentMessages: [{content: "Hello!", role: "assistant"}],
724
+ });
725
+
726
+ fireEvent(getByTestId("gpt-viewport"), "layout", {
727
+ nativeEvent: {layout: {height: 200, width: 100, x: 0, y: 0}},
728
+ });
729
+ fireEvent(getByTestId("gpt-messages"), "layout", {
730
+ nativeEvent: {layout: {height: 600, width: 100, x: 0, y: 0}},
731
+ });
732
+ await act(async () => {
733
+ fireEvent.scroll(UNSAFE_getByType(ScrollView), {
734
+ nativeEvent: {contentOffset: {x: 0, y: 0}},
735
+ });
736
+ });
737
+ assert.isOk(getByText("Scroll to bottom"));
738
+
739
+ await act(async () => {
740
+ fireEvent(getByTestId("gpt-messages"), "layout", {
741
+ nativeEvent: {layout: {height: 150, width: 100, x: 0, y: 0}},
742
+ });
743
+ });
744
+
745
+ assert.isNull(queryByText("Scroll to bottom"));
746
+ });
747
+
622
748
  it("renders attachments and the attach button", () => {
623
749
  const onAttachFiles = mock(() => {});
624
750
  const onRemoveAttachment = mock((_index: number) => {});
@@ -668,6 +794,7 @@ describe("GPTChat", () => {
668
794
  const onUpdateTitle = mock((_id: string, _title: string) => {});
669
795
  const {getByTestId} = renderChat({onUpdateTitle});
670
796
 
797
+ await press(getByTestId("gpt-history-menu-h1"));
671
798
  await press(getByTestId("gpt-rename-history-h1"));
672
799
  fireEvent.changeText(getByTestId("gpt-rename-input-h1"), "Renamed");
673
800
  const input = getByTestId("gpt-rename-input-h1");
package/src/GPTChat.tsx CHANGED
@@ -1,3 +1,4 @@
1
+ import {DateTime} from "luxon";
1
2
  import React, {useCallback, useEffect, useRef, useState} from "react";
2
3
  import {
3
4
  Platform,
@@ -9,6 +10,8 @@ import {
9
10
  import {AttachmentPreview} from "./AttachmentPreview";
10
11
  import {Box} from "./Box";
11
12
  import {Button} from "./Button";
13
+ import {DropdownMenuItem} from "./DropdownMenuItem";
14
+ import {DropdownPanel} from "./DropdownPanel";
12
15
  import type {SelectedFile} from "./FilePickerButton";
13
16
  import {FilePickerButton} from "./FilePickerButton";
14
17
  import {Heading} from "./Heading";
@@ -228,18 +231,103 @@ const handleDownloadFile = (url: string, filename: string): void => {
228
231
  document.body.removeChild(link);
229
232
  };
230
233
 
234
+ const IMAGE_EXTENSIONS: Record<string, string> = {
235
+ "image/gif": "gif",
236
+ "image/jpeg": "jpg",
237
+ "image/png": "png",
238
+ "image/webp": "webp",
239
+ };
240
+
241
+ const getImageFilename = (part: ImageContentPart): string => {
242
+ const extension = IMAGE_EXTENSIONS[part.mimeType ?? ""] ?? "png";
243
+ return `image-${DateTime.now().toMillis()}.${extension}`;
244
+ };
245
+
246
+ // Browsers reliably accept only PNG on the clipboard, so other formats are redrawn as PNG.
247
+ const convertBlobToPng = async (blob: Blob): Promise<Blob> => {
248
+ if (blob.type === "image/png") {
249
+ return blob;
250
+ }
251
+ const bitmap = await createImageBitmap(blob);
252
+ const canvas = document.createElement("canvas");
253
+ canvas.width = bitmap.width;
254
+ canvas.height = bitmap.height;
255
+ canvas.getContext("2d")?.drawImage(bitmap, 0, 0);
256
+ return new Promise((resolve, reject) => {
257
+ canvas.toBlob((png) => (png ? resolve(png) : reject(new Error("PNG conversion failed"))));
258
+ });
259
+ };
260
+
261
+ /** Copies the image itself (not a text placeholder) to the clipboard. */
262
+ const copyImageToClipboard = async (part: ImageContentPart): Promise<void> => {
263
+ if (Platform.OS === "web") {
264
+ if (typeof ClipboardItem === "undefined" || !navigator.clipboard?.write) {
265
+ console.warn("Copying images is not supported in this browser");
266
+ return;
267
+ }
268
+ const response = await fetch(part.url);
269
+ const png = await convertBlobToPng(await response.blob());
270
+ await navigator.clipboard.write([new ClipboardItem({"image/png": png})]);
271
+ return;
272
+ }
273
+ const Clipboard = await import("expo-clipboard");
274
+ const base64 = part.url.startsWith("data:") ? part.url.split(",")[1] : undefined;
275
+ if (base64) {
276
+ await Clipboard.setImageAsync(base64);
277
+ } else {
278
+ await Clipboard.setStringAsync(part.url);
279
+ }
280
+ };
281
+
282
+ const ImageActions = ({part}: {part: ImageContentPart}): React.ReactElement => {
283
+ const handleCopy = useCallback(async (): Promise<void> => {
284
+ try {
285
+ await copyImageToClipboard(part);
286
+ } catch (error) {
287
+ console.warn("Failed to copy image", error);
288
+ }
289
+ }, [part]);
290
+
291
+ const handleDownload = useCallback((): void => {
292
+ handleDownloadFile(part.url, getImageFilename(part));
293
+ }, [part]);
294
+
295
+ return (
296
+ <Box direction="row" gap={1} testID="gpt-image-actions">
297
+ <IconButton
298
+ accessibilityLabel="Copy image"
299
+ iconName="copy"
300
+ onClick={handleCopy}
301
+ testID="gpt-copy-image"
302
+ variant="ghost"
303
+ />
304
+ {Platform.OS === "web" ? (
305
+ <IconButton
306
+ accessibilityLabel="Download image"
307
+ iconName="download"
308
+ onClick={handleDownload}
309
+ testID="gpt-download-image"
310
+ variant="ghost"
311
+ />
312
+ ) : null}
313
+ </Box>
314
+ );
315
+ };
316
+
231
317
  const MessageContentParts = ({parts}: {parts: MessageContentPart[]}): React.ReactElement => {
232
318
  return (
233
319
  <Box gap={2}>
234
320
  {parts.map((part, index) => {
235
321
  if (part.type === "image") {
236
322
  return (
237
- <RNImage
238
- key={`content-${index}`}
239
- resizeMode="contain"
240
- source={{uri: part.url}}
241
- style={{borderRadius: 8, height: 400, maxWidth: 800, minWidth: 400, width: "100%"}}
242
- />
323
+ <Box gap={1} key={`content-${index}`}>
324
+ <RNImage
325
+ resizeMode="contain"
326
+ source={{uri: part.url}}
327
+ style={{borderRadius: 8, height: 400, maxWidth: 800, minWidth: 400, width: "100%"}}
328
+ />
329
+ <ImageActions part={part} />
330
+ </Box>
243
331
  );
244
332
  }
245
333
  if (part.type === "file") {
@@ -464,25 +552,44 @@ const HistoryItemTitle = ({
464
552
  );
465
553
  }
466
554
  return (
467
- <Text color={history.id === currentHistoryId ? "inverted" : "primary"} size="sm" truncate>
468
- {history.title ?? "New Chat"}
469
- </Text>
555
+ <Box flex="grow" minWidth={0}>
556
+ <Text color={history.id === currentHistoryId ? "inverted" : "primary"} size="sm" truncate>
557
+ {history.title ?? "New Chat"}
558
+ </Text>
559
+ </Box>
470
560
  );
471
561
  };
472
562
 
473
- const HistoryItemActionButton = ({
563
+ const HistoryItemActions = ({
474
564
  editingHistoryId,
475
565
  handleFinishRename,
476
566
  handleStartRename,
477
567
  history,
568
+ isSelected,
569
+ onDeleteHistory,
478
570
  onUpdateTitle,
479
571
  }: {
480
572
  editingHistoryId: string | null;
481
573
  handleFinishRename: () => void;
482
574
  handleStartRename: (id: string, title: string) => void;
483
575
  history: GPTChatHistory;
576
+ isSelected: boolean;
577
+ onDeleteHistory: (id: string) => void;
484
578
  onUpdateTitle?: (id: string, title: string) => void;
485
- }): React.ReactElement | null => {
579
+ }): React.ReactElement => {
580
+ const [isMenuOpen, setIsMenuOpen] = useState(false);
581
+ const title = history.title ?? "New Chat";
582
+
583
+ const handleRename = useCallback((): void => {
584
+ setIsMenuOpen(false);
585
+ handleStartRename(history.id, history.title ?? "");
586
+ }, [handleStartRename, history.id, history.title]);
587
+
588
+ const handleDelete = useCallback((): void => {
589
+ setIsMenuOpen(false);
590
+ onDeleteHistory(history.id);
591
+ }, [history.id, onDeleteHistory]);
592
+
486
593
  if (editingHistoryId === history.id) {
487
594
  return (
488
595
  <IconButton
@@ -493,16 +600,45 @@ const HistoryItemActionButton = ({
493
600
  />
494
601
  );
495
602
  }
496
- if (!onUpdateTitle) {
497
- return null;
498
- }
603
+
499
604
  return (
500
- <IconButton
501
- accessibilityLabel={`Rename chat: ${history.title ?? "New Chat"}`}
502
- iconName="pencil"
503
- onClick={() => handleStartRename(history.id, history.title ?? "")}
504
- testID={`gpt-rename-history-${history.id}`}
505
- />
605
+ <DropdownPanel
606
+ align="auto"
607
+ isOpen={isMenuOpen}
608
+ onOpenChange={setIsMenuOpen}
609
+ renderTrigger={({toggle}) => (
610
+ <IconButton
611
+ accessibilityLabel={`Chat actions: ${title}`}
612
+ iconName="ellipsis-vertical"
613
+ onClick={toggle}
614
+ testID={`gpt-history-menu-${history.id}`}
615
+ variant={isSelected ? "primary" : "ghost"}
616
+ />
617
+ )}
618
+ showActionButtons={false}
619
+ testID={`gpt-history-menu-panel-${history.id}`}
620
+ width={180}
621
+ >
622
+ <Box gap={1}>
623
+ {onUpdateTitle ? (
624
+ <DropdownMenuItem
625
+ accessibilityLabel={`Rename chat: ${title}`}
626
+ iconName="pen-to-square"
627
+ label="Rename"
628
+ onClick={handleRename}
629
+ testID={`gpt-rename-history-${history.id}`}
630
+ />
631
+ ) : null}
632
+ <DropdownMenuItem
633
+ accessibilityLabel={`Delete chat: ${title}`}
634
+ color="error"
635
+ iconName="trash-can"
636
+ label="Delete"
637
+ onClick={handleDelete}
638
+ testID={`gpt-delete-history-${history.id}`}
639
+ />
640
+ </Box>
641
+ </DropdownPanel>
506
642
  );
507
643
  };
508
644
 
@@ -569,7 +705,7 @@ const AssistantActions = ({
569
705
  message,
570
706
  onRateFeedback,
571
707
  }: {
572
- handleCopyMessage: (text: string) => void;
708
+ handleCopyMessage: (message: GPTChatMessage) => void;
573
709
  index: number;
574
710
  message: GPTChatMessage;
575
711
  onRateFeedback?: (promptIndex: number, rating: "up" | "down" | null) => void;
@@ -583,7 +719,7 @@ const AssistantActions = ({
583
719
  <IconButton
584
720
  accessibilityLabel="Copy message"
585
721
  iconName="copy"
586
- onClick={() => handleCopyMessage(message.content)}
722
+ onClick={() => handleCopyMessage(message)}
587
723
  testID={`gpt-copy-msg-${index}`}
588
724
  />
589
725
  </Box>
@@ -657,7 +793,7 @@ const MessageList = ({
657
793
  onRateFeedback,
658
794
  }: {
659
795
  currentMessages: GPTChatMessage[];
660
- handleCopyMessage: (text: string) => void;
796
+ handleCopyMessage: (message: GPTChatMessage) => void;
661
797
  onRateFeedback?: (promptIndex: number, rating: "up" | "down" | null) => void;
662
798
  }): React.ReactElement => {
663
799
  return (
@@ -858,6 +994,11 @@ const ApiKeyModal = ({
858
994
  // Main Component
859
995
  // ============================================================
860
996
 
997
+ /** Pixels of content below the viewport before "Scroll to bottom" appears. */
998
+ const SCROLL_TO_BOTTOM_THRESHOLD = 100;
999
+ /** Height the composer grows to before its text scrolls. */
1000
+ const COMPOSER_MAX_HEIGHT = 200;
1001
+
861
1002
  export const GPTChat = ({
862
1003
  attachments = [],
863
1004
  availableModels,
@@ -943,9 +1084,21 @@ export const GPTChat = ({
943
1084
  return () => el.removeEventListener("keydown", handler);
944
1085
  }, [inputElement]);
945
1086
 
946
- const handleCopyMessage = useCallback(async (text: string) => {
1087
+ // Image-only replies have no meaningful text, so copy the image instead of a placeholder.
1088
+ const handleCopyMessage = useCallback(async (message: GPTChatMessage) => {
1089
+ const firstImage = message.contentParts?.find(
1090
+ (part): part is ImageContentPart => part.type === "image"
1091
+ );
1092
+ if (firstImage && !message.content.trim()) {
1093
+ try {
1094
+ await copyImageToClipboard(firstImage);
1095
+ } catch (error) {
1096
+ console.warn("Failed to copy image", error);
1097
+ }
1098
+ return;
1099
+ }
947
1100
  const Clipboard = await import("expo-clipboard");
948
- await Clipboard.setStringAsync(text);
1101
+ await Clipboard.setStringAsync(message.content);
949
1102
  }, []);
950
1103
 
951
1104
  const scrollToBottom = useCallback(() => {
@@ -963,12 +1116,17 @@ export const GPTChat = ({
963
1116
  const handleScroll = useCallback((offsetY: number) => {
964
1117
  scrollOffsetRef.current = offsetY;
965
1118
  const distanceFromBottom = contentHeightRef.current - offsetY - viewportHeightRef.current;
966
- setIsScrolledUp(distanceFromBottom > 100);
1119
+ setIsScrolledUp(distanceFromBottom > SCROLL_TO_BOTTOM_THRESHOLD);
967
1120
  }, []);
968
1121
 
1122
+ // Growing content (a streaming reply) must not count as the user scrolling up, but content
1123
+ // that shrinks to fit the viewport (switching to a short or empty chat) clears the flag.
969
1124
  const handleContentLayout = useCallback(
970
- (_event: {nativeEvent: {layout: {height: number; width: number; x: number; y: number}}}) => {
971
- contentHeightRef.current = _event.nativeEvent.layout.height;
1125
+ (event: {nativeEvent: {layout: {height: number; width: number; x: number; y: number}}}) => {
1126
+ contentHeightRef.current = event.nativeEvent.layout.height;
1127
+ if (contentHeightRef.current <= viewportHeightRef.current + SCROLL_TO_BOTTOM_THRESHOLD) {
1128
+ setIsScrolledUp(false);
1129
+ }
972
1130
  },
973
1131
  []
974
1132
  );
@@ -1095,21 +1253,16 @@ export const GPTChat = ({
1095
1253
  history={history}
1096
1254
  setEditingTitle={setEditingTitle}
1097
1255
  />
1098
- <Box direction="row" gap={1}>
1099
- <HistoryItemActionButton
1256
+ <Box marginLeft={1}>
1257
+ <HistoryItemActions
1100
1258
  editingHistoryId={editingHistoryId}
1101
1259
  handleFinishRename={handleFinishRename}
1102
1260
  handleStartRename={handleStartRename}
1103
1261
  history={history}
1262
+ isSelected={history.id === currentHistoryId}
1263
+ onDeleteHistory={onDeleteHistory}
1104
1264
  onUpdateTitle={onUpdateTitle}
1105
1265
  />
1106
- <IconButton
1107
- accessibilityLabel={`Delete chat: ${history.title ?? "New Chat"}`}
1108
- iconName="trash"
1109
- onClick={() => onDeleteHistory(history.id)}
1110
- testID={`gpt-delete-history-${history.id}`}
1111
- variant="destructive"
1112
- />
1113
1266
  </Box>
1114
1267
  </Box>
1115
1268
  ))}
@@ -1143,7 +1296,10 @@ export const GPTChat = ({
1143
1296
  </Box>
1144
1297
  </Box>
1145
1298
 
1146
- <ScrollToBottomButton isScrolledUp={isScrolledUp} scrollToBottom={scrollToBottom} />
1299
+ <ScrollToBottomButton
1300
+ isScrolledUp={isScrolledUp && !isEmptyChat}
1301
+ scrollToBottom={scrollToBottom}
1302
+ />
1147
1303
  <AttachmentSection attachments={attachments} onRemoveAttachment={onRemoveAttachment} />
1148
1304
 
1149
1305
  {/* Input */}
@@ -1171,7 +1327,9 @@ export const GPTChat = ({
1171
1327
  <TextArea
1172
1328
  blurOnSubmit={false}
1173
1329
  disabled={isStreaming}
1330
+ grow
1174
1331
  inputRef={handleInputRef}
1332
+ maxHeight={COMPOSER_MAX_HEIGHT}
1175
1333
  onChange={setInputValue}
1176
1334
  placeholder="Type a message..."
1177
1335
  testID="gpt-input"
@@ -8,7 +8,7 @@ import {FieldError} from "./fieldElements/FieldError";
8
8
  import {FieldHelperText} from "./fieldElements/FieldHelperText";
9
9
  import {FieldTitle} from "./fieldElements/FieldTitle";
10
10
  import {HeightActionSheet} from "./HeightActionSheet";
11
- import {isMobileDevice} from "./MediaQuery";
11
+ import {isNarrowViewport} from "./MediaQuery";
12
12
  import {SelectField} from "./SelectField";
13
13
  import {Text} from "./Text";
14
14
  import {useTheme} from "./Theme";
@@ -158,7 +158,7 @@ export const HeightField: FC<HeightFieldProps> = ({
158
158
  }) => {
159
159
  const {theme} = useTheme();
160
160
  const actionSheetRef = useRef<ActionSheet | null>(null);
161
- const isMobileOrNative = isMobileDevice() || isNative();
161
+ const isMobileOrNative = isNarrowViewport() || isNative();
162
162
 
163
163
  const minInches = min ?? DEFAULT_MIN_INCHES;
164
164
  const maxInches = max ?? DEFAULT_MAX_INCHES;
@@ -1,7 +1,10 @@
1
1
  import {describe, expect, it, mock} from "bun:test";
2
+ import type {ReactTestInstance} from "react-test-renderer";
2
3
 
3
4
  import {IconButton} from "./IconButton";
5
+ import {useTheme} from "./Theme";
4
6
  import {renderWithIcons, renderWithTheme} from "./test-utils";
7
+ import {applyColorOpacity} from "./Utilities";
5
8
 
6
9
  describe("IconButton", () => {
7
10
  it("renders correctly with default props", () => {
@@ -129,6 +132,24 @@ describe("IconButton", () => {
129
132
  expect(toJSON()).toMatchSnapshot();
130
133
  });
131
134
 
135
+ it("uses the supplied accessibility hint without announcing a confirmation dialog", async () => {
136
+ // bunSetup replaces ./IconButton with a null mock; the query suffix loads the real module.
137
+ const actualIconButtonPath = "./IconButton.tsx?accessibility";
138
+ const {IconButton: ActualIconButton} = (await import(
139
+ actualIconButtonPath
140
+ )) as typeof import("./IconButton");
141
+ const {getByLabelText} = renderWithTheme(
142
+ <ActualIconButton
143
+ accessibilityHint="Back to list"
144
+ accessibilityLabel="Back to list"
145
+ iconName="arrow-left"
146
+ onClick={() => {}}
147
+ />
148
+ );
149
+
150
+ expect(getByLabelText("Back to list").props.accessibilityHint).toBe("Back to list");
151
+ });
152
+
132
153
  it("renders with confirmation props", () => {
133
154
  const {toJSON} = renderWithTheme(
134
155
  <IconButton
@@ -183,6 +204,48 @@ describe("IconButton", () => {
183
204
  expect(toJSON()).toMatchSnapshot();
184
205
  });
185
206
 
207
+ it("keeps a translucent muted background and an opaque icon", async () => {
208
+ // bunSetup replaces ./IconButton with a null mock; the query suffix loads the real module.
209
+ const actualIconButtonPath = "./IconButton.tsx?actual";
210
+ const {IconButton: ActualIconButton} = (await import(
211
+ actualIconButtonPath
212
+ )) as typeof import("./IconButton");
213
+ let inverted = "";
214
+ const CaptureTheme = (): null => {
215
+ const {theme} = useTheme();
216
+ inverted = theme.text.inverted;
217
+ return null;
218
+ };
219
+ const {getByLabelText, UNSAFE_root} = renderWithTheme(
220
+ <>
221
+ <CaptureTheme />
222
+ <ActualIconButton
223
+ accessibilityLabel="muted background solid"
224
+ iconName="check"
225
+ onClick={() => {}}
226
+ variant="muted"
227
+ />
228
+ <ActualIconButton
229
+ accessibilityLabel="muted background translucent"
230
+ backgroundOpacity={0.88}
231
+ iconName="check"
232
+ onClick={() => {}}
233
+ variant="muted"
234
+ />
235
+ </>
236
+ );
237
+
238
+ expect(getByLabelText("muted background solid")).toHaveStyle({backgroundColor: inverted});
239
+ expect(getByLabelText("muted background translucent")).toHaveStyle({
240
+ backgroundColor: applyColorOpacity({color: inverted, opacity: 0.88}),
241
+ });
242
+ const icons = UNSAFE_root.findAll(
243
+ (node: ReactTestInstance) => node.props?.name === "check" && Boolean(node.props?.color)
244
+ );
245
+ expect(icons).toHaveLength(2);
246
+ expect(icons[0].props.color).toBe(icons[1].props.color);
247
+ });
248
+
186
249
  describe("custom icons", () => {
187
250
  // IconButton renders `null` under the bun/react-test-renderer harness (all of
188
251
  // its snapshots are null), so we verify the custom-icon code path renders