@rsdoctor/components 0.1.6 → 0.1.7

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 (41) hide show
  1. package/dist/components/BundleDiff/DiffContainer/assets.d.ts +7 -0
  2. package/dist/components/BundleDiff/DiffContainer/assets.js +507 -0
  3. package/dist/components/BundleDiff/DiffContainer/cards.d.ts +3 -0
  4. package/dist/components/BundleDiff/DiffContainer/cards.js +156 -0
  5. package/dist/components/BundleDiff/DiffContainer/changes.d.ts +15 -0
  6. package/dist/components/BundleDiff/DiffContainer/changes.js +69 -0
  7. package/dist/components/BundleDiff/DiffContainer/constants.d.ts +11 -0
  8. package/dist/components/BundleDiff/DiffContainer/constants.js +17 -0
  9. package/dist/components/BundleDiff/DiffContainer/diff.d.ts +23 -0
  10. package/dist/components/BundleDiff/DiffContainer/diff.js +114 -0
  11. package/dist/components/BundleDiff/DiffContainer/index.d.ts +3 -0
  12. package/dist/components/BundleDiff/DiffContainer/index.js +180 -0
  13. package/dist/components/BundleDiff/DiffContainer/modules.d.ts +8 -0
  14. package/dist/components/BundleDiff/DiffContainer/modules.js +302 -0
  15. package/dist/components/BundleDiff/DiffContainer/overview.d.ts +5 -0
  16. package/dist/components/BundleDiff/DiffContainer/overview.js +178 -0
  17. package/dist/components/BundleDiff/DiffContainer/packages.d.ts +19 -0
  18. package/dist/components/BundleDiff/DiffContainer/packages.js +330 -0
  19. package/dist/components/BundleDiff/DiffContainer/row.d.ts +9 -0
  20. package/dist/components/BundleDiff/DiffContainer/row.js +369 -0
  21. package/dist/components/BundleDiff/DiffContainer/types.d.ts +45 -0
  22. package/dist/components/BundleDiff/DiffContainer/types.js +0 -0
  23. package/dist/components/BundleDiff/DiffContainer/utils.d.ts +2 -0
  24. package/dist/components/BundleDiff/DiffContainer/utils.js +24 -0
  25. package/dist/components/BundleDiff/DiffServerAPIProvider/index.d.ts +4 -0
  26. package/dist/components/BundleDiff/DiffServerAPIProvider/index.js +37 -0
  27. package/dist/components/BundleDiff/constants.d.ts +11 -0
  28. package/dist/components/BundleDiff/constants.js +19 -0
  29. package/dist/components/BundleDiff/index.d.ts +1 -0
  30. package/dist/components/BundleDiff/index.js +1 -0
  31. package/dist/components/Card/diff.d.ts +1 -0
  32. package/dist/components/Card/diff.js +18 -4
  33. package/dist/components/Card/index.d.ts +1 -0
  34. package/dist/components/Card/index.js +22 -3
  35. package/dist/components/index.d.ts +4 -0
  36. package/dist/components/index.js +4 -0
  37. package/dist/utils/data/base.d.ts +1 -1
  38. package/dist/utils/data/remote.js +8 -2
  39. package/dist/utils/request.d.ts +4 -0
  40. package/dist/utils/request.js +25 -8
  41. package/package.json +6 -6
@@ -0,0 +1,69 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import React, { useState } from "react";
3
+ import { Col, Row, Typography, Segmented } from "antd";
4
+ import { DiffOutlined } from "@ant-design/icons";
5
+ import { DiffViewer } from "@rsdoctor/components";
6
+ import { TextDrawer } from "@rsdoctor/components";
7
+ import { Size } from "../../../constants";
8
+ const ViewChangesContent = ({
9
+ file,
10
+ data
11
+ }) => {
12
+ const [group, setGroup] = useState(data[0].group);
13
+ const match = data.find((e) => e.group === group);
14
+ return /* @__PURE__ */ jsxs(
15
+ Row,
16
+ {
17
+ wrap: true,
18
+ gutter: [Size.BasePadding, Size.BasePadding],
19
+ style: { height: "100%" },
20
+ children: [
21
+ data.length > 1 ? /* @__PURE__ */ jsx(Col, { span: 24, children: /* @__PURE__ */ jsx(
22
+ Segmented,
23
+ {
24
+ style: { marginTop: Size.BasePadding },
25
+ value: group,
26
+ options: data.map((e) => e.group),
27
+ onChange: (e) => setGroup(e)
28
+ }
29
+ ) }) : null,
30
+ match ? /* @__PURE__ */ jsxs(React.Fragment, { children: [
31
+ /* @__PURE__ */ jsx(Col, { span: 12, children: /* @__PURE__ */ jsx(Typography.Text, { strong: true, children: match.baselineTitle || "Baseline" }) }),
32
+ /* @__PURE__ */ jsx(Col, { span: 12, children: /* @__PURE__ */ jsx(Typography.Text, { strong: true, children: match.currentTitle || "Current" }) }),
33
+ /* @__PURE__ */ jsx(Col, { span: 24, children: /* @__PURE__ */ jsx(
34
+ DiffViewer,
35
+ {
36
+ filepath: file,
37
+ before: match.baseline || "",
38
+ after: match.current || "",
39
+ editorProps: {
40
+ // eslint-disable-next-line financial/no-float-calculation
41
+ height: Math.floor(window.innerHeight / 1.25)
42
+ }
43
+ }
44
+ ) })
45
+ ] }, group) : null
46
+ ]
47
+ }
48
+ );
49
+ };
50
+ const ViewChanges = ({ text = "View Changes", ...props }) => {
51
+ return /* @__PURE__ */ jsx(
52
+ TextDrawer,
53
+ {
54
+ text,
55
+ buttonProps: {
56
+ size: "small",
57
+ icon: /* @__PURE__ */ jsx(DiffOutlined, {})
58
+ },
59
+ drawerProps: {
60
+ destroyOnClose: true,
61
+ title: `Content diff for "${props.file}"`
62
+ },
63
+ children: /* @__PURE__ */ jsx(ViewChangesContent, { ...props })
64
+ }
65
+ );
66
+ };
67
+ export {
68
+ ViewChanges
69
+ };
@@ -0,0 +1,11 @@
1
+ export declare enum UpdateType {
2
+ New = "New",
3
+ Changed = "Changed",
4
+ Deleted = "Deleted",
5
+ NotChanged = "Not Changed"
6
+ }
7
+ export declare enum SortType {
8
+ Name = "Sorted by Name",
9
+ Size = "Sorted by Size",
10
+ Delta = "Sorted by Delta"
11
+ }
@@ -0,0 +1,17 @@
1
+ var UpdateType = /* @__PURE__ */ ((UpdateType2) => {
2
+ UpdateType2["New"] = "New";
3
+ UpdateType2["Changed"] = "Changed";
4
+ UpdateType2["Deleted"] = "Deleted";
5
+ UpdateType2["NotChanged"] = "Not Changed";
6
+ return UpdateType2;
7
+ })(UpdateType || {});
8
+ var SortType = /* @__PURE__ */ ((SortType2) => {
9
+ SortType2["Name"] = "Sorted by Name";
10
+ SortType2["Size"] = "Sorted by Size";
11
+ SortType2["Delta"] = "Sorted by Delta";
12
+ return SortType2;
13
+ })(SortType || {});
14
+ export {
15
+ SortType,
16
+ UpdateType
17
+ };
@@ -0,0 +1,23 @@
1
+ import { Client } from '@rsdoctor/types';
2
+ import React from 'react';
3
+ export interface DiffCardProps extends Pick<DiffCardContentProps, 'formatter'> {
4
+ titles: Array<string> | [string | React.ReactNode];
5
+ datas: Array<DiffCardContentProps['data']>;
6
+ showPercentInTitle?: boolean;
7
+ }
8
+ export interface DiffCardContentProps {
9
+ data: Client.RsdoctorClientAssetsDiffItem;
10
+ formatter?(v: number, target: 'baseline' | 'current'): number | string | React.ReactNode;
11
+ }
12
+ export interface PercentProps {
13
+ percent: number;
14
+ state: Client.RsdoctorClientDiffState;
15
+ fontSize?: React.CSSProperties['fontSize'];
16
+ }
17
+ export declare const SizePercent: React.FC<{
18
+ baseline: number;
19
+ current: number;
20
+ } & Omit<PercentProps, 'percent' | 'state'>>;
21
+ export declare const Percent: React.FC<PercentProps>;
22
+ export declare const DiffCardContent: React.FC<DiffCardContentProps>;
23
+ export declare const DiffCard: React.FC<DiffCardProps>;
@@ -0,0 +1,114 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { Client } from "@rsdoctor/types";
3
+ import { Segmented, Space, Tooltip, Typography } from "antd";
4
+ import { Graph } from "@rsdoctor/utils/common";
5
+ import { useState } from "react";
6
+ import { Color } from "../../../constants";
7
+ import { StatisticCard } from "../../Card";
8
+ import { formatSize } from "../../../utils";
9
+ const SizePercent = ({ baseline, current, ...rest }) => {
10
+ const diff = Graph.diffSize(baseline, current);
11
+ return /* @__PURE__ */ jsx(Percent, { ...rest, ...diff });
12
+ };
13
+ const Percent = ({
14
+ percent,
15
+ state,
16
+ fontSize = 14
17
+ }) => {
18
+ const _percent = +percent.toFixed(2);
19
+ if (_percent > 0) {
20
+ const percentText = `${_percent}`;
21
+ if (state === Client.RsdoctorClientDiffState.Up) {
22
+ return /* @__PURE__ */ jsxs(Typography.Text, { strong: true, style: { fontSize, color: Color.Red }, children: [
23
+ "+",
24
+ percentText,
25
+ "%"
26
+ ] });
27
+ }
28
+ if (state === Client.RsdoctorClientDiffState.Down) {
29
+ return /* @__PURE__ */ jsxs(Typography.Text, { strong: true, style: { fontSize, color: Color.Green }, children: [
30
+ "-",
31
+ percentText,
32
+ "%"
33
+ ] });
34
+ }
35
+ }
36
+ return null;
37
+ };
38
+ const DiffCardContent = ({
39
+ data,
40
+ formatter
41
+ }) => {
42
+ const { percent, state, size } = data;
43
+ const { baseline, current } = size;
44
+ const bSize = formatter ? formatter(baseline, "baseline") : formatSize(baseline);
45
+ const cSize = formatter ? formatter(current, "current") : formatSize(current);
46
+ return /* @__PURE__ */ jsx(Space, { align: "start", children: /* @__PURE__ */ jsxs(Space, { direction: "vertical", style: { textAlign: "left" }, children: [
47
+ /* @__PURE__ */ jsxs(Space, { children: [
48
+ /* @__PURE__ */ jsx(Typography.Text, { style: { fontSize: 10, color: "inherit" }, keyboard: true, children: "Current" }),
49
+ /* @__PURE__ */ jsx(
50
+ Tooltip,
51
+ {
52
+ title: typeof cSize === "number" || typeof cSize === "string" ? `Value of Current is ${cSize}` : void 0,
53
+ children: /* @__PURE__ */ jsx(Typography.Text, { style: { fontSize: 16, color: "inherit" }, strong: true, children: cSize })
54
+ }
55
+ ),
56
+ /* @__PURE__ */ jsx(Percent, { percent, state })
57
+ ] }),
58
+ /* @__PURE__ */ jsxs(Space, { children: [
59
+ /* @__PURE__ */ jsx(Typography.Text, { style: { fontSize: 10, color: "inherit" }, keyboard: true, children: "Baseline" }),
60
+ /* @__PURE__ */ jsx(
61
+ Tooltip,
62
+ {
63
+ title: typeof bSize === "number" || typeof bSize === "string" ? `Value of Baseline is ${bSize}` : void 0,
64
+ children: /* @__PURE__ */ jsx(Typography.Text, { style: { fontSize: 14 }, type: "secondary", children: bSize })
65
+ }
66
+ )
67
+ ] })
68
+ ] }) });
69
+ };
70
+ const DiffCard = ({
71
+ titles,
72
+ datas,
73
+ formatter,
74
+ showPercentInTitle
75
+ }) => {
76
+ const [idx, setIdx] = useState(0);
77
+ return /* @__PURE__ */ jsx(
78
+ StatisticCard,
79
+ {
80
+ title: titles.length > 1 ? /* @__PURE__ */ jsx(
81
+ Segmented,
82
+ {
83
+ defaultValue: titles[idx],
84
+ options: showPercentInTitle ? titles.map((e, i) => {
85
+ const data = datas[i];
86
+ return {
87
+ label: /* @__PURE__ */ jsxs(Space, { children: [
88
+ /* @__PURE__ */ jsx(Typography.Text, { children: e }),
89
+ /* @__PURE__ */ jsx(Percent, { percent: data.percent, state: data.state })
90
+ ] }),
91
+ value: e
92
+ };
93
+ }) : titles,
94
+ onChange: (e) => {
95
+ setIdx(titles.indexOf(e));
96
+ },
97
+ size: "small",
98
+ style: { transition: "transform 0.3s ease" },
99
+ value: titles[idx] || titles[0]
100
+ }
101
+ ) : titles[idx],
102
+ value: /* @__PURE__ */ jsx(DiffCardContent, { data: datas[idx], formatter }),
103
+ statisticProps: {
104
+ style: { textAlign: "left" }
105
+ }
106
+ }
107
+ );
108
+ };
109
+ export {
110
+ DiffCard,
111
+ DiffCardContent,
112
+ Percent,
113
+ SizePercent
114
+ };
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import { BundleDiffContainerProps } from './types';
3
+ export declare const DiffContainer: React.FC<BundleDiffContainerProps>;
@@ -0,0 +1,180 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import {
3
+ Button,
4
+ Card,
5
+ Divider,
6
+ FloatButton,
7
+ Popconfirm,
8
+ Space,
9
+ Tabs,
10
+ Tooltip,
11
+ Typography
12
+ } from "antd";
13
+ import { useEffect } from "react";
14
+ import { Graph } from "@rsdoctor/utils/common";
15
+ import { InfoCircleOutlined, LogoutOutlined } from "@ant-design/icons";
16
+ import { SDK } from "@rsdoctor/types";
17
+ import { DiffCards } from "./cards";
18
+ import { Overview } from "./overview";
19
+ import { Assets } from "./assets";
20
+ import { Modules } from "./modules";
21
+ import { Packages } from "./packages";
22
+ import { DiffServerAPIProvider } from "../DiffServerAPIProvider";
23
+ import { Size } from "../../../constants";
24
+ const DiffContainer = ({
25
+ manifests
26
+ }) => {
27
+ useEffect(() => {
28
+ console.log("BundleDiff Webpack Manifests: ", manifests);
29
+ }, [manifests]);
30
+ return /* @__PURE__ */ jsx(
31
+ DiffServerAPIProvider,
32
+ {
33
+ api: SDK.ServerAPI.API.GetBundleDiffSummary,
34
+ manifests,
35
+ children: (baselineSummary, currentSummary) => {
36
+ const onlyBaseline = baselineSummary.chunkGraph === currentSummary.chunkGraph;
37
+ const baselineChunkGraph = baselineSummary.chunkGraph;
38
+ const currentChunkGraph = onlyBaseline ? baselineChunkGraph : currentSummary.chunkGraph;
39
+ const assetsDiffResult = Graph.getAssetsDiffResult(
40
+ baselineChunkGraph,
41
+ currentChunkGraph
42
+ );
43
+ return /* @__PURE__ */ jsxs("div", { children: [
44
+ /* @__PURE__ */ jsxs(FloatButton.Group, { children: [
45
+ /* @__PURE__ */ jsx(
46
+ Tooltip,
47
+ {
48
+ placement: "leftBottom",
49
+ title: /* @__PURE__ */ jsx(Space, { direction: "vertical", children: [
50
+ { title: "Baseline", data: baselineSummary },
51
+ { title: "Current", data: currentSummary }
52
+ ].map(({ title, data }) => {
53
+ return /* @__PURE__ */ jsx(Card, { size: "small", children: /* @__PURE__ */ jsxs(Space, { direction: "vertical", children: [
54
+ /* @__PURE__ */ jsx(Typography.Text, { strong: true, children: title }),
55
+ /* @__PURE__ */ jsxs(Space, { style: { fontSize: 10 }, children: [
56
+ /* @__PURE__ */ jsx(
57
+ Typography.Text,
58
+ {
59
+ style: {
60
+ fontSize: "inherit",
61
+ width: 30,
62
+ display: "inline-block"
63
+ },
64
+ children: "Hash"
65
+ }
66
+ ),
67
+ /* @__PURE__ */ jsx(Divider, { type: "vertical" }),
68
+ /* @__PURE__ */ jsx(
69
+ Typography.Text,
70
+ {
71
+ type: "secondary",
72
+ style: { fontSize: "inherit" },
73
+ children: data.hash || "-"
74
+ }
75
+ )
76
+ ] }),
77
+ data.cloudManifestUrl ? /* @__PURE__ */ jsx(
78
+ Button,
79
+ {
80
+ type: "link",
81
+ size: "small",
82
+ style: { padding: 0, fontSize: 10 },
83
+ onClick: () => window.open(data.cloudManifestUrl),
84
+ children: "Open File"
85
+ }
86
+ ) : null
87
+ ] }) }, title);
88
+ }) }),
89
+ children: /* @__PURE__ */ jsx(FloatButton, { icon: /* @__PURE__ */ jsx(InfoCircleOutlined, {}) })
90
+ }
91
+ ),
92
+ /* @__PURE__ */ jsx(
93
+ Popconfirm,
94
+ {
95
+ title: /* @__PURE__ */ jsxs(Typography.Text, { children: [
96
+ "Are you sure to",
97
+ /* @__PURE__ */ jsx(Typography.Text, { strong: true, children: " re-upload " }),
98
+ "json files for bundle diff?"
99
+ ] }),
100
+ onConfirm: () => {
101
+ },
102
+ okText: "Yes",
103
+ cancelText: "Cancel",
104
+ placement: "topLeft",
105
+ trigger: "hover",
106
+ children: /* @__PURE__ */ jsx(FloatButton, { icon: /* @__PURE__ */ jsx(LogoutOutlined, {}) })
107
+ }
108
+ ),
109
+ /* @__PURE__ */ jsx(FloatButton.BackTop, {})
110
+ ] }),
111
+ /* @__PURE__ */ jsx(
112
+ DiffCards,
113
+ {
114
+ baseline: baselineSummary,
115
+ current: currentSummary,
116
+ onlyBaseline,
117
+ assetsDiffResult
118
+ }
119
+ ),
120
+ /* @__PURE__ */ jsx(
121
+ Tabs,
122
+ {
123
+ defaultActiveKey: "Overview",
124
+ tabBarStyle: { marginBottom: Size.BasePadding / 3 },
125
+ items: [
126
+ {
127
+ label: "Overview",
128
+ key: "Overview",
129
+ children: /* @__PURE__ */ jsx(Overview, { assetsDiffResult })
130
+ },
131
+ {
132
+ label: "Assets",
133
+ key: "Assets",
134
+ children: /* @__PURE__ */ jsx(
135
+ Assets,
136
+ {
137
+ outputFilename: baselineSummary.outputFilename,
138
+ baseline: baselineSummary,
139
+ current: currentSummary
140
+ }
141
+ )
142
+ },
143
+ {
144
+ label: "Modules",
145
+ key: "Modules",
146
+ children: /* @__PURE__ */ jsx(
147
+ Modules,
148
+ {
149
+ baseline: baselineSummary,
150
+ current: currentSummary,
151
+ onlyBaseline,
152
+ assetsDiffResult
153
+ }
154
+ )
155
+ },
156
+ {
157
+ label: "Packages",
158
+ key: "Packages",
159
+ children: /* @__PURE__ */ jsx(
160
+ Packages,
161
+ {
162
+ baseline: baselineSummary.packageGraph,
163
+ current: currentSummary.packageGraph
164
+ }
165
+ )
166
+ }
167
+ ].map((el) => ({
168
+ ...el,
169
+ label: /* @__PURE__ */ jsx(Typography.Text, { strong: true, children: el.label })
170
+ }))
171
+ }
172
+ )
173
+ ] });
174
+ }
175
+ }
176
+ );
177
+ };
178
+ export {
179
+ DiffContainer
180
+ };
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import { BundleDiffComponentCardProps, BundleDiffTableModulesData } from './types';
3
+ import { UpdateType } from './constants';
4
+ export declare function getUpdateType(e: BundleDiffTableModulesData): UpdateType;
5
+ export declare const FileUpdateTypeTag: React.FC<{
6
+ type: UpdateType;
7
+ }>;
8
+ export declare const Modules: React.FC<BundleDiffComponentCardProps>;