@marsio/vue-draggable 1.0.2 → 1.0.4
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.89b0ffb5e5b82299d838.hot-update.js +30 -0
- package/build/web/vue-draggable.min.js +1420 -2
- package/build/web/vue-draggable_min.89b0ffb5e5b82299d838.hot-update.json +1 -0
- package/package.json +35 -11
- package/typings/index.d.ts +21 -4
- package/LICENSE +0 -21
- package/build/cjs/utils/test.js +0 -12
- package/build/web/vue-draggable.min.js.LICENSE.txt +0 -6
package/build/cjs/utils/shims.js
CHANGED
|
@@ -8,9 +8,18 @@ exports.findInArray = findInArray;
|
|
|
8
8
|
exports.int = int;
|
|
9
9
|
exports.isFunction = isFunction;
|
|
10
10
|
exports.isNum = isNum;
|
|
11
|
-
exports.
|
|
11
|
+
exports.propIsNotNode = propIsNotNode;
|
|
12
12
|
var _vueTypes = _interopRequireDefault(require("vue-types"));
|
|
13
|
-
function _interopRequireDefault(
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
/**
|
|
15
|
+
* Searches for an element in an array or TouchList that satisfies the provided callback function.
|
|
16
|
+
* @param {T[] | TouchList} array - The array or TouchList to search.
|
|
17
|
+
* @param {(element: T, index: number, arr: T[] | TouchList) => boolean} callback - A function that accepts up to three arguments.
|
|
18
|
+
* The findInArray method calls the callback function one time for each element in the array, in order, until the callback returns true.
|
|
19
|
+
* If such an element is found, findInArray immediately returns that element value. Otherwise, findInArray returns undefined.
|
|
20
|
+
* @returns {any} The found element in the array, or undefined if not found.
|
|
21
|
+
*/
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
23
|
function findInArray(array, callback) {
|
|
15
24
|
for (let i = 0, length = array.length; i < length; i++) {
|
|
16
25
|
const element = array instanceof TouchList ? array.item(i) : array[i];
|
|
@@ -18,22 +27,52 @@ function findInArray(array, callback) {
|
|
|
18
27
|
return element;
|
|
19
28
|
}
|
|
20
29
|
}
|
|
21
|
-
return undefined;
|
|
22
30
|
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Checks if the passed argument is a function.
|
|
34
|
+
* @param {unknown} func - The argument to check.
|
|
35
|
+
* @returns {boolean} True if the argument is a function, false otherwise.
|
|
36
|
+
*/
|
|
23
37
|
function isFunction(func) {
|
|
24
38
|
return typeof func === 'function' || Object.prototype.toString.call(func) === '[object Function]';
|
|
25
39
|
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Checks if the passed argument is a number.
|
|
43
|
+
* @param {unknown} num - The argument to check.
|
|
44
|
+
* @returns {boolean} True if the argument is a number and not NaN, false otherwise.
|
|
45
|
+
*/
|
|
26
46
|
function isNum(num) {
|
|
27
47
|
return typeof num === 'number' && !isNaN(num);
|
|
28
48
|
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Converts a string to an integer.
|
|
52
|
+
* @param {string} a - The string to convert.
|
|
53
|
+
* @returns {number} The converted integer.
|
|
54
|
+
*/
|
|
29
55
|
function int(a) {
|
|
30
56
|
return parseInt(a, 10);
|
|
31
57
|
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Creates a custom Vue prop type that fails validation.
|
|
61
|
+
* @param {string} propsName - The name of the prop.
|
|
62
|
+
* @param {string} componentName - The name of the component.
|
|
63
|
+
* @returns {VueTypeDef<T>} A VueTypeDef that always fails validation.
|
|
64
|
+
*/
|
|
32
65
|
function dontSetMe(propsName, componentName) {
|
|
33
|
-
const
|
|
66
|
+
const failedPropType = () => !propsName;
|
|
34
67
|
const message = `Invalid prop ${propsName} passed to ${componentName} - do not set this, set it on the child.`;
|
|
35
|
-
return _vueTypes.default.custom(
|
|
68
|
+
return _vueTypes.default.custom(failedPropType, message);
|
|
36
69
|
}
|
|
37
|
-
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Checks if the passed argument is a DOM Node but not a text node.
|
|
73
|
+
* @param {unknown} node - The argument to check.
|
|
74
|
+
* @returns {boolean} True if the argument is a DOM Node and not a text node, false otherwise.
|
|
75
|
+
*/
|
|
76
|
+
function propIsNotNode(node) {
|
|
38
77
|
return typeof node === 'object' && node !== null && 'nodeType' in node && node.nodeType === 1;
|
|
39
78
|
}
|
package/build/cjs/utils/types.js
CHANGED
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.TouchEvent2 = exports.SVGElement = void 0;
|
|
7
|
-
function _defineProperty(
|
|
8
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i :
|
|
7
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
8
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
9
9
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
10
10
|
class SVGElement extends HTMLElement {}
|
|
11
11
|
|
|
@@ -18,4 +18,12 @@ class TouchEvent2 extends TouchEvent {
|
|
|
18
18
|
_defineProperty(this, "targetTouches", void 0);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
+
|
|
22
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
23
|
+
|
|
24
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
25
|
+
|
|
26
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
27
|
+
|
|
28
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
21
29
|
exports.TouchEvent2 = TouchEvent2;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
|
|
4
|
+
* This devtool is neither made for production nor for readable output files.
|
|
5
|
+
* It uses "eval()" calls to create a separate source file in the browser devtools.
|
|
6
|
+
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
|
|
7
|
+
* or disable the default devtool with "devtool: false".
|
|
8
|
+
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
|
|
9
|
+
*/
|
|
10
|
+
self["webpackHotUpdateVueDraggable"]("vue-draggable.min",{
|
|
11
|
+
|
|
12
|
+
/***/ "./lib/utils/positionFns.ts":
|
|
13
|
+
/*!**********************************!*\
|
|
14
|
+
!*** ./lib/utils/positionFns.ts ***!
|
|
15
|
+
\**********************************/
|
|
16
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
17
|
+
|
|
18
|
+
eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.createDraggableData = exports.createCoreData = exports.getControlPosition = exports.canDragY = exports.canDragX = exports.snapToGrid = exports.getBoundPosition = void 0;\nvar domFns_1 = __webpack_require__(/*! ./domFns */ \"./lib/utils/domFns.ts\");\nvar shims_1 = __webpack_require__(/*! ./shims */ \"./lib/utils/shims.ts\");\n// Quick clone for bounds. We're doing this because we don't want to mess with the original bounds object.\n// It's a simple copy, nothing fancy.\nvar cloneBounds = function (bounds) {\n return {\n left: bounds.left,\n top: bounds.top,\n right: bounds.right,\n bottom: bounds.bottom\n };\n};\n// This one's a bit tricky. We're trying to find the actual DOM node for a draggable component.\n// It's using some internal stuff, so don't worry if it looks a bit weird.\nvar findDOMNode = function (draggable) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return draggable.findDOMNode();\n};\n// Ever got annoyed by CSS values being strings? Yeah, me too. This function takes those strings and turns them into numbers.\n// Also, it warns you if something's not right, which is pretty handy.\nvar parseStyleToInt = function (style, property) {\n if (!(property in style)) {\n console.warn(\"Property \\\"\".concat(String(property), \"\\\" does not exist on the provided style object.\"));\n return 0;\n }\n var value = style[property];\n var parsed = parseInt(value, 10);\n if (isNaN(parsed)) {\n console.warn(\"Value of property \\\"\".concat(String(property), \"\\\" is not a valid number.\"));\n return 0;\n }\n return parsed;\n};\n// This is where the magic happens. We're making sure the draggable stays within its bounds.\n// It's a bit of math and some conditionals. Nothing too scary, but it does the job.\nvar getBoundPosition = function (draggable, x, y) {\n if (!draggable.props.bounds)\n return [x, y];\n var bounds = draggable.props.bounds;\n bounds = typeof bounds === 'string' ? bounds : cloneBounds(bounds);\n var node = findDOMNode(draggable);\n if (!node)\n return [x, y];\n var ownerDocument = node.ownerDocument;\n var ownerWindow = ownerDocument === null || ownerDocument === void 0 ? void 0 : ownerDocument.defaultView;\n if (!ownerWindow) {\n return [x, y];\n }\n if (typeof bounds === 'string') {\n var boundNode = bounds === 'parent' ? node.parentNode : ownerDocument.querySelector(bounds);\n if (!(boundNode instanceof ownerWindow.HTMLElement)) {\n throw new Error(\"Bounds selector \\\"\".concat(bounds, \"\\\" could not find an element.\"));\n }\n var nodeStyle = ownerWindow.getComputedStyle(node);\n var boundNodeStyle = ownerWindow.getComputedStyle(boundNode);\n bounds = {\n left: -node.offsetLeft + parseStyleToInt(boundNodeStyle, 'paddingLeft') + parseStyleToInt(nodeStyle, 'marginLeft'),\n top: -node.offsetTop + parseStyleToInt(boundNodeStyle, 'paddingTop') + parseStyleToInt(nodeStyle, 'marginTop'),\n right: (0, domFns_1.innerWidth)(boundNode) - (0, domFns_1.outerWidth)(node) - node.offsetLeft + parseStyleToInt(boundNodeStyle, 'paddingRight') - parseStyleToInt(nodeStyle, 'marginRight'),\n bottom: (0, domFns_1.innerHeight)(boundNode) - (0, domFns_1.outerHeight)(node) - node.offsetTop + parseStyleToInt(boundNodeStyle, 'paddingBottom') - parseStyleToInt(nodeStyle, 'marginBottom')\n };\n }\n // Clamp x and y to be within the bounds.\n x = Math.max(Math.min(x, bounds.right || 0), bounds.left || 0);\n y = Math.max(Math.min(y, bounds.bottom || 0), bounds.top || 0);\n return [x, y];\n};\nexports.getBoundPosition = getBoundPosition;\n// Snapping to a grid is super useful for aligning stuff. This function just rounds the position to the nearest grid point.\nvar snapToGrid = function (grid, pendingX, pendingY) {\n var x = Math.round(pendingX / grid[0]) * grid[0];\n var y = Math.round(pendingY / grid[1]) * grid[1];\n return [x, y];\n};\nexports.snapToGrid = snapToGrid;\n// Can we drag along the x-axis? This checks the draggable's props to see what's allowed.\nvar canDragX = function (draggable) {\n return draggable.props.axis === 'both' || draggable.props.axis === 'x';\n};\nexports.canDragX = canDragX;\n// Same as canDragX, but for the y-axis. Gotta keep things flexible.\nvar canDragY = function (draggable) {\n return draggable.props.axis === 'both' || draggable.props.axis === 'y';\n};\nexports.canDragY = canDragY;\n// Getting the control position is a bit of DOM manipulation and event handling.\n// It's a bit dense, but it's just calculating positions based on the event and the draggable's state.\nvar getControlPosition = function (e, draggableCore, touchIdentifier) {\n var touchObj = typeof touchIdentifier === 'number' ? (0, domFns_1.getTouch)(e, touchIdentifier) : null;\n if (typeof touchIdentifier === 'number' && !touchObj)\n return null; // not the right touch\n var node = findDOMNode(draggableCore);\n // User can provide an offsetParent if desired.\n var offsetParent = draggableCore.props.offsetParent || node.offsetParent || node.ownerDocument.body;\n return (0, domFns_1.offsetXYFromParent)(touchObj || e, offsetParent, draggableCore.props.scale);\n};\nexports.getControlPosition = getControlPosition;\n// When you start dragging, or move the draggable, this function updates the state with the new position.\n// It's a bit of a state management thing, keeping track of deltas and positions.\nvar createCoreData = function (draggable, x, y) {\n var state = draggable.state;\n var isStart = !(0, shims_1.isNum)(state.lastX);\n var node = findDOMNode(draggable);\n if (isStart) {\n // If this is our first move, use the x and y as last coords.\n return {\n node: node,\n deltaX: 0,\n deltaY: 0,\n lastX: x,\n lastY: y,\n x: x,\n y: y\n };\n }\n else {\n // Otherwise, calculate the delta.\n return {\n node: node,\n deltaX: x - state.lastX,\n deltaY: y - state.lastY,\n lastX: state.lastX,\n lastY: state.lastY,\n x: x,\n y: y\n };\n }\n};\nexports.createCoreData = createCoreData;\n// This takes the core data and adjusts it based on the draggable's scale.\n// It's for when you're scaling the draggable and need the position to reflect that.\nvar createDraggableData = function (draggable, coreData) {\n var scale = draggable.props.scale;\n return {\n node: coreData.node,\n x: draggable.state.x + coreData.deltaX / scale,\n y: draggable.state.y + coreData.deltaY / scale,\n deltaX: coreData.deltaX / scale,\n deltaY: coreData.deltaY / scale,\n lastX: draggable.state.x,\n lastY: draggable.state.y\n };\n};\nexports.createDraggableData = createDraggableData;\n\n\n//# sourceURL=.././lib/utils/positionFns.ts");
|
|
19
|
+
|
|
20
|
+
/***/ })
|
|
21
|
+
|
|
22
|
+
},
|
|
23
|
+
/******/ function(__webpack_require__) { // webpackRuntimeModules
|
|
24
|
+
/******/ /* webpack/runtime/getFullHash */
|
|
25
|
+
/******/ (() => {
|
|
26
|
+
/******/ __webpack_require__.h = () => ("70be4e0fbe9db9ffb1bb")
|
|
27
|
+
/******/ })();
|
|
28
|
+
/******/
|
|
29
|
+
/******/ }
|
|
30
|
+
);
|