@studiometa/js-toolkit 2.0.0-alpha.8 → 2.0.0-beta.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 (43) hide show
  1. package/Base/index.d.ts +26 -1
  2. package/Base/index.js +66 -15
  3. package/Base/managers/ChildrenManager.js +22 -4
  4. package/Base/managers/EventsManager.js +32 -2
  5. package/Base/managers/OptionsManager.js +17 -1
  6. package/Base/managers/RefsManager.js +22 -4
  7. package/Base/managers/ServicesManager.d.ts +7 -0
  8. package/Base/managers/ServicesManager.js +27 -5
  9. package/Base/utils.d.ts +0 -8
  10. package/Base/utils.js +0 -25
  11. package/README.md +21 -11
  12. package/decorators/index.d.ts +3 -1
  13. package/decorators/index.js +3 -1
  14. package/decorators/withDrag.d.ts +3 -3
  15. package/decorators/withDrag.js +6 -12
  16. package/decorators/withIntersectionObserver.js +1 -4
  17. package/decorators/withMountWhenInView.d.ts +4 -4
  18. package/decorators/withMountWhenInView.js +6 -2
  19. package/decorators/withScrolledInView.d.ts +14 -0
  20. package/decorators/withScrolledInView.js +77 -0
  21. package/decorators/withVue2.d.ts +7 -0
  22. package/decorators/withVue2.js +45 -0
  23. package/index.d.ts +3 -1
  24. package/index.js +2 -2
  25. package/index.modern.js +1 -1
  26. package/index.umd.js +1 -1
  27. package/package.json +1 -1
  28. package/services/drag.d.ts +1 -1
  29. package/services/drag.js +5 -5
  30. package/utils/collide/index.d.ts +4 -4
  31. package/utils/collide/index.js +4 -4
  32. package/utils/history.d.ts +6 -6
  33. package/utils/history.js +6 -2
  34. package/utils/index.d.ts +29 -7
  35. package/utils/index.js +11 -7
  36. package/utils/math/damp.d.ts +6 -5
  37. package/utils/math/damp.js +2 -1
  38. package/utils/math/index.d.ts +2 -1
  39. package/utils/math/index.js +2 -1
  40. package/utils/math/inertiaFinalValue.d.ts +2 -2
  41. package/utils/math/inertiaFinalValue.js +4 -4
  42. package/utils/scrollTo.d.ts +11 -0
  43. package/utils/scrollTo.js +75 -0
package/Base/index.d.ts CHANGED
@@ -64,6 +64,13 @@ export default class Base {
64
64
  * @type {Boolean}
65
65
  */
66
66
  $isMounted: boolean;
67
+ /**
68
+ * Store the event handlers.
69
+ *
70
+ * @private
71
+ * @type {Map<string, Set<EventListenerOrEventListenerObject>>}
72
+ */
73
+ private __eventHandlers;
67
74
  /**
68
75
  * Get the root instance of the app.
69
76
  * @return {Base}
@@ -126,9 +133,27 @@ export default class Base {
126
133
  /**
127
134
  * Small helper to debug information.
128
135
  *
136
+ * @private
129
137
  * @return {(...args:any) => void}
130
138
  */
131
- get __debug(): (...args: any) => void;
139
+ private get __debug();
140
+ /**
141
+ * Call an instance method and emit corresponding events.
142
+ *
143
+ * @private
144
+ * @param {string} method
145
+ * @param {any[]} args
146
+ * @return {void}
147
+ */
148
+ private __callMethod;
149
+ /**
150
+ * Test if the given event has been bound to the instance.
151
+ *
152
+ * @private
153
+ * @param {string} event The event's name.
154
+ * @return {boolean} Wether the given event has been bound or not.
155
+ */
156
+ private __hasEvent;
132
157
  /**
133
158
  * Trigger the `mounted` callback.
134
159
  * @return {this}
package/Base/index.js CHANGED
@@ -4,7 +4,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
4
4
 
5
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
6
 
7
- import { callMethod, getComponentElements } from './utils.js';
7
+ import { getComponentElements } from './utils.js';
8
8
  import ChildrenManager from './managers/ChildrenManager.js';
9
9
  import RefsManager from './managers/RefsManager.js';
10
10
  import ServicesManager from './managers/ServicesManager.js';
@@ -85,6 +85,36 @@ export default class Base {
85
85
  return this.__options.debug && typeof window.__DEV__ !== 'undefined' && window.__DEV__ ? window.console.log.bind(window, "[debug] [".concat(this.$id, "]")) : noop;
86
86
  }
87
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;
99
+ }
100
+
101
+ this.$emit(method, ...args);
102
+
103
+ if (typeof this[method] !== 'function') {
104
+ return;
105
+ }
106
+
107
+ this[method].call(this, ...args);
108
+
109
+ this.__debug(method, this, ...args);
110
+ }
111
+
112
+ __hasEvent(event) {
113
+ var eventHandlers = this.__eventHandlers.get(event);
114
+
115
+ return eventHandlers && eventHandlers.size > 0;
116
+ }
117
+
88
118
  constructor(element) {
89
119
  _defineProperty(this, "$parent", null);
90
120
 
@@ -94,6 +124,8 @@ export default class Base {
94
124
 
95
125
  _defineProperty(this, "$isMounted", false);
96
126
 
127
+ _defineProperty(this, "__eventHandlers", new Map());
128
+
97
129
  _defineProperty(this, "__services", void 0);
98
130
 
99
131
  _defineProperty(this, "__refs", void 0);
@@ -152,7 +184,9 @@ export default class Base {
152
184
 
153
185
  this.$services.enableAll();
154
186
  this.$children.mountAll();
155
- callMethod(this, 'mounted');
187
+
188
+ this.__callMethod('mounted');
189
+
156
190
  this.$isMounted = true;
157
191
  return this;
158
192
  }
@@ -166,7 +200,9 @@ export default class Base {
166
200
  this.$refs.registerAll();
167
201
  this.$services.enableAll();
168
202
  this.$children.updateAll();
169
- callMethod(this, 'updated');
203
+
204
+ this.__callMethod('updated');
205
+
170
206
  return this;
171
207
  }
172
208
 
@@ -178,7 +214,9 @@ export default class Base {
178
214
  this.$refs.unregisterAll();
179
215
  this.$services.disableAll();
180
216
  this.$children.destroyAll();
181
- callMethod(this, 'destroyed');
217
+
218
+ this.__callMethod('destroyed');
219
+
182
220
  this.$isMounted = false;
183
221
  return this;
184
222
  }
@@ -187,7 +225,9 @@ export default class Base {
187
225
  this.__debug('$terminate');
188
226
 
189
227
  this.$destroy();
190
- callMethod(this, 'terminated');
228
+
229
+ this.__callMethod('terminated');
230
+
191
231
  Object.defineProperty(this.$el, '__base__', {
192
232
  value: 'terminated',
193
233
  configurable: false,
@@ -195,17 +235,18 @@ export default class Base {
195
235
  });
196
236
  }
197
237
 
198
- static $factory(nameOrSelector) {
199
- if (!nameOrSelector) {
200
- throw new Error('The $factory method requires a component’s name or selector to be specified.');
201
- }
202
-
203
- return getComponentElements(nameOrSelector).map(el => new this(el).$mount());
204
- }
205
-
206
238
  $on(event, listener, options) {
207
239
  this.__debug('$on', event, listener, options);
208
240
 
241
+ var set = this.__eventHandlers.get(event);
242
+
243
+ if (!set) {
244
+ set = new Set();
245
+
246
+ this.__eventHandlers.set(event, set);
247
+ }
248
+
249
+ set.add(listener);
209
250
  this.$el.addEventListener(event, listener, options);
210
251
  return () => {
211
252
  this.$off(event, listener, options);
@@ -215,12 +256,14 @@ export default class Base {
215
256
  $off(event, listener, options) {
216
257
  this.__debug('$off', event, listener);
217
258
 
259
+ this.__eventHandlers.get(event).delete(listener);
260
+
218
261
  this.$el.removeEventListener(event, listener, options);
219
262
  }
220
263
 
221
264
  $emit(event) {
222
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
223
- args[_key - 1] = arguments[_key];
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];
224
267
  }
225
268
 
226
269
  this.__debug('$emit', event, args);
@@ -230,6 +273,14 @@ export default class Base {
230
273
  }));
231
274
  }
232
275
 
276
+ static $factory(nameOrSelector) {
277
+ if (!nameOrSelector) {
278
+ throw new Error('The $factory method requires a component’s name or selector to be specified.');
279
+ }
280
+
281
+ return getComponentElements(nameOrSelector).map(el => new this(el).$mount());
282
+ }
283
+
233
284
  }
234
285
 
235
286
  _defineProperty(Base, "$isBase", true);
@@ -14,10 +14,28 @@ export default class ChildrenManager {
14
14
 
15
15
  _defineProperty(this, "__eventsManager", void 0);
16
16
 
17
- this.__base = base;
18
- this.__element = element;
19
- this.__components = components;
20
- this.__eventsManager = eventsManager;
17
+ Object.defineProperties(this, {
18
+ __base: {
19
+ enumerable: false,
20
+ writable: false,
21
+ value: base
22
+ },
23
+ __element: {
24
+ enumerable: false,
25
+ writable: false,
26
+ value: element
27
+ },
28
+ __components: {
29
+ enumerable: false,
30
+ writable: false,
31
+ value: components
32
+ },
33
+ __eventsManager: {
34
+ enumerable: false,
35
+ writable: false,
36
+ value: eventsManager
37
+ }
38
+ });
21
39
  }
22
40
 
23
41
  registerAll() {
@@ -59,8 +59,38 @@ export default class EventsManager {
59
59
  }
60
60
  });
61
61
 
62
- this.__rootElement = rootElement;
63
- this.__base = base;
62
+ Object.defineProperties(this, {
63
+ __rootElement: {
64
+ enumerable: false,
65
+ writable: false,
66
+ value: rootElement
67
+ },
68
+ __base: {
69
+ enumerable: false,
70
+ writable: false,
71
+ value: base
72
+ },
73
+ __methodsCache: {
74
+ enumerable: false,
75
+ writable: false,
76
+ value: this.__methodsCache
77
+ },
78
+ __rootElementHandler: {
79
+ enumerable: false,
80
+ writable: false,
81
+ value: this.__rootElementHandler
82
+ },
83
+ __refsHandler: {
84
+ enumerable: false,
85
+ writable: false,
86
+ value: this.__refsHandler
87
+ },
88
+ __childrenHandler: {
89
+ enumerable: false,
90
+ writable: false,
91
+ value: this.__childrenHandler
92
+ }
93
+ });
64
94
  }
65
95
 
66
96
  __manageRef(name, elements) {
@@ -23,7 +23,23 @@ export default class OptionsManager {
23
23
 
24
24
  _defineProperty(this, "log", false);
25
25
 
26
- this.__element = element;
26
+ Object.defineProperties(this, {
27
+ __element: {
28
+ enumerable: false,
29
+ writable: false,
30
+ value: element
31
+ },
32
+ __values: {
33
+ enumerable: false,
34
+ writable: false,
35
+ value: this.__values
36
+ },
37
+ __defaultValues: {
38
+ enumerable: false,
39
+ writable: false,
40
+ value: this.__defaultValues
41
+ }
42
+ });
27
43
  this.name = baseConfig.name;
28
44
  schema.debug = {
29
45
  type: Boolean,
@@ -9,10 +9,28 @@ export default class RefsManager {
9
9
 
10
10
  _defineProperty(this, "__eventsManager", void 0);
11
11
 
12
- this.__element = element;
13
- this.__refs = refs;
14
- this.__base = base;
15
- this.__eventsManager = eventsManager;
12
+ Object.defineProperties(this, {
13
+ __element: {
14
+ enumerable: false,
15
+ writable: false,
16
+ value: element
17
+ },
18
+ __refs: {
19
+ enumerable: false,
20
+ writable: false,
21
+ value: refs
22
+ },
23
+ __base: {
24
+ enumerable: false,
25
+ writable: false,
26
+ value: base
27
+ },
28
+ __eventsManager: {
29
+ enumerable: false,
30
+ writable: false,
31
+ value: eventsManager
32
+ }
33
+ });
16
34
  }
17
35
 
18
36
  registerAll() {
@@ -56,6 +56,13 @@ export default class ServicesManager {
56
56
  * @return {void}
57
57
  */
58
58
  disable(service: string): void;
59
+ /**
60
+ * Toggle a service.
61
+ * @param {string} service The name of the service.
62
+ * @param {boolean} [force] The state to force.
63
+ * @return {void}
64
+ */
65
+ toggle(service: string, force?: boolean): void;
59
66
  /**
60
67
  * Register a new service to be enabled/disabled.
61
68
  *
@@ -10,7 +10,7 @@ import useResize from '../../services/resize.js';
10
10
  import useScroll from '../../services/scroll.js';
11
11
  import useKey from '../../services/key.js';
12
12
  import useLoad from '../../services/load.js';
13
- import { hasMethod, callMethod } from '../utils.js';
13
+ import { hasMethod } from '../utils.js';
14
14
  var SERVICES_MAP = {
15
15
  scrolled: useScroll,
16
16
  resized: useResize,
@@ -30,11 +30,17 @@ export default class ServicesManager {
30
30
 
31
31
  _defineProperty(this, "__customServices", {});
32
32
 
33
- this.__base = instance;
33
+ Object.defineProperties(this, {
34
+ __base: {
35
+ enumerable: false,
36
+ writable: false,
37
+ value: instance
38
+ }
39
+ });
34
40
  }
35
41
 
36
42
  has(service) {
37
- if (!hasMethod(this.__base, service) && !this.__services[service]) {
43
+ if (!((hasMethod(this.__base, service) || this.__base.__hasEvent(service)) && this.__services[service])) {
38
44
  return false;
39
45
  }
40
46
 
@@ -50,7 +56,7 @@ export default class ServicesManager {
50
56
  return this.disable.bind(this, service);
51
57
  }
52
58
 
53
- if (!hasMethod(this.__base, service) || !this.__services[service]) {
59
+ if (!(hasMethod(this.__base, service) || this.__base.__hasEvent(service)) || !this.__services[service]) {
54
60
  return function noop() {};
55
61
  }
56
62
 
@@ -65,7 +71,7 @@ export default class ServicesManager {
65
71
  args[_key] = arguments[_key];
66
72
  }
67
73
 
68
- callMethod(self.__base, service, ...args);
74
+ self.__base.__callMethod(service, ...args);
69
75
  }
70
76
 
71
77
  add(this.__base.$id, serviceHandler);
@@ -94,6 +100,22 @@ export default class ServicesManager {
94
100
  remove(this.__base.$id);
95
101
  }
96
102
 
103
+ toggle(service, force) {
104
+ if (typeof force !== 'undefined') {
105
+ if (force && !this.has(service)) {
106
+ this.enable(service);
107
+ }
108
+
109
+ if (!force && this.has(service)) {
110
+ this.disable(service);
111
+ }
112
+ } else if (this.has(service)) {
113
+ this.disable(service);
114
+ } else {
115
+ this.enable(service);
116
+ }
117
+ }
118
+
97
119
  register(name, useFunction) {
98
120
  this.__customServices[name] = useFunction;
99
121
  }
package/Base/utils.d.ts CHANGED
@@ -9,14 +9,6 @@
9
9
  * @return {Boolean}
10
10
  */
11
11
  export function hasMethod(obj: any, name: string): boolean;
12
- /**
13
- * Call the given method while applying the given arguments.
14
- *
15
- * @param {Base} instance The Base instance on which to trigger the method.
16
- * @param {String} method The method to call.
17
- * @param {...any} args The arguments to pass to the method.
18
- */
19
- export function callMethod(instance: Base, method: string, ...args: any[]): import("./index.js").default;
20
12
  /**
21
13
  * Get a list of elements based on the name of a component.
22
14
  *
package/Base/utils.js CHANGED
@@ -1,31 +1,6 @@
1
1
  export function hasMethod(obj, name) {
2
2
  return typeof obj[name] === 'function';
3
3
  }
4
- export function callMethod(instance, method) {
5
- for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
6
- args[_key - 2] = arguments[_key];
7
- }
8
-
9
- instance.__debug('callMethod', method, ...args);
10
-
11
- if (method === 'destroyed' && !instance.$isMounted || method === 'mounted' && instance.$isMounted) {
12
- instance.__debug('not', method, 'because the method has already been triggered once.');
13
-
14
- return instance;
15
- }
16
-
17
- instance.$emit(method, ...args);
18
-
19
- if (!hasMethod(instance, method)) {
20
- return instance;
21
- }
22
-
23
- instance[method].call(instance, ...args);
24
-
25
- instance.__debug(method, instance, ...args);
26
-
27
- return instance;
28
- }
29
4
  export function getComponentElements(nameOrSelector) {
30
5
  var element = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document;
31
6
  var selector = "[data-component=\"".concat(nameOrSelector, "\"]");
package/README.md CHANGED
@@ -15,27 +15,31 @@ Install the latest version via NPM:
15
15
  npm install @studiometa/js-toolkit
16
16
  ```
17
17
 
18
+ ## Concept
19
+
20
+ [] todo
21
+
18
22
  ## Usage
19
23
 
20
24
  Import the `Base` class and extend it to create your components:
21
25
 
22
26
  ```js
23
- import { Base } from '@studiometa/js-toolkit';
24
- import Modal from '@studiometa/ui/Modal';
27
+ import { Base, createApp } from '@studiometa/js-toolkit';
25
28
 
26
- class Component {
29
+ class Component extends Base {
27
30
  static config = {
28
31
  name: 'Component',
29
32
  }
33
+
34
+ sayHello() {
35
+ console.log('Hello!');
36
+ }
30
37
  }
31
38
 
32
39
  class App extends Base {
33
40
  static config = {
34
41
  name: 'App',
35
- log: true,
36
- debug: true,
37
42
  components: {
38
- Modal,
39
43
  Component,
40
44
  },
41
45
  refs: ['btn', 'items[]'],
@@ -51,16 +55,16 @@ class App extends Base {
51
55
  // Options
52
56
  this.$options.name; // 'App'
53
57
  this.$options.log; // true
54
- this.$options.debug; // true
58
+ this.$options.debug; // false
55
59
  this.$options.foo // ''
56
60
  this.$options.bar // 'bar'
57
61
 
58
62
  // Children
59
- this.$children.Modal; // Array<Modal>
63
+ this.$children.Component; // Array<Component>
60
64
 
61
65
  // DOM references
62
66
  this.$refs.btn; // <button data-ref="btn"></button>
63
- this.$refs.items; // <li data-ref="items[]"></li>
67
+ this.$refs.items[0]; // <li data-ref="items[]"></li>
64
68
  }
65
69
 
66
70
  destroyed() {
@@ -76,9 +80,15 @@ class App extends Base {
76
80
  }
77
81
  }
78
82
 
79
- export default new App(document.querySelector('#app'));
83
+ export default createApp(App, document.body);
80
84
  ```
81
85
 
82
- Read the [documentation](https://js-toolkit.meta.fr/) to learn more.
86
+ Read the [documentation](https://js-toolkit.studiometa.dev/) to learn more.
87
+
88
+ ## Contribution
89
+
90
+ This projects follows the [Git Flow](https://github.com/petervanderdoes/gitflow-avh) methodology to manage its branches and features.
83
91
 
92
+ The packages from this project are managed with NPM workspaces.
84
93
 
94
+ The files are linted with ESLint, type checked with TypeScript and formatted with Prettier.
@@ -4,4 +4,6 @@ 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 };
7
+ import withScrolledInView from "./withScrolledInView.js";
8
+ import withVue2 from "./withVue2.js";
9
+ export { withBreakpointManager, withBreakpointObserver, withDrag, withExtraConfig, withIntersectionObserver, withMountWhenInView, withScrolledInView, withVue2 };
@@ -4,4 +4,6 @@ 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 };
7
+ import withScrolledInView from './withScrolledInView.js';
8
+ import withVue2 from './withVue2.js';
9
+ export { withBreakpointManager, withBreakpointObserver, withDrag, withExtraConfig, withIntersectionObserver, withMountWhenInView, withScrolledInView, withVue2 };
@@ -4,7 +4,7 @@
4
4
  * @typedef {import('../services/drag').DragServiceOptions} DragServiceOptions
5
5
  */
6
6
  /**
7
- * @typedef {DragServiceOptions & { target: (this:Base) => HTMLElement }} DragDecoratorOptions
7
+ * @typedef {DragServiceOptions & { target?: (this:Base, Base) => HTMLElement }} DragDecoratorOptions
8
8
  */
9
9
  /**
10
10
  * Add dragging capabilities to a component.
@@ -14,10 +14,10 @@
14
14
  * @param {DragDecoratorOptions} options
15
15
  * @return {T}
16
16
  */
17
- export default function withDrag<T extends typeof import("../Base").default>(BaseClass: T, options?: DragDecoratorOptions): T;
17
+ export default function withDrag<T extends typeof import("../Base").default>(BaseClass: T, { target, ...options }?: DragDecoratorOptions): T;
18
18
  export type Base = import('../Base').default;
19
19
  export type BaseConstructor = import('../Base').BaseConstructor;
20
20
  export type DragServiceOptions = import('../services/drag').DragServiceOptions;
21
21
  export type DragDecoratorOptions = import("../services/drag.js").DragServiceOptions & {
22
- target: (this: Base) => HTMLElement;
22
+ target?: (this: import("../Base").default, Base: any) => HTMLElement;
23
23
  };
@@ -2,23 +2,17 @@ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProper
2
2
  var _excluded = ["target"];
3
3
  import useDrag from '../services/drag.js';
4
4
  export default function withDrag(BaseClass) {
5
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
6
- target() {
7
- return this.$el;
8
- }
5
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
6
+ {
7
+ target = instance => instance.$el
8
+ } = _ref,
9
+ options = _objectWithoutProperties(_ref, _excluded);
9
10
 
10
- };
11
11
  return class extends BaseClass {
12
12
  constructor(el) {
13
13
  super(el);
14
14
  this.$on('mounted', () => {
15
- var {
16
- target
17
- } = options,
18
- otherOptions = _objectWithoutProperties(options, _excluded);
19
-
20
- var boundUseDrag = useDrag.bind(undefined, target.call(this), otherOptions);
21
- this.$services.register('dragged', boundUseDrag);
15
+ this.$services.register('dragged', useDrag.bind(undefined, target.call(this, this), options));
22
16
  this.$services.enable('dragged');
23
17
  });
24
18
  this.$on('destroyed', () => {
@@ -23,10 +23,7 @@ export default function withIntersectionObserver(BaseClass) {
23
23
  }
24
24
 
25
25
  this.$observer = new IntersectionObserver(entries => {
26
- this.__debug('intersected', entries);
27
-
28
- this.$emit('intersected', entries);
29
- this.intersected(entries);
26
+ this.__callMethod('intersected', entries);
30
27
  }, _objectSpread(_objectSpread({}, defaultOptions), this.$options.intersectionObserver || {}));
31
28
  this.$on('mounted', () => {
32
29
  this.$observer.observe(this.$el);
@@ -5,7 +5,7 @@
5
5
  */
6
6
  /**
7
7
  * @typedef {Object} WithMountWhenInViewOptions
8
- * @property {Object} intersectionObserver
8
+ * @property {IntersectionObserverInit} intersectionObserver
9
9
  */
10
10
  /**
11
11
  * @typedef {Object} WithMountWhenInViewInterface
@@ -17,15 +17,15 @@
17
17
  *
18
18
  * @template {BaseConstructor} T
19
19
  * @param {T} BaseClass The Base class to extend.
20
- * @param {Object} [defaultOptions] The options for the IntersectionObserver instance.
20
+ * @param {IntersectionObserverInit} [defaultOptions] The options for the IntersectionObserver instance.
21
21
  * @return {T}
22
22
  */
23
- export default function withMountWhenInView<T extends typeof import("../Base").default>(BaseClass: T, defaultOptions?: any): T;
23
+ export default function withMountWhenInView<T extends typeof import("../Base").default>(BaseClass: T, defaultOptions?: IntersectionObserverInit): T;
24
24
  export type Base = import('../Base').default;
25
25
  export type BaseOptions = import('../Base').BaseOptions;
26
26
  export type BaseConstructor = import('../Base').BaseConstructor;
27
27
  export type WithMountWhenInViewOptions = {
28
- intersectionObserver: any;
28
+ intersectionObserver: IntersectionObserverInit;
29
29
  };
30
30
  export type WithMountWhenInViewInterface = {
31
31
  terminated: () => void;
@@ -6,6 +6,10 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
6
6
 
7
7
  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; }
8
8
 
9
+ function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
10
+
11
+ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
12
+
9
13
  export default function withMountWhenInView(BaseClass) {
10
14
  var _class, _isVisible, _observer, _temp, _BaseClass$config$nam, _BaseClass$config, _BaseClass$config2;
11
15
 
@@ -16,12 +20,12 @@ export default function withMountWhenInView(BaseClass) {
16
20
  constructor(element) {
17
21
  super(element);
18
22
 
19
- _isVisible.set(this, {
23
+ _classPrivateFieldInitSpec(this, _isVisible, {
20
24
  writable: true,
21
25
  value: false
22
26
  });
23
27
 
24
- _observer.set(this, {
28
+ _classPrivateFieldInitSpec(this, _observer, {
25
29
  writable: true,
26
30
  value: void 0
27
31
  });