Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Cleanup; Improve autocomplete styling

Tomas Valenta3120b6dc1817
diff --git a/components/Editor/RouteEditor/PromptEditor/Autocomplete/Item.tsx b/components/Editor/RouteEditor/PromptEditor/Autocomplete/Item.tsx
index 385c5dca6..fdb7f3636 100644
--- a/components/Editor/RouteEditor/PromptEditor/Autocomplete/Item.tsx
+++ b/components/Editor/RouteEditor/PromptEditor/Autocomplete/Item.tsx
@@ -1,19 +1,32 @@
import { useLayoutEffect } from 'react'
import cn from 'clsx'
+import { Package, Server } from 'lucide-react'
import useElement from 'hooks/useElement'
import Text from 'components/Text'
+import { Reference, ReferenceType } from 'editor/referenceType'
export interface Props {
selectItem: () => void
isSelected: boolean
- title: string
+ item: Reference,
+}
+
+function getReferenceIcon(reference: Reference) {
+ switch (reference.type) {
+ case ReferenceType.DEPLOYMENT:
+ return <Server size="16px" />
+ case ReferenceType.NPMPackage:
+ return <Package size="16px" />
+ default:
+ return null
+ }
}
function Item({
selectItem,
isSelected,
- title,
+ item,
}: Props) {
const [scrollEl, setScrollRef] = useElement<HTMLDivElement>()
@@ -29,27 +42,29 @@ function Item({
<div
ref={setScrollRef}
className={cn(
- 'px-6',
'py-0.5',
+ 'px-2',
+ 'py-1',
+ 'space-x-2',
'shrink-0',
'flex',
'font-mono',
'items-center',
- 'text-sm',
'group',
-
+ 'hover:text-slate-800',
'overflow-ellipsis',
'overflow-hidden',
'cursor-pointer',
{
- 'text-slate-600': !isSelected,
- 'bg-indigo-100 text-indigo-400': isSelected,
+ 'text-slate-500': !isSelected,
+ 'bg-indigo-100 text-slate-800': isSelected,
},
)}
onMouseDown={selectItem}
>
+ {getReferenceIcon(item)}
<Text
- text={title}
+ text={item.value}
/>
</div >
)
diff --git a/components/Editor/RouteEditor/PromptEditor/Autocomplete/index.tsx b/components/Editor/RouteEditor/PromptEditor/Autocomplete/index.tsx
index 4ef30b446..a2d453e36 100644
--- a/components/Editor/RouteEditor/PromptEditor/Autocomplete/index.tsx
+++ b/components/Editor/RouteEditor/PromptEditor/Autocomplete/index.tsx
@@ -8,29 +8,13 @@ import Item from './Item'
import { AutocompleteList } from './ListWrapper'
const Autocomplete: AutocompleteList = forwardRef(({
- editor,
- range,
items,
command,
}, ref) => {
const [selectedIndex, setSelectedIndex] = useState(0)
- const selectItem = useCallback((index: number) => {
- const cmd = editor
- .chain()
- .deleteRange(range)
-
- command(items[index])
-
- // items[index]
- // .extendCommand(cmd)
- // .setTextSelection(0)
- // .run()
-
- }, [
- range,
+ const selectItem = useCallback((index: number) => command(items[index]), [
command,
- editor,
items,
])
@@ -56,6 +40,10 @@ const Autocomplete: AutocompleteList = forwardRef(({
items.length,
])
+ if (items.length === 0) {
+ return null
+ }
+
return (
<div
className="
@@ -78,7 +66,7 @@ const Autocomplete: AutocompleteList = forwardRef(({
{items.map((item, index) => (
<Item
key={item.value}
- title={item.value}
+ item={item}
isSelected={index === selectedIndex}
selectItem={() => selectItem(index)}
/>
diff --git a/editor/schema.ts b/editor/schema.ts
index 5956d556d..c866447a6 100644
--- a/editor/schema.ts
+++ b/editor/schema.ts
@@ -61,9 +61,7 @@ export const extensions = [
BulletList,
AutocompleteExtension.configure({
suggestion: {
- items: (query) => {
- return searchEngine.search(query).map(q => q.item)
- },
+ items: (query) => searchEngine.search(query).map(q => q.item),
},
}),
ReferenceExtension,
diff --git a/styles/prosemirror.css b/styles/prosemirror.css
index 8ec3201e1..d3458ecfd 100644
--- a/styles/prosemirror.css
+++ b/styles/prosemirror.css
@@ -39,6 +39,6 @@
}
.reference {
- @apply text-slate-600 font-semibold font-mono;
+ @apply text-slate-600 font-mono font-semibold;
box-decoration-break: clone;
}