@atlaskit/pragmatic-drag-and-drop 0.21.0 → 0.23.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,64 @@
1
1
  # @atlaskit/pragmatic-drag-and-drop
2
2
 
3
+ ## 0.23.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`3da89e29dfc`](https://bitbucket.org/atlassian/atlassian-frontend/commits/3da89e29dfc) - We have renamed and tweaked the recently added `setCustomNativeDragPreview` `getOffset` utility `preserveOffsetFromPointer` to be a bit easier to understand what it is doing.
8
+
9
+ ```diff
10
+ - import { preserveOffsetFromPointer } from '@atlaskit/pragmatic-drag-and-drop/util/preserve-offset-from-pointer';
11
+ + import { preserveOffsetOnSource } from '@atlaskit/pragmatic-drag-and-drop/util/preserve-offset-on-source';
12
+
13
+ draggable({
14
+ element: myElement,
15
+ onGenerateDragPreview: ({ nativeSetDragImage, location, source }) => {
16
+ setCustomNativeDragPreview({
17
+ - getOffset: preserveOffsetFromPointer({
18
+ + 'preserveOffsetOnSource' is a more accurate description of what is being achieved
19
+ + getOffset: preserveOffsetOnSource({
20
+ - sourceElement: source.element,
21
+ + // no longer including 'source' in argument name
22
+ + // as it is implied by the function name
23
+ + element: source.element,
24
+ input: location.current.input,
25
+ }),
26
+ render: function render({ container }) {
27
+ /* ... */
28
+ },
29
+ nativeSetDragImage,
30
+ });
31
+ },
32
+ });
33
+ ```
34
+
35
+ ## 0.22.0
36
+
37
+ ### Minor Changes
38
+
39
+ - [`d644a68ddf6`](https://bitbucket.org/atlassian/atlassian-frontend/commits/d644a68ddf6) - Added a new `setCustomNativeDragPreview` `getOffset` utility: `preserveOffsetFromPointer`. `preserveOffsetFromPointer` mimics the default behaviour for non custom drag previews when starting a drag: the initial cursor position offset is preserved for a seamless drag and drop experience.
40
+
41
+ ```ts
42
+ import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/util/set-custom-native-drag-preview';
43
+ import { preserveOffsetFromPointer } from '@atlaskit/pragmatic-drag-and-drop/util/preserve-offset-from-pointer';
44
+
45
+ draggable({
46
+ element: myElement,
47
+ onGenerateDragPreview: ({ nativeSetDragImage, location, source }) => {
48
+ setCustomNativeDragPreview({
49
+ getOffset: preserveOffsetFromPointer({
50
+ sourceElement: source.element,
51
+ input: location.current.input,
52
+ }),
53
+ render: function render({ container }) {
54
+ /* ... */
55
+ },
56
+ nativeSetDragImage,
57
+ });
58
+ },
59
+ });
60
+ ```
61
+
3
62
  ## 0.21.0
4
63
 
5
64
  ### Minor Changes
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "preserveOffsetOnSource", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _preserveOffsetOnSource.preserveOffsetOnSource;
10
+ }
11
+ });
12
+ var _preserveOffsetOnSource = require("../../util/custom-native-drag-preview/preserve-offset-on-source");
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.preserveOffsetOnSource = preserveOffsetOnSource;
7
+ function preserveOffsetOnSource(_ref) {
8
+ var element = _ref.element,
9
+ input = _ref.input;
10
+ return function (_ref2) {
11
+ var container = _ref2.container;
12
+ var sourceRect = element.getBoundingClientRect();
13
+ var containerRect = container.getBoundingClientRect();
14
+ var offsetX = Math.min(
15
+ // difference
16
+ input.clientX - sourceRect.x,
17
+ // don't let the difference be more than the width of the container,
18
+ // otherwise the pointer will be off the preview
19
+ containerRect.width);
20
+ var offsetY = Math.min(
21
+ // difference
22
+ input.clientY - sourceRect.y,
23
+ // don't let the difference be more than the height of the container,
24
+ // otherwise the pointer will be off the preview
25
+ containerRect.height);
26
+ return {
27
+ x: offsetX,
28
+ y: offsetY
29
+ };
30
+ };
31
+ }
@@ -0,0 +1 @@
1
+ export { preserveOffsetOnSource } from '../../util/custom-native-drag-preview/preserve-offset-on-source';
@@ -0,0 +1,27 @@
1
+ export function preserveOffsetOnSource({
2
+ element,
3
+ input
4
+ }) {
5
+ return ({
6
+ container
7
+ }) => {
8
+ const sourceRect = element.getBoundingClientRect();
9
+ const containerRect = container.getBoundingClientRect();
10
+ const offsetX = Math.min(
11
+ // difference
12
+ input.clientX - sourceRect.x,
13
+ // don't let the difference be more than the width of the container,
14
+ // otherwise the pointer will be off the preview
15
+ containerRect.width);
16
+ const offsetY = Math.min(
17
+ // difference
18
+ input.clientY - sourceRect.y,
19
+ // don't let the difference be more than the height of the container,
20
+ // otherwise the pointer will be off the preview
21
+ containerRect.height);
22
+ return {
23
+ x: offsetX,
24
+ y: offsetY
25
+ };
26
+ };
27
+ }
@@ -0,0 +1 @@
1
+ export { preserveOffsetOnSource } from '../../util/custom-native-drag-preview/preserve-offset-on-source';
@@ -0,0 +1,25 @@
1
+ export function preserveOffsetOnSource(_ref) {
2
+ var element = _ref.element,
3
+ input = _ref.input;
4
+ return function (_ref2) {
5
+ var container = _ref2.container;
6
+ var sourceRect = element.getBoundingClientRect();
7
+ var containerRect = container.getBoundingClientRect();
8
+ var offsetX = Math.min(
9
+ // difference
10
+ input.clientX - sourceRect.x,
11
+ // don't let the difference be more than the width of the container,
12
+ // otherwise the pointer will be off the preview
13
+ containerRect.width);
14
+ var offsetY = Math.min(
15
+ // difference
16
+ input.clientY - sourceRect.y,
17
+ // don't let the difference be more than the height of the container,
18
+ // otherwise the pointer will be off the preview
19
+ containerRect.height);
20
+ return {
21
+ x: offsetX,
22
+ y: offsetY
23
+ };
24
+ };
25
+ }
@@ -0,0 +1 @@
1
+ export { preserveOffsetOnSource } from '../../util/custom-native-drag-preview/preserve-offset-on-source';
@@ -0,0 +1,6 @@
1
+ import { Input } from '../../entry-point/types';
2
+ import type { GetOffsetFn } from './types';
3
+ export declare function preserveOffsetOnSource({ element, input, }: {
4
+ element: HTMLElement;
5
+ input: Input;
6
+ }): GetOffsetFn;
@@ -0,0 +1 @@
1
+ export { preserveOffsetOnSource } from '../../util/custom-native-drag-preview/preserve-offset-on-source';
@@ -0,0 +1,6 @@
1
+ import { Input } from '../../entry-point/types';
2
+ import type { GetOffsetFn } from './types';
3
+ export declare function preserveOffsetOnSource({ element, input, }: {
4
+ element: HTMLElement;
5
+ input: Input;
6
+ }): GetOffsetFn;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/pragmatic-drag-and-drop",
3
- "version": "0.21.0",
3
+ "version": "0.23.0",
4
4
  "description": "The core Pragmatic drag and drop framework, optimized for performance.",
5
5
  "repository": "https://bitbucket.org/atlassian/atlassian-frontend-mirror",
6
6
  "author": "Atlassian Pty Ltd",
@@ -46,6 +46,7 @@
46
46
  "./util/set-custom-native-drag-preview": "./src/entry-point/util/set-custom-native-drag-preview.ts",
47
47
  "./util/offset-from-pointer": "./src/entry-point/util/offset-from-pointer.ts",
48
48
  "./util/center-under-pointer": "./src/entry-point/util/center-under-pointer.ts",
49
+ "./util/preserve-offset-on-source": "./src/entry-point/util/preserve-offset-on-source.ts",
49
50
  "./util/disable-native-drag-preview": "./src/entry-point/util/disable-native-drag-preview.ts",
50
51
  "./util/scroll-just-enough-into-view": "./src/entry-point/util/scroll-just-enough-into-view.ts",
51
52
  "./experimental/cross-window-element-adapter": "./src/entry-point/experimental/cross-with-element-adapter.ts"
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@atlaskit/pragmatic-drag-and-drop/util/preserve-offset-on-source",
3
+ "main": "../../dist/cjs/entry-point/util/preserve-offset-on-source.js",
4
+ "module": "../../dist/esm/entry-point/util/preserve-offset-on-source.js",
5
+ "module:es2019": "../../dist/es2019/entry-point/util/preserve-offset-on-source.js",
6
+ "sideEffects": false,
7
+ "types": "../../dist/types/entry-point/util/preserve-offset-on-source.d.ts",
8
+ "typesVersions": {
9
+ ">=4.5 <4.9": {
10
+ "*": [
11
+ "../../dist/types-ts4.5/entry-point/util/preserve-offset-on-source.d.ts"
12
+ ]
13
+ }
14
+ }
15
+ }
@@ -1,5 +0,0 @@
1
- {
2
- "name": "@atlaskit/pragmatic-drag-and-drop",
3
- "version": "0.21.0",
4
- "sideEffects": false
5
- }
@@ -1,5 +0,0 @@
1
- {
2
- "name": "@atlaskit/pragmatic-drag-and-drop",
3
- "version": "0.21.0",
4
- "sideEffects": false
5
- }
@@ -1,5 +0,0 @@
1
- {
2
- "name": "@atlaskit/pragmatic-drag-and-drop",
3
- "version": "0.21.0",
4
- "sideEffects": false
5
- }