@backstage/plugin-techdocs
Version:
The Backstage plugin that renders technical documentation for your components
213 lines (210 loc) • 7.99 kB
JavaScript
import { jsx, jsxs } from 'react/jsx-runtime';
import { Suspense } from 'react';
import { z } from 'zod/v4';
import { RiArticleLine } from '@remixicon/react';
import { ApiBlueprint, PageBlueprint, createExtensionInput, coreExtensionData, createExtension, PluginHeaderActionBlueprint, createFrontendPlugin } from '@backstage/frontend-plugin-api';
import { fetchApiRef, discoveryApiRef, configApiRef } from '@backstage/core-plugin-api';
import { EntityIconLinkBlueprint, EntityContentBlueprint } from '@backstage/plugin-catalog-react/alpha';
import { SearchResultListItemBlueprint, SearchFilterResultTypeBlueprint } from '@backstage/plugin-search-react/alpha';
import { AddonBlueprint, attachTechDocsAddonComponentData } from '@backstage/plugin-techdocs-react/alpha';
import { techdocsAddonsApiRef, TechDocsAddonsApiExtension } from './alpha/addonsApi.esm.js';
import { TechDocsStorageClient, TechDocsClient } from './client.esm.js';
import { rootRouteRef, rootDocsRouteRef, rootCatalogDocsRouteRef } from './routes.esm.js';
import { TechDocsReaderLayout } from './alpha/components/TechDocsReaderLayout.esm.js';
import { techdocsStorageApiRef, techdocsApiRef, TechDocsAddons } from '@backstage/plugin-techdocs-react';
import { useTechdocsReaderIconLinkProps } from './alpha/hooks/useTechdocsReaderIconLinkProps.esm.js';
import { DocsIcon, SupportButton } from '@backstage/core-components';
export { techdocsTranslationRef } from './translation.esm.js';
const techdocsEntityIconLink = EntityIconLinkBlueprint.make({
name: "read-docs",
params: {
useProps: useTechdocsReaderIconLinkProps
}
});
const techDocsStorageApi = ApiBlueprint.make({
name: "storage",
params: (defineParams) => defineParams({
api: techdocsStorageApiRef,
deps: {
configApi: configApiRef,
discoveryApi: discoveryApiRef,
fetchApi: fetchApiRef
},
factory: ({ configApi, discoveryApi, fetchApi }) => new TechDocsStorageClient({
configApi,
discoveryApi,
fetchApi
})
})
});
const techDocsClientApi = ApiBlueprint.make({
params: (defineParams) => defineParams({
api: techdocsApiRef,
deps: {
configApi: configApiRef,
discoveryApi: discoveryApiRef,
fetchApi: fetchApiRef
},
factory: ({ configApi, discoveryApi, fetchApi }) => new TechDocsClient({
configApi,
discoveryApi,
fetchApi
})
})
});
const techDocsSearchResultListItemExtension = SearchResultListItemBlueprint.makeWithOverrides({
configSchema: {
title: z.string().optional(),
lineClamp: z.number().default(5),
asLink: z.boolean().default(true),
asListItem: z.boolean().default(true)
},
factory(originalFactory, { config }) {
return originalFactory({
icon: /* @__PURE__ */ jsx(DocsIcon, {}),
predicate: (result) => result.type === "techdocs",
component: async () => {
const { TechDocsSearchResultListItem } = await import('./search/components/TechDocsSearchResultListItem.esm.js');
return (props) => /* @__PURE__ */ jsx(TechDocsSearchResultListItem, { ...props, ...config });
}
});
}
});
const techDocsSearchFilterResultTypeExtension = SearchFilterResultTypeBlueprint.make({
params: {
value: "techdocs",
name: "Documentation",
icon: /* @__PURE__ */ jsx(DocsIcon, {})
}
});
const techDocsPage = PageBlueprint.make({
params: {
path: "/docs",
routeRef: rootRouteRef,
title: "Docs",
icon: /* @__PURE__ */ jsx(RiArticleLine, {}),
loader: () => import('./alpha/components/TechDocsIndexPageContent.esm.js').then((m) => /* @__PURE__ */ jsx(m.TechDocsIndexPageContent, {}))
}
});
const techDocsReaderPage = PageBlueprint.makeWithOverrides({
name: "reader",
inputs: {
addons: createExtensionInput([AddonBlueprint.dataRefs.addon])
},
configSchema: {
withoutSearch: z.boolean().default(false),
withoutHeader: z.boolean().default(false)
},
factory(originalFactory, { apis, inputs, config }) {
const addonsApi = apis.get(techdocsAddonsApiRef);
return originalFactory({
path: "/docs/:namespace/:kind/:name",
routeRef: rootDocsRouteRef,
loader: async () => {
const apiAddons = addonsApi?.getAddons() ?? [];
const directAddons = inputs.addons.map(
(output) => output.get(AddonBlueprint.dataRefs.addon)
);
const addonOptions = [...apiAddons, ...directAddons];
const addons = addonOptions.map((options) => {
const Addon = options.component;
attachTechDocsAddonComponentData(Addon, options);
return /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(Addon, {}) }, options.name);
});
return import('./Router.esm.js').then(({ TechDocsReaderRouter }) => /* @__PURE__ */ jsxs(TechDocsReaderRouter, { children: [
/* @__PURE__ */ jsx(
TechDocsReaderLayout,
{
withSearch: !config.withoutSearch,
withHeader: !config.withoutHeader
}
),
/* @__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) {
const addonsApi = context.apis.get(techdocsAddonsApiRef);
return originalFactory(
{
path: "docs",
title: "TechDocs",
group: "documentation",
routeRef: rootCatalogDocsRouteRef,
loader: () => {
const apiAddons = addonsApi?.getAddons() ?? [];
const directAddons = context.inputs.addons.map(
(output) => output.get(AddonBlueprint.dataRefs.addon)
);
const addonOptions = [...apiAddons, ...directAddons];
const addons = addonOptions.map((options) => {
const Addon = options.component;
attachTechDocsAddonComponentData(Addon, options);
return /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(Addon, {}) }, options.name);
});
return import('./Router.esm.js').then(({ EmbeddedDocsRouter }) => /* @__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 techDocsSupportAction = PluginHeaderActionBlueprint.make({
params: (defineParams) => defineParams({
loader: async () => /* @__PURE__ */ jsx(SupportButton, { children: "Discover documentation in your ecosystem." })
})
});
var index = createFrontendPlugin({
pluginId: "techdocs",
title: "Documentation",
icon: /* @__PURE__ */ jsx(RiArticleLine, {}),
info: { packageJson: () => import('./plugins/techdocs/package.json.esm.js') },
extensions: [
techDocsClientApi,
techDocsStorageApi,
TechDocsAddonsApiExtension,
techDocsSupportAction,
techDocsPage,
techDocsReaderPage,
techdocsEntityIconLink,
techDocsEntityContent,
techDocsEntityContentEmptyState,
techDocsSearchFilterResultTypeExtension,
techDocsSearchResultListItemExtension
],
routes: {
root: rootRouteRef,
docRoot: rootDocsRouteRef,
entityContent: rootCatalogDocsRouteRef
}
});
export { index as default, techDocsSearchResultListItemExtension };
//# sourceMappingURL=alpha.esm.js.map