-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.js
66 lines (55 loc) · 1.71 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* WordPress dependencies
*/
import { __, sprintf } from '@wordpress/i18n';
import { search as icon } from '@wordpress/icons';
import { select } from '@wordpress/data';
import { store as blockEditorStore } from '@wordpress/block-editor';
/**
* Internal dependencies
*/
import initBlock from '../utils/init-block';
import metadata from './block.json';
import edit from './edit';
import variations from './variations';
const { name } = metadata;
export { metadata, name };
export const settings = {
icon,
__experimentalLabel( attributes, { clientId } ) {
const { label } = attributes;
const customName = attributes?.metadata?.name;
// Check if the block is inside a Query Loop block.
const queryLoopBlockIds = select(
blockEditorStore
).getBlockParentsByBlockName( clientId, 'core/query' );
// If the block is not inside a Query Loop block, return the block label.
if ( ! queryLoopBlockIds.length ) {
return customName || label;
}
const queryLoopBlock = select( blockEditorStore ).getBlock(
queryLoopBlockIds[ 0 ]
);
// Check if the Query Loop block has enhanced pagination enabled and
// if the `__experimentalEnableSearchQueryBlock` flag is enabled.
const hasInstantSearch = !! (
queryLoopBlock?.attributes?.enhancedPagination &&
window?.__experimentalEnableSearchQueryBlock
);
if ( ! hasInstantSearch ) {
return customName || label;
}
return sprintf(
/* translators: %s: The block label */
__( '%s (Instant search enabled)' ),
customName || label || 'Search'
);
},
example: {
attributes: { buttonText: __( 'Search' ), label: __( 'Search' ) },
viewportWidth: 400,
},
variations,
edit,
};
export const init = () => initBlock( { name, metadata, settings } );