docusaurus-plugin-typedoc-api
Version:
Docusaurus plugin that provides source code API documentation powered by TypeDoc.
115 lines (112 loc) • 5.46 kB
JavaScript
'use strict';
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
Object.defineProperty(exports, '__esModule', {
value: true
});
const react = require('react');
const themeCommon = require('@docusaurus/theme-common');
const useReflection = require('../hooks/useReflection.js');
const useReflectionMap = require('../hooks/useReflectionMap.js');
const helpers = require('../utils/helpers.js');
const icons = require('../utils/icons.js');
const ApiItemLayout = require('./ApiItemLayout.js');
const Comment = require('./Comment.js');
const Flags = require('./Flags.js');
const Reflection = require('./Reflection.js');
const TypeParametersGeneric = require('./TypeParametersGeneric.js');
const jsxRuntime = require('react/jsx-runtime');
function extractTOC(item, map, hideInherited) {
const toc = [];
const mapped = new Set();
item.groups?.forEach(group => {
group.children?.forEach(childId => {
const child = map[childId];
const shouldShow = child.inheritedFrom ? !hideInherited : true;
if (!shouldShow || mapped.has(child.name)) {
return;
}
if (!child.permalink || child.permalink.includes('#')) {
const iconHtml = icons.getKindIconHtml(child.kind, child.name);
const value = helpers.escapeMdx(child.name);
toc.push({
// @ts-expect-error Not typed upstream
children: [],
id: child.name,
value: iconHtml ? `${iconHtml} ${value}` : value,
level: 1
});
mapped.add(child.name);
}
});
});
return toc;
}
const ApiOptionsContext = /*#__PURE__*/react.createContext({
hideInherited: false,
setHideInherited: hideInherited => {}
});
function ApiItem({
readme: Readme,
route
}) {
const _react$useState = react.useState(false),
_react$useState2 = _slicedToArray(_react$useState, 2),
hideInherited = _react$useState2[0],
setHideInherited = _react$useState2[1];
const apiOptions = react.useMemo(() => ({
hideInherited,
setHideInherited
}), [hideInherited, setHideInherited]);
const item = useReflection.useRequiredReflection(route.id);
const reflections = useReflectionMap.useReflectionMap();
const toc = react.useMemo(() => extractTOC(item, reflections, hideInherited), [item, reflections, hideInherited]);
// Pagination
const prevItem = useReflection.useReflection(item.previousId);
const nextItem = useReflection.useReflection(item.nextId);
const pagingMetadata = react.useMemo(() => ({
next: nextItem ? {
permalink: nextItem.permalink,
title: helpers.escapeMdx(nextItem.name)
} : undefined,
previous: prevItem ? {
permalink: prevItem.permalink,
title: helpers.escapeMdx(prevItem.name)
} : undefined
}), [nextItem, prevItem]);
return /*#__PURE__*/jsxRuntime.jsx(ApiOptionsContext.Provider, {
value: apiOptions,
children: /*#__PURE__*/jsxRuntime.jsxs(ApiItemLayout, {
heading: /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
children: [/*#__PURE__*/jsxRuntime.jsx("span", {
className: "tsd-header-flags",
children: /*#__PURE__*/jsxRuntime.jsx(Flags.Flags, {
flags: item.flags
})
}), helpers.escapeMdx(item.name), " ", /*#__PURE__*/jsxRuntime.jsx(TypeParametersGeneric.TypeParametersGeneric, {
params: item.typeParameters
})]
}),
pageMetadata: /*#__PURE__*/jsxRuntime.jsx(themeCommon.PageMetadata, {
description: item.comment?.summary ? Comment.displayPartsToMarkdown(item.comment.summary) : '',
title: `${item.name} | API`
}),
pagingMetadata: pagingMetadata,
route: route,
toc: toc,
children: [Readme && /*#__PURE__*/jsxRuntime.jsx("section", {
className: "tsd-readme",
children: /*#__PURE__*/jsxRuntime.jsx(Readme, {})
}), /*#__PURE__*/jsxRuntime.jsx(Reflection.Reflection, {
reflection: item
})]
})
});
}
exports.ApiOptionsContext = ApiOptionsContext;
exports.default = ApiItem;
//# sourceMappingURL=ApiItem.js.map