@wordpress/block-library 9.43.0 → 9.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/code/edit.cjs +2 -1
  3. package/build/code/edit.cjs.map +2 -2
  4. package/build/cover/edit/color-utils.cjs +1 -1
  5. package/build/cover/edit/color-utils.cjs.map +2 -2
  6. package/build/cover/edit/index.cjs +39 -26
  7. package/build/cover/edit/index.cjs.map +2 -2
  8. package/build/cover/embed-video-utils.cjs +9 -7
  9. package/build/cover/embed-video-utils.cjs.map +2 -2
  10. package/build/embed/embed-preview.cjs +2 -1
  11. package/build/embed/embed-preview.cjs.map +2 -2
  12. package/build/file/utils/index.cjs +1 -1
  13. package/build/file/utils/index.cjs.map +2 -2
  14. package/build/form/view.cjs +1 -1
  15. package/build/form/view.cjs.map +2 -2
  16. package/build/icon/edit.cjs +1 -3
  17. package/build/icon/edit.cjs.map +2 -2
  18. package/build/image/image.cjs +32 -9
  19. package/build/image/image.cjs.map +2 -2
  20. package/build/navigation-link/link-ui/index.cjs +12 -1
  21. package/build/navigation-link/link-ui/index.cjs.map +2 -2
  22. package/build/navigation-link/link-ui/page-creator.cjs +1 -1
  23. package/build/navigation-link/link-ui/page-creator.cjs.map +2 -2
  24. package/build/navigation-link/shared/update-attributes.cjs +1 -1
  25. package/build/navigation-link/shared/update-attributes.cjs.map +2 -2
  26. package/build/navigation-link/shared/use-link-preview.cjs +1 -1
  27. package/build/navigation-link/shared/use-link-preview.cjs.map +2 -2
  28. package/build/paragraph/use-enter.cjs +4 -5
  29. package/build/paragraph/use-enter.cjs.map +2 -2
  30. package/build/pattern/edit.cjs +1 -1
  31. package/build/pattern/edit.cjs.map +2 -2
  32. package/build/search/block.json +5 -5
  33. package/build/search/edit.cjs +8 -33
  34. package/build/search/edit.cjs.map +2 -2
  35. package/build/separator/transforms.cjs +12 -4
  36. package/build/separator/transforms.cjs.map +2 -2
  37. package/build/tab/add-tab-toolbar-control.cjs +5 -17
  38. package/build/tab/add-tab-toolbar-control.cjs.map +2 -2
  39. package/build/tab/block.json +2 -1
  40. package/build/tab/remove-tab-toolbar-control.cjs +1 -4
  41. package/build/tab/remove-tab-toolbar-control.cjs.map +2 -2
  42. package/build/tabs/edit.cjs +45 -45
  43. package/build/tabs/edit.cjs.map +2 -2
  44. package/build/tabs-menu/block.json +1 -2
  45. package/build/tabs-menu-item/block.json +0 -6
  46. package/build/tabs-menu-item/edit.cjs +2 -8
  47. package/build/tabs-menu-item/edit.cjs.map +2 -2
  48. package/build-module/code/edit.mjs +2 -1
  49. package/build-module/code/edit.mjs.map +2 -2
  50. package/build-module/cover/edit/color-utils.mjs +1 -1
  51. package/build-module/cover/edit/color-utils.mjs.map +2 -2
  52. package/build-module/cover/edit/index.mjs +47 -29
  53. package/build-module/cover/edit/index.mjs.map +2 -2
  54. package/build-module/cover/embed-video-utils.mjs +8 -6
  55. package/build-module/cover/embed-video-utils.mjs.map +2 -2
  56. package/build-module/embed/embed-preview.mjs +2 -1
  57. package/build-module/embed/embed-preview.mjs.map +2 -2
  58. package/build-module/file/utils/index.mjs +1 -1
  59. package/build-module/file/utils/index.mjs.map +2 -2
  60. package/build-module/form/view.mjs +1 -1
  61. package/build-module/form/view.mjs.map +2 -2
  62. package/build-module/icon/edit.mjs +1 -3
  63. package/build-module/icon/edit.mjs.map +2 -2
  64. package/build-module/image/image.mjs +32 -9
  65. package/build-module/image/image.mjs.map +2 -2
  66. package/build-module/navigation-link/link-ui/index.mjs +12 -1
  67. package/build-module/navigation-link/link-ui/index.mjs.map +2 -2
  68. package/build-module/navigation-link/link-ui/page-creator.mjs +1 -1
  69. package/build-module/navigation-link/link-ui/page-creator.mjs.map +2 -2
  70. package/build-module/navigation-link/shared/update-attributes.mjs +1 -1
  71. package/build-module/navigation-link/shared/update-attributes.mjs.map +2 -2
  72. package/build-module/navigation-link/shared/use-link-preview.mjs +1 -1
  73. package/build-module/navigation-link/shared/use-link-preview.mjs.map +2 -2
  74. package/build-module/paragraph/use-enter.mjs +4 -5
  75. package/build-module/paragraph/use-enter.mjs.map +2 -2
  76. package/build-module/pattern/edit.mjs +1 -1
  77. package/build-module/pattern/edit.mjs.map +2 -2
  78. package/build-module/search/block.json +5 -5
  79. package/build-module/search/edit.mjs +8 -33
  80. package/build-module/search/edit.mjs.map +2 -2
  81. package/build-module/separator/transforms.mjs +17 -5
  82. package/build-module/separator/transforms.mjs.map +2 -2
  83. package/build-module/tab/add-tab-toolbar-control.mjs +6 -18
  84. package/build-module/tab/add-tab-toolbar-control.mjs.map +2 -2
  85. package/build-module/tab/block.json +2 -1
  86. package/build-module/tab/remove-tab-toolbar-control.mjs +1 -4
  87. package/build-module/tab/remove-tab-toolbar-control.mjs.map +2 -2
  88. package/build-module/tabs/edit.mjs +45 -45
  89. package/build-module/tabs/edit.mjs.map +2 -2
  90. package/build-module/tabs-menu/block.json +1 -2
  91. package/build-module/tabs-menu-item/block.json +0 -6
  92. package/build-module/tabs-menu-item/edit.mjs +3 -9
  93. package/build-module/tabs-menu-item/edit.mjs.map +2 -2
  94. package/build-style/code/style-rtl.css +1 -1
  95. package/build-style/code/style.css +1 -1
  96. package/build-style/post-author-biography/style-rtl.css +1 -0
  97. package/build-style/post-author-biography/style.css +1 -0
  98. package/build-style/style-rtl.css +11 -16
  99. package/build-style/style.css +11 -16
  100. package/build-style/tabs-menu-item/style-rtl.css +9 -6
  101. package/build-style/tabs-menu-item/style.css +9 -6
  102. package/package.json +38 -38
  103. package/src/code/edit.js +1 -0
  104. package/src/code/style.scss +1 -1
  105. package/src/cover/edit/color-utils.js +1 -1
  106. package/src/cover/edit/index.js +72 -35
  107. package/src/cover/embed-video-utils.js +10 -8
  108. package/src/embed/embed-preview.js +6 -5
  109. package/src/embed/test/index.native.js +3 -2
  110. package/src/file/utils/index.js +1 -1
  111. package/src/form/view.js +1 -1
  112. package/src/icon/edit.js +1 -3
  113. package/src/image/image.js +56 -9
  114. package/src/image/index.php +4 -4
  115. package/src/navigation-link/link-ui/index.js +12 -1
  116. package/src/navigation-link/link-ui/page-creator.js +1 -1
  117. package/src/navigation-link/shared/update-attributes.js +1 -1
  118. package/src/navigation-link/shared/use-link-preview.js +1 -1
  119. package/src/paragraph/use-enter.js +5 -5
  120. package/src/pattern/edit.js +1 -1
  121. package/src/post-author-biography/style.scss +1 -0
  122. package/src/search/block.json +5 -5
  123. package/src/search/edit.js +4 -35
  124. package/src/search/index.php +23 -3
  125. package/src/separator/transforms.js +19 -5
  126. package/src/style.scss +0 -1
  127. package/src/tab/add-tab-toolbar-control.js +24 -42
  128. package/src/tab/block.json +2 -1
  129. package/src/tab/index.php +21 -4
  130. package/src/tab/remove-tab-toolbar-control.js +1 -9
  131. package/src/tabs/edit.js +59 -66
  132. package/src/tabs/index.php +14 -15
  133. package/src/tabs-menu/block.json +1 -2
  134. package/src/tabs-menu/index.php +6 -17
  135. package/src/tabs-menu-item/block.json +0 -6
  136. package/src/tabs-menu-item/edit.js +3 -15
  137. package/src/tabs-menu-item/style.scss +10 -8
  138. package/build-style/tabs-menu/style-rtl.css +0 -8
  139. package/build-style/tabs-menu/style.css +0 -8
  140. package/src/tabs-menu/style.scss +0 -8
@@ -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, focus } 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';\nimport { isURL } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { LinkUIPageCreator } from './page-creator';\nimport LinkUIBlockInserter from './block-inserter';\nimport { useEntityBinding, useLinkPreview } from '../shared';\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\t// How many results to show initially and per search.\n\tconst perPage = 20;\n\n\tswitch ( type ) {\n\t\tcase 'post':\n\t\tcase 'page':\n\t\t\treturn { type: 'post', subtype: type, perPage };\n\t\tcase 'category':\n\t\t\treturn { type: 'term', subtype: 'category', perPage };\n\t\tcase 'tag':\n\t\t\treturn { type: 'term', subtype: 'post_tag', perPage };\n\t\tcase 'post_format':\n\t\t\treturn { type: 'post-format', perPage };\n\t\tdefault:\n\t\t\tif ( kind === 'taxonomy' ) {\n\t\t\t\treturn { type: 'term', subtype: type, perPage };\n\t\t\t}\n\t\t\tif ( kind === 'post-type' ) {\n\t\t\t\treturn { type: 'post', subtype: type, perPage };\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,\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 } = props.link;\n\n\tconst { entityRecord, hasBinding, isEntityAvailable } = props.entity || {};\n\n\tconst { image, badges } = useLinkPreview( {\n\t\turl,\n\t\tentityRecord,\n\t\ttype,\n\t\thasBinding,\n\t\tisEntityAvailable,\n\t} );\n\n\tconst { clientId } = props;\n\tconst postType = type || 'page';\n\n\tconst [ addingBlock, setAddingBlock ] = useState( false );\n\tconst [ addingPage, setAddingPage ] = useState( false );\n\tconst [ shouldFocusPane, setShouldFocusPane ] = useState( null );\n\t// Stable initial value for LinkControl's uncontrolled inputValue prop.\n\t// We track the search with the searchInputValueRef, then update the\n\t// initialSearchValue state with the observed searchInputValueRef\n\t// when mounting the LinkControl. If LinkControl becomes a fully\n\t// controlled component, then we can remove this extra complexity.\n\tconst [ initialSearchValue, setInitialSearchValue ] = useState( '' );\n\t// Tracks the live search input between renders without causing re-renders.\n\tconst searchInputValueRef = useRef( '' );\n\t// Call this instead of setting searchInputValueRef.current and\n\t// setInitialSearchValue separately, to keep both in sync.\n\tconst updateSearchValue = ( value ) => {\n\t\tsearchInputValueRef.current = value;\n\t\tsetInitialSearchValue( value );\n\t};\n\tconst linkControlWrapperRef = useRef();\n\tconst addPageButtonRef = useRef();\n\tconst addBlockButtonRef = useRef();\n\tconst permissions = useResourcePermissions( {\n\t\tkind: 'postType',\n\t\tname: postType,\n\t} );\n\n\t// Use the entity binding hook to get binding status\n\tconst { isBoundEntityAvailable } = useEntityBinding( {\n\t\tclientId,\n\t\tattributes: props.link,\n\t} );\n\n\t// Memoize link value to avoid overriding the LinkControl's internal state.\n\t// This is a temporary fix. See https://github.com/WordPress/gutenberg/issues/50976#issuecomment-1568226407.\n\tconst link = useMemo(\n\t\t() => ( {\n\t\t\turl,\n\t\t\topensInNewTab,\n\t\t\ttitle: label && stripHTML( label ),\n\t\t\tkind,\n\t\t\ttype,\n\t\t\tid,\n\t\t\timage,\n\t\t\tbadges,\n\t\t} ),\n\t\t[ label, opensInNewTab, url, kind, type, id, image, badges ]\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 and focus the first focusable element\n\t\tsetAddingPage( false );\n\t\tsetShouldFocusPane( true );\n\t\t// Clear search input value\n\t\tupdateSearchValue( '' );\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\t// Focus management when transitioning between panes\n\tuseEffect( () => {\n\t\tif ( shouldFocusPane && linkControlWrapperRef.current ) {\n\t\t\t// If we have a specific element to focus, focus it\n\t\t\tif ( shouldFocusPane?.current ) {\n\t\t\t\t// Focus the specific element passed\n\t\t\t\tshouldFocusPane.current.focus();\n\t\t\t} else {\n\t\t\t\t// Focus the first tabbable element (keyboard-accessible, excluding tabindex=\"-1\")\n\t\t\t\tconst tabbableElements = focus.tabbable.find(\n\t\t\t\t\tlinkControlWrapperRef.current\n\t\t\t\t);\n\t\t\t\tconst nextFocusTarget =\n\t\t\t\t\ttabbableElements[ 0 ] || linkControlWrapperRef.current;\n\t\t\t\tnextFocusTarget.focus();\n\t\t\t}\n\n\t\t\t// Reset the state\n\t\t\tsetShouldFocusPane( false );\n\t\t}\n\t}, [ shouldFocusPane ] );\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\tref={ linkControlWrapperRef }\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\tonInputChange={ ( value ) => {\n\t\t\t\t\t\t\t// Observe the input value so we can pass the value to the page creator\n\t\t\t\t\t\t\t// and restore it on back button click\n\t\t\t\t\t\t\tsearchInputValueRef.current = value;\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tinputValue={ initialSearchValue }\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={ isBoundEntityAvailable }\n\t\t\t\t\t\tforceIsEditingLink={ link?.url ? false : undefined }\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\taddPageButtonRef={ addPageButtonRef }\n\t\t\t\t\t\t\t\t\taddBlockButtonRef={ addBlockButtonRef }\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} }\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} }\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\tsetShouldFocusPane( addBlockButtonRef );\n\t\t\t\t\t\tupdateSearchValue( searchInputValueRef.current );\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\tsetShouldFocusPane( addPageButtonRef );\n\t\t\t\t\t\tupdateSearchValue( searchInputValueRef.current );\n\t\t\t\t\t} }\n\t\t\t\t\tonPageCreated={ handlePageCreated }\n\t\t\t\t\tinitialTitle={\n\t\t\t\t\t\tsearchInputValueRef.current &&\n\t\t\t\t\t\t! isURL( searchInputValueRef.current )\n\t\t\t\t\t\t\t? searchInputValueRef.current\n\t\t\t\t\t\t\t: ''\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t) }\n\t\t</Popover>\n\t);\n}\n\nexport const LinkUI = forwardRef( UnforwardedLinkUI );\n\nconst LinkUITools = ( {\n\taddPageButtonRef,\n\taddBlockButtonRef,\n\tsetAddingBlock,\n\tsetAddingPage,\n\tcanAddPage,\n\tcanAddBlock,\n} ) => {\n\tconst blockInserterAriaRole = 'listbox';\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": ";AAGA,SAAS,uBAAuB,WAAW,aAAa;AACxD;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;AAC9B,SAAS,aAAa;AAKtB,SAAS,yBAAyB;AAClC,OAAO,yBAAyB;AAChC,SAAS,kBAAkB,sBAAsB;AAoK5C,SACC,KADD;AA1JE,SAAS,oBAAqB,MAAM,MAAO;AAEjD,QAAM,UAAU;AAEhB,UAAS,M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ependencies\n */\nimport { __unstableStripHTML as stripHTML, focus } 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';\nimport { isURL } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { LinkUIPageCreator } from './page-creator';\nimport LinkUIBlockInserter from './block-inserter';\nimport { useEntityBinding, useLinkPreview } from '../shared';\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\t// How many results to show initially and per search.\n\tconst perPage = 20;\n\n\tswitch ( type ) {\n\t\tcase 'post':\n\t\tcase 'page':\n\t\t\treturn { type: 'post', subtype: type, perPage };\n\t\tcase 'category':\n\t\t\treturn { type: 'term', subtype: 'category', perPage };\n\t\tcase 'tag':\n\t\t\treturn { type: 'term', subtype: 'post_tag', perPage };\n\t\tcase 'post_format':\n\t\t\treturn { type: 'post-format', perPage };\n\t\tdefault:\n\t\t\tif ( kind === 'taxonomy' ) {\n\t\t\t\treturn { type: 'term', subtype: type, perPage };\n\t\t\t}\n\t\t\tif ( kind === 'post-type' ) {\n\t\t\t\treturn { type: 'post', subtype: type, perPage };\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,\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 } = props.link;\n\n\tconst { entityRecord, hasBinding, isEntityAvailable } = props.entity || {};\n\n\tconst { image, badges } = useLinkPreview( {\n\t\turl,\n\t\tentityRecord,\n\t\ttype,\n\t\thasBinding,\n\t\tisEntityAvailable,\n\t} );\n\n\tconst { clientId } = props;\n\tconst postType = type || 'page';\n\n\tconst [ addingBlock, setAddingBlock ] = useState( false );\n\tconst [ addingPage, setAddingPage ] = useState( false );\n\tconst [ shouldFocusPane, setShouldFocusPane ] = useState( null );\n\t// Stable initial value for LinkControl's uncontrolled inputValue prop.\n\t// We track the search with the searchInputValueRef, then update the\n\t// initialSearchValue state with the observed searchInputValueRef\n\t// when mounting the LinkControl. If LinkControl becomes a fully\n\t// controlled component, then we can remove this extra complexity.\n\tconst [ initialSearchValue, setInitialSearchValue ] = useState( '' );\n\t// Tracks the live search input between renders without causing re-renders.\n\tconst searchInputValueRef = useRef( '' );\n\t// Call this instead of setting searchInputValueRef.current and\n\t// setInitialSearchValue separately, to keep both in sync.\n\tconst updateSearchValue = ( value ) => {\n\t\tsearchInputValueRef.current = value;\n\t\tsetInitialSearchValue( value );\n\t};\n\tconst linkControlWrapperRef = useRef();\n\tconst addPageButtonRef = useRef();\n\tconst addBlockButtonRef = useRef();\n\tconst permissions = useResourcePermissions( {\n\t\tkind: 'postType',\n\t\tname: postType,\n\t} );\n\n\t// Use the entity binding hook to get binding status\n\tconst { isBoundEntityAvailable } = useEntityBinding( {\n\t\tclientId,\n\t\tattributes: props.link,\n\t} );\n\n\t// Memoize link value to avoid overriding the LinkControl's internal state.\n\t// This is a temporary fix. See https://github.com/WordPress/gutenberg/issues/50976#issuecomment-1568226407.\n\tconst link = useMemo(\n\t\t() => ( {\n\t\t\turl,\n\t\t\topensInNewTab,\n\t\t\ttitle: label && stripHTML( label ),\n\t\t\tentityTitle: entityRecord?.title?.rendered || entityRecord?.name,\n\t\t\tkind,\n\t\t\ttype,\n\t\t\tid,\n\t\t\timage,\n\t\t\tbadges,\n\t\t} ),\n\t\t[\n\t\t\tlabel,\n\t\t\topensInNewTab,\n\t\t\turl,\n\t\t\tkind,\n\t\t\ttype,\n\t\t\tid,\n\t\t\timage,\n\t\t\tbadges,\n\t\t\tentityRecord,\n\t\t]\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 and focus the first focusable element\n\t\tsetAddingPage( false );\n\t\tsetShouldFocusPane( true );\n\t\t// Clear search input value\n\t\tupdateSearchValue( '' );\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\t// Focus management when transitioning between panes\n\tuseEffect( () => {\n\t\tif ( shouldFocusPane && linkControlWrapperRef.current ) {\n\t\t\t// If we have a specific element to focus, focus it\n\t\t\tif ( shouldFocusPane?.current ) {\n\t\t\t\t// Focus the specific element passed\n\t\t\t\tshouldFocusPane.current.focus();\n\t\t\t} else {\n\t\t\t\t// Focus the first tabbable element (keyboard-accessible, excluding tabindex=\"-1\")\n\t\t\t\tconst tabbableElements = focus.tabbable.find(\n\t\t\t\t\tlinkControlWrapperRef.current\n\t\t\t\t);\n\t\t\t\tconst nextFocusTarget =\n\t\t\t\t\ttabbableElements[ 0 ] || linkControlWrapperRef.current;\n\t\t\t\tnextFocusTarget.focus();\n\t\t\t}\n\n\t\t\t// Reset the state\n\t\t\tsetShouldFocusPane( false );\n\t\t}\n\t}, [ shouldFocusPane ] );\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\tref={ linkControlWrapperRef }\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\tonInputChange={ ( value ) => {\n\t\t\t\t\t\t\t// Observe the input value so we can pass the value to the page creator\n\t\t\t\t\t\t\t// and restore it on back button click\n\t\t\t\t\t\t\tsearchInputValueRef.current = value;\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tinputValue={ initialSearchValue }\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={ isBoundEntityAvailable }\n\t\t\t\t\t\tforceIsEditingLink={ link?.url ? false : undefined }\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\taddPageButtonRef={ addPageButtonRef }\n\t\t\t\t\t\t\t\t\taddBlockButtonRef={ addBlockButtonRef }\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} }\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} }\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\tsetShouldFocusPane( addBlockButtonRef );\n\t\t\t\t\t\tupdateSearchValue( searchInputValueRef.current );\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\tsetShouldFocusPane( addPageButtonRef );\n\t\t\t\t\t\tupdateSearchValue( searchInputValueRef.current );\n\t\t\t\t\t} }\n\t\t\t\t\tonPageCreated={ handlePageCreated }\n\t\t\t\t\tinitialTitle={\n\t\t\t\t\t\tsearchInputValueRef.current &&\n\t\t\t\t\t\t! isURL( searchInputValueRef.current )\n\t\t\t\t\t\t\t? searchInputValueRef.current\n\t\t\t\t\t\t\t: ''\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t) }\n\t\t</Popover>\n\t);\n}\n\nexport const LinkUI = forwardRef( UnforwardedLinkUI );\n\nconst LinkUITools = ( {\n\taddPageButtonRef,\n\taddBlockButtonRef,\n\tsetAddingBlock,\n\tsetAddingPage,\n\tcanAddPage,\n\tcanAddBlock,\n} ) => {\n\tconst blockInserterAriaRole = 'listbox';\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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Ac;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
  }
@@ -75,7 +75,7 @@ function LinkUIPageCreator({
75
75
  );
76
76
  onPageCreated(pageLink);
77
77
  }
78
- } catch (error) {
78
+ } catch {
79
79
  createErrorNotice(
80
80
  __("Failed to create page. Please try again."),
81
81
  {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/navigation-link/link-ui/page-creator.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tTextControl,\n\tNotice,\n\tCheckboxControl,\n\t__experimentalVStack as VStack,\n\t__experimentalHStack as HStack,\n} from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport DialogWrapper from './dialog-wrapper';\n\n/**\n * Component for creating new pages within the Navigation Link UI.\n *\n * @param {Object} props Component props.\n * @param {string} props.postType The post type to create.\n * @param {Function} props.onBack Callback when user wants to go back.\n * @param {Function} props.onPageCreated Callback when page is successfully created.\n * @param {string} [props.initialTitle] Initial title to pre-fill the form.\n */\nexport function LinkUIPageCreator( {\n\tpostType,\n\tonBack,\n\tonPageCreated,\n\tinitialTitle = '',\n} ) {\n\tconst [ title, setTitle ] = useState( initialTitle );\n\tconst [ shouldPublish, setShouldPublish ] = useState( true );\n\n\t// Check if the title is valid for submission\n\tconst isTitleValid = title.trim().length > 0;\n\n\t// Get the last created entity record (without ID) to track creation state\n\tconst { lastError, isSaving } = useSelect(\n\t\t( select ) => ( {\n\t\t\tlastError: select( coreStore ).getLastEntitySaveError(\n\t\t\t\t'postType',\n\t\t\t\tpostType\n\t\t\t),\n\t\t\tisSaving: select( coreStore ).isSavingEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tpostType\n\t\t\t),\n\t\t} ),\n\t\t[ postType ]\n\t);\n\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\n\tasync function createPage( event ) {\n\t\tevent.preventDefault();\n\t\tif ( isSaving || ! isTitleValid ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tconst savedRecord = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tpostType,\n\t\t\t\t{\n\t\t\t\t\ttitle,\n\t\t\t\t\tstatus: shouldPublish ? 'publish' : 'draft',\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\n\t\t\tif ( savedRecord ) {\n\t\t\t\t// Create the page link object from the saved record\n\t\t\t\tconst pageLink = {\n\t\t\t\t\tid: savedRecord.id,\n\t\t\t\t\ttype: postType,\n\t\t\t\t\ttitle: decodeEntities( savedRecord.title.rendered ),\n\t\t\t\t\turl: savedRecord.link,\n\t\t\t\t\tkind: 'post-type',\n\t\t\t\t};\n\n\t\t\t\t// Show success notice\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t// translators: %s: the name of the new page being created.\n\t\t\t\t\t\t__( '%s page created successfully.' ),\n\t\t\t\t\t\tdecodeEntities( savedRecord.title.rendered )\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tid: 'page-created-success',\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\tonPageCreated( pageLink );\n\t\t\t}\n\t\t} catch ( error ) {\n\t\t\t// Show error notice\n\t\t\tcreateErrorNotice(\n\t\t\t\t__( 'Failed to create page. Please try again.' ),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tid: 'page-created-error',\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t}\n\n\tconst isSubmitDisabled = isSaving || ! isTitleValid;\n\n\treturn (\n\t\t<DialogWrapper\n\t\t\tclassName=\"link-ui-page-creator\"\n\t\t\ttitle={ __( 'Create page' ) }\n\t\t\tdescription={ __( 'Create a new page to add to your Navigation.' ) }\n\t\t\tonBack={ onBack }\n\t\t>\n\t\t\t<VStack className=\"link-ui-page-creator__inner\" spacing={ 4 }>\n\t\t\t\t<form onSubmit={ createPage }>\n\t\t\t\t\t<VStack spacing={ 4 }>\n\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tlabel={ __( 'Title' ) }\n\t\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\t\tplaceholder={ __( 'No title' ) }\n\t\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\t/>\n\n\t\t\t\t\t\t<CheckboxControl\n\t\t\t\t\t\t\tlabel={ __( 'Publish' ) }\n\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t\"Turn off to save as a draft. Drafts won't appear on your site until published.\"\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tchecked={ shouldPublish }\n\t\t\t\t\t\t\tonChange={ setShouldPublish }\n\t\t\t\t\t\t/>\n\n\t\t\t\t\t\t{ lastError && (\n\t\t\t\t\t\t\t<Notice status=\"error\" isDismissible={ false }>\n\t\t\t\t\t\t\t\t{ lastError.message }\n\t\t\t\t\t\t\t</Notice>\n\t\t\t\t\t\t) }\n\n\t\t\t\t\t\t<HStack spacing={ 2 } justify=\"flex-end\">\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\t\tonClick={ onBack }\n\t\t\t\t\t\t\t\tdisabled={ isSaving }\n\t\t\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\t\tisBusy={ isSaving }\n\t\t\t\t\t\t\t\taria-disabled={ isSubmitDisabled }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'Create page' ) }\n\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t</HStack>\n\t\t\t\t\t</VStack>\n\t\t\t\t</form>\n\t\t\t</VStack>\n\t\t</DialogWrapper>\n\t);\n}\n"],
5
- "mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,wBAAwB;AAAA,EACxB,wBAAwB;AAAA,OAClB;AACP,SAAS,IAAI,eAAe;AAC5B,SAAS,WAAW,mBAAmB;AACvC,SAAS,SAAS,iBAAiB;AACnC,SAAS,SAAS,oBAAoB;AACtC,SAAS,sBAAsB;AAC/B,SAAS,gBAAgB;AAKzB,OAAO,mBAAmB;AA4GpB,cAuBA,YAvBA;AAjGC,SAAS,kBAA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Notice,\n\tCheckboxControl,\n\t__experimentalVStack as VStack,\n\t__experimentalHStack as HStack,\n} from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport DialogWrapper from './dialog-wrapper';\n\n/**\n * Component for creating new pages within the Navigation Link UI.\n *\n * @param {Object} props Component props.\n * @param {string} props.postType The post type to create.\n * @param {Function} props.onBack Callback when user wants to go back.\n * @param {Function} props.onPageCreated Callback when page is successfully created.\n * @param {string} [props.initialTitle] Initial title to pre-fill the form.\n */\nexport function LinkUIPageCreator( {\n\tpostType,\n\tonBack,\n\tonPageCreated,\n\tinitialTitle = '',\n} ) {\n\tconst [ title, setTitle ] = useState( initialTitle );\n\tconst [ shouldPublish, setShouldPublish ] = useState( true );\n\n\t// Check if the title is valid for submission\n\tconst isTitleValid = title.trim().length > 0;\n\n\t// Get the last created entity record (without ID) to track creation state\n\tconst { lastError, isSaving } = useSelect(\n\t\t( select ) => ( {\n\t\t\tlastError: select( coreStore ).getLastEntitySaveError(\n\t\t\t\t'postType',\n\t\t\t\tpostType\n\t\t\t),\n\t\t\tisSaving: select( coreStore ).isSavingEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tpostType\n\t\t\t),\n\t\t} ),\n\t\t[ postType ]\n\t);\n\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\n\tasync function createPage( event ) {\n\t\tevent.preventDefault();\n\t\tif ( isSaving || ! isTitleValid ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tconst savedRecord = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tpostType,\n\t\t\t\t{\n\t\t\t\t\ttitle,\n\t\t\t\t\tstatus: shouldPublish ? 'publish' : 'draft',\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\n\t\t\tif ( savedRecord ) {\n\t\t\t\t// Create the page link object from the saved record\n\t\t\t\tconst pageLink = {\n\t\t\t\t\tid: savedRecord.id,\n\t\t\t\t\ttype: postType,\n\t\t\t\t\ttitle: decodeEntities( savedRecord.title.rendered ),\n\t\t\t\t\turl: savedRecord.link,\n\t\t\t\t\tkind: 'post-type',\n\t\t\t\t};\n\n\t\t\t\t// Show success notice\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t// translators: %s: the name of the new page being created.\n\t\t\t\t\t\t__( '%s page created successfully.' ),\n\t\t\t\t\t\tdecodeEntities( savedRecord.title.rendered )\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tid: 'page-created-success',\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\tonPageCreated( pageLink );\n\t\t\t}\n\t\t} catch {\n\t\t\t// Show error notice\n\t\t\tcreateErrorNotice(\n\t\t\t\t__( 'Failed to create page. Please try again.' ),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tid: 'page-created-error',\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t}\n\n\tconst isSubmitDisabled = isSaving || ! isTitleValid;\n\n\treturn (\n\t\t<DialogWrapper\n\t\t\tclassName=\"link-ui-page-creator\"\n\t\t\ttitle={ __( 'Create page' ) }\n\t\t\tdescription={ __( 'Create a new page to add to your Navigation.' ) }\n\t\t\tonBack={ onBack }\n\t\t>\n\t\t\t<VStack className=\"link-ui-page-creator__inner\" spacing={ 4 }>\n\t\t\t\t<form onSubmit={ createPage }>\n\t\t\t\t\t<VStack spacing={ 4 }>\n\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tlabel={ __( 'Title' ) }\n\t\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\t\tplaceholder={ __( 'No title' ) }\n\t\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\t/>\n\n\t\t\t\t\t\t<CheckboxControl\n\t\t\t\t\t\t\tlabel={ __( 'Publish' ) }\n\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t\"Turn off to save as a draft. Drafts won't appear on your site until published.\"\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tchecked={ shouldPublish }\n\t\t\t\t\t\t\tonChange={ setShouldPublish }\n\t\t\t\t\t\t/>\n\n\t\t\t\t\t\t{ lastError && (\n\t\t\t\t\t\t\t<Notice status=\"error\" isDismissible={ false }>\n\t\t\t\t\t\t\t\t{ lastError.message }\n\t\t\t\t\t\t\t</Notice>\n\t\t\t\t\t\t) }\n\n\t\t\t\t\t\t<HStack spacing={ 2 } justify=\"flex-end\">\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\t\tonClick={ onBack }\n\t\t\t\t\t\t\t\tdisabled={ isSaving }\n\t\t\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\t\tisBusy={ isSaving }\n\t\t\t\t\t\t\t\taria-disabled={ isSubmitDisabled }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'Create page' ) }\n\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t</HStack>\n\t\t\t\t\t</VStack>\n\t\t\t\t</form>\n\t\t\t</VStack>\n\t\t</DialogWrapper>\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;AAAA,cAEpB,aAAI,QAAS;AAAA;AAAA,UAChB;AAAA,UACA;AAAA,YAAC;AAAA;AAAA,cACA,uBAAqB;AAAA,cACrB,SAAQ;AAAA,cACR,MAAK;AAAA,cACL,QAAS;AAAA,cACT,iBAAgB;AAAA,cAEd,aAAI,aAAc;AAAA;AAAA,UACrB;AAAA,WACD;AAAA,SACD,GACD,GACD;AAAA;AAAA,EACD;AAEF;",
6
6
  "names": []
7
7
  }
@@ -15,7 +15,7 @@ var shouldSeverEntityLink = (originalUrl, newUrl) => {
15
15
  try {
16
16
  const base = baseUrl || (typeof window !== "undefined" ? window.location.origin : "https://wordpress.org");
17
17
  return new URL(url, base);
18
- } catch (error) {
18
+ } catch {
19
19
  return null;
20
20
  }
21
21
  };
@@ -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\tattributes, // Return the computed attributes object\n\t};\n};\n"],
5
- "mappings": ";AAGA,SAAS,kBAAkB;AAC3B,SAAS,eAAe,eAAe;AASvC,IAAM,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,SAChB;AACJ,aAAO,IAAI,IAAK,KAAK,IAAK;AAAA,IAC3B,SAAU,OAAQ;AAGjB,aAAO;AAAA,IACR;AAAA,EACD;AAEA,QAAM,iBAAiB,gBAAiB,WAAY;AACpD,MAAK,CAAE,gBAAiB;AACvB,WAAO;AAAA,EACR;AAEA,QAAM,YAAY,gBAAiB,QAAQ,WAAY;AACvD,MAAK,CAAE,WAAY;AAClB,WAAO;AAAA,EACR;AAGA,QAAM,mBAAmB,eAAe;AACxC,QAAM,cAAc,UAAU;AAC9B,QAAM,eAAe,cAAe,QAAS,eAAe,SAAS,CAAE,CAAE;AACzE,QAAM,UAAU,cAAe,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AE,QAAS,IAAK,IAAI;AAEzD,QAAM,eACH,CAAE,WAAW,CAAE,iBAAmB,YAAY;AACjD,QAAM,OAAO,eAAe,WAAW;AAEvC,QAAM,aAAa;AAAA;AAAA,IAElB,GAAK,WAAW,SACb,EAAE,KAAK,SAAS,UAAW,cAAe,MAAO,CAAE,IAAI,OAAO,IAC9D,CAAC;AAAA,IACJ,GAAK,SAAS,EAAE,MAAM;AAAA,IACtB,GAAK,WAAc,iBAAiB,EAAE,cAAc;AAAA,IACpD,GAAK,QAAQ,EAAE,KAAK;AAAA,IACpB,GAAK,QAAQ,SAAS,SAAS,EAAE,KAAK;AAAA,EACvC;AAKA,MAAK,UAAU,CAAE,SAAS,gBAAgB,IAAK;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;",
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 {\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
+ "mappings": ";AAGA,SAAS,kBAAkB;AAC3B,SAAS,eAAe,eAAe;AASvC,IAAM,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,SAChB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,aAAa,WAAW,OAAO,gBAAgB;AAE1D,SAAO;AAAA,IACN,cAAc,CAAC,CAAE,WAAW,cAAc;AAAA,IAC1C;AAAA;AAAA,EACD;AACD;",
6
6
  "names": []
7
7
  }
@@ -52,7 +52,7 @@ function computeDisplayUrl({ linkUrl, homeUrl } = {}) {
52
52
  } else {
53
53
  isExternal = true;
54
54
  }
55
- } catch (e) {
55
+ } catch {
56
56
  isExternal = true;
57
57
  }
58
58
  return { displayUrl, isExternal };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/navigation-link/shared/use-link-preview.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { safeDecodeURI } from '@wordpress/url';\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreDataStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\n\nconst { useRemoteUrlData, isHashLink, isRelativePath } = unlock(\n\tblockEditorPrivateApis\n);\n\n/**\n * Capitalize the first letter of a string.\n *\n * @param {string} str - The string to capitalize\n * @return {string} Capitalized string\n */\nfunction capitalize( str ) {\n\treturn str.charAt( 0 ).toUpperCase() + str.slice( 1 );\n}\n\n/**\n * Check if a URL points to the site homepage.\n * Handles protocol (http/https) and trailing slash variations.\n * Does not match subdomains unless they are the site URL.\n *\n * @param {string} url - The URL to check\n * @param {string} homeUrl - The WordPress site URL\n * @return {boolean} True if url is the homepage\n */\nexport function isHomepage( url, homeUrl ) {\n\tif ( url === '/' ) {\n\t\treturn true;\n\t}\n\tif ( ! url || ! homeUrl ) {\n\t\treturn false;\n\t}\n\ttry {\n\t\tconst urlParsed = new URL( url, homeUrl );\n\t\tconst homeParsed = new URL( homeUrl );\n\n\t\t// Same host, i.e. sub.homepage.com or homepage.com\n\t\tif ( urlParsed.hostname !== homeParsed.hostname ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Path must match site root (normalize trailing slash)\n\t\tconst urlPath = urlParsed.pathname.replace( /\\/$/, '' );\n\t\tconst homePath = homeParsed.pathname.replace( /\\/$/, '' );\n\n\t\treturn urlPath === homePath;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * Compute display URL - strips site URL if internal, shows full URL if external.\n *\n * @param {Object} options - Parameters object\n * @param {string} options.linkUrl - The URL to process\n * @param {string} options.homeUrl - The WordPress site URL (required for internal/external detection)\n * @return {Object} Object with displayUrl and isExternal flag\n */\nexport function computeDisplayUrl( { linkUrl, homeUrl } = {} ) {\n\tif ( ! linkUrl ) {\n\t\treturn { displayUrl: '', isExternal: false };\n\t}\n\n\tlet displayUrl = safeDecodeURI( linkUrl );\n\tlet isExternal = false;\n\n\t// Check hash links and relative paths first - these are always internal\n\tif ( isRelativePath( linkUrl ) || isHashLink( linkUrl ) ) {\n\t\treturn { displayUrl, isExternal: false };\n\t}\n\n\t// Try to parse as a full URL to determine if it's actually external\n\t// This must happen before trusting the type attribute\n\ttry {\n\t\tconst parsedUrl = new URL( linkUrl );\n\t\t// Compare by host (not origin) so http/https to same site both count as internal\n\t\tconst siteHost = new URL( homeUrl ).host;\n\n\t\tif ( parsedUrl.host === siteHost ) {\n\t\t\t// Show only the pathname (and search/hash if present)\n\t\t\tlet path = parsedUrl.pathname + parsedUrl.search + parsedUrl.hash;\n\t\t\t// Remove trailing slash\n\t\t\tif ( path.endsWith( '/' ) && path.length > 1 ) {\n\t\t\t\tpath = path.slice( 0, -1 );\n\t\t\t}\n\t\t\tdisplayUrl = path;\n\t\t} else {\n\t\t\t// Different host - this is an external link\n\t\t\tisExternal = true;\n\t\t}\n\t} catch ( e ) {\n\t\t// URL parsing failed - treat as external (e.g. no homeUrl, or URL without protocol)\n\t\tisExternal = true;\n\t}\n\n\treturn { displayUrl, isExternal };\n}\n\n/**\n * Compute badges for the link preview.\n *\n * @param {Object} options - Options object\n * @param {string} options.url - Link URL\n * @param {string} options.homeUrl - WordPress site URL (for homepage detection)\n * @param {string} options.type - Entity type (page, post, etc.)\n * @param {boolean} options.isExternal - Whether link is external\n * @param {string} options.entityStatus - Entity status (publish, draft, etc.)\n * @param {boolean} options.hasBinding - Whether link has entity binding\n * @param {boolean} options.isEntityAvailable - Whether bound entity exists\n * @return {Array} Array of badge objects with label and intent\n */\nexport function computeBadges( {\n\turl,\n\thomeUrl,\n\ttype,\n\tisExternal,\n\tentityStatus,\n\thasBinding,\n\tisEntityAvailable,\n} ) {\n\tconst badges = [];\n\t// Kind badge\n\tif ( url ) {\n\t\tif ( isExternal ) {\n\t\t\tbadges.push( {\n\t\t\t\tlabel: __( 'External link' ),\n\t\t\t\tintent: 'default',\n\t\t\t} );\n\t\t} else if ( isHashLink( url ) ) {\n\t\t\t// Hash links should be detected before type check\n\t\t\t// because they're not entity links even if type is set\n\t\t\tbadges.push( {\n\t\t\t\tlabel: __( 'Internal link' ),\n\t\t\t\tintent: 'default',\n\t\t\t} );\n\t\t} else if ( isHomepage( url, homeUrl ) ) {\n\t\t\tbadges.push( {\n\t\t\t\tlabel: __( 'Homepage' ),\n\t\t\t\tintent: 'default',\n\t\t\t} );\n\t\t} else if ( type && type !== 'custom' ) {\n\t\t\t// Show entity type badge (page, post, category, etc.)\n\t\t\t// but not 'custom' since that's just a manual link\n\t\t\tbadges.push( { label: capitalize( type ), intent: 'default' } );\n\t\t} else {\n\t\t\t// Internal link (not external, not hash, not entity)\n\t\t\tbadges.push( {\n\t\t\t\tlabel: __( 'Page' ),\n\t\t\t\tintent: 'default',\n\t\t\t} );\n\t\t}\n\t}\n\n\t// Status badge\n\tif ( hasBinding && ! isEntityAvailable ) {\n\t\tbadges.push( {\n\t\t\tlabel: sprintf(\n\t\t\t\t/* translators: %s is the entity type (e.g., \"page\", \"post\", \"category\") */\n\t\t\t\t__( 'Missing %s' ),\n\t\t\t\ttype\n\t\t\t),\n\t\t\tintent: 'error',\n\t\t} );\n\t} else if ( ! url ) {\n\t\tbadges.push( { label: __( 'No link selected' ), intent: 'error' } );\n\t} else if ( entityStatus ) {\n\t\tconst statusMap = {\n\t\t\tpublish: { label: __( 'Published' ), intent: 'success' },\n\t\t\tfuture: { label: __( 'Scheduled' ), intent: 'warning' },\n\t\t\tdraft: { label: __( 'Draft' ), intent: 'warning' },\n\t\t\tpending: { label: __( 'Pending' ), intent: 'warning' },\n\t\t\tprivate: { label: __( 'Private' ), intent: 'default' },\n\t\t\ttrash: { label: __( 'Trash' ), intent: 'error' },\n\t\t};\n\t\tconst badge = statusMap[ entityStatus ];\n\t\tif ( badge ) {\n\t\t\tbadges.push( badge );\n\t\t}\n\t}\n\n\treturn badges;\n}\n\n/**\n * Hook to compute link preview data for display.\n *\n * This hook takes raw link data and entity information and computes\n * presentation-ready preview data including formatted title, URL, and badges.\n *\n * @param {Object} options - Options object\n * @param {string} options.url - Link URL\n * @param {string} options.type - Entity type (page, post, etc.)\n * @param {Object} options.entityRecord - Entity record\n * @param {boolean} options.hasBinding - Whether link has entity binding\n * @param {boolean} options.isEntityAvailable - Whether bound entity exists\n * @return {Object} Preview data object with title, url, image, and badges\n */\nexport function useLinkPreview( {\n\turl,\n\tentityRecord,\n\ttype,\n\thasBinding,\n\tisEntityAvailable,\n} ) {\n\t// Get the WordPress homepage URL from settings\n\tconst homeUrl = useSelect( ( select ) => {\n\t\treturn select( coreDataStore ).getEntityRecord(\n\t\t\t'root',\n\t\t\t'__unstableBase'\n\t\t)?.home;\n\t}, [] );\n\n\tconst title =\n\t\tentityRecord?.title?.rendered ||\n\t\tentityRecord?.title ||\n\t\tentityRecord?.name;\n\n\t// Fetch rich URL data if we don't have a title. Internal links should have passed a title.\n\tconst { richData } = useRemoteUrlData( title ? null : url );\n\n\t// Compute display URL and external flag\n\tconst { displayUrl, isExternal } = computeDisplayUrl( {\n\t\tlinkUrl: url,\n\t\thomeUrl,\n\t} );\n\n\tconst image = useSelect(\n\t\t( select ) => {\n\t\t\t// Only fetch for post-type entities with featured media\n\t\t\tif ( ! entityRecord?.featured_media ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst { getEntityRecord } = select( coreDataStore );\n\n\t\t\t// Get the media entity to fetch the image URL\n\t\t\tconst media = getEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'attachment',\n\t\t\t\tentityRecord.featured_media\n\t\t\t);\n\n\t\t\t// Return the thumbnail or medium size URL, fallback to source_url\n\t\t\treturn (\n\t\t\t\tmedia?.media_details?.sizes?.thumbnail?.source_url ||\n\t\t\t\tmedia?.media_details?.sizes?.medium?.source_url ||\n\t\t\t\tmedia?.source_url ||\n\t\t\t\tnull\n\t\t\t);\n\t\t},\n\t\t[ entityRecord?.featured_media ]\n\t);\n\n\t// Compute badges\n\tconst badges = computeBadges( {\n\t\turl,\n\t\thomeUrl,\n\t\ttype,\n\t\tisExternal,\n\t\tentityStatus: entityRecord?.status,\n\t\thasBinding,\n\t\tisEntityAvailable,\n\t} );\n\n\t// Get display title - use provided title, fallback to rich data, or URL\n\tconst displayTitle = url\n\t\t? title || richData?.title || safeDecodeURI( url )\n\t\t: __( 'Add link' );\n\n\treturn {\n\t\ttitle: displayTitle,\n\t\turl: displayUrl,\n\t\timage,\n\t\tbadges,\n\t};\n}\n"],
5
- "mappings": ";AAGA,SAAS,IAAI,eAAe;AAC5B,SAAS,qBAAqB;AAC9B,SAAS,eAAe,8BAA8B;AACtD,SAAS,iBAAiB;AAC1B,SAAS,SAAS,qBAAqB;AAKvC,SAAS,cAAc;AAEvB,IAAM,EAAE,kBAAkB,YAAY,eAAe,IAAI;AAAA,EACxD;AACD;AAQA,SAAS,WAAY,KAAM;AAC1B,SAAO,IAAI,OAAQ,CAAE,EAAE,YAAY,IAAI,IAAI,MAAO,CAAE;AACrD;AAWO,SAAS,WAAY,KAAK,SAAU;AAC1C,MAAK,QAAQ,KAAM;AAClB,WAAO;AAAA,EACR;AACA,MAAK,CAAE,OAAO,CAAE,SAAU;AACzB,WAAO;AAAA,EACR;AACA,MAA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AAQ;AACZ,aAAO,KAAM,KAAM;AAAA,IACpB;AAAA,EACD;AAEA,SAAO;AACR;AAgBO,SAAS,eAAgB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAI;AAEH,QAAM,UAAU,UAAW,CAAE,WAAY;AACxC,WAAO,OAAQ,aAAc,EAAE;AAAA,MAC9B;AAAA,MACA;AAAA,IACD,GAAG;AAAA,EACJ,GAAG,CAAC,CAAE;AAEN,QAAM,QACL,cAAc,OAAO,YACrB,cAAc,SACd,cAAc;AAGf,QAAM,EAAE,SAAS,IAAI,iBAAkB,QAAQ,OAAO,GAAI;AAG1D,QAAM,EAAE,YAAY,WAAW,IAAI,kBAAmB;AAAA,IACrD,SAAS;AAAA,IACT;AAAA,EACD,CAAE;AAEF,QAAM,QAAQ;AAAA,IACb,CAAE,WAAY;AAEb,UAAK,CAAE,cAAc,gBAAiB;AACrC,eAAO;AAAA,MACR;AAEA,YAAM,EAAE,gBAAgB,IAAI,OAAQ,aAAc;AAGlD,YAAM,QAAQ;AAAA,QACb;AAAA,QACA;AAAA,QACA,aAAa;AAAA,MACd;AAGA,aACC,OAAO,eAAe,OAAO,WAAW,cACxC,OAAO,eAAe,OAAO,QAAQ,cACrC,OAAO,cACP;AAAA,IAEF;AAAA,IACA,CAAE,cAAc,cAAe;AAAA,EAChC;AAGA,QAAM,SAAS,cAAe;AAAA,IAC7B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc,cAAc;AAAA,IAC5B;AAAA,IACA;AAAA,EACD,CAAE;AAGF,QAAM,eAAe,MAClB,SAAS,UAAU,SAAS,cAAe,GAAI,IAC/C,GAAI,UAAW;AAElB,SAAO;AAAA,IACN,OAAO;AAAA,IACP,KAAK;AAAA,IACL;AAAA,IACA;AAAA,EACD;AACD;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { safeDecodeURI } from '@wordpress/url';\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreDataStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\n\nconst { useRemoteUrlData, isHashLink, isRelativePath } = unlock(\n\tblockEditorPrivateApis\n);\n\n/**\n * Capitalize the first letter of a string.\n *\n * @param {string} str - The string to capitalize\n * @return {string} Capitalized string\n */\nfunction capitalize( str ) {\n\treturn str.charAt( 0 ).toUpperCase() + str.slice( 1 );\n}\n\n/**\n * Check if a URL points to the site homepage.\n * Handles protocol (http/https) and trailing slash variations.\n * Does not match subdomains unless they are the site URL.\n *\n * @param {string} url - The URL to check\n * @param {string} homeUrl - The WordPress site URL\n * @return {boolean} True if url is the homepage\n */\nexport function isHomepage( url, homeUrl ) {\n\tif ( url === '/' ) {\n\t\treturn true;\n\t}\n\tif ( ! url || ! homeUrl ) {\n\t\treturn false;\n\t}\n\ttry {\n\t\tconst urlParsed = new URL( url, homeUrl );\n\t\tconst homeParsed = new URL( homeUrl );\n\n\t\t// Same host, i.e. sub.homepage.com or homepage.com\n\t\tif ( urlParsed.hostname !== homeParsed.hostname ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Path must match site root (normalize trailing slash)\n\t\tconst urlPath = urlParsed.pathname.replace( /\\/$/, '' );\n\t\tconst homePath = homeParsed.pathname.replace( /\\/$/, '' );\n\n\t\treturn urlPath === homePath;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * Compute display URL - strips site URL if internal, shows full URL if external.\n *\n * @param {Object} options - Parameters object\n * @param {string} options.linkUrl - The URL to process\n * @param {string} options.homeUrl - The WordPress site URL (required for internal/external detection)\n * @return {Object} Object with displayUrl and isExternal flag\n */\nexport function computeDisplayUrl( { linkUrl, homeUrl } = {} ) {\n\tif ( ! linkUrl ) {\n\t\treturn { displayUrl: '', isExternal: false };\n\t}\n\n\tlet displayUrl = safeDecodeURI( linkUrl );\n\tlet isExternal = false;\n\n\t// Check hash links and relative paths first - these are always internal\n\tif ( isRelativePath( linkUrl ) || isHashLink( linkUrl ) ) {\n\t\treturn { displayUrl, isExternal: false };\n\t}\n\n\t// Try to parse as a full URL to determine if it's actually external\n\t// This must happen before trusting the type attribute\n\ttry {\n\t\tconst parsedUrl = new URL( linkUrl );\n\t\t// Compare by host (not origin) so http/https to same site both count as internal\n\t\tconst siteHost = new URL( homeUrl ).host;\n\n\t\tif ( parsedUrl.host === siteHost ) {\n\t\t\t// Show only the pathname (and search/hash if present)\n\t\t\tlet path = parsedUrl.pathname + parsedUrl.search + parsedUrl.hash;\n\t\t\t// Remove trailing slash\n\t\t\tif ( path.endsWith( '/' ) && path.length > 1 ) {\n\t\t\t\tpath = path.slice( 0, -1 );\n\t\t\t}\n\t\t\tdisplayUrl = path;\n\t\t} else {\n\t\t\t// Different host - this is an external link\n\t\t\tisExternal = true;\n\t\t}\n\t} catch {\n\t\t// URL parsing failed - treat as external (e.g. no homeUrl, or URL without protocol)\n\t\tisExternal = true;\n\t}\n\n\treturn { displayUrl, isExternal };\n}\n\n/**\n * Compute badges for the link preview.\n *\n * @param {Object} options - Options object\n * @param {string} options.url - Link URL\n * @param {string} options.homeUrl - WordPress site URL (for homepage detection)\n * @param {string} options.type - Entity type (page, post, etc.)\n * @param {boolean} options.isExternal - Whether link is external\n * @param {string} options.entityStatus - Entity status (publish, draft, etc.)\n * @param {boolean} options.hasBinding - Whether link has entity binding\n * @param {boolean} options.isEntityAvailable - Whether bound entity exists\n * @return {Array} Array of badge objects with label and intent\n */\nexport function computeBadges( {\n\turl,\n\thomeUrl,\n\ttype,\n\tisExternal,\n\tentityStatus,\n\thasBinding,\n\tisEntityAvailable,\n} ) {\n\tconst badges = [];\n\t// Kind badge\n\tif ( url ) {\n\t\tif ( isExternal ) {\n\t\t\tbadges.push( {\n\t\t\t\tlabel: __( 'External link' ),\n\t\t\t\tintent: 'default',\n\t\t\t} );\n\t\t} else if ( isHashLink( url ) ) {\n\t\t\t// Hash links should be detected before type check\n\t\t\t// because they're not entity links even if type is set\n\t\t\tbadges.push( {\n\t\t\t\tlabel: __( 'Internal link' ),\n\t\t\t\tintent: 'default',\n\t\t\t} );\n\t\t} else if ( isHomepage( url, homeUrl ) ) {\n\t\t\tbadges.push( {\n\t\t\t\tlabel: __( 'Homepage' ),\n\t\t\t\tintent: 'default',\n\t\t\t} );\n\t\t} else if ( type && type !== 'custom' ) {\n\t\t\t// Show entity type badge (page, post, category, etc.)\n\t\t\t// but not 'custom' since that's just a manual link\n\t\t\tbadges.push( { label: capitalize( type ), intent: 'default' } );\n\t\t} else {\n\t\t\t// Internal link (not external, not hash, not entity)\n\t\t\tbadges.push( {\n\t\t\t\tlabel: __( 'Page' ),\n\t\t\t\tintent: 'default',\n\t\t\t} );\n\t\t}\n\t}\n\n\t// Status badge\n\tif ( hasBinding && ! isEntityAvailable ) {\n\t\tbadges.push( {\n\t\t\tlabel: sprintf(\n\t\t\t\t/* translators: %s is the entity type (e.g., \"page\", \"post\", \"category\") */\n\t\t\t\t__( 'Missing %s' ),\n\t\t\t\ttype\n\t\t\t),\n\t\t\tintent: 'error',\n\t\t} );\n\t} else if ( ! url ) {\n\t\tbadges.push( { label: __( 'No link selected' ), intent: 'error' } );\n\t} else if ( entityStatus ) {\n\t\tconst statusMap = {\n\t\t\tpublish: { label: __( 'Published' ), intent: 'success' },\n\t\t\tfuture: { label: __( 'Scheduled' ), intent: 'warning' },\n\t\t\tdraft: { label: __( 'Draft' ), intent: 'warning' },\n\t\t\tpending: { label: __( 'Pending' ), intent: 'warning' },\n\t\t\tprivate: { label: __( 'Private' ), intent: 'default' },\n\t\t\ttrash: { label: __( 'Trash' ), intent: 'error' },\n\t\t};\n\t\tconst badge = statusMap[ entityStatus ];\n\t\tif ( badge ) {\n\t\t\tbadges.push( badge );\n\t\t}\n\t}\n\n\treturn badges;\n}\n\n/**\n * Hook to compute link preview data for display.\n *\n * This hook takes raw link data and entity information and computes\n * presentation-ready preview data including formatted title, URL, and badges.\n *\n * @param {Object} options - Options object\n * @param {string} options.url - Link URL\n * @param {string} options.type - Entity type (page, post, etc.)\n * @param {Object} options.entityRecord - Entity record\n * @param {boolean} options.hasBinding - Whether link has entity binding\n * @param {boolean} options.isEntityAvailable - Whether bound entity exists\n * @return {Object} Preview data object with title, url, image, and badges\n */\nexport function useLinkPreview( {\n\turl,\n\tentityRecord,\n\ttype,\n\thasBinding,\n\tisEntityAvailable,\n} ) {\n\t// Get the WordPress homepage URL from settings\n\tconst homeUrl = useSelect( ( select ) => {\n\t\treturn select( coreDataStore ).getEntityRecord(\n\t\t\t'root',\n\t\t\t'__unstableBase'\n\t\t)?.home;\n\t}, [] );\n\n\tconst title =\n\t\tentityRecord?.title?.rendered ||\n\t\tentityRecord?.title ||\n\t\tentityRecord?.name;\n\n\t// Fetch rich URL data if we don't have a title. Internal links should have passed a title.\n\tconst { richData } = useRemoteUrlData( title ? null : url );\n\n\t// Compute display URL and external flag\n\tconst { displayUrl, isExternal } = computeDisplayUrl( {\n\t\tlinkUrl: url,\n\t\thomeUrl,\n\t} );\n\n\tconst image = useSelect(\n\t\t( select ) => {\n\t\t\t// Only fetch for post-type entities with featured media\n\t\t\tif ( ! entityRecord?.featured_media ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst { getEntityRecord } = select( coreDataStore );\n\n\t\t\t// Get the media entity to fetch the image URL\n\t\t\tconst media = getEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'attachment',\n\t\t\t\tentityRecord.featured_media\n\t\t\t);\n\n\t\t\t// Return the thumbnail or medium size URL, fallback to source_url\n\t\t\treturn (\n\t\t\t\tmedia?.media_details?.sizes?.thumbnail?.source_url ||\n\t\t\t\tmedia?.media_details?.sizes?.medium?.source_url ||\n\t\t\t\tmedia?.source_url ||\n\t\t\t\tnull\n\t\t\t);\n\t\t},\n\t\t[ entityRecord?.featured_media ]\n\t);\n\n\t// Compute badges\n\tconst badges = computeBadges( {\n\t\turl,\n\t\thomeUrl,\n\t\ttype,\n\t\tisExternal,\n\t\tentityStatus: entityRecord?.status,\n\t\thasBinding,\n\t\tisEntityAvailable,\n\t} );\n\n\t// Get display title - use provided title, fallback to rich data, or URL\n\tconst displayTitle = url\n\t\t? title || richData?.title || safeDecodeURI( url )\n\t\t: __( 'Add link' );\n\n\treturn {\n\t\ttitle: displayTitle,\n\t\turl: displayUrl,\n\t\timage,\n\t\tbadges,\n\t};\n}\n"],
5
+ "mappings": ";AAGA,SAAS,IAAI,eAAe;AAC5B,SAAS,qBAAqB;AAC9B,SAAS,eAAe,8BAA8B;AACtD,SAAS,iBAAiB;AAC1B,SAAS,SAAS,qBAAqB;AAKvC,SAAS,cAAc;AAEvB,IAAM,EAAE,kBAAkB,YAAY,eAAe,IAAI;AAAA,EACxD;AACD;AAQA,SAAS,WAAY,KAAM;AAC1B,SAAO,IAAI,OAAQ,CAAE,EAAE,YAAY,IAAI,IAAI,MAAO,CAAE;AACrD;AAWO,SAAS,WAAY,KAAK,SAAU;AAC1C,MAAK,QAAQ,KAAM;AAClB,WAAO;AAAA,EACR;AACA,MAAK,CAAE,OAAO,CAAE,SAAU;AACzB,WAAO;AAAA,EACR;AACA,MAAI;AACH,UAAM,YAAY,IAAI,IAAK,KAAK,OAAQ;AACxC,UAAM,aAAa,IAAI,IAAK,OAAQ;AAGpC,QAAK,UAAU,aAAa,WAAW,UAAW;AACjD,aAAO;AAAA,IACR;AAGA,UAAM,UAAU,UAAU,SAAS,QAAS,OAAO,EAAG;AACtD,UAAM,WAAW,WAAW,SAAS,QAAS,OAAO,EAAG;AAExD,WAAO,YAAY;AAAA,EACpB,QAAQ;AACP,WAAO;AAAA,EACR;AACD;AAUO,SAAS,kBAAmB,EAAE,SAAS,QAAQ,IAAI,CAAC,GAAI;AAC9D,MAAK,CAAE,SAAU;AAChB,WAAO,EAAE,YAAY,IAAI,YAAY,MAAM;AAAA,EAC5C;AAEA,MAAI,aAAa,cAAe,OAAQ;AACxC,MAAI,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D,CAAE;AAEF,QAAM,QAAQ;AAAA,IACb,CAAE,WAAY;AAEb,UAAK,CAAE,cAAc,gBAAiB;AACrC,eAAO;AAAA,MACR;AAEA,YAAM,EAAE,gBAAgB,IAAI,OAAQ,aAAc;AAGlD,YAAM,QAAQ;AAAA,QACb;AAAA,QACA;AAAA,QACA,aAAa;AAAA,MACd;AAGA,aACC,OAAO,eAAe,OAAO,WAAW,cACxC,OAAO,eAAe,OAAO,QAAQ,cACrC,OAAO,cACP;AAAA,IAEF;AAAA,IACA,CAAE,cAAc,cAAe;AAAA,EAChC;AAGA,QAAM,SAAS,cAAe;AAAA,IAC7B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc,cAAc;AAAA,IAC5B;AAAA,IACA;AAAA,EACD,CAAE;AAGF,QAAM,eAAe,MAClB,SAAS,UAAU,SAAS,cAAe,GAAI,IAC/C,GAAI,UAAW;AAElB,SAAO;AAAA,IACN,OAAO;AAAA,IACP,KAAK;AAAA,IACL;AAAA,IACA;AAAA,EACD;AACD;",
6
6
  "names": []
7
7
  }
@@ -70,10 +70,9 @@ function useOnEnter(props) {
70
70
  return;
71
71
  }
72
72
  const defaultBlockName = getDefaultBlockName();
73
- if (!canInsertBlockType(
74
- defaultBlockName,
75
- getBlockRootClientId(wrapperClientId)
76
- )) {
73
+ const wrapperBlockName = getBlockName(wrapperClientId);
74
+ const grandparentClientId = getBlockRootClientId(wrapperClientId);
75
+ if (!canInsertBlockType(defaultBlockName, grandparentClientId) || !canInsertBlockType(wrapperBlockName, grandparentClientId)) {
77
76
  return;
78
77
  }
79
78
  event.preventDefault();
@@ -92,7 +91,7 @@ function useOnEnter(props) {
92
91
  insertBlock(
93
92
  createBlock(defaultBlockName),
94
93
  blockIndex + 1,
95
- getBlockRootClientId(wrapperClientId),
94
+ grandparentClientId,
96
95
  true
97
96
  );
98
97
  });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/paragraph/use-enter.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\nimport { useRefEffect } from '@wordpress/compose';\nimport { ENTER } from '@wordpress/keycodes';\nimport { useSelect, useDispatch, useRegistry } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport {\n\thasBlockSupport,\n\tcreateBlock,\n\tgetDefaultBlockName,\n} from '@wordpress/blocks';\n\nexport function useOnEnter( props ) {\n\tconst { batch } = useRegistry();\n\tconst {\n\t\tmoveBlocksToPosition,\n\t\treplaceInnerBlocks,\n\t\tduplicateBlocks,\n\t\tinsertBlock,\n\t} = useDispatch( blockEditorStore );\n\tconst {\n\t\tgetBlockRootClientId,\n\t\tgetBlockIndex,\n\t\tgetBlockOrder,\n\t\tgetBlockName,\n\t\tgetBlock,\n\t\tgetNextBlockClientId,\n\t\tcanInsertBlockType,\n\t} = useSelect( blockEditorStore );\n\tconst propsRef = useRef( props );\n\tpropsRef.current = props;\n\treturn useRefEffect( ( element ) => {\n\t\tfunction onKeyDown( event ) {\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( event.keyCode !== ENTER ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { content, clientId } = propsRef.current;\n\n\t\t\t// The paragraph should be empty.\n\t\t\tif ( content.length ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst wrapperClientId = getBlockRootClientId( clientId );\n\n\t\t\tif (\n\t\t\t\t! hasBlockSupport(\n\t\t\t\t\tgetBlockName( wrapperClientId ),\n\t\t\t\t\t'__experimentalOnEnter',\n\t\t\t\t\tfalse\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst order = getBlockOrder( wrapperClientId );\n\t\t\tconst position = order.indexOf( clientId );\n\n\t\t\t// If it is the last block, exit.\n\t\t\tif ( position === order.length - 1 ) {\n\t\t\t\tlet newWrapperClientId = wrapperClientId;\n\n\t\t\t\twhile (\n\t\t\t\t\t! canInsertBlockType(\n\t\t\t\t\t\tgetBlockName( clientId ),\n\t\t\t\t\t\tgetBlockRootClientId( newWrapperClientId )\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tnewWrapperClientId =\n\t\t\t\t\t\tgetBlockRootClientId( newWrapperClientId );\n\t\t\t\t}\n\n\t\t\t\tif ( typeof newWrapperClientId === 'string' ) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tmoveBlocksToPosition(\n\t\t\t\t\t\t[ clientId ],\n\t\t\t\t\t\twrapperClientId,\n\t\t\t\t\t\tgetBlockRootClientId( newWrapperClientId ),\n\t\t\t\t\t\tgetBlockIndex( newWrapperClientId ) + 1\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst defaultBlockName = getDefaultBlockName();\n\n\t\t\tif (\n\t\t\t\t! canInsertBlockType(\n\t\t\t\t\tdefaultBlockName,\n\t\t\t\t\tgetBlockRootClientId( wrapperClientId )\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tevent.preventDefault();\n\n\t\t\t// If it is in the middle, split the block in two.\n\t\t\tconst wrapperBlock = getBlock( wrapperClientId );\n\t\t\tbatch( () => {\n\t\t\t\tduplicateBlocks( [ wrapperClientId ] );\n\t\t\t\tconst blockIndex = getBlockIndex( wrapperClientId );\n\n\t\t\t\treplaceInnerBlocks(\n\t\t\t\t\twrapperClientId,\n\t\t\t\t\twrapperBlock.innerBlocks.slice( 0, position )\n\t\t\t\t);\n\t\t\t\treplaceInnerBlocks(\n\t\t\t\t\tgetNextBlockClientId( wrapperClientId ),\n\t\t\t\t\twrapperBlock.innerBlocks.slice( position + 1 )\n\t\t\t\t);\n\t\t\t\tinsertBlock(\n\t\t\t\t\tcreateBlock( defaultBlockName ),\n\t\t\t\t\tblockIndex + 1,\n\t\t\t\t\tgetBlockRootClientId( wrapperClientId ),\n\t\t\t\t\ttrue\n\t\t\t\t);\n\t\t\t} );\n\t\t}\n\n\t\telement.addEventListener( 'keydown', onKeyDown );\n\t\treturn () => {\n\t\t\telement.removeEventListener( 'keydown', onKeyDown );\n\t\t};\n\t}, [] );\n}\n"],
5
- "mappings": ";AAGA,SAAS,cAAc;AACvB,SAAS,oBAAoB;AAC7B,SAAS,aAAa;AACtB,SAAS,WAAW,aAAa,mBAAmB;AACpD,SAAS,SAAS,wBAAwB;AAC1C;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAEA,SAAS,WAAY,OAAQ;AACnC,QAAM,EAAE,MAAM,IAAI,YAAY;AAC9B,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,IAAI,YAAa,gBAAiB;AAClC,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,IAAI,UAAW,gBAAiB;AAChC,QAAM,WAAW,OAAQ,KAAM;AAC/B,WAAS,UAAU;AACnB,SAAO,aAAc,CAAE,YAAa;AACnC,aAAS,UAAW,OAAQ;AAC3B,UAAK,MAAM,kBAAmB;AAC7B;AAAA,MACD;AAEA,UAAK,MAAM,YAAY,OAAQ;AAC9B;AAAA,MACD;AAEA,YAAM,EAAE,SAAS,SAAS,IAAI,SAAS;AAGvC,UAAK,QAAQ,QAAS;AACrB;AAAA,MACD;AAEA,YAAM,kBAAkB,qBAAsB,QAAS;AAEvD,UACC,CAAE;AAAA,QACD,aAAc,eAAgB;AAAA,QAC9B;AAAA,QACA;AAAA,MACD,GACC;AACD;AAAA,MACD;AAEA,YAAM,QAAQ,cAAe,eAAgB;AAC7C,YAAM,WAAW,MAAM,QAAS,QAAS;AAGzC,UAAK,aAAa,MAAM,SAAS,GAAI;AACpC,YAAI,qBAAqB;AAEzB,eACC,CAAE;AAAA,UACD,aAAc,QAAS;AAAA,UACvB,qBAAsB,kBAAmB;AAAA,QAC1C,GACC;AACD,+BACC,qBAAsB,kBAAmB;AAAA,QAC3C;AAEA,YAAK,OAAO,uBAAuB,UAAW;AAC7C,gBAAM,eAAe;AACrB;AAAA,YACC,CAAE,QAAS;AAAA,YACX;AAAA,YACA,qBAAsB,kBAAmB;AAAA,YACzC,cAAe,kBAAmB,IAAI;AAAA,UACvC;AAAA,QACD;AACA;AAAA,MACD;AAEA,YAAM,mBAAmB,oBAAoB;AAE7C,UACC,CAAE;AAAA,QACD;AAAA,QACA,qBAAsB,eAAgB;AAAA,MACvC,GACC;AACD;AAAA,MACD;AAEA,YAAM,eAAe;AAGrB,YAAM,eAAe,SAAU,eAAgB;AAC/C,YAAO,MAAM;AACZ,wBAAiB,CAAE,eAAgB,CAAE;AACrC,cAAM,aAAa,cAAe,eAAgB;AAElD;AAAA,UACC;AAAA,UACA,aAAa,YAAY,MAAO,GAAG,QAAS;AAAA,QAC7C;AACA;AAAA,UACC,qBAAsB,eAAgB;AAAA,UACtC,aAAa,YAAY,MAAO,WAAW,CAAE;AAAA,QAC9C;AACA;AAAA,UACC,YAAa,gBAAiB;AAAA,UAC9B,aAAa;AAAA,UACb,qBAAsB,eAAgB;AAAA,UACtC;AAAA,QACD;AAAA,MACD,CAAE;AAAA,IACH;AAEA,YAAQ,iBAAkB,WAAW,SAAU;AAC/C,WAAO,MAAM;AACZ,cAAQ,oBAAqB,WAAW,SAAU;AAAA,IACnD;AAAA,EACD,GAAG,CAAC,CAAE;AACP;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\nimport { useRefEffect } from '@wordpress/compose';\nimport { ENTER } from '@wordpress/keycodes';\nimport { useSelect, useDispatch, useRegistry } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport {\n\thasBlockSupport,\n\tcreateBlock,\n\tgetDefaultBlockName,\n} from '@wordpress/blocks';\n\nexport function useOnEnter( props ) {\n\tconst { batch } = useRegistry();\n\tconst {\n\t\tmoveBlocksToPosition,\n\t\treplaceInnerBlocks,\n\t\tduplicateBlocks,\n\t\tinsertBlock,\n\t} = useDispatch( blockEditorStore );\n\tconst {\n\t\tgetBlockRootClientId,\n\t\tgetBlockIndex,\n\t\tgetBlockOrder,\n\t\tgetBlockName,\n\t\tgetBlock,\n\t\tgetNextBlockClientId,\n\t\tcanInsertBlockType,\n\t} = useSelect( blockEditorStore );\n\tconst propsRef = useRef( props );\n\tpropsRef.current = props;\n\treturn useRefEffect( ( element ) => {\n\t\tfunction onKeyDown( event ) {\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( event.keyCode !== ENTER ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { content, clientId } = propsRef.current;\n\n\t\t\t// The paragraph should be empty.\n\t\t\tif ( content.length ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst wrapperClientId = getBlockRootClientId( clientId );\n\n\t\t\tif (\n\t\t\t\t! hasBlockSupport(\n\t\t\t\t\tgetBlockName( wrapperClientId ),\n\t\t\t\t\t'__experimentalOnEnter',\n\t\t\t\t\tfalse\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst order = getBlockOrder( wrapperClientId );\n\t\t\tconst position = order.indexOf( clientId );\n\n\t\t\t// If it is the last block, exit.\n\t\t\tif ( position === order.length - 1 ) {\n\t\t\t\tlet newWrapperClientId = wrapperClientId;\n\n\t\t\t\twhile (\n\t\t\t\t\t! canInsertBlockType(\n\t\t\t\t\t\tgetBlockName( clientId ),\n\t\t\t\t\t\tgetBlockRootClientId( newWrapperClientId )\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tnewWrapperClientId =\n\t\t\t\t\t\tgetBlockRootClientId( newWrapperClientId );\n\t\t\t\t}\n\n\t\t\t\tif ( typeof newWrapperClientId === 'string' ) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tmoveBlocksToPosition(\n\t\t\t\t\t\t[ clientId ],\n\t\t\t\t\t\twrapperClientId,\n\t\t\t\t\t\tgetBlockRootClientId( newWrapperClientId ),\n\t\t\t\t\t\tgetBlockIndex( newWrapperClientId ) + 1\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst defaultBlockName = getDefaultBlockName();\n\t\t\tconst wrapperBlockName = getBlockName( wrapperClientId );\n\t\t\tconst grandparentClientId = getBlockRootClientId( wrapperClientId );\n\n\t\t\tif (\n\t\t\t\t! canInsertBlockType( defaultBlockName, grandparentClientId ) ||\n\t\t\t\t! canInsertBlockType( wrapperBlockName, grandparentClientId )\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tevent.preventDefault();\n\n\t\t\t// If it is in the middle, split the block in two.\n\t\t\tconst wrapperBlock = getBlock( wrapperClientId );\n\t\t\tbatch( () => {\n\t\t\t\tduplicateBlocks( [ wrapperClientId ] );\n\t\t\t\tconst blockIndex = getBlockIndex( wrapperClientId );\n\n\t\t\t\treplaceInnerBlocks(\n\t\t\t\t\twrapperClientId,\n\t\t\t\t\twrapperBlock.innerBlocks.slice( 0, position )\n\t\t\t\t);\n\t\t\t\treplaceInnerBlocks(\n\t\t\t\t\tgetNextBlockClientId( wrapperClientId ),\n\t\t\t\t\twrapperBlock.innerBlocks.slice( position + 1 )\n\t\t\t\t);\n\t\t\t\tinsertBlock(\n\t\t\t\t\tcreateBlock( defaultBlockName ),\n\t\t\t\t\tblockIndex + 1,\n\t\t\t\t\tgrandparentClientId,\n\t\t\t\t\ttrue\n\t\t\t\t);\n\t\t\t} );\n\t\t}\n\n\t\telement.addEventListener( 'keydown', onKeyDown );\n\t\treturn () => {\n\t\t\telement.removeEventListener( 'keydown', onKeyDown );\n\t\t};\n\t}, [] );\n}\n"],
5
+ "mappings": ";AAGA,SAAS,cAAc;AACvB,SAAS,oBAAoB;AAC7B,SAAS,aAAa;AACtB,SAAS,WAA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A,YAAM,mBAAmB,oBAAoB;AAC7C,YAAM,mBAAmB,aAAc,eAAgB;AACvD,YAAM,sBAAsB,qBAAsB,eAAgB;AAElE,UACC,CAAE,mBAAoB,kBAAkB,mBAAoB,KAC5D,CAAE,mBAAoB,kBAAkB,mBAAoB,GAC3D;AACD;AAAA,MACD;AAEA,YAAM,eAAe;AAGrB,YAAM,eAAe,SAAU,eAAgB;AAC/C,YAAO,MAAM;AACZ,wBAAiB,CAAE,eAAgB,CAAE;AACrC,cAAM,aAAa,cAAe,eAAgB;AAElD;AAAA,UACC;AAAA,UACA,aAAa,YAAY,MAAO,GAAG,QAAS;AAAA,QAC7C;AACA;AAAA,UACC,qBAAsB,eAAgB;AAAA,UACtC,aAAa,YAAY,MAAO,WAAW,CAAE;AAAA,QAC9C;AACA;AAAA,UACC,YAAa,gBAAiB;AAAA,UAC9B,aAAa;AAAA,UACb;AAAA,UACA;AAAA,QACD;AAAA,MACD,CAAE;AAAA,IACH;AAEA,YAAQ,iBAAkB,WAAW,SAAU;AAC/C,WAAO,MAAM;AACZ,cAAQ,oBAAqB,WAAW,SAAU;AAAA,IACnD;AAAA,EACD,GAAG,CAAC,CAAE;AACP;",
6
6
  "names": []
7
7
  }
@@ -51,7 +51,7 @@ var PatternEdit = ({ attributes, clientId }) => {
51
51
  if (!hasRecursionError && selectedPattern?.blocks) {
52
52
  try {
53
53
  parsePatternDependencies(selectedPattern);
54
- } catch (error) {
54
+ } catch {
55
55
  setHasRecursionError(true);
56
56
  return;
57
57
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/pattern/edit.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { cloneBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch, useRegistry } from '@wordpress/data';\nimport { useState, useEffect } from '@wordpress/element';\nimport {\n\tWarning,\n\tstore as blockEditorStore,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { useParsePatternDependencies } from './recursion-detector';\n\nconst PatternEdit = ( { attributes, clientId } ) => {\n\tconst registry = useRegistry();\n\tconst selectedPattern = useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).__experimentalGetParsedPattern(\n\t\t\t\tattributes.slug\n\t\t\t),\n\t\t[ attributes.slug ]\n\t);\n\n\tconst currentThemeStylesheet = useSelect(\n\t\t( select ) => select( coreStore ).getCurrentTheme()?.stylesheet,\n\t\t[]\n\t);\n\n\tconst {\n\t\treplaceBlocks,\n\t\tsetBlockEditingMode,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t} = useDispatch( blockEditorStore );\n\tconst { getBlockRootClientId, getBlockEditingMode } =\n\t\tuseSelect( blockEditorStore );\n\n\tconst [ hasRecursionError, setHasRecursionError ] = useState( false );\n\tconst parsePatternDependencies = useParsePatternDependencies();\n\n\t// Duplicated in packages/editor/src/components/start-template-options/index.js.\n\tfunction injectThemeAttributeInBlockTemplateContent( block ) {\n\t\tif (\n\t\t\tblock.innerBlocks.find(\n\t\t\t\t( innerBlock ) => innerBlock.name === 'core/template-part'\n\t\t\t)\n\t\t) {\n\t\t\tblock.innerBlocks = block.innerBlocks.map( ( innerBlock ) => {\n\t\t\t\tif (\n\t\t\t\t\tinnerBlock.name === 'core/template-part' &&\n\t\t\t\t\tinnerBlock.attributes.theme === undefined\n\t\t\t\t) {\n\t\t\t\t\tinnerBlock.attributes.theme = currentThemeStylesheet;\n\t\t\t\t}\n\t\t\t\treturn innerBlock;\n\t\t\t} );\n\t\t}\n\n\t\tif (\n\t\t\tblock.name === 'core/template-part' &&\n\t\t\tblock.attributes.theme === undefined\n\t\t) {\n\t\t\tblock.attributes.theme = currentThemeStylesheet;\n\t\t}\n\t\treturn block;\n\t}\n\n\t// Run this effect when the component loads.\n\t// This adds the Pattern's contents to the post.\n\t// This change won't be saved.\n\t// It will continue to pull from the pattern file unless changes are made to its respective template part.\n\tuseEffect( () => {\n\t\tif ( ! hasRecursionError && selectedPattern?.blocks ) {\n\t\t\ttry {\n\t\t\t\tparsePatternDependencies( selectedPattern );\n\t\t\t} catch ( error ) {\n\t\t\t\tsetHasRecursionError( true );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// We batch updates to block list settings to avoid triggering cascading renders\n\t\t\t// for each container block included in a tree and optimize initial render.\n\t\t\t// Since the above uses microtasks, we need to use a microtask here as well,\n\t\t\t// because nested pattern blocks cannot be inserted if the parent block supports\n\t\t\t// inner blocks but doesn't have blockSettings in the state.\n\t\t\twindow.queueMicrotask( () => {\n\t\t\t\tconst rootClientId = getBlockRootClientId( clientId );\n\t\t\t\t// Clone blocks from the pattern before insertion to ensure they receive\n\t\t\t\t// distinct client ids. See https://github.com/WordPress/gutenberg/issues/50628.\n\t\t\t\tconst clonedBlocks = selectedPattern.blocks.map( ( block ) =>\n\t\t\t\t\tcloneBlock(\n\t\t\t\t\t\tinjectThemeAttributeInBlockTemplateContent( block )\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t\t// If the pattern has a single block and categories, we should add the\n\t\t\t\t// categories of the pattern to the block's metadata.\n\t\t\t\tif (\n\t\t\t\t\tclonedBlocks.length === 1 &&\n\t\t\t\t\tselectedPattern.categories?.length > 0\n\t\t\t\t) {\n\t\t\t\t\tclonedBlocks[ 0 ].attributes = {\n\t\t\t\t\t\t...clonedBlocks[ 0 ].attributes,\n\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\t...clonedBlocks[ 0 ].attributes.metadata,\n\t\t\t\t\t\t\tcategories: selectedPattern.categories,\n\t\t\t\t\t\t\tpatternName: selectedPattern.name,\n\t\t\t\t\t\t\tname:\n\t\t\t\t\t\t\t\tclonedBlocks[ 0 ].attributes.metadata.name ||\n\t\t\t\t\t\t\t\tselectedPattern.title,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tconst rootEditingMode = getBlockEditingMode( rootClientId );\n\t\t\t\tregistry.batch( () => {\n\t\t\t\t\t// Temporarily set the root block to default mode to allow replacing the pattern.\n\t\t\t\t\t// This could happen when the page is disabling edits of non-content blocks.\n\t\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\t\tsetBlockEditingMode( rootClientId, 'default' );\n\t\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\t\treplaceBlocks( clientId, clonedBlocks );\n\t\t\t\t\t// Restore the root block's original mode.\n\t\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\t\tsetBlockEditingMode( rootClientId, rootEditingMode );\n\t\t\t\t} );\n\t\t\t} );\n\t\t}\n\t}, [\n\t\tclientId,\n\t\thasRecursionError,\n\t\tselectedPattern,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t\treplaceBlocks,\n\t\tgetBlockEditingMode,\n\t\tsetBlockEditingMode,\n\t\tgetBlockRootClientId,\n\t] );\n\n\tconst props = useBlockProps();\n\n\tif ( hasRecursionError ) {\n\t\treturn (\n\t\t\t<div { ...props }>\n\t\t\t\t<Warning>\n\t\t\t\t\t{ sprintf(\n\t\t\t\t\t\t// translators: A warning in which %s is the name of a pattern.\n\t\t\t\t\t\t__( 'Pattern \"%s\" cannot be rendered inside itself.' ),\n\t\t\t\t\t\tselectedPattern?.name\n\t\t\t\t\t) }\n\t\t\t\t</Warning>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn <div { ...props } />;\n};\n\nexport default PatternEdit;\n"],
5
- "mappings": ";AAGA,SAAS,kBAAkB;AAC3B,SAAS,WAAW,aAAa,mBAAmB;AACpD,SAAS,UAAU,iBAAiB;AACpC;AAAA,EACC;AAAA,EACA,SAAS;AAAA,EACT;AAAA,OACM;AACP,SAAS,SAAS,iBAAiB;AACnC,SAAS,IAAI,eAAe;AAK5B,SAAS,mCAAmC;AAkIxC;AAhIJ,IAAM,cAAc,CAAE,EAAE,YAAY,SAAS,MAAO;AAC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B,gBAAgB,YAAY,SAAS,GACpC;AACD,uBAAc,CAAE,EAAE,aAAa;AAAA,YAC9B,GAAG,aAAc,CAAE,EAAE;AAAA,YACrB,UAAU;AAAA,cACT,GAAG,aAAc,CAAE,EAAE,WAAW;AAAA,cAChC,YAAY,gBAAgB;AAAA,cAC5B,aAAa,gBAAgB;AAAA,cAC7B,MACC,aAAc,CAAE,EAAE,WAAW,SAAS,QACtC,gBAAgB;AAAA,YAClB;AAAA,UACD;AAAA,QACD;AACA,cAAM,kBAAkB,oBAAqB,YAAa;AAC1D,iBAAS,MAAO,MAAM;AAGrB,kDAAwC;AACxC,8BAAqB,cAAc,SAAU;AAC7C,kDAAwC;AACxC,wBAAe,UAAU,YAAa;AAEtC,kDAAwC;AACxC,8BAAqB,cAAc,eAAgB;AAAA,QACpD,CAAE;AAAA,MACH,CAAE;AAAA,IACH;AAAA,EACD,GAAG;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,CAAE;AAEF,QAAM,QAAQ,cAAc;AAE5B,MAAK,mBAAoB;AACxB,WACC,oBAAC,SAAM,GAAG,OACT,8BAAC,WACE;AAAA;AAAA,MAED,GAAI,gDAAiD;AAAA,MACrD,iBAAiB;AAAA,IAClB,GACD,GACD;AAAA,EAEF;AAEA,SAAO,oBAAC,SAAM,GAAG,OAAQ;AAC1B;AAEA,IAAO,eAAQ;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { cloneBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch, useRegistry } from '@wordpress/data';\nimport { useState, useEffect } from '@wordpress/element';\nimport {\n\tWarning,\n\tstore as blockEditorStore,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { useParsePatternDependencies } from './recursion-detector';\n\nconst PatternEdit = ( { attributes, clientId } ) => {\n\tconst registry = useRegistry();\n\tconst selectedPattern = useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).__experimentalGetParsedPattern(\n\t\t\t\tattributes.slug\n\t\t\t),\n\t\t[ attributes.slug ]\n\t);\n\n\tconst currentThemeStylesheet = useSelect(\n\t\t( select ) => select( coreStore ).getCurrentTheme()?.stylesheet,\n\t\t[]\n\t);\n\n\tconst {\n\t\treplaceBlocks,\n\t\tsetBlockEditingMode,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t} = useDispatch( blockEditorStore );\n\tconst { getBlockRootClientId, getBlockEditingMode } =\n\t\tuseSelect( blockEditorStore );\n\n\tconst [ hasRecursionError, setHasRecursionError ] = useState( false );\n\tconst parsePatternDependencies = useParsePatternDependencies();\n\n\t// Duplicated in packages/editor/src/components/start-template-options/index.js.\n\tfunction injectThemeAttributeInBlockTemplateContent( block ) {\n\t\tif (\n\t\t\tblock.innerBlocks.find(\n\t\t\t\t( innerBlock ) => innerBlock.name === 'core/template-part'\n\t\t\t)\n\t\t) {\n\t\t\tblock.innerBlocks = block.innerBlocks.map( ( innerBlock ) => {\n\t\t\t\tif (\n\t\t\t\t\tinnerBlock.name === 'core/template-part' &&\n\t\t\t\t\tinnerBlock.attributes.theme === undefined\n\t\t\t\t) {\n\t\t\t\t\tinnerBlock.attributes.theme = currentThemeStylesheet;\n\t\t\t\t}\n\t\t\t\treturn innerBlock;\n\t\t\t} );\n\t\t}\n\n\t\tif (\n\t\t\tblock.name === 'core/template-part' &&\n\t\t\tblock.attributes.theme === undefined\n\t\t) {\n\t\t\tblock.attributes.theme = currentThemeStylesheet;\n\t\t}\n\t\treturn block;\n\t}\n\n\t// Run this effect when the component loads.\n\t// This adds the Pattern's contents to the post.\n\t// This change won't be saved.\n\t// It will continue to pull from the pattern file unless changes are made to its respective template part.\n\tuseEffect( () => {\n\t\tif ( ! hasRecursionError && selectedPattern?.blocks ) {\n\t\t\ttry {\n\t\t\t\tparsePatternDependencies( selectedPattern );\n\t\t\t} catch {\n\t\t\t\tsetHasRecursionError( true );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// We batch updates to block list settings to avoid triggering cascading renders\n\t\t\t// for each container block included in a tree and optimize initial render.\n\t\t\t// Since the above uses microtasks, we need to use a microtask here as well,\n\t\t\t// because nested pattern blocks cannot be inserted if the parent block supports\n\t\t\t// inner blocks but doesn't have blockSettings in the state.\n\t\t\twindow.queueMicrotask( () => {\n\t\t\t\tconst rootClientId = getBlockRootClientId( clientId );\n\t\t\t\t// Clone blocks from the pattern before insertion to ensure they receive\n\t\t\t\t// distinct client ids. See https://github.com/WordPress/gutenberg/issues/50628.\n\t\t\t\tconst clonedBlocks = selectedPattern.blocks.map( ( block ) =>\n\t\t\t\t\tcloneBlock(\n\t\t\t\t\t\tinjectThemeAttributeInBlockTemplateContent( block )\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t\t// If the pattern has a single block and categories, we should add the\n\t\t\t\t// categories of the pattern to the block's metadata.\n\t\t\t\tif (\n\t\t\t\t\tclonedBlocks.length === 1 &&\n\t\t\t\t\tselectedPattern.categories?.length > 0\n\t\t\t\t) {\n\t\t\t\t\tclonedBlocks[ 0 ].attributes = {\n\t\t\t\t\t\t...clonedBlocks[ 0 ].attributes,\n\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\t...clonedBlocks[ 0 ].attributes.metadata,\n\t\t\t\t\t\t\tcategories: selectedPattern.categories,\n\t\t\t\t\t\t\tpatternName: selectedPattern.name,\n\t\t\t\t\t\t\tname:\n\t\t\t\t\t\t\t\tclonedBlocks[ 0 ].attributes.metadata.name ||\n\t\t\t\t\t\t\t\tselectedPattern.title,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tconst rootEditingMode = getBlockEditingMode( rootClientId );\n\t\t\t\tregistry.batch( () => {\n\t\t\t\t\t// Temporarily set the root block to default mode to allow replacing the pattern.\n\t\t\t\t\t// This could happen when the page is disabling edits of non-content blocks.\n\t\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\t\tsetBlockEditingMode( rootClientId, 'default' );\n\t\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\t\treplaceBlocks( clientId, clonedBlocks );\n\t\t\t\t\t// Restore the root block's original mode.\n\t\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\t\tsetBlockEditingMode( rootClientId, rootEditingMode );\n\t\t\t\t} );\n\t\t\t} );\n\t\t}\n\t}, [\n\t\tclientId,\n\t\thasRecursionError,\n\t\tselectedPattern,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t\treplaceBlocks,\n\t\tgetBlockEditingMode,\n\t\tsetBlockEditingMode,\n\t\tgetBlockRootClientId,\n\t] );\n\n\tconst props = useBlockProps();\n\n\tif ( hasRecursionError ) {\n\t\treturn (\n\t\t\t<div { ...props }>\n\t\t\t\t<Warning>\n\t\t\t\t\t{ sprintf(\n\t\t\t\t\t\t// translators: A warning in which %s is the name of a pattern.\n\t\t\t\t\t\t__( 'Pattern \"%s\" cannot be rendered inside itself.' ),\n\t\t\t\t\t\tselectedPattern?.name\n\t\t\t\t\t) }\n\t\t\t\t</Warning>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn <div { ...props } />;\n};\n\nexport default PatternEdit;\n"],
5
+ "mappings": ";AAGA,SAAS,kBAAkB;AAC3B,SAAS,WAAW,aAAa,mBAAmB;AACpD,SAAS,UAAU,iBAAiB;AACpC;AAAA,EACC;AAAA,EACA,SAAS;AAAA,EACT;AAAA,OACM;AACP,SAAS,SAAS,iBAAiB;AACnC,SAAS,IAAI,eAAe;AAK5B,SAAS,mCAAmC;AAkIxC;AAhIJ,IAAM,cAAc,CAAE,EAAE,YAAY,SAAS,MAAO;AACnD,QAAM,WAAW,YAAY;AAC7B,QAAM,kBAAkB;AAAA,IACvB,CAAE,WACD,OAAQ,gBAAiB,EAAE;AAAA,MAC1B,WAAW;AAAA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,cACT,GAAG,aAAc,CAAE,EAAE,WAAW;AAAA,cAChC,YAAY,gBAAgB;AAAA,cAC5B,aAAa,gBAAgB;AAAA,cAC7B,MACC,aAAc,CAAE,EAAE,WAAW,SAAS,QACtC,gBAAgB;AAAA,YAClB;AAAA,UACD;AAAA,QACD;AACA,cAAM,kBAAkB,oBAAqB,YAAa;AAC1D,iBAAS,MAAO,MAAM;AAGrB,kDAAwC;AACxC,8BAAqB,cAAc,SAAU;AAC7C,kDAAwC;AACxC,wBAAe,UAAU,YAAa;AAEtC,kDAAwC;AACxC,8BAAqB,cAAc,eAAgB;AAAA,QACpD,CAAE;AAAA,MACH,CAAE;AAAA,IACH;AAAA,EACD,GAAG;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,CAAE;AAEF,QAAM,QAAQ,cAAc;AAE5B,MAAK,mBAAoB;AACxB,WACC,oBAAC,SAAM,GAAG,OACT,8BAAC,WACE;AAAA;AAAA,MAED,GAAI,gDAAiD;AAAA,MACrD,iBAAiB;AAAA,IAClB,GACD,GACD;AAAA,EAEF;AAEA,SAAO,oBAAC,SAAM,GAAG,OAAQ;AAC1B;AAEA,IAAO,eAAQ;",
6
6
  "names": []
7
7
  }
@@ -42,10 +42,6 @@
42
42
  "query": {
43
43
  "type": "object",
44
44
  "default": {}
45
- },
46
- "isSearchFieldHidden": {
47
- "type": "boolean",
48
- "default": false
49
45
  }
50
46
  },
51
47
  "supports": {
@@ -92,5 +88,9 @@
92
88
  "html": false
93
89
  },
94
90
  "editorStyle": "wp-block-search-editor",
95
- "style": "wp-block-search"
91
+ "style": "wp-block-search",
92
+ "selectors": {
93
+ "color": ".wp-block-search .wp-block-search__button, .wp-block-search.wp-block-search__no-button .wp-block-search__input",
94
+ "border": ".wp-block-search.wp-block-search__button-outside .wp-block-search__input, .wp-block-search.wp-block-search__button-outside .wp-block-search__button, .wp-block-search.wp-block-search__no-button .wp-block-search__input, .wp-block-search.wp-block-search__button-only .wp-block-search__input, .wp-block-search.wp-block-search__button-only .wp-block-search__button, .wp-block-search.wp-block-search__button-inside .wp-block-search__inside-wrapper"
95
+ }
96
96
  }
@@ -57,7 +57,6 @@ function SearchEdit({
57
57
  buttonText,
58
58
  buttonPosition,
59
59
  buttonUseIcon,
60
- isSearchFieldHidden,
61
60
  style
62
61
  } = attributes;
63
62
  const wasJustInsertedIntoNavigationBlock = useSelect(
@@ -112,27 +111,13 @@ function SearchEdit({
112
111
  const isButtonPositionOutside = "button-outside" === buttonPosition;
113
112
  const hasNoButton = "no-button" === buttonPosition;
114
113
  const hasOnlyButton = "button-only" === buttonPosition;
114
+ const isSearchFieldHidden = hasOnlyButton && !isSelected;
115
115
  const searchFieldRef = useRef();
116
116
  const buttonRef = useRef();
117
117
  const units = useCustomUnits({
118
118
  availableUnits: ["%", "px"],
119
119
  defaultValues: { "%": PC_WIDTH_DEFAULT, px: PX_WIDTH_DEFAULT }
120
120
  });
121
- useEffect(() => {
122
- if (hasOnlyButton && !isSelected) {
123
- setAttributes({
124
- isSearchFieldHidden: true
125
- });
126
- }
127
- }, [hasOnlyButton, isSelected, setAttributes]);
128
- useEffect(() => {
129
- if (!hasOnlyButton || !isSelected) {
130
- return;
131
- }
132
- setAttributes({
133
- isSearchFieldHidden: false
134
- });
135
- }, [hasOnlyButton, isSelected, setAttributes, width]);
136
121
  const getBlockClassNames = () => {
137
122
  return clsx(
138
123
  className,
@@ -142,7 +127,7 @@ function SearchEdit({
142
127
  hasOnlyButton ? "wp-block-search__button-only" : void 0,
143
128
  !buttonUseIcon && !hasNoButton ? "wp-block-search__text-button" : void 0,
144
129
  buttonUseIcon && !hasNoButton ? "wp-block-search__icon-button" : void 0,
145
- hasOnlyButton && isSearchFieldHidden ? "wp-block-search__searchfield-hidden" : void 0
130
+ isSearchFieldHidden ? "wp-block-search__searchfield-hidden" : void 0
146
131
  );
147
132
  };
148
133
  const buttonPositionControls = [
@@ -175,10 +160,12 @@ function SearchEdit({
175
160
  const renderTextField = () => {
176
161
  const textFieldClasses = clsx(
177
162
  "wp-block-search__input",
163
+ hasNoButton ? colorProps.className : void 0,
178
164
  isButtonPositionInside ? void 0 : borderProps.className,
179
165
  typographyProps.className
180
166
  );
181
167
  const textFieldStyles = {
168
+ ...hasNoButton ? colorProps.style : {},
182
169
  ...isButtonPositionInside ? {
183
170
  borderRadius: borderProps.style?.borderRadius,
184
171
  borderTopLeftRadius: borderProps.style?.borderTopLeftRadius,
@@ -223,13 +210,6 @@ function SearchEdit({
223
210
  borderBottomRightRadius: borderProps.style?.borderBottomRightRadius
224
211
  } : borderProps.style
225
212
  };
226
- const handleButtonClick = () => {
227
- if (hasOnlyButton) {
228
- setAttributes({
229
- isSearchFieldHidden: !isSearchFieldHidden
230
- });
231
- }
232
- };
233
213
  return /* @__PURE__ */ jsxs(Fragment, { children: [
234
214
  buttonUseIcon && /* @__PURE__ */ jsx(
235
215
  "button",
@@ -238,7 +218,6 @@ function SearchEdit({
238
218
  className: buttonClasses,
239
219
  style: buttonStyles,
240
220
  "aria-label": buttonText ? stripHTML(buttonText) : __("Search"),
241
- onClick: handleButtonClick,
242
221
  ref: buttonRef,
243
222
  children: /* @__PURE__ */ jsx(Icon, { icon: search })
244
223
  }
@@ -253,8 +232,7 @@ function SearchEdit({
253
232
  placeholder: __("Add button text\u2026"),
254
233
  withoutInteractiveFormatting: true,
255
234
  value: buttonText,
256
- onChange: (html) => setAttributes({ buttonText: html }),
257
- onClick: handleButtonClick
235
+ onChange: (html) => setAttributes({ buttonText: html })
258
236
  }
259
237
  )
260
238
  ] });
@@ -270,8 +248,7 @@ function SearchEdit({
270
248
  widthUnit: void 0,
271
249
  showLabel: true,
272
250
  buttonUseIcon: false,
273
- buttonPosition: "button-outside",
274
- isSearchFieldHidden: false
251
+ buttonPosition: "button-outside"
275
252
  });
276
253
  },
277
254
  dropdownMenuProps,
@@ -306,8 +283,7 @@ function SearchEdit({
306
283
  label: __("Button position"),
307
284
  onDeselect: () => {
308
285
  setAttributes({
309
- buttonPosition: "button-outside",
310
- isSearchFieldHidden: false
286
+ buttonPosition: "button-outside"
311
287
  });
312
288
  },
313
289
  isShownByDefault: true,
@@ -319,8 +295,7 @@ function SearchEdit({
319
295
  label: __("Button position"),
320
296
  onChange: (value) => {
321
297
  setAttributes({
322
- buttonPosition: value,
323
- isSearchFieldHidden: value === "button-only"
298
+ buttonPosition: value
324
299
  });
325
300
  },
326
301
  options: buttonPositionControls