Skip to content

Commit

Permalink
Merge branch 'trunk' of github.com:WordPress/gutenberg into rnmobile/…
Browse files Browse the repository at this point in the history
…appium-2
  • Loading branch information
dcalhoun committed Oct 16, 2023
2 parents c545e8f + 58064cc commit 0dbf082
Show file tree
Hide file tree
Showing 85 changed files with 1,691 additions and 652 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/publish-npm-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ jobs:
with:
path: publish
ref: wp/${{ github.event.inputs.wp_version }}
# We need to ensure that Lerna can read the commit created during the previous npm publishing.
# Lerna assumes that all packages need publishing if it can't access the necessary information.
fetch-depth: 999
token: ${{ secrets.GUTENBERG_TOKEN }}
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}

Expand Down
22 changes: 6 additions & 16 deletions bin/plugin/commands/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,14 @@ async function checkoutNpmReleaseBranch( {
/*
* Create the release branch.
*
* Note that we are grabbing an arbitrary depth of commits
* during the fetch. When `lerna` attempts to determine if
* a package needs an update, it looks at `git` history,
* and if we have pruned that history it will pre-emptively
* publish when it doesn't need to.
*
* We could set a different arbitrary depth if this isn't
* long enough or if it's excessive. We could also try and
* find a way to more specifically fetch what we expect to
* change. For example, if we knew we'll be performing
* updates every two weeks, we might be conservative and
* use `--shallow-since=4.weeks.ago`.
*
* At the time of writing, a depth of 100 pulls in all
* `trunk` commits from within the past week.
* Note that we are grabbing an arbitrary depth of commits (999) during the fetch.
* When Lerna attempts to determine if a package needs an update, it looks at
* `git` history to find the commit created during the previous npm publishing.
* Lerna assumes that all packages need publishing if it can't access
* the necessary information.
*/
await SimpleGit( gitWorkingDirectoryPath )
.fetch( 'origin', npmReleaseBranch, [ '--depth=100' ] )
.fetch( 'origin', npmReleaseBranch, [ '--depth=999' ] )
.checkout( npmReleaseBranch );
log(
'>> The local npm release branch ' +
Expand Down
12 changes: 11 additions & 1 deletion docs/how-to-guides/block-tutorial/nested-blocks-inner-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ registerBlockType( 'gutenberg-examples/example-06', {

## Allowed Blocks

Using the `ALLOWED_BLOCKS` property, you can define the set of blocks allowed in your InnerBlock. This restricts the blocks that can be included only to those listed, all other blocks will not show in the inserter.
Using the `allowedBlocks` property, you can define the set of blocks allowed in your InnerBlock. This restricts the blocks that can be included only to those listed, all other blocks will not show in the inserter.

```js
const ALLOWED_BLOCKS = [ 'core/image', 'core/paragraph' ];
Expand All @@ -87,6 +87,16 @@ By default, `InnerBlocks` expects its blocks to be shown in a vertical list. A v

Specifying this prop does not affect the layout of the inner blocks, but results in the block mover icons in the child blocks being displayed horizontally, and also ensures that drag and drop works correctly.

## Default Block

By default `InnerBlocks` opens a list of permitted blocks via `allowedBlocks` when the block appender is clicked. You can modify the default block and its attributes that are inserted when the initial block appender is clicked by using the `defaultBlock` property. For example:

```js
<InnerBlocks defaultBlock={['core/paragraph', {placeholder: "Lorem ipsum..."}]} directInsert />
```

By default this behavior is disabled until the `directInsert` prop is set to `true`. This allows you to specify conditions for when the default block should or should not be inserted.

## Template

Use the template property to define a set of blocks that prefill the InnerBlocks component when inserted. You can set attributes on the blocks to define their use. The example below shows a book review template using InnerBlocks component and setting placeholders values to show the block usage.
Expand Down
1 change: 1 addition & 0 deletions docs/how-to-guides/themes/theme-json.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ Note, however, that not all settings are relevant for all blocks. The settings s

There's one special setting property, `appearanceTools`, which is a boolean and its default value is false. Themes can use this setting to enable the following ones:

- background: backgroundImage
- border: color, radius, style, width
- color: link
- dimensions: minHeight
Expand Down
29 changes: 25 additions & 4 deletions docs/reference-guides/filters/block-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ var withInspectorControls = wp.compose.createHigherOrderComponent( function (
)
);
};
},
'withInspectorControls' );
}, 'withInspectorControls' );

wp.hooks.addFilter(
'editor.BlockEdit',
Expand All @@ -239,6 +238,29 @@ wp.hooks.addFilter(

{% end %}

Note that as this hook is run for _all blocks_, consuming it has potential for performance regressions particularly around block selection metrics.

To mitigate this, consider whether any work you perform can be altered to run only under certain conditions.

For example, if you are adding components that only need to render when the block is _selected_, then you can use the block's "selected" state (`props.isSelected`) to conditionalize your rendering.

```js
const withInspectorControls = createHigherOrderComponent( ( BlockEdit ) => {
return ( props ) => {
return (
<>
<BlockEdit { ...props } />
{ props.isSelected && {
<InspectorControls>
<PanelBody>My custom control</PanelBody>
</InspectorControls>
}}
</>
);
};
}, 'withInspectorControl' );
```

#### `editor.BlockListBlock`

Used to modify the block's wrapper component containing the block's `edit` component and all toolbars. It receives the original `BlockListBlock` component and returns a new wrapped component.
Expand Down Expand Up @@ -288,8 +310,7 @@ var withClientIdClassName = wp.compose.createHigherOrderComponent( function (

return el( BlockListBlock, newProps );
};
},
'withClientIdClassName' );
}, 'withClientIdClassName' );

wp.hooks.addFilter(
'editor.BlockListBlock',
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import { __ } from '@wordpress/i18n';
import { Spinner } from '@wordpress/components';
import { compose } from '@wordpress/compose';
import { store as blockEditorStore } from '@wordpress/block-editor';
import { store as coreStore } from '@wordpress/core-data';
import { withSelect } from '@wordpress/data';
import { getBlockType } from '@wordpress/blocks';

/**
* Internal dependencies
Expand Down Expand Up @@ -72,10 +72,12 @@ function DownloadableBlocksPanel( {
}

export default compose( [
withSelect( ( select, { filterValue, rootClientId = null } ) => {
const { getDownloadableBlocks, isRequestingDownloadableBlocks } =
select( blockDirectoryStore );
const { canInsertBlockType } = select( blockEditorStore );
withSelect( ( select, { filterValue } ) => {
const {
getDownloadableBlocks,
isRequestingDownloadableBlocks,
getInstalledBlockTypes,
} = select( blockDirectoryStore );

const hasPermission = select( coreStore ).canUser(
'read',
Expand All @@ -84,9 +86,19 @@ export default compose( [

function getInstallableBlocks( term ) {
const downloadableBlocks = getDownloadableBlocks( term );
const installableBlocks = downloadableBlocks.filter( ( block ) =>
canInsertBlockType( block, rootClientId, true )
);
const installedBlockTypes = getInstalledBlockTypes();
// Filter out blocks that are already installed.
const installableBlocks = downloadableBlocks.filter( ( block ) => {
// Check if the block has just been installed, in which case it
// should still show in the list to avoid suddenly disappearing.
// `installedBlockTypes` only returns blocks stored in state
// immediately after installation, not all installed blocks.
const isJustInstalled = !! installedBlockTypes.find(
( blockType ) => blockType.name === block.name
);
const isPreviouslyInstalled = getBlockType( block.name );
return isJustInstalled || ! isPreviouslyInstalled;
} );

if ( downloadableBlocks.length === installableBlocks.length ) {
return downloadableBlocks;
Expand Down
9 changes: 6 additions & 3 deletions packages/block-editor/src/components/block-controls/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ export default function useBlockControlsFill( group, shareWithChildBlocks ) {
const { clientId } = useBlockEditContext();
const isParentDisplayed = useSelect(
( select ) => {
if ( ! shareWithChildBlocks ) {
return false;
}

const { getBlockName, hasSelectedInnerBlock } =
select( blockEditorStore );
const { hasBlockSupport } = select( blocksStore );

return (
shareWithChildBlocks &&
hasBlockSupport(
getBlockName( clientId ),
'__experimentalExposeControlsToChildren',
false
) &&
hasSelectedInnerBlock( clientId )
) && hasSelectedInnerBlock( clientId )
);
},
[ shareWithChildBlocks, clientId ]
Expand Down
8 changes: 7 additions & 1 deletion packages/block-editor/src/components/block-preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import deprecated from '@wordpress/deprecated';
*/
import { ExperimentalBlockEditorProvider } from '../provider';
import AutoHeightBlockPreview from './auto';
import EditorStyles from '../editor-styles';
import { store as blockEditorStore } from '../../store';
import { BlockListItems } from '../block-list';

Expand Down Expand Up @@ -113,7 +114,11 @@ export function useBlockPreview( { blocks, props = {}, layout } ) {
[]
);
const settings = useMemo(
() => ( { ...originalSettings, __unstableIsPreviewMode: true } ),
() => ( {
...originalSettings,
styles: undefined, // Clear styles included by the parent settings, as they are already output by the parent's EditorStyles.
__unstableIsPreviewMode: true,
} ),
[ originalSettings ]
);
const disabledRef = useDisabled();
Expand All @@ -128,6 +133,7 @@ export function useBlockPreview( { blocks, props = {}, layout } ) {
value={ renderedBlocks }
settings={ settings }
>
<EditorStyles />
<BlockListItems renderAppender={ false } layout={ layout } />
</ExperimentalBlockEditorProvider>
);
Expand Down
16 changes: 13 additions & 3 deletions packages/block-editor/src/components/list-view/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import {
useMergeRefs,
__experimentalUseFixedWindowList as useFixedWindowList,
} from '@wordpress/compose';
import { __experimentalTreeGrid as TreeGrid } from '@wordpress/components';
import {
__experimentalTreeGrid as TreeGrid,
VisuallyHidden,
} from '@wordpress/components';
import { AsyncModeProvider, useSelect } from '@wordpress/data';
import deprecated from '@wordpress/deprecated';
import {
Expand Down Expand Up @@ -257,12 +260,20 @@ function ListViewComponent(
return null;
}

const describedById =
description && `block-editor-list-view-description-${ instanceId }`;

return (
<AsyncModeProvider value={ true }>
<ListViewDropIndicator
listViewRef={ elementRef }
blockDropTarget={ blockDropTarget }
/>
{ description && (
<VisuallyHidden id={ describedById }>
{ description }
</VisuallyHidden>
) }
<TreeGrid
id={ id }
className="block-editor-list-view-tree"
Expand All @@ -272,8 +283,7 @@ function ListViewComponent(
onExpandRow={ expandRow }
onFocusRow={ focusRow }
applicationAriaLabel={ __( 'Block navigation structure' ) }
// eslint-disable-next-line jsx-a11y/aria-props
aria-description={ description }
aria-describedby={ describedById }
>
<ListViewContext.Provider value={ contextValue }>
<ListViewBranch
Expand Down
45 changes: 22 additions & 23 deletions packages/block-editor/src/components/rich-text/use-paste-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,6 @@ export function usePasteHandler( props ) {
return;
}

const transformed = formatTypes.reduce(
( accumlator, { __unstablePasteRule } ) => {
// Only allow one transform.
if ( __unstablePasteRule && accumlator === value ) {
accumlator = __unstablePasteRule( value, {
html,
plainText,
} );
}

return accumlator;
},
value
);

if ( transformed !== value ) {
onChange( transformed );
return;
}

const isInternal =
event.clipboardData.getData( 'rich-text' ) === 'true';

Expand Down Expand Up @@ -160,9 +140,28 @@ export function usePasteHandler( props ) {
} );

if ( typeof content === 'string' ) {
const valueToInsert = create( { html: content } );
addActiveFormats( valueToInsert, value.activeFormats );
onChange( insert( value, valueToInsert ) );
const transformed = formatTypes.reduce(
( accumlator, { __unstablePasteRule } ) => {
// Only allow one transform.
if ( __unstablePasteRule && accumlator === value ) {
accumlator = __unstablePasteRule( value, {
html,
plainText,
} );
}

return accumlator;
},
value
);

if ( transformed !== value ) {
onChange( transformed );
} else {
const valueToInsert = create( { html: content } );
addActiveFormats( valueToInsert, value.activeFormats );
onChange( insert( value, valueToInsert ) );
}
} else if ( content.length > 0 ) {
if ( onReplace && isEmpty( value ) ) {
onReplace( content, content.length - 1, -1 );
Expand Down
Loading

0 comments on commit 0dbf082

Please sign in to comment.