This commit is contained in:
Andrew Kingston 2024-05-03 11:47:54 +01:00
parent 40430e5155
commit 269aa41732
10 changed files with 43 additions and 63 deletions

View File

@ -1,5 +1,5 @@
<script> <script>
import EditComponentPopover from "../EditComponentPopover/EditComponentPopover.svelte" import EditComponentPopover from "../EditComponentPopover.svelte"
import { Icon } from "@budibase/bbui" import { Icon } from "@budibase/bbui"
import { runtimeToReadableBinding } from "dataBinding" import { runtimeToReadableBinding } from "dataBinding"
import { isJSBinding } from "@budibase/string-templates" import { isJSBinding } from "@budibase/string-templates"

View File

@ -100,9 +100,6 @@
on:click={() => { on:click={() => {
get(store).actions.select(draggableItem.id) get(store).actions.select(draggableItem.id)
}} }}
on:mousedown={() => {
get(store).actions.select()
}}
bind:this={anchors[draggableItem.id]} bind:this={anchors[draggableItem.id]}
class:highlighted={draggableItem.id === $store.selected} class:highlighted={draggableItem.id === $store.selected}
> >

View File

@ -3,7 +3,6 @@
import { componentStore } from "stores/builder" import { componentStore } from "stores/builder"
import { cloneDeep } from "lodash/fp" import { cloneDeep } from "lodash/fp"
import { createEventDispatcher, getContext } from "svelte" import { createEventDispatcher, getContext } from "svelte"
import { customPositionHandler } from "."
import ComponentSettingsSection from "pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Component/ComponentSettingsSection.svelte" import ComponentSettingsSection from "pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Component/ComponentSettingsSection.svelte"
export let anchor export let anchor
@ -18,76 +17,74 @@
let popover let popover
let drawers = [] let drawers = []
let open = false let isOpen = false
// Auto hide the component when another item is selected // Auto hide the component when another item is selected
$: if (open && $draggable.selected !== componentInstance._id) { $: if (open && $draggable.selected !== componentInstance._id) {
popover.hide() close()
} }
// Open automatically if the component is marked as selected // Open automatically if the component is marked as selected
$: if (!open && $draggable.selected === componentInstance._id && popover) { $: if (!open && $draggable.selected === componentInstance._id && popover) {
popover.show() open()
open = true
} }
$: componentDef = componentStore.getDefinition(componentInstance._component) $: componentDef = componentStore.getDefinition(componentInstance._component)
$: parsedComponentDef = processComponentDefinitionSettings(componentDef) $: parsedComponentDef = processComponentDefinitionSettings(componentDef)
const open = () => {
isOpen = true
drawers = []
$draggable.actions.select(componentInstance._id)
}
const close = () => {
// Slight delay allows us to be able to properly toggle open/close state by
// clicking again on the settings icon
setTimeout(() => {
isOpen = false
if ($draggable.selected === componentInstance._id) {
$draggable.actions.select()
}
}, 10)
}
const toggleOpen = () => {
if (isOpen) {
close()
} else {
open()
}
}
const processComponentDefinitionSettings = componentDef => { const processComponentDefinitionSettings = componentDef => {
if (!componentDef) { if (!componentDef) {
return {} return {}
} }
const clone = cloneDeep(componentDef) const clone = cloneDeep(componentDef)
if (typeof parseSettings === "function") { if (typeof parseSettings === "function") {
clone.settings = parseSettings(clone.settings) clone.settings = parseSettings(clone.settings)
} }
return clone return clone
} }
const updateSetting = async (setting, value) => { const updateSetting = async (setting, value) => {
const nestedComponentInstance = cloneDeep(componentInstance) const nestedComponentInstance = cloneDeep(componentInstance)
const patchFn = componentStore.updateComponentSetting(setting.key, value) const patchFn = componentStore.updateComponentSetting(setting.key, value)
patchFn(nestedComponentInstance) patchFn(nestedComponentInstance)
dispatch("change", nestedComponentInstance) dispatch("change", nestedComponentInstance)
} }
</script> </script>
<Icon <Icon name="Settings" hoverable size="S" on:click={toggleOpen} />
name="Settings"
hoverable
size="S"
on:click={() => {
if (!open) {
popover.show()
open = true
}
}}
/>
<Popover <Popover
bind:this={popover} open={isOpen}
on:open={() => { on:close={close}
drawers = []
$draggable.actions.select(componentInstance._id)
}}
on:close={() => {
open = false
if ($draggable.selected === componentInstance._id) {
$draggable.actions.select()
}
}}
{anchor} {anchor}
align="left-outside" align="left-outside"
showPopover={drawers.length === 0} showPopover={drawers.length === 0}
clickOutsideOverride={drawers.length > 0} clickOutsideOverride={drawers.length > 0}
maxHeight={600} maxHeight={600}
offset={18} offset={18}
handlePostionUpdate={customPositionHandler}
> >
<span class="popover-wrap"> <span class="popover-wrap">
<Layout noPadding noGap> <Layout noPadding noGap>

View File

@ -1,18 +0,0 @@
export const customPositionHandler = (anchorBounds, eleBounds, cfg) => {
let { left, top, offset } = cfg
let percentageOffset = 30
// left-outside
left = anchorBounds.left - eleBounds.width - (offset || 5)
// shift up from the anchor, if space allows
let offsetPos = Math.floor(eleBounds.height / 100) * percentageOffset
let defaultTop = anchorBounds.top - offsetPos
if (window.innerHeight - defaultTop < eleBounds.height) {
top = window.innerHeight - eleBounds.height - 5
} else {
top = anchorBounds.top - offsetPos
}
return { ...cfg, left, top }
}

View File

@ -1,5 +1,5 @@
<script> <script>
import EditComponentPopover from "../EditComponentPopover/EditComponentPopover.svelte" import EditComponentPopover from "../EditComponentPopover.svelte"
import { Toggle, Icon } from "@budibase/bbui" import { Toggle, Icon } from "@budibase/bbui"
import { createEventDispatcher } from "svelte" import { createEventDispatcher } from "svelte"
import { cloneDeep } from "lodash/fp" import { cloneDeep } from "lodash/fp"

View File

@ -1,5 +1,5 @@
<script> <script>
import EditComponentPopover from "../EditComponentPopover/EditComponentPopover.svelte" import EditComponentPopover from "../EditComponentPopover.svelte"
import { Toggle, Icon } from "@budibase/bbui" import { Toggle, Icon } from "@budibase/bbui"
import { createEventDispatcher } from "svelte" import { createEventDispatcher } from "svelte"
import { cloneDeep } from "lodash/fp" import { cloneDeep } from "lodash/fp"

View File

@ -1,5 +1,5 @@
<script> <script>
import EditComponentPopover from "../EditComponentPopover/EditComponentPopover.svelte" import EditComponentPopover from "../EditComponentPopover.svelte"
import { Icon } from "@budibase/bbui" import { Icon } from "@budibase/bbui"
import { setContext } from "svelte" import { setContext } from "svelte"
import { writable } from "svelte/store" import { writable } from "svelte/store"

View File

@ -67,6 +67,7 @@ const toGridFormat = draggableListColumns => {
label: entry.label, label: entry.label,
field: entry.field, field: entry.field,
active: entry.active, active: entry.active,
width: entry.width,
})) }))
} }
@ -81,6 +82,7 @@ const toDraggableListFormat = (gridFormatColumns, createComponent, schema) => {
field: column.field, field: column.field,
label: column.label, label: column.label,
columnType: schema[column.field].type, columnType: schema[column.field].type,
width: column.width,
}, },
{} {}
) )

View File

@ -10,7 +10,6 @@ import {
NewFormSteps, NewFormSteps,
} from "./steps" } from "./steps"
import { API } from "api" import { API } from "api"
import { customPositionHandler } from "components/design/settings/controls/EditComponentPopover"
const ONBOARDING_EVENT_PREFIX = "onboarding" const ONBOARDING_EVENT_PREFIX = "onboarding"
@ -187,7 +186,6 @@ const getTours = () => {
tourEvent(TOUR_STEP_KEYS.BUILDER_FORM_CREATE_STEPS) tourEvent(TOUR_STEP_KEYS.BUILDER_FORM_CREATE_STEPS)
builderStore.highlightSetting("steps", "info") builderStore.highlightSetting("steps", "info")
}, },
positionHandler: customPositionHandler,
align: "left-outside", align: "left-outside",
}, },
], ],
@ -203,7 +201,6 @@ const getTours = () => {
tourEvent(TOUR_STEP_KEYS.BUILDER_FORM_ROW_ID) tourEvent(TOUR_STEP_KEYS.BUILDER_FORM_ROW_ID)
builderStore.highlightSetting("rowId", "info") builderStore.highlightSetting("rowId", "info")
}, },
positionHandler: customPositionHandler,
align: "left-outside", align: "left-outside",
}, },
{ {
@ -219,7 +216,6 @@ const getTours = () => {
tourEvent(TOUR_STEP_KEYS.BUILDER_FORM_VIEW_UPDATE_STEPS) tourEvent(TOUR_STEP_KEYS.BUILDER_FORM_VIEW_UPDATE_STEPS)
builderStore.highlightSetting("steps", "info") builderStore.highlightSetting("steps", "info")
}, },
positionHandler: customPositionHandler,
align: "left-outside", align: "left-outside",
scrollIntoView: true, scrollIntoView: true,
}, },

View File

@ -2746,6 +2746,12 @@
"type": "plainText", "type": "plainText",
"label": "Label", "label": "Label",
"key": "label" "key": "label"
},
{
"type": "number",
"label": "Width",
"key": "width",
"placeholder": "Auto"
} }
] ]
}, },