@studiometa/js-toolkit 2.0.0-alpha.1 → 2.0.0-alpha.10

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 (201) hide show
  1. package/Base/index.d.ts +29 -47
  2. package/Base/index.js +144 -171
  3. package/Base/managers/ChildrenManager.d.ts +6 -6
  4. package/Base/managers/ChildrenManager.js +95 -119
  5. package/Base/managers/EventsManager.d.ts +9 -9
  6. package/Base/managers/EventsManager.js +128 -161
  7. package/Base/managers/OptionsManager.d.ts +50 -5
  8. package/Base/managers/OptionsManager.js +115 -116
  9. package/Base/managers/RefsManager.js +62 -73
  10. package/Base/managers/ServicesManager.d.ts +14 -3
  11. package/Base/managers/ServicesManager.js +78 -77
  12. package/Base/utils.js +5 -8
  13. package/README.md +12 -70
  14. package/decorators/index.js +1 -2
  15. package/decorators/withBreakpointManager.d.ts +4 -4
  16. package/decorators/withBreakpointManager.js +37 -75
  17. package/decorators/withBreakpointObserver.d.ts +2 -2
  18. package/decorators/withBreakpointObserver.js +54 -77
  19. package/decorators/withDrag.d.ts +3 -3
  20. package/decorators/withDrag.js +17 -41
  21. package/decorators/withExtraConfig.d.ts +3 -3
  22. package/decorators/withExtraConfig.js +2 -24
  23. package/decorators/withIntersectionObserver.d.ts +2 -2
  24. package/decorators/withIntersectionObserver.js +17 -56
  25. package/decorators/withMountWhenInView.d.ts +3 -3
  26. package/decorators/withMountWhenInView.js +23 -51
  27. package/helpers/createApp.d.ts +3 -3
  28. package/helpers/createApp.js +10 -12
  29. package/helpers/importOnInteraction.d.ts +3 -3
  30. package/helpers/importOnInteraction.js +7 -8
  31. package/helpers/importWhenIdle.d.ts +3 -3
  32. package/helpers/importWhenIdle.js +7 -8
  33. package/helpers/importWhenVisible.d.ts +3 -3
  34. package/helpers/importWhenVisible.js +9 -16
  35. package/helpers/index.d.ts +1 -3
  36. package/helpers/index.js +1 -4
  37. package/helpers/utils.js +1 -2
  38. package/index.d.ts +14 -4
  39. package/index.js +4 -4
  40. package/index.modern.js +1 -2
  41. package/index.umd.js +1 -2
  42. package/package.json +4 -6
  43. package/services/Service.js +48 -67
  44. package/services/drag.js +143 -179
  45. package/services/index.js +1 -2
  46. package/services/key.js +55 -97
  47. package/services/load.d.ts +1 -1
  48. package/services/load.js +21 -50
  49. package/services/pointer.js +117 -156
  50. package/services/raf.js +36 -64
  51. package/services/resize.js +47 -86
  52. package/services/scroll.js +81 -120
  53. package/utils/collide/boundingRectToCircle.js +7 -6
  54. package/utils/collide/collideCircleCircle.js +1 -2
  55. package/utils/collide/collideCircleRect.js +1 -2
  56. package/utils/collide/collidePointCircle.js +1 -2
  57. package/utils/collide/collidePointRect.js +1 -2
  58. package/utils/collide/collideRectRect.js +1 -2
  59. package/utils/collide/index.js +1 -2
  60. package/utils/css/classes.js +2 -3
  61. package/utils/css/index.js +1 -2
  62. package/utils/css/matrix.js +1 -2
  63. package/utils/css/styles.js +3 -8
  64. package/utils/css/transition.js +67 -140
  65. package/utils/debounce.js +3 -4
  66. package/utils/focusTrap.js +4 -5
  67. package/utils/history.js +13 -20
  68. package/utils/index.d.ts +2 -1
  69. package/utils/index.js +2 -2
  70. package/utils/keyCodes.js +1 -2
  71. package/utils/math/clamp.js +1 -2
  72. package/utils/math/clamp01.js +1 -2
  73. package/utils/math/damp.js +1 -2
  74. package/utils/math/index.js +1 -2
  75. package/utils/math/inertiaFinalValue.js +1 -2
  76. package/utils/math/lerp.js +1 -2
  77. package/utils/math/map.js +1 -2
  78. package/utils/math/round.js +1 -2
  79. package/utils/memoize.d.ts +30 -0
  80. package/utils/memoize.js +30 -0
  81. package/utils/nextFrame.js +4 -9
  82. package/utils/object/autoBind.js +11 -19
  83. package/utils/object/getAllProperties.js +3 -11
  84. package/utils/object/index.js +1 -2
  85. package/utils/object/isObject.js +2 -4
  86. package/utils/string/index.js +1 -2
  87. package/utils/string/withLeadingCharacters.js +1 -2
  88. package/utils/string/withLeadingSlash.js +1 -2
  89. package/utils/string/withTrailingCharacters.js +1 -2
  90. package/utils/string/withTrailingSlash.js +1 -2
  91. package/utils/string/withoutLeadingCharacters.js +1 -2
  92. package/utils/string/withoutLeadingCharactersRecursive.js +1 -2
  93. package/utils/string/withoutLeadingSlash.js +1 -2
  94. package/utils/string/withoutTrailingCharacters.js +1 -2
  95. package/utils/string/withoutTrailingCharactersRecursive.js +1 -2
  96. package/utils/string/withoutTrailingSlash.js +1 -2
  97. package/utils/throttle.js +2 -3
  98. package/Base/index.js.map +0 -1
  99. package/Base/managers/ChildrenManager.js.map +0 -1
  100. package/Base/managers/EventsManager.js.map +0 -1
  101. package/Base/managers/OptionsManager.js.map +0 -1
  102. package/Base/managers/RefsManager.js.map +0 -1
  103. package/Base/managers/ServicesManager.js.map +0 -1
  104. package/Base/utils.js.map +0 -1
  105. package/components/Accordion/Accordion.d.ts +0 -83
  106. package/components/Accordion/Accordion.js +0 -121
  107. package/components/Accordion/Accordion.js.map +0 -1
  108. package/components/Accordion/AccordionItem.d.ts +0 -122
  109. package/components/Accordion/AccordionItem.js +0 -327
  110. package/components/Accordion/AccordionItem.js.map +0 -1
  111. package/components/Accordion/index.d.ts +0 -27
  112. package/components/Accordion/index.js +0 -39
  113. package/components/Accordion/index.js.map +0 -1
  114. package/components/Cursor.d.ts +0 -138
  115. package/components/Cursor.js +0 -167
  116. package/components/Cursor.js.map +0 -1
  117. package/components/Draggable.d.ts +0 -49
  118. package/components/Draggable.js +0 -77
  119. package/components/Draggable.js.map +0 -1
  120. package/components/Modal.d.ts +0 -158
  121. package/components/Modal.js +0 -270
  122. package/components/Modal.js.map +0 -1
  123. package/components/Tabs.d.ts +0 -108
  124. package/components/Tabs.js +0 -195
  125. package/components/Tabs.js.map +0 -1
  126. package/components/index.d.ts +0 -6
  127. package/components/index.js +0 -7
  128. package/components/index.js.map +0 -1
  129. package/decorators/index.js.map +0 -1
  130. package/decorators/withBreakpointManager.js.map +0 -1
  131. package/decorators/withBreakpointObserver.js.map +0 -1
  132. package/decorators/withDrag.js.map +0 -1
  133. package/decorators/withExtraConfig.js.map +0 -1
  134. package/decorators/withIntersectionObserver.js.map +0 -1
  135. package/decorators/withMountWhenInView.js.map +0 -1
  136. package/helpers/createApp.js.map +0 -1
  137. package/helpers/createBase.d.ts +0 -7
  138. package/helpers/createBase.js +0 -7
  139. package/helpers/createBase.js.map +0 -1
  140. package/helpers/defineComponent.d.ts +0 -11
  141. package/helpers/defineComponent.js +0 -68
  142. package/helpers/defineComponent.js.map +0 -1
  143. package/helpers/importOnInteraction.js.map +0 -1
  144. package/helpers/importWhenIdle.js.map +0 -1
  145. package/helpers/importWhenVisible.js.map +0 -1
  146. package/helpers/index.js.map +0 -1
  147. package/helpers/utils.js.map +0 -1
  148. package/index.js.map +0 -1
  149. package/index.modern.js.map +0 -1
  150. package/index.umd.js.map +0 -1
  151. package/services/Service.js.map +0 -1
  152. package/services/drag.js.map +0 -1
  153. package/services/index.js.map +0 -1
  154. package/services/key.js.map +0 -1
  155. package/services/load.js.map +0 -1
  156. package/services/pointer.js.map +0 -1
  157. package/services/raf.js.map +0 -1
  158. package/services/resize.js.map +0 -1
  159. package/services/scroll.js.map +0 -1
  160. package/utils/collide/boundingRectToCircle.js.map +0 -1
  161. package/utils/collide/collideCircleCircle.js.map +0 -1
  162. package/utils/collide/collideCircleRect.js.map +0 -1
  163. package/utils/collide/collidePointCircle.js.map +0 -1
  164. package/utils/collide/collidePointRect.js.map +0 -1
  165. package/utils/collide/collideRectRect.js.map +0 -1
  166. package/utils/collide/index.js.map +0 -1
  167. package/utils/css/classes.js.map +0 -1
  168. package/utils/css/index.js.map +0 -1
  169. package/utils/css/matrix.js.map +0 -1
  170. package/utils/css/styles.js.map +0 -1
  171. package/utils/css/transition.js.map +0 -1
  172. package/utils/debounce.js.map +0 -1
  173. package/utils/focusTrap.js.map +0 -1
  174. package/utils/history.js.map +0 -1
  175. package/utils/index.js.map +0 -1
  176. package/utils/keyCodes.js.map +0 -1
  177. package/utils/math/clamp.js.map +0 -1
  178. package/utils/math/clamp01.js.map +0 -1
  179. package/utils/math/damp.js.map +0 -1
  180. package/utils/math/index.js.map +0 -1
  181. package/utils/math/inertiaFinalValue.js.map +0 -1
  182. package/utils/math/lerp.js.map +0 -1
  183. package/utils/math/map.js.map +0 -1
  184. package/utils/math/round.js.map +0 -1
  185. package/utils/nextFrame.js.map +0 -1
  186. package/utils/object/autoBind.js.map +0 -1
  187. package/utils/object/getAllProperties.js.map +0 -1
  188. package/utils/object/index.js.map +0 -1
  189. package/utils/object/isObject.js.map +0 -1
  190. package/utils/string/index.js.map +0 -1
  191. package/utils/string/withLeadingCharacters.js.map +0 -1
  192. package/utils/string/withLeadingSlash.js.map +0 -1
  193. package/utils/string/withTrailingCharacters.js.map +0 -1
  194. package/utils/string/withTrailingSlash.js.map +0 -1
  195. package/utils/string/withoutLeadingCharacters.js.map +0 -1
  196. package/utils/string/withoutLeadingCharactersRecursive.js.map +0 -1
  197. package/utils/string/withoutLeadingSlash.js.map +0 -1
  198. package/utils/string/withoutTrailingCharacters.js.map +0 -1
  199. package/utils/string/withoutTrailingCharactersRecursive.js.map +0 -1
  200. package/utils/string/withoutTrailingSlash.js.map +0 -1
  201. package/utils/throttle.js.map +0 -1
@@ -1,6 +1,9 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
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
+
4
7
  import usePointer from '../../services/pointer.js';
5
8
  import useRaf from '../../services/raf.js';
6
9
  import useResize from '../../services/resize.js';
@@ -16,99 +19,97 @@ var SERVICES_MAP = {
16
19
  keyed: useKey,
17
20
  loaded: useLoad
18
21
  };
22
+ var SERVICE_NAMES = Object.keys(SERVICES_MAP);
23
+ export default class ServicesManager {
24
+ get __services() {
25
+ return _objectSpread(_objectSpread({}, this.__customServices), SERVICES_MAP);
26
+ }
19
27
 
20
- var ServicesManager = function () {
21
- function ServicesManager(instance) {
22
- _classCallCheck(this, ServicesManager);
23
-
28
+ constructor(instance) {
24
29
  _defineProperty(this, "__base", void 0);
25
30
 
26
- this.__base = instance;
27
- }
31
+ _defineProperty(this, "__customServices", {});
28
32
 
29
- _createClass(ServicesManager, [{
30
- key: "has",
31
- value: function has(service) {
32
- if (!hasMethod(this.__base, service) && !SERVICES_MAP[service]) {
33
- return false;
33
+ Object.defineProperties(this, {
34
+ __base: {
35
+ enumerable: false,
36
+ writable: false,
37
+ value: instance
34
38
  }
39
+ });
40
+ }
35
41
 
36
- var _SERVICES_MAP$service = SERVICES_MAP[service](),
37
- has = _SERVICES_MAP$service.has;
38
-
39
- return has(this.__base.$id);
42
+ has(service) {
43
+ if (!hasMethod(this.__base, service) && !this.__services[service]) {
44
+ return false;
40
45
  }
41
- }, {
42
- key: "enable",
43
- value: function enable(service) {
44
- if (this.has(service)) {
45
- return this.disable.bind(this, service);
46
- }
47
46
 
48
- if (!hasMethod(this.__base, service) || !SERVICES_MAP[service]) {
49
- return function noop() {};
50
- }
47
+ var {
48
+ has
49
+ } = this.__services[service]();
50
+
51
+ return has(this.__base.$id);
52
+ }
53
+
54
+ enable(service) {
55
+ if (this.has(service)) {
56
+ return this.disable.bind(this, service);
57
+ }
51
58
 
52
- var _SERVICES_MAP$service2 = SERVICES_MAP[service](),
53
- add = _SERVICES_MAP$service2.add;
59
+ if (!hasMethod(this.__base, service) || !this.__services[service]) {
60
+ return function noop() {};
61
+ }
54
62
 
55
- var self = this;
63
+ var {
64
+ add
65
+ } = this.__services[service]();
56
66
 
57
- function serviceHandler() {
58
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
59
- args[_key] = arguments[_key];
60
- }
67
+ var self = this;
61
68
 
62
- callMethod.apply(void 0, [self.__base, service].concat(args));
69
+ function serviceHandler() {
70
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
71
+ args[_key] = arguments[_key];
63
72
  }
64
73
 
65
- add(this.__base.$id, serviceHandler);
66
- return this.disable.bind(this, service);
74
+ callMethod(self.__base, service, ...args);
67
75
  }
68
- }, {
69
- key: "enableAll",
70
- value: function enableAll() {
71
- var _this = this;
72
-
73
- return Object.keys(SERVICES_MAP).map(function (serviceName) {
74
- return _this.enable(serviceName);
75
- });
76
- }
77
- }, {
78
- key: "disableAll",
79
- value: function disableAll() {
80
- var _this2 = this;
81
-
82
- Object.keys(SERVICES_MAP).forEach(function (serviceName) {
83
- _this2.disable(serviceName);
84
- });
85
- }
86
- }, {
87
- key: "disable",
88
- value: function disable(service) {
89
- if (!SERVICES_MAP[service]) {
90
- return;
91
- }
92
76
 
93
- var _SERVICES_MAP$service3 = SERVICES_MAP[service](),
94
- remove = _SERVICES_MAP$service3.remove;
77
+ add(this.__base.$id, serviceHandler);
78
+ return this.disable.bind(this, service);
79
+ }
80
+
81
+ enableAll() {
82
+ return Object.keys(this.__services).map(serviceName => this.enable(serviceName));
83
+ }
95
84
 
96
- remove(this.__base.$id);
97
- }
98
- }, {
99
- key: "register",
100
- value: function register(name, useFunction) {
101
- SERVICES_MAP[name] = useFunction;
85
+ disableAll() {
86
+ Object.keys(this.__services).forEach(serviceName => {
87
+ this.disable(serviceName);
88
+ });
89
+ }
90
+
91
+ disable(service) {
92
+ if (!this.__services[service]) {
93
+ return;
102
94
  }
103
- }, {
104
- key: "unregister",
105
- value: function unregister(name) {
106
- delete SERVICES_MAP[name];
95
+
96
+ var {
97
+ remove
98
+ } = this.__services[service]();
99
+
100
+ remove(this.__base.$id);
101
+ }
102
+
103
+ register(name, useFunction) {
104
+ this.__customServices[name] = useFunction;
105
+ }
106
+
107
+ unregister(name) {
108
+ if (SERVICE_NAMES.includes(name)) {
109
+ throw new Error("[ServicesManager] The `".concat(name, "` core service can not be unregistered."));
107
110
  }
108
- }]);
109
111
 
110
- return ServicesManager;
111
- }();
112
+ delete this.__customServices[name];
113
+ }
112
114
 
113
- export { ServicesManager as default };
114
- //# sourceMappingURL=ServicesManager.js.map
115
+ }
package/Base/utils.js CHANGED
@@ -2,13 +2,11 @@ export function hasMethod(obj, name) {
2
2
  return typeof obj[name] === 'function';
3
3
  }
4
4
  export function callMethod(instance, method) {
5
- var _instance$method;
6
-
7
5
  for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
8
6
  args[_key - 2] = arguments[_key];
9
7
  }
10
8
 
11
- instance.__debug.apply(instance, ['callMethod', method].concat(args));
9
+ instance.__debug('callMethod', method, ...args);
12
10
 
13
11
  if (method === 'destroyed' && !instance.$isMounted || method === 'mounted' && instance.$isMounted) {
14
12
  instance.__debug('not', method, 'because the method has already been triggered once.');
@@ -16,15 +14,15 @@ export function callMethod(instance, method) {
16
14
  return instance;
17
15
  }
18
16
 
19
- instance.$emit.apply(instance, [method].concat(args));
17
+ instance.$emit(method, ...args);
20
18
 
21
19
  if (!hasMethod(instance, method)) {
22
20
  return instance;
23
21
  }
24
22
 
25
- (_instance$method = instance[method]).call.apply(_instance$method, [instance].concat(args));
23
+ instance[method].call(instance, ...args);
26
24
 
27
- instance.__debug.apply(instance, [method, instance].concat(args));
25
+ instance.__debug(method, instance, ...args);
28
26
 
29
27
  return instance;
30
28
  }
@@ -42,5 +40,4 @@ export function getComponentElements(nameOrSelector) {
42
40
  }
43
41
 
44
42
  return elements;
45
- }
46
- //# sourceMappingURL=utils.js.map
43
+ }
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # JS Toolkit
2
2
 
3
3
  [![NPM Version](https://img.shields.io/npm/v/@studiometa/js-toolkit.svg?style=flat-square)](https://www.npmjs.com/package/@studiometa/js-toolkit/)
4
- [![Dependency Status](https://img.shields.io/david/studiometa/js-toolkit.svg?label=deps&style=flat-square)](https://david-dm.org/studiometa/js-toolkit)
5
- [![devDependency Status](https://img.shields.io/david/dev/studiometa/js-toolkit.svg?label=devDeps&style=flat-square)](https://david-dm.org/studiometa/js-toolkit?type=dev)
4
+ [![Size](https://img.shields.io/bundlephobia/minzip/@studiometa/js-toolkit?label=size&style=flat-square)](https://bundlephobia.com/package/@studiometa/js-toolkit)
5
+ [![Dependency Status](https://img.shields.io/librariesio/release/npm/@studiometa/js-toolkit?style=flat-square)](https://david-dm.org/studiometa/js-toolkit)
6
6
  ![Codecov](https://img.shields.io/codecov/c/github/studiometa/js-toolkit?style=flat-square)
7
7
 
8
8
  > A set of useful little bits of JavaScript to boost your project! 🚀
@@ -15,29 +15,19 @@ Install the latest version via NPM:
15
15
  npm install @studiometa/js-toolkit
16
16
  ```
17
17
 
18
- The package can be used directly with the [Skypack CDN](https://www.skypack.dev) as follow:
19
-
20
- ```html
21
- <script type="module">
22
- // Import the Base class
23
- import Base from 'https://cdn.skypack.dev/@studiometa/js-toolkit/';
24
- // Import the full toolkit
25
- import * as components from 'https://cdn.skypack.dev/@studiometa/js-toolkit/components';
26
- import * as decorators from 'https://cdn.skypack.dev/@studiometa/js-toolkit/decorators';
27
- import * as services from 'https://cdn.skypack.dev/@studiometa/js-toolkit/services';
28
- import * as utils from 'https://cdn.skypack.dev/@studiometa/js-toolkit/utils';
29
- </script>
30
- ```
31
-
32
18
  ## Usage
33
19
 
34
- ### Modern JS with bundler
35
-
36
- Import the `Base` class to create your components from your `node_modules`:
20
+ Import the `Base` class and extend it to create your components:
37
21
 
38
22
  ```js
39
- import Base from '@studiometa/js-toolkit';
40
- import Modal from '@studiometa/js-toolkit/components/Modal';
23
+ import { Base } from '@studiometa/js-toolkit';
24
+ import Modal from '@studiometa/ui/Modal';
25
+
26
+ class Component {
27
+ static config = {
28
+ name: 'Component',
29
+ }
30
+ }
41
31
 
42
32
  class App extends Base {
43
33
  static config = {
@@ -46,6 +36,7 @@ class App extends Base {
46
36
  debug: true,
47
37
  components: {
48
38
  Modal,
39
+ Component,
49
40
  },
50
41
  refs: ['btn', 'items[]'],
51
42
  options: {
@@ -90,53 +81,4 @@ export default new App(document.querySelector('#app'));
90
81
 
91
82
  Read the [documentation](https://js-toolkit.meta.fr/) to learn more.
92
83
 
93
- ### Modern JS in browser
94
-
95
- Two modern builds are provided for prototyping purpose, they can be used as follow:
96
84
 
97
- ```html
98
- <script type="module">
99
- // Import the Base class
100
- import Base from 'https://cdn.skypack.dev/@studiometa/js-toolkit/';
101
- // Import the full toolkit
102
- import Modal from 'https://cdn.skypack.dev/@studiometa/js-toolkit/components/Modal';
103
- </script>
104
- ```
105
-
106
- ### Legacy JS
107
-
108
- Two UMD builds are also provided to be used in legacy projects.
109
-
110
- ```html
111
- <div id="app">
112
- <button data-ref="btn">Add more</button>
113
- <input data-ref="input" value="0" readonly />
114
- <div data-component="Component"></div>
115
- </div>
116
- <script src="https://unpkg.com/@studiometa/js-toolkit/index.umd.js"></script>
117
- <script>
118
- var Component = Base.defineComponent({
119
- config: {
120
- name: 'Component',
121
- },
122
- });
123
-
124
- Base.createBase(document.querySelector('#app'), {
125
- config: {
126
- name: 'App',
127
- log: true,
128
- components: {
129
- Component: Component,
130
- },
131
- },
132
- mounted: function() {
133
- this.$log('mounted');
134
- },
135
- methods: {
136
- onBtnClick: function() {
137
- this.$refs.input.value = Number(this.$refs.input.value) + 1;
138
- },
139
- },
140
- });
141
- </script>
142
- ```
@@ -4,5 +4,4 @@ import withDrag from './withDrag.js';
4
4
  import withExtraConfig from './withExtraConfig.js';
5
5
  import withIntersectionObserver from './withIntersectionObserver.js';
6
6
  import withMountWhenInView from './withMountWhenInView.js';
7
- export { withBreakpointManager, withBreakpointObserver, withDrag, withExtraConfig, withIntersectionObserver, withMountWhenInView };
8
- //# sourceMappingURL=index.js.map
7
+ export { withBreakpointManager, withBreakpointObserver, withDrag, withExtraConfig, withIntersectionObserver, withMountWhenInView };
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * BreakpointManager class.
3
- * @template {BaseComponent} T
3
+ * @template {BaseConstructor} T
4
4
  * @param {T} BaseClass
5
- * @param {Array<[String, BaseComponent]>} breakpoints
5
+ * @param {Array<[String, BaseConstructor]>} breakpoints
6
6
  * @return {T}
7
7
  */
8
- export default function withBreakpointManager<T extends typeof import("../Base").default>(BaseClass: T, breakpoints: Array<[string, BaseComponent]>): T;
8
+ export default function withBreakpointManager<T extends typeof import("../Base").default>(BaseClass: T, breakpoints: Array<[string, BaseConstructor]>): T;
9
9
  export type Base = import('../Base').default;
10
- export type BaseComponent = import('../Base').BaseComponent;
10
+ export type BaseConstructor = import('../Base').BaseConstructor;
@@ -1,31 +1,14 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
4
- import _get from "@babel/runtime/helpers/get";
5
- import _inherits from "@babel/runtime/helpers/inherits";
6
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
7
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
8
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
9
-
10
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
11
-
12
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
13
-
14
1
  import useResize from '../services/resize.js';
15
2
 
16
3
  function testBreakpoints(breakpoints) {
17
- var _useResize$props = useResize().props(),
18
- breakpoint = _useResize$props.breakpoint;
19
-
20
- breakpoints.forEach(function (_ref) {
21
- var _ref2 = _slicedToArray(_ref, 2),
22
- breakpointKeys = _ref2[0],
23
- instance = _ref2[1];
4
+ var {
5
+ breakpoint
6
+ } = useResize().props();
7
+ breakpoints.forEach(_ref => {
8
+ var [breakpointKeys, instance] = _ref;
24
9
 
25
10
  if (breakpointKeys.includes(breakpoint) && !instance.$isMounted) {
26
- setTimeout(function () {
27
- return instance.$mount();
28
- }, 0);
11
+ setTimeout(() => instance.$mount(), 0);
29
12
  } else if (!breakpointKeys.includes(breakpoint) && instance.$isMounted) {
30
13
  instance.$destroy();
31
14
  }
@@ -33,16 +16,11 @@ function testBreakpoints(breakpoints) {
33
16
  }
34
17
 
35
18
  function mountComponents(instance, breakpoints) {
36
- return breakpoints.map(function (_ref3) {
37
- var _ref4 = _slicedToArray(_ref3, 2),
38
- bk = _ref4[0],
39
- ComponentClass = _ref4[1];
40
-
19
+ return breakpoints.map(_ref2 => {
20
+ var [bk, ComponentClass] = _ref2;
41
21
  var child = new ComponentClass(instance.$el);
42
22
  Object.defineProperty(child, '$parent', {
43
- get: function get() {
44
- return instance.$parent;
45
- }
23
+ get: () => instance.$parent
46
24
  });
47
25
  return [bk, child];
48
26
  });
@@ -58,62 +36,46 @@ export default function withBreakpointManager(BaseClass, breakpoints) {
58
36
  throw new Error('[withBreakpointManager] You must define at least 2 breakpoints.');
59
37
  }
60
38
 
61
- var _useResize = useResize(),
62
- add = _useResize.add,
63
- props = _useResize.props;
39
+ var {
40
+ add,
41
+ props
42
+ } = useResize();
64
43
 
65
44
  if (!props().breakpoint) {
66
45
  throw new Error("The `BreakpointManager` class requires breakpoints to be defined.");
67
46
  }
68
47
 
69
- return function (_BaseClass) {
70
- _inherits(_class, _BaseClass);
71
-
72
- var _super = _createSuper(_class);
73
-
74
- function _class(element) {
75
- var _this;
76
-
77
- _classCallCheck(this, _class);
48
+ return class extends BaseClass {
49
+ constructor(element) {
50
+ super(element);
78
51
 
79
- _this = _super.call(this, element);
80
-
81
- if (!instances.has(_assertThisInitialized(_this))) {
82
- instances.set(_assertThisInitialized(_this), mountComponents(_assertThisInitialized(_this), breakpoints));
52
+ if (!instances.has(this)) {
53
+ instances.set(this, mountComponents(this, breakpoints));
83
54
  }
84
55
 
85
- add("BreakpointManager-".concat(_this.$id), function () {
86
- testBreakpoints(instances.get(_assertThisInitialized(_this)));
56
+ add("BreakpointManager-".concat(this.$id), () => {
57
+ testBreakpoints(instances.get(this));
87
58
  });
88
- _this.instances = instances.get(_assertThisInitialized(_this));
89
- return _possibleConstructorReturn(_this, _assertThisInitialized(_this));
59
+ this.instances = instances.get(this);
60
+ return this;
90
61
  }
91
62
 
92
- _createClass(_class, [{
93
- key: "$mount",
94
- value: function $mount() {
95
- _get(_getPrototypeOf(_class.prototype), "$mount", this).call(this);
63
+ $mount() {
64
+ super.$mount();
65
+ testBreakpoints(instances.get(this));
66
+ return this;
67
+ }
96
68
 
97
- testBreakpoints(instances.get(this));
98
- return this;
69
+ $destroy() {
70
+ if (Array.isArray(instances.get(this))) {
71
+ instances.get(this).forEach(_ref3 => {
72
+ var [, instance] = _ref3;
73
+ instance.$destroy();
74
+ });
99
75
  }
100
- }, {
101
- key: "$destroy",
102
- value: function $destroy() {
103
- if (Array.isArray(instances.get(this))) {
104
- instances.get(this).forEach(function (_ref5) {
105
- var _ref6 = _slicedToArray(_ref5, 2),
106
- instance = _ref6[1];
107
76
 
108
- instance.$destroy();
109
- });
110
- }
111
-
112
- return _get(_getPrototypeOf(_class.prototype), "$destroy", this).call(this);
113
- }
114
- }]);
77
+ return super.$destroy();
78
+ }
115
79
 
116
- return _class;
117
- }(BaseClass);
118
- }
119
- //# sourceMappingURL=withBreakpointManager.js.map
80
+ };
81
+ }
@@ -1,13 +1,13 @@
1
1
  /**
2
2
  * BreakpointObserver class.
3
3
  *
4
- * @template {BaseComponent} T
4
+ * @template {BaseConstructor} T
5
5
  * @param {T} BaseClass The Base class to extend from.
6
6
  * @return {T}
7
7
  */
8
8
  export default function withBreakpointObserver<T extends typeof import("../Base").default>(BaseClass: T): T;
9
9
  export type Base = import('../Base').default;
10
- export type BaseComponent = import('../Base').BaseComponent;
10
+ export type BaseConstructor = import('../Base').BaseConstructor;
11
11
  export type WithBreakpointObserverOptions = {
12
12
  activeBreakpoints?: string;
13
13
  inactiveBreakpoints?: string;