Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set of GUI2 widgets fixes #8749

Merged
merged 2 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions app/gui2/mock/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ export const graphSelection: GraphSelection = {
events: {} as any,
anchor: undefined,
deselectAll: () => {},
addHoveredPort: () => new Set(),
removeHoveredPort: () => false,
handleSelectionOf: () => {},
hoveredNode: undefined,
hoveredPort: undefined,
Expand Down
2 changes: 1 addition & 1 deletion app/gui2/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default defineConfig({
env: {
E2E: 'true',
},
command: 'vite build && vite preview',
command: 'npx vite build && npx vite preview',
port: 4173,
// We use our special, mocked version of server, thus do not want to re-use user's one.
reuseExistingServer: false,
Expand Down
1 change: 1 addition & 0 deletions app/gui2/src/components/GraphEditor/NodeWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const spanStart = computed(() => {
:input="props.input"
:nesting="nesting"
:data-span-start="spanStart"
:data-port="props.input.portId"
@update="updateHandler"
/>
<span
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,15 @@ const visualizationData = project.useVisualizationData(visualizationConfig)
const widgetConfiguration = computed(() => {
if (props.input.dynamicConfig?.kind === 'FunctionCall') return props.input.dynamicConfig
const data = visualizationData.value
if (data != null && data.ok) {
if (data?.ok) {
const parseResult = argsWidgetConfigurationSchema.safeParse(data.value)
if (parseResult.success) {
return functionCallConfiguration(parseResult.data)
} else {
console.error('Unable to parse widget configuration.', data, parseResult.error)
}
} else if (data != null && !data.ok) {
data.error.log('Cannot load dynamic configuration')
}
return undefined
})
Expand Down
13 changes: 1 addition & 12 deletions app/gui2/src/components/GraphEditor/widgets/WidgetPort.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
nextTick,
onUpdated,
proxyRefs,
ref,
shallowRef,
toRef,
watch,
Expand All @@ -35,7 +34,7 @@ const navigator = injectGraphNavigator()
const tree = injectWidgetTree()
const selection = injectGraphSelection(true)

const isHovered = ref(false)
const isHovered = computed(() => selection?.hoveredPort === props.input.portId)

const hasConnection = computed(
() => graph.db.connections.reverseLookup(portId.value as ExprId).size > 0,
Expand All @@ -48,14 +47,6 @@ const connected = computed(() => hasConnection.value || isCurrentEdgeHoverTarget
const rootNode = shallowRef<HTMLElement>()
const nodeSize = useResizeObserver(rootNode, false)

watchEffect((onCleanup) => {
if (selection != null && isHovered.value === true) {
const id = portId.value
selection.addHoveredPort(id)
onCleanup(() => selection.removeHoveredPort(id))
}
})

// Compute the scene-space bounding rectangle of the expression's widget. Those bounds are later
// used for edge positioning. Querying and updating those bounds is relatively expensive, so we only
// do it when the node has any potential for being used as an edge source or target. This is true
Expand Down Expand Up @@ -155,8 +146,6 @@ export const widgetDefinition = defineWidget(WidgetInput.isAstOrPlaceholder, {
}"
:data-id="portId"
:data-h="randSlice"
@pointerenter="isHovered = true"
@pointerleave="isHovered = false"
>
<NodeWidget :input="innerWidget" />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const widgetDefinition = defineWidget(WidgetInput.isAstOrPlaceholder, {
</script>

<template>
<div class="WidgetSelection" @pointerdown="toggleDropdownWidget">
<div class="WidgetSelection" @pointerdown.stop="toggleDropdownWidget">
<NodeWidget :input="innerWidgetInput" />
<DropdownWidget
v-if="showDropdownWidget"
Expand Down
19 changes: 14 additions & 5 deletions app/gui2/src/composables/selection.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @file A Vue composable for keeping track of selected DOM elements. */

import { selectionMouseBindings } from '@/bindings'
import { usePointer } from '@/composables/events'
import { useEvent, usePointer } from '@/composables/events'
import type { NavigatorComposable } from '@/composables/navigator'
import type { PortId } from '@/providers/portInfo.ts'
import type { Rect } from '@/util/data/rect'
Expand All @@ -23,8 +23,19 @@ export function useSelection<T>(
const initiallySelected = new Set<T>()
const selected = reactive(new Set<T>())
const hoveredNode = ref<ExprId>()
const hoveredPorts = reactive(new Set<PortId>())
const hoveredPort = computed(() => [...hoveredPorts].pop())
const hoveredPort = ref<PortId>()

useEvent(document, 'pointerover', (event) => {
if (event.target instanceof Element) {
const widgetPort = event.target.closest('.WidgetPort')
hoveredPort.value =
widgetPort instanceof HTMLElement &&
'port' in widgetPort.dataset &&
typeof widgetPort.dataset.port === 'string'
? (widgetPort.dataset.port as PortId)
: undefined
}
})

function readInitiallySelected() {
initiallySelected.clear()
Expand Down Expand Up @@ -137,8 +148,6 @@ export function useSelection<T>(
hoveredPort,
mouseHandler: selectionEventHandler,
events: pointer.events,
addHoveredPort: (port: PortId) => hoveredPorts.add(port),
removeHoveredPort: (port: PortId) => hoveredPorts.delete(port),
})
}

Expand Down
1 change: 0 additions & 1 deletion app/gui2/src/stores/suggestionDatabase/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useProjectStore } from '@/stores/project'
import { entryQn, type SuggestionEntry, type SuggestionId } from '@/stores/suggestionDatabase/entry'
import { applyUpdates, entryFromLs } from '@/stores/suggestionDatabase/lsUpdate'
import { type Opt } from '@/util/data/opt'
import { ReactiveDb, ReactiveIndex } from '@/util/database/reactiveDb'
import { AsyncQueue, rpcWithRetries } from '@/util/net'
import { qnJoin, qnParent, tryQualifiedName, type QualifiedName } from '@/util/qualifiedName'
Expand Down
2 changes: 1 addition & 1 deletion app/gui2/ydoc-server/edits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import diff from 'fast-diff'
import * as json from 'lib0/json'
import * as Y from 'yjs'
import { TextEdit } from '../shared/languageServerTypes'
import { IdMap, ModuleDoc, type NodeMetadata, type VisualizationMetadata } from '../shared/yjsModel'
import { ModuleDoc, type NodeMetadata, type VisualizationMetadata } from '../shared/yjsModel'
import * as fileFormat from './fileFormat'
import { serializeIdMap } from './serialization'

Expand Down
Loading