@backstage/plugin-techdocs 1.14.0-next.2 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/dist/EntityPageDocs.esm.js.map +1 -1
- package/dist/Router.esm.js.map +1 -1
- package/dist/alpha/hooks/useTechdocsReaderIconLinkProps.esm.js.map +1 -1
- package/dist/alpha.d.ts +1 -1
- package/dist/alpha.esm.js +1 -1
- package/dist/alpha.esm.js.map +1 -1
- package/dist/api.esm.js.map +1 -1
- package/dist/client.esm.js +1 -1
- package/dist/client.esm.js.map +1 -1
- package/dist/helpers.esm.js.map +1 -1
- package/dist/home/components/DefaultTechDocsHome.esm.js.map +1 -1
- package/dist/home/components/Grids/DocsCardGrid.esm.js.map +1 -1
- package/dist/home/components/Grids/EntityListDocsGrid.esm.js.map +1 -1
- package/dist/home/components/Grids/InfoCardGrid.esm.js.map +1 -1
- package/dist/home/components/Tables/CursorPaginatedDocsTable.esm.js.map +1 -1
- package/dist/home/components/Tables/DocsTable.esm.js.map +1 -1
- package/dist/home/components/Tables/EntityListDocsTable.esm.js.map +1 -1
- package/dist/home/components/Tables/OffsetPaginatedDocsTable.esm.js.map +1 -1
- package/dist/home/components/Tables/actions.esm.js.map +1 -1
- package/dist/home/components/Tables/columns.esm.js.map +1 -1
- package/dist/home/components/Tables/helpers.esm.js.map +1 -1
- package/dist/home/components/TechDocsCustomHome.esm.js +2 -2
- package/dist/home/components/TechDocsCustomHome.esm.js.map +1 -1
- package/dist/home/components/TechDocsIndexPage.esm.js.map +1 -1
- package/dist/home/components/TechDocsPageWrapper.esm.js.map +1 -1
- package/dist/home/components/TechDocsPicker.esm.js.map +1 -1
- package/dist/package.json.esm.js +1 -1
- package/dist/plugin.esm.js +2 -2
- package/dist/plugin.esm.js.map +1 -1
- package/dist/reader/components/TechDocsBuildLogs.esm.js.map +1 -1
- package/dist/reader/components/TechDocsNotFound.esm.js.map +1 -1
- package/dist/reader/components/TechDocsReaderPage/TechDocsReaderPage.esm.js +1 -1
- package/dist/reader/components/TechDocsReaderPage/TechDocsReaderPage.esm.js.map +1 -1
- package/dist/reader/components/TechDocsReaderPageContent/TechDocsReaderPageContent.esm.js.map +1 -1
- package/dist/reader/components/TechDocsReaderPageContent/TechDocsReaderPageContentAddons.esm.js.map +1 -1
- package/dist/reader/components/TechDocsReaderPageContent/dom.esm.js.map +1 -1
- package/dist/reader/components/TechDocsReaderPageContent/useNavigateUrl.esm.js.map +1 -1
- package/dist/reader/components/TechDocsReaderPageHeader/TechDocsReaderPageHeader.esm.js.map +1 -1
- package/dist/reader/components/TechDocsReaderPageSubheader/TechDocsReaderPageSubheader.esm.js.map +1 -1
- package/dist/reader/components/TechDocsReaderProvider.esm.js.map +1 -1
- package/dist/reader/components/TechDocsRedirectNotification/TechDocsRedirectNotification.esm.js.map +1 -1
- package/dist/reader/components/TechDocsStateIndicator.esm.js.map +1 -1
- package/dist/reader/components/useReaderState.esm.js.map +1 -1
- package/dist/reader/transformers/addBaseUrl.esm.js.map +1 -1
- package/dist/reader/transformers/addGitFeedbackLink.esm.js.map +1 -1
- package/dist/reader/transformers/addLinkClickListener.esm.js.map +1 -1
- package/dist/reader/transformers/addNavLinkKeyboardToggle.esm.js.map +1 -1
- package/dist/reader/transformers/addSidebarToggle.esm.js.map +1 -1
- package/dist/reader/transformers/copyToClipboard.esm.js.map +1 -1
- package/dist/reader/transformers/handleMetaRedirects.esm.js.map +1 -1
- package/dist/reader/transformers/html/hooks/iframes.esm.js.map +1 -1
- package/dist/reader/transformers/html/hooks/links.esm.js.map +1 -1
- package/dist/reader/transformers/html/transformer.esm.js.map +1 -1
- package/dist/reader/transformers/onCssReady.esm.js.map +1 -1
- package/dist/reader/transformers/removeMkdocsHeader.esm.js.map +1 -1
- package/dist/reader/transformers/renderReactElement.esm.js.map +1 -1
- package/dist/reader/transformers/rewriteDocLinks.esm.js.map +1 -1
- package/dist/reader/transformers/scrollIntoNavigation.esm.js.map +1 -1
- package/dist/reader/transformers/simplifyMkdocsFooter.esm.js.map +1 -1
- package/dist/reader/transformers/styles/rules/extensions.esm.js.map +1 -1
- package/dist/reader/transformers/styles/rules/layout.esm.js +16 -5
- package/dist/reader/transformers/styles/rules/layout.esm.js.map +1 -1
- package/dist/reader/transformers/styles/rules/palette.esm.js.map +1 -1
- package/dist/reader/transformers/styles/rules/reset.esm.js.map +1 -1
- package/dist/reader/transformers/styles/rules/rules.esm.js.map +1 -1
- package/dist/reader/transformers/styles/rules/typeset.esm.js.map +1 -1
- package/dist/reader/transformers/styles/rules/variables.esm.js.map +1 -1
- package/dist/reader/transformers/styles/transformer.esm.js +13 -1
- package/dist/reader/transformers/styles/transformer.esm.js.map +1 -1
- package/dist/reader/transformers/transformer.esm.js.map +1 -1
- package/dist/routes.esm.js.map +1 -1
- package/dist/search/components/TechDocsSearch.esm.js.map +1 -1
- package/dist/search/components/TechDocsSearchResultListItem.esm.js.map +1 -1
- package/dist/search/hooks/useTechDocsLocation.esm.js.map +1 -1
- package/dist/translation.esm.js.map +1 -1
- package/package.json +24 -24
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TechDocsReaderPageHeader.esm.js","sources":["../../../../src/reader/components/TechDocsReaderPageHeader/TechDocsReaderPageHeader.tsx"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { PropsWithChildren, useEffect } from 'react';\nimport Helmet from 'react-helmet';\n\nimport Grid from '@material-ui/core/Grid';\nimport Skeleton from '@material-ui/lab/Skeleton';\nimport CodeIcon from '@material-ui/icons/Code';\n\nimport {\n TechDocsAddonLocations as locations,\n useTechDocsAddons,\n useTechDocsReaderPage,\n TechDocsEntityMetadata,\n TechDocsMetadata,\n} from '@backstage/plugin-techdocs-react';\nimport {\n entityPresentationApiRef,\n EntityRefLink,\n EntityRefLinks,\n getEntityRelations,\n} from '@backstage/plugin-catalog-react';\nimport {\n RELATION_OWNED_BY,\n CompoundEntityRef,\n stringifyEntityRef,\n} from '@backstage/catalog-model';\nimport { Header, HeaderLabel } from '@backstage/core-components';\nimport { useRouteRef, configApiRef, useApi } from '@backstage/core-plugin-api';\n\nimport capitalize from 'lodash/capitalize';\n\nimport { rootRouteRef } from '../../../routes';\nimport { useParams } from 'react-router-dom';\n\nconst skeleton = <Skeleton animation=\"wave\" variant=\"text\" height={40} />;\n\n/**\n * Props for {@link TechDocsReaderPageHeader}\n *\n * @public\n * @deprecated No need to pass down properties anymore. The component consumes data from `TechDocsReaderPageContext` instead. Use the {@link @backstage/plugin-techdocs-react#useTechDocsReaderPage} hook for custom header.\n */\nexport type TechDocsReaderPageHeaderProps = PropsWithChildren<{\n entityRef?: CompoundEntityRef;\n entityMetadata?: TechDocsEntityMetadata;\n techDocsMetadata?: TechDocsMetadata;\n}>;\n\n/**\n * Renders the reader page header.\n * This component does not accept props, please use\n * the Tech Docs add-ons to customize it\n * @public\n */\nexport const TechDocsReaderPageHeader = (\n props: TechDocsReaderPageHeaderProps,\n) => {\n const { children } = props;\n const addons = useTechDocsAddons();\n const configApi = useApi(configApiRef);\n\n const entityPresentationApi = useApi(entityPresentationApiRef);\n const { '*': path = '' } = useParams();\n\n const {\n title,\n setTitle,\n subtitle,\n setSubtitle,\n entityRef,\n metadata: { value: metadata, loading: metadataLoading },\n entityMetadata: { value: entityMetadata, loading: entityMetadataLoading },\n } = useTechDocsReaderPage();\n\n useEffect(() => {\n if (!metadata) return;\n setTitle(metadata.site_name);\n setSubtitle(() => {\n let { site_description } = metadata;\n if (!site_description || site_description === 'None') {\n site_description = '';\n }\n return site_description;\n });\n }, [metadata, setTitle, setSubtitle]);\n\n const appTitle = configApi.getOptional('app.title') || 'Backstage';\n\n const { locationMetadata, spec } = entityMetadata || {};\n const lifecycle = spec?.lifecycle;\n\n const ownedByRelations = entityMetadata\n ? getEntityRelations(entityMetadata, RELATION_OWNED_BY)\n : [];\n\n const docsRootLink = useRouteRef(rootRouteRef)();\n\n const labels = (\n <>\n <HeaderLabel\n label={capitalize(entityMetadata?.kind || 'entity')}\n value={\n <EntityRefLink\n color=\"inherit\"\n entityRef={entityRef}\n title={entityMetadata?.metadata.title}\n defaultKind=\"Component\"\n />\n }\n />\n {ownedByRelations.length > 0 && (\n <HeaderLabel\n label=\"Owner\"\n value={\n <EntityRefLinks\n color=\"inherit\"\n entityRefs={ownedByRelations}\n defaultKind=\"group\"\n />\n }\n />\n )}\n {lifecycle ? (\n <HeaderLabel label=\"Lifecycle\" value={String(lifecycle)} />\n ) : null}\n {locationMetadata &&\n locationMetadata.type !== 'dir' &&\n locationMetadata.type !== 'file' ? (\n <HeaderLabel\n label=\"\"\n value={\n <Grid container direction=\"column\" alignItems=\"center\">\n <Grid style={{ padding: 0 }} item>\n <CodeIcon style={{ marginTop: '-25px' }} />\n </Grid>\n <Grid style={{ padding: 0 }} item>\n Source\n </Grid>\n </Grid>\n }\n url={locationMetadata.target}\n />\n ) : null}\n </>\n );\n\n // If there is no entity or techdocs metadata, there's no reason to show the\n // header (hides the header on 404 error pages).\n const noEntMetadata = !entityMetadataLoading && entityMetadata === undefined;\n const noTdMetadata = !metadataLoading && metadata === undefined;\n if (noEntMetadata || noTdMetadata) return null;\n\n const stringEntityRef = stringifyEntityRef(entityRef);\n\n const entityDisplayName =\n entityPresentationApi.forEntity(stringEntityRef).snapshot.primaryTitle;\n\n const removeTrailingSlash = (str: string) => str.replace(/\\/$/, '');\n const normalizeAndSpace = (str: string) =>\n str.replace(/-/g, ' ').split(' ').map(capitalize).join(' ');\n\n let techdocsTabTitleItems: string[] = [];\n\n if (path !== '')\n techdocsTabTitleItems = removeTrailingSlash(path)\n .split('/')\n .slice(0, 3)\n .map(normalizeAndSpace);\n\n const tabTitleItems = [appTitle, entityDisplayName, ...techdocsTabTitleItems];\n const tabTitle = tabTitleItems.join(' | ');\n\n return (\n <Header\n type=\"Documentation\"\n typeLink={docsRootLink}\n title={title || skeleton}\n subtitle={subtitle === '' ? undefined : subtitle || skeleton}\n >\n <Helmet titleTemplate=\"%s\">\n <title>{tabTitle}</title>\n </Helmet>\n {labels}\n {children}\n {addons.renderComponentsByLocation(locations.Header)}\n </Header>\n );\n};\n"],"names":["locations"],"mappings":";;;;;;;;;;;;;;;AAiDA,MAAM,QAAA,uBAAY,QAAS,EAAA,EAAA,SAAA,EAAU,QAAO,OAAQ,EAAA,MAAA,EAAO,QAAQ,EAAI,EAAA,CAAA;AAoB1D,MAAA,wBAAA,GAA2B,CACtC,KACG,KAAA;AACH,EAAM,MAAA,EAAE,UAAa,GAAA,KAAA;AACrB,EAAA,MAAM,SAAS,iBAAkB,EAAA;AACjC,EAAM,MAAA,SAAA,GAAY,OAAO,YAAY,CAAA;AAErC,EAAM,MAAA,qBAAA,GAAwB,OAAO,wBAAwB,CAAA;AAC7D,EAAA,MAAM,EAAE,GAAA,EAAK,IAAO,GAAA,EAAA,KAAO,SAAU,EAAA;AAErC,EAAM,MAAA;AAAA,IACJ,KAAA;AAAA,IACA,QAAA;AAAA,IACA,QAAA;AAAA,IACA,WAAA;AAAA,IACA,SAAA;AAAA,IACA,QAAU,EAAA,EAAE,KAAO,EAAA,QAAA,EAAU,SAAS,eAAgB,EAAA;AAAA,IACtD,cAAgB,EAAA,EAAE,KAAO,EAAA,cAAA,EAAgB,SAAS,qBAAsB;AAAA,MACtE,qBAAsB,EAAA;AAE1B,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,IAAI,CAAC,QAAU,EAAA;AACf,IAAA,QAAA,CAAS,SAAS,SAAS,CAAA;AAC3B,IAAA,WAAA,CAAY,MAAM;AAChB,MAAI,IAA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":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { PropsWithChildren, useEffect } from 'react';\nimport Helmet from 'react-helmet';\n\nimport Grid from '@material-ui/core/Grid';\nimport Skeleton from '@material-ui/lab/Skeleton';\nimport CodeIcon from '@material-ui/icons/Code';\n\nimport {\n TechDocsAddonLocations as locations,\n useTechDocsAddons,\n useTechDocsReaderPage,\n TechDocsEntityMetadata,\n TechDocsMetadata,\n} from '@backstage/plugin-techdocs-react';\nimport {\n entityPresentationApiRef,\n EntityRefLink,\n EntityRefLinks,\n getEntityRelations,\n} from '@backstage/plugin-catalog-react';\nimport {\n RELATION_OWNED_BY,\n CompoundEntityRef,\n stringifyEntityRef,\n} from '@backstage/catalog-model';\nimport { Header, HeaderLabel } from '@backstage/core-components';\nimport { useRouteRef, configApiRef, useApi } from '@backstage/core-plugin-api';\n\nimport capitalize from 'lodash/capitalize';\n\nimport { rootRouteRef } from '../../../routes';\nimport { useParams } from 'react-router-dom';\n\nconst skeleton = <Skeleton animation=\"wave\" variant=\"text\" height={40} />;\n\n/**\n * Props for {@link TechDocsReaderPageHeader}\n *\n * @public\n * @deprecated No need to pass down properties anymore. The component consumes data from `TechDocsReaderPageContext` instead. Use the {@link @backstage/plugin-techdocs-react#useTechDocsReaderPage} hook for custom header.\n */\nexport type TechDocsReaderPageHeaderProps = PropsWithChildren<{\n entityRef?: CompoundEntityRef;\n entityMetadata?: TechDocsEntityMetadata;\n techDocsMetadata?: TechDocsMetadata;\n}>;\n\n/**\n * Renders the reader page header.\n * This component does not accept props, please use\n * the Tech Docs add-ons to customize it\n * @public\n */\nexport const TechDocsReaderPageHeader = (\n props: TechDocsReaderPageHeaderProps,\n) => {\n const { children } = props;\n const addons = useTechDocsAddons();\n const configApi = useApi(configApiRef);\n\n const entityPresentationApi = useApi(entityPresentationApiRef);\n const { '*': path = '' } = useParams();\n\n const {\n title,\n setTitle,\n subtitle,\n setSubtitle,\n entityRef,\n metadata: { value: metadata, loading: metadataLoading },\n entityMetadata: { value: entityMetadata, loading: entityMetadataLoading },\n } = useTechDocsReaderPage();\n\n useEffect(() => {\n if (!metadata) return;\n setTitle(metadata.site_name);\n setSubtitle(() => {\n let { site_description } = metadata;\n if (!site_description || site_description === 'None') {\n site_description = '';\n }\n return site_description;\n });\n }, [metadata, setTitle, setSubtitle]);\n\n const appTitle = configApi.getOptional('app.title') || 'Backstage';\n\n const { locationMetadata, spec } = entityMetadata || {};\n const lifecycle = spec?.lifecycle;\n\n const ownedByRelations = entityMetadata\n ? getEntityRelations(entityMetadata, RELATION_OWNED_BY)\n : [];\n\n const docsRootLink = useRouteRef(rootRouteRef)();\n\n const labels = (\n <>\n <HeaderLabel\n label={capitalize(entityMetadata?.kind || 'entity')}\n value={\n <EntityRefLink\n color=\"inherit\"\n entityRef={entityRef}\n title={entityMetadata?.metadata.title}\n defaultKind=\"Component\"\n />\n }\n />\n {ownedByRelations.length > 0 && (\n <HeaderLabel\n label=\"Owner\"\n value={\n <EntityRefLinks\n color=\"inherit\"\n entityRefs={ownedByRelations}\n defaultKind=\"group\"\n />\n }\n />\n )}\n {lifecycle ? (\n <HeaderLabel label=\"Lifecycle\" value={String(lifecycle)} />\n ) : null}\n {locationMetadata &&\n locationMetadata.type !== 'dir' &&\n locationMetadata.type !== 'file' ? (\n <HeaderLabel\n label=\"\"\n value={\n <Grid container direction=\"column\" alignItems=\"center\">\n <Grid style={{ padding: 0 }} item>\n <CodeIcon style={{ marginTop: '-25px' }} />\n </Grid>\n <Grid style={{ padding: 0 }} item>\n Source\n </Grid>\n </Grid>\n }\n url={locationMetadata.target}\n />\n ) : null}\n </>\n );\n\n // If there is no entity or techdocs metadata, there's no reason to show the\n // header (hides the header on 404 error pages).\n const noEntMetadata = !entityMetadataLoading && entityMetadata === undefined;\n const noTdMetadata = !metadataLoading && metadata === undefined;\n if (noEntMetadata || noTdMetadata) return null;\n\n const stringEntityRef = stringifyEntityRef(entityRef);\n\n const entityDisplayName =\n entityPresentationApi.forEntity(stringEntityRef).snapshot.primaryTitle;\n\n const removeTrailingSlash = (str: string) => str.replace(/\\/$/, '');\n const normalizeAndSpace = (str: string) =>\n str.replace(/-/g, ' ').split(' ').map(capitalize).join(' ');\n\n let techdocsTabTitleItems: string[] = [];\n\n if (path !== '')\n techdocsTabTitleItems = removeTrailingSlash(path)\n .split('/')\n .slice(0, 3)\n .map(normalizeAndSpace);\n\n const tabTitleItems = [appTitle, entityDisplayName, ...techdocsTabTitleItems];\n const tabTitle = tabTitleItems.join(' | ');\n\n return (\n <Header\n type=\"Documentation\"\n typeLink={docsRootLink}\n title={title || skeleton}\n subtitle={subtitle === '' ? undefined : subtitle || skeleton}\n >\n <Helmet titleTemplate=\"%s\">\n <title>{tabTitle}</title>\n </Helmet>\n {labels}\n {children}\n {addons.renderComponentsByLocation(locations.Header)}\n </Header>\n );\n};\n"],"names":["locations"],"mappings":";;;;;;;;;;;;;;;AAiDA,MAAM,QAAA,uBAAY,QAAA,EAAA,EAAS,SAAA,EAAU,QAAO,OAAA,EAAQ,MAAA,EAAO,QAAQ,EAAA,EAAI,CAAA;AAoBhE,MAAM,wBAAA,GAA2B,CACtC,KAAA,KACG;AACH,EAAA,MAAM,EAAE,UAAS,GAAI,KAAA;AACrB,EAAA,MAAM,SAAS,iBAAA,EAAkB;AACjC,EAAA,MAAM,SAAA,GAAY,OAAO,YAAY,CAAA;AAErC,EAAA,MAAM,qBAAA,GAAwB,OAAO,wBAAwB,CAAA;AAC7D,EAAA,MAAM,EAAE,GAAA,EAAK,IAAA,GAAO,EAAA,KAAO,SAAA,EAAU;AAErC,EAAA,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AAA,IAAY,QAAA;AAAA,MAEpD,QAAA,EAAA;AAAA,wBAAA,GAAA,CAAC,UAAO,aAAA,EAAc,IAAA,EACpB,QAAA,kBAAA,GAAA,CAAC,OAAA,EAAA,EAAO,oBAAS,CAAA,EACnB,CAAA;AAAA,QACC,MAAA;AAAA,QACA,QAAA;AAAA,QACA,MAAA,CAAO,0BAAA,CAA2BA,sBAAA,CAAU,MAAM;AAAA;AAAA;AAAA,GACrD;AAEJ;;;;"}
|
package/dist/reader/components/TechDocsReaderPageSubheader/TechDocsReaderPageSubheader.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TechDocsReaderPageSubheader.esm.js","sources":["../../../../src/reader/components/TechDocsReaderPageSubheader/TechDocsReaderPageSubheader.tsx"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { MouseEvent, useState, useCallback } from 'react';\n\nimport { makeStyles } from '@material-ui/core/styles';\nimport IconButton from '@material-ui/core/IconButton';\nimport Toolbar from '@material-ui/core/Toolbar';\nimport { ToolbarProps } from '@material-ui/core/Toolbar';\nimport Tooltip from '@material-ui/core/Tooltip';\nimport Menu from '@material-ui/core/Menu';\nimport Box from '@material-ui/core/Box';\nimport SettingsIcon from '@material-ui/icons/Settings';\n\nimport {\n TechDocsAddonLocations as locations,\n useTechDocsAddons,\n useTechDocsReaderPage,\n} from '@backstage/plugin-techdocs-react';\n\nconst useStyles = makeStyles(theme => ({\n root: {\n gridArea: 'pageSubheader',\n flexDirection: 'column',\n minHeight: 'auto',\n padding: theme.spacing(3, 3, 0),\n '@media print': {\n display: 'none',\n },\n },\n}));\n\n/**\n * Renders the reader page subheader.\n * Please use the Tech Docs add-ons to customize it\n * @public\n */\nexport const TechDocsReaderPageSubheader = (props: {\n toolbarProps?: ToolbarProps;\n}) => {\n const classes = useStyles();\n const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);\n\n const handleClick = useCallback((event: MouseEvent<HTMLButtonElement>) => {\n setAnchorEl(event.currentTarget);\n }, []);\n\n const handleClose = useCallback(() => {\n setAnchorEl(null);\n }, []);\n\n const {\n entityMetadata: { value: entityMetadata, loading: entityMetadataLoading },\n } = useTechDocsReaderPage();\n\n const addons = useTechDocsAddons();\n\n const subheaderAddons = addons.renderComponentsByLocation(\n locations.Subheader,\n );\n\n const settingsAddons = addons.renderComponentsByLocation(locations.Settings);\n\n if (!subheaderAddons && !settingsAddons) return null;\n\n // No entity metadata = 404. Don't render subheader on 404.\n if (entityMetadataLoading === false && !entityMetadata) return null;\n\n return (\n <Toolbar classes={classes} {...props.toolbarProps}>\n <Box\n display=\"flex\"\n justifyContent=\"flex-end\"\n width=\"100%\"\n flexWrap=\"wrap\"\n >\n {subheaderAddons}\n {settingsAddons ? (\n <>\n <Tooltip title=\"Settings\">\n <IconButton\n aria-controls=\"tech-docs-reader-page-settings\"\n aria-haspopup=\"true\"\n onClick={handleClick}\n >\n <SettingsIcon />\n </IconButton>\n </Tooltip>\n <Menu\n id=\"tech-docs-reader-page-settings\"\n getContentAnchorEl={null}\n anchorEl={anchorEl}\n anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}\n open={Boolean(anchorEl)}\n onClose={handleClose}\n keepMounted\n >\n <div>{settingsAddons}</div>\n </Menu>\n </>\n ) : null}\n </Box>\n </Toolbar>\n );\n};\n"],"names":["locations"],"mappings":";;;;;;;;;;;AAiCA,MAAM,SAAA,GAAY,WAAW,
|
|
1
|
+
{"version":3,"file":"TechDocsReaderPageSubheader.esm.js","sources":["../../../../src/reader/components/TechDocsReaderPageSubheader/TechDocsReaderPageSubheader.tsx"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { MouseEvent, useState, useCallback } from 'react';\n\nimport { makeStyles } from '@material-ui/core/styles';\nimport IconButton from '@material-ui/core/IconButton';\nimport Toolbar from '@material-ui/core/Toolbar';\nimport { ToolbarProps } from '@material-ui/core/Toolbar';\nimport Tooltip from '@material-ui/core/Tooltip';\nimport Menu from '@material-ui/core/Menu';\nimport Box from '@material-ui/core/Box';\nimport SettingsIcon from '@material-ui/icons/Settings';\n\nimport {\n TechDocsAddonLocations as locations,\n useTechDocsAddons,\n useTechDocsReaderPage,\n} from '@backstage/plugin-techdocs-react';\n\nconst useStyles = makeStyles(theme => ({\n root: {\n gridArea: 'pageSubheader',\n flexDirection: 'column',\n minHeight: 'auto',\n padding: theme.spacing(3, 3, 0),\n '@media print': {\n display: 'none',\n },\n },\n}));\n\n/**\n * Renders the reader page subheader.\n * Please use the Tech Docs add-ons to customize it\n * @public\n */\nexport const TechDocsReaderPageSubheader = (props: {\n toolbarProps?: ToolbarProps;\n}) => {\n const classes = useStyles();\n const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);\n\n const handleClick = useCallback((event: MouseEvent<HTMLButtonElement>) => {\n setAnchorEl(event.currentTarget);\n }, []);\n\n const handleClose = useCallback(() => {\n setAnchorEl(null);\n }, []);\n\n const {\n entityMetadata: { value: entityMetadata, loading: entityMetadataLoading },\n } = useTechDocsReaderPage();\n\n const addons = useTechDocsAddons();\n\n const subheaderAddons = addons.renderComponentsByLocation(\n locations.Subheader,\n );\n\n const settingsAddons = addons.renderComponentsByLocation(locations.Settings);\n\n if (!subheaderAddons && !settingsAddons) return null;\n\n // No entity metadata = 404. Don't render subheader on 404.\n if (entityMetadataLoading === false && !entityMetadata) return null;\n\n return (\n <Toolbar classes={classes} {...props.toolbarProps}>\n <Box\n display=\"flex\"\n justifyContent=\"flex-end\"\n width=\"100%\"\n flexWrap=\"wrap\"\n >\n {subheaderAddons}\n {settingsAddons ? (\n <>\n <Tooltip title=\"Settings\">\n <IconButton\n aria-controls=\"tech-docs-reader-page-settings\"\n aria-haspopup=\"true\"\n onClick={handleClick}\n >\n <SettingsIcon />\n </IconButton>\n </Tooltip>\n <Menu\n id=\"tech-docs-reader-page-settings\"\n getContentAnchorEl={null}\n anchorEl={anchorEl}\n anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}\n open={Boolean(anchorEl)}\n onClose={handleClose}\n keepMounted\n >\n <div>{settingsAddons}</div>\n </Menu>\n </>\n ) : null}\n </Box>\n </Toolbar>\n );\n};\n"],"names":["locations"],"mappings":";;;;;;;;;;;AAiCA,MAAM,SAAA,GAAY,WAAW,CAAA,KAAA,MAAU;AAAA,EACrC,IAAA,EAAM;AAAA,IACJ,QAAA,EAAU,eAAA;AAAA,IACV,aAAA,EAAe,QAAA;AAAA,IACf,SAAA,EAAW,MAAA;AAAA,IACX,OAAA,EAAS,KAAA,CAAM,OAAA,CAAQ,CAAA,EAAG,GAAG,CAAC,CAAA;AAAA,IAC9B,cAAA,EAAgB;AAAA,MACd,OAAA,EAAS;AAAA;AACX;AAEJ,CAAA,CAAE,CAAA;AAOK,MAAM,2BAAA,GAA8B,CAAC,KAAA,KAEtC;AACJ,EAAA,MAAM,UAAU,SAAA,EAAU;AAC1B,EAAA,MAAM,CAAC,QAAA,EAAU,WAAW,CAAA,GAAI,SAA6B,IAAI,CAAA;AAEjE,EAAA,MAAM,WAAA,GAAc,WAAA,CAAY,CAAC,KAAA,KAAyC;AACxE,IAAA,WAAA,CAAY,MAAM,aAAa,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ChB,EACF,CAAA;AAAA,0BACA,GAAA;AAAA,YAAC,IAAA;AAAA,YAAA;AAAA,cACC,EAAA,EAAG,gCAAA;AAAA,cACH,kBAAA,EAAoB,IAAA;AAAA,cACpB,QAAA;AAAA,cACA,YAAA,EAAc,EAAE,QAAA,EAAU,QAAA,EAAU,YAAY,OAAA,EAAQ;AAAA,cACxD,IAAA,EAAM,QAAQ,QAAQ,CAAA;AAAA,cACtB,OAAA,EAAS,WAAA;AAAA,cACT,WAAA,EAAW,IAAA;AAAA,cAEX,QAAA,kBAAA,GAAA,CAAC,SAAK,QAAA,EAAA,cAAA,EAAe;AAAA;AAAA;AACvB,SAAA,EACF,CAAA,GACE;AAAA;AAAA;AAAA,GACN,EACF,CAAA;AAEJ;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TechDocsReaderProvider.esm.js","sources":["../../../src/reader/components/TechDocsReaderProvider.tsx"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ComponentType, createContext, useContext, ReactNode } from 'react';\nimport { useParams } from 'react-router-dom';\nimport { useTechDocsReaderPage } from '@backstage/plugin-techdocs-react';\n\nimport { useReaderState, ReaderState } from './useReaderState';\n\nconst TechDocsReaderContext = createContext<ReaderState>({} as ReaderState);\n\nexport const useTechDocsReader = () => useContext(TechDocsReaderContext);\n\n/**\n * @public Render function for {@link TechDocsReaderProvider}\n */\nexport type TechDocsReaderProviderRenderFunction = (\n value: ReaderState,\n) => JSX.Element;\n\n/**\n * @public Props for {@link TechDocsReaderProvider}\n */\nexport type TechDocsReaderProviderProps = {\n children: TechDocsReaderProviderRenderFunction | ReactNode;\n};\n\n/**\n * Provides shared building process state to the reader page components.\n *\n * @public\n */\nexport const TechDocsReaderProvider = (props: TechDocsReaderProviderProps) => {\n const { children } = props;\n\n const { '*': path = '' } = useParams();\n const { entityRef } = useTechDocsReaderPage();\n const { kind, namespace, name } = entityRef;\n const value = useReaderState(kind, namespace, name, path);\n\n return (\n <TechDocsReaderContext.Provider value={value}>\n {children instanceof Function ? children(value) : children}\n </TechDocsReaderContext.Provider>\n );\n};\n\nexport const withTechDocsReaderProvider =\n <T extends {}>(Component: ComponentType<T>) =>\n (props: T) =>\n (\n <TechDocsReaderProvider>\n <Component {...props} />\n </TechDocsReaderProvider>\n );\n"],"names":[],"mappings":";;;;;;AAsBA,MAAM,qBAAA,GAAwB,
|
|
1
|
+
{"version":3,"file":"TechDocsReaderProvider.esm.js","sources":["../../../src/reader/components/TechDocsReaderProvider.tsx"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ComponentType, createContext, useContext, ReactNode } from 'react';\nimport { useParams } from 'react-router-dom';\nimport { useTechDocsReaderPage } from '@backstage/plugin-techdocs-react';\n\nimport { useReaderState, ReaderState } from './useReaderState';\n\nconst TechDocsReaderContext = createContext<ReaderState>({} as ReaderState);\n\nexport const useTechDocsReader = () => useContext(TechDocsReaderContext);\n\n/**\n * @public Render function for {@link TechDocsReaderProvider}\n */\nexport type TechDocsReaderProviderRenderFunction = (\n value: ReaderState,\n) => JSX.Element;\n\n/**\n * @public Props for {@link TechDocsReaderProvider}\n */\nexport type TechDocsReaderProviderProps = {\n children: TechDocsReaderProviderRenderFunction | ReactNode;\n};\n\n/**\n * Provides shared building process state to the reader page components.\n *\n * @public\n */\nexport const TechDocsReaderProvider = (props: TechDocsReaderProviderProps) => {\n const { children } = props;\n\n const { '*': path = '' } = useParams();\n const { entityRef } = useTechDocsReaderPage();\n const { kind, namespace, name } = entityRef;\n const value = useReaderState(kind, namespace, name, path);\n\n return (\n <TechDocsReaderContext.Provider value={value}>\n {children instanceof Function ? children(value) : children}\n </TechDocsReaderContext.Provider>\n );\n};\n\nexport const withTechDocsReaderProvider =\n <T extends {}>(Component: ComponentType<T>) =>\n (props: T) =>\n (\n <TechDocsReaderProvider>\n <Component {...props} />\n </TechDocsReaderProvider>\n );\n"],"names":[],"mappings":";;;;;;AAsBA,MAAM,qBAAA,GAAwB,aAAA,CAA2B,EAAiB,CAAA;AAEnE,MAAM,iBAAA,GAAoB,MAAM,UAAA,CAAW,qBAAqB;AAqBhE,MAAM,sBAAA,GAAyB,CAAC,KAAA,KAAuC;AAC5E,EAAA,MAAM,EAAE,UAAS,GAAI,KAAA;AAErB,EAAA,MAAM,EAAE,GAAA,EAAK,IAAA,GAAO,EAAA,KAAO,SAAA,EAAU;AACrC,EAAA,MAAM,EAAE,SAAA,EAAU,GAAI,qBAAA,EAAsB;AAC5C,EAAA,MAAM,EAAE,IAAA,EAAM,SAAA,EAAW,IAAA,EAAK,GAAI,SAAA;AAClC,EAAA,MAAM,KAAA,GAAQ,cAAA,CAAe,IAAA,EAAM,SAAA,EAAW,MAAM,IAAI,CAAA;AAExD,EAAA,uBACE,GAAA,CAAC,qBAAA,CAAsB,QAAA,EAAtB,EAA+B,KAAA,EAC7B,8BAAoB,QAAA,GAAW,QAAA,CAAS,KAAK,CAAA,GAAI,QAAA,EACpD,CAAA;AAEJ;AAEO,MAAM,0BAAA,GACX,CAAe,SAAA,KACf,CAAC,KAAA,qBAEG,GAAA,CAAC,sBAAA,EAAA,EACC,QAAA,kBAAA,GAAA,CAAC,SAAA,EAAA,EAAW,GAAG,KAAA,EAAO,CAAA,EACxB;;;;"}
|
package/dist/reader/components/TechDocsRedirectNotification/TechDocsRedirectNotification.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TechDocsRedirectNotification.esm.js","sources":["../../../../src/reader/components/TechDocsRedirectNotification/TechDocsRedirectNotification.tsx"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { makeStyles } from '@material-ui/core/styles';\nimport { useState } from 'react';\nimport Snackbar from '@material-ui/core/Snackbar';\nimport Button from '@material-ui/core/Button';\n\ntype TechDocsRedirectNotificationProps = {\n handleButtonClick: () => void;\n message: string;\n autoHideDuration: number;\n};\n\nconst useStyles = makeStyles(theme => ({\n button: {\n color: theme.palette.primary.light,\n textDecoration: 'underline',\n },\n}));\n\nexport const TechDocsRedirectNotification = ({\n message,\n handleButtonClick,\n autoHideDuration,\n}: TechDocsRedirectNotificationProps) => {\n const classes = useStyles();\n const [open, setOpen] = useState(true);\n\n const handleClose = () => setOpen(false);\n\n return (\n <Snackbar\n open={open}\n anchorOrigin={{ vertical: 'top', horizontal: 'right' }}\n autoHideDuration={autoHideDuration}\n color=\"primary\"\n onClose={handleClose}\n message={message}\n action={\n <Button\n classes={{ root: classes.button }}\n size=\"small\"\n onClick={() => {\n handleClose();\n handleButtonClick();\n }}\n >\n Redirect now\n </Button>\n }\n />\n );\n};\n"],"names":[],"mappings":";;;;;;AA2BA,MAAM,SAAA,GAAY,WAAW,
|
|
1
|
+
{"version":3,"file":"TechDocsRedirectNotification.esm.js","sources":["../../../../src/reader/components/TechDocsRedirectNotification/TechDocsRedirectNotification.tsx"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { makeStyles } from '@material-ui/core/styles';\nimport { useState } from 'react';\nimport Snackbar from '@material-ui/core/Snackbar';\nimport Button from '@material-ui/core/Button';\n\ntype TechDocsRedirectNotificationProps = {\n handleButtonClick: () => void;\n message: string;\n autoHideDuration: number;\n};\n\nconst useStyles = makeStyles(theme => ({\n button: {\n color: theme.palette.primary.light,\n textDecoration: 'underline',\n },\n}));\n\nexport const TechDocsRedirectNotification = ({\n message,\n handleButtonClick,\n autoHideDuration,\n}: TechDocsRedirectNotificationProps) => {\n const classes = useStyles();\n const [open, setOpen] = useState(true);\n\n const handleClose = () => setOpen(false);\n\n return (\n <Snackbar\n open={open}\n anchorOrigin={{ vertical: 'top', horizontal: 'right' }}\n autoHideDuration={autoHideDuration}\n color=\"primary\"\n onClose={handleClose}\n message={message}\n action={\n <Button\n classes={{ root: classes.button }}\n size=\"small\"\n onClick={() => {\n handleClose();\n handleButtonClick();\n }}\n >\n Redirect now\n </Button>\n }\n />\n );\n};\n"],"names":[],"mappings":";;;;;;AA2BA,MAAM,SAAA,GAAY,WAAW,CAAA,KAAA,MAAU;AAAA,EACrC,MAAA,EAAQ;AAAA,IACN,KAAA,EAAO,KAAA,CAAM,OAAA,CAAQ,OAAA,CAAQ,KAAA;AAAA,IAC7B,cAAA,EAAgB;AAAA;AAEpB,CAAA,CAAE,CAAA;AAEK,MAAM,+BAA+B,CAAC;AAAA,EAC3C,OAAA;AAAA,EACA,iBAAA;AAAA,EACA;AACF,CAAA,KAAyC;AACvC,EAAA,MAAM,UAAU,SAAA,EAAU;AAC1B,EAAA,MAAM,CAAC,IAAA,EAAM,OAAO,CAAA,GAAI,SAAS,IAAI,CAAA;AAErC,EAAA,MAAM,WAAA,GAAc,MAAM,OAAA,CAAQ,KAAK,CAAA;AAEvC,EAAA,uBACE,GAAA;AAAA,IAAC,QAAA;AAAA,IAAA;AAAA,MACC,IAAA;AAAA,MACA,YAAA,EAAc,EAAE,QAAA,EAAU,KAAA,EAAO,YAAY,OAAA,EAAQ;AAAA,MACrD,gBAAA;AAAA,MACA,KAAA,EAAM,SAAA;AAAA,MACN,OAAA,EAAS,WAAA;AAAA,MACT,OAAA;AAAA,MACA,MAAA,kBACE,GAAA;AAAA,QAAC,MAAA;AAAA,QAAA;AAAA,UACC,OAAA,EAAS,EAAE,IAAA,EAAM,OAAA,CAAQ,MAAA,EAAO;AAAA,UAChC,IAAA,EAAK,OAAA;AAAA,UACL,SAAS,MAAM;AACb,YAAA,WAAA,EAAY;AACZ,YAAA,iBAAA,EAAkB;AAAA,UACpB,CAAA;AAAA,UACD,QAAA,EAAA;AAAA;AAAA;AAED;AAAA,GAEJ;AAEJ;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TechDocsStateIndicator.esm.js","sources":["../../../src/reader/components/TechDocsStateIndicator.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport CircularProgress from '@material-ui/core/CircularProgress';\nimport Button from '@material-ui/core/Button';\nimport { makeStyles } from '@material-ui/core/styles';\nimport Alert from '@material-ui/lab/Alert';\n\nimport { TechDocsBuildLogs } from './TechDocsBuildLogs';\nimport { TechDocsNotFound } from './TechDocsNotFound';\nimport { useTechDocsReader } from './TechDocsReaderProvider';\n\nconst useStyles = makeStyles(theme => ({\n root: {\n marginBottom: theme.spacing(2),\n },\n message: {\n // `word-break: break-word` is deprecated, but gives legacy support to browsers not supporting `overflow-wrap` yet\n // https://developer.mozilla.org/en-US/docs/Web/CSS/word-break\n wordBreak: 'break-word',\n overflowWrap: 'anywhere',\n },\n}));\n\nexport const TechDocsStateIndicator = () => {\n let StateAlert: JSX.Element | null = null;\n const classes = useStyles();\n\n const {\n state,\n contentReload,\n contentErrorMessage,\n syncErrorMessage,\n buildLog,\n } = useTechDocsReader();\n\n if (state === 'INITIAL_BUILD') {\n StateAlert = (\n <Alert\n classes={{ root: classes.root }}\n variant=\"outlined\"\n severity=\"info\"\n icon={<CircularProgress size=\"24px\" />}\n action={<TechDocsBuildLogs buildLog={buildLog} />}\n >\n Documentation is accessed for the first time and is being prepared. The\n subsequent loads are much faster.\n </Alert>\n );\n }\n\n if (state === 'CONTENT_STALE_REFRESHING') {\n StateAlert = (\n <Alert\n variant=\"outlined\"\n severity=\"info\"\n icon={<CircularProgress size=\"24px\" />}\n action={<TechDocsBuildLogs buildLog={buildLog} />}\n classes={{ root: classes.root }}\n >\n A newer version of this documentation is being prepared and will be\n available shortly.\n </Alert>\n );\n }\n\n if (state === 'CONTENT_STALE_READY') {\n StateAlert = (\n <Alert\n variant=\"outlined\"\n severity=\"success\"\n action={\n <Button color=\"inherit\" onClick={() => contentReload()}>\n Refresh\n </Button>\n }\n classes={{ root: classes.root }}\n >\n A newer version of this documentation is now available, please refresh\n to view.\n </Alert>\n );\n }\n\n if (state === 'CONTENT_STALE_ERROR') {\n StateAlert = (\n <Alert\n variant=\"outlined\"\n severity=\"error\"\n action={<TechDocsBuildLogs buildLog={buildLog} />}\n classes={{ root: classes.root, message: classes.message }}\n >\n Building a newer version of this documentation failed.{' '}\n {syncErrorMessage}\n </Alert>\n );\n }\n\n if (state === 'CONTENT_NOT_FOUND') {\n StateAlert = (\n <>\n {syncErrorMessage && (\n <Alert\n variant=\"outlined\"\n severity=\"error\"\n action={<TechDocsBuildLogs buildLog={buildLog} />}\n classes={{ root: classes.root, message: classes.message }}\n >\n Building a newer version of this documentation failed.{' '}\n {syncErrorMessage}\n </Alert>\n )}\n <TechDocsNotFound errorMessage={contentErrorMessage} />\n </>\n );\n }\n\n return StateAlert;\n};\n"],"names":[],"mappings":";;;;;;;;;AAyBA,MAAM,SAAA,GAAY,WAAW,
|
|
1
|
+
{"version":3,"file":"TechDocsStateIndicator.esm.js","sources":["../../../src/reader/components/TechDocsStateIndicator.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport CircularProgress from '@material-ui/core/CircularProgress';\nimport Button from '@material-ui/core/Button';\nimport { makeStyles } from '@material-ui/core/styles';\nimport Alert from '@material-ui/lab/Alert';\n\nimport { TechDocsBuildLogs } from './TechDocsBuildLogs';\nimport { TechDocsNotFound } from './TechDocsNotFound';\nimport { useTechDocsReader } from './TechDocsReaderProvider';\n\nconst useStyles = makeStyles(theme => ({\n root: {\n marginBottom: theme.spacing(2),\n },\n message: {\n // `word-break: break-word` is deprecated, but gives legacy support to browsers not supporting `overflow-wrap` yet\n // https://developer.mozilla.org/en-US/docs/Web/CSS/word-break\n wordBreak: 'break-word',\n overflowWrap: 'anywhere',\n },\n}));\n\nexport const TechDocsStateIndicator = () => {\n let StateAlert: JSX.Element | null = null;\n const classes = useStyles();\n\n const {\n state,\n contentReload,\n contentErrorMessage,\n syncErrorMessage,\n buildLog,\n } = useTechDocsReader();\n\n if (state === 'INITIAL_BUILD') {\n StateAlert = (\n <Alert\n classes={{ root: classes.root }}\n variant=\"outlined\"\n severity=\"info\"\n icon={<CircularProgress size=\"24px\" />}\n action={<TechDocsBuildLogs buildLog={buildLog} />}\n >\n Documentation is accessed for the first time and is being prepared. The\n subsequent loads are much faster.\n </Alert>\n );\n }\n\n if (state === 'CONTENT_STALE_REFRESHING') {\n StateAlert = (\n <Alert\n variant=\"outlined\"\n severity=\"info\"\n icon={<CircularProgress size=\"24px\" />}\n action={<TechDocsBuildLogs buildLog={buildLog} />}\n classes={{ root: classes.root }}\n >\n A newer version of this documentation is being prepared and will be\n available shortly.\n </Alert>\n );\n }\n\n if (state === 'CONTENT_STALE_READY') {\n StateAlert = (\n <Alert\n variant=\"outlined\"\n severity=\"success\"\n action={\n <Button color=\"inherit\" onClick={() => contentReload()}>\n Refresh\n </Button>\n }\n classes={{ root: classes.root }}\n >\n A newer version of this documentation is now available, please refresh\n to view.\n </Alert>\n );\n }\n\n if (state === 'CONTENT_STALE_ERROR') {\n StateAlert = (\n <Alert\n variant=\"outlined\"\n severity=\"error\"\n action={<TechDocsBuildLogs buildLog={buildLog} />}\n classes={{ root: classes.root, message: classes.message }}\n >\n Building a newer version of this documentation failed.{' '}\n {syncErrorMessage}\n </Alert>\n );\n }\n\n if (state === 'CONTENT_NOT_FOUND') {\n StateAlert = (\n <>\n {syncErrorMessage && (\n <Alert\n variant=\"outlined\"\n severity=\"error\"\n action={<TechDocsBuildLogs buildLog={buildLog} />}\n classes={{ root: classes.root, message: classes.message }}\n >\n Building a newer version of this documentation failed.{' '}\n {syncErrorMessage}\n </Alert>\n )}\n <TechDocsNotFound errorMessage={contentErrorMessage} />\n </>\n );\n }\n\n return StateAlert;\n};\n"],"names":[],"mappings":";;;;;;;;;AAyBA,MAAM,SAA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C,iBAAA,EAAA,EAAkB,QAAA,EAAoB,CAAA;AAAA,UAC/C,SAAS,EAAE,IAAA,EAAM,QAAQ,IAAA,EAAM,OAAA,EAAS,QAAQ,OAAA,EAAQ;AAAA,UACzD,QAAA,EAAA;AAAA,YAAA,wDAAA;AAAA,YACwD,GAAA;AAAA,YACtD;AAAA;AAAA;AAAA,OACH;AAAA,sBAEF,GAAA,CAAC,gBAAA,EAAA,EAAiB,YAAA,EAAc,mBAAA,EAAqB;AAAA,KAAA,EACvD,CAAA;AAAA,EAEJ;AAEA,EAAA,OAAO,UAAA;AACT;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useReaderState.esm.js","sources":["../../../src/reader/components/useReaderState.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useApi } from '@backstage/core-plugin-api';\nimport { useMemo, useReducer, useRef } from 'react';\nimport useAsync from 'react-use/esm/useAsync';\nimport useAsyncRetry from 'react-use/esm/useAsyncRetry';\nimport { techdocsStorageApiRef } from '@backstage/plugin-techdocs-react';\n\n/**\n * @public\n * A state representation that is used to configure the UI of <Reader />\n */\nexport type ContentStateTypes =\n /** There is nothing to display but a loading indicator */\n | 'CHECKING'\n\n /** There is no content yet -> present a full screen loading page */\n | 'INITIAL_BUILD'\n\n /** There is content, but the backend is about to update it */\n | 'CONTENT_STALE_REFRESHING'\n\n /** There is content, but after a reload, the content will be different */\n | 'CONTENT_STALE_READY'\n\n /** There is content, the backend tried to update it, but failed */\n | 'CONTENT_STALE_ERROR'\n\n /** There is nothing to see but a \"not found\" page. Is also shown on page load errors */\n | 'CONTENT_NOT_FOUND'\n\n /** There is only the latest and greatest content */\n | 'CONTENT_FRESH';\n\n/**\n * Calculate the state that should be reported to the display component.\n */\nexport function calculateDisplayState({\n contentLoading,\n content,\n activeSyncState,\n}: Pick<\n ReducerState,\n 'contentLoading' | 'content' | 'activeSyncState'\n>): ContentStateTypes {\n // we have nothing to display yet\n if (contentLoading) {\n return 'CHECKING';\n }\n\n // the build is ready, but it triggered a content reload and the content variable is not trusted\n if (activeSyncState === 'BUILD_READY_RELOAD') {\n return 'CHECKING';\n }\n\n // there is no content, but the sync process is still evaluating\n if (!content && activeSyncState === 'CHECKING') {\n return 'CHECKING';\n }\n\n // there is no content yet so we assume that we are building it for the first time\n if (!content && activeSyncState === 'BUILDING') {\n return 'INITIAL_BUILD';\n }\n\n // if there is still no content after building, it might just not exist\n if (!content) {\n return 'CONTENT_NOT_FOUND';\n }\n\n // we are still building, but we already show stale content\n if (activeSyncState === 'BUILDING') {\n return 'CONTENT_STALE_REFRESHING';\n }\n\n // the build is ready, but the content is still stale\n if (activeSyncState === 'BUILD_READY') {\n return 'CONTENT_STALE_READY';\n }\n\n // the build failed, but the content is still stale\n if (activeSyncState === 'ERROR') {\n return 'CONTENT_STALE_ERROR';\n }\n\n // seems like the content is up-to-date (or we don't know yet and the sync process is still evaluating in the background)\n return 'CONTENT_FRESH';\n}\n\n/**\n * The state of the synchronization task. It checks whether the docs are\n * up-to-date. If they aren't, it triggers a build.\n */\ntype SyncStates =\n /** Checking if it should be synced */\n | 'CHECKING'\n\n /** Building the documentation */\n | 'BUILDING'\n\n /** Finished building the documentation */\n | 'BUILD_READY'\n\n /**\n * Finished building the documentation and triggered a content reload.\n * This state is left toward UP_TO_DATE when the content loading has finished.\n */\n | 'BUILD_READY_RELOAD'\n\n /** No need for a sync. The content was already up-to-date. */\n | 'UP_TO_DATE'\n\n /** An error occurred */\n | 'ERROR';\n\ntype ReducerActions =\n | {\n type: 'sync';\n state: SyncStates;\n syncError?: Error;\n }\n | { type: 'contentLoading' }\n | {\n type: 'content';\n path?: string;\n content?: string;\n contentError?: Error;\n }\n | { type: 'buildLog'; log: string };\n\ntype ReducerState = {\n /**\n * The path of the current page\n */\n path: string;\n\n /**\n * The current sync state\n */\n activeSyncState: SyncStates;\n\n /**\n * If true, the content is downloading from the storage.\n */\n contentLoading: boolean;\n /**\n * The content that has been downloaded and should be displayed.\n */\n content?: string;\n\n contentError?: Error;\n syncError?: Error;\n\n /**\n * A list of log messages that were emitted by the build process.\n */\n buildLog: string[];\n};\n\nexport function reducer(\n oldState: ReducerState,\n action: ReducerActions,\n): ReducerState {\n const newState = { ...oldState };\n\n switch (action.type) {\n case 'sync':\n // reset the build log when a new check starts\n if (action.state === 'CHECKING') {\n newState.buildLog = [];\n }\n\n newState.activeSyncState = action.state;\n newState.syncError = action.syncError;\n break;\n\n case 'contentLoading':\n newState.contentLoading = true;\n\n // only reset errors but keep the old content until it is replaced by the 'content' action\n newState.contentError = undefined;\n break;\n\n case 'content':\n // only override the path if it is part of the action\n if (typeof action.path === 'string') {\n newState.path = action.path;\n }\n\n newState.contentLoading = false;\n newState.content = action.content;\n newState.contentError = action.contentError;\n break;\n\n case 'buildLog':\n newState.buildLog = newState.buildLog.concat(action.log);\n break;\n\n default:\n throw new Error();\n }\n\n // a content update loads fresh content so the build is updated to being up-to-date\n if (\n ['BUILD_READY', 'BUILD_READY_RELOAD'].includes(newState.activeSyncState) &&\n ['contentLoading', 'content'].includes(action.type)\n ) {\n newState.activeSyncState = 'UP_TO_DATE';\n newState.buildLog = [];\n }\n\n return newState;\n}\n/**\n * @public shared reader state\n */\nexport type ReaderState = {\n state: ContentStateTypes;\n path: string;\n contentReload: () => void;\n content?: string;\n contentErrorMessage?: string;\n syncErrorMessage?: string;\n buildLog: string[];\n};\n\nexport function useReaderState(\n kind: string,\n namespace: string,\n name: string,\n path: string,\n): ReaderState {\n const [state, dispatch] = useReducer(reducer, {\n activeSyncState: 'CHECKING',\n path,\n contentLoading: true,\n buildLog: [],\n });\n\n const techdocsStorageApi = useApi(techdocsStorageApiRef);\n\n // try to load the content. the function will fire events and we don't care for the return values\n const { retry: contentReload } = useAsyncRetry(async () => {\n dispatch({ type: 'contentLoading' });\n\n try {\n const entityDocs = await techdocsStorageApi.getEntityDocs(\n { kind, namespace, name },\n path,\n );\n\n // update content and path at the same time\n dispatch({ type: 'content', content: entityDocs, path });\n\n return entityDocs;\n } catch (e) {\n dispatch({ type: 'content', contentError: e, path });\n }\n\n return undefined;\n }, [techdocsStorageApi, kind, namespace, name, path]);\n\n // create a ref that holds the latest content. This provides a useAsync hook\n // with the latest content without restarting the useAsync hook.\n const contentRef = useRef<{ content?: string; reload: () => void }>({\n content: undefined,\n reload: () => {},\n });\n contentRef.current = { content: state.content, reload: contentReload };\n\n // try to derive the state. the function will fire events and we don't care for the return values\n useAsync(async () => {\n dispatch({ type: 'sync', state: 'CHECKING' });\n\n // should only switch to BUILDING if the request takes more than 1 seconds\n const buildingTimeout = setTimeout(() => {\n dispatch({ type: 'sync', state: 'BUILDING' });\n }, 1000);\n\n try {\n const result = await techdocsStorageApi.syncEntityDocs(\n {\n kind,\n namespace,\n name,\n },\n log => {\n dispatch({ type: 'buildLog', log });\n },\n );\n\n switch (result) {\n case 'updated':\n // if there was no content prior to building, retry the loading\n if (!contentRef.current.content) {\n contentRef.current.reload();\n dispatch({ type: 'sync', state: 'BUILD_READY_RELOAD' });\n } else {\n dispatch({ type: 'sync', state: 'BUILD_READY' });\n }\n break;\n case 'cached':\n dispatch({ type: 'sync', state: 'UP_TO_DATE' });\n break;\n\n default:\n dispatch({\n type: 'sync',\n state: 'ERROR',\n syncError: new Error('Unexpected return state'),\n });\n break;\n }\n } catch (e) {\n dispatch({ type: 'sync', state: 'ERROR', syncError: e });\n } finally {\n // Cancel the timer that sets the state \"BUILDING\"\n clearTimeout(buildingTimeout);\n }\n }, [kind, name, namespace, techdocsStorageApi, dispatch, contentRef]);\n\n const displayState = useMemo(\n () =>\n calculateDisplayState({\n activeSyncState: state.activeSyncState,\n contentLoading: state.contentLoading,\n content: state.content,\n }),\n [state.activeSyncState, state.content, state.contentLoading],\n );\n\n return useMemo(\n () => ({\n state: displayState,\n contentReload,\n path: state.path,\n content: state.content,\n contentErrorMessage: state.contentError?.toString(),\n syncErrorMessage: state.syncError?.toString(),\n buildLog: state.buildLog,\n }),\n [\n displayState,\n contentReload,\n state.path,\n state.content,\n state.contentError,\n state.syncError,\n state.buildLog,\n ],\n );\n}\n"],"names":[],"mappings":";;;;;;AAmDO,SAAS,qBAAsB,CAAA;AAAA,EACpC,cAAA;AAAA,EACA,OAAA;AAAA,EACA;AACF,CAGsB,EAAA;AAEpB,EAAA,IAAI,cAAgB,EAAA;AAClB,IAAO,OAAA,UAAA;AAAA;AAIT,EAAA,IAAI,oBAAoB,oBAAsB,EAAA;AAC5C,IAAO,OAAA,UAAA;AAAA;AAIT,EAAI,IAAA,CAAC,OAAW,IAAA,eAAA,KAAoB,UAAY,EAAA;AAC9C,IAAO,OAAA,UAAA;AAAA;AAIT,EAAI,IAAA,CAAC,OAAW,IAAA,eAAA,KAAoB,UAAY,EAAA;AAC9C,IAAO,OAAA,eAAA;AAAA;AAIT,EAAA,IAAI,CAAC,OAAS,EAAA;AACZ,IAAO,OAAA,mBAAA;AAAA;AAIT,EAAA,IAAI,oBAAoB,UAAY,EAAA;AAClC,IAAO,OAAA,0BAAA;AAAA;AAIT,EAAA,IAAI,oBAAoB,aAAe,EAAA;AACrC,IAAO,OAAA,qBAAA;AAAA;AAIT,EAAA,IAAI,oBAAoB,OAAS,EAAA;AAC/B,IAAO,OAAA,qBAAA;AAAA;AAIT,EAAO,OAAA,eAAA;AACT;AAwEgB,SAAA,OAAA,CACd,UACA,MACc,EAAA;AACd,EAAM,MAAA,QAAA,GAAW,EAAE,GAAG,QAAS,EAAA;AAE/B,EAAA,QAAQ,OAAO,IAAM;AAAA,IACnB,KAAK,MAAA;AAEH,MAAI,IAAA,MAAA,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IACnB,MACE,qBAAsB,CAAA;AAAA,MACpB,iBAAiB,KAAM,CAAA,eAAA;AAAA,MACvB,gBAAgB,KAAM,CAAA,cAAA;AAAA,MACtB,SAAS,KAAM,CAAA;AAAA,KAChB,CAAA;AAAA,IACH,CAAC,KAAM,CAAA,eAAA,EAAiB,KAAM,CAAA,OAAA,EAAS,MAAM,cAAc;AAAA,GAC7D;AAEA,EAAO,OAAA,OAAA;AAAA,IACL,OAAO;AAAA,MACL,KAAO,EAAA,YAAA;AAAA,MACP,aAAA;AAAA,MACA,MAAM,KAAM,CAAA,IAAA;AAAA,MACZ,SAAS,KAAM,CAAA,OAAA;AAAA,MACf,mBAAA,EAAqB,KAAM,CAAA,YAAA,EAAc,QAAS,EAAA;AAAA,MAClD,gBAAA,EAAkB,KAAM,CAAA,SAAA,EAAW,QAAS,EAAA;AAAA,MAC5C,UAAU,KAAM,CAAA;AAAA,KAClB,CAAA;AAAA,IACA;AAAA,MACE,YAAA;AAAA,MACA,aAAA;AAAA,MACA,KAAM,CAAA,IAAA;AAAA,MACN,KAAM,CAAA,OAAA;AAAA,MACN,KAAM,CAAA,YAAA;AAAA,MACN,KAAM,CAAA,SAAA;AAAA,MACN,KAAM,CAAA;AAAA;AACR,GACF;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"useReaderState.esm.js","sources":["../../../src/reader/components/useReaderState.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useApi } from '@backstage/core-plugin-api';\nimport { useMemo, useReducer, useRef } from 'react';\nimport useAsync from 'react-use/esm/useAsync';\nimport useAsyncRetry from 'react-use/esm/useAsyncRetry';\nimport { techdocsStorageApiRef } from '@backstage/plugin-techdocs-react';\n\n/**\n * @public\n * A state representation that is used to configure the UI of <Reader />\n */\nexport type ContentStateTypes =\n /** There is nothing to display but a loading indicator */\n | 'CHECKING'\n\n /** There is no content yet -> present a full screen loading page */\n | 'INITIAL_BUILD'\n\n /** There is content, but the backend is about to update it */\n | 'CONTENT_STALE_REFRESHING'\n\n /** There is content, but after a reload, the content will be different */\n | 'CONTENT_STALE_READY'\n\n /** There is content, the backend tried to update it, but failed */\n | 'CONTENT_STALE_ERROR'\n\n /** There is nothing to see but a \"not found\" page. Is also shown on page load errors */\n | 'CONTENT_NOT_FOUND'\n\n /** There is only the latest and greatest content */\n | 'CONTENT_FRESH';\n\n/**\n * Calculate the state that should be reported to the display component.\n */\nexport function calculateDisplayState({\n contentLoading,\n content,\n activeSyncState,\n}: Pick<\n ReducerState,\n 'contentLoading' | 'content' | 'activeSyncState'\n>): ContentStateTypes {\n // we have nothing to display yet\n if (contentLoading) {\n return 'CHECKING';\n }\n\n // the build is ready, but it triggered a content reload and the content variable is not trusted\n if (activeSyncState === 'BUILD_READY_RELOAD') {\n return 'CHECKING';\n }\n\n // there is no content, but the sync process is still evaluating\n if (!content && activeSyncState === 'CHECKING') {\n return 'CHECKING';\n }\n\n // there is no content yet so we assume that we are building it for the first time\n if (!content && activeSyncState === 'BUILDING') {\n return 'INITIAL_BUILD';\n }\n\n // if there is still no content after building, it might just not exist\n if (!content) {\n return 'CONTENT_NOT_FOUND';\n }\n\n // we are still building, but we already show stale content\n if (activeSyncState === 'BUILDING') {\n return 'CONTENT_STALE_REFRESHING';\n }\n\n // the build is ready, but the content is still stale\n if (activeSyncState === 'BUILD_READY') {\n return 'CONTENT_STALE_READY';\n }\n\n // the build failed, but the content is still stale\n if (activeSyncState === 'ERROR') {\n return 'CONTENT_STALE_ERROR';\n }\n\n // seems like the content is up-to-date (or we don't know yet and the sync process is still evaluating in the background)\n return 'CONTENT_FRESH';\n}\n\n/**\n * The state of the synchronization task. It checks whether the docs are\n * up-to-date. If they aren't, it triggers a build.\n */\ntype SyncStates =\n /** Checking if it should be synced */\n | 'CHECKING'\n\n /** Building the documentation */\n | 'BUILDING'\n\n /** Finished building the documentation */\n | 'BUILD_READY'\n\n /**\n * Finished building the documentation and triggered a content reload.\n * This state is left toward UP_TO_DATE when the content loading has finished.\n */\n | 'BUILD_READY_RELOAD'\n\n /** No need for a sync. The content was already up-to-date. */\n | 'UP_TO_DATE'\n\n /** An error occurred */\n | 'ERROR';\n\ntype ReducerActions =\n | {\n type: 'sync';\n state: SyncStates;\n syncError?: Error;\n }\n | { type: 'contentLoading' }\n | {\n type: 'content';\n path?: string;\n content?: string;\n contentError?: Error;\n }\n | { type: 'buildLog'; log: string };\n\ntype ReducerState = {\n /**\n * The path of the current page\n */\n path: string;\n\n /**\n * The current sync state\n */\n activeSyncState: SyncStates;\n\n /**\n * If true, the content is downloading from the storage.\n */\n contentLoading: boolean;\n /**\n * The content that has been downloaded and should be displayed.\n */\n content?: string;\n\n contentError?: Error;\n syncError?: Error;\n\n /**\n * A list of log messages that were emitted by the build process.\n */\n buildLog: string[];\n};\n\nexport function reducer(\n oldState: ReducerState,\n action: ReducerActions,\n): ReducerState {\n const newState = { ...oldState };\n\n switch (action.type) {\n case 'sync':\n // reset the build log when a new check starts\n if (action.state === 'CHECKING') {\n newState.buildLog = [];\n }\n\n newState.activeSyncState = action.state;\n newState.syncError = action.syncError;\n break;\n\n case 'contentLoading':\n newState.contentLoading = true;\n\n // only reset errors but keep the old content until it is replaced by the 'content' action\n newState.contentError = undefined;\n break;\n\n case 'content':\n // only override the path if it is part of the action\n if (typeof action.path === 'string') {\n newState.path = action.path;\n }\n\n newState.contentLoading = false;\n newState.content = action.content;\n newState.contentError = action.contentError;\n break;\n\n case 'buildLog':\n newState.buildLog = newState.buildLog.concat(action.log);\n break;\n\n default:\n throw new Error();\n }\n\n // a content update loads fresh content so the build is updated to being up-to-date\n if (\n ['BUILD_READY', 'BUILD_READY_RELOAD'].includes(newState.activeSyncState) &&\n ['contentLoading', 'content'].includes(action.type)\n ) {\n newState.activeSyncState = 'UP_TO_DATE';\n newState.buildLog = [];\n }\n\n return newState;\n}\n/**\n * @public shared reader state\n */\nexport type ReaderState = {\n state: ContentStateTypes;\n path: string;\n contentReload: () => void;\n content?: string;\n contentErrorMessage?: string;\n syncErrorMessage?: string;\n buildLog: string[];\n};\n\nexport function useReaderState(\n kind: string,\n namespace: string,\n name: string,\n path: string,\n): ReaderState {\n const [state, dispatch] = useReducer(reducer, {\n activeSyncState: 'CHECKING',\n path,\n contentLoading: true,\n buildLog: [],\n });\n\n const techdocsStorageApi = useApi(techdocsStorageApiRef);\n\n // try to load the content. the function will fire events and we don't care for the return values\n const { retry: contentReload } = useAsyncRetry(async () => {\n dispatch({ type: 'contentLoading' });\n\n try {\n const entityDocs = await techdocsStorageApi.getEntityDocs(\n { kind, namespace, name },\n path,\n );\n\n // update content and path at the same time\n dispatch({ type: 'content', content: entityDocs, path });\n\n return entityDocs;\n } catch (e) {\n dispatch({ type: 'content', contentError: e, path });\n }\n\n return undefined;\n }, [techdocsStorageApi, kind, namespace, name, path]);\n\n // create a ref that holds the latest content. This provides a useAsync hook\n // with the latest content without restarting the useAsync hook.\n const contentRef = useRef<{ content?: string; reload: () => void }>({\n content: undefined,\n reload: () => {},\n });\n contentRef.current = { content: state.content, reload: contentReload };\n\n // try to derive the state. the function will fire events and we don't care for the return values\n useAsync(async () => {\n dispatch({ type: 'sync', state: 'CHECKING' });\n\n // should only switch to BUILDING if the request takes more than 1 seconds\n const buildingTimeout = setTimeout(() => {\n dispatch({ type: 'sync', state: 'BUILDING' });\n }, 1000);\n\n try {\n const result = await techdocsStorageApi.syncEntityDocs(\n {\n kind,\n namespace,\n name,\n },\n log => {\n dispatch({ type: 'buildLog', log });\n },\n );\n\n switch (result) {\n case 'updated':\n // if there was no content prior to building, retry the loading\n if (!contentRef.current.content) {\n contentRef.current.reload();\n dispatch({ type: 'sync', state: 'BUILD_READY_RELOAD' });\n } else {\n dispatch({ type: 'sync', state: 'BUILD_READY' });\n }\n break;\n case 'cached':\n dispatch({ type: 'sync', state: 'UP_TO_DATE' });\n break;\n\n default:\n dispatch({\n type: 'sync',\n state: 'ERROR',\n syncError: new Error('Unexpected return state'),\n });\n break;\n }\n } catch (e) {\n dispatch({ type: 'sync', state: 'ERROR', syncError: e });\n } finally {\n // Cancel the timer that sets the state \"BUILDING\"\n clearTimeout(buildingTimeout);\n }\n }, [kind, name, namespace, techdocsStorageApi, dispatch, contentRef]);\n\n const displayState = useMemo(\n () =>\n calculateDisplayState({\n activeSyncState: state.activeSyncState,\n contentLoading: state.contentLoading,\n content: state.content,\n }),\n [state.activeSyncState, state.content, state.contentLoading],\n );\n\n return useMemo(\n () => ({\n state: displayState,\n contentReload,\n path: state.path,\n content: state.content,\n contentErrorMessage: state.contentError?.toString(),\n syncErrorMessage: state.syncError?.toString(),\n buildLog: state.buildLog,\n }),\n [\n displayState,\n contentReload,\n state.path,\n state.content,\n state.contentError,\n state.syncError,\n state.buildLog,\n ],\n );\n}\n"],"names":[],"mappings":";;;;;;AAmDO,SAAS,qBAAA,CAAsB;AAAA,EACpC,cAAA;AAAA,EACA,OAAA;AAAA,EACA;AACF,CAAA,EAGsB;AAEpB,EAAA,IAAI,cAAA,EAAgB;AAClB,IAAA,OAAO,UAAA;AAAA,EACT;AAGA,EAAA,IAAI,oBAAoB,oBAAA,EAAsB;AAC5C,IAAA,OAAO,UAAA;AAAA,EACT;AAGA,EAAA,IAAI,CAAC,OAAA,IAAW,eAAA,KAAoB,UAAA,EAAY;AAC9C,IAAA,OAAO,UAAA;AAAA,EACT;AAGA,EAAA,IAAI,CAAC,OAAA,IAAW,eAAA,KAAoB,UAAA,EAAY;AAC9C,IAAA,OAAO,eAAA;AAAA,EACT;AAGA,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,OAAO,mBAAA;AAAA,EACT;A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N,KAAA,CAAM;AAAA;AACR,GACF;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addBaseUrl.esm.js","sources":["../../../src/reader/transformers/addBaseUrl.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { CompoundEntityRef } from '@backstage/catalog-model';\nimport { TechDocsStorageApi } from '../../api';\nimport type { Transformer } from './transformer';\n\ntype AddBaseUrlOptions = {\n techdocsStorageApi: TechDocsStorageApi;\n entityId: CompoundEntityRef;\n path: string;\n};\n\n/**\n * TechDocs backend serves SVGs with text/plain content-type for security. This\n * helper determines if an SVG is being loaded from the backend, and thus needs\n * inlining to be displayed properly.\n */\nconst isSvgNeedingInlining = (\n attrName: string,\n attrVal: string,\n apiOrigin: string,\n) => {\n // Let's let the URL object do automatic parsing of the pathname for us\n const pathname = new URL(attrVal, 'https://ignored.com').pathname;\n const isSrcToSvg = attrName === 'src' && pathname.endsWith('.svg');\n\n const isRelativeUrl = !attrVal.match(/^([a-z]*:)?\\/\\//i);\n const pointsToOurBackend = attrVal.startsWith(apiOrigin);\n return isSrcToSvg && (isRelativeUrl || pointsToOurBackend);\n};\n\nexport const addBaseUrl = ({\n techdocsStorageApi,\n entityId,\n path,\n}: AddBaseUrlOptions): Transformer => {\n return async dom => {\n const apiOrigin = await techdocsStorageApi.getApiOrigin();\n\n const updateDom = async <T extends Element>(\n list: HTMLCollectionOf<T> | NodeListOf<T>,\n attributeName: string,\n ) => {\n for (const elem of list) {\n if (elem.hasAttribute(attributeName)) {\n const elemAttribute = elem.getAttribute(attributeName);\n if (!elemAttribute) return;\n\n // Special handling for SVG images.\n const newValue = await techdocsStorageApi.getBaseUrl(\n elemAttribute,\n entityId,\n path,\n );\n\n if (isSvgNeedingInlining(attributeName, elemAttribute, apiOrigin)) {\n try {\n const svg = await fetch(newValue, { credentials: 'include' });\n const svgContent = await svg.text();\n elem.setAttribute(\n attributeName,\n `data:image/svg+xml;base64,${btoa(\n unescape(encodeURIComponent(svgContent)),\n )}`,\n );\n } catch (e) {\n elem.setAttribute('alt', `Error: ${elemAttribute}`);\n }\n } else {\n elem.setAttribute(attributeName, newValue);\n }\n }\n }\n };\n\n await Promise.all([\n updateDom<HTMLImageElement>(dom.querySelectorAll('img'), 'src'),\n updateDom<HTMLScriptElement>(dom.querySelectorAll('script'), 'src'),\n updateDom<HTMLSourceElement>(dom.querySelectorAll('source'), 'src'),\n updateDom<HTMLLinkElement>(dom.querySelectorAll('link'), 'href'),\n updateDom<HTMLAnchorElement>(dom.querySelectorAll('a[download]'), 'href'),\n ]);\n\n return dom;\n };\n};\n"],"names":[],"mappings":"AA8BA,MAAM,
|
|
1
|
+
{"version":3,"file":"addBaseUrl.esm.js","sources":["../../../src/reader/transformers/addBaseUrl.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { CompoundEntityRef } from '@backstage/catalog-model';\nimport { TechDocsStorageApi } from '../../api';\nimport type { Transformer } from './transformer';\n\ntype AddBaseUrlOptions = {\n techdocsStorageApi: TechDocsStorageApi;\n entityId: CompoundEntityRef;\n path: string;\n};\n\n/**\n * TechDocs backend serves SVGs with text/plain content-type for security. This\n * helper determines if an SVG is being loaded from the backend, and thus needs\n * inlining to be displayed properly.\n */\nconst isSvgNeedingInlining = (\n attrName: string,\n attrVal: string,\n apiOrigin: string,\n) => {\n // Let's let the URL object do automatic parsing of the pathname for us\n const pathname = new URL(attrVal, 'https://ignored.com').pathname;\n const isSrcToSvg = attrName === 'src' && pathname.endsWith('.svg');\n\n const isRelativeUrl = !attrVal.match(/^([a-z]*:)?\\/\\//i);\n const pointsToOurBackend = attrVal.startsWith(apiOrigin);\n return isSrcToSvg && (isRelativeUrl || pointsToOurBackend);\n};\n\nexport const addBaseUrl = ({\n techdocsStorageApi,\n entityId,\n path,\n}: AddBaseUrlOptions): Transformer => {\n return async dom => {\n const apiOrigin = await techdocsStorageApi.getApiOrigin();\n\n const updateDom = async <T extends Element>(\n list: HTMLCollectionOf<T> | NodeListOf<T>,\n attributeName: string,\n ) => {\n for (const elem of list) {\n if (elem.hasAttribute(attributeName)) {\n const elemAttribute = elem.getAttribute(attributeName);\n if (!elemAttribute) return;\n\n // Special handling for SVG images.\n const newValue = await techdocsStorageApi.getBaseUrl(\n elemAttribute,\n entityId,\n path,\n );\n\n if (isSvgNeedingInlining(attributeName, elemAttribute, apiOrigin)) {\n try {\n const svg = await fetch(newValue, { credentials: 'include' });\n const svgContent = await svg.text();\n elem.setAttribute(\n attributeName,\n `data:image/svg+xml;base64,${btoa(\n unescape(encodeURIComponent(svgContent)),\n )}`,\n );\n } catch (e) {\n elem.setAttribute('alt', `Error: ${elemAttribute}`);\n }\n } else {\n elem.setAttribute(attributeName, newValue);\n }\n }\n }\n };\n\n await Promise.all([\n updateDom<HTMLImageElement>(dom.querySelectorAll('img'), 'src'),\n updateDom<HTMLScriptElement>(dom.querySelectorAll('script'), 'src'),\n updateDom<HTMLSourceElement>(dom.querySelectorAll('source'), 'src'),\n updateDom<HTMLLinkElement>(dom.querySelectorAll('link'), 'href'),\n updateDom<HTMLAnchorElement>(dom.querySelectorAll('a[download]'), 'href'),\n ]);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MAAM,UAAA,GAAa,MAAM,GAAA,CAAI,IAAA,EAAK;AAClC,cAAA,IAAA,CAAK,YAAA;AAAA,gBACH,aAAA;AAAA,gBACA,CAAA,0BAAA,EAA6B,IAAA;AAAA,kBAC3B,QAAA,CAAS,kBAAA,CAAmB,UAAU,CAAC;AAAA,iBACxC,CAAA;AAAA,eACH;AAAA,YACF,SAAS,CAAA,EAAG;AACV,cAAA,IAAA,CAAK,YAAA,CAAa,KAAA,EAAO,CAAA,OAAA,EAAU,aAAa,CAAA,CAAE,CAAA;AAAA,YACpD;AAAA,UACF,CAAA,MAAO;AACL,YAAA,IAAA,CAAK,YAAA,CAAa,eAAe,QAAQ,CAAA;AAAA,UAC3C;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAA;AAEA,IAAA,MAAM,QAAQ,GAAA,CAAI;AAAA,MAChB,SAAA,CAA4B,GAAA,CAAI,gBAAA,CAAiB,KAAK,GAAG,KAAK,CAAA;AAAA,MAC9D,SAAA,CAA6B,GAAA,CAAI,gBAAA,CAAiB,QAAQ,GAAG,KAAK,CAAA;AAAA,MAClE,SAAA,CAA6B,GAAA,CAAI,gBAAA,CAAiB,QAAQ,GAAG,KAAK,CAAA;AAAA,MAClE,SAAA,CAA2B,GAAA,CAAI,gBAAA,CAAiB,MAAM,GAAG,MAAM,CAAA;AAAA,MAC/D,SAAA,CAA6B,GAAA,CAAI,gBAAA,CAAiB,aAAa,GAAG,MAAM;AAAA,KACzE,CAAA;AAED,IAAA,OAAO,GAAA;AAAA,EACT,CAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addGitFeedbackLink.esm.js","sources":["../../../src/reader/transformers/addGitFeedbackLink.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Transformer } from './transformer';\nimport {\n replaceGithubUrlType,\n ScmIntegrationRegistry,\n} from '@backstage/integration';\nimport FeedbackOutlinedIcon from '@material-ui/icons/FeedbackOutlined';\nimport { createElement } from 'react';\nimport parseGitUrl from 'git-url-parse';\nimport { renderReactElement } from './renderReactElement';\n\n// requires repo\nexport const addGitFeedbackLink = (\n scmIntegrationsApi: ScmIntegrationRegistry,\n): Transformer => {\n return dom => {\n // attempting to use selectors that are more likely to be static as MkDocs updates over time\n const sourceAnchor = dom.querySelector(\n '[title=\"Edit this page\"]',\n ) as HTMLAnchorElement;\n\n // don't show if edit link not available in raw page\n if (!sourceAnchor || !sourceAnchor.href) {\n return dom;\n }\n\n const sourceURL = new URL(sourceAnchor.href);\n const integration = scmIntegrationsApi.byUrl(sourceURL);\n\n // don't show if can't identify edit link hostname as a gitlab/github hosting\n if (integration?.type !== 'github' && integration?.type !== 'gitlab') {\n return dom;\n }\n\n // topmost h1 only contains title for whole page\n const title =\n (dom.querySelector('article>h1') as HTMLElement)?.childNodes[0]\n .textContent || '';\n const issueTitle = encodeURIComponent(`Documentation Feedback: ${title}`);\n const issueDesc = encodeURIComponent(\n `Page source:\\n${sourceAnchor.href}\\n\\nFeedback:`,\n );\n\n // Convert GitHub edit url to blob type so it can be parsed by git-url-parse correctly\n const gitUrl =\n integration?.type === 'github'\n ? replaceGithubUrlType(sourceURL.href, 'blob')\n : sourceURL.href;\n const gitInfo = parseGitUrl(gitUrl);\n const repoPath = `/${gitInfo.organization}/${gitInfo.name}`;\n\n const feedbackLink = sourceAnchor.cloneNode() as HTMLAnchorElement;\n switch (integration?.type) {\n case 'gitlab':\n feedbackLink.href = `${sourceURL.origin}${repoPath}/issues/new?issue[title]=${issueTitle}&issue[description]=${issueDesc}`;\n break;\n case 'github':\n feedbackLink.href = `${sourceURL.origin}${repoPath}/issues/new?title=${issueTitle}&body=${issueDesc}`;\n break;\n default:\n return dom;\n }\n renderReactElement(createElement(FeedbackOutlinedIcon), feedbackLink);\n feedbackLink.style.paddingLeft = '5px';\n feedbackLink.title = 'Leave feedback for this page';\n feedbackLink.id = 'git-feedback-link';\n sourceAnchor?.insertAdjacentElement('beforebegin', feedbackLink);\n return dom;\n };\n};\n"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"addGitFeedbackLink.esm.js","sources":["../../../src/reader/transformers/addGitFeedbackLink.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Transformer } from './transformer';\nimport {\n replaceGithubUrlType,\n ScmIntegrationRegistry,\n} from '@backstage/integration';\nimport FeedbackOutlinedIcon from '@material-ui/icons/FeedbackOutlined';\nimport { createElement } from 'react';\nimport parseGitUrl from 'git-url-parse';\nimport { renderReactElement } from './renderReactElement';\n\n// requires repo\nexport const addGitFeedbackLink = (\n scmIntegrationsApi: ScmIntegrationRegistry,\n): Transformer => {\n return dom => {\n // attempting to use selectors that are more likely to be static as MkDocs updates over time\n const sourceAnchor = dom.querySelector(\n '[title=\"Edit this page\"]',\n ) as HTMLAnchorElement;\n\n // don't show if edit link not available in raw page\n if (!sourceAnchor || !sourceAnchor.href) {\n return dom;\n }\n\n const sourceURL = new URL(sourceAnchor.href);\n const integration = scmIntegrationsApi.byUrl(sourceURL);\n\n // don't show if can't identify edit link hostname as a gitlab/github hosting\n if (integration?.type !== 'github' && integration?.type !== 'gitlab') {\n return dom;\n }\n\n // topmost h1 only contains title for whole page\n const title =\n (dom.querySelector('article>h1') as HTMLElement)?.childNodes[0]\n .textContent || '';\n const issueTitle = encodeURIComponent(`Documentation Feedback: ${title}`);\n const issueDesc = encodeURIComponent(\n `Page source:\\n${sourceAnchor.href}\\n\\nFeedback:`,\n );\n\n // Convert GitHub edit url to blob type so it can be parsed by git-url-parse correctly\n const gitUrl =\n integration?.type === 'github'\n ? replaceGithubUrlType(sourceURL.href, 'blob')\n : sourceURL.href;\n const gitInfo = parseGitUrl(gitUrl);\n const repoPath = `/${gitInfo.organization}/${gitInfo.name}`;\n\n const feedbackLink = sourceAnchor.cloneNode() as HTMLAnchorElement;\n switch (integration?.type) {\n case 'gitlab':\n feedbackLink.href = `${sourceURL.origin}${repoPath}/issues/new?issue[title]=${issueTitle}&issue[description]=${issueDesc}`;\n break;\n case 'github':\n feedbackLink.href = `${sourceURL.origin}${repoPath}/issues/new?title=${issueTitle}&body=${issueDesc}`;\n break;\n default:\n return dom;\n }\n renderReactElement(createElement(FeedbackOutlinedIcon), feedbackLink);\n feedbackLink.style.paddingLeft = '5px';\n feedbackLink.title = 'Leave feedback for this page';\n feedbackLink.id = 'git-feedback-link';\n sourceAnchor?.insertAdjacentElement('beforebegin', feedbackLink);\n return dom;\n };\n};\n"],"names":[],"mappings":";;;;;;AA2BO,MAAM,kBAAA,GAAqB,CAChC,kBAAA,KACgB;AAChB,EAAA,OAAO,CAAA,GAAA,KAAO;AAEZ,IAAA,MAAM,eAAe,GAAA,CAAI,aAAA;AAAA,MACvB;AAAA,KACF;AAGA,IAAA,IAAI,CAAC,YAAA,IAAgB,CAAC,YAAA,CAAa,IAAA,EAAM;AACvC,MAAA,OAAO,GAAA;AAAA,IACT;AAEA,IAAA,MAAM,SAAA,GAAY,IAAI,GAAA,CAAI,YAAA,CAAa,IAAI,CAAA;AAC3C,IAAA,MAAM,WAAA,GAAc,kBAAA,CAAmB,KAAA,CAAM,SAAS,CAAA;AAGtD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ACpE,IAAA,YAAA,CAAa,MAAM,WAAA,GAAc,KAAA;AACjC,IAAA,YAAA,CAAa,KAAA,GAAQ,8BAAA;AACrB,IAAA,YAAA,CAAa,EAAA,GAAK,mBAAA;AAClB,IAAA,YAAA,EAAc,qBAAA,CAAsB,eAAe,YAAY,CAAA;AAC/D,IAAA,OAAO,GAAA;AAAA,EACT,CAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addLinkClickListener.esm.js","sources":["../../../src/reader/transformers/addLinkClickListener.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Transformer } from './transformer';\n\ntype AddLinkClickListenerOptions = {\n baseUrl: string;\n onClick: (e: MouseEvent, newUrl: string) => void;\n};\n\nexport const addLinkClickListener = ({\n baseUrl,\n onClick,\n}: AddLinkClickListenerOptions): Transformer => {\n return dom => {\n Array.from(dom.getElementsByTagName('a')).forEach(elem => {\n elem.addEventListener('click', (e: MouseEvent) => {\n const target = elem as HTMLAnchorElement;\n const href = target.getAttribute('href');\n\n if (!href) return;\n if (href.startsWith(baseUrl) && !elem.hasAttribute('download')) {\n e.preventDefault();\n onClick(e, href);\n }\n });\n });\n\n return dom;\n };\n};\n"],"names":[],"mappings":"AAuBO,MAAM,uBAAuB,CAAC;AAAA,EACnC,OAAA;AAAA,EACA;AACF,
|
|
1
|
+
{"version":3,"file":"addLinkClickListener.esm.js","sources":["../../../src/reader/transformers/addLinkClickListener.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Transformer } from './transformer';\n\ntype AddLinkClickListenerOptions = {\n baseUrl: string;\n onClick: (e: MouseEvent, newUrl: string) => void;\n};\n\nexport const addLinkClickListener = ({\n baseUrl,\n onClick,\n}: AddLinkClickListenerOptions): Transformer => {\n return dom => {\n Array.from(dom.getElementsByTagName('a')).forEach(elem => {\n elem.addEventListener('click', (e: MouseEvent) => {\n const target = elem as HTMLAnchorElement;\n const href = target.getAttribute('href');\n\n if (!href) return;\n if (href.startsWith(baseUrl) && !elem.hasAttribute('download')) {\n e.preventDefault();\n onClick(e, href);\n }\n });\n });\n\n return dom;\n };\n};\n"],"names":[],"mappings":"AAuBO,MAAM,uBAAuB,CAAC;AAAA,EACnC,OAAA;AAAA,EACA;AACF,CAAA,KAAgD;AAC9C,EAAA,OAAO,CAAA,GAAA,KAAO;AACZ,IAAA,KAAA,CAAM,KAAK,GAAA,CAAI,oBAAA,CAAqB,GAAG,CAAC,CAAA,CAAE,QAAQ,CAAA,IAAA,KAAQ;AACxD,MAAA,IAAA,CAAK,gBAAA,CAAiB,OAAA,EAAS,CAAC,CAAA,KAAkB;AAChD,QAAA,MAAM,MAAA,GAAS,IAAA;AACf,QAAA,MAAM,IAAA,GAAO,MAAA,CAAO,YAAA,CAAa,MAAM,CAAA;AAEvC,QAAA,IAAI,CAAC,IAAA,EAAM;AACX,QAAA,IAAI,IAAA,CAAK,WAAW,OAAO,CAAA,IAAK,CAAC,IAAA,CAAK,YAAA,CAAa,UAAU,CAAA,EAAG;AAC9D,UAAA,CAAA,CAAE,cAAA,EAAe;AACjB,UAAA,OAAA,CAAQ,GAAG,IAAI,CAAA;AAAA,QACjB;AAAA,MACF,CAAC,CAAA;AAAA,IACH,CAAC,CAAA;AAED,IAAA,OAAO,GAAA;AAAA,EACT,CAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addNavLinkKeyboardToggle.esm.js","sources":["../../../src/reader/transformers/addNavLinkKeyboardToggle.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport function addNavLinkKeyboardToggle() {\n return (element: Element) => {\n const navLabels = element.querySelectorAll('label.md-nav__link[for]');\n navLabels.forEach(label => {\n label.setAttribute('tabIndex', '0');\n label.addEventListener('keydown', event => {\n const keyboardEvent = event as KeyboardEvent;\n if (keyboardEvent.key === 'Enter' || keyboardEvent.key === ' ') {\n const forId = label.getAttribute('for');\n if (!forId) return;\n const checkbox = element.querySelector(\n `#${forId}`,\n ) as HTMLInputElement | null;\n if (checkbox && checkbox.type === 'checkbox') {\n checkbox.checked = !checkbox.checked;\n checkbox.dispatchEvent(new Event('change', { bubbles: true }));\n event.preventDefault();\n event.stopPropagation();\n }\n }\n });\n });\n return element;\n };\n}\n"],"names":[],"mappings":"AAgBO,SAAS,
|
|
1
|
+
{"version":3,"file":"addNavLinkKeyboardToggle.esm.js","sources":["../../../src/reader/transformers/addNavLinkKeyboardToggle.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport function addNavLinkKeyboardToggle() {\n return (element: Element) => {\n const navLabels = element.querySelectorAll('label.md-nav__link[for]');\n navLabels.forEach(label => {\n label.setAttribute('tabIndex', '0');\n label.addEventListener('keydown', event => {\n const keyboardEvent = event as KeyboardEvent;\n if (keyboardEvent.key === 'Enter' || keyboardEvent.key === ' ') {\n const forId = label.getAttribute('for');\n if (!forId) return;\n const checkbox = element.querySelector(\n `#${forId}`,\n ) as HTMLInputElement | null;\n if (checkbox && checkbox.type === 'checkbox') {\n checkbox.checked = !checkbox.checked;\n checkbox.dispatchEvent(new Event('change', { bubbles: true }));\n event.preventDefault();\n event.stopPropagation();\n }\n }\n });\n });\n return element;\n };\n}\n"],"names":[],"mappings":"AAgBO,SAAS,wBAAA,GAA2B;AACzC,EAAA,OAAO,CAAC,OAAA,KAAqB;AAC3B,IAAA,MAAM,SAAA,GAAY,OAAA,CAAQ,gBAAA,CAAiB,yBAAyB,CAAA;AACpE,IAAA,SAAA,CAAU,QAAQ,CAAA,KAAA,KAAS;AACzB,MAAA,KAAA,CAAM,YAAA,CAAa,YAAY,GAAG,CAAA;AAClC,MAAA,KAAA,CAAM,gBAAA,CAAiB,WAAW,CAAA,KAAA,KAAS;AACzC,QAAA,MAAM,aAAA,GAAgB,KAAA;AACtB,QAAA,IAAI,aAAA,CAAc,GAAA,KAAQ,OAAA,IAAW,aAAA,CAAc,QAAQ,GAAA,EAAK;AAC9D,UAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,YAAA,CAAa,KAAK,CAAA;AACtC,UAAA,IAAI,CAAC,KAAA,EAAO;AACZ,UAAA,MAAM,WAAW,OAAA,CAAQ,aAAA;AAAA,YACvB,IAAI,KAAK,CAAA;AAAA,WACX;AACA,UAAA,IAAI,QAAA,IAAY,QAAA,CAAS,IAAA,KAAS,UAAA,EAAY;AAC5C,YAAA,QAAA,CAAS,OAAA,GAAU,CAAC,QAAA,CAAS,OAAA;AAC7B,YAAA,QAAA,CAAS,aAAA,CAAc,IAAI,KAAA,CAAM,QAAA,EAAU,EAAE,OAAA,EAAS,IAAA,EAAM,CAAC,CAAA;AAC7D,YAAA,KAAA,CAAM,cAAA,EAAe;AACrB,YAAA,KAAA,CAAM,eAAA,EAAgB;AAAA,UACxB;AAAA,QACF;AAAA,MACF,CAAC,CAAA;AAAA,IACH,CAAC,CAAA;AACD,IAAA,OAAO,OAAA;AAAA,EACT,CAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addSidebarToggle.esm.js","sources":["../../../src/reader/transformers/addSidebarToggle.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Transformer } from './transformer';\nimport MenuIcon from '@material-ui/icons/Menu';\nimport { createElement } from 'react';\nimport { renderReactElement } from './renderReactElement';\n\nexport const addSidebarToggle = (): Transformer => {\n return dom => {\n // attempting to use selectors that are more likely to be static as MkDocs updates over time\n const mkdocsToggleSidebar = dom.querySelector(\n '.md-header label[for=\"__drawer\"]',\n ) as HTMLLabelElement;\n const article = dom.querySelector('article') as HTMLElement;\n\n // Fail gracefully\n if (!mkdocsToggleSidebar || !article) {\n return dom;\n }\n\n const toggleSidebar = mkdocsToggleSidebar.cloneNode() as HTMLLabelElement;\n renderReactElement(createElement(MenuIcon), toggleSidebar);\n toggleSidebar.id = 'toggle-sidebar';\n toggleSidebar.title = 'Toggle Sidebar';\n toggleSidebar.classList.add('md-content__button');\n toggleSidebar.style.setProperty('padding', '0 0 0 5px');\n toggleSidebar.style.setProperty('margin', '0.4rem 0 0.4rem 0.4rem');\n article?.prepend(toggleSidebar);\n return dom;\n };\n};\n"],"names":[],"mappings":";;;;AAqBO,MAAM,mBAAmB,MAAmB;AACjD,EAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"addSidebarToggle.esm.js","sources":["../../../src/reader/transformers/addSidebarToggle.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Transformer } from './transformer';\nimport MenuIcon from '@material-ui/icons/Menu';\nimport { createElement } from 'react';\nimport { renderReactElement } from './renderReactElement';\n\nexport const addSidebarToggle = (): Transformer => {\n return dom => {\n // attempting to use selectors that are more likely to be static as MkDocs updates over time\n const mkdocsToggleSidebar = dom.querySelector(\n '.md-header label[for=\"__drawer\"]',\n ) as HTMLLabelElement;\n const article = dom.querySelector('article') as HTMLElement;\n\n // Fail gracefully\n if (!mkdocsToggleSidebar || !article) {\n return dom;\n }\n\n const toggleSidebar = mkdocsToggleSidebar.cloneNode() as HTMLLabelElement;\n renderReactElement(createElement(MenuIcon), toggleSidebar);\n toggleSidebar.id = 'toggle-sidebar';\n toggleSidebar.title = 'Toggle Sidebar';\n toggleSidebar.classList.add('md-content__button');\n toggleSidebar.style.setProperty('padding', '0 0 0 5px');\n toggleSidebar.style.setProperty('margin', '0.4rem 0 0.4rem 0.4rem');\n article?.prepend(toggleSidebar);\n return dom;\n };\n};\n"],"names":[],"mappings":";;;;AAqBO,MAAM,mBAAmB,MAAmB;AACjD,EAAA,OAAO,CAAA,GAAA,KAAO;AAEZ,IAAA,MAAM,sBAAsB,GAAA,CAAI,aAAA;AAAA,MAC9B;AAAA,KACF;AACA,IAAA,MAAM,OAAA,GAAU,GAAA,CAAI,aAAA,CAAc,SAAS,CAAA;AAG3C,IAAA,IAAI,CAAC,mBAAA,IAAuB,CAAC,OAAA,EAAS;AACpC,MAAA,OAAO,GAAA;AAAA,IACT;AAEA,IAAA,MAAM,aAAA,GAAgB,oBAAoB,SAAA,EAAU;AACpD,IAAA,kBAAA,CAAmB,aAAA,CAAc,QAAQ,CAAA,EAAG,aAAa,CAAA;AACzD,IAAA,aAAA,CAAc,EAAA,GAAK,gBAAA;AACnB,IAAA,aAAA,CAAc,KAAA,GAAQ,gBAAA;AACtB,IAAA,aAAA,CAAc,SAAA,CAAU,IAAI,oBAAoB,CAAA;AAChD,IAAA,aAAA,CAAc,KAAA,CAAM,WAAA,CAAY,SAAA,EAAW,WAAW,CAAA;AACtD,IAAA,aAAA,CAAc,KAAA,CAAM,WAAA,CAAY,QAAA,EAAU,wBAAwB,CAAA;AAClE,IAAA,OAAA,EAAS,QAAQ,aAAa,CAAA;AAC9B,IAAA,OAAO,GAAA;AAAA,EACT,CAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copyToClipboard.esm.js","sources":["../../../src/reader/transformers/copyToClipboard.tsx"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useState, useCallback } from 'react';\nimport { renderReactElement } from './renderReactElement';\nimport { ThemeProvider } from '@material-ui/core/styles';\nimport SvgIcon from '@material-ui/core/SvgIcon';\nimport Tooltip from '@material-ui/core/Tooltip';\nimport { withStyles, Theme } from '@material-ui/core/styles';\nimport IconButton from '@material-ui/core/IconButton';\nimport type { Transformer } from './transformer';\nimport useCopyToClipboard from 'react-use/esm/useCopyToClipboard';\n\nconst CopyToClipboardTooltip = withStyles(theme => ({\n tooltip: {\n fontSize: 'inherit',\n color: theme.palette.text.primary,\n margin: 0,\n padding: theme.spacing(0.5),\n backgroundColor: 'transparent',\n boxShadow: 'none',\n },\n}))(Tooltip);\n\nconst CopyToClipboardIcon = () => (\n <SvgIcon>\n <path d=\"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z\" />\n </SvgIcon>\n);\n\ntype CopyToClipboardButtonProps = {\n text: string;\n};\n\nconst CopyToClipboardButton = ({ text }: CopyToClipboardButtonProps) => {\n const [open, setOpen] = useState(false);\n const [, copyToClipboard] = useCopyToClipboard();\n\n const handleClick = useCallback(() => {\n copyToClipboard(text);\n setOpen(true);\n }, [text, copyToClipboard]);\n\n const handleClose = useCallback(() => {\n setOpen(false);\n }, [setOpen]);\n\n return (\n <CopyToClipboardTooltip\n title=\"Copied to clipboard\"\n placement=\"left\"\n open={open}\n onClose={handleClose}\n leaveDelay={1000}\n >\n <IconButton\n style={{ position: 'absolute' }}\n className=\"md-clipboard md-icon\"\n onClick={handleClick}\n aria-label=\"Copy to clipboard\"\n >\n <CopyToClipboardIcon />\n </IconButton>\n </CopyToClipboardTooltip>\n );\n};\n\n/**\n * Recreates copy-to-clipboard functionality attached to <code> snippets that\n * is native to mkdocs-material theme.\n */\nexport const copyToClipboard = (theme: Theme): Transformer => {\n return dom => {\n const codes = dom.querySelectorAll('pre > code');\n for (const code of codes) {\n const text = code.textContent || '';\n const container = document.createElement('div');\n code?.parentElement?.prepend(container);\n renderReactElement(\n <ThemeProvider theme={theme}>\n <CopyToClipboardButton text={text} />\n </ThemeProvider>,\n container,\n );\n }\n return dom;\n };\n};\n"],"names":["copyToClipboard"],"mappings":";;;;;;;;;AA0BA,MAAM,sBAAA,GAAyB,WAAW,
|
|
1
|
+
{"version":3,"file":"copyToClipboard.esm.js","sources":["../../../src/reader/transformers/copyToClipboard.tsx"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useState, useCallback } from 'react';\nimport { renderReactElement } from './renderReactElement';\nimport { ThemeProvider } from '@material-ui/core/styles';\nimport SvgIcon from '@material-ui/core/SvgIcon';\nimport Tooltip from '@material-ui/core/Tooltip';\nimport { withStyles, Theme } from '@material-ui/core/styles';\nimport IconButton from '@material-ui/core/IconButton';\nimport type { Transformer } from './transformer';\nimport useCopyToClipboard from 'react-use/esm/useCopyToClipboard';\n\nconst CopyToClipboardTooltip = withStyles(theme => ({\n tooltip: {\n fontSize: 'inherit',\n color: theme.palette.text.primary,\n margin: 0,\n padding: theme.spacing(0.5),\n backgroundColor: 'transparent',\n boxShadow: 'none',\n },\n}))(Tooltip);\n\nconst CopyToClipboardIcon = () => (\n <SvgIcon>\n <path d=\"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z\" />\n </SvgIcon>\n);\n\ntype CopyToClipboardButtonProps = {\n text: string;\n};\n\nconst CopyToClipboardButton = ({ text }: CopyToClipboardButtonProps) => {\n const [open, setOpen] = useState(false);\n const [, copyToClipboard] = useCopyToClipboard();\n\n const handleClick = useCallback(() => {\n copyToClipboard(text);\n setOpen(true);\n }, [text, copyToClipboard]);\n\n const handleClose = useCallback(() => {\n setOpen(false);\n }, [setOpen]);\n\n return (\n <CopyToClipboardTooltip\n title=\"Copied to clipboard\"\n placement=\"left\"\n open={open}\n onClose={handleClose}\n leaveDelay={1000}\n >\n <IconButton\n style={{ position: 'absolute' }}\n className=\"md-clipboard md-icon\"\n onClick={handleClick}\n aria-label=\"Copy to clipboard\"\n >\n <CopyToClipboardIcon />\n </IconButton>\n </CopyToClipboardTooltip>\n );\n};\n\n/**\n * Recreates copy-to-clipboard functionality attached to <code> snippets that\n * is native to mkdocs-material theme.\n */\nexport const copyToClipboard = (theme: Theme): Transformer => {\n return dom => {\n const codes = dom.querySelectorAll('pre > code');\n for (const code of codes) {\n const text = code.textContent || '';\n const container = document.createElement('div');\n code?.parentElement?.prepend(container);\n renderReactElement(\n <ThemeProvider theme={theme}>\n <CopyToClipboardButton text={text} />\n </ThemeProvider>,\n container,\n );\n }\n return dom;\n };\n};\n"],"names":["copyToClipboard"],"mappings":";;;;;;;;;AA0BA,MAAM,sBAAA,GAAyB,WAAW,CAAA,KAAA,MAAU;AAAA,EAClD,OAAA,EAAS;AAAA,IACP,QAAA,EAAU,SAAA;AAAA,IACV,KAAA,EAAO,KAAA,CAAM,OAAA,CAAQ,IAAA,CAAK,OAAA;AAAA,IAC1B,MAAA,EAAQ,CAAA;AAAA,IACR,OAAA,EAAS,KAAA,CAAM,OAAA,CAAQ,GAAG,CAAA;AAAA,IAC1B,eAAA,EAAiB,aAAA;AAAA,IACjB,SAAA,EAAW;AAAA;AAEf,CAAA,CAAE,EAAE,OAAO,CAAA;AAEX,MAAM,mBAAA,GAAsB,sBAC1B,GAAA,CAAC,OAAA,EAAA,EACC,8BAAC,MAAA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MAAM,IAAA,GAAO,KAAK,WAAA,IAAe,EAAA;AACjC,MAAA,MAAM,SAAA,GAAY,QAAA,CAAS,aAAA,CAAc,KAAK,CAAA;AAC9C,MAAA,IAAA,EAAM,aAAA,EAAe,QAAQ,SAAS,CAAA;AACtC,MAAA,kBAAA;AAAA,4BACG,aAAA,EAAA,EAAc,KAAA,EACb,QAAA,kBAAA,GAAA,CAAC,qBAAA,EAAA,EAAsB,MAAY,CAAA,EACrC,CAAA;AAAA,QACA;AAAA,OACF;AAAA,IACF;AACA,IAAA,OAAO,GAAA;AAAA,EACT,CAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleMetaRedirects.esm.js","sources":["../../../src/reader/transformers/handleMetaRedirects.tsx"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Transformer } from './transformer';\nimport { normalizeUrl } from './rewriteDocLinks';\nimport { renderReactElement } from './renderReactElement';\nimport { TechDocsRedirectNotification } from '../components/TechDocsRedirectNotification';\n\nexport const handleMetaRedirects = (\n navigate: (to: string) => void,\n entityName: string,\n): Transformer => {\n const redirectAfterMs = 3000;\n\n const determineRedirectURL = (metaUrl: string) => {\n const normalizedCurrentUrl = normalizeUrl(window.location.href);\n // When creating URL object, if the metaUrl is relative, it will be resolved with base href. If it is absolute, it will replace the base href.\n const absoluteRedirectObj = new URL(metaUrl, normalizedCurrentUrl);\n const isExternalRedirect =\n absoluteRedirectObj.hostname !== window.location.hostname;\n\n if (isExternalRedirect) {\n const currentTechDocPath = window.location.pathname;\n const indexOfSiteHome = currentTechDocPath.indexOf(entityName);\n const siteHomePath = currentTechDocPath.slice(\n 0,\n indexOfSiteHome + entityName.length,\n );\n return new URL(siteHomePath, normalizedCurrentUrl).href;\n }\n return absoluteRedirectObj.href;\n };\n\n return dom => {\n for (const elem of Array.from(dom.querySelectorAll('meta'))) {\n if (elem.getAttribute('http-equiv') === 'refresh') {\n const metaContentParameters = elem\n .getAttribute('content')\n ?.split('url=');\n\n if (!metaContentParameters || metaContentParameters.length < 2) {\n return dom;\n }\n\n const metaUrl = metaContentParameters[1];\n const redirectURL = determineRedirectURL(metaUrl);\n\n // If the current URL is the same as the redirect URL, do not proceed with the redirect.\n if (window.location.href === redirectURL) {\n return dom;\n }\n\n const container = document.createElement('div');\n\n renderReactElement(\n <TechDocsRedirectNotification\n message=\"This TechDocs page is no longer maintained. Will automatically redirect to the designated replacement.\"\n handleButtonClick={() => navigate(redirectURL)}\n autoHideDuration={redirectAfterMs}\n />,\n container,\n );\n document.body.appendChild(container);\n\n setTimeout(() => {\n navigate(redirectURL);\n }, redirectAfterMs);\n\n return dom;\n }\n }\n return dom;\n };\n};\n"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"handleMetaRedirects.esm.js","sources":["../../../src/reader/transformers/handleMetaRedirects.tsx"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Transformer } from './transformer';\nimport { normalizeUrl } from './rewriteDocLinks';\nimport { renderReactElement } from './renderReactElement';\nimport { TechDocsRedirectNotification } from '../components/TechDocsRedirectNotification';\n\nexport const handleMetaRedirects = (\n navigate: (to: string) => void,\n entityName: string,\n): Transformer => {\n const redirectAfterMs = 3000;\n\n const determineRedirectURL = (metaUrl: string) => {\n const normalizedCurrentUrl = normalizeUrl(window.location.href);\n // When creating URL object, if the metaUrl is relative, it will be resolved with base href. If it is absolute, it will replace the base href.\n const absoluteRedirectObj = new URL(metaUrl, normalizedCurrentUrl);\n const isExternalRedirect =\n absoluteRedirectObj.hostname !== window.location.hostname;\n\n if (isExternalRedirect) {\n const currentTechDocPath = window.location.pathname;\n const indexOfSiteHome = currentTechDocPath.indexOf(entityName);\n const siteHomePath = currentTechDocPath.slice(\n 0,\n indexOfSiteHome + entityName.length,\n );\n return new URL(siteHomePath, normalizedCurrentUrl).href;\n }\n return absoluteRedirectObj.href;\n };\n\n return dom => {\n for (const elem of Array.from(dom.querySelectorAll('meta'))) {\n if (elem.getAttribute('http-equiv') === 'refresh') {\n const metaContentParameters = elem\n .getAttribute('content')\n ?.split('url=');\n\n if (!metaContentParameters || metaContentParameters.length < 2) {\n return dom;\n }\n\n const metaUrl = metaContentParameters[1];\n const redirectURL = determineRedirectURL(metaUrl);\n\n // If the current URL is the same as the redirect URL, do not proceed with the redirect.\n if (window.location.href === redirectURL) {\n return dom;\n }\n\n const container = document.createElement('div');\n\n renderReactElement(\n <TechDocsRedirectNotification\n message=\"This TechDocs page is no longer maintained. Will automatically redirect to the designated replacement.\"\n handleButtonClick={() => navigate(redirectURL)}\n autoHideDuration={redirectAfterMs}\n />,\n container,\n );\n document.body.appendChild(container);\n\n setTimeout(() => {\n navigate(redirectURL);\n }, redirectAfterMs);\n\n return dom;\n }\n }\n return dom;\n };\n};\n"],"names":[],"mappings":";;;;;AAqBO,MAAM,mBAAA,GAAsB,CACjC,QAAA,EACA,UAAA,KACgB;AAChB,EAAA,MAAM,eAAA,GAAkB,GAAA;AAExB,EAAA,MAAM,oBAAA,GAAuB,CAAC,OAAA,KAAoB;AAChD,IAAA,MAAM,oBAAA,GAAuB,YAAA,CAAa,MAAA,CAAO,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AM,SAAA,GAAY,QAAA,CAAS,aAAA,CAAc,KAAK,CAAA;AAE9C,QAAA,kBAAA;AAAA,0BACE,GAAA;AAAA,YAAC,4BAAA;AAAA,YAAA;AAAA,cACC,OAAA,EAAQ,wGAAA;AAAA,cACR,iBAAA,EAAmB,MAAM,QAAA,CAAS,WAAW,CAAA;AAAA,cAC7C,gBAAA,EAAkB;AAAA;AAAA,WACpB;AAAA,UACA;AAAA,SACF;AACA,QAAA,QAAA,CAAS,IAAA,CAAK,YAAY,SAAS,CAAA;AAEnC,QAAA,UAAA,CAAW,MAAM;AACf,UAAA,QAAA,CAAS,WAAW,CAAA;AAAA,QACtB,GAAG,eAAe,CAAA;AAElB,QAAA,OAAO,GAAA;AAAA,MACT;AAAA,IACF;AACA,IAAA,OAAO,GAAA;AAAA,EACT,CAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iframes.esm.js","sources":["../../../../../src/reader/transformers/html/hooks/iframes.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Checks whether a node is iframe or not.\n * @param node - can be any element.\n * @returns true when node is iframe.\n */\nconst isIframe = (node: Element) => node.nodeName === 'IFRAME';\n\n/**\n * Checks whether a iframe is safe or not.\n * @param node - is an iframe element.\n * @param hosts - list of allowed hosts.\n * @returns true when iframe is included in hosts.\n */\nconst isSafe = (node: Element, hosts: string[]) => {\n const src = node.getAttribute('src') || '';\n try {\n const { host } = new URL(src);\n return hosts.includes(host);\n } catch {\n return false;\n }\n};\n\n/**\n * Returns a function that removes unsafe iframe nodes.\n * @param node - can be any element.\n * @param hosts - list of allowed hosts.\n */\nexport const removeUnsafeIframes = (hosts: string[]) => (node: Element) => {\n if (isIframe(node) && !isSafe(node, hosts)) {\n node.remove();\n }\n return node;\n};\n"],"names":[],"mappings":"AAqBA,MAAM,
|
|
1
|
+
{"version":3,"file":"iframes.esm.js","sources":["../../../../../src/reader/transformers/html/hooks/iframes.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Checks whether a node is iframe or not.\n * @param node - can be any element.\n * @returns true when node is iframe.\n */\nconst isIframe = (node: Element) => node.nodeName === 'IFRAME';\n\n/**\n * Checks whether a iframe is safe or not.\n * @param node - is an iframe element.\n * @param hosts - list of allowed hosts.\n * @returns true when iframe is included in hosts.\n */\nconst isSafe = (node: Element, hosts: string[]) => {\n const src = node.getAttribute('src') || '';\n try {\n const { host } = new URL(src);\n return hosts.includes(host);\n } catch {\n return false;\n }\n};\n\n/**\n * Returns a function that removes unsafe iframe nodes.\n * @param node - can be any element.\n * @param hosts - list of allowed hosts.\n */\nexport const removeUnsafeIframes = (hosts: string[]) => (node: Element) => {\n if (isIframe(node) && !isSafe(node, hosts)) {\n node.remove();\n }\n return node;\n};\n"],"names":[],"mappings":"AAqBA,MAAM,QAAA,GAAW,CAAC,IAAA,KAAkB,IAAA,CAAK,QAAA,KAAa,QAAA;AAQtD,MAAM,MAAA,GAAS,CAAC,IAAA,EAAe,KAAA,KAAoB;AACjD,EAAA,MAAM,GAAA,GAAM,IAAA,CAAK,YAAA,CAAa,KAAK,CAAA,IAAK,EAAA;AACxC,EAAA,IAAI;AACF,IAAA,MAAM,EAAE,IAAA,EAAK,GAAI,IAAI,IAAI,GAAG,CAAA;AAC5B,IAAA,OAAO,KAAA,CAAM,SAAS,IAAI,CAAA;AAAA,EAC5B,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,KAAA;AAAA,EACT;AACF,CAAA;AAOO,MAAM,mBAAA,GAAsB,CAAC,KAAA,KAAoB,CAAC,IAAA,KAAkB;AACzE,EAAA,IAAI,SAAS,IAAI,CAAA,IAAK,CAAC,MAAA,CAAO,IAAA,EAAM,KAAK,CAAA,EAAG;AAC1C,IAAA,IAAA,CAAK,MAAA,EAAO;AAAA,EACd;AACA,EAAA,OAAO,IAAA;AACT;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"links.esm.js","sources":["../../../../../src/reader/transformers/html/hooks/links.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nconst MKDOCS_CSS = /main\\.[A-Fa-f0-9]{8}\\.min\\.css$/;\nconst GOOGLE_FONTS = /^https:\\/\\/fonts\\.googleapis\\.com/;\nconst GSTATIC_FONTS = /^https:\\/\\/fonts\\.gstatic\\.com/;\n\n/**\n * Checks whether a node is link or not.\n * @param node - can be any element.\n * @returns true when node is link.\n */\nconst isLink = (node: Element) => node.nodeName === 'LINK';\n\n/**\n * Checks whether a link is safe or not.\n * @param node - is an link element.\n * @returns true when link is mkdocs css, google fonts or gstatic fonts.\n */\nconst isSafe = (node: Element) => {\n const href = node?.getAttribute('href') || '';\n const isMkdocsCss = href.match(MKDOCS_CSS);\n const isGoogleFonts = href.match(GOOGLE_FONTS);\n const isGstaticFonts = href.match(GSTATIC_FONTS);\n return isMkdocsCss || isGoogleFonts || isGstaticFonts;\n};\n\n/**\n * Function that removes unsafe link nodes.\n * @param node - can be any element.\n * @param hosts - list of allowed hosts.\n */\nexport const removeUnsafeLinks = (node: Element) => {\n if (isLink(node) && !isSafe(node)) {\n node.remove();\n }\n return node;\n};\n"],"names":[],"mappings":"AAgBA,MAAM,
|
|
1
|
+
{"version":3,"file":"links.esm.js","sources":["../../../../../src/reader/transformers/html/hooks/links.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nconst MKDOCS_CSS = /main\\.[A-Fa-f0-9]{8}\\.min\\.css$/;\nconst GOOGLE_FONTS = /^https:\\/\\/fonts\\.googleapis\\.com/;\nconst GSTATIC_FONTS = /^https:\\/\\/fonts\\.gstatic\\.com/;\n\n/**\n * Checks whether a node is link or not.\n * @param node - can be any element.\n * @returns true when node is link.\n */\nconst isLink = (node: Element) => node.nodeName === 'LINK';\n\n/**\n * Checks whether a link is safe or not.\n * @param node - is an link element.\n * @returns true when link is mkdocs css, google fonts or gstatic fonts.\n */\nconst isSafe = (node: Element) => {\n const href = node?.getAttribute('href') || '';\n const isMkdocsCss = href.match(MKDOCS_CSS);\n const isGoogleFonts = href.match(GOOGLE_FONTS);\n const isGstaticFonts = href.match(GSTATIC_FONTS);\n return isMkdocsCss || isGoogleFonts || isGstaticFonts;\n};\n\n/**\n * Function that removes unsafe link nodes.\n * @param node - can be any element.\n * @param hosts - list of allowed hosts.\n */\nexport const removeUnsafeLinks = (node: Element) => {\n if (isLink(node) && !isSafe(node)) {\n node.remove();\n }\n return node;\n};\n"],"names":[],"mappings":"AAgBA,MAAM,UAAA,GAAa,iCAAA;AACnB,MAAM,YAAA,GAAe,mCAAA;AACrB,MAAM,aAAA,GAAgB,gCAAA;AAOtB,MAAM,MAAA,GAAS,CAAC,IAAA,KAAkB,IAAA,CAAK,QAAA,KAAa,MAAA;AAOpD,MAAM,MAAA,GAAS,CAAC,IAAA,KAAkB;AAChC,EAAA,MAAM,IAAA,GAAO,IAAA,EAAM,YAAA,CAAa,MAAM,CAAA,IAAK,EAAA;AAC3C,EAAA,MAAM,WAAA,GAAc,IAAA,CAAK,KAAA,CAAM,UAAU,CAAA;AACzC,EAAA,MAAM,aAAA,GAAgB,IAAA,CAAK,KAAA,CAAM,YAAY,CAAA;AAC7C,EAAA,MAAM,cAAA,GAAiB,IAAA,CAAK,KAAA,CAAM,aAAa,CAAA;AAC/C,EAAA,OAAO,eAAe,aAAA,IAAiB,cAAA;AACzC,CAAA;AAOO,MAAM,iBAAA,GAAoB,CAAC,IAAA,KAAkB;AAClD,EAAA,IAAI,OAAO,IAAI,CAAA,IAAK,CAAC,MAAA,CAAO,IAAI,CAAA,EAAG;AACjC,IAAA,IAAA,CAAK,MAAA,EAAO;AAAA,EACd;AACA,EAAA,OAAO,IAAA;AACT;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformer.esm.js","sources":["../../../../src/reader/transformers/html/transformer.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport DOMPurify from 'dompurify';\nimport { useCallback, useMemo } from 'react';\n\nimport { configApiRef, useApi } from '@backstage/core-plugin-api';\n\nimport { Transformer } from '../transformer';\nimport { removeUnsafeIframes, removeUnsafeLinks } from './hooks';\n\n/**\n * Returns html sanitizer configuration\n */\nconst useSanitizerConfig = () => {\n const configApi = useApi(configApiRef);\n\n return useMemo(() => {\n return configApi.getOptionalConfig('techdocs.sanitizer');\n }, [configApi]);\n};\n\n/**\n * Returns a transformer that sanitizes the dom\n */\nexport const useSanitizerTransformer = (): Transformer => {\n const config = useSanitizerConfig();\n\n return useCallback(\n async (dom: Element) => {\n const hosts = config?.getOptionalStringArray('allowedIframeHosts');\n\n DOMPurify.addHook('beforeSanitizeElements', removeUnsafeLinks);\n const tags = ['link', 'meta'];\n\n if (hosts) {\n tags.push('iframe');\n DOMPurify.addHook('beforeSanitizeElements', removeUnsafeIframes(hosts));\n }\n\n // Only allow meta tags if they are used for refreshing the page. They are required for the redirect feature.\n DOMPurify.addHook('uponSanitizeElement', (currNode, data) => {\n if (data.tagName === 'meta') {\n const isMetaRefreshTag =\n currNode.getAttribute('http-equiv') === 'refresh' &&\n currNode.getAttribute('content')?.includes('url=');\n if (!isMetaRefreshTag) {\n currNode.parentNode?.removeChild(currNode);\n }\n }\n });\n\n // Only allow http-equiv and content attributes on meta tags. They are required for the redirect feature.\n DOMPurify.addHook('uponSanitizeAttribute', (currNode, data) => {\n if (currNode.tagName !== 'meta') {\n if (data.attrName === 'http-equiv' || data.attrName === 'content') {\n currNode.removeAttribute(data.attrName);\n }\n }\n });\n\n const tagNameCheck = config?.getOptionalString(\n 'allowedCustomElementTagNameRegExp',\n );\n const attributeNameCheck = config?.getOptionalString(\n 'allowedCustomElementAttributeNameRegExp',\n );\n const additionalAllowedURIProtocols =\n config?.getOptionalStringArray('additionalAllowedURIProtocols') || [];\n\n // Define allowed URI protocols, including any additional ones from the config.\n // The default protocols are based on the DOMPurify defaults.\n const allowedURIProtocols = [\n 'callto',\n 'cid',\n 'ftp',\n 'ftps',\n 'http',\n 'https',\n 'mailto',\n 'matrix',\n 'sms',\n 'tel',\n 'xmpp',\n ...additionalAllowedURIProtocols,\n ].filter(Boolean);\n\n const allowedURIRegExp = new RegExp(\n // This regex is not exposed by DOMPurify, so we need to define it ourselves.\n // It is possible for this to drift from the default in future versions of DOMPurify.\n // See: https://raw.githubusercontent.com/cure53/DOMPurify/master/src/regexp.ts\n `^(?:${allowedURIProtocols.join(\n '|',\n )}:|[^a-z]|[a-z+.-]+(?:[^a-z+.\\\\-:]|$))`,\n 'i',\n );\n\n // using outerHTML as we want to preserve the html tag attributes (lang)\n return DOMPurify.sanitize(dom.outerHTML, {\n ADD_TAGS: tags,\n FORBID_TAGS: ['style'],\n ADD_ATTR: ['http-equiv', 'content', 'dominant-baseline'],\n WHOLE_DOCUMENT: true,\n RETURN_DOM: true,\n ALLOWED_URI_REGEXP: allowedURIRegExp,\n CUSTOM_ELEMENT_HANDLING: {\n tagNameCheck: tagNameCheck ? new RegExp(tagNameCheck) : undefined,\n attributeNameCheck: attributeNameCheck\n ? new RegExp(attributeNameCheck)\n : undefined,\n },\n });\n },\n [config],\n );\n};\n"],"names":[],"mappings":";;;;;;AA2BA,MAAM,qBAAqB,MAAM;AAC/B,
|
|
1
|
+
{"version":3,"file":"transformer.esm.js","sources":["../../../../src/reader/transformers/html/transformer.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport DOMPurify from 'dompurify';\nimport { useCallback, useMemo } from 'react';\n\nimport { configApiRef, useApi } from '@backstage/core-plugin-api';\n\nimport { Transformer } from '../transformer';\nimport { removeUnsafeIframes, removeUnsafeLinks } from './hooks';\n\n/**\n * Returns html sanitizer configuration\n */\nconst useSanitizerConfig = () => {\n const configApi = useApi(configApiRef);\n\n return useMemo(() => {\n return configApi.getOptionalConfig('techdocs.sanitizer');\n }, [configApi]);\n};\n\n/**\n * Returns a transformer that sanitizes the dom\n */\nexport const useSanitizerTransformer = (): Transformer => {\n const config = useSanitizerConfig();\n\n return useCallback(\n async (dom: Element) => {\n const hosts = config?.getOptionalStringArray('allowedIframeHosts');\n\n DOMPurify.addHook('beforeSanitizeElements', removeUnsafeLinks);\n const tags = ['link', 'meta'];\n\n if (hosts) {\n tags.push('iframe');\n DOMPurify.addHook('beforeSanitizeElements', removeUnsafeIframes(hosts));\n }\n\n // Only allow meta tags if they are used for refreshing the page. They are required for the redirect feature.\n DOMPurify.addHook('uponSanitizeElement', (currNode, data) => {\n if (data.tagName === 'meta') {\n const isMetaRefreshTag =\n currNode.getAttribute('http-equiv') === 'refresh' &&\n currNode.getAttribute('content')?.includes('url=');\n if (!isMetaRefreshTag) {\n currNode.parentNode?.removeChild(currNode);\n }\n }\n });\n\n // Only allow http-equiv and content attributes on meta tags. They are required for the redirect feature.\n DOMPurify.addHook('uponSanitizeAttribute', (currNode, data) => {\n if (currNode.tagName !== 'meta') {\n if (data.attrName === 'http-equiv' || data.attrName === 'content') {\n currNode.removeAttribute(data.attrName);\n }\n }\n });\n\n const tagNameCheck = config?.getOptionalString(\n 'allowedCustomElementTagNameRegExp',\n );\n const attributeNameCheck = config?.getOptionalString(\n 'allowedCustomElementAttributeNameRegExp',\n );\n const additionalAllowedURIProtocols =\n config?.getOptionalStringArray('additionalAllowedURIProtocols') || [];\n\n // Define allowed URI protocols, including any additional ones from the config.\n // The default protocols are based on the DOMPurify defaults.\n const allowedURIProtocols = [\n 'callto',\n 'cid',\n 'ftp',\n 'ftps',\n 'http',\n 'https',\n 'mailto',\n 'matrix',\n 'sms',\n 'tel',\n 'xmpp',\n ...additionalAllowedURIProtocols,\n ].filter(Boolean);\n\n const allowedURIRegExp = new RegExp(\n // This regex is not exposed by DOMPurify, so we need to define it ourselves.\n // It is possible for this to drift from the default in future versions of DOMPurify.\n // See: https://raw.githubusercontent.com/cure53/DOMPurify/master/src/regexp.ts\n `^(?:${allowedURIProtocols.join(\n '|',\n )}:|[^a-z]|[a-z+.-]+(?:[^a-z+.\\\\-:]|$))`,\n 'i',\n );\n\n // using outerHTML as we want to preserve the html tag attributes (lang)\n return DOMPurify.sanitize(dom.outerHTML, {\n ADD_TAGS: tags,\n FORBID_TAGS: ['style'],\n ADD_ATTR: ['http-equiv', 'content', 'dominant-baseline'],\n WHOLE_DOCUMENT: true,\n RETURN_DOM: true,\n ALLOWED_URI_REGEXP: allowedURIRegExp,\n CUSTOM_ELEMENT_HANDLING: {\n tagNameCheck: tagNameCheck ? new RegExp(tagNameCheck) : undefined,\n attributeNameCheck: attributeNameCheck\n ? new RegExp(attributeNameCheck)\n : undefined,\n },\n });\n },\n [config],\n );\n};\n"],"names":[],"mappings":";;;;;;AA2BA,MAAM,qBAAqB,MAAM;AAC/B,EAAA,MAAM,SAAA,GAAY,OAAO,YAAY,CAAA;AAErC,EAAA,OAAO,QAAQ,MAAM;AACnB,IAAA,OAAO,SAAA,CAAU,kBAAkB,oBAAoB,CAAA;AAAA,EACzD,CAAA,EAAG,CAAC,SAAS,CAAC,CAAA;AAChB,CAAA;AAKO,MAAM,0BAA0B,MAAmB;AACxD,EAAA,MAAM,SAAS,kBAAA,EAAmB;AAElC,EAAA,OAAO,WAAA;AAAA,IACL,OAAO,GAAA,KAAiB;AACtB,MAAA,MAAM,KAAA,GAAQ,MAAA,EAAQ,sBAAA,CAAuB,oBAAoB,CAAA;AAEjE,MAAA,SAAA,CAAU,OAAA,CAAQ,0BAA0B,iBAAiB,CAAA;AAC7D,MAAA,MAAM,IAAA,GAAO,CAAC,MAAA,EAAQ,MAAM,CAAA;AAE5B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,QACA,MAAA;AAAA,QACA,OAAA;AAAA,QACA,QAAA;AAAA,QACA,QAAA;AAAA,QACA,KAAA;AAAA,QACA,KAAA;AAAA,QACA,MAAA;AAAA,QACA,GAAG;AAAA,OACL,CAAE,OAAO,OAAO,CAAA;AAEhB,MAAA,MAAM,mBAAmB,IAAI,MAAA;AAAA;AAAA;AAAA;AAAA,QAI3B,OAAO,mBAAA,CAAoB,IAAA;AAAA,UACzB;AAAA,SACD,CAAA,qCAAA,CAAA;AAAA,QACD;AAAA,OACF;AAGA,MAAA,OAAO,SAAA,CAAU,QAAA,CAAS,GAAA,CAAI,SAAA,EAAW;AAAA,QACvC,QAAA,EAAU,IAAA;AAAA,QACV,WAAA,EAAa,CAAC,OAAO,CAAA;AAAA,QACrB,QAAA,EAAU,CAAC,YAAA,EAAc,SAAA,EAAW,mBAAmB,CAAA;AAAA,QACvD,cAAA,EAAgB,IAAA;AAAA,QAChB,UAAA,EAAY,IAAA;AAAA,QACZ,kBAAA,EAAoB,gBAAA;AAAA,QACpB,uBAAA,EAAyB;AAAA,UACvB,YAAA,EAAc,YAAA,GAAe,IAAI,MAAA,CAAO,YAAY,CAAA,GAAI,MAAA;AAAA,UACxD,kBAAA,EAAoB,kBAAA,GAChB,IAAI,MAAA,CAAO,kBAAkB,CAAA,GAC7B;AAAA;AACN,OACD,CAAA;AAAA,IACH,CAAA;AAAA,IACA,CAAC,MAAM;AAAA,GACT;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onCssReady.esm.js","sources":["../../../src/reader/transformers/onCssReady.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { SHADOW_DOM_STYLE_LOAD_EVENT } from '@backstage/plugin-techdocs-react';\nimport type { Transformer } from './transformer';\n\ntype OnCssReadyOptions = {\n onLoading: () => void;\n onLoaded: () => void;\n};\n\nexport const onCssReady = ({\n onLoading,\n onLoaded,\n}: OnCssReadyOptions): Transformer => {\n return dom => {\n onLoading();\n dom.addEventListener(\n SHADOW_DOM_STYLE_LOAD_EVENT,\n function handleShadowDomStyleLoad() {\n onLoaded();\n dom.removeEventListener(\n SHADOW_DOM_STYLE_LOAD_EVENT,\n handleShadowDomStyleLoad,\n );\n },\n );\n return dom;\n };\n};\n"],"names":[],"mappings":";;AAwBO,MAAM,aAAa,CAAC;AAAA,EACzB,SAAA;AAAA,EACA;AACF,
|
|
1
|
+
{"version":3,"file":"onCssReady.esm.js","sources":["../../../src/reader/transformers/onCssReady.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { SHADOW_DOM_STYLE_LOAD_EVENT } from '@backstage/plugin-techdocs-react';\nimport type { Transformer } from './transformer';\n\ntype OnCssReadyOptions = {\n onLoading: () => void;\n onLoaded: () => void;\n};\n\nexport const onCssReady = ({\n onLoading,\n onLoaded,\n}: OnCssReadyOptions): Transformer => {\n return dom => {\n onLoading();\n dom.addEventListener(\n SHADOW_DOM_STYLE_LOAD_EVENT,\n function handleShadowDomStyleLoad() {\n onLoaded();\n dom.removeEventListener(\n SHADOW_DOM_STYLE_LOAD_EVENT,\n handleShadowDomStyleLoad,\n );\n },\n );\n return dom;\n };\n};\n"],"names":[],"mappings":";;AAwBO,MAAM,aAAa,CAAC;AAAA,EACzB,SAAA;AAAA,EACA;AACF,CAAA,KAAsC;AACpC,EAAA,OAAO,CAAA,GAAA,KAAO;AACZ,IAAA,SAAA,EAAU;AACV,IAAA,GAAA,CAAI,gBAAA;AAAA,MACF,2BAAA;AAAA,MACA,SAAS,wBAAA,GAA2B;AAClC,QAAA,QAAA,EAAS;AACT,QAAA,GAAA,CAAI,mBAAA;AAAA,UACF,2BAAA;AAAA,UACA;AAAA,SACF;AAAA,MACF;AAAA,KACF;AACA,IAAA,OAAO,GAAA;AAAA,EACT,CAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"removeMkdocsHeader.esm.js","sources":["../../../src/reader/transformers/removeMkdocsHeader.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Transformer } from './transformer';\n\nexport const removeMkdocsHeader = (): Transformer => {\n return dom => {\n // Remove the header\n dom.querySelector('.md-header')?.remove();\n\n return dom;\n };\n};\n"],"names":[],"mappings":"AAkBO,MAAM,qBAAqB,MAAmB;AACnD,EAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"removeMkdocsHeader.esm.js","sources":["../../../src/reader/transformers/removeMkdocsHeader.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Transformer } from './transformer';\n\nexport const removeMkdocsHeader = (): Transformer => {\n return dom => {\n // Remove the header\n dom.querySelector('.md-header')?.remove();\n\n return dom;\n };\n};\n"],"names":[],"mappings":"AAkBO,MAAM,qBAAqB,MAAmB;AACnD,EAAA,OAAO,CAAA,GAAA,KAAO;AAEZ,IAAA,GAAA,CAAI,aAAA,CAAc,YAAY,CAAA,EAAG,MAAA,EAAO;AAExC,IAAA,OAAO,GAAA;AAAA,EACT,CAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderReactElement.esm.js","sources":["../../../src/reader/transformers/renderReactElement.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nlet ReactDOMPromise: Promise<\n typeof import('react-dom') | typeof import('react-dom/client')\n>;\nif (process.env.HAS_REACT_DOM_CLIENT) {\n ReactDOMPromise = import('react-dom/client');\n} else {\n ReactDOMPromise = import('react-dom');\n}\n\n/** @internal */\nexport function renderReactElement(element: JSX.Element, root: HTMLElement) {\n ReactDOMPromise.then(ReactDOM => {\n if ('createRoot' in ReactDOM) {\n ReactDOM.createRoot(root).render(element);\n } else {\n ReactDOM.render(element, root);\n }\n });\n}\n"],"names":[],"mappings":"AAgBA,IAAI,eAAA;AAGJ,IAAI,OAAA,CAAQ,IAAI,
|
|
1
|
+
{"version":3,"file":"renderReactElement.esm.js","sources":["../../../src/reader/transformers/renderReactElement.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nlet ReactDOMPromise: Promise<\n typeof import('react-dom') | typeof import('react-dom/client')\n>;\nif (process.env.HAS_REACT_DOM_CLIENT) {\n ReactDOMPromise = import('react-dom/client');\n} else {\n ReactDOMPromise = import('react-dom');\n}\n\n/** @internal */\nexport function renderReactElement(element: JSX.Element, root: HTMLElement) {\n ReactDOMPromise.then(ReactDOM => {\n if ('createRoot' in ReactDOM) {\n ReactDOM.createRoot(root).render(element);\n } else {\n ReactDOM.render(element, root);\n }\n });\n}\n"],"names":[],"mappings":"AAgBA,IAAI,eAAA;AAGJ,IAAI,OAAA,CAAQ,IAAI,oBAAA,EAAsB;AACpC,EAAA,eAAA,GAAkB,OAAO,kBAAkB,CAAA;AAC7C,CAAA,MAAO;AACL,EAAA,eAAA,GAAkB,OAAO,WAAW,CAAA;AACtC;AAGO,SAAS,kBAAA,CAAmB,SAAsB,IAAA,EAAmB;AAC1E,EAAA,eAAA,CAAgB,KAAK,CAAA,QAAA,KAAY;AAC/B,IAAA,IAAI,gBAAgB,QAAA,EAAU;AAC5B,MAAA,QAAA,CAAS,UAAA,CAAW,IAAI,CAAA,CAAE,MAAA,CAAO,OAAO,CAAA;AAAA,IAC1C,CAAA,MAAO;AACL,MAAA,QAAA,CAAS,MAAA,CAAO,SAAS,IAAI,CAAA;AAAA,IAC/B;AAAA,EACF,CAAC,CAAA;AACH;;;;"}
|