@studiometa/js-toolkit 2.0.0-beta.1 → 2.0.0-beta.13

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 (184) hide show
  1. package/Base/index.cjs +294 -0
  2. package/Base/index.d.ts +27 -1
  3. package/Base/index.js +149 -179
  4. package/Base/managers/ChildrenManager.cjs +124 -0
  5. package/Base/managers/ChildrenManager.js +29 -55
  6. package/Base/managers/EventsManager.cjs +184 -0
  7. package/Base/managers/EventsManager.d.ts +3 -1
  8. package/Base/managers/EventsManager.js +85 -127
  9. package/Base/managers/OptionsManager.cjs +175 -0
  10. package/Base/managers/OptionsManager.d.ts +2 -0
  11. package/Base/managers/OptionsManager.js +46 -88
  12. package/Base/managers/RefsManager.cjs +98 -0
  13. package/Base/managers/RefsManager.d.ts +2 -0
  14. package/Base/managers/RefsManager.js +24 -35
  15. package/Base/managers/ServicesManager.cjs +132 -0
  16. package/Base/managers/ServicesManager.d.ts +29 -4
  17. package/Base/managers/ServicesManager.js +33 -63
  18. package/Base/utils.cjs +45 -0
  19. package/Base/utils.js +12 -11
  20. package/README.md +13 -70
  21. package/decorators/index.cjs +49 -0
  22. package/decorators/index.d.ts +8 -9
  23. package/decorators/index.js +18 -9
  24. package/decorators/withBreakpointManager.cjs +91 -0
  25. package/decorators/withBreakpointManager.js +18 -39
  26. package/decorators/withBreakpointObserver.cjs +116 -0
  27. package/decorators/withBreakpointObserver.js +40 -88
  28. package/decorators/withDrag.cjs +54 -0
  29. package/decorators/withDrag.js +16 -18
  30. package/decorators/withExtraConfig.cjs +44 -0
  31. package/decorators/withExtraConfig.js +11 -12
  32. package/decorators/withIntersectionObserver.cjs +61 -0
  33. package/decorators/withIntersectionObserver.js +23 -31
  34. package/decorators/withMountWhenInView.cjs +68 -0
  35. package/decorators/withMountWhenInView.js +31 -55
  36. package/decorators/withScrolledInView.cjs +112 -0
  37. package/decorators/withScrolledInView.d.ts +4 -1
  38. package/decorators/withScrolledInView.js +77 -73
  39. package/decorators/withVue2.cjs +60 -0
  40. package/decorators/withVue2.js +21 -32
  41. package/helpers/createApp.cjs +56 -0
  42. package/helpers/createApp.js +12 -12
  43. package/helpers/importOnInteraction.cjs +56 -0
  44. package/helpers/importOnInteraction.js +17 -18
  45. package/helpers/importWhenIdle.cjs +52 -0
  46. package/helpers/importWhenIdle.js +13 -17
  47. package/helpers/importWhenVisible.cjs +54 -0
  48. package/helpers/importWhenVisible.js +16 -18
  49. package/helpers/index.cjs +41 -0
  50. package/helpers/index.d.ts +4 -5
  51. package/helpers/index.js +10 -5
  52. package/helpers/utils.cjs +39 -0
  53. package/helpers/utils.js +7 -6
  54. package/index.cjs +38 -0
  55. package/index.d.ts +4 -21
  56. package/index.js +7 -5
  57. package/package.json +14 -3
  58. package/services/Service.cjs +75 -0
  59. package/services/Service.d.ts +22 -17
  60. package/services/Service.js +14 -28
  61. package/services/drag.cjs +194 -0
  62. package/services/drag.d.ts +4 -18
  63. package/services/drag.js +103 -156
  64. package/services/index.cjs +47 -0
  65. package/services/index.d.ts +13 -10
  66. package/services/index.js +16 -8
  67. package/services/key.cjs +101 -0
  68. package/services/key.d.ts +4 -13
  69. package/services/key.js +58 -77
  70. package/services/load.cjs +70 -0
  71. package/services/load.d.ts +3 -13
  72. package/services/load.js +31 -36
  73. package/services/pointer.cjs +159 -0
  74. package/services/pointer.d.ts +4 -13
  75. package/services/pointer.js +91 -121
  76. package/services/raf.cjs +81 -0
  77. package/services/raf.d.ts +3 -13
  78. package/services/raf.js +32 -52
  79. package/services/resize.cjs +106 -0
  80. package/services/resize.d.ts +3 -13
  81. package/services/resize.js +52 -52
  82. package/services/scroll.cjs +129 -0
  83. package/services/scroll.d.ts +3 -13
  84. package/services/scroll.js +75 -89
  85. package/utils/collide/boundingRectToCircle.cjs +38 -0
  86. package/utils/collide/boundingRectToCircle.d.ts +1 -1
  87. package/utils/collide/boundingRectToCircle.js +7 -10
  88. package/utils/collide/collideCircleCircle.cjs +38 -0
  89. package/utils/collide/collideCircleCircle.js +8 -7
  90. package/utils/collide/collideCircleRect.cjs +50 -0
  91. package/utils/collide/collideCircleRect.js +10 -12
  92. package/utils/collide/collidePointCircle.cjs +35 -0
  93. package/utils/collide/collidePointCircle.js +8 -5
  94. package/utils/collide/collidePointRect.cjs +32 -0
  95. package/utils/collide/collidePointRect.js +5 -2
  96. package/utils/collide/collideRectRect.cjs +32 -0
  97. package/utils/collide/collideRectRect.js +5 -2
  98. package/utils/collide/index.cjs +45 -0
  99. package/utils/collide/index.d.ts +6 -7
  100. package/utils/collide/index.js +14 -7
  101. package/utils/css/classes.cjs +48 -0
  102. package/utils/css/classes.js +13 -12
  103. package/utils/css/index.cjs +41 -0
  104. package/utils/css/index.d.ts +4 -5
  105. package/utils/css/index.js +10 -5
  106. package/utils/css/matrix.cjs +33 -0
  107. package/utils/css/matrix.js +6 -5
  108. package/utils/css/styles.cjs +51 -0
  109. package/utils/css/styles.js +13 -12
  110. package/utils/css/transition.cjs +121 -0
  111. package/utils/css/transition.js +62 -117
  112. package/utils/debounce.cjs +38 -0
  113. package/utils/debounce.js +7 -9
  114. package/utils/focusTrap.cjs +88 -0
  115. package/utils/focusTrap.js +30 -21
  116. package/utils/history.cjs +95 -0
  117. package/utils/history.js +28 -57
  118. package/utils/index.cjs +57 -0
  119. package/utils/index.d.ts +12 -35
  120. package/utils/index.js +30 -17
  121. package/utils/keyCodes.cjs +39 -0
  122. package/utils/keyCodes.js +5 -2
  123. package/utils/math/clamp.cjs +32 -0
  124. package/utils/math/clamp.js +5 -2
  125. package/utils/math/clamp01.cjs +38 -0
  126. package/utils/math/clamp01.js +6 -3
  127. package/utils/math/damp.cjs +32 -0
  128. package/utils/math/damp.js +5 -4
  129. package/utils/math/ease.cjs +92 -0
  130. package/utils/math/ease.d.ts +78 -0
  131. package/utils/math/ease.js +66 -0
  132. package/utils/math/index.cjs +48 -0
  133. package/utils/math/index.d.ts +8 -8
  134. package/utils/math/index.js +17 -8
  135. package/utils/math/inertiaFinalValue.cjs +41 -0
  136. package/utils/math/inertiaFinalValue.js +8 -10
  137. package/utils/math/lerp.cjs +32 -0
  138. package/utils/math/lerp.js +5 -2
  139. package/utils/math/map.cjs +32 -0
  140. package/utils/math/map.js +5 -2
  141. package/utils/math/round.cjs +32 -0
  142. package/utils/math/round.js +5 -3
  143. package/utils/memoize.cjs +47 -0
  144. package/utils/memoize.js +10 -19
  145. package/utils/nextFrame.cjs +44 -0
  146. package/utils/nextFrame.js +14 -9
  147. package/utils/object/autoBind.cjs +55 -0
  148. package/utils/object/autoBind.js +12 -22
  149. package/utils/object/getAllProperties.cjs +41 -0
  150. package/utils/object/getAllProperties.js +11 -14
  151. package/utils/object/index.cjs +39 -0
  152. package/utils/object/index.d.ts +3 -4
  153. package/utils/object/index.js +8 -4
  154. package/utils/object/isObject.cjs +32 -0
  155. package/utils/object/isObject.js +6 -3
  156. package/utils/scrollTo.cjs +86 -0
  157. package/utils/scrollTo.js +20 -40
  158. package/utils/string/index.cjs +53 -0
  159. package/utils/string/index.d.ts +10 -11
  160. package/utils/string/index.js +22 -11
  161. package/utils/string/withLeadingCharacters.cjs +38 -0
  162. package/utils/string/withLeadingCharacters.js +7 -4
  163. package/utils/string/withLeadingSlash.cjs +38 -0
  164. package/utils/string/withLeadingSlash.js +7 -4
  165. package/utils/string/withTrailingCharacters.cjs +38 -0
  166. package/utils/string/withTrailingCharacters.js +7 -4
  167. package/utils/string/withTrailingSlash.cjs +38 -0
  168. package/utils/string/withTrailingSlash.js +7 -4
  169. package/utils/string/withoutLeadingCharacters.cjs +32 -0
  170. package/utils/string/withoutLeadingCharacters.js +6 -3
  171. package/utils/string/withoutLeadingCharactersRecursive.cjs +43 -0
  172. package/utils/string/withoutLeadingCharactersRecursive.js +8 -7
  173. package/utils/string/withoutLeadingSlash.cjs +38 -0
  174. package/utils/string/withoutLeadingSlash.js +7 -4
  175. package/utils/string/withoutTrailingCharacters.cjs +32 -0
  176. package/utils/string/withoutTrailingCharacters.js +6 -3
  177. package/utils/string/withoutTrailingCharactersRecursive.cjs +43 -0
  178. package/utils/string/withoutTrailingCharactersRecursive.js +8 -7
  179. package/utils/string/withoutTrailingSlash.cjs +38 -0
  180. package/utils/string/withoutTrailingSlash.js +7 -4
  181. package/utils/throttle.cjs +40 -0
  182. package/utils/throttle.js +9 -9
  183. package/index.modern.js +0 -1
  184. package/index.umd.js +0 -1
package/Base/index.js CHANGED
@@ -1,288 +1,258 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
-
3
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
4
-
5
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
6
-
7
- import { getComponentElements } from './utils.js';
8
- import ChildrenManager from './managers/ChildrenManager.js';
9
- import RefsManager from './managers/RefsManager.js';
10
- import ServicesManager from './managers/ServicesManager.js';
11
- import EventsManager from './managers/EventsManager.js';
12
- import OptionsManager from './managers/OptionsManager.js';
13
- var id = 0;
14
-
15
- function noop() {}
16
-
17
- export default class Base {
1
+ import { getComponentElements } from "./utils.js";
2
+ import ChildrenManager from "./managers/ChildrenManager.js";
3
+ import RefsManager from "./managers/RefsManager.js";
4
+ import ServicesManager from "./managers/ServicesManager.js";
5
+ import EventsManager from "./managers/EventsManager.js";
6
+ import OptionsManager from "./managers/OptionsManager.js";
7
+ let id = 0;
8
+ const isDev = typeof __DEV__ !== "undefined" && __DEV__;
9
+ function noop() {
10
+ }
11
+ class Base extends EventTarget {
12
+ static $isBase = true;
13
+ $parent = null;
14
+ $id;
15
+ $el;
16
+ $isMounted = false;
17
+ __eventHandlers = /* @__PURE__ */ new Map();
18
18
  get $root() {
19
19
  if (!this.$parent) {
20
20
  return this;
21
21
  }
22
-
23
- var parent = this.$parent;
24
- var root = this.$parent;
25
-
22
+ let parent = this.$parent;
23
+ let root = this.$parent;
26
24
  while (parent) {
27
25
  if (!parent.$parent) {
28
26
  root = parent;
29
27
  }
30
-
31
28
  parent = parent.$parent;
32
29
  }
33
-
34
30
  return root;
35
31
  }
36
-
37
32
  get __config() {
38
- var proto = Object.getPrototypeOf(this);
39
- var {
40
- config
41
- } = proto.constructor;
42
-
33
+ let proto = Object.getPrototypeOf(this);
34
+ let { config } = proto.constructor;
43
35
  while (proto.constructor.config && proto.constructor.$isBase) {
44
- config = _objectSpread(_objectSpread({}, proto.constructor.config), config);
45
-
36
+ config = {
37
+ ...proto.constructor.config,
38
+ ...config
39
+ };
46
40
  if (proto.constructor.config.options) {
47
- config.options = _objectSpread(_objectSpread({}, proto.constructor.config.options), config.options);
41
+ config.options = {
42
+ ...proto.constructor.config.options,
43
+ ...config.options
44
+ };
45
+ }
46
+ if (proto.constructor.config.emits && config.emits) {
47
+ config.emits = [...proto.constructor.config.emits, ...config.emits];
48
48
  }
49
-
50
49
  proto = Object.getPrototypeOf(proto);
51
50
  }
52
-
53
51
  return config;
54
52
  }
55
-
53
+ static config = {
54
+ name: "Base",
55
+ emits: [
56
+ "mounted",
57
+ "updated",
58
+ "destroyed",
59
+ "terminated",
60
+ "ticked",
61
+ "scrolled",
62
+ "resized",
63
+ "moved",
64
+ "loaded",
65
+ "keyed"
66
+ ]
67
+ };
68
+ __services;
56
69
  get $services() {
57
- var services = this.__services;
58
- this.$emit('get:services', services);
59
- return services;
70
+ return this.__services;
60
71
  }
61
-
72
+ __refs;
62
73
  get $refs() {
63
- var refs = this.__refs;
64
- this.$emit('get:refs', refs);
65
- return refs;
74
+ return this.__refs;
66
75
  }
67
-
76
+ __options;
68
77
  get $options() {
69
- var options = this.__options;
70
- this.$emit('get:options', options);
71
- return options;
78
+ return this.__options;
72
79
  }
73
-
80
+ __children;
74
81
  get $children() {
75
- var children = this.__children;
76
- this.$emit('get:children', children);
77
- return children;
82
+ return this.__children;
78
83
  }
79
-
84
+ __events;
80
85
  get $log() {
81
- return this.__options.log ? window.console.log.bind(window, "[".concat(this.__config.name, "]")) : noop;
86
+ return this.__options.log ? window.console.log.bind(window, `[${this.__config.name}]`) : noop;
82
87
  }
83
-
84
88
  get __debug() {
85
- return this.__options.debug && typeof window.__DEV__ !== 'undefined' && window.__DEV__ ? window.console.log.bind(window, "[debug] [".concat(this.$id, "]")) : noop;
89
+ return isDev && this.__options.debug ? window.console.log.bind(window, `[debug] [${this.$id}]`) : noop;
86
90
  }
87
-
88
- __callMethod(method) {
89
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
90
- args[_key - 1] = arguments[_key];
91
- }
92
-
93
- this.__debug('callMethod', method, ...args);
94
-
95
- if (method === 'destroyed' && !this.$isMounted || method === 'mounted' && this.$isMounted) {
96
- this.__debug('not', method, 'because the method has already been triggered once.');
97
-
98
- return;
91
+ __callMethod(method, ...args) {
92
+ if (isDev) {
93
+ this.__debug("callMethod", method, ...args);
99
94
  }
100
-
101
95
  this.$emit(method, ...args);
102
-
103
- if (typeof this[method] !== 'function') {
96
+ if (typeof this[method] !== "function") {
104
97
  return;
105
98
  }
106
-
107
99
  this[method].call(this, ...args);
108
-
109
- this.__debug(method, this, ...args);
100
+ if (isDev) {
101
+ this.__debug(method, this, ...args);
102
+ }
110
103
  }
111
-
112
104
  __hasEvent(event) {
113
- var eventHandlers = this.__eventHandlers.get(event);
114
-
105
+ const eventHandlers = this.__eventHandlers.get(event);
115
106
  return eventHandlers && eventHandlers.size > 0;
116
107
  }
117
-
118
108
  constructor(element) {
119
- _defineProperty(this, "$parent", null);
120
-
121
- _defineProperty(this, "$id", void 0);
122
-
123
- _defineProperty(this, "$el", void 0);
124
-
125
- _defineProperty(this, "$isMounted", false);
126
-
127
- _defineProperty(this, "__eventHandlers", new Map());
128
-
129
- _defineProperty(this, "__services", void 0);
130
-
131
- _defineProperty(this, "__refs", void 0);
132
-
133
- _defineProperty(this, "__options", void 0);
134
-
135
- _defineProperty(this, "__children", void 0);
136
-
137
- _defineProperty(this, "__events", void 0);
138
-
109
+ super();
139
110
  if (!element) {
140
- throw new Error('The root element must be defined.');
141
- }
142
-
143
- var {
144
- __config
145
- } = this;
146
-
147
- if (!__config) {
148
- throw new Error('The `config` static property must be defined.');
111
+ throw new Error("The root element must be defined.");
149
112
  }
150
-
151
- if (!__config.name) {
152
- throw new Error('The `config.name` property is required.');
113
+ const { __config } = this;
114
+ if (__config.name === "Base") {
115
+ throw new Error("The `config.name` property is required.");
153
116
  }
154
-
155
- this.$id = "".concat(__config.name, "-").concat(id);
117
+ this.$id = `${__config.name}-${id}`;
156
118
  id += 1;
157
119
  this.$el = element;
158
-
159
- if (!('__base__' in this.$el)) {
160
- Object.defineProperty(this.$el, '__base__', {
120
+ if (!("__base__" in this.$el)) {
121
+ Object.defineProperty(this.$el, "__base__", {
161
122
  get: () => this,
162
123
  configurable: true
163
124
  });
164
125
  }
165
-
166
126
  this.__options = new OptionsManager(element, __config.options || {}, __config);
167
127
  this.__services = new ServicesManager(this);
168
128
  this.__events = new EventsManager(element, this);
169
129
  this.__children = new ChildrenManager(this, element, __config.components || {}, this.__events);
170
130
  this.__refs = new RefsManager(this, element, __config.refs || [], this.__events);
171
-
172
- this.__debug('constructor', this);
173
-
131
+ if (isDev) {
132
+ this.__debug("constructor", this);
133
+ }
174
134
  return this;
175
135
  }
176
-
177
136
  $mount() {
178
- this.__debug('$mount');
179
-
137
+ if (this.$isMounted) {
138
+ return this;
139
+ }
140
+ this.$isMounted = true;
141
+ if (isDev) {
142
+ this.__debug("$mount");
143
+ }
180
144
  this.$children.registerAll();
181
145
  this.$refs.registerAll();
182
-
183
146
  this.__events.bindRootElement();
184
-
185
147
  this.$services.enableAll();
186
148
  this.$children.mountAll();
187
-
188
- this.__callMethod('mounted');
189
-
190
- this.$isMounted = true;
149
+ this.__callMethod("mounted");
191
150
  return this;
192
151
  }
193
-
194
152
  $update() {
195
- this.__debug('$update');
196
-
153
+ if (isDev) {
154
+ this.__debug("$update");
155
+ }
197
156
  this.$refs.unregisterAll();
198
157
  this.$services.disableAll();
199
158
  this.$children.registerAll();
200
159
  this.$refs.registerAll();
201
160
  this.$services.enableAll();
202
161
  this.$children.updateAll();
203
-
204
- this.__callMethod('updated');
205
-
162
+ this.__callMethod("updated");
206
163
  return this;
207
164
  }
208
-
209
165
  $destroy() {
210
- this.__debug('$destroy');
211
-
166
+ if (!this.$isMounted) {
167
+ return this;
168
+ }
169
+ this.$isMounted = false;
170
+ if (isDev) {
171
+ this.__debug("$destroy");
172
+ }
212
173
  this.__events.unbindRootElement();
213
-
214
174
  this.$refs.unregisterAll();
215
175
  this.$services.disableAll();
216
176
  this.$children.destroyAll();
217
-
218
- this.__callMethod('destroyed');
219
-
220
- this.$isMounted = false;
177
+ this.__callMethod("destroyed");
221
178
  return this;
222
179
  }
223
-
224
180
  $terminate() {
225
- this.__debug('$terminate');
226
-
181
+ if (isDev) {
182
+ this.__debug("$terminate");
183
+ }
227
184
  this.$destroy();
228
-
229
- this.__callMethod('terminated');
230
-
231
- Object.defineProperty(this.$el, '__base__', {
232
- value: 'terminated',
185
+ this.__callMethod("terminated");
186
+ Object.defineProperty(this.$el, "__base__", {
187
+ value: "terminated",
233
188
  configurable: false,
234
189
  writable: false
235
190
  });
236
191
  }
237
-
192
+ __testEventIsDefined(event) {
193
+ if (!(Array.isArray(this.__config.emits) && this.__config.emits.includes(event))) {
194
+ console.warn(`[${this.__config.name}]`, `The "${event}" event is missing from the configuration.`);
195
+ }
196
+ }
197
+ __addEmits(event) {
198
+ const ctor = this.constructor;
199
+ if (Array.isArray(ctor.config.emits)) {
200
+ ctor.config.emits.push(event);
201
+ } else {
202
+ ctor.config.emits = [event];
203
+ }
204
+ }
205
+ __removeEmits(event) {
206
+ const ctor = this.constructor;
207
+ const index = ctor.config.emits.findIndex((value) => value === event);
208
+ ctor.config.emits.splice(index, 1);
209
+ }
238
210
  $on(event, listener, options) {
239
- this.__debug('$on', event, listener, options);
240
-
241
- var set = this.__eventHandlers.get(event);
242
-
211
+ if (isDev) {
212
+ this.__debug("$on", event, listener, options);
213
+ }
214
+ if (isDev) {
215
+ this.__testEventIsDefined(event);
216
+ }
217
+ let set = this.__eventHandlers.get(event);
243
218
  if (!set) {
244
- set = new Set();
245
-
219
+ set = /* @__PURE__ */ new Set();
246
220
  this.__eventHandlers.set(event, set);
247
221
  }
248
-
249
222
  set.add(listener);
250
- this.$el.addEventListener(event, listener, options);
223
+ this.addEventListener(event, listener, options);
251
224
  return () => {
252
225
  this.$off(event, listener, options);
253
226
  };
254
227
  }
255
-
256
228
  $off(event, listener, options) {
257
- this.__debug('$off', event, listener);
258
-
229
+ if (isDev) {
230
+ this.__debug("$off", event, listener);
231
+ }
232
+ if (isDev) {
233
+ this.__testEventIsDefined(event);
234
+ }
259
235
  this.__eventHandlers.get(event).delete(listener);
260
-
261
- this.$el.removeEventListener(event, listener, options);
236
+ this.removeEventListener(event, listener, options);
262
237
  }
263
-
264
- $emit(event) {
265
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
266
- args[_key2 - 1] = arguments[_key2];
238
+ $emit(event, ...args) {
239
+ if (isDev) {
240
+ this.__debug("$emit", event, args);
241
+ }
242
+ if (isDev) {
243
+ this.__testEventIsDefined(event);
267
244
  }
268
-
269
- this.__debug('$emit', event, args);
270
-
271
- this.$el.dispatchEvent(new CustomEvent(event, {
245
+ this.dispatchEvent(new CustomEvent(event, {
272
246
  detail: args
273
247
  }));
274
248
  }
275
-
276
249
  static $factory(nameOrSelector) {
277
250
  if (!nameOrSelector) {
278
- throw new Error('The $factory method requires a component’s name or selector to be specified.');
251
+ throw new Error("The $factory method requires a component\u2019s name or selector to be specified.");
279
252
  }
280
-
281
- return getComponentElements(nameOrSelector).map(el => new this(el).$mount());
253
+ return getComponentElements(nameOrSelector).map((el) => new this(el).$mount());
282
254
  }
283
-
284
255
  }
285
-
286
- _defineProperty(Base, "$isBase", true);
287
-
288
- _defineProperty(Base, "config", void 0);
256
+ export {
257
+ Base as default
258
+ };
@@ -0,0 +1,124 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __reExport = (target, module2, copyDefault, desc) => {
11
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
12
+ for (let key of __getOwnPropNames(module2))
13
+ if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
14
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
15
+ }
16
+ return target;
17
+ };
18
+ var __toCommonJS = /* @__PURE__ */ ((cache) => {
19
+ return (module2, temp) => {
20
+ return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
21
+ };
22
+ })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
23
+
24
+ // packages/js-toolkit/Base/managers/ChildrenManager.js
25
+ var ChildrenManager_exports = {};
26
+ __export(ChildrenManager_exports, {
27
+ default: () => ChildrenManager
28
+ });
29
+ var import_utils = require("../utils.cjs");
30
+ var ChildrenManager = class {
31
+ __base;
32
+ __element;
33
+ __components;
34
+ __eventsManager;
35
+ get registeredNames() {
36
+ return Object.keys(this).filter((key) => !key.startsWith("__"));
37
+ }
38
+ constructor(base, element, components, eventsManager) {
39
+ Object.defineProperties(this, {
40
+ __base: {
41
+ enumerable: false,
42
+ writable: false,
43
+ value: base
44
+ },
45
+ __element: {
46
+ enumerable: false,
47
+ writable: false,
48
+ value: element
49
+ },
50
+ __components: {
51
+ enumerable: false,
52
+ writable: false,
53
+ value: components
54
+ },
55
+ __eventsManager: {
56
+ enumerable: false,
57
+ writable: false,
58
+ value: eventsManager
59
+ }
60
+ });
61
+ }
62
+ registerAll() {
63
+ Object.entries(this.__components).forEach(([name, component]) => this.__register(name, component));
64
+ }
65
+ __register(name, component) {
66
+ Object.defineProperty(this, name, {
67
+ enumerable: true,
68
+ configurable: true,
69
+ get: () => {
70
+ const elements = (0, import_utils.getComponentElements)(name, this.__element);
71
+ if (elements.length === 0) {
72
+ return [];
73
+ }
74
+ return elements.map((element) => this.__getChild(element, component, name)).filter((instance) => instance !== "terminated");
75
+ }
76
+ });
77
+ }
78
+ __getChild(el, ComponentClass, name) {
79
+ if (el.__base__) {
80
+ return el.__base__;
81
+ }
82
+ if ("$isBase" in ComponentClass) {
83
+ const child = new ComponentClass(el);
84
+ Object.defineProperty(child, "$parent", { get: () => this.__base });
85
+ return child;
86
+ }
87
+ return ComponentClass(this.__base).then((module2) => {
88
+ return this.__getChild(el, module2.default ?? module2, name);
89
+ });
90
+ }
91
+ mountAll() {
92
+ this.__triggerHookForAll("$mount");
93
+ }
94
+ updateAll() {
95
+ this.__triggerHookForAll("$update");
96
+ }
97
+ destroyAll() {
98
+ this.__triggerHookForAll("$destroy");
99
+ }
100
+ __triggerHookForAll(hook) {
101
+ this.registeredNames.forEach((name) => {
102
+ this[name].forEach((instance) => {
103
+ if (instance instanceof Promise) {
104
+ instance.then((resolvedInstance) => this.__triggerHook(hook, resolvedInstance, name));
105
+ } else {
106
+ this.__triggerHook(hook, instance, name);
107
+ }
108
+ });
109
+ });
110
+ }
111
+ __triggerHook(hook, instance, name) {
112
+ if (hook === "$update" && !instance.$isMounted) {
113
+ hook = "$mount";
114
+ }
115
+ if (hook === "$update" || hook === "$destroy") {
116
+ this.__eventsManager.unbindChild(name, instance);
117
+ }
118
+ if (hook === "$update" || hook === "$mount") {
119
+ this.__eventsManager.bindChild(name, instance);
120
+ }
121
+ instance[hook]();
122
+ }
123
+ };
124
+ module.exports = __toCommonJS(ChildrenManager_exports);