@studiometa/js-toolkit 2.0.0-beta.8 → 2.0.0-rc.2

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