@pie-lib/drag 4.0.6 → 4.0.7-next.46
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/lib/drag-provider.js
CHANGED
|
@@ -18,16 +18,27 @@ function DragProvider(_ref) {
|
|
|
18
18
|
onDragStart = _ref.onDragStart,
|
|
19
19
|
collisionDetection = _ref.collisionDetection,
|
|
20
20
|
modifiers = _ref.modifiers,
|
|
21
|
-
autoScroll = _ref.autoScroll
|
|
21
|
+
autoScroll = _ref.autoScroll,
|
|
22
|
+
keyboardCoordinateGetter = _ref.keyboardCoordinateGetter,
|
|
23
|
+
keyboardCodes = _ref.keyboardCodes,
|
|
24
|
+
accessibility = _ref.accessibility;
|
|
22
25
|
var _useState = (0, _react.useState)(null),
|
|
23
26
|
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
24
27
|
activeId = _useState2[0],
|
|
25
28
|
setActiveId = _useState2[1];
|
|
29
|
+
|
|
30
|
+
// Only build a keyboard sensor options object when a consumer actually customizes
|
|
31
|
+
// it, so consumers that don't pass these props get dnd-kit's own defaults exactly
|
|
32
|
+
// as before (arrow-key nudging, Tab ends the drag, etc.).
|
|
33
|
+
var keyboardSensorOptions = keyboardCoordinateGetter || keyboardCodes ? {
|
|
34
|
+
coordinateGetter: keyboardCoordinateGetter,
|
|
35
|
+
keyboardCodes: keyboardCodes
|
|
36
|
+
} : undefined;
|
|
26
37
|
var sensors = (0, _core.useSensors)((0, _core.useSensor)(_core.PointerSensor, {
|
|
27
38
|
activationConstraint: {
|
|
28
39
|
distance: 8
|
|
29
40
|
}
|
|
30
|
-
}), (0, _core.useSensor)(_core.KeyboardSensor));
|
|
41
|
+
}), (0, _core.useSensor)(_core.KeyboardSensor, keyboardSensorOptions));
|
|
31
42
|
var handleDragStart = function handleDragStart(event) {
|
|
32
43
|
setActiveId(event.active.id);
|
|
33
44
|
if (onDragStart) {
|
|
@@ -46,7 +57,8 @@ function DragProvider(_ref) {
|
|
|
46
57
|
onDragEnd: handleDragEnd,
|
|
47
58
|
collisionDetection: collisionDetection,
|
|
48
59
|
modifiers: modifiers,
|
|
49
|
-
autoScroll: autoScroll
|
|
60
|
+
autoScroll: autoScroll,
|
|
61
|
+
accessibility: accessibility
|
|
50
62
|
}, children);
|
|
51
63
|
}
|
|
52
64
|
DragProvider.propTypes = {
|
|
@@ -55,7 +67,20 @@ DragProvider.propTypes = {
|
|
|
55
67
|
onDragStart: _propTypes["default"].func,
|
|
56
68
|
collisionDetection: _propTypes["default"].func,
|
|
57
69
|
modifiers: _propTypes["default"].arrayOf(_propTypes["default"].func),
|
|
58
|
-
autoScroll: _propTypes["default"].object
|
|
70
|
+
autoScroll: _propTypes["default"].object,
|
|
71
|
+
// Custom dnd-kit KeyboardSensor coordinateGetter (e.g. for Tab/Shift+Tab-based placement).
|
|
72
|
+
// Omit to keep dnd-kit's default keyboard-dragging behavior.
|
|
73
|
+
keyboardCoordinateGetter: _propTypes["default"].func,
|
|
74
|
+
// Overrides for dnd-kit's KeyboardSensor keyboardCodes (start/cancel/end).
|
|
75
|
+
// Omit to keep dnd-kit's defaults.
|
|
76
|
+
keyboardCodes: _propTypes["default"].shape({
|
|
77
|
+
start: _propTypes["default"].arrayOf(_propTypes["default"].string),
|
|
78
|
+
cancel: _propTypes["default"].arrayOf(_propTypes["default"].string),
|
|
79
|
+
end: _propTypes["default"].arrayOf(_propTypes["default"].string)
|
|
80
|
+
}),
|
|
81
|
+
// Passed straight through to dnd-kit's DndContext (screenReaderInstructions,
|
|
82
|
+
// announcements, container). Omit to keep dnd-kit's defaults.
|
|
83
|
+
accessibility: _propTypes["default"].object
|
|
59
84
|
};
|
|
60
85
|
var _default = exports["default"] = DragProvider;
|
|
61
86
|
//# sourceMappingURL=drag-provider.js.map
|
package/lib/drag-provider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drag-provider.js","names":["_react","_interopRequireWildcard","require","_propTypes","_interopRequireDefault","_core","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","_typeof","has","get","set","_t","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","DragProvider","_ref","children","onDragEnd","onDragStart","collisionDetection","modifiers","autoScroll","_useState","useState","_useState2","_slicedToArray2","activeId","setActiveId","sensors","useSensors","useSensor","PointerSensor","activationConstraint","distance","KeyboardSensor","handleDragStart","event","active","id","handleDragEnd","createElement","DndContext","propTypes","PropTypes","node","isRequired","func","arrayOf","object","_default","exports"],"sources":["../src/drag-provider.jsx"],"sourcesContent":["import React, { useState } from 'react';\nimport PropTypes from 'prop-types';\nimport { DndContext, KeyboardSensor, PointerSensor, useSensor, useSensors } from '@dnd-kit/core';\n\nexport function DragProvider({
|
|
1
|
+
{"version":3,"file":"drag-provider.js","names":["_react","_interopRequireWildcard","require","_propTypes","_interopRequireDefault","_core","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","_typeof","has","get","set","_t","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","DragProvider","_ref","children","onDragEnd","onDragStart","collisionDetection","modifiers","autoScroll","keyboardCoordinateGetter","keyboardCodes","accessibility","_useState","useState","_useState2","_slicedToArray2","activeId","setActiveId","keyboardSensorOptions","coordinateGetter","undefined","sensors","useSensors","useSensor","PointerSensor","activationConstraint","distance","KeyboardSensor","handleDragStart","event","active","id","handleDragEnd","createElement","DndContext","propTypes","PropTypes","node","isRequired","func","arrayOf","object","shape","start","string","cancel","end","_default","exports"],"sources":["../src/drag-provider.jsx"],"sourcesContent":["import React, { useState } from 'react';\nimport PropTypes from 'prop-types';\nimport { DndContext, KeyboardSensor, PointerSensor, useSensor, useSensors } from '@dnd-kit/core';\n\nexport function DragProvider({\n children,\n onDragEnd,\n onDragStart,\n collisionDetection,\n modifiers,\n autoScroll,\n keyboardCoordinateGetter,\n keyboardCodes,\n accessibility,\n}) {\n const [activeId, setActiveId] = useState(null);\n\n // Only build a keyboard sensor options object when a consumer actually customizes\n // it, so consumers that don't pass these props get dnd-kit's own defaults exactly\n // as before (arrow-key nudging, Tab ends the drag, etc.).\n const keyboardSensorOptions =\n keyboardCoordinateGetter || keyboardCodes ? { coordinateGetter: keyboardCoordinateGetter, keyboardCodes } : undefined;\n\n const sensors = useSensors(\n useSensor(PointerSensor, { activationConstraint: { distance: 8 } }),\n useSensor(KeyboardSensor, keyboardSensorOptions),\n );\n\n const handleDragStart = (event) => {\n setActiveId(event.active.id);\n if (onDragStart) {\n onDragStart(event);\n }\n };\n\n const handleDragEnd = (event) => {\n setActiveId(null);\n if (onDragEnd) {\n onDragEnd(event);\n }\n };\n\n return (\n <DndContext\n sensors={sensors}\n onDragStart={handleDragStart}\n onDragEnd={handleDragEnd}\n collisionDetection={collisionDetection}\n modifiers={modifiers}\n autoScroll={autoScroll}\n accessibility={accessibility}\n >\n {children}\n </DndContext>\n );\n}\n\nDragProvider.propTypes = {\n children: PropTypes.node.isRequired,\n onDragEnd: PropTypes.func,\n onDragStart: PropTypes.func,\n collisionDetection: PropTypes.func,\n modifiers: PropTypes.arrayOf(PropTypes.func),\n autoScroll: PropTypes.object,\n // Custom dnd-kit KeyboardSensor coordinateGetter (e.g. for Tab/Shift+Tab-based placement).\n // Omit to keep dnd-kit's default keyboard-dragging behavior.\n keyboardCoordinateGetter: PropTypes.func,\n // Overrides for dnd-kit's KeyboardSensor keyboardCodes (start/cancel/end).\n // Omit to keep dnd-kit's defaults.\n keyboardCodes: PropTypes.shape({\n start: PropTypes.arrayOf(PropTypes.string),\n cancel: PropTypes.arrayOf(PropTypes.string),\n end: PropTypes.arrayOf(PropTypes.string),\n }),\n // Passed straight through to dnd-kit's DndContext (screenReaderInstructions,\n // announcements, container). Omit to keep dnd-kit's defaults.\n accessibility: PropTypes.object,\n};\n\nexport default DragProvider;\n"],"mappings":";;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,KAA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EAAEA,UAAW;IACvBG,aAAa,EAAEA;EAAc,GAE5BR,QACS,CAAC;AAEjB;AAEAF,YAAY,CAACkC,SAAS,GAAG;EACvBhC,QAAQ,EAAEiC,qBAAS,CAACC,IAAI,CAACC,UAAU;EACnClC,SAAS,EAAEgC,qBAAS,CAACG,IAAI;EACzBlC,WAAW,EAAE+B,qBAAS,CAACG,IAAI;EAC3BjC,kBAAkB,EAAE8B,qBAAS,CAACG,IAAI;EAClChC,SAAS,EAAE6B,qBAAS,CAACI,OAAO,CAACJ,qBAAS,CAACG,IAAI,CAAC;EAC5C/B,UAAU,EAAE4B,qBAAS,CAACK,MAAM;EAC5B;EACA;EACAhC,wBAAwB,EAAE2B,qBAAS,CAACG,IAAI;EACxC;EACA;EACA7B,aAAa,EAAE0B,qBAAS,CAACM,KAAK,CAAC;IAC7BC,KAAK,EAAEP,qBAAS,CAACI,OAAO,CAACJ,qBAAS,CAACQ,MAAM,CAAC;IAC1CC,MAAM,EAAET,qBAAS,CAACI,OAAO,CAACJ,qBAAS,CAACQ,MAAM,CAAC;IAC3CE,GAAG,EAAEV,qBAAS,CAACI,OAAO,CAACJ,qBAAS,CAACQ,MAAM;EACzC,CAAC,CAAC;EACF;EACA;EACAjC,aAAa,EAAEyB,qBAAS,CAACK;AAC3B,CAAC;AAAC,IAAAM,QAAA,GAAAC,OAAA,cAEa/C,YAAY","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/drag",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.7-next.46+a7883b3a8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"@mui/icons-material": "^7.3.4",
|
|
15
15
|
"@mui/material": "^7.3.4",
|
|
16
16
|
"@pie-lib/math-rendering": "^5.1.0",
|
|
17
|
-
"@pie-lib/render-ui": "^6.1.
|
|
17
|
+
"@pie-lib/render-ui": "^6.1.4-next.46+a7883b3a8",
|
|
18
18
|
"classnames": "^2.2.6",
|
|
19
19
|
"lodash-es": "^4.17.23",
|
|
20
20
|
"prop-types": "^15.7.2",
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"scripts": {},
|
|
27
27
|
"author": "",
|
|
28
28
|
"license": "ISC",
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "a7883b3a8ec42e0ea2c8051dd0e9729daf2fac01"
|
|
30
30
|
}
|
|
@@ -3,13 +3,14 @@ import { render, screen } from '@testing-library/react';
|
|
|
3
3
|
import { DragProvider } from '../drag-provider';
|
|
4
4
|
|
|
5
5
|
jest.mock('@dnd-kit/core', () => ({
|
|
6
|
-
DndContext: ({ children, onDragStart, onDragEnd, sensors, collisionDetection, modifiers, autoScroll }) => (
|
|
6
|
+
DndContext: ({ children, onDragStart, onDragEnd, sensors, collisionDetection, modifiers, autoScroll, accessibility }) => (
|
|
7
7
|
<div
|
|
8
8
|
data-testid="dnd-context"
|
|
9
9
|
data-has-sensors={!!sensors}
|
|
10
10
|
data-has-collision-detection={!!collisionDetection}
|
|
11
11
|
data-has-modifiers={!!modifiers}
|
|
12
12
|
data-has-auto-scroll={!!autoScroll}
|
|
13
|
+
data-has-accessibility={!!accessibility}
|
|
13
14
|
data-on-drag-start={typeof onDragStart === 'function' ? 'function' : 'undefined'}
|
|
14
15
|
data-on-drag-end={typeof onDragEnd === 'function' ? 'function' : 'undefined'}
|
|
15
16
|
>
|
|
@@ -114,12 +115,20 @@ describe('DragProvider', () => {
|
|
|
114
115
|
expect(dndContext).toHaveAttribute('data-has-auto-scroll', 'true');
|
|
115
116
|
});
|
|
116
117
|
|
|
118
|
+
it('should pass accessibility to DndContext', () => {
|
|
119
|
+
const accessibility = { screenReaderInstructions: { draggable: 'Press Space or Enter to pick up.' } };
|
|
120
|
+
render(<DragProvider {...defaultProps} accessibility={accessibility} />);
|
|
121
|
+
const dndContext = screen.getByTestId('dnd-context');
|
|
122
|
+
expect(dndContext).toHaveAttribute('data-has-accessibility', 'true');
|
|
123
|
+
});
|
|
124
|
+
|
|
117
125
|
it('should pass all props to DndContext', () => {
|
|
118
126
|
const onDragStart = jest.fn();
|
|
119
127
|
const onDragEnd = jest.fn();
|
|
120
128
|
const collisionDetection = jest.fn();
|
|
121
129
|
const modifiers = [jest.fn()];
|
|
122
130
|
const autoScroll = { enabled: true };
|
|
131
|
+
const accessibility = { screenReaderInstructions: { draggable: 'Press Space or Enter to pick up.' } };
|
|
123
132
|
|
|
124
133
|
render(
|
|
125
134
|
<DragProvider
|
|
@@ -129,6 +138,7 @@ describe('DragProvider', () => {
|
|
|
129
138
|
collisionDetection={collisionDetection}
|
|
130
139
|
modifiers={modifiers}
|
|
131
140
|
autoScroll={autoScroll}
|
|
141
|
+
accessibility={accessibility}
|
|
132
142
|
/>,
|
|
133
143
|
);
|
|
134
144
|
|
|
@@ -138,6 +148,7 @@ describe('DragProvider', () => {
|
|
|
138
148
|
expect(dndContext).toHaveAttribute('data-has-collision-detection', 'true');
|
|
139
149
|
expect(dndContext).toHaveAttribute('data-has-modifiers', 'true');
|
|
140
150
|
expect(dndContext).toHaveAttribute('data-has-auto-scroll', 'true');
|
|
151
|
+
expect(dndContext).toHaveAttribute('data-has-accessibility', 'true');
|
|
141
152
|
});
|
|
142
153
|
});
|
|
143
154
|
|
|
@@ -171,6 +182,12 @@ describe('DragProvider', () => {
|
|
|
171
182
|
const dndContext = screen.getByTestId('dnd-context');
|
|
172
183
|
expect(dndContext).toHaveAttribute('data-has-auto-scroll', 'false');
|
|
173
184
|
});
|
|
185
|
+
|
|
186
|
+
it('should work without accessibility', () => {
|
|
187
|
+
render(<DragProvider {...defaultProps} />);
|
|
188
|
+
const dndContext = screen.getByTestId('dnd-context');
|
|
189
|
+
expect(dndContext).toHaveAttribute('data-has-accessibility', 'false');
|
|
190
|
+
});
|
|
174
191
|
});
|
|
175
192
|
|
|
176
193
|
describe('sensors setup', () => {
|
|
@@ -181,11 +198,11 @@ describe('DragProvider', () => {
|
|
|
181
198
|
expect(useSensor).toHaveBeenCalledWith('PointerSensor', { activationConstraint: { distance: 8 } });
|
|
182
199
|
});
|
|
183
200
|
|
|
184
|
-
it('should initialize KeyboardSensor', () => {
|
|
201
|
+
it('should initialize KeyboardSensor with no options by default', () => {
|
|
185
202
|
const { useSensor } = require('@dnd-kit/core');
|
|
186
203
|
render(<DragProvider {...defaultProps} />);
|
|
187
204
|
|
|
188
|
-
expect(useSensor).toHaveBeenCalledWith('KeyboardSensor');
|
|
205
|
+
expect(useSensor).toHaveBeenCalledWith('KeyboardSensor', undefined);
|
|
189
206
|
});
|
|
190
207
|
|
|
191
208
|
it('should combine sensors with useSensors', () => {
|
|
@@ -194,6 +211,35 @@ describe('DragProvider', () => {
|
|
|
194
211
|
|
|
195
212
|
expect(useSensors).toHaveBeenCalled();
|
|
196
213
|
});
|
|
214
|
+
|
|
215
|
+
it('should initialize KeyboardSensor with a custom coordinateGetter when provided', () => {
|
|
216
|
+
const { useSensor } = require('@dnd-kit/core');
|
|
217
|
+
const keyboardCoordinateGetter = jest.fn();
|
|
218
|
+
render(<DragProvider {...defaultProps} keyboardCoordinateGetter={keyboardCoordinateGetter} />);
|
|
219
|
+
|
|
220
|
+
expect(useSensor).toHaveBeenCalledWith('KeyboardSensor', {
|
|
221
|
+
coordinateGetter: keyboardCoordinateGetter,
|
|
222
|
+
keyboardCodes: undefined,
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('should initialize KeyboardSensor with custom keyboardCodes when provided', () => {
|
|
227
|
+
const { useSensor } = require('@dnd-kit/core');
|
|
228
|
+
const keyboardCodes = { start: ['Space'], cancel: ['Escape'], end: ['Space'] };
|
|
229
|
+
render(<DragProvider {...defaultProps} keyboardCodes={keyboardCodes} />);
|
|
230
|
+
|
|
231
|
+
expect(useSensor).toHaveBeenCalledWith('KeyboardSensor', {
|
|
232
|
+
coordinateGetter: undefined,
|
|
233
|
+
keyboardCodes,
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('should not customize KeyboardSensor when only unrelated props are passed', () => {
|
|
238
|
+
const { useSensor } = require('@dnd-kit/core');
|
|
239
|
+
render(<DragProvider {...defaultProps} collisionDetection={jest.fn()} />);
|
|
240
|
+
|
|
241
|
+
expect(useSensor).toHaveBeenCalledWith('KeyboardSensor', undefined);
|
|
242
|
+
});
|
|
197
243
|
});
|
|
198
244
|
|
|
199
245
|
describe('re-rendering', () => {
|
package/src/drag-provider.jsx
CHANGED
|
@@ -2,12 +2,28 @@ import React, { useState } from 'react';
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { DndContext, KeyboardSensor, PointerSensor, useSensor, useSensors } from '@dnd-kit/core';
|
|
4
4
|
|
|
5
|
-
export function DragProvider({
|
|
5
|
+
export function DragProvider({
|
|
6
|
+
children,
|
|
7
|
+
onDragEnd,
|
|
8
|
+
onDragStart,
|
|
9
|
+
collisionDetection,
|
|
10
|
+
modifiers,
|
|
11
|
+
autoScroll,
|
|
12
|
+
keyboardCoordinateGetter,
|
|
13
|
+
keyboardCodes,
|
|
14
|
+
accessibility,
|
|
15
|
+
}) {
|
|
6
16
|
const [activeId, setActiveId] = useState(null);
|
|
7
17
|
|
|
18
|
+
// Only build a keyboard sensor options object when a consumer actually customizes
|
|
19
|
+
// it, so consumers that don't pass these props get dnd-kit's own defaults exactly
|
|
20
|
+
// as before (arrow-key nudging, Tab ends the drag, etc.).
|
|
21
|
+
const keyboardSensorOptions =
|
|
22
|
+
keyboardCoordinateGetter || keyboardCodes ? { coordinateGetter: keyboardCoordinateGetter, keyboardCodes } : undefined;
|
|
23
|
+
|
|
8
24
|
const sensors = useSensors(
|
|
9
25
|
useSensor(PointerSensor, { activationConstraint: { distance: 8 } }),
|
|
10
|
-
useSensor(KeyboardSensor),
|
|
26
|
+
useSensor(KeyboardSensor, keyboardSensorOptions),
|
|
11
27
|
);
|
|
12
28
|
|
|
13
29
|
const handleDragStart = (event) => {
|
|
@@ -32,6 +48,7 @@ export function DragProvider({ children, onDragEnd, onDragStart, collisionDetect
|
|
|
32
48
|
collisionDetection={collisionDetection}
|
|
33
49
|
modifiers={modifiers}
|
|
34
50
|
autoScroll={autoScroll}
|
|
51
|
+
accessibility={accessibility}
|
|
35
52
|
>
|
|
36
53
|
{children}
|
|
37
54
|
</DndContext>
|
|
@@ -45,6 +62,19 @@ DragProvider.propTypes = {
|
|
|
45
62
|
collisionDetection: PropTypes.func,
|
|
46
63
|
modifiers: PropTypes.arrayOf(PropTypes.func),
|
|
47
64
|
autoScroll: PropTypes.object,
|
|
65
|
+
// Custom dnd-kit KeyboardSensor coordinateGetter (e.g. for Tab/Shift+Tab-based placement).
|
|
66
|
+
// Omit to keep dnd-kit's default keyboard-dragging behavior.
|
|
67
|
+
keyboardCoordinateGetter: PropTypes.func,
|
|
68
|
+
// Overrides for dnd-kit's KeyboardSensor keyboardCodes (start/cancel/end).
|
|
69
|
+
// Omit to keep dnd-kit's defaults.
|
|
70
|
+
keyboardCodes: PropTypes.shape({
|
|
71
|
+
start: PropTypes.arrayOf(PropTypes.string),
|
|
72
|
+
cancel: PropTypes.arrayOf(PropTypes.string),
|
|
73
|
+
end: PropTypes.arrayOf(PropTypes.string),
|
|
74
|
+
}),
|
|
75
|
+
// Passed straight through to dnd-kit's DndContext (screenReaderInstructions,
|
|
76
|
+
// announcements, container). Omit to keep dnd-kit's defaults.
|
|
77
|
+
accessibility: PropTypes.object,
|
|
48
78
|
};
|
|
49
79
|
|
|
50
80
|
export default DragProvider;
|