@copilotkit/react-textarea 0.18.0 → 0.19.0-alpha.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 (236) hide show
  1. package/.turbo/turbo-build.log +303 -189
  2. package/CHANGELOG.md +19 -0
  3. package/dist/chunk-2NURR2DX.mjs +47 -0
  4. package/dist/chunk-2NURR2DX.mjs.map +1 -0
  5. package/dist/chunk-3YJ63D5D.mjs +106 -0
  6. package/dist/chunk-3YJ63D5D.mjs.map +1 -0
  7. package/dist/chunk-4S5ZJH3I.mjs +18 -0
  8. package/dist/chunk-4S5ZJH3I.mjs.map +1 -0
  9. package/dist/chunk-55EGOC5T.mjs +87 -0
  10. package/dist/chunk-55EGOC5T.mjs.map +1 -0
  11. package/dist/{chunk-3A2CNIG5.mjs → chunk-5ARCOTW3.mjs} +8 -5
  12. package/dist/chunk-5ARCOTW3.mjs.map +1 -0
  13. package/dist/chunk-5EJ5XOGP.mjs +22 -0
  14. package/dist/chunk-5EJ5XOGP.mjs.map +1 -0
  15. package/dist/chunk-5FO6ISW4.mjs +3 -0
  16. package/dist/{chunk-5GGCWNTT.mjs → chunk-5SL5L4VS.mjs} +67 -29
  17. package/dist/chunk-5SL5L4VS.mjs.map +1 -0
  18. package/dist/{chunk-JWN2VEE3.mjs → chunk-A2RRLD23.mjs} +13 -12
  19. package/dist/chunk-A2RRLD23.mjs.map +1 -0
  20. package/dist/chunk-CDB7HFCY.mjs +65 -0
  21. package/dist/chunk-CDB7HFCY.mjs.map +1 -0
  22. package/dist/{chunk-MFJNLKRC.mjs → chunk-D7SEV5PR.mjs} +4 -3
  23. package/dist/chunk-D7SEV5PR.mjs.map +1 -0
  24. package/dist/chunk-HAFHLU4N.mjs +55 -0
  25. package/dist/chunk-HAFHLU4N.mjs.map +1 -0
  26. package/dist/chunk-ITZHK3YV.mjs +477 -0
  27. package/dist/chunk-ITZHK3YV.mjs.map +1 -0
  28. package/dist/{chunk-3UQM3NLM.mjs → chunk-IXJ2HCOA.mjs} +42 -7
  29. package/dist/chunk-IXJ2HCOA.mjs.map +1 -0
  30. package/dist/{chunk-UW3ITU2Y.mjs → chunk-JAFCXEPU.mjs} +1 -1
  31. package/dist/chunk-JAFCXEPU.mjs.map +1 -0
  32. package/dist/chunk-KDFCAQGV.mjs +44 -0
  33. package/dist/chunk-KDFCAQGV.mjs.map +1 -0
  34. package/dist/chunk-L7VVZH4Q.mjs +3 -0
  35. package/dist/chunk-ND5PXTAW.mjs +17 -0
  36. package/dist/chunk-ND5PXTAW.mjs.map +1 -0
  37. package/dist/chunk-O5OWT5GE.mjs +114 -0
  38. package/dist/chunk-O5OWT5GE.mjs.map +1 -0
  39. package/dist/chunk-OD7ZMOVE.mjs +45 -0
  40. package/dist/chunk-OD7ZMOVE.mjs.map +1 -0
  41. package/dist/chunk-OM5WQQOU.mjs +47 -0
  42. package/dist/chunk-OM5WQQOU.mjs.map +1 -0
  43. package/dist/chunk-QL2GYGG5.mjs +19 -0
  44. package/dist/chunk-QL2GYGG5.mjs.map +1 -0
  45. package/dist/chunk-RPDVSCLO.mjs +107 -0
  46. package/dist/chunk-RPDVSCLO.mjs.map +1 -0
  47. package/dist/{chunk-HZGSG7ST.mjs → chunk-UHD44NC5.mjs} +10 -5
  48. package/dist/chunk-UHD44NC5.mjs.map +1 -0
  49. package/dist/chunk-VBIJPE3H.mjs +108 -0
  50. package/dist/chunk-VBIJPE3H.mjs.map +1 -0
  51. package/dist/chunk-XDT7BF3V.mjs +81 -0
  52. package/dist/chunk-XDT7BF3V.mjs.map +1 -0
  53. package/dist/chunk-XHUMROEY.mjs +91 -0
  54. package/dist/chunk-XHUMROEY.mjs.map +1 -0
  55. package/dist/{chunk-LWVCQYWV.mjs → chunk-YQU7WG7T.mjs} +2 -2
  56. package/dist/chunk-YTOPHPSG.mjs +45 -0
  57. package/dist/chunk-YTOPHPSG.mjs.map +1 -0
  58. package/dist/chunk-YW3REYX6.mjs +23 -0
  59. package/dist/chunk-YW3REYX6.mjs.map +1 -0
  60. package/dist/components/base-copilot-textarea/base-copilot-textarea.d.ts +3 -5
  61. package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +21 -7
  62. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.d.ts +6 -0
  63. package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs +5 -0
  64. package/dist/components/copilot-textarea/copilot-textarea.d.ts +13 -10
  65. package/dist/components/copilot-textarea/copilot-textarea.mjs +31 -12
  66. package/dist/components/hovering-toolbar/hovering-editor-provider.d.ts +13 -0
  67. package/dist/components/hovering-toolbar/hovering-editor-provider.mjs +4 -0
  68. package/dist/components/hovering-toolbar/hovering-toolbar-components.d.ts +18 -0
  69. package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs +4 -0
  70. package/dist/components/hovering-toolbar/hovering-toolbar.d.ts +8 -0
  71. package/dist/components/hovering-toolbar/hovering-toolbar.mjs +17 -0
  72. package/dist/components/hovering-toolbar/hovering-toolbar.mjs.map +1 -0
  73. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.d.ts +12 -0
  74. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +12 -0
  75. package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs.map +1 -0
  76. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.d.ts +3 -0
  77. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +13 -0
  78. package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs.map +1 -0
  79. package/dist/components/hovering-toolbar/text-insertion-prompt-box/mode-pre-suggestion.d.ts +16 -0
  80. package/dist/components/hovering-toolbar/text-insertion-prompt-box/mode-pre-suggestion.mjs +5 -0
  81. package/dist/components/hovering-toolbar/text-insertion-prompt-box/mode-pre-suggestion.mjs.map +1 -0
  82. package/dist/components/hovering-toolbar/text-insertion-prompt-box/mode-suggestion-appearing.d.ts +37 -0
  83. package/dist/components/hovering-toolbar/text-insertion-prompt-box/mode-suggestion-appearing.mjs +10 -0
  84. package/dist/components/hovering-toolbar/text-insertion-prompt-box/mode-suggestion-appearing.mjs.map +1 -0
  85. package/dist/components/index.d.ts +9 -4
  86. package/dist/components/index.mjs +31 -12
  87. package/dist/components/manual-ui/chip-with-icon.d.ts +10 -0
  88. package/dist/components/manual-ui/chip-with-icon.mjs +29 -0
  89. package/dist/components/manual-ui/chip-with-icon.mjs.map +1 -0
  90. package/dist/components/source-search-box/source-search-box.d.ts +17 -0
  91. package/dist/components/source-search-box/source-search-box.mjs +10 -0
  92. package/dist/components/source-search-box/source-search-box.mjs.map +1 -0
  93. package/dist/components/ui/button.d.ts +14 -0
  94. package/dist/components/ui/button.mjs +5 -0
  95. package/dist/components/ui/button.mjs.map +1 -0
  96. package/dist/components/ui/card.d.ts +10 -0
  97. package/dist/components/ui/card.mjs +63 -0
  98. package/dist/components/ui/card.mjs.map +1 -0
  99. package/dist/components/ui/command.d.ts +48 -0
  100. package/dist/components/ui/command.mjs +6 -0
  101. package/dist/components/ui/command.mjs.map +1 -0
  102. package/dist/components/ui/dialog.d.ts +18 -0
  103. package/dist/components/ui/dialog.mjs +5 -0
  104. package/dist/components/ui/dialog.mjs.map +1 -0
  105. package/dist/components/ui/label.d.ts +8 -0
  106. package/dist/components/ui/label.mjs +5 -0
  107. package/dist/components/ui/label.mjs.map +1 -0
  108. package/dist/components/ui/separator.d.ts +6 -0
  109. package/dist/components/ui/separator.mjs +26 -0
  110. package/dist/components/ui/separator.mjs.map +1 -0
  111. package/dist/components/ui/textarea.d.ts +7 -0
  112. package/dist/components/ui/textarea.mjs +22 -0
  113. package/dist/components/ui/textarea.mjs.map +1 -0
  114. package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs +2 -2
  115. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.d.ts +2 -2
  116. package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs +2 -2
  117. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.d.ts +5 -7
  118. package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +2 -1
  119. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.d.ts +23 -0
  120. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +5 -0
  121. package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs.map +1 -0
  122. package/dist/hooks/misc/use-autosize-textarea.d.ts +5 -0
  123. package/dist/hooks/misc/use-autosize-textarea.mjs +4 -0
  124. package/dist/hooks/misc/use-autosize-textarea.mjs.map +1 -0
  125. package/dist/index.css +674 -0
  126. package/dist/index.css.map +1 -1
  127. package/dist/index.d.ts +8 -3
  128. package/dist/index.mjs +31 -12
  129. package/dist/lib/editor-to-text.mjs +1 -42
  130. package/dist/lib/editor-to-text.mjs.map +1 -1
  131. package/dist/lib/get-text-around-cursor.d.ts +10 -3
  132. package/dist/lib/get-text-around-cursor.mjs +1 -1
  133. package/dist/lib/retry.d.ts +3 -0
  134. package/dist/lib/retry.mjs +4 -0
  135. package/dist/lib/retry.mjs.map +1 -0
  136. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.d.ts +25 -0
  137. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs +3 -0
  138. package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs.map +1 -0
  139. package/dist/types/autosuggestions-config/autosuggestions-config.d.ts +20 -0
  140. package/dist/types/autosuggestions-config/autosuggestions-config.mjs +10 -0
  141. package/dist/types/autosuggestions-config/autosuggestions-config.mjs.map +1 -0
  142. package/dist/types/autosuggestions-config/editing-api-config.d.ts +17 -0
  143. package/dist/types/autosuggestions-config/editing-api-config.mjs +5 -0
  144. package/dist/types/autosuggestions-config/editing-api-config.mjs.map +1 -0
  145. package/dist/types/autosuggestions-config/index.d.ts +10 -0
  146. package/dist/types/autosuggestions-config/index.mjs +11 -0
  147. package/dist/types/autosuggestions-config/index.mjs.map +1 -0
  148. package/dist/types/autosuggestions-config/insertions-api-config.d.ts +17 -0
  149. package/dist/types/autosuggestions-config/insertions-api-config.mjs +5 -0
  150. package/dist/types/autosuggestions-config/insertions-api-config.mjs.map +1 -0
  151. package/dist/types/{standard-autosuggestions → autosuggestions-config/subtypes}/chatlike-api-endpoint.d.ts +7 -4
  152. package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.mjs +4 -0
  153. package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.mjs.map +1 -0
  154. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.d.ts +3 -0
  155. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs +3 -0
  156. package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs.map +1 -0
  157. package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs.map +1 -0
  158. package/dist/types/autosuggestions-config/suggestions-api-config.d.ts +17 -0
  159. package/dist/types/autosuggestions-config/suggestions-api-config.mjs +5 -0
  160. package/dist/types/autosuggestions-config/suggestions-api-config.mjs.map +1 -0
  161. package/dist/types/base/autosuggestions-bare-function.d.ts +16 -2
  162. package/dist/types/base/base-autosuggestions-config.d.ts +5 -1
  163. package/dist/types/base/base-autosuggestions-config.mjs +1 -1
  164. package/dist/types/base/base-copilot-textarea-props.d.ts +3 -1
  165. package/dist/types/base/editor-autocomplete-state.mjs +1 -1
  166. package/dist/types/base/index.mjs +1 -1
  167. package/dist/types/index.d.ts +8 -3
  168. package/dist/types/index.mjs +7 -4
  169. package/package.json +19 -5
  170. package/src/components/base-copilot-textarea/base-copilot-textarea.tsx +64 -13
  171. package/src/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.tsx +61 -0
  172. package/src/components/copilot-textarea/copilot-textarea.tsx +29 -17
  173. package/src/components/hovering-toolbar/hovering-editor-provider.tsx +29 -0
  174. package/src/components/hovering-toolbar/hovering-toolbar-components.tsx +115 -0
  175. package/src/components/hovering-toolbar/hovering-toolbar.tsx +156 -0
  176. package/src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.tsx +73 -0
  177. package/src/components/hovering-toolbar/text-insertion-prompt-box/index.ts +2 -0
  178. package/src/components/hovering-toolbar/text-insertion-prompt-box/mode-pre-suggestion.tsx +83 -0
  179. package/src/components/hovering-toolbar/text-insertion-prompt-box/mode-suggestion-appearing.tsx +410 -0
  180. package/src/components/manual-ui/chip-with-icon.tsx +28 -0
  181. package/src/components/source-search-box/source-search-box.tsx +133 -0
  182. package/src/components/ui/button.tsx +56 -0
  183. package/src/components/ui/card.tsx +86 -0
  184. package/src/components/ui/command.tsx +155 -0
  185. package/src/components/ui/dialog.tsx +123 -0
  186. package/src/components/ui/label.tsx +26 -0
  187. package/src/components/ui/separator.tsx +31 -0
  188. package/src/components/ui/textarea.tsx +24 -0
  189. package/src/hooks/base-copilot-textarea-implementation/use-autosuggestions.ts +10 -3
  190. package/src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx +29 -44
  191. package/src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx +150 -0
  192. package/src/hooks/misc/use-autosize-textarea.tsx +21 -0
  193. package/src/lib/get-text-around-cursor.ts +71 -6
  194. package/src/lib/retry.tsx +23 -0
  195. package/src/styles.css +2 -0
  196. package/src/types/autosuggestions-config/autosuggestions-config-user-specified.tsx +27 -0
  197. package/src/types/autosuggestions-config/autosuggestions-config.tsx +43 -0
  198. package/src/types/autosuggestions-config/editing-api-config.tsx +102 -0
  199. package/src/types/autosuggestions-config/index.ts +11 -0
  200. package/src/types/autosuggestions-config/insertions-api-config.tsx +95 -0
  201. package/src/types/{standard-autosuggestions → autosuggestions-config/subtypes}/chatlike-api-endpoint.tsx +19 -7
  202. package/src/types/autosuggestions-config/subtypes/make-system-prompt.ts +4 -0
  203. package/src/types/{standard-autosuggestions/autosuggestions-config.tsx → autosuggestions-config/suggestions-api-config.tsx} +12 -23
  204. package/src/types/base/autosuggestions-bare-function.ts +24 -2
  205. package/src/types/base/base-autosuggestions-config.tsx +7 -2
  206. package/src/types/base/base-copilot-textarea-props.tsx +3 -1
  207. package/src/types/base/editor-autocomplete-state.ts +1 -0
  208. package/src/types/index.ts +1 -1
  209. package/tailwind.config.js +2 -0
  210. package/dist/chunk-3A2CNIG5.mjs.map +0 -1
  211. package/dist/chunk-3UQM3NLM.mjs.map +0 -1
  212. package/dist/chunk-5GGCWNTT.mjs.map +0 -1
  213. package/dist/chunk-BLRD23HM.mjs +0 -32
  214. package/dist/chunk-BLRD23HM.mjs.map +0 -1
  215. package/dist/chunk-BTAUKCBN.mjs +0 -60
  216. package/dist/chunk-BTAUKCBN.mjs.map +0 -1
  217. package/dist/chunk-HZGSG7ST.mjs.map +0 -1
  218. package/dist/chunk-JWN2VEE3.mjs.map +0 -1
  219. package/dist/chunk-MFJNLKRC.mjs.map +0 -1
  220. package/dist/chunk-SL4J5HMW.mjs +0 -3
  221. package/dist/chunk-UW3ITU2Y.mjs.map +0 -1
  222. package/dist/types/standard-autosuggestions/autosuggestions-config.d.ts +0 -19
  223. package/dist/types/standard-autosuggestions/autosuggestions-config.mjs +0 -6
  224. package/dist/types/standard-autosuggestions/chatlike-api-endpoint.mjs +0 -4
  225. package/dist/types/standard-autosuggestions/index.d.ts +0 -4
  226. package/dist/types/standard-autosuggestions/index.mjs +0 -8
  227. package/src/types/standard-autosuggestions/index.ts +0 -14
  228. /package/dist/{chunk-SL4J5HMW.mjs.map → chunk-5FO6ISW4.mjs.map} +0 -0
  229. /package/dist/{types/standard-autosuggestions/autosuggestions-config.mjs.map → chunk-L7VVZH4Q.mjs.map} +0 -0
  230. /package/dist/{chunk-LWVCQYWV.mjs.map → chunk-YQU7WG7T.mjs.map} +0 -0
  231. /package/dist/{types/standard-autosuggestions/chatlike-api-endpoint.mjs.map → components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs.map} +0 -0
  232. /package/dist/{types/standard-autosuggestions/index.mjs.map → components/hovering-toolbar/hovering-editor-provider.mjs.map} +0 -0
  233. /package/dist/{types/standard-autosuggestions/minimal-chat-gpt-message.mjs.map → components/hovering-toolbar/hovering-toolbar-components.mjs.map} +0 -0
  234. /package/dist/types/{standard-autosuggestions → autosuggestions-config/subtypes}/minimal-chat-gpt-message.d.ts +0 -0
  235. /package/dist/types/{standard-autosuggestions → autosuggestions-config/subtypes}/minimal-chat-gpt-message.mjs +0 -0
  236. /package/src/types/{standard-autosuggestions → autosuggestions-config/subtypes}/minimal-chat-gpt-message.tsx +0 -0
@@ -0,0 +1,410 @@
1
+ import useAutosizeTextArea from "../../../hooks/misc/use-autosize-textarea";
2
+ import { MinimalChatGPTMessage } from "../../../types";
3
+ import {
4
+ EditingEditorState,
5
+ Generator_InsertionOrEditingSuggestion,
6
+ } from "../../../types/base/autosuggestions-bare-function";
7
+ import { ChipWithIcon } from "../../manual-ui/chip-with-icon";
8
+ import {
9
+ FilePointer,
10
+ SourceSearchBox,
11
+ } from "../../source-search-box/source-search-box";
12
+ import { Button } from "../../ui/button";
13
+ import { Label } from "../../ui/label";
14
+ import React, { useEffect, useRef, useState } from "react";
15
+
16
+ import Chip from "@mui/material/Chip";
17
+ import Avatar from "@mui/material/Avatar";
18
+
19
+ export type State_SuggestionAppearing = {
20
+ type: "suggestion-appearing";
21
+ initialSuggestion: SuggestionSnapshot;
22
+ };
23
+
24
+ type SuggestionSnapshot = {
25
+ adjustmentPrompt: string;
26
+ generatingSuggestion: ReadableStream<string>;
27
+ editorState: EditingEditorState;
28
+ };
29
+
30
+ export interface SuggestionAppearingProps {
31
+ state: State_SuggestionAppearing;
32
+ performInsertion: (insertedText: string) => void;
33
+ goBack: () => void;
34
+ insertionOrEditingFunction: Generator_InsertionOrEditingSuggestion;
35
+ onGeneratedText: (generatedText: ReadableStream<string>) => void;
36
+ }
37
+
38
+ export const SuggestionAppearing: React.FC<SuggestionAppearingProps> = ({
39
+ performInsertion,
40
+ state,
41
+ goBack,
42
+ insertionOrEditingFunction,
43
+ onGeneratedText,
44
+ }) => {
45
+ const [adjustmentHistory, setAdjustmentHistory] = useState<
46
+ SuggestionSnapshot[]
47
+ >([state.initialSuggestion]);
48
+
49
+ const [editSuggestion, setEditSuggestion] = useState<string>("");
50
+ const [suggestionIsLoading, setSuggestionIsLoading] =
51
+ useState<boolean>(false);
52
+
53
+ const [adjustmentPrompt, setAdjustmentPrompt] = useState<string>("");
54
+ const [adjustmentLoading, setAdjustmentLoading] = useState<boolean>(false);
55
+
56
+ const suggestionTextAreaRef = useRef<HTMLTextAreaElement>(null);
57
+ const adjustmentTextAreaRef = useRef<HTMLTextAreaElement>(null);
58
+
59
+ const [filePointers, setFilePointers] = useState<FilePointer[]>([]);
60
+
61
+ useAutosizeTextArea(suggestionTextAreaRef, editSuggestion || "");
62
+ useAutosizeTextArea(adjustmentTextAreaRef, adjustmentPrompt || "");
63
+
64
+ // initially focus on the end of the suggestion text area
65
+ useEffect(() => {
66
+ suggestionTextAreaRef.current?.focus();
67
+ suggestionTextAreaRef.current?.setSelectionRange(
68
+ editSuggestion.length,
69
+ editSuggestion.length
70
+ );
71
+ }, []);
72
+
73
+ useEffect(() => {
74
+ // Check if the stream is already locked
75
+ if (state.initialSuggestion.generatingSuggestion.locked) {
76
+ return;
77
+ }
78
+ // reset the edit suggestion
79
+ setEditSuggestion("");
80
+
81
+ // read the generating suggestion stream and continuously update the edit suggestion
82
+ const reader = state.initialSuggestion.generatingSuggestion.getReader();
83
+
84
+ const read = async () => {
85
+ setSuggestionIsLoading(true);
86
+ while (true) {
87
+ const { done, value } = await reader.read();
88
+ if (done) {
89
+ break;
90
+ }
91
+ setEditSuggestion((prev) => {
92
+ const newSuggestion = prev + value;
93
+ // Scroll to the bottom of the textarea. We call this here to make sure scroll-to-bottom is synchronous with the state update.
94
+ if (suggestionTextAreaRef.current) {
95
+ suggestionTextAreaRef.current.scrollTop =
96
+ suggestionTextAreaRef.current.scrollHeight;
97
+ }
98
+ return newSuggestion;
99
+ });
100
+ }
101
+
102
+ setSuggestionIsLoading(false);
103
+ };
104
+ read();
105
+
106
+ return () => {
107
+ const releaseLockIfNotClosed = async () => {
108
+ try {
109
+ await reader.closed;
110
+ } catch {
111
+ reader.releaseLock();
112
+ }
113
+ };
114
+
115
+ releaseLockIfNotClosed();
116
+ };
117
+ }, [state]);
118
+
119
+ const generateAdjustment = async () => {
120
+ // don't generate text if the prompt is empty
121
+ if (!adjustmentPrompt.trim()) {
122
+ return;
123
+ }
124
+
125
+ setAdjustmentLoading(true);
126
+ // use insertionOrEditingFunction
127
+ const adjustmentSuggestionTextStream = await insertionOrEditingFunction(
128
+ {
129
+ ...state.initialSuggestion.editorState,
130
+ selectedText: editSuggestion,
131
+ },
132
+ adjustmentPrompt,
133
+ new AbortController().signal
134
+ );
135
+ setAdjustmentLoading(false);
136
+ onGeneratedText(adjustmentSuggestionTextStream);
137
+ };
138
+
139
+ const showLoading = suggestionIsLoading || adjustmentLoading;
140
+
141
+ const AdjustmentPromptComponent = (
142
+ <>
143
+ <Label className="">Describe adjustments to the suggested text:</Label>
144
+ <div className="relative w-full flex items-center">
145
+ <textarea
146
+ disabled={suggestionIsLoading}
147
+ ref={adjustmentTextAreaRef}
148
+ value={adjustmentPrompt}
149
+ onChange={(e) => setAdjustmentPrompt(e.target.value)}
150
+ onKeyDown={(e) => {
151
+ if (e.key === "Enter" && e.shiftKey) {
152
+ e.preventDefault();
153
+ setAdjustmentPrompt(adjustmentPrompt + "\n");
154
+ } else if (e.key === "Enter") {
155
+ e.preventDefault();
156
+ generateAdjustment();
157
+ }
158
+ }}
159
+ placeholder={'"make it more formal", "be more specific", ...'}
160
+ style={{ minHeight: "3rem" }}
161
+ className="w-full bg-slate-100 h-auto h-min-14 text-sm p-2 rounded-md resize-none overflow-visible focus:outline-none focus:ring-0 focus:border-non pr-[3rem]"
162
+ rows={1}
163
+ />
164
+ <button
165
+ onClick={generateAdjustment}
166
+ className="absolute right-2 bg-blue-500 text-white w-8 h-8 rounded-full flex items-center justify-center"
167
+ >
168
+ <i className="material-icons">arrow_forward</i>
169
+ </button>
170
+ </div>
171
+ </>
172
+ );
173
+
174
+ const SuggestionComponent = (
175
+ <>
176
+ <div className="flex justify-between items-end w-full">
177
+ <Label className="mt-4">Suggested:</Label>
178
+ <div className="ml-auto">
179
+ {showLoading && (
180
+ <div className="flex justify-center items-center">
181
+ <div
182
+ className="inline-block h-4 w-4 animate-spin rounded-full border-4 border-solid border-current border-r-transparent align-[-0.125em] motion-reduce:animate-[spin_1.5s_linear_infinite]"
183
+ role="status"
184
+ >
185
+ <span className="!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]">
186
+ Loading...
187
+ </span>
188
+ </div>
189
+ </div>
190
+ )}
191
+ </div>
192
+ </div>
193
+ <textarea
194
+ ref={suggestionTextAreaRef}
195
+ value={editSuggestion}
196
+ disabled={adjustmentLoading}
197
+ onChange={(e) => setEditSuggestion(e.target.value)}
198
+ className="w-full text-base p-2 border border-gray-300 rounded-md resize-none bg-green-50"
199
+ style={{ overflow: "auto", maxHeight: "10em" }}
200
+ />
201
+ </>
202
+ );
203
+
204
+ const SubmitComponent = (
205
+ <div className="flex w-full gap-4 justify-start">
206
+ <Button
207
+ className=" bg-gray-300"
208
+ onClick={() => {
209
+ goBack();
210
+ }}
211
+ >
212
+ <i className="material-icons">arrow_back</i> Back
213
+ </Button>
214
+
215
+ <Button
216
+ className=" bg-green-700 text-white"
217
+ onClick={() => {
218
+ performInsertion(editSuggestion);
219
+ }}
220
+ >
221
+ Insert <i className="material-icons">check</i>
222
+ </Button>
223
+ </div>
224
+ );
225
+
226
+ // show source search if the last word in the adjustment prompt BEGINS with an @
227
+ const sourceSearchCandidate = adjustmentPrompt.split(" ").pop();
228
+ // if the candidate is @someCandidate, then 'someCandidate', otherwise undefined
229
+ const sourceSearchWord = sourceSearchCandidate?.startsWith("@")
230
+ ? sourceSearchCandidate.slice(1)
231
+ : undefined;
232
+
233
+ return (
234
+ <div className="w-full flex flex-col items-start relative gap-2">
235
+ {AdjustmentPromptComponent}
236
+ {filePointers.length > 0 && (
237
+ <IncludedFilesPreview
238
+ includedFiles={filePointers}
239
+ setIncludedFiles={setFilePointers}
240
+ />
241
+ )}
242
+ {sourceSearchWord !== undefined && (
243
+ <SourceSearchBox
244
+ searchTerm={sourceSearchWord}
245
+ recentFiles={mockFiles}
246
+ onSelectedFile={(filePointer) => {
247
+ setAdjustmentPrompt(
248
+ adjustmentPrompt.replace(new RegExp(`@${sourceSearchWord}$`), "")
249
+ );
250
+ setFilePointers((prev) => [...prev, filePointer]);
251
+
252
+ // focus back on the adjustment prompt, and move the cursor to the end
253
+ adjustmentTextAreaRef.current?.focus();
254
+ }}
255
+ />
256
+ )}
257
+ {SuggestionComponent}
258
+ {SubmitComponent}
259
+ </div>
260
+ );
261
+ };
262
+
263
+ interface IncludedFilesPreviewProps {
264
+ includedFiles: FilePointer[];
265
+ setIncludedFiles: React.Dispatch<React.SetStateAction<FilePointer[]>>;
266
+ }
267
+
268
+ export const IncludedFilesPreview: React.FC<IncludedFilesPreviewProps> = ({
269
+ includedFiles,
270
+ setIncludedFiles,
271
+ }) => {
272
+ return (
273
+ <div className="flex flex-col gap-2">
274
+ <div className="flex flex-wrap gap-2">
275
+ {includedFiles.map((filePointer, index) => {
276
+ return (
277
+ <FileChipPreview
278
+ key={`file-${filePointer.sourceApplication}.${filePointer.name}`}
279
+ filePointer={filePointer}
280
+ onDelete={() => {
281
+ setIncludedFiles((prev) =>
282
+ prev.filter((fp) => fp !== filePointer)
283
+ );
284
+ }}
285
+ />
286
+ );
287
+ })}
288
+ </div>
289
+ </div>
290
+ );
291
+ };
292
+
293
+ export interface FileChipPreviewProp {
294
+ filePointer: FilePointer;
295
+ onDelete: () => void;
296
+ }
297
+
298
+ export const FileChipPreview: React.FC<FileChipPreviewProp> = ({
299
+ filePointer,
300
+ onDelete,
301
+ }) => {
302
+ return (
303
+ <Chip
304
+ label={filePointer.name}
305
+ onDelete={onDelete}
306
+ avatar={
307
+ <Avatar sx={{ backgroundColor: "transparent" }}>
308
+ <IconForFilePointer
309
+ filePointer={filePointer}
310
+ className="w-4 h-4 object-contain"
311
+ />
312
+ </Avatar>
313
+ }
314
+ />
315
+ );
316
+ };
317
+
318
+ export function IconForFilePointer({
319
+ filePointer,
320
+ className,
321
+ }: {
322
+ filePointer: FilePointer;
323
+ className: string;
324
+ }): JSX.Element {
325
+ if (filePointer.sourceApplication === "Salesforce") {
326
+ return <IconSalesforce className={className} />;
327
+ } else {
328
+ return <IconSalesforce className={className} />;
329
+ }
330
+ }
331
+
332
+ function IconSalesforce({ className, ...props }: React.ComponentProps<"svg">) {
333
+ return (
334
+ <svg
335
+ xmlns="http://www.w3.org/2000/svg"
336
+ xmlnsXlink="http://www.w3.org/1999/xlink"
337
+ preserveAspectRatio="xMidYMid meet"
338
+ viewBox="0 0 273 191"
339
+ {...props}
340
+ >
341
+ <title>{"Salesforce.com logo"}</title>
342
+ <defs>
343
+ <path id="a" d="M.06.5h272v190H.06z" />
344
+ </defs>
345
+ <g fillRule="evenodd">
346
+ <mask id="b" fill="#fff">
347
+ <use xlinkHref="#a" />
348
+ </mask>
349
+ <path
350
+ fill="#00A1E0"
351
+ d="M113 21.3c8.78-9.14 21-14.8 34.5-14.8 18 0 33.6 10 42 24.9a58 58 0 0 1 23.7-5.05c32.4 0 58.7 26.5 58.7 59.2s-26.3 59.2-58.7 59.2c-3.96 0-7.82-.398-11.6-1.15-7.35 13.1-21.4 22-37.4 22a42.7 42.7 0 0 1-18.8-4.32c-7.45 17.5-24.8 29.8-45 29.8-21.1 0-39-13.3-45.9-32a45.1 45.1 0 0 1-9.34.972c-25.1 0-45.4-20.6-45.4-45.9 0-17 9.14-31.8 22.7-39.8a52.6 52.6 0 0 1-4.35-21c0-29.2 23.7-52.8 52.9-52.8 17.1 0 32.4 8.15 42 20.8"
352
+ mask="url(#b)"
353
+ />
354
+ <path
355
+ fill="#FFFFFE"
356
+ d="M39.4 99.3c-.171.446.061.539.116.618.511.37 1.03.638 1.55.939 2.78 1.47 5.4 1.9 8.14 1.9 5.58 0 9.05-2.97 9.05-7.75v-.094c0-4.42-3.92-6.03-7.58-7.18l-.479-.155c-2.77-.898-5.16-1.68-5.16-3.5v-.093c0-1.56 1.4-2.71 3.56-2.71 2.4 0 5.26.799 7.09 1.81 0 0 .542.35.739-.173.107-.283 1.04-2.78 1.14-3.06.106-.293-.08-.514-.271-.628-2.1-1.28-5-2.15-8-2.15l-.557.002c-5.11 0-8.68 3.09-8.68 7.51v.095c0 4.66 3.94 6.18 7.62 7.23l.592.184c2.68.824 5 1.54 5 3.42v.094c0 1.73-1.51 3.02-3.93 3.02-.941 0-3.94-.016-7.19-2.07-.393-.229-.617-.394-.92-.579-.16-.097-.56-.272-.734.252l-1.1 3.06m81.7 0c-.171.446.061.539.118.618.509.37 1.03.638 1.55.939 2.78 1.47 5.4 1.9 8.14 1.9 5.58 0 9.05-2.97 9.05-7.75v-.094c0-4.42-3.91-6.03-7.58-7.18l-.479-.155c-2.77-.898-5.16-1.68-5.16-3.5v-.093c0-1.56 1.4-2.71 3.56-2.71 2.4 0 5.25.799 7.09 1.81 0 0 .542.35.74-.173.106-.283 1.04-2.78 1.13-3.06.107-.293-.08-.514-.27-.628-2.1-1.28-5-2.15-8-2.15l-.558.002c-5.11 0-8.68 3.09-8.68 7.51v.095c0 4.66 3.94 6.18 7.62 7.23l.591.184c2.69.824 5 1.54 5 3.42v.094c0 1.73-1.51 3.02-3.93 3.02-.943 0-3.95-.016-7.19-2.07-.393-.229-.623-.387-.921-.579-.101-.064-.572-.248-.733.252l-1.1 3.06m55.8-9.36c0 2.7-.504 4.83-1.49 6.34-.984 1.49-2.47 2.22-4.54 2.22s-3.55-.724-4.52-2.21c-.977-1.5-1.47-3.64-1.47-6.34 0-2.7.496-4.82 1.47-6.31.968-1.48 2.44-2.19 4.52-2.19s3.56.717 4.54 2.19c.992 1.49 1.49 3.61 1.49 6.31m4.66-5.01c-.459-1.55-1.17-2.91-2.12-4.05a10.151 10.151 0 0 0-3.58-2.72c-1.42-.665-3.1-1-5-1s-3.57.337-5 1c-1.42.664-2.63 1.58-3.58 2.72-.948 1.14-1.66 2.5-2.12 4.05-.455 1.54-.686 3.22-.686 5.01 0 1.79.231 3.47.686 5.01.457 1.55 1.17 2.91 2.12 4.05.951 1.14 2.16 2.05 3.58 2.7 1.43.648 3.11.978 5 .978 1.89 0 3.57-.33 4.99-.978 1.42-.648 2.63-1.56 3.58-2.7.949-1.14 1.66-2.5 2.12-4.05.454-1.54.685-3.22.685-5.01 0-1.78-.231-3.47-.685-5.01m38.3 12.8c-.153-.453-.595-.282-.595-.282-.677.259-1.4.499-2.17.619-.776.122-1.64.183-2.55.183-2.25 0-4.05-.671-5.33-2-1.29-1.33-2.01-3.47-2-6.37.007-2.64.645-4.62 1.79-6.14 1.13-1.5 2.87-2.28 5.17-2.28 1.92 0 3.39.223 4.93.705 0 0 .365.159.54-.322.409-1.13.711-1.94 1.15-3.18.124-.355-.18-.505-.291-.548-.604-.236-2.03-.623-3.11-.786-1.01-.154-2.18-.234-3.5-.234-1.96 0-3.7.335-5.19.999-1.49.663-2.75 1.58-3.75 2.72-1 1.14-1.76 2.5-2.27 4.05-.505 1.54-.76 3.23-.76 5.02 0 3.86 1.04 6.99 3.1 9.28 2.06 2.3 5.16 3.46 9.2 3.46 2.39 0 4.84-.483 6.6-1.18 0 0 .336-.162.19-.554l-1.15-3.16m8.15-10.4c.223-1.5.634-2.75 1.28-3.72.967-1.48 2.44-2.29 4.51-2.29s3.44.814 4.42 2.29c.65.975.934 2.27 1.04 3.72l-11.3-.002zm15.7-3.3c-.397-1.49-1.38-3-2.02-3.69-1.02-1.09-2.01-1.86-3-2.28a11.5 11.5 0 0 0-4.52-.917c-1.97 0-3.76.333-5.21 1.01-1.45.682-2.67 1.61-3.63 2.77-.959 1.16-1.68 2.53-2.14 4.1-.46 1.55-.692 3.25-.692 5.03 0 1.82.241 3.51.715 5.04.479 1.54 1.25 2.89 2.29 4.01 1.04 1.13 2.37 2.01 3.97 2.63 1.59.615 3.52.934 5.73.927 4.56-.015 6.96-1.03 7.94-1.58.175-.098.34-.267.134-.754l-1.03-2.89c-.158-.431-.594-.275-.594-.275-1.13.422-2.73 1.18-6.48 1.17-2.45-.004-4.26-.727-5.4-1.86-1.16-1.16-1.74-2.85-1.83-5.25l15.8.012s.416-.004.459-.41c.017-.168.541-3.24-.471-6.79zm-142 3.3c.223-1.5.635-2.75 1.28-3.72.968-1.48 2.44-2.29 4.51-2.29s3.44.814 4.42 2.29c.649.975.933 2.27 1.04 3.72l-11.3-.002zm15.7-3.3c-.396-1.49-1.38-3-2.02-3.69-1.02-1.09-2.01-1.86-3-2.28a11.5 11.5 0 0 0-4.52-.917c-1.97 0-3.76.333-5.21 1.01-1.45.682-2.67 1.61-3.63 2.77-.957 1.16-1.68 2.53-2.14 4.1-.459 1.55-.69 3.25-.69 5.03 0 1.82.239 3.51.716 5.04.478 1.54 1.25 2.89 2.28 4.01 1.04 1.13 2.37 2.01 3.97 2.63 1.59.615 3.51.934 5.73.927 4.56-.015 6.96-1.03 7.94-1.58.174-.098.34-.267.133-.754l-1.03-2.89c-.159-.431-.595-.275-.595-.275-1.13.422-2.73 1.18-6.48 1.17-2.44-.004-4.26-.727-5.4-1.86-1.16-1.16-1.74-2.85-1.83-5.25l15.8.012s.416-.004.459-.41c.017-.168.541-3.24-.472-6.79zm-49.8 13.6c-.619-.494-.705-.615-.91-.936-.313-.483-.473-1.17-.473-2.05 0-1.38.46-2.38 1.41-3.05-.01.002 1.36-1.18 4.58-1.14a32 32 0 0 1 4.28.365v7.17h.002s-2 .431-4.26.567c-3.21.193-4.63-.924-4.62-.921zm6.28-11.1c-.64-.047-1.47-.07-2.46-.07-1.35 0-2.66.168-3.88.498-1.23.332-2.34.846-3.29 1.53a7.63 7.63 0 0 0-2.29 2.6c-.559 1.04-.844 2.26-.844 3.64 0 1.4.243 2.61.723 3.6a6.54 6.54 0 0 0 2.06 2.47c.877.638 1.96 1.11 3.21 1.39 1.24.283 2.64.426 4.18.426 1.62 0 3.23-.136 4.79-.399a95.1 95.1 0 0 0 3.97-.772c.526-.121 1.11-.28 1.11-.28.39-.099.36-.516.36-.516l-.009-14.4c0-3.16-.844-5.51-2.51-6.96-1.66-1.45-4.09-2.18-7.24-2.18-1.18 0-3.09.16-4.23.389 0 0-3.44.668-4.86 1.78 0 0-.312.192-.142.627l1.12 3c.139.389.518.256.518.256s.119-.047.259-.13c3.03-1.65 6.87-1.6 6.87-1.6 1.7 0 3.02.345 3.9 1.02.861.661 1.3 1.66 1.3 3.76v.667c-1.35-.196-2.6-.309-2.6-.309zm127-8.13a.428.428 0 0 0-.237-.568c-.269-.102-1.61-.385-2.64-.449-1.98-.124-3.08.21-4.07.654-.978.441-2.06 1.15-2.66 1.97l-.002-1.92c0-.264-.187-.477-.453-.477h-4.04c-.262 0-.452.213-.452.477v23.5a.48.48 0 0 0 .479.479h4.14a.479.479 0 0 0 .478-.479v-11.8c0-1.58.174-3.15.521-4.14.342-.979.807-1.76 1.38-2.32a4.79 4.79 0 0 1 1.95-1.17 7.68 7.68 0 0 1 2.12-.298c.825 0 1.73.212 1.73.212.304.034.473-.152.576-.426.271-.721 1.04-2.88 1.19-3.31"
357
+ />
358
+ <path
359
+ fill="#FFFFFE"
360
+ d="M162.201 67.548a13.258 13.258 0 0 0-1.559-.37 12.217 12.217 0 0 0-2.144-.166c-2.853 0-5.102.806-6.681 2.398-1.568 1.58-2.635 3.987-3.17 7.154l-.193 1.069h-3.581s-.437-.018-.529.459l-.588 3.28c-.041.314.094.51.514.508h3.486l-3.537 19.743c-.277 1.59-.594 2.898-.945 3.889-.346.978-.684 1.711-1.1 2.243-.403.515-.785.894-1.444 1.115-.544.183-1.17.267-1.856.267-.382 0-.89-.064-1.265-.139-.375-.074-.57-.158-.851-.276 0 0-.409-.156-.57.254-.131.335-1.06 2.89-1.17 3.206-.112.312.045.558.243.629.464.166.809.272 1.441.421.878.207 1.618.22 2.311.22 1.452 0 2.775-.204 3.872-.6 1.104-.399 2.065-1.094 2.915-2.035.919-1.015 1.497-2.078 2.05-3.528.547-1.437 1.013-3.221 1.386-5.3l3.554-20.109h5.196s.438.016.529-.459l.588-3.28c.041-.314-.093-.51-.515-.508h-5.043c.025-.114.254-1.888.833-3.558.247-.713.712-1.288 1.106-1.683a3.273 3.273 0 0 1 1.321-.822 5.48 5.48 0 0 1 1.693-.244c.475 0 .941.057 1.296.131.489.104.679.159.807.197.514.157.583.005.684-.244l1.206-3.312c.124-.356-.178-.506-.29-.55m-70.474 34.117c0 .264-.188.479-.452.479h-4.183c-.265 0-.453-.215-.453-.479V67.997c0-.263.188-.476.453-.476h4.183c.264 0 .452.213.452.476v33.668"
361
+ />
362
+ </g>
363
+ </svg>
364
+ );
365
+ }
366
+
367
+ const mockFiles: FilePointer[] = [
368
+ {
369
+ name: "prospecting call transcript",
370
+ sourceApplication: "Salesforce",
371
+ getContents: async () => {
372
+ return "some contents";
373
+ },
374
+ },
375
+ {
376
+ name: "customer feedback",
377
+ sourceApplication: "Zendesk",
378
+ getContents: async () => {
379
+ return "some contents";
380
+ },
381
+ },
382
+ {
383
+ name: "product specifications",
384
+ sourceApplication: "Google Docs",
385
+ getContents: async () => {
386
+ return "some contents";
387
+ },
388
+ },
389
+ {
390
+ name: "meeting minutes",
391
+ sourceApplication: "Microsoft Teams",
392
+ getContents: async () => {
393
+ return "some contents";
394
+ },
395
+ },
396
+ {
397
+ name: "project plan",
398
+ sourceApplication: "Trello",
399
+ getContents: async () => {
400
+ return "some contents";
401
+ },
402
+ },
403
+ {
404
+ name: "code review comments",
405
+ sourceApplication: "Github",
406
+ getContents: async () => {
407
+ return "some contents";
408
+ },
409
+ },
410
+ ];
@@ -0,0 +1,28 @@
1
+ import React from "react";
2
+
3
+ export interface ChipWithIconProps {
4
+ label: string;
5
+ onDelete: () => void;
6
+ iconUrl: string;
7
+ }
8
+
9
+ export const ChipWithIcon: React.FC<ChipWithIconProps> = ({
10
+ label,
11
+ onDelete,
12
+ iconUrl,
13
+ }) => {
14
+ return (
15
+ <span className="inline-flex items-center px-3 py-1 rounded-full bg-slate-200 text-sm font-medium text-white">
16
+ {iconUrl && (
17
+ <img src={iconUrl} alt="icon" className="w-4 h-4 rounded-full mr-2" />
18
+ )}
19
+ {label}
20
+ <button
21
+ className="ml-2 text-white hover:text-gray-200 focus:outline-none"
22
+ onClick={onDelete}
23
+ >
24
+ x
25
+ </button>
26
+ </span>
27
+ );
28
+ };
@@ -0,0 +1,133 @@
1
+ import { useState } from "react";
2
+ import {
3
+ Command,
4
+ CommandDialog,
5
+ CommandEmpty,
6
+ CommandGroup,
7
+ CommandInput,
8
+ CommandItem,
9
+ CommandList,
10
+ CommandSeparator,
11
+ CommandShortcut,
12
+ } from "../ui/command";
13
+
14
+ import {
15
+ Calculator,
16
+ Calendar,
17
+ CreditCard,
18
+ Settings,
19
+ Smile,
20
+ User,
21
+ } from "lucide-react";
22
+ import { IconForFilePointer } from "../hovering-toolbar/text-insertion-prompt-box/mode-suggestion-appearing";
23
+
24
+ export interface FilePointer {
25
+ name: string;
26
+ sourceApplication: string;
27
+ getContents: () => Promise<string>;
28
+ }
29
+
30
+ export interface SourceSearchBoxProps {
31
+ searchTerm: string;
32
+ recentFiles: FilePointer[];
33
+ onSelectedFile: (filePointer: FilePointer) => void;
34
+ }
35
+
36
+ export function SourceSearchBox(props: SourceSearchBoxProps) {
37
+ const [selectedValue, setSelectedValue] = useState<string>("");
38
+
39
+ return (
40
+ <Command
41
+ className="rounded-lg border shadow-md"
42
+ value={selectedValue}
43
+ onValueChange={(value) => {
44
+ setSelectedValue(value);
45
+ }}
46
+ filter={(value, search) => {
47
+ // if the search term is empty, show all commands
48
+ if (props.searchTerm === "") return 1;
49
+
50
+ // if the search term is a prefix of the command, show it
51
+ if (value.startsWith(props.searchTerm)) return 1;
52
+
53
+ // otherwise, don't show it
54
+ return 0;
55
+ }}
56
+ >
57
+ <CommandInput
58
+ value={props.searchTerm}
59
+ className="rounded-t-lg hidden"
60
+ placeholder="Search for a command..."
61
+ />
62
+ <CommandList>
63
+ <CommandEmpty>No results found.</CommandEmpty>
64
+
65
+ <CommandGroup heading="Recents">
66
+ {props.recentFiles.map((filePointer) => {
67
+ return (
68
+ <CommandItem
69
+ key={`word-${filePointer.sourceApplication}.${filePointer.name}`}
70
+ value={filePointer.name}
71
+ onSelect={(value) => {
72
+ console.log(filePointer.name);
73
+ props.onSelectedFile(filePointer);
74
+ }}
75
+ >
76
+ <div className="flex flex-row gap-3 items-center bg-slate-400 ">
77
+ <Logo size="40px">
78
+ <IconForFilePointer
79
+ filePointer={filePointer}
80
+ className="mx-auto my-auto"
81
+ />
82
+ </Logo>
83
+ {filePointer.name}
84
+ </div>
85
+ </CommandItem>
86
+ );
87
+ })}
88
+ </CommandGroup>
89
+
90
+ <CommandGroup heading="Suggestions">
91
+ <CommandItem
92
+ onSelect={(value) => {
93
+ console.log(value);
94
+ console.log(value);
95
+ }}
96
+ >
97
+ <Calendar className="mr-2 h-4 w-4" />
98
+ <span>Calendar</span>
99
+ </CommandItem>
100
+ <CommandItem>
101
+ <Smile className="mr-2 h-4 w-4" />
102
+ <span>Search Emoji</span>
103
+ </CommandItem>
104
+ <CommandItem>
105
+ <Calculator className="mr-2 h-4 w-4" />
106
+ <span>Calculator</span>
107
+ </CommandItem>
108
+ </CommandGroup>
109
+ <CommandSeparator />
110
+ </CommandList>
111
+ </Command>
112
+ );
113
+ }
114
+
115
+ export function Logo({
116
+ children,
117
+ size = "20px",
118
+ }: {
119
+ children: React.ReactNode;
120
+ size?: string;
121
+ }) {
122
+ return (
123
+ <div
124
+ className={""}
125
+ style={{
126
+ width: size,
127
+ height: size,
128
+ }}
129
+ >
130
+ <div className={""}>{children}</div>
131
+ </div>
132
+ );
133
+ }
@@ -0,0 +1,56 @@
1
+ import * as React from "react";
2
+ import { Slot } from "@radix-ui/react-slot";
3
+ import { cva, type VariantProps } from "class-variance-authority";
4
+
5
+ import { cn } from "../../lib/utils";
6
+
7
+ const buttonVariants = cva(
8
+ "inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
9
+ {
10
+ variants: {
11
+ variant: {
12
+ default: "bg-primary text-primary-foreground hover:bg-primary/90",
13
+ destructive:
14
+ "bg-destructive text-destructive-foreground hover:bg-destructive/90",
15
+ outline:
16
+ "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
17
+ secondary:
18
+ "bg-secondary text-secondary-foreground hover:bg-secondary/80",
19
+ ghost: "hover:bg-accent hover:text-accent-foreground",
20
+ link: "text-primary underline-offset-4 hover:underline",
21
+ },
22
+ size: {
23
+ default: "h-10 px-4 py-2",
24
+ sm: "h-9 rounded-md px-3",
25
+ lg: "h-11 rounded-md px-8",
26
+ icon: "h-10 w-10",
27
+ },
28
+ },
29
+ defaultVariants: {
30
+ variant: "default",
31
+ size: "default",
32
+ },
33
+ }
34
+ );
35
+
36
+ export interface ButtonProps
37
+ extends React.ButtonHTMLAttributes<HTMLButtonElement>,
38
+ VariantProps<typeof buttonVariants> {
39
+ asChild?: boolean;
40
+ }
41
+
42
+ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
43
+ ({ className, variant, size, asChild = false, ...props }, ref) => {
44
+ const Comp = asChild ? Slot : "button";
45
+ return (
46
+ <Comp
47
+ className={cn(buttonVariants({ variant, size, className }))}
48
+ ref={ref}
49
+ {...props}
50
+ />
51
+ );
52
+ }
53
+ );
54
+ Button.displayName = "Button";
55
+
56
+ export { Button, buttonVariants };