-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
index.js
70 lines (62 loc) · 1.23 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* External dependencies
*/
import memize from 'memize';
/**
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
/**
* Internal dependencies
*/
import Edit from './edit';
import { BlockEditContextProvider, useBlockEditContext } from './context';
class BlockEdit extends Component {
constructor() {
super( ...arguments );
// It is important to return the same object if props haven't changed
// to avoid unnecessary rerenders.
// See https://reactjs.org/docs/context.html#caveats.
this.propsToContext = memize( this.propsToContext.bind( this ), {
maxSize: 1,
} );
}
propsToContext(
name,
isSelected,
clientId,
onFocus,
onCaretVerticalPositionChange
) {
return {
name,
isSelected,
clientId,
onFocus,
onCaretVerticalPositionChange,
};
}
render() {
const {
name,
isSelected,
clientId,
onFocus,
onCaretVerticalPositionChange,
} = this.props;
const value = this.propsToContext(
name,
isSelected,
clientId,
onFocus,
onCaretVerticalPositionChange
);
return (
<BlockEditContextProvider value={ value }>
<Edit { ...this.props } />
</BlockEditContextProvider>
);
}
}
export default BlockEdit;
export { useBlockEditContext };