Big react upgrade (#41)

This commit is contained in:
Borys Levytskyi
2023-05-04 18:26:41 +02:00
committed by GitHub
parent d9ce07b3c2
commit 742f74fe44
14 changed files with 22153 additions and 21940 deletions

46
build.md Normal file
View File

@@ -0,0 +1,46 @@
# 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:
### `npm 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.
### `npm 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.
### `npm run 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.
### `npm run eject`
**Note: this is a one-way operation. Once you `eject`, you cant go back!**
If you arent 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 youre on your own.
You dont have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldnt feel obligated to use this feature. However we understand that this tool wouldnt be useful if you couldnt 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/).

43921
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -3,25 +3,26 @@
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"dependencies": { "dependencies": {
"@fortawesome/fontawesome-free": "^5.15.2", "@fortawesome/fontawesome-free": "^6.4.0",
"@fortawesome/fontawesome-svg-core": "^1.2.34", "@fortawesome/fontawesome-svg-core": "^6.4.0",
"@fortawesome/free-brands-svg-icons": "^5.15.2", "@fortawesome/free-brands-svg-icons": "^6.4.0",
"@fortawesome/free-solid-svg-icons": "^5.15.2", "@fortawesome/free-solid-svg-icons": "^6.4.0",
"@fortawesome/react-fontawesome": "^0.1.14", "@fortawesome/react-fontawesome": "^0.2.0",
"@types/enzyme": "^3.9.4", "@testing-library/jest-dom": "^5.16.5",
"@types/jest": "^24.0.15", "@testing-library/react": "^13.4.0",
"@types/node": "^12.0.10", "@testing-library/user-event": "^13.5.0",
"@types/react": "^16.8.22", "@types/jest": "^27.5.2",
"@types/react-dom": "^16.8.4", "@types/node": "^16.18.25",
"@types/uuid": "^3.4.4", "@types/react": "^18.2.4",
"enzyme": "^3.10.0", "@types/react-dom": "^18.2.3",
"enzyme-adapter-react-16": "^1.14.0", "@types/uuid": "^9.0.1",
"react": "^16.8.6", "loglevel": "^1.8.1",
"react-dom": "^16.8.6", "react": "^18.2.0",
"react-scripts": "3.0.1", "react-dom": "^18.2.0",
"react-test-renderer": "^16.8.6", "react-scripts": "5.0.1",
"typescript": "^3.5.2", "typescript": "^4.9.5",
"uuid": "^3.3.2" "uuid": "^9.0.0",
"web-vitals": "^2.1.4"
}, },
"scripts": { "scripts": {
"start": "react-scripts start", "start": "react-scripts start",
@@ -31,7 +32,10 @@
"serve-build": "npx http-server ./build -p 3030" "serve-build": "npx http-server ./build -p 3030"
}, },
"eslintConfig": { "eslintConfig": {
"extends": "react-app" "extends": [
"react-app",
"react-app/jest"
]
}, },
"browserslist": { "browserslist": {
"production": [ "production": [
@@ -46,7 +50,6 @@
] ]
}, },
"devDependencies": { "devDependencies": {
"@types/enzyme-adapter-react-16": "^1.0.5", "http-server": "^14.1.1"
"http-server": "^0.12.3"
} }
} }

3
public/robots.txt Normal file
View File

@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:

View File

@@ -1,3 +1,4 @@
import { OperationCanceledException } from "typescript";
import { parser, ListOfNumbersExpression, BitwiseOperationExpression, NumericOperand, ExpressionOperand } from "./expression"; import { parser, ListOfNumbersExpression, BitwiseOperationExpression, NumericOperand, ExpressionOperand } from "./expression";
describe("expression parser", () => { describe("expression parser", () => {
@@ -21,11 +22,16 @@ describe("expression parser", () => {
const second = result.expressionItems[1]; const second = result.expressionItems[1];
expect(first).toBeInstanceOf(NumericOperand); expect(first).toBeInstanceOf(NumericOperand);
expect(first.value).toBe(1);
expect((first as NumericOperand).value).toBe(1);
expect(second).toBeInstanceOf(ExpressionOperand); expect(second).toBeInstanceOf(ExpressionOperand);
expect(second.sign).toBe("^"); var secondOp = second as ExpressionOperand;
expect(second.operand.value).toBe(2); expect(secondOp.sign).toBe("^");
expect(secondOp.operand).toBeInstanceOf(NumericOperand);
var childOp = secondOp.operand as NumericOperand;
expect(childOp.value).toBe(2);
}); });
it("bug", () => { it("bug", () => {

View File

@@ -1,8 +1,10 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import reportWebVitals from './reportWebVitals';
import cmd, { CommandInput } from './shell/cmd'; import cmd, { CommandInput } from './shell/cmd';
import AppRoot from './shell/components/AppRoot'; import AppRoot from './shell/components/AppRoot';
import log from 'loglevel'; import log from 'loglevel';
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css'; import './index.css';
import networkingAppModule from './networking/module'; import networkingAppModule from './networking/module';
import expressionAppModule from './expression/module'; import expressionAppModule from './expression/module';
@@ -10,13 +12,11 @@ import shellModule from './shell/module';
import bootstrapAppData from './shell/startup'; import bootstrapAppData from './shell/startup';
import UnknownInputResultView from './shell/components/UnknownInputResultView'; import UnknownInputResultView from './shell/components/UnknownInputResultView';
const appData = bootstrapAppData(); const appData = bootstrapAppData();
initializeModules(); initializeModules();
var root = <AppRoot appState={appData.appState} />;
ReactDOM.render(root, document.getElementById('root'));
executeStartupCommands(); executeStartupCommands();
appData.appState.registerVisit(); appData.appState.registerVisit();
@@ -40,5 +40,18 @@ function initializeModules() {
}); });
} }
const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement
);
root.render(
<React.StrictMode>
<AppRoot appState={appData.appState} />
</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
//eportWebVitals();

15
src/reportWebVitals.ts Normal file
View File

@@ -0,0 +1,15 @@
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;

5
src/setupTests.ts Normal file
View File

@@ -0,0 +1,5 @@
// 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';

View File

@@ -8,8 +8,8 @@ describe("CmdShell", () => {
test2() { } test2() { }
}; };
spyOn(handler, "test1"); jest.spyOn(handler, "test1");
spyOn(handler, "test2"); jest.spyOn(handler, "test2");
var sut = new CmdShell(); var sut = new CmdShell();
sut.command("test1", handler.test1); sut.command("test1", handler.test1);
@@ -32,7 +32,7 @@ describe("CmdShell", () => {
handle: function (input: string) { } handle: function (input: string) { }
}; };
spyOn(handler, "handle"); jest.spyOn(handler, "handle");
var sut = new CmdShell(); var sut = new CmdShell();
sut.command(handler); sut.command(handler);

View File

@@ -48,7 +48,7 @@ export class CmdShell {
try { try {
this.invokeHandler(input, handler, ops); this.invokeHandler(input, handler, ops);
} catch (e) { } catch (e) {
this.handleError(input, e); this.handleError(input, e as Error);
} }
} }
} }

View File

@@ -10,7 +10,8 @@ type DisplayResultProps = {
input: string, input: string,
resultKey: number, resultKey: number,
resultIndex: number, resultIndex: number,
onRemove?: (i: number) => void; onRemove?: (i: number) => void,
children: JSX.Element
} }
const DisplayResultView: React.FunctionComponent<DisplayResultProps> = (props) => { const DisplayResultView: React.FunctionComponent<DisplayResultProps> = (props) => {

View File

@@ -6,7 +6,8 @@ export type ToggleProps = {
isOn: boolean, isOn: boolean,
title: string, title: string,
elementId?: string elementId?: string
onClick: () => void onClick: () => void,
children?: React.ReactNode
}; };
const Toggle: React.FunctionComponent<ToggleProps> = (props) => { const Toggle: React.FunctionComponent<ToggleProps> = (props) => {

View File

@@ -1,5 +1,5 @@
import React from 'react'; import React from 'react';
import uuid from 'uuid'; import {v4 as uuid} from 'uuid';
import { sendAnalyticsEvent } from './analytics'; import { sendAnalyticsEvent } from './analytics';
import AppState from './AppState'; import AppState from './AppState';
import { CmdShell, CommandInput } from './cmd'; import { CmdShell, CommandInput } from './cmd';

View File

@@ -12,14 +12,15 @@
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
"strict": true, "strict": true,
"forceConsistentCasingInFileNames": true, "forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext", "module": "esnext",
"moduleResolution": "node", "moduleResolution": "node",
"resolveJsonModule": true, "resolveJsonModule": true,
"isolatedModules": true, "isolatedModules": true,
"noEmit": true, "noEmit": true,
"jsx": "preserve" "jsx": "react-jsx"
}, },
"include": [ "include": [
"src" "src"
, "public/analytics.js" ] ]
} }