@studiometa/js-toolkit 2.0.0-beta.5 → 2.0.0-beta.9
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 +27 -1
- package/Base/index.js +98 -42
- package/Base/managers/EventsManager.d.ts +3 -1
- package/Base/managers/EventsManager.js +6 -2
- package/Base/managers/OptionsManager.d.ts +2 -0
- package/Base/managers/RefsManager.d.ts +2 -0
- package/Base/managers/RefsManager.js +5 -0
- package/Base/managers/ServicesManager.d.ts +29 -4
- package/Base/managers/ServicesManager.js +6 -2
- package/README.md +13 -70
- package/decorators/index.d.ts +8 -9
- package/decorators/index.js +8 -9
- package/decorators/withBreakpointObserver.js +2 -2
- package/decorators/withDrag.js +8 -2
- package/decorators/withIntersectionObserver.js +4 -3
- package/decorators/withMountWhenInView.js +7 -4
- package/decorators/withScrolledInView.d.ts +4 -1
- package/decorators/withScrolledInView.js +56 -39
- package/decorators/withVue2.js +2 -2
- package/helpers/index.d.ts +4 -5
- package/helpers/index.js +4 -5
- package/index.d.ts +4 -21
- 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 +4 -18
- package/services/drag.js +81 -104
- 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.js +2 -2
- package/utils/index.d.ts +11 -35
- package/utils/index.js +11 -17
- package/utils/math/ease.d.ts +78 -0
- package/utils/math/ease.js +41 -0
- package/utils/math/index.d.ts +8 -8
- package/utils/math/index.js +8 -8
- package/utils/object/getAllProperties.js +1 -1
- package/utils/object/index.d.ts +3 -4
- package/utils/object/index.js +3 -4
- 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}
|
|
@@ -174,6 +175,30 @@ export default class Base {
|
|
|
174
175
|
* @return {void}
|
|
175
176
|
*/
|
|
176
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;
|
|
177
202
|
/**
|
|
178
203
|
* Bind a listener function to an event.
|
|
179
204
|
*
|
|
@@ -233,6 +258,7 @@ export type BaseConfig = {
|
|
|
233
258
|
debug?: boolean;
|
|
234
259
|
log?: boolean;
|
|
235
260
|
refs?: string[];
|
|
261
|
+
emits?: string[];
|
|
236
262
|
components?: BaseConfigComponents;
|
|
237
263
|
options?: BaseConfigOptions;
|
|
238
264
|
};
|
package/Base/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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
7
|
import { getComponentElements } from './utils.js';
|
|
8
8
|
import ChildrenManager from './managers/ChildrenManager.js';
|
|
@@ -11,10 +11,11 @@ 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,7 +79,7 @@ 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;
|
|
86
83
|
}
|
|
87
84
|
|
|
88
85
|
__callMethod(method) {
|
|
@@ -90,12 +87,8 @@ export default class Base {
|
|
|
90
87
|
args[_key - 1] = arguments[_key];
|
|
91
88
|
}
|
|
92
89
|
|
|
93
|
-
|
|
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;
|
|
90
|
+
if (isDev) {
|
|
91
|
+
this.__debug('callMethod', method, ...args);
|
|
99
92
|
}
|
|
100
93
|
|
|
101
94
|
this.$emit(method, ...args);
|
|
@@ -106,7 +99,9 @@ export default class Base {
|
|
|
106
99
|
|
|
107
100
|
this[method].call(this, ...args);
|
|
108
101
|
|
|
109
|
-
|
|
102
|
+
if (isDev) {
|
|
103
|
+
this.__debug(method, this, ...args);
|
|
104
|
+
}
|
|
110
105
|
}
|
|
111
106
|
|
|
112
107
|
__hasEvent(event) {
|
|
@@ -116,6 +111,8 @@ export default class Base {
|
|
|
116
111
|
}
|
|
117
112
|
|
|
118
113
|
constructor(element) {
|
|
114
|
+
super();
|
|
115
|
+
|
|
119
116
|
_defineProperty(this, "$parent", null);
|
|
120
117
|
|
|
121
118
|
_defineProperty(this, "$id", void 0);
|
|
@@ -144,11 +141,7 @@ export default class Base {
|
|
|
144
141
|
__config
|
|
145
142
|
} = this;
|
|
146
143
|
|
|
147
|
-
if (
|
|
148
|
-
throw new Error('The `config` static property must be defined.');
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (!__config.name) {
|
|
144
|
+
if (__config.name === 'Base') {
|
|
152
145
|
throw new Error('The `config.name` property is required.');
|
|
153
146
|
}
|
|
154
147
|
|
|
@@ -169,13 +162,23 @@ export default class Base {
|
|
|
169
162
|
this.__children = new ChildrenManager(this, element, __config.components || {}, this.__events);
|
|
170
163
|
this.__refs = new RefsManager(this, element, __config.refs || [], this.__events);
|
|
171
164
|
|
|
172
|
-
|
|
165
|
+
if (isDev) {
|
|
166
|
+
this.__debug('constructor', this);
|
|
167
|
+
}
|
|
173
168
|
|
|
174
169
|
return this;
|
|
175
170
|
}
|
|
176
171
|
|
|
177
172
|
$mount() {
|
|
178
|
-
this
|
|
173
|
+
if (this.$isMounted) {
|
|
174
|
+
return this;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
this.$isMounted = true;
|
|
178
|
+
|
|
179
|
+
if (isDev) {
|
|
180
|
+
this.__debug('$mount');
|
|
181
|
+
}
|
|
179
182
|
|
|
180
183
|
this.$children.registerAll();
|
|
181
184
|
this.$refs.registerAll();
|
|
@@ -187,12 +190,13 @@ export default class Base {
|
|
|
187
190
|
|
|
188
191
|
this.__callMethod('mounted');
|
|
189
192
|
|
|
190
|
-
this.$isMounted = true;
|
|
191
193
|
return this;
|
|
192
194
|
}
|
|
193
195
|
|
|
194
196
|
$update() {
|
|
195
|
-
|
|
197
|
+
if (isDev) {
|
|
198
|
+
this.__debug('$update');
|
|
199
|
+
}
|
|
196
200
|
|
|
197
201
|
this.$refs.unregisterAll();
|
|
198
202
|
this.$services.disableAll();
|
|
@@ -207,7 +211,15 @@ export default class Base {
|
|
|
207
211
|
}
|
|
208
212
|
|
|
209
213
|
$destroy() {
|
|
210
|
-
this
|
|
214
|
+
if (!this.$isMounted) {
|
|
215
|
+
return this;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
this.$isMounted = false;
|
|
219
|
+
|
|
220
|
+
if (isDev) {
|
|
221
|
+
this.__debug('$destroy');
|
|
222
|
+
}
|
|
211
223
|
|
|
212
224
|
this.__events.unbindRootElement();
|
|
213
225
|
|
|
@@ -217,12 +229,13 @@ export default class Base {
|
|
|
217
229
|
|
|
218
230
|
this.__callMethod('destroyed');
|
|
219
231
|
|
|
220
|
-
this.$isMounted = false;
|
|
221
232
|
return this;
|
|
222
233
|
}
|
|
223
234
|
|
|
224
235
|
$terminate() {
|
|
225
|
-
|
|
236
|
+
if (isDev) {
|
|
237
|
+
this.__debug('$terminate');
|
|
238
|
+
}
|
|
226
239
|
|
|
227
240
|
this.$destroy();
|
|
228
241
|
|
|
@@ -235,8 +248,36 @@ export default class Base {
|
|
|
235
248
|
});
|
|
236
249
|
}
|
|
237
250
|
|
|
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."));
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
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);
|
|
271
|
+
}
|
|
272
|
+
|
|
238
273
|
$on(event, listener, options) {
|
|
239
|
-
|
|
274
|
+
if (isDev) {
|
|
275
|
+
this.__debug('$on', event, listener, options);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (isDev) {
|
|
279
|
+
this.__testEventIsDefined(event);
|
|
280
|
+
}
|
|
240
281
|
|
|
241
282
|
var set = this.__eventHandlers.get(event);
|
|
242
283
|
|
|
@@ -247,18 +288,24 @@ export default class Base {
|
|
|
247
288
|
}
|
|
248
289
|
|
|
249
290
|
set.add(listener);
|
|
250
|
-
this
|
|
291
|
+
this.addEventListener(event, listener, options);
|
|
251
292
|
return () => {
|
|
252
293
|
this.$off(event, listener, options);
|
|
253
294
|
};
|
|
254
295
|
}
|
|
255
296
|
|
|
256
297
|
$off(event, listener, options) {
|
|
257
|
-
|
|
298
|
+
if (isDev) {
|
|
299
|
+
this.__debug('$off', event, listener);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (isDev) {
|
|
303
|
+
this.__testEventIsDefined(event);
|
|
304
|
+
}
|
|
258
305
|
|
|
259
306
|
this.__eventHandlers.get(event).delete(listener);
|
|
260
307
|
|
|
261
|
-
this
|
|
308
|
+
this.removeEventListener(event, listener, options);
|
|
262
309
|
}
|
|
263
310
|
|
|
264
311
|
$emit(event) {
|
|
@@ -266,9 +313,15 @@ export default class Base {
|
|
|
266
313
|
args[_key2 - 1] = arguments[_key2];
|
|
267
314
|
}
|
|
268
315
|
|
|
269
|
-
|
|
316
|
+
if (isDev) {
|
|
317
|
+
this.__debug('$emit', event, args);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
if (isDev) {
|
|
321
|
+
this.__testEventIsDefined(event);
|
|
322
|
+
}
|
|
270
323
|
|
|
271
|
-
this
|
|
324
|
+
this.dispatchEvent(new CustomEvent(event, {
|
|
272
325
|
detail: args
|
|
273
326
|
}));
|
|
274
327
|
}
|
|
@@ -285,4 +338,7 @@ export default class Base {
|
|
|
285
338
|
|
|
286
339
|
_defineProperty(Base, "$isBase", true);
|
|
287
340
|
|
|
288
|
-
_defineProperty(Base, "config",
|
|
341
|
+
_defineProperty(Base, "config", {
|
|
342
|
+
name: 'Base',
|
|
343
|
+
emits: ['mounted', 'updated', 'destroyed', 'terminated', 'ticked', 'scrolled', 'resized', 'moved', 'loaded', 'keyed']
|
|
344
|
+
});
|
|
@@ -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;
|
|
@@ -141,10 +141,14 @@ export default class EventsManager {
|
|
|
141
141
|
|
|
142
142
|
var methods = this.__getEventMethodsByName();
|
|
143
143
|
|
|
144
|
+
var {
|
|
145
|
+
emits = []
|
|
146
|
+
} = this.__base.__config;
|
|
144
147
|
methods.forEach(method => {
|
|
145
148
|
var event = this.__getEventNameByMethod(method);
|
|
146
149
|
|
|
147
|
-
|
|
150
|
+
var target = emits.includes(event) ? this.__base : this.__rootElement;
|
|
151
|
+
target[modeMethod](event, this.__rootElementHandler);
|
|
148
152
|
});
|
|
149
153
|
}
|
|
150
154
|
|
|
@@ -50,6 +50,11 @@ export default class RefsManager {
|
|
|
50
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?');
|
|
51
51
|
}
|
|
52
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
|
+
|
|
53
58
|
this.__eventsManager.bindRef(refName, refs);
|
|
54
59
|
|
|
55
60
|
Object.defineProperty(this, propName, {
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @typedef {
|
|
2
|
+
* @typedef {typeof SERVICES_MAP & Record<string, () => ServiceInterface>} Services
|
|
3
|
+
* @typedef {keyof SERVICES_MAP|string} ServiceName
|
|
3
4
|
*/
|
|
4
5
|
/**
|
|
5
6
|
* Services management for the Base class.
|
|
7
|
+
*
|
|
8
|
+
* @todo Add support for disabled services on mount when the method is defined.
|
|
6
9
|
*/
|
|
7
10
|
export default class ServicesManager {
|
|
8
11
|
/**
|
|
@@ -81,7 +84,29 @@ export default class ServicesManager {
|
|
|
81
84
|
unregister(name: string): void;
|
|
82
85
|
}
|
|
83
86
|
export type Base = import('../index').default;
|
|
84
|
-
export type
|
|
87
|
+
export type BaseConstructor = import('../index').BaseConstructor;
|
|
88
|
+
export type ServiceInterface = import('../../services').ServiceInterface<any>;
|
|
89
|
+
export type Services = typeof SERVICES_MAP & Record<string, () => ServiceInterface>;
|
|
85
90
|
export type ServiceName = keyof {
|
|
86
|
-
|
|
87
|
-
|
|
91
|
+
scrolled: typeof useScroll;
|
|
92
|
+
resized: typeof useResize;
|
|
93
|
+
ticked: typeof useRaf;
|
|
94
|
+
moved: typeof usePointer;
|
|
95
|
+
keyed: typeof useKey;
|
|
96
|
+
loaded: typeof useLoad;
|
|
97
|
+
} | string;
|
|
98
|
+
declare namespace SERVICES_MAP {
|
|
99
|
+
export { useScroll as scrolled };
|
|
100
|
+
export { useResize as resized };
|
|
101
|
+
export { useRaf as ticked };
|
|
102
|
+
export { usePointer as moved };
|
|
103
|
+
export { useKey as keyed };
|
|
104
|
+
export { useLoad as loaded };
|
|
105
|
+
}
|
|
106
|
+
import useScroll from "../../services/scroll.js";
|
|
107
|
+
import useResize from "../../services/resize.js";
|
|
108
|
+
import useRaf from "../../services/raf.js";
|
|
109
|
+
import usePointer from "../../services/pointer.js";
|
|
110
|
+
import useKey from "../../services/key.js";
|
|
111
|
+
import useLoad from "../../services/load.js";
|
|
112
|
+
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
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
7
|
import usePointer from '../../services/pointer.js';
|
|
8
8
|
import useRaf from '../../services/raf.js';
|
|
@@ -118,6 +118,8 @@ export default class ServicesManager {
|
|
|
118
118
|
|
|
119
119
|
register(name, useFunction) {
|
|
120
120
|
this.__customServices[name] = useFunction;
|
|
121
|
+
|
|
122
|
+
this.__base.__addEmits(name);
|
|
121
123
|
}
|
|
122
124
|
|
|
123
125
|
unregister(name) {
|
|
@@ -125,6 +127,8 @@ export default class ServicesManager {
|
|
|
125
127
|
throw new Error("[ServicesManager] The `".concat(name, "` core service can not be unregistered."));
|
|
126
128
|
}
|
|
127
129
|
|
|
130
|
+
this.__base.__removeEmits(name);
|
|
131
|
+
|
|
128
132
|
delete this.__customServices[name];
|
|
129
133
|
}
|
|
130
134
|
|
package/README.md
CHANGED
|
@@ -15,80 +15,23 @@ Install the latest version via NPM:
|
|
|
15
15
|
npm install @studiometa/js-toolkit
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
##
|
|
18
|
+
## Documentation
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
This project contains a JavaScript micro-framework and its utility functions whose main objectives are:
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
- Enforcing best-practice and consistency between projects
|
|
23
|
+
- Using elements from the DOM easily
|
|
24
|
+
- Enabling custom behaviours on component initialization or other user events
|
|
25
|
+
- Disabling custom behaviours on component destruction or other user events
|
|
26
|
+
- Initializing components in the right place at the right time
|
|
27
|
+
- Defining dependencies between components
|
|
23
28
|
|
|
24
|
-
|
|
29
|
+
Visit [js-toolkit.studiometa.dev](https://js-toolkit.studiometa.dev) to learn more.
|
|
25
30
|
|
|
26
|
-
|
|
27
|
-
import { Base, createApp } from '@studiometa/js-toolkit';
|
|
31
|
+
## Contributing
|
|
28
32
|
|
|
29
|
-
|
|
30
|
-
static config = {
|
|
31
|
-
name: 'Component',
|
|
32
|
-
}
|
|
33
|
+
This projects follows the [Git Flow](https://github.com/petervanderdoes/gitflow-avh) methodology to manage its branches and features. The packages and their dependencies are managed with NPM workspaces. The files are linted with ESLint, type checked with TypeScript and formatted with Prettier.
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
console.log('Hello!');
|
|
36
|
-
}
|
|
37
|
-
}
|
|
35
|
+
## License
|
|
38
36
|
|
|
39
|
-
|
|
40
|
-
static config = {
|
|
41
|
-
name: 'App',
|
|
42
|
-
components: {
|
|
43
|
-
Component,
|
|
44
|
-
},
|
|
45
|
-
refs: ['btn', 'items[]'],
|
|
46
|
-
options: {
|
|
47
|
-
foo: String,
|
|
48
|
-
bar: { type: String, default: 'bar' },
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
mounted() {
|
|
53
|
-
this.$log('mounted');
|
|
54
|
-
|
|
55
|
-
// Options
|
|
56
|
-
this.$options.name; // 'App'
|
|
57
|
-
this.$options.log; // true
|
|
58
|
-
this.$options.debug; // false
|
|
59
|
-
this.$options.foo // ''
|
|
60
|
-
this.$options.bar // 'bar'
|
|
61
|
-
|
|
62
|
-
// Children
|
|
63
|
-
this.$children.Component; // Array<Component>
|
|
64
|
-
|
|
65
|
-
// DOM references
|
|
66
|
-
this.$refs.btn; // <button data-ref="btn"></button>
|
|
67
|
-
this.$refs.items[0]; // <li data-ref="items[]"></li>
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
destroyed() {
|
|
71
|
-
this.$log('destroyed');
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
scrolled(props) {
|
|
75
|
-
this.$log('scrolled', props);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
resized(props) {
|
|
79
|
-
this.$log('resized', props);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export default createApp(App, document.body);
|
|
84
|
-
```
|
|
85
|
-
|
|
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.
|
|
91
|
-
|
|
92
|
-
The packages from this project are managed with NPM workspaces.
|
|
93
|
-
|
|
94
|
-
The files are linted with ESLint, type checked with TypeScript and formatted with Prettier.
|
|
37
|
+
See [LICENSE](./LICENSE).
|
package/decorators/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export { withBreakpointManager, withBreakpointObserver, withDrag, withExtraConfig, withIntersectionObserver, withMountWhenInView, withScrolledInView, withVue2 };
|
|
1
|
+
export { default as withBreakpointManager } from "./withBreakpointManager.js";
|
|
2
|
+
export { default as withBreakpointObserver } from "./withBreakpointObserver.js";
|
|
3
|
+
export { default as withDrag } from "./withDrag.js";
|
|
4
|
+
export { default as withExtraConfig } from "./withExtraConfig.js";
|
|
5
|
+
export { default as withIntersectionObserver } from "./withIntersectionObserver.js";
|
|
6
|
+
export { default as withMountWhenInView } from "./withMountWhenInView.js";
|
|
7
|
+
export { default as withScrolledInView } from "./withScrolledInView.js";
|
|
8
|
+
export { default as withVue2 } from "./withVue2.js";
|
package/decorators/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export { withBreakpointManager, withBreakpointObserver, withDrag, withExtraConfig, withIntersectionObserver, withMountWhenInView, withScrolledInView, withVue2 };
|
|
1
|
+
export { default as withBreakpointManager } from './withBreakpointManager.js';
|
|
2
|
+
export { default as withBreakpointObserver } from './withBreakpointObserver.js';
|
|
3
|
+
export { default as withDrag } from './withDrag.js';
|
|
4
|
+
export { default as withExtraConfig } from './withExtraConfig.js';
|
|
5
|
+
export { default as withIntersectionObserver } from './withIntersectionObserver.js';
|
|
6
|
+
export { default as withMountWhenInView } from './withMountWhenInView.js';
|
|
7
|
+
export { default as withScrolledInView } from './withScrolledInView.js';
|
|
8
|
+
export { default as withVue2 } from './withVue2.js';
|
|
@@ -1,8 +1,8 @@
|
|
|
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
7
|
import useResize from '../services/resize.js';
|
|
8
8
|
|
package/decorators/withDrag.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
1
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
3
|
var _excluded = ["target"];
|
|
3
4
|
import useDrag from '../services/drag.js';
|
|
4
5
|
export default function withDrag(BaseClass) {
|
|
6
|
+
var _class, _temp;
|
|
7
|
+
|
|
5
8
|
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
6
9
|
{
|
|
7
10
|
target = instance => instance.$el
|
|
8
11
|
} = _ref,
|
|
9
12
|
options = _objectWithoutProperties(_ref, _excluded);
|
|
10
13
|
|
|
11
|
-
return class extends BaseClass {
|
|
14
|
+
return _temp = _class = class extends BaseClass {
|
|
12
15
|
constructor(el) {
|
|
13
16
|
super(el);
|
|
14
17
|
this.$on('mounted', () => {
|
|
@@ -21,5 +24,8 @@ export default function withDrag(BaseClass) {
|
|
|
21
24
|
});
|
|
22
25
|
}
|
|
23
26
|
|
|
24
|
-
}
|
|
27
|
+
}, _defineProperty(_class, "config", {
|
|
28
|
+
name: "".concat(BaseClass.config.name, "WithDrag"),
|
|
29
|
+
emits: ['dragged']
|
|
30
|
+
}), _temp;
|
|
25
31
|
}
|