view-api 3.0.2 → 3.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "view-api",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
4
4
  "description": "Run mock APIs locally from a JSON configuration file",
5
5
  "type": "module",
6
6
  "bin": {
@@ -76,3 +76,23 @@ function showStatus(text, isError) {
76
76
  statusEl.style.opacity = "0";
77
77
  }, 2500);
78
78
  }
79
+
80
+ // Prettify button
81
+ document.getElementById("prettify-btn").addEventListener("click", () => {
82
+ try {
83
+ const value = editor.state.doc.toString();
84
+ const pretty = JSON.stringify(JSON.parse(value), null, 2);
85
+
86
+ editor.dispatch({
87
+ changes: {
88
+ from: 0,
89
+ to: editor.state.doc.length,
90
+ insert: pretty,
91
+ },
92
+ });
93
+
94
+ showStatus("Prettified ✓", false);
95
+ } catch {
96
+ showStatus("Invalid JSON ✗", true);
97
+ }
98
+ });
@@ -6,6 +6,7 @@
6
6
  <link rel="stylesheet" href="./style.css" />
7
7
  </head>
8
8
  <body>
9
+ <button id="prettify-btn" title="Prettify JSON">⚡ Prettify</button>
9
10
  <div id="editor"></div>
10
11
  <div id="status"></div>
11
12
 
@@ -38,3 +38,26 @@ body {
38
38
  background: #7f1d1d;
39
39
  color: #fecaca;
40
40
  }
41
+
42
+ #prettify-btn {
43
+ background: #3b82f6;
44
+ color: #fff;
45
+ border: none;
46
+ border-radius: 6px;
47
+ padding: 6px 14px;
48
+ font-size: 18px;
49
+ font-family: inherit;
50
+ cursor: pointer;
51
+ position: fixed;
52
+ top: 10px;
53
+ right: 10px;
54
+ z-index: 1000;
55
+ }
56
+
57
+ #prettify-btn:hover {
58
+ background: #2563eb;
59
+ }
60
+
61
+ #prettify-btn:active {
62
+ background: #1d4ed8;
63
+ }