@datenlotse/jsonjoy-builder 0.5.0 → 0.5.1
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/components/SchemaEditor/AddFieldButton.js +59 -4
- package/dist/components/SchemaEditor/SchemaVisualEditor.js +1 -0
- package/dist/components/SchemaEditor/types/ObjectEditor.js +1 -0
- package/dist/i18n/locales/de.js +3 -3
- package/dist/index.css +19 -1
- package/dist/lib/schemaEditor.js +3 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { CirclePlus, HelpCircle, Info } from "lucide-react";
|
|
3
|
-
import { useId, useState } from "react";
|
|
3
|
+
import { useEffect, useId, useState } from "react";
|
|
4
4
|
import { Badge } from "../ui/badge.js";
|
|
5
5
|
import { Button } from "../ui/button.js";
|
|
6
6
|
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "../ui/dialog.js";
|
|
@@ -8,30 +8,64 @@ import { Input } from "../ui/input.js";
|
|
|
8
8
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../ui/tooltip.js";
|
|
9
9
|
import { useTranslation } from "../../hooks/use-translation.js";
|
|
10
10
|
import SchemaTypeSelector from "./SchemaTypeSelector.js";
|
|
11
|
-
|
|
11
|
+
import TypeEditor from "./TypeEditor.js";
|
|
12
|
+
const ENUM_TYPES = [
|
|
13
|
+
"string",
|
|
14
|
+
"number",
|
|
15
|
+
"integer"
|
|
16
|
+
];
|
|
17
|
+
function createEmptyDraftSchema(type) {
|
|
18
|
+
return {
|
|
19
|
+
type
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const AddFieldButton = ({ parentSchema, onAddField, variant = "primary" })=>{
|
|
12
23
|
const [dialogOpen, setDialogOpen] = useState(false);
|
|
13
24
|
const [fieldName, setFieldName] = useState("");
|
|
14
25
|
const [fieldType, setFieldType] = useState("string");
|
|
15
26
|
const [fieldDesc, setFieldDesc] = useState("");
|
|
16
27
|
const [fieldRequired, setFieldRequired] = useState(false);
|
|
28
|
+
const [draftSchema, setDraftSchema] = useState(()=>createEmptyDraftSchema("string"));
|
|
17
29
|
const fieldNameId = useId();
|
|
18
30
|
const fieldDescId = useId();
|
|
19
31
|
const fieldRequiredId = useId();
|
|
20
32
|
const fieldTypeId = useId();
|
|
21
33
|
const t = useTranslation();
|
|
34
|
+
useEffect(()=>{
|
|
35
|
+
setDraftSchema((prev)=>{
|
|
36
|
+
const nextType = fieldType;
|
|
37
|
+
const prevType = prev.type;
|
|
38
|
+
if (prevType === nextType) return prev;
|
|
39
|
+
return createEmptyDraftSchema(nextType);
|
|
40
|
+
});
|
|
41
|
+
}, [
|
|
42
|
+
fieldType
|
|
43
|
+
]);
|
|
44
|
+
useEffect(()=>{
|
|
45
|
+
if (dialogOpen) setDraftSchema(createEmptyDraftSchema(fieldType));
|
|
46
|
+
}, [
|
|
47
|
+
dialogOpen
|
|
48
|
+
]);
|
|
22
49
|
const handleSubmit = (e)=>{
|
|
23
50
|
e.preventDefault();
|
|
24
51
|
if (!fieldName.trim()) return;
|
|
52
|
+
const validation = ENUM_TYPES.includes(fieldType) && Object.keys(draftSchema).length > 1 ? {
|
|
53
|
+
...draftSchema,
|
|
54
|
+
type: fieldType
|
|
55
|
+
} : void 0;
|
|
25
56
|
onAddField({
|
|
26
|
-
name: fieldName,
|
|
57
|
+
name: fieldName.trim(),
|
|
27
58
|
type: fieldType,
|
|
28
59
|
description: fieldDesc,
|
|
29
|
-
required: fieldRequired
|
|
60
|
+
required: fieldRequired,
|
|
61
|
+
default: draftSchema.default,
|
|
62
|
+
validation
|
|
30
63
|
});
|
|
31
64
|
setFieldName("");
|
|
32
65
|
setFieldType("string");
|
|
33
66
|
setFieldDesc("");
|
|
34
67
|
setFieldRequired(false);
|
|
68
|
+
setDraftSchema(createEmptyDraftSchema("string"));
|
|
35
69
|
setDialogOpen(false);
|
|
36
70
|
};
|
|
37
71
|
return /*#__PURE__*/ jsxs(Fragment, {
|
|
@@ -283,6 +317,27 @@ const AddFieldButton = ({ onAddField, variant = "primary" })=>{
|
|
|
283
317
|
})
|
|
284
318
|
]
|
|
285
319
|
}),
|
|
320
|
+
ENUM_TYPES.includes(fieldType) && /*#__PURE__*/ jsxs("details", {
|
|
321
|
+
className: "group rounded-lg border bg-muted/30",
|
|
322
|
+
children: [
|
|
323
|
+
/*#__PURE__*/ jsx("summary", {
|
|
324
|
+
className: "cursor-pointer list-none px-4 py-3 text-sm font-medium",
|
|
325
|
+
children: t.stringAllowedValuesEnumLabel
|
|
326
|
+
}),
|
|
327
|
+
/*#__PURE__*/ jsx("div", {
|
|
328
|
+
className: "border-t px-4 pb-4 pt-2",
|
|
329
|
+
children: /*#__PURE__*/ jsx(TypeEditor, {
|
|
330
|
+
schema: draftSchema,
|
|
331
|
+
readOnly: false,
|
|
332
|
+
parentSchema: parentSchema,
|
|
333
|
+
propertyName: fieldName.trim() || void 0,
|
|
334
|
+
validationNode: void 0,
|
|
335
|
+
onChange: setDraftSchema,
|
|
336
|
+
depth: 1
|
|
337
|
+
})
|
|
338
|
+
})
|
|
339
|
+
]
|
|
340
|
+
}),
|
|
286
341
|
/*#__PURE__*/ jsxs(DialogFooter, {
|
|
287
342
|
className: "mt-6 gap-2 flex-wrap",
|
|
288
343
|
children: [
|
|
@@ -44,6 +44,7 @@ const SchemaVisualEditor = ({ schema, onChange, readOnly = false })=>{
|
|
|
44
44
|
!readOnly && /*#__PURE__*/ jsx("div", {
|
|
45
45
|
className: "mb-6 shrink-0",
|
|
46
46
|
children: /*#__PURE__*/ jsx(AddFieldButton, {
|
|
47
|
+
parentSchema: asObjectSchema(schema),
|
|
47
48
|
onAddField: handleAddField
|
|
48
49
|
})
|
|
49
50
|
}),
|
|
@@ -79,6 +79,7 @@ const ObjectEditor = ({ schema, validationNode, onChange, depth = 0, readOnly =
|
|
|
79
79
|
!readOnly && /*#__PURE__*/ jsx("div", {
|
|
80
80
|
className: "mt-4",
|
|
81
81
|
children: /*#__PURE__*/ jsx(AddFieldButton, {
|
|
82
|
+
parentSchema: normalizedSchema,
|
|
82
83
|
onAddField: handleAddProperty,
|
|
83
84
|
variant: "secondary"
|
|
84
85
|
})
|
package/dist/i18n/locales/de.js
CHANGED
|
@@ -30,7 +30,7 @@ const de = {
|
|
|
30
30
|
fieldTypeBooleanDescription: "Für Wahr/Falsch-Werte",
|
|
31
31
|
fieldTypeObjectLabel: "Gruppe",
|
|
32
32
|
fieldTypeObjectDescription: "Zum Gruppieren verwandter Felder",
|
|
33
|
-
fieldTypeArrayLabel: "
|
|
33
|
+
fieldTypeArrayLabel: "Mehrfach-Auswahl",
|
|
34
34
|
fieldTypeArrayDescription: "Für Sammlungen von Elementen",
|
|
35
35
|
propertyDescriptionPlaceholder: "Beschreibung hinzufügen...",
|
|
36
36
|
propertyDescriptionButton: "Beschreibung hinzufügen...",
|
|
@@ -112,10 +112,10 @@ const de = {
|
|
|
112
112
|
whenPropertyEquals: "Wenn {property} = {value}",
|
|
113
113
|
stringFormatSelectPlaceholder: "Format auswählen",
|
|
114
114
|
stringValidationErrorLengthRange: "'Minimale Länge' darf nicht größer als 'Maximale Länge' sein.",
|
|
115
|
-
schemaTypeArray: "
|
|
115
|
+
schemaTypeArray: "Mehrfach-Auswahl",
|
|
116
116
|
schemaTypeBoolean: "Ja/Nein",
|
|
117
117
|
schemaTypeNumber: "Zahl",
|
|
118
|
-
schemaTypeObject: "
|
|
118
|
+
schemaTypeObject: "Gruppe",
|
|
119
119
|
schemaTypeString: "Text",
|
|
120
120
|
schemaTypeNull: "Leer",
|
|
121
121
|
inferrerTitle: "JSON-Schema ableiten",
|
package/dist/index.css
CHANGED
|
@@ -1356,6 +1356,10 @@
|
|
|
1356
1356
|
cursor: text;
|
|
1357
1357
|
}
|
|
1358
1358
|
|
|
1359
|
+
.jsonjoy .list-none, .jsonjoy.list-none {
|
|
1360
|
+
list-style-type: none;
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1359
1363
|
.jsonjoy .grid-cols-1, .jsonjoy.grid-cols-1 {
|
|
1360
1364
|
grid-template-columns: repeat(1, minmax(0, 1fr));
|
|
1361
1365
|
}
|
|
@@ -1719,7 +1723,17 @@
|
|
|
1719
1723
|
background-color: var(--jsonjoy-color-green-50);
|
|
1720
1724
|
}
|
|
1721
1725
|
|
|
1722
|
-
.jsonjoy .bg-muted, .jsonjoy.bg-muted, .jsonjoy .bg-muted\/
|
|
1726
|
+
.jsonjoy .bg-muted, .jsonjoy.bg-muted, .jsonjoy .bg-muted\/30, .jsonjoy.bg-muted\/30 {
|
|
1727
|
+
background-color: var(--jsonjoy-color-muted);
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1730
|
+
@supports (color: color-mix(in lab, red, red)) {
|
|
1731
|
+
.jsonjoy .bg-muted\/30, .jsonjoy.bg-muted\/30 {
|
|
1732
|
+
background-color: color-mix(in oklab, var(--jsonjoy-color-muted) 30%, transparent);
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
|
|
1736
|
+
.jsonjoy .bg-muted\/40, .jsonjoy.bg-muted\/40 {
|
|
1723
1737
|
background-color: var(--jsonjoy-color-muted);
|
|
1724
1738
|
}
|
|
1725
1739
|
|
|
@@ -1968,6 +1982,10 @@
|
|
|
1968
1982
|
padding-bottom: calc(var(--jsonjoy-spacing) * 2);
|
|
1969
1983
|
}
|
|
1970
1984
|
|
|
1985
|
+
.jsonjoy .pb-4, .jsonjoy.pb-4 {
|
|
1986
|
+
padding-bottom: calc(var(--jsonjoy-spacing) * 4);
|
|
1987
|
+
}
|
|
1988
|
+
|
|
1971
1989
|
.jsonjoy .pb-24, .jsonjoy.pb-24 {
|
|
1972
1990
|
padding-bottom: calc(var(--jsonjoy-spacing) * 24);
|
|
1973
1991
|
}
|
package/dist/lib/schemaEditor.js
CHANGED
|
@@ -129,7 +129,9 @@ function renameObjectProperty(schema, oldName, newName) {
|
|
|
129
129
|
const propertyOrder = newSchema.$propertyOrder || Object.keys(newSchema.properties);
|
|
130
130
|
for (const key of propertyOrder)if (key === oldName) newProperties[newName] = newSchema.properties[oldName];
|
|
131
131
|
else if (key in newSchema.properties) newProperties[key] = newSchema.properties[key];
|
|
132
|
-
for (const [key, value] of Object.entries(newSchema.properties))if (
|
|
132
|
+
for (const [key, value] of Object.entries(newSchema.properties))if (key !== oldName) {
|
|
133
|
+
if (!(key in newProperties)) newProperties[key] = value;
|
|
134
|
+
}
|
|
133
135
|
newSchema.properties = newProperties;
|
|
134
136
|
if (newSchema.required) newSchema.required = newSchema.required.map((field)=>field === oldName ? newName : field);
|
|
135
137
|
if (newSchema.$propertyOrder) newSchema.$propertyOrder = newSchema.$propertyOrder.map((name)=>name === oldName ? newName : name);
|