@wordpress/reusable-blocks 5.3.0 → 5.4.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 +2 -0
- package/build/components/reusable-blocks-menu-items/reusable-block-convert-button.js +7 -12
- package/build/components/reusable-blocks-menu-items/reusable-block-convert-button.js.map +1 -1
- package/build/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js +9 -2
- package/build/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js.map +1 -1
- package/build-module/components/reusable-blocks-menu-items/reusable-block-convert-button.js +10 -13
- package/build-module/components/reusable-blocks-menu-items/reusable-block-convert-button.js.map +1 -1
- package/build-module/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js +9 -2
- package/build-module/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js.map +1 -1
- package/package.json +13 -13
- package/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js +6 -15
- package/src/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js +9 -6
package/CHANGELOG.md
CHANGED
|
@@ -14,7 +14,6 @@ var _i18n = require("@wordpress/i18n");
|
|
|
14
14
|
var _notices = require("@wordpress/notices");
|
|
15
15
|
var _coreData = require("@wordpress/core-data");
|
|
16
16
|
var _store = require("../../store");
|
|
17
|
-
var _lockUnlock = require("../../lock-unlock");
|
|
18
17
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
19
18
|
/**
|
|
20
19
|
* WordPress dependencies
|
|
@@ -24,11 +23,6 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
24
23
|
* Internal dependencies
|
|
25
24
|
*/
|
|
26
25
|
|
|
27
|
-
const {
|
|
28
|
-
useReusableBlocksRenameHint,
|
|
29
|
-
ReusableBlocksRenameHint
|
|
30
|
-
} = (0, _lockUnlock.unlock)(_blockEditor.privateApis);
|
|
31
|
-
|
|
32
26
|
/**
|
|
33
27
|
* Menu control to convert block(s) to reusable block.
|
|
34
28
|
*
|
|
@@ -37,13 +31,11 @@ const {
|
|
|
37
31
|
* @param {string} props.rootClientId ID of the currently selected top-level block.
|
|
38
32
|
* @param {()=>void} props.onClose Callback to close the menu.
|
|
39
33
|
* @return {import('react').ComponentType} The menu control or null.
|
|
40
|
-
*/
|
|
41
|
-
function ReusableBlockConvertButton({
|
|
34
|
+
*/function ReusableBlockConvertButton({
|
|
42
35
|
clientIds,
|
|
43
36
|
rootClientId,
|
|
44
37
|
onClose
|
|
45
38
|
}) {
|
|
46
|
-
const showRenameHint = useReusableBlocksRenameHint();
|
|
47
39
|
const [syncType, setSyncType] = (0, _element.useState)(undefined);
|
|
48
40
|
const [isModalOpen, setIsModalOpen] = (0, _element.useState)(false);
|
|
49
41
|
const [title, setTitle] = (0, _element.useState)('');
|
|
@@ -73,7 +65,10 @@ function ReusableBlockConvertButton({
|
|
|
73
65
|
(0, _blocks.hasBlockSupport)(block.name, 'reusable', true)) &&
|
|
74
66
|
// Hide when current doesn't have permission to do that.
|
|
75
67
|
// Blocks refers to the wp_block post type, this checks the ability to create a post of that type.
|
|
76
|
-
!!canUser('create',
|
|
68
|
+
!!canUser('create', {
|
|
69
|
+
kind: 'postType',
|
|
70
|
+
name: 'wp_block'
|
|
71
|
+
});
|
|
77
72
|
return _canConvert;
|
|
78
73
|
}, [clientIds, rootClientId]);
|
|
79
74
|
const {
|
|
@@ -108,7 +103,7 @@ function ReusableBlockConvertButton({
|
|
|
108
103
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.MenuItem, {
|
|
109
104
|
icon: _icons.symbol,
|
|
110
105
|
onClick: () => setIsModalOpen(true),
|
|
111
|
-
children:
|
|
106
|
+
children: (0, _i18n.__)('Create pattern')
|
|
112
107
|
}), isModalOpen && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Modal, {
|
|
113
108
|
title: (0, _i18n.__)('Create pattern'),
|
|
114
109
|
onRequestClose: () => {
|
|
@@ -126,7 +121,7 @@ function ReusableBlockConvertButton({
|
|
|
126
121
|
},
|
|
127
122
|
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalVStack, {
|
|
128
123
|
spacing: "5",
|
|
129
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
124
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.TextControl, {
|
|
130
125
|
__nextHasNoMarginBottom: true,
|
|
131
126
|
label: (0, _i18n.__)('Name'),
|
|
132
127
|
value: title,
|
|
@@ -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// 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\t\t</form>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],"mappings":";;;;;;AAGA,IAAAA,OAAA,GAAAC,OAAA;AACA,I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G;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","_jsxRuntime","ReusableBlockConvertButton","clientIds","rootClientId","onClose","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","kind","__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 { store as blockEditorStore } 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';\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 [ 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', {\n\t\t\t\t\tkind: 'postType',\n\t\t\t\t\tname: 'wp_block',\n\t\t\t\t} );\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{ __( '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<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\t\t</Modal>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],"mappings":";;;;;;AAGA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AASA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,KAAA,GAAAN,OAAA;AACA,IAAAO,QAAA,GAAAP,OAAA;AACA,IAAAQ,SAAA,GAAAR,OAAA;A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tBwB,KAAK,EAAG9D,KAAO;YACf+D,QAAQ,EAAG9D,QAAU;YACrB+D,WAAW,EAAG,IAAA1B,QAAE,EAAE,YAAa;UAAG,CAClC,CAAC,eACF,IAAAjD,WAAA,CAAAyD,GAAA,EAAChE,WAAA,CAAAmF,aAAa;YACbJ,KAAK,EAAG,IAAAK,QAAE,EAAE,QAAQ,EAAE,oBAAqB,CAAG;YAC9CC,IAAI,EAAG,IAAA7B,QAAE,EACR,8CACD,CAAG;YACH8B,OAAO,EAAG,CAAE1E,QAAU;YACtBqE,QAAQ,EAAGA,CAAA,KAAM;cAChBpE,WAAW,CACV,CAAED,QAAQ,GAAG,UAAU,GAAGG,SAC3B,CAAC;YACF;UAAG,CACH,CAAC,eACF,IAAAR,WAAA,CAAAsD,IAAA,EAAC7D,WAAA,CAAAuF,oBAAM;YAACC,OAAO,EAAC,OAAO;YAAAzB,QAAA,gBACtB,IAAAxD,WAAA,CAAAyD,GAAA,EAAChE,WAAA,CAAAyF,MAAM;cACNC,OAAO,EAAC,UAAU;cAClBtB,OAAO,EAAGA,CAAA,KAAM;gBACfnD,cAAc,CAAE,KAAM,CAAC;gBACvBE,QAAQ,CAAE,EAAG,CAAC;cACf,CAAG;cAAA4C,QAAA,EAED,IAAAP,QAAE,EAAE,QAAS;YAAC,CACT,CAAC,eAET,IAAAjD,WAAA,CAAAyD,GAAA,EAAChE,WAAA,CAAAyF,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":[]}
|
|
@@ -40,12 +40,19 @@ function ReusableBlocksManageButton({
|
|
|
40
40
|
const reusableBlock = getBlock(clientId);
|
|
41
41
|
return {
|
|
42
42
|
canRemove: canRemoveBlock(clientId),
|
|
43
|
-
isVisible: !!reusableBlock && (0, _blocks.isReusableBlock)(reusableBlock) && !!canUser('update',
|
|
43
|
+
isVisible: !!reusableBlock && (0, _blocks.isReusableBlock)(reusableBlock) && !!canUser('update', {
|
|
44
|
+
kind: 'postType',
|
|
45
|
+
name: 'wp_block',
|
|
46
|
+
id: reusableBlock.attributes.ref
|
|
47
|
+
}),
|
|
44
48
|
innerBlockCount: getBlockCount(clientId),
|
|
45
49
|
// The site editor and templates both check whether the user
|
|
46
50
|
// has edit_theme_options capabilities. We can leverage that here
|
|
47
51
|
// and omit the manage patterns link if the user can't access it.
|
|
48
|
-
managePatternsUrl: canUser('create',
|
|
52
|
+
managePatternsUrl: canUser('create', {
|
|
53
|
+
kind: 'postType',
|
|
54
|
+
name: 'wp_template'
|
|
55
|
+
}) ? (0, _url.addQueryArgs)('site-editor.php', {
|
|
49
56
|
path: '/patterns'
|
|
50
57
|
}) : (0, _url.addQueryArgs)('edit.php', {
|
|
51
58
|
post_type: 'wp_block'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_components","require","_i18n","_blocks","_data","_blockEditor","_url","_coreData","_store","_jsxRuntime","ReusableBlocksManageButton","clientId","canRemove","isVisible","managePatternsUrl","useSelect","select","getBlock","canRemoveBlock","getBlockCount","blockEditorStore","canUser","coreStore","reusableBlock","isReusableBlock","attributes","ref","innerBlockCount","addQueryArgs","path","post_type","__experimentalConvertBlockToStatic","convertBlockToStatic","useDispatch","reusableBlocksStore","jsxs","Fragment","children","jsx","MenuItem","href","__","onClick","_default","exports","default"],"sources":["@wordpress/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { MenuItem } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { isReusableBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { addQueryArgs } from '@wordpress/url';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as reusableBlocksStore } from '../../store';\n\nfunction ReusableBlocksManageButton( { clientId } ) {\n\tconst { canRemove, isVisible, managePatternsUrl } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlock, canRemoveBlock, getBlockCount } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst reusableBlock = getBlock( clientId );\n\n\t\t\treturn {\n\t\t\t\tcanRemove: canRemoveBlock( clientId ),\n\t\t\t\tisVisible:\n\t\t\t\t\t!! reusableBlock &&\n\t\t\t\t\tisReusableBlock( reusableBlock ) &&\n\t\t\t\t\t!! canUser(\n\t\t\t\t\t\
|
|
1
|
+
{"version":3,"names":["_components","require","_i18n","_blocks","_data","_blockEditor","_url","_coreData","_store","_jsxRuntime","ReusableBlocksManageButton","clientId","canRemove","isVisible","managePatternsUrl","useSelect","select","getBlock","canRemoveBlock","getBlockCount","blockEditorStore","canUser","coreStore","reusableBlock","isReusableBlock","kind","name","id","attributes","ref","innerBlockCount","addQueryArgs","path","post_type","__experimentalConvertBlockToStatic","convertBlockToStatic","useDispatch","reusableBlocksStore","jsxs","Fragment","children","jsx","MenuItem","href","__","onClick","_default","exports","default"],"sources":["@wordpress/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { MenuItem } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { isReusableBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { addQueryArgs } from '@wordpress/url';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as reusableBlocksStore } from '../../store';\n\nfunction ReusableBlocksManageButton( { clientId } ) {\n\tconst { canRemove, isVisible, managePatternsUrl } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlock, canRemoveBlock, getBlockCount } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst reusableBlock = getBlock( clientId );\n\n\t\t\treturn {\n\t\t\t\tcanRemove: canRemoveBlock( clientId ),\n\t\t\t\tisVisible:\n\t\t\t\t\t!! reusableBlock &&\n\t\t\t\t\tisReusableBlock( reusableBlock ) &&\n\t\t\t\t\t!! canUser( 'update', {\n\t\t\t\t\t\tkind: 'postType',\n\t\t\t\t\t\tname: 'wp_block',\n\t\t\t\t\t\tid: reusableBlock.attributes.ref,\n\t\t\t\t\t} ),\n\t\t\t\tinnerBlockCount: getBlockCount( clientId ),\n\t\t\t\t// The site editor and templates both check whether the user\n\t\t\t\t// has edit_theme_options capabilities. We can leverage that here\n\t\t\t\t// and omit the manage patterns link if the user can't access it.\n\t\t\t\tmanagePatternsUrl: canUser( 'create', {\n\t\t\t\t\tkind: 'postType',\n\t\t\t\t\tname: 'wp_template',\n\t\t\t\t} )\n\t\t\t\t\t? addQueryArgs( 'site-editor.php', {\n\t\t\t\t\t\t\tpath: '/patterns',\n\t\t\t\t\t } )\n\t\t\t\t\t: addQueryArgs( 'edit.php', {\n\t\t\t\t\t\t\tpost_type: 'wp_block',\n\t\t\t\t\t } ),\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst { __experimentalConvertBlockToStatic: convertBlockToStatic } =\n\t\tuseDispatch( reusableBlocksStore );\n\n\tif ( ! isVisible ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<MenuItem href={ managePatternsUrl }>\n\t\t\t\t{ __( 'Manage patterns' ) }\n\t\t\t</MenuItem>\n\t\t\t{ canRemove && (\n\t\t\t\t<MenuItem onClick={ () => convertBlockToStatic( clientId ) }>\n\t\t\t\t\t{ __( 'Detach' ) }\n\t\t\t\t</MenuItem>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default ReusableBlocksManageButton;\n"],"mappings":";;;;;;AAGA,IAAAA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AAE,UAAU,EAAE;QAC1BE,SAAS,EAAE;MACX,CAAE;IACN,CAAC;EACF,CAAC,EACD,CAAEtB,QAAQ,CACX,CAAC;EAED,MAAM;IAAEuB,kCAAkC,EAAEC;EAAqB,CAAC,GACjE,IAAAC,iBAAW,EAAEC,YAAoB,CAAC;EAEnC,IAAK,CAAExB,SAAS,EAAG;IAClB,OAAO,IAAI;EACZ;EAEA,oBACC,IAAAJ,WAAA,CAAA6B,IAAA,EAAA7B,WAAA,CAAA8B,QAAA;IAAAC,QAAA,gBACC,IAAA/B,WAAA,CAAAgC,GAAA,EAACzC,WAAA,CAAA0C,QAAQ;MAACC,IAAI,EAAG7B,iBAAmB;MAAA0B,QAAA,EACjC,IAAAI,QAAE,EAAE,iBAAkB;IAAC,CAChB,CAAC,EACThC,SAAS,iBACV,IAAAH,WAAA,CAAAgC,GAAA,EAACzC,WAAA,CAAA0C,QAAQ;MAACG,OAAO,EAAGA,CAAA,KAAMV,oBAAoB,CAAExB,QAAS,CAAG;MAAA6B,QAAA,EACzD,IAAAI,QAAE,EAAE,QAAS;IAAC,CACP,CACV;EAAA,CACA,CAAC;AAEL;AAAC,IAAAE,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEctC,0BAA0B","ignoreList":[]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { hasBlockSupport, isReusableBlock } from '@wordpress/blocks';
|
|
5
|
-
import { store as blockEditorStore
|
|
5
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
6
6
|
import { useCallback, useState } from '@wordpress/element';
|
|
7
7
|
import { MenuItem, Modal, Button, TextControl, __experimentalHStack as HStack, __experimentalVStack as VStack, ToggleControl } from '@wordpress/components';
|
|
8
8
|
import { symbol } from '@wordpress/icons';
|
|
@@ -15,14 +15,6 @@ import { store as coreStore } from '@wordpress/core-data';
|
|
|
15
15
|
* Internal dependencies
|
|
16
16
|
*/
|
|
17
17
|
import { store } from '../../store';
|
|
18
|
-
import { unlock } from '../../lock-unlock';
|
|
19
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
20
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
21
|
-
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
22
|
-
const {
|
|
23
|
-
useReusableBlocksRenameHint,
|
|
24
|
-
ReusableBlocksRenameHint
|
|
25
|
-
} = unlock(blockEditorPrivateApis);
|
|
26
18
|
|
|
27
19
|
/**
|
|
28
20
|
* Menu control to convert block(s) to reusable block.
|
|
@@ -33,12 +25,14 @@ const {
|
|
|
33
25
|
* @param {()=>void} props.onClose Callback to close the menu.
|
|
34
26
|
* @return {import('react').ComponentType} The menu control or null.
|
|
35
27
|
*/
|
|
28
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
29
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
30
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
36
31
|
export default function ReusableBlockConvertButton({
|
|
37
32
|
clientIds,
|
|
38
33
|
rootClientId,
|
|
39
34
|
onClose
|
|
40
35
|
}) {
|
|
41
|
-
const showRenameHint = useReusableBlocksRenameHint();
|
|
42
36
|
const [syncType, setSyncType] = useState(undefined);
|
|
43
37
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
44
38
|
const [title, setTitle] = useState('');
|
|
@@ -68,7 +62,10 @@ export default function ReusableBlockConvertButton({
|
|
|
68
62
|
hasBlockSupport(block.name, 'reusable', true)) &&
|
|
69
63
|
// Hide when current doesn't have permission to do that.
|
|
70
64
|
// Blocks refers to the wp_block post type, this checks the ability to create a post of that type.
|
|
71
|
-
!!canUser('create',
|
|
65
|
+
!!canUser('create', {
|
|
66
|
+
kind: 'postType',
|
|
67
|
+
name: 'wp_block'
|
|
68
|
+
});
|
|
72
69
|
return _canConvert;
|
|
73
70
|
}, [clientIds, rootClientId]);
|
|
74
71
|
const {
|
|
@@ -103,7 +100,7 @@ export default function ReusableBlockConvertButton({
|
|
|
103
100
|
children: [/*#__PURE__*/_jsx(MenuItem, {
|
|
104
101
|
icon: symbol,
|
|
105
102
|
onClick: () => setIsModalOpen(true),
|
|
106
|
-
children:
|
|
103
|
+
children: __('Create pattern')
|
|
107
104
|
}), isModalOpen && /*#__PURE__*/_jsx(Modal, {
|
|
108
105
|
title: __('Create pattern'),
|
|
109
106
|
onRequestClose: () => {
|
|
@@ -121,7 +118,7 @@ export default function ReusableBlockConvertButton({
|
|
|
121
118
|
},
|
|
122
119
|
children: /*#__PURE__*/_jsxs(VStack, {
|
|
123
120
|
spacing: "5",
|
|
124
|
-
children: [/*#__PURE__*/_jsx(
|
|
121
|
+
children: [/*#__PURE__*/_jsx(TextControl, {
|
|
125
122
|
__nextHasNoMarginBottom: true,
|
|
126
123
|
label: __('Name'),
|
|
127
124
|
value: title,
|
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// 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<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AO;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","useCallback","useState","MenuItem","Modal","Button","TextControl","__experimentalHStack","HStack","__experimentalVStack","VStack","ToggleControl","symbol","useDispatch","useSelect","__","_x","sprintf","noticesStore","coreStore","jsx","_jsx","jsxs","_jsxs","Fragment","_Fragment","ReusableBlockConvertButton","clientIds","rootClientId","onClose","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","kind","__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 { store as blockEditorStore } 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';\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 [ 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', {\n\t\t\t\t\tkind: 'postType',\n\t\t\t\t\tname: 'wp_block',\n\t\t\t\t} );\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{ __( '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<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\t\t</Modal>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAe,EAAEC,eAAe,QAAQ,mBAAmB;AACpE,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,yBAAyB;AACnE,SAASC,WAAW,EAAEC,QAAQ,QAAQ,oBAAoB;AAC1D,SACCC,QAAQ,EACRC,KAAK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AACb,MAAM;UAACiE,OAAO,EAAC,GAAG;UAAAR,QAAA,gBAClB9C,IAAA,CAACf,WAAW;YACXsE,uBAAuB;YACvBC,KAAK,EAAG9D,EAAE,CAAE,MAAO,CAAG;YACtB+D,KAAK,EAAG3C,KAAO;YACf4C,QAAQ,EAAG3C,QAAU;YACrB4C,WAAW,EAAGjE,EAAE,CAAE,YAAa;UAAG,CAClC,CAAC,eACFM,IAAA,CAACV,aAAa;YACbkE,KAAK,EAAG7D,EAAE,CAAE,QAAQ,EAAE,oBAAqB,CAAG;YAC9CiE,IAAI,EAAGlE,EAAE,CACR,8CACD,CAAG;YACHmE,OAAO,EAAG,CAAEpD,QAAU;YACtBiD,QAAQ,EAAGA,CAAA,KAAM;cAChBhD,WAAW,CACV,CAAED,QAAQ,GAAG,UAAU,GAAGE,SAC3B,CAAC;YACF;UAAG,CACH,CAAC,eACFT,KAAA,CAACf,MAAM;YAAC2E,OAAO,EAAC,OAAO;YAAAhB,QAAA,gBACtB9C,IAAA,CAAChB,MAAM;cACN+E,OAAO,EAAC,UAAU;cAClBf,OAAO,EAAGA,CAAA,KAAM;gBACfnC,cAAc,CAAE,KAAM,CAAC;gBACvBE,QAAQ,CAAE,EAAG,CAAC;cACf,CAAG;cAAA+B,QAAA,EAEDpD,EAAE,CAAE,QAAS;YAAC,CACT,CAAC,eAETM,IAAA,CAAChB,MAAM;cAAC+E,OAAO,EAAC,SAAS;cAACrB,IAAI,EAAC,QAAQ;cAAAI,QAAA,EACpCpD,EAAE,CAAE,QAAS;YAAC,CACT,CAAC;UAAA,CACF,CAAC;QAAA,CACF;MAAC,CACJ;IAAC,CACD,CACP;EAAA,CACA,CAAC;AAEL","ignoreList":[]}
|
|
@@ -35,12 +35,19 @@ function ReusableBlocksManageButton({
|
|
|
35
35
|
const reusableBlock = getBlock(clientId);
|
|
36
36
|
return {
|
|
37
37
|
canRemove: canRemoveBlock(clientId),
|
|
38
|
-
isVisible: !!reusableBlock && isReusableBlock(reusableBlock) && !!canUser('update',
|
|
38
|
+
isVisible: !!reusableBlock && isReusableBlock(reusableBlock) && !!canUser('update', {
|
|
39
|
+
kind: 'postType',
|
|
40
|
+
name: 'wp_block',
|
|
41
|
+
id: reusableBlock.attributes.ref
|
|
42
|
+
}),
|
|
39
43
|
innerBlockCount: getBlockCount(clientId),
|
|
40
44
|
// The site editor and templates both check whether the user
|
|
41
45
|
// has edit_theme_options capabilities. We can leverage that here
|
|
42
46
|
// and omit the manage patterns link if the user can't access it.
|
|
43
|
-
managePatternsUrl: canUser('create',
|
|
47
|
+
managePatternsUrl: canUser('create', {
|
|
48
|
+
kind: 'postType',
|
|
49
|
+
name: 'wp_template'
|
|
50
|
+
}) ? addQueryArgs('site-editor.php', {
|
|
44
51
|
path: '/patterns'
|
|
45
52
|
}) : addQueryArgs('edit.php', {
|
|
46
53
|
post_type: 'wp_block'
|
package/build-module/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["MenuItem","__","isReusableBlock","useSelect","useDispatch","store","blockEditorStore","addQueryArgs","coreStore","reusableBlocksStore","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","ReusableBlocksManageButton","clientId","canRemove","isVisible","managePatternsUrl","select","getBlock","canRemoveBlock","getBlockCount","canUser","reusableBlock","attributes","ref","innerBlockCount","path","post_type","__experimentalConvertBlockToStatic","convertBlockToStatic","children","href","onClick"],"sources":["@wordpress/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { MenuItem } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { isReusableBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { addQueryArgs } from '@wordpress/url';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as reusableBlocksStore } from '../../store';\n\nfunction ReusableBlocksManageButton( { clientId } ) {\n\tconst { canRemove, isVisible, managePatternsUrl } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlock, canRemoveBlock, getBlockCount } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst reusableBlock = getBlock( clientId );\n\n\t\t\treturn {\n\t\t\t\tcanRemove: canRemoveBlock( clientId ),\n\t\t\t\tisVisible:\n\t\t\t\t\t!! reusableBlock &&\n\t\t\t\t\tisReusableBlock( reusableBlock ) &&\n\t\t\t\t\t!! canUser(\n\t\t\t\t\t\
|
|
1
|
+
{"version":3,"names":["MenuItem","__","isReusableBlock","useSelect","useDispatch","store","blockEditorStore","addQueryArgs","coreStore","reusableBlocksStore","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","ReusableBlocksManageButton","clientId","canRemove","isVisible","managePatternsUrl","select","getBlock","canRemoveBlock","getBlockCount","canUser","reusableBlock","kind","name","id","attributes","ref","innerBlockCount","path","post_type","__experimentalConvertBlockToStatic","convertBlockToStatic","children","href","onClick"],"sources":["@wordpress/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { MenuItem } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { isReusableBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { addQueryArgs } from '@wordpress/url';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as reusableBlocksStore } from '../../store';\n\nfunction ReusableBlocksManageButton( { clientId } ) {\n\tconst { canRemove, isVisible, managePatternsUrl } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlock, canRemoveBlock, getBlockCount } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst reusableBlock = getBlock( clientId );\n\n\t\t\treturn {\n\t\t\t\tcanRemove: canRemoveBlock( clientId ),\n\t\t\t\tisVisible:\n\t\t\t\t\t!! reusableBlock &&\n\t\t\t\t\tisReusableBlock( reusableBlock ) &&\n\t\t\t\t\t!! canUser( 'update', {\n\t\t\t\t\t\tkind: 'postType',\n\t\t\t\t\t\tname: 'wp_block',\n\t\t\t\t\t\tid: reusableBlock.attributes.ref,\n\t\t\t\t\t} ),\n\t\t\t\tinnerBlockCount: getBlockCount( clientId ),\n\t\t\t\t// The site editor and templates both check whether the user\n\t\t\t\t// has edit_theme_options capabilities. We can leverage that here\n\t\t\t\t// and omit the manage patterns link if the user can't access it.\n\t\t\t\tmanagePatternsUrl: canUser( 'create', {\n\t\t\t\t\tkind: 'postType',\n\t\t\t\t\tname: 'wp_template',\n\t\t\t\t} )\n\t\t\t\t\t? addQueryArgs( 'site-editor.php', {\n\t\t\t\t\t\t\tpath: '/patterns',\n\t\t\t\t\t } )\n\t\t\t\t\t: addQueryArgs( 'edit.php', {\n\t\t\t\t\t\t\tpost_type: 'wp_block',\n\t\t\t\t\t } ),\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst { __experimentalConvertBlockToStatic: convertBlockToStatic } =\n\t\tuseDispatch( reusableBlocksStore );\n\n\tif ( ! isVisible ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<MenuItem href={ managePatternsUrl }>\n\t\t\t\t{ __( 'Manage patterns' ) }\n\t\t\t</MenuItem>\n\t\t\t{ canRemove && (\n\t\t\t\t<MenuItem onClick={ () => convertBlockToStatic( clientId ) }>\n\t\t\t\t\t{ __( 'Detach' ) }\n\t\t\t\t</MenuItem>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default ReusableBlocksManageButton;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,QAAQ,QAAQ,uBAAuB;AAChD,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,eAAe,QAAQ,mB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AC,GACH1B,YAAY,CAAE,UAAU,EAAE;QAC1B2B,SAAS,EAAE;MACX,CAAE;IACN,CAAC;EACF,CAAC,EACD,CAAEjB,QAAQ,CACX,CAAC;EAED,MAAM;IAAEkB,kCAAkC,EAAEC;EAAqB,CAAC,GACjEhC,WAAW,CAAEK,mBAAoB,CAAC;EAEnC,IAAK,CAAEU,SAAS,EAAG;IAClB,OAAO,IAAI;EACZ;EAEA,oBACCJ,KAAA,CAAAF,SAAA;IAAAwB,QAAA,gBACC1B,IAAA,CAACX,QAAQ;MAACsC,IAAI,EAAGlB,iBAAmB;MAAAiB,QAAA,EACjCpC,EAAE,CAAE,iBAAkB;IAAC,CAChB,CAAC,EACTiB,SAAS,iBACVP,IAAA,CAACX,QAAQ;MAACuC,OAAO,EAAGA,CAAA,KAAMH,oBAAoB,CAAEnB,QAAS,CAAG;MAAAoB,QAAA,EACzDpC,EAAE,CAAE,QAAS;IAAC,CACP,CACV;EAAA,CACA,CAAC;AAEL;AAEA,eAAee,0BAA0B","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/reusable-blocks",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.4.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.
|
|
34
|
-
"@wordpress/blocks": "^13.
|
|
35
|
-
"@wordpress/components": "^28.
|
|
36
|
-
"@wordpress/core-data": "^7.
|
|
37
|
-
"@wordpress/data": "^10.
|
|
38
|
-
"@wordpress/element": "^6.
|
|
39
|
-
"@wordpress/i18n": "^5.
|
|
40
|
-
"@wordpress/icons": "^10.
|
|
41
|
-
"@wordpress/notices": "^5.
|
|
42
|
-
"@wordpress/private-apis": "^1.
|
|
43
|
-
"@wordpress/url": "^4.
|
|
33
|
+
"@wordpress/block-editor": "^13.4.0",
|
|
34
|
+
"@wordpress/blocks": "^13.4.0",
|
|
35
|
+
"@wordpress/components": "^28.4.0",
|
|
36
|
+
"@wordpress/core-data": "^7.4.0",
|
|
37
|
+
"@wordpress/data": "^10.4.0",
|
|
38
|
+
"@wordpress/element": "^6.4.0",
|
|
39
|
+
"@wordpress/i18n": "^5.4.0",
|
|
40
|
+
"@wordpress/icons": "^10.4.0",
|
|
41
|
+
"@wordpress/notices": "^5.4.0",
|
|
42
|
+
"@wordpress/private-apis": "^1.4.0",
|
|
43
|
+
"@wordpress/url": "^4.4.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": "363edb39b8dda8727f652e42cbb8497732693ed2"
|
|
53
53
|
}
|
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { hasBlockSupport, isReusableBlock } from '@wordpress/blocks';
|
|
5
|
-
import {
|
|
6
|
-
store as blockEditorStore,
|
|
7
|
-
privateApis as blockEditorPrivateApis,
|
|
8
|
-
} from '@wordpress/block-editor';
|
|
5
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
9
6
|
import { useCallback, useState } from '@wordpress/element';
|
|
10
7
|
import {
|
|
11
8
|
MenuItem,
|
|
@@ -26,11 +23,6 @@ import { store as coreStore } from '@wordpress/core-data';
|
|
|
26
23
|
* Internal dependencies
|
|
27
24
|
*/
|
|
28
25
|
import { store } from '../../store';
|
|
29
|
-
import { unlock } from '../../lock-unlock';
|
|
30
|
-
|
|
31
|
-
const { useReusableBlocksRenameHint, ReusableBlocksRenameHint } = unlock(
|
|
32
|
-
blockEditorPrivateApis
|
|
33
|
-
);
|
|
34
26
|
|
|
35
27
|
/**
|
|
36
28
|
* Menu control to convert block(s) to reusable block.
|
|
@@ -46,7 +38,6 @@ export default function ReusableBlockConvertButton( {
|
|
|
46
38
|
rootClientId,
|
|
47
39
|
onClose,
|
|
48
40
|
} ) {
|
|
49
|
-
const showRenameHint = useReusableBlocksRenameHint();
|
|
50
41
|
const [ syncType, setSyncType ] = useState( undefined );
|
|
51
42
|
const [ isModalOpen, setIsModalOpen ] = useState( false );
|
|
52
43
|
const [ title, setTitle ] = useState( '' );
|
|
@@ -93,7 +84,10 @@ export default function ReusableBlockConvertButton( {
|
|
|
93
84
|
) &&
|
|
94
85
|
// Hide when current doesn't have permission to do that.
|
|
95
86
|
// Blocks refers to the wp_block post type, this checks the ability to create a post of that type.
|
|
96
|
-
!! canUser( 'create',
|
|
87
|
+
!! canUser( 'create', {
|
|
88
|
+
kind: 'postType',
|
|
89
|
+
name: 'wp_block',
|
|
90
|
+
} );
|
|
97
91
|
|
|
98
92
|
return _canConvert;
|
|
99
93
|
},
|
|
@@ -153,9 +147,7 @@ export default function ReusableBlockConvertButton( {
|
|
|
153
147
|
return (
|
|
154
148
|
<>
|
|
155
149
|
<MenuItem icon={ symbol } onClick={ () => setIsModalOpen( true ) }>
|
|
156
|
-
{
|
|
157
|
-
? __( 'Create pattern/reusable block' )
|
|
158
|
-
: __( 'Create pattern' ) }
|
|
150
|
+
{ __( 'Create pattern' ) }
|
|
159
151
|
</MenuItem>
|
|
160
152
|
{ isModalOpen && (
|
|
161
153
|
<Modal
|
|
@@ -176,7 +168,6 @@ export default function ReusableBlockConvertButton( {
|
|
|
176
168
|
} }
|
|
177
169
|
>
|
|
178
170
|
<VStack spacing="5">
|
|
179
|
-
<ReusableBlocksRenameHint />
|
|
180
171
|
<TextControl
|
|
181
172
|
__nextHasNoMarginBottom
|
|
182
173
|
label={ __( 'Name' ) }
|
|
@@ -27,16 +27,19 @@ function ReusableBlocksManageButton( { clientId } ) {
|
|
|
27
27
|
isVisible:
|
|
28
28
|
!! reusableBlock &&
|
|
29
29
|
isReusableBlock( reusableBlock ) &&
|
|
30
|
-
!! canUser(
|
|
31
|
-
'
|
|
32
|
-
'
|
|
33
|
-
reusableBlock.attributes.ref
|
|
34
|
-
),
|
|
30
|
+
!! canUser( 'update', {
|
|
31
|
+
kind: 'postType',
|
|
32
|
+
name: 'wp_block',
|
|
33
|
+
id: reusableBlock.attributes.ref,
|
|
34
|
+
} ),
|
|
35
35
|
innerBlockCount: getBlockCount( clientId ),
|
|
36
36
|
// The site editor and templates both check whether the user
|
|
37
37
|
// has edit_theme_options capabilities. We can leverage that here
|
|
38
38
|
// and omit the manage patterns link if the user can't access it.
|
|
39
|
-
managePatternsUrl: canUser( 'create',
|
|
39
|
+
managePatternsUrl: canUser( 'create', {
|
|
40
|
+
kind: 'postType',
|
|
41
|
+
name: 'wp_template',
|
|
42
|
+
} )
|
|
40
43
|
? addQueryArgs( 'site-editor.php', {
|
|
41
44
|
path: '/patterns',
|
|
42
45
|
} )
|