diff --git a/packages/builder/src/components/common/NavItem.svelte b/packages/builder/src/components/common/NavItem.svelte
index b319560ddd..1fd43e2c70 100644
--- a/packages/builder/src/components/common/NavItem.svelte
+++ b/packages/builder/src/components/common/NavItem.svelte
@@ -16,6 +16,7 @@
export let scrollable = false
export let highlighted = false
export let rightAlignIcon = false
+ export let id
const scrollApi = getContext("scroll")
const dispatch = createEventDispatcher()
@@ -58,6 +59,7 @@
on:click={onClick}
ondragover="return false"
ondragenter="return false"
+ {id}
>
{#if withArrow}
diff --git a/packages/builder/src/components/design/settings/controls/EjectBlockButton.svelte b/packages/builder/src/components/design/settings/controls/EjectBlockButton.svelte
index 66a93975ca..e19d4b584b 100644
--- a/packages/builder/src/components/design/settings/controls/EjectBlockButton.svelte
+++ b/packages/builder/src/components/design/settings/controls/EjectBlockButton.svelte
@@ -1,23 +1,13 @@
-
- Eject block
-
+
Eject block
-
- store.actions.components.requestEjectBlock(componentInstance?._id)}
- okText="Eject block"
-/>
diff --git a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/_components/navigation/ComponentKeyHandler.svelte b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/_components/navigation/ComponentKeyHandler.svelte
new file mode 100644
index 0000000000..004db799d0
--- /dev/null
+++ b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/_components/navigation/ComponentKeyHandler.svelte
@@ -0,0 +1,131 @@
+
+
+ store.actions.components.delete(componentToDelete)}
+/>
+ store.actions.components.requestEjectBlock(componentToEject?._id)}
+ okText="Eject block"
+/>
diff --git a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/_components/navigation/ComponentListPanel.svelte b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/_components/navigation/ComponentListPanel.svelte
index 86b71b9785..71d0b9ae52 100644
--- a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/_components/navigation/ComponentListPanel.svelte
+++ b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/_components/navigation/ComponentListPanel.svelte
@@ -2,119 +2,15 @@
import Panel from "components/design/Panel.svelte"
import ComponentTree from "./ComponentTree.svelte"
import { dndStore } from "./dndStore.js"
- import { goto, isActive } from "@roxi/routify"
- import { store, selectedScreen, selectedComponent } from "builderStore"
+ import { goto } from "@roxi/routify"
+ import { store, selectedScreen } from "builderStore"
import NavItem from "components/common/NavItem.svelte"
import ScreenslotDropdownMenu from "./ScreenslotDropdownMenu.svelte"
- import { setContext, onMount } from "svelte"
import DNDPositionIndicator from "./DNDPositionIndicator.svelte"
import { DropPosition } from "./dndStore"
- import ConfirmDialog from "components/common/ConfirmDialog.svelte"
import { notifications, Button } from "@budibase/bbui"
- import { findComponent } from "builderStore/componentUtils"
-
- let scrollRef
- let confirmDeleteDialog
- let confirmEjectDialog
- let componentToDelete
- let componentToEject
-
- const keyHandlers = {
- ["^ArrowUp"]: async component => {
- await store.actions.components.moveUp(component)
- },
- ["^ArrowDown"]: async component => {
- await store.actions.components.moveDown(component)
- },
- ["^c"]: component => {
- store.actions.components.copy(component, false)
- },
- ["^x"]: component => {
- store.actions.components.copy(component, true)
- },
- ["^v"]: async component => {
- await store.actions.components.paste(component, "inside")
- },
- ["^d"]: async component => {
- store.actions.components.copy(component)
- await store.actions.components.paste(component, "below")
- },
- ["^e"]: component => {
- componentToEject = component
- confirmEjectDialog.show()
- },
- ["^Enter"]: () => {
- $goto("./new")
- },
- ["Delete"]: component => {
- // Don't show confirmation for the screen itself
- if (component?._id === $selectedScreen.props._id) {
- return false
- }
- componentToDelete = component
- confirmDeleteDialog.show()
- },
- ["ArrowUp"]: () => {
- store.actions.components.selectPrevious()
- },
- ["ArrowDown"]: () => {
- store.actions.components.selectNext()
- },
- ["Escape"]: () => {
- if (!$isActive("/new")) {
- return false
- }
- $goto("./")
- },
- }
-
- const scrollTo = bounds => {
- if (!bounds) {
- return
- }
- const sidebarWidth = 259
- const navItemHeight = 32
- const { scrollLeft, scrollTop, offsetHeight } = scrollRef
- let scrollBounds = scrollRef.getBoundingClientRect()
- let newOffsets = {}
-
- // Calculate left offset
- const offsetX = bounds.left + bounds.width + scrollLeft - 36
- if (offsetX > sidebarWidth) {
- newOffsets.left = offsetX - sidebarWidth
- } else {
- newOffsets.left = 0
- }
- if (newOffsets.left === scrollLeft) {
- delete newOffsets.left
- }
-
- // Calculate top offset
- const offsetY = bounds.top - scrollBounds?.top + scrollTop
- if (offsetY > scrollTop + offsetHeight - 2 * navItemHeight) {
- newOffsets.top = offsetY - offsetHeight + 2 * navItemHeight
- } else if (offsetY < scrollTop + navItemHeight) {
- newOffsets.top = offsetY - navItemHeight
- } else {
- delete newOffsets.top
- }
-
- // Skip if offset is unchanged
- if (newOffsets.left == null && newOffsets.top == null) {
- return
- }
-
- // Smoothly scroll to the offset
- scrollRef.scroll({
- ...newOffsets,
- behavior: "smooth",
- })
- }
-
- // Set scroll context so components can invoke scrolling when selected
- setContext("scroll", {
- scrollTo,
- })
+ import ComponentKeyHandler from "./ComponentKeyHandler.svelte"
+ import ComponentScrollWrapper from "./ComponentScrollWrapper.svelte"
const onDrop = async () => {
try {
@@ -124,74 +20,15 @@
notifications.error("Error saving component")
}
}
-
- const handleKeyAction = async (component, key, ctrlKey = false) => {
- if (!component || !key) {
- return false
- }
- try {
- // Delete and backspace are the same
- if (key === "Backspace") {
- key = "Delete"
- }
- // Prefix key with a caret for ctrl modifier
- if (ctrlKey) {
- key = "^" + key
- }
- const handler = keyHandlers[key]
- if (!handler) {
- return false
- }
- return handler(component)
- } catch (error) {
- console.log(error)
- notifications.error("Error handling key press")
- }
- }
-
- const handleKeyPress = async e => {
- // Ignore repeating events
- if (e.repeat) {
- return
- }
- // Ignore events when typing
- const activeTag = document.activeElement?.tagName.toLowerCase()
- if (["input", "textarea"].indexOf(activeTag) !== -1 && e.key !== "Escape") {
- return
- }
- // Key events are always for the selected component
- return handleKeyAction($selectedComponent, e.key, e.ctrlKey || e.metaKey)
- }
-
- const handleComponentMenu = async e => {
- // Menu events can be for any component
- const { id, key, ctrlKey } = e.detail
- const component = findComponent($selectedScreen.props, id)
- return await handleKeyAction(component, key, ctrlKey)
- }
-
- onMount(() => {
- document.addEventListener("keydown", handleKeyPress)
- document.addEventListener("component-menu", handleComponentMenu)
- return () => {
- document.removeEventListener("keydown", handleKeyPress)
- document.removeEventListener("component-menu", handleComponentMenu)
- }
- })
-
+
- - {
- $store.selectedComponentId = $selectedScreen?.props._id
- }}
- id={`component-${$selectedScreen?.props._id}`}
- >
+
-
{
+ $store.selectedComponentId = $selectedScreen?.props._id
+ }}
+ id={`component-${$selectedScreen?.props._id}`}
>
@@ -223,22 +64,9 @@
{/if}
-
+
- store.actions.components.delete(componentToDelete)}
-/>
- store.actions.components.requestEjectBlock(componentToEject?._id)}
- okText="Eject block"
-/>
+
diff --git a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/_components/settings/ComponentSettingsSection.svelte b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/_components/settings/ComponentSettingsSection.svelte
index 903ff3acdf..c561efda0c 100644
--- a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/_components/settings/ComponentSettingsSection.svelte
+++ b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/components/[componentId]/_components/settings/ComponentSettingsSection.svelte
@@ -126,7 +126,7 @@
{/if}
{#if idx === 0 && componentDefinition?.block}
-
+
{/if}
{/each}