diff --git a/package-lock.json b/package-lock.json index 3547a50a074523..0b6c20509ea534 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16912,6 +16912,7 @@ "@wordpress/compose": "file:packages/compose", "@wordpress/deprecated": "file:packages/deprecated", "@wordpress/element": "file:packages/element", + "@wordpress/experiments": "file:packages/experiments", "@wordpress/is-shallow-equal": "file:packages/is-shallow-equal", "@wordpress/priority-queue": "file:packages/priority-queue", "@wordpress/redux-routine": "file:packages/redux-routine", @@ -22213,6 +22214,12 @@ "integrity": "sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw==", "dev": true }, + "follow-redirects": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.1.tgz", + "integrity": "sha512-HWqDgT7ZEkqRzBvc2s64vSZ/hfOceEol3ac/7tKwzuvEyWx3/4UegXh5oBOIotkGsObyk3xznnSRVADBgWSQVg==", + "dev": true + }, "forever-agent": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", @@ -22546,7 +22553,8 @@ "immediate": { "version": "3.0.6", "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz", - "integrity": "sha1-nbHb0Pr43m++D13V5Wu2BigN5ps=" + "integrity": "sha1-nbHb0Pr43m++D13V5Wu2BigN5ps=", + "dev": true }, "inflight": { "version": "1.0.6", @@ -22798,6 +22806,35 @@ "verror": "1.10.0" } }, + "jszip": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/jszip/-/jszip-3.6.0.tgz", + "integrity": "sha512-jgnQoG9LKnWO3mnVNBnfhkh0QknICd1FGSrXcgrl67zioyJ4wgx25o9ZqwNtrROSflGBCGYnJfjrIyRIby1OoQ==", + "dev": true, + "requires": { + "lie": "~3.3.0", + "pako": "~1.0.2", + "readable-stream": "~2.3.6", + "set-immediate-shim": "~1.0.1" + }, + "dependencies": { + "readable-stream": { + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + } + } + }, "keypather": { "version": "1.10.2", "resolved": "https://registry.npmjs.org/keypather/-/keypather-1.10.2.tgz", @@ -22870,6 +22907,7 @@ "version": "3.3.0", "resolved": "https://registry.npmjs.org/lie/-/lie-3.3.0.tgz", "integrity": "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==", + "dev": true, "requires": { "immediate": "~3.0.5" } @@ -24220,7 +24258,8 @@ "set-immediate-shim": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/set-immediate-shim/-/set-immediate-shim-1.0.1.tgz", - "integrity": "sha1-SysbJ+uAip+NzEgaWOXlb1mfP2E=" + "integrity": "sha1-SysbJ+uAip+NzEgaWOXlb1mfP2E=", + "dev": true }, "setprototypeof": { "version": "1.1.1", @@ -37550,12 +37589,6 @@ "resolved": "https://registry.npmjs.org/image-size/-/image-size-0.6.3.tgz", "integrity": "sha512-47xSUiQioGaB96nqtp5/q55m0aBQSQdyIloMOc/x+QVTDZLNmXE892IIDrJ0hM1A5vcNUDD5tDffkSP5lCaIIA==" }, - "immediate": { - "version": "3.0.6", - "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz", - "integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==", - "dev": true - }, "import-fresh": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.1.0.tgz", @@ -42360,18 +42393,6 @@ } } }, - "jszip": { - "version": "3.10.1", - "resolved": "https://registry.npmjs.org/jszip/-/jszip-3.10.1.tgz", - "integrity": "sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==", - "dev": true, - "requires": { - "lie": "~3.3.0", - "pako": "~1.0.2", - "readable-stream": "~2.3.6", - "setimmediate": "^1.0.5" - } - }, "junk": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/junk/-/junk-3.1.0.tgz", @@ -42510,15 +42531,6 @@ "type-check": "~0.3.2" } }, - "lie": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/lie/-/lie-3.3.0.tgz", - "integrity": "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==", - "dev": true, - "requires": { - "immediate": "~3.0.5" - } - }, "lilconfig": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-2.0.3.tgz", diff --git a/packages/block-editor/package.json b/packages/block-editor/package.json index 92a5ae12b53ae0..194462dc84006c 100644 --- a/packages/block-editor/package.json +++ b/packages/block-editor/package.json @@ -44,6 +44,7 @@ "@wordpress/deprecated": "file:../deprecated", "@wordpress/dom": "file:../dom", "@wordpress/element": "file:../element", + "@wordpress/experiments": "file:../experiments", "@wordpress/hooks": "file:../hooks", "@wordpress/html-entities": "file:../html-entities", "@wordpress/i18n": "file:../i18n", diff --git a/packages/block-editor/src/components/block-inspector/index.js b/packages/block-editor/src/components/block-inspector/index.js index 3accd8ee6babd3..e4dfe06df25c48 100644 --- a/packages/block-editor/src/components/block-inspector/index.js +++ b/packages/block-editor/src/components/block-inspector/index.js @@ -35,6 +35,12 @@ import BlockVariationTransforms from '../block-variation-transforms'; import useBlockDisplayInformation from '../use-block-display-information'; import { store as blockEditorStore } from '../../store'; import BlockIcon from '../block-icon'; +import { + unlock, + __experimentalAccessKey as blockEditorExperiments, +} from '../../experiments'; + +const { __unstableGetContentLockingParent } = unlock( blockEditorExperiments ); function useContentBlocks( blockTypes, block ) { const contenBlocksObjectAux = useMemo( () => { @@ -142,7 +148,6 @@ const BlockInspector = ( { showNoBlockSelectedMessage = true } ) => { getSelectedBlockClientId, getSelectedBlockCount, getBlockName, - __unstableGetContentLockingParent, getTemplateLock, } = select( blockEditorStore ); diff --git a/packages/block-editor/src/components/block-list/block.js b/packages/block-editor/src/components/block-list/block.js index da0cfd9bda481e..3599083d3fd5c9 100644 --- a/packages/block-editor/src/components/block-list/block.js +++ b/packages/block-editor/src/components/block-list/block.js @@ -18,7 +18,6 @@ import { isUnmodifiedDefaultBlock, serializeRawBlock, switchToBlockType, - store as blocksStore, } from '@wordpress/blocks'; import { withFilters } from '@wordpress/components'; import { @@ -40,6 +39,16 @@ import BlockCrashBoundary from './block-crash-boundary'; import BlockHtml from './block-html'; import { useBlockProps } from './use-block-props'; import { store as blockEditorStore } from '../../store'; +import { + unlock, + __experimentalAccessKey as blockEditorExperiments, +} from '../../experiments'; + +const { + __experimentalHasContentRoleAttribute, + __unstableGetContentLockingParent, + __unstableGetTemporarilyEditingAsBlocks, +} = unlock( blockEditorExperiments ); export const BlockListBlockContext = createContext(); @@ -102,20 +111,12 @@ function BlockListBlock( { isTemporarilyEditingAsBlocks, } = useSelect( ( select ) => { - const { - getSettings, - __unstableGetContentLockingParent, - getTemplateLock, - __unstableGetTemporarilyEditingAsBlocks, - } = select( blockEditorStore ); + const { getSettings, getTemplateLock } = select( blockEditorStore ); const _hasContentLockedParent = !! __unstableGetContentLockingParent( clientId ); return { themeSupportsLayout: getSettings().supportsLayout, - isContentBlock: - select( blocksStore ).__experimentalHasContentRoleAttribute( - name - ), + isContentBlock: __experimentalHasContentRoleAttribute( name ), hasContentLockedParent: _hasContentLockedParent, isContentLocking: getTemplateLock( clientId ) === 'contentOnly' && diff --git a/packages/block-editor/src/components/block-list/use-block-props/use-block-class-names.js b/packages/block-editor/src/components/block-list/use-block-props/use-block-class-names.js index fce94b85f91190..0889f637816e92 100644 --- a/packages/block-editor/src/components/block-list/use-block-props/use-block-class-names.js +++ b/packages/block-editor/src/components/block-list/use-block-props/use-block-class-names.js @@ -6,13 +6,19 @@ import classnames from 'classnames'; /** * WordPress dependencies */ -import { useSelect } from '@wordpress/data'; +import { + useSelect, + __experimentalAccessKey as dataExperiments, +} from '@wordpress/data'; import { isReusableBlock, getBlockType } from '@wordpress/blocks'; /** * Internal dependencies */ import { store as blockEditorStore } from '../../../store'; +import { unlock } from '../../../experiments'; + +const { __unstableSelectionHasUnmergeableBlock } = unlock( dataExperiments ); /** * Returns the class names used for the different states of the block. @@ -34,7 +40,6 @@ export function useBlockClassNames( clientId ) { hasSelectedInnerBlock, isTyping, __unstableIsFullySelected, - __unstableSelectionHasUnmergeableBlock, } = select( blockEditorStore ); const { outlineMode } = getSettings(); const isDragging = isBlockBeingDragged( clientId ); diff --git a/packages/block-editor/src/components/block-toolbar/index.js b/packages/block-editor/src/components/block-toolbar/index.js index 07d4e861f60947..989675199b6ffd 100644 --- a/packages/block-editor/src/components/block-toolbar/index.js +++ b/packages/block-editor/src/components/block-toolbar/index.js @@ -27,6 +27,12 @@ import BlockEditVisuallyButton from '../block-edit-visually-button'; import { useShowMoversGestures } from './utils'; import { store as blockEditorStore } from '../../store'; import __unstableBlockNameContext from './block-name-context'; +import { + unlock, + __experimentalAccessKey as blockEditorExperiments, +} from '../../experiments'; + +const { __unstableGetContentLockingParent } = unlock( blockEditorExperiments ); const BlockToolbar = ( { hideDragHandle } ) => { const { @@ -46,7 +52,6 @@ const BlockToolbar = ( { hideDragHandle } ) => { isBlockValid, getBlockRootClientId, getSettings, - __unstableGetContentLockingParent, } = select( blockEditorStore ); const selectedBlockClientIds = getSelectedBlockClientIds(); const selectedBlockClientId = selectedBlockClientIds[ 0 ]; diff --git a/packages/block-editor/src/components/block-tools/block-contextual-toolbar.js b/packages/block-editor/src/components/block-tools/block-contextual-toolbar.js index ba31043ada2dd8..72cbe92ade0ea8 100644 --- a/packages/block-editor/src/components/block-tools/block-contextual-toolbar.js +++ b/packages/block-editor/src/components/block-tools/block-contextual-toolbar.js @@ -16,16 +16,18 @@ import { useSelect } from '@wordpress/data'; import NavigableToolbar from '../navigable-toolbar'; import BlockToolbar from '../block-toolbar'; import { store as blockEditorStore } from '../../store'; +import { + unlock, + __experimentalAccessKey as blockEditorExperiments, +} from '../../experiments'; + +const { __unstableGetContentLockingParent } = unlock( blockEditorExperiments ); function BlockContextualToolbar( { focusOnMount, isFixed, ...props } ) { const { blockType, hasParents, showParentSelector } = useSelect( ( select ) => { - const { - getBlockName, - getBlockParents, - getSelectedBlockClientIds, - __unstableGetContentLockingParent, - } = select( blockEditorStore ); + const { getBlockName, getBlockParents, getSelectedBlockClientIds } = + select( blockEditorStore ); const { getBlockType } = select( blocksStore ); const selectedBlockClientIds = getSelectedBlockClientIds(); const selectedBlockClientId = selectedBlockClientIds[ 0 ]; diff --git a/packages/block-editor/src/experiments.js b/packages/block-editor/src/experiments.js new file mode 100644 index 00000000000000..799d9c7408238f --- /dev/null +++ b/packages/block-editor/src/experiments.js @@ -0,0 +1,42 @@ +/** + * WordPress dependencies + */ +import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/experiments'; +import { __experimentalAccessKey as dataExperiments } from '@wordpress/data'; + +/** + * Internal dependencies + */ +import { store } from './store'; +import { + __unstableSelectionHasUnmergeableBlock, + __unstableGetContentLockingParent, + __unstableGetTemporarilyEditingAsBlocks, +} from './store/selectors'; + +export const { register, unlock } = + __dangerousOptInToUnstableAPIsOnlyForCoreModules( + 'I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.', + '@wordpress/block-editor' + ); + +const { __experimentalPrivateSelector } = unlock( dataExperiments ); + +export const __experimentalAccessKey = register( { + // Follow-up on https://github.com/WordPress/gutenberg/pull/42934 + __unstableSelectionHasUnmergeableBlock: () => + __experimentalPrivateSelector( + store, + __unstableSelectionHasUnmergeableBlock + ), + + // Follow-up on https://github.com/WordPress/gutenberg/pull/43037 + __unstableGetContentLockingParent: ( ...args ) => + __experimentalPrivateSelector( store, () => + __unstableGetContentLockingParent( ...args ) + ), + __unstableGetTemporarilyEditingAsBlocks: ( ...args ) => + __experimentalPrivateSelector( store, () => + __unstableGetTemporarilyEditingAsBlocks( ...args ) + ), +} ); diff --git a/packages/block-editor/src/hooks/align.js b/packages/block-editor/src/hooks/align.js index d559d5d8ea585a..1df960fecb04fa 100644 --- a/packages/block-editor/src/hooks/align.js +++ b/packages/block-editor/src/hooks/align.js @@ -21,7 +21,12 @@ import { useSelect } from '@wordpress/data'; */ import { BlockControls, BlockAlignmentControl } from '../components'; import useAvailableAlignments from '../components/block-alignment-control/use-available-alignments'; -import { store as blockEditorStore } from '../store'; +import { + unlock, + __experimentalAccessKey as blockEditorExperiments, +} from '../experiments'; + +const { __unstableGetContentLockingParent } = unlock( blockEditorExperiments ); /** * An array which includes all possible valid alignments, @@ -132,14 +137,9 @@ export const withToolbarControls = createHigherOrderComponent( const validAlignments = useAvailableAlignments( blockAllowedAlignments ).map( ( { name } ) => name ); - const isContentLocked = useSelect( - ( select ) => { - return select( - blockEditorStore - ).__unstableGetContentLockingParent( props.clientId ); - }, - [ props.clientId ] - ); + const isContentLocked = useSelect( () => { + return __unstableGetContentLockingParent( props.clientId ); + }, [ props.clientId ] ); if ( ! validAlignments.length || isContentLocked ) { return blockEdit; } diff --git a/packages/block-editor/src/hooks/content-lock-ui.js b/packages/block-editor/src/hooks/content-lock-ui.js index b373c01422e995..a07a8f71b80e09 100644 --- a/packages/block-editor/src/hooks/content-lock-ui.js +++ b/packages/block-editor/src/hooks/content-lock-ui.js @@ -13,6 +13,16 @@ import { useEffect, useRef, useCallback } from '@wordpress/element'; */ import { store as blockEditorStore } from '../store'; import { BlockControls } from '../components'; +import { + unlock, + __experimentalAccessKey as blockEditorExperiments, +} from '../experiments'; + +const { + __unstableGetContentLockingParent, + __unstableGetTemporarilyEditingAsBlocks, +} = unlock( blockEditorExperiments ); + /** * External dependencies */ @@ -48,11 +58,7 @@ export const withBlockControls = createHigherOrderComponent( const focusModeToRevert = useRef(); const { templateLock, isLockedByParent, isEditingAsBlocks } = useSelect( ( select ) => { - const { - __unstableGetContentLockingParent, - getTemplateLock, - __unstableGetTemporarilyEditingAsBlocks, - } = select( blockEditorStore ); + const { getTemplateLock } = select( blockEditorStore ); return { templateLock: getTemplateLock( props.clientId ), isLockedByParent: !! __unstableGetContentLockingParent( diff --git a/packages/block-editor/src/hooks/duotone.js b/packages/block-editor/src/hooks/duotone.js index a33ad059cb6653..5af140296ea524 100644 --- a/packages/block-editor/src/hooks/duotone.js +++ b/packages/block-editor/src/hooks/duotone.js @@ -28,7 +28,12 @@ import { __unstableDuotoneStylesheet as DuotoneStylesheet, __unstableDuotoneUnsetStylesheet as DuotoneUnsetStylesheet, } from '../components/duotone'; -import { store as blockEditorStore } from '../store'; +import { + unlock, + __experimentalAccessKey as blockEditorExperiments, +} from '../experiments'; + +const { __unstableGetContentLockingParent } = unlock( blockEditorExperiments ); const EMPTY_ARRAY = []; @@ -159,14 +164,9 @@ const withDuotoneControls = createHigherOrderComponent( props.name, 'color.__experimentalDuotone' ); - const isContentLocked = useSelect( - ( select ) => { - return select( - blockEditorStore - ).__unstableGetContentLockingParent( props.clientId ); - }, - [ props.clientId ] - ); + const isContentLocked = useSelect( () => { + return __unstableGetContentLockingParent( props.clientId ); + }, [ props.clientId ] ); return ( <> diff --git a/packages/block-editor/src/index.js b/packages/block-editor/src/index.js index 1c81c910b21e12..67b8e9f69e7f4a 100644 --- a/packages/block-editor/src/index.js +++ b/packages/block-editor/src/index.js @@ -20,3 +20,4 @@ export * from './elements'; export * from './utils'; export { storeConfig, store } from './store'; export { SETTINGS_DEFAULTS } from './store/defaults'; +export { __experimentalAccessKey } from './experiments'; diff --git a/packages/block-editor/src/store/index.js b/packages/block-editor/src/store/index.js index a4fc9f5b99a06f..5f5a268c7398f3 100644 --- a/packages/block-editor/src/store/index.js +++ b/packages/block-editor/src/store/index.js @@ -11,6 +11,13 @@ import * as selectors from './selectors'; import * as actions from './actions'; import { STORE_NAME } from './constants'; +const { + __unstableSelectionHasUnmergeableBlock, + __unstableGetContentLockingParent, + __unstableGetTemporarilyEditingAsBlocks, + ...stableSelectors +} = selectors; + /** * Block editor data store configuration. * @@ -18,7 +25,7 @@ import { STORE_NAME } from './constants'; */ export const storeConfig = { reducer, - selectors, + selectors: stableSelectors, actions, }; diff --git a/packages/block-library/package.json b/packages/block-library/package.json index b99743fd0dcbaf..1b2a5b5c0a91e5 100644 --- a/packages/block-library/package.json +++ b/packages/block-library/package.json @@ -45,6 +45,7 @@ "@wordpress/deprecated": "file:../deprecated", "@wordpress/dom": "file:../dom", "@wordpress/element": "file:../element", + "@wordpress/experiments": "file:../experiments", "@wordpress/hooks": "file:../hooks", "@wordpress/html-entities": "file:../html-entities", "@wordpress/i18n": "file:../i18n", diff --git a/packages/block-library/src/experiments.js b/packages/block-library/src/experiments.js new file mode 100644 index 00000000000000..fd0a1fb3cbb8ad --- /dev/null +++ b/packages/block-library/src/experiments.js @@ -0,0 +1,10 @@ +/** + * WordPress dependencies + */ +import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/experiments'; + +export const { register, unlock } = + __dangerousOptInToUnstableAPIsOnlyForCoreModules( + 'I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.', + '@wordpress/block-editor' + ); diff --git a/packages/block-library/src/image/edit.js b/packages/block-library/src/image/edit.js index baba2cee24ec33..136c60171d3441 100644 --- a/packages/block-library/src/image/edit.js +++ b/packages/block-library/src/image/edit.js @@ -18,6 +18,7 @@ import { useBlockProps, store as blockEditorStore, __experimentalUseBorderProps as useBorderProps, + __experimentalAccessKey as blockEditorExperiments, } from '@wordpress/block-editor'; import { useEffect, useRef, useState } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; @@ -28,6 +29,9 @@ import { store as noticesStore } from '@wordpress/notices'; * Internal dependencies */ import Image from './image'; +import { unlock } from '../experiments'; + +const { __unstableGetContentLockingParent } = unlock( blockEditorExperiments ); // Much of this description is duplicated from MediaPlaceholder. const placeholder = ( content ) => { @@ -139,8 +143,7 @@ export function ImageEdit( { const ref = useRef(); const { imageDefaultSize, mediaUpload, isContentLocked } = useSelect( ( select ) => { - const { getSettings, __unstableGetContentLockingParent } = - select( blockEditorStore ); + const { getSettings } = select( blockEditorStore ); const settings = getSettings(); return { imageDefaultSize: settings.imageDefaultSize, diff --git a/packages/block-library/src/media-text/edit.js b/packages/block-library/src/media-text/edit.js index 5a88830d385d18..2ea9a02d64813d 100644 --- a/packages/block-library/src/media-text/edit.js +++ b/packages/block-library/src/media-text/edit.js @@ -16,6 +16,7 @@ import { useInnerBlocksProps, InspectorControls, useBlockProps, + __experimentalAccessKey as blockEditorExperiments, __experimentalImageURLInputUI as ImageURLInputUI, __experimentalImageSizeControl as ImageSizeControl, store as blockEditorStore, @@ -38,6 +39,9 @@ import { store as coreStore } from '@wordpress/core-data'; */ import MediaContainer from './media-container'; import { DEFAULT_MEDIA_SIZE_SLUG } from './constants'; +import { unlock } from '../experiments'; + +const { __unstableGetContentLockingParent } = unlock( blockEditorExperiments ); /** * Constants @@ -159,8 +163,7 @@ function MediaTextEdit( { attributes, isSelected, setAttributes, clientId } ) { const { imageSizes, image, isContentLocked } = useSelect( ( select ) => { - const { __unstableGetContentLockingParent, getSettings } = - select( blockEditorStore ); + const { getSettings } = select( blockEditorStore ); return { isContentLocked: !! __unstableGetContentLockingParent( clientId ), diff --git a/packages/block-library/src/media-text/experiments.js b/packages/block-library/src/media-text/experiments.js new file mode 100644 index 00000000000000..fd0a1fb3cbb8ad --- /dev/null +++ b/packages/block-library/src/media-text/experiments.js @@ -0,0 +1,10 @@ +/** + * WordPress dependencies + */ +import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/experiments'; + +export const { register, unlock } = + __dangerousOptInToUnstableAPIsOnlyForCoreModules( + 'I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.', + '@wordpress/block-editor' + ); diff --git a/packages/blocks/package.json b/packages/blocks/package.json index bd03c1b7dfd574..4718f88a391fd3 100644 --- a/packages/blocks/package.json +++ b/packages/blocks/package.json @@ -36,6 +36,7 @@ "@wordpress/deprecated": "file:../deprecated", "@wordpress/dom": "file:../dom", "@wordpress/element": "file:../element", + "@wordpress/experiments": "file:../experiments", "@wordpress/hooks": "file:../hooks", "@wordpress/html-entities": "file:../html-entities", "@wordpress/i18n": "file:../i18n", diff --git a/packages/blocks/src/experiments.js b/packages/blocks/src/experiments.js new file mode 100644 index 00000000000000..52e0eb9f64ca9d --- /dev/null +++ b/packages/blocks/src/experiments.js @@ -0,0 +1,27 @@ +/** + * WordPress dependencies + */ +import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/experiments'; +import { __experimentalAccessKey as dataExperiments } from '@wordpress/data'; + +/** + * Internal dependencies + */ +import { store } from './store'; +import { __experimentalHasContentRoleAttribute } from './store/selectors'; + +export const { register, unlock } = + __dangerousOptInToUnstableAPIsOnlyForCoreModules( + 'I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.', + '@wordpress/blocks' + ); + +const { __experimentalPrivateSelector } = unlock( dataExperiments ); + +export const __experimentalAccessKey = register( { + // Follow-up on https://github.com/WordPress/gutenberg/pull/42934 + __experimentalHasContentRoleAttribute: ( ...args ) => + __experimentalPrivateSelector( store, () => + __experimentalHasContentRoleAttribute( ...args ) + ), +} ); diff --git a/packages/blocks/src/store/index.js b/packages/blocks/src/store/index.js index 6d2dc7c822dbde..5e00f82c3bba5d 100644 --- a/packages/blocks/src/store/index.js +++ b/packages/blocks/src/store/index.js @@ -11,6 +11,8 @@ import * as selectors from './selectors'; import * as actions from './actions'; import { STORE_NAME } from './constants'; +const { __experimentalHasContentRoleAttribute, ...stableSelectors } = selectors; + /** * Store definition for the blocks namespace. * @@ -20,7 +22,7 @@ import { STORE_NAME } from './constants'; */ export const store = createReduxStore( STORE_NAME, { reducer, - selectors, + selectors: stableSelectors, actions, } ); diff --git a/packages/data/package.json b/packages/data/package.json index f5e3e17aefc50c..21037b97f2c1fc 100644 --- a/packages/data/package.json +++ b/packages/data/package.json @@ -32,6 +32,7 @@ "@wordpress/compose": "file:../compose", "@wordpress/deprecated": "file:../deprecated", "@wordpress/element": "file:../element", + "@wordpress/experiments": "file:../experiments", "@wordpress/is-shallow-equal": "file:../is-shallow-equal", "@wordpress/priority-queue": "file:../priority-queue", "@wordpress/redux-routine": "file:../redux-routine", diff --git a/packages/data/src/index.js b/packages/data/src/index.js index 91675d48c0354d..8145cacde2efc5 100644 --- a/packages/data/src/index.js +++ b/packages/data/src/index.js @@ -3,6 +3,11 @@ */ import turboCombineReducers from 'turbo-combine-reducers'; +/** + * WordPress dependencies + */ +import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/experiments'; + /** * Internal dependencies */ @@ -229,3 +234,20 @@ export const use = defaultRegistry.use; * @param {StoreDescriptor} store Store descriptor. */ export const register = defaultRegistry.register; + +const experimentalAPIs = __dangerousOptInToUnstableAPIsOnlyForCoreModules( + 'I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.', + '@wordpress/data' +); + +function __experimentalPrivateSelector( { name }, selector ) { + return defaultRegistry.stores[ name ].store.select( selector ); +} +function __experimentalPrivateDispatch( { name }, actionThunk ) { + return defaultRegistry.stores[ name ].store.dispatch( actionThunk ); +} + +export const __experimentalAccessKey = experimentalAPIs.register( { + __experimentalPrivateSelector, + __experimentalPrivateDispatch, +} );