greatly simplified app
This commit is contained in:
parent
9c0c2dab90
commit
35d1034c67
8 changed files with 156 additions and 204 deletions
|
|
@ -21,7 +21,6 @@ export type EditorState =
|
|||
|
||||
interface EditorProps extends State2Props<EditorState> {
|
||||
filter: (suggestion: [string, Dynamic]) => boolean;
|
||||
onResolve: (state: EditorState) => void;
|
||||
onCancel: () => void;
|
||||
}
|
||||
|
||||
|
|
@ -52,7 +51,7 @@ function removeFocus(state: EditorState): EditorState {
|
|||
return state;
|
||||
}
|
||||
|
||||
export function Editor({state, setState, onResolve, onCancel, filter}: EditorProps) {
|
||||
export function Editor({state, setState, onCancel, filter}: EditorProps) {
|
||||
const [needCommand, setNeedCommand] = useState(false);
|
||||
const commandInputRef = useRef<HTMLInputElement>(null);
|
||||
useEffect(() => {
|
||||
|
|
@ -60,21 +59,21 @@ export function Editor({state, setState, onResolve, onCancel, filter}: EditorPro
|
|||
commandInputRef.current?.focus();
|
||||
}
|
||||
}, [needCommand]);
|
||||
const onMyResolve = (editorState: EditorState) => {
|
||||
setState(editorState);
|
||||
onResolve(editorState);
|
||||
return;
|
||||
// const onMyResolve = (editorState: EditorState) => {
|
||||
// setState(editorState);
|
||||
// onResolve(editorState);
|
||||
// return;
|
||||
|
||||
|
||||
if (editorState.resolved) {
|
||||
setNeedCommand(true);
|
||||
}
|
||||
else {
|
||||
// unresolved
|
||||
setNeedCommand(false);
|
||||
onResolve(editorState); // pass up the fact that we're unresolved
|
||||
}
|
||||
}
|
||||
// if (editorState.resolved) {
|
||||
// setNeedCommand(true);
|
||||
// }
|
||||
// else {
|
||||
// // unresolved
|
||||
// setNeedCommand(false);
|
||||
// onResolve(editorState); // pass up the fact that we're unresolved
|
||||
// }
|
||||
// }
|
||||
|
||||
const globalContext = useContext(CommandContext);
|
||||
const onCommand = (e: React.KeyboardEvent) => {
|
||||
|
|
@ -88,7 +87,7 @@ export function Editor({state, setState, onResolve, onCancel, filter}: EditorPro
|
|||
setNeedCommand(false);
|
||||
// u -> pass Up
|
||||
if (e.key === "e" || e.key === "Enter" || e.key === "Tab" && !e.shiftKey) {
|
||||
onResolve(state);
|
||||
// onResolve(state);
|
||||
globalContext?.doHighlight.eval();
|
||||
return;
|
||||
}
|
||||
|
|
@ -99,12 +98,12 @@ export function Editor({state, setState, onResolve, onCancel, filter}: EditorPro
|
|||
// c -> Call
|
||||
if (e.key === "c") {
|
||||
// we become CallBlock
|
||||
setState({
|
||||
setState(state => ({
|
||||
kind: "call",
|
||||
fn: removeFocus(state),
|
||||
input: initialEditorState,
|
||||
resolved: undefined,
|
||||
});
|
||||
}));
|
||||
globalContext?.doHighlight.call();
|
||||
// focusNextElement();
|
||||
return;
|
||||
|
|
@ -112,12 +111,12 @@ export function Editor({state, setState, onResolve, onCancel, filter}: EditorPro
|
|||
// t -> Transform
|
||||
if (e.key === "t" || e.key === ".") {
|
||||
// we become CallBlock
|
||||
setState({
|
||||
setState(state => ({
|
||||
kind: "call",
|
||||
fn: initialEditorState,
|
||||
input: removeFocus(state),
|
||||
resolved: undefined,
|
||||
});
|
||||
}));
|
||||
globalContext?.doHighlight.transform();
|
||||
return;
|
||||
}
|
||||
|
|
@ -133,13 +132,13 @@ export function Editor({state, setState, onResolve, onCancel, filter}: EditorPro
|
|||
// = -> assign to name
|
||||
if (e.key === 'l' || e.key === '=') {
|
||||
// we become LetInBlock
|
||||
setState({
|
||||
setState(state => ({
|
||||
kind: "let",
|
||||
inner: removeFocus(initialEditorState),
|
||||
name: "",
|
||||
value: removeFocus(state),
|
||||
resolved: undefined,
|
||||
});
|
||||
}));
|
||||
globalContext?.doHighlight.let();
|
||||
return;
|
||||
}
|
||||
|
|
@ -150,22 +149,19 @@ export function Editor({state, setState, onResolve, onCancel, filter}: EditorPro
|
|||
case "input":
|
||||
return <InputBlock
|
||||
state={state}
|
||||
setState={setState}
|
||||
setState={setState as (callback:(p:InputBlockState)=>EditorState)=>void}
|
||||
filter={filter}
|
||||
onResolve={onMyResolve}
|
||||
onCancel={onCancel}
|
||||
/>;
|
||||
case "call":
|
||||
return <CallBlock
|
||||
state={state}
|
||||
setState={setState}
|
||||
onResolve={onMyResolve}
|
||||
setState={setState as (callback:(p:CallBlockState)=>EditorState)=>void}
|
||||
/>;
|
||||
case "let":
|
||||
return <LetInBlock
|
||||
state={state}
|
||||
setState={setState}
|
||||
onResolve={() => {}}
|
||||
setState={setState as (callback:(p:LetInBlockState)=>EditorState)=>void}
|
||||
/>;
|
||||
case "lambda":
|
||||
return <></>;
|
||||
|
|
@ -174,7 +170,7 @@ export function Editor({state, setState, onResolve, onCancel, filter}: EditorPro
|
|||
return <>
|
||||
{renderBlock()}
|
||||
{
|
||||
(state.resolved)
|
||||
(state.resolved && !(state.resolved instanceof Error))
|
||||
? <div className="typeSignature">
|
||||
:: <Type type={getType(state.resolved)} />
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue