@cloud-ru/ft-storybook-deps-graph-addon 1.0.1-preview-2888ee9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -0
- package/LICENSE +201 -0
- package/README.md +15 -0
- package/dist/cjs/components/ErrorBoundary/ErrorBoundary.d.ts +15 -0
- package/dist/cjs/components/ErrorBoundary/ErrorBoundary.js +28 -0
- package/dist/cjs/components/ErrorBoundary/index.d.ts +1 -0
- package/dist/cjs/components/ErrorBoundary/index.js +17 -0
- package/dist/cjs/components/Graph/Graph.d.ts +8 -0
- package/dist/cjs/components/Graph/Graph.js +97 -0
- package/dist/cjs/components/Graph/index.d.ts +1 -0
- package/dist/cjs/components/Graph/index.js +17 -0
- package/dist/cjs/components/NotFound/NotFound.d.ts +1 -0
- package/dist/cjs/components/NotFound/NotFound.js +8 -0
- package/dist/cjs/components/NotFound/index.d.ts +1 -0
- package/dist/cjs/components/NotFound/index.js +17 -0
- package/dist/cjs/components/Panel/Panel.d.ts +1 -0
- package/dist/cjs/components/Panel/Panel.js +32 -0
- package/dist/cjs/components/Panel/index.d.ts +1 -0
- package/dist/cjs/components/Panel/index.js +17 -0
- package/dist/cjs/components/index.d.ts +2 -0
- package/dist/cjs/components/index.js +18 -0
- package/dist/cjs/const.d.ts +18 -0
- package/dist/cjs/const.js +21 -0
- package/dist/cjs/register.d.ts +1 -0
- package/dist/cjs/register.js +18 -0
- package/dist/cjs/styles.css +19 -0
- package/dist/cjs/types.d.ts +22 -0
- package/dist/cjs/types.js +8 -0
- package/dist/cjs/utils.d.ts +6 -0
- package/dist/cjs/utils.js +66 -0
- package/dist/esm/components/ErrorBoundary/ErrorBoundary.d.ts +15 -0
- package/dist/esm/components/ErrorBoundary/ErrorBoundary.js +24 -0
- package/dist/esm/components/ErrorBoundary/index.d.ts +1 -0
- package/dist/esm/components/ErrorBoundary/index.js +1 -0
- package/dist/esm/components/Graph/Graph.d.ts +8 -0
- package/dist/esm/components/Graph/Graph.js +90 -0
- package/dist/esm/components/Graph/index.d.ts +1 -0
- package/dist/esm/components/Graph/index.js +1 -0
- package/dist/esm/components/NotFound/NotFound.d.ts +1 -0
- package/dist/esm/components/NotFound/NotFound.js +4 -0
- package/dist/esm/components/NotFound/index.d.ts +1 -0
- package/dist/esm/components/NotFound/index.js +1 -0
- package/dist/esm/components/Panel/Panel.d.ts +1 -0
- package/dist/esm/components/Panel/Panel.js +28 -0
- package/dist/esm/components/Panel/index.d.ts +1 -0
- package/dist/esm/components/Panel/index.js +1 -0
- package/dist/esm/components/index.d.ts +2 -0
- package/dist/esm/components/index.js +2 -0
- package/dist/esm/const.d.ts +18 -0
- package/dist/esm/const.js +18 -0
- package/dist/esm/register.d.ts +1 -0
- package/dist/esm/register.js +16 -0
- package/dist/esm/styles.css +19 -0
- package/dist/esm/types.d.ts +22 -0
- package/dist/esm/types.js +5 -0
- package/dist/esm/utils.d.ts +6 -0
- package/dist/esm/utils.js +62 -0
- package/package.json +50 -0
- package/preset.js +5 -0
- package/src/components/ErrorBoundary/ErrorBoundary.tsx +34 -0
- package/src/components/ErrorBoundary/index.ts +1 -0
- package/src/components/Graph/Graph.tsx +113 -0
- package/src/components/Graph/index.ts +1 -0
- package/src/components/NotFound/NotFound.tsx +8 -0
- package/src/components/NotFound/index.ts +1 -0
- package/src/components/Panel/Panel.tsx +35 -0
- package/src/components/Panel/index.ts +1 -0
- package/src/components/index.ts +2 -0
- package/src/const.ts +18 -0
- package/src/register.tsx +25 -0
- package/src/styles.css +19 -0
- package/src/types.ts +27 -0
- package/src/utils.ts +95 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractSubgraph = void 0;
|
|
4
|
+
const createNode = (name) => ({
|
|
5
|
+
data: {
|
|
6
|
+
id: name,
|
|
7
|
+
label: name,
|
|
8
|
+
},
|
|
9
|
+
});
|
|
10
|
+
const createLink = (source, target, isReversed) => {
|
|
11
|
+
if (isReversed) {
|
|
12
|
+
return {
|
|
13
|
+
data: {
|
|
14
|
+
source: target,
|
|
15
|
+
target: source,
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
data: {
|
|
21
|
+
source,
|
|
22
|
+
target,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
const isLinkElement = (element) => 'source' in element.data && 'target' in element.data;
|
|
27
|
+
const getKey = (element) => {
|
|
28
|
+
if (isLinkElement(element)) {
|
|
29
|
+
return element.data.source + element.data.target;
|
|
30
|
+
}
|
|
31
|
+
return element.data.id + element.data.label;
|
|
32
|
+
};
|
|
33
|
+
function deleteDuplicateElements(graph) {
|
|
34
|
+
const usedKeys = new Set();
|
|
35
|
+
return graph.filter(graphElement => {
|
|
36
|
+
const key = getKey(graphElement);
|
|
37
|
+
if (usedKeys.has(key)) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
usedKeys.add(key);
|
|
41
|
+
return true;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const extractSubgraph = ({ title, links, graphType, }) => {
|
|
45
|
+
const result = [];
|
|
46
|
+
const usedNodes = new Set();
|
|
47
|
+
const isReversedGraph = graphType === 'parent';
|
|
48
|
+
const helper = (storyName, children) => () => {
|
|
49
|
+
result.push(createNode(storyName));
|
|
50
|
+
const queue = [];
|
|
51
|
+
if (!Array.isArray(children)) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
children.forEach(child => {
|
|
55
|
+
if (!usedNodes.has(child)) {
|
|
56
|
+
result.push(createLink(storyName, child, isReversedGraph));
|
|
57
|
+
}
|
|
58
|
+
usedNodes.add(child);
|
|
59
|
+
queue.push(helper(child, links[child]));
|
|
60
|
+
});
|
|
61
|
+
queue.forEach(func => func());
|
|
62
|
+
};
|
|
63
|
+
helper(title, links[title])();
|
|
64
|
+
return deleteDuplicateElements(result);
|
|
65
|
+
};
|
|
66
|
+
exports.extractSubgraph = extractSubgraph;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import '../../styles.css';
|
|
2
|
+
import { Component, ReactNode } from 'react';
|
|
3
|
+
type Props = {
|
|
4
|
+
children?: ReactNode;
|
|
5
|
+
};
|
|
6
|
+
type State = {
|
|
7
|
+
hasError: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare class ErrorBoundary extends Component<Props, State> {
|
|
10
|
+
state: State;
|
|
11
|
+
static getDerivedStateFromError(): State;
|
|
12
|
+
componentDidCatch(error: unknown): void;
|
|
13
|
+
render(): string | number | boolean | import("react/jsx-runtime").JSX.Element | Iterable<ReactNode> | null | undefined;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import '../../styles.css';
|
|
3
|
+
import { Component } from 'react';
|
|
4
|
+
export class ErrorBoundary extends Component {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this.state = { hasError: false };
|
|
8
|
+
}
|
|
9
|
+
static getDerivedStateFromError() {
|
|
10
|
+
return {
|
|
11
|
+
hasError: true,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
componentDidCatch(error) {
|
|
15
|
+
// eslint-disable-next-line no-console
|
|
16
|
+
console.error(error);
|
|
17
|
+
}
|
|
18
|
+
render() {
|
|
19
|
+
if (this.state.hasError) {
|
|
20
|
+
return _jsx("div", Object.assign({ className: 'deps_graph__error' }, { children: "\u041F\u0440\u043E\u0438\u0437\u043E\u0448\u043B\u0430 \u043E\u0448\u0438\u0431\u043A\u0430 \u043F\u0440\u0438 \u043F\u043E\u0441\u0442\u0440\u043E\u0435\u043D\u0438\u0438 \u0433\u0440\u0430\u0444\u0430." }));
|
|
21
|
+
}
|
|
22
|
+
return this.props.children;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ErrorBoundary';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ErrorBoundary';
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useTheme } from '@storybook/theming';
|
|
3
|
+
import Cytoscape from 'cytoscape';
|
|
4
|
+
import dagre from 'cytoscape-dagre';
|
|
5
|
+
import { useEffect, useRef } from 'react';
|
|
6
|
+
import { color } from '../../const';
|
|
7
|
+
Cytoscape.use(dagre);
|
|
8
|
+
const layout = {
|
|
9
|
+
name: 'dagre',
|
|
10
|
+
padding: 50,
|
|
11
|
+
nodeDimensionsIncludeLabels: true,
|
|
12
|
+
nodeSep: 7,
|
|
13
|
+
};
|
|
14
|
+
export function Graph({ storyName, elements }) {
|
|
15
|
+
const containerRef = useRef(null);
|
|
16
|
+
const cyRef = useRef();
|
|
17
|
+
const { base } = useTheme();
|
|
18
|
+
const themeColors = color[base] || color.light;
|
|
19
|
+
const cytoscapeStylesheet = [
|
|
20
|
+
{
|
|
21
|
+
selector: 'node',
|
|
22
|
+
style: {
|
|
23
|
+
'background-color': themeColors.componentBackground,
|
|
24
|
+
width: 'label',
|
|
25
|
+
height: 'label',
|
|
26
|
+
'padding-top': '8',
|
|
27
|
+
'padding-bottom': '8',
|
|
28
|
+
'padding-left': '8',
|
|
29
|
+
'padding-right': '8',
|
|
30
|
+
shape: 'round-rectangle',
|
|
31
|
+
'text-margin-y': -1,
|
|
32
|
+
'border-width': 2,
|
|
33
|
+
'border-color': themeColors.componentBorder,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
selector: 'node[label]',
|
|
38
|
+
style: {
|
|
39
|
+
label: 'data(label)',
|
|
40
|
+
'font-size': '12',
|
|
41
|
+
color: themeColors.componentFontColor,
|
|
42
|
+
'text-halign': 'center',
|
|
43
|
+
'text-valign': 'center',
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
selector: `node[label='${storyName}']`,
|
|
48
|
+
style: {
|
|
49
|
+
'background-color': themeColors.selectedComponentBackground,
|
|
50
|
+
'padding-top': '14',
|
|
51
|
+
'padding-bottom': '14',
|
|
52
|
+
'padding-left': '14',
|
|
53
|
+
'padding-right': '14',
|
|
54
|
+
'border-width': '0',
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
selector: `node[label='${storyName}'][label]`,
|
|
59
|
+
style: {
|
|
60
|
+
'font-size': '16',
|
|
61
|
+
color: themeColors.selectedComponentFontColor,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
selector: 'edge',
|
|
66
|
+
style: {
|
|
67
|
+
'curve-style': 'bezier',
|
|
68
|
+
'target-arrow-shape': 'triangle',
|
|
69
|
+
'target-arrow-color': themeColors.arrowBackground,
|
|
70
|
+
'line-color': themeColors.arrowBackground,
|
|
71
|
+
width: 2,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
];
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
cyRef.current = Cytoscape({
|
|
77
|
+
container: containerRef.current,
|
|
78
|
+
elements: elements,
|
|
79
|
+
layout,
|
|
80
|
+
style: cytoscapeStylesheet,
|
|
81
|
+
zoom: 2,
|
|
82
|
+
maxZoom: 2,
|
|
83
|
+
});
|
|
84
|
+
const cy = cyRef.current;
|
|
85
|
+
return () => {
|
|
86
|
+
cy.destroy();
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
return (_jsx("div", { className: 'deps_graph__wrapper', ref: containerRef, style: { backgroundColor: themeColors.componentBackground } }));
|
|
90
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Graph';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Graph';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function NotFound(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
export function NotFound() {
|
|
3
|
+
return (_jsxs("div", Object.assign({ className: 'deps_graph__info' }, { children: [_jsx("div", { children: "\u041D\u0435 \u0432\u044B\u0431\u0440\u0430\u043D \u043A\u043E\u043C\u043F\u043E\u043D\u0435\u043D\u0442." }), _jsx("div", { children: "\u041F\u043E\u0436\u0430\u043B\u0443\u0439\u0441\u0442\u0430, \u0432\u044B\u0431\u0435\u0440\u0438\u0442\u0435 UI \u043A\u043E\u0441\u043F\u043E\u043D\u0435\u043D\u0442 \u0434\u043B\u044F \u043E\u0442\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u044F \u0433\u0440\u0430\u0444\u0430." })] })));
|
|
4
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './NotFound';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './NotFound';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Panel(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useParameter } from '@storybook/manager-api';
|
|
3
|
+
import { GraphType } from '../../types';
|
|
4
|
+
import { extractSubgraph } from '../../utils';
|
|
5
|
+
import { Graph } from '../Graph';
|
|
6
|
+
import { NotFound } from '../NotFound';
|
|
7
|
+
export function Panel() {
|
|
8
|
+
const pkgName = useParameter('packageName');
|
|
9
|
+
const dependenciesGraph = useParameter('dependenciesGraph');
|
|
10
|
+
if (!pkgName || !dependenciesGraph) {
|
|
11
|
+
return _jsx(NotFound, {});
|
|
12
|
+
}
|
|
13
|
+
const storyName = pkgName.includes('snack-ui')
|
|
14
|
+
? pkgName.split('/')[1]
|
|
15
|
+
: pkgName.replace('@cloud-ru/uikit-product-', '');
|
|
16
|
+
const parents = extractSubgraph({
|
|
17
|
+
title: storyName,
|
|
18
|
+
links: dependenciesGraph.graphLinks.reversedLinks,
|
|
19
|
+
graphType: GraphType.Parent,
|
|
20
|
+
});
|
|
21
|
+
const children = extractSubgraph({
|
|
22
|
+
title: storyName,
|
|
23
|
+
links: dependenciesGraph.graphLinks.links,
|
|
24
|
+
graphType: GraphType.Children,
|
|
25
|
+
});
|
|
26
|
+
const graph = [...parents, ...children];
|
|
27
|
+
return _jsx(Graph, { storyName: storyName, elements: graph });
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Panel';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Panel';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const color: {
|
|
2
|
+
dark: {
|
|
3
|
+
selectedComponentBackground: string;
|
|
4
|
+
selectedComponentFontColor: string;
|
|
5
|
+
componentFontColor: string;
|
|
6
|
+
componentBorder: string;
|
|
7
|
+
componentBackground: string;
|
|
8
|
+
arrowBackground: string;
|
|
9
|
+
};
|
|
10
|
+
light: {
|
|
11
|
+
selectedComponentBackground: string;
|
|
12
|
+
selectedComponentFontColor: string;
|
|
13
|
+
componentFontColor: string;
|
|
14
|
+
componentBorder: string;
|
|
15
|
+
componentBackground: string;
|
|
16
|
+
arrowBackground: string;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const color = {
|
|
2
|
+
dark: {
|
|
3
|
+
selectedComponentBackground: '#997adc',
|
|
4
|
+
selectedComponentFontColor: '#130f25',
|
|
5
|
+
componentFontColor: '#9e9e9e',
|
|
6
|
+
componentBorder: '#898989',
|
|
7
|
+
componentBackground: '#181818',
|
|
8
|
+
arrowBackground: '#898989',
|
|
9
|
+
},
|
|
10
|
+
light: {
|
|
11
|
+
selectedComponentBackground: '#794ed3',
|
|
12
|
+
selectedComponentFontColor: '#fdfbff',
|
|
13
|
+
componentFontColor: '#565656',
|
|
14
|
+
componentBorder: '#757575',
|
|
15
|
+
componentBackground: '#f9f9f9',
|
|
16
|
+
arrowBackground: '#757575',
|
|
17
|
+
},
|
|
18
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { AddonPanel } from '@storybook/components';
|
|
3
|
+
import { addons, types } from '@storybook/manager-api';
|
|
4
|
+
import { ErrorBoundary, Panel } from './components';
|
|
5
|
+
const ADDON_ID = '@cloud-ru/ft-storybook-dependencies-graph-addon';
|
|
6
|
+
const PANEL_ID = `${ADDON_ID}/panel`;
|
|
7
|
+
addons.register(ADDON_ID, () => {
|
|
8
|
+
addons.add(PANEL_ID, {
|
|
9
|
+
type: types.PANEL,
|
|
10
|
+
title: 'Dependencies graph',
|
|
11
|
+
match: ({ viewMode }) => viewMode === 'story',
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
render: ({ active = false, key }) => (_jsx(AddonPanel, Object.assign({ active: active }, { children: _jsx(ErrorBoundary, { children: _jsx(Panel, {}) }) }), key)),
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
.deps_graph__error{
|
|
2
|
+
text-align: center;
|
|
3
|
+
margin-top: 40px;
|
|
4
|
+
font-size: 16px;
|
|
5
|
+
}
|
|
6
|
+
.deps_graph__info{
|
|
7
|
+
text-align: center;
|
|
8
|
+
margin-top: 40px;
|
|
9
|
+
font-size: 16px;
|
|
10
|
+
}
|
|
11
|
+
.deps_graph__info div:first-of-type{
|
|
12
|
+
font-weight: 500;
|
|
13
|
+
}
|
|
14
|
+
.deps_graph__wrapper{
|
|
15
|
+
top: 0;
|
|
16
|
+
bottom: 0;
|
|
17
|
+
position: absolute;
|
|
18
|
+
width: 100%;
|
|
19
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type LinksType = Record<string, string[]>;
|
|
2
|
+
export type DependenciesGraphType = {
|
|
3
|
+
reversedLinks: LinksType;
|
|
4
|
+
links: LinksType;
|
|
5
|
+
};
|
|
6
|
+
export type NodeElementType = {
|
|
7
|
+
data: {
|
|
8
|
+
id: string;
|
|
9
|
+
label: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export type LinkElementType = {
|
|
13
|
+
data: {
|
|
14
|
+
source: string;
|
|
15
|
+
target: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export declare enum GraphType {
|
|
19
|
+
Children = "children",
|
|
20
|
+
Parent = "parent"
|
|
21
|
+
}
|
|
22
|
+
export type GraphElementType = NodeElementType | LinkElementType;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const createNode = (name) => ({
|
|
2
|
+
data: {
|
|
3
|
+
id: name,
|
|
4
|
+
label: name,
|
|
5
|
+
},
|
|
6
|
+
});
|
|
7
|
+
const createLink = (source, target, isReversed) => {
|
|
8
|
+
if (isReversed) {
|
|
9
|
+
return {
|
|
10
|
+
data: {
|
|
11
|
+
source: target,
|
|
12
|
+
target: source,
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
data: {
|
|
18
|
+
source,
|
|
19
|
+
target,
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
const isLinkElement = (element) => 'source' in element.data && 'target' in element.data;
|
|
24
|
+
const getKey = (element) => {
|
|
25
|
+
if (isLinkElement(element)) {
|
|
26
|
+
return element.data.source + element.data.target;
|
|
27
|
+
}
|
|
28
|
+
return element.data.id + element.data.label;
|
|
29
|
+
};
|
|
30
|
+
function deleteDuplicateElements(graph) {
|
|
31
|
+
const usedKeys = new Set();
|
|
32
|
+
return graph.filter(graphElement => {
|
|
33
|
+
const key = getKey(graphElement);
|
|
34
|
+
if (usedKeys.has(key)) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
usedKeys.add(key);
|
|
38
|
+
return true;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
export const extractSubgraph = ({ title, links, graphType, }) => {
|
|
42
|
+
const result = [];
|
|
43
|
+
const usedNodes = new Set();
|
|
44
|
+
const isReversedGraph = graphType === 'parent';
|
|
45
|
+
const helper = (storyName, children) => () => {
|
|
46
|
+
result.push(createNode(storyName));
|
|
47
|
+
const queue = [];
|
|
48
|
+
if (!Array.isArray(children)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
children.forEach(child => {
|
|
52
|
+
if (!usedNodes.has(child)) {
|
|
53
|
+
result.push(createLink(storyName, child, isReversedGraph));
|
|
54
|
+
}
|
|
55
|
+
usedNodes.add(child);
|
|
56
|
+
queue.push(helper(child, links[child]));
|
|
57
|
+
});
|
|
58
|
+
queue.forEach(func => func());
|
|
59
|
+
};
|
|
60
|
+
helper(title, links[title])();
|
|
61
|
+
return deleteDuplicateElements(result);
|
|
62
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cloud-ru/ft-storybook-deps-graph-addon",
|
|
3
|
+
"version": "1.0.1-preview-2888ee9.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"description": "storybook dependencies graph",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"packages",
|
|
10
|
+
"storybook",
|
|
11
|
+
"addon",
|
|
12
|
+
"dependencies"
|
|
13
|
+
],
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@storybook/components": "7.0.26",
|
|
16
|
+
"@storybook/manager-api": "7.0.26",
|
|
17
|
+
"cytoscape": "3.26.0",
|
|
18
|
+
"cytoscape-dagre": "2.5.0"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"react": "^17.0.2 || ^18.0.0",
|
|
22
|
+
"react-dom": "^17.0.2 || ^18.0.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/cytoscape": "3.19.10",
|
|
26
|
+
"@types/cytoscape-dagre": "2.3.0",
|
|
27
|
+
"@types/react": "18.2.14",
|
|
28
|
+
"react": "18.2.0",
|
|
29
|
+
"react-dom": "18.2.0"
|
|
30
|
+
},
|
|
31
|
+
"license": "Apache-2.0",
|
|
32
|
+
"types": "./dist/esm/index.d.ts",
|
|
33
|
+
"files": [
|
|
34
|
+
"src",
|
|
35
|
+
"dist/cjs",
|
|
36
|
+
"dist/esm",
|
|
37
|
+
"preset.js",
|
|
38
|
+
"./CHANGELOG.md"
|
|
39
|
+
],
|
|
40
|
+
"homepage": "https://github.com/cloud-ru-tech/frontend-tools/tree/master/packages/storybook-deps-graph-addon",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "https://github.com/cloud-ru-tech/frontend-tools.git",
|
|
44
|
+
"directory": "packages/storybook-deps-graph-addon"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"compile": "ts-node scripts/custom-copy.ts"
|
|
48
|
+
},
|
|
49
|
+
"gitHead": "7daac1875ad43c55871834717454c4c2d371a2a9"
|
|
50
|
+
}
|
package/preset.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import '../../styles.css';
|
|
2
|
+
|
|
3
|
+
import { Component, ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
type Props = {
|
|
6
|
+
children?: ReactNode;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
type State = {
|
|
10
|
+
hasError: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export class ErrorBoundary extends Component<Props, State> {
|
|
14
|
+
public state: State = { hasError: false };
|
|
15
|
+
|
|
16
|
+
static getDerivedStateFromError(): State {
|
|
17
|
+
return {
|
|
18
|
+
hasError: true,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public componentDidCatch(error: unknown): void {
|
|
23
|
+
// eslint-disable-next-line no-console
|
|
24
|
+
console.error(error);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public render() {
|
|
28
|
+
if (this.state.hasError) {
|
|
29
|
+
return <div className={'deps_graph__error'}>Произошла ошибка при построении графа.</div>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return this.props.children;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ErrorBoundary';
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { useTheme } from '@storybook/theming';
|
|
2
|
+
import Cytoscape from 'cytoscape';
|
|
3
|
+
import dagre from 'cytoscape-dagre';
|
|
4
|
+
import React, { ReactElement, useEffect, useRef } from 'react';
|
|
5
|
+
|
|
6
|
+
import { color } from '../../const';
|
|
7
|
+
import { GraphElementType } from '../../types';
|
|
8
|
+
|
|
9
|
+
Cytoscape.use(dagre);
|
|
10
|
+
|
|
11
|
+
const layout = {
|
|
12
|
+
name: 'dagre',
|
|
13
|
+
padding: 50,
|
|
14
|
+
nodeDimensionsIncludeLabels: true,
|
|
15
|
+
nodeSep: 7,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type GraphProps = {
|
|
19
|
+
storyName: string;
|
|
20
|
+
elements: GraphElementType[];
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export function Graph({ storyName, elements }: GraphProps): ReactElement {
|
|
24
|
+
const containerRef = useRef(null);
|
|
25
|
+
const cyRef = useRef<Cytoscape.Core>();
|
|
26
|
+
|
|
27
|
+
const { base } = useTheme() as unknown as { base: 'light' | 'dark' };
|
|
28
|
+
|
|
29
|
+
const themeColors = color[base] || color.light;
|
|
30
|
+
|
|
31
|
+
const cytoscapeStylesheet: Array<cytoscape.Stylesheet> = [
|
|
32
|
+
{
|
|
33
|
+
selector: 'node',
|
|
34
|
+
style: {
|
|
35
|
+
'background-color': themeColors.componentBackground,
|
|
36
|
+
width: 'label',
|
|
37
|
+
height: 'label',
|
|
38
|
+
'padding-top': '8',
|
|
39
|
+
'padding-bottom': '8',
|
|
40
|
+
'padding-left': '8',
|
|
41
|
+
'padding-right': '8',
|
|
42
|
+
shape: 'round-rectangle',
|
|
43
|
+
'text-margin-y': -1,
|
|
44
|
+
'border-width': 2,
|
|
45
|
+
'border-color': themeColors.componentBorder,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
{
|
|
50
|
+
selector: 'node[label]',
|
|
51
|
+
style: {
|
|
52
|
+
label: 'data(label)',
|
|
53
|
+
'font-size': '12',
|
|
54
|
+
color: themeColors.componentFontColor,
|
|
55
|
+
'text-halign': 'center',
|
|
56
|
+
'text-valign': 'center',
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
selector: `node[label='${storyName}']`,
|
|
61
|
+
style: {
|
|
62
|
+
'background-color': themeColors.selectedComponentBackground,
|
|
63
|
+
'padding-top': '14',
|
|
64
|
+
'padding-bottom': '14',
|
|
65
|
+
'padding-left': '14',
|
|
66
|
+
'padding-right': '14',
|
|
67
|
+
'border-width': '0',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
selector: `node[label='${storyName}'][label]`,
|
|
72
|
+
style: {
|
|
73
|
+
'font-size': '16',
|
|
74
|
+
color: themeColors.selectedComponentFontColor,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
selector: 'edge',
|
|
79
|
+
style: {
|
|
80
|
+
'curve-style': 'bezier',
|
|
81
|
+
'target-arrow-shape': 'triangle',
|
|
82
|
+
'target-arrow-color': themeColors.arrowBackground,
|
|
83
|
+
'line-color': themeColors.arrowBackground,
|
|
84
|
+
width: 2,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
cyRef.current = Cytoscape({
|
|
91
|
+
container: containerRef.current,
|
|
92
|
+
elements: elements,
|
|
93
|
+
layout,
|
|
94
|
+
style: cytoscapeStylesheet,
|
|
95
|
+
zoom: 2,
|
|
96
|
+
maxZoom: 2,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const cy = cyRef.current;
|
|
100
|
+
|
|
101
|
+
return () => {
|
|
102
|
+
cy.destroy();
|
|
103
|
+
};
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<div
|
|
108
|
+
className={'deps_graph__wrapper'}
|
|
109
|
+
ref={containerRef}
|
|
110
|
+
style={{ backgroundColor: themeColors.componentBackground }}
|
|
111
|
+
/>
|
|
112
|
+
);
|
|
113
|
+
}
|