2024-08-02 16:42:23 +00:00
|
|
|
/*!
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright Google LLC All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
|
* found in the LICENSE file at https://angular.dev/license
|
|
|
|
|
*/
|
|
|
|
|
|
2025-05-05 22:10:49 +00:00
|
|
|
import {Fragment, h} from 'preact';
|
2024-08-02 16:42:23 +00:00
|
|
|
import {
|
2024-11-12 07:35:24 +00:00
|
|
|
FunctionEntryRenderable,
|
|
|
|
|
FunctionSignatureMetadataRenderable,
|
2025-05-06 20:59:30 +00:00
|
|
|
} from '../entities/renderables.mjs';
|
2024-11-12 07:35:24 +00:00
|
|
|
import {
|
|
|
|
|
API_REFERENCE_CONTAINER,
|
2024-08-02 16:42:23 +00:00
|
|
|
REFERENCE_MEMBERS,
|
|
|
|
|
REFERENCE_MEMBER_CARD,
|
|
|
|
|
REFERENCE_MEMBER_CARD_BODY,
|
2024-08-04 21:12:14 +00:00
|
|
|
REFERENCE_MEMBER_CARD_HEADER,
|
2025-05-06 20:59:30 +00:00
|
|
|
} from '../styling/css-classes.mjs';
|
|
|
|
|
import {printInitializerFunctionSignatureLine} from '../transforms/code-transforms.mjs';
|
|
|
|
|
import {getFunctionMetadataRenderable} from '../transforms/function-transforms.mjs';
|
2024-08-02 16:42:23 +00:00
|
|
|
import {ClassMethodInfo} from './class-method-info';
|
2025-05-05 22:10:49 +00:00
|
|
|
import {CodeSymbol} from './code-symbols';
|
2026-01-12 12:08:31 +00:00
|
|
|
import {DeprecationWarning} from './deprecation-warning';
|
2024-08-02 16:42:23 +00:00
|
|
|
import {HeaderApi} from './header-api';
|
2025-05-05 22:10:49 +00:00
|
|
|
import {HighlightTypeScript} from './highlight-ts';
|
2024-11-12 07:35:24 +00:00
|
|
|
import {SectionApi} from './section-api';
|
|
|
|
|
import {SectionDescription} from './section-description';
|
|
|
|
|
import {SectionUsageNotes} from './section-usage-notes';
|
2024-08-04 21:12:14 +00:00
|
|
|
|
|
|
|
|
export const signatureCard = (
|
|
|
|
|
name: string,
|
|
|
|
|
signature: FunctionSignatureMetadataRenderable,
|
2026-01-12 12:08:31 +00:00
|
|
|
opts: {id: string; printSignaturesAsHeader: boolean; hideUsageNotes?: boolean},
|
2024-08-04 21:12:14 +00:00
|
|
|
) => {
|
|
|
|
|
return (
|
2025-02-15 09:05:59 +00:00
|
|
|
<div id={opts.id} class={REFERENCE_MEMBER_CARD}>
|
2024-11-12 07:35:24 +00:00
|
|
|
<header class={REFERENCE_MEMBER_CARD_HEADER}>
|
2026-01-12 12:08:31 +00:00
|
|
|
{opts.printSignaturesAsHeader ? (
|
2025-04-28 16:02:29 +00:00
|
|
|
<HighlightTypeScript
|
|
|
|
|
code={printInitializerFunctionSignatureLine(
|
|
|
|
|
name,
|
|
|
|
|
signature,
|
|
|
|
|
// Always omit types in signature headers, to keep them short.
|
|
|
|
|
true,
|
|
|
|
|
)}
|
|
|
|
|
/>
|
2024-08-04 21:12:14 +00:00
|
|
|
) : (
|
2024-11-12 07:35:24 +00:00
|
|
|
<>
|
2024-08-04 21:12:14 +00:00
|
|
|
<h3>{name}</h3>
|
|
|
|
|
<div>
|
2024-08-20 23:52:41 +00:00
|
|
|
<CodeSymbol code={signature.returnType} />
|
2024-08-04 21:12:14 +00:00
|
|
|
</div>
|
2024-11-12 07:35:24 +00:00
|
|
|
</>
|
2024-08-04 21:12:14 +00:00
|
|
|
)}
|
|
|
|
|
</header>
|
|
|
|
|
<div class={REFERENCE_MEMBER_CARD_BODY}>
|
2026-01-12 12:08:31 +00:00
|
|
|
<ClassMethodInfo entry={signature} hideUsageNotes={opts.hideUsageNotes} />
|
2024-08-04 21:12:14 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
2024-08-02 16:42:23 +00:00
|
|
|
|
|
|
|
|
/** Component to render a function API reference document. */
|
|
|
|
|
export function FunctionReference(entry: FunctionEntryRenderable) {
|
2024-08-04 21:12:14 +00:00
|
|
|
// Use signatures as header if there are multiple signatures.
|
|
|
|
|
const printSignaturesAsHeader = entry.signatures.length > 1;
|
|
|
|
|
|
2024-08-02 16:42:23 +00:00
|
|
|
return (
|
2024-11-12 07:35:24 +00:00
|
|
|
<div className={API_REFERENCE_CONTAINER}>
|
2024-08-02 16:42:23 +00:00
|
|
|
<HeaderApi entry={entry} />
|
2025-07-02 09:52:09 +00:00
|
|
|
<DeprecationWarning entry={entry} />
|
2024-11-12 07:35:24 +00:00
|
|
|
<SectionApi entry={entry} />
|
|
|
|
|
<div className={REFERENCE_MEMBERS}>
|
2026-01-20 21:16:53 +00:00
|
|
|
{entry.signatures.length > 1 &&
|
|
|
|
|
entry.signatures.map((s, i) =>
|
|
|
|
|
signatureCard(s.name, getFunctionMetadataRenderable(s, entry.moduleName, entry.repo), {
|
|
|
|
|
id: `${s.name}_${i}`,
|
|
|
|
|
printSignaturesAsHeader,
|
|
|
|
|
hideUsageNotes: true,
|
|
|
|
|
}),
|
|
|
|
|
)}
|
2024-08-02 16:42:23 +00:00
|
|
|
</div>
|
2024-11-12 07:35:24 +00:00
|
|
|
|
|
|
|
|
<SectionDescription entry={entry} />
|
|
|
|
|
<SectionUsageNotes entry={entry} />
|
2024-08-02 16:42:23 +00:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|