mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 01:53:30 +01:00
refactor: reset state and code cleanup
This commit is contained in:
@@ -1,36 +1,36 @@
|
||||
import {
|
||||
ApiModel,
|
||||
type ApiModel,
|
||||
ApiDeclaredItem,
|
||||
ApiPropertyItem,
|
||||
ApiMethod,
|
||||
ApiParameterListMixin,
|
||||
ApiTypeParameterListMixin,
|
||||
ApiClass,
|
||||
ApiFunction,
|
||||
type ApiPropertyItem,
|
||||
type ApiMethod,
|
||||
type ApiParameterListMixin,
|
||||
type ApiTypeParameterListMixin,
|
||||
type ApiClass,
|
||||
type ApiFunction,
|
||||
ApiItemKind,
|
||||
ApiTypeAlias,
|
||||
ApiEnum,
|
||||
ApiInterface,
|
||||
ApiMethodSignature,
|
||||
ApiPropertySignature,
|
||||
ApiVariable,
|
||||
ApiItem,
|
||||
ApiConstructor,
|
||||
ApiItemContainerMixin,
|
||||
type ApiTypeAlias,
|
||||
type ApiEnum,
|
||||
type ApiInterface,
|
||||
type ApiMethodSignature,
|
||||
type ApiPropertySignature,
|
||||
type ApiVariable,
|
||||
type ApiItem,
|
||||
type ApiConstructor,
|
||||
type ApiItemContainerMixin,
|
||||
} from '@microsoft/api-extractor-model';
|
||||
import { generateTypeParamData } from './TypeParameterMixin';
|
||||
import { Visibility } from './Visibility';
|
||||
import { createCommentNode } from './comment';
|
||||
import type { DocBlockJSON } from './comment/CommentBlock';
|
||||
import type { AnyDocNodeJSON } from './comment/CommentNode';
|
||||
import { DocNodeContainerJSON, nodeContainer } from './comment/CommentNodeContainer';
|
||||
import { type DocNodeContainerJSON, nodeContainer } from './comment/CommentNodeContainer';
|
||||
import {
|
||||
generatePath,
|
||||
genParameter,
|
||||
genReference,
|
||||
genToken,
|
||||
resolveName,
|
||||
TokenDocumentation,
|
||||
type TokenDocumentation,
|
||||
} from '~/util/parse.server';
|
||||
|
||||
export interface ReferenceData {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { ApiItem, ApiModel, TypeParameter } from '@microsoft/api-extractor-model';
|
||||
import { block, DocBlockJSON } from './comment/CommentBlock';
|
||||
import { genToken, TokenDocumentation } from '~/util/parse.server';
|
||||
import { block, type DocBlockJSON } from './comment/CommentBlock';
|
||||
import { genToken, type TokenDocumentation } from '~/util/parse.server';
|
||||
|
||||
export interface TypeParameterData {
|
||||
name: string;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { ApiModel, ApiItem } from '@microsoft/api-extractor-model';
|
||||
import type { DocBlock } from '@microsoft/tsdoc';
|
||||
import { createCommentNode } from '.';
|
||||
import { blockTag, DocBlockTagJSON } from './CommentBlockTag';
|
||||
import { AnyDocNodeJSON, DocNodeJSON, node } from './CommentNode';
|
||||
import { blockTag, type DocBlockTagJSON } from './CommentBlockTag';
|
||||
import { type AnyDocNodeJSON, type DocNodeJSON, node } from './CommentNode';
|
||||
|
||||
export interface DocBlockJSON extends DocNodeJSON {
|
||||
content: AnyDocNodeJSON[];
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { DocCodeSpan } from '@microsoft/tsdoc';
|
||||
import { DocNodeJSON, node } from './CommentNode';
|
||||
import { type DocNodeJSON, node } from './CommentNode';
|
||||
|
||||
export interface DocCodeSpanJSON extends DocNodeJSON {
|
||||
code: string;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { ApiItem, ApiModel } from '@microsoft/api-extractor-model';
|
||||
import type { DocNodeContainer } from '@microsoft/tsdoc';
|
||||
import { createCommentNode } from '.';
|
||||
import { AnyDocNodeJSON, DocNodeJSON, node } from './CommentNode';
|
||||
import { type AnyDocNodeJSON, type DocNodeJSON, node } from './CommentNode';
|
||||
|
||||
export interface DocNodeContainerJSON extends DocNodeJSON {
|
||||
nodes: AnyDocNodeJSON[];
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { DocFencedCode } from '@microsoft/tsdoc';
|
||||
import { DocNodeJSON, node } from './CommentNode';
|
||||
import { type DocNodeJSON, node } from './CommentNode';
|
||||
|
||||
export interface DocFencedCodeJSON extends DocNodeJSON {
|
||||
code: string;
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
import type { ApiItem, ApiModel } from '@microsoft/api-extractor-model';
|
||||
import type { DocDeclarationReference, DocLinkTag } from '@microsoft/tsdoc';
|
||||
import { DocNodeJSON, node } from './CommentNode';
|
||||
import { type DocNodeJSON, node } from './CommentNode';
|
||||
import { generatePath, resolveName } from '~/util/parse.server';
|
||||
|
||||
interface LinkTagCodeLink {
|
||||
name: string;
|
||||
kind: string;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export interface DocLinkTagJSON extends DocNodeJSON {
|
||||
text: string | null;
|
||||
codeDestination: LinkTagCodeLink | null;
|
||||
@@ -28,12 +34,6 @@ export function genToken(
|
||||
};
|
||||
}
|
||||
|
||||
export interface LinkTagCodeLink {
|
||||
name: string;
|
||||
kind: string;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export function linkTagNode(
|
||||
linkNode: DocLinkTag,
|
||||
model: ApiModel,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { ApiItem, ApiModel } from '@microsoft/api-extractor-model';
|
||||
import type { DocParamBlock } from '@microsoft/tsdoc';
|
||||
import { block, DocBlockJSON } from './CommentBlock';
|
||||
import { block, type DocBlockJSON } from './CommentBlock';
|
||||
|
||||
export interface DocParamBlockJSON extends DocBlockJSON {
|
||||
interface DocParamBlockJSON extends DocBlockJSON {
|
||||
name: string;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { DocPlainText } from '@microsoft/tsdoc';
|
||||
import { DocNodeJSON, node } from './CommentNode';
|
||||
import { type DocNodeJSON, node } from './CommentNode';
|
||||
|
||||
export interface DocPlainTextJSON extends DocNodeJSON {
|
||||
text: string;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { ApiItem, ApiModel } from '@microsoft/api-extractor-model';
|
||||
import type { DocComment } from '@microsoft/tsdoc';
|
||||
import { createCommentNode } from '.';
|
||||
import { block, DocBlockJSON } from './CommentBlock';
|
||||
import { DocNodeJSON, node } from './CommentNode';
|
||||
import { block, type DocBlockJSON } from './CommentBlock';
|
||||
import { type DocNodeJSON, node } from './CommentNode';
|
||||
|
||||
export interface DocCommentJSON extends DocNodeJSON {
|
||||
summary: DocNodeJSON[];
|
||||
|
||||
@@ -7,9 +7,9 @@ import {
|
||||
type DocFencedCode,
|
||||
DocNodeKind,
|
||||
type DocBlock,
|
||||
DocComment,
|
||||
DocCodeSpan,
|
||||
DocParamBlock,
|
||||
type DocComment,
|
||||
type DocCodeSpan,
|
||||
type DocParamBlock,
|
||||
} from '@microsoft/tsdoc';
|
||||
import { block } from './CommentBlock';
|
||||
import { codeSpan } from './CommentCodeSpan';
|
||||
|
||||
@@ -23,7 +23,7 @@ import type { TypeParameterData } from '~/DocModel/TypeParameterMixin';
|
||||
import type { AnyDocNodeJSON } from '~/DocModel/comment/CommentNode';
|
||||
import type { TokenDocumentation } from '~/util/parse.server';
|
||||
|
||||
export interface DocContainerProps {
|
||||
interface DocContainerProps {
|
||||
name: string;
|
||||
kind: string;
|
||||
excerpt: string;
|
||||
|
||||
@@ -6,9 +6,7 @@ import { TSDoc } from './tsdoc/TSDoc';
|
||||
import type { ApiMethodJSON, ApiMethodSignatureJSON } from '~/DocModel/ApiNodeJSONEncoder';
|
||||
import { Visibility } from '~/DocModel/Visibility';
|
||||
|
||||
type MethodResolvable = ApiMethodJSON | ApiMethodSignatureJSON;
|
||||
|
||||
function getShorthandName(data: MethodResolvable) {
|
||||
function getShorthandName(data: ApiMethodJSON | ApiMethodSignatureJSON) {
|
||||
return `${data.name}${data.optional ? '?' : ''}(${data.parameters.reduce((prev, cur, index) => {
|
||||
if (index === 0) {
|
||||
return `${prev}${cur.isOptional ? `${cur.name}?` : cur.name}`;
|
||||
@@ -18,7 +16,7 @@ function getShorthandName(data: MethodResolvable) {
|
||||
}, '')})`;
|
||||
}
|
||||
|
||||
export function MethodItem({ data }: { data: MethodResolvable }) {
|
||||
export function MethodItem({ data }: { data: ApiMethodJSON | ApiMethodSignatureJSON }) {
|
||||
const method = data as ApiMethodJSON;
|
||||
|
||||
return (
|
||||
|
||||
@@ -4,6 +4,11 @@ import { Table } from './Table';
|
||||
import { TSDoc } from './tsdoc/TSDoc';
|
||||
import type { ParameterDocumentation } from '~/util/parse.server';
|
||||
|
||||
const columnStyles = {
|
||||
Name: 'font-mono whitespace-nowrap',
|
||||
Type: 'font-mono whitespace-pre-wrap break-normal',
|
||||
};
|
||||
|
||||
export function ParameterTable({ data }: { data: ParameterDocumentation[] }) {
|
||||
const rows = data.map((param) => ({
|
||||
Name: param.name,
|
||||
@@ -12,11 +17,6 @@ export function ParameterTable({ data }: { data: ParameterDocumentation[] }) {
|
||||
Description: param.paramCommentBlock ? <TSDoc node={param.paramCommentBlock} /> : 'None',
|
||||
}));
|
||||
|
||||
const columnStyles = {
|
||||
Name: 'font-mono whitespace-nowrap',
|
||||
Type: 'font-mono whitespace-pre-wrap break-normal',
|
||||
};
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<ScrollArea pb="xs" offsetScrollbars>
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
Text,
|
||||
useMantineColorScheme,
|
||||
} from '@mantine/core';
|
||||
import { type ReactNode, useState } from 'react';
|
||||
import { type ReactNode, useState, useEffect } from 'react';
|
||||
import { VscChevronDown } from 'react-icons/vsc';
|
||||
|
||||
const useStyles = createStyles((theme, { opened }: { opened: boolean }) => ({
|
||||
@@ -51,6 +51,11 @@ export function Section({
|
||||
const { colorScheme } = useMantineColorScheme();
|
||||
const { classes } = useStyles({ opened });
|
||||
|
||||
useEffect(() => {
|
||||
setOpened(!defaultClosed);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Box sx={{ wordBreak: 'break-all' }}>
|
||||
<UnstyledButton className={classes.control} onClick={() => setOpened((o) => !o)}>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Stack, Group, Badge, Title } from '@mantine/core';
|
||||
import { useMediaQuery } from '@mantine/hooks';
|
||||
import { VscSymbolConstant, VscSymbolMethod, VscSymbolProperty } from 'react-icons/vsc';
|
||||
|
||||
import { MethodList } from './MethodList';
|
||||
import { ParameterTable } from './ParameterTable';
|
||||
import { PropertyList } from './PropertyList';
|
||||
|
||||
@@ -27,7 +27,7 @@ import type { MDXRemoteSerializeResult } from 'next-mdx-remote';
|
||||
import Image from 'next/future/image';
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
import { type PropsWithChildren, useState } from 'react';
|
||||
import { type PropsWithChildren, useState, useEffect } from 'react';
|
||||
import { VscChevronDown, VscGithubInverted, VscPackage, VscVersions } from 'react-icons/vsc';
|
||||
import { WiDaySunny, WiNightClear } from 'react-icons/wi';
|
||||
import useSWR from 'swr';
|
||||
@@ -99,6 +99,12 @@ const libraries = [
|
||||
{ label: 'ws', value: 'ws' },
|
||||
];
|
||||
|
||||
const libraryMenuItems = libraries.map((item) => (
|
||||
<Menu.Item key={item.label} component={NextLink} href={`/docs/packages/${item.value}/main`}>
|
||||
{item.label}
|
||||
</Menu.Item>
|
||||
));
|
||||
|
||||
export function SidebarLayout({
|
||||
packageName,
|
||||
branchName,
|
||||
@@ -117,13 +123,13 @@ export function SidebarLayout({
|
||||
const [openedLibPicker, setOpenedLibPicker] = useState(false);
|
||||
const [openedVersionPicker, setOpenedVersionPicker] = useState(false);
|
||||
|
||||
const { classes } = useStyles({ openedLib: openedLibPicker, openedVersion: openedVersionPicker });
|
||||
useEffect(() => {
|
||||
setOpened(false);
|
||||
setOpenedLibPicker(false);
|
||||
setOpenedVersionPicker(false);
|
||||
}, []);
|
||||
|
||||
const libraryMenuItems = libraries.map((item) => (
|
||||
<Menu.Item key={item.label} component={NextLink} href={`/docs/packages/${item.value}/main`}>
|
||||
{item.label}
|
||||
</Menu.Item>
|
||||
));
|
||||
const { classes } = useStyles({ openedLib: openedLibPicker, openedVersion: openedVersionPicker });
|
||||
|
||||
const versionMenuItems =
|
||||
versions?.map((item) => (
|
||||
|
||||
@@ -4,6 +4,12 @@ import { Table } from './Table';
|
||||
import { TSDoc } from './tsdoc/TSDoc';
|
||||
import type { TypeParameterData } from '~/DocModel/TypeParameterMixin';
|
||||
|
||||
const rowElements = {
|
||||
Name: 'font-mono whitespace-nowrap',
|
||||
Constraints: 'font-mono whitespace-pre break-normal',
|
||||
Default: 'font-mono whitespace-pre break-normal',
|
||||
};
|
||||
|
||||
export function TypeParamTable({ data }: { data: TypeParameterData[] }) {
|
||||
const rows = data.map((typeParam) => ({
|
||||
Name: typeParam.name,
|
||||
@@ -13,12 +19,6 @@ export function TypeParamTable({ data }: { data: TypeParameterData[] }) {
|
||||
Description: typeParam.commentBlock ? <TSDoc node={typeParam.commentBlock} /> : 'None',
|
||||
}));
|
||||
|
||||
const rowElements = {
|
||||
Name: 'font-mono whitespace-nowrap',
|
||||
Constraints: 'font-mono whitespace-pre break-normal',
|
||||
Default: 'font-mono whitespace-pre break-normal',
|
||||
};
|
||||
|
||||
return (
|
||||
<ScrollArea pb="xs" offsetScrollbars>
|
||||
<Table
|
||||
|
||||
@@ -3,12 +3,7 @@ import { StandardTags } from '@microsoft/tsdoc';
|
||||
import type { ReactNode } from 'react';
|
||||
import { VscWarning } from 'react-icons/vsc';
|
||||
|
||||
export interface BlockProps {
|
||||
children: ReactNode;
|
||||
title: string;
|
||||
}
|
||||
|
||||
export function Block({ children, title }: BlockProps) {
|
||||
export function Block({ children, title }: { children: ReactNode; title: string }) {
|
||||
return (
|
||||
<Box>
|
||||
<Title order={5}>{title}</Title>
|
||||
@@ -17,18 +12,13 @@ export function Block({ children, title }: BlockProps) {
|
||||
);
|
||||
}
|
||||
|
||||
export interface BlockCommentProps {
|
||||
tagName: string;
|
||||
children: ReactNode;
|
||||
index?: number | undefined;
|
||||
}
|
||||
|
||||
export interface ExampleBlockProps {
|
||||
export function ExampleBlock({
|
||||
children,
|
||||
exampleIndex,
|
||||
}: {
|
||||
children: ReactNode;
|
||||
exampleIndex?: number | undefined;
|
||||
}
|
||||
|
||||
export function ExampleBlock({ children, exampleIndex }: ExampleBlockProps): JSX.Element {
|
||||
}): JSX.Element {
|
||||
return <Block title={`Example ${exampleIndex ? exampleIndex : ''}`}>{children}</Block>;
|
||||
}
|
||||
|
||||
@@ -48,7 +38,15 @@ export function RemarksBlock({ children }: { children: ReactNode }): JSX.Element
|
||||
return <Block title="Remarks">{children}</Block>;
|
||||
}
|
||||
|
||||
export function BlockComment({ children, tagName, index }: BlockCommentProps): JSX.Element {
|
||||
export function BlockComment({
|
||||
children,
|
||||
tagName,
|
||||
index,
|
||||
}: {
|
||||
tagName: string;
|
||||
children: ReactNode;
|
||||
index?: number | undefined;
|
||||
}): JSX.Element {
|
||||
switch (tagName.toUpperCase()) {
|
||||
case StandardTags.example.tagNameWithUpperCase:
|
||||
return <ExampleBlock exampleIndex={index}>{children}</ExampleBlock>;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ColorScheme, ColorSchemeProvider, MantineProvider } from '@mantine/core';
|
||||
import { useColorScheme } from '@mantine/hooks';
|
||||
import { SpotlightAction, SpotlightProvider } from '@mantine/spotlight';
|
||||
import { type SpotlightAction, SpotlightProvider } from '@mantine/spotlight';
|
||||
import type { AppProps } from 'next/app';
|
||||
import Head from 'next/head';
|
||||
import { type NextRouter, useRouter } from 'next/router';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createStylesServer, ServerStyles } from '@mantine/next';
|
||||
import Document, { Html, Head, Main, NextScript, DocumentContext, DocumentInitialProps } from 'next/document';
|
||||
import Document, { Html, Head, Main, NextScript, type DocumentContext, type DocumentInitialProps } from 'next/document';
|
||||
|
||||
const stylesServer = createStylesServer();
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { readFile } from 'node:fs/promises';
|
||||
import { join } from 'node:path';
|
||||
import { Affix, Box, Button, LoadingOverlay, Transition } from '@mantine/core';
|
||||
import { useMediaQuery, useWindowScroll } from '@mantine/hooks';
|
||||
import { ApiFunction, ApiPackage } from '@microsoft/api-extractor-model';
|
||||
import { ApiFunction, type ApiPackage } from '@microsoft/api-extractor-model';
|
||||
import { MDXRemote } from 'next-mdx-remote';
|
||||
import { serialize } from 'next-mdx-remote/serialize';
|
||||
import Head from 'next/head';
|
||||
@@ -175,7 +175,6 @@ export const getStaticProps: GetStaticProps = async ({ params }) => {
|
||||
memberName && containerKey ? findMemberByKey(model, packageName, containerKey, branchName) ?? null : null,
|
||||
source: mdxSource,
|
||||
},
|
||||
key: `${memberName ?? 'index'}-${branchName}`,
|
||||
revalidate: 3600,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
import { ApiItem, ApiModel, ApiPackage } from '~/util/api-extractor.server';
|
||||
import { ApiItem, ApiModel, type ApiPackage } from '~/util/api-extractor.server';
|
||||
import { TSDocConfigFile } from '~/util/tsdoc-config.server';
|
||||
import { TSDocConfiguration } from '~/util/tsdoc.server';
|
||||
|
||||
|
||||
@@ -10,10 +10,10 @@ import {
|
||||
type ApiPropertyItem,
|
||||
type ExcerptToken,
|
||||
type Parameter,
|
||||
ApiFunction,
|
||||
type ApiFunction,
|
||||
} from '@microsoft/api-extractor-model';
|
||||
import type { DocNode, DocParagraph, DocPlainText } from '@microsoft/tsdoc';
|
||||
import { Meaning, ModuleSource } from '@microsoft/tsdoc/lib-commonjs/beta/DeclarationReference';
|
||||
import { type Meaning, ModuleSource } from '@microsoft/tsdoc/lib-commonjs/beta/DeclarationReference';
|
||||
import { createCommentNode } from '~/DocModel/comment';
|
||||
import type { DocBlockJSON } from '~/DocModel/comment/CommentBlock';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user