Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
jameskoster committed Sep 21, 2023
2 parents ba2a37f + b30a3f2 commit ccc62f1
Show file tree
Hide file tree
Showing 124 changed files with 58,046 additions and 544 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ private static function parse_settings( array $settings ) {
foreach ( $settings['typography']['fontFamilies'] as $font_families ) {
foreach ( $font_families as $definition ) {

// Skip if font-family "name" is not defined.
if ( empty( $definition['name'] ) ) {
continue;
}
// // Skip if font-family "name" is not defined.
// if ( empty( $definition['name'] ) ) {
// continue;
// }

// Skip if "fontFace" is not defined, meaning there are no variations.
if ( empty( $definition['fontFace'] ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function get_data() {
return new WP_Error( 'font_collection_file_error', __( 'Font Collection data JSON file does not exist.', 'gutenberg' ) );
}

$data = file_get_contents( $this->config['data_json_file'] );
$data = wp_json_file_decode( $this->config['data_json_file'], array( 'associative' => true ) );
if ( empty( $data ) ) {
return new WP_Error( 'font_collection_read_error', __( 'Error reading the Font Collection data JSON file contents.', 'gutenberg' ) );
}
Expand Down
55,714 changes: 55,714 additions & 0 deletions lib/experimental/fonts/font-library/default-font-collection.json

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion lib/experimental/fonts/font-library/font-library.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,18 @@ function wp_register_font_collection( $config ) {
}
}

// @core-merge: This code needs to be removed.
add_action(
'enqueue_block_editor_assets',
function () {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalFontLibrary = true', 'before' );
}
);

$default_font_collection = array(
'id' => 'default-font-collection',
'name' => 'Google Fonts',
'description' => __( 'Add from Google Fonts. Fonts are copied to and served from your site.', 'gutenberg' ),
'data_json_file' => path_join( __DIR__, 'default-font-collection.json' ),
);

wp_register_font_collection( $default_font_collection );
57 changes: 55 additions & 2 deletions packages/block-editor/src/components/link-control/search-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
file,
} from '@wordpress/icons';
import { __unstableStripHTML as stripHTML } from '@wordpress/dom';
import { safeDecodeURI, filterURLForDisplay } from '@wordpress/url';
import { safeDecodeURI, filterURLForDisplay, getPath } from '@wordpress/url';
import { pipe } from '@wordpress/compose';

const ICONS_MAP = {
post: postList,
Expand Down Expand Up @@ -44,6 +45,58 @@ function SearchItemIcon( { isURL, suggestion } ) {
return null;
}

/**
* Adds a leading slash to a url if it doesn't already have one.
* @param {string} url the url to add a leading slash to.
* @return {string} the url with a leading slash.
*/
function addLeadingSlash( url ) {
const trimmedURL = url?.trim();

if ( ! trimmedURL?.length ) return url;

return url?.replace( /^\/?/, '/' );
}

function removeTrailingSlash( url ) {
const trimmedURL = url?.trim();

if ( ! trimmedURL?.length ) return url;

return url?.replace( /\/$/, '' );
}

const partialRight =
( fn, ...partialArgs ) =>
( ...args ) =>
fn( ...args, ...partialArgs );

const defaultTo = ( d ) => ( v ) => {
return v === null || v === undefined || v !== v ? d : v;
};

/**
* Prepares a URL for display in the UI.
* - decodes the URL.
* - filters it (removes protocol, www, etc.).
* - truncates it if necessary.
* - adds a leading slash.
* @param {string} url the url.
* @return {string} the processed url to display.
*/
function getURLForDisplay( url ) {
if ( ! url ) return url;

return pipe(
safeDecodeURI,
getPath,
defaultTo( '' ),
partialRight( filterURLForDisplay, 24 ),
removeTrailingSlash,
addLeadingSlash
)( url );
}

export const LinkControlSearchItem = ( {
itemProps,
suggestion,
Expand All @@ -54,7 +107,7 @@ export const LinkControlSearchItem = ( {
} ) => {
const info = isURL
? __( 'Press ENTER to add this link' )
: filterURLForDisplay( safeDecodeURI( suggestion?.url ), 24 );
: getURLForDisplay( suggestion.url );

return (
<MenuItem
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/hooks/block-rename-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function RenameModal( { blockName, originalBlockName, onClose, onSave } ) {
aria={ {
describedby: dialogDescription,
} }
focusOnMount="firstContentElement"
>
<p id={ dialogDescription }>
{ __( 'Enter a custom name for this block.' ) }
Expand Down
10 changes: 7 additions & 3 deletions packages/block-editor/src/store/private-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ export function getLastInsertedBlocksClientIds( state ) {
export const isBlockSubtreeDisabled = createSelector(
( state, clientId ) => {
const isChildSubtreeDisabled = ( childClientId ) => {
const mode = state.blockEditingModes.get( childClientId );
return (
( mode === undefined || mode === 'disabled' ) &&
getBlockEditingMode( state, childClientId ) === 'disabled' &&
getBlockOrder( state, childClientId ).every(
isChildSubtreeDisabled
)
Expand All @@ -58,7 +57,12 @@ export const isBlockSubtreeDisabled = createSelector(
getBlockOrder( state, clientId ).every( isChildSubtreeDisabled )
);
},
( state ) => [ state.blockEditingModes, state.blocks.parents ]
( state ) => [
state.blocks.parents,
state.blocks.order,
state.blockEditingModes,
state.blockListSettings,
]
);

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/block-library/src/cover/test/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ describe( 'Cover block', () => {
await setup();

expect(
screen.getByRole( 'group', {
name: 'To edit this block, you need permission to upload media.',
} )
within( screen.getByLabelText( 'Block: Cover' ) ).getByText(
'To edit this block, you need permission to upload media.'
)
).toBeInTheDocument();
} );

Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/file/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ static function ( $matches ) {
* Ensure that the view script has the `wp-interactivity` dependency.
*
* @since 6.4.0
*
* @global WP_Scripts $wp_scripts
*/
function block_core_file_ensure_interactivity_dependency() {
global $wp_scripts;
Expand Down
32 changes: 26 additions & 6 deletions packages/block-library/src/html/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import {
PlainText,
useBlockProps,
} from '@wordpress/block-editor';
import { ToolbarButton, Disabled, ToolbarGroup } from '@wordpress/components';
import {
ToolbarButton,
Disabled,
ToolbarGroup,
VisuallyHidden,
} from '@wordpress/components';
import { useInstanceId } from '@wordpress/compose';

/**
* Internal dependencies
Expand All @@ -19,6 +25,8 @@ export default function HTMLEdit( { attributes, setAttributes, isSelected } ) {
const [ isPreview, setIsPreview ] = useState();
const isDisabled = useContext( Disabled.Context );

const instanceId = useInstanceId( HTMLEdit, 'html-edit-desc' );

function switchToPreview() {
setIsPreview( true );
}
Expand All @@ -27,8 +35,13 @@ export default function HTMLEdit( { attributes, setAttributes, isSelected } ) {
setIsPreview( false );
}

const blockProps = useBlockProps( {
className: 'block-library-html__edit',
'aria-describedby': isPreview ? instanceId : undefined,
} );

return (
<div { ...useBlockProps( { className: 'block-library-html__edit' } ) }>
<div { ...blockProps }>
<BlockControls>
<ToolbarGroup>
<ToolbarButton
Expand All @@ -48,10 +61,17 @@ export default function HTMLEdit( { attributes, setAttributes, isSelected } ) {
</ToolbarGroup>
</BlockControls>
{ isPreview || isDisabled ? (
<Preview
content={ attributes.content }
isSelected={ isSelected }
/>
<>
<Preview
content={ attributes.content }
isSelected={ isSelected }
/>
<VisuallyHidden id={ instanceId }>
{ __(
'HTML preview is not yet fully accessible. Please switch screen reader to virtualized mode to navigate the below iFrame.'
) }
</VisuallyHidden>
</>
) : (
<PlainText
value={ attributes.content }
Expand Down
8 changes: 7 additions & 1 deletion packages/block-library/src/html/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '@wordpress/block-editor';
import { SandBox } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';

// Default styles used to unset some of the styles
// that might be inherited from the editor style.
Expand All @@ -32,7 +33,12 @@ export default function HTMLEditPreview( { content, isSelected } ) {

return (
<>
<SandBox html={ content } styles={ styles } />
<SandBox
html={ content }
styles={ styles }
title={ __( 'Custom HTML Preview' ) }
tabIndex={ -1 }
/>
{ /*
An overlay is added when the block is not selected in order to register click events.
Some browsers do not bubble up the clicks from the sandboxed iframe, which makes it
Expand Down
16 changes: 9 additions & 7 deletions packages/block-library/src/image/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ function block_core_image_get_lightbox_settings( $block ) {
}

if ( ! isset( $lightbox_settings ) ) {
$lightbox_settings = gutenberg_get_global_settings( array( 'lightbox' ), array( 'block_name' => 'core/image' ) );
$lightbox_settings = wp_get_global_settings( array( 'lightbox' ), array( 'block_name' => 'core/image' ) );

// If not present in global settings, check the top-level global settings.
//
// NOTE: If no block-level settings are found, the previous call to
// `gutenberg_get_global_settings` will return the whole `theme.json`
// `wp_get_global_settings` will return the whole `theme.json`
// structure in which case we can check if the "lightbox" key is present at
// the top-level of the global settings and use its value.
if ( isset( $lightbox_settings['lightbox'] ) ) {
$lightbox_settings = gutenberg_get_global_settings( array( 'lightbox' ) );
$lightbox_settings = wp_get_global_settings( array( 'lightbox' ) );
}
}

Expand All @@ -117,7 +117,7 @@ function block_core_image_get_lightbox_settings( $block ) {
function block_core_image_render_lightbox( $block_content, $block ) {
$processor = new WP_HTML_Tag_Processor( $block_content );

$aria_label = __( 'Enlarge image', 'gutenberg' );
$aria_label = __( 'Enlarge image' );

$alt_attribute = $processor->get_attribute( 'alt' );

Expand All @@ -127,7 +127,7 @@ function block_core_image_render_lightbox( $block_content, $block ) {

if ( $alt_attribute ) {
/* translators: %s: Image alt text. */
$aria_label = sprintf( __( 'Enlarge image: %s', 'gutenberg' ), $alt_attribute );
$aria_label = sprintf( __( 'Enlarge image: %s' ), $alt_attribute );
}
$content = $processor->get_updated_html();

Expand Down Expand Up @@ -251,8 +251,8 @@ function block_core_image_render_lightbox( $block_content, $block ) {

$close_button_icon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="15" height="15" aria-hidden="true" focusable="false"><path d="M13 11.8l6.1-6.3-1-1-6.1 6.2-6.1-6.2-1 1 6.1 6.3-6.5 6.7 1 1 6.5-6.6 6.5 6.6 1-1z"></path></svg>';
$close_button_color = esc_attr( wp_get_global_styles( array( 'color', 'text' ) ) );
$dialog_label = $alt_attribute ? esc_attr( $alt_attribute ) : esc_attr__( 'Image', 'gutenberg' );
$close_button_label = esc_attr__( 'Close', 'gutenberg' );
$dialog_label = $alt_attribute ? esc_attr( $alt_attribute ) : esc_attr__( 'Image' );
$close_button_label = esc_attr__( 'Close' );

$lightbox_html = <<<HTML
<div data-wp-body="" class="wp-lightbox-overlay $lightbox_animation"
Expand Down Expand Up @@ -286,6 +286,8 @@ function block_core_image_render_lightbox( $block_content, $block ) {
* Ensure that the view script has the `wp-interactivity` dependency.
*
* @since 6.4.0
*
* @global WP_Scripts $wp_scripts
*/
function block_core_image_ensure_interactivity_dependency() {
global $wp_scripts;
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,8 @@ function block_core_navigation_typographic_presets_backcompatibility( $parsed_bl
* Ensure that the view script has the `wp-interactivity` dependency.
*
* @since 6.4.0
*
* @global WP_Scripts $wp_scripts
*/
function block_core_navigation_ensure_interactivity_dependency() {
global $wp_scripts;
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/query/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class="wp-block-query__enhanced-pagination-animation"
* Ensure that the view script has the `wp-interactivity` dependency.
*
* @since 6.4.0
*
* @global WP_Scripts $wp_scripts
*/
function block_core_query_ensure_interactivity_dependency() {
global $wp_scripts;
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/search/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ function register_block_core_search() {
* Ensure that the view script has the `wp-interactivity` dependency.
*
* @since 6.4.0
*
* @global WP_Scripts $wp_scripts
*/
function block_core_search_ensure_interactivity_dependency() {
global $wp_scripts;
Expand Down
9 changes: 9 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@

## Unreleased

### Enhancements

- `SearchControl`: polish metrics for `compact` size variant ([#54663](https://github.com/WordPress/gutenberg/pull/54663)).

### Bug Fix

- `Placeholder`: Improved DOM structure and screen reader announcements ([#45801](https://github.com/WordPress/gutenberg/pull/45801)).
- `DateTimePicker`: fix onChange callback check so that it also works inside iframes ([#54669](https://github.com/WordPress/gutenberg/pull/54669)).

## 25.8.0 (2023-09-20)

### Enhancements

- Add new option `firstContentElement` to Modal's `focusOnMount` prop to allow consumers to focus the first element within the Modal's **contents** ([#54590](https://github.com/WordPress/gutenberg/pull/54590)).
- `Notice`: Improve accessibility by adding visually hidden text to clarify what a notice text is about and the notice type (success, error, warning, info) ([#54498](https://github.com/WordPress/gutenberg/pull/54498)).
- Making Circular Option Picker a `listbox`. Note that while this changes some public API, new props are optional, and currently have default values; this will change in another patch ([#52255](https://github.com/WordPress/gutenberg/pull/52255)).
- `ToggleGroupControl`: Rewrite backdrop animation using framer motion shared layout animations, add better support for controlled and uncontrolled modes ([#50278](https://github.com/WordPress/gutenberg/pull/50278)).
Expand All @@ -20,6 +28,7 @@
- `DuotonePicker/ColorListPicker`: Adds appropriate labels to 'Duotone Filter' color pickers ([#54468](https://github.com/WordPress/gutenberg/pull/54468)).
- `SearchControl`: support new `40px` and `32px` sizes ([#54548](https://github.com/WordPress/gutenberg/pull/54548)).
- `FormTokenField`: Add `tokenizeOnBlur` prop to add any incompleteTokenValue as a new token when field loses focus ([#54445](https://github.com/WordPress/gutenberg/pull/54445)).
- `Sandbox`: Add `tabIndex` prop ([#54408](https://github.com/WordPress/gutenberg/pull/54408)).

### Bug Fix

Expand Down
9 changes: 8 additions & 1 deletion packages/components/src/date-time/time/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,14 @@ export function TimePicker( {
method: 'hours' | 'minutes' | 'date' | 'year'
) => {
const callback: InputChangeCallback = ( value, { event } ) => {
if ( ! ( event.target instanceof HTMLInputElement ) ) {
// `instanceof` checks need to get the instance definition from the
// corresponding window object — therefore, the following logic makes
// the component work correctly even when rendered inside an iframe.
const HTMLInputElementInstance =
( event.target as HTMLInputElement )?.ownerDocument.defaultView
?.HTMLInputElement ?? HTMLInputElement;

if ( ! ( event.target instanceof HTMLInputElementInstance ) ) {
return;
}

Expand Down
Loading

0 comments on commit ccc62f1

Please sign in to comment.