Merge branch 'master' of github.com:jonathan-ash/backstage into techdocs-reader-custom-error-page
This commit is contained in:
@@ -1,5 +1,63 @@
|
||||
# @backstage/plugin-techdocs
|
||||
|
||||
## 0.13.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- @backstage/core-components@0.8.8
|
||||
- @backstage/plugin-search@0.6.2
|
||||
- @backstage/plugin-catalog-react@0.6.14
|
||||
- @backstage/plugin-catalog@0.7.12
|
||||
- @backstage/integration-react@0.1.21
|
||||
|
||||
## 0.13.3-next.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- @backstage/core-components@0.8.8-next.0
|
||||
- @backstage/plugin-search@0.6.2-next.0
|
||||
- @backstage/plugin-catalog-react@0.6.14-next.0
|
||||
- @backstage/integration-react@0.1.21-next.0
|
||||
- @backstage/plugin-catalog@0.7.12-next.0
|
||||
|
||||
## 0.13.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 742434a6ba: Fixed a bug where links to files within a TechDocs site that use the `download` attribute would result in a 404 in cases where the TechDocs backend and Backstage frontend application are on the same host.
|
||||
- 359c31e31d: Added support for documentation using the raw `<source>` tag to point to relative resources like audio or video files.
|
||||
- 18317a08db: Fixed a bug where copy-to-clipboard buttons were appended to unintended elements.
|
||||
- Updated dependencies
|
||||
- @backstage/core-components@0.8.7
|
||||
- @backstage/plugin-catalog-react@0.6.13
|
||||
- @backstage/integration-react@0.1.20
|
||||
- @backstage/plugin-catalog@0.7.11
|
||||
- @backstage/plugin-search@0.6.1
|
||||
|
||||
## 0.13.2-next.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 742434a6ba: Fixed a bug where links to files within a TechDocs site that use the `download` attribute would result in a 404 in cases where the TechDocs backend and Backstage frontend application are on the same host.
|
||||
- Updated dependencies
|
||||
- @backstage/core-components@0.8.7-next.1
|
||||
- @backstage/plugin-catalog-react@0.6.13-next.1
|
||||
- @backstage/plugin-catalog@0.7.11-next.1
|
||||
|
||||
## 0.13.2-next.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 359c31e31d: Added support for documentation using the raw `<source>` tag to point to relative resources like audio or video files.
|
||||
- Updated dependencies
|
||||
- @backstage/core-components@0.8.7-next.0
|
||||
- @backstage/integration-react@0.1.20-next.0
|
||||
- @backstage/plugin-catalog@0.7.11-next.0
|
||||
- @backstage/plugin-catalog-react@0.6.13-next.0
|
||||
- @backstage/plugin-search@0.6.1-next.0
|
||||
|
||||
## 0.13.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@backstage/plugin-techdocs",
|
||||
"description": "The Backstage plugin that renders technical documentation for your components",
|
||||
"version": "0.13.1",
|
||||
"version": "0.13.3",
|
||||
"main": "src/index.ts",
|
||||
"types": "src/index.ts",
|
||||
"license": "Apache-2.0",
|
||||
@@ -34,14 +34,14 @@
|
||||
"dependencies": {
|
||||
"@backstage/catalog-model": "^0.9.10",
|
||||
"@backstage/config": "^0.1.13",
|
||||
"@backstage/core-components": "^0.8.6",
|
||||
"@backstage/core-components": "^0.8.8",
|
||||
"@backstage/core-plugin-api": "^0.6.0",
|
||||
"@backstage/errors": "^0.2.0",
|
||||
"@backstage/integration": "^0.7.2",
|
||||
"@backstage/integration-react": "^0.1.19",
|
||||
"@backstage/plugin-catalog": "^0.7.10",
|
||||
"@backstage/plugin-catalog-react": "^0.6.12",
|
||||
"@backstage/plugin-search": "^0.6.0",
|
||||
"@backstage/integration-react": "^0.1.21",
|
||||
"@backstage/plugin-catalog": "^0.7.12",
|
||||
"@backstage/plugin-catalog-react": "^0.6.14",
|
||||
"@backstage/plugin-search": "^0.6.2",
|
||||
"@backstage/theme": "^0.2.14",
|
||||
"@material-ui/core": "^4.12.2",
|
||||
"@material-ui/icons": "^4.9.1",
|
||||
@@ -62,10 +62,10 @@
|
||||
"react-dom": "^16.13.1 || ^17.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@backstage/cli": "^0.13.0",
|
||||
"@backstage/core-app-api": "^0.5.1",
|
||||
"@backstage/dev-utils": "^0.2.19",
|
||||
"@backstage/test-utils": "^0.2.3",
|
||||
"@backstage/cli": "^0.13.2",
|
||||
"@backstage/core-app-api": "^0.5.2",
|
||||
"@backstage/dev-utils": "^0.2.21",
|
||||
"@backstage/test-utils": "^0.2.4",
|
||||
"@testing-library/jest-dom": "^5.10.1",
|
||||
"@testing-library/react": "^11.2.5",
|
||||
"@testing-library/react-hooks": "^7.0.2",
|
||||
@@ -74,7 +74,7 @@
|
||||
"@types/jest": "^26.0.7",
|
||||
"@types/node": "^14.14.32",
|
||||
"canvas": "^2.6.1",
|
||||
"cross-fetch": "^3.0.6",
|
||||
"cross-fetch": "^3.1.5",
|
||||
"msw": "^0.35.0"
|
||||
},
|
||||
"files": [
|
||||
|
||||
@@ -142,6 +142,7 @@ export const useTechDocsReaderDom = (entityRef: EntityName): Element | null => {
|
||||
const techdocsSanitizer = useApi(configApiRef);
|
||||
const { namespace = '', kind = '', name = '' } = entityRef;
|
||||
const { state, path, content: rawPage } = useTechDocsReader();
|
||||
const isDarkTheme = theme.palette.type === 'dark';
|
||||
|
||||
const [sidebars, setSidebars] = useState<HTMLElement[]>();
|
||||
const [dom, setDom] = useState<HTMLElement | null>(null);
|
||||
@@ -219,6 +220,27 @@ export const useTechDocsReaderDom = (entityRef: EntityName): Element | null => {
|
||||
--md-accent-fg-color: ${theme.palette.primary.main};
|
||||
--md-default-fg-color--lightest: ${theme.palette.textVerySubtle};
|
||||
}
|
||||
.codehilite .gd, .highlight .gd {
|
||||
background-color: ${isDarkTheme ? 'rgba(248,81,73,0.65)' : '#fdd'};
|
||||
}
|
||||
.codehilite .gi, .highlight .gi {
|
||||
background-color: ${isDarkTheme ? 'rgba(46,160,67,0.65)' : '#dfd'};
|
||||
}
|
||||
.highlight .kd {
|
||||
color: ${isDarkTheme ? '#4aaaf7' : '#3b78e7'};
|
||||
}
|
||||
.highlight .k {
|
||||
color: ${isDarkTheme ? '#4aaaf7' : '#3b78e7'};
|
||||
}
|
||||
.highlight .nx {
|
||||
color: ${isDarkTheme ? '#ff53a3' : '#ec407a'};
|
||||
}
|
||||
.highlight .s1 {
|
||||
color: ${isDarkTheme ? '#1cad46' : 'rgb(13, 144, 79)'};
|
||||
}
|
||||
.highlight .kt {
|
||||
color: ${isDarkTheme ? '#4aaaf7' : '#3e61a2'};
|
||||
}
|
||||
.md-main__inner { margin-top: 0; }
|
||||
.md-sidebar { position: fixed; bottom: 100px; width: 20rem; }
|
||||
.md-sidebar--secondary { right: 2rem; }
|
||||
@@ -351,21 +373,22 @@ export const useTechDocsReaderDom = (entityRef: EntityName): Element | null => {
|
||||
}),
|
||||
]),
|
||||
[
|
||||
techdocsSanitizer,
|
||||
techdocsStorageApi,
|
||||
kind,
|
||||
name,
|
||||
namespace,
|
||||
scmIntegrationsApi,
|
||||
techdocsStorageApi,
|
||||
techdocsSanitizer,
|
||||
theme.palette.action.disabledBackground,
|
||||
theme.palette.background.default,
|
||||
theme.palette.background.paper,
|
||||
theme.palette.primary.main,
|
||||
theme.palette.success.main,
|
||||
theme.palette.text.primary,
|
||||
theme.palette.textSubtle,
|
||||
theme.palette.textVerySubtle,
|
||||
theme.typography.fontFamily,
|
||||
theme.palette.text.primary,
|
||||
theme.palette.primary.main,
|
||||
theme.palette.background.paper,
|
||||
theme.palette.background.default,
|
||||
theme.palette.textVerySubtle,
|
||||
theme.palette.textSubtle,
|
||||
theme.palette.action.disabledBackground,
|
||||
theme.palette.success.main,
|
||||
isDarkTheme,
|
||||
isPinned,
|
||||
],
|
||||
);
|
||||
|
||||
@@ -42,6 +42,10 @@ const fixture = `
|
||||
<img src="test.jpg" />
|
||||
<script type="javascript" src="script.js"></script>
|
||||
<a href="afile.pdf" download>Download Now</a>
|
||||
<video width="800" height="450" controls preload="auto">
|
||||
<source src="avideo.mp4" type="video/mp4">
|
||||
Your browser does not support the video tag.
|
||||
</video>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
@@ -88,12 +92,18 @@ describe('addBaseUrl', () => {
|
||||
);
|
||||
expect(techdocsStorageApi.getBaseUrl).toHaveBeenNthCalledWith(
|
||||
3,
|
||||
'astyle.css',
|
||||
'avideo.mp4',
|
||||
mockEntityId,
|
||||
'',
|
||||
);
|
||||
expect(techdocsStorageApi.getBaseUrl).toHaveBeenNthCalledWith(
|
||||
4,
|
||||
'astyle.css',
|
||||
mockEntityId,
|
||||
'',
|
||||
);
|
||||
expect(techdocsStorageApi.getBaseUrl).toHaveBeenNthCalledWith(
|
||||
5,
|
||||
'afile.pdf',
|
||||
mockEntityId,
|
||||
'',
|
||||
|
||||
@@ -84,6 +84,7 @@ export const addBaseUrl = ({
|
||||
await Promise.all([
|
||||
updateDom<HTMLImageElement>(dom.querySelectorAll('img'), 'src'),
|
||||
updateDom<HTMLScriptElement>(dom.querySelectorAll('script'), 'src'),
|
||||
updateDom<HTMLSourceElement>(dom.querySelectorAll('source'), 'src'),
|
||||
updateDom<HTMLLinkElement>(dom.querySelectorAll('link'), 'href'),
|
||||
updateDom<HTMLAnchorElement>(dom.querySelectorAll('a[download]'), 'href'),
|
||||
]);
|
||||
|
||||
@@ -71,4 +71,31 @@ describe('addLinkClickListener', () => {
|
||||
|
||||
expect(fn).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
it('does not call onClick when a link has a download attribute', async () => {
|
||||
const fn = jest.fn();
|
||||
const shadowDom = await createTestShadowDom(
|
||||
`
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<a download href="http://localhost:3000/file.pdf">Download</a>
|
||||
</body>
|
||||
</html>
|
||||
`,
|
||||
{
|
||||
preTransformers: [],
|
||||
postTransformers: [
|
||||
addLinkClickListener({
|
||||
baseUrl: 'http://localhost:3000',
|
||||
onClick: fn,
|
||||
}),
|
||||
],
|
||||
},
|
||||
);
|
||||
|
||||
shadowDom.querySelector('a')?.click();
|
||||
|
||||
expect(fn).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -32,7 +32,7 @@ export const addLinkClickListener = ({
|
||||
const href = target.getAttribute('href');
|
||||
|
||||
if (!href) return;
|
||||
if (href.startsWith(baseUrl)) {
|
||||
if (href.startsWith(baseUrl) && !elem.hasAttribute('download')) {
|
||||
e.preventDefault();
|
||||
onClick(e, href);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ describe('copyToClipboard', () => {
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<code><span>${expectedClipboard}</span></code>
|
||||
<pre><code><span>${expectedClipboard}</span></code></pre>
|
||||
</body>
|
||||
</html>
|
||||
`,
|
||||
@@ -46,4 +46,25 @@ describe('copyToClipboard', () => {
|
||||
|
||||
expect(clipboardSpy).toHaveBeenCalledWith(expectedClipboard);
|
||||
});
|
||||
|
||||
it('only gets applied to code blocks', async () => {
|
||||
const expectedClipboard = 'function foo() {return "bar";}';
|
||||
const shadowDom = await createTestShadowDom(
|
||||
`
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<code><span>${expectedClipboard}</span></code>
|
||||
</body>
|
||||
</html>
|
||||
`,
|
||||
{
|
||||
preTransformers: [],
|
||||
postTransformers: [copyToClipboard()],
|
||||
},
|
||||
);
|
||||
|
||||
const copyButton = shadowDom.querySelector('button');
|
||||
expect(copyButton).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -22,7 +22,7 @@ import type { Transformer } from './transformer';
|
||||
*/
|
||||
export const copyToClipboard = (): Transformer => {
|
||||
return dom => {
|
||||
Array.from(dom.querySelectorAll('code')).forEach(codeElem => {
|
||||
Array.from(dom.querySelectorAll('pre > code')).forEach(codeElem => {
|
||||
const button = document.createElement('button');
|
||||
const toBeCopied = codeElem.textContent || '';
|
||||
button.className = 'md-clipboard md-icon';
|
||||
|
||||
Reference in New Issue
Block a user