-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Json dom styled counting input fix console fix doc done cell modification fix
- Loading branch information
Showing
18 changed files
with
522 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,27 @@ | ||
# scripter | ||
i hate python, so i build a jupyter notebook for javascript | ||
|
||
|
||
https://stackoverflow.com/questions/1340872/how-to-get-javascript-caller-function-line-number-and-caller-source-url/37081135#37081135 | ||
|
||
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval | ||
|
||
https://github.com/WebDevSimplified/React-CodePen-Clone/tree/master | ||
|
||
|
||
``` | ||
var regex = /\((.*?)\)/; | ||
let x =1 | ||
var strToMatch = `console.log(x + 1)` | ||
var matched = regex.exec(strToMatch); | ||
console.log(eval(matched[1])) | ||
eval(strToMatch) | ||
``` | ||
|
||
|
||
``` | ||
console.stdlog = console.log.bind(console); | ||
console.logs = []; | ||
console.log = function(){ | ||
console.logs.push(Array.from(arguments)); | ||
console.stdlog.apply(console, arguments); | ||
import type { User } from '../interfaces' | ||
import useSwr from 'swr' | ||
import Link from 'next/link' | ||
const fetcher = (url: string) => fetch(url).then((res) => res.json()) | ||
export default function Index() { | ||
const { data, error, isLoading } = useSwr<User[]>('/api/users', fetcher) | ||
if (error) return <div>Failed to load users</div> | ||
if (isLoading) return <div>Loading...</div> | ||
if (!data) return null | ||
return ( | ||
<ul> | ||
{data.map((user) => ( | ||
<li key={user.id}> | ||
<Link href="/user/[id]" as={`/user/${user.id}`}> | ||
{user.name ?? `User ${user.id}`} | ||
</Link> | ||
</li> | ||
))} | ||
</ul> | ||
) | ||
} | ||
``` | ||
|
||
``` | ||
// js = js.replace("console.log", "alert"); | ||
// var regex = /\((.*?)\)/; | ||
// var strToMatch = "This is a test string (more or less)"; | ||
// var matched = regex.exec(strToMatch); | ||
// console.log(matched[1]); | ||
// var content = template(jsEditor.value); | ||
``` | ||
|
||
|
||
``` | ||
onInput={()=>hljs.highlightAll()} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,4 @@ | ||
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). | ||
|
||
## Getting Started | ||
|
||
First, run the development server: | ||
|
||
```bash | ||
npm run dev | ||
# or | ||
yarn dev | ||
# or | ||
pnpm dev | ||
``` | ||
|
||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. | ||
|
||
You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file. | ||
|
||
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.js`. | ||
|
||
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages. | ||
|
||
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font. | ||
|
||
## Learn More | ||
|
||
To learn more about Next.js, take a look at the following resources: | ||
|
||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. | ||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. | ||
|
||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! | ||
|
||
## Deploy on Vercel | ||
|
||
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. | ||
|
||
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. | ||
let domData = document.querySelectorAll('[data-language=json]')[0].innerText | ||
console.log(JSON.parse(domData)) | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import Codespace from '@/components/codemirror' | ||
import { useEffect, useImperativeHandle,forwardRef, useState } from 'react' | ||
import useSwr from 'swr' | ||
import styles from '@/styles/Home.module.scss' | ||
|
||
function removeElementAtIndex(arr, index) { | ||
if (index < 0 || index >= arr.length) { | ||
throw new Error('Index out of bounds'); | ||
} | ||
const newArr = [...arr]; | ||
newArr.splice(index, 1); | ||
return newArr; | ||
} | ||
|
||
|
||
const fetcher = (url) => fetch(url).then((res) => res.json()) | ||
const CodeSpaceContainer = forwardRef((props, ref) => { | ||
const fileName = props.fileName | ||
const {data: code, error: codeError, isLoading: codeLoading} = useSwr(`api/code/${fileName}`, fetcher) | ||
const [cells, setCells] = useState([]) | ||
|
||
|
||
useImperativeHandle(ref, () => ({ | ||
deleteAllCell: () => setCells([]) | ||
})) | ||
|
||
useEffect(() => { | ||
if (code) setCells(() => code) | ||
}, [code]); | ||
|
||
if (codeError) return <p>Failed to Load</p> | ||
if (codeLoading) return <div className="spinner-border text-white m-auto" role="status"><span className="sr-only"></span></div> | ||
|
||
|
||
|
||
function newCell(){ | ||
const x = { | ||
init: '// start coding here', | ||
output: '' | ||
} | ||
setCells((cells) => [...cells, x]) | ||
} | ||
const deleteCell = (index) => setCells(cells.filter((value, arrIndex) => index !== arrIndex)) | ||
const clearCell = (index) => setCells((cells) => cells.map((cell, arrIndex) => index === arrIndex ? {output:' ', init: ' '} : cell )) | ||
|
||
return ( | ||
<> | ||
{cells.length > 0? | ||
cells.map((eachCell, i)=>(<Codespace key={i} index={i} data={eachCell} func={{deleteFunc:deleteCell, clearFunc: clearCell}} />)) | ||
: <span className='d-flex flex-column align-items-center'><p className='text-white-50'>Create new cell to start coding</p> | ||
<i className="bi bi-arrow-down text-white-50"/></span> | ||
} | ||
<ul className='d-flex gap-3'> | ||
<button onClick={newCell} className={styles.Button}> | ||
Add Cell <i className="bi bi-plus-square-fill"></i> | ||
</button> | ||
<button disabled className={styles.Button}> | ||
Markdown <i className="bi bi-hash"></i> | ||
</button> | ||
<button disabled className={styles.Button}> | ||
Web Builder <i className="bi bi-filetype-html"></i> | ||
</button> | ||
</ul> | ||
</> | ||
) | ||
}) | ||
|
||
export default CodeSpaceContainer; |
Oops, something went wrong.
4db6a77
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
scripter – ./
scriptw.vercel.app
scripter-git-main-rajatsandeepsen.vercel.app
scripter-rajatsandeepsen.vercel.app