@backstage/plugin-techdocs
Version:
The Backstage plugin that renders technical documentation for your components
203 lines (200 loc) • 7.26 kB
JavaScript
import { jsx, jsxs } from 'react/jsx-runtime';
import LibraryBooks from '@material-ui/icons/LibraryBooks';
import { ApiBlueprint, PageBlueprint, createExtensionInput, coreExtensionData, createExtension, NavItemBlueprint, createFrontendPlugin } from '@backstage/frontend-plugin-api';
import { createApiFactory, configApiRef, discoveryApiRef, fetchApiRef } from '@backstage/core-plugin-api';
import { compatWrapper, convertLegacyRouteRef, convertLegacyRouteRefs } from '@backstage/core-compat-api';
import { EntityIconLinkBlueprint, EntityContentBlueprint } from '@backstage/plugin-catalog-react/alpha';
import { SearchResultListItemBlueprint } from '@backstage/plugin-search-react/alpha';
import { AddonBlueprint, attachTechDocsAddonComponentData } from '@backstage/plugin-techdocs-react/alpha';
import { TechDocsStorageClient, TechDocsClient } from './client.esm.js';
import { rootRouteRef, rootDocsRouteRef, rootCatalogDocsRouteRef } from './routes.esm.js';
import './reader/components/TechDocsReaderProvider.esm.js';
import { TechDocsReaderLayout } from './reader/components/TechDocsReaderPage/TechDocsReaderPage.esm.js';
import 'react';
import 'react-helmet';
import '@material-ui/core/Grid';
import '@material-ui/lab/Skeleton';
import '@material-ui/icons/Code';
import { techdocsStorageApiRef, techdocsApiRef, TechDocsAddons } from '@backstage/plugin-techdocs-react';
import '@backstage/plugin-catalog-react';
import '@backstage/catalog-model';
import '@backstage/core-components';
import 'lodash/capitalize';
import 'react-router-dom';
import './reader/components/TechDocsReaderPageContent/TechDocsReaderPageContent.esm.js';
import './reader/components/TechDocsReaderPageSubheader/TechDocsReaderPageSubheader.esm.js';
import { useTechdocsReaderIconLinkProps } from './alpha/hooks/useTechdocsReaderIconLinkProps.esm.js';
const techdocsEntityIconLink = EntityIconLinkBlueprint.make({
name: "read-docs",
params: {
useProps: useTechdocsReaderIconLinkProps
}
});
const techDocsStorageApi = ApiBlueprint.make({
name: "storage",
params: {
factory: createApiFactory({
api: techdocsStorageApiRef,
deps: {
configApi: configApiRef,
discoveryApi: discoveryApiRef,
fetchApi: fetchApiRef
},
factory: ({ configApi, discoveryApi, fetchApi }) => new TechDocsStorageClient({
configApi,
discoveryApi,
fetchApi
})
})
}
});
const techDocsClientApi = ApiBlueprint.make({
params: {
factory: createApiFactory({
api: techdocsApiRef,
deps: {
configApi: configApiRef,
discoveryApi: discoveryApiRef,
fetchApi: fetchApiRef
},
factory: ({ configApi, discoveryApi, fetchApi }) => new TechDocsClient({
configApi,
discoveryApi,
fetchApi
})
})
}
});
const techDocsSearchResultListItemExtension = SearchResultListItemBlueprint.makeWithOverrides({
config: {
schema: {
title: (z) => z.string().optional(),
lineClamp: (z) => z.number().default(5),
asLink: (z) => z.boolean().default(true),
asListItem: (z) => z.boolean().default(true)
}
},
factory(originalFactory, { config }) {
return originalFactory({
predicate: (result) => result.type === "techdocs",
component: async () => {
const { TechDocsSearchResultListItem } = await import('./search/components/TechDocsSearchResultListItem.esm.js');
return (props) => compatWrapper(
/* @__PURE__ */ jsx(TechDocsSearchResultListItem, { ...props, ...config })
);
}
});
}
});
const techDocsPage = PageBlueprint.make({
params: {
defaultPath: "/docs",
routeRef: convertLegacyRouteRef(rootRouteRef),
loader: () => import('./home/components/TechDocsIndexPage.esm.js').then(
(m) => compatWrapper(/* @__PURE__ */ jsx(m.TechDocsIndexPage, {}))
)
}
});
const techDocsReaderPage = PageBlueprint.makeWithOverrides({
name: "reader",
inputs: {
addons: createExtensionInput([AddonBlueprint.dataRefs.addon])
},
factory(originalFactory, { inputs }) {
const addons = inputs.addons.map((output) => {
const options = output.get(AddonBlueprint.dataRefs.addon);
const Addon = options.component;
attachTechDocsAddonComponentData(Addon, options);
return /* @__PURE__ */ jsx(Addon, {}, options.name);
});
return originalFactory({
defaultPath: "/docs/:namespace/:kind/:name",
routeRef: convertLegacyRouteRef(rootDocsRouteRef),
loader: async () => await import('./Router.esm.js').then(({ TechDocsReaderRouter }) => {
return compatWrapper(
/* @__PURE__ */ jsxs(TechDocsReaderRouter, { children: [
/* @__PURE__ */ jsx(TechDocsReaderLayout, {}),
/* @__PURE__ */ jsx(TechDocsAddons, { children: addons })
] })
);
})
});
}
});
const techDocsEntityContent = EntityContentBlueprint.makeWithOverrides({
inputs: {
addons: createExtensionInput([AddonBlueprint.dataRefs.addon]),
emptyState: createExtensionInput(
[coreExtensionData.reactElement.optional()],
{
singleton: true,
optional: true
}
)
},
factory(originalFactory, context) {
return originalFactory(
{
defaultPath: "docs",
defaultTitle: "TechDocs",
routeRef: convertLegacyRouteRef(rootCatalogDocsRouteRef),
loader: () => import('./Router.esm.js').then(({ EmbeddedDocsRouter }) => {
const addons = context.inputs.addons.map((output) => {
const options = output.get(AddonBlueprint.dataRefs.addon);
const Addon = options.component;
attachTechDocsAddonComponentData(Addon, options);
return /* @__PURE__ */ jsx(Addon, {}, options.name);
});
return compatWrapper(
/* @__PURE__ */ jsx(
EmbeddedDocsRouter,
{
emptyState: context.inputs.emptyState?.get(
coreExtensionData.reactElement
),
children: /* @__PURE__ */ jsx(TechDocsAddons, { children: addons })
}
)
);
})
},
context
);
}
});
const techDocsEntityContentEmptyState = createExtension({
kind: "empty-state",
name: "entity-content",
attachTo: { id: "entity-content:techdocs", input: "emptyState" },
output: [coreExtensionData.reactElement.optional()],
factory: () => []
});
const techDocsNavItem = NavItemBlueprint.make({
params: {
icon: LibraryBooks,
title: "Docs",
routeRef: convertLegacyRouteRef(rootRouteRef)
}
});
var index = createFrontendPlugin({
pluginId: "techdocs",
info: { packageJson: () => import('./package.json.esm.js') },
extensions: [
techDocsClientApi,
techDocsStorageApi,
techDocsNavItem,
techDocsPage,
techDocsReaderPage,
techdocsEntityIconLink,
techDocsEntityContent,
techDocsEntityContentEmptyState,
techDocsSearchResultListItemExtension
],
routes: convertLegacyRouteRefs({
root: rootRouteRef,
docRoot: rootDocsRouteRef,
entityContent: rootCatalogDocsRouteRef
})
});
export { index as default, techDocsSearchResultListItemExtension };
//# sourceMappingURL=alpha.esm.js.map