diff --git a/src/App.tsx b/src/App.tsx
index ff8a0bd..eb3cc95 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -1,12 +1,12 @@
import React from "react";
-import Editor from "./Editor";
+import Explorer from "./Explorer";
import styles from "./App.module.css";
import "./reset.css";
function App({}) {
return (
-
+
);
}
diff --git a/src/Editor.css b/src/Editor.module.css
similarity index 77%
rename from src/Editor.css
rename to src/Editor.module.css
index bdb9465..b5aa502 100644
--- a/src/Editor.css
+++ b/src/Editor.module.css
@@ -1,13 +1,4 @@
-.Editor {
- display: flex;
- flex-direction: row;
- height: 100%;
- width: 100%;
-}
-
-.Editor-textwrapper {
- flex: 1;
- flex-basis: 0;
+.EditorTextWrapper {
position: relative;
background: white;
font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas,
@@ -17,8 +8,8 @@
text-align: initial;
}
-.Editor-textarea,
-.Editor-underlay {
+.EditorTextArea,
+.EditorUnderlay {
font-family: inherit;
font-weight: inherit;
font-size: inherit;
@@ -28,7 +19,7 @@
line-height: normal;
}
-.Editor-textarea {
+.EditorTextArea {
position: absolute;
top: 0;
bottom: 0;
@@ -43,7 +34,7 @@
outline: none;
}
-.Editor-underlay {
+.EditorUnderlay {
width: 100%;
height: 100%;
pointer-events: none;
@@ -52,7 +43,7 @@
word-wrap: break-word;
overflow-y: scroll;
- .highlighted {
+ .EditorHighlighted {
background: #ffff00;
}
}
diff --git a/src/Editor.module.css.d.ts b/src/Editor.module.css.d.ts
new file mode 100644
index 0000000..930d01a
--- /dev/null
+++ b/src/Editor.module.css.d.ts
@@ -0,0 +1,4 @@
+export const EditorTextWrapper: string;
+export const EditorTextArea: string;
+export const EditorUnderlay: string;
+export const EditorHighlighted: string;
diff --git a/src/Editor.tsx b/src/Editor.tsx
index dff073b..27d3816 100644
--- a/src/Editor.tsx
+++ b/src/Editor.tsx
@@ -1,68 +1,25 @@
-import React, { ReactNode, useEffect, useMemo, useRef, useState } from "react";
-import "./Editor.css";
+import React, { useEffect, useRef } from "react";
import { Highlight } from "./highlight";
import { buildShadow } from "./shadow";
-import OrgAst, { OrgNodeReference } from "./OrgAst";
-import { parse_org } from "../../organic/target/wasm32-unknown-unknown/js/wasm";
+import styles from "./Editor.module.css";
-const default_org_source: string = `* Welcome to the Organic Ast Explorer!
-
-Type your Org [fn:1] source in this text box, and it will be parsed by Organic [fn:2] that has been compiled into wasm and embedded in this page. The resulting AST will be rendered to the right.
-
-In the AST on the right, you can:
-
-1. Click on an AST node to highlight the corresponding portion of the Org source on the left.
-2. Expand/Collapse the children, properties, and standard properties.
-
-* Footnotes
-
-[fn:1] https://orgmode.org/
-
-[fn:2] https://code.fizz.buzz/talexander/organic
-`;
-
-function Editor({ defaultValue = default_org_source }) {
+interface EditorProps {
+ value: string;
+ setValue: Function;
+ highlights: Highlight[];
+ clearHighlights: Function;
+}
+function Editor({
+ value,
+ setValue,
+ highlights,
+ clearHighlights,
+}: EditorProps): React.ReactNode {
function handleChange(event: React.ChangeEvent) {
setValue(event.target.value);
clearHighlights();
}
- const [value, setValue] = useState(defaultValue);
-
- const [highlights, setHighlights] = useState>([]);
-
- const astTree = useMemo(() => {
- const astTree = parse_org(value);
- console.log(JSON.stringify(astTree));
- return astTree;
- }, [value]);
-
- function setHighlight(nodes: OrgNodeReference[]) {
- let new_highlights = nodes.map((node: OrgNodeReference) => {
- return new Highlight(node.start - 1, node.end - 1);
- });
- new_highlights.sort(function (a, b) {
- if (a.start < b.start) return -1;
- if (a.start > b.start) return 1;
- return 0;
- });
- setHighlights(new_highlights);
- }
-
- function addHighlight(start: number, end: number) {
- let new_highlights = [...highlights, new Highlight(start, end)];
- new_highlights.sort(function (a, b) {
- if (a.start < b.start) return -1;
- if (a.start > b.start) return 1;
- return 0;
- });
- setHighlights(new_highlights);
- }
-
- function clearHighlights() {
- setHighlights([]);
- }
-
const textAreaRef = useRef(null);
const shadowRef = useRef(null);
function onTextAreaScroll() {
@@ -78,26 +35,18 @@ function Editor({ defaultValue = default_org_source }) {
}, []);
return (
-
-
-
-
- {buildShadow(highlights, value)}
-
-
-
-
+
+
+ {buildShadow(highlights, value)}
+
+
);
}
diff --git a/src/Explorer.module.css b/src/Explorer.module.css
new file mode 100644
index 0000000..a858ccd
--- /dev/null
+++ b/src/Explorer.module.css
@@ -0,0 +1,11 @@
+.Explorer {
+ display: flex;
+ flex-direction: row;
+ height: 100%;
+ width: 100%;
+
+ > * {
+ flex: 1;
+ flex-basis: 0;
+ }
+}
diff --git a/src/Explorer.module.css.d.ts b/src/Explorer.module.css.d.ts
new file mode 100644
index 0000000..88c9463
--- /dev/null
+++ b/src/Explorer.module.css.d.ts
@@ -0,0 +1 @@
+export const Explorer: string;
diff --git a/src/Explorer.tsx b/src/Explorer.tsx
new file mode 100644
index 0000000..996e557
--- /dev/null
+++ b/src/Explorer.tsx
@@ -0,0 +1,83 @@
+import React, { useMemo, useState } from "react";
+import styles from "./Explorer.module.css";
+import { Highlight } from "./highlight";
+import OrgAst, { OrgNodeReference } from "./OrgAst";
+import { parse_org } from "../../organic/target/wasm32-unknown-unknown/js/wasm";
+import Editor from "./Editor";
+
+const default_org_source: string = `* Welcome to the Organic Ast Explorer!
+
+Type your Org [fn:1] source in this text box, and it will be parsed by Organic [fn:2] that has been compiled into wasm and embedded in this page. The resulting AST will be rendered to the right.
+
+In the AST on the right, you can:
+
+1. Click on an AST node to highlight the corresponding portion of the Org source on the left.
+2. Expand/Collapse the children, properties, and standard properties.
+
+* Footnotes
+
+[fn:1] https://orgmode.org/
+
+[fn:2] https://code.fizz.buzz/talexander/organic
+`;
+
+interface ExplorerProps {
+ defaultValue?: string;
+}
+function Explorer({ defaultValue = default_org_source }: ExplorerProps) {
+ const [value, setValue] = useState(defaultValue);
+
+ const [highlights, setHighlights] = useState>([]);
+
+ const astTree = useMemo(() => {
+ const astTree = parse_org(value);
+ console.log(JSON.stringify(astTree));
+ return astTree;
+ }, [value]);
+
+ function setHighlight(nodes: OrgNodeReference[]) {
+ let new_highlights = nodes.map((node: OrgNodeReference) => {
+ return new Highlight(node.start - 1, node.end - 1);
+ });
+ new_highlights.sort(function (a, b) {
+ if (a.start < b.start) return -1;
+ if (a.start > b.start) return 1;
+ return 0;
+ });
+ setHighlights(new_highlights);
+ }
+
+ function addHighlight(start: number, end: number) {
+ let new_highlights = [...highlights, new Highlight(start, end)];
+ new_highlights.sort(function (a, b) {
+ if (a.start < b.start) return -1;
+ if (a.start > b.start) return 1;
+ return 0;
+ });
+ setHighlights(new_highlights);
+ }
+
+ function clearHighlights() {
+ setHighlights([]);
+ }
+
+
+ return (
+
+
+
+
+ );
+}
+
+export default Explorer;
diff --git a/src/OrgAst.module.css b/src/OrgAst.module.css
index c4c5eb9..7dc10e6 100644
--- a/src/OrgAst.module.css
+++ b/src/OrgAst.module.css
@@ -1,5 +1,4 @@
.OrgAst {
- flex: 1;
background: #eeeeee;
padding: 5px;
overflow: auto;
diff --git a/src/shadow.tsx b/src/shadow.tsx
index a24cf5f..763d7c8 100644
--- a/src/shadow.tsx
+++ b/src/shadow.tsx
@@ -1,5 +1,6 @@
-import React, { ReactNode, useState } from "react";
+import React, { ReactNode } from "react";
import { Highlight } from "./highlight";
+import styles from "./Editor.module.css";
function buildShadow(highlights: Highlight[], text: string): ReactNode[] {
let output: ReactNode[] = [];
@@ -22,7 +23,7 @@ function buildShadow(highlights: Highlight[], text: string): ReactNode[] {
} else if (state == ShadowState.Highlight && !thisCharHighlighted) {
// End the span
output.push(
-
+
{buffer}
,
);
@@ -37,7 +38,7 @@ function buildShadow(highlights: Highlight[], text: string): ReactNode[] {
output.push(buffer);
} else if (state == ShadowState.Highlight) {
output.push(
-
+
{buffer}
,
);