@wordpress/block-editor 8.1.2 → 8.2.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 +10 -0
- package/README.md +0 -24
- package/build/components/block-list/block.js +16 -2
- package/build/components/block-list/block.js.map +1 -1
- package/build/components/block-list/block.native.js +1 -1
- package/build/components/block-list/block.native.js.map +1 -1
- package/build/components/block-list/use-block-props/use-focus-first-element.js +3 -0
- package/build/components/block-list/use-block-props/use-focus-first-element.js.map +1 -1
- package/build/components/block-list/use-block-props/use-multi-selection.js +25 -27
- package/build/components/block-list/use-block-props/use-multi-selection.js.map +1 -1
- package/build/components/block-settings/container.native.js +1 -5
- package/build/components/block-settings/container.native.js.map +1 -1
- package/build/components/index.js +9 -0
- package/build/components/index.js.map +1 -1
- package/build/components/index.native.js +9 -0
- package/build/components/index.native.js.map +1 -1
- package/build/components/inserter/block-patterns-tab.js +3 -3
- package/build/components/inserter/block-patterns-tab.js.map +1 -1
- package/build/components/inserter/quick-inserter.js +19 -7
- package/build/components/inserter/quick-inserter.js.map +1 -1
- package/build/components/inserter/search-results.js +28 -11
- package/build/components/inserter/search-results.js.map +1 -1
- package/build/components/line-height-control/index.js +61 -43
- package/build/components/line-height-control/index.js.map +1 -1
- package/build/components/list-view/block-contents.js +8 -4
- package/build/components/list-view/block-contents.js.map +1 -1
- package/build/components/list-view/block-select-button.js +0 -1
- package/build/components/list-view/block-select-button.js.map +1 -1
- package/build/components/list-view/block.js +19 -8
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/branch.js +2 -1
- package/build/components/list-view/branch.js.map +1 -1
- package/build/components/list-view/index.js +49 -41
- package/build/components/list-view/index.js.map +1 -1
- package/build/components/list-view/use-block-selection.js +139 -0
- package/build/components/list-view/use-block-selection.js.map +1 -0
- package/build/components/list-view/use-list-view-expand-selected-item.js +60 -0
- package/build/components/list-view/use-list-view-expand-selected-item.js.map +1 -0
- package/build/components/list-view/utils.js +29 -1
- package/build/components/list-view/utils.js.map +1 -1
- package/build/components/rich-text/index.js +7 -12
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/use-paste-handler.js +0 -1
- package/build/components/rich-text/use-paste-handler.js.map +1 -1
- package/build/components/writing-flow/index.js +1 -0
- package/build/components/writing-flow/index.js.map +1 -1
- package/build/components/writing-flow/use-multi-selection.js +22 -24
- package/build/components/writing-flow/use-multi-selection.js.map +1 -1
- package/build/components/writing-flow/use-select-all.js +3 -2
- package/build/components/writing-flow/use-select-all.js.map +1 -1
- package/build/hooks/custom-class-name.js +40 -0
- package/build/hooks/custom-class-name.js.map +1 -1
- package/build/hooks/line-height.js +2 -0
- package/build/hooks/line-height.js.map +1 -1
- package/build/hooks/style.js +27 -11
- package/build/hooks/style.js.map +1 -1
- package/build/layouts/flow.js +7 -5
- package/build/layouts/flow.js.map +1 -1
- package/build/store/actions.js +51 -44
- package/build/store/actions.js.map +1 -1
- package/build/store/defaults.js +1 -0
- package/build/store/defaults.js.map +1 -1
- package/build/store/index.js +1 -2
- package/build/store/index.js.map +1 -1
- package/build/store/reducer.js +2 -2
- package/build/store/reducer.js.map +1 -1
- package/build/utils/index.js +0 -14
- package/build/utils/index.js.map +1 -1
- package/build-module/components/block-list/block.js +17 -3
- package/build-module/components/block-list/block.js.map +1 -1
- package/build-module/components/block-list/block.native.js +2 -2
- package/build-module/components/block-list/block.native.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-focus-first-element.js +2 -0
- package/build-module/components/block-list/use-block-props/use-focus-first-element.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-multi-selection.js +23 -28
- package/build-module/components/block-list/use-block-props/use-multi-selection.js.map +1 -1
- package/build-module/components/block-settings/container.native.js +2 -6
- package/build-module/components/block-settings/container.native.js.map +1 -1
- package/build-module/components/index.js +1 -0
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/index.native.js +1 -0
- package/build-module/components/index.native.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab.js +3 -3
- package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
- package/build-module/components/inserter/quick-inserter.js +19 -7
- package/build-module/components/inserter/quick-inserter.js.map +1 -1
- package/build-module/components/inserter/search-results.js +28 -11
- package/build-module/components/inserter/search-results.js.map +1 -1
- package/build-module/components/line-height-control/index.js +59 -43
- package/build-module/components/line-height-control/index.js.map +1 -1
- package/build-module/components/list-view/block-contents.js +8 -4
- package/build-module/components/list-view/block-contents.js.map +1 -1
- package/build-module/components/list-view/block-select-button.js +0 -1
- package/build-module/components/list-view/block-select-button.js.map +1 -1
- package/build-module/components/list-view/block.js +19 -8
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/branch.js +2 -1
- package/build-module/components/list-view/branch.js.map +1 -1
- package/build-module/components/list-view/index.js +46 -42
- package/build-module/components/list-view/index.js.map +1 -1
- package/build-module/components/list-view/use-block-selection.js +123 -0
- package/build-module/components/list-view/use-block-selection.js.map +1 -0
- package/build-module/components/list-view/use-list-view-expand-selected-item.js +50 -0
- package/build-module/components/list-view/use-list-view-expand-selected-item.js.map +1 -0
- package/build-module/components/list-view/utils.js +25 -0
- package/build-module/components/list-view/utils.js.map +1 -1
- package/build-module/components/rich-text/index.js +7 -12
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/use-paste-handler.js +0 -1
- package/build-module/components/rich-text/use-paste-handler.js.map +1 -1
- package/build-module/components/writing-flow/index.js +1 -0
- package/build-module/components/writing-flow/index.js.map +1 -1
- package/build-module/components/writing-flow/use-multi-selection.js +21 -21
- package/build-module/components/writing-flow/use-multi-selection.js.map +1 -1
- package/build-module/components/writing-flow/use-select-all.js +3 -2
- package/build-module/components/writing-flow/use-select-all.js.map +1 -1
- package/build-module/hooks/custom-class-name.js +38 -0
- package/build-module/hooks/custom-class-name.js.map +1 -1
- package/build-module/hooks/line-height.js +2 -0
- package/build-module/hooks/line-height.js.map +1 -1
- package/build-module/hooks/style.js +26 -11
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/layouts/flow.js +7 -5
- package/build-module/layouts/flow.js.map +1 -1
- package/build-module/store/actions.js +48 -41
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/defaults.js +1 -0
- package/build-module/store/defaults.js.map +1 -1
- package/build-module/store/index.js +1 -2
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/reducer.js +2 -2
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/utils/index.js +0 -1
- package/build-module/utils/index.js.map +1 -1
- package/build-style/style-rtl.css +3 -12
- package/build-style/style.css +3 -12
- package/package.json +12 -11
- package/src/components/block-list/block.js +27 -3
- package/src/components/block-list/block.native.js +2 -1
- package/src/components/block-list/style.scss +3 -1
- package/src/components/block-list/use-block-props/use-focus-first-element.js +3 -0
- package/src/components/block-list/use-block-props/use-multi-selection.js +22 -30
- package/src/components/block-settings/container.native.js +5 -6
- package/src/components/index.js +1 -0
- package/src/components/index.native.js +1 -0
- package/src/components/inserter/block-patterns-tab.js +12 -16
- package/src/components/inserter/quick-inserter.js +31 -9
- package/src/components/inserter/search-results.js +54 -42
- package/src/components/line-height-control/README.md +13 -2
- package/src/components/line-height-control/index.js +63 -40
- package/src/components/line-height-control/stories/index.js +33 -0
- package/src/components/line-height-control/test/index.js +61 -0
- package/src/components/list-view/README.md +2 -2
- package/src/components/list-view/block-contents.js +10 -3
- package/src/components/list-view/block-select-button.js +0 -1
- package/src/components/list-view/block.js +29 -9
- package/src/components/list-view/branch.js +1 -0
- package/src/components/list-view/index.js +56 -30
- package/src/components/list-view/test/utils.js +50 -0
- package/src/components/list-view/use-block-selection.js +163 -0
- package/src/components/list-view/use-list-view-expand-selected-item.js +58 -0
- package/src/components/list-view/utils.js +31 -0
- package/src/components/rich-text/index.js +7 -14
- package/src/components/rich-text/use-paste-handler.js +0 -1
- package/src/components/writing-flow/index.js +1 -0
- package/src/components/writing-flow/use-multi-selection.js +17 -20
- package/src/components/writing-flow/use-select-all.js +6 -2
- package/src/hooks/custom-class-name.js +45 -0
- package/src/hooks/line-height.js +2 -0
- package/src/hooks/style.js +26 -11
- package/src/hooks/typography.scss +0 -4
- package/src/layouts/flow.js +10 -5
- package/src/store/actions.js +20 -10
- package/src/store/defaults.js +1 -0
- package/src/store/index.js +0 -1
- package/src/store/reducer.js +2 -1
- package/src/store/test/actions.js +1 -1
- package/src/store/test/reducer.js +9 -0
- package/src/style.scss +0 -1
- package/src/utils/index.js +0 -1
- package/build/utils/theme.js +0 -63
- package/build/utils/theme.js.map +0 -1
- package/build-module/utils/theme.js +0 -53
- package/build-module/utils/theme.js.map +0 -1
- package/src/components/line-height-control/style.scss +0 -8
- package/src/components/writing-flow/test/use-multi-selection.js +0 -36
- package/src/utils/theme.js +0 -48
|
@@ -30,3 +30,34 @@ export const isClientIdSelected = ( clientId, selectedBlockClientIds ) =>
|
|
|
30
30
|
isArray( selectedBlockClientIds ) && selectedBlockClientIds.length
|
|
31
31
|
? selectedBlockClientIds.indexOf( clientId ) !== -1
|
|
32
32
|
: selectedBlockClientIds === clientId;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* From a start and end clientId of potentially different nesting levels,
|
|
36
|
+
* return the nearest-depth ids that have a common level of depth in the
|
|
37
|
+
* nesting hierarchy. For multiple block selection, this ensure that the
|
|
38
|
+
* selection is always at the same nesting level, and not split across
|
|
39
|
+
* separate levels.
|
|
40
|
+
*
|
|
41
|
+
* @param {string} startId The first id of a selection.
|
|
42
|
+
* @param {string} endId The end id of a selection, usually one that has been clicked on.
|
|
43
|
+
* @param {string[]} startParents An array of ancestor ids for the start id, in descending order.
|
|
44
|
+
* @param {string[]} endParents An array of ancestor ids for the end id, in descending order.
|
|
45
|
+
* @return {Object} An object containing the start and end ids.
|
|
46
|
+
*/
|
|
47
|
+
export function getCommonDepthClientIds(
|
|
48
|
+
startId,
|
|
49
|
+
endId,
|
|
50
|
+
startParents,
|
|
51
|
+
endParents
|
|
52
|
+
) {
|
|
53
|
+
const startPath = [ ...startParents, startId ];
|
|
54
|
+
const endPath = [ ...endParents, endId ];
|
|
55
|
+
const depth = Math.min( startPath.length, endPath.length ) - 1;
|
|
56
|
+
const start = startPath[ depth ];
|
|
57
|
+
const end = endPath[ depth ];
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
start,
|
|
61
|
+
end,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -120,12 +120,9 @@ function RichTextWrapper(
|
|
|
120
120
|
const anchorRef = useRef();
|
|
121
121
|
const { clientId } = useBlockEditContext();
|
|
122
122
|
const selector = ( select ) => {
|
|
123
|
-
const {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
isMultiSelecting,
|
|
127
|
-
hasMultiSelection,
|
|
128
|
-
} = select( blockEditorStore );
|
|
123
|
+
const { getSelectionStart, getSelectionEnd } = select(
|
|
124
|
+
blockEditorStore
|
|
125
|
+
);
|
|
129
126
|
const selectionStart = getSelectionStart();
|
|
130
127
|
const selectionEnd = getSelectionEnd();
|
|
131
128
|
|
|
@@ -143,15 +140,12 @@ function RichTextWrapper(
|
|
|
143
140
|
selectionStart: isSelected ? selectionStart.offset : undefined,
|
|
144
141
|
selectionEnd: isSelected ? selectionEnd.offset : undefined,
|
|
145
142
|
isSelected,
|
|
146
|
-
disabled: isMultiSelecting() || hasMultiSelection(),
|
|
147
143
|
};
|
|
148
144
|
};
|
|
149
145
|
// This selector must run on every render so the right selection state is
|
|
150
146
|
// retreived from the store on merge.
|
|
151
147
|
// To do: fix this somehow.
|
|
152
|
-
const { selectionStart, selectionEnd, isSelected
|
|
153
|
-
selector
|
|
154
|
-
);
|
|
148
|
+
const { selectionStart, selectionEnd, isSelected } = useSelect( selector );
|
|
155
149
|
const { selectionChange } = useDispatch( blockEditorStore );
|
|
156
150
|
const multilineTag = getMultilineTag( multiline );
|
|
157
151
|
const adjustedAllowedFormats = getAllowedFormats( {
|
|
@@ -331,7 +325,7 @@ function RichTextWrapper(
|
|
|
331
325
|
<TagName
|
|
332
326
|
// Overridable props.
|
|
333
327
|
role="textbox"
|
|
334
|
-
aria-multiline={
|
|
328
|
+
aria-multiline={ ! disableLineBreaks }
|
|
335
329
|
aria-label={ placeholder }
|
|
336
330
|
{ ...props }
|
|
337
331
|
{ ...autocompleteProps }
|
|
@@ -379,9 +373,8 @@ function RichTextWrapper(
|
|
|
379
373
|
anchorRef,
|
|
380
374
|
forwardedRef,
|
|
381
375
|
] ) }
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
suppressContentEditableWarning={ ! disabled }
|
|
376
|
+
contentEditable={ true }
|
|
377
|
+
suppressContentEditableWarning={ true }
|
|
385
378
|
className={ classnames(
|
|
386
379
|
'block-editor-rich-text__editable',
|
|
387
380
|
props.className,
|
|
@@ -15,21 +15,6 @@ import { useSelect } from '@wordpress/data';
|
|
|
15
15
|
import { store as blockEditorStore } from '../../store';
|
|
16
16
|
import { __unstableUseBlockRef as useBlockRef } from '../block-list/use-block-props/use-block-refs';
|
|
17
17
|
|
|
18
|
-
export function toggleRichText( container, toggle ) {
|
|
19
|
-
Array.from(
|
|
20
|
-
container.querySelectorAll(
|
|
21
|
-
// Exclude the Post Title from multi-select disable.
|
|
22
|
-
'.rich-text:not( .editor-post-title__input )'
|
|
23
|
-
)
|
|
24
|
-
).forEach( ( node ) => {
|
|
25
|
-
if ( toggle ) {
|
|
26
|
-
node.setAttribute( 'contenteditable', true );
|
|
27
|
-
} else {
|
|
28
|
-
node.removeAttribute( 'contenteditable' );
|
|
29
|
-
}
|
|
30
|
-
} );
|
|
31
|
-
}
|
|
32
|
-
|
|
33
18
|
/**
|
|
34
19
|
* Returns for the deepest node at the start or end of a container node. Ignores
|
|
35
20
|
* any text nodes that only contain HTML formatting whitespace.
|
|
@@ -62,6 +47,7 @@ function selector( select ) {
|
|
|
62
47
|
getMultiSelectedBlockClientIds,
|
|
63
48
|
hasMultiSelection,
|
|
64
49
|
getSelectedBlockClientId,
|
|
50
|
+
getSelectedBlocksInitialCaretPosition,
|
|
65
51
|
} = select( blockEditorStore );
|
|
66
52
|
|
|
67
53
|
return {
|
|
@@ -69,11 +55,13 @@ function selector( select ) {
|
|
|
69
55
|
multiSelectedBlockClientIds: getMultiSelectedBlockClientIds(),
|
|
70
56
|
hasMultiSelection: hasMultiSelection(),
|
|
71
57
|
selectedBlockClientId: getSelectedBlockClientId(),
|
|
58
|
+
initialPosition: getSelectedBlocksInitialCaretPosition(),
|
|
72
59
|
};
|
|
73
60
|
}
|
|
74
61
|
|
|
75
62
|
export default function useMultiSelection() {
|
|
76
63
|
const {
|
|
64
|
+
initialPosition,
|
|
77
65
|
isMultiSelecting,
|
|
78
66
|
multiSelectedBlockClientIds,
|
|
79
67
|
hasMultiSelection,
|
|
@@ -93,6 +81,13 @@ export default function useMultiSelection() {
|
|
|
93
81
|
const { ownerDocument } = node;
|
|
94
82
|
const { defaultView } = ownerDocument;
|
|
95
83
|
|
|
84
|
+
// Allow initialPosition to bypass focus behavior. This is useful
|
|
85
|
+
// for the list view or other areas where we don't want to transfer
|
|
86
|
+
// focus to the editor canvas.
|
|
87
|
+
if ( initialPosition === undefined || initialPosition === null ) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
96
91
|
if ( ! hasMultiSelection || isMultiSelecting ) {
|
|
97
92
|
if ( ! selectedBlockClientId || isMultiSelecting ) {
|
|
98
93
|
return;
|
|
@@ -131,6 +126,12 @@ export default function useMultiSelection() {
|
|
|
131
126
|
return;
|
|
132
127
|
}
|
|
133
128
|
|
|
129
|
+
// Allow cross contentEditable selection by temporarily making
|
|
130
|
+
// all content editable. We can't rely on using the store and
|
|
131
|
+
// React because re-rending happens too slowly. We need to be
|
|
132
|
+
// able to select across instances immediately.
|
|
133
|
+
node.contentEditable = true;
|
|
134
|
+
|
|
134
135
|
// For some browsers, like Safari, it is important that focus happens
|
|
135
136
|
// BEFORE selection.
|
|
136
137
|
node.focus();
|
|
@@ -144,11 +145,6 @@ export default function useMultiSelection() {
|
|
|
144
145
|
const startNode = getDeepestNode( startRef.current, 'start' );
|
|
145
146
|
const endNode = getDeepestNode( endRef.current, 'end' );
|
|
146
147
|
|
|
147
|
-
// While rich text will be disabled with a delay when there is a multi
|
|
148
|
-
// selection, we must do it immediately because it's not possible to set
|
|
149
|
-
// selection across editable hosts.
|
|
150
|
-
toggleRichText( node, false );
|
|
151
|
-
|
|
152
148
|
range.setStartBefore( startNode );
|
|
153
149
|
range.setEndAfter( endNode );
|
|
154
150
|
|
|
@@ -160,6 +156,7 @@ export default function useMultiSelection() {
|
|
|
160
156
|
isMultiSelecting,
|
|
161
157
|
multiSelectedBlockClientIds,
|
|
162
158
|
selectedBlockClientId,
|
|
159
|
+
initialPosition,
|
|
163
160
|
]
|
|
164
161
|
);
|
|
165
162
|
}
|
|
@@ -31,11 +31,15 @@ export default function useSelectAll() {
|
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
const selectedClientIds = getSelectedBlockClientIds();
|
|
35
|
+
|
|
36
|
+
if (
|
|
37
|
+
selectedClientIds.length < 2 &&
|
|
38
|
+
! isEntirelySelected( event.target )
|
|
39
|
+
) {
|
|
35
40
|
return;
|
|
36
41
|
}
|
|
37
42
|
|
|
38
|
-
const selectedClientIds = getSelectedBlockClientIds();
|
|
39
43
|
const [ firstSelectedClientId ] = selectedClientIds;
|
|
40
44
|
const rootClientId = getBlockRootClientId( firstSelectedClientId );
|
|
41
45
|
let blockClientIds = getBlockOrder( rootClientId );
|
|
@@ -112,6 +112,45 @@ export function addSaveProps( extraProps, blockType, attributes ) {
|
|
|
112
112
|
return extraProps;
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
export function addTransforms( result, source, index, results ) {
|
|
116
|
+
if ( ! hasBlockSupport( result.name, 'customClassName', true ) ) {
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// If the condition verifies we are probably in the presence of a wrapping transform
|
|
121
|
+
// e.g: nesting paragraphs in a group or columns and in that case the class should not be kept.
|
|
122
|
+
if ( results.length === 1 && result.innerBlocks.length === source.length ) {
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// If we are transforming one block to multiple blocks or multiple blocks to one block,
|
|
127
|
+
// we ignore the class during the transform.
|
|
128
|
+
if (
|
|
129
|
+
( results.length === 1 && source.length > 1 ) ||
|
|
130
|
+
( results.length > 1 && source.length === 1 )
|
|
131
|
+
) {
|
|
132
|
+
return result;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// If we are in presence of transform between one or more block in the source
|
|
136
|
+
// that have one or more blocks in the result
|
|
137
|
+
// we apply the class on source N to the result N,
|
|
138
|
+
// if source N does not exists we do nothing.
|
|
139
|
+
if ( source[ index ] ) {
|
|
140
|
+
const originClassName = source[ index ]?.attributes.className;
|
|
141
|
+
if ( originClassName ) {
|
|
142
|
+
return {
|
|
143
|
+
...result,
|
|
144
|
+
attributes: {
|
|
145
|
+
...result.attributes,
|
|
146
|
+
className: originClassName,
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
|
|
115
154
|
addFilter(
|
|
116
155
|
'blocks.registerBlockType',
|
|
117
156
|
'core/custom-class-name/attribute',
|
|
@@ -127,3 +166,9 @@ addFilter(
|
|
|
127
166
|
'core/custom-class-name/save-props',
|
|
128
167
|
addSaveProps
|
|
129
168
|
);
|
|
169
|
+
|
|
170
|
+
addFilter(
|
|
171
|
+
'blocks.switchToBlockType.transformedBlock',
|
|
172
|
+
'core/color/addTransforms',
|
|
173
|
+
addTransforms
|
|
174
|
+
);
|
package/src/hooks/line-height.js
CHANGED
package/src/hooks/style.js
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
__EXPERIMENTAL_ELEMENTS as ELEMENTS,
|
|
28
28
|
} from '@wordpress/blocks';
|
|
29
29
|
import { createHigherOrderComponent, useInstanceId } from '@wordpress/compose';
|
|
30
|
+
import { getCSSRules } from '@wordpress/style-engine';
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
33
|
* Internal dependencies
|
|
@@ -85,21 +86,35 @@ export function getInlineStyles( styles = {} ) {
|
|
|
85
86
|
// option and backwards compatibility for border radius support.
|
|
86
87
|
const styleValue = get( styles, path );
|
|
87
88
|
|
|
88
|
-
if (
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
89
|
+
if ( ! STYLE_PROPERTY[ propKey ].useEngine ) {
|
|
90
|
+
if ( !! subPaths && ! isString( styleValue ) ) {
|
|
91
|
+
Object.entries( subPaths ).forEach( ( entry ) => {
|
|
92
|
+
const [ name, subPath ] = entry;
|
|
93
|
+
const value = get( styleValue, [ subPath ] );
|
|
94
|
+
|
|
95
|
+
if ( value ) {
|
|
96
|
+
output[ name ] = compileStyleValue( value );
|
|
97
|
+
}
|
|
98
|
+
} );
|
|
99
|
+
} else if ( ! ignoredStyles.includes( path.join( '.' ) ) ) {
|
|
100
|
+
output[ propKey ] = compileStyleValue(
|
|
101
|
+
get( styles, path )
|
|
102
|
+
);
|
|
103
|
+
}
|
|
99
104
|
}
|
|
100
105
|
}
|
|
101
106
|
} );
|
|
102
107
|
|
|
108
|
+
// The goal is to move everything to server side generated engine styles
|
|
109
|
+
// This is temporary as we absorb more and more styles into the engine.
|
|
110
|
+
const extraRules = getCSSRules( styles, { selector: 'self' } );
|
|
111
|
+
extraRules.forEach( ( rule ) => {
|
|
112
|
+
if ( rule.selector !== 'self' ) {
|
|
113
|
+
throw "This style can't be added as inline style";
|
|
114
|
+
}
|
|
115
|
+
output[ rule.key ] = rule.value;
|
|
116
|
+
} );
|
|
117
|
+
|
|
103
118
|
return output;
|
|
104
119
|
}
|
|
105
120
|
|
package/src/layouts/flow.js
CHANGED
|
@@ -115,31 +115,36 @@ export default {
|
|
|
115
115
|
let output =
|
|
116
116
|
!! contentSize || !! wideSize
|
|
117
117
|
? `
|
|
118
|
-
${ appendSelectors(
|
|
118
|
+
${ appendSelectors(
|
|
119
|
+
selector,
|
|
120
|
+
'> :where(:not(.alignleft):not(.alignright))'
|
|
121
|
+
) } {
|
|
119
122
|
max-width: ${ contentSize ?? wideSize };
|
|
120
123
|
margin-left: auto !important;
|
|
121
124
|
margin-right: auto !important;
|
|
122
125
|
}
|
|
123
126
|
|
|
124
|
-
${ appendSelectors( selector, '>
|
|
127
|
+
${ appendSelectors( selector, '> .alignwide' ) } {
|
|
125
128
|
max-width: ${ wideSize ?? contentSize };
|
|
126
129
|
}
|
|
127
130
|
|
|
128
|
-
${ appendSelectors( selector, '>
|
|
131
|
+
${ appendSelectors( selector, '> .alignfull' ) } {
|
|
129
132
|
max-width: none;
|
|
130
133
|
}
|
|
131
134
|
`
|
|
132
135
|
: '';
|
|
133
136
|
|
|
134
137
|
output += `
|
|
135
|
-
${ appendSelectors( selector, '>
|
|
138
|
+
${ appendSelectors( selector, '> .alignleft' ) } {
|
|
136
139
|
float: left;
|
|
137
140
|
margin-right: 2em;
|
|
141
|
+
margin-left: 0;
|
|
138
142
|
}
|
|
139
143
|
|
|
140
|
-
${ appendSelectors( selector, '>
|
|
144
|
+
${ appendSelectors( selector, '> .alignright' ) } {
|
|
141
145
|
float: right;
|
|
142
146
|
margin-left: 2em;
|
|
147
|
+
margin-right: 0;
|
|
143
148
|
}
|
|
144
149
|
|
|
145
150
|
`;
|
package/src/store/actions.js
CHANGED
|
@@ -259,10 +259,15 @@ export function stopMultiSelect() {
|
|
|
259
259
|
/**
|
|
260
260
|
* Action that changes block multi-selection.
|
|
261
261
|
*
|
|
262
|
-
* @param {string}
|
|
263
|
-
* @param {string}
|
|
262
|
+
* @param {string} start First block of the multi selection.
|
|
263
|
+
* @param {string} end Last block of the multiselection.
|
|
264
|
+
* @param {number|null} __experimentalInitialPosition Optional initial position. Pass as null to skip focus within editor canvas.
|
|
264
265
|
*/
|
|
265
|
-
export const multiSelect = (
|
|
266
|
+
export const multiSelect = (
|
|
267
|
+
start,
|
|
268
|
+
end,
|
|
269
|
+
__experimentalInitialPosition = 0
|
|
270
|
+
) => ( { select, dispatch } ) => {
|
|
266
271
|
const startBlockRootClientId = select.getBlockRootClientId( start );
|
|
267
272
|
const endBlockRootClientId = select.getBlockRootClientId( end );
|
|
268
273
|
|
|
@@ -271,7 +276,12 @@ export const multiSelect = ( start, end ) => ( { select, dispatch } ) => {
|
|
|
271
276
|
return;
|
|
272
277
|
}
|
|
273
278
|
|
|
274
|
-
dispatch( {
|
|
279
|
+
dispatch( {
|
|
280
|
+
type: 'MULTI_SELECT',
|
|
281
|
+
start,
|
|
282
|
+
end,
|
|
283
|
+
initialPosition: __experimentalInitialPosition,
|
|
284
|
+
} );
|
|
275
285
|
|
|
276
286
|
const blockCount = select.getSelectedBlockCount();
|
|
277
287
|
|
|
@@ -996,11 +1006,11 @@ export function selectionChange(
|
|
|
996
1006
|
* @param {?Object} attributes Optional attributes of the block to assign.
|
|
997
1007
|
* @param {?string} rootClientId Optional root client ID of block list on which
|
|
998
1008
|
* to append.
|
|
999
|
-
* @param {?number} index Optional index where to insert the default block
|
|
1000
|
-
*
|
|
1001
|
-
* @return {Object} Action object
|
|
1009
|
+
* @param {?number} index Optional index where to insert the default block.
|
|
1002
1010
|
*/
|
|
1003
|
-
export
|
|
1011
|
+
export const insertDefaultBlock = ( attributes, rootClientId, index ) => ( {
|
|
1012
|
+
dispatch,
|
|
1013
|
+
} ) => {
|
|
1004
1014
|
// Abort if there is no default block type (if it has been unregistered).
|
|
1005
1015
|
const defaultBlockName = getDefaultBlockName();
|
|
1006
1016
|
if ( ! defaultBlockName ) {
|
|
@@ -1009,8 +1019,8 @@ export function insertDefaultBlock( attributes, rootClientId, index ) {
|
|
|
1009
1019
|
|
|
1010
1020
|
const block = createBlock( defaultBlockName, attributes );
|
|
1011
1021
|
|
|
1012
|
-
return insertBlock( block, index, rootClientId );
|
|
1013
|
-
}
|
|
1022
|
+
return dispatch.insertBlock( block, index, rootClientId );
|
|
1023
|
+
};
|
|
1014
1024
|
|
|
1015
1025
|
/**
|
|
1016
1026
|
* Action that changes the nested settings of a given block.
|
package/src/store/defaults.js
CHANGED
|
@@ -156,6 +156,7 @@ export const SETTINGS_DEFAULTS = {
|
|
|
156
156
|
__experimentalBlockPatterns: [],
|
|
157
157
|
__experimentalBlockPatternCategories: [],
|
|
158
158
|
__experimentalSpotlightEntityBlocks: [],
|
|
159
|
+
__experimentalGenerateAnchors: false,
|
|
159
160
|
__unstableGalleryWithImageBlocks: false,
|
|
160
161
|
|
|
161
162
|
// gradients setting is not used anymore now defaults are passed from theme.json on the server and core has its own defaults.
|
package/src/store/index.js
CHANGED
package/src/store/reducer.js
CHANGED
|
@@ -1380,7 +1380,7 @@ export function isSelectionEnabled( state = true, action ) {
|
|
|
1380
1380
|
}
|
|
1381
1381
|
|
|
1382
1382
|
/**
|
|
1383
|
-
* Reducer returning the
|
|
1383
|
+
* Reducer returning the initial block selection.
|
|
1384
1384
|
*
|
|
1385
1385
|
* Currently this in only used to restore the selection after block deletion and
|
|
1386
1386
|
* pasting new content.This reducer should eventually be removed in favour of setting
|
|
@@ -1399,6 +1399,7 @@ export function initialPosition( state = null, action ) {
|
|
|
1399
1399
|
return action.initialPosition;
|
|
1400
1400
|
} else if (
|
|
1401
1401
|
[
|
|
1402
|
+
'MULTI_SELECT',
|
|
1402
1403
|
'SELECT_BLOCK',
|
|
1403
1404
|
'RESET_SELECTION',
|
|
1404
1405
|
'INSERT_BLOCKS',
|
|
@@ -165,6 +165,7 @@ describe( 'actions', () => {
|
|
|
165
165
|
type: 'MULTI_SELECT',
|
|
166
166
|
start,
|
|
167
167
|
end,
|
|
168
|
+
initialPosition: 0,
|
|
168
169
|
} );
|
|
169
170
|
} );
|
|
170
171
|
|
|
@@ -1166,7 +1167,6 @@ describe( 'actions', () => {
|
|
|
1166
1167
|
actions,
|
|
1167
1168
|
selectors,
|
|
1168
1169
|
reducer,
|
|
1169
|
-
__experimentalUseThunks: true,
|
|
1170
1170
|
} );
|
|
1171
1171
|
|
|
1172
1172
|
registerBlockType( 'core/test-block', defaultBlockSettings );
|
|
@@ -2187,6 +2187,15 @@ describe( 'state', () => {
|
|
|
2187
2187
|
|
|
2188
2188
|
expect( state ).toBe( -1 );
|
|
2189
2189
|
} );
|
|
2190
|
+
|
|
2191
|
+
it( 'should allow setting null value in multi selection', () => {
|
|
2192
|
+
const state = initialPosition( undefined, {
|
|
2193
|
+
type: 'MULTI_SELECT',
|
|
2194
|
+
initialPosition: null,
|
|
2195
|
+
} );
|
|
2196
|
+
|
|
2197
|
+
expect( state ).toBe( null );
|
|
2198
|
+
} );
|
|
2190
2199
|
} );
|
|
2191
2200
|
|
|
2192
2201
|
describe( 'isMultiSelecting()', () => {
|
package/src/style.scss
CHANGED
|
@@ -36,7 +36,6 @@
|
|
|
36
36
|
@import "./components/inner-blocks/style.scss";
|
|
37
37
|
@import "./components/inserter-list-item/style.scss";
|
|
38
38
|
@import "./components/justify-content-control/style.scss";
|
|
39
|
-
@import "./components/line-height-control/style.scss";
|
|
40
39
|
@import "./components/link-control/style.scss";
|
|
41
40
|
@import "./components/list-view/style.scss";
|
|
42
41
|
@import "./components/media-replace-flow/style.scss";
|
package/src/utils/index.js
CHANGED
package/build/utils/theme.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.validateThemeColors = validateThemeColors;
|
|
7
|
-
exports.validateThemeGradients = validateThemeGradients;
|
|
8
|
-
|
|
9
|
-
var _defaults = require("../store/defaults");
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Internal dependencies
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Given an array of theme colors checks colors for validity
|
|
17
|
-
*
|
|
18
|
-
* @param {Array} colors The array of theme colors
|
|
19
|
-
*
|
|
20
|
-
* @return {Array} The array of valid theme colors or the default colors
|
|
21
|
-
*/
|
|
22
|
-
function validateThemeColors(colors) {
|
|
23
|
-
if (colors === undefined) {
|
|
24
|
-
colors = _defaults.SETTINGS_DEFAULTS.colors;
|
|
25
|
-
} else {
|
|
26
|
-
const validColors = colors.filter(c => c.color);
|
|
27
|
-
|
|
28
|
-
if (validColors.length === 0) {
|
|
29
|
-
colors = _defaults.SETTINGS_DEFAULTS.colors;
|
|
30
|
-
} else if (validColors.length < colors.length) {
|
|
31
|
-
// Filter out invalid colors
|
|
32
|
-
colors = validColors;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return colors;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Given an array of theme gradients checks gradients for validity
|
|
40
|
-
*
|
|
41
|
-
* @param {Array} gradients The array of theme gradients
|
|
42
|
-
*
|
|
43
|
-
* @return {Array} The array of valid theme gradients or the default gradients
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
function validateThemeGradients(gradients) {
|
|
48
|
-
if (gradients === undefined) {
|
|
49
|
-
gradients = _defaults.SETTINGS_DEFAULTS.gradients;
|
|
50
|
-
} else {
|
|
51
|
-
const validGradients = gradients.filter(c => c.gradient);
|
|
52
|
-
|
|
53
|
-
if (validGradients.length === 0) {
|
|
54
|
-
gradients = _defaults.SETTINGS_DEFAULTS.gradients;
|
|
55
|
-
} else if (validGradients.length < gradients.length) {
|
|
56
|
-
// Filter out invalid gradients
|
|
57
|
-
gradients = validGradients;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return gradients;
|
|
62
|
-
}
|
|
63
|
-
//# sourceMappingURL=theme.js.map
|
package/build/utils/theme.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/utils/theme.js"],"names":["validateThemeColors","colors","undefined","SETTINGS_DEFAULTS","validColors","filter","c","color","length","validateThemeGradients","gradients","validGradients","gradient"],"mappings":";;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,mBAAT,CAA8BC,MAA9B,EAAuC;AAC7C,MAAKA,MAAM,KAAKC,SAAhB,EAA4B;AAC3BD,IAAAA,MAAM,GAAGE,4BAAkBF,MAA3B;AACA,GAFD,MAEO;AACN,UAAMG,WAAW,GAAGH,MAAM,CAACI,MAAP,CAAiBC,CAAF,IAASA,CAAC,CAACC,KAA1B,CAApB;;AACA,QAAKH,WAAW,CAACI,MAAZ,KAAuB,CAA5B,EAAgC;AAC/BP,MAAAA,MAAM,GAAGE,4BAAkBF,MAA3B;AACA,KAFD,MAEO,IAAKG,WAAW,CAACI,MAAZ,GAAqBP,MAAM,CAACO,MAAjC,EAA0C;AAChD;AACAP,MAAAA,MAAM,GAAGG,WAAT;AACA;AACD;;AACD,SAAOH,MAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASQ,sBAAT,CAAiCC,SAAjC,EAA6C;AACnD,MAAKA,SAAS,KAAKR,SAAnB,EAA+B;AAC9BQ,IAAAA,SAAS,GAAGP,4BAAkBO,SAA9B;AACA,GAFD,MAEO;AACN,UAAMC,cAAc,GAAGD,SAAS,CAACL,MAAV,CAAoBC,CAAF,IAASA,CAAC,CAACM,QAA7B,CAAvB;;AACA,QAAKD,cAAc,CAACH,MAAf,KAA0B,CAA/B,EAAmC;AAClCE,MAAAA,SAAS,GAAGP,4BAAkBO,SAA9B;AACA,KAFD,MAEO,IAAKC,cAAc,CAACH,MAAf,GAAwBE,SAAS,CAACF,MAAvC,EAAgD;AACtD;AACAE,MAAAA,SAAS,GAAGC,cAAZ;AACA;AACD;;AACD,SAAOD,SAAP;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { SETTINGS_DEFAULTS } from '../store/defaults';\n\n/**\n * Given an array of theme colors checks colors for validity\n *\n * @param {Array} colors The array of theme colors\n *\n * @return {Array} The array of valid theme colors or the default colors\n */\nexport function validateThemeColors( colors ) {\n\tif ( colors === undefined ) {\n\t\tcolors = SETTINGS_DEFAULTS.colors;\n\t} else {\n\t\tconst validColors = colors.filter( ( c ) => c.color );\n\t\tif ( validColors.length === 0 ) {\n\t\t\tcolors = SETTINGS_DEFAULTS.colors;\n\t\t} else if ( validColors.length < colors.length ) {\n\t\t\t// Filter out invalid colors\n\t\t\tcolors = validColors;\n\t\t}\n\t}\n\treturn colors;\n}\n\n/**\n * Given an array of theme gradients checks gradients for validity\n *\n * @param {Array} gradients The array of theme gradients\n *\n * @return {Array} The array of valid theme gradients or the default gradients\n */\nexport function validateThemeGradients( gradients ) {\n\tif ( gradients === undefined ) {\n\t\tgradients = SETTINGS_DEFAULTS.gradients;\n\t} else {\n\t\tconst validGradients = gradients.filter( ( c ) => c.gradient );\n\t\tif ( validGradients.length === 0 ) {\n\t\t\tgradients = SETTINGS_DEFAULTS.gradients;\n\t\t} else if ( validGradients.length < gradients.length ) {\n\t\t\t// Filter out invalid gradients\n\t\t\tgradients = validGradients;\n\t\t}\n\t}\n\treturn gradients;\n}\n"]}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { SETTINGS_DEFAULTS } from '../store/defaults';
|
|
5
|
-
/**
|
|
6
|
-
* Given an array of theme colors checks colors for validity
|
|
7
|
-
*
|
|
8
|
-
* @param {Array} colors The array of theme colors
|
|
9
|
-
*
|
|
10
|
-
* @return {Array} The array of valid theme colors or the default colors
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
export function validateThemeColors(colors) {
|
|
14
|
-
if (colors === undefined) {
|
|
15
|
-
colors = SETTINGS_DEFAULTS.colors;
|
|
16
|
-
} else {
|
|
17
|
-
const validColors = colors.filter(c => c.color);
|
|
18
|
-
|
|
19
|
-
if (validColors.length === 0) {
|
|
20
|
-
colors = SETTINGS_DEFAULTS.colors;
|
|
21
|
-
} else if (validColors.length < colors.length) {
|
|
22
|
-
// Filter out invalid colors
|
|
23
|
-
colors = validColors;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return colors;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Given an array of theme gradients checks gradients for validity
|
|
31
|
-
*
|
|
32
|
-
* @param {Array} gradients The array of theme gradients
|
|
33
|
-
*
|
|
34
|
-
* @return {Array} The array of valid theme gradients or the default gradients
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
export function validateThemeGradients(gradients) {
|
|
38
|
-
if (gradients === undefined) {
|
|
39
|
-
gradients = SETTINGS_DEFAULTS.gradients;
|
|
40
|
-
} else {
|
|
41
|
-
const validGradients = gradients.filter(c => c.gradient);
|
|
42
|
-
|
|
43
|
-
if (validGradients.length === 0) {
|
|
44
|
-
gradients = SETTINGS_DEFAULTS.gradients;
|
|
45
|
-
} else if (validGradients.length < gradients.length) {
|
|
46
|
-
// Filter out invalid gradients
|
|
47
|
-
gradients = validGradients;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return gradients;
|
|
52
|
-
}
|
|
53
|
-
//# sourceMappingURL=theme.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/utils/theme.js"],"names":["SETTINGS_DEFAULTS","validateThemeColors","colors","undefined","validColors","filter","c","color","length","validateThemeGradients","gradients","validGradients","gradient"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,iBAAT,QAAkC,mBAAlC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,mBAAT,CAA8BC,MAA9B,EAAuC;AAC7C,MAAKA,MAAM,KAAKC,SAAhB,EAA4B;AAC3BD,IAAAA,MAAM,GAAGF,iBAAiB,CAACE,MAA3B;AACA,GAFD,MAEO;AACN,UAAME,WAAW,GAAGF,MAAM,CAACG,MAAP,CAAiBC,CAAF,IAASA,CAAC,CAACC,KAA1B,CAApB;;AACA,QAAKH,WAAW,CAACI,MAAZ,KAAuB,CAA5B,EAAgC;AAC/BN,MAAAA,MAAM,GAAGF,iBAAiB,CAACE,MAA3B;AACA,KAFD,MAEO,IAAKE,WAAW,CAACI,MAAZ,GAAqBN,MAAM,CAACM,MAAjC,EAA0C;AAChD;AACAN,MAAAA,MAAM,GAAGE,WAAT;AACA;AACD;;AACD,SAAOF,MAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASO,sBAAT,CAAiCC,SAAjC,EAA6C;AACnD,MAAKA,SAAS,KAAKP,SAAnB,EAA+B;AAC9BO,IAAAA,SAAS,GAAGV,iBAAiB,CAACU,SAA9B;AACA,GAFD,MAEO;AACN,UAAMC,cAAc,GAAGD,SAAS,CAACL,MAAV,CAAoBC,CAAF,IAASA,CAAC,CAACM,QAA7B,CAAvB;;AACA,QAAKD,cAAc,CAACH,MAAf,KAA0B,CAA/B,EAAmC;AAClCE,MAAAA,SAAS,GAAGV,iBAAiB,CAACU,SAA9B;AACA,KAFD,MAEO,IAAKC,cAAc,CAACH,MAAf,GAAwBE,SAAS,CAACF,MAAvC,EAAgD;AACtD;AACAE,MAAAA,SAAS,GAAGC,cAAZ;AACA;AACD;;AACD,SAAOD,SAAP;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { SETTINGS_DEFAULTS } from '../store/defaults';\n\n/**\n * Given an array of theme colors checks colors for validity\n *\n * @param {Array} colors The array of theme colors\n *\n * @return {Array} The array of valid theme colors or the default colors\n */\nexport function validateThemeColors( colors ) {\n\tif ( colors === undefined ) {\n\t\tcolors = SETTINGS_DEFAULTS.colors;\n\t} else {\n\t\tconst validColors = colors.filter( ( c ) => c.color );\n\t\tif ( validColors.length === 0 ) {\n\t\t\tcolors = SETTINGS_DEFAULTS.colors;\n\t\t} else if ( validColors.length < colors.length ) {\n\t\t\t// Filter out invalid colors\n\t\t\tcolors = validColors;\n\t\t}\n\t}\n\treturn colors;\n}\n\n/**\n * Given an array of theme gradients checks gradients for validity\n *\n * @param {Array} gradients The array of theme gradients\n *\n * @return {Array} The array of valid theme gradients or the default gradients\n */\nexport function validateThemeGradients( gradients ) {\n\tif ( gradients === undefined ) {\n\t\tgradients = SETTINGS_DEFAULTS.gradients;\n\t} else {\n\t\tconst validGradients = gradients.filter( ( c ) => c.gradient );\n\t\tif ( validGradients.length === 0 ) {\n\t\t\tgradients = SETTINGS_DEFAULTS.gradients;\n\t\t} else if ( validGradients.length < gradients.length ) {\n\t\t\t// Filter out invalid gradients\n\t\t\tgradients = validGradients;\n\t\t}\n\t}\n\treturn gradients;\n}\n"]}
|