@@ -3,7 +3,6 @@ import { componentBrowserBindings, listBindings } from '@/bindings'
33import { type Component } from ' @/components/ComponentBrowser/component'
44import ComponentEditor from ' @/components/ComponentBrowser/ComponentEditor.vue'
55import ComponentList from ' @/components/ComponentBrowser/ComponentList.vue'
6- import { Filtering } from ' @/components/ComponentBrowser/filtering'
76import { useComponentBrowserInput , type Usage } from ' @/components/ComponentBrowser/input'
87import GraphVisualization from ' @/components/GraphEditor/GraphVisualization.vue'
98import SvgButton from ' @/components/SvgButton.vue'
@@ -15,7 +14,6 @@ import { injectNodeColors } from '@/providers/graphNodeColors'
1514import { injectInteractionHandler , type Interaction } from ' @/providers/interactionHandler'
1615import { useGraphStore } from ' @/stores/graph'
1716import type { RequiredImport } from ' @/stores/graph/imports'
18- import { useProjectStore } from ' @/stores/project'
1917import { injectProjectNames } from ' @/stores/projectNames'
2018import { useSuggestionDbStore } from ' @/stores/suggestionDatabase'
2119import { type Typename } from ' @/stores/suggestionDatabase/entry'
@@ -29,6 +27,8 @@ import { debouncedGetter } from '@/util/reactivity'
2927import type { ComponentInstance } from ' vue'
3028import { computed , onMounted , onUnmounted , ref , toValue , watch , watchEffect } from ' vue'
3129import type { SuggestionId } from ' ydoc-shared/languageServerTypes/suggestions'
30+ import { Range } from ' ydoc-shared/util/data/range'
31+ import { Ok } from ' ydoc-shared/util/data/result'
3232import type { VisualizationIdentifier } from ' ydoc-shared/yjsModel'
3333
3434// Difference in position between the component browser and a node for the input of the component browser to
@@ -47,7 +47,6 @@ const EDGE_Y_OFFSET = -8
4747
4848const cssComponentEditorPadding = ` ${COMPONENT_EDITOR_PADDING }px `
4949
50- const projectStore = useProjectStore ()
5150const suggestionDbStore = useSuggestionDbStore ()
5251const graphStore = useGraphStore ()
5352const interaction = injectInteractionHandler ()
@@ -177,15 +176,6 @@ const selectedSuggestion = computed(() => {
177176
178177const input = useComponentBrowserInput ()
179178
180- const currentFiltering = computed (() => {
181- if (input .mode .mode === ' componentBrowsing' ) {
182- const currentModule = projectStore .moduleProjectPath
183- return new Filtering (input .mode .filter , currentModule ?.ok ? currentModule .value : undefined )
184- } else {
185- return undefined
186- }
187- })
188-
189179onUnmounted (() => {
190180 graphStore .cbEditedEdge = undefined
191181})
@@ -285,20 +275,37 @@ watch(
285275
286276// === Accepting Entry ===
287277
288- function acceptSuggestion(component : Opt <Component > = null ) {
289- const suggestionId = component ?.suggestionId ?? selectedSuggestionId .value
290- if (suggestionId == null ) return acceptInput ()
291- const result = input .applySuggestion (suggestionId )
278+ function applyComponent(component : Opt <Component > = null ) {
279+ component ?? = selected .value
280+ if (component == null ) {
281+ input .switchToCodeEditMode ()
282+ return Ok ()
283+ }
284+ if (component .suggestionId ) {
285+ return input .applySuggestion (component .suggestionId )
286+ } else {
287+ // Component without suggestion database entry, for example "literal" component.
288+ input .content = { text: component .label , selection: Range .emptyAt (component .label .length ) }
289+ input .switchToCodeEditMode ()
290+ return Ok ()
291+ }
292+ }
293+
294+ function acceptComponent(component : Opt <Component > = null ) {
295+ const result = applyComponent (component )
292296 if (result .ok ) acceptInput ()
293297 else result .error .log (' Cannot apply suggestion' )
294298}
295299
296- function applySuggestion(component : Opt <Component > = null ) {
297- const suggestionId = component ?.suggestionId ?? selectedSuggestionId .value
298- if (suggestionId == null ) return input .switchToCodeEditMode ()
299- const result = input .applySuggestion (suggestionId )
300- if (! result .ok ) result .error .log (' Cannot apply suggestion' )
301- }
300+ // function editComponent(component: Opt<Component> = null) {
301+ // const result = applyComponentToInput(component)
302+ // if (result.ok) acceptInput()
303+ // else result.error.log('Cannot apply suggestion')
304+ // const suggestionId = component?.suggestionId ?? selectedSuggestionId.value
305+ // if (suggestionId == null) return input.switchToCodeEditMode()
306+ // const result = input.applySuggestion(suggestionId)
307+ // if (!result.ok) result.error.log('Cannot apply suggestion')
308+ // }
302309
303310function acceptInput() {
304311 const appliedReturnType =
@@ -314,11 +321,14 @@ function acceptInput() {
314321const outsideComponentBrowsing = computed (() => input .mode .mode != ' componentBrowsing' )
315322const actions = registerHandlers ({
316323 ' componentBrowser.editSuggestion' : {
317- action: applySuggestion ,
324+ action : () => {
325+ const result = applyComponent ()
326+ if (! result .ok ) result .error .log (' Cannot apply component' )
327+ },
318328 disabled: outsideComponentBrowsing ,
319329 },
320330 ' componentBrowser.acceptSuggestion' : {
321- action: acceptSuggestion ,
331+ action: acceptComponent ,
322332 disabled: outsideComponentBrowsing ,
323333 },
324334 ' componentBrowser.acceptInputAsCode' : {
@@ -427,10 +437,11 @@ const listsHandler = listBindings.handler({
427437 />
428438 </div >
429439 <ComponentList
430- v-if =" input.mode.mode === 'componentBrowsing' && currentFiltering "
440+ v-if =" input.mode.mode === 'componentBrowsing'"
431441 ref =" componentList"
432- :filtering =" currentFiltering"
433- @acceptSuggestion =" acceptSuggestion($event)"
442+ :filter =" input.mode.filter"
443+ :literal =" input.mode.literal"
444+ @acceptSuggestion =" acceptComponent($event)"
434445 @update:selectedComponent =" selected = $event"
435446 />
436447 </div >
0 commit comments