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: introduce distance threshold before scrub begins to avoid accidental scrub when user clicks (#3139)
Oleg Isonen303fe25bf1c8
diff --git a/apps/builder/app/builder/features/workspace/canvas-tools/resize-handles.tsx b/apps/builder/app/builder/features/workspace/canvas-tools/resize-handles.tsxindex f7ac58cc36..010ea9588f 100644--- a/apps/builder/app/builder/features/workspace/canvas-tools/resize-handles.tsx+++ b/apps/builder/app/builder/features/workspace/canvas-tools/resize-handles.tsx@@ -105,7 +105,7 @@ const useScrub = ({ side }: { side: "right" | "left" }) => {const disposeScrubControl = numericScrubControl(ref.current, {getInitialValue() {- return $canvasWidth.get();+ return $canvasWidth.get() ?? 0;},getValue(state, movement) {const value =diff --git a/packages/design-system/src/components/primitives/numeric-gesture-control.ts b/packages/design-system/src/components/primitives/numeric-gesture-control.tsindex fc193ffffb..f24e9c31a3 100644--- a/packages/design-system/src/components/primitives/numeric-gesture-control.ts+++ b/packages/design-system/src/components/primitives/numeric-gesture-control.ts@@ -31,7 +31,8 @@ export type NumericScrubOptions = {getAcceleration?: () => number | undefined;minValue?: NumericScrubValue;maxValue?: NumericScrubValue;- getInitialValue: () => number | undefined;+ distanceThreshold?: number;+ getInitialValue: () => number;onStart?: () => void;getValue?: (state: NumericScrubState,@@ -77,6 +78,7 @@ export const numericScrubControl = (onStart,getValue = getValueDefault,direction = "horizontal",+ distanceThreshold = 3,onValueInput,onValueChange,onStatusChange,@@ -87,7 +89,7 @@ export const numericScrubControl = (// We will read value lazyly in a moment it will be used to avoid having outdated valuevalue: -1,cursor: undefined,- direction: direction,+ direction,timerId: undefined,status: "idle",};@@ -105,7 +107,6 @@ export const numericScrubControl = (}clearTimeout(state.timerId);-exitPointerLock?.();exitPointerLock = undefined;if (originalUserSelect) {@@ -132,7 +133,8 @@ export const numericScrubControl = (switch (type) {case "pointerup": {- const shouldComponentUpdate = Boolean(state.cursor);+ const shouldComponentUpdate =+ Boolean(state.cursor) && state.status === "scrubbing";cleanup();if (shouldComponentUpdate) {onValueChange?.({@@ -154,28 +156,14 @@ export const numericScrubControl = (if (event.pressure === 0 || event.button !== 0) {break;}- const value = getInitialValue();-- // We don't support scrub on non unit values- // Its highly unlikely that the value here will be undefined, as useScrub tries to not create scrub on non unit values- // but having that we use lazy getInitialValue() and vanilla js events it's possible.- if (value === undefined) {- return;- }onStart?.();-- state.value = value;-+ state.value = getInitialValue();state.timerId = setTimeout(() => {exitPointerLock?.();-exitPointerLock = requestPointerLock(state, event, targetNode);}, 150);- state.status = "scrubbing";- onStatusChange?.("scrubbing");-targetNode.addEventListener("pointermove", handleEvent);originalUserSelect =targetNode.ownerDocument.documentElement.style.userSelect;@@ -188,6 +176,19 @@ export const numericScrubControl = (break;}state.value = nextValue;++ if (state.status !== "scrubbing") {+ const initialValue = getInitialValue();+ // If the value is not changing enough, we don't want to start scrubbing.+ if (Math.abs(initialValue - nextValue) < distanceThreshold) {+ return;+ }+ // We need to reset the value to the initial so that the actual value starts from the initial value+ // when we start calling onValueInput.+ state.value = initialValue;+ state.status = "scrubbing";+ onStatusChange?.("scrubbing");+ }onValueInput?.({target: targetNode,value: state.value,