@enact/core 4.5.2 → 4.5.3
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/CHANGELOG.md +4 -0
- package/dispatcher/dispatcher.js +8 -27
- package/dispatcher/listeners.js +0 -8
- package/dispatcher/tests/dispatcher-specs.js +0 -3
- package/handle/handle.js +33 -90
- package/handle/tests/handle-specs.js +21 -42
- package/hoc/hoc.js +2 -13
- package/hoc/tests/hoc-specs.js +0 -23
- package/internal/ApiDecorator/ApiDecorator.js +4 -34
- package/internal/ApiDecorator/tests/ApiDecorator-specs.js +0 -24
- package/internal/Registry/Registry.js +0 -7
- package/internal/Registry/tests/Registry-specs.js +10 -70
- package/internal/deprecate/deprecate.js +8 -22
- package/internal/prop-types/prop-types.js +3 -20
- package/keymap/index.js +2 -3
- package/keymap/keymap.js +10 -18
- package/keymap/tests/keymap-specs.js +0 -3
- package/kind/computed.js +2 -9
- package/kind/kind.js +14 -53
- package/kind/styles.js +6 -19
- package/kind/tests/computed-specs.js +4 -6
- package/kind/tests/kind-specs.js +9 -44
- package/kind/tests/styles-specs.js +12 -7
- package/kind/util.js +0 -2
- package/package.json +7 -1
- package/platform/platform.js +51 -57
- package/platform/tests/platform-specs.js +2 -2
- package/snapshot/snapshot.js +4 -9
- package/useChainRefs/tests/useChainRefs-specs.js +0 -14
- package/useChainRefs/useChainRefs.js +3 -11
- package/useClass/tests/useClass-specs.js +6 -21
- package/useClass/useClass.js +0 -8
- package/useHandlers/Handlers.js +0 -11
- package/useHandlers/tests/useHandlers-specs.js +11 -23
- package/useHandlers/useHandlers.js +0 -5
- package/usePublicClassNames/tests/usePublicClassNames-specs.js +21 -28
- package/usePublicClassNames/usePublicClassNames.js +4 -10
- package/util/Job.js +1 -43
- package/util/tests/Job-specs.js +0 -14
- package/util/tests/util-specs.js +9 -10
- package/util/util.js +14 -54
package/platform/platform.js
CHANGED
|
@@ -4,66 +4,58 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.platform = exports.parseUserAgent = exports.detect = exports["default"] = void 0;
|
|
7
|
-
|
|
8
7
|
var _uniq = _interopRequireDefault(require("ramda/src/uniq"));
|
|
9
|
-
|
|
10
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
11
|
-
|
|
12
9
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
13
|
-
|
|
14
10
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
15
|
-
|
|
16
11
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
17
|
-
|
|
18
12
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
19
|
-
|
|
20
13
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
21
|
-
|
|
22
14
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
23
|
-
|
|
24
15
|
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; }
|
|
25
|
-
|
|
26
16
|
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; }
|
|
27
|
-
|
|
28
17
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
29
|
-
|
|
30
18
|
var hasGesture = function hasGesture() {
|
|
31
19
|
return Boolean('ongesturestart' in window || 'onmsgesturestart' in window && (window.navigator.msMaxTouchPoints > 1 || window.navigator.maxTouchPoints > 1));
|
|
32
20
|
};
|
|
33
|
-
|
|
34
21
|
var hasTouch = function hasTouch() {
|
|
35
22
|
return Boolean('TouchEvent' in window || 'ontouchstart' in window || window.navigator.msMaxTouchPoints || window.navigator.msManipulationViewsEnabled && window.navigator.maxTouchPoints);
|
|
36
|
-
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// Adapted from https://patrickhlauke.github.io/touch/touchscreen-detection/
|
|
37
26
|
// I've omitted the touch event fallback since that is covered by hasTouch and we're less concerned
|
|
38
27
|
// with legacy browsers used in touchscreen environments.
|
|
39
|
-
|
|
40
|
-
|
|
41
28
|
var hasTouchScreen = function hasTouchScreen() {
|
|
42
|
-
return (
|
|
43
|
-
|
|
29
|
+
return (
|
|
30
|
+
// if Pointer Events are supported, just check maxTouchPoints
|
|
31
|
+
window.PointerEvent && 'maxTouchPoints' in window.navigator && window.navigator.maxTouchPoints > 0 ||
|
|
32
|
+
// check for any-pointer:coarse which mostly means touchscreen
|
|
44
33
|
window.matchMedia && window.matchMedia('(any-pointer:coarse)').matches
|
|
45
34
|
);
|
|
46
35
|
};
|
|
47
|
-
|
|
48
36
|
var webOSVersion = {
|
|
49
37
|
38: 3,
|
|
50
38
|
53: 4,
|
|
51
39
|
68: 5,
|
|
52
40
|
79: 6
|
|
53
41
|
};
|
|
54
|
-
var platforms = [
|
|
42
|
+
var platforms = [
|
|
43
|
+
// Windows Phone 7 - 10
|
|
55
44
|
{
|
|
56
45
|
platform: 'windowsPhone',
|
|
57
46
|
regex: /Windows Phone (?:OS )?(\d+)[.\d]+/
|
|
58
|
-
},
|
|
47
|
+
},
|
|
48
|
+
// Android 4+ using Chrome
|
|
59
49
|
{
|
|
60
50
|
platform: 'androidChrome',
|
|
61
51
|
regex: /Android .* Chrome\/(\d+)[.\d]+/
|
|
62
|
-
},
|
|
52
|
+
},
|
|
53
|
+
// Android 2 - 4
|
|
63
54
|
{
|
|
64
55
|
platform: 'android',
|
|
65
56
|
regex: /Android(?:\s|\/)(\d+)/
|
|
66
|
-
},
|
|
57
|
+
},
|
|
58
|
+
// Kindle Fire
|
|
67
59
|
// Force version to 2, (desktop mode does not list android version)
|
|
68
60
|
{
|
|
69
61
|
platform: 'android',
|
|
@@ -72,7 +64,8 @@ var platforms = [// Windows Phone 7 - 10
|
|
|
72
64
|
extra: {
|
|
73
65
|
silk: 1
|
|
74
66
|
}
|
|
75
|
-
},
|
|
67
|
+
},
|
|
68
|
+
// Kindle Fire HD (Silk versions 2 or 3)
|
|
76
69
|
// Force version to 4
|
|
77
70
|
{
|
|
78
71
|
platform: 'android',
|
|
@@ -88,24 +81,29 @@ var platforms = [// Windows Phone 7 - 10
|
|
|
88
81
|
extra: {
|
|
89
82
|
silk: 3
|
|
90
83
|
}
|
|
91
|
-
},
|
|
84
|
+
},
|
|
85
|
+
// IE 8 - 10
|
|
92
86
|
{
|
|
93
87
|
platform: 'ie',
|
|
94
88
|
regex: /MSIE (\d+)/
|
|
95
|
-
},
|
|
89
|
+
},
|
|
90
|
+
// IE 11
|
|
96
91
|
{
|
|
97
92
|
platform: 'ie',
|
|
98
93
|
regex: /Trident\/.*; rv:(\d+)/
|
|
99
|
-
},
|
|
94
|
+
},
|
|
95
|
+
// Edge
|
|
100
96
|
{
|
|
101
97
|
platform: 'edge',
|
|
102
98
|
regex: /Edge\/(\d+)/
|
|
103
|
-
},
|
|
99
|
+
},
|
|
100
|
+
// iOS 3 - 5
|
|
104
101
|
// Apple likes to make this complicated
|
|
105
102
|
{
|
|
106
103
|
platform: 'ios',
|
|
107
104
|
regex: /iP(?:hone|ad;(?: U;)? CPU) OS (\d+)/
|
|
108
|
-
},
|
|
105
|
+
},
|
|
106
|
+
// LG webOS
|
|
109
107
|
{
|
|
110
108
|
platform: 'webos',
|
|
111
109
|
regex: /Web0S;.*Safari\/537.41/,
|
|
@@ -117,12 +115,14 @@ var platforms = [// Windows Phone 7 - 10
|
|
|
117
115
|
}, {
|
|
118
116
|
platform: 'webos',
|
|
119
117
|
regex: /Web0S;.*Chrome\/(\d+)/
|
|
120
|
-
},
|
|
118
|
+
},
|
|
119
|
+
// LG webOS of indeterminate versionre
|
|
121
120
|
{
|
|
122
121
|
platform: 'webos',
|
|
123
122
|
regex: /Web0S;/,
|
|
124
123
|
forceVersion: -1
|
|
125
|
-
},
|
|
124
|
+
},
|
|
125
|
+
// LuneOS
|
|
126
126
|
{
|
|
127
127
|
platform: 'webos',
|
|
128
128
|
regex: /LuneOS/,
|
|
@@ -130,7 +130,8 @@ var platforms = [// Windows Phone 7 - 10
|
|
|
130
130
|
extra: {
|
|
131
131
|
luneos: 1
|
|
132
132
|
}
|
|
133
|
-
},
|
|
133
|
+
},
|
|
134
|
+
// Palm/HP/Open webOS
|
|
134
135
|
{
|
|
135
136
|
platform: 'webos',
|
|
136
137
|
regex: /WebAppManager|Isis|webOS\./,
|
|
@@ -159,47 +160,52 @@ var platforms = [// Windows Phone 7 - 10
|
|
|
159
160
|
extra: {
|
|
160
161
|
legacy: 3
|
|
161
162
|
}
|
|
162
|
-
},
|
|
163
|
+
},
|
|
164
|
+
// desktop Safari
|
|
163
165
|
{
|
|
164
166
|
platform: 'safari',
|
|
165
167
|
regex: /Version\/(\d+)[.\d]+\s+Safari/
|
|
166
|
-
},
|
|
168
|
+
},
|
|
169
|
+
// desktop Chrome
|
|
167
170
|
{
|
|
168
171
|
platform: 'chrome',
|
|
169
172
|
regex: /Chrome\/(\d+)[.\d]+/
|
|
170
|
-
},
|
|
173
|
+
},
|
|
174
|
+
// Firefox on Android
|
|
171
175
|
{
|
|
172
176
|
platform: 'androidFirefox',
|
|
173
177
|
regex: /Android;.*Firefox\/(\d+)/
|
|
174
|
-
},
|
|
178
|
+
},
|
|
179
|
+
// FirefoxOS
|
|
175
180
|
{
|
|
176
181
|
platform: 'firefoxOS',
|
|
177
182
|
regex: /Mobile;.*Firefox\/(\d+)/
|
|
178
|
-
},
|
|
183
|
+
},
|
|
184
|
+
// desktop Firefox
|
|
179
185
|
{
|
|
180
186
|
platform: 'firefox',
|
|
181
187
|
regex: /Firefox\/(\d+)/
|
|
182
|
-
},
|
|
188
|
+
},
|
|
189
|
+
// Blackberry Playbook
|
|
183
190
|
{
|
|
184
191
|
platform: 'blackberry',
|
|
185
192
|
regex: /PlayBook/i,
|
|
186
193
|
forceVersion: 2
|
|
187
|
-
},
|
|
194
|
+
},
|
|
195
|
+
// Blackberry 10+
|
|
188
196
|
{
|
|
189
197
|
platform: 'blackberry',
|
|
190
198
|
regex: /BB1\d;.*Version\/(\d+\.\d+)/
|
|
191
|
-
},
|
|
199
|
+
},
|
|
200
|
+
// Tizen
|
|
192
201
|
{
|
|
193
202
|
platform: 'tizen',
|
|
194
203
|
regex: /Tizen (\d+)/
|
|
195
204
|
}];
|
|
196
|
-
|
|
197
205
|
var ua = function ua() {
|
|
198
206
|
return window.navigator ? window.navigator.userAgent : '';
|
|
199
207
|
};
|
|
200
|
-
|
|
201
208
|
var _platform;
|
|
202
|
-
|
|
203
209
|
var parseUserAgent = function parseUserAgent(userAgent) {
|
|
204
210
|
var plat = {
|
|
205
211
|
gesture: hasGesture(),
|
|
@@ -208,38 +214,31 @@ var parseUserAgent = function parseUserAgent(userAgent) {
|
|
|
208
214
|
touchscreen: hasTouchScreen(),
|
|
209
215
|
unknown: true
|
|
210
216
|
};
|
|
211
|
-
|
|
212
217
|
for (var i = 0, p, m, v; p = platforms[i]; i++) {
|
|
213
218
|
m = p.regex.exec(userAgent);
|
|
214
|
-
|
|
215
219
|
if (m) {
|
|
216
220
|
plat.unknown = false;
|
|
217
|
-
|
|
218
221
|
if ('forceVersion' in p) {
|
|
219
222
|
v = p.forceVersion;
|
|
220
223
|
} else if (p.platform === 'webos') {
|
|
221
224
|
v = webOSVersion[m[1]] || -1;
|
|
222
|
-
|
|
223
225
|
if (v >= 7 || v === -1) {
|
|
224
226
|
plat.chrome = Number(m[1]);
|
|
225
227
|
}
|
|
226
228
|
} else {
|
|
227
229
|
v = Number(m[1]);
|
|
228
230
|
}
|
|
229
|
-
|
|
230
231
|
plat[p.platform] = v;
|
|
231
|
-
|
|
232
232
|
if (p.extra) {
|
|
233
233
|
plat = _objectSpread(_objectSpread({}, plat), p.extra);
|
|
234
234
|
}
|
|
235
|
-
|
|
236
235
|
plat.platformName = p.platform;
|
|
237
236
|
break;
|
|
238
237
|
}
|
|
239
238
|
}
|
|
240
|
-
|
|
241
239
|
return plat;
|
|
242
240
|
};
|
|
241
|
+
|
|
243
242
|
/**
|
|
244
243
|
* @typedef {Object} PlatformDescription
|
|
245
244
|
* @property {Object} [extra] - Additional information about the detected platform
|
|
@@ -262,10 +261,7 @@ var parseUserAgent = function parseUserAgent(userAgent) {
|
|
|
262
261
|
* @memberof core/platform
|
|
263
262
|
* @public
|
|
264
263
|
*/
|
|
265
|
-
|
|
266
|
-
|
|
267
264
|
exports.parseUserAgent = parseUserAgent;
|
|
268
|
-
|
|
269
265
|
var detect = function detect() {
|
|
270
266
|
if (_platform) {
|
|
271
267
|
// if we've already determined the platform, we'll use that determination
|
|
@@ -278,10 +274,10 @@ var detect = function detect() {
|
|
|
278
274
|
unknown: true
|
|
279
275
|
};
|
|
280
276
|
}
|
|
281
|
-
|
|
282
277
|
var userAgent = ua();
|
|
283
278
|
return _platform = parseUserAgent(userAgent);
|
|
284
279
|
};
|
|
280
|
+
|
|
285
281
|
/**
|
|
286
282
|
* Provides basic information about the running platform.
|
|
287
283
|
*
|
|
@@ -289,8 +285,6 @@ var detect = function detect() {
|
|
|
289
285
|
* @memberof core/platform
|
|
290
286
|
* @public
|
|
291
287
|
*/
|
|
292
|
-
|
|
293
|
-
|
|
294
288
|
exports.detect = detect;
|
|
295
289
|
var platform = {};
|
|
296
290
|
exports.platform = platform;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _platform = require("../platform");
|
|
4
|
-
|
|
5
4
|
describe('platform', function () {
|
|
6
5
|
describe('webOS', function () {
|
|
7
6
|
// From http://webostv.developer.lge.com/discover/specifications/web-engine/
|
|
@@ -11,8 +10,9 @@ describe('platform', function () {
|
|
|
11
10
|
var webOSTV4 = 'Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.1785.34 Safari/537.36 WebAppManager';
|
|
12
11
|
var webOSTV3 = 'Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.1.1 Chrome/38.0.2125.122 Safari/537.36 WebAppManager';
|
|
13
12
|
var webOSTV2 = 'Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/538.2 (KHTML, like Gecko) Large Screen WebAppManager Safari/538.2';
|
|
14
|
-
var webOSTV1 = 'Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/537.41 (KHTML, like Gecko) Large Screen WebAppManager Safari/537.41';
|
|
13
|
+
var webOSTV1 = 'Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/537.41 (KHTML, like Gecko) Large Screen WebAppManager Safari/537.41';
|
|
15
14
|
|
|
15
|
+
// From https://developers.whatismybrowser.com/useragents/explore/operating_system_name/webos/
|
|
16
16
|
var LuneOS2 = 'Mozilla/5.0 (LuneOS, like webOS/3.0.5; Tablet) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.9.2 Chrome/56.0.2924.103 Safari/537.36';
|
|
17
17
|
var LuneOS1 = 'Mozilla/5.0 (LuneOS, like webOS/3.0.5; Tablet) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.6.2 Chrome/45.0.2454.103 Safari/537.36';
|
|
18
18
|
var webOS10 = 'Mozilla/5.0 (webOS/1.0; U; en-US) AppleWebKit/525.27.1 (KHTML, like Geko) Version/1.0 Safari/525.27.1 Pre/1.0';
|
package/snapshot/snapshot.js
CHANGED
|
@@ -7,11 +7,8 @@ exports["default"] = void 0;
|
|
|
7
7
|
exports.isWindowReady = isWindowReady;
|
|
8
8
|
exports.onWindowReady = onWindowReady;
|
|
9
9
|
exports.windowReady = windowReady;
|
|
10
|
-
|
|
11
10
|
var _invariant = _interopRequireDefault(require("invariant"));
|
|
12
|
-
|
|
13
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
14
|
-
|
|
15
12
|
/**
|
|
16
13
|
* Utilities to facilitate integration with v8 snapshot builds
|
|
17
14
|
*
|
|
@@ -21,7 +18,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
|
|
|
21
18
|
* @exports windowReady
|
|
22
19
|
* @public
|
|
23
20
|
*/
|
|
21
|
+
|
|
24
22
|
var windowCallbacks = [];
|
|
23
|
+
|
|
25
24
|
/**
|
|
26
25
|
* Determines if the `window` is available
|
|
27
26
|
*
|
|
@@ -31,10 +30,10 @@ var windowCallbacks = [];
|
|
|
31
30
|
* @memberof core/snapshot
|
|
32
31
|
* @public
|
|
33
32
|
*/
|
|
34
|
-
|
|
35
33
|
function isWindowReady() {
|
|
36
34
|
return typeof window !== 'undefined';
|
|
37
35
|
}
|
|
36
|
+
|
|
38
37
|
/**
|
|
39
38
|
* Executes a callback, such as registering event handlers, when a valid `window` is available.
|
|
40
39
|
*
|
|
@@ -56,8 +55,6 @@ function isWindowReady() {
|
|
|
56
55
|
* @memberof core/snapshot
|
|
57
56
|
* @public
|
|
58
57
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
58
|
function onWindowReady(callback) {
|
|
62
59
|
if (isWindowReady()) {
|
|
63
60
|
callback();
|
|
@@ -65,6 +62,7 @@ function onWindowReady(callback) {
|
|
|
65
62
|
windowCallbacks.push(callback);
|
|
66
63
|
}
|
|
67
64
|
}
|
|
65
|
+
|
|
68
66
|
/**
|
|
69
67
|
* Executes all queued window callbacks.
|
|
70
68
|
*
|
|
@@ -76,14 +74,11 @@ function onWindowReady(callback) {
|
|
|
76
74
|
* @memberof core/snapshot
|
|
77
75
|
* @public
|
|
78
76
|
*/
|
|
79
|
-
|
|
80
|
-
|
|
81
77
|
function windowReady() {
|
|
82
78
|
!isWindowReady() ? process.env.NODE_ENV !== "production" ? (0, _invariant["default"])(false, 'windowReady cannot be run until the window is available') : (0, _invariant["default"])(false) : void 0;
|
|
83
79
|
windowCallbacks.forEach(function (f) {
|
|
84
80
|
return f();
|
|
85
81
|
});
|
|
86
82
|
}
|
|
87
|
-
|
|
88
83
|
var _default = onWindowReady;
|
|
89
84
|
exports["default"] = _default;
|
|
@@ -1,38 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
require("@testing-library/jest-dom");
|
|
4
|
-
|
|
5
4
|
var _react = require("@testing-library/react");
|
|
6
|
-
|
|
7
5
|
var _react2 = require("react");
|
|
8
|
-
|
|
9
6
|
var _useChainRefs = _interopRequireDefault(require("../useChainRefs"));
|
|
10
|
-
|
|
11
7
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
|
-
|
|
13
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
14
|
-
|
|
15
9
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
16
|
-
|
|
17
10
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
18
|
-
|
|
19
11
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
20
|
-
|
|
21
12
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
22
|
-
|
|
23
13
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
24
|
-
|
|
25
14
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
26
|
-
|
|
27
15
|
describe('useChainRefs', function () {
|
|
28
16
|
function Component(props) {
|
|
29
17
|
var ref = _useChainRefs["default"].apply(void 0, _toConsumableArray(props.refs));
|
|
30
|
-
|
|
31
18
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
32
19
|
ref: ref
|
|
33
20
|
});
|
|
34
21
|
}
|
|
35
|
-
|
|
36
22
|
test('should call a single functional ref', function () {
|
|
37
23
|
var ref = jest.fn();
|
|
38
24
|
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
@@ -6,13 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.chainRefs = chainRefs;
|
|
7
7
|
exports["default"] = void 0;
|
|
8
8
|
exports.useChainRefs = useChainRefs;
|
|
9
|
-
|
|
10
9
|
var _react = require("react");
|
|
11
|
-
|
|
12
10
|
var _warning = _interopRequireDefault(require("warning"));
|
|
13
|
-
|
|
14
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
15
|
-
|
|
16
12
|
/**
|
|
17
13
|
* Updates multiple reference callbacks or objects
|
|
18
14
|
*
|
|
@@ -21,6 +17,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
|
|
|
21
17
|
* @exports chainRefs
|
|
22
18
|
* @private
|
|
23
19
|
*/
|
|
20
|
+
|
|
24
21
|
// Safely handles functional and object refs (and ignores invalid refs)
|
|
25
22
|
function updateRef(ref, node) {
|
|
26
23
|
if (ref) {
|
|
@@ -34,6 +31,7 @@ function updateRef(ref, node) {
|
|
|
34
31
|
}
|
|
35
32
|
}
|
|
36
33
|
}
|
|
34
|
+
|
|
37
35
|
/**
|
|
38
36
|
* Creates a reference callback that updates each of the provided references
|
|
39
37
|
*
|
|
@@ -42,19 +40,17 @@ function updateRef(ref, node) {
|
|
|
42
40
|
* @returns {Function} A callback that updates each reference
|
|
43
41
|
* @public
|
|
44
42
|
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
43
|
function chainRefs() {
|
|
48
44
|
for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
49
45
|
refs[_key] = arguments[_key];
|
|
50
46
|
}
|
|
51
|
-
|
|
52
47
|
return function (node) {
|
|
53
48
|
refs.forEach(function (ref) {
|
|
54
49
|
return updateRef(ref, node);
|
|
55
50
|
});
|
|
56
51
|
};
|
|
57
52
|
}
|
|
53
|
+
|
|
58
54
|
/**
|
|
59
55
|
* Creates a memoized reference callback that updates each of the provided references
|
|
60
56
|
*
|
|
@@ -63,16 +59,12 @@ function chainRefs() {
|
|
|
63
59
|
* @returns {Function} A memoized callback that updates each reference
|
|
64
60
|
* @public
|
|
65
61
|
*/
|
|
66
|
-
|
|
67
|
-
|
|
68
62
|
function useChainRefs() {
|
|
69
63
|
for (var _len2 = arguments.length, refs = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
70
64
|
refs[_key2] = arguments[_key2];
|
|
71
65
|
}
|
|
72
|
-
|
|
73
66
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
74
67
|
return (0, _react.useCallback)(chainRefs.apply(void 0, refs), refs);
|
|
75
68
|
}
|
|
76
|
-
|
|
77
69
|
var _default = useChainRefs;
|
|
78
70
|
exports["default"] = _default;
|
|
@@ -1,28 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
require("@testing-library/jest-dom");
|
|
4
|
-
|
|
5
4
|
var _react = require("@testing-library/react");
|
|
6
|
-
|
|
7
5
|
var _useClass = _interopRequireDefault(require("../useClass"));
|
|
8
|
-
|
|
9
6
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
|
-
|
|
11
7
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
12
|
-
|
|
13
8
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
14
|
-
|
|
15
9
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
16
|
-
|
|
17
10
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
18
|
-
|
|
19
11
|
describe('useClass', function () {
|
|
20
12
|
var Class = /*#__PURE__*/_createClass(function Class(arg) {
|
|
21
13
|
_classCallCheck(this, Class);
|
|
22
|
-
|
|
23
14
|
this.arg = arg;
|
|
24
15
|
});
|
|
25
|
-
|
|
26
16
|
function Component(props) {
|
|
27
17
|
var instance = (0, _useClass["default"])(Class, props.arg);
|
|
28
18
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
@@ -31,33 +21,28 @@ describe('useClass', function () {
|
|
|
31
21
|
"data-fromprops": props.arg
|
|
32
22
|
});
|
|
33
23
|
}
|
|
34
|
-
|
|
35
24
|
test('should pass arg to Class', function () {
|
|
36
25
|
var arg = 'arg';
|
|
37
26
|
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
38
27
|
arg: arg
|
|
39
28
|
}));
|
|
40
|
-
|
|
41
29
|
var div = _react.screen.getByTestId('div');
|
|
42
|
-
|
|
43
30
|
expect(div).toHaveAttribute('data-fromclass', arg);
|
|
44
31
|
});
|
|
45
32
|
test('should use the same instance of Class across renders', function () {
|
|
46
33
|
var arg = 'arg';
|
|
47
|
-
|
|
48
34
|
var _render = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
35
|
+
arg: arg
|
|
36
|
+
})),
|
|
37
|
+
rerender = _render.rerender;
|
|
53
38
|
var div = _react.screen.getByTestId('div');
|
|
54
|
-
|
|
55
39
|
expect(div).toHaveAttribute('data-fromprops', arg);
|
|
56
40
|
rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
57
41
|
arg: "changed"
|
|
58
|
-
}));
|
|
59
|
-
// value was updated when props were updated
|
|
42
|
+
}));
|
|
60
43
|
|
|
44
|
+
// verify that the children still reflects the class value set at construction but the prop
|
|
45
|
+
// value was updated when props were updated
|
|
61
46
|
expect(div).toHaveAttribute('data-fromclass', arg);
|
|
62
47
|
expect(div).toHaveAttribute('data-fromprops', 'changed');
|
|
63
48
|
});
|
package/useClass/useClass.js
CHANGED
|
@@ -5,15 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
7
|
exports.useClass = useClass;
|
|
8
|
-
|
|
9
8
|
var _react = require("react");
|
|
10
|
-
|
|
11
9
|
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
|
12
|
-
|
|
13
10
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
14
|
-
|
|
15
11
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
16
|
-
|
|
17
12
|
/**
|
|
18
13
|
* Creates one instance of the class, `Ctor` with the provided `args`, for the life of the
|
|
19
14
|
* component.
|
|
@@ -44,14 +39,11 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Objec
|
|
|
44
39
|
*/
|
|
45
40
|
function useClass(Ctor) {
|
|
46
41
|
var ref = (0, _react.useRef)(null);
|
|
47
|
-
|
|
48
42
|
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
49
43
|
args[_key - 1] = arguments[_key];
|
|
50
44
|
}
|
|
51
|
-
|
|
52
45
|
ref.current = ref.current || _construct(Ctor, args);
|
|
53
46
|
return ref.current;
|
|
54
47
|
}
|
|
55
|
-
|
|
56
48
|
var _default = useClass;
|
|
57
49
|
exports["default"] = _default;
|
package/useHandlers/Handlers.js
CHANGED
|
@@ -4,34 +4,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = exports.Handlers = void 0;
|
|
7
|
-
|
|
8
7
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
9
|
-
|
|
10
8
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
11
|
-
|
|
12
9
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
13
|
-
|
|
14
10
|
var Handlers = /*#__PURE__*/function () {
|
|
15
11
|
function Handlers(_handlers) {
|
|
16
12
|
var _this = this;
|
|
17
|
-
|
|
18
13
|
_classCallCheck(this, Handlers);
|
|
19
|
-
|
|
20
14
|
this.props = {};
|
|
21
15
|
this.context = {};
|
|
22
16
|
this._handlers = {};
|
|
23
|
-
|
|
24
17
|
if (_handlers) {
|
|
25
18
|
Object.keys(_handlers).forEach(function (fn) {
|
|
26
19
|
_this._handlers[fn] = function (ev) {
|
|
27
20
|
return _handlers[fn](ev, _this.props, _this.context);
|
|
28
21
|
};
|
|
29
|
-
|
|
30
22
|
_this._handlers[fn].displayName = fn;
|
|
31
23
|
});
|
|
32
24
|
}
|
|
33
25
|
}
|
|
34
|
-
|
|
35
26
|
_createClass(Handlers, [{
|
|
36
27
|
key: "handlers",
|
|
37
28
|
get: function get() {
|
|
@@ -46,10 +37,8 @@ var Handlers = /*#__PURE__*/function () {
|
|
|
46
37
|
this.context = context;
|
|
47
38
|
}
|
|
48
39
|
}]);
|
|
49
|
-
|
|
50
40
|
return Handlers;
|
|
51
41
|
}();
|
|
52
|
-
|
|
53
42
|
exports.Handlers = Handlers;
|
|
54
43
|
var _default = Handlers;
|
|
55
44
|
exports["default"] = _default;
|