1095 lines
28 KiB
Vue
1095 lines
28 KiB
Vue
<script setup lang="ts">
|
||
import {
|
||
ABILITY_PALETTE,
|
||
EFFECT_PALETTE,
|
||
NODE_WIDTH,
|
||
STATIC_EFFECT_PALETTE,
|
||
VALUE_PALETTE,
|
||
abilityRequiresEffects,
|
||
blockOf,
|
||
connectNodes,
|
||
estimateNodeHeight,
|
||
graphFromSource,
|
||
hasBodyPort,
|
||
nextNodeId,
|
||
parseCall,
|
||
shapeFromText,
|
||
sourceFromGraph,
|
||
} from '../utils/cardGraph'
|
||
import type { CanvasNode, GraphEdge, GraphModel, GraphPort, NodeSlot } from '../utils/cardGraph'
|
||
|
||
const props = defineProps<{ modelValue: string }>()
|
||
const emit = defineEmits<{ 'update:modelValue': [value: string] }>()
|
||
|
||
// Keep in sync with .port top offsets in the style block (center = top + 7px).
|
||
const PORT_Y = 28
|
||
const BODY_PORT_Y = 52
|
||
const ARG_START = 52
|
||
const ARG_STEP = 48
|
||
|
||
const model = reactive<GraphModel>(graphFromSource(props.modelValue))
|
||
const canvas = ref<HTMLElement>()
|
||
const pan = reactive({ x: 30, y: 30 })
|
||
const zoom = ref(1)
|
||
const problems = ref<string[]>(sourceFromGraph(model).problems)
|
||
const drag = ref<
|
||
| { kind: 'node'; id: number; startX: number; startY: number; nodeX: number; nodeY: number }
|
||
| { kind: 'pan'; startX: number; startY: number; panX: number; panY: number }
|
||
| { kind: 'link'; from: number; port: GraphPort; x: number; y: number }
|
||
>()
|
||
|
||
let lastEmitted = props.modelValue
|
||
let cascade = 0
|
||
|
||
const isLinking = computed(() => drag.value?.kind === 'link')
|
||
|
||
watch(() => props.modelValue, value => {
|
||
if (value.trimEnd() === lastEmitted.trimEnd()) return
|
||
const graph = graphFromSource(value)
|
||
model.nodes = graph.nodes
|
||
model.edges = graph.edges
|
||
lastEmitted = value
|
||
problems.value = sourceFromGraph(model).problems
|
||
nextTick(fitView)
|
||
})
|
||
|
||
onMounted(() => nextTick(fitView))
|
||
|
||
const layerStyle = computed(() => ({
|
||
transform: `translate(${pan.x}px, ${pan.y}px) scale(${zoom.value})`,
|
||
}))
|
||
|
||
const canvasStyle = computed(() => ({
|
||
backgroundPosition: `${pan.x}px ${pan.y}px`,
|
||
backgroundSize: `${24 * zoom.value}px ${24 * zoom.value}px`,
|
||
}))
|
||
|
||
const PALETTE = [
|
||
...ABILITY_PALETTE.map(group => ({ title: `Ability · ${group.group}`, kind: 'ability' as const, items: group.items })),
|
||
...EFFECT_PALETTE.map(group => ({ title: group.group, kind: 'effect' as const, items: group.items })),
|
||
...STATIC_EFFECT_PALETTE.map(group => ({ title: `Static · ${group.group}`, kind: 'effect' as const, items: group.items })),
|
||
...VALUE_PALETTE.map(group => ({ title: `Value · ${group.group}`, kind: 'value' as const, items: group.items })),
|
||
]
|
||
|
||
const paletteSearch = ref('')
|
||
const filteredPalette = computed(() => {
|
||
const term = paletteSearch.value.trim().toLowerCase()
|
||
if (!term) return PALETTE
|
||
return PALETTE
|
||
.map(group => ({
|
||
...group,
|
||
items: group.items.filter(item =>
|
||
group.title.toLowerCase().includes(term)
|
||
|| item.label.toLowerCase().includes(term)
|
||
|| item.value.toLowerCase().includes(term)
|
||
),
|
||
}))
|
||
.filter(group => group.items.length)
|
||
})
|
||
|
||
function push() {
|
||
const result = sourceFromGraph(model)
|
||
problems.value = result.problems
|
||
lastEmitted = result.source
|
||
emit('update:modelValue', result.source)
|
||
}
|
||
|
||
// --- Pointer interaction ---------------------------------------------------
|
||
|
||
function clientToGraph(clientX: number, clientY: number) {
|
||
const element = canvas.value
|
||
if (!element) return { x: 0, y: 0 }
|
||
const rect = element.getBoundingClientRect()
|
||
return {
|
||
x: (clientX - rect.left - pan.x) / zoom.value,
|
||
y: (clientY - rect.top - pan.y) / zoom.value,
|
||
}
|
||
}
|
||
|
||
function addWindowListeners() {
|
||
window.addEventListener('pointermove', onPointerMove)
|
||
window.addEventListener('pointerup', onPointerUp)
|
||
window.addEventListener('pointercancel', onPointerUp)
|
||
}
|
||
|
||
function removeWindowListeners() {
|
||
window.removeEventListener('pointermove', onPointerMove)
|
||
window.removeEventListener('pointerup', onPointerUp)
|
||
window.removeEventListener('pointercancel', onPointerUp)
|
||
}
|
||
|
||
onBeforeUnmount(() => {
|
||
drag.value = undefined
|
||
removeWindowListeners()
|
||
})
|
||
|
||
function startNodeDrag(event: PointerEvent, node: CanvasNode) {
|
||
if (event.button !== 0) return
|
||
if ((event.target as Element).closest('input, textarea, button, select, [data-port]')) return
|
||
event.preventDefault()
|
||
drag.value = {
|
||
kind: 'node',
|
||
id: node.id,
|
||
startX: event.clientX,
|
||
startY: event.clientY,
|
||
nodeX: node.x,
|
||
nodeY: node.y,
|
||
}
|
||
addWindowListeners()
|
||
}
|
||
|
||
function onCanvasDown(event: PointerEvent) {
|
||
if (event.button !== 0) return
|
||
if ((event.target as Element).closest('.node, .wire-hit')) return
|
||
event.preventDefault()
|
||
drag.value = { kind: 'pan', startX: event.clientX, startY: event.clientY, panX: pan.x, panY: pan.y }
|
||
addWindowListeners()
|
||
}
|
||
|
||
function startLink(event: PointerEvent, node: CanvasNode, port: GraphPort) {
|
||
if (event.button !== 0) return
|
||
const start = outPoint(node, port)
|
||
drag.value = { kind: 'link', from: node.id, port, x: start.x, y: start.y }
|
||
addWindowListeners()
|
||
}
|
||
|
||
function onPointerMove(event: PointerEvent) {
|
||
const state = drag.value
|
||
if (!state) return
|
||
if (state.kind === 'node') {
|
||
const node = model.nodes.find(entry => entry.id === state.id)
|
||
if (!node) return
|
||
node.x = state.nodeX + (event.clientX - state.startX) / zoom.value
|
||
node.y = state.nodeY + (event.clientY - state.startY) / zoom.value
|
||
return
|
||
}
|
||
if (state.kind === 'pan') {
|
||
pan.x = state.panX + event.clientX - state.startX
|
||
pan.y = state.panY + event.clientY - state.startY
|
||
return
|
||
}
|
||
const point = clientToGraph(event.clientX, event.clientY)
|
||
state.x = point.x
|
||
state.y = point.y
|
||
}
|
||
|
||
function onPointerUp(event: PointerEvent) {
|
||
const state = drag.value
|
||
if (state?.kind === 'link' && event.type === 'pointerup') {
|
||
const target = document.elementFromPoint(event.clientX, event.clientY) as Element | null
|
||
if (state.port === 'value') {
|
||
const arg = target?.closest<HTMLElement>('[data-port="arg"]')
|
||
const to = arg ? Number(arg.dataset.nodeId) : NaN
|
||
const slot = arg ? Number(arg.dataset.slot) : NaN
|
||
if (Number.isFinite(to) && Number.isFinite(slot)
|
||
&& connectNodes(model, state.from, 'value', to, slot)) push()
|
||
} else {
|
||
const input = target?.closest<HTMLElement>('[data-port="in"]')
|
||
const to = input ? Number(input.dataset.nodeId) : NaN
|
||
if (Number.isFinite(to) && connectNodes(model, state.from, state.port, to)) push()
|
||
}
|
||
}
|
||
drag.value = undefined
|
||
removeWindowListeners()
|
||
}
|
||
|
||
function onWheel(event: WheelEvent) {
|
||
const element = canvas.value
|
||
if (!element) return
|
||
const rect = element.getBoundingClientRect()
|
||
const cursorX = event.clientX - rect.left
|
||
const cursorY = event.clientY - rect.top
|
||
const next = Math.min(1.8, Math.max(0.35, zoom.value * Math.exp(-event.deltaY * 0.0015)))
|
||
pan.x = cursorX - (cursorX - pan.x) * (next / zoom.value)
|
||
pan.y = cursorY - (cursorY - pan.y) * (next / zoom.value)
|
||
zoom.value = next
|
||
}
|
||
|
||
function nodeHeight(node: CanvasNode): number {
|
||
if (node.kind === 'value') {
|
||
return node.shape ? 64 + node.shape.slots.length * ARG_STEP : 86
|
||
}
|
||
return estimateNodeHeight(node.text, node.shape?.slots.length, Boolean(node.shape?.name))
|
||
}
|
||
|
||
function fitView() {
|
||
const element = canvas.value
|
||
if (!element || !model.nodes.length) return
|
||
const rect = element.getBoundingClientRect()
|
||
let minX = Infinity
|
||
let minY = Infinity
|
||
let maxX = -Infinity
|
||
let maxY = -Infinity
|
||
for (const node of model.nodes) {
|
||
minX = Math.min(minX, node.x)
|
||
minY = Math.min(minY, node.y)
|
||
maxX = Math.max(maxX, node.x + NODE_WIDTH)
|
||
maxY = Math.max(maxY, node.y + nodeHeight(node))
|
||
}
|
||
const width = Math.max(1, maxX - minX)
|
||
const height = Math.max(1, maxY - minY)
|
||
const scale = Math.min((rect.width - 70) / width, (rect.height - 70) / height, 1.1)
|
||
// Do not shrink the cards into unreadable specks; the user can pan instead.
|
||
zoom.value = Math.min(1.1, Math.max(0.7, scale))
|
||
pan.x = (rect.width - width * zoom.value) / 2 - minX * zoom.value
|
||
pan.y = (rect.height - height * zoom.value) / 2 - minY * zoom.value
|
||
}
|
||
|
||
// --- Graph structure -------------------------------------------------------
|
||
|
||
function outPoint(node: CanvasNode, port: GraphPort) {
|
||
return { x: node.x + NODE_WIDTH, y: node.y + (port === 'body' ? BODY_PORT_Y : PORT_Y) }
|
||
}
|
||
|
||
function inPoint(node: CanvasNode) {
|
||
return { x: node.x, y: node.y + PORT_Y }
|
||
}
|
||
|
||
function argPortTop(node: CanvasNode, index: number) {
|
||
return ARG_START + (node.shape?.name ? 24 : 0) + index * ARG_STEP
|
||
}
|
||
|
||
function argPortCenter(node: CanvasNode, index: number) {
|
||
return node.y + argPortTop(node, index)
|
||
}
|
||
|
||
function argPoint(node: CanvasNode, index: number) {
|
||
return { x: node.x, y: argPortCenter(node, index) }
|
||
}
|
||
|
||
function wirePath(from: { x: number; y: number }, to: { x: number; y: number }) {
|
||
const bend = Math.max(45, Math.abs(to.x - from.x) * 0.45)
|
||
return `M ${from.x} ${from.y} C ${from.x + bend} ${from.y}, ${to.x - bend} ${to.y}, ${to.x} ${to.y}`
|
||
}
|
||
|
||
const wires = computed(() => {
|
||
const byId = new Map(model.nodes.map(node => [node.id, node]))
|
||
return model.edges.flatMap(edge => {
|
||
const from = byId.get(edge.from)
|
||
const to = byId.get(edge.to)
|
||
if (!from || !to) return []
|
||
const start = outPoint(from, edge.port)
|
||
const end = edge.port === 'value' ? argPoint(to, edge.slot ?? 0) : inPoint(to)
|
||
return [{ edge, d: wirePath(start, end) }]
|
||
})
|
||
})
|
||
|
||
const tempWire = computed(() => {
|
||
const state = drag.value
|
||
if (state?.kind !== 'link') return ''
|
||
const from = model.nodes.find(node => node.id === state.from)
|
||
return from ? wirePath(outPoint(from, state.port), { x: state.x, y: state.y }) : ''
|
||
})
|
||
|
||
function removeEdge(edge: GraphEdge) {
|
||
model.edges = model.edges.filter(entry => entry.id !== edge.id)
|
||
push()
|
||
}
|
||
|
||
function disconnectNode(node: CanvasNode) {
|
||
const current = model.edges
|
||
model.edges = current.filter(edge =>
|
||
!(edge.to === node.id && (edge.port === 'next' || edge.port === 'body')),
|
||
)
|
||
if (model.edges.length !== current.length) push()
|
||
}
|
||
|
||
function slotEdge(node: CanvasNode, index: number) {
|
||
return model.edges.find(edge => edge.port === 'value' && edge.to === node.id && edge.slot === index)
|
||
}
|
||
|
||
function slotChild(node: CanvasNode, index: number) {
|
||
const edge = slotEdge(node, index)
|
||
return edge ? model.nodes.find(entry => entry.id === edge.from) : undefined
|
||
}
|
||
|
||
function slotChildText(node: CanvasNode, index: number): string {
|
||
return slotChild(node, index)?.text ?? ''
|
||
}
|
||
|
||
function disconnectSlot(node: CanvasNode, index: number) {
|
||
const edge = slotEdge(node, index)
|
||
if (!edge) return
|
||
model.edges = model.edges.filter(entry => entry.id !== edge.id)
|
||
push()
|
||
}
|
||
|
||
function removeNode(node: CanvasNode) {
|
||
model.nodes = model.nodes.filter(entry => entry.id !== node.id)
|
||
model.edges = model.edges.filter(edge => edge.from !== node.id && edge.to !== node.id)
|
||
push()
|
||
}
|
||
|
||
function addFromPalette(template: string, kind: 'ability' | 'effect' | 'value', label?: string) {
|
||
const element = canvas.value
|
||
const rect = element?.getBoundingClientRect()
|
||
const center = rect
|
||
? {
|
||
x: (rect.width / 2 - pan.x) / zoom.value - NODE_WIDTH / 2,
|
||
y: (rect.height / 2 - pan.y) / zoom.value - 40,
|
||
}
|
||
: { x: 80, y: 80 }
|
||
const offset = (cascade++ % 5) * 26
|
||
|
||
let node: CanvasNode
|
||
if (kind === 'value') {
|
||
if (template === '__or__' || template === '__and__') {
|
||
const combine = template === '__or__' ? 'or' : 'and'
|
||
node = {
|
||
id: nextNodeId(),
|
||
kind: 'value',
|
||
text: '',
|
||
valueLabel: 'Logic',
|
||
combine,
|
||
x: center.x + offset,
|
||
y: center.y + offset,
|
||
shape: {
|
||
head: '',
|
||
tail: '',
|
||
separator: ` ${combine} `,
|
||
slots: [
|
||
{ label: 'left', text: combine === 'or' ? 'creature' : 'red' },
|
||
{ label: 'right', text: combine === 'or' ? 'artifact' : 'creature' },
|
||
],
|
||
},
|
||
}
|
||
} else if (template === '__selector__') {
|
||
node = {
|
||
id: nextNodeId(),
|
||
kind: 'value',
|
||
text: '',
|
||
valueLabel: 'Selector',
|
||
x: center.x + offset,
|
||
y: center.y + offset,
|
||
shape: {
|
||
head: '',
|
||
tail: '',
|
||
separator: ' ',
|
||
slots: [
|
||
{ label: 'prefix', text: 'each', options: ['each', 'each other'] },
|
||
{ label: 'state', text: 'nontoken', options: ['nontoken', 'token', 'tapped', 'untapped', 'attacking'] },
|
||
{
|
||
label: 'type',
|
||
text: 'dragon',
|
||
options: [
|
||
'dragon',
|
||
'angel',
|
||
'creature',
|
||
'artifact',
|
||
'enchantment',
|
||
'land',
|
||
'planeswalker',
|
||
'elf',
|
||
'goblin',
|
||
'human',
|
||
'soldier',
|
||
'zombie',
|
||
'vampire',
|
||
],
|
||
},
|
||
{
|
||
label: 'controller',
|
||
text: 'you control',
|
||
options: ['you control', "you don't control", 'an opponent controls', 'your opponents control'],
|
||
},
|
||
],
|
||
},
|
||
}
|
||
} else {
|
||
node = {
|
||
id: nextNodeId(),
|
||
kind: 'value',
|
||
text: template,
|
||
literal: template,
|
||
valueLabel: label?.replace('Value · ', ''),
|
||
x: center.x + offset,
|
||
y: center.y + offset,
|
||
}
|
||
}
|
||
} else {
|
||
node = {
|
||
id: nextNodeId(),
|
||
kind,
|
||
text: template,
|
||
shape: shapeFromText(template),
|
||
x: center.x + offset,
|
||
y: center.y + offset,
|
||
}
|
||
}
|
||
|
||
model.nodes.push(node)
|
||
push()
|
||
}
|
||
|
||
const linked = computed(() => new Set(
|
||
model.edges
|
||
.filter(edge => edge.port === 'next' || edge.port === 'body')
|
||
.map(edge => edge.to),
|
||
))
|
||
|
||
function isAbilityEmpty(node: CanvasNode): boolean {
|
||
return node.kind === 'ability'
|
||
&& abilityRequiresEffects(node.text)
|
||
&& !model.edges.some(edge => edge.from === node.id && edge.port === 'next')
|
||
}
|
||
|
||
function isUnlinked(node: CanvasNode): boolean {
|
||
if (node.kind === 'effect') return !linked.value.has(node.id)
|
||
if (node.kind === 'value') {
|
||
return !model.edges.some(edge => edge.from === node.id && edge.port === 'value')
|
||
}
|
||
return false
|
||
}
|
||
|
||
// --- Node presentation -----------------------------------------------------
|
||
|
||
function abilityKind(text: string): string {
|
||
if (text.startsWith('on ')) return 'trigger'
|
||
if (text.startsWith('activate ')) return 'activated'
|
||
if (text.startsWith('static')) return 'static'
|
||
if (text.startsWith('spell')) return 'spell'
|
||
if (text.startsWith('keyword')) return 'keyword'
|
||
if (text.startsWith('chapter ')) return 'chapter'
|
||
if (text.startsWith('additional cost')) return 'additional'
|
||
if (text.startsWith('level')) return 'level'
|
||
if (text.startsWith('unsupported')) return 'unsupported'
|
||
return 'other'
|
||
}
|
||
|
||
function nodeTone(node: CanvasNode): string {
|
||
if (node.kind === 'raw') return 'raw'
|
||
if (node.kind === 'value') return 'value'
|
||
if (node.kind === 'ability') {
|
||
const kind = abilityKind(node.text)
|
||
return kind === 'other' ? 'effect' : kind
|
||
}
|
||
return blockOf(node.text)?.kind ?? 'effect'
|
||
}
|
||
|
||
function nodeLabel(node: CanvasNode): string {
|
||
if (node.kind === 'raw') {
|
||
return node.text.startsWith('##') ? 'FACE' : node.text.startsWith('#') ? 'CARD' : 'NOTE'
|
||
}
|
||
if (node.kind === 'value') return (node.combine ?? node.valueLabel ?? 'value').toUpperCase()
|
||
if (node.kind === 'ability') return abilityKind(node.text).toUpperCase()
|
||
if (node.shape?.name) return node.shape.name.toUpperCase()
|
||
const block = blockOf(node.text)
|
||
if (block) return block.kind.toUpperCase()
|
||
if (/^grant_ability\(/.test(node.text)) return 'GRANT ABILITY'
|
||
if (/^\d+\.\s/.test(node.text)) return 'MODE'
|
||
return parseCall(node.text)?.name?.toUpperCase() ?? 'LINE'
|
||
}
|
||
|
||
function hasNextPort(node: CanvasNode): boolean {
|
||
if (node.kind === 'ability') {
|
||
return abilityRequiresEffects(node.text)
|
||
|| model.edges.some(edge => edge.from === node.id && edge.port === 'next')
|
||
}
|
||
return node.kind === 'effect'
|
||
}
|
||
|
||
function inputValue(event: Event): string {
|
||
return (event.target as HTMLInputElement | HTMLSelectElement).value
|
||
}
|
||
|
||
function slotOptions(slot: NodeSlot): string[] {
|
||
const options = slot.options ?? []
|
||
return options.includes(slot.text) ? options : [slot.text, ...options]
|
||
}
|
||
|
||
function setText(node: CanvasNode, event: Event) {
|
||
node.text = inputValue(event)
|
||
push()
|
||
}
|
||
|
||
function setSlot(node: CanvasNode, index: number, event: Event) {
|
||
if (!node.shape?.slots[index]) return
|
||
node.shape.slots[index].text = inputValue(event)
|
||
push()
|
||
}
|
||
|
||
function setValueLiteral(node: CanvasNode, event: Event) {
|
||
node.literal = inputValue(event)
|
||
push()
|
||
}
|
||
</script>
|
||
|
||
<template>
|
||
<div class="graph-editor">
|
||
<div class="graph-toolbar">
|
||
<span class="muted">
|
||
Drag a socket to another node to connect. Blue/orange wires order effects; green wires feed arguments.
|
||
Wheel zooms, background drags pan.
|
||
</span>
|
||
<button type="button" @click="fitView">Fit</button>
|
||
</div>
|
||
|
||
<div class="graph-body">
|
||
<aside class="palette">
|
||
<input
|
||
v-model="paletteSearch"
|
||
class="palette-search"
|
||
type="search"
|
||
placeholder="Search blocks…"
|
||
spellcheck="false"
|
||
>
|
||
<section v-for="group in filteredPalette" :key="group.title">
|
||
<h4>{{ group.title }}</h4>
|
||
<button
|
||
v-for="item in group.items"
|
||
:key="item.value"
|
||
type="button"
|
||
@click="addFromPalette(item.value, group.kind, group.title)"
|
||
>
|
||
{{ item.label }}
|
||
</button>
|
||
</section>
|
||
</aside>
|
||
|
||
<div
|
||
ref="canvas"
|
||
class="graph-canvas"
|
||
:class="{ linking: isLinking }"
|
||
:style="canvasStyle"
|
||
@pointerdown="onCanvasDown"
|
||
@wheel.prevent="onWheel"
|
||
>
|
||
<div class="graph-layer" :style="layerStyle">
|
||
<svg class="wires">
|
||
<g v-for="wire in wires" :key="wire.edge.id">
|
||
<path class="wire" :class="wire.edge.port" :d="wire.d" />
|
||
<path class="wire-hit" :d="wire.d" @pointerdown.stop.prevent="removeEdge(wire.edge)" />
|
||
</g>
|
||
<path v-if="isLinking" class="wire temp" :d="tempWire" />
|
||
</svg>
|
||
|
||
<div
|
||
v-for="node in model.nodes"
|
||
:key="node.id"
|
||
class="node-wrap"
|
||
:style="{ transform: `translate(${node.x}px, ${node.y}px)` }"
|
||
@pointerdown="startNodeDrag($event, node)"
|
||
>
|
||
<article
|
||
class="node"
|
||
:class="[nodeTone(node), { unlinked: isUnlinked(node), empty: isAbilityEmpty(node) }]"
|
||
>
|
||
<header class="node-head">
|
||
<span class="dot" />
|
||
<span class="node-kind">{{ nodeLabel(node) }}</span>
|
||
<button type="button" class="delete" title="Delete node" @pointerdown.stop @click="removeNode(node)">
|
||
×
|
||
</button>
|
||
</header>
|
||
|
||
<template v-if="node.shape">
|
||
<span v-if="node.shape.name" class="call-name">{{ node.shape.name }}</span>
|
||
<div v-for="(slot, slotIndex) in node.shape.slots" :key="slotIndex" class="slot">
|
||
<span class="slot-label">{{ slot.label }}</span>
|
||
<div v-if="slotChild(node, slotIndex)" class="slot-linked">
|
||
{{ slotChildText(node, slotIndex) }}
|
||
</div>
|
||
<select
|
||
v-else-if="slot.options?.length"
|
||
class="arg-input"
|
||
:value="slot.text"
|
||
@change="setSlot(node, slotIndex, $event)"
|
||
>
|
||
<option v-for="option in slotOptions(slot)" :key="option" :value="option">
|
||
{{ option }}
|
||
</option>
|
||
</select>
|
||
<input
|
||
v-else
|
||
class="arg-input"
|
||
:value="slot.text"
|
||
:placeholder="slot.label"
|
||
spellcheck="false"
|
||
@input="setSlot(node, slotIndex, $event)"
|
||
>
|
||
</div>
|
||
</template>
|
||
|
||
<input
|
||
v-else-if="node.kind === 'value'"
|
||
class="header-input"
|
||
:value="node.literal"
|
||
spellcheck="false"
|
||
@input="setValueLiteral(node, $event)"
|
||
>
|
||
|
||
<input
|
||
v-else
|
||
class="header-input"
|
||
:value="node.text"
|
||
spellcheck="false"
|
||
@input="setText(node, $event)"
|
||
>
|
||
|
||
<span
|
||
v-if="node.kind === 'effect'"
|
||
class="port in"
|
||
data-port="in"
|
||
:data-node-id="node.id"
|
||
title="Input — click to disconnect"
|
||
@pointerdown.stop.prevent="disconnectNode(node)"
|
||
/>
|
||
|
||
<template v-if="node.shape">
|
||
<span
|
||
v-for="(_, slotIndex) in node.shape.slots"
|
||
:key="'arg' + slotIndex"
|
||
class="port arg"
|
||
data-port="arg"
|
||
:data-node-id="node.id"
|
||
:data-slot="slotIndex"
|
||
:style="{ top: `${argPortTop(node, slotIndex) - 10}px` }"
|
||
:title="`${node.shape.slots[slotIndex].label} — click to disconnect`"
|
||
@pointerdown.stop.prevent="disconnectSlot(node, slotIndex)"
|
||
/>
|
||
</template>
|
||
|
||
<span
|
||
v-if="hasNextPort(node)"
|
||
class="port out next"
|
||
title="Output — drag to the input socket of another node"
|
||
@pointerdown.stop.prevent="startLink($event, node, 'next')"
|
||
/>
|
||
<span
|
||
v-if="hasBodyPort(model, node)"
|
||
class="port out body"
|
||
title="Body output — drag nested effects from here"
|
||
@pointerdown.stop.prevent="startLink($event, node, 'body')"
|
||
/>
|
||
<span
|
||
v-if="node.kind === 'value'"
|
||
class="port out value"
|
||
title="Value output — drag to an argument socket"
|
||
@pointerdown.stop.prevent="startLink($event, node, 'value')"
|
||
/>
|
||
</article>
|
||
</div>
|
||
</div>
|
||
|
||
<div v-if="problems.length" class="problems">
|
||
<span v-for="problem in problems.slice(0, 3)" :key="problem">{{ problem }}</span>
|
||
<span v-if="problems.length > 3">+{{ problems.length - 3 }} more</span>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<style scoped>
|
||
.graph-editor {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 0.55rem;
|
||
flex: 1;
|
||
min-height: 0;
|
||
}
|
||
|
||
.graph-toolbar {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 0.75rem;
|
||
flex-wrap: wrap;
|
||
}
|
||
|
||
.graph-toolbar button {
|
||
padding: 0.25rem 0.6rem;
|
||
}
|
||
|
||
.graph-body {
|
||
display: flex;
|
||
gap: 0.6rem;
|
||
flex: 1;
|
||
min-height: 0;
|
||
}
|
||
|
||
.palette {
|
||
width: 11rem;
|
||
flex: none;
|
||
overflow-y: auto;
|
||
max-height: 100%;
|
||
padding: 0.5rem;
|
||
border: 1px solid var(--line);
|
||
border-radius: 8px;
|
||
background: var(--panel);
|
||
}
|
||
|
||
.palette-search {
|
||
width: 100%;
|
||
margin-bottom: 0.5rem;
|
||
font-size: 0.75rem;
|
||
padding: 0.25rem 0.35rem;
|
||
background: #0e121a;
|
||
border: 1px solid var(--line);
|
||
border-radius: 6px;
|
||
color: var(--text);
|
||
}
|
||
|
||
.palette section + section {
|
||
margin-top: 0.65rem;
|
||
}
|
||
|
||
.palette h4 {
|
||
margin: 0 0 0.2rem;
|
||
font-size: 0.68rem;
|
||
letter-spacing: 0.06em;
|
||
text-transform: uppercase;
|
||
color: var(--muted);
|
||
}
|
||
|
||
.palette button {
|
||
display: block;
|
||
width: 100%;
|
||
text-align: left;
|
||
font-size: 0.75rem;
|
||
padding: 0.22rem 0.35rem;
|
||
background: transparent;
|
||
border-color: transparent;
|
||
color: var(--text);
|
||
}
|
||
|
||
.palette button:hover {
|
||
background: #1b2130;
|
||
border-color: var(--accent);
|
||
}
|
||
|
||
.graph-canvas {
|
||
position: relative;
|
||
flex: 1;
|
||
min-width: 0;
|
||
min-height: 18rem;
|
||
overflow: hidden;
|
||
border: 1px solid var(--line);
|
||
border-radius: 8px;
|
||
background-color: #0b0e14;
|
||
background-image:
|
||
linear-gradient(#171c28 1px, transparent 1px),
|
||
linear-gradient(90deg, #171c28 1px, transparent 1px);
|
||
cursor: grab;
|
||
touch-action: none;
|
||
}
|
||
|
||
.graph-canvas:active {
|
||
cursor: grabbing;
|
||
}
|
||
|
||
.graph-layer {
|
||
position: absolute;
|
||
inset: 0;
|
||
transform-origin: 0 0;
|
||
}
|
||
|
||
.wires {
|
||
position: absolute;
|
||
left: 0;
|
||
top: 0;
|
||
width: 100%;
|
||
height: 100%;
|
||
overflow: visible;
|
||
pointer-events: none;
|
||
}
|
||
|
||
.wire {
|
||
fill: none;
|
||
stroke: var(--accent);
|
||
stroke-width: 2;
|
||
opacity: 0.8;
|
||
}
|
||
|
||
.wire.body {
|
||
stroke: var(--warn);
|
||
stroke-dasharray: 6 4;
|
||
}
|
||
|
||
.wire.value {
|
||
stroke: var(--ok);
|
||
stroke-dasharray: 2 3;
|
||
}
|
||
|
||
.wire.temp {
|
||
stroke: #fff;
|
||
stroke-dasharray: 4 4;
|
||
opacity: 0.9;
|
||
}
|
||
|
||
.wire-hit {
|
||
fill: none;
|
||
stroke: transparent;
|
||
stroke-width: 14;
|
||
pointer-events: stroke;
|
||
cursor: pointer;
|
||
}
|
||
|
||
.node-wrap {
|
||
position: absolute;
|
||
left: 0;
|
||
top: 0;
|
||
width: 230px;
|
||
touch-action: none;
|
||
}
|
||
|
||
.node {
|
||
--tone: var(--accent);
|
||
position: relative;
|
||
width: 230px;
|
||
background: #151a24;
|
||
border: 1px solid var(--line);
|
||
border-top: 3px solid var(--tone);
|
||
border-radius: 7px;
|
||
box-shadow: 0 6px 18px #0006;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 0.4rem;
|
||
padding: 0.35rem 0.55rem 0.55rem;
|
||
cursor: grab;
|
||
}
|
||
|
||
.node.unlinked {
|
||
border-style: dashed;
|
||
opacity: 0.72;
|
||
}
|
||
|
||
.node.trigger {
|
||
--tone: #5ec9b8;
|
||
}
|
||
|
||
.node.activated {
|
||
--tone: #e8c07d;
|
||
}
|
||
|
||
.node.static {
|
||
--tone: #b59af7;
|
||
}
|
||
|
||
.node.spell,
|
||
.node.chapter {
|
||
--tone: #7aa2f7;
|
||
}
|
||
|
||
.node.keyword {
|
||
--tone: #7dd3a0;
|
||
}
|
||
|
||
.node.unsupported {
|
||
--tone: var(--bad);
|
||
}
|
||
|
||
.node.if {
|
||
--tone: #e8a45c;
|
||
}
|
||
|
||
.node.choose {
|
||
--tone: #c39af7;
|
||
}
|
||
|
||
.node.schedule {
|
||
--tone: #5ec9b8;
|
||
}
|
||
|
||
.node.raw {
|
||
--tone: #5c6577;
|
||
cursor: grab;
|
||
}
|
||
|
||
.node.value {
|
||
--tone: var(--ok);
|
||
}
|
||
|
||
.node.empty {
|
||
--tone: var(--warn);
|
||
}
|
||
|
||
.node-head {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 0.35rem;
|
||
cursor: grab;
|
||
}
|
||
|
||
.dot {
|
||
width: 7px;
|
||
height: 7px;
|
||
border-radius: 50%;
|
||
background: var(--tone);
|
||
flex: none;
|
||
}
|
||
|
||
.node-kind {
|
||
font-size: 0.65rem;
|
||
letter-spacing: 0.08em;
|
||
font-weight: 700;
|
||
color: var(--tone);
|
||
}
|
||
|
||
.delete {
|
||
margin-left: auto;
|
||
padding: 0 0.3rem;
|
||
line-height: 1.3;
|
||
background: transparent;
|
||
border-color: transparent;
|
||
color: var(--muted);
|
||
}
|
||
|
||
.delete:hover {
|
||
color: var(--text);
|
||
border-color: var(--line);
|
||
}
|
||
|
||
.header-input,
|
||
.arg-input {
|
||
width: 100%;
|
||
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
||
font-size: 0.78rem;
|
||
padding: 0.25rem 0.35rem;
|
||
background: #0e121a;
|
||
cursor: text;
|
||
}
|
||
|
||
select.arg-input {
|
||
cursor: pointer;
|
||
}
|
||
|
||
.call-name {
|
||
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
||
font-size: 0.76rem;
|
||
color: var(--tone);
|
||
}
|
||
|
||
.slot {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 0.1rem;
|
||
}
|
||
|
||
.slot-label {
|
||
font-size: 0.6rem;
|
||
letter-spacing: 0.05em;
|
||
text-transform: uppercase;
|
||
color: var(--muted);
|
||
}
|
||
|
||
.slot-linked {
|
||
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
||
font-size: 0.75rem;
|
||
color: var(--ok);
|
||
background: #0e121a;
|
||
border: 1px dashed #3f6b52;
|
||
border-radius: 6px;
|
||
padding: 0.25rem 0.35rem;
|
||
overflow-wrap: anywhere;
|
||
}
|
||
|
||
.arg-input::placeholder {
|
||
color: #5c6577;
|
||
font-style: italic;
|
||
}
|
||
|
||
.port {
|
||
position: absolute;
|
||
width: 14px;
|
||
height: 14px;
|
||
border-radius: 50%;
|
||
background: #0b0e14;
|
||
border: 2px solid var(--accent);
|
||
z-index: 2;
|
||
cursor: crosshair;
|
||
}
|
||
|
||
.port:hover {
|
||
box-shadow: 0 0 0 4px #7aa2f755;
|
||
}
|
||
|
||
.port.in {
|
||
left: -7px;
|
||
top: 18px;
|
||
}
|
||
|
||
.port.out {
|
||
right: -7px;
|
||
background: var(--accent);
|
||
}
|
||
|
||
.port.next {
|
||
top: 18px;
|
||
}
|
||
|
||
.port.body {
|
||
top: 42px;
|
||
border-radius: 3px;
|
||
background: var(--warn);
|
||
border-color: var(--warn);
|
||
}
|
||
|
||
.port.body::after {
|
||
content: 'B';
|
||
position: absolute;
|
||
inset: 0;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 8px;
|
||
font-weight: 700;
|
||
color: #0b0e14;
|
||
}
|
||
|
||
.port.arg {
|
||
left: -7px;
|
||
border-color: var(--ok);
|
||
}
|
||
|
||
.port.arg:hover {
|
||
box-shadow: 0 0 0 4px #7dd3a055;
|
||
}
|
||
|
||
.port.value {
|
||
top: 18px;
|
||
background: var(--ok);
|
||
border-color: var(--ok);
|
||
}
|
||
|
||
.graph-canvas.linking .port.in,
|
||
.graph-canvas.linking .port.arg {
|
||
box-shadow: 0 0 0 4px #7aa2f755;
|
||
}
|
||
|
||
.problems {
|
||
position: absolute;
|
||
left: 0.5rem;
|
||
right: 0.5rem;
|
||
bottom: 0.5rem;
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 0.35rem;
|
||
pointer-events: none;
|
||
}
|
||
|
||
.problems span {
|
||
font-size: 0.72rem;
|
||
color: var(--warn);
|
||
background: #1a1710e6;
|
||
border: 1px solid #5c4a2a;
|
||
border-radius: 5px;
|
||
padding: 0.15rem 0.4rem;
|
||
}
|
||
|
||
@media (max-width: 800px) {
|
||
.graph-body {
|
||
flex-direction: column;
|
||
}
|
||
|
||
.palette {
|
||
width: auto;
|
||
max-height: 10rem;
|
||
}
|
||
|
||
.graph-canvas {
|
||
min-height: 20rem;
|
||
}
|
||
}
|
||
</style>
|