Reworked generating API docs

This commit is contained in:
thepaperpilot 2023-04-12 18:41:44 -05:00
parent d0ef0dd1e0
commit 7d86acc534
71 changed files with 1685 additions and 39 deletions

View file

@ -31,7 +31,7 @@ function component(renderedUsage, // props, events, methods and slots documentat
{ isSubComponent, hasSubComponents }) {
const { displayName, description, docsBlocks } = doc
return `
# Component: ${displayName}
### ${displayName} Component
${description ? '> ' + description : ''}
@ -50,7 +50,7 @@ const eventShouldDisplayCol = {
[eventCols[2]]: event => event.properties?.length
}
const eventGetDisplay = {
[eventCols[0]]: event => `<pre>${clean(event.name)}</pre>`,
[eventCols[0]]: event => `<code>${clean(event.name)}</code>`,
[eventCols[1]]: event => clean(event.description || ""),
[eventCols[2]]: event => {
if (!event.properties) return "";
@ -59,12 +59,12 @@ const eventGetDisplay = {
if (!type) {
return ''
}
return `**${name}** <pre>${clean(type.names.length ? type.names.join(', ') : '')}</pre> - ${description}`
return `**${name}** <code>${clean(type.names.length ? type.names.join(', ') : '')}</code> - ${description}`
}).join('<br/>')
}
}
const propCols = ["Name", "Types", "Description", "Values", "Default"];
const propCols = ["Name", "Type", "Description", "Values", "Default"];
const propShouldDisplayCol = {
[propCols[0]]: pr => pr.name,
[propCols[1]]: pr => pr.type?.name,
@ -73,12 +73,12 @@ const propShouldDisplayCol = {
[propCols[4]]: pr => pr.defaultValue
}
const propGetDisplay = {
[propCols[0]]: pr => `<pre>${clean(pr.name)}</pre>` + (pr.required ? "*" : ""),
[propCols[0]]: pr => `<code>${clean(pr.name)}</code>` + (pr.required ? "*" : ""),
[propCols[1]]: pr => {
let n = pr.type?.name ?? ''
if (n === "union") n = pr.type?.elements.map(el => el.name).join(' | ')
if (n === "Array") n = (pr.type?.elements.length > 1 ? "(" : "") + pr.type?.elements.map(el => el.name).join(' | ') + (pr.type?.elements.length > 1 ? ")" : "") + "[]"
return n ? '<pre>' + clean(n) + '</pre>' : ''
return n ? '<code>' + clean(n) + '</code>' : ''
},
[propCols[2]]: pr => clean((pr.description ?? '') + renderTags(pr.tags)),
[propCols[3]]: pr => clean(pr.values?.map(pv => `\`${pv}\``).join(', ') ?? '-'),
@ -92,7 +92,7 @@ const slotShouldDisplayCol = {
[slotCols[2]]: slot => slot.bindings?.length
}
const slotGetDisplay = {
[slotCols[0]]: slot => `<pre>${clean(slot.name)}</pre>`,
[slotCols[0]]: slot => `<code>${clean(slot.name)}</code>`,
[slotCols[1]]: slot => clean(slot.description || ""),
[slotCols[2]]: slot => {
if (!slot.bindings) return "";
@ -101,11 +101,11 @@ const slotGetDisplay = {
if (!type) {
return ''
}
return `**${name}** <pre>${
return `**${name}** <code>${
type.name === 'union' && type.elements
? type.elements.map(({ name: insideName }) => insideName).join(', ')
: type.name
}</pre> - ${description}`
}</code> - ${description}`
}).join('<br/>')
}
}
@ -114,7 +114,7 @@ function displayUsedCols(title, cols, shouldDisplayCol, getDisplay, rows, opt) {
cols = cols.filter(col => rows.some(shouldDisplayCol[col]));
if (!cols) return "";
let output = `\n${opt.isSubComponent || opt.hasSubComponents ? '#' : ''}## ${title}\n|`;
let output = `\n${opt.isSubComponent || opt.hasSubComponents ? '#' : ''}#### ${title}\n|`;
cols.forEach(col => (output += ` ${col} |`));
output += `\n|`;
cols.forEach(col => (output += ' :-- |'));

View file

@ -139,7 +139,9 @@ function walk(dir, sidebar) {
const resolvedFile = path.join(dir, file);
const stat = fs.statSync(resolvedFile);
if (stat.isDirectory()) {
walk(resolvedFile, sidebar);
const subSidebar = { text: camelToTitle(file), items: [], collapsed: true };
sidebar.push(subSidebar);
walk(resolvedFile, subSidebar.items);
} else if (!file.includes("Component") || dir.includes("components")) {
sidebar.push({ text: camelToTitle(file.substr(0, file.length - 3)), link: "/" + resolvedFile.substr(5, resolvedFile.length - 8).replace(/\\/g, "/") + ".html" });
}

View file

@ -48,3 +48,7 @@ body {
color: var(--vp-c-text-light-1);
background-color: var(--vp-code-block-bg);
}
.vp-doc h3 + h4 {
margin-top: 16px;
}

View file

@ -15,14 +15,14 @@ function walk(dir, cb) {
}
(async () => {
// Replace overview file
fs.copyFileSync("./overview.md", "./docs/api/overview.md");
fs.unlinkSync("./docs/api/index.md");
await walk("./components", (dir, file, resolve) => {
const relPath = path.relative("./components", dir);
let dest = path.resolve("./docs/api", relPath);
if (relPath.includes("features")) {
dest = path.resolve("./docs/api/modules", relPath);
}
// Copy components over
await walk("./components/components", (dir, file, resolve) => {
const relPath = path.relative("./components/components", dir);
let dest = path.resolve("./docs/api/components", relPath);
const filePath = path.resolve(dir, file);
const stream = fs.createReadStream(filePath);
let lineCount = 0;
@ -41,32 +41,53 @@ function walk(dir, cb) {
resolve();
});
});
// Write features' components to end of file
await walk("./components/features", (dir, file, resolve) => {
const relPath = path.relative("./components/features", dir);
let dest = path.resolve("./docs/api/modules/features", relPath);
if (relPath == "infoboxes") {
dest = dest.slice(0, -2);
} else if (relPath === "tabs") {
dest += file.includes("TabComponent") ? "\\tab" : "\\tabFamily";
}
try {
fs.accessSync(dest + ".md", fs.constants.R_OK | fs.constants.W_OK);
} catch (err) {
dest = dest.slice(0, -1);
try {
fs.accessSync(dest + ".md", fs.constants.R_OK | fs.constants.W_OK);
} catch (err) {
console.log("Couldn't find file at", dest + ".md");
resolve();
return;
}
}
dest = dest + ".md";
let data = fs.readFileSync(dest).toString();
const elementData = fs.readFileSync(path.resolve(dir, file));
const fd = fs.openSync(dest, "w+");
const componentsSection = data.indexOf("## Components");
if (componentsSection == -1) {
data += `\n## Components\n`;
}
fs.writeSync(fd, data);
fs.writeSync(fd, "\n" + elementData + "\n");
fs.closeSync(fd);
resolve();
});
// Add frontmatter to every file
const frontmatter = Buffer.from("---\neditLink: false\n---\n");
await walk("./docs/api", function addFrontmatter(dir, file, resolve) {
if (path.extname(file) !== ".md") return;
const filePath = path.resolve(dir, file);
if (dir.endsWith("interfaces")) {
fs.unlinkSync(filePath);
resolve();
return;
}
const data = fs.readFileSync(filePath).toString();
const fd = fs.openSync(filePath, "w+");
fs.writeSync(fd, frontmatter);
if (!path.relative("./docs/api", dir).includes("components") && !path.basename(file).includes("Component")) {
const files = fs.readdirSync(dir).filter(p => p.match(/.*Component.md/));
if (files.length > 0) {
const firstSectionIndex = data.indexOf("##");
fs.writeSync(fd, data.slice(0, firstSectionIndex));
const componentsList = `## Components\n\n${files.map(f => `- [${f.slice(0, -12)}](./${f})`).join("\n")}\n\n`;
fs.writeSync(fd, componentsList);
fs.writeSync(fd, data.slice(firstSectionIndex));
} else {
fs.writeSync(fd, data);
}
} else {
fs.writeSync(fd, data);
}
fs.writeSync(fd, data);
fs.closeSync(fd);
resolve();
});

View file

@ -0,0 +1,2 @@
import { MarkdownTheme } from '../../theme';
export default function (theme: MarkdownTheme): void;

View file

@ -0,0 +1,37 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Handlebars = require("handlebars");
const utils_1 = require("../../utils");
function default_1(theme) {
Handlebars.registerHelper('breadcrumbs', function () {
const { entryPoints, entryDocument, project, readme } = theme;
if (!project) {
return '';
}
const hasReadmeFile = !readme.endsWith('none');
const breadcrumbs = [];
const globalsName = entryPoints.length > 1 ? 'Modules' : 'Exports';
breadcrumbs.push(this.url === entryDocument
? project.name
: `[${project.name}](${Handlebars.helpers.relativeURL(entryDocument)})`);
if (hasReadmeFile) {
breadcrumbs.push(this.url === project.url
? globalsName
: `[${globalsName}](${Handlebars.helpers.relativeURL('modules.md')})`);
}
const breadcrumbsOut = breadcrumb(this, this.model, breadcrumbs);
return breadcrumbsOut;
});
}
exports.default = default_1;
function breadcrumb(page, model, md) {
if (model && model.parent) {
breadcrumb(page, model.parent, md);
if (model.url) {
md.push(page.url === model.url
? `${(0, utils_1.escapeChars)(model.name)}`
: `[${(0, utils_1.escapeChars)(model.name)}](${Handlebars.helpers.relativeURL(model.url)})`);
}
}
return md.join(' / ');
}

View file

@ -0,0 +1,3 @@
import { MarkdownTheme } from '../../theme';
export default function (theme: MarkdownTheme): void;
export declare function readFile(file: string): string;

View file

@ -0,0 +1,106 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.readFile = void 0;
const fs = require("fs");
const Handlebars = require("handlebars");
const Path = require("path");
function default_1(theme) {
Handlebars.registerHelper('comment', function (parts) {
const result = [];
for (const part of parts) {
switch (part.kind) {
case 'text':
case 'code':
result.push(part.text);
break;
case 'inline-tag':
switch (part.tag) {
case '@label':
case '@inheritdoc':
break;
case '@link':
case '@linkcode':
case '@linkplain': {
if (part.target) {
const url = typeof part.target === 'string'
? part.target
: Handlebars.helpers.relativeURL(part.target.url);
const wrap = part.tag === '@linkcode' ? '`' : '';
result.push(url ? `[${wrap}${part.text}${wrap}](${url})` : part.text);
}
else {
result.push(part.text);
}
break;
}
default:
result.push(`{${part.tag} ${part.text}}`);
break;
}
break;
default:
result.push('');
}
}
return parseMarkdown(result.join(''), theme);
});
}
exports.default = default_1;
function parseMarkdown(text, theme) {
const includePattern = /\[\[include:([^\]]+?)\]\]/g;
const mediaPattern = /media:\/\/([^ ")\]}]+)/g;
if (theme.includes) {
text = text.replace(includePattern, (_match, path) => {
path = Path.join(theme.includes, path.trim());
if (fs.existsSync(path) && fs.statSync(path).isFile()) {
const contents = readFile(path);
return contents;
}
else {
theme.application.logger.warn('Could not find file to include: ' + path);
return '';
}
});
}
if (theme.mediaDirectory) {
text = text.replace(mediaPattern, (match, path) => {
const fileName = Path.join(theme.mediaDirectory, path);
if (fs.existsSync(fileName) && fs.statSync(fileName).isFile()) {
return Handlebars.helpers.relativeURL('media') + '/' + path;
}
else {
theme.application.logger.warn('Could not find media file: ' + fileName);
return match;
}
});
}
return text;
}
function readFile(file) {
const buffer = fs.readFileSync(file);
switch (buffer[0]) {
case 0xfe:
if (buffer[1] === 0xff) {
let i = 0;
while (i + 1 < buffer.length) {
const temp = buffer[i];
buffer[i] = buffer[i + 1];
buffer[i + 1] = temp;
i += 2;
}
return buffer.toString('ucs2', 2);
}
break;
case 0xff:
if (buffer[1] === 0xfe) {
return buffer.toString('ucs2', 2);
}
break;
case 0xef:
if (buffer[1] === 0xbb) {
return buffer.toString('utf8', 3);
}
}
return buffer.toString('utf8', 0);
}
exports.readFile = readFile;

View file

@ -0,0 +1 @@
export default function (): void;

View file

@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Handlebars = require("handlebars");
const utils_1 = require("../../utils");
function default_1() {
Handlebars.registerHelper('comments', function (comment) {
var _a;
const md = [];
if (comment.summary) {
md.push(Handlebars.helpers.comment(comment.summary));
}
if ((_a = comment.blockTags) === null || _a === void 0 ? void 0 : _a.length) {
const tags = comment.blockTags
.filter((tag) => tag.tag !== '@returns')
.map((tag) => `**\`${(0, utils_1.camelToTitleCase)(tag.tag.substring(1))}\`**\n\n${Handlebars.helpers.comment(tag.content)}`);
md.push(tags.join('\n\n'));
}
return md.join('\n\n');
});
}
exports.default = default_1;

View file

@ -0,0 +1,2 @@
import { MarkdownTheme } from '../../theme';
export default function (theme: MarkdownTheme): void;

View file

@ -0,0 +1,36 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Handlebars = require("handlebars");
const typedoc_1 = require("typedoc");
const utils_1 = require("../../utils");
function default_1(theme) {
Handlebars.registerHelper('declarationTitle', function () {
const md = theme.hideMembersSymbol ? [] : [(0, utils_1.memberSymbol)(this)];
function getType(reflection) {
var _a, _b;
const reflectionType = reflection.type;
if (reflectionType && ((_a = reflectionType.declaration) === null || _a === void 0 ? void 0 : _a.children)) {
return ': `Object`';
}
return ((((_b = reflection.parent) === null || _b === void 0 ? void 0 : _b.kindOf(typedoc_1.ReflectionKind.Enum)) ? ' = ' : ': ') +
Handlebars.helpers.type.call(reflectionType ? reflectionType : reflection, 'object'));
}
if (this.flags && this.flags.length > 0 && !this.flags.isRest) {
md.push(' ' + this.flags.map((flag) => `\`${flag}\``).join(' '));
}
md.push(`${this.flags.isRest ? '... ' : ''} **${(0, utils_1.escapeChars)(this.name)}**`);
if (this instanceof typedoc_1.DeclarationReflection && this.typeParameters) {
md.push(`<${this.typeParameters
.map((typeParameter) => `\`${typeParameter.name}\``)
.join(', ')}\\>`);
}
md.push(getType(this));
if (!(this.type instanceof typedoc_1.LiteralType) &&
this.defaultValue &&
this.defaultValue !== '...') {
md.push(` = \`${(0, utils_1.stripLineBreaks)((0, utils_1.stripComments)(this.defaultValue))}\``);
}
return md.join('');
});
}
exports.default = default_1;

View file

@ -0,0 +1 @@
export default function (): void;

View file

@ -0,0 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Handlebars = require("handlebars");
const utils_1 = require("../../utils");
function default_1() {
Handlebars.registerHelper('escape', function (str) {
return (0, utils_1.escapeChars)(str);
});
}
exports.default = default_1;

View file

@ -0,0 +1 @@
export default function (): void;

View file

@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Handlebars = require("handlebars");
const utils_1 = require("../../utils");
function default_1() {
Handlebars.registerHelper('hierarchy', function (level) {
const md = [];
const symbol = level > 0 ? getSymbol(level) : '-';
this.types.forEach((hierarchyType) => {
if (this.isTarget) {
md.push(`${symbol} **\`${hierarchyType}\`**`);
}
else {
md.push(`${symbol} ${Handlebars.helpers.type.call(hierarchyType)}`);
}
});
if (this.next) {
md.push(Handlebars.helpers.hierarchy.call(this.next, level + 1));
}
return md.join('\n\n');
});
function getSymbol(level) {
return (0, utils_1.spaces)(2) + [...Array(level)].map(() => '↳').join('');
}
}
exports.default = default_1;

View file

@ -0,0 +1 @@
export default function (): void;

View file

@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Handlebars = require("handlebars");
const typedoc_1 = require("typedoc");
function default_1() {
Handlebars.registerHelper('ifIsReference', function (options) {
return this instanceof typedoc_1.ReferenceReflection
? options.fn(this)
: options.inverse(this);
});
}
exports.default = default_1;

View file

@ -0,0 +1,2 @@
import { MarkdownTheme } from '../../theme';
export default function (theme: MarkdownTheme): void;

View file

@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Handlebars = require("handlebars");
function default_1(theme) {
Handlebars.registerHelper('ifNamedAnchors', function (options) {
return theme.namedAnchors ? options.fn(this) : options.inverse(this);
});
}
exports.default = default_1;

View file

@ -0,0 +1,2 @@
import { MarkdownTheme } from '../../theme';
export default function (theme: MarkdownTheme): void;

View file

@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Handlebars = require("handlebars");
function default_1(theme) {
Handlebars.registerHelper('ifShowBreadcrumbs', function (options) {
return theme.hideBreadcrumbs ? options.inverse(this) : options.fn(this);
});
}
exports.default = default_1;

View file

@ -0,0 +1,2 @@
import { MarkdownTheme } from '../../theme';
export default function (theme: MarkdownTheme): void;

View file

@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Handlebars = require("handlebars");
function default_1(theme) {
Handlebars.registerHelper('ifShowNamedAnchors', function (options) {
return theme.namedAnchors ? options.fn(this) : options.inverse(this);
});
}
exports.default = default_1;

View file

@ -0,0 +1,2 @@
import { MarkdownTheme } from '../../theme';
export default function (theme: MarkdownTheme): void;

View file

@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Handlebars = require("handlebars");
function default_1(theme) {
Handlebars.registerHelper('ifShowPageTitle', function (options) {
return theme.hidePageTitle ? options.inverse(this) : options.fn(this);
});
}
exports.default = default_1;

View file

@ -0,0 +1 @@
export default function (): void;

View file

@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Handlebars = require("handlebars");
const typedoc_1 = require("typedoc");
function default_1() {
Handlebars.registerHelper('ifShowReturns', function (options) {
var _a;
return this.type && !((_a = this.parent) === null || _a === void 0 ? void 0 : _a.kindOf(typedoc_1.ReflectionKind.Constructor))
? options.fn(this)
: options.inverse(this);
});
}
exports.default = default_1;

View file

@ -0,0 +1 @@
export default function (): void;

View file

@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Handlebars = require("handlebars");
function default_1() {
Handlebars.registerHelper('ifShowTypeHierarchy', function (options) {
var _a;
const typeHierarchy = (_a = this.model) === null || _a === void 0 ? void 0 : _a.typeHierarchy;
return typeHierarchy && typeHierarchy.next
? options.fn(this)
: options.inverse(this);
});
}
exports.default = default_1;

View file

@ -0,0 +1 @@
export default function (): void;

View file

@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Handlebars = require("handlebars");
function default_1() {
Handlebars.registerHelper('indexSignatureTitle', function () {
const md = ['▪'];
const parameters = this.parameters
? this.parameters.map((parameter) => {
return `${parameter.name}: ${Handlebars.helpers.type.call(parameter.type)}`;
})
: [];
md.push(`\[${parameters.join('')}\]: ${Handlebars.helpers.type.call(this.type)}`);
return md.join(' ');
});
}
exports.default = default_1;

View file

@ -0,0 +1 @@
export default function (): void;

View file

@ -0,0 +1,100 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Handlebars = require("handlebars");
const typedoc_1 = require("typedoc");
const utils_1 = require("../../utils");
const type_1 = require("./type");
function default_1() {
Handlebars.registerHelper('parameterTable', function () {
const flattenParams = (current) => {
var _a, _b, _c;
return (_c = (_b = (_a = current.type) === null || _a === void 0 ? void 0 : _a.declaration) === null || _b === void 0 ? void 0 : _b.children) === null || _c === void 0 ? void 0 : _c.reduce((acc, child) => {
const childObj = {
...child,
name: `${current.name}.${child.name}`,
};
return parseParams(childObj, acc);
}, []);
};
const parseParams = (current, acc) => {
var _a, _b, _c, _d;
const shouldFlatten = ((_b = (_a = current.type) === null || _a === void 0 ? void 0 : _a.declaration) === null || _b === void 0 ? void 0 : _b.kind) === typedoc_1.ReflectionKind.TypeLiteral &&
((_d = (_c = current.type) === null || _c === void 0 ? void 0 : _c.declaration) === null || _d === void 0 ? void 0 : _d.children);
return shouldFlatten
? [...acc, current, ...flattenParams(current)]
: [...acc, current];
};
return table(this.reduce((acc, current) => parseParams(current, acc), []));
});
}
exports.default = default_1;
function table(parameters) {
const showDefaults = hasDefaultValues(parameters);
const comments = parameters.map((param) => { var _a; return !!((_a = param.comment) === null || _a === void 0 ? void 0 : _a.hasVisibleComponent()); });
const hasComments = !comments.every((value) => !value);
const headers = ['Name', 'Type'];
if (showDefaults) {
headers.push('Default value');
}
if (hasComments) {
headers.push('Description');
}
const rows = parameters.map((parameter) => {
const row = [];
const nbsp = ' ';
const rest = parameter.flags.isRest ? '...' : '';
const optional = parameter.flags.isOptional ? '?' : '';
const isDestructuredParam = parameter.name == '__namedParameters';
const isDestructuredParamProp = parameter.name.startsWith('__namedParameters.');
if (isDestructuredParam) {
row.push(`\`${rest}«destructured»\``);
}
else if (isDestructuredParamProp) {
row.push(`${nbsp}\`${rest}${parameter.name.slice(18)}${optional}\``);
}
else {
row.push(`\`${rest}${parameter.name}${optional}\``);
}
row.push(parameter.type
? Handlebars.helpers.type.call(parameter.type, 'object')
: (0, type_1.getReflectionType)(parameter, 'object'));
if (showDefaults) {
row.push(getDefaultValue(parameter));
}
if (hasComments) {
const comments = getComments(parameter);
if (comments) {
row.push((0, utils_1.stripLineBreaks)(Handlebars.helpers.comments(comments)).replace(/\|/g, '\\|'));
}
else {
row.push('-');
}
}
return `| ${row.join(' | ')} |\n`;
});
const output = `\n| ${headers.join(' | ')} |\n| ${headers
.map(() => ':------')
.join(' | ')} |\n${rows.join('')}`;
return output;
}
function getDefaultValue(parameter) {
return parameter.defaultValue && parameter.defaultValue !== '...'
? `\`${parameter.defaultValue}\``
: '`undefined`';
}
function hasDefaultValues(parameters) {
const defaultValues = parameters.map((param) => param.defaultValue !== '{}' &&
param.defaultValue !== '...' &&
!!param.defaultValue);
return !defaultValues.every((value) => !value);
}
function getComments(parameter) {
var _a, _b, _c, _d, _e, _f, _g, _h;
if (parameter.type instanceof typedoc_1.ReflectionType) {
if (((_b = (_a = parameter.type) === null || _a === void 0 ? void 0 : _a.declaration) === null || _b === void 0 ? void 0 : _b.signatures) &&
((_e = (_d = (_c = parameter.type) === null || _c === void 0 ? void 0 : _c.declaration) === null || _d === void 0 ? void 0 : _d.signatures[0]) === null || _e === void 0 ? void 0 : _e.comment)) {
return (_h = (_g = (_f = parameter.type) === null || _f === void 0 ? void 0 : _f.declaration) === null || _g === void 0 ? void 0 : _g.signatures[0]) === null || _h === void 0 ? void 0 : _h.comment;
}
}
return parameter.comment;
}

View file

@ -0,0 +1 @@
export default function (): void;

View file

@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Handlebars = require("handlebars");
function default_1() {
Handlebars.registerHelper('referenceMember', function () {
const referenced = this.tryGetTargetReflectionDeep();
if (!referenced) {
return `Re-exports ${this.name}`;
}
if (this.name === referenced.name) {
return `Re-exports [${referenced.name}](${Handlebars.helpers.relativeURL(referenced.url)})`;
}
return `Renames and re-exports [${referenced.name}](${Handlebars.helpers.relativeURL(referenced.url)})`;
});
}
exports.default = default_1;

View file

@ -0,0 +1 @@
export default function (): void;

View file

@ -0,0 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Handlebars = require("handlebars");
const typedoc_1 = require("typedoc");
function default_1() {
Handlebars.registerHelper('reflectionPath', function () {
var _a, _b;
if (this.model) {
if (this.model.kind && this.model.kind !== typedoc_1.ReflectionKind.Module) {
const title = [];
if (this.model.parent && this.model.parent.parent) {
if (this.model.parent.parent.parent) {
title.push(`[${this.model.parent.parent.name}](${Handlebars.helpers.relativeURL((_b = (_a = this.model) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.parent.url)})`);
}
title.push(`[${this.model.parent.name}](${Handlebars.helpers.relativeURL(this.model.parent.url)})`);
}
title.push(this.model.name);
return title.length > 1 ? `${title.join('.')}` : null;
}
}
return null;
});
}
exports.default = default_1;

View file

@ -0,0 +1,2 @@
import { MarkdownTheme } from '../../theme';
export default function (theme: MarkdownTheme): void;

View file

@ -0,0 +1,28 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Handlebars = require("handlebars");
const utils_1 = require("../../utils");
function default_1(theme) {
Handlebars.registerHelper('reflectionTitle', function (shouldEscape = true) {
const title = [''];
if (this.model &&
this.model.kindString &&
this.url !== this.project.url) {
title.push(`${this.model.kindString}: `);
}
if (this.url === this.project.url) {
title.push(theme.indexTitle || this.project.name);
}
else {
title.push(shouldEscape ? (0, utils_1.escapeChars)(this.model.name) : this.model.name);
if (this.model.typeParameters) {
const typeParameters = this.model.typeParameters
.map((typeParameter) => typeParameter.name)
.join(', ');
title.push(`<${typeParameters}${shouldEscape ? '\\>' : '>'}`);
}
}
return title.join('');
});
}
exports.default = default_1;

View file

@ -0,0 +1,2 @@
import { MarkdownTheme } from '../../theme';
export default function (theme: MarkdownTheme): void;

View file

@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Handlebars = require("handlebars");
function default_1(theme) {
Handlebars.registerHelper('relativeURL', function (url) {
return url
? theme.publicPath
? theme.publicPath + url
: theme.getRelativeUrl(url)
: url;
});
}
exports.default = default_1;

View file

@ -0,0 +1 @@
export default function (): void;

View file

@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Handlebars = require("handlebars");
function default_1() {
Handlebars.registerHelper('returns', function (comment) {
var _a;
const md = [];
if ((_a = comment.blockTags) === null || _a === void 0 ? void 0 : _a.length) {
const tags = comment.blockTags
.filter((tag) => tag.tag === '@returns')
.map((tag) => Handlebars.helpers.comment(tag.content));
md.push(tags.join('\n\n'));
}
return md.join('');
});
}
exports.default = default_1;

View file

@ -0,0 +1,2 @@
import { MarkdownTheme } from '../../theme';
export default function (theme: MarkdownTheme): void;

View file

@ -0,0 +1,43 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Handlebars = require("handlebars");
const typedoc_1 = require("typedoc");
const utils_1 = require("../../utils");
function default_1(theme) {
Handlebars.registerHelper('signatureTitle', function (accessor, standalone = true) {
var _a, _b;
const md = [];
if (standalone && !theme.hideMembersSymbol) {
md.push(`${(0, utils_1.memberSymbol)(this)} `);
}
if (this.parent && ((_a = this.parent.flags) === null || _a === void 0 ? void 0 : _a.length) > 0) {
md.push(this.parent.flags.map((flag) => `\`${flag}\``).join(' ') + ' ');
}
if (accessor) {
md.push(`\`${accessor}\` **${this.name}**`);
}
else if (this.name !== '__call' && this.name !== '__type') {
md.push(`**${this.name}**`);
}
if (this.typeParameters) {
md.push(`<${this.typeParameters
.map((typeParameter) => `\`${typeParameter.name}\``)
.join(', ')}\\>`);
}
md.push(`(${getParameters(this.parameters)})`);
if (this.type && !((_b = this.parent) === null || _b === void 0 ? void 0 : _b.kindOf(typedoc_1.ReflectionKind.Constructor))) {
md.push(`: ${Handlebars.helpers.type.call(this.type, 'object')}`);
}
return md.join('') + (standalone ? '\n' : '');
});
}
exports.default = default_1;
const getParameters = (parameters = [], backticks = true) => {
return parameters
.map((param) => {
const isDestructuredParam = param.name == '__namedParameters';
const paramItem = `${param.flags.isRest ? '...' : ''}${isDestructuredParam ? '«destructured»' : param.name}${param.flags.isOptional || param.defaultValue ? '?' : ''}`;
return backticks ? `\`${paramItem}\`` : paramItem;
})
.join(', ');
};

View file

@ -0,0 +1,2 @@
import { MarkdownTheme } from '../../theme';
export default function (theme: MarkdownTheme): void;

View file

@ -0,0 +1,41 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Handlebars = require("handlebars");
const utils_1 = require("../../utils");
function default_1(theme) {
Handlebars.registerHelper('toc', function () {
var _a, _b;
const md = [];
const { hideInPageTOC } = theme;
const isVisible = (_a = this.groups) === null || _a === void 0 ? void 0 : _a.some((group) => group.allChildrenHaveOwnDocument());
function pushGroup(group, md) {
const children = group.children.map((child) => `- [${(0, utils_1.escapeChars)(child.name)}](${Handlebars.helpers.relativeURL(child.url)})`);
md.push(children.join('\n'));
}
if ((!hideInPageTOC && this.groups) || (isVisible && this.groups)) {
if (!hideInPageTOC) {
md.push(`## Table of contents\n\n`);
}
const headingLevel = hideInPageTOC ? `##` : `###`;
(_b = this.groups) === null || _b === void 0 ? void 0 : _b.forEach((group) => {
const groupTitle = group.title;
if (group.categories) {
group.categories.forEach((category) => {
md.push(`${headingLevel} ${category.title} ${groupTitle}\n\n`);
pushGroup(category, md);
md.push('\n');
});
}
else {
if (!hideInPageTOC || group.allChildrenHaveOwnDocument()) {
md.push(`${headingLevel} ${groupTitle}\n\n`);
pushGroup(group, md);
md.push('\n');
}
}
});
}
return md.length > 0 ? md.join('\n') : null;
});
}
exports.default = default_1;

View file

@ -0,0 +1 @@
export default function (): void;

View file

@ -0,0 +1,43 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Handlebars = require("handlebars");
const typedoc_1 = require("typedoc");
const utils_1 = require("../../utils");
function default_1() {
Handlebars.registerHelper('typeAndParent', function () {
var _a, _b, _c;
const getUrl = (name, url) => `[${name}](${Handlebars.helpers.relativeURL(url)})`;
if (this) {
if ('elementType' in this) {
return Handlebars.helpers.typeAndParent.call(this.elementType) + '[]';
}
else {
if (this.reflection) {
const md = [];
if (this.reflection instanceof typedoc_1.SignatureReflection) {
if ((_b = (_a = this.reflection.parent) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.url) {
md.push(getUrl(this.reflection.parent.parent.name, this.reflection.parent.parent.url));
if (this.reflection.parent.url) {
md.push(getUrl(this.reflection.parent.name, this.reflection.parent.url));
}
}
}
else {
if ((_c = this.reflection.parent) === null || _c === void 0 ? void 0 : _c.url) {
md.push(getUrl(this.reflection.parent.name, this.reflection.parent.url));
if (this.reflection.url) {
md.push(getUrl(this.reflection.name, this.reflection.url));
}
}
}
return md.join('.');
}
else {
return (0, utils_1.escapeChars)(this.toString());
}
}
}
return 'void';
});
}
exports.default = default_1;

View file

@ -0,0 +1,2 @@
import { MarkdownTheme } from '../../theme';
export default function (theme: MarkdownTheme): void;

View file

@ -0,0 +1,151 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Handlebars = require("handlebars");
const typedoc_1 = require("typedoc");
const utils_1 = require("../../utils");
function default_1(theme) {
Handlebars.registerHelper('typeDeclarationMembers', function () {
const comments = this.map((param) => { var _a; return !!((_a = param.comment) === null || _a === void 0 ? void 0 : _a.hasVisibleComponent()); });
const hasComments = !comments.every((value) => !value);
const flattenParams = (current) => {
var _a, _b, _c;
return (_c = (_b = (_a = current.type) === null || _a === void 0 ? void 0 : _a.declaration) === null || _b === void 0 ? void 0 : _b.children) === null || _c === void 0 ? void 0 : _c.reduce((acc, child) => {
const childObj = {
...child,
name: `${current.name}.${child.name}`,
};
return parseParams(childObj, acc);
}, []);
};
const parseParams = (current, acc) => {
var _a, _b;
const shouldFlatten = (_b = (_a = current.type) === null || _a === void 0 ? void 0 : _a.declaration) === null || _b === void 0 ? void 0 : _b.children;
return shouldFlatten
? [...acc, current, ...flattenParams(current)]
: [...acc, current];
};
const properties = this.reduce((acc, current) => parseParams(current, acc), []);
let result = '';
switch (theme.objectLiteralTypeDeclarationStyle) {
case 'list': {
result = getListMarkdownContent(properties);
break;
}
case 'table': {
result = getTableMarkdownContent(properties, hasComments);
break;
}
}
return result;
});
}
exports.default = default_1;
function getListMarkdownContent(properties) {
const propertyTable = getTableMarkdownContentWithoutComment(properties);
const propertyDescriptions = properties.map((property) => {
const name = property.name.match(/[\\`\\|]/g) !== null
? (0, utils_1.escapeChars)(getName(property))
: `${getName(property)}`;
const propertyType = getPropertyType(property);
const propertyTypeStr = Handlebars.helpers.type.call(propertyType);
const comments = getComments(property);
const commentsStr = comments
? Handlebars.helpers.comments(comments)
: '\\-';
const md = `**${name}**: ${propertyTypeStr}
${commentsStr}
-----
`;
return md;
});
const propertyComments = propertyDescriptions.join('\n\n');
const result = `
${propertyTable}
${propertyComments}
`;
return result;
}
function getTableMarkdownContent(properties, hasComments) {
const headers = ['Name', 'Type'];
if (hasComments) {
headers.push('Description');
}
const rows = properties.map((property) => {
const propertyType = getPropertyType(property);
const row = [];
const nameCol = [];
const name = property.name.match(/[\\`\\|]/g) !== null
? (0, utils_1.escapeChars)(getName(property))
: `\`${getName(property)}\``;
nameCol.push(name);
row.push(nameCol.join(' '));
row.push(Handlebars.helpers.type.call(propertyType).replace(/(?<!\\)\|/g, '\\|'));
if (hasComments) {
const comments = getComments(property);
if (comments) {
row.push((0, utils_1.stripLineBreaks)(Handlebars.helpers.comments(comments)).replace(/\|/g, '\\|'));
}
else {
row.push('-');
}
}
return `| ${row.join(' | ')} |\n`;
});
const output = `\n| ${headers.join(' | ')} |\n| ${headers
.map(() => ':------')
.join(' | ')} |\n${rows.join('')}`;
return output;
}
function getTableMarkdownContentWithoutComment(properties) {
const result = getTableMarkdownContent(properties, false);
return result;
}
function getPropertyType(property) {
if (property.getSignature) {
return property.getSignature.type;
}
if (property.setSignature) {
return property.setSignature.type;
}
return property.type ? property.type : property;
}
function getName(property) {
var _a;
const md = [];
if (property.flags.isRest) {
md.push('...');
}
if (property.getSignature) {
md.push(`get ${property.getSignature.name}()`);
}
else if (property.setSignature) {
md.push(`set ${property.setSignature.name}(${(_a = property.setSignature.parameters) === null || _a === void 0 ? void 0 : _a.map((parameter) => {
return `${parameter.name}:${Handlebars.helpers.type.call(parameter.type, 'all', false)}`;
})})`);
}
else {
md.push(property.name);
}
if (property.flags.isOptional) {
md.push('?');
}
return md.join('');
}
function getComments(property) {
var _a, _b, _c, _d;
if (property.type instanceof typedoc_1.ReflectionType) {
if ((_b = (_a = property.type) === null || _a === void 0 ? void 0 : _a.declaration) === null || _b === void 0 ? void 0 : _b.signatures) {
return (_c = property.type) === null || _c === void 0 ? void 0 : _c.declaration.signatures[0].comment;
}
}
if ((_d = property.signatures) === null || _d === void 0 ? void 0 : _d.length) {
return property.signatures[0].comment;
}
return property.comment;
}

View file

@ -0,0 +1 @@
export default function (): void;

View file

@ -0,0 +1,60 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Handlebars = require("handlebars");
const utils_1 = require("../../utils");
function default_1() {
Handlebars.registerHelper('typeParameterTable', function () {
return table(this);
});
}
exports.default = default_1;
function table(parameters) {
const showTypeCol = hasTypes(parameters);
const comments = parameters.map((param) => { var _a; return !!((_a = param.comment) === null || _a === void 0 ? void 0 : _a.hasVisibleComponent()); });
const hasComments = !comments.every((value) => !value);
const headers = ['Name'];
if (showTypeCol) {
headers.push('Type');
}
if (hasComments) {
headers.push('Description');
}
const rows = parameters.map((parameter) => {
var _a, _b;
const row = [];
row.push(`\`${parameter.name}\``);
if (showTypeCol) {
const typeCol = [];
if (!parameter.type && !parameter.default) {
typeCol.push(`\`${parameter.name}\``);
}
if (parameter.type) {
typeCol.push(`extends ${Handlebars.helpers.type.call(parameter.type, 'object')}`);
}
if (parameter.default) {
if (parameter.type) {
typeCol.push(' = ');
}
typeCol.push(Handlebars.helpers.type.call(parameter.default));
}
row.push(typeCol.join(''));
}
if (hasComments) {
if ((_a = parameter.comment) === null || _a === void 0 ? void 0 : _a.summary) {
row.push((0, utils_1.stripLineBreaks)(Handlebars.helpers.comment((_b = parameter.comment) === null || _b === void 0 ? void 0 : _b.summary)).replace(/\|/g, '\\|'));
}
else {
row.push('-');
}
}
return `| ${row.join(' | ')} |\n`;
});
const output = `\n| ${headers.join(' | ')} |\n| ${headers
.map(() => ':------')
.join(' | ')} |\n${rows.join('')}`;
return output;
}
function hasTypes(parameters) {
const types = parameters.map((param) => !!param.type || !!param.default);
return !types.every((value) => !value);
}

View file

@ -0,0 +1,6 @@
import { DeclarationReflection, ReflectionType, SignatureReflection } from 'typedoc';
type Collapse = 'object' | 'function' | 'all' | 'none';
export default function (): void;
export declare function getReflectionType(model: DeclarationReflection | ReflectionType, collapse: Collapse): string;
export declare function getFunctionType(modelSignatures: SignatureReflection[]): string;
export {};

View file

@ -0,0 +1,206 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFunctionType = exports.getReflectionType = void 0;
const Handlebars = require("handlebars");
const typedoc_1 = require("typedoc");
const utils_1 = require("../../utils");
function default_1() {
Handlebars.registerHelper('type', function (collapse = 'none', emphasis = true) {
if (this instanceof typedoc_1.ReferenceType) {
return getReferenceType(this, emphasis);
}
if (this instanceof typedoc_1.ArrayType && this.elementType) {
return getArrayType(this, emphasis);
}
if (this instanceof typedoc_1.UnionType && this.types) {
return getUnionType(this, emphasis);
}
if (this instanceof typedoc_1.IntersectionType && this.types) {
return getIntersectionType(this);
}
if (this instanceof typedoc_1.TupleType && this.elements) {
return getTupleType(this);
}
if (this instanceof typedoc_1.IntrinsicType && this.name) {
return getIntrinsicType(this, emphasis);
}
if (this instanceof typedoc_1.ReflectionType) {
return getReflectionType(this, collapse);
}
if (this instanceof typedoc_1.DeclarationReflection) {
return getReflectionType(this, collapse);
}
if (this instanceof typedoc_1.TypeOperatorType) {
return getTypeOperatorType(this);
}
if (this instanceof typedoc_1.QueryType) {
return getQueryType(this);
}
if (this instanceof typedoc_1.ConditionalType) {
return getConditionalType(this);
}
if (this instanceof typedoc_1.IndexedAccessType) {
return getIndexAccessType(this);
}
if (this instanceof typedoc_1.UnknownType) {
return getUnknownType(this);
}
if (this instanceof typedoc_1.InferredType) {
return getInferredType(this);
}
if (this instanceof typedoc_1.LiteralType) {
return getLiteralType(this);
}
return this ? (0, utils_1.escapeChars)(this.toString()) : '';
});
}
exports.default = default_1;
function getLiteralType(model) {
if (typeof model.value === 'bigint') {
return `\`${model.value}n\``;
}
return `\`\`${JSON.stringify(model.value)}\`\``;
}
function getReflectionType(model, collapse) {
const root = model instanceof typedoc_1.ReflectionType ? model.declaration : model;
if (root.signatures) {
return collapse === 'function' || collapse === 'all'
? `\`fn\``
: getFunctionType(root.signatures);
}
return collapse === 'object' || collapse === 'all'
? `\`Object\``
: getDeclarationType(root);
}
exports.getReflectionType = getReflectionType;
function getDeclarationType(model) {
if (model.indexSignature || model.children) {
let indexSignature = '';
const declarationIndexSignature = model.indexSignature;
if (declarationIndexSignature) {
const key = declarationIndexSignature.parameters
? declarationIndexSignature.parameters.map((param) => `\`[${param.name}: ${param.type}]\``)
: '';
const obj = Handlebars.helpers.type.call(declarationIndexSignature.type);
indexSignature = `${key}: ${obj}; `;
}
const types = model.children &&
model.children.map((obj) => {
return `\`${obj.name}${obj.flags.isOptional ? '?' : ''}\`: ${Handlebars.helpers.type.call(obj.signatures || obj.children ? obj : obj.type)} ${obj.defaultValue && obj.defaultValue !== '...'
? `= ${(0, utils_1.escapeChars)(obj.defaultValue)}`
: ''}`;
});
return `{ ${indexSignature ? indexSignature : ''}${types ? types.join('; ') : ''} }${model.defaultValue && model.defaultValue !== '...'
? `= ${(0, utils_1.escapeChars)(model.defaultValue)}`
: ''}`;
}
return '{}';
}
function getFunctionType(modelSignatures) {
const functions = modelSignatures.map((fn) => {
const typeParams = fn.typeParameters
? `<${fn.typeParameters
.map((typeParameter) => typeParameter.name)
.join(', ')}\\>`
: [];
const params = fn.parameters
? fn.parameters.map((param) => {
return `${param.flags.isRest ? '...' : ''}\`${param.name}${param.flags.isOptional ? '?' : ''}\`: ${Handlebars.helpers.type.call(param.type ? param.type : param)}`;
})
: [];
const returns = Handlebars.helpers.type.call(fn.type);
return typeParams + `(${params.join(', ')}) => ${returns}`;
});
return functions.join('');
}
exports.getFunctionType = getFunctionType;
function getReferenceType(model, emphasis) {
var _a;
if (model.reflection || (model.name && model.typeArguments)) {
const reflection = [];
if ((_a = model.reflection) === null || _a === void 0 ? void 0 : _a.url) {
reflection.push(`[${`\`${model.reflection.name}\``}](${Handlebars.helpers.relativeURL(model.reflection.url)})`);
}
else {
reflection.push(model.externalUrl
? `[${`\`${model.name}\``}]( ${model.externalUrl} )`
: `\`${model.name}\``);
}
if (model.typeArguments && model.typeArguments.length > 0) {
reflection.push(`<${model.typeArguments
.map((typeArgument) => Handlebars.helpers.type.call(typeArgument))
.join(', ')}\\>`);
}
return reflection.join('');
}
return emphasis
? model.externalUrl
? `[${`\`${model.name}\``}]( ${model.externalUrl} )`
: `\`${model.name}\``
: (0, utils_1.escapeChars)(model.name);
}
function getArrayType(model, emphasis) {
const arrayType = Handlebars.helpers.type.call(model.elementType, 'none', emphasis);
return model.elementType.type === 'union'
? `(${arrayType})[]`
: `${arrayType}[]`;
}
function getUnionType(model, emphasis) {
return model.types
.map((unionType) => Handlebars.helpers.type.call(unionType, 'none', emphasis))
.join(` \\| `);
}
function getIntersectionType(model) {
return model.types
.map((intersectionType) => Handlebars.helpers.type.call(intersectionType))
.join(' & ');
}
function getTupleType(model) {
return `[${model.elements
.map((element) => Handlebars.helpers.type.call(element))
.join(', ')}]`;
}
function getIntrinsicType(model, emphasis) {
return emphasis ? `\`${model.name}\`` : (0, utils_1.escapeChars)(model.name);
}
function getTypeOperatorType(model) {
return `${model.operator} ${Handlebars.helpers.type.call(model.target)}`;
}
function getQueryType(model) {
return `typeof ${Handlebars.helpers.type.call(model.queryType)}`;
}
function getInferredType(model) {
return `infer ${(0, utils_1.escapeChars)(model.name)}`;
}
function getUnknownType(model) {
return (0, utils_1.escapeChars)(model.name);
}
function getConditionalType(model) {
const md = [];
if (model.checkType) {
md.push(Handlebars.helpers.type.call(model.checkType));
}
md.push('extends');
if (model.extendsType) {
md.push(Handlebars.helpers.type.call(model.extendsType));
}
md.push('?');
if (model.trueType) {
md.push(Handlebars.helpers.type.call(model.trueType));
}
md.push(':');
if (model.falseType) {
md.push(Handlebars.helpers.type.call(model.falseType));
}
return md.join(' ');
}
function getIndexAccessType(model) {
const md = [];
if (model.objectType) {
md.push(Handlebars.helpers.type.call(model.objectType));
}
if (model.indexType) {
md.push(`[${Handlebars.helpers.type.call(model.indexType)}]`);
}
return md.join('');
}

View file

@ -0,0 +1,9 @@
{{#with comment}}
{{#if hasVisibleComponent}}
{{{comments this}}}
{{/if}}
{{/with}}

View file

@ -0,0 +1,5 @@
{{#ifShowBreadcrumbs}}
{{{breadcrumbs}}}
{{/ifShowBreadcrumbs}}

View file

@ -0,0 +1,3 @@
{{ toc }}
{{> members}}

View file

@ -0,0 +1,71 @@
{{{declarationTitle}}}
{{> comment}}
{{#if typeParameters}}
#### Type parameters
{{#with typeParameters}}
{{{typeParameterTable}}}
{{/with}}
{{/if}}
{{#if type.declaration}}
{{#if type.declaration.indexSignature}}
{{#with type.declaration.indexSignature}}
#### Index signature
{{{indexSignatureTitle}}}
{{> comment}}
{{/with}}
{{/if}}
{{#if type.declaration.signatures}}
{{#if type.declaration.children}}
#### Call signature
{{else}}
#### Type declaration
{{/if}}
{{#each type.declaration.signatures}}
{{> member.signature showSources=false }}
{{/each}}
{{/if}}
{{#if type.declaration.children}}
{{#with type.declaration}}
#### Type declaration
{{/with}}
{{#with type.declaration.children}}
{{{typeDeclarationMembers}}}
{{/with}}
{{/if}}
{{/if}}
{{> member.sources}}

View file

@ -0,0 +1,19 @@
{{#if getSignature}}
{{#with getSignature}}
{{> member.signature accessor="get" showSources=true }}
{{/with}}
{{/if}}
{{#if setSignature}}
{{#with setSignature}}
{{> member.signature accessor="set" showSources=true }}
{{/with}}
{{/if}}

View file

@ -0,0 +1,25 @@
{{#unless hasOwnDocument}}
{{#if name}}
### {{#ifNamedAnchors}}<a id="{{anchor}}" name="{{this.anchor}}"></a> {{/ifNamedAnchors}}{{ escape name }}
{{/if}}
{{/unless}}
{{#each signatures}}
{{> member.signature showSources=true }}
{{/each}}
{{> member.getterSetter}}
{{> member.declaration}}
{{#unless @last}}
{{#unless hasOwnDocument}}
___
{{/unless}}
{{/unless}}

View file

@ -0,0 +1,103 @@
{{{signatureTitle accessor}}}
{{> comment}}
{{#if typeParameters}}
{{#if showSources}}
#### Type parameters
{{else}}
##### Type parameters
{{/if}}
{{#with typeParameters}}
{{{typeParameterTable}}}
{{/with}}
{{/if}}
{{#if parameters}}
{{#if showSources}}
#### Parameters
{{else}}
##### Parameters
{{/if}}
{{#with parameters}}
{{{parameterTable}}}
{{/with}}
{{/if}}
{{#ifShowReturns}}
{{#if type}}
{{#if showSources}}
#### Returns
{{else}}
##### Returns
{{/if}}
{{#with type}}
{{{type 'all'}}}
{{/with}}
{{#with comment}}
{{{returns this}}}
{{/with}}
{{#with type}}
{{#if declaration.signatures}}
{{#each declaration.signatures}}
{{> member.signature showSources=false }}
{{/each}}
{{/if}}
{{#if declaration.children}}
{{#with declaration.children}}
{{{typeDeclarationMembers}}}
{{/with}}
{{/if}}
{{/with}}
{{/if}}
{{/ifShowReturns}}
{{#if showSources}}
{{> member.sources}}
{{/if}}

View file

@ -0,0 +1,55 @@
{{#if implementationOf}}
#### Implementation of
{{#with implementationOf}}
{{typeAndParent}}
{{/with}}
{{/if}}
{{#if inheritedFrom}}
#### Inherited from
{{#with inheritedFrom}}
{{{typeAndParent}}}
{{/with}}
{{/if}}
{{#if overwrites}}
#### Overrides
{{#with overwrites}}
{{typeAndParent}}
{{/with}}
{{/if}}
{{#if sources}}
#### Defined in
{{#each sources}}
{{#if url}}
[{{fileName}}:{{line}}]({{url}})
{{else}}
{{fileName}}:{{line}}
{{/if}}
{{/each}}
{{/if}}

View file

@ -0,0 +1,29 @@
{{#if categories}}
{{#each categories}}
{{#unless @first}}
___
{{/unless}}
## {{title}} {{../title}}
{{#each children}}
{{> member}}
{{/each}}
{{/each}}
{{else}}
## {{title}}
{{#each children}}
{{> member}}
{{/each}}
{{/if}}

View file

@ -0,0 +1,35 @@
{{#if categories}}
{{#each categories}}
{{#unless allChildrenHaveOwnDocument}}
## {{title}}
{{#each children}}
{{#unless hasOwnDocument}}
{{> member}}
{{/unless}}
{{/each}}
{{/unless}}
{{/each}}
{{else}}
{{#each groups}}
{{#unless allChildrenHaveOwnDocument}}
{{> members.group}}
{{/unless}}
{{/each}}
{{/if}}

View file

@ -0,0 +1,7 @@
{{#ifShowPageTitle}}
# {{{reflectionTitle true}}}
{{/ifShowPageTitle}}
{{{reflectionPath}}}

View file

@ -0,0 +1,7 @@
{{> header}}
{{#with model.readme}}
{{{comment this}}}
{{/with}}

View file

@ -0,0 +1,99 @@
{{> header}}
{{> title}}
{{#with model}}
{{#if hasComment}}
{{> comment}}
{{/if}}
{{/with}}
{{#if model.typeParameters}}
## Type parameters
{{#with model.typeParameters}}
{{{typeParameterTable}}}
{{/with}}
{{/if}}
{{#ifShowTypeHierarchy}}
## Hierarchy
{{#with model.typeHierarchy}}
{{{hierarchy 0}}}
{{/with}}
{{/ifShowTypeHierarchy}}
{{#if model.implementedTypes}}
## Implements
{{#each model.implementedTypes}}
- {{{type}}}
{{/each}}
{{/if}}
{{#if model.implementedBy}}
## Implemented by
{{#each model.implementedBy}}
- {{{type}}}
{{/each}}
{{/if}}
{{#if model.signatures}}
## Callable
{{#with model}}
{{#each signatures}}
### {{name}}
{{> member.signature showSources=true }}
{{/each}}
{{/with}}
{{/if}}
{{#if model.indexSignature}}
## Indexable
{{#with model}}
{{#with indexSignature}}
{{{indexSignatureTitle}}}
{{> comment}}
{{/with}}
{{/with}}
{{/if}}
{{#with model}}
{{> main}}
{{/with}}

View file

@ -0,0 +1,9 @@
{{> header}}
{{> title}}
{{#with model}}
{{> member}}
{{/with}}

View file

@ -1,15 +1,20 @@
import * as fs from 'fs';
import * as Handlebars from 'handlebars';
import * as path from "path";
import {
ContainerReflection,
PageEvent,
Renderer,
DeclarationReflection,
ReflectionKind,
RendererEvent
} from 'typedoc';
import { MarkdownTheme } from 'typedoc-plugin-markdown';
import registerTypeHelper from './type';
const TEMPLATE_PATH = path.join(__dirname, '..', 'profectus-theme', 'resources', 'templates');
export class ProfectusTheme extends MarkdownTheme {
constructor(renderer: Renderer) {
super(renderer);
@ -21,14 +26,25 @@ export class ProfectusTheme extends MarkdownTheme {
// registerTypeHelper();
}
getReflectionMemberTemplate() {
const templ = super.getReflectionMemberTemplate();
return (pageEvent) => {
return templ(pageEvent);
}
}
getReflectionTemplate() {
const templ = super.getReflectionTemplate();
return (pageEvent) => {
if (pageEvent.url === "index.md") {
return "# Profectus API";
}
return templ(pageEvent);
return Handlebars.compile(
fs.readFileSync(path.join(TEMPLATE_PATH, 'reflection.hbs')).toString(),
)(pageEvent, {
allowProtoMethodsByDefault: true,
allowProtoPropertiesByDefault: true,
data: { theme: this }
})
}
}
@ -41,6 +57,21 @@ export class ProfectusTheme extends MarkdownTheme {
}
toUrl(mapping: any, reflection: DeclarationReflection) {
return `${mapping.directory}/${reflection.getFullName()}.md`;
let name = reflection.getFullName();
if (name.match(/features\/.*\/.*/) != null && !name.includes("/tabs/")) {
name = name.replace(/features\/.*\/(.*)/, "features/$1");
}
return `${mapping.directory}/${name}.md`;
}
get mappings() {
return [
{
kind: [ReflectionKind.Module],
isLeaf: false,
directory: 'modules',
template: this.getReflectionTemplate(),
}
];
}
}