MCPcopy Create free account
hub / github.com/TanStack/devtools / Trigger

Function Trigger

packages/devtools/src/components/trigger.tsx:8–50  ·  view source on GitHub ↗
(props: {
  isOpen: Accessor<boolean>
  setIsOpen: (isOpen: boolean) => void
})

Source from the content-addressed store, hash-verified

6 onCleanup,
7 untrack,
8} from 'solid-js'
9import clsx from 'clsx'
10import { createDevtoolsSettings } from '../context/use-devtools-context'
11import { createStyles } from '../styles/use-styles'
12import { TanStackTriggerMark } from './tanstack-trigger-mark'
13import type { TriggerCoords } from '../context/devtools-store'
14import type { Accessor } from 'solid-js'
15
16// --- Throw physics (pure, unit-tested in trigger.test.tsx) ---
17const FRICTION = 0.95 // velocity retained each frame
18const RESTITUTION = 0.5 // velocity retained after a wall bounce
19const MIN_SPEED = 0.1 // px/frame below which the throw stops
20const DRAG_THRESHOLD = 4 // px of movement before a press counts as a drag
21const PADDING_RATIO = 0.5 // matches size[2] = --tsrd-font-size * 0.5
22
23export const clamp = (value: number, min: number, max: number) =>
24 Math.max(min, Math.min(max, value))
25
26/**
27 * Advance one axis by its velocity for a single frame, bouncing off the
28 * [min, max] walls with damping. Returns the new position and velocity.
29 */
30export const stepAxis = (
31 pos: number,
32 vel: number,
33 min: number,
34 max: number,
35): { pos: number; vel: number } => {
36 let p = pos + vel
37 let v = vel * FRICTION
38 if (p <= min) {
39 p = min
40 v = -v * RESTITUTION
41 } else if (p >= max) {
42 p = max
43 v = -v * RESTITUTION
44 }
45 return { pos: p, vel: v }
46}
47
48export const Trigger = (props: {
49 isOpen: Accessor<boolean>
50 setIsOpen: (isOpen: boolean) => void
51}) => {
52 const { settings, setSettings } = createDevtoolsSettings()
53 const [containerRef, setContainerRef] = createSignal<HTMLElement>()

Callers 1

convertTriggerFunction · 0.85

Calls 3

createDevtoolsSettingsFunction · 0.90
createStylesFunction · 0.90
isOpenMethod · 0.80

Tested by

no test coverage detected