@khanacademy/wonder-blocks-core 11.0.1 → 12.0.0
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 +12 -0
- package/dist/components/text.d.ts +42 -42
- package/dist/es/index.js +18 -2
- package/dist/hooks/use-on-mount-effect.d.ts +24 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +18 -1
- package/dist/util/keys.d.ts +12 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-core
|
|
2
2
|
|
|
3
|
+
## 12.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 0199324d: Fixes keyboard tests in Dropdown and Clickable with specific key events. We now check `event.key` instead of `event.which` or `event.keyCode` to remove deprecated event properties and match the keys returned from Testing Library/userEvent.
|
|
8
|
+
|
|
9
|
+
## 11.1.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 7516b239: Update useOnMountEffect to pass isMountedRef to callback
|
|
14
|
+
|
|
3
15
|
## 11.0.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -13,54 +13,54 @@ import * as React from "react";
|
|
|
13
13
|
*/
|
|
14
14
|
declare const Text: React.ForwardRefExoticComponent<{
|
|
15
15
|
children?: React.ReactNode;
|
|
16
|
-
style?: import("
|
|
17
|
-
testId?: string
|
|
18
|
-
lang?: string
|
|
19
|
-
className?: string
|
|
20
|
-
htmlFor?: string
|
|
21
|
-
tabIndex?: number
|
|
22
|
-
id?: string
|
|
23
|
-
title?: string
|
|
24
|
-
"data-modal-launcher-portal"?: boolean
|
|
25
|
-
"data-placement"?: string
|
|
16
|
+
style?: import("..").StyleType;
|
|
17
|
+
testId?: string;
|
|
18
|
+
lang?: string;
|
|
19
|
+
className?: string;
|
|
20
|
+
htmlFor?: string;
|
|
21
|
+
tabIndex?: number;
|
|
22
|
+
id?: string;
|
|
23
|
+
title?: string;
|
|
24
|
+
"data-modal-launcher-portal"?: boolean;
|
|
25
|
+
"data-placement"?: string;
|
|
26
26
|
} & Readonly<import("..").AriaAttributes> & Readonly<{
|
|
27
|
-
role?: import("..").AriaRole
|
|
27
|
+
role?: import("..").AriaRole;
|
|
28
28
|
}> & {
|
|
29
|
-
onMouseDown?: (
|
|
30
|
-
onMouseUp?: (
|
|
31
|
-
onMouseMove?: (
|
|
32
|
-
onClick?: (
|
|
33
|
-
onDoubleClick?: (
|
|
34
|
-
onMouseEnter?: (
|
|
35
|
-
onMouseLeave?: (
|
|
36
|
-
onMouseOut?: (
|
|
37
|
-
onMouseOver?: (
|
|
38
|
-
onDrag?: (
|
|
39
|
-
onDragEnd?: (
|
|
40
|
-
onDragEnter?: (
|
|
41
|
-
onDragExit?: (
|
|
42
|
-
onDragLeave?: (
|
|
43
|
-
onDragOver?: (
|
|
44
|
-
onDragStart?: (
|
|
45
|
-
onDrop?: (
|
|
29
|
+
onMouseDown?: (e: React.MouseEvent) => unknown;
|
|
30
|
+
onMouseUp?: (e: React.MouseEvent) => unknown;
|
|
31
|
+
onMouseMove?: (e: React.MouseEvent) => unknown;
|
|
32
|
+
onClick?: (e: React.MouseEvent) => unknown;
|
|
33
|
+
onDoubleClick?: (e: React.MouseEvent) => unknown;
|
|
34
|
+
onMouseEnter?: (e: React.MouseEvent) => unknown;
|
|
35
|
+
onMouseLeave?: (e: React.MouseEvent) => unknown;
|
|
36
|
+
onMouseOut?: (e: React.MouseEvent) => unknown;
|
|
37
|
+
onMouseOver?: (e: React.MouseEvent) => unknown;
|
|
38
|
+
onDrag?: (e: React.MouseEvent) => unknown;
|
|
39
|
+
onDragEnd?: (e: React.MouseEvent) => unknown;
|
|
40
|
+
onDragEnter?: (e: React.MouseEvent) => unknown;
|
|
41
|
+
onDragExit?: (e: React.MouseEvent) => unknown;
|
|
42
|
+
onDragLeave?: (e: React.MouseEvent) => unknown;
|
|
43
|
+
onDragOver?: (e: React.MouseEvent) => unknown;
|
|
44
|
+
onDragStart?: (e: React.MouseEvent) => unknown;
|
|
45
|
+
onDrop?: (e: React.MouseEvent) => unknown;
|
|
46
46
|
} & {
|
|
47
|
-
onKeyDown?: (
|
|
48
|
-
onKeyPress?: (
|
|
49
|
-
onKeyUp?: (
|
|
47
|
+
onKeyDown?: (e: React.KeyboardEvent) => unknown;
|
|
48
|
+
onKeyPress?: (e: React.KeyboardEvent) => unknown;
|
|
49
|
+
onKeyUp?: (e: React.KeyboardEvent) => unknown;
|
|
50
50
|
} & {
|
|
51
|
-
onChange?: (
|
|
52
|
-
onInput?: (
|
|
53
|
-
onInvalid?: (
|
|
54
|
-
onSubmit?: (
|
|
51
|
+
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => unknown;
|
|
52
|
+
onInput?: (e: React.ChangeEvent<HTMLInputElement>) => unknown;
|
|
53
|
+
onInvalid?: (e: React.ChangeEvent<HTMLInputElement>) => unknown;
|
|
54
|
+
onSubmit?: (e: React.ChangeEvent<HTMLInputElement>) => unknown;
|
|
55
55
|
} & {
|
|
56
|
-
onTouchCancel?: (
|
|
57
|
-
onTouchEnd?: (
|
|
58
|
-
onTouchMove?: (
|
|
59
|
-
onTouchStart?: (
|
|
56
|
+
onTouchCancel?: (e: React.TouchEvent) => unknown;
|
|
57
|
+
onTouchEnd?: (e: React.TouchEvent) => unknown;
|
|
58
|
+
onTouchMove?: (e: React.TouchEvent) => unknown;
|
|
59
|
+
onTouchStart?: (e: React.TouchEvent) => unknown;
|
|
60
60
|
} & {
|
|
61
|
-
onFocus?: (
|
|
62
|
-
onBlur?: (
|
|
61
|
+
onFocus?: (e: React.FocusEvent) => unknown;
|
|
62
|
+
onBlur?: (e: React.FocusEvent) => unknown;
|
|
63
63
|
} & {
|
|
64
|
-
tag?: string
|
|
64
|
+
tag?: string;
|
|
65
65
|
} & React.RefAttributes<unknown>>;
|
|
66
66
|
export default Text;
|
package/dist/es/index.js
CHANGED
|
@@ -291,7 +291,14 @@ function useLatestRef(value) {
|
|
|
291
291
|
}
|
|
292
292
|
|
|
293
293
|
const useOnMountEffect = callback => {
|
|
294
|
-
React.
|
|
294
|
+
const isMountedRef = React.useRef(true);
|
|
295
|
+
React.useEffect(() => {
|
|
296
|
+
const cleanup = callback(isMountedRef);
|
|
297
|
+
return () => {
|
|
298
|
+
cleanup == null ? void 0 : cleanup();
|
|
299
|
+
isMountedRef.current = false;
|
|
300
|
+
};
|
|
301
|
+
}, []);
|
|
295
302
|
};
|
|
296
303
|
|
|
297
304
|
const useOnline = () => {
|
|
@@ -348,4 +355,13 @@ const RenderStateRoot = ({
|
|
|
348
355
|
}, children);
|
|
349
356
|
};
|
|
350
357
|
|
|
351
|
-
|
|
358
|
+
const keys = {
|
|
359
|
+
enter: "Enter",
|
|
360
|
+
escape: "Escape",
|
|
361
|
+
tab: "Tab",
|
|
362
|
+
space: " ",
|
|
363
|
+
up: "ArrowUp",
|
|
364
|
+
down: "ArrowDown"
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
export { Id, InitialFallback, RenderState, RenderStateRoot, Server, Text, View, addStyle, keys, useForceUpdate, useIsMounted, useLatestRef, useOnMountEffect, useOnline, usePreHydrationEffect, useRenderState };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import * as React from "react";
|
|
1
2
|
/**
|
|
2
3
|
* Runs a callback once on mount.
|
|
3
4
|
*
|
|
4
5
|
* If the callback returns a cleanup function, it will be called when the component is unmounted.
|
|
5
6
|
*
|
|
6
|
-
* @param {() =>
|
|
7
|
+
* @param {(isMountedRef: React.MutableRefObject<boolean>) => void | (() => void)} callback function that forces the component to update.
|
|
7
8
|
*
|
|
8
9
|
* The following code snippets are equivalent
|
|
9
10
|
* ```
|
|
@@ -25,5 +26,26 @@
|
|
|
25
26
|
* }, []);
|
|
26
27
|
*
|
|
27
28
|
* If you only need to do something on mount, don't return a cleanup function from `callback`.
|
|
29
|
+
*
|
|
30
|
+
* If your callback is async, use the `isMountedRef` ref that's passed to the callback to ensure
|
|
31
|
+
* that the component using `useOnMountEffect` hasn't been unmounted, e.g.
|
|
32
|
+
*
|
|
33
|
+
* ```
|
|
34
|
+
* const MyComponent = () => {
|
|
35
|
+
* const [foo, setFoo] = React.useState("");
|
|
36
|
+
* useOnMountEffect((isMountedRef) => {
|
|
37
|
+
* const action = async () => {
|
|
38
|
+
* const res = await fetch("/foo");
|
|
39
|
+
* const text = res.text();
|
|
40
|
+
* if (isMountedRef.current) {
|
|
41
|
+
* setFoo(text);
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
44
|
+
*
|
|
45
|
+
* action();
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* return foo !== "" ? <h1>Loading...</h1> : <h1>{foo}</h1>;
|
|
49
|
+
* }
|
|
28
50
|
*/
|
|
29
|
-
export declare const useOnMountEffect: (callback: () => void | (() => void)) => void;
|
|
51
|
+
export declare const useOnMountEffect: (callback: (isMountedRef: React.MutableRefObject<boolean>) => void | (() => void)) => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -15,3 +15,4 @@ export { RenderStateRoot } from "./components/render-state-root";
|
|
|
15
15
|
export { RenderState } from "./components/render-state-context";
|
|
16
16
|
export type { AriaRole, AriaAttributes } from "./util/aria-types";
|
|
17
17
|
export type { AriaProps, StyleType, PropsFor } from "./util/types";
|
|
18
|
+
export { keys } from "./util/keys";
|
package/dist/index.js
CHANGED
|
@@ -318,7 +318,14 @@ function useLatestRef(value) {
|
|
|
318
318
|
}
|
|
319
319
|
|
|
320
320
|
const useOnMountEffect = callback => {
|
|
321
|
-
React__namespace.
|
|
321
|
+
const isMountedRef = React__namespace.useRef(true);
|
|
322
|
+
React__namespace.useEffect(() => {
|
|
323
|
+
const cleanup = callback(isMountedRef);
|
|
324
|
+
return () => {
|
|
325
|
+
cleanup == null ? void 0 : cleanup();
|
|
326
|
+
isMountedRef.current = false;
|
|
327
|
+
};
|
|
328
|
+
}, []);
|
|
322
329
|
};
|
|
323
330
|
|
|
324
331
|
const useOnline = () => {
|
|
@@ -375,6 +382,15 @@ const RenderStateRoot = ({
|
|
|
375
382
|
}, children);
|
|
376
383
|
};
|
|
377
384
|
|
|
385
|
+
const keys = {
|
|
386
|
+
enter: "Enter",
|
|
387
|
+
escape: "Escape",
|
|
388
|
+
tab: "Tab",
|
|
389
|
+
space: " ",
|
|
390
|
+
up: "ArrowUp",
|
|
391
|
+
down: "ArrowDown"
|
|
392
|
+
};
|
|
393
|
+
|
|
378
394
|
exports.Id = Id;
|
|
379
395
|
exports.InitialFallback = InitialFallback;
|
|
380
396
|
exports.RenderState = RenderState;
|
|
@@ -383,6 +399,7 @@ exports.Server = Server;
|
|
|
383
399
|
exports.Text = Text;
|
|
384
400
|
exports.View = View;
|
|
385
401
|
exports.addStyle = addStyle;
|
|
402
|
+
exports.keys = keys;
|
|
386
403
|
exports.useForceUpdate = useForceUpdate;
|
|
387
404
|
exports.useIsMounted = useIsMounted;
|
|
388
405
|
exports.useLatestRef = useLatestRef;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Key value mapping reference:
|
|
3
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values
|
|
4
|
+
*/
|
|
5
|
+
export declare const keys: {
|
|
6
|
+
readonly enter: "Enter";
|
|
7
|
+
readonly escape: "Escape";
|
|
8
|
+
readonly tab: "Tab";
|
|
9
|
+
readonly space: " ";
|
|
10
|
+
readonly up: "ArrowUp";
|
|
11
|
+
readonly down: "ArrowDown";
|
|
12
|
+
};
|