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
{!!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) .sort((a, b) => { if (a[0] < b[0]) { return -1; } else if (a[0] > b[0]) { return 1; } else { return 0; } }) .filter((entry) => { return !(is_object(entry[1]) && entry[1]["noop"] == "Noop"); }) .map(([key, value]) => { return ( {key}: ); }); return ( {entries}
); }; const OrgPropertyValue = (props: { selectNode: Function; parentUniqueId: string; selectedNode: string; value: any; }): React.ReactNode => { return JSON.stringify(props.value); }; function is_object(val: any): boolean { return val instanceof Object && !(val instanceof Array); } export default OrgAst;