@wordpress/edit-post 8.43.1-next.v.202604091042.0 → 8.45.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 +8 -0
- package/build/components/back-button/fullscreen-mode-close.cjs +1 -1
- package/build/components/back-button/fullscreen-mode-close.cjs.map +1 -1
- package/build/components/layout/index.cjs +2 -1
- package/build/components/layout/index.cjs.map +2 -2
- package/build/components/meta-boxes/use-meta-box-initialization.cjs +10 -4
- package/build/components/meta-boxes/use-meta-box-initialization.cjs.map +3 -3
- package/build/store/reducer.cjs +4 -1
- package/build/store/reducer.cjs.map +2 -2
- package/build-module/components/back-button/fullscreen-mode-close.mjs +1 -1
- package/build-module/components/back-button/fullscreen-mode-close.mjs.map +1 -1
- package/build-module/components/layout/index.mjs +1 -1
- package/build-module/components/layout/index.mjs.map +2 -2
- package/build-module/components/meta-boxes/use-meta-box-initialization.mjs +10 -4
- package/build-module/components/meta-boxes/use-meta-box-initialization.mjs.map +2 -2
- package/build-module/store/reducer.mjs +4 -1
- package/build-module/store/reducer.mjs.map +2 -2
- package/build-style/classic-rtl.css +2 -1
- package/build-style/classic.css +2 -1
- package/build-style/style-rtl.css +1 -136
- package/build-style/style.css +1 -136
- package/package.json +34 -33
- package/src/classic.scss +4 -1
- package/src/components/back-button/fullscreen-mode-close.js +1 -1
- package/src/components/layout/index.js +2 -2
- package/src/components/layout/style.scss +1 -1
- package/src/components/meta-boxes/test/use-meta-box-initialization.js +191 -0
- package/src/components/meta-boxes/use-meta-box-initialization.js +14 -4
- package/src/store/reducer.js +4 -1
- package/src/style.scss +0 -1
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { render } from '@testing-library/react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { RegistryProvider, createRegistry } from '@wordpress/data';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
import { useMetaBoxInitialization } from '../use-meta-box-initialization';
|
|
15
|
+
import { STORE_NAME } from '../../../store/constants';
|
|
16
|
+
|
|
17
|
+
// Mock unlock to be an identity function so private actions are directly accessible.
|
|
18
|
+
jest.mock( '../../../lock-unlock', () => ( {
|
|
19
|
+
unlock: ( value ) => value,
|
|
20
|
+
} ) );
|
|
21
|
+
|
|
22
|
+
const storeConfig = {
|
|
23
|
+
actions: {
|
|
24
|
+
forceUpdate: jest.fn( () => ( { type: 'FORCE_UPDATE' } ) ),
|
|
25
|
+
},
|
|
26
|
+
reducer: ( state = {}, action ) =>
|
|
27
|
+
action.type === 'FORCE_UPDATE' ? { ...state } : state,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const setCollaborationSupported = jest.fn( () => ( {
|
|
31
|
+
type: 'SET_COLLABORATION_SUPPORTED',
|
|
32
|
+
} ) );
|
|
33
|
+
|
|
34
|
+
const initializeMetaBoxes = jest.fn( () => ( {
|
|
35
|
+
type: 'META_BOXES_INITIALIZED',
|
|
36
|
+
} ) );
|
|
37
|
+
|
|
38
|
+
function createMockStores( {
|
|
39
|
+
isEditorReady = true,
|
|
40
|
+
isCollaborationEnabled = true,
|
|
41
|
+
metaBoxes = [],
|
|
42
|
+
} = {} ) {
|
|
43
|
+
return {
|
|
44
|
+
'core/editor': {
|
|
45
|
+
...storeConfig,
|
|
46
|
+
selectors: {
|
|
47
|
+
__unstableIsEditorReady: jest.fn( () => isEditorReady ),
|
|
48
|
+
isCollaborationEnabledForCurrentPost: jest.fn(
|
|
49
|
+
() => isCollaborationEnabled
|
|
50
|
+
),
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
core: {
|
|
54
|
+
...storeConfig,
|
|
55
|
+
actions: {
|
|
56
|
+
...storeConfig.actions,
|
|
57
|
+
setCollaborationSupported,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
[ STORE_NAME ]: {
|
|
61
|
+
...storeConfig,
|
|
62
|
+
actions: {
|
|
63
|
+
...storeConfig.actions,
|
|
64
|
+
initializeMetaBoxes,
|
|
65
|
+
},
|
|
66
|
+
selectors: {
|
|
67
|
+
getAllMetaBoxes: jest.fn( () => metaBoxes ),
|
|
68
|
+
hasMetaBoxes: jest.fn( () => metaBoxes.length > 0 ),
|
|
69
|
+
getActiveMetaBoxLocations: jest.fn( () =>
|
|
70
|
+
metaBoxes.length > 0 ? [ 'normal' ] : []
|
|
71
|
+
),
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function TestComponent( { enabled } ) {
|
|
78
|
+
useMetaBoxInitialization( enabled );
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function renderHook( registry, enabled = true ) {
|
|
83
|
+
return render(
|
|
84
|
+
<RegistryProvider value={ registry }>
|
|
85
|
+
<TestComponent enabled={ enabled } />
|
|
86
|
+
</RegistryProvider>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
describe( 'useMetaBoxInitialization', () => {
|
|
91
|
+
afterEach( () => {
|
|
92
|
+
setCollaborationSupported.mockClear();
|
|
93
|
+
initializeMetaBoxes.mockClear();
|
|
94
|
+
} );
|
|
95
|
+
|
|
96
|
+
it( 'disables collaboration when metaboxes are present', () => {
|
|
97
|
+
const mockStores = createMockStores( {
|
|
98
|
+
metaBoxes: [
|
|
99
|
+
{ id: 'my-metabox', title: 'My Meta Box' },
|
|
100
|
+
{ id: 'another-metabox', title: 'Another' },
|
|
101
|
+
],
|
|
102
|
+
} );
|
|
103
|
+
const registry = createRegistry( mockStores );
|
|
104
|
+
|
|
105
|
+
renderHook( registry );
|
|
106
|
+
|
|
107
|
+
expect( initializeMetaBoxes ).toHaveBeenCalled();
|
|
108
|
+
expect( setCollaborationSupported ).toHaveBeenCalledWith( false );
|
|
109
|
+
} );
|
|
110
|
+
|
|
111
|
+
it( 'does not disable collaboration when all metaboxes are rtcCompatible', () => {
|
|
112
|
+
const mockStores = createMockStores( {
|
|
113
|
+
metaBoxes: [
|
|
114
|
+
{
|
|
115
|
+
id: 'my-metabox',
|
|
116
|
+
title: 'My Meta Box',
|
|
117
|
+
__rtc_compatible: true,
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
id: 'another-metabox',
|
|
121
|
+
title: 'Another',
|
|
122
|
+
__rtc_compatible: true,
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
} );
|
|
126
|
+
const registry = createRegistry( mockStores );
|
|
127
|
+
|
|
128
|
+
renderHook( registry );
|
|
129
|
+
|
|
130
|
+
expect( initializeMetaBoxes ).toHaveBeenCalled();
|
|
131
|
+
expect( setCollaborationSupported ).not.toHaveBeenCalled();
|
|
132
|
+
} );
|
|
133
|
+
|
|
134
|
+
it( 'disables collaboration when some metaboxes lack rtcCompatible', () => {
|
|
135
|
+
const mockStores = createMockStores( {
|
|
136
|
+
metaBoxes: [
|
|
137
|
+
{
|
|
138
|
+
id: 'compatible-metabox',
|
|
139
|
+
title: 'Compatible',
|
|
140
|
+
__rtc_compatible: true,
|
|
141
|
+
},
|
|
142
|
+
{ id: 'incompatible-metabox', title: 'Incompatible' },
|
|
143
|
+
],
|
|
144
|
+
} );
|
|
145
|
+
const registry = createRegistry( mockStores );
|
|
146
|
+
|
|
147
|
+
renderHook( registry );
|
|
148
|
+
|
|
149
|
+
expect( setCollaborationSupported ).toHaveBeenCalledWith( false );
|
|
150
|
+
} );
|
|
151
|
+
|
|
152
|
+
it( 'does not disable collaboration when the only metabox is rtcCompatible', () => {
|
|
153
|
+
const mockStores = createMockStores( {
|
|
154
|
+
metaBoxes: [
|
|
155
|
+
{
|
|
156
|
+
id: 'compatible-metabox',
|
|
157
|
+
title: 'Compatible',
|
|
158
|
+
__rtc_compatible: true,
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
} );
|
|
162
|
+
const registry = createRegistry( mockStores );
|
|
163
|
+
|
|
164
|
+
renderHook( registry );
|
|
165
|
+
|
|
166
|
+
expect( setCollaborationSupported ).not.toHaveBeenCalled();
|
|
167
|
+
} );
|
|
168
|
+
|
|
169
|
+
it( 'does not disable collaboration when there are no metaboxes', () => {
|
|
170
|
+
const mockStores = createMockStores( {
|
|
171
|
+
metaBoxes: [],
|
|
172
|
+
} );
|
|
173
|
+
const registry = createRegistry( mockStores );
|
|
174
|
+
|
|
175
|
+
renderHook( registry );
|
|
176
|
+
|
|
177
|
+
expect( setCollaborationSupported ).not.toHaveBeenCalled();
|
|
178
|
+
} );
|
|
179
|
+
|
|
180
|
+
it( 'does not disable collaboration when collaboration is not enabled', () => {
|
|
181
|
+
const mockStores = createMockStores( {
|
|
182
|
+
isCollaborationEnabled: false,
|
|
183
|
+
metaBoxes: [ { id: 'my-metabox', title: 'My Meta Box' } ],
|
|
184
|
+
} );
|
|
185
|
+
const registry = createRegistry( mockStores );
|
|
186
|
+
|
|
187
|
+
renderHook( registry );
|
|
188
|
+
|
|
189
|
+
expect( setCollaborationSupported ).not.toHaveBeenCalled();
|
|
190
|
+
} );
|
|
191
|
+
} );
|
|
@@ -18,26 +18,35 @@ import { unlock } from '../../lock-unlock';
|
|
|
18
18
|
* @param { boolean } enabled
|
|
19
19
|
*/
|
|
20
20
|
export const useMetaBoxInitialization = ( enabled ) => {
|
|
21
|
-
const {
|
|
21
|
+
const {
|
|
22
|
+
isEnabledAndEditorReady,
|
|
23
|
+
isCollaborationEnabled,
|
|
24
|
+
hasIncompatibleMetaBoxes,
|
|
25
|
+
} = useSelect(
|
|
22
26
|
( select ) => ( {
|
|
23
27
|
isEnabledAndEditorReady:
|
|
24
28
|
enabled && select( editorStore ).__unstableIsEditorReady(),
|
|
25
29
|
isCollaborationEnabled:
|
|
26
30
|
select( editorStore ).isCollaborationEnabledForCurrentPost(),
|
|
31
|
+
hasIncompatibleMetaBoxes: enabled
|
|
32
|
+
? select( editPostStore )
|
|
33
|
+
.getAllMetaBoxes()
|
|
34
|
+
.some( ( metaBox ) => ! metaBox.__rtc_compatible )
|
|
35
|
+
: false,
|
|
27
36
|
} ),
|
|
28
37
|
[ enabled ]
|
|
29
38
|
);
|
|
30
39
|
const { setCollaborationSupported } = unlock( useDispatch( coreStore ) );
|
|
31
|
-
|
|
32
40
|
const { initializeMetaBoxes } = useDispatch( editPostStore );
|
|
41
|
+
|
|
33
42
|
// The effect has to rerun when the editor is ready because initializeMetaBoxes
|
|
34
43
|
// will noop until then.
|
|
35
44
|
useEffect( () => {
|
|
36
45
|
if ( isEnabledAndEditorReady ) {
|
|
37
46
|
initializeMetaBoxes();
|
|
38
47
|
|
|
39
|
-
// Disable real-time collaboration when
|
|
40
|
-
if ( isCollaborationEnabled ) {
|
|
48
|
+
// Disable real-time collaboration when incompatible meta boxes are detected.
|
|
49
|
+
if ( isCollaborationEnabled && hasIncompatibleMetaBoxes ) {
|
|
41
50
|
setCollaborationSupported( false );
|
|
42
51
|
}
|
|
43
52
|
}
|
|
@@ -46,5 +55,6 @@ export const useMetaBoxInitialization = ( enabled ) => {
|
|
|
46
55
|
initializeMetaBoxes,
|
|
47
56
|
isCollaborationEnabled,
|
|
48
57
|
setCollaborationSupported,
|
|
58
|
+
hasIncompatibleMetaBoxes,
|
|
49
59
|
] );
|
|
50
60
|
};
|
package/src/store/reducer.js
CHANGED
|
@@ -32,7 +32,10 @@ function mergeMetaboxes( metaboxes = [], newMetaboxes ) {
|
|
|
32
32
|
( box ) => box.id === metabox.id
|
|
33
33
|
);
|
|
34
34
|
if ( existing !== -1 ) {
|
|
35
|
-
mergedMetaboxes[ existing ] =
|
|
35
|
+
mergedMetaboxes[ existing ] = {
|
|
36
|
+
...mergedMetaboxes[ existing ],
|
|
37
|
+
...metabox,
|
|
38
|
+
};
|
|
36
39
|
} else {
|
|
37
40
|
mergedMetaboxes.push( metabox );
|
|
38
41
|
}
|
package/src/style.scss
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
@use "@wordpress/base-styles/default-custom-properties";
|
|
2
2
|
@use "@wordpress/base-styles/mixins" as *;
|
|
3
3
|
@use "@wordpress/base-styles/variables" as *;
|
|
4
|
-
@use "@wordpress/admin-ui/build-style/style.css" as *;
|
|
5
4
|
@use "./components/back-button/style.scss" as *;
|
|
6
5
|
@use "./components/layout/style.scss" as *;
|
|
7
6
|
@use "./components/meta-boxes/meta-boxes-area/style.scss" as *;
|