diff --git a/src/@adobe/gatsby-theme-aio/components/MDXFilter/index.js b/src/@adobe/gatsby-theme-aio/components/MDXFilter/index.js deleted file mode 100644 index 4a0904100..000000000 --- a/src/@adobe/gatsby-theme-aio/components/MDXFilter/index.js +++ /dev/null @@ -1,416 +0,0 @@ -/* - * Copyright 2020 Adobe. All rights reserved. - * This file is licensed to you under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. You may obtain a copy - * of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - * OF ANY KIND, either express or implied. See the License for the specific language - * governing permissions and limitations under the License. - */ - -import React, { Children, cloneElement, useContext } from 'react'; -import { withPrefix } from 'gatsby'; -import { MDXProvider } from '@mdx-js/react'; -import { css } from '@emotion/react'; -import '@spectrum-css/divider'; -import '@spectrum-css/actiongroup'; -import Context from '@adobe/gatsby-theme-aio/src/components/Context'; -import { - layoutColumns, - findSelectedPage, - findSelectedPageSiblings, - findSelectedPageNextPrev, - findSelectedTopPage, - findSelectedTopPageMenu, - findSelectedPages, - DESKTOP_SCREEN_WIDTH, - SIDENAV_WIDTH, - DEFAULT_HOME, - rootFix, - rootFixPages, - cleanRootFix -} from '@adobe/gatsby-theme-aio/src/utils'; - -import { Footer } from '@adobe/gatsby-theme-aio/src/components/Footer'; -import { Contributors } from '@adobe/gatsby-theme-aio/src/components/Contributors'; -import { Feedback } from '@adobe/gatsby-theme-aio/src/components/Feedback'; -import { GitHubActions } from '@adobe/gatsby-theme-aio/src/components/GitHubActions'; -import { Breadcrumbs } from '@adobe/gatsby-theme-aio/src/components/Breadcrumbs'; -import { Attribution } from '@adobe/gatsby-theme-aio/src/components/Attribution'; -import { Edition } from '@adobe/gatsby-theme-aio/src/components/Edition'; -import { OnThisPage } from '@adobe/gatsby-theme-aio/src/components/OnThisPage'; -import { NextSteps } from '@adobe/gatsby-theme-aio/src/components/NextSteps'; -import { NextPrev } from '@adobe/gatsby-theme-aio/src/components/NextPrev'; - -import { jsDocFilter } from '@adobe/gatsby-theme-aio/src/components/JsDocParameters'; - -import { MDXComponents } from '@adobe/gatsby-theme-aio/src/components/MDXFilter/MDXComponents'; -import { MDXBlocks } from '@adobe/gatsby-theme-aio/src/components/MDXFilter/MDXBlocks'; - -// Filters custom MDX components out of the markdown -const filterChildren = ({ childrenArray, query, hasSideNav }) => { - const filteredChildren = []; - - let heroChild = null; - let resourcesChild = null; - - while (childrenArray.length) { - const child = childrenArray[0]; - let ignoredChildrenCount = 0; - - // Verify if child is a custom MDX component - Object.keys(MDXBlocks).forEach((customComponent) => { - if (child?.props?.mdxType === customComponent) { - ignoredChildrenCount++; - - let slots = []; - // Custom MDX components have slots and/or repeat props to identify markdown content - // It's currently not possible to Interleaving Markdown in JSX with MDX v1 (https://github.com/mdx-js/mdx/issues/628) - if (child.props.slots || child.props.repeat) { - const repeat = Math.max(parseInt(child.props.repeat) || 1, 1); - - for (let i = 0; i < repeat; i++) { - slots = slots.concat( - // Set default slots to element if repeat is defined - (child.props.slots || 'element') - .split(',') - .map((slot, k) => [`${slot.trim()}${repeat === 1 ? '' : i}`, childrenArray[slots.length + k + 1]]) - ); - } - } - - if (slots.length) { - ignoredChildrenCount += slots.length; - - const props = Object.fromEntries(slots); - - if (child.props.mdxType === 'Variant') { - // Set the query to define if the Variant should show its content - props.query = query; - } - - if (child.props.mdxType === 'Hero' && hasSideNav) { - props.width = `calc(${DESKTOP_SCREEN_WIDTH} - ${SIDENAV_WIDTH});`; - } - - const childClone = cloneElement(child, { - ...props - }); - - if (child.props.mdxType === 'Hero') { - // Only 1 Hero per page allowed - heroChild = heroChild || childClone; - } else if (child.props.mdxType === 'Resources') { - // Only 1 Resources per page allowed - resourcesChild = resourcesChild || childClone; - } else { - filteredChildren.push(childClone); - } - } else { - filteredChildren.push(child); - } - } - }); - - if (ignoredChildrenCount === 0) { - ignoredChildrenCount++; - - filteredChildren.push(child); - } - - childrenArray = childrenArray.splice(ignoredChildrenCount); - } - - return { - filteredChildren, - heroChild, - resourcesChild - }; -}; - -export default ({ children, pageContext, query }) => { - const { hasSideNav, siteMetadata, location, allSitePage, allMdx, allGithub, allGithubContributors } = - useContext(Context); - const isTranscludedContent = typeof pageContext === 'undefined'; - let childrenArray = Children.toArray(children); - - if (isTranscludedContent || pageContext?.frontmatter?.layout === 'none') { - const { filteredChildren } = filterChildren({ childrenArray: jsDocFilter(childrenArray), query, hasSideNav }); - return isTranscludedContent ? ( - {filteredChildren} - ) : ( - - {filteredChildren} -