Skip to content

Commit

Permalink
prep build 09/06
Browse files Browse the repository at this point in the history
  • Loading branch information
bph committed Sep 6, 2023
2 parents 9a21ea5 + 62b8de2 commit 6ece0ca
Show file tree
Hide file tree
Showing 81 changed files with 1,667 additions and 958 deletions.
32 changes: 2 additions & 30 deletions docs/how-to-guides/platform/custom-block-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,7 @@ return (
<Sidebar.InspectorFill>
<BlockInspector />
</Sidebar.InspectorFill>
<div className="editor-styles-wrapper">
<BlockEditorKeyboardShortcuts />
<WritingFlow>
<BlockList className="getdavesbe-block-editor__block-list" />
</WritingFlow>
</div>
<BlockCanvas height="400px" />
</BlockEditorProvider>
</div>
);
Expand Down Expand Up @@ -419,27 +414,6 @@ Here is roughly how this works together to render the list of blocks:

The `@wordpress/block-editor` package components are among the most complex and involved. Understanding them is crucial if you want to grasp how the editor functions at a fundamental level. Studying these components is strongly advised.

### Utility components in the custom block editor

Jumping back to your custom `<BlockEditor>` component, it is also worth noting the following "utility" components:

```js
// File: src/components/block-editor/index.js

<div className="editor-styles-wrapper">
<BlockEditorKeyboardShortcuts /> /* 1. */
<WritingFlow>
/* 2. */
<BlockList className="getdavesbe-block-editor__block-list" />
</WritingFlow>
</div>
```

These provide other important elements of functionality for the editor instance.

1. [`<BlockEditorKeyboardShortcuts />`](https://github.com/WordPress/gutenberg/blob/e38dbe958c04d8089695eb686d4f5caff2707505/packages/block-editor/src/components/keyboard-shortcuts/index.js) – Enables and usage of keyboard shortcuts within the editor
2. [`<WritingFlow>`](https://github.com/WordPress/gutenberg/blob/e38dbe958c04d8089695eb686d4f5caff2707505/packages/block-editor/src/components/writing-flow/index.js) – Handles selection, focus management, and navigation across blocks

## Reviewing the sidebar

Also within the render of the `<BlockEditor>`, is the `<Sidebar>` component.
Expand All @@ -453,9 +427,7 @@ return (
<Sidebar.InspectorFill> /* <-- SIDEBAR */
<BlockInspector />
</Sidebar.InspectorFill>
<div className="editor-styles-wrapper">
// snip
</div>
<BlockCanvas height="400px" />
</BlockEditorProvider>
</div>
);
Expand Down
6 changes: 6 additions & 0 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1979,6 +1979,12 @@
"markdown_source": "../docs/reference-guides/data/data-core-blocks.md",
"parent": "data"
},
{
"title": "The Commands Data",
"slug": "data-core-commands",
"markdown_source": "../docs/reference-guides/data/data-core-commands.md",
"parent": "data"
},
{
"title": "Customize Widgets",
"slug": "data-core-customize-widgets",
Expand Down
3 changes: 3 additions & 0 deletions docs/toc.json
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@
"docs/reference-guides/data/data-core-block-editor.md": []
},
{ "docs/reference-guides/data/data-core-blocks.md": [] },
{
"docs/reference-guides/data/data-core-commands.md": []
},
{
"docs/reference-guides/data/data-core-customize-widgets.md": []
},
Expand Down
9 changes: 8 additions & 1 deletion lib/block-supports/typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,14 @@ function gutenberg_get_computed_fluid_typography_value( $args = array() ) {

/**
* Returns a font-size value based on a given font-size preset.
* Takes into account fluid typography parameters and attempts to return a css formula depending on available, valid values.
* Takes into account fluid typography parameters and attempts to return a CSS
* formula depending on available, valid values.
*
* @since 6.1.0
* @since 6.1.1 Adjusted rules for min and max font sizes.
* @since 6.2.0 Added 'settings.typography.fluid.minFontSize' support.
* @since 6.3.0 Using layout.wideSize as max viewport width, and logarithmic scale factor to calculate minimum font scale.
* @since 6.4.0 Added configurable min and max viewport width values to the typography.fluid theme.json schema.
*
* @param array $preset {
* Required. fontSizes preset value as seen in theme.json.
Expand Down
2 changes: 1 addition & 1 deletion lib/experimental/auto-inserting-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ function gutenberg_register_auto_insert_rest_field() {
'auto_insert',
array(
'schema' => array(
'description' => __( 'Block types that may be automatically inserted near this block and the associated relative position where they are inserted.', 'gutenberg' ),
'description' => __( 'This block is automatically inserted near any occurence of the block types used as keys of this map, into a relative position given by the corresponding value.', 'gutenberg' ),
'patternProperties' => array(
'^[a-zA-Z0-9-]+/[a-zA-Z0-9-]+$' => array(
'type' => 'string',
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@
"fixtures:generate": "cross-env GENERATE_MISSING_FIXTURES=y npm run test:unit test/integration/full-content/ && npm run format test/integration/fixtures/blocks/*.json",
"fixtures:regenerate": "npm-run-all fixtures:clean fixtures:generate",
"format": "wp-scripts format",
"preformat:php": "npm run other:update-packages:php",
"format:php": "wp-env run --env-cwd='wp-content/plugins/gutenberg' cli composer run-script format",
"lint": "concurrently \"npm run lint:lockfile\" \"npm run lint:tsconfig\" \"npm run lint:js\" \"npm run lint:pkg-json\" \"npm run lint:css\"",
"lint:css": "wp-scripts lint-style \"**/*.scss\"",
Expand All @@ -291,7 +292,7 @@
"lint:lockfile": "node ./bin/validate-package-lock.js",
"lint:tsconfig": "node ./bin/validate-tsconfig.mjs",
"lint:md:docs": "wp-scripts lint-md-docs",
"prelint:php": "wp-env run --env-cwd='wp-content/plugins/gutenberg' cli composer update --no-interaction",
"prelint:php": "npm run other:update-packages:php",
"lint:php": "wp-env run --env-cwd='wp-content/plugins/gutenberg' cli composer run-script lint",
"lint:pkg-json": "wp-scripts lint-pkg-json . 'packages/*/package.json'",
"native": "npm run --prefix packages/react-native-editor",
Expand All @@ -300,6 +301,7 @@
"preother:check-local-changes": "npm run docs:build",
"other:check-local-changes": "node ./bin/check-local-changes.js",
"other:cherry-pick": "node ./bin/cherry-pick.mjs",
"other:update-packages:php": "wp-env run --env-cwd='wp-content/plugins/gutenberg' cli composer update --no-interaction",
"postinstall": "patch-package && node ./patches/patch-xcode.js",
"prepare": "husky install",
"prepublishOnly": "npm run clean:package-types && npm run build:packages",
Expand Down
36 changes: 33 additions & 3 deletions packages/block-editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ function MyEditorComponent() {
onChange={ ( blocks ) => updateBlocks( blocks ) }
>
<BlockTools>
<WritingFlow>
<BlockList />
</WritingFlow>
<BlockCanvas height="400px" />
</BlockTools>
</BlockEditorProvider>
);
Expand Down Expand Up @@ -118,6 +116,38 @@ _Returns_

- `WPElement`: Block Breadcrumb.

### BlockCanvas

BlockCanvas component is a component used to display the canvas of the block editor. What we call the canvas is an iframe containing the block list that you can manipulate. The component is also responsible of wiring up all the necessary hooks to enable the keyboard navigation across blocks in the editor and inject content styles into the iframe.

_Usage_

```jsx
function MyBlockEditor() {
const [ blocks, updateBlocks ] = useState( [] );
return (
<BlockEditorProvider
value={ blocks }
onInput={ updateBlocks }
onChange={ persistBlocks }
>
<BlockCanvas height="400px" />
</BlockEditorProvider>
);
}
```

_Parameters_

- _props_ `Object`: Component props.
- _props.height_ `string`: Canvas height, defaults to 300px.
- _props.styles_ `Array`: Content styles to inject into the iframe.
- _props.children_ `WPElement`: Content of the canvas, defaults to the BlockList component.

_Returns_

- `WPElement`: Block Breadcrumb.

### BlockColorsStyleSelector

Undocumented declaration.
Expand Down
99 changes: 99 additions & 0 deletions packages/block-editor/src/components/block-canvas/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/**
* WordPress dependencies
*/
import { useMergeRefs } from '@wordpress/compose';

/**
* Internal dependencies
*/
import BlockList from '../block-list';
import EditorStyles from '../editor-styles';
import Iframe from '../iframe';
import WritingFlow from '../writing-flow';
import { useMouseMoveTypingReset } from '../observe-typing';
import { useClipboardHandler } from '../copy-handler';

export function ExperimentalBlockCanvas( {
shouldIframe = true,
height = '300px',
children = <BlockList />,
styles,
contentRef: contentRefProp,
iframeProps,
} ) {
const resetTypingRef = useMouseMoveTypingReset();
const copyHandler = useClipboardHandler();
const contentRef = useMergeRefs( [ copyHandler, contentRefProp ] );

if ( ! shouldIframe ) {
return (
<>
<EditorStyles styles={ styles } />
<WritingFlow
ref={ contentRef }
className="editor-styles-wrapper"
tabIndex={ -1 }
style={ { height } }
>
{ children }
</WritingFlow>
</>
);
}

return (
<Iframe
{ ...iframeProps }
ref={ resetTypingRef }
contentRef={ contentRef }
style={ {
width: '100%',
height,
...iframeProps?.style,
} }
name="editor-canvas"
>
<EditorStyles styles={ styles } />
{ children }
</Iframe>
);
}

/**
* BlockCanvas component is a component used to display the canvas of the block editor.
* What we call the canvas is an iframe containing the block list that you can manipulate.
* The component is also responsible of wiring up all the necessary hooks to enable
* the keyboard navigation across blocks in the editor and inject content styles into the iframe.
*
* @example
*
* ```jsx
* function MyBlockEditor() {
* const [ blocks, updateBlocks ] = useState([]);
* return (
* <BlockEditorProvider
* value={ blocks }
* onInput={ updateBlocks }
* onChange={ persistBlocks }
* >
* <BlockCanvas height="400px" />
* </BlockEditorProvider>
* );
* }
* ```
*
* @param {Object} props Component props.
* @param {string} props.height Canvas height, defaults to 300px.
* @param {Array} props.styles Content styles to inject into the iframe.
* @param {WPElement} props.children Content of the canvas, defaults to the BlockList component.
* @return {WPElement} Block Breadcrumb.
*/
function BlockCanvas( { children, height, styles } ) {
return (
<ExperimentalBlockCanvas height={ height } styles={ styles }>
{ children }
</ExperimentalBlockCanvas>
);
}

export default BlockCanvas;
1 change: 1 addition & 0 deletions packages/block-editor/src/components/iframe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ function Iframe( {
<iframe
{ ...props }
style={ {
border: 0,
...props.style,
height: expand ? contentHeight : props.style?.height,
marginTop:
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export { default as __experimentalBlockAlignmentMatrixControl } from './block-al
export { default as BlockBreadcrumb } from './block-breadcrumb';
export { default as __experimentalUseBlockOverlayActive } from './block-content-overlay';
export { BlockContextProvider } from './block-context';
export { default as BlockCanvas } from './block-canvas';
export {
default as BlockControls,
BlockFormatControls,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/**
* WordPress dependencies
*/
import { useLayoutEffect, useMemo } from '@wordpress/element';
import { useLayoutEffect, useMemo, useState } from '@wordpress/element';
import { useSelect, useDispatch, useRegistry } from '@wordpress/data';
import deprecated from '@wordpress/deprecated';
import isShallowEqual from '@wordpress/is-shallow-equal';

/**
* Internal dependencies
Expand All @@ -15,6 +16,14 @@ import { getLayoutType } from '../../layouts';

const pendingSettingsUpdates = new WeakMap();

function useShallowMemo( value ) {
const [ prevValue, setPrevValue ] = useState( value );
if ( ! isShallowEqual( prevValue, value ) ) {
setPrevValue( value );
}
return prevValue;
}

/**
* This hook is a side effect which updates the block-editor store when changes
* happen to inner block settings. The given props are transformed into a
Expand Down Expand Up @@ -70,16 +79,12 @@ export default function useNestedSettingsUpdate(
[ clientId ]
);

// Memoize allowedBlocks and prioritisedInnerBlocks based on the contents
// of the arrays. Implementors often pass a new array on every render,
// Implementors often pass a new array on every render,
// and the contents of the arrays are just strings, so the entire array
// can be passed as dependencies.

const _allowedBlocks = useMemo(
() => allowedBlocks,
// eslint-disable-next-line react-hooks/exhaustive-deps
allowedBlocks
);
// can be passed as dependencies but We need to include the length of the array,
// otherwise if the arrays change length but the first elements are equal the comparison,
// does not works as expected.
const _allowedBlocks = useShallowMemo( allowedBlocks );

const _prioritizedInserterBlocks = useMemo(
() => prioritizedInserterBlocks,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,27 @@
* WordPress dependencies
*/
import { __experimentalToolsPanelContext as ToolsPanelContext } from '@wordpress/components';
import { useContext } from '@wordpress/element';
import { useContext, useMemo } from '@wordpress/element';

export default function BlockSupportSlotContainer( { Slot, ...props } ) {
export default function BlockSupportSlotContainer( {
Slot,
fillProps,
...props
} ) {
// Add the toolspanel context provider and value to existing fill props
const toolsPanelContext = useContext( ToolsPanelContext );
const computedFillProps = useMemo(
() => ( {
...( fillProps ?? {} ),
forwardedContext: [
...( fillProps?.forwardedContext ?? [] ),
[ ToolsPanelContext.Provider, { value: toolsPanelContext } ],
],
} ),
[ toolsPanelContext, fillProps ]
);

return (
<Slot { ...props } fillProps={ toolsPanelContext } bubblesVirtually />
<Slot { ...props } fillProps={ computedFillProps } bubblesVirtually />
);
}
Loading

0 comments on commit 6ece0ca

Please sign in to comment.