diff --git a/src/lib/editor/form/AbstractField.svelte b/src/lib/editor/form/AbstractField.svelte index 91c0ecf..24eebfe 100644 --- a/src/lib/editor/form/AbstractField.svelte +++ b/src/lib/editor/form/AbstractField.svelte @@ -12,6 +12,7 @@ import BooleanField from "./BooleanField.svelte"; import clsx from "clsx"; import { getBuilderContext } from "$lib/store/builder"; + import type { Schema } from "./utils/schema"; const dispatch = createEventDispatcher(); @@ -34,6 +35,7 @@ export let readOnly = false; + $: childrenType = (field.schema.items as Schema)?.type; $: isHover = $activeItem === field.id; $: highlight = $highlightedItem === field.id; $: showContextMenu = !readOnly && isHover; @@ -42,12 +44,12 @@ const offset = top + height - window.innerHeight; contextMenuOffset = offset > 0 ? offset : 0; } - $: isParent = ["object", "array"].includes(field.type); + $: isParent = ["object", "array"].includes(field.type) && childrenType !== "string"; $: isSection = isParent && field.parent?.is.root; $: wrapperClasses = clsx({ "bg-neutral-50 border-neutral-100": isHover && !isParent, "border-transparent": !isHover, - "border-l border-t border-b": !isParent, + "border-l border-t border-b": !["object", "array"].includes(field.type), "border-r rounded-r": readOnly && !isParent, "pl-2": isParent && !isSection, }); @@ -55,6 +57,7 @@ "bg-neutral-50": isHover, "border-workspace-accent-500": highlight, "border-neutral-200": !highlight, + "border-l border-t border-b": childrenType !== "string", }); $: contextMenuClasses = clsx({ "mt-1": isParent && !isSection && !field.is.root, @@ -78,20 +81,29 @@ function handleAddField() { showAddMenu = false; + // Children of string arrays can add items directly from the row + if (field.type === "string" && field.parent?.type === "array") { + addFieldToArray(field.parent); + return; + } + // @note: Add field directly instead of showing the dropdown option list if (field.type === "array" || field.controlType === "dictionary") { - const [childOption] = field.options || []; - - const newField = field.addChildField(childOption); - newField?.tryFocus(); - dispatch("fieldAdded", newField); - + addFieldToArray(field); return; } showAddMenu = true; } + function addFieldToArray(f: UIModelField) { + const [childOption] = f.options || []; + + const newField = f.addChildField(childOption); + newField?.tryFocus(); + dispatch("fieldAdded", newField); + } + function focusNextField(nextField = field.getNextFocusableField()) { if (!nextField) return; nextField.tryFocus(5, 0); @@ -156,7 +168,7 @@ >
{#if isParent && !isSection && !field.is.root} -
+
{/if}
-
- - - - {#if showAddMenu} -
+ - (showAddMenu = false)} /> -
- {/if} -
+ + + {#if showAddMenu} +
+ (showAddMenu = false)} /> +
+ {/if} + + {/if}