@copilotkit/react-textarea 0.18.0 → 0.19.0-alpha.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 (236) hide show
  1. package/.turbo/turbo-build.log +304 -190
  2. package/CHANGELOG.md +11 -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-4T72ROFJ.mjs +469 -0
  10. package/dist/chunk-4T72ROFJ.mjs.map +1 -0
  11. package/dist/chunk-55EGOC5T.mjs +87 -0
  12. package/dist/chunk-55EGOC5T.mjs.map +1 -0
  13. package/dist/{chunk-3A2CNIG5.mjs → chunk-5ARCOTW3.mjs} +8 -5
  14. package/dist/chunk-5ARCOTW3.mjs.map +1 -0
  15. package/dist/chunk-5EJ5XOGP.mjs +22 -0
  16. package/dist/chunk-5EJ5XOGP.mjs.map +1 -0
  17. package/dist/chunk-5FO6ISW4.mjs +3 -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-ASPOPGV7.mjs +47 -0
  21. package/dist/chunk-ASPOPGV7.mjs.map +1 -0
  22. package/dist/chunk-CDB7HFCY.mjs +65 -0
  23. package/dist/chunk-CDB7HFCY.mjs.map +1 -0
  24. package/dist/chunk-CIFH63LP.mjs +107 -0
  25. package/dist/chunk-CIFH63LP.mjs.map +1 -0
  26. package/dist/{chunk-MFJNLKRC.mjs → chunk-D7SEV5PR.mjs} +4 -3
  27. package/dist/chunk-D7SEV5PR.mjs.map +1 -0
  28. package/dist/chunk-HAFHLU4N.mjs +55 -0
  29. package/dist/chunk-HAFHLU4N.mjs.map +1 -0
  30. package/dist/{chunk-3UQM3NLM.mjs → chunk-IXJ2HCOA.mjs} +42 -7
  31. package/dist/chunk-IXJ2HCOA.mjs.map +1 -0
  32. package/dist/{chunk-UW3ITU2Y.mjs → chunk-JAFCXEPU.mjs} +1 -1
  33. package/dist/chunk-JAFCXEPU.mjs.map +1 -0
  34. package/dist/chunk-L7VVZH4Q.mjs +3 -0
  35. package/dist/{chunk-5GGCWNTT.mjs → chunk-MA4NHL3H.mjs} +68 -30
  36. package/dist/chunk-MA4NHL3H.mjs.map +1 -0
  37. package/dist/chunk-ND5PXTAW.mjs +17 -0
  38. package/dist/chunk-ND5PXTAW.mjs.map +1 -0
  39. package/dist/chunk-O5OWT5GE.mjs +114 -0
  40. package/dist/chunk-O5OWT5GE.mjs.map +1 -0
  41. package/dist/chunk-OD7ZMOVE.mjs +45 -0
  42. package/dist/chunk-OD7ZMOVE.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-HZGSG7ST.mjs → chunk-UHD44NC5.mjs} +10 -5
  46. package/dist/chunk-UHD44NC5.mjs.map +1 -0
  47. package/dist/chunk-VBIJPE3H.mjs +108 -0
  48. package/dist/chunk-VBIJPE3H.mjs.map +1 -0
  49. package/dist/chunk-VHIS7RTM.mjs +44 -0
  50. package/dist/chunk-VHIS7RTM.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 +22 -8
  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 +32 -13
  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 +32 -13
  87. package/dist/components/manual-ui/chip-with-icon.d.ts +10 -0
  88. package/dist/components/manual-ui/chip-with-icon.mjs +25 -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 +33 -14
  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 +70 -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 +399 -0
  180. package/src/components/manual-ui/chip-with-icon.tsx +29 -0
  181. package/src/components/source-search-box/source-search-box.tsx +127 -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,399 @@
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
+
20
+ export type State_SuggestionAppearing = {
21
+ type: "suggestion-appearing";
22
+ initialSuggestion: SuggestionSnapshot;
23
+ };
24
+
25
+ type SuggestionSnapshot = {
26
+ adjustmentPrompt: string;
27
+ generatingSuggestion: ReadableStream<string>;
28
+ editorState: EditingEditorState;
29
+ };
30
+
31
+ export interface SuggestionAppearingProps {
32
+ state: State_SuggestionAppearing;
33
+ performInsertion: (insertedText: string) => void;
34
+ goBack: () => void;
35
+ insertionOrEditingFunction: Generator_InsertionOrEditingSuggestion;
36
+ onGeneratedText: (generatedText: ReadableStream<string>) => void;
37
+ }
38
+
39
+ export const SuggestionAppearing: React.FC<SuggestionAppearingProps> = ({
40
+ performInsertion,
41
+ state,
42
+ goBack,
43
+ insertionOrEditingFunction,
44
+ onGeneratedText,
45
+ }) => {
46
+ const [adjustmentHistory, setAdjustmentHistory] = useState<
47
+ SuggestionSnapshot[]
48
+ >([state.initialSuggestion]);
49
+
50
+ const [editSuggestion, setEditSuggestion] = useState<string>("");
51
+ const [suggestionIsLoading, setSuggestionIsLoading] =
52
+ useState<boolean>(false);
53
+
54
+ const [adjustmentPrompt, setAdjustmentPrompt] = useState<string>("");
55
+ const [adjustmentLoading, setAdjustmentLoading] = useState<boolean>(false);
56
+
57
+ const suggestionTextAreaRef = useRef<HTMLTextAreaElement>(null);
58
+ const adjustmentTextAreaRef = useRef<HTMLTextAreaElement>(null);
59
+
60
+ const [filePointers, setFilePointers] = useState<FilePointer[]>([]);
61
+
62
+ useAutosizeTextArea(suggestionTextAreaRef, editSuggestion || "");
63
+ useAutosizeTextArea(adjustmentTextAreaRef, adjustmentPrompt || "");
64
+
65
+ // initially focus on the end of the suggestion text area
66
+ useEffect(() => {
67
+ suggestionTextAreaRef.current?.focus();
68
+ suggestionTextAreaRef.current?.setSelectionRange(
69
+ editSuggestion.length,
70
+ editSuggestion.length
71
+ );
72
+ }, []);
73
+
74
+ useEffect(() => {
75
+ // Check if the stream is already locked
76
+ if (state.initialSuggestion.generatingSuggestion.locked) {
77
+ return;
78
+ }
79
+ // reset the edit suggestion
80
+ setEditSuggestion("");
81
+
82
+ // read the generating suggestion stream and continuously update the edit suggestion
83
+ const reader = state.initialSuggestion.generatingSuggestion.getReader();
84
+
85
+ const read = async () => {
86
+ setSuggestionIsLoading(true);
87
+ while (true) {
88
+ const { done, value } = await reader.read();
89
+ if (done) {
90
+ break;
91
+ }
92
+ setEditSuggestion((prev) => {
93
+ const newSuggestion = prev + value;
94
+ // Scroll to the bottom of the textarea. We call this here to make sure scroll-to-bottom is synchronous with the state update.
95
+ if (suggestionTextAreaRef.current) {
96
+ suggestionTextAreaRef.current.scrollTop =
97
+ suggestionTextAreaRef.current.scrollHeight;
98
+ }
99
+ return newSuggestion;
100
+ });
101
+ }
102
+
103
+ setSuggestionIsLoading(false);
104
+ };
105
+ read();
106
+
107
+ return () => {
108
+ const releaseLockIfNotClosed = async () => {
109
+ try {
110
+ await reader.closed;
111
+ } catch {
112
+ reader.releaseLock();
113
+ }
114
+ };
115
+
116
+ releaseLockIfNotClosed();
117
+ };
118
+ }, [state]);
119
+
120
+ const generateAdjustment = async () => {
121
+ // don't generate text if the prompt is empty
122
+ if (!adjustmentPrompt.trim()) {
123
+ return;
124
+ }
125
+
126
+ setAdjustmentLoading(true);
127
+ // use insertionOrEditingFunction
128
+ const adjustmentSuggestionTextStream = await insertionOrEditingFunction(
129
+ {
130
+ ...state.initialSuggestion.editorState,
131
+ selectedText: editSuggestion,
132
+ },
133
+ adjustmentPrompt,
134
+ new AbortController().signal
135
+ );
136
+ setAdjustmentLoading(false);
137
+ onGeneratedText(adjustmentSuggestionTextStream);
138
+ };
139
+
140
+ const showLoading = suggestionIsLoading || adjustmentLoading;
141
+
142
+ const AdjustmentPromptComponent = (
143
+ <>
144
+ <Label className="">Describe adjustments to the suggested text:</Label>
145
+ <div className="relative w-full flex items-center">
146
+ <textarea
147
+ disabled={suggestionIsLoading}
148
+ ref={adjustmentTextAreaRef}
149
+ value={adjustmentPrompt}
150
+ onChange={(e) => setAdjustmentPrompt(e.target.value)}
151
+ onKeyDown={(e) => {
152
+ if (e.key === "Enter" && e.shiftKey) {
153
+ e.preventDefault();
154
+ setAdjustmentPrompt(adjustmentPrompt + "\n");
155
+ } else if (e.key === "Enter") {
156
+ e.preventDefault();
157
+ generateAdjustment();
158
+ }
159
+ }}
160
+ placeholder={'"make it more formal", "be more specific", ...'}
161
+ style={{ minHeight: "3rem" }}
162
+ 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]"
163
+ rows={1}
164
+ />
165
+ <button
166
+ onClick={generateAdjustment}
167
+ className="absolute right-2 bg-blue-500 text-white w-8 h-8 rounded-full flex items-center justify-center"
168
+ >
169
+ <i className="material-icons">arrow_forward</i>
170
+ </button>
171
+ </div>
172
+ </>
173
+ );
174
+
175
+ const SuggestionComponent = (
176
+ <>
177
+ <div className="flex justify-between items-end w-full">
178
+ <Label className="mt-4">Suggested:</Label>
179
+ <div className="ml-auto">
180
+ {showLoading && (
181
+ <div className="flex justify-center items-center">
182
+ <div
183
+ 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]"
184
+ role="status"
185
+ >
186
+ <span className="!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]">
187
+ Loading...
188
+ </span>
189
+ </div>
190
+ </div>
191
+ )}
192
+ </div>
193
+ </div>
194
+ <textarea
195
+ ref={suggestionTextAreaRef}
196
+ value={editSuggestion}
197
+ disabled={adjustmentLoading}
198
+ onChange={(e) => setEditSuggestion(e.target.value)}
199
+ className="w-full text-base p-2 border border-gray-300 rounded-md resize-none bg-green-50"
200
+ style={{ overflow: "auto", maxHeight: "10em" }}
201
+ />
202
+ </>
203
+ );
204
+
205
+ const SubmitComponent = (
206
+ <div className="flex w-full gap-4 justify-start">
207
+ <Button
208
+ className=" bg-gray-300"
209
+ onClick={() => {
210
+ goBack();
211
+ }}
212
+ >
213
+ <i className="material-icons">arrow_back</i> Back
214
+ </Button>
215
+
216
+ <Button
217
+ className=" bg-green-700 text-white"
218
+ onClick={() => {
219
+ performInsertion(editSuggestion);
220
+ }}
221
+ >
222
+ Insert <i className="material-icons">check</i>
223
+ </Button>
224
+ </div>
225
+ );
226
+
227
+ // show source search if the last word in the adjustment prompt BEGINS with an @
228
+ const sourceSearchCandidate = adjustmentPrompt.split(" ").pop();
229
+ // if the candidate is @someCandidate, then 'someCandidate', otherwise undefined
230
+ const sourceSearchWord = sourceSearchCandidate?.startsWith("@")
231
+ ? sourceSearchCandidate.slice(1)
232
+ : undefined;
233
+
234
+ return (
235
+ <div className="w-full flex flex-col items-start relative gap-2">
236
+ {AdjustmentPromptComponent}
237
+ { filePointers.length > 0 && (
238
+ <IncludedFilesPreview includedFiles={filePointers} setIncludedFiles={setFilePointers} />
239
+ )}
240
+ {sourceSearchWord !== undefined && (
241
+ <SourceSearchBox
242
+ searchTerm={sourceSearchWord}
243
+ recentFiles={mockFiles}
244
+ onSelectedFile={(filePointer) => {
245
+ setAdjustmentPrompt(
246
+ adjustmentPrompt.replace(
247
+ new RegExp(`@${sourceSearchWord}$`),
248
+ ""
249
+ )
250
+ );
251
+ setFilePointers((prev) => [...prev, filePointer]);
252
+
253
+ // focus back on the adjustment prompt, and move the cursor to the end
254
+ adjustmentTextAreaRef.current?.focus();
255
+ }}
256
+ />
257
+ )}
258
+ {SuggestionComponent}
259
+ {SubmitComponent}
260
+ </div>
261
+ );
262
+ };
263
+
264
+
265
+ interface IncludedFilesPreviewProps {
266
+ includedFiles: FilePointer[];
267
+ setIncludedFiles: React.Dispatch<React.SetStateAction<FilePointer[]>>;
268
+ }
269
+
270
+ export const IncludedFilesPreview: React.FC<IncludedFilesPreviewProps> = ({ includedFiles, setIncludedFiles }) => {
271
+ return (
272
+ <div className="flex flex-col gap-2">
273
+ <div className="flex flex-wrap gap-2">
274
+ {includedFiles.map((filePointer, index) => {
275
+ return (
276
+ <FileChipPreview
277
+ key={`file-${filePointer.sourceApplication}.${filePointer.name}`}
278
+ filePointer={filePointer}
279
+ onDelete={() => {
280
+ setIncludedFiles((prev) => prev.filter((fp) => fp !== filePointer));
281
+ }}
282
+ />
283
+ );
284
+ })}
285
+ </div>
286
+ </div>
287
+ );
288
+ };
289
+
290
+ export interface FileChipPreviewProp {
291
+ filePointer: FilePointer;
292
+ onDelete: () => void;
293
+ }
294
+
295
+ export const FileChipPreview: React.FC<FileChipPreviewProp> = ({
296
+ filePointer,
297
+ onDelete,
298
+ }) => {
299
+ return (
300
+ <Chip
301
+ label={filePointer.name}
302
+ onDelete={onDelete}
303
+ avatar={
304
+ <Avatar sx={{ backgroundColor: 'transparent' }}>
305
+ <IconForFilePointer filePointer={filePointer} className="w-4 h-4 object-contain" />
306
+ </Avatar>
307
+ }
308
+ />
309
+ );
310
+ }
311
+
312
+ export function IconForFilePointer({filePointer, className}: {filePointer: FilePointer, className: string}): JSX.Element {
313
+ if(filePointer.sourceApplication === "Salesforce") {
314
+ return <IconSalesforce className={className} />
315
+ } else {
316
+ return <IconSalesforce className={className} />
317
+ }
318
+ }
319
+
320
+ function IconSalesforce({ className, ...props }: React.ComponentProps<"svg">) {
321
+ return (
322
+ <svg
323
+ xmlns="http://www.w3.org/2000/svg"
324
+ xmlnsXlink="http://www.w3.org/1999/xlink"
325
+ preserveAspectRatio="xMidYMid meet"
326
+ viewBox="0 0 273 191"
327
+ {...props}
328
+ >
329
+ <title>{"Salesforce.com logo"}</title>
330
+ <defs>
331
+ <path id="a" d="M.06.5h272v190H.06z" />
332
+ </defs>
333
+ <g fillRule="evenodd">
334
+ <mask id="b" fill="#fff">
335
+ <use xlinkHref="#a" />
336
+ </mask>
337
+ <path
338
+ fill="#00A1E0"
339
+ 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"
340
+ mask="url(#b)"
341
+ />
342
+ <path
343
+ fill="#FFFFFE"
344
+ 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"
345
+ />
346
+ <path
347
+ fill="#FFFFFE"
348
+ 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"
349
+ />
350
+ </g>
351
+ </svg>
352
+ );
353
+ }
354
+
355
+
356
+ const mockFiles: FilePointer[] = [
357
+ {
358
+ name: "prospecting call transcript",
359
+ sourceApplication: "Salesforce",
360
+ getContents: async () => {
361
+ return "some contents";
362
+ },
363
+ },
364
+ {
365
+ name: "customer feedback",
366
+ sourceApplication: "Zendesk",
367
+ getContents: async () => {
368
+ return "some contents";
369
+ },
370
+ },
371
+ {
372
+ name: "product specifications",
373
+ sourceApplication: "Google Docs",
374
+ getContents: async () => {
375
+ return "some contents";
376
+ },
377
+ },
378
+ {
379
+ name: "meeting minutes",
380
+ sourceApplication: "Microsoft Teams",
381
+ getContents: async () => {
382
+ return "some contents";
383
+ },
384
+ },
385
+ {
386
+ name: "project plan",
387
+ sourceApplication: "Trello",
388
+ getContents: async () => {
389
+ return "some contents";
390
+ },
391
+ },
392
+ {
393
+ name: "code review comments",
394
+ sourceApplication: "Github",
395
+ getContents: async () => {
396
+ return "some contents";
397
+ },
398
+ },
399
+ ];
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+
3
+
4
+ export interface ChipWithIconProps {
5
+ label: string;
6
+ onDelete: () => void;
7
+ iconUrl: string;
8
+ }
9
+
10
+ export const ChipWithIcon: React.FC<ChipWithIconProps> = ({ label, onDelete, iconUrl }) => {
11
+ return (
12
+ <span className="inline-flex items-center px-3 py-1 rounded-full bg-slate-200 text-sm font-medium text-white">
13
+ {iconUrl && (
14
+ <img
15
+ src={iconUrl}
16
+ alt="icon"
17
+ className="w-4 h-4 rounded-full mr-2"
18
+ />
19
+ )}
20
+ {label}
21
+ <button
22
+ className="ml-2 text-white hover:text-gray-200 focus:outline-none"
23
+ onClick={onDelete}
24
+ >
25
+ x
26
+ </button>
27
+ </span>
28
+ );
29
+ };
@@ -0,0 +1,127 @@
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
+
38
+ const [selectedValue, setSelectedValue] = useState<string>("");
39
+
40
+ return (
41
+ <Command
42
+ className="rounded-lg border shadow-md"
43
+ value={selectedValue}
44
+ onValueChange={(value) => {
45
+ setSelectedValue(value);
46
+ }}
47
+ filter={(value, search) => {
48
+ // if the search term is empty, show all commands
49
+ if (props.searchTerm === "") return 1;
50
+
51
+ // if the search term is a prefix of the command, show it
52
+ if (value.startsWith(props.searchTerm)) return 1;
53
+
54
+ // otherwise, don't show it
55
+ return 0;
56
+ }}
57
+ >
58
+ <CommandInput
59
+ value={props.searchTerm}
60
+ className="rounded-t-lg hidden"
61
+ placeholder="Search for a command..."
62
+ />
63
+ <CommandList>
64
+ <CommandEmpty>No results found.</CommandEmpty>
65
+
66
+ <CommandGroup heading="Recents">
67
+ {props.recentFiles.map((filePointer) => {
68
+ return (
69
+ <CommandItem
70
+ key={`word-${filePointer.sourceApplication}.${filePointer.name}`}
71
+ value={filePointer.name}
72
+ onSelect={(value) => {
73
+ console.log(filePointer.name)
74
+ props.onSelectedFile(filePointer);
75
+ }}
76
+ >
77
+ <div className="flex flex-row gap-3 items-center bg-slate-400 ">
78
+ <Logo size="40px">
79
+ <IconForFilePointer filePointer={filePointer} className="mx-auto my-auto" />
80
+ </Logo>
81
+ {filePointer.name}
82
+ </div>
83
+ </CommandItem>
84
+ );
85
+ })}
86
+ </CommandGroup>
87
+
88
+ <CommandGroup heading="Suggestions">
89
+ <CommandItem
90
+ onSelect={(value) => {
91
+ console.log(value);
92
+ console.log(value);
93
+ }}
94
+ >
95
+ <Calendar className="mr-2 h-4 w-4" />
96
+ <span>Calendar</span>
97
+ </CommandItem>
98
+ <CommandItem>
99
+ <Smile className="mr-2 h-4 w-4" />
100
+ <span>Search Emoji</span>
101
+ </CommandItem>
102
+ <CommandItem>
103
+ <Calculator className="mr-2 h-4 w-4" />
104
+ <span>Calculator</span>
105
+ </CommandItem>
106
+ </CommandGroup>
107
+ <CommandSeparator />
108
+ </CommandList>
109
+ </Command>
110
+ );
111
+ }
112
+
113
+ export function Logo({ children, size = '20px' }: { children: React.ReactNode; size?: string }) {
114
+ return (
115
+ <div
116
+ className={""}
117
+ style={{
118
+ width: size,
119
+ height: size,
120
+ }}
121
+ >
122
+ <div className={""}>
123
+ {children}
124
+ </div>
125
+ </div>
126
+ )
127
+ }
@@ -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 };