@wordpress/block-editor 12.8.0 → 12.9.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 +6 -0
- package/README.md +30 -12
- package/build/components/block-controls/slot.js +1 -1
- package/build/components/block-controls/slot.js.map +1 -1
- package/build/components/block-controls/slot.native.js +1 -1
- package/build/components/block-controls/slot.native.js.map +1 -1
- package/build/components/block-controls/use-has-block-controls.js +1 -1
- package/build/components/block-controls/use-has-block-controls.js.map +1 -1
- package/build/components/block-list/block-outline.native.js +4 -3
- package/build/components/block-list/block-outline.native.js.map +1 -1
- package/build/components/block-list/index.js +4 -3
- package/build/components/block-list/index.js.map +1 -1
- package/build/components/block-list/use-block-props/index.js +27 -1
- package/build/components/block-list/use-block-props/index.js.map +1 -1
- package/build/components/block-list/use-block-props/use-nav-mode-exit.js +1 -1
- package/build/components/block-list/use-block-props/use-nav-mode-exit.js.map +1 -1
- package/build/components/block-lock/menu-item.js +3 -1
- package/build/components/block-lock/menu-item.js.map +1 -1
- package/build/components/block-lock/toolbar.js +3 -1
- package/build/components/block-lock/toolbar.js.map +1 -1
- package/build/components/block-popover/inbetween.js +4 -5
- package/build/components/block-popover/inbetween.js.map +1 -1
- package/build/components/block-popover/index.js +3 -2
- package/build/components/block-popover/index.js.map +1 -1
- package/build/components/color-style-selector/index.js +1 -1
- package/build/components/color-style-selector/index.js.map +1 -1
- package/build/components/iframe/index.js +1 -0
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/inserter/reusable-blocks-tab.native.js +7 -4
- package/build/components/inserter/reusable-blocks-tab.native.js.map +1 -1
- package/build/components/inserter/search-results.native.js +10 -8
- package/build/components/inserter/search-results.native.js.map +1 -1
- package/build/components/inspector-controls/fill.js +1 -1
- package/build/components/inspector-controls/fill.js.map +1 -1
- package/build/components/inspector-controls/fill.native.js +1 -1
- package/build/components/inspector-controls/fill.native.js.map +1 -1
- package/build/components/inspector-controls/slot.js +1 -1
- package/build/components/inspector-controls/slot.js.map +1 -1
- package/build/components/inspector-controls/slot.native.js +1 -1
- package/build/components/inspector-controls/slot.native.js.map +1 -1
- package/build/components/link-control/index.js +1 -7
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/list-view/block-select-button.js +48 -7
- package/build/components/list-view/block-select-button.js.map +1 -1
- package/build/components/list-view/drop-indicator.js +3 -3
- package/build/components/list-view/drop-indicator.js.map +1 -1
- package/build/components/list-view/index.js +14 -8
- package/build/components/list-view/index.js.map +1 -1
- package/build/components/list-view/use-list-view-images.js +5 -4
- package/build/components/list-view/use-list-view-images.js.map +1 -1
- package/build/components/preview-options/index.js +3 -1
- package/build/components/preview-options/index.js.map +1 -1
- package/build/components/provider/index.js +3 -1
- package/build/components/provider/index.js.map +1 -1
- package/build/components/rich-text/use-remove-browser-shortcuts.js +1 -1
- package/build/components/rich-text/use-remove-browser-shortcuts.js.map +1 -1
- package/build/components/use-block-commands/index.js +74 -63
- package/build/components/use-block-commands/index.js.map +1 -1
- package/build/components/warning/index.js +1 -1
- package/build/components/warning/index.js.map +1 -1
- package/build/hooks/auto-inserting-blocks.js +174 -0
- package/build/hooks/auto-inserting-blocks.js.map +1 -0
- package/build/hooks/index.js +1 -0
- package/build/hooks/index.js.map +1 -1
- package/build/store/selectors.js +1 -1
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/block-controls/slot.js +1 -1
- package/build-module/components/block-controls/slot.js.map +1 -1
- package/build-module/components/block-controls/slot.native.js +1 -1
- package/build-module/components/block-controls/slot.native.js.map +1 -1
- package/build-module/components/block-controls/use-has-block-controls.js +1 -1
- package/build-module/components/block-controls/use-has-block-controls.js.map +1 -1
- package/build-module/components/block-list/block-outline.native.js +4 -3
- package/build-module/components/block-list/block-outline.native.js.map +1 -1
- package/build-module/components/block-list/index.js +4 -3
- package/build-module/components/block-list/index.js.map +1 -1
- package/build-module/components/block-list/use-block-props/index.js +27 -1
- package/build-module/components/block-list/use-block-props/index.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-nav-mode-exit.js +1 -1
- package/build-module/components/block-list/use-block-props/use-nav-mode-exit.js.map +1 -1
- package/build-module/components/block-lock/menu-item.js +3 -1
- package/build-module/components/block-lock/menu-item.js.map +1 -1
- package/build-module/components/block-lock/toolbar.js +3 -1
- package/build-module/components/block-lock/toolbar.js.map +1 -1
- package/build-module/components/block-popover/inbetween.js +4 -5
- package/build-module/components/block-popover/inbetween.js.map +1 -1
- package/build-module/components/block-popover/index.js +3 -2
- package/build-module/components/block-popover/index.js.map +1 -1
- package/build-module/components/color-style-selector/index.js +1 -1
- package/build-module/components/color-style-selector/index.js.map +1 -1
- package/build-module/components/iframe/index.js +1 -0
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/inserter/reusable-blocks-tab.native.js +8 -4
- package/build-module/components/inserter/reusable-blocks-tab.native.js.map +1 -1
- package/build-module/components/inserter/search-results.native.js +11 -8
- package/build-module/components/inserter/search-results.native.js.map +1 -1
- package/build-module/components/inspector-controls/fill.js +1 -1
- package/build-module/components/inspector-controls/fill.js.map +1 -1
- package/build-module/components/inspector-controls/fill.native.js +1 -1
- package/build-module/components/inspector-controls/fill.native.js.map +1 -1
- package/build-module/components/inspector-controls/slot.js +1 -1
- package/build-module/components/inspector-controls/slot.js.map +1 -1
- package/build-module/components/inspector-controls/slot.native.js +1 -1
- package/build-module/components/inspector-controls/slot.native.js.map +1 -1
- package/build-module/components/link-control/index.js +1 -7
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/list-view/block-select-button.js +48 -7
- package/build-module/components/list-view/block-select-button.js.map +1 -1
- package/build-module/components/list-view/drop-indicator.js +3 -3
- package/build-module/components/list-view/drop-indicator.js.map +1 -1
- package/build-module/components/list-view/index.js +14 -8
- package/build-module/components/list-view/index.js.map +1 -1
- package/build-module/components/list-view/use-list-view-images.js +5 -4
- package/build-module/components/list-view/use-list-view-images.js.map +1 -1
- package/build-module/components/preview-options/index.js +3 -1
- package/build-module/components/preview-options/index.js.map +1 -1
- package/build-module/components/provider/index.js +3 -1
- package/build-module/components/provider/index.js.map +1 -1
- package/build-module/components/rich-text/use-remove-browser-shortcuts.js +1 -1
- package/build-module/components/rich-text/use-remove-browser-shortcuts.js.map +1 -1
- package/build-module/components/use-block-commands/index.js +74 -63
- package/build-module/components/use-block-commands/index.js.map +1 -1
- package/build-module/components/warning/index.js +2 -2
- package/build-module/components/warning/index.js.map +1 -1
- package/build-module/hooks/auto-inserting-blocks.js +167 -0
- package/build-module/hooks/auto-inserting-blocks.js.map +1 -0
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/store/selectors.js +1 -1
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/content-rtl.css +8 -7
- package/build-style/content.css +8 -7
- package/build-style/style-rtl.css +0 -3
- package/build-style/style.css +0 -3
- package/package.json +32 -32
- package/src/components/block-icon/test/index.js +2 -2
- package/src/components/block-list/block-outline.native.js +5 -2
- package/src/components/block-list/content.scss +2 -3
- package/src/components/block-list/index.js +4 -3
- package/src/components/block-list/use-block-props/index.js +26 -0
- package/src/components/block-list/use-block-props/use-nav-mode-exit.js +1 -1
- package/src/components/block-lock/menu-item.js +2 -0
- package/src/components/block-lock/toolbar.js +3 -1
- package/src/components/block-popover/inbetween.js +4 -3
- package/src/components/block-popover/index.js +3 -2
- package/src/components/block-styles/style.scss +0 -3
- package/src/components/button-block-appender/content.scss +8 -0
- package/src/components/color-style-selector/index.js +1 -1
- package/src/components/iframe/index.js +1 -0
- package/src/components/inserter/reusable-blocks-tab.native.js +7 -2
- package/src/components/inserter/search-results.native.js +13 -9
- package/src/components/link-control/index.js +1 -5
- package/src/components/link-control/test/index.js +1 -0
- package/src/components/list-view/block-select-button.js +67 -15
- package/src/components/list-view/drop-indicator.js +4 -5
- package/src/components/list-view/index.js +19 -13
- package/src/components/list-view/use-list-view-images.js +8 -4
- package/src/components/observe-typing/README.md +2 -2
- package/src/components/preview-options/index.js +2 -0
- package/src/components/provider/index.js +8 -1
- package/src/components/rich-text/use-remove-browser-shortcuts.js +1 -1
- package/src/components/use-block-commands/index.js +92 -88
- package/src/components/warning/index.js +2 -2
- package/src/hooks/auto-inserting-blocks.js +232 -0
- package/src/hooks/index.js +1 -0
- package/src/store/selectors.js +1 -1
- package/build/utils/pre-parse-patterns.js +0 -68
- package/build/utils/pre-parse-patterns.js.map +0 -1
- package/build-module/utils/pre-parse-patterns.js +0 -61
- package/build-module/utils/pre-parse-patterns.js.map +0 -1
- package/src/components/url-popover/test/__snapshots__/index.js.snap +0 -133
- package/src/components/url-popover/test/index.js +0 -75
- package/src/utils/pre-parse-patterns.js +0 -69
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
import { addFilter } from '@wordpress/hooks';
|
|
6
|
+
import { Fragment } from '@wordpress/element';
|
|
7
|
+
import { PanelBody, ToggleControl } from '@wordpress/components';
|
|
8
|
+
import { createHigherOrderComponent } from '@wordpress/compose';
|
|
9
|
+
import { createBlock, store as blocksStore } from '@wordpress/blocks';
|
|
10
|
+
import { useDispatch, useSelect } from '@wordpress/data';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Internal dependencies
|
|
14
|
+
*/
|
|
15
|
+
import { InspectorControls } from '../components';
|
|
16
|
+
import { store as blockEditorStore } from '../store';
|
|
17
|
+
|
|
18
|
+
function AutoInsertingBlocksControl( props ) {
|
|
19
|
+
const { autoInsertedBlocksForCurrentBlock, groupedAutoInsertedBlocks } =
|
|
20
|
+
useSelect(
|
|
21
|
+
( select ) => {
|
|
22
|
+
const { getBlockTypes } = select( blocksStore );
|
|
23
|
+
const _autoInsertedBlocksForCurrentBlock =
|
|
24
|
+
getBlockTypes()?.filter(
|
|
25
|
+
( { autoInsert } ) =>
|
|
26
|
+
autoInsert && props.blockName in autoInsert
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
// Group by block namespace (i.e. prefix before the slash).
|
|
30
|
+
const _groupedAutoInsertedBlocks =
|
|
31
|
+
_autoInsertedBlocksForCurrentBlock?.reduce(
|
|
32
|
+
( groups, block ) => {
|
|
33
|
+
const [ namespace ] = block.name.split( '/' );
|
|
34
|
+
if ( ! groups[ namespace ] ) {
|
|
35
|
+
groups[ namespace ] = [];
|
|
36
|
+
}
|
|
37
|
+
groups[ namespace ].push( block );
|
|
38
|
+
return groups;
|
|
39
|
+
},
|
|
40
|
+
{}
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
autoInsertedBlocksForCurrentBlock:
|
|
45
|
+
_autoInsertedBlocksForCurrentBlock,
|
|
46
|
+
groupedAutoInsertedBlocks: _groupedAutoInsertedBlocks,
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
[ props.blockName ]
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const {
|
|
53
|
+
autoInsertedBlockClientIds,
|
|
54
|
+
blockIndex,
|
|
55
|
+
rootClientId,
|
|
56
|
+
innerBlocksLength,
|
|
57
|
+
} = useSelect(
|
|
58
|
+
( select ) => {
|
|
59
|
+
const { getBlock, getBlockIndex, getBlockRootClientId } =
|
|
60
|
+
select( blockEditorStore );
|
|
61
|
+
const _rootClientId = getBlockRootClientId( props.clientId );
|
|
62
|
+
|
|
63
|
+
const _autoInsertedBlockClientIds =
|
|
64
|
+
autoInsertedBlocksForCurrentBlock.reduce(
|
|
65
|
+
( clientIds, block ) => {
|
|
66
|
+
const relativePosition =
|
|
67
|
+
block?.autoInsert?.[ props.blockName ];
|
|
68
|
+
let candidates;
|
|
69
|
+
|
|
70
|
+
switch ( relativePosition ) {
|
|
71
|
+
case 'before':
|
|
72
|
+
case 'after':
|
|
73
|
+
// Any of the current block's siblings (with the right block type) qualifies
|
|
74
|
+
// as an auto-inserted block (inserted `before` or `after` the current one),
|
|
75
|
+
// as the block might've been auto-inserted and then moved around a bit by the user.
|
|
76
|
+
candidates =
|
|
77
|
+
getBlock( _rootClientId )?.innerBlocks;
|
|
78
|
+
break;
|
|
79
|
+
|
|
80
|
+
case 'first_child':
|
|
81
|
+
case 'last_child':
|
|
82
|
+
// Any of the current block's child blocks (with the right block type) qualifies
|
|
83
|
+
// as an auto-inserted first or last child block, as the block might've been
|
|
84
|
+
// auto-inserted and then moved around a bit by the user.
|
|
85
|
+
candidates = getBlock(
|
|
86
|
+
props.clientId
|
|
87
|
+
).innerBlocks;
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const autoInsertedBlock = candidates?.find(
|
|
92
|
+
( { name } ) => name === block.name
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
if ( autoInsertedBlock ) {
|
|
96
|
+
clientIds[ block.name ] =
|
|
97
|
+
autoInsertedBlock.clientId;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// TOOD: If no auto-inserted block was found in any of its designated locations,
|
|
101
|
+
// we want to check if it's present elsewhere in the block tree.
|
|
102
|
+
// If it is, we'd consider it manually inserted and would want to remove the
|
|
103
|
+
// corresponding toggle from the block inspector panel.
|
|
104
|
+
|
|
105
|
+
return clientIds;
|
|
106
|
+
},
|
|
107
|
+
{}
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
blockIndex: getBlockIndex( props.clientId ),
|
|
112
|
+
innerBlocksLength: getBlock( props.clientId )?.innerBlocks
|
|
113
|
+
?.length,
|
|
114
|
+
rootClientId: _rootClientId,
|
|
115
|
+
autoInsertedBlockClientIds: _autoInsertedBlockClientIds,
|
|
116
|
+
};
|
|
117
|
+
},
|
|
118
|
+
[ autoInsertedBlocksForCurrentBlock, props.blockName, props.clientId ]
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
const { insertBlock, removeBlock } = useDispatch( blockEditorStore );
|
|
122
|
+
|
|
123
|
+
if ( ! autoInsertedBlocksForCurrentBlock.length ) {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const insertBlockIntoDesignatedLocation = ( block, relativePosition ) => {
|
|
128
|
+
switch ( relativePosition ) {
|
|
129
|
+
case 'before':
|
|
130
|
+
case 'after':
|
|
131
|
+
insertBlock(
|
|
132
|
+
block,
|
|
133
|
+
relativePosition === 'after' ? blockIndex + 1 : blockIndex,
|
|
134
|
+
rootClientId, // Insert as a child of the current block's parent
|
|
135
|
+
false
|
|
136
|
+
);
|
|
137
|
+
break;
|
|
138
|
+
|
|
139
|
+
case 'first_child':
|
|
140
|
+
case 'last_child':
|
|
141
|
+
insertBlock(
|
|
142
|
+
block,
|
|
143
|
+
// TODO: It'd be great if insertBlock() would accept negative indices for insertion.
|
|
144
|
+
relativePosition === 'first_child' ? 0 : innerBlocksLength,
|
|
145
|
+
props.clientId, // Insert as a child of the current block.
|
|
146
|
+
false
|
|
147
|
+
);
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
return (
|
|
153
|
+
<InspectorControls>
|
|
154
|
+
<PanelBody title={ __( 'Plugins' ) } initialOpen={ true }>
|
|
155
|
+
{ Object.keys( groupedAutoInsertedBlocks ).map( ( vendor ) => {
|
|
156
|
+
return (
|
|
157
|
+
<Fragment key={ vendor }>
|
|
158
|
+
<h3>{ vendor }</h3>
|
|
159
|
+
{ groupedAutoInsertedBlocks[ vendor ].map(
|
|
160
|
+
( block ) => {
|
|
161
|
+
// TODO: Display block icon.
|
|
162
|
+
// <BlockIcon icon={ block.icon } />
|
|
163
|
+
|
|
164
|
+
const checked =
|
|
165
|
+
block.name in
|
|
166
|
+
autoInsertedBlockClientIds;
|
|
167
|
+
|
|
168
|
+
return (
|
|
169
|
+
<ToggleControl
|
|
170
|
+
checked={ checked }
|
|
171
|
+
key={ block.title }
|
|
172
|
+
label={ block.title }
|
|
173
|
+
onChange={ () => {
|
|
174
|
+
if ( ! checked ) {
|
|
175
|
+
// Create and insert block.
|
|
176
|
+
const relativePosition =
|
|
177
|
+
block.autoInsert[
|
|
178
|
+
props.blockName
|
|
179
|
+
];
|
|
180
|
+
insertBlockIntoDesignatedLocation(
|
|
181
|
+
createBlock(
|
|
182
|
+
block.name
|
|
183
|
+
),
|
|
184
|
+
relativePosition
|
|
185
|
+
);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Remove block.
|
|
190
|
+
const clientId =
|
|
191
|
+
autoInsertedBlockClientIds[
|
|
192
|
+
block.name
|
|
193
|
+
];
|
|
194
|
+
removeBlock( clientId, false );
|
|
195
|
+
} }
|
|
196
|
+
/>
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
) }
|
|
200
|
+
</Fragment>
|
|
201
|
+
);
|
|
202
|
+
} ) }
|
|
203
|
+
</PanelBody>
|
|
204
|
+
</InspectorControls>
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export const withAutoInsertingBlocks = createHigherOrderComponent(
|
|
209
|
+
( BlockEdit ) => {
|
|
210
|
+
return ( props ) => {
|
|
211
|
+
const blockEdit = <BlockEdit key="edit" { ...props } />;
|
|
212
|
+
return (
|
|
213
|
+
<>
|
|
214
|
+
{ blockEdit }
|
|
215
|
+
<AutoInsertingBlocksControl
|
|
216
|
+
blockName={ props.name }
|
|
217
|
+
clientId={ props.clientId }
|
|
218
|
+
/>
|
|
219
|
+
</>
|
|
220
|
+
);
|
|
221
|
+
};
|
|
222
|
+
},
|
|
223
|
+
'withAutoInsertingBlocks'
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
if ( window?.__experimentalAutoInsertingBlocks ) {
|
|
227
|
+
addFilter(
|
|
228
|
+
'editor.BlockEdit',
|
|
229
|
+
'core/auto-inserting-blocks/with-inspector-control',
|
|
230
|
+
withAutoInsertingBlocks
|
|
231
|
+
);
|
|
232
|
+
}
|
package/src/hooks/index.js
CHANGED
package/src/store/selectors.js
CHANGED
|
@@ -1978,7 +1978,7 @@ export const getInserterItems = createSelector(
|
|
|
1978
1978
|
id,
|
|
1979
1979
|
name: 'core/block',
|
|
1980
1980
|
initialAttributes: { ref: reusableBlock.id },
|
|
1981
|
-
title: reusableBlock.title
|
|
1981
|
+
title: reusableBlock.title?.raw,
|
|
1982
1982
|
icon,
|
|
1983
1983
|
category: 'reusable',
|
|
1984
1984
|
keywords: [ 'reusable' ],
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.usePreParsePatterns = usePreParsePatterns;
|
|
7
|
-
var _data = require("@wordpress/data");
|
|
8
|
-
var _element = require("@wordpress/element");
|
|
9
|
-
var _store = require("../store");
|
|
10
|
-
/**
|
|
11
|
-
* WordPress dependencies
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Internal dependencies
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
const requestIdleCallback = (() => {
|
|
19
|
-
if (typeof window === 'undefined') {
|
|
20
|
-
return callback => {
|
|
21
|
-
setTimeout(() => callback(Date.now()), 0);
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
return window.requestIdleCallback || window.requestAnimationFrame;
|
|
25
|
-
})();
|
|
26
|
-
const cancelIdleCallback = (() => {
|
|
27
|
-
if (typeof window === 'undefined') {
|
|
28
|
-
return clearTimeout;
|
|
29
|
-
}
|
|
30
|
-
return window.cancelIdleCallback || window.cancelAnimationFrame;
|
|
31
|
-
})();
|
|
32
|
-
function usePreParsePatterns() {
|
|
33
|
-
const {
|
|
34
|
-
patterns,
|
|
35
|
-
isPreviewMode
|
|
36
|
-
} = (0, _data.useSelect)(_select => {
|
|
37
|
-
const {
|
|
38
|
-
__experimentalBlockPatterns,
|
|
39
|
-
__unstableIsPreviewMode
|
|
40
|
-
} = _select(_store.store).getSettings();
|
|
41
|
-
return {
|
|
42
|
-
patterns: __experimentalBlockPatterns,
|
|
43
|
-
isPreviewMode: __unstableIsPreviewMode
|
|
44
|
-
};
|
|
45
|
-
}, []);
|
|
46
|
-
(0, _element.useEffect)(() => {
|
|
47
|
-
if (isPreviewMode) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
if (!patterns?.length) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
let handle;
|
|
54
|
-
let index = -1;
|
|
55
|
-
const callback = () => {
|
|
56
|
-
index++;
|
|
57
|
-
if (index >= patterns.length) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
(0, _data.select)(_store.store).__experimentalGetParsedPattern(patterns[index].name);
|
|
61
|
-
handle = requestIdleCallback(callback);
|
|
62
|
-
};
|
|
63
|
-
handle = requestIdleCallback(callback);
|
|
64
|
-
return () => cancelIdleCallback(handle);
|
|
65
|
-
}, [patterns, isPreviewMode]);
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
//# sourceMappingURL=pre-parse-patterns.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_data","require","_element","_store","requestIdleCallback","window","callback","setTimeout","Date","now","requestAnimationFrame","cancelIdleCallback","clearTimeout","cancelAnimationFrame","usePreParsePatterns","patterns","isPreviewMode","useSelect","_select","__experimentalBlockPatterns","__unstableIsPreviewMode","blockEditorStore","getSettings","useEffect","length","handle","index","select","__experimentalGetParsedPattern","name"],"sources":["@wordpress/block-editor/src/utils/pre-parse-patterns.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, select } from '@wordpress/data';\nimport { useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../store';\n\nconst requestIdleCallback = ( () => {\n\tif ( typeof window === 'undefined' ) {\n\t\treturn ( callback ) => {\n\t\t\tsetTimeout( () => callback( Date.now() ), 0 );\n\t\t};\n\t}\n\n\treturn window.requestIdleCallback || window.requestAnimationFrame;\n} )();\n\nconst cancelIdleCallback = ( () => {\n\tif ( typeof window === 'undefined' ) {\n\t\treturn clearTimeout;\n\t}\n\n\treturn window.cancelIdleCallback || window.cancelAnimationFrame;\n} )();\n\nexport function usePreParsePatterns() {\n\tconst { patterns, isPreviewMode } = useSelect( ( _select ) => {\n\t\tconst { __experimentalBlockPatterns, __unstableIsPreviewMode } =\n\t\t\t_select( blockEditorStore ).getSettings();\n\t\treturn {\n\t\t\tpatterns: __experimentalBlockPatterns,\n\t\t\tisPreviewMode: __unstableIsPreviewMode,\n\t\t};\n\t}, [] );\n\n\tuseEffect( () => {\n\t\tif ( isPreviewMode ) {\n\t\t\treturn;\n\t\t}\n\t\tif ( ! patterns?.length ) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet handle;\n\t\tlet index = -1;\n\n\t\tconst callback = () => {\n\t\t\tindex++;\n\t\t\tif ( index >= patterns.length ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tselect( blockEditorStore ).__experimentalGetParsedPattern(\n\t\t\t\tpatterns[ index ].name\n\t\t\t);\n\n\t\t\thandle = requestIdleCallback( callback );\n\t\t};\n\n\t\thandle = requestIdleCallback( callback );\n\t\treturn () => cancelIdleCallback( handle );\n\t}, [ patterns, isPreviewMode ] );\n\n\treturn null;\n}\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAKA,IAAAE,MAAA,GAAAF,OAAA;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA,MAAMG,mBAAmB,GAAG,CAAE,MAAM;EACnC,IAAK,OAAOC,MAAM,KAAK,WAAW,EAAG;IACpC,OAASC,QAAQ,IAAM;MACtBC,UAAU,CAAE,MAAMD,QAAQ,CAAEE,IAAI,CAACC,GAAG,CAAC,CAAE,CAAC,EAAE,CAAE,CAAC;IAC9C,CAAC;EACF;EAEA,OAAOJ,MAAM,CAACD,mBAAmB,IAAIC,MAAM,CAACK,qBAAqB;AAClE,CAAC,EAAG,CAAC;AAEL,MAAMC,kBAAkB,GAAG,CAAE,MAAM;EAClC,IAAK,OAAON,MAAM,KAAK,WAAW,EAAG;IACpC,OAAOO,YAAY;EACpB;EAEA,OAAOP,MAAM,CAACM,kBAAkB,IAAIN,MAAM,CAACQ,oBAAoB;AAChE,CAAC,EAAG,CAAC;AAEE,SAASC,mBAAmBA,CAAA,EAAG;EACrC,MAAM;IAAEC,QAAQ;IAAEC;EAAc,CAAC,GAAG,IAAAC,eAAS,EAAIC,OAAO,IAAM;IAC7D,MAAM;MAAEC,2BAA2B;MAAEC;IAAwB,CAAC,GAC7DF,OAAO,CAAEG,YAAiB,CAAC,CAACC,WAAW,CAAC,CAAC;IAC1C,OAAO;MACNP,QAAQ,EAAEI,2BAA2B;MACrCH,aAAa,EAAEI;IAChB,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;EAEP,IAAAG,kBAAS,EAAE,MAAM;IAChB,IAAKP,aAAa,EAAG;MACpB;IACD;IACA,IAAK,CAAED,QAAQ,EAAES,MAAM,EAAG;MACzB;IACD;IAEA,IAAIC,MAAM;IACV,IAAIC,KAAK,GAAG,CAAC,CAAC;IAEd,MAAMpB,QAAQ,GAAGA,CAAA,KAAM;MACtBoB,KAAK,EAAE;MACP,IAAKA,KAAK,IAAIX,QAAQ,CAACS,MAAM,EAAG;QAC/B;MACD;MAEA,IAAAG,YAAM,EAAEN,YAAiB,CAAC,CAACO,8BAA8B,CACxDb,QAAQ,CAAEW,KAAK,CAAE,CAACG,IACnB,CAAC;MAEDJ,MAAM,GAAGrB,mBAAmB,CAAEE,QAAS,CAAC;IACzC,CAAC;IAEDmB,MAAM,GAAGrB,mBAAmB,CAAEE,QAAS,CAAC;IACxC,OAAO,MAAMK,kBAAkB,CAAEc,MAAO,CAAC;EAC1C,CAAC,EAAE,CAAEV,QAAQ,EAAEC,aAAa,CAAG,CAAC;EAEhC,OAAO,IAAI;AACZ"}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { useSelect, select } from '@wordpress/data';
|
|
5
|
-
import { useEffect } from '@wordpress/element';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Internal dependencies
|
|
9
|
-
*/
|
|
10
|
-
import { store as blockEditorStore } from '../store';
|
|
11
|
-
const requestIdleCallback = (() => {
|
|
12
|
-
if (typeof window === 'undefined') {
|
|
13
|
-
return callback => {
|
|
14
|
-
setTimeout(() => callback(Date.now()), 0);
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
return window.requestIdleCallback || window.requestAnimationFrame;
|
|
18
|
-
})();
|
|
19
|
-
const cancelIdleCallback = (() => {
|
|
20
|
-
if (typeof window === 'undefined') {
|
|
21
|
-
return clearTimeout;
|
|
22
|
-
}
|
|
23
|
-
return window.cancelIdleCallback || window.cancelAnimationFrame;
|
|
24
|
-
})();
|
|
25
|
-
export function usePreParsePatterns() {
|
|
26
|
-
const {
|
|
27
|
-
patterns,
|
|
28
|
-
isPreviewMode
|
|
29
|
-
} = useSelect(_select => {
|
|
30
|
-
const {
|
|
31
|
-
__experimentalBlockPatterns,
|
|
32
|
-
__unstableIsPreviewMode
|
|
33
|
-
} = _select(blockEditorStore).getSettings();
|
|
34
|
-
return {
|
|
35
|
-
patterns: __experimentalBlockPatterns,
|
|
36
|
-
isPreviewMode: __unstableIsPreviewMode
|
|
37
|
-
};
|
|
38
|
-
}, []);
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
if (isPreviewMode) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
if (!patterns?.length) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
let handle;
|
|
47
|
-
let index = -1;
|
|
48
|
-
const callback = () => {
|
|
49
|
-
index++;
|
|
50
|
-
if (index >= patterns.length) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
select(blockEditorStore).__experimentalGetParsedPattern(patterns[index].name);
|
|
54
|
-
handle = requestIdleCallback(callback);
|
|
55
|
-
};
|
|
56
|
-
handle = requestIdleCallback(callback);
|
|
57
|
-
return () => cancelIdleCallback(handle);
|
|
58
|
-
}, [patterns, isPreviewMode]);
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
//# sourceMappingURL=pre-parse-patterns.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["useSelect","select","useEffect","store","blockEditorStore","requestIdleCallback","window","callback","setTimeout","Date","now","requestAnimationFrame","cancelIdleCallback","clearTimeout","cancelAnimationFrame","usePreParsePatterns","patterns","isPreviewMode","_select","__experimentalBlockPatterns","__unstableIsPreviewMode","getSettings","length","handle","index","__experimentalGetParsedPattern","name"],"sources":["@wordpress/block-editor/src/utils/pre-parse-patterns.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, select } from '@wordpress/data';\nimport { useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../store';\n\nconst requestIdleCallback = ( () => {\n\tif ( typeof window === 'undefined' ) {\n\t\treturn ( callback ) => {\n\t\t\tsetTimeout( () => callback( Date.now() ), 0 );\n\t\t};\n\t}\n\n\treturn window.requestIdleCallback || window.requestAnimationFrame;\n} )();\n\nconst cancelIdleCallback = ( () => {\n\tif ( typeof window === 'undefined' ) {\n\t\treturn clearTimeout;\n\t}\n\n\treturn window.cancelIdleCallback || window.cancelAnimationFrame;\n} )();\n\nexport function usePreParsePatterns() {\n\tconst { patterns, isPreviewMode } = useSelect( ( _select ) => {\n\t\tconst { __experimentalBlockPatterns, __unstableIsPreviewMode } =\n\t\t\t_select( blockEditorStore ).getSettings();\n\t\treturn {\n\t\t\tpatterns: __experimentalBlockPatterns,\n\t\t\tisPreviewMode: __unstableIsPreviewMode,\n\t\t};\n\t}, [] );\n\n\tuseEffect( () => {\n\t\tif ( isPreviewMode ) {\n\t\t\treturn;\n\t\t}\n\t\tif ( ! patterns?.length ) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet handle;\n\t\tlet index = -1;\n\n\t\tconst callback = () => {\n\t\t\tindex++;\n\t\t\tif ( index >= patterns.length ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tselect( blockEditorStore ).__experimentalGetParsedPattern(\n\t\t\t\tpatterns[ index ].name\n\t\t\t);\n\n\t\t\thandle = requestIdleCallback( callback );\n\t\t};\n\n\t\thandle = requestIdleCallback( callback );\n\t\treturn () => cancelIdleCallback( handle );\n\t}, [ patterns, isPreviewMode ] );\n\n\treturn null;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,MAAM,QAAQ,iBAAiB;AACnD,SAASC,SAAS,QAAQ,oBAAoB;;AAE9C;AACA;AACA;AACA,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,UAAU;AAEpD,MAAMC,mBAAmB,GAAG,CAAE,MAAM;EACnC,IAAK,OAAOC,MAAM,KAAK,WAAW,EAAG;IACpC,OAASC,QAAQ,IAAM;MACtBC,UAAU,CAAE,MAAMD,QAAQ,CAAEE,IAAI,CAACC,GAAG,CAAC,CAAE,CAAC,EAAE,CAAE,CAAC;IAC9C,CAAC;EACF;EAEA,OAAOJ,MAAM,CAACD,mBAAmB,IAAIC,MAAM,CAACK,qBAAqB;AAClE,CAAC,EAAG,CAAC;AAEL,MAAMC,kBAAkB,GAAG,CAAE,MAAM;EAClC,IAAK,OAAON,MAAM,KAAK,WAAW,EAAG;IACpC,OAAOO,YAAY;EACpB;EAEA,OAAOP,MAAM,CAACM,kBAAkB,IAAIN,MAAM,CAACQ,oBAAoB;AAChE,CAAC,EAAG,CAAC;AAEL,OAAO,SAASC,mBAAmBA,CAAA,EAAG;EACrC,MAAM;IAAEC,QAAQ;IAAEC;EAAc,CAAC,GAAGjB,SAAS,CAAIkB,OAAO,IAAM;IAC7D,MAAM;MAAEC,2BAA2B;MAAEC;IAAwB,CAAC,GAC7DF,OAAO,CAAEd,gBAAiB,CAAC,CAACiB,WAAW,CAAC,CAAC;IAC1C,OAAO;MACNL,QAAQ,EAAEG,2BAA2B;MACrCF,aAAa,EAAEG;IAChB,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;EAEPlB,SAAS,CAAE,MAAM;IAChB,IAAKe,aAAa,EAAG;MACpB;IACD;IACA,IAAK,CAAED,QAAQ,EAAEM,MAAM,EAAG;MACzB;IACD;IAEA,IAAIC,MAAM;IACV,IAAIC,KAAK,GAAG,CAAC,CAAC;IAEd,MAAMjB,QAAQ,GAAGA,CAAA,KAAM;MACtBiB,KAAK,EAAE;MACP,IAAKA,KAAK,IAAIR,QAAQ,CAACM,MAAM,EAAG;QAC/B;MACD;MAEArB,MAAM,CAAEG,gBAAiB,CAAC,CAACqB,8BAA8B,CACxDT,QAAQ,CAAEQ,KAAK,CAAE,CAACE,IACnB,CAAC;MAEDH,MAAM,GAAGlB,mBAAmB,CAAEE,QAAS,CAAC;IACzC,CAAC;IAEDgB,MAAM,GAAGlB,mBAAmB,CAAEE,QAAS,CAAC;IACxC,OAAO,MAAMK,kBAAkB,CAAEW,MAAO,CAAC;EAC1C,CAAC,EAAE,CAAEP,QAAQ,EAAEC,aAAa,CAAG,CAAC;EAEhC,OAAO,IAAI;AACZ"}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`URLPopover matches the snapshot in its default state 1`] = `
|
|
4
|
-
<div>
|
|
5
|
-
<span>
|
|
6
|
-
<div
|
|
7
|
-
class="components-popover block-editor-url-popover is-positioned"
|
|
8
|
-
style="position: absolute; top: 0px; left: 0px; transform: none;"
|
|
9
|
-
tabindex="-1"
|
|
10
|
-
>
|
|
11
|
-
<div
|
|
12
|
-
class="components-popover__content"
|
|
13
|
-
style="max-height: 0px; overflow: auto;"
|
|
14
|
-
>
|
|
15
|
-
<div
|
|
16
|
-
class="block-editor-url-popover__input-container"
|
|
17
|
-
>
|
|
18
|
-
<div
|
|
19
|
-
class="block-editor-url-popover__row"
|
|
20
|
-
>
|
|
21
|
-
<div>
|
|
22
|
-
Editor
|
|
23
|
-
</div>
|
|
24
|
-
<button
|
|
25
|
-
aria-expanded="false"
|
|
26
|
-
aria-label="Link settings"
|
|
27
|
-
class="components-button block-editor-url-popover__settings-toggle has-icon"
|
|
28
|
-
type="button"
|
|
29
|
-
>
|
|
30
|
-
<svg
|
|
31
|
-
aria-hidden="true"
|
|
32
|
-
focusable="false"
|
|
33
|
-
height="24"
|
|
34
|
-
viewBox="0 0 24 24"
|
|
35
|
-
width="24"
|
|
36
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
37
|
-
>
|
|
38
|
-
<path
|
|
39
|
-
d="M17.5 11.6L12 16l-5.5-4.4.9-1.2L12 14l4.5-3.6 1 1.2z"
|
|
40
|
-
/>
|
|
41
|
-
</svg>
|
|
42
|
-
</button>
|
|
43
|
-
</div>
|
|
44
|
-
</div>
|
|
45
|
-
</div>
|
|
46
|
-
</div>
|
|
47
|
-
</span>
|
|
48
|
-
</div>
|
|
49
|
-
`;
|
|
50
|
-
|
|
51
|
-
exports[`URLPopover matches the snapshot when the settings are toggled open 1`] = `
|
|
52
|
-
<div>
|
|
53
|
-
<span>
|
|
54
|
-
<div
|
|
55
|
-
class="components-popover block-editor-url-popover is-positioned"
|
|
56
|
-
style="position: absolute; top: 0px; left: 0px; transform: none;"
|
|
57
|
-
tabindex="-1"
|
|
58
|
-
>
|
|
59
|
-
<div
|
|
60
|
-
class="components-popover__content"
|
|
61
|
-
style="max-height: 0px; overflow: auto;"
|
|
62
|
-
>
|
|
63
|
-
<div
|
|
64
|
-
class="block-editor-url-popover__input-container"
|
|
65
|
-
>
|
|
66
|
-
<div
|
|
67
|
-
class="block-editor-url-popover__row"
|
|
68
|
-
>
|
|
69
|
-
<div>
|
|
70
|
-
Editor
|
|
71
|
-
</div>
|
|
72
|
-
<button
|
|
73
|
-
aria-expanded="true"
|
|
74
|
-
aria-label="Link settings"
|
|
75
|
-
class="components-button block-editor-url-popover__settings-toggle has-icon"
|
|
76
|
-
type="button"
|
|
77
|
-
>
|
|
78
|
-
<svg
|
|
79
|
-
aria-hidden="true"
|
|
80
|
-
focusable="false"
|
|
81
|
-
height="24"
|
|
82
|
-
viewBox="0 0 24 24"
|
|
83
|
-
width="24"
|
|
84
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
85
|
-
>
|
|
86
|
-
<path
|
|
87
|
-
d="M17.5 11.6L12 16l-5.5-4.4.9-1.2L12 14l4.5-3.6 1 1.2z"
|
|
88
|
-
/>
|
|
89
|
-
</svg>
|
|
90
|
-
</button>
|
|
91
|
-
</div>
|
|
92
|
-
<div
|
|
93
|
-
class="block-editor-url-popover__row block-editor-url-popover__settings"
|
|
94
|
-
>
|
|
95
|
-
<div>
|
|
96
|
-
Settings
|
|
97
|
-
</div>
|
|
98
|
-
</div>
|
|
99
|
-
</div>
|
|
100
|
-
</div>
|
|
101
|
-
</div>
|
|
102
|
-
</span>
|
|
103
|
-
</div>
|
|
104
|
-
`;
|
|
105
|
-
|
|
106
|
-
exports[`URLPopover matches the snapshot when there are no settings 1`] = `
|
|
107
|
-
<div>
|
|
108
|
-
<span>
|
|
109
|
-
<div
|
|
110
|
-
class="components-popover block-editor-url-popover is-positioned"
|
|
111
|
-
style="position: absolute; top: 0px; left: 0px; transform: none;"
|
|
112
|
-
tabindex="-1"
|
|
113
|
-
>
|
|
114
|
-
<div
|
|
115
|
-
class="components-popover__content"
|
|
116
|
-
style="max-height: 0px; overflow: auto;"
|
|
117
|
-
>
|
|
118
|
-
<div
|
|
119
|
-
class="block-editor-url-popover__input-container"
|
|
120
|
-
>
|
|
121
|
-
<div
|
|
122
|
-
class="block-editor-url-popover__row"
|
|
123
|
-
>
|
|
124
|
-
<div>
|
|
125
|
-
Editor
|
|
126
|
-
</div>
|
|
127
|
-
</div>
|
|
128
|
-
</div>
|
|
129
|
-
</div>
|
|
130
|
-
</div>
|
|
131
|
-
</span>
|
|
132
|
-
</div>
|
|
133
|
-
`;
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { render, screen, waitFor } from '@testing-library/react';
|
|
5
|
-
import userEvent from '@testing-library/user-event';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Internal dependencies
|
|
9
|
-
*/
|
|
10
|
-
import URLPopover from '../';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Returns the first found popover element up the DOM tree.
|
|
14
|
-
*
|
|
15
|
-
* @param {HTMLElement} element Element to start with.
|
|
16
|
-
* @return {HTMLElement|null} Popover element, or `null` if not found.
|
|
17
|
-
*/
|
|
18
|
-
function getWrappingPopoverElement( element ) {
|
|
19
|
-
return element.closest( '.components-popover' );
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
describe( 'URLPopover', () => {
|
|
23
|
-
it( 'matches the snapshot in its default state', async () => {
|
|
24
|
-
const { container } = render(
|
|
25
|
-
<URLPopover
|
|
26
|
-
animate={ false }
|
|
27
|
-
renderSettings={ () => <div>Settings</div> }
|
|
28
|
-
>
|
|
29
|
-
<div>Editor</div>
|
|
30
|
-
</URLPopover>
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
await waitFor( () =>
|
|
34
|
-
expect(
|
|
35
|
-
getWrappingPopoverElement( screen.getByText( 'Editor' ) )
|
|
36
|
-
).toBePositionedPopover()
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
expect( container ).toMatchSnapshot();
|
|
40
|
-
} );
|
|
41
|
-
|
|
42
|
-
it( 'matches the snapshot when the settings are toggled open', async () => {
|
|
43
|
-
const user = userEvent.setup();
|
|
44
|
-
const { container } = render(
|
|
45
|
-
<URLPopover
|
|
46
|
-
animate={ false }
|
|
47
|
-
renderSettings={ () => <div>Settings</div> }
|
|
48
|
-
>
|
|
49
|
-
<div>Editor</div>
|
|
50
|
-
</URLPopover>
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
await user.click(
|
|
54
|
-
screen.getByRole( 'button', { name: 'Link settings' } )
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
expect( container ).toMatchSnapshot();
|
|
58
|
-
} );
|
|
59
|
-
|
|
60
|
-
it( 'matches the snapshot when there are no settings', async () => {
|
|
61
|
-
const { container } = render(
|
|
62
|
-
<URLPopover animate={ false }>
|
|
63
|
-
<div>Editor</div>
|
|
64
|
-
</URLPopover>
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
await waitFor( () =>
|
|
68
|
-
expect(
|
|
69
|
-
getWrappingPopoverElement( screen.getByText( 'Editor' ) )
|
|
70
|
-
).toBePositionedPopover()
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
expect( container ).toMatchSnapshot();
|
|
74
|
-
} );
|
|
75
|
-
} );
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { useSelect, select } from '@wordpress/data';
|
|
5
|
-
import { useEffect } from '@wordpress/element';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Internal dependencies
|
|
9
|
-
*/
|
|
10
|
-
import { store as blockEditorStore } from '../store';
|
|
11
|
-
|
|
12
|
-
const requestIdleCallback = ( () => {
|
|
13
|
-
if ( typeof window === 'undefined' ) {
|
|
14
|
-
return ( callback ) => {
|
|
15
|
-
setTimeout( () => callback( Date.now() ), 0 );
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return window.requestIdleCallback || window.requestAnimationFrame;
|
|
20
|
-
} )();
|
|
21
|
-
|
|
22
|
-
const cancelIdleCallback = ( () => {
|
|
23
|
-
if ( typeof window === 'undefined' ) {
|
|
24
|
-
return clearTimeout;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return window.cancelIdleCallback || window.cancelAnimationFrame;
|
|
28
|
-
} )();
|
|
29
|
-
|
|
30
|
-
export function usePreParsePatterns() {
|
|
31
|
-
const { patterns, isPreviewMode } = useSelect( ( _select ) => {
|
|
32
|
-
const { __experimentalBlockPatterns, __unstableIsPreviewMode } =
|
|
33
|
-
_select( blockEditorStore ).getSettings();
|
|
34
|
-
return {
|
|
35
|
-
patterns: __experimentalBlockPatterns,
|
|
36
|
-
isPreviewMode: __unstableIsPreviewMode,
|
|
37
|
-
};
|
|
38
|
-
}, [] );
|
|
39
|
-
|
|
40
|
-
useEffect( () => {
|
|
41
|
-
if ( isPreviewMode ) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
if ( ! patterns?.length ) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
let handle;
|
|
49
|
-
let index = -1;
|
|
50
|
-
|
|
51
|
-
const callback = () => {
|
|
52
|
-
index++;
|
|
53
|
-
if ( index >= patterns.length ) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
select( blockEditorStore ).__experimentalGetParsedPattern(
|
|
58
|
-
patterns[ index ].name
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
handle = requestIdleCallback( callback );
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
handle = requestIdleCallback( callback );
|
|
65
|
-
return () => cancelIdleCallback( handle );
|
|
66
|
-
}, [ patterns, isPreviewMode ] );
|
|
67
|
-
|
|
68
|
-
return null;
|
|
69
|
-
}
|