@moises.ai/design-system 4.20.8 → 4.20.9

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": "@moises.ai/design-system",
3
- "version": "4.20.8",
3
+ "version": "4.20.9",
4
4
  "description": "Design System package based on @radix-ui/themes with custom defaults",
5
5
  "private": false,
6
6
  "type": "module",
@@ -27,10 +27,12 @@ export const PanControl = ({
27
27
  tooltipCloseDelay = 500,
28
28
  }) => {
29
29
  const containerRef = useRef(null)
30
+ const knobRef = useRef(null)
30
31
  const [isDragging, setIsDragging] = useState(false)
31
32
  const styleRef = useRef(null)
32
33
 
33
34
  const startYRef = useRef(0)
35
+ const activePointerIdRef = useRef(null)
34
36
  const pendingNormRef = useRef(value)
35
37
  const rafRef = useRef(0)
36
38
  const openTimeoutRef = useRef(null)
@@ -44,12 +46,43 @@ export const PanControl = ({
44
46
  const [knobFocused, setKnobFocused] = useState(false)
45
47
  const [isHovering, setIsHovering] = useState(false)
46
48
 
49
+ const clearOpenTimeout = useCallback(() => {
50
+ if (openTimeoutRef.current != null) {
51
+ clearTimeout(openTimeoutRef.current)
52
+ openTimeoutRef.current = null
53
+ }
54
+ }, [])
55
+
56
+ const clearCloseTimeout = useCallback(() => {
57
+ if (closeTimeoutRef.current != null) {
58
+ clearTimeout(closeTimeoutRef.current)
59
+ closeTimeoutRef.current = null
60
+ }
61
+ }, [])
62
+
63
+ const endDrag = useCallback(() => {
64
+ const pointerId = activePointerIdRef.current
65
+ const knob = knobRef.current
66
+ if (pointerId != null && knob?.hasPointerCapture?.(pointerId)) {
67
+ try {
68
+ knob.releasePointerCapture(pointerId)
69
+ } catch {
70
+ // Capture may already be gone (lostpointercapture / interrupt).
71
+ }
72
+ }
73
+ activePointerIdRef.current = null
74
+ setIsDragging(false)
75
+ }, [])
76
+
47
77
  useEffect(() => {
48
78
  if (disabled) {
79
+ endDrag()
80
+ clearOpenTimeout()
81
+ clearCloseTimeout()
49
82
  setIsHovering(false)
50
83
  setKnobFocused(false)
51
84
  }
52
- }, [disabled])
85
+ }, [disabled, endDrag, clearOpenTimeout, clearCloseTimeout])
53
86
 
54
87
  useEffect(() => {
55
88
  return () => {
@@ -59,17 +92,13 @@ export const PanControl = ({
59
92
  }, [])
60
93
 
61
94
  useEffect(() => {
62
- if (isDragging) {
63
- const style = document.createElement('style')
64
- style.textContent = '* { cursor: ns-resize !important; }'
65
- document.head.appendChild(style)
66
- styleRef.current = style
67
- } else {
68
- if (styleRef.current) {
69
- document.head.removeChild(styleRef.current)
70
- styleRef.current = null
71
- }
72
- }
95
+ if (!isDragging) return undefined
96
+
97
+ const style = document.createElement('style')
98
+ style.textContent = '* { cursor: ns-resize !important; }'
99
+ document.head.appendChild(style)
100
+ styleRef.current = style
101
+
73
102
  return () => {
74
103
  if (styleRef.current) {
75
104
  document.head.removeChild(styleRef.current)
@@ -82,6 +111,47 @@ export const PanControl = ({
82
111
  }
83
112
  }, [isDragging])
84
113
 
114
+ // Window-level end handlers: releasing outside the element, context menu,
115
+ // tab blur, visibility changes, and Escape must all clear the global ns-resize cursor.
116
+ useEffect(() => {
117
+ if (!isDragging) return undefined
118
+
119
+ const isActivePointer = (e) =>
120
+ activePointerIdRef.current == null ||
121
+ e.pointerId === activePointerIdRef.current
122
+
123
+ const onPointerEnd = (e) => {
124
+ if (!isActivePointer(e)) return
125
+ endDrag()
126
+ }
127
+ const onInterrupt = () => endDrag()
128
+ const onKeyDown = (e) => {
129
+ if (e.key === 'Escape') {
130
+ e.preventDefault()
131
+ endDrag()
132
+ }
133
+ }
134
+ const onVisibilityChange = () => {
135
+ if (document.visibilityState !== 'visible') endDrag()
136
+ }
137
+
138
+ window.addEventListener('pointerup', onPointerEnd)
139
+ window.addEventListener('pointercancel', onPointerEnd)
140
+ window.addEventListener('blur', onInterrupt)
141
+ window.addEventListener('contextmenu', onInterrupt)
142
+ window.addEventListener('keydown', onKeyDown)
143
+ document.addEventListener('visibilitychange', onVisibilityChange)
144
+
145
+ return () => {
146
+ window.removeEventListener('pointerup', onPointerEnd)
147
+ window.removeEventListener('pointercancel', onPointerEnd)
148
+ window.removeEventListener('blur', onInterrupt)
149
+ window.removeEventListener('contextmenu', onInterrupt)
150
+ window.removeEventListener('keydown', onKeyDown)
151
+ document.removeEventListener('visibilitychange', onVisibilityChange)
152
+ }
153
+ }, [isDragging, endDrag])
154
+
85
155
  const scheduleEmit = useCallback(
86
156
  (nextNormalized) => {
87
157
  pendingNormRef.current = clampNorm(nextNormalized)
@@ -110,18 +180,29 @@ export const PanControl = ({
110
180
  const onPointerDown = useCallback(
111
181
  (e) => {
112
182
  if (disabled) return
183
+ // Ignore secondary/auxiliary buttons (e.g. Mac trackpad two-finger click).
184
+ // Those can start drag without a reliable pointerup and leave cursor stuck.
185
+ if (e.button !== 0) return
113
186
  e.preventDefault()
114
187
  const target = e.currentTarget
188
+ activePointerIdRef.current = e.pointerId
115
189
  target.setPointerCapture?.(e.pointerId)
190
+ clearCloseTimeout()
116
191
  setIsDragging(true)
117
192
  startYRef.current = e.clientY
118
193
  },
119
- [disabled],
194
+ [disabled, clearCloseTimeout],
120
195
  )
121
196
 
122
197
  const onPointerMove = useCallback(
123
198
  (e) => {
124
199
  if (!isDragging) return
200
+ if (
201
+ activePointerIdRef.current != null &&
202
+ e.pointerId !== activePointerIdRef.current
203
+ ) {
204
+ return
205
+ }
125
206
  const deltaY = startYRef.current - e.clientY
126
207
  const next = value + deltaY * STEP_SIZE
127
208
  scheduleEmit(next)
@@ -130,10 +211,26 @@ export const PanControl = ({
130
211
  [isDragging, value, scheduleEmit],
131
212
  )
132
213
 
133
- const onPointerUp = useCallback((e) => {
134
- e.currentTarget?.releasePointerCapture?.(e.pointerId)
135
- setIsDragging(false)
136
- }, [])
214
+ const onPointerUp = useCallback(
215
+ (e) => {
216
+ if (
217
+ activePointerIdRef.current != null &&
218
+ e.pointerId !== activePointerIdRef.current
219
+ ) {
220
+ return
221
+ }
222
+ endDrag()
223
+ },
224
+ [endDrag],
225
+ )
226
+
227
+ const onContextMenu = useCallback(
228
+ (e) => {
229
+ e.preventDefault()
230
+ endDrag()
231
+ },
232
+ [endDrag],
233
+ )
137
234
 
138
235
  const handleClick = useCallback(
139
236
  (e) => {
@@ -204,20 +301,6 @@ export const PanControl = ({
204
301
  const displayNorm = clampNorm(denormalize(value, minValue, maxValue))
205
302
  const ariaPanPct = Math.round(displayNorm * 100)
206
303
 
207
- const clearOpenTimeout = () => {
208
- if (openTimeoutRef.current != null) {
209
- clearTimeout(openTimeoutRef.current)
210
- openTimeoutRef.current = null
211
- }
212
- }
213
-
214
- const clearCloseTimeout = () => {
215
- if (closeTimeoutRef.current != null) {
216
- clearTimeout(closeTimeoutRef.current)
217
- closeTimeoutRef.current = null
218
- }
219
- }
220
-
221
304
  const handlePointerEnter = () => {
222
305
  if (disabled) return
223
306
  clearCloseTimeout()
@@ -234,6 +317,9 @@ export const PanControl = ({
234
317
  }
235
318
 
236
319
  const handlePointerLeave = () => {
320
+ // Keep tooltip visible while actively dragging, even if the pointer
321
+ // leaves the knob (common when adjusting vertically).
322
+ if (isDragging) return
237
323
  clearOpenTimeout()
238
324
  const { tooltipCloseDelay: delay } = tooltipTimingRef.current
239
325
  if (delay <= 0) {
@@ -251,6 +337,7 @@ export const PanControl = ({
251
337
 
252
338
  const pan = (
253
339
  <div
340
+ ref={knobRef}
254
341
  role="slider"
255
342
  tabIndex={disabled ? -1 : 0}
256
343
  aria-label="Pan"
@@ -268,8 +355,10 @@ export const PanControl = ({
268
355
  onPointerMove={onPointerMove}
269
356
  onPointerUp={onPointerUp}
270
357
  onPointerCancel={onPointerUp}
358
+ onLostPointerCapture={onPointerUp}
271
359
  onPointerEnter={handlePointerEnter}
272
360
  onPointerLeave={handlePointerLeave}
361
+ onContextMenu={onContextMenu}
273
362
  onFocus={() => setKnobFocused(true)}
274
363
  onBlur={() => setKnobFocused(false)}
275
364
  onKeyDown={handleKnobKeyDown}