UNPKG

docusaurus-plugin-typedoc-api

Version:

Docusaurus plugin that provides source code API documentation powered by TypeDoc.

145 lines (140 loc) 6.82 kB
'use strict'; const react = require('react'); const useMinimalLayout = require('../hooks/useMinimalLayout.js'); const Comment = require('./Comment.js'); const CommentBadges = require('./CommentBadges.js'); const DefaultValue = require('./DefaultValue.js'); const Flags = require('./Flags.js'); const MemberSources = require('./MemberSources.js'); const Parameter = require('./Parameter.js'); const Type = require('./Type.js'); const TypeParameters = require('./TypeParameters.js'); const jsxRuntime = require('react/jsx-runtime'); // https://github.com/TypeStrong/typedoc-default-themes/blob/master/src/default/partials/member.signature.body.hbs function hasSigBody(sig, minimal, hideSources = false) { if (!sig) { return false; } return !hideSources && MemberSources.hasSources(sig) || Comment.hasComment(sig.comment) || sig.typeParameter && sig.typeParameter.length > 0 || !minimal && sig.parameters && sig.parameters.length > 0 || !minimal && sig.type; } function intoReturnComment(comment) { if (comment?.blockTags) { const tags = comment.blockTags.map(tag => tag.tag); if (tags.includes('@returns')) { const index = tags.indexOf('@returns'); return { summary: comment.blockTags[index].content }; } } return undefined; } const HIDE_TAGS = ['@returns', '@param']; // eslint-disable-next-line complexity function MemberSignatureBody({ hideSources, sig }) { const minimal = useMinimalLayout.useMinimalLayout(); const showTypes = sig.typeParameter && sig.typeParameter.length > 0; const showParams = !minimal && sig.parameters && sig.parameters.length > 0; const showReturn = !minimal && sig.type; return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!hideSources && /*#__PURE__*/jsxRuntime.jsx(MemberSources.MemberSources, { reflection: sig }), CommentBadges.isCommentWithModifiers(sig.comment) && /*#__PURE__*/jsxRuntime.jsx(CommentBadges.CommentBadges, { comment: sig.comment }), /*#__PURE__*/jsxRuntime.jsx(Comment.Comment, { comment: sig.comment, hideTags: HIDE_TAGS }), Comment.hasComment(sig.comment) && (showTypes || showParams || showReturn) && /*#__PURE__*/jsxRuntime.jsx("hr", { className: "tsd-divider" }), showTypes && /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [/*#__PURE__*/jsxRuntime.jsx("h4", { className: "tsd-type-parameters-title", children: "Type parameters" }), /*#__PURE__*/jsxRuntime.jsx(TypeParameters.TypeParameters, { params: sig.typeParameter })] }), showParams && /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [/*#__PURE__*/jsxRuntime.jsx("h4", { className: "tsd-parameters-title", children: "Parameters" }), /*#__PURE__*/jsxRuntime.jsx("ul", { className: "tsd-parameters", children: sig.parameters?.map(param => /*#__PURE__*/jsxRuntime.jsxs(react.Fragment, { children: [/*#__PURE__*/jsxRuntime.jsxs("li", { children: [/*#__PURE__*/jsxRuntime.jsxs("h5", { children: [/*#__PURE__*/jsxRuntime.jsx(Flags.Flags, { flags: param.flags }), param.flags?.isRest && /*#__PURE__*/jsxRuntime.jsx("span", { className: "tsd-signature-symbol", children: "..." }), `${param.name}: `, /*#__PURE__*/jsxRuntime.jsx(Type.Type, { type: param.type }), /*#__PURE__*/jsxRuntime.jsx(DefaultValue.DefaultValue, { comment: param.comment, type: param.type, value: param.defaultValue })] }), /*#__PURE__*/jsxRuntime.jsx(Comment.Comment, { comment: param.comment })] }), param.type?.type === 'reflection' && /*#__PURE__*/jsxRuntime.jsx("ul", { children: param.type.declaration?.children?.map(reflectionChild => /*#__PURE__*/jsxRuntime.jsxs("li", { children: [/*#__PURE__*/jsxRuntime.jsxs("h5", { children: [/*#__PURE__*/jsxRuntime.jsx(Flags.Flags, { flags: reflectionChild.flags }), reflectionChild.flags?.isRest && /*#__PURE__*/jsxRuntime.jsx("span", { className: "tsd-signature-symbol", children: "..." }), `${reflectionChild.name}: `, /*#__PURE__*/jsxRuntime.jsx(Type.Type, { type: reflectionChild.type }), /*#__PURE__*/jsxRuntime.jsx(DefaultValue.DefaultValue, { comment: reflectionChild.comment, type: reflectionChild.type, value: reflectionChild.defaultValue })] }), /*#__PURE__*/jsxRuntime.jsx(Comment.Comment, { comment: reflectionChild.comment })] }, reflectionChild.id)) }, param.type.declaration.id), param.type?.type === 'union' && param.type.types.filter(unionType => unionType.type === 'reflection').map(unionReflectionType => /*#__PURE__*/jsxRuntime.jsx("ul", { children: unionReflectionType.declaration?.children?.map(unionChild => /*#__PURE__*/jsxRuntime.jsxs("li", { children: [/*#__PURE__*/jsxRuntime.jsxs("h5", { children: [/*#__PURE__*/jsxRuntime.jsx(Flags.Flags, { flags: unionChild.flags }), unionChild.flags?.isRest && /*#__PURE__*/jsxRuntime.jsx("span", { className: "tsd-signature-symbol", children: "..." }), `${unionChild.name}: `, /*#__PURE__*/jsxRuntime.jsx(Type.Type, { type: unionChild.type }), /*#__PURE__*/jsxRuntime.jsx(DefaultValue.DefaultValue, { comment: unionChild.comment, type: unionChild.type, value: unionChild.defaultValue })] }), /*#__PURE__*/jsxRuntime.jsx(Comment.Comment, { comment: unionChild.comment })] }, unionChild.id)) }, unionReflectionType.declaration.id))] }, param.id)) })] }), showReturn && /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [/*#__PURE__*/jsxRuntime.jsxs("h4", { className: "tsd-returns-title", children: ["Returns ", /*#__PURE__*/jsxRuntime.jsx(Type.Type, { type: sig.type })] }), /*#__PURE__*/jsxRuntime.jsx(Comment.Comment, { comment: intoReturnComment(sig.comment) }), /*#__PURE__*/jsxRuntime.jsx(Parameter.Parameter, { param: Type.extractDeclarationFromType(sig.type) })] })] }); } exports.MemberSignatureBody = MemberSignatureBody; exports.hasSigBody = hasSigBody; //# sourceMappingURL=MemberSignatureBody.js.map