@studiometa/js-toolkit 2.0.0-beta.1 → 2.0.0-beta.6
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/ServicesManager.d.ts +29 -4
- package/Base/managers/ServicesManager.js +6 -2
- 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 +2 -0
- package/decorators/withScrolledInView.js +7 -2
- package/decorators/withVue2.js +2 -2
- 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 +6 -2
- 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/css/transition.js +2 -2
- package/utils/history.js +2 -2
- package/utils/object/getAllProperties.js +1 -1
- package/utils/scrollTo.js +1 -1
package/services/drag.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 Service from './Service.js';
|
|
8
8
|
import usePointer from './pointer.js';
|
|
@@ -24,36 +24,29 @@ class Drag extends Service {
|
|
|
24
24
|
|
|
25
25
|
_defineProperty(this, "id", void 0);
|
|
26
26
|
|
|
27
|
-
_defineProperty(this, "
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
_defineProperty(this, "hasInertia", false);
|
|
34
|
-
|
|
35
|
-
_defineProperty(this, "x", 0);
|
|
36
|
-
|
|
37
|
-
_defineProperty(this, "y", 0);
|
|
38
|
-
|
|
39
|
-
_defineProperty(this, "delta", {
|
|
40
|
-
x: 0,
|
|
41
|
-
y: 0
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
_defineProperty(this, "origin", {
|
|
45
|
-
x: 0,
|
|
46
|
-
y: 0
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
_defineProperty(this, "distance", {
|
|
50
|
-
x: 0,
|
|
51
|
-
y: 0
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
_defineProperty(this, "final", {
|
|
27
|
+
_defineProperty(this, "props", {
|
|
28
|
+
target: null,
|
|
29
|
+
mode: undefined,
|
|
30
|
+
isGrabbing: false,
|
|
31
|
+
hasInertia: false,
|
|
55
32
|
x: 0,
|
|
56
|
-
y: 0
|
|
33
|
+
y: 0,
|
|
34
|
+
delta: {
|
|
35
|
+
x: 0,
|
|
36
|
+
y: 0
|
|
37
|
+
},
|
|
38
|
+
origin: {
|
|
39
|
+
x: 0,
|
|
40
|
+
y: 0
|
|
41
|
+
},
|
|
42
|
+
distance: {
|
|
43
|
+
x: 0,
|
|
44
|
+
y: 0
|
|
45
|
+
},
|
|
46
|
+
final: {
|
|
47
|
+
x: 0,
|
|
48
|
+
y: 0
|
|
49
|
+
}
|
|
57
50
|
});
|
|
58
51
|
|
|
59
52
|
_defineProperty(this, "options", {
|
|
@@ -62,7 +55,7 @@ class Drag extends Service {
|
|
|
62
55
|
|
|
63
56
|
instanceIds += 1;
|
|
64
57
|
this.id = "drag-".concat(instanceIds);
|
|
65
|
-
this.target = target;
|
|
58
|
+
this.props.target = target;
|
|
66
59
|
this.options = _objectSpread(_objectSpread({}, this.options), options);
|
|
67
60
|
this.pointerHandler = this.pointerHandler.bind(this);
|
|
68
61
|
this.rafHandler = this.rafHandler.bind(this);
|
|
@@ -73,16 +66,16 @@ class Drag extends Service {
|
|
|
73
66
|
var options = {
|
|
74
67
|
passive: true
|
|
75
68
|
};
|
|
76
|
-
this.target.addEventListener('mousedown', this, options);
|
|
77
|
-
this.target.addEventListener('touchstart', this, options);
|
|
69
|
+
this.props.target.addEventListener('mousedown', this, options);
|
|
70
|
+
this.props.target.addEventListener('touchstart', this, options);
|
|
78
71
|
var pointer = usePointer();
|
|
79
72
|
pointer.add(this.id, this.pointerHandler);
|
|
80
73
|
return this;
|
|
81
74
|
}
|
|
82
75
|
|
|
83
76
|
kill() {
|
|
84
|
-
this.target.removeEventListener('mousemove', this);
|
|
85
|
-
this.target.removeEventListener('touchmove', this);
|
|
77
|
+
this.props.target.removeEventListener('mousemove', this);
|
|
78
|
+
this.props.target.removeEventListener('touchmove', this);
|
|
86
79
|
var pointer = usePointer();
|
|
87
80
|
pointer.remove(this.id);
|
|
88
81
|
return this;
|
|
@@ -95,27 +88,27 @@ class Drag extends Service {
|
|
|
95
88
|
}
|
|
96
89
|
|
|
97
90
|
start(x, y) {
|
|
98
|
-
this.x = x;
|
|
99
|
-
this.y = y;
|
|
100
|
-
this.origin.x = x;
|
|
101
|
-
this.origin.y = y;
|
|
102
|
-
this.delta.x = 0;
|
|
103
|
-
this.delta.y = 0;
|
|
104
|
-
this.distance.x = 0;
|
|
105
|
-
this.distance.y = 0;
|
|
106
|
-
this.final.x = x;
|
|
107
|
-
this.final.y = y;
|
|
108
|
-
this.mode = MODES.START;
|
|
109
|
-
this.isGrabbing = true;
|
|
91
|
+
this.props.x = x;
|
|
92
|
+
this.props.y = y;
|
|
93
|
+
this.props.origin.x = x;
|
|
94
|
+
this.props.origin.y = y;
|
|
95
|
+
this.props.delta.x = 0;
|
|
96
|
+
this.props.delta.y = 0;
|
|
97
|
+
this.props.distance.x = 0;
|
|
98
|
+
this.props.distance.y = 0;
|
|
99
|
+
this.props.final.x = x;
|
|
100
|
+
this.props.final.y = y;
|
|
101
|
+
this.props.mode = MODES.START;
|
|
102
|
+
this.props.isGrabbing = true;
|
|
110
103
|
this.trigger(this.props);
|
|
111
104
|
}
|
|
112
105
|
|
|
113
106
|
drop() {
|
|
114
|
-
this.isGrabbing = false;
|
|
115
|
-
this.mode = MODES.DROP;
|
|
116
|
-
this.hasInertia = true;
|
|
117
|
-
this.final.x = inertiaFinalValue(this.x, this.delta.x, this.options.dampFactor);
|
|
118
|
-
this.final.y = inertiaFinalValue(this.y, this.delta.y, this.options.dampFactor);
|
|
107
|
+
this.props.isGrabbing = false;
|
|
108
|
+
this.props.mode = MODES.DROP;
|
|
109
|
+
this.props.hasInertia = true;
|
|
110
|
+
this.props.final.x = inertiaFinalValue(this.props.x, this.props.delta.x, this.options.dampFactor);
|
|
111
|
+
this.props.final.y = inertiaFinalValue(this.props.y, this.props.delta.y, this.options.dampFactor);
|
|
119
112
|
this.trigger(this.props);
|
|
120
113
|
setTimeout(() => {
|
|
121
114
|
var raf = useRaf();
|
|
@@ -126,45 +119,45 @@ class Drag extends Service {
|
|
|
126
119
|
|
|
127
120
|
stop() {
|
|
128
121
|
useRaf().remove(this.id);
|
|
129
|
-
this.hasInertia = false;
|
|
130
|
-
this.mode = MODES.STOP;
|
|
122
|
+
this.props.hasInertia = false;
|
|
123
|
+
this.props.mode = MODES.STOP;
|
|
131
124
|
this.trigger(this.props);
|
|
132
125
|
}
|
|
133
126
|
|
|
134
127
|
rafHandler() {
|
|
135
|
-
if (!this.isGrabbing) {
|
|
136
|
-
this.x += this.delta.x;
|
|
137
|
-
this.y += this.delta.y;
|
|
138
|
-
this.distance.x = this.x - this.origin.x;
|
|
139
|
-
this.distance.y = this.y - this.origin.y;
|
|
140
|
-
this.delta.x *= this.options.dampFactor;
|
|
141
|
-
this.delta.y *= this.options.dampFactor;
|
|
142
|
-
|
|
143
|
-
if (this.mode !== MODES.INERTIA) {
|
|
144
|
-
this.mode = MODES.INERTIA;
|
|
128
|
+
if (!this.props.isGrabbing) {
|
|
129
|
+
this.props.x += this.props.delta.x;
|
|
130
|
+
this.props.y += this.props.delta.y;
|
|
131
|
+
this.props.distance.x = this.props.x - this.props.origin.x;
|
|
132
|
+
this.props.distance.y = this.props.y - this.props.origin.y;
|
|
133
|
+
this.props.delta.x *= this.options.dampFactor;
|
|
134
|
+
this.props.delta.y *= this.options.dampFactor;
|
|
135
|
+
|
|
136
|
+
if (this.props.mode !== MODES.INERTIA) {
|
|
137
|
+
this.props.mode = MODES.INERTIA;
|
|
145
138
|
}
|
|
146
139
|
|
|
147
140
|
this.trigger(this.props);
|
|
148
141
|
|
|
149
|
-
if (Math.abs(this.delta.x) < 0.1 && Math.abs(this.delta.y) < 0.1) {
|
|
142
|
+
if (Math.abs(this.props.delta.x) < 0.1 && Math.abs(this.props.delta.y) < 0.1) {
|
|
150
143
|
this.stop();
|
|
151
144
|
}
|
|
152
145
|
}
|
|
153
146
|
}
|
|
154
147
|
|
|
155
148
|
pointerHandler(props) {
|
|
156
|
-
if (this.isGrabbing) {
|
|
157
|
-
this.x = props.x;
|
|
158
|
-
this.y = props.y;
|
|
159
|
-
this.delta.x = props.delta.x;
|
|
160
|
-
this.delta.y = props.delta.y;
|
|
161
|
-
this.final.x = props.x;
|
|
162
|
-
this.final.y = props.y;
|
|
163
|
-
this.distance.x = this.x - this.origin.x;
|
|
164
|
-
this.distance.y = this.y - this.origin.y;
|
|
165
|
-
|
|
166
|
-
if (this.mode !== MODES.DRAG) {
|
|
167
|
-
this.mode = MODES.DRAG;
|
|
149
|
+
if (this.props.isGrabbing) {
|
|
150
|
+
this.props.x = props.x;
|
|
151
|
+
this.props.y = props.y;
|
|
152
|
+
this.props.delta.x = props.delta.x;
|
|
153
|
+
this.props.delta.y = props.delta.y;
|
|
154
|
+
this.props.final.x = props.x;
|
|
155
|
+
this.props.final.y = props.y;
|
|
156
|
+
this.props.distance.x = this.props.x - this.props.origin.x;
|
|
157
|
+
this.props.distance.y = this.props.y - this.props.origin.y;
|
|
158
|
+
|
|
159
|
+
if (this.props.mode !== MODES.DRAG) {
|
|
160
|
+
this.props.mode = MODES.DRAG;
|
|
168
161
|
}
|
|
169
162
|
|
|
170
163
|
this.trigger(this.props);
|
|
@@ -175,19 +168,8 @@ class Drag extends Service {
|
|
|
175
168
|
}
|
|
176
169
|
}
|
|
177
170
|
|
|
178
|
-
|
|
179
|
-
return
|
|
180
|
-
target: this.target,
|
|
181
|
-
mode: this.mode,
|
|
182
|
-
isGrabbing: this.isGrabbing,
|
|
183
|
-
hasInertia: this.hasInertia,
|
|
184
|
-
x: this.x,
|
|
185
|
-
y: this.y,
|
|
186
|
-
delta: this.delta,
|
|
187
|
-
origin: this.origin,
|
|
188
|
-
distance: this.distance,
|
|
189
|
-
final: this.final
|
|
190
|
-
};
|
|
171
|
+
updateProps() {
|
|
172
|
+
return this.props;
|
|
191
173
|
}
|
|
192
174
|
|
|
193
175
|
}
|
|
@@ -197,20 +179,15 @@ export default function useDrag(target, options) {
|
|
|
197
179
|
var drag = instances.get(target);
|
|
198
180
|
|
|
199
181
|
if (!drag) {
|
|
200
|
-
|
|
182
|
+
var instance = new Drag(target, options);
|
|
183
|
+
drag = {
|
|
184
|
+
add: instance.add.bind(instance),
|
|
185
|
+
remove: instance.remove.bind(instance),
|
|
186
|
+
has: instance.has.bind(instance),
|
|
187
|
+
props: instance.updateProps.bind(instance)
|
|
188
|
+
};
|
|
201
189
|
instances.set(target, drag);
|
|
202
190
|
}
|
|
203
191
|
|
|
204
|
-
|
|
205
|
-
var remove = drag.remove.bind(drag);
|
|
206
|
-
var has = drag.has.bind(drag);
|
|
207
|
-
|
|
208
|
-
var props = () => drag.props;
|
|
209
|
-
|
|
210
|
-
return {
|
|
211
|
-
add,
|
|
212
|
-
remove,
|
|
213
|
-
has,
|
|
214
|
-
props
|
|
215
|
-
};
|
|
192
|
+
return drag;
|
|
216
193
|
}
|
package/services/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type ServiceInterface = {
|
|
1
|
+
export type ServiceInterface<T> = {
|
|
2
2
|
/**
|
|
3
3
|
* Remove a function from the resize service by its key.
|
|
4
4
|
*/
|
|
@@ -6,11 +6,15 @@ export type ServiceInterface = {
|
|
|
6
6
|
/**
|
|
7
7
|
* Add a callback to the service. The callback will receive the current service props as parameter.
|
|
8
8
|
*/
|
|
9
|
-
add: (key: string, cb: (props:
|
|
9
|
+
add: (key: string, cb: (props: T) => void) => void;
|
|
10
10
|
/**
|
|
11
11
|
* Test if the service has alreaydy a callback for the given key.
|
|
12
12
|
*/
|
|
13
13
|
has: (key: string) => boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Get the service's props.
|
|
16
|
+
*/
|
|
17
|
+
props: () => T;
|
|
14
18
|
};
|
|
15
19
|
import useKey from "./key.js";
|
|
16
20
|
import usePointer from "./pointer.js";
|
package/services/key.d.ts
CHANGED
|
@@ -9,13 +9,14 @@
|
|
|
9
9
|
* props();
|
|
10
10
|
* ```
|
|
11
11
|
*
|
|
12
|
-
* @return {
|
|
12
|
+
* @return {KeyService}
|
|
13
13
|
*/
|
|
14
|
-
export default function useKey():
|
|
15
|
-
export type
|
|
14
|
+
export default function useKey(): KeyService;
|
|
15
|
+
export type KeyService = import('./index').ServiceInterface<KeyServiceProps>;
|
|
16
16
|
export type KeyServiceProps = {
|
|
17
17
|
event: KeyboardEvent;
|
|
18
18
|
triggered: number;
|
|
19
|
+
direction: 'up' | 'down' | 'none';
|
|
19
20
|
isUp: boolean;
|
|
20
21
|
isDown: boolean;
|
|
21
22
|
ENTER: boolean;
|
|
@@ -27,13 +28,3 @@ export type KeyServiceProps = {
|
|
|
27
28
|
RIGHT: boolean;
|
|
28
29
|
DOWN: boolean;
|
|
29
30
|
};
|
|
30
|
-
export type KeyService = {
|
|
31
|
-
/**
|
|
32
|
-
* Add a function to the resize service. The key must be uniq.
|
|
33
|
-
*/
|
|
34
|
-
add: (key: string, callback: (props: KeyServiceProps) => void) => void;
|
|
35
|
-
/**
|
|
36
|
-
* Get the current values of the resize service props.
|
|
37
|
-
*/
|
|
38
|
-
props: () => KeyServiceProps;
|
|
39
|
-
};
|
package/services/key.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
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
|
-
|
|
7
2
|
import Service from './Service.js';
|
|
8
3
|
import keyCodes from '../utils/keyCodes.js';
|
|
9
4
|
|
|
@@ -11,79 +6,83 @@ class Key extends Service {
|
|
|
11
6
|
constructor() {
|
|
12
7
|
super(...arguments);
|
|
13
8
|
|
|
14
|
-
_defineProperty(this, "
|
|
15
|
-
|
|
16
|
-
_defineProperty(this, "
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
_defineProperty(this, "previousEvent", void 0);
|
|
10
|
+
|
|
11
|
+
_defineProperty(this, "props", {
|
|
12
|
+
event: null,
|
|
13
|
+
triggered: 0,
|
|
14
|
+
isUp: false,
|
|
15
|
+
isDown: false,
|
|
16
|
+
ENTER: false,
|
|
17
|
+
SPACE: false,
|
|
18
|
+
TAB: false,
|
|
19
|
+
ESC: false,
|
|
20
|
+
LEFT: false,
|
|
21
|
+
UP: false,
|
|
22
|
+
RIGHT: false,
|
|
23
|
+
DOWN: false,
|
|
24
|
+
direction: 'none'
|
|
25
|
+
});
|
|
19
26
|
}
|
|
20
27
|
|
|
21
28
|
init() {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
29
|
+
document.addEventListener('keydown', this);
|
|
30
|
+
document.addEventListener('keyup', this);
|
|
31
|
+
}
|
|
26
32
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
document.addEventListener('keyup', this.handler, {
|
|
31
|
-
passive: false
|
|
32
|
-
});
|
|
33
|
-
return this;
|
|
33
|
+
handleEvent(event) {
|
|
34
|
+
this.updateProps(event);
|
|
35
|
+
this.trigger(this.props);
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
kill() {
|
|
37
|
-
document.removeEventListener('keydown', this
|
|
38
|
-
document.removeEventListener('keyup', this
|
|
39
|
-
return this;
|
|
39
|
+
document.removeEventListener('keydown', this);
|
|
40
|
+
document.removeEventListener('keyup', this);
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
var
|
|
43
|
+
updateProps(event) {
|
|
44
|
+
var _this$previousEvent;
|
|
45
|
+
|
|
46
|
+
this.props.event = event;
|
|
47
|
+
Object.entries(keyCodes).forEach(_ref => {
|
|
44
48
|
var [name, code] = _ref;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}, {});
|
|
49
|
+
this.props[name] = code === event.keyCode;
|
|
50
|
+
});
|
|
48
51
|
|
|
49
|
-
if (!this.previousEvent
|
|
50
|
-
this.triggered = 0;
|
|
52
|
+
if (!this.previousEvent) {
|
|
53
|
+
this.props.triggered = 0;
|
|
51
54
|
}
|
|
52
55
|
|
|
53
|
-
if (this.event.type === 'keydown' && this.previousEvent.type === 'keydown') {
|
|
54
|
-
this.triggered += 1;
|
|
56
|
+
if (this.props.event.type === 'keydown' && ((_this$previousEvent = this.previousEvent) === null || _this$previousEvent === void 0 ? void 0 : _this$previousEvent.type) === 'keydown') {
|
|
57
|
+
this.props.triggered += 1;
|
|
55
58
|
} else {
|
|
56
|
-
this.triggered = 1;
|
|
59
|
+
this.props.triggered = 1;
|
|
57
60
|
}
|
|
58
61
|
|
|
59
|
-
this.previousEvent = this.event;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
isUp: this.event.type === 'keyup',
|
|
65
|
-
isDown: this.event.type === 'keydown'
|
|
66
|
-
}, keys);
|
|
62
|
+
this.previousEvent = this.props.event;
|
|
63
|
+
this.props.direction = this.props.event.type === 'keydown' ? 'down' : 'up';
|
|
64
|
+
this.props.isUp = this.props.event.type === 'keyup';
|
|
65
|
+
this.props.isDown = this.props.event.type === 'keydown';
|
|
66
|
+
return this.props;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
var
|
|
71
|
+
var instance;
|
|
72
|
+
var key;
|
|
72
73
|
export default function useKey() {
|
|
73
74
|
if (!key) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
var add = key.add.bind(key);
|
|
78
|
-
var remove = key.remove.bind(key);
|
|
79
|
-
var has = key.has.bind(key);
|
|
75
|
+
if (!instance) {
|
|
76
|
+
instance = new Key();
|
|
77
|
+
}
|
|
80
78
|
|
|
81
|
-
|
|
79
|
+
key = {
|
|
80
|
+
add: instance.add.bind(instance),
|
|
81
|
+
remove: instance.remove.bind(instance),
|
|
82
|
+
has: instance.has.bind(instance),
|
|
83
|
+
props: instance.updateProps.bind(instance)
|
|
84
|
+
};
|
|
85
|
+
}
|
|
82
86
|
|
|
83
|
-
return
|
|
84
|
-
add,
|
|
85
|
-
remove,
|
|
86
|
-
has,
|
|
87
|
-
props
|
|
88
|
-
};
|
|
87
|
+
return key;
|
|
89
88
|
}
|
package/services/load.d.ts
CHANGED
|
@@ -9,20 +9,10 @@
|
|
|
9
9
|
* props();
|
|
10
10
|
* ```
|
|
11
11
|
*
|
|
12
|
-
* @return {
|
|
12
|
+
* @return {LoadService}
|
|
13
13
|
*/
|
|
14
|
-
export default function useLoad():
|
|
15
|
-
export type
|
|
14
|
+
export default function useLoad(): LoadService;
|
|
15
|
+
export type LoadService = import('./index').ServiceInterface<LoadServiceProps>;
|
|
16
16
|
export type LoadServiceProps = {
|
|
17
17
|
time: DOMHighResTimeStamp;
|
|
18
18
|
};
|
|
19
|
-
export type LoadService = {
|
|
20
|
-
/**
|
|
21
|
-
* Add a function to the resize service. The key must be uniq.
|
|
22
|
-
*/
|
|
23
|
-
add: (key: string, callback: (props: LoadServiceProps) => void) => void;
|
|
24
|
-
/**
|
|
25
|
-
* Get the current values of the resize service props.
|
|
26
|
-
*/
|
|
27
|
-
props: () => LoadServiceProps;
|
|
28
|
-
};
|
package/services/load.js
CHANGED
|
@@ -1,44 +1,50 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
1
2
|
import Service from './Service.js';
|
|
2
3
|
|
|
3
4
|
class Load extends Service {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
|
|
8
|
+
_defineProperty(this, "props", {
|
|
9
|
+
time: window.performance.now()
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
4
13
|
init() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
14
|
+
window.addEventListener('load', this);
|
|
15
|
+
}
|
|
8
16
|
|
|
9
|
-
|
|
10
|
-
|
|
17
|
+
handleEvent() {
|
|
18
|
+
this.updateProps();
|
|
19
|
+
this.trigger(this.props);
|
|
11
20
|
}
|
|
12
21
|
|
|
13
22
|
kill() {
|
|
14
|
-
window.removeEventListener('load', this
|
|
15
|
-
return this;
|
|
23
|
+
window.removeEventListener('load', this);
|
|
16
24
|
}
|
|
17
25
|
|
|
18
|
-
|
|
19
|
-
|
|
26
|
+
updateProps() {
|
|
27
|
+
this.props.time = window.performance.now();
|
|
28
|
+
return this.props;
|
|
20
29
|
}
|
|
21
30
|
|
|
22
31
|
}
|
|
23
32
|
|
|
24
|
-
var instance
|
|
33
|
+
var instance;
|
|
34
|
+
var load;
|
|
25
35
|
export default function useLoad() {
|
|
26
|
-
if (!
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
if (!load) {
|
|
37
|
+
if (!instance) {
|
|
38
|
+
instance = new Load();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
load = {
|
|
42
|
+
add: instance.add.bind(instance),
|
|
43
|
+
remove: instance.remove.bind(instance),
|
|
44
|
+
has: instance.has.bind(instance),
|
|
45
|
+
props: instance.updateProps.bind(instance)
|
|
46
|
+
};
|
|
36
47
|
}
|
|
37
48
|
|
|
38
|
-
return
|
|
39
|
-
add,
|
|
40
|
-
remove,
|
|
41
|
-
has,
|
|
42
|
-
props
|
|
43
|
-
};
|
|
49
|
+
return load;
|
|
44
50
|
}
|
package/services/pointer.d.ts
CHANGED
|
@@ -9,10 +9,11 @@
|
|
|
9
9
|
* props();
|
|
10
10
|
* ```
|
|
11
11
|
*
|
|
12
|
-
* @
|
|
12
|
+
* @todo Add element as parameter to get the pointer position relatively from.
|
|
13
|
+
* @return {PointerService}
|
|
13
14
|
*/
|
|
14
|
-
export default function usePointer():
|
|
15
|
-
export type
|
|
15
|
+
export default function usePointer(): PointerService;
|
|
16
|
+
export type PointerService = import('./index').ServiceInterface<PointerServiceProps>;
|
|
16
17
|
export type PointerServiceProps = {
|
|
17
18
|
event: MouseEvent | TouchEvent;
|
|
18
19
|
isDown: boolean;
|
|
@@ -39,13 +40,3 @@ export type PointerServiceProps = {
|
|
|
39
40
|
y: number;
|
|
40
41
|
};
|
|
41
42
|
};
|
|
42
|
-
export type PointerService = {
|
|
43
|
-
/**
|
|
44
|
-
* Add a function to the resize service. The key must be uniq.
|
|
45
|
-
*/
|
|
46
|
-
add: (key: string, callback: (props: PointerServiceProps) => void) => void;
|
|
47
|
-
/**
|
|
48
|
-
* Get the current values of the resize service props.
|
|
49
|
-
*/
|
|
50
|
-
props: () => PointerServiceProps;
|
|
51
|
-
};
|