Skip to content

Commit

Permalink
Include forwardedRefs in autogenerated component docs (#887)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasIO authored Jun 6, 2024
1 parent ce90dd1 commit 589ed63
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/react/etc/components-react.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ export interface UseMediaDeviceSelectProps {
}

// @alpha
export const useMultibandTrackVolume: (trackOrTrackReference?: LocalAudioTrack | RemoteAudioTrack | TrackReferenceOrPlaceholder, options?: MultiBandTrackVolumeOptions) => number[];
export function useMultibandTrackVolume(trackOrTrackReference?: LocalAudioTrack | RemoteAudioTrack | TrackReferenceOrPlaceholder, options?: MultiBandTrackVolumeOptions): number[];

// @alpha
export function usePagination(itemPerPage: number, trackReferences: TrackReferenceOrPlaceholder[]): {
Expand Down Expand Up @@ -1121,7 +1121,7 @@ export function useTrackTranscription(trackRef: TrackReferenceOrPlaceholder, opt
};

// @alpha
export const useTrackVolume: (trackOrTrackReference?: LocalAudioTrack | RemoteAudioTrack | TrackReference, options?: AudioAnalyserOptions) => number;
export function useTrackVolume(trackOrTrackReference?: LocalAudioTrack | RemoteAudioTrack | TrackReference, options?: AudioAnalyserOptions): number;

// @public
export function useVisualStableUpdate(
Expand Down
12 changes: 6 additions & 6 deletions packages/react/src/hooks/useTrackVolume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import {
* @alpha
* Hook for tracking the volume of an audio track using the Web Audio API.
*/
export const useTrackVolume = (
export function useTrackVolume(
trackOrTrackReference?: LocalAudioTrack | RemoteAudioTrack | TrackReference,
options: AudioAnalyserOptions = { fftSize: 32, smoothingTimeConstant: 0 },
) => {
) {
const track = isTrackReference(trackOrTrackReference)
? <LocalAudioTrack | RemoteAudioTrack | undefined>trackOrTrackReference.publication.track
: trackOrTrackReference;
Expand Down Expand Up @@ -48,7 +48,7 @@ export const useTrackVolume = (
}, [track, track?.mediaStream, JSON.stringify(options)]);

return volume;
};
}

const normalizeFrequencies = (frequencies: Float32Array) => {
const normalizeDb = (value: number) => {
Expand Down Expand Up @@ -104,10 +104,10 @@ const multibandDefaults = {
* Hook for tracking the volume of an audio track across multiple frequency bands using the Web Audio API.
* @alpha
*/
export const useMultibandTrackVolume = (
export function useMultibandTrackVolume(
trackOrTrackReference?: LocalAudioTrack | RemoteAudioTrack | TrackReferenceOrPlaceholder,
options: MultiBandTrackVolumeOptions = {},
) => {
) {
const track =
trackOrTrackReference instanceof Track
? trackOrTrackReference
Expand Down Expand Up @@ -153,4 +153,4 @@ export const useMultibandTrackVolume = (
}, [track, track?.mediaStream, JSON.stringify(options)]);

return frequencyBands;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export class MarkdownDocumenter {
pageTitle = `${scopedName} type`;
break;
case ApiItemKind.Variable:
pageTitle = `${scopedName} variable`;
pageTitle = `${scopedName}`;
break;
default:
throw new Error('Unsupported API item kind: ' + apiItem.kind);
Expand Down
30 changes: 27 additions & 3 deletions tooling/api-documenter/src/livekitUtils/classifiers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { ApiFunction, ApiItem } from '@microsoft/api-extractor-model';
import {
ApiFunction,
ApiItem,
ApiVariable,
ExcerptTokenKind,
} from '@microsoft/api-extractor-model';

export type LkType = 'component' | 'hook' | 'prefab' | undefined;
function isHook(apiItem: ApiItem): boolean {
Expand All @@ -13,11 +18,30 @@ function isPrefab(apiItem: ApiItem): boolean {
}
return false;
}

function isConstDeclarationComponent(apiItem: ApiItem): boolean {
return (
apiItem instanceof ApiVariable &&
apiItem.isReadonly &&
apiItem.excerptTokens.some(
(token) =>
token.kind === ExcerptTokenKind.Reference &&
['React.ReactNode', 'React.Context'].includes(token.text),
)
);
}

function isComponent(apiItem: ApiItem): boolean {
if (apiItem instanceof ApiFunction) {
if (
apiItem instanceof ApiFunction ||
(apiItem instanceof ApiVariable && isConstDeclarationComponent(apiItem))
) {
return (
isComponentReactPackage(apiItem) &&
!!apiItem.fileUrlPath?.startsWith('src/components/') &&
!!(
apiItem.fileUrlPath?.startsWith('src/components/') ||
apiItem.fileUrlPath?.startsWith('src/context/')
) &&
startsWithCapitalLetter(apiItem.displayName)
);
}
Expand Down

0 comments on commit 589ed63

Please sign in to comment.