json-schema-builder-react 0.0.6 → 0.0.7
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/README.md +62 -2
- package/dist-lib/components/PropertyEditDialog.d.ts +35 -2
- package/dist-lib/hooks/useDialogManager.d.ts +1 -1
- package/dist-lib/index.cjs +1 -1
- package/dist-lib/index.cjs.map +1 -1
- package/dist-lib/index.d.ts +3 -0
- package/dist-lib/index.js +45 -43
- package/dist-lib/index.js.map +1 -1
- package/package.json +1 -1
package/dist-lib/index.d.ts
CHANGED
|
@@ -4,4 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export { JsonSchemaBuilder } from "./components/JsonSchemaBuilder";
|
|
6
6
|
export type { JsonSchemaBuilderProps } from "./components/JsonSchemaBuilder";
|
|
7
|
+
export { default as PropertyEditDialog } from "./components/PropertyEditDialog";
|
|
8
|
+
export { TypeLabelsProvider } from "./contexts/TypeLabelsContext";
|
|
7
9
|
export type { TypeLabels } from "./contexts/TypeLabelsContext";
|
|
10
|
+
export type { PropertyData, PropertyType } from "./types/schema";
|
package/dist-lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as e, jsxs as s, Fragment as le } from "react/jsx-runtime";
|
|
2
2
|
import * as y from "react";
|
|
3
|
-
import {
|
|
4
|
-
import { Slot as
|
|
3
|
+
import { useContext as ke, createContext as Ie, useState as O, useEffect as Z, useMemo as Se, useCallback as E } from "react";
|
|
4
|
+
import { Slot as Te } from "@radix-ui/react-slot";
|
|
5
5
|
import { cva as de } from "class-variance-authority";
|
|
6
6
|
import { clsx as De } from "clsx";
|
|
7
7
|
import { twMerge as je } from "tailwind-merge";
|
|
@@ -38,9 +38,9 @@ const He = de(
|
|
|
38
38
|
size: "default"
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
),
|
|
41
|
+
), S = y.forwardRef(
|
|
42
42
|
({ className: t, variant: i, size: a, asChild: d = !1, ...n }, l) => /* @__PURE__ */ e(
|
|
43
|
-
d ?
|
|
43
|
+
d ? Te : "button",
|
|
44
44
|
{
|
|
45
45
|
className: p(He({ variant: i, size: a, className: t })),
|
|
46
46
|
ref: l,
|
|
@@ -48,7 +48,7 @@ const He = de(
|
|
|
48
48
|
}
|
|
49
49
|
)
|
|
50
50
|
);
|
|
51
|
-
|
|
51
|
+
S.displayName = "Button";
|
|
52
52
|
const D = y.forwardRef(
|
|
53
53
|
({ className: t, type: i, ...a }, d) => /* @__PURE__ */ e(
|
|
54
54
|
"input",
|
|
@@ -340,7 +340,7 @@ const tt = (t) => t.trim().toLowerCase().replace(/[^\w\s]/g, "").replace(/\s+/g,
|
|
|
340
340
|
array: "Array",
|
|
341
341
|
null: "Null",
|
|
342
342
|
file: "File"
|
|
343
|
-
}, be =
|
|
343
|
+
}, be = Ie({
|
|
344
344
|
getTypeLabel: (t) => X[t],
|
|
345
345
|
typeLabels: X
|
|
346
346
|
});
|
|
@@ -352,13 +352,13 @@ function it({
|
|
|
352
352
|
return /* @__PURE__ */ e(be.Provider, { value: { getTypeLabel: d, typeLabels: a }, children: t });
|
|
353
353
|
}
|
|
354
354
|
function Ne() {
|
|
355
|
-
return
|
|
355
|
+
return ke(be);
|
|
356
356
|
}
|
|
357
357
|
function G({
|
|
358
358
|
property: t,
|
|
359
359
|
open: i,
|
|
360
360
|
onOpenChange: a,
|
|
361
|
-
|
|
361
|
+
onSave: d,
|
|
362
362
|
isArrayItem: n = !1,
|
|
363
363
|
isNewProperty: l = !1,
|
|
364
364
|
propertyLabel: r = { singular: "Property", plural: "Properties" },
|
|
@@ -522,7 +522,7 @@ function G({
|
|
|
522
522
|
)
|
|
523
523
|
] }),
|
|
524
524
|
/* @__PURE__ */ s(
|
|
525
|
-
|
|
525
|
+
S,
|
|
526
526
|
{
|
|
527
527
|
variant: "ghost",
|
|
528
528
|
size: "sm",
|
|
@@ -536,7 +536,7 @@ function G({
|
|
|
536
536
|
}
|
|
537
537
|
)
|
|
538
538
|
] }) : /* @__PURE__ */ s(
|
|
539
|
-
|
|
539
|
+
S,
|
|
540
540
|
{
|
|
541
541
|
variant: "outline",
|
|
542
542
|
size: "sm",
|
|
@@ -637,15 +637,15 @@ function G({
|
|
|
637
637
|
placeholder: j === (((A = o.enum) == null ? void 0 : A.length) || 0) ? "Add new value..." : "Enum value",
|
|
638
638
|
value: m,
|
|
639
639
|
onChange: (J) => {
|
|
640
|
-
const
|
|
640
|
+
const T = J.target.value, R = o.enum || [];
|
|
641
641
|
if (j === R.length)
|
|
642
|
-
|
|
642
|
+
T.trim() && b("enum", [
|
|
643
643
|
...R,
|
|
644
|
-
|
|
644
|
+
T.trim()
|
|
645
645
|
]);
|
|
646
|
-
else if (
|
|
646
|
+
else if (T.trim()) {
|
|
647
647
|
const z = [...R];
|
|
648
|
-
z[j] =
|
|
648
|
+
z[j] = T.trim(), b("enum", z);
|
|
649
649
|
} else {
|
|
650
650
|
const z = R.filter(
|
|
651
651
|
(vt, Ce) => Ce !== j
|
|
@@ -763,7 +763,7 @@ function G({
|
|
|
763
763
|
] }),
|
|
764
764
|
/* @__PURE__ */ s(ye, { className: "px-6 py-4 border-t bg-background shrink-0", children: [
|
|
765
765
|
/* @__PURE__ */ e(
|
|
766
|
-
|
|
766
|
+
S,
|
|
767
767
|
{
|
|
768
768
|
variant: "outline",
|
|
769
769
|
onClick: h,
|
|
@@ -772,7 +772,7 @@ function G({
|
|
|
772
772
|
}
|
|
773
773
|
),
|
|
774
774
|
/* @__PURE__ */ e(
|
|
775
|
-
|
|
775
|
+
S,
|
|
776
776
|
{
|
|
777
777
|
onClick: q,
|
|
778
778
|
"data-testid": "button-save",
|
|
@@ -983,7 +983,7 @@ function Q({
|
|
|
983
983
|
] })
|
|
984
984
|
] }) }),
|
|
985
985
|
t.type === "object" && /* @__PURE__ */ e(
|
|
986
|
-
|
|
986
|
+
S,
|
|
987
987
|
{
|
|
988
988
|
variant: "ghost",
|
|
989
989
|
size: "icon",
|
|
@@ -1025,7 +1025,7 @@ function Q({
|
|
|
1025
1025
|
] }) }),
|
|
1026
1026
|
/* @__PURE__ */ s("div", { className: "flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity shrink-0", children: [
|
|
1027
1027
|
/* @__PURE__ */ e(
|
|
1028
|
-
|
|
1028
|
+
S,
|
|
1029
1029
|
{
|
|
1030
1030
|
variant: "ghost",
|
|
1031
1031
|
size: "icon",
|
|
@@ -1036,7 +1036,7 @@ function Q({
|
|
|
1036
1036
|
}
|
|
1037
1037
|
),
|
|
1038
1038
|
I && t.type !== "object" && /* @__PURE__ */ e(
|
|
1039
|
-
|
|
1039
|
+
S,
|
|
1040
1040
|
{
|
|
1041
1041
|
variant: "ghost",
|
|
1042
1042
|
size: "icon",
|
|
@@ -1047,7 +1047,7 @@ function Q({
|
|
|
1047
1047
|
}
|
|
1048
1048
|
),
|
|
1049
1049
|
/* @__PURE__ */ e(
|
|
1050
|
-
|
|
1050
|
+
S,
|
|
1051
1051
|
{
|
|
1052
1052
|
variant: "ghost",
|
|
1053
1053
|
size: "icon",
|
|
@@ -1107,7 +1107,7 @@ function Q({
|
|
|
1107
1107
|
property: c.data || t,
|
|
1108
1108
|
open: c.isOpen,
|
|
1109
1109
|
onOpenChange: c.setIsOpen,
|
|
1110
|
-
|
|
1110
|
+
onSave: (h) => {
|
|
1111
1111
|
i(h), c.close();
|
|
1112
1112
|
},
|
|
1113
1113
|
isArrayItem: n,
|
|
@@ -1123,7 +1123,7 @@ function Q({
|
|
|
1123
1123
|
open: g.addChildDialog.isOpen,
|
|
1124
1124
|
isNewProperty: !0,
|
|
1125
1125
|
onOpenChange: g.addChildDialog.setIsOpen,
|
|
1126
|
-
|
|
1126
|
+
onSave: g.addChildDialog.confirm,
|
|
1127
1127
|
showRegex: l,
|
|
1128
1128
|
keyEditable: r
|
|
1129
1129
|
}
|
|
@@ -1211,7 +1211,7 @@ function ut({ schema: t }) {
|
|
|
1211
1211
|
/* @__PURE__ */ e("h2", { className: "text-sm font-medium", children: "JSON Schema Output" }),
|
|
1212
1212
|
/* @__PURE__ */ s("div", { className: "flex gap-2", children: [
|
|
1213
1213
|
/* @__PURE__ */ e(
|
|
1214
|
-
|
|
1214
|
+
S,
|
|
1215
1215
|
{
|
|
1216
1216
|
variant: "outline",
|
|
1217
1217
|
size: "sm",
|
|
@@ -1223,7 +1223,7 @@ function ut({ schema: t }) {
|
|
|
1223
1223
|
}
|
|
1224
1224
|
),
|
|
1225
1225
|
/* @__PURE__ */ e(
|
|
1226
|
-
|
|
1226
|
+
S,
|
|
1227
1227
|
{
|
|
1228
1228
|
variant: "outline",
|
|
1229
1229
|
size: "sm",
|
|
@@ -1255,7 +1255,7 @@ function ht({
|
|
|
1255
1255
|
const [n, l] = O(!1);
|
|
1256
1256
|
return /* @__PURE__ */ s(ne, { className: "p-4", children: [
|
|
1257
1257
|
/* @__PURE__ */ s(
|
|
1258
|
-
|
|
1258
|
+
S,
|
|
1259
1259
|
{
|
|
1260
1260
|
variant: "ghost",
|
|
1261
1261
|
onClick: () => l(!n),
|
|
@@ -1393,7 +1393,7 @@ const M = (t, i, a = !0) => {
|
|
|
1393
1393
|
onChange: i,
|
|
1394
1394
|
includeMetadata: a = !0
|
|
1395
1395
|
}) => {
|
|
1396
|
-
const { properties: d, metadata: n } =
|
|
1396
|
+
const { properties: d, metadata: n } = Se(
|
|
1397
1397
|
() => ft(t),
|
|
1398
1398
|
[t]
|
|
1399
1399
|
), l = d, r = n || {
|
|
@@ -1465,7 +1465,7 @@ function gt() {
|
|
|
1465
1465
|
const n = localStorage.getItem("theme") || (window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light");
|
|
1466
1466
|
i(n), document.documentElement.classList.toggle("dark", n === "dark");
|
|
1467
1467
|
}, []), /* @__PURE__ */ e(
|
|
1468
|
-
|
|
1468
|
+
S,
|
|
1469
1469
|
{
|
|
1470
1470
|
variant: "ghost",
|
|
1471
1471
|
size: "icon",
|
|
@@ -1508,8 +1508,8 @@ function It({
|
|
|
1508
1508
|
includeMetadata: a
|
|
1509
1509
|
}), j = ie({
|
|
1510
1510
|
createInitialData: () => I(),
|
|
1511
|
-
onConfirm: (
|
|
1512
|
-
b(
|
|
1511
|
+
onConfirm: (T) => {
|
|
1512
|
+
b(T.id, T);
|
|
1513
1513
|
}
|
|
1514
1514
|
}), A = () => {
|
|
1515
1515
|
h();
|
|
@@ -1519,7 +1519,7 @@ function It({
|
|
|
1519
1519
|
return /* @__PURE__ */ e(it, { customLabels: c, children: /* @__PURE__ */ s("div", { className: `${u} flex flex-col json-schema-builder-react`, children: [
|
|
1520
1520
|
r && /* @__PURE__ */ e("header", { className: "h-16 border-b flex items-center justify-between px-6", children: /* @__PURE__ */ s("div", { className: "flex items-center gap-3", children: [
|
|
1521
1521
|
d && /* @__PURE__ */ e(
|
|
1522
|
-
|
|
1522
|
+
S,
|
|
1523
1523
|
{
|
|
1524
1524
|
variant: "outline",
|
|
1525
1525
|
size: "sm",
|
|
@@ -1529,7 +1529,7 @@ function It({
|
|
|
1529
1529
|
}
|
|
1530
1530
|
),
|
|
1531
1531
|
n && /* @__PURE__ */ e(
|
|
1532
|
-
|
|
1532
|
+
S,
|
|
1533
1533
|
{
|
|
1534
1534
|
variant: "outline",
|
|
1535
1535
|
size: "sm",
|
|
@@ -1550,7 +1550,7 @@ function It({
|
|
|
1550
1550
|
title: f.title,
|
|
1551
1551
|
description: f.description,
|
|
1552
1552
|
version: f.version,
|
|
1553
|
-
onUpdate: (
|
|
1553
|
+
onUpdate: (T, R) => L(T, R)
|
|
1554
1554
|
}
|
|
1555
1555
|
),
|
|
1556
1556
|
g.length === 0 ? /* @__PURE__ */ s("div", { className: "flex flex-col items-center justify-center py-16 text-center", children: [
|
|
@@ -1566,7 +1566,7 @@ function It({
|
|
|
1566
1566
|
o.singular
|
|
1567
1567
|
] }),
|
|
1568
1568
|
/* @__PURE__ */ s(
|
|
1569
|
-
|
|
1569
|
+
S,
|
|
1570
1570
|
{
|
|
1571
1571
|
onClick: () => j.open(),
|
|
1572
1572
|
"data-testid": "button-add-first",
|
|
@@ -1578,16 +1578,16 @@ function It({
|
|
|
1578
1578
|
}
|
|
1579
1579
|
)
|
|
1580
1580
|
] }) : /* @__PURE__ */ s(le, { children: [
|
|
1581
|
-
/* @__PURE__ */ e("div", { className: "space-y-1", children: g.map((
|
|
1581
|
+
/* @__PURE__ */ e("div", { className: "space-y-1", children: g.map((T) => /* @__PURE__ */ e(
|
|
1582
1582
|
Q,
|
|
1583
1583
|
{
|
|
1584
|
-
property:
|
|
1585
|
-
onUpdate: (R) => b(
|
|
1586
|
-
onDelete: () => q(
|
|
1584
|
+
property: T,
|
|
1585
|
+
onUpdate: (R) => b(T.id, R),
|
|
1586
|
+
onDelete: () => q(T.id),
|
|
1587
1587
|
showRegex: v,
|
|
1588
1588
|
keyEditable: x
|
|
1589
1589
|
},
|
|
1590
|
-
|
|
1590
|
+
T.id
|
|
1591
1591
|
)) }),
|
|
1592
1592
|
C && /* @__PURE__ */ s("div", { className: "pt-4 border-t flex items-center justify-between text-sm text-muted-foreground", children: [
|
|
1593
1593
|
/* @__PURE__ */ s("span", { children: [
|
|
@@ -1596,14 +1596,14 @@ function It({
|
|
|
1596
1596
|
g.length === 1 ? o.singular : o.plural
|
|
1597
1597
|
] }),
|
|
1598
1598
|
/* @__PURE__ */ s("span", { children: [
|
|
1599
|
-
g.filter((
|
|
1599
|
+
g.filter((T) => T.required).length,
|
|
1600
1600
|
" required"
|
|
1601
1601
|
] })
|
|
1602
1602
|
] })
|
|
1603
1603
|
] })
|
|
1604
1604
|
] }),
|
|
1605
1605
|
g.length > 0 && /* @__PURE__ */ e("div", { className: "border-t p-2 pt-4 bg-background", children: /* @__PURE__ */ s(
|
|
1606
|
-
|
|
1606
|
+
S,
|
|
1607
1607
|
{
|
|
1608
1608
|
onClick: () => j.open(),
|
|
1609
1609
|
className: "w-full",
|
|
@@ -1627,7 +1627,7 @@ function It({
|
|
|
1627
1627
|
isNewProperty: !0,
|
|
1628
1628
|
onOpenChange: j.setIsOpen,
|
|
1629
1629
|
propertyLabel: o,
|
|
1630
|
-
|
|
1630
|
+
onSave: j.confirm,
|
|
1631
1631
|
showRegex: v,
|
|
1632
1632
|
keyEditable: x
|
|
1633
1633
|
}
|
|
@@ -1635,6 +1635,8 @@ function It({
|
|
|
1635
1635
|
] }) });
|
|
1636
1636
|
}
|
|
1637
1637
|
export {
|
|
1638
|
-
It as JsonSchemaBuilder
|
|
1638
|
+
It as JsonSchemaBuilder,
|
|
1639
|
+
G as PropertyEditDialog,
|
|
1640
|
+
it as TypeLabelsProvider
|
|
1639
1641
|
};
|
|
1640
1642
|
//# sourceMappingURL=index.js.map
|