Skip to content

Commit

Permalink
prep build 02/23
Browse files Browse the repository at this point in the history
  • Loading branch information
bph committed Feb 23, 2024
2 parents 4a5a179 + ca96667 commit 5e1f52b
Show file tree
Hide file tree
Showing 85 changed files with 1,625 additions and 828 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/end2end-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ jobs:
run: |
npm run wp-env start
- name: Running the tests
run: |
npx wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --cacheDirectory="$HOME/.jest-cache"
- name: Archive debug artifacts (screenshots, HTML snapshots)
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
if: always()
Expand Down
6 changes: 6 additions & 0 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1679,6 +1679,12 @@
"markdown_source": "../packages/interactivity/README.md",
"parent": "packages"
},
{
"title": "API Reference",
"slug": "packages-interactivity-api-reference",
"markdown_source": "../packages/interactivity/docs/api-reference.md",
"parent": "packages-interactivity"
},
{
"title": "@wordpress/interface",
"slug": "packages-interface",
Expand Down
2 changes: 1 addition & 1 deletion docs/reference-guides/block-api/block-registration.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ The key is the name of the block (`string`) to hook into, and the value is the p
```js
{
blockHooks: {
'core/verse': 'before'
'core/verse': 'before',
'core/spacer': 'after',
'core/column': 'firstChild',
'core/group': 'lastChild',
Expand Down
3 changes: 3 additions & 0 deletions lib/experimental/editor-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ function gutenberg_enable_experiments() {
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-color-randomizer', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableColorRandomizer = true', 'before' );
}
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-grid-interactivity', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableGridInteractivity = true', 'before' );
}
if ( gutenberg_is_experiment_enabled( 'gutenberg-no-tinymce' ) ) {
wp_add_inline_script( 'wp-block-library', 'window.__experimentalDisableTinymce = true', 'before' );
}
Expand Down
14 changes: 14 additions & 0 deletions lib/experiments-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function gutenberg_initialize_experiments_settings() {
'id' => 'gutenberg-color-randomizer',
)
);

add_settings_field(
'gutenberg-form-blocks',
__( 'Form and input blocks ', 'gutenberg' ),
Expand All @@ -101,6 +102,19 @@ function gutenberg_initialize_experiments_settings() {
'id' => 'gutenberg-form-blocks',
)
);

add_settings_field(
'gutenberg-grid-interactivity',
__( 'Grid interactivty ', 'gutenberg' ),
'gutenberg_display_experiment_field',
'gutenberg-experiments',
'gutenberg_experiments_section',
array(
'label' => __( 'Test enhancements to the Grid block that let you move and resize items in the editor canvas.', 'gutenberg' ),
'id' => 'gutenberg-grid-interactivity',
)
);

add_settings_field(
'gutenberg-no-tinymce',
__( 'Disable TinyMCE and Classic block', 'gutenberg' ),
Expand Down
3 changes: 3 additions & 0 deletions packages/base-styles/_z-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ $z-layers: (
// Above the block list and the header.
".block-editor-block-popover": 31,

// Below the block toolbar.
".block-editor-grid-visualizer": 30,

// Show snackbars above everything (similar to popovers)
".components-snackbar-list": 100000,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,25 @@ import { __ } from '@wordpress/i18n';
import {
__experimentalVStack as VStack,
__experimentalHeading as Heading,
__experimentalGrid as Grid,
__experimentalHStack as HStack,
__experimentalDropdownContentWrapper as DropdownContentWrapper,
Button,
FlexItem,
Dropdown,
privateApis as componentsPrivateApis,
} from '@wordpress/components';
import { shadow as shadowIcon, Icon, check } from '@wordpress/icons';

/**
* External dependencies
*/
import classNames from 'classnames';

/**
* Internal dependencies
*/
import { unlock } from '../../lock-unlock';

export function ShadowPopoverContainer( { shadow, onShadowChange, settings } ) {
const defaultShadows = settings?.shadow?.presets?.default || [];
const themeShadows = settings?.shadow?.presets?.theme || [];
Expand All @@ -43,8 +49,16 @@ export function ShadowPopoverContainer( { shadow, onShadowChange, settings } ) {
}

export function ShadowPresets( { presets, activeShadow, onSelect } ) {
const { CompositeV2: Composite, useCompositeStoreV2: useCompositeStore } =
unlock( componentsPrivateApis );
const compositeStore = useCompositeStore();
return ! presets ? null : (
<Grid columns={ 6 } gap={ 0 } align="center" justify="center">
<Composite
store={ compositeStore }
role="listbox"
className="block-editor-global-styles__shadow__list"
aria-label={ __( 'Drop shadows' ) }
>
{ presets.map( ( { name, slug, shadow } ) => (
<ShadowIndicator
key={ slug }
Expand All @@ -56,23 +70,35 @@ export function ShadowPresets( { presets, activeShadow, onSelect } ) {
shadow={ shadow }
/>
) ) }
</Grid>
</Composite>
);
}

export function ShadowIndicator( { label, isActive, onSelect, shadow } ) {
const { CompositeItemV2: CompositeItem } = unlock( componentsPrivateApis );
return (
<div className="block-editor-global-styles__shadow-indicator-wrapper">
<Button
className="block-editor-global-styles__shadow-indicator"
onClick={ onSelect }
label={ label }
style={ { boxShadow: shadow } }
showTooltip
>
{ isActive && <Icon icon={ check } /> }
</Button>
</div>
<CompositeItem
role="option"
aria-label={ label }
aria-selected={ isActive }
className={ classNames(
'block-editor-global-styles__shadow__item',
{
'is-active': isActive,
}
) }
render={
<Button
className="block-editor-global-styles__shadow-indicator"
onClick={ onSelect }
label={ label }
style={ { boxShadow: shadow } }
showTooltip
>
{ isActive && <Icon icon={ check } /> }
</Button>
}
/>
);
}

Expand Down
27 changes: 17 additions & 10 deletions packages/block-editor/src/components/global-styles/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,31 @@
}
}

// wrapper to clip the shadow beyond 6px
.block-editor-global-styles__shadow-indicator-wrapper {
padding: $grid-unit-15 * 0.5;
display: flex;
align-items: center;
justify-content: center;
}

// These styles are similar to the color palette.
.block-editor-global-styles__shadow-indicator {
color: $gray-800;
border: $gray-200 $border-width solid;
border-radius: $radius-block-ui;
cursor: pointer;
padding: 0;
margin-right: $grid-unit-15;
margin-bottom: $grid-unit-15;

height: $button-size-small + 2 * $border-width;
width: $button-size-small + 2 * $border-width;
box-sizing: border-box;

transform: scale(1);
transition: transform 0.1s ease;
will-change: transform;

height: $button-size-small;
width: $button-size-small;
&:focus {
border: #{ $border-width * 2 } solid $gray-700;
}

&:hover {
transform: scale(1.2);
}
}

.block-editor-global-styles-advanced-panel__custom-css-input textarea {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/**
* WordPress dependencies
*/
import { ResizableBox } from '@wordpress/components';

/**
* Internal dependencies
*/
import { __unstableUseBlockElement as useBlockElement } from '../block-list/use-block-props/use-block-refs';
import BlockPopoverCover from '../block-popover/cover';
import { getComputedCSS } from './utils';

export function GridItemResizer( { clientId, onChange } ) {
const blockElement = useBlockElement( clientId );
if ( ! blockElement ) {
return null;
}
return (
<BlockPopoverCover
className="block-editor-grid-item-resizer"
clientId={ clientId }
__unstablePopoverSlot="block-toolbar"
>
<ResizableBox
className="block-editor-grid-item-resizer__box"
size={ {
width: '100%',
height: '100%',
} }
enable={ {
bottom: true,
bottomLeft: false,
bottomRight: false,
left: false,
right: true,
top: false,
topLeft: false,
topRight: false,
} }
onResizeStop={ ( event, direction, boxElement ) => {
const gridElement = blockElement.parentElement;
const columnGap = parseFloat(
getComputedCSS( gridElement, 'column-gap' )
);
const rowGap = parseFloat(
getComputedCSS( gridElement, 'row-gap' )
);
const gridColumnLines = getGridLines(
getComputedCSS( gridElement, 'grid-template-columns' ),
columnGap
);
const gridRowLines = getGridLines(
getComputedCSS( gridElement, 'grid-template-rows' ),
rowGap
);
const columnStart = getClosestLine(
gridColumnLines,
blockElement.offsetLeft
);
const rowStart = getClosestLine(
gridRowLines,
blockElement.offsetTop
);
const columnEnd = getClosestLine(
gridColumnLines,
blockElement.offsetLeft + boxElement.offsetWidth
);
const rowEnd = getClosestLine(
gridRowLines,
blockElement.offsetTop + boxElement.offsetHeight
);
onChange( {
columnSpan: Math.max( columnEnd - columnStart, 1 ),
rowSpan: Math.max( rowEnd - rowStart, 1 ),
} );
} }
/>
</BlockPopoverCover>
);
}

function getGridLines( template, gap ) {
const lines = [ 0 ];
for ( const size of template.split( ' ' ) ) {
const line = parseFloat( size );
lines.push( lines[ lines.length - 1 ] + line + gap );
}
return lines;
}

function getClosestLine( lines, position ) {
return lines.reduce(
( closest, line, index ) =>
Math.abs( line - position ) <
Math.abs( lines[ closest ] - position )
? index
: closest,
0
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* WordPress dependencies
*/
import { useState, useEffect } from '@wordpress/element';

/**
* Internal dependencies
*/
import { __unstableUseBlockElement as useBlockElement } from '../block-list/use-block-props/use-block-refs';
import BlockPopoverCover from '../block-popover/cover';
import { getComputedCSS } from './utils';

export function GridVisualizer( { clientId } ) {
const blockElement = useBlockElement( clientId );
if ( ! blockElement ) {
return null;
}
return (
<BlockPopoverCover
className="block-editor-grid-visualizer"
clientId={ clientId }
__unstablePopoverSlot="block-toolbar"
>
<GridVisualizerGrid blockElement={ blockElement } />
</BlockPopoverCover>
);
}

function GridVisualizerGrid( { blockElement } ) {
const [ gridInfo, setGridInfo ] = useState( () =>
getGridInfo( blockElement )
);
useEffect( () => {
const observers = [];
for ( const element of [ blockElement, ...blockElement.children ] ) {
const observer = new window.ResizeObserver( () => {
setGridInfo( getGridInfo( blockElement ) );
} );
observer.observe( element );
observers.push( observer );
}
return () => {
for ( const observer of observers ) {
observer.disconnect();
}
};
}, [ blockElement ] );
return (
<div
className="block-editor-grid-visualizer__grid"
style={ gridInfo.style }
>
{ Array.from( { length: gridInfo.numItems }, ( _, i ) => (
<div key={ i } className="block-editor-grid-visualizer__item" />
) ) }
</div>
);
}

function getGridInfo( blockElement ) {
const gridTemplateColumns = getComputedCSS(
blockElement,
'grid-template-columns'
);
const gridTemplateRows = getComputedCSS(
blockElement,
'grid-template-rows'
);
const numColumns = gridTemplateColumns.split( ' ' ).length;
const numRows = gridTemplateRows.split( ' ' ).length;
const numItems = numColumns * numRows;
return {
numItems,
style: {
gridTemplateColumns,
gridTemplateRows,
gap: getComputedCSS( blockElement, 'gap' ),
padding: getComputedCSS( blockElement, 'padding' ),
},
};
}
Loading

0 comments on commit 5e1f52b

Please sign in to comment.