Allow form block fields to be clicked from within the preview
This commit is contained in:
parent
02fb5f3865
commit
291ecd45fe
|
@ -0,0 +1,13 @@
|
||||||
|
let subscribers = []
|
||||||
|
|
||||||
|
export const onPreviewEvent = cb => {
|
||||||
|
subscribers.push(cb)
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
subscribers = subscribers.filter(callback => callback !== cb)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const emitPreviewEvent = event => {
|
||||||
|
subscribers.forEach(cb => cb(event))
|
||||||
|
}
|
|
@ -2,9 +2,10 @@
|
||||||
import { Icon, Popover, Layout } from "@budibase/bbui"
|
import { Icon, Popover, Layout } from "@budibase/bbui"
|
||||||
import { store } from "builderStore"
|
import { store } from "builderStore"
|
||||||
import { cloneDeep } from "lodash/fp"
|
import { cloneDeep } from "lodash/fp"
|
||||||
import { createEventDispatcher } from "svelte"
|
import { createEventDispatcher, onDestroy, onMount } from "svelte"
|
||||||
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"
|
||||||
import { getContext } from "svelte"
|
import { getContext } from "svelte"
|
||||||
|
import { onPreviewEvent } from "builderStore/previewEvents"
|
||||||
|
|
||||||
export let anchor
|
export let anchor
|
||||||
export let field
|
export let field
|
||||||
|
@ -61,6 +62,21 @@
|
||||||
|
|
||||||
dispatch("change", update)
|
dispatch("change", update)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handlePreviewEvent = event => {
|
||||||
|
const { type, data } = event?.data || {}
|
||||||
|
if (type === "click-form-block-field") {
|
||||||
|
if (data.field === field.field) {
|
||||||
|
popover.show()
|
||||||
|
open = true
|
||||||
|
} else {
|
||||||
|
popover.hide()
|
||||||
|
open = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(() => onPreviewEvent(handlePreviewEvent))
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Icon
|
<Icon
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
import ErrorSVG from "@budibase/frontend-core/assets/error.svg?raw"
|
import ErrorSVG from "@budibase/frontend-core/assets/error.svg?raw"
|
||||||
import { findComponent, findComponentPath } from "builderStore/componentUtils"
|
import { findComponent, findComponentPath } from "builderStore/componentUtils"
|
||||||
import { isActive, goto } from "@roxi/routify"
|
import { isActive, goto } from "@roxi/routify"
|
||||||
|
import { emitPreviewEvent } from "builderStore/previewEvents"
|
||||||
|
|
||||||
let iframe
|
let iframe
|
||||||
let layout
|
let layout
|
||||||
|
@ -36,12 +37,14 @@
|
||||||
|
|
||||||
// Determine selected component ID
|
// Determine selected component ID
|
||||||
$: selectedComponentId = $store.selectedComponentId
|
$: selectedComponentId = $store.selectedComponentId
|
||||||
|
$: selectedBlockComponentId = $store.selectedBlockComponentId
|
||||||
|
|
||||||
$: previewData = {
|
$: previewData = {
|
||||||
appId: $store.appId,
|
appId: $store.appId,
|
||||||
layout,
|
layout,
|
||||||
screen,
|
screen,
|
||||||
selectedComponentId,
|
selectedComponentId,
|
||||||
|
selectedBlockComponentId,
|
||||||
theme: $store.theme,
|
theme: $store.theme,
|
||||||
customTheme: $store.customTheme,
|
customTheme: $store.customTheme,
|
||||||
previewDevice: $store.previewDevice,
|
previewDevice: $store.previewDevice,
|
||||||
|
@ -93,6 +96,7 @@
|
||||||
// Await the event handler
|
// Await the event handler
|
||||||
try {
|
try {
|
||||||
await handleBudibaseEvent(message)
|
await handleBudibaseEvent(message)
|
||||||
|
emitPreviewEvent(message)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
notifications.error(error || "Error handling event from app preview")
|
notifications.error(error || "Error handling event from app preview")
|
||||||
}
|
}
|
||||||
|
@ -181,6 +185,8 @@
|
||||||
} else if (type === "add-parent-component") {
|
} else if (type === "add-parent-component") {
|
||||||
const { componentId, parentType } = data
|
const { componentId, parentType } = data
|
||||||
await store.actions.components.addParent(componentId, parentType)
|
await store.actions.components.addParent(componentId, parentType)
|
||||||
|
} else if (type === "click-form-block-field") {
|
||||||
|
// Swallow and let this be handled by form block settings
|
||||||
} else {
|
} else {
|
||||||
console.warn(`Client sent unknown event type: ${type}`)
|
console.warn(`Client sent unknown event type: ${type}`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
export let name
|
export let name
|
||||||
export let order = 0
|
export let order = 0
|
||||||
export let containsSlot = false
|
export let containsSlot = false
|
||||||
|
export let onClick = null
|
||||||
|
|
||||||
// ID is only exposed as a prop so that it can be bound to from parent
|
// ID is only exposed as a prop so that it can be bound to from parent
|
||||||
// block components
|
// block components
|
||||||
|
@ -26,15 +27,15 @@
|
||||||
$: parentId = $component?.id
|
$: parentId = $component?.id
|
||||||
$: inBuilder = $builderStore.inBuilder
|
$: inBuilder = $builderStore.inBuilder
|
||||||
$: instance = {
|
$: instance = {
|
||||||
|
...props,
|
||||||
_component: getComponent(type),
|
_component: getComponent(type),
|
||||||
_id: id,
|
_id: id,
|
||||||
_instanceName: getInstanceName(name, type),
|
_instanceName: getInstanceName(name, type),
|
||||||
|
_containsSlot: containsSlot,
|
||||||
_styles: {
|
_styles: {
|
||||||
...styles,
|
...styles,
|
||||||
normal: styles?.normal || {},
|
normal: styles?.normal || {},
|
||||||
},
|
},
|
||||||
_containsSlot: containsSlot,
|
|
||||||
...props,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register this block component if we're inside the builder so it can be
|
// Register this block component if we're inside the builder so it can be
|
||||||
|
@ -76,6 +77,6 @@
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Component {instance} isBlock>
|
<Component {instance} isBlock {onClick}>
|
||||||
<slot />
|
<slot />
|
||||||
</Component>
|
</Component>
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
export let isLayout = false
|
export let isLayout = false
|
||||||
export let isRoot = false
|
export let isRoot = false
|
||||||
export let isBlock = false
|
export let isBlock = false
|
||||||
|
export let onClick = null
|
||||||
|
|
||||||
// Get parent contexts
|
// Get parent contexts
|
||||||
const context = getContext("context")
|
const context = getContext("context")
|
||||||
|
@ -131,7 +132,10 @@
|
||||||
// Interactive components can be selected, dragged and highlighted inside
|
// Interactive components can be selected, dragged and highlighted inside
|
||||||
// the builder preview
|
// the builder preview
|
||||||
$: builderInteractive =
|
$: builderInteractive =
|
||||||
$builderStore.inBuilder && insideScreenslot && !isBlock && !instance.static
|
$builderStore.inBuilder &&
|
||||||
|
insideScreenslot &&
|
||||||
|
(!isBlock || onClick) &&
|
||||||
|
!instance.static
|
||||||
$: devToolsInteractive = $devToolsStore.allowSelection && !isBlock
|
$: devToolsInteractive = $devToolsStore.allowSelection && !isBlock
|
||||||
$: interactive = !isRoot && (builderInteractive || devToolsInteractive)
|
$: interactive = !isRoot && (builderInteractive || devToolsInteractive)
|
||||||
$: editing = editable && selected && $builderStore.editMode
|
$: editing = editable && selected && $builderStore.editMode
|
||||||
|
@ -194,6 +198,8 @@
|
||||||
interactive,
|
interactive,
|
||||||
draggable,
|
draggable,
|
||||||
editable,
|
editable,
|
||||||
|
isBlock,
|
||||||
|
onClick,
|
||||||
},
|
},
|
||||||
empty: emptyState,
|
empty: emptyState,
|
||||||
selected,
|
selected,
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
bb_reference: "bbreferencefield",
|
bb_reference: "bbreferencefield",
|
||||||
}
|
}
|
||||||
const context = getContext("context")
|
const context = getContext("context")
|
||||||
|
const { builderStore } = getContext("sdk")
|
||||||
|
|
||||||
let formId
|
let formId
|
||||||
|
|
||||||
|
@ -223,6 +224,11 @@
|
||||||
type={getComponentForField(field)}
|
type={getComponentForField(field)}
|
||||||
props={getPropsForField(field)}
|
props={getPropsForField(field)}
|
||||||
order={idx}
|
order={idx}
|
||||||
|
interactive
|
||||||
|
name={field?.field}
|
||||||
|
onClick={() => {
|
||||||
|
builderStore.actions.clickFormBlockField(field?.field)
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
|
|
|
@ -31,6 +31,8 @@ const loadBudibase = async () => {
|
||||||
layout: window["##BUDIBASE_PREVIEW_LAYOUT##"],
|
layout: window["##BUDIBASE_PREVIEW_LAYOUT##"],
|
||||||
screen: window["##BUDIBASE_PREVIEW_SCREEN##"],
|
screen: window["##BUDIBASE_PREVIEW_SCREEN##"],
|
||||||
selectedComponentId: window["##BUDIBASE_SELECTED_COMPONENT_ID##"],
|
selectedComponentId: window["##BUDIBASE_SELECTED_COMPONENT_ID##"],
|
||||||
|
selectedBlockComponentId:
|
||||||
|
window["##BUDIBASE_SELECTED_BLOCK_COMPONENT_ID##"],
|
||||||
previewId: window["##BUDIBASE_PREVIEW_ID##"],
|
previewId: window["##BUDIBASE_PREVIEW_ID##"],
|
||||||
theme: window["##BUDIBASE_PREVIEW_THEME##"],
|
theme: window["##BUDIBASE_PREVIEW_THEME##"],
|
||||||
customTheme: window["##BUDIBASE_PREVIEW_CUSTOM_THEME##"],
|
customTheme: window["##BUDIBASE_PREVIEW_CUSTOM_THEME##"],
|
||||||
|
|
|
@ -8,6 +8,7 @@ const createBuilderStore = () => {
|
||||||
inBuilder: false,
|
inBuilder: false,
|
||||||
screen: null,
|
screen: null,
|
||||||
selectedComponentId: null,
|
selectedComponentId: null,
|
||||||
|
selectedBlockComponentId: null,
|
||||||
editMode: false,
|
editMode: false,
|
||||||
previewId: null,
|
previewId: null,
|
||||||
theme: null,
|
theme: null,
|
||||||
|
@ -35,6 +36,9 @@ const createBuilderStore = () => {
|
||||||
devToolsStore.actions.setAllowSelection(false)
|
devToolsStore.actions.setAllowSelection(false)
|
||||||
eventStore.actions.dispatchEvent("select-component", { id })
|
eventStore.actions.dispatchEvent("select-component", { id })
|
||||||
},
|
},
|
||||||
|
clickFormBlockField: field => {
|
||||||
|
eventStore.actions.dispatchEvent("click-form-block-field", { field })
|
||||||
|
},
|
||||||
updateProp: (prop, value) => {
|
updateProp: (prop, value) => {
|
||||||
eventStore.actions.dispatchEvent("update-prop", { prop, value })
|
eventStore.actions.dispatchEvent("update-prop", { prop, value })
|
||||||
},
|
},
|
||||||
|
|
|
@ -40,6 +40,7 @@ export const styleable = (node, styles = {}) => {
|
||||||
|
|
||||||
const componentId = newStyles.id
|
const componentId = newStyles.id
|
||||||
const customStyles = newStyles.custom || ""
|
const customStyles = newStyles.custom || ""
|
||||||
|
const { isBlock, onClick } = newStyles
|
||||||
const normalStyles = { ...baseStyles, ...newStyles.normal }
|
const normalStyles = { ...baseStyles, ...newStyles.normal }
|
||||||
const hoverStyles = {
|
const hoverStyles = {
|
||||||
...normalStyles,
|
...normalStyles,
|
||||||
|
@ -67,7 +68,11 @@ export const styleable = (node, styles = {}) => {
|
||||||
// Handler to select a component in the builder when clicking it in the
|
// Handler to select a component in the builder when clicking it in the
|
||||||
// builder preview
|
// builder preview
|
||||||
selectComponent = event => {
|
selectComponent = event => {
|
||||||
builderStore.actions.selectComponent(componentId)
|
if (isBlock && onClick) {
|
||||||
|
onClick()
|
||||||
|
} else {
|
||||||
|
builderStore.actions.selectComponent(componentId, isBlock)
|
||||||
|
}
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
event.stopPropagation()
|
event.stopPropagation()
|
||||||
return false
|
return false
|
||||||
|
@ -76,6 +81,9 @@ export const styleable = (node, styles = {}) => {
|
||||||
// Handler to start editing a component (if applicable) when double
|
// Handler to start editing a component (if applicable) when double
|
||||||
// clicking in the builder preview
|
// clicking in the builder preview
|
||||||
editComponent = event => {
|
editComponent = event => {
|
||||||
|
if (isBlock) {
|
||||||
|
return
|
||||||
|
}
|
||||||
if (newStyles.interactive && newStyles.editable) {
|
if (newStyles.interactive && newStyles.editable) {
|
||||||
builderStore.actions.setEditMode(true)
|
builderStore.actions.setEditMode(true)
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,7 @@
|
||||||
// Extract data from message
|
// Extract data from message
|
||||||
const {
|
const {
|
||||||
selectedComponentId,
|
selectedComponentId,
|
||||||
|
selectedBlockComponentId,
|
||||||
layout,
|
layout,
|
||||||
screen,
|
screen,
|
||||||
appId,
|
appId,
|
||||||
|
@ -81,6 +82,7 @@
|
||||||
window["##BUDIBASE_PREVIEW_LAYOUT##"] = layout
|
window["##BUDIBASE_PREVIEW_LAYOUT##"] = layout
|
||||||
window["##BUDIBASE_PREVIEW_SCREEN##"] = screen
|
window["##BUDIBASE_PREVIEW_SCREEN##"] = screen
|
||||||
window["##BUDIBASE_SELECTED_COMPONENT_ID##"] = selectedComponentId
|
window["##BUDIBASE_SELECTED_COMPONENT_ID##"] = selectedComponentId
|
||||||
|
window["##BUDIBASE_SELECTED_BLOCK_COMPONENT_ID##"] = selectedBlockComponentId
|
||||||
window["##BUDIBASE_PREVIEW_ID##"] = Math.random()
|
window["##BUDIBASE_PREVIEW_ID##"] = Math.random()
|
||||||
window["##BUDIBASE_PREVIEW_THEME##"] = theme
|
window["##BUDIBASE_PREVIEW_THEME##"] = theme
|
||||||
window["##BUDIBASE_PREVIEW_CUSTOM_THEME##"] = customTheme
|
window["##BUDIBASE_PREVIEW_CUSTOM_THEME##"] = customTheme
|
||||||
|
|
Loading…
Reference in New Issue