@wordpress/edit-widgets 6.22.0 → 6.24.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 +4 -0
- package/build/components/save-button/index.js +7 -4
- package/build/components/save-button/index.js.map +1 -1
- package/build/components/secondary-sidebar/inserter-sidebar.js +0 -6
- package/build/components/secondary-sidebar/inserter-sidebar.js.map +1 -1
- package/build/store/actions.js +62 -1
- package/build/store/actions.js.map +1 -1
- package/build/store/reducer.js +32 -1
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +32 -0
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/save-button/index.js +7 -4
- package/build-module/components/save-button/index.js.map +1 -1
- package/build-module/components/secondary-sidebar/inserter-sidebar.js +1 -7
- package/build-module/components/secondary-sidebar/inserter-sidebar.js.map +1 -1
- package/build-module/store/actions.js +58 -0
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/reducer.js +31 -1
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +31 -0
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +130 -9
- package/build-style/style.css +130 -9
- package/package.json +28 -28
- package/src/components/save-button/index.js +17 -9
- package/src/components/secondary-sidebar/inserter-sidebar.js +2 -14
- package/src/store/actions.js +58 -0
- package/src/store/reducer.js +26 -0
- package/src/store/selectors.js +31 -0
- package/src/store/test/reducer.js +56 -0
- package/src/store/test/selectors.js +31 -0
package/build-style/style.css
CHANGED
|
@@ -1,15 +1,57 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Converts a hex value into the rgb equivalent.
|
|
3
|
-
*
|
|
4
|
-
* @param {string} hex - the hexadecimal value to convert
|
|
5
|
-
* @return {string} comma separated rgb values
|
|
6
|
-
*/
|
|
7
1
|
/**
|
|
8
2
|
* Colors
|
|
9
3
|
*/
|
|
10
4
|
/**
|
|
11
5
|
* Breakpoints & Media Queries
|
|
12
6
|
*/
|
|
7
|
+
/**
|
|
8
|
+
* Colors
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* SCSS Variables.
|
|
12
|
+
*
|
|
13
|
+
* Please use variables from this sheet to ensure consistency across the UI.
|
|
14
|
+
* Don't add to this sheet unless you're pretty sure the value will be reused in many places.
|
|
15
|
+
* For example, don't add rules to this sheet that affect block visuals. It's purely for UI.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Fonts & basic variables.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Typography
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* Grid System.
|
|
25
|
+
* https://make.wordpress.org/design/2019/10/31/proposal-a-consistent-spacing-system-for-wordpress/
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* Radius scale.
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* Elevation scale.
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* Dimensions.
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* Mobile specific styles
|
|
38
|
+
*/
|
|
39
|
+
/**
|
|
40
|
+
* Editor styles.
|
|
41
|
+
*/
|
|
42
|
+
/**
|
|
43
|
+
* Block & Editor UI.
|
|
44
|
+
*/
|
|
45
|
+
/**
|
|
46
|
+
* Block paddings.
|
|
47
|
+
*/
|
|
48
|
+
/**
|
|
49
|
+
* React Native specific.
|
|
50
|
+
* These variables do not appear to be used anywhere else.
|
|
51
|
+
*/
|
|
52
|
+
/**
|
|
53
|
+
* Colors
|
|
54
|
+
*/
|
|
13
55
|
/**
|
|
14
56
|
* SCSS Variables.
|
|
15
57
|
*
|
|
@@ -17,15 +59,91 @@
|
|
|
17
59
|
* Don't add to this sheet unless you're pretty sure the value will be reused in many places.
|
|
18
60
|
* For example, don't add rules to this sheet that affect block visuals. It's purely for UI.
|
|
19
61
|
*/
|
|
62
|
+
/**
|
|
63
|
+
* Fonts & basic variables.
|
|
64
|
+
*/
|
|
65
|
+
/**
|
|
66
|
+
* Typography
|
|
67
|
+
*/
|
|
68
|
+
/**
|
|
69
|
+
* Grid System.
|
|
70
|
+
* https://make.wordpress.org/design/2019/10/31/proposal-a-consistent-spacing-system-for-wordpress/
|
|
71
|
+
*/
|
|
72
|
+
/**
|
|
73
|
+
* Radius scale.
|
|
74
|
+
*/
|
|
75
|
+
/**
|
|
76
|
+
* Elevation scale.
|
|
77
|
+
*/
|
|
78
|
+
/**
|
|
79
|
+
* Dimensions.
|
|
80
|
+
*/
|
|
81
|
+
/**
|
|
82
|
+
* Mobile specific styles
|
|
83
|
+
*/
|
|
84
|
+
/**
|
|
85
|
+
* Editor styles.
|
|
86
|
+
*/
|
|
87
|
+
/**
|
|
88
|
+
* Block & Editor UI.
|
|
89
|
+
*/
|
|
90
|
+
/**
|
|
91
|
+
* Block paddings.
|
|
92
|
+
*/
|
|
93
|
+
/**
|
|
94
|
+
* React Native specific.
|
|
95
|
+
* These variables do not appear to be used anywhere else.
|
|
96
|
+
*/
|
|
97
|
+
/**
|
|
98
|
+
* Breakpoints & Media Queries
|
|
99
|
+
*/
|
|
20
100
|
/**
|
|
21
101
|
* Converts a hex value into the rgb equivalent.
|
|
22
102
|
*
|
|
23
103
|
* @param {string} hex - the hexadecimal value to convert
|
|
24
104
|
* @return {string} comma separated rgb values
|
|
25
105
|
*/
|
|
106
|
+
/**
|
|
107
|
+
* Long content fade mixin
|
|
108
|
+
*
|
|
109
|
+
* Creates a fading overlay to signify that the content is longer
|
|
110
|
+
* than the space allows.
|
|
111
|
+
*/
|
|
112
|
+
/**
|
|
113
|
+
* Typography
|
|
114
|
+
*/
|
|
115
|
+
/**
|
|
116
|
+
* Breakpoint mixins
|
|
117
|
+
*/
|
|
118
|
+
/**
|
|
119
|
+
* Focus styles.
|
|
120
|
+
*/
|
|
121
|
+
/**
|
|
122
|
+
* Applies editor left position to the selector passed as argument
|
|
123
|
+
*/
|
|
124
|
+
/**
|
|
125
|
+
* Styles that are reused verbatim in a few places
|
|
126
|
+
*/
|
|
127
|
+
/**
|
|
128
|
+
* Allows users to opt-out of animations via OS-level preferences.
|
|
129
|
+
*/
|
|
130
|
+
/**
|
|
131
|
+
* Reset default styles for JavaScript UI based pages.
|
|
132
|
+
* This is a WP-admin agnostic reset
|
|
133
|
+
*/
|
|
134
|
+
/**
|
|
135
|
+
* Reset the WP Admin page styles for Gutenberg-like pages.
|
|
136
|
+
*/
|
|
26
137
|
/**
|
|
27
138
|
* Colors
|
|
28
139
|
*/
|
|
140
|
+
/**
|
|
141
|
+
* SCSS Variables.
|
|
142
|
+
*
|
|
143
|
+
* Please use variables from this sheet to ensure consistency across the UI.
|
|
144
|
+
* Don't add to this sheet unless you're pretty sure the value will be reused in many places.
|
|
145
|
+
* For example, don't add rules to this sheet that affect block visuals. It's purely for UI.
|
|
146
|
+
*/
|
|
29
147
|
/**
|
|
30
148
|
* Fonts & basic variables.
|
|
31
149
|
*/
|
|
@@ -61,6 +179,9 @@
|
|
|
61
179
|
* React Native specific.
|
|
62
180
|
* These variables do not appear to be used anywhere else.
|
|
63
181
|
*/
|
|
182
|
+
/**
|
|
183
|
+
* Breakpoints & Media Queries
|
|
184
|
+
*/
|
|
64
185
|
/**
|
|
65
186
|
* Converts a hex value into the rgb equivalent.
|
|
66
187
|
*
|
|
@@ -99,6 +220,9 @@
|
|
|
99
220
|
* Reset the WP Admin page styles for Gutenberg-like pages.
|
|
100
221
|
*/
|
|
101
222
|
:root {
|
|
223
|
+
--wp-block-synced-color: #7a00df;
|
|
224
|
+
--wp-block-synced-color--rgb: 122, 0, 223;
|
|
225
|
+
--wp-bound-block-color: var(--wp-block-synced-color);
|
|
102
226
|
--wp-admin-theme-color: #007cba;
|
|
103
227
|
--wp-admin-theme-color--rgb: 0, 124, 186;
|
|
104
228
|
--wp-admin-theme-color-darker-10: #006ba1;
|
|
@@ -106,9 +230,6 @@
|
|
|
106
230
|
--wp-admin-theme-color-darker-20: #005a87;
|
|
107
231
|
--wp-admin-theme-color-darker-20--rgb: 0, 90, 135;
|
|
108
232
|
--wp-admin-border-width-focus: 2px;
|
|
109
|
-
--wp-block-synced-color: #7a00df;
|
|
110
|
-
--wp-block-synced-color--rgb: 122, 0, 223;
|
|
111
|
-
--wp-bound-block-color: var(--wp-block-synced-color);
|
|
112
233
|
}
|
|
113
234
|
@media (min-resolution: 192dpi) {
|
|
114
235
|
:root {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/edit-widgets",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.24.0",
|
|
4
4
|
"description": "Widgets Page module for WordPress..",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -29,32 +29,32 @@
|
|
|
29
29
|
"wpScript": true,
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@babel/runtime": "7.25.7",
|
|
32
|
-
"@wordpress/api-fetch": "^7.
|
|
33
|
-
"@wordpress/block-editor": "^14.
|
|
34
|
-
"@wordpress/block-library": "^9.
|
|
35
|
-
"@wordpress/blocks": "^14.
|
|
36
|
-
"@wordpress/components": "^29.
|
|
37
|
-
"@wordpress/compose": "^7.
|
|
38
|
-
"@wordpress/core-data": "^7.
|
|
39
|
-
"@wordpress/data": "^10.
|
|
40
|
-
"@wordpress/deprecated": "^4.
|
|
41
|
-
"@wordpress/dom": "^4.
|
|
42
|
-
"@wordpress/element": "^6.
|
|
43
|
-
"@wordpress/hooks": "^4.
|
|
44
|
-
"@wordpress/i18n": "^5.
|
|
45
|
-
"@wordpress/icons": "^10.
|
|
46
|
-
"@wordpress/interface": "^9.
|
|
47
|
-
"@wordpress/keyboard-shortcuts": "^5.
|
|
48
|
-
"@wordpress/keycodes": "^4.
|
|
49
|
-
"@wordpress/media-utils": "^5.
|
|
50
|
-
"@wordpress/notices": "^5.
|
|
51
|
-
"@wordpress/patterns": "^2.
|
|
52
|
-
"@wordpress/plugins": "^7.
|
|
53
|
-
"@wordpress/preferences": "^4.
|
|
54
|
-
"@wordpress/private-apis": "^1.
|
|
55
|
-
"@wordpress/reusable-blocks": "^5.
|
|
56
|
-
"@wordpress/url": "^4.
|
|
57
|
-
"@wordpress/widgets": "^4.
|
|
32
|
+
"@wordpress/api-fetch": "^7.24.0",
|
|
33
|
+
"@wordpress/block-editor": "^14.19.0",
|
|
34
|
+
"@wordpress/block-library": "^9.24.0",
|
|
35
|
+
"@wordpress/blocks": "^14.13.0",
|
|
36
|
+
"@wordpress/components": "^29.10.0",
|
|
37
|
+
"@wordpress/compose": "^7.24.0",
|
|
38
|
+
"@wordpress/core-data": "^7.24.0",
|
|
39
|
+
"@wordpress/data": "^10.24.0",
|
|
40
|
+
"@wordpress/deprecated": "^4.24.0",
|
|
41
|
+
"@wordpress/dom": "^4.24.0",
|
|
42
|
+
"@wordpress/element": "^6.24.0",
|
|
43
|
+
"@wordpress/hooks": "^4.24.0",
|
|
44
|
+
"@wordpress/i18n": "^5.24.0",
|
|
45
|
+
"@wordpress/icons": "^10.24.0",
|
|
46
|
+
"@wordpress/interface": "^9.9.0",
|
|
47
|
+
"@wordpress/keyboard-shortcuts": "^5.24.0",
|
|
48
|
+
"@wordpress/keycodes": "^4.24.0",
|
|
49
|
+
"@wordpress/media-utils": "^5.24.0",
|
|
50
|
+
"@wordpress/notices": "^5.24.0",
|
|
51
|
+
"@wordpress/patterns": "^2.24.0",
|
|
52
|
+
"@wordpress/plugins": "^7.24.0",
|
|
53
|
+
"@wordpress/preferences": "^4.24.0",
|
|
54
|
+
"@wordpress/private-apis": "^1.24.0",
|
|
55
|
+
"@wordpress/reusable-blocks": "^5.24.0",
|
|
56
|
+
"@wordpress/url": "^4.24.0",
|
|
57
|
+
"@wordpress/widgets": "^4.24.0",
|
|
58
58
|
"clsx": "^2.1.1"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"publishConfig": {
|
|
65
65
|
"access": "public"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "9c03d1458cae76792ae15e67b421205836bf4393"
|
|
68
68
|
}
|
|
@@ -11,18 +11,26 @@ import { useDispatch, useSelect } from '@wordpress/data';
|
|
|
11
11
|
import { store as editWidgetsStore } from '../../store';
|
|
12
12
|
|
|
13
13
|
function SaveButton() {
|
|
14
|
-
const { hasEditedWidgetAreaIds, isSaving } = useSelect(
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const { hasEditedWidgetAreaIds, isSaving, isWidgetSaveLocked } = useSelect(
|
|
15
|
+
( select ) => {
|
|
16
|
+
const {
|
|
17
|
+
getEditedWidgetAreas,
|
|
18
|
+
isSavingWidgetAreas,
|
|
19
|
+
isWidgetSavingLocked,
|
|
20
|
+
} = select( editWidgetsStore );
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
return {
|
|
23
|
+
hasEditedWidgetAreaIds: getEditedWidgetAreas()?.length > 0,
|
|
24
|
+
isSaving: isSavingWidgetAreas(),
|
|
25
|
+
isWidgetSaveLocked: isWidgetSavingLocked(),
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
[]
|
|
29
|
+
);
|
|
23
30
|
const { saveEditedWidgetAreas } = useDispatch( editWidgetsStore );
|
|
24
31
|
|
|
25
|
-
const isDisabled =
|
|
32
|
+
const isDisabled =
|
|
33
|
+
isWidgetSaveLocked || isSaving || ! hasEditedWidgetAreaIds;
|
|
26
34
|
|
|
27
35
|
return (
|
|
28
36
|
<Button
|
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { __experimentalLibrary as Library } from '@wordpress/block-editor';
|
|
5
|
-
import {
|
|
6
|
-
useViewportMatch,
|
|
7
|
-
__experimentalUseDialog as useDialog,
|
|
8
|
-
} from '@wordpress/compose';
|
|
5
|
+
import { useViewportMatch } from '@wordpress/compose';
|
|
9
6
|
import { useCallback, useRef } from '@wordpress/element';
|
|
10
7
|
import { useDispatch } from '@wordpress/data';
|
|
11
8
|
|
|
@@ -25,19 +22,10 @@ export default function InserterSidebar() {
|
|
|
25
22
|
return setIsInserterOpened( false );
|
|
26
23
|
}, [ setIsInserterOpened ] );
|
|
27
24
|
|
|
28
|
-
const [ inserterDialogRef, inserterDialogProps ] = useDialog( {
|
|
29
|
-
onClose: closeInserter,
|
|
30
|
-
focusOnMount: true,
|
|
31
|
-
} );
|
|
32
|
-
|
|
33
25
|
const libraryRef = useRef();
|
|
34
26
|
|
|
35
27
|
return (
|
|
36
|
-
<div
|
|
37
|
-
ref={ inserterDialogRef }
|
|
38
|
-
{ ...inserterDialogProps }
|
|
39
|
-
className="edit-widgets-layout__inserter-panel"
|
|
40
|
-
>
|
|
28
|
+
<div className="edit-widgets-layout__inserter-panel">
|
|
41
29
|
<div className="edit-widgets-layout__inserter-panel-content">
|
|
42
30
|
<Library
|
|
43
31
|
showInserterHelpPanel
|
package/src/store/actions.js
CHANGED
|
@@ -431,3 +431,61 @@ export const moveBlockToWidgetArea =
|
|
|
431
431
|
destinationIndex
|
|
432
432
|
);
|
|
433
433
|
};
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Returns an action object used to signal that widget saving is unlocked.
|
|
437
|
+
*
|
|
438
|
+
* @param {string} lockName The lock name.
|
|
439
|
+
*
|
|
440
|
+
* @example
|
|
441
|
+
* ```js
|
|
442
|
+
* import { store as widgetStore } from '@wordpress/edit-widgets';
|
|
443
|
+
* import { useDispatch } from '@wordpress/data';
|
|
444
|
+
*
|
|
445
|
+
* const ExampleComponent = () => {
|
|
446
|
+
* const { unlockWidgetSaving } = useDispatch( widgetStore );
|
|
447
|
+
* return (
|
|
448
|
+
* <Button onClick={ () => unlockWidgetSaving( 'lockName' ) }>
|
|
449
|
+
* { __( 'Unlock Widget Saving' ) }
|
|
450
|
+
* </Button>
|
|
451
|
+
* );
|
|
452
|
+
* };
|
|
453
|
+
* ```
|
|
454
|
+
*
|
|
455
|
+
* @return {Object} Action object
|
|
456
|
+
*/
|
|
457
|
+
export function unlockWidgetSaving( lockName ) {
|
|
458
|
+
return {
|
|
459
|
+
type: 'UNLOCK_WIDGET_SAVING',
|
|
460
|
+
lockName,
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Returns an action object used to signal that widget saving is locked.
|
|
466
|
+
*
|
|
467
|
+
* @param {string} lockName The lock name.
|
|
468
|
+
*
|
|
469
|
+
* @example
|
|
470
|
+
* ```js
|
|
471
|
+
* import { store as widgetStore } from '@wordpress/edit-widgets';
|
|
472
|
+
* import { useDispatch } from '@wordpress/data';
|
|
473
|
+
*
|
|
474
|
+
* const ExampleComponent = () => {
|
|
475
|
+
* const { lockWidgetSaving } = useDispatch( widgetStore );
|
|
476
|
+
* return (
|
|
477
|
+
* <Button onClick={ () => lockWidgetSaving( 'lockName' ) }>
|
|
478
|
+
* { __( 'Lock Widget Saving' ) }
|
|
479
|
+
* </Button>
|
|
480
|
+
* );
|
|
481
|
+
* };
|
|
482
|
+
* ```
|
|
483
|
+
*
|
|
484
|
+
* @return {Object} Action object
|
|
485
|
+
*/
|
|
486
|
+
export function lockWidgetSaving( lockName ) {
|
|
487
|
+
return {
|
|
488
|
+
type: 'LOCK_WIDGET_SAVING',
|
|
489
|
+
lockName,
|
|
490
|
+
};
|
|
491
|
+
}
|
package/src/store/reducer.js
CHANGED
|
@@ -90,10 +90,36 @@ export function inserterSidebarToggleRef( state = { current: null } ) {
|
|
|
90
90
|
return state;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Widget saving lock.
|
|
95
|
+
*
|
|
96
|
+
* When widget saving is locked, the widget cannot be updated.
|
|
97
|
+
*
|
|
98
|
+
* @param {Object} state Current state.
|
|
99
|
+
* @param {Object} action Dispatched action.
|
|
100
|
+
*
|
|
101
|
+
* @return {Object} Updated state.
|
|
102
|
+
*/
|
|
103
|
+
export function widgetSavingLock( state = {}, action ) {
|
|
104
|
+
switch ( action.type ) {
|
|
105
|
+
case 'LOCK_WIDGET_SAVING':
|
|
106
|
+
return { ...state, [ action.lockName ]: true };
|
|
107
|
+
|
|
108
|
+
case 'UNLOCK_WIDGET_SAVING': {
|
|
109
|
+
const { [ action.lockName ]: removedLockName, ...restState } =
|
|
110
|
+
state;
|
|
111
|
+
return restState;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return state;
|
|
116
|
+
}
|
|
117
|
+
|
|
93
118
|
export default combineReducers( {
|
|
94
119
|
blockInserterPanel,
|
|
95
120
|
inserterSidebarToggleRef,
|
|
96
121
|
listViewPanel,
|
|
97
122
|
listViewToggleRef,
|
|
98
123
|
widgetAreasOpenState,
|
|
124
|
+
widgetSavingLock,
|
|
99
125
|
} );
|
package/src/store/selectors.js
CHANGED
|
@@ -311,3 +311,34 @@ export const canInsertBlockInWidgetArea = createRegistrySelector(
|
|
|
311
311
|
export function isListViewOpened( state ) {
|
|
312
312
|
return state.listViewPanel;
|
|
313
313
|
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Returns whether widget saving is locked.
|
|
317
|
+
*
|
|
318
|
+
* @param {Object} state Global application state.
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* ```jsx
|
|
322
|
+
* import { __ } from '@wordpress/i18n';
|
|
323
|
+
* import { store as widgetStore } from '@wordpress/edit-widgets';
|
|
324
|
+
* import { useSelect } from '@wordpress/data';
|
|
325
|
+
*
|
|
326
|
+
* const ExampleComponent = () => {
|
|
327
|
+
* const isSavingLocked = useSelect(
|
|
328
|
+
* ( select ) => select( widgetStore ).isWidgetSavingLocked(),
|
|
329
|
+
* []
|
|
330
|
+
* );
|
|
331
|
+
*
|
|
332
|
+
* return isSavingLocked ? (
|
|
333
|
+
* <p>{ __( 'Widget saving is locked' ) }</p>
|
|
334
|
+
* ) : (
|
|
335
|
+
* <p>{ __( 'Widget saving is not locked' ) }</p>
|
|
336
|
+
* );
|
|
337
|
+
* };
|
|
338
|
+
* ```
|
|
339
|
+
*
|
|
340
|
+
* @return {boolean} Is locked.
|
|
341
|
+
*/
|
|
342
|
+
export function isWidgetSavingLocked( state ) {
|
|
343
|
+
return Object.keys( state.widgetSavingLock ).length > 0;
|
|
344
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import deepFreeze from 'deep-freeze';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { widgetSavingLock } from '../reducer';
|
|
10
|
+
|
|
11
|
+
describe( 'state', () => {
|
|
12
|
+
describe( 'widgetSavingLock', () => {
|
|
13
|
+
it( 'returns empty object by default', () => {
|
|
14
|
+
const state = widgetSavingLock( undefined, {} );
|
|
15
|
+
|
|
16
|
+
expect( state ).toEqual( {} );
|
|
17
|
+
} );
|
|
18
|
+
|
|
19
|
+
it( 'returns correct widget saving locks when locks added and removed', () => {
|
|
20
|
+
let state = widgetSavingLock( undefined, {
|
|
21
|
+
type: 'LOCK_WIDGET_SAVING',
|
|
22
|
+
lockName: 'test-lock',
|
|
23
|
+
} );
|
|
24
|
+
|
|
25
|
+
expect( state ).toEqual( {
|
|
26
|
+
'test-lock': true,
|
|
27
|
+
} );
|
|
28
|
+
|
|
29
|
+
state = widgetSavingLock( deepFreeze( state ), {
|
|
30
|
+
type: 'LOCK_WIDGET_SAVING',
|
|
31
|
+
lockName: 'test-lock-2',
|
|
32
|
+
} );
|
|
33
|
+
|
|
34
|
+
expect( state ).toEqual( {
|
|
35
|
+
'test-lock': true,
|
|
36
|
+
'test-lock-2': true,
|
|
37
|
+
} );
|
|
38
|
+
|
|
39
|
+
state = widgetSavingLock( deepFreeze( state ), {
|
|
40
|
+
type: 'UNLOCK_WIDGET_SAVING',
|
|
41
|
+
lockName: 'test-lock',
|
|
42
|
+
} );
|
|
43
|
+
|
|
44
|
+
expect( state ).toEqual( {
|
|
45
|
+
'test-lock-2': true,
|
|
46
|
+
} );
|
|
47
|
+
|
|
48
|
+
state = widgetSavingLock( deepFreeze( state ), {
|
|
49
|
+
type: 'UNLOCK_WIDGET_SAVING',
|
|
50
|
+
lockName: 'test-lock-2',
|
|
51
|
+
} );
|
|
52
|
+
|
|
53
|
+
expect( state ).toEqual( {} );
|
|
54
|
+
} );
|
|
55
|
+
} );
|
|
56
|
+
} );
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import * as _selectors from '../selectors';
|
|
5
|
+
|
|
6
|
+
const selectors = { ..._selectors };
|
|
7
|
+
const { isWidgetSavingLocked } = selectors;
|
|
8
|
+
|
|
9
|
+
describe( 'selectors', () => {
|
|
10
|
+
describe( 'isWidgetSavingLocked', () => {
|
|
11
|
+
it( 'should return true if the post has widgetSavingLocks', () => {
|
|
12
|
+
const state = {
|
|
13
|
+
widgetSavingLock: { example: true },
|
|
14
|
+
currentWidget: {},
|
|
15
|
+
saving: {},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
expect( isWidgetSavingLocked( state ) ).toBe( true );
|
|
19
|
+
} );
|
|
20
|
+
|
|
21
|
+
it( 'should return false if the post has no widgetSavingLocks', () => {
|
|
22
|
+
const state = {
|
|
23
|
+
widgetSavingLock: {},
|
|
24
|
+
currentWidget: {},
|
|
25
|
+
saving: {},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
expect( isWidgetSavingLocked( state ) ).toBe( false );
|
|
29
|
+
} );
|
|
30
|
+
} );
|
|
31
|
+
} );
|