refactor a bit more
This commit is contained in:
parent
230916ceb1
commit
fdbf43a4e9
11 changed files with 79 additions and 90 deletions
|
|
@ -10,6 +10,9 @@ import type { ExprBlockState, State2Props } from "./ExprBlock";
|
|||
import { attemptParseLiteral } from "./eval";
|
||||
import { Input } from "./Input";
|
||||
import { initialEditorState } from "./configurations";
|
||||
import { CallContext } from "./CallContext";
|
||||
import { getActions } from "./actions";
|
||||
import { GlobalContext } from "./GlobalContext";
|
||||
|
||||
interface Literal {
|
||||
kind: "literal";
|
||||
|
|
@ -35,7 +38,6 @@ export type PrioritizedSuggestionType = [number, ...SuggestionType];
|
|||
|
||||
interface InputBlockProps extends State2Props<InputBlockState,ExprBlockState> {
|
||||
onCancel: () => void;
|
||||
addParam: (e: ExprBlockState) => void;
|
||||
}
|
||||
|
||||
const computeSuggestions = (text, env, suggestionPriority: (s: ResolvedType) => number): PrioritizedSuggestionType[] => {
|
||||
|
|
@ -61,9 +63,11 @@ const computeSuggestions = (text, env, suggestionPriority: (s: ResolvedType) =>
|
|||
.sort(([priorityA], [priorityB]) => priorityB - priorityA)
|
||||
}
|
||||
|
||||
export function InputBlock({ state, setState, suggestionPriority, onCancel, addParam }: InputBlockProps) {
|
||||
export function InputBlock({ state, setState, suggestionPriority, onCancel }: InputBlockProps) {
|
||||
const {text, focus} = state;
|
||||
const globalContext = useContext(GlobalContext);
|
||||
const env = useContext(EnvContext);
|
||||
const callContext = useContext(CallContext);
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const [i, setI] = useState(0); // selected suggestion idx
|
||||
|
||||
|
|
@ -121,7 +125,13 @@ export function InputBlock({ state, setState, suggestionPriority, onCancel, addP
|
|||
},
|
||||
" ": (e) => {
|
||||
if (text.length > 0) {
|
||||
addParam(initialEditorState);
|
||||
if (callContext.addParam) {
|
||||
callContext.addParam();
|
||||
}
|
||||
else {
|
||||
const actions = getActions(globalContext, setState);
|
||||
actions.c();
|
||||
}
|
||||
}
|
||||
e.preventDefault();
|
||||
},
|
||||
|
|
@ -129,8 +139,6 @@ export function InputBlock({ state, setState, suggestionPriority, onCancel, addP
|
|||
|
||||
return <Input
|
||||
placeholder="<name or literal>"
|
||||
focus={focus}
|
||||
setFocus={focus => setState(state => ({...state, focus}))}
|
||||
onCancel={onCancel}
|
||||
onEnter={onSelectSuggestion}
|
||||
onTextChange={onTextChange}
|
||||
|
|
@ -138,12 +146,12 @@ export function InputBlock({ state, setState, suggestionPriority, onCancel, addP
|
|||
suggestion={singleSuggestion}
|
||||
extraHandlers={extraHandlers}
|
||||
>
|
||||
{focus && <span className="suggestionsPlaceholder">
|
||||
<span className="suggestionsPlaceholder">
|
||||
<Suggestions
|
||||
suggestions={suggestions}
|
||||
onSelect={onSelectSuggestion}
|
||||
i={i} setI={setI} />
|
||||
</span>}
|
||||
</span>
|
||||
</Input>
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue