How to use the @wordpress/data.select function in @wordpress/data

To help you get started, we’ve selected a few @wordpress/data examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / wordpress__block-editor / wordpress__block-editor-tests.tsx View on Github external
dispatch('core/block-editor').updateBlockAttributes('foo', { foo: 'bar' });

// $ExpectType void
dispatch('core/block-editor').updateBlockListSettings('foo', { allowedBlocks: ['core/paragraph'] });

// $ExpectType void
dispatch('core/block-editor').updateSettings({
    focusMode: true,
    codeEditingEnabled: false,
    maxUploadFileSize: 500,
    richEditingEnabled: false,
});

// $ExpectType boolean
select('core/block-editor').canInsertBlockType('core/paragraph');
select('core/block-editor').canInsertBlockType('core/paragraph', 'foo');

// $ExpectType string | null
select('core/block-editor').getAdjacentBlockClientId();
select('core/block-editor').getAdjacentBlockClientId('foo');
select('core/block-editor').getAdjacentBlockClientId('foo', -1);
select('core/block-editor').getAdjacentBlockClientId('foo', 1);
github jmau111 / jm-twitter-cards / admin / js / cards / components / image / index.js View on Github external
function theImageUrl(props) {

    let fallback = props.meta.cardImage || tcData.defaultImage;
    const {getPostType} = select('core');
    let postTypeCheck = getPostType(select('core/editor').getEditedPostAttribute('type'));// no use if no support for thumbnail

    if (!postTypeCheck || !postTypeCheck.supports['thumbnail']) {
        return fallback;
    }
    let featuredImageId = select('core/editor').getEditedPostAttribute('featured_media');

    if (featuredImageId === 0) {
        return fallback;
    }

    let media = select('core').getMedia(featuredImageId);

    if (typeof(media) !== 'undefined') {
        return props.meta.cardImage || media.source_url;
    }

    return fallback;

}
github moderntribe / events-gutenberg / src / modules / data / organizers / reducers.js View on Github external
} ).then( ( body ) => {
		// Prevent responses from old searches to be stored.
		const current = select( STORE_NAME ).getSearch( id );
		if ( current.trim() !== search.trim() ) {
			return;
		}

		store.dispatch( {
			type: 'SET_RESULTS',
			id,
			payload: {
				results: body,
				search,
			},
		} );
	} );
github gambitph / Stackable / src / block / columns / edit.js View on Github external
// Only do this when there's a change in column number.
	if ( typeof attributes.columns !== 'undefined' ) {
		if ( attributes.columns !== blockProps.attributes.columns ) {
			columns = attributes.columns
		}
	}

	// Only do this when there's a change in the design.
	if ( typeof attributes.design !== 'undefined' ) {
		if ( blockProps.attributes.design === 'grid' && attributes.design !== 'grid' && blockProps.attributes.columns > 6 ) {
			columns = 6
		}
	}

	// Form the new innerBlock list.
	const currentInnerBlocks = select( 'core/block-editor' ).getBlock( blockProps.clientId ).innerBlocks
	const newInnerBlocks = range( columns || 2 ).map( i => {
		return currentInnerBlocks[ i ] || createBlock( 'ugb/column', {}, [] )
	} )

	// Replace the current list of inner blocks.
	dispatch( 'core/block-editor' ).replaceInnerBlocks( blockProps.clientId, newInnerBlocks, false )

	return attributes
} )
github WordPress / gutenberg / packages / rich-text / src / register-format-type.js View on Github external
if ( typeof settings.name !== 'string' ) {
		window.console.error(
			'Format names must be strings.'
		);
		return;
	}

	if ( ! /^[a-z][a-z0-9-]*\/[a-z][a-z0-9-]*$/.test( settings.name ) ) {
		window.console.error(
			'Format names must contain a namespace prefix, include only lowercase alphanumeric characters or dashes, and start with a letter. Example: my-plugin/my-custom-format'
		);
		return;
	}

	if ( select( 'core/rich-text' ).getFormatType( settings.name ) ) {
		window.console.error(
			'Format "' + settings.name + '" is already registered.'
		);
		return;
	}

	if (
		typeof settings.tagName !== 'string' ||
		settings.tagName === ''
	) {
		window.console.error(
			'Format tag names must be a string.'
		);
		return;
	}
github WordPress / gutenberg / packages / blocks / src / api / registration.js View on Github external
export function getDefaultBlockName() {
	return select( 'core/blocks' ).getDefaultBlockName();
}
github moderntribe / events-gutenberg / plugins / tickets / src / modules / blocks / rsvp / header-image / container.js View on Github external
const mapDispatchToProps = ( dispatch ) => {
	const postId = select( 'core/editor' ).getCurrentPostId();
	return {
		onRemove: () => dispatch( thunks.deleteRSVPHeaderImage( ownPrs.postId ) ),
		/**
		 * Full payload from gutenberg media upload is not used,
		 * only id, alt, and medium src are used for this specific case.
		 */
		onSelect: ( image ) => dispatch(
			thunks.updateRSVPHeaderImage( postId, image )
		),
	};
};
github ampproject / amp-wp / assets / src / components / get-featured-image-message.js View on Github external
export default ( validateImageSize, invalidSizeMessage ) => {
	const currentPost = select( 'core/editor' ).getCurrentPost();
	const editedFeaturedMedia = select( 'core/editor' ).getEditedPostAttribute( 'featured_media' );
	const featuredMedia = currentPost.featured_media || editedFeaturedMedia;

	if ( ! featuredMedia ) {
		return __( 'Selecting a featured image is required.', 'amp' );
	}

	const media = select( 'core' ).getMedia( featuredMedia );
	if ( ! media || ! media.media_details || ! validateImageSize( media.media_details ) ) {
		return invalidSizeMessage;
	}
};
github LearnPress / learnpress / assets / src / js / frontend / quiz / store / selectors.js View on Github external
export function getItemStatus( state, itemId ) {
	const item = select( 'course-learner/user' ).getItemById( itemId );
	return item ? get( item, 'userSettings.status' ) : '';
}