@marsio/vue-draggable 1.0.2 → 1.0.3
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/README.md +86 -46
- package/build/cjs/Draggable.js +57 -25
- package/build/cjs/DraggableCore.js +44 -21
- package/build/cjs/utils/domFns.js +221 -97
- package/build/cjs/utils/log.js +2 -3
- package/build/cjs/utils/positionFns.js +86 -68
- package/build/cjs/utils/shims.js +45 -6
- package/build/cjs/utils/types.js +10 -2
- package/build/web/vue-draggable.min.js +1 -2
- package/package.json +33 -11
- package/LICENSE +0 -21
- package/build/cjs/utils/test.js +0 -12
- package/build/web/vue-draggable.min.js.LICENSE.txt +0 -6
package/README.md
CHANGED
|
@@ -1,11 +1,89 @@
|
|
|
1
|
-
# Vue-Draggable
|
|
2
|
-
|
|
1
|
+
# Vue-Draggable
|
|
3
2
|
|
|
3
|
+
Draggable and DraggableCore are **Vue3** components designed to make elements draggable within a Vue application. They provide a flexible and powerful way to add drag-and-drop functionality to your Vue components.
|
|
4
4
|
|
|
5
5
|
<p align="center">
|
|
6
6
|
<img src="https://user-images.githubusercontent.com/6365230/95649276-f3a02480-0b06-11eb-8504-e0614a780ba4.gif" />
|
|
7
7
|
</p>
|
|
8
8
|
|
|
9
|
+
## Features
|
|
10
|
+
- **Drag Handlers**: Offers customizable drag handlers (`startFn`, `dragFn`, `stopFn`) that allow developers to hook into drag start, during drag, and drag stop events, providing flexibility in handling these events.
|
|
11
|
+
- **Position Control**: Supports controlled (`position`) and uncontrolled (`defaultPosition`) modes for element positioning, giving developers the choice to manage the draggable element's position externally or let the component handle it internally.
|
|
12
|
+
- **Axis Constraints**: Allows dragging to be constrained along a specific axis (`axis`) with options for 'x', 'y', 'both', or 'none', enabling more precise control over the draggable behavior.
|
|
13
|
+
- **Bounds Limitation**: Supports constraining the draggable area within specified bounds (`bounds`), which can be defined as an object with `left`, `right`, `top`, and `bottom` properties, a selector string, or `false` for no bounds.
|
|
14
|
+
- **Position Offset**: Supports an offset for the draggable position (`positionOffset`), enabling adjustments to the element's position without altering its actual position properties.
|
|
15
|
+
- **Grid Snapping**: Allows the draggable element to snap to a grid (`grid` prop), facilitating alignment and precise placement during dragging.
|
|
16
|
+
- **Accessibility and Interaction**: Includes props for disabling the draggable functionality (`disabled`), allowing any mouse button to initiate dragging (`allowAnyClick`), and enabling a hack to prevent text selection during drag (`enableUserSelectHack`), enhancing usability and accessibility.
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
To quickly start using `@marsio/vue-draggable`, follow the steps below:
|
|
21
|
+
|
|
22
|
+
### Step 1: Installation
|
|
23
|
+
|
|
24
|
+
First, you need to install the package. Run the following command in your project directory:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install @marsio/vue-draggable
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
or if you prefer using Yarn:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
yarn add @marsio/vue-draggable
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
or if you prefer using Pnpm:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pnpm add @marsio/vue-draggable
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
### Step 2: Importing
|
|
44
|
+
|
|
45
|
+
In your Vue component, import `@marsio/vue-draggable`:
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
import Draggable from '@marsio/vue-draggable';
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Step 3: Using `@marsio/vue-draggable`
|
|
52
|
+
|
|
53
|
+
Now, you can use the `Draggable` component in your Vue application. Wrap any element with `<Draggable>` to make it draggable:
|
|
54
|
+
|
|
55
|
+
```vue
|
|
56
|
+
<template>
|
|
57
|
+
<Draggable>
|
|
58
|
+
<div class="draggable-item">I can now be moved around!</div>
|
|
59
|
+
</Draggable>
|
|
60
|
+
</template>
|
|
61
|
+
|
|
62
|
+
<script>
|
|
63
|
+
import Draggable from '@marsio/vue-draggable';
|
|
64
|
+
|
|
65
|
+
export default {
|
|
66
|
+
components: {
|
|
67
|
+
Draggable
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
</script>
|
|
71
|
+
|
|
72
|
+
<style>
|
|
73
|
+
.draggable-item {
|
|
74
|
+
/* Your styles for draggable items */
|
|
75
|
+
}
|
|
76
|
+
</style>
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Step 4: Enjoy!
|
|
80
|
+
|
|
81
|
+
That's it! You've successfully integrated draggable functionality into your Vue application. Customize it further according to your needs.
|
|
82
|
+
|
|
83
|
+
For more detailed documentation, refer to the [Technical Documentation](#technical-documentation) section.
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
9
87
|
A simple component for making elements draggable.
|
|
10
88
|
|
|
11
89
|
```js
|
|
@@ -26,20 +104,6 @@ A simple component for making elements draggable.
|
|
|
26
104
|
- [DraggableCore API](#draggablecore-api)
|
|
27
105
|
|
|
28
106
|
|
|
29
|
-
|
|
30
|
-
### Installing
|
|
31
|
-
|
|
32
|
-
```bash
|
|
33
|
-
$ npm install @marsio/vue-draggable
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
If you aren't using browserify/webpack, a
|
|
37
|
-
[UMD version of vue-draggable](dist/vue-draggable.js) is available. It is updated per-release only.
|
|
38
|
-
This bundle is also what is loaded when installing from npm. It expects external Vue3.
|
|
39
|
-
|
|
40
|
-
If you want a UMD version of the latest `master` revision, you can generate it yourself from master by cloning this
|
|
41
|
-
repository and running `$ make`. This will create umd dist files in the `build/` folder.
|
|
42
|
-
|
|
43
107
|
### Exports
|
|
44
108
|
|
|
45
109
|
The default export is `<Draggable>`. At the `.DraggableCore` property is [`<DraggableCore>`](#draggablecore).
|
|
@@ -201,28 +265,6 @@ dragFn: DraggableEventHandler,
|
|
|
201
265
|
// Called when dragging stops.
|
|
202
266
|
stopFn: DraggableEventHandler,
|
|
203
267
|
|
|
204
|
-
// import { defineComponent, ref } from 'vue';
|
|
205
|
-
// import Draggable from 'vue-draggable'
|
|
206
|
-
|
|
207
|
-
// const Component1 = defineComponent({
|
|
208
|
-
// props: {
|
|
209
|
-
// title: String
|
|
210
|
-
// },
|
|
211
|
-
// setup(props) {
|
|
212
|
-
// return { title };
|
|
213
|
-
// }
|
|
214
|
-
// });
|
|
215
|
-
|
|
216
|
-
// export default defineComponent({
|
|
217
|
-
// setup(props) {
|
|
218
|
-
// const nodeRef = ref(null)
|
|
219
|
-
// return () => (
|
|
220
|
-
// <DraggableCore dragFn={onDrag} nodeRef={nodeRef}>
|
|
221
|
-
// <Component1 ref={nodeRef} />
|
|
222
|
-
// </DraggableCore>
|
|
223
|
-
// )
|
|
224
|
-
// }
|
|
225
|
-
// });
|
|
226
268
|
// `nodeRef` is also available on <DraggableCore>.
|
|
227
269
|
nodeRef: Ref<HTMLElement | null>,
|
|
228
270
|
|
|
@@ -301,19 +343,17 @@ Drag callbacks (`startFn`, `dragFn`, `stopFn`) are called with the [same argumen
|
|
|
301
343
|
|
|
302
344
|
----
|
|
303
345
|
|
|
304
|
-
###
|
|
346
|
+
### Modern browsers.
|
|
305
347
|
|
|
306
|
-
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
- Update README with appropriate docs.
|
|
310
|
-
- Commit and PR
|
|
348
|
+
| [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png" alt="Edge" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Edge | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png" alt="Firefox" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Firefox | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png" alt="Chrome" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Chrome | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_48x48.png" alt="Safari" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Safari | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/opera/opera_48x48.png" alt="Opera" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Opera |
|
|
349
|
+
| --- | --- | --- | --- | --- |
|
|
350
|
+
| Edge | last 2 versions | last 2 versions | last 2 versions | last 2 versions |
|
|
311
351
|
|
|
312
352
|
### Release checklist
|
|
313
353
|
|
|
314
354
|
- Update CHANGELOG
|
|
315
|
-
- `
|
|
316
|
-
- `
|
|
355
|
+
- `pnpm release`
|
|
356
|
+
- `pnpm publish`
|
|
317
357
|
|
|
318
358
|
### License
|
|
319
359
|
|
package/build/cjs/Draggable.js
CHANGED
|
@@ -20,8 +20,43 @@ var _shims = require("./utils/shims");
|
|
|
20
20
|
var _DraggableCore = _interopRequireWildcard(require("./DraggableCore"));
|
|
21
21
|
var _log = _interopRequireDefault(require("./utils/log"));
|
|
22
22
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
23
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u &&
|
|
24
|
-
function _interopRequireDefault(
|
|
23
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
24
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
25
|
+
/**
|
|
26
|
+
* Draggable is a Vue component that allows elements to be dragged and dropped.
|
|
27
|
+
* It extends DraggableCore by adding Vue-specific props for more customized behavior.
|
|
28
|
+
*
|
|
29
|
+
* Props:
|
|
30
|
+
* - axis: Specifies the axis along which the element can be dragged. Options are 'both', 'x', 'y', or 'none'. Default is 'both'.
|
|
31
|
+
* - bounds: Constrains the draggable area. Can be an object specifying left, right, top, and bottom bounds, a string selector, or false for no bounds. Default is false.
|
|
32
|
+
* - defaultClassName: The default class name applied to the element. Default is 'vue-draggable'.
|
|
33
|
+
* - defaultClassNameDragging: The class name applied to the element while dragging. Default is 'vue-draggable-dragging'.
|
|
34
|
+
* - defaultClassNameDragged: The class name applied to the element after it has been dragged. Default is 'vue-draggable-dragged'.
|
|
35
|
+
* - defaultPosition: The default position of the element. An object with x and y properties. Default is {x: 0, y: 0}.
|
|
36
|
+
* - positionOffset: Offset of the position. An object with x and y properties, each can be a number or a string. Default is {x: 0, y: 0}.
|
|
37
|
+
* - position: Controls the position of the draggable element. An object with x and y properties.
|
|
38
|
+
* - cancel: Specifies a selector to be used to prevent drag initialization.
|
|
39
|
+
* - offsetParent: Specifies the offset parent of the draggable element. Must be a DOM Node.
|
|
40
|
+
* - grid: Specifies the grid to snap the draggable element to during drag. An array of two numbers.
|
|
41
|
+
* - handle: Specifies a selector to be used as the handle that initiates drag.
|
|
42
|
+
* - nodeRef: A reference to the draggable node.
|
|
43
|
+
* - allowAnyClick: Allows dragging to be initiated with any mouse button. Default is false.
|
|
44
|
+
* - disabled: If true, the element cannot be dragged. Default is false.
|
|
45
|
+
* - enableUserSelectHack: Enables a hack that prevents text selection during drag. Default is true.
|
|
46
|
+
* - startFn, dragFn, stopFn: Functions that are called on drag start, during drag, and on drag stop, respectively. Each defaults to a no-op function.
|
|
47
|
+
* - scale: The scale of the draggable element. Default is 1.
|
|
48
|
+
*
|
|
49
|
+
* Usage:
|
|
50
|
+
* Wrap a single child component or element with <Draggable> to make it draggable. Configure behavior with props.
|
|
51
|
+
*
|
|
52
|
+
* Example:
|
|
53
|
+
* <Draggable axis="x" :defaultPosition="{x: 100, y: 0}">
|
|
54
|
+
* <div>Drag me!</div>
|
|
55
|
+
* </Draggable>
|
|
56
|
+
*
|
|
57
|
+
* Note:
|
|
58
|
+
* This component requires Vue 3 and is designed to work within a Vue 3 application.
|
|
59
|
+
*/
|
|
25
60
|
function _isSlot(s) {
|
|
26
61
|
return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !(0, _vue.isVNode)(s);
|
|
27
62
|
}
|
|
@@ -51,7 +86,7 @@ const draggableProps = exports.draggableProps = {
|
|
|
51
86
|
position: _vueTypes.default.shape({
|
|
52
87
|
x: _vueTypes.default.number,
|
|
53
88
|
y: _vueTypes.default.number
|
|
54
|
-
}).def(
|
|
89
|
+
}).def(undefined)
|
|
55
90
|
};
|
|
56
91
|
const componentName = 'Draggable';
|
|
57
92
|
const Draggable = exports.default = (0, _vue.defineComponent)({
|
|
@@ -111,7 +146,7 @@ const Draggable = exports.default = (0, _vue.defineComponent)({
|
|
|
111
146
|
(0, _log.default)('Draggable: onDragStart: %j', coreData);
|
|
112
147
|
|
|
113
148
|
// Short-circuit if user's callback killed it.
|
|
114
|
-
const shouldStart = props.startFn(e, (0, _positionFns.createDraggableData)({
|
|
149
|
+
const shouldStart = props.startFn?.(e, (0, _positionFns.createDraggableData)({
|
|
115
150
|
props,
|
|
116
151
|
state
|
|
117
152
|
}, coreData));
|
|
@@ -162,12 +197,12 @@ const Draggable = exports.default = (0, _vue.defineComponent)({
|
|
|
162
197
|
// Update the event we fire to reflect what really happened after bounds took effect.
|
|
163
198
|
uiData.x = newState.x;
|
|
164
199
|
uiData.y = newState.y;
|
|
165
|
-
uiData.deltaX = newState.x - state.x;
|
|
166
|
-
uiData.deltaY = newState.y - state.y;
|
|
200
|
+
uiData.deltaX = newState.x - (state.x ?? 0);
|
|
201
|
+
uiData.deltaY = newState.y - (state.y ?? 0);
|
|
167
202
|
}
|
|
168
203
|
|
|
169
204
|
// Short-circuit if user's callback killed it.
|
|
170
|
-
const shouldUpdate = props.dragFn(e, uiData);
|
|
205
|
+
const shouldUpdate = props.dragFn?.(e, uiData);
|
|
171
206
|
if (shouldUpdate === false) return false;
|
|
172
207
|
Object.keys(newState).forEach(key => {
|
|
173
208
|
state[key] = newState[key];
|
|
@@ -177,7 +212,7 @@ const Draggable = exports.default = (0, _vue.defineComponent)({
|
|
|
177
212
|
if (!state.dragging) return false;
|
|
178
213
|
|
|
179
214
|
// Short-circuit if user's callback killed it.
|
|
180
|
-
const shouldContinue = props.stopFn(e, (0, _positionFns.createDraggableData)({
|
|
215
|
+
const shouldContinue = props.stopFn?.(e, (0, _positionFns.createDraggableData)({
|
|
181
216
|
props,
|
|
182
217
|
state
|
|
183
218
|
}, coreData));
|
|
@@ -205,10 +240,10 @@ const Draggable = exports.default = (0, _vue.defineComponent)({
|
|
|
205
240
|
});
|
|
206
241
|
};
|
|
207
242
|
return () => {
|
|
243
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
208
244
|
const {
|
|
209
245
|
axis,
|
|
210
246
|
bounds,
|
|
211
|
-
// children,
|
|
212
247
|
defaultPosition,
|
|
213
248
|
defaultClassName,
|
|
214
249
|
defaultClassNameDragging,
|
|
@@ -218,20 +253,22 @@ const Draggable = exports.default = (0, _vue.defineComponent)({
|
|
|
218
253
|
scale,
|
|
219
254
|
...draggableCoreProps
|
|
220
255
|
} = props;
|
|
256
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
257
|
+
|
|
221
258
|
let style = {};
|
|
222
|
-
let svgTransform =
|
|
259
|
+
let svgTransform = '';
|
|
223
260
|
const controlled = Boolean(position);
|
|
224
261
|
const draggable = !controlled || state.dragging;
|
|
225
262
|
const validPosition = position || defaultPosition;
|
|
226
263
|
const transformOpts = {
|
|
227
264
|
// Set left if horizontal drag is enabled
|
|
228
|
-
x: (0, _positionFns.canDragX)({
|
|
265
|
+
x: ((0, _positionFns.canDragX)({
|
|
229
266
|
props
|
|
230
|
-
}) && draggable ? state.x : validPosition.x,
|
|
267
|
+
}) && draggable ? state.x : validPosition.x) ?? 0,
|
|
231
268
|
// Set top if vertical drag is enabled
|
|
232
|
-
y: (0, _positionFns.canDragY)({
|
|
269
|
+
y: ((0, _positionFns.canDragY)({
|
|
233
270
|
props
|
|
234
|
-
}) && draggable ? state.y : validPosition.y
|
|
271
|
+
}) && draggable ? state.y : validPosition.y) ?? 0
|
|
235
272
|
};
|
|
236
273
|
|
|
237
274
|
// If this element was SVG, we use the `transform` attribute.
|
|
@@ -244,23 +281,18 @@ const Draggable = exports.default = (0, _vue.defineComponent)({
|
|
|
244
281
|
// has a clean slate.
|
|
245
282
|
style = (0, _domFns.createCSSTransform)(transformOpts, positionOffset);
|
|
246
283
|
}
|
|
247
|
-
const slotContent = (0, _vue.renderSlot)(slots, 'default');
|
|
248
|
-
let children = slotContent.children;
|
|
249
|
-
if (!Array.isArray(children)) {
|
|
250
|
-
children = []; // 如果不是数组,则使用空数组
|
|
251
|
-
}
|
|
252
284
|
|
|
253
285
|
// Mark with class while dragging
|
|
254
286
|
const className = (0, _clsx.default)(defaultClassName, {
|
|
255
287
|
[defaultClassNameDragging]: state.dragging,
|
|
256
288
|
[defaultClassNameDragged]: state.dragged
|
|
257
289
|
});
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
290
|
+
const child = slots.default ? slots.default()[0] : null;
|
|
291
|
+
if (!child) return null;
|
|
292
|
+
const clonedChildren = (0, _vue.cloneVNode)(child, {
|
|
293
|
+
class: className,
|
|
294
|
+
style,
|
|
295
|
+
transform: svgTransform
|
|
264
296
|
});
|
|
265
297
|
const coreProps = {
|
|
266
298
|
...draggableCoreProps,
|
|
@@ -11,7 +11,42 @@ var _domFns = require("./utils/domFns");
|
|
|
11
11
|
var _positionFns = require("./utils/positionFns");
|
|
12
12
|
var _shims = require("./utils/shims");
|
|
13
13
|
var _log = _interopRequireDefault(require("./utils/log"));
|
|
14
|
-
function _interopRequireDefault(
|
|
14
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
+
/**
|
|
16
|
+
* DraggableCore is a low-level wrapper for draggable functionality, allowing for more fine-grained control over drag events.
|
|
17
|
+
* It provides the core functionality needed to make an element draggable, such as mouse and touch event handling, without
|
|
18
|
+
* imposing any specific styling or structure on the element being dragged. It's designed to be used as a building block
|
|
19
|
+
* for more complex draggable components.
|
|
20
|
+
*
|
|
21
|
+
* @compatConfig {MODE: 3} - Compatibility mode setting for Vue 3.
|
|
22
|
+
* @name DraggableCore - The name of the component.
|
|
23
|
+
* @inheritAttrs false - Instructs Vue not to add inherited attributes to the component's root element.
|
|
24
|
+
*
|
|
25
|
+
* @props
|
|
26
|
+
* - `allowAnyClick` (Boolean): Allows dragging using any mouse button. Default is `false`, which means only the left mouse button can initiate dragging.
|
|
27
|
+
* - `disabled` (Boolean): Disables the draggable functionality when set to `true`.
|
|
28
|
+
* - `enableUserSelectHack` (Boolean): Enables a hack that prevents user text selection during dragging. Default is `true`.
|
|
29
|
+
* - `startFn` (Function): A function that is called at the start of a drag operation. Default is a no-op function.
|
|
30
|
+
* - `dragFn` (Function): A function that is called during a drag operation. Default is a no-op function.
|
|
31
|
+
* - `stopFn` (Function): A function that is called at the end of a drag operation. Default is a no-op function.
|
|
32
|
+
* - `scale` (Number): The scale of the draggable element, affecting drag sensitivity. Default is `1`.
|
|
33
|
+
* - `cancel` (String): CSS selector that defines elements within the draggable element that should prevent dragging when clicked.
|
|
34
|
+
* - `offsetParent` (HTMLElement): The offset parent of the draggable element, used to calculate drag distances. Must be a DOM Node.
|
|
35
|
+
* - `grid` (Array[Number, Number]): Specifies a grid [x, y] to which the element's movement will be snapped.
|
|
36
|
+
* - `handle` (String): CSS selector that defines the handle element that initiates drag actions. If not defined, the entire element is draggable.
|
|
37
|
+
* - `nodeRef` (Object): A Vue ref object pointing to the draggable element. Used when direct DOM access is necessary.
|
|
38
|
+
*
|
|
39
|
+
* @setup
|
|
40
|
+
* The setup function initializes the component's reactive state and event handlers for drag operations. It handles the
|
|
41
|
+
* initialization and cleanup of event listeners for mouse and touch events that control the drag behavior.
|
|
42
|
+
*
|
|
43
|
+
* @returns
|
|
44
|
+
* The setup function returns a render function that clones the component's default slot's first child, applying the necessary
|
|
45
|
+
* event handlers and a ref to the root element to enable dragging functionality.
|
|
46
|
+
*
|
|
47
|
+
* Note: This component does not render any DOM elements itself; it merely wraps its default slot's content with draggable functionality.
|
|
48
|
+
*/
|
|
49
|
+
|
|
15
50
|
// Simple abstraction for dragging events names.
|
|
16
51
|
const eventsFor = {
|
|
17
52
|
touch: {
|
|
@@ -25,6 +60,8 @@ const eventsFor = {
|
|
|
25
60
|
stop: 'mouseup'
|
|
26
61
|
}
|
|
27
62
|
};
|
|
63
|
+
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
28
65
|
const defaultDraggableEventHandler = (e, data) => true;
|
|
29
66
|
exports.defaultDraggableEventHandler = defaultDraggableEventHandler;
|
|
30
67
|
const funcVoid = function () {};
|
|
@@ -43,10 +80,10 @@ const draggableCoreDefaultProps = exports.draggableCoreDefaultProps = {
|
|
|
43
80
|
const draggableCoreProps = exports.draggableCoreProps = {
|
|
44
81
|
...draggableCoreDefaultProps,
|
|
45
82
|
cancel: _vueTypes.default.string,
|
|
46
|
-
offsetParent: _vueTypes.default.custom(_shims.
|
|
83
|
+
offsetParent: _vueTypes.default.custom(_shims.propIsNotNode, 'Draggable\'s offsetParent must be a DOM Node.'),
|
|
47
84
|
grid: _vueTypes.default.arrayOf(_vueTypes.default.number),
|
|
48
85
|
handle: _vueTypes.default.string,
|
|
49
|
-
nodeRef: _vueTypes.default.object.def(null)
|
|
86
|
+
nodeRef: _vueTypes.default.object.def(() => null)
|
|
50
87
|
};
|
|
51
88
|
const componentName = 'DraggableCore';
|
|
52
89
|
var _default = exports.default = (0, _vue.defineComponent)({
|
|
@@ -57,9 +94,6 @@ var _default = exports.default = (0, _vue.defineComponent)({
|
|
|
57
94
|
inheritAttrs: false,
|
|
58
95
|
props: {
|
|
59
96
|
...draggableCoreProps
|
|
60
|
-
// style: dontSetMe('style', componentName),
|
|
61
|
-
// class: dontSetMe('class', componentName),
|
|
62
|
-
// transform: dontSetMe('transform', componentName),
|
|
63
97
|
},
|
|
64
98
|
setup(props, _ref) {
|
|
65
99
|
let {
|
|
@@ -67,7 +101,6 @@ var _default = exports.default = (0, _vue.defineComponent)({
|
|
|
67
101
|
emit
|
|
68
102
|
} = _ref;
|
|
69
103
|
const rootElement = (0, _vue.ref)(null);
|
|
70
|
-
const displayName = 'DraggableCore';
|
|
71
104
|
const state = (0, _vue.reactive)({
|
|
72
105
|
dragging: false,
|
|
73
106
|
// Used while dragging to determine deltas.
|
|
@@ -178,7 +211,7 @@ var _default = exports.default = (0, _vue.defineComponent)({
|
|
|
178
211
|
// Get nodes. Be sure to grab relative document (could be iframed)
|
|
179
212
|
const thisNode = findDOMNode();
|
|
180
213
|
if (!(0, _get.default)(thisNode, 'ownerDocument.body')) {
|
|
181
|
-
throw new Error('<DraggableCore> not mounted on DragStart!');
|
|
214
|
+
// throw new Error('<DraggableCore> not mounted on DragStart!');
|
|
182
215
|
}
|
|
183
216
|
const {
|
|
184
217
|
ownerDocument
|
|
@@ -219,7 +252,7 @@ var _default = exports.default = (0, _vue.defineComponent)({
|
|
|
219
252
|
|
|
220
253
|
// Call event handler. If it returns explicit false, cancel.
|
|
221
254
|
(0, _log.default)('calling', props.startFn);
|
|
222
|
-
const shouldUpdate = props.startFn(e, coreEvent);
|
|
255
|
+
const shouldUpdate = props.startFn?.(e, coreEvent);
|
|
223
256
|
if (shouldUpdate === false || state.mounted === false) return;
|
|
224
257
|
|
|
225
258
|
// Add a style to the body to disable user-select. This prevents text from
|
|
@@ -243,12 +276,6 @@ var _default = exports.default = (0, _vue.defineComponent)({
|
|
|
243
276
|
dragEventFor = eventsFor.mouse; // on touchscreen laptops we could switch back to mouse
|
|
244
277
|
return handleDragStart(e);
|
|
245
278
|
};
|
|
246
|
-
|
|
247
|
-
// const onMoueDown = (e: MouseTouchEvent) => {
|
|
248
|
-
// dragEventFor = eventsFor.mouse // on touchscreen laptops we could switch back to mouse
|
|
249
|
-
// return handleDragStart(e)
|
|
250
|
-
// }
|
|
251
|
-
|
|
252
279
|
const onMouseup = e => {
|
|
253
280
|
dragEventFor = eventsFor.mouse;
|
|
254
281
|
return handleDragStop(e);
|
|
@@ -292,12 +319,8 @@ var _default = exports.default = (0, _vue.defineComponent)({
|
|
|
292
319
|
}
|
|
293
320
|
});
|
|
294
321
|
return () => {
|
|
295
|
-
const
|
|
296
|
-
|
|
297
|
-
if (!Array.isArray(children)) {
|
|
298
|
-
children = []; // 如果不是数组,则使用空数组
|
|
299
|
-
}
|
|
300
|
-
const child = (0, _get.default)(children, '0.children[0]');
|
|
322
|
+
const child = slots.default ? slots.default()[0] : null;
|
|
323
|
+
if (!child) return null;
|
|
301
324
|
const clonedChildren = (0, _vue.isVNode)(child) ? (0, _vue.cloneVNode)(child, {
|
|
302
325
|
onMousedown,
|
|
303
326
|
onMouseup,
|