-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Closes #8261 - Add vector editor widget - Adding element to end - Dragging elements - Removing elements by dragging away # Important Notes - Both <kbd>Left Click</kbd> and <kbd>Ctrl</kbd> + <kbd>Left Click</kbd> are supported to begin a drag. - Just <kbd>Left Click</kbd> alone is not sufficient as some widgets interact via left click
- Loading branch information
1 parent
2d35be9
commit 2707262
Showing
15 changed files
with
810 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
app/gui2/src/components/GraphEditor/widgets/WidgetVector.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<script setup lang="ts"> | ||
import NodeWidget from '@/components/GraphEditor/NodeWidget.vue' | ||
import ListWidget from '@/components/widgets/ListWidget.vue' | ||
import { Tree, type Token } from '@/generated/ast' | ||
import { injectGraphNavigator } from '@/providers/graphNavigator' | ||
import { Score, defineWidget, widgetProps } from '@/providers/widgetRegistry' | ||
import { useGraphStore } from '@/stores/graph' | ||
import { AstExtended } from '@/util/ast' | ||
import { computed } from 'vue' | ||
type Item = AstExtended<Tree.Tree | Token.Token, boolean> | ||
const props = defineProps(widgetProps(widgetDefinition)) | ||
const graph = useGraphStore() | ||
const value = computed({ | ||
get() { | ||
return props.input.children().filter((child) => child.isTree()) | ||
}, | ||
set(value) { | ||
const id = props.input.astId | ||
if (!id) return | ||
graph.replaceNodeSubexpression( | ||
id, | ||
undefined!, | ||
`[${value.map((item) => item.repr()).join(', ')}]`, | ||
) | ||
}, | ||
}) | ||
function encodeAstPayload(ast: Item): string { | ||
return ast.repr() | ||
} | ||
function decodeAstPayload(id: string): Item { | ||
return AstExtended.parse(id) | ||
} | ||
const navigator = injectGraphNavigator(true) | ||
</script> | ||
|
||
<script lang="ts"> | ||
export const widgetDefinition = defineWidget(AstExtended.isTree([Tree.Type.Array]), { | ||
priority: 1000, | ||
score: () => Score.Perfect, | ||
}) | ||
</script> | ||
|
||
<template> | ||
<ListWidget | ||
v-model="value" | ||
:default="() => AstExtended.parse('_')" | ||
:getKey="(item: Item) => item.astId" | ||
dragMimeType="application/x-enso-ast-node" | ||
:toPlainText="(item: Item) => item.repr()" | ||
:toDragPayload="encodeAstPayload" | ||
:fromDragPayload="decodeAstPayload" | ||
:toDragPosition="(p) => navigator?.clientToScenePos(p) ?? p" | ||
class="WidgetVector" | ||
contenteditable="false" | ||
> | ||
<template #default="{ item }"> | ||
<NodeWidget :input="item" /> | ||
</template> | ||
</ListWidget> | ||
</template> | ||
|
||
<style scoped> | ||
.drag-preview { | ||
position: fixed; | ||
background-color: var(--node-color-primary); | ||
border-radius: var(--node-border-radius); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.