@cratis/showrunner.playbill.react 0.0.0-stage → 2.19.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/Badge/PlaybillBadge.tsx +45 -0
- package/Badge/index.ts +4 -0
- package/Client/PlaybillClient.ts +78 -0
- package/Client/index.ts +5 -0
- package/Client/models.ts +64 -0
- package/Configuration/PlaybillProvider.tsx +38 -0
- package/Configuration/index.ts +4 -0
- package/Dialog/PlaybillDialog.tsx +83 -0
- package/Dialog/index.ts +4 -0
- package/Icons.tsx +14 -0
- package/Labels/PlaybillLabels.ts +46 -0
- package/Labels/defaultPlaybillLabels.ts +29 -0
- package/Labels/index.ts +6 -0
- package/Labels/resolveLabels.ts +20 -0
- package/Markdown/PlaybillLink.tsx +14 -0
- package/Markdown/PlaybillMarkdown.tsx +41 -0
- package/Markdown/assetUrl.ts +28 -0
- package/Markdown/index.ts +6 -0
- package/Markdown/safeLink.ts +25 -0
- package/Playbill.tsx +121 -0
- package/README.md +54 -2
- package/Release/ReleaseNoteView.tsx +79 -0
- package/Release/formatReleaseDate.ts +22 -0
- package/Release/index.ts +6 -0
- package/Release/sectionPresentation.ts +35 -0
- package/dist/cjs/Badge/PlaybillBadge.d.ts +10 -0
- package/dist/cjs/Badge/PlaybillBadge.d.ts.map +1 -0
- package/dist/cjs/Badge/PlaybillBadge.js +38 -0
- package/dist/cjs/Badge/PlaybillBadge.js.map +1 -0
- package/dist/cjs/Badge/index.d.ts +2 -0
- package/dist/cjs/Badge/index.d.ts.map +1 -0
- package/dist/cjs/Client/PlaybillClient.d.ts +13 -0
- package/dist/cjs/Client/PlaybillClient.d.ts.map +1 -0
- package/dist/cjs/Client/PlaybillClient.js +71 -0
- package/dist/cjs/Client/PlaybillClient.js.map +1 -0
- package/dist/cjs/Client/index.d.ts +3 -0
- package/dist/cjs/Client/index.d.ts.map +1 -0
- package/dist/cjs/Client/models.d.ts +27 -0
- package/dist/cjs/Client/models.d.ts.map +1 -0
- package/dist/cjs/Configuration/PlaybillProvider.d.ts +11 -0
- package/dist/cjs/Configuration/PlaybillProvider.d.ts.map +1 -0
- package/dist/cjs/Configuration/PlaybillProvider.js +30 -0
- package/dist/cjs/Configuration/PlaybillProvider.js.map +1 -0
- package/dist/cjs/Configuration/index.d.ts +2 -0
- package/dist/cjs/Configuration/index.d.ts.map +1 -0
- package/dist/cjs/Dialog/PlaybillDialog.d.ts +13 -0
- package/dist/cjs/Dialog/PlaybillDialog.d.ts.map +1 -0
- package/dist/cjs/Dialog/PlaybillDialog.js +79 -0
- package/dist/cjs/Dialog/PlaybillDialog.js.map +1 -0
- package/dist/cjs/Dialog/index.d.ts +2 -0
- package/dist/cjs/Dialog/index.d.ts.map +1 -0
- package/dist/cjs/Examples/AppShell.d.ts +5 -0
- package/dist/cjs/Examples/AppShell.d.ts.map +1 -0
- package/dist/cjs/Examples/LocalizedPlaybill.d.ts +2 -0
- package/dist/cjs/Examples/LocalizedPlaybill.d.ts.map +1 -0
- package/dist/cjs/Examples/OwnEndpoint.d.ts +2 -0
- package/dist/cjs/Examples/OwnEndpoint.d.ts.map +1 -0
- package/dist/cjs/Examples/OwnMarkdown.d.ts +2 -0
- package/dist/cjs/Examples/OwnMarkdown.d.ts.map +1 -0
- package/dist/cjs/Examples/OwnRelease.d.ts +2 -0
- package/dist/cjs/Examples/OwnRelease.d.ts.map +1 -0
- package/dist/cjs/Examples/OwnSurface.d.ts +2 -0
- package/dist/cjs/Examples/OwnSurface.d.ts.map +1 -0
- package/dist/cjs/Examples/ReleaseNotesPage.d.ts +2 -0
- package/dist/cjs/Examples/ReleaseNotesPage.d.ts.map +1 -0
- package/dist/cjs/Icons.d.ts +2 -0
- package/dist/cjs/Icons.d.ts.map +1 -0
- package/dist/cjs/Icons.js +36 -0
- package/dist/cjs/Icons.js.map +1 -0
- package/dist/cjs/Labels/PlaybillLabels.d.ts +22 -0
- package/dist/cjs/Labels/PlaybillLabels.d.ts.map +1 -0
- package/dist/cjs/Labels/defaultPlaybillLabels.d.ts +3 -0
- package/dist/cjs/Labels/defaultPlaybillLabels.d.ts.map +1 -0
- package/dist/cjs/Labels/defaultPlaybillLabels.js +30 -0
- package/dist/cjs/Labels/defaultPlaybillLabels.js.map +1 -0
- package/dist/cjs/Labels/index.d.ts +4 -0
- package/dist/cjs/Labels/index.d.ts.map +1 -0
- package/dist/cjs/Labels/resolveLabels.d.ts +4 -0
- package/dist/cjs/Labels/resolveLabels.d.ts.map +1 -0
- package/dist/cjs/Labels/resolveLabels.js +24 -0
- package/dist/cjs/Labels/resolveLabels.js.map +1 -0
- package/dist/cjs/Markdown/PlaybillLink.d.ts +5 -0
- package/dist/cjs/Markdown/PlaybillLink.d.ts.map +1 -0
- package/dist/cjs/Markdown/PlaybillLink.js +21 -0
- package/dist/cjs/Markdown/PlaybillLink.js.map +1 -0
- package/dist/cjs/Markdown/PlaybillMarkdown.d.ts +7 -0
- package/dist/cjs/Markdown/PlaybillMarkdown.d.ts.map +1 -0
- package/dist/cjs/Markdown/PlaybillMarkdown.js +34 -0
- package/dist/cjs/Markdown/PlaybillMarkdown.js.map +1 -0
- package/dist/cjs/Markdown/assetUrl.d.ts +2 -0
- package/dist/cjs/Markdown/assetUrl.d.ts.map +1 -0
- package/dist/cjs/Markdown/assetUrl.js +29 -0
- package/dist/cjs/Markdown/assetUrl.js.map +1 -0
- package/dist/cjs/Markdown/index.d.ts +4 -0
- package/dist/cjs/Markdown/index.d.ts.map +1 -0
- package/dist/cjs/Markdown/safeLink.d.ts +3 -0
- package/dist/cjs/Markdown/safeLink.d.ts.map +1 -0
- package/dist/cjs/Markdown/safeLink.js +30 -0
- package/dist/cjs/Markdown/safeLink.js.map +1 -0
- package/dist/cjs/Playbill.d.ts +15 -0
- package/dist/cjs/Playbill.d.ts.map +1 -0
- package/dist/cjs/Playbill.js +135 -0
- package/dist/cjs/Playbill.js.map +1 -0
- package/dist/cjs/Release/ReleaseNoteView.d.ts +16 -0
- package/dist/cjs/Release/ReleaseNoteView.d.ts.map +1 -0
- package/dist/cjs/Release/ReleaseNoteView.js +75 -0
- package/dist/cjs/Release/ReleaseNoteView.js.map +1 -0
- package/dist/cjs/Release/formatReleaseDate.d.ts +2 -0
- package/dist/cjs/Release/formatReleaseDate.d.ts.map +1 -0
- package/dist/cjs/Release/formatReleaseDate.js +26 -0
- package/dist/cjs/Release/formatReleaseDate.js.map +1 -0
- package/dist/cjs/Release/index.d.ts +4 -0
- package/dist/cjs/Release/index.d.ts.map +1 -0
- package/dist/cjs/Release/sectionPresentation.d.ts +7 -0
- package/dist/cjs/Release/sectionPresentation.d.ts.map +1 -0
- package/dist/cjs/Release/sectionPresentation.js +31 -0
- package/dist/cjs/Release/sectionPresentation.js.map +1 -0
- package/dist/cjs/index.d.ts +13 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +46 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/useLoaded.d.ts +7 -0
- package/dist/cjs/useLoaded.d.ts.map +1 -0
- package/dist/cjs/useLoaded.js +45 -0
- package/dist/cjs/useLoaded.js.map +1 -0
- package/dist/cjs/usePlaybill.d.ts +5 -0
- package/dist/cjs/usePlaybill.d.ts.map +1 -0
- package/dist/cjs/usePlaybill.js +18 -0
- package/dist/cjs/usePlaybill.js.map +1 -0
- package/dist/cjs/usePlaybillStatus.d.ts +8 -0
- package/dist/cjs/usePlaybillStatus.d.ts.map +1 -0
- package/dist/cjs/usePlaybillStatus.js +34 -0
- package/dist/cjs/usePlaybillStatus.js.map +1 -0
- package/dist/cjs/useReleases.d.ts +12 -0
- package/dist/cjs/useReleases.d.ts.map +1 -0
- package/dist/cjs/useReleases.js +58 -0
- package/dist/cjs/useReleases.js.map +1 -0
- package/dist/esm/Badge/PlaybillBadge.d.ts +10 -0
- package/dist/esm/Badge/PlaybillBadge.d.ts.map +1 -0
- package/dist/esm/Badge/PlaybillBadge.js +36 -0
- package/dist/esm/Badge/PlaybillBadge.js.map +1 -0
- package/dist/esm/Badge/index.d.ts +2 -0
- package/dist/esm/Badge/index.d.ts.map +1 -0
- package/dist/esm/Badge/index.js +2 -0
- package/dist/esm/Badge/index.js.map +1 -0
- package/dist/esm/Client/PlaybillClient.d.ts +13 -0
- package/dist/esm/Client/PlaybillClient.d.ts.map +1 -0
- package/dist/esm/Client/PlaybillClient.js +68 -0
- package/dist/esm/Client/PlaybillClient.js.map +1 -0
- package/dist/esm/Client/index.d.ts +3 -0
- package/dist/esm/Client/index.d.ts.map +1 -0
- package/dist/esm/Client/index.js +3 -0
- package/dist/esm/Client/index.js.map +1 -0
- package/dist/esm/Client/models.d.ts +27 -0
- package/dist/esm/Client/models.d.ts.map +1 -0
- package/dist/esm/Client/models.js +2 -0
- package/dist/esm/Client/models.js.map +1 -0
- package/dist/esm/Configuration/PlaybillProvider.d.ts +11 -0
- package/dist/esm/Configuration/PlaybillProvider.d.ts.map +1 -0
- package/dist/esm/Configuration/PlaybillProvider.js +27 -0
- package/dist/esm/Configuration/PlaybillProvider.js.map +1 -0
- package/dist/esm/Configuration/index.d.ts +2 -0
- package/dist/esm/Configuration/index.d.ts.map +1 -0
- package/dist/esm/Configuration/index.js +2 -0
- package/dist/esm/Configuration/index.js.map +1 -0
- package/dist/esm/Dialog/PlaybillDialog.d.ts +13 -0
- package/dist/esm/Dialog/PlaybillDialog.d.ts.map +1 -0
- package/dist/esm/Dialog/PlaybillDialog.js +77 -0
- package/dist/esm/Dialog/PlaybillDialog.js.map +1 -0
- package/dist/esm/Dialog/index.d.ts +2 -0
- package/dist/esm/Dialog/index.d.ts.map +1 -0
- package/dist/esm/Dialog/index.js +2 -0
- package/dist/esm/Dialog/index.js.map +1 -0
- package/dist/esm/Examples/AppShell.d.ts +5 -0
- package/dist/esm/Examples/AppShell.d.ts.map +1 -0
- package/dist/esm/Examples/AppShell.js +6 -0
- package/dist/esm/Examples/AppShell.js.map +1 -0
- package/dist/esm/Examples/LocalizedPlaybill.d.ts +2 -0
- package/dist/esm/Examples/LocalizedPlaybill.d.ts.map +1 -0
- package/dist/esm/Examples/LocalizedPlaybill.js +13 -0
- package/dist/esm/Examples/LocalizedPlaybill.js.map +1 -0
- package/dist/esm/Examples/OwnEndpoint.d.ts +2 -0
- package/dist/esm/Examples/OwnEndpoint.d.ts.map +1 -0
- package/dist/esm/Examples/OwnEndpoint.js +8 -0
- package/dist/esm/Examples/OwnEndpoint.js.map +1 -0
- package/dist/esm/Examples/OwnMarkdown.d.ts +2 -0
- package/dist/esm/Examples/OwnMarkdown.d.ts.map +1 -0
- package/dist/esm/Examples/OwnMarkdown.js +5 -0
- package/dist/esm/Examples/OwnMarkdown.js.map +1 -0
- package/dist/esm/Examples/OwnRelease.d.ts +2 -0
- package/dist/esm/Examples/OwnRelease.d.ts.map +1 -0
- package/dist/esm/Examples/OwnRelease.js +5 -0
- package/dist/esm/Examples/OwnRelease.js.map +1 -0
- package/dist/esm/Examples/OwnSurface.d.ts +2 -0
- package/dist/esm/Examples/OwnSurface.d.ts.map +1 -0
- package/dist/esm/Examples/OwnSurface.js +8 -0
- package/dist/esm/Examples/OwnSurface.js.map +1 -0
- package/dist/esm/Examples/ReleaseNotesPage.d.ts +2 -0
- package/dist/esm/Examples/ReleaseNotesPage.d.ts.map +1 -0
- package/dist/esm/Examples/ReleaseNotesPage.js +4 -0
- package/dist/esm/Examples/ReleaseNotesPage.js.map +1 -0
- package/dist/esm/Icons.d.ts +2 -0
- package/dist/esm/Icons.d.ts.map +1 -0
- package/dist/esm/Icons.js +34 -0
- package/dist/esm/Icons.js.map +1 -0
- package/dist/esm/Labels/PlaybillLabels.d.ts +22 -0
- package/dist/esm/Labels/PlaybillLabels.d.ts.map +1 -0
- package/dist/esm/Labels/PlaybillLabels.js +2 -0
- package/dist/esm/Labels/PlaybillLabels.js.map +1 -0
- package/dist/esm/Labels/defaultPlaybillLabels.d.ts +3 -0
- package/dist/esm/Labels/defaultPlaybillLabels.d.ts.map +1 -0
- package/dist/esm/Labels/defaultPlaybillLabels.js +28 -0
- package/dist/esm/Labels/defaultPlaybillLabels.js.map +1 -0
- package/dist/esm/Labels/index.d.ts +4 -0
- package/dist/esm/Labels/index.d.ts.map +1 -0
- package/dist/esm/Labels/index.js +4 -0
- package/dist/esm/Labels/index.js.map +1 -0
- package/dist/esm/Labels/resolveLabels.d.ts +4 -0
- package/dist/esm/Labels/resolveLabels.d.ts.map +1 -0
- package/dist/esm/Labels/resolveLabels.js +21 -0
- package/dist/esm/Labels/resolveLabels.js.map +1 -0
- package/dist/esm/Markdown/PlaybillLink.d.ts +5 -0
- package/dist/esm/Markdown/PlaybillLink.d.ts.map +1 -0
- package/dist/esm/Markdown/PlaybillLink.js +19 -0
- package/dist/esm/Markdown/PlaybillLink.js.map +1 -0
- package/dist/esm/Markdown/PlaybillMarkdown.d.ts +7 -0
- package/dist/esm/Markdown/PlaybillMarkdown.d.ts.map +1 -0
- package/dist/esm/Markdown/PlaybillMarkdown.js +32 -0
- package/dist/esm/Markdown/PlaybillMarkdown.js.map +1 -0
- package/dist/esm/Markdown/assetUrl.d.ts +2 -0
- package/dist/esm/Markdown/assetUrl.d.ts.map +1 -0
- package/dist/esm/Markdown/assetUrl.js +27 -0
- package/dist/esm/Markdown/assetUrl.js.map +1 -0
- package/dist/esm/Markdown/index.d.ts +4 -0
- package/dist/esm/Markdown/index.d.ts.map +1 -0
- package/dist/esm/Markdown/index.js +4 -0
- package/dist/esm/Markdown/index.js.map +1 -0
- package/dist/esm/Markdown/safeLink.d.ts +3 -0
- package/dist/esm/Markdown/safeLink.d.ts.map +1 -0
- package/dist/esm/Markdown/safeLink.js +27 -0
- package/dist/esm/Markdown/safeLink.js.map +1 -0
- package/dist/esm/Playbill.d.ts +15 -0
- package/dist/esm/Playbill.d.ts.map +1 -0
- package/dist/esm/Playbill.js +133 -0
- package/dist/esm/Playbill.js.map +1 -0
- package/dist/esm/Release/ReleaseNoteView.d.ts +16 -0
- package/dist/esm/Release/ReleaseNoteView.d.ts.map +1 -0
- package/dist/esm/Release/ReleaseNoteView.js +73 -0
- package/dist/esm/Release/ReleaseNoteView.js.map +1 -0
- package/dist/esm/Release/formatReleaseDate.d.ts +2 -0
- package/dist/esm/Release/formatReleaseDate.d.ts.map +1 -0
- package/dist/esm/Release/formatReleaseDate.js +24 -0
- package/dist/esm/Release/formatReleaseDate.js.map +1 -0
- package/dist/esm/Release/index.d.ts +4 -0
- package/dist/esm/Release/index.d.ts.map +1 -0
- package/dist/esm/Release/index.js +4 -0
- package/dist/esm/Release/index.js.map +1 -0
- package/dist/esm/Release/sectionPresentation.d.ts +7 -0
- package/dist/esm/Release/sectionPresentation.d.ts.map +1 -0
- package/dist/esm/Release/sectionPresentation.js +29 -0
- package/dist/esm/Release/sectionPresentation.js.map +1 -0
- package/dist/esm/index.d.ts +13 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +18 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/useLoaded.d.ts +7 -0
- package/dist/esm/useLoaded.d.ts.map +1 -0
- package/dist/esm/useLoaded.js +43 -0
- package/dist/esm/useLoaded.js.map +1 -0
- package/dist/esm/usePlaybill.d.ts +5 -0
- package/dist/esm/usePlaybill.d.ts.map +1 -0
- package/dist/esm/usePlaybill.js +16 -0
- package/dist/esm/usePlaybill.js.map +1 -0
- package/dist/esm/usePlaybillStatus.d.ts +8 -0
- package/dist/esm/usePlaybillStatus.d.ts.map +1 -0
- package/dist/esm/usePlaybillStatus.js +32 -0
- package/dist/esm/usePlaybillStatus.js.map +1 -0
- package/dist/esm/useReleases.d.ts +12 -0
- package/dist/esm/useReleases.d.ts.map +1 -0
- package/dist/esm/useReleases.js +54 -0
- package/dist/esm/useReleases.js.map +1 -0
- package/index.ts +15 -0
- package/package.json +87 -4
- package/styles.css +298 -0
- package/useLoaded.ts +45 -0
- package/usePlaybill.ts +17 -0
- package/usePlaybillStatus.ts +48 -0
- package/useReleases.ts +59 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { ReactNode, useMemo } from 'react';
|
|
5
|
+
import { PlaybillIcon } from '../Icons.js';
|
|
6
|
+
import { PlaybillLabels, resolveLabels, withCount } from '../Labels/index.js';
|
|
7
|
+
import { usePlaybillStatus } from '../usePlaybillStatus.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Props for {@link PlaybillBadge}.
|
|
11
|
+
*/
|
|
12
|
+
export interface PlaybillBadgeProps {
|
|
13
|
+
/** Called when the badge is pressed; open the release notes page or dialog from it. */
|
|
14
|
+
onClick?: () => void;
|
|
15
|
+
/** The texts to replace; the rest stay English. */
|
|
16
|
+
labels?: Partial<PlaybillLabels>;
|
|
17
|
+
/** Leaves the badge out when nothing is unread. By default it stays, so the history is always one press away. */
|
|
18
|
+
hideWhenRead?: boolean;
|
|
19
|
+
/** Replaces the icon. */
|
|
20
|
+
children?: ReactNode;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A button for the application's header that tells the person how many releases they have not seen the notes of. It
|
|
25
|
+
* updates on every device when the notes are seen on one of them. The count is a number on the button; its accessible
|
|
26
|
+
* name says it in words.
|
|
27
|
+
*/
|
|
28
|
+
export const PlaybillBadge = ({ onClick, labels, hideWhenRead = false, children }: PlaybillBadgeProps) => {
|
|
29
|
+
const { unread } = usePlaybillStatus();
|
|
30
|
+
const resolved = useMemo(() => resolveLabels(labels), [labels]);
|
|
31
|
+
if (unread === 0 && hideWhenRead) {
|
|
32
|
+
return <></>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<button
|
|
37
|
+
type='button'
|
|
38
|
+
className={unread > 0 ? 'playbill-badge playbill-badge--unread' : 'playbill-badge'}
|
|
39
|
+
aria-label={unread > 0 ? withCount(resolved.badgeUnread, unread) : resolved.badge}
|
|
40
|
+
onClick={onClick}>
|
|
41
|
+
{children ?? <PlaybillIcon />}
|
|
42
|
+
{unread > 0 && <span className='playbill-badge__count' aria-hidden='true'>{unread}</span>}
|
|
43
|
+
</button>
|
|
44
|
+
);
|
|
45
|
+
};
|
package/Badge/index.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { CurrentRelease, Release, ReleaseList } from './models.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Where Playbill serves the release history from, relative to the origin of the application.
|
|
8
|
+
*/
|
|
9
|
+
export const defaultBasePath = '/.cratis/playbill/v1';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Reads the release history an application serves with `MapPlaybill`. Give your own to {@link PlaybillProvider} to change
|
|
13
|
+
* where the history is read from or how the request is made.
|
|
14
|
+
*/
|
|
15
|
+
export class PlaybillClient {
|
|
16
|
+
/**
|
|
17
|
+
* Initializes a new instance of the {@link PlaybillClient} class.
|
|
18
|
+
* @param basePath Where the history is served from. Defaults to `/.cratis/playbill/v1`.
|
|
19
|
+
* @param fetcher Makes the request. Defaults to `fetch`; give one to add headers or point at another origin.
|
|
20
|
+
*/
|
|
21
|
+
constructor(
|
|
22
|
+
readonly basePath: string = defaultBasePath,
|
|
23
|
+
private readonly fetcher: typeof fetch = (input, init) => fetch(input, init)) {
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Lists the releases, the newest first.
|
|
28
|
+
* @param since When set, only the releases newer than this version.
|
|
29
|
+
* @param signal Cancels the request.
|
|
30
|
+
* @returns The list.
|
|
31
|
+
*/
|
|
32
|
+
list(since?: string, signal?: AbortSignal): Promise<ReleaseList> {
|
|
33
|
+
const query = since ? `?since=${encodeURIComponent(since)}` : '';
|
|
34
|
+
return this.read<ReleaseList>(`/releases${query}`, signal);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Gets one release with its note.
|
|
39
|
+
* @param version The version of the release.
|
|
40
|
+
* @param signal Cancels the request.
|
|
41
|
+
* @returns The release.
|
|
42
|
+
*/
|
|
43
|
+
get(version: string, signal?: AbortSignal): Promise<Release> {
|
|
44
|
+
return this.read<Release>(`/releases/${encodeURIComponent(version)}`, signal);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Gets the version the application is running and the newest release that has a note.
|
|
49
|
+
* @param signal Cancels the request.
|
|
50
|
+
* @returns The current release.
|
|
51
|
+
*/
|
|
52
|
+
current(signal?: AbortSignal): Promise<CurrentRelease> {
|
|
53
|
+
return this.read<CurrentRelease>('/current', signal);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Gets the address the files of a release are served from: an image the note refers to as `hero.png` is at
|
|
58
|
+
* `<this address>/hero.png`.
|
|
59
|
+
* @param version The version of the release.
|
|
60
|
+
* @returns The address, without a trailing slash.
|
|
61
|
+
*/
|
|
62
|
+
assetBase(version: string): string {
|
|
63
|
+
return `${this.basePath}/releases/${encodeURIComponent(version)}`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private async read<TResult>(path: string, signal?: AbortSignal): Promise<TResult> {
|
|
67
|
+
const response = await this.fetcher(`${this.basePath}${path}`, {
|
|
68
|
+
headers: { Accept: 'application/json' },
|
|
69
|
+
credentials: 'same-origin',
|
|
70
|
+
signal
|
|
71
|
+
});
|
|
72
|
+
if (!response.ok) {
|
|
73
|
+
throw new Error(`Playbill could not read ${path}: ${response.status} ${response.statusText}`.trim());
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return await response.json() as TResult;
|
|
77
|
+
}
|
|
78
|
+
}
|
package/Client/index.ts
ADDED
package/Client/models.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A release in the list of releases, as `GET /.cratis/playbill/v1/releases` gives it.
|
|
6
|
+
*/
|
|
7
|
+
export interface ReleaseSummary {
|
|
8
|
+
/** The version of the release, such as `2.3.0`. */
|
|
9
|
+
version: string;
|
|
10
|
+
/** When the release was made, as an ISO date; absent when the capture did not record it. */
|
|
11
|
+
releasedAt?: string | null;
|
|
12
|
+
/** The pull request the release was made from; absent when the capture did not record it. */
|
|
13
|
+
pull?: string | null;
|
|
14
|
+
/** One line that says what the release is about. */
|
|
15
|
+
summary: string;
|
|
16
|
+
/** The headings of the note, such as `Added` and `Fixed`. */
|
|
17
|
+
sections: string[];
|
|
18
|
+
/** The files the note refers to, such as images. */
|
|
19
|
+
assets: string[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* One heading of a release note and what is written under it.
|
|
24
|
+
*/
|
|
25
|
+
export interface ReleaseSection {
|
|
26
|
+
/** The heading, such as `Added`. */
|
|
27
|
+
name: string;
|
|
28
|
+
/** The markdown under the heading. */
|
|
29
|
+
markdown: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* One release with its note, as `GET /.cratis/playbill/v1/releases/{version}` gives it when JSON is asked for.
|
|
34
|
+
*/
|
|
35
|
+
export interface Release extends Omit<ReleaseSummary, 'sections'> {
|
|
36
|
+
/** What is written before the first section, as markdown; empty when the note starts with a section. */
|
|
37
|
+
lead: string;
|
|
38
|
+
/** The sections of the note, in the order they are written. */
|
|
39
|
+
sections: ReleaseSection[];
|
|
40
|
+
/** The note as it was captured. */
|
|
41
|
+
markdown: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The list of releases.
|
|
46
|
+
*/
|
|
47
|
+
export interface ReleaseList {
|
|
48
|
+
/** The version the application is running; absent when it is not known. */
|
|
49
|
+
current?: string | null;
|
|
50
|
+
/** The releases, the newest first. */
|
|
51
|
+
releases: ReleaseSummary[];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The version the application is running, as `GET /.cratis/playbill/v1/current` gives it.
|
|
56
|
+
*/
|
|
57
|
+
export interface CurrentRelease {
|
|
58
|
+
/** The version; absent when it is not known. */
|
|
59
|
+
version?: string | null;
|
|
60
|
+
/** The release of that version; absent when it has no note. */
|
|
61
|
+
release?: ReleaseSummary | null;
|
|
62
|
+
/** The newest release that has a note; absent when none has. */
|
|
63
|
+
newest?: string | null;
|
|
64
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { createContext, ReactNode, useContext, useMemo } from 'react';
|
|
5
|
+
import { PlaybillClient } from '../Client/index.js';
|
|
6
|
+
|
|
7
|
+
const defaultClient = new PlaybillClient();
|
|
8
|
+
|
|
9
|
+
const PlaybillContext = createContext<PlaybillClient>(defaultClient);
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Props for {@link PlaybillProvider}.
|
|
13
|
+
*/
|
|
14
|
+
export interface PlaybillProviderProps {
|
|
15
|
+
/** Where the history is served from. Defaults to `/.cratis/playbill/v1`. Ignored when a `client` is given. */
|
|
16
|
+
basePath?: string;
|
|
17
|
+
/** Makes the requests, for adding headers or reading another origin. Defaults to `fetch`. Ignored when a `client` is given. */
|
|
18
|
+
fetcher?: typeof fetch;
|
|
19
|
+
/** Reads the history instead of the default client. */
|
|
20
|
+
client?: PlaybillClient;
|
|
21
|
+
/** What reads the history. */
|
|
22
|
+
children: ReactNode;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Tells the Playbill components where to read the release history from. It is optional: without it they read
|
|
27
|
+
* `/.cratis/playbill/v1` of the page's own origin, which is where `MapPlaybill` serves it.
|
|
28
|
+
*/
|
|
29
|
+
export const PlaybillProvider = ({ basePath, fetcher, client, children }: PlaybillProviderProps) => {
|
|
30
|
+
const value = useMemo(() => client ?? new PlaybillClient(basePath, fetcher), [client, basePath, fetcher]);
|
|
31
|
+
return <PlaybillContext.Provider value={value}>{children}</PlaybillContext.Provider>;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Gets the client that reads the release history.
|
|
36
|
+
* @returns The client of the nearest {@link PlaybillProvider}, or the default one.
|
|
37
|
+
*/
|
|
38
|
+
export const usePlaybillClient = (): PlaybillClient => useContext(PlaybillContext);
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { DialogButtons } from '@cratis/arc.react/dialogs';
|
|
5
|
+
import { Dialog, DialogInitialFocus } from '@cratis/components/Dialogs';
|
|
6
|
+
import { ComponentType, useMemo, useState } from 'react';
|
|
7
|
+
import { usePlaybillClient } from '../Configuration/index.js';
|
|
8
|
+
import { PlaybillLabels, resolveLabels, withCount } from '../Labels/index.js';
|
|
9
|
+
import { PlaybillMarkdown, PlaybillMarkdownProps } from '../Markdown/index.js';
|
|
10
|
+
import { ReleaseNoteView, ReleaseNoteViewProps } from '../Release/index.js';
|
|
11
|
+
import { usePlaybillStatus } from '../usePlaybillStatus.js';
|
|
12
|
+
import { useReleaseNotes } from '../useReleases.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Props for {@link PlaybillDialog}.
|
|
16
|
+
*/
|
|
17
|
+
export interface PlaybillDialogProps {
|
|
18
|
+
/** Replaces how one release is drawn. */
|
|
19
|
+
release?: ComponentType<ReleaseNoteViewProps>;
|
|
20
|
+
/** Replaces the Markdown renderer the default release view uses, and that a custom one is given. */
|
|
21
|
+
markdown?: ComponentType<PlaybillMarkdownProps>;
|
|
22
|
+
/** The texts to replace; the rest stay English. */
|
|
23
|
+
labels?: Partial<PlaybillLabels>;
|
|
24
|
+
/** The locale to write the dates in; the browser's when not given. */
|
|
25
|
+
locale?: string | string[];
|
|
26
|
+
/** The most releases to show at once, the newest first. Defaults to 5; the rest are pointed to with the `earlier` text. */
|
|
27
|
+
maxReleases?: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Tells the signed-in person what is new: a dialog that opens by itself with the notes of the releases they have not
|
|
32
|
+
* seen, and records that they have when it is closed, so it does not return on any device. Nothing opens when nothing
|
|
33
|
+
* is unread. Mount it once, in the application shell and inside Arc's context.
|
|
34
|
+
*/
|
|
35
|
+
export const PlaybillDialog = ({ release: Release = ReleaseNoteView, markdown, labels, locale, maxReleases = 5 }: PlaybillDialogProps) => {
|
|
36
|
+
const client = usePlaybillClient();
|
|
37
|
+
const { unreadVersions, markSeen } = usePlaybillStatus();
|
|
38
|
+
const resolved = useMemo(() => resolveLabels(labels), [labels]);
|
|
39
|
+
const shown = useMemo(() => unreadVersions.slice(0, maxReleases), [unreadVersions, maxReleases]);
|
|
40
|
+
const key = shown.join('|');
|
|
41
|
+
const [dismissed, setDismissed] = useState<string>();
|
|
42
|
+
const { data: releases, isLoading, error } = useReleaseNotes(shown);
|
|
43
|
+
|
|
44
|
+
if (shown.length === 0 || dismissed === key) {
|
|
45
|
+
return <></>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const close = () => {
|
|
49
|
+
setDismissed(key);
|
|
50
|
+
// Failing to remember it must not keep a person from reading on.
|
|
51
|
+
markSeen(shown[0]).catch(() => undefined);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<Dialog
|
|
56
|
+
title={resolved.title}
|
|
57
|
+
width='40rem'
|
|
58
|
+
buttons={DialogButtons.Ok}
|
|
59
|
+
okLabel={resolved.acknowledge}
|
|
60
|
+
closeAriaLabel={resolved.close}
|
|
61
|
+
initialFocus={DialogInitialFocus.Content}
|
|
62
|
+
onConfirm={close}
|
|
63
|
+
onCancel={close}>
|
|
64
|
+
<div className='playbill-dialog'>
|
|
65
|
+
{isLoading && <p className='playbill-status' role='status'>{resolved.loading}</p>}
|
|
66
|
+
{error && <p className='playbill-status playbill-status--failed' role='alert'>{resolved.failed}</p>}
|
|
67
|
+
{!isLoading && !error && releases?.map(note => (
|
|
68
|
+
<Release
|
|
69
|
+
key={note.version}
|
|
70
|
+
release={note}
|
|
71
|
+
assetBase={client.assetBase(note.version)}
|
|
72
|
+
labels={resolved}
|
|
73
|
+
markdown={markdown ?? PlaybillMarkdown}
|
|
74
|
+
locale={locale}
|
|
75
|
+
headingLevel={3} />
|
|
76
|
+
))}
|
|
77
|
+
{unreadVersions.length > shown.length && (
|
|
78
|
+
<p className='playbill-dialog__earlier'>{withCount(resolved.earlier, unreadVersions.length - shown.length)}</p>
|
|
79
|
+
)}
|
|
80
|
+
</div>
|
|
81
|
+
</Dialog>
|
|
82
|
+
);
|
|
83
|
+
};
|
package/Dialog/index.ts
ADDED
package/Icons.tsx
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The icon of the release notes: a page with a ribbon. It is decorative, so it is hidden from assistive technology; the
|
|
6
|
+
* control that holds it carries the accessible name.
|
|
7
|
+
*/
|
|
8
|
+
export const PlaybillIcon = () => (
|
|
9
|
+
<svg className='playbill-icon' viewBox='0 0 24 24' width='1em' height='1em' fill='none' stroke='currentColor' strokeWidth='2' strokeLinecap='round' strokeLinejoin='round' aria-hidden='true' focusable='false'>
|
|
10
|
+
<path d='M6 3h9l4 4v14H6z' />
|
|
11
|
+
<path d='M14 3v5h5' />
|
|
12
|
+
<path d='M9 13h7M9 17h7' />
|
|
13
|
+
</svg>
|
|
14
|
+
);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The texts Playbill shows. Every one is a prop so a product can localize it. A text with `{count}` has the number put in.
|
|
6
|
+
*/
|
|
7
|
+
export interface PlaybillLabels {
|
|
8
|
+
/** The heading of the page and of the dialog. */
|
|
9
|
+
title: string;
|
|
10
|
+
/** The button that closes the dialog. */
|
|
11
|
+
acknowledge: string;
|
|
12
|
+
/** The accessible name of the close button in the header of the dialog. */
|
|
13
|
+
close: string;
|
|
14
|
+
/** The accessible name of the list of releases. */
|
|
15
|
+
releases: string;
|
|
16
|
+
/** The tag on a release the person has not seen the notes of. */
|
|
17
|
+
unread: string;
|
|
18
|
+
/** The tag on the release the application is running. */
|
|
19
|
+
current: string;
|
|
20
|
+
/** The word before the date a release was made. */
|
|
21
|
+
released: string;
|
|
22
|
+
/** Shown while the release notes are being read. */
|
|
23
|
+
loading: string;
|
|
24
|
+
/** Shown when the release notes could not be read. */
|
|
25
|
+
failed: string;
|
|
26
|
+
/** Shown when the application has no release notes. */
|
|
27
|
+
empty: string;
|
|
28
|
+
/** The accessible name of the badge when nothing is unread. */
|
|
29
|
+
badge: string;
|
|
30
|
+
/** The accessible name of the badge when releases are unread; has `{count}`. */
|
|
31
|
+
badgeUnread: string;
|
|
32
|
+
/** Shown in the dialog when it holds fewer releases than are unread; has `{count}`. */
|
|
33
|
+
earlier: string;
|
|
34
|
+
/** The heading of the `Added` section. */
|
|
35
|
+
added: string;
|
|
36
|
+
/** The heading of the `Changed` section. */
|
|
37
|
+
changed: string;
|
|
38
|
+
/** The heading of the `Fixed` section. */
|
|
39
|
+
fixed: string;
|
|
40
|
+
/** The heading of the `Removed` section. */
|
|
41
|
+
removed: string;
|
|
42
|
+
/** The heading of the `Security` section. */
|
|
43
|
+
security: string;
|
|
44
|
+
/** The heading of the `Deprecated` section. */
|
|
45
|
+
deprecated: string;
|
|
46
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { PlaybillLabels } from './PlaybillLabels.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The English texts Playbill shows unless a product replaces them.
|
|
8
|
+
*/
|
|
9
|
+
export const defaultPlaybillLabels: PlaybillLabels = {
|
|
10
|
+
title: 'What\'s new',
|
|
11
|
+
acknowledge: 'Got it',
|
|
12
|
+
close: 'Close',
|
|
13
|
+
releases: 'Releases',
|
|
14
|
+
unread: 'New',
|
|
15
|
+
current: 'Current',
|
|
16
|
+
released: 'Released',
|
|
17
|
+
loading: 'Loading release notes…',
|
|
18
|
+
failed: 'The release notes could not be loaded.',
|
|
19
|
+
empty: 'There are no release notes yet.',
|
|
20
|
+
badge: 'Release notes',
|
|
21
|
+
badgeUnread: 'Release notes, {count} new',
|
|
22
|
+
earlier: '{count} earlier releases are on the release notes page.',
|
|
23
|
+
added: 'Added',
|
|
24
|
+
changed: 'Changed',
|
|
25
|
+
fixed: 'Fixed',
|
|
26
|
+
removed: 'Removed',
|
|
27
|
+
security: 'Security',
|
|
28
|
+
deprecated: 'Deprecated'
|
|
29
|
+
};
|
package/Labels/index.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
export * from './defaultPlaybillLabels.js';
|
|
5
|
+
export * from './PlaybillLabels.js';
|
|
6
|
+
export * from './resolveLabels.js';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { defaultPlaybillLabels } from './defaultPlaybillLabels.js';
|
|
5
|
+
import { PlaybillLabels } from './PlaybillLabels.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Overlays the texts a product gives on the English defaults.
|
|
9
|
+
* @param overrides The texts to replace; the rest stay English.
|
|
10
|
+
* @returns The texts to show.
|
|
11
|
+
*/
|
|
12
|
+
export const resolveLabels = (overrides?: Partial<PlaybillLabels>): PlaybillLabels => ({ ...defaultPlaybillLabels, ...overrides });
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Puts a number into a text that has `{count}`.
|
|
16
|
+
* @param text The text.
|
|
17
|
+
* @param count The number.
|
|
18
|
+
* @returns The text with the number in it.
|
|
19
|
+
*/
|
|
20
|
+
export const withCount = (text: string, count: number): string => text.split('{count}').join(count.toString());
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { ComponentProps } from 'react';
|
|
5
|
+
|
|
6
|
+
type LinkProps = ComponentProps<'a'>;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A link in a release note: it opens in a new tab with `noopener noreferrer`. A link that is not safe has no `href`
|
|
10
|
+
* left, because the URL transform emptied it, and is only its text.
|
|
11
|
+
*/
|
|
12
|
+
export const PlaybillLink = ({ href, title, children }: LinkProps) => href
|
|
13
|
+
? <a href={href} title={title} target='_blank' rel='noopener noreferrer'>{children}</a>
|
|
14
|
+
: <span>{children}</span>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { ComponentProps, ComponentType } from 'react';
|
|
5
|
+
import ReactMarkdown from 'react-markdown';
|
|
6
|
+
import { resolveAssetUrl } from './assetUrl.js';
|
|
7
|
+
import { PlaybillLink } from './PlaybillLink.js';
|
|
8
|
+
import { safeLinkOrEmpty } from './safeLink.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Props for the component that renders the Markdown of a release note. Give your own to the `markdown` slot of
|
|
12
|
+
* {@link Playbill}, {@link PlaybillDialog} or {@link ReleaseNoteView}.
|
|
13
|
+
*/
|
|
14
|
+
export interface PlaybillMarkdownProps {
|
|
15
|
+
/** The Markdown source. */
|
|
16
|
+
source: string;
|
|
17
|
+
/** Where the files of the release are served from, so an image written as `hero.png` can be loaded. */
|
|
18
|
+
assetBase?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type ImageProps = ComponentProps<'img'>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Renders the Markdown of a release note as React elements, never as injected HTML: raw HTML in the source is dropped,
|
|
25
|
+
* a link opens in a new tab with `noopener noreferrer`, and only `https`, `mailto` and `tel` links are links at all.
|
|
26
|
+
* Images are the ones captured with the release, loaded from its own folder, and `https` images the capture could not
|
|
27
|
+
* download; every other image is left out.
|
|
28
|
+
*/
|
|
29
|
+
export const PlaybillMarkdown: ComponentType<PlaybillMarkdownProps> = ({ source, assetBase }: PlaybillMarkdownProps) => (
|
|
30
|
+
<div className='playbill-markdown'>
|
|
31
|
+
<ReactMarkdown
|
|
32
|
+
skipHtml
|
|
33
|
+
urlTransform={(url, key) => key === 'src' ? resolveAssetUrl(url, assetBase) : safeLinkOrEmpty(url)}
|
|
34
|
+
components={{
|
|
35
|
+
a: PlaybillLink,
|
|
36
|
+
img: ({ src, alt }: ImageProps) => src ? <img src={src} alt={alt ?? ''} loading='lazy' /> : <></>
|
|
37
|
+
}}>
|
|
38
|
+
{source}
|
|
39
|
+
</ReactMarkdown>
|
|
40
|
+
</div>
|
|
41
|
+
);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { isSafeLink } from './safeLink.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Works out where an image of a release note is loaded from. A note refers to the files captured with it by their
|
|
8
|
+
* name, such as `hero.png`; those are served from the release's own folder. An `https` image the capture could not
|
|
9
|
+
* download is left as it was written. Anything else, such as `javascript:`, `data:` or a path that climbs out of the
|
|
10
|
+
* folder, is not an image.
|
|
11
|
+
* @param source The image as written in the note.
|
|
12
|
+
* @param assetBase Where the files of the release are served from, without a trailing slash; absent when it is not known.
|
|
13
|
+
* @returns The address to load the image from, or an empty string when it is not safe to load.
|
|
14
|
+
*/
|
|
15
|
+
export const resolveAssetUrl = (source: string, assetBase?: string): string => {
|
|
16
|
+
if (/^https:\/\//i.test(source)) {
|
|
17
|
+
return isSafeLink(source) ? source : '';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const relative = source.replace(/^\.\//, '');
|
|
21
|
+
const hasScheme = /^[a-z][a-z0-9+.-]*:/i.test(relative) || relative.startsWith('//') || relative.startsWith('/');
|
|
22
|
+
const climbs = relative.split('/').includes('..');
|
|
23
|
+
if (!assetBase || !relative || hasScheme || climbs) {
|
|
24
|
+
return '';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return `${assetBase}/${relative.split('/').map(encodeURIComponent).join('/')}`;
|
|
28
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
const allowedProtocols = new Set(['https:', 'mailto:', 'tel:']);
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Whether a link may be followed from a release note: only `https`, `mailto` and `tel`. A relative link, a scheme that
|
|
8
|
+
* runs code such as `javascript:` and a scheme that carries content such as `data:` are not.
|
|
9
|
+
* @param url The link as written in the note.
|
|
10
|
+
* @returns True when it is safe to link to.
|
|
11
|
+
*/
|
|
12
|
+
export const isSafeLink = (url: string): boolean => {
|
|
13
|
+
try {
|
|
14
|
+
return allowedProtocols.has(new URL(url).protocol);
|
|
15
|
+
} catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Empties a link that is not safe, so it never reaches an `href`.
|
|
22
|
+
* @param url The link as written in the note.
|
|
23
|
+
* @returns The link, or an empty string.
|
|
24
|
+
*/
|
|
25
|
+
export const safeLinkOrEmpty = (url: string): string => isSafeLink(url) ? url : '';
|