From 9bb8b5723ae30845718813c0020738cfc92fdb24 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Mon, 17 Jul 2023 10:01:12 +1200 Subject: [PATCH 01/11] Remove `reusable` text from menu once rename hint has been dismissed --- packages/block-editor/README.md | 4 ++++ packages/block-editor/src/components/index.js | 5 ++++- .../inserter/reusable-block-rename-hint.js | 8 ++++++++ .../reusable-block-convert-button.js | 16 ++++++++++------ 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/packages/block-editor/README.md b/packages/block-editor/README.md index 937bfea2f49656..7bb33e2be40206 100644 --- a/packages/block-editor/README.md +++ b/packages/block-editor/README.md @@ -854,6 +854,10 @@ _Parameters_ - _props_ `Object`: Optional. Props to pass to the element. Must contain the ref if one is defined. - _options_ `Object`: Optional. Inner blocks options. +### useReusableBlocksRenameHint + +Undocumented declaration. + ### useSetting Hook that retrieves the given setting for the block instance in use. diff --git a/packages/block-editor/src/components/index.js b/packages/block-editor/src/components/index.js index db93f112a366d3..57c306cb7f9e8f 100644 --- a/packages/block-editor/src/components/index.js +++ b/packages/block-editor/src/components/index.js @@ -169,4 +169,7 @@ export { default as useSetting } from './use-setting'; /* * The following rename hint component can be removed in 6.4. */ -export { default as ReusableBlocksRenameHint } from './inserter/reusable-block-rename-hint'; +export { + default as ReusableBlocksRenameHint, + useReusableBlocksRenameHint, +} from './inserter/reusable-block-rename-hint'; diff --git a/packages/block-editor/src/components/inserter/reusable-block-rename-hint.js b/packages/block-editor/src/components/inserter/reusable-block-rename-hint.js index d4702eb1372831..460c4f4a3db3db 100644 --- a/packages/block-editor/src/components/inserter/reusable-block-rename-hint.js +++ b/packages/block-editor/src/components/inserter/reusable-block-rename-hint.js @@ -11,6 +11,14 @@ import { store as preferencesStore } from '@wordpress/preferences'; const PREFERENCE_NAME = 'isResuableBlocksrRenameHintVisible'; +export function useReusableBlocksRenameHint() { + return useSelect( + ( select ) => + select( preferencesStore ).get( 'core', PREFERENCE_NAME ) ?? true, + [] + ); +} + export default function ReusableBlocksRenameHint() { const isReusableBlocksRenameHint = useSelect( ( select ) => diff --git a/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js b/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js index 981776880a1374..7a37ed8cfab206 100644 --- a/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js +++ b/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js @@ -6,6 +6,7 @@ import { BlockSettingsMenuControls, store as blockEditorStore, ReusableBlocksRenameHint, + useReusableBlocksRenameHint, } from '@wordpress/block-editor'; import { useCallback, useState } from '@wordpress/element'; import { @@ -40,7 +41,8 @@ export default function ReusableBlockConvertButton( { clientIds, rootClientId, } ) { - const [ syncType, setSyncType ] = useState( 'unsynced' ); + const showRenameHint = useReusableBlocksRenameHint(); + const [ syncType, setSyncType ] = useState( undefined ); const [ isModalOpen, setIsModalOpen ] = useState( false ); const [ title, setTitle ] = useState( '' ); const canConvert = useSelect( @@ -97,7 +99,7 @@ export default function ReusableBlockConvertButton( { syncType ); createSuccessNotice( - syncType === 'fully' + ! syncType ? sprintf( // translators: %s: the name the user has given to the pattern. __( 'Synced Pattern created: %s' ), @@ -141,7 +143,9 @@ export default function ReusableBlockConvertButton( { icon={ symbol } onClick={ () => setIsModalOpen( true ) } > - { __( 'Create pattern/reusable block' ) } + { showRenameHint + ? __( 'Create pattern/reusable block' ) + : __( 'Create pattern' ) } { isModalOpen && ( { setSyncType( - syncType === 'fully' + ! syncType ? 'unsynced' - : 'fully' + : undefined ); } } /> From c45e3f50ad304a43c4a7faa464123381aa30ddd6 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Mon, 17 Jul 2023 11:26:44 +1200 Subject: [PATCH 02/11] Fix e2e tests --- packages/e2e-test-utils/src/create-reusable-block.js | 2 +- .../editor/various/block-editor-keyboard-shortcuts.test.js | 2 +- .../e2e-tests/specs/editor/various/reusable-blocks.test.js | 4 ++-- packages/reusable-blocks/src/store/actions.js | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/e2e-test-utils/src/create-reusable-block.js b/packages/e2e-test-utils/src/create-reusable-block.js index 97146381544037..446cf169b5c39c 100644 --- a/packages/e2e-test-utils/src/create-reusable-block.js +++ b/packages/e2e-test-utils/src/create-reusable-block.js @@ -24,7 +24,7 @@ export const createReusableBlock = async ( content, title ) => { await page.keyboard.type( content ); await clickBlockToolbarButton( 'Options' ); - await clickMenuItem( 'Create pattern/reusable block' ); + await clickMenuItem( 'Create pattern' ); const nameInput = await page.waitForSelector( reusableBlockNameInputSelector ); diff --git a/packages/e2e-tests/specs/editor/various/block-editor-keyboard-shortcuts.test.js b/packages/e2e-tests/specs/editor/various/block-editor-keyboard-shortcuts.test.js index 3be73830a42991..24e8e3104aaaa2 100644 --- a/packages/e2e-tests/specs/editor/various/block-editor-keyboard-shortcuts.test.js +++ b/packages/e2e-tests/specs/editor/various/block-editor-keyboard-shortcuts.test.js @@ -90,7 +90,7 @@ describe( 'block editor keyboard shortcuts', () => { } ); it( 'should prevent deleting multiple selected blocks from inputs', async () => { await clickBlockToolbarButton( 'Options' ); - await clickMenuItem( 'Create pattern/reusable block' ); + await clickMenuItem( 'Create pattern' ); const reusableBlockNameInputSelector = '.reusable-blocks-menu-items__convert-modal .components-text-control__input'; const nameInput = await page.waitForSelector( diff --git a/packages/e2e-tests/specs/editor/various/reusable-blocks.test.js b/packages/e2e-tests/specs/editor/various/reusable-blocks.test.js index 2f237822b1ccc8..551ce2f4b895f8 100644 --- a/packages/e2e-tests/specs/editor/various/reusable-blocks.test.js +++ b/packages/e2e-tests/specs/editor/various/reusable-blocks.test.js @@ -197,7 +197,7 @@ describe( 'Reusable blocks', () => { // Convert block to a reusable block. await clickBlockToolbarButton( 'Options' ); - await clickMenuItem( 'Create pattern/reusable block' ); + await clickMenuItem( 'Create pattern' ); // Set title. const nameInput = await page.waitForSelector( @@ -383,7 +383,7 @@ describe( 'Reusable blocks', () => { // Convert to reusable. await clickBlockToolbarButton( 'Options' ); - await clickMenuItem( 'Create pattern/reusable block' ); + await clickMenuItem( 'Create pattern' ); const nameInput = await page.waitForSelector( reusableBlockNameInputSelector ); diff --git a/packages/reusable-blocks/src/store/actions.js b/packages/reusable-blocks/src/store/actions.js index 17a2e83d5e776a..292a3082146aaa 100644 --- a/packages/reusable-blocks/src/store/actions.js +++ b/packages/reusable-blocks/src/store/actions.js @@ -42,9 +42,9 @@ export const __experimentalConvertBlockToStatic = /** * Returns a generator converting one or more static blocks into a pattern. * - * @param {string[]} clientIds The client IDs of the block to detach. - * @param {string} title Pattern title. - * @param {'fully'|'unsynced'} syncType They way block is synced, current 'fully' and 'unsynced'. + * @param {string[]} clientIds The client IDs of the block to detach. + * @param {string} title Pattern title. + * @param {undefined|'unsynced'} syncType They way block is synced, current undefined (synced) and 'unsynced'. */ export const __experimentalConvertBlocksToReusable = ( clientIds, title, syncType ) => From bfad338fec0024ae10d41847271ce46f1b53b140 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Mon, 17 Jul 2023 12:15:59 +1200 Subject: [PATCH 03/11] Revert "Fix e2e tests" This reverts commit c45e3f50ad304a43c4a7faa464123381aa30ddd6. --- packages/e2e-test-utils/src/create-reusable-block.js | 2 +- .../editor/various/block-editor-keyboard-shortcuts.test.js | 2 +- .../e2e-tests/specs/editor/various/reusable-blocks.test.js | 4 ++-- packages/reusable-blocks/src/store/actions.js | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/e2e-test-utils/src/create-reusable-block.js b/packages/e2e-test-utils/src/create-reusable-block.js index 446cf169b5c39c..97146381544037 100644 --- a/packages/e2e-test-utils/src/create-reusable-block.js +++ b/packages/e2e-test-utils/src/create-reusable-block.js @@ -24,7 +24,7 @@ export const createReusableBlock = async ( content, title ) => { await page.keyboard.type( content ); await clickBlockToolbarButton( 'Options' ); - await clickMenuItem( 'Create pattern' ); + await clickMenuItem( 'Create pattern/reusable block' ); const nameInput = await page.waitForSelector( reusableBlockNameInputSelector ); diff --git a/packages/e2e-tests/specs/editor/various/block-editor-keyboard-shortcuts.test.js b/packages/e2e-tests/specs/editor/various/block-editor-keyboard-shortcuts.test.js index 24e8e3104aaaa2..3be73830a42991 100644 --- a/packages/e2e-tests/specs/editor/various/block-editor-keyboard-shortcuts.test.js +++ b/packages/e2e-tests/specs/editor/various/block-editor-keyboard-shortcuts.test.js @@ -90,7 +90,7 @@ describe( 'block editor keyboard shortcuts', () => { } ); it( 'should prevent deleting multiple selected blocks from inputs', async () => { await clickBlockToolbarButton( 'Options' ); - await clickMenuItem( 'Create pattern' ); + await clickMenuItem( 'Create pattern/reusable block' ); const reusableBlockNameInputSelector = '.reusable-blocks-menu-items__convert-modal .components-text-control__input'; const nameInput = await page.waitForSelector( diff --git a/packages/e2e-tests/specs/editor/various/reusable-blocks.test.js b/packages/e2e-tests/specs/editor/various/reusable-blocks.test.js index 551ce2f4b895f8..2f237822b1ccc8 100644 --- a/packages/e2e-tests/specs/editor/various/reusable-blocks.test.js +++ b/packages/e2e-tests/specs/editor/various/reusable-blocks.test.js @@ -197,7 +197,7 @@ describe( 'Reusable blocks', () => { // Convert block to a reusable block. await clickBlockToolbarButton( 'Options' ); - await clickMenuItem( 'Create pattern' ); + await clickMenuItem( 'Create pattern/reusable block' ); // Set title. const nameInput = await page.waitForSelector( @@ -383,7 +383,7 @@ describe( 'Reusable blocks', () => { // Convert to reusable. await clickBlockToolbarButton( 'Options' ); - await clickMenuItem( 'Create pattern' ); + await clickMenuItem( 'Create pattern/reusable block' ); const nameInput = await page.waitForSelector( reusableBlockNameInputSelector ); diff --git a/packages/reusable-blocks/src/store/actions.js b/packages/reusable-blocks/src/store/actions.js index 292a3082146aaa..17a2e83d5e776a 100644 --- a/packages/reusable-blocks/src/store/actions.js +++ b/packages/reusable-blocks/src/store/actions.js @@ -42,9 +42,9 @@ export const __experimentalConvertBlockToStatic = /** * Returns a generator converting one or more static blocks into a pattern. * - * @param {string[]} clientIds The client IDs of the block to detach. - * @param {string} title Pattern title. - * @param {undefined|'unsynced'} syncType They way block is synced, current undefined (synced) and 'unsynced'. + * @param {string[]} clientIds The client IDs of the block to detach. + * @param {string} title Pattern title. + * @param {'fully'|'unsynced'} syncType They way block is synced, current 'fully' and 'unsynced'. */ export const __experimentalConvertBlocksToReusable = ( clientIds, title, syncType ) => From bd2d8fef4cdc35ca73251bd3e5cf28d5d4c4c8c9 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Mon, 17 Jul 2023 12:19:42 +1200 Subject: [PATCH 04/11] Fix doc comment --- packages/reusable-blocks/src/store/actions.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/reusable-blocks/src/store/actions.js b/packages/reusable-blocks/src/store/actions.js index 17a2e83d5e776a..292a3082146aaa 100644 --- a/packages/reusable-blocks/src/store/actions.js +++ b/packages/reusable-blocks/src/store/actions.js @@ -42,9 +42,9 @@ export const __experimentalConvertBlockToStatic = /** * Returns a generator converting one or more static blocks into a pattern. * - * @param {string[]} clientIds The client IDs of the block to detach. - * @param {string} title Pattern title. - * @param {'fully'|'unsynced'} syncType They way block is synced, current 'fully' and 'unsynced'. + * @param {string[]} clientIds The client IDs of the block to detach. + * @param {string} title Pattern title. + * @param {undefined|'unsynced'} syncType They way block is synced, current undefined (synced) and 'unsynced'. */ export const __experimentalConvertBlocksToReusable = ( clientIds, title, syncType ) => From 8a94de4cdd45a45241212ba4afaa6947816c76a3 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Mon, 17 Jul 2023 12:29:15 +1200 Subject: [PATCH 05/11] Another attempt to fix e2e tests --- packages/e2e-test-utils/src/create-reusable-block.js | 4 ---- .../e2e-tests/specs/editor/various/reusable-blocks.test.js | 6 ------ 2 files changed, 10 deletions(-) diff --git a/packages/e2e-test-utils/src/create-reusable-block.js b/packages/e2e-test-utils/src/create-reusable-block.js index 97146381544037..860b5ac5660eb4 100644 --- a/packages/e2e-test-utils/src/create-reusable-block.js +++ b/packages/e2e-test-utils/src/create-reusable-block.js @@ -15,8 +15,6 @@ import { canvas } from './canvas'; export const createReusableBlock = async ( content, title ) => { const reusableBlockNameInputSelector = '.reusable-blocks-menu-items__convert-modal .components-text-control__input'; - const syncToggleSelector = - '.reusable-blocks-menu-items__convert-modal .components-form-toggle__input'; const syncToggleSelectorChecked = '.reusable-blocks-menu-items__convert-modal .components-form-toggle.is-checked'; // Insert a paragraph block @@ -31,8 +29,6 @@ export const createReusableBlock = async ( content, title ) => { await nameInput.click(); await page.keyboard.type( title ); - const syncToggle = await page.waitForSelector( syncToggleSelector ); - syncToggle.click(); await page.waitForSelector( syncToggleSelectorChecked ); await page.keyboard.press( 'Enter' ); diff --git a/packages/e2e-tests/specs/editor/various/reusable-blocks.test.js b/packages/e2e-tests/specs/editor/various/reusable-blocks.test.js index 2f237822b1ccc8..1fc9217b4a77c0 100644 --- a/packages/e2e-tests/specs/editor/various/reusable-blocks.test.js +++ b/packages/e2e-tests/specs/editor/various/reusable-blocks.test.js @@ -23,8 +23,6 @@ const reusableBlockNameInputSelector = '.reusable-blocks-menu-items__convert-modal .components-text-control__input'; const reusableBlockInspectorNameInputSelector = '.block-editor-block-inspector .components-text-control__input'; -const syncToggleSelector = - '.reusable-blocks-menu-items__convert-modal .components-form-toggle__input'; const syncToggleSelectorChecked = '.reusable-blocks-menu-items__convert-modal .components-form-toggle.is-checked'; @@ -205,8 +203,6 @@ describe( 'Reusable blocks', () => { ); await nameInput.click(); await page.keyboard.type( 'Multi-selection reusable block' ); - const syncToggle = await page.waitForSelector( syncToggleSelector ); - syncToggle.click(); await page.waitForSelector( syncToggleSelectorChecked ); await page.keyboard.press( 'Enter' ); @@ -389,8 +385,6 @@ describe( 'Reusable blocks', () => { ); await nameInput.click(); await page.keyboard.type( 'Block with styles' ); - const syncToggle = await page.waitForSelector( syncToggleSelector ); - syncToggle.click(); await page.waitForSelector( syncToggleSelectorChecked ); await page.keyboard.press( 'Enter' ); const reusableBlock = await canvas().waitForSelector( From b48ecf11560d6bceb58eb7de397340c3189cf7b6 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Mon, 17 Jul 2023 12:47:31 +1200 Subject: [PATCH 06/11] Add doc comment to explain temporary nature of component and hook. --- .../components/inserter/reusable-block-rename-hint.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/inserter/reusable-block-rename-hint.js b/packages/block-editor/src/components/inserter/reusable-block-rename-hint.js index 460c4f4a3db3db..6a3a3d1eec260b 100644 --- a/packages/block-editor/src/components/inserter/reusable-block-rename-hint.js +++ b/packages/block-editor/src/components/inserter/reusable-block-rename-hint.js @@ -10,7 +10,11 @@ import { close } from '@wordpress/icons'; import { store as preferencesStore } from '@wordpress/preferences'; const PREFERENCE_NAME = 'isResuableBlocksrRenameHintVisible'; - +/* + * This hook was added in 6.3 to help users with the transition from Reusable blocks to Patterns. + * It is only exported for use in the reusable-blocks package as well as block-editor. + * It will be removed in 6.4. and should not be used in any new code. + */ export function useReusableBlocksRenameHint() { return useSelect( ( select ) => @@ -19,6 +23,11 @@ export function useReusableBlocksRenameHint() { ); } +/* + * This component was added in 6.3 to help users with the transition from Reusable blocks to Patterns. + * It is only exported for use in the reusable-blocks package as well as block-editor. + * It will be removed in 6.4. and should not be used in any new code. + */ export default function ReusableBlocksRenameHint() { const isReusableBlocksRenameHint = useSelect( ( select ) => From 772a41295f1f7edde22bf055ee7330a19f1c6fd6 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Mon, 17 Jul 2023 13:04:59 +1200 Subject: [PATCH 07/11] Move to private API --- packages/block-editor/README.md | 8 -------- packages/block-editor/src/components/index.js | 8 -------- packages/block-editor/src/private-apis.js | 6 ++++++ packages/reusable-blocks/package.json | 1 + .../reusable-block-convert-button.js | 7 +++++-- packages/reusable-blocks/src/private-apis.js | 10 ++++++++++ 6 files changed, 22 insertions(+), 18 deletions(-) create mode 100644 packages/reusable-blocks/src/private-apis.js diff --git a/packages/block-editor/README.md b/packages/block-editor/README.md index 7bb33e2be40206..2c42b42afc4424 100644 --- a/packages/block-editor/README.md +++ b/packages/block-editor/README.md @@ -680,10 +680,6 @@ _Related_ Private @wordpress/block-editor APIs. -### ReusableBlocksRenameHint - -Undocumented declaration. - ### RichText _Related_ @@ -854,10 +850,6 @@ _Parameters_ - _props_ `Object`: Optional. Props to pass to the element. Must contain the ref if one is defined. - _options_ `Object`: Optional. Inner blocks options. -### useReusableBlocksRenameHint - -Undocumented declaration. - ### useSetting Hook that retrieves the given setting for the block instance in use. diff --git a/packages/block-editor/src/components/index.js b/packages/block-editor/src/components/index.js index 57c306cb7f9e8f..5876eb4ec01e9e 100644 --- a/packages/block-editor/src/components/index.js +++ b/packages/block-editor/src/components/index.js @@ -165,11 +165,3 @@ export { default as __experimentalInspectorPopoverHeader } from './inspector-pop export { default as BlockEditorProvider } from './provider'; export { default as useSetting } from './use-setting'; - -/* - * The following rename hint component can be removed in 6.4. - */ -export { - default as ReusableBlocksRenameHint, - useReusableBlocksRenameHint, -} from './inserter/reusable-block-rename-hint'; diff --git a/packages/block-editor/src/private-apis.js b/packages/block-editor/src/private-apis.js index 453fbd7ce63eb9..20aeaa2a79040b 100644 --- a/packages/block-editor/src/private-apis.js +++ b/packages/block-editor/src/private-apis.js @@ -19,6 +19,10 @@ import { BlockRemovalWarningModal } from './components/block-removal-warning-mod import { useLayoutClasses, useLayoutStyles } from './hooks'; import DimensionsTool from './components/dimensions-tool'; import ResolutionTool from './components/resolution-tool'; +import { + default as ReusableBlocksRenameHint, + useReusableBlocksRenameHint, +} from './components/inserter/reusable-block-rename-hint'; /** * Private @wordpress/block-editor APIs. @@ -43,4 +47,6 @@ lock( privateApis, { useLayoutStyles, DimensionsTool, ResolutionTool, + ReusableBlocksRenameHint, + useReusableBlocksRenameHint, } ); diff --git a/packages/reusable-blocks/package.json b/packages/reusable-blocks/package.json index a15e98ac1a9068..81bd9f54245725 100644 --- a/packages/reusable-blocks/package.json +++ b/packages/reusable-blocks/package.json @@ -37,6 +37,7 @@ "@wordpress/i18n": "file:../i18n", "@wordpress/icons": "file:../icons", "@wordpress/notices": "file:../notices", + "@wordpress/private-apis": "^0.19.0", "@wordpress/url": "file:../url" }, "peerDependencies": { diff --git a/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js b/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js index 7a37ed8cfab206..9dc9d5a3e8ef42 100644 --- a/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js +++ b/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js @@ -5,8 +5,7 @@ import { hasBlockSupport, isReusableBlock } from '@wordpress/blocks'; import { BlockSettingsMenuControls, store as blockEditorStore, - ReusableBlocksRenameHint, - useReusableBlocksRenameHint, + privateApis as blockEditorPrivateApis, } from '@wordpress/block-editor'; import { useCallback, useState } from '@wordpress/element'; import { @@ -28,6 +27,7 @@ import { store as coreStore } from '@wordpress/core-data'; * Internal dependencies */ import { store } from '../../store'; +import { unlock } from '../../private-apis'; /** * Menu control to convert block(s) to reusable block. @@ -41,6 +41,9 @@ export default function ReusableBlockConvertButton( { clientIds, rootClientId, } ) { + const { useReusableBlocksRenameHint, ReusableBlocksRenameHint } = unlock( + blockEditorPrivateApis + ); const showRenameHint = useReusableBlocksRenameHint(); const [ syncType, setSyncType ] = useState( undefined ); const [ isModalOpen, setIsModalOpen ] = useState( false ); diff --git a/packages/reusable-blocks/src/private-apis.js b/packages/reusable-blocks/src/private-apis.js new file mode 100644 index 00000000000000..9934484ea23473 --- /dev/null +++ b/packages/reusable-blocks/src/private-apis.js @@ -0,0 +1,10 @@ +/** + * WordPress dependencies + */ +import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis'; + +export const { lock, unlock } = + __dangerousOptInToUnstableAPIsOnlyForCoreModules( + 'I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.', + '@wordpress/edit-site' + ); From e026fa3a6a43d2c631d0d58ca5ececb0818ccd72 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Mon, 17 Jul 2023 14:09:42 +1200 Subject: [PATCH 08/11] Rename file to lock-unlock and correct package name --- .../reusable-block-convert-button.js | 2 +- packages/reusable-blocks/src/lock-unlock.js | 9 +++++++++ packages/reusable-blocks/src/private-apis.js | 10 ---------- 3 files changed, 10 insertions(+), 11 deletions(-) create mode 100644 packages/reusable-blocks/src/lock-unlock.js delete mode 100644 packages/reusable-blocks/src/private-apis.js diff --git a/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js b/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js index 9dc9d5a3e8ef42..2dfd635e2963a3 100644 --- a/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js +++ b/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js @@ -27,7 +27,7 @@ import { store as coreStore } from '@wordpress/core-data'; * Internal dependencies */ import { store } from '../../store'; -import { unlock } from '../../private-apis'; +import { unlock } from '../../lock-unlock'; /** * Menu control to convert block(s) to reusable block. diff --git a/packages/reusable-blocks/src/lock-unlock.js b/packages/reusable-blocks/src/lock-unlock.js new file mode 100644 index 00000000000000..c33f209c9d76ae --- /dev/null +++ b/packages/reusable-blocks/src/lock-unlock.js @@ -0,0 +1,9 @@ +/** + * WordPress dependencies + */ +import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis'; + +export const { unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules( + 'I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.', + '@wordpress/reusable-blocks' +); diff --git a/packages/reusable-blocks/src/private-apis.js b/packages/reusable-blocks/src/private-apis.js deleted file mode 100644 index 9934484ea23473..00000000000000 --- a/packages/reusable-blocks/src/private-apis.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * WordPress dependencies - */ -import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis'; - -export const { lock, unlock } = - __dangerousOptInToUnstableAPIsOnlyForCoreModules( - 'I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.', - '@wordpress/edit-site' - ); From 7a62ac7cfa2791edc211c0cfd14c2cd2329e2c2b Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Mon, 17 Jul 2023 14:12:15 +1200 Subject: [PATCH 09/11] Also use private API in post edit modal --- packages/editor/src/components/post-sync-status/index.js | 5 +++-- packages/reusable-blocks/src/lock-unlock.js | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/editor/src/components/post-sync-status/index.js b/packages/editor/src/components/post-sync-status/index.js index 8219ef7c0e4f54..bbc8cd0cfe974f 100644 --- a/packages/editor/src/components/post-sync-status/index.js +++ b/packages/editor/src/components/post-sync-status/index.js @@ -12,12 +12,13 @@ import { ToggleControl, } from '@wordpress/components'; import { useEffect, useState } from '@wordpress/element'; -import { ReusableBlocksRenameHint } from '@wordpress/block-editor'; +import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; /** * Internal dependencies */ import { store as editorStore } from '../../store'; +import { unlock } from '../../lock-unlock'; export default function PostSyncStatus() { const { syncStatus, postType, meta } = useSelect( ( select ) => { @@ -81,7 +82,7 @@ export function PostSyncStatusModal() { if ( postType !== 'wp_block' || ! isNewPost ) { return null; } - + const { ReusableBlocksRenameHint } = unlock( blockEditorPrivateApis ); return ( <> { isModalOpen && ( diff --git a/packages/reusable-blocks/src/lock-unlock.js b/packages/reusable-blocks/src/lock-unlock.js index c33f209c9d76ae..39568950e159b1 100644 --- a/packages/reusable-blocks/src/lock-unlock.js +++ b/packages/reusable-blocks/src/lock-unlock.js @@ -5,5 +5,5 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/pri export const { unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules( 'I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.', - '@wordpress/reusable-blocks' + '@wordpress/block-editor' ); From e619b30a95bbd678a3593238b63ceed025817156 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Mon, 17 Jul 2023 14:23:44 +1200 Subject: [PATCH 10/11] Add reusable blocks module to list of core packages --- packages/private-apis/src/implementation.js | 1 + packages/reusable-blocks/src/lock-unlock.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/private-apis/src/implementation.js b/packages/private-apis/src/implementation.js index 31936fba5ad516..2c9fdadb27c57f 100644 --- a/packages/private-apis/src/implementation.js +++ b/packages/private-apis/src/implementation.js @@ -23,6 +23,7 @@ const CORE_MODULES_USING_PRIVATE_APIS = [ '@wordpress/edit-site', '@wordpress/edit-widgets', '@wordpress/editor', + '@wordpress/reusable-blocks', '@wordpress/router', ]; diff --git a/packages/reusable-blocks/src/lock-unlock.js b/packages/reusable-blocks/src/lock-unlock.js index 39568950e159b1..c33f209c9d76ae 100644 --- a/packages/reusable-blocks/src/lock-unlock.js +++ b/packages/reusable-blocks/src/lock-unlock.js @@ -5,5 +5,5 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/pri export const { unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules( 'I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.', - '@wordpress/block-editor' + '@wordpress/reusable-blocks' ); From 608836d2f6aedc7853ebe8cdf5c1f136909646d0 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Mon, 17 Jul 2023 15:51:51 +1200 Subject: [PATCH 11/11] Commit updated package-lock.json after adding private apis to reusable blocks --- package-lock.json | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3c96f25259cbce..42ace4e6e0d7ff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18572,6 +18572,7 @@ "@wordpress/i18n": "file:packages/i18n", "@wordpress/icons": "file:packages/icons", "@wordpress/notices": "file:packages/notices", + "@wordpress/private-apis": "^0.19.0", "@wordpress/url": "file:packages/url" } }, @@ -25919,7 +25920,7 @@ "array-ify": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/array-ify/-/array-ify-1.0.0.tgz", - "integrity": "sha512-c5AMf34bKdvPhQ7tBGhqkgKNUzMr4WUs+WDtC2ZUGOUncbxKMTvqxYctiseW3+L4bA8ec+GcZ6/A/FW4m8ukng==", + "integrity": "sha1-nlKHYrSpBmrRY6aWKjZEGOlibs4=", "dev": true }, "array-includes": { @@ -31074,7 +31075,7 @@ "debuglog": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/debuglog/-/debuglog-1.0.1.tgz", - "integrity": "sha512-syBZ+rnAK3EgMsH2aYEOLUW7mZSY9Gb+0wUMCFsZvcmiz+HigA0LOcq/HoQqVuGG+EKykunc7QG2bzrponfaSw==", + "integrity": "sha1-qiT/uaw9+aI1GDfPstJ5NgzXhJI=", "dev": true }, "decache": { @@ -35920,7 +35921,7 @@ "git-remote-origin-url": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/git-remote-origin-url/-/git-remote-origin-url-2.0.0.tgz", - "integrity": "sha512-eU+GGrZgccNJcsDH5LkXR3PB9M958hxc7sbA8DFJjrv9j4L2P/eZfKhM+QD6wyzpiv+b1BpK0XrYCxkovtjSLw==", + "integrity": "sha1-UoJlna4hBxRaERJhEq0yFuxfpl8=", "dev": true, "requires": { "gitconfiglocal": "^1.0.0", @@ -35967,7 +35968,7 @@ "gitconfiglocal": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/gitconfiglocal/-/gitconfiglocal-1.0.0.tgz", - "integrity": "sha512-spLUXeTAVHxDtKsJc8FkFVgFtMdEN9qPGpL23VfSHx4fP4+Ds097IXLvymbnDH8FnmxX5Nr9bPw3A+AQ6mWEaQ==", + "integrity": "sha1-QdBF84UaXqiPA/JMocYXgRRGS5s=", "dev": true, "requires": { "ini": "^1.3.2" @@ -37215,7 +37216,7 @@ "humanize-ms": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/humanize-ms/-/humanize-ms-1.2.1.tgz", - "integrity": "sha512-Fl70vYtsAFb/C06PTS9dZBo7ihau+Tu/DNCk/OyHhea07S+aeMWpFFkUaXRa8fI+ScZbEI8dfSxwY7gxZ9SAVQ==", + "integrity": "sha1-xG4xWaKT9riW2ikxbYtv6Lt5u+0=", "dev": true, "requires": { "ms": "^2.0.0" @@ -38231,7 +38232,7 @@ "is-text-path": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/is-text-path/-/is-text-path-1.0.1.tgz", - "integrity": "sha512-xFuJpne9oFz5qDaodwmmG08e3CawH/2ZV8Qqza1Ko7Sk8POWbkRdwIoAWVhqvq0XeUzANEhKo2n0IXUGBm7A/w==", + "integrity": "sha1-Thqg+1G/vLPpJogAE5cgLBd1tm4=", "dev": true, "requires": { "text-extensions": "^1.0.0" @@ -40004,7 +40005,7 @@ "jsonparse": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-1.3.1.tgz", - "integrity": "sha512-POQXvpdL69+CluYsillJ7SUhKvytYjW9vG/GKpnf+xP8UWgYEM/RaMzHHofbALDiKbbP1W8UEYmgGl39WkPZsg==", + "integrity": "sha1-P02uSpH6wxX3EGL4UhzCOfE2YoA=", "dev": true }, "jsprim": { @@ -41110,7 +41111,7 @@ "lodash.ismatch": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/lodash.ismatch/-/lodash.ismatch-4.4.0.tgz", - "integrity": "sha512-fPMfXjGQEV9Xsq/8MTSgUf255gawYRbjwMyDbcvDhXgV7enSZA0hynz6vMPnpAb5iONEzBHBPsT+0zes5Z301g==", + "integrity": "sha1-dWy1FQyjum8RCFp4hJZF8Yj4Xzc=", "dev": true }, "lodash.isplainobject": { @@ -48716,7 +48717,7 @@ "promzard": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/promzard/-/promzard-0.3.0.tgz", - "integrity": "sha512-JZeYqd7UAcHCwI+sTOeUDYkvEU+1bQ7iE0UT1MgB/tERkAPkesW46MrpIySzODi+owTjZtiF8Ay5j9m60KmMBw==", + "integrity": "sha1-JqXW7ox97kyxIggwWs+5O6OCqe4=", "dev": true, "requires": { "read": "1" @@ -48750,7 +48751,7 @@ "proto-list": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/proto-list/-/proto-list-1.2.4.tgz", - "integrity": "sha512-vtK/94akxsTMhe0/cbfpR+syPuszcuwhqVjJq26CuNDgFGj682oRBXOP5MJpv2r7JtE8MsiepGIqvvOTBwn2vA==", + "integrity": "sha1-IS1b/hMYMGpCD2QCuOJv85ZHqEk=", "dev": true }, "protocols": { @@ -50367,7 +50368,7 @@ "read": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/read/-/read-1.0.7.tgz", - "integrity": "sha512-rSOKNYUmaxy0om1BNjMN4ezNT6VKK+2xF4GBhc81mkH7L60i6dp8qPYrkndNLT3QPphoII3maL9PVC9XmhHwVQ==", + "integrity": "sha1-s9oZvQUkMal2cdRKQmNK33ELQMQ=", "dev": true, "requires": { "mute-stream": "~0.0.4" @@ -55757,7 +55758,7 @@ "temp-dir": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/temp-dir/-/temp-dir-1.0.0.tgz", - "integrity": "sha512-xZFXEGbG7SNC3itwBzI3RYjq/cEhBkx2hJuKGIUOcEULmkQExXiHat2z/qkISYsuR+IKumhEfKKbV5qXmhICFQ==", + "integrity": "sha1-CnwOom06Oa+n4OvqnB/AvE2qAR0=", "dev": true }, "terminal-link": {