add 'filter' property to CallBlock to prepare to filter suggestions on output type

This commit is contained in:
Joeri Exelmans 2025-05-14 10:36:49 +02:00
parent 0a8d430d3a
commit d3138e6617
2 changed files with 7 additions and 5 deletions

View file

@ -22,9 +22,10 @@ interface CallBlockProps<
FnState=EditorState,
InputState=EditorState,
> extends State2Props<CallBlockState<FnState,InputState>,EditorState> {
filter: (suggestion: SuggestionType) => boolean;
}
function headlessCallBlock({setState}: CallBlockProps) {
function headlessCallBlock(setState: (callback: SetStateFn<CallBlockState,EditorState>) => void) {
const setFn = (callback: SetStateFn) => {
setState(state => ({...state, fn: callback(state.fn)}));
}
@ -40,9 +41,9 @@ function headlessCallBlock({setState}: CallBlockProps) {
return {setFn, setInput, onFnCancel, onInputCancel};
}
export function CallBlock({ state, setState }: CallBlockProps) {
export function CallBlock({ state, setState, filter }: CallBlockProps) {
const {setFn, setInput, onFnCancel, onInputCancel}
= headlessCallBlock({ state, setState });
= headlessCallBlock(setState);
const env = useContext(EnvContext);
const resolved = evalEditorBlock(state, env);
return <span className={"functionBlock" + ((resolved instanceof DeepError) ? " unifyError" : "")}>
@ -84,7 +85,7 @@ function FunctionHeader({ fn, setFn, input, onFnCancel }) {
const {
setFn : setFnFn,
onFnCancel : onFnFnCancel,
} = headlessCallBlock({state: fn, setState: setFn});
} = headlessCallBlock(setFn);
return <FunctionHeader
fn={fn.fn}
@ -130,7 +131,7 @@ function NestedParams({fn, setFn, depth, errorDepth}) {
const {
setFn : setFnFn,
setInput : setFnInput,
} = headlessCallBlock({state: fn, setState: setFn});
} = headlessCallBlock(setFn);
return <InputParams
fn={fn.fn}
setFn={setFnFn}

View file

@ -151,6 +151,7 @@ export function Editor({state, setState, onCancel, filter}: EditorProps) {
return <CallBlock
state={state}
setState={setState as (callback:(p:CallBlockState)=>EditorState)=>void}
filter={filter}
/>;
case "let":
return <LetInBlock