Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Second round of bugfixes for 6.3 Beta 4 #52493

Merged
merged 31 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
69236dc
Post and Comment Template blocks: Change render_block_context priorit…
ockham Jul 7, 2023
8dc04dd
Footnotes: fix lingering format boundary attr (#52439)
ellatrix Jul 7, 2023
59234d3
Footnotes: Fix incorrect anchor position in Firefox (#52425)
t-hamano Jul 7, 2023
c0e0230
Scope CSS rules for the wp admin reset to js support only. (#52376)
afercia Jul 7, 2023
eb8ef9f
Fix: Patterns & template parts: remove "apply globally" option from b…
carolinan Jul 7, 2023
8b10e6a
make the body of the editor minimmum viewport height so that smaller …
draganescu Jul 7, 2023
3e5bc99
Patterns: Add renaming, duplication, and deletion options (#52270)
aaronrobertshaw Jul 7, 2023
cfcf5ff
Patterns: Update manage pattern links to go to site editor if availab…
aaronrobertshaw Jul 7, 2023
509fcf3
[Patterns] Separate sync status into a filter control (#52303)
kevin940726 Jul 10, 2023
1219af6
Patterns: Add missing decoding entities processing in Patterns and Te…
t-hamano Jul 10, 2023
0d3432f
Fix document title icon appearance (#52424)
jameskoster Jul 10, 2023
80a84f8
Quote block: Add transform to paragraph (#51809)
richtabor Jul 10, 2023
34b374b
remove sidebar group descriptions (#52453)
SaxonF Jul 10, 2023
b8faaa8
Patterns: alternative grid layout to improve keyboard accessibility …
tellthemachines Jul 10, 2023
0fd4e20
add sync tooltip (#52458)
SaxonF Jul 10, 2023
3b9c88d
Patterns: Update section heading levels (#52273)
aaronrobertshaw Jul 5, 2023
78d8766
Ensure that the unsaved title is not persisted when reopening the mod…
t-hamano Jul 10, 2023
730f7f1
Iframe: avoid asset parsing & fix script localisation (#52405)
ellatrix Jul 10, 2023
93a06ed
Update descriptions (#52468)
jameskoster Jul 10, 2023
c98e64d
Footnotes: show in inserter and placehold (#52445)
ellatrix Jul 10, 2023
12db007
Fix: Focus loss on navigation link label editing on Firefox. (#52428)
jorgefilipecosta Jul 10, 2023
f87efd4
Update tooltip (#52465)
jameskoster Jul 10, 2023
223feaa
Refactor, document, and fix image block deprecations (#52081)
ajlende Jun 29, 2023
a1c08a0
Respect custom aspect ratio (#52286)
draganescu Jul 5, 2023
d807093
RichText/Footnotes: make getRichTextValues work with InnerBlocks.Cont…
ellatrix Jul 10, 2023
dd53d7b
Footnotes: save numbering through the entity provider (#52423)
ellatrix Jul 10, 2023
4441db6
Revert "Post editor: Require confirmation before removing Footnotes (…
priethor Jul 11, 2023
cea0a6f
List block: Fix selected type option (#52472)
Jul 11, 2023
967ce9a
Library - make pattern title clickable (#51898)
getdave Jul 11, 2023
9b718a2
remove status icon (#52457)
SaxonF Jul 11, 2023
7f83e9a
Rename block theme activation nonce variable. (#52398)
peterwilsoncc Jul 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ Add a link to a downloadable file. ([Source](https://github.com/WordPress/gutenb

- **Name:** core/footnotes
- **Category:** text
- **Supports:** ~~html~~, ~~inserter~~, ~~multiple~~, ~~reusable~~
- **Supports:** ~~html~~, ~~multiple~~, ~~reusable~~
- **Attributes:**

## Classic
Expand Down
2 changes: 1 addition & 1 deletion lib/compat/wordpress-6.3/theme-previews.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function block_theme_activate_nonce() {
$nonce_handle = 'switch-theme_' . gutenberg_get_theme_preview_path();
?>
<script type="text/javascript">
window.BLOCK_THEME_ACTIVATE_NONCE = '<?php echo wp_create_nonce( $nonce_handle ); ?>';
window.WP_BLOCK_THEME_ACTIVATE_NONCE = '<?php echo wp_create_nonce( $nonce_handle ); ?>';
</script>
<?php
}
Expand Down
63 changes: 16 additions & 47 deletions packages/block-editor/src/components/iframe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
createPortal,
forwardRef,
useMemo,
useReducer,
useEffect,
} from '@wordpress/element';
import { __ } from '@wordpress/i18n';
Expand Down Expand Up @@ -78,29 +77,6 @@ function bubbleEvents( doc ) {
}
}

function useParsedAssets( html ) {
return useMemo( () => {
const doc = document.implementation.createHTMLDocument( '' );
doc.body.innerHTML = html;
return Array.from( doc.body.children );
}, [ html ] );
}

async function loadScript( head, { id, src } ) {
return new Promise( ( resolve, reject ) => {
const script = head.ownerDocument.createElement( 'script' );
script.id = id;
if ( src ) {
script.src = src;
script.onload = () => resolve();
script.onerror = () => reject();
} else {
resolve();
}
head.appendChild( script );
} );
}

function Iframe( {
contentRef,
children,
Expand All @@ -112,21 +88,22 @@ function Iframe( {
forwardedRef: ref,
...props
} ) {
const assets = useSelect(
const { styles = '', scripts = '' } = useSelect(
( select ) =>
select( blockEditorStore ).getSettings().__unstableResolvedAssets,
[]
);
const [ , forceRender ] = useReducer( () => ( {} ) );
const [ iframeDocument, setIframeDocument ] = useState();
const [ bodyClasses, setBodyClasses ] = useState( [] );
const compatStyles = useCompatibilityStyles();
const scripts = useParsedAssets( assets?.scripts );
const clearerRef = useBlockSelectionClearer();
const [ before, writingFlowRef, after ] = useWritingFlow();
const [ contentResizeListener, { height: contentHeight } ] =
useResizeObserver();
const setRef = useRefEffect( ( node ) => {
node._load = () => {
setIframeDocument( node.contentDocument );
};
let iFrameDocument;
// Prevent the default browser action for files dropped outside of dropzones.
function preventFileDropDefault( event ) {
Expand All @@ -138,7 +115,6 @@ function Iframe( {
iFrameDocument = contentDocument;

bubbleEvents( contentDocument );
setIframeDocument( contentDocument );
clearerRef( documentElement );

// Ideally ALL classes that are added through get_body_class should
Expand All @@ -154,7 +130,6 @@ function Iframe( {
);

contentDocument.dir = ownerDocument.dir;
documentElement.removeChild( contentDocument.body );

for ( const compatStyle of compatStyles ) {
if ( contentDocument.getElementById( compatStyle.id ) ) {
Expand Down Expand Up @@ -199,35 +174,29 @@ function Iframe( {
};
}, [] );

const headRef = useRefEffect( ( element ) => {
scripts
.reduce(
( promise, script ) =>
promise.then( () => loadScript( element, script ) ),
Promise.resolve()
)
.finally( () => {
// When script are loaded, re-render blocks to allow them
// to initialise.
forceRender();
} );
}, [] );
const disabledRef = useDisabled( { isDisabled: ! readonly } );
const bodyRef = useMergeRefs( [
contentRef,
clearerRef,
writingFlowRef,
disabledRef,
headRef,
] );

// Correct doctype is required to enable rendering in standards
// mode. Also preload the styles to avoid a flash of unstyled
// content.
const html =
'<!doctype html>' +
'<style>html{height:auto!important;min-height:100%;}body{margin:0}</style>' +
( assets?.styles ?? '' );
const html = `<!doctype html>
<html>
<head>
<script>window.frameElement._load()</script>
<style>html{height:auto!important;min-height:100%;}body{margin:0}</style>
${ styles }
${ scripts }
</head>
<body>
<script>document.currentScript.parentElement.remove()</script>
</body>
</html>`;

const [ src, cleanup ] = useMemo( () => {
const _src = URL.createObjectURL(
Expand Down
47 changes: 1 addition & 46 deletions packages/block-editor/src/components/rich-text/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
* WordPress dependencies
*/
import { RawHTML } from '@wordpress/element';
import {
children as childrenSource,
getSaveElement,
__unstableGetBlockProps as getBlockProps,
} from '@wordpress/blocks';
import { children as childrenSource } from '@wordpress/blocks';
import deprecated from '@wordpress/deprecated';

/**
Expand Down Expand Up @@ -42,44 +38,3 @@ export const Content = ( { value, tagName: Tag, multiline, ...props } ) => {

return content;
};

Content.__unstableIsRichTextContent = {};

function findContent( blocks, richTextValues = [] ) {
if ( ! Array.isArray( blocks ) ) {
blocks = [ blocks ];
}

for ( const block of blocks ) {
if (
block?.type?.__unstableIsRichTextContent ===
Content.__unstableIsRichTextContent
) {
richTextValues.push( block.props.value );
continue;
}

if ( block?.props?.children ) {
findContent( block.props.children, richTextValues );
}
}

return richTextValues;
}

function _getSaveElement( { name, attributes, innerBlocks } ) {
return getSaveElement(
name,
attributes,
innerBlocks.map( _getSaveElement )
);
}

export function getRichTextValues( blocks = [] ) {
getBlockProps.skipFilters = true;
const values = findContent(
( Array.isArray( blocks ) ? blocks : [ blocks ] ).map( _getSaveElement )
);
getBlockProps.skipFilters = false;
return values;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/**
* WordPress dependencies
*/
import { RawHTML, StrictMode, Fragment } from '@wordpress/element';
import {
getSaveElement,
__unstableGetBlockProps as getBlockProps,
} from '@wordpress/blocks';

/**
* Internal dependencies
*/
import InnerBlocks from '../inner-blocks';
import { Content } from './content';

/*
* This function is similar to `@wordpress/element`'s `renderToString` function,
* except that it does not render the elements to a string, but instead collects
* the values of all rich text `Content` elements.
*/
function addValuesForElement( element, ...args ) {
if ( null === element || undefined === element || false === element ) {
return;
}

if ( Array.isArray( element ) ) {
return addValuesForElements( element, ...args );
}

switch ( typeof element ) {
case 'string':
case 'number':
return;
}

const { type, props } = element;

switch ( type ) {
case StrictMode:
case Fragment:
return addValuesForElements( props.children, ...args );
case RawHTML:
return;
case InnerBlocks.Content:
return addValuesForBlocks( ...args );
case Content:
const [ values ] = args;
values.push( props.value );
return;
}

switch ( typeof type ) {
case 'string':
if ( typeof props.children !== 'undefined' ) {
return addValuesForElements( props.children, ...args );
}
return;
case 'function':
if (
type.prototype &&
typeof type.prototype.render === 'function'
) {
return addValuesForElement(
new type( props ).render(),
...args
);
}

return addValuesForElement( type( props ), ...args );
}
}

function addValuesForElements( children, ...args ) {
children = Array.isArray( children ) ? children : [ children ];

for ( let i = 0; i < children.length; i++ ) {
addValuesForElement( children[ i ], ...args );
}
}

function addValuesForBlocks( values, blocks ) {
for ( let i = 0; i < blocks.length; i++ ) {
const { name, attributes, innerBlocks } = blocks[ i ];
const saveElement = getSaveElement( name, attributes );
addValuesForElement( saveElement, values, innerBlocks );
}
}

export function getRichTextValues( blocks = [] ) {
getBlockProps.skipFilters = true;
const values = [];
addValuesForBlocks( values, blocks );
getBlockProps.skipFilters = false;
return values;
}
2 changes: 1 addition & 1 deletion packages/block-editor/src/private-apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import * as globalStyles from './components/global-styles';
import { ExperimentalBlockEditorProvider } from './components/provider';
import { lock } from './lock-unlock';
import { getRichTextValues } from './components/rich-text/content';
import { getRichTextValues } from './components/rich-text/get-rich-text-values';
import ResizableBoxPopover from './components/resizable-box-popover';
import { ComposedPrivateInserter as PrivateInserter } from './components/inserter';
import { PrivateListView } from './components/list-view';
Expand Down
7 changes: 5 additions & 2 deletions packages/block-library/src/comment-template/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,19 @@ function block_core_comment_template_render_comments( $comments, $block ) {
* We set commentId context through the `render_block_context` filter so
* that dynamically inserted blocks (at `render_block` filter stage)
* will also receive that context.
*
* Use an early priority to so that other 'render_block_context' filters
* have access to the values.
*/
add_filter( 'render_block_context', $filter_block_context );
add_filter( 'render_block_context', $filter_block_context, 1 );

/*
* We construct a new WP_Block instance from the parsed block so that
* it'll receive any changes made by the `render_block_data` filter.
*/
$block_content = ( new WP_Block( $block->parsed_block ) )->render( array( 'dynamic' => false ) );

remove_filter( 'render_block_context', $filter_block_context );
remove_filter( 'render_block_context', $filter_block_context, 1 );

$children = $comment->get_children();

Expand Down
1 change: 0 additions & 1 deletion packages/block-library/src/footnotes/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"supports": {
"html": false,
"multiple": false,
"inserter": false,
"reusable": false
},
"style": "wp-block-footnotes"
Expand Down
23 changes: 21 additions & 2 deletions packages/block-library/src/footnotes/edit.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/**
* WordPress dependencies
*/
import { RichText, useBlockProps } from '@wordpress/block-editor';
import { BlockIcon, RichText, useBlockProps } from '@wordpress/block-editor';
import { useEntityProp } from '@wordpress/core-data';
import { __ } from '@wordpress/i18n';
import { Placeholder } from '@wordpress/components';
import { formatListNumbered as icon } from '@wordpress/icons';

export default function FootnotesEdit( { context: { postType, postId } } ) {
const [ meta, updateMeta ] = useEntityProp(
Expand All @@ -12,8 +15,24 @@ export default function FootnotesEdit( { context: { postType, postId } } ) {
postId
);
const footnotes = meta?.footnotes ? JSON.parse( meta.footnotes ) : [];
const blockProps = useBlockProps();

if ( ! footnotes.length ) {
return (
<div { ...blockProps }>
<Placeholder
icon={ <BlockIcon icon={ icon } /> }
label={ __( 'Footnotes' ) }
instructions={ __(
'Footnotes found in blocks within this document will be displayed here.'
) }
/>
</div>
);
}

return (
<ol { ...useBlockProps() }>
<ol { ...blockProps }>
{ footnotes.map( ( { id, content } ) => (
<li key={ id }>
<RichText
Expand Down