@atlaskit/pragmatic-drag-and-drop 0.17.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.
Files changed (155) hide show
  1. package/CHANGELOG.md +209 -0
  2. package/LICENSE.md +13 -0
  3. package/README.md +43 -0
  4. package/__perf__/add-example.todo +1 -0
  5. package/adapter/element/package.json +15 -0
  6. package/adapter/file/package.json +15 -0
  7. package/addon/cancel-unhandled/package.json +15 -0
  8. package/constellation/index/about.mdx +329 -0
  9. package/constellation/index/props.mdx +3 -0
  10. package/dist/cjs/adapter/element-adapter.js +151 -0
  11. package/dist/cjs/adapter/file-adapter.js +98 -0
  12. package/dist/cjs/addon/cancel-unhandled.js +50 -0
  13. package/dist/cjs/entry-point/adapter/element.js +24 -0
  14. package/dist/cjs/entry-point/adapter/file.js +18 -0
  15. package/dist/cjs/entry-point/addon/cancel-unhandled.js +12 -0
  16. package/dist/cjs/entry-point/experimental/cross-with-element-adapter.js +30 -0
  17. package/dist/cjs/entry-point/types.js +5 -0
  18. package/dist/cjs/entry-point/util/combine.js +12 -0
  19. package/dist/cjs/entry-point/util/disable-native-drag-preview.js +12 -0
  20. package/dist/cjs/entry-point/util/once.js +12 -0
  21. package/dist/cjs/entry-point/util/reorder.js +12 -0
  22. package/dist/cjs/entry-point/util/scroll-just-enough-into-view.js +12 -0
  23. package/dist/cjs/entry-point/util/set-custom-native-drag-preview.js +12 -0
  24. package/dist/cjs/experimental/cross-window-element-adapter.js +131 -0
  25. package/dist/cjs/index.js +12 -0
  26. package/dist/cjs/internal-types.js +5 -0
  27. package/dist/cjs/ledger/dispatch-consumer-event.js +132 -0
  28. package/dist/cjs/ledger/lifecycle-manager.js +335 -0
  29. package/dist/cjs/ledger/usage-ledger.js +37 -0
  30. package/dist/cjs/make-adapter/make-adapter.js +59 -0
  31. package/dist/cjs/make-adapter/make-drop-target.js +271 -0
  32. package/dist/cjs/make-adapter/make-monitor.js +100 -0
  33. package/dist/cjs/util/add-attribute.js +14 -0
  34. package/dist/cjs/util/combine.js +17 -0
  35. package/dist/cjs/util/disable-native-drag-preview.js +36 -0
  36. package/dist/cjs/util/entering-and-leaving-the-window.js +162 -0
  37. package/dist/cjs/util/fix-post-drag-pointer-bug.js +114 -0
  38. package/dist/cjs/util/get-input.js +20 -0
  39. package/dist/cjs/util/once.js +22 -0
  40. package/dist/cjs/util/reorder.js +26 -0
  41. package/dist/cjs/util/scroll-just-enough-into-view.js +17 -0
  42. package/dist/cjs/util/set-custom-native-drag-preview.js +109 -0
  43. package/dist/cjs/version.json +5 -0
  44. package/dist/es2019/adapter/element-adapter.js +143 -0
  45. package/dist/es2019/adapter/file-adapter.js +90 -0
  46. package/dist/es2019/addon/cancel-unhandled.js +43 -0
  47. package/dist/es2019/entry-point/adapter/element.js +1 -0
  48. package/dist/es2019/entry-point/adapter/file.js +1 -0
  49. package/dist/es2019/entry-point/addon/cancel-unhandled.js +1 -0
  50. package/dist/es2019/entry-point/experimental/cross-with-element-adapter.js +1 -0
  51. package/dist/es2019/entry-point/types.js +1 -0
  52. package/dist/es2019/entry-point/util/combine.js +1 -0
  53. package/dist/es2019/entry-point/util/disable-native-drag-preview.js +1 -0
  54. package/dist/es2019/entry-point/util/once.js +1 -0
  55. package/dist/es2019/entry-point/util/reorder.js +1 -0
  56. package/dist/es2019/entry-point/util/scroll-just-enough-into-view.js +1 -0
  57. package/dist/es2019/entry-point/util/set-custom-native-drag-preview.js +1 -0
  58. package/dist/es2019/experimental/cross-window-element-adapter.js +121 -0
  59. package/dist/es2019/index.js +7 -0
  60. package/dist/es2019/internal-types.js +1 -0
  61. package/dist/es2019/ledger/dispatch-consumer-event.js +128 -0
  62. package/dist/es2019/ledger/lifecycle-manager.js +333 -0
  63. package/dist/es2019/ledger/usage-ledger.js +32 -0
  64. package/dist/es2019/make-adapter/make-adapter.js +55 -0
  65. package/dist/es2019/make-adapter/make-drop-target.js +233 -0
  66. package/dist/es2019/make-adapter/make-monitor.js +80 -0
  67. package/dist/es2019/util/add-attribute.js +7 -0
  68. package/dist/es2019/util/combine.js +6 -0
  69. package/dist/es2019/util/disable-native-drag-preview.js +31 -0
  70. package/dist/es2019/util/entering-and-leaving-the-window.js +159 -0
  71. package/dist/es2019/util/fix-post-drag-pointer-bug.js +110 -0
  72. package/dist/es2019/util/get-input.js +14 -0
  73. package/dist/es2019/util/once.js +13 -0
  74. package/dist/es2019/util/reorder.js +17 -0
  75. package/dist/es2019/util/scroll-just-enough-into-view.js +12 -0
  76. package/dist/es2019/util/set-custom-native-drag-preview.js +106 -0
  77. package/dist/es2019/version.json +5 -0
  78. package/dist/esm/adapter/element-adapter.js +142 -0
  79. package/dist/esm/adapter/file-adapter.js +90 -0
  80. package/dist/esm/addon/cancel-unhandled.js +43 -0
  81. package/dist/esm/entry-point/adapter/element.js +1 -0
  82. package/dist/esm/entry-point/adapter/file.js +1 -0
  83. package/dist/esm/entry-point/addon/cancel-unhandled.js +1 -0
  84. package/dist/esm/entry-point/experimental/cross-with-element-adapter.js +1 -0
  85. package/dist/esm/entry-point/types.js +1 -0
  86. package/dist/esm/entry-point/util/combine.js +1 -0
  87. package/dist/esm/entry-point/util/disable-native-drag-preview.js +1 -0
  88. package/dist/esm/entry-point/util/once.js +1 -0
  89. package/dist/esm/entry-point/util/reorder.js +1 -0
  90. package/dist/esm/entry-point/util/scroll-just-enough-into-view.js +1 -0
  91. package/dist/esm/entry-point/util/set-custom-native-drag-preview.js +1 -0
  92. package/dist/esm/experimental/cross-window-element-adapter.js +120 -0
  93. package/dist/esm/index.js +7 -0
  94. package/dist/esm/internal-types.js +1 -0
  95. package/dist/esm/ledger/dispatch-consumer-event.js +125 -0
  96. package/dist/esm/ledger/lifecycle-manager.js +328 -0
  97. package/dist/esm/ledger/usage-ledger.js +31 -0
  98. package/dist/esm/make-adapter/make-adapter.js +53 -0
  99. package/dist/esm/make-adapter/make-drop-target.js +264 -0
  100. package/dist/esm/make-adapter/make-monitor.js +93 -0
  101. package/dist/esm/util/add-attribute.js +8 -0
  102. package/dist/esm/util/combine.js +11 -0
  103. package/dist/esm/util/disable-native-drag-preview.js +30 -0
  104. package/dist/esm/util/entering-and-leaving-the-window.js +156 -0
  105. package/dist/esm/util/fix-post-drag-pointer-bug.js +108 -0
  106. package/dist/esm/util/get-input.js +14 -0
  107. package/dist/esm/util/once.js +16 -0
  108. package/dist/esm/util/reorder.js +19 -0
  109. package/dist/esm/util/scroll-just-enough-into-view.js +11 -0
  110. package/dist/esm/util/set-custom-native-drag-preview.js +104 -0
  111. package/dist/esm/version.json +5 -0
  112. package/dist/types/adapter/element-adapter.d.ts +42 -0
  113. package/dist/types/adapter/file-adapter.d.ts +18 -0
  114. package/dist/types/addon/cancel-unhandled.d.ts +7 -0
  115. package/dist/types/entry-point/adapter/element.d.ts +2 -0
  116. package/dist/types/entry-point/adapter/file.d.ts +2 -0
  117. package/dist/types/entry-point/addon/cancel-unhandled.d.ts +1 -0
  118. package/dist/types/entry-point/experimental/cross-with-element-adapter.d.ts +1 -0
  119. package/dist/types/entry-point/types.d.ts +1 -0
  120. package/dist/types/entry-point/util/combine.d.ts +1 -0
  121. package/dist/types/entry-point/util/disable-native-drag-preview.d.ts +1 -0
  122. package/dist/types/entry-point/util/once.d.ts +1 -0
  123. package/dist/types/entry-point/util/reorder.d.ts +1 -0
  124. package/dist/types/entry-point/util/scroll-just-enough-into-view.d.ts +1 -0
  125. package/dist/types/entry-point/util/set-custom-native-drag-preview.d.ts +1 -0
  126. package/dist/types/experimental/cross-window-element-adapter.d.ts +17 -0
  127. package/dist/types/index.d.ts +2 -0
  128. package/dist/types/internal-types.d.ts +275 -0
  129. package/dist/types/ledger/dispatch-consumer-event.d.ts +26 -0
  130. package/dist/types/ledger/lifecycle-manager.d.ts +16 -0
  131. package/dist/types/ledger/usage-ledger.d.ts +5 -0
  132. package/dist/types/make-adapter/make-adapter.d.ts +14 -0
  133. package/dist/types/make-adapter/make-drop-target.d.ts +5 -0
  134. package/dist/types/make-adapter/make-monitor.d.ts +8 -0
  135. package/dist/types/util/add-attribute.d.ts +5 -0
  136. package/dist/types/util/combine.d.ts +3 -0
  137. package/dist/types/util/disable-native-drag-preview.d.ts +3 -0
  138. package/dist/types/util/entering-and-leaving-the-window.d.ts +6 -0
  139. package/dist/types/util/fix-post-drag-pointer-bug.d.ts +14 -0
  140. package/dist/types/util/get-input.d.ts +2 -0
  141. package/dist/types/util/once.d.ts +2 -0
  142. package/dist/types/util/reorder.d.ts +9 -0
  143. package/dist/types/util/scroll-just-enough-into-view.d.ts +7 -0
  144. package/dist/types/util/set-custom-native-drag-preview.d.ts +52 -0
  145. package/experimental/cross-window-element-adapter/package.json +15 -0
  146. package/package.json +87 -0
  147. package/report.api.md +35 -0
  148. package/tmp/api-report-tmp.d.ts +13 -0
  149. package/types/package.json +15 -0
  150. package/util/combine/package.json +15 -0
  151. package/util/disable-native-drag-preview/package.json +15 -0
  152. package/util/once/package.json +15 -0
  153. package/util/reorder/package.json +15 -0
  154. package/util/scroll-just-enough-into-view/package.json +15 -0
  155. package/util/set-custom-native-drag-preview/package.json +15 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,209 @@
1
+ # @atlaskit/pragmatic-drag-and-drop
2
+
3
+ ## 0.17.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`34ed7b2ec63`](https://bitbucket.org/atlassian/atlassian-frontend/commits/34ed7b2ec63) - We have changed the name of our drag and drop packages to align on the single name of "Pragmatic drag and drop"
8
+
9
+ ```diff
10
+ - @atlaskit/drag-and-drop
11
+ + @atlaskit/pragmatic-drag-and-drop
12
+
13
+ - @atlaskit/drag-and-drop-autoscroll
14
+ + @atlaskit/pragmatic-drag-and-drop-autoscroll
15
+
16
+ - @atlaskit/drag-and-drop-hitbox
17
+ + @atlaskit/pragmatic-drag-and-drop-hitbox
18
+
19
+ - @atlaskit/drag-and-drop-indicator
20
+ + @atlaskit/pragmatic-drag-and-drop-react-indicator
21
+ # Note: `react` was added to this package name as our indicator package is designed for usage with `react`.
22
+
23
+ - @atlaskit/drag-and-drop-live-region
24
+ + @atlaskit/pragmatic-drag-and-drop-live-region
25
+
26
+ - @atlaskit/drag-and-drop-react-beautiful-dnd-migration
27
+ + @atlaskit/pragmatic-drag-and-drop-react-beautiful-dnd-migration
28
+
29
+ - @atlaskit/drag-and-drop-docs
30
+ + @atlaskit/pragmatic-drag-and-drop-docs
31
+ ```
32
+
33
+ The new `@atlaskit/pragmatic-drag-and-drop*` packages will start their initial versions from where the ``@atlaskit/drag-and-drop*` packages left off. Doing this will make it easier to look back on changelogs and see how the packages have progressed.
34
+
35
+ ## 0.16.0
36
+
37
+ ### Minor Changes
38
+
39
+ - [`56507598609`](https://bitbucket.org/atlassian/atlassian-frontend/commits/56507598609) - Skip minor dependency bump
40
+
41
+ ## 0.15.1
42
+
43
+ ### Patch Changes
44
+
45
+ - [`2e01c9c74b5`](https://bitbucket.org/atlassian/atlassian-frontend/commits/2e01c9c74b5) - DUMMY remove before merging to master; dupe adf-schema via adf-utils
46
+
47
+ ## 0.15.0
48
+
49
+ ### Minor Changes
50
+
51
+ - [`ed028658f13`](https://bitbucket.org/atlassian/atlassian-frontend/commits/ed028658f13) - Minor internal refactor and adding additional tests
52
+
53
+ ## 0.14.0
54
+
55
+ ### Minor Changes
56
+
57
+ - [`eab6d26451d`](https://bitbucket.org/atlassian/atlassian-frontend/commits/eab6d26451d) - Improving the resilience of our workaround for a [Browser bug](https://bugs.chromium.org/p/chromium/issues/detail?id=410328) where after a drag finishes, an unrelated element can be entered into.
58
+ - [`ba7ea570aee`](https://bitbucket.org/atlassian/atlassian-frontend/commits/ba7ea570aee) - > Both of these changes should not impact most consumers as they are targeted at edge cases.
59
+
60
+ - **Fix**: We no longer extract user input (eg `clientX`) from native `"dragleave"` events due to a [Bug with Chrome we discovered](https://bugs.chromium.org/p/chromium/issues/detail?id=1429937). Due to this bug, it was possible for `location.current.input` to be incorrectly set in `onDropTargetChange` and `onDrop` when a user was cancelling a drag or dropping or no drop targets.
61
+
62
+ - **Fix**: `location.previous.dropTargets` _should_ always point to the `location.current.dropTargets` value from the previous event (exception: `onGenerateDragPreview` and `onDragStart` have the same `location.previous` and `location.current` values). Previously, the `location.previous.dropTargets` value did not match the last events `location.current.dropTargets` value in `onDrop`. `onDrop()` would incorrectly use the `location.current` and `location.previous` values from the last event rather than creating a new `location.current` entry. Now, `onDrop()`, `location.previous.dropTargets` points to the `location.current.dropTargets` from the last event (same as all other events) and `location.current.dropTargets` points to what the previous drop target was as well (no change)
63
+
64
+ ## 0.13.0
65
+
66
+ ### Minor Changes
67
+
68
+ - [`2582df26509`](https://bitbucket.org/atlassian/atlassian-frontend/commits/2582df26509) - Fixing a browser bug where after a drag finishes, a unrelated element can be entered into by the browser
69
+
70
+ - [Visual explanation of bug](https://twitter.com/alexandereardon/status/1633614212873465856)
71
+ - [Chrome bug](https://bugs.chromium.org/p/chromium/issues/detail?id=410328)
72
+
73
+ ## 0.12.0
74
+
75
+ ### Minor Changes
76
+
77
+ - [`90901f5bbe0`](https://bitbucket.org/atlassian/atlassian-frontend/commits/90901f5bbe0) - Replace default entry point of `undefined` with `{}`.
78
+
79
+ > **NOTE:** Importing from the default entry point isn't supported.
80
+ > _Please use individual entry points in order to always obtain minimum kbs._
81
+
82
+ ## 0.11.0
83
+
84
+ ### Minor Changes
85
+
86
+ - [`1ecbb19d450`](https://bitbucket.org/atlassian/atlassian-frontend/commits/1ecbb19d450) - Adding a new function to make creating _custom_ native drag previews safe and easy: `setCustomNativeDragPreview`
87
+
88
+ ```tsx
89
+ import { setCustomNativeDragPreview } from '@atlaskit/drag-and-drop/util/set-custom-native-drag-preview';
90
+
91
+ draggable({
92
+ element: myElement,
93
+ onGenerateDragPreview: ({ nativeSetDragImage }) => {
94
+ setCustomNativeDragPreview({
95
+ render: function render({ container }) {
96
+ ReactDOM.render(<Preview item={item} />, container);
97
+ return function cleanup() {
98
+ ReactDOM.unmountComponentAtNode(container);
99
+ };
100
+ },
101
+ nativeSetDragImage,
102
+ });
103
+ },
104
+ });
105
+ ```
106
+
107
+ Please see our element adapter documentation for more detailed usage information
108
+
109
+ ## 0.10.0
110
+
111
+ ### Minor Changes
112
+
113
+ - [`9c0975e2fab`](https://bitbucket.org/atlassian/atlassian-frontend/commits/9c0975e2fab) - Bug fix: A _monitor_ should not be called after it is removed. Previously, if a _monitor_ (monitor 1) removed another _monitor_ (monitor 2) for the same event, then the second monitor (monitor 2) would still be called. This has been fixed
114
+
115
+ ```ts
116
+ const cleanupMonitor1 = monitorForElements({
117
+ onDragStart: () => {
118
+ cleanupMonitor2();
119
+ },
120
+ });
121
+ const cleanupMonitor2 = monitorForElements({
122
+ // Previously this `onDragStart` would have been called during `onDragStart` even though it was unbound by the first monitor
123
+ onDragStart: () => {},
124
+ });
125
+ ```
126
+
127
+ ## 0.9.0
128
+
129
+ ### Minor Changes
130
+
131
+ - [`03e0aa5ae85`](https://bitbucket.org/atlassian/atlassian-frontend/commits/03e0aa5ae85) - `@atlaskit/drag-and-drop` adds event listeners to the `window` during a drag operation. These drag operation event listeners were [`bubble` phase event listeners](https://domevents.dev/), but they are now `capture` phase event listeners to be more resliant against external code (incorrectly) stopping events.
132
+
133
+ This does not impact the ability of a consumer to have their own `draggable`s on a page not controlled by `@atlaskit/drag-and-drop`
134
+
135
+ ## 0.8.1
136
+
137
+ ### Patch Changes
138
+
139
+ - [`6455cf006b3`](https://bitbucket.org/atlassian/atlassian-frontend/commits/6455cf006b3) - Builds for this package now pass through a tokens babel plugin, removing runtime invocations of the tokens() function and improving performance.
140
+
141
+ ## 0.8.0
142
+
143
+ ### Minor Changes
144
+
145
+ - [`1e3f9743e57`](https://bitbucket.org/atlassian/atlassian-frontend/commits/1e3f9743e57) - A _monitor_ that is added during an event (eg `onDragStart`) will no longer be called for the current event. This is to prevent the accidental creation of infinite loops. This behaviour matches native [`EventTargets`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget) where an event listener cannot add another event listener during an active event to the same event target in the same event phase.
146
+
147
+ ## 0.7.1
148
+
149
+ ### Patch Changes
150
+
151
+ - [`8cc2f888c83`](https://bitbucket.org/atlassian/atlassian-frontend/commits/8cc2f888c83) - Upgrade Typescript from `4.3.5` to `4.5.5`
152
+
153
+ ## 0.7.0
154
+
155
+ ### Minor Changes
156
+
157
+ - [`f2a7931d609`](https://bitbucket.org/atlassian/atlassian-frontend/commits/f2a7931d609) - Adding jsdoc to DragLocation type for better autocomplete
158
+
159
+ ## 0.6.0
160
+
161
+ ### Minor Changes
162
+
163
+ - [`0f755214ee7`](https://bitbucket.org/atlassian/atlassian-frontend/commits/0f755214ee7) - Internal folder renaming. No API impact
164
+
165
+ ## 0.5.0
166
+
167
+ ### Minor Changes
168
+
169
+ - [`17950433a70`](https://bitbucket.org/atlassian/atlassian-frontend/commits/17950433a70) - Touching package to release re-release previous version. The previous (now deprecated) version did not have it's entry points built correctly
170
+
171
+ ## 0.4.0
172
+
173
+ ### Minor Changes
174
+
175
+ - [`4d739042b04`](https://bitbucket.org/atlassian/atlassian-frontend/commits/4d739042b04) - Improving jsdoc auto complete information for `GetFeedbackArgs`
176
+
177
+ ## 0.3.0
178
+
179
+ ### Minor Changes
180
+
181
+ - [`52403a2c11f`](https://bitbucket.org/atlassian/atlassian-frontend/commits/52403a2c11f) - Adding a `canMonitor()` function to _monitors_ to allow a _monitor_ to conditionally apply to a drag operation.
182
+
183
+ ```ts
184
+ monitorForElements({
185
+ canMonitor: ({ source }) => source.data.type === 'card',
186
+ onDragStart: () =>
187
+ console.log('I will only be activated when dragging a card!'),
188
+ });
189
+ ```
190
+
191
+ ## 0.2.0
192
+
193
+ ### Minor Changes
194
+
195
+ - [`1cf9e484b4b`](https://bitbucket.org/atlassian/atlassian-frontend/commits/1cf9e484b4b) - We have improved our naming consistency across our drag and drop packages.
196
+
197
+ - `@atlaskit/drag-and-drop/util/cancel-unhandled` has been renamed to `@atlaskit/drag-and-drop/addon/cancel-unhandled`
198
+
199
+ ## 0.1.0
200
+
201
+ ### Minor Changes
202
+
203
+ - [`73427c38077`](https://bitbucket.org/atlassian/atlassian-frontend/commits/73427c38077) - Initial release of `@atlaskit/drag-and-drop` packages 🎉
204
+
205
+ ## 0.0.1
206
+
207
+ ### Patch Changes
208
+
209
+ - [`8d4228767b0`](https://bitbucket.org/atlassian/atlassian-frontend/commits/8d4228767b0) - Upgrade Typescript from `4.2.4` to `4.3.5`.
package/LICENSE.md ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2022 Atlassian Pty Ltd
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Pragmatic drag and drop
2
+
3
+ A performance optimized drag and drop framework
4
+
5
+ > ℹ️ This package is in early access. We have not yet guaranteed API stability
6
+
7
+ ## Background
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/atlassian-drag-and-drop/).
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@atlaskit/pragmatic-drag-and-drop/adapter/element",
3
+ "main": "../../dist/cjs/entry-point/adapter/element.js",
4
+ "module": "../../dist/esm/entry-point/adapter/element.js",
5
+ "module:es2019": "../../dist/es2019/entry-point/adapter/element.js",
6
+ "sideEffects": false,
7
+ "types": "../../dist/types/entry-point/adapter/element.d.ts",
8
+ "typesVersions": {
9
+ ">=4.0 <4.5": {
10
+ "*": [
11
+ "../../dist/types-ts4.0/entry-point/adapter/element.d.ts"
12
+ ]
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@atlaskit/pragmatic-drag-and-drop/adapter/file",
3
+ "main": "../../dist/cjs/entry-point/adapter/file.js",
4
+ "module": "../../dist/esm/entry-point/adapter/file.js",
5
+ "module:es2019": "../../dist/es2019/entry-point/adapter/file.js",
6
+ "sideEffects": false,
7
+ "types": "../../dist/types/entry-point/adapter/file.d.ts",
8
+ "typesVersions": {
9
+ ">=4.0 <4.5": {
10
+ "*": [
11
+ "../../dist/types-ts4.0/entry-point/adapter/file.d.ts"
12
+ ]
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@atlaskit/pragmatic-drag-and-drop/addon/cancel-unhandled",
3
+ "main": "../../dist/cjs/entry-point/addon/cancel-unhandled.js",
4
+ "module": "../../dist/esm/entry-point/addon/cancel-unhandled.js",
5
+ "module:es2019": "../../dist/es2019/entry-point/addon/cancel-unhandled.js",
6
+ "sideEffects": false,
7
+ "types": "../../dist/types/entry-point/addon/cancel-unhandled.d.ts",
8
+ "typesVersions": {
9
+ ">=4.0 <4.5": {
10
+ "*": [
11
+ "../../dist/types-ts4.0/entry-point/addon/cancel-unhandled.d.ts"
12
+ ]
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,329 @@
1
+ ---
2
+ order: 0
3
+ ---
4
+
5
+ import SectionMessage from '@atlaskit/section-message';
6
+
7
+ <!-- I'd like to change this section to be called Drag-and-drop or something, not Core, but still mulling it over. -->
8
+
9
+ This package contains the essential pieces of the system, and is not tied to any JavaScript framework.
10
+
11
+ - The [element adapter](/components/drag-and-drop/adapter/element-adapter) powers drag operations of elements.
12
+ - The [file adapter](/components/drag-and-drop/adapter/file-adapter) powers drag operations of external files.
13
+ - All of the base TypeScript types of Pragmatic drag and drop are in `@atlaskit/pragmatic-drag-and-drop/types`.
14
+
15
+ ## Addons
16
+
17
+ ### Cancel unhandled
18
+
19
+ ```ts
20
+ import { cancelUnhandled } from '@atlaskit/pragmatic-drag-and-drop/addon/cancel-unhandled';
21
+ ```
22
+
23
+ An _addon_ that absorbs unhandled drags. Using this function will mean that drops that don't occur in a _drop target_ will be _swallowed_ and the standard browser behaviour will not occur. This _addon_ is useful when disabling the native drag preview and for file drag operations
24
+
25
+ ```ts
26
+ import { monitorForFiles } from '@atlaskit/pragmatic-drag-and-drop/adapter/file';
27
+ import { cancelUnhandled } from '@atlaskit/pragmatic-drag-and-drop/addon/cancel-unhandled';
28
+
29
+ monitorForFiles({
30
+ onDragStart: () => {
31
+ // when any drag starts for files block unhandled drags
32
+ cancelUnhandled.start();
33
+ },
34
+ onDrop: () => {
35
+ // resume standard behaviour when the drag is finished
36
+ cancelUnhandled.stop();
37
+ },
38
+ });
39
+ ```
40
+
41
+ ## Utilities
42
+
43
+ ### Combine cleanup functions
44
+
45
+ Combines the cleanup functions returned by _draggables_, _drop targets_ and _monitors_.
46
+
47
+ ```ts
48
+ import { combine } from '@atlaskit/pragmatic-drag-and-drop/util/combine';
49
+ ```
50
+
51
+ _Draggables_, _drop targets_ and _monitors_ return a cleanup function.
52
+
53
+ ```ts
54
+ import { CleanupFn } from '@atlaskit/pragmatic-drag-and-drop/types';
55
+ import { draggable } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
56
+
57
+ const cleanup: CleanupFn = draggable({ element: myElement });
58
+
59
+ // unbind functionality
60
+ cleanup();
61
+ ```
62
+
63
+ Sometimes you might be creating a whole lot of cleanup functions:
64
+
65
+ ```ts
66
+ const cleanupDraggable: CleanupFn = draggable({ element: myElement });
67
+ const cleanupDropTarget: CleanupFn = dropTargetForElements({
68
+ element: myElement,
69
+ });
70
+ const cleanupMonitor: CleanupFn = monitorForElements({ element: myElement });
71
+
72
+ // unbind all functionality:
73
+ cleanupDraggable();
74
+ cleanupDropTarget();
75
+ cleanupMonitor();
76
+ ```
77
+
78
+ The `combine` utility smooshes multiple cleanup functions into a single cleanup function.
79
+
80
+ ```ts
81
+ const cleanup: CleanupFn = combine(
82
+ draggable({ element: myElement }),
83
+ dropTargetForElements({
84
+ element: myElement,
85
+ }),
86
+ monitorForElements({ element: myElement }),
87
+ );
88
+
89
+ // unbind all functionality:
90
+ cleanup();
91
+ ```
92
+
93
+ Using `combine()` is helpful when working with `react` effects:
94
+
95
+ ```ts
96
+ useEffect(() => {
97
+ const cleanup: CleanupFn = combine(
98
+ draggable({ element: myElement }),
99
+ dropTargetForElements({
100
+ element: myElement,
101
+ }),
102
+ monitorForElements({ element: myElement }),
103
+ );
104
+ return cleanup;
105
+ }, []);
106
+
107
+ // or even simpler:
108
+ useEffect(() => {
109
+ return combine(
110
+ draggable({ element: myElement }),
111
+ dropTargetForElements({
112
+ element: myElement,
113
+ }),
114
+ monitorForElements({ element: myElement }),
115
+ );
116
+ }, []);
117
+ ```
118
+
119
+ ### Once
120
+
121
+ A function that will only allow the provided function to be called once.
122
+
123
+ ```ts
124
+ import { once } from '@atlaskit/pragmatic-drag-and-drop/util/once';
125
+ ```
126
+
127
+ This is useful if your drop target `getData()` is expensive to calculate.
128
+
129
+ ```ts
130
+ dropTargetForFiles({
131
+ getData: once(getExpensiveData),
132
+ });
133
+ ```
134
+
135
+ ```ts
136
+ // calculate your data outside of get data
137
+ const data = getExpensiveData();
138
+ dropTargetForFiles({
139
+ getData: () => data,
140
+ });
141
+ ```
142
+
143
+ ```ts
144
+ // have expensive data along with updated addons
145
+ const getDataOnce = once(getExpensiveData);
146
+ dropTargetForFiles({
147
+ getData: ({ input, element }) => {
148
+ const data = getDataOnce();
149
+ return attachClosestEdge(data, { input, element, allowedEdges: ['top'] });
150
+ },
151
+ });
152
+ ```
153
+
154
+ ### Reorder array
155
+
156
+ A function to make common array reordering operations easier.
157
+
158
+ ```ts
159
+ import { reorder } from '@atlaskit/pragmatic-drag-and-drop/util/reorder';
160
+ ```
161
+
162
+ This is useful when you want to reorder items in a list. `reorder` returns a new array and does not modify the provided `list`.
163
+
164
+ ```ts
165
+ const reordered = reorder({
166
+ list: [A, B, C],
167
+ startIndex: 0,
168
+ finishIndex: 1,
169
+ });
170
+ console.log(reordered); // [B, A, C]
171
+ ```
172
+
173
+ ### Set a custom native drag preview
174
+
175
+ You can use `setCustomNativeDragPreview` to mount a new element to the page to be used as the drag preview. `setCustomNativeDragPreview` will call your `cleanup` function to remove the preview element from the page after the browser has taken a photo of the element. `setCustomNativeDragPreview` adds the `container` `Element` to the `document.body` and will remove the `container` `Element` after your `cleanup` function is called.
176
+
177
+ `setCustomNativeDragPreview` has been designed to work with any view abstraction
178
+
179
+ ```ts
180
+ import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/util/set-custom-native-drag-preview';
181
+ ```
182
+
183
+ #### Usage example: `react` portals
184
+
185
+ This technique requires your component to be re-rendered, but maintains the current `react` `context`
186
+
187
+ ```tsx
188
+ type State =
189
+ | {
190
+ type: 'idle';
191
+ }
192
+ | {
193
+ type: 'preview';
194
+ container: HTMLElement;
195
+ };
196
+
197
+ function Item() {
198
+ const [state, setState] = useState<State>({ type: 'idle' });
199
+ const ref = useRef<HTMLDivElement | null>(null);
200
+
201
+ useEffect(() => {
202
+ invariant(ref.current);
203
+
204
+ return draggable({
205
+ element: ref.current,
206
+ onGenerateDragPreview({ nativeSetDragImage }) {
207
+ setCustomNativeDragPreview({
208
+ render({ container }) {
209
+ // Cause a `react` re-render to create your portal synchronously
210
+ setState({ type: 'preview', container });
211
+ // In our cleanup function: cause a `react` re-render to create remove your portal
212
+ // Note: you can also remove the portal in `onDragStart`,
213
+ // which is when the cleanup function is called
214
+ return () => setState({ type: 'idle' });
215
+ },
216
+ nativeSetDragImage,
217
+ });
218
+ },
219
+ });
220
+ }, []);
221
+
222
+ return (
223
+ <>
224
+ <div ref={ref}>Drag Me</div>
225
+ {state.type === 'preview'
226
+ ? ReactDOM.createPortal(<Preview />, state.container)
227
+ : null}
228
+ </>
229
+ );
230
+ }
231
+ ```
232
+
233
+ #### Usage example: A new `react` application
234
+
235
+ This technique requires no re-rendering of your component, but does not maintain the current `react` `context`
236
+
237
+
238
+ ```tsx
239
+ import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/util/set-custom-native-drag-preview';
240
+
241
+ draggable({
242
+ element: myElement,
243
+ onGenerateDragPreview: ({ nativeSetDragImage }) => {
244
+ setCustomNativeDragPreview({
245
+ render: function render({ container }) {
246
+ ReactDOM.render(<Preview item={item} />, container);
247
+ return function cleanup() {
248
+ ReactDOM.unmountComponentAtNode(container);
249
+ };
250
+ },
251
+ nativeSetDragImage,
252
+ });
253
+ },
254
+ });
255
+ ```
256
+
257
+ #### Placement
258
+
259
+ You can control where the custom native drag preview is placed by using the `placement` argument:
260
+
261
+ - `type: 'center'`: Place the center of the drag preview user the users pointer
262
+ - `type: 'offset-from-pointer'`: Shift the drag preview away from the users pointer
263
+
264
+ ```tsx
265
+ import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/util/set-custom-native-drag-preview';
266
+
267
+ draggable({
268
+ element: myElement,
269
+ onGenerateDragPreview: ({ nativeSetDragImage }) => {
270
+ setCustomNativeDragPreview({
271
+ placement: { type: 'offset-from-pointer', x: '16px', y: '8px' },
272
+ render: function render({ container }) {
273
+ ReactDOM.render(<Preview item={item} />, container);
274
+ return function cleanup() {
275
+ ReactDOM.unmountComponentAtNode(container);
276
+ };
277
+ },
278
+ nativeSetDragImage,
279
+ });
280
+ },
281
+ });
282
+ ```
283
+
284
+ ### Disable native drag preview
285
+
286
+ In some situations, you might want to disable the native drag preview. The `disableNativeDragPreview` utility does this for all supported browsers and platforms.
287
+
288
+ ```ts
289
+ import { disableNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/util/disable-native-drag-preview';
290
+ ```
291
+
292
+ ```ts
293
+ import { disableNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/util/disable-native-drag-preview';
294
+
295
+ draggable({
296
+ element: myElement,
297
+ onGenerateDragPreview({ setNativeDragPreview }) {
298
+ disableNativeDragPreview({ setNativeDragPreview });
299
+ },
300
+ });
301
+ ```
302
+
303
+ ### Scroll just enough into view
304
+
305
+ A function that scrolls a draggable element just enough into view so that the element becomes totally visible. If the element is already fully visible, then no scrolling will occur.
306
+
307
+ ```ts
308
+ import { scrollJustEnoughIntoView } from '@atlaskit/pragmatic-drag-and-drop/util/scroll-just-enough-into-view';
309
+ ```
310
+
311
+ Useful to avoid having drag previews cut off by scroll containers. See [element adapter](/components/drag-and-drop/adapter/element-adapter) for more information.
312
+
313
+ ```ts
314
+ import { scrollJustEnoughIntoView } from '@atlaskit/pragmatic-drag-and-drop/util/scroll-just-enough-into-view';
315
+ import { draggable } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
316
+
317
+ draggable({
318
+ element: myElement,
319
+ onGenerateDragPreview: ({ source }) => {
320
+ scrollJustEnoughIntoView({ element: source.element });
321
+ },
322
+ });
323
+ ```
324
+
325
+ <SectionMessage>
326
+
327
+ We don't bake `scrollJustEnoughIntoView` into Pragmatic drag and drop, as it may not be the best approach in all circumstances (for example, you might be making a small drag preview for a large draggable element, or you might be opting out of the native drag preview)
328
+
329
+ </SectionMessage>
@@ -0,0 +1,3 @@
1
+ ---
2
+ order: 3
3
+ ---