@miman/json-schema-viewer-react 1.0.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/dist/index.cjs +726 -0
- package/dist/index.js +1204 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/react/SchemaViewer.d.ts +9 -0
- package/dist/types/react/index.d.ts +1 -0
- package/dist/types/styles/ensureStyles.d.ts +1 -0
- package/dist/types/styles/styles.d.ts +7 -0
- package/dist/types/viewerCore.d.ts +15 -0
- package/dist/types/viewerDom.d.ts +11 -0
- package/dist/types/viewerDomNormal.d.ts +13 -0
- package/dist/types/viewerDomTree.d.ts +11 -0
- package/package.json +38 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1204 @@
|
|
|
1
|
+
import { jsx as F } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as D, useMemo as P, useEffect as R } from "react";
|
|
3
|
+
function J() {
|
|
4
|
+
return `
|
|
5
|
+
.schema-container {
|
|
6
|
+
--bg-color: #1e1e1e;
|
|
7
|
+
--text-color: #d4d4d4;
|
|
8
|
+
--border-color: #3c3c3c;
|
|
9
|
+
--header-bg: #252526;
|
|
10
|
+
--type-string: #ce9178;
|
|
11
|
+
--type-number: #b5cea8;
|
|
12
|
+
--type-boolean: #569cd6;
|
|
13
|
+
--type-array: #dcdcaa;
|
|
14
|
+
--type-object: #4ec9b0;
|
|
15
|
+
--type-enum: #8a2be2; /* purple */
|
|
16
|
+
--type-null: #808080;
|
|
17
|
+
--required-color: #d18616; /* Orange */
|
|
18
|
+
--missing-color: #f14c4c; /* Red */
|
|
19
|
+
--description-color: #6a9955;
|
|
20
|
+
--property-name: #9cdcfe;
|
|
21
|
+
--expand-icon: #808080;
|
|
22
|
+
--hover-bg: #2a2d2e;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@media (prefers-color-scheme: light) {
|
|
26
|
+
.schema-container {
|
|
27
|
+
--bg-color: #ffffff;
|
|
28
|
+
--text-color: #333333;
|
|
29
|
+
--border-color: #e0e0e0;
|
|
30
|
+
--header-bg: #f5f5f5;
|
|
31
|
+
--type-string: #a31515;
|
|
32
|
+
--type-number: #098658;
|
|
33
|
+
--type-boolean: #0000ff;
|
|
34
|
+
--type-array: #795e26;
|
|
35
|
+
--type-object: #267f99;
|
|
36
|
+
--type-enum: #6a00d9;
|
|
37
|
+
--type-null: #808080;
|
|
38
|
+
--required-color: #b85a00; /* Darker Orange */
|
|
39
|
+
--missing-color: #d32f2f; /* Darker Red */
|
|
40
|
+
--description-color: #008000;
|
|
41
|
+
--property-name: #001080;
|
|
42
|
+
--expand-icon: #666666;
|
|
43
|
+
--hover-bg: #f0f0f0;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.schema-container {
|
|
48
|
+
width: 100%;
|
|
49
|
+
margin: 0 auto;
|
|
50
|
+
font-family: var(--vscode-font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif);
|
|
51
|
+
font-size: 13px;
|
|
52
|
+
line-height: 1.5;
|
|
53
|
+
color: var(--text-color);
|
|
54
|
+
background-color: var(--bg-color);
|
|
55
|
+
padding: 16px;
|
|
56
|
+
box-sizing: border-box;
|
|
57
|
+
text-align: left;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.schema-container.normal-view {
|
|
61
|
+
max-width: 1200px;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.schema-container * {
|
|
65
|
+
box-sizing: border-box;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.schema-header {
|
|
69
|
+
background: var(--header-bg);
|
|
70
|
+
padding: 16px;
|
|
71
|
+
border-radius: 8px;
|
|
72
|
+
margin-bottom: 16px;
|
|
73
|
+
border: 1px solid var(--border-color);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.schema-header-top {
|
|
77
|
+
display: flex;
|
|
78
|
+
justify-content: space-between;
|
|
79
|
+
align-items: center;
|
|
80
|
+
margin-bottom: 8px;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.schema-title {
|
|
84
|
+
font-size: 24px;
|
|
85
|
+
font-weight: 600;
|
|
86
|
+
color: var(--type-object);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.view-selector {
|
|
90
|
+
display: flex;
|
|
91
|
+
flex-direction: column;
|
|
92
|
+
align-items: flex-end;
|
|
93
|
+
gap: 8px;
|
|
94
|
+
font-size: 12px;
|
|
95
|
+
color: var(--expand-icon);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.view-switch {
|
|
99
|
+
display: inline-flex;
|
|
100
|
+
align-items: center;
|
|
101
|
+
gap: 8px;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.view-switch-label {
|
|
105
|
+
font-size: 12px;
|
|
106
|
+
color: var(--expand-icon);
|
|
107
|
+
user-select: none;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.view-switch-checkbox {
|
|
111
|
+
appearance: none;
|
|
112
|
+
width: 33px;
|
|
113
|
+
height: 18px;
|
|
114
|
+
border-radius: 18px;
|
|
115
|
+
background: var(--border-color);
|
|
116
|
+
position: relative;
|
|
117
|
+
cursor: pointer;
|
|
118
|
+
outline: none;
|
|
119
|
+
display: inline-block;
|
|
120
|
+
vertical-align: middle;
|
|
121
|
+
transition: background 0.15s ease;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.view-switch-checkbox::after {
|
|
125
|
+
content: '';
|
|
126
|
+
position: absolute;
|
|
127
|
+
top: 3px;
|
|
128
|
+
left: 3px;
|
|
129
|
+
width: 12px;
|
|
130
|
+
height: 12px;
|
|
131
|
+
border-radius: 50%;
|
|
132
|
+
background: var(--bg-color);
|
|
133
|
+
box-shadow: 0 1px 2px rgba(0,0,0,0.2);
|
|
134
|
+
transition: transform 0.15s ease;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.view-switch-checkbox:checked::after {
|
|
138
|
+
transform: translateX(15px);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.view-switch-left {
|
|
142
|
+
margin-right: 6px;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.view-switch-right {
|
|
146
|
+
margin-left: 6px;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.active-link-label {
|
|
150
|
+
display: inline-flex;
|
|
151
|
+
align-items: center;
|
|
152
|
+
gap: 6px;
|
|
153
|
+
font-size: 12px;
|
|
154
|
+
color: var(--expand-icon);
|
|
155
|
+
cursor: pointer;
|
|
156
|
+
user-select: none;
|
|
157
|
+
font-style: normal;
|
|
158
|
+
white-space: nowrap;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.active-link-checkbox {
|
|
162
|
+
appearance: none;
|
|
163
|
+
width: 16px;
|
|
164
|
+
height: 16px;
|
|
165
|
+
border: 1px solid var(--border-color);
|
|
166
|
+
border-radius: 3px;
|
|
167
|
+
cursor: pointer;
|
|
168
|
+
position: relative;
|
|
169
|
+
background: var(--bg-color);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.active-link-checkbox:checked {
|
|
173
|
+
background: var(--type-boolean);
|
|
174
|
+
border-color: var(--type-boolean);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
.active-link-checkbox:checked::after {
|
|
178
|
+
content: '✓';
|
|
179
|
+
position: absolute;
|
|
180
|
+
top: 50%;
|
|
181
|
+
left: 50%;
|
|
182
|
+
transform: translate(-50%, -50%);
|
|
183
|
+
color: var(--bg-color);
|
|
184
|
+
font-size: 12px;
|
|
185
|
+
font-weight: bold;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
.source-highlight {
|
|
189
|
+
background-color: rgba(255, 255, 0, 0.2) !important;
|
|
190
|
+
outline: 2px solid rgba(255, 255, 0, 0.4);
|
|
191
|
+
outline-offset: -2px;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
.schema-object-header[data-source-line]:hover {
|
|
195
|
+
cursor: pointer;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
.schema-description {
|
|
199
|
+
color: var(--description-color);
|
|
200
|
+
font-style: italic;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.active-link-bottom-row {
|
|
204
|
+
margin-top: 8px;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.schema-meta {
|
|
208
|
+
display: flex;
|
|
209
|
+
gap: 16px;
|
|
210
|
+
margin-top: 12px;
|
|
211
|
+
font-size: 12px;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
.schema-meta-item {
|
|
215
|
+
display: flex;
|
|
216
|
+
align-items: center;
|
|
217
|
+
gap: 4px;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
.schema-meta-label {
|
|
221
|
+
color: var(--expand-icon);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
.schema-meta-value {
|
|
225
|
+
color: var(--type-string);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
.definitions-section {
|
|
229
|
+
margin-top: 24px;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
.section-title {
|
|
233
|
+
font-size: 18px;
|
|
234
|
+
font-weight: 600;
|
|
235
|
+
margin-bottom: 12px;
|
|
236
|
+
padding-bottom: 8px;
|
|
237
|
+
border-bottom: 1px solid var(--border-color);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
.schema-object {
|
|
241
|
+
border: 1px solid var(--border-color);
|
|
242
|
+
border-radius: 6px;
|
|
243
|
+
margin-bottom: 8px;
|
|
244
|
+
overflow: hidden;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
.schema-object-header {
|
|
248
|
+
display: flex;
|
|
249
|
+
align-items: center;
|
|
250
|
+
padding: 10px 12px;
|
|
251
|
+
background: var(--header-bg);
|
|
252
|
+
cursor: pointer;
|
|
253
|
+
user-select: none;
|
|
254
|
+
transition: background-color 0.15s ease;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
.schema-object-header:hover {
|
|
258
|
+
background: var(--hover-bg);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
.expand-icon {
|
|
262
|
+
width: 16px;
|
|
263
|
+
height: 16px;
|
|
264
|
+
margin-right: 8px;
|
|
265
|
+
color: var(--expand-icon);
|
|
266
|
+
transition: transform 0.2s ease;
|
|
267
|
+
flex-shrink: 0;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
.expand-icon.expanded {
|
|
271
|
+
transform: rotate(90deg);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
.property-name {
|
|
275
|
+
font-weight: 600;
|
|
276
|
+
color: var(--property-name);
|
|
277
|
+
margin-right: 8px;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
.property-type {
|
|
281
|
+
font-size: 12px;
|
|
282
|
+
padding: 2px 8px;
|
|
283
|
+
border-radius: 4px;
|
|
284
|
+
margin-right: 8px;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
.type-string { background: rgba(206, 145, 120, 0.2); color: var(--type-string); }
|
|
288
|
+
.type-integer, .type-number { background: rgba(181, 206, 168, 0.2); color: var(--type-number); }
|
|
289
|
+
.type-boolean { background: rgba(86, 156, 214, 0.2); color: var(--type-boolean); }
|
|
290
|
+
.type-array { background: rgba(220, 220, 170, 0.2); color: var(--type-array); }
|
|
291
|
+
.type-object { background: rgba(78, 201, 176, 0.2); color: var(--type-object); }
|
|
292
|
+
.type-enum { background: rgba(138, 43, 226, 0.12); color: var(--type-enum); }
|
|
293
|
+
.type-null { background: rgba(128, 128, 128, 0.2); color: var(--type-null); }
|
|
294
|
+
|
|
295
|
+
.required-badge {
|
|
296
|
+
font-size: 10px;
|
|
297
|
+
padding: 2px 6px;
|
|
298
|
+
border-radius: 4px;
|
|
299
|
+
background: rgba(209, 134, 22, 0.2);
|
|
300
|
+
color: var(--required-color);
|
|
301
|
+
margin-right: 8px;
|
|
302
|
+
text-transform: uppercase;
|
|
303
|
+
font-weight: 600;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
.missing-badge {
|
|
307
|
+
font-size: 10px;
|
|
308
|
+
padding: 2px 6px;
|
|
309
|
+
border-radius: 4px;
|
|
310
|
+
background: rgba(241, 76, 76, 0.2);
|
|
311
|
+
color: var(--missing-color);
|
|
312
|
+
margin-right: 8px;
|
|
313
|
+
text-transform: uppercase;
|
|
314
|
+
font-weight: 600;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
.imported-badge {
|
|
318
|
+
font-size: 10px;
|
|
319
|
+
padding: 2px 6px;
|
|
320
|
+
border-radius: 4px;
|
|
321
|
+
background: rgba(86, 156, 214, 0.2);
|
|
322
|
+
color: var(--type-boolean);
|
|
323
|
+
margin-right: 8px;
|
|
324
|
+
text-transform: uppercase;
|
|
325
|
+
font-weight: 600;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
.property-description {
|
|
330
|
+
color: var(--description-color);
|
|
331
|
+
font-size: 12px;
|
|
332
|
+
flex: 1;
|
|
333
|
+
overflow: hidden;
|
|
334
|
+
text-overflow: ellipsis;
|
|
335
|
+
white-space: nowrap;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
.schema-object-content {
|
|
339
|
+
display: none;
|
|
340
|
+
padding: 12px;
|
|
341
|
+
border-top: 1px solid var(--border-color);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
.schema-object-content.expanded {
|
|
345
|
+
display: block;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
.property-details {
|
|
349
|
+
font-size: 12px;
|
|
350
|
+
margin-bottom: 12px;
|
|
351
|
+
padding: 8px;
|
|
352
|
+
background: var(--header-bg);
|
|
353
|
+
border-radius: 4px;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
.property-detail-row {
|
|
357
|
+
display: flex;
|
|
358
|
+
margin-bottom: 4px;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
.property-detail-row:last-child {
|
|
362
|
+
margin-bottom: 0;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
.property-detail-label {
|
|
366
|
+
color: var(--expand-icon);
|
|
367
|
+
min-width: 120px;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
.property-detail-value {
|
|
371
|
+
color: var(--text-color);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
.nested-properties {
|
|
375
|
+
margin-left: 16px;
|
|
376
|
+
padding-left: 16px;
|
|
377
|
+
border-left: 2px solid var(--border-color);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
.array-items-label {
|
|
381
|
+
font-size: 11px;
|
|
382
|
+
color: var(--expand-icon);
|
|
383
|
+
margin-bottom: 8px;
|
|
384
|
+
text-transform: uppercase;
|
|
385
|
+
letter-spacing: 0.5px;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
.enum-values {
|
|
389
|
+
display: flex;
|
|
390
|
+
flex-wrap: wrap;
|
|
391
|
+
gap: 4px;
|
|
392
|
+
margin-top: 4px;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
.enum-value {
|
|
396
|
+
font-size: 11px;
|
|
397
|
+
padding: 2px 6px;
|
|
398
|
+
background: var(--header-bg);
|
|
399
|
+
border: 1px solid var(--border-color);
|
|
400
|
+
border-radius: 3px;
|
|
401
|
+
color: var(--type-enum);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
.ref-link {
|
|
405
|
+
color: var(--type-object);
|
|
406
|
+
cursor: pointer;
|
|
407
|
+
text-decoration: underline;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
.ref-link:hover {
|
|
411
|
+
opacity: 0.8;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
.no-properties {
|
|
415
|
+
color: var(--expand-icon);
|
|
416
|
+
font-style: italic;
|
|
417
|
+
padding: 8px;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
.root-type-badge {
|
|
421
|
+
font-size: 12px;
|
|
422
|
+
padding: 4px 12px;
|
|
423
|
+
border-radius: 4px;
|
|
424
|
+
display: inline-block;
|
|
425
|
+
margin-top: 8px;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
.view-toggle {
|
|
429
|
+
display: inline-flex;
|
|
430
|
+
margin-bottom: 12px;
|
|
431
|
+
border: 1px solid var(--border-color);
|
|
432
|
+
border-radius: 4px;
|
|
433
|
+
overflow: hidden;
|
|
434
|
+
font-size: 11px;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
.view-toggle-btn {
|
|
438
|
+
padding: 4px 12px;
|
|
439
|
+
border: none;
|
|
440
|
+
background: transparent;
|
|
441
|
+
color: var(--text-color);
|
|
442
|
+
cursor: pointer;
|
|
443
|
+
font-size: 11px;
|
|
444
|
+
font-family: inherit;
|
|
445
|
+
transition: background-color 0.15s ease;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
.view-toggle-btn:hover {
|
|
449
|
+
background: var(--hover-bg);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
.view-toggle-btn.active {
|
|
453
|
+
background: var(--type-object);
|
|
454
|
+
color: #ffffff;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
.view-toggle-btn:first-child {
|
|
458
|
+
border-right: 1px solid var(--border-color);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
.object-example-view {
|
|
462
|
+
background: var(--bg-color);
|
|
463
|
+
border: 1px solid var(--border-color);
|
|
464
|
+
border-radius: 4px;
|
|
465
|
+
padding: 12px;
|
|
466
|
+
margin-top: 8px;
|
|
467
|
+
overflow-x: auto;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
.object-example-view pre {
|
|
471
|
+
margin: 0;
|
|
472
|
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
|
473
|
+
font-size: 12px;
|
|
474
|
+
line-height: 1.4;
|
|
475
|
+
white-space: pre-wrap;
|
|
476
|
+
word-break: break-word;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
.example-view {
|
|
480
|
+
background: var(--header-bg);
|
|
481
|
+
border: 1px solid var(--border-color);
|
|
482
|
+
border-radius: 6px;
|
|
483
|
+
padding: 16px;
|
|
484
|
+
overflow-x: auto;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
.example-view pre {
|
|
488
|
+
margin: 0;
|
|
489
|
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
|
490
|
+
font-size: 13px;
|
|
491
|
+
line-height: 1.5;
|
|
492
|
+
white-space: pre-wrap;
|
|
493
|
+
word-break: break-word;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
.example-view .json-key {
|
|
497
|
+
color: var(--property-name);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
.example-view .json-string {
|
|
501
|
+
color: var(--type-string);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
.example-view .json-number {
|
|
505
|
+
color: var(--type-number);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
.example-view .json-boolean {
|
|
509
|
+
color: var(--type-boolean);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
.example-view .json-null {
|
|
513
|
+
color: var(--type-null);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/* Styles for the new Imported Files section */
|
|
517
|
+
.imported-files-container {
|
|
518
|
+
margin-top: 12px; /* Adjust margin as section-title now precedes it */
|
|
519
|
+
padding: 16px;
|
|
520
|
+
border: 1px solid var(--border-color);
|
|
521
|
+
border-radius: 8px;
|
|
522
|
+
background: var(--header-bg);
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
.imported-files-container ul {
|
|
526
|
+
list-style: none; /* Remove default list bullets */
|
|
527
|
+
padding-left: 0;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
.imported-files-container li {
|
|
531
|
+
margin-bottom: 8px;
|
|
532
|
+
color: var(--text-color);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/* Tree View Styles */
|
|
536
|
+
.tree-view-wrapper {
|
|
537
|
+
width: 100%;
|
|
538
|
+
overflow-x: auto;
|
|
539
|
+
overflow-y: hidden;
|
|
540
|
+
padding: 20px 0;
|
|
541
|
+
display: block;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
.tree-view-container {
|
|
545
|
+
position: relative;
|
|
546
|
+
display: inline-flex;
|
|
547
|
+
min-width: 100%;
|
|
548
|
+
padding-bottom: 40px;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
.tree-nodes-container {
|
|
552
|
+
display: flex;
|
|
553
|
+
gap: 60px;
|
|
554
|
+
z-index: 1;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
.tree-column {
|
|
558
|
+
display: flex;
|
|
559
|
+
flex-direction: column;
|
|
560
|
+
gap: 20px;
|
|
561
|
+
justify-content: center;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
.tree-node {
|
|
565
|
+
background: var(--header-bg);
|
|
566
|
+
border: 1px solid var(--border-color);
|
|
567
|
+
border-radius: 8px;
|
|
568
|
+
padding: 12px;
|
|
569
|
+
min-width: 180px;
|
|
570
|
+
max-width: 300px;
|
|
571
|
+
position: relative;
|
|
572
|
+
transition: transform 0.2s ease, box-shadow 0.2s ease;
|
|
573
|
+
cursor: default;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
.tree-node:hover {
|
|
577
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
|
|
578
|
+
border-color: var(--type-object);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
.tree-node-header {
|
|
582
|
+
display: flex;
|
|
583
|
+
flex-direction: column;
|
|
584
|
+
gap: 4px;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
.tree-node-title-row {
|
|
588
|
+
display: flex;
|
|
589
|
+
align-items: center;
|
|
590
|
+
justify-content: space-between;
|
|
591
|
+
gap: 8px;
|
|
592
|
+
margin-bottom: 2px;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
.tree-node-meta {
|
|
596
|
+
font-size: 11px;
|
|
597
|
+
margin-top: 8px;
|
|
598
|
+
padding-top: 8px;
|
|
599
|
+
border-top: 1px solid var(--border-color);
|
|
600
|
+
display: flex;
|
|
601
|
+
flex-direction: column;
|
|
602
|
+
gap: 4px;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
.tree-node-meta-item {
|
|
606
|
+
color: var(--text-color);
|
|
607
|
+
opacity: 0.9;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
.tree-node-meta-item code {
|
|
611
|
+
background: rgba(0,0,0,0.1);
|
|
612
|
+
padding: 1px 4px;
|
|
613
|
+
border-radius: 3px;
|
|
614
|
+
font-family: 'Consolas', monospace;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
.tree-enum-values {
|
|
618
|
+
color: var(--type-string);
|
|
619
|
+
font-size: 10px;
|
|
620
|
+
word-break: break-all;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
.tree-node-header .property-name {
|
|
624
|
+
margin-right: 0;
|
|
625
|
+
font-size: 14px;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
.tree-node-description {
|
|
629
|
+
font-size: 11px;
|
|
630
|
+
color: var(--description-color);
|
|
631
|
+
margin-top: 8px;
|
|
632
|
+
border-top: 1px solid var(--border-color);
|
|
633
|
+
padding-top: 8px;
|
|
634
|
+
font-style: italic;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
.tree-node-toggle {
|
|
638
|
+
position: absolute;
|
|
639
|
+
right: -12px;
|
|
640
|
+
top: 50%;
|
|
641
|
+
transform: translateY(-50%);
|
|
642
|
+
width: 20px;
|
|
643
|
+
height: 20px;
|
|
644
|
+
background: var(--type-object);
|
|
645
|
+
color: white;
|
|
646
|
+
border-radius: 50%;
|
|
647
|
+
display: flex;
|
|
648
|
+
align-items: center;
|
|
649
|
+
justify-content: center;
|
|
650
|
+
font-size: 14px;
|
|
651
|
+
cursor: pointer;
|
|
652
|
+
border: 2px solid var(--bg-color);
|
|
653
|
+
z-index: 2;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
.tree-connectors {
|
|
657
|
+
position: absolute;
|
|
658
|
+
top: 0;
|
|
659
|
+
left: 0;
|
|
660
|
+
pointer-events: none;
|
|
661
|
+
z-index: 0;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
.tree-connector-line {
|
|
665
|
+
fill: none;
|
|
666
|
+
stroke: var(--border-color);
|
|
667
|
+
stroke-width: 1.5px;
|
|
668
|
+
transition: stroke 0.2s ease;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
.tree-node:hover + .tree-connector-line {
|
|
672
|
+
stroke: var(--type-object);
|
|
673
|
+
}
|
|
674
|
+
`;
|
|
675
|
+
}
|
|
676
|
+
const S = "json-schema-viewer-styles";
|
|
677
|
+
function B() {
|
|
678
|
+
if (typeof document > "u" || document.getElementById(S)) return;
|
|
679
|
+
const e = document.createElement("style");
|
|
680
|
+
e.id = S, e.textContent = J(), document.head.appendChild(e);
|
|
681
|
+
}
|
|
682
|
+
function T(e) {
|
|
683
|
+
const t = Math.max(e.lastIndexOf("/"), e.lastIndexOf("\\"));
|
|
684
|
+
return t >= 0 ? e.slice(t + 1) : e;
|
|
685
|
+
}
|
|
686
|
+
function O(e) {
|
|
687
|
+
if (!e || typeof e != "object")
|
|
688
|
+
return !1;
|
|
689
|
+
for (const t in e) {
|
|
690
|
+
if (!Object.prototype.hasOwnProperty.call(e, t)) continue;
|
|
691
|
+
const n = e[t];
|
|
692
|
+
if (t === "$ref" && typeof n == "string" && n.includes(".json") || O(n))
|
|
693
|
+
return !0;
|
|
694
|
+
}
|
|
695
|
+
return !1;
|
|
696
|
+
}
|
|
697
|
+
function C(e, t, n) {
|
|
698
|
+
if (!e || !e.$ref)
|
|
699
|
+
return e || {};
|
|
700
|
+
const r = e.$ref, c = n || {};
|
|
701
|
+
let l = null, d = !1;
|
|
702
|
+
if (r.includes(".json#/")) {
|
|
703
|
+
const [s, p] = r.split("#"), i = T(s), a = c[i];
|
|
704
|
+
if (!a)
|
|
705
|
+
return { $ref: r, __isMissing: !0 };
|
|
706
|
+
let o = a;
|
|
707
|
+
const m = (p || "").split("/").slice(1);
|
|
708
|
+
for (const f of m)
|
|
709
|
+
if (o && typeof o == "object" && f in o)
|
|
710
|
+
o = o[f];
|
|
711
|
+
else
|
|
712
|
+
return { $ref: r, __isMissing: !0 };
|
|
713
|
+
l = o, d = !0;
|
|
714
|
+
} else if (r.includes(".json")) {
|
|
715
|
+
const s = T(r.split("#")[0]);
|
|
716
|
+
if (l = c[s], !l)
|
|
717
|
+
return { $ref: r, __isMissing: !0 };
|
|
718
|
+
d = !0;
|
|
719
|
+
} else if (r.startsWith("#/")) {
|
|
720
|
+
let s = t;
|
|
721
|
+
const p = r.split("/").slice(1);
|
|
722
|
+
for (const i of p)
|
|
723
|
+
if (s && typeof s == "object" && i in s)
|
|
724
|
+
s = s[i];
|
|
725
|
+
else
|
|
726
|
+
return { $ref: r, __isMissing: !0 };
|
|
727
|
+
l = s;
|
|
728
|
+
}
|
|
729
|
+
if (l && d) {
|
|
730
|
+
const s = { ...l };
|
|
731
|
+
return Object.defineProperty(s, "__isImported", { value: !0, enumerable: !1 }), s;
|
|
732
|
+
}
|
|
733
|
+
return l || e;
|
|
734
|
+
}
|
|
735
|
+
function L(e) {
|
|
736
|
+
return e ? e.__isMissing ? "missing" : e.$ref ? "ref" : e.type ? Array.isArray(e.type) ? e.type.join(" | ") : e.type : e.enum ? "enum" : e.oneOf ? "oneOf" : e.anyOf ? "anyOf" : e.allOf ? "allOf" : e.properties ? "object" : e.items ? "array" : "any" : "any";
|
|
737
|
+
}
|
|
738
|
+
function M(e) {
|
|
739
|
+
return e ? !!(e.properties || e.items || e.oneOf || e.anyOf || e.allOf || e.description || e.enum || e.default !== void 0 || e.example !== void 0 || e.format || e.pattern || e.minimum !== void 0 || e.maximum !== void 0 || e.minLength !== void 0 || e.maxLength !== void 0) : !1;
|
|
740
|
+
}
|
|
741
|
+
function E(e, t, n, r) {
|
|
742
|
+
if (!e) return null;
|
|
743
|
+
if (e.$ref) {
|
|
744
|
+
if (r.has(e.$ref))
|
|
745
|
+
return "...";
|
|
746
|
+
r.add(e.$ref);
|
|
747
|
+
const l = C(e, t, n), d = E(l, t, n, r);
|
|
748
|
+
return r.delete(e.$ref), d;
|
|
749
|
+
}
|
|
750
|
+
if (e.example !== void 0) return e.example;
|
|
751
|
+
if (e.default !== void 0) return e.default;
|
|
752
|
+
if (e.enum && e.enum.length > 0) return e.enum[0];
|
|
753
|
+
if (e.const !== void 0) return e.const;
|
|
754
|
+
if (e.oneOf && e.oneOf.length > 0)
|
|
755
|
+
return E(e.oneOf[0], t, n, r);
|
|
756
|
+
if (e.anyOf && e.anyOf.length > 0)
|
|
757
|
+
return E(e.anyOf[0], t, n, r);
|
|
758
|
+
if (e.allOf && e.allOf.length > 0) {
|
|
759
|
+
let l = {};
|
|
760
|
+
for (const d of e.allOf) {
|
|
761
|
+
const s = C(d, t, n);
|
|
762
|
+
if (s.properties) {
|
|
763
|
+
const p = E(s, t, n, r);
|
|
764
|
+
l = { ...l, ...p };
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
return l;
|
|
768
|
+
}
|
|
769
|
+
const c = Array.isArray(e.type) ? e.type[0] : e.type;
|
|
770
|
+
switch (c) {
|
|
771
|
+
case "object": {
|
|
772
|
+
if (e.properties) {
|
|
773
|
+
const l = {};
|
|
774
|
+
for (const [d, s] of Object.entries(e.properties))
|
|
775
|
+
l[d] = E(s, t, n, r);
|
|
776
|
+
return l;
|
|
777
|
+
}
|
|
778
|
+
return {};
|
|
779
|
+
}
|
|
780
|
+
case "array":
|
|
781
|
+
return e.items ? [E(e.items, t, n, r)] : [];
|
|
782
|
+
case "string":
|
|
783
|
+
return e.format === "date-time" ? (/* @__PURE__ */ new Date()).toISOString() : e.format === "date" ? (/* @__PURE__ */ new Date()).toISOString().split("T")[0] : e.format === "time" ? "12:00:00" : e.format === "email" ? "user@example.com" : e.format === "uri" || e.format === "url" ? "https://example.com" : e.format === "uuid" ? "550e8400-e29b-41d4-a716-446655440000" : e.minLength ? "x".repeat(e.minLength) : "string";
|
|
784
|
+
case "number":
|
|
785
|
+
case "integer":
|
|
786
|
+
return e.minimum !== void 0 ? e.minimum : e.maximum !== void 0 ? e.maximum : 0;
|
|
787
|
+
case "boolean":
|
|
788
|
+
return !0;
|
|
789
|
+
case "null":
|
|
790
|
+
return null;
|
|
791
|
+
default: {
|
|
792
|
+
if (e.properties) {
|
|
793
|
+
const l = {};
|
|
794
|
+
for (const [d, s] of Object.entries(e.properties))
|
|
795
|
+
l[d] = E(s, t, n, r);
|
|
796
|
+
return l;
|
|
797
|
+
}
|
|
798
|
+
return e.items ? [E(e.items, t, n, r)] : null;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
function K(e) {
|
|
803
|
+
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\\"])*")(\s*:)?/g, (t) => {
|
|
804
|
+
let n = "json-string";
|
|
805
|
+
return /:$/.test(t) && (n = "json-key"), '<span class="' + n + '">' + t + "</span>";
|
|
806
|
+
}).replace(/\b(true|false)\b/g, '<span class="json-boolean">$1</span>').replace(/\bnull\b/g, '<span class="json-null">null</span>').replace(/\b(-?\d+(\.\d+)?([eE][+-]?\d+)?)\b/g, '<span class="json-number">$1</span>');
|
|
807
|
+
}
|
|
808
|
+
function g(e) {
|
|
809
|
+
if (typeof e != "string") return String(e ?? "");
|
|
810
|
+
const t = document.createElement("div");
|
|
811
|
+
return t.textContent = e, t.innerHTML;
|
|
812
|
+
}
|
|
813
|
+
function W(e, t) {
|
|
814
|
+
const n = t.schema, r = t.bundle ?? {}, c = t.importedFileNames ?? [], l = t.missingFileNames ?? [], d = t.sourcePositions ?? {}, s = t.activeLinkEnabled ?? !1, p = t.onNavigateToSource;
|
|
815
|
+
if (n.properties) {
|
|
816
|
+
const a = document.createElement("div");
|
|
817
|
+
a.innerHTML = '<div class="section-title">Properties</div>';
|
|
818
|
+
const o = n.required || [];
|
|
819
|
+
N(a, n.properties, o, n, r, d, s, p, "properties"), e.appendChild(a);
|
|
820
|
+
}
|
|
821
|
+
const i = n.definitions || n.$defs || {};
|
|
822
|
+
if (Object.keys(i).length > 0) {
|
|
823
|
+
const a = document.createElement("div");
|
|
824
|
+
a.className = "definitions-section", a.innerHTML = '<div class="section-title">Definitions</div>';
|
|
825
|
+
const o = n.definitions ? "definitions" : "$defs";
|
|
826
|
+
for (const [m, f] of Object.entries(i)) {
|
|
827
|
+
const v = X(String(m), f, n, r, d, s, p, o);
|
|
828
|
+
a.appendChild(v);
|
|
829
|
+
}
|
|
830
|
+
e.appendChild(a);
|
|
831
|
+
}
|
|
832
|
+
if (c.length > 0) {
|
|
833
|
+
const a = document.createElement("h2");
|
|
834
|
+
a.className = "section-title", a.textContent = "Imported files", e.appendChild(a);
|
|
835
|
+
const o = document.createElement("div");
|
|
836
|
+
o.className = "imported-files-container";
|
|
837
|
+
const m = document.createElement("ul");
|
|
838
|
+
c.forEach((f) => {
|
|
839
|
+
const v = document.createElement("li");
|
|
840
|
+
if (v.textContent = f, l.includes(f)) {
|
|
841
|
+
const h = document.createElement("span");
|
|
842
|
+
h.className = "missing-badge", h.textContent = "file not found", v.appendChild(document.createTextNode(" ")), v.appendChild(h);
|
|
843
|
+
}
|
|
844
|
+
m.appendChild(v);
|
|
845
|
+
}), o.appendChild(m), e.appendChild(o);
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
function N(e, t, n, r, c, l, d, s, p) {
|
|
849
|
+
for (const [i, a] of Object.entries(t)) {
|
|
850
|
+
const o = n.includes(i), m = `${p}.${i}`, f = A(i, a, o, r, c, l, d, s, m);
|
|
851
|
+
e.appendChild(f);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
function A(e, t, n, r, c, l, d, s, p) {
|
|
855
|
+
const i = document.createElement("div");
|
|
856
|
+
i.className = "schema-object";
|
|
857
|
+
const a = C(t, r, c), o = L(a), m = M(a), f = a.description || "", v = a.__isImported || O(t), h = a.__isMissing, w = l[p], x = (b) => {
|
|
858
|
+
if (!b) return null;
|
|
859
|
+
const u = b.match(/[#/](\$defs|definitions)\/([^/]+)$/);
|
|
860
|
+
if (u) return u[2];
|
|
861
|
+
const k = b.match(/\/([^/]+)$/);
|
|
862
|
+
return k ? k[1] : null;
|
|
863
|
+
};
|
|
864
|
+
let $ = o;
|
|
865
|
+
if (t.$ref) {
|
|
866
|
+
const b = x(t.$ref);
|
|
867
|
+
b && ($ = `object<${b}>`);
|
|
868
|
+
} else if (o === "array" && t.items?.$ref) {
|
|
869
|
+
const b = x(t.items.$ref);
|
|
870
|
+
b && ($ = `array<${b}>`);
|
|
871
|
+
}
|
|
872
|
+
const y = document.createElement("div");
|
|
873
|
+
if (y.className = "schema-object-header", w !== void 0 && (y.dataset.sourceLine = String(w)), y.innerHTML = `
|
|
874
|
+
${m ? '<svg class="expand-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M9 18l6-6-6-6"/></svg>' : '<div style="width: 24px;"></div>'}
|
|
875
|
+
<span class="property-name">${g(e)}</span>
|
|
876
|
+
<span class="property-type type-${g(o)}">${o === "missing" ? "file not found" : g($)}</span>
|
|
877
|
+
${n ? '<span class="required-badge">required</span>' : ""}
|
|
878
|
+
${v ? '<span class="imported-badge">imported</span>' : ""}
|
|
879
|
+
${h ? '<span class="missing-badge">file not found</span>' : ""}
|
|
880
|
+
${f ? `<span class="property-description">${g(f)}</span>` : ""}
|
|
881
|
+
`, y.addEventListener("click", (b) => {
|
|
882
|
+
if (m) {
|
|
883
|
+
const u = i.querySelector(".schema-object-content"), k = y.querySelector(".expand-icon");
|
|
884
|
+
u?.classList.toggle("expanded"), k?.classList.toggle("expanded");
|
|
885
|
+
}
|
|
886
|
+
d && w !== void 0 && s && (s(w), b.stopPropagation());
|
|
887
|
+
}), i.appendChild(y), m && !h) {
|
|
888
|
+
const b = document.createElement("div");
|
|
889
|
+
b.className = "schema-object-content", H(b, a, r, c, l, d, s, p), i.appendChild(b);
|
|
890
|
+
}
|
|
891
|
+
return i;
|
|
892
|
+
}
|
|
893
|
+
function H(e, t, n, r, c, l, d, s) {
|
|
894
|
+
if (!(t.properties || t.items || t.oneOf || t.anyOf || t.allOf)) {
|
|
895
|
+
q(e, t, n, r, c, l, d, s);
|
|
896
|
+
return;
|
|
897
|
+
}
|
|
898
|
+
let i = "schema";
|
|
899
|
+
const a = document.createElement("div");
|
|
900
|
+
a.className = "view-toggle", a.innerHTML = `
|
|
901
|
+
<button class="view-toggle-btn" data-view="example">Example Value</button>
|
|
902
|
+
<button class="view-toggle-btn active" data-view="schema">Schema</button>
|
|
903
|
+
`;
|
|
904
|
+
const o = document.createElement("div");
|
|
905
|
+
o.className = "property-content-area";
|
|
906
|
+
const m = () => {
|
|
907
|
+
if (o.innerHTML = "", a.querySelectorAll(".view-toggle-btn").forEach((f) => {
|
|
908
|
+
f.classList.toggle("active", f.dataset.view === i);
|
|
909
|
+
}), i === "example") {
|
|
910
|
+
const f = document.createElement("div");
|
|
911
|
+
f.className = "object-example-view";
|
|
912
|
+
const v = E(t, n, r, /* @__PURE__ */ new Set()), h = K(JSON.stringify(v, null, 2));
|
|
913
|
+
f.innerHTML = `<pre>${h}</pre>`, o.appendChild(f);
|
|
914
|
+
} else
|
|
915
|
+
q(o, t, n, r, c, l, d, s);
|
|
916
|
+
};
|
|
917
|
+
a.addEventListener("click", (f) => {
|
|
918
|
+
const v = f.target?.closest(".view-toggle-btn");
|
|
919
|
+
v && v.dataset.view && v.dataset.view !== i && (i = v.dataset.view, m());
|
|
920
|
+
}), e.appendChild(a), e.appendChild(o), m();
|
|
921
|
+
}
|
|
922
|
+
function q(e, t, n, r, c, l, d, s) {
|
|
923
|
+
const p = document.createElement("div");
|
|
924
|
+
p.className = "property-details";
|
|
925
|
+
let i = "";
|
|
926
|
+
if (t.description && (i += `<div class="property-detail-row"><span class="property-detail-label">Description:</span><span class="property-detail-value">${g(t.description)}</span></div>`), t.default !== void 0 && (i += `<div class="property-detail-row"><span class="property-detail-label">Default:</span><span class="property-detail-value">${g(JSON.stringify(t.default))}</span></div>`), t.example !== void 0 && (i += `<div class="property-detail-row"><span class="property-detail-label">Example:</span><span class="property-detail-value">${g(JSON.stringify(t.example))}</span></div>`), t.format && (i += `<div class="property-detail-row"><span class="property-detail-label">Format:</span><span class="property-detail-value">${g(t.format)}</span></div>`), t.pattern && (i += `<div class="property-detail-row"><span class="property-detail-label">Pattern:</span><span class="property-detail-value">${g(t.pattern)}</span></div>`), t.minimum !== void 0 && (i += `<div class="property-detail-row"><span class="property-detail-label">Minimum:</span><span class="property-detail-value">${String(t.minimum)}</span></div>`), t.maximum !== void 0 && (i += `<div class="property-detail-row"><span class="property-detail-label">Maximum:</span><span class="property-detail-value">${String(t.maximum)}</span></div>`), t.minLength !== void 0 && (i += `<div class="property-detail-row"><span class="property-detail-label">Min Length:</span><span class="property-detail-value">${String(t.minLength)}</span></div>`), t.maxLength !== void 0 && (i += `<div class="property-detail-row"><span class="property-detail-label">Max Length:</span><span class="property-detail-value">${String(t.maxLength)}</span></div>`), t.minItems !== void 0 && (i += `<div class="property-detail-row"><span class="property-detail-label">Min Items:</span><span class="property-detail-value">${String(t.minItems)}</span></div>`), t.maxItems !== void 0 && (i += `<div class="property-detail-row"><span class="property-detail-label">Max Items:</span><span class="property-detail-value">${String(t.maxItems)}</span></div>`), t.enum && (i += `<div class="property-detail-row"><span class="property-detail-label">Enum Values:</span><span class="property-detail-value"><div class="enum-values">${t.enum.map((a) => `<span class="enum-value">${g(JSON.stringify(a))}</span>`).join("")}</div></span></div>`), i && (p.innerHTML = i, e.appendChild(p)), t.properties) {
|
|
927
|
+
const a = document.createElement("div");
|
|
928
|
+
a.className = "nested-properties";
|
|
929
|
+
const o = t.required || [];
|
|
930
|
+
N(a, t.properties, o, n, r, c, l, d, `${s}.properties`), e.appendChild(a);
|
|
931
|
+
}
|
|
932
|
+
if (t.items) {
|
|
933
|
+
const a = document.createElement("div");
|
|
934
|
+
a.className = "array-items-label", a.textContent = "Array Items:", e.appendChild(a);
|
|
935
|
+
const o = C(t.items, n, r);
|
|
936
|
+
if (o.properties) {
|
|
937
|
+
const m = document.createElement("div");
|
|
938
|
+
m.className = "nested-properties";
|
|
939
|
+
const f = o.required || [];
|
|
940
|
+
N(m, o.properties, f, n, r, c, l, d, `${s}.items.properties`), e.appendChild(m);
|
|
941
|
+
} else {
|
|
942
|
+
const m = L(o), f = document.createElement("div");
|
|
943
|
+
f.innerHTML = `<span class="property-type type-${g(m)}">${g(m)}</span>`, o.description && (f.innerHTML += ` <span class="property-description">${g(o.description)}</span>`), e.appendChild(f);
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
["oneOf", "anyOf", "allOf"].forEach((a) => {
|
|
947
|
+
if (t[a]) {
|
|
948
|
+
const o = document.createElement("div");
|
|
949
|
+
o.className = "array-items-label", o.textContent = a + ":", e.appendChild(o), t[a].forEach((m, f) => {
|
|
950
|
+
const v = C(m, n, r), h = `${s}.${a}.${f}`, w = A(`Option ${f + 1}`, v, !1, n, r, c, l, d, h);
|
|
951
|
+
e.appendChild(w);
|
|
952
|
+
});
|
|
953
|
+
}
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
function X(e, t, n, r, c, l, d, s) {
|
|
957
|
+
const p = document.createElement("div");
|
|
958
|
+
p.className = "schema-object", p.id = `def-${e}`;
|
|
959
|
+
const i = C(t, n, r), a = L(i), o = M(i), m = i.description || "", f = i.__isImported || O(t), v = i.__isMissing, h = `${s}.${e}`, w = c[h], x = document.createElement("div");
|
|
960
|
+
if (x.className = "schema-object-header", w !== void 0 && (x.dataset.sourceLine = String(w)), x.innerHTML = `
|
|
961
|
+
${o ? '<svg class="expand-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M9 18l6-6-6-6"/></svg>' : '<div style="width: 24px;"></div>'}
|
|
962
|
+
<span class="property-name">${g(e)}</span>
|
|
963
|
+
<span class="property-type type-${g(a)}">${a === "missing" ? "file not found" : g(a)}</span>
|
|
964
|
+
${f ? '<span class="imported-badge">imported</span>' : ""}
|
|
965
|
+
${v ? '<span class="missing-badge">file not found</span>' : ""}
|
|
966
|
+
${m ? `<span class="property-description">${g(m)}</span>` : ""}
|
|
967
|
+
`, x.addEventListener("click", ($) => {
|
|
968
|
+
if (o) {
|
|
969
|
+
const y = p.querySelector(".schema-object-content"), b = x.querySelector(".expand-icon");
|
|
970
|
+
y?.classList.toggle("expanded"), b?.classList.toggle("expanded");
|
|
971
|
+
}
|
|
972
|
+
l && w !== void 0 && d && (d(w), $.stopPropagation());
|
|
973
|
+
}), p.appendChild(x), o && !v) {
|
|
974
|
+
const $ = document.createElement("div");
|
|
975
|
+
$.className = "schema-object-content", H($, i, n, r, c, l, d, h), p.appendChild($);
|
|
976
|
+
}
|
|
977
|
+
return p;
|
|
978
|
+
}
|
|
979
|
+
function Y(e, t) {
|
|
980
|
+
const { schema: n, bundle: r = {}, sourcePositions: c = {}, activeLinkEnabled: l = !1, onNavigateToSource: d } = t;
|
|
981
|
+
e.innerHTML = "", e.classList.add("tree-view-wrapper");
|
|
982
|
+
const s = Z(n);
|
|
983
|
+
G(e, s, n, r, c, l, d);
|
|
984
|
+
}
|
|
985
|
+
function Z(e, t) {
|
|
986
|
+
return {
|
|
987
|
+
name: e.title || "root",
|
|
988
|
+
prop: e,
|
|
989
|
+
level: 0,
|
|
990
|
+
children: [],
|
|
991
|
+
isExpanded: !0,
|
|
992
|
+
parentId: null,
|
|
993
|
+
id: "root",
|
|
994
|
+
jsonPath: ""
|
|
995
|
+
};
|
|
996
|
+
}
|
|
997
|
+
function G(e, t, n, r, c, l, d) {
|
|
998
|
+
const s = document.createElement("div");
|
|
999
|
+
s.className = "tree-view-container", e.appendChild(s);
|
|
1000
|
+
const p = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
1001
|
+
p.setAttribute("class", "tree-connectors"), s.appendChild(p);
|
|
1002
|
+
const i = document.createElement("div");
|
|
1003
|
+
i.className = "tree-nodes-container", s.appendChild(i);
|
|
1004
|
+
const a = {
|
|
1005
|
+
expandedNodes: /* @__PURE__ */ new Set(["root"]),
|
|
1006
|
+
nodeElements: /* @__PURE__ */ new Map()
|
|
1007
|
+
}, o = () => {
|
|
1008
|
+
i.innerHTML = "", a.nodeElements.clear(), _(i, t, 0, a, n, r, o, c, l, d), setTimeout(() => I(p, a), 0);
|
|
1009
|
+
};
|
|
1010
|
+
o(), window.addEventListener("resize", () => I(p, a));
|
|
1011
|
+
}
|
|
1012
|
+
function _(e, t, n, r, c, l, d, s, p, i) {
|
|
1013
|
+
const a = Q(e, n), o = document.createElement("div");
|
|
1014
|
+
o.className = "tree-node", o.id = `node-${t.id}`;
|
|
1015
|
+
const m = C(t.prop, c, l);
|
|
1016
|
+
let f = t.jsonPath || "";
|
|
1017
|
+
if (t.prop.$ref && typeof t.prop.$ref == "string") {
|
|
1018
|
+
const u = t.prop.$ref.match(/#\/(.+)$/);
|
|
1019
|
+
u && (f = u[1].replace(/\//g, "."));
|
|
1020
|
+
}
|
|
1021
|
+
const v = f ? s[f] : void 0;
|
|
1022
|
+
v !== void 0 && (o.dataset.sourceLine = String(v));
|
|
1023
|
+
const h = L(m), w = M(m), x = r.expandedNodes.has(t.id), $ = (u) => {
|
|
1024
|
+
if (!u) return null;
|
|
1025
|
+
const k = u.match(/[#/](\$defs|definitions)\/([^/]+)$/);
|
|
1026
|
+
if (k) return k[2];
|
|
1027
|
+
const z = u.match(/\/([^/]+)$/);
|
|
1028
|
+
return z ? z[1] : null;
|
|
1029
|
+
};
|
|
1030
|
+
let y = m.enum ? "enum" : h;
|
|
1031
|
+
if (t.prop.$ref) {
|
|
1032
|
+
const u = $(t.prop.$ref);
|
|
1033
|
+
u && (y = u);
|
|
1034
|
+
} else if (h === "array" && t.prop.items?.$ref) {
|
|
1035
|
+
const u = $(t.prop.items.$ref);
|
|
1036
|
+
u && (y = `array<${u}>`);
|
|
1037
|
+
} else if (h === "object" && m.properties) {
|
|
1038
|
+
const u = Object.keys(m.properties).length;
|
|
1039
|
+
y = `object (${u} ${u === 1 ? "property" : "properties"})`;
|
|
1040
|
+
} else if (h === "array" && m.items) {
|
|
1041
|
+
const u = C(m.items, c, l);
|
|
1042
|
+
y = `array<${L(u)}>`;
|
|
1043
|
+
}
|
|
1044
|
+
let b = "";
|
|
1045
|
+
x && (m.pattern && (b += `<div class="tree-node-meta-item">Pattern: <code>${g(m.pattern)}</code></div>`), m.minLength !== void 0 && (b += `<div class="tree-node-meta-item">Min Length: ${m.minLength}</div>`)), m.enum && (b += `<div class="tree-node-meta-item">Enum: <span class="tree-enum-values">${m.enum.map((u) => JSON.stringify(u)).join(", ")}</span></div>`), o.innerHTML = `
|
|
1046
|
+
<div class="tree-node-header">
|
|
1047
|
+
<div class="tree-node-title-row">
|
|
1048
|
+
<span class="property-name">${g(t.name)}</span>
|
|
1049
|
+
${t.isRequired ? '<span class="required-badge">required</span>' : ""}
|
|
1050
|
+
</div>
|
|
1051
|
+
<span class="property-type type-${g(y)}">${g(y)}</span>
|
|
1052
|
+
</div>
|
|
1053
|
+
${b ? `<div class="tree-node-meta">${b}</div>` : ""}
|
|
1054
|
+
${x && m.description ? `<div class="tree-node-description">${g(m.description)}</div>` : ""}
|
|
1055
|
+
${w ? `
|
|
1056
|
+
<div class="tree-node-toggle">
|
|
1057
|
+
${x ? "−" : "+"}
|
|
1058
|
+
</div>
|
|
1059
|
+
` : ""}
|
|
1060
|
+
`, w && o.querySelector(".tree-node-toggle")?.addEventListener("click", (u) => {
|
|
1061
|
+
u.stopPropagation(), x ? r.expandedNodes.delete(t.id) : r.expandedNodes.add(t.id), d();
|
|
1062
|
+
}), o.addEventListener("click", (u) => {
|
|
1063
|
+
p && v !== void 0 && i && i(v);
|
|
1064
|
+
}), a.appendChild(o), r.nodeElements.set(t.id, o), x && U(m, c, l, t.id, f).forEach((k) => {
|
|
1065
|
+
_(e, k, n + 1, r, c, l, d, s, p, i);
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
1068
|
+
function Q(e, t) {
|
|
1069
|
+
let n = e.querySelector(`.tree-column[data-depth="${t}"]`);
|
|
1070
|
+
return n || (n = document.createElement("div"), n.className = "tree-column", n.setAttribute("data-depth", t.toString()), e.appendChild(n)), n;
|
|
1071
|
+
}
|
|
1072
|
+
function U(e, t, n, r, c) {
|
|
1073
|
+
const l = [], d = Array.isArray(e.required) ? e.required : [];
|
|
1074
|
+
if (e.properties) {
|
|
1075
|
+
const s = c ? `${c}.properties` : "properties";
|
|
1076
|
+
for (const [p, i] of Object.entries(e.properties))
|
|
1077
|
+
l.push({
|
|
1078
|
+
name: p,
|
|
1079
|
+
prop: i,
|
|
1080
|
+
level: 0,
|
|
1081
|
+
children: [],
|
|
1082
|
+
isExpanded: !1,
|
|
1083
|
+
parentId: r,
|
|
1084
|
+
id: `${r}.${p}`,
|
|
1085
|
+
isRequired: d.includes(p),
|
|
1086
|
+
jsonPath: `${s}.${p}`
|
|
1087
|
+
});
|
|
1088
|
+
}
|
|
1089
|
+
if (e.items) {
|
|
1090
|
+
const s = c ? `${c}.items` : "items";
|
|
1091
|
+
l.push({
|
|
1092
|
+
name: "items",
|
|
1093
|
+
prop: e.items,
|
|
1094
|
+
// Keep the original to preserve $ref
|
|
1095
|
+
level: 0,
|
|
1096
|
+
children: [],
|
|
1097
|
+
isExpanded: !1,
|
|
1098
|
+
parentId: r,
|
|
1099
|
+
id: `${r}.items`,
|
|
1100
|
+
jsonPath: s
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1103
|
+
return ["oneOf", "anyOf", "allOf"].forEach((s) => {
|
|
1104
|
+
e[s] && Array.isArray(e[s]) && e[s].forEach((p, i) => {
|
|
1105
|
+
const a = c ? `${c}.${s}.${i}` : `${s}.${i}`;
|
|
1106
|
+
l.push({
|
|
1107
|
+
name: `${s}[${i}]`,
|
|
1108
|
+
prop: p,
|
|
1109
|
+
level: 0,
|
|
1110
|
+
children: [],
|
|
1111
|
+
isExpanded: !1,
|
|
1112
|
+
parentId: r,
|
|
1113
|
+
id: `${r}.${s}[${i}]`,
|
|
1114
|
+
jsonPath: a
|
|
1115
|
+
});
|
|
1116
|
+
});
|
|
1117
|
+
}), l;
|
|
1118
|
+
}
|
|
1119
|
+
function I(e, t) {
|
|
1120
|
+
e.innerHTML = "";
|
|
1121
|
+
const n = e.parentElement.getBoundingClientRect();
|
|
1122
|
+
e.setAttribute("width", n.width.toString()), e.setAttribute("height", n.height.toString()), t.nodeElements.forEach((r, c) => {
|
|
1123
|
+
const l = c.substring(0, c.lastIndexOf("."));
|
|
1124
|
+
if (l && t.nodeElements.has(l)) {
|
|
1125
|
+
const d = t.nodeElements.get(l);
|
|
1126
|
+
ee(e, d, r, n);
|
|
1127
|
+
} else c !== "root" && c.includes(".");
|
|
1128
|
+
});
|
|
1129
|
+
}
|
|
1130
|
+
function ee(e, t, n, r) {
|
|
1131
|
+
const c = t.getBoundingClientRect(), l = n.getBoundingClientRect(), d = c.right - r.left, s = c.top + c.height / 2 - r.top, p = l.left - r.left, i = l.top + l.height / 2 - r.top, a = document.createElementNS("http://www.w3.org/2000/svg", "path"), o = (d + p) / 2, m = `M ${d} ${s} C ${o} ${s}, ${o} ${i}, ${p} ${i}`;
|
|
1132
|
+
a.setAttribute("d", m), a.setAttribute("class", "tree-connector-line"), e.appendChild(a);
|
|
1133
|
+
}
|
|
1134
|
+
let j = "normal";
|
|
1135
|
+
function V(e, t) {
|
|
1136
|
+
const n = t.schema;
|
|
1137
|
+
if (t.initialView && (j = t.initialView), e.innerHTML = "", e.classList.add("schema-container"), e.classList.toggle("normal-view", j === "normal"), !n) {
|
|
1138
|
+
const o = document.createElement("div");
|
|
1139
|
+
o.className = "loading", o.textContent = "Loading schema...", e.appendChild(o);
|
|
1140
|
+
return;
|
|
1141
|
+
}
|
|
1142
|
+
const r = document.createElement("div");
|
|
1143
|
+
r.className = "schema-header";
|
|
1144
|
+
const c = n.title || "JSON Schema", l = n.description || "", d = n.$schema || "", s = n.$id || "";
|
|
1145
|
+
r.innerHTML = `
|
|
1146
|
+
<div class="schema-header-top">
|
|
1147
|
+
<div class="schema-title">${g(c)}</div>
|
|
1148
|
+
<div class="view-selector">
|
|
1149
|
+
<div class="view-switch" title="Toggle between normal and tree view modes">
|
|
1150
|
+
<span class="view-switch-label view-switch-left">Normal</span>
|
|
1151
|
+
<input type="checkbox" id="view-toggle" class="view-switch-checkbox" aria-label="Toggle Tree View" ${j === "tree" ? "checked" : ""} />
|
|
1152
|
+
<span class="view-switch-label view-switch-right">Tree view</span>
|
|
1153
|
+
</div>
|
|
1154
|
+
</div>
|
|
1155
|
+
</div>
|
|
1156
|
+
${l ? `<div class="schema-description">${g(l)}</div>` : ""}
|
|
1157
|
+
<div class="schema-meta">
|
|
1158
|
+
${d ? `<div class="schema-meta-item"><span class="schema-meta-label">Schema:</span><span class="schema-meta-value">${g(d)}</span></div>` : ""}
|
|
1159
|
+
${s ? `<div class="schema-meta-item"><span class="schema-meta-label">ID:</span><span class="schema-meta-value">${g(s)}</span></div>` : ""}
|
|
1160
|
+
</div>
|
|
1161
|
+
${t.onActiveLinkChange ? `<div class="active-link-bottom-row">
|
|
1162
|
+
<label class="active-link-label" title="Enable clicking on properties to navigate to their source location">
|
|
1163
|
+
<input type="checkbox" id="active-link-toggle" class="active-link-checkbox" ${t.activeLinkEnabled ? "checked" : ""} />
|
|
1164
|
+
<span>Active link</span>
|
|
1165
|
+
</label>
|
|
1166
|
+
</div>` : ""}
|
|
1167
|
+
`, e.appendChild(r);
|
|
1168
|
+
const p = r.querySelector("#view-toggle");
|
|
1169
|
+
p && p.addEventListener("change", () => {
|
|
1170
|
+
j = p.checked ? "tree" : "normal", V(e, { ...t, initialView: j });
|
|
1171
|
+
});
|
|
1172
|
+
const i = r.querySelector("#active-link-toggle");
|
|
1173
|
+
i && t.onActiveLinkChange && i.addEventListener("change", () => {
|
|
1174
|
+
t.onActiveLinkChange && t.onActiveLinkChange(i.checked);
|
|
1175
|
+
});
|
|
1176
|
+
const a = document.createElement("div");
|
|
1177
|
+
a.className = "schema-content-root", e.appendChild(a), j === "tree" ? Y(a, t) : W(a, t);
|
|
1178
|
+
}
|
|
1179
|
+
function re(e) {
|
|
1180
|
+
const t = D(null), n = P(
|
|
1181
|
+
() => ({
|
|
1182
|
+
schema: e.schema,
|
|
1183
|
+
bundle: e.bundle ?? {},
|
|
1184
|
+
importedFileNames: e.importedFileNames ?? [],
|
|
1185
|
+
missingFileNames: e.missingFileNames ?? []
|
|
1186
|
+
}),
|
|
1187
|
+
[e.schema, e.bundle, e.importedFileNames, e.missingFileNames]
|
|
1188
|
+
);
|
|
1189
|
+
return R(() => {
|
|
1190
|
+
B(), t.current && V(t.current, n);
|
|
1191
|
+
}, [n]), /* @__PURE__ */ F("div", { ref: t, className: e.className });
|
|
1192
|
+
}
|
|
1193
|
+
export {
|
|
1194
|
+
re as SchemaViewer,
|
|
1195
|
+
B as ensureSchemaViewerStyles,
|
|
1196
|
+
g as escapeHtml,
|
|
1197
|
+
E as generateExampleValue,
|
|
1198
|
+
L as getType,
|
|
1199
|
+
M as hasNestedContent,
|
|
1200
|
+
O as hasRemoteRef,
|
|
1201
|
+
V as renderSchemaInto,
|
|
1202
|
+
C as resolveRef,
|
|
1203
|
+
K as syntaxHighlightJson
|
|
1204
|
+
};
|