@wordpress/block-library 8.3.2 → 8.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/button/edit.js +3 -1
  3. package/build/button/edit.js.map +1 -1
  4. package/build/button/index.js +17 -6
  5. package/build/button/index.js.map +1 -1
  6. package/build/cover/edit/index.js +3 -2
  7. package/build/cover/edit/index.js.map +1 -1
  8. package/build/file/index.js +10 -1
  9. package/build/file/index.js.map +1 -1
  10. package/build/image/image.js +21 -15
  11. package/build/image/image.js.map +1 -1
  12. package/build/latest-comments/edit.js +6 -2
  13. package/build/latest-comments/edit.js.map +1 -1
  14. package/build/latest-comments/index.js +13 -0
  15. package/build/latest-comments/index.js.map +1 -1
  16. package/build/navigation/edit/index.js +2 -28
  17. package/build/navigation/edit/index.js.map +1 -1
  18. package/build/navigation/edit/menu-inspector-controls.js +5 -6
  19. package/build/navigation/edit/menu-inspector-controls.js.map +1 -1
  20. package/build/navigation/edit/navigation-menu-selector.js +14 -11
  21. package/build/navigation/edit/navigation-menu-selector.js.map +1 -1
  22. package/build/navigation/edit/unsaved-inner-blocks.js +4 -5
  23. package/build/navigation/edit/unsaved-inner-blocks.js.map +1 -1
  24. package/build/navigation/edit/use-create-navigation-menu.js +11 -2
  25. package/build/navigation/edit/use-create-navigation-menu.js.map +1 -1
  26. package/build/navigation/use-navigation-menu.js +1 -1
  27. package/build/navigation/use-navigation-menu.js.map +1 -1
  28. package/build/navigation-link/edit.js +4 -0
  29. package/build/navigation-link/edit.js.map +1 -1
  30. package/build/navigation-link/link-ui.js +1 -0
  31. package/build/navigation-link/link-ui.js.map +1 -1
  32. package/build/navigation-submenu/edit.js +4 -0
  33. package/build/navigation-submenu/edit.js.map +1 -1
  34. package/build/page-list/edit.js +5 -4
  35. package/build/page-list/edit.js.map +1 -1
  36. package/build/page-list/use-convert-to-navigation-links.js +61 -5
  37. package/build/page-list/use-convert-to-navigation-links.js.map +1 -1
  38. package/build/post-excerpt/edit.js +49 -3
  39. package/build/post-excerpt/edit.js.map +1 -1
  40. package/build/post-excerpt/index.js +4 -0
  41. package/build/post-excerpt/index.js.map +1 -1
  42. package/build/post-featured-image/dimension-controls.js +52 -1
  43. package/build/post-featured-image/dimension-controls.js.map +1 -1
  44. package/build/post-featured-image/edit.js +9 -4
  45. package/build/post-featured-image/edit.js.map +1 -1
  46. package/build/post-featured-image/index.js +3 -0
  47. package/build/post-featured-image/index.js.map +1 -1
  48. package/build/{experiments.js → private-apis.js} +3 -3
  49. package/build/private-apis.js.map +1 -0
  50. package/build/site-logo/edit.js +7 -11
  51. package/build/site-logo/edit.js.map +1 -1
  52. package/build/table/edit.js +3 -3
  53. package/build/table/edit.js.map +1 -1
  54. package/build/table-of-contents/utils.js +1 -1
  55. package/build/table-of-contents/utils.js.map +1 -1
  56. package/build/verse/index.js +6 -0
  57. package/build/verse/index.js.map +1 -1
  58. package/build-module/button/edit.js +2 -1
  59. package/build-module/button/edit.js.map +1 -1
  60. package/build-module/button/index.js +17 -6
  61. package/build-module/button/index.js.map +1 -1
  62. package/build-module/cover/edit/index.js +3 -2
  63. package/build-module/cover/edit/index.js.map +1 -1
  64. package/build-module/file/index.js +10 -1
  65. package/build-module/file/index.js.map +1 -1
  66. package/build-module/image/image.js +21 -15
  67. package/build-module/image/image.js.map +1 -1
  68. package/build-module/latest-comments/edit.js +6 -2
  69. package/build-module/latest-comments/edit.js.map +1 -1
  70. package/build-module/latest-comments/index.js +13 -0
  71. package/build-module/latest-comments/index.js.map +1 -1
  72. package/build-module/navigation/edit/index.js +3 -29
  73. package/build-module/navigation/edit/index.js.map +1 -1
  74. package/build-module/navigation/edit/menu-inspector-controls.js +5 -5
  75. package/build-module/navigation/edit/menu-inspector-controls.js.map +1 -1
  76. package/build-module/navigation/edit/navigation-menu-selector.js +14 -10
  77. package/build-module/navigation/edit/navigation-menu-selector.js.map +1 -1
  78. package/build-module/navigation/edit/unsaved-inner-blocks.js +4 -5
  79. package/build-module/navigation/edit/unsaved-inner-blocks.js.map +1 -1
  80. package/build-module/navigation/edit/use-create-navigation-menu.js +11 -2
  81. package/build-module/navigation/edit/use-create-navigation-menu.js.map +1 -1
  82. package/build-module/navigation/use-navigation-menu.js +1 -1
  83. package/build-module/navigation/use-navigation-menu.js.map +1 -1
  84. package/build-module/navigation-link/edit.js +4 -0
  85. package/build-module/navigation-link/edit.js.map +1 -1
  86. package/build-module/navigation-link/link-ui.js +1 -0
  87. package/build-module/navigation-link/link-ui.js.map +1 -1
  88. package/build-module/navigation-submenu/edit.js +4 -0
  89. package/build-module/navigation-submenu/edit.js.map +1 -1
  90. package/build-module/page-list/edit.js +5 -4
  91. package/build-module/page-list/edit.js.map +1 -1
  92. package/build-module/page-list/use-convert-to-navigation-links.js +61 -5
  93. package/build-module/page-list/use-convert-to-navigation-links.js.map +1 -1
  94. package/build-module/post-excerpt/edit.js +52 -5
  95. package/build-module/post-excerpt/edit.js.map +1 -1
  96. package/build-module/post-excerpt/index.js +4 -0
  97. package/build-module/post-excerpt/index.js.map +1 -1
  98. package/build-module/post-featured-image/dimension-controls.js +52 -1
  99. package/build-module/post-featured-image/dimension-controls.js.map +1 -1
  100. package/build-module/post-featured-image/edit.js +9 -4
  101. package/build-module/post-featured-image/edit.js.map +1 -1
  102. package/build-module/post-featured-image/index.js +3 -0
  103. package/build-module/post-featured-image/index.js.map +1 -1
  104. package/build-module/{experiments.js → private-apis.js} +2 -2
  105. package/build-module/private-apis.js.map +1 -0
  106. package/build-module/site-logo/edit.js +7 -11
  107. package/build-module/site-logo/edit.js.map +1 -1
  108. package/build-module/table/edit.js +3 -3
  109. package/build-module/table/edit.js.map +1 -1
  110. package/build-module/table-of-contents/utils.js +1 -1
  111. package/build-module/table-of-contents/utils.js.map +1 -1
  112. package/build-module/verse/index.js +6 -0
  113. package/build-module/verse/index.js.map +1 -1
  114. package/build-style/avatar/style-rtl.css +3 -0
  115. package/build-style/avatar/style.css +3 -0
  116. package/build-style/button/editor-rtl.css +31 -0
  117. package/build-style/button/editor.css +31 -0
  118. package/build-style/button/style-rtl.css +31 -0
  119. package/build-style/button/style.css +31 -0
  120. package/build-style/classic-rtl.css +5 -0
  121. package/build-style/classic.css +5 -0
  122. package/build-style/editor-rtl.css +36 -1
  123. package/build-style/editor.css +36 -1
  124. package/build-style/file/style-rtl.css +1 -0
  125. package/build-style/file/style.css +1 -0
  126. package/build-style/image/editor-rtl.css +1 -0
  127. package/build-style/image/editor.css +1 -0
  128. package/build-style/image/style-rtl.css +6 -2
  129. package/build-style/image/style.css +6 -0
  130. package/build-style/latest-comments/style-rtl.css +18 -5
  131. package/build-style/latest-comments/style.css +18 -5
  132. package/build-style/quote/style-rtl.css +5 -5
  133. package/build-style/quote/style.css +5 -5
  134. package/build-style/style-rtl.css +64 -12
  135. package/build-style/style.css +64 -10
  136. package/build-types/table-of-contents/utils.d.ts +1 -1
  137. package/package.json +30 -30
  138. package/src/avatar/index.php +67 -63
  139. package/src/avatar/style.scss +3 -0
  140. package/src/button/block.json +17 -6
  141. package/src/button/edit.js +2 -1
  142. package/src/button/editor.scss +36 -0
  143. package/src/button/style.scss +37 -1
  144. package/src/classic.scss +5 -0
  145. package/src/cover/edit/index.js +4 -1
  146. package/src/editor.scss +5 -0
  147. package/src/file/block.json +10 -1
  148. package/src/file/style.scss +1 -0
  149. package/src/image/editor.scss +1 -0
  150. package/src/image/image.js +32 -27
  151. package/src/image/style.scss +13 -0
  152. package/src/latest-comments/block.json +13 -0
  153. package/src/latest-comments/edit.js +9 -2
  154. package/src/latest-comments/style.scss +25 -7
  155. package/src/navigation/edit/index.js +1 -30
  156. package/src/navigation/edit/menu-inspector-controls.js +3 -4
  157. package/src/navigation/edit/navigation-menu-selector.js +12 -26
  158. package/src/navigation/edit/test/navigation-menu-selector.js +638 -0
  159. package/src/navigation/edit/unsaved-inner-blocks.js +29 -36
  160. package/src/navigation/edit/use-create-navigation-menu.js +13 -1
  161. package/src/navigation/index.php +8 -6
  162. package/src/navigation/use-navigation-menu.js +1 -1
  163. package/src/navigation-link/edit.js +3 -0
  164. package/src/navigation-link/link-ui.js +1 -0
  165. package/src/navigation-submenu/edit.js +3 -0
  166. package/src/page-list/edit.js +6 -5
  167. package/src/page-list/index.php +4 -4
  168. package/src/page-list/test/convert-to-links-modal.js +134 -0
  169. package/src/page-list/use-convert-to-navigation-links.js +64 -4
  170. package/src/post-excerpt/block.json +4 -0
  171. package/src/post-excerpt/edit.js +72 -7
  172. package/src/post-excerpt/index.php +29 -5
  173. package/src/post-featured-image/block.json +3 -0
  174. package/src/post-featured-image/dimension-controls.js +64 -2
  175. package/src/post-featured-image/edit.js +18 -6
  176. package/src/post-featured-image/index.php +25 -9
  177. package/src/post-title/index.php +3 -3
  178. package/src/{experiments.js → private-apis.js} +1 -1
  179. package/src/quote/style.scss +2 -2
  180. package/src/site-logo/edit.js +3 -6
  181. package/src/table/edit.js +3 -3
  182. package/src/table-of-contents/utils.ts +1 -1
  183. package/src/template-part/index.php +1 -1
  184. package/src/verse/block.json +6 -0
  185. package/tsconfig.json +24 -1
  186. package/tsconfig.tsbuildinfo +1 -1
  187. package/build/experiments.js.map +0 -1
  188. package/build/navigation/leaf-more-menu.js +0 -95
  189. package/build/navigation/leaf-more-menu.js.map +0 -1
  190. package/build-module/experiments.js.map +0 -1
  191. package/build-module/navigation/leaf-more-menu.js +0 -76
  192. package/build-module/navigation/leaf-more-menu.js.map +0 -1
  193. package/src/navigation/leaf-more-menu.js +0 -93
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-library/src/navigation-submenu/edit.js"],"names":["ALLOWED_BLOCKS","DEFAULT_BLOCK","name","useIsDraggingWithin","elementRef","isDraggingWithin","setIsDraggingWithin","ownerDocument","current","handleDragStart","event","handleDragEnter","handleDragEnd","contains","target","addEventListener","removeEventListener","NavigationSubmenuEdit","attributes","isSelected","setAttributes","mergeBlocks","onReplace","context","clientId","label","type","url","description","rel","title","showSubmenuIcon","maxNestingLevel","openSubmenusOnClick","__unstableMarkNextChangeAsNotPersistent","replaceBlock","blockEditorStore","isLinkOpen","setIsLinkOpen","popoverAnchor","setPopoverAnchor","listItemRef","itemLabelPlaceholder","ref","pagesPermissions","postsPermissions","isAtMaxNesting","isTopLevelItem","isParentOfSelectedBlock","isImmediateParentOfSelectedBlock","hasChildren","selectedBlockHasChildren","onlyDescendantIsEmptyLink","select","hasSelectedInnerBlock","getSelectedBlockClientId","getBlockParentsByBlockName","getBlock","getBlockCount","getBlockOrder","_onlyDescendantIsEmptyLink","selectedBlockId","selectedBlockChildren","length","singleBlock","prevHasChildren","test","selectLabelText","focus","defaultView","selection","getSelection","range","createRange","selectNodeContents","removeAllRanges","addRange","userCanCreate","canCreate","textColor","customTextColor","backgroundColor","customBackgroundColor","onKeyDown","isKeyboardEvent","primary","blockProps","className","style","color","innerBlocksColors","allowedBlocks","filter","blockName","navigationChildBlockProps","innerBlocksProps","__experimentalDefaultBlock","__experimentalDirectInsert","__experimentalCaptureToolbars","renderAppender","InnerBlocks","ButtonBlockAppender","ParentElement","transformToLink","newLinkBlock","canConvertToLink","linkIcon","displayShortcut","removeSubmenu","labelValue","urlValue","descriptionValue","titleValue","relValue","updatedValue"],"mappings":";;;;;;;;;AA6BA;;AA1BA;;AAKA;;AACA;;AAOA;;AACA;;AACA;;AAUA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AAEA;;AACA;;AACA;;AA5CA;AACA;AACA;;AAGA;AACA;AACA;;AA8BA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,MAAMA,cAAc,GAAG,CACtB,sBADsB,EAEtB,yBAFsB,EAGtB,gBAHsB,CAAvB;AAMA,MAAMC,aAAa,GAAG;AACrBC,EAAAA,IAAI,EAAE;AADe,CAAtB;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,mBAAmB,GAAKC,UAA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IAAA,SAAS,EAAGC,SATb;AAUC,kBAAa,cAAI,sBAAJ,CAVd;AAWC,IAAA,WAAW,EAAGoB,oBAXf;AAYC,IAAA,4BAA4B,MAZ7B;AAaC,IAAA,cAAc,EAAG,CAChB,WADgB,EAEhB,aAFgB,EAGhB,YAHgB,EAIhB,oBAJgB,CAblB;AAmBC,IAAA,OAAO,EAAG,MAAM;AACf,UAAK,CAAET,mBAAF,IAAyB,CAAEN,GAAhC,EAAsC;AACrCW,QAAAA,aAAa,CAAE,IAAF,CAAb;AACA;AACD;AAvBF,IAHF,EA6BG,CAAEL,mBAAF,IAAyBI,UAAzB,IACD,4BAAC,cAAD;AACC,IAAA,SAAS,EAAC,6CADX;AAEC,IAAA,QAAQ,EAAGb,QAFZ;AAGC,IAAA,IAAI,EAAGN,UAHR;AAIC,IAAA,OAAO,EAAG,MAAMoB,aAAa,CAAE,KAAF,CAJ9B;AAKC,IAAA,MAAM,EAAGC,aALV;AAMC,IAAA,mBAAmB,EAAGsC,aANvB;AAOC,IAAA,QAAQ,EAAG,MAAM;AAChBzD,MAAAA,aAAa,CAAE;AAAEO,QAAAA,GAAG,EAAE;AAAP,OAAF,CAAb;AACA,uBAAO,cAAI,eAAJ,CAAP,EAA8B,WAA9B;AACA,KAVF;AAWC,IAAA,QAAQ,EAAKuF,YAAF,IAAoB;AAC9B,8CACCA,YADD,EAEC9F,aAFD,EAGCF,UAHD;AAKA;AAjBF,IA9BF,CAFD,EAqDG,CAAEa,eAAe,IAAIE,mBAArB,KACD;AAAM,IAAA,SAAS,EAAC;AAAhB,KACC,4BAAC,uBAAD,OADD,CAtDF,EA0DC,mCAAU8D,gBAAV,CA1DD,CA7ED,CADD;AA4IA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport {\n\tPanelBody,\n\tTextControl,\n\tTextareaControl,\n\tToolbarButton,\n\tToolbarGroup,\n} from '@wordpress/components';\nimport { displayShortcut, isKeyboardEvent } from '@wordpress/keycodes';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tBlockControls,\n\tInnerBlocks,\n\tuseInnerBlocksProps,\n\tInspectorControls,\n\tRichText,\n\tuseBlockProps,\n\tstore as blockEditorStore,\n\tgetColorClassName,\n} from '@wordpress/block-editor';\nimport { isURL, prependHTTP } from '@wordpress/url';\nimport { useState, useEffect, useRef } from '@wordpress/element';\nimport { placeCaretAtHorizontalEdge } from '@wordpress/dom';\nimport { link as linkIcon, removeSubmenu } from '@wordpress/icons';\nimport { useResourcePermissions } from '@wordpress/core-data';\nimport { speak } from '@wordpress/a11y';\nimport { createBlock } from '@wordpress/blocks';\nimport { useMergeRefs, usePrevious } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { ItemSubmenuIcon } from './icons';\nimport { name } from './block.json';\nimport { LinkUI } from '../navigation-link/link-ui';\nimport { updateAttributes } from '../navigation-link/update-attributes';\nimport {\n\tgetColors,\n\tgetNavigationChildBlockProps,\n} from '../navigation/edit/utils';\n\nconst ALLOWED_BLOCKS = [\n\t'core/navigation-link',\n\t'core/navigation-submenu',\n\t'core/page-list',\n];\n\nconst DEFAULT_BLOCK = {\n\tname: 'core/navigation-link',\n};\n\n/**\n * A React hook to determine if it's dragging within the target element.\n *\n * @typedef {import('@wordpress/element').RefObject} RefObject\n *\n * @param {RefObject<HTMLElement>} elementRef The target elementRef object.\n *\n * @return {boolean} Is dragging within the target element.\n */\nconst useIsDraggingWithin = ( elementRef ) => {\n\tconst [ isDraggingWithin, setIsDraggingWithin ] = useState( false );\n\n\tuseEffect( () => {\n\t\tconst { ownerDocument } = elementRef.current;\n\n\t\tfunction handleDragStart( event ) {\n\t\t\t// Check the first time when the dragging starts.\n\t\t\thandleDragEnter( event );\n\t\t}\n\n\t\t// Set to false whenever the user cancel the drag event by either releasing the mouse or press Escape.\n\t\tfunction handleDragEnd() {\n\t\t\tsetIsDraggingWithin( false );\n\t\t}\n\n\t\tfunction handleDragEnter( event ) {\n\t\t\t// Check if the current target is inside the item element.\n\t\t\tif ( elementRef.current.contains( event.target ) ) {\n\t\t\t\tsetIsDraggingWithin( true );\n\t\t\t} else {\n\t\t\t\tsetIsDraggingWithin( false );\n\t\t\t}\n\t\t}\n\n\t\t// Bind these events to the document to catch all drag events.\n\t\t// Ideally, we can also use `event.relatedTarget`, but sadly that\n\t\t// doesn't work in Safari.\n\t\townerDocument.addEventListener( 'dragstart', handleDragStart );\n\t\townerDocument.addEventListener( 'dragend', handleDragEnd );\n\t\townerDocument.addEventListener( 'dragenter', handleDragEnter );\n\n\t\treturn () => {\n\t\t\townerDocument.removeEventListener( 'dragstart', handleDragStart );\n\t\t\townerDocument.removeEventListener( 'dragend', handleDragEnd );\n\t\t\townerDocument.removeEventListener( 'dragenter', handleDragEnter );\n\t\t};\n\t}, [] );\n\n\treturn isDraggingWithin;\n};\n\n/**\n * @typedef {'post-type'|'custom'|'taxonomy'|'post-type-archive'} WPNavigationLinkKind\n */\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\nexport default function NavigationSubmenuEdit( {\n\tattributes,\n\tisSelected,\n\tsetAttributes,\n\tmergeBlocks,\n\tonReplace,\n\tcontext,\n\tclientId,\n} ) {\n\tconst { label, type, url, description, rel, title } = attributes;\n\n\tconst { showSubmenuIcon, maxNestingLevel, openSubmenusOnClick } = context;\n\n\tconst { __unstableMarkNextChangeAsNotPersistent, replaceBlock } =\n\t\tuseDispatch( blockEditorStore );\n\tconst [ isLinkOpen, setIsLinkOpen ] = useState( false );\n\t// Use internal state instead of a ref to make sure that the component\n\t// re-renders when the popover's anchor updates.\n\tconst [ popoverAnchor, setPopoverAnchor ] = useState( null );\n\tconst listItemRef = useRef( null );\n\tconst isDraggingWithin = useIsDraggingWithin( listItemRef );\n\tconst itemLabelPlaceholder = __( 'Add text…' );\n\tconst ref = useRef();\n\n\tconst pagesPermissions = useResourcePermissions( 'pages' );\n\tconst postsPermissions = useResourcePermissions( 'posts' );\n\n\tconst {\n\t\tisAtMaxNesting,\n\t\tisTopLevelItem,\n\t\tisParentOfSelectedBlock,\n\t\tisImmediateParentOfSelectedBlock,\n\t\thasChildren,\n\t\tselectedBlockHasChildren,\n\t\tonlyDescendantIsEmptyLink,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\thasSelectedInnerBlock,\n\t\t\t\tgetSelectedBlockClientId,\n\t\t\t\tgetBlockParentsByBlockName,\n\t\t\t\tgetBlock,\n\t\t\t\tgetBlockCount,\n\t\t\t\tgetBlockOrder,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tlet _onlyDescendantIsEmptyLink;\n\n\t\t\tconst selectedBlockId = getSelectedBlockClientId();\n\n\t\t\tconst selectedBlockChildren = getBlockOrder( selectedBlockId );\n\n\t\t\t// Check for a single descendant in the submenu. If that block\n\t\t\t// is a link block in a \"placeholder\" state with no label then\n\t\t\t// we can consider as an \"empty\" link.\n\t\t\tif ( selectedBlockChildren?.length === 1 ) {\n\t\t\t\tconst singleBlock = getBlock( selectedBlockChildren[ 0 ] );\n\n\t\t\t\t_onlyDescendantIsEmptyLink =\n\t\t\t\t\tsingleBlock?.name === 'core/navigation-link' &&\n\t\t\t\t\t! singleBlock?.attributes?.label;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tisAtMaxNesting:\n\t\t\t\t\tgetBlockParentsByBlockName( clientId, name ).length >=\n\t\t\t\t\tmaxNestingLevel,\n\t\t\t\tisTopLevelItem:\n\t\t\t\t\tgetBlockParentsByBlockName( clientId, name ).length === 0,\n\t\t\t\tisParentOfSelectedBlock: hasSelectedInnerBlock(\n\t\t\t\t\tclientId,\n\t\t\t\t\ttrue\n\t\t\t\t),\n\t\t\t\tisImmediateParentOfSelectedBlock: hasSelectedInnerBlock(\n\t\t\t\t\tclientId,\n\t\t\t\t\tfalse\n\t\t\t\t),\n\t\t\t\thasChildren: !! getBlockCount( clientId ),\n\t\t\t\tselectedBlockHasChildren: !! selectedBlockChildren?.length,\n\t\t\t\tonlyDescendantIsEmptyLink: _onlyDescendantIsEmptyLink,\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst prevHasChildren = usePrevious( hasChildren );\n\n\t// Show the LinkControl on mount if the URL is empty\n\t// ( When adding a new menu item)\n\t// This can't be done in the useState call because it conflicts\n\t// with the autofocus behavior of the BlockListBlock component.\n\tuseEffect( () => {\n\t\tif ( ! openSubmenusOnClick && ! url ) {\n\t\t\tsetIsLinkOpen( true );\n\t\t}\n\t}, [] );\n\n\t// Store the colors from context as attributes for rendering.\n\tuseEffect( () => {\n\t\t// This side-effect should not create an undo level as those should\n\t\t// only be created via user interactions. Mark this change as\n\t\t// not persistent to avoid undo level creation.\n\t\t// See https://github.com/WordPress/gutenberg/issues/34564.\n\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\tsetAttributes( { isTopLevelItem } );\n\t}, [ isTopLevelItem ] );\n\n\t/**\n\t * The hook shouldn't be necessary but due to a focus loss happening\n\t * when selecting a suggestion in the link popover, we force close on block unselection.\n\t */\n\tuseEffect( () => {\n\t\tif ( ! isSelected ) {\n\t\t\tsetIsLinkOpen( false );\n\t\t}\n\t}, [ isSelected ] );\n\n\t// If the LinkControl popover is open and the URL has changed, close the LinkControl and focus the label text.\n\tuseEffect( () => {\n\t\tif ( isLinkOpen && url ) {\n\t\t\t// Does this look like a URL and have something TLD-ish?\n\t\t\tif (\n\t\t\t\tisURL( prependHTTP( label ) ) &&\n\t\t\t\t/^.+\\.[a-z]+/.test( label )\n\t\t\t) {\n\t\t\t\t// Focus and select the label text.\n\t\t\t\tselectLabelText();\n\t\t\t} else {\n\t\t\t\t// Focus it (but do not select).\n\t\t\t\tplaceCaretAtHorizontalEdge( ref.current, true );\n\t\t\t}\n\t\t}\n\t}, [ url ] );\n\n\t/**\n\t * Focus the Link label text and select it.\n\t */\n\tfunction selectLabelText() {\n\t\tref.current.focus();\n\t\tconst { ownerDocument } = ref.current;\n\t\tconst { defaultView } = ownerDocument;\n\t\tconst selection = defaultView.getSelection();\n\t\tconst range = ownerDocument.createRange();\n\t\t// Get the range of the current ref contents so we can add this range to the selection.\n\t\trange.selectNodeContents( ref.current );\n\t\tselection.removeAllRanges();\n\t\tselection.addRange( range );\n\t}\n\n\tlet userCanCreate = false;\n\tif ( ! type || type === 'page' ) {\n\t\tuserCanCreate = pagesPermissions.canCreate;\n\t} else if ( type === 'post' ) {\n\t\tuserCanCreate = postsPermissions.canCreate;\n\t}\n\n\tconst {\n\t\ttextColor,\n\t\tcustomTextColor,\n\t\tbackgroundColor,\n\t\tcustomBackgroundColor,\n\t} = getColors( context, ! isTopLevelItem );\n\n\tfunction onKeyDown( event ) {\n\t\tif ( isKeyboardEvent.primary( event, 'k' ) ) {\n\t\t\tsetIsLinkOpen( true );\n\t\t}\n\t}\n\n\tconst blockProps = useBlockProps( {\n\t\tref: useMergeRefs( [ setPopoverAnchor, listItemRef ] ),\n\t\tclassName: classnames( 'wp-block-navigation-item', {\n\t\t\t'is-editing': isSelected || isParentOfSelectedBlock,\n\t\t\t'is-dragging-within': isDraggingWithin,\n\t\t\t'has-link': !! url,\n\t\t\t'has-child': hasChildren,\n\t\t\t'has-text-color': !! textColor || !! customTextColor,\n\t\t\t[ getColorClassName( 'color', textColor ) ]: !! textColor,\n\t\t\t'has-background': !! backgroundColor || customBackgroundColor,\n\t\t\t[ getColorClassName( 'background-color', backgroundColor ) ]:\n\t\t\t\t!! backgroundColor,\n\t\t\t'open-on-click': openSubmenusOnClick,\n\t\t} ),\n\t\tstyle: {\n\t\t\tcolor: ! textColor && customTextColor,\n\t\t\tbackgroundColor: ! backgroundColor && customBackgroundColor,\n\t\t},\n\t\tonKeyDown,\n\t} );\n\n\t// Always use overlay colors for submenus.\n\tconst innerBlocksColors = getColors( context, true );\n\n\tconst allowedBlocks = isAtMaxNesting\n\t\t? ALLOWED_BLOCKS.filter(\n\t\t\t\t( blockName ) => blockName !== 'core/navigation-submenu'\n\t\t )\n\t\t: ALLOWED_BLOCKS;\n\n\tconst navigationChildBlockProps =\n\t\tgetNavigationChildBlockProps( innerBlocksColors );\n\tconst innerBlocksProps = useInnerBlocksProps( navigationChildBlockProps, {\n\t\tallowedBlocks,\n\t\t__experimentalDefaultBlock: DEFAULT_BLOCK,\n\t\t__experimentalDirectInsert: true,\n\n\t\t// Ensure block toolbar is not too far removed from item\n\t\t// being edited.\n\t\t// see: https://github.com/WordPress/gutenberg/pull/34615.\n\t\t__experimentalCaptureToolbars: true,\n\n\t\trenderAppender:\n\t\t\tisSelected ||\n\t\t\t( isImmediateParentOfSelectedBlock &&\n\t\t\t\t! selectedBlockHasChildren ) ||\n\t\t\t// Show the appender while dragging to allow inserting element between item and the appender.\n\t\t\thasChildren\n\t\t\t\t? InnerBlocks.ButtonBlockAppender\n\t\t\t\t: false,\n\t} );\n\n\tconst ParentElement = openSubmenusOnClick ? 'button' : 'a';\n\n\tfunction transformToLink() {\n\t\tconst newLinkBlock = createBlock( 'core/navigation-link', attributes );\n\t\treplaceBlock( clientId, newLinkBlock );\n\t}\n\n\tuseEffect( () => {\n\t\t// If block becomes empty, transform to Navigation Link.\n\t\tif ( ! hasChildren && prevHasChildren ) {\n\t\t\ttransformToLink();\n\t\t}\n\t}, [ hasChildren, prevHasChildren ] );\n\n\tconst canConvertToLink =\n\t\t! selectedBlockHasChildren || onlyDescendantIsEmptyLink;\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls>\n\t\t\t\t<ToolbarGroup>\n\t\t\t\t\t{ ! openSubmenusOnClick && (\n\t\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\t\tname=\"link\"\n\t\t\t\t\t\t\ticon={ linkIcon }\n\t\t\t\t\t\t\ttitle={ __( 'Link' ) }\n\t\t\t\t\t\t\tshortcut={ displayShortcut.primary( 'k' ) }\n\t\t\t\t\t\t\tonClick={ () => setIsLinkOpen( true ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\tname=\"revert\"\n\t\t\t\t\t\ticon={ removeSubmenu }\n\t\t\t\t\t\ttitle={ __( 'Convert to Link' ) }\n\t\t\t\t\t\tonClick={ transformToLink }\n\t\t\t\t\t\tclassName=\"wp-block-navigation__submenu__revert\"\n\t\t\t\t\t\tisDisabled={ ! canConvertToLink }\n\t\t\t\t\t/>\n\t\t\t\t</ToolbarGroup>\n\t\t\t</BlockControls>\n\t\t\t{ /* Warning, this duplicated in packages/block-library/src/navigation-link/edit.js */ }\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody title={ __( 'Link settings' ) }>\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tvalue={ label || '' }\n\t\t\t\t\t\tonChange={ ( labelValue ) => {\n\t\t\t\t\t\t\tsetAttributes( { label: labelValue } );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tlabel={ __( 'Label' ) }\n\t\t\t\t\t\tautoComplete=\"off\"\n\t\t\t\t\t/>\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tvalue={ url || '' }\n\t\t\t\t\t\tonChange={ ( urlValue ) => {\n\t\t\t\t\t\t\tsetAttributes( { url: urlValue } );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tlabel={ __( 'URL' ) }\n\t\t\t\t\t\tautoComplete=\"off\"\n\t\t\t\t\t/>\n\t\t\t\t\t<TextareaControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tvalue={ description || '' }\n\t\t\t\t\t\tonChange={ ( descriptionValue ) => {\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tdescription: descriptionValue,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tlabel={ __( 'Description' ) }\n\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t'The description will be displayed in the menu if the current theme supports it.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t/>\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tvalue={ title || '' }\n\t\t\t\t\t\tonChange={ ( titleValue ) => {\n\t\t\t\t\t\t\tsetAttributes( { title: titleValue } );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tlabel={ __( 'Link title' ) }\n\t\t\t\t\t\tautoComplete=\"off\"\n\t\t\t\t\t/>\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tvalue={ rel || '' }\n\t\t\t\t\t\tonChange={ ( relValue ) => {\n\t\t\t\t\t\t\tsetAttributes( { rel: relValue } );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tlabel={ __( 'Link rel' ) }\n\t\t\t\t\t\tautoComplete=\"off\"\n\t\t\t\t\t/>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t<div { ...blockProps }>\n\t\t\t\t{ /* eslint-disable jsx-a11y/anchor-is-valid */ }\n\t\t\t\t<ParentElement className=\"wp-block-navigation-item__content\">\n\t\t\t\t\t{ /* eslint-enable */ }\n\t\t\t\t\t{\n\t\t\t\t\t\t<RichText\n\t\t\t\t\t\t\tref={ ref }\n\t\t\t\t\t\t\tidentifier=\"label\"\n\t\t\t\t\t\t\tclassName=\"wp-block-navigation-item__label\"\n\t\t\t\t\t\t\tvalue={ label }\n\t\t\t\t\t\t\tonChange={ ( labelValue ) =>\n\t\t\t\t\t\t\t\tsetAttributes( { label: labelValue } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tonMerge={ mergeBlocks }\n\t\t\t\t\t\t\tonReplace={ onReplace }\n\t\t\t\t\t\t\taria-label={ __( 'Navigation link text' ) }\n\t\t\t\t\t\t\tplaceholder={ itemLabelPlaceholder }\n\t\t\t\t\t\t\twithoutInteractiveFormatting\n\t\t\t\t\t\t\tallowedFormats={ [\n\t\t\t\t\t\t\t\t'core/bold',\n\t\t\t\t\t\t\t\t'core/italic',\n\t\t\t\t\t\t\t\t'core/image',\n\t\t\t\t\t\t\t\t'core/strikethrough',\n\t\t\t\t\t\t\t] }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tif ( ! openSubmenusOnClick && ! url ) {\n\t\t\t\t\t\t\t\t\tsetIsLinkOpen( true );\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\t{ ! openSubmenusOnClick && isLinkOpen && (\n\t\t\t\t\t\t<LinkUI\n\t\t\t\t\t\t\tclassName=\"wp-block-navigation-link__inline-link-input\"\n\t\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\t\tlink={ attributes }\n\t\t\t\t\t\t\tonClose={ () => setIsLinkOpen( false ) }\n\t\t\t\t\t\t\tanchor={ popoverAnchor }\n\t\t\t\t\t\t\thasCreateSuggestion={ userCanCreate }\n\t\t\t\t\t\t\tonRemove={ () => {\n\t\t\t\t\t\t\t\tsetAttributes( { url: '' } );\n\t\t\t\t\t\t\t\tspeak( __( 'Link removed.' ), 'assertive' );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tonChange={ ( updatedValue ) => {\n\t\t\t\t\t\t\t\tupdateAttributes(\n\t\t\t\t\t\t\t\t\tupdatedValue,\n\t\t\t\t\t\t\t\t\tsetAttributes,\n\t\t\t\t\t\t\t\t\tattributes\n\t\t\t\t\t\t\t\t);\n\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</ParentElement>\n\t\t\t\t{ ( showSubmenuIcon || openSubmenusOnClick ) && (\n\t\t\t\t\t<span className=\"wp-block-navigation__submenu-icon\">\n\t\t\t\t\t\t<ItemSubmenuIcon />\n\t\t\t\t\t</span>\n\t\t\t\t) }\n\t\t\t\t<div { ...innerBlocksProps } />\n\t\t\t</div>\n\t\t</>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-library/src/navigation-submenu/edit.js"],"names":["ALLOWED_BLOCKS","DEFAULT_BLOCK","name","useIsDraggingWithin","elementRef","isDraggingWithin","setIsDraggingWithin","ownerDocument","current","handleDragStart","event","handleDragEnter","handleDragEnd","contains","target","addEventListener","removeEventListener","NavigationSubmenuEdit","attributes","isSelected","setAttributes","mergeBlocks","onReplace","context","clientId","label","type","url","description","rel","title","showSubmenuIcon","maxNestingLevel","openSubmenusOnClick","__unstableMarkNextChangeAsNotPersistent","replaceBlock","blockEditorStore","isLinkOpen","setIsLinkOpen","popoverAnchor","setPopoverAnchor","listItemRef","itemLabelPlaceholder","ref","pagesPermissions","postsPermissions","isAtMaxNesting","isTopLevelItem","isParentOfSelectedBlock","isImmediateParentOfSelectedBlock","hasChildren","selectedBlockHasChildren","onlyDescendantIsEmptyLink","select","hasSelectedInnerBlock","getSelectedBlockClientId","getBlockParentsByBlockName","getBlock","getBlockCount","getBlockOrder","_onlyDescendantIsEmptyLink","selectedBlockId","selectedBlockChildren","length","singleBlock","prevHasChildren","test","selectLabelText","focus","defaultView","selection","getSelection","range","createRange","selectNodeContents","removeAllRanges","addRange","userCanCreate","canCreate","textColor","customTextColor","backgroundColor","customBackgroundColor","onKeyDown","isKeyboardEvent","primary","blockProps","className","style","color","innerBlocksColors","allowedBlocks","filter","blockName","navigationChildBlockProps","innerBlocksProps","__experimentalDefaultBlock","__experimentalDirectInsert","__experimentalCaptureToolbars","renderAppender","InnerBlocks","ButtonBlockAppender","ParentElement","transformToLink","newLinkBlock","canConvertToLink","linkIcon","displayShortcut","removeSubmenu","labelValue","urlValue","descriptionValue","titleValue","relValue","updatedValue"],"mappings":";;;;;;;;;AA6BA;;AA1BA;;AAKA;;AACA;;AAOA;;AACA;;AACA;;AAUA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AAEA;;AACA;;AACA;;AA5CA;AACA;AACA;;AAGA;AACA;AACA;;AA8BA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,MAAMA,cAAc,GAAG,CACtB,sBADsB,EAEtB,yBAFsB,EAGtB,gBAHsB,CAAvB;AAMA,MAAMC,aAAa,GAAG;AACrBC,EAAAA,IAAI,EAAE;AADe,CAAtB;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,mBAAmB,GAAKC,UAAF,IAAkB;AAC7C,QAAM,CAAEC,gBAAF,EAAoBC,mBAApB,IAA4C,uBAAU,KAAV,CAAlD;AAEA,0BAAW,MAAM;AAChB,UAAM;AAAEC,MAAAA;AAAF,QAAoBH,UAAU,CAACI,OAArC;;AAEA,aAASC,eAAT,CAA0BC,KAA1B,EAAkC;AACjC;AACAC,MAAAA,eAAe,CAAED,KAAF,CAAf;AACA,KANe,CAQhB;;;AACA,aAASE,aAAT,GAAyB;AACxBN,MAAAA,mBAAmB,CAAE,KAAF,CAAnB;AACA;;AAED,aAASK,eAAT,CAA0BD,KAA1B,EAAkC;AACjC;AACA,UAAKN,UAAU,CAACI,OAAX,CAAmBK,QAAnB,CAA6BH,KAAK,CAACI,MAAnC,CAAL,EAAmD;AAClDR,QAAAA,mBAAmB,CAAE,IAAF,CAAnB;AACA,OAFD,MAEO;AACNA,QAAAA,mBAAmB,CAAE,KAAF,CAAnB;AACA;AACD,KApBe,CAsBhB;AACA;AACA;;;AACAC,IAAAA,aAAa,CAACQ,gBAAd,CAAgC,WAAhC,EAA6CN,eAA7C;AACAF,IAAAA,aAAa,CAACQ,gB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zD,MAAAA,aAAa,CAAE;AAAEO,QAAAA,GAAG,EAAE;AAAP,OAAF,CAAb;AACA,uBAAO,cAAI,eAAJ,CAAP,EAA8B,WAA9B;AACA,KAVF;AAWC,IAAA,QAAQ,EAAKuF,YAAF,IAAoB;AAC9B,8CACCA,YADD,EAEC9F,aAFD,EAGCF,UAHD;AAKA;AAjBF,IA9BF,CAFD,EAqDG,CAAEa,eAAe,IAAIE,mBAArB,KACD;AAAM,IAAA,SAAS,EAAC;AAAhB,KACC,4BAAC,uBAAD,OADD,CAtDF,EA0DC,mCAAU8D,gBAAV,CA1DD,CA7ED,CADD;AA4IA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport {\n\tPanelBody,\n\tTextControl,\n\tTextareaControl,\n\tToolbarButton,\n\tToolbarGroup,\n} from '@wordpress/components';\nimport { displayShortcut, isKeyboardEvent } from '@wordpress/keycodes';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tBlockControls,\n\tInnerBlocks,\n\tuseInnerBlocksProps,\n\tInspectorControls,\n\tRichText,\n\tuseBlockProps,\n\tstore as blockEditorStore,\n\tgetColorClassName,\n} from '@wordpress/block-editor';\nimport { isURL, prependHTTP } from '@wordpress/url';\nimport { useState, useEffect, useRef } from '@wordpress/element';\nimport { placeCaretAtHorizontalEdge } from '@wordpress/dom';\nimport { link as linkIcon, removeSubmenu } from '@wordpress/icons';\nimport { useResourcePermissions } from '@wordpress/core-data';\nimport { speak } from '@wordpress/a11y';\nimport { createBlock } from '@wordpress/blocks';\nimport { useMergeRefs, usePrevious } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { ItemSubmenuIcon } from './icons';\nimport { name } from './block.json';\nimport { LinkUI } from '../navigation-link/link-ui';\nimport { updateAttributes } from '../navigation-link/update-attributes';\nimport {\n\tgetColors,\n\tgetNavigationChildBlockProps,\n} from '../navigation/edit/utils';\n\nconst ALLOWED_BLOCKS = [\n\t'core/navigation-link',\n\t'core/navigation-submenu',\n\t'core/page-list',\n];\n\nconst DEFAULT_BLOCK = {\n\tname: 'core/navigation-link',\n};\n\n/**\n * A React hook to determine if it's dragging within the target element.\n *\n * @typedef {import('@wordpress/element').RefObject} RefObject\n *\n * @param {RefObject<HTMLElement>} elementRef The target elementRef object.\n *\n * @return {boolean} Is dragging within the target element.\n */\nconst useIsDraggingWithin = ( elementRef ) => {\n\tconst [ isDraggingWithin, setIsDraggingWithin ] = useState( false );\n\n\tuseEffect( () => {\n\t\tconst { ownerDocument } = elementRef.current;\n\n\t\tfunction handleDragStart( event ) {\n\t\t\t// Check the first time when the dragging starts.\n\t\t\thandleDragEnter( event );\n\t\t}\n\n\t\t// Set to false whenever the user cancel the drag event by either releasing the mouse or press Escape.\n\t\tfunction handleDragEnd() {\n\t\t\tsetIsDraggingWithin( false );\n\t\t}\n\n\t\tfunction handleDragEnter( event ) {\n\t\t\t// Check if the current target is inside the item element.\n\t\t\tif ( elementRef.current.contains( event.target ) ) {\n\t\t\t\tsetIsDraggingWithin( true );\n\t\t\t} else {\n\t\t\t\tsetIsDraggingWithin( false );\n\t\t\t}\n\t\t}\n\n\t\t// Bind these events to the document to catch all drag events.\n\t\t// Ideally, we can also use `event.relatedTarget`, but sadly that\n\t\t// doesn't work in Safari.\n\t\townerDocument.addEventListener( 'dragstart', handleDragStart );\n\t\townerDocument.addEventListener( 'dragend', handleDragEnd );\n\t\townerDocument.addEventListener( 'dragenter', handleDragEnter );\n\n\t\treturn () => {\n\t\t\townerDocument.removeEventListener( 'dragstart', handleDragStart );\n\t\t\townerDocument.removeEventListener( 'dragend', handleDragEnd );\n\t\t\townerDocument.removeEventListener( 'dragenter', handleDragEnter );\n\t\t};\n\t}, [] );\n\n\treturn isDraggingWithin;\n};\n\n/**\n * @typedef {'post-type'|'custom'|'taxonomy'|'post-type-archive'} WPNavigationLinkKind\n */\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\nexport default function NavigationSubmenuEdit( {\n\tattributes,\n\tisSelected,\n\tsetAttributes,\n\tmergeBlocks,\n\tonReplace,\n\tcontext,\n\tclientId,\n} ) {\n\tconst { label, type, url, description, rel, title } = attributes;\n\n\tconst { showSubmenuIcon, maxNestingLevel, openSubmenusOnClick } = context;\n\n\tconst { __unstableMarkNextChangeAsNotPersistent, replaceBlock } =\n\t\tuseDispatch( blockEditorStore );\n\tconst [ isLinkOpen, setIsLinkOpen ] = useState( false );\n\t// Use internal state instead of a ref to make sure that the component\n\t// re-renders when the popover's anchor updates.\n\tconst [ popoverAnchor, setPopoverAnchor ] = useState( null );\n\tconst listItemRef = useRef( null );\n\tconst isDraggingWithin = useIsDraggingWithin( listItemRef );\n\tconst itemLabelPlaceholder = __( 'Add text…' );\n\tconst ref = useRef();\n\n\tconst pagesPermissions = useResourcePermissions( 'pages' );\n\tconst postsPermissions = useResourcePermissions( 'posts' );\n\n\tconst {\n\t\tisAtMaxNesting,\n\t\tisTopLevelItem,\n\t\tisParentOfSelectedBlock,\n\t\tisImmediateParentOfSelectedBlock,\n\t\thasChildren,\n\t\tselectedBlockHasChildren,\n\t\tonlyDescendantIsEmptyLink,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\thasSelectedInnerBlock,\n\t\t\t\tgetSelectedBlockClientId,\n\t\t\t\tgetBlockParentsByBlockName,\n\t\t\t\tgetBlock,\n\t\t\t\tgetBlockCount,\n\t\t\t\tgetBlockOrder,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tlet _onlyDescendantIsEmptyLink;\n\n\t\t\tconst selectedBlockId = getSelectedBlockClientId();\n\n\t\t\tconst selectedBlockChildren = getBlockOrder( selectedBlockId );\n\n\t\t\t// Check for a single descendant in the submenu. If that block\n\t\t\t// is a link block in a \"placeholder\" state with no label then\n\t\t\t// we can consider as an \"empty\" link.\n\t\t\tif ( selectedBlockChildren?.length === 1 ) {\n\t\t\t\tconst singleBlock = getBlock( selectedBlockChildren[ 0 ] );\n\n\t\t\t\t_onlyDescendantIsEmptyLink =\n\t\t\t\t\tsingleBlock?.name === 'core/navigation-link' &&\n\t\t\t\t\t! singleBlock?.attributes?.label;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tisAtMaxNesting:\n\t\t\t\t\tgetBlockParentsByBlockName( clientId, name ).length >=\n\t\t\t\t\tmaxNestingLevel,\n\t\t\t\tisTopLevelItem:\n\t\t\t\t\tgetBlockParentsByBlockName( clientId, name ).length === 0,\n\t\t\t\tisParentOfSelectedBlock: hasSelectedInnerBlock(\n\t\t\t\t\tclientId,\n\t\t\t\t\ttrue\n\t\t\t\t),\n\t\t\t\tisImmediateParentOfSelectedBlock: hasSelectedInnerBlock(\n\t\t\t\t\tclientId,\n\t\t\t\t\tfalse\n\t\t\t\t),\n\t\t\t\thasChildren: !! getBlockCount( clientId ),\n\t\t\t\tselectedBlockHasChildren: !! selectedBlockChildren?.length,\n\t\t\t\tonlyDescendantIsEmptyLink: _onlyDescendantIsEmptyLink,\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst prevHasChildren = usePrevious( hasChildren );\n\n\t// Show the LinkControl on mount if the URL is empty\n\t// ( When adding a new menu item)\n\t// This can't be done in the useState call because it conflicts\n\t// with the autofocus behavior of the BlockListBlock component.\n\tuseEffect( () => {\n\t\tif ( ! openSubmenusOnClick && ! url ) {\n\t\t\tsetIsLinkOpen( true );\n\t\t}\n\t}, [] );\n\n\t// Store the colors from context as attributes for rendering.\n\tuseEffect( () => {\n\t\t// This side-effect should not create an undo level as those should\n\t\t// only be created via user interactions. Mark this change as\n\t\t// not persistent to avoid undo level creation.\n\t\t// See https://github.com/WordPress/gutenberg/issues/34564.\n\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\tsetAttributes( { isTopLevelItem } );\n\t}, [ isTopLevelItem ] );\n\n\t/**\n\t * The hook shouldn't be necessary but due to a focus loss happening\n\t * when selecting a suggestion in the link popover, we force close on block unselection.\n\t */\n\tuseEffect( () => {\n\t\tif ( ! isSelected ) {\n\t\t\tsetIsLinkOpen( false );\n\t\t}\n\t}, [ isSelected ] );\n\n\t// If the LinkControl popover is open and the URL has changed, close the LinkControl and focus the label text.\n\tuseEffect( () => {\n\t\tif ( isLinkOpen && url ) {\n\t\t\t// Does this look like a URL and have something TLD-ish?\n\t\t\tif (\n\t\t\t\tisURL( prependHTTP( label ) ) &&\n\t\t\t\t/^.+\\.[a-z]+/.test( label )\n\t\t\t) {\n\t\t\t\t// Focus and select the label text.\n\t\t\t\tselectLabelText();\n\t\t\t} else {\n\t\t\t\t// Focus it (but do not select).\n\t\t\t\tplaceCaretAtHorizontalEdge( ref.current, true );\n\t\t\t}\n\t\t}\n\t}, [ url ] );\n\n\t/**\n\t * Focus the Link label text and select it.\n\t */\n\tfunction selectLabelText() {\n\t\tref.current.focus();\n\t\tconst { ownerDocument } = ref.current;\n\t\tconst { defaultView } = ownerDocument;\n\t\tconst selection = defaultView.getSelection();\n\t\tconst range = ownerDocument.createRange();\n\t\t// Get the range of the current ref contents so we can add this range to the selection.\n\t\trange.selectNodeContents( ref.current );\n\t\tselection.removeAllRanges();\n\t\tselection.addRange( range );\n\t}\n\n\tlet userCanCreate = false;\n\tif ( ! type || type === 'page' ) {\n\t\tuserCanCreate = pagesPermissions.canCreate;\n\t} else if ( type === 'post' ) {\n\t\tuserCanCreate = postsPermissions.canCreate;\n\t}\n\n\tconst {\n\t\ttextColor,\n\t\tcustomTextColor,\n\t\tbackgroundColor,\n\t\tcustomBackgroundColor,\n\t} = getColors( context, ! isTopLevelItem );\n\n\tfunction onKeyDown( event ) {\n\t\tif ( isKeyboardEvent.primary( event, 'k' ) ) {\n\t\t\tsetIsLinkOpen( true );\n\t\t}\n\t}\n\n\tconst blockProps = useBlockProps( {\n\t\tref: useMergeRefs( [ setPopoverAnchor, listItemRef ] ),\n\t\tclassName: classnames( 'wp-block-navigation-item', {\n\t\t\t'is-editing': isSelected || isParentOfSelectedBlock,\n\t\t\t'is-dragging-within': isDraggingWithin,\n\t\t\t'has-link': !! url,\n\t\t\t'has-child': hasChildren,\n\t\t\t'has-text-color': !! textColor || !! customTextColor,\n\t\t\t[ getColorClassName( 'color', textColor ) ]: !! textColor,\n\t\t\t'has-background': !! backgroundColor || customBackgroundColor,\n\t\t\t[ getColorClassName( 'background-color', backgroundColor ) ]:\n\t\t\t\t!! backgroundColor,\n\t\t\t'open-on-click': openSubmenusOnClick,\n\t\t} ),\n\t\tstyle: {\n\t\t\tcolor: ! textColor && customTextColor,\n\t\t\tbackgroundColor: ! backgroundColor && customBackgroundColor,\n\t\t},\n\t\tonKeyDown,\n\t} );\n\n\t// Always use overlay colors for submenus.\n\tconst innerBlocksColors = getColors( context, true );\n\n\tconst allowedBlocks = isAtMaxNesting\n\t\t? ALLOWED_BLOCKS.filter(\n\t\t\t\t( blockName ) => blockName !== 'core/navigation-submenu'\n\t\t )\n\t\t: ALLOWED_BLOCKS;\n\n\tconst navigationChildBlockProps =\n\t\tgetNavigationChildBlockProps( innerBlocksColors );\n\tconst innerBlocksProps = useInnerBlocksProps( navigationChildBlockProps, {\n\t\tallowedBlocks,\n\t\t__experimentalDefaultBlock: DEFAULT_BLOCK,\n\t\t__experimentalDirectInsert: true,\n\n\t\t// Ensure block toolbar is not too far removed from item\n\t\t// being edited.\n\t\t// see: https://github.com/WordPress/gutenberg/pull/34615.\n\t\t__experimentalCaptureToolbars: true,\n\n\t\trenderAppender:\n\t\t\tisSelected ||\n\t\t\t( isImmediateParentOfSelectedBlock &&\n\t\t\t\t! selectedBlockHasChildren ) ||\n\t\t\t// Show the appender while dragging to allow inserting element between item and the appender.\n\t\t\thasChildren\n\t\t\t\t? InnerBlocks.ButtonBlockAppender\n\t\t\t\t: false,\n\t} );\n\n\tconst ParentElement = openSubmenusOnClick ? 'button' : 'a';\n\n\tfunction transformToLink() {\n\t\tconst newLinkBlock = createBlock( 'core/navigation-link', attributes );\n\t\treplaceBlock( clientId, newLinkBlock );\n\t}\n\n\tuseEffect( () => {\n\t\t// If block becomes empty, transform to Navigation Link.\n\t\tif ( ! hasChildren && prevHasChildren ) {\n\t\t\t// This side-effect should not create an undo level as those should\n\t\t\t// only be created via user interactions.\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\ttransformToLink();\n\t\t}\n\t}, [ hasChildren, prevHasChildren ] );\n\n\tconst canConvertToLink =\n\t\t! selectedBlockHasChildren || onlyDescendantIsEmptyLink;\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls>\n\t\t\t\t<ToolbarGroup>\n\t\t\t\t\t{ ! openSubmenusOnClick && (\n\t\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\t\tname=\"link\"\n\t\t\t\t\t\t\ticon={ linkIcon }\n\t\t\t\t\t\t\ttitle={ __( 'Link' ) }\n\t\t\t\t\t\t\tshortcut={ displayShortcut.primary( 'k' ) }\n\t\t\t\t\t\t\tonClick={ () => setIsLinkOpen( true ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\tname=\"revert\"\n\t\t\t\t\t\ticon={ removeSubmenu }\n\t\t\t\t\t\ttitle={ __( 'Convert to Link' ) }\n\t\t\t\t\t\tonClick={ transformToLink }\n\t\t\t\t\t\tclassName=\"wp-block-navigation__submenu__revert\"\n\t\t\t\t\t\tisDisabled={ ! canConvertToLink }\n\t\t\t\t\t/>\n\t\t\t\t</ToolbarGroup>\n\t\t\t</BlockControls>\n\t\t\t{ /* Warning, this duplicated in packages/block-library/src/navigation-link/edit.js */ }\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody title={ __( 'Link settings' ) }>\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tvalue={ label || '' }\n\t\t\t\t\t\tonChange={ ( labelValue ) => {\n\t\t\t\t\t\t\tsetAttributes( { label: labelValue } );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tlabel={ __( 'Label' ) }\n\t\t\t\t\t\tautoComplete=\"off\"\n\t\t\t\t\t/>\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tvalue={ url || '' }\n\t\t\t\t\t\tonChange={ ( urlValue ) => {\n\t\t\t\t\t\t\tsetAttributes( { url: urlValue } );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tlabel={ __( 'URL' ) }\n\t\t\t\t\t\tautoComplete=\"off\"\n\t\t\t\t\t/>\n\t\t\t\t\t<TextareaControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tvalue={ description || '' }\n\t\t\t\t\t\tonChange={ ( descriptionValue ) => {\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tdescription: descriptionValue,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tlabel={ __( 'Description' ) }\n\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t'The description will be displayed in the menu if the current theme supports it.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t/>\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tvalue={ title || '' }\n\t\t\t\t\t\tonChange={ ( titleValue ) => {\n\t\t\t\t\t\t\tsetAttributes( { title: titleValue } );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tlabel={ __( 'Link title' ) }\n\t\t\t\t\t\tautoComplete=\"off\"\n\t\t\t\t\t/>\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tvalue={ rel || '' }\n\t\t\t\t\t\tonChange={ ( relValue ) => {\n\t\t\t\t\t\t\tsetAttributes( { rel: relValue } );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tlabel={ __( 'Link rel' ) }\n\t\t\t\t\t\tautoComplete=\"off\"\n\t\t\t\t\t/>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t<div { ...blockProps }>\n\t\t\t\t{ /* eslint-disable jsx-a11y/anchor-is-valid */ }\n\t\t\t\t<ParentElement className=\"wp-block-navigation-item__content\">\n\t\t\t\t\t{ /* eslint-enable */ }\n\t\t\t\t\t{\n\t\t\t\t\t\t<RichText\n\t\t\t\t\t\t\tref={ ref }\n\t\t\t\t\t\t\tidentifier=\"label\"\n\t\t\t\t\t\t\tclassName=\"wp-block-navigation-item__label\"\n\t\t\t\t\t\t\tvalue={ label }\n\t\t\t\t\t\t\tonChange={ ( labelValue ) =>\n\t\t\t\t\t\t\t\tsetAttributes( { label: labelValue } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tonMerge={ mergeBlocks }\n\t\t\t\t\t\t\tonReplace={ onReplace }\n\t\t\t\t\t\t\taria-label={ __( 'Navigation link text' ) }\n\t\t\t\t\t\t\tplaceholder={ itemLabelPlaceholder }\n\t\t\t\t\t\t\twithoutInteractiveFormatting\n\t\t\t\t\t\t\tallowedFormats={ [\n\t\t\t\t\t\t\t\t'core/bold',\n\t\t\t\t\t\t\t\t'core/italic',\n\t\t\t\t\t\t\t\t'core/image',\n\t\t\t\t\t\t\t\t'core/strikethrough',\n\t\t\t\t\t\t\t] }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tif ( ! openSubmenusOnClick && ! url ) {\n\t\t\t\t\t\t\t\t\tsetIsLinkOpen( true );\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\t{ ! openSubmenusOnClick && isLinkOpen && (\n\t\t\t\t\t\t<LinkUI\n\t\t\t\t\t\t\tclassName=\"wp-block-navigation-link__inline-link-input\"\n\t\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\t\tlink={ attributes }\n\t\t\t\t\t\t\tonClose={ () => setIsLinkOpen( false ) }\n\t\t\t\t\t\t\tanchor={ popoverAnchor }\n\t\t\t\t\t\t\thasCreateSuggestion={ userCanCreate }\n\t\t\t\t\t\t\tonRemove={ () => {\n\t\t\t\t\t\t\t\tsetAttributes( { url: '' } );\n\t\t\t\t\t\t\t\tspeak( __( 'Link removed.' ), 'assertive' );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tonChange={ ( updatedValue ) => {\n\t\t\t\t\t\t\t\tupdateAttributes(\n\t\t\t\t\t\t\t\t\tupdatedValue,\n\t\t\t\t\t\t\t\t\tsetAttributes,\n\t\t\t\t\t\t\t\t\tattributes\n\t\t\t\t\t\t\t\t);\n\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</ParentElement>\n\t\t\t\t{ ( showSubmenuIcon || openSubmenusOnClick ) && (\n\t\t\t\t\t<span className=\"wp-block-navigation__submenu-icon\">\n\t\t\t\t\t\t<ItemSubmenuIcon />\n\t\t\t\t\t</span>\n\t\t\t\t) }\n\t\t\t\t<div { ...innerBlocksProps } />\n\t\t\t</div>\n\t\t</>\n\t);\n}\n"]}
@@ -155,10 +155,6 @@ function PageListEdit(_ref3) {
155
155
  order: 'asc'
156
156
  });
157
157
  const allowConvertToLinks = 'showSubmenuIcon' in context && (pages === null || pages === void 0 ? void 0 : pages.length) > 0 && (pages === null || pages === void 0 ? void 0 : pages.length) <= MAX_PAGE_COUNT;
158
- const convertToNavigationLinks = (0, _useConvertToNavigationLinks.useConvertToNavigationLinks)({
159
- clientId,
160
- pages
161
- });
162
158
  const pagesByParentId = (0, _element.useMemo)(() => {
163
159
  if (pages === null) {
164
160
  return new Map();
@@ -188,6 +184,11 @@ function PageListEdit(_ref3) {
188
184
  return accumulator;
189
185
  }, new Map());
190
186
  }, [pages]);
187
+ const convertToNavigationLinks = (0, _useConvertToNavigationLinks.useConvertToNavigationLinks)({
188
+ clientId,
189
+ pages,
190
+ parentPageID
191
+ });
191
192
  const blockProps = (0, _blockEditor.useBlockProps)({
192
193
  className: (0, _classnames.default)('wp-block-page-list', {
193
194
  'has-text-color': !!context.textColor,
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-library/src/page-list/edit.js"],"names":["MAX_PAGE_COUNT","NOOP","convertDescription","BlockContent","blockProps","innerBlocksProps","hasResolvedPages","blockList","pages","parentPageID","length","parentPageDetails","find","page","id","title","rendered","ConvertToLinksModal","onClick","disabled","isOpen","setOpen","openModal","closeModal","describedby","PageListEdit","context","clientId","attributes","setAttributes","records","hasResolved","per_page","_fields","orderby","order","allowConvertToLinks","convertToNavigationLinks","pagesByParentId","Map","sortedPages","sort","a","b","menu_order","localeCompare","reduce","accumulator","parent","has","get","push","set","className","textColor","backgroundColor","style","color","getBlockList","parentId","childPages","template","hasChildren","pageProps","label","link","url","item","children","makePagesTree","level","tree","value","repeat","rawName","pagesTree","allowedBlocks","renderAppender","__unstableDisableDropZone","templateLock","onInput","onChange","isNested","select","getBlockParentsByBlockName","blockEditorStore","blockParents"],"mappings":";;;;;;;;;AA4BA;;AAzBA;;AAKA;;AACA;;AASA;;AASA;;AAEA;;AACA;;AAKA;;AAnCA;AACA;AACA;;AAGA;AACA;AACA;;AAyBA;AACA;AACA;AAGA;AACA;AACA,MAAMA,cAAc,GAAG,GAAvB;;AACA,MAAMC,IAAI,GAAG,MAAM,CAAE,CAArB;;AAEA,MAAMC,kBAAkB,GAAG,cAC1B,6HAD0B,CAA3B;;AAIA,SAASC,YAAT,OAOI;AAAA,MAPmB;AACtBC,IAAAA,UADsB;AAEtBC,IAAAA,gBAFsB;AAGtBC,IAAAA,gBAHsB;AAItBC,IAAAA,SA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,aAAa,CAAE;AAAEqD,MAAAA;AAAF,KAAF,CAAb;AACA,GAFD,EAEG,CAAEA,QAAF,CAFH;AAIA,SACC,qDACC,4BAAC,8BAAD,QACGP,SAAS,CAACjE,MAAV,GAAmB,CAAnB,IACD,4BAAC,qBAAD,QACC,4BAAC,2BAAD;AACC,IAAA,SAAS,EAAC,gCADX;AAEC,IAAA,KAAK,EAAG,cAAI,aAAJ,CAFT;AAGC,IAAA,KAAK,EAAGD,YAHT;AAIC,IAAA,OAAO,EAAGkE,SAJX;AAKC,IAAA,QAAQ,EAAKH,KAAF,IACV3C,aAAa,CAAE;AAAEpB,MAAAA,YAAY,EAAE+D,KAAF,aAAEA,KAAF,cAAEA,KAAF,GAAW;AAAzB,KAAF,CANf;AAQC,IAAA,IAAI,EAAG,cACN,0CADM;AARR,IADD,CAFF,EAiBGpC,mBAAmB,IACpB,4BAAC,qBAAD;AAAW,IAAA,KAAK,EAAG,cAAI,gBAAJ;AAAnB,KACC,uCAAKlC,kBAAL,CADD,EAEC,4BAAC,kBAAD;AACC,IAAA,OAAO,EAAC,SADT;AAEC,IAAA,QAAQ,EAAG,CAAEI,gBAFd;AAGC,IAAA,OAAO,EAAG+B;AAHX,KAKG,cAAI,MAAJ,CALH,CAFD,CAlBF,CADD,EA+BGD,mBAAmB,IACpB,4BAAC,mBAAD;AACC,IAAA,QAAQ,EAAG,CAAE9B,gBADd;AAEC,IAAA,OAAO,EAAG+B;AAFX,IAhCF,EAqCC,4BAAC,YAAD;AACC,IAAA,UAAU,EAAGjC,UADd;AAEC,IAAA,gBAAgB,EAAGC,gBAFpB;AAGC,IAAA,gBAAgB,EAAGC,gBAHpB;AAIC,IAAA,SAAS,EAAGC,SAJb;AAKC,IAAA,KAAK,EAAGC,KALT;AAMC,IAAA,YAAY,EAAGC;AANhB,IArCD,CADD;AAgDA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { createBlock } from '@wordpress/blocks';\nimport {\n\tInspectorControls,\n\tBlockControls,\n\tuseBlockProps,\n\tuseInnerBlocksProps,\n\tgetColorClassName,\n\tstore as blockEditorStore,\n\tWarning,\n} from '@wordpress/block-editor';\nimport {\n\tPanelBody,\n\tToolbarButton,\n\tSpinner,\n\tNotice,\n\tComboboxControl,\n\tButton,\n\tModal,\n} from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useMemo, useState, useEffect } from '@wordpress/element';\nimport { useEntityRecords } from '@wordpress/core-data';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { useConvertToNavigationLinks } from './use-convert-to-navigation-links';\n\n// We only show the edit option when page count is <= MAX_PAGE_COUNT\n// Performance of Navigation Links is not good past this value.\nconst MAX_PAGE_COUNT = 100;\nconst NOOP = () => {};\n\nconst convertDescription = __(\n\t'This menu is automatically kept in sync with pages on your site. You can manage the menu yourself by clicking \"Edit\" below.'\n);\n\nfunction BlockContent( {\n\tblockProps,\n\tinnerBlocksProps,\n\thasResolvedPages,\n\tblockList,\n\tpages,\n\tparentPageID,\n} ) {\n\tif ( ! hasResolvedPages ) {\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<Spinner />\n\t\t\t</div>\n\t\t);\n\t}\n\n\tif ( pages === null ) {\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<Notice status={ 'warning' } isDismissible={ false }>\n\t\t\t\t\t{ __( 'Page List: Cannot retrieve Pages.' ) }\n\t\t\t\t</Notice>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tif ( pages.length === 0 ) {\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<Notice status={ 'info' } isDismissible={ false }>\n\t\t\t\t\t{ __( 'Page List: Cannot retrieve Pages.' ) }\n\t\t\t\t</Notice>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tif ( blockList.length === 0 ) {\n\t\tconst parentPageDetails = pages.find(\n\t\t\t( page ) => page.id === parentPageID\n\t\t);\n\n\t\tif ( parentPageDetails?.title?.rendered ) {\n\t\t\treturn (\n\t\t\t\t<div { ...blockProps }>\n\t\t\t\t\t<Warning>\n\t\t\t\t\t\t{ sprintf(\n\t\t\t\t\t\t\t// translators: %s: Page title.\n\t\t\t\t\t\t\t__( 'Page List: \"%s\" page has no children.' ),\n\t\t\t\t\t\t\tparentPageDetails.title.rendered\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Warning>\n\t\t\t\t</div>\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<Notice status={ 'warning' } isDismissible={ false }>\n\t\t\t\t\t{ __( 'Page List: Cannot retrieve Pages.' ) }\n\t\t\t\t</Notice>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tif ( pages.length > 0 ) {\n\t\treturn <ul { ...innerBlocksProps }></ul>;\n\t}\n}\n\nfunction ConvertToLinksModal( { onClick, disabled } ) {\n\tconst [ isOpen, setOpen ] = useState( false );\n\tconst openModal = () => setOpen( true );\n\tconst closeModal = () => setOpen( false );\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls group=\"other\">\n\t\t\t\t<ToolbarButton title={ __( 'Edit' ) } onClick={ openModal }>\n\t\t\t\t\t{ __( 'Edit' ) }\n\t\t\t\t</ToolbarButton>\n\t\t\t</BlockControls>\n\t\t\t{ isOpen && (\n\t\t\t\t<Modal\n\t\t\t\t\tonRequestClose={ closeModal }\n\t\t\t\t\ttitle={ __( 'Edit this menu' ) }\n\t\t\t\t\tclassName={ 'wp-block-page-list-modal' }\n\t\t\t\t\taria={ {\n\t\t\t\t\t\tdescribedby: 'wp-block-page-list-modal__description',\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t<p id={ 'wp-block-page-list-modal__description' }>\n\t\t\t\t\t\t{ convertDescription }\n\t\t\t\t\t</p>\n\t\t\t\t\t<div className=\"wp-block-page-list-modal-buttons\">\n\t\t\t\t\t\t<Button variant=\"tertiary\" onClick={ closeModal }>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\tdisabled={ disabled }\n\t\t\t\t\t\t\tonClick={ onClick }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Edit' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</div>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default function PageListEdit( {\n\tcontext,\n\tclientId,\n\tattributes,\n\tsetAttributes,\n} ) {\n\tconst { parentPageID } = attributes;\n\n\tconst { records: pages, hasResolved: hasResolvedPages } = useEntityRecords(\n\t\t'postType',\n\t\t'page',\n\t\t{\n\t\t\tper_page: MAX_PAGE_COUNT,\n\t\t\t_fields: [ 'id', 'link', 'menu_order', 'parent', 'title', 'type' ],\n\t\t\t// TODO: When https://core.trac.wordpress.org/ticket/39037 REST API support for multiple orderby\n\t\t\t// values is resolved, update 'orderby' to [ 'menu_order', 'post_title' ] to provide a consistent\n\t\t\t// sort.\n\t\t\torderby: 'menu_order',\n\t\t\torder: 'asc',\n\t\t}\n\t);\n\n\tconst allowConvertToLinks =\n\t\t'showSubmenuIcon' in context &&\n\t\tpages?.length > 0 &&\n\t\tpages?.length <= MAX_PAGE_COUNT;\n\n\tconst convertToNavigationLinks = useConvertToNavigationLinks( {\n\t\tclientId,\n\t\tpages,\n\t} );\n\n\tconst pagesByParentId = useMemo( () => {\n\t\tif ( pages === null ) {\n\t\t\treturn new Map();\n\t\t}\n\n\t\t// TODO: Once the REST API supports passing multiple values to\n\t\t// 'orderby', this can be removed.\n\t\t// https://core.trac.wordpress.org/ticket/39037\n\t\tconst sortedPages = pages.sort( ( a, b ) => {\n\t\t\tif ( a.menu_order === b.menu_order ) {\n\t\t\t\treturn a.title.rendered.localeCompare( b.title.rendered );\n\t\t\t}\n\t\t\treturn a.menu_order - b.menu_order;\n\t\t} );\n\n\t\treturn sortedPages.reduce( ( accumulator, page ) => {\n\t\t\tconst { parent } = page;\n\t\t\tif ( accumulator.has( parent ) ) {\n\t\t\t\taccumulator.get( parent ).push( page );\n\t\t\t} else {\n\t\t\t\taccumulator.set( parent, [ page ] );\n\t\t\t}\n\t\t\treturn accumulator;\n\t\t}, new Map() );\n\t}, [ pages ] );\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: classnames( 'wp-block-page-list', {\n\t\t\t'has-text-color': !! context.textColor,\n\t\t\t[ getColorClassName( 'color', context.textColor ) ]:\n\t\t\t\t!! context.textColor,\n\t\t\t'has-background': !! context.backgroundColor,\n\t\t\t[ getColorClassName(\n\t\t\t\t'background-color',\n\t\t\t\tcontext.backgroundColor\n\t\t\t) ]: !! context.backgroundColor,\n\t\t} ),\n\t\tstyle: { ...context.style?.color },\n\t} );\n\n\tconst getBlockList = ( parentId = parentPageID ) => {\n\t\tconst childPages = pagesByParentId.get( parentId );\n\n\t\tif ( ! childPages?.length ) {\n\t\t\treturn [];\n\t\t}\n\n\t\treturn childPages.reduce( ( template, page ) => {\n\t\t\tconst hasChildren = pagesByParentId.has( page.id );\n\t\t\tconst pageProps = {\n\t\t\t\tid: page.id,\n\t\t\t\tlabel: page.title?.rendered,\n\t\t\t\ttitle: page.title?.rendered,\n\t\t\t\tlink: page.url,\n\t\t\t\thasChildren,\n\t\t\t};\n\t\t\tlet item = null;\n\t\t\tconst children = getBlockList( page.id );\n\t\t\titem = createBlock( 'core/page-list-item', pageProps, children );\n\t\t\ttemplate.push( item );\n\n\t\t\treturn template;\n\t\t}, [] );\n\t};\n\n\tconst makePagesTree = ( parentId = 0, level = 0 ) => {\n\t\tconst childPages = pagesByParentId.get( parentId );\n\n\t\tif ( ! childPages?.length ) {\n\t\t\treturn [];\n\t\t}\n\n\t\treturn childPages.reduce( ( tree, page ) => {\n\t\t\tconst hasChildren = pagesByParentId.has( page.id );\n\t\t\tconst item = {\n\t\t\t\tvalue: page.id,\n\t\t\t\tlabel: '— '.repeat( level ) + page.title.rendered,\n\t\t\t\trawName: page.title.rendered,\n\t\t\t};\n\t\t\ttree.push( item );\n\t\t\tif ( hasChildren ) {\n\t\t\t\ttree.push( ...makePagesTree( page.id, level + 1 ) );\n\t\t\t}\n\t\t\treturn tree;\n\t\t}, [] );\n\t};\n\n\tconst pagesTree = useMemo( makePagesTree, [ pagesByParentId ] );\n\n\tconst blockList = useMemo( getBlockList, [\n\t\tpagesByParentId,\n\t\tparentPageID,\n\t] );\n\n\tconst innerBlocksProps = useInnerBlocksProps( blockProps, {\n\t\tallowedBlocks: [ 'core/page-list-item' ],\n\t\trenderAppender: false,\n\t\t__unstableDisableDropZone: true,\n\t\ttemplateLock: 'all',\n\t\tonInput: NOOP,\n\t\tonChange: NOOP,\n\t\tvalue: blockList,\n\t} );\n\n\tconst { isNested } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockParentsByBlockName } = select( blockEditorStore );\n\t\t\tconst blockParents = getBlockParentsByBlockName(\n\t\t\t\tclientId,\n\t\t\t\t'core/navigation-submenu',\n\t\t\t\ttrue\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tisNested: blockParents.length > 0,\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tuseEffect( () => {\n\t\tsetAttributes( { isNested } );\n\t}, [ isNested ] );\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls>\n\t\t\t\t{ pagesTree.length > 0 && (\n\t\t\t\t\t<PanelBody>\n\t\t\t\t\t\t<ComboboxControl\n\t\t\t\t\t\t\tclassName=\"editor-page-attributes__parent\"\n\t\t\t\t\t\t\tlabel={ __( 'Parent page' ) }\n\t\t\t\t\t\t\tvalue={ parentPageID }\n\t\t\t\t\t\t\toptions={ pagesTree }\n\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\tsetAttributes( { parentPageID: value ?? 0 } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t'Choose a page to show only its subpages.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</PanelBody>\n\t\t\t\t) }\n\t\t\t\t{ allowConvertToLinks && (\n\t\t\t\t\t<PanelBody title={ __( 'Edit this menu' ) }>\n\t\t\t\t\t\t<p>{ convertDescription }</p>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\tdisabled={ ! hasResolvedPages }\n\t\t\t\t\t\t\tonClick={ convertToNavigationLinks }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Edit' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</PanelBody>\n\t\t\t\t) }\n\t\t\t</InspectorControls>\n\t\t\t{ allowConvertToLinks && (\n\t\t\t\t<ConvertToLinksModal\n\t\t\t\t\tdisabled={ ! hasResolvedPages }\n\t\t\t\t\tonClick={ convertToNavigationLinks }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t<BlockContent\n\t\t\t\tblockProps={ blockProps }\n\t\t\t\tinnerBlocksProps={ innerBlocksProps }\n\t\t\t\thasResolvedPages={ hasResolvedPages }\n\t\t\t\tblockList={ blockList }\n\t\t\t\tpages={ pages }\n\t\t\t\tparentPageID={ parentPageID }\n\t\t\t/>\n\t\t</>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-library/src/page-list/edit.js"],"names":["MAX_PAGE_COUNT","NOOP","convertDescription","BlockContent","blockProps","innerBlocksProps","hasResolvedPages","blockList","pages","parentPageID","length","parentPageDetails","find","page","id","title","rendered","ConvertToLinksModal","onClick","disabled","isOpen","setOpen","openModal","closeModal","describedby","PageListEdit","context","clientId","attributes","setAttributes","records","hasResolved","per_page","_fields","orderby","order","allowConvertToLinks","pagesByParentId","Map","sortedPages","sort","a","b","menu_order","localeCompare","reduce","accumulator","parent","has","get","push","set","convertToNavigationLinks","className","textColor","backgroundColor","style","color","getBlockList","parentId","childPages","template","hasChildren","pageProps","label","link","url","item","children","makePagesTree","level","tree","value","repeat","rawName","pagesTree","allowedBlocks","renderAppender","__unstableDisableDropZone","templateLock","onInput","onChange","isNested","select","getBlockParentsByBlockName","blockEditorStore","blockParents"],"mappings":";;;;;;;;;AA4BA;;AAzBA;;AAKA;;AACA;;AASA;;AASA;;AAEA;;AACA;;AAKA;;AAnCA;AACA;AACA;;AAGA;AACA;AACA;;AAyBA;AACA;AACA;AAGA;AACA;AACA,MAAMA,cAAc,GAAG,GAAvB;;AACA,MAAMC,IAAI,GAAG,MAAM,CAAE,CAArB;;AAEA,MAAMC,kBAAkB,GAAG,cAC1B,6HAD0B,CAA3B;;AAIA,SAASC,YAAT,OAOI;AAAA,MAPmB;AACtBC,IAAAA,UADsB;AAEtBC,IAAAA,gBAFsB;AAGtBC,IAAAA,gBAHsB;AAItBC,IAAAA,SAJsB;AAKtBC,IAAAA,KALsB;AAMtBC,IAAAA;AANsB,GAOnB;;AACH,MAAK,CAAEH,gBAAP,EAA0B;AACzB,WACC,mCAAUF,UAAV,EACC,4BAAC,mBAAD,OADD,CADD;AAKA;;AAED,MAAKI,KAAK,KAAK,IAAf,EAAsB;AACrB,WACC,mCAAUJ,UAAV,EACC,4BAAC,kBAAD;AAAQ,MAAA,MAAM,EAAG,SAAjB;AAA6B,MAAA,aAAa,EAAG;AAA7C,OACG,cAAI,mCAAJ,CADH,CADD,CADD;AAOA;;AAED,MAAKI,KAAK,CAACE,MAAN,KAAiB,CAAtB,EAA0B;AACzB,WACC,mCAAUN,UAAV,EACC,4BAAC,kBAAD;AAAQ,MAAA,MAAM,EAAG,MAAjB;AAA0B,MAAA,aAAa,EAAG;AAA1C,OACG,cAAI,mCAAJ,CADH,CADD,CADD;AAOA;;AAED,MAAKG,SAAS,CAACG,MAAV,KAAqB,CAA1B,EAA8B;AAAA;;AAC7B,UAAMC,iBAAiB,GAAGH,KAAK,CAACI,IAAN,CACvBC,IAAF,IAAYA,IAAI,CAACC,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,OAAO,EAAC,SADT;AAEC,IAAA,QAAQ,EAAG,CAAEI,gBAFd;AAGC,IAAA,OAAO,EAAG8C;AAHX,KAKG,cAAI,MAAJ,CALH,CAFD,CAlBF,CADD,EA+BGhB,mBAAmB,IACpB,4BAAC,mBAAD;AACC,IAAA,QAAQ,EAAG,CAAE9B,gBADd;AAEC,IAAA,OAAO,EAAG8C;AAFX,IAhCF,EAqCC,4BAAC,YAAD;AACC,IAAA,UAAU,EAAGhD,UADd;AAEC,IAAA,gBAAgB,EAAGC,gBAFpB;AAGC,IAAA,gBAAgB,EAAGC,gBAHpB;AAIC,IAAA,SAAS,EAAGC,SAJb;AAKC,IAAA,KAAK,EAAGC,KALT;AAMC,IAAA,YAAY,EAAGC;AANhB,IArCD,CADD;AAgDA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { createBlock } from '@wordpress/blocks';\nimport {\n\tInspectorControls,\n\tBlockControls,\n\tuseBlockProps,\n\tuseInnerBlocksProps,\n\tgetColorClassName,\n\tstore as blockEditorStore,\n\tWarning,\n} from '@wordpress/block-editor';\nimport {\n\tPanelBody,\n\tToolbarButton,\n\tSpinner,\n\tNotice,\n\tComboboxControl,\n\tButton,\n\tModal,\n} from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useMemo, useState, useEffect } from '@wordpress/element';\nimport { useEntityRecords } from '@wordpress/core-data';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { useConvertToNavigationLinks } from './use-convert-to-navigation-links';\n\n// We only show the edit option when page count is <= MAX_PAGE_COUNT\n// Performance of Navigation Links is not good past this value.\nconst MAX_PAGE_COUNT = 100;\nconst NOOP = () => {};\n\nconst convertDescription = __(\n\t'This menu is automatically kept in sync with pages on your site. You can manage the menu yourself by clicking \"Edit\" below.'\n);\n\nfunction BlockContent( {\n\tblockProps,\n\tinnerBlocksProps,\n\thasResolvedPages,\n\tblockList,\n\tpages,\n\tparentPageID,\n} ) {\n\tif ( ! hasResolvedPages ) {\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<Spinner />\n\t\t\t</div>\n\t\t);\n\t}\n\n\tif ( pages === null ) {\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<Notice status={ 'warning' } isDismissible={ false }>\n\t\t\t\t\t{ __( 'Page List: Cannot retrieve Pages.' ) }\n\t\t\t\t</Notice>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tif ( pages.length === 0 ) {\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<Notice status={ 'info' } isDismissible={ false }>\n\t\t\t\t\t{ __( 'Page List: Cannot retrieve Pages.' ) }\n\t\t\t\t</Notice>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tif ( blockList.length === 0 ) {\n\t\tconst parentPageDetails = pages.find(\n\t\t\t( page ) => page.id === parentPageID\n\t\t);\n\n\t\tif ( parentPageDetails?.title?.rendered ) {\n\t\t\treturn (\n\t\t\t\t<div { ...blockProps }>\n\t\t\t\t\t<Warning>\n\t\t\t\t\t\t{ sprintf(\n\t\t\t\t\t\t\t// translators: %s: Page title.\n\t\t\t\t\t\t\t__( 'Page List: \"%s\" page has no children.' ),\n\t\t\t\t\t\t\tparentPageDetails.title.rendered\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Warning>\n\t\t\t\t</div>\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<Notice status={ 'warning' } isDismissible={ false }>\n\t\t\t\t\t{ __( 'Page List: Cannot retrieve Pages.' ) }\n\t\t\t\t</Notice>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tif ( pages.length > 0 ) {\n\t\treturn <ul { ...innerBlocksProps }></ul>;\n\t}\n}\n\nfunction ConvertToLinksModal( { onClick, disabled } ) {\n\tconst [ isOpen, setOpen ] = useState( false );\n\tconst openModal = () => setOpen( true );\n\tconst closeModal = () => setOpen( false );\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls group=\"other\">\n\t\t\t\t<ToolbarButton title={ __( 'Edit' ) } onClick={ openModal }>\n\t\t\t\t\t{ __( 'Edit' ) }\n\t\t\t\t</ToolbarButton>\n\t\t\t</BlockControls>\n\t\t\t{ isOpen && (\n\t\t\t\t<Modal\n\t\t\t\t\tonRequestClose={ closeModal }\n\t\t\t\t\ttitle={ __( 'Edit this menu' ) }\n\t\t\t\t\tclassName={ 'wp-block-page-list-modal' }\n\t\t\t\t\taria={ {\n\t\t\t\t\t\tdescribedby: 'wp-block-page-list-modal__description',\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t<p id={ 'wp-block-page-list-modal__description' }>\n\t\t\t\t\t\t{ convertDescription }\n\t\t\t\t\t</p>\n\t\t\t\t\t<div className=\"wp-block-page-list-modal-buttons\">\n\t\t\t\t\t\t<Button variant=\"tertiary\" onClick={ closeModal }>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\tdisabled={ disabled }\n\t\t\t\t\t\t\tonClick={ onClick }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Edit' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</div>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default function PageListEdit( {\n\tcontext,\n\tclientId,\n\tattributes,\n\tsetAttributes,\n} ) {\n\tconst { parentPageID } = attributes;\n\n\tconst { records: pages, hasResolved: hasResolvedPages } = useEntityRecords(\n\t\t'postType',\n\t\t'page',\n\t\t{\n\t\t\tper_page: MAX_PAGE_COUNT,\n\t\t\t_fields: [ 'id', 'link', 'menu_order', 'parent', 'title', 'type' ],\n\t\t\t// TODO: When https://core.trac.wordpress.org/ticket/39037 REST API support for multiple orderby\n\t\t\t// values is resolved, update 'orderby' to [ 'menu_order', 'post_title' ] to provide a consistent\n\t\t\t// sort.\n\t\t\torderby: 'menu_order',\n\t\t\torder: 'asc',\n\t\t}\n\t);\n\n\tconst allowConvertToLinks =\n\t\t'showSubmenuIcon' in context &&\n\t\tpages?.length > 0 &&\n\t\tpages?.length <= MAX_PAGE_COUNT;\n\n\tconst pagesByParentId = useMemo( () => {\n\t\tif ( pages === null ) {\n\t\t\treturn new Map();\n\t\t}\n\n\t\t// TODO: Once the REST API supports passing multiple values to\n\t\t// 'orderby', this can be removed.\n\t\t// https://core.trac.wordpress.org/ticket/39037\n\t\tconst sortedPages = pages.sort( ( a, b ) => {\n\t\t\tif ( a.menu_order === b.menu_order ) {\n\t\t\t\treturn a.title.rendered.localeCompare( b.title.rendered );\n\t\t\t}\n\t\t\treturn a.menu_order - b.menu_order;\n\t\t} );\n\n\t\treturn sortedPages.reduce( ( accumulator, page ) => {\n\t\t\tconst { parent } = page;\n\t\t\tif ( accumulator.has( parent ) ) {\n\t\t\t\taccumulator.get( parent ).push( page );\n\t\t\t} else {\n\t\t\t\taccumulator.set( parent, [ page ] );\n\t\t\t}\n\t\t\treturn accumulator;\n\t\t}, new Map() );\n\t}, [ pages ] );\n\n\tconst convertToNavigationLinks = useConvertToNavigationLinks( {\n\t\tclientId,\n\t\tpages,\n\t\tparentPageID,\n\t} );\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: classnames( 'wp-block-page-list', {\n\t\t\t'has-text-color': !! context.textColor,\n\t\t\t[ getColorClassName( 'color', context.textColor ) ]:\n\t\t\t\t!! context.textColor,\n\t\t\t'has-background': !! context.backgroundColor,\n\t\t\t[ getColorClassName(\n\t\t\t\t'background-color',\n\t\t\t\tcontext.backgroundColor\n\t\t\t) ]: !! context.backgroundColor,\n\t\t} ),\n\t\tstyle: { ...context.style?.color },\n\t} );\n\n\tconst getBlockList = ( parentId = parentPageID ) => {\n\t\tconst childPages = pagesByParentId.get( parentId );\n\n\t\tif ( ! childPages?.length ) {\n\t\t\treturn [];\n\t\t}\n\n\t\treturn childPages.reduce( ( template, page ) => {\n\t\t\tconst hasChildren = pagesByParentId.has( page.id );\n\t\t\tconst pageProps = {\n\t\t\t\tid: page.id,\n\t\t\t\tlabel: page.title?.rendered,\n\t\t\t\ttitle: page.title?.rendered,\n\t\t\t\tlink: page.url,\n\t\t\t\thasChildren,\n\t\t\t};\n\t\t\tlet item = null;\n\t\t\tconst children = getBlockList( page.id );\n\t\t\titem = createBlock( 'core/page-list-item', pageProps, children );\n\t\t\ttemplate.push( item );\n\n\t\t\treturn template;\n\t\t}, [] );\n\t};\n\n\tconst makePagesTree = ( parentId = 0, level = 0 ) => {\n\t\tconst childPages = pagesByParentId.get( parentId );\n\n\t\tif ( ! childPages?.length ) {\n\t\t\treturn [];\n\t\t}\n\n\t\treturn childPages.reduce( ( tree, page ) => {\n\t\t\tconst hasChildren = pagesByParentId.has( page.id );\n\t\t\tconst item = {\n\t\t\t\tvalue: page.id,\n\t\t\t\tlabel: '— '.repeat( level ) + page.title.rendered,\n\t\t\t\trawName: page.title.rendered,\n\t\t\t};\n\t\t\ttree.push( item );\n\t\t\tif ( hasChildren ) {\n\t\t\t\ttree.push( ...makePagesTree( page.id, level + 1 ) );\n\t\t\t}\n\t\t\treturn tree;\n\t\t}, [] );\n\t};\n\n\tconst pagesTree = useMemo( makePagesTree, [ pagesByParentId ] );\n\n\tconst blockList = useMemo( getBlockList, [\n\t\tpagesByParentId,\n\t\tparentPageID,\n\t] );\n\n\tconst innerBlocksProps = useInnerBlocksProps( blockProps, {\n\t\tallowedBlocks: [ 'core/page-list-item' ],\n\t\trenderAppender: false,\n\t\t__unstableDisableDropZone: true,\n\t\ttemplateLock: 'all',\n\t\tonInput: NOOP,\n\t\tonChange: NOOP,\n\t\tvalue: blockList,\n\t} );\n\n\tconst { isNested } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockParentsByBlockName } = select( blockEditorStore );\n\t\t\tconst blockParents = getBlockParentsByBlockName(\n\t\t\t\tclientId,\n\t\t\t\t'core/navigation-submenu',\n\t\t\t\ttrue\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tisNested: blockParents.length > 0,\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tuseEffect( () => {\n\t\tsetAttributes( { isNested } );\n\t}, [ isNested ] );\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls>\n\t\t\t\t{ pagesTree.length > 0 && (\n\t\t\t\t\t<PanelBody>\n\t\t\t\t\t\t<ComboboxControl\n\t\t\t\t\t\t\tclassName=\"editor-page-attributes__parent\"\n\t\t\t\t\t\t\tlabel={ __( 'Parent page' ) }\n\t\t\t\t\t\t\tvalue={ parentPageID }\n\t\t\t\t\t\t\toptions={ pagesTree }\n\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\tsetAttributes( { parentPageID: value ?? 0 } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t'Choose a page to show only its subpages.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</PanelBody>\n\t\t\t\t) }\n\t\t\t\t{ allowConvertToLinks && (\n\t\t\t\t\t<PanelBody title={ __( 'Edit this menu' ) }>\n\t\t\t\t\t\t<p>{ convertDescription }</p>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\tdisabled={ ! hasResolvedPages }\n\t\t\t\t\t\t\tonClick={ convertToNavigationLinks }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Edit' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</PanelBody>\n\t\t\t\t) }\n\t\t\t</InspectorControls>\n\t\t\t{ allowConvertToLinks && (\n\t\t\t\t<ConvertToLinksModal\n\t\t\t\t\tdisabled={ ! hasResolvedPages }\n\t\t\t\t\tonClick={ convertToNavigationLinks }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t<BlockContent\n\t\t\t\tblockProps={ blockProps }\n\t\t\t\tinnerBlocksProps={ innerBlocksProps }\n\t\t\t\thasResolvedPages={ hasResolvedPages }\n\t\t\t\tblockList={ blockList }\n\t\t\t\tpages={ pages }\n\t\t\t\tparentPageID={ parentPageID }\n\t\t\t/>\n\t\t</>\n\t);\n}\n"]}
@@ -15,7 +15,15 @@ var _blockEditor = require("@wordpress/block-editor");
15
15
  /**
16
16
  * WordPress dependencies
17
17
  */
18
- function convertToNavigationLinks() {
18
+
19
+ /**
20
+ * Converts an array of pages into a nested array of navigation link blocks.
21
+ *
22
+ * @param {Array} pages An array of pages.
23
+ *
24
+ * @return {Array} A nested array of navigation link blocks.
25
+ */
26
+ function createNavigationLinks() {
19
27
  let pages = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
20
28
  const linkMap = {};
21
29
  const navigationLinks = [];
@@ -47,14 +55,61 @@ function convertToNavigationLinks() {
47
55
  linkMap[parent] = {
48
56
  innerBlocks: []
49
57
  };
50
- }
58
+ } // Although these variables are not referenced, they are needed to store the innerBlocks in memory.
59
+
51
60
 
52
61
  const parentLinkInnerBlocks = linkMap[parent].innerBlocks;
53
62
  parentLinkInnerBlocks.push(linkMap[id]);
54
63
  }
55
- }); // Transform all links with innerBlocks into Submenus. This can't be done
64
+ });
65
+ return navigationLinks;
66
+ }
67
+ /**
68
+ * Finds a navigation link block by id, recursively.
69
+ * It might be possible to make this a more generic helper function.
70
+ *
71
+ * @param {Array} navigationLinks An array of navigation link blocks.
72
+ * @param {number} id The id of the navigation link to find.
73
+ *
74
+ * @return {Object|null} The navigation link block with the given id.
75
+ */
76
+
77
+
78
+ function findNavigationLinkById(navigationLinks, id) {
79
+ for (const navigationLink of navigationLinks) {
80
+ // Is this the link we're looking for?
81
+ if (navigationLink.attributes.id === id) {
82
+ return navigationLink;
83
+ } // If not does it have innerBlocks?
84
+
85
+
86
+ if (navigationLink.innerBlocks && navigationLink.innerBlocks.length) {
87
+ const foundNavigationLink = findNavigationLinkById(navigationLink.innerBlocks, id);
88
+
89
+ if (foundNavigationLink) {
90
+ return foundNavigationLink;
91
+ }
92
+ }
93
+ }
94
+
95
+ return null;
96
+ }
97
+
98
+ function convertToNavigationLinks() {
99
+ let pages = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
100
+ let parentPageID = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
101
+ let navigationLinks = createNavigationLinks(pages); // If a parent page ID is provided, only return the children of that page.
102
+
103
+ if (parentPageID) {
104
+ const parentPage = findNavigationLinkById(navigationLinks, parentPageID);
105
+
106
+ if (parentPage && parentPage.innerBlocks) {
107
+ navigationLinks = parentPage.innerBlocks;
108
+ }
109
+ } // Transform all links with innerBlocks into Submenus. This can't be done
56
110
  // sooner because page objects have no information on their children.
57
111
 
112
+
58
113
  const transformSubmenus = listOfLinks => {
59
114
  listOfLinks.forEach((block, index, listOfLinksArray) => {
60
115
  const {
@@ -77,7 +132,8 @@ function convertToNavigationLinks() {
77
132
  function useConvertToNavigationLinks(_ref2) {
78
133
  let {
79
134
  clientId,
80
- pages
135
+ pages,
136
+ parentPageID
81
137
  } = _ref2;
82
138
  const {
83
139
  replaceBlock,
@@ -98,7 +154,7 @@ function useConvertToNavigationLinks(_ref2) {
98
154
  };
99
155
  }, [clientId]);
100
156
  return () => {
101
- const navigationLinks = convertToNavigationLinks(pages); // Replace the Page List block with the Navigation Links.
157
+ const navigationLinks = convertToNavigationLinks(pages, parentPageID); // Replace the Page List block with the Navigation Links.
102
158
 
103
159
  replaceBlock(clientId, navigationLinks); // Select the Navigation block to reveal the changes.
104
160
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-library/src/page-list/use-convert-to-navigation-links.js"],"names":["convertToNavigationLinks","pages","linkMap","navigationLinks","forEach","id","title","link","url","type","parent","innerBlocks","label","rendered","kind","push","parentLinkInnerBlocks","transformSubmenus","listOfLinks","block","index","listOfLinksArray","attributes","length","transformedBlock","useConvertToNavigationLinks","clientId","replaceBlock","selectBlock","blockEditorStore","parentNavBlockClientId","select","getSelectedBlockClientId","getBlockParentsByBlockName","_selectedBlockClientId"],"mappings":";;;;;;;;AAGA;;AACA;;AACA;;AALA;AACA;AACA;AAKO,SAASA,wBAAT,GAAgD;AAAA,MAAbC,KAAa,uEAAL,EAAK;AACtD,QAAMC,OAAO,GAAG,EAAhB;AACA,QAAMC,eAAe,GAAG,EAAxB;AACAF,EAAAA,KAAK,CAACG,OAAN,CAAe,QAA8C;AAAA;;AAAA,QAA5C;AAAEC,MAAAA,EAAF;AAAMC,MAAAA,KAAN;AAAaC,MAAAA,IAAI,EAAEC,GAAnB;AAAwBC,MAAAA,IAAxB;AAA8BC,MAAAA;AAA9B,KAA4C;AAC5D;AACA,UAAMC,WAAW,2CAAGT,OAAO,CAAEG,EAAF,CAAV,gDAAG,YAAeM,WAAlB,yEAAiC,EAAlD;AACAT,IAAAA,OAAO,CAAEG,EAAF,CAAP,GAAgB,yBACf,sBADe,EAEf;AACCA,MAAAA,EADD;AAECO,MAAAA,KAAK,EAAEN,KAAK,CAACO,QAFd;AAGCL,MAAAA,GAHD;AAICC,MAAAA,IAJD;AAKCK,MAAAA,IAAI,EAAE;AALP,KAFe,EASfH,WATe,CAAhB;;AAYA,QAAK,CAAED,MAAP,EAAgB;AACfP,MAAAA,eAAe,CAACY,IAAhB,CAAsBb,OAAO,CAAEG,EAAF,CAA7B;AACA,KAFD,MAEO;AACN,UAAK,CAAEH,OAAO,CAAEQ,MAAF,CAAd,EAA2B;AAC1B;AACAR,QAAAA,OAAO,CAAEQ,MAAF,CAAP,GAAoB;AAAEC,UAAAA,WAAW,EAAE;AAAf,SAApB;AACA;;AACD,YAAMK,qBAAqB,GAAGd,OAAO,CAAEQ,MAAF,CAAP,CAAkBC,WAAhD;AACAK,MAAAA,qBAAqB,CAACD,IAAtB,CAA4Bb,OAAO,CAAEG,EAAF,CAAnC;AACA;AACD,GAzBD,EAHsD,CA8BtD;AACA;;AACA,QAAMY,iB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IAAAA,WAAW,CAAEE,sBAAF,CAAX;AACA,GARD;AASA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\nexport function convertToNavigationLinks( pages = [] ) {\n\tconst linkMap = {};\n\tconst navigationLinks = [];\n\tpages.forEach( ( { id, title, link: url, type, parent } ) => {\n\t\t// See if a placeholder exists. This is created if children appear before parents in list.\n\t\tconst innerBlocks = linkMap[ id ]?.innerBlocks ?? [];\n\t\tlinkMap[ id ] = createBlock(\n\t\t\t'core/navigation-link',\n\t\t\t{\n\t\t\t\tid,\n\t\t\t\tlabel: title.rendered,\n\t\t\t\turl,\n\t\t\t\ttype,\n\t\t\t\tkind: 'post-type',\n\t\t\t},\n\t\t\tinnerBlocks\n\t\t);\n\n\t\tif ( ! parent ) {\n\t\t\tnavigationLinks.push( linkMap[ id ] );\n\t\t} else {\n\t\t\tif ( ! linkMap[ parent ] ) {\n\t\t\t\t// Use a placeholder if the child appears before parent in list.\n\t\t\t\tlinkMap[ parent ] = { innerBlocks: [] };\n\t\t\t}\n\t\t\tconst parentLinkInnerBlocks = linkMap[ parent ].innerBlocks;\n\t\t\tparentLinkInnerBlocks.push( linkMap[ id ] );\n\t\t}\n\t} );\n\n\t// Transform all links with innerBlocks into Submenus. This can't be done\n\t// sooner because page objects have no information on their children.\n\tconst transformSubmenus = ( listOfLinks ) => {\n\t\tlistOfLinks.forEach( ( block, index, listOfLinksArray ) => {\n\t\t\tconst { attributes, innerBlocks } = block;\n\t\t\tif ( innerBlocks.length !== 0 ) {\n\t\t\t\ttransformSubmenus( innerBlocks );\n\t\t\t\tconst transformedBlock = createBlock(\n\t\t\t\t\t'core/navigation-submenu',\n\t\t\t\t\tattributes,\n\t\t\t\t\tinnerBlocks\n\t\t\t\t);\n\t\t\t\tlistOfLinksArray[ index ] = transformedBlock;\n\t\t\t}\n\t\t} );\n\t};\n\n\ttransformSubmenus( navigationLinks );\n\n\treturn navigationLinks;\n}\n\nexport function useConvertToNavigationLinks( { clientId, pages } ) {\n\tconst { replaceBlock, selectBlock } = useDispatch( blockEditorStore );\n\n\tconst { parentNavBlockClientId } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getSelectedBlockClientId, getBlockParentsByBlockName } =\n\t\t\t\tselect( blockEditorStore );\n\n\t\t\tconst _selectedBlockClientId = getSelectedBlockClientId();\n\n\t\t\treturn {\n\t\t\t\tparentNavBlockClientId: getBlockParentsByBlockName(\n\t\t\t\t\t_selectedBlockClientId,\n\t\t\t\t\t'core/navigation',\n\t\t\t\t\ttrue\n\t\t\t\t)[ 0 ],\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\treturn () => {\n\t\tconst navigationLinks = convertToNavigationLinks( pages );\n\n\t\t// Replace the Page List block with the Navigation Links.\n\t\treplaceBlock( clientId, navigationLinks );\n\n\t\t// Select the Navigation block to reveal the changes.\n\t\tselectBlock( parentNavBlockClientId );\n\t};\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-library/src/page-list/use-convert-to-navigation-links.js"],"names":["createNavigationLinks","pages","linkMap","navigationLinks","forEach","id","title","link","url","type","parent","innerBlocks","label","rendered","kind","push","parentLinkInnerBlocks","findNavigationLinkById","navigationLink","attributes","length","foundNavigationLink","convertToNavigationLinks","parentPageID","parentPage","transformSubmenus","listOfLinks","block","index","listOfLinksArray","transformedBlock","useConvertToNavigationLinks","clientId","replaceBlock","selectBlock","blockEditorStore","parentNavBlockClientId","select","getSelectedBlockClientId","getBlockParentsByBlockName","_selectedBlockClientId"],"mappings":";;;;;;;;AAGA;;AACA;;AACA;;AALA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,qBAAT,GAA6C;AAAA,MAAbC,KAAa,uEAAL,EAAK;AAC5C,QAAMC,OAAO,GAAG,EAAhB;AACA,QAAMC,eAAe,GAAG,EAAxB;AACAF,EAAAA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AIH;AAAA,MAJyC;AAC5CC,IAAAA,QAD4C;AAE5C/B,IAAAA,KAF4C;AAG5CsB,IAAAA;AAH4C,GAIzC;AACH,QAAM;AAAEU,IAAAA,YAAF;AAAgBC,IAAAA;AAAhB,MAAgC,uBAAaC,kBAAb,CAAtC;AAEA,QAAM;AAAEC,IAAAA;AAAF,MAA6B,qBAChCC,MAAF,IAAc;AACb,UAAM;AAAEC,MAAAA,wBAAF;AAA4BC,MAAAA;AAA5B,QACLF,MAAM,CAAEF,kBAAF,CADP;;AAGA,UAAMK,sBAAsB,GAAGF,wBAAwB,EAAvD;;AAEA,WAAO;AACNF,MAAAA,sBAAsB,EAAEG,0BAA0B,CACjDC,sBADiD,EAEjD,iBAFiD,EAGjD,IAHiD,CAA1B,CAIrB,CAJqB;AADlB,KAAP;AAOA,GAdiC,EAelC,CAAER,QAAF,CAfkC,CAAnC;AAkBA,SAAO,MAAM;AACZ,UAAM7B,eAAe,GAAGmB,wBAAwB,CAAErB,KAAF,EAASsB,YAAT,CAAhD,CADY,CAGZ;;AACAU,IAAAA,YAAY,CAAED,QAAF,EAAY7B,eAAZ,CAAZ,CAJY,CAMZ;;AACA+B,IAAAA,WAAW,CAAEE,sBAAF,CAAX;AACA,GARD;AASA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Converts an array of pages into a nested array of navigation link blocks.\n *\n * @param {Array} pages An array of pages.\n *\n * @return {Array} A nested array of navigation link blocks.\n */\nfunction createNavigationLinks( pages = [] ) {\n\tconst linkMap = {};\n\tconst navigationLinks = [];\n\tpages.forEach( ( { id, title, link: url, type, parent } ) => {\n\t\t// See if a placeholder exists. This is created if children appear before parents in list.\n\t\tconst innerBlocks = linkMap[ id ]?.innerBlocks ?? [];\n\t\tlinkMap[ id ] = createBlock(\n\t\t\t'core/navigation-link',\n\t\t\t{\n\t\t\t\tid,\n\t\t\t\tlabel: title.rendered,\n\t\t\t\turl,\n\t\t\t\ttype,\n\t\t\t\tkind: 'post-type',\n\t\t\t},\n\t\t\tinnerBlocks\n\t\t);\n\n\t\tif ( ! parent ) {\n\t\t\tnavigationLinks.push( linkMap[ id ] );\n\t\t} else {\n\t\t\tif ( ! linkMap[ parent ] ) {\n\t\t\t\t// Use a placeholder if the child appears before parent in list.\n\t\t\t\tlinkMap[ parent ] = { innerBlocks: [] };\n\t\t\t}\n\t\t\t// Although these variables are not referenced, they are needed to store the innerBlocks in memory.\n\t\t\tconst parentLinkInnerBlocks = linkMap[ parent ].innerBlocks;\n\t\t\tparentLinkInnerBlocks.push( linkMap[ id ] );\n\t\t}\n\t} );\n\n\treturn navigationLinks;\n}\n\n/**\n * Finds a navigation link block by id, recursively.\n * It might be possible to make this a more generic helper function.\n *\n * @param {Array} navigationLinks An array of navigation link blocks.\n * @param {number} id The id of the navigation link to find.\n *\n * @return {Object|null} The navigation link block with the given id.\n */\nfunction findNavigationLinkById( navigationLinks, id ) {\n\tfor ( const navigationLink of navigationLinks ) {\n\t\t// Is this the link we're looking for?\n\t\tif ( navigationLink.attributes.id === id ) {\n\t\t\treturn navigationLink;\n\t\t}\n\n\t\t// If not does it have innerBlocks?\n\t\tif ( navigationLink.innerBlocks && navigationLink.innerBlocks.length ) {\n\t\t\tconst foundNavigationLink = findNavigationLinkById(\n\t\t\t\tnavigationLink.innerBlocks,\n\t\t\t\tid\n\t\t\t);\n\n\t\t\tif ( foundNavigationLink ) {\n\t\t\t\treturn foundNavigationLink;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn null;\n}\n\nexport function convertToNavigationLinks( pages = [], parentPageID = null ) {\n\tlet navigationLinks = createNavigationLinks( pages );\n\n\t// If a parent page ID is provided, only return the children of that page.\n\tif ( parentPageID ) {\n\t\tconst parentPage = findNavigationLinkById(\n\t\t\tnavigationLinks,\n\t\t\tparentPageID\n\t\t);\n\t\tif ( parentPage && parentPage.innerBlocks ) {\n\t\t\tnavigationLinks = parentPage.innerBlocks;\n\t\t}\n\t}\n\n\t// Transform all links with innerBlocks into Submenus. This can't be done\n\t// sooner because page objects have no information on their children.\n\tconst transformSubmenus = ( listOfLinks ) => {\n\t\tlistOfLinks.forEach( ( block, index, listOfLinksArray ) => {\n\t\t\tconst { attributes, innerBlocks } = block;\n\t\t\tif ( innerBlocks.length !== 0 ) {\n\t\t\t\ttransformSubmenus( innerBlocks );\n\t\t\t\tconst transformedBlock = createBlock(\n\t\t\t\t\t'core/navigation-submenu',\n\t\t\t\t\tattributes,\n\t\t\t\t\tinnerBlocks\n\t\t\t\t);\n\t\t\t\tlistOfLinksArray[ index ] = transformedBlock;\n\t\t\t}\n\t\t} );\n\t};\n\n\ttransformSubmenus( navigationLinks );\n\treturn navigationLinks;\n}\n\nexport function useConvertToNavigationLinks( {\n\tclientId,\n\tpages,\n\tparentPageID,\n} ) {\n\tconst { replaceBlock, selectBlock } = useDispatch( blockEditorStore );\n\n\tconst { parentNavBlockClientId } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getSelectedBlockClientId, getBlockParentsByBlockName } =\n\t\t\t\tselect( blockEditorStore );\n\n\t\t\tconst _selectedBlockClientId = getSelectedBlockClientId();\n\n\t\t\treturn {\n\t\t\t\tparentNavBlockClientId: getBlockParentsByBlockName(\n\t\t\t\t\t_selectedBlockClientId,\n\t\t\t\t\t'core/navigation',\n\t\t\t\t\ttrue\n\t\t\t\t)[ 0 ],\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\treturn () => {\n\t\tconst navigationLinks = convertToNavigationLinks( pages, parentPageID );\n\n\t\t// Replace the Page List block with the Navigation Links.\n\t\treplaceBlock( clientId, navigationLinks );\n\n\t\t// Select the Navigation block to reveal the changes.\n\t\tselectBlock( parentNavBlockClientId );\n\t};\n}\n"]}
@@ -37,7 +37,8 @@ function PostExcerptEditor(_ref) {
37
37
  attributes: {
38
38
  textAlign,
39
39
  moreText,
40
- showMoreOnNewLine
40
+ showMoreOnNewLine,
41
+ excerptLength
41
42
  },
42
43
  setAttributes,
43
44
  isSelected,
@@ -59,6 +60,13 @@ function PostExcerptEditor(_ref) {
59
60
  [`has-text-align-${textAlign}`]: textAlign
60
61
  })
61
62
  });
63
+ /**
64
+ * translators: If your word count is based on single characters (e.g. East Asian characters),
65
+ * enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'.
66
+ * Do not translate into your own language.
67
+ */
68
+
69
+ const wordCountType = (0, _i18n._x)('words', 'Word count type. Do not translate!');
62
70
  /**
63
71
  * When excerpt is editable, strip the html tags from
64
72
  * rendered excerpt. This will be used if the entity's
@@ -98,15 +106,42 @@ function PostExcerptEditor(_ref) {
98
106
  const excerptClassName = (0, _classnames.default)('wp-block-post-excerpt__excerpt', {
99
107
  'is-inline': !showMoreOnNewLine
100
108
  });
109
+ /**
110
+ * The excerpt length setting needs to be applied to both
111
+ * the raw and the rendered excerpt depending on which is being used.
112
+ */
113
+
114
+ const rawOrRenderedExcerpt = !!renderedExcerpt ? strippedRenderedExcerpt : rawExcerpt;
115
+ let trimmedExcerpt = '';
116
+
117
+ if (wordCountType === 'words') {
118
+ trimmedExcerpt = rawOrRenderedExcerpt.trim().split(' ', excerptLength).join(' ');
119
+ } else if (wordCountType === 'characters_excluding_spaces') {
120
+ /*
121
+ * 1. Split the excerpt at the character limit,
122
+ * then join the substrings back into one string.
123
+ * 2. Count the number of spaces in the excerpt
124
+ * by comparing the lengths of the string with and without spaces.
125
+ * 3. Add the number to the length of the visible excerpt,
126
+ * so that the spaces are excluded from the word count.
127
+ */
128
+ const excerptWithSpaces = rawOrRenderedExcerpt.trim().split('', excerptLength).join('');
129
+ const numberOfSpaces = excerptWithSpaces.length - excerptWithSpaces.replaceAll(' ', '').length;
130
+ trimmedExcerpt = rawOrRenderedExcerpt.trim().split('', excerptLength + numberOfSpaces).join('');
131
+ } else if (wordCountType === 'characters_including_spaces') {
132
+ trimmedExcerpt = rawOrRenderedExcerpt.trim().split('', excerptLength);
133
+ }
134
+
135
+ trimmedExcerpt = trimmedExcerpt + '...';
101
136
  const excerptContent = isEditable ? (0, _element.createElement)(_blockEditor.RichText, {
102
137
  className: excerptClassName,
103
138
  "aria-label": (0, _i18n.__)('Post excerpt text'),
104
- value: rawExcerpt || strippedRenderedExcerpt || (isSelected ? '' : (0, _i18n.__)('No post excerpt found')),
139
+ value: isSelected ? rawOrRenderedExcerpt : (trimmedExcerpt !== '...' ? trimmedExcerpt : '') || (0, _i18n.__)('No post excerpt found'),
105
140
  onChange: setExcerpt,
106
141
  tagName: "p"
107
142
  }) : (0, _element.createElement)("p", {
108
143
  className: excerptClassName
109
- }, strippedRenderedExcerpt || (0, _i18n.__)('No post excerpt found'));
144
+ }, trimmedExcerpt !== '...' ? trimmedExcerpt : (0, _i18n.__)('No post excerpt found'));
110
145
  return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_blockEditor.BlockControls, null, (0, _element.createElement)(_blockEditor.AlignmentToolbar, {
111
146
  value: textAlign,
112
147
  onChange: newAlign => setAttributes({
@@ -120,6 +155,17 @@ function PostExcerptEditor(_ref) {
120
155
  onChange: newShowMoreOnNewLine => setAttributes({
121
156
  showMoreOnNewLine: newShowMoreOnNewLine
122
157
  })
158
+ }), (0, _element.createElement)(_components.RangeControl, {
159
+ label: (0, _i18n.__)('Max number of words'),
160
+ value: excerptLength,
161
+ onChange: value => {
162
+ setAttributes({
163
+ excerptLength: value
164
+ });
165
+ setExcerpt();
166
+ },
167
+ min: "10",
168
+ max: "100"
123
169
  }))), (0, _element.createElement)("div", blockProps, excerptContent, !showMoreOnNewLine && ' ', showMoreOnNewLine ? (0, _element.createElement)("p", {
124
170
  className: "wp-block-post-excerpt__more-text"
125
171
  }, readMoreLink) : readMoreLink));
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-library/src/post-excerpt/edit.js"],"names":["PostExcerptEditor","attributes","textAlign","moreText","showMoreOnNewLine","setAttributes","isSelected","context","postId","postType","queryId","isDescendentOfQueryLoop","Number","isFinite","userCanEdit","isEditable","rawExcerpt","setExcerpt","rendered","renderedExcerpt","protected","isProtected","blockProps","className","strippedRenderedExcerpt","document","window","DOMParser","parseFromString","body","textContent","innerText","newAlign","readMoreLink","newMoreText","excerptClassName","excerptContent","newShowMoreOnNewLine"],"mappings":";;;;;;;;;AASA;;AANA;;AAKA;;AAEA;;AAQA;;AACA;;AAKA;;AAxBA;AACA;AACA;;AAGA;AACA;AACA;;AAcA;AACA;AACA;AAGe,SAASA,iBAAT,OAKX;AAAA,MALuC;AAC1CC,IAAAA,UAAU,EAAE;AAAEC,MAAAA,SAAF;AAAaC,MAAAA,QAAb;AAAuBC,MAAAA;AAAvB,KAD8B;AAE1CC,IAAAA,aAF0C;AAG1CC,IAAAA,UAH0C;AAI1CC,IAAAA,OAAO,EAAE;AAAEC,MAAAA,MAAF;AAAUC,MAAAA,QAAV;AAAoBC,MAAAA;AAApB;AAJiC,GAKvC;AACH,QAAMC,uBAAuB,GAAGC,MAAM,CAACC,QAAP,CAAiBH,OAAjB,CAAhC;AACA,QAAMI,WAAW,GAAG,6BAAkB,UAAlB,EAA8BL,QAA9B,EAAwCD,MAAxC,CAApB;AACA,QAAMO,UAAU,GAAGD,WAAW,IAAI,CAAEH,uBAApC;AACA,QAAM,CACLK,UADK,EAELC,UAFK,EAGL;AAAEC,IAAAA,QAAQ,EAAEC,eAAZ;AAA6BC,IAAAA,SAAS,EAAEC;AAAxC,MAAwD,EAHnD,IAIF,6BAAe,UAAf,EAA2BZ,QAA3B,EAAqC,SAArC,EAAgDD,MAAhD,CAJJ;AAKA,QAAMc,UAAU,GAAG,gCAAe;AACjCC,IAAAA,SAAS,EAAE,yBAAY;AACtB,OAAG,kBAAkBrB,SAAW,EAAhC,GAAqCA;AADf,KAAZ;AADsB,GAAf,CAAnB;AAKA;AACD;AACA;AACA;AACA;;AACC,QAAMsB,uBAAuB,GAAG,sBAAS,MAAM;AAC9C,QAAK,CAAEL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AC,qBAAD;AACC,IAAA,SAAS,EAAGoB,gBADb;AAEC,kBAAa,cAAI,mBAAJ,CAFd;AAGC,IAAA,KAAK,EACJnB,UAAU,IACVQ,uBADA,KAEElB,UAAU,GAAG,EAAH,GAAQ,cAAI,uBAAJ,CAFpB,CAJF;AAQC,IAAA,QAAQ,EAAGW,UARZ;AASC,IAAA,OAAO,EAAC;AATT,IADgC,GAahC;AAAG,IAAA,SAAS,EAAGkB;AAAf,KACGX,uBAAuB,IAAI,cAAI,uBAAJ,CAD9B,CAbD;AAiBA,SACC,qDACC,4BAAC,0BAAD,QACC,4BAAC,6BAAD;AACC,IAAA,KAAK,EAAGtB,SADT;AAEC,IAAA,QAAQ,EAAK8B,QAAF,IACV3B,aAAa,CAAE;AAAEH,MAAAA,SAAS,EAAE8B;AAAb,KAAF;AAHf,IADD,CADD,EASC,4BAAC,8BAAD,QACC,4BAAC,qBAAD;AAAW,IAAA,KAAK,EAAG,cAAI,UAAJ;AAAnB,KACC,4BAAC,yBAAD;AACC,IAAA,KAAK,EAAG,cAAI,uBAAJ,CADT;AAEC,IAAA,OAAO,EAAG5B,iBAFX;AAGC,IAAA,QAAQ,EAAKiC,oBAAF,IACVhC,aAAa,CAAE;AACdD,MAAAA,iBAAiB,EAAEiC;AADL,KAAF;AAJf,IADD,CADD,CATD,EAsBC,mCAAUf,UAAV,EACGc,cADH,EAEG,CAAEhC,iBAAF,IAAuB,GAF1B,EAGGA,iBAAiB,GAClB;AAAG,IAAA,SAAS,EAAC;AAAb,KACG6B,YADH,CADkB,GAKlBA,YARF,CAtBD,CADD;AAoCA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useEntityProp } from '@wordpress/core-data';\nimport { useMemo } from '@wordpress/element';\nimport {\n\tAlignmentToolbar,\n\tBlockControls,\n\tInspectorControls,\n\tRichText,\n\tWarning,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { PanelBody, ToggleControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { useCanEditEntity } from '../utils/hooks';\n\nexport default function PostExcerptEditor( {\n\tattributes: { textAlign, moreText, showMoreOnNewLine },\n\tsetAttributes,\n\tisSelected,\n\tcontext: { postId, postType, queryId },\n} ) {\n\tconst isDescendentOfQueryLoop = Number.isFinite( queryId );\n\tconst userCanEdit = useCanEditEntity( 'postType', postType, postId );\n\tconst isEditable = userCanEdit && ! isDescendentOfQueryLoop;\n\tconst [\n\t\trawExcerpt,\n\t\tsetExcerpt,\n\t\t{ rendered: renderedExcerpt, protected: isProtected } = {},\n\t] = useEntityProp( 'postType', postType, 'excerpt', postId );\n\tconst blockProps = useBlockProps( {\n\t\tclassName: classnames( {\n\t\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t\t} ),\n\t} );\n\t/**\n\t * When excerpt is editable, strip the html tags from\n\t * rendered excerpt. This will be used if the entity's\n\t * excerpt has been produced from the content.\n\t */\n\tconst strippedRenderedExcerpt = useMemo( () => {\n\t\tif ( ! renderedExcerpt ) return '';\n\t\tconst document = new window.DOMParser().parseFromString(\n\t\t\trenderedExcerpt,\n\t\t\t'text/html'\n\t\t);\n\t\treturn document.body.textContent || document.body.innerText || '';\n\t}, [ renderedExcerpt ] );\n\tif ( ! postType || ! postId ) {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<BlockControls>\n\t\t\t\t\t<AlignmentToolbar\n\t\t\t\t\t\tvalue={ textAlign }\n\t\t\t\t\t\tonChange={ ( newAlign ) =>\n\t\t\t\t\t\t\tsetAttributes( { textAlign: newAlign } )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</BlockControls>\n\t\t\t\t<div { ...blockProps }>\n\t\t\t\t\t<p>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'This is the Post Excerpt block, it will display the excerpt from single posts.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t\t<p>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'If there are any Custom Post Types with support for excerpts, the Post Excerpt block can display the excerpts of those entries as well.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t</div>\n\t\t\t</>\n\t\t);\n\t}\n\tif ( isProtected && ! userCanEdit ) {\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<Warning>\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'There is no excerpt because this is a protected post.'\n\t\t\t\t\t) }\n\t\t\t\t</Warning>\n\t\t\t</div>\n\t\t);\n\t}\n\tconst readMoreLink = (\n\t\t<RichText\n\t\t\tclassName=\"wp-block-post-excerpt__more-link\"\n\t\t\ttagName=\"a\"\n\t\t\taria-label={ __( '“Read more” link text' ) }\n\t\t\tplaceholder={ __( 'Add \"read more\" link text' ) }\n\t\t\tvalue={ moreText }\n\t\t\tonChange={ ( newMoreText ) =>\n\t\t\t\tsetAttributes( { moreText: newMoreText } )\n\t\t\t}\n\t\t\twithoutInteractiveFormatting={ true }\n\t\t/>\n\t);\n\tconst excerptClassName = classnames( 'wp-block-post-excerpt__excerpt', {\n\t\t'is-inline': ! showMoreOnNewLine,\n\t} );\n\tconst excerptContent = isEditable ? (\n\t\t<RichText\n\t\t\tclassName={ excerptClassName }\n\t\t\taria-label={ __( 'Post excerpt text' ) }\n\t\t\tvalue={\n\t\t\t\trawExcerpt ||\n\t\t\t\tstrippedRenderedExcerpt ||\n\t\t\t\t( isSelected ? '' : __( 'No post excerpt found' ) )\n\t\t\t}\n\t\t\tonChange={ setExcerpt }\n\t\t\ttagName=\"p\"\n\t\t/>\n\t) : (\n\t\t<p className={ excerptClassName }>\n\t\t\t{ strippedRenderedExcerpt || __( 'No post excerpt found' ) }\n\t\t</p>\n\t);\n\treturn (\n\t\t<>\n\t\t\t<BlockControls>\n\t\t\t\t<AlignmentToolbar\n\t\t\t\t\tvalue={ textAlign }\n\t\t\t\t\tonChange={ ( newAlign ) =>\n\t\t\t\t\t\tsetAttributes( { textAlign: newAlign } )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody title={ __( 'Settings' ) }>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Show link on new line' ) }\n\t\t\t\t\t\tchecked={ showMoreOnNewLine }\n\t\t\t\t\t\tonChange={ ( newShowMoreOnNewLine ) =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tshowMoreOnNewLine: newShowMoreOnNewLine,\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</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t<div { ...blockProps }>\n\t\t\t\t{ excerptContent }\n\t\t\t\t{ ! showMoreOnNewLine && ' ' }\n\t\t\t\t{ showMoreOnNewLine ? (\n\t\t\t\t\t<p className=\"wp-block-post-excerpt__more-text\">\n\t\t\t\t\t\t{ readMoreLink }\n\t\t\t\t\t</p>\n\t\t\t\t) : (\n\t\t\t\t\treadMoreLink\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-library/src/post-excerpt/edit.js"],"names":["PostExcerptEditor","attributes","textAlign","moreText","showMoreOnNewLine","excerptLength","setAttributes","isSelected","context","postId","postType","queryId","isDescendentOfQueryLoop","Number","isFinite","userCanEdit","isEditable","rawExcerpt","setExcerpt","rendered","renderedExcerpt","protected","isProtected","blockProps","className","wordCountType","strippedRenderedExcerpt","document","window","DOMParser","parseFromString","body","textContent","innerText","newAlign","readMoreLink","newMoreText","excerptClassName","rawOrRenderedExcerpt","trimmedExcerpt","trim","split","join","excerptWithSpaces","numberOfSpaces","length","replaceAll","excerptContent","newShowMoreOnNewLine","value"],"mappings":";;;;;;;;;AASA;;AANA;;AAKA;;AAEA;;AAQA;;AACA;;AAKA;;AAxBA;AACA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BAAD,QACC,4BAAC,6BAAD;AACC,IAAA,KAAK,EAAGrC,SADT;AAEC,IAAA,QAAQ,EAAKgC,QAAF,IACV5B,aAAa,CAAE;AAAEJ,MAAAA,SAAS,EAAEgC;AAAb,KAAF;AAHf,IADD,CADD,EASC,4BAAC,8BAAD,QACC,4BAAC,qBAAD;AAAW,IAAA,KAAK,EAAG,cAAI,UAAJ;AAAnB,KACC,4BAAC,yBAAD;AACC,IAAA,KAAK,EAAG,cAAI,uBAAJ,CADT;AAEC,IAAA,OAAO,EAAG9B,iBAFX;AAGC,IAAA,QAAQ,EAAK4C,oBAAF,IACV1C,aAAa,CAAE;AACdF,MAAAA,iBAAiB,EAAE4C;AADL,KAAF;AAJf,IADD,EAUC,4BAAC,wBAAD;AACC,IAAA,KAAK,EAAG,cAAI,qBAAJ,CADT;AAEC,IAAA,KAAK,EAAG3C,aAFT;AAGC,IAAA,QAAQ,EAAK4C,KAAF,IAAa;AACvB3C,MAAAA,aAAa,CAAE;AAAED,QAAAA,aAAa,EAAE4C;AAAjB,OAAF,CAAb;AACA/B,MAAAA,UAAU;AACV,KANF;AAOC,IAAA,GAAG,EAAC,IAPL;AAQC,IAAA,GAAG,EAAC;AARL,IAVD,CADD,CATD,EAgCC,mCAAUK,UAAV,EACGwB,cADH,EAEG,CAAE3C,iBAAF,IAAuB,GAF1B,EAGGA,iBAAiB,GAClB;AAAG,IAAA,SAAS,EAAC;AAAb,KACG+B,YADH,CADkB,GAKlBA,YARF,CAhCD,CADD;AA8CA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useEntityProp } from '@wordpress/core-data';\nimport { useMemo } from '@wordpress/element';\nimport {\n\tAlignmentToolbar,\n\tBlockControls,\n\tInspectorControls,\n\tRichText,\n\tWarning,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { PanelBody, ToggleControl, RangeControl } from '@wordpress/components';\nimport { __, _x } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { useCanEditEntity } from '../utils/hooks';\n\nexport default function PostExcerptEditor( {\n\tattributes: { textAlign, moreText, showMoreOnNewLine, excerptLength },\n\tsetAttributes,\n\tisSelected,\n\tcontext: { postId, postType, queryId },\n} ) {\n\tconst isDescendentOfQueryLoop = Number.isFinite( queryId );\n\tconst userCanEdit = useCanEditEntity( 'postType', postType, postId );\n\tconst isEditable = userCanEdit && ! isDescendentOfQueryLoop;\n\n\tconst [\n\t\trawExcerpt,\n\t\tsetExcerpt,\n\t\t{ rendered: renderedExcerpt, protected: isProtected } = {},\n\t] = useEntityProp( 'postType', postType, 'excerpt', postId );\n\tconst blockProps = useBlockProps( {\n\t\tclassName: classnames( {\n\t\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t\t} ),\n\t} );\n\n\t/**\n\t * translators: If your word count is based on single characters (e.g. East Asian characters),\n\t * enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'.\n\t * Do not translate into your own language.\n\t */\n\tconst wordCountType = _x( 'words', 'Word count type. Do not translate!' );\n\n\t/**\n\t * When excerpt is editable, strip the html tags from\n\t * rendered excerpt. This will be used if the entity's\n\t * excerpt has been produced from the content.\n\t */\n\tconst strippedRenderedExcerpt = useMemo( () => {\n\t\tif ( ! renderedExcerpt ) return '';\n\t\tconst document = new window.DOMParser().parseFromString(\n\t\t\trenderedExcerpt,\n\t\t\t'text/html'\n\t\t);\n\t\treturn document.body.textContent || document.body.innerText || '';\n\t}, [ renderedExcerpt ] );\n\tif ( ! postType || ! postId ) {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<BlockControls>\n\t\t\t\t\t<AlignmentToolbar\n\t\t\t\t\t\tvalue={ textAlign }\n\t\t\t\t\t\tonChange={ ( newAlign ) =>\n\t\t\t\t\t\t\tsetAttributes( { textAlign: newAlign } )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</BlockControls>\n\t\t\t\t<div { ...blockProps }>\n\t\t\t\t\t<p>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'This is the Post Excerpt block, it will display the excerpt from single posts.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t\t<p>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'If there are any Custom Post Types with support for excerpts, the Post Excerpt block can display the excerpts of those entries as well.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t</div>\n\t\t\t</>\n\t\t);\n\t}\n\tif ( isProtected && ! userCanEdit ) {\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<Warning>\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'There is no excerpt because this is a protected post.'\n\t\t\t\t\t) }\n\t\t\t\t</Warning>\n\t\t\t</div>\n\t\t);\n\t}\n\tconst readMoreLink = (\n\t\t<RichText\n\t\t\tclassName=\"wp-block-post-excerpt__more-link\"\n\t\t\ttagName=\"a\"\n\t\t\taria-label={ __( '“Read more” link text' ) }\n\t\t\tplaceholder={ __( 'Add \"read more\" link text' ) }\n\t\t\tvalue={ moreText }\n\t\t\tonChange={ ( newMoreText ) =>\n\t\t\t\tsetAttributes( { moreText: newMoreText } )\n\t\t\t}\n\t\t\twithoutInteractiveFormatting={ true }\n\t\t/>\n\t);\n\tconst excerptClassName = classnames( 'wp-block-post-excerpt__excerpt', {\n\t\t'is-inline': ! showMoreOnNewLine,\n\t} );\n\n\t/**\n\t * The excerpt length setting needs to be applied to both\n\t * the raw and the rendered excerpt depending on which is being used.\n\t */\n\tconst rawOrRenderedExcerpt = !! renderedExcerpt\n\t\t? strippedRenderedExcerpt\n\t\t: rawExcerpt;\n\n\tlet trimmedExcerpt = '';\n\tif ( wordCountType === 'words' ) {\n\t\ttrimmedExcerpt = rawOrRenderedExcerpt\n\t\t\t.trim()\n\t\t\t.split( ' ', excerptLength )\n\t\t\t.join( ' ' );\n\t} else if ( wordCountType === 'characters_excluding_spaces' ) {\n\t\t/*\n\t\t * 1. Split the excerpt at the character limit,\n\t\t * then join the substrings back into one string.\n\t\t * 2. Count the number of spaces in the excerpt\n\t\t * by comparing the lengths of the string with and without spaces.\n\t\t * 3. Add the number to the length of the visible excerpt,\n\t\t * so that the spaces are excluded from the word count.\n\t\t */\n\t\tconst excerptWithSpaces = rawOrRenderedExcerpt\n\t\t\t.trim()\n\t\t\t.split( '', excerptLength )\n\t\t\t.join( '' );\n\n\t\tconst numberOfSpaces =\n\t\t\texcerptWithSpaces.length -\n\t\t\texcerptWithSpaces.replaceAll( ' ', '' ).length;\n\n\t\ttrimmedExcerpt = rawOrRenderedExcerpt\n\t\t\t.trim()\n\t\t\t.split( '', excerptLength + numberOfSpaces )\n\t\t\t.join( '' );\n\t} else if ( wordCountType === 'characters_including_spaces' ) {\n\t\ttrimmedExcerpt = rawOrRenderedExcerpt.trim().split( '', excerptLength );\n\t}\n\n\ttrimmedExcerpt = trimmedExcerpt + '...';\n\n\tconst excerptContent = isEditable ? (\n\t\t<RichText\n\t\t\tclassName={ excerptClassName }\n\t\t\taria-label={ __( 'Post excerpt text' ) }\n\t\t\tvalue={\n\t\t\t\tisSelected\n\t\t\t\t\t? rawOrRenderedExcerpt\n\t\t\t\t\t: ( trimmedExcerpt !== '...' ? trimmedExcerpt : '' ) ||\n\t\t\t\t\t __( 'No post excerpt found' )\n\t\t\t}\n\t\t\tonChange={ setExcerpt }\n\t\t\ttagName=\"p\"\n\t\t/>\n\t) : (\n\t\t<p className={ excerptClassName }>\n\t\t\t{ trimmedExcerpt !== '...'\n\t\t\t\t? trimmedExcerpt\n\t\t\t\t: __( 'No post excerpt found' ) }\n\t\t</p>\n\t);\n\treturn (\n\t\t<>\n\t\t\t<BlockControls>\n\t\t\t\t<AlignmentToolbar\n\t\t\t\t\tvalue={ textAlign }\n\t\t\t\t\tonChange={ ( newAlign ) =>\n\t\t\t\t\t\tsetAttributes( { textAlign: newAlign } )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody title={ __( 'Settings' ) }>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Show link on new line' ) }\n\t\t\t\t\t\tchecked={ showMoreOnNewLine }\n\t\t\t\t\t\tonChange={ ( newShowMoreOnNewLine ) =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tshowMoreOnNewLine: newShowMoreOnNewLine,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t<RangeControl\n\t\t\t\t\t\tlabel={ __( 'Max number of words' ) }\n\t\t\t\t\t\tvalue={ excerptLength }\n\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\tsetAttributes( { excerptLength: value } );\n\t\t\t\t\t\t\tsetExcerpt();\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tmin=\"10\"\n\t\t\t\t\t\tmax=\"100\"\n\t\t\t\t\t/>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t<div { ...blockProps }>\n\t\t\t\t{ excerptContent }\n\t\t\t\t{ ! showMoreOnNewLine && ' ' }\n\t\t\t\t{ showMoreOnNewLine ? (\n\t\t\t\t\t<p className=\"wp-block-post-excerpt__more-text\">\n\t\t\t\t\t\t{ readMoreLink }\n\t\t\t\t\t</p>\n\t\t\t\t) : (\n\t\t\t\t\treadMoreLink\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</>\n\t);\n}\n"]}
@@ -40,6 +40,10 @@ const metadata = {
40
40
  showMoreOnNewLine: {
41
41
  type: "boolean",
42
42
  "default": true
43
+ },
44
+ excerptLength: {
45
+ type: "number",
46
+ "default": 55
43
47
  }
44
48
  },
45
49
  usesContext: ["postId", "postType", "queryId"],
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-library/src/post-excerpt/index.js"],"names":["name","metadata","settings","icon","transforms","edit","init"],"mappings":";;;;;;;;;AAGA;;AAKA;;AAEA;;AACA;;AAXA;AACA;AACA;;AAGA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAM;AAAEA,EAAAA;AAAF,IAAWC,QAAjB;;AAGO,MAAMC,QAAQ,GAAG;AACvBC,EAAAA,IAAI,EAAJA,kBADuB;AAEvBC,EAAAA,UAAU,EAAVA,mBAFuB;AAGvBC,EAAAA,IAAI,EAAJA;AAHuB,CAAjB;;;AAMA,MAAMC,IAAI,GAAG,MAAM,wBAAW;AAAEN,EAAAA,IAAF;AAAQC,EAAAA,QAAR;AAAkBC,EAAAA;AAAlB,CAAX,CAAnB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { postExcerpt as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport transforms from './transforms';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\ttransforms,\n\tedit,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"]}
1
+ {"version":3,"sources":["@wordpress/block-library/src/post-excerpt/index.js"],"names":["name","metadata","settings","icon","transforms","edit","init"],"mappings":";;;;;;;;;AAGA;;AAKA;;AAEA;;AACA;;AAXA;AACA;AACA;;AAGA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAM;AAAEA,EAAAA;AAAF,IAAWC,QAAjB;;AAGO,MAAMC,QAAQ,GAAG;AACvBC,EAAAA,IAAI,EAAJA,kBADuB;AAEvBC,EAAAA,UAAU,EAAVA,mBAFuB;AAGvBC,EAAAA,IAAI,EAAJA;AAHuB,CAAjB;;;AAMA,MAAMC,IAAI,GAAG,MAAM,wBAAW;AAAEN,EAAAA,IAAF;AAAQC,EAAAA,QAAR;AAAkBC,EAAAA;AAAlB,CAAX,CAAnB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { postExcerpt as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport transforms from './transforms';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\ttransforms,\n\tedit,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"]}