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

Export off canvas editor via experiments package #47465

Merged
merged 6 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package-lock.json

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

1 change: 0 additions & 1 deletion packages/block-editor/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export { default as __experimentalLinkControlSearchResults } from './link-contro
export { default as __experimentalLinkControlSearchItem } from './link-control/search-item';
export { default as LineHeightControl } from './line-height-control';
export { default as __experimentalListView } from './list-view';
export { default as __experimentalOffCanvasEditor } from './off-canvas-editor';
export { default as MediaReplaceFlow } from './media-replace-flow';
export { default as MediaPlaceholder } from './media-placeholder';
export { default as MediaUpload } from './media-upload';
Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/src/experiments.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/exp
*/
import * as globalStyles from './components/global-styles';
import { ExperimentalBlockEditorProvider } from './components/provider';
import { default as __experimentalOffCanvasEditor } from './components/off-canvas-editor';
draganescu marked this conversation as resolved.
Show resolved Hide resolved

export const { lock, unlock } =
__dangerousOptInToUnstableAPIsOnlyForCoreModules(
Expand All @@ -22,4 +23,5 @@ export const experiments = {};
lock( experiments, {
...globalStyles,
ExperimentalBlockEditorProvider,
__experimentalOffCanvasEditor,
draganescu marked this conversation as resolved.
Show resolved Hide resolved
} );
1 change: 1 addition & 0 deletions packages/block-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@wordpress/dom": "file:../dom",
"@wordpress/element": "file:../element",
"@wordpress/escape-html": "file:../escape-html",
"@wordpress/experiments": "file:../experiments",
"@wordpress/hooks": "file:../hooks",
"@wordpress/html-entities": "file:../html-entities",
"@wordpress/i18n": "file:../i18n",
Expand Down
10 changes: 10 additions & 0 deletions packages/block-library/src/experiments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* WordPress dependencies
*/
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/experiments';

export const { lock, unlock } =
__dangerousOptInToUnstableAPIsOnlyForCoreModules(
'I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.',
'@wordpress/block-library'
);
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import {
__experimentalOffCanvasEditor as OffCanvasEditor,
experiments as blockEditorExperiments,
InspectorControls,
store as blockEditorStore,
} from '@wordpress/block-editor';
Expand All @@ -21,6 +21,7 @@ import { __ } from '@wordpress/i18n';
import ManageMenusButton from './manage-menus-button';
import NavigationMenuSelector from './navigation-menu-selector';
import { LeafMoreMenu } from '../leaf-more-menu';
import { unlock } from '../../experiments';

/* translators: %s: The name of a menu. */
const actionLabel = __( "Switch to '%s'" );
Expand All @@ -31,6 +32,9 @@ const ExperimentMainContent = ( {
isLoading,
isNavigationMenuMissing,
} ) => {
const { __experimentalOffCanvasEditor: OffCanvasEditor } = unlock(
blockEditorExperiments
);
// Provide a hierarchy of clientIds for the given Navigation block (clientId).
// This is required else the list view will display the entire block tree.
const clientIdsTree = useSelect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
* WordPress dependencies
*/
import {
__experimentalOffCanvasEditor as OffCanvasEditor,
experiments as blockEditorExperiments,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { useEffect } from '@wordpress/element';
import { useDispatch } from '@wordpress/data';

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

const ALLOWED_BLOCKS = {
'core/navigation': [
'core/navigation-link',
Expand All @@ -34,6 +39,10 @@ const ALLOWED_BLOCKS = {
export default function NavigationMenu( { innerBlocks } ) {
const { updateBlockListSettings } = useDispatch( blockEditorStore );

const { __experimentalOffCanvasEditor: OffCanvasEditor } = unlock(
blockEditorExperiments
);

//TODO: Block settings are normally updated as a side effect of rendering InnerBlocks in BlockList
//Think through a better way of doing this, possible with adding allowed blocks to block library metadata
useEffect( () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/experiments/src/implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const CORE_MODULES_USING_EXPERIMENTS = [
'@wordpress/edit-site',
'@wordpress/edit-post',
'@wordpress/edit-widgets',
'@wordpress/edit-navigation',
'@wordpress/block-library',
];

/**
Expand Down