How to use the @wordpress/element.compose function in @wordpress/element

To help you get started, we’ve selected a few @wordpress/element 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 WordPress / gutenberg / editor / components / block-drop-zone / index.js View on Github external
const isAppender = index === undefined;

		return (
			
		);
	}
}

export default compose(
	withDispatch( ( dispatch, ownProps ) => {
		const {
			insertBlocks,
			updateBlockAttributes,
			moveBlockToPosition,
		} = dispatch( 'core/editor' );

		return {
			insertBlocks( blocks, insertIndex ) {
				const { rootUID, layout } = ownProps;

				if ( layout ) {
					// A block's transform function may return a single
					// transformed block or an array of blocks, so ensure
					// to first coerce to an array before mapping to inject
					// the layout attribute.
github WordPress / gutenberg / editor / components / block-mover / index.js View on Github external
* managing block movement.
 *
 * @param {string}   type     Action type to dispatch.
 * @param {Function} dispatch Store dispatch.
 * @param {Object}   ownProps The wrapped component's own props.
 *
 * @return {Function} Prop dispatcher callback.
 */
function createOnMove( type, dispatch, ownProps ) {
	return () => {
		const { uids, rootUID } = ownProps;
		dispatch( { type, uids, rootUID } );
	};
}

export default compose(
	connect(
		( state, ownProps ) => {
			const { uids, rootUID } = ownProps;
			const block = getBlock( state, first( uids ) );

			return ( {
				firstIndex: getBlockIndex( state, first( uids ), rootUID ),
				blockType: block ? getBlockType( block.name ) : null,
			} );
		},
		( ...args ) => ( {
			onMoveDown: createOnMove( 'MOVE_BLOCKS_DOWN', ...args ),
			onMoveUp: createOnMove( 'MOVE_BLOCKS_UP', ...args ),
		} )
	),
	withContext( 'editor' )( ( settings ) => {
github WordPress / gutenberg / edit-post / components / layout / index.js View on Github external
{ publishSidebarOpened && (
				
			) }
			{ editorSidebarOpened &&  }
			{ pluginSidebarOpened &&  }
			
			
		
	);
}

export default compose(
	withSelect( ( select ) => ( {
		mode: select( 'core/edit-post' ).getEditorMode(),
		editorSidebarOpened: select( 'core/edit-post' ).isEditorSidebarOpened(),
		pluginSidebarOpened: select( 'core/edit-post' ).isPluginSidebarOpened(),
		sidebarName: select( 'core/edit-post' ).getActiveGeneralSidebarName(),
		publishSidebarOpened: select( 'core/edit-post' ).isPublishSidebarOpened(),
		hasFixedToolbar: select( 'core/edit-post' ).isFeatureActive( 'fixedToolbar' ),
		metaBoxes: select( 'core/edit-post' ).getMetaBoxes(),
		hasActiveMetaboxes: select( 'core/edit-post' ).hasMetaBoxes(),
		isSaving: select( 'core/edit-post' ).isSavingMetaBoxes(),
	} ) ),
	withDispatch( ( dispatch ) => ( {
		closePublishSidebar: dispatch( 'core/edit-post' ).closePublishSidebar,
	} ) ),
	navigateRegions
)( Layout );
github WordPress / gutenberg / edit-post / components / sidebar / featured-image / index.js View on Github external
return {
		postType: getPostType( getEditedPostAttribute( 'type' ) ),
		isOpened: isEditorSidebarPanelOpened( PANEL_NAME ),
	};
} );

const applyWithDispatch = withDispatch( ( dispatch ) => {
	const { toggleGeneralSidebarEditorPanel } = dispatch( 'core/edit-post' );

	return {
		onTogglePanel: partial( toggleGeneralSidebarEditorPanel, PANEL_NAME ),
	};
} );

export default compose(
	applyWithSelect,
	applyWithDispatch,
)( FeaturedImage );
github WordPress / gutenberg / editor / components / post-title / index.js View on Github external
} = dispatch( 'core/editor' );

	return {
		onEnterPress() {
			insertDefaultBlock( undefined, undefined, 0 );
		},
		onUpdate( title ) {
			editPost( { title } );
		},
		onUndo: undo,
		onRedo: redo,
		clearSelectedBlock,
	};
} );

export default compose(
	applyWithSelect,
	applyWithDispatch,
	withInstanceId,
	withFocusOutside
)( PostTitle );
github WordPress / gutenberg / editor / components / post-taxonomies / flat-term-selector.js View on Github external
onChange={ this.onChange }
				onInputChange={ this.searchTerms }
				maxSuggestions={ MAX_TERMS_SUGGESTIONS }
				disabled={ loading }
				placeholder={ newTermPlaceholderLabel }
				messages={ {
					added: termAddedLabel,
					removed: termRemovedLabel,
					remove: removeTermLabel,
				} }
			/>
		);
	}
}

export default compose(
	withAPIData( ( props ) => {
		const { slug } = props;
		return {
			taxonomy: `/wp/v2/taxonomies/${ slug }?context=edit`,
		};
	} ),
	withSelect( ( select, ownProps ) => {
		const { getCurrentPost } = select( 'core/editor' );
		return {
			hasCreateAction: get( getCurrentPost(), [ '_links', 'wp:action-create-' + ownProps.restBase ], false ),
			hasAssignAction: get( getCurrentPost(), [ '_links', 'wp:action-assign-' + ownProps.restBase ], false ),
			terms: select( 'core/editor' ).getEditedPostAttribute( ownProps.restBase ),
		};
	} ),
	withDispatch( ( dispatch ) => {
		return {
github WordPress / gutenberg / editor / components / inserter-with-shortcuts / index.js View on Github external
{ itemsWithoutDefaultBlock.map( ( item ) => (
				 onInsert( item ) }
					label={ sprintf( __( 'Add %s' ), item.title ) }
					icon={ (
						
					) }
				/>
			) ) }
		
	);
}

export default compose(
	withEditorSettings( ( settings ) => {
		const { templateLock, allowedBlockTypes } = settings;

		return {
			isLocked: !! templateLock,
			allowedBlockTypes,
		};
	} ),
	withSelect( ( select, { allowedBlockTypes } ) => ( {
		items: select( 'core/editor' ).getFrecentInserterItems( allowedBlockTypes, 4 ),
	} ) ),
	withDispatch( ( dispatch, ownProps ) => {
		const { uid, rootUID, layout } = ownProps;

		return {
			onInsert( { name, initialAttributes } ) {
github WordPress / gutenberg / edit-post / components / sidebar / settings-header / index.js View on Github external
aria-label={ __( 'Document settings' ) }
			>
				{ __( 'Document' ) }
			
			<button aria-label="{">
				{ sprintf( _n( 'Block', '%d Blocks', count ), count ) }
			</button>
		
	);
};

export default compose(
	withSelect( ( select ) =&gt; ( {
		count: select( 'core/editor' ).getSelectedBlockCount(),
	} ) ),
	withDispatch( ( dispatch ) =&gt; {
		const { openGeneralSidebar } = dispatch( 'core/edit-post' );
		const { clearSelectedBlock } = dispatch( 'core/editor' );
		return {
			openDocumentSettings() {
				openGeneralSidebar( 'edit-post/document' );
				clearSelectedBlock();
			},
			openBlockSettings() {
				openGeneralSidebar( 'edit-post/block' );
			},
		};
	} ),
github WordPress / gutenberg / edit-post / components / plugins-panel / index.js View on Github external
<div>
				<h3>{ title }</h3>
				
			</div>
			<div>
				{ render() }
			</div>
		
	);
}

export default compose(
	withSelect( ( select ) =&gt; ( {
		pluginSidebar: getSidebarSettings( select( 'core/edit-post' ).getActiveGeneralSidebarName() ),
	} ) ),
	withDispatch( ( dispatch ) =&gt; ( {
		onClose: dispatch( 'core/edit-post' ).closeGeneralSidebar,
	} ) ),
	withFocusReturn,
)( PluginsPanel );