chore: refactor packages/app files (#13236)
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Frank <frank@anoma.ly>
This commit is contained in:
@@ -9,6 +9,37 @@ import { SessionTurn } from "@opencode-ai/ui/session-turn"
|
||||
import type { UserMessage } from "@opencode-ai/sdk/v2"
|
||||
import { shouldMarkBoundaryGesture, normalizeWheelDelta } from "@/pages/session/message-gesture"
|
||||
|
||||
const boundaryTarget = (root: HTMLElement, target: EventTarget | null) => {
|
||||
const current = target instanceof Element ? target : undefined
|
||||
const nested = current?.closest("[data-scrollable]")
|
||||
if (!nested || nested === root) return root
|
||||
if (!(nested instanceof HTMLElement)) return root
|
||||
return nested
|
||||
}
|
||||
|
||||
const markBoundaryGesture = (input: {
|
||||
root: HTMLDivElement
|
||||
target: EventTarget | null
|
||||
delta: number
|
||||
onMarkScrollGesture: (target?: EventTarget | null) => void
|
||||
}) => {
|
||||
const target = boundaryTarget(input.root, input.target)
|
||||
if (target === input.root) {
|
||||
input.onMarkScrollGesture(input.root)
|
||||
return
|
||||
}
|
||||
if (
|
||||
shouldMarkBoundaryGesture({
|
||||
delta: input.delta,
|
||||
scrollTop: target.scrollTop,
|
||||
scrollHeight: target.scrollHeight,
|
||||
clientHeight: target.clientHeight,
|
||||
})
|
||||
) {
|
||||
input.onMarkScrollGesture(input.root)
|
||||
}
|
||||
}
|
||||
|
||||
export function MessageTimeline(props: {
|
||||
mobileChanges: boolean
|
||||
mobileFallback: JSX.Element
|
||||
@@ -86,35 +117,13 @@ export function MessageTimeline(props: {
|
||||
ref={props.setScrollRef}
|
||||
onWheel={(e) => {
|
||||
const root = e.currentTarget
|
||||
const target = e.target instanceof Element ? e.target : undefined
|
||||
const nested = target?.closest("[data-scrollable]")
|
||||
if (!nested || nested === root) {
|
||||
props.onMarkScrollGesture(root)
|
||||
return
|
||||
}
|
||||
|
||||
if (!(nested instanceof HTMLElement)) {
|
||||
props.onMarkScrollGesture(root)
|
||||
return
|
||||
}
|
||||
|
||||
const delta = normalizeWheelDelta({
|
||||
deltaY: e.deltaY,
|
||||
deltaMode: e.deltaMode,
|
||||
rootHeight: root.clientHeight,
|
||||
})
|
||||
if (!delta) return
|
||||
|
||||
if (
|
||||
shouldMarkBoundaryGesture({
|
||||
delta,
|
||||
scrollTop: nested.scrollTop,
|
||||
scrollHeight: nested.scrollHeight,
|
||||
clientHeight: nested.clientHeight,
|
||||
})
|
||||
) {
|
||||
props.onMarkScrollGesture(root)
|
||||
}
|
||||
markBoundaryGesture({ root, target: e.target, delta, onMarkScrollGesture: props.onMarkScrollGesture })
|
||||
}}
|
||||
onTouchStart={(e) => {
|
||||
touchGesture = e.touches[0]?.clientY
|
||||
@@ -129,28 +138,7 @@ export function MessageTimeline(props: {
|
||||
if (!delta) return
|
||||
|
||||
const root = e.currentTarget
|
||||
const target = e.target instanceof Element ? e.target : undefined
|
||||
const nested = target?.closest("[data-scrollable]")
|
||||
if (!nested || nested === root) {
|
||||
props.onMarkScrollGesture(root)
|
||||
return
|
||||
}
|
||||
|
||||
if (!(nested instanceof HTMLElement)) {
|
||||
props.onMarkScrollGesture(root)
|
||||
return
|
||||
}
|
||||
|
||||
if (
|
||||
shouldMarkBoundaryGesture({
|
||||
delta,
|
||||
scrollTop: nested.scrollTop,
|
||||
scrollHeight: nested.scrollHeight,
|
||||
clientHeight: nested.clientHeight,
|
||||
})
|
||||
) {
|
||||
props.onMarkScrollGesture(root)
|
||||
}
|
||||
markBoundaryGesture({ root, target: e.target, delta, onMarkScrollGesture: props.onMarkScrollGesture })
|
||||
}}
|
||||
onTouchEnd={() => {
|
||||
touchGesture = undefined
|
||||
|
||||
Reference in New Issue
Block a user