@marsio/vue-draggable 1.0.4 → 1.0.7
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/build/cjs/Draggable.js +37 -32
- package/build/cjs/DraggableCore.js +68 -22
- package/build/cjs/type.js +5 -0
- package/build/cjs/utils/positionFns.js +1 -1
- package/build/cjs/utils/shims.js +10 -6
- package/build/cjs/utils/types.js +0 -4
- package/build/web/vue-draggable.min.js +1 -1420
- package/package.json +12 -12
- package/typings/index.d.ts +35 -32
- package/build/web/vue-draggable.min.89b0ffb5e5b82299d838.hot-update.js +0 -30
- package/build/web/vue-draggable_min.89b0ffb5e5b82299d838.hot-update.json +0 -1
package/build/cjs/Draggable.js
CHANGED
|
@@ -12,7 +12,6 @@ Object.defineProperty(exports, "DraggableCore", {
|
|
|
12
12
|
exports.draggableProps = exports.default = void 0;
|
|
13
13
|
var _vue = require("vue");
|
|
14
14
|
var _get = _interopRequireDefault(require("lodash/get"));
|
|
15
|
-
var _vueTypes = _interopRequireDefault(require("vue-types"));
|
|
16
15
|
var _clsx = _interopRequireDefault(require("clsx"));
|
|
17
16
|
var _domFns = require("./utils/domFns");
|
|
18
17
|
var _positionFns = require("./utils/positionFns");
|
|
@@ -62,31 +61,40 @@ function _isSlot(s) {
|
|
|
62
61
|
}
|
|
63
62
|
const draggableProps = exports.draggableProps = {
|
|
64
63
|
..._DraggableCore.draggableCoreProps,
|
|
65
|
-
axis:
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
64
|
+
axis: {
|
|
65
|
+
type: String,
|
|
66
|
+
default: 'both'
|
|
67
|
+
},
|
|
68
|
+
bounds: {
|
|
69
|
+
type: [Object, String, Boolean],
|
|
70
|
+
default: false
|
|
71
|
+
},
|
|
72
|
+
defaultClassName: {
|
|
73
|
+
type: String,
|
|
74
|
+
default: 'vue-draggable'
|
|
75
|
+
},
|
|
76
|
+
defaultClassNameDragging: {
|
|
77
|
+
type: String,
|
|
78
|
+
default: 'vue-draggable-dragging'
|
|
79
|
+
},
|
|
80
|
+
defaultClassNameDragged: {
|
|
81
|
+
type: String,
|
|
82
|
+
default: 'vue-draggable-dragged'
|
|
83
|
+
},
|
|
84
|
+
defaultPosition: {
|
|
85
|
+
type: Object,
|
|
86
|
+
default: () => ({
|
|
87
|
+
x: 0,
|
|
88
|
+
y: 0
|
|
89
|
+
})
|
|
90
|
+
},
|
|
91
|
+
positionOffset: {
|
|
92
|
+
type: Object
|
|
93
|
+
},
|
|
94
|
+
position: {
|
|
95
|
+
type: Object,
|
|
96
|
+
default: undefined
|
|
97
|
+
}
|
|
90
98
|
};
|
|
91
99
|
const componentName = 'Draggable';
|
|
92
100
|
const Draggable = exports.default = (0, _vue.defineComponent)({
|
|
@@ -105,10 +113,11 @@ const Draggable = exports.default = (0, _vue.defineComponent)({
|
|
|
105
113
|
let {
|
|
106
114
|
slots
|
|
107
115
|
} = _ref;
|
|
116
|
+
console.log('props', props);
|
|
108
117
|
const rootElement = (0, _vue.ref)(null);
|
|
109
118
|
if (props.position && !(props.dragFn || props.stopFn)) {
|
|
110
119
|
// eslint-disable-next-line no-console
|
|
111
|
-
console.warn('A `position` was applied to this <Draggable>, without drag handlers. This will make this ' + 'component effectively undraggable. Please attach `
|
|
120
|
+
console.warn('A `position` was applied to this <Draggable>, without drag handlers. This will make this ' + 'component effectively undraggable. Please attach `dragFn` or `stopFn` handlers so you can adjust the ' + '`position` of this element.');
|
|
112
121
|
}
|
|
113
122
|
const state = (0, _vue.reactive)({
|
|
114
123
|
// Whether or not we are currently dragging.
|
|
@@ -127,10 +136,6 @@ const Draggable = exports.default = (0, _vue.defineComponent)({
|
|
|
127
136
|
// Can only determine if SVG after mounting
|
|
128
137
|
isElementSVG: false
|
|
129
138
|
});
|
|
130
|
-
|
|
131
|
-
// const position = ref(props.position);
|
|
132
|
-
// const prevPropsPosition = ref(null);
|
|
133
|
-
|
|
134
139
|
const findDOMNode = () => {
|
|
135
140
|
return (0, _get.default)(props, 'nodeRef.value') || rootElement.value;
|
|
136
141
|
};
|
|
@@ -157,7 +162,7 @@ const Draggable = exports.default = (0, _vue.defineComponent)({
|
|
|
157
162
|
};
|
|
158
163
|
const onDrag = (e, coreData) => {
|
|
159
164
|
if (!state.dragging) return false;
|
|
160
|
-
(0, _log.default)('Draggable:
|
|
165
|
+
(0, _log.default)('Draggable: dragFn: %j', coreData);
|
|
161
166
|
const uiData = (0, _positionFns.createDraggableData)({
|
|
162
167
|
props,
|
|
163
168
|
state
|
|
@@ -4,13 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.draggableCoreProps = exports.draggableCoreDefaultProps = exports.defaultDraggableEventHandler = exports.default = void 0;
|
|
7
|
+
var _get2 = _interopRequireDefault(require("lodash/get"));
|
|
7
8
|
var _vue = require("vue");
|
|
8
|
-
var _vueTypes = _interopRequireDefault(require("vue-types"));
|
|
9
|
-
var _get = _interopRequireDefault(require("lodash/get"));
|
|
10
9
|
var _domFns = require("./utils/domFns");
|
|
11
10
|
var _positionFns = require("./utils/positionFns");
|
|
12
|
-
var _shims = require("./utils/shims");
|
|
13
11
|
var _log = _interopRequireDefault(require("./utils/log"));
|
|
12
|
+
var _shims = require("./utils/shims");
|
|
14
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
14
|
/**
|
|
16
15
|
* DraggableCore is a low-level wrapper for draggable functionality, allowing for more fine-grained control over drag events.
|
|
@@ -35,7 +34,6 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
35
34
|
* - `grid` (Array[Number, Number]): Specifies a grid [x, y] to which the element's movement will be snapped.
|
|
36
35
|
* - `handle` (String): CSS selector that defines the handle element that initiates drag actions. If not defined, the entire element is draggable.
|
|
37
36
|
* - `nodeRef` (Object): A Vue ref object pointing to the draggable element. Used when direct DOM access is necessary.
|
|
38
|
-
*
|
|
39
37
|
* @setup
|
|
40
38
|
* The setup function initializes the component's reactive state and event handlers for drag operations. It handles the
|
|
41
39
|
* initialization and cleanup of event listeners for mouse and touch events that control the drag behavior.
|
|
@@ -47,6 +45,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
47
45
|
* Note: This component does not render any DOM elements itself; it merely wraps its default slot's content with draggable functionality.
|
|
48
46
|
*/
|
|
49
47
|
|
|
48
|
+
const funcVoid = function () {};
|
|
50
49
|
// Simple abstraction for dragging events names.
|
|
51
50
|
const eventsFor = {
|
|
52
51
|
touch: {
|
|
@@ -63,27 +62,67 @@ const eventsFor = {
|
|
|
63
62
|
|
|
64
63
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
65
64
|
const defaultDraggableEventHandler = (e, data) => true;
|
|
66
|
-
exports.defaultDraggableEventHandler = defaultDraggableEventHandler;
|
|
67
|
-
const funcVoid = function () {};
|
|
68
65
|
|
|
69
66
|
// Default to mouse events.
|
|
67
|
+
exports.defaultDraggableEventHandler = defaultDraggableEventHandler;
|
|
70
68
|
let dragEventFor = eventsFor.mouse;
|
|
71
69
|
const draggableCoreDefaultProps = exports.draggableCoreDefaultProps = {
|
|
72
|
-
allowAnyClick:
|
|
73
|
-
disabled:
|
|
74
|
-
enableUserSelectHack:
|
|
75
|
-
startFn:
|
|
76
|
-
dragFn:
|
|
77
|
-
stopFn:
|
|
78
|
-
scale:
|
|
70
|
+
// allowAnyClick: VueTypes.bool.def(false),
|
|
71
|
+
// disabled: VueTypes.bool.def(false),
|
|
72
|
+
// enableUserSelectHack: VueTypes.bool.def(true),
|
|
73
|
+
// startFn: VueTypes.func.def(defaultDraggableEventHandler).def(funcVoid),
|
|
74
|
+
// dragFn: VueTypes.func.def(defaultDraggableEventHandler).def(funcVoid),
|
|
75
|
+
// stopFn: VueTypes.func.def(defaultDraggableEventHandler).def(funcVoid),
|
|
76
|
+
// scale: VueTypes.number.def(1),
|
|
77
|
+
allowAnyClick: {
|
|
78
|
+
type: Boolean,
|
|
79
|
+
default: false
|
|
80
|
+
},
|
|
81
|
+
disabled: {
|
|
82
|
+
type: Boolean,
|
|
83
|
+
default: false
|
|
84
|
+
},
|
|
85
|
+
enableUserSelectHack: {
|
|
86
|
+
type: Boolean,
|
|
87
|
+
default: true
|
|
88
|
+
},
|
|
89
|
+
startFn: {
|
|
90
|
+
type: Function,
|
|
91
|
+
default: () => funcVoid
|
|
92
|
+
},
|
|
93
|
+
dragFn: {
|
|
94
|
+
type: Function,
|
|
95
|
+
default: () => funcVoid
|
|
96
|
+
},
|
|
97
|
+
stopFn: {
|
|
98
|
+
type: Function,
|
|
99
|
+
default: () => funcVoid
|
|
100
|
+
},
|
|
101
|
+
scale: {
|
|
102
|
+
type: Number,
|
|
103
|
+
default: 1
|
|
104
|
+
}
|
|
79
105
|
};
|
|
80
106
|
const draggableCoreProps = exports.draggableCoreProps = {
|
|
81
107
|
...draggableCoreDefaultProps,
|
|
82
|
-
cancel:
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
108
|
+
cancel: {
|
|
109
|
+
type: String
|
|
110
|
+
},
|
|
111
|
+
offsetParent: {
|
|
112
|
+
type: Object,
|
|
113
|
+
default: () => document.body,
|
|
114
|
+
validator: value => (0, _shims.propIsNotNode)(value)
|
|
115
|
+
},
|
|
116
|
+
grid: {
|
|
117
|
+
type: Array
|
|
118
|
+
},
|
|
119
|
+
handle: {
|
|
120
|
+
type: String
|
|
121
|
+
},
|
|
122
|
+
nodeRef: {
|
|
123
|
+
type: Object,
|
|
124
|
+
default: () => null
|
|
125
|
+
}
|
|
87
126
|
};
|
|
88
127
|
const componentName = 'DraggableCore';
|
|
89
128
|
var _default = exports.default = (0, _vue.defineComponent)({
|
|
@@ -95,6 +134,7 @@ var _default = exports.default = (0, _vue.defineComponent)({
|
|
|
95
134
|
props: {
|
|
96
135
|
...draggableCoreProps
|
|
97
136
|
},
|
|
137
|
+
emits: ['mousedown', 'mouseup', 'touchend'],
|
|
98
138
|
setup(props, _ref) {
|
|
99
139
|
let {
|
|
100
140
|
slots,
|
|
@@ -110,7 +150,7 @@ var _default = exports.default = (0, _vue.defineComponent)({
|
|
|
110
150
|
mounted: false
|
|
111
151
|
});
|
|
112
152
|
const findDOMNode = () => {
|
|
113
|
-
return
|
|
153
|
+
return props.nodeRef?.value || rootElement.value;
|
|
114
154
|
};
|
|
115
155
|
const handleDrag = e => {
|
|
116
156
|
// Get the current drag point from the event. This is used as the offset.
|
|
@@ -210,7 +250,7 @@ var _default = exports.default = (0, _vue.defineComponent)({
|
|
|
210
250
|
|
|
211
251
|
// Get nodes. Be sure to grab relative document (could be iframed)
|
|
212
252
|
const thisNode = findDOMNode();
|
|
213
|
-
if (!(0,
|
|
253
|
+
if (!(0, _get2.default)(thisNode, 'ownerDocument.body')) {
|
|
214
254
|
// throw new Error('<DraggableCore> not mounted on DragStart!');
|
|
215
255
|
}
|
|
216
256
|
const {
|
|
@@ -218,7 +258,7 @@ var _default = exports.default = (0, _vue.defineComponent)({
|
|
|
218
258
|
} = thisNode;
|
|
219
259
|
|
|
220
260
|
// Short circuit if handle or cancel prop was provided and selector doesn't match.
|
|
221
|
-
if (props.disabled || !(e.target instanceof ownerDocument.defaultView.Node) || props.handle && !(0, _domFns.matchesSelectorAndParentsTo)(e.target, props.handle, thisNode) || props.cancel && (0, _domFns.matchesSelectorAndParentsTo)(e.target, props.cancel, thisNode)) {
|
|
261
|
+
if (props.disabled || ownerDocument && !(e.target instanceof ownerDocument.defaultView.Node) || props.handle && !(0, _domFns.matchesSelectorAndParentsTo)(e.target, props.handle, thisNode) || props.cancel && (0, _domFns.matchesSelectorAndParentsTo)(e.target, props.cancel, thisNode)) {
|
|
222
262
|
return;
|
|
223
263
|
}
|
|
224
264
|
|
|
@@ -274,6 +314,7 @@ var _default = exports.default = (0, _vue.defineComponent)({
|
|
|
274
314
|
};
|
|
275
315
|
const onMousedown = e => {
|
|
276
316
|
dragEventFor = eventsFor.mouse; // on touchscreen laptops we could switch back to mouse
|
|
317
|
+
emit('mousedown', e);
|
|
277
318
|
return handleDragStart(e);
|
|
278
319
|
};
|
|
279
320
|
const onMouseup = e => {
|
|
@@ -321,12 +362,17 @@ var _default = exports.default = (0, _vue.defineComponent)({
|
|
|
321
362
|
return () => {
|
|
322
363
|
const child = slots.default ? slots.default()[0] : null;
|
|
323
364
|
if (!child) return null;
|
|
365
|
+
// 判断child.type是否是一个组件
|
|
366
|
+
const isComponent = typeof child.type === 'object' && 'name' in child.type;
|
|
367
|
+
// const clonedChildren = isVNode(child) ? cloneVNode(child, { onMousedown, onMouseup, onTouchend, ref: props.nodeRef || rootElement }) : child;
|
|
324
368
|
const clonedChildren = (0, _vue.isVNode)(child) ? (0, _vue.cloneVNode)(child, {
|
|
325
369
|
onMousedown,
|
|
326
370
|
onMouseup,
|
|
327
371
|
onTouchend,
|
|
328
|
-
ref: rootElement
|
|
372
|
+
ref: props.nodeRef || rootElement
|
|
329
373
|
}) : child;
|
|
374
|
+
// const clonedChildren = isVNode(child) ? cloneVNode(child, {}) : child;
|
|
375
|
+
|
|
330
376
|
return clonedChildren;
|
|
331
377
|
};
|
|
332
378
|
}
|
|
@@ -18,7 +18,7 @@ const cloneBounds = bounds => {
|
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
// This one's a bit tricky. We're trying to find the actual DOM node for a draggable component.
|
|
21
|
-
// It's using some internal
|
|
21
|
+
// It's using some internal stuff, so don't worry if it looks a bit weird.
|
|
22
22
|
const findDOMNode = draggable => {
|
|
23
23
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
24
|
return draggable.findDOMNode();
|
package/build/cjs/utils/shims.js
CHANGED
|
@@ -9,8 +9,6 @@ exports.int = int;
|
|
|
9
9
|
exports.isFunction = isFunction;
|
|
10
10
|
exports.isNum = isNum;
|
|
11
11
|
exports.propIsNotNode = propIsNotNode;
|
|
12
|
-
var _vueTypes = _interopRequireDefault(require("vue-types"));
|
|
13
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
12
|
/**
|
|
15
13
|
* Searches for an element in an array or TouchList that satisfies the provided callback function.
|
|
16
14
|
* @param {T[] | TouchList} array - The array or TouchList to search.
|
|
@@ -60,12 +58,18 @@ function int(a) {
|
|
|
60
58
|
* Creates a custom Vue prop type that fails validation.
|
|
61
59
|
* @param {string} propsName - The name of the prop.
|
|
62
60
|
* @param {string} componentName - The name of the component.
|
|
63
|
-
* @returns {VueTypeDef<T>} A VueTypeDef that always fails validation.
|
|
64
61
|
*/
|
|
65
62
|
function dontSetMe(propsName, componentName) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
return {
|
|
64
|
+
validator() {
|
|
65
|
+
if (!propsName) {
|
|
66
|
+
console.error(`Invalid prop ${propsName} passed to ${componentName} - do not set this, set it on the child.`);
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
// 如果有其他验证逻辑,可以在这里添加
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
/**
|
package/build/cjs/utils/types.js
CHANGED
|
@@ -21,9 +21,5 @@ class TouchEvent2 extends TouchEvent {
|
|
|
21
21
|
|
|
22
22
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
23
23
|
|
|
24
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
25
|
-
|
|
26
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
27
|
-
|
|
28
24
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
29
25
|
exports.TouchEvent2 = TouchEvent2;
|