@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,609 lines (1,607 loc) • 40.1 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: !0 });
var store = require("@sanity/tsdoc/store"), sanity = require("sanity"), jsxRuntime = require("react/jsx-runtime"), compilerRuntime = require("react/compiler-runtime"), icons = require("@sanity/icons"), ui = require("@sanity/ui"), react = require("react"), styledComponents = require("styled-components"), router = require("sanity/router"), react$1 = require("@portabletext/react");
const useDeletePackageAction = (props) => {
const $ = compilerRuntime.c(7), {
id: documentId
} = props, [dialogOpen, setDialogOpen] = react.useState(!1);
let t0;
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = () => {
setDialogOpen(!0);
}, $[0] = t0) : t0 = $[0];
const onHandle = t0;
let t1;
bb0: {
if (!dialogOpen) {
t1 = null;
break bb0;
}
let t22;
$[1] === Symbol.for("react.memo_cache_sentinel") ? (t22 = () => setDialogOpen(!1), $[1] = t22) : t22 = $[1];
let t3;
$[2] !== documentId ? (t3 = {
type: "dialog",
header: "Delete package",
content: /* @__PURE__ */ jsxRuntime.jsx(DeletePackageDialogContent, { documentId, onComplete: t22 }),
onClose() {
setDialogOpen(!1);
}
}, $[2] = documentId, $[3] = t3) : t3 = $[3], t1 = t3;
}
const dialog = t1;
let t2;
return $[4] !== dialog || $[5] !== dialogOpen ? (t2 = {
dialog,
disabled: dialogOpen,
icon: icons.TrashIcon,
label: "Delete package",
onHandle,
tone: "critical"
}, $[4] = dialog, $[5] = dialogOpen, $[6] = t2) : t2 = $[6], t2;
};
function DeletePackageDialogContent(props) {
const $ = compilerRuntime.c(26), {
documentId,
onComplete
} = props;
let t0;
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = {
apiVersion: "2023-01-01"
}, $[0] = t0) : t0 = $[0];
const client = sanity.useClient(t0), schema = sanity.useSchema();
let t1;
$[1] !== schema ? (t1 = schema.get("api.package"), $[1] = schema, $[2] = t1) : t1 = $[2];
const schemaType = t1, [error, setError] = react.useState(null), [running, setRunning] = react.useState(!1);
let t2, t3;
$[3] !== documentId ? (t3 = {
_type: "api.package",
_id: documentId
}, $[3] = documentId, $[4] = t3) : t3 = $[4], t2 = t3;
const previewValue = t2;
let t4;
$[5] !== client || $[6] !== documentId || $[7] !== onComplete ? (t4 = async () => {
try {
setRunning(!0), await client.delete({
query: "*[_id == $documentId || (references($documentId) && _type in $types)]",
params: {
documentId,
types: store.API_MEMBER_TYPES.concat(["api.release", "api.export", "api.symbol"])
}
}), onComplete(), setRunning(!1);
} catch (t52) {
const err = t52;
err instanceof Error ? setError(err) : setError(new Error(String(err))), setRunning(!1);
}
}, $[5] = client, $[6] = documentId, $[7] = onComplete, $[8] = t4) : t4 = $[8];
const handleDelete = t4;
if (error) {
let t52;
$[9] !== error.message ? (t52 = /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { children: [
"Error: ",
error.message
] }), $[9] = error.message, $[10] = t52) : t52 = $[10];
let t62;
$[11] !== error.stack ? (t62 = /* @__PURE__ */ jsxRuntime.jsx(ui.Code, { size: 1, children: error.stack }), $[11] = error.stack, $[12] = t62) : t62 = $[12];
let t72;
return $[13] !== t52 || $[14] !== t62 ? (t72 = /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 4, children: [
t52,
t62
] }), $[13] = t52, $[14] = t62, $[15] = t72) : t72 = $[15], t72;
}
let t5;
$[16] === Symbol.for("react.memo_cache_sentinel") ? (t5 = /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Are you sure you want to delete this package and all related documents?" }), $[16] = t5) : t5 = $[16];
let t6;
$[17] !== previewValue || $[18] !== schemaType ? (t6 = /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { border: !0, padding: 2, radius: 2, children: /* @__PURE__ */ jsxRuntime.jsx(sanity.Preview, { schemaType, value: previewValue }) }), $[17] = previewValue, $[18] = schemaType, $[19] = t6) : t6 = $[19];
let t7;
$[20] !== handleDelete || $[21] !== running ? (t7 = /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { loading: running, onClick: handleDelete, text: "Yes, delete now", tone: "critical" }), $[20] = handleDelete, $[21] = running, $[22] = t7) : t7 = $[22];
let t8;
return $[23] !== t6 || $[24] !== t7 ? (t8 = /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 4, children: [
t5,
t6,
t7
] }), $[23] = t6, $[24] = t7, $[25] = t8) : t8 = $[25], t8;
}
const apiExportType = sanity.defineType({
type: "document",
name: "api.export",
title: "Export",
icon: icons.PublishIcon,
fields: [sanity.defineField({
type: "string",
name: "name",
title: "Name"
}), sanity.defineField({
type: "string",
name: "path",
title: "Path"
}), sanity.defineField({
type: "array",
name: "members",
title: "Members",
of: [sanity.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"
}]
})]
}), sanity.defineField({
type: "reference",
name: "release",
title: "Release",
to: [{
type: "api.release"
}],
hidden: !0
}), sanity.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: icons.PublishIcon,
subtitle: [data.packageScope, data.packageName].filter(Boolean).join("/") + `@${data.version}`
})
},
readOnly: !0
}), apiCallSignatureType = sanity.defineType({
type: "object",
name: "api.callSignature",
title: "Call signature",
fields: [sanity.defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
}), sanity.defineField({
type: "array",
name: "parameters",
title: "Parameters",
of: [sanity.defineArrayMember({
type: "api.parameter"
})]
}), sanity.defineField({
type: "api.tokens",
name: "returnType",
title: "Return type"
}), sanity.defineField({
type: "array",
name: "typeParameters",
title: "Type parameters",
of: [sanity.defineArrayMember({
type: "api.typeParameter"
})]
}), sanity.defineField({
type: "tsdoc.docComment",
name: "comment",
title: "Comment"
})],
preview: {
select: {
title: "name"
},
prepare: ({
title
}) => ({
title,
subtitle: "Call signature"
})
}
}), apiClassType = sanity.defineType({
type: "document",
name: "api.class",
title: "Class",
fields: [sanity.defineField({
type: "string",
name: "name",
title: "Name"
}), sanity.defineField({
type: "slug",
name: "slug",
title: "Slug"
}), sanity.defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
}), sanity.defineField({
type: "reference",
name: "export",
title: "Export",
to: [{
type: "api.export"
}],
hidden: !0
}), sanity.defineField({
type: "reference",
name: "release",
title: "Release",
to: [{
type: "api.release"
}],
hidden: !0
}), sanity.defineField({
type: "reference",
name: "package",
title: "Package",
to: [{
type: "api.package"
}],
hidden: !0
}), sanity.defineField({
type: "boolean",
name: "isReactComponentType",
title: "This is a React component",
options: {
layout: "checkbox"
}
}), sanity.defineField({
type: "array",
name: "typeParameters",
title: "Type parameters",
of: [sanity.defineArrayMember({
type: "api.typeParameter"
})]
}), sanity.defineField({
type: "array",
name: "members",
title: "Members",
of: [sanity.defineArrayMember({
type: "api.constructor"
}), sanity.defineArrayMember({
type: "api.method"
}), sanity.defineArrayMember({
type: "api.property"
})]
}), sanity.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: icons.ComponentIcon
} : {
title,
subtitle: "Class",
icon: icons.TokenIcon
};
}
},
readOnly: !0
}), apiConstructorType = sanity.defineType({
type: "object",
name: "api.constructor",
title: "Constructor",
fields: [sanity.defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
}), sanity.defineField({
type: "array",
name: "parameters",
title: "Parameters",
of: [sanity.defineArrayMember({
type: "api.parameter"
})]
}), sanity.defineField({
type: "tsdoc.docComment",
name: "comment",
title: "Comment"
})],
preview: {
select: {},
prepare: () => ({
title: "(constructor)"
})
}
}), apiConstructSignatureType = sanity.defineType({
type: "object",
name: "api.constructSignature",
title: "Construct signature",
fields: [sanity.defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
})],
preview: {
select: {
title: "name"
},
prepare: ({
title
}) => ({
title,
subtitle: "Construct signature"
})
}
}), apiEnumType = sanity.defineType({
type: "document",
name: "api.enum",
title: "Enum",
fields: [sanity.defineField({
type: "string",
name: "name",
title: "Name"
}), sanity.defineField({
type: "slug",
name: "slug",
title: "Slug"
}), sanity.defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
}), sanity.defineField({
type: "reference",
name: "export",
title: "Export",
to: [{
type: "api.export"
}],
hidden: !0
}), sanity.defineField({
type: "reference",
name: "release",
title: "Release",
to: [{
type: "api.release"
}],
hidden: !0
}), sanity.defineField({
type: "reference",
name: "package",
title: "Package",
to: [{
type: "api.package"
}],
hidden: !0
}), sanity.defineField({
type: "tsdoc.docComment",
name: "comment",
title: "Comment"
})],
preview: {
select: {
title: "name"
},
prepare: ({
title
}) => ({
title,
subtitle: "Enum"
})
},
readOnly: !0
}), apiFunctionType = sanity.defineType({
type: "document",
name: "api.function",
title: "Function",
fields: [sanity.defineField({
type: "string",
name: "name",
title: "Name"
}), sanity.defineField({
type: "slug",
name: "slug",
title: "Slug"
}), sanity.defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
}), sanity.defineField({
type: "reference",
name: "export",
title: "Export",
to: [{
type: "api.export"
}],
hidden: !0
}), sanity.defineField({
type: "reference",
name: "release",
title: "Release",
to: [{
type: "api.release"
}],
hidden: !0
}), sanity.defineField({
type: "reference",
name: "package",
title: "Package",
to: [{
type: "api.package"
}],
hidden: !0
}), sanity.defineField({
type: "array",
name: "parameters",
title: "Parameters",
of: [sanity.defineArrayMember({
type: "api.parameter"
})]
}), sanity.defineField({
type: "api.tokens",
name: "returnType",
title: "Return type"
}), sanity.defineField({
type: "array",
name: "typeParameters",
title: "Type parameters",
of: [sanity.defineArrayMember({
type: "api.typeParameter"
})]
}), sanity.defineField({
type: "boolean",
name: "isReactComponentType",
title: "This is a React component",
options: {
layout: "checkbox"
}
}), sanity.defineField({
type: "boolean",
name: "isReactHook",
title: "This is a React hook",
options: {
layout: "checkbox"
}
}), sanity.defineField({
type: "boolean",
name: "isOverloading",
title: "This function is overloaded",
options: {
layout: "checkbox"
}
}), sanity.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: icons.ComponentIcon
} : {
title,
subtitle: "Function",
icon: icons.TokenIcon
};
}
},
readOnly: !0
}), apiIndexSignatureType = sanity.defineType({
type: "object",
name: "api.indexSignature",
title: "Index signature",
fields: [sanity.defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
})],
preview: {
select: {
title: "name"
},
prepare: ({
title
}) => ({
title,
subtitle: "Index signature"
})
}
}), apiInterfaceType = sanity.defineType({
type: "document",
name: "api.interface",
title: "Interface",
fields: [sanity.defineField({
type: "string",
name: "name",
title: "Name"
}), sanity.defineField({
type: "slug",
name: "slug",
title: "Slug"
}), sanity.defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
}), sanity.defineField({
type: "reference",
name: "export",
title: "Export",
to: [{
type: "api.export"
}],
hidden: !0
}), sanity.defineField({
type: "reference",
name: "release",
title: "Release",
to: [{
type: "api.release"
}],
hidden: !0
}), sanity.defineField({
type: "reference",
name: "package",
title: "Package",
to: [{
type: "api.package"
}],
hidden: !0
}), sanity.defineField({
type: "array",
name: "typeParameters",
title: "Type parameters",
of: [sanity.defineArrayMember({
type: "api.typeParameter"
})]
}), sanity.defineField({
type: "array",
name: "extends",
title: "Extends",
of: [sanity.defineArrayMember({
type: "object",
name: "api.extend",
title: "Extend",
fields: [sanity.defineField({
type: "api.tokens",
name: "type",
title: "Type"
})],
preview: {
select: {
type: "type"
},
prepare: ({
type
}) => ({
title: type.map((t) => t.text).join("")
})
}
})]
}), sanity.defineField({
type: "array",
name: "members",
title: "Members",
of: [sanity.defineArrayMember({
type: "api.callSignature"
}), sanity.defineArrayMember({
type: "api.constructSignature"
}), sanity.defineArrayMember({
type: "api.indexSignature"
}), sanity.defineArrayMember({
type: "api.methodSignature"
}), sanity.defineArrayMember({
type: "api.propertySignature"
})]
}), sanity.defineField({
type: "tsdoc.docComment",
name: "comment",
title: "Comment"
})],
preview: {
select: {
title: "name"
},
prepare: ({
title
}) => ({
title,
subtitle: "Interface"
})
},
readOnly: !0
}), apiMethodType = sanity.defineType({
type: "object",
name: "api.method",
title: "Method",
fields: [sanity.defineField({
type: "string",
name: "name",
title: "Name"
}), sanity.defineField({
type: "boolean",
name: "isOptional",
title: "Is optional",
options: {
layout: "checkbox"
}
}), sanity.defineField({
type: "boolean",
name: "isStatic",
title: "Is static",
options: {
layout: "checkbox"
}
}), sanity.defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
}), sanity.defineField({
type: "array",
name: "parameters",
title: "Parameters",
of: [sanity.defineArrayMember({
type: "api.parameter"
})]
}), sanity.defineField({
type: "api.tokens",
name: "returnType",
title: "Return type"
}), sanity.defineField({
type: "array",
name: "typeParameters",
title: "Type parameters",
of: [sanity.defineArrayMember({
type: "api.typeParameter"
})]
}), sanity.defineField({
type: "tsdoc.docComment",
name: "comment",
title: "Comment"
})],
preview: {
select: {
title: "name"
},
prepare: ({
title
}) => ({
title,
subtitle: "Method"
})
}
}), apiMethodSignatureType = sanity.defineType({
type: "object",
name: "api.methodSignature",
title: "Method signature",
fields: [sanity.defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
})],
preview: {
select: {
title: "name"
},
prepare: ({
title
}) => ({
title,
subtitle: "Method signature"
})
}
}), apiNamespaceType = sanity.defineType({
type: "document",
name: "api.namespace",
title: "Namespace",
fields: [sanity.defineField({
type: "string",
name: "name",
title: "Name"
}), sanity.defineField({
type: "slug",
name: "slug",
title: "Slug"
}), sanity.defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
}), sanity.defineField({
type: "reference",
name: "export",
title: "Export",
to: [{
type: "api.export"
}],
hidden: !0
}), sanity.defineField({
type: "reference",
name: "release",
title: "Release",
to: [{
type: "api.release"
}],
hidden: !0
}), sanity.defineField({
type: "reference",
name: "package",
title: "Package",
to: [{
type: "api.package"
}],
hidden: !0
}), sanity.defineField({
type: "tsdoc.docComment",
name: "comment",
title: "Comment"
})],
preview: {
select: {
title: "name"
},
prepare: ({
title
}) => ({
title,
subtitle: "Namespace"
})
},
readOnly: !0
}), apiPropertyType = sanity.defineType({
type: "object",
name: "api.property",
title: "Property",
fields: [sanity.defineField({
type: "string",
name: "name",
title: "Name"
}), sanity.defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
}), sanity.defineField({
type: "boolean",
name: "isEventProperty",
title: "Is event property",
options: {
layout: "checkbox"
}
}), sanity.defineField({
type: "boolean",
name: "isOptional",
title: "Is optional",
options: {
layout: "checkbox"
}
}), sanity.defineField({
type: "boolean",
name: "isStatic",
title: "Is static",
options: {
layout: "checkbox"
}
}), sanity.defineField({
type: "api.tokens",
name: "type",
title: "Type"
}), sanity.defineField({
type: "tsdoc.docComment",
name: "comment",
title: "Comment"
})],
preview: {
select: {
title: "name"
},
prepare: ({
title
}) => ({
title,
subtitle: "Property"
})
}
}), StyledText = styledComponents.styled(ui.Text)`
code {
background-color: transparent;
color: inherit;
}
`;
function APIPropertySignaturePreview(props) {
const $ = compilerRuntime.c(9), {
name,
isOptional,
type
} = props, t0 = isOptional ? "?" : "";
let t1;
$[0] !== type ? (t1 = type?.map(_temp$2).join(""), $[0] = type, $[1] = t1) : t1 = $[1];
let t2;
$[2] !== name || $[3] !== t0 || $[4] !== t1 ? (t2 = /* @__PURE__ */ jsxRuntime.jsx(StyledText, { size: 1, textOverflow: "ellipsis", weight: "semibold", children: /* @__PURE__ */ jsxRuntime.jsxs("code", { children: [
name,
t0,
": ",
t1
] }) }), $[2] = name, $[3] = t0, $[4] = t1, $[5] = t2) : t2 = $[5];
let t3;
$[6] === Symbol.for("react.memo_cache_sentinel") ? (t3 = /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { muted: !0, size: 1, children: "Property signature" }), $[6] = t3) : t3 = $[6];
let t4;
return $[7] !== t2 ? (t4 = /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { padding: 2, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 2, children: [
t2,
t3
] }) }), $[7] = t2, $[8] = t4) : t4 = $[8], t4;
}
function _temp$2(t) {
return t.text;
}
const apiPropertySignatureType = sanity.defineType({
type: "object",
name: "api.propertySignature",
title: "Property signature",
components: {
preview: APIPropertySignaturePreview
},
fields: [sanity.defineField({
type: "string",
name: "name",
title: "Name"
}), sanity.defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
}), sanity.defineField({
type: "boolean",
name: "isOptional",
title: "Is optional",
options: {
layout: "checkbox"
}
}), sanity.defineField({
type: "api.tokens",
name: "type",
title: "Type"
}), sanity.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 = sanity.defineType({
type: "document",
name: "api.typeAlias",
title: "Type alias",
fields: [sanity.defineField({
type: "string",
name: "name",
title: "Name"
}), sanity.defineField({
type: "slug",
name: "slug",
title: "Slug"
}), sanity.defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
}), sanity.defineField({
type: "reference",
name: "export",
title: "Export",
to: [{
type: "api.export"
}],
hidden: !0
}), sanity.defineField({
type: "reference",
name: "release",
title: "Release",
to: [{
type: "api.release"
}],
hidden: !0
}), sanity.defineField({
type: "reference",
name: "package",
title: "Package",
to: [{
type: "api.package"
}],
hidden: !0
}), sanity.defineField({
type: "api.tokens",
name: "type",
title: "Type"
}), sanity.defineField({
type: "array",
name: "typeParameters",
title: "Type parameters",
of: [sanity.defineArrayMember({
type: "api.typeParameter"
})]
}), sanity.defineField({
type: "tsdoc.docComment",
name: "comment",
title: "Comment"
})],
preview: {
select: {
title: "name"
},
prepare: ({
title
}) => ({
title,
subtitle: "Type alias"
})
},
readOnly: !0
}), apiVariableType = sanity.defineType({
type: "document",
name: "api.variable",
title: "Variable",
fields: [sanity.defineField({
type: "string",
name: "name",
title: "Name"
}), sanity.defineField({
type: "slug",
name: "slug",
title: "Slug"
}), sanity.defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
}), sanity.defineField({
type: "reference",
name: "export",
title: "Export",
to: [{
type: "api.export"
}],
hidden: !0
}), sanity.defineField({
type: "reference",
name: "release",
title: "Release",
to: [{
type: "api.release"
}],
hidden: !0
}), sanity.defineField({
type: "reference",
name: "package",
title: "Package",
to: [{
type: "api.package"
}],
hidden: !0
}), sanity.defineField({
type: "api.tokens",
name: "type",
title: "Type"
}), sanity.defineField({
type: "reference",
name: "propsType",
title: "Props type",
to: [{
type: "api.interface"
}, {
type: "api.typeAlias"
}]
}), sanity.defineField({
type: "boolean",
name: "isReactComponentType",
title: "This is a React component",
options: {
layout: "checkbox"
}
}), sanity.defineField({
type: "boolean",
name: "isReactHook",
title: "This is a React hook",
options: {
layout: "checkbox"
}
}), sanity.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: icons.ComponentIcon
} : {
title,
subtitle: "Variable",
icon: icons.TokenIcon
};
}
},
readOnly: !0
}), apiPackageType = sanity.defineType({
type: "document",
name: "api.package",
title: "Package",
icon: icons.PackageIcon,
fields: [sanity.defineField({
type: "string",
name: "scope",
title: "Scope"
}), sanity.defineField({
type: "string",
name: "name",
title: "Name"
}), sanity.defineField({
type: "reference",
name: "latestRelease",
title: "Latest release",
to: [{
type: "api.release"
}]
}), sanity.defineField({
type: "array",
name: "releases",
title: "Releases",
of: [sanity.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 = sanity.defineType({
type: "document",
name: "api.release",
title: "Release",
icon: icons.RocketIcon,
fields: [sanity.defineField({
type: "string",
name: "version",
title: "Version"
}), sanity.defineField({
type: "array",
name: "exports",
title: "Exports",
of: [sanity.defineArrayMember({
type: "reference",
to: [{
type: "api.export"
}]
})]
}), sanity.defineField({
type: "array",
name: "memberNames",
title: "Member names",
of: [{
type: "string"
}],
options: {
layout: "tags"
}
}), sanity.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: icons.RocketIcon,
subtitle: [data.packageScope, data.packageName].filter(Boolean).join("/")
})
},
readOnly: !0
}), apiParameterType = sanity.defineType({
type: "object",
name: "api.parameter",
title: "Parameter",
fields: [sanity.defineField({
type: "string",
name: "name",
title: "Name"
}), sanity.defineField({
type: "api.releaseTag",
name: "releaseTag",
title: "Release tag"
}), sanity.defineField({
type: "api.tokens",
name: "type",
title: "Type"
}), sanity.defineField({
type: "boolean",
name: "isOptional",
title: "Is optional",
options: {
layout: "checkbox"
}
}), sanity.defineField({
type: "tsdoc.docComment",
name: "comment",
title: "Comment"
})]
}), apiReleaseTagType = sanity.defineType({
type: "string",
name: "api.releaseTag",
title: "Release tag",
options: {
list: [{
title: "Public",
value: "public"
}, {
title: "Beta",
value: "beta"
}]
}
}), apiTokenType = sanity.defineType({
type: "object",
name: "api.token",
title: "Token",
fields: [sanity.defineField({
type: "string",
name: "text",
title: "Text"
}), sanity.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 = styledComponents.styled(ui.Code)`
& a {
color: var(--card-link-color);
&:hover {
text-decoration: underline;
}
}
`;
function APITokensInput(props) {
const $ = compilerRuntime.c(7), {
value: t0
} = props;
let t1;
$[0] !== t0 ? (t1 = t0 === void 0 ? [] : t0, $[0] = t0, $[1] = t1) : t1 = $[1];
const value = t1;
let t2;
$[2] !== value ? (t2 = value.length > 0 && value.map(_temp$1), $[2] = value, $[3] = t2) : t2 = $[3];
const t3 = value.length === 0 && " ";
let t4;
return $[4] !== t2 || $[5] !== t3 ? (t4 = /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { border: !0, padding: 3, overflow: "auto", radius: 1, children: /* @__PURE__ */ jsxRuntime.jsxs(Code, { size: 1, children: [
t2,
t3
] }) }), $[4] = t2, $[5] = t3, $[6] = t4) : t4 = $[6], t4;
}
function _temp$1(token) {
return /* @__PURE__ */ jsxRuntime.jsx(TokenPreview, { token }, token._key);
}
function TokenPreview(t0) {
const $ = compilerRuntime.c(7), {
token
} = t0;
if (token.member?._ref) {
const t12 = token.member?._ref;
let t2;
$[0] !== t12 ? (t2 = {
id: t12
}, $[0] = t12, $[1] = t2) : t2 = $[1];
let t3;
return $[2] !== t2 || $[3] !== token.text ? (t3 = /* @__PURE__ */ jsxRuntime.jsx(router.IntentLink, { intent: "edit", params: t2, children: token.text }), $[2] = t2, $[3] = token.text, $[4] = t3) : t3 = $[4], t3;
}
let t1;
return $[5] !== token.text ? (t1 = /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: token.text }), $[5] = token.text, $[6] = t1) : t1 = $[6], t1;
}
const apiTokensType = sanity.defineType({
type: "array",
name: "api.tokens",
title: "Tokens",
of: [{
type: "api.token"
}],
components: {
input: APITokensInput
}
}), apiTypeParameterType = sanity.defineType({
type: "object",
name: "api.typeParameter",
title: "Type parameter",
fields: [
sanity.defineField({
type: "string",
name: "name",
title: "Name"
}),
sanity.defineField({
type: "api.tokens",
name: "constraintType",
title: "Constraint type"
}),
sanity.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 = sanity.defineType({
type: "document",
name: "api.symbol",
title: "Symbol",
fields: [sanity.defineField({
type: "string",
name: "name",
title: "Name"
}), sanity.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__ */ jsxRuntime.jsx(ui.Text, { as: "p", muted: !0, children })
},
types: {
code: ({
value
}) => /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { padding: 3, tone: "transparent", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Code, { language: CODE_LANGUAGE[value?.language || "tsx"], size: 1, children: value?.code }) })
}
};
function Blocks(props) {
const $ = compilerRuntime.c(4), {
value: t0
} = props;
let t1;
$[0] !== t0 ? (t1 = t0 === void 0 ? [] : t0, $[0] = t0, $[1] = t1) : t1 = $[1];
const value = t1;
let t2;
return $[2] !== value ? (t2 = /* @__PURE__ */ jsxRuntime.jsx(react$1.PortableText, { value, components }), $[2] = value, $[3] = t2) : t2 = $[3], t2;
}
function TsdocComment(props) {
const $ = compilerRuntime.c(19);
let t0;
$[0] !== props.value ? (t0 = props.value || {}, $[0] = props.value, $[1] = t0) : t0 = $[1];
const {
customBlocks,
deprecated,
exampleBlocks,
seeBlocks,
summary
} = t0;
if (!deprecated && !exampleBlocks && !seeBlocks && !summary) {
let t12;
return $[2] === Symbol.for("react.memo_cache_sentinel") ? (t12 = /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { padding: 3, radius: 2, tone: "caution", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 3, children: [
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, weight: "semibold", children: "No comment" }),
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { muted: !0, children: "No extracted tsdoc comment." })
] }) }), $[2] = t12) : t12 = $[2], t12;
}
let t1;
$[3] !== deprecated ? (t1 = deprecated && /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { padding: 3, radius: 2, tone: "caution", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 3, children: [
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, weight: "semibold", children: "Deprecated" }),
/* @__PURE__ */ jsxRuntime.jsx(Blocks, { value: deprecated.content || [] })
] }) }), $[3] = deprecated, $[4] = t1) : t1 = $[4];
let t2;
$[5] !== summary ? (t2 = summary && /* @__PURE__ */ jsxRuntime.jsx(Blocks, { value: summary || [] }), $[5] = summary, $[6] = t2) : t2 = $[6];
let t3;
$[7] !== exampleBlocks ? (t3 = exampleBlocks && exampleBlocks.length > 0 && exampleBlocks.map(_temp), $[7] = exampleBlocks, $[8] = t3) : t3 = $[8];
let t4;
$[9] !== customBlocks ? (t4 = customBlocks && /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 3, children: [
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, weight: "semibold", children: "Custom blocks" }),
/* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { space: 1, children: customBlocks.map(_temp2) })
] }), $[9] = customBlocks, $[10] = t4) : t4 = $[10];
let t5;
$[11] !== seeBlocks ? (t5 = seeBlocks && /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 3, children: [
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, weight: "semibold", children: "See also" }),
/* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { space: 1, children: seeBlocks.map(_temp3) })
] }), $[11] = seeBlocks, $[12] = t5) : t5 = $[12];
let t6;
return $[13] !== t1 || $[14] !== t2 || $[15] !== t3 || $[16] !== t4 || $[17] !== t5 ? (t6 = /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 4, children: [
t1,
t2,
t3,
t4,
t5
] }), $[13] = t1, $[14] = t2, $[15] = t3, $[16] = t4, $[17] = t5, $[18] = t6) : t6 = $[18], t6;
}
function _temp3(block_0) {
return /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { padding: 3, radius: 2, tone: "transparent", children: /* @__PURE__ */ jsxRuntime.jsx(Blocks, { value: block_0?.content || [] }) }, block_0._key);
}
function _temp2(block) {
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Card, { padding: 3, radius: 2, tone: "transparent", children: [
/* @__PURE__ */ jsxRuntime.jsx("div", { children: block.tag }),
/* @__PURE__ */ jsxRuntime.jsx(Blocks, { value: block?.content || [] })
] }, block._key);
}
function _temp(exampleBlock, i) {
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 3, children: [
/* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: 1, weight: "semibold", children: [
"Example #",
i + 1
] }),
/* @__PURE__ */ jsxRuntime.jsx(Blocks, { value: exampleBlock.content || [] })
] }, exampleBlock._key);
}
const tsdocCommentType = sanity.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 = sanity.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 = sanity.defineType({
type: "object",
name: "tsdoc.modifierTag",
title: "Modifier tag",
fields: [{
type: "string",
name: "name",
title: "Name"
}]
}), tsdocParamBlockType = sanity.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 = sanity.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 = sanity.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 = sanity.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 = sanity.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" ? [] : store.API_MEMBER_TYPES.includes(ctx.schemaType) ? [] : prev
},
schema: {
types: [...apiTypes, ...tsdocTypes]
}
}));
exports.tsdoc = tsdoc;
//# sourceMappingURL=studio.js.map