akanjs 3.3.0-rc.44 → 3.3.0-rc.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akanjs",
3
- "version": "3.3.0-rc.44",
3
+ "version": "3.3.0-rc.45",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -1,3 +1,4 @@
1
1
  type DragAxis = "x" | "y";
2
+ export declare const SWIPE_BACK_EDGE_PX = 24;
2
3
  export declare const scrollerTakesDrag: (target: EventTarget | null, frame: Element | null, axis: DragAxis, movement: number) => boolean;
3
4
  export {};
package/ui/DragAction.tsx CHANGED
@@ -5,6 +5,7 @@ import type { ReactDOMAttributes } from "@use-gesture/react/dist/declarations/sr
5
5
  import { cn } from "akanjs/client";
6
6
  import { type ReactNode, useContext, useRef } from "react";
7
7
  import { sharedContext } from "../client/sharedContext";
8
+ import { SWIPE_BACK_EDGE_PX } from "../webkit/scrollerTakesDrag";
8
9
  import { animated } from "./animated";
9
10
 
10
11
  interface DragActionContextType {
@@ -53,8 +54,12 @@ export const DragAction = ({ className, children, onClick, onLeft, onRight }: Dr
53
54
  if (!action.current) onClick?.();
54
55
  action.current = null;
55
56
  },
56
- onDrag: ({ down, movement: [mx], event }) => {
57
+ onDrag: ({ down, movement: [mx], initial: [ix], cancel }) => {
57
58
  if (!ref.current) return;
59
+ if (ix <= SWIPE_BACK_EDGE_PX) {
60
+ cancel();
61
+ return;
62
+ }
58
63
  void api.start({
59
64
  x: down ? mx : 0,
60
65
  leftOpacity: mx > 0 && down ? mx / ref.current.clientWidth : 0,
@@ -64,8 +69,8 @@ export const DragAction = ({ className, children, onClick, onLeft, onRight }: Dr
64
69
  });
65
70
  action.current = mx > 0 ? "left" : mx < 0 ? "right" : null;
66
71
  },
67
- onDragEnd: ({ movement: [mx] }) => {
68
- if (!ref.current) return;
72
+ onDragEnd: ({ movement: [mx], initial: [ix] }) => {
73
+ if (!ref.current || ix <= SWIPE_BACK_EDGE_PX) return;
69
74
  void api.start({ x: 0, leftOpacity: 0, leftWidth: 0, rightOpacity: 0, rightWidth: 0 });
70
75
  if (mx > ref.current.clientWidth / 2 && onLeft) onLeft();
71
76
  if (mx < -ref.current.clientWidth / 2 && onRight) onRight();
@@ -75,7 +80,7 @@ export const DragAction = ({ className, children, onClick, onLeft, onRight }: Dr
75
80
  );
76
81
  return (
77
82
  <DragActionContext.Provider value={{ bind, x, y, leftOpacity, leftWidth, rightOpacity, rightWidth, onClick }}>
78
- <div ref={ref} className={cn("relative overflow-x-hidden", className)}>
83
+ <div ref={ref} data-akan-drag="x" className={cn("relative overflow-x-hidden", className)}>
79
84
  {children}
80
85
  </div>
81
86
  </DragActionContext.Provider>
@@ -1,5 +1,7 @@
1
1
  type DragAxis = "x" | "y";
2
2
 
3
+ export const SWIPE_BACK_EDGE_PX = 24;
4
+
3
5
  const isScrollable = (overflow: string) => overflow === "auto" || overflow === "scroll";
4
6
 
5
7
  const isReversed = (style: CSSStyleDeclaration, axis: DragAxis) =>
@@ -8,6 +10,7 @@ const isReversed = (style: CSSStyleDeclaration, axis: DragAxis) =>
8
10
  : (style.flexDirection === "row-reverse") !== (style.direction === "rtl");
9
11
 
10
12
  const takes = (node: Element, style: CSSStyleDeclaration, axis: DragAxis, movement: number) => {
13
+ if (node.getAttribute("data-akan-drag") === axis) return true;
11
14
  if (!isScrollable(axis === "x" ? style.overflowX : style.overflowY)) return false;
12
15
  const span = axis === "x" ? node.scrollWidth - node.clientWidth : node.scrollHeight - node.clientHeight;
13
16
  if (span < 1) return false;
@@ -14,7 +14,7 @@ import { clamp } from "akanjs/common";
14
14
  import { type RefObject, useCallback, useEffect, useLayoutEffect, useMemo, useRef } from "react";
15
15
  import { CsrSlide, type CsrSlideFrame } from "./csrSlide";
16
16
  import { isDragLift } from "./isDragLift";
17
- import { scrollerTakesDrag } from "./scrollerTakesDrag";
17
+ import { SWIPE_BACK_EDGE_PX, scrollerTakesDrag } from "./scrollerTakesDrag";
18
18
  import { STACK_TRANSITION_DURATION_MS } from "./useFrameRuntime";
19
19
 
20
20
  const linearEasing = (t: number) => t;
@@ -486,7 +486,8 @@ const useStackTrans = (routeState: RouteState): UseCsrTransition => {
486
486
  const absY = Math.abs(my);
487
487
  const isVertical = absY >= GESTURE_INTENT_THRESHOLD && absY > absX * GESTURE_AXIS_LOCK_RATIO;
488
488
  const isHorizontal = absX >= GESTURE_INTENT_THRESHOLD && absX > absY * GESTURE_AXIS_LOCK_RATIO;
489
- if (isVertical || (isHorizontal && scrollerTakesDrag(target, pageContentRef.current, "x", mx))) {
489
+ const yields = ix > SWIPE_BACK_EDGE_PX && scrollerTakesDrag(target, pageContentRef.current, "x", mx);
490
+ if (isVertical || (isHorizontal && yields)) {
490
491
  gestureIntent.current = "scroll";
491
492
  void transUnit.start(transUnitRange[1], { immediate: true });
492
493
  cancel();