mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Name a node's connectors sockets
- Rename the node connector names and their data attribute
This commit is contained in:
1 parent
d8c0c2cc61
commit
5040d32cb8
5 files changed
+19
-19
No files matched your search
@@ -49,7 +49,7 @@ describe('layoutNodes', () => {
|
||||
expect(placedAt(layout, ['parts', 1]).y).toBeGreaterThan(placedAt(layout, ['parts', 0]).y + 300)
|
||||
})
|
||||
|
||||
it('puts a node where it was dragged, and marks which nodes have ports', () => {
|
||||
it('puts a node where it was dragged, and marks which nodes have sockets', () => {
|
||||
const layout = layoutNodes([node([], [node(['parts', 0])])], height, new Map([[JSON.stringify(['parts', 0]), { x: 500, y: 44 }]]))
|
||||
const part = placedAt(layout, ['parts', 0])
|
||||
|
||||
|
||||
@@ -19,9 +19,9 @@ export interface PlacedNode {
|
||||
x: number
|
||||
y: number
|
||||
height: number
|
||||
/** Whether it grows from another node, so it has an input port. */
|
||||
/** Whether it grows from another node, so it has an input socket. */
|
||||
grown: boolean
|
||||
/** Whether other nodes grow from it, so it has an output port. */
|
||||
/** Whether other nodes grow from it, so it has an output socket. */
|
||||
growing: boolean
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@ import { NODE_HEADER, NODE_STRIPE, type NodeRows } from '../editor/nodeRows'
|
||||
import { colorOfKind, colorOfRole } from './nodeColors'
|
||||
import { NodeRowView } from './NodeRows'
|
||||
|
||||
/** Where a node's ports sit below its top: level with the middle of its header. */
|
||||
export const PORT_TOP = NODE_STRIPE + NODE_HEADER / 2
|
||||
const PORT_SIZE = 9
|
||||
/** Where a node's sockets sit below its top: level with the middle of its header. */
|
||||
export const SOCKET_TOP = NODE_STRIPE + NODE_HEADER / 2
|
||||
const SOCKET_SIZE = 9
|
||||
const CHIP_FILL_ALPHA = '47'
|
||||
|
||||
interface NodeBoxProps {
|
||||
@@ -25,8 +25,8 @@ interface NodeBoxProps {
|
||||
|
||||
/**
|
||||
* One node as the editor draws it: a stripe in the colour of its kind, a header with its title and roles, and a row
|
||||
* per setting, edited in place. A part has an input port on its left, a ring to drag when it can grow elsewhere; a
|
||||
* node others grow from has an output port on its right.
|
||||
* per setting, edited in place. A part has an input socket on its left, a ring to drag when it can grow elsewhere; a
|
||||
* node others grow from has an output socket on its right.
|
||||
*/
|
||||
export const NodeBox = memo(function NodeBox({ placed, rows, selected, dropTarget, offset, locked }: NodeBoxProps): React.JSX.Element {
|
||||
const { node } = placed
|
||||
@@ -47,8 +47,8 @@ export const NodeBox = memo(function NodeBox({ placed, rows, selected, dropTarge
|
||||
{rows.rows.map((row) => (
|
||||
<NodeRowView key={row.id} row={row} addable={rows.addable} editable={editable} />
|
||||
))}
|
||||
{placed.grown && <InputPort handle={node.movable && !locked} />}
|
||||
{placed.growing && <span className="absolute rounded-full bg-secondary-text" style={portStyle('right')} />}
|
||||
{placed.grown && <InputSocket handle={node.movable && !locked} />}
|
||||
{placed.growing && <span className="absolute rounded-full bg-secondary-text" style={socketStyle('right')} />}
|
||||
</div>
|
||||
)
|
||||
})
|
||||
@@ -76,20 +76,20 @@ function RoleChip({ role }: { role: string }): React.JSX.Element {
|
||||
}
|
||||
|
||||
// A part that can grow elsewhere has a ring for an input, a handle to drag onto the node it should grow from.
|
||||
function InputPort({ handle }: { handle: boolean }): React.JSX.Element {
|
||||
function InputSocket({ handle }: { handle: boolean }): React.JSX.Element {
|
||||
return (
|
||||
<span
|
||||
data-port={handle ? 'regrow' : 'input'}
|
||||
data-socket={handle ? 'regrow' : 'input'}
|
||||
title={handle ? 'Drag onto another node to grow from it' : undefined}
|
||||
className={cn(
|
||||
'absolute rounded-full border-[1.5px] border-secondary-text transition-transform',
|
||||
handle ? 'cursor-pointer bg-popover hover:scale-[1.35] hover:border-primary dark:bg-secondary' : 'bg-secondary-text'
|
||||
)}
|
||||
style={portStyle('left')}
|
||||
style={socketStyle('left')}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function portStyle(side: 'left' | 'right'): React.CSSProperties {
|
||||
return { [side]: -PORT_SIZE / 2, top: PORT_TOP - PORT_SIZE / 2, width: PORT_SIZE, height: PORT_SIZE }
|
||||
function socketStyle(side: 'left' | 'right'): React.CSSProperties {
|
||||
return { [side]: -SOCKET_SIZE / 2, top: SOCKET_TOP - SOCKET_SIZE / 2, width: SOCKET_SIZE, height: SOCKET_SIZE }
|
||||
}
|
||||
@@ -98,7 +98,7 @@ export function NodeCanvas({ roots, types, values, file, selectedId, locked, sug
|
||||
return
|
||||
}
|
||||
event.currentTarget.setPointerCapture(event.pointerId)
|
||||
if (target.closest('[data-port="regrow"]') !== null) {
|
||||
if (target.closest('[data-socket="regrow"]') !== null) {
|
||||
setGesture({ kind: 'regrowing', placed, pointer: view.graphPoint(event.clientX, event.clientY), target: null })
|
||||
} else {
|
||||
setGesture({ kind: 'moving', placed, start: { x: event.clientX, y: event.clientY }, moved: false, offset: { x: 0, y: 0 } })
|
||||
|
||||
@@ -2,7 +2,7 @@ import { memo } from 'react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { NODE_WIDTH, type PlacedNode, type PlacedWire, type Point } from '../editor/nodeLayout'
|
||||
import { colorOfKind } from './nodeColors'
|
||||
import { PORT_TOP } from './NodeBox'
|
||||
import { SOCKET_TOP } from './NodeBox'
|
||||
|
||||
/** The wire to a part placed once per copy, such as a branch of branches, rather than once. */
|
||||
export const EACH_COPY_WIRE = 'each copy'
|
||||
@@ -41,7 +41,7 @@ export const NodeWires = memo(function NodeWires({ wires, selectedId, moved, reg
|
||||
return (
|
||||
<path
|
||||
key={`${from.id}>${to.id}`}
|
||||
d={curve({ x: start.x + NODE_WIDTH, y: start.y + PORT_TOP }, { x: end.x, y: end.y + PORT_TOP })}
|
||||
d={curve({ x: start.x + NODE_WIDTH, y: start.y + SOCKET_TOP }, { x: end.x, y: end.y + SOCKET_TOP })}
|
||||
className={cn('fill-none', lit ? 'stroke-primary' : !copies && 'stroke-input')}
|
||||
style={copies && !lit ? { stroke: colorOfKind(from.node.kind) } : undefined}
|
||||
strokeWidth={lit ? 2 : 1.5}
|
||||
@@ -52,7 +52,7 @@ export const NodeWires = memo(function NodeWires({ wires, selectedId, moved, reg
|
||||
})}
|
||||
{regrow !== null && (
|
||||
<path
|
||||
d={curve(regrow.pointer, { x: regrow.part.x, y: regrow.part.y + PORT_TOP })}
|
||||
d={curve(regrow.pointer, { x: regrow.part.x, y: regrow.part.y + SOCKET_TOP })}
|
||||
className={cn('fill-none', regrow.onTarget ? 'stroke-success' : 'stroke-primary')}
|
||||
strokeWidth={2}
|
||||
strokeDasharray={COPY_DASH}
|
||||
|
||||
Reference in new issue
Block a user