import React, { ReactNode, useState } from "react"; import styles from "./OrgAst.module.css"; import { Fragment } from 'react'; const OrgAst = (props: { setHighlight: Function; clearHighlights: Function; astTree: any, value: string; }) => { const [selectedNode, setSelectedNode] = useState(""); function selectNode(uid: string, start: number, end: number) { props.setHighlight(start, end); setSelectedNode(uid); } if (props.astTree.status !== "success") { return
Error! {props.astTree.content}
; } else { return (
); } }; const OrgAstNode = (props: { selectNode: Function; node: any; uid: string; selectedNode: string; }) => { function selectNode() { props.selectNode( props.uid, props.node["standard-properties"]["begin"] - 1, props.node["standard-properties"]["end"] - 1, ); } const nodeClassName = props.selectedNode === props.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"]}
{!!Object.keys(props.node.properties).length ? ( <>
Properties
) : null } {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) => { const uid = props.parentUniqueId + "_" + node["ast-node"] + "/" + node["standard-properties"]["begin"] + "/" + node["standard-properties"]["end"] + "#"; return ( ); }); }; const OrgPropertiesList = (props: { selectNode: Function; parentUniqueId: string; selectedNode: string; properties: Object; }): React.JSX.Element => { const entries = Object.entries(props.properties).map(([key, value]) => { return (
{key}
{JSON.stringify(value)}
); }); return (
{entries}
); }; export default OrgAst;