@wordpress/reusable-blocks 5.0.3 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -3
- package/build/components/reusable-blocks-menu-items/reusable-block-convert-button.js +1 -0
- package/build/components/reusable-blocks-menu-items/reusable-block-convert-button.js.map +1 -1
- package/build-module/components/reusable-blocks-menu-items/reusable-block-convert-button.js +1 -0
- package/build-module/components/reusable-blocks-menu-items/reusable-block-convert-button.js.map +1 -1
- package/package.json +13 -13
- package/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 5.2.0 (2024-06-26)
|
|
6
|
+
|
|
7
|
+
## 5.1.0 (2024-06-15)
|
|
8
|
+
|
|
5
9
|
## 5.0.0 (2024-05-31)
|
|
6
10
|
|
|
7
11
|
### Breaking Changes
|
|
@@ -124,7 +128,7 @@
|
|
|
124
128
|
|
|
125
129
|
## 3.1.1 (2022-02-10)
|
|
126
130
|
|
|
127
|
-
### Bug
|
|
131
|
+
### Bug Fixes
|
|
128
132
|
|
|
129
133
|
- Removed unused `@wordpress/compose` dependency ([#38388](https://github.com/WordPress/gutenberg/pull/38388)).
|
|
130
134
|
|
|
@@ -132,7 +136,7 @@
|
|
|
132
136
|
|
|
133
137
|
## 3.0.0 (2021-07-29)
|
|
134
138
|
|
|
135
|
-
### Breaking
|
|
139
|
+
### Breaking Changes
|
|
136
140
|
|
|
137
141
|
- Upgraded React components to work with v17.0 ([#29118](https://github.com/WordPress/gutenberg/pull/29118)). There are no new features in React v17.0 as explained in the [blog post](https://reactjs.org/blog/2020/10/20/react-v17.html).
|
|
138
142
|
|
|
@@ -151,7 +155,7 @@
|
|
|
151
155
|
|
|
152
156
|
## 1.1.0 (2020-12-17)
|
|
153
157
|
|
|
154
|
-
### New
|
|
158
|
+
### New Features
|
|
155
159
|
|
|
156
160
|
- Added a store definition `store` for the reusable blocks namespace to use with `@wordpress/data` API ([#26655](https://github.com/WordPress/gutenberg/pull/26655)).
|
|
157
161
|
|
|
@@ -72,6 +72,7 @@ function ReusableBlockConvertButton({
|
|
|
72
72
|
// Hide when block doesn't support being made reusable.
|
|
73
73
|
(0, _blocks.hasBlockSupport)(block.name, 'reusable', true)) &&
|
|
74
74
|
// Hide when current doesn't have permission to do that.
|
|
75
|
+
// Blocks refers to the wp_block post type, this checks the ability to create a post of that type.
|
|
75
76
|
!!canUser('create', 'blocks');
|
|
76
77
|
return _canConvert;
|
|
77
78
|
}, [clientIds, rootClientId]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_blocks","require","_blockEditor","_element","_components","_icons","_data","_i18n","_notices","_coreData","_store","_lockUnlock","_jsxRuntime","useReusableBlocksRenameHint","ReusableBlocksRenameHint","unlock","blockEditorPrivateApis","ReusableBlockConvertButton","clientIds","rootClientId","onClose","showRenameHint","syncType","setSyncType","useState","undefined","isModalOpen","setIsModalOpen","title","setTitle","canConvert","useSelect","select","_getBlocksByClientId","canUser","coreStore","getBlocksByClientId","canInsertBlockType","getBlockRootClientId","blockEditorStore","rootId","length","blocks","isReusable","isReusableBlock","getEntityRecord","attributes","ref","_canConvert","every","block","isValid","hasBlockSupport","name","__experimentalConvertBlocksToReusable","convertBlocksToReusable","useDispatch","store","createSuccessNotice","createErrorNotice","noticesStore","onConvert","useCallback","reusableBlockTitle","sprintf","__","type","id","error","message","jsxs","Fragment","children","jsx","MenuItem","icon","symbol","onClick","Modal","onRequestClose","overlayClassName","onSubmit","event","preventDefault","__experimentalVStack","spacing","TextControl","__nextHasNoMarginBottom","label","value","onChange","placeholder","ToggleControl","_x","help","checked","__experimentalHStack","justify","Button","variant"],"sources":["@wordpress/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { hasBlockSupport, isReusableBlock } from '@wordpress/blocks';\nimport {\n\tstore as blockEditorStore,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { useCallback, useState } from '@wordpress/element';\nimport {\n\tMenuItem,\n\tModal,\n\tButton,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\tToggleControl,\n} from '@wordpress/components';\nimport { symbol } from '@wordpress/icons';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\nconst { useReusableBlocksRenameHint, ReusableBlocksRenameHint } = unlock(\n\tblockEditorPrivateApis\n);\n\n/**\n * Menu control to convert block(s) to reusable block.\n *\n * @param {Object} props Component props.\n * @param {string[]} props.clientIds Client ids of selected blocks.\n * @param {string} props.rootClientId ID of the currently selected top-level block.\n * @param {()=>void} props.onClose Callback to close the menu.\n * @return {import('react').ComponentType} The menu control or null.\n */\nexport default function ReusableBlockConvertButton( {\n\tclientIds,\n\trootClientId,\n\tonClose,\n} ) {\n\tconst showRenameHint = useReusableBlocksRenameHint();\n\tconst [ syncType, setSyncType ] = useState( undefined );\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst [ title, setTitle ] = useState( '' );\n\tconst canConvert = useSelect(\n\t\t( select ) => {\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst {\n\t\t\t\tgetBlocksByClientId,\n\t\t\t\tcanInsertBlockType,\n\t\t\t\tgetBlockRootClientId,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tconst rootId =\n\t\t\t\trootClientId ||\n\t\t\t\t( clientIds.length > 0\n\t\t\t\t\t? getBlockRootClientId( clientIds[ 0 ] )\n\t\t\t\t\t: undefined );\n\n\t\t\tconst blocks = getBlocksByClientId( clientIds ) ?? [];\n\n\t\t\tconst isReusable =\n\t\t\t\tblocks.length === 1 &&\n\t\t\t\tblocks[ 0 ] &&\n\t\t\t\tisReusableBlock( blocks[ 0 ] ) &&\n\t\t\t\t!! select( coreStore ).getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_block',\n\t\t\t\t\tblocks[ 0 ].attributes.ref\n\t\t\t\t);\n\n\t\t\tconst _canConvert =\n\t\t\t\t// Hide when this is already a reusable block.\n\t\t\t\t! isReusable &&\n\t\t\t\t// Hide when reusable blocks are disabled.\n\t\t\t\tcanInsertBlockType( 'core/block', rootId ) &&\n\t\t\t\tblocks.every(\n\t\t\t\t\t( block ) =>\n\t\t\t\t\t\t// Guard against the case where a regular block has *just* been converted.\n\t\t\t\t\t\t!! block &&\n\t\t\t\t\t\t// Hide on invalid blocks.\n\t\t\t\t\t\tblock.isValid &&\n\t\t\t\t\t\t// Hide when block doesn't support being made reusable.\n\t\t\t\t\t\thasBlockSupport( block.name, 'reusable', true )\n\t\t\t\t) &&\n\t\t\t\t// Hide when current doesn't have permission to do that.\n\t\t\t\t!! canUser( 'create', 'blocks' );\n\n\t\t\treturn _canConvert;\n\t\t},\n\t\t[ clientIds, rootClientId ]\n\t);\n\n\tconst { __experimentalConvertBlocksToReusable: convertBlocksToReusable } =\n\t\tuseDispatch( store );\n\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\tconst onConvert = useCallback(\n\t\tasync function ( reusableBlockTitle ) {\n\t\t\ttry {\n\t\t\t\tawait convertBlocksToReusable(\n\t\t\t\t\tclientIds,\n\t\t\t\t\treusableBlockTitle,\n\t\t\t\t\tsyncType\n\t\t\t\t);\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\t! syncType\n\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t\t\t__( 'Synced pattern created: %s' ),\n\t\t\t\t\t\t\t\treusableBlockTitle\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t\t\t__( 'Unsynced pattern created: %s' ),\n\t\t\t\t\t\t\t\treusableBlockTitle\n\t\t\t\t\t\t ),\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tid: 'convert-to-reusable-block-success',\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} catch ( error ) {\n\t\t\t\tcreateErrorNotice( error.message, {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tid: 'convert-to-reusable-block-error',\n\t\t\t\t} );\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\tconvertBlocksToReusable,\n\t\t\tclientIds,\n\t\t\tsyncType,\n\t\t\tcreateSuccessNotice,\n\t\t\tcreateErrorNotice,\n\t\t]\n\t);\n\n\tif ( ! canConvert ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<MenuItem icon={ symbol } onClick={ () => setIsModalOpen( true ) }>\n\t\t\t\t{ showRenameHint\n\t\t\t\t\t? __( 'Create pattern/reusable block' )\n\t\t\t\t\t: __( 'Create pattern' ) }\n\t\t\t</MenuItem>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Create pattern' ) }\n\t\t\t\t\tonRequestClose={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t} }\n\t\t\t\t\toverlayClassName=\"reusable-blocks-menu-items__convert-modal\"\n\t\t\t\t>\n\t\t\t\t\t<form\n\t\t\t\t\t\tonSubmit={ ( event ) => {\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\tonConvert( title );\n\t\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t\t\t<ReusableBlocksRenameHint />\n\t\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\t\t\tplaceholder={ __( 'My pattern' ) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\tlabel={ _x( 'Synced', 'pattern (singular)' ) }\n\t\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t\t'Sync this pattern across multiple locations.'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tchecked={ ! syncType }\n\t\t\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\t\t\tsetSyncType(\n\t\t\t\t\t\t\t\t\t\t! syncType ? 'unsynced' : undefined\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t\t\t</Button>\n\n\t\t\t\t\t\t\t\t<Button variant=\"primary\" type=\"submit\">\n\t\t\t\t\t\t\t\t\t{ __( 'Create' ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t</HStack>\n\t\t\t\t\t\t</VStack>\n\t\t\t\t\t</form>\n\t\t\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EAAGA,CAAA,KAAM;gBACflD,cAAc,CAAE,KAAM,CAAC;gBACvBE,QAAQ,CAAE,EAAG,CAAC;cACf,CAAG;cAAA2C,QAAA,EAED,IAAAP,QAAE,EAAE,QAAS;YAAC,CACT,CAAC,eAET,IAAArD,WAAA,CAAA6D,GAAA,EAACrE,WAAA,CAAA8F,MAAM;cAACC,OAAO,EAAC,SAAS;cAACjC,IAAI,EAAC,QAAQ;cAAAM,QAAA,EACpC,IAAAP,QAAE,EAAE,QAAS;YAAC,CACT,CAAC;UAAA,CACF,CAAC;QAAA,CACF;MAAC,CACJ;IAAC,CACD,CACP;EAAA,CACA,CAAC;AAEL","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_blocks","require","_blockEditor","_element","_components","_icons","_data","_i18n","_notices","_coreData","_store","_lockUnlock","_jsxRuntime","useReusableBlocksRenameHint","ReusableBlocksRenameHint","unlock","blockEditorPrivateApis","ReusableBlockConvertButton","clientIds","rootClientId","onClose","showRenameHint","syncType","setSyncType","useState","undefined","isModalOpen","setIsModalOpen","title","setTitle","canConvert","useSelect","select","_getBlocksByClientId","canUser","coreStore","getBlocksByClientId","canInsertBlockType","getBlockRootClientId","blockEditorStore","rootId","length","blocks","isReusable","isReusableBlock","getEntityRecord","attributes","ref","_canConvert","every","block","isValid","hasBlockSupport","name","__experimentalConvertBlocksToReusable","convertBlocksToReusable","useDispatch","store","createSuccessNotice","createErrorNotice","noticesStore","onConvert","useCallback","reusableBlockTitle","sprintf","__","type","id","error","message","jsxs","Fragment","children","jsx","MenuItem","icon","symbol","onClick","Modal","onRequestClose","overlayClassName","onSubmit","event","preventDefault","__experimentalVStack","spacing","TextControl","__nextHasNoMarginBottom","label","value","onChange","placeholder","ToggleControl","_x","help","checked","__experimentalHStack","justify","Button","variant"],"sources":["@wordpress/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { hasBlockSupport, isReusableBlock } from '@wordpress/blocks';\nimport {\n\tstore as blockEditorStore,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { useCallback, useState } from '@wordpress/element';\nimport {\n\tMenuItem,\n\tModal,\n\tButton,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\tToggleControl,\n} from '@wordpress/components';\nimport { symbol } from '@wordpress/icons';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\nconst { useReusableBlocksRenameHint, ReusableBlocksRenameHint } = unlock(\n\tblockEditorPrivateApis\n);\n\n/**\n * Menu control to convert block(s) to reusable block.\n *\n * @param {Object} props Component props.\n * @param {string[]} props.clientIds Client ids of selected blocks.\n * @param {string} props.rootClientId ID of the currently selected top-level block.\n * @param {()=>void} props.onClose Callback to close the menu.\n * @return {import('react').ComponentType} The menu control or null.\n */\nexport default function ReusableBlockConvertButton( {\n\tclientIds,\n\trootClientId,\n\tonClose,\n} ) {\n\tconst showRenameHint = useReusableBlocksRenameHint();\n\tconst [ syncType, setSyncType ] = useState( undefined );\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst [ title, setTitle ] = useState( '' );\n\tconst canConvert = useSelect(\n\t\t( select ) => {\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst {\n\t\t\t\tgetBlocksByClientId,\n\t\t\t\tcanInsertBlockType,\n\t\t\t\tgetBlockRootClientId,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tconst rootId =\n\t\t\t\trootClientId ||\n\t\t\t\t( clientIds.length > 0\n\t\t\t\t\t? getBlockRootClientId( clientIds[ 0 ] )\n\t\t\t\t\t: undefined );\n\n\t\t\tconst blocks = getBlocksByClientId( clientIds ) ?? [];\n\n\t\t\tconst isReusable =\n\t\t\t\tblocks.length === 1 &&\n\t\t\t\tblocks[ 0 ] &&\n\t\t\t\tisReusableBlock( blocks[ 0 ] ) &&\n\t\t\t\t!! select( coreStore ).getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_block',\n\t\t\t\t\tblocks[ 0 ].attributes.ref\n\t\t\t\t);\n\n\t\t\tconst _canConvert =\n\t\t\t\t// Hide when this is already a reusable block.\n\t\t\t\t! isReusable &&\n\t\t\t\t// Hide when reusable blocks are disabled.\n\t\t\t\tcanInsertBlockType( 'core/block', rootId ) &&\n\t\t\t\tblocks.every(\n\t\t\t\t\t( block ) =>\n\t\t\t\t\t\t// Guard against the case where a regular block has *just* been converted.\n\t\t\t\t\t\t!! block &&\n\t\t\t\t\t\t// Hide on invalid blocks.\n\t\t\t\t\t\tblock.isValid &&\n\t\t\t\t\t\t// Hide when block doesn't support being made reusable.\n\t\t\t\t\t\thasBlockSupport( block.name, 'reusable', true )\n\t\t\t\t) &&\n\t\t\t\t// Hide when current doesn't have permission to do that.\n\t\t\t\t// Blocks refers to the wp_block post type, this checks the ability to create a post of that type.\n\t\t\t\t!! canUser( 'create', 'blocks' );\n\n\t\t\treturn _canConvert;\n\t\t},\n\t\t[ clientIds, rootClientId ]\n\t);\n\n\tconst { __experimentalConvertBlocksToReusable: convertBlocksToReusable } =\n\t\tuseDispatch( store );\n\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\tconst onConvert = useCallback(\n\t\tasync function ( reusableBlockTitle ) {\n\t\t\ttry {\n\t\t\t\tawait convertBlocksToReusable(\n\t\t\t\t\tclientIds,\n\t\t\t\t\treusableBlockTitle,\n\t\t\t\t\tsyncType\n\t\t\t\t);\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\t! syncType\n\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t\t\t__( 'Synced pattern created: %s' ),\n\t\t\t\t\t\t\t\treusableBlockTitle\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t\t\t__( 'Unsynced pattern created: %s' ),\n\t\t\t\t\t\t\t\treusableBlockTitle\n\t\t\t\t\t\t ),\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tid: 'convert-to-reusable-block-success',\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} catch ( error ) {\n\t\t\t\tcreateErrorNotice( error.message, {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tid: 'convert-to-reusable-block-error',\n\t\t\t\t} );\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\tconvertBlocksToReusable,\n\t\t\tclientIds,\n\t\t\tsyncType,\n\t\t\tcreateSuccessNotice,\n\t\t\tcreateErrorNotice,\n\t\t]\n\t);\n\n\tif ( ! canConvert ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<MenuItem icon={ symbol } onClick={ () => setIsModalOpen( true ) }>\n\t\t\t\t{ showRenameHint\n\t\t\t\t\t? __( 'Create pattern/reusable block' )\n\t\t\t\t\t: __( 'Create pattern' ) }\n\t\t\t</MenuItem>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Create pattern' ) }\n\t\t\t\t\tonRequestClose={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t} }\n\t\t\t\t\toverlayClassName=\"reusable-blocks-menu-items__convert-modal\"\n\t\t\t\t>\n\t\t\t\t\t<form\n\t\t\t\t\t\tonSubmit={ ( event ) => {\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\tonConvert( title );\n\t\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t\t\t<ReusableBlocksRenameHint />\n\t\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\t\t\tplaceholder={ __( 'My pattern' ) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\tlabel={ _x( 'Synced', 'pattern (singular)' ) }\n\t\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t\t'Sync this pattern across multiple locations.'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tchecked={ ! syncType }\n\t\t\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\t\t\tsetSyncType(\n\t\t\t\t\t\t\t\t\t\t! syncType ? 'unsynced' : undefined\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t\t\t</Button>\n\n\t\t\t\t\t\t\t\t<Button variant=\"primary\" type=\"submit\">\n\t\t\t\t\t\t\t\t\t{ __( 'Create' ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t</HStack>\n\t\t\t\t\t\t</VStack>\n\t\t\t\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UAAU;cAClBtB,OAAO,EAAGA,CAAA,KAAM;gBACflD,cAAc,CAAE,KAAM,CAAC;gBACvBE,QAAQ,CAAE,EAAG,CAAC;cACf,CAAG;cAAA2C,QAAA,EAED,IAAAP,QAAE,EAAE,QAAS;YAAC,CACT,CAAC,eAET,IAAArD,WAAA,CAAA6D,GAAA,EAACrE,WAAA,CAAA8F,MAAM;cAACC,OAAO,EAAC,SAAS;cAACjC,IAAI,EAAC,QAAQ;cAAAM,QAAA,EACpC,IAAAP,QAAE,EAAE,QAAS;YAAC,CACT,CAAC;UAAA,CACF,CAAC;QAAA,CACF;MAAC,CACJ;IAAC,CACD,CACP;EAAA,CACA,CAAC;AAEL","ignoreList":[]}
|
|
@@ -67,6 +67,7 @@ export default function ReusableBlockConvertButton({
|
|
|
67
67
|
// Hide when block doesn't support being made reusable.
|
|
68
68
|
hasBlockSupport(block.name, 'reusable', true)) &&
|
|
69
69
|
// Hide when current doesn't have permission to do that.
|
|
70
|
+
// Blocks refers to the wp_block post type, this checks the ability to create a post of that type.
|
|
70
71
|
!!canUser('create', 'blocks');
|
|
71
72
|
return _canConvert;
|
|
72
73
|
}, [clientIds, rootClientId]);
|
package/build-module/components/reusable-blocks-menu-items/reusable-block-convert-button.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["hasBlockSupport","isReusableBlock","store","blockEditorStore","privateApis","blockEditorPrivateApis","useCallback","useState","MenuItem","Modal","Button","TextControl","__experimentalHStack","HStack","__experimentalVStack","VStack","ToggleControl","symbol","useDispatch","useSelect","__","_x","sprintf","noticesStore","coreStore","unlock","jsx","_jsx","jsxs","_jsxs","Fragment","_Fragment","useReusableBlocksRenameHint","ReusableBlocksRenameHint","ReusableBlockConvertButton","clientIds","rootClientId","onClose","showRenameHint","syncType","setSyncType","undefined","isModalOpen","setIsModalOpen","title","setTitle","canConvert","select","_getBlocksByClientId","canUser","getBlocksByClientId","canInsertBlockType","getBlockRootClientId","rootId","length","blocks","isReusable","getEntityRecord","attributes","ref","_canConvert","every","block","isValid","name","__experimentalConvertBlocksToReusable","convertBlocksToReusable","createSuccessNotice","createErrorNotice","onConvert","reusableBlockTitle","type","id","error","message","children","icon","onClick","onRequestClose","overlayClassName","onSubmit","event","preventDefault","spacing","__nextHasNoMarginBottom","label","value","onChange","placeholder","help","checked","justify","variant"],"sources":["@wordpress/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { hasBlockSupport, isReusableBlock } from '@wordpress/blocks';\nimport {\n\tstore as blockEditorStore,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { useCallback, useState } from '@wordpress/element';\nimport {\n\tMenuItem,\n\tModal,\n\tButton,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\tToggleControl,\n} from '@wordpress/components';\nimport { symbol } from '@wordpress/icons';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\nconst { useReusableBlocksRenameHint, ReusableBlocksRenameHint } = unlock(\n\tblockEditorPrivateApis\n);\n\n/**\n * Menu control to convert block(s) to reusable block.\n *\n * @param {Object} props Component props.\n * @param {string[]} props.clientIds Client ids of selected blocks.\n * @param {string} props.rootClientId ID of the currently selected top-level block.\n * @param {()=>void} props.onClose Callback to close the menu.\n * @return {import('react').ComponentType} The menu control or null.\n */\nexport default function ReusableBlockConvertButton( {\n\tclientIds,\n\trootClientId,\n\tonClose,\n} ) {\n\tconst showRenameHint = useReusableBlocksRenameHint();\n\tconst [ syncType, setSyncType ] = useState( undefined );\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst [ title, setTitle ] = useState( '' );\n\tconst canConvert = useSelect(\n\t\t( select ) => {\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst {\n\t\t\t\tgetBlocksByClientId,\n\t\t\t\tcanInsertBlockType,\n\t\t\t\tgetBlockRootClientId,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tconst rootId =\n\t\t\t\trootClientId ||\n\t\t\t\t( clientIds.length > 0\n\t\t\t\t\t? getBlockRootClientId( clientIds[ 0 ] )\n\t\t\t\t\t: undefined );\n\n\t\t\tconst blocks = getBlocksByClientId( clientIds ) ?? [];\n\n\t\t\tconst isReusable =\n\t\t\t\tblocks.length === 1 &&\n\t\t\t\tblocks[ 0 ] &&\n\t\t\t\tisReusableBlock( blocks[ 0 ] ) &&\n\t\t\t\t!! select( coreStore ).getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_block',\n\t\t\t\t\tblocks[ 0 ].attributes.ref\n\t\t\t\t);\n\n\t\t\tconst _canConvert =\n\t\t\t\t// Hide when this is already a reusable block.\n\t\t\t\t! isReusable &&\n\t\t\t\t// Hide when reusable blocks are disabled.\n\t\t\t\tcanInsertBlockType( 'core/block', rootId ) &&\n\t\t\t\tblocks.every(\n\t\t\t\t\t( block ) =>\n\t\t\t\t\t\t// Guard against the case where a regular block has *just* been converted.\n\t\t\t\t\t\t!! block &&\n\t\t\t\t\t\t// Hide on invalid blocks.\n\t\t\t\t\t\tblock.isValid &&\n\t\t\t\t\t\t// Hide when block doesn't support being made reusable.\n\t\t\t\t\t\thasBlockSupport( block.name, 'reusable', true )\n\t\t\t\t) &&\n\t\t\t\t// Hide when current doesn't have permission to do that.\n\t\t\t\t!! canUser( 'create', 'blocks' );\n\n\t\t\treturn _canConvert;\n\t\t},\n\t\t[ clientIds, rootClientId ]\n\t);\n\n\tconst { __experimentalConvertBlocksToReusable: convertBlocksToReusable } =\n\t\tuseDispatch( store );\n\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\tconst onConvert = useCallback(\n\t\tasync function ( reusableBlockTitle ) {\n\t\t\ttry {\n\t\t\t\tawait convertBlocksToReusable(\n\t\t\t\t\tclientIds,\n\t\t\t\t\treusableBlockTitle,\n\t\t\t\t\tsyncType\n\t\t\t\t);\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\t! syncType\n\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t\t\t__( 'Synced pattern created: %s' ),\n\t\t\t\t\t\t\t\treusableBlockTitle\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t\t\t__( 'Unsynced pattern created: %s' ),\n\t\t\t\t\t\t\t\treusableBlockTitle\n\t\t\t\t\t\t ),\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tid: 'convert-to-reusable-block-success',\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} catch ( error ) {\n\t\t\t\tcreateErrorNotice( error.message, {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tid: 'convert-to-reusable-block-error',\n\t\t\t\t} );\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\tconvertBlocksToReusable,\n\t\t\tclientIds,\n\t\t\tsyncType,\n\t\t\tcreateSuccessNotice,\n\t\t\tcreateErrorNotice,\n\t\t]\n\t);\n\n\tif ( ! canConvert ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<MenuItem icon={ symbol } onClick={ () => setIsModalOpen( true ) }>\n\t\t\t\t{ showRenameHint\n\t\t\t\t\t? __( 'Create pattern/reusable block' )\n\t\t\t\t\t: __( 'Create pattern' ) }\n\t\t\t</MenuItem>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Create pattern' ) }\n\t\t\t\t\tonRequestClose={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t} }\n\t\t\t\t\toverlayClassName=\"reusable-blocks-menu-items__convert-modal\"\n\t\t\t\t>\n\t\t\t\t\t<form\n\t\t\t\t\t\tonSubmit={ ( event ) => {\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\tonConvert( title );\n\t\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t\t\t<ReusableBlocksRenameHint />\n\t\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\t\t\tplaceholder={ __( 'My pattern' ) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\tlabel={ _x( 'Synced', 'pattern (singular)' ) }\n\t\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t\t'Sync this pattern across multiple locations.'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tchecked={ ! syncType }\n\t\t\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\t\t\tsetSyncType(\n\t\t\t\t\t\t\t\t\t\t! syncType ? 'unsynced' : undefined\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\t\t\t\t\tsetT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A,KAAM;cAChB/C,WAAW,CACV,CAAED,QAAQ,GAAG,UAAU,GAAGE,SAC3B,CAAC;YACF;UAAG,CACH,CAAC,eACFZ,KAAA,CAAChB,MAAM;YAAC8E,OAAO,EAAC,OAAO;YAAAhB,QAAA,gBACtBhD,IAAA,CAACjB,MAAM;cACNkF,OAAO,EAAC,UAAU;cAClBf,OAAO,EAAGA,CAAA,KAAM;gBACflC,cAAc,CAAE,KAAM,CAAC;gBACvBE,QAAQ,CAAE,EAAG,CAAC;cACf,CAAG;cAAA8B,QAAA,EAEDvD,EAAE,CAAE,QAAS;YAAC,CACT,CAAC,eAETO,IAAA,CAACjB,MAAM;cAACkF,OAAO,EAAC,SAAS;cAACrB,IAAI,EAAC,QAAQ;cAAAI,QAAA,EACpCvD,EAAE,CAAE,QAAS;YAAC,CACT,CAAC;UAAA,CACF,CAAC;QAAA,CACF;MAAC,CACJ;IAAC,CACD,CACP;EAAA,CACA,CAAC;AAEL","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["hasBlockSupport","isReusableBlock","store","blockEditorStore","privateApis","blockEditorPrivateApis","useCallback","useState","MenuItem","Modal","Button","TextControl","__experimentalHStack","HStack","__experimentalVStack","VStack","ToggleControl","symbol","useDispatch","useSelect","__","_x","sprintf","noticesStore","coreStore","unlock","jsx","_jsx","jsxs","_jsxs","Fragment","_Fragment","useReusableBlocksRenameHint","ReusableBlocksRenameHint","ReusableBlockConvertButton","clientIds","rootClientId","onClose","showRenameHint","syncType","setSyncType","undefined","isModalOpen","setIsModalOpen","title","setTitle","canConvert","select","_getBlocksByClientId","canUser","getBlocksByClientId","canInsertBlockType","getBlockRootClientId","rootId","length","blocks","isReusable","getEntityRecord","attributes","ref","_canConvert","every","block","isValid","name","__experimentalConvertBlocksToReusable","convertBlocksToReusable","createSuccessNotice","createErrorNotice","onConvert","reusableBlockTitle","type","id","error","message","children","icon","onClick","onRequestClose","overlayClassName","onSubmit","event","preventDefault","spacing","__nextHasNoMarginBottom","label","value","onChange","placeholder","help","checked","justify","variant"],"sources":["@wordpress/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { hasBlockSupport, isReusableBlock } from '@wordpress/blocks';\nimport {\n\tstore as blockEditorStore,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { useCallback, useState } from '@wordpress/element';\nimport {\n\tMenuItem,\n\tModal,\n\tButton,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\tToggleControl,\n} from '@wordpress/components';\nimport { symbol } from '@wordpress/icons';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\nconst { useReusableBlocksRenameHint, ReusableBlocksRenameHint } = unlock(\n\tblockEditorPrivateApis\n);\n\n/**\n * Menu control to convert block(s) to reusable block.\n *\n * @param {Object} props Component props.\n * @param {string[]} props.clientIds Client ids of selected blocks.\n * @param {string} props.rootClientId ID of the currently selected top-level block.\n * @param {()=>void} props.onClose Callback to close the menu.\n * @return {import('react').ComponentType} The menu control or null.\n */\nexport default function ReusableBlockConvertButton( {\n\tclientIds,\n\trootClientId,\n\tonClose,\n} ) {\n\tconst showRenameHint = useReusableBlocksRenameHint();\n\tconst [ syncType, setSyncType ] = useState( undefined );\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst [ title, setTitle ] = useState( '' );\n\tconst canConvert = useSelect(\n\t\t( select ) => {\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst {\n\t\t\t\tgetBlocksByClientId,\n\t\t\t\tcanInsertBlockType,\n\t\t\t\tgetBlockRootClientId,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tconst rootId =\n\t\t\t\trootClientId ||\n\t\t\t\t( clientIds.length > 0\n\t\t\t\t\t? getBlockRootClientId( clientIds[ 0 ] )\n\t\t\t\t\t: undefined );\n\n\t\t\tconst blocks = getBlocksByClientId( clientIds ) ?? [];\n\n\t\t\tconst isReusable =\n\t\t\t\tblocks.length === 1 &&\n\t\t\t\tblocks[ 0 ] &&\n\t\t\t\tisReusableBlock( blocks[ 0 ] ) &&\n\t\t\t\t!! select( coreStore ).getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_block',\n\t\t\t\t\tblocks[ 0 ].attributes.ref\n\t\t\t\t);\n\n\t\t\tconst _canConvert =\n\t\t\t\t// Hide when this is already a reusable block.\n\t\t\t\t! isReusable &&\n\t\t\t\t// Hide when reusable blocks are disabled.\n\t\t\t\tcanInsertBlockType( 'core/block', rootId ) &&\n\t\t\t\tblocks.every(\n\t\t\t\t\t( block ) =>\n\t\t\t\t\t\t// Guard against the case where a regular block has *just* been converted.\n\t\t\t\t\t\t!! block &&\n\t\t\t\t\t\t// Hide on invalid blocks.\n\t\t\t\t\t\tblock.isValid &&\n\t\t\t\t\t\t// Hide when block doesn't support being made reusable.\n\t\t\t\t\t\thasBlockSupport( block.name, 'reusable', true )\n\t\t\t\t) &&\n\t\t\t\t// Hide when current doesn't have permission to do that.\n\t\t\t\t// Blocks refers to the wp_block post type, this checks the ability to create a post of that type.\n\t\t\t\t!! canUser( 'create', 'blocks' );\n\n\t\t\treturn _canConvert;\n\t\t},\n\t\t[ clientIds, rootClientId ]\n\t);\n\n\tconst { __experimentalConvertBlocksToReusable: convertBlocksToReusable } =\n\t\tuseDispatch( store );\n\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\tconst onConvert = useCallback(\n\t\tasync function ( reusableBlockTitle ) {\n\t\t\ttry {\n\t\t\t\tawait convertBlocksToReusable(\n\t\t\t\t\tclientIds,\n\t\t\t\t\treusableBlockTitle,\n\t\t\t\t\tsyncType\n\t\t\t\t);\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\t! syncType\n\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t\t\t__( 'Synced pattern created: %s' ),\n\t\t\t\t\t\t\t\treusableBlockTitle\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t\t\t__( 'Unsynced pattern created: %s' ),\n\t\t\t\t\t\t\t\treusableBlockTitle\n\t\t\t\t\t\t ),\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tid: 'convert-to-reusable-block-success',\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} catch ( error ) {\n\t\t\t\tcreateErrorNotice( error.message, {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tid: 'convert-to-reusable-block-error',\n\t\t\t\t} );\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\tconvertBlocksToReusable,\n\t\t\tclientIds,\n\t\t\tsyncType,\n\t\t\tcreateSuccessNotice,\n\t\t\tcreateErrorNotice,\n\t\t]\n\t);\n\n\tif ( ! canConvert ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<MenuItem icon={ symbol } onClick={ () => setIsModalOpen( true ) }>\n\t\t\t\t{ showRenameHint\n\t\t\t\t\t? __( 'Create pattern/reusable block' )\n\t\t\t\t\t: __( 'Create pattern' ) }\n\t\t\t</MenuItem>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Create pattern' ) }\n\t\t\t\t\tonRequestClose={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t} }\n\t\t\t\t\toverlayClassName=\"reusable-blocks-menu-items__convert-modal\"\n\t\t\t\t>\n\t\t\t\t\t<form\n\t\t\t\t\t\tonSubmit={ ( event ) => {\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\tonConvert( title );\n\t\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t\t\t<ReusableBlocksRenameHint />\n\t\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\t\t\tplaceholder={ __( 'My pattern' ) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\tlabel={ _x( 'Synced', 'pattern (singular)' ) }\n\t\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t\t'Sync this pattern across multiple locations.'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tchecked={ ! syncType }\n\t\t\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\t\t\tsetSyncType(\n\t\t\t\t\t\t\t\t\t\t! syncType ? 'unsynced' : undefined\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t\t\t</Button>\n\n\t\t\t\t\t\t\t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,OAAO;YAAAhB,QAAA,gBACtBhD,IAAA,CAACjB,MAAM;cACNkF,OAAO,EAAC,UAAU;cAClBf,OAAO,EAAGA,CAAA,KAAM;gBACflC,cAAc,CAAE,KAAM,CAAC;gBACvBE,QAAQ,CAAE,EAAG,CAAC;cACf,CAAG;cAAA8B,QAAA,EAEDvD,EAAE,CAAE,QAAS;YAAC,CACT,CAAC,eAETO,IAAA,CAACjB,MAAM;cAACkF,OAAO,EAAC,SAAS;cAACrB,IAAI,EAAC,QAAQ;cAAAI,QAAA,EACpCvD,EAAE,CAAE,QAAS;YAAC,CACT,CAAC;UAAA,CACF,CAAC;QAAA,CACF;MAAC,CACJ;IAAC,CACD,CACP;EAAA,CACA,CAAC;AAEL","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/reusable-blocks",
|
|
3
|
-
"version": "5.0
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "Reusable blocks utilities.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -30,17 +30,17 @@
|
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@babel/runtime": "^7.16.0",
|
|
33
|
-
"@wordpress/block-editor": "^13.0
|
|
34
|
-
"@wordpress/blocks": "^13.0
|
|
35
|
-
"@wordpress/components": "^28.0
|
|
36
|
-
"@wordpress/core-data": "^7.0
|
|
37
|
-
"@wordpress/data": "^10.0
|
|
38
|
-
"@wordpress/element": "^6.0
|
|
39
|
-
"@wordpress/i18n": "^5.0
|
|
40
|
-
"@wordpress/icons": "^10.0
|
|
41
|
-
"@wordpress/notices": "^5.0
|
|
42
|
-
"@wordpress/private-apis": "^1.0
|
|
43
|
-
"@wordpress/url": "^4.0
|
|
33
|
+
"@wordpress/block-editor": "^13.2.0",
|
|
34
|
+
"@wordpress/blocks": "^13.2.0",
|
|
35
|
+
"@wordpress/components": "^28.2.0",
|
|
36
|
+
"@wordpress/core-data": "^7.2.0",
|
|
37
|
+
"@wordpress/data": "^10.2.0",
|
|
38
|
+
"@wordpress/element": "^6.2.0",
|
|
39
|
+
"@wordpress/i18n": "^5.2.0",
|
|
40
|
+
"@wordpress/icons": "^10.2.0",
|
|
41
|
+
"@wordpress/notices": "^5.2.0",
|
|
42
|
+
"@wordpress/private-apis": "^1.2.0",
|
|
43
|
+
"@wordpress/url": "^4.2.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"react": "^18.0.0",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "aa5b14bb5bdbb8d8a02914e154c3bc1c2f18ace6"
|
|
53
53
|
}
|
|
@@ -92,6 +92,7 @@ export default function ReusableBlockConvertButton( {
|
|
|
92
92
|
hasBlockSupport( block.name, 'reusable', true )
|
|
93
93
|
) &&
|
|
94
94
|
// Hide when current doesn't have permission to do that.
|
|
95
|
+
// Blocks refers to the wp_block post type, this checks the ability to create a post of that type.
|
|
95
96
|
!! canUser( 'create', 'blocks' );
|
|
96
97
|
|
|
97
98
|
return _canConvert;
|