Format the code.

This commit is contained in:
Tom Alexander 2024-01-23 22:06:47 -05:00
parent 4847ec07d8
commit d1ce90ac42
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
11 changed files with 46 additions and 54 deletions

View File

@ -1,8 +1,8 @@
import React from 'react'; import React from "react";
import { render, screen } from '@testing-library/react'; import { render, screen } from "@testing-library/react";
import App from './App'; import App from "./App";
test('renders learn react link', () => { test("renders learn react link", () => {
render(<App />); render(<App />);
const linkElement = screen.getByText(/learn react/i); const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument(); expect(linkElement).toBeInTheDocument();

View File

@ -1,5 +1,5 @@
import './App.css'; import "./App.css";
import Editor from './Editor'; import Editor from "./Editor";
function App() { function App() {
return ( return (

View File

@ -1,13 +1,13 @@
body { body {
margin: 0; margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
sans-serif; sans-serif;
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
} }
code { code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
monospace; monospace;
} }

View File

@ -1,16 +1,16 @@
import React from 'react'; import React from "react";
import ReactDOM from 'react-dom/client'; import ReactDOM from "react-dom/client";
import './index.css'; import "./index.css";
import App from './App'; import App from "./App";
import reportWebVitals from './reportWebVitals'; import reportWebVitals from "./reportWebVitals";
const root = ReactDOM.createRoot( const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement document.getElementById("root") as HTMLElement,
); );
root.render( root.render(
<React.StrictMode> <React.StrictMode>
<App /> <App />
</React.StrictMode> </React.StrictMode>,
); );
// If you want to start measuring performance in your app, pass a function // If you want to start measuring performance in your app, pass a function

View File

@ -1,8 +1,8 @@
import { ReportHandler } from 'web-vitals'; import { ReportHandler } from "web-vitals";
const reportWebVitals = (onPerfEntry?: ReportHandler) => { const reportWebVitals = (onPerfEntry?: ReportHandler) => {
if (onPerfEntry && onPerfEntry instanceof Function) { if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { import("web-vitals").then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
getCLS(onPerfEntry); getCLS(onPerfEntry);
getFID(onPerfEntry); getFID(onPerfEntry);
getFCP(onPerfEntry); getFCP(onPerfEntry);

View File

@ -2,4 +2,4 @@
// allows you to do things like: // allows you to do things like:
// expect(element).toHaveTextContent(/react/i) // expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom // learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom'; import "@testing-library/jest-dom";

View File

@ -1,11 +1,7 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "es5", "target": "es5",
"lib": [ "lib": ["dom", "dom.iterable", "esnext"],
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true, "allowJs": true,
"skipLibCheck": true, "skipLibCheck": true,
"esModuleInterop": true, "esModuleInterop": true,
@ -18,9 +14,7 @@
"resolveJsonModule": true, "resolveJsonModule": true,
"isolatedModules": true, "isolatedModules": true,
"noEmit": true, "noEmit": true,
"jsx": "react-jsx" "jsx": "react-jsx",
}, },
"include": [ "include": ["src"],
"src"
]
} }

View File

@ -15,7 +15,7 @@ function Editor({ defaultValue = "I have a text value." }) {
function addHighlight(start: number, end: number) { function addHighlight(start: number, end: number) {
let new_highlights = [...highlights, new Highlight(start, end)]; let new_highlights = [...highlights, new Highlight(start, end)];
new_highlights.sort(function (a,b) { new_highlights.sort(function (a, b) {
if (a.start < b.start) return -1; if (a.start < b.start) return -1;
if (a.start > b.start) return 1; if (a.start > b.start) return 1;
return 0; return 0;

View File

@ -1,35 +1,32 @@
import React, { ReactNode, useState } from "react"; import React, { ReactNode, useState } from "react";
import { import { parse_org } from "../../organic/target/wasm32-unknown-unknown/js/wasm";
parse_org,
} from "../../organic/target/wasm32-unknown-unknown/js/wasm";
import styles from "./OrgAst.module.css"; import styles from "./OrgAst.module.css";
const OrgAst = (props: {addHighlight: Function, value: string}) => { const OrgAst = (props: { addHighlight: Function; value: string }) => {
console.log(styles); console.log(styles);
const ast_tree = parse_org(props.value); const ast_tree = parse_org(props.value);
console.log(JSON.stringify(ast_tree)); console.log(JSON.stringify(ast_tree));
if (ast_tree.status !== "success") { if (ast_tree.status !== "success") {
return ( return <div className={styles.OrgAst}>Error! {ast_tree.content}</div>;
<div className={styles.OrgAst}>Error! {ast_tree.content}</div>
);
} else { } else {
return ( return (
<div className={styles.OrgAst}><OrgAstNode node={ast_tree.content}/></div> <div className={styles.OrgAst}>
<OrgAstNode node={ast_tree.content} />
</div>
); );
} }
} };
const OrgAstNode = (props: {node: any}) => { const OrgAstNode = (props: { node: any }) => {
return ( return (
<div className={styles.OrgAstNode}> <div className={styles.OrgAstNode}>
<div className={styles.OrgAstNodeType}>{props.node["ast-node"]}</div> <div className={styles.OrgAstNodeType}>{props.node["ast-node"]}</div>
{Array.isArray(props.node.children) && props.node.children.length > 0 ? (<> {Array.isArray(props.node.children) && props.node.children.length > 0 ? (
Has children <>Has children</>
</>) : null} ) : null}
</div> </div>
); );
} };
export default OrgAst; export default OrgAst;

View File

@ -9,7 +9,10 @@ function buildShadow(highlights: Highlight[], text: string): ReactNode[] {
let buffer = ""; let buffer = "";
for (let chr of text) { for (let chr of text) {
if (state == ShadowState.Text) { if (state == ShadowState.Text) {
if (remaining_highlights.length > 0 && i == remaining_highlights[0].start) { if (
remaining_highlights.length > 0 &&
i == remaining_highlights[0].start
) {
// Start a span // Start a span
output.push(buffer); output.push(buffer);
buffer = chr; buffer = chr;
@ -35,9 +38,9 @@ function buildShadow(highlights: Highlight[], text: string): ReactNode[] {
if (buffer.length > 0) { if (buffer.length > 0) {
if (state == ShadowState.Text) { if (state == ShadowState.Text) {
output.push(buffer); output.push(buffer);
} else if (state == ShadowState.Highlight) { } else if (state == ShadowState.Highlight) {
output.push(<span className="highlighted">{buffer}</span>); output.push(<span className="highlighted">{buffer}</span>);
} }
} }
return output; return output;
@ -64,6 +67,4 @@ const enum ShadowState {
Highlight, Highlight,
} }
export { export { buildShadow };
buildShadow
}

View File

@ -5,10 +5,10 @@ const CSSModuleLoader = {
loader: "css-loader", loader: "css-loader",
options: { options: {
importLoaders: 2, importLoaders: 2,
sourceMap: true, sourceMap: true,
modules: { modules: {
localIdentName: '[name]_[local]_[hash:base64:5]', localIdentName: "[name]_[local]_[hash:base64:5]",
} },
}, },
}; };