@atlaspack/inspector-frontend 0.1.1
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/.atlaspackrc +4 -0
- package/.eslintrc.json +19 -0
- package/CHANGELOG.md +12 -0
- package/dist/atlassian-dark-brand-refresh.91b786da.js +2 -0
- package/dist/atlassian-dark-brand-refresh.91b786da.js.map +1 -0
- package/dist/atlassian-dark-future.59ebadca.js +2 -0
- package/dist/atlassian-dark-future.59ebadca.js.map +1 -0
- package/dist/atlassian-dark-increased-contrast.ff6775f2.js +2 -0
- package/dist/atlassian-dark-increased-contrast.ff6775f2.js.map +1 -0
- package/dist/atlassian-dark.ad679134.js +2 -0
- package/dist/atlassian-dark.ad679134.js.map +1 -0
- package/dist/atlassian-legacy-dark.8aa27f7f.js +2 -0
- package/dist/atlassian-legacy-dark.8aa27f7f.js.map +1 -0
- package/dist/atlassian-legacy-light.2eb372ce.js +2 -0
- package/dist/atlassian-legacy-light.2eb372ce.js.map +1 -0
- package/dist/atlassian-light-brand-refresh.fadcab0a.js +2 -0
- package/dist/atlassian-light-brand-refresh.fadcab0a.js.map +1 -0
- package/dist/atlassian-light-future.612afe8a.js +2 -0
- package/dist/atlassian-light-future.612afe8a.js.map +1 -0
- package/dist/atlassian-light-increased-contrast.7161cd79.js +2 -0
- package/dist/atlassian-light-increased-contrast.7161cd79.js.map +1 -0
- package/dist/atlassian-light.bc343d4c.js +2 -0
- package/dist/atlassian-light.bc343d4c.js.map +1 -0
- package/dist/atlassian-shape.b92d69c0.js +2 -0
- package/dist/atlassian-shape.b92d69c0.js.map +1 -0
- package/dist/atlassian-spacing.60ddd8e7.js +2 -0
- package/dist/atlassian-spacing.60ddd8e7.js.map +1 -0
- package/dist/atlassian-typography-adg3.f88947f6.js +2 -0
- package/dist/atlassian-typography-adg3.f88947f6.js.map +1 -0
- package/dist/atlassian-typography-modernized.42016c51.js +2 -0
- package/dist/atlassian-typography-modernized.42016c51.js.map +1 -0
- package/dist/atlassian-typography-refreshed.ec0d111b.js +2 -0
- package/dist/atlassian-typography-refreshed.ec0d111b.js.map +1 -0
- package/dist/atlassian-typography.66d7e8f4.js +2 -0
- package/dist/atlassian-typography.66d7e8f4.js.map +1 -0
- package/dist/badge-light.7e55986a.png +0 -0
- package/dist/custom-theme.4680282a.js +2 -0
- package/dist/custom-theme.4680282a.js.map +1 -0
- package/dist/drag-handle.136830d3.js +2 -0
- package/dist/drag-handle.136830d3.js.map +1 -0
- package/dist/drag-handle.63bdb345.css +2 -0
- package/dist/drag-handle.63bdb345.css.map +1 -0
- package/dist/index.13289f53.js +28 -0
- package/dist/index.13289f53.js.map +1 -0
- package/dist/index.a41fafce.css +2 -0
- package/dist/index.a41fafce.css.map +1 -0
- package/dist/index.html +1 -0
- package/dist/index.runtime.3c39d71d.js +2 -0
- package/dist/index.runtime.3c39d71d.js.map +1 -0
- package/dist/refractor.2c1fd9a1.js +2 -0
- package/dist/refractor.2c1fd9a1.js.map +1 -0
- package/index.html +11 -0
- package/jest.config.js +16 -0
- package/package.json +64 -0
- package/src/APIError.test.ts +72 -0
- package/src/APIError.tsx +29 -0
- package/src/AppRoutes.tsx +56 -0
- package/src/hack-feature-flags.ts +6 -0
- package/src/main.tsx +50 -0
- package/src/test/stubCssModule.js +1 -0
- package/src/ui/App.module.css +122 -0
- package/src/ui/App.module.css.d.ts +8 -0
- package/src/ui/AppLayout/AppLayout.tsx +26 -0
- package/src/ui/AppLayout/SidebarNavigation/LinkItem.tsx +26 -0
- package/src/ui/AppLayout/SidebarNavigation/SidebarNavigation.tsx +45 -0
- package/src/ui/AppLayout/TopNavigation/Logo.module.css +12 -0
- package/src/ui/AppLayout/TopNavigation/Logo.module.css.d.ts +4 -0
- package/src/ui/AppLayout/TopNavigation/Logo.tsx +11 -0
- package/src/ui/AppLayout/TopNavigation/TopNavigation.module.css +14 -0
- package/src/ui/AppLayout/TopNavigation/TopNavigation.module.css.d.ts +3 -0
- package/src/ui/AppLayout/TopNavigation/TopNavigation.tsx +45 -0
- package/src/ui/AppLayout/TopNavigation/badge-light.png +0 -0
- package/src/ui/AppLayout/TopNavigation/logo-light.png +0 -0
- package/src/ui/DefaultLoadingIndicator/DefaultLoadingIndicator.module.css +9 -0
- package/src/ui/DefaultLoadingIndicator/DefaultLoadingIndicator.module.css.d.ts +3 -0
- package/src/ui/DefaultLoadingIndicator/DefaultLoadingIndicator.test.tsx +15 -0
- package/src/ui/DefaultLoadingIndicator/DefaultLoadingIndicator.tsx +14 -0
- package/src/ui/app/StatsPage.tsx +77 -0
- package/src/ui/app/cache/CacheKeysIndexPage.tsx +13 -0
- package/src/ui/app/cache/CacheKeysPage.module.css +11 -0
- package/src/ui/app/cache/CacheKeysPage.module.css.d.ts +4 -0
- package/src/ui/app/cache/CacheKeysPage.tsx +23 -0
- package/src/ui/app/cache/[key]/CacheValuePage.tsx +40 -0
- package/src/ui/app/cache/ui/CacheKeyList.module.css +40 -0
- package/src/ui/app/cache/ui/CacheKeyList.module.css.d.ts +7 -0
- package/src/ui/app/cache/ui/CacheKeyList.tsx +187 -0
- package/src/ui/app/cache-invalidation/CacheInvalidationPage.tsx +22 -0
- package/src/ui/app/cache-invalidation/[fileId]/CacheInvalidationFilePage.tsx +22 -0
- package/src/ui/app/cache-invalidation/ui/CacheFileList.module.css +40 -0
- package/src/ui/app/cache-invalidation/ui/CacheFileList.module.css.d.ts +7 -0
- package/src/ui/app/cache-invalidation/ui/CacheFileList.tsx +185 -0
- package/src/ui/app/treemap/BottomPanelResizeState.test.ts +25 -0
- package/src/ui/app/treemap/BottomPanelResizeState.tsx +48 -0
- package/src/ui/app/treemap/FoamTreemapPage.module.css +24 -0
- package/src/ui/app/treemap/FoamTreemapPage.module.css.d.ts +6 -0
- package/src/ui/app/treemap/FoamTreemapPage.tsx +47 -0
- package/src/ui/app/treemap/controllers/RelatedBundlesController.tsx +41 -0
- package/src/ui/app/treemap/controllers/UrlFocusController.tsx +33 -0
- package/src/ui/app/treemap/ui/BottomPanel/BottomPanel.module.css +24 -0
- package/src/ui/app/treemap/ui/BottomPanel/BottomPanel.module.css.d.ts +5 -0
- package/src/ui/app/treemap/ui/BottomPanel/BottomPanel.tsx +24 -0
- package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/AdvancedSettings.module.css +13 -0
- package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/AdvancedSettings.module.css.d.ts +5 -0
- package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/AdvancedSettings.tsx +53 -0
- package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/AssetTable/AssetTable.tsx +135 -0
- package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/AssetTable/CollapsibleTable/CollapsibleTable.module.css +7 -0
- package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/AssetTable/CollapsibleTable/CollapsibleTable.module.css.d.ts +3 -0
- package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/AssetTable/CollapsibleTable/CollapsibleTable.tsx +123 -0
- package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/AssetTable/CollapsibleTable/CollapsibleTableModel.tsx +18 -0
- package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/AssetTable/CollapsibleTable/CollapsibleTableRow.module.css +20 -0
- package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/AssetTable/CollapsibleTable/CollapsibleTableRow.module.css.d.ts +6 -0
- package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/AssetTable/CollapsibleTable/CollapsibleTableRow.tsx +79 -0
- package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/AssetTable/getFileURL.test.ts +19 -0
- package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/AssetTable/getFileURL.ts +24 -0
- package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/FocusedGroupInfo.module.css +20 -0
- package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/FocusedGroupInfo.module.css.d.ts +5 -0
- package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/FocusedGroupInfo.tsx +42 -0
- package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/FocusedGroupInfoInner.module.css +29 -0
- package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/FocusedGroupInfoInner.module.css.d.ts +6 -0
- package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/FocusedGroupInfoInner.tsx +107 -0
- package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/GraphContainer.module.css +7 -0
- package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/GraphContainer.module.css.d.ts +3 -0
- package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/GraphContainer.tsx +20 -0
- package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/SourceCodeURL.tsx +5 -0
- package/src/ui/app/treemap/ui/BundleGraphRenderer.module.css +13 -0
- package/src/ui/app/treemap/ui/BundleGraphRenderer.module.css.d.ts +4 -0
- package/src/ui/app/treemap/ui/BundleGraphRenderer.tsx +95 -0
- package/src/ui/app/treemap/ui/FocusBreadcrumbs/FocusBreadcrumbs.module.css +6 -0
- package/src/ui/app/treemap/ui/FocusBreadcrumbs/FocusBreadcrumbs.module.css.d.ts +3 -0
- package/src/ui/app/treemap/ui/FocusBreadcrumbs/FocusBreadcrumbs.tsx +49 -0
- package/src/ui/app/treemap/ui/SigmaGraph.module.css +5 -0
- package/src/ui/app/treemap/ui/SigmaGraph.module.css.d.ts +3 -0
- package/src/ui/app/treemap/ui/SigmaGraph.tsx +80 -0
- package/src/ui/app/treemap/ui/Treemap.tsx +14 -0
- package/src/ui/app/treemap/ui/TreemapRenderer/ImpactScore.module.css +32 -0
- package/src/ui/app/treemap/ui/TreemapRenderer/ImpactScore.module.css.d.ts +5 -0
- package/src/ui/app/treemap/ui/TreemapRenderer/ImpactScore.tsx +24 -0
- package/src/ui/app/treemap/ui/TreemapRenderer/TreemapRenderer.module.css +14 -0
- package/src/ui/app/treemap/ui/TreemapRenderer/TreemapRenderer.module.css.d.ts +4 -0
- package/src/ui/app/treemap/ui/TreemapRenderer/TreemapRenderer.tsx +271 -0
- package/src/ui/app/treemap/ui/TreemapRenderer/TreemapTooltip.module.css +15 -0
- package/src/ui/app/treemap/ui/TreemapRenderer/TreemapTooltip.module.css.d.ts +4 -0
- package/src/ui/app/treemap/ui/TreemapRenderer/TreemapTooltip.tsx +111 -0
- package/src/ui/app/treemap/ui/TreemapRenderer/controllers/useStableCallback.test.ts +27 -0
- package/src/ui/app/treemap/ui/TreemapRenderer/controllers/useStableCallback.ts +21 -0
- package/src/ui/app/treemap/ui/TreemapRenderer/useMouseMoveController.ts +20 -0
- package/src/ui/globals.css +26 -0
- package/src/ui/globals.css.d.ts +1 -0
- package/src/ui/globals.d.ts +9 -0
- package/src/ui/model/ViewModel.test.ts +31 -0
- package/src/ui/model/ViewModel.ts +62 -0
- package/src/ui/not-found/NotFoundPage.module.css +7 -0
- package/src/ui/not-found/NotFoundPage.module.css.d.ts +3 -0
- package/src/ui/not-found/NotFoundPage.tsx +9 -0
- package/src/ui/types/Graph.tsx +12 -0
- package/src/ui/util/ErrorBoundary.module.css +3 -0
- package/src/ui/util/ErrorBoundary.module.css.d.ts +3 -0
- package/src/ui/util/ErrorBoundary.test.tsx +65 -0
- package/src/ui/util/ErrorBoundary.tsx +75 -0
- package/src/ui/util/colorPalette.tsx +122 -0
- package/src/ui/util/formatBytes.test.ts +13 -0
- package/src/ui/util/formatBytes.tsx +9 -0
- package/src/ui/util/getRandomDarkerColor.tsx +31 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {useEffect} from 'react';
|
|
2
|
+
import {runInAction} from 'mobx';
|
|
3
|
+
import {viewModel} from '../../../../model/ViewModel';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Sync mouse state into viewModel
|
|
7
|
+
*/
|
|
8
|
+
export function useMouseMoveController() {
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const onMouseMove = (e: MouseEvent) => {
|
|
11
|
+
runInAction(() => {
|
|
12
|
+
viewModel.mouseState = {x: e.offsetX, y: e.offsetY};
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
window.addEventListener('mousemove', onMouseMove);
|
|
17
|
+
|
|
18
|
+
return () => window.removeEventListener('mousemove', onMouseMove);
|
|
19
|
+
}, []);
|
|
20
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
body,
|
|
2
|
+
html {
|
|
3
|
+
margin: 0;
|
|
4
|
+
font-family: sans-serif;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
* {
|
|
8
|
+
box-sizing: border-box;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
h1,
|
|
12
|
+
h2,
|
|
13
|
+
h3,
|
|
14
|
+
h4,
|
|
15
|
+
h5,
|
|
16
|
+
h6 {
|
|
17
|
+
margin: 0;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
nav {
|
|
21
|
+
display: initial !important;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
strong {
|
|
25
|
+
font-weight: 600;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {ViewModel} from './ViewModel';
|
|
2
|
+
|
|
3
|
+
describe('ViewModel', () => {
|
|
4
|
+
describe('ViewModel::groupsById', () => {
|
|
5
|
+
it('should return a map of groups by id', () => {
|
|
6
|
+
const viewModel = new ViewModel();
|
|
7
|
+
viewModel.data = {
|
|
8
|
+
groups: [
|
|
9
|
+
{
|
|
10
|
+
id: '1',
|
|
11
|
+
type: 'bundle',
|
|
12
|
+
label: 'Bundle 1',
|
|
13
|
+
weight: 1,
|
|
14
|
+
groups: [],
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
id: '2',
|
|
18
|
+
type: 'bundle',
|
|
19
|
+
label: 'Bundle 2',
|
|
20
|
+
weight: 2,
|
|
21
|
+
groups: [],
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
expect(viewModel.groupsById.size).toBe(2);
|
|
27
|
+
expect(viewModel.groupsById.get('1')?.label).toBe('Bundle 1');
|
|
28
|
+
expect(viewModel.groupsById.get('2')?.label).toBe('Bundle 2');
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {makeAutoObservable} from 'mobx';
|
|
2
|
+
|
|
3
|
+
export class ViewModel {
|
|
4
|
+
data: BundleData | null = null;
|
|
5
|
+
focusedBundle: Group | null = null;
|
|
6
|
+
focusedGroup: Group | null = null;
|
|
7
|
+
relatedBundles: RelatedBundles | null = null;
|
|
8
|
+
hasDetails: boolean = false;
|
|
9
|
+
showLeftSidebar: boolean = true;
|
|
10
|
+
showRightSidebar: boolean = false;
|
|
11
|
+
tooltipState: TooltipState | null = null;
|
|
12
|
+
mouseState: {x: number; y: number} = {x: 0, y: 0};
|
|
13
|
+
bottomPanelHeight: number = 400;
|
|
14
|
+
|
|
15
|
+
get groupsById(): Map<string, Group> {
|
|
16
|
+
const groupsById = new Map<string, Group>();
|
|
17
|
+
|
|
18
|
+
function collectGroups(group: Group) {
|
|
19
|
+
groupsById.set(group.id, group);
|
|
20
|
+
for (const childGroup of group.groups ?? []) {
|
|
21
|
+
collectGroups(childGroup);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
for (const group of this.data?.groups ?? []) {
|
|
26
|
+
collectGroups(group);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return groupsById;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
constructor() {
|
|
33
|
+
makeAutoObservable(this);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const viewModel: ViewModel = new ViewModel();
|
|
38
|
+
|
|
39
|
+
export interface BundleData {
|
|
40
|
+
groups: Array<Group>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface RelatedBundles {
|
|
44
|
+
childBundles: Array<{id: string; displayName: string; size: number}>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type Group = {
|
|
48
|
+
id: string;
|
|
49
|
+
type: 'bundle' | 'asset';
|
|
50
|
+
label: string;
|
|
51
|
+
weight: number;
|
|
52
|
+
groups?: Array<Group>;
|
|
53
|
+
/**
|
|
54
|
+
* If this is a bundle, then the size on disk is diff. than the sum of the assets
|
|
55
|
+
* due to minification.
|
|
56
|
+
*/
|
|
57
|
+
assetTreeSize?: number;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export interface TooltipState {
|
|
61
|
+
group: Group;
|
|
62
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import '../../hack-feature-flags';
|
|
2
|
+
import '@testing-library/jest-dom';
|
|
3
|
+
import {act, render, screen} from '@testing-library/react';
|
|
4
|
+
import {ErrorBoundary} from './ErrorBoundary';
|
|
5
|
+
import {makeAutoObservable, runInAction} from 'mobx';
|
|
6
|
+
import {observer} from 'mobx-react-lite';
|
|
7
|
+
|
|
8
|
+
describe('ErrorBoundary', () => {
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
11
|
+
});
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
jest.restoreAllMocks();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should render the main content when no error is thrown', () => {
|
|
17
|
+
render(
|
|
18
|
+
<ErrorBoundary>
|
|
19
|
+
<div>Hello</div>
|
|
20
|
+
</ErrorBoundary>,
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
expect(screen.getByText('Hello')).toBeInTheDocument();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should render the fallback component when an error is thrown', () => {
|
|
27
|
+
let state = makeAutoObservable({
|
|
28
|
+
shouldThrow: false,
|
|
29
|
+
});
|
|
30
|
+
let stopThrowing = false;
|
|
31
|
+
const Throws = observer(() => {
|
|
32
|
+
if (state.shouldThrow && !stopThrowing) {
|
|
33
|
+
throw new Error('test error');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return <div>Hello</div>;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const Sample = () => {
|
|
40
|
+
return (
|
|
41
|
+
<ErrorBoundary>
|
|
42
|
+
<Throws />
|
|
43
|
+
</ErrorBoundary>
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
render(<Sample />);
|
|
48
|
+
act(() => {
|
|
49
|
+
runInAction(() => {
|
|
50
|
+
state.shouldThrow = true;
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
expect(screen.getByText('test error')).toBeInTheDocument();
|
|
55
|
+
|
|
56
|
+
act(() => {
|
|
57
|
+
stopThrowing = true;
|
|
58
|
+
screen
|
|
59
|
+
.getByTestId('atlaspack-inspector-error-boundary-reset-error')
|
|
60
|
+
.click();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
expect(screen.getByText('Hello')).toBeInTheDocument();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {CodeBlock} from '@atlaskit/code';
|
|
2
|
+
import {Stack} from '@atlaskit/primitives';
|
|
3
|
+
import Button from '@atlaskit/button/new';
|
|
4
|
+
import {Component} from 'react';
|
|
5
|
+
import * as styles from './ErrorBoundary.module.css';
|
|
6
|
+
|
|
7
|
+
interface ErrorBoundaryProps {
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
fallback?: (props: {error: Error; resetError: () => void}) => React.ReactNode;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function DefaultFallback({
|
|
13
|
+
error,
|
|
14
|
+
resetError,
|
|
15
|
+
}: {
|
|
16
|
+
error: Error;
|
|
17
|
+
resetError: () => void;
|
|
18
|
+
}) {
|
|
19
|
+
return (
|
|
20
|
+
<Stack
|
|
21
|
+
alignBlock="center"
|
|
22
|
+
alignInline="center"
|
|
23
|
+
space="space.300"
|
|
24
|
+
xcss={{
|
|
25
|
+
height: '100%',
|
|
26
|
+
width: '100%',
|
|
27
|
+
}}
|
|
28
|
+
>
|
|
29
|
+
<h1 className={styles.errorMessage}>
|
|
30
|
+
Error: <span>{error.message}</span>
|
|
31
|
+
</h1>
|
|
32
|
+
<CodeBlock text={error.stack ?? ''} />
|
|
33
|
+
<Button
|
|
34
|
+
appearance="primary"
|
|
35
|
+
onClick={resetError}
|
|
36
|
+
testId="atlaspack-inspector-error-boundary-reset-error"
|
|
37
|
+
>
|
|
38
|
+
Retry loading
|
|
39
|
+
</Button>
|
|
40
|
+
</Stack>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class ErrorBoundary extends Component<
|
|
45
|
+
ErrorBoundaryProps,
|
|
46
|
+
{error: Error | null}
|
|
47
|
+
> {
|
|
48
|
+
state = {
|
|
49
|
+
error: null as Error | null,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
componentDidCatch(error: Error): void {
|
|
53
|
+
this.setState({error});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
render() {
|
|
57
|
+
if (this.state.error) {
|
|
58
|
+
if (this.props.fallback == null) {
|
|
59
|
+
return (
|
|
60
|
+
<DefaultFallback
|
|
61
|
+
error={this.state.error}
|
|
62
|
+
resetError={() => this.setState({error: null})}
|
|
63
|
+
/>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return this.props.fallback({
|
|
68
|
+
error: this.state.error,
|
|
69
|
+
resetError: () => this.setState({error: null}),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return this.props.children;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
export const colorPalette = {
|
|
2
|
+
Lime: [
|
|
3
|
+
'#E3FCEF',
|
|
4
|
+
'#ABF5D1',
|
|
5
|
+
'#79F2C0',
|
|
6
|
+
'#57D9A3',
|
|
7
|
+
'#36B37E',
|
|
8
|
+
'#00875A',
|
|
9
|
+
'#006644',
|
|
10
|
+
'#004E3A',
|
|
11
|
+
'#003D2C',
|
|
12
|
+
'#002A1F',
|
|
13
|
+
],
|
|
14
|
+
Red: [
|
|
15
|
+
'#FFEBE6',
|
|
16
|
+
'#FFBDAD',
|
|
17
|
+
'#FF8F73',
|
|
18
|
+
'#FF7452',
|
|
19
|
+
'#FF5630',
|
|
20
|
+
'#DE350B',
|
|
21
|
+
'#BF2600',
|
|
22
|
+
'#A32100',
|
|
23
|
+
'#8A1C00',
|
|
24
|
+
'#6A1400',
|
|
25
|
+
],
|
|
26
|
+
Orange: [
|
|
27
|
+
'#FFFAE6',
|
|
28
|
+
'#FFF0B3',
|
|
29
|
+
'#FFE380',
|
|
30
|
+
'#FFC400',
|
|
31
|
+
'#FFAB00',
|
|
32
|
+
'#FF991F',
|
|
33
|
+
'#FF8B00',
|
|
34
|
+
'#FF7000',
|
|
35
|
+
'#FF5C00',
|
|
36
|
+
'#FF4A00',
|
|
37
|
+
],
|
|
38
|
+
Yellow: [
|
|
39
|
+
'#FFFAE6',
|
|
40
|
+
'#FFF0B3',
|
|
41
|
+
'#FFE380',
|
|
42
|
+
'#FFC400',
|
|
43
|
+
'#FFAB00',
|
|
44
|
+
'#FF991F',
|
|
45
|
+
'#FF8B00',
|
|
46
|
+
'#FF7000',
|
|
47
|
+
'#FF5C00',
|
|
48
|
+
'#FF4A00',
|
|
49
|
+
],
|
|
50
|
+
Green: [
|
|
51
|
+
'#E3FCEF',
|
|
52
|
+
'#ABF5D1',
|
|
53
|
+
'#79F2C0',
|
|
54
|
+
'#57D9A3',
|
|
55
|
+
'#36B37E',
|
|
56
|
+
'#00875A',
|
|
57
|
+
'#006644',
|
|
58
|
+
'#004E3A',
|
|
59
|
+
'#003D2C',
|
|
60
|
+
'#002A1F',
|
|
61
|
+
],
|
|
62
|
+
Teal: [
|
|
63
|
+
'#E6FCFF',
|
|
64
|
+
'#B3F5FF',
|
|
65
|
+
'#79E2F2',
|
|
66
|
+
'#00C7E6',
|
|
67
|
+
'#00B8D9',
|
|
68
|
+
'#00A3BF',
|
|
69
|
+
'#008DA6',
|
|
70
|
+
'#007C91',
|
|
71
|
+
'#006B7C',
|
|
72
|
+
'#005A68',
|
|
73
|
+
],
|
|
74
|
+
Blue: [
|
|
75
|
+
'#DEEBFF',
|
|
76
|
+
'#B3D4FF',
|
|
77
|
+
'#4C9AFF',
|
|
78
|
+
'#2684FF',
|
|
79
|
+
'#0065FF',
|
|
80
|
+
'#0052CC',
|
|
81
|
+
'#0747A6',
|
|
82
|
+
'#053E85',
|
|
83
|
+
'#032F6B',
|
|
84
|
+
'#021F4B',
|
|
85
|
+
],
|
|
86
|
+
Purple: [
|
|
87
|
+
'#EAE6FF',
|
|
88
|
+
'#C0B6F2',
|
|
89
|
+
'#998DD9',
|
|
90
|
+
'#8777D9',
|
|
91
|
+
'#6554C0',
|
|
92
|
+
'#5243AA',
|
|
93
|
+
'#403294',
|
|
94
|
+
'#352C63',
|
|
95
|
+
'#2B2451',
|
|
96
|
+
'#221C3F',
|
|
97
|
+
],
|
|
98
|
+
Magenta: [
|
|
99
|
+
'#FFECF8',
|
|
100
|
+
'#FFB8D2',
|
|
101
|
+
'#FF8AB8',
|
|
102
|
+
'#F797D2',
|
|
103
|
+
'#E774BB',
|
|
104
|
+
'#DA62AC',
|
|
105
|
+
'#CD519D',
|
|
106
|
+
'#AE4787',
|
|
107
|
+
'#943D73',
|
|
108
|
+
'#50253F',
|
|
109
|
+
],
|
|
110
|
+
Neutral: [
|
|
111
|
+
'#FAFBFC',
|
|
112
|
+
'#F4F5F7',
|
|
113
|
+
'#EBECF0',
|
|
114
|
+
'#DFE1E6',
|
|
115
|
+
'#C1C7D0',
|
|
116
|
+
'#B3BAC5',
|
|
117
|
+
'#A5ADBA',
|
|
118
|
+
'#8993A4',
|
|
119
|
+
'#7A869A',
|
|
120
|
+
'#6B778C',
|
|
121
|
+
],
|
|
122
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {formatBytes} from './formatBytes';
|
|
2
|
+
|
|
3
|
+
describe('formatBytes', () => {
|
|
4
|
+
it('should format bytes correctly', () => {
|
|
5
|
+
expect(formatBytes(0)).toBe('0 B');
|
|
6
|
+
expect(formatBytes(1024)).toBe('1.00 KB');
|
|
7
|
+
expect(formatBytes(1024 * 1024)).toBe('1.00 MB');
|
|
8
|
+
expect(formatBytes(1024 * 1024 * 1024)).toBe('1.00 GB');
|
|
9
|
+
|
|
10
|
+
// other examples
|
|
11
|
+
expect(formatBytes(1024 * 1024 * 2.55)).toBe('2.55 MB');
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format a number of bytes into a human-readable string.
|
|
3
|
+
*/
|
|
4
|
+
export function formatBytes(bytes: number): string {
|
|
5
|
+
const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
6
|
+
if (bytes === 0) return '0 B';
|
|
7
|
+
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
8
|
+
return (bytes / Math.pow(1024, i)).toFixed(2) + ' ' + sizes[i];
|
|
9
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {colorPalette} from './colorPalette';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Unused function.
|
|
5
|
+
*
|
|
6
|
+
* Was meant to color bundle nodes hierarchically.
|
|
7
|
+
*
|
|
8
|
+
* @deprecated
|
|
9
|
+
*/
|
|
10
|
+
export function getRandomDarkerColor(name: string): {
|
|
11
|
+
familyName: string;
|
|
12
|
+
family: string[];
|
|
13
|
+
shade: string;
|
|
14
|
+
} {
|
|
15
|
+
const hash = name.split('').reduce((acc, char) => {
|
|
16
|
+
return acc + char.charCodeAt(0);
|
|
17
|
+
}, 0);
|
|
18
|
+
const randomIndex = hash % Object.keys(colorPalette).length;
|
|
19
|
+
const randomFamily = Object.keys(colorPalette)[
|
|
20
|
+
randomIndex
|
|
21
|
+
] as keyof typeof colorPalette;
|
|
22
|
+
const darkerShades = randomFamily.slice(6);
|
|
23
|
+
const randomShade =
|
|
24
|
+
darkerShades[Math.floor(Math.random() * darkerShades.length)];
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
familyName: randomFamily,
|
|
28
|
+
family: colorPalette[randomFamily],
|
|
29
|
+
shade: randomShade,
|
|
30
|
+
};
|
|
31
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"include": ["src/**/*.ts", "src/**/*.tsx"],
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"jsx": "react-jsx",
|
|
5
|
+
"target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
|
|
6
|
+
"module": "commonjs" /* Specify what module code is generated. */,
|
|
7
|
+
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
|
|
8
|
+
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
|
|
9
|
+
"strict": true /* Enable all strict type-checking options. */,
|
|
10
|
+
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
11
|
+
}
|
|
12
|
+
}
|