From 58c87cf19f781301c1567a512526e7c5777f55ed Mon Sep 17 00:00:00 2001 From: Kelly Dwan Date: Tue, 10 Sep 2024 17:06:17 -0400 Subject: [PATCH 1/2] Blocks: Remove Chapter List This block has been moved to wporg-mu-plugins. --- .../themes/wporg-developer-2023/functions.php | 1 - .../src/chapter-list/block.json | 35 ---- .../src/chapter-list/block.php | 78 --------- .../src/chapter-list/class-chapter-walker.php | 95 ----------- .../src/chapter-list/index.js | 15 -- .../src/chapter-list/style.scss | 158 ------------------ .../src/chapter-list/view.js | 83 --------- 7 files changed, 465 deletions(-) delete mode 100644 source/wp-content/themes/wporg-developer-2023/src/chapter-list/block.json delete mode 100644 source/wp-content/themes/wporg-developer-2023/src/chapter-list/block.php delete mode 100644 source/wp-content/themes/wporg-developer-2023/src/chapter-list/class-chapter-walker.php delete mode 100644 source/wp-content/themes/wporg-developer-2023/src/chapter-list/index.js delete mode 100644 source/wp-content/themes/wporg-developer-2023/src/chapter-list/style.scss delete mode 100644 source/wp-content/themes/wporg-developer-2023/src/chapter-list/view.js diff --git a/source/wp-content/themes/wporg-developer-2023/functions.php b/source/wp-content/themes/wporg-developer-2023/functions.php index 0472684d4..277cf7062 100644 --- a/source/wp-content/themes/wporg-developer-2023/functions.php +++ b/source/wp-content/themes/wporg-developer-2023/functions.php @@ -150,7 +150,6 @@ require __DIR__ . '/inc/block-hooks.php'; // Block files -require_once __DIR__ . '/src/chapter-list/block.php'; require_once __DIR__ . '/src/cli-command-table/block.php'; require_once __DIR__ . '/src/code-changelog/block.php'; require_once __DIR__ . '/src/code-deprecated/block.php'; diff --git a/source/wp-content/themes/wporg-developer-2023/src/chapter-list/block.json b/source/wp-content/themes/wporg-developer-2023/src/chapter-list/block.json deleted file mode 100644 index 6542ea5f8..000000000 --- a/source/wp-content/themes/wporg-developer-2023/src/chapter-list/block.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "$schema": "https://schemas.wp.org/trunk/block.json", - "apiVersion": 2, - "name": "wporg/chapter-list", - "version": "0.1.0", - "title": "Chapter Navigation", - "category": "widgets", - "icon": "smiley", - "description": "", - "usesContext": [ "postId" ], - "attributes": { - "postType": { - "type": "string" - } - }, - "supports": { - "html": false, - "spacing": { - "margin": [ - "top", - "bottom" - ], - "padding": true, - "blockGap": true - }, - "typography": { - "fontSize": true, - "lineHeight": true - } - }, - "textdomain": "wporg", - "editorScript": "file:./index.js", - "style": "file:./style-index.css", - "viewScript": "file:./view.js" -} diff --git a/source/wp-content/themes/wporg-developer-2023/src/chapter-list/block.php b/source/wp-content/themes/wporg-developer-2023/src/chapter-list/block.php deleted file mode 100644 index b546790c5..000000000 --- a/source/wp-content/themes/wporg-developer-2023/src/chapter-list/block.php +++ /dev/null @@ -1,78 +0,0 @@ - __NAMESPACE__ . '\render', - ) - ); -} - -/** - * Render the block content. - * - * @param array $attributes Block attributes. - * @param string $content Block default content. - * @param WP_Block $block Block instance. - * - * @return string Returns the block markup. - */ -function render( $attributes, $content, $block ) { - if ( ! isset( $block->context['postId'] ) ) { - return ''; - } - - $post_id = $block->context['postId']; - $post_type = get_post_type( $post_id ); - - $args = array( - 'title_li' => '', - 'echo' => 0, - 'sort_column' => 'menu_order, title', - 'post_type' => $post_type, - - // Use custom walker that excludes display of orphaned pages. (An ancestor - // of such a page is likely not published and thus this is not accessible.) - 'walker' => new Chapter_Walker(), - ); - - $post_type_obj = get_post_type_object( $post_type ); - - if ( $post_type_obj && current_user_can( $post_type_obj->cap->read_private_posts ) ) { - $args['post_status'] = array( 'publish', 'private' ); - } - - $content = wp_list_pages( $args ); - - $header = '
'; - $header .= do_blocks( - ' -

' . esc_html__( 'Chapters', 'wporg' ) . '

- ' - ); - $header .= ''; - $header .= '
'; - - $wrapper_attributes = get_block_wrapper_attributes(); - return sprintf( - '', - $wrapper_attributes, - $header, - $content - ); -} diff --git a/source/wp-content/themes/wporg-developer-2023/src/chapter-list/class-chapter-walker.php b/source/wp-content/themes/wporg-developer-2023/src/chapter-list/class-chapter-walker.php deleted file mode 100644 index 0db2c87ef..000000000 --- a/source/wp-content/themes/wporg-developer-2023/src/chapter-list/class-chapter-walker.php +++ /dev/null @@ -1,95 +0,0 @@ - 0 specifies the number of display levels. - * - * NOTE: This is identical to `Walker::walk()` except that it ignores orphaned - * pages, which are essentially pages whose ancestor is not published. - * - * @param array $elements An array of elements. - * @param int $max_depth The maximum hierarchical depth. - * @param mixed ...$args Optional additional arguments. - * @return string The hierarchical item output. - */ - public function walk( $elements, $max_depth, ...$args ) { - $output = ''; - - //invalid parameter or nothing to walk - if ( $max_depth < -1 || empty( $elements ) ) { - return $output; - } - - $parent_field = $this->db_fields['parent']; - - // flat display - if ( -1 === $max_depth ) { - $empty_array = array(); - foreach ( $elements as $e ) { - $this->display_element( $e, $empty_array, 1, 0, $args, $output ); - } - return $output; - } - - /* - * Need to display in hierarchical order. - * Separate elements into two buckets: top level and children elements. - * Children_elements is two dimensional array, eg. - * Children_elements[10][] contains all sub-elements whose parent is 10. - */ - $top_level_elements = array(); - $children_elements = array(); - foreach ( $elements as $e ) { - if ( empty( $e->$parent_field ) ) { - $top_level_elements[] = $e; - } else { - $children_elements[ $e->$parent_field ][] = $e; - } - } - - /* - * When none of the elements is top level. - * Assume the first one must be root of the sub elements. - */ - if ( empty( $top_level_elements ) ) { - $first = array_slice( $elements, 0, 1 ); - $root = $first[0]; - - $top_level_elements = array(); - $children_elements = array(); - foreach ( $elements as $e ) { - if ( $root->$parent_field === $e->$parent_field ) { - $top_level_elements[] = $e; - } else { - $children_elements[ $e->$parent_field ][] = $e; - } - } - } - - foreach ( $top_level_elements as $e ) { - $this->display_element( $e, $children_elements, $max_depth, 0, $args, $output ); - } - - /* - * Here is where it differs from the original `walk()`. The original would - * automatically display orphans. - */ - - return $output; - } -} diff --git a/source/wp-content/themes/wporg-developer-2023/src/chapter-list/index.js b/source/wp-content/themes/wporg-developer-2023/src/chapter-list/index.js deleted file mode 100644 index 8dac349aa..000000000 --- a/source/wp-content/themes/wporg-developer-2023/src/chapter-list/index.js +++ /dev/null @@ -1,15 +0,0 @@ -/** - * WordPress dependencies - */ -import { registerBlockType } from '@wordpress/blocks'; - -/** - * Internal dependencies - */ -import Edit from '../shared/dynamic-edit'; -import metadata from './block.json'; -import './style.scss'; - -registerBlockType( metadata.name, { - edit: Edit, -} ); diff --git a/source/wp-content/themes/wporg-developer-2023/src/chapter-list/style.scss b/source/wp-content/themes/wporg-developer-2023/src/chapter-list/style.scss deleted file mode 100644 index 09b8094d3..000000000 --- a/source/wp-content/themes/wporg-developer-2023/src/chapter-list/style.scss +++ /dev/null @@ -1,158 +0,0 @@ -.wp-block-wporg-chapter-list { - --local--line-height: var(--wp--custom--body--small--typography--line-height); - --local--icon-size: calc(var(--local--line-height) * 1em); - line-height: var(--local--line-height); - - @media (max-width: 767px) { - border: 1px solid var(--wp--preset--color--light-grey-1); - border-radius: 2px; - } - - .wporg-chapter-list__header { - position: relative; - - @media (max-width: 767px) { - padding: 15px var(--wp--preset--spacing--20); - } - - .wp-block-heading { - margin-bottom: 0; - } - } - - .wporg-chapter-list__list { - - @media (max-width: 767px) { - display: none; - margin-top: 0; - padding: 0 var(--wp--preset--spacing--20) 15px; - } - } - - ul { - margin-top: 0; - margin-bottom: 0; - list-style-type: none; - padding-inline-start: 0; - } - - li { - margin-block: calc(var(--wp--preset--spacing--20) / 4); - color: var(--wp--preset--color--charcoal-4); - padding-inline-start: var(--local--icon-size); - position: relative; - - &::before { - content: ""; - display: inline-block; - position: absolute; - inset-inline-start: 0; - width: var(--local--icon-size); - height: var(--local--icon-size); - mask-image: url(../../images/dot.svg); - mask-repeat: no-repeat; - mask-position: center; - background-color: var(--wp--preset--color--charcoal-4); - } - } - - .children { - // Shift the children to the left by half the icon size, allowing for the dot width of 4px. - margin-inline-start: calc((var(--local--icon-size) - 4px) * -0.5); - } - - a { - text-decoration: none; - color: inherit; - } - - &.has-js-control { - .page_item_has_children { - padding-inline-start: 0; - - &::before { - display: none; - } - } - - .children { - display: none; - padding-inline-start: var(--local--icon-size); - - &.is-open { - display: revert; - } - } - } - - .wporg-chapter-list__button-group { - display: flex; - align-items: flex-start; - } - - .wporg-chapter-list__toggle, - .wporg-chapter-list__button-group > button { - font-size: inherit; - background-color: transparent; - border: none; - padding: 0; - cursor: pointer; - height: var(--local--icon-size); - - &::before { - content: ""; - display: inline-block; - height: var(--local--icon-size); - width: var(--local--icon-size); - mask-image: url(../../images/chevron-small.svg); - mask-repeat: no-repeat; - mask-position: center; - transform: rotate(-90deg); - background-color: var(--wp--preset--color--charcoal-4); - } - - &[aria-expanded="true"]::before { - transform: revert; - } - - &:focus-visible { - outline: 1px dashed var(--wp--preset--color--blueberry-1); - } - } - - .wporg-chapter-list__toggle { - display: flex; - justify-content: flex-end; - align-items: center; - position: absolute; - top: 0; - right: 0; - width: 100%; - height: 100%; - padding: 0 var(--wp--preset--spacing--20) 0 0; - - @media (min-width: 768px) { - display: none; - } - - &[aria-expanded="true"]::before { - background-color: var(--wp--preset--color--charcoal-1); - } - } - - // Descendent is `span` if there are children, or `a` if not. - .current_page_item, - .current_page_item > span a, - .current_page_item > a { - color: var(--wp--preset--color--charcoal-1); - } - - .current_page_item > span a, - .current_page_item > a { - font-weight: 700; - } - - .current_page_item > span button::before { - background-color: var(--wp--preset--color--charcoal-1); - } -} diff --git a/source/wp-content/themes/wporg-developer-2023/src/chapter-list/view.js b/source/wp-content/themes/wporg-developer-2023/src/chapter-list/view.js deleted file mode 100644 index 727b0389a..000000000 --- a/source/wp-content/themes/wporg-developer-2023/src/chapter-list/view.js +++ /dev/null @@ -1,83 +0,0 @@ -/** - * WordPress dependencies - */ -import { __, sprintf } from '@wordpress/i18n'; - -const init = () => { - const container = document.querySelector( '.wp-block-wporg-chapter-list' ); - const toggleButton = container?.querySelector( '.wporg-chapter-list__toggle' ); - const list = container?.querySelector( '.wporg-chapter-list__list' ); - - if ( toggleButton && list ) { - toggleButton.addEventListener( 'click', function () { - if ( toggleButton.getAttribute( 'aria-expanded' ) === 'true' ) { - toggleButton.setAttribute( 'aria-expanded', false ); - list.removeAttribute( 'style' ); - } else { - toggleButton.setAttribute( 'aria-expanded', true ); - list.setAttribute( 'style', 'display:block;' ); - } - } ); - } - - if ( container ) { - container.classList.toggle( 'has-js-control' ); - - const parents = container.querySelectorAll( '.page_item_has_children' ); - parents.forEach( ( item ) => { - // Get link, remove (will re-ad later). - const link = item.querySelector( ':scope > a' ); - link.remove(); - - // Get submenu - const submenu = item.querySelector( ':scope > ul' ); - - // Create the toggle button. - const button = document.createElement( 'button' ); - button.setAttribute( 'aria-expanded', false ); - // translators: %s link title. - button.setAttribute( 'aria-label', sprintf( __( 'Open %s submenu', 'wporg' ), link.innerText ) ); - button.onclick = () => { - submenu.classList.toggle( 'is-open' ); - // This attribute returns a string. - const isOpen = button.getAttribute( 'aria-expanded' ); - button.setAttribute( 'aria-expanded', isOpen === 'false' ); - if ( isOpen === 'false' ) { - button.setAttribute( - 'aria-label', - // translators: %s link title. - sprintf( __( 'Close %s submenu', 'wporg' ), link.innerText ) - ); - } else { - button.setAttribute( - 'aria-label', - // translators: %s link title. - sprintf( __( 'Open %s submenu', 'wporg' ), link.innerText ) - ); - } - }; - - const buttonGroup = document.createElement( 'span' ); - buttonGroup.className = 'wporg-chapter-list__button-group'; - buttonGroup.append( button, link ); - - item.insertBefore( buttonGroup, submenu ); - - // Automatically open the trail to the current page. - if ( - item.classList.contains( 'current_page_item' ) || - item.classList.contains( 'current_page_ancestor' ) - ) { - submenu.classList.toggle( 'is-open' ); - button.setAttribute( 'aria-expanded', true ); - button.setAttribute( - 'aria-label', - // translators: %s link title. - sprintf( __( 'Close %s submenu', 'wporg' ), link.innerText ) - ); - } - } ); - } -}; - -window.addEventListener( 'load', init ); From fe427c338389b3830ebf45a93e97efa194138ff1 Mon Sep 17 00:00:00 2001 From: Kelly Dwan Date: Tue, 10 Sep 2024 17:08:06 -0400 Subject: [PATCH 2/2] Remove styles from theme.json --- .../themes/wporg-developer-2023/theme.json | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/source/wp-content/themes/wporg-developer-2023/theme.json b/source/wp-content/themes/wporg-developer-2023/theme.json index b52519608..1a96fdc6a 100644 --- a/source/wp-content/themes/wporg-developer-2023/theme.json +++ b/source/wp-content/themes/wporg-developer-2023/theme.json @@ -233,23 +233,6 @@ "lineHeight": "1.3" } }, - "wporg/chapter-list": { - "typography": { - "fontSize": "var(--wp--preset--font-size--small)" - }, - "elements": { - "heading": { - "typography": { - "fontSize": "var(--wp--preset--font-size--normal) !important" - } - }, - "link": { - "color": { - "text": "var(--wp--preset--color--charcoal-4)" - } - } - } - }, "wporg/code-reference-title": { "typography": { "fontFamily": "var(--wp--preset--font-family--monospace)",