lone-format 0.1.1 → 0.1.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.
|
@@ -20,7 +20,7 @@ declare const _sfc_main: import("vue").DefineComponent<import("vue").ExtractProp
|
|
|
20
20
|
required: false;
|
|
21
21
|
default: boolean;
|
|
22
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<{
|
|
23
|
+
}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("update:modelValue" | "copy-success" | "copy-error" | "expand-all" | "collapse-all" | "compress")[], "update:modelValue" | "copy-success" | "copy-error" | "expand-all" | "collapse-all" | "compress", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
24
24
|
modelValue: {
|
|
25
25
|
type: __PropType<string>;
|
|
26
26
|
required: true;
|
|
@@ -47,6 +47,7 @@ declare const _sfc_main: import("vue").DefineComponent<import("vue").ExtractProp
|
|
|
47
47
|
"onCopy-error"?: (...args: any[]) => any;
|
|
48
48
|
"onExpand-all"?: (...args: any[]) => any;
|
|
49
49
|
"onCollapse-all"?: (...args: any[]) => any;
|
|
50
|
+
onCompress?: (...args: any[]) => any;
|
|
50
51
|
}>, {
|
|
51
52
|
modelValue: string;
|
|
52
53
|
readonly: boolean;
|
package/dist/lone-format.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.json-node[data-v-
|
|
1
|
+
.json-node[data-v-5a60a3b2]{font-family:Monaco,Consolas,Lucida Console,Courier New,ui-monospace,SFMono-Regular,SF Mono,Liberation Mono,Menlo,monospace}.json-node__container[data-v-5a60a3b2]{display:block}.json-node__line[data-v-5a60a3b2]{display:flex;align-items:baseline;margin-left:calc(var(--56869946) * 20px)}.json-node__child[data-v-5a60a3b2]{position:relative;display:inline-block;width:100%}.json-node__comma[data-v-5a60a3b2]{color:#24292f;margin-left:0;display:inline}.json-node__primitive[data-v-5a60a3b2]{display:flex;align-items:baseline;margin-left:calc(var(--56869946) * 20px)}.json-node__key[data-v-5a60a3b2]{color:#0969da;cursor:pointer;-webkit-user-select:none;user-select:none}.json-node__key[data-v-5a60a3b2]:hover{background-color:#f6f8fa;border-radius:3px}.json-node__colon[data-v-5a60a3b2]{color:#24292f;margin:0 4px 0 0}.json-node__bracket[data-v-5a60a3b2]{color:#6f42c1;font-weight:600;-webkit-user-select:none;user-select:none}.json-node__bracket--clickable[data-v-5a60a3b2]{cursor:pointer;padding:2px;border-radius:3px}.json-node__bracket--clickable[data-v-5a60a3b2]:hover{background-color:#f6f8fa}.json-node__collapsed[data-v-5a60a3b2]{color:#656d76;font-style:italic;margin:0 4px}.json-node__value[data-v-5a60a3b2]{cursor:pointer;padding:1px 3px;border-radius:3px;-webkit-user-select:text;user-select:text}.json-node__value[data-v-5a60a3b2]:hover{background-color:#f6f8fa}.json-node__value--string[data-v-5a60a3b2]{color:#0a3069}.json-node__value--number[data-v-5a60a3b2]{color:#0969da}.json-node__value--boolean[data-v-5a60a3b2]{color:#8250df;font-weight:600}.json-node__value--null[data-v-5a60a3b2]{color:#656d76;font-style:italic}.json-node__key-input[data-v-5a60a3b2],.json-node__value-input[data-v-5a60a3b2]{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-5a60a3b2]{color:#0969da}.json-node__children-content[data-v-5a60a3b2]:before{content:"";position:absolute;left:calc(var(--56869946) * 20px);top:0;bottom:0;width:1px;background:#d0d7de;opacity:.5;pointer-events:none}.json-node__children[data-v-5a60a3b2],.json-node__children-content[data-v-5a60a3b2]{position:relative}@media (max-width: 768px){.json-node__line[data-v-5a60a3b2],.json-node__primitive[data-v-5a60a3b2]{margin-left:calc(var(--56869946) * 12px)}}.json-format[data-v-e91f0005]{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-e91f0005]{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-e91f0005]{display:flex;gap:8px}.json-format__btn[data-v-e91f0005]{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-e91f0005]:hover:not(:disabled){background:#f3f4f6;border-color:#d0d7de}.json-format__btn[data-v-e91f0005]:disabled{opacity:.5;cursor:not-allowed}.json-format__btn--primary[data-v-e91f0005]{background:#2da44e;color:#fff;border-color:#2da44e}.json-format__btn--primary[data-v-e91f0005]:hover:not(:disabled){background:#2c974b}.json-format__btn--secondary[data-v-e91f0005]{background:#fff;border-color:#d0d7de}.json-format__info[data-v-e91f0005]{display:flex;align-items:center}.json-format__status[data-v-e91f0005]{padding:2px 6px;border-radius:4px;font-size:11px;font-weight:500}.json-format__status--success[data-v-e91f0005]{background:#dafbe1;color:#1a7f37}.json-format__status--error[data-v-e91f0005]{background:#ffebe9;color:#cf222e}.json-format__content[data-v-e91f0005]{padding:8px 16px;overflow:auto}.json-format__error[data-v-e91f0005]{color:#cf222e;background:#ffebe9;border:1px solid #ff818266;border-radius:6px;padding:8px 16px}.json-format__error h4[data-v-e91f0005]{margin:0 0 8px;font-size:14px;font-weight:600}.json-format__error pre[data-v-e91f0005]{margin:0;font-size:12px;white-space:pre-wrap;word-break:break-word}.json-format__viewer[data-v-e91f0005]{color:#24292f}.json-format__content[data-v-e91f0005]::-webkit-scrollbar{width:4px;height:4px}.json-format__content[data-v-e91f0005]::-webkit-scrollbar-track{background:#f6f8fa}.json-format__content[data-v-e91f0005]::-webkit-scrollbar-thumb{background:#d0d7de;border-radius:px}.json-format__content[data-v-e91f0005]::-webkit-scrollbar-thumb:hover{background:#afb8c1}
|
package/dist/lone-format.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { defineComponent as
|
|
1
|
+
import { defineComponent as z, useCssVars as Q, ref as C, computed as g, resolveComponent as X, createElementBlock as a, openBlock as u, createElementVNode as _, createCommentVNode as k, withDirectives as R, toDisplayString as $, withKeys as O, vModelText as q, createTextVNode as Y, Fragment as Z, renderList as ee, createVNode as W, normalizeClass as te, nextTick as K, watch as ne } from "vue";
|
|
2
2
|
const se = { class: "json-node" }, oe = {
|
|
3
3
|
key: 0,
|
|
4
4
|
class: "json-node__container"
|
|
5
|
-
}, le = { class: "json-node__line" },
|
|
5
|
+
}, le = { class: "json-node__line" }, re = {
|
|
6
6
|
key: 2,
|
|
7
7
|
class: "json-node__colon"
|
|
8
|
-
},
|
|
8
|
+
}, ae = ["title"], ue = {
|
|
9
9
|
key: 3,
|
|
10
10
|
class: "json-node__collapsed"
|
|
11
11
|
}, ie = {
|
|
@@ -14,19 +14,19 @@ const se = { class: "json-node" }, oe = {
|
|
|
14
14
|
}, ce = {
|
|
15
15
|
key: 0,
|
|
16
16
|
class: "json-node__children"
|
|
17
|
-
}, de = { class: "json-node__line" },
|
|
17
|
+
}, de = { class: "json-node__children-content" }, pe = { class: "json-node__line json-node__closing-bracket" }, fe = { class: "json-node__bracket" }, ve = {
|
|
18
18
|
key: 0,
|
|
19
19
|
class: "json-node__comma"
|
|
20
|
-
},
|
|
20
|
+
}, _e = {
|
|
21
21
|
key: 1,
|
|
22
22
|
class: "json-node__primitive"
|
|
23
23
|
}, ye = {
|
|
24
24
|
key: 2,
|
|
25
25
|
class: "json-node__colon"
|
|
26
|
-
},
|
|
26
|
+
}, me = ["title"], ke = {
|
|
27
27
|
key: 5,
|
|
28
28
|
class: "json-node__comma"
|
|
29
|
-
},
|
|
29
|
+
}, ge = /* @__PURE__ */ z({
|
|
30
30
|
name: "JsonNode",
|
|
31
31
|
__name: "JsonNode",
|
|
32
32
|
props: {
|
|
@@ -38,196 +38,198 @@ const se = { class: "json-node" }, oe = {
|
|
|
38
38
|
isLast: { type: Boolean, default: !1 }
|
|
39
39
|
},
|
|
40
40
|
emits: ["update:value", "toggle-expand", "copy", "update:key"],
|
|
41
|
-
setup(
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
setup(h, { emit: b }) {
|
|
42
|
+
Q((e) => ({
|
|
43
|
+
56869946: e.level
|
|
44
44
|
}));
|
|
45
|
-
const o =
|
|
45
|
+
const o = h, j = b, d = C(!1), p = C(!1), y = C(""), c = C(""), m = (e) => {
|
|
46
46
|
if (!/^-?\d+(\.\d+)?$/.test(e)) return !1;
|
|
47
47
|
const t = Number(e);
|
|
48
48
|
return !Number.isSafeInteger(t) || e.length > 15;
|
|
49
|
-
},
|
|
49
|
+
}, w = g(() => o.value !== null && typeof o.value == "object"), S = g(() => Array.isArray(o.value)), N = g(() => o.path ? o.path : o.keyName ? o.keyName : "root"), J = g(() => o.expanded.has(N.value)), x = g(() => o.keyName), I = g(() => S.value ? "[" : "{"), E = g(() => S.value ? "]" : "}"), F = g(() => {
|
|
50
50
|
if (!o.value) return "";
|
|
51
51
|
const t = Object.keys(o.value).length;
|
|
52
|
-
return
|
|
53
|
-
}),
|
|
52
|
+
return S.value ? t > 0 ? ` ${t} items ` : " " : t > 0 ? ` ${t} keys ` : " ";
|
|
53
|
+
}), U = g(() => {
|
|
54
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" ?
|
|
56
|
-
}),
|
|
55
|
+
return o.value === null ? "json-node__value--null" : e === "boolean" ? "json-node__value--boolean" : e === "number" ? "json-node__value--number" : e === "string" ? m(o.value) ? "json-node__value--number" : "json-node__value--string" : "";
|
|
56
|
+
}), T = g(() => p.value ? c.value : o.value === null ? "null" : typeof o.value == "boolean" || typeof o.value == "number" ? String(o.value) : typeof o.value == "string" ? m(o.value) ? o.value : `"${o.value}"` : String(o.value)), P = g(() => "Click to edit, double-click to copy"), L = (e) => o.level === 0 ? e : N.value ? `${N.value}.${e}` : e, M = (e) => {
|
|
57
57
|
const t = Object.keys(o.value);
|
|
58
58
|
return t.indexOf(e) === t.length - 1;
|
|
59
|
+
}, A = () => {
|
|
60
|
+
j("toggle-expand", N.value);
|
|
59
61
|
}, B = () => {
|
|
60
|
-
|
|
61
|
-
}, P = () => {
|
|
62
|
-
o.level !== 0 && (p.value = !0, c.value = o.keyName, W(() => {
|
|
62
|
+
o.level !== 0 && (d.value = !0, y.value = o.keyName, K(() => {
|
|
63
63
|
const e = document.querySelectorAll(".json-node__key-input"), t = e[e.length - 1];
|
|
64
64
|
t && (t.focus(), t.select());
|
|
65
65
|
}));
|
|
66
|
-
},
|
|
67
|
-
|
|
66
|
+
}, D = () => {
|
|
67
|
+
w.value || (p.value = !0, typeof o.value == "string" && m(o.value) || typeof o.value == "string" ? c.value = o.value : c.value = String(o.value), K(() => {
|
|
68
68
|
const e = document.querySelectorAll(".json-node__value-input"), t = e[e.length - 1];
|
|
69
69
|
t && (t.focus(), t.select());
|
|
70
70
|
}));
|
|
71
|
-
},
|
|
72
|
-
if (o.level === 0 || !
|
|
73
|
-
const e =
|
|
71
|
+
}, V = () => {
|
|
72
|
+
if (o.level === 0 || !d.value) return;
|
|
73
|
+
const e = y.value.trim();
|
|
74
74
|
if (!e) {
|
|
75
|
-
|
|
75
|
+
s();
|
|
76
76
|
return;
|
|
77
77
|
}
|
|
78
78
|
if (e === o.keyName) {
|
|
79
|
-
|
|
79
|
+
d.value = !1;
|
|
80
80
|
return;
|
|
81
81
|
}
|
|
82
|
-
|
|
83
|
-
},
|
|
82
|
+
d.value = !1, j("update:key", N.value, e);
|
|
83
|
+
}, n = () => {
|
|
84
84
|
try {
|
|
85
85
|
let e;
|
|
86
|
-
const t =
|
|
86
|
+
const t = c.value.trim();
|
|
87
87
|
if (t === "null")
|
|
88
88
|
e = null;
|
|
89
89
|
else if (t === "true" || t === "false")
|
|
90
90
|
e = t === "true";
|
|
91
91
|
else if (!isNaN(Number(t)) && t !== "") {
|
|
92
|
-
const
|
|
93
|
-
!Number.isSafeInteger(
|
|
92
|
+
const l = Number(t);
|
|
93
|
+
!Number.isSafeInteger(l) || t.length > 15 ? e = t : e = l;
|
|
94
94
|
} else
|
|
95
|
-
e =
|
|
96
|
-
|
|
95
|
+
e = c.value;
|
|
96
|
+
j("update:value", N.value, e), p.value = !1;
|
|
97
97
|
} catch (e) {
|
|
98
|
-
console.error("Failed to parse value:", e),
|
|
98
|
+
console.error("Failed to parse value:", e), p.value = !1;
|
|
99
99
|
}
|
|
100
|
-
},
|
|
101
|
-
|
|
102
|
-
},
|
|
103
|
-
|
|
100
|
+
}, s = () => {
|
|
101
|
+
d.value = !1, y.value = o.keyName;
|
|
102
|
+
}, r = () => {
|
|
103
|
+
p.value = !1, typeof o.value == "string" && m(o.value) || typeof o.value == "string" ? c.value = o.value : c.value = String(o.value);
|
|
104
104
|
};
|
|
105
105
|
return (e, t) => {
|
|
106
|
-
const
|
|
107
|
-
return u(),
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
e.keyName && !
|
|
106
|
+
const l = X("JsonNode", !0);
|
|
107
|
+
return u(), a("div", se, [
|
|
108
|
+
w.value ? (u(), a("div", oe, [
|
|
109
|
+
_("div", le, [
|
|
110
|
+
e.keyName && !d.value ? (u(), a("span", {
|
|
111
111
|
key: 0,
|
|
112
112
|
class: "json-node__key",
|
|
113
|
-
onClick:
|
|
113
|
+
onClick: B,
|
|
114
114
|
title: "Click to edit key"
|
|
115
|
-
}, ' "' +
|
|
116
|
-
e.keyName &&
|
|
115
|
+
}, ' "' + $(x.value) + '" ', 1)) : k("", !0),
|
|
116
|
+
e.keyName && d.value ? R((u(), a("input", {
|
|
117
117
|
key: 1,
|
|
118
|
-
"onUpdate:modelValue": t[0] || (t[0] = (i) =>
|
|
118
|
+
"onUpdate:modelValue": t[0] || (t[0] = (i) => y.value = i),
|
|
119
119
|
onKeyup: [
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
O(V, ["enter"]),
|
|
121
|
+
O(s, ["escape"])
|
|
122
122
|
],
|
|
123
|
-
onBlur:
|
|
123
|
+
onBlur: V,
|
|
124
124
|
class: "json-node__key-input"
|
|
125
125
|
}, null, 544)), [
|
|
126
|
-
[
|
|
127
|
-
]) :
|
|
128
|
-
e.keyName ? (u(),
|
|
129
|
-
|
|
126
|
+
[q, y.value]
|
|
127
|
+
]) : k("", !0),
|
|
128
|
+
e.keyName ? (u(), a("span", re, ": ")) : k("", !0),
|
|
129
|
+
_("span", {
|
|
130
130
|
class: "json-node__bracket json-node__bracket--clickable",
|
|
131
|
-
onClick:
|
|
132
|
-
title:
|
|
133
|
-
},
|
|
134
|
-
|
|
135
|
-
Y(
|
|
136
|
-
|
|
131
|
+
onClick: A,
|
|
132
|
+
title: J.value ? "Click to collapse" : "Click to expand"
|
|
133
|
+
}, $(I.value), 9, ae),
|
|
134
|
+
J.value ? k("", !0) : (u(), a("span", ue, [
|
|
135
|
+
Y($(F.value) + " ", 1),
|
|
136
|
+
_("span", {
|
|
137
137
|
class: "json-node__bracket json-node__bracket--clickable",
|
|
138
|
-
onClick:
|
|
139
|
-
},
|
|
138
|
+
onClick: A
|
|
139
|
+
}, $(E.value), 1)
|
|
140
140
|
])),
|
|
141
|
-
!
|
|
141
|
+
!J.value && !e.isLast ? (u(), a("span", ie, ",")) : k("", !0)
|
|
142
142
|
]),
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
143
|
+
J.value ? (u(), a("div", ce, [
|
|
144
|
+
_("div", de, [
|
|
145
|
+
(u(!0), a(Z, null, ee(e.value, (i, v) => (u(), a("div", {
|
|
146
|
+
key: v,
|
|
147
|
+
class: "json-node__child"
|
|
148
|
+
}, [
|
|
149
|
+
W(l, {
|
|
150
|
+
value: i,
|
|
151
|
+
"key-name": S.value ? "" : String(v),
|
|
152
|
+
level: e.level + 1,
|
|
153
|
+
path: L(String(v)),
|
|
154
|
+
expanded: e.expanded,
|
|
155
|
+
"onUpdate:value": t[1] || (t[1] = (f, G) => e.$emit("update:value", f, G)),
|
|
156
|
+
onToggleExpand: t[2] || (t[2] = (f) => e.$emit("toggle-expand", f)),
|
|
157
|
+
onCopy: t[3] || (t[3] = (f) => e.$emit("copy", f)),
|
|
158
|
+
"onUpdate:key": t[4] || (t[4] = (f, G) => e.$emit("update:key", f, G)),
|
|
159
|
+
"is-last": M(String(v))
|
|
160
|
+
}, null, 8, ["value", "key-name", "level", "path", "expanded", "is-last"])
|
|
161
|
+
]))), 128))
|
|
162
|
+
]),
|
|
163
|
+
_("div", pe, [
|
|
164
|
+
_("span", fe, $(E.value), 1),
|
|
165
|
+
e.isLast ? k("", !0) : (u(), a("span", ve, ","))
|
|
164
166
|
])
|
|
165
|
-
])) :
|
|
166
|
-
])) : (u(),
|
|
167
|
-
e.keyName && !
|
|
167
|
+
])) : k("", !0)
|
|
168
|
+
])) : (u(), a("div", _e, [
|
|
169
|
+
e.keyName && !d.value ? (u(), a("span", {
|
|
168
170
|
key: 0,
|
|
169
171
|
class: "json-node__key",
|
|
170
|
-
onClick:
|
|
172
|
+
onClick: B,
|
|
171
173
|
title: "Click to edit key"
|
|
172
|
-
}, ' "' +
|
|
173
|
-
e.keyName &&
|
|
174
|
+
}, ' "' + $(x.value) + '" ', 1)) : k("", !0),
|
|
175
|
+
e.keyName && d.value ? R((u(), a("input", {
|
|
174
176
|
key: 1,
|
|
175
|
-
"onUpdate:modelValue": t[5] || (t[5] = (i) =>
|
|
177
|
+
"onUpdate:modelValue": t[5] || (t[5] = (i) => y.value = i),
|
|
176
178
|
onKeyup: [
|
|
177
|
-
|
|
178
|
-
|
|
179
|
+
O(V, ["enter"]),
|
|
180
|
+
O(s, ["escape"])
|
|
179
181
|
],
|
|
180
|
-
onBlur:
|
|
182
|
+
onBlur: V,
|
|
181
183
|
class: "json-node__key-input"
|
|
182
184
|
}, null, 544)), [
|
|
183
|
-
[
|
|
184
|
-
]) :
|
|
185
|
-
e.keyName ? (u(),
|
|
186
|
-
|
|
185
|
+
[q, y.value]
|
|
186
|
+
]) : k("", !0),
|
|
187
|
+
e.keyName ? (u(), a("span", ye, ": ")) : k("", !0),
|
|
188
|
+
p.value ? k("", !0) : (u(), a("span", {
|
|
187
189
|
key: 3,
|
|
188
|
-
class: te(["json-node__value",
|
|
189
|
-
onClick:
|
|
190
|
+
class: te(["json-node__value", U.value]),
|
|
191
|
+
onClick: D,
|
|
190
192
|
onDblclick: t[6] || (t[6] = (i) => e.$emit("copy", e.value)),
|
|
191
|
-
title:
|
|
192
|
-
},
|
|
193
|
-
|
|
193
|
+
title: P.value
|
|
194
|
+
}, $(T.value), 43, me)),
|
|
195
|
+
p.value ? R((u(), a("input", {
|
|
194
196
|
key: 4,
|
|
195
|
-
"onUpdate:modelValue": t[7] || (t[7] = (i) =>
|
|
197
|
+
"onUpdate:modelValue": t[7] || (t[7] = (i) => c.value = i),
|
|
196
198
|
onKeyup: [
|
|
197
|
-
|
|
198
|
-
|
|
199
|
+
O(n, ["enter"]),
|
|
200
|
+
O(r, ["escape"])
|
|
199
201
|
],
|
|
200
|
-
onBlur:
|
|
202
|
+
onBlur: n,
|
|
201
203
|
class: "json-node__value-input"
|
|
202
204
|
}, null, 544)), [
|
|
203
|
-
[
|
|
204
|
-
]) :
|
|
205
|
-
e.isLast ?
|
|
205
|
+
[q, c.value]
|
|
206
|
+
]) : k("", !0),
|
|
207
|
+
e.isLast ? k("", !0) : (u(), a("span", ke, ","))
|
|
206
208
|
]))
|
|
207
209
|
]);
|
|
208
210
|
};
|
|
209
211
|
}
|
|
210
|
-
}),
|
|
211
|
-
const o =
|
|
212
|
-
for (const [
|
|
213
|
-
o[
|
|
212
|
+
}), H = (h, b) => {
|
|
213
|
+
const o = h.__vccOpts || h;
|
|
214
|
+
for (const [j, d] of b)
|
|
215
|
+
o[j] = d;
|
|
214
216
|
return o;
|
|
215
|
-
},
|
|
217
|
+
}, Ne = /* @__PURE__ */ H(ge, [["__scopeId", "data-v-5a60a3b2"]]), be = { class: "json-format" }, je = {
|
|
216
218
|
key: 0,
|
|
217
219
|
class: "json-format__toolbar"
|
|
218
|
-
},
|
|
220
|
+
}, he = { class: "json-format__actions" }, $e = ["disabled"], Se = ["disabled"], Je = ["disabled"], Ae = ["disabled"], Ce = { class: "json-format__info" }, Ee = {
|
|
219
221
|
key: 0,
|
|
220
222
|
class: "json-format__status json-format__status--success"
|
|
221
|
-
},
|
|
223
|
+
}, Ve = {
|
|
222
224
|
key: 1,
|
|
223
225
|
class: "json-format__status json-format__status--error"
|
|
224
|
-
},
|
|
226
|
+
}, Oe = { class: "json-format__content" }, we = {
|
|
225
227
|
key: 0,
|
|
226
228
|
class: "json-format__error"
|
|
227
|
-
},
|
|
229
|
+
}, Be = {
|
|
228
230
|
key: 1,
|
|
229
231
|
class: "json-format__viewer"
|
|
230
|
-
},
|
|
232
|
+
}, xe = /* @__PURE__ */ z({
|
|
231
233
|
name: "JsonFormat",
|
|
232
234
|
__name: "index",
|
|
233
235
|
props: {
|
|
@@ -236,217 +238,242 @@ const se = { class: "json-node" }, oe = {
|
|
|
236
238
|
maxDepth: { default: 10 },
|
|
237
239
|
showToolbar: { type: Boolean, default: !0 }
|
|
238
240
|
},
|
|
239
|
-
emits: ["update:modelValue", "copy-success", "copy-error", "expand-all", "collapse-all"],
|
|
240
|
-
setup(
|
|
241
|
-
const
|
|
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) => {
|
|
241
|
+
emits: ["update:modelValue", "copy-success", "copy-error", "expand-all", "collapse-all", "compress"],
|
|
242
|
+
setup(h, { expose: b, emit: o }) {
|
|
243
|
+
const j = h, d = o, p = C(null), y = C(""), c = C(/* @__PURE__ */ new Set()), m = g(() => y.value === ""), w = (n) => {
|
|
246
244
|
if (!n.trim()) {
|
|
247
|
-
|
|
245
|
+
p.value = null, y.value = "";
|
|
248
246
|
return;
|
|
249
247
|
}
|
|
250
248
|
try {
|
|
251
|
-
|
|
252
|
-
|
|
249
|
+
let s = n;
|
|
250
|
+
s = s.replace(/:\s*(\d{16,})\s*([,}])/g, ': "$1"$2'), s = s.replace(/:\s*(\d+\.\d*?0+)\s*([,}])/g, ': "$1"$2'), p.value = JSON.parse(s), y.value = "", K(() => {
|
|
251
|
+
p.value !== null && E();
|
|
253
252
|
});
|
|
254
253
|
} catch (s) {
|
|
255
|
-
|
|
254
|
+
y.value = s instanceof Error ? s.message : "Unknown parsing error", p.value = null;
|
|
256
255
|
}
|
|
257
256
|
};
|
|
258
|
-
ne(() =>
|
|
259
|
-
|
|
257
|
+
ne(() => j.modelValue, (n) => {
|
|
258
|
+
w(n);
|
|
260
259
|
}, { immediate: !0 });
|
|
261
|
-
const
|
|
262
|
-
if (!
|
|
260
|
+
const S = (n) => {
|
|
261
|
+
if (!/^-?\d+(\.\d+)?$/.test(n)) return !1;
|
|
262
|
+
const s = Number(n);
|
|
263
|
+
return !Number.isSafeInteger(s) || n.length > 15;
|
|
264
|
+
}, N = (n, s, r) => JSON.stringify(n, (e, t) => {
|
|
265
|
+
if (typeof t == "string" && S(t))
|
|
266
|
+
return `__BIG_NUMBER__${t}__BIG_NUMBER__`;
|
|
267
|
+
if (typeof t == "string" && /^-?\d+(\.\d+)?$/.test(t)) {
|
|
268
|
+
const l = Number(t);
|
|
269
|
+
if (Number.isSafeInteger(l) && l.toString() === t)
|
|
270
|
+
return l;
|
|
271
|
+
if (!Number.isNaN(l) && isFinite(l) && t.includes("."))
|
|
272
|
+
return l.toString() === t ? l : t;
|
|
273
|
+
if (!Number.isNaN(l) && isFinite(l))
|
|
274
|
+
return l;
|
|
275
|
+
}
|
|
276
|
+
return s && typeof s == "function" ? s(e, t) : t;
|
|
277
|
+
}, r).replace(/"__BIG_NUMBER__(.+?)__BIG_NUMBER__"/g, "$1"), J = (n, s) => {
|
|
278
|
+
if (!j.readonly)
|
|
263
279
|
try {
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
} catch (
|
|
267
|
-
console.error("Failed to update JSON:",
|
|
280
|
+
const r = x(p.value, n, s), e = N(r, null, 2);
|
|
281
|
+
d("update:modelValue", e);
|
|
282
|
+
} catch (r) {
|
|
283
|
+
console.error("Failed to update JSON:", r);
|
|
268
284
|
}
|
|
269
|
-
},
|
|
270
|
-
if (!s || s === "root") return
|
|
271
|
-
const
|
|
272
|
-
let
|
|
273
|
-
for (let
|
|
274
|
-
const
|
|
275
|
-
|
|
285
|
+
}, x = (n, s, r) => {
|
|
286
|
+
if (!s || s === "root") return r;
|
|
287
|
+
const e = s.split("."), t = A(n, e.slice(0, -1));
|
|
288
|
+
let l = t;
|
|
289
|
+
for (let v = 0; v < e.length - 1; v++) {
|
|
290
|
+
const f = e[v];
|
|
291
|
+
f !== "root" && (Array.isArray(l) ? l = l[parseInt(f)] : l = l[f]);
|
|
276
292
|
}
|
|
277
|
-
const
|
|
278
|
-
return
|
|
279
|
-
},
|
|
280
|
-
|
|
281
|
-
},
|
|
282
|
-
const n = /* @__PURE__ */ new Set(), s = (
|
|
283
|
-
|
|
284
|
-
const
|
|
285
|
-
s(
|
|
286
|
-
}) : Object.keys(
|
|
287
|
-
const
|
|
288
|
-
s(
|
|
293
|
+
const i = e[e.length - 1];
|
|
294
|
+
return i === "root" ? r : (Array.isArray(l) ? l[parseInt(i)] = r : l[i] = r, t);
|
|
295
|
+
}, I = (n) => {
|
|
296
|
+
c.value.has(n) ? c.value.delete(n) : c.value.add(n);
|
|
297
|
+
}, E = () => {
|
|
298
|
+
const n = /* @__PURE__ */ new Set(), s = (r, e = "") => {
|
|
299
|
+
r !== null && typeof r == "object" && (n.add(e || "root"), Array.isArray(r) ? r.forEach((t, l) => {
|
|
300
|
+
const i = e ? `${e}.${l}` : `${l}`;
|
|
301
|
+
s(t, i);
|
|
302
|
+
}) : Object.keys(r).forEach((t) => {
|
|
303
|
+
const l = e ? `${e}.${t}` : t;
|
|
304
|
+
s(r[t], l);
|
|
289
305
|
}));
|
|
290
306
|
};
|
|
291
|
-
s(
|
|
292
|
-
},
|
|
293
|
-
|
|
294
|
-
},
|
|
295
|
-
if (
|
|
307
|
+
s(p.value), c.value = n, d("expand-all");
|
|
308
|
+
}, F = () => {
|
|
309
|
+
c.value = /* @__PURE__ */ new Set(["root"]), d("collapse-all");
|
|
310
|
+
}, U = async () => {
|
|
311
|
+
if (m.value)
|
|
296
312
|
try {
|
|
297
|
-
const s = JSON.stringify(
|
|
298
|
-
await navigator.clipboard.writeText(s),
|
|
313
|
+
const s = JSON.stringify(p.value, null, 2).replace(/"(\d{16,})"/g, "$1");
|
|
314
|
+
await navigator.clipboard.writeText(s), d("copy-success", s);
|
|
299
315
|
} catch (n) {
|
|
300
|
-
console.error("Failed to copy JSON:", n),
|
|
316
|
+
console.error("Failed to copy JSON:", n), d("copy-error", n instanceof Error ? n : new Error("Failed to copy JSON"));
|
|
301
317
|
}
|
|
302
|
-
},
|
|
303
|
-
if (
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
318
|
+
}, T = () => {
|
|
319
|
+
if (m.value)
|
|
320
|
+
try {
|
|
321
|
+
const n = N(p.value);
|
|
322
|
+
d("update:modelValue", n), d("compress", n);
|
|
323
|
+
} catch (n) {
|
|
324
|
+
console.error("Failed to compress JSON:", n);
|
|
325
|
+
}
|
|
326
|
+
}, P = async (n) => {
|
|
307
327
|
try {
|
|
308
328
|
let s;
|
|
309
|
-
typeof n == "string" &&
|
|
329
|
+
typeof n == "string" && S(n) ? s = n : typeof n == "string" ? s = `"${n}"` : s = JSON.stringify(n), await navigator.clipboard.writeText(s);
|
|
310
330
|
} catch (s) {
|
|
311
331
|
console.error("Failed to copy value:", s);
|
|
312
332
|
}
|
|
313
|
-
},
|
|
314
|
-
if (!
|
|
333
|
+
}, L = (n, s) => {
|
|
334
|
+
if (!j.readonly)
|
|
315
335
|
try {
|
|
316
|
-
const
|
|
317
|
-
|
|
318
|
-
} catch (
|
|
319
|
-
console.error("Failed to rename key:",
|
|
336
|
+
const r = M(p.value, n, s), e = N(r, null, 2);
|
|
337
|
+
d("update:modelValue", e), V(n, s);
|
|
338
|
+
} catch (r) {
|
|
339
|
+
console.error("Failed to rename key:", r);
|
|
320
340
|
}
|
|
321
|
-
},
|
|
341
|
+
}, M = (n, s, r) => {
|
|
322
342
|
if (!s || s === "root") return n;
|
|
323
|
-
const
|
|
324
|
-
if (
|
|
325
|
-
const
|
|
326
|
-
return
|
|
343
|
+
const e = s.split("."), t = A(n, e.slice(0, -1));
|
|
344
|
+
if (e.length === 1) {
|
|
345
|
+
const v = e[0];
|
|
346
|
+
return t && typeof t == "object" && !Array.isArray(t) ? B(t, v, r) : t;
|
|
327
347
|
}
|
|
328
|
-
let
|
|
329
|
-
for (let
|
|
330
|
-
const
|
|
331
|
-
Array.isArray(
|
|
348
|
+
let l = t;
|
|
349
|
+
for (let v = 0; v < e.length - 1; v++) {
|
|
350
|
+
const f = e[v];
|
|
351
|
+
Array.isArray(l) ? l = l[parseInt(f)] : l = l[f];
|
|
332
352
|
}
|
|
333
|
-
const
|
|
334
|
-
if (!Array.isArray(
|
|
335
|
-
const
|
|
336
|
-
|
|
353
|
+
const i = e[e.length - 1];
|
|
354
|
+
if (!Array.isArray(l) && l && typeof l == "object") {
|
|
355
|
+
const v = B(l, i, r), f = e.slice(0, -1);
|
|
356
|
+
f.length > 0 && D(t, f, v);
|
|
337
357
|
}
|
|
338
|
-
return
|
|
339
|
-
},
|
|
358
|
+
return t;
|
|
359
|
+
}, A = (n, s) => {
|
|
340
360
|
if (s.length === 0) return n;
|
|
341
361
|
if (Array.isArray(n)) {
|
|
342
|
-
const
|
|
343
|
-
return s.length === 1 || (
|
|
362
|
+
const r = [...n], e = s[0], t = parseInt(e);
|
|
363
|
+
return s.length === 1 || (r[t] = A(n[t], s.slice(1))), r;
|
|
344
364
|
} else if (n && typeof n == "object") {
|
|
345
|
-
const
|
|
346
|
-
return s.length === 1 || (
|
|
365
|
+
const r = { ...n }, e = s[0];
|
|
366
|
+
return s.length === 1 || (r[e] = A(n[e], s.slice(1))), r;
|
|
347
367
|
}
|
|
348
368
|
return n;
|
|
349
|
-
}, B = (n, s,
|
|
369
|
+
}, B = (n, s, r) => {
|
|
350
370
|
if (!n || typeof n != "object" || Array.isArray(n))
|
|
351
371
|
return n;
|
|
352
|
-
const
|
|
353
|
-
for (const
|
|
354
|
-
|
|
355
|
-
return
|
|
356
|
-
},
|
|
357
|
-
let
|
|
358
|
-
for (let
|
|
359
|
-
const
|
|
360
|
-
Array.isArray(
|
|
372
|
+
const e = Object.keys(n), t = {};
|
|
373
|
+
for (const l of e)
|
|
374
|
+
l === s ? t[r] = n[l] : t[l] = n[l];
|
|
375
|
+
return t;
|
|
376
|
+
}, D = (n, s, r) => {
|
|
377
|
+
let e = n;
|
|
378
|
+
for (let l = 0; l < s.length - 1; l++) {
|
|
379
|
+
const i = s[l];
|
|
380
|
+
Array.isArray(e) ? e = e[parseInt(i)] : e = e[i];
|
|
361
381
|
}
|
|
362
|
-
const
|
|
363
|
-
Array.isArray(
|
|
364
|
-
},
|
|
365
|
-
const
|
|
366
|
-
|
|
367
|
-
if (
|
|
368
|
-
const
|
|
369
|
-
|
|
370
|
-
} else if (
|
|
371
|
-
const
|
|
372
|
-
|
|
373
|
-
const
|
|
374
|
-
|
|
382
|
+
const t = s[s.length - 1];
|
|
383
|
+
Array.isArray(e) ? e[parseInt(t)] = r : e[t] = r;
|
|
384
|
+
}, V = (n, s) => {
|
|
385
|
+
const r = /* @__PURE__ */ new Set();
|
|
386
|
+
c.value.forEach((e) => {
|
|
387
|
+
if (e === n) {
|
|
388
|
+
const t = n.split(".");
|
|
389
|
+
t[t.length - 1] = s, r.add(t.join("."));
|
|
390
|
+
} else if (e.startsWith(n + ".")) {
|
|
391
|
+
const t = n.split(".");
|
|
392
|
+
t[t.length - 1] = s;
|
|
393
|
+
const l = t.join("."), i = e.substring(n.length);
|
|
394
|
+
r.add(l + i);
|
|
375
395
|
} else
|
|
376
|
-
|
|
377
|
-
}),
|
|
396
|
+
r.add(e);
|
|
397
|
+
}), c.value = r;
|
|
378
398
|
};
|
|
379
|
-
return
|
|
399
|
+
return b({
|
|
380
400
|
// 核心操作方法
|
|
381
|
-
copyJson:
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
401
|
+
copyJson: U,
|
|
402
|
+
compressSource: T,
|
|
403
|
+
expandAll: E,
|
|
404
|
+
collapseAll: F,
|
|
405
|
+
toggleExpand: I,
|
|
406
|
+
updateValue: J,
|
|
407
|
+
updateKey: L,
|
|
387
408
|
// 状态访问方法
|
|
388
|
-
isValidJson: () =>
|
|
389
|
-
getParsedJson: () =>
|
|
390
|
-
getExpandedNodes: () =>
|
|
391
|
-
getParseError: () =>
|
|
409
|
+
isValidJson: () => m.value,
|
|
410
|
+
getParsedJson: () => p.value,
|
|
411
|
+
getExpandedNodes: () => c.value,
|
|
412
|
+
getParseError: () => y.value,
|
|
392
413
|
// 工具方法
|
|
393
|
-
parseJson: (n) =>
|
|
394
|
-
copyValue: (n) =>
|
|
395
|
-
}), (n, s) => (u(),
|
|
396
|
-
n.showToolbar ? (u(),
|
|
397
|
-
|
|
398
|
-
|
|
414
|
+
parseJson: (n) => w(n),
|
|
415
|
+
copyValue: (n) => P(n)
|
|
416
|
+
}), (n, s) => (u(), a("div", be, [
|
|
417
|
+
n.showToolbar ? (u(), a("div", je, [
|
|
418
|
+
_("div", he, [
|
|
419
|
+
_("button", {
|
|
399
420
|
class: "json-format__btn json-format__btn--primary",
|
|
400
|
-
onClick:
|
|
401
|
-
disabled: !
|
|
421
|
+
onClick: U,
|
|
422
|
+
disabled: !m.value,
|
|
402
423
|
title: "Copy JSON"
|
|
403
|
-
}, " 📋 Copy ", 8,
|
|
404
|
-
|
|
424
|
+
}, " 📋 Copy ", 8, $e),
|
|
425
|
+
_("button", {
|
|
405
426
|
class: "json-format__btn json-format__btn--secondary",
|
|
406
|
-
onClick:
|
|
407
|
-
disabled: !
|
|
427
|
+
onClick: E,
|
|
428
|
+
disabled: !m.value,
|
|
408
429
|
title: "Expand All"
|
|
409
|
-
}, " ⬇️ Expand All ", 8,
|
|
410
|
-
|
|
430
|
+
}, " ⬇️ Expand All ", 8, Se),
|
|
431
|
+
_("button", {
|
|
411
432
|
class: "json-format__btn json-format__btn--secondary",
|
|
412
|
-
onClick:
|
|
413
|
-
disabled: !
|
|
433
|
+
onClick: F,
|
|
434
|
+
disabled: !m.value,
|
|
414
435
|
title: "Collapse All"
|
|
415
|
-
}, " ➡️ Collapse All ", 8,
|
|
436
|
+
}, " ➡️ Collapse All ", 8, Je),
|
|
437
|
+
_("button", {
|
|
438
|
+
class: "json-format__btn json-format__btn--secondary",
|
|
439
|
+
onClick: T,
|
|
440
|
+
disabled: !m.value,
|
|
441
|
+
title: "Compress JSON"
|
|
442
|
+
}, " 📦 Compress ", 8, Ae)
|
|
416
443
|
]),
|
|
417
|
-
|
|
418
|
-
|
|
444
|
+
_("div", Ce, [
|
|
445
|
+
m.value ? (u(), a("span", Ee, " ✅ Valid JSON ")) : (u(), a("span", Ve, " ❌ Invalid JSON "))
|
|
419
446
|
])
|
|
420
|
-
])) :
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
value:
|
|
447
|
+
])) : k("", !0),
|
|
448
|
+
_("div", Oe, [
|
|
449
|
+
m.value ? (u(), a("div", Be, [
|
|
450
|
+
W(Ne, {
|
|
451
|
+
value: p.value,
|
|
425
452
|
"key-name": "",
|
|
426
453
|
level: 0,
|
|
427
|
-
expanded:
|
|
454
|
+
expanded: c.value,
|
|
428
455
|
"is-last": !0,
|
|
429
|
-
"onUpdate:value":
|
|
430
|
-
onToggleExpand:
|
|
431
|
-
onCopy:
|
|
432
|
-
"onUpdate:key":
|
|
456
|
+
"onUpdate:value": J,
|
|
457
|
+
onToggleExpand: I,
|
|
458
|
+
onCopy: P,
|
|
459
|
+
"onUpdate:key": L
|
|
433
460
|
}, null, 8, ["value", "expanded"])
|
|
434
|
-
])) : (u(),
|
|
435
|
-
s[0] || (s[0] =
|
|
436
|
-
|
|
461
|
+
])) : (u(), a("div", we, [
|
|
462
|
+
s[0] || (s[0] = _("h4", null, "JSON Parse Error:", -1)),
|
|
463
|
+
_("pre", null, $(y.value), 1)
|
|
437
464
|
]))
|
|
438
465
|
])
|
|
439
466
|
]));
|
|
440
467
|
}
|
|
441
|
-
}),
|
|
442
|
-
|
|
443
|
-
const o =
|
|
444
|
-
|
|
468
|
+
}), Ie = /* @__PURE__ */ H(xe, [["__scopeId", "data-v-e91f0005"]]), Fe = [Ie], Ue = (h) => {
|
|
469
|
+
Fe.forEach((b) => {
|
|
470
|
+
const o = b.name || b.__name || "UnknownComponent";
|
|
471
|
+
h.component(o, b);
|
|
445
472
|
});
|
|
446
|
-
},
|
|
447
|
-
install:
|
|
473
|
+
}, Pe = {
|
|
474
|
+
install: Ue
|
|
448
475
|
};
|
|
449
476
|
export {
|
|
450
|
-
|
|
451
|
-
|
|
477
|
+
Ie as JsonFormat,
|
|
478
|
+
Pe as default
|
|
452
479
|
};
|
package/dist/lone-format.umd.cjs
CHANGED
|
@@ -1 +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"}})});
|
|
1
|
+
(function(N,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(N=typeof globalThis<"u"?globalThis:N||self,e(N.LoneFormat={},N.Vue))})(this,function(N,e){"use strict";const M={class:"json-node"},P={key:0,class:"json-node__container"},K={class:"json-node__line"},L={key:2,class:"json-node__colon"},G=["title"],R={key:3,class:"json-node__collapsed"},q={key:4,class:"json-node__comma"},z={key:0,class:"json-node__children"},W={class:"json-node__children-content"},H={class:"json-node__line json-node__closing-bracket"},Q={class:"json-node__bracket"},X={key:0,class:"json-node__comma"},Y={key:1,class:"json-node__primitive"},Z={key:2,class:"json-node__colon"},ee=["title"],te={key:5,class:"json-node__comma"},ne=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(B,{emit:k}){e.useCssVars(t=>({56869946:t.level}));const l=B,g=k,d=e.ref(!1),u=e.ref(!1),f=e.ref(""),i=e.ref(""),y=t=>{if(!/^-?\d+(\.\d+)?$/.test(t))return!1;const n=Number(t);return!Number.isSafeInteger(n)||t.length>15},S=e.computed(()=>l.value!==null&&typeof l.value=="object"),E=e.computed(()=>Array.isArray(l.value)),_=e.computed(()=>l.path?l.path:l.keyName?l.keyName:"root"),V=e.computed(()=>l.expanded.has(_.value)),C=e.computed(()=>l.keyName),$=e.computed(()=>E.value?"[":"{"),b=e.computed(()=>E.value?"]":"}"),J=e.computed(()=>{if(!l.value)return"";const n=Object.keys(l.value).length;return E.value?n>0?` ${n} items `:" ":n>0?` ${n} keys `:" "}),A=e.computed(()=>{const t=typeof l.value;return l.value===null?"json-node__value--null":t==="boolean"?"json-node__value--boolean":t==="number"?"json-node__value--number":t==="string"?y(l.value)?"json-node__value--number":"json-node__value--string":""}),w=e.computed(()=>u.value?i.value:l.value===null?"null":typeof l.value=="boolean"||typeof l.value=="number"?String(l.value):typeof l.value=="string"?y(l.value)?l.value:`"${l.value}"`:String(l.value)),O=e.computed(()=>"Click to edit, double-click to copy"),x=t=>l.level===0?t:_.value?`${_.value}.${t}`:t,I=t=>{const n=Object.keys(l.value);return n.indexOf(t)===n.length-1},h=()=>{g("toggle-expand",_.value)},v=()=>{l.level!==0&&(d.value=!0,f.value=l.keyName,e.nextTick(()=>{const t=document.querySelectorAll(".json-node__key-input"),n=t[t.length-1];n&&(n.focus(),n.select())}))},T=()=>{S.value||(u.value=!0,typeof l.value=="string"&&y(l.value)||typeof l.value=="string"?i.value=l.value:i.value=String(l.value),e.nextTick(()=>{const t=document.querySelectorAll(".json-node__value-input"),n=t[t.length-1];n&&(n.focus(),n.select())}))},j=()=>{if(l.level===0||!d.value)return;const t=f.value.trim();if(!t){s();return}if(t===l.keyName){d.value=!1;return}d.value=!1,g("update:key",_.value,t)},o=()=>{try{let t;const n=i.value.trim();if(n==="null")t=null;else if(n==="true"||n==="false")t=n==="true";else if(!isNaN(Number(n))&&n!==""){const r=Number(n);!Number.isSafeInteger(r)||n.length>15?t=n:t=r}else t=i.value;g("update:value",_.value,t),u.value=!1}catch(t){console.error("Failed to parse value:",t),u.value=!1}},s=()=>{d.value=!1,f.value=l.keyName},a=()=>{u.value=!1,typeof l.value=="string"&&y(l.value)||typeof l.value=="string"?i.value=l.value:i.value=String(l.value)};return(t,n)=>{const r=e.resolveComponent("JsonNode",!0);return e.openBlock(),e.createElementBlock("div",M,[S.value?(e.openBlock(),e.createElementBlock("div",P,[e.createElementVNode("div",K,[t.keyName&&!d.value?(e.openBlock(),e.createElementBlock("span",{key:0,class:"json-node__key",onClick:v,title:"Click to edit key"},' "'+e.toDisplayString(C.value)+'" ',1)):e.createCommentVNode("",!0),t.keyName&&d.value?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:1,"onUpdate:modelValue":n[0]||(n[0]=c=>f.value=c),onKeyup:[e.withKeys(j,["enter"]),e.withKeys(s,["escape"])],onBlur:j,class:"json-node__key-input"},null,544)),[[e.vModelText,f.value]]):e.createCommentVNode("",!0),t.keyName?(e.openBlock(),e.createElementBlock("span",L,": ")):e.createCommentVNode("",!0),e.createElementVNode("span",{class:"json-node__bracket json-node__bracket--clickable",onClick:h,title:V.value?"Click to collapse":"Click to expand"},e.toDisplayString($.value),9,G),V.value?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("span",R,[e.createTextVNode(e.toDisplayString(J.value)+" ",1),e.createElementVNode("span",{class:"json-node__bracket json-node__bracket--clickable",onClick:h},e.toDisplayString(b.value),1)])),!V.value&&!t.isLast?(e.openBlock(),e.createElementBlock("span",q,",")):e.createCommentVNode("",!0)]),V.value?(e.openBlock(),e.createElementBlock("div",z,[e.createElementVNode("div",W,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.value,(c,m)=>(e.openBlock(),e.createElementBlock("div",{key:m,class:"json-node__child"},[e.createVNode(r,{value:c,"key-name":E.value?"":String(m),level:t.level+1,path:x(String(m)),expanded:t.expanded,"onUpdate:value":n[1]||(n[1]=(p,F)=>t.$emit("update:value",p,F)),onToggleExpand:n[2]||(n[2]=p=>t.$emit("toggle-expand",p)),onCopy:n[3]||(n[3]=p=>t.$emit("copy",p)),"onUpdate:key":n[4]||(n[4]=(p,F)=>t.$emit("update:key",p,F)),"is-last":I(String(m))},null,8,["value","key-name","level","path","expanded","is-last"])]))),128))]),e.createElementVNode("div",H,[e.createElementVNode("span",Q,e.toDisplayString(b.value),1),t.isLast?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("span",X,","))])])):e.createCommentVNode("",!0)])):(e.openBlock(),e.createElementBlock("div",Y,[t.keyName&&!d.value?(e.openBlock(),e.createElementBlock("span",{key:0,class:"json-node__key",onClick:v,title:"Click to edit key"},' "'+e.toDisplayString(C.value)+'" ',1)):e.createCommentVNode("",!0),t.keyName&&d.value?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:1,"onUpdate:modelValue":n[5]||(n[5]=c=>f.value=c),onKeyup:[e.withKeys(j,["enter"]),e.withKeys(s,["escape"])],onBlur:j,class:"json-node__key-input"},null,544)),[[e.vModelText,f.value]]):e.createCommentVNode("",!0),t.keyName?(e.openBlock(),e.createElementBlock("span",Z,": ")):e.createCommentVNode("",!0),u.value?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("span",{key:3,class:e.normalizeClass(["json-node__value",A.value]),onClick:T,onDblclick:n[6]||(n[6]=c=>t.$emit("copy",t.value)),title:O.value},e.toDisplayString(w.value),43,ee)),u.value?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:4,"onUpdate:modelValue":n[7]||(n[7]=c=>i.value=c),onKeyup:[e.withKeys(o,["enter"]),e.withKeys(a,["escape"])],onBlur:o,class:"json-node__value-input"},null,544)),[[e.vModelText,i.value]]):e.createCommentVNode("",!0),t.isLast?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("span",te,","))]))])}}}),D=(B,k)=>{const l=B.__vccOpts||B;for(const[g,d]of k)l[g]=d;return l},oe=D(ne,[["__scopeId","data-v-5a60a3b2"]]),se={class:"json-format"},le={key:0,class:"json-format__toolbar"},re={class:"json-format__actions"},ae=["disabled"],ce=["disabled"],ie=["disabled"],de=["disabled"],ue={class:"json-format__info"},pe={key:0,class:"json-format__status json-format__status--success"},me={key:1,class:"json-format__status json-format__status--error"},fe={class:"json-format__content"},ye={key:0,class:"json-format__error"},_e={key:1,class:"json-format__viewer"},U=D(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","compress"],setup(B,{expose:k,emit:l}){const g=B,d=l,u=e.ref(null),f=e.ref(""),i=e.ref(new Set),y=e.computed(()=>f.value===""),S=o=>{if(!o.trim()){u.value=null,f.value="";return}try{let s=o;s=s.replace(/:\s*(\d{16,})\s*([,}])/g,': "$1"$2'),s=s.replace(/:\s*(\d+\.\d*?0+)\s*([,}])/g,': "$1"$2'),u.value=JSON.parse(s),f.value="",e.nextTick(()=>{u.value!==null&&b()})}catch(s){f.value=s instanceof Error?s.message:"Unknown parsing error",u.value=null}};e.watch(()=>g.modelValue,o=>{S(o)},{immediate:!0});const E=o=>{if(!/^-?\d+(\.\d+)?$/.test(o))return!1;const s=Number(o);return!Number.isSafeInteger(s)||o.length>15},_=(o,s,a)=>JSON.stringify(o,(t,n)=>{if(typeof n=="string"&&E(n))return`__BIG_NUMBER__${n}__BIG_NUMBER__`;if(typeof n=="string"&&/^-?\d+(\.\d+)?$/.test(n)){const r=Number(n);if(Number.isSafeInteger(r)&&r.toString()===n)return r;if(!Number.isNaN(r)&&isFinite(r)&&n.includes("."))return r.toString()===n?r:n;if(!Number.isNaN(r)&&isFinite(r))return r}return s&&typeof s=="function"?s(t,n):n},a).replace(/"__BIG_NUMBER__(.+?)__BIG_NUMBER__"/g,"$1"),V=(o,s)=>{if(!g.readonly)try{const a=C(u.value,o,s),t=_(a,null,2);d("update:modelValue",t)}catch(a){console.error("Failed to update JSON:",a)}},C=(o,s,a)=>{if(!s||s==="root")return a;const t=s.split("."),n=h(o,t.slice(0,-1));let r=n;for(let m=0;m<t.length-1;m++){const p=t[m];p!=="root"&&(Array.isArray(r)?r=r[parseInt(p)]:r=r[p])}const c=t[t.length-1];return c==="root"?a:(Array.isArray(r)?r[parseInt(c)]=a:r[c]=a,n)},$=o=>{i.value.has(o)?i.value.delete(o):i.value.add(o)},b=()=>{const o=new Set,s=(a,t="")=>{a!==null&&typeof a=="object"&&(o.add(t||"root"),Array.isArray(a)?a.forEach((n,r)=>{const c=t?`${t}.${r}`:`${r}`;s(n,c)}):Object.keys(a).forEach(n=>{const r=t?`${t}.${n}`:n;s(a[n],r)}))};s(u.value),i.value=o,d("expand-all")},J=()=>{i.value=new Set(["root"]),d("collapse-all")},A=async()=>{if(y.value)try{const s=JSON.stringify(u.value,null,2).replace(/"(\d{16,})"/g,"$1");await navigator.clipboard.writeText(s),d("copy-success",s)}catch(o){console.error("Failed to copy JSON:",o),d("copy-error",o instanceof Error?o:new Error("Failed to copy JSON"))}},w=()=>{if(y.value)try{const o=_(u.value);d("update:modelValue",o),d("compress",o)}catch(o){console.error("Failed to compress JSON:",o)}},O=async o=>{try{let s;typeof o=="string"&&E(o)?s=o:typeof o=="string"?s=`"${o}"`:s=JSON.stringify(o),await navigator.clipboard.writeText(s)}catch(s){console.error("Failed to copy value:",s)}},x=(o,s)=>{if(!g.readonly)try{const a=I(u.value,o,s),t=_(a,null,2);d("update:modelValue",t),j(o,s)}catch(a){console.error("Failed to rename key:",a)}},I=(o,s,a)=>{if(!s||s==="root")return o;const t=s.split("."),n=h(o,t.slice(0,-1));if(t.length===1){const m=t[0];return n&&typeof n=="object"&&!Array.isArray(n)?v(n,m,a):n}let r=n;for(let m=0;m<t.length-1;m++){const p=t[m];Array.isArray(r)?r=r[parseInt(p)]:r=r[p]}const c=t[t.length-1];if(!Array.isArray(r)&&r&&typeof r=="object"){const m=v(r,c,a),p=t.slice(0,-1);p.length>0&&T(n,p,m)}return n},h=(o,s)=>{if(s.length===0)return o;if(Array.isArray(o)){const a=[...o],t=s[0],n=parseInt(t);return s.length===1||(a[n]=h(o[n],s.slice(1))),a}else if(o&&typeof o=="object"){const a={...o},t=s[0];return s.length===1||(a[t]=h(o[t],s.slice(1))),a}return o},v=(o,s,a)=>{if(!o||typeof o!="object"||Array.isArray(o))return o;const t=Object.keys(o),n={};for(const r of t)r===s?n[a]=o[r]:n[r]=o[r];return n},T=(o,s,a)=>{let t=o;for(let r=0;r<s.length-1;r++){const c=s[r];Array.isArray(t)?t=t[parseInt(c)]:t=t[c]}const n=s[s.length-1];Array.isArray(t)?t[parseInt(n)]=a:t[n]=a},j=(o,s)=>{const a=new Set;i.value.forEach(t=>{if(t===o){const n=o.split(".");n[n.length-1]=s,a.add(n.join("."))}else if(t.startsWith(o+".")){const n=o.split(".");n[n.length-1]=s;const r=n.join("."),c=t.substring(o.length);a.add(r+c)}else a.add(t)}),i.value=a};return k({copyJson:A,compressSource:w,expandAll:b,collapseAll:J,toggleExpand:$,updateValue:V,updateKey:x,isValidJson:()=>y.value,getParsedJson:()=>u.value,getExpandedNodes:()=>i.value,getParseError:()=>f.value,parseJson:o=>S(o),copyValue:o=>O(o)}),(o,s)=>(e.openBlock(),e.createElementBlock("div",se,[o.showToolbar?(e.openBlock(),e.createElementBlock("div",le,[e.createElementVNode("div",re,[e.createElementVNode("button",{class:"json-format__btn json-format__btn--primary",onClick:A,disabled:!y.value,title:"Copy JSON"}," 📋 Copy ",8,ae),e.createElementVNode("button",{class:"json-format__btn json-format__btn--secondary",onClick:b,disabled:!y.value,title:"Expand All"}," ⬇️ Expand All ",8,ce),e.createElementVNode("button",{class:"json-format__btn json-format__btn--secondary",onClick:J,disabled:!y.value,title:"Collapse All"}," ➡️ Collapse All ",8,ie),e.createElementVNode("button",{class:"json-format__btn json-format__btn--secondary",onClick:w,disabled:!y.value,title:"Compress JSON"}," 📦 Compress ",8,de)]),e.createElementVNode("div",ue,[y.value?(e.openBlock(),e.createElementBlock("span",pe," ✅ Valid JSON ")):(e.openBlock(),e.createElementBlock("span",me," ❌ Invalid JSON "))])])):e.createCommentVNode("",!0),e.createElementVNode("div",fe,[y.value?(e.openBlock(),e.createElementBlock("div",_e,[e.createVNode(oe,{value:u.value,"key-name":"",level:0,expanded:i.value,"is-last":!0,"onUpdate:value":V,onToggleExpand:$,onCopy:O,"onUpdate:key":x},null,8,["value","expanded"])])):(e.openBlock(),e.createElementBlock("div",ye,[s[0]||(s[0]=e.createElementVNode("h4",null,"JSON Parse Error:",-1)),e.createElementVNode("pre",null,e.toDisplayString(f.value),1)]))])]))}}),[["__scopeId","data-v-e91f0005"]]),ke=[U],ge={install:B=>{ke.forEach(k=>{const l=k.name||k.__name||"UnknownComponent";B.component(l,k)})}};N.JsonFormat=U,N.default=ge,Object.defineProperties(N,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|