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