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: { setHighlight: Function; clearHighlights: Function; value: string; }) => { const ast_tree = parse_org(props.value); console.log(JSON.stringify(ast_tree)); const [selectedNode, setSelectedNode] = useState(""); function selectNode(uid: string, start: number, end: number) { props.setHighlight(start, end); setSelectedNode(uid); } if (ast_tree.status !== "success") { return
Error! {ast_tree.content}
; } else { return (
); } }; const OrgAstNode = (props: { selectNode: Function; node: any; parentUniqueId: string; selectedNode: string; }) => { const uid = props.parentUniqueId + "_" + props.node["ast-node"] + "/" + props.node["standard-properties"]["begin"] + "/" + props.node["standard-properties"]["end"] + "#"; function selectNode() { props.selectNode( uid, props.node["standard-properties"]["begin"] - 1, props.node["standard-properties"]["end"] - 1, ); } const nodeClassName = props.selectedNode === uid ? styles.OrgAstNode + " " + styles.selected : styles.OrgAstNode; return (
{props.node["ast-node"]}
Standard Properties
begin
{props.node["standard-properties"]["begin"]}
contents-begin
{props.node["standard-properties"]["contents-begin"]}
contents-end
{props.node["standard-properties"]["contents-end"]}
end
{props.node["standard-properties"]["end"]}
post-blank
{props.node["standard-properties"]["post-blank"]}
{Array.isArray(props.node.children) && props.node.children.length > 0 ? (
Children
) : null}
); }; const OrgAstNodeList = (props: { selectNode: Function; parentUniqueId: string; selectedNode: string; node_list: any[]; }): React.JSX.Element[] => { return props.node_list.map((node) => { return ( ); }); }; export default OrgAst;