瀏覽代碼

песочница песочит

Maik 3 年之前
父節點
當前提交
c85b2f8d9d
共有 6 個文件被更改,包括 119 次插入16 次删除
  1. 32 0
      front/package-lock.json
  2. 2 1
      front/package.json
  3. 1 0
      front/public/index.html
  4. 15 7
      front/src/App.css
  5. 68 7
      front/src/App.js
  6. 1 1
      front/src/reducers/userR.js

+ 32 - 0
front/package-lock.json

@@ -2774,6 +2774,11 @@
         "negotiator": "0.6.2"
       }
     },
+    "ace-builds": {
+      "version": "1.4.12",
+      "resolved": "https://registry.npmjs.org/ace-builds/-/ace-builds-1.4.12.tgz",
+      "integrity": "sha512-G+chJctFPiiLGvs3+/Mly3apXTcfgE45dT5yp12BcWZ1kUs+gm0qd3/fv4gsz6fVag4mM0moHVpjHDIgph6Psg=="
+    },
     "acorn": {
       "version": "7.4.1",
       "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz",
@@ -5085,6 +5090,11 @@
         }
       }
     },
+    "diff-match-patch": {
+      "version": "1.0.5",
+      "resolved": "https://registry.npmjs.org/diff-match-patch/-/diff-match-patch-1.0.5.tgz",
+      "integrity": "sha512-IayShXAgj/QMXgB0IWmKx+rOPuGMhqm5w6jvFxmVenXKIzRqTAAsbBPT3kWQeGANj3jGgvcvv4yK6SxqYmikgw=="
+    },
     "diff-sequences": {
       "version": "26.6.2",
       "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-26.6.2.tgz",
@@ -9833,6 +9843,16 @@
       "resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz",
       "integrity": "sha1-gteb/zCmfEAF/9XiUVMArZyk168="
     },
+    "lodash.get": {
+      "version": "4.4.2",
+      "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz",
+      "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk="
+    },
+    "lodash.isequal": {
+      "version": "4.5.0",
+      "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz",
+      "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA="
+    },
     "lodash.memoize": {
       "version": "4.1.2",
       "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz",
@@ -12394,6 +12414,18 @@
         "object-assign": "^4.1.1"
       }
     },
+    "react-ace": {
+      "version": "9.4.1",
+      "resolved": "https://registry.npmjs.org/react-ace/-/react-ace-9.4.1.tgz",
+      "integrity": "sha512-vhOFrB5Xy++mcPNc6wc1mwMFP/FZOnYxQPqgRl/dLfkZBbrJf4SAgXaa6PU4AXWu1u5bfxOmRwwHaZPrLb6d9Q==",
+      "requires": {
+        "ace-builds": "^1.4.12",
+        "diff-match-patch": "^1.0.4",
+        "lodash.get": "^4.4.2",
+        "lodash.isequal": "^4.5.0",
+        "prop-types": "^15.7.2"
+      }
+    },
     "react-app-polyfill": {
       "version": "2.0.0",
       "resolved": "https://registry.npmjs.org/react-app-polyfill/-/react-app-polyfill-2.0.0.tgz",

+ 2 - 1
front/package.json

@@ -8,6 +8,7 @@
     "@testing-library/user-event": "^12.8.3",
     "axios": "^0.21.1",
     "react": "^17.0.2",
+    "react-ace": "^9.4.1",
     "react-dom": "^17.0.2",
     "react-redux": "^7.2.4",
     "react-router-dom": "^5.2.0",
@@ -29,7 +30,7 @@
       "react-app/jest"
     ]
   },
-  "proxy":"http://localhost:4000/",
+  "proxy": "http://localhost:4000/",
   "browserslist": {
     "production": [
       ">0.2%",

+ 1 - 0
front/public/index.html

@@ -9,6 +9,7 @@
       name="description"
       content="Web site created using create-react-app"
     />
+    <link href="https://fonts.googleapis.com/css2?family=Jost:wght@300&family=Lobster+Two:ital,wght@1,700&display=swap" rel="stylesheet">
     <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
     <!--
       manifest.json provides metadata used when your web app is installed on a

+ 15 - 7
front/src/App.css

@@ -16,11 +16,12 @@ a{
   text-decoration: none;
   color: yellow;
   font-family: 'Jost', sans-serif;
+  font-size: 20px;
   margin: 5px;
   transition: 0.3s;
 }
 .logo{
-  font-family: 'Lobster Two', cursive;
+  font-family: 'Jost', sans-serif;
   font-size: 40px;
   margin: 0 0 60px 5px ;  
 }
@@ -50,10 +51,6 @@ a{
 .lr_title{
   font-size: 30px;
 }
-.links:hover{
-
-  font-size: 20px;
-}
 legend{
   color: yellow;
 }
@@ -84,6 +81,17 @@ legend{
   text-decoration: none;
   color: yellow;
 }
+.legend3 {
+  position: absolute;
+  bottom: 0.5em;
+  right: 35px;
+  font-size: 20px;
+  background-color: black;
+  line-height:1.2em;
+  text-decoration: none;
+  color: yellow;
+  cursor: pointer;
+}
 .dev{
   width: 33%;
   height: 400px;
@@ -99,7 +107,7 @@ legend{
   color: yellow;
   outline:none;
 }
-.oput{
+.body{
   position: absolute;
   right: 0;
   top:550px;
@@ -126,7 +134,7 @@ legend{
     cursor: pointer;
 }
 .nameProj {
-  width: 90%;
+  width: 96.5%;
   resize: none;
   border: none;
   background-color: rgb(0, 0, 0);

+ 68 - 7
front/src/App.js

@@ -5,6 +5,67 @@ import { useHttp  } from './hooks/httpReqest'
 import { setUser , logout } from './reducers/userR';
 import {useSelector , useDispatch} from 'react-redux'
 
+import AceEditor from "react-ace";
+import "ace-builds/src-noconflict/mode-html";
+import "ace-builds/src-noconflict/mode-css";
+import "ace-builds/src-noconflict/mode-javascript";
+import "ace-builds/src-noconflict/theme-terminal";
+import "ace-builds/src-noconflict/ext-language_tools"
+
+const Sandbox =()=>{
+
+  let codeHTML 
+  let codeCSS 
+  let codeJS 
+  let title
+
+  let saveProject 
+
+  const htmlCodeGenerator=(codeHTML)=>{
+    const htmlOutput = document.getElementById("htmlOutput")
+    htmlOutput.innerHTML=codeHTML
+  }
+
+  const cssCodeGenerator=(codeCSS)=>{
+    const cssOutput = document.getElementById("cssOutput")
+    var trueCSS = codeCSS.replace(/body/gi, '.body')
+    cssOutput.innerHTML=`<style type="text/css" id="styl">${trueCSS}</style>`
+  }
+
+  let jsnov
+  const runJsCode =()=>{
+    eval(jsnov)
+  }
+
+  return(
+    <div>
+      <fieldset className="title">
+        <legend>Title</legend>
+        <textarea className="nameProj" name="title">{title}</textarea>
+        <button className='saveProject' type='button' onClick={saveProject} >save</button>
+      </fieldset>
+       <form className="ide">
+        <fieldset className="dev">
+          <legend>codeHTML</legend>
+          <AceEditor className="windDev" onChange={htmlCodeGenerator} id="coderHTML" placeholder="your html code could be here ..." mode="html" value={codeHTML} theme="terminal" name="coderHTML"  fontSize={14} showPrintMargin={true} showGutter={true} highlightActiveLine={true} setOptions={{ enableBasicAutocompletion: true, enableLiveAutocompletion: true, enableSnippets: true, showLineNumbers: true,tabSize: 2,}} style={{height:"380px",width:"100%"}}/>,
+        </fieldset>
+        <fieldset className="dev">
+          <legend>codeCSS</legend>
+          <AceEditor className="windDev" onChange={cssCodeGenerator} placeholder="your css code could be here ..." mode="css" value={codeCSS} theme="terminal" name="blah2"  fontSize={14} showPrintMargin={true} showGutter={true} highlightActiveLine={true} setOptions={{ enableBasicAutocompletion: true, enableLiveAutocompletion: true, enableSnippets: true, showLineNumbers: true,tabSize: 2,}} style={{height:"380px",width:"100%"}}/>,
+        </fieldset><fieldset className="dev">
+          <legend>codeJS</legend>
+          <AceEditor className="windDev" onChange={(cods)=>{jsnov=cods}} placeholder="your js code could be here ..." mode="javascript" theme="terminal" name="blah2"  fontSize={14} showPrintMargin={true} showGutter={true} highlightActiveLine={true} value={codeJS} setOptions={{ enableBasicAutocompletion: true, enableLiveAutocompletion: true, enableSnippets: true, showLineNumbers: true,tabSize: 2,}} style={{height:"380px",width:"100%"}}/>,
+          <a className="legend3" onClick={runJsCode}>run script</a>
+        </fieldset>    
+      </form>
+      <fieldset className="body" style={{backgroundColor:"#2f0000"} }>
+      <legend>outPut</legend>
+        <div  id="htmlOutput"/>
+        <div  id="cssOutput"/>
+      </fieldset>
+    </div>
+  )
+}
 
 const AuthorizationLogin = () =>{
   const [email,setEmail]=useState('')
@@ -131,13 +192,14 @@ const AuthorizationRegistration = () =>{
         {(emailWrong&&emailError)&& <p style={{color:'orange'}}>{emailError}</p>}
         {(passwordWrong&&passwordError) && <p style={{color:'orange'}}>{passwordError}</p>}
       </form>
-      <a href="/" className="legend2">Login</a>
+      <a href="/login" className="legend2">Login</a>
     </fieldset>
   )
 }
 
 
 
+
 const App =()=>{
   const isAuthorization = useSelector(state => state.user.isAuth)
   const dispatch =useDispatch()
@@ -158,25 +220,24 @@ const App =()=>{
   useEffect(()=>{
     dispatch(authorization())
   },[])
-
-
-
-
   return(
         <BrowserRouter>
           <div className="navBar">
             <h1 className="logo"><a href="/">SandBox</a></h1>
             <a href="/Project" className="links">Project</a>
             <a href="/my_project" className="links">My project</a>
-            <a href="/sandbox" className="links">Sandbox</a>
+            <a href="/" className="links">Sandbox</a>
             {isAuthorization && <a onClick={()=>dispatch(logout())} className="links" style={{cursor:"pointer"}}>Exit</a>}
           </div>
           {!isAuthorization &&
           <Switch>
-            <Route path="/" component={AuthorizationLogin} exact/>
+            <Route path="/login" component={AuthorizationLogin}/>
             <Route path="/registration" component={AuthorizationRegistration}/>
           </Switch>
           }
+          <Switch>
+            <Route path="/" component={Sandbox} exact/>
+          </Switch>
         </BrowserRouter>)
 }
 

+ 1 - 1
front/src/reducers/userR.js

@@ -10,7 +10,7 @@ export default function userReduser(state= defaultState, action){
         case SET_USER:
             return{
                 ...state,
-                currentUser: action.payload.user,
+                currentUser: action.payload,
                 isAuth: true
             }
         case LOGOUT: