@studiometa/js-toolkit 2.0.0 → 2.2.0-alpha.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.
Files changed (72) hide show
  1. package/Base/index.cjs +55 -18
  2. package/Base/index.d.ts +23 -1
  3. package/Base/index.js +55 -18
  4. package/Base/managers/AbstractManager.cjs +56 -0
  5. package/Base/managers/AbstractManager.d.ts +44 -0
  6. package/Base/managers/AbstractManager.js +35 -0
  7. package/Base/managers/ChildrenManager.cjs +79 -100
  8. package/Base/managers/ChildrenManager.d.ts +7 -82
  9. package/Base/managers/ChildrenManager.js +76 -100
  10. package/Base/managers/EventsManager.cjs +75 -99
  11. package/Base/managers/EventsManager.d.ts +31 -100
  12. package/Base/managers/EventsManager.js +75 -99
  13. package/Base/managers/OptionsManager.cjs +65 -78
  14. package/Base/managers/OptionsManager.d.ts +37 -79
  15. package/Base/managers/OptionsManager.js +66 -79
  16. package/Base/managers/RefsManager.cjs +44 -68
  17. package/Base/managers/RefsManager.d.ts +10 -64
  18. package/Base/managers/RefsManager.js +41 -69
  19. package/Base/managers/ResponsiveOptionsManager.cjs +62 -0
  20. package/Base/managers/ResponsiveOptionsManager.d.ts +26 -0
  21. package/Base/managers/ResponsiveOptionsManager.js +37 -0
  22. package/Base/managers/ServicesManager.cjs +5 -11
  23. package/Base/managers/ServicesManager.d.ts +2 -11
  24. package/Base/managers/ServicesManager.js +5 -11
  25. package/decorators/index.cjs +2 -0
  26. package/decorators/index.d.ts +1 -0
  27. package/decorators/index.js +6 -4
  28. package/decorators/withFreezedOptions.cjs +12 -3
  29. package/decorators/withFreezedOptions.js +13 -3
  30. package/decorators/withResponsiveOptions.cjs +39 -0
  31. package/decorators/withResponsiveOptions.d.ts +8 -0
  32. package/decorators/withResponsiveOptions.js +14 -0
  33. package/decorators/withScrolledInView.cjs +66 -23
  34. package/decorators/withScrolledInView.d.ts +4 -2
  35. package/decorators/withScrolledInView.js +67 -24
  36. package/package.json +2 -1
  37. package/services/Service.cjs +2 -2
  38. package/services/Service.d.ts +9 -1
  39. package/services/Service.js +2 -2
  40. package/services/raf.cjs +16 -0
  41. package/services/raf.js +16 -0
  42. package/services/scroll.cjs +3 -1
  43. package/services/scroll.js +3 -1
  44. package/utils/css/animate.cjs +207 -0
  45. package/utils/css/animate.d.ts +57 -0
  46. package/utils/css/animate.js +182 -0
  47. package/utils/css/getOffsetSizes.cjs +47 -0
  48. package/utils/css/getOffsetSizes.d.ts +15 -0
  49. package/utils/css/getOffsetSizes.js +25 -0
  50. package/utils/css/index.cjs +6 -0
  51. package/utils/css/index.d.ts +3 -0
  52. package/utils/css/index.js +9 -4
  53. package/utils/css/transform.cjs +91 -0
  54. package/utils/css/transform.d.ts +43 -0
  55. package/utils/css/transform.js +66 -0
  56. package/utils/css/transition.cjs +2 -0
  57. package/utils/css/transition.js +2 -0
  58. package/utils/index.cjs +5 -0
  59. package/utils/index.d.ts +3 -0
  60. package/utils/index.js +5 -0
  61. package/utils/isDefined.cjs +28 -0
  62. package/utils/isDefined.d.ts +7 -0
  63. package/utils/isDefined.js +6 -0
  64. package/utils/isFunction.cjs +28 -0
  65. package/utils/isFunction.d.ts +7 -0
  66. package/utils/isFunction.js +6 -0
  67. package/utils/math/index.cjs +2 -0
  68. package/utils/math/index.d.ts +1 -0
  69. package/utils/math/index.js +2 -0
  70. package/utils/scheduler.cjs +72 -0
  71. package/utils/scheduler.d.ts +19 -0
  72. package/utils/scheduler.js +50 -0
package/Base/index.cjs CHANGED
@@ -40,6 +40,40 @@ var id = 0;
40
40
  var isDev = typeof __DEV__ !== "undefined" && __DEV__;
41
41
  function noop() {
42
42
  }
43
+ function createAndTestManagers(instance) {
44
+ [
45
+ {
46
+ prop: "__options",
47
+ constructorName: "OptionsManager",
48
+ constructor: import_OptionsManager.default
49
+ },
50
+ {
51
+ prop: "__services",
52
+ constructorName: "ServicesManager",
53
+ constructor: import_ServicesManager.default
54
+ },
55
+ {
56
+ prop: "__events",
57
+ constructorName: "EventsManager",
58
+ constructor: import_EventsManager.default
59
+ },
60
+ {
61
+ prop: "__refs",
62
+ constructorName: "RefsManager",
63
+ constructor: import_RefsManager.default
64
+ },
65
+ {
66
+ prop: "__children",
67
+ constructorName: "ChildrenManager",
68
+ constructor: import_ChildrenManager.default
69
+ }
70
+ ].forEach(({ prop, constructorName, constructor }) => {
71
+ instance[prop] = new instance.__managers[constructorName](instance);
72
+ if (!(instance[prop] instanceof constructor)) {
73
+ throw new Error(`The \`$managers.${constructorName}\` must extend the \`${constructorName}\` class.`);
74
+ }
75
+ });
76
+ }
43
77
  var Base = class extends EventTarget {
44
78
  constructor(element) {
45
79
  super();
@@ -67,11 +101,7 @@ var Base = class extends EventTarget {
67
101
  this.$el.__base__ = /* @__PURE__ */ new WeakMap();
68
102
  }
69
103
  this.$el.__base__.set(this.__ctor, this);
70
- this.__options = new import_OptionsManager.default(element, __config.options || {}, __config);
71
- this.__services = new import_ServicesManager.default(this);
72
- this.__events = new import_EventsManager.default(element, this);
73
- this.__children = new import_ChildrenManager.default(this, element, __config.components || {}, this.__events);
74
- this.__refs = new import_RefsManager.default(this, element, __config.refs || [], this.__events);
104
+ createAndTestManagers(this);
75
105
  if (isDev) {
76
106
  this.__debug("constructor", this);
77
107
  }
@@ -91,24 +121,22 @@ var Base = class extends EventTarget {
91
121
  return root;
92
122
  }
93
123
  get __config() {
124
+ var _a, _b, _c;
94
125
  let proto = Object.getPrototypeOf(this);
95
126
  let { config } = proto.constructor;
96
127
  while (proto.constructor.config && proto.constructor.$isBase) {
97
- config = {
98
- ...proto.constructor.config,
99
- ...config
100
- };
128
+ config = { ...proto.constructor.config, ...config };
101
129
  if (proto.constructor.config.options) {
102
- config.options = {
103
- ...proto.constructor.config.options,
104
- ...config.options
105
- };
130
+ config.options = { ...proto.constructor.config.options, ...config.options };
106
131
  }
107
132
  if (proto.constructor.config.emits && config.emits) {
108
133
  config.emits = [...proto.constructor.config.emits, ...config.emits];
109
134
  }
110
135
  proto = Object.getPrototypeOf(proto);
111
136
  }
137
+ config.options = (_a = config.options) != null ? _a : {};
138
+ config.refs = (_b = config.refs) != null ? _b : [];
139
+ config.components = (_c = config.components) != null ? _c : {};
112
140
  return config;
113
141
  }
114
142
  get $services() {
@@ -129,18 +157,27 @@ var Base = class extends EventTarget {
129
157
  get __debug() {
130
158
  return isDev && this.__options.debug ? window.console.log.bind(window, `[debug] [${this.$id}]`) : noop;
131
159
  }
160
+ get __managers() {
161
+ return {
162
+ ChildrenManager: import_ChildrenManager.default,
163
+ EventsManager: import_EventsManager.default,
164
+ OptionsManager: import_OptionsManager.default,
165
+ RefsManager: import_RefsManager.default,
166
+ ServicesManager: import_ServicesManager.default
167
+ };
168
+ }
132
169
  __callMethod(method, ...args) {
133
170
  if (isDev) {
134
171
  this.__debug("callMethod", method, ...args);
135
172
  }
136
173
  this.$emit(method, ...args);
137
174
  if (typeof this[method] !== "function") {
138
- return;
175
+ return null;
139
176
  }
140
- this[method].call(this, ...args);
141
177
  if (isDev) {
142
178
  this.__debug(method, this, ...args);
143
179
  }
180
+ return this[method].call(this, ...args);
144
181
  }
145
182
  __hasEvent(event) {
146
183
  const eventHandlers = this.__eventHandlers.get(event);
@@ -150,6 +187,7 @@ var Base = class extends EventTarget {
150
187
  if (this.$isMounted) {
151
188
  return this;
152
189
  }
190
+ this.$emit("before-mounted");
153
191
  this.$isMounted = true;
154
192
  if (isDev) {
155
193
  this.__debug("$mount");
@@ -254,9 +292,7 @@ var Base = class extends EventTarget {
254
292
  if (isDev) {
255
293
  this.__testEventIsDefined(event);
256
294
  }
257
- this.dispatchEvent(new CustomEvent(event, {
258
- detail: args
259
- }));
295
+ this.dispatchEvent(new CustomEvent(event, { detail: args }));
260
296
  }
261
297
  static $factory(nameOrSelector) {
262
298
  if (!nameOrSelector) {
@@ -269,6 +305,7 @@ __publicField(Base, "$isBase", true);
269
305
  __publicField(Base, "config", {
270
306
  name: "Base",
271
307
  emits: [
308
+ "before-mounted",
272
309
  "mounted",
273
310
  "updated",
274
311
  "destroyed",
package/Base/index.d.ts CHANGED
@@ -18,6 +18,14 @@
18
18
  * @property {BaseConfigComponents} [components]
19
19
  * @property {BaseConfigOptions} [options]
20
20
  */
21
+ /**
22
+ * @typedef {Object} Managers
23
+ * @property {typeof ChildrenManager} ChildrenManager
24
+ * @property {typeof EventsManager} EventsManager
25
+ * @property {typeof OptionsManager} OptionsManager
26
+ * @property {typeof RefsManager} RefsManager
27
+ * @property {typeof ServicesManager} ServicesManager
28
+ */
21
29
  /**
22
30
  * Base class.
23
31
  */
@@ -140,13 +148,19 @@ export default class Base extends EventTarget {
140
148
  * @returns {(...args:any) => void}
141
149
  */
142
150
  private get __debug();
151
+ /**
152
+ * Get manager constructors.
153
+ *
154
+ * @returns {Managers}
155
+ */
156
+ get __managers(): Managers;
143
157
  /**
144
158
  * Call an instance method and emit corresponding events.
145
159
  *
146
160
  * @private
147
161
  * @param {string} method
148
162
  * @param {any[]} args
149
- * @returns {void}
163
+ * @returns {any}
150
164
  */
151
165
  private __callMethod;
152
166
  /**
@@ -270,7 +284,15 @@ export type BaseConfig = {
270
284
  components?: BaseConfigComponents;
271
285
  options?: BaseConfigOptions;
272
286
  };
287
+ export type Managers = {
288
+ ChildrenManager: typeof ChildrenManager;
289
+ EventsManager: typeof EventsManager;
290
+ OptionsManager: typeof OptionsManager;
291
+ RefsManager: typeof RefsManager;
292
+ ServicesManager: typeof ServicesManager;
293
+ };
273
294
  import ServicesManager from "./managers/ServicesManager.js";
274
295
  import RefsManager from "./managers/RefsManager.js";
275
296
  import ChildrenManager from "./managers/ChildrenManager.js";
276
297
  import OptionsManager from "./managers/OptionsManager.js";
298
+ import EventsManager from "./managers/EventsManager.js";
package/Base/index.js CHANGED
@@ -14,6 +14,40 @@ let id = 0;
14
14
  const isDev = typeof __DEV__ !== "undefined" && __DEV__;
15
15
  function noop() {
16
16
  }
17
+ function createAndTestManagers(instance) {
18
+ [
19
+ {
20
+ prop: "__options",
21
+ constructorName: "OptionsManager",
22
+ constructor: OptionsManager
23
+ },
24
+ {
25
+ prop: "__services",
26
+ constructorName: "ServicesManager",
27
+ constructor: ServicesManager
28
+ },
29
+ {
30
+ prop: "__events",
31
+ constructorName: "EventsManager",
32
+ constructor: EventsManager
33
+ },
34
+ {
35
+ prop: "__refs",
36
+ constructorName: "RefsManager",
37
+ constructor: RefsManager
38
+ },
39
+ {
40
+ prop: "__children",
41
+ constructorName: "ChildrenManager",
42
+ constructor: ChildrenManager
43
+ }
44
+ ].forEach(({ prop, constructorName, constructor }) => {
45
+ instance[prop] = new instance.__managers[constructorName](instance);
46
+ if (!(instance[prop] instanceof constructor)) {
47
+ throw new Error(`The \`$managers.${constructorName}\` must extend the \`${constructorName}\` class.`);
48
+ }
49
+ });
50
+ }
17
51
  class Base extends EventTarget {
18
52
  constructor(element) {
19
53
  super();
@@ -41,11 +75,7 @@ class Base extends EventTarget {
41
75
  this.$el.__base__ = /* @__PURE__ */ new WeakMap();
42
76
  }
43
77
  this.$el.__base__.set(this.__ctor, this);
44
- this.__options = new OptionsManager(element, __config.options || {}, __config);
45
- this.__services = new ServicesManager(this);
46
- this.__events = new EventsManager(element, this);
47
- this.__children = new ChildrenManager(this, element, __config.components || {}, this.__events);
48
- this.__refs = new RefsManager(this, element, __config.refs || [], this.__events);
78
+ createAndTestManagers(this);
49
79
  if (isDev) {
50
80
  this.__debug("constructor", this);
51
81
  }
@@ -65,24 +95,22 @@ class Base extends EventTarget {
65
95
  return root;
66
96
  }
67
97
  get __config() {
98
+ var _a, _b, _c;
68
99
  let proto = Object.getPrototypeOf(this);
69
100
  let { config } = proto.constructor;
70
101
  while (proto.constructor.config && proto.constructor.$isBase) {
71
- config = {
72
- ...proto.constructor.config,
73
- ...config
74
- };
102
+ config = { ...proto.constructor.config, ...config };
75
103
  if (proto.constructor.config.options) {
76
- config.options = {
77
- ...proto.constructor.config.options,
78
- ...config.options
79
- };
104
+ config.options = { ...proto.constructor.config.options, ...config.options };
80
105
  }
81
106
  if (proto.constructor.config.emits && config.emits) {
82
107
  config.emits = [...proto.constructor.config.emits, ...config.emits];
83
108
  }
84
109
  proto = Object.getPrototypeOf(proto);
85
110
  }
111
+ config.options = (_a = config.options) != null ? _a : {};
112
+ config.refs = (_b = config.refs) != null ? _b : [];
113
+ config.components = (_c = config.components) != null ? _c : {};
86
114
  return config;
87
115
  }
88
116
  get $services() {
@@ -103,18 +131,27 @@ class Base extends EventTarget {
103
131
  get __debug() {
104
132
  return isDev && this.__options.debug ? window.console.log.bind(window, `[debug] [${this.$id}]`) : noop;
105
133
  }
134
+ get __managers() {
135
+ return {
136
+ ChildrenManager,
137
+ EventsManager,
138
+ OptionsManager,
139
+ RefsManager,
140
+ ServicesManager
141
+ };
142
+ }
106
143
  __callMethod(method, ...args) {
107
144
  if (isDev) {
108
145
  this.__debug("callMethod", method, ...args);
109
146
  }
110
147
  this.$emit(method, ...args);
111
148
  if (typeof this[method] !== "function") {
112
- return;
149
+ return null;
113
150
  }
114
- this[method].call(this, ...args);
115
151
  if (isDev) {
116
152
  this.__debug(method, this, ...args);
117
153
  }
154
+ return this[method].call(this, ...args);
118
155
  }
119
156
  __hasEvent(event) {
120
157
  const eventHandlers = this.__eventHandlers.get(event);
@@ -124,6 +161,7 @@ class Base extends EventTarget {
124
161
  if (this.$isMounted) {
125
162
  return this;
126
163
  }
164
+ this.$emit("before-mounted");
127
165
  this.$isMounted = true;
128
166
  if (isDev) {
129
167
  this.__debug("$mount");
@@ -228,9 +266,7 @@ class Base extends EventTarget {
228
266
  if (isDev) {
229
267
  this.__testEventIsDefined(event);
230
268
  }
231
- this.dispatchEvent(new CustomEvent(event, {
232
- detail: args
233
- }));
269
+ this.dispatchEvent(new CustomEvent(event, { detail: args }));
234
270
  }
235
271
  static $factory(nameOrSelector) {
236
272
  if (!nameOrSelector) {
@@ -243,6 +279,7 @@ __publicField(Base, "$isBase", true);
243
279
  __publicField(Base, "config", {
244
280
  name: "Base",
245
281
  emits: [
282
+ "before-mounted",
246
283
  "mounted",
247
284
  "updated",
248
285
  "destroyed",
@@ -0,0 +1,56 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var __publicField = (obj, key, value) => {
20
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
+ return value;
22
+ };
23
+
24
+ // packages/js-toolkit/Base/managers/AbstractManager.js
25
+ var AbstractManager_exports = {};
26
+ __export(AbstractManager_exports, {
27
+ default: () => AbstractManager
28
+ });
29
+ module.exports = __toCommonJS(AbstractManager_exports);
30
+ var AbstractManager = class {
31
+ constructor(base) {
32
+ __publicField(this, "__base");
33
+ this.__base = base;
34
+ this.__hideProperties(["__base"]);
35
+ }
36
+ get __element() {
37
+ return this.__base.$el;
38
+ }
39
+ get __config() {
40
+ return this.__base.__config;
41
+ }
42
+ get __eventsManager() {
43
+ return this.__base.__events;
44
+ }
45
+ __hideProperties(properties) {
46
+ Object.defineProperties(this, Object.fromEntries(properties.map((property) => [
47
+ property,
48
+ {
49
+ enumerable: false,
50
+ writable: false,
51
+ value: this[property]
52
+ }
53
+ ])));
54
+ }
55
+ };
56
+ if (module.exports.default) module.exports = module.exports.default;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @typedef {import('../index.js').default} Base
3
+ * @typedef {import('../index.js').BaseConfig} BaseConfig
4
+ * @typedef {import('./EventsManager.js').default} EventsManager
5
+ */
6
+ /**
7
+ * AbstractManager class.
8
+ */
9
+ export default class AbstractManager {
10
+ /**
11
+ * Class constructor.
12
+ *
13
+ * @param {Base} base
14
+ */
15
+ constructor(base: Base);
16
+ /**
17
+ * @type {Base}
18
+ */
19
+ __base: Base;
20
+ /**
21
+ * Get the base instance root element.
22
+ * @returns {HTMLElement}
23
+ */
24
+ get __element(): HTMLElement;
25
+ /**
26
+ * Get the base instance config.
27
+ * @returns {BaseConfig}
28
+ */
29
+ get __config(): import("../index.js").BaseConfig;
30
+ /**
31
+ * Get the events manager.
32
+ * @returns {EventsManager}
33
+ */
34
+ get __eventsManager(): import("./EventsManager.js").default;
35
+ /**
36
+ * Prevent a list of properties from being enumerable and writable.
37
+ * @param {string[]} properties
38
+ * @returns {void}
39
+ */
40
+ __hideProperties(properties: string[]): void;
41
+ }
42
+ export type Base = import('../index.js').default;
43
+ export type BaseConfig = import('../index.js').BaseConfig;
44
+ export type EventsManager = import('./EventsManager.js').default;
@@ -0,0 +1,35 @@
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
+ class AbstractManager {
8
+ constructor(base) {
9
+ __publicField(this, "__base");
10
+ this.__base = base;
11
+ this.__hideProperties(["__base"]);
12
+ }
13
+ get __element() {
14
+ return this.__base.$el;
15
+ }
16
+ get __config() {
17
+ return this.__base.__config;
18
+ }
19
+ get __eventsManager() {
20
+ return this.__base.__events;
21
+ }
22
+ __hideProperties(properties) {
23
+ Object.defineProperties(this, Object.fromEntries(properties.map((property) => [
24
+ property,
25
+ {
26
+ enumerable: false,
27
+ writable: false,
28
+ value: this[property]
29
+ }
30
+ ])));
31
+ }
32
+ }
33
+ export {
34
+ AbstractManager as default
35
+ };
@@ -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
- var ChildrenManager = class {
32
- constructor(base, element, components, eventsManager) {
33
- __publicField(this, "__base");
34
- __publicField(this, "__element");
35
- __publicField(this, "__components");
36
- __publicField(this, "__eventsManager");
37
- __publicField(this, "__asyncComponentPromises", /* @__PURE__ */ new WeakMap());
38
- Object.defineProperties(this, {
39
- __base: {
40
- enumerable: false,
41
- writable: false,
42
- value: base
43
- },
44
- __element: {
45
- enumerable: false,
46
- writable: false,
47
- value: element
48
- },
49
- __components: {
50
- enumerable: false,
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
- get registeredNames() {
62
- return Object.keys(this).filter((key) => !key.startsWith("__"));
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
- registerAll() {
65
- Object.entries(this.__components).forEach(([name, component]) => this.__register(name, component));
85
+ if (hook === "$update" || hook === "$destroy") {
86
+ that.__eventsManager.unbindChild(name, instance);
66
87
  }
67
- __register(name, component) {
68
- Object.defineProperty(this, name, {
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
- __getChild(el, ComponentClass, name) {
81
- const asyncComponentPromise = this.__asyncComponentPromises.get(ComponentClass);
82
- if ("$isBase" in ComponentClass || asyncComponentPromise && asyncComponentPromise.status === "resolved") {
83
- let ctor = ComponentClass;
84
- if (asyncComponentPromise) {
85
- ctor = asyncComponentPromise.ctor;
86
- }
87
- if (el.__base__ && el.__base__.has(ctor)) {
88
- return el.__base__.get(ctor);
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
- this.__triggerHookForAll("$mount");
116
+ __triggerHookForAll(this, "$mount");
115
117
  }
116
118
  updateAll() {
117
- this.__triggerHookForAll("$update");
119
+ __triggerHookForAll(this, "$update");
118
120
  }
119
121
  destroyAll() {
120
- this.__triggerHookForAll("$destroy");
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;