Skip to content

Commit

Permalink
Init project.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jul 22, 2021
0 parents commit c8028c6
Show file tree
Hide file tree
Showing 15 changed files with 411 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Build & Deploy
on:
push:
branches:
- main

jobs:
build-deploy:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 14

- run: npm install
- run: npm run build
- run: npm run coverage

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./build
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
coverage
build
node_modules
npm-debug.log*
package-lock.json

.eslintcache
.DS_Store
.cache
.vscode

*.bak
*.tem
*.temp
#.swp
*.*~
~*.*
18 changes: 18 additions & 0 deletions .kktrc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import webpack, { Configuration } from 'webpack';
import lessModules from '@kkt/less-modules';
import { LoaderConfOptions } from 'kkt';
import pkg from './package.json';

export default (conf: Configuration, env: 'development' | 'production', options: LoaderConfOptions) => {
conf = lessModules(conf, env, options);
// Get the project version.
conf.plugins!.push(
new webpack.DefinePlugin({
VERSION: JSON.stringify(pkg.version),
}),
);
if (env === 'production') {
conf.output = { ...conf.output, publicPath: './' };
}
return conf;
};
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Basic Example for TypeScript
===

Use an example of `TypeScript`.

## Quick Start

```bash
$ npx create-kkt my-app -e typescript
cd my-app
npm install
```

## Open in CodeSandbox

[![Open in CodeSandbox](https://img.shields.io/badge/Open%20in-CodeSandbox-blue?logo=codesandbox)](https://codesandbox.io/s/github/kktjs/kkt/tree/master/example/typescript)

## Development

**development**

Runs the project in development mode.

```bash
npm run start
```

**production**

Builds the app for production to the build folder.

```bash
npm run build
```

The build is minified and the filenames include the hashes.
Your app is ready to be deployed!
59 changes: 59 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"name": "json-viewer",
"version": "1.0.0",
"description": "Online JSON Viewer, JSON Beautifier to beautify and tree view of JSON data - It works as JSON Pretty Print to pretty print JSON data.",
"private": true,
"scripts": {
"start": "kkt start",
"build": "kkt build",
"test": "kkt test --env=jsdom",
"coverage": "kkt test --env=jsdom --coverage"
},
"repository": {
"type": "git",
"url": "https://github.com/uiwjs/json-viewer.git"
},
"author": "",
"license": "MIT",
"dependencies": {
"@uiw/react-copy-to-clipboard": "4.9.1",
"@uiw/react-github-corners": "1.4.0",
"@uiw/react-split": "5.7.4",
"@uiw/react-textarea-code-editor": "1.3.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-json-view": "1.21.3"
},
"devDependencies": {
"@kkt/less-modules": "6.11.0",
"@types/react": "17.0.14",
"@types/react-dom": "17.0.9",
"kkt": "6.11.0"
},
"jest": {
"testMatch": [
"<rootDir>/src/**/*.test.{ts,tsx}"
],
"collectCoverageFrom": [
"<rootDir>/src/app/*.{tsx,ts}"
]
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Binary file added public/favicon.ico
Binary file not shown.
31 changes: 31 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<meta name="description" content="Online JSON Viewer, JSON Beautifier to beautify and tree view of JSON data - It works as JSON Pretty Print to pretty print JSON data.">
<meta name="keywords" content="json viewer,json beautifier,json pretty print,online json viewer,pretty json,format json, json reader,json pretty, pretty print json,beautify json,json file viewer,prettify json, json converter,json viewer online">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<title>Best JSON Viewer and JSON Beautifier Online</title>
</head>

<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>

</html>
25 changes: 25 additions & 0 deletions src/app/App.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.app {
height: 100%;
}

.message {
background: #ff000087;
padding: 2px 4px;
border-radius: 2px;
color: white;
}

.toolbar {
padding: 0 5px;
font-size: 12px;
border-top: 1px solid #d5d5d5;
background: #fff;
height: 28px;
position: absolute;
bottom: 0;
left: 0;
right: 0;
display: flex;
align-items: center;
justify-content: space-between;
}
9 changes: 9 additions & 0 deletions src/app/App.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
});
119 changes: 119 additions & 0 deletions src/app/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import React, { useCallback, useEffect, useRef} from 'react';
import Split from '@uiw/react-split';
import CodeEditor, { SelectionText } from '@uiw/react-textarea-code-editor';
import JsonViewer from 'react-json-view';
import styles from './App.module.css';

const App = () => {
const textareaRef = useRef<HTMLTextAreaElement>(null);
const colElm = useRef<HTMLSpanElement>(null);
const selectedElm = useRef<HTMLSpanElement>(null);
const [code, setCode] = React.useState('');
const [json, setJson] = React.useState();
const [message, setMessage] = React.useState('');

const handleJson = useCallback(() => {
setMessage('');
try {
if (code) {
const obj = JSON.parse(code);
setJson(obj);
}
} catch (error) {
setMessage(error.message);
setJson(undefined)
}
}, [code]);

const formatJson = useCallback((_, replacer: number = 2) => {
setMessage('');
try {
if (code) {
const obj = JSON.parse(code);
const str = JSON.stringify(obj, null, replacer);
setCode(str);
}
} catch (error) {
setMessage(error.message);
setJson(undefined)
}
}, [code]);

const handleSelect = useCallback((evn: React.SyntheticEvent<HTMLTextAreaElement>) => {
handleColLn(evn.target as HTMLTextAreaElement);
}, []);

const handleColLn = (target: HTMLTextAreaElement | null) => {
if (!target) {
return
}
const result = new SelectionText(target as HTMLTextAreaElement);
colElm.current!.innerHTML = result.end as unknown as string;
selectedElm.current!.innerHTML = result.end - result.start === 0 ? '' : ` selected(${result.end - result.start})`;
}

useEffect(() => {
handleColLn(textareaRef.current)
}, []);

useEffect(() => {
handleJson()
}, [code, handleJson]);

return (
<div className={styles.app}>
<Split>
<div style={{ minWidth: 230, width: '45%', position: 'relative', backgroundColor: 'rgb(245, 245, 245)' }}>
<div style={{overflow: 'auto',height: '100%', paddingBottom: 25, boxSizing: 'border-box' }}>
<CodeEditor
value={code}
language="json"
placeholder="Please enter JSON code."
ref={textareaRef}
onChange={(evn) => setCode(evn.target.value)}
padding={5}
onMouseMove={handleSelect}
onSelect={handleSelect}
style={{
minHeight: '100%',
fontSize: 12,
backgroundColor: "#f5f5f5",
fontFamily: 'ui-monospace,SFMono-Regular,SF Mono,Consolas,Liberation Mono,Menlo,monospace',
}}
/>
</div>
<div className={styles.toolbar}>
<div>
<button onClick={formatJson}>
Format
</button>
<button onClick={() => formatJson(null, 0)}>
Compress
</button>
</div>
<div>
<span ref={colElm} /><span ref={selectedElm} />
</div>
<div>
{message && (
<div className={styles.message}>{message}</div>
)}
</div>
</div>
</div>
<div style={{ flex: 1, minWidth: 230, userSelect: 'none', padding: 10, overflow: 'auto' }}>
{message && (
<pre style={{ padding: 0, margin: 0 }}>
{message}
</pre>
)}
{json && typeof json == 'object' && (
<JsonViewer src={json!} theme="rjv-default" style={{ }} displayDataTypes={false} />
)}
</div>
</Split>
</div>
)
};

export default App;
7 changes: 7 additions & 0 deletions src/app/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
body {
margin: 0;
padding: 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;
}

body, html, #root {
height: 100%;
}
6 changes: 6 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './app/App';
import './index.css';

ReactDOM.render(<App />, document.getElementById('root'));
Loading

0 comments on commit c8028c6

Please sign in to comment.