@tremolo-ui/react 0.4.0 → 0.6.0
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/dist/compose-refs.cjs +72 -0
- package/dist/compose-refs.cjs.map +1 -0
- package/dist/compose-refs.d.cts +43 -0
- package/dist/compose-refs.d.cts.map +1 -0
- package/dist/compose-refs.d.ts +43 -0
- package/dist/compose-refs.d.ts.map +1 -0
- package/dist/compose-refs.js +70 -0
- package/dist/compose-refs.js.map +1 -0
- package/dist/index.cjs +2272 -1650
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1461 -475
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +1461 -475
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2258 -1648
- package/dist/index.js.map +1 -1
- package/package.json +32 -31
- package/src/components/AnimationCanvas/index.tsx +162 -194
- package/src/components/Knob/ActiveLine.tsx +9 -8
- package/src/components/Knob/InactiveLine.tsx +11 -14
- package/src/components/Knob/SVGRoot.tsx +10 -17
- package/src/components/Knob/Thumb.tsx +33 -11
- package/src/components/Knob/context.tsx +73 -89
- package/src/components/Knob/index.tsx +227 -105
- package/src/components/NumberInput/DecrementStepper.tsx +21 -50
- package/src/components/NumberInput/IncrementStepper.tsx +22 -50
- package/src/components/NumberInput/InputField.tsx +206 -0
- package/src/components/NumberInput/Stepper.tsx +150 -21
- package/src/components/NumberInput/StepperButton.tsx +95 -0
- package/src/components/NumberInput/context.tsx +104 -149
- package/src/components/NumberInput/index.tsx +461 -110
- package/src/components/Piano/index.tsx +413 -263
- package/src/components/Piano/keyboard-shortcuts.ts +61 -0
- package/src/components/PointsEditor/Background.tsx +19 -4
- package/src/components/PointsEditor/Container.tsx +92 -22
- package/src/components/PointsEditor/Point.tsx +293 -53
- package/src/components/PointsEditor/SelectionBox.tsx +54 -0
- package/src/components/PointsEditor/context.tsx +97 -75
- package/src/components/PointsEditor/index.tsx +497 -62
- package/src/components/Slider/Marks.tsx +84 -0
- package/src/components/Slider/MarksOption.tsx +115 -0
- package/src/components/Slider/Thumb.tsx +99 -54
- package/src/components/Slider/Track.tsx +73 -62
- package/src/components/Slider/context.tsx +40 -53
- package/src/components/Slider/index.tsx +237 -190
- package/src/components/Slider/type.ts +27 -9
- package/src/components/XYPad/Area.tsx +52 -33
- package/src/components/XYPad/Thumb.tsx +121 -60
- package/src/components/XYPad/context.tsx +49 -0
- package/src/components/XYPad/index.tsx +338 -246
- package/src/components/_util/Placement.tsx +68 -0
- package/src/components/_util/VisuallyHiddenRangeInput.tsx +24 -0
- package/src/components/_util/css-length.ts +13 -0
- package/src/{components/_util/composeRefs.tsx → compose-refs/index.tsx} +33 -5
- package/src/hooks/{useCallbackRef.ts → _internal/useCallbackRef.ts} +3 -1
- package/src/hooks/_internal/useCheckSteps.ts +170 -0
- package/src/hooks/useAnimationFrame.ts +17 -7
- package/src/hooks/useDrag.ts +39 -9
- package/src/hooks/useDragValue.ts +194 -0
- package/src/hooks/useEventListener.ts +11 -7
- package/src/hooks/useLongPress.ts +42 -8
- package/src/hooks/useMIDIAccess.ts +82 -11
- package/src/hooks/useMIDIInput.ts +45 -13
- package/src/hooks/useMIDIMessage.ts +23 -5
- package/src/hooks/useWheel.ts +29 -9
- package/src/index.ts +50 -27
- package/src/input-event.ts +32 -0
- package/dist/index.css +0 -536
- package/src/Globals.d.ts +0 -3
- package/src/components/AnimationCanvas/canvas.ts +0 -46
- package/src/components/Knob/index.css +0 -77
- package/src/components/NumberInput/InternalInput.tsx +0 -216
- package/src/components/NumberInput/index.css +0 -185
- package/src/components/NumberInput/type.ts +0 -58
- package/src/components/Piano/KeyLabel.tsx +0 -51
- package/src/components/Piano/context.tsx +0 -73
- package/src/components/Piano/index.css +0 -90
- package/src/components/Piano/key.tsx +0 -205
- package/src/components/Piano/keyboardShortcuts.ts +0 -31
- package/src/components/PointsEditor/index.css +0 -30
- package/src/components/Slider/Scale.tsx +0 -52
- package/src/components/Slider/ScaleOption.tsx +0 -103
- package/src/components/Slider/index.css +0 -112
- package/src/components/XYPad/index.css +0 -48
- package/src/components/_util/index.ts +0 -28
- package/src/components/_util/type.ts +0 -1
- package/src/hooks/useDragWithElement.ts +0 -100
- package/src/hooks/usePianoDrag.ts +0 -75
- package/src/hooks/useRefCallbackEvent.ts +0 -34
- package/src/styles/global.css +0 -19
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { useRef, useCallback, RefObject } from 'react'
|
|
2
|
-
|
|
3
|
-
import { normalizeValue } from '@tremolo-ui/functions'
|
|
4
|
-
|
|
5
|
-
import { useEventListener } from './useEventListener'
|
|
6
|
-
import { useRefCallbackEvent } from './useRefCallbackEvent'
|
|
7
|
-
|
|
8
|
-
interface UsePianoDrag<T extends Element> {
|
|
9
|
-
baseElementRef: RefObject<T | null>
|
|
10
|
-
onDrag: (normalizedX: number, normalizedY: number) => void
|
|
11
|
-
onDragStart?: (normalizedX: number, normalizedY: number) => void
|
|
12
|
-
onDragEnd?: (normalizedX: number, normalizedY: number) => void
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Internal
|
|
17
|
-
* @returns [refCallback, pointerDownHandler]
|
|
18
|
-
* @private
|
|
19
|
-
*/
|
|
20
|
-
export function usePianoDrag<T extends Element>({
|
|
21
|
-
baseElementRef,
|
|
22
|
-
onDrag,
|
|
23
|
-
onDragStart,
|
|
24
|
-
onDragEnd,
|
|
25
|
-
}: UsePianoDrag<T>) {
|
|
26
|
-
const dragged = useRef(false)
|
|
27
|
-
const normalizedX = useRef(0)
|
|
28
|
-
const normalizedY = useRef(0)
|
|
29
|
-
|
|
30
|
-
const handleDrag = useCallback(
|
|
31
|
-
(event: MouseEvent | React.PointerEvent<T> | TouchEvent) => {
|
|
32
|
-
if (!baseElementRef.current || !dragged.current) {
|
|
33
|
-
return
|
|
34
|
-
}
|
|
35
|
-
const isTouch = event instanceof TouchEvent
|
|
36
|
-
if (isTouch && event.cancelable) event.preventDefault()
|
|
37
|
-
const { left, top, right, bottom } =
|
|
38
|
-
baseElementRef.current.getBoundingClientRect()
|
|
39
|
-
const mouseX = isTouch ? event.touches[0].clientX : event.clientX
|
|
40
|
-
const mouseY = isTouch ? event.touches[0].clientY : event.clientY
|
|
41
|
-
const nx = normalizeValue(mouseX, left, right)
|
|
42
|
-
const ny = normalizeValue(mouseY, top, bottom)
|
|
43
|
-
normalizedX.current = nx
|
|
44
|
-
normalizedY.current = ny
|
|
45
|
-
onDrag(nx, ny)
|
|
46
|
-
},
|
|
47
|
-
[onDrag, baseElementRef],
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
const refHandler = useRefCallbackEvent(
|
|
51
|
-
'touchmove',
|
|
52
|
-
handleDrag,
|
|
53
|
-
{ passive: false },
|
|
54
|
-
[onDrag],
|
|
55
|
-
)
|
|
56
|
-
|
|
57
|
-
const pointerDownHandler = useCallback(
|
|
58
|
-
(event: React.PointerEvent<T>) => {
|
|
59
|
-
dragged.current = true
|
|
60
|
-
handleDrag(event)
|
|
61
|
-
onDragStart?.(normalizedX.current, normalizedY.current)
|
|
62
|
-
},
|
|
63
|
-
[handleDrag, onDragStart],
|
|
64
|
-
)
|
|
65
|
-
|
|
66
|
-
useEventListener(globalThis.window, 'pointermove', handleDrag)
|
|
67
|
-
|
|
68
|
-
useEventListener(globalThis.window, 'pointerup', () => {
|
|
69
|
-
if (!dragged.current) return
|
|
70
|
-
dragged.current = false
|
|
71
|
-
onDragEnd?.(normalizedX.current, normalizedY.current)
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
return { refHandler, pointerDownHandler }
|
|
75
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { useMemo } from 'react'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Internal
|
|
5
|
-
* @private
|
|
6
|
-
*/
|
|
7
|
-
export function useRefCallbackEvent<K extends keyof DocumentEventMap>(
|
|
8
|
-
event: K,
|
|
9
|
-
handler: (event: DocumentEventMap[K]) => void,
|
|
10
|
-
options?: boolean | AddEventListenerOptions,
|
|
11
|
-
deps?: React.DependencyList,
|
|
12
|
-
): (div: EventTarget | null) => void
|
|
13
|
-
export function useRefCallbackEvent(
|
|
14
|
-
event: string,
|
|
15
|
-
handler: (event: Event) => void,
|
|
16
|
-
options?: boolean | AddEventListenerOptions,
|
|
17
|
-
deps: React.DependencyList = [],
|
|
18
|
-
): (div: EventTarget | null) => void {
|
|
19
|
-
return useMemo(() => {
|
|
20
|
-
let cleanup: (() => void) | undefined
|
|
21
|
-
return (node: EventTarget | null) => {
|
|
22
|
-
if (!node) {
|
|
23
|
-
cleanup?.()
|
|
24
|
-
return
|
|
25
|
-
}
|
|
26
|
-
node.addEventListener(event, handler, options)
|
|
27
|
-
|
|
28
|
-
cleanup = () => {
|
|
29
|
-
node.removeEventListener(event, handler, options)
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
33
|
-
}, deps)
|
|
34
|
-
}
|
package/src/styles/global.css
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
.tremolo-user-select-none {
|
|
2
|
-
user-select: none;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
.tremolo-cursor-pointer {
|
|
6
|
-
cursor: pointer;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
.tremolo-cursor-move {
|
|
10
|
-
cursor: move;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
.tremolo-cursor-grabbing {
|
|
14
|
-
cursor: grabbing;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
.tremolo-cursor-none {
|
|
18
|
-
cursor: none;
|
|
19
|
-
}
|