diff --git a/README.md b/README.md index f91225f..54c811b 100644 --- a/README.md +++ b/README.md @@ -1,44 +1,7 @@ -This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app), using the [Redux](https://redux.js.org/) and [Redux Toolkit](https://redux-toolkit.js.org/) template. +# Calc-constructor -## Available Scripts +This is small calc-constructor where you can : -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 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. Drag elements from pallete to desk when constructor mode enabled; +2. Use calculator functional when constructor mode disabled; +3. Remove elements from desk on Double Click; diff --git a/package-lock.json b/package-lock.json index 76c2b54..ff5bacf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1212,6 +1212,120 @@ "resolved": "https://registry.npmjs.org/@csstools/normalize.css/-/normalize.css-10.1.0.tgz", "integrity": "sha512-ij4wRiunFfaJxjB0BdrYHIH8FxBJpOwNPhhAcunlmPdXudL1WQV1qoP9un6JsEBAgQH+7UXyyjh0g7jTxXK6tg==" }, + "@emotion/babel-plugin": { + "version": "11.7.2", + "resolved": "https://registry.npmjs.org/@emotion/babel-plugin/-/babel-plugin-11.7.2.tgz", + "integrity": "sha512-6mGSCWi9UzXut/ZAN6lGFu33wGR3SJisNl3c0tvlmb8XChH1b2SUvxvnOh7hvLpqyRdHHU9AiazV3Cwbk5SXKQ==", + "requires": { + "@babel/helper-module-imports": "^7.12.13", + "@babel/plugin-syntax-jsx": "^7.12.13", + "@babel/runtime": "^7.13.10", + "@emotion/hash": "^0.8.0", + "@emotion/memoize": "^0.7.5", + "@emotion/serialize": "^1.0.2", + "babel-plugin-macros": "^2.6.1", + "convert-source-map": "^1.5.0", + "escape-string-regexp": "^4.0.0", + "find-root": "^1.1.0", + "source-map": "^0.5.7", + "stylis": "4.0.13" + }, + "dependencies": { + "escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==" + } + } + }, + "@emotion/cache": { + "version": "11.7.1", + "resolved": "https://registry.npmjs.org/@emotion/cache/-/cache-11.7.1.tgz", + "integrity": "sha512-r65Zy4Iljb8oyjtLeCuBH8Qjiy107dOYC6SJq7g7GV5UCQWMObY4SJDPGFjiiVpPrOJ2hmJOoBiYTC7hwx9E2A==", + "requires": { + "@emotion/memoize": "^0.7.4", + "@emotion/sheet": "^1.1.0", + "@emotion/utils": "^1.0.0", + "@emotion/weak-memoize": "^0.2.5", + "stylis": "4.0.13" + } + }, + "@emotion/hash": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/@emotion/hash/-/hash-0.8.0.tgz", + "integrity": "sha512-kBJtf7PH6aWwZ6fka3zQ0p6SBYzx4fl1LoZXE2RrnYST9Xljm7WfKJrU4g/Xr3Beg72MLrp1AWNUmuYJTL7Cow==" + }, + "@emotion/is-prop-valid": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@emotion/is-prop-valid/-/is-prop-valid-1.1.1.tgz", + "integrity": "sha512-bW1Tos67CZkOURLc0OalnfxtSXQJMrAMV0jZTVGJUPSOd4qgjF3+tTD5CwJM13PHA8cltGW1WGbbvV9NpvUZPw==", + "requires": { + "@emotion/memoize": "^0.7.4" + } + }, + "@emotion/memoize": { + "version": "0.7.5", + "resolved": "https://registry.npmjs.org/@emotion/memoize/-/memoize-0.7.5.tgz", + "integrity": "sha512-igX9a37DR2ZPGYtV6suZ6whr8pTFtyHL3K/oLUotxpSVO2ASaprmAe2Dkq7tBo7CRY7MMDrAa9nuQP9/YG8FxQ==" + }, + "@emotion/react": { + "version": "11.7.1", + "resolved": "https://registry.npmjs.org/@emotion/react/-/react-11.7.1.tgz", + "integrity": "sha512-DV2Xe3yhkF1yT4uAUoJcYL1AmrnO5SVsdfvu+fBuS7IbByDeTVx9+wFmvx9Idzv7/78+9Mgx2Hcmr7Fex3tIyw==", + "requires": { + "@babel/runtime": "^7.13.10", + "@emotion/cache": "^11.7.1", + "@emotion/serialize": "^1.0.2", + "@emotion/sheet": "^1.1.0", + "@emotion/utils": "^1.0.0", + "@emotion/weak-memoize": "^0.2.5", + "hoist-non-react-statics": "^3.3.1" + } + }, + "@emotion/serialize": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@emotion/serialize/-/serialize-1.0.2.tgz", + "integrity": "sha512-95MgNJ9+/ajxU7QIAruiOAdYNjxZX7G2mhgrtDWswA21VviYIRP1R5QilZ/bDY42xiKsaktP4egJb3QdYQZi1A==", + "requires": { + "@emotion/hash": "^0.8.0", + "@emotion/memoize": "^0.7.4", + "@emotion/unitless": "^0.7.5", + "@emotion/utils": "^1.0.0", + "csstype": "^3.0.2" + } + }, + "@emotion/sheet": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@emotion/sheet/-/sheet-1.1.0.tgz", + "integrity": "sha512-u0AX4aSo25sMAygCuQTzS+HsImZFuS8llY8O7b9MDRzbJM0kVJlAz6KNDqcG7pOuQZJmj/8X/rAW+66kMnMW+g==" + }, + "@emotion/styled": { + "version": "11.6.0", + "resolved": "https://registry.npmjs.org/@emotion/styled/-/styled-11.6.0.tgz", + "integrity": "sha512-mxVtVyIOTmCAkFbwIp+nCjTXJNgcz4VWkOYQro87jE2QBTydnkiYusMrRGFtzuruiGK4dDaNORk4gH049iiQuw==", + "requires": { + "@babel/runtime": "^7.13.10", + "@emotion/babel-plugin": "^11.3.0", + "@emotion/is-prop-valid": "^1.1.1", + "@emotion/serialize": "^1.0.2", + "@emotion/utils": "^1.0.0" + } + }, + "@emotion/unitless": { + "version": "0.7.5", + "resolved": "https://registry.npmjs.org/@emotion/unitless/-/unitless-0.7.5.tgz", + "integrity": "sha512-OWORNpfjMsSSUBVrRBVGECkhWcULOAJz9ZW8uK9qgxD+87M7jHRcvh/A96XXNhXTLmKcoYSQtBEX7lHMO7YRwg==" + }, + "@emotion/utils": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@emotion/utils/-/utils-1.0.0.tgz", + "integrity": "sha512-mQC2b3XLDs6QCW+pDQDiyO/EdGZYOygE8s5N5rrzjSI4M3IejPE/JPndCBwRT9z982aqQNi6beWs1UeayrQxxA==" + }, + "@emotion/weak-memoize": { + "version": "0.2.5", + "resolved": "https://registry.npmjs.org/@emotion/weak-memoize/-/weak-memoize-0.2.5.tgz", + "integrity": "sha512-6U71C2Wp7r5XtFtQzYrW5iKFT67OixrSxjI4MptCHzdSVlgabczzqLe0ZSgnub/5Kp4hSbpDB1tMytZY9pwxxA==" + }, "@eslint/eslintrc": { "version": "0.4.3", "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.4.3.tgz", @@ -1795,6 +1909,112 @@ } } }, + "@mui/base": { + "version": "5.0.0-alpha.63", + "resolved": "https://registry.npmjs.org/@mui/base/-/base-5.0.0-alpha.63.tgz", + "integrity": "sha512-/jURXlBAYqZaWw92XfJgc6aiHnDcNVuRxBskub57HXWCMK3OiVVdfUEWJEdCjOacCKiw3+Etc5alI9Omaqrg2g==", + "requires": { + "@babel/runtime": "^7.16.3", + "@emotion/is-prop-valid": "^1.1.1", + "@mui/utils": "^5.2.3", + "@popperjs/core": "^2.4.4", + "clsx": "^1.1.1", + "prop-types": "^15.7.2", + "react-is": "^17.0.2" + }, + "dependencies": { + "react-is": { + "version": "17.0.2", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", + "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==" + } + } + }, + "@mui/material": { + "version": "5.2.7", + "resolved": "https://registry.npmjs.org/@mui/material/-/material-5.2.7.tgz", + "integrity": "sha512-JaDl9GJSV17QLf4OoDUZKvVjZ/7UvqOBAxwLwUTnKZEME4REaGTkaAeHrzLpcKCm0LlNGD2HOKAIeykI6WJiqg==", + "requires": { + "@babel/runtime": "^7.16.3", + "@mui/base": "5.0.0-alpha.63", + "@mui/system": "^5.2.6", + "@mui/types": "^7.1.0", + "@mui/utils": "^5.2.3", + "@types/react-transition-group": "^4.4.4", + "clsx": "^1.1.1", + "csstype": "^3.0.10", + "hoist-non-react-statics": "^3.3.2", + "prop-types": "^15.7.2", + "react-is": "^17.0.2", + "react-transition-group": "^4.4.2" + }, + "dependencies": { + "react-is": { + "version": "17.0.2", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", + "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==" + } + } + }, + "@mui/private-theming": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/@mui/private-theming/-/private-theming-5.2.3.tgz", + "integrity": "sha512-Lc1Cmu8lSsYZiXADi9PBb17Ho82ZbseHQujUFAcp6bCJ5x/d+87JYCIpCBMagPu/isRlFCwbziuXPmz7WOzJPQ==", + "requires": { + "@babel/runtime": "^7.16.3", + "@mui/utils": "^5.2.3", + "prop-types": "^15.7.2" + } + }, + "@mui/styled-engine": { + "version": "5.2.6", + "resolved": "https://registry.npmjs.org/@mui/styled-engine/-/styled-engine-5.2.6.tgz", + "integrity": "sha512-bqAhli8eGS6v2qxivy2/4K0Ag8o//jsu1G2G6QcieFiT6y7oIF/nd/6Tvw6OSm3roOTifVQWNKwkt1yFWhGS+w==", + "requires": { + "@babel/runtime": "^7.16.3", + "@emotion/cache": "^11.7.1", + "prop-types": "^15.7.2" + } + }, + "@mui/system": { + "version": "5.2.6", + "resolved": "https://registry.npmjs.org/@mui/system/-/system-5.2.6.tgz", + "integrity": "sha512-PZ7bmpWOLikWgqn2zWv9/Xa7lxnRBOmfjoMH7c/IVYJs78W3971brXJ3xV9MEWWQcoqiYQeXzUJaNf4rFbKCBA==", + "requires": { + "@babel/runtime": "^7.16.3", + "@mui/private-theming": "^5.2.3", + "@mui/styled-engine": "^5.2.6", + "@mui/types": "^7.1.0", + "@mui/utils": "^5.2.3", + "clsx": "^1.1.1", + "csstype": "^3.0.10", + "prop-types": "^15.7.2" + } + }, + "@mui/types": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/@mui/types/-/types-7.1.0.tgz", + "integrity": "sha512-Hh7ALdq/GjfIwLvqH3XftuY3bcKhupktTm+S6qRIDGOtPtRuq2L21VWzOK4p7kblirK0XgGVH5BLwa6u8z/6QQ==" + }, + "@mui/utils": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/@mui/utils/-/utils-5.2.3.tgz", + "integrity": "sha512-sQujlajIS0zQKcGIS6tZR0L1R+ib26B6UtuEn+cZqwKHsPo3feuS+SkdscYBdcCdMbrZs4gj8WIJHl2z6tbSzQ==", + "requires": { + "@babel/runtime": "^7.16.3", + "@types/prop-types": "^15.7.4", + "@types/react-is": "^16.7.1 || ^17.0.0", + "prop-types": "^15.7.2", + "react-is": "^17.0.2" + }, + "dependencies": { + "react-is": { + "version": "17.0.2", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", + "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==" + } + } + }, "@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -1873,6 +2093,11 @@ } } }, + "@popperjs/core": { + "version": "2.11.2", + "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.2.tgz", + "integrity": "sha512-92FRmppjjqz29VMJ2dn+xdyXZBrMlE42AV6Kq6BwjWV7CNUW1hs2FtxSNLQE+gJhaZ6AAmYuO9y8dshhcBl7vA==" + }, "@reduxjs/toolkit": { "version": "1.6.2", "resolved": "https://registry.npmjs.org/@reduxjs/toolkit/-/toolkit-1.6.2.tgz", @@ -2437,6 +2662,14 @@ "@types/react": "*" } }, + "@types/react-is": { + "version": "17.0.3", + "resolved": "https://registry.npmjs.org/@types/react-is/-/react-is-17.0.3.tgz", + "integrity": "sha512-aBTIWg1emtu95bLTLx0cpkxwGW3ueZv71nE2YFBpL8k/z5czEW8yYpOo8Dp+UUAFAtKwNaOsh/ioSeQnWlZcfw==", + "requires": { + "@types/react": "*" + } + }, "@types/react-redux": { "version": "7.1.20", "resolved": "https://registry.npmjs.org/@types/react-redux/-/react-redux-7.1.20.tgz", @@ -2448,6 +2681,14 @@ "redux": "^4.0.0" } }, + "@types/react-transition-group": { + "version": "4.4.4", + "resolved": "https://registry.npmjs.org/@types/react-transition-group/-/react-transition-group-4.4.4.tgz", + "integrity": "sha512-7gAPz7anVK5xzbeQW9wFBDg7G++aPLAFY0QaSMOou9rJZpbuI58WAuJrgu+qR92l61grlnCUe7AFX8KGahAgug==", + "requires": { + "@types/react": "*" + } + }, "@types/resolve": { "version": "0.0.8", "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-0.0.8.tgz", @@ -4340,6 +4581,11 @@ "wrap-ansi": "^6.2.0" } }, + "clsx": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/clsx/-/clsx-1.1.1.tgz", + "integrity": "sha512-6/bPho624p3S2pMyvP5kKBPXnI3ufHLObBFCfgx+LkeR5lg2XYy2hqZqUf45ypD8COn2bhgGJSUE+l5dhNBieA==" + }, "co": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", @@ -5321,6 +5567,15 @@ "utila": "~0.4" } }, + "dom-helpers": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/dom-helpers/-/dom-helpers-5.2.1.tgz", + "integrity": "sha512-nRCa7CK3VTrM2NmGkIy4cbK7IZlgBE/PYMn55rrXefr5xXDP0LdtfPnblFDoVdcAfslJ7or6iqAUnx0CCGIWQA==", + "requires": { + "@babel/runtime": "^7.8.7", + "csstype": "^3.0.2" + } + }, "dom-serializer": { "version": "0.2.2", "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.2.2.tgz", @@ -5472,6 +5727,12 @@ } } }, + "email-addresses": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/email-addresses/-/email-addresses-3.1.0.tgz", + "integrity": "sha512-k0/r7GrWVL32kZlGwfPNgB2Y/mMXVTq/decgLczm/j34whdaspNrZO8CnXPf1laaHxI6ptUlsnAxN+UAPw+fzg==", + "dev": true + }, "emittery": { "version": "0.7.2", "resolved": "https://registry.npmjs.org/emittery/-/emittery-0.7.2.tgz", @@ -6697,6 +6958,23 @@ } } }, + "filename-reserved-regex": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/filename-reserved-regex/-/filename-reserved-regex-2.0.0.tgz", + "integrity": "sha1-q/c9+rc10EVECr/qLZHzieu/oik=", + "dev": true + }, + "filenamify": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/filenamify/-/filenamify-4.3.0.tgz", + "integrity": "sha512-hcFKyUG57yWGAzu1CMt/dPzYZuv+jAJUT85bL8mrXvNe6hWj6yEHEc4EdcgiA6Z3oi1/9wXJdZPXF2dZNgwgOg==", + "dev": true, + "requires": { + "filename-reserved-regex": "^2.0.0", + "strip-outer": "^1.0.1", + "trim-repeated": "^1.0.0" + } + }, "filesize": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/filesize/-/filesize-6.1.0.tgz", @@ -6749,6 +7027,11 @@ "pkg-dir": "^3.0.0" } }, + "find-root": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/find-root/-/find-root-1.1.0.tgz", + "integrity": "sha512-NKfW6bec6GfKc0SGx1e07QZY9PE99u0Bft/0rzSD5k3sO/vwkVUpDUKVm5Gpp5Ue3YfShPFTX2070tDs5kB9Ng==" + }, "find-up": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", @@ -7052,6 +7335,118 @@ "resolved": "https://registry.npmjs.org/get-value/-/get-value-2.0.6.tgz", "integrity": "sha1-3BXKHGcjh8p2vTesCjlbogQqLCg=" }, + "gh-pages": { + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/gh-pages/-/gh-pages-3.2.3.tgz", + "integrity": "sha512-jA1PbapQ1jqzacECfjUaO9gV8uBgU6XNMV0oXLtfCX3haGLe5Atq8BxlrADhbD6/UdG9j6tZLWAkAybndOXTJg==", + "dev": true, + "requires": { + "async": "^2.6.1", + "commander": "^2.18.0", + "email-addresses": "^3.0.1", + "filenamify": "^4.3.0", + "find-cache-dir": "^3.3.1", + "fs-extra": "^8.1.0", + "globby": "^6.1.0" + }, + "dependencies": { + "array-union": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/array-union/-/array-union-1.0.2.tgz", + "integrity": "sha1-mjRBDk9OPaI96jdb5b5w8kd47Dk=", + "dev": true, + "requires": { + "array-uniq": "^1.0.1" + } + }, + "commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", + "dev": true + }, + "find-cache-dir": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-3.3.2.tgz", + "integrity": "sha512-wXZV5emFEjrridIgED11OoUKLxiYjAcqot/NJdAkOhlJ+vGzwhOAfcG5OX1jP+S0PcjEn8bdMJv+g2jwQ3Onig==", + "dev": true, + "requires": { + "commondir": "^1.0.1", + "make-dir": "^3.0.2", + "pkg-dir": "^4.1.0" + } + }, + "fs-extra": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", + "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", + "dev": true, + "requires": { + "graceful-fs": "^4.2.0", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + } + }, + "globby": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-6.1.0.tgz", + "integrity": "sha1-9abXDoOV4hyFj7BInWTfAkJNUGw=", + "dev": true, + "requires": { + "array-union": "^1.0.1", + "glob": "^7.0.3", + "object-assign": "^4.0.1", + "pify": "^2.0.0", + "pinkie-promise": "^2.0.0" + } + }, + "jsonfile": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", + "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", + "dev": true, + "requires": { + "graceful-fs": "^4.1.6" + } + }, + "make-dir": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", + "integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==", + "dev": true, + "requires": { + "semver": "^6.0.0" + } + }, + "pify": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", + "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", + "dev": true + }, + "pkg-dir": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-4.2.0.tgz", + "integrity": "sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==", + "dev": true, + "requires": { + "find-up": "^4.0.0" + } + }, + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true + }, + "universalify": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", + "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", + "dev": true + } + } + }, "glob": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz", @@ -12448,6 +12843,17 @@ "workbox-webpack-plugin": "5.1.4" } }, + "react-transition-group": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/react-transition-group/-/react-transition-group-4.4.2.tgz", + "integrity": "sha512-/RNYfRAMlZwDSr6z4zNKV6xu53/e2BuaBbGhbyYIXTrmgu/bGHzmqOs7mJSJBHy9Ud+ApHx3QjrkKSp1pxvlFg==", + "requires": { + "@babel/runtime": "^7.5.5", + "dom-helpers": "^5.0.1", + "loose-envify": "^1.4.0", + "prop-types": "^15.6.2" + } + }, "read-pkg": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-5.2.0.tgz", @@ -14000,6 +14406,15 @@ "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==" }, + "strip-outer": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/strip-outer/-/strip-outer-1.0.1.tgz", + "integrity": "sha512-k55yxKHwaXnpYGsOzg4Vl8+tDrWylxDEpknGjhTiZB8dFRU5rTo9CAzeycivxV3s+zlTKwrs6WxMxR95n26kwg==", + "dev": true, + "requires": { + "escape-string-regexp": "^1.0.2" + } + }, "style-loader": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/style-loader/-/style-loader-1.3.0.tgz", @@ -14031,6 +14446,11 @@ } } }, + "stylis": { + "version": "4.0.13", + "resolved": "https://registry.npmjs.org/stylis/-/stylis-4.0.13.tgz", + "integrity": "sha512-xGPXiFVl4YED9Jh7Euv2V220mriG9u4B2TA6Ybjc1catrstKD2PpIdU3U0RKpkVBC2EhmL/F0sPCr9vrFTNRag==" + }, "supports-color": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", @@ -14424,6 +14844,15 @@ "punycode": "^2.1.1" } }, + "trim-repeated": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/trim-repeated/-/trim-repeated-1.0.0.tgz", + "integrity": "sha1-42RqLqTokTEr9+rObPsFOAvAHCE=", + "dev": true, + "requires": { + "escape-string-regexp": "^1.0.2" + } + }, "tryer": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/tryer/-/tryer-1.0.1.tgz", diff --git a/package.json b/package.json index c81b062..4eab137 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,12 @@ { + "homepage": "https://skippikp.github.io/Calc-constructor", "name": "calc-constructor", "version": "0.1.0", "private": true, "dependencies": { + "@emotion/react": "^11.7.1", + "@emotion/styled": "^11.6.0", + "@mui/material": "^5.2.7", "@reduxjs/toolkit": "^1.6.2", "@testing-library/jest-dom": "^4.2.4", "@testing-library/react": "^9.5.0", @@ -13,6 +17,8 @@ "react-scripts": "4.0.3" }, "scripts": { + "predeploy": "npm run build", + "deploy": "gh-pages -d build", "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", diff --git a/public/index.html b/public/index.html index 1dbdca6..0f8a4af 100644 --- a/public/index.html +++ b/public/index.html @@ -9,35 +9,12 @@ name="description" content="Web site created using create-react-app" /> - - + - React Redux App
- diff --git a/public/logo192.png b/public/logo192.png deleted file mode 100644 index 3362410..0000000 Binary files a/public/logo192.png and /dev/null differ diff --git a/public/logo512.png b/public/logo512.png deleted file mode 100644 index b351622..0000000 Binary files a/public/logo512.png and /dev/null differ diff --git a/public/manifest.json b/public/manifest.json index 080d6c7..0452f8c 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -2,21 +2,7 @@ "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", diff --git a/src/App.css b/src/App.css deleted file mode 100644 index 01cc586..0000000 --- a/src/App.css +++ /dev/null @@ -1,39 +0,0 @@ -.App { - text-align: center; -} - -.App-logo { - height: 40vmin; - pointer-events: none; -} - -@media (prefers-reduced-motion: no-preference) { - .App-logo { - animation: App-logo-float infinite 3s ease-in-out; - } -} - -.App-header { - min-height: 100vh; - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - font-size: calc(10px + 2vmin); -} - -.App-link { - color: rgb(112, 76, 182); -} - -@keyframes App-logo-float { - 0% { - transform: translateY(0); - } - 50% { - transform: translateY(10px); - } - 100% { - transform: translateY(0px); - } -} diff --git a/src/App.js b/src/App.js deleted file mode 100644 index a40f66d..0000000 --- a/src/App.js +++ /dev/null @@ -1,58 +0,0 @@ -import React from 'react'; -import logo from './logo.svg'; -import { Counter } from './features/counter/Counter'; -import './App.css'; - -function App() { - return ( -
-
- logo - -

- Edit src/App.js and save to reload. -

- - Learn - - React - - , - - Redux - - , - - Redux Toolkit - - , and - - React Redux - - -
-
- ); -} - -export default App; diff --git a/src/App.test.js b/src/App.test.js deleted file mode 100644 index 659cc13..0000000 --- a/src/App.test.js +++ /dev/null @@ -1,15 +0,0 @@ -import React from 'react'; -import { render } from '@testing-library/react'; -import { Provider } from 'react-redux'; -import { store } from './app/store'; -import App from './App'; - -test('renders learn react link', () => { - const { getByText } = render( - - - - ); - - expect(getByText(/learn/i)).toBeInTheDocument(); -}); diff --git a/src/HOC/DragContainer.js b/src/HOC/DragContainer.js new file mode 100644 index 0000000..9215962 --- /dev/null +++ b/src/HOC/DragContainer.js @@ -0,0 +1,25 @@ +import React from 'react'; + +const DragContainer = ({ + children, + onDragStart, + onDragEnd, + draggable, + onDblClick, + ...props +}) => { + return ( +
+ {React.Children.map(children, (child) => { + return React.cloneElement(child, { props }); + })} +
+ ); +}; + +export default DragContainer; diff --git a/src/actions/actions.js b/src/actions/actions.js new file mode 100644 index 0000000..54ee7f3 --- /dev/null +++ b/src/actions/actions.js @@ -0,0 +1,58 @@ +import { + ADD_DIGIT, + CHOOSE_OPERATION, + SET_DROPPABLE_SECTION, + EVALUATE, + SET_DRAGGABLE_BLOCK, + SET_BLOCKS, + DRAG_START, + DRAG_END, + CHANGE_CONSTRUCTOR_MODE, +} from './constants'; + +const addDigit = (digit) => { + return { type: ADD_DIGIT, payload: digit }; +}; + +const chooseOperation = (operation) => { + return { type: CHOOSE_OPERATION, payload: operation }; +}; + +const setBlocks = (blocks) => { + return { type: SET_BLOCKS, payload: blocks }; +}; + +const setDraggableBlock = (block) => { + return { type: SET_DRAGGABLE_BLOCK, payload: block }; +}; + +const evaluate = () => { + return { type: EVALUATE }; +}; + +const dragEnd = () => { + return { type: DRAG_END }; +}; + +const dragStart = (draggableBlock) => { + return { type: DRAG_START, payload: draggableBlock }; +}; + +const setDroppableSection = (section) => { + return { type: SET_DROPPABLE_SECTION, payload: section }; +}; + +const changeConstructorMode = () => { + return { type: CHANGE_CONSTRUCTOR_MODE }; +}; +export { + addDigit, + chooseOperation, + evaluate, + dragStart, + setDroppableSection, + changeConstructorMode, + dragEnd, + setBlocks, + setDraggableBlock, +}; diff --git a/src/actions/constants.js b/src/actions/constants.js new file mode 100644 index 0000000..7c13731 --- /dev/null +++ b/src/actions/constants.js @@ -0,0 +1,21 @@ +const ADD_DIGIT = 'ADD_DIGIT'; +const CHOOSE_OPERATION = 'CHOOSE_OPERATION'; +const SET_BLOCKS = 'SET_BLOCKS'; +const SET_DRAGGABLE_BLOCK = 'SET_DRAGGABLE_BLOCK'; +const EVALUATE = 'EVALUATE'; +const DRAG_END = 'DRAG_END'; +const DRAG_START = 'DRAG_START'; +const SET_DROPPABLE_SECTION = 'SET_DROPPABLE_SECTION'; +const CHANGE_CONSTRUCTOR_MODE = 'CHANGE_CONSTRUCTOR_MODE'; + +export { + ADD_DIGIT, + CHOOSE_OPERATION, + SET_BLOCKS, + SET_DRAGGABLE_BLOCK, + EVALUATE, + DRAG_END, + DRAG_START, + SET_DROPPABLE_SECTION, + CHANGE_CONSTRUCTOR_MODE, +}; diff --git a/src/app/store.js b/src/app/store.js deleted file mode 100644 index 9eca6d2..0000000 --- a/src/app/store.js +++ /dev/null @@ -1,8 +0,0 @@ -import { configureStore } from '@reduxjs/toolkit'; -import counterReducer from '../features/counter/counterSlice'; - -export const store = configureStore({ - reducer: { - counter: counterReducer, - }, -}); diff --git a/src/components/App/App.css b/src/components/App/App.css new file mode 100644 index 0000000..e69de29 diff --git a/src/components/App/App.js b/src/components/App/App.js new file mode 100644 index 0000000..26b7b7c --- /dev/null +++ b/src/components/App/App.js @@ -0,0 +1,15 @@ +import React from 'react'; +import CalcPalette from '../CalcPalette/CalcPalette'; +import Desk from '../Desk/Desk'; +import './App.css'; + +function App() { + return ( +
+ + +
+ ); +} + +export default App; diff --git a/src/components/App/store.js b/src/components/App/store.js new file mode 100644 index 0000000..1bdbfc3 --- /dev/null +++ b/src/components/App/store.js @@ -0,0 +1,6 @@ +import { createStore } from 'redux'; +import reducer from '../../reducers/reducer'; + +const store = createStore(reducer); + +export default store; diff --git a/src/components/Button/Button.js b/src/components/Button/Button.js new file mode 100644 index 0000000..00674c4 --- /dev/null +++ b/src/components/Button/Button.js @@ -0,0 +1,24 @@ +import React from 'react'; +import { connect } from 'react-redux'; + +const Button = ({ constructorModeEnable, className, value, onClick }) => { + const clickHandler = () => { + if (constructorModeEnable) { + return; + } + onClick(); + }; + return ( +
+ {value} +
+ ); +}; + +const mapStateToProps = ({ drag: { constructorModeEnable } }) => { + return { + constructorModeEnable, + }; +}; + +export default connect(mapStateToProps)(Button); diff --git a/src/components/CalcPalette/CalcPalette.css b/src/components/CalcPalette/CalcPalette.css new file mode 100644 index 0000000..49d244a --- /dev/null +++ b/src/components/CalcPalette/CalcPalette.css @@ -0,0 +1,3 @@ +.calc-palete { + gap: 10px; +} \ No newline at end of file diff --git a/src/components/CalcPalette/CalcPalette.js b/src/components/CalcPalette/CalcPalette.js new file mode 100644 index 0000000..ffc8f6c --- /dev/null +++ b/src/components/CalcPalette/CalcPalette.js @@ -0,0 +1,99 @@ +import React, { useState } from 'react'; +import { + dragEnd, + dragStart, + setDroppableSection, + setBlocks, +} from '../../actions/actions'; +import { connect } from 'react-redux'; +import './CalcPalette.css'; +import DragContainer from '../../HOC/DragContainer'; +import Display from '../Display/Display'; +import DigitalBlock from '../Digital-block/DigitalBlock'; +import Operations from '../Operations/Operations'; +import EqualBlock from '../Equal-block/EqualBlock'; + +const CalcPalette = ({ + droppableSection, + dragStart, + constructorModeEnable, + setDroppableSection, + dragEnd, + blocks, + setBlocks, +}) => { + const [index, setIndex] = useState(null); + + const dragStartHandler = (e, item) => { + const elemIdx = blocks.indexOf(item); + if (constructorModeEnable) { + setIndex(elemIdx); + dragStart(item); + setTimeout(() => (e.target.style.visibility = 'hidden'), 50); + } + return; + }; + + const dragEndHandler = (e) => { + e.preventDefault(); + if (droppableSection) { + const updatedState = [ + ...blocks.slice(0, index), + ...blocks.slice(index + 1), + ]; + setBlocks(updatedState); + setDroppableSection(null); + } + dragEnd(); + e.target.style.visibility = 'visible'; + }; + + const renderElement = (element) => { + switch (element) { + case 'Display': + return ; + case 'DigitalBlock': + return ; + case 'Operations': + return ; + case 'EqualBlock': + return ; + default: + return
Error
; + } + }; + + return ( +
+ {blocks.map((block) => ( + dragStartHandler(e, block)} + onDragEnd={dragEndHandler} + > + {renderElement(block.component)} + + ))} +
+ ); +}; + +const mapStateToProps = ({ + drag: { droppableSection, blocks, constructorModeEnable }, +}) => { + return { + droppableSection, + constructorModeEnable, + blocks, + }; +}; + +const mapDispatchToProps = { + dragStart, + setDroppableSection, + dragEnd, + setBlocks, +}; + +export default connect(mapStateToProps, mapDispatchToProps)(CalcPalette); diff --git a/src/components/Desk/Desk.css b/src/components/Desk/Desk.css new file mode 100644 index 0000000..02b0b79 --- /dev/null +++ b/src/components/Desk/Desk.css @@ -0,0 +1,40 @@ +.desk { + border: 2px dashed blue; + height: 500px; + width: 300px; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; +} + +.desk-item { + flex-basis: 33%; + padding-top: 20px; + width: 100%; + padding-left:50px ; + display: flex; + flex-direction: column; + gap: 20px; +} + +.desk h5 { + font-size: 15px; + color: blue; + text-align: center; + position: absolute; +} + +.desk p { + font-weight: 300; +} + +.right-side { + display: flex; + flex-direction: column; + align-items: center; +} + +.deskInfo { + z-index: -1; +} \ No newline at end of file diff --git a/src/components/Desk/Desk.js b/src/components/Desk/Desk.js new file mode 100644 index 0000000..e084a2e --- /dev/null +++ b/src/components/Desk/Desk.js @@ -0,0 +1,174 @@ +import React, { useState } from 'react'; +import { connect } from 'react-redux'; +import { + changeConstructorMode, + setDroppableSection, + dragEnd, + setBlocks, + setDraggableBlock, +} from '../../actions/actions'; +import FormGroup from '@mui/material/FormGroup'; +import FormControlLabel from '@mui/material/FormControlLabel'; +import Switch from '@mui/material/Switch'; +import DragContainer from '../../HOC/DragContainer'; +import Display from '../Display/Display'; +import DigitalBlock from '../Digital-block/DigitalBlock'; +import Operations from '../Operations/Operations'; +import EqualBlock from '../Equal-block/EqualBlock'; +import './Desk.css'; + +const Desk = ({ + draggableBlock, + setDroppableSection, + changeConstructorMode, + constructorModeEnable, + blocks, + setBlocks, + setDraggableBlock, +}) => { + const [desk, setDesk] = useState([ + { id: 1, section: 'top', items: [] }, + { id: 2, section: 'middle', items: [] }, + { id: 3, section: 'bottom', items: [] }, + ]); + + const [filled, setFill] = useState(false); + + const dragOverHandler = (e, section) => { + e.preventDefault(); + if (!draggableBlock) { + return; + } + if (e.target.className === 'desk-item') { + e.target.style.backgroundColor = 'rgba(0, 159, 249, 0.4)'; + } + setDroppableSection(section); + }; + + const removeBlockFromDesk = (block, section) => { + if (!constructorModeEnable) { + return; + } + setDraggableBlock(block); + const blockIndex = section.items.indexOf(block); + const sectionIndex = desk.findIndex( + (item) => item.section === section.section + ); + + const updatedPalette = [ + ...blocks.slice(0, block.id - 1), + block, + ...blocks.slice(block.id - 1), + ]; + + setDesk((state) => { + const newDesk = state.slice(); + newDesk[sectionIndex].items.splice(blockIndex, 1); + return newDesk; + }); + setBlocks(updatedPalette); + setDraggableBlock(null); + }; + + const dropHandler = (e, section) => { + e.preventDefault(); + if (e.target.className === 'desk-item') { + e.target.style.backgroundColor = ''; + } + + if (!draggableBlock) { + return; + } + + const itemId = desk.indexOf(section); + + setDesk((state) => { + let newState = state.slice(); + newState[itemId].items.push(draggableBlock); + return newState; + }); + dragEnd(); + setFill(true); + }; + + const dragLeaveHandler = (e) => { + e.preventDefault(); + if (e.target.className === 'desk-item') { + e.target.style.backgroundColor = ''; + } + setDroppableSection(null); + }; + + const renderElement = (element) => { + switch (element) { + case 'Display': + return ; + case 'DigitalBlock': + return ; + case 'Operations': + return ; + case 'EqualBlock': + return ; + default: + return
Error
; + } + }; + + return ( +
+ + } + label={`Constructor Mode ${constructorModeEnable ? 'On' : 'Off'}`} + /> + +
+ {desk.map((section) => ( +
dragOverHandler(e, section)} + onDragLeave={(e) => dragLeaveHandler(e)} + onDrop={(e) => dropHandler(e, section)} + className="desk-item" + > + {section.items.map((item) => ( + removeBlockFromDesk(item, section)} + draggable={false} + > + {renderElement(item.component)} + + ))} +
+ ))} + {filled ? null : ( +
+ Перетащите сюда +

любой элемент из левой панели

+
+ )} +
+
+ ); +}; + +const mapStateToProps = ({ + drag: { constructorModeEnable, draggableBlock, blocks }, +}) => { + return { + draggableBlock, + constructorModeEnable, + blocks, + }; +}; + +const mapDispatchToProps = { + setDroppableSection, + changeConstructorMode, + dragEnd, + setBlocks, + setDraggableBlock, +}; + +export default connect(mapStateToProps, mapDispatchToProps)(Desk); diff --git a/src/components/Digital-block/DigitalBlock.css b/src/components/Digital-block/DigitalBlock.css new file mode 100644 index 0000000..0e92b84 --- /dev/null +++ b/src/components/Digital-block/DigitalBlock.css @@ -0,0 +1,15 @@ +.digital-block { + display: grid; + padding: 5px; + border-radius: 5px; + height: 200px; + width: 200px; + grid-template-columns: 1fr 1fr 1fr; + grid-gap: 5px; + box-shadow: 0 3px 2px rgba(0,0,0,0.2); +} + +.numbers_0 { + grid-column-start: 1; + grid-column-end: 3; +} \ No newline at end of file diff --git a/src/components/Digital-block/DigitalBlock.js b/src/components/Digital-block/DigitalBlock.js new file mode 100644 index 0000000..e3e35e6 --- /dev/null +++ b/src/components/Digital-block/DigitalBlock.js @@ -0,0 +1,28 @@ +import React from 'react'; +import Button from '../Button/Button'; +import { connect } from 'react-redux'; +import { addDigit } from '../../actions/actions'; +import './DigitalBlock.css'; + +const NUMBERS = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '.']; + +const DigitalBlock = ({ addDigit }) => { + return ( +
+ {NUMBERS.map((item) => ( +
+ ); +}; + +const mapDispatchToProps = { + addDigit, +}; + +export default connect(null, mapDispatchToProps)(DigitalBlock); diff --git a/src/components/Display/Display.css b/src/components/Display/Display.css new file mode 100644 index 0000000..d05e33d --- /dev/null +++ b/src/components/Display/Display.css @@ -0,0 +1,19 @@ +.display { + border-radius: 5px; + box-shadow: 0 3px 2px rgba(0,0,0,0.2); + padding: 5px; + width: 200px; + +} + +.display_text-field { + background-color: gray; + border-radius: 5px; + padding: 5px; + height: 45px; +} + +.display_text-field h3,h6 { + margin: 0; + text-align: end; +} \ No newline at end of file diff --git a/src/components/Display/Display.js b/src/components/Display/Display.js new file mode 100644 index 0000000..329b4e7 --- /dev/null +++ b/src/components/Display/Display.js @@ -0,0 +1,28 @@ +import React from 'react'; +import { connect } from 'react-redux'; +import './Display.css'; + +const Display = ({ currentOperand }) => { + const bigNumber = `${currentOperand + ?.slice(0, 21) + .toString()}\n${currentOperand?.slice(21).toString()}`; + return ( +
+
+ {currentOperand?.length > 11 ? ( +
{bigNumber}
+ ) : ( +

{currentOperand || '0'}

+ )} +
+
+ ); +}; + +const mapStateToProps = ({ calc: { currentOperand } }) => { + return { + currentOperand: currentOperand, + }; +}; + +export default connect(mapStateToProps)(Display); diff --git a/src/components/Equal-block/EqualBlock.css b/src/components/Equal-block/EqualBlock.css new file mode 100644 index 0000000..b26638e --- /dev/null +++ b/src/components/Equal-block/EqualBlock.css @@ -0,0 +1,10 @@ +.equal { + box-shadow: 0 3px 2px rgba(0,0,0,0.2); + padding: 5px; + border-radius: 5px; + width: 200px; +} + +.equal_btn { + display: block; +} \ No newline at end of file diff --git a/src/components/Equal-block/EqualBlock.js b/src/components/Equal-block/EqualBlock.js new file mode 100644 index 0000000..eaaaed2 --- /dev/null +++ b/src/components/Equal-block/EqualBlock.js @@ -0,0 +1,23 @@ +import Button from '../Button/Button'; +import React from 'react'; +import { connect } from 'react-redux'; +import { evaluate } from '../../actions/actions'; +import './EqualBlock.css'; + +const EqualBlock = ({ evaluate }) => { + return ( +
+
+ ); +}; + +const mapDispatchToProps = { + evaluate, +}; + +export default connect(null, mapDispatchToProps)(EqualBlock); diff --git a/src/components/Operations/Operations.css b/src/components/Operations/Operations.css new file mode 100644 index 0000000..b0be61c --- /dev/null +++ b/src/components/Operations/Operations.css @@ -0,0 +1,12 @@ +.operations { + display: flex; + gap: 5px; + padding: 5px; + border-radius: 5px; + width: 200px; + box-shadow: 0 3px 2px rgba(0,0,0,0.2); +} + +.operations .btn { + flex-basis: 33%; +} \ No newline at end of file diff --git a/src/components/Operations/Operations.js b/src/components/Operations/Operations.js new file mode 100644 index 0000000..8da5f42 --- /dev/null +++ b/src/components/Operations/Operations.js @@ -0,0 +1,27 @@ +import React from 'react'; +import Button from '../Button/Button'; +import { chooseOperation } from '../../actions/actions'; +import { connect } from 'react-redux'; +import './Operations.css'; + +const OPERATIONS = ['/', 'x', '-', '+']; +const Operations = ({ chooseOperation }) => { + return ( +
+ {OPERATIONS.map((item) => ( +
+ ); +}; + +const mapDispatchToProps = { + chooseOperation, +}; + +export default connect(null, mapDispatchToProps)(Operations); diff --git a/src/features/counter/Counter.js b/src/features/counter/Counter.js deleted file mode 100644 index 772a6ba..0000000 --- a/src/features/counter/Counter.js +++ /dev/null @@ -1,67 +0,0 @@ -import React, { useState } from 'react'; -import { useSelector, useDispatch } from 'react-redux'; -import { - decrement, - increment, - incrementByAmount, - incrementAsync, - incrementIfOdd, - selectCount, -} from './counterSlice'; -import styles from './Counter.module.css'; - -export function Counter() { - const count = useSelector(selectCount); - const dispatch = useDispatch(); - const [incrementAmount, setIncrementAmount] = useState('2'); - - const incrementValue = Number(incrementAmount) || 0; - - return ( -
-
- - {count} - -
-
- setIncrementAmount(e.target.value)} - /> - - - -
-
- ); -} diff --git a/src/features/counter/Counter.module.css b/src/features/counter/Counter.module.css deleted file mode 100644 index 004ae33..0000000 --- a/src/features/counter/Counter.module.css +++ /dev/null @@ -1,78 +0,0 @@ -.row { - display: flex; - align-items: center; - justify-content: center; -} - -.row > button { - margin-left: 4px; - margin-right: 8px; -} -.row:not(:last-child) { - margin-bottom: 16px; -} - -.value { - font-size: 78px; - padding-left: 16px; - padding-right: 16px; - margin-top: 2px; - font-family: 'Courier New', Courier, monospace; -} - -.button { - appearance: none; - background: none; - font-size: 32px; - padding-left: 12px; - padding-right: 12px; - outline: none; - border: 2px solid transparent; - color: rgb(112, 76, 182); - padding-bottom: 4px; - cursor: pointer; - background-color: rgba(112, 76, 182, 0.1); - border-radius: 2px; - transition: all 0.15s; -} - -.textbox { - font-size: 32px; - padding: 2px; - width: 64px; - text-align: center; - margin-right: 4px; -} - -.button:hover, -.button:focus { - border: 2px solid rgba(112, 76, 182, 0.4); -} - -.button:active { - background-color: rgba(112, 76, 182, 0.2); -} - -.asyncButton { - composes: button; - position: relative; -} - -.asyncButton:after { - content: ''; - background-color: rgba(112, 76, 182, 0.15); - display: block; - position: absolute; - width: 100%; - height: 100%; - left: 0; - top: 0; - opacity: 0; - transition: width 1s linear, opacity 0.5s ease 1s; -} - -.asyncButton:active:after { - width: 0%; - opacity: 1; - transition: 0s; -} diff --git a/src/features/counter/counterAPI.js b/src/features/counter/counterAPI.js deleted file mode 100644 index cc9b4a4..0000000 --- a/src/features/counter/counterAPI.js +++ /dev/null @@ -1,6 +0,0 @@ -// A mock function to mimic making an async request for data -export function fetchCount(amount = 1) { - return new Promise((resolve) => - setTimeout(() => resolve({ data: amount }), 500) - ); -} diff --git a/src/features/counter/counterSlice.js b/src/features/counter/counterSlice.js deleted file mode 100644 index 8dc4b5c..0000000 --- a/src/features/counter/counterSlice.js +++ /dev/null @@ -1,73 +0,0 @@ -import { createAsyncThunk, createSlice } from '@reduxjs/toolkit'; -import { fetchCount } from './counterAPI'; - -const initialState = { - value: 0, - status: 'idle', -}; - -// The function below is called a thunk and allows us to perform async logic. It -// can be dispatched like a regular action: `dispatch(incrementAsync(10))`. This -// will call the thunk with the `dispatch` function as the first argument. Async -// code can then be executed and other actions can be dispatched. Thunks are -// typically used to make async requests. -export const incrementAsync = createAsyncThunk( - 'counter/fetchCount', - async (amount) => { - const response = await fetchCount(amount); - // The value we return becomes the `fulfilled` action payload - return response.data; - } -); - -export const counterSlice = createSlice({ - name: 'counter', - initialState, - // The `reducers` field lets us define reducers and generate associated actions - reducers: { - increment: (state) => { - // Redux Toolkit allows us to write "mutating" logic in reducers. It - // doesn't actually mutate the state because it uses the Immer library, - // which detects changes to a "draft state" and produces a brand new - // immutable state based off those changes - state.value += 1; - }, - decrement: (state) => { - state.value -= 1; - }, - // Use the PayloadAction type to declare the contents of `action.payload` - incrementByAmount: (state, action) => { - state.value += action.payload; - }, - }, - // The `extraReducers` field lets the slice handle actions defined elsewhere, - // including actions generated by createAsyncThunk or in other slices. - extraReducers: (builder) => { - builder - .addCase(incrementAsync.pending, (state) => { - state.status = 'loading'; - }) - .addCase(incrementAsync.fulfilled, (state, action) => { - state.status = 'idle'; - state.value += action.payload; - }); - }, -}); - -export const { increment, decrement, incrementByAmount } = counterSlice.actions; - -// The function below is called a selector and allows us to select a value from -// the state. Selectors can also be defined inline where they're used instead of -// in the slice file. For example: `useSelector((state: RootState) => state.counter.value)` -export const selectCount = (state) => state.counter.value; - -// We can also write thunks by hand, which may contain both sync and async logic. -// Here's an example of conditionally dispatching actions based on current state. -export const incrementIfOdd = (amount) => (dispatch, getState) => { - const currentValue = selectCount(getState()); - if (currentValue % 2 === 1) { - dispatch(incrementByAmount(amount)); - } -}; - -export default counterSlice.reducer; diff --git a/src/features/counter/counterSlice.spec.js b/src/features/counter/counterSlice.spec.js deleted file mode 100644 index c1fed2c..0000000 --- a/src/features/counter/counterSlice.spec.js +++ /dev/null @@ -1,33 +0,0 @@ -import counterReducer, { - increment, - decrement, - incrementByAmount, -} from './counterSlice'; - -describe('counter reducer', () => { - const initialState = { - value: 3, - status: 'idle', - }; - it('should handle initial state', () => { - expect(counterReducer(undefined, { type: 'unknown' })).toEqual({ - value: 0, - status: 'idle', - }); - }); - - it('should handle increment', () => { - const actual = counterReducer(initialState, increment()); - expect(actual.value).toEqual(4); - }); - - it('should handle decrement', () => { - const actual = counterReducer(initialState, decrement()); - expect(actual.value).toEqual(2); - }); - - it('should handle incrementByAmount', () => { - const actual = counterReducer(initialState, incrementByAmount(2)); - expect(actual.value).toEqual(5); - }); -}); diff --git a/src/index.css b/src/index.css deleted file mode 100644 index ec2585e..0000000 --- a/src/index.css +++ /dev/null @@ -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; -} diff --git a/src/index.js b/src/index.js index 9cc8015..d273bb1 100644 --- a/src/index.js +++ b/src/index.js @@ -1,21 +1,12 @@ import React from 'react'; import ReactDOM from 'react-dom'; -import './index.css'; -import App from './App'; -import { store } from './app/store'; +import App from './components/App/App'; +import store from './components/App/store'; import { Provider } from 'react-redux'; -import * as serviceWorker from './serviceWorker'; ReactDOM.render( - - - - - , - document.getElementById('root') + + + , + document.getElementById('root') ); - -// If you want your app to work offline and load faster, you can change -// unregister() to register() below. Note this comes with some pitfalls. -// Learn more about service workers: https://bit.ly/CRA-PWA -serviceWorker.unregister(); diff --git a/src/logo.svg b/src/logo.svg deleted file mode 100644 index 8466738..0000000 --- a/src/logo.svg +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/reducers/CalcReducer.js b/src/reducers/CalcReducer.js new file mode 100644 index 0000000..fb53e67 --- /dev/null +++ b/src/reducers/CalcReducer.js @@ -0,0 +1,137 @@ +import { ADD_DIGIT, CHOOSE_OPERATION, EVALUATE } from '../actions/constants'; + +const initialState = { + currentOperand: null, + previousOperand: null, + operation: null, + evaluated: false, +}; + +const evaluate = ({ currentOperand, previousOperand, operation }) => { + const prev = parseFloat(previousOperand); + const current = parseFloat(currentOperand); + if (isNaN(prev) || isNaN(current)) { + return '0'; + } + + let computation = ''; + + switch (operation) { + case '+': + computation = prev + current; + break; + case '-': + computation = prev - current; + break; + case '/': + computation = prev / current; + break; + case 'x': + computation = prev * current; + break; + default: + return ''; + } + + return computation.toString(); +}; + +const calcReducer = (state = initialState, { type, payload }) => { + switch (type) { + case ADD_DIGIT: + if (state.currentOperand === null && payload === '.') { + return { + ...state, + currentOperand: '0.', + }; + } + + if ( + state.evaluated || + (state.currentOperand === null && payload !== '.') + ) { + return { + ...state, + currentOperand: payload, + evaluated: false, + }; + } + + if (state.currentOperand.length === 11) { + return state; + } + + if ( + payload === '0' && + (state.currentOperand === null || state.currentOperand === '0') + ) { + return state; + } + + if (payload === '.' && state.currentOperand.includes('.')) { + return state; + } + + return { + ...state, + currentOperand: `${state.currentOperand}${payload}`, + }; + + case CHOOSE_OPERATION: + if (state.currentOperand === null && state.previousOperand == null) { + return state; + } + + if ( + (!state.evaluated && state.currentOperand === null) || + (state.evaluated && state.currentOperand === state.previousOperand) || + (state.previousOperand && + state.currentOperand === null && + state.operation) + ) { + return { + ...state, + operation: payload, + }; + } + + if (state.previousOperand == null) { + return { + ...state, + operation: payload, + previousOperand: state.currentOperand, + currentOperand: null, + }; + } + + return { + ...state, + currentOperand: evaluate(state), + previousOperand: evaluate(state), + evaluated: true, + operation: payload, + }; + + case EVALUATE: + if ( + state.operation === null || + state.currentOperand === null || + state.previousOperand === null + ) { + return state; + } + + return { + ...state, + evaluated: true, + currentOperand: evaluate(state), + previousOperand: null, + operation: null, + }; + + default: + return state; + } +}; + +export default calcReducer; diff --git a/src/reducers/ConstructorReducer.js b/src/reducers/ConstructorReducer.js new file mode 100644 index 0000000..509f292 --- /dev/null +++ b/src/reducers/ConstructorReducer.js @@ -0,0 +1,66 @@ +import { + SET_DROPPABLE_SECTION, + SET_DRAGGABLE_BLOCK, + SET_BLOCKS, + DRAG_START, + DRAG_END, + CHANGE_CONSTRUCTOR_MODE, +} from '../actions/constants'; + +const initialState = { + draggableBlock: null, + droppableSection: null, + blocks: [ + { id: 1, name: 'display', component: 'Display' }, + { id: 2, name: 'operations', component: 'Operations' }, + { id: 3, name: 'digitalBlock', component: 'DigitalBlock' }, + { id: 4, name: 'equalBlock', component: 'EqualBlock' }, + ], + constructorModeEnable: true, +}; + +const constructorReducer = (state = initialState, { type, payload }) => { + switch (type) { + case CHANGE_CONSTRUCTOR_MODE: + return { + ...state, + constructorModeEnable: !state.constructorModeEnable, + }; + case SET_BLOCKS: + return { + ...state, + blocks: payload, + }; + case DRAG_START: + if (state.draggableBlock === payload) { + return { ...state }; + } + return { + ...state, + draggableBlock: payload, + }; + + case DRAG_END: + return { + ...state, + draggableBlock: null, + }; + + case SET_DROPPABLE_SECTION: + return { + ...state, + droppableSection: payload, + }; + + case SET_DRAGGABLE_BLOCK: + return { + ...state, + draggableBlock: payload, + }; + + default: + return state; + } +}; + +export default constructorReducer; diff --git a/src/reducers/reducer.js b/src/reducers/reducer.js new file mode 100644 index 0000000..f581b12 --- /dev/null +++ b/src/reducers/reducer.js @@ -0,0 +1,10 @@ +import calcReducer from './CalcReducer'; +import constructorReducer from './ConstructorReducer'; +import { combineReducers } from 'redux'; + +const rootReducer = combineReducers({ + calc: calcReducer, + drag: constructorReducer, +}); + +export default rootReducer; diff --git a/src/serviceWorker.js b/src/serviceWorker.js deleted file mode 100644 index 6f9c97b..0000000 --- a/src/serviceWorker.js +++ /dev/null @@ -1,137 +0,0 @@ -// This optional code is used to register a service worker. -// register() is not called by default. - -// This lets the app load faster on subsequent visits in production, and gives -// it offline capabilities. However, it also means that developers (and users) -// will only see deployed updates on subsequent visits to a page, after all the -// existing tabs open on the page have been closed, since previously cached -// resources are updated in the background. - -// To learn more about the benefits of this model and instructions on how to -// opt-in, read https://bit.ly/CRA-PWA - -const isLocalhost = Boolean( - window.location.hostname === 'localhost' || - // [::1] is the IPv6 localhost address. - window.location.hostname === '[::1]' || - // 127.0.0.0/8 are considered localhost for IPv4. - window.location.hostname.match( - /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ - ) -); - -export function register(config) { - if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { - // The URL constructor is available in all browsers that support SW. - const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href); - if (publicUrl.origin !== window.location.origin) { - // Our service worker won't work if PUBLIC_URL is on a different origin - // from what our page is served on. This might happen if a CDN is used to - // serve assets; see https://github.com/facebook/create-react-app/issues/2374 - return; - } - - window.addEventListener('load', () => { - const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; - - if (isLocalhost) { - // This is running on localhost. Let's check if a service worker still exists or not. - checkValidServiceWorker(swUrl, config); - - // Add some additional logging to localhost, pointing developers to the - // service worker/PWA documentation. - navigator.serviceWorker.ready.then(() => { - console.log( - 'This web app is being served cache-first by a service ' + - 'worker. To learn more, visit https://bit.ly/CRA-PWA' - ); - }); - } else { - // Is not localhost. Just register service worker - registerValidSW(swUrl, config); - } - }); - } -} - -function registerValidSW(swUrl, config) { - navigator.serviceWorker - .register(swUrl) - .then((registration) => { - registration.onupdatefound = () => { - const installingWorker = registration.installing; - if (installingWorker == null) { - return; - } - installingWorker.onstatechange = () => { - if (installingWorker.state === 'installed') { - if (navigator.serviceWorker.controller) { - // At this point, the updated precached content has been fetched, - // but the previous service worker will still serve the older - // content until all client tabs are closed. - console.log( - 'New content is available and will be used when all ' + - 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' - ); - - // Execute callback - if (config && config.onUpdate) { - config.onUpdate(registration); - } - } else { - // At this point, everything has been precached. - // It's the perfect time to display a - // "Content is cached for offline use." message. - console.log('Content is cached for offline use.'); - - // Execute callback - if (config && config.onSuccess) { - config.onSuccess(registration); - } - } - } - }; - }; - }) - .catch((error) => { - console.error('Error during service worker registration:', error); - }); -} - -function checkValidServiceWorker(swUrl, config) { - // Check if the service worker can be found. If it can't reload the page. - fetch(swUrl, { - headers: { 'Service-Worker': 'script' }, - }) - .then((response) => { - // Ensure service worker exists, and that we really are getting a JS file. - const contentType = response.headers.get('content-type'); - if ( - response.status === 404 || - (contentType != null && contentType.indexOf('javascript') === -1) - ) { - // No service worker found. Probably a different app. Reload the page. - navigator.serviceWorker.ready.then((registration) => { - registration.unregister().then(() => { - window.location.reload(); - }); - }); - } else { - // Service worker found. Proceed as normal. - registerValidSW(swUrl, config); - } - }) - .catch(() => { - console.log( - 'No internet connection found. App is running in offline mode.' - ); - }); -} - -export function unregister() { - if ('serviceWorker' in navigator) { - navigator.serviceWorker.ready.then((registration) => { - registration.unregister(); - }); - } -} diff --git a/src/setupTests.js b/src/setupTests.js deleted file mode 100644 index 74b1a27..0000000 --- a/src/setupTests.js +++ /dev/null @@ -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/extend-expect';