Skip to content

Commit

Permalink
Merge branch 'trunk' into rnmobile/demo-app-with-hermes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerardo committed Sep 27, 2023
2 parents c577cfe + 66903ed commit edc6d8e
Show file tree
Hide file tree
Showing 22 changed files with 172 additions and 156 deletions.
4 changes: 2 additions & 2 deletions docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ Add a link to a downloadable file. ([Source](https://github.com/WordPress/gutenb

## Footnotes

([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/footnotes))
Display footnotes added to the page. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/footnotes))

- **Name:** core/footnotes
- **Category:** text
Expand Down Expand Up @@ -384,7 +384,7 @@ Show login & logout links. ([Source](https://github.com/WordPress/gutenberg/tree

- **Name:** core/loginout
- **Category:** theme
- **Supports:** className, typography (fontSize, lineHeight)
- **Supports:** className, spacing (margin, padding), typography (fontSize, lineHeight)
- **Attributes:** displayLoginAsForm, redirectToCurrent

## Media & Text
Expand Down
2 changes: 1 addition & 1 deletion lib/block-supports/background.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function gutenberg_register_background_support( $block_type ) {
*/
function gutenberg_render_background_support( $block_content, $block ) {
$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
$block_attributes = $block['attrs'];
$block_attributes = ( isset( $block['attrs'] ) && is_array( $block['attrs'] ) ) ? $block['attrs'] : array();
$has_background_image_support = block_has_support( $block_type, array( 'background', 'backgroundImage' ), false );

if (
Expand Down
98 changes: 0 additions & 98 deletions lib/compat/wordpress-6.3/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,101 +12,3 @@
*/
remove_action( 'wp_body_open', 'wp_global_styles_render_svg_filters' );
remove_action( 'in_admin_header', 'wp_global_styles_render_svg_filters' );

/**
* Collect the block editor assets that need to be loaded into the editor's iframe.
*
* @since 6.0.0
* @access private
*
* @return array {
* The block editor assets.
*
* @type string|false $styles String containing the HTML for styles.
* @type string|false $scripts String containing the HTML for scripts.
* }
*/
function _gutenberg_get_iframed_editor_assets() {
global $wp_styles, $wp_scripts, $pagenow;

// Keep track of the styles and scripts instance to restore later.
$current_wp_styles = $wp_styles;
$current_wp_scripts = $wp_scripts;

// Create new instances to collect the assets.
$wp_styles = new WP_Styles();
$wp_scripts = new WP_Scripts();

// Register all currently registered styles and scripts. The actions that
// follow enqueue assets, but don't necessarily register them.
$wp_styles->registered = $current_wp_styles->registered;
$wp_scripts->registered = $current_wp_scripts->registered;

// We generally do not need reset styles for the iframed editor.
// However, if it's a classic theme, margins will be added to every block,
// which is reset specifically for list items, so classic themes rely on
// these reset styles.
$wp_styles->done =
wp_theme_has_theme_json() ? array( 'wp-reset-editor-styles' ) : array();

wp_enqueue_script( 'wp-polyfill' );
// Enqueue the `editorStyle` handles for all core block, and dependencies.
wp_enqueue_style( 'wp-edit-blocks' );

if ( 'site-editor.php' === $pagenow ) {
wp_enqueue_style( 'wp-edit-site' );
}

if ( current_theme_supports( 'wp-block-styles' ) ) {
wp_enqueue_style( 'wp-block-library-theme' );
}

// We don't want to load EDITOR scripts in the iframe, only enqueue
// front-end assets for the content.
add_filter( 'should_load_block_editor_scripts_and_styles', '__return_false' );
do_action( 'enqueue_block_assets' );
remove_filter( 'should_load_block_editor_scripts_and_styles', '__return_false' );

$block_registry = WP_Block_Type_Registry::get_instance();

// Additionally, do enqueue `editorStyle` assets for all blocks, which
// contains editor-only styling for blocks (editor content).
foreach ( $block_registry->get_all_registered() as $block_type ) {
if ( isset( $block_type->editor_style_handles ) && is_array( $block_type->editor_style_handles ) ) {
foreach ( $block_type->editor_style_handles as $style_handle ) {
wp_enqueue_style( $style_handle );
}
}
}

// Remove the deprecated `print_emoji_styles` handler.
// It avoids breaking style generation with a deprecation message.
remove_action( 'wp_print_styles', 'print_emoji_styles' );
ob_start();
wp_print_styles();
$styles = ob_get_clean();
add_action( 'wp_print_styles', 'print_emoji_styles' );

ob_start();
wp_print_head_scripts();
wp_print_footer_scripts();
$scripts = ob_get_clean();

// Restore the original instances.
$wp_styles = $current_wp_styles;
$wp_scripts = $current_wp_scripts;

return array(
'styles' => $styles,
'scripts' => $scripts,
);
}

add_filter(
'block_editor_settings_all',
static function ( $settings ) {
// We must override what core is passing now.
$settings['__unstableResolvedAssets'] = _gutenberg_get_iframed_editor_assets();
return $settings;
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function get_config() {
*/
public function get_data() {
// If the src is a URL, fetch the data from the URL.
if ( false !== strpos( $this->config['src'], 'http' ) && false !== strpos( $this->config['src'], '://' ) ) {
if ( str_contains( $this->config['src'], 'http' ) && str_contains( $this->config['src'], '://' ) ) {
if ( ! wp_http_validate_url( $this->config['src'] ) ) {
return new WP_Error( 'font_collection_read_error', __( 'Invalid URL for Font Collection data.', 'gutenberg' ) );
}
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/footnotes/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "core/footnotes",
"title": "Footnotes",
"category": "text",
"description": "",
"description": "Display footnotes added to the page.",
"keywords": [ "references" ],
"textdomain": "default",
"usesContext": [ "postId", "postType" ],
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/footnotes/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ function _wp_rest_api_autosave_meta( $autosave ) {
return;
}

update_post_meta( $id, 'footnotes', wp_slash( $body['meta']['footnotes'] ) );
// Can't use update_post_meta() because it doesn't allow revisions.
update_metadata( 'post', $id, 'footnotes', wp_slash( $body['meta']['footnotes'] ) );
}
// See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L391C1-L391C1.
add_action( 'wp_creating_autosave', '_wp_rest_api_autosave_meta' );
Expand Down
8 changes: 8 additions & 0 deletions packages/block-library/src/loginout/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
},
"supports": {
"className": true,
"spacing": {
"margin": true,
"padding": true,
"__experimentalDefaultControls": {
"margin": false,
"padding": false
}
},
"typography": {
"fontSize": true,
"lineHeight": true,
Expand Down
9 changes: 5 additions & 4 deletions packages/block-library/src/search/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ $button-spacing-y: math.div($grid-unit-15, 2); // 6px
margin-left: 0;
// Prevent unintended text wrapping.
flex-shrink: 0;
// Ensure minimum input field width in small viewports.
max-width: 100%;
}

// Ensure minimum input field width in small viewports.
.wp-block-search__button[aria-expanded="true"] {
max-width: calc(100% - 100px);
&.has-icon {
max-width: 100%;
}
}
}

Expand Down
28 changes: 26 additions & 2 deletions packages/block-library/src/table-of-contents/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
import { useDispatch, useSelect } from '@wordpress/data';
import { renderToString } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { useInstanceId } from '@wordpress/compose';
import { store as noticeStore } from '@wordpress/notices';

/**
* Internal dependencies
Expand Down Expand Up @@ -50,6 +52,24 @@ export default function TableOfContentsEdit( {
useObserveHeadings( clientId );

const blockProps = useBlockProps();
const instanceId = useInstanceId(
TableOfContentsEdit,
'table-of-contents'
);

// If a user clicks to a link prevent redirection and show a warning.
const { createWarningNotice, removeNotice } = useDispatch( noticeStore );
let noticeId;
const showRedirectionPreventedNotice = ( event ) => {
event.preventDefault();
// Remove previous warning if any, to show one at a time per block.
removeNotice( noticeId );
noticeId = `block-library/core/table-of-contents/redirection-prevented/${ instanceId }`;
createWarningNotice( __( 'Links are disabled in the editor.' ), {
id: noticeId,
type: 'snackbar',
} );
};

const canInsertList = useSelect(
( select ) => {
Expand Down Expand Up @@ -137,8 +157,12 @@ export default function TableOfContentsEdit( {
return (
<>
<nav { ...blockProps }>
<ol inert="true">
<TableOfContentsList nestedHeadingList={ headingTree } />
<ol>
<TableOfContentsList
nestedHeadingList={ headingTree }
disableLinkActivation={ true }
onClick={ showRedirectionPreventedNotice }
/>
</ol>
</nav>
{ toolbarControls }
Expand Down
30 changes: 29 additions & 1 deletion packages/block-library/src/table-of-contents/list.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import type { MouseEvent } from 'react';

/**
* WordPress dependencies
*/
Expand All @@ -12,16 +17,30 @@ const ENTRY_CLASS_NAME = 'wp-block-table-of-contents__entry';

export default function TableOfContentsList( {
nestedHeadingList,
disableLinkActivation,
onClick,
}: {
nestedHeadingList: NestedHeadingData[];
disableLinkActivation?: boolean;
onClick?: ( event: MouseEvent< HTMLAnchorElement > ) => void;
} ): WPElement {
return (
<>
{ nestedHeadingList.map( ( node, index ) => {
const { content, link } = node.heading;

const entry = link ? (
<a className={ ENTRY_CLASS_NAME } href={ link }>
<a
className={ ENTRY_CLASS_NAME }
href={ link }
aria-disabled={ disableLinkActivation || undefined }
onClick={
disableLinkActivation &&
'function' === typeof onClick
? onClick
: undefined
}
>
{ content }
</a>
) : (
Expand All @@ -35,6 +54,15 @@ export default function TableOfContentsList( {
<ol>
<TableOfContentsList
nestedHeadingList={ node.children }
disableLinkActivation={
disableLinkActivation
}
onClick={
disableLinkActivation &&
'function' === typeof onClick
? onClick
: undefined
}
/>
</ol>
) : null }
Expand Down
9 changes: 2 additions & 7 deletions packages/components/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,12 @@ Many components include CSS to add styles, which you will need to load in order

In non-WordPress projects, link to the `build-style/style.css` file directly, it is located at `node_modules/@wordpress/components/build-style/style.css`.

### Popovers and Tooltips

_If you're using [`Popover`](/packages/components/src/popover/README.md) or [`Tooltip`](/packages/components/src/tooltip/README.md) components outside of the editor, make sure they are rendered within a `SlotFillProvider` and with a `Popover.Slot` somewhere up the element tree._
### Popovers

By default, the `Popover` component will render within an extra element appended to the body of the document.

If you want to precisely contol where the popovers render, you will need to use the `Popover.Slot` component.

A `Popover` is also used as the underlying mechanism to display `Tooltip` components.
So the same considerations should be applied to them.

The following example illustrates how you can wrap a component using a
`Popover` and have those popovers render to a single location in the DOM.

Expand All @@ -58,7 +53,7 @@ const Example = () => {
<SlotFillProvider>
<MyComponentWithPopover />
<Popover.Slot />
</SlotFillProvider>
</SlotFillProvider>;
};
```

Expand Down
15 changes: 14 additions & 1 deletion packages/core-commands/src/site-editor-navigation-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { useIsTemplatesAccessible, useIsBlockBasedTheme } from './hooks';
import { unlock } from './lock-unlock';
import { orderEntityRecordsBySearch } from './utils/order-entity-records-by-search';

const { useHistory } = unlock( routerPrivateApis );
const { useHistory, useLocation } = unlock( routerPrivateApis );

const icons = {
post,
Expand Down Expand Up @@ -136,6 +136,14 @@ const getNavigationCommandLoaderPerPostType = ( postType ) =>
const getNavigationCommandLoaderPerTemplate = ( templateType ) =>
function useNavigationCommandLoader( { search } ) {
const history = useHistory();
const location = useLocation();

const isPatternsPage =
location?.params?.path === '/patterns' ||
location?.params?.postType === 'wp_block';
const didAccessPatternsPage =
!! location?.params?.didAccessPatternsPage;

const isBlockBasedTheme = useIsBlockBasedTheme();
const { records, isLoading } = useSelect( ( select ) => {
const { getEntityRecords } = select( coreStore );
Expand Down Expand Up @@ -184,6 +192,11 @@ const getNavigationCommandLoaderPerTemplate = ( templateType ) =>
const args = {
postType: templateType,
postId: record.id,
didAccessPatternsPage:
! isBlockBasedTheme &&
( isPatternsPage || didAccessPatternsPage )
? 1
: undefined,
...extraArgs,
};
const targetUrl = addQueryArgs(
Expand Down
Loading

0 comments on commit edc6d8e

Please sign in to comment.