@sanity/tsdoc
Version:
Generate API reference docs from TypeScript projects and store in a Sanity-friendly JSON format. Render a static frontend, or as React components.
1,435 lines (1,433 loc) • 35.3 kB
JavaScript
import { API_MEMBER_TYPES } from "@sanity/tsdoc/store";
import { useClient, useSchema, Preview, defineType, defineField, defineArrayMember, definePlugin } from "sanity";
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
import { TrashIcon, PublishIcon, ComponentIcon, TokenIcon, PackageIcon, RocketIcon } from "@sanity/icons";
import { Stack, Text, Code as Code$1, Card, Button, Box } from "@sanity/ui";
import { useState, useCallback, useMemo } from "react";
import { styled } from "styled-components";
import { IntentLink } from "sanity/router";
import { PortableText } from "@portabletext/react";
const useDeletePackageAction = (props) => {
const { id: documentId } = props, [dialogOpen, setDialogOpen] = useState(!1), onHandle = useCallback(() => {
setDialogOpen(!0);
}, []);
return {
dialog: useMemo(() => dialogOpen ? {
type: "dialog",
header: "Delete package",
content: /* @__PURE__ */ jsx(
DeletePackageDialogContent,
{
documentId,
onComplete: () => setDialogOpen(!1)
}
),
onClose() {
setDialogOpen(!1);
}
} : null, [dialogOpen, documentId]),
disabled: dialogOpen,
icon: TrashIcon,
label: "Delete package",
onHandle,
tone: "critical"
};
};
function DeletePackageDialogContent(props) {
const { documentId, onComplete } = props, client = useClient({ apiVersion: "2023-01-01" }), schemaType = useSchema().get("api.package"), [error, setError] = useState(null), [running, setRunning] = useState(!1), previewValue = useMemo(() => ({ _type: "api.package", _id: documentId }), [documentId]), handleDelete = useCallback(async () => {
try {
setRunning(!0), await client.delete({
query: "*[_id == $documentId || (references($documentId) && _type in $types)]",
params: {
documentId,
types: API_MEMBER_TYPES.concat(["api.release", "api.export", "api.symbol"])
}
}), onComplete(), setRunning(!1);
} catch (err) {
err instanceof Error ? setError(err) : setError(new Error(String(err))), setRunning(!1);
}
}, [client, documentId, onComplete]);
return error ? /* @__PURE__ */ jsxs(Stack, { space: 4, children: [
/* @__PURE__ */ jsxs(Text, { children: [
"Error: ",
error.message
] }),
/* @__PURE__ */ jsx(Code$1, { size: 1, children: error.stack })
] }) : /* @__PURE__ */ jsxs(Stack, { space: 4, children: [
/* @__PURE__ */ jsx(Text, { children: "Are you sure you want to delete this package and all related documents?" }),
/* @__PURE__ */ jsx(Card, { border: !0, padding: 2, radius: 2, children: /* @__PURE__ */ jsx(Preview, { schemaType, value: previewValue }) }),
/* @__PURE__ */ jsx(
Button,
{
loading: running,
onClick: handleDelete,
text: "Yes, delete now",
tone: "critical"
}
)
] });
}
const apiExportType = defineType({
type: "document",
name: "api.export",
title: "Export",
icon: PublishIcon,
fields: [
defineField({
type: "string",
name: "name",
title: "Name"
}),
defineField({
type: "string",
name: "path",
title: "Path"
}),
defineField({
type: "array",
name: "members",
title: "Members",
of: [
defineArrayMember({
type: "reference",
to: [
{ type: "api.class" },
{ type: "api.enum" },
{ type: "api.function" },
{ type: "api.interface" },
{ type: "api.namespace" },
{ type: "api.typeAlias" },
{ type: "api.variable" }
]
})
]
}),
defineField({
type: "reference",
name: "release",
title: "Release",
to: [{ type: "api.release" }],
hidden: !0
}),
defineField({
type: "reference",
name: "package",
title: "Package",
to: [{ type: "api.package" }],
hidden: !0
})
],
preview: {
select: {
name: "name",
packageScope: "package.scope",
packageName: "package.name",
version: "release.version"
},
prepare: (data) => ({
title: data.name,
icon: PublishIcon,
subtitle: [data.packageScope, data.packageName].filter(Boolean).join("/") + `@${data.version}`
})
},
readOnly: !0
}), apiCallSignatureType = defineType({
type: "object",
name: "api.callSignature",
title: "Call signature",
fields: [
defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
}),
defineField({
type: "array",
name: "parameters",
title: "Parameters",
of: [defineArrayMember({ type: "api.parameter" })]
}),
defineField({
type: "api.tokens",
name: "returnType",
title: "Return type"
}),
defineField({
type: "array",
name: "typeParameters",
title: "Type parameters",
of: [defineArrayMember({ type: "api.typeParameter" })]
}),
defineField({
type: "tsdoc.docComment",
name: "comment",
title: "Comment"
})
],
preview: {
select: { title: "name" },
prepare: ({ title }) => ({ title, subtitle: "Call signature" })
}
}), apiClassType = defineType({
type: "document",
name: "api.class",
title: "Class",
fields: [
defineField({
type: "string",
name: "name",
title: "Name"
}),
defineField({
type: "slug",
name: "slug",
title: "Slug"
}),
defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
}),
defineField({
type: "reference",
name: "export",
title: "Export",
to: [{ type: "api.export" }],
hidden: !0
}),
defineField({
type: "reference",
name: "release",
title: "Release",
to: [{ type: "api.release" }],
hidden: !0
}),
defineField({
type: "reference",
name: "package",
title: "Package",
to: [{ type: "api.package" }],
hidden: !0
}),
defineField({
type: "boolean",
name: "isReactComponentType",
title: "This is a React component",
options: { layout: "checkbox" }
}),
defineField({
type: "array",
name: "typeParameters",
title: "Type parameters",
of: [defineArrayMember({ type: "api.typeParameter" })]
}),
defineField({
type: "array",
name: "members",
title: "Members",
of: [
defineArrayMember({ type: "api.constructor" }),
defineArrayMember({ type: "api.method" }),
defineArrayMember({ type: "api.property" })
]
}),
defineField({
type: "tsdoc.docComment",
name: "comment",
title: "Comment"
})
],
preview: {
select: { title: "name", isReactComponentType: "isReactComponentType" },
prepare({ isReactComponentType, title }) {
return isReactComponentType ? { title: `<${title}>`, subtitle: "Component \xB7 Class", icon: ComponentIcon } : { title, subtitle: "Class", icon: TokenIcon };
}
},
readOnly: !0
}), apiConstructorType = defineType({
type: "object",
name: "api.constructor",
title: "Constructor",
fields: [
defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
}),
defineField({
type: "array",
name: "parameters",
title: "Parameters",
of: [defineArrayMember({ type: "api.parameter" })]
}),
defineField({
type: "tsdoc.docComment",
name: "comment",
title: "Comment"
})
],
preview: {
select: {},
prepare: () => ({ title: "(constructor)" })
}
}), apiConstructSignatureType = defineType({
type: "object",
name: "api.constructSignature",
title: "Construct signature",
fields: [
defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
})
],
preview: {
select: { title: "name" },
prepare: ({ title }) => ({ title, subtitle: "Construct signature" })
}
}), apiEnumType = defineType({
type: "document",
name: "api.enum",
title: "Enum",
fields: [
defineField({
type: "string",
name: "name",
title: "Name"
}),
defineField({
type: "slug",
name: "slug",
title: "Slug"
}),
defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
}),
defineField({
type: "reference",
name: "export",
title: "Export",
to: [{ type: "api.export" }],
hidden: !0
}),
defineField({
type: "reference",
name: "release",
title: "Release",
to: [{ type: "api.release" }],
hidden: !0
}),
defineField({
type: "reference",
name: "package",
title: "Package",
to: [{ type: "api.package" }],
hidden: !0
}),
defineField({
type: "tsdoc.docComment",
name: "comment",
title: "Comment"
})
],
preview: {
select: { title: "name" },
prepare: ({ title }) => ({ title, subtitle: "Enum" })
},
readOnly: !0
}), apiFunctionType = defineType({
type: "document",
name: "api.function",
title: "Function",
fields: [
defineField({
type: "string",
name: "name",
title: "Name"
}),
defineField({
type: "slug",
name: "slug",
title: "Slug"
}),
defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
}),
defineField({
type: "reference",
name: "export",
title: "Export",
to: [{ type: "api.export" }],
hidden: !0
}),
defineField({
type: "reference",
name: "release",
title: "Release",
to: [{ type: "api.release" }],
hidden: !0
}),
defineField({
type: "reference",
name: "package",
title: "Package",
to: [{ type: "api.package" }],
hidden: !0
}),
defineField({
type: "array",
name: "parameters",
title: "Parameters",
of: [defineArrayMember({ type: "api.parameter" })]
}),
defineField({
type: "api.tokens",
name: "returnType",
title: "Return type"
}),
defineField({
type: "array",
name: "typeParameters",
title: "Type parameters",
of: [defineArrayMember({ type: "api.typeParameter" })]
}),
defineField({
type: "boolean",
name: "isReactComponentType",
title: "This is a React component",
options: { layout: "checkbox" }
}),
defineField({
type: "boolean",
name: "isReactHook",
title: "This is a React hook",
options: { layout: "checkbox" }
}),
defineField({
type: "boolean",
name: "isOverloading",
title: "This function is overloaded",
options: { layout: "checkbox" }
}),
defineField({
type: "tsdoc.docComment",
name: "comment",
title: "Comment"
})
],
preview: {
select: { title: "name", isReactComponentType: "isReactComponentType" },
prepare({ isReactComponentType, title }) {
return isReactComponentType ? { title: `<${title}>`, subtitle: "Component \xB7 Function", icon: ComponentIcon } : { title, subtitle: "Function", icon: TokenIcon };
}
},
readOnly: !0
}), apiIndexSignatureType = defineType({
type: "object",
name: "api.indexSignature",
title: "Index signature",
fields: [
defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
})
],
preview: {
select: { title: "name" },
prepare: ({ title }) => ({ title, subtitle: "Index signature" })
}
}), apiInterfaceType = defineType({
type: "document",
name: "api.interface",
title: "Interface",
fields: [
defineField({
type: "string",
name: "name",
title: "Name"
}),
defineField({
type: "slug",
name: "slug",
title: "Slug"
}),
defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
}),
defineField({
type: "reference",
name: "export",
title: "Export",
to: [{ type: "api.export" }],
hidden: !0
}),
defineField({
type: "reference",
name: "release",
title: "Release",
to: [{ type: "api.release" }],
hidden: !0
}),
defineField({
type: "reference",
name: "package",
title: "Package",
to: [{ type: "api.package" }],
hidden: !0
}),
defineField({
type: "array",
name: "typeParameters",
title: "Type parameters",
of: [defineArrayMember({ type: "api.typeParameter" })]
}),
defineField({
type: "array",
name: "extends",
title: "Extends",
of: [
defineArrayMember({
type: "object",
name: "api.extend",
title: "Extend",
fields: [
defineField({
type: "api.tokens",
name: "type",
title: "Type"
})
],
preview: {
select: { type: "type" },
prepare: ({ type }) => ({ title: type.map((t) => t.text).join("") })
}
})
]
}),
defineField({
type: "array",
name: "members",
title: "Members",
of: [
defineArrayMember({ type: "api.callSignature" }),
defineArrayMember({ type: "api.constructSignature" }),
defineArrayMember({ type: "api.indexSignature" }),
defineArrayMember({ type: "api.methodSignature" }),
defineArrayMember({ type: "api.propertySignature" })
]
}),
defineField({
type: "tsdoc.docComment",
name: "comment",
title: "Comment"
})
],
preview: {
select: { title: "name" },
prepare: ({ title }) => ({ title, subtitle: "Interface" })
},
readOnly: !0
}), apiMethodType = defineType({
type: "object",
name: "api.method",
title: "Method",
fields: [
defineField({
type: "string",
name: "name",
title: "Name"
}),
defineField({
type: "boolean",
name: "isOptional",
title: "Is optional",
options: { layout: "checkbox" }
}),
defineField({
type: "boolean",
name: "isStatic",
title: "Is static",
options: { layout: "checkbox" }
}),
defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
}),
defineField({
type: "array",
name: "parameters",
title: "Parameters",
of: [defineArrayMember({ type: "api.parameter" })]
}),
defineField({
type: "api.tokens",
name: "returnType",
title: "Return type"
}),
defineField({
type: "array",
name: "typeParameters",
title: "Type parameters",
of: [defineArrayMember({ type: "api.typeParameter" })]
}),
defineField({
type: "tsdoc.docComment",
name: "comment",
title: "Comment"
})
],
preview: {
select: { title: "name" },
prepare: ({ title }) => ({ title, subtitle: "Method" })
}
}), apiMethodSignatureType = defineType({
type: "object",
name: "api.methodSignature",
title: "Method signature",
fields: [
defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
})
],
preview: {
select: { title: "name" },
prepare: ({ title }) => ({ title, subtitle: "Method signature" })
}
}), apiNamespaceType = defineType({
type: "document",
name: "api.namespace",
title: "Namespace",
fields: [
defineField({
type: "string",
name: "name",
title: "Name"
}),
defineField({
type: "slug",
name: "slug",
title: "Slug"
}),
defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
}),
defineField({
type: "reference",
name: "export",
title: "Export",
to: [{ type: "api.export" }],
hidden: !0
}),
defineField({
type: "reference",
name: "release",
title: "Release",
to: [{ type: "api.release" }],
hidden: !0
}),
defineField({
type: "reference",
name: "package",
title: "Package",
to: [{ type: "api.package" }],
hidden: !0
}),
defineField({
type: "tsdoc.docComment",
name: "comment",
title: "Comment"
})
],
preview: {
select: { title: "name" },
prepare: ({ title }) => ({ title, subtitle: "Namespace" })
},
readOnly: !0
}), apiPropertyType = defineType({
type: "object",
name: "api.property",
title: "Property",
fields: [
defineField({
type: "string",
name: "name",
title: "Name"
}),
defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
}),
defineField({
type: "boolean",
name: "isEventProperty",
title: "Is event property",
options: { layout: "checkbox" }
}),
defineField({
type: "boolean",
name: "isOptional",
title: "Is optional",
options: { layout: "checkbox" }
}),
defineField({
type: "boolean",
name: "isStatic",
title: "Is static",
options: { layout: "checkbox" }
}),
defineField({
type: "api.tokens",
name: "type",
title: "Type"
}),
defineField({
type: "tsdoc.docComment",
name: "comment",
title: "Comment"
})
],
preview: {
select: { title: "name" },
prepare: ({ title }) => ({ title, subtitle: "Property" })
}
}), StyledText = styled(Text)`
code {
background-color: transparent;
color: inherit;
}
`;
function APIPropertySignaturePreview(props) {
const { name, isOptional, type } = props;
return /* @__PURE__ */ jsx(Box, { padding: 2, children: /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
/* @__PURE__ */ jsx(StyledText, { size: 1, textOverflow: "ellipsis", weight: "semibold", children: /* @__PURE__ */ jsxs("code", { children: [
name,
isOptional ? "?" : "",
": ",
type?.map((t) => t.text).join("")
] }) }),
/* @__PURE__ */ jsx(Text, { muted: !0, size: 1, children: "Property signature" })
] }) });
}
const apiPropertySignatureType = defineType({
type: "object",
name: "api.propertySignature",
title: "Property signature",
components: {
preview: APIPropertySignaturePreview
},
fields: [
defineField({
type: "string",
name: "name",
title: "Name"
}),
defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
}),
defineField({
type: "boolean",
name: "isOptional",
title: "Is optional",
options: { layout: "checkbox" }
}),
defineField({
type: "api.tokens",
name: "type",
title: "Type"
}),
defineField({
type: "tsdoc.docComment",
name: "comment",
title: "Comment"
})
],
preview: {
select: { name: "name", isOptional: "isOptional", type: "type" }
// prepare: ({isOptional, name, type}: any) => ({
// title: `${name}${isOptional ? '?' : ''}: ${type?.map((t) => t.text).join('')})}`,
// subtitle: 'Property signature',
// }),
}
}), apiTypeAliasType = defineType({
type: "document",
name: "api.typeAlias",
title: "Type alias",
fields: [
defineField({
type: "string",
name: "name",
title: "Name"
}),
defineField({
type: "slug",
name: "slug",
title: "Slug"
}),
defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
}),
defineField({
type: "reference",
name: "export",
title: "Export",
to: [{ type: "api.export" }],
hidden: !0
}),
defineField({
type: "reference",
name: "release",
title: "Release",
to: [{ type: "api.release" }],
hidden: !0
}),
defineField({
type: "reference",
name: "package",
title: "Package",
to: [{ type: "api.package" }],
hidden: !0
}),
defineField({
type: "api.tokens",
name: "type",
title: "Type"
}),
defineField({
type: "array",
name: "typeParameters",
title: "Type parameters",
of: [defineArrayMember({ type: "api.typeParameter" })]
}),
defineField({
type: "tsdoc.docComment",
name: "comment",
title: "Comment"
})
],
preview: {
select: { title: "name" },
prepare: ({ title }) => ({ title, subtitle: "Type alias" })
},
readOnly: !0
}), apiVariableType = defineType({
type: "document",
name: "api.variable",
title: "Variable",
fields: [
defineField({
type: "string",
name: "name",
title: "Name"
}),
defineField({
type: "slug",
name: "slug",
title: "Slug"
}),
defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
}),
defineField({
type: "reference",
name: "export",
title: "Export",
to: [{ type: "api.export" }],
hidden: !0
}),
defineField({
type: "reference",
name: "release",
title: "Release",
to: [{ type: "api.release" }],
hidden: !0
}),
defineField({
type: "reference",
name: "package",
title: "Package",
to: [{ type: "api.package" }],
hidden: !0
}),
defineField({
type: "api.tokens",
name: "type",
title: "Type"
}),
defineField({
type: "reference",
name: "propsType",
title: "Props type",
to: [{ type: "api.interface" }, { type: "api.typeAlias" }]
}),
defineField({
type: "boolean",
name: "isReactComponentType",
title: "This is a React component",
options: { layout: "checkbox" }
}),
defineField({
type: "boolean",
name: "isReactHook",
title: "This is a React hook",
options: { layout: "checkbox" }
}),
defineField({
type: "tsdoc.docComment",
name: "comment",
title: "Comment"
})
],
preview: {
select: { title: "name", isReactComponentType: "isReactComponentType" },
prepare({ isReactComponentType, title }) {
return isReactComponentType ? { title: `<${title}>`, subtitle: "Component \xB7 Variable", icon: ComponentIcon } : { title, subtitle: "Variable", icon: TokenIcon };
}
},
readOnly: !0
}), apiPackageType = defineType({
type: "document",
name: "api.package",
title: "Package",
icon: PackageIcon,
fields: [
defineField({
type: "string",
name: "scope",
title: "Scope"
}),
defineField({
type: "string",
name: "name",
title: "Name"
}),
defineField({
type: "reference",
name: "latestRelease",
title: "Latest release",
to: [{ type: "api.release" }]
}),
defineField({
type: "array",
name: "releases",
title: "Releases",
of: [
defineArrayMember({
type: "reference",
to: [{ type: "api.release" }]
})
]
})
],
readOnly: !0,
preview: {
select: {
scope: "scope",
name: "name"
},
prepare(data) {
return {
title: [data.scope, data.name].filter(Boolean).join("/")
};
}
}
}), apiReleaseType = defineType({
type: "document",
name: "api.release",
title: "Release",
icon: RocketIcon,
fields: [
defineField({
type: "string",
name: "version",
title: "Version"
}),
defineField({
type: "array",
name: "exports",
title: "Exports",
of: [
defineArrayMember({
type: "reference",
to: [{ type: "api.export" }]
})
]
}),
defineField({
type: "array",
name: "memberNames",
title: "Member names",
of: [{ type: "string" }],
options: {
layout: "tags"
}
}),
defineField({
type: "reference",
name: "package",
title: "Package",
to: [{ type: "api.package" }],
hidden: !0
})
],
preview: {
select: {
packageScope: "package.scope",
packageName: "package.name",
version: "version"
},
prepare: (data) => ({
title: data.version,
icon: RocketIcon,
subtitle: [data.packageScope, data.packageName].filter(Boolean).join("/")
})
},
readOnly: !0
}), apiParameterType = defineType({
type: "object",
name: "api.parameter",
title: "Parameter",
fields: [
defineField({
type: "string",
name: "name",
title: "Name"
}),
defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
}),
defineField({
type: "api.tokens",
name: "type",
title: "Type"
}),
defineField({
type: "boolean",
name: "isOptional",
title: "Is optional",
options: { layout: "checkbox" }
}),
defineField({
type: "tsdoc.docComment",
name: "comment",
title: "Comment"
})
]
}), apiReleaseTagType = defineType({
type: "string",
name: "api.releaseTag",
title: "Release tag",
options: {
list: [
{ title: "Public", value: "public" },
{ title: "Beta", value: "beta" }
]
}
}), apiTokenType = defineType({
type: "object",
name: "api.token",
title: "Token",
fields: [
defineField({
type: "string",
name: "text",
title: "Text"
}),
defineField({
type: "reference",
name: "member",
title: "Member",
to: [
{ type: "api.class" },
{ type: "api.enum" },
{ type: "api.function" },
{ type: "api.interface" },
{ type: "api.typeAlias" },
{ type: "api.variable" }
]
})
]
}), Code = styled(Code$1)`
& a {
color: var(--card-link-color);
&:hover {
text-decoration: underline;
}
}
`;
function APITokensInput(props) {
const { value = [] } = props;
return /* @__PURE__ */ jsx(Card, { border: !0, padding: 3, overflow: "auto", radius: 1, children: /* @__PURE__ */ jsxs(Code, { size: 1, children: [
value.length > 0 && value.map((token) => /* @__PURE__ */ jsx(TokenPreview, { token }, token._key)),
value.length === 0 && " "
] }) });
}
function TokenPreview({ token }) {
return token.member?._ref ? /* @__PURE__ */ jsx(IntentLink, { intent: "edit", params: { id: token.member?._ref }, children: token.text }) : /* @__PURE__ */ jsx(Fragment, { children: token.text });
}
const apiTokensType = defineType({
type: "array",
name: "api.tokens",
title: "Tokens",
of: [{ type: "api.token" }],
components: {
input: APITokensInput
}
}), apiTypeParameterType = defineType({
type: "object",
name: "api.typeParameter",
title: "Type parameter",
fields: [
defineField({
type: "string",
name: "name",
title: "Name"
}),
defineField({
type: "api.tokens",
name: "constraintType",
title: "Constraint type"
}),
defineField({
type: "api.tokens",
name: "defaultType",
title: "Default type"
})
// defineField({
// type: 'api.releaseTag',
// name: 'releaseTag',
// title: 'Release tag',
// }),
// defineField({
// type: 'api.tokens',
// name: 'type',
// title: 'Type',
// }),
]
}), apiSymbolType = defineType({
type: "document",
name: "api.symbol",
title: "Symbol",
fields: [
defineField({
type: "string",
name: "name",
title: "Name"
}),
defineField({
type: "reference",
name: "package",
title: "Package",
to: [{ type: "api.package" }]
// hidden: true,
})
],
preview: {
select: {
name: "name",
packageScope: "package.scope",
packageName: "package.name"
},
prepare(data) {
return {
title: data.name,
subtitle: [data.packageScope, data.packageName].filter(Boolean).join("/")
};
}
},
readOnly: !0
}), apiTypes = [
apiPackageType,
apiReleaseType,
apiExportType,
apiSymbolType,
// members
apiCallSignatureType,
apiClassType,
apiConstructSignatureType,
apiConstructorType,
apiEnumType,
apiFunctionType,
apiIndexSignatureType,
apiInterfaceType,
apiMethodSignatureType,
apiMethodType,
apiNamespaceType,
apiPropertySignatureType,
apiPropertyType,
apiTypeAliasType,
apiVariableType,
// shared
apiParameterType,
apiReleaseTagType,
apiTokenType,
apiTokensType,
apiTypeParameterType
], CODE_LANGUAGE = {
tsx: "typescript"
}, components = {
block: {
normal: ({ children }) => /* @__PURE__ */ jsx(Text, { as: "p", muted: !0, children })
},
types: {
code: ({ value }) => /* @__PURE__ */ jsx(Card, { padding: 3, tone: "transparent", children: /* @__PURE__ */ jsx(Code$1, { language: CODE_LANGUAGE[value?.language || "tsx"], size: 1, children: value?.code }) })
}
};
function Blocks(props) {
const { value = [] } = props;
return /* @__PURE__ */ jsx(PortableText, { value, components });
}
function TsdocComment(props) {
const {
customBlocks,
deprecated,
exampleBlocks,
// modifierTags,
// parameters,
// remarks,
// returns,
seeBlocks,
summary
// ...rest
} = props.value || {};
return !deprecated && !exampleBlocks && !seeBlocks && !summary ? /* @__PURE__ */ jsx(Card, { padding: 3, radius: 2, tone: "caution", children: /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
/* @__PURE__ */ jsx(Text, { size: 1, weight: "semibold", children: "No comment" }),
/* @__PURE__ */ jsx(Text, { muted: !0, children: "No extracted tsdoc comment." })
] }) }) : /* @__PURE__ */ jsxs(Stack, { space: 4, children: [
deprecated && /* @__PURE__ */ jsx(Card, { padding: 3, radius: 2, tone: "caution", children: /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
/* @__PURE__ */ jsx(Text, { size: 1, weight: "semibold", children: "Deprecated" }),
/* @__PURE__ */ jsx(Blocks, { value: deprecated.content || [] })
] }) }),
summary && /* @__PURE__ */ jsx(Blocks, { value: summary || [] }),
exampleBlocks && exampleBlocks.length > 0 && exampleBlocks.map((exampleBlock, i) => /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
/* @__PURE__ */ jsxs(Text, { size: 1, weight: "semibold", children: [
"Example #",
i + 1
] }),
/* @__PURE__ */ jsx(Blocks, { value: exampleBlock.content || [] })
] }, exampleBlock._key)),
customBlocks && /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
/* @__PURE__ */ jsx(Text, { size: 1, weight: "semibold", children: "Custom blocks" }),
/* @__PURE__ */ jsx(Stack, { space: 1, children: customBlocks.map((block) => /* @__PURE__ */ jsxs(Card, { padding: 3, radius: 2, tone: "transparent", children: [
/* @__PURE__ */ jsx("div", { children: block.tag }),
/* @__PURE__ */ jsx(Blocks, { value: block?.content || [] })
] }, block._key)) })
] }),
seeBlocks && /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
/* @__PURE__ */ jsx(Text, { size: 1, weight: "semibold", children: "See also" }),
/* @__PURE__ */ jsx(Stack, { space: 1, children: seeBlocks.map((block) => /* @__PURE__ */ jsx(Card, { padding: 3, radius: 2, tone: "transparent", children: /* @__PURE__ */ jsx(Blocks, { value: block?.content || [] }) }, block._key)) })
] })
] });
}
const tsdocCommentType = defineType({
type: "object",
name: "tsdoc.docComment",
title: "TSDoc comment",
components: { input: TsdocComment },
fields: [
{
type: "array",
name: "summary",
title: "Summary",
of: [{ type: "block" }]
},
{
type: "tsdoc.remarksBlock",
name: "remarks",
title: "Remarks"
},
{
type: "array",
name: "seeBlocks",
title: "See",
of: [{ type: "tsdoc.seeBlock" }]
},
{
type: "array",
name: "parameters",
title: "Parameters",
of: [{ type: "tsdoc.paramBlock" }]
},
{
type: "tsdoc.returnsBlock",
name: "returns",
title: "Returns"
},
{
type: "array",
name: "exampleBlocks",
title: "Example blocks",
of: [{ type: "tsdoc.exampleBlock" }]
},
{
type: "array",
name: "modifierTags",
title: "Modifier tags",
of: [{ type: "tsdoc.modifierTag" }]
}
],
options: {
collapsible: !0
}
}), tsdocExampleBlockType = defineType({
type: "object",
name: "tsdoc.exampleBlock",
title: "Example block",
fields: [
{
type: "array",
name: "content",
title: "Content",
of: [
{
type: "block"
},
{
type: "code",
name: "code",
title: "Code"
}
]
}
]
}), tsdocModifierTagType = defineType({
type: "object",
name: "tsdoc.modifierTag",
title: "Modifier tag",
fields: [
{
type: "string",
name: "name",
title: "Name"
}
]
}), tsdocParamBlockType = defineType({
type: "object",
name: "tsdoc.paramBlock",
title: "Param block",
fields: [
{
type: "string",
name: "name",
title: "Name"
},
{
type: "array",
name: "content",
title: "Content",
of: [
{
type: "block"
},
{
type: "code",
name: "code",
title: "Code"
}
]
}
]
}), tsdocRemarksBlockType = defineType({
type: "object",
name: "tsdoc.remarksBlock",
title: "Remarks",
fields: [
{
type: "array",
name: "content",
title: "Content",
of: [
{
type: "block"
},
{
type: "code",
name: "code",
title: "Code"
}
]
}
]
}), tsdocReturnsBlockType = defineType({
type: "object",
name: "tsdoc.returnsBlock",
title: "Returns block",
fields: [
{
type: "array",
name: "content",
title: "Content",
of: [
{
type: "block"
},
{
type: "code",
name: "code",
title: "Code"
}
]
}
]
}), tsdocSeeBlockType = defineType({
type: "object",
name: "tsdoc.seeBlock",
title: "See block",
fields: [
{
type: "array",
name: "content",
title: "Content",
of: [
{
type: "block"
},
{
type: "code",
name: "code",
title: "Code"
}
]
}
]
}), tsdocTypes = [
tsdocCommentType,
tsdocExampleBlockType,
tsdocModifierTagType,
tsdocParamBlockType,
tsdocRemarksBlockType,
tsdocReturnsBlockType,
tsdocSeeBlockType
], tsdoc = definePlugin(() => ({
name: "@sanity/tsdoc/studio-plugin",
document: {
actions: (prev, ctx) => ctx.schemaType === "api.package" ? [useDeletePackageAction] : ctx.schemaType === "api.release" ? [] : ctx.schemaType === "api.export" ? [] : ctx.schemaType === "api.symbol" ? [] : API_MEMBER_TYPES.includes(ctx.schemaType) ? [] : prev
},
schema: {
types: [...apiTypes, ...tsdocTypes]
}
}));
export {
tsdoc
};
//# sourceMappingURL=studio.mjs.map