@studiometa/js-toolkit 2.0.0-beta.9 → 2.0.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 +284 -0
- package/Base/index.d.ts +36 -28
- package/Base/index.js +113 -197
- package/Base/managers/ChildrenManager.cjs +146 -0
- package/Base/managers/ChildrenManager.d.ts +11 -3
- package/Base/managers/ChildrenManager.js +60 -59
- package/Base/managers/EventsManager.cjs +183 -0
- package/Base/managers/EventsManager.d.ts +13 -20
- package/Base/managers/EventsManager.js +72 -112
- package/Base/managers/OptionsManager.cjs +173 -0
- package/Base/managers/OptionsManager.d.ts +20 -13
- package/Base/managers/OptionsManager.js +60 -91
- package/Base/managers/RefsManager.cjs +99 -0
- package/Base/managers/RefsManager.d.ts +4 -4
- package/Base/managers/RefsManager.js +28 -38
- package/Base/managers/ServicesManager.cjs +134 -0
- package/Base/managers/ServicesManager.d.ts +14 -8
- package/Base/managers/ServicesManager.js +42 -67
- package/Base/utils.cjs +41 -0
- package/Base/utils.d.ts +4 -4
- package/Base/utils.js +12 -11
- package/decorators/index.cjs +45 -0
- package/decorators/index.d.ts +1 -0
- package/decorators/index.js +20 -8
- package/decorators/withBreakpointManager.cjs +84 -0
- package/decorators/withBreakpointManager.d.ts +2 -2
- package/decorators/withBreakpointManager.js +18 -40
- package/decorators/withBreakpointObserver.cjs +114 -0
- package/decorators/withBreakpointObserver.d.ts +1 -1
- package/decorators/withBreakpointObserver.js +45 -88
- package/decorators/withDrag.cjs +53 -0
- package/decorators/withDrag.d.ts +1 -1
- package/decorators/withDrag.js +24 -26
- package/decorators/withExtraConfig.cjs +43 -0
- package/decorators/withExtraConfig.d.ts +1 -1
- package/decorators/withExtraConfig.js +17 -12
- package/decorators/withFreezedOptions.cjs +37 -0
- package/decorators/withFreezedOptions.d.ts +14 -0
- package/decorators/withFreezedOptions.js +15 -0
- package/decorators/withIntersectionObserver.cjs +61 -0
- package/decorators/withIntersectionObserver.d.ts +1 -1
- package/decorators/withIntersectionObserver.js +29 -33
- package/decorators/withMountWhenInView.cjs +68 -0
- package/decorators/withMountWhenInView.d.ts +1 -1
- package/decorators/withMountWhenInView.js +31 -53
- package/decorators/withScrolledInView.cjs +114 -0
- package/decorators/withScrolledInView.d.ts +1 -1
- package/decorators/withScrolledInView.js +35 -39
- package/decorators/withVue2.cjs +61 -0
- package/decorators/withVue2.js +27 -32
- package/helpers/createApp.cjs +52 -0
- package/helpers/createApp.d.ts +3 -26
- package/helpers/createApp.js +12 -12
- package/helpers/getInstanceFromElement.cjs +32 -0
- package/helpers/getInstanceFromElement.d.ts +14 -0
- package/helpers/getInstanceFromElement.js +10 -0
- package/helpers/importOnInteraction.cjs +52 -0
- package/helpers/importOnInteraction.d.ts +3 -5
- package/helpers/importOnInteraction.js +17 -18
- package/helpers/importWhenIdle.cjs +49 -0
- package/helpers/importWhenIdle.d.ts +3 -5
- package/helpers/importWhenIdle.js +14 -17
- package/helpers/importWhenVisible.cjs +50 -0
- package/helpers/importWhenVisible.d.ts +4 -6
- package/helpers/importWhenVisible.js +16 -18
- package/helpers/index.cjs +37 -0
- package/helpers/index.d.ts +1 -0
- package/helpers/index.js +12 -4
- package/helpers/utils.cjs +35 -0
- package/helpers/utils.d.ts +3 -4
- package/helpers/utils.js +7 -6
- package/index.cjs +33 -0
- package/index.js +7 -4
- package/package.json +14 -4
- package/services/Service.cjs +76 -0
- package/services/Service.d.ts +9 -9
- package/services/Service.js +19 -32
- package/services/drag.cjs +212 -0
- package/services/drag.d.ts +3 -2
- package/services/drag.js +64 -69
- package/services/index.cjs +41 -0
- package/services/index.js +16 -7
- package/services/key.cjs +104 -0
- package/services/key.d.ts +1 -1
- package/services/key.js +28 -36
- package/services/load.cjs +72 -0
- package/services/load.d.ts +1 -1
- package/services/load.js +17 -19
- package/services/pointer.cjs +162 -0
- package/services/pointer.d.ts +1 -1
- package/services/pointer.js +43 -60
- package/services/raf.cjs +83 -0
- package/services/raf.d.ts +1 -1
- package/services/raf.js +20 -28
- package/services/resize.cjs +108 -0
- package/services/resize.d.ts +1 -1
- package/services/resize.js +33 -42
- package/services/scroll.cjs +131 -0
- package/services/scroll.d.ts +1 -1
- package/services/scroll.js +26 -35
- package/utils/collide/boundingRectToCircle.cjs +34 -0
- package/utils/collide/boundingRectToCircle.d.ts +6 -6
- package/utils/collide/boundingRectToCircle.js +7 -10
- package/utils/collide/collideCircleCircle.cjs +34 -0
- package/utils/collide/collideCircleCircle.d.ts +4 -4
- package/utils/collide/collideCircleCircle.js +8 -7
- package/utils/collide/collideCircleRect.cjs +46 -0
- package/utils/collide/collideCircleRect.d.ts +8 -8
- package/utils/collide/collideCircleRect.js +10 -12
- package/utils/collide/collidePointCircle.cjs +31 -0
- package/utils/collide/collidePointCircle.d.ts +6 -6
- package/utils/collide/collidePointCircle.js +8 -5
- package/utils/collide/collidePointRect.cjs +28 -0
- package/utils/collide/collidePointRect.d.ts +7 -7
- package/utils/collide/collidePointRect.js +5 -2
- package/utils/collide/collideRectRect.cjs +28 -0
- package/utils/collide/collideRectRect.d.ts +5 -5
- package/utils/collide/collideRectRect.js +5 -2
- package/utils/collide/index.cjs +39 -0
- package/utils/collide/index.js +14 -6
- package/utils/css/classes.cjs +47 -0
- package/utils/css/classes.d.ts +13 -12
- package/utils/css/classes.js +19 -15
- package/utils/css/index.cjs +38 -0
- package/utils/css/index.d.ts +2 -2
- package/utils/css/index.js +13 -6
- package/utils/css/matrix.cjs +30 -0
- package/utils/css/matrix.d.ts +14 -15
- package/utils/css/matrix.js +7 -5
- package/utils/css/styles.cjs +44 -0
- package/utils/css/styles.d.ts +8 -20
- package/utils/css/styles.js +12 -12
- package/utils/css/transition.cjs +120 -0
- package/utils/css/transition.d.ts +15 -9
- package/utils/css/transition.js +70 -119
- package/utils/debounce.cjs +34 -0
- package/utils/debounce.d.ts +4 -4
- package/utils/debounce.js +7 -9
- package/utils/focusTrap.cjs +82 -0
- package/utils/focusTrap.d.ts +1 -0
- package/utils/focusTrap.js +31 -22
- package/utils/history.cjs +89 -0
- package/utils/history.d.ts +13 -11
- package/utils/history.js +28 -57
- package/utils/index.cjs +54 -0
- package/utils/index.d.ts +4 -1
- package/utils/index.js +32 -11
- package/utils/keyCodes.cjs +35 -0
- package/utils/keyCodes.js +5 -2
- package/utils/math/clamp.cjs +28 -0
- package/utils/math/clamp.d.ts +1 -1
- package/utils/math/clamp.js +5 -2
- package/utils/math/clamp01.cjs +32 -0
- package/utils/math/clamp01.d.ts +1 -1
- package/utils/math/clamp01.js +6 -3
- package/utils/math/damp.cjs +28 -0
- package/utils/math/damp.d.ts +6 -6
- package/utils/math/damp.js +5 -4
- package/utils/math/ease.cjs +88 -0
- package/utils/math/ease.d.ts +7 -7
- package/utils/math/ease.js +50 -25
- package/utils/math/index.cjs +43 -0
- package/utils/math/index.js +17 -8
- package/utils/math/inertiaFinalValue.cjs +37 -0
- package/utils/math/inertiaFinalValue.d.ts +5 -5
- package/utils/math/inertiaFinalValue.js +8 -10
- package/utils/math/lerp.cjs +28 -0
- package/utils/math/lerp.d.ts +4 -4
- package/utils/math/lerp.js +5 -2
- package/utils/math/map.cjs +28 -0
- package/utils/math/map.d.ts +6 -6
- package/utils/math/map.js +5 -2
- package/utils/math/round.cjs +28 -0
- package/utils/math/round.d.ts +4 -4
- package/utils/math/round.js +5 -3
- package/utils/memoize.cjs +43 -0
- package/utils/memoize.d.ts +1 -1
- package/utils/memoize.js +10 -19
- package/utils/nextFrame.cjs +38 -0
- package/utils/nextFrame.d.ts +6 -6
- package/utils/nextFrame.js +13 -10
- package/utils/nextMicrotask.cjs +28 -0
- package/utils/nextMicrotask.d.ts +8 -0
- package/utils/nextMicrotask.js +6 -0
- package/utils/nextTick.cjs +30 -0
- package/utils/nextTick.d.ts +8 -0
- package/utils/nextTick.js +8 -0
- package/utils/object/autoBind.cjs +49 -0
- package/utils/object/autoBind.d.ts +3 -3
- package/utils/object/autoBind.js +12 -22
- package/utils/object/getAllProperties.cjs +37 -0
- package/utils/object/getAllProperties.d.ts +3 -3
- package/utils/object/getAllProperties.js +10 -13
- package/utils/object/index.cjs +33 -0
- package/utils/object/index.js +8 -3
- package/utils/object/isObject.cjs +28 -0
- package/utils/object/isObject.d.ts +1 -1
- package/utils/object/isObject.js +6 -3
- package/utils/scrollTo.cjs +80 -0
- package/utils/scrollTo.d.ts +1 -1
- package/utils/scrollTo.js +20 -40
- package/utils/string/index.cjs +47 -0
- package/utils/string/index.js +22 -10
- package/utils/string/withLeadingCharacters.cjs +32 -0
- package/utils/string/withLeadingCharacters.d.ts +3 -2
- package/utils/string/withLeadingCharacters.js +7 -4
- package/utils/string/withLeadingSlash.cjs +32 -0
- package/utils/string/withLeadingSlash.d.ts +1 -1
- package/utils/string/withLeadingSlash.js +7 -4
- package/utils/string/withTrailingCharacters.cjs +32 -0
- package/utils/string/withTrailingCharacters.d.ts +3 -2
- package/utils/string/withTrailingCharacters.js +7 -4
- package/utils/string/withTrailingSlash.cjs +32 -0
- package/utils/string/withTrailingSlash.d.ts +1 -1
- package/utils/string/withTrailingSlash.js +7 -4
- package/utils/string/withoutLeadingCharacters.cjs +28 -0
- package/utils/string/withoutLeadingCharacters.d.ts +3 -2
- package/utils/string/withoutLeadingCharacters.js +6 -3
- package/utils/string/withoutLeadingCharactersRecursive.cjs +37 -0
- package/utils/string/withoutLeadingCharactersRecursive.d.ts +3 -2
- package/utils/string/withoutLeadingCharactersRecursive.js +8 -7
- package/utils/string/withoutLeadingSlash.cjs +32 -0
- package/utils/string/withoutLeadingSlash.d.ts +1 -1
- package/utils/string/withoutLeadingSlash.js +7 -4
- package/utils/string/withoutTrailingCharacters.cjs +28 -0
- package/utils/string/withoutTrailingCharacters.d.ts +3 -2
- package/utils/string/withoutTrailingCharacters.js +6 -3
- package/utils/string/withoutTrailingCharactersRecursive.cjs +37 -0
- package/utils/string/withoutTrailingCharactersRecursive.d.ts +3 -2
- package/utils/string/withoutTrailingCharactersRecursive.js +8 -7
- package/utils/string/withoutTrailingSlash.cjs +32 -0
- package/utils/string/withoutTrailingSlash.d.ts +1 -1
- package/utils/string/withoutTrailingSlash.js +7 -4
- package/utils/throttle.cjs +36 -0
- package/utils/throttle.d.ts +3 -3
- package/utils/throttle.js +9 -9
- package/index.modern.js +0 -1
- package/index.umd.js +0 -1
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
import { getComponentElements } from "../utils.js";
|
|
8
|
+
class ChildrenManager {
|
|
8
9
|
constructor(base, element, components, eventsManager) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
_defineProperty(this, "__eventsManager", void 0);
|
|
16
|
-
|
|
10
|
+
__publicField(this, "__base");
|
|
11
|
+
__publicField(this, "__element");
|
|
12
|
+
__publicField(this, "__components");
|
|
13
|
+
__publicField(this, "__eventsManager");
|
|
14
|
+
__publicField(this, "__asyncComponentPromises", /* @__PURE__ */ new WeakMap());
|
|
17
15
|
Object.defineProperties(this, {
|
|
18
16
|
__base: {
|
|
19
17
|
enumerable: false,
|
|
@@ -37,88 +35,91 @@ export default class ChildrenManager {
|
|
|
37
35
|
}
|
|
38
36
|
});
|
|
39
37
|
}
|
|
40
|
-
|
|
38
|
+
get registeredNames() {
|
|
39
|
+
return Object.keys(this).filter((key) => !key.startsWith("__"));
|
|
40
|
+
}
|
|
41
41
|
registerAll() {
|
|
42
|
-
Object.entries(this.__components).forEach(
|
|
43
|
-
var [name, component] = _ref;
|
|
44
|
-
return this.__register(name, component);
|
|
45
|
-
});
|
|
42
|
+
Object.entries(this.__components).forEach(([name, component]) => this.__register(name, component));
|
|
46
43
|
}
|
|
47
|
-
|
|
48
44
|
__register(name, component) {
|
|
49
45
|
Object.defineProperty(this, name, {
|
|
50
46
|
enumerable: true,
|
|
51
47
|
configurable: true,
|
|
52
48
|
get: () => {
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
const elements = getComponentElements(name, this.__element);
|
|
55
50
|
if (elements.length === 0) {
|
|
56
51
|
return [];
|
|
57
52
|
}
|
|
58
|
-
|
|
59
|
-
return elements.map(element => this.__getChild(element, component, name)).filter(instance => instance !== 'terminated');
|
|
53
|
+
return elements.map((element) => this.__getChild(element, component, name)).filter((instance) => instance !== "terminated");
|
|
60
54
|
}
|
|
61
55
|
});
|
|
62
56
|
}
|
|
63
|
-
|
|
64
57
|
__getChild(el, ComponentClass, name) {
|
|
65
|
-
|
|
66
|
-
|
|
58
|
+
const asyncComponentPromise = this.__asyncComponentPromises.get(ComponentClass);
|
|
59
|
+
if ("$isBase" in ComponentClass || asyncComponentPromise && asyncComponentPromise.status === "resolved") {
|
|
60
|
+
let ctor = ComponentClass;
|
|
61
|
+
if (asyncComponentPromise) {
|
|
62
|
+
ctor = asyncComponentPromise.ctor;
|
|
63
|
+
}
|
|
64
|
+
if (el.__base__ && el.__base__.has(ctor)) {
|
|
65
|
+
return el.__base__.get(ctor);
|
|
66
|
+
}
|
|
67
|
+
const child = new ctor(el);
|
|
68
|
+
Object.defineProperty(child, "$parent", { get: () => this.__base });
|
|
69
|
+
return child;
|
|
67
70
|
}
|
|
68
|
-
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
const promise = asyncComponentPromise ? asyncComponentPromise.promise : ComponentClass(this.__base);
|
|
72
|
+
if (!asyncComponentPromise) {
|
|
73
|
+
this.__asyncComponentPromises.set(ComponentClass, {
|
|
74
|
+
promise,
|
|
75
|
+
status: "pending",
|
|
76
|
+
ctor: void 0
|
|
73
77
|
});
|
|
74
|
-
return child;
|
|
75
78
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
return promise.then((module) => {
|
|
80
|
+
var _a;
|
|
81
|
+
const ctor = (_a = module.default) != null ? _a : module;
|
|
82
|
+
this.__asyncComponentPromises.set(ComponentClass, {
|
|
83
|
+
promise,
|
|
84
|
+
status: "resolved",
|
|
85
|
+
ctor
|
|
86
|
+
});
|
|
87
|
+
return this.__getChild(el, ctor, name);
|
|
81
88
|
});
|
|
82
89
|
}
|
|
83
|
-
|
|
84
90
|
mountAll() {
|
|
85
|
-
this.__triggerHookForAll(
|
|
91
|
+
this.__triggerHookForAll("$mount");
|
|
86
92
|
}
|
|
87
|
-
|
|
88
93
|
updateAll() {
|
|
89
|
-
this.__triggerHookForAll(
|
|
94
|
+
this.__triggerHookForAll("$update");
|
|
90
95
|
}
|
|
91
|
-
|
|
92
96
|
destroyAll() {
|
|
93
|
-
this.__triggerHookForAll(
|
|
97
|
+
this.__triggerHookForAll("$destroy");
|
|
94
98
|
}
|
|
95
|
-
|
|
96
99
|
__triggerHookForAll(hook) {
|
|
97
|
-
this.registeredNames.forEach(name => {
|
|
98
|
-
this[name].forEach(instance => {
|
|
100
|
+
this.registeredNames.forEach((name) => {
|
|
101
|
+
this[name].forEach((instance) => {
|
|
99
102
|
if (instance instanceof Promise) {
|
|
100
|
-
instance.then(resolvedInstance => this.__triggerHook(hook, resolvedInstance, name));
|
|
103
|
+
instance.then((resolvedInstance) => this.__triggerHook(hook, resolvedInstance, name));
|
|
101
104
|
} else {
|
|
102
105
|
this.__triggerHook(hook, instance, name);
|
|
103
106
|
}
|
|
104
107
|
});
|
|
105
108
|
});
|
|
106
109
|
}
|
|
107
|
-
|
|
108
110
|
__triggerHook(hook, instance, name) {
|
|
109
|
-
if (hook ===
|
|
110
|
-
hook =
|
|
111
|
+
if (hook === "$update" && !instance.$isMounted) {
|
|
112
|
+
hook = "$mount";
|
|
111
113
|
}
|
|
112
|
-
|
|
113
|
-
if (hook === '$update' || hook === '$destroy') {
|
|
114
|
+
if (hook === "$update" || hook === "$destroy") {
|
|
114
115
|
this.__eventsManager.unbindChild(name, instance);
|
|
115
116
|
}
|
|
116
|
-
|
|
117
|
-
if (hook === '$update' || hook === '$mount') {
|
|
117
|
+
if (hook === "$update" || hook === "$mount") {
|
|
118
118
|
this.__eventsManager.bindChild(name, instance);
|
|
119
119
|
}
|
|
120
|
-
|
|
121
120
|
instance[hook]();
|
|
122
121
|
}
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
}
|
|
123
|
+
export {
|
|
124
|
+
ChildrenManager as default
|
|
125
|
+
};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
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
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
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));
|
|
21
|
+
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
|
+
|
|
27
|
+
// packages/js-toolkit/Base/managers/EventsManager.js
|
|
28
|
+
var EventsManager_exports = {};
|
|
29
|
+
__export(EventsManager_exports, {
|
|
30
|
+
default: () => EventsManager
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(EventsManager_exports);
|
|
33
|
+
var import_getAllProperties = __toESM(require("../../utils/object/getAllProperties.cjs"), 1);
|
|
34
|
+
var import_RefsManager = __toESM(require("./RefsManager.cjs"), 1);
|
|
35
|
+
var EventsManager = class {
|
|
36
|
+
constructor(rootElement, base) {
|
|
37
|
+
__publicField(this, "__rootElement");
|
|
38
|
+
__publicField(this, "__base");
|
|
39
|
+
__publicField(this, "__methodsCache", /* @__PURE__ */ new Map());
|
|
40
|
+
__publicField(this, "__rootElementHandler", {
|
|
41
|
+
handleEvent: (event) => {
|
|
42
|
+
const normalizedEventName = EventsManager.normalizeName(event.type);
|
|
43
|
+
const method = `on${normalizedEventName}`;
|
|
44
|
+
this.__base[method](event);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
__publicField(this, "__refsHandler", {
|
|
48
|
+
handleEvent: (event) => {
|
|
49
|
+
const ref = event.currentTarget;
|
|
50
|
+
const refName = import_RefsManager.default.normalizeRefName(ref.dataset.ref);
|
|
51
|
+
const normalizedRefName = EventsManager.normalizeName(refName);
|
|
52
|
+
const normalizedEventName = EventsManager.normalizeName(event.type);
|
|
53
|
+
const method = `on${normalizedRefName}${normalizedEventName}`;
|
|
54
|
+
let index = 0;
|
|
55
|
+
if (Array.isArray(this.__base.$refs[refName])) {
|
|
56
|
+
index = this.__base.$refs[refName].indexOf(ref);
|
|
57
|
+
}
|
|
58
|
+
this.__base[method](event, index);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
__publicField(this, "__childrenHandler", {
|
|
62
|
+
handleEvent: (event) => {
|
|
63
|
+
const child = event.currentTarget;
|
|
64
|
+
let childName;
|
|
65
|
+
let index = 0;
|
|
66
|
+
const childrenManager = this.__base.$children;
|
|
67
|
+
childrenManager.registeredNames.find((name) => {
|
|
68
|
+
if (childrenManager[name].includes(child)) {
|
|
69
|
+
childName = name;
|
|
70
|
+
index = childrenManager[name].indexOf(child);
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
});
|
|
75
|
+
const normalizedRefName = EventsManager.normalizeName(childName);
|
|
76
|
+
const normalizedEventName = EventsManager.normalizeName(event.type);
|
|
77
|
+
const method = `on${normalizedRefName}${normalizedEventName}`;
|
|
78
|
+
const args = Array.isArray(event.detail) ? event.detail : [];
|
|
79
|
+
this.__base[method](...args, index, event);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
Object.defineProperties(this, {
|
|
83
|
+
__rootElement: {
|
|
84
|
+
enumerable: false,
|
|
85
|
+
writable: false,
|
|
86
|
+
value: rootElement
|
|
87
|
+
},
|
|
88
|
+
__base: {
|
|
89
|
+
enumerable: false,
|
|
90
|
+
writable: false,
|
|
91
|
+
value: base
|
|
92
|
+
},
|
|
93
|
+
__methodsCache: {
|
|
94
|
+
enumerable: false,
|
|
95
|
+
writable: false,
|
|
96
|
+
value: this.__methodsCache
|
|
97
|
+
},
|
|
98
|
+
__rootElementHandler: {
|
|
99
|
+
enumerable: false,
|
|
100
|
+
writable: false,
|
|
101
|
+
value: this.__rootElementHandler
|
|
102
|
+
},
|
|
103
|
+
__refsHandler: {
|
|
104
|
+
enumerable: false,
|
|
105
|
+
writable: false,
|
|
106
|
+
value: this.__refsHandler
|
|
107
|
+
},
|
|
108
|
+
__childrenHandler: {
|
|
109
|
+
enumerable: false,
|
|
110
|
+
writable: false,
|
|
111
|
+
value: this.__childrenHandler
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
__manageRef(name, elements, mode = "add") {
|
|
116
|
+
const action = `${mode}EventListener`;
|
|
117
|
+
const methods = this.__getEventMethodsByName(name);
|
|
118
|
+
methods.forEach((method) => {
|
|
119
|
+
const event = this.__getEventNameByMethod(method, name);
|
|
120
|
+
elements.forEach((element) => element[action](event, this.__refsHandler));
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
bindRef(name, elements) {
|
|
124
|
+
this.__manageRef(name, elements);
|
|
125
|
+
}
|
|
126
|
+
unbindRef(name, elements) {
|
|
127
|
+
this.__manageRef(name, elements, "remove");
|
|
128
|
+
}
|
|
129
|
+
__manageChild(name, instance, mode = "add") {
|
|
130
|
+
const action = mode === "add" ? "$on" : "$off";
|
|
131
|
+
const methods = this.__getEventMethodsByName(name);
|
|
132
|
+
methods.forEach((method) => {
|
|
133
|
+
const event = this.__getEventNameByMethod(method, name);
|
|
134
|
+
instance[action](event, this.__childrenHandler);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
bindChild(name, instance) {
|
|
138
|
+
this.__manageChild(name, instance);
|
|
139
|
+
}
|
|
140
|
+
unbindChild(name, instance) {
|
|
141
|
+
this.__manageChild(name, instance, "remove");
|
|
142
|
+
}
|
|
143
|
+
__manageRootElement(mode = "add") {
|
|
144
|
+
const modeMethod = `${mode}EventListener`;
|
|
145
|
+
const methods = this.__getEventMethodsByName();
|
|
146
|
+
const { emits = [] } = this.__base.__config;
|
|
147
|
+
methods.forEach((method) => {
|
|
148
|
+
const event = this.__getEventNameByMethod(method);
|
|
149
|
+
const target = emits.includes(event) ? this.__base : this.__rootElement;
|
|
150
|
+
target[modeMethod](event, this.__rootElementHandler);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
bindRootElement() {
|
|
154
|
+
this.__manageRootElement();
|
|
155
|
+
}
|
|
156
|
+
unbindRootElement() {
|
|
157
|
+
this.__manageRootElement("remove");
|
|
158
|
+
}
|
|
159
|
+
__getEventNameByMethod(method, name = "") {
|
|
160
|
+
const normalizedName = EventsManager.normalizeName(name);
|
|
161
|
+
const regex = new RegExp(`^on${normalizedName}([A-Z].*)$`);
|
|
162
|
+
const [, event] = method.match(regex);
|
|
163
|
+
return EventsManager.normalizeEventName(event);
|
|
164
|
+
}
|
|
165
|
+
__getEventMethodsByName(name = "") {
|
|
166
|
+
const normalizedName = EventsManager.normalizeName(name);
|
|
167
|
+
const regex = new RegExp(`^on${normalizedName}[A-Z].*$`);
|
|
168
|
+
const key = regex.toString();
|
|
169
|
+
let methods = this.__methodsCache.get(key);
|
|
170
|
+
if (!methods) {
|
|
171
|
+
methods = Array.from((0, import_getAllProperties.default)(this.__base, [], (method) => regex.test(method)).reduce((set, [method]) => set.add(method), /* @__PURE__ */ new Set()));
|
|
172
|
+
this.__methodsCache.set(key, methods);
|
|
173
|
+
}
|
|
174
|
+
return methods;
|
|
175
|
+
}
|
|
176
|
+
static normalizeName(name) {
|
|
177
|
+
return name.replace(/[A-Z]([A-Z].*)/g, (c) => c.toLowerCase()).replace(/[^a-zA-Z\d\s:]/g, " ").replace(/(^\w|\s+\w)/g, (c) => c.trim().toUpperCase()).trim();
|
|
178
|
+
}
|
|
179
|
+
static normalizeEventName(name) {
|
|
180
|
+
return name.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`).replace(/^-/, "");
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
if (module.exports.default) module.exports = module.exports.default;
|
|
@@ -26,14 +26,14 @@ export default class EventsManager {
|
|
|
26
26
|
* ```
|
|
27
27
|
*
|
|
28
28
|
* @param {string} name
|
|
29
|
-
* @
|
|
29
|
+
* @returns {string}
|
|
30
30
|
*/
|
|
31
31
|
static normalizeName(name: string): string;
|
|
32
32
|
/**
|
|
33
33
|
* Normalize the event names from PascalCase to kebab-case.
|
|
34
34
|
*
|
|
35
35
|
* @param {string} name
|
|
36
|
-
* @
|
|
36
|
+
* @returns {string}
|
|
37
37
|
*/
|
|
38
38
|
static normalizeEventName(name: string): string;
|
|
39
39
|
/**
|
|
@@ -85,8 +85,7 @@ export default class EventsManager {
|
|
|
85
85
|
* The elements of the ref.
|
|
86
86
|
* @param {'add'|'remove'} [mode]
|
|
87
87
|
* The action to perform: add or remove the event listeners.
|
|
88
|
-
*
|
|
89
|
-
* @return {void}
|
|
88
|
+
* @returns {void}
|
|
90
89
|
* @private
|
|
91
90
|
*/
|
|
92
91
|
private __manageRef;
|
|
@@ -97,8 +96,7 @@ export default class EventsManager {
|
|
|
97
96
|
* The name of the ref.
|
|
98
97
|
* @param {HTMLElement[]} elements
|
|
99
98
|
* The elements of the ref.
|
|
100
|
-
*
|
|
101
|
-
* @return {void}
|
|
99
|
+
* @returns {void}
|
|
102
100
|
*/
|
|
103
101
|
bindRef(name: string, elements: HTMLElement[]): void;
|
|
104
102
|
/**
|
|
@@ -108,8 +106,7 @@ export default class EventsManager {
|
|
|
108
106
|
* The name of the ref.
|
|
109
107
|
* @param {HTMLElement[]} elements
|
|
110
108
|
* The elements of the ref.
|
|
111
|
-
*
|
|
112
|
-
* @return {void}
|
|
109
|
+
* @returns {void}
|
|
113
110
|
*/
|
|
114
111
|
unbindRef(name: string, elements: HTMLElement[]): void;
|
|
115
112
|
/**
|
|
@@ -121,8 +118,7 @@ export default class EventsManager {
|
|
|
121
118
|
* A base instance.
|
|
122
119
|
* @param {'add'|'remove'} [mode]
|
|
123
120
|
* The action to perform: add or remove the event listeners.
|
|
124
|
-
*
|
|
125
|
-
* @return {void}
|
|
121
|
+
* @returns {void}
|
|
126
122
|
* @private
|
|
127
123
|
*/
|
|
128
124
|
private __manageChild;
|
|
@@ -133,8 +129,7 @@ export default class EventsManager {
|
|
|
133
129
|
* The name of the ref.
|
|
134
130
|
* @param {Base} instance
|
|
135
131
|
* A base instance.
|
|
136
|
-
*
|
|
137
|
-
* @return {void}
|
|
132
|
+
* @returns {void}
|
|
138
133
|
*/
|
|
139
134
|
bindChild(name: string, instance: Base): void;
|
|
140
135
|
/**
|
|
@@ -144,8 +139,7 @@ export default class EventsManager {
|
|
|
144
139
|
* The name of the ref.
|
|
145
140
|
* @param {Base} instance
|
|
146
141
|
* A base instance.
|
|
147
|
-
*
|
|
148
|
-
* @return {void}
|
|
142
|
+
* @returns {void}
|
|
149
143
|
*/
|
|
150
144
|
unbindChild(name: string, instance: Base): void;
|
|
151
145
|
/**
|
|
@@ -153,21 +147,20 @@ export default class EventsManager {
|
|
|
153
147
|
*
|
|
154
148
|
* @param {'add'|'remove'} [mode]
|
|
155
149
|
* The action to perform: add or remove the event listeners, defaults to 'add'.
|
|
156
|
-
*
|
|
157
|
-
* @return {void}
|
|
150
|
+
* @returns {void}
|
|
158
151
|
* @private
|
|
159
152
|
*/
|
|
160
153
|
private __manageRootElement;
|
|
161
154
|
/**
|
|
162
155
|
* Bind event methods on the root element.
|
|
163
156
|
*
|
|
164
|
-
* @
|
|
157
|
+
* @returns {void}
|
|
165
158
|
*/
|
|
166
159
|
bindRootElement(): void;
|
|
167
160
|
/**
|
|
168
161
|
* Unbind event method from the root element.
|
|
169
162
|
*
|
|
170
|
-
* @
|
|
163
|
+
* @returns {void}
|
|
171
164
|
*/
|
|
172
165
|
unbindRootElement(): void;
|
|
173
166
|
/**
|
|
@@ -175,7 +168,7 @@ export default class EventsManager {
|
|
|
175
168
|
*
|
|
176
169
|
* @param {string} method
|
|
177
170
|
* @param {string} name
|
|
178
|
-
* @
|
|
171
|
+
* @returns {string}
|
|
179
172
|
* @private
|
|
180
173
|
*/
|
|
181
174
|
private __getEventNameByMethod;
|
|
@@ -183,7 +176,7 @@ export default class EventsManager {
|
|
|
183
176
|
* Get the base instance methods matching the `onSomething` pattern.
|
|
184
177
|
*
|
|
185
178
|
* @param {string} [name]
|
|
186
|
-
* @
|
|
179
|
+
* @returns {string[]}
|
|
187
180
|
* @private
|
|
188
181
|
*/
|
|
189
182
|
private __getEventMethodsByName;
|