Skip to content

Commit 9bb8aff

Browse files
committed
First commit 🤩
0 parents  commit 9bb8aff

31 files changed

+2716
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Vue JSON Viewer
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
1+
# Vue 3 JSON Viewer
2+
3+
A modern, sleek Vue 3 component for viewing, editing, and manipulating JSON data with two view modes: Tree Mode and Text Mode.
4+
5+
## ✨ Features
6+
7+
- 🌳 **Tree Mode**: Hierarchical display with expandable/collapsible nodes
8+
- 📝 **Text Mode**: Raw JSON text display with syntax highlighting
9+
- ✏️ **Inline Editing**: Edit values directly in the tree view
10+
-**Add/Remove Nodes**: Add new key-value pairs or remove existing ones
11+
- 🔍 **Search & Filter**: Search across all JSON keys and values
12+
- 📋 **Copy to Clipboard**: Easy copying of JSON content
13+
- 💾 **Download JSON**: Save current JSON to file
14+
- 🎨 **Dark/Light Theme**: Support for both themes
15+
- 📱 **Responsive Design**: Works on desktop and mobile devices
16+
- ⌨️ **Keyboard Navigation**: Full keyboard support
17+
-**Accessibility**: Screen reader support with proper ARIA labels
18+
19+
## 🚀 Installation
20+
21+
```bash
22+
npm install vue3-json-viewer
23+
```
24+
25+
Or with yarn:
26+
27+
```bash
28+
yarn add vue3-json-viewer
29+
```
30+
31+
## 📖 Usage
32+
33+
### Basic Usage
34+
35+
```vue
36+
<template>
37+
<div>
38+
<JsonViewer
39+
v-model:data="jsonData"
40+
:editable="true"
41+
theme="light"
42+
default-mode="tree"
43+
@update:data="handleDataUpdate"
44+
/>
45+
</div>
46+
</template>
47+
48+
<script setup lang="ts">
49+
import { ref } from 'vue'
50+
import JsonViewer from 'vue3-json-viewer'
51+
52+
const jsonData = ref({
53+
name: "John Doe",
54+
age: 30,
55+
active: true,
56+
hobbies: ["reading", "coding"],
57+
address: {
58+
street: "123 Main St",
59+
city: "Anytown"
60+
}
61+
})
62+
63+
const handleDataUpdate = (newData: any) => {
64+
console.log('Data updated:', newData)
65+
}
66+
</script>
67+
```
68+
69+
### Advanced Usage
70+
71+
```vue
72+
<template>
73+
<JsonViewer
74+
v-model:data="complexData"
75+
:editable="true"
76+
:theme="currentTheme"
77+
default-mode="tree"
78+
:show-line-numbers="true"
79+
:max-depth="3"
80+
@update:data="handleDataUpdate"
81+
@node-click="handleNodeClick"
82+
@node-expand="handleNodeExpand"
83+
@node-collapse="handleNodeCollapse"
84+
@edit-start="handleEditStart"
85+
@edit-save="handleEditSave"
86+
@edit-cancel="handleEditCancel"
87+
/>
88+
</template>
89+
90+
<script setup lang="ts">
91+
import { ref } from 'vue'
92+
import JsonViewer from 'vue3-json-viewer'
93+
94+
const complexData = ref({
95+
// Your complex JSON data
96+
})
97+
98+
const currentTheme = ref<'light' | 'dark'>('light')
99+
100+
// Event handlers
101+
const handleDataUpdate = (newData: any) => {
102+
console.log('Data updated:', newData)
103+
}
104+
105+
const handleNodeClick = (node: any) => {
106+
console.log('Node clicked:', node)
107+
}
108+
109+
const handleNodeExpand = (node: any) => {
110+
console.log('Node expanded:', node)
111+
}
112+
113+
const handleNodeCollapse = (node: any) => {
114+
console.log('Node collapsed:', node)
115+
}
116+
117+
const handleEditStart = () => {
118+
console.log('Edit mode started')
119+
}
120+
121+
const handleEditSave = (data: any) => {
122+
console.log('Changes saved:', data)
123+
}
124+
125+
const handleEditCancel = () => {
126+
console.log('Edit cancelled')
127+
}
128+
</script>
129+
```
130+
131+
## 📋 Props
132+
133+
| Prop | Type | Default | Description |
134+
|------|------|---------|-------------|
135+
| `data` | `any` | `{}` | JSON data to display |
136+
| `editable` | `boolean` | `true` | Enable editing capabilities |
137+
| `theme` | `'light' \| 'dark'` | `'light'` | Theme preference |
138+
| `defaultMode` | `'tree' \| 'text'` | `'tree'` | Default view mode |
139+
| `showLineNumbers` | `boolean` | `false` | Show line numbers in text mode |
140+
| `maxDepth` | `number` | `3` | Maximum depth to expand by default |
141+
142+
## 🎭 Events
143+
144+
| Event | Payload | Description |
145+
|-------|---------|-------------|
146+
| `update:data` | `newData: any` | Data changed event |
147+
| `node-click` | `node: JsonNode` | Node clicked event |
148+
| `node-expand` | `node: JsonNode` | Node expanded event |
149+
| `node-collapse` | `node: JsonNode` | Node collapsed event |
150+
| `edit-start` | - | Edit mode started |
151+
| `edit-save` | `data: any` | Changes saved |
152+
| `edit-cancel` | - | Edit mode cancelled |
153+
154+
## 🏗️ Data Structure
155+
156+
```typescript
157+
interface JsonNode {
158+
key: string;
159+
value: any;
160+
type: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'null';
161+
path: string[];
162+
level: number;
163+
expanded?: boolean;
164+
children?: JsonNode[];
165+
}
166+
```
167+
168+
## 🎨 Styling
169+
170+
The component uses CSS custom properties for theming. You can customize the appearance by overriding these variables:
171+
172+
```css
173+
.json-viewer {
174+
--bg-primary: #ffffff;
175+
--bg-secondary: #f8fafc;
176+
--bg-tertiary: #f1f5f9;
177+
--text-primary: #1e293b;
178+
--text-secondary: #64748b;
179+
--border-color: #e2e8f0;
180+
--accent-color: #3b82f6;
181+
--hover-color: #f1f5f9;
182+
--success-color: #10b981;
183+
--error-color: #ef4444;
184+
--warning-color: #f59e0b;
185+
}
186+
```
187+
188+
## 🛠️ Development
189+
190+
### Setup
191+
192+
```bash
193+
# Clone the repository
194+
git clone https://github.com/jeevan-lal/vue3-json-viewer.git
195+
196+
# Install dependencies
197+
npm install
198+
199+
# Start development server
200+
npm run dev
201+
```
202+
203+
### Build
204+
205+
```bash
206+
# Build for production
207+
npm run build
208+
209+
# Preview production build
210+
npm run preview
211+
```
212+
213+
### Lint
214+
215+
```bash
216+
# Run ESLint
217+
npm run lint
218+
219+
# Type check
220+
npm run type-check
221+
```
222+
223+
## 🧪 Testing
224+
225+
Run the test suite:
226+
227+
```bash
228+
npm run test
229+
```
230+
231+
## 📱 Browser Support
232+
233+
- Chrome ≥ 87
234+
- Firefox ≥ 78
235+
- Safari ≥ 14
236+
- Edge ≥ 88
237+
238+
## 🤝 Contributing
239+
240+
Contributions are welcome! Please feel free to submit a Pull Request.
241+
242+
1. Fork the repository
243+
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
244+
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
245+
4. Push to the branch (`git push origin feature/AmazingFeature`)
246+
5. Open a Pull Request
247+
248+
## 📄 License
249+
250+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
251+
252+
## 🙏 Acknowledgments
253+
254+
- Icons provided by [Heroicons](https://heroicons.com/)
255+
- Font families: [Inter](https://rsms.me/inter/) and [Fira Code](https://github.com/tonsky/FiraCode)
256+
- Built with [Vue 3](https://vuejs.org/) and [Vite](https://vitejs.dev/)
257+
258+
## 📞 Support
259+
260+
If you have any questions or need help, please:
261+
262+
1. Check the [documentation](#-usage)
263+
2. Search [existing issues](https://github.com/jeevan-lal/vue3-json-viewer/issues)
264+
3. Create a [new issue](https://github.com/jeevan-lal/vue3-json-viewer/issues/new)
265+
266+
---
267+
268+
Made with ❤️ and Vue 3

index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vue 3 JSON Viewer</title>
8+
<link rel="preconnect" href="https://fonts.googleapis.com">
9+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
10+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Fira+Code:wght@400;500&display=swap" rel="stylesheet">
11+
</head>
12+
<body>
13+
<div id="app"></div>
14+
<script type="module" src="/src/main.ts"></script>
15+
</body>
16+
</html>

package.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"name": "vue3-json-viewer",
3+
"version": "1.0.0",
4+
"description": "A modern, sleek Vue 3 JSON viewer component with tree and text modes",
5+
"main": "src/components/JsonViewer.vue",
6+
"scripts": {
7+
"dev": "vite",
8+
"build": "vue-tsc && vite build",
9+
"preview": "vite preview",
10+
"lint": "eslint src --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
11+
"type-check": "vue-tsc --noEmit"
12+
},
13+
"dependencies": {
14+
"vue": "^3.3.4"
15+
},
16+
"devDependencies": {
17+
"@types/node": "^20.0.0",
18+
"@typescript-eslint/eslint-plugin": "^6.0.0",
19+
"@typescript-eslint/parser": "^6.0.0",
20+
"@vitejs/plugin-vue": "^4.2.3",
21+
"@vue/eslint-config-typescript": "^11.0.0",
22+
"@vue/tsconfig": "^0.4.0",
23+
"eslint": "^8.45.0",
24+
"eslint-plugin-vue": "^9.15.0",
25+
"typescript": "~5.1.6",
26+
"vite": "^4.4.5",
27+
"vue-tsc": "^1.8.5"
28+
},
29+
"keywords": [
30+
"vue",
31+
"vue3",
32+
"json",
33+
"viewer",
34+
"editor",
35+
"tree",
36+
"typescript",
37+
"composition-api"
38+
],
39+
"author": "Vue JSON Viewer",
40+
"license": "MIT",
41+
"repository": {
42+
"type": "git",
43+
"url": "https://github.com/jeevan-lal/vue3-json-viewer.git"
44+
},
45+
"bugs": {
46+
"url": "https://github.com/jeevan-lal/vue3-json-viewer/issues"
47+
},
48+
"homepage": "https://github.com/jeevan-lal/vue3-json-viewer#readme"
49+
}

0 commit comments

Comments
 (0)