@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.
Files changed (164) hide show
  1. package/.atlaspackrc +4 -0
  2. package/.eslintrc.json +19 -0
  3. package/CHANGELOG.md +12 -0
  4. package/dist/atlassian-dark-brand-refresh.91b786da.js +2 -0
  5. package/dist/atlassian-dark-brand-refresh.91b786da.js.map +1 -0
  6. package/dist/atlassian-dark-future.59ebadca.js +2 -0
  7. package/dist/atlassian-dark-future.59ebadca.js.map +1 -0
  8. package/dist/atlassian-dark-increased-contrast.ff6775f2.js +2 -0
  9. package/dist/atlassian-dark-increased-contrast.ff6775f2.js.map +1 -0
  10. package/dist/atlassian-dark.ad679134.js +2 -0
  11. package/dist/atlassian-dark.ad679134.js.map +1 -0
  12. package/dist/atlassian-legacy-dark.8aa27f7f.js +2 -0
  13. package/dist/atlassian-legacy-dark.8aa27f7f.js.map +1 -0
  14. package/dist/atlassian-legacy-light.2eb372ce.js +2 -0
  15. package/dist/atlassian-legacy-light.2eb372ce.js.map +1 -0
  16. package/dist/atlassian-light-brand-refresh.fadcab0a.js +2 -0
  17. package/dist/atlassian-light-brand-refresh.fadcab0a.js.map +1 -0
  18. package/dist/atlassian-light-future.612afe8a.js +2 -0
  19. package/dist/atlassian-light-future.612afe8a.js.map +1 -0
  20. package/dist/atlassian-light-increased-contrast.7161cd79.js +2 -0
  21. package/dist/atlassian-light-increased-contrast.7161cd79.js.map +1 -0
  22. package/dist/atlassian-light.bc343d4c.js +2 -0
  23. package/dist/atlassian-light.bc343d4c.js.map +1 -0
  24. package/dist/atlassian-shape.b92d69c0.js +2 -0
  25. package/dist/atlassian-shape.b92d69c0.js.map +1 -0
  26. package/dist/atlassian-spacing.60ddd8e7.js +2 -0
  27. package/dist/atlassian-spacing.60ddd8e7.js.map +1 -0
  28. package/dist/atlassian-typography-adg3.f88947f6.js +2 -0
  29. package/dist/atlassian-typography-adg3.f88947f6.js.map +1 -0
  30. package/dist/atlassian-typography-modernized.42016c51.js +2 -0
  31. package/dist/atlassian-typography-modernized.42016c51.js.map +1 -0
  32. package/dist/atlassian-typography-refreshed.ec0d111b.js +2 -0
  33. package/dist/atlassian-typography-refreshed.ec0d111b.js.map +1 -0
  34. package/dist/atlassian-typography.66d7e8f4.js +2 -0
  35. package/dist/atlassian-typography.66d7e8f4.js.map +1 -0
  36. package/dist/badge-light.7e55986a.png +0 -0
  37. package/dist/custom-theme.4680282a.js +2 -0
  38. package/dist/custom-theme.4680282a.js.map +1 -0
  39. package/dist/drag-handle.136830d3.js +2 -0
  40. package/dist/drag-handle.136830d3.js.map +1 -0
  41. package/dist/drag-handle.63bdb345.css +2 -0
  42. package/dist/drag-handle.63bdb345.css.map +1 -0
  43. package/dist/index.13289f53.js +28 -0
  44. package/dist/index.13289f53.js.map +1 -0
  45. package/dist/index.a41fafce.css +2 -0
  46. package/dist/index.a41fafce.css.map +1 -0
  47. package/dist/index.html +1 -0
  48. package/dist/index.runtime.3c39d71d.js +2 -0
  49. package/dist/index.runtime.3c39d71d.js.map +1 -0
  50. package/dist/refractor.2c1fd9a1.js +2 -0
  51. package/dist/refractor.2c1fd9a1.js.map +1 -0
  52. package/index.html +11 -0
  53. package/jest.config.js +16 -0
  54. package/package.json +64 -0
  55. package/src/APIError.test.ts +72 -0
  56. package/src/APIError.tsx +29 -0
  57. package/src/AppRoutes.tsx +56 -0
  58. package/src/hack-feature-flags.ts +6 -0
  59. package/src/main.tsx +50 -0
  60. package/src/test/stubCssModule.js +1 -0
  61. package/src/ui/App.module.css +122 -0
  62. package/src/ui/App.module.css.d.ts +8 -0
  63. package/src/ui/AppLayout/AppLayout.tsx +26 -0
  64. package/src/ui/AppLayout/SidebarNavigation/LinkItem.tsx +26 -0
  65. package/src/ui/AppLayout/SidebarNavigation/SidebarNavigation.tsx +45 -0
  66. package/src/ui/AppLayout/TopNavigation/Logo.module.css +12 -0
  67. package/src/ui/AppLayout/TopNavigation/Logo.module.css.d.ts +4 -0
  68. package/src/ui/AppLayout/TopNavigation/Logo.tsx +11 -0
  69. package/src/ui/AppLayout/TopNavigation/TopNavigation.module.css +14 -0
  70. package/src/ui/AppLayout/TopNavigation/TopNavigation.module.css.d.ts +3 -0
  71. package/src/ui/AppLayout/TopNavigation/TopNavigation.tsx +45 -0
  72. package/src/ui/AppLayout/TopNavigation/badge-light.png +0 -0
  73. package/src/ui/AppLayout/TopNavigation/logo-light.png +0 -0
  74. package/src/ui/DefaultLoadingIndicator/DefaultLoadingIndicator.module.css +9 -0
  75. package/src/ui/DefaultLoadingIndicator/DefaultLoadingIndicator.module.css.d.ts +3 -0
  76. package/src/ui/DefaultLoadingIndicator/DefaultLoadingIndicator.test.tsx +15 -0
  77. package/src/ui/DefaultLoadingIndicator/DefaultLoadingIndicator.tsx +14 -0
  78. package/src/ui/app/StatsPage.tsx +77 -0
  79. package/src/ui/app/cache/CacheKeysIndexPage.tsx +13 -0
  80. package/src/ui/app/cache/CacheKeysPage.module.css +11 -0
  81. package/src/ui/app/cache/CacheKeysPage.module.css.d.ts +4 -0
  82. package/src/ui/app/cache/CacheKeysPage.tsx +23 -0
  83. package/src/ui/app/cache/[key]/CacheValuePage.tsx +40 -0
  84. package/src/ui/app/cache/ui/CacheKeyList.module.css +40 -0
  85. package/src/ui/app/cache/ui/CacheKeyList.module.css.d.ts +7 -0
  86. package/src/ui/app/cache/ui/CacheKeyList.tsx +187 -0
  87. package/src/ui/app/cache-invalidation/CacheInvalidationPage.tsx +22 -0
  88. package/src/ui/app/cache-invalidation/[fileId]/CacheInvalidationFilePage.tsx +22 -0
  89. package/src/ui/app/cache-invalidation/ui/CacheFileList.module.css +40 -0
  90. package/src/ui/app/cache-invalidation/ui/CacheFileList.module.css.d.ts +7 -0
  91. package/src/ui/app/cache-invalidation/ui/CacheFileList.tsx +185 -0
  92. package/src/ui/app/treemap/BottomPanelResizeState.test.ts +25 -0
  93. package/src/ui/app/treemap/BottomPanelResizeState.tsx +48 -0
  94. package/src/ui/app/treemap/FoamTreemapPage.module.css +24 -0
  95. package/src/ui/app/treemap/FoamTreemapPage.module.css.d.ts +6 -0
  96. package/src/ui/app/treemap/FoamTreemapPage.tsx +47 -0
  97. package/src/ui/app/treemap/controllers/RelatedBundlesController.tsx +41 -0
  98. package/src/ui/app/treemap/controllers/UrlFocusController.tsx +33 -0
  99. package/src/ui/app/treemap/ui/BottomPanel/BottomPanel.module.css +24 -0
  100. package/src/ui/app/treemap/ui/BottomPanel/BottomPanel.module.css.d.ts +5 -0
  101. package/src/ui/app/treemap/ui/BottomPanel/BottomPanel.tsx +24 -0
  102. package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/AdvancedSettings.module.css +13 -0
  103. package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/AdvancedSettings.module.css.d.ts +5 -0
  104. package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/AdvancedSettings.tsx +53 -0
  105. package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/AssetTable/AssetTable.tsx +135 -0
  106. package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/AssetTable/CollapsibleTable/CollapsibleTable.module.css +7 -0
  107. package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/AssetTable/CollapsibleTable/CollapsibleTable.module.css.d.ts +3 -0
  108. package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/AssetTable/CollapsibleTable/CollapsibleTable.tsx +123 -0
  109. package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/AssetTable/CollapsibleTable/CollapsibleTableModel.tsx +18 -0
  110. package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/AssetTable/CollapsibleTable/CollapsibleTableRow.module.css +20 -0
  111. package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/AssetTable/CollapsibleTable/CollapsibleTableRow.module.css.d.ts +6 -0
  112. package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/AssetTable/CollapsibleTable/CollapsibleTableRow.tsx +79 -0
  113. package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/AssetTable/getFileURL.test.ts +19 -0
  114. package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/AssetTable/getFileURL.ts +24 -0
  115. package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/FocusedGroupInfo.module.css +20 -0
  116. package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/FocusedGroupInfo.module.css.d.ts +5 -0
  117. package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/FocusedGroupInfo.tsx +42 -0
  118. package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/FocusedGroupInfoInner.module.css +29 -0
  119. package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/FocusedGroupInfoInner.module.css.d.ts +6 -0
  120. package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/FocusedGroupInfoInner.tsx +107 -0
  121. package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/GraphContainer.module.css +7 -0
  122. package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/GraphContainer.module.css.d.ts +3 -0
  123. package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/GraphContainer.tsx +20 -0
  124. package/src/ui/app/treemap/ui/BottomPanel/FocusedGroupInfo/SourceCodeURL.tsx +5 -0
  125. package/src/ui/app/treemap/ui/BundleGraphRenderer.module.css +13 -0
  126. package/src/ui/app/treemap/ui/BundleGraphRenderer.module.css.d.ts +4 -0
  127. package/src/ui/app/treemap/ui/BundleGraphRenderer.tsx +95 -0
  128. package/src/ui/app/treemap/ui/FocusBreadcrumbs/FocusBreadcrumbs.module.css +6 -0
  129. package/src/ui/app/treemap/ui/FocusBreadcrumbs/FocusBreadcrumbs.module.css.d.ts +3 -0
  130. package/src/ui/app/treemap/ui/FocusBreadcrumbs/FocusBreadcrumbs.tsx +49 -0
  131. package/src/ui/app/treemap/ui/SigmaGraph.module.css +5 -0
  132. package/src/ui/app/treemap/ui/SigmaGraph.module.css.d.ts +3 -0
  133. package/src/ui/app/treemap/ui/SigmaGraph.tsx +80 -0
  134. package/src/ui/app/treemap/ui/Treemap.tsx +14 -0
  135. package/src/ui/app/treemap/ui/TreemapRenderer/ImpactScore.module.css +32 -0
  136. package/src/ui/app/treemap/ui/TreemapRenderer/ImpactScore.module.css.d.ts +5 -0
  137. package/src/ui/app/treemap/ui/TreemapRenderer/ImpactScore.tsx +24 -0
  138. package/src/ui/app/treemap/ui/TreemapRenderer/TreemapRenderer.module.css +14 -0
  139. package/src/ui/app/treemap/ui/TreemapRenderer/TreemapRenderer.module.css.d.ts +4 -0
  140. package/src/ui/app/treemap/ui/TreemapRenderer/TreemapRenderer.tsx +271 -0
  141. package/src/ui/app/treemap/ui/TreemapRenderer/TreemapTooltip.module.css +15 -0
  142. package/src/ui/app/treemap/ui/TreemapRenderer/TreemapTooltip.module.css.d.ts +4 -0
  143. package/src/ui/app/treemap/ui/TreemapRenderer/TreemapTooltip.tsx +111 -0
  144. package/src/ui/app/treemap/ui/TreemapRenderer/controllers/useStableCallback.test.ts +27 -0
  145. package/src/ui/app/treemap/ui/TreemapRenderer/controllers/useStableCallback.ts +21 -0
  146. package/src/ui/app/treemap/ui/TreemapRenderer/useMouseMoveController.ts +20 -0
  147. package/src/ui/globals.css +26 -0
  148. package/src/ui/globals.css.d.ts +1 -0
  149. package/src/ui/globals.d.ts +9 -0
  150. package/src/ui/model/ViewModel.test.ts +31 -0
  151. package/src/ui/model/ViewModel.ts +62 -0
  152. package/src/ui/not-found/NotFoundPage.module.css +7 -0
  153. package/src/ui/not-found/NotFoundPage.module.css.d.ts +3 -0
  154. package/src/ui/not-found/NotFoundPage.tsx +9 -0
  155. package/src/ui/types/Graph.tsx +12 -0
  156. package/src/ui/util/ErrorBoundary.module.css +3 -0
  157. package/src/ui/util/ErrorBoundary.module.css.d.ts +3 -0
  158. package/src/ui/util/ErrorBoundary.test.tsx +65 -0
  159. package/src/ui/util/ErrorBoundary.tsx +75 -0
  160. package/src/ui/util/colorPalette.tsx +122 -0
  161. package/src/ui/util/formatBytes.test.ts +13 -0
  162. package/src/ui/util/formatBytes.tsx +9 -0
  163. package/src/ui/util/getRandomDarkerColor.tsx +31 -0
  164. 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,9 @@
1
+ declare module '*.png' {
2
+ const content: string;
3
+ export default content;
4
+ }
5
+
6
+ declare module '*.module.css' {
7
+ const content: Record<string, string>;
8
+ export default content;
9
+ }
@@ -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,7 @@
1
+ .notFoundPage {
2
+ display: flex;
3
+ padding-top: 100px;
4
+ flex-direction: column;
5
+ gap: 8px;
6
+ align-items: center;
7
+ }
@@ -0,0 +1,3 @@
1
+ export const __esModule: true;
2
+ export const notFoundPage: string;
3
+
@@ -0,0 +1,9 @@
1
+ import * as styles from './NotFoundPage.module.css';
2
+
3
+ export function NotFoundPage() {
4
+ return (
5
+ <div className={styles.notFoundPage}>
6
+ <h1>404: Page not found</h1>
7
+ </div>
8
+ );
9
+ }
@@ -0,0 +1,12 @@
1
+ export interface Node<T = null> {
2
+ id: string;
3
+ nodeId: string;
4
+ path: string[] | null;
5
+ displayName: string;
6
+ level: number;
7
+ edges: string[];
8
+ extra: T;
9
+ }
10
+ export interface Graph<T = null> {
11
+ nodes: Node<T>[];
12
+ }
@@ -0,0 +1,3 @@
1
+ .errorMessage {
2
+ padding-top: 32px;
3
+ }
@@ -0,0 +1,3 @@
1
+ export const __esModule: true;
2
+ export const errorMessage: string;
3
+
@@ -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
+ }