@wordpress/block-library 9.33.1-next.b8c8708f3.0 → 9.33.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +1 -1
- package/build/breadcrumbs/block.json +8 -2
- package/build/breadcrumbs/edit.js +113 -12
- package/build/breadcrumbs/edit.js.map +2 -2
- package/build/buttons/transforms.js +7 -7
- package/build/buttons/transforms.js.map +2 -2
- package/build/code/transforms.js +19 -15
- package/build/code/transforms.js.map +2 -2
- package/build/heading/index.js +1 -3
- package/build/heading/index.js.map +3 -3
- package/build/heading/transforms.js +22 -20
- package/build/heading/transforms.js.map +2 -2
- package/build/index.js +5 -1
- package/build/index.js.map +2 -2
- package/build/math/block.json +21 -0
- package/build/math/edit.js +132 -0
- package/build/math/edit.js.map +7 -0
- package/build/math/index.js +63 -0
- package/build/math/index.js.map +7 -0
- package/build/math/init.js +35 -0
- package/build/math/init.js.map +7 -0
- package/build/math/save.js +40 -0
- package/build/math/save.js.map +7 -0
- package/build/navigation/edit/menu-inspector-controls.js +3 -3
- package/build/navigation/edit/menu-inspector-controls.js.map +2 -2
- package/build/navigation-link/edit.js +6 -3
- package/build/navigation-link/edit.js.map +2 -2
- package/build/navigation-link/link-ui/index.js +1 -1
- package/build/navigation-link/link-ui/index.js.map +2 -2
- package/build/navigation-link/shared/controls.js +4 -1
- package/build/navigation-link/shared/controls.js.map +3 -3
- package/build/navigation-link/shared/index.js +2 -0
- package/build/navigation-link/shared/index.js.map +2 -2
- package/build/navigation-link/shared/update-attributes.js +3 -1
- package/build/navigation-link/shared/update-attributes.js.map +2 -2
- package/build/navigation-link/shared/use-entity-binding.js +46 -13
- package/build/navigation-link/shared/use-entity-binding.js.map +2 -2
- package/build/navigation-submenu/edit.js +6 -3
- package/build/navigation-submenu/edit.js.map +2 -2
- package/build/page-list/use-convert-to-navigation-links.js +6 -1
- package/build/page-list/use-convert-to-navigation-links.js.map +2 -2
- package/build/paragraph/index.js +1 -3
- package/build/paragraph/index.js.map +3 -3
- package/build/post-date/deprecated.js +98 -2
- package/build/post-date/deprecated.js.map +2 -2
- package/build/post-date/edit.js +1 -1
- package/build/post-date/edit.js.map +1 -1
- package/build/post-date/variations.js +4 -4
- package/build/post-date/variations.js.map +2 -2
- package/build/term-template/edit.js +4 -1
- package/build/term-template/edit.js.map +2 -2
- package/build/utils/get-transformed-attributes.js +82 -0
- package/build/utils/get-transformed-attributes.js.map +7 -0
- package/build-module/breadcrumbs/block.json +8 -2
- package/build-module/breadcrumbs/edit.js +117 -14
- package/build-module/breadcrumbs/edit.js.map +2 -2
- package/build-module/buttons/transforms.js +7 -7
- package/build-module/buttons/transforms.js.map +2 -2
- package/build-module/code/transforms.js +19 -15
- package/build-module/code/transforms.js.map +2 -2
- package/build-module/heading/index.js +1 -3
- package/build-module/heading/index.js.map +2 -2
- package/build-module/heading/transforms.js +22 -20
- package/build-module/heading/transforms.js.map +2 -2
- package/build-module/index.js +5 -1
- package/build-module/index.js.map +2 -2
- package/build-module/math/block.json +21 -0
- package/build-module/math/edit.js +110 -0
- package/build-module/math/edit.js.map +7 -0
- package/build-module/math/index.js +26 -0
- package/build-module/math/index.js.map +7 -0
- package/build-module/math/init.js +8 -0
- package/build-module/math/init.js.map +7 -0
- package/build-module/math/save.js +20 -0
- package/build-module/math/save.js.map +7 -0
- package/build-module/navigation/edit/menu-inspector-controls.js +3 -3
- package/build-module/navigation/edit/menu-inspector-controls.js.map +2 -2
- package/build-module/navigation-link/edit.js +6 -3
- package/build-module/navigation-link/edit.js.map +2 -2
- package/build-module/navigation-link/link-ui/index.js +1 -1
- package/build-module/navigation-link/link-ui/index.js.map +2 -2
- package/build-module/navigation-link/shared/controls.js +4 -1
- package/build-module/navigation-link/shared/controls.js.map +2 -2
- package/build-module/navigation-link/shared/index.js +5 -1
- package/build-module/navigation-link/shared/index.js.map +2 -2
- package/build-module/navigation-link/shared/update-attributes.js +3 -1
- package/build-module/navigation-link/shared/update-attributes.js.map +2 -2
- package/build-module/navigation-link/shared/use-entity-binding.js +45 -13
- package/build-module/navigation-link/shared/use-entity-binding.js.map +2 -2
- package/build-module/navigation-submenu/edit.js +6 -3
- package/build-module/navigation-submenu/edit.js.map +2 -2
- package/build-module/page-list/use-convert-to-navigation-links.js +6 -1
- package/build-module/page-list/use-convert-to-navigation-links.js.map +2 -2
- package/build-module/paragraph/index.js +1 -3
- package/build-module/paragraph/index.js.map +2 -2
- package/build-module/post-date/deprecated.js +98 -2
- package/build-module/post-date/deprecated.js.map +2 -2
- package/build-module/post-date/edit.js +1 -1
- package/build-module/post-date/edit.js.map +1 -1
- package/build-module/post-date/variations.js +4 -4
- package/build-module/post-date/variations.js.map +2 -2
- package/build-module/term-template/edit.js +4 -1
- package/build-module/term-template/edit.js.map +2 -2
- package/build-module/utils/get-transformed-attributes.js +58 -0
- package/build-module/utils/get-transformed-attributes.js.map +7 -0
- package/package.json +61 -36
- package/src/breadcrumbs/block.json +8 -2
- package/src/breadcrumbs/edit.js +163 -18
- package/src/breadcrumbs/index.php +118 -16
- package/src/buttons/transforms.js +6 -6
- package/src/code/transforms.js +16 -14
- package/src/heading/index.js +0 -2
- package/src/heading/transforms.js +25 -24
- package/src/index.js +6 -1
- package/src/math/block.json +21 -0
- package/src/math/edit.js +123 -0
- package/src/math/index.js +31 -0
- package/src/math/init.js +4 -0
- package/src/math/save.js +20 -0
- package/src/navigation/edit/menu-inspector-controls.js +8 -7
- package/src/navigation-link/edit.js +6 -3
- package/src/navigation-link/index.php +4 -18
- package/src/navigation-link/link-ui/index.js +4 -2
- package/src/navigation-link/shared/controls.js +12 -3
- package/src/navigation-link/shared/index.js +4 -1
- package/src/navigation-link/shared/test/update-attributes.test.js +8 -0
- package/src/navigation-link/shared/test/use-entity-binding.js +132 -17
- package/src/navigation-link/shared/update-attributes.js +1 -0
- package/src/navigation-link/shared/use-entity-binding.js +74 -19
- package/src/navigation-submenu/edit.js +6 -3
- package/src/navigation-submenu/index.php +3 -17
- package/src/page-list/test/{convert-to-links-modal.js → convert-to-navigation-links.js} +67 -0
- package/src/page-list/use-convert-to-navigation-links.js +11 -1
- package/src/paragraph/index.js +0 -2
- package/src/post-date/deprecated.js +100 -2
- package/src/post-date/edit.js +1 -1
- package/src/post-date/index.php +3 -3
- package/src/post-date/variations.js +5 -4
- package/src/term-template/edit.js +4 -1
- package/src/term-template/index.php +4 -6
- package/src/utils/get-transformed-attributes.js +98 -0
- package/tsconfig.json +1 -0
- package/build/heading/variations.js +0 -48
- package/build/heading/variations.js.map +0 -7
- package/build/paragraph/variations.js +0 -48
- package/build/paragraph/variations.js.map +0 -7
- package/build/utils/get-transformed-metadata.js +0 -59
- package/build/utils/get-transformed-metadata.js.map +0 -7
- package/build-module/heading/variations.js +0 -28
- package/build-module/heading/variations.js.map +0 -7
- package/build-module/paragraph/variations.js +0 -28
- package/build-module/paragraph/variations.js.map +0 -7
- package/build-module/utils/get-transformed-metadata.js +0 -35
- package/build-module/utils/get-transformed-metadata.js.map +0 -7
- package/src/heading/variations.js +0 -29
- package/src/paragraph/variations.js +0 -29
- package/src/utils/get-transformed-metadata.js +0 -60
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/navigation-link/edit.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { createBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { ToolbarButton, ToolbarGroup } from '@wordpress/components';\nimport { displayShortcut, isKeyboardEvent } from '@wordpress/keycodes';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tBlockControls,\n\tInspectorControls,\n\tRichText,\n\tuseBlockProps,\n\tstore as blockEditorStore,\n\tgetColorClassName,\n\tuseInnerBlocksProps,\n\tuseBlockEditingMode,\n} from '@wordpress/block-editor';\nimport { isURL, prependHTTP } from '@wordpress/url';\nimport { useState, useEffect, useRef, useCallback } from '@wordpress/element';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { link as linkIcon, addSubmenu } from '@wordpress/icons';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useMergeRefs, usePrevious } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { getColors } from '../navigation/edit/utils';\nimport { Controls, LinkUI, updateAttributes, useEntityBinding } from './shared';\n\nconst DEFAULT_BLOCK = { name: 'core/navigation-link' };\nconst NESTING_BLOCK_NAMES = [\n\t'core/navigation-link',\n\t'core/navigation-submenu',\n];\n\n/**\n * A React hook to determine if it's dragging within the target element.\n *\n * @typedef {import('@wordpress/element').RefObject} RefObject\n *\n * @param {RefObject<HTMLElement>} elementRef The target elementRef object.\n *\n * @return {boolean} Is dragging within the target element.\n */\nconst useIsDraggingWithin = ( elementRef ) => {\n\tconst [ isDraggingWithin, setIsDraggingWithin ] = useState( false );\n\n\tuseEffect( () => {\n\t\tconst { ownerDocument } = elementRef.current;\n\n\t\tfunction handleDragStart( event ) {\n\t\t\t// Check the first time when the dragging starts.\n\t\t\thandleDragEnter( event );\n\t\t}\n\n\t\t// Set to false whenever the user cancel the drag event by either releasing the mouse or press Escape.\n\t\tfunction handleDragEnd() {\n\t\t\tsetIsDraggingWithin( false );\n\t\t}\n\n\t\tfunction handleDragEnter( event ) {\n\t\t\t// Check if the current target is inside the item element.\n\t\t\tif ( elementRef.current.contains( event.target ) ) {\n\t\t\t\tsetIsDraggingWithin( true );\n\t\t\t} else {\n\t\t\t\tsetIsDraggingWithin( false );\n\t\t\t}\n\t\t}\n\n\t\t// Bind these events to the document to catch all drag events.\n\t\t// Ideally, we can also use `event.relatedTarget`, but sadly that\n\t\t// doesn't work in Safari.\n\t\townerDocument.addEventListener( 'dragstart', handleDragStart );\n\t\townerDocument.addEventListener( 'dragend', handleDragEnd );\n\t\townerDocument.addEventListener( 'dragenter', handleDragEnter );\n\n\t\treturn () => {\n\t\t\townerDocument.removeEventListener( 'dragstart', handleDragStart );\n\t\t\townerDocument.removeEventListener( 'dragend', handleDragEnd );\n\t\t\townerDocument.removeEventListener( 'dragenter', handleDragEnter );\n\t\t};\n\t}, [ elementRef ] );\n\n\treturn isDraggingWithin;\n};\n\nconst useIsInvalidLink = ( kind, type, id, enabled ) => {\n\tconst isPostType =\n\t\tkind === 'post-type' || type === 'post' || type === 'page';\n\tconst hasId = Number.isInteger( id );\n\tconst blockEditingMode = useBlockEditingMode();\n\n\tconst postStatus = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! isPostType ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\t// Fetching the posts status is an \"expensive\" operation. Especially for sites with large navigations.\n\t\t\t// When the block is rendered in a template or other disabled contexts we can skip this check in order\n\t\t\t// to avoid all these additional requests that don't really add any value in that mode.\n\t\t\tif ( blockEditingMode === 'disabled' || ! enabled ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst { getEntityRecord } = select( coreStore );\n\t\t\treturn getEntityRecord( 'postType', type, id )?.status;\n\t\t},\n\t\t[ isPostType, blockEditingMode, enabled, type, id ]\n\t);\n\n\t// Check Navigation Link validity if:\n\t// 1. Link is 'post-type'.\n\t// 2. It has an id.\n\t// 3. It's neither null, nor undefined, as valid items might be either of those while loading.\n\t// If those conditions are met, check if\n\t// 1. The post status is published.\n\t// 2. The Navigation Link item has no label.\n\t// If either of those is true, invalidate.\n\tconst isInvalid =\n\t\tisPostType && hasId && postStatus && 'trash' === postStatus;\n\tconst isDraft = 'draft' === postStatus;\n\n\treturn [ isInvalid, isDraft ];\n};\n\nfunction getMissingText( type ) {\n\tlet missingText = '';\n\n\tswitch ( type ) {\n\t\tcase 'post':\n\t\t\t/* translators: label for missing post in navigation link block */\n\t\t\tmissingText = __( 'Select post' );\n\t\t\tbreak;\n\t\tcase 'page':\n\t\t\t/* translators: label for missing page in navigation link block */\n\t\t\tmissingText = __( 'Select page' );\n\t\t\tbreak;\n\t\tcase 'category':\n\t\t\t/* translators: label for missing category in navigation link block */\n\t\t\tmissingText = __( 'Select category' );\n\t\t\tbreak;\n\t\tcase 'tag':\n\t\t\t/* translators: label for missing tag in navigation link block */\n\t\t\tmissingText = __( 'Select tag' );\n\t\t\tbreak;\n\t\tdefault:\n\t\t\t/* translators: label for missing values in navigation link block */\n\t\t\tmissingText = __( 'Add link' );\n\t}\n\n\treturn missingText;\n}\n\nexport default function NavigationLinkEdit( {\n\tattributes,\n\tisSelected,\n\tsetAttributes,\n\tinsertBlocksAfter,\n\tmergeBlocks,\n\tonReplace,\n\tcontext,\n\tclientId,\n} ) {\n\tconst { id, label, type, url, description, kind, metadata } = attributes;\n\tconst { maxNestingLevel } = context;\n\n\tconst {\n\t\treplaceBlock,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t\tselectBlock,\n\t} = useDispatch( blockEditorStore );\n\t// Have the link editing ui open on mount when lacking a url and selected.\n\tconst [ isLinkOpen, setIsLinkOpen ] = useState( isSelected && ! url );\n\t// Use internal state instead of a ref to make sure that the component\n\t// re-renders when the popover's anchor updates.\n\tconst [ popoverAnchor, setPopoverAnchor ] = useState( null );\n\tconst listItemRef = useRef( null );\n\tconst isDraggingWithin = useIsDraggingWithin( listItemRef );\n\tconst itemLabelPlaceholder = __( 'Add label\u2026' );\n\tconst ref = useRef();\n\tconst linkUIref = useRef();\n\tconst prevUrl = usePrevious( url );\n\tconst isNewLink = useRef( ! url );\n\n\tconst {\n\t\tisAtMaxNesting,\n\t\tisTopLevelLink,\n\t\tisParentOfSelectedBlock,\n\t\thasChildren,\n\t\tvalidateLinkStatus,\n\t\tparentBlockClientId,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockCount,\n\t\t\t\tgetBlockName,\n\t\t\t\tgetBlockRootClientId,\n\t\t\t\thasSelectedInnerBlock,\n\t\t\t\tgetBlockParentsByBlockName,\n\t\t\t\tgetSelectedBlockClientId,\n\t\t\t} = select( blockEditorStore );\n\t\t\tconst rootClientId = getBlockRootClientId( clientId );\n\t\t\tconst parentBlockName = getBlockName( rootClientId );\n\t\t\tconst isTopLevel = parentBlockName === 'core/navigation';\n\t\t\tconst selectedBlockClientId = getSelectedBlockClientId();\n\t\t\tconst rootNavigationClientId = isTopLevel\n\t\t\t\t? rootClientId\n\t\t\t\t: getBlockParentsByBlockName(\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t'core/navigation'\n\t\t\t\t )[ 0 ];\n\n\t\t\t// Get the immediate parent - if it's a submenu, use it; otherwise use the navigation block\n\t\t\tconst parentBlockId =\n\t\t\t\tparentBlockName === 'core/navigation-submenu'\n\t\t\t\t\t? rootClientId\n\t\t\t\t\t: rootNavigationClientId;\n\n\t\t\t// Enable when the root Navigation block is selected or any of its inner blocks.\n\t\t\tconst enableLinkStatusValidation =\n\t\t\t\tselectedBlockClientId === rootNavigationClientId ||\n\t\t\t\thasSelectedInnerBlock( rootNavigationClientId, true );\n\n\t\t\treturn {\n\t\t\t\tisAtMaxNesting:\n\t\t\t\t\tgetBlockParentsByBlockName( clientId, NESTING_BLOCK_NAMES )\n\t\t\t\t\t\t.length >= maxNestingLevel,\n\t\t\t\tisTopLevelLink: isTopLevel,\n\t\t\t\tisParentOfSelectedBlock: hasSelectedInnerBlock(\n\t\t\t\t\tclientId,\n\t\t\t\t\ttrue\n\t\t\t\t),\n\t\t\t\thasChildren: !! getBlockCount( clientId ),\n\t\t\t\tvalidateLinkStatus: enableLinkStatusValidation,\n\t\t\t\tparentBlockClientId: parentBlockId,\n\t\t\t};\n\t\t},\n\t\t[ clientId, maxNestingLevel ]\n\t);\n\tconst { getBlocks } = useSelect( blockEditorStore );\n\n\t// URL binding logic\n\tconst { clearBinding, createBinding } = useEntityBinding( {\n\t\tclientId,\n\t\tattributes,\n\t} );\n\n\tconst [ isInvalid, isDraft ] = useIsInvalidLink(\n\t\tkind,\n\t\ttype,\n\t\tid,\n\t\tvalidateLinkStatus\n\t);\n\n\t/**\n\t * Transform to submenu block.\n\t */\n\tconst transformToSubmenu = useCallback( () => {\n\t\tlet innerBlocks = getBlocks( clientId );\n\t\tif ( innerBlocks.length === 0 ) {\n\t\t\tinnerBlocks = [ createBlock( 'core/navigation-link' ) ];\n\t\t\tselectBlock( innerBlocks[ 0 ].clientId );\n\t\t}\n\t\tconst newSubmenu = createBlock(\n\t\t\t'core/navigation-submenu',\n\t\t\tattributes,\n\t\t\tinnerBlocks\n\t\t);\n\t\treplaceBlock( clientId, newSubmenu );\n\t}, [ getBlocks, clientId, selectBlock, replaceBlock, attributes ] );\n\n\t// On mount, if this is a new link without a URL and it's selected,\n\t// select the parent block (submenu or navigation) instead to keep the appender visible.\n\t// This helps us return focus to the appender if the user closes the link ui without creating a link.\n\t// If we leave focus on this block, then when we close the link without creating a link, focus will\n\t// be lost during the new block selection process.\n\tuseEffect( () => {\n\t\tif ( isNewLink.current && isSelected && ! url ) {\n\t\t\tselectBlock( parentBlockClientId );\n\t\t}\n\t}, [] ); // eslint-disable-line react-hooks/exhaustive-deps\n\n\tuseEffect( () => {\n\t\t// If block has inner blocks, transform to Submenu.\n\t\tif ( hasChildren ) {\n\t\t\t// This side-effect should not create an undo level as those should\n\t\t\t// only be created via user interactions.\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\ttransformToSubmenu();\n\t\t}\n\t}, [\n\t\thasChildren,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t\ttransformToSubmenu,\n\t] );\n\n\t// If the LinkControl popover is open and the URL has changed, close the LinkControl and focus the label text.\n\tuseEffect( () => {\n\t\t// We only want to do this when the URL has gone from nothing to a new URL AND the label looks like a URL\n\t\tif (\n\t\t\t! prevUrl &&\n\t\t\turl &&\n\t\t\tisLinkOpen &&\n\t\t\tisURL( prependHTTP( label ) ) &&\n\t\t\t/^.+\\.[a-z]+/.test( label )\n\t\t) {\n\t\t\t// Focus and select the label text.\n\t\t\tselectLabelText();\n\t\t}\n\t}, [ prevUrl, url, isLinkOpen, label ] );\n\n\t/**\n\t * Focus the Link label text and select it.\n\t */\n\tfunction selectLabelText() {\n\t\tref.current.focus();\n\t\tconst { ownerDocument } = ref.current;\n\t\tconst { defaultView } = ownerDocument;\n\t\tconst selection = defaultView.getSelection();\n\t\tconst range = ownerDocument.createRange();\n\t\t// Get the range of the current ref contents so we can add this range to the selection.\n\t\trange.selectNodeContents( ref.current );\n\t\tselection.removeAllRanges();\n\t\tselection.addRange( range );\n\t}\n\n\t/**\n\t * Removes the current link if set.\n\t */\n\tfunction removeLink() {\n\t\t// Reset all attributes that comprise the link.\n\t\t// It is critical that all attributes are reset\n\t\t// to their default values otherwise this may\n\t\t// in advertently trigger side effects because\n\t\t// the values will have \"changed\".\n\t\tsetAttributes( {\n\t\t\turl: undefined,\n\t\t\tlabel: undefined,\n\t\t\tid: undefined,\n\t\t\tkind: undefined,\n\t\t\ttype: undefined,\n\t\t\topensInNewTab: false,\n\t\t} );\n\n\t\t// Close the link editing UI.\n\t\tsetIsLinkOpen( false );\n\t}\n\n\tconst {\n\t\ttextColor,\n\t\tcustomTextColor,\n\t\tbackgroundColor,\n\t\tcustomBackgroundColor,\n\t} = getColors( context, ! isTopLevelLink );\n\n\tfunction onKeyDown( event ) {\n\t\tif ( isKeyboardEvent.primary( event, 'k' ) ) {\n\t\t\t// Required to prevent the command center from opening,\n\t\t\t// as it shares the CMD+K shortcut.\n\t\t\t// See https://github.com/WordPress/gutenberg/pull/59845.\n\t\t\tevent.preventDefault();\n\t\t\t// If this link is a child of a parent submenu item, the parent submenu item event will also open, closing this popover\n\t\t\tevent.stopPropagation();\n\t\t\tsetIsLinkOpen( true );\n\t\t}\n\t}\n\n\tconst blockProps = useBlockProps( {\n\t\tref: useMergeRefs( [ setPopoverAnchor, listItemRef ] ),\n\t\tclassName: clsx( 'wp-block-navigation-item', {\n\t\t\t'is-editing': isSelected || isParentOfSelectedBlock,\n\t\t\t'is-dragging-within': isDraggingWithin,\n\t\t\t'has-link': !! url,\n\t\t\t'has-child': hasChildren,\n\t\t\t'has-text-color': !! textColor || !! customTextColor,\n\t\t\t[ getColorClassName( 'color', textColor ) ]: !! textColor,\n\t\t\t'has-background': !! backgroundColor || customBackgroundColor,\n\t\t\t[ getColorClassName( 'background-color', backgroundColor ) ]:\n\t\t\t\t!! backgroundColor,\n\t\t} ),\n\t\tstyle: {\n\t\t\tcolor: ! textColor && customTextColor,\n\t\t\tbackgroundColor: ! backgroundColor && customBackgroundColor,\n\t\t},\n\t\tonKeyDown,\n\t} );\n\n\tconst innerBlocksProps = useInnerBlocksProps(\n\t\t{\n\t\t\t...blockProps,\n\t\t\tclassName: 'remove-outline', // Remove the outline from the inner blocks container.\n\t\t},\n\t\t{\n\t\t\tdefaultBlock: DEFAULT_BLOCK,\n\t\t\tdirectInsert: true,\n\t\t\trenderAppender: false,\n\t\t}\n\t);\n\n\tif ( ! url || isInvalid || isDraft ) {\n\t\tblockProps.onClick = () => {\n\t\t\tsetIsLinkOpen( true );\n\t\t};\n\t}\n\n\tconst classes = clsx( 'wp-block-navigation-item__content', {\n\t\t'wp-block-navigation-link__placeholder': ! url || isInvalid || isDraft,\n\t} );\n\n\tconst missingText = getMissingText( type );\n\t/* translators: Whether the navigation link is Invalid or a Draft. */\n\tconst placeholderText = `(${\n\t\tisInvalid ? __( 'Invalid' ) : __( 'Draft' )\n\t})`;\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls>\n\t\t\t\t<ToolbarGroup>\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\tname=\"link\"\n\t\t\t\t\t\ticon={ linkIcon }\n\t\t\t\t\t\ttitle={ __( 'Link' ) }\n\t\t\t\t\t\tshortcut={ displayShortcut.primary( 'k' ) }\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tsetIsLinkOpen( true );\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t\t{ ! isAtMaxNesting && (\n\t\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\t\tname=\"submenu\"\n\t\t\t\t\t\t\ticon={ addSubmenu }\n\t\t\t\t\t\t\ttitle={ __( 'Add submenu' ) }\n\t\t\t\t\t\t\tonClick={ transformToSubmenu }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</ToolbarGroup>\n\t\t\t</BlockControls>\n\t\t\t<InspectorControls>\n\t\t\t\t<Controls\n\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t<div { ...blockProps }>\n\t\t\t\t{ /* eslint-disable jsx-a11y/anchor-is-valid */ }\n\t\t\t\t<a className={ classes }>\n\t\t\t\t\t{ /* eslint-enable */ }\n\t\t\t\t\t{ ! url && ! metadata?.bindings?.url ? (\n\t\t\t\t\t\t<div className=\"wp-block-navigation-link__placeholder-text\">\n\t\t\t\t\t\t\t<span>{ missingText }</span>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t{ ! isInvalid && ! isDraft && (\n\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t<RichText\n\t\t\t\t\t\t\t\t\t\tref={ ref }\n\t\t\t\t\t\t\t\t\t\tidentifier=\"label\"\n\t\t\t\t\t\t\t\t\t\tclassName=\"wp-block-navigation-item__label\"\n\t\t\t\t\t\t\t\t\t\tvalue={ label }\n\t\t\t\t\t\t\t\t\t\tonChange={ ( labelValue ) =>\n\t\t\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\t\t\tlabel: labelValue,\n\t\t\t\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tonMerge={ mergeBlocks }\n\t\t\t\t\t\t\t\t\t\tonReplace={ onReplace }\n\t\t\t\t\t\t\t\t\t\t__unstableOnSplitAtEnd={ () =>\n\t\t\t\t\t\t\t\t\t\t\tinsertBlocksAfter(\n\t\t\t\t\t\t\t\t\t\t\t\tcreateBlock(\n\t\t\t\t\t\t\t\t\t\t\t\t\t'core/navigation-link'\n\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\taria-label={ __(\n\t\t\t\t\t\t\t\t\t\t\t'Navigation link text'\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\tplaceholder={ itemLabelPlaceholder }\n\t\t\t\t\t\t\t\t\t\twithoutInteractiveFormatting\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t{ description && (\n\t\t\t\t\t\t\t\t\t\t<span className=\"wp-block-navigation-item__description\">\n\t\t\t\t\t\t\t\t\t\t\t{ description }\n\t\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t{ ( isInvalid || isDraft ) && (\n\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t\t\t\t'wp-block-navigation-link__placeholder-text',\n\t\t\t\t\t\t\t\t\t\t'wp-block-navigation-link__label',\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t'is-invalid': isInvalid,\n\t\t\t\t\t\t\t\t\t\t\t'is-draft': isDraft,\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t// Some attributes are stored in an escaped form. It's a legacy issue.\n\t\t\t\t\t\t\t\t\t\t\t// Ideally they would be stored in a raw, unescaped form.\n\t\t\t\t\t\t\t\t\t\t\t// Unescape is used here to \"recover\" the escaped characters\n\t\t\t\t\t\t\t\t\t\t\t// so they display without encoding.\n\t\t\t\t\t\t\t\t\t\t\t// See `updateAttributes` for more details.\n\t\t\t\t\t\t\t\t\t\t\t`${ decodeEntities( label ) } ${\n\t\t\t\t\t\t\t\t\t\t\t\tisInvalid || isDraft\n\t\t\t\t\t\t\t\t\t\t\t\t\t? placeholderText\n\t\t\t\t\t\t\t\t\t\t\t\t\t: ''\n\t\t\t\t\t\t\t\t\t\t\t}`.trim()\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t</div>\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\t{ isLinkOpen && (\n\t\t\t\t\t\t<LinkUI\n\t\t\t\t\t\t\tref={ linkUIref }\n\t\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\t\tlink={ attributes }\n\t\t\t\t\t\t\tonClose={ () => {\n\t\t\t\t\t\t\t\tsetIsLinkOpen( false );\n\t\t\t\t\t\t\t\t// If there is no link then remove the auto-inserted block.\n\t\t\t\t\t\t\t\t// This avoids empty blocks which can provided a poor UX.\n\t\t\t\t\t\t\t\tif ( ! url ) {\n\t\t\t\t\t\t\t\t\tonReplace( [] );\n\t\t\t\t\t\t\t\t} else if ( isNewLink.current ) {\n\t\t\t\t\t\t\t\t\t// If we just created a new link, select it\n\t\t\t\t\t\t\t\t\tselectBlock( clientId );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tanchor={ popoverAnchor }\n\t\t\t\t\t\t\tonRemove={ removeLink }\n\t\t\t\t\t\t\tonChange={ ( updatedValue ) => {\n\t\t\t\t\t\t\t\tconst { isEntityLink } = updateAttributes(\n\t\t\t\t\t\t\t\t\tupdatedValue,\n\t\t\t\t\t\t\t\t\tsetAttributes,\n\t\t\t\t\t\t\t\t\tattributes\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\t// Handle URL binding based on the final computed state\n\t\t\t\t\t\t\t\t// Only create bindings for entity links (posts, pages, taxonomies)\n\t\t\t\t\t\t\t\t// Never create bindings for custom links (manual URLs)\n\t\t\t\t\t\t\t\tif ( isEntityLink ) {\n\t\t\t\t\t\t\t\t\tcreateBinding();\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tclearBinding();\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</a>\n\t\t\t\t<div { ...innerBlocksProps } />\n\t\t\t</div>\n\t\t</>\n\t);\n}\n"],
|
|
5
|
-
"mappings": "AA0aI,SAsCI,UArCH,KADD;AAvaJ,OAAO,UAAU;AAKjB,SAAS,mBAAmB;AAC5B,SAAS,WAAW,mBAAmB;AACvC,SAAS,eAAe,oBAAoB;AAC5C,SAAS,iBAAiB,uBAAuB;AACjD,SAAS,UAAU;AACnB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,OAAO,mBAAmB;AACnC,SAAS,UAAU,WAAW,QAAQ,mBAAmB;AACzD,SAAS,sBAAsB;AAC/B,SAAS,QAAQ,UAAU,kBAAkB;AAC7C,SAAS,SAAS,iBAAiB;AACnC,SAAS,cAAc,mBAAmB;AAK1C,SAAS,iBAAiB;AAC1B,SAAS,UAAU,QAAQ,kBAAkB,wBAAwB;AAErE,MAAM,gBAAgB,EAAE,MAAM,uBAAuB;AACrD,MAAM,sBAAsB;AAAA,EAC3B;AAAA,EACA;AACD;AAWA,MAAM,sBAAsB,CAAE,eAAgB;AAC7C,QAAM,CAAE,kBAAkB,mBAAoB,IAAI,SAAU,KAAM;AAElE,YAAW,MAAM;AAChB,UAAM,EAAE,cAAc,IAAI,WAAW;AAErC,aAAS,gBAAiB,OAAQ;AAEjC,sBAAiB,KAAM;AAAA,IACxB;A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
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { createBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { ToolbarButton, ToolbarGroup } from '@wordpress/components';\nimport { displayShortcut, isKeyboardEvent } from '@wordpress/keycodes';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tBlockControls,\n\tInspectorControls,\n\tRichText,\n\tuseBlockProps,\n\tstore as blockEditorStore,\n\tgetColorClassName,\n\tuseInnerBlocksProps,\n\tuseBlockEditingMode,\n} from '@wordpress/block-editor';\nimport { isURL, prependHTTP } from '@wordpress/url';\nimport { useState, useEffect, useRef, useCallback } from '@wordpress/element';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { link as linkIcon, addSubmenu } from '@wordpress/icons';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useMergeRefs, usePrevious } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { getColors } from '../navigation/edit/utils';\nimport { Controls, LinkUI, updateAttributes, useEntityBinding } from './shared';\n\nconst DEFAULT_BLOCK = { name: 'core/navigation-link' };\nconst NESTING_BLOCK_NAMES = [\n\t'core/navigation-link',\n\t'core/navigation-submenu',\n];\n\n/**\n * A React hook to determine if it's dragging within the target element.\n *\n * @typedef {import('@wordpress/element').RefObject} RefObject\n *\n * @param {RefObject<HTMLElement>} elementRef The target elementRef object.\n *\n * @return {boolean} Is dragging within the target element.\n */\nconst useIsDraggingWithin = ( elementRef ) => {\n\tconst [ isDraggingWithin, setIsDraggingWithin ] = useState( false );\n\n\tuseEffect( () => {\n\t\tconst { ownerDocument } = elementRef.current;\n\n\t\tfunction handleDragStart( event ) {\n\t\t\t// Check the first time when the dragging starts.\n\t\t\thandleDragEnter( event );\n\t\t}\n\n\t\t// Set to false whenever the user cancel the drag event by either releasing the mouse or press Escape.\n\t\tfunction handleDragEnd() {\n\t\t\tsetIsDraggingWithin( false );\n\t\t}\n\n\t\tfunction handleDragEnter( event ) {\n\t\t\t// Check if the current target is inside the item element.\n\t\t\tif ( elementRef.current.contains( event.target ) ) {\n\t\t\t\tsetIsDraggingWithin( true );\n\t\t\t} else {\n\t\t\t\tsetIsDraggingWithin( false );\n\t\t\t}\n\t\t}\n\n\t\t// Bind these events to the document to catch all drag events.\n\t\t// Ideally, we can also use `event.relatedTarget`, but sadly that\n\t\t// doesn't work in Safari.\n\t\townerDocument.addEventListener( 'dragstart', handleDragStart );\n\t\townerDocument.addEventListener( 'dragend', handleDragEnd );\n\t\townerDocument.addEventListener( 'dragenter', handleDragEnter );\n\n\t\treturn () => {\n\t\t\townerDocument.removeEventListener( 'dragstart', handleDragStart );\n\t\t\townerDocument.removeEventListener( 'dragend', handleDragEnd );\n\t\t\townerDocument.removeEventListener( 'dragenter', handleDragEnter );\n\t\t};\n\t}, [ elementRef ] );\n\n\treturn isDraggingWithin;\n};\n\nconst useIsInvalidLink = ( kind, type, id, enabled ) => {\n\tconst isPostType =\n\t\tkind === 'post-type' || type === 'post' || type === 'page';\n\tconst hasId = Number.isInteger( id );\n\tconst blockEditingMode = useBlockEditingMode();\n\n\tconst postStatus = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! isPostType ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\t// Fetching the posts status is an \"expensive\" operation. Especially for sites with large navigations.\n\t\t\t// When the block is rendered in a template or other disabled contexts we can skip this check in order\n\t\t\t// to avoid all these additional requests that don't really add any value in that mode.\n\t\t\tif ( blockEditingMode === 'disabled' || ! enabled ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst { getEntityRecord } = select( coreStore );\n\t\t\treturn getEntityRecord( 'postType', type, id )?.status;\n\t\t},\n\t\t[ isPostType, blockEditingMode, enabled, type, id ]\n\t);\n\n\t// Check Navigation Link validity if:\n\t// 1. Link is 'post-type'.\n\t// 2. It has an id.\n\t// 3. It's neither null, nor undefined, as valid items might be either of those while loading.\n\t// If those conditions are met, check if\n\t// 1. The post status is published.\n\t// 2. The Navigation Link item has no label.\n\t// If either of those is true, invalidate.\n\tconst isInvalid =\n\t\tisPostType && hasId && postStatus && 'trash' === postStatus;\n\tconst isDraft = 'draft' === postStatus;\n\n\treturn [ isInvalid, isDraft ];\n};\n\nfunction getMissingText( type ) {\n\tlet missingText = '';\n\n\tswitch ( type ) {\n\t\tcase 'post':\n\t\t\t/* translators: label for missing post in navigation link block */\n\t\t\tmissingText = __( 'Select post' );\n\t\t\tbreak;\n\t\tcase 'page':\n\t\t\t/* translators: label for missing page in navigation link block */\n\t\t\tmissingText = __( 'Select page' );\n\t\t\tbreak;\n\t\tcase 'category':\n\t\t\t/* translators: label for missing category in navigation link block */\n\t\t\tmissingText = __( 'Select category' );\n\t\t\tbreak;\n\t\tcase 'tag':\n\t\t\t/* translators: label for missing tag in navigation link block */\n\t\t\tmissingText = __( 'Select tag' );\n\t\t\tbreak;\n\t\tdefault:\n\t\t\t/* translators: label for missing values in navigation link block */\n\t\t\tmissingText = __( 'Add link' );\n\t}\n\n\treturn missingText;\n}\n\nexport default function NavigationLinkEdit( {\n\tattributes,\n\tisSelected,\n\tsetAttributes,\n\tinsertBlocksAfter,\n\tmergeBlocks,\n\tonReplace,\n\tcontext,\n\tclientId,\n} ) {\n\tconst { id, label, type, url, description, kind, metadata } = attributes;\n\tconst { maxNestingLevel } = context;\n\n\tconst {\n\t\treplaceBlock,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t\tselectBlock,\n\t} = useDispatch( blockEditorStore );\n\t// Have the link editing ui open on mount when lacking a url and selected.\n\tconst [ isLinkOpen, setIsLinkOpen ] = useState( isSelected && ! url );\n\t// Use internal state instead of a ref to make sure that the component\n\t// re-renders when the popover's anchor updates.\n\tconst [ popoverAnchor, setPopoverAnchor ] = useState( null );\n\tconst listItemRef = useRef( null );\n\tconst isDraggingWithin = useIsDraggingWithin( listItemRef );\n\tconst itemLabelPlaceholder = __( 'Add label\u2026' );\n\tconst ref = useRef();\n\tconst linkUIref = useRef();\n\tconst prevUrl = usePrevious( url );\n\tconst isNewLink = useRef( ! url );\n\n\tconst {\n\t\tisAtMaxNesting,\n\t\tisTopLevelLink,\n\t\tisParentOfSelectedBlock,\n\t\thasChildren,\n\t\tvalidateLinkStatus,\n\t\tparentBlockClientId,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockCount,\n\t\t\t\tgetBlockName,\n\t\t\t\tgetBlockRootClientId,\n\t\t\t\thasSelectedInnerBlock,\n\t\t\t\tgetBlockParentsByBlockName,\n\t\t\t\tgetSelectedBlockClientId,\n\t\t\t} = select( blockEditorStore );\n\t\t\tconst rootClientId = getBlockRootClientId( clientId );\n\t\t\tconst parentBlockName = getBlockName( rootClientId );\n\t\t\tconst isTopLevel = parentBlockName === 'core/navigation';\n\t\t\tconst selectedBlockClientId = getSelectedBlockClientId();\n\t\t\tconst rootNavigationClientId = isTopLevel\n\t\t\t\t? rootClientId\n\t\t\t\t: getBlockParentsByBlockName(\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t'core/navigation'\n\t\t\t\t )[ 0 ];\n\n\t\t\t// Get the immediate parent - if it's a submenu, use it; otherwise use the navigation block\n\t\t\tconst parentBlockId =\n\t\t\t\tparentBlockName === 'core/navigation-submenu'\n\t\t\t\t\t? rootClientId\n\t\t\t\t\t: rootNavigationClientId;\n\n\t\t\t// Enable when the root Navigation block is selected or any of its inner blocks.\n\t\t\tconst enableLinkStatusValidation =\n\t\t\t\tselectedBlockClientId === rootNavigationClientId ||\n\t\t\t\thasSelectedInnerBlock( rootNavigationClientId, true );\n\n\t\t\treturn {\n\t\t\t\tisAtMaxNesting:\n\t\t\t\t\tgetBlockParentsByBlockName( clientId, NESTING_BLOCK_NAMES )\n\t\t\t\t\t\t.length >= maxNestingLevel,\n\t\t\t\tisTopLevelLink: isTopLevel,\n\t\t\t\tisParentOfSelectedBlock: hasSelectedInnerBlock(\n\t\t\t\t\tclientId,\n\t\t\t\t\ttrue\n\t\t\t\t),\n\t\t\t\thasChildren: !! getBlockCount( clientId ),\n\t\t\t\tvalidateLinkStatus: enableLinkStatusValidation,\n\t\t\t\tparentBlockClientId: parentBlockId,\n\t\t\t};\n\t\t},\n\t\t[ clientId, maxNestingLevel ]\n\t);\n\tconst { getBlocks } = useSelect( blockEditorStore );\n\n\t// URL binding logic\n\tconst { clearBinding, createBinding } = useEntityBinding( {\n\t\tclientId,\n\t\tattributes,\n\t} );\n\n\tconst [ isInvalid, isDraft ] = useIsInvalidLink(\n\t\tkind,\n\t\ttype,\n\t\tid,\n\t\tvalidateLinkStatus\n\t);\n\n\t/**\n\t * Transform to submenu block.\n\t */\n\tconst transformToSubmenu = useCallback( () => {\n\t\tlet innerBlocks = getBlocks( clientId );\n\t\tif ( innerBlocks.length === 0 ) {\n\t\t\tinnerBlocks = [ createBlock( 'core/navigation-link' ) ];\n\t\t\tselectBlock( innerBlocks[ 0 ].clientId );\n\t\t}\n\t\tconst newSubmenu = createBlock(\n\t\t\t'core/navigation-submenu',\n\t\t\tattributes,\n\t\t\tinnerBlocks\n\t\t);\n\t\treplaceBlock( clientId, newSubmenu );\n\t}, [ getBlocks, clientId, selectBlock, replaceBlock, attributes ] );\n\n\t// On mount, if this is a new link without a URL and it's selected,\n\t// select the parent block (submenu or navigation) instead to keep the appender visible.\n\t// This helps us return focus to the appender if the user closes the link ui without creating a link.\n\t// If we leave focus on this block, then when we close the link without creating a link, focus will\n\t// be lost during the new block selection process.\n\tuseEffect( () => {\n\t\tif ( isNewLink.current && isSelected && ! url ) {\n\t\t\tselectBlock( parentBlockClientId );\n\t\t}\n\t}, [] ); // eslint-disable-line react-hooks/exhaustive-deps\n\n\tuseEffect( () => {\n\t\t// If block has inner blocks, transform to Submenu.\n\t\tif ( hasChildren ) {\n\t\t\t// This side-effect should not create an undo level as those should\n\t\t\t// only be created via user interactions.\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\ttransformToSubmenu();\n\t\t}\n\t}, [\n\t\thasChildren,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t\ttransformToSubmenu,\n\t] );\n\n\t// If the LinkControl popover is open and the URL has changed, close the LinkControl and focus the label text.\n\tuseEffect( () => {\n\t\t// We only want to do this when the URL has gone from nothing to a new URL AND the label looks like a URL\n\t\tif (\n\t\t\t! prevUrl &&\n\t\t\turl &&\n\t\t\tisLinkOpen &&\n\t\t\tisURL( prependHTTP( label ) ) &&\n\t\t\t/^.+\\.[a-z]+/.test( label )\n\t\t) {\n\t\t\t// Focus and select the label text.\n\t\t\tselectLabelText();\n\t\t}\n\t}, [ prevUrl, url, isLinkOpen, label ] );\n\n\t/**\n\t * Focus the Link label text and select it.\n\t */\n\tfunction selectLabelText() {\n\t\tref.current.focus();\n\t\tconst { ownerDocument } = ref.current;\n\t\tconst { defaultView } = ownerDocument;\n\t\tconst selection = defaultView.getSelection();\n\t\tconst range = ownerDocument.createRange();\n\t\t// Get the range of the current ref contents so we can add this range to the selection.\n\t\trange.selectNodeContents( ref.current );\n\t\tselection.removeAllRanges();\n\t\tselection.addRange( range );\n\t}\n\n\t/**\n\t * Removes the current link if set.\n\t */\n\tfunction removeLink() {\n\t\t// Reset all attributes that comprise the link.\n\t\t// It is critical that all attributes are reset\n\t\t// to their default values otherwise this may\n\t\t// in advertently trigger side effects because\n\t\t// the values will have \"changed\".\n\t\tsetAttributes( {\n\t\t\turl: undefined,\n\t\t\tlabel: undefined,\n\t\t\tid: undefined,\n\t\t\tkind: undefined,\n\t\t\ttype: undefined,\n\t\t\topensInNewTab: false,\n\t\t} );\n\n\t\t// Close the link editing UI.\n\t\tsetIsLinkOpen( false );\n\t}\n\n\tconst {\n\t\ttextColor,\n\t\tcustomTextColor,\n\t\tbackgroundColor,\n\t\tcustomBackgroundColor,\n\t} = getColors( context, ! isTopLevelLink );\n\n\tfunction onKeyDown( event ) {\n\t\tif ( isKeyboardEvent.primary( event, 'k' ) ) {\n\t\t\t// Required to prevent the command center from opening,\n\t\t\t// as it shares the CMD+K shortcut.\n\t\t\t// See https://github.com/WordPress/gutenberg/pull/59845.\n\t\t\tevent.preventDefault();\n\t\t\t// If this link is a child of a parent submenu item, the parent submenu item event will also open, closing this popover\n\t\t\tevent.stopPropagation();\n\t\t\tsetIsLinkOpen( true );\n\t\t}\n\t}\n\n\tconst blockProps = useBlockProps( {\n\t\tref: useMergeRefs( [ setPopoverAnchor, listItemRef ] ),\n\t\tclassName: clsx( 'wp-block-navigation-item', {\n\t\t\t'is-editing': isSelected || isParentOfSelectedBlock,\n\t\t\t'is-dragging-within': isDraggingWithin,\n\t\t\t'has-link': !! url,\n\t\t\t'has-child': hasChildren,\n\t\t\t'has-text-color': !! textColor || !! customTextColor,\n\t\t\t[ getColorClassName( 'color', textColor ) ]: !! textColor,\n\t\t\t'has-background': !! backgroundColor || customBackgroundColor,\n\t\t\t[ getColorClassName( 'background-color', backgroundColor ) ]:\n\t\t\t\t!! backgroundColor,\n\t\t} ),\n\t\tstyle: {\n\t\t\tcolor: ! textColor && customTextColor,\n\t\t\tbackgroundColor: ! backgroundColor && customBackgroundColor,\n\t\t},\n\t\tonKeyDown,\n\t} );\n\n\tconst innerBlocksProps = useInnerBlocksProps(\n\t\t{\n\t\t\t...blockProps,\n\t\t\tclassName: 'remove-outline', // Remove the outline from the inner blocks container.\n\t\t},\n\t\t{\n\t\t\tdefaultBlock: DEFAULT_BLOCK,\n\t\t\tdirectInsert: true,\n\t\t\trenderAppender: false,\n\t\t}\n\t);\n\n\tif ( ! url || isInvalid || isDraft ) {\n\t\tblockProps.onClick = () => {\n\t\t\tsetIsLinkOpen( true );\n\t\t};\n\t}\n\n\tconst classes = clsx( 'wp-block-navigation-item__content', {\n\t\t'wp-block-navigation-link__placeholder': ! url || isInvalid || isDraft,\n\t} );\n\n\tconst missingText = getMissingText( type );\n\t/* translators: Whether the navigation link is Invalid or a Draft. */\n\tconst placeholderText = `(${\n\t\tisInvalid ? __( 'Invalid' ) : __( 'Draft' )\n\t})`;\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls>\n\t\t\t\t<ToolbarGroup>\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\tname=\"link\"\n\t\t\t\t\t\ticon={ linkIcon }\n\t\t\t\t\t\ttitle={ __( 'Link' ) }\n\t\t\t\t\t\tshortcut={ displayShortcut.primary( 'k' ) }\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tsetIsLinkOpen( true );\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t\t{ ! isAtMaxNesting && (\n\t\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\t\tname=\"submenu\"\n\t\t\t\t\t\t\ticon={ addSubmenu }\n\t\t\t\t\t\t\ttitle={ __( 'Add submenu' ) }\n\t\t\t\t\t\t\tonClick={ transformToSubmenu }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</ToolbarGroup>\n\t\t\t</BlockControls>\n\t\t\t<InspectorControls>\n\t\t\t\t<Controls\n\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t<div { ...blockProps }>\n\t\t\t\t{ /* eslint-disable jsx-a11y/anchor-is-valid */ }\n\t\t\t\t<a className={ classes }>\n\t\t\t\t\t{ /* eslint-enable */ }\n\t\t\t\t\t{ ! url && ! metadata?.bindings?.url ? (\n\t\t\t\t\t\t<div className=\"wp-block-navigation-link__placeholder-text\">\n\t\t\t\t\t\t\t<span>{ missingText }</span>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t{ ! isInvalid && ! isDraft && (\n\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t<RichText\n\t\t\t\t\t\t\t\t\t\tref={ ref }\n\t\t\t\t\t\t\t\t\t\tidentifier=\"label\"\n\t\t\t\t\t\t\t\t\t\tclassName=\"wp-block-navigation-item__label\"\n\t\t\t\t\t\t\t\t\t\tvalue={ label }\n\t\t\t\t\t\t\t\t\t\tonChange={ ( labelValue ) =>\n\t\t\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\t\t\tlabel: labelValue,\n\t\t\t\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tonMerge={ mergeBlocks }\n\t\t\t\t\t\t\t\t\t\tonReplace={ onReplace }\n\t\t\t\t\t\t\t\t\t\t__unstableOnSplitAtEnd={ () =>\n\t\t\t\t\t\t\t\t\t\t\tinsertBlocksAfter(\n\t\t\t\t\t\t\t\t\t\t\t\tcreateBlock(\n\t\t\t\t\t\t\t\t\t\t\t\t\t'core/navigation-link'\n\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\taria-label={ __(\n\t\t\t\t\t\t\t\t\t\t\t'Navigation link text'\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\tplaceholder={ itemLabelPlaceholder }\n\t\t\t\t\t\t\t\t\t\twithoutInteractiveFormatting\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t{ description && (\n\t\t\t\t\t\t\t\t\t\t<span className=\"wp-block-navigation-item__description\">\n\t\t\t\t\t\t\t\t\t\t\t{ description }\n\t\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t{ ( isInvalid || isDraft ) && (\n\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t\t\t\t'wp-block-navigation-link__placeholder-text',\n\t\t\t\t\t\t\t\t\t\t'wp-block-navigation-link__label',\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t'is-invalid': isInvalid,\n\t\t\t\t\t\t\t\t\t\t\t'is-draft': isDraft,\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t// Some attributes are stored in an escaped form. It's a legacy issue.\n\t\t\t\t\t\t\t\t\t\t\t// Ideally they would be stored in a raw, unescaped form.\n\t\t\t\t\t\t\t\t\t\t\t// Unescape is used here to \"recover\" the escaped characters\n\t\t\t\t\t\t\t\t\t\t\t// so they display without encoding.\n\t\t\t\t\t\t\t\t\t\t\t// See `updateAttributes` for more details.\n\t\t\t\t\t\t\t\t\t\t\t`${ decodeEntities( label ) } ${\n\t\t\t\t\t\t\t\t\t\t\t\tisInvalid || isDraft\n\t\t\t\t\t\t\t\t\t\t\t\t\t? placeholderText\n\t\t\t\t\t\t\t\t\t\t\t\t\t: ''\n\t\t\t\t\t\t\t\t\t\t\t}`.trim()\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t</div>\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\t{ isLinkOpen && (\n\t\t\t\t\t\t<LinkUI\n\t\t\t\t\t\t\tref={ linkUIref }\n\t\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\t\tlink={ attributes }\n\t\t\t\t\t\t\tonClose={ () => {\n\t\t\t\t\t\t\t\tsetIsLinkOpen( false );\n\t\t\t\t\t\t\t\t// If there is no link then remove the auto-inserted block.\n\t\t\t\t\t\t\t\t// This avoids empty blocks which can provided a poor UX.\n\t\t\t\t\t\t\t\tif ( ! url ) {\n\t\t\t\t\t\t\t\t\tonReplace( [] );\n\t\t\t\t\t\t\t\t} else if ( isNewLink.current ) {\n\t\t\t\t\t\t\t\t\t// If we just created a new link, select it\n\t\t\t\t\t\t\t\t\tselectBlock( clientId );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tanchor={ popoverAnchor }\n\t\t\t\t\t\t\tonRemove={ removeLink }\n\t\t\t\t\t\t\tonChange={ ( updatedValue ) => {\n\t\t\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\t\t\tisEntityLink,\n\t\t\t\t\t\t\t\t\tattributes: updatedAttributes,\n\t\t\t\t\t\t\t\t} = updateAttributes(\n\t\t\t\t\t\t\t\t\tupdatedValue,\n\t\t\t\t\t\t\t\t\tsetAttributes,\n\t\t\t\t\t\t\t\t\tattributes\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\t// Handle URL binding based on the final computed state\n\t\t\t\t\t\t\t\t// Only create bindings for entity links (posts, pages, taxonomies)\n\t\t\t\t\t\t\t\t// Never create bindings for custom links (manual URLs)\n\t\t\t\t\t\t\t\tif ( isEntityLink ) {\n\t\t\t\t\t\t\t\t\tcreateBinding( updatedAttributes );\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tclearBinding( updatedAttributes );\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</a>\n\t\t\t\t<div { ...innerBlocksProps } />\n\t\t\t</div>\n\t\t</>\n\t);\n}\n"],
|
|
5
|
+
"mappings": "AA0aI,SAsCI,UArCH,KADD;AAvaJ,OAAO,UAAU;AAKjB,SAAS,mBAAmB;AAC5B,SAAS,WAAW,mBAAmB;AACvC,SAAS,eAAe,oBAAoB;AAC5C,SAAS,iBAAiB,uBAAuB;AACjD,SAAS,UAAU;AACnB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,OAAO,mBA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A,cACD;AAAA,cAEA,8BAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAOC,aAAI,eAAgB,KAAM,CAAE,IAC3B,aAAa,UACV,kBACA,EACJ,GAAG,KAAK;AAAA,eAEV;AAAA;AAAA,UACD;AAAA,WAEF;AAAA,QAEC,cACD;AAAA,UAAC;AAAA;AAAA,YACA,KAAM;AAAA,YACN;AAAA,YACA,MAAO;AAAA,YACP,SAAU,MAAM;AACf,4BAAe,KAAM;AAGrB,kBAAK,CAAE,KAAM;AACZ,0BAAW,CAAC,CAAE;AAAA,cACf,WAAY,UAAU,SAAU;AAE/B,4BAAa,QAAS;AAAA,cACvB;AAAA,YACD;AAAA,YACA,QAAS;AAAA,YACT,UAAW;AAAA,YACX,UAAW,CAAE,iBAAkB;AAC9B,oBAAM;AAAA,gBACL;AAAA,gBACA,YAAY;AAAA,cACb,IAAI;AAAA,gBACH;AAAA,gBACA;AAAA,gBACA;AAAA,cACD;AAKA,kBAAK,cAAe;AACnB,8BAAe,iBAAkB;AAAA,cAClC,OAAO;AACN,6BAAc,iBAAkB;AAAA,cACjC;AAAA,YACD;AAAA;AAAA,QACD;AAAA,SAEF;AAAA,MACA,oBAAC,SAAM,GAAG,kBAAmB;AAAA,OAC9B;AAAA,KACD;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -60,7 +60,7 @@ function UnforwardedLinkUI(props, ref) {
|
|
|
60
60
|
kind: "postType",
|
|
61
61
|
name: postType
|
|
62
62
|
});
|
|
63
|
-
const hasUrlBinding = metadata?.bindings?.url?.source === "core/
|
|
63
|
+
const hasUrlBinding = (metadata?.bindings?.url?.source === "core/post-data" || metadata?.bindings?.url?.source === "core/term-data") && !!id;
|
|
64
64
|
const link = useMemo(
|
|
65
65
|
() => ({
|
|
66
66
|
url,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/navigation-link/link-ui/index.js"],
|
|
4
|
-
"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 { __ } from '@wordpress/i18n';\nimport { LinkControl, useBlockEditingMode } 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 { plus } from '@wordpress/icons';\nimport { useInstanceId } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { LinkUIPageCreator } from './page-creator';\nimport LinkUIBlockInserter from './block-inserter';\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 UnforwardedLinkUI( props, ref ) {\n\tconst { label, url, opensInNewTab, type, kind, id, metadata } = 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// Check if there's a URL binding with the
|
|
5
|
-
"mappings": "
|
|
4
|
+
"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 { __ } from '@wordpress/i18n';\nimport { LinkControl, useBlockEditingMode } 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 { plus } from '@wordpress/icons';\nimport { useInstanceId } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { LinkUIPageCreator } from './page-creator';\nimport LinkUIBlockInserter from './block-inserter';\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 UnforwardedLinkUI( props, ref ) {\n\tconst { label, url, opensInNewTab, type, kind, id, metadata } = 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// Check if there's a URL binding with the new binding sources\n\t// Only enable handleEntities when there's actually a binding present\n\tconst hasUrlBinding =\n\t\t( metadata?.bindings?.url?.source === 'core/post-data' ||\n\t\t\tmetadata?.bindings?.url?.source === 'core/term-data' ) &&\n\t\t!! id;\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\tkind,\n\t\t\ttype,\n\t\t\tid,\n\t\t} ),\n\t\t[ label, opensInNewTab, url, kind, type, id ]\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\thandleEntities={ hasUrlBinding }\n\t\t\t\t\t\trenderControlBottom={ () => {\n\t\t\t\t\t\t\t// Don't show the tools when there is submitted link (preview state).\n\t\t\t\t\t\t\tif ( link?.url?.length ) {\n\t\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\treturn (\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\tcanAddPage={\n\t\t\t\t\t\t\t\t\t\tpermissions?.canCreate &&\n\t\t\t\t\t\t\t\t\t\ttype === 'page'\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tcanAddBlock={\n\t\t\t\t\t\t\t\t\t\tblockEditingMode === 'default'\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\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\tcanAddPage,\n\tcanAddBlock,\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\t// Don't render anything if neither button should be shown\n\tif ( ! canAddPage && ! canAddBlock ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<VStack spacing={ 0 } className=\"link-ui-tools\">\n\t\t\t{ canAddPage && (\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{ canAddBlock && (\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"],
|
|
5
|
+
"mappings": "AAqIK,SACC,KADD;AAlIL,SAAS,uBAAuB,iBAAiB;AACjD;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA,wBAAwB;AAAA,OAClB;AACP,SAAS,UAAU;AACnB,SAAS,aAAa,2BAA2B;AACjD;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,8BAA8B;AACvC,SAAS,YAAY;AACrB,SAAS,qBAAqB;AAK9B,SAAS,yBAAyB;AAClC,OAAO,yBAAyB;AAUzB,SAAS,oBAAqB,MAAM,MAAO;AACjD,UAAS,MAAO;AAAA,IACf,KAAK;AAAA,IACL,KAAK;AACJ,aAAO,EAAE,MAAM,QAAQ,SAAS,KAAK;AAAA,IACtC,KAAK;AACJ,aAAO,EAAE,MAAM,QAAQ,SAAS,WAAW;AAAA,IAC5C,KAAK;AACJ,aAAO,EAAE,MAAM,QAAQ,SAAS,WAAW;AAAA,IAC5C,KAAK;AACJ,aAAO,EAAE,MAAM,cAAc;AAAA,IAC9B;AACC,UAAK,SAAS,YAAa;AAC1B,eAAO,EAAE,MAAM,QAAQ,SAAS,KAAK;AAAA,MACtC;AACA,UAAK,SAAS,aAAc;AAC3B,eAAO,EAAE,MAAM,QAAQ,SAAS,KAAK;AAAA,MACtC;AACA,aAAO;AAAA;AAAA;AAAA,QAGN,iCAAiC;AAAA,UAChC,MAAM;AAAA,UACN,SAAS;AAAA,UACT,SAAS;AAAA,QACV;AAAA,MACD;AAAA,EACF;AACD;AAEA,SAAS,kBAAmB,OAAO,KAAM;AACxC,QAAM,EAAE,OAAO,KAAK,eAAe,MAAM,MAAM,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AEF;AAEO,MAAM,SAAS,WAAY,iBAAkB;AAEpD,MAAM,cAAc,CAAE;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,MAAO;AACN,QAAM,wBAAwB;AAC9B,QAAM,oBAAoB,OAAO;AACjC,QAAM,mBAAmB,OAAO;AAGhC,YAAW,MAAM;AAChB,QAAK,qBAAsB;AAC1B,wBAAkB,SAAS,MAAM;AAAA,IAClC;AAAA,EACD,GAAG,CAAE,mBAAoB,CAAE;AAG3B,YAAW,MAAM;AAChB,QAAK,oBAAqB;AACzB,uBAAiB,SAAS,MAAM;AAAA,IACjC;AAAA,EACD,GAAG,CAAE,kBAAmB,CAAE;AAG1B,MAAK,CAAE,cAAc,CAAE,aAAc;AACpC,WAAO;AAAA,EACR;AAEA,SACC,qBAAC,UAAO,SAAU,GAAI,WAAU,iBAC7B;AAAA,kBACD;AAAA,MAAC;AAAA;AAAA,QACA,uBAAqB;AAAA,QACrB,KAAM;AAAA,QACN,MAAO;AAAA,QACP,SAAU,CAAE,MAAO;AAClB,YAAE,eAAe;AACjB,wBAAe,IAAK;AAAA,QACrB;AAAA,QACA,iBAAgB;AAAA,QAEd,aAAI,aAAc;AAAA;AAAA,IACrB;AAAA,IAEC,eACD;AAAA,MAAC;AAAA;AAAA,QACA,uBAAqB;AAAA,QACrB,KAAM;AAAA,QACN,MAAO;AAAA,QACP,SAAU,CAAE,MAAO;AAClB,YAAE,eAAe;AACjB,yBAAgB,IAAK;AAAA,QACtB;AAAA,QACA,iBAAgB;AAAA,QAEd,aAAI,WAAY;AAAA;AAAA,IACnB;AAAA,KAEF;AAEF;AAEA,IAAO,kBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -14,6 +14,8 @@ import { useInstanceId } from "@wordpress/compose";
|
|
|
14
14
|
import { safeDecodeURI } from "@wordpress/url";
|
|
15
15
|
import { __unstableStripHTML as stripHTML } from "@wordpress/dom";
|
|
16
16
|
import { linkOff as unlinkIcon } from "@wordpress/icons";
|
|
17
|
+
import { useDispatch } from "@wordpress/data";
|
|
18
|
+
import { store as blockEditorStore } from "@wordpress/block-editor";
|
|
17
19
|
import { useToolsPanelDropdownMenuProps } from "../../utils/hooks";
|
|
18
20
|
import { updateAttributes } from "./update-attributes";
|
|
19
21
|
import { useEntityBinding } from "./use-entity-binding";
|
|
@@ -50,9 +52,10 @@ function Controls({ attributes, setAttributes, clientId }) {
|
|
|
50
52
|
clientId,
|
|
51
53
|
attributes
|
|
52
54
|
});
|
|
55
|
+
const { updateBlockAttributes } = useDispatch(blockEditorStore);
|
|
53
56
|
const editBoundLink = () => {
|
|
54
57
|
clearBinding();
|
|
55
|
-
|
|
58
|
+
updateBlockAttributes(clientId, { url: "", id: void 0 });
|
|
56
59
|
};
|
|
57
60
|
return /* @__PURE__ */ jsxs(
|
|
58
61
|
ToolsPanel,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/navigation-link/shared/controls.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\t__experimentalInputControl as InputControl,\n\tButton,\n\tCheckboxControl,\n\tTextControl,\n\tTextareaControl,\n} from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useRef } from '@wordpress/element';\nimport { useInstanceId } from '@wordpress/compose';\nimport { safeDecodeURI } from '@wordpress/url';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\nimport { linkOff as unlinkIcon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { useToolsPanelDropdownMenuProps } from '../../utils/hooks';\nimport { updateAttributes } from './update-attributes';\nimport { useEntityBinding } from './use-entity-binding';\n\n/**\n * Get a human-readable entity type name.\n *\n * @param {string} type - The entity type\n * @param {string} kind - The entity kind\n * @return {string} Human-readable entity type name\n */\nfunction getEntityTypeName( type, kind ) {\n\tif ( kind === 'post-type' ) {\n\t\tswitch ( type ) {\n\t\t\tcase 'post':\n\t\t\t\treturn __( 'post' );\n\t\t\tcase 'page':\n\t\t\t\treturn __( 'page' );\n\t\t\tdefault:\n\t\t\t\treturn type || __( 'post' );\n\t\t}\n\t}\n\tif ( kind === 'taxonomy' ) {\n\t\tswitch ( type ) {\n\t\t\tcase 'category':\n\t\t\t\treturn __( 'category' );\n\t\t\tcase 'tag':\n\t\t\t\treturn __( 'tag' );\n\t\t\tdefault:\n\t\t\t\treturn type || __( 'term' );\n\t\t}\n\t}\n\treturn type || __( 'item' );\n}\n\n/**\n * Shared Controls component for Navigation Link and Navigation Submenu blocks.\n *\n * This component provides the inspector controls (ToolsPanel) that are identical\n * between both navigation blocks.\n *\n * @param {Object} props - Component props\n * @param {Object} props.attributes - Block attributes\n * @param {Function} props.setAttributes - Function to update block attributes\n * @param {string} props.clientId - Block client ID\n */\nexport function Controls( { attributes, setAttributes, clientId } ) {\n\tconst { label, url, description, rel, opensInNewTab } = attributes;\n\tconst lastURLRef = useRef( url );\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\tconst inputId = useInstanceId( Controls, 'link-input' );\n\tconst helpTextId = `${ inputId }__help`;\n\n\t// Use the entity binding hook internally\n\tconst { hasUrlBinding, clearBinding } = useEntityBinding( {\n\t\tclientId,\n\t\tattributes,\n\t} );\n\n\tconst editBoundLink = () => {\n\t\t//
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\t__experimentalInputControl as InputControl,\n\tButton,\n\tCheckboxControl,\n\tTextControl,\n\tTextareaControl,\n} from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useRef } from '@wordpress/element';\nimport { useInstanceId } from '@wordpress/compose';\nimport { safeDecodeURI } from '@wordpress/url';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\nimport { linkOff as unlinkIcon } from '@wordpress/icons';\nimport { useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { useToolsPanelDropdownMenuProps } from '../../utils/hooks';\nimport { updateAttributes } from './update-attributes';\nimport { useEntityBinding } from './use-entity-binding';\n\n/**\n * Get a human-readable entity type name.\n *\n * @param {string} type - The entity type\n * @param {string} kind - The entity kind\n * @return {string} Human-readable entity type name\n */\nfunction getEntityTypeName( type, kind ) {\n\tif ( kind === 'post-type' ) {\n\t\tswitch ( type ) {\n\t\t\tcase 'post':\n\t\t\t\treturn __( 'post' );\n\t\t\tcase 'page':\n\t\t\t\treturn __( 'page' );\n\t\t\tdefault:\n\t\t\t\treturn type || __( 'post' );\n\t\t}\n\t}\n\tif ( kind === 'taxonomy' ) {\n\t\tswitch ( type ) {\n\t\t\tcase 'category':\n\t\t\t\treturn __( 'category' );\n\t\t\tcase 'tag':\n\t\t\t\treturn __( 'tag' );\n\t\t\tdefault:\n\t\t\t\treturn type || __( 'term' );\n\t\t}\n\t}\n\treturn type || __( 'item' );\n}\n\n/**\n * Shared Controls component for Navigation Link and Navigation Submenu blocks.\n *\n * This component provides the inspector controls (ToolsPanel) that are identical\n * between both navigation blocks.\n *\n * @param {Object} props - Component props\n * @param {Object} props.attributes - Block attributes\n * @param {Function} props.setAttributes - Function to update block attributes\n * @param {string} props.clientId - Block client ID\n */\nexport function Controls( { attributes, setAttributes, clientId } ) {\n\tconst { label, url, description, rel, opensInNewTab } = attributes;\n\tconst lastURLRef = useRef( url );\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\tconst inputId = useInstanceId( Controls, 'link-input' );\n\tconst helpTextId = `${ inputId }__help`;\n\n\t// Use the entity binding hook internally\n\tconst { hasUrlBinding, clearBinding } = useEntityBinding( {\n\t\tclientId,\n\t\tattributes,\n\t} );\n\n\t// Get direct store dispatch to bypass setBoundAttributes wrapper\n\tconst { updateBlockAttributes } = useDispatch( blockEditorStore );\n\n\tconst editBoundLink = () => {\n\t\t// Clear the binding first\n\t\tclearBinding();\n\n\t\t// Use direct store dispatch to bypass block bindings safeguards\n\t\t// which prevent updates to bound attributes when calling setAttributes.\n\t\t// setAttributes is actually setBoundAttributes, a wrapper function that\n\t\t// processes attributes through the binding system.\n\t\t// See: packages/block-editor/src/components/block-edit/edit.js\n\t\tupdateBlockAttributes( clientId, { url: '', id: undefined } );\n\t};\n\n\treturn (\n\t\t<ToolsPanel\n\t\t\tlabel={ __( 'Settings' ) }\n\t\t\tresetAll={ () => {\n\t\t\t\tsetAttributes( {\n\t\t\t\t\tlabel: '',\n\t\t\t\t\turl: '',\n\t\t\t\t\tdescription: '',\n\t\t\t\t\trel: '',\n\t\t\t\t\topensInNewTab: false,\n\t\t\t\t} );\n\t\t\t} }\n\t\t\tdropdownMenuProps={ dropdownMenuProps }\n\t\t>\n\t\t\t<ToolsPanelItem\n\t\t\t\thasValue={ () => !! label }\n\t\t\t\tlabel={ __( 'Text' ) }\n\t\t\t\tonDeselect={ () => setAttributes( { label: '' } ) }\n\t\t\t\tisShownByDefault\n\t\t\t>\n\t\t\t\t<TextControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tlabel={ __( 'Text' ) }\n\t\t\t\t\tvalue={ label ? stripHTML( label ) : '' }\n\t\t\t\t\tonChange={ ( labelValue ) => {\n\t\t\t\t\t\tsetAttributes( { label: labelValue } );\n\t\t\t\t\t} }\n\t\t\t\t\tautoComplete=\"off\"\n\t\t\t\t/>\n\t\t\t</ToolsPanelItem>\n\n\t\t\t<ToolsPanelItem\n\t\t\t\thasValue={ () => !! url }\n\t\t\t\tlabel={ __( 'Link' ) }\n\t\t\t\tonDeselect={ () => setAttributes( { url: '' } ) }\n\t\t\t\tisShownByDefault\n\t\t\t>\n\t\t\t\t<InputControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tid={ inputId }\n\t\t\t\t\tlabel={ __( 'Link' ) }\n\t\t\t\t\tvalue={ url ? safeDecodeURI( url ) : '' }\n\t\t\t\t\tonChange={ ( urlValue ) => {\n\t\t\t\t\t\tif ( hasUrlBinding ) {\n\t\t\t\t\t\t\treturn; // Prevent editing when URL is bound\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\turl: encodeURI( safeDecodeURI( urlValue ) ),\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\tautoComplete=\"off\"\n\t\t\t\t\ttype=\"url\"\n\t\t\t\t\tdisabled={ hasUrlBinding }\n\t\t\t\t\tonFocus={ () => {\n\t\t\t\t\t\tif ( hasUrlBinding ) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlastURLRef.current = url;\n\t\t\t\t\t} }\n\t\t\t\t\tonBlur={ () => {\n\t\t\t\t\t\tif ( hasUrlBinding ) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Defer the updateAttributes call to ensure entity connection isn't severed by accident.\n\t\t\t\t\t\tupdateAttributes(\n\t\t\t\t\t\t\t{ url: ! url ? lastURLRef.current : url },\n\t\t\t\t\t\t\tsetAttributes,\n\t\t\t\t\t\t\t{ ...attributes, url: lastURLRef.current }\n\t\t\t\t\t\t);\n\t\t\t\t\t} }\n\t\t\t\t\thelp={\n\t\t\t\t\t\thasUrlBinding && (\n\t\t\t\t\t\t\t<BindingHelpText\n\t\t\t\t\t\t\t\ttype={ attributes.type }\n\t\t\t\t\t\t\t\tkind={ attributes.kind }\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\tsuffix={\n\t\t\t\t\t\thasUrlBinding && (\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\ticon={ unlinkIcon }\n\t\t\t\t\t\t\t\tonClick={ editBoundLink }\n\t\t\t\t\t\t\t\taria-describedby={ helpTextId }\n\t\t\t\t\t\t\t\tshowTooltip\n\t\t\t\t\t\t\t\tlabel={ __( 'Unsync and edit' ) }\n\t\t\t\t\t\t\t\t__next40pxDefaultSize\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/>\n\t\t\t</ToolsPanelItem>\n\n\t\t\t<ToolsPanelItem\n\t\t\t\thasValue={ () => !! opensInNewTab }\n\t\t\t\tlabel={ __( 'Open in new tab' ) }\n\t\t\t\tonDeselect={ () => setAttributes( { opensInNewTab: false } ) }\n\t\t\t\tisShownByDefault\n\t\t\t>\n\t\t\t\t<CheckboxControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tlabel={ __( 'Open in new tab' ) }\n\t\t\t\t\tchecked={ opensInNewTab }\n\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\tsetAttributes( { opensInNewTab: value } )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</ToolsPanelItem>\n\n\t\t\t<ToolsPanelItem\n\t\t\t\thasValue={ () => !! description }\n\t\t\t\tlabel={ __( 'Description' ) }\n\t\t\t\tonDeselect={ () => setAttributes( { description: '' } ) }\n\t\t\t\tisShownByDefault\n\t\t\t>\n\t\t\t\t<TextareaControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tlabel={ __( 'Description' ) }\n\t\t\t\t\tvalue={ description || '' }\n\t\t\t\t\tonChange={ ( descriptionValue ) => {\n\t\t\t\t\t\tsetAttributes( { description: descriptionValue } );\n\t\t\t\t\t} }\n\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t'The description will be displayed in the menu if the current theme supports it.'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</ToolsPanelItem>\n\n\t\t\t<ToolsPanelItem\n\t\t\t\thasValue={ () => !! rel }\n\t\t\t\tlabel={ __( 'Rel attribute' ) }\n\t\t\t\tonDeselect={ () => setAttributes( { rel: '' } ) }\n\t\t\t\tisShownByDefault\n\t\t\t>\n\t\t\t\t<TextControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tlabel={ __( 'Rel attribute' ) }\n\t\t\t\t\tvalue={ rel || '' }\n\t\t\t\t\tonChange={ ( relValue ) => {\n\t\t\t\t\t\tsetAttributes( { rel: relValue } );\n\t\t\t\t\t} }\n\t\t\t\t\tautoComplete=\"off\"\n\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t'The relationship of the linked URL as space-separated link types.'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</ToolsPanelItem>\n\t\t</ToolsPanel>\n\t);\n}\n\n/**\n * Component to display help text for bound URL attributes.\n *\n * @param {Object} props - Component props\n * @param {string} props.type - The entity type\n * @param {string} props.kind - The entity kind\n * @return {string} Help text for the bound URL\n */\nfunction BindingHelpText( { type, kind } ) {\n\tconst entityType = getEntityTypeName( type, kind );\n\treturn sprintf(\n\t\t/* translators: %s is the entity type (e.g., \"page\", \"post\", \"category\") */\n\t\t__( 'Synced with the selected %s.' ),\n\t\tentityType\n\t);\n}\n"],
|
|
5
|
+
"mappings": "AAmGE,SAmBE,KAnBF;AAhGF;AAAA,EACC,4BAA4B;AAAA,EAC5B,gCAAgC;AAAA,EAChC,8BAA8B;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,IAAI,eAAe;AAC5B,SAAS,cAAc;AACvB,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB,iBAAiB;AACjD,SAAS,WAAW,kBAAkB;AACtC,SAAS,mBAAmB;AAC5B,SAAS,SAAS,wBAAwB;AAK1C,SAAS,sCAAsC;AAC/C,SAAS,wBAAwB;AACjC,SAAS,wBAAwB;AASjC,SAAS,kBAAmB,MAAM,MA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eAAgB;AAAA,YAC5B,YAAa,MAAM,cAAe,EAAE,KAAK,GAAG,CAAE;AAAA,YAC9C,kBAAgB;AAAA,YAEhB;AAAA,cAAC;AAAA;AAAA,gBACA,yBAAuB;AAAA,gBACvB,uBAAqB;AAAA,gBACrB,OAAQ,GAAI,eAAgB;AAAA,gBAC5B,OAAQ,OAAO;AAAA,gBACf,UAAW,CAAE,aAAc;AAC1B,gCAAe,EAAE,KAAK,SAAS,CAAE;AAAA,gBAClC;AAAA,gBACA,cAAa;AAAA,gBACb,MAAO;AAAA,kBACN;AAAA,gBACD;AAAA;AAAA,YACD;AAAA;AAAA,QACD;AAAA;AAAA;AAAA,EACD;AAEF;AAUA,SAAS,gBAAiB,EAAE,MAAM,KAAK,GAAI;AAC1C,QAAM,aAAa,kBAAmB,MAAM,IAAK;AACjD,SAAO;AAAA;AAAA,IAEN,GAAI,8BAA+B;AAAA,IACnC;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { Controls } from "./controls";
|
|
2
2
|
import { updateAttributes } from "./update-attributes";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
useEntityBinding,
|
|
5
|
+
buildNavigationLinkEntityBinding
|
|
6
|
+
} from "./use-entity-binding";
|
|
4
7
|
import { LinkUI } from "../link-ui";
|
|
5
8
|
export {
|
|
6
9
|
Controls,
|
|
7
10
|
LinkUI,
|
|
11
|
+
buildNavigationLinkEntityBinding,
|
|
8
12
|
updateAttributes,
|
|
9
13
|
useEntityBinding
|
|
10
14
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/navigation-link/shared/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * Shared components for Navigation Link and Navigation Submenu blocks.\n *\n * This module provides common functionality that can be used by both blocks\n * to reduce code duplication and ensure consistent behavior.\n */\n\nexport { Controls } from './controls';\nexport { updateAttributes } from './update-attributes';\nexport {
|
|
5
|
-
"mappings": "AAOA,SAAS,gBAAgB;AACzB,SAAS,wBAAwB;AACjC,
|
|
4
|
+
"sourcesContent": ["/**\n * Shared components for Navigation Link and Navigation Submenu blocks.\n *\n * This module provides common functionality that can be used by both blocks\n * to reduce code duplication and ensure consistent behavior.\n */\n\nexport { Controls } from './controls';\nexport { updateAttributes } from './update-attributes';\nexport {\n\tuseEntityBinding,\n\tbuildNavigationLinkEntityBinding,\n} from './use-entity-binding';\nexport { LinkUI } from '../link-ui';\n"],
|
|
5
|
+
"mappings": "AAOA,SAAS,gBAAgB;AACzB,SAAS,wBAAwB;AACjC;AAAA,EACC;AAAA,EACA;AAAA,OACM;AACP,SAAS,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -108,7 +108,9 @@ const updateAttributes = (updatedValue = {}, setAttributes, blockAttributes = {}
|
|
|
108
108
|
const finalId = "id" in attributes ? attributes.id : blockAttributes.id;
|
|
109
109
|
const finalKind = "kind" in attributes ? attributes.kind : blockAttributes.kind;
|
|
110
110
|
return {
|
|
111
|
-
isEntityLink: !!finalId && finalKind !== "custom"
|
|
111
|
+
isEntityLink: !!finalId && finalKind !== "custom",
|
|
112
|
+
attributes
|
|
113
|
+
// Return the computed attributes object
|
|
112
114
|
};
|
|
113
115
|
};
|
|
114
116
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/navigation-link/shared/update-attributes.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { escapeHTML } from '@wordpress/escape-html';\nimport { safeDecodeURI, getPath } from '@wordpress/url';\n\n/**\n * Determines if an entity link should be severed based on URL changes.\n *\n * @param {string} originalUrl - The original URL\n * @param {string} newUrl - The new URL\n * @return {boolean} True if the entity link should be severed\n */\nconst shouldSeverEntityLink = ( originalUrl, newUrl ) => {\n\tif ( ! originalUrl || ! newUrl ) {\n\t\treturn false;\n\t}\n\n\tconst normalizePath = ( path ) => {\n\t\tif ( ! path ) {\n\t\t\treturn '';\n\t\t}\n\t\treturn path.replace( /\\/+$/, '' ); // Remove trailing slashes\n\t};\n\n\t// Helper function to create URL objects with proper base handling\n\tconst createUrlObject = ( url, baseUrl = null ) => {\n\t\ttry {\n\t\t\t// Always provide a base URL - it will be ignored for absolute URLs\n\t\t\t// Use window.location.origin in browser, fallback for Node/tests\n\t\t\tconst base =\n\t\t\t\tbaseUrl ||\n\t\t\t\t( typeof window !== 'undefined'\n\t\t\t\t\t? window.location.origin\n\t\t\t\t\t: 'https://wordpress.org' );\n\t\t\treturn new URL( url, base );\n\t\t} catch ( error ) {\n\t\t\t// If URL construction still fails, it's likely an invalid URL\n\t\t\t// and we should sever the entity link\n\t\t\treturn null;\n\t\t}\n\t};\n\n\tconst originalUrlObj = createUrlObject( originalUrl );\n\tif ( ! originalUrlObj ) {\n\t\treturn true;\n\t}\n\n\tconst newUrlObj = createUrlObject( newUrl, originalUrl );\n\tif ( ! newUrlObj ) {\n\t\treturn true;\n\t}\n\n\t// Move these declarations here, after the null checks\n\tconst originalHostname = originalUrlObj.hostname;\n\tconst newHostname = newUrlObj.hostname;\n\tconst originalPath = normalizePath( getPath( originalUrlObj.toString() ) );\n\tconst newPath = normalizePath( getPath( newUrlObj.toString() ) );\n\n\t// If hostname or path changed, sever the entity link\n\tif ( originalHostname !== newHostname || originalPath !== newPath ) {\n\t\treturn true;\n\t}\n\n\t// Special handling for plain permalinks (query string post IDs)\n\tconst originalP = originalUrlObj.searchParams.get( 'p' );\n\tconst newP = newUrlObj.searchParams.get( 'p' );\n\n\t// If both are plain permalinks (with ?p= or ?page_id=), compare the IDs\n\tif ( originalP && newP && originalP !== newP ) {\n\t\treturn true;\n\t}\n\n\tconst originalPageId = originalUrlObj.searchParams.get( 'page_id' );\n\tconst newPageId = newUrlObj.searchParams.get( 'page_id' );\n\n\tif ( originalPageId && newPageId && originalPageId !== newPageId ) {\n\t\treturn true;\n\t}\n\t// If switching between ?p= and ?page_id=, or one is missing, sever\n\tif ( ( originalP && newPageId ) || ( originalPageId && newP ) ) {\n\t\treturn true;\n\t}\n\n\t// If only query string or fragment changed, preserve the entity link\n\treturn false;\n};\n\n/**\n * @typedef {'post-type'|'custom'|'taxonomy'|'post-type-archive'} WPNavigationLinkKind\n */\n/**\n * Navigation Link Block Attributes\n *\n * @typedef {Object} WPNavigationLinkBlockAttributes\n *\n * @property {string} [label] Link text.\n * @property {WPNavigationLinkKind} [kind] Kind is used to differentiate between term and post ids to check post draft status.\n * @property {string} [type] The type such as post, page, tag, category and other custom types.\n * @property {string} [rel] The relationship of the linked URL.\n * @property {number} [id] A post or term id.\n * @property {boolean} [opensInNewTab] Sets link target to _blank when true.\n * @property {string} [url] Link href.\n * @property {string} [title] Link title attribute.\n */\n/**\n * Link Control onChange handler that updates block attributes when a setting is changed.\n *\n * @param {Object} updatedValue New block attributes to update.\n * @param {Function} setAttributes Block attribute update function.\n * @param {WPNavigationLinkBlockAttributes} blockAttributes Current block attributes.\n */\n\nexport const updateAttributes = (\n\tupdatedValue = {},\n\tsetAttributes,\n\tblockAttributes = {}\n) => {\n\tconst {\n\t\tlabel: originalLabel = '',\n\t\tkind: originalKind = '',\n\t\ttype: originalType = '',\n\t} = blockAttributes;\n\n\tconst {\n\t\ttitle: newLabel = '', // the title of any provided Post.\n\t\tlabel: newLabelFromLabel = '', // alternative to title\n\t\turl: newUrl,\n\t\topensInNewTab,\n\t\tid: newID,\n\t\tkind: newKind = originalKind,\n\t\ttype: newType = originalType,\n\t} = updatedValue;\n\n\t// Use title if provided, otherwise fall back to label\n\tconst finalNewLabel = newLabel || newLabelFromLabel;\n\n\tconst newLabelWithoutHttp = finalNewLabel.replace( /http(s?):\\/\\//gi, '' );\n\tconst newUrlWithoutHttp = newUrl?.replace( /http(s?):\\/\\//gi, '' ) ?? '';\n\n\tconst useNewLabel =\n\t\tfinalNewLabel &&\n\t\tfinalNewLabel !== originalLabel &&\n\t\t// LinkControl without the title field relies\n\t\t// on the check below. Specifically, it assumes that\n\t\t// the URL is the same as a title.\n\t\t// This logic a) looks suspicious and b) should really\n\t\t// live in the LinkControl and not here. It's a great\n\t\t// candidate for future refactoring.\n\t\tnewLabelWithoutHttp !== newUrlWithoutHttp;\n\n\t// Unfortunately this causes the escaping model to be inverted.\n\t// The escaped content is stored in the block attributes (and ultimately in the database),\n\t// and then the raw data is \"recovered\" when outputting into the DOM.\n\t// It would be preferable to store the **raw** data in the block attributes and escape it in JS.\n\t// Why? Because there isn't one way to escape data. Depending on the context, you need to do\n\t// different transforms. It doesn't make sense to me to choose one of them for the purposes of storage.\n\t// See also:\n\t// - https://github.com/WordPress/gutenberg/pull/41063\n\t// - https://github.com/WordPress/gutenberg/pull/18617.\n\tconst label = useNewLabel\n\t\t? escapeHTML( finalNewLabel )\n\t\t: originalLabel || escapeHTML( newUrlWithoutHttp );\n\n\t// In https://github.com/WordPress/gutenberg/pull/24670 we decided to use \"tag\" in favor of \"post_tag\"\n\tconst type = newType === 'post_tag' ? 'tag' : newType.replace( '-', '_' );\n\n\tconst isBuiltInType =\n\t\t[ 'post', 'page', 'tag', 'category' ].indexOf( type ) > -1;\n\n\tconst isCustomLink =\n\t\t( ! newKind && ! isBuiltInType ) || newKind === 'custom';\n\tconst kind = isCustomLink ? 'custom' : newKind;\n\n\tconst attributes = {\n\t\t// Passed `url` may already be encoded. To prevent double encoding, decodeURI is executed to revert to the original string.\n\t\t...( newUrl !== undefined\n\t\t\t? { url: newUrl ? encodeURI( safeDecodeURI( newUrl ) ) : newUrl }\n\t\t\t: {} ),\n\t\t...( label && { label } ),\n\t\t...( undefined !== opensInNewTab && { opensInNewTab } ),\n\t\t...( kind && { kind } ),\n\t\t...( type && type !== 'URL' && { type } ),\n\t};\n\n\t// If the block's id is set then the menu item is linking to an entity.\n\t// Therefore, if the URL is set but a new ID is not provided, check if\n\t// the entity link should be severed based on URL changes.\n\tif ( newUrl && ! newID && blockAttributes.id ) {\n\t\tconst shouldSever = shouldSeverEntityLink(\n\t\t\tblockAttributes.url,\n\t\t\tnewUrl\n\t\t);\n\n\t\tif ( shouldSever ) {\n\t\t\tattributes.id = undefined; // explicitly \"unset\" the ID.\n\t\t\t// When URL is manually changed in a way that severs the entity link,\n\t\t\t// update kind and type to \"custom\" to indicate this is now a custom link.\n\t\t\tattributes.kind = 'custom';\n\t\t\tattributes.type = 'custom';\n\t\t}\n\t} else if ( newID && Number.isInteger( newID ) ) {\n\t\tattributes.id = newID;\n\t} else if ( blockAttributes.id ) {\n\t\t// If we have an existing ID and no URL change, ensure kind and type are preserved\n\t\tattributes.kind = kind;\n\t\tattributes.type = type;\n\t}\n\n\tsetAttributes( attributes );\n\n\t// Return metadata about the final state for binding decisions.\n\t// We need to distinguish between:\n\t// 1. Property not set in attributes (use blockAttributes fallback)\n\t// 2. Property explicitly set to undefined (means \"remove this\")\n\t// Using 'in' operator checks if property exists, even if undefined.\n\t// This is critical for severing: attributes.id = undefined means \"remove the ID\",\n\t// not \"keep the old ID from blockAttributes\".\n\tconst finalId = 'id' in attributes ? attributes.id : blockAttributes.id;\n\tconst finalKind =\n\t\t'kind' in attributes ? attributes.kind : blockAttributes.kind;\n\n\treturn {\n\t\tisEntityLink: !! finalId && finalKind !== 'custom',\n\t};\n};\n"],
|
|
5
|
-
"mappings": "AAGA,SAAS,kBAAkB;AAC3B,SAAS,eAAe,eAAe;AASvC,MAAM,wBAAwB,CAAE,aAAa,WAAY;AACxD,MAAK,CAAE,eAAe,CAAE,QAAS;AAChC,WAAO;AAAA,EACR;AAEA,QAAM,gBAAgB,CAAE,SAAU;AACjC,QAAK,CAAE,MAAO;AACb,aAAO;AAAA,IACR;AACA,WAAO,KAAK,QAAS,QAAQ,EAAG;AAAA,EACjC;AAGA,QAAM,kBAAkB,CAAE,KAAK,UAAU,SAAU;AAClD,QAAI;AAGH,YAAM,OACL,YACE,OAAO,WAAW,cACjB,OAAO,SAAS,SACh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ACL,UAAU,aAAa,WAAW,OAAO,gBAAgB;AAE1D,SAAO;AAAA,IACN,cAAc,CAAC,CAAE,WAAW,cAAc;AAAA,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { escapeHTML } from '@wordpress/escape-html';\nimport { safeDecodeURI, getPath } from '@wordpress/url';\n\n/**\n * Determines if an entity link should be severed based on URL changes.\n *\n * @param {string} originalUrl - The original URL\n * @param {string} newUrl - The new URL\n * @return {boolean} True if the entity link should be severed\n */\nconst shouldSeverEntityLink = ( originalUrl, newUrl ) => {\n\tif ( ! originalUrl || ! newUrl ) {\n\t\treturn false;\n\t}\n\n\tconst normalizePath = ( path ) => {\n\t\tif ( ! path ) {\n\t\t\treturn '';\n\t\t}\n\t\treturn path.replace( /\\/+$/, '' ); // Remove trailing slashes\n\t};\n\n\t// Helper function to create URL objects with proper base handling\n\tconst createUrlObject = ( url, baseUrl = null ) => {\n\t\ttry {\n\t\t\t// Always provide a base URL - it will be ignored for absolute URLs\n\t\t\t// Use window.location.origin in browser, fallback for Node/tests\n\t\t\tconst base =\n\t\t\t\tbaseUrl ||\n\t\t\t\t( typeof window !== 'undefined'\n\t\t\t\t\t? window.location.origin\n\t\t\t\t\t: 'https://wordpress.org' );\n\t\t\treturn new URL( url, base );\n\t\t} catch ( error ) {\n\t\t\t// If URL construction still fails, it's likely an invalid URL\n\t\t\t// and we should sever the entity link\n\t\t\treturn null;\n\t\t}\n\t};\n\n\tconst originalUrlObj = createUrlObject( originalUrl );\n\tif ( ! originalUrlObj ) {\n\t\treturn true;\n\t}\n\n\tconst newUrlObj = createUrlObject( newUrl, originalUrl );\n\tif ( ! newUrlObj ) {\n\t\treturn true;\n\t}\n\n\t// Move these declarations here, after the null checks\n\tconst originalHostname = originalUrlObj.hostname;\n\tconst newHostname = newUrlObj.hostname;\n\tconst originalPath = normalizePath( getPath( originalUrlObj.toString() ) );\n\tconst newPath = normalizePath( getPath( newUrlObj.toString() ) );\n\n\t// If hostname or path changed, sever the entity link\n\tif ( originalHostname !== newHostname || originalPath !== newPath ) {\n\t\treturn true;\n\t}\n\n\t// Special handling for plain permalinks (query string post IDs)\n\tconst originalP = originalUrlObj.searchParams.get( 'p' );\n\tconst newP = newUrlObj.searchParams.get( 'p' );\n\n\t// If both are plain permalinks (with ?p= or ?page_id=), compare the IDs\n\tif ( originalP && newP && originalP !== newP ) {\n\t\treturn true;\n\t}\n\n\tconst originalPageId = originalUrlObj.searchParams.get( 'page_id' );\n\tconst newPageId = newUrlObj.searchParams.get( 'page_id' );\n\n\tif ( originalPageId && newPageId && originalPageId !== newPageId ) {\n\t\treturn true;\n\t}\n\t// If switching between ?p= and ?page_id=, or one is missing, sever\n\tif ( ( originalP && newPageId ) || ( originalPageId && newP ) ) {\n\t\treturn true;\n\t}\n\n\t// If only query string or fragment changed, preserve the entity link\n\treturn false;\n};\n\n/**\n * @typedef {'post-type'|'custom'|'taxonomy'|'post-type-archive'} WPNavigationLinkKind\n */\n/**\n * Navigation Link Block Attributes\n *\n * @typedef {Object} WPNavigationLinkBlockAttributes\n *\n * @property {string} [label] Link text.\n * @property {WPNavigationLinkKind} [kind] Kind is used to differentiate between term and post ids to check post draft status.\n * @property {string} [type] The type such as post, page, tag, category and other custom types.\n * @property {string} [rel] The relationship of the linked URL.\n * @property {number} [id] A post or term id.\n * @property {boolean} [opensInNewTab] Sets link target to _blank when true.\n * @property {string} [url] Link href.\n * @property {string} [title] Link title attribute.\n */\n/**\n * Link Control onChange handler that updates block attributes when a setting is changed.\n *\n * @param {Object} updatedValue New block attributes to update.\n * @param {Function} setAttributes Block attribute update function.\n * @param {WPNavigationLinkBlockAttributes} blockAttributes Current block attributes.\n */\n\nexport const updateAttributes = (\n\tupdatedValue = {},\n\tsetAttributes,\n\tblockAttributes = {}\n) => {\n\tconst {\n\t\tlabel: originalLabel = '',\n\t\tkind: originalKind = '',\n\t\ttype: originalType = '',\n\t} = blockAttributes;\n\n\tconst {\n\t\ttitle: newLabel = '', // the title of any provided Post.\n\t\tlabel: newLabelFromLabel = '', // alternative to title\n\t\turl: newUrl,\n\t\topensInNewTab,\n\t\tid: newID,\n\t\tkind: newKind = originalKind,\n\t\ttype: newType = originalType,\n\t} = updatedValue;\n\n\t// Use title if provided, otherwise fall back to label\n\tconst finalNewLabel = newLabel || newLabelFromLabel;\n\n\tconst newLabelWithoutHttp = finalNewLabel.replace( /http(s?):\\/\\//gi, '' );\n\tconst newUrlWithoutHttp = newUrl?.replace( /http(s?):\\/\\//gi, '' ) ?? '';\n\n\tconst useNewLabel =\n\t\tfinalNewLabel &&\n\t\tfinalNewLabel !== originalLabel &&\n\t\t// LinkControl without the title field relies\n\t\t// on the check below. Specifically, it assumes that\n\t\t// the URL is the same as a title.\n\t\t// This logic a) looks suspicious and b) should really\n\t\t// live in the LinkControl and not here. It's a great\n\t\t// candidate for future refactoring.\n\t\tnewLabelWithoutHttp !== newUrlWithoutHttp;\n\n\t// Unfortunately this causes the escaping model to be inverted.\n\t// The escaped content is stored in the block attributes (and ultimately in the database),\n\t// and then the raw data is \"recovered\" when outputting into the DOM.\n\t// It would be preferable to store the **raw** data in the block attributes and escape it in JS.\n\t// Why? Because there isn't one way to escape data. Depending on the context, you need to do\n\t// different transforms. It doesn't make sense to me to choose one of them for the purposes of storage.\n\t// See also:\n\t// - https://github.com/WordPress/gutenberg/pull/41063\n\t// - https://github.com/WordPress/gutenberg/pull/18617.\n\tconst label = useNewLabel\n\t\t? escapeHTML( finalNewLabel )\n\t\t: originalLabel || escapeHTML( newUrlWithoutHttp );\n\n\t// In https://github.com/WordPress/gutenberg/pull/24670 we decided to use \"tag\" in favor of \"post_tag\"\n\tconst type = newType === 'post_tag' ? 'tag' : newType.replace( '-', '_' );\n\n\tconst isBuiltInType =\n\t\t[ 'post', 'page', 'tag', 'category' ].indexOf( type ) > -1;\n\n\tconst isCustomLink =\n\t\t( ! newKind && ! isBuiltInType ) || newKind === 'custom';\n\tconst kind = isCustomLink ? 'custom' : newKind;\n\n\tconst attributes = {\n\t\t// Passed `url` may already be encoded. To prevent double encoding, decodeURI is executed to revert to the original string.\n\t\t...( newUrl !== undefined\n\t\t\t? { url: newUrl ? encodeURI( safeDecodeURI( newUrl ) ) : newUrl }\n\t\t\t: {} ),\n\t\t...( label && { label } ),\n\t\t...( undefined !== opensInNewTab && { opensInNewTab } ),\n\t\t...( kind && { kind } ),\n\t\t...( type && type !== 'URL' && { type } ),\n\t};\n\n\t// If the block's id is set then the menu item is linking to an entity.\n\t// Therefore, if the URL is set but a new ID is not provided, check if\n\t// the entity link should be severed based on URL changes.\n\tif ( newUrl && ! newID && blockAttributes.id ) {\n\t\tconst shouldSever = shouldSeverEntityLink(\n\t\t\tblockAttributes.url,\n\t\t\tnewUrl\n\t\t);\n\n\t\tif ( shouldSever ) {\n\t\t\tattributes.id = undefined; // explicitly \"unset\" the ID.\n\t\t\t// When URL is manually changed in a way that severs the entity link,\n\t\t\t// update kind and type to \"custom\" to indicate this is now a custom link.\n\t\t\tattributes.kind = 'custom';\n\t\t\tattributes.type = 'custom';\n\t\t}\n\t} else if ( newID && Number.isInteger( newID ) ) {\n\t\tattributes.id = newID;\n\t} else if ( blockAttributes.id ) {\n\t\t// If we have an existing ID and no URL change, ensure kind and type are preserved\n\t\tattributes.kind = kind;\n\t\tattributes.type = type;\n\t}\n\n\tsetAttributes( attributes );\n\n\t// Return metadata about the final state for binding decisions.\n\t// We need to distinguish between:\n\t// 1. Property not set in attributes (use blockAttributes fallback)\n\t// 2. Property explicitly set to undefined (means \"remove this\")\n\t// Using 'in' operator checks if property exists, even if undefined.\n\t// This is critical for severing: attributes.id = undefined means \"remove the ID\",\n\t// not \"keep the old ID from blockAttributes\".\n\tconst finalId = 'id' in attributes ? attributes.id : blockAttributes.id;\n\tconst finalKind =\n\t\t'kind' in attributes ? attributes.kind : blockAttributes.kind;\n\n\treturn {\n\t\tisEntityLink: !! finalId && finalKind !== 'custom',\n\t\tattributes, // Return the computed attributes object\n\t};\n};\n"],
|
|
5
|
+
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AAK;AAC9C,UAAM,cAAc;AAAA,MACnB,gBAAgB;AAAA,MAChB;AAAA,IACD;AAEA,QAAK,aAAc;AAClB,iBAAW,KAAK;AAGhB,iBAAW,OAAO;AAClB,iBAAW,OAAO;AAAA,IACnB;AAAA,EACD,WAAY,SAAS,OAAO,UAAW,KAAM,GAAI;AAChD,eAAW,KAAK;AAAA,EACjB,WAAY,gBAAgB,IAAK;AAEhC,eAAW,OAAO;AAClB,eAAW,OAAO;AAAA,EACnB;AAEA,gBAAe,UAAW;AAS1B,QAAM,UAAU,QAAQ,aAAa,WAAW,KAAK,gBAAgB;AACrE,QAAM,YACL,UAAU,aAAa,WAAW,OAAO,gBAAgB;AAE1D,SAAO;AAAA,IACN,cAAc,CAAC,CAAE,WAAW,cAAc;AAAA,IAC1C;AAAA;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,31 +1,63 @@
|
|
|
1
1
|
import { useCallback } from "@wordpress/element";
|
|
2
2
|
import { useBlockBindingsUtils } from "@wordpress/block-editor";
|
|
3
|
+
function buildNavigationLinkEntityBinding(kind) {
|
|
4
|
+
if (kind === void 0) {
|
|
5
|
+
throw new Error(
|
|
6
|
+
'buildNavigationLinkEntityBinding requires a kind parameter. Only "post-type" and "taxonomy" are supported.'
|
|
7
|
+
);
|
|
8
|
+
}
|
|
9
|
+
if (kind !== "post-type" && kind !== "taxonomy") {
|
|
10
|
+
throw new Error(
|
|
11
|
+
`Invalid kind "${kind}" provided to buildNavigationLinkEntityBinding. Only 'post-type' and 'taxonomy' are supported.`
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
const source = kind === "taxonomy" ? "core/term-data" : "core/post-data";
|
|
15
|
+
return {
|
|
16
|
+
url: {
|
|
17
|
+
source,
|
|
18
|
+
args: {
|
|
19
|
+
field: "link"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
3
24
|
function useEntityBinding({ clientId, attributes }) {
|
|
4
25
|
const { updateBlockBindings } = useBlockBindingsUtils(clientId);
|
|
5
|
-
const { metadata, id } = attributes;
|
|
6
|
-
const hasUrlBinding = metadata?.bindings?.url
|
|
26
|
+
const { metadata, id, kind } = attributes;
|
|
27
|
+
const hasUrlBinding = !!metadata?.bindings?.url && !!id;
|
|
28
|
+
const expectedSource = kind === "post-type" ? "core/post-data" : "core/term-data";
|
|
29
|
+
const hasCorrectBinding = hasUrlBinding && metadata?.bindings?.url?.source === expectedSource;
|
|
7
30
|
const clearBinding = useCallback(() => {
|
|
8
31
|
if (hasUrlBinding) {
|
|
9
32
|
updateBlockBindings({ url: void 0 });
|
|
10
33
|
}
|
|
11
|
-
}, [hasUrlBinding,
|
|
12
|
-
const createBinding = useCallback(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
34
|
+
}, [updateBlockBindings, hasUrlBinding, metadata, id]);
|
|
35
|
+
const createBinding = useCallback(
|
|
36
|
+
(updatedAttributes) => {
|
|
37
|
+
const kindToUse = updatedAttributes?.kind ?? kind;
|
|
38
|
+
if (!kindToUse) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const binding = buildNavigationLinkEntityBinding(kindToUse);
|
|
43
|
+
updateBlockBindings(binding);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.warn(
|
|
46
|
+
"Failed to create entity binding:",
|
|
47
|
+
error.message
|
|
48
|
+
);
|
|
19
49
|
}
|
|
20
|
-
}
|
|
21
|
-
|
|
50
|
+
},
|
|
51
|
+
[updateBlockBindings, kind, id]
|
|
52
|
+
);
|
|
22
53
|
return {
|
|
23
|
-
hasUrlBinding,
|
|
54
|
+
hasUrlBinding: hasCorrectBinding,
|
|
24
55
|
clearBinding,
|
|
25
56
|
createBinding
|
|
26
57
|
};
|
|
27
58
|
}
|
|
28
59
|
export {
|
|
60
|
+
buildNavigationLinkEntityBinding,
|
|
29
61
|
useEntityBinding
|
|
30
62
|
};
|
|
31
63
|
//# sourceMappingURL=use-entity-binding.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/navigation-link/shared/use-entity-binding.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback } from '@wordpress/element';\nimport { useBlockBindingsUtils } from '@wordpress/block-editor';\n\n/**\n * Shared hook for entity binding functionality in Navigation blocks.\n *\n * This hook provides common entity binding logic that can be used by both\n * Navigation Link and Navigation Submenu blocks to maintain feature parity.\n *\n * @param {Object} props - Hook parameters\n * @param {string} props.clientId - Block client ID\n * @param {Object} props.attributes - Block attributes\n * @return {Object} Hook return value\n */\nexport function useEntityBinding( { clientId, attributes } ) {\n\tconst { updateBlockBindings } = useBlockBindingsUtils( clientId );\n\tconst { metadata, id } = attributes;\n\n\
|
|
5
|
-
"mappings": "AAGA,SAAS,mBAAmB;AAC5B,SAAS,6BAA6B;AAa/B,SAAS,iBAAkB,EAAE,UAAU,WAAW,GAAI;AAC5D,QAAM,EAAE,oBAAoB,IAAI,sBAAuB,QAAS;AAChE,QAAM,EAAE,UAAU,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback } from '@wordpress/element';\nimport { useBlockBindingsUtils } from '@wordpress/block-editor';\n\n/**\n * Builds entity binding configuration for navigation link URLs.\n * This function generates the structure used to bind navigation link URLs to their entity sources.\n *\n * Using a function instead of a constant allows for future enhancements where the binding\n * might need dynamic data (e.g., entity ID, context-specific arguments).\n *\n * @param {('post-type'|'taxonomy')} kind - The kind of entity. Only 'post-type' and 'taxonomy' are supported.\n * @return {Object} Entity binding configuration object\n * @throws {Error} If kind is not 'post-type' or 'taxonomy'\n */\nexport function buildNavigationLinkEntityBinding( kind ) {\n\t// Validate kind parameter exists\n\tif ( kind === undefined ) {\n\t\tthrow new Error(\n\t\t\t'buildNavigationLinkEntityBinding requires a kind parameter. ' +\n\t\t\t\t'Only \"post-type\" and \"taxonomy\" are supported.'\n\t\t);\n\t}\n\n\t// Validate kind parameter value\n\tif ( kind !== 'post-type' && kind !== 'taxonomy' ) {\n\t\tthrow new Error(\n\t\t\t`Invalid kind \"${ kind }\" provided to buildNavigationLinkEntityBinding. ` +\n\t\t\t\t`Only 'post-type' and 'taxonomy' are supported.`\n\t\t);\n\t}\n\n\tconst source = kind === 'taxonomy' ? 'core/term-data' : 'core/post-data';\n\n\treturn {\n\t\turl: {\n\t\t\tsource,\n\t\t\targs: {\n\t\t\t\tfield: 'link',\n\t\t\t},\n\t\t},\n\t};\n}\n\n/**\n * Shared hook for entity binding functionality in Navigation blocks.\n *\n * This hook provides common entity binding logic that can be used by both\n * Navigation Link and Navigation Submenu blocks to maintain feature parity.\n *\n * @param {Object} props - Hook parameters\n * @param {string} props.clientId - Block client ID\n * @param {Object} props.attributes - Block attributes\n * @return {Object} Hook return value\n */\nexport function useEntityBinding( { clientId, attributes } ) {\n\tconst { updateBlockBindings } = useBlockBindingsUtils( clientId );\n\tconst { metadata, id, kind } = attributes;\n\n\tconst hasUrlBinding = !! metadata?.bindings?.url && !! id;\n\tconst expectedSource =\n\t\tkind === 'post-type' ? 'core/post-data' : 'core/term-data';\n\tconst hasCorrectBinding =\n\t\thasUrlBinding && metadata?.bindings?.url?.source === expectedSource;\n\n\tconst clearBinding = useCallback( () => {\n\t\tif ( hasUrlBinding ) {\n\t\t\tupdateBlockBindings( { url: undefined } );\n\t\t}\n\t}, [ updateBlockBindings, hasUrlBinding, metadata, id ] );\n\n\tconst createBinding = useCallback(\n\t\t( updatedAttributes ) => {\n\t\t\t// Use updated attributes if provided, otherwise fall back to closure attributes\n\t\t\t// updatedAttributes needed to access the most up-to-date data when called synchronously\n\t\t\tconst kindToUse = updatedAttributes?.kind ?? kind;\n\n\t\t\t// Avoid creating binding if no kind is provided\n\t\t\tif ( ! kindToUse ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst binding = buildNavigationLinkEntityBinding( kindToUse );\n\t\t\t\tupdateBlockBindings( binding );\n\t\t\t} catch ( error ) {\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.warn(\n\t\t\t\t\t'Failed to create entity binding:',\n\t\t\t\t\terror.message\n\t\t\t\t);\n\t\t\t\t// Don't create binding if validation fails\n\t\t\t}\n\t\t},\n\t\t[ updateBlockBindings, kind, id ]\n\t);\n\n\treturn {\n\t\thasUrlBinding: hasCorrectBinding,\n\t\tclearBinding,\n\t\tcreateBinding,\n\t};\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,mBAAmB;AAC5B,SAAS,6BAA6B;AAa/B,SAAS,iCAAkC,MAAO;AAExD,MAAK,SAAS,QAAY;AACzB,UAAM,IAAI;AAAA,MACT;AAAA,IAED;AAAA,EACD;AAGA,MAAK,SAAS,eAAe,SAAS,YAAa;AAClD,UAAM,IAAI;AAAA,MACT,iBAAkB,IAAK;AAAA,IAExB;AAAA,EACD;AAEA,QAAM,SAAS,SAAS,aAAa,mBAAmB;AAExD,SAAO;AAAA,IACN,KAAK;AAAA,MACJ;AAAA,MACA,MAAM;AAAA,QACL,OAAO;AAAA,MACR;AAAA,IACD;AAAA,EACD;AACD;AAaO,SAAS,iBAAkB,EAAE,UAAU,WAAW,GAAI;AAC5D,QAAM,EAAE,oBAAoB,IAAI,sBAAuB,QAAS;AAChE,QAAM,EAAE,UAAU,IAAI,KAAK,IAAI;AAE/B,QAAM,gBAAgB,CAAC,CAAE,UAAU,UAAU,OAAO,CAAC,CAAE;AACvD,QAAM,iBACL,SAAS,cAAc,mBAAmB;AAC3C,QAAM,oBACL,iBAAiB,UAAU,UAAU,KAAK,WAAW;AAEtD,QAAM,eAAe,YAAa,MAAM;AACvC,QAAK,eAAgB;AACpB,0BAAqB,EAAE,KAAK,OAAU,CAAE;AAAA,IACzC;AAAA,EACD,GAAG,CAAE,qBAAqB,eAAe,UAAU,EAAG,CAAE;AAExD,QAAM,gBAAgB;AAAA,IACrB,CAAE,sBAAuB;AAGxB,YAAM,YAAY,mBAAmB,QAAQ;AAG7C,UAAK,CAAE,WAAY;AAClB;AAAA,MACD;AAEA,UAAI;AACH,cAAM,UAAU,iCAAkC,SAAU;AAC5D,4BAAqB,OAAQ;AAAA,MAC9B,SAAU,OAAQ;AAEjB,gBAAQ;AAAA,UACP;AAAA,UACA,MAAM;AAAA,QACP;AAAA,MAED;AAAA,IACD;AAAA,IACA,CAAE,qBAAqB,MAAM,EAAG;AAAA,EACjC;AAEA,SAAO;AAAA,IACN,eAAe;AAAA,IACf;AAAA,IACA;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -297,15 +297,18 @@ function NavigationSubmenuEdit({
|
|
|
297
297
|
speak(__("Link removed."), "assertive");
|
|
298
298
|
},
|
|
299
299
|
onChange: (updatedValue) => {
|
|
300
|
-
const {
|
|
300
|
+
const {
|
|
301
|
+
isEntityLink,
|
|
302
|
+
attributes: updatedAttributes
|
|
303
|
+
} = updateAttributes(
|
|
301
304
|
updatedValue,
|
|
302
305
|
setAttributes,
|
|
303
306
|
attributes
|
|
304
307
|
);
|
|
305
308
|
if (isEntityLink) {
|
|
306
|
-
createBinding();
|
|
309
|
+
createBinding(updatedAttributes);
|
|
307
310
|
} else {
|
|
308
|
-
clearBinding();
|
|
311
|
+
clearBinding(updatedAttributes);
|
|
309
312
|
}
|
|
310
313
|
}
|
|
311
314
|
}
|