refactor: move exported type definitions to declaration file (#6300)

* refactor: move exported type definitions to declaration file

* fix

* fix
This commit is contained in:
Joshua Chen 2022-01-09 22:02:31 +08:00 committed by GitHub
parent 9c0e659a44
commit cf265c051e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
53 changed files with 482 additions and 452 deletions

View file

@ -7,21 +7,18 @@
import {matchPath} from '@docusaurus/router';
import type {GlobalPluginData, GlobalVersion, GlobalDoc} from '../types';
import type {
GlobalPluginData,
GlobalVersion,
GlobalDoc,
GetActivePluginOptions,
ActivePlugin,
ActiveDocContext,
DocVersionSuggestions,
} from '@docusaurus/plugin-content-docs/client';
// This code is not part of the api surface, not in ./theme on purpose
// Short/convenient type aliases
type Version = GlobalVersion;
type Doc = GlobalDoc;
export type ActivePlugin = {
pluginId: string;
pluginData: GlobalPluginData;
};
export type GetActivePluginOptions = {failfast?: boolean}; // use fail-fast option if you know for sure one plugin instance is active
// get the data of the plugin that is currently "active"
// ie the docs of that plugin are currently browsed
// it is useful to support multiple docs plugin instances
@ -56,13 +53,7 @@ export function getActivePlugin(
return activePlugin;
}
export type ActiveDocContext = {
activeVersion?: Version;
activeDoc?: Doc;
alternateDocVersions: Record<string, Doc>;
};
export const getLatestVersion = (data: GlobalPluginData): Version =>
export const getLatestVersion = (data: GlobalPluginData): GlobalVersion =>
data.versions.find((version) => version.isLast)!;
// Note: return undefined on doc-unrelated pages,
@ -70,7 +61,7 @@ export const getLatestVersion = (data: GlobalPluginData): Version =>
export const getActiveVersion = (
data: GlobalPluginData,
pathname: string,
): Version | undefined => {
): GlobalVersion | undefined => {
const lastVersion = getLatestVersion(data);
// Last version is a route like /docs/*,
// we need to try to match it last or it would match /docs/version-1.0/* as well
@ -127,13 +118,6 @@ export const getActiveDocContext = (
};
};
export type DocVersionSuggestions = {
// suggest the latest version
latestVersionSuggestion: GlobalVersion;
// suggest the same doc, in latest version (if exist)
latestDocSuggestion?: GlobalDoc;
};
export const getDocVersionSuggestions = (
data: GlobalPluginData,
pathname: string,