Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
fix: Scroll to display contents elements. (#4519)
Ivan Starkovdb2fcf1ebf87
diff --git a/apps/builder/app/builder/features/workspace/canvas-tools/outline/block-instance-outline.tsx b/apps/builder/app/builder/features/workspace/canvas-tools/outline/block-instance-outline.tsxindex 9c4eafb10c..5164d5f653 100644--- a/apps/builder/app/builder/features/workspace/canvas-tools/outline/block-instance-outline.tsx+++ b/apps/builder/app/builder/features/workspace/canvas-tools/outline/block-instance-outline.tsx@@ -53,6 +53,7 @@ import {import { shallowEqual } from "shallow-equal";import { MetaIcon } from "~/builder/shared/meta-icon";import { skipInertHandlersAttribute } from "~/builder/shared/inert-handlers";+import { selectInstance } from "~/shared/awareness";export const findBlockSelector = (anchor: InstanceSelector,@@ -274,6 +275,8 @@ const TemplatesMenu = ({{ type: "id", value: newRootInstanceId },];insertInstanceChildrenMutable(data, children, target);++ selectInstance([newRootInstanceId, ...target.parentSelector]);});}}>diff --git a/apps/builder/app/canvas/instance-selected.ts b/apps/builder/app/canvas/instance-selected.tsindex b44508422f..6e4d51b6e1 100644--- a/apps/builder/app/canvas/instance-selected.ts+++ b/apps/builder/app/canvas/instance-selected.ts@@ -123,10 +123,29 @@ const subscribeSelectedInstance = (selectedInstanceSelector);- visibleElements[0]?.scrollIntoView({- behavior: "smooth",- block: "nearest",- });+ const updateScroll = () => {+ const bbox = getAllElementsBoundingBox(visibleElements);++ // Adds a small amount of space around the element after scrolling+ const topScrollMargin = 16;++ if (bbox.top < 0 || bbox.bottom > window.innerHeight) {+ const moveToTopDelta = bbox.top - topScrollMargin;+ const moveToBottomDelta =+ bbox.bottom - window.innerHeight + topScrollMargin;++ // scrollTo is used because scrollIntoView does not work with elements that have display:contents, etc.+ // Here, we can be confident that if the outline can be calculated, we can scroll to it.+ window.scrollTo({+ top:+ window.scrollY ++ (Math.abs(moveToTopDelta) < Math.abs(moveToBottomDelta)+ ? moveToTopDelta+ : moveToBottomDelta),+ behavior: "smooth",+ });+ }+ };const updateElements = () => {visibleElements = getVisibleElementsByInstanceSelector(@@ -236,6 +255,9 @@ const subscribeSelectedInstance = (// Having that elements can be changed (i.e. div => address tag change, observe again)updateObservers();++ // update scroll state+ updateScroll();});};