@wordpress/block-library 9.30.0 → 9.30.1-next.836ecdcae.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/link-ui.js +64 -56
- package/build/navigation-link/link-ui.js.map +1 -1
- package/build/navigation-link/page-creator.js +143 -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/link-ui.js +68 -60
- package/build-module/navigation-link/link-ui.js.map +1 -1
- package/build-module/navigation-link/page-creator.js +137 -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/editor.scss +17 -0
- package/src/navigation-link/link-ui.js +88 -81
- package/src/navigation-link/page-creator.js +164 -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,GAAAL,OAAA;AAAgF,IAAAM,WAAA,GAAAN,OAAA;AAbhF;AACA;AACA;;AAaA,MAAMO,aAAa,GAAG;EACrBC,SAAS,EAAE,2CAA2C;EACtDC,SAAS,EAAE;AACZ,CAAC;AAED,MAAMC,uCAAuC,GAAG,CAC/C,sBAAsB,EACtB,yBAAyB,CACzB;AAED,SAASC,cAAcA,CAAE;EACxBC,KAAK;EACLC,OAAO;EACPC,aAAa;EACbC,MAAM;EACNC;AACD,CAAC,EAAG;EACH,MAAM;IAAEC,WA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AC,CAAC;UACV,CAAG;UAAA0B,QAAA,EAED,IAAAC,QAAE,EAAE,SAAU;QAAC,CACR,CAAC,eACX,IAAAlC,WAAA,CAAAoB,GAAA,EAACxB,WAAA,CAAAyB,QAAQ;UACRC,IAAI,EAAGmC,kBAAa;UACpBhC,OAAO,EAAGA,CAAA,KAAM;YACfY,cAAc,CAAE,CAAErB,QAAQ,CAAE,EAAE4B,YAAa,CAAC;YAC5CrC,OAAO,CAAC,CAAC;UACV,CAAG;UAAA0B,QAAA,EAED,IAAAC,QAAE,EAAE,WAAY;QAAC,CACV,CAAC,eACX,IAAAlC,WAAA,CAAAoB,GAAA,EAACf,cAAc;UACdC,KAAK,EAAGA,KAAO;UACfC,OAAO,EAAGA,OAAS;UACnBC,aAAa,EAAG4B,KAAK,CAAC5B,aAAe;UACrCC,MAAM,EAAG2B,KAAK,CAAC3B,MAAQ;UACvBC,gBAAgB,EAAG0B,KAAK,CAAC1B;QAAkB,CAC3C,CAAC;MAAA,CACQ,CAAC,eACZ,IAAAV,WAAA,CAAAoB,GAAA,EAACxB,WAAA,CAAA2D,SAAS;QAAAtB,QAAA,eACT,IAAAjC,WAAA,CAAAoB,GAAA,EAACxB,WAAA,CAAAyB,QAAQ;UACRI,OAAO,EAAGA,CAAA,KAAM;YACfc,YAAY,CAAE,CAAEvB,QAAQ,CAAE,EAAE,KAAM,CAAC;YACnCT,OAAO,CAAC,CAAC;UACV,CAAG;UAAA0B,QAAA,EAEDO;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,2BAA2B,GAAG,CACnC,sBAAsB,EACtB,yBAAyB,CACzB;AACD,MAAM;EAAEC;AAAgB,CAAC,GAAG,IAAAC,kBAAM,EAAEC,wBAAuB,CAAC;AAE5D,SAASC,sBAAsBA,CAAE;EAAEC,KAAK;EAAEC,aAAa;EAAEC;AAAiB,CAAC,EAAG;EAC7E,MAAM;IAAEC;EAAsB,CAAC,GAAG,IAAAC,iBAAW,EAAEC,kBAAiB,CAAC;EAEjE,MAAMC,oBAAoB,GAAGX,2BAA2B,EAAEY,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D,WAAA,CAAAuB,GAAA,EAACpC,YAAA,CAAA+E,iBAAiB;IAACC,KAAK,EAAC,MAAM;IAAAhB,QAAA,eAC9B,IAAAnD,WAAA,CAAAiD,IAAA,EAAC5D,WAAA,CAAA+E,SAAS;MAACpB,KAAK,EAAG,IAAM;MAAAG,QAAA,gBACxB,IAAAnD,WAAA,CAAAiD,IAAA,EAAC5D,WAAA,CAAAgF,oBAAM;QAACnB,SAAS,EAAC,+CAA+C;QAAAC,QAAA,gBAChE,IAAAnD,WAAA,CAAAuB,GAAA,EAAClC,WAAA,CAAAiF,qBAAO;UACPpB,SAAS,EAAC,8CAA8C;UACxDqB,KAAK,EAAG,CAAG;UAAApB,QAAA,EAET,IAAAjD,QAAE,EAAE,MAAO;QAAC,CACN,CAAC,EACR+D,gBAAgB,KAAK,SAAS,iBAC/B,IAAAjE,WAAA,CAAAuB,GAAA,EAAC/B,uBAAA,CAAAmD,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;UACD5D,WAAW,EAAGA,WAAa;UAC3B+D,2BAA2B,EAC1BA;QACA,CACD,CACD;MAAA,CACM,CAAC,eACT,IAAAhE,WAAA,CAAAuB,GAAA,EAACS,WAAW;QAAA,GAAM2B;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,MAAMC,2BAA2B,GAAG,CACnC,sBAAsB,EACtB,yBAAyB,CACzB;AACD,MAAM;EAAEC;AAAgB,CAAC,GAAG,IAAAC,kBAAM,EAAEC,wBAAuB,CAAC;AAE5D,SAASC,sBAAsBA,CAAE;EAAEC,KAAK;EAAEC,aAAa;EAAEC;AAAiB,CAAC,EAAG;EAC7E,MAAM;IAAEC,qBAAqB;IAAEC;EAAY,CAAC,GAC3C,IAAAC,iBAAW,EAAEC,kBAAiB,CAAC;EAEhC,MAAMC,oBAAoB,GAAG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sB,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":[]}
|
|
@@ -11,11 +11,11 @@ var _i18n = require("@wordpress/i18n");
|
|
|
11
11
|
var _blockEditor = require("@wordpress/block-editor");
|
|
12
12
|
var _element = require("@wordpress/element");
|
|
13
13
|
var _coreData = require("@wordpress/core-data");
|
|
14
|
-
var _htmlEntities = require("@wordpress/html-entities");
|
|
15
14
|
var _data = require("@wordpress/data");
|
|
16
15
|
var _icons = require("@wordpress/icons");
|
|
17
16
|
var _compose = require("@wordpress/compose");
|
|
18
17
|
var _lockUnlock = require("../lock-unlock");
|
|
18
|
+
var _pageCreator = require("./page-creator");
|
|
19
19
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
20
20
|
/**
|
|
21
21
|
* WordPress dependencies
|
|
@@ -85,7 +85,8 @@ function getSuggestionsQuery(type, kind) {
|
|
|
85
85
|
}
|
|
86
86
|
function LinkUIBlockInserter({
|
|
87
87
|
clientId,
|
|
88
|
-
onBack
|
|
88
|
+
onBack,
|
|
89
|
+
onBlockInsert
|
|
89
90
|
}) {
|
|
90
91
|
const {
|
|
91
92
|
rootBlockClientId
|
|
@@ -131,7 +132,8 @@ function LinkUIBlockInserter({
|
|
|
131
132
|
clientId: clientId,
|
|
132
133
|
isAppender: false,
|
|
133
134
|
prioritizePatterns: false,
|
|
134
|
-
selectBlockOnInsert:
|
|
135
|
+
selectBlockOnInsert: !onBlockInsert,
|
|
136
|
+
onSelect: onBlockInsert ? onBlockInsert : undefined,
|
|
135
137
|
hasSearch: false
|
|
136
138
|
})]
|
|
137
139
|
});
|
|
@@ -146,42 +148,14 @@ function UnforwardedLinkUI(props, ref) {
|
|
|
146
148
|
} = props.link;
|
|
147
149
|
const postType = type || 'page';
|
|
148
150
|
const [addingBlock, setAddingBlock] = (0, _element.useState)(false);
|
|
151
|
+
const [addingPage, setAddingPage] = (0, _element.useState)(false);
|
|
149
152
|
const [focusAddBlockButton, setFocusAddBlockButton] = (0, _element.useState)(false);
|
|
150
|
-
const
|
|
151
|
-
saveEntityRecord
|
|
152
|
-
} = (0, _data.useDispatch)(_coreData.store);
|
|
153
|
+
const [focusAddPageButton, setFocusAddPageButton] = (0, _element.useState)(false);
|
|
153
154
|
const permissions = (0, _coreData.useResourcePermissions)({
|
|
154
155
|
kind: 'postType',
|
|
155
156
|
name: postType
|
|
156
157
|
});
|
|
157
158
|
|
|
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
159
|
// Memoize link value to avoid overriding the LinkControl's internal state.
|
|
186
160
|
// This is a temporary fix. See https://github.com/WordPress/gutenberg/issues/50976#issuecomment-1568226407.
|
|
187
161
|
const link = (0, _element.useMemo)(() => ({
|
|
@@ -189,15 +163,22 @@ function UnforwardedLinkUI(props, ref) {
|
|
|
189
163
|
opensInNewTab,
|
|
190
164
|
title: label && (0, _dom.__unstableStripHTML)(label)
|
|
191
165
|
}), [label, opensInNewTab, url]);
|
|
166
|
+
const handlePageCreated = pageLink => {
|
|
167
|
+
// Set the new page as the current link
|
|
168
|
+
props.onChange(pageLink);
|
|
169
|
+
// Return to main Link UI
|
|
170
|
+
setAddingPage(false);
|
|
171
|
+
};
|
|
192
172
|
const dialogTitleId = (0, _compose.useInstanceId)(LinkUI, `link-ui-link-control__title`);
|
|
193
173
|
const dialogDescriptionId = (0, _compose.useInstanceId)(LinkUI, `link-ui-link-control__description`);
|
|
174
|
+
const blockEditingMode = (0, _blockEditor.useBlockEditingMode)();
|
|
194
175
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.Popover, {
|
|
195
176
|
ref: ref,
|
|
196
177
|
placement: "bottom",
|
|
197
178
|
onClose: props.onClose,
|
|
198
179
|
anchor: props.anchor,
|
|
199
180
|
shift: true,
|
|
200
|
-
children: [!addingBlock && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
181
|
+
children: [!addingBlock && !addingPage && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
201
182
|
role: "dialog",
|
|
202
183
|
"aria-labelledby": dialogTitleId,
|
|
203
184
|
"aria-describedby": dialogDescriptionId,
|
|
@@ -214,33 +195,26 @@ function UnforwardedLinkUI(props, ref) {
|
|
|
214
195
|
hasRichPreviews: true,
|
|
215
196
|
value: link,
|
|
216
197
|
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
|
-
},
|
|
198
|
+
withCreateSuggestion: false,
|
|
232
199
|
noDirectEntry: !!type,
|
|
233
200
|
noURLSuggestion: !!type,
|
|
234
201
|
suggestionsQuery: getSuggestionsQuery(type, kind),
|
|
235
202
|
onChange: props.onChange,
|
|
236
203
|
onRemove: props.onRemove,
|
|
237
204
|
onCancel: props.onCancel,
|
|
238
|
-
renderControlBottom: () => !link?.url?.length &&
|
|
205
|
+
renderControlBottom: () => !link?.url?.length && /*#__PURE__*/(0, _jsxRuntime.jsx)(LinkUITools, {
|
|
239
206
|
focusAddBlockButton: focusAddBlockButton,
|
|
207
|
+
focusAddPageButton: focusAddPageButton,
|
|
240
208
|
setAddingBlock: () => {
|
|
241
209
|
setAddingBlock(true);
|
|
242
210
|
setFocusAddBlockButton(false);
|
|
243
|
-
}
|
|
211
|
+
},
|
|
212
|
+
setAddingPage: () => {
|
|
213
|
+
setAddingPage(true);
|
|
214
|
+
setFocusAddPageButton(false);
|
|
215
|
+
},
|
|
216
|
+
canCreatePage: permissions.canCreate,
|
|
217
|
+
blockEditingMode: blockEditingMode
|
|
244
218
|
})
|
|
245
219
|
})]
|
|
246
220
|
}), addingBlock && /*#__PURE__*/(0, _jsxRuntime.jsx)(LinkUIBlockInserter, {
|
|
@@ -248,17 +222,33 @@ function UnforwardedLinkUI(props, ref) {
|
|
|
248
222
|
onBack: () => {
|
|
249
223
|
setAddingBlock(false);
|
|
250
224
|
setFocusAddBlockButton(true);
|
|
251
|
-
|
|
225
|
+
setFocusAddPageButton(false);
|
|
226
|
+
},
|
|
227
|
+
onBlockInsert: props?.onBlockInsert
|
|
228
|
+
}), addingPage && /*#__PURE__*/(0, _jsxRuntime.jsx)(_pageCreator.LinkUIPageCreator, {
|
|
229
|
+
postType: postType,
|
|
230
|
+
onBack: () => {
|
|
231
|
+
setAddingPage(false);
|
|
232
|
+
setFocusAddPageButton(true);
|
|
233
|
+
setFocusAddBlockButton(false);
|
|
234
|
+
},
|
|
235
|
+
onPageCreated: handlePageCreated,
|
|
236
|
+
initialTitle: link?.url || ''
|
|
252
237
|
})]
|
|
253
238
|
});
|
|
254
239
|
}
|
|
255
240
|
const LinkUI = exports.LinkUI = (0, _element.forwardRef)(UnforwardedLinkUI);
|
|
256
241
|
const LinkUITools = ({
|
|
257
242
|
setAddingBlock,
|
|
258
|
-
|
|
243
|
+
setAddingPage,
|
|
244
|
+
focusAddBlockButton,
|
|
245
|
+
focusAddPageButton,
|
|
246
|
+
canCreatePage,
|
|
247
|
+
blockEditingMode
|
|
259
248
|
}) => {
|
|
260
249
|
const blockInserterAriaRole = 'listbox';
|
|
261
250
|
const addBlockButtonRef = (0, _element.useRef)();
|
|
251
|
+
const addPageButtonRef = (0, _element.useRef)();
|
|
262
252
|
|
|
263
253
|
// Focus the add block button when the popover is opened.
|
|
264
254
|
(0, _element.useEffect)(() => {
|
|
@@ -266,9 +256,27 @@ const LinkUITools = ({
|
|
|
266
256
|
addBlockButtonRef.current?.focus();
|
|
267
257
|
}
|
|
268
258
|
}, [focusAddBlockButton]);
|
|
269
|
-
|
|
259
|
+
|
|
260
|
+
// Focus the add page button when the popover is opened.
|
|
261
|
+
(0, _element.useEffect)(() => {
|
|
262
|
+
if (focusAddPageButton) {
|
|
263
|
+
addPageButtonRef.current?.focus();
|
|
264
|
+
}
|
|
265
|
+
}, [focusAddPageButton]);
|
|
266
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalVStack, {
|
|
267
|
+
spacing: 0,
|
|
270
268
|
className: "link-ui-tools",
|
|
271
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
269
|
+
children: [canCreatePage && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
270
|
+
__next40pxDefaultSize: true,
|
|
271
|
+
ref: addPageButtonRef,
|
|
272
|
+
icon: _icons.plus,
|
|
273
|
+
onClick: e => {
|
|
274
|
+
e.preventDefault();
|
|
275
|
+
setAddingPage(true);
|
|
276
|
+
},
|
|
277
|
+
"aria-haspopup": blockInserterAriaRole,
|
|
278
|
+
children: (0, _i18n.__)('Create page')
|
|
279
|
+
}), blockEditingMode === 'default' && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
272
280
|
__next40pxDefaultSize: true,
|
|
273
281
|
ref: addBlockButtonRef,
|
|
274
282
|
icon: _icons.plus,
|
|
@@ -278,7 +286,7 @@ const LinkUITools = ({
|
|
|
278
286
|
},
|
|
279
287
|
"aria-haspopup": blockInserterAriaRole,
|
|
280
288
|
children: (0, _i18n.__)('Add block')
|
|
281
|
-
})
|
|
289
|
+
})]
|
|
282
290
|
});
|
|
283
291
|
};
|
|
284
292
|
var _default = exports.default = LinkUITools;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_dom","require","_components","_i18n","_blockEditor","_element","_coreData","_htmlEntities","_data","_icons","_compose","_lockUnlock","_jsxRuntime","PrivateQuickInserter","QuickInserter","unlock","blockEditorPrivateApis","getSuggestionsQuery","type","kind","subtype","initialSuggestionsSearchOptions","perPage","LinkUIBlockInserter","clientId","onBack","rootBlockClientId","useSelect","select","getBlockRootClientId","blockEditorStore","focusOnMountRef","useFocusOnMount","dialogTitleId","useInstanceId","LinkControl","dialogDescriptionId","jsxs","className","role","ref","children","VisuallyHidden","jsx","id","__","Button","icon","isRTL","chevronRightSmall","chevronLeftSmall","onClick","e","preventDefault","size","rootClientId","isAppender","prioritizePatterns","selectBlockOnInsert","hasSearch","UnforwardedLinkUI","props","label","url","opensInNewTab","link","postType","addingBlock","setAddingBlock","useState","focusAddBlockButton","setFocusAddBlockButton","saveEntityRecord","useDispatch","coreStore","permissions","useResourcePermissions","name","blockEditingMode","useBlockEditingMode","isDefaultBlockEditingMode","handleCreate","pageTitle","page","title","status","decodeEntities","rendered","useMemo","stripHTML","LinkUI","Popover","placement","onClose","anchor","shift","hasTextControl","hasRichPreviews","value","showInitialSuggestions","withCreateSuggestion","canCreate","createSuggestion","createSuggestionButtonText","searchTerm","format","createInterpolateElement","sprintf","mark","noDirectEntry","noURLSuggestion","suggestionsQuery","onChange","onRemove","onCancel","renderControlBottom","length","LinkUITools","exports","forwardRef","blockInserterAriaRole","addBlockButtonRef","useRef","useEffect","current","focus","__experimentalVStack","__next40pxDefaultSize","plus","_default","default"],"sources":["@wordpress/block-library/src/navigation-link/link-ui.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\nimport {\n\tPopover,\n\tButton,\n\tVisuallyHidden,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { __, sprintf, isRTL } from '@wordpress/i18n';\nimport {\n\tLinkControl,\n\tstore as blockEditorStore,\n\tprivateApis as blockEditorPrivateApis,\n\tuseBlockEditingMode,\n} from '@wordpress/block-editor';\nimport {\n\tcreateInterpolateElement,\n\tuseMemo,\n\tuseState,\n\tuseRef,\n\tuseEffect,\n\tforwardRef,\n} from '@wordpress/element';\nimport {\n\tstore as coreStore,\n\tuseResourcePermissions,\n} from '@wordpress/core-data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { chevronLeftSmall, chevronRightSmall, plus } from '@wordpress/icons';\nimport { useInstanceId, useFocusOnMount } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../lock-unlock';\n\nconst { PrivateQuickInserter: QuickInserter } = unlock(\n\tblockEditorPrivateApis\n);\n\n/**\n * Given the Link block's type attribute, return the query params to give to\n * /wp/v2/search.\n *\n * @param {string} type Link block's type attribute.\n * @param {string} kind Link block's entity of kind (post-type|taxonomy)\n * @return {{ type?: string, subtype?: string }} Search query params.\n */\nexport function getSuggestionsQuery( type, kind ) {\n\tswitch ( type ) {\n\t\tcase 'post':\n\t\tcase 'page':\n\t\t\treturn { type: 'post', subtype: type };\n\t\tcase 'category':\n\t\t\treturn { type: 'term', subtype: 'category' };\n\t\tcase 'tag':\n\t\t\treturn { type: 'term', subtype: 'post_tag' };\n\t\tcase 'post_format':\n\t\t\treturn { type: 'post-format' };\n\t\tdefault:\n\t\t\tif ( kind === 'taxonomy' ) {\n\t\t\t\treturn { type: 'term', subtype: type };\n\t\t\t}\n\t\t\tif ( kind === 'post-type' ) {\n\t\t\t\treturn { type: 'post', subtype: type };\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t// for custom link which has no type\n\t\t\t\t// always show pages as initial suggestions\n\t\t\t\tinitialSuggestionsSearchOptions: {\n\t\t\t\t\ttype: 'post',\n\t\t\t\t\tsubtype: 'page',\n\t\t\t\t\tperPage: 20,\n\t\t\t\t},\n\t\t\t};\n\t}\n}\n\nfunction LinkUIBlockInserter( { clientId, onBack } ) {\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\tconst focusOnMountRef = useFocusOnMount( 'firstElement' );\n\n\tconst dialogTitleId = useInstanceId(\n\t\tLinkControl,\n\t\t`link-ui-block-inserter__title`\n\t);\n\tconst dialogDescriptionId = useInstanceId(\n\t\tLinkControl,\n\t\t`link-ui-block-inserter__description`\n\t);\n\n\tif ( ! clientId ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<div\n\t\t\tclassName=\"link-ui-block-inserter\"\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 }>{ __( 'Add block' ) }</h2>\n\n\t\t\t\t<p id={ dialogDescriptionId }>\n\t\t\t\t\t{ __( 'Choose a block to add to your Navigation.' ) }\n\t\t\t\t</p>\n\t\t\t</VisuallyHidden>\n\n\t\t\t<Button\n\t\t\t\tclassName=\"link-ui-block-inserter__back\"\n\t\t\t\ticon={ isRTL() ? chevronRightSmall : chevronLeftSmall }\n\t\t\t\tonClick={ ( e ) => {\n\t\t\t\t\te.preventDefault();\n\t\t\t\t\tonBack();\n\t\t\t\t} }\n\t\t\t\tsize=\"small\"\n\t\t\t>\n\t\t\t\t{ __( 'Back' ) }\n\t\t\t</Button>\n\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\n\t\t\t\thasSearch={ false }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n\nfunction UnforwardedLinkUI( props, ref ) {\n\tconst { label, url, opensInNewTab, type, kind } = props.link;\n\tconst postType = type || 'page';\n\n\tconst [ addingBlock, setAddingBlock ] = useState( false );\n\tconst [ focusAddBlockButton, setFocusAddBlockButton ] = useState( false );\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst permissions = useResourcePermissions( {\n\t\tkind: 'postType',\n\t\tname: postType,\n\t} );\n\n\t// Check if we're in contentOnly mode\n\tconst blockEditingMode = useBlockEditingMode();\n\tconst isDefaultBlockEditingMode = blockEditingMode === 'default';\n\n\tasync function handleCreate( pageTitle ) {\n\t\tconst page = await saveEntityRecord( 'postType', postType, {\n\t\t\ttitle: pageTitle,\n\t\t\tstatus: 'draft',\n\t\t} );\n\n\t\treturn {\n\t\t\tid: page.id,\n\t\t\ttype: postType,\n\t\t\t// Make `title` property consistent with that in `fetchLinkSuggestions` where the `rendered` title (containing HTML entities)\n\t\t\t// is also being decoded. By being consistent in both locations we avoid having to branch in the rendering output code.\n\t\t\t// Ideally in the future we will update both APIs to utilise the \"raw\" form of the title which is better suited to edit contexts.\n\t\t\t// e.g.\n\t\t\t// - title.raw = \"Yes & No\"\n\t\t\t// - title.rendered = \"Yes & No\"\n\t\t\t// - decodeEntities( title.rendered ) = \"Yes & No\"\n\t\t\t// See:\n\t\t\t// - https://github.com/WordPress/gutenberg/pull/41063\n\t\t\t// - https://github.com/WordPress/gutenberg/blob/a1e1fdc0e6278457e9f4fc0b31ac6d2095f5450b/packages/core-data/src/fetch/__experimental-fetch-link-suggestions.js#L212-L218\n\t\t\ttitle: decodeEntities( page.title.rendered ),\n\t\t\turl: page.link,\n\t\t\tkind: 'post-type',\n\t\t};\n\t}\n\n\t// Memoize link value to avoid overriding the LinkControl's internal state.\n\t// This is a temporary fix. See https://github.com/WordPress/gutenberg/issues/50976#issuecomment-1568226407.\n\tconst link = useMemo(\n\t\t() => ( {\n\t\t\turl,\n\t\t\topensInNewTab,\n\t\t\ttitle: label && stripHTML( label ),\n\t\t} ),\n\t\t[ label, opensInNewTab, url ]\n\t);\n\n\tconst dialogTitleId = useInstanceId(\n\t\tLinkUI,\n\t\t`link-ui-link-control__title`\n\t);\n\tconst dialogDescriptionId = useInstanceId(\n\t\tLinkUI,\n\t\t`link-ui-link-control__description`\n\t);\n\n\treturn (\n\t\t<Popover\n\t\t\tref={ ref }\n\t\t\tplacement=\"bottom\"\n\t\t\tonClose={ props.onClose }\n\t\t\tanchor={ props.anchor }\n\t\t\tshift\n\t\t>\n\t\t\t{ ! addingBlock && (\n\t\t\t\t<div\n\t\t\t\t\trole=\"dialog\"\n\t\t\t\t\taria-labelledby={ dialogTitleId }\n\t\t\t\t\taria-describedby={ dialogDescriptionId }\n\t\t\t\t>\n\t\t\t\t\t<VisuallyHidden>\n\t\t\t\t\t\t<h2 id={ dialogTitleId }>{ __( 'Add link' ) }</h2>\n\n\t\t\t\t\t\t<p id={ dialogDescriptionId }>\n\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t'Search for and add a link to your Navigation.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</p>\n\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t\t<LinkControl\n\t\t\t\t\t\thasTextControl\n\t\t\t\t\t\thasRichPreviews\n\t\t\t\t\t\tvalue={ link }\n\t\t\t\t\t\tshowInitialSuggestions\n\t\t\t\t\t\twithCreateSuggestion={ permissions.canCreate }\n\t\t\t\t\t\tcreateSuggestion={ handleCreate }\n\t\t\t\t\t\tcreateSuggestionButtonText={ ( searchTerm ) => {\n\t\t\t\t\t\t\tlet format;\n\n\t\t\t\t\t\t\tif ( type === 'post' ) {\n\t\t\t\t\t\t\t\t/* translators: %s: search term. */\n\t\t\t\t\t\t\t\tformat = __(\n\t\t\t\t\t\t\t\t\t'Create draft post: <mark>%s</mark>'\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t/* translators: %s: search term. */\n\t\t\t\t\t\t\t\tformat = __(\n\t\t\t\t\t\t\t\t\t'Create draft page: <mark>%s</mark>'\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\treturn createInterpolateElement(\n\t\t\t\t\t\t\t\tsprintf( format, searchTerm ),\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tmark: <mark />,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tnoDirectEntry={ !! type }\n\t\t\t\t\t\tnoURLSuggestion={ !! type }\n\t\t\t\t\t\tsuggestionsQuery={ getSuggestionsQuery( type, kind ) }\n\t\t\t\t\t\tonChange={ props.onChange }\n\t\t\t\t\t\tonRemove={ props.onRemove }\n\t\t\t\t\t\tonCancel={ props.onCancel }\n\t\t\t\t\t\trenderControlBottom={ () =>\n\t\t\t\t\t\t\t! link?.url?.length &&\n\t\t\t\t\t\t\tisDefaultBlockEditingMode && (\n\t\t\t\t\t\t\t\t<LinkUITools\n\t\t\t\t\t\t\t\t\tfocusAddBlockButton={ focusAddBlockButton }\n\t\t\t\t\t\t\t\t\tsetAddingBlock={ () => {\n\t\t\t\t\t\t\t\t\t\tsetAddingBlock( true );\n\t\t\t\t\t\t\t\t\t\tsetFocusAddBlockButton( false );\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}\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t) }\n\n\t\t\t{ addingBlock && (\n\t\t\t\t<LinkUIBlockInserter\n\t\t\t\t\tclientId={ props.clientId }\n\t\t\t\t\tonBack={ () => {\n\t\t\t\t\t\tsetAddingBlock( false );\n\t\t\t\t\t\tsetFocusAddBlockButton( true );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</Popover>\n\t);\n}\n\nexport const LinkUI = forwardRef( UnforwardedLinkUI );\n\nconst LinkUITools = ( { setAddingBlock, focusAddBlockButton } ) => {\n\tconst blockInserterAriaRole = 'listbox';\n\tconst addBlockButtonRef = useRef();\n\n\t// Focus the add block button when the popover is opened.\n\tuseEffect( () => {\n\t\tif ( focusAddBlockButton ) {\n\t\t\taddBlockButtonRef.current?.focus();\n\t\t}\n\t}, [ focusAddBlockButton ] );\n\n\treturn (\n\t\t<VStack className=\"link-ui-tools\">\n\t\t\t<Button\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\tref={ addBlockButtonRef }\n\t\t\t\ticon={ plus }\n\t\t\t\tonClick={ ( e ) => {\n\t\t\t\t\te.preventDefault();\n\t\t\t\t\tsetAddingBlock( true );\n\t\t\t\t} }\n\t\t\t\taria-haspopup={ blockInserterAriaRole }\n\t\t\t>\n\t\t\t\t{ __( 'Add block' ) }\n\t\t\t</Button>\n\t\t</VStack>\n\t);\n};\n\nexport default LinkUITools;\n"],"mappings":";;;;;;;AAGA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAMA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,YAAA,GAAAH,OAAA;AAMA,IAAAI,QAAA,GAAAJ,OAAA;AAQA,IAAAK,SAAA,GAAAL,OAAA;AAIA,IAAAM,aAAA,GAAAN,OAAA;AACA,IAAAO,KAAA,GAAAP,OAAA;AACA,IAAAQ,MAAA,GAAAR,OAAA;AACA,IAAAS,QAAA,GAAAT,OAAA;AAKA,IAAAU,WAAA,GAAAV,OAAA;AAAwC,IAAAW,WAAA,GAAAX,OAAA;AArCxC;AACA;AACA;;AAgCA;AACA;AACA;;AAGA,MAAM;EAAEY,oBAAoB,EAAEC;AAAc,CAAC,GAAG,IAAAC,kBAAM,EACrDC,wBACD,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,mBAAmBA,CAAEC,IAAI,EAAEC,IAAI,EAAG;EACjD,QAASD,IAAI;IACZ,KAAK,MAAM;IACX,KAAK,MAAM;MACV,OAAO;QAAEA,IAAI,EAAE,MAAM;QAAEE,OAAO,EAAEF;MAAK,CAAC;IACvC,KAAK,UAAU;MACd,OAAO;QAAEA,IAAI,EAAE,MAAM;QAAEE,OAAO,EAAE;MAAW,CAAC;IAC7C,KAAK,KAAK;MACT,OAAO;QAAEF,IAAI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ChB,IAAKrD,mBAAmB,EAAG;MAC1BmD,iBAAiB,CAACG,OAAO,EAAEC,KAAK,CAAC,CAAC;IACnC;EACD,CAAC,EAAE,CAAEvD,mBAAmB,CAAG,CAAC;EAE5B,oBACC,IAAA1D,WAAA,CAAA+B,GAAA,EAACzC,WAAA,CAAA4H,oBAAM;IAACxF,SAAS,EAAC,eAAe;IAAAG,QAAA,eAChC,IAAA7B,WAAA,CAAA+B,GAAA,EAACzC,WAAA,CAAA4C,MAAM;MACNiF,qBAAqB;MACrBvF,GAAG,EAAGiF,iBAAmB;MACzB1E,IAAI,EAAGiF,WAAM;MACb7E,OAAO,EAAKC,CAAC,IAAM;QAClBA,CAAC,CAACC,cAAc,CAAC,CAAC;QAClBe,cAAc,CAAE,IAAK,CAAC;MACvB,CAAG;MACH,iBAAgBoD,qBAAuB;MAAA/E,QAAA,EAErC,IAAAI,QAAE,EAAE,WAAY;IAAC,CACZ;EAAC,CACF,CAAC;AAEX,CAAC;AAAC,IAAAoF,QAAA,GAAAX,OAAA,CAAAY,OAAA,GAEab,WAAW","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_dom","require","_components","_i18n","_blockEditor","_element","_coreData","_data","_icons","_compose","_lockUnlock","_pageCreator","_jsxRuntime","PrivateQuickInserter","QuickInserter","unlock","blockEditorPrivateApis","getSuggestionsQuery","type","kind","subtype","initialSuggestionsSearchOptions","perPage","LinkUIBlockInserter","clientId","onBack","onBlockInsert","rootBlockClientId","useSelect","select","getBlockRootClientId","blockEditorStore","focusOnMountRef","useFocusOnMount","dialogTitleId","useInstanceId","LinkControl","dialogDescriptionId","jsxs","className","role","ref","children","VisuallyHidden","jsx","id","__","Button","icon","isRTL","chevronRightSmall","chevronLeftSmall","onClick","e","preventDefault","size","rootClientId","isAppender","prioritizePatterns","selectBlockOnInsert","onSelect","undefined","hasSearch","UnforwardedLinkUI","props","label","url","opensInNewTab","link","postType","addingBlock","setAddingBlock","useState","addingPage","setAddingPage","focusAddBlockButton","setFocusAddBlockButton","focusAddPageButton","setFocusAddPageButton","permissions","useResourcePermissions","name","useMemo","title","stripHTML","handlePageCreated","pageLink","onChange","LinkUI","blockEditingMode","useBlockEditingMode","Popover","placement","onClose","anchor","shift","hasTextControl","hasRichPreviews","value","showInitialSuggestions","withCreateSuggestion","noDirectEntry","noURLSuggestion","suggestionsQuery","onRemove","onCancel","renderControlBottom","length","LinkUITools","canCreatePage","canCreate","LinkUIPageCreator","onPageCreated","initialTitle","exports","forwardRef","blockInserterAriaRole","addBlockButtonRef","useRef","addPageButtonRef","useEffect","current","focus","__experimentalVStack","spacing","__next40pxDefaultSize","plus","_default","default"],"sources":["@wordpress/block-library/src/navigation-link/link-ui.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\nimport {\n\tPopover,\n\tButton,\n\tVisuallyHidden,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { __, isRTL } from '@wordpress/i18n';\nimport {\n\tLinkControl,\n\tstore as blockEditorStore,\n\tprivateApis as blockEditorPrivateApis,\n\tuseBlockEditingMode,\n} from '@wordpress/block-editor';\nimport {\n\tuseMemo,\n\tuseState,\n\tuseRef,\n\tuseEffect,\n\tforwardRef,\n} from '@wordpress/element';\nimport { useResourcePermissions } from '@wordpress/core-data';\nimport { useSelect } from '@wordpress/data';\nimport { chevronLeftSmall, chevronRightSmall, plus } from '@wordpress/icons';\nimport { useInstanceId, useFocusOnMount } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../lock-unlock';\nimport { LinkUIPageCreator } from './page-creator';\n\nconst { PrivateQuickInserter: QuickInserter } = unlock(\n\tblockEditorPrivateApis\n);\n\n/**\n * Given the Link block's type attribute, return the query params to give to\n * /wp/v2/search.\n *\n * @param {string} type Link block's type attribute.\n * @param {string} kind Link block's entity of kind (post-type|taxonomy)\n * @return {{ type?: string, subtype?: string }} Search query params.\n */\nexport function getSuggestionsQuery( type, kind ) {\n\tswitch ( type ) {\n\t\tcase 'post':\n\t\tcase 'page':\n\t\t\treturn { type: 'post', subtype: type };\n\t\tcase 'category':\n\t\t\treturn { type: 'term', subtype: 'category' };\n\t\tcase 'tag':\n\t\t\treturn { type: 'term', subtype: 'post_tag' };\n\t\tcase 'post_format':\n\t\t\treturn { type: 'post-format' };\n\t\tdefault:\n\t\t\tif ( kind === 'taxonomy' ) {\n\t\t\t\treturn { type: 'term', subtype: type };\n\t\t\t}\n\t\t\tif ( kind === 'post-type' ) {\n\t\t\t\treturn { type: 'post', subtype: type };\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t// for custom link which has no type\n\t\t\t\t// always show pages as initial suggestions\n\t\t\t\tinitialSuggestionsSearchOptions: {\n\t\t\t\t\ttype: 'post',\n\t\t\t\t\tsubtype: 'page',\n\t\t\t\t\tperPage: 20,\n\t\t\t\t},\n\t\t\t};\n\t}\n}\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\tconst focusOnMountRef = useFocusOnMount( 'firstElement' );\n\n\tconst dialogTitleId = useInstanceId(\n\t\tLinkControl,\n\t\t`link-ui-block-inserter__title`\n\t);\n\tconst dialogDescriptionId = useInstanceId(\n\t\tLinkControl,\n\t\t`link-ui-block-inserter__description`\n\t);\n\n\tif ( ! clientId ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<div\n\t\t\tclassName=\"link-ui-block-inserter\"\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 }>{ __( 'Add block' ) }</h2>\n\n\t\t\t\t<p id={ dialogDescriptionId }>\n\t\t\t\t\t{ __( 'Choose a block to add to your Navigation.' ) }\n\t\t\t\t</p>\n\t\t\t</VisuallyHidden>\n\n\t\t\t<Button\n\t\t\t\tclassName=\"link-ui-block-inserter__back\"\n\t\t\t\ticon={ isRTL() ? chevronRightSmall : chevronLeftSmall }\n\t\t\t\tonClick={ ( e ) => {\n\t\t\t\t\te.preventDefault();\n\t\t\t\t\tonBack();\n\t\t\t\t} }\n\t\t\t\tsize=\"small\"\n\t\t\t>\n\t\t\t\t{ __( 'Back' ) }\n\t\t\t</Button>\n\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</div>\n\t);\n}\n\nfunction UnforwardedLinkUI( props, ref ) {\n\tconst { label, url, opensInNewTab, type, kind } = props.link;\n\tconst postType = type || 'page';\n\n\tconst [ addingBlock, setAddingBlock ] = useState( false );\n\tconst [ addingPage, setAddingPage ] = useState( false );\n\tconst [ focusAddBlockButton, setFocusAddBlockButton ] = useState( false );\n\tconst [ focusAddPageButton, setFocusAddPageButton ] = useState( false );\n\tconst permissions = useResourcePermissions( {\n\t\tkind: 'postType',\n\t\tname: postType,\n\t} );\n\n\t// Memoize link value to avoid overriding the LinkControl's internal state.\n\t// This is a temporary fix. See https://github.com/WordPress/gutenberg/issues/50976#issuecomment-1568226407.\n\tconst link = useMemo(\n\t\t() => ( {\n\t\t\turl,\n\t\t\topensInNewTab,\n\t\t\ttitle: label && stripHTML( label ),\n\t\t} ),\n\t\t[ label, opensInNewTab, url ]\n\t);\n\n\tconst handlePageCreated = ( pageLink ) => {\n\t\t// Set the new page as the current link\n\t\tprops.onChange( pageLink );\n\t\t// Return to main Link UI\n\t\tsetAddingPage( false );\n\t};\n\n\tconst dialogTitleId = useInstanceId(\n\t\tLinkUI,\n\t\t`link-ui-link-control__title`\n\t);\n\tconst dialogDescriptionId = useInstanceId(\n\t\tLinkUI,\n\t\t`link-ui-link-control__description`\n\t);\n\n\tconst blockEditingMode = useBlockEditingMode();\n\n\treturn (\n\t\t<Popover\n\t\t\tref={ ref }\n\t\t\tplacement=\"bottom\"\n\t\t\tonClose={ props.onClose }\n\t\t\tanchor={ props.anchor }\n\t\t\tshift\n\t\t>\n\t\t\t{ ! addingBlock && ! addingPage && (\n\t\t\t\t<div\n\t\t\t\t\trole=\"dialog\"\n\t\t\t\t\taria-labelledby={ dialogTitleId }\n\t\t\t\t\taria-describedby={ dialogDescriptionId }\n\t\t\t\t>\n\t\t\t\t\t<VisuallyHidden>\n\t\t\t\t\t\t<h2 id={ dialogTitleId }>{ __( 'Add link' ) }</h2>\n\n\t\t\t\t\t\t<p id={ dialogDescriptionId }>\n\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t'Search for and add a link to your Navigation.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</p>\n\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t\t<LinkControl\n\t\t\t\t\t\thasTextControl\n\t\t\t\t\t\thasRichPreviews\n\t\t\t\t\t\tvalue={ link }\n\t\t\t\t\t\tshowInitialSuggestions\n\t\t\t\t\t\twithCreateSuggestion={ false }\n\t\t\t\t\t\tnoDirectEntry={ !! type }\n\t\t\t\t\t\tnoURLSuggestion={ !! type }\n\t\t\t\t\t\tsuggestionsQuery={ getSuggestionsQuery( type, kind ) }\n\t\t\t\t\t\tonChange={ props.onChange }\n\t\t\t\t\t\tonRemove={ props.onRemove }\n\t\t\t\t\t\tonCancel={ props.onCancel }\n\t\t\t\t\t\trenderControlBottom={ () =>\n\t\t\t\t\t\t\t! link?.url?.length && (\n\t\t\t\t\t\t\t\t<LinkUITools\n\t\t\t\t\t\t\t\t\tfocusAddBlockButton={ focusAddBlockButton }\n\t\t\t\t\t\t\t\t\tfocusAddPageButton={ focusAddPageButton }\n\t\t\t\t\t\t\t\t\tsetAddingBlock={ () => {\n\t\t\t\t\t\t\t\t\t\tsetAddingBlock( true );\n\t\t\t\t\t\t\t\t\t\tsetFocusAddBlockButton( false );\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\tsetAddingPage={ () => {\n\t\t\t\t\t\t\t\t\t\tsetAddingPage( true );\n\t\t\t\t\t\t\t\t\t\tsetFocusAddPageButton( false );\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\tcanCreatePage={ permissions.canCreate }\n\t\t\t\t\t\t\t\t\tblockEditingMode={ blockEditingMode }\n\t\t\t\t\t\t\t\t/>\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</div>\n\t\t\t) }\n\n\t\t\t{ addingBlock && (\n\t\t\t\t<LinkUIBlockInserter\n\t\t\t\t\tclientId={ props.clientId }\n\t\t\t\t\tonBack={ () => {\n\t\t\t\t\t\tsetAddingBlock( false );\n\t\t\t\t\t\tsetFocusAddBlockButton( true );\n\t\t\t\t\t\tsetFocusAddPageButton( false );\n\t\t\t\t\t} }\n\t\t\t\t\tonBlockInsert={ props?.onBlockInsert }\n\t\t\t\t/>\n\t\t\t) }\n\n\t\t\t{ addingPage && (\n\t\t\t\t<LinkUIPageCreator\n\t\t\t\t\tpostType={ postType }\n\t\t\t\t\tonBack={ () => {\n\t\t\t\t\t\tsetAddingPage( false );\n\t\t\t\t\t\tsetFocusAddPageButton( true );\n\t\t\t\t\t\tsetFocusAddBlockButton( false );\n\t\t\t\t\t} }\n\t\t\t\t\tonPageCreated={ handlePageCreated }\n\t\t\t\t\tinitialTitle={ link?.url || '' }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</Popover>\n\t);\n}\n\nexport const LinkUI = forwardRef( UnforwardedLinkUI );\n\nconst LinkUITools = ( {\n\tsetAddingBlock,\n\tsetAddingPage,\n\tfocusAddBlockButton,\n\tfocusAddPageButton,\n\tcanCreatePage,\n\tblockEditingMode,\n} ) => {\n\tconst blockInserterAriaRole = 'listbox';\n\tconst addBlockButtonRef = useRef();\n\tconst addPageButtonRef = useRef();\n\n\t// Focus the add block button when the popover is opened.\n\tuseEffect( () => {\n\t\tif ( focusAddBlockButton ) {\n\t\t\taddBlockButtonRef.current?.focus();\n\t\t}\n\t}, [ focusAddBlockButton ] );\n\n\t// Focus the add page button when the popover is opened.\n\tuseEffect( () => {\n\t\tif ( focusAddPageButton ) {\n\t\t\taddPageButtonRef.current?.focus();\n\t\t}\n\t}, [ focusAddPageButton ] );\n\n\treturn (\n\t\t<VStack spacing={ 0 } className=\"link-ui-tools\">\n\t\t\t{ canCreatePage && (\n\t\t\t\t<Button\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tref={ addPageButtonRef }\n\t\t\t\t\ticon={ plus }\n\t\t\t\t\tonClick={ ( e ) => {\n\t\t\t\t\t\te.preventDefault();\n\t\t\t\t\t\tsetAddingPage( true );\n\t\t\t\t\t} }\n\t\t\t\t\taria-haspopup={ blockInserterAriaRole }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Create page' ) }\n\t\t\t\t</Button>\n\t\t\t) }\n\t\t\t{ blockEditingMode === 'default' && (\n\t\t\t\t<Button\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tref={ addBlockButtonRef }\n\t\t\t\t\ticon={ plus }\n\t\t\t\t\tonClick={ ( e ) => {\n\t\t\t\t\t\te.preventDefault();\n\t\t\t\t\t\tsetAddingBlock( true );\n\t\t\t\t\t} }\n\t\t\t\t\taria-haspopup={ blockInserterAriaRole }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Add block' ) }\n\t\t\t\t</Button>\n\t\t\t) }\n\t\t</VStack>\n\t);\n};\n\nexport default LinkUITools;\n"],"mappings":";;;;;;;AAGA,IAAAA,IAAA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C;EACD,CAAC,EAAE,CAAE7C,kBAAkB,CAAG,CAAC;EAE3B,oBACC,IAAAjE,WAAA,CAAA0B,IAAA,EAACpC,WAAA,CAAAyH,oBAAM;IAACC,OAAO,EAAG,CAAG;IAACrF,SAAS,EAAC,eAAe;IAAAG,QAAA,GAC5CmE,aAAa,iBACd,IAAAjG,WAAA,CAAAgC,GAAA,EAAC1C,WAAA,CAAA6C,MAAM;MACN8E,qBAAqB;MACrBpF,GAAG,EAAG8E,gBAAkB;MACxBvE,IAAI,EAAG8E,WAAM;MACb1E,OAAO,EAAKC,CAAC,IAAM;QAClBA,CAAC,CAACC,cAAc,CAAC,CAAC;QAClBoB,aAAa,CAAE,IAAK,CAAC;MACtB,CAAG;MACH,iBAAgB0C,qBAAuB;MAAA1E,QAAA,EAErC,IAAAI,QAAE,EAAE,aAAc;IAAC,CACd,CACR,EACC2C,gBAAgB,KAAK,SAAS,iBAC/B,IAAA7E,WAAA,CAAAgC,GAAA,EAAC1C,WAAA,CAAA6C,MAAM;MACN8E,qBAAqB;MACrBpF,GAAG,EAAG4E,iBAAmB;MACzBrE,IAAI,EAAG8E,WAAM;MACb1E,OAAO,EAAKC,CAAC,IAAM;QAClBA,CAAC,CAACC,cAAc,CAAC,CAAC;QAClBiB,cAAc,CAAE,IAAK,CAAC;MACvB,CAAG;MACH,iBAAgB6C,qBAAuB;MAAA1E,QAAA,EAErC,IAAAI,QAAE,EAAE,WAAY;IAAC,CACZ,CACR;EAAA,CACM,CAAC;AAEX,CAAC;AAAC,IAAAiF,QAAA,GAAAb,OAAA,CAAAc,OAAA,GAEapB,WAAW","ignoreList":[]}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.LinkUIPageCreator = LinkUIPageCreator;
|
|
7
|
+
var _components = require("@wordpress/components");
|
|
8
|
+
var _i18n = require("@wordpress/i18n");
|
|
9
|
+
var _data = require("@wordpress/data");
|
|
10
|
+
var _coreData = require("@wordpress/core-data");
|
|
11
|
+
var _htmlEntities = require("@wordpress/html-entities");
|
|
12
|
+
var _element = require("@wordpress/element");
|
|
13
|
+
var _icons = require("@wordpress/icons");
|
|
14
|
+
var _compose = require("@wordpress/compose");
|
|
15
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
16
|
+
/**
|
|
17
|
+
* WordPress dependencies
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Component for creating new pages within the Navigation Link UI.
|
|
22
|
+
*
|
|
23
|
+
* @param {Object} props Component props.
|
|
24
|
+
* @param {string} props.postType The post type to create.
|
|
25
|
+
* @param {Function} props.onBack Callback when user wants to go back.
|
|
26
|
+
* @param {Function} props.onPageCreated Callback when page is successfully created.
|
|
27
|
+
* @param {string} [props.initialTitle] Initial title to pre-fill the form.
|
|
28
|
+
*/
|
|
29
|
+
function LinkUIPageCreator({
|
|
30
|
+
postType,
|
|
31
|
+
onBack,
|
|
32
|
+
onPageCreated,
|
|
33
|
+
initialTitle = ''
|
|
34
|
+
}) {
|
|
35
|
+
const [title, setTitle] = (0, _element.useState)(initialTitle);
|
|
36
|
+
const [shouldPublish, setShouldPublish] = (0, _element.useState)(false);
|
|
37
|
+
|
|
38
|
+
// Focus the first element when the component mounts
|
|
39
|
+
const focusOnMountRef = (0, _compose.useFocusOnMount)('firstElement');
|
|
40
|
+
|
|
41
|
+
// Check if the title is valid for submission
|
|
42
|
+
const isTitleValid = title.trim().length > 0;
|
|
43
|
+
|
|
44
|
+
// Get the last created entity record (without ID) to track creation state
|
|
45
|
+
const {
|
|
46
|
+
lastError,
|
|
47
|
+
isSaving
|
|
48
|
+
} = (0, _data.useSelect)(select => ({
|
|
49
|
+
lastError: select(_coreData.store).getLastEntitySaveError('postType', postType),
|
|
50
|
+
isSaving: select(_coreData.store).isSavingEntityRecord('postType', postType)
|
|
51
|
+
}), [postType]);
|
|
52
|
+
const {
|
|
53
|
+
saveEntityRecord
|
|
54
|
+
} = (0, _data.useDispatch)(_coreData.store);
|
|
55
|
+
async function createPage(event) {
|
|
56
|
+
event.preventDefault();
|
|
57
|
+
if (isSaving || !isTitleValid) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
const savedRecord = await saveEntityRecord('postType', postType, {
|
|
62
|
+
title,
|
|
63
|
+
status: shouldPublish ? 'publish' : 'draft'
|
|
64
|
+
}, {
|
|
65
|
+
throwOnError: true
|
|
66
|
+
});
|
|
67
|
+
if (savedRecord) {
|
|
68
|
+
// Create the page link object from the saved record
|
|
69
|
+
const pageLink = {
|
|
70
|
+
id: savedRecord.id,
|
|
71
|
+
type: postType,
|
|
72
|
+
title: (0, _htmlEntities.decodeEntities)(savedRecord.title.rendered),
|
|
73
|
+
url: savedRecord.link,
|
|
74
|
+
kind: 'post-type'
|
|
75
|
+
};
|
|
76
|
+
onPageCreated(pageLink);
|
|
77
|
+
}
|
|
78
|
+
} catch (error) {
|
|
79
|
+
// Error handling is done via the data store selectors
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const isSubmitDisabled = isSaving || !isTitleValid;
|
|
83
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
84
|
+
className: "link-ui-page-creator",
|
|
85
|
+
ref: focusOnMountRef,
|
|
86
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
87
|
+
className: "link-ui-page-creator__back",
|
|
88
|
+
icon: (0, _i18n.isRTL)() ? _icons.chevronRightSmall : _icons.chevronLeftSmall,
|
|
89
|
+
onClick: e => {
|
|
90
|
+
e.preventDefault();
|
|
91
|
+
onBack();
|
|
92
|
+
},
|
|
93
|
+
size: "small",
|
|
94
|
+
children: (0, _i18n.__)('Back')
|
|
95
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalVStack, {
|
|
96
|
+
className: "link-ui-page-creator__inner",
|
|
97
|
+
spacing: 4,
|
|
98
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("form", {
|
|
99
|
+
onSubmit: createPage,
|
|
100
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalVStack, {
|
|
101
|
+
spacing: 4,
|
|
102
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.TextControl, {
|
|
103
|
+
__next40pxDefaultSize: true,
|
|
104
|
+
__nextHasNoMarginBottom: true,
|
|
105
|
+
label: (0, _i18n.__)('Title'),
|
|
106
|
+
onChange: setTitle,
|
|
107
|
+
placeholder: (0, _i18n.__)('No title'),
|
|
108
|
+
value: title
|
|
109
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.CheckboxControl, {
|
|
110
|
+
__nextHasNoMarginBottom: true,
|
|
111
|
+
label: (0, _i18n.__)('Publish immediately'),
|
|
112
|
+
help: (0, _i18n.__)('If unchecked, the page will be created as a draft.'),
|
|
113
|
+
checked: shouldPublish,
|
|
114
|
+
onChange: setShouldPublish
|
|
115
|
+
}), lastError && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Notice, {
|
|
116
|
+
status: "error",
|
|
117
|
+
isDismissible: false,
|
|
118
|
+
children: lastError.message
|
|
119
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
|
|
120
|
+
spacing: 2,
|
|
121
|
+
justify: "flex-end",
|
|
122
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
123
|
+
__next40pxDefaultSize: true,
|
|
124
|
+
variant: "tertiary",
|
|
125
|
+
onClick: onBack,
|
|
126
|
+
disabled: isSaving,
|
|
127
|
+
accessibleWhenDisabled: true,
|
|
128
|
+
children: (0, _i18n.__)('Cancel')
|
|
129
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
130
|
+
__next40pxDefaultSize: true,
|
|
131
|
+
variant: "primary",
|
|
132
|
+
type: "submit",
|
|
133
|
+
isBusy: isSaving,
|
|
134
|
+
"aria-disabled": isSubmitDisabled,
|
|
135
|
+
children: (0, _i18n.__)('Create page')
|
|
136
|
+
})]
|
|
137
|
+
})]
|
|
138
|
+
})
|
|
139
|
+
})
|
|
140
|
+
})]
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=page-creator.js.map
|