@studiometa/js-toolkit 2.0.1 → 2.2.0-alpha.1
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 +55 -18
- package/Base/index.d.ts +23 -1
- package/Base/index.js +55 -18
- package/Base/managers/AbstractManager.cjs +56 -0
- package/Base/managers/AbstractManager.d.ts +44 -0
- package/Base/managers/AbstractManager.js +35 -0
- package/Base/managers/ChildrenManager.cjs +79 -100
- package/Base/managers/ChildrenManager.d.ts +7 -82
- package/Base/managers/ChildrenManager.js +76 -100
- package/Base/managers/EventsManager.cjs +75 -99
- package/Base/managers/EventsManager.d.ts +31 -100
- package/Base/managers/EventsManager.js +75 -99
- package/Base/managers/OptionsManager.cjs +65 -78
- package/Base/managers/OptionsManager.d.ts +37 -79
- package/Base/managers/OptionsManager.js +66 -79
- package/Base/managers/RefsManager.cjs +44 -68
- package/Base/managers/RefsManager.d.ts +10 -64
- package/Base/managers/RefsManager.js +41 -69
- package/Base/managers/ResponsiveOptionsManager.cjs +62 -0
- package/Base/managers/ResponsiveOptionsManager.d.ts +26 -0
- package/Base/managers/ResponsiveOptionsManager.js +37 -0
- package/Base/managers/ServicesManager.cjs +5 -11
- package/Base/managers/ServicesManager.d.ts +2 -11
- package/Base/managers/ServicesManager.js +5 -11
- package/decorators/index.cjs +2 -0
- package/decorators/index.d.ts +1 -0
- package/decorators/index.js +6 -4
- package/decorators/withResponsiveOptions.cjs +39 -0
- package/decorators/withResponsiveOptions.d.ts +8 -0
- package/decorators/withResponsiveOptions.js +14 -0
- package/decorators/withScrolledInView.cjs +66 -23
- package/decorators/withScrolledInView.d.ts +4 -2
- package/decorators/withScrolledInView.js +67 -24
- package/package.json +2 -1
- package/services/Service.cjs +2 -2
- package/services/Service.d.ts +9 -1
- package/services/Service.js +2 -2
- package/services/raf.cjs +16 -0
- package/services/raf.js +16 -0
- package/utils/css/animate.cjs +207 -0
- package/utils/css/animate.d.ts +57 -0
- package/utils/css/animate.js +182 -0
- package/utils/css/getOffsetSizes.cjs +47 -0
- package/utils/css/getOffsetSizes.d.ts +15 -0
- package/utils/css/getOffsetSizes.js +25 -0
- package/utils/css/index.cjs +6 -0
- package/utils/css/index.d.ts +3 -0
- package/utils/css/index.js +9 -4
- package/utils/css/transform.cjs +91 -0
- package/utils/css/transform.d.ts +43 -0
- package/utils/css/transform.js +66 -0
- package/utils/index.cjs +5 -0
- package/utils/index.d.ts +3 -0
- package/utils/index.js +5 -0
- package/utils/isDefined.cjs +28 -0
- package/utils/isDefined.d.ts +7 -0
- package/utils/isDefined.js +6 -0
- package/utils/isFunction.cjs +28 -0
- package/utils/isFunction.d.ts +7 -0
- package/utils/isFunction.js +6 -0
- package/utils/math/index.cjs +2 -0
- package/utils/math/index.d.ts +1 -0
- package/utils/math/index.js +2 -0
- package/utils/scheduler.cjs +73 -0
- package/utils/scheduler.d.ts +19 -0
- package/utils/scheduler.js +51 -0
|
@@ -1,53 +1,18 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {import('../index.js').default} Base
|
|
3
|
-
* @typedef {import('../index.js').BaseConstructor} BaseConstructor
|
|
4
|
-
* @typedef {import('../index.js').BaseAsyncConstructor} BaseAsyncConstructor
|
|
5
|
-
* @typedef {import('../index.js').BaseConfigComponents} BaseConfigComponents
|
|
6
|
-
* @typedef {import('./EventsManager.js').default} EventsManager
|
|
7
|
-
*/
|
|
8
1
|
/**
|
|
9
2
|
* Children manager.
|
|
10
3
|
*/
|
|
11
|
-
export default class ChildrenManager {
|
|
12
|
-
/**
|
|
13
|
-
* Class constructor.
|
|
14
|
-
* @param {Base} base
|
|
15
|
-
* The component's instance.
|
|
16
|
-
* @param {HTMLElement} element
|
|
17
|
-
* The component's root element
|
|
18
|
-
* @param {BaseConfigComponents} components
|
|
19
|
-
* The children components' classes
|
|
20
|
-
* @param {EventsManager} eventsManager
|
|
21
|
-
*/
|
|
22
|
-
constructor(base: Base, element: HTMLElement, components: BaseConfigComponents, eventsManager: EventsManager);
|
|
23
|
-
/**
|
|
24
|
-
* @type {Base}
|
|
25
|
-
* @private
|
|
26
|
-
*/
|
|
27
|
-
private __base;
|
|
28
|
-
/**
|
|
29
|
-
* @type {HTMLElement}
|
|
30
|
-
* @private
|
|
31
|
-
*/
|
|
32
|
-
private __element;
|
|
33
|
-
/**
|
|
34
|
-
* @type {BaseConfigComponents}
|
|
35
|
-
* @private
|
|
36
|
-
*/
|
|
37
|
-
private __components;
|
|
38
|
-
/**
|
|
39
|
-
* @type {EventsManager}
|
|
40
|
-
* @private
|
|
41
|
-
*/
|
|
42
|
-
private __eventsManager;
|
|
4
|
+
export default class ChildrenManager extends AbstractManager {
|
|
43
5
|
/**
|
|
44
6
|
* Store async component promises to avoid calling them multiple times and
|
|
45
7
|
* waiting for them when they are already resolved.
|
|
46
8
|
*
|
|
47
|
-
* @private
|
|
48
9
|
* @type {WeakMap<BaseAsyncConstructor, { promise: ReturnType<BaseAsyncConstructor>, status: 'pending'|'resolved', ctor?: BaseConstructor }>}
|
|
49
10
|
*/
|
|
50
|
-
|
|
11
|
+
__asyncComponentPromises: WeakMap<BaseAsyncConstructor, {
|
|
12
|
+
promise: ReturnType<BaseAsyncConstructor>;
|
|
13
|
+
status: 'pending' | 'resolved';
|
|
14
|
+
ctor?: BaseConstructor;
|
|
15
|
+
}>;
|
|
51
16
|
/**
|
|
52
17
|
* @returns {string[]}
|
|
53
18
|
*/
|
|
@@ -56,30 +21,6 @@ export default class ChildrenManager {
|
|
|
56
21
|
* Register instances of all children components.
|
|
57
22
|
*/
|
|
58
23
|
registerAll(): void;
|
|
59
|
-
/**
|
|
60
|
-
* Register instance of a child component.
|
|
61
|
-
*
|
|
62
|
-
* @param {string} name
|
|
63
|
-
* The name of the child component.
|
|
64
|
-
* @param {BaseConstructor|BaseAsyncConstructor} component
|
|
65
|
-
* A Base class or a Promise for async components.
|
|
66
|
-
* @private
|
|
67
|
-
*/
|
|
68
|
-
private __register;
|
|
69
|
-
/**
|
|
70
|
-
* Get a child component's instance.
|
|
71
|
-
*
|
|
72
|
-
* @param {HTMLElement & { __base__?: WeakMap<BaseConstructor, Base> }} el
|
|
73
|
-
* The root element of the child component.
|
|
74
|
-
* @param {BaseConstructor|BaseAsyncConstructor} ComponentClass
|
|
75
|
-
* A Base class or a Promise for async components.
|
|
76
|
-
* @param {string} name
|
|
77
|
-
* The name of the child component.
|
|
78
|
-
* @returns {Base|Promise|'terminated'}
|
|
79
|
-
* A Base instance or a Promise resolving to a Base instance.
|
|
80
|
-
* @private
|
|
81
|
-
*/
|
|
82
|
-
private __getChild;
|
|
83
24
|
/**
|
|
84
25
|
* Mount all child component instances.
|
|
85
26
|
*/
|
|
@@ -92,25 +33,9 @@ export default class ChildrenManager {
|
|
|
92
33
|
* Destroy all child component instances.
|
|
93
34
|
*/
|
|
94
35
|
destroyAll(): void;
|
|
95
|
-
/**
|
|
96
|
-
* Execute the given hook for all children instances.
|
|
97
|
-
*
|
|
98
|
-
* @param {'$mount'|'$update'|'$destroy'} hook The hook to execute.
|
|
99
|
-
* @private
|
|
100
|
-
*/
|
|
101
|
-
private __triggerHookForAll;
|
|
102
|
-
/**
|
|
103
|
-
* Execute the given hook for the given instance.
|
|
104
|
-
*
|
|
105
|
-
* @param {'$mount'|'$update'|'$destroy'} hook The hook to trigger.
|
|
106
|
-
* @param {Base} instance The target instance.
|
|
107
|
-
* @param {string} name The name of the component.
|
|
108
|
-
* @private
|
|
109
|
-
*/
|
|
110
|
-
private __triggerHook;
|
|
111
36
|
}
|
|
112
37
|
export type Base = import('../index.js').default;
|
|
113
38
|
export type BaseConstructor = import('../index.js').BaseConstructor;
|
|
114
39
|
export type BaseAsyncConstructor = import('../index.js').BaseAsyncConstructor;
|
|
115
40
|
export type BaseConfigComponents = import('../index.js').BaseConfigComponents;
|
|
116
|
-
|
|
41
|
+
import AbstractManager from "./AbstractManager.js";
|
|
@@ -4,120 +4,96 @@ var __publicField = (obj, key, value) => {
|
|
|
4
4
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
5
|
return value;
|
|
6
6
|
};
|
|
7
|
+
import AbstractManager from "./AbstractManager.js";
|
|
7
8
|
import { getComponentElements } from "../utils.js";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
writable: false,
|
|
29
|
-
value: components
|
|
30
|
-
},
|
|
31
|
-
__eventsManager: {
|
|
32
|
-
enumerable: false,
|
|
33
|
-
writable: false,
|
|
34
|
-
value: eventsManager
|
|
35
|
-
}
|
|
9
|
+
function __getChild(that, el, ComponentClass, name) {
|
|
10
|
+
const asyncComponentPromise = that.__asyncComponentPromises.get(ComponentClass);
|
|
11
|
+
if ("$isBase" in ComponentClass || asyncComponentPromise && asyncComponentPromise.status === "resolved") {
|
|
12
|
+
let ctor = ComponentClass;
|
|
13
|
+
if (asyncComponentPromise) {
|
|
14
|
+
ctor = asyncComponentPromise.ctor;
|
|
15
|
+
}
|
|
16
|
+
if (el.__base__ && el.__base__.has(ctor)) {
|
|
17
|
+
return el.__base__.get(ctor);
|
|
18
|
+
}
|
|
19
|
+
const child = new ctor(el);
|
|
20
|
+
Object.defineProperty(child, "$parent", { get: () => that.__base });
|
|
21
|
+
return child;
|
|
22
|
+
}
|
|
23
|
+
const promise = asyncComponentPromise ? asyncComponentPromise.promise : ComponentClass(that.__base);
|
|
24
|
+
if (!asyncComponentPromise) {
|
|
25
|
+
that.__asyncComponentPromises.set(ComponentClass, {
|
|
26
|
+
promise,
|
|
27
|
+
status: "pending",
|
|
28
|
+
ctor: void 0
|
|
36
29
|
});
|
|
37
30
|
}
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
return promise.then((module) => {
|
|
32
|
+
var _a;
|
|
33
|
+
const ctor = (_a = module.default) != null ? _a : module;
|
|
34
|
+
that.__asyncComponentPromises.set(ComponentClass, {
|
|
35
|
+
promise,
|
|
36
|
+
status: "resolved",
|
|
37
|
+
ctor
|
|
38
|
+
});
|
|
39
|
+
return __getChild(that, el, ctor, name);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function __register(that, name, component) {
|
|
43
|
+
Object.defineProperty(that, name, {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
configurable: true,
|
|
46
|
+
get: () => {
|
|
47
|
+
const elements = getComponentElements(name, that.__element);
|
|
48
|
+
if (elements.length === 0) {
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
return elements.map((element) => __getChild(that, element, component, name)).filter((instance) => instance !== "terminated");
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function __triggerHook(that, hook, instance, name) {
|
|
56
|
+
if (hook === "$update" && !instance.$isMounted) {
|
|
57
|
+
hook = "$mount";
|
|
40
58
|
}
|
|
41
|
-
|
|
42
|
-
|
|
59
|
+
if (hook === "$update" || hook === "$destroy") {
|
|
60
|
+
that.__eventsManager.unbindChild(name, instance);
|
|
43
61
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
enumerable: true,
|
|
47
|
-
configurable: true,
|
|
48
|
-
get: () => {
|
|
49
|
-
const elements = getComponentElements(name, this.__element);
|
|
50
|
-
if (elements.length === 0) {
|
|
51
|
-
return [];
|
|
52
|
-
}
|
|
53
|
-
return elements.map((element) => this.__getChild(element, component, name)).filter((instance) => instance !== "terminated");
|
|
54
|
-
}
|
|
55
|
-
});
|
|
62
|
+
if (hook === "$update" || hook === "$mount") {
|
|
63
|
+
that.__eventsManager.bindChild(name, instance);
|
|
56
64
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
instance[hook]();
|
|
66
|
+
}
|
|
67
|
+
function __triggerHookForAll(that, hook) {
|
|
68
|
+
that.registeredNames.forEach((name) => {
|
|
69
|
+
that[name].forEach((instance) => {
|
|
70
|
+
if (instance instanceof Promise) {
|
|
71
|
+
instance.then((resolvedInstance) => __triggerHook(that, hook, resolvedInstance, name));
|
|
72
|
+
} else {
|
|
73
|
+
__triggerHook(that, hook, instance, name);
|
|
66
74
|
}
|
|
67
|
-
const child = new ctor(el);
|
|
68
|
-
Object.defineProperty(child, "$parent", { get: () => this.__base });
|
|
69
|
-
return child;
|
|
70
|
-
}
|
|
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
|
|
77
|
-
});
|
|
78
|
-
}
|
|
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);
|
|
88
75
|
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
class ChildrenManager extends AbstractManager {
|
|
79
|
+
constructor() {
|
|
80
|
+
super(...arguments);
|
|
81
|
+
__publicField(this, "__asyncComponentPromises", /* @__PURE__ */ new WeakMap());
|
|
82
|
+
}
|
|
83
|
+
get registeredNames() {
|
|
84
|
+
return Object.keys(this).filter((key) => !key.startsWith("__"));
|
|
85
|
+
}
|
|
86
|
+
registerAll() {
|
|
87
|
+
Object.entries(this.__config.components).forEach(([name, component]) => __register(this, name, component));
|
|
89
88
|
}
|
|
90
89
|
mountAll() {
|
|
91
|
-
|
|
90
|
+
__triggerHookForAll(this, "$mount");
|
|
92
91
|
}
|
|
93
92
|
updateAll() {
|
|
94
|
-
|
|
93
|
+
__triggerHookForAll(this, "$update");
|
|
95
94
|
}
|
|
96
95
|
destroyAll() {
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
__triggerHookForAll(hook) {
|
|
100
|
-
this.registeredNames.forEach((name) => {
|
|
101
|
-
this[name].forEach((instance) => {
|
|
102
|
-
if (instance instanceof Promise) {
|
|
103
|
-
instance.then((resolvedInstance) => this.__triggerHook(hook, resolvedInstance, name));
|
|
104
|
-
} else {
|
|
105
|
-
this.__triggerHook(hook, instance, name);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
__triggerHook(hook, instance, name) {
|
|
111
|
-
if (hook === "$update" && !instance.$isMounted) {
|
|
112
|
-
hook = "$mount";
|
|
113
|
-
}
|
|
114
|
-
if (hook === "$update" || hook === "$destroy") {
|
|
115
|
-
this.__eventsManager.unbindChild(name, instance);
|
|
116
|
-
}
|
|
117
|
-
if (hook === "$update" || hook === "$mount") {
|
|
118
|
-
this.__eventsManager.bindChild(name, instance);
|
|
119
|
-
}
|
|
120
|
-
instance[hook]();
|
|
96
|
+
__triggerHookForAll(this, "$destroy");
|
|
121
97
|
}
|
|
122
98
|
}
|
|
123
99
|
export {
|
|
@@ -27,19 +27,70 @@ var __publicField = (obj, key, value) => {
|
|
|
27
27
|
// packages/js-toolkit/Base/managers/EventsManager.js
|
|
28
28
|
var EventsManager_exports = {};
|
|
29
29
|
__export(EventsManager_exports, {
|
|
30
|
-
default: () => EventsManager
|
|
30
|
+
default: () => EventsManager,
|
|
31
|
+
normalizeEventName: () => normalizeEventName,
|
|
32
|
+
normalizeName: () => normalizeName
|
|
31
33
|
});
|
|
32
34
|
module.exports = __toCommonJS(EventsManager_exports);
|
|
33
35
|
var import_getAllProperties = __toESM(require("../../utils/object/getAllProperties.cjs"), 1);
|
|
34
|
-
var
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
var import_AbstractManager = __toESM(require("./AbstractManager.cjs"), 1);
|
|
37
|
+
var import_RefsManager = require("./RefsManager.cjs");
|
|
38
|
+
function normalizeName(name) {
|
|
39
|
+
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();
|
|
40
|
+
}
|
|
41
|
+
function normalizeEventName(name) {
|
|
42
|
+
return name.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`).replace(/^-/, "");
|
|
43
|
+
}
|
|
44
|
+
function __getEventNameByMethod(that, method, name = "") {
|
|
45
|
+
const normalizedName = normalizeName(name);
|
|
46
|
+
const regex = new RegExp(`^on${normalizedName}([A-Z].*)$`);
|
|
47
|
+
const [, event] = method.match(regex);
|
|
48
|
+
return normalizeEventName(event);
|
|
49
|
+
}
|
|
50
|
+
function __getEventMethodsByName(that, name = "") {
|
|
51
|
+
const normalizedName = normalizeName(name);
|
|
52
|
+
const regex = new RegExp(`^on${normalizedName}[A-Z].*$`);
|
|
53
|
+
const key = regex.toString();
|
|
54
|
+
let methods = that.__methodsCache.get(key);
|
|
55
|
+
if (!methods) {
|
|
56
|
+
methods = Array.from((0, import_getAllProperties.default)(that.__base, [], (method) => regex.test(method)).reduce((set, [method]) => set.add(method), /* @__PURE__ */ new Set()));
|
|
57
|
+
that.__methodsCache.set(key, methods);
|
|
58
|
+
}
|
|
59
|
+
return methods;
|
|
60
|
+
}
|
|
61
|
+
function __manageRef(that, name, elements, mode = "add") {
|
|
62
|
+
const action = `${mode}EventListener`;
|
|
63
|
+
const methods = __getEventMethodsByName(that, name);
|
|
64
|
+
methods.forEach((method) => {
|
|
65
|
+
const event = __getEventNameByMethod(that, method, name);
|
|
66
|
+
elements.forEach((element) => element[action](event, that.__refsHandler));
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function __manageChild(that, name, instance, mode = "add") {
|
|
70
|
+
const action = mode === "add" ? "$on" : "$off";
|
|
71
|
+
const methods = __getEventMethodsByName(that, name);
|
|
72
|
+
methods.forEach((method) => {
|
|
73
|
+
const event = __getEventNameByMethod(that, method, name);
|
|
74
|
+
instance[action](event, that.__childrenHandler);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function __manageRootElement(that, mode = "add") {
|
|
78
|
+
const modeMethod = `${mode}EventListener`;
|
|
79
|
+
const methods = __getEventMethodsByName(that);
|
|
80
|
+
const { emits = [] } = that.__base.__config;
|
|
81
|
+
methods.forEach((method) => {
|
|
82
|
+
const event = __getEventNameByMethod(that, method);
|
|
83
|
+
const target = emits.includes(event) ? that.__base : that.__element;
|
|
84
|
+
target[modeMethod](event, that.__rootElementHandler);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
var EventsManager = class extends import_AbstractManager.default {
|
|
88
|
+
constructor(base) {
|
|
89
|
+
super(base);
|
|
39
90
|
__publicField(this, "__methodsCache", /* @__PURE__ */ new Map());
|
|
40
91
|
__publicField(this, "__rootElementHandler", {
|
|
41
92
|
handleEvent: (event) => {
|
|
42
|
-
const normalizedEventName =
|
|
93
|
+
const normalizedEventName = normalizeName(event.type);
|
|
43
94
|
const method = `on${normalizedEventName}`;
|
|
44
95
|
this.__base[method](event);
|
|
45
96
|
}
|
|
@@ -47,9 +98,9 @@ var EventsManager = class {
|
|
|
47
98
|
__publicField(this, "__refsHandler", {
|
|
48
99
|
handleEvent: (event) => {
|
|
49
100
|
const ref = event.currentTarget;
|
|
50
|
-
const refName = import_RefsManager.
|
|
51
|
-
const normalizedRefName =
|
|
52
|
-
const normalizedEventName =
|
|
101
|
+
const refName = (0, import_RefsManager.normalizeRefName)(ref.dataset.ref);
|
|
102
|
+
const normalizedRefName = normalizeName(refName);
|
|
103
|
+
const normalizedEventName = normalizeName(event.type);
|
|
53
104
|
const method = `on${normalizedRefName}${normalizedEventName}`;
|
|
54
105
|
let index = 0;
|
|
55
106
|
if (Array.isArray(this.__base.$refs[refName])) {
|
|
@@ -72,112 +123,37 @@ var EventsManager = class {
|
|
|
72
123
|
}
|
|
73
124
|
return false;
|
|
74
125
|
});
|
|
75
|
-
const normalizedRefName =
|
|
76
|
-
const normalizedEventName =
|
|
126
|
+
const normalizedRefName = normalizeName(childName);
|
|
127
|
+
const normalizedEventName = normalizeName(event.type);
|
|
77
128
|
const method = `on${normalizedRefName}${normalizedEventName}`;
|
|
78
129
|
const args = Array.isArray(event.detail) ? event.detail : [];
|
|
79
130
|
this.__base[method](...args, index, event);
|
|
80
131
|
}
|
|
81
132
|
});
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
});
|
|
133
|
+
this.__hideProperties([
|
|
134
|
+
"__methodsCache",
|
|
135
|
+
"__rootElementHandler",
|
|
136
|
+
"__refsHandler",
|
|
137
|
+
"__childrenHandler"
|
|
138
|
+
]);
|
|
122
139
|
}
|
|
123
140
|
bindRef(name, elements) {
|
|
124
|
-
|
|
141
|
+
__manageRef(this, name, elements);
|
|
125
142
|
}
|
|
126
143
|
unbindRef(name, elements) {
|
|
127
|
-
|
|
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
|
-
});
|
|
144
|
+
__manageRef(this, name, elements, "remove");
|
|
136
145
|
}
|
|
137
146
|
bindChild(name, instance) {
|
|
138
|
-
|
|
147
|
+
__manageChild(this, name, instance);
|
|
139
148
|
}
|
|
140
149
|
unbindChild(name, instance) {
|
|
141
|
-
|
|
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
|
-
});
|
|
150
|
+
__manageChild(this, name, instance, "remove");
|
|
152
151
|
}
|
|
153
152
|
bindRootElement() {
|
|
154
|
-
|
|
153
|
+
__manageRootElement(this);
|
|
155
154
|
}
|
|
156
155
|
unbindRootElement() {
|
|
157
|
-
|
|
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(/^-/, "");
|
|
156
|
+
__manageRootElement(this, "remove");
|
|
181
157
|
}
|
|
182
158
|
};
|
|
183
159
|
if (module.exports.default) module.exports = module.exports.default;
|