Move parsing up into the Editor.

This commit is contained in:
Tom Alexander 2024-01-27 14:56:12 -05:00
parent 3fa5ba1546
commit aac0ebe619
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 10 additions and 7 deletions

View File

@ -3,6 +3,7 @@ import "./Editor.css";
import { Highlight } from "./highlight";
import { buildShadow } from "./shadow";
import OrgAst from "./OrgAst";
import { parse_org } from "../../organic/target/wasm32-unknown-unknown/js/wasm";
const default_org_source: string = `Welcome to the Organic Wasm Demo!
@ -48,6 +49,9 @@ function Editor({ defaultValue = default_org_source }) {
setHighlights([]);
}
const astTree = parse_org(value);
console.log(JSON.stringify(astTree));
return (
<div className="Editor">
<div className="Editor-textwrapper">
@ -62,6 +66,7 @@ function Editor({ defaultValue = default_org_source }) {
setHighlight={setHighlight}
clearHighlights={clearHighlights}
value={value}
astTree={astTree}
/>
</div>
);

View File

@ -5,11 +5,9 @@ import styles from "./OrgAst.module.css";
const OrgAst = (props: {
setHighlight: Function;
clearHighlights: Function;
astTree: any,
value: string;
}) => {
const ast_tree = parse_org(props.value);
console.log(JSON.stringify(ast_tree));
const [selectedNode, setSelectedNode] = useState<string>("");
function selectNode(uid: string, start: number, end: number) {
@ -17,14 +15,14 @@ const OrgAst = (props: {
setSelectedNode(uid);
}
if (ast_tree.status !== "success") {
return <div className={styles.OrgAst}>Error! {ast_tree.content}</div>;
if (props.astTree.status !== "success") {
return <div className={styles.OrgAst}>Error! {props.astTree.content}</div>;
} else {
return (
<div className={styles.OrgAst}>
<OrgAstNode
selectNode={selectNode}
node={ast_tree.content}
node={props.astTree.content}
parentUniqueId="^"
selectedNode={selectedNode}
/>
@ -88,7 +86,7 @@ const OrgAstNode = (props: {
<div className={styles.OrgAstChildren}>
<OrgAstNodeList
selectNode={props.selectNode}
parentUniqueId={props.parentUniqueId}
parentUniqueId={uid}
selectedNode={props.selectedNode}
node_list={props.node.children}
/>