diff --git a/docs/faq.md b/docs/faq.md index bc0f8b7..fa4e6b9 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -226,7 +226,7 @@ will return the wire error. Alternatively, if you wish to cancel the operation and immediately stop the client stream, see [below](#cancel-stream) to cancel the operation. -### How do I cancel a client response stream in Connect-Go? +### How do I cancel a client response stream in Connect-Go? {#cancel-stream} To cancel and abort a stream, call the cancel function of the underlying context associated with the stream. This context is provided on stream diff --git a/src/components/home/examples.tsx b/src/components/home/examples.tsx index bfe4cd9..3e19d30 100644 --- a/src/components/home/examples.tsx +++ b/src/components/home/examples.tsx @@ -203,23 +203,23 @@ function CodeBlock({ const lineProps = getLineProps({ line, - key: i, }); if (lineClassNames[i]) { lineProps.className += lineClassNames[i].join(" "); } - const { key: _, ...rest } = lineProps; - return ( - + {line.map((token, key) => { - const { key: _, ...restOf } = getTokenProps({ - token, - key, - }); - return ; + return ( + + ); })}
@@ -243,23 +243,17 @@ function CodeBlock({ line[0].content = "\n"; // eslint-disable-line no-param-reassign } - const lineProps = getLineProps({ line, key: i }); + const lineProps = getLineProps({ line }); // Do not apply syntax highlighting to console output delete lineProps.style; - const { key, ...rest } = lineProps; - return ( - + {line.map((token, key) => { - const tokenProps = getTokenProps({ token, key }); + const tokenProps = getTokenProps({ token }); // Do not apply syntax highlighting to console output delete tokenProps.style; - const { key: _, ...restOf } = getTokenProps({ - token, - key, - }); - return ; + return ; })} ); diff --git a/src/theme/NavbarItem/DocNavbarItem.tsx b/src/theme/NavbarItem/DocNavbarItem.tsx deleted file mode 100644 index 29fad1f..0000000 --- a/src/theme/NavbarItem/DocNavbarItem.tsx +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright 2022-2023 The Connect Authors -// -// Licensed 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 CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * This file is a swizzled and wrapped component, generated and adapted from the - * docusaurus source code, copyright of Facebook, Inc. - * - * The adapted content is licensed under the MIT licence; and the licence can be - * found at https://github.com/facebook/docusaurus/blob/master/LICENSE - * - * To learn more about component swizzling, see: - * https://docusaurus.io/docs/using-themes#wrapping-theme-components - * - * For original sources see: - * https://github.com/facebook/docusaurus/tree/v2.0.0-beta.17/packages/docusaurus-theme-classic/src/theme/NavbarItem/DocNavbarItem.tsx - */ -import { - useActiveDocContext, - useLatestVersion, -} from "@docusaurus/plugin-content-docs/client"; -import { uniq, useDocsPreferredVersion } from "@docusaurus/theme-common"; -import DefaultNavbarItem from "@theme/NavbarItem/DefaultNavbarItem"; -import { getInfimaActiveClassName } from "./utils"; -import clsx from "clsx"; -import React from "react"; - -import type { Props } from "@theme/NavbarItem/DocNavbarItem"; -import type { GlobalVersion } from "@docusaurus/plugin-content-docs/client"; - -function getDocInVersions(versions: GlobalVersion[], docId: string) { - const allDocs = versions.flatMap((version) => version.docs); - const doc = allDocs.find((versionDoc) => versionDoc.id === docId); - if (!doc) { - const docIds = allDocs.map((versionDoc) => versionDoc.id).join("\n- "); - throw new Error( - `DocNavbarItem: couldn't find any doc with id "${docId}" in version${ - versions.length ? "s" : "" - } ${versions.map((version) => version.name).join(", ")}". -Available doc ids are:\n- ${docIds}`, - ); - } - return doc; -} - -export default function DocNavbarItem({ - docId, - label: staticLabel, - docsPluginId, - ...props -}: Props): JSX.Element { - const { activeVersion, activeDoc } = useActiveDocContext(docsPluginId); - const { preferredVersion } = useDocsPreferredVersion(docsPluginId); - const latestVersion = useLatestVersion(docsPluginId); - - // Versions used to look for the doc to link to, ordered + no duplicate - const versions = uniq( - [activeVersion, preferredVersion, latestVersion].filter( - Boolean, - ) as GlobalVersion[], - ); - const doc = getDocInVersions(versions, docId); - const activeDocInfimaClassName = getInfimaActiveClassName(props.mobile); - - return ( - - ); -} diff --git a/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx b/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx deleted file mode 100644 index 7c01983..0000000 --- a/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright 2022-2023 The Connect Authors -// -// Licensed 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 CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * This file is a swizzled and wrapped component, generated and adapted from the - * docusaurus source code, copyright of Facebook, Inc. - * - * The adapted content is licensed under the MIT licence; and the licence can be - * found at https://github.com/facebook/docusaurus/blob/master/LICENSE - * - * To learn more about component swizzling, see: - * https://docusaurus.io/docs/using-themes#wrapping-theme-components - * - * For original sources see: - * https://github.com/facebook/docusaurus/tree/v2.0.0-beta.17/packages/docusaurus-theme-classic/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx - */ -import { - useActiveDocContext, - useLatestVersion, - useVersions, -} from "@docusaurus/plugin-content-docs/client"; -import { useDocsPreferredVersion } from "@docusaurus/theme-common"; -import { translate } from "@docusaurus/Translate"; -import DefaultNavbarItem from "@theme/NavbarItem/DefaultNavbarItem"; -import DropdownNavbarItem from "@theme/NavbarItem/DropdownNavbarItem"; -import React from "react"; - -import type { Props } from "@theme/NavbarItem/DocsVersionDropdownNavbarItem"; -import type { GlobalVersion } from "@docusaurus/plugin-content-docs/client"; -import type { LinkLikeNavbarItemProps } from "@theme/NavbarItem"; - -/* eslint @typescript-eslint/no-non-null-assertion: "off" */ - -const getVersionMainDoc = (version: GlobalVersion) => - version.docs.find((doc) => doc.id === version.mainDocId)!; - -export default function DocsVersionDropdownNavbarItem({ - mobile, - docsPluginId, - dropdownActiveClassDisabled, - dropdownItemsBefore, - dropdownItemsAfter, - ...props -}: Props): JSX.Element { - const activeDocContext = useActiveDocContext(docsPluginId); - const versions = useVersions(docsPluginId); - const latestVersion = useLatestVersion(docsPluginId); - - const { preferredVersion, savePreferredVersionName } = - useDocsPreferredVersion(docsPluginId); - - function getItems(): LinkLikeNavbarItemProps[] { - const versionLinks = versions.map((version) => { - // We try to link to the same doc, in another version - // When not possible, fallback to the "main doc" of the version - const versionDoc = - activeDocContext?.alternateDocVersions[version.name] || - getVersionMainDoc(version); - return { - isNavLink: true, - label: version.label, - to: versionDoc.path, - isActive: () => version === activeDocContext?.activeVersion, - onClick: () => { - savePreferredVersionName(version.name); - }, - }; - }); - - return [...dropdownItemsBefore, ...versionLinks, ...dropdownItemsAfter]; - } - - const items = getItems(); - - const dropdownVersion = - activeDocContext.activeVersion ?? preferredVersion ?? latestVersion; - - // Mobile dropdown is handled a bit differently - const dropdownLabel = - mobile && items.length > 1 - ? translate({ - id: "theme.navbar.mobileVersionsDropdown.label", - message: "Versions", - description: - "The label for the navbar versions dropdown on mobile view", - }) - : dropdownVersion.label; - const dropdownTo = - mobile && items.length > 1 - ? undefined - : getVersionMainDoc(dropdownVersion).path; - - // We don't want to render a version dropdown with 0 or 1 item. If we build - // the site with a single docs version (onlyIncludeVersions: ['1.0.0']), - // We'd rather render a button instead of a dropdown - if (items.length <= 1) { - return ( - false : undefined} - /> - ); - } - - return ( - false : undefined} - /> - ); -} diff --git a/src/theme/NavbarItem/DocsVersionNavbarItem.tsx b/src/theme/NavbarItem/DocsVersionNavbarItem.tsx deleted file mode 100644 index 57c6dae..0000000 --- a/src/theme/NavbarItem/DocsVersionNavbarItem.tsx +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2022-2023 The Connect Authors -// -// Licensed 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 CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * This file is a swizzled and wrapped component, generated and adapted from the - * docusaurus source code, copyright of Facebook, Inc. - * - * The adapted content is licensed under the MIT licence; and the licence can be - * found at https://github.com/facebook/docusaurus/blob/master/LICENSE - * - * To learn more about component swizzling, see: - * https://docusaurus.io/docs/using-themes#wrapping-theme-components - * - * For original sources see: - * https://github.com/facebook/docusaurus/tree/v2.0.0-beta.17/packages/docusaurus-theme-classic/src/theme/NavbarItem/DocsVersionNavbarItem.tsx - */ -import { - GlobalVersion, - useActiveVersion, - useLatestVersion, -} from "@docusaurus/plugin-content-docs/client"; -import { useDocsPreferredVersion } from "@docusaurus/theme-common"; -import DefaultNavbarItem from "@theme/NavbarItem/DefaultNavbarItem"; -import React from "react"; - -import type { Props } from "@theme/NavbarItem/DocsVersionNavbarItem"; - -/* eslint @typescript-eslint/no-non-null-assertion: "off", - @typescript-eslint/no-unused-vars: "off" */ - -const getVersionMainDoc = (version: GlobalVersion) => - version.docs.find((doc) => doc.id === version.mainDocId)!; - -export default function DocsVersionNavbarItem({ - label: staticLabel, - to: staticTo, - docsPluginId, - ...props -}: Props): JSX.Element { - const activeVersion = useActiveVersion(docsPluginId); - const { preferredVersion } = useDocsPreferredVersion(docsPluginId); - const latestVersion = useLatestVersion(docsPluginId); - const version = activeVersion ?? preferredVersion ?? latestVersion; - const label = staticLabel ?? version.label; - const path = staticTo ?? getVersionMainDoc(version).path; - return ; -} diff --git a/tsconfig.json b/tsconfig.json index 68af32d..f43bd23 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { // This file is not used in compilation. It is here just for a nice editor experience. - "extends": "@tsconfig/docusaurus/tsconfig.json", + "extends": "@docusaurus/tsconfig", "compilerOptions": { "jsx": "react", "baseUrl": ".",