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

Fused output for Pass Through node #2341

Merged
merged 1 commit into from
Nov 27, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 13 additions & 4 deletions backend/src/api/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ def to_dict(self):
}


@dataclass
class IOFusion:
output_id: OutputId


class LiteralErrorValue(TypedDict):
type: Literal["literal"]
value: str | int | float | None
Expand Down Expand Up @@ -88,7 +93,7 @@ def __init__(
self.id: InputId = InputId(-1)
self.associated_type: Any = associated_type

self.fused_with_output: OutputId | None = None
self.fused: IOFusion | None = None

# Optional documentation
self.description: str | None = None
Expand Down Expand Up @@ -141,7 +146,11 @@ def to_dict(self):
"hasHandle": self.has_handle,
"description": self.description,
"hint": self.hint,
"fusedWithOutput": self.fused_with_output,
"fused": {
"outputId": self.fused.output_id,
}
if self.fused
else None,
}

def with_id(self, input_id: InputId | int):
Expand All @@ -160,8 +169,8 @@ def make_optional(self):
self.associated_type = Optional[associated_type]
return self

def fused(self, with_output: OutputId | int = 0):
self.fused_with_output = OutputId(with_output)
def make_fused(self, with_output: OutputId | int = 0):
self.fused = IOFusion(output_id=OutputId(with_output))
return self

def __repr__(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
description="Outputs the given color.",
icon="MdColorLens",
inputs=[
ColorInput().fused(),
ColorInput().make_fused(),
],
outputs=[
ColorOutput(color_type="Input0"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
inputs=[
DirectoryInput(
"Directory", must_exist=False, hide_label=True, has_handle=True
).fused(),
).make_fused(),
],
outputs=[
DirectoryOutput("Directory", output_type="Input0"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
precision=100,
controls_step=1,
hide_label=True,
).fused(),
).make_fused(),
],
outputs=[
NumberOutput("Number", output_type="Input0"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
name="Pass Through",
description="Outputs the input value as is.",
icon="MdDoubleArrow",
inputs=[AnyInput(label="Value")],
outputs=[BaseOutput(output_type="Input0", label="Value")],
inputs=[
AnyInput(label="Value").make_fused(),
],
outputs=[
BaseOutput(output_type="Input0", label="Value"),
],
)
def pass_through_node(value: object) -> object:
return value
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
precision=0,
controls_step=1,
unit="%",
).fused(),
).make_fused(),
],
outputs=[
NumberOutput("Percent", output_type="Input0"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
inputs=[
TextInput(
"Text", min_length=0, hide_label=True, allow_empty_string=True
).fused(),
).make_fused(),
],
outputs=[
TextOutput("Text", output_type="Input0"),
Expand Down
6 changes: 5 additions & 1 deletion src/common/common-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export interface InputConversionSchema {
readonly convert: ExpressionJson;
}

export interface IOFusion {
readonly outputId: OutputId;
}

interface InputBase {
readonly id: InputId;
readonly type: ExpressionJson;
Expand All @@ -54,7 +58,7 @@ interface InputBase {
readonly hasHandle: boolean;
readonly description?: string;
readonly hint: boolean;
readonly fusedWithOutput?: OutputId | null;
readonly fused?: IOFusion | null;
}
export interface InputOption {
option: string;
Expand Down
27 changes: 19 additions & 8 deletions src/renderer/components/inputs/SchemaInput.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { NeverType } from '@chainner/navi';
import { Box, HStack } from '@chakra-ui/react';
import { Box, Center, HStack } from '@chakra-ui/react';
import { memo, useCallback } from 'react';
import { useContextSelector } from 'use-context-selector';
import { Input, InputKind, InputValue, Size } from '../../../common/common-types';
import { getInputValue } from '../../../common/util';
import { BackendContext } from '../../contexts/BackendContext';
import { NodeState } from '../../helpers/nodeState';
import { OutputHandle } from '../outputs/OutputContainer';
import { TypeTags } from '../TypeTag';
import { ColorInput } from './ColorInput';
import { DirectoryInput } from './DirectoryInput';
import { DropDownInput } from './DropDownInput';
Expand Down Expand Up @@ -43,7 +44,7 @@ export interface SingleInputProps {
* Represents a single input from a schema's input list.
*/
export const SchemaInput = memo(({ input, nodeState, afterInput }: SingleInputProps) => {
const { id: inputId, kind, hasHandle, fusedWithOutput } = input;
const { id: inputId, kind, hasHandle, fused } = input;
const {
schemaId,
id: nodeId,
Expand Down Expand Up @@ -132,28 +133,38 @@ export const SchemaInput = memo(({ input, nodeState, afterInput }: SingleInputPr
);
}

if (fusedWithOutput != null) {
if (fused) {
const outputType = nodeState.type.instance?.outputs.get(fused.outputId);

const fusedOutputHandle = (
<OutputHandle
definitionType={
functionDefinition?.outputDefaults.get(fusedWithOutput) ?? NeverType.instance
functionDefinition?.outputDefaults.get(fused.outputId) ?? NeverType.instance
}
id={nodeId}
isConnected={nodeState.connectedOutputs.has(fusedWithOutput)}
isConnected={nodeState.connectedOutputs.has(fused.outputId)}
nodeType={schema.nodeType}
outputId={fusedWithOutput}
type={nodeState.type.instance?.outputs.get(fusedWithOutput)}
outputId={fused.outputId}
type={outputType}
/>
);

inputElement = (
<HStack>
<HStack spacing={0}>
<Box
flexGrow={1}
mr="0.5em"
>
{inputElement}
</Box>
{input.kind === 'generic' && outputType && (
<Center pr="0.5em">
<TypeTags
isOptional={false}
type={outputType}
/>
</Center>
)}
{fusedOutputHandle}
</HStack>
);
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/node/NodeBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const NodeBody = memo(({ nodeState, animated = false }: NodeBodyProps) =>

const autoInput = inputs.length === 1 && isAutoInput(inputs[0]);
const anyVisibleOutputs = outputs.some((output) => {
return !inputs.some((input) => input.fusedWithOutput === output.id);
return !inputs.some((input) => input.fused?.outputId === output.id);
});

return (
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/node/NodeOutputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const NodeOutputs = memo(({ nodeState, animated }: NodeOutputProps) => {
return (
<>
{schema.outputs.map((output) => {
if (schema.inputs.some((i) => i.fusedWithOutput === output.id)) {
if (schema.inputs.some((i) => i.fused?.outputId === output.id)) {
return null;
}

Expand Down