@studiometa/js-toolkit 2.2.2 → 2.4.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/Base/index.cjs +29 -37
- package/Base/index.d.ts +0 -8
- package/Base/index.js +18 -26
- package/Base/managers/EventsManager.cjs +35 -36
- package/Base/managers/EventsManager.js +35 -36
- package/Base/managers/OptionsManager.cjs +19 -13
- package/Base/managers/OptionsManager.js +19 -13
- package/Base/managers/RefsManager.cjs +8 -5
- package/Base/managers/RefsManager.js +8 -5
- package/Base/managers/ResponsiveOptionsManager.cjs +4 -1
- package/Base/managers/ResponsiveOptionsManager.js +4 -1
- package/Base/managers/ServicesManager.cjs +9 -7
- package/Base/managers/ServicesManager.js +9 -7
- package/Base/utils.cjs +22 -4
- package/Base/utils.d.ts +25 -8
- package/Base/utils.js +22 -4
- package/README.md +3 -3
- package/decorators/withBreakpointManager.cjs +15 -5
- package/decorators/withBreakpointManager.js +15 -5
- package/decorators/withBreakpointObserver.cjs +8 -2
- package/decorators/withBreakpointObserver.js +8 -2
- package/decorators/withVue2.cjs +10 -3
- package/decorators/withVue2.js +10 -3
- package/helpers/getDirectChildren.cjs +46 -0
- package/helpers/getDirectChildren.d.ts +24 -0
- package/helpers/getDirectChildren.js +24 -0
- package/helpers/importOnInteraction.cjs +2 -1
- package/helpers/importOnInteraction.js +2 -1
- package/helpers/importWhenVisible.cjs +2 -1
- package/helpers/importWhenVisible.js +2 -1
- package/helpers/index.cjs +2 -0
- package/helpers/index.d.ts +1 -0
- package/helpers/index.js +1 -0
- package/helpers/utils.cjs +3 -2
- package/helpers/utils.js +3 -2
- package/package.json +4 -1
- package/services/drag.cjs +126 -148
- package/services/drag.d.ts +10 -10
- package/services/drag.js +125 -148
- package/services/index.cjs +3 -1
- package/services/index.d.ts +1 -0
- package/services/index.js +3 -1
- package/services/key.cjs +48 -63
- package/services/key.d.ts +0 -8
- package/services/key.js +47 -63
- package/services/load.cjs +24 -40
- package/services/load.d.ts +0 -8
- package/services/load.js +23 -37
- package/services/pointer.cjs +73 -103
- package/services/pointer.d.ts +1 -9
- package/services/pointer.js +72 -100
- package/services/raf.cjs +38 -58
- package/services/raf.d.ts +0 -8
- package/services/raf.js +37 -55
- package/services/resize.cjs +59 -68
- package/services/resize.d.ts +0 -7
- package/services/resize.js +58 -68
- package/services/scroll.cjs +49 -71
- package/services/scroll.js +48 -71
- package/services/service.cjs +68 -0
- package/services/service.d.ts +18 -0
- package/services/service.js +46 -0
- package/utils/css/animate.cjs +31 -96
- package/utils/css/animate.d.ts +4 -16
- package/utils/css/animate.js +28 -93
- package/utils/css/classes.cjs +2 -1
- package/utils/css/classes.js +2 -1
- package/utils/css/styles.cjs +2 -5
- package/utils/css/styles.js +1 -1
- package/utils/css/transform.cjs +13 -16
- package/utils/css/transform.js +1 -1
- package/utils/css/transition.cjs +5 -3
- package/utils/css/transition.js +5 -3
- package/utils/focusTrap.cjs +2 -1
- package/utils/focusTrap.js +2 -1
- package/utils/{isFunction.cjs → has.cjs} +7 -7
- package/utils/has.d.ts +6 -0
- package/utils/has.js +6 -0
- package/utils/history.cjs +5 -7
- package/utils/history.js +4 -3
- package/utils/index.cjs +6 -5
- package/utils/index.d.ts +4 -2
- package/utils/index.js +6 -5
- package/utils/{object/isObject.cjs → is.cjs} +20 -8
- package/utils/is.d.ts +8 -0
- package/utils/is.js +18 -0
- package/utils/math/inertiaFinalValue.cjs +5 -3
- package/utils/math/inertiaFinalValue.js +2 -3
- package/utils/nextFrame.cjs +5 -3
- package/utils/nextFrame.js +5 -3
- package/utils/nextMicrotask.cjs +2 -1
- package/utils/nextMicrotask.js +2 -1
- package/utils/nextTick.cjs +2 -1
- package/utils/nextTick.js +2 -1
- package/utils/{isDefined.cjs → noop.cjs} +10 -7
- package/utils/noop.d.ts +12 -0
- package/utils/noop.js +9 -0
- package/utils/object/autoBind.cjs +3 -2
- package/utils/object/autoBind.js +3 -2
- package/utils/object/getAllProperties.cjs +2 -1
- package/utils/object/getAllProperties.js +2 -1
- package/utils/object/index.cjs +1 -3
- package/utils/object/index.d.ts +0 -1
- package/utils/object/index.js +1 -3
- package/utils/tween.cjs +114 -0
- package/utils/tween.d.ts +25 -0
- package/utils/tween.js +89 -0
- package/services/Service.cjs +0 -76
- package/services/Service.d.ts +0 -76
- package/services/Service.js +0 -55
- package/utils/isDefined.d.ts +0 -7
- package/utils/isDefined.js +0 -6
- package/utils/isFunction.d.ts +0 -7
- package/utils/isFunction.js +0 -6
- package/utils/object/isObject.d.ts +0 -7
- package/utils/object/isObject.js +0 -6
|
@@ -5,6 +5,7 @@ var __publicField = (obj, key, value) => {
|
|
|
5
5
|
return value;
|
|
6
6
|
};
|
|
7
7
|
import useResize from "../services/resize.js";
|
|
8
|
+
import { isDev } from "../utils/index.js";
|
|
8
9
|
function testBreakpoints(instance, breakpoint = useResize().props().breakpoint) {
|
|
9
10
|
const { activeBreakpoints, inactiveBreakpoints } = instance.$options;
|
|
10
11
|
const isInActiveBreakpoint = activeBreakpoints && activeBreakpoints.split(" ").includes(breakpoint);
|
|
@@ -25,7 +26,9 @@ function testConflictingBreakpointConfiguration(instance) {
|
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
function addToResize(key, instance) {
|
|
28
|
-
|
|
29
|
+
if (isDev) {
|
|
30
|
+
testConflictingBreakpointConfiguration(instance);
|
|
31
|
+
}
|
|
29
32
|
const { add, has } = useResize();
|
|
30
33
|
if (!has(key)) {
|
|
31
34
|
add(key, function onResize({ breakpoint }) {
|
|
@@ -46,7 +49,10 @@ function withBreakpointObserver(BaseClass) {
|
|
|
46
49
|
const { remove, props } = useResize();
|
|
47
50
|
const { name } = this.$options;
|
|
48
51
|
if (!props().breakpoint) {
|
|
49
|
-
|
|
52
|
+
if (isDev) {
|
|
53
|
+
throw new Error(`[${name}] The \`BreakpointObserver\` class requires breakpoints to be defined.`);
|
|
54
|
+
}
|
|
55
|
+
return;
|
|
50
56
|
}
|
|
51
57
|
const key = `BreakpointObserver-${this.$id}`;
|
|
52
58
|
const mutationObserver = new MutationObserver(([mutation]) => {
|
package/decorators/withVue2.cjs
CHANGED
|
@@ -27,6 +27,7 @@ __export(withVue2_exports, {
|
|
|
27
27
|
default: () => withVue2_default
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(withVue2_exports);
|
|
30
|
+
var import_utils = require("../utils/index.cjs");
|
|
30
31
|
var withVue2_default = (BaseClass, Vue) => {
|
|
31
32
|
var _a, _b, _c;
|
|
32
33
|
return _c = class extends BaseClass {
|
|
@@ -36,10 +37,16 @@ var withVue2_default = (BaseClass, Vue) => {
|
|
|
36
37
|
__publicField(this, "$vue");
|
|
37
38
|
const vueConfig = (_a2 = this.vueConfig) != null ? _a2 : this.constructor.vueConfig;
|
|
38
39
|
if (!vueConfig) {
|
|
39
|
-
|
|
40
|
+
if (import_utils.isDev) {
|
|
41
|
+
throw new Error("[withVue] You must define a `vueConfig` object.");
|
|
42
|
+
}
|
|
43
|
+
return;
|
|
40
44
|
}
|
|
41
|
-
if (
|
|
42
|
-
|
|
45
|
+
if (!(0, import_utils.isFunction)(vueConfig.render)) {
|
|
46
|
+
if (import_utils.isDev) {
|
|
47
|
+
throw new Error("[withVue] You must define a `render` function in vueConfig.");
|
|
48
|
+
}
|
|
49
|
+
return;
|
|
43
50
|
}
|
|
44
51
|
this.$vue = new Vue(vueConfig);
|
|
45
52
|
this.$on("mounted", () => {
|
package/decorators/withVue2.js
CHANGED
|
@@ -4,6 +4,7 @@ var __publicField = (obj, key, value) => {
|
|
|
4
4
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
5
|
return value;
|
|
6
6
|
};
|
|
7
|
+
import { isDev, isFunction } from "../utils/index.js";
|
|
7
8
|
var withVue2_default = (BaseClass, Vue) => {
|
|
8
9
|
var _a, _b, _c;
|
|
9
10
|
return _c = class extends BaseClass {
|
|
@@ -13,10 +14,16 @@ var withVue2_default = (BaseClass, Vue) => {
|
|
|
13
14
|
__publicField(this, "$vue");
|
|
14
15
|
const vueConfig = (_a2 = this.vueConfig) != null ? _a2 : this.constructor.vueConfig;
|
|
15
16
|
if (!vueConfig) {
|
|
16
|
-
|
|
17
|
+
if (isDev) {
|
|
18
|
+
throw new Error("[withVue] You must define a `vueConfig` object.");
|
|
19
|
+
}
|
|
20
|
+
return;
|
|
17
21
|
}
|
|
18
|
-
if (
|
|
19
|
-
|
|
22
|
+
if (!isFunction(vueConfig.render)) {
|
|
23
|
+
if (isDev) {
|
|
24
|
+
throw new Error("[withVue] You must define a `render` function in vueConfig.");
|
|
25
|
+
}
|
|
26
|
+
return;
|
|
20
27
|
}
|
|
21
28
|
this.$vue = new Vue(vueConfig);
|
|
22
29
|
this.$on("mounted", () => {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// packages/js-toolkit/helpers/getDirectChildren.js
|
|
20
|
+
var getDirectChildren_exports = {};
|
|
21
|
+
__export(getDirectChildren_exports, {
|
|
22
|
+
getDirectChildren: () => getDirectChildren,
|
|
23
|
+
isDirectChild: () => isDirectChild
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(getDirectChildren_exports);
|
|
26
|
+
var import_utils = require("../utils/index.cjs");
|
|
27
|
+
function getDirectChildren(parentInstance, parentName, childrenName) {
|
|
28
|
+
const children = parentInstance.$children[childrenName];
|
|
29
|
+
const nestedParents = parentInstance.$children[parentName];
|
|
30
|
+
if (!(0, import_utils.isArray)(children)) {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
if (!(0, import_utils.isArray)(nestedParents) || nestedParents.length <= 0) {
|
|
34
|
+
return children;
|
|
35
|
+
}
|
|
36
|
+
return children.filter((child) => {
|
|
37
|
+
return nestedParents.every((nestedParent) => {
|
|
38
|
+
const nestedChildren = nestedParent.$children[childrenName];
|
|
39
|
+
return (0, import_utils.isArray)(nestedChildren) ? !nestedChildren.includes(child) : true;
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function isDirectChild(parentInstance, parentName, childrenName, childInstance) {
|
|
44
|
+
return getDirectChildren(parentInstance, parentName, childrenName).includes(childInstance);
|
|
45
|
+
}
|
|
46
|
+
if (module.exports.default) module.exports = module.exports.default;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('../Base/index.js').default} Base
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Get direct children from a parent when working with nested components.
|
|
6
|
+
*
|
|
7
|
+
* @template {Base} T
|
|
8
|
+
* @param {Base} parentInstance
|
|
9
|
+
* @param {string} parentName
|
|
10
|
+
* @param {string} childrenName
|
|
11
|
+
* @returns {Array<T>}
|
|
12
|
+
*/
|
|
13
|
+
export function getDirectChildren<T extends import("../Base/index.js").default>(parentInstance: Base, parentName: string, childrenName: string): T[];
|
|
14
|
+
/**
|
|
15
|
+
* Test if a component instance is a direct child from the given component.
|
|
16
|
+
*
|
|
17
|
+
* @param {Base} parentInstance
|
|
18
|
+
* @param {string} parentName
|
|
19
|
+
* @param {string} childrenName
|
|
20
|
+
* @param {Base} childInstance
|
|
21
|
+
* @returns {boolean}
|
|
22
|
+
*/
|
|
23
|
+
export function isDirectChild(parentInstance: Base, parentName: string, childrenName: string, childInstance: Base): boolean;
|
|
24
|
+
export type Base = import('../Base/index.js').default;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { isArray } from "../utils/index.js";
|
|
2
|
+
function getDirectChildren(parentInstance, parentName, childrenName) {
|
|
3
|
+
const children = parentInstance.$children[childrenName];
|
|
4
|
+
const nestedParents = parentInstance.$children[parentName];
|
|
5
|
+
if (!isArray(children)) {
|
|
6
|
+
return [];
|
|
7
|
+
}
|
|
8
|
+
if (!isArray(nestedParents) || nestedParents.length <= 0) {
|
|
9
|
+
return children;
|
|
10
|
+
}
|
|
11
|
+
return children.filter((child) => {
|
|
12
|
+
return nestedParents.every((nestedParent) => {
|
|
13
|
+
const nestedChildren = nestedParent.$children[childrenName];
|
|
14
|
+
return isArray(nestedChildren) ? !nestedChildren.includes(child) : true;
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function isDirectChild(parentInstance, parentName, childrenName, childInstance) {
|
|
19
|
+
return getDirectChildren(parentInstance, parentName, childrenName).includes(childInstance);
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
getDirectChildren,
|
|
23
|
+
isDirectChild
|
|
24
|
+
};
|
|
@@ -23,8 +23,9 @@ __export(importOnInteraction_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(importOnInteraction_exports);
|
|
25
25
|
var import_utils = require("./utils.cjs");
|
|
26
|
+
var import_utils2 = require("../utils/index.cjs");
|
|
26
27
|
function importOnInteraction(fn, nameOrSelectorOrElement, events, parent) {
|
|
27
|
-
const normalizedEvents =
|
|
28
|
+
const normalizedEvents = (0, import_utils2.isString)(events) ? [events] : events;
|
|
28
29
|
let ResolvedClass;
|
|
29
30
|
const resolver = (resolve) => {
|
|
30
31
|
fn().then((module2) => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getTargetElements } from "./utils.js";
|
|
2
|
+
import { isString } from "../utils/index.js";
|
|
2
3
|
function importOnInteraction(fn, nameOrSelectorOrElement, events, parent) {
|
|
3
|
-
const normalizedEvents =
|
|
4
|
+
const normalizedEvents = isString(events) ? [events] : events;
|
|
4
5
|
let ResolvedClass;
|
|
5
6
|
const resolver = (resolve) => {
|
|
6
7
|
fn().then((module) => {
|
|
@@ -23,13 +23,14 @@ __export(importWhenVisible_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(importWhenVisible_exports);
|
|
25
25
|
var import_utils = require("./utils.cjs");
|
|
26
|
+
var import_utils2 = require("../utils/index.cjs");
|
|
26
27
|
function importWhenVisible(fn, nameOrSelectorOrElement, parent, observerOptions = {}) {
|
|
27
28
|
let ResolvedClass;
|
|
28
29
|
const resolver = (resolve, cb) => {
|
|
29
30
|
fn().then((module2) => {
|
|
30
31
|
ResolvedClass = "default" in module2 ? module2.default : module2;
|
|
31
32
|
resolve(ResolvedClass);
|
|
32
|
-
if (
|
|
33
|
+
if ((0, import_utils2.isFunction)(cb)) {
|
|
33
34
|
cb();
|
|
34
35
|
}
|
|
35
36
|
});
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { getTargetElements } from "./utils.js";
|
|
2
|
+
import { isFunction } from "../utils/index.js";
|
|
2
3
|
function importWhenVisible(fn, nameOrSelectorOrElement, parent, observerOptions = {}) {
|
|
3
4
|
let ResolvedClass;
|
|
4
5
|
const resolver = (resolve, cb) => {
|
|
5
6
|
fn().then((module) => {
|
|
6
7
|
ResolvedClass = "default" in module ? module.default : module;
|
|
7
8
|
resolve(ResolvedClass);
|
|
8
|
-
if (
|
|
9
|
+
if (isFunction(cb)) {
|
|
9
10
|
cb();
|
|
10
11
|
}
|
|
11
12
|
});
|
package/helpers/index.cjs
CHANGED
|
@@ -16,6 +16,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
}
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
20
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
20
21
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
22
|
|
|
@@ -30,6 +31,7 @@ __export(helpers_exports, {
|
|
|
30
31
|
});
|
|
31
32
|
module.exports = __toCommonJS(helpers_exports);
|
|
32
33
|
var import_createApp = __toESM(require("./createApp.cjs"), 1);
|
|
34
|
+
__reExport(helpers_exports, require("./getDirectChildren.cjs"), module.exports);
|
|
33
35
|
var import_getInstanceFromElement = __toESM(require("./getInstanceFromElement.cjs"), 1);
|
|
34
36
|
var import_importOnInteraction = __toESM(require("./importOnInteraction.cjs"), 1);
|
|
35
37
|
var import_importWhenIdle = __toESM(require("./importWhenIdle.cjs"), 1);
|
package/helpers/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { default as createApp } from "./createApp.js";
|
|
2
|
+
export * from "./getDirectChildren.js";
|
|
2
3
|
export { default as getInstanceFromElement } from "./getInstanceFromElement.js";
|
|
3
4
|
export { default as importOnInteraction } from "./importOnInteraction.js";
|
|
4
5
|
export { default as importWhenIdle } from "./importWhenIdle.js";
|
package/helpers/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { default as default2 } from "./createApp.js";
|
|
2
|
+
export * from "./getDirectChildren.js";
|
|
2
3
|
import { default as default3 } from "./getInstanceFromElement.js";
|
|
3
4
|
import { default as default4 } from "./importOnInteraction.js";
|
|
4
5
|
import { default as default5 } from "./importWhenIdle.js";
|
package/helpers/utils.cjs
CHANGED
|
@@ -23,11 +23,12 @@ __export(utils_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(utils_exports);
|
|
25
25
|
var import_utils = require("../Base/utils.cjs");
|
|
26
|
+
var import_utils2 = require("../utils/index.cjs");
|
|
26
27
|
function getTargetElements(nameOrSelectorOrElement, context) {
|
|
27
|
-
if (
|
|
28
|
+
if ((0, import_utils2.isString)(nameOrSelectorOrElement)) {
|
|
28
29
|
return (0, import_utils.getComponentElements)(nameOrSelectorOrElement, context);
|
|
29
30
|
}
|
|
30
|
-
if (!
|
|
31
|
+
if (!(0, import_utils2.isArray)(nameOrSelectorOrElement)) {
|
|
31
32
|
return [nameOrSelectorOrElement];
|
|
32
33
|
}
|
|
33
34
|
return nameOrSelectorOrElement;
|
package/helpers/utils.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { getComponentElements } from "../Base/utils.js";
|
|
2
|
+
import { isString, isArray } from "../utils/index.js";
|
|
2
3
|
function getTargetElements(nameOrSelectorOrElement, context) {
|
|
3
|
-
if (
|
|
4
|
+
if (isString(nameOrSelectorOrElement)) {
|
|
4
5
|
return getComponentElements(nameOrSelectorOrElement, context);
|
|
5
6
|
}
|
|
6
|
-
if (!
|
|
7
|
+
if (!isArray(nameOrSelectorOrElement)) {
|
|
7
8
|
return [nameOrSelectorOrElement];
|
|
8
9
|
}
|
|
9
10
|
return nameOrSelectorOrElement;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@studiometa/js-toolkit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "A set of useful little bits of JavaScript to boost your project! 🚀",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -41,5 +41,8 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@motionone/easing": "^10.9.0",
|
|
43
43
|
"deepmerge": "^4.2.2"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"vue": "2.6"
|
|
44
47
|
}
|
|
45
48
|
}
|
package/services/drag.cjs
CHANGED
|
@@ -4,7 +4,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
7
|
var __export = (target, all) => {
|
|
9
8
|
for (var name in all)
|
|
10
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -19,10 +18,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
19
18
|
};
|
|
20
19
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
21
20
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
-
var __publicField = (obj, key, value) => {
|
|
23
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
24
|
-
return value;
|
|
25
|
-
};
|
|
26
21
|
|
|
27
22
|
// packages/js-toolkit/services/drag.js
|
|
28
23
|
var drag_exports = {};
|
|
@@ -30,7 +25,7 @@ __export(drag_exports, {
|
|
|
30
25
|
default: () => useDrag
|
|
31
26
|
});
|
|
32
27
|
module.exports = __toCommonJS(drag_exports);
|
|
33
|
-
var
|
|
28
|
+
var import_service = require("./service.cjs");
|
|
34
29
|
var import_pointer = __toESM(require("./pointer.cjs"), 1);
|
|
35
30
|
var import_raf = __toESM(require("./raf.cjs"), 1);
|
|
36
31
|
var import_inertiaFinalValue = __toESM(require("../utils/math/inertiaFinalValue.cjs"), 1);
|
|
@@ -41,13 +36,103 @@ var MODES = {
|
|
|
41
36
|
INERTIA: "inertia",
|
|
42
37
|
STOP: "stop"
|
|
43
38
|
};
|
|
44
|
-
var
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
39
|
+
var count = 0;
|
|
40
|
+
function createDragService(target, { dampFactor = 0.85, dragTreshold = 10 } = {}) {
|
|
41
|
+
count += 1;
|
|
42
|
+
const id = `drag-${count}`;
|
|
43
|
+
function shouldPreventClick() {
|
|
44
|
+
return Math.abs(props.distance.x) > dragTreshold || Math.abs(props.distance.y) > dragTreshold;
|
|
45
|
+
}
|
|
46
|
+
function start(x, y) {
|
|
47
|
+
props.x = x;
|
|
48
|
+
props.y = y;
|
|
49
|
+
props.origin.x = x;
|
|
50
|
+
props.origin.y = y;
|
|
51
|
+
props.delta.x = 0;
|
|
52
|
+
props.delta.y = 0;
|
|
53
|
+
props.distance.x = 0;
|
|
54
|
+
props.distance.y = 0;
|
|
55
|
+
props.final.x = x;
|
|
56
|
+
props.final.y = y;
|
|
57
|
+
props.mode = MODES.START;
|
|
58
|
+
props.isGrabbing = true;
|
|
59
|
+
trigger(props);
|
|
60
|
+
}
|
|
61
|
+
function drop() {
|
|
62
|
+
props.isGrabbing = false;
|
|
63
|
+
props.mode = MODES.DROP;
|
|
64
|
+
props.hasInertia = true;
|
|
65
|
+
props.final.x = (0, import_inertiaFinalValue.default)(props.x, props.delta.x, dampFactor);
|
|
66
|
+
props.final.y = (0, import_inertiaFinalValue.default)(props.y, props.delta.y, dampFactor);
|
|
67
|
+
trigger(props);
|
|
68
|
+
setTimeout(() => {
|
|
69
|
+
const raf = (0, import_raf.default)();
|
|
70
|
+
raf.remove(id);
|
|
71
|
+
raf.add(id, rafHandler);
|
|
72
|
+
}, 0);
|
|
73
|
+
}
|
|
74
|
+
function stop() {
|
|
75
|
+
(0, import_raf.default)().remove(id);
|
|
76
|
+
props.hasInertia = false;
|
|
77
|
+
props.mode = MODES.STOP;
|
|
78
|
+
trigger(props);
|
|
79
|
+
}
|
|
80
|
+
function rafHandler() {
|
|
81
|
+
if (!props.isGrabbing) {
|
|
82
|
+
props.x += props.delta.x;
|
|
83
|
+
props.y += props.delta.y;
|
|
84
|
+
props.distance.x = props.x - props.origin.x;
|
|
85
|
+
props.distance.y = props.y - props.origin.y;
|
|
86
|
+
props.delta.x *= dampFactor;
|
|
87
|
+
props.delta.y *= dampFactor;
|
|
88
|
+
if (props.mode !== MODES.INERTIA) {
|
|
89
|
+
props.mode = MODES.INERTIA;
|
|
90
|
+
}
|
|
91
|
+
trigger(props);
|
|
92
|
+
if (Math.abs(props.delta.x) < 0.1 && Math.abs(props.delta.y) < 0.1) {
|
|
93
|
+
stop();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function pointerHandler(pointerProps) {
|
|
98
|
+
if (props.isGrabbing) {
|
|
99
|
+
props.x = pointerProps.x;
|
|
100
|
+
props.y = pointerProps.y;
|
|
101
|
+
props.delta.x = pointerProps.delta.x;
|
|
102
|
+
props.delta.y = pointerProps.delta.y;
|
|
103
|
+
props.final.x = pointerProps.x;
|
|
104
|
+
props.final.y = pointerProps.y;
|
|
105
|
+
props.distance.x = props.x - props.origin.x;
|
|
106
|
+
props.distance.y = props.y - props.origin.y;
|
|
107
|
+
if (props.mode !== MODES.DRAG) {
|
|
108
|
+
props.mode = MODES.DRAG;
|
|
109
|
+
}
|
|
110
|
+
trigger(props);
|
|
111
|
+
if (!pointerProps.isDown) {
|
|
112
|
+
drop();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function handleEvent(event) {
|
|
117
|
+
if (event.type === "dragstart") {
|
|
118
|
+
event.preventDefault();
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (event.type === "click") {
|
|
122
|
+
if (shouldPreventClick()) {
|
|
123
|
+
event.stopImmediatePropagation();
|
|
124
|
+
event.stopPropagation();
|
|
125
|
+
event.preventDefault();
|
|
126
|
+
}
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const x = event instanceof MouseEvent ? event.clientX : event.touches[0].clientX;
|
|
130
|
+
const y = event instanceof MouseEvent ? event.clientY : event.touches[0].clientY;
|
|
131
|
+
start(x, y);
|
|
132
|
+
}
|
|
133
|
+
const { add, remove, has, trigger, props } = (0, import_service.useService)({
|
|
134
|
+
props: {
|
|
135
|
+
target,
|
|
51
136
|
mode: void 0,
|
|
52
137
|
isGrabbing: false,
|
|
53
138
|
hasInertia: false,
|
|
@@ -69,144 +154,37 @@ var Drag = class extends import_Service.default {
|
|
|
69
154
|
x: 0,
|
|
70
155
|
y: 0
|
|
71
156
|
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
this.props.target.addEventListener("click", this, { capture: true });
|
|
90
|
-
const pointer = (0, import_pointer.default)();
|
|
91
|
-
pointer.add(this.id, this.pointerHandler);
|
|
92
|
-
return this;
|
|
93
|
-
}
|
|
94
|
-
kill() {
|
|
95
|
-
this.props.target.removeEventListener("mousedown", this);
|
|
96
|
-
this.props.target.removeEventListener("touchstart", this);
|
|
97
|
-
this.props.target.removeEventListener("dragstart", this);
|
|
98
|
-
this.props.target.removeEventListener("click", this);
|
|
99
|
-
const pointer = (0, import_pointer.default)();
|
|
100
|
-
pointer.remove(this.id);
|
|
101
|
-
return this;
|
|
102
|
-
}
|
|
103
|
-
handleEvent(event) {
|
|
104
|
-
if (event.type === "dragstart") {
|
|
105
|
-
event.preventDefault();
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
if (event.type === "click") {
|
|
109
|
-
if (this.__shouldPreventClick) {
|
|
110
|
-
event.stopImmediatePropagation();
|
|
111
|
-
event.stopPropagation();
|
|
112
|
-
event.preventDefault();
|
|
113
|
-
}
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
const x = event instanceof MouseEvent ? event.clientX : event.touches[0].clientX;
|
|
117
|
-
const y = event instanceof MouseEvent ? event.clientY : event.touches[0].clientY;
|
|
118
|
-
this.start(x, y);
|
|
119
|
-
}
|
|
120
|
-
start(x, y) {
|
|
121
|
-
this.props.x = x;
|
|
122
|
-
this.props.y = y;
|
|
123
|
-
this.props.origin.x = x;
|
|
124
|
-
this.props.origin.y = y;
|
|
125
|
-
this.props.delta.x = 0;
|
|
126
|
-
this.props.delta.y = 0;
|
|
127
|
-
this.props.distance.x = 0;
|
|
128
|
-
this.props.distance.y = 0;
|
|
129
|
-
this.props.final.x = x;
|
|
130
|
-
this.props.final.y = y;
|
|
131
|
-
this.props.mode = MODES.START;
|
|
132
|
-
this.props.isGrabbing = true;
|
|
133
|
-
this.trigger(this.props);
|
|
134
|
-
}
|
|
135
|
-
drop() {
|
|
136
|
-
this.props.isGrabbing = false;
|
|
137
|
-
this.props.mode = MODES.DROP;
|
|
138
|
-
this.props.hasInertia = true;
|
|
139
|
-
this.props.final.x = (0, import_inertiaFinalValue.default)(this.props.x, this.props.delta.x, this.options.dampFactor);
|
|
140
|
-
this.props.final.y = (0, import_inertiaFinalValue.default)(this.props.y, this.props.delta.y, this.options.dampFactor);
|
|
141
|
-
this.trigger(this.props);
|
|
142
|
-
setTimeout(() => {
|
|
143
|
-
const raf = (0, import_raf.default)();
|
|
144
|
-
raf.remove(this.id);
|
|
145
|
-
raf.add(this.id, this.rafHandler);
|
|
146
|
-
}, 0);
|
|
147
|
-
}
|
|
148
|
-
stop() {
|
|
149
|
-
(0, import_raf.default)().remove(this.id);
|
|
150
|
-
this.props.hasInertia = false;
|
|
151
|
-
this.props.mode = MODES.STOP;
|
|
152
|
-
this.trigger(this.props);
|
|
153
|
-
}
|
|
154
|
-
rafHandler() {
|
|
155
|
-
if (!this.props.isGrabbing) {
|
|
156
|
-
this.props.x += this.props.delta.x;
|
|
157
|
-
this.props.y += this.props.delta.y;
|
|
158
|
-
this.props.distance.x = this.props.x - this.props.origin.x;
|
|
159
|
-
this.props.distance.y = this.props.y - this.props.origin.y;
|
|
160
|
-
this.props.delta.x *= this.options.dampFactor;
|
|
161
|
-
this.props.delta.y *= this.options.dampFactor;
|
|
162
|
-
if (this.props.mode !== MODES.INERTIA) {
|
|
163
|
-
this.props.mode = MODES.INERTIA;
|
|
164
|
-
}
|
|
165
|
-
this.trigger(this.props);
|
|
166
|
-
if (Math.abs(this.props.delta.x) < 0.1 && Math.abs(this.props.delta.y) < 0.1) {
|
|
167
|
-
this.stop();
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
pointerHandler(props) {
|
|
172
|
-
if (this.props.isGrabbing) {
|
|
173
|
-
this.props.x = props.x;
|
|
174
|
-
this.props.y = props.y;
|
|
175
|
-
this.props.delta.x = props.delta.x;
|
|
176
|
-
this.props.delta.y = props.delta.y;
|
|
177
|
-
this.props.final.x = props.x;
|
|
178
|
-
this.props.final.y = props.y;
|
|
179
|
-
this.props.distance.x = this.props.x - this.props.origin.x;
|
|
180
|
-
this.props.distance.y = this.props.y - this.props.origin.y;
|
|
181
|
-
if (this.props.mode !== MODES.DRAG) {
|
|
182
|
-
this.props.mode = MODES.DRAG;
|
|
183
|
-
}
|
|
184
|
-
this.trigger(this.props);
|
|
185
|
-
if (!props.isDown) {
|
|
186
|
-
this.drop();
|
|
187
|
-
}
|
|
157
|
+
},
|
|
158
|
+
init() {
|
|
159
|
+
const options = { passive: true };
|
|
160
|
+
props.target.addEventListener("mousedown", handleEvent, options);
|
|
161
|
+
props.target.addEventListener("touchstart", handleEvent, options);
|
|
162
|
+
props.target.addEventListener("dragstart", handleEvent, { capture: true });
|
|
163
|
+
props.target.addEventListener("click", handleEvent, { capture: true });
|
|
164
|
+
const pointer = (0, import_pointer.default)();
|
|
165
|
+
pointer.add(id, pointerHandler);
|
|
166
|
+
},
|
|
167
|
+
kill() {
|
|
168
|
+
props.target.removeEventListener("mousedown", handleEvent);
|
|
169
|
+
props.target.removeEventListener("touchstart", handleEvent);
|
|
170
|
+
props.target.removeEventListener("dragstart", handleEvent);
|
|
171
|
+
props.target.removeEventListener("click", handleEvent);
|
|
172
|
+
const pointer = (0, import_pointer.default)();
|
|
173
|
+
pointer.remove(id);
|
|
188
174
|
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
}
|
|
175
|
+
});
|
|
176
|
+
return {
|
|
177
|
+
add,
|
|
178
|
+
remove,
|
|
179
|
+
has,
|
|
180
|
+
props: () => props
|
|
181
|
+
};
|
|
182
|
+
}
|
|
197
183
|
var instances = /* @__PURE__ */ new WeakMap();
|
|
198
184
|
function useDrag(target, options) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
const instance = new Drag(target, options);
|
|
202
|
-
drag = {
|
|
203
|
-
add: instance.add.bind(instance),
|
|
204
|
-
remove: instance.remove.bind(instance),
|
|
205
|
-
has: instance.has.bind(instance),
|
|
206
|
-
props: instance.updateProps.bind(instance)
|
|
207
|
-
};
|
|
208
|
-
instances.set(target, drag);
|
|
185
|
+
if (!instances.has(target)) {
|
|
186
|
+
instances.set(target, createDragService(target, options));
|
|
209
187
|
}
|
|
210
|
-
return
|
|
188
|
+
return instances.get(target);
|
|
211
189
|
}
|
|
212
190
|
if (module.exports.default) module.exports = module.exports.default;
|