@wordpress/block-library 9.30.0 → 9.30.1-next.6870dfe5b.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/build/accordion-content/edit.js +8 -8
- package/build/accordion-content/edit.js.map +1 -1
- package/build/accordion-content/index.js +2 -1
- package/build/accordion-content/index.js.map +1 -1
- package/build/accordion-panel/index.js +2 -1
- package/build/accordion-panel/index.js.map +1 -1
- package/build/navigation/constants.js +5 -1
- package/build/navigation/constants.js.map +1 -1
- package/build/navigation/edit/index.js +45 -1
- package/build/navigation/edit/index.js.map +1 -1
- package/build/navigation/edit/leaf-more-menu.js +0 -1
- package/build/navigation/edit/leaf-more-menu.js.map +1 -1
- package/build/navigation/edit/menu-inspector-controls.js +40 -5
- package/build/navigation/edit/menu-inspector-controls.js.map +1 -1
- package/build/navigation-link/block-inserter.js +69 -0
- package/build/navigation-link/block-inserter.js.map +1 -0
- package/build/navigation-link/dialog-wrapper.js +80 -0
- package/build/navigation-link/dialog-wrapper.js.map +1 -0
- package/build/navigation-link/link-ui.js +80 -120
- package/build/navigation-link/link-ui.js.map +1 -1
- package/build/navigation-link/page-creator.js +137 -0
- package/build/navigation-link/page-creator.js.map +1 -0
- package/build/search/edit.js +22 -14
- package/build/search/edit.js.map +1 -1
- package/build-module/accordion-content/edit.js +8 -8
- package/build-module/accordion-content/edit.js.map +1 -1
- package/build-module/accordion-content/index.js +2 -1
- package/build-module/accordion-content/index.js.map +1 -1
- package/build-module/accordion-panel/index.js +2 -1
- package/build-module/accordion-panel/index.js.map +1 -1
- package/build-module/navigation/constants.js +5 -1
- package/build-module/navigation/constants.js.map +1 -1
- package/build-module/navigation/edit/index.js +50 -4
- package/build-module/navigation/edit/index.js.map +1 -1
- package/build-module/navigation/edit/leaf-more-menu.js +0 -1
- package/build-module/navigation/edit/leaf-more-menu.js.map +1 -1
- package/build-module/navigation/edit/menu-inspector-controls.js +40 -5
- package/build-module/navigation/edit/menu-inspector-controls.js.map +1 -1
- package/build-module/navigation-link/block-inserter.js +61 -0
- package/build-module/navigation-link/block-inserter.js.map +1 -0
- package/build-module/navigation-link/dialog-wrapper.js +75 -0
- package/build-module/navigation-link/dialog-wrapper.js.map +1 -0
- package/build-module/navigation-link/link-ui.js +85 -125
- package/build-module/navigation-link/link-ui.js.map +1 -1
- package/build-module/navigation-link/page-creator.js +130 -0
- package/build-module/navigation-link/page-creator.js.map +1 -0
- package/build-module/search/edit.js +22 -14
- package/build-module/search/edit.js.map +1 -1
- package/build-style/accordion/style-rtl.css +5 -6
- package/build-style/accordion/style.css +5 -6
- package/build-style/editor-rtl.css +14 -0
- package/build-style/editor.css +14 -0
- package/build-style/form-input/style-rtl.css +4 -3
- package/build-style/form-input/style.css +4 -3
- package/build-style/navigation-link/editor-rtl.css +14 -0
- package/build-style/navigation-link/editor.css +14 -0
- package/build-style/navigation-link/style-rtl.css +1 -1
- package/build-style/navigation-link/style.css +1 -1
- package/build-style/post-comments-form/style-rtl.css +8 -5
- package/build-style/post-comments-form/style.css +8 -5
- package/build-style/search/style-rtl.css +11 -12
- package/build-style/search/style.css +11 -12
- package/build-style/style-rtl.css +29 -27
- package/build-style/style.css +29 -27
- package/package.json +35 -35
- package/src/accordion/style.scss +6 -6
- package/src/accordion-content/block.json +2 -1
- package/src/accordion-content/edit.js +21 -27
- package/src/accordion-panel/block.json +2 -1
- package/src/cover/test/edit.js +1 -5
- package/src/form-input/style.scss +3 -2
- package/src/navigation/constants.js +4 -0
- package/src/navigation/edit/index.js +50 -1
- package/src/navigation/edit/leaf-more-menu.js +0 -1
- package/src/navigation/edit/menu-inspector-controls.js +40 -5
- package/src/navigation-link/block-inserter.js +65 -0
- package/src/navigation-link/dialog-wrapper.js +74 -0
- package/src/navigation-link/editor.scss +17 -0
- package/src/navigation-link/link-ui.js +108 -164
- package/src/navigation-link/page-creator.js +157 -0
- package/src/navigation-link/style.scss +1 -1
- package/src/post-comments-form/style.scss +11 -11
- package/src/search/edit.js +44 -13
- package/src/search/index.php +16 -2
- package/src/search/style.scss +15 -16
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_blocks","require","_icons","_components","_data","_i18n","_blockEditor","_jsxRuntime","POPOVER_PROPS","className","placement","BLOCKS_THAT_CAN_BE_CONVERTED_TO_SUBMENU","AddSubmenuItem","block","onClose","expandedState","expand","setInsertedBlock","insertBlock","replaceBlock","replaceInnerBlocks","useDispatch","blockEditorStore","clientId","isDisabled","includes","name","jsx","MenuItem","icon","addSubmenu","disabled","onClick","updateSelectionOnInsert","newLink","createBlock","innerBlocks","length","newSubmenu","attributes","children","__","LeafMoreMenu","props","moveBlocksDown","moveBlocksUp","removeBlocks","removeLabel","sprintf","BlockTitle","maximumLength","rootClientId","useSelect","select","getBlockRootClientId","DropdownMenu","moreVertical","label","popoverProps","noIcons","jsxs","Fragment","MenuGroup","chevronUp","chevronDown"
|
|
1
|
+
{"version":3,"names":["_blocks","require","_icons","_components","_data","_i18n","_blockEditor","_jsxRuntime","POPOVER_PROPS","className","placement","BLOCKS_THAT_CAN_BE_CONVERTED_TO_SUBMENU","AddSubmenuItem","block","onClose","expandedState","expand","setInsertedBlock","insertBlock","replaceBlock","replaceInnerBlocks","useDispatch","blockEditorStore","clientId","isDisabled","includes","name","jsx","MenuItem","icon","addSubmenu","disabled","onClick","updateSelectionOnInsert","newLink","createBlock","innerBlocks","length","newSubmenu","attributes","children","__","LeafMoreMenu","props","moveBlocksDown","moveBlocksUp","removeBlocks","removeLabel","sprintf","BlockTitle","maximumLength","rootClientId","useSelect","select","getBlockRootClientId","DropdownMenu","moreVertical","label","popoverProps","noIcons","jsxs","Fragment","MenuGroup","chevronUp","chevronDown"],"sources":["@wordpress/block-library/src/navigation/edit/leaf-more-menu.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createBlock } from '@wordpress/blocks';\nimport {\n\taddSubmenu,\n\tchevronUp,\n\tchevronDown,\n\tmoreVertical,\n} from '@wordpress/icons';\nimport { DropdownMenu, MenuItem, MenuGroup } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { BlockTitle, store as blockEditorStore } from '@wordpress/block-editor';\n\nconst POPOVER_PROPS = {\n\tclassName: 'block-editor-block-settings-menu__popover',\n\tplacement: 'bottom-start',\n};\n\nconst BLOCKS_THAT_CAN_BE_CONVERTED_TO_SUBMENU = [\n\t'core/navigation-link',\n\t'core/navigation-submenu',\n];\n\nfunction AddSubmenuItem( {\n\tblock,\n\tonClose,\n\texpandedState,\n\texpand,\n\tsetInsertedBlock,\n} ) {\n\tconst { insertBlock, replaceBlock, replaceInnerBlocks } =\n\t\tuseDispatch( blockEditorStore );\n\n\tconst clientId = block.clientId;\n\tconst isDisabled = ! BLOCKS_THAT_CAN_BE_CONVERTED_TO_SUBMENU.includes(\n\t\tblock.name\n\t);\n\treturn (\n\t\t<MenuItem\n\t\t\ticon={ addSubmenu }\n\t\t\tdisabled={ isDisabled }\n\t\t\tonClick={ () => {\n\t\t\t\tconst updateSelectionOnInsert = false;\n\t\t\t\tconst newLink = createBlock( 'core/navigation-link' );\n\n\t\t\t\tif ( block.name === 'core/navigation-submenu' ) {\n\t\t\t\t\tinsertBlock(\n\t\t\t\t\t\tnewLink,\n\t\t\t\t\t\tblock.innerBlocks.length,\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t\tupdateSelectionOnInsert\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\t// Convert to a submenu if the block currently isn't one.\n\t\t\t\t\tconst newSubmenu = createBlock(\n\t\t\t\t\t\t'core/navigation-submenu',\n\t\t\t\t\t\tblock.attributes,\n\t\t\t\t\t\tblock.innerBlocks\n\t\t\t\t\t);\n\n\t\t\t\t\t// The following must happen as two independent actions.\n\t\t\t\t\t// Why? Because the offcanvas editor relies on the getLastInsertedBlocksClientIds\n\t\t\t\t\t// selector to determine which block is \"active\". As the UX needs the newLink to be\n\t\t\t\t\t// the \"active\" block it must be the last block to be inserted.\n\t\t\t\t\t// Therefore the Submenu is first created and **then** the newLink is inserted\n\t\t\t\t\t// thus ensuring it is the last inserted block.\n\t\t\t\t\treplaceBlock( clientId, newSubmenu );\n\n\t\t\t\t\treplaceInnerBlocks(\n\t\t\t\t\t\tnewSubmenu.clientId,\n\t\t\t\t\t\t[ newLink ],\n\t\t\t\t\t\tupdateSelectionOnInsert\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// This call sets the local List View state for the \"last inserted block\".\n\t\t\t\t// This is required for the Nav Block to determine whether or not to display\n\t\t\t\t// the Link UI for this new block.\n\t\t\t\tsetInsertedBlock( newLink );\n\n\t\t\t\tif ( ! expandedState[ block.clientId ] ) {\n\t\t\t\t\texpand( block.clientId );\n\t\t\t\t}\n\t\t\t\tonClose();\n\t\t\t} }\n\t\t>\n\t\t\t{ __( 'Add submenu link' ) }\n\t\t</MenuItem>\n\t);\n}\n\nexport default function LeafMoreMenu( props ) {\n\tconst { block } = props;\n\tconst { clientId } = block;\n\n\tconst { moveBlocksDown, moveBlocksUp, removeBlocks } =\n\t\tuseDispatch( blockEditorStore );\n\n\tconst removeLabel = sprintf(\n\t\t/* translators: %s: block name */\n\t\t__( 'Remove %s' ),\n\t\tBlockTitle( { clientId, maximumLength: 25 } )\n\t);\n\n\tconst rootClientId = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockRootClientId } = select( blockEditorStore );\n\n\t\t\treturn getBlockRootClientId( clientId );\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\treturn (\n\t\t<DropdownMenu\n\t\t\ticon={ moreVertical }\n\t\t\tlabel={ __( 'Options' ) }\n\t\t\tclassName=\"block-editor-block-settings-menu\"\n\t\t\tpopoverProps={ POPOVER_PROPS }\n\t\t\tnoIcons\n\t\t\t{ ...props }\n\t\t>\n\t\t\t{ ( { onClose } ) => (\n\t\t\t\t<>\n\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\ticon={ chevronUp }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tmoveBlocksUp( [ clientId ], rootClientId );\n\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Move up' ) }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\ticon={ chevronDown }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tmoveBlocksDown( [ clientId ], rootClientId );\n\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Move down' ) }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t<AddSubmenuItem\n\t\t\t\t\t\t\tblock={ block }\n\t\t\t\t\t\t\tonClose={ onClose }\n\t\t\t\t\t\t\texpandedState={ props.expandedState }\n\t\t\t\t\t\t\texpand={ props.expand }\n\t\t\t\t\t\t\tsetInsertedBlock={ props.setInsertedBlock }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tremoveBlocks( [ clientId ], false );\n\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ removeLabel }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t</MenuGroup>\n\t\t\t\t</>\n\t\t\t) }\n\t\t</DropdownMenu>\n\t);\n}\n"],"mappings":";;;;;;AAGA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAMA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,YAAA,G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DO;QAAW,CACJ;MAAC,CACD,CAAC;IAAA,CACX;EACF,CACY,CAAC;AAEjB","ignoreList":[]}
|
|
@@ -36,7 +36,8 @@ function AdditionalBlockContent({
|
|
|
36
36
|
setInsertedBlock
|
|
37
37
|
}) {
|
|
38
38
|
const {
|
|
39
|
-
updateBlockAttributes
|
|
39
|
+
updateBlockAttributes,
|
|
40
|
+
removeBlock
|
|
40
41
|
} = (0, _data.useDispatch)(_blockEditor.store);
|
|
41
42
|
const supportsLinkControls = BLOCKS_WITH_LINK_UI_SUPPORT?.includes(insertedBlock?.name);
|
|
42
43
|
const blockWasJustInserted = insertedBlock?.clientId === block.clientId;
|
|
@@ -44,24 +45,58 @@ function AdditionalBlockContent({
|
|
|
44
45
|
if (!showLinkControls) {
|
|
45
46
|
return null;
|
|
46
47
|
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Cleanup function for auto-inserted Navigation Link blocks.
|
|
51
|
+
*
|
|
52
|
+
* Removes the block if it has no URL and clears the inserted block state.
|
|
53
|
+
* This ensures consistent cleanup behavior across different contexts.
|
|
54
|
+
*/
|
|
55
|
+
const cleanupInsertedBlock = () => {
|
|
56
|
+
// Prevent automatic block selection when removing blocks in list view context
|
|
57
|
+
// This avoids focus stealing that would close the list view and switch to canvas
|
|
58
|
+
const shouldAutoSelectBlock = false;
|
|
59
|
+
|
|
60
|
+
// Follows the exact same pattern as Navigation Link block's onClose handler
|
|
61
|
+
// If there is no URL then remove the auto-inserted block to avoid empty blocks
|
|
62
|
+
if (!insertedBlock?.attributes?.url && insertedBlock?.clientId) {
|
|
63
|
+
// Remove the block entirely to avoid poor UX
|
|
64
|
+
// This matches the Navigation Link block's behavior
|
|
65
|
+
removeBlock(insertedBlock.clientId, shouldAutoSelectBlock);
|
|
66
|
+
}
|
|
67
|
+
setInsertedBlock(null);
|
|
68
|
+
};
|
|
47
69
|
const setInsertedBlockAttributes = _insertedBlockClientId => _updatedAttributes => {
|
|
48
70
|
if (!_insertedBlockClientId) {
|
|
49
71
|
return;
|
|
50
72
|
}
|
|
51
73
|
updateBlockAttributes(_insertedBlockClientId, _updatedAttributes);
|
|
52
74
|
};
|
|
75
|
+
|
|
76
|
+
// Wrapper function to clean up original block when a new block is selected
|
|
77
|
+
const handleSetInsertedBlock = newBlock => {
|
|
78
|
+
// Prevent automatic block selection when removing blocks in list view context
|
|
79
|
+
// This avoids focus stealing that would close the list view and switch to canvas
|
|
80
|
+
const shouldAutoSelectBlock = false;
|
|
81
|
+
|
|
82
|
+
// If we have an existing inserted block and a new block is being set,
|
|
83
|
+
// remove the original block to avoid duplicates
|
|
84
|
+
if (insertedBlock?.clientId && newBlock) {
|
|
85
|
+
removeBlock(insertedBlock.clientId, shouldAutoSelectBlock);
|
|
86
|
+
}
|
|
87
|
+
setInsertedBlock(newBlock);
|
|
88
|
+
};
|
|
53
89
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_linkUi.LinkUI, {
|
|
54
90
|
clientId: insertedBlock?.clientId,
|
|
55
91
|
link: insertedBlock?.attributes,
|
|
92
|
+
onBlockInsert: handleSetInsertedBlock,
|
|
56
93
|
onClose: () => {
|
|
57
|
-
|
|
94
|
+
// Use cleanup function
|
|
95
|
+
cleanupInsertedBlock();
|
|
58
96
|
},
|
|
59
97
|
onChange: updatedValue => {
|
|
60
98
|
(0, _updateAttributes.updateAttributes)(updatedValue, setInsertedBlockAttributes(insertedBlock?.clientId), insertedBlock?.attributes);
|
|
61
99
|
setInsertedBlock(null);
|
|
62
|
-
},
|
|
63
|
-
onCancel: () => {
|
|
64
|
-
setInsertedBlock(null);
|
|
65
100
|
}
|
|
66
101
|
});
|
|
67
102
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_blockEditor","require","_components","_data","_i18n","_navigationMenuSelector","_interopRequireDefault","_lockUnlock","_deletedNavigationWarning","_useNavigationMenu","_leafMoreMenu","_updateAttributes","_linkUi","_jsxRuntime","actionLabel","__","BLOCKS_WITH_LINK_UI_SUPPORT","PrivateListView","unlock","blockEditorPrivateApis","AdditionalBlockContent","block","insertedBlock","setInsertedBlock","updateBlockAttributes","useDispatch","blockEditorStore","supportsLinkControls","includes","name","blockWasJustInserted","clientId","showLinkControls","setInsertedBlockAttributes","_insertedBlockClientId","_updatedAttributes","jsx","LinkUI","link","attributes","onClose","onChange","updatedValue","updateAttributes","onCancel","MainContent","currentMenuId","isLoading","isNavigationMenuMissing","onCreateNew","hasChildren","useSelect","select","getBlockCount","navigationMenu","useNavigationMenu","default","isNotice","Spinner","description","sprintf","title","jsxs","className","children","rootClientId","isExpanded","showAppender","blockSettingsMenu","LeafMoreMenu","additionalBlockContent","MenuInspectorControls","props","createNavigationMenuIsSuccess","createNavigationMenuIsError","onSelectClassicMenu","onSelectNavigationMenu","isManageMenusButtonDisabled","blockEditingMode","InspectorControls","group","PanelBody","__experimentalHStack","__experimentalHeading","level","_default","exports"],"sources":["@wordpress/block-library/src/navigation/edit/menu-inspector-controls.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tprivateApis as blockEditorPrivateApis,\n\tInspectorControls,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport {\n\tPanelBody,\n\t__experimentalHStack as HStack,\n\t__experimentalHeading as Heading,\n\tSpinner,\n} from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport NavigationMenuSelector from './navigation-menu-selector';\nimport { unlock } from '../../lock-unlock';\nimport DeletedNavigationWarning from './deleted-navigation-warning';\nimport useNavigationMenu from '../use-navigation-menu';\nimport LeafMoreMenu from './leaf-more-menu';\nimport { updateAttributes } from '../../navigation-link/update-attributes';\nimport { LinkUI } from '../../navigation-link/link-ui';\n\nconst actionLabel =\n\t/* translators: %s: The name of a menu. */ __( \"Switch to '%s'\" );\nconst BLOCKS_WITH_LINK_UI_SUPPORT = [\n\t'core/navigation-link',\n\t'core/navigation-submenu',\n];\nconst { PrivateListView } = unlock( blockEditorPrivateApis );\n\nfunction AdditionalBlockContent( { block, insertedBlock, setInsertedBlock } ) {\n\tconst { updateBlockAttributes } = useDispatch( blockEditorStore );\n\n\tconst supportsLinkControls = BLOCKS_WITH_LINK_UI_SUPPORT?.includes(\n\t\tinsertedBlock?.name\n\t);\n\tconst blockWasJustInserted = insertedBlock?.clientId === block.clientId;\n\tconst showLinkControls = supportsLinkControls && blockWasJustInserted;\n\n\tif ( ! showLinkControls ) {\n\t\treturn null;\n\t}\n\n\tconst setInsertedBlockAttributes =\n\t\t( _insertedBlockClientId ) => ( _updatedAttributes ) => {\n\t\t\tif ( ! _insertedBlockClientId ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tupdateBlockAttributes( _insertedBlockClientId, _updatedAttributes );\n\t\t};\n\n\treturn (\n\t\t<LinkUI\n\t\t\tclientId={ insertedBlock?.clientId }\n\t\t\tlink={ insertedBlock?.attributes }\n\t\t\tonClose={ () => {\n\t\t\t\tsetInsertedBlock( null );\n\t\t\t} }\n\t\t\tonChange={ ( updatedValue ) => {\n\t\t\t\tupdateAttributes(\n\t\t\t\t\tupdatedValue,\n\t\t\t\t\tsetInsertedBlockAttributes( insertedBlock?.clientId ),\n\t\t\t\t\tinsertedBlock?.attributes\n\t\t\t\t);\n\t\t\t\tsetInsertedBlock( null );\n\t\t\t} }\n\t\t\tonCancel={ () => {\n\t\t\t\tsetInsertedBlock( null );\n\t\t\t} }\n\t\t/>\n\t);\n}\n\nconst MainContent = ( {\n\tclientId,\n\tcurrentMenuId,\n\tisLoading,\n\tisNavigationMenuMissing,\n\tonCreateNew,\n} ) => {\n\tconst hasChildren = useSelect(\n\t\t( select ) => {\n\t\t\treturn !! select( blockEditorStore ).getBlockCount( clientId );\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst { navigationMenu } = useNavigationMenu( currentMenuId );\n\n\tif ( currentMenuId && isNavigationMenuMissing ) {\n\t\treturn (\n\t\t\t<DeletedNavigationWarning onCreateNew={ onCreateNew } isNotice />\n\t\t);\n\t}\n\n\tif ( isLoading ) {\n\t\treturn <Spinner />;\n\t}\n\n\tconst description = navigationMenu\n\t\t? sprintf(\n\t\t\t\t/* translators: %s: The name of a menu. */\n\t\t\t\t__( 'Structure for Navigation Menu: %s' ),\n\t\t\t\tnavigationMenu?.title || __( 'Untitled menu' )\n\t\t )\n\t\t: __(\n\t\t\t\t'You have not yet created any menus. Displaying a list of your Pages'\n\t\t );\n\n\treturn (\n\t\t<div className=\"wp-block-navigation__menu-inspector-controls\">\n\t\t\t{ ! hasChildren && (\n\t\t\t\t<p className=\"wp-block-navigation__menu-inspector-controls__empty-message\">\n\t\t\t\t\t{ __( 'This Navigation Menu is empty.' ) }\n\t\t\t\t</p>\n\t\t\t) }\n\t\t\t<PrivateListView\n\t\t\t\trootClientId={ clientId }\n\t\t\t\tisExpanded\n\t\t\t\tdescription={ description }\n\t\t\t\tshowAppender\n\t\t\t\tblockSettingsMenu={ LeafMoreMenu }\n\t\t\t\tadditionalBlockContent={ AdditionalBlockContent }\n\t\t\t/>\n\t\t</div>\n\t);\n};\n\nconst MenuInspectorControls = ( props ) => {\n\tconst {\n\t\tcreateNavigationMenuIsSuccess,\n\t\tcreateNavigationMenuIsError,\n\t\tcurrentMenuId = null,\n\t\tonCreateNew,\n\t\tonSelectClassicMenu,\n\t\tonSelectNavigationMenu,\n\t\tisManageMenusButtonDisabled,\n\t\tblockEditingMode,\n\t} = props;\n\n\treturn (\n\t\t<InspectorControls group=\"list\">\n\t\t\t<PanelBody title={ null }>\n\t\t\t\t<HStack className=\"wp-block-navigation-off-canvas-editor__header\">\n\t\t\t\t\t<Heading\n\t\t\t\t\t\tclassName=\"wp-block-navigation-off-canvas-editor__title\"\n\t\t\t\t\t\tlevel={ 2 }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Menu' ) }\n\t\t\t\t\t</Heading>\n\t\t\t\t\t{ blockEditingMode === 'default' && (\n\t\t\t\t\t\t<NavigationMenuSelector\n\t\t\t\t\t\t\tcurrentMenuId={ currentMenuId }\n\t\t\t\t\t\t\tonSelectClassicMenu={ onSelectClassicMenu }\n\t\t\t\t\t\t\tonSelectNavigationMenu={ onSelectNavigationMenu }\n\t\t\t\t\t\t\tonCreateNew={ onCreateNew }\n\t\t\t\t\t\t\tcreateNavigationMenuIsSuccess={\n\t\t\t\t\t\t\t\tcreateNavigationMenuIsSuccess\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcreateNavigationMenuIsError={\n\t\t\t\t\t\t\t\tcreateNavigationMenuIsError\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tactionLabel={ actionLabel }\n\t\t\t\t\t\t\tisManageMenusButtonDisabled={\n\t\t\t\t\t\t\t\tisManageMenusButtonDisabled\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</HStack>\n\t\t\t\t<MainContent { ...props } />\n\t\t\t</PanelBody>\n\t\t</InspectorControls>\n\t);\n};\n\nexport default MenuInspectorControls;\n"],"mappings":";;;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AAKA,IAAAC,WAAA,GAAAD,OAAA;AAMA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAKA,IAAAI,uBAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,WAAA,GAAAN,OAAA;AACA,IAAAO,yBAAA,GAAAF,sBAAA,CAAAL,OAAA;AACA,IAAAQ,kBAAA,GAAAH,sBAAA,CAAAL,OAAA;AACA,IAAAS,aAAA,GAAAJ,sBAAA,CAAAL,OAAA;AACA,IAAAU,iBAAA,GAAAV,OAAA;AACA,IAAAW,OAAA,GAAAX,OAAA;AAAuD,IAAAY,WAAA,GAAAZ,OAAA;AA1BvD;AACA;AACA;;AAeA;AACA;AACA;;AASA,MAAMa,WAAW,GAChB,0CAA2C,IAAAC,QAAE,EAAE,gBAAiB,CAAC;AAClE,MAAMC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MAAK,CAAI,CAAC;IAAA,CAClB;EAAC,CACM,CAAC;AAEtB,CAAC;AAAC,IAAAa,QAAA,GAAAC,OAAA,CAAA9B,OAAA,GAEae,qBAAqB","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_blockEditor","require","_components","_data","_i18n","_navigationMenuSelector","_interopRequireDefault","_lockUnlock","_deletedNavigationWarning","_useNavigationMenu","_leafMoreMenu","_updateAttributes","_linkUi","_jsxRuntime","actionLabel","__","BLOCKS_WITH_LINK_UI_SUPPORT","PrivateListView","unlock","blockEditorPrivateApis","AdditionalBlockContent","block","insertedBlock","setInsertedBlock","updateBlockAttributes","removeBlock","useDispatch","blockEditorStore","supportsLinkControls","includes","name","blockWasJustInserted","clientId","showLinkControls","cleanupInsertedBlock","shouldAutoSelectBlock","attributes","url","setInsertedBlockAttributes","_insertedBlockClientId","_updatedAttributes","handleSetInsertedBlock","newBlock","jsx","LinkUI","link","onBlockInsert","onClose","onChange","updatedValue","updateAttributes","MainContent","currentMenuId","isLoading","isNavigationMenuMissing","onCreateNew","hasChildren","useSelect","select","getBlockCount","navigationMenu","useNavigationMenu","default","isNotice","Spinner","description","sprintf","title","jsxs","className","children","rootClientId","isExpanded","showAppender","blockSettingsMenu","LeafMoreMenu","additionalBlockContent","MenuInspectorControls","props","createNavigationMenuIsSuccess","createNavigationMenuIsError","onSelectClassicMenu","onSelectNavigationMenu","isManageMenusButtonDisabled","blockEditingMode","InspectorControls","group","PanelBody","__experimentalHStack","__experimentalHeading","level","_default","exports"],"sources":["@wordpress/block-library/src/navigation/edit/menu-inspector-controls.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tprivateApis as blockEditorPrivateApis,\n\tInspectorControls,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport {\n\tPanelBody,\n\t__experimentalHStack as HStack,\n\t__experimentalHeading as Heading,\n\tSpinner,\n} from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport NavigationMenuSelector from './navigation-menu-selector';\nimport { unlock } from '../../lock-unlock';\nimport DeletedNavigationWarning from './deleted-navigation-warning';\nimport useNavigationMenu from '../use-navigation-menu';\nimport LeafMoreMenu from './leaf-more-menu';\nimport { updateAttributes } from '../../navigation-link/update-attributes';\nimport { LinkUI } from '../../navigation-link/link-ui';\n\nconst actionLabel =\n\t/* translators: %s: The name of a menu. */ __( \"Switch to '%s'\" );\nconst BLOCKS_WITH_LINK_UI_SUPPORT = [\n\t'core/navigation-link',\n\t'core/navigation-submenu',\n];\nconst { PrivateListView } = unlock( blockEditorPrivateApis );\n\nfunction AdditionalBlockContent( { block, insertedBlock, setInsertedBlock } ) {\n\tconst { updateBlockAttributes, removeBlock } =\n\t\tuseDispatch( blockEditorStore );\n\n\tconst supportsLinkControls = BLOCKS_WITH_LINK_UI_SUPPORT?.includes(\n\t\tinsertedBlock?.name\n\t);\n\tconst blockWasJustInserted = insertedBlock?.clientId === block.clientId;\n\tconst showLinkControls = supportsLinkControls && blockWasJustInserted;\n\n\tif ( ! showLinkControls ) {\n\t\treturn null;\n\t}\n\n\t/**\n\t * Cleanup function for auto-inserted Navigation Link blocks.\n\t *\n\t * Removes the block if it has no URL and clears the inserted block state.\n\t * This ensures consistent cleanup behavior across different contexts.\n\t */\n\tconst cleanupInsertedBlock = () => {\n\t\t// Prevent automatic block selection when removing blocks in list view context\n\t\t// This avoids focus stealing that would close the list view and switch to canvas\n\t\tconst shouldAutoSelectBlock = false;\n\n\t\t// Follows the exact same pattern as Navigation Link block's onClose handler\n\t\t// If there is no URL then remove the auto-inserted block to avoid empty blocks\n\t\tif ( ! insertedBlock?.attributes?.url && insertedBlock?.clientId ) {\n\t\t\t// Remove the block entirely to avoid poor UX\n\t\t\t// This matches the Navigation Link block's behavior\n\t\t\tremoveBlock( insertedBlock.clientId, shouldAutoSelectBlock );\n\t\t}\n\t\tsetInsertedBlock( null );\n\t};\n\n\tconst setInsertedBlockAttributes =\n\t\t( _insertedBlockClientId ) => ( _updatedAttributes ) => {\n\t\t\tif ( ! _insertedBlockClientId ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tupdateBlockAttributes( _insertedBlockClientId, _updatedAttributes );\n\t\t};\n\n\t// Wrapper function to clean up original block when a new block is selected\n\tconst handleSetInsertedBlock = ( newBlock ) => {\n\t\t// Prevent automatic block selection when removing blocks in list view context\n\t\t// This avoids focus stealing that would close the list view and switch to canvas\n\t\tconst shouldAutoSelectBlock = false;\n\n\t\t// If we have an existing inserted block and a new block is being set,\n\t\t// remove the original block to avoid duplicates\n\t\tif ( insertedBlock?.clientId && newBlock ) {\n\t\t\tremoveBlock( insertedBlock.clientId, shouldAutoSelectBlock );\n\t\t}\n\t\tsetInsertedBlock( newBlock );\n\t};\n\n\treturn (\n\t\t<LinkUI\n\t\t\tclientId={ insertedBlock?.clientId }\n\t\t\tlink={ insertedBlock?.attributes }\n\t\t\tonBlockInsert={ handleSetInsertedBlock }\n\t\t\tonClose={ () => {\n\t\t\t\t// Use cleanup function\n\t\t\t\tcleanupInsertedBlock();\n\t\t\t} }\n\t\t\tonChange={ ( updatedValue ) => {\n\t\t\t\tupdateAttributes(\n\t\t\t\t\tupdatedValue,\n\t\t\t\t\tsetInsertedBlockAttributes( insertedBlock?.clientId ),\n\t\t\t\t\tinsertedBlock?.attributes\n\t\t\t\t);\n\t\t\t\tsetInsertedBlock( null );\n\t\t\t} }\n\t\t/>\n\t);\n}\n\nconst MainContent = ( {\n\tclientId,\n\tcurrentMenuId,\n\tisLoading,\n\tisNavigationMenuMissing,\n\tonCreateNew,\n} ) => {\n\tconst hasChildren = useSelect(\n\t\t( select ) => {\n\t\t\treturn !! select( blockEditorStore ).getBlockCount( clientId );\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst { navigationMenu } = useNavigationMenu( currentMenuId );\n\n\tif ( currentMenuId && isNavigationMenuMissing ) {\n\t\treturn (\n\t\t\t<DeletedNavigationWarning onCreateNew={ onCreateNew } isNotice />\n\t\t);\n\t}\n\n\tif ( isLoading ) {\n\t\treturn <Spinner />;\n\t}\n\n\tconst description = navigationMenu\n\t\t? sprintf(\n\t\t\t\t/* translators: %s: The name of a menu. */\n\t\t\t\t__( 'Structure for Navigation Menu: %s' ),\n\t\t\t\tnavigationMenu?.title || __( 'Untitled menu' )\n\t\t )\n\t\t: __(\n\t\t\t\t'You have not yet created any menus. Displaying a list of your Pages'\n\t\t );\n\n\treturn (\n\t\t<div className=\"wp-block-navigation__menu-inspector-controls\">\n\t\t\t{ ! hasChildren && (\n\t\t\t\t<p className=\"wp-block-navigation__menu-inspector-controls__empty-message\">\n\t\t\t\t\t{ __( 'This Navigation Menu is empty.' ) }\n\t\t\t\t</p>\n\t\t\t) }\n\t\t\t<PrivateListView\n\t\t\t\trootClientId={ clientId }\n\t\t\t\tisExpanded\n\t\t\t\tdescription={ description }\n\t\t\t\tshowAppender\n\t\t\t\tblockSettingsMenu={ LeafMoreMenu }\n\t\t\t\tadditionalBlockContent={ AdditionalBlockContent }\n\t\t\t/>\n\t\t</div>\n\t);\n};\n\nconst MenuInspectorControls = ( props ) => {\n\tconst {\n\t\tcreateNavigationMenuIsSuccess,\n\t\tcreateNavigationMenuIsError,\n\t\tcurrentMenuId = null,\n\t\tonCreateNew,\n\t\tonSelectClassicMenu,\n\t\tonSelectNavigationMenu,\n\t\tisManageMenusButtonDisabled,\n\t\tblockEditingMode,\n\t} = props;\n\n\treturn (\n\t\t<InspectorControls group=\"list\">\n\t\t\t<PanelBody title={ null }>\n\t\t\t\t<HStack className=\"wp-block-navigation-off-canvas-editor__header\">\n\t\t\t\t\t<Heading\n\t\t\t\t\t\tclassName=\"wp-block-navigation-off-canvas-editor__title\"\n\t\t\t\t\t\tlevel={ 2 }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Menu' ) }\n\t\t\t\t\t</Heading>\n\t\t\t\t\t{ blockEditingMode === 'default' && (\n\t\t\t\t\t\t<NavigationMenuSelector\n\t\t\t\t\t\t\tcurrentMenuId={ currentMenuId }\n\t\t\t\t\t\t\tonSelectClassicMenu={ onSelectClassicMenu }\n\t\t\t\t\t\t\tonSelectNavigationMenu={ onSelectNavigationMenu }\n\t\t\t\t\t\t\tonCreateNew={ onCreateNew }\n\t\t\t\t\t\t\tcreateNavigationMenuIsSuccess={\n\t\t\t\t\t\t\t\tcreateNavigationMenuIsSuccess\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcreateNavigationMenuIsError={\n\t\t\t\t\t\t\t\tcreateNavigationMenuIsError\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tactionLabel={ actionLabel }\n\t\t\t\t\t\t\tisManageMenusButtonDisabled={\n\t\t\t\t\t\t\t\tisManageMenusButtonDisabled\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</HStack>\n\t\t\t\t<MainContent { ...props } />\n\t\t\t</PanelBody>\n\t\t</InspectorControls>\n\t);\n};\n\nexport default MenuInspectorControls;\n"],"mappings":";;;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AAKA,IAAAC,WAAA,GAAAD,OAAA;AAMA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAKA,IAAAI,uBAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,WAAA,GAAAN,OAAA;AACA,IAAAO,yBAAA,GAAAF,sBAAA,CAAAL,OAAA;AACA,IAAAQ,kBAAA,GAAAH,sBAAA,CAAAL,OAAA;AACA,IAAAS,aAAA,GAAAJ,sBAAA,CAAAL,OAAA;AACA,IAAAU,iBAAA,GAAAV,OAAA;AACA,IAAAW,OAAA,GAAAX,OAAA;AAAuD,IAAAY,WAAA,GAAAZ,OAAA;AA1BvD;AACA;AACA;;AAeA;AACA;AACA;;AASA,MAAMa,WAAW,GAChB,0CAA2C,IAAAC,QAAE,EAAE,gBAAiB,CAAC;AAClE,MAA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CAAA8B,GAAA,EAACzC,WAAA,CAAAuF,qBAAO;UACPpB,SAAS,EAAC,8CAA8C;UACxDqB,KAAK,EAAG,CAAG;UAAApB,QAAA,EAET,IAAAvD,QAAE,EAAE,MAAO;QAAC,CACN,CAAC,EACRqE,gBAAgB,KAAK,SAAS,iBAC/B,IAAAvE,WAAA,CAAA8B,GAAA,EAACtC,uBAAA,CAAAyD,OAAsB;UACtBV,aAAa,EAAGA,aAAe;UAC/B6B,mBAAmB,EAAGA,mBAAqB;UAC3CC,sBAAsB,EAAGA,sBAAwB;UACjD3B,WAAW,EAAGA,WAAa;UAC3BwB,6BAA6B,EAC5BA,6BACA;UACDC,2BAA2B,EAC1BA,2BACA;UACDlE,WAAW,EAAGA,WAAa;UAC3BqE,2BAA2B,EAC1BA;QACA,CACD,CACD;MAAA,CACM,CAAC,eACT,IAAAtE,WAAA,CAAA8B,GAAA,EAACQ,WAAW;QAAA,GAAM2B;MAAK,CAAI,CAAC;IAAA,CAClB;EAAC,CACM,CAAC;AAEtB,CAAC;AAAC,IAAAa,QAAA,GAAAC,OAAA,CAAA9B,OAAA,GAEae,qBAAqB","ignoreList":[]}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _i18n = require("@wordpress/i18n");
|
|
9
|
+
var _data = require("@wordpress/data");
|
|
10
|
+
var _blockEditor = require("@wordpress/block-editor");
|
|
11
|
+
var _dialogWrapper = _interopRequireDefault(require("./dialog-wrapper"));
|
|
12
|
+
var _lockUnlock = require("../lock-unlock");
|
|
13
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
|
+
/**
|
|
15
|
+
* WordPress dependencies
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Internal dependencies
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const {
|
|
23
|
+
PrivateQuickInserter: QuickInserter
|
|
24
|
+
} = (0, _lockUnlock.unlock)(_blockEditor.privateApis);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Component for inserting blocks within the Navigation Link UI.
|
|
28
|
+
*
|
|
29
|
+
* @param {Object} props Component props.
|
|
30
|
+
* @param {string} props.clientId Client ID of the navigation link block.
|
|
31
|
+
* @param {Function} props.onBack Callback when user wants to go back.
|
|
32
|
+
* @param {Function} props.onBlockInsert Callback when a block is inserted.
|
|
33
|
+
*/
|
|
34
|
+
function LinkUIBlockInserter({
|
|
35
|
+
clientId,
|
|
36
|
+
onBack,
|
|
37
|
+
onBlockInsert
|
|
38
|
+
}) {
|
|
39
|
+
const {
|
|
40
|
+
rootBlockClientId
|
|
41
|
+
} = (0, _data.useSelect)(select => {
|
|
42
|
+
const {
|
|
43
|
+
getBlockRootClientId
|
|
44
|
+
} = select(_blockEditor.store);
|
|
45
|
+
return {
|
|
46
|
+
rootBlockClientId: getBlockRootClientId(clientId)
|
|
47
|
+
};
|
|
48
|
+
}, [clientId]);
|
|
49
|
+
if (!clientId) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_dialogWrapper.default, {
|
|
53
|
+
className: "link-ui-block-inserter",
|
|
54
|
+
title: (0, _i18n.__)('Add block'),
|
|
55
|
+
description: (0, _i18n.__)('Choose a block to add to your Navigation.'),
|
|
56
|
+
onBack: onBack,
|
|
57
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(QuickInserter, {
|
|
58
|
+
rootClientId: rootBlockClientId,
|
|
59
|
+
clientId: clientId,
|
|
60
|
+
isAppender: false,
|
|
61
|
+
prioritizePatterns: false,
|
|
62
|
+
selectBlockOnInsert: !onBlockInsert,
|
|
63
|
+
onSelect: onBlockInsert ? onBlockInsert : undefined,
|
|
64
|
+
hasSearch: false
|
|
65
|
+
})
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
var _default = exports.default = LinkUIBlockInserter;
|
|
69
|
+
//# sourceMappingURL=block-inserter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_i18n","require","_data","_blockEditor","_dialogWrapper","_interopRequireDefault","_lockUnlock","_jsxRuntime","PrivateQuickInserter","QuickInserter","unlock","blockEditorPrivateApis","LinkUIBlockInserter","clientId","onBack","onBlockInsert","rootBlockClientId","useSelect","select","getBlockRootClientId","blockEditorStore","jsx","default","className","title","__","description","children","rootClientId","isAppender","prioritizePatterns","selectBlockOnInsert","onSelect","undefined","hasSearch","_default","exports"],"sources":["@wordpress/block-library/src/navigation-link/block-inserter.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tstore as blockEditorStore,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport DialogWrapper from './dialog-wrapper';\nimport { unlock } from '../lock-unlock';\n\nconst { PrivateQuickInserter: QuickInserter } = unlock(\n\tblockEditorPrivateApis\n);\n\n/**\n * Component for inserting blocks within the Navigation Link UI.\n *\n * @param {Object} props Component props.\n * @param {string} props.clientId Client ID of the navigation link block.\n * @param {Function} props.onBack Callback when user wants to go back.\n * @param {Function} props.onBlockInsert Callback when a block is inserted.\n */\nfunction LinkUIBlockInserter( { clientId, onBack, onBlockInsert } ) {\n\tconst { rootBlockClientId } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockRootClientId } = select( blockEditorStore );\n\n\t\t\treturn {\n\t\t\t\trootBlockClientId: getBlockRootClientId( clientId ),\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tif ( ! clientId ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<DialogWrapper\n\t\t\tclassName=\"link-ui-block-inserter\"\n\t\t\ttitle={ __( 'Add block' ) }\n\t\t\tdescription={ __( 'Choose a block to add to your Navigation.' ) }\n\t\t\tonBack={ onBack }\n\t\t>\n\t\t\t<QuickInserter\n\t\t\t\trootClientId={ rootBlockClientId }\n\t\t\t\tclientId={ clientId }\n\t\t\t\tisAppender={ false }\n\t\t\t\tprioritizePatterns={ false }\n\t\t\t\tselectBlockOnInsert={ ! onBlockInsert }\n\t\t\t\tonSelect={ onBlockInsert ? onBlockInsert : undefined }\n\t\t\t\thasSearch={ false }\n\t\t\t/>\n\t\t</DialogWrapper>\n\t);\n}\n\nexport default LinkUIBlockInserter;\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAQA,IAAAG,cAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,WAAA,GAAAL,OAAA;AAAwC,IAAAM,WAAA,GAAAN,OAAA;AAdxC;AACA;AACA;;AAQA;AACA;AACA;;AAIA,MAAM;EAAEO,oBAAoB,EAAEC;AAAc,CAAC,GAAG,IAAAC,kBAAM,EACrDC,wBACD,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,mBAAmBA,CAAE;EAAEC,QAAQ;EAAEC,MAAM;EAAEC;AAAc,CAAC,EAAG;EACnE,MAAM;IAAEC;EAAkB,CAAC,GAAG,IAAAC,eAAS,EACpCC,MAAM,IAAM;IACb,MAAM;MAAEC;IAAqB,CAAC,GAAGD,MAAM,CAAEE,kBAAiB,CAAC;IAE3D,OAAO;MACNJ,iBAAiB,EAAEG,oBAAoB,CAAEN,QAAS;IACnD,CAAC;EACF,CAAC,EACD,CAAEA,QAAQ,CACX,CAAC;EAED,IAAK,CAAEA,QAAQ,EAAG;IACjB,OAAO,IAAI;EACZ;EAEA,oBACC,IAAAN,WAAA,CAAAc,GAAA,EAACjB,cAAA,CAAAkB,OAAa;IACbC,SAAS,EAAC,wBAAwB;IAClCC,KAAK,EAAG,IAAAC,QAAE,EAAE,WAAY,CAAG;IAC3BC,WAAW,EAAG,IAAAD,QAAE,EAAE,2CAA4C,CAAG;IACjEX,MAAM,EAAGA,MAAQ;IAAAa,QAAA,eAEjB,IAAApB,WAAA,CAAAc,GAAA,EAACZ,aAAa;MACbmB,YAAY,EAAGZ,iBAAmB;MAClCH,QAAQ,EAAGA,QAAU;MACrBgB,UAAU,EAAG,KAAO;MACpBC,kBAAkB,EAAG,KAAO;MAC5BC,mBAAmB,EAAG,CAAEhB,aAAe;MACvCiB,QAAQ,EAAGjB,aAAa,GAAGA,aAAa,GAAGkB,SAAW;MACtDC,SAAS,EAAG;IAAO,CACnB;EAAC,CACY,CAAC;AAElB;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAd,OAAA,GAEcV,mBAAmB","ignoreList":[]}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _components = require("@wordpress/components");
|
|
8
|
+
var _i18n = require("@wordpress/i18n");
|
|
9
|
+
var _icons = require("@wordpress/icons");
|
|
10
|
+
var _compose = require("@wordpress/compose");
|
|
11
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
|
+
/**
|
|
13
|
+
* WordPress dependencies
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Shared BackButton component for consistent navigation across LinkUI sub-components.
|
|
18
|
+
*
|
|
19
|
+
* @param {Object} props Component props.
|
|
20
|
+
* @param {string} props.className CSS class name for the button.
|
|
21
|
+
* @param {Function} props.onBack Callback when user wants to go back.
|
|
22
|
+
*/function BackButton({
|
|
23
|
+
className,
|
|
24
|
+
onBack
|
|
25
|
+
}) {
|
|
26
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
27
|
+
className: className,
|
|
28
|
+
icon: (0, _i18n.isRTL)() ? _icons.chevronRightSmall : _icons.chevronLeftSmall,
|
|
29
|
+
onClick: e => {
|
|
30
|
+
e.preventDefault();
|
|
31
|
+
onBack();
|
|
32
|
+
},
|
|
33
|
+
size: "small",
|
|
34
|
+
children: (0, _i18n.__)('Back')
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Shared DialogWrapper component for consistent dialog structure across LinkUI sub-components.
|
|
40
|
+
*
|
|
41
|
+
* @param {Object} props Component props.
|
|
42
|
+
* @param {string} props.className CSS class name for the dialog container.
|
|
43
|
+
* @param {string} props.title Dialog title for accessibility.
|
|
44
|
+
* @param {string} props.description Dialog description for accessibility.
|
|
45
|
+
* @param {Function} props.onBack Callback when user wants to go back.
|
|
46
|
+
* @param {Object} props.children Child components to render inside the dialog.
|
|
47
|
+
*/
|
|
48
|
+
function DialogWrapper({
|
|
49
|
+
className,
|
|
50
|
+
title,
|
|
51
|
+
description,
|
|
52
|
+
onBack,
|
|
53
|
+
children
|
|
54
|
+
}) {
|
|
55
|
+
const dialogTitleId = (0, _compose.useInstanceId)(DialogWrapper, 'link-ui-dialog-title');
|
|
56
|
+
const dialogDescriptionId = (0, _compose.useInstanceId)(DialogWrapper, 'link-ui-dialog-description');
|
|
57
|
+
const focusOnMountRef = (0, _compose.useFocusOnMount)('firstElement');
|
|
58
|
+
const backButtonClassName = `${className}__back`;
|
|
59
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
60
|
+
className: className,
|
|
61
|
+
role: "dialog",
|
|
62
|
+
"aria-labelledby": dialogTitleId,
|
|
63
|
+
"aria-describedby": dialogDescriptionId,
|
|
64
|
+
ref: focusOnMountRef,
|
|
65
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.VisuallyHidden, {
|
|
66
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h2", {
|
|
67
|
+
id: dialogTitleId,
|
|
68
|
+
children: title
|
|
69
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
|
|
70
|
+
id: dialogDescriptionId,
|
|
71
|
+
children: description
|
|
72
|
+
})]
|
|
73
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(BackButton, {
|
|
74
|
+
className: backButtonClassName,
|
|
75
|
+
onBack: onBack
|
|
76
|
+
}), children]
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
var _default = exports.default = DialogWrapper;
|
|
80
|
+
//# sourceMappingURL=dialog-wrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_components","require","_i18n","_icons","_compose","_jsxRuntime","BackButton","className","onBack","jsx","Button","icon","isRTL","chevronRightSmall","chevronLeftSmall","onClick","e","preventDefault","size","children","__","DialogWrapper","title","description","dialogTitleId","useInstanceId","dialogDescriptionId","focusOnMountRef","useFocusOnMount","backButtonClassName","jsxs","role","ref","VisuallyHidden","id","_default","exports","default"],"sources":["@wordpress/block-library/src/navigation-link/dialog-wrapper.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Button, VisuallyHidden } from '@wordpress/components';\nimport { __, isRTL } from '@wordpress/i18n';\nimport { chevronLeftSmall, chevronRightSmall } from '@wordpress/icons';\nimport { useInstanceId, useFocusOnMount } from '@wordpress/compose';\n\n/**\n * Shared BackButton component for consistent navigation across LinkUI sub-components.\n *\n * @param {Object} props Component props.\n * @param {string} props.className CSS class name for the button.\n * @param {Function} props.onBack Callback when user wants to go back.\n */\nfunction BackButton( { className, onBack } ) {\n\treturn (\n\t\t<Button\n\t\t\tclassName={ className }\n\t\t\ticon={ isRTL() ? chevronRightSmall : chevronLeftSmall }\n\t\t\tonClick={ ( e ) => {\n\t\t\t\te.preventDefault();\n\t\t\t\tonBack();\n\t\t\t} }\n\t\t\tsize=\"small\"\n\t\t>\n\t\t\t{ __( 'Back' ) }\n\t\t</Button>\n\t);\n}\n\n/**\n * Shared DialogWrapper component for consistent dialog structure across LinkUI sub-components.\n *\n * @param {Object} props Component props.\n * @param {string} props.className CSS class name for the dialog container.\n * @param {string} props.title Dialog title for accessibility.\n * @param {string} props.description Dialog description for accessibility.\n * @param {Function} props.onBack Callback when user wants to go back.\n * @param {Object} props.children Child components to render inside the dialog.\n */\nfunction DialogWrapper( { className, title, description, onBack, children } ) {\n\tconst dialogTitleId = useInstanceId(\n\t\tDialogWrapper,\n\t\t'link-ui-dialog-title'\n\t);\n\tconst dialogDescriptionId = useInstanceId(\n\t\tDialogWrapper,\n\t\t'link-ui-dialog-description'\n\t);\n\tconst focusOnMountRef = useFocusOnMount( 'firstElement' );\n\tconst backButtonClassName = `${ className }__back`;\n\n\treturn (\n\t\t<div\n\t\t\tclassName={ className }\n\t\t\trole=\"dialog\"\n\t\t\taria-labelledby={ dialogTitleId }\n\t\t\taria-describedby={ dialogDescriptionId }\n\t\t\tref={ focusOnMountRef }\n\t\t>\n\t\t\t<VisuallyHidden>\n\t\t\t\t<h2 id={ dialogTitleId }>{ title }</h2>\n\t\t\t\t<p id={ dialogDescriptionId }>{ description }</p>\n\t\t\t</VisuallyHidden>\n\n\t\t\t<BackButton className={ backButtonClassName } onBack={ onBack } />\n\n\t\t\t{ children }\n\t\t</div>\n\t);\n}\n\nexport default DialogWrapper;\n"],"mappings":";;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAAoE,IAAAI,WAAA,GAAAJ,OAAA;AANpE;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,SAASK,UAAUA,CAAE;EAAEC,SAAS;EAAEC;AAAO,CAAC,EAAG;EAC5C,oBACC,IAAAH,WAAA,CAAAI,GAAA,EAACT,WAAA,CAAAU,MAAM;IACNH,SAAS,EAAGA,SAAW;IACvBI,IA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AGA;IAAQ,CAAE,CAAC,EAEhEW,QAAQ;EAAA,CACN,CAAC;AAER;AAAC,IAAAgB,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEchB,aAAa","ignoreList":[]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
@@ -11,11 +12,10 @@ var _i18n = require("@wordpress/i18n");
|
|
|
11
12
|
var _blockEditor = require("@wordpress/block-editor");
|
|
12
13
|
var _element = require("@wordpress/element");
|
|
13
14
|
var _coreData = require("@wordpress/core-data");
|
|
14
|
-
var _htmlEntities = require("@wordpress/html-entities");
|
|
15
|
-
var _data = require("@wordpress/data");
|
|
16
15
|
var _icons = require("@wordpress/icons");
|
|
17
16
|
var _compose = require("@wordpress/compose");
|
|
18
|
-
var
|
|
17
|
+
var _pageCreator = require("./page-creator");
|
|
18
|
+
var _blockInserter = _interopRequireDefault(require("./block-inserter"));
|
|
19
19
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
20
20
|
/**
|
|
21
21
|
* WordPress dependencies
|
|
@@ -25,10 +25,6 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
25
25
|
* Internal dependencies
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
-
const {
|
|
29
|
-
PrivateQuickInserter: QuickInserter
|
|
30
|
-
} = (0, _lockUnlock.unlock)(_blockEditor.privateApis);
|
|
31
|
-
|
|
32
28
|
/**
|
|
33
29
|
* Given the Link block's type attribute, return the query params to give to
|
|
34
30
|
* /wp/v2/search.
|
|
@@ -83,59 +79,6 @@ function getSuggestionsQuery(type, kind) {
|
|
|
83
79
|
};
|
|
84
80
|
}
|
|
85
81
|
}
|
|
86
|
-
function LinkUIBlockInserter({
|
|
87
|
-
clientId,
|
|
88
|
-
onBack
|
|
89
|
-
}) {
|
|
90
|
-
const {
|
|
91
|
-
rootBlockClientId
|
|
92
|
-
} = (0, _data.useSelect)(select => {
|
|
93
|
-
const {
|
|
94
|
-
getBlockRootClientId
|
|
95
|
-
} = select(_blockEditor.store);
|
|
96
|
-
return {
|
|
97
|
-
rootBlockClientId: getBlockRootClientId(clientId)
|
|
98
|
-
};
|
|
99
|
-
}, [clientId]);
|
|
100
|
-
const focusOnMountRef = (0, _compose.useFocusOnMount)('firstElement');
|
|
101
|
-
const dialogTitleId = (0, _compose.useInstanceId)(_blockEditor.LinkControl, `link-ui-block-inserter__title`);
|
|
102
|
-
const dialogDescriptionId = (0, _compose.useInstanceId)(_blockEditor.LinkControl, `link-ui-block-inserter__description`);
|
|
103
|
-
if (!clientId) {
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
107
|
-
className: "link-ui-block-inserter",
|
|
108
|
-
role: "dialog",
|
|
109
|
-
"aria-labelledby": dialogTitleId,
|
|
110
|
-
"aria-describedby": dialogDescriptionId,
|
|
111
|
-
ref: focusOnMountRef,
|
|
112
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.VisuallyHidden, {
|
|
113
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h2", {
|
|
114
|
-
id: dialogTitleId,
|
|
115
|
-
children: (0, _i18n.__)('Add block')
|
|
116
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
|
|
117
|
-
id: dialogDescriptionId,
|
|
118
|
-
children: (0, _i18n.__)('Choose a block to add to your Navigation.')
|
|
119
|
-
})]
|
|
120
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
121
|
-
className: "link-ui-block-inserter__back",
|
|
122
|
-
icon: (0, _i18n.isRTL)() ? _icons.chevronRightSmall : _icons.chevronLeftSmall,
|
|
123
|
-
onClick: e => {
|
|
124
|
-
e.preventDefault();
|
|
125
|
-
onBack();
|
|
126
|
-
},
|
|
127
|
-
size: "small",
|
|
128
|
-
children: (0, _i18n.__)('Back')
|
|
129
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(QuickInserter, {
|
|
130
|
-
rootClientId: rootBlockClientId,
|
|
131
|
-
clientId: clientId,
|
|
132
|
-
isAppender: false,
|
|
133
|
-
prioritizePatterns: false,
|
|
134
|
-
selectBlockOnInsert: true,
|
|
135
|
-
hasSearch: false
|
|
136
|
-
})]
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
82
|
function UnforwardedLinkUI(props, ref) {
|
|
140
83
|
const {
|
|
141
84
|
label,
|
|
@@ -146,42 +89,14 @@ function UnforwardedLinkUI(props, ref) {
|
|
|
146
89
|
} = props.link;
|
|
147
90
|
const postType = type || 'page';
|
|
148
91
|
const [addingBlock, setAddingBlock] = (0, _element.useState)(false);
|
|
92
|
+
const [addingPage, setAddingPage] = (0, _element.useState)(false);
|
|
149
93
|
const [focusAddBlockButton, setFocusAddBlockButton] = (0, _element.useState)(false);
|
|
150
|
-
const
|
|
151
|
-
saveEntityRecord
|
|
152
|
-
} = (0, _data.useDispatch)(_coreData.store);
|
|
94
|
+
const [focusAddPageButton, setFocusAddPageButton] = (0, _element.useState)(false);
|
|
153
95
|
const permissions = (0, _coreData.useResourcePermissions)({
|
|
154
96
|
kind: 'postType',
|
|
155
97
|
name: postType
|
|
156
98
|
});
|
|
157
99
|
|
|
158
|
-
// Check if we're in contentOnly mode
|
|
159
|
-
const blockEditingMode = (0, _blockEditor.useBlockEditingMode)();
|
|
160
|
-
const isDefaultBlockEditingMode = blockEditingMode === 'default';
|
|
161
|
-
async function handleCreate(pageTitle) {
|
|
162
|
-
const page = await saveEntityRecord('postType', postType, {
|
|
163
|
-
title: pageTitle,
|
|
164
|
-
status: 'draft'
|
|
165
|
-
});
|
|
166
|
-
return {
|
|
167
|
-
id: page.id,
|
|
168
|
-
type: postType,
|
|
169
|
-
// Make `title` property consistent with that in `fetchLinkSuggestions` where the `rendered` title (containing HTML entities)
|
|
170
|
-
// is also being decoded. By being consistent in both locations we avoid having to branch in the rendering output code.
|
|
171
|
-
// Ideally in the future we will update both APIs to utilise the "raw" form of the title which is better suited to edit contexts.
|
|
172
|
-
// e.g.
|
|
173
|
-
// - title.raw = "Yes & No"
|
|
174
|
-
// - title.rendered = "Yes & No"
|
|
175
|
-
// - decodeEntities( title.rendered ) = "Yes & No"
|
|
176
|
-
// See:
|
|
177
|
-
// - https://github.com/WordPress/gutenberg/pull/41063
|
|
178
|
-
// - https://github.com/WordPress/gutenberg/blob/a1e1fdc0e6278457e9f4fc0b31ac6d2095f5450b/packages/core-data/src/fetch/__experimental-fetch-link-suggestions.js#L212-L218
|
|
179
|
-
title: (0, _htmlEntities.decodeEntities)(page.title.rendered),
|
|
180
|
-
url: page.link,
|
|
181
|
-
kind: 'post-type'
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
|
|
185
100
|
// Memoize link value to avoid overriding the LinkControl's internal state.
|
|
186
101
|
// This is a temporary fix. See https://github.com/WordPress/gutenberg/issues/50976#issuecomment-1568226407.
|
|
187
102
|
const link = (0, _element.useMemo)(() => ({
|
|
@@ -189,15 +104,22 @@ function UnforwardedLinkUI(props, ref) {
|
|
|
189
104
|
opensInNewTab,
|
|
190
105
|
title: label && (0, _dom.__unstableStripHTML)(label)
|
|
191
106
|
}), [label, opensInNewTab, url]);
|
|
192
|
-
const
|
|
193
|
-
|
|
107
|
+
const handlePageCreated = pageLink => {
|
|
108
|
+
// Set the new page as the current link
|
|
109
|
+
props.onChange(pageLink);
|
|
110
|
+
// Return to main Link UI
|
|
111
|
+
setAddingPage(false);
|
|
112
|
+
};
|
|
113
|
+
const dialogTitleId = (0, _compose.useInstanceId)(LinkUI, 'link-ui-link-control__title');
|
|
114
|
+
const dialogDescriptionId = (0, _compose.useInstanceId)(LinkUI, 'link-ui-link-control__description');
|
|
115
|
+
const blockEditingMode = (0, _blockEditor.useBlockEditingMode)();
|
|
194
116
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.Popover, {
|
|
195
117
|
ref: ref,
|
|
196
118
|
placement: "bottom",
|
|
197
119
|
onClose: props.onClose,
|
|
198
120
|
anchor: props.anchor,
|
|
199
121
|
shift: true,
|
|
200
|
-
children: [!addingBlock && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
122
|
+
children: [!addingBlock && !addingPage && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
201
123
|
role: "dialog",
|
|
202
124
|
"aria-labelledby": dialogTitleId,
|
|
203
125
|
"aria-describedby": dialogDescriptionId,
|
|
@@ -214,51 +136,66 @@ function UnforwardedLinkUI(props, ref) {
|
|
|
214
136
|
hasRichPreviews: true,
|
|
215
137
|
value: link,
|
|
216
138
|
showInitialSuggestions: true,
|
|
217
|
-
withCreateSuggestion:
|
|
218
|
-
createSuggestion: handleCreate,
|
|
219
|
-
createSuggestionButtonText: searchTerm => {
|
|
220
|
-
let format;
|
|
221
|
-
if (type === 'post') {
|
|
222
|
-
/* translators: %s: search term. */
|
|
223
|
-
format = (0, _i18n.__)('Create draft post: <mark>%s</mark>');
|
|
224
|
-
} else {
|
|
225
|
-
/* translators: %s: search term. */
|
|
226
|
-
format = (0, _i18n.__)('Create draft page: <mark>%s</mark>');
|
|
227
|
-
}
|
|
228
|
-
return (0, _element.createInterpolateElement)((0, _i18n.sprintf)(format, searchTerm), {
|
|
229
|
-
mark: /*#__PURE__*/(0, _jsxRuntime.jsx)("mark", {})
|
|
230
|
-
});
|
|
231
|
-
},
|
|
139
|
+
withCreateSuggestion: false,
|
|
232
140
|
noDirectEntry: !!type,
|
|
233
141
|
noURLSuggestion: !!type,
|
|
234
142
|
suggestionsQuery: getSuggestionsQuery(type, kind),
|
|
235
143
|
onChange: props.onChange,
|
|
236
144
|
onRemove: props.onRemove,
|
|
237
145
|
onCancel: props.onCancel,
|
|
238
|
-
renderControlBottom: () =>
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
setFocusAddBlockButton(false);
|
|
146
|
+
renderControlBottom: () => {
|
|
147
|
+
// Don't show the tools when there is submitted link (preview state).
|
|
148
|
+
if (link?.url?.length) {
|
|
149
|
+
return null;
|
|
243
150
|
}
|
|
244
|
-
|
|
151
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(LinkUITools, {
|
|
152
|
+
focusAddBlockButton: focusAddBlockButton,
|
|
153
|
+
focusAddPageButton: focusAddPageButton,
|
|
154
|
+
setAddingBlock: () => {
|
|
155
|
+
setAddingBlock(true);
|
|
156
|
+
setFocusAddBlockButton(false);
|
|
157
|
+
},
|
|
158
|
+
setAddingPage: () => {
|
|
159
|
+
setAddingPage(true);
|
|
160
|
+
setFocusAddPageButton(false);
|
|
161
|
+
},
|
|
162
|
+
canAddPage: permissions?.canCreate && type === 'page',
|
|
163
|
+
canAddBlock: blockEditingMode === 'default'
|
|
164
|
+
});
|
|
165
|
+
}
|
|
245
166
|
})]
|
|
246
|
-
}), addingBlock && /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
167
|
+
}), addingBlock && /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockInserter.default, {
|
|
247
168
|
clientId: props.clientId,
|
|
248
169
|
onBack: () => {
|
|
249
170
|
setAddingBlock(false);
|
|
250
171
|
setFocusAddBlockButton(true);
|
|
251
|
-
|
|
172
|
+
setFocusAddPageButton(false);
|
|
173
|
+
},
|
|
174
|
+
onBlockInsert: props?.onBlockInsert
|
|
175
|
+
}), addingPage && /*#__PURE__*/(0, _jsxRuntime.jsx)(_pageCreator.LinkUIPageCreator, {
|
|
176
|
+
postType: postType,
|
|
177
|
+
onBack: () => {
|
|
178
|
+
setAddingPage(false);
|
|
179
|
+
setFocusAddPageButton(true);
|
|
180
|
+
setFocusAddBlockButton(false);
|
|
181
|
+
},
|
|
182
|
+
onPageCreated: handlePageCreated,
|
|
183
|
+
initialTitle: link?.url || ''
|
|
252
184
|
})]
|
|
253
185
|
});
|
|
254
186
|
}
|
|
255
187
|
const LinkUI = exports.LinkUI = (0, _element.forwardRef)(UnforwardedLinkUI);
|
|
256
188
|
const LinkUITools = ({
|
|
257
189
|
setAddingBlock,
|
|
258
|
-
|
|
190
|
+
setAddingPage,
|
|
191
|
+
focusAddBlockButton,
|
|
192
|
+
focusAddPageButton,
|
|
193
|
+
canAddPage,
|
|
194
|
+
canAddBlock
|
|
259
195
|
}) => {
|
|
260
196
|
const blockInserterAriaRole = 'listbox';
|
|
261
197
|
const addBlockButtonRef = (0, _element.useRef)();
|
|
198
|
+
const addPageButtonRef = (0, _element.useRef)();
|
|
262
199
|
|
|
263
200
|
// Focus the add block button when the popover is opened.
|
|
264
201
|
(0, _element.useEffect)(() => {
|
|
@@ -266,9 +203,32 @@ const LinkUITools = ({
|
|
|
266
203
|
addBlockButtonRef.current?.focus();
|
|
267
204
|
}
|
|
268
205
|
}, [focusAddBlockButton]);
|
|
269
|
-
|
|
206
|
+
|
|
207
|
+
// Focus the add page button when the popover is opened.
|
|
208
|
+
(0, _element.useEffect)(() => {
|
|
209
|
+
if (focusAddPageButton) {
|
|
210
|
+
addPageButtonRef.current?.focus();
|
|
211
|
+
}
|
|
212
|
+
}, [focusAddPageButton]);
|
|
213
|
+
|
|
214
|
+
// Don't render anything if neither button should be shown
|
|
215
|
+
if (!canAddPage && !canAddBlock) {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalVStack, {
|
|
219
|
+
spacing: 0,
|
|
270
220
|
className: "link-ui-tools",
|
|
271
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
221
|
+
children: [canAddPage && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
222
|
+
__next40pxDefaultSize: true,
|
|
223
|
+
ref: addPageButtonRef,
|
|
224
|
+
icon: _icons.plus,
|
|
225
|
+
onClick: e => {
|
|
226
|
+
e.preventDefault();
|
|
227
|
+
setAddingPage(true);
|
|
228
|
+
},
|
|
229
|
+
"aria-haspopup": blockInserterAriaRole,
|
|
230
|
+
children: (0, _i18n.__)('Create page')
|
|
231
|
+
}), canAddBlock && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
272
232
|
__next40pxDefaultSize: true,
|
|
273
233
|
ref: addBlockButtonRef,
|
|
274
234
|
icon: _icons.plus,
|
|
@@ -278,7 +238,7 @@ const LinkUITools = ({
|
|
|
278
238
|
},
|
|
279
239
|
"aria-haspopup": blockInserterAriaRole,
|
|
280
240
|
children: (0, _i18n.__)('Add block')
|
|
281
|
-
})
|
|
241
|
+
})]
|
|
282
242
|
});
|
|
283
243
|
};
|
|
284
244
|
var _default = exports.default = LinkUITools;
|