Start rendering the Org Ast.

This commit is contained in:
Tom Alexander 2024-01-23 21:27:12 -05:00
parent c419a41998
commit 6901541fe4
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
6 changed files with 48 additions and 11 deletions

View File

@ -43,11 +43,6 @@
outline: none; outline: none;
} }
.Editor-ast {
flex: 1;
background: green;
}
.Editor-underlay { .Editor-underlay {
width: 100%; width: 100%;
height: 100%; height: 100%;

View File

@ -2,10 +2,10 @@ import React, { ReactNode, useState } from "react";
import "./Editor.css"; import "./Editor.css";
import { Highlight } from "./highlight"; import { Highlight } from "./highlight";
import { buildShadow } from "./shadow"; import { buildShadow } from "./shadow";
import OrgAst from "./OrgAst";
function Editor({ defaultValue = "I have a text value." }) { function Editor({ defaultValue = "I have a text value." }) {
function handleChange(event: React.ChangeEvent<HTMLTextAreaElement>) { function handleChange(event: React.ChangeEvent<HTMLTextAreaElement>) {
console.log(event.target.value);
setValue(event.target.value); setValue(event.target.value);
} }
@ -41,7 +41,7 @@ function Editor({ defaultValue = "I have a text value." }) {
/> />
<div className="Editor-underlay">{buildShadow(highlights, value)}</div> <div className="Editor-underlay">{buildShadow(highlights, value)}</div>
</div> </div>
<div className="Editor-ast"></div> <OrgAst addHighlight={addHighlight} value={value} />
</div> </div>
); );
} }

10
src/OrgAst.module.css Normal file
View File

@ -0,0 +1,10 @@
.OrgAst {
flex: 1;
background: green;
}
.OrgAstNode {
}
.OrgAstNodeType {
}

3
src/OrgAst.module.css.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
export const OrgAst: string;
export const OrgAstNode: string;
export const OrgAstNodeType: string;

32
src/OrgAst.tsx Normal file
View File

@ -0,0 +1,32 @@
import React, { ReactNode, useState } from "react";
import {
parse_org,
} from "../../organic/target/wasm32-unknown-unknown/js/wasm";
import styles from "./OrgAst.module.css";
const OrgAst = (props: {addHighlight: Function, value: string}) => {
console.log(styles);
const ast_tree = parse_org(props.value);
console.log(JSON.stringify(ast_tree));
if (ast_tree.status !== "success") {
return (
<div className={styles.OrgAst}>Error! {ast_tree.content}</div>
);
} else {
return (
<div className={styles.OrgAst}><OrgAstNode node={ast_tree.content}/></div>
);
}
}
const OrgAstNode = (props: {node: any}) => {
return (
<div className={styles.OrgAstNode}>
<div className={styles.OrgAstNodeType}>{props.node["ast-node"]}</div>
</div>
);
}
export default OrgAst;

View File

@ -1,12 +1,9 @@
import React from "react"; import React from "react";
import ReactDOM from "react-dom"; import ReactDOM from "react-dom";
import init, { import init from "../../organic/target/wasm32-unknown-unknown/js/wasm";
parse_org,
} from "../../organic/target/wasm32-unknown-unknown/js/wasm";
import App from "./App"; import App from "./App";
init().then(() => { init().then(() => {
console.log(parse_org("foo"));
ReactDOM.render( ReactDOM.render(
<> <>
<App /> <App />