From ababdeda91f92358a63daf1a6a0e6885656a4810 Mon Sep 17 00:00:00 2001 From: Javier Martinez Date: Mon, 28 Aug 2023 15:38:26 +0000 Subject: [PATCH] avoid adding siblings only array and object types can add children --- src/lib/editor/form/AbstractField.svelte | 30 +++++++++------------ src/lib/editor/form/FieldButton.svelte | 26 ++++++++++++++++-- src/lib/editor/form/FieldButtons.svelte | 10 +++++-- src/lib/editor/form/FieldContextMenu.svelte | 2 +- 4 files changed, 45 insertions(+), 23 deletions(-) diff --git a/src/lib/editor/form/AbstractField.svelte b/src/lib/editor/form/AbstractField.svelte index 3dbab0e..0388d5a 100644 --- a/src/lib/editor/form/AbstractField.svelte +++ b/src/lib/editor/form/AbstractField.svelte @@ -25,10 +25,9 @@ let isHover = false; let isFocus = false; - $: showContextMenu = !field.is.root && (isHover || isFocus); - $: parentField = field.parent as UIModelField; + $: showContextMenu = isHover || isFocus; $: addMenuEmptyItem = field.is.empty; - $: addMenu = !addMenuEmptyItem && showAddMenu && !parentField.is.complete; + $: addMenu = !addMenuEmptyItem && showAddMenu && !field.is.complete; $: { if (addMenuRef) { @@ -41,7 +40,6 @@ function handleHover(e: CustomEvent) { // @note: Prevent undesired hover events on other items while dragging - console.log(e.detail); isHover = e.detail; } @@ -58,15 +56,16 @@ } function handleAddField() { - if (parentField.is.complete) return; + if (field.is.complete) return; showAddMenu = false; // @note: Add field directly instead of showing the dropdown option list - if (parentField.type === "array" || parentField.controlType === "dictionary") { - const [childOption] = parentField.options || []; + if (field.type === "array" || field.controlType === "dictionary") { + console.log(field.options); + const [childOption] = field.options || []; - addField(parentField, childOption); + addField(field, childOption); return; } @@ -101,7 +100,7 @@ const nextItem = field.getNextFocusableField(); // @note: Last item but the parent is not complete, show the add field menu - if (nextItem?.isContainer() && !parentField.is.complete) { + if (nextItem?.isContainer() && !field.is.complete) { return handleAddField(); } else { return focusNextField(nextItem); @@ -126,22 +125,17 @@ on:focusin={handleFocusIn} on:focusout={handleFocusOut} > -
+
-
- +
+
{#if addMenu} - + {/if} diff --git a/src/lib/editor/form/FieldButton.svelte b/src/lib/editor/form/FieldButton.svelte index e75b0f7..db69a7b 100644 --- a/src/lib/editor/form/FieldButton.svelte +++ b/src/lib/editor/form/FieldButton.svelte @@ -1,10 +1,32 @@ @@ -12,11 +34,11 @@

{tooltipText}

diff --git a/src/lib/editor/form/FieldButtons.svelte b/src/lib/editor/form/FieldButtons.svelte index 9c9f00e..efa2868 100644 --- a/src/lib/editor/form/FieldButtons.svelte +++ b/src/lib/editor/form/FieldButtons.svelte @@ -1,6 +1,6 @@