@studiometa/js-toolkit 2.0.0-alpha.8 → 2.0.0-beta.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.
- package/Base/index.d.ts +53 -2
- package/Base/index.js +153 -46
- package/Base/managers/ChildrenManager.js +22 -4
- package/Base/managers/EventsManager.d.ts +3 -1
- package/Base/managers/EventsManager.js +38 -4
- package/Base/managers/OptionsManager.d.ts +2 -0
- package/Base/managers/OptionsManager.js +17 -1
- package/Base/managers/RefsManager.d.ts +2 -0
- package/Base/managers/RefsManager.js +27 -4
- package/Base/managers/ServicesManager.d.ts +36 -4
- package/Base/managers/ServicesManager.js +33 -7
- package/Base/utils.d.ts +0 -8
- package/Base/utils.js +0 -25
- package/README.md +13 -60
- package/decorators/index.d.ts +8 -7
- package/decorators/index.js +8 -7
- package/decorators/withBreakpointObserver.js +2 -2
- package/decorators/withDrag.d.ts +3 -3
- package/decorators/withDrag.js +14 -14
- package/decorators/withIntersectionObserver.js +5 -7
- package/decorators/withMountWhenInView.d.ts +4 -4
- package/decorators/withMountWhenInView.js +13 -6
- package/decorators/withScrolledInView.d.ts +17 -0
- package/decorators/withScrolledInView.js +94 -0
- package/decorators/withVue2.d.ts +7 -0
- package/decorators/withVue2.js +45 -0
- package/helpers/index.d.ts +4 -5
- package/helpers/index.js +4 -5
- package/index.d.ts +4 -19
- package/index.js +4 -5
- package/index.modern.js +1 -1
- package/index.umd.js +1 -1
- package/package.json +1 -1
- package/services/Service.d.ts +22 -17
- package/services/Service.js +12 -7
- package/services/drag.d.ts +5 -19
- package/services/drag.js +82 -105
- package/services/index.d.ts +13 -10
- package/services/index.js +7 -8
- package/services/key.d.ts +4 -13
- package/services/key.js +55 -56
- package/services/load.d.ts +3 -13
- package/services/load.js +32 -26
- package/services/pointer.d.ts +4 -13
- package/services/pointer.js +61 -64
- package/services/raf.d.ts +3 -13
- package/services/raf.js +22 -25
- package/services/resize.d.ts +3 -13
- package/services/resize.js +48 -30
- package/services/scroll.d.ts +3 -13
- package/services/scroll.js +65 -61
- package/utils/collide/index.d.ts +6 -7
- package/utils/collide/index.js +6 -7
- package/utils/css/index.d.ts +4 -5
- package/utils/css/index.js +6 -5
- package/utils/css/transition.js +2 -2
- package/utils/history.d.ts +6 -6
- package/utils/history.js +8 -4
- package/utils/index.d.ts +11 -13
- package/utils/index.js +11 -13
- package/utils/math/damp.d.ts +6 -5
- package/utils/math/damp.js +2 -1
- package/utils/math/ease.d.ts +78 -0
- package/utils/math/ease.js +41 -0
- package/utils/math/index.d.ts +8 -7
- package/utils/math/index.js +8 -7
- package/utils/math/inertiaFinalValue.d.ts +2 -2
- package/utils/math/inertiaFinalValue.js +4 -4
- package/utils/object/getAllProperties.js +1 -1
- package/utils/object/index.d.ts +3 -4
- package/utils/object/index.js +3 -4
- package/utils/scrollTo.d.ts +11 -0
- package/utils/scrollTo.js +75 -0
- package/utils/string/index.d.ts +10 -11
- package/utils/string/index.js +10 -11
package/Base/index.d.ts
CHANGED
|
@@ -14,13 +14,14 @@
|
|
|
14
14
|
* @property {Boolean} [debug]
|
|
15
15
|
* @property {Boolean} [log]
|
|
16
16
|
* @property {String[]} [refs]
|
|
17
|
+
* @property {String[]} [emits]
|
|
17
18
|
* @property {BaseConfigComponents} [components]
|
|
18
19
|
* @property {BaseConfigOptions} [options]
|
|
19
20
|
*/
|
|
20
21
|
/**
|
|
21
22
|
* Base class.
|
|
22
23
|
*/
|
|
23
|
-
export default class Base {
|
|
24
|
+
export default class Base extends EventTarget {
|
|
24
25
|
/**
|
|
25
26
|
* This is a Base instance.
|
|
26
27
|
* @type {Boolean}
|
|
@@ -64,6 +65,13 @@ export default class Base {
|
|
|
64
65
|
* @type {Boolean}
|
|
65
66
|
*/
|
|
66
67
|
$isMounted: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Store the event handlers.
|
|
70
|
+
*
|
|
71
|
+
* @private
|
|
72
|
+
* @type {Map<string, Set<EventListenerOrEventListenerObject>>}
|
|
73
|
+
*/
|
|
74
|
+
private __eventHandlers;
|
|
67
75
|
/**
|
|
68
76
|
* Get the root instance of the app.
|
|
69
77
|
* @return {Base}
|
|
@@ -126,9 +134,27 @@ export default class Base {
|
|
|
126
134
|
/**
|
|
127
135
|
* Small helper to debug information.
|
|
128
136
|
*
|
|
137
|
+
* @private
|
|
129
138
|
* @return {(...args:any) => void}
|
|
130
139
|
*/
|
|
131
|
-
get __debug()
|
|
140
|
+
private get __debug();
|
|
141
|
+
/**
|
|
142
|
+
* Call an instance method and emit corresponding events.
|
|
143
|
+
*
|
|
144
|
+
* @private
|
|
145
|
+
* @param {string} method
|
|
146
|
+
* @param {any[]} args
|
|
147
|
+
* @return {void}
|
|
148
|
+
*/
|
|
149
|
+
private __callMethod;
|
|
150
|
+
/**
|
|
151
|
+
* Test if the given event has been bound to the instance.
|
|
152
|
+
*
|
|
153
|
+
* @private
|
|
154
|
+
* @param {string} event The event's name.
|
|
155
|
+
* @return {boolean} Wether the given event has been bound or not.
|
|
156
|
+
*/
|
|
157
|
+
private __hasEvent;
|
|
132
158
|
/**
|
|
133
159
|
* Trigger the `mounted` callback.
|
|
134
160
|
* @return {this}
|
|
@@ -149,6 +175,30 @@ export default class Base {
|
|
|
149
175
|
* @return {void}
|
|
150
176
|
*/
|
|
151
177
|
$terminate(): void;
|
|
178
|
+
/**
|
|
179
|
+
* Test if the given event is configured and warn otherwise.
|
|
180
|
+
*
|
|
181
|
+
* @private
|
|
182
|
+
* @param {string} event The event name.
|
|
183
|
+
* @returns {void}
|
|
184
|
+
*/
|
|
185
|
+
private __testEventIsDefined;
|
|
186
|
+
/**
|
|
187
|
+
* Add an emitted event.
|
|
188
|
+
*
|
|
189
|
+
* @private
|
|
190
|
+
* @param {string} event The event name.
|
|
191
|
+
* @returns {void}
|
|
192
|
+
*/
|
|
193
|
+
private __addEmits;
|
|
194
|
+
/**
|
|
195
|
+
* Remove an emitted event.
|
|
196
|
+
*
|
|
197
|
+
* @private
|
|
198
|
+
* @param {string} event The event name.
|
|
199
|
+
* @returns {void}
|
|
200
|
+
*/
|
|
201
|
+
private __removeEmits;
|
|
152
202
|
/**
|
|
153
203
|
* Bind a listener function to an event.
|
|
154
204
|
*
|
|
@@ -208,6 +258,7 @@ export type BaseConfig = {
|
|
|
208
258
|
debug?: boolean;
|
|
209
259
|
log?: boolean;
|
|
210
260
|
refs?: string[];
|
|
261
|
+
emits?: string[];
|
|
211
262
|
components?: BaseConfigComponents;
|
|
212
263
|
options?: BaseConfigOptions;
|
|
213
264
|
};
|
package/Base/index.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
|
|
3
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
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
4
|
|
|
5
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
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
6
|
|
|
7
|
-
import {
|
|
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';
|
|
11
11
|
import EventsManager from './managers/EventsManager.js';
|
|
12
12
|
import OptionsManager from './managers/OptionsManager.js';
|
|
13
13
|
var id = 0;
|
|
14
|
+
var isDev = typeof __DEV__ !== 'undefined' && __DEV__;
|
|
14
15
|
|
|
15
16
|
function noop() {}
|
|
16
17
|
|
|
17
|
-
export default class Base {
|
|
18
|
+
export default class Base extends EventTarget {
|
|
18
19
|
get $root() {
|
|
19
20
|
if (!this.$parent) {
|
|
20
21
|
return this;
|
|
@@ -47,6 +48,10 @@ export default class Base {
|
|
|
47
48
|
config.options = _objectSpread(_objectSpread({}, proto.constructor.config.options), config.options);
|
|
48
49
|
}
|
|
49
50
|
|
|
51
|
+
if (proto.constructor.config.emits && config.emits) {
|
|
52
|
+
config.emits = [...proto.constructor.config.emits, ...config.emits];
|
|
53
|
+
}
|
|
54
|
+
|
|
50
55
|
proto = Object.getPrototypeOf(proto);
|
|
51
56
|
}
|
|
52
57
|
|
|
@@ -54,27 +59,19 @@ export default class Base {
|
|
|
54
59
|
}
|
|
55
60
|
|
|
56
61
|
get $services() {
|
|
57
|
-
|
|
58
|
-
this.$emit('get:services', services);
|
|
59
|
-
return services;
|
|
62
|
+
return this.__services;
|
|
60
63
|
}
|
|
61
64
|
|
|
62
65
|
get $refs() {
|
|
63
|
-
|
|
64
|
-
this.$emit('get:refs', refs);
|
|
65
|
-
return refs;
|
|
66
|
+
return this.__refs;
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
get $options() {
|
|
69
|
-
|
|
70
|
-
this.$emit('get:options', options);
|
|
71
|
-
return options;
|
|
70
|
+
return this.__options;
|
|
72
71
|
}
|
|
73
72
|
|
|
74
73
|
get $children() {
|
|
75
|
-
|
|
76
|
-
this.$emit('get:children', children);
|
|
77
|
-
return children;
|
|
74
|
+
return this.__children;
|
|
78
75
|
}
|
|
79
76
|
|
|
80
77
|
get $log() {
|
|
@@ -82,10 +79,40 @@ export default class Base {
|
|
|
82
79
|
}
|
|
83
80
|
|
|
84
81
|
get __debug() {
|
|
85
|
-
return this.__options.debug
|
|
82
|
+
return isDev && this.__options.debug ? window.console.log.bind(window, "[debug] [".concat(this.$id, "]")) : noop;
|
|
83
|
+
}
|
|
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
|
+
|
|
90
|
+
if (isDev) {
|
|
91
|
+
this.__debug('callMethod', method, ...args);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
this.$emit(method, ...args);
|
|
95
|
+
|
|
96
|
+
if (typeof this[method] !== 'function') {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
this[method].call(this, ...args);
|
|
101
|
+
|
|
102
|
+
if (isDev) {
|
|
103
|
+
this.__debug(method, this, ...args);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
__hasEvent(event) {
|
|
108
|
+
var eventHandlers = this.__eventHandlers.get(event);
|
|
109
|
+
|
|
110
|
+
return eventHandlers && eventHandlers.size > 0;
|
|
86
111
|
}
|
|
87
112
|
|
|
88
113
|
constructor(element) {
|
|
114
|
+
super();
|
|
115
|
+
|
|
89
116
|
_defineProperty(this, "$parent", null);
|
|
90
117
|
|
|
91
118
|
_defineProperty(this, "$id", void 0);
|
|
@@ -94,6 +121,8 @@ export default class Base {
|
|
|
94
121
|
|
|
95
122
|
_defineProperty(this, "$isMounted", false);
|
|
96
123
|
|
|
124
|
+
_defineProperty(this, "__eventHandlers", new Map());
|
|
125
|
+
|
|
97
126
|
_defineProperty(this, "__services", void 0);
|
|
98
127
|
|
|
99
128
|
_defineProperty(this, "__refs", void 0);
|
|
@@ -112,11 +141,7 @@ export default class Base {
|
|
|
112
141
|
__config
|
|
113
142
|
} = this;
|
|
114
143
|
|
|
115
|
-
if (
|
|
116
|
-
throw new Error('The `config` static property must be defined.');
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (!__config.name) {
|
|
144
|
+
if (__config.name === 'Base') {
|
|
120
145
|
throw new Error('The `config.name` property is required.');
|
|
121
146
|
}
|
|
122
147
|
|
|
@@ -137,13 +162,23 @@ export default class Base {
|
|
|
137
162
|
this.__children = new ChildrenManager(this, element, __config.components || {}, this.__events);
|
|
138
163
|
this.__refs = new RefsManager(this, element, __config.refs || [], this.__events);
|
|
139
164
|
|
|
140
|
-
|
|
165
|
+
if (isDev) {
|
|
166
|
+
this.__debug('constructor', this);
|
|
167
|
+
}
|
|
141
168
|
|
|
142
169
|
return this;
|
|
143
170
|
}
|
|
144
171
|
|
|
145
172
|
$mount() {
|
|
146
|
-
this
|
|
173
|
+
if (this.$isMounted) {
|
|
174
|
+
return this;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
this.$isMounted = true;
|
|
178
|
+
|
|
179
|
+
if (isDev) {
|
|
180
|
+
this.__debug('$mount');
|
|
181
|
+
}
|
|
147
182
|
|
|
148
183
|
this.$children.registerAll();
|
|
149
184
|
this.$refs.registerAll();
|
|
@@ -152,13 +187,16 @@ export default class Base {
|
|
|
152
187
|
|
|
153
188
|
this.$services.enableAll();
|
|
154
189
|
this.$children.mountAll();
|
|
155
|
-
|
|
156
|
-
this
|
|
190
|
+
|
|
191
|
+
this.__callMethod('mounted');
|
|
192
|
+
|
|
157
193
|
return this;
|
|
158
194
|
}
|
|
159
195
|
|
|
160
196
|
$update() {
|
|
161
|
-
|
|
197
|
+
if (isDev) {
|
|
198
|
+
this.__debug('$update');
|
|
199
|
+
}
|
|
162
200
|
|
|
163
201
|
this.$refs.unregisterAll();
|
|
164
202
|
this.$services.disableAll();
|
|
@@ -166,28 +204,43 @@ export default class Base {
|
|
|
166
204
|
this.$refs.registerAll();
|
|
167
205
|
this.$services.enableAll();
|
|
168
206
|
this.$children.updateAll();
|
|
169
|
-
|
|
207
|
+
|
|
208
|
+
this.__callMethod('updated');
|
|
209
|
+
|
|
170
210
|
return this;
|
|
171
211
|
}
|
|
172
212
|
|
|
173
213
|
$destroy() {
|
|
174
|
-
this
|
|
214
|
+
if (!this.$isMounted) {
|
|
215
|
+
return this;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
this.$isMounted = false;
|
|
219
|
+
|
|
220
|
+
if (isDev) {
|
|
221
|
+
this.__debug('$destroy');
|
|
222
|
+
}
|
|
175
223
|
|
|
176
224
|
this.__events.unbindRootElement();
|
|
177
225
|
|
|
178
226
|
this.$refs.unregisterAll();
|
|
179
227
|
this.$services.disableAll();
|
|
180
228
|
this.$children.destroyAll();
|
|
181
|
-
|
|
182
|
-
this
|
|
229
|
+
|
|
230
|
+
this.__callMethod('destroyed');
|
|
231
|
+
|
|
183
232
|
return this;
|
|
184
233
|
}
|
|
185
234
|
|
|
186
235
|
$terminate() {
|
|
187
|
-
|
|
236
|
+
if (isDev) {
|
|
237
|
+
this.__debug('$terminate');
|
|
238
|
+
}
|
|
188
239
|
|
|
189
240
|
this.$destroy();
|
|
190
|
-
|
|
241
|
+
|
|
242
|
+
this.__callMethod('terminated');
|
|
243
|
+
|
|
191
244
|
Object.defineProperty(this.$el, '__base__', {
|
|
192
245
|
value: 'terminated',
|
|
193
246
|
configurable: false,
|
|
@@ -195,43 +248,97 @@ export default class Base {
|
|
|
195
248
|
});
|
|
196
249
|
}
|
|
197
250
|
|
|
198
|
-
|
|
199
|
-
if (!
|
|
200
|
-
|
|
251
|
+
__testEventIsDefined(event) {
|
|
252
|
+
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."));
|
|
201
254
|
}
|
|
255
|
+
}
|
|
202
256
|
|
|
203
|
-
|
|
257
|
+
__addEmits(event) {
|
|
258
|
+
var ctor = this.constructor;
|
|
259
|
+
|
|
260
|
+
if (Array.isArray(ctor.config.emits)) {
|
|
261
|
+
ctor.config.emits.push(event);
|
|
262
|
+
} else {
|
|
263
|
+
ctor.config.emits = [event];
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
__removeEmits(event) {
|
|
268
|
+
var ctor = this.constructor;
|
|
269
|
+
var index = ctor.config.emits.findIndex(value => value === event);
|
|
270
|
+
ctor.config.emits.splice(index, 1);
|
|
204
271
|
}
|
|
205
272
|
|
|
206
273
|
$on(event, listener, options) {
|
|
207
|
-
|
|
274
|
+
if (isDev) {
|
|
275
|
+
this.__debug('$on', event, listener, options);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (isDev) {
|
|
279
|
+
this.__testEventIsDefined(event);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
var set = this.__eventHandlers.get(event);
|
|
208
283
|
|
|
209
|
-
|
|
284
|
+
if (!set) {
|
|
285
|
+
set = new Set();
|
|
286
|
+
|
|
287
|
+
this.__eventHandlers.set(event, set);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
set.add(listener);
|
|
291
|
+
this.addEventListener(event, listener, options);
|
|
210
292
|
return () => {
|
|
211
293
|
this.$off(event, listener, options);
|
|
212
294
|
};
|
|
213
295
|
}
|
|
214
296
|
|
|
215
297
|
$off(event, listener, options) {
|
|
216
|
-
|
|
298
|
+
if (isDev) {
|
|
299
|
+
this.__debug('$off', event, listener);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (isDev) {
|
|
303
|
+
this.__testEventIsDefined(event);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
this.__eventHandlers.get(event).delete(listener);
|
|
217
307
|
|
|
218
|
-
this
|
|
308
|
+
this.removeEventListener(event, listener, options);
|
|
219
309
|
}
|
|
220
310
|
|
|
221
311
|
$emit(event) {
|
|
222
|
-
for (var
|
|
223
|
-
args[
|
|
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
|
+
|
|
316
|
+
if (isDev) {
|
|
317
|
+
this.__debug('$emit', event, args);
|
|
224
318
|
}
|
|
225
319
|
|
|
226
|
-
|
|
320
|
+
if (isDev) {
|
|
321
|
+
this.__testEventIsDefined(event);
|
|
322
|
+
}
|
|
227
323
|
|
|
228
|
-
this
|
|
324
|
+
this.dispatchEvent(new CustomEvent(event, {
|
|
229
325
|
detail: args
|
|
230
326
|
}));
|
|
231
327
|
}
|
|
232
328
|
|
|
329
|
+
static $factory(nameOrSelector) {
|
|
330
|
+
if (!nameOrSelector) {
|
|
331
|
+
throw new Error('The $factory method requires a component’s name or selector to be specified.');
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
return getComponentElements(nameOrSelector).map(el => new this(el).$mount());
|
|
335
|
+
}
|
|
336
|
+
|
|
233
337
|
}
|
|
234
338
|
|
|
235
339
|
_defineProperty(Base, "$isBase", true);
|
|
236
340
|
|
|
237
|
-
_defineProperty(Base, "config",
|
|
341
|
+
_defineProperty(Base, "config", {
|
|
342
|
+
name: 'Base',
|
|
343
|
+
emits: ['mounted', 'updated', 'destroyed', 'terminated', 'ticked', 'scrolled', 'resized', 'moved', 'loaded', 'keyed']
|
|
344
|
+
});
|
|
@@ -14,10 +14,28 @@ export default class ChildrenManager {
|
|
|
14
14
|
|
|
15
15
|
_defineProperty(this, "__eventsManager", void 0);
|
|
16
16
|
|
|
17
|
-
this
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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() {
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* Event management class.
|
|
7
|
+
* @todo Prevent binding of `onChildOrRefEvent` to the root element
|
|
8
|
+
* @todo Use event delegation?
|
|
7
9
|
*/
|
|
8
10
|
export default class EventsManager {
|
|
9
11
|
/**
|
|
@@ -150,7 +152,7 @@ export default class EventsManager {
|
|
|
150
152
|
* Manage event methods on the root element.
|
|
151
153
|
*
|
|
152
154
|
* @param {'add'|'remove'} [mode]
|
|
153
|
-
* The action to perform: add or remove the event listeners.
|
|
155
|
+
* The action to perform: add or remove the event listeners, defaults to 'add'.
|
|
154
156
|
*
|
|
155
157
|
* @return {void}
|
|
156
158
|
* @private
|
|
@@ -37,7 +37,7 @@ export default class EventsManager {
|
|
|
37
37
|
|
|
38
38
|
_defineProperty(this, "__childrenHandler", {
|
|
39
39
|
handleEvent: event => {
|
|
40
|
-
var child = event.currentTarget
|
|
40
|
+
var child = event.currentTarget;
|
|
41
41
|
var childName;
|
|
42
42
|
var index = 0;
|
|
43
43
|
var childrenManager = this.__base.$children;
|
|
@@ -59,8 +59,38 @@ export default class EventsManager {
|
|
|
59
59
|
}
|
|
60
60
|
});
|
|
61
61
|
|
|
62
|
-
this
|
|
63
|
-
|
|
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) {
|
|
@@ -111,10 +141,14 @@ export default class EventsManager {
|
|
|
111
141
|
|
|
112
142
|
var methods = this.__getEventMethodsByName();
|
|
113
143
|
|
|
144
|
+
var {
|
|
145
|
+
emits = []
|
|
146
|
+
} = this.__base.__config;
|
|
114
147
|
methods.forEach(method => {
|
|
115
148
|
var event = this.__getEventNameByMethod(method);
|
|
116
149
|
|
|
117
|
-
|
|
150
|
+
var target = emits.includes(event) ? this.__base : this.__rootElement;
|
|
151
|
+
target[modeMethod](event, this.__rootElementHandler);
|
|
118
152
|
});
|
|
119
153
|
}
|
|
120
154
|
|
|
@@ -23,7 +23,23 @@ export default class OptionsManager {
|
|
|
23
23
|
|
|
24
24
|
_defineProperty(this, "log", false);
|
|
25
25
|
|
|
26
|
-
this
|
|
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
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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() {
|
|
@@ -32,6 +50,11 @@ export default class RefsManager {
|
|
|
32
50
|
console.warn("[".concat(this.__base.$options.name, "]"), "The \"".concat(refName, "\" ref has been found multiple times."), 'Did you forgot to add the `[]` suffix to its name?');
|
|
33
51
|
}
|
|
34
52
|
|
|
53
|
+
if (!isMultiple && refs.length <= 1 && refs[0] === undefined) {
|
|
54
|
+
console.warn("[".concat(this.__base.$options.name, "]"), "The \"".concat(refName, "\" ref is missing."), "Is there an `[data-ref=\"".concat(refName, "\"]` element in the component's scope?"));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
35
58
|
this.__eventsManager.bindRef(refName, refs);
|
|
36
59
|
|
|
37
60
|
Object.defineProperty(this, propName, {
|