@satoshibits/react-json-schema-builder 1.1.3 → 1.1.5
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.js +1 -1
- package/dist/index.cjs10.js +1 -1
- package/dist/index.cjs10.js.map +1 -1
- package/dist/index.cjs11.js +1 -1
- package/dist/index.cjs11.js.map +1 -1
- package/dist/index.cjs12.js +1 -1
- package/dist/index.cjs12.js.map +1 -1
- package/dist/index.cjs13.js +1 -1
- package/dist/index.cjs13.js.map +1 -1
- package/dist/index.cjs14.js +1 -1
- package/dist/index.cjs14.js.map +1 -1
- package/dist/index.cjs15.js +6 -1
- package/dist/index.cjs15.js.map +1 -1
- package/dist/index.cjs16.js +1 -1
- package/dist/index.cjs16.js.map +1 -1
- package/dist/index.cjs17.js +1 -1
- package/dist/index.cjs17.js.map +1 -1
- package/dist/index.cjs18.js +1 -1
- package/dist/index.cjs18.js.map +1 -1
- package/dist/index.cjs19.js +1 -1
- package/dist/index.cjs19.js.map +1 -1
- package/dist/index.cjs2.js +1 -1
- package/dist/index.cjs2.js.map +1 -1
- package/dist/index.cjs20.js +1 -1
- package/dist/index.cjs20.js.map +1 -1
- package/dist/index.cjs21.js +1 -1
- package/dist/index.cjs21.js.map +1 -1
- package/dist/index.cjs22.js +1 -1
- package/dist/index.cjs22.js.map +1 -1
- package/dist/index.cjs23.js +1 -6
- package/dist/index.cjs23.js.map +1 -1
- package/dist/index.cjs24.js +1 -6
- package/dist/index.cjs24.js.map +1 -1
- package/dist/index.cjs25.js +1 -6
- package/dist/index.cjs25.js.map +1 -1
- package/dist/index.cjs26.js +1 -1
- package/dist/index.cjs26.js.map +1 -1
- package/dist/index.cjs27.js +1 -1
- package/dist/index.cjs27.js.map +1 -1
- package/dist/index.cjs28.js +6 -1
- package/dist/index.cjs28.js.map +1 -1
- package/dist/index.cjs29.js +6 -1
- package/dist/index.cjs29.js.map +1 -1
- package/dist/index.cjs3.js +1 -1
- package/dist/index.cjs3.js.map +1 -1
- package/dist/index.cjs30.js +1 -1
- package/dist/index.cjs30.js.map +1 -1
- package/dist/index.cjs31.js +1 -1
- package/dist/index.cjs34.js +1 -1
- package/dist/index.cjs36.js +1 -1
- package/dist/index.cjs37.js +1 -1
- package/dist/index.cjs38.js +1 -1
- package/dist/index.cjs39.js +1 -1
- package/dist/index.cjs4.js +1 -1
- package/dist/index.cjs4.js.map +1 -1
- package/dist/index.cjs41.js +1 -1
- package/dist/index.cjs42.js +1 -1
- package/dist/index.cjs42.js.map +1 -1
- package/dist/index.cjs43.js +1 -1
- package/dist/index.cjs47.js +1 -1
- package/dist/index.cjs5.js +1 -1
- package/dist/index.cjs5.js.map +1 -1
- package/dist/index.cjs55.js +1 -5
- package/dist/index.cjs55.js.map +1 -1
- package/dist/index.cjs56.js +1 -1
- package/dist/index.cjs56.js.map +1 -1
- package/dist/index.cjs57.js +1 -1
- package/dist/index.cjs57.js.map +1 -1
- package/dist/index.cjs58.js +1 -1
- package/dist/index.cjs58.js.map +1 -1
- package/dist/index.cjs59.js +1 -1
- package/dist/index.cjs59.js.map +1 -1
- package/dist/index.cjs6.js +1 -1
- package/dist/index.cjs6.js.map +1 -1
- package/dist/index.cjs60.js +1 -1
- package/dist/index.cjs60.js.map +1 -1
- package/dist/index.cjs61.js +1 -1
- package/dist/index.cjs61.js.map +1 -1
- package/dist/index.cjs62.js +5 -1
- package/dist/index.cjs62.js.map +1 -1
- package/dist/index.cjs63.js +1 -1
- package/dist/index.cjs63.js.map +1 -1
- package/dist/index.cjs65.js +1 -1
- package/dist/index.cjs67.js +1 -1
- package/dist/index.cjs69.js +1 -1
- package/dist/index.cjs7.js +1 -1
- package/dist/index.cjs7.js.map +1 -1
- package/dist/index.cjs71.js +1 -1
- package/dist/index.cjs72.js +1 -1
- package/dist/index.cjs75.js +1 -1
- package/dist/index.cjs78.js +1 -1
- package/dist/index.cjs8.js +1 -1
- package/dist/index.cjs8.js.map +1 -1
- package/dist/index.cjs81.js +1 -1
- package/dist/index.cjs9.js +1 -1
- package/dist/index.cjs9.js.map +1 -1
- package/dist/index.d.mts +5 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.es.js +18 -28
- package/dist/index.es10.js +22 -22
- package/dist/index.es10.js.map +1 -1
- package/dist/index.es11.js +14 -42
- package/dist/index.es11.js.map +1 -1
- package/dist/index.es12.js +5 -65
- package/dist/index.es12.js.map +1 -1
- package/dist/index.es13.js +43 -24
- package/dist/index.es13.js.map +1 -1
- package/dist/index.es14.js +21 -126
- package/dist/index.es14.js.map +1 -1
- package/dist/index.es15.js +13 -20
- package/dist/index.es15.js.map +1 -1
- package/dist/index.es16.js +129 -130
- package/dist/index.es16.js.map +1 -1
- package/dist/index.es17.js +3 -137
- package/dist/index.es17.js.map +1 -1
- package/dist/index.es18.js +20 -61
- package/dist/index.es18.js.map +1 -1
- package/dist/index.es19.js +65 -10
- package/dist/index.es19.js.map +1 -1
- package/dist/index.es2.js +156 -113
- package/dist/index.es2.js.map +1 -1
- package/dist/index.es20.js +134 -22
- package/dist/index.es20.js.map +1 -1
- package/dist/index.es21.js +131 -421
- package/dist/index.es21.js.map +1 -1
- package/dist/index.es22.js +63 -5
- package/dist/index.es22.js.map +1 -1
- package/dist/index.es23.js +11 -13
- package/dist/index.es23.js.map +1 -1
- package/dist/index.es24.js +23 -16
- package/dist/index.es24.js.map +1 -1
- package/dist/index.es25.js +428 -13
- package/dist/index.es25.js.map +1 -1
- package/dist/index.es26.js +7 -13
- package/dist/index.es26.js.map +1 -1
- package/dist/index.es27.js +9 -3
- package/dist/index.es27.js.map +1 -1
- package/dist/index.es28.js +13 -19
- package/dist/index.es28.js.map +1 -1
- package/dist/index.es29.js +19 -23
- package/dist/index.es29.js.map +1 -1
- package/dist/index.es3.js +129 -340
- package/dist/index.es3.js.map +1 -1
- package/dist/index.es30.js +4 -7
- package/dist/index.es30.js.map +1 -1
- package/dist/index.es31.js +1 -1
- package/dist/index.es34.js +1 -1
- package/dist/index.es36.js +7 -7
- package/dist/index.es37.js +3 -3
- package/dist/index.es38.js +3 -3
- package/dist/index.es39.js +2 -2
- package/dist/index.es4.js +92 -70
- package/dist/index.es4.js.map +1 -1
- package/dist/index.es41.js +2 -2
- package/dist/index.es42.js +4 -4
- package/dist/index.es43.js +6 -6
- package/dist/index.es47.js +4 -4
- package/dist/index.es5.js +225 -79
- package/dist/index.es5.js.map +1 -1
- package/dist/index.es55.js +30 -252
- package/dist/index.es55.js.map +1 -1
- package/dist/index.es56.js +26 -21
- package/dist/index.es56.js.map +1 -1
- package/dist/index.es57.js +6 -32
- package/dist/index.es57.js.map +1 -1
- package/dist/index.es58.js +62 -23
- package/dist/index.es58.js.map +1 -1
- package/dist/index.es59.js +29 -6
- package/dist/index.es59.js.map +1 -1
- package/dist/index.es6.js +117 -57
- package/dist/index.es6.js.map +1 -1
- package/dist/index.es60.js +4 -64
- package/dist/index.es60.js.map +1 -1
- package/dist/index.es61.js +24 -29
- package/dist/index.es61.js.map +1 -1
- package/dist/index.es62.js +254 -5
- package/dist/index.es62.js.map +1 -1
- package/dist/index.es63.js +21 -24
- package/dist/index.es63.js.map +1 -1
- package/dist/index.es65.js +2 -2
- package/dist/index.es67.js +3 -3
- package/dist/index.es69.js +2 -2
- package/dist/index.es7.js +345 -48
- package/dist/index.es7.js.map +1 -1
- package/dist/index.es71.js +4 -4
- package/dist/index.es72.js +1 -1
- package/dist/index.es75.js +1 -1
- package/dist/index.es78.js +1 -1
- package/dist/index.es8.js +73 -163
- package/dist/index.es8.js.map +1 -1
- package/dist/index.es81.js +1 -1
- package/dist/index.es9.js +18 -3
- package/dist/index.es9.js.map +1 -1
- package/dist/packages/builder/add-dialog.d.ts +5 -5
- package/dist/packages/builder/context.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.es19.js
CHANGED
|
@@ -1,14 +1,69 @@
|
|
|
1
|
-
import t from "
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { jsx as t } from "react/jsx-runtime";
|
|
2
|
+
import { Slot as n } from "./index.es34.js";
|
|
3
|
+
import { cn as a } from "./index.es12.js";
|
|
4
|
+
import m from "./index.es30.js";
|
|
5
|
+
function d({ ...r }) {
|
|
6
|
+
return /* @__PURE__ */ t("nav", { "aria-label": "breadcrumb", "data-slot": "breadcrumb", ...r });
|
|
7
|
+
}
|
|
8
|
+
function b({ className: r, ...e }) {
|
|
9
|
+
return /* @__PURE__ */ t(
|
|
10
|
+
"ol",
|
|
11
|
+
{
|
|
12
|
+
"data-slot": "breadcrumb-list",
|
|
13
|
+
className: a(
|
|
14
|
+
"text-muted-foreground flex flex-wrap items-center gap-1.5 text-sm break-words sm:gap-2.5",
|
|
15
|
+
r
|
|
16
|
+
),
|
|
17
|
+
...e
|
|
18
|
+
}
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
function f({ className: r, ...e }) {
|
|
22
|
+
return /* @__PURE__ */ t(
|
|
23
|
+
"li",
|
|
24
|
+
{
|
|
25
|
+
"data-slot": "breadcrumb-item",
|
|
26
|
+
className: a("inline-flex items-center gap-1.5", r),
|
|
27
|
+
...e
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
function p({
|
|
32
|
+
asChild: r,
|
|
33
|
+
className: e,
|
|
34
|
+
...o
|
|
35
|
+
}) {
|
|
36
|
+
return /* @__PURE__ */ t(
|
|
37
|
+
r ? n : "a",
|
|
38
|
+
{
|
|
39
|
+
"data-slot": "breadcrumb-link",
|
|
40
|
+
className: a("hover:text-foreground transition-colors", e),
|
|
41
|
+
...o
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
function x({
|
|
46
|
+
children: r,
|
|
47
|
+
className: e,
|
|
48
|
+
...o
|
|
49
|
+
}) {
|
|
50
|
+
return /* @__PURE__ */ t(
|
|
51
|
+
"li",
|
|
52
|
+
{
|
|
53
|
+
"data-slot": "breadcrumb-separator",
|
|
54
|
+
role: "presentation",
|
|
55
|
+
"aria-hidden": "true",
|
|
56
|
+
className: a("[&>svg]:size-3.5", e),
|
|
57
|
+
...o,
|
|
58
|
+
children: r ?? /* @__PURE__ */ t(m, {})
|
|
59
|
+
}
|
|
60
|
+
);
|
|
9
61
|
}
|
|
10
62
|
export {
|
|
11
|
-
|
|
12
|
-
|
|
63
|
+
d as Breadcrumb,
|
|
64
|
+
f as BreadcrumbItem,
|
|
65
|
+
p as BreadcrumbLink,
|
|
66
|
+
b as BreadcrumbList,
|
|
67
|
+
x as BreadcrumbSeparator
|
|
13
68
|
};
|
|
14
69
|
//# sourceMappingURL=index.es19.js.map
|
package/dist/index.es19.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es19.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"index.es19.js","sources":["../src/components/ui/breadcrumb.tsx"],"sourcesContent":["import * as React from \"react\"\nimport { Slot } from \"@radix-ui/react-slot\"\nimport { ChevronRight, MoreHorizontal } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\n\nfunction Breadcrumb({ ...props }: React.ComponentProps<\"nav\">) {\n return <nav aria-label=\"breadcrumb\" data-slot=\"breadcrumb\" {...props} />\n}\n\nfunction BreadcrumbList({ className, ...props }: React.ComponentProps<\"ol\">) {\n return (\n <ol\n data-slot=\"breadcrumb-list\"\n className={cn(\n \"text-muted-foreground flex flex-wrap items-center gap-1.5 text-sm break-words sm:gap-2.5\",\n className\n )}\n {...props}\n />\n )\n}\n\nfunction BreadcrumbItem({ className, ...props }: React.ComponentProps<\"li\">) {\n return (\n <li\n data-slot=\"breadcrumb-item\"\n className={cn(\"inline-flex items-center gap-1.5\", className)}\n {...props}\n />\n )\n}\n\nfunction BreadcrumbLink({\n asChild,\n className,\n ...props\n}: React.ComponentProps<\"a\"> & {\n asChild?: boolean\n}) {\n const Comp = asChild ? Slot : \"a\"\n\n return (\n <Comp\n data-slot=\"breadcrumb-link\"\n className={cn(\"hover:text-foreground transition-colors\", className)}\n {...props}\n />\n )\n}\n\nfunction BreadcrumbPage({ className, ...props }: React.ComponentProps<\"span\">) {\n return (\n <span\n data-slot=\"breadcrumb-page\"\n role=\"link\"\n aria-disabled=\"true\"\n aria-current=\"page\"\n className={cn(\"text-foreground font-normal\", className)}\n {...props}\n />\n )\n}\n\nfunction BreadcrumbSeparator({\n children,\n className,\n ...props\n}: React.ComponentProps<\"li\">) {\n return (\n <li\n data-slot=\"breadcrumb-separator\"\n role=\"presentation\"\n aria-hidden=\"true\"\n className={cn(\"[&>svg]:size-3.5\", className)}\n {...props}\n >\n {children ?? <ChevronRight />}\n </li>\n )\n}\n\nfunction BreadcrumbEllipsis({\n className,\n ...props\n}: React.ComponentProps<\"span\">) {\n return (\n <span\n data-slot=\"breadcrumb-ellipsis\"\n role=\"presentation\"\n aria-hidden=\"true\"\n className={cn(\"flex size-9 items-center justify-center\", className)}\n {...props}\n >\n <MoreHorizontal className=\"size-4\" />\n <span className=\"sr-only\">More</span>\n </span>\n )\n}\n\nexport {\n Breadcrumb,\n BreadcrumbList,\n BreadcrumbItem,\n BreadcrumbLink,\n BreadcrumbPage,\n BreadcrumbSeparator,\n BreadcrumbEllipsis,\n}\n"],"names":["Breadcrumb","props","BreadcrumbList","className","jsx","cn","BreadcrumbItem","BreadcrumbLink","asChild","Slot","BreadcrumbSeparator","children","ChevronRight"],"mappings":";;;;AAMA,SAASA,EAAW,EAAE,GAAGC,KAAsC;AAC7D,2BAAQ,OAAI,EAAA,cAAW,cAAa,aAAU,cAAc,GAAGA,GAAO;AACxE;AAEA,SAASC,EAAe,EAAE,WAAAC,GAAW,GAAGF,KAAqC;AAEzE,SAAA,gBAAAG;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,aAAU;AAAA,MACV,WAAWC;AAAA,QACT;AAAA,QACAF;AAAA,MACF;AAAA,MACC,GAAGF;AAAA,IAAA;AAAA,EACN;AAEJ;AAEA,SAASK,EAAe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
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
1
|
+
import { jsx as t, jsxs as i } from "react/jsx-runtime";
|
|
2
|
+
import { Input as x } from "./index.es9.js";
|
|
3
|
+
import { InputErrorWrapper as u } from "./index.es10.js";
|
|
4
|
+
import { Label as d } from "./index.es11.js";
|
|
5
|
+
import { cn as p } from "./index.es12.js";
|
|
6
|
+
import { useConstraints as h } from "./index.es8.js";
|
|
7
|
+
import { Button as f } from "./index.es13.js";
|
|
8
|
+
import { Switch as g } from "./index.es14.js";
|
|
9
|
+
import y from "./index.es15.js";
|
|
10
|
+
const b = ({
|
|
11
|
+
constraintName: n,
|
|
12
|
+
value: s,
|
|
13
|
+
onConstraintChange: a,
|
|
14
|
+
disabled: m,
|
|
15
|
+
error: r,
|
|
16
|
+
onRemoveConstraint: o
|
|
17
|
+
}) => {
|
|
18
|
+
const { getConstraintDefinition: c } = h(), e = c(n);
|
|
19
|
+
return e ? /* @__PURE__ */ t(
|
|
20
|
+
u,
|
|
21
|
+
{
|
|
22
|
+
errorCode: r?.code,
|
|
23
|
+
errorDescription: r?.message,
|
|
24
|
+
showError: !!r,
|
|
25
|
+
children: /* @__PURE__ */ i("div", { children: [
|
|
26
|
+
/* @__PURE__ */ t(d, { className: "mb-2", htmlFor: e.name, children: e.name }),
|
|
27
|
+
/* @__PURE__ */ i("div", { className: "flex items-center gap-2", children: [
|
|
28
|
+
/* @__PURE__ */ t(
|
|
29
|
+
x,
|
|
30
|
+
{
|
|
31
|
+
id: e.name,
|
|
32
|
+
type: "number",
|
|
33
|
+
value: s,
|
|
34
|
+
onChange: (l) => a(Number(l.target.value)),
|
|
35
|
+
disabled: m,
|
|
36
|
+
min: 0,
|
|
37
|
+
className: p({ "border-destructive": r })
|
|
38
|
+
}
|
|
39
|
+
),
|
|
40
|
+
/* @__PURE__ */ t(
|
|
41
|
+
f,
|
|
42
|
+
{
|
|
43
|
+
type: "button",
|
|
44
|
+
variant: "ghost",
|
|
45
|
+
size: "icon",
|
|
46
|
+
onClick: () => o(),
|
|
47
|
+
children: /* @__PURE__ */ t(y, { className: "size-4" })
|
|
48
|
+
}
|
|
49
|
+
)
|
|
50
|
+
] }),
|
|
51
|
+
e.description && /* @__PURE__ */ t("div", { className: "mt-2 text-sm text-gray-500", children: e.description })
|
|
52
|
+
] })
|
|
51
53
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
54
|
+
) : null;
|
|
55
|
+
}, I = ({
|
|
56
|
+
constraintName: n,
|
|
57
|
+
value: s,
|
|
58
|
+
onConstraintChange: a,
|
|
59
|
+
disabled: m,
|
|
60
|
+
error: r,
|
|
61
|
+
onRemoveConstraint: o
|
|
62
|
+
}) => {
|
|
63
|
+
const { getConstraintDefinition: c } = h(), e = c(n);
|
|
64
|
+
return e ? /* @__PURE__ */ t(
|
|
65
|
+
u,
|
|
66
|
+
{
|
|
67
|
+
errorCode: r?.code,
|
|
68
|
+
errorDescription: r?.message,
|
|
69
|
+
showError: !!r,
|
|
70
|
+
children: /* @__PURE__ */ i("div", { children: [
|
|
71
|
+
/* @__PURE__ */ i("div", { className: "mb-2 flex items-center justify-between", children: [
|
|
72
|
+
/* @__PURE__ */ t(d, { htmlFor: e.name, children: e.name }),
|
|
73
|
+
/* @__PURE__ */ i("div", { className: "flex items-center gap-2", children: [
|
|
74
|
+
/* @__PURE__ */ t(
|
|
75
|
+
g,
|
|
76
|
+
{
|
|
77
|
+
id: e.name,
|
|
78
|
+
checked: s,
|
|
79
|
+
onCheckedChange: (l) => a(l),
|
|
80
|
+
disabled: m,
|
|
81
|
+
className: p({ "border-destructive": r })
|
|
82
|
+
}
|
|
83
|
+
),
|
|
84
|
+
/* @__PURE__ */ t(
|
|
85
|
+
f,
|
|
86
|
+
{
|
|
87
|
+
type: "button",
|
|
88
|
+
variant: "ghost",
|
|
89
|
+
size: "icon",
|
|
90
|
+
onClick: () => o(),
|
|
91
|
+
children: /* @__PURE__ */ t(y, { className: "size-4" })
|
|
92
|
+
}
|
|
93
|
+
)
|
|
94
|
+
] })
|
|
95
|
+
] }),
|
|
96
|
+
e.description && /* @__PURE__ */ t("div", { className: "mt-2 text-sm text-gray-500", children: e.description })
|
|
97
|
+
] })
|
|
71
98
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
99
|
+
) : null;
|
|
100
|
+
}, C = b, v = b, N = I, j = {
|
|
101
|
+
id: "array-constraints",
|
|
102
|
+
hooks: {
|
|
103
|
+
registerConstraints() {
|
|
104
|
+
return [
|
|
105
|
+
{
|
|
106
|
+
name: "minItems",
|
|
107
|
+
label: "Min Items",
|
|
108
|
+
appliesTo: ["array"],
|
|
109
|
+
schema: {
|
|
110
|
+
type: "integer",
|
|
111
|
+
title: "Minimum Items Constraint",
|
|
112
|
+
description: "The minimum number of items the array must contain",
|
|
113
|
+
examples: [1, 2, 5],
|
|
114
|
+
minimum: 0
|
|
115
|
+
},
|
|
116
|
+
description: "Specifies the minimum number of items in the array",
|
|
117
|
+
defaultValue: 0
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: "maxItems",
|
|
121
|
+
label: "Max Items",
|
|
122
|
+
appliesTo: ["array"],
|
|
123
|
+
schema: {
|
|
124
|
+
type: "integer",
|
|
125
|
+
title: "Maximum Items Constraint",
|
|
126
|
+
description: "The maximum number of items the array can contain",
|
|
127
|
+
examples: [10, 20, 100],
|
|
128
|
+
minimum: 0
|
|
129
|
+
},
|
|
130
|
+
description: "Specifies the maximum number of items in the array",
|
|
131
|
+
defaultValue: 10
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
name: "uniqueItems",
|
|
135
|
+
label: "Unique Items",
|
|
136
|
+
appliesTo: ["array"],
|
|
137
|
+
schema: {
|
|
138
|
+
type: "boolean",
|
|
139
|
+
title: "Unique Items Constraint",
|
|
140
|
+
description: "Whether array items must be unique"
|
|
141
|
+
},
|
|
142
|
+
description: "When true, all items in the array must be unique",
|
|
143
|
+
defaultValue: !1
|
|
144
|
+
}
|
|
145
|
+
];
|
|
146
|
+
},
|
|
147
|
+
registerRenderers() {
|
|
148
|
+
return {
|
|
149
|
+
minItems: C,
|
|
150
|
+
maxItems: v,
|
|
151
|
+
uniqueItems: N
|
|
152
|
+
};
|
|
97
153
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return {
|
|
101
|
-
...f,
|
|
102
|
-
getCurrentSchema: a,
|
|
103
|
-
getCurrentProperty: b,
|
|
104
|
-
handlePropertyChange: P,
|
|
105
|
-
handleAddProperty: d,
|
|
106
|
-
handleKeyChange: j,
|
|
107
|
-
navigateToCorrectNesting: l,
|
|
108
|
-
handleDeleteProperty: S,
|
|
109
|
-
isPropertyRequired: h,
|
|
110
|
-
getValue: () => n,
|
|
111
|
-
handleDuplicateProperty: w
|
|
112
|
-
};
|
|
113
|
-
}
|
|
154
|
+
}
|
|
155
|
+
};
|
|
114
156
|
export {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
157
|
+
v as ArrayMaxItemsRenderer,
|
|
158
|
+
C as ArrayMinItemsRenderer,
|
|
159
|
+
N as ArrayUniqueItemsRenderer,
|
|
160
|
+
j as default
|
|
118
161
|
};
|
|
119
162
|
//# sourceMappingURL=index.es2.js.map
|
package/dist/index.es2.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es2.js","sources":["../src/packages/builder/context.tsx"],"sourcesContent":["import { createContext, useContext, useState } from \"react\";\n\nimport type { PropsWithChildren, SetStateAction } from \"react\";\nimport type { JSONSchema7, JSONSchema7Definition } from \"json-schema\";\nimport { clone, isEmpty } from \"remeda\";\nimport type { OperationError } from \"./shared-types\";\n\ninterface ContextState<T extends JSONSchema7> {\n schema: T;\n setSchema: React.Dispatch<T>;\n path: string[];\n setPath: React.Dispatch<SetStateAction<string[]>>;\n}\n\nexport const SchemaContext = createContext<\n ContextState<JSONSchema7> | undefined\n>(undefined);\n\nconst defaultSchema: JSONSchema7 = {\n $schema: \"http://json-schema.org/draft-07/schema#\",\n type: \"object\",\n title: \"title\",\n description: \"\",\n properties: {},\n required: [],\n};\n\nfunction SchemaProvider({\n children,\n initialSchema,\n}: PropsWithChildren<{ initialSchema?: JSONSchema7 }>) {\n const [schema, setSchema] = useState<JSONSchema7>(\n initialSchema ?? defaultSchema,\n );\n\n /**\n * Path represents the path to a nested property in the schema.\n * It should only contain property keys.\n * An empty path means the current schema is the root schema since\n * the path only represents nested properties.\n */\n const [path, setPath] = useState<string[]>([]);\n\n // NOTE: you *might* need to memoize your values\n // Learn more in http://kcd.im/optimize-context\n\n return (\n <SchemaContext.Provider value={{ schema, setSchema, path, setPath }}>\n {children}\n </SchemaContext.Provider>\n );\n}\n\nexport type PropertyAddError = OperationError & {\n status: \"error\";\n};\n\nexport interface PropertyAddSuccess {\n status: \"success\";\n property: JSONSchema7;\n}\n\nexport interface PropertyChangeSuccess {\n status: \"success\";\n property: JSONSchema7Definition;\n}\n\nfunction useSchema({\n onSchemaChange,\n}: {\n onSchemaChange?: (schema: JSONSchema7) => void;\n} = {}) {\n const context = useContext(SchemaContext);\n\n if (context === undefined) {\n throw new Error(\"useSchema must be used within a SchemaProvider\");\n }\n\n const { path, schema, setSchema } = context;\n\n /**\n * Navigates to the correct property schema of the latest key in the provided path.\n *\n * It will traverse both \"properties\" and \"items\" to find the correct property schema.\n *\n * It will only return a property schema if the provided path is valid i.e. it\n * correctly follows the schema's nesting structure.\n *\n * It will only return a parent schema if the provided path is valid i.e. it\n * correctly follows the schema's nesting structure.\n */\n const navigateToCorrectNesting = (\n providedSchema: JSONSchema7,\n providedPath: string[],\n ) => {\n let current = providedSchema;\n let propertySchema: JSONSchema7 | null = null;\n // Should be the schema of type \"object\" containing the property in its properties key\n let parentSchema: JSONSchema7 | null = null;\n\n for (const p of providedPath) {\n if (\n current.type === \"array\" &&\n current.items &&\n !Array.isArray(current.items) &&\n typeof current.items === \"object\" &&\n current.items.type === \"object\" &&\n typeof current.items.properties?.[p] === \"object\"\n ) {\n parentSchema = current.items;\n propertySchema = current.items.properties[p];\n current = current.items;\n } else if (\n current.type === \"object\" &&\n current.properties &&\n !Array.isArray(current.properties) &&\n typeof current.properties[p] === \"object\"\n ) {\n parentSchema = current;\n propertySchema = current.properties[p];\n current = current.properties[p];\n }\n }\n\n return { propertySchema, parentSchema };\n };\n\n /**\n * Gets the current schema of the latest key in the path.\n * If path is empty, it will return the root schema.\n *\n * It should always return the \"object\" schema of the current path.\n */\n const getCurrentSchema = (initialSchema?: JSONSchema7) => {\n // Gets the correct object schema if under nesting\n // Otherwise, return the root schema\n const { propertySchema } = navigateToCorrectNesting(\n initialSchema ?? schema,\n path,\n );\n\n if (propertySchema) {\n if (propertySchema.type === \"array\") {\n return propertySchema.items as JSONSchema7;\n }\n\n return propertySchema;\n }\n\n return initialSchema ?? schema;\n };\n\n /**\n * Gets the correct property schema of the latest key in the path.\n * If no path is provided, it will return null.\n */\n const getCurrentProperty = () => {\n const { propertySchema } = navigateToCorrectNesting(schema, path);\n\n return propertySchema;\n };\n\n /**\n * Change the key of a property in the schema. It expects\n * the find the key at the current path.\n */\n const handleKeyChange = (key: string, newKey: string) => {\n const newSchema = clone(schema);\n\n // The current schema containing the property to change\n const current: JSONSchema7 = getCurrentSchema(newSchema);\n\n if (current.properties?.[key]) {\n //Important: maintain order as to not confuse users\n const newProperties = Object.entries(current.properties).map(\n ([k, val]) => {\n return [k === key ? newKey : k, val];\n },\n );\n\n current.properties = Object.fromEntries(\n newProperties,\n ) as JSONSchema7[\"properties\"];\n }\n\n if (current.required?.includes(key)) {\n current.required = current.required.map((item) =>\n item === key ? newKey : item,\n );\n }\n\n setSchema(newSchema);\n onSchemaChange?.(newSchema);\n };\n\n const handlePropertyChange = (\n key: string,\n updates: Partial<JSONSchema7Definition> & { isRequired?: boolean },\n ): PropertyChangeSuccess | undefined => {\n const newSchema = clone(schema);\n\n // The current schema containing the property to change\n const current: JSONSchema7 = getCurrentSchema(newSchema);\n\n // Handle required field updates\n if (typeof updates === \"object\" && \"isRequired\" in updates) {\n if (current.type === \"object\") {\n if (!current.required) {\n current.required = [];\n }\n if (updates.isRequired) {\n if (!current.required.includes(key)) {\n current.required.push(key);\n }\n } else {\n current.required = current.required.filter((item) => item !== key);\n }\n }\n delete updates.isRequired;\n }\n\n let isUpdated = false;\n\n // Update the property\n if (current.type === \"object\" && current.properties) {\n const originalProperty = current.properties[key];\n // Ensure the property exists and is not a boolean\n if (typeof originalProperty !== \"boolean\" && originalProperty) {\n if (typeof updates !== \"boolean\") {\n //if updates changes the type of the property,\n //only the title, description, and default properties should remain\n //from the original property\n if (updates.type && updates.type !== originalProperty.type) {\n updates = {\n title: originalProperty.title,\n description: originalProperty.description,\n default: originalProperty.default,\n ...updates,\n };\n } else if (updates.enum) {\n //if the property is an enum, only the title and description should remain\n //from the original property\n delete updates.type;\n delete updates.items;\n delete updates.properties;\n updates = {\n title: originalProperty.title,\n description: originalProperty.description,\n ...updates,\n };\n } else {\n updates = { ...originalProperty, ...updates };\n }\n\n current.properties[key] = updates;\n }\n }\n isUpdated = true;\n }\n\n setSchema(newSchema);\n onSchemaChange?.(newSchema);\n\n if (isUpdated) {\n return { status: \"success\", property: current.properties![key]! };\n }\n };\n\n /**\n * Adds a sibling property to the current schema.\n */\n const handleAddProperty = (\n key: string,\n propertyToAdd: JSONSchema7,\n isRequired: boolean,\n ) => {\n const newSchema = clone(schema);\n\n // The current schema containing the property to add\n const current: JSONSchema7 = getCurrentSchema(newSchema);\n\n // Ensure the current schema has a properties object\n if (current.type !== \"object\") {\n current.type = \"object\";\n }\n if (!current.properties) {\n current.properties = {};\n }\n\n //Ensure there's no existing property with the same key\n if (current.properties[key]) {\n return {\n status: \"error\",\n code: \"key-exists\" as const,\n message: `Property with key ${key} already exists`,\n } satisfies PropertyAddError;\n }\n\n if (propertyToAdd.enum) {\n //ensure that only the enum property is present\n delete propertyToAdd.type;\n delete propertyToAdd.items;\n delete propertyToAdd.properties;\n }\n\n // Add the new property\n current.properties[key] = propertyToAdd;\n\n // Handle required field\n if (isRequired) {\n if (!current.required) {\n current.required = [];\n }\n if (!current.required.includes(key)) {\n current.required.push(key);\n }\n }\n\n setSchema(newSchema);\n onSchemaChange?.(newSchema);\n\n return {\n status: \"success\" as const,\n property: current.properties[key],\n } satisfies PropertyAddSuccess;\n };\n\n const handleDeleteProperty = (key: string) => {\n const newSchema = clone(schema);\n\n // The current schema containing the property to delete\n const current: JSONSchema7 = getCurrentSchema(newSchema);\n\n // Handle required field updates\n if (current.type === \"object\") {\n if (current.required) {\n current.required = current.required.filter((item) => item !== key);\n }\n }\n\n // Delete the property\n if (current.type === \"object\" && current.properties) {\n delete current.properties[key];\n }\n\n setSchema(newSchema);\n onSchemaChange?.(newSchema);\n };\n\n const handleDuplicateProperty = (key: string) => {\n const currentProperties = getCurrentSchema().properties;\n if (\n !currentProperties ||\n isEmpty(currentProperties) ||\n typeof currentProperties[key] === \"boolean\"\n ) {\n return;\n }\n\n const propertyToDuplicate = currentProperties[key]!;\n const newKey = `${key}_copy`;\n const newProperty = clone(propertyToDuplicate);\n\n // Add the duplicated property\n return handleAddProperty(newKey, newProperty, isPropertyRequired(key));\n };\n\n const isPropertyRequired = (key: string) => {\n if (path.length) {\n const { propertySchema } = navigateToCorrectNesting(schema, path);\n\n if (\n propertySchema?.type === \"array\" &&\n propertySchema.items &&\n typeof propertySchema.items !== \"boolean\" &&\n !Array.isArray(propertySchema.items) &&\n propertySchema.items?.type === \"object\"\n ) {\n return Boolean(propertySchema.items?.required?.includes(key));\n } else {\n return Boolean(propertySchema?.required?.includes(key));\n }\n }\n\n return Boolean(schema?.required?.includes(key));\n };\n\n /**\n * Programatically get the current schema value\n */\n const getValue = () => {\n return schema;\n };\n\n return {\n ...context,\n getCurrentSchema,\n getCurrentProperty,\n handlePropertyChange,\n handleAddProperty,\n handleKeyChange,\n navigateToCorrectNesting,\n handleDeleteProperty,\n isPropertyRequired,\n getValue,\n handleDuplicateProperty,\n };\n}\n\nexport { SchemaProvider, useSchema };\n"],"names":["SchemaContext","createContext","defaultSchema","SchemaProvider","children","initialSchema","schema","setSchema","useState","path","setPath","jsx","useSchema","onSchemaChange","context","useContext","navigateToCorrectNesting","providedSchema","providedPath","current","propertySchema","parentSchema","p","getCurrentSchema","getCurrentProperty","handleKeyChange","key","newKey","newSchema","clone","newProperties","k","val","item","handlePropertyChange","updates","isUpdated","originalProperty","handleAddProperty","propertyToAdd","isRequired","handleDeleteProperty","handleDuplicateProperty","currentProperties","isEmpty","propertyToDuplicate","newProperty","isPropertyRequired"],"mappings":";;;;AAca,MAAAA,IAAgBC,EAE3B,MAAS,GAELC,IAA6B;AAAA,EACjC,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AAAA,EACP,aAAa;AAAA,EACb,YAAY,CAAC;AAAA,EACb,UAAU,CAAA;AACZ;AAEA,SAASC,EAAe;AAAA,EACtB,UAAAC;AAAA,EACA,eAAAC;AACF,GAAuD;AAC/C,QAAA,CAACC,GAAQC,CAAS,IAAIC;AAA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M;AAAA,IACA,UAde,MACRzC;AAAA,IAcP,yBAAAoC;AAAA,EACF;AACF;"}
|
|
1
|
+
{"version":3,"file":"index.es2.js","sources":["../src/packages/plugins/array.tsx"],"sourcesContent":["import { Input } from \"@/components/ui/input\";\nimport { InputErrorWrapper } from \"@/components/input-error\";\nimport { Label } from \"@/components/ui/label\";\nimport { cn } from \"@/lib/utils\";\nimport {\n BaseJSONSchemaPlugin,\n ConstraintRendererProps,\n useConstraints,\n} from \"@/packages/constraints/context\";\nimport { Button } from \"@/components/ui/button\";\nimport { X } from \"lucide-react\";\nimport { Switch } from \"@/components/ui/switch\";\n\n// Generic numeric constraint renderer for arrays (minItems, maxItems)\nconst ArrayNumberConstraintRenderer = ({\n constraintName,\n value,\n onConstraintChange,\n disabled,\n error,\n onRemoveConstraint,\n}: ConstraintRendererProps<number> & { disabled?: boolean }) => {\n const { getConstraintDefinition } = useConstraints();\n const constraintDef = getConstraintDefinition(constraintName);\n\n if (!constraintDef) {\n return null;\n }\n\n return (\n <InputErrorWrapper\n errorCode={error?.code}\n errorDescription={error?.message}\n showError={!!error}\n >\n <div>\n <Label className=\"mb-2\" htmlFor={constraintDef.name}>\n {constraintDef.name}\n </Label>\n <div className=\"flex items-center gap-2\">\n <Input\n id={constraintDef.name}\n type=\"number\"\n value={value}\n onChange={(e) => onConstraintChange(Number(e.target.value))}\n disabled={disabled}\n min={0}\n className={cn({ \"border-destructive\": error })}\n />\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"icon\"\n onClick={() => onRemoveConstraint()}\n >\n <X className=\"size-4\" />\n </Button>\n </div>\n {constraintDef.description && (\n <div className=\"mt-2 text-sm text-gray-500\">\n {constraintDef.description}\n </div>\n )}\n </div>\n </InputErrorWrapper>\n );\n};\n\n// Boolean constraint renderer for uniqueItems\nconst ArrayBooleanConstraintRenderer = ({\n constraintName,\n value,\n onConstraintChange,\n disabled,\n error,\n onRemoveConstraint,\n}: ConstraintRendererProps<boolean> & { disabled?: boolean }) => {\n const { getConstraintDefinition } = useConstraints();\n const constraintDef = getConstraintDefinition(constraintName);\n\n if (!constraintDef) {\n return null;\n }\n\n return (\n <InputErrorWrapper\n errorCode={error?.code}\n errorDescription={error?.message}\n showError={!!error}\n >\n <div>\n <div className=\"mb-2 flex items-center justify-between\">\n <Label htmlFor={constraintDef.name}>{constraintDef.name}</Label>\n <div className=\"flex items-center gap-2\">\n <Switch\n id={constraintDef.name}\n checked={value}\n onCheckedChange={(checked) => onConstraintChange(checked)}\n disabled={disabled}\n className={cn({ \"border-destructive\": error })}\n />\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"icon\"\n onClick={() => onRemoveConstraint()}\n >\n <X className=\"size-4\" />\n </Button>\n </div>\n </div>\n {constraintDef.description && (\n <div className=\"mt-2 text-sm text-gray-500\">\n {constraintDef.description}\n </div>\n )}\n </div>\n </InputErrorWrapper>\n );\n};\n\n// Export the renderers\nexport const ArrayMinItemsRenderer = ArrayNumberConstraintRenderer;\nexport const ArrayMaxItemsRenderer = ArrayNumberConstraintRenderer;\nexport const ArrayUniqueItemsRenderer = ArrayBooleanConstraintRenderer;\n\nconst plugin: BaseJSONSchemaPlugin = {\n id: \"array-constraints\",\n hooks: {\n registerConstraints() {\n return [\n {\n name: \"minItems\",\n label: \"Min Items\",\n appliesTo: [\"array\"],\n schema: {\n type: \"integer\",\n title: \"Minimum Items Constraint\",\n description: \"The minimum number of items the array must contain\",\n examples: [1, 2, 5],\n minimum: 0,\n },\n description: \"Specifies the minimum number of items in the array\",\n defaultValue: 0,\n },\n {\n name: \"maxItems\",\n label: \"Max Items\",\n appliesTo: [\"array\"],\n schema: {\n type: \"integer\",\n title: \"Maximum Items Constraint\",\n description: \"The maximum number of items the array can contain\",\n examples: [10, 20, 100],\n minimum: 0,\n },\n description: \"Specifies the maximum number of items in the array\",\n defaultValue: 10,\n },\n {\n name: \"uniqueItems\",\n label: \"Unique Items\",\n appliesTo: [\"array\"],\n schema: {\n type: \"boolean\",\n title: \"Unique Items Constraint\",\n description: \"Whether array items must be unique\",\n },\n description: \"When true, all items in the array must be unique\",\n defaultValue: false,\n },\n ];\n },\n registerRenderers() {\n return {\n minItems: ArrayMinItemsRenderer,\n maxItems: ArrayMaxItemsRenderer,\n uniqueItems: ArrayUniqueItemsRenderer,\n };\n },\n },\n};\n\nexport default plugin;\n"],"names":["ArrayNumberConstraintRenderer","constraintName","value","onConstraintChange","disabled","error","onRemoveConstraint","getConstraintDefinition","useConstraints","constraintDef","jsx","InputErrorWrapper","Label","jsxs","Input","e","cn","Button","X","ArrayBooleanConstraintRenderer","Switch","checked","ArrayMinItemsRenderer","ArrayMaxItemsRenderer","ArrayUniqueItemsRenderer","plugin"],"mappings":";;;;;;;;;AAcA,MAAMA,IAAgC,CAAC;AAAA,EACrC,gBAAAC;AAAA,EACA,OAAAC;AAAA,EACA,oBAAAC;AAAA,EACA,UAAAC;AAAA,EACA,OAAAC;AAAA,EACA,oBAAAC;AACF,MAAgE;AACxD,QAAA,EAAE,yBAAAC,EAAwB,IAAIC,EAAe,GAC7CC,IAAgBF,EAAwBN,CAAc;AAE5D,SAAKQ,IAKH,gBAAAC;AAAA,IAACC;AAAA,IAAA;AAAA,MACC,WAAWN,GAAO;AAAA,MAClB,kBAAkBA,GAAO;AAAA,MACzB,WAAW,CAAC,CAACA;AAAA,MAEb,4BAAC,OACC,EAAA,UAAA;AAAA,QAAA,gBAAAK,EAACE,KAAM,WAAU,QAAO,SAASH,EAAc,MAC5C,YAAc,KACjB,CAAA;AAAA,QACA,gBAAAI,EAAC,OAAI,EAAA,WAAU,2BACb,UAAA;AAAA,UAAA,gBAAAH;AAAA,YAACI;AAAA,YAAA;AAAA,cACC,IAAIL,EAAc;AAAA,cAClB,MAAK;AAAA,cACL,OAAAP;AAAA,cACA,UAAU,CAACa,MAAMZ,EAAmB,OAAOY,EAAE,OAAO,KAAK,CAAC;AAAA,cAC1D,UAAAX;AAAA,cACA,KAAK;AAAA,cACL,WAAWY,EAAG,EAAE,sBAA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AAAA,QAAA;AAAA,MAElB;AAAA,IACF;AAAA,IACA,oBAAoB;AACX,aAAA;AAAA,QACL,UAAUH;AAAA,QACV,UAAUC;AAAA,QACV,aAAaC;AAAA,MACf;AAAA,IAAA;AAAA,EACF;AAEJ;"}
|
package/dist/index.es20.js
CHANGED
|
@@ -1,26 +1,138 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
s(f.target.value);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
);
|
|
1
|
+
import { jsx as s, jsxs as u } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo as R, useEffect as V } from "react";
|
|
3
|
+
import { Button as A } from "./index.es13.js";
|
|
4
|
+
import { Dialog as $, DialogContent as N, DialogHeader as j, DialogTitle as w, DialogDescription as E, DialogFooter as I } from "./index.es37.js";
|
|
5
|
+
import { Label as L } from "./index.es11.js";
|
|
6
|
+
import { a as d } from "./index.es18.js";
|
|
7
|
+
import { useConstraints as _ } from "./index.es8.js";
|
|
8
|
+
import k from "./index.es38.js";
|
|
9
|
+
import { Separator as z } from "./index.es39.js";
|
|
10
|
+
import { AddFormSchema as B } from "./index.es25.js";
|
|
11
|
+
import { useForm as H } from "react-hook-form";
|
|
12
|
+
import { zodResolver as M } from "./index.es40.js";
|
|
13
|
+
import { Form as O } from "./index.es41.js";
|
|
14
|
+
const P = B.pick({
|
|
15
|
+
constraints: !0,
|
|
16
|
+
property: !0
|
|
21
17
|
});
|
|
22
|
-
|
|
18
|
+
function et({
|
|
19
|
+
open: p,
|
|
20
|
+
onOpenChange: f,
|
|
21
|
+
onSubmit: h,
|
|
22
|
+
property: i,
|
|
23
|
+
propertyKey: g
|
|
24
|
+
}) {
|
|
25
|
+
const e = H({
|
|
26
|
+
resolver: M(P),
|
|
27
|
+
defaultValues: {
|
|
28
|
+
property: i
|
|
29
|
+
}
|
|
30
|
+
}), m = e.watch("constraints"), {
|
|
31
|
+
getConstraintDefinitionsForType: C,
|
|
32
|
+
getRendererForConstraint: y,
|
|
33
|
+
validateConstraintValue: v
|
|
34
|
+
} = _(), D = (t) => {
|
|
35
|
+
const { constraints: r } = t, a = {
|
|
36
|
+
...r?.reduce((n, o) => ({
|
|
37
|
+
...n,
|
|
38
|
+
[o.name]: o.value
|
|
39
|
+
}), {})
|
|
40
|
+
};
|
|
41
|
+
h([g, a]), e.reset();
|
|
42
|
+
}, S = (t, r) => {
|
|
43
|
+
const a = d(m), n = a?.[t];
|
|
44
|
+
if (!n) {
|
|
45
|
+
e.setError(`constraints.${t}`, {
|
|
46
|
+
message: "The constraint was not found",
|
|
47
|
+
type: "constraint_not_found"
|
|
48
|
+
});
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const o = v(
|
|
52
|
+
n.name,
|
|
53
|
+
r
|
|
54
|
+
);
|
|
55
|
+
if (o.status === "error") {
|
|
56
|
+
let c = o.message;
|
|
57
|
+
o.code === "invalid" && (c = `${c}: ${o.error?.map((b) => b.message).join(", ")}`), e.setError(`constraints.${t}`, {
|
|
58
|
+
type: o.code,
|
|
59
|
+
message: c
|
|
60
|
+
});
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
n.value = r, e.setValue("constraints", a), e.clearErrors(`constraints.${t}`);
|
|
64
|
+
}, F = (t) => {
|
|
65
|
+
if (!m) return;
|
|
66
|
+
const a = d(m).filter((n) => n.name !== t);
|
|
67
|
+
e.setValue("constraints", a);
|
|
68
|
+
}, l = R(() => C(
|
|
69
|
+
typeof i?.type == "string" ? i.type : ""
|
|
70
|
+
), [i.type]);
|
|
71
|
+
return V(() => {
|
|
72
|
+
const t = [];
|
|
73
|
+
for (const r of l)
|
|
74
|
+
r.name in i && t.push({
|
|
75
|
+
name: r.name,
|
|
76
|
+
value: i[r.name]
|
|
77
|
+
});
|
|
78
|
+
e.setValue("constraints", t);
|
|
79
|
+
}, [l]), /* @__PURE__ */ s($, { open: p, onOpenChange: f, children: /* @__PURE__ */ u(N, { children: [
|
|
80
|
+
/* @__PURE__ */ u(j, { children: [
|
|
81
|
+
/* @__PURE__ */ s(w, { children: "Edit" }),
|
|
82
|
+
/* @__PURE__ */ s(E, { children: "Constraints and other properties" })
|
|
83
|
+
] }),
|
|
84
|
+
/* @__PURE__ */ s(O, { ...e, children: /* @__PURE__ */ u(
|
|
85
|
+
"form",
|
|
86
|
+
{
|
|
87
|
+
onSubmit: e.handleSubmit(D),
|
|
88
|
+
className: "space-y-4",
|
|
89
|
+
"data-testid": "edit-property-form",
|
|
90
|
+
children: [
|
|
91
|
+
l.length ? /* @__PURE__ */ u("div", { className: "space-y-2", children: [
|
|
92
|
+
/* @__PURE__ */ s(L, { children: "Constraints" }),
|
|
93
|
+
/* @__PURE__ */ s(
|
|
94
|
+
k,
|
|
95
|
+
{
|
|
96
|
+
addedConstraints: m ?? [],
|
|
97
|
+
availableDefinitions: l,
|
|
98
|
+
onAdd: (t) => {
|
|
99
|
+
e.setValue("constraints", t);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
),
|
|
103
|
+
/* @__PURE__ */ s(z, {}),
|
|
104
|
+
m?.map((t, r) => {
|
|
105
|
+
const a = y(t.name);
|
|
106
|
+
if (!a) return null;
|
|
107
|
+
const n = e.formState.errors.constraints?.[r];
|
|
108
|
+
let o;
|
|
109
|
+
return n && (o = {
|
|
110
|
+
code: n?.type ?? "INVALID",
|
|
111
|
+
message: n.message ?? "An error occurred"
|
|
112
|
+
}), /* @__PURE__ */ s(
|
|
113
|
+
a,
|
|
114
|
+
{
|
|
115
|
+
constraintName: t.name,
|
|
116
|
+
value: t.value,
|
|
117
|
+
onConstraintChange: (c) => {
|
|
118
|
+
S(r, c);
|
|
119
|
+
},
|
|
120
|
+
onRemoveConstraint: () => {
|
|
121
|
+
F(t.name);
|
|
122
|
+
},
|
|
123
|
+
error: o
|
|
124
|
+
},
|
|
125
|
+
t.name
|
|
126
|
+
);
|
|
127
|
+
})
|
|
128
|
+
] }) : null,
|
|
129
|
+
/* @__PURE__ */ s(I, { children: /* @__PURE__ */ s(A, { type: "submit", children: "Save" }) })
|
|
130
|
+
]
|
|
131
|
+
}
|
|
132
|
+
) })
|
|
133
|
+
] }) });
|
|
134
|
+
}
|
|
23
135
|
export {
|
|
24
|
-
|
|
136
|
+
et as EditPropertyDialog
|
|
25
137
|
};
|
|
26
138
|
//# sourceMappingURL=index.es20.js.map
|