Compare commits
29 Commits
e89be0feff
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6db3dc65fa | ||
|
|
43d65b4fe3 | ||
|
|
ff3618b67d | ||
|
|
8c2c48a719 | ||
|
|
43de54039b | ||
|
|
acaf757ce3 | ||
|
|
1cc5dd7911 | ||
|
|
083b0aa376 | ||
|
|
d158fafd77 | ||
|
|
33ed9c4f56 | ||
|
|
a11201363e | ||
|
|
3b3ef70d3b | ||
|
|
6129bdad3e | ||
|
|
f89e62b9e1 | ||
|
|
5d31d50863 | ||
|
|
c2850fa879 | ||
|
|
d5020d3f24 | ||
|
|
e881102ade | ||
|
|
536e364364 | ||
|
|
f60725b341 | ||
|
|
d73f344dd0 | ||
|
|
04b79631d7 | ||
|
|
8f360fda4b | ||
|
|
bb15dbcbaf | ||
|
|
49905f1273 | ||
|
|
cc48040f11 | ||
|
|
8627181480 | ||
|
|
5feac8e4d7 | ||
|
|
0e02e09018 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
/node_modules/
|
||||
/dist/
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
# Getting Started with Create React App
|
||||
|
||||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
||||
|
||||
## Available Scripts
|
||||
|
||||
In the project directory, you can run:
|
||||
|
||||
### `yarn start`
|
||||
|
||||
Runs the app in the development mode.\
|
||||
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
|
||||
|
||||
The page will reload if you make edits.\
|
||||
You will also see any lint errors in the console.
|
||||
|
||||
### `yarn test`
|
||||
|
||||
Launches the test runner in the interactive watch mode.\
|
||||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
||||
|
||||
### `yarn build`
|
||||
|
||||
Builds the app for production to the `build` folder.\
|
||||
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||
|
||||
The build is minified and the filenames include the hashes.\
|
||||
Your app is ready to be deployed!
|
||||
|
||||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
||||
|
||||
### `yarn eject`
|
||||
|
||||
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
|
||||
|
||||
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
||||
|
||||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
|
||||
|
||||
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
|
||||
|
||||
## Learn More
|
||||
|
||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||
|
||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
||||
@@ -1,50 +0,0 @@
|
||||
{
|
||||
"name": "my-app",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@testing-library/jest-dom": "^5.14.1",
|
||||
"@testing-library/react": "^13.0.0",
|
||||
"@testing-library/user-event": "^13.2.1",
|
||||
"@types/jest": "^27.0.1",
|
||||
"@types/node": "^16.7.13",
|
||||
"@types/react": "^18.0.0",
|
||||
"@types/react-dom": "^18.0.0",
|
||||
"organic": "link:../organic/target/wasm32-unknown-unknown/js",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-scripts": "5.0.1",
|
||||
"typescript": "^4.4.2",
|
||||
"web-vitals": "^2.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/plugin-proposal-private-property-in-object": "^7.21.11"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"react-app",
|
||||
"react-app/jest"
|
||||
]
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
},
|
||||
"prettier": {
|
||||
"tabWidth": 2
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.8 KiB |
@@ -1,43 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Web site created using create-react-app"
|
||||
/>
|
||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
||||
<!--
|
||||
manifest.json provides metadata used when your web app is installed on a
|
||||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||
-->
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||
<!--
|
||||
Notice the use of %PUBLIC_URL% in the tags above.
|
||||
It will be replaced with the URL of the `public` folder during the build.
|
||||
Only files inside the `public` folder can be referenced from the HTML.
|
||||
|
||||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
||||
work correctly both with client-side routing and a non-root public URL.
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>React App</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
<!--
|
||||
This HTML file is a template.
|
||||
If you open it directly in the browser, you will see an empty page.
|
||||
|
||||
You can add webfonts, meta tags, or analytics to this file.
|
||||
The build step will place the bundled scripts into the <body> tag.
|
||||
|
||||
To begin the development, run `npm start` or `yarn start`.
|
||||
To create a production bundle, use `npm run build` or `yarn build`.
|
||||
-->
|
||||
</body>
|
||||
</html>
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 5.2 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 9.4 KiB |
@@ -1,25 +0,0 @@
|
||||
{
|
||||
"short_name": "React App",
|
||||
"name": "Create React App Sample",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
},
|
||||
{
|
||||
"src": "logo192.png",
|
||||
"type": "image/png",
|
||||
"sizes": "192x192"
|
||||
},
|
||||
{
|
||||
"src": "logo512.png",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512"
|
||||
}
|
||||
],
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"theme_color": "#000000",
|
||||
"background_color": "#ffffff"
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
# https://www.robotstxt.org/robotstxt.html
|
||||
User-agent: *
|
||||
Disallow:
|
||||
@@ -1,40 +0,0 @@
|
||||
.App {
|
||||
text-align: center;
|
||||
height: 100vh;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.App-logo {
|
||||
height: 40vmin;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: no-preference) {
|
||||
.App-logo {
|
||||
animation: App-logo-spin infinite 20s linear;
|
||||
}
|
||||
}
|
||||
|
||||
.App-header {
|
||||
background-color: #282c34;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: calc(10px + 2vmin);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.App-link {
|
||||
color: #61dafb;
|
||||
}
|
||||
|
||||
@keyframes App-logo-spin {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import React from "react";
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import App from "./App";
|
||||
|
||||
test("renders learn react link", () => {
|
||||
render(<App />);
|
||||
const linkElement = screen.getByText(/learn react/i);
|
||||
expect(linkElement).toBeInTheDocument();
|
||||
});
|
||||
@@ -1,12 +0,0 @@
|
||||
import "./App.css";
|
||||
import Editor from "./Editor";
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<div className="App">
|
||||
<Editor />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
@@ -1,13 +0,0 @@
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
|
||||
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
|
||||
monospace;
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
import React from "react";
|
||||
import ReactDOM from "react-dom/client";
|
||||
import "./index.css";
|
||||
import App from "./App";
|
||||
import reportWebVitals from "./reportWebVitals";
|
||||
|
||||
const root = ReactDOM.createRoot(
|
||||
document.getElementById("root") as HTMLElement,
|
||||
);
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>,
|
||||
);
|
||||
|
||||
// If you want to start measuring performance in your app, pass a function
|
||||
// to log results (for example: reportWebVitals(console.log))
|
||||
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
||||
reportWebVitals();
|
||||
@@ -1 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>
|
||||
|
Before Width: | Height: | Size: 2.6 KiB |
1
old/src/react-app-env.d.ts
vendored
1
old/src/react-app-env.d.ts
vendored
@@ -1 +0,0 @@
|
||||
/// <reference types="react-scripts" />
|
||||
@@ -1,15 +0,0 @@
|
||||
import { ReportHandler } from "web-vitals";
|
||||
|
||||
const reportWebVitals = (onPerfEntry?: ReportHandler) => {
|
||||
if (onPerfEntry && onPerfEntry instanceof Function) {
|
||||
import("web-vitals").then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
|
||||
getCLS(onPerfEntry);
|
||||
getFID(onPerfEntry);
|
||||
getFCP(onPerfEntry);
|
||||
getLCP(onPerfEntry);
|
||||
getTTFB(onPerfEntry);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export default reportWebVitals;
|
||||
@@ -1,5 +0,0 @@
|
||||
// jest-dom adds custom jest matchers for asserting on DOM nodes.
|
||||
// allows you to do things like:
|
||||
// expect(element).toHaveTextContent(/react/i)
|
||||
// learn more: https://github.com/testing-library/jest-dom
|
||||
import "@testing-library/jest-dom";
|
||||
@@ -1,20 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
},
|
||||
"include": ["src"],
|
||||
}
|
||||
9813
old/yarn.lock
9813
old/yarn.lock
File diff suppressed because it is too large
Load Diff
7
package-lock.json
generated
7
package-lock.json
generated
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "organic_wasm_demo",
|
||||
"name": "organic_ast_explorer",
|
||||
"version": "0.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "organic_wasm_demo",
|
||||
"name": "organic_ast_explorer",
|
||||
"version": "0.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
@@ -28,7 +28,8 @@
|
||||
"typescript": "^5.3.3",
|
||||
"webpack": "^5.89.0",
|
||||
"webpack-cli": "^5.1.4",
|
||||
"webpack-dev-server": "^4.15.1"
|
||||
"webpack-dev-server": "^4.15.1",
|
||||
"webpack-merge": "^5.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@ampproject/remapping": {
|
||||
|
||||
11
package.json
11
package.json
@@ -1,11 +1,13 @@
|
||||
{
|
||||
"name": "organic_wasm_demo",
|
||||
"name": "organic_ast_explorer",
|
||||
"version": "0.0.0",
|
||||
"description": "",
|
||||
"main": "index.jsx",
|
||||
"scripts": {
|
||||
"dev": "webpack server",
|
||||
"format": "prettier --write '**/*.{json,js,ts,tsx,css}'"
|
||||
"dev": "webpack server --config webpack.dev.js",
|
||||
"format": "prettier --write '**/*.{json,js,ts,tsx,css}'",
|
||||
"build": "webpack --config webpack.dev.js",
|
||||
"release": "webpack --config webpack.prd.js"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
@@ -30,6 +32,7 @@
|
||||
"typescript": "^5.3.3",
|
||||
"webpack": "^5.89.0",
|
||||
"webpack-cli": "^5.1.4",
|
||||
"webpack-dev-server": "^4.15.1"
|
||||
"webpack-dev-server": "^4.15.1",
|
||||
"webpack-merge": "^5.10.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Organic Wasm Demo</title>
|
||||
<title>Organic Ast Explorer</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
@@ -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 (
|
||||
<div className={styles.App}>
|
||||
<Editor />
|
||||
<Explorer />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
.Editor {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
.EditorTextWrapper {
|
||||
--editor-background-color: #000000;
|
||||
--editor-font-color: #ffffff;
|
||||
--editor-highlight-color: #0000ff;
|
||||
}
|
||||
@media (prefers-color-scheme: light) {
|
||||
.EditorTextWrapper {
|
||||
--editor-background-color: #ffffff;
|
||||
--editor-font-color: #000000;
|
||||
--editor-highlight-color: #ffff00;
|
||||
}
|
||||
}
|
||||
|
||||
.Editor-textwrapper {
|
||||
flex: 1;
|
||||
flex-basis: 0;
|
||||
.EditorTextWrapper {
|
||||
position: relative;
|
||||
background: white;
|
||||
background: var(--editor-background-color);
|
||||
font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas,
|
||||
"DejaVu Sans Mono", monospace;
|
||||
font-weight: normal;
|
||||
@@ -17,8 +21,9 @@
|
||||
text-align: initial;
|
||||
}
|
||||
|
||||
.Editor-textarea,
|
||||
.Editor-underlay {
|
||||
.EditorTextArea,
|
||||
.EditorUnderlay {
|
||||
color: var(--editor-font-color);
|
||||
font-family: inherit;
|
||||
font-weight: inherit;
|
||||
font-size: inherit;
|
||||
@@ -28,7 +33,7 @@
|
||||
line-height: normal;
|
||||
}
|
||||
|
||||
.Editor-textarea {
|
||||
.EditorTextArea {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
@@ -43,14 +48,16 @@
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.Editor-underlay {
|
||||
.EditorUnderlay {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
pointer-events: none;
|
||||
color: transparent;
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
overflow-y: scroll;
|
||||
|
||||
.highlighted {
|
||||
background: #ffff00;
|
||||
.EditorHighlighted {
|
||||
background: var(--editor-highlight-color);
|
||||
}
|
||||
}
|
||||
4
src/Editor.module.css.d.ts
vendored
Normal file
4
src/Editor.module.css.d.ts
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
export const EditorTextWrapper: string;
|
||||
export const EditorTextArea: string;
|
||||
export const EditorUnderlay: string;
|
||||
export const EditorHighlighted: string;
|
||||
@@ -1,74 +1,53 @@
|
||||
import React, { ReactNode, useState } from "react";
|
||||
import "./Editor.css";
|
||||
import React, { useEffect, useRef } from "react";
|
||||
import { Highlight } from "./highlight";
|
||||
import { buildShadow } from "./shadow";
|
||||
import OrgAst 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 Wasm Demo!
|
||||
|
||||
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<HTMLTextAreaElement>) {
|
||||
setValue(event.target.value);
|
||||
clearHighlights();
|
||||
}
|
||||
|
||||
const [value, setValue] = useState(defaultValue);
|
||||
|
||||
const [highlights, setHighlights] = useState<Array<Highlight>>([]);
|
||||
|
||||
function setHighlight(start: number, end: number) {
|
||||
let new_highlights = [new Highlight(start, end)];
|
||||
setHighlights(new_highlights);
|
||||
const textAreaRef = useRef<HTMLTextAreaElement>(null);
|
||||
const shadowRef = useRef<HTMLDivElement>(null);
|
||||
function onTextAreaScroll() {
|
||||
if (shadowRef.current !== null && textAreaRef.current !== null) {
|
||||
const textAreaScrollTop = textAreaRef.current.scrollTop;
|
||||
shadowRef.current.scrollTop = textAreaScrollTop;
|
||||
}
|
||||
}
|
||||
|
||||
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 astTree = parse_org(value);
|
||||
console.log(JSON.stringify(astTree));
|
||||
useEffect(() => {
|
||||
// Make sure the text area and shadow div start out in sync.
|
||||
onTextAreaScroll();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="Editor">
|
||||
<div className="Editor-textwrapper">
|
||||
<textarea
|
||||
onChange={handleChange}
|
||||
className="Editor-textarea"
|
||||
value={value}
|
||||
/>
|
||||
<div className="Editor-underlay">{buildShadow(highlights, value)}</div>
|
||||
</div>
|
||||
<OrgAst
|
||||
setHighlight={setHighlight}
|
||||
clearHighlights={clearHighlights}
|
||||
<div className={styles.EditorTextWrapper}>
|
||||
<textarea
|
||||
ref={textAreaRef}
|
||||
onChange={handleChange}
|
||||
className={styles.EditorTextArea}
|
||||
value={value}
|
||||
astTree={astTree}
|
||||
onScroll={onTextAreaScroll}
|
||||
spellCheck={false}
|
||||
/>
|
||||
<div ref={shadowRef} className={styles.EditorUnderlay}>
|
||||
{buildShadow(highlights, value)}
|
||||
<br />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
11
src/Explorer.module.css
Normal file
11
src/Explorer.module.css
Normal file
@@ -0,0 +1,11 @@
|
||||
.Explorer {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
|
||||
> * {
|
||||
flex: 1;
|
||||
flex-basis: 0;
|
||||
}
|
||||
}
|
||||
1
src/Explorer.module.css.d.ts
vendored
Normal file
1
src/Explorer.module.css.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export const Explorer: string;
|
||||
82
src/Explorer.tsx
Normal file
82
src/Explorer.tsx
Normal file
@@ -0,0 +1,82 @@
|
||||
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<Array<Highlight>>([]);
|
||||
|
||||
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 (
|
||||
<div className={styles.Explorer}>
|
||||
<Editor
|
||||
value={value}
|
||||
setValue={setValue}
|
||||
highlights={highlights}
|
||||
clearHighlights={clearHighlights}
|
||||
/>
|
||||
<OrgAst
|
||||
setHighlight={setHighlight}
|
||||
clearHighlights={clearHighlights}
|
||||
value={value}
|
||||
astTree={astTree}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Explorer;
|
||||
@@ -1,17 +1,57 @@
|
||||
.OrgAst {
|
||||
flex: 1;
|
||||
background: #eeeeee;
|
||||
--ast-background-color: #111111;
|
||||
--ast-font-color: #ffffff;
|
||||
|
||||
--ast-node-border-color: #bbbbbb;
|
||||
--ast-node-shadow-color: #bbbbbb;
|
||||
|
||||
--ast-node-type-background-color: #933009;
|
||||
--ast-node-type-hover-background-color: #8f0745;
|
||||
--ast-node-type-selected-background-color: #630368;
|
||||
|
||||
--ast-node-subsection-border-color: #ffffff;
|
||||
|
||||
--ast-node-children-background-color: #111111;
|
||||
|
||||
--ast-node-table-row-odd-background-color: #111111;
|
||||
--ast-node-table-row-even-background-color: #000000;
|
||||
}
|
||||
@media (prefers-color-scheme: light) {
|
||||
.OrgAst {
|
||||
--ast-background-color: #eeeeee;
|
||||
--ast-font-color: #000000;
|
||||
|
||||
--ast-node-background-color: #ffffff;
|
||||
--ast-node-border-color: #000000;
|
||||
--ast-node-shadow-color: #000000;
|
||||
|
||||
--ast-node-type-background-color: #6ccff6;
|
||||
--ast-node-type-hover-background-color: #70f8ba;
|
||||
--ast-node-type-selected-background-color: #9cfc97;
|
||||
|
||||
--ast-node-subsection-border-color: #000000;
|
||||
|
||||
--ast-node-children-background-color: #eeeeee;
|
||||
|
||||
--ast-node-table-row-odd-background-color: #eeeeee;
|
||||
--ast-node-table-row-even-background-color: #ffffff;
|
||||
}
|
||||
}
|
||||
|
||||
.OrgAst {
|
||||
background: var(--ast-background-color);
|
||||
color: var(--ast-font-color);
|
||||
padding: 5px;
|
||||
overflow: scroll;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.OrgAstNode {
|
||||
border: 1px solid #000000;
|
||||
background: #ffffff;
|
||||
box-shadow: 3px 3px 4px #000000;
|
||||
border: 1px solid var(--ast-node-border-color);
|
||||
background: var(--ast-node-background-color);
|
||||
box-shadow: -3px 3px 1px var(--ast-node-shadow-color);
|
||||
|
||||
> details {
|
||||
border: 1px solid #000000;
|
||||
border: 1px solid var(--ast-node-subsection-border-color);
|
||||
margin: 5px 5px 5px 2px;
|
||||
|
||||
> summary {
|
||||
@@ -24,39 +64,61 @@
|
||||
> summary {
|
||||
border-width: 0 0 1px 0;
|
||||
border-style: dotted;
|
||||
border-color: #000000;
|
||||
border-color: var(--ast-node-subsection-border-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.OrgAstNode.selected {
|
||||
> .OrgAstNodeType {
|
||||
background: #9cfc97;
|
||||
background: var(--ast-node-type-selected-background-color);
|
||||
}
|
||||
}
|
||||
|
||||
.OrgAstNode.hovered:not(.selected) {
|
||||
> .OrgAstNodeType {
|
||||
background: var(--ast-node-type-hover-background-color);
|
||||
}
|
||||
}
|
||||
|
||||
.OrgAstNodeType {
|
||||
font-size: 1.3rem;
|
||||
font-weight: 700;
|
||||
background: #6ccff6;
|
||||
background: var(--ast-node-type-background-color);
|
||||
padding: 3px;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
|
||||
> span:first-child {
|
||||
font-size: 1.1rem;
|
||||
font-weight: 700;
|
||||
white-space: nowrap;
|
||||
}
|
||||
> span:nth-child(2) {
|
||||
margin-left: 1rem;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo,
|
||||
Consolas, "DejaVu Sans Mono", monospace;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
}
|
||||
|
||||
.OrgAstChildren {
|
||||
padding: 5px 5px 5px 20px;
|
||||
background: #eeeeee;
|
||||
background: var(--ast-node-children-background-color);
|
||||
}
|
||||
|
||||
.OrgAstProperties,
|
||||
.OrgAstObjectTree {
|
||||
border: 1px solid #000000;
|
||||
.OrgAstObjectTree,
|
||||
.OrgAstOptionalPair {
|
||||
border: 1px solid var(--ast-node-subsection-border-color);
|
||||
margin: 5px;
|
||||
|
||||
> tbody {
|
||||
> tr {
|
||||
border-width: 1px 0;
|
||||
border-style: solid;
|
||||
border-color: #000000;
|
||||
border-color: var(--ast-node-subsection-border-color);
|
||||
|
||||
> th,
|
||||
> td {
|
||||
@@ -71,10 +133,10 @@
|
||||
}
|
||||
|
||||
> tr:nth-child(odd) {
|
||||
background-color: #eeeeee;
|
||||
background-color: var(--ast-node-table-row-odd-background-color);
|
||||
}
|
||||
> tr:nth-child(even) {
|
||||
background-color: #ffffff;
|
||||
background-color: var(--ast-node-table-row-even-background-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,7 +144,7 @@
|
||||
.OrgAstObjectTree {
|
||||
> tbody {
|
||||
border-style: dashed;
|
||||
border-color: #000000;
|
||||
border-color: var(--ast-node-subsection-border-color);
|
||||
}
|
||||
> tbody:not(:first-child, :last-child) {
|
||||
border-width: 3px 0;
|
||||
|
||||
2
src/OrgAst.module.css.d.ts
vendored
2
src/OrgAst.module.css.d.ts
vendored
@@ -3,5 +3,7 @@ export const OrgAstNode: string;
|
||||
export const OrgAstNodeType: string;
|
||||
export const OrgAstChildren: string;
|
||||
export const selected: string;
|
||||
export const hovered: string;
|
||||
export const OrgAstProperties: string;
|
||||
export const OrgAstObjectTree: string;
|
||||
export const OrgAstOptionalPair: string;
|
||||
|
||||
201
src/OrgAst.tsx
201
src/OrgAst.tsx
@@ -8,11 +8,36 @@ const OrgAst = (props: {
|
||||
astTree: any;
|
||||
value: string;
|
||||
}) => {
|
||||
const [selectedNode, setSelectedNode] = useState<string>("");
|
||||
const [selectedNode, setSelectedNode] = useState<OrgNodeReference | null>(
|
||||
null,
|
||||
);
|
||||
const [hoveredNode, setHoveredNode] = useState<OrgNodeReference | null>(null);
|
||||
|
||||
function selectNode(uid: string, start: number, end: number) {
|
||||
props.setHighlight(start, end);
|
||||
setSelectedNode(uid);
|
||||
if (selectedNode !== null && selectedNode.uid === uid) {
|
||||
props.setHighlight([]);
|
||||
setSelectedNode(null);
|
||||
setHoveredNode(null);
|
||||
} else {
|
||||
const new_node: OrgNodeReference = { uid: uid, start: start, end: end };
|
||||
props.setHighlight(
|
||||
[new_node, hoveredNode].filter((node) => node !== null),
|
||||
);
|
||||
setSelectedNode({ uid: uid, start: start, end: end });
|
||||
}
|
||||
}
|
||||
|
||||
function startHoverNode(uid: string, start: number, end: number) {
|
||||
const new_node: OrgNodeReference = { uid: uid, start: start, end: end };
|
||||
props.setHighlight(
|
||||
[selectedNode, new_node].filter((node) => node !== null),
|
||||
);
|
||||
setHoveredNode({ uid: uid, start: start, end: end });
|
||||
}
|
||||
|
||||
function endHoverNode(uid: string) {
|
||||
props.setHighlight([selectedNode].filter((node) => node !== null));
|
||||
setHoveredNode(null);
|
||||
}
|
||||
|
||||
if (props.astTree.status !== "success") {
|
||||
@@ -24,45 +49,127 @@ const OrgAst = (props: {
|
||||
key="^"
|
||||
uid="^"
|
||||
selectNode={selectNode}
|
||||
startHoverNode={startHoverNode}
|
||||
endHoverNode={endHoverNode}
|
||||
node={props.astTree.content}
|
||||
selectedNode={selectedNode}
|
||||
fullSource={props.value}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
interface OrgNodeReference {
|
||||
uid: string;
|
||||
start: number;
|
||||
end: number;
|
||||
}
|
||||
|
||||
const OrgAstNode = (props: {
|
||||
selectNode: Function;
|
||||
startHoverNode: Function;
|
||||
endHoverNode: Function;
|
||||
node: any;
|
||||
uid: string;
|
||||
selectedNode: string;
|
||||
selectedNode: OrgNodeReference | null;
|
||||
fullSource: string;
|
||||
}) => {
|
||||
const [isHovered, setIsHovered] = useState(false);
|
||||
|
||||
function selectNode() {
|
||||
props.selectNode(
|
||||
props.uid,
|
||||
props.node["standard-properties"]["begin"] - 1,
|
||||
props.node["standard-properties"]["end"] - 1,
|
||||
props.node["standard-properties"]["begin"],
|
||||
props.node["standard-properties"]["end"],
|
||||
);
|
||||
}
|
||||
|
||||
const nodeClassName =
|
||||
props.selectedNode === props.uid
|
||||
? styles.OrgAstNode + " " + styles.selected
|
||||
: styles.OrgAstNode;
|
||||
function hoverNode() {
|
||||
props.startHoverNode(
|
||||
props.uid,
|
||||
props.node["standard-properties"]["begin"],
|
||||
props.node["standard-properties"]["end"],
|
||||
);
|
||||
setIsHovered(true);
|
||||
}
|
||||
|
||||
function endHoverNode() {
|
||||
props.endHoverNode(props.uid);
|
||||
setIsHovered(false);
|
||||
}
|
||||
|
||||
function unicodeAwareSlice(text: string, start: number, end: number) {
|
||||
// Boooo javascript
|
||||
let i = 0;
|
||||
let output = "";
|
||||
for (const chr of text) {
|
||||
if (i >= end) {
|
||||
break;
|
||||
}
|
||||
if (i >= start) {
|
||||
output += chr;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
let nodeClassName = styles.OrgAstNode;
|
||||
if (props.selectedNode?.uid === props.uid) {
|
||||
nodeClassName = nodeClassName + " " + styles.selected;
|
||||
}
|
||||
if (isHovered) {
|
||||
nodeClassName = nodeClassName + " " + styles.hovered;
|
||||
}
|
||||
|
||||
const selfSource = JSON.stringify(
|
||||
unicodeAwareSlice(
|
||||
props.fullSource,
|
||||
props.node["standard-properties"].begin - 1,
|
||||
props.node["standard-properties"].end - 1,
|
||||
),
|
||||
);
|
||||
|
||||
if (props.node["ast-node"] === "plain-text") {
|
||||
return (
|
||||
<div className={nodeClassName}>
|
||||
<div
|
||||
className={styles.OrgAstNodeType}
|
||||
onClick={selectNode}
|
||||
onMouseEnter={hoverNode}
|
||||
onMouseLeave={endHoverNode}
|
||||
title={selfSource}
|
||||
>
|
||||
<span>{props.node["ast-node"]}</span>
|
||||
<span>{selfSource}</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={nodeClassName}>
|
||||
<div className={styles.OrgAstNodeType} onClick={selectNode}>
|
||||
{props.node["ast-node"]}
|
||||
<div
|
||||
className={styles.OrgAstNodeType}
|
||||
onClick={selectNode}
|
||||
onMouseEnter={hoverNode}
|
||||
onMouseLeave={endHoverNode}
|
||||
title={selfSource}
|
||||
>
|
||||
<span>{props.node["ast-node"]}</span>
|
||||
<span>{selfSource}</span>
|
||||
</div>
|
||||
<details>
|
||||
<summary>Standard Properties</summary>
|
||||
<OrgPropertiesList
|
||||
selectNode={props.selectNode}
|
||||
startHoverNode={props.startHoverNode}
|
||||
endHoverNode={props.endHoverNode}
|
||||
parentUniqueId={props.uid}
|
||||
selectedNode={props.selectedNode}
|
||||
properties={props.node["standard-properties"]}
|
||||
fullSource={props.fullSource}
|
||||
/>
|
||||
</details>
|
||||
{!!Object.keys(props.node.properties).length ? (
|
||||
@@ -71,9 +178,12 @@ const OrgAstNode = (props: {
|
||||
<summary>Properties</summary>
|
||||
<OrgPropertiesList
|
||||
selectNode={props.selectNode}
|
||||
startHoverNode={props.startHoverNode}
|
||||
endHoverNode={props.endHoverNode}
|
||||
parentUniqueId={props.uid}
|
||||
selectedNode={props.selectedNode}
|
||||
properties={props.node.properties}
|
||||
fullSource={props.fullSource}
|
||||
/>
|
||||
</details>
|
||||
</>
|
||||
@@ -84,9 +194,12 @@ const OrgAstNode = (props: {
|
||||
<div className={styles.OrgAstChildren}>
|
||||
<OrgAstNodeList
|
||||
selectNode={props.selectNode}
|
||||
startHoverNode={props.startHoverNode}
|
||||
endHoverNode={props.endHoverNode}
|
||||
parentUniqueId={props.uid}
|
||||
selectedNode={props.selectedNode}
|
||||
node_list={props.node.children}
|
||||
fullSource={props.fullSource}
|
||||
/>
|
||||
</div>
|
||||
</details>
|
||||
@@ -97,9 +210,12 @@ const OrgAstNode = (props: {
|
||||
|
||||
const OrgAstNodeList = (props: {
|
||||
selectNode: Function;
|
||||
startHoverNode: Function;
|
||||
endHoverNode: Function;
|
||||
parentUniqueId: string;
|
||||
selectedNode: string;
|
||||
selectedNode: OrgNodeReference | null;
|
||||
node_list: any[];
|
||||
fullSource: string;
|
||||
}): React.JSX.Element[] => {
|
||||
return props.node_list.map((node) => {
|
||||
const uid =
|
||||
@@ -116,8 +232,11 @@ const OrgAstNodeList = (props: {
|
||||
key={uid}
|
||||
uid={uid}
|
||||
selectNode={props.selectNode}
|
||||
startHoverNode={props.startHoverNode}
|
||||
endHoverNode={props.endHoverNode}
|
||||
selectedNode={props.selectedNode}
|
||||
node={node}
|
||||
fullSource={props.fullSource}
|
||||
/>
|
||||
);
|
||||
});
|
||||
@@ -125,9 +244,12 @@ const OrgAstNodeList = (props: {
|
||||
|
||||
const OrgPropertiesList = (props: {
|
||||
selectNode: Function;
|
||||
startHoverNode: Function;
|
||||
endHoverNode: Function;
|
||||
parentUniqueId: string;
|
||||
selectedNode: string;
|
||||
selectedNode: OrgNodeReference | null;
|
||||
properties: Object;
|
||||
fullSource: string;
|
||||
}): React.JSX.Element => {
|
||||
const entries = Object.entries(props.properties)
|
||||
.sort((a, b) => {
|
||||
@@ -150,9 +272,12 @@ const OrgPropertiesList = (props: {
|
||||
<td>
|
||||
<OrgPropertyValue
|
||||
selectNode={props.selectNode}
|
||||
startHoverNode={props.startHoverNode}
|
||||
endHoverNode={props.endHoverNode}
|
||||
parentUniqueId={props.parentUniqueId}
|
||||
selectedNode={props.selectedNode}
|
||||
value={value}
|
||||
fullSource={props.fullSource}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -168,9 +293,12 @@ const OrgPropertiesList = (props: {
|
||||
|
||||
const OrgPropertyValue = (props: {
|
||||
selectNode: Function;
|
||||
startHoverNode: Function;
|
||||
endHoverNode: Function;
|
||||
parentUniqueId: string;
|
||||
selectedNode: string;
|
||||
selectedNode: OrgNodeReference | null;
|
||||
value: any;
|
||||
fullSource: string;
|
||||
}): React.ReactNode => {
|
||||
if (
|
||||
props.value === null ||
|
||||
@@ -183,19 +311,40 @@ const OrgPropertyValue = (props: {
|
||||
<div className={styles.OrgAstChildren}>
|
||||
<OrgAstNodeList
|
||||
selectNode={props.selectNode}
|
||||
startHoverNode={props.startHoverNode}
|
||||
endHoverNode={props.endHoverNode}
|
||||
parentUniqueId={props.parentUniqueId}
|
||||
selectedNode={props.selectedNode}
|
||||
node_list={props.value}
|
||||
fullSource={props.fullSource}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
} else if (is_optional_pair(props.value)) {
|
||||
return (
|
||||
<table className={styles.OrgAstOptionalPair}>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row">Optional value:</th>
|
||||
<td>{JSON.stringify(props.value.optval)}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Value:</th>
|
||||
<td>{JSON.stringify(props.value.val)}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
} else if (is_object_tree(props.value)) {
|
||||
return (
|
||||
<OrgObjectTree
|
||||
selectNode={props.selectNode}
|
||||
startHoverNode={props.startHoverNode}
|
||||
endHoverNode={props.endHoverNode}
|
||||
parentUniqueId={props.parentUniqueId}
|
||||
selectedNode={props.selectedNode}
|
||||
value={props.value}
|
||||
fullSource={props.fullSource}
|
||||
/>
|
||||
);
|
||||
} else {
|
||||
@@ -205,16 +354,22 @@ const OrgPropertyValue = (props: {
|
||||
|
||||
interface OrgObjectTreeProps {
|
||||
selectNode: Function;
|
||||
startHoverNode: Function;
|
||||
endHoverNode: Function;
|
||||
parentUniqueId: string;
|
||||
selectedNode: string;
|
||||
selectedNode: OrgNodeReference | null;
|
||||
value: any;
|
||||
fullSource: string;
|
||||
}
|
||||
|
||||
function OrgObjectTree({
|
||||
selectNode,
|
||||
startHoverNode,
|
||||
endHoverNode,
|
||||
parentUniqueId,
|
||||
selectedNode,
|
||||
value,
|
||||
fullSource,
|
||||
}: OrgObjectTreeProps): React.ReactNode {
|
||||
const entries = value["object-tree"].map((entry: any) => {
|
||||
return (
|
||||
@@ -224,9 +379,12 @@ function OrgObjectTree({
|
||||
<td>
|
||||
<OrgAstNodeList
|
||||
selectNode={selectNode}
|
||||
startHoverNode={startHoverNode}
|
||||
endHoverNode={endHoverNode}
|
||||
parentUniqueId={parentUniqueId}
|
||||
selectedNode={selectedNode}
|
||||
node_list={entry[0]}
|
||||
fullSource={fullSource}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -235,9 +393,12 @@ function OrgObjectTree({
|
||||
<td>
|
||||
<OrgAstNodeList
|
||||
selectNode={selectNode}
|
||||
startHoverNode={startHoverNode}
|
||||
endHoverNode={endHoverNode}
|
||||
parentUniqueId={parentUniqueId}
|
||||
selectedNode={selectedNode}
|
||||
node_list={entry[1]}
|
||||
fullSource={fullSource}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -271,8 +432,14 @@ function is_list_of_ast_nodes(val: any): boolean {
|
||||
});
|
||||
}
|
||||
|
||||
function is_optional_pair(val: any): boolean {
|
||||
return (
|
||||
is_object(val) && val.hasOwnProperty("optval") && val.hasOwnProperty("val")
|
||||
);
|
||||
}
|
||||
|
||||
function is_object_tree(val: any): boolean {
|
||||
return is_object(val) && val.hasOwnProperty("object-tree");
|
||||
}
|
||||
|
||||
export default OrgAst;
|
||||
export { OrgAst as default, OrgNodeReference };
|
||||
|
||||
@@ -1,37 +1,34 @@
|
||||
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 remaining_highlights = highlights.slice();
|
||||
let output: ReactNode[] = [];
|
||||
let i = 0;
|
||||
let state = ShadowState.Text;
|
||||
let buffer = "";
|
||||
for (let chr of text) {
|
||||
if (state == ShadowState.Text) {
|
||||
if (
|
||||
remaining_highlights.length > 0 &&
|
||||
i == remaining_highlights[0].start
|
||||
) {
|
||||
// Start a span
|
||||
output.push(buffer);
|
||||
buffer = chr;
|
||||
state = ShadowState.Highlight;
|
||||
} else {
|
||||
// Add a character
|
||||
buffer += chr;
|
||||
}
|
||||
} else if (state == ShadowState.Highlight) {
|
||||
if (remaining_highlights.length > 0 && i == remaining_highlights[0].end) {
|
||||
// End the span
|
||||
output.push(<span className="highlighted">{buffer}</span>);
|
||||
buffer = chr;
|
||||
state = ShadowState.Text;
|
||||
remaining_highlights = remaining_highlights.slice(1);
|
||||
} else {
|
||||
// Add a character
|
||||
buffer += chr;
|
||||
}
|
||||
const thisCharHighlighted = isInHighlight(highlights, i);
|
||||
if (state == ShadowState.Text && thisCharHighlighted) {
|
||||
// Start a span
|
||||
output.push(buffer);
|
||||
buffer = chr;
|
||||
state = ShadowState.Highlight;
|
||||
} else if (state == ShadowState.Text && !thisCharHighlighted) {
|
||||
// Add a character
|
||||
buffer += chr;
|
||||
} else if (state == ShadowState.Highlight && thisCharHighlighted) {
|
||||
// Add a character
|
||||
buffer += chr;
|
||||
} else if (state == ShadowState.Highlight && !thisCharHighlighted) {
|
||||
// End the span
|
||||
output.push(
|
||||
<span key={i} className={styles.EditorHighlighted}>
|
||||
{buffer}
|
||||
</span>,
|
||||
);
|
||||
buffer = chr;
|
||||
state = ShadowState.Text;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
@@ -40,26 +37,23 @@ function buildShadow(highlights: Highlight[], text: string): ReactNode[] {
|
||||
if (state == ShadowState.Text) {
|
||||
output.push(buffer);
|
||||
} else if (state == ShadowState.Highlight) {
|
||||
output.push(<span className="highlighted">{buffer}</span>);
|
||||
output.push(
|
||||
<span key={i} className={styles.EditorHighlighted}>
|
||||
{buffer}
|
||||
</span>,
|
||||
);
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
function unicodeAwareSlice(text: string, start: number, end: number): string {
|
||||
// Boooo javascript
|
||||
let i = 0;
|
||||
let output = "";
|
||||
for (let chr of text) {
|
||||
if (i >= end) {
|
||||
break;
|
||||
function isInHighlight(highlights: Highlight[], offset: number): boolean {
|
||||
for (const highlight of highlights) {
|
||||
if (highlight.start <= offset && offset < highlight.end) {
|
||||
return true;
|
||||
}
|
||||
if (i >= start) {
|
||||
output += chr;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
return output;
|
||||
return false;
|
||||
}
|
||||
|
||||
const enum ShadowState {
|
||||
|
||||
@@ -75,8 +75,6 @@ module.exports = {
|
||||
filename: "index.html",
|
||||
}),
|
||||
],
|
||||
mode: "development",
|
||||
devtool: "inline-source-map",
|
||||
experiments: {
|
||||
asyncWebAssembly: true,
|
||||
},
|
||||
7
webpack.dev.js
Normal file
7
webpack.dev.js
Normal file
@@ -0,0 +1,7 @@
|
||||
const { merge } = require("webpack-merge");
|
||||
const common = require("./webpack.common.js");
|
||||
|
||||
module.exports = merge(common, {
|
||||
mode: "development",
|
||||
devtool: "inline-source-map",
|
||||
});
|
||||
6
webpack.prd.js
Normal file
6
webpack.prd.js
Normal file
@@ -0,0 +1,6 @@
|
||||
const { merge } = require("webpack-merge");
|
||||
const common = require("./webpack.common.js");
|
||||
|
||||
module.exports = merge(common, {
|
||||
mode: "production",
|
||||
});
|
||||
Reference in New Issue
Block a user