cleanup more

This commit is contained in:
Joeri Exelmans 2025-05-18 10:59:25 +02:00
parent 1d54ac1433
commit 802373ba16

View file

@ -51,22 +51,16 @@ function nestedInputProperties({state, setState, suggestionPriority}: CallBlockP
return {state: state.input, setState: setInput, onCancel: onInputCancel, suggestionPriority: inputSuggestionPriorirty}; return {state: state.input, setState: setInput, onCancel: onInputCancel, suggestionPriority: inputSuggestionPriorirty};
} }
export function CallBlock({ state, setState, suggestionPriority }: CallBlockProps) { export function CallBlock(props: CallBlockProps) {
const env = useContext(EnvContext); const env = useContext(EnvContext);
const resolved = evalEditorBlock(state, env); const resolved = evalEditorBlock(props.state, env);
return <span className={"functionBlock" + ((resolved.kind === "error") ? " unifyError" : "")}> return <span className={"functionBlock" + ((resolved.kind === "error") ? " unifyError" : "")}>
<FunctionHeader <FunctionHeader {...props} />
state={state}
setState={setState}
suggestionPriority={suggestionPriority}
/>
<div className="functionParams"> <div className="functionParams">
<div className="outputParam"> <div className="outputParam">
{/* Sequence of input parameters */} {/* Sequence of input parameters */}
<InputParams <InputParams
state={state} {...props}
setState={setState}
suggestionPriority={suggestionPriority}
depth={0} depth={0}
errorDepth={(resolved.kind === "error") ? (resolved.depth) : -1} errorDepth={(resolved.kind === "error") ? (resolved.depth) : -1}
/> />
@ -84,11 +78,11 @@ function computePriority(fn: ResolvedType, input: ResolvedType, outPriority: (s:
return score; return score;
} }
function FunctionHeader({ state, setState, suggestionPriority }) { function FunctionHeader(props) {
const env = useContext(EnvContext); const env = useContext(EnvContext);
const globalContext = useContext(GlobalContext); const globalContext = useContext(GlobalContext);
const nestedProperties = nestedFnProperties({state, setState, suggestionPriority}, env); const nestedProperties = nestedFnProperties(props, env);
if (state.fn.kind === "call" && globalContext?.syntacticSugar) { if (props.state.fn.kind === "call" && globalContext?.syntacticSugar) {
// if the function we're calling is itself the result of a function call, // if the function we're calling is itself the result of a function call,
// then we are anonymous, and so we don't draw a function name // then we are anonymous, and so we don't draw a function name
return <FunctionHeader {...nestedProperties} />; return <FunctionHeader {...nestedProperties} />;
@ -102,21 +96,21 @@ function FunctionHeader({ state, setState, suggestionPriority }) {
} }
} }
function InputParams({ state, setState, suggestionPriority, depth, errorDepth }) { function InputParams({ depth, errorDepth, ...rest }) {
const env = useContext(EnvContext); const env = useContext(EnvContext);
const globalContext = useContext(GlobalContext); const globalContext = useContext(GlobalContext);
const isOffending = depth === errorDepth; const isOffending = depth === errorDepth;
return <div className={"inputParam" + (isOffending ? " offending" : "")}> return <div className={"inputParam" + (isOffending ? " offending" : "")}>
{state.fn.kind === "call" {rest.state.fn.kind === "call"
&& globalContext?.syntacticSugar && globalContext?.syntacticSugar
&& <InputParams && <InputParams
{...nestedFnProperties({state, setState, suggestionPriority}, env)} {...nestedFnProperties(rest as CallBlockProps, env)}
depth={depth+1} depth={depth+1}
errorDepth={errorDepth} errorDepth={errorDepth}
/>} />}
{/* Our own input param */} {/* Our own input param */}
<Editor <Editor
{...nestedInputProperties({state, setState, suggestionPriority}, env)} {...nestedInputProperties(rest as CallBlockProps, env)}
/> />
</div>; </div>;
} }