@atlaskit/pragmatic-drag-and-drop 1.0.2 → 1.1.1
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/CHANGELOG.md +32 -0
- package/README.md +3 -39
- package/dist/cjs/ledger/dispatch-consumer-event.js +2 -0
- package/dist/cjs/ledger/lifecycle-manager.js +106 -68
- package/dist/cjs/public-utils/prevent-unhandled.js +56 -23
- package/dist/es2019/ledger/dispatch-consumer-event.js +2 -0
- package/dist/es2019/ledger/lifecycle-manager.js +104 -68
- package/dist/es2019/public-utils/prevent-unhandled.js +54 -23
- package/dist/esm/ledger/dispatch-consumer-event.js +2 -0
- package/dist/esm/ledger/lifecycle-manager.js +106 -68
- package/dist/esm/public-utils/prevent-unhandled.js +55 -23
- package/dist/types/entry-point/types.d.ts +1 -1
- package/dist/types/internal-types.d.ts +17 -5
- package/dist/types/ledger/dispatch-consumer-event.d.ts +3 -2
- package/dist/types/make-adapter/make-adapter.d.ts +2 -2
- package/dist/types/make-adapter/make-drop-target.d.ts +2 -2
- package/dist/types/public-utils/prevent-unhandled.d.ts +14 -2
- package/dist/types-ts4.5/entry-point/types.d.ts +1 -1
- package/dist/types-ts4.5/internal-types.d.ts +17 -5
- package/dist/types-ts4.5/ledger/dispatch-consumer-event.d.ts +3 -2
- package/dist/types-ts4.5/make-adapter/make-adapter.d.ts +2 -2
- package/dist/types-ts4.5/make-adapter/make-drop-target.d.ts +2 -2
- package/dist/types-ts4.5/public-utils/prevent-unhandled.d.ts +14 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# @atlaskit/pragmatic-drag-and-drop
|
|
2
2
|
|
|
3
|
+
## 1.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#83702](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/83702) [`4d9e25ab4eaa`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/4d9e25ab4eaa) - Updating the descriptions of Pragmatic drag and drop packages, so they each provide a consistent description to various consumers, and so they are consistently formed amongst each other.
|
|
8
|
+
|
|
9
|
+
- `package.json` `description`
|
|
10
|
+
- `README.md`
|
|
11
|
+
- Website documentation
|
|
12
|
+
|
|
13
|
+
## 1.1.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- [#82653](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/82653) [`136d8da5542d`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/136d8da5542d) - Adding additional information to `onDrop()` events to expose what the final `dropEffect` was for a drag operation.
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
type DropData = {
|
|
21
|
+
dropEffect: DataTransfer['dropEffect'];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
monitorForElements({
|
|
25
|
+
onDrop(payload) {
|
|
26
|
+
const drop: DropData = payload.drop;
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Fixing a bug where `preventUnhandled.start()` would prevent unhandled drag operations forever. It now only prevents unhandled drag operations for the current drag operation. `preventUnhandled.stop()` is now optional, as `preventUnhandled.start()` now tidies up itself. You can still leverage `preventUnhandled.stop()` to stop preventing unhandled drag operations during a drag.
|
|
32
|
+
|
|
33
|
+
Tightening the `getDropEffect()` function on drop targets slightly so that `"none"` cannot be provided. Using `"none"` as the drop effect would break the expected behaviour for nested drop targets.
|
|
34
|
+
|
|
3
35
|
## 1.0.2
|
|
4
36
|
|
|
5
37
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,43 +1,7 @@
|
|
|
1
1
|
# Pragmatic drag and drop
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> Fast drag and drop for any experience on any tech stack
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The core package for Pragmatic drag and drop.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
There are a wealth of existing drag and drop libraries for the web. Some drag and drop libraries are general purpose (e.g. `@shopify/draggable`, `react-dnd`), and some are for specific experiences (e.g. `react-beautiful-dnd` is for lists and connected lists). Some libraries leverage the platform's built in drag and drop capabilities, and some rebuild the drag and drop operation from scratch.
|
|
10
|
-
|
|
11
|
-
Every drag and drop solution will make tradeoffs regarding feature sets, user experience, startup performance and runtime performance.
|
|
12
|
-
|
|
13
|
-
The goals of `@atlaskit/pragmatic-drag-and-drop` are:
|
|
14
|
-
|
|
15
|
-
- 🚀 Speed: Best of class startup and runtime performance
|
|
16
|
-
- 🤸 Flexibility: Can be used to power any interaction
|
|
17
|
-
- 🧑🦽 Accessibility\*: Ensuring that all users have a good experience
|
|
18
|
-
|
|
19
|
-
> \*Accessible experiences are achieved through alternative keyboard and screen reader flows. Unfortunately, the browsers drag and drop behaviour is not accessible (yet). But don't worry, we have a comprehensive guide and toolchain to help you be successful here
|
|
20
|
-
|
|
21
|
-
## Core characteristics
|
|
22
|
-
|
|
23
|
-
- 🌎 Platform powered: leverages the browsers drag and drop capabilities
|
|
24
|
-
- 🐁 Tiny: ~`4.5kB` base
|
|
25
|
-
- 🪡 Incremental: only pay for what you use
|
|
26
|
-
- ⏳ Deferred compatible: consumers can delay the loading of `@atlaskit/pragmatic-drag-and-drop` (and related packages) in order to improve page load speeds
|
|
27
|
-
- 🎨 Headless: full rendering and style control
|
|
28
|
-
- 🦊 Cross browser support: full feature support in Firefox, Safari and Chrome
|
|
29
|
-
- 📱 Touch device compatible
|
|
30
|
-
- 🎁 Addons: patterns that allow sharing small pieces of functionality that can be added together
|
|
31
|
-
- 🎄 Framework agnostic: works with any frontend framework
|
|
32
|
-
- 👾 Virtualization support
|
|
33
|
-
- 🧑🦽 Accessible: comprehensive toolchain and patterns for creating highly accessible experiences
|
|
34
|
-
|
|
35
|
-
## Installation
|
|
36
|
-
|
|
37
|
-
```sh
|
|
38
|
-
yarn add @atlaskit/pragmatic-drag-and-drop
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
## Usage
|
|
42
|
-
|
|
43
|
-
Detailed docs and example usage can be found on [atlassian.design](https://atlassian.design/components/pragmatic-drag-and-drop/).
|
|
7
|
+
[📖 Documentation](https://atlassian.design/components/pragmatic-drag-and-drop/)
|
|
@@ -112,12 +112,14 @@ function makeDispatch(_ref) {
|
|
|
112
112
|
},
|
|
113
113
|
drop: function drop(_ref5) {
|
|
114
114
|
var current = _ref5.current,
|
|
115
|
+
drop = _ref5.drop,
|
|
115
116
|
updatedSourcePayload = _ref5.updatedSourcePayload;
|
|
116
117
|
dragStart.flush();
|
|
117
118
|
scheduleOnDrag.cancel();
|
|
118
119
|
safeDispatch({
|
|
119
120
|
eventName: 'onDrop',
|
|
120
121
|
payload: {
|
|
122
|
+
drop: drop,
|
|
121
123
|
source: updatedSourcePayload !== null && updatedSourcePayload !== void 0 ? updatedSourcePayload : source,
|
|
122
124
|
location: {
|
|
123
125
|
current: current,
|
|
@@ -12,9 +12,11 @@ var _detectBrokenDrag = require("../util/detect-broken-drag");
|
|
|
12
12
|
var _fixPostDragPointerBug = require("../util/fix-post-drag-pointer-bug");
|
|
13
13
|
var _getInput = require("../util/get-input");
|
|
14
14
|
var _dispatchConsumerEvent = require("./dispatch-consumer-event");
|
|
15
|
-
var
|
|
15
|
+
var globalState = {
|
|
16
|
+
isActive: false
|
|
17
|
+
};
|
|
16
18
|
function canStart() {
|
|
17
|
-
return !isActive;
|
|
19
|
+
return !globalState.isActive;
|
|
18
20
|
}
|
|
19
21
|
function getNativeSetDragImage(event) {
|
|
20
22
|
if (event.dataTransfer) {
|
|
@@ -47,15 +49,18 @@ function start(_ref2) {
|
|
|
47
49
|
if (!canStart()) {
|
|
48
50
|
return;
|
|
49
51
|
}
|
|
50
|
-
isActive = true;
|
|
51
52
|
var initial = getStartLocation({
|
|
52
53
|
event: event,
|
|
53
54
|
dragType: dragType,
|
|
54
55
|
getDropTargetsOver: getDropTargetsOver
|
|
55
56
|
});
|
|
56
|
-
|
|
57
|
+
globalState.isActive = true;
|
|
58
|
+
var state = {
|
|
59
|
+
current: initial
|
|
60
|
+
};
|
|
61
|
+
|
|
57
62
|
// Setting initial drop effect for the drag
|
|
58
|
-
|
|
63
|
+
setDropEffectOnEvent({
|
|
59
64
|
event: event,
|
|
60
65
|
current: initial.dropTargets
|
|
61
66
|
});
|
|
@@ -67,17 +72,17 @@ function start(_ref2) {
|
|
|
67
72
|
function updateDropTargets(next) {
|
|
68
73
|
// only looking at whether hierarchy has changed to determine whether something as 'changed'
|
|
69
74
|
var hasChanged = hasHierarchyChanged({
|
|
70
|
-
current: current.dropTargets,
|
|
75
|
+
current: state.current.dropTargets,
|
|
71
76
|
next: next.dropTargets
|
|
72
77
|
});
|
|
73
78
|
|
|
74
79
|
// Always updating the state to include latest data, dropEffect and stickiness
|
|
75
80
|
// Only updating consumers if the hierarchy has changed in some way
|
|
76
81
|
// Consumers can get the latest data by using `onDrag`
|
|
77
|
-
current = next;
|
|
82
|
+
state.current = next;
|
|
78
83
|
if (hasChanged) {
|
|
79
84
|
dispatch.dragUpdate({
|
|
80
|
-
current: current
|
|
85
|
+
current: state.current
|
|
81
86
|
});
|
|
82
87
|
}
|
|
83
88
|
}
|
|
@@ -87,12 +92,12 @@ function start(_ref2) {
|
|
|
87
92
|
target: event.target,
|
|
88
93
|
input: input,
|
|
89
94
|
source: dragType.payload,
|
|
90
|
-
current: current.dropTargets
|
|
95
|
+
current: state.current.dropTargets
|
|
91
96
|
});
|
|
92
97
|
if (nextDropTargets.length) {
|
|
93
98
|
// 🩸 must call `event.preventDefault()` to allow a browser drop to occur
|
|
94
99
|
event.preventDefault();
|
|
95
|
-
|
|
100
|
+
setDropEffectOnEvent({
|
|
96
101
|
event: event,
|
|
97
102
|
current: nextDropTargets
|
|
98
103
|
});
|
|
@@ -102,22 +107,7 @@ function start(_ref2) {
|
|
|
102
107
|
input: input
|
|
103
108
|
});
|
|
104
109
|
}
|
|
105
|
-
function
|
|
106
|
-
// When dropping something native, we need to extract the latest
|
|
107
|
-
// `.items` from the "drop" event as it is now accessible
|
|
108
|
-
if (args.type === 'success' && dragType.type === 'external') {
|
|
109
|
-
dispatch.drop({
|
|
110
|
-
current: current,
|
|
111
|
-
updatedSourcePayload: dragType.getDropPayload(args.event)
|
|
112
|
-
});
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
dispatch.drop({
|
|
116
|
-
current: current,
|
|
117
|
-
updatedSourcePayload: null
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
function cancel() {
|
|
110
|
+
function cancel(drop) {
|
|
121
111
|
// The spec behaviour is that when a drag is cancelled, or when dropping on no drop targets,
|
|
122
112
|
// a "dragleave" event is fired on the active drop target before a "dragend" event.
|
|
123
113
|
// We are replicating that behaviour in `cancel` if there are any active drop targets to
|
|
@@ -126,19 +116,21 @@ function start(_ref2) {
|
|
|
126
116
|
// Note: When cancelling, or dropping on no drop targets, a "dragleave" event
|
|
127
117
|
// will have already cleared the dropTargets to `[]` (as that particular "dragleave" has a `relatedTarget` of `null`)
|
|
128
118
|
|
|
129
|
-
if (current.dropTargets.length) {
|
|
119
|
+
if (state.current.dropTargets.length) {
|
|
130
120
|
updateDropTargets({
|
|
131
121
|
dropTargets: [],
|
|
132
|
-
input: current.input
|
|
122
|
+
input: state.current.input
|
|
133
123
|
});
|
|
134
124
|
}
|
|
135
|
-
|
|
136
|
-
|
|
125
|
+
dispatch.drop({
|
|
126
|
+
current: state.current,
|
|
127
|
+
drop: drop,
|
|
128
|
+
updatedSourcePayload: null
|
|
137
129
|
});
|
|
138
130
|
finish();
|
|
139
131
|
}
|
|
140
132
|
function finish() {
|
|
141
|
-
isActive = false;
|
|
133
|
+
globalState.isActive = false;
|
|
142
134
|
unbindEvents();
|
|
143
135
|
}
|
|
144
136
|
var unbindEvents = (0, _bindEventListener.bindAll)(window, [{
|
|
@@ -163,20 +155,13 @@ function start(_ref2) {
|
|
|
163
155
|
// 2. let consumers know a move has occurred
|
|
164
156
|
// This will include the latest 'input' values
|
|
165
157
|
dispatch.drag({
|
|
166
|
-
current: current
|
|
158
|
+
current: state.current
|
|
167
159
|
});
|
|
168
160
|
}
|
|
169
161
|
}, {
|
|
170
162
|
type: 'dragenter',
|
|
171
163
|
listener: onUpdateEvent
|
|
172
164
|
}, {
|
|
173
|
-
// This was the only reliable cross browser way I found to detect
|
|
174
|
-
// when the user is leaving the `window`.
|
|
175
|
-
// Internal drags: when we leave the `window` we want to clear any active drop targets,
|
|
176
|
-
// but the drag is not yet over. The user could drag back into the window.
|
|
177
|
-
// We only need to do this because of stickiness
|
|
178
|
-
// External drags: when we leave the `window` the drag operation is over,
|
|
179
|
-
// we will start another drag operation
|
|
180
165
|
type: 'dragleave',
|
|
181
166
|
listener: function listener(event) {
|
|
182
167
|
if (!(0, _isLeavingWindow.isLeavingWindow)({
|
|
@@ -185,45 +170,82 @@ function start(_ref2) {
|
|
|
185
170
|
return;
|
|
186
171
|
}
|
|
187
172
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
173
|
+
/**
|
|
174
|
+
* At this point we don't know if a drag is being cancelled,
|
|
175
|
+
* or if a drag is leaving the `window`.
|
|
176
|
+
*
|
|
177
|
+
* Both have:
|
|
178
|
+
* 1. "dragleave" (with `relatedTarget: null`)
|
|
179
|
+
* 2. "dragend" (a "dragend" can occur when outside the `window`)
|
|
180
|
+
*
|
|
181
|
+
* **Clearing drop targets**
|
|
182
|
+
*
|
|
183
|
+
* For either case we are clearing the the drop targets
|
|
184
|
+
*
|
|
185
|
+
* - cancelling: we clear drop targets in `"dragend"` anyway
|
|
186
|
+
* - leaving the `window`: we clear the drop targets (to clear stickiness)
|
|
187
|
+
*
|
|
188
|
+
* **Leaving the window and finishing the drag**
|
|
189
|
+
*
|
|
190
|
+
* _internal drags_
|
|
191
|
+
*
|
|
192
|
+
* - The drag continues when the user is outside the `window`
|
|
193
|
+
* and can resume if the user drags back over the `window`,
|
|
194
|
+
* or end when the user drops in an external `window`.
|
|
195
|
+
* - We will get a `"dragend"`, or we can listen for other
|
|
196
|
+
* events to determine the drag is finished when the user re-enters the `window`).
|
|
197
|
+
*
|
|
198
|
+
* _external drags_
|
|
199
|
+
*
|
|
200
|
+
* - We conclude the drag operation.
|
|
201
|
+
* - We have no idea if the user will drag back over the `window`,
|
|
202
|
+
* or if the drag ends elsewhere.
|
|
203
|
+
* - We will create a new drag if the user re-enters the `window`.
|
|
204
|
+
*
|
|
205
|
+
* **Not updating `input`**
|
|
206
|
+
*
|
|
207
|
+
* 🐛 Bug[Chrome] the final `"dragleave"` has default input values (eg `clientX == 0`)
|
|
208
|
+
* Workaround: intentionally not updating `input` in "dragleave"
|
|
209
|
+
* rather than the users current input values
|
|
210
|
+
* - [Conversation](https://twitter.com/alexandereardon/status/1642697633864241152)
|
|
211
|
+
* - [Bug](https://bugs.chromium.org/p/chromium/issues/detail?id=1429937)
|
|
212
|
+
**/
|
|
194
213
|
|
|
195
|
-
// 🐛 Bug workaround: intentionally not updating `input` in "dragleave"
|
|
196
|
-
// In Chrome, this final "dragleave" has default input values (eg clientX == 0)
|
|
197
|
-
// rather than the users current input values
|
|
198
|
-
//
|
|
199
|
-
// - [Conversation](https://twitter.com/alexandereardon/status/1642697633864241152)
|
|
200
|
-
// - [Bug](https://bugs.chromium.org/p/chromium/issues/detail?id=1429937)
|
|
201
214
|
updateDropTargets({
|
|
202
|
-
input: current.input,
|
|
215
|
+
input: state.current.input,
|
|
203
216
|
dropTargets: []
|
|
204
217
|
});
|
|
205
|
-
|
|
206
|
-
// End the drag operation if a native drag is leaving the window
|
|
207
218
|
if (dragType.startedFrom === 'external') {
|
|
208
|
-
cancel(
|
|
219
|
+
cancel({
|
|
220
|
+
dropEffect: 'none'
|
|
221
|
+
});
|
|
209
222
|
}
|
|
210
223
|
}
|
|
211
224
|
}, {
|
|
212
225
|
type: 'drop',
|
|
213
226
|
listener: function listener(event) {
|
|
227
|
+
var _event$dataTransfer$d, _event$dataTransfer;
|
|
214
228
|
// A "drop" can only happen if the browser allowed the drop
|
|
215
229
|
|
|
216
|
-
//
|
|
230
|
+
// Accepting drop operation.
|
|
231
|
+
// Also: opting out of standard browser drop behaviour for the drag
|
|
217
232
|
event.preventDefault();
|
|
218
233
|
|
|
219
234
|
// applying the latest drop effect to the event
|
|
220
|
-
|
|
235
|
+
setDropEffectOnEvent({
|
|
221
236
|
event: event,
|
|
222
|
-
current: current.dropTargets
|
|
237
|
+
current: state.current.dropTargets
|
|
223
238
|
});
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
239
|
+
dispatch.drop({
|
|
240
|
+
current: state.current,
|
|
241
|
+
drop: {
|
|
242
|
+
// At this point the dropEffect has been set on the event
|
|
243
|
+
// (if we have set it), so we can read it from there
|
|
244
|
+
dropEffect: (_event$dataTransfer$d = (_event$dataTransfer = event.dataTransfer) === null || _event$dataTransfer === void 0 ? void 0 : _event$dataTransfer.dropEffect) !== null && _event$dataTransfer$d !== void 0 ? _event$dataTransfer$d : 'none'
|
|
245
|
+
},
|
|
246
|
+
// When dropping something native, we need to extract the latest
|
|
247
|
+
// `.items` from the "drop" event as it is now accessible
|
|
248
|
+
updatedSourcePayload: dragType.type === 'external' ? dragType.getDropPayload(event) : null
|
|
227
249
|
});
|
|
228
250
|
finish();
|
|
229
251
|
|
|
@@ -231,30 +253,46 @@ function start(_ref2) {
|
|
|
231
253
|
// to update UI in response to a "onDrop".
|
|
232
254
|
if (dragType.startedFrom === 'internal') {
|
|
233
255
|
(0, _fixPostDragPointerBug.fixPostDragPointerBug)({
|
|
234
|
-
current: current
|
|
256
|
+
current: state.current
|
|
235
257
|
});
|
|
236
258
|
}
|
|
237
259
|
}
|
|
238
260
|
}, {
|
|
239
261
|
// "dragend" fires when on the drag source (eg a draggable element)
|
|
240
262
|
// when the drag is finished.
|
|
241
|
-
// "dragend" will fire after "drop"(if there was a successful drop)
|
|
263
|
+
// "dragend" will fire after "drop" (if there was a successful drop)
|
|
242
264
|
// "dragend" does not fire if the draggable source has been removed during the drag
|
|
243
265
|
// or for external drag sources (eg files)
|
|
266
|
+
|
|
267
|
+
// This "dragend" listener will not fire if there was a successful drop
|
|
268
|
+
// as we will have already removed the event listener
|
|
244
269
|
type: 'dragend',
|
|
245
|
-
listener: function listener() {
|
|
246
|
-
|
|
270
|
+
listener: function listener(event) {
|
|
271
|
+
var _event$dataTransfer$d2, _event$dataTransfer2;
|
|
272
|
+
// The `dropEffect` will be:
|
|
273
|
+
// - "none" if dropped on no drop targets
|
|
274
|
+
// - "none" if cancelled locally
|
|
275
|
+
// - "none" if cancelled externally
|
|
276
|
+
// - "none" if `preventUnhandled` is used (and there is no drop target)
|
|
277
|
+
// - [not "none"] if accepted externally
|
|
278
|
+
cancel({
|
|
279
|
+
dropEffect: (_event$dataTransfer$d2 = (_event$dataTransfer2 = event.dataTransfer) === null || _event$dataTransfer2 === void 0 ? void 0 : _event$dataTransfer2.dropEffect) !== null && _event$dataTransfer$d2 !== void 0 ? _event$dataTransfer$d2 : 'none'
|
|
280
|
+
});
|
|
247
281
|
|
|
248
282
|
// Applying this fix after `dispatch.drop` so that frameworks have the opportunity
|
|
249
283
|
// to update UI in response to a "onDrop".
|
|
250
284
|
if (dragType.startedFrom === 'internal') {
|
|
251
285
|
(0, _fixPostDragPointerBug.fixPostDragPointerBug)({
|
|
252
|
-
current: current
|
|
286
|
+
current: state.current
|
|
253
287
|
});
|
|
254
288
|
}
|
|
255
289
|
}
|
|
256
290
|
}].concat((0, _toConsumableArray2.default)((0, _detectBrokenDrag.getBindingsForBrokenDrags)({
|
|
257
|
-
onDragEnd:
|
|
291
|
+
onDragEnd: function onDragEnd() {
|
|
292
|
+
return cancel({
|
|
293
|
+
dropEffect: 'none'
|
|
294
|
+
});
|
|
295
|
+
}
|
|
258
296
|
}))),
|
|
259
297
|
// Once we have started a managed drag operation it is important that we see / own all drag events
|
|
260
298
|
// We got one adoption bug pop up where some code was stopping (`event.stopPropagation()`)
|
|
@@ -267,7 +305,7 @@ function start(_ref2) {
|
|
|
267
305
|
nativeSetDragImage: getNativeSetDragImage(event)
|
|
268
306
|
});
|
|
269
307
|
}
|
|
270
|
-
function
|
|
308
|
+
function setDropEffectOnEvent(_ref3) {
|
|
271
309
|
var _current$;
|
|
272
310
|
var event = _ref3.event,
|
|
273
311
|
current = _ref3.current;
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.preventUnhandled = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
7
9
|
var _bindEventListener = require("bind-event-listener");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// we don't need to do anything
|
|
10
|
+
var _detectBrokenDrag = require("../util/detect-broken-drag");
|
|
11
|
+
function acceptDrop(event) {
|
|
12
|
+
// if the event is already prevented the event we don't need to do anything
|
|
11
13
|
if (event.defaultPrevented) {
|
|
12
14
|
return;
|
|
13
15
|
}
|
|
14
16
|
// Using "move" as the drop effect as that uses the standard
|
|
15
17
|
// cursor. Doing this so the user doesn't think they are dropping
|
|
16
18
|
// on the page
|
|
17
|
-
// Note: using "none" will not allow a drop to occur, so we are using "move"
|
|
19
|
+
// Note: using "none" will not allow a "drop" to occur, so we are using "move"
|
|
18
20
|
if (event.dataTransfer) {
|
|
19
21
|
event.dataTransfer.dropEffect = 'move';
|
|
20
22
|
}
|
|
@@ -26,24 +28,55 @@ var unbindEvents = null;
|
|
|
26
28
|
/**
|
|
27
29
|
* Block drag operations outside of `@atlaskit/pragmatic-drag-and-drop`
|
|
28
30
|
*/
|
|
31
|
+
function start() {
|
|
32
|
+
cleanup();
|
|
33
|
+
unbindEvents = (0, _bindEventListener.bindAll)(window, [{
|
|
34
|
+
type: 'dragover',
|
|
35
|
+
listener: acceptDrop
|
|
36
|
+
}, {
|
|
37
|
+
type: 'dragenter',
|
|
38
|
+
listener: acceptDrop
|
|
39
|
+
}, {
|
|
40
|
+
type: 'drop',
|
|
41
|
+
listener: function listener(event) {
|
|
42
|
+
// our lifecycle manager already prevents events, but just being super safe
|
|
43
|
+
event.preventDefault();
|
|
44
|
+
|
|
45
|
+
// not setting dropEffect, as `drop.dropEffect` has already been published to the user
|
|
46
|
+
// (lifecycle-manager binds events in the capture phase)
|
|
47
|
+
|
|
48
|
+
// we don't need to wait for "dragend", and "dragend" might not even happen,
|
|
49
|
+
// such as when the draggable has been removed during a drag.
|
|
50
|
+
cleanup();
|
|
51
|
+
}
|
|
52
|
+
}, {
|
|
53
|
+
type: 'dragend',
|
|
54
|
+
listener: cleanup
|
|
55
|
+
}].concat((0, _toConsumableArray2.default)((0, _detectBrokenDrag.getBindingsForBrokenDrags)({
|
|
56
|
+
onDragEnd: cleanup
|
|
57
|
+
}))),
|
|
58
|
+
// being clear that these are added in the bubble phase
|
|
59
|
+
{
|
|
60
|
+
capture: false
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function cleanup() {
|
|
64
|
+
var _unbindEvents;
|
|
65
|
+
(_unbindEvents = unbindEvents) === null || _unbindEvents === void 0 || _unbindEvents();
|
|
66
|
+
unbindEvents = null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* TODO: for next major, we could look at do the following:
|
|
71
|
+
*
|
|
72
|
+
* ```diff
|
|
73
|
+
* - preventUnhandled.start();
|
|
74
|
+
* - preventUnhandled.stop();
|
|
75
|
+
* + const stop = preventUnhandled();
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
|
|
29
79
|
var preventUnhandled = exports.preventUnhandled = {
|
|
30
|
-
start:
|
|
31
|
-
|
|
32
|
-
(_unbindEvents = unbindEvents) === null || _unbindEvents === void 0 || _unbindEvents();
|
|
33
|
-
unbindEvents = (0, _bindEventListener.bindAll)(window, [{
|
|
34
|
-
type: 'dragover',
|
|
35
|
-
listener: cancel
|
|
36
|
-
}, {
|
|
37
|
-
type: 'dragenter',
|
|
38
|
-
listener: cancel
|
|
39
|
-
}, {
|
|
40
|
-
type: 'drop',
|
|
41
|
-
listener: cancel
|
|
42
|
-
}]);
|
|
43
|
-
},
|
|
44
|
-
stop: function stop() {
|
|
45
|
-
var _unbindEvents2;
|
|
46
|
-
(_unbindEvents2 = unbindEvents) === null || _unbindEvents2 === void 0 || _unbindEvents2();
|
|
47
|
-
unbindEvents = null;
|
|
48
|
-
}
|
|
80
|
+
start: start,
|
|
81
|
+
stop: cleanup
|
|
49
82
|
};
|
|
@@ -107,6 +107,7 @@ export function makeDispatch({
|
|
|
107
107
|
},
|
|
108
108
|
drop({
|
|
109
109
|
current,
|
|
110
|
+
drop,
|
|
110
111
|
updatedSourcePayload
|
|
111
112
|
}) {
|
|
112
113
|
dragStart.flush();
|
|
@@ -114,6 +115,7 @@ export function makeDispatch({
|
|
|
114
115
|
safeDispatch({
|
|
115
116
|
eventName: 'onDrop',
|
|
116
117
|
payload: {
|
|
118
|
+
drop,
|
|
117
119
|
source: updatedSourcePayload !== null && updatedSourcePayload !== void 0 ? updatedSourcePayload : source,
|
|
118
120
|
location: {
|
|
119
121
|
current,
|