lone-format 0.1.0
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/LICENSE +21 -0
- package/README.md +2 -0
- package/dist/index.d.ts +3 -0
- package/dist/lone-format.css +1 -0
- package/dist/lone-format.js +452 -0
- package/dist/lone-format.umd.cjs +1 -0
- package/dist/src/components/JsonFormat/JsonNode.vue.d.ts +65 -0
- package/dist/src/components/JsonFormat/index.vue.d.ts +56 -0
- package/dist/src/components/JsonFormat/types.d.ts +36 -0
- package/dist/src/components/index.d.ts +2 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/vite.svg +1 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 lonisletend
|
|
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.
|
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.json-node[data-v-ac834fbd]{font-family:Monaco,Consolas,Lucida Console,Courier New,ui-monospace,SFMono-Regular,SF Mono,Liberation Mono,Menlo,monospace}.json-node__container[data-v-ac834fbd]{display:block}.json-node__line[data-v-ac834fbd]{display:flex;align-items:baseline;margin-left:calc(var(--623b775d) * 20px)}.json-node__child[data-v-ac834fbd]{position:relative;display:inline-block;width:100%}.json-node__comma[data-v-ac834fbd]{color:#24292f;margin-left:0;display:inline}.json-node__primitive[data-v-ac834fbd]{display:flex;align-items:baseline;margin-left:calc(var(--623b775d) * 20px)}.json-node__key[data-v-ac834fbd]{color:#0969da;cursor:pointer;-webkit-user-select:none;user-select:none}.json-node__key[data-v-ac834fbd]:hover{background-color:#f6f8fa;border-radius:3px}.json-node__colon[data-v-ac834fbd]{color:#24292f;margin:0 4px 0 0}.json-node__bracket[data-v-ac834fbd]{color:#6f42c1;font-weight:600;-webkit-user-select:none;user-select:none}.json-node__bracket--clickable[data-v-ac834fbd]{cursor:pointer;padding:2px;border-radius:3px}.json-node__bracket--clickable[data-v-ac834fbd]:hover{background-color:#f6f8fa}.json-node__collapsed[data-v-ac834fbd]{color:#656d76;font-style:italic;margin:0 4px}.json-node__value[data-v-ac834fbd]{cursor:pointer;padding:1px 3px;border-radius:3px;-webkit-user-select:text;user-select:text}.json-node__value[data-v-ac834fbd]:hover{background-color:#f6f8fa}.json-node__value--string[data-v-ac834fbd]{color:#0a3069}.json-node__value--number[data-v-ac834fbd]{color:#0969da}.json-node__value--boolean[data-v-ac834fbd]{color:#8250df;font-weight:600}.json-node__value--null[data-v-ac834fbd]{color:#656d76;font-style:italic}.json-node__key-input[data-v-ac834fbd],.json-node__value-input[data-v-ac834fbd]{border:1px solid #0969da;border-radius:3px;padding:1px 3px;font-family:inherit;font-size:inherit;color:inherit;background:#fff;outline:none}.json-node__key-input[data-v-ac834fbd]{color:#0969da}.json-node__children[data-v-ac834fbd]:before{content:"";position:absolute;left:calc(var(--623b775d) * 20px);top:0;bottom:0;width:1px;background:#d0d7de;opacity:.5;pointer-events:none}.json-node__children[data-v-ac834fbd]{position:relative}@media (max-width: 768px){.json-node__line[data-v-ac834fbd],.json-node__primitive[data-v-ac834fbd]{margin-left:calc(var(--623b775d) * 12px)}}.json-format[data-v-c044be43]{border:1px solid #d0d7de;border-radius:6px;background:#fff;font-family:Monaco,Consolas,Lucida Console,Courier New,ui-monospace,SFMono-Regular,SF Mono,Liberation Mono,Menlo,monospace;font-size:14px;line-height:1.45}.json-format__toolbar[data-v-c044be43]{display:flex;justify-content:space-between;align-items:center;padding:8px 12px;background:#f6f8fa;border-bottom:1px solid #d0d7de;border-radius:6px 6px 0 0}.json-format__actions[data-v-c044be43]{display:flex;gap:8px}.json-format__btn[data-v-c044be43]{padding:4px 8px;border:1px solid #d0d7de;border-radius:6px;background:#f6f8fa;color:#24292f;font-size:12px;cursor:pointer;transition:all .2s ease}.json-format__btn[data-v-c044be43]:hover:not(:disabled){background:#f3f4f6;border-color:#d0d7de}.json-format__btn[data-v-c044be43]:disabled{opacity:.5;cursor:not-allowed}.json-format__btn--primary[data-v-c044be43]{background:#2da44e;color:#fff;border-color:#2da44e}.json-format__btn--primary[data-v-c044be43]:hover:not(:disabled){background:#2c974b}.json-format__btn--secondary[data-v-c044be43]{background:#fff;border-color:#d0d7de}.json-format__info[data-v-c044be43]{display:flex;align-items:center}.json-format__status[data-v-c044be43]{padding:2px 6px;border-radius:4px;font-size:11px;font-weight:500}.json-format__status--success[data-v-c044be43]{background:#dafbe1;color:#1a7f37}.json-format__status--error[data-v-c044be43]{background:#ffebe9;color:#cf222e}.json-format__content[data-v-c044be43]{padding:16px;max-height:600px;overflow:auto}.json-format__error[data-v-c044be43]{color:#cf222e;background:#ffebe9;border:1px solid #ff818266;border-radius:6px;padding:16px}.json-format__error h4[data-v-c044be43]{margin:0 0 8px;font-size:14px;font-weight:600}.json-format__error pre[data-v-c044be43]{margin:0;font-size:12px;white-space:pre-wrap;word-break:break-word}.json-format__viewer[data-v-c044be43]{color:#24292f}.json-format__content[data-v-c044be43]::-webkit-scrollbar{width:8px;height:8px}.json-format__content[data-v-c044be43]::-webkit-scrollbar-track{background:#f6f8fa}.json-format__content[data-v-c044be43]::-webkit-scrollbar-thumb{background:#d0d7de;border-radius:4px}.json-format__content[data-v-c044be43]::-webkit-scrollbar-thumb:hover{background:#afb8c1}
|
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
import { defineComponent as G, useCssVars as R, ref as C, computed as g, resolveComponent as X, createElementBlock as r, openBlock as u, createElementVNode as k, createCommentVNode as m, withDirectives as z, toDisplayString as S, withKeys as w, vModelText as M, createTextVNode as Y, Fragment as Z, renderList as ee, createVNode as H, normalizeClass as te, nextTick as W, watch as ne } from "vue";
|
|
2
|
+
const se = { class: "json-node" }, oe = {
|
|
3
|
+
key: 0,
|
|
4
|
+
class: "json-node__container"
|
|
5
|
+
}, le = { class: "json-node__line" }, ae = {
|
|
6
|
+
key: 2,
|
|
7
|
+
class: "json-node__colon"
|
|
8
|
+
}, re = ["title"], ue = {
|
|
9
|
+
key: 3,
|
|
10
|
+
class: "json-node__collapsed"
|
|
11
|
+
}, ie = {
|
|
12
|
+
key: 4,
|
|
13
|
+
class: "json-node__comma"
|
|
14
|
+
}, ce = {
|
|
15
|
+
key: 0,
|
|
16
|
+
class: "json-node__children"
|
|
17
|
+
}, de = { class: "json-node__line" }, ve = { class: "json-node__bracket" }, pe = {
|
|
18
|
+
key: 0,
|
|
19
|
+
class: "json-node__comma"
|
|
20
|
+
}, fe = {
|
|
21
|
+
key: 1,
|
|
22
|
+
class: "json-node__primitive"
|
|
23
|
+
}, ye = {
|
|
24
|
+
key: 2,
|
|
25
|
+
class: "json-node__colon"
|
|
26
|
+
}, _e = ["title"], me = {
|
|
27
|
+
key: 5,
|
|
28
|
+
class: "json-node__comma"
|
|
29
|
+
}, ke = /* @__PURE__ */ G({
|
|
30
|
+
name: "JsonNode",
|
|
31
|
+
__name: "JsonNode",
|
|
32
|
+
props: {
|
|
33
|
+
value: {},
|
|
34
|
+
keyName: {},
|
|
35
|
+
level: {},
|
|
36
|
+
path: { default: "" },
|
|
37
|
+
expanded: {},
|
|
38
|
+
isLast: { type: Boolean, default: !1 }
|
|
39
|
+
},
|
|
40
|
+
emits: ["update:value", "toggle-expand", "copy", "update:key"],
|
|
41
|
+
setup(A, { emit: j }) {
|
|
42
|
+
R((e) => ({
|
|
43
|
+
"623b775d": e.level
|
|
44
|
+
}));
|
|
45
|
+
const o = A, b = j, p = C(!1), y = C(!1), c = C(""), d = C(""), f = (e) => {
|
|
46
|
+
if (!/^-?\d+(\.\d+)?$/.test(e)) return !1;
|
|
47
|
+
const t = Number(e);
|
|
48
|
+
return !Number.isSafeInteger(t) || e.length > 15;
|
|
49
|
+
}, N = g(() => o.value !== null && typeof o.value == "object"), $ = g(() => Array.isArray(o.value)), h = g(() => o.path ? o.path : o.keyName ? o.keyName : "root"), V = g(() => o.expanded.has(h.value)), O = g(() => o.keyName), I = g(() => $.value ? "[" : "{"), x = g(() => $.value ? "]" : "}"), T = g(() => {
|
|
50
|
+
if (!o.value) return "";
|
|
51
|
+
const t = Object.keys(o.value).length;
|
|
52
|
+
return $.value ? t > 0 ? ` ${t} items ` : " " : t > 0 ? ` ${t} keys ` : " ";
|
|
53
|
+
}), L = g(() => {
|
|
54
|
+
const e = typeof o.value;
|
|
55
|
+
return o.value === null ? "json-node__value--null" : e === "boolean" ? "json-node__value--boolean" : e === "number" ? "json-node__value--number" : e === "string" ? f(o.value) ? "json-node__value--number" : "json-node__value--string" : "";
|
|
56
|
+
}), F = g(() => y.value ? d.value : o.value === null ? "null" : typeof o.value == "boolean" || typeof o.value == "number" ? String(o.value) : typeof o.value == "string" ? f(o.value) ? o.value : `"${o.value}"` : String(o.value)), U = g(() => "Click to edit, double-click to copy"), D = (e) => o.level === 0 ? e : h.value ? `${h.value}.${e}` : e, E = (e) => {
|
|
57
|
+
const t = Object.keys(o.value);
|
|
58
|
+
return t.indexOf(e) === t.length - 1;
|
|
59
|
+
}, B = () => {
|
|
60
|
+
b("toggle-expand", h.value);
|
|
61
|
+
}, P = () => {
|
|
62
|
+
o.level !== 0 && (p.value = !0, c.value = o.keyName, W(() => {
|
|
63
|
+
const e = document.querySelectorAll(".json-node__key-input"), t = e[e.length - 1];
|
|
64
|
+
t && (t.focus(), t.select());
|
|
65
|
+
}));
|
|
66
|
+
}, q = () => {
|
|
67
|
+
N.value || (y.value = !0, typeof o.value == "string" && f(o.value) || typeof o.value == "string" ? d.value = o.value : d.value = String(o.value), W(() => {
|
|
68
|
+
const e = document.querySelectorAll(".json-node__value-input"), t = e[e.length - 1];
|
|
69
|
+
t && (t.focus(), t.select());
|
|
70
|
+
}));
|
|
71
|
+
}, n = () => {
|
|
72
|
+
if (o.level === 0 || !p.value) return;
|
|
73
|
+
const e = c.value.trim();
|
|
74
|
+
if (!e) {
|
|
75
|
+
a();
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (e === o.keyName) {
|
|
79
|
+
p.value = !1;
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
p.value = !1, b("update:key", h.value, e);
|
|
83
|
+
}, s = () => {
|
|
84
|
+
try {
|
|
85
|
+
let e;
|
|
86
|
+
const t = d.value.trim();
|
|
87
|
+
if (t === "null")
|
|
88
|
+
e = null;
|
|
89
|
+
else if (t === "true" || t === "false")
|
|
90
|
+
e = t === "true";
|
|
91
|
+
else if (!isNaN(Number(t)) && t !== "") {
|
|
92
|
+
const v = Number(t);
|
|
93
|
+
!Number.isSafeInteger(v) || t.length > 15 ? e = t : e = v;
|
|
94
|
+
} else
|
|
95
|
+
e = d.value;
|
|
96
|
+
b("update:value", h.value, e), y.value = !1;
|
|
97
|
+
} catch (e) {
|
|
98
|
+
console.error("Failed to parse value:", e), y.value = !1;
|
|
99
|
+
}
|
|
100
|
+
}, a = () => {
|
|
101
|
+
p.value = !1, c.value = o.keyName;
|
|
102
|
+
}, l = () => {
|
|
103
|
+
y.value = !1, typeof o.value == "string" && f(o.value) || typeof o.value == "string" ? d.value = o.value : d.value = String(o.value);
|
|
104
|
+
};
|
|
105
|
+
return (e, t) => {
|
|
106
|
+
const v = X("JsonNode", !0);
|
|
107
|
+
return u(), r("div", se, [
|
|
108
|
+
N.value ? (u(), r("div", oe, [
|
|
109
|
+
k("div", le, [
|
|
110
|
+
e.keyName && !p.value ? (u(), r("span", {
|
|
111
|
+
key: 0,
|
|
112
|
+
class: "json-node__key",
|
|
113
|
+
onClick: P,
|
|
114
|
+
title: "Click to edit key"
|
|
115
|
+
}, ' "' + S(O.value) + '" ', 1)) : m("", !0),
|
|
116
|
+
e.keyName && p.value ? z((u(), r("input", {
|
|
117
|
+
key: 1,
|
|
118
|
+
"onUpdate:modelValue": t[0] || (t[0] = (i) => c.value = i),
|
|
119
|
+
onKeyup: [
|
|
120
|
+
w(n, ["enter"]),
|
|
121
|
+
w(a, ["escape"])
|
|
122
|
+
],
|
|
123
|
+
onBlur: n,
|
|
124
|
+
class: "json-node__key-input"
|
|
125
|
+
}, null, 544)), [
|
|
126
|
+
[M, c.value]
|
|
127
|
+
]) : m("", !0),
|
|
128
|
+
e.keyName ? (u(), r("span", ae, ": ")) : m("", !0),
|
|
129
|
+
k("span", {
|
|
130
|
+
class: "json-node__bracket json-node__bracket--clickable",
|
|
131
|
+
onClick: B,
|
|
132
|
+
title: V.value ? "Click to collapse" : "Click to expand"
|
|
133
|
+
}, S(I.value), 9, re),
|
|
134
|
+
V.value ? m("", !0) : (u(), r("span", ue, [
|
|
135
|
+
Y(S(T.value) + " ", 1),
|
|
136
|
+
k("span", {
|
|
137
|
+
class: "json-node__bracket json-node__bracket--clickable",
|
|
138
|
+
onClick: B
|
|
139
|
+
}, S(x.value), 1)
|
|
140
|
+
])),
|
|
141
|
+
!V.value && !e.isLast ? (u(), r("span", ie, ",")) : m("", !0)
|
|
142
|
+
]),
|
|
143
|
+
V.value ? (u(), r("div", ce, [
|
|
144
|
+
(u(!0), r(Z, null, ee(e.value, (i, _) => (u(), r("div", {
|
|
145
|
+
key: _,
|
|
146
|
+
class: "json-node__child"
|
|
147
|
+
}, [
|
|
148
|
+
H(v, {
|
|
149
|
+
value: i,
|
|
150
|
+
"key-name": $.value ? "" : String(_),
|
|
151
|
+
level: e.level + 1,
|
|
152
|
+
path: D(String(_)),
|
|
153
|
+
expanded: e.expanded,
|
|
154
|
+
"onUpdate:value": t[1] || (t[1] = (J, K) => e.$emit("update:value", J, K)),
|
|
155
|
+
onToggleExpand: t[2] || (t[2] = (J) => e.$emit("toggle-expand", J)),
|
|
156
|
+
onCopy: t[3] || (t[3] = (J) => e.$emit("copy", J)),
|
|
157
|
+
"onUpdate:key": t[4] || (t[4] = (J, K) => e.$emit("update:key", J, K)),
|
|
158
|
+
"is-last": E(String(_))
|
|
159
|
+
}, null, 8, ["value", "key-name", "level", "path", "expanded", "is-last"])
|
|
160
|
+
]))), 128)),
|
|
161
|
+
k("div", de, [
|
|
162
|
+
k("span", ve, S(x.value), 1),
|
|
163
|
+
e.isLast ? m("", !0) : (u(), r("span", pe, ","))
|
|
164
|
+
])
|
|
165
|
+
])) : m("", !0)
|
|
166
|
+
])) : (u(), r("div", fe, [
|
|
167
|
+
e.keyName && !p.value ? (u(), r("span", {
|
|
168
|
+
key: 0,
|
|
169
|
+
class: "json-node__key",
|
|
170
|
+
onClick: P,
|
|
171
|
+
title: "Click to edit key"
|
|
172
|
+
}, ' "' + S(O.value) + '" ', 1)) : m("", !0),
|
|
173
|
+
e.keyName && p.value ? z((u(), r("input", {
|
|
174
|
+
key: 1,
|
|
175
|
+
"onUpdate:modelValue": t[5] || (t[5] = (i) => c.value = i),
|
|
176
|
+
onKeyup: [
|
|
177
|
+
w(n, ["enter"]),
|
|
178
|
+
w(a, ["escape"])
|
|
179
|
+
],
|
|
180
|
+
onBlur: n,
|
|
181
|
+
class: "json-node__key-input"
|
|
182
|
+
}, null, 544)), [
|
|
183
|
+
[M, c.value]
|
|
184
|
+
]) : m("", !0),
|
|
185
|
+
e.keyName ? (u(), r("span", ye, ": ")) : m("", !0),
|
|
186
|
+
y.value ? m("", !0) : (u(), r("span", {
|
|
187
|
+
key: 3,
|
|
188
|
+
class: te(["json-node__value", L.value]),
|
|
189
|
+
onClick: q,
|
|
190
|
+
onDblclick: t[6] || (t[6] = (i) => e.$emit("copy", e.value)),
|
|
191
|
+
title: U.value
|
|
192
|
+
}, S(F.value), 43, _e)),
|
|
193
|
+
y.value ? z((u(), r("input", {
|
|
194
|
+
key: 4,
|
|
195
|
+
"onUpdate:modelValue": t[7] || (t[7] = (i) => d.value = i),
|
|
196
|
+
onKeyup: [
|
|
197
|
+
w(s, ["enter"]),
|
|
198
|
+
w(l, ["escape"])
|
|
199
|
+
],
|
|
200
|
+
onBlur: s,
|
|
201
|
+
class: "json-node__value-input"
|
|
202
|
+
}, null, 544)), [
|
|
203
|
+
[M, d.value]
|
|
204
|
+
]) : m("", !0),
|
|
205
|
+
e.isLast ? m("", !0) : (u(), r("span", me, ","))
|
|
206
|
+
]))
|
|
207
|
+
]);
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
}), Q = (A, j) => {
|
|
211
|
+
const o = A.__vccOpts || A;
|
|
212
|
+
for (const [b, p] of j)
|
|
213
|
+
o[b] = p;
|
|
214
|
+
return o;
|
|
215
|
+
}, ge = /* @__PURE__ */ Q(ke, [["__scopeId", "data-v-ac834fbd"]]), Ne = { class: "json-format" }, je = {
|
|
216
|
+
key: 0,
|
|
217
|
+
class: "json-format__toolbar"
|
|
218
|
+
}, be = { class: "json-format__actions" }, he = ["disabled"], Ae = ["disabled"], Se = ["disabled"], $e = { class: "json-format__info" }, Je = {
|
|
219
|
+
key: 0,
|
|
220
|
+
class: "json-format__status json-format__status--success"
|
|
221
|
+
}, Ce = {
|
|
222
|
+
key: 1,
|
|
223
|
+
class: "json-format__status json-format__status--error"
|
|
224
|
+
}, Ve = { class: "json-format__content" }, Ee = {
|
|
225
|
+
key: 0,
|
|
226
|
+
class: "json-format__error"
|
|
227
|
+
}, we = {
|
|
228
|
+
key: 1,
|
|
229
|
+
class: "json-format__viewer"
|
|
230
|
+
}, Oe = require("json-bigint"), xe = /* @__PURE__ */ G({
|
|
231
|
+
name: "JsonFormat",
|
|
232
|
+
__name: "index",
|
|
233
|
+
props: {
|
|
234
|
+
modelValue: { default: "" },
|
|
235
|
+
readonly: { type: Boolean, default: !1 },
|
|
236
|
+
maxDepth: { default: 10 },
|
|
237
|
+
showToolbar: { type: Boolean, default: !0 }
|
|
238
|
+
},
|
|
239
|
+
emits: ["update:modelValue", "copy-success", "copy-error", "expand-all", "collapse-all"],
|
|
240
|
+
setup(A, { expose: j, emit: o }) {
|
|
241
|
+
const b = Oe({
|
|
242
|
+
storeAsString: !0,
|
|
243
|
+
// 将大数存储为字符串
|
|
244
|
+
useNativeBigInt: !1
|
|
245
|
+
}), p = A, y = o, c = C(null), d = C(""), f = C(/* @__PURE__ */ new Set()), N = g(() => d.value === ""), $ = (n) => {
|
|
246
|
+
if (!n.trim()) {
|
|
247
|
+
c.value = null, d.value = "";
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
try {
|
|
251
|
+
c.value = b.parse(n), d.value = "", W(() => {
|
|
252
|
+
c.value !== null && f.value.add("root");
|
|
253
|
+
});
|
|
254
|
+
} catch (s) {
|
|
255
|
+
d.value = s instanceof Error ? s.message : "Unknown parsing error", c.value = null;
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
ne(() => p.modelValue, (n) => {
|
|
259
|
+
$(n);
|
|
260
|
+
}, { immediate: !0 });
|
|
261
|
+
const h = (n, s) => {
|
|
262
|
+
if (!p.readonly)
|
|
263
|
+
try {
|
|
264
|
+
const a = V(c.value, n, s), l = b.stringify(a, null, 2);
|
|
265
|
+
y("update:modelValue", l);
|
|
266
|
+
} catch (a) {
|
|
267
|
+
console.error("Failed to update JSON:", a);
|
|
268
|
+
}
|
|
269
|
+
}, V = (n, s, a) => {
|
|
270
|
+
if (!s || s === "root") return a;
|
|
271
|
+
const l = s.split("."), e = E(n, l.slice(0, -1));
|
|
272
|
+
let t = e;
|
|
273
|
+
for (let i = 0; i < l.length - 1; i++) {
|
|
274
|
+
const _ = l[i];
|
|
275
|
+
_ !== "root" && (Array.isArray(t) ? t = t[parseInt(_)] : t = t[_]);
|
|
276
|
+
}
|
|
277
|
+
const v = l[l.length - 1];
|
|
278
|
+
return v === "root" ? a : (Array.isArray(t) ? t[parseInt(v)] = a : t[v] = a, e);
|
|
279
|
+
}, O = (n) => {
|
|
280
|
+
f.value.has(n) ? f.value.delete(n) : f.value.add(n);
|
|
281
|
+
}, I = () => {
|
|
282
|
+
const n = /* @__PURE__ */ new Set(), s = (a, l = "") => {
|
|
283
|
+
a !== null && typeof a == "object" && (n.add(l || "root"), Array.isArray(a) ? a.forEach((e, t) => {
|
|
284
|
+
const v = l ? `${l}.${t}` : `${t}`;
|
|
285
|
+
s(e, v);
|
|
286
|
+
}) : Object.keys(a).forEach((e) => {
|
|
287
|
+
const t = l ? `${l}.${e}` : e;
|
|
288
|
+
s(a[e], t);
|
|
289
|
+
}));
|
|
290
|
+
};
|
|
291
|
+
s(c.value), f.value = n, y("expand-all");
|
|
292
|
+
}, x = () => {
|
|
293
|
+
f.value = /* @__PURE__ */ new Set(["root"]), y("collapse-all");
|
|
294
|
+
}, T = async () => {
|
|
295
|
+
if (N.value)
|
|
296
|
+
try {
|
|
297
|
+
const s = JSON.stringify(c.value, null, 2).replace(/"(\d{16,})"/g, "$1");
|
|
298
|
+
await navigator.clipboard.writeText(s), y("copy-success", s);
|
|
299
|
+
} catch (n) {
|
|
300
|
+
console.error("Failed to copy JSON:", n), y("copy-error", n instanceof Error ? n : new Error("Failed to copy JSON"));
|
|
301
|
+
}
|
|
302
|
+
}, L = (n) => {
|
|
303
|
+
if (!/^-?\d+(\.\d+)?$/.test(n)) return !1;
|
|
304
|
+
const s = Number(n);
|
|
305
|
+
return !Number.isSafeInteger(s) || n.length > 15;
|
|
306
|
+
}, F = async (n) => {
|
|
307
|
+
try {
|
|
308
|
+
let s;
|
|
309
|
+
typeof n == "string" && L(n) ? s = n : typeof n == "string" ? s = `"${n}"` : s = JSON.stringify(n), await navigator.clipboard.writeText(s);
|
|
310
|
+
} catch (s) {
|
|
311
|
+
console.error("Failed to copy value:", s);
|
|
312
|
+
}
|
|
313
|
+
}, U = (n, s) => {
|
|
314
|
+
if (!p.readonly)
|
|
315
|
+
try {
|
|
316
|
+
const a = D(c.value, n, s), l = b.stringify(a, null, 2);
|
|
317
|
+
y("update:modelValue", l), q(n, s);
|
|
318
|
+
} catch (a) {
|
|
319
|
+
console.error("Failed to rename key:", a);
|
|
320
|
+
}
|
|
321
|
+
}, D = (n, s, a) => {
|
|
322
|
+
if (!s || s === "root") return n;
|
|
323
|
+
const l = s.split("."), e = E(n, l.slice(0, -1));
|
|
324
|
+
if (l.length === 1) {
|
|
325
|
+
const i = l[0];
|
|
326
|
+
return e && typeof e == "object" && !Array.isArray(e) ? B(e, i, a) : e;
|
|
327
|
+
}
|
|
328
|
+
let t = e;
|
|
329
|
+
for (let i = 0; i < l.length - 1; i++) {
|
|
330
|
+
const _ = l[i];
|
|
331
|
+
Array.isArray(t) ? t = t[parseInt(_)] : t = t[_];
|
|
332
|
+
}
|
|
333
|
+
const v = l[l.length - 1];
|
|
334
|
+
if (!Array.isArray(t) && t && typeof t == "object") {
|
|
335
|
+
const i = B(t, v, a), _ = l.slice(0, -1);
|
|
336
|
+
_.length > 0 && P(e, _, i);
|
|
337
|
+
}
|
|
338
|
+
return e;
|
|
339
|
+
}, E = (n, s) => {
|
|
340
|
+
if (s.length === 0) return n;
|
|
341
|
+
if (Array.isArray(n)) {
|
|
342
|
+
const a = [...n], l = s[0], e = parseInt(l);
|
|
343
|
+
return s.length === 1 || (a[e] = E(n[e], s.slice(1))), a;
|
|
344
|
+
} else if (n && typeof n == "object") {
|
|
345
|
+
const a = { ...n }, l = s[0];
|
|
346
|
+
return s.length === 1 || (a[l] = E(n[l], s.slice(1))), a;
|
|
347
|
+
}
|
|
348
|
+
return n;
|
|
349
|
+
}, B = (n, s, a) => {
|
|
350
|
+
if (!n || typeof n != "object" || Array.isArray(n))
|
|
351
|
+
return n;
|
|
352
|
+
const l = Object.keys(n), e = {};
|
|
353
|
+
for (const t of l)
|
|
354
|
+
t === s ? e[a] = n[t] : e[t] = n[t];
|
|
355
|
+
return e;
|
|
356
|
+
}, P = (n, s, a) => {
|
|
357
|
+
let l = n;
|
|
358
|
+
for (let t = 0; t < s.length - 1; t++) {
|
|
359
|
+
const v = s[t];
|
|
360
|
+
Array.isArray(l) ? l = l[parseInt(v)] : l = l[v];
|
|
361
|
+
}
|
|
362
|
+
const e = s[s.length - 1];
|
|
363
|
+
Array.isArray(l) ? l[parseInt(e)] = a : l[e] = a;
|
|
364
|
+
}, q = (n, s) => {
|
|
365
|
+
const a = /* @__PURE__ */ new Set();
|
|
366
|
+
f.value.forEach((l) => {
|
|
367
|
+
if (l === n) {
|
|
368
|
+
const e = n.split(".");
|
|
369
|
+
e[e.length - 1] = s, a.add(e.join("."));
|
|
370
|
+
} else if (l.startsWith(n + ".")) {
|
|
371
|
+
const e = n.split(".");
|
|
372
|
+
e[e.length - 1] = s;
|
|
373
|
+
const t = e.join("."), v = l.substring(n.length);
|
|
374
|
+
a.add(t + v);
|
|
375
|
+
} else
|
|
376
|
+
a.add(l);
|
|
377
|
+
}), f.value = a;
|
|
378
|
+
};
|
|
379
|
+
return j({
|
|
380
|
+
// 核心操作方法
|
|
381
|
+
copyJson: T,
|
|
382
|
+
expandAll: I,
|
|
383
|
+
collapseAll: x,
|
|
384
|
+
toggleExpand: O,
|
|
385
|
+
updateValue: h,
|
|
386
|
+
updateKey: U,
|
|
387
|
+
// 状态访问方法
|
|
388
|
+
isValidJson: () => N.value,
|
|
389
|
+
getParsedJson: () => c.value,
|
|
390
|
+
getExpandedNodes: () => f.value,
|
|
391
|
+
getParseError: () => d.value,
|
|
392
|
+
// 工具方法
|
|
393
|
+
parseJson: (n) => $(n),
|
|
394
|
+
copyValue: (n) => F(n)
|
|
395
|
+
}), (n, s) => (u(), r("div", Ne, [
|
|
396
|
+
n.showToolbar ? (u(), r("div", je, [
|
|
397
|
+
k("div", be, [
|
|
398
|
+
k("button", {
|
|
399
|
+
class: "json-format__btn json-format__btn--primary",
|
|
400
|
+
onClick: T,
|
|
401
|
+
disabled: !N.value,
|
|
402
|
+
title: "Copy JSON"
|
|
403
|
+
}, " 📋 Copy ", 8, he),
|
|
404
|
+
k("button", {
|
|
405
|
+
class: "json-format__btn json-format__btn--secondary",
|
|
406
|
+
onClick: I,
|
|
407
|
+
disabled: !N.value,
|
|
408
|
+
title: "Expand All"
|
|
409
|
+
}, " ⬇️ Expand All ", 8, Ae),
|
|
410
|
+
k("button", {
|
|
411
|
+
class: "json-format__btn json-format__btn--secondary",
|
|
412
|
+
onClick: x,
|
|
413
|
+
disabled: !N.value,
|
|
414
|
+
title: "Collapse All"
|
|
415
|
+
}, " ➡️ Collapse All ", 8, Se)
|
|
416
|
+
]),
|
|
417
|
+
k("div", $e, [
|
|
418
|
+
N.value ? (u(), r("span", Je, " ✅ Valid JSON ")) : (u(), r("span", Ce, " ❌ Invalid JSON "))
|
|
419
|
+
])
|
|
420
|
+
])) : m("", !0),
|
|
421
|
+
k("div", Ve, [
|
|
422
|
+
N.value ? (u(), r("div", we, [
|
|
423
|
+
H(ge, {
|
|
424
|
+
value: c.value,
|
|
425
|
+
"key-name": "",
|
|
426
|
+
level: 0,
|
|
427
|
+
expanded: f.value,
|
|
428
|
+
"is-last": !0,
|
|
429
|
+
"onUpdate:value": h,
|
|
430
|
+
onToggleExpand: O,
|
|
431
|
+
onCopy: F,
|
|
432
|
+
"onUpdate:key": U
|
|
433
|
+
}, null, 8, ["value", "expanded"])
|
|
434
|
+
])) : (u(), r("div", Ee, [
|
|
435
|
+
s[0] || (s[0] = k("h4", null, "JSON Parse Error:", -1)),
|
|
436
|
+
k("pre", null, S(d.value), 1)
|
|
437
|
+
]))
|
|
438
|
+
])
|
|
439
|
+
]));
|
|
440
|
+
}
|
|
441
|
+
}), Be = /* @__PURE__ */ Q(xe, [["__scopeId", "data-v-c044be43"]]), Ie = [Be], Te = (A) => {
|
|
442
|
+
Ie.forEach((j) => {
|
|
443
|
+
const o = j.name || j.__name || "UnknownComponent";
|
|
444
|
+
A.component(o, j);
|
|
445
|
+
});
|
|
446
|
+
}, Ue = {
|
|
447
|
+
install: Te
|
|
448
|
+
};
|
|
449
|
+
export {
|
|
450
|
+
Be as JsonFormat,
|
|
451
|
+
Ue as default
|
|
452
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(B,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(B=typeof globalThis<"u"?globalThis:B||self,e(B.LoneFormat={},B.Vue))})(this,function(B,e){"use strict";const P={class:"json-node"},K={key:0,class:"json-node__container"},L={class:"json-node__line"},M={key:2,class:"json-node__colon"},q=["title"],z={key:3,class:"json-node__collapsed"},W={key:4,class:"json-node__comma"},G={key:0,class:"json-node__children"},H={class:"json-node__line"},Q={class:"json-node__bracket"},R={key:0,class:"json-node__comma"},X={key:1,class:"json-node__primitive"},Y={key:2,class:"json-node__colon"},Z=["title"],ee={key:5,class:"json-node__comma"},te=e.defineComponent({name:"JsonNode",__name:"JsonNode",props:{value:{},keyName:{},level:{},path:{default:""},expanded:{},isLast:{type:Boolean,default:!1}},emits:["update:value","toggle-expand","copy","update:key"],setup(E,{emit:_}){e.useCssVars(t=>({"623b775d":t.level}));const s=E,g=_,p=e.ref(!1),f=e.ref(!1),i=e.ref(""),d=e.ref(""),m=t=>{if(!/^-?\d+(\.\d+)?$/.test(t))return!1;const n=Number(t);return!Number.isSafeInteger(n)||t.length>15},k=e.computed(()=>s.value!==null&&typeof s.value=="object"),v=e.computed(()=>Array.isArray(s.value)),N=e.computed(()=>s.path?s.path:s.keyName?s.keyName:"root"),h=e.computed(()=>s.expanded.has(N.value)),b=e.computed(()=>s.keyName),A=e.computed(()=>v.value?"[":"{"),C=e.computed(()=>v.value?"]":"}"),J=e.computed(()=>{if(!s.value)return"";const n=Object.keys(s.value).length;return v.value?n>0?` ${n} items `:" ":n>0?` ${n} keys `:" "}),O=e.computed(()=>{const t=typeof s.value;return s.value===null?"json-node__value--null":t==="boolean"?"json-node__value--boolean":t==="number"?"json-node__value--number":t==="string"?m(s.value)?"json-node__value--number":"json-node__value--string":""}),$=e.computed(()=>f.value?d.value:s.value===null?"null":typeof s.value=="boolean"||typeof s.value=="number"?String(s.value):typeof s.value=="string"?m(s.value)?s.value:`"${s.value}"`:String(s.value)),w=e.computed(()=>"Click to edit, double-click to copy"),T=t=>s.level===0?t:N.value?`${N.value}.${t}`:t,j=t=>{const n=Object.keys(s.value);return n.indexOf(t)===n.length-1},S=()=>{g("toggle-expand",N.value)},x=()=>{s.level!==0&&(p.value=!0,i.value=s.keyName,e.nextTick(()=>{const t=document.querySelectorAll(".json-node__key-input"),n=t[t.length-1];n&&(n.focus(),n.select())}))},I=()=>{k.value||(f.value=!0,typeof s.value=="string"&&m(s.value)||typeof s.value=="string"?d.value=s.value:d.value=String(s.value),e.nextTick(()=>{const t=document.querySelectorAll(".json-node__value-input"),n=t[t.length-1];n&&(n.focus(),n.select())}))},o=()=>{if(s.level===0||!p.value)return;const t=i.value.trim();if(!t){r();return}if(t===s.keyName){p.value=!1;return}p.value=!1,g("update:key",N.value,t)},l=()=>{try{let t;const n=d.value.trim();if(n==="null")t=null;else if(n==="true"||n==="false")t=n==="true";else if(!isNaN(Number(n))&&n!==""){const u=Number(n);!Number.isSafeInteger(u)||n.length>15?t=n:t=u}else t=d.value;g("update:value",N.value,t),f.value=!1}catch(t){console.error("Failed to parse value:",t),f.value=!1}},r=()=>{p.value=!1,i.value=s.keyName},a=()=>{f.value=!1,typeof s.value=="string"&&m(s.value)||typeof s.value=="string"?d.value=s.value:d.value=String(s.value)};return(t,n)=>{const u=e.resolveComponent("JsonNode",!0);return e.openBlock(),e.createElementBlock("div",P,[k.value?(e.openBlock(),e.createElementBlock("div",K,[e.createElementVNode("div",L,[t.keyName&&!p.value?(e.openBlock(),e.createElementBlock("span",{key:0,class:"json-node__key",onClick:x,title:"Click to edit key"},' "'+e.toDisplayString(b.value)+'" ',1)):e.createCommentVNode("",!0),t.keyName&&p.value?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:1,"onUpdate:modelValue":n[0]||(n[0]=c=>i.value=c),onKeyup:[e.withKeys(o,["enter"]),e.withKeys(r,["escape"])],onBlur:o,class:"json-node__key-input"},null,544)),[[e.vModelText,i.value]]):e.createCommentVNode("",!0),t.keyName?(e.openBlock(),e.createElementBlock("span",M,": ")):e.createCommentVNode("",!0),e.createElementVNode("span",{class:"json-node__bracket json-node__bracket--clickable",onClick:S,title:h.value?"Click to collapse":"Click to expand"},e.toDisplayString(A.value),9,q),h.value?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("span",z,[e.createTextVNode(e.toDisplayString(J.value)+" ",1),e.createElementVNode("span",{class:"json-node__bracket json-node__bracket--clickable",onClick:S},e.toDisplayString(C.value),1)])),!h.value&&!t.isLast?(e.openBlock(),e.createElementBlock("span",W,",")):e.createCommentVNode("",!0)]),h.value?(e.openBlock(),e.createElementBlock("div",G,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.value,(c,y)=>(e.openBlock(),e.createElementBlock("div",{key:y,class:"json-node__child"},[e.createVNode(u,{value:c,"key-name":v.value?"":String(y),level:t.level+1,path:T(String(y)),expanded:t.expanded,"onUpdate:value":n[1]||(n[1]=(V,D)=>t.$emit("update:value",V,D)),onToggleExpand:n[2]||(n[2]=V=>t.$emit("toggle-expand",V)),onCopy:n[3]||(n[3]=V=>t.$emit("copy",V)),"onUpdate:key":n[4]||(n[4]=(V,D)=>t.$emit("update:key",V,D)),"is-last":j(String(y))},null,8,["value","key-name","level","path","expanded","is-last"])]))),128)),e.createElementVNode("div",H,[e.createElementVNode("span",Q,e.toDisplayString(C.value),1),t.isLast?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("span",R,","))])])):e.createCommentVNode("",!0)])):(e.openBlock(),e.createElementBlock("div",X,[t.keyName&&!p.value?(e.openBlock(),e.createElementBlock("span",{key:0,class:"json-node__key",onClick:x,title:"Click to edit key"},' "'+e.toDisplayString(b.value)+'" ',1)):e.createCommentVNode("",!0),t.keyName&&p.value?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:1,"onUpdate:modelValue":n[5]||(n[5]=c=>i.value=c),onKeyup:[e.withKeys(o,["enter"]),e.withKeys(r,["escape"])],onBlur:o,class:"json-node__key-input"},null,544)),[[e.vModelText,i.value]]):e.createCommentVNode("",!0),t.keyName?(e.openBlock(),e.createElementBlock("span",Y,": ")):e.createCommentVNode("",!0),f.value?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("span",{key:3,class:e.normalizeClass(["json-node__value",O.value]),onClick:I,onDblclick:n[6]||(n[6]=c=>t.$emit("copy",t.value)),title:w.value},e.toDisplayString($.value),43,Z)),f.value?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:4,"onUpdate:modelValue":n[7]||(n[7]=c=>d.value=c),onKeyup:[e.withKeys(l,["enter"]),e.withKeys(a,["escape"])],onBlur:l,class:"json-node__value-input"},null,544)),[[e.vModelText,d.value]]):e.createCommentVNode("",!0),t.isLast?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("span",ee,","))]))])}}}),F=(E,_)=>{const s=E.__vccOpts||E;for(const[g,p]of _)s[g]=p;return s},ne=F(te,[["__scopeId","data-v-ac834fbd"]]),oe={class:"json-format"},le={key:0,class:"json-format__toolbar"},se={class:"json-format__actions"},ae=["disabled"],re=["disabled"],ce=["disabled"],ie={class:"json-format__info"},de={key:0,class:"json-format__status json-format__status--success"},ue={key:1,class:"json-format__status json-format__status--error"},pe={class:"json-format__content"},me={key:0,class:"json-format__error"},fe={key:1,class:"json-format__viewer"},ye=require("json-bigint"),U=F(e.defineComponent({name:"JsonFormat",__name:"index",props:{modelValue:{default:""},readonly:{type:Boolean,default:!1},maxDepth:{default:10},showToolbar:{type:Boolean,default:!0}},emits:["update:modelValue","copy-success","copy-error","expand-all","collapse-all"],setup(E,{expose:_,emit:s}){const g=ye({storeAsString:!0,useNativeBigInt:!1}),p=E,f=s,i=e.ref(null),d=e.ref(""),m=e.ref(new Set),k=e.computed(()=>d.value===""),v=o=>{if(!o.trim()){i.value=null,d.value="";return}try{i.value=g.parse(o),d.value="",e.nextTick(()=>{i.value!==null&&m.value.add("root")})}catch(l){d.value=l instanceof Error?l.message:"Unknown parsing error",i.value=null}};e.watch(()=>p.modelValue,o=>{v(o)},{immediate:!0});const N=(o,l)=>{if(!p.readonly)try{const r=h(i.value,o,l),a=g.stringify(r,null,2);f("update:modelValue",a)}catch(r){console.error("Failed to update JSON:",r)}},h=(o,l,r)=>{if(!l||l==="root")return r;const a=l.split("."),t=j(o,a.slice(0,-1));let n=t;for(let c=0;c<a.length-1;c++){const y=a[c];y!=="root"&&(Array.isArray(n)?n=n[parseInt(y)]:n=n[y])}const u=a[a.length-1];return u==="root"?r:(Array.isArray(n)?n[parseInt(u)]=r:n[u]=r,t)},b=o=>{m.value.has(o)?m.value.delete(o):m.value.add(o)},A=()=>{const o=new Set,l=(r,a="")=>{r!==null&&typeof r=="object"&&(o.add(a||"root"),Array.isArray(r)?r.forEach((t,n)=>{const u=a?`${a}.${n}`:`${n}`;l(t,u)}):Object.keys(r).forEach(t=>{const n=a?`${a}.${t}`:t;l(r[t],n)}))};l(i.value),m.value=o,f("expand-all")},C=()=>{m.value=new Set(["root"]),f("collapse-all")},J=async()=>{if(k.value)try{const l=JSON.stringify(i.value,null,2).replace(/"(\d{16,})"/g,"$1");await navigator.clipboard.writeText(l),f("copy-success",l)}catch(o){console.error("Failed to copy JSON:",o),f("copy-error",o instanceof Error?o:new Error("Failed to copy JSON"))}},O=o=>{if(!/^-?\d+(\.\d+)?$/.test(o))return!1;const l=Number(o);return!Number.isSafeInteger(l)||o.length>15},$=async o=>{try{let l;typeof o=="string"&&O(o)?l=o:typeof o=="string"?l=`"${o}"`:l=JSON.stringify(o),await navigator.clipboard.writeText(l)}catch(l){console.error("Failed to copy value:",l)}},w=(o,l)=>{if(!p.readonly)try{const r=T(i.value,o,l),a=g.stringify(r,null,2);f("update:modelValue",a),I(o,l)}catch(r){console.error("Failed to rename key:",r)}},T=(o,l,r)=>{if(!l||l==="root")return o;const a=l.split("."),t=j(o,a.slice(0,-1));if(a.length===1){const c=a[0];return t&&typeof t=="object"&&!Array.isArray(t)?S(t,c,r):t}let n=t;for(let c=0;c<a.length-1;c++){const y=a[c];Array.isArray(n)?n=n[parseInt(y)]:n=n[y]}const u=a[a.length-1];if(!Array.isArray(n)&&n&&typeof n=="object"){const c=S(n,u,r),y=a.slice(0,-1);y.length>0&&x(t,y,c)}return t},j=(o,l)=>{if(l.length===0)return o;if(Array.isArray(o)){const r=[...o],a=l[0],t=parseInt(a);return l.length===1||(r[t]=j(o[t],l.slice(1))),r}else if(o&&typeof o=="object"){const r={...o},a=l[0];return l.length===1||(r[a]=j(o[a],l.slice(1))),r}return o},S=(o,l,r)=>{if(!o||typeof o!="object"||Array.isArray(o))return o;const a=Object.keys(o),t={};for(const n of a)n===l?t[r]=o[n]:t[n]=o[n];return t},x=(o,l,r)=>{let a=o;for(let n=0;n<l.length-1;n++){const u=l[n];Array.isArray(a)?a=a[parseInt(u)]:a=a[u]}const t=l[l.length-1];Array.isArray(a)?a[parseInt(t)]=r:a[t]=r},I=(o,l)=>{const r=new Set;m.value.forEach(a=>{if(a===o){const t=o.split(".");t[t.length-1]=l,r.add(t.join("."))}else if(a.startsWith(o+".")){const t=o.split(".");t[t.length-1]=l;const n=t.join("."),u=a.substring(o.length);r.add(n+u)}else r.add(a)}),m.value=r};return _({copyJson:J,expandAll:A,collapseAll:C,toggleExpand:b,updateValue:N,updateKey:w,isValidJson:()=>k.value,getParsedJson:()=>i.value,getExpandedNodes:()=>m.value,getParseError:()=>d.value,parseJson:o=>v(o),copyValue:o=>$(o)}),(o,l)=>(e.openBlock(),e.createElementBlock("div",oe,[o.showToolbar?(e.openBlock(),e.createElementBlock("div",le,[e.createElementVNode("div",se,[e.createElementVNode("button",{class:"json-format__btn json-format__btn--primary",onClick:J,disabled:!k.value,title:"Copy JSON"}," 📋 Copy ",8,ae),e.createElementVNode("button",{class:"json-format__btn json-format__btn--secondary",onClick:A,disabled:!k.value,title:"Expand All"}," ⬇️ Expand All ",8,re),e.createElementVNode("button",{class:"json-format__btn json-format__btn--secondary",onClick:C,disabled:!k.value,title:"Collapse All"}," ➡️ Collapse All ",8,ce)]),e.createElementVNode("div",ie,[k.value?(e.openBlock(),e.createElementBlock("span",de," ✅ Valid JSON ")):(e.openBlock(),e.createElementBlock("span",ue," ❌ Invalid JSON "))])])):e.createCommentVNode("",!0),e.createElementVNode("div",pe,[k.value?(e.openBlock(),e.createElementBlock("div",fe,[e.createVNode(ne,{value:i.value,"key-name":"",level:0,expanded:m.value,"is-last":!0,"onUpdate:value":N,onToggleExpand:b,onCopy:$,"onUpdate:key":w},null,8,["value","expanded"])])):(e.openBlock(),e.createElementBlock("div",me,[l[0]||(l[0]=e.createElementVNode("h4",null,"JSON Parse Error:",-1)),e.createElementVNode("pre",null,e.toDisplayString(d.value),1)]))])]))}}),[["__scopeId","data-v-c044be43"]]),ke=[U],_e={install:E=>{ke.forEach(_=>{const s=_.name||_.__name||"UnknownComponent";E.component(s,_)})}};B.JsonFormat=U,B.default=_e,Object.defineProperties(B,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { PropType as __PropType } from 'vue';
|
|
2
|
+
declare const _sfc_main: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
3
|
+
value: {
|
|
4
|
+
type: __PropType<any>;
|
|
5
|
+
required: true;
|
|
6
|
+
};
|
|
7
|
+
keyName: {
|
|
8
|
+
type: __PropType<string>;
|
|
9
|
+
required: true;
|
|
10
|
+
};
|
|
11
|
+
level: {
|
|
12
|
+
type: __PropType<number>;
|
|
13
|
+
required: true;
|
|
14
|
+
};
|
|
15
|
+
path: {
|
|
16
|
+
type: __PropType<string>;
|
|
17
|
+
required: false;
|
|
18
|
+
default: string;
|
|
19
|
+
};
|
|
20
|
+
expanded: {
|
|
21
|
+
type: __PropType<Set<string>>;
|
|
22
|
+
required: true;
|
|
23
|
+
};
|
|
24
|
+
isLast: {
|
|
25
|
+
type: __PropType<boolean>;
|
|
26
|
+
required: false;
|
|
27
|
+
default: boolean;
|
|
28
|
+
};
|
|
29
|
+
}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("update:value" | "toggle-expand" | "copy" | "update:key")[], "update:value" | "toggle-expand" | "copy" | "update:key", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
30
|
+
value: {
|
|
31
|
+
type: __PropType<any>;
|
|
32
|
+
required: true;
|
|
33
|
+
};
|
|
34
|
+
keyName: {
|
|
35
|
+
type: __PropType<string>;
|
|
36
|
+
required: true;
|
|
37
|
+
};
|
|
38
|
+
level: {
|
|
39
|
+
type: __PropType<number>;
|
|
40
|
+
required: true;
|
|
41
|
+
};
|
|
42
|
+
path: {
|
|
43
|
+
type: __PropType<string>;
|
|
44
|
+
required: false;
|
|
45
|
+
default: string;
|
|
46
|
+
};
|
|
47
|
+
expanded: {
|
|
48
|
+
type: __PropType<Set<string>>;
|
|
49
|
+
required: true;
|
|
50
|
+
};
|
|
51
|
+
isLast: {
|
|
52
|
+
type: __PropType<boolean>;
|
|
53
|
+
required: false;
|
|
54
|
+
default: boolean;
|
|
55
|
+
};
|
|
56
|
+
}>> & Readonly<{
|
|
57
|
+
"onUpdate:value"?: (...args: any[]) => any;
|
|
58
|
+
"onToggle-expand"?: (...args: any[]) => any;
|
|
59
|
+
onCopy?: (...args: any[]) => any;
|
|
60
|
+
"onUpdate:key"?: (...args: any[]) => any;
|
|
61
|
+
}>, {
|
|
62
|
+
path: string;
|
|
63
|
+
isLast: boolean;
|
|
64
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
65
|
+
export default _sfc_main;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { PropType as __PropType } from 'vue';
|
|
2
|
+
declare const _sfc_main: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
3
|
+
modelValue: {
|
|
4
|
+
type: __PropType<string>;
|
|
5
|
+
required: true;
|
|
6
|
+
default: string;
|
|
7
|
+
};
|
|
8
|
+
readonly: {
|
|
9
|
+
type: __PropType<boolean>;
|
|
10
|
+
required: false;
|
|
11
|
+
default: boolean;
|
|
12
|
+
};
|
|
13
|
+
maxDepth: {
|
|
14
|
+
type: __PropType<number>;
|
|
15
|
+
required: false;
|
|
16
|
+
default: number;
|
|
17
|
+
};
|
|
18
|
+
showToolbar: {
|
|
19
|
+
type: __PropType<boolean>;
|
|
20
|
+
required: false;
|
|
21
|
+
default: boolean;
|
|
22
|
+
};
|
|
23
|
+
}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("update:modelValue" | "copy-success" | "copy-error" | "expand-all" | "collapse-all")[], "update:modelValue" | "copy-success" | "copy-error" | "expand-all" | "collapse-all", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
24
|
+
modelValue: {
|
|
25
|
+
type: __PropType<string>;
|
|
26
|
+
required: true;
|
|
27
|
+
default: string;
|
|
28
|
+
};
|
|
29
|
+
readonly: {
|
|
30
|
+
type: __PropType<boolean>;
|
|
31
|
+
required: false;
|
|
32
|
+
default: boolean;
|
|
33
|
+
};
|
|
34
|
+
maxDepth: {
|
|
35
|
+
type: __PropType<number>;
|
|
36
|
+
required: false;
|
|
37
|
+
default: number;
|
|
38
|
+
};
|
|
39
|
+
showToolbar: {
|
|
40
|
+
type: __PropType<boolean>;
|
|
41
|
+
required: false;
|
|
42
|
+
default: boolean;
|
|
43
|
+
};
|
|
44
|
+
}>> & Readonly<{
|
|
45
|
+
"onUpdate:modelValue"?: (...args: any[]) => any;
|
|
46
|
+
"onCopy-success"?: (...args: any[]) => any;
|
|
47
|
+
"onCopy-error"?: (...args: any[]) => any;
|
|
48
|
+
"onExpand-all"?: (...args: any[]) => any;
|
|
49
|
+
"onCollapse-all"?: (...args: any[]) => any;
|
|
50
|
+
}>, {
|
|
51
|
+
modelValue: string;
|
|
52
|
+
readonly: boolean;
|
|
53
|
+
maxDepth: number;
|
|
54
|
+
showToolbar: boolean;
|
|
55
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
56
|
+
export default _sfc_main;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JsonFormat 组件暴露的方法接口
|
|
3
|
+
*/
|
|
4
|
+
export interface JsonFormatExposed {
|
|
5
|
+
copyJson: () => Promise<void>;
|
|
6
|
+
expandAll: () => void;
|
|
7
|
+
collapseAll: () => void;
|
|
8
|
+
toggleExpand: (path: string) => void;
|
|
9
|
+
updateValue: (path: string, newValue: any) => void;
|
|
10
|
+
updateKey: (oldPath: string, newKey: string) => void;
|
|
11
|
+
isValidJson: () => boolean;
|
|
12
|
+
getParsedJson: () => any;
|
|
13
|
+
getExpandedNodes: () => Set<string>;
|
|
14
|
+
getParseError: () => string;
|
|
15
|
+
parseJson: (jsonString: string) => void;
|
|
16
|
+
copyValue: (value: any) => Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* JsonFormat 组件的 Props 接口
|
|
20
|
+
*/
|
|
21
|
+
export interface JsonFormatProps {
|
|
22
|
+
modelValue: string;
|
|
23
|
+
readonly?: boolean;
|
|
24
|
+
maxDepth?: number;
|
|
25
|
+
showToolbar?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* JsonFormat 组件的事件接口
|
|
29
|
+
*/
|
|
30
|
+
export interface JsonFormatEmits {
|
|
31
|
+
'update:modelValue': [value: string];
|
|
32
|
+
'copy-success': [value: string];
|
|
33
|
+
'copy-error': [error: Error];
|
|
34
|
+
'expand-all': [];
|
|
35
|
+
'collapse-all': [];
|
|
36
|
+
}
|
package/dist/vite.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "lone-format",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "A Vue 3 component library for formatting with tree-shaking support",
|
|
6
|
+
"main": "./dist/lone-format.umd.cjs",
|
|
7
|
+
"module": "./dist/lone-format.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/lone-format.js",
|
|
13
|
+
"require": "./dist/lone-format.umd.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./json-format": {
|
|
16
|
+
"types": "./dist/components/JsonFormat/index.d.ts",
|
|
17
|
+
"import": "./dist/components/JsonFormat/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"dev": "vite",
|
|
25
|
+
"build": "vue-tsc -b && vite build",
|
|
26
|
+
"build:lib": "vue-tsc -b && vite build --mode lib",
|
|
27
|
+
"preview": "vite preview",
|
|
28
|
+
"docs:dev": "vitepress dev docs",
|
|
29
|
+
"docs:build": "vitepress build docs",
|
|
30
|
+
"docs:preview": "vitepress preview docs",
|
|
31
|
+
"publish:lib": "npm publish --access public",
|
|
32
|
+
"publish:dry": "npm publish --dry-run"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@types/json-bigint": "^1.0.4",
|
|
36
|
+
"json-bigint": "^1.0.0"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"vue": ">=3.0.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/node": "^24.1.0",
|
|
43
|
+
"@vitejs/plugin-vue": "^6.0.0",
|
|
44
|
+
"@vue/tsconfig": "^0.7.0",
|
|
45
|
+
"glob": "^11.0.3",
|
|
46
|
+
"prettier": "^3.6.2",
|
|
47
|
+
"typescript": "~5.8.3",
|
|
48
|
+
"vite": "^7.0.4",
|
|
49
|
+
"vitepress": "^1.6.3",
|
|
50
|
+
"vue-tsc": "^2.2.12"
|
|
51
|
+
}
|
|
52
|
+
}
|