Fix scrolling to component
This commit is contained in:
parent
d0b2c08a9a
commit
1348fbb917
|
@ -25,14 +25,16 @@
|
||||||
export let wide
|
export let wide
|
||||||
|
|
||||||
let highlightType
|
let highlightType
|
||||||
|
let domElement
|
||||||
|
|
||||||
$: highlightedProp = $builderStore.highlightedSetting
|
$: highlightedProp = $builderStore.highlightedSetting
|
||||||
$: allBindings = getAllBindings(bindings, componentBindings, nested)
|
$: allBindings = getAllBindings(bindings, componentBindings, nested)
|
||||||
$: safeValue = getSafeValue(value, defaultValue, allBindings)
|
$: safeValue = getSafeValue(value, defaultValue, allBindings)
|
||||||
$: replaceBindings = val => readableToRuntimeBinding(allBindings, val)
|
$: replaceBindings = val => readableToRuntimeBinding(allBindings, val)
|
||||||
|
|
||||||
$: highlightType =
|
$: isHighlighted = highlightedProp?.key === key
|
||||||
highlightedProp?.key === key ? `highlighted-${highlightedProp?.type}` : ""
|
|
||||||
|
$: highlightType = isHighlighted ? `highlighted-${highlightedProp?.type}` : ""
|
||||||
|
|
||||||
const getAllBindings = (bindings, componentBindings, nested) => {
|
const getAllBindings = (bindings, componentBindings, nested) => {
|
||||||
if (!nested) {
|
if (!nested) {
|
||||||
|
@ -72,9 +74,19 @@
|
||||||
? defaultValue
|
? defaultValue
|
||||||
: enriched
|
: enriched
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function scrollToElement(element) {
|
||||||
|
element?.scrollIntoView({
|
||||||
|
behavior: "smooth",
|
||||||
|
block: "center",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
$: isHighlighted && scrollToElement(domElement)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
bind:this={domElement}
|
||||||
id={`${key}-prop-control-wrap`}
|
id={`${key}-prop-control-wrap`}
|
||||||
class={`property-control ${highlightType}`}
|
class={`property-control ${highlightType}`}
|
||||||
class:wide={!label || labelHidden || wide === true}
|
class:wide={!label || labelHidden || wide === true}
|
||||||
|
|
|
@ -183,16 +183,6 @@
|
||||||
toggleAddComponent()
|
toggleAddComponent()
|
||||||
} else if (type === "highlight-setting") {
|
} else if (type === "highlight-setting") {
|
||||||
builderStore.highlightSetting(data.setting, "error")
|
builderStore.highlightSetting(data.setting, "error")
|
||||||
|
|
||||||
// Also scroll setting into view
|
|
||||||
const selector = `#${data.setting}-prop-control`
|
|
||||||
const element = document.querySelector(selector)?.parentElement
|
|
||||||
if (element) {
|
|
||||||
element.scrollIntoView({
|
|
||||||
behavior: "smooth",
|
|
||||||
block: "center",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} else if (type === "eject-block") {
|
} else if (type === "eject-block") {
|
||||||
const { id, definition } = data
|
const { id, definition } = data
|
||||||
await componentStore.handleEjectBlock(id, definition)
|
await componentStore.handleEjectBlock(id, definition)
|
||||||
|
|
|
@ -28,20 +28,10 @@
|
||||||
return titleParts.join(" - ")
|
return titleParts.join(" - ")
|
||||||
}
|
}
|
||||||
|
|
||||||
function onErrorClick(error: UIComponentError) {
|
async function onErrorClick(error: UIComponentError) {
|
||||||
componentStore.select(error.componentId)
|
componentStore.select(error.componentId)
|
||||||
if (error.errorType === "setting") {
|
if (error.errorType === "setting") {
|
||||||
builderStore.highlightSetting(error.key, "error")
|
builderStore.highlightSetting(error.key, "error")
|
||||||
|
|
||||||
// TODO: dry from AppPreview
|
|
||||||
const selector = `#${error.key}-prop-control`
|
|
||||||
const element = document.querySelector(selector)?.parentElement
|
|
||||||
if (element) {
|
|
||||||
element.scrollIntoView({
|
|
||||||
behavior: "smooth",
|
|
||||||
block: "center",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue