@studiometa/js-toolkit 2.0.0-rc.2 → 2.1.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 +54 -18
- package/Base/index.d.ts +47 -26
- package/Base/index.js +54 -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 +8 -83
- package/Base/managers/ChildrenManager.js +76 -100
- package/Base/managers/EventsManager.cjs +75 -99
- package/Base/managers/EventsManager.d.ts +37 -113
- package/Base/managers/EventsManager.js +75 -99
- package/Base/managers/OptionsManager.cjs +65 -79
- package/Base/managers/OptionsManager.d.ts +41 -80
- package/Base/managers/OptionsManager.js +66 -80
- package/Base/managers/RefsManager.cjs +44 -68
- package/Base/managers/RefsManager.d.ts +12 -66
- 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 +7 -10
- package/Base/managers/ServicesManager.d.ts +16 -19
- package/Base/managers/ServicesManager.js +7 -10
- package/Base/utils.d.ts +4 -4
- package/decorators/index.cjs +2 -0
- package/decorators/index.d.ts +1 -0
- package/decorators/index.js +6 -4
- package/decorators/withBreakpointManager.cjs +0 -1
- package/decorators/withBreakpointManager.d.ts +2 -2
- package/decorators/withBreakpointManager.js +0 -1
- package/decorators/withBreakpointObserver.cjs +1 -2
- package/decorators/withBreakpointObserver.d.ts +1 -1
- package/decorators/withBreakpointObserver.js +1 -2
- package/decorators/withDrag.d.ts +1 -1
- package/decorators/withExtraConfig.d.ts +1 -1
- package/decorators/withFreezedOptions.cjs +12 -3
- package/decorators/withFreezedOptions.d.ts +1 -1
- package/decorators/withFreezedOptions.js +13 -3
- package/decorators/withIntersectionObserver.cjs +0 -1
- package/decorators/withIntersectionObserver.d.ts +1 -1
- package/decorators/withIntersectionObserver.js +0 -1
- package/decorators/withMountWhenInView.cjs +0 -1
- package/decorators/withMountWhenInView.d.ts +1 -1
- package/decorators/withMountWhenInView.js +0 -1
- package/decorators/withResponsiveOptions.cjs +39 -0
- package/decorators/withResponsiveOptions.d.ts +8 -0
- package/decorators/withResponsiveOptions.js +14 -0
- package/decorators/withScrolledInView.cjs +58 -23
- package/decorators/withScrolledInView.d.ts +5 -3
- package/decorators/withScrolledInView.js +59 -24
- package/helpers/createApp.d.ts +3 -26
- package/helpers/getInstanceFromElement.cjs +32 -0
- package/helpers/getInstanceFromElement.d.ts +14 -0
- package/helpers/getInstanceFromElement.js +10 -0
- package/helpers/importOnInteraction.d.ts +3 -5
- package/helpers/importWhenIdle.d.ts +3 -5
- package/helpers/importWhenVisible.d.ts +4 -6
- package/helpers/index.cjs +2 -0
- package/helpers/index.d.ts +1 -0
- package/helpers/index.js +8 -6
- package/helpers/utils.d.ts +3 -4
- package/package.json +2 -1
- package/services/Service.d.ts +9 -9
- package/services/drag.cjs +0 -1
- package/services/drag.d.ts +3 -3
- package/services/drag.js +0 -1
- package/services/key.d.ts +1 -1
- package/services/load.d.ts +1 -1
- package/services/pointer.d.ts +1 -1
- package/services/raf.d.ts +1 -1
- package/services/resize.cjs +2 -2
- package/services/resize.d.ts +1 -1
- package/services/resize.js +2 -2
- package/services/scroll.cjs +3 -1
- package/services/scroll.d.ts +1 -1
- package/services/scroll.js +3 -1
- package/utils/collide/boundingRectToCircle.d.ts +5 -5
- package/utils/collide/collideCircleCircle.d.ts +4 -4
- package/utils/collide/collideCircleRect.d.ts +8 -8
- package/utils/collide/collidePointCircle.d.ts +6 -6
- package/utils/collide/collidePointRect.d.ts +7 -7
- package/utils/collide/collideRectRect.d.ts +5 -5
- package/utils/css/animate.cjs +190 -0
- package/utils/css/animate.d.ts +57 -0
- package/utils/css/animate.js +165 -0
- package/utils/css/classes.cjs +3 -3
- package/utils/css/classes.d.ts +10 -10
- package/utils/css/classes.js +3 -3
- 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/matrix.d.ts +14 -15
- package/utils/css/styles.d.ts +2 -2
- package/utils/css/transform.cjs +91 -0
- package/utils/css/transform.d.ts +43 -0
- package/utils/css/transform.js +66 -0
- package/utils/css/transition.cjs +2 -0
- package/utils/css/transition.d.ts +2 -2
- package/utils/css/transition.js +2 -0
- package/utils/debounce.d.ts +4 -4
- package/utils/focusTrap.cjs +1 -1
- package/utils/focusTrap.d.ts +1 -0
- package/utils/focusTrap.js +1 -1
- package/utils/history.d.ts +13 -11
- package/utils/index.cjs +4 -0
- package/utils/index.d.ts +2 -0
- package/utils/index.js +4 -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/clamp.d.ts +1 -1
- package/utils/math/clamp01.d.ts +1 -1
- package/utils/math/damp.d.ts +6 -6
- package/utils/math/ease.d.ts +7 -7
- package/utils/math/index.cjs +2 -0
- package/utils/math/index.d.ts +1 -0
- package/utils/math/index.js +2 -0
- package/utils/math/inertiaFinalValue.d.ts +5 -5
- package/utils/math/lerp.d.ts +4 -4
- package/utils/math/map.d.ts +6 -6
- package/utils/math/round.d.ts +4 -4
- package/utils/memoize.d.ts +1 -1
- package/utils/nextFrame.d.ts +3 -4
- package/utils/nextMicrotask.d.ts +1 -1
- package/utils/nextTick.d.ts +1 -1
- package/utils/object/autoBind.d.ts +3 -3
- package/utils/object/getAllProperties.d.ts +3 -3
- package/utils/object/isObject.d.ts +1 -1
- package/utils/scrollTo.cjs +1 -1
- package/utils/scrollTo.d.ts +1 -1
- package/utils/scrollTo.js +1 -1
- package/utils/string/withLeadingCharacters.d.ts +3 -2
- package/utils/string/withLeadingSlash.d.ts +1 -1
- package/utils/string/withTrailingCharacters.d.ts +3 -2
- package/utils/string/withTrailingSlash.d.ts +1 -1
- package/utils/string/withoutLeadingCharacters.d.ts +3 -2
- package/utils/string/withoutLeadingCharactersRecursive.d.ts +3 -2
- package/utils/string/withoutLeadingSlash.d.ts +1 -1
- package/utils/string/withoutTrailingCharacters.d.ts +3 -2
- package/utils/string/withoutTrailingCharactersRecursive.d.ts +3 -2
- package/utils/string/withoutTrailingSlash.d.ts +1 -1
- package/utils/throttle.cjs +1 -1
- package/utils/throttle.d.ts +3 -3
- package/utils/throttle.js +1 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
8
|
var __export = (target, all) => {
|
|
@@ -15,6 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
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));
|
|
18
21
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
22
|
var __publicField = (obj, key, value) => {
|
|
20
23
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
@@ -27,120 +30,96 @@ __export(ChildrenManager_exports, {
|
|
|
27
30
|
default: () => ChildrenManager
|
|
28
31
|
});
|
|
29
32
|
module.exports = __toCommonJS(ChildrenManager_exports);
|
|
33
|
+
var import_AbstractManager = __toESM(require("./AbstractManager.cjs"), 1);
|
|
30
34
|
var import_utils = require("../utils.cjs");
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
writable: false,
|
|
52
|
-
value: components
|
|
53
|
-
},
|
|
54
|
-
__eventsManager: {
|
|
55
|
-
enumerable: false,
|
|
56
|
-
writable: false,
|
|
57
|
-
value: eventsManager
|
|
58
|
-
}
|
|
35
|
+
function __getChild(that, el, ComponentClass, name) {
|
|
36
|
+
const asyncComponentPromise = that.__asyncComponentPromises.get(ComponentClass);
|
|
37
|
+
if ("$isBase" in ComponentClass || asyncComponentPromise && asyncComponentPromise.status === "resolved") {
|
|
38
|
+
let ctor = ComponentClass;
|
|
39
|
+
if (asyncComponentPromise) {
|
|
40
|
+
ctor = asyncComponentPromise.ctor;
|
|
41
|
+
}
|
|
42
|
+
if (el.__base__ && el.__base__.has(ctor)) {
|
|
43
|
+
return el.__base__.get(ctor);
|
|
44
|
+
}
|
|
45
|
+
const child = new ctor(el);
|
|
46
|
+
Object.defineProperty(child, "$parent", { get: () => that.__base });
|
|
47
|
+
return child;
|
|
48
|
+
}
|
|
49
|
+
const promise = asyncComponentPromise ? asyncComponentPromise.promise : ComponentClass(that.__base);
|
|
50
|
+
if (!asyncComponentPromise) {
|
|
51
|
+
that.__asyncComponentPromises.set(ComponentClass, {
|
|
52
|
+
promise,
|
|
53
|
+
status: "pending",
|
|
54
|
+
ctor: void 0
|
|
59
55
|
});
|
|
60
56
|
}
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
return promise.then((module2) => {
|
|
58
|
+
var _a;
|
|
59
|
+
const ctor = (_a = module2.default) != null ? _a : module2;
|
|
60
|
+
that.__asyncComponentPromises.set(ComponentClass, {
|
|
61
|
+
promise,
|
|
62
|
+
status: "resolved",
|
|
63
|
+
ctor
|
|
64
|
+
});
|
|
65
|
+
return __getChild(that, el, ctor, name);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function __register(that, name, component) {
|
|
69
|
+
Object.defineProperty(that, name, {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
configurable: true,
|
|
72
|
+
get: () => {
|
|
73
|
+
const elements = (0, import_utils.getComponentElements)(name, that.__element);
|
|
74
|
+
if (elements.length === 0) {
|
|
75
|
+
return [];
|
|
76
|
+
}
|
|
77
|
+
return elements.map((element) => __getChild(that, element, component, name)).filter((instance) => instance !== "terminated");
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function __triggerHook(that, hook, instance, name) {
|
|
82
|
+
if (hook === "$update" && !instance.$isMounted) {
|
|
83
|
+
hook = "$mount";
|
|
63
84
|
}
|
|
64
|
-
|
|
65
|
-
|
|
85
|
+
if (hook === "$update" || hook === "$destroy") {
|
|
86
|
+
that.__eventsManager.unbindChild(name, instance);
|
|
66
87
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
enumerable: true,
|
|
70
|
-
configurable: true,
|
|
71
|
-
get: () => {
|
|
72
|
-
const elements = (0, import_utils.getComponentElements)(name, this.__element);
|
|
73
|
-
if (elements.length === 0) {
|
|
74
|
-
return [];
|
|
75
|
-
}
|
|
76
|
-
return elements.map((element) => this.__getChild(element, component, name)).filter((instance) => instance !== "terminated");
|
|
77
|
-
}
|
|
78
|
-
});
|
|
88
|
+
if (hook === "$update" || hook === "$mount") {
|
|
89
|
+
that.__eventsManager.bindChild(name, instance);
|
|
79
90
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
91
|
+
instance[hook]();
|
|
92
|
+
}
|
|
93
|
+
function __triggerHookForAll(that, hook) {
|
|
94
|
+
that.registeredNames.forEach((name) => {
|
|
95
|
+
that[name].forEach((instance) => {
|
|
96
|
+
if (instance instanceof Promise) {
|
|
97
|
+
instance.then((resolvedInstance) => __triggerHook(that, hook, resolvedInstance, name));
|
|
98
|
+
} else {
|
|
99
|
+
__triggerHook(that, hook, instance, name);
|
|
89
100
|
}
|
|
90
|
-
const child = new ctor(el);
|
|
91
|
-
Object.defineProperty(child, "$parent", { get: () => this.__base });
|
|
92
|
-
return child;
|
|
93
|
-
}
|
|
94
|
-
const promise = asyncComponentPromise ? asyncComponentPromise.promise : ComponentClass(this.__base);
|
|
95
|
-
if (!asyncComponentPromise) {
|
|
96
|
-
this.__asyncComponentPromises.set(ComponentClass, {
|
|
97
|
-
promise,
|
|
98
|
-
status: "pending",
|
|
99
|
-
ctor: void 0
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
return promise.then((module2) => {
|
|
103
|
-
var _a;
|
|
104
|
-
const ctor = (_a = module2.default) != null ? _a : module2;
|
|
105
|
-
this.__asyncComponentPromises.set(ComponentClass, {
|
|
106
|
-
promise,
|
|
107
|
-
status: "resolved",
|
|
108
|
-
ctor
|
|
109
|
-
});
|
|
110
|
-
return this.__getChild(el, ctor, name);
|
|
111
101
|
});
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
var ChildrenManager = class extends import_AbstractManager.default {
|
|
105
|
+
constructor() {
|
|
106
|
+
super(...arguments);
|
|
107
|
+
__publicField(this, "__asyncComponentPromises", /* @__PURE__ */ new WeakMap());
|
|
108
|
+
}
|
|
109
|
+
get registeredNames() {
|
|
110
|
+
return Object.keys(this).filter((key) => !key.startsWith("__"));
|
|
111
|
+
}
|
|
112
|
+
registerAll() {
|
|
113
|
+
Object.entries(this.__config.components).forEach(([name, component]) => __register(this, name, component));
|
|
112
114
|
}
|
|
113
115
|
mountAll() {
|
|
114
|
-
|
|
116
|
+
__triggerHookForAll(this, "$mount");
|
|
115
117
|
}
|
|
116
118
|
updateAll() {
|
|
117
|
-
|
|
119
|
+
__triggerHookForAll(this, "$update");
|
|
118
120
|
}
|
|
119
121
|
destroyAll() {
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
__triggerHookForAll(hook) {
|
|
123
|
-
this.registeredNames.forEach((name) => {
|
|
124
|
-
this[name].forEach((instance) => {
|
|
125
|
-
if (instance instanceof Promise) {
|
|
126
|
-
instance.then((resolvedInstance) => this.__triggerHook(hook, resolvedInstance, name));
|
|
127
|
-
} else {
|
|
128
|
-
this.__triggerHook(hook, instance, name);
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
__triggerHook(hook, instance, name) {
|
|
134
|
-
if (hook === "$update" && !instance.$isMounted) {
|
|
135
|
-
hook = "$mount";
|
|
136
|
-
}
|
|
137
|
-
if (hook === "$update" || hook === "$destroy") {
|
|
138
|
-
this.__eventsManager.unbindChild(name, instance);
|
|
139
|
-
}
|
|
140
|
-
if (hook === "$update" || hook === "$mount") {
|
|
141
|
-
this.__eventsManager.bindChild(name, instance);
|
|
142
|
-
}
|
|
143
|
-
instance[hook]();
|
|
122
|
+
__triggerHookForAll(this, "$destroy");
|
|
144
123
|
}
|
|
145
124
|
};
|
|
146
125
|
if (module.exports.default) module.exports = module.exports.default;
|
|
@@ -1,85 +1,26 @@
|
|
|
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
|
*/
|
|
54
19
|
get registeredNames(): string[];
|
|
55
20
|
/**
|
|
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
|
-
* @return {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 {
|