@moises.ai/design-system 4.22.1 → 4.22.2
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/index.js +4158 -4107
- package/package.json +1 -1
- package/src/components/DataTable/DataTable.module.css +32 -6
- package/src/components/DataTable/dnd/DataTableRowSortable.jsx +82 -3
- package/src/components/DataTable/dnd/dataTableDnd.utils.js +17 -0
- package/src/components/DataTable/dnd/useDataTableDnd.js +9 -3
- package/src/components/SetlistList/SetlistList.stories.jsx +12 -2
package/package.json
CHANGED
|
@@ -158,7 +158,12 @@
|
|
|
158
158
|
opacity: 0;
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
-
|
|
161
|
+
@media (hover: hover) and (pointer: fine) {
|
|
162
|
+
.DataTable :global(.rt-TableRow:hover) .checkboxCell {
|
|
163
|
+
opacity: 1;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
162
167
|
.selectColumn:focus-within .checkboxCell,
|
|
163
168
|
.rowSelected .checkboxCell {
|
|
164
169
|
opacity: 1;
|
|
@@ -276,8 +281,10 @@
|
|
|
276
281
|
--row-bg: transparent;
|
|
277
282
|
}
|
|
278
283
|
|
|
279
|
-
|
|
280
|
-
|
|
284
|
+
@media (hover: hover) and (pointer: fine) {
|
|
285
|
+
.DataTable :global(.rt-TableRow:hover) {
|
|
286
|
+
--row-bg: var(--neutral-alpha-2);
|
|
287
|
+
}
|
|
281
288
|
}
|
|
282
289
|
|
|
283
290
|
.DataTable :global(.rt-TableRow:focus-within) {
|
|
@@ -315,6 +322,9 @@
|
|
|
315
322
|
color: inherit;
|
|
316
323
|
text-align: left;
|
|
317
324
|
cursor: pointer;
|
|
325
|
+
-webkit-touch-callout: none;
|
|
326
|
+
-webkit-user-select: none;
|
|
327
|
+
user-select: none;
|
|
318
328
|
}
|
|
319
329
|
|
|
320
330
|
.rowActionButton > * {
|
|
@@ -327,8 +337,13 @@
|
|
|
327
337
|
outline-offset: 2px;
|
|
328
338
|
}
|
|
329
339
|
|
|
330
|
-
|
|
331
|
-
|
|
340
|
+
@media (hover: hover) and (pointer: fine) {
|
|
341
|
+
.DataTable
|
|
342
|
+
:global(.rt-TableRow:hover)
|
|
343
|
+
.projectCell:not(.dropdownColumn)
|
|
344
|
+
:not(.artistText) {
|
|
345
|
+
color: var(--neutral-12);
|
|
346
|
+
}
|
|
332
347
|
}
|
|
333
348
|
|
|
334
349
|
.DataTable
|
|
@@ -524,12 +539,23 @@
|
|
|
524
539
|
min-width: 100%;
|
|
525
540
|
}
|
|
526
541
|
|
|
527
|
-
|
|
542
|
+
@media (hover: hover) and (pointer: fine) {
|
|
543
|
+
.DataTable :global(.rt-TableRow:hover) .dropdownTriggerWrapperIcon {
|
|
544
|
+
opacity: 1;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
528
548
|
.dropdownColumn:focus-within .dropdownTriggerWrapperIcon,
|
|
529
549
|
.showDropdownOnSelect .dropdownTriggerWrapperIcon {
|
|
530
550
|
opacity: 1;
|
|
531
551
|
}
|
|
532
552
|
|
|
553
|
+
@media (pointer: coarse) {
|
|
554
|
+
.dropdownTriggerWrapperIcon {
|
|
555
|
+
opacity: 1;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
533
559
|
|
|
534
560
|
.headerActions {
|
|
535
561
|
width: max-content;
|
|
@@ -1,11 +1,37 @@
|
|
|
1
|
-
import React, { useRef } from 'react'
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react'
|
|
2
2
|
import { useSortable } from '@dnd-kit/sortable'
|
|
3
3
|
import { CSS } from '@dnd-kit/utilities'
|
|
4
4
|
import classNames from 'classnames'
|
|
5
5
|
import { Flex, Table, Checkbox, DropdownMenu } from '../../../index'
|
|
6
6
|
import { MoreButton } from '../../MoreButton/MoreButton'
|
|
7
7
|
import styles from '../DataTable.module.css'
|
|
8
|
-
import { resolveRowDraggable } from './dataTableDnd.utils'
|
|
8
|
+
import { isTouchTap, resolveRowDraggable } from './dataTableDnd.utils'
|
|
9
|
+
|
|
10
|
+
let lastScroll = null
|
|
11
|
+
let scrollListenerAttached = false
|
|
12
|
+
|
|
13
|
+
const recordScroll = (e) => {
|
|
14
|
+
lastScroll = { target: e.target, time: performance.now() }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const listenForScroll = () => {
|
|
18
|
+
if (scrollListenerAttached) return
|
|
19
|
+
scrollListenerAttached = true
|
|
20
|
+
document.addEventListener('scroll', recordScroll, {
|
|
21
|
+
capture: true,
|
|
22
|
+
passive: true,
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const toPoint = (e) => ({
|
|
27
|
+
pointerId: e.pointerId,
|
|
28
|
+
x: e.clientX,
|
|
29
|
+
y: e.clientY,
|
|
30
|
+
time: performance.now(),
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
// Keeps a press on a cell control from arming the row's drag sensor.
|
|
34
|
+
const stopDragActivation = (e) => e.stopPropagation()
|
|
9
35
|
|
|
10
36
|
export const DataTableRowSortable = React.memo(function DataTableRowSortable({
|
|
11
37
|
row,
|
|
@@ -32,6 +58,9 @@ export const DataTableRowSortable = React.memo(function DataTableRowSortable({
|
|
|
32
58
|
const touchHandledRef = useRef(false)
|
|
33
59
|
const checkboxTouchHandledRef = useRef(false)
|
|
34
60
|
const checkboxKeyboardHandledRef = useRef(false)
|
|
61
|
+
const pointerStartRef = useRef(null)
|
|
62
|
+
const gestureDraggedRef = useRef(false)
|
|
63
|
+
const [menuOpen, setMenuOpen] = useState(false)
|
|
35
64
|
const { listeners, setNodeRef, transform, transition, isDragging } =
|
|
36
65
|
useSortable({
|
|
37
66
|
id: rowId,
|
|
@@ -45,6 +74,30 @@ export const DataTableRowSortable = React.memo(function DataTableRowSortable({
|
|
|
45
74
|
},
|
|
46
75
|
})
|
|
47
76
|
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (isDragging) gestureDraggedRef.current = true
|
|
79
|
+
}, [isDragging])
|
|
80
|
+
|
|
81
|
+
const handleRowPointerDownCapture = (e) => {
|
|
82
|
+
if (e.pointerType === 'touch') listenForScroll()
|
|
83
|
+
pointerStartRef.current = toPoint(e)
|
|
84
|
+
gestureDraggedRef.current = false
|
|
85
|
+
touchHandledRef.current = false
|
|
86
|
+
checkboxTouchHandledRef.current = false
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const handleRowPointerCancel = () => {
|
|
90
|
+
pointerStartRef.current = null
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const isTap = (e) => {
|
|
94
|
+
if (gestureDraggedRef.current) return false
|
|
95
|
+
const scroll = lastScroll?.target?.contains?.(e.currentTarget)
|
|
96
|
+
? lastScroll
|
|
97
|
+
: null
|
|
98
|
+
return isTouchTap(pointerStartRef.current, toPoint(e), scroll)
|
|
99
|
+
}
|
|
100
|
+
|
|
48
101
|
const sortableStyle = {
|
|
49
102
|
...(transform ? { transform: CSS.Transform.toString(transform) } : {}),
|
|
50
103
|
...(transition ? { transition } : {}),
|
|
@@ -69,6 +122,7 @@ export const DataTableRowSortable = React.memo(function DataTableRowSortable({
|
|
|
69
122
|
const handleRowPointerUp = (e) => {
|
|
70
123
|
if (e.pointerType !== 'touch') return
|
|
71
124
|
touchHandledRef.current = true
|
|
125
|
+
if (!isTap(e)) return
|
|
72
126
|
if (e.shiftKey) {
|
|
73
127
|
onShiftClickRow?.(row, rowIndex)
|
|
74
128
|
} else {
|
|
@@ -126,6 +180,7 @@ export const DataTableRowSortable = React.memo(function DataTableRowSortable({
|
|
|
126
180
|
if (e.pointerType !== 'touch') return
|
|
127
181
|
e.stopPropagation()
|
|
128
182
|
checkboxTouchHandledRef.current = true
|
|
183
|
+
if (!isTap(e)) return
|
|
129
184
|
if (e.shiftKey) {
|
|
130
185
|
onShiftClickRow?.(row, rowIndex)
|
|
131
186
|
} else if (rowId != null) {
|
|
@@ -133,6 +188,16 @@ export const DataTableRowSortable = React.memo(function DataTableRowSortable({
|
|
|
133
188
|
}
|
|
134
189
|
}
|
|
135
190
|
|
|
191
|
+
// Radix opens the menu on pointerdown, which would open it at the start of
|
|
192
|
+
// a scroll. On touch the row opens it on a tap instead.
|
|
193
|
+
const handleMenuPointerDown = (e) => {
|
|
194
|
+
if (e.pointerType === 'touch') e.preventDefault()
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const handleMenuPointerUp = (e) => {
|
|
198
|
+
if (e.pointerType === 'touch' && isTap(e)) setMenuOpen(true)
|
|
199
|
+
}
|
|
200
|
+
|
|
136
201
|
const handleCheckedChange = (value) => {
|
|
137
202
|
if (shiftClickRef.current) {
|
|
138
203
|
shiftClickRef.current = false
|
|
@@ -166,12 +231,17 @@ export const DataTableRowSortable = React.memo(function DataTableRowSortable({
|
|
|
166
231
|
})}
|
|
167
232
|
style={rowStyle}
|
|
168
233
|
{...(isDraggable ? listeners : {})}
|
|
234
|
+
onPointerDownCapture={handleRowPointerDownCapture}
|
|
235
|
+
onPointerCancel={handleRowPointerCancel}
|
|
169
236
|
>
|
|
170
237
|
<Table.Cell
|
|
171
238
|
className={styles.selectColumn}
|
|
172
239
|
data-column-id="select"
|
|
173
240
|
data-sorted="false"
|
|
174
241
|
onClick={handleCheckboxCellClick}
|
|
242
|
+
onPointerDown={stopDragActivation}
|
|
243
|
+
onMouseDown={stopDragActivation}
|
|
244
|
+
onTouchStart={stopDragActivation}
|
|
175
245
|
onPointerUp={handleCheckboxCellPointerUp}
|
|
176
246
|
>
|
|
177
247
|
<Checkbox
|
|
@@ -226,11 +296,20 @@ export const DataTableRowSortable = React.memo(function DataTableRowSortable({
|
|
|
226
296
|
styles.dropdownColumnCell,
|
|
227
297
|
)}
|
|
228
298
|
data-column-id="actions"
|
|
299
|
+
onPointerDown={stopDragActivation}
|
|
300
|
+
onMouseDown={stopDragActivation}
|
|
301
|
+
onTouchStart={stopDragActivation}
|
|
229
302
|
>
|
|
230
303
|
{row.dropdownOptions?.length ? (
|
|
231
304
|
<DropdownMenu
|
|
305
|
+
open={menuOpen}
|
|
306
|
+
onOpenChange={setMenuOpen}
|
|
232
307
|
trigger={
|
|
233
|
-
<Flex
|
|
308
|
+
<Flex
|
|
309
|
+
className={styles.dropdownTriggerWrapper}
|
|
310
|
+
onPointerDown={handleMenuPointerDown}
|
|
311
|
+
onPointerUp={handleMenuPointerUp}
|
|
312
|
+
>
|
|
234
313
|
<MoreButton
|
|
235
314
|
aria-label={`More options for ${row.title ?? ''}`}
|
|
236
315
|
className={classNames(
|
|
@@ -14,6 +14,23 @@ export const resolveRowId = (row, fallbackIndex = null) => {
|
|
|
14
14
|
export const DATA_TABLE_DROP_TOP_ID = 'data-table-drop-top'
|
|
15
15
|
export const DATA_TABLE_DROP_BOTTOM_ID = 'data-table-drop-bottom'
|
|
16
16
|
|
|
17
|
+
// Mouse drags after a short move; a finger has to hold still first, so a
|
|
18
|
+
// swipe stays a scroll. The touch tolerance sits under the tap slop.
|
|
19
|
+
export const DATA_TABLE_MOUSE_ACTIVATION = { distance: 6 }
|
|
20
|
+
export const DATA_TABLE_TOUCH_ACTIVATION = { delay: 250, tolerance: 8 }
|
|
21
|
+
|
|
22
|
+
export const TOUCH_TAP_SLOP_PX = 10
|
|
23
|
+
export const TOUCH_TAP_SCROLL_GRACE_MS = 100
|
|
24
|
+
|
|
25
|
+
// start/end: { pointerId, x, y, time }; lastScroll: { time } or null.
|
|
26
|
+
export const isTouchTap = (start, end, lastScroll) => {
|
|
27
|
+
if (!start || !end || start.pointerId !== end.pointerId) return false
|
|
28
|
+
if (Math.hypot(end.x - start.x, end.y - start.y) >= TOUCH_TAP_SLOP_PX) {
|
|
29
|
+
return false
|
|
30
|
+
}
|
|
31
|
+
return !lastScroll || lastScroll.time < start.time - TOUCH_TAP_SCROLL_GRACE_MS
|
|
32
|
+
}
|
|
33
|
+
|
|
17
34
|
export const resolveRowType = (row) => {
|
|
18
35
|
return (
|
|
19
36
|
row?.type ??
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useCallback, useMemo, useState } from 'react'
|
|
2
2
|
import {
|
|
3
|
+
MouseSensor,
|
|
3
4
|
pointerWithin,
|
|
4
|
-
|
|
5
|
+
TouchSensor,
|
|
5
6
|
useDndMonitor,
|
|
6
7
|
useSensor,
|
|
7
8
|
useSensors,
|
|
@@ -10,6 +11,8 @@ import {
|
|
|
10
11
|
buildReorderPayload,
|
|
11
12
|
DATA_TABLE_DROP_TOP_ID,
|
|
12
13
|
DATA_TABLE_DROP_BOTTOM_ID,
|
|
14
|
+
DATA_TABLE_MOUSE_ACTIVATION,
|
|
15
|
+
DATA_TABLE_TOUCH_ACTIVATION,
|
|
13
16
|
} from './dataTableDnd.utils'
|
|
14
17
|
|
|
15
18
|
const isDataTableDrag = (event, dndScopeId) => {
|
|
@@ -72,8 +75,11 @@ export const useDataTableDnd = ({
|
|
|
72
75
|
const [activeDragContext, setActiveDragContext] = useState(null)
|
|
73
76
|
|
|
74
77
|
const sensors = useSensors(
|
|
75
|
-
useSensor(
|
|
76
|
-
activationConstraint:
|
|
78
|
+
useSensor(MouseSensor, {
|
|
79
|
+
activationConstraint: DATA_TABLE_MOUSE_ACTIVATION,
|
|
80
|
+
}),
|
|
81
|
+
useSensor(TouchSensor, {
|
|
82
|
+
activationConstraint: DATA_TABLE_TOUCH_ACTIVATION,
|
|
77
83
|
}),
|
|
78
84
|
)
|
|
79
85
|
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { useState, useCallback } from 'react'
|
|
2
2
|
import {
|
|
3
3
|
DndContext,
|
|
4
|
-
|
|
4
|
+
MouseSensor,
|
|
5
|
+
TouchSensor,
|
|
5
6
|
useSensor,
|
|
6
7
|
useSensors,
|
|
7
8
|
pointerWithin,
|
|
8
9
|
} from '@dnd-kit/core'
|
|
9
10
|
import { SetlistList } from './SetlistList'
|
|
10
11
|
import { DataTable } from '../DataTable/DataTable'
|
|
12
|
+
import {
|
|
13
|
+
DATA_TABLE_MOUSE_ACTIVATION,
|
|
14
|
+
DATA_TABLE_TOUCH_ACTIVATION,
|
|
15
|
+
} from '../DataTable/dnd/dataTableDnd.utils'
|
|
11
16
|
|
|
12
17
|
const defaultSetlists = [
|
|
13
18
|
{
|
|
@@ -331,7 +336,12 @@ export const DragFromDataTable = {
|
|
|
331
336
|
const [dropLog, setDropLog] = useState([])
|
|
332
337
|
|
|
333
338
|
const sensors = useSensors(
|
|
334
|
-
useSensor(
|
|
339
|
+
useSensor(MouseSensor, {
|
|
340
|
+
activationConstraint: DATA_TABLE_MOUSE_ACTIVATION,
|
|
341
|
+
}),
|
|
342
|
+
useSensor(TouchSensor, {
|
|
343
|
+
activationConstraint: DATA_TABLE_TOUCH_ACTIVATION,
|
|
344
|
+
}),
|
|
335
345
|
)
|
|
336
346
|
|
|
337
347
|
const handleDragEnd = useCallback(
|