@shuvi/error-overlay 1.0.0-rc.6

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 (190) hide show
  1. package/lib/client.d.ts +15 -0
  2. package/lib/client.js +168 -0
  3. package/lib/constants.d.ts +7 -0
  4. package/lib/constants.js +10 -0
  5. package/lib/iframe-bundle.js +2629 -0
  6. package/lib/iframeScript.d.ts +1 -0
  7. package/lib/iframeScript.js +66 -0
  8. package/lib/index.d.ts +2 -0
  9. package/lib/index.js +22 -0
  10. package/lib/middleware/helper/createOriginalStackFrame.d.ts +15 -0
  11. package/lib/middleware/helper/createOriginalStackFrame.js +59 -0
  12. package/lib/middleware/helper/findOriginalSourcePositionAndContent.d.ts +7 -0
  13. package/lib/middleware/helper/findOriginalSourcePositionAndContent.js +49 -0
  14. package/lib/middleware/helper/getModuleById.d.ts +2 -0
  15. package/lib/middleware/helper/getModuleById.js +7 -0
  16. package/lib/middleware/helper/getOriginalStackFrame.d.ts +6 -0
  17. package/lib/middleware/helper/getOriginalStackFrame.js +79 -0
  18. package/lib/middleware/helper/getSourceById.d.ts +6 -0
  19. package/lib/middleware/helper/getSourceById.js +129 -0
  20. package/lib/middleware/helper/getSourceMapUrl.d.ts +1 -0
  21. package/lib/middleware/helper/getSourceMapUrl.js +19 -0
  22. package/lib/middleware/helper/getSourcePath.d.ts +1 -0
  23. package/lib/middleware/helper/getSourcePath.js +17 -0
  24. package/lib/middleware/index.d.ts +2 -0
  25. package/lib/middleware/index.js +7 -0
  26. package/lib/middleware/launchEditorMiddleware.d.ts +2 -0
  27. package/lib/middleware/launchEditorMiddleware.js +35 -0
  28. package/lib/middleware/stackFrameMiddleware.d.ts +2 -0
  29. package/lib/middleware/stackFrameMiddleware.js +103 -0
  30. package/lib/view/ErrorOverlay.d.ts +2 -0
  31. package/lib/view/ErrorOverlay.js +80 -0
  32. package/lib/view/components/Dialog/Dialog.d.ts +10 -0
  33. package/lib/view/components/Dialog/Dialog.js +75 -0
  34. package/lib/view/components/Dialog/DialogBody.d.ts +7 -0
  35. package/lib/view/components/Dialog/DialogBody.js +8 -0
  36. package/lib/view/components/Dialog/DialogContent.d.ts +7 -0
  37. package/lib/view/components/Dialog/DialogContent.js +8 -0
  38. package/lib/view/components/Dialog/DialogHeader.d.ts +7 -0
  39. package/lib/view/components/Dialog/DialogHeader.js +8 -0
  40. package/lib/view/components/Dialog/index.d.ts +5 -0
  41. package/lib/view/components/Dialog/index.js +13 -0
  42. package/lib/view/components/Dialog/styles.d.ts +2 -0
  43. package/lib/view/components/Dialog/styles.js +92 -0
  44. package/lib/view/components/Errors/CallStackFrame/CallStackFrame.d.ts +10 -0
  45. package/lib/view/components/Errors/CallStackFrame/CallStackFrame.js +50 -0
  46. package/lib/view/components/Errors/CallStackFrame/index.d.ts +1 -0
  47. package/lib/view/components/Errors/CallStackFrame/index.js +5 -0
  48. package/lib/view/components/Errors/CodeFrame/CodeFrame.d.ts +7 -0
  49. package/lib/view/components/Errors/CodeFrame/CodeFrame.js +79 -0
  50. package/lib/view/components/Errors/CodeFrame/index.d.ts +1 -0
  51. package/lib/view/components/Errors/CodeFrame/index.js +5 -0
  52. package/lib/view/components/Errors/Errors.d.ts +7 -0
  53. package/lib/view/components/Errors/Errors.js +62 -0
  54. package/lib/view/components/Errors/index.d.ts +2 -0
  55. package/lib/view/components/Errors/index.js +7 -0
  56. package/lib/view/components/Errors/styles.d.ts +1 -0
  57. package/lib/view/components/Errors/styles.js +99 -0
  58. package/lib/view/components/Icons/ArrowLeftIcon.d.ts +3 -0
  59. package/lib/view/components/Icons/ArrowLeftIcon.js +8 -0
  60. package/lib/view/components/Icons/ArrowRightIcon.d.ts +3 -0
  61. package/lib/view/components/Icons/ArrowRightIcon.js +8 -0
  62. package/lib/view/components/Icons/CloseIcon.d.ts +3 -0
  63. package/lib/view/components/Icons/CloseIcon.js +8 -0
  64. package/lib/view/components/Icons/ExternalLinkIcon.d.ts +3 -0
  65. package/lib/view/components/Icons/ExternalLinkIcon.js +8 -0
  66. package/lib/view/components/Icons/WarningIcon.d.ts +3 -0
  67. package/lib/view/components/Icons/WarningIcon.js +8 -0
  68. package/lib/view/components/Icons/index.d.ts +5 -0
  69. package/lib/view/components/Icons/index.js +13 -0
  70. package/lib/view/components/NavigationBar/NavigationBar.d.ts +10 -0
  71. package/lib/view/components/NavigationBar/NavigationBar.js +108 -0
  72. package/lib/view/components/NavigationBar/index.d.ts +2 -0
  73. package/lib/view/components/NavigationBar/index.js +7 -0
  74. package/lib/view/components/NavigationBar/styles.d.ts +2 -0
  75. package/lib/view/components/NavigationBar/styles.js +62 -0
  76. package/lib/view/components/Overlay/Overlay.d.ts +8 -0
  77. package/lib/view/components/Overlay/Overlay.js +39 -0
  78. package/lib/view/components/Overlay/body-locker.d.ts +2 -0
  79. package/lib/view/components/Overlay/body-locker.js +37 -0
  80. package/lib/view/components/Overlay/index.d.ts +2 -0
  81. package/lib/view/components/Overlay/index.js +7 -0
  82. package/lib/view/components/Overlay/styles.d.ts +2 -0
  83. package/lib/view/components/Overlay/styles.js +45 -0
  84. package/lib/view/components/ShadowPortal.d.ts +5 -0
  85. package/lib/view/components/ShadowPortal.js +47 -0
  86. package/lib/view/components/Terminal/Terminal.d.ts +5 -0
  87. package/lib/view/components/Terminal/Terminal.js +47 -0
  88. package/lib/view/components/Terminal/index.d.ts +2 -0
  89. package/lib/view/components/Terminal/index.js +7 -0
  90. package/lib/view/components/Terminal/styles.d.ts +2 -0
  91. package/lib/view/components/Terminal/styles.js +31 -0
  92. package/lib/view/components/Toast/Toast.d.ts +7 -0
  93. package/lib/view/components/Toast/Toast.js +8 -0
  94. package/lib/view/components/Toast/index.d.ts +2 -0
  95. package/lib/view/components/Toast/index.js +7 -0
  96. package/lib/view/components/Toast/styles.d.ts +2 -0
  97. package/lib/view/components/Toast/styles.js +31 -0
  98. package/lib/view/container/BuildError.d.ts +6 -0
  99. package/lib/view/container/BuildError.js +55 -0
  100. package/lib/view/container/RuntimeError.d.ts +11 -0
  101. package/lib/view/container/RuntimeError.js +205 -0
  102. package/lib/view/container/index.d.ts +2 -0
  103. package/lib/view/container/index.js +7 -0
  104. package/lib/view/errorTypeHandler.d.ts +27 -0
  105. package/lib/view/errorTypeHandler.js +42 -0
  106. package/lib/view/helpers/getErrorByType.d.ts +9 -0
  107. package/lib/view/helpers/getErrorByType.js +36 -0
  108. package/lib/view/helpers/nodeStackFrames.d.ts +7 -0
  109. package/lib/view/helpers/nodeStackFrames.js +70 -0
  110. package/lib/view/helpers/noop-template.d.ts +1 -0
  111. package/lib/view/helpers/noop-template.js +9 -0
  112. package/lib/view/helpers/parseStack.d.ts +3 -0
  113. package/lib/view/helpers/parseStack.js +31 -0
  114. package/lib/view/helpers/stack-frame.d.ts +12 -0
  115. package/lib/view/helpers/stack-frame.js +60 -0
  116. package/lib/view/hooks/use-on-click-outside.d.ts +1 -0
  117. package/lib/view/hooks/use-on-click-outside.js +49 -0
  118. package/lib/view/styles/Base.d.ts +2 -0
  119. package/lib/view/styles/Base.js +84 -0
  120. package/lib/view/styles/ComponentStyles.d.ts +2 -0
  121. package/lib/view/styles/ComponentStyles.js +27 -0
  122. package/lib/view/styles/CssReset.d.ts +2 -0
  123. package/lib/view/styles/CssReset.js +361 -0
  124. package/lib/view/styles/index.d.ts +3 -0
  125. package/lib/view/styles/index.js +9 -0
  126. package/package.json +50 -0
  127. package/umd/client.d.ts +15 -0
  128. package/umd/constants.d.ts +7 -0
  129. package/umd/iframeScript.d.ts +1 -0
  130. package/umd/index.d.ts +2 -0
  131. package/umd/index.js +460 -0
  132. package/umd/middleware/helper/createOriginalStackFrame.d.ts +15 -0
  133. package/umd/middleware/helper/findOriginalSourcePositionAndContent.d.ts +7 -0
  134. package/umd/middleware/helper/getModuleById.d.ts +2 -0
  135. package/umd/middleware/helper/getOriginalStackFrame.d.ts +6 -0
  136. package/umd/middleware/helper/getSourceById.d.ts +6 -0
  137. package/umd/middleware/helper/getSourceMapUrl.d.ts +1 -0
  138. package/umd/middleware/helper/getSourcePath.d.ts +1 -0
  139. package/umd/middleware/helper/index.d.ts +5 -0
  140. package/umd/middleware/index.d.ts +2 -0
  141. package/umd/middleware/launchEditorMiddleware.d.ts +2 -0
  142. package/umd/middleware/stackFrameMiddleware.d.ts +2 -0
  143. package/umd/view/ErrorOverlay.d.ts +2 -0
  144. package/umd/view/components/Dialog/Dialog.d.ts +10 -0
  145. package/umd/view/components/Dialog/DialogBody.d.ts +7 -0
  146. package/umd/view/components/Dialog/DialogContent.d.ts +7 -0
  147. package/umd/view/components/Dialog/DialogHeader.d.ts +7 -0
  148. package/umd/view/components/Dialog/index.d.ts +5 -0
  149. package/umd/view/components/Dialog/styles.d.ts +2 -0
  150. package/umd/view/components/Errors/CallStackFrame/CallStackFrame.d.ts +10 -0
  151. package/umd/view/components/Errors/CallStackFrame/index.d.ts +1 -0
  152. package/umd/view/components/Errors/CodeFrame/CodeFrame.d.ts +7 -0
  153. package/umd/view/components/Errors/CodeFrame/index.d.ts +1 -0
  154. package/umd/view/components/Errors/Errors.d.ts +7 -0
  155. package/umd/view/components/Errors/index.d.ts +2 -0
  156. package/umd/view/components/Errors/styles.d.ts +1 -0
  157. package/umd/view/components/Icons/ArrowLeftIcon.d.ts +3 -0
  158. package/umd/view/components/Icons/ArrowRightIcon.d.ts +3 -0
  159. package/umd/view/components/Icons/CloseIcon.d.ts +3 -0
  160. package/umd/view/components/Icons/ExternalLinkIcon.d.ts +3 -0
  161. package/umd/view/components/Icons/WarningIcon.d.ts +3 -0
  162. package/umd/view/components/Icons/index.d.ts +5 -0
  163. package/umd/view/components/NavigationBar/NavigationBar.d.ts +10 -0
  164. package/umd/view/components/NavigationBar/index.d.ts +2 -0
  165. package/umd/view/components/NavigationBar/styles.d.ts +2 -0
  166. package/umd/view/components/Overlay/Overlay.d.ts +8 -0
  167. package/umd/view/components/Overlay/body-locker.d.ts +2 -0
  168. package/umd/view/components/Overlay/index.d.ts +2 -0
  169. package/umd/view/components/Overlay/styles.d.ts +2 -0
  170. package/umd/view/components/ShadowPortal.d.ts +5 -0
  171. package/umd/view/components/Terminal/Terminal.d.ts +5 -0
  172. package/umd/view/components/Terminal/index.d.ts +2 -0
  173. package/umd/view/components/Terminal/styles.d.ts +2 -0
  174. package/umd/view/components/Toast/Toast.d.ts +7 -0
  175. package/umd/view/components/Toast/index.d.ts +2 -0
  176. package/umd/view/components/Toast/styles.d.ts +2 -0
  177. package/umd/view/container/BuildError.d.ts +6 -0
  178. package/umd/view/container/RuntimeError.d.ts +11 -0
  179. package/umd/view/container/index.d.ts +2 -0
  180. package/umd/view/errorTypeHandler.d.ts +27 -0
  181. package/umd/view/helpers/getErrorByType.d.ts +9 -0
  182. package/umd/view/helpers/nodeStackFrames.d.ts +7 -0
  183. package/umd/view/helpers/noop-template.d.ts +1 -0
  184. package/umd/view/helpers/parseStack.d.ts +3 -0
  185. package/umd/view/helpers/stack-frame.d.ts +12 -0
  186. package/umd/view/hooks/use-on-click-outside.d.ts +1 -0
  187. package/umd/view/styles/Base.d.ts +2 -0
  188. package/umd/view/styles/ComponentStyles.d.ts +2 -0
  189. package/umd/view/styles/CssReset.d.ts +2 -0
  190. package/umd/view/styles/index.d.ts +3 -0
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.stackFrameMiddleware = void 0;
16
+ const url_1 = __importDefault(require("url"));
17
+ const constants_1 = require("@shuvi/shared/lib/constants");
18
+ const getSourceById_1 = require("./helper/getSourceById");
19
+ const getOriginalStackFrame_1 = require("./helper/getOriginalStackFrame");
20
+ function stackFrameMiddleware(originalStackFrameEndpoint, bundler, resolveBuildFile, buildDefaultDir, buildServerDir) {
21
+ var _a, _b;
22
+ let clientStats = null;
23
+ let serverStats = null;
24
+ (_a = bundler
25
+ .getSubCompiler(constants_1.BUNDLER_TARGET_CLIENT)) === null || _a === void 0 ? void 0 : _a.hooks.done.tap('stackFrameMiddlewareForClient', (stats) => {
26
+ clientStats = stats;
27
+ });
28
+ (_b = bundler
29
+ .getSubCompiler(constants_1.BUNDLER_TARGET_SERVER)) === null || _b === void 0 ? void 0 : _b.hooks.done.tap('stackFrameMiddlewareForServer', (stats) => {
30
+ serverStats = stats;
31
+ });
32
+ const collectSourceMaps = (files, compiler, compilation, cache, buildDir) => __awaiter(this, void 0, void 0, function* () {
33
+ yield Promise.all(files.map((fileName) => __awaiter(this, void 0, void 0, function* () {
34
+ try {
35
+ const moduleId = fileName.replace(/^(webpack-internal:\/\/\/|file:\/\/)/, '');
36
+ const source = yield (0, getSourceById_1.getSourceById)(fileName.startsWith('file:'), moduleId, compiler, resolveBuildFile, buildDir, compilation);
37
+ cache.set(fileName, source);
38
+ }
39
+ catch (_c) {
40
+ cache.set(fileName, null);
41
+ }
42
+ })));
43
+ });
44
+ const getStackFrames = (frames, errorMessage, compilation, sourceMap, buildDir) => __awaiter(this, void 0, void 0, function* () {
45
+ return yield Promise.all(frames.map((frame) => __awaiter(this, void 0, void 0, function* () {
46
+ let result;
47
+ try {
48
+ result = yield (0, getOriginalStackFrame_1.getOriginalStackFrame)(frame, sourceMap, resolveBuildFile, buildDir, errorMessage, compilation);
49
+ }
50
+ catch (_d) {
51
+ result = {
52
+ error: true,
53
+ reason: 'No Content',
54
+ external: false,
55
+ expanded: false,
56
+ sourceStackFrame: frame,
57
+ originalStackFrame: null,
58
+ originalCodeFrame: null
59
+ };
60
+ }
61
+ return result;
62
+ })));
63
+ });
64
+ return function (req, res, next) {
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ if (!req.url.startsWith(originalStackFrameEndpoint)) {
67
+ return next();
68
+ }
69
+ const files = [];
70
+ const sourceMap = new Map();
71
+ const { query: queryFromUrl } = url_1.default.parse(req.url, true);
72
+ const query = queryFromUrl;
73
+ const frames = JSON.parse(query.frames);
74
+ const { isServer, errorMessage } = query;
75
+ const compiler = isServer === 'true'
76
+ ? bundler.getSubCompiler(constants_1.BUNDLER_TARGET_SERVER)
77
+ : bundler.getSubCompiler(constants_1.BUNDLER_TARGET_CLIENT);
78
+ const compilation = isServer === 'true' ? serverStats === null || serverStats === void 0 ? void 0 : serverStats.compilation : clientStats === null || clientStats === void 0 ? void 0 : clientStats.compilation;
79
+ const buildDir = isServer === 'true' ? buildServerDir : buildDefaultDir;
80
+ // handle duplicate files
81
+ frames.forEach((frame) => {
82
+ const { file } = frame;
83
+ if (file == null) {
84
+ return;
85
+ }
86
+ if (files.indexOf(file) !== -1) {
87
+ return;
88
+ }
89
+ files.push(file);
90
+ });
91
+ // collect the sourcemaps from the files
92
+ yield collectSourceMaps(files, compiler, compilation, sourceMap, buildDir);
93
+ // handle the source position
94
+ const originalStackFrames = yield getStackFrames(frames, errorMessage, compilation, sourceMap, buildDir);
95
+ sourceMap.clear();
96
+ res.statusCode = 200;
97
+ res.setHeader('Content-Type', 'application/json');
98
+ res.write(Buffer.from(JSON.stringify(originalStackFrames)));
99
+ res.end();
100
+ });
101
+ };
102
+ }
103
+ exports.stackFrameMiddleware = stackFrameMiddleware;
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const ErrorOverlay: () => JSX.Element;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.ErrorOverlay = void 0;
27
+ const jsx_runtime_1 = require("react/jsx-runtime");
28
+ const React = __importStar(require("react"));
29
+ const ErrorTypeHandler = __importStar(require("./errorTypeHandler"));
30
+ const ShadowPortal_1 = require("./components/ShadowPortal");
31
+ const BuildError_1 = require("./container/BuildError");
32
+ const RuntimeError_1 = require("./container/RuntimeError");
33
+ const constants_1 = require("../constants");
34
+ const Base_1 = require("./styles/Base");
35
+ const ComponentStyles_1 = require("./styles/ComponentStyles");
36
+ const CssReset_1 = require("./styles/CssReset");
37
+ function reducer(state, ev) {
38
+ switch (ev.type) {
39
+ case constants_1.TYPE_BUILD_OK: {
40
+ return Object.assign(Object.assign({}, state), { buildError: null });
41
+ }
42
+ case constants_1.TYPE_REFRESH: {
43
+ return Object.assign(Object.assign({}, state), { buildError: null, errors: [] });
44
+ }
45
+ case constants_1.TYPE_BUILD_ERROR: {
46
+ return Object.assign(Object.assign({}, state), { buildError: ev.message });
47
+ }
48
+ case constants_1.TYPE_UNHANDLED_ERROR:
49
+ case constants_1.TYPE_UNHANDLED_REJECTION: {
50
+ return Object.assign(Object.assign({}, state), { nextId: state.nextId + 1, errors: [
51
+ ...state.errors.filter(err => {
52
+ // Filter out duplicate errors
53
+ return err.event.reason !== ev.reason;
54
+ }),
55
+ { id: state.nextId, event: ev }
56
+ ] });
57
+ }
58
+ default: {
59
+ return state;
60
+ }
61
+ }
62
+ }
63
+ const ErrorOverlay = function ErrorOverlay() {
64
+ const [state, dispatch] = React.useReducer(reducer, {
65
+ nextId: 1,
66
+ buildError: null,
67
+ errors: []
68
+ });
69
+ React.useEffect(() => {
70
+ ErrorTypeHandler.on(dispatch);
71
+ return function () {
72
+ ErrorTypeHandler.off(dispatch);
73
+ };
74
+ }, [dispatch]);
75
+ const hasBuildError = state.buildError != null;
76
+ const hasRuntimeErrors = Boolean(state.errors.length);
77
+ const isMounted = hasBuildError || hasRuntimeErrors;
78
+ return ((0, jsx_runtime_1.jsx)(React.Fragment, { children: isMounted ? ((0, jsx_runtime_1.jsxs)(ShadowPortal_1.ShadowPortal, { children: [(0, jsx_runtime_1.jsx)(CssReset_1.CssReset, {}), (0, jsx_runtime_1.jsx)(Base_1.Base, {}), (0, jsx_runtime_1.jsx)(ComponentStyles_1.ComponentStyles, {}), hasBuildError ? ((0, jsx_runtime_1.jsx)(BuildError_1.BuildError, { error: state.buildError })) : hasRuntimeErrors ? ((0, jsx_runtime_1.jsx)(RuntimeError_1.RuntimeError, { errors: state.errors })) : undefined] })) : undefined }));
79
+ };
80
+ exports.ErrorOverlay = ErrorOverlay;
@@ -0,0 +1,10 @@
1
+ import * as React from 'react';
2
+ export declare type DialogProps = {
3
+ type: 'error' | 'warning';
4
+ 'aria-labelledby': string;
5
+ 'aria-describedby': string;
6
+ onClose?: (e: MouseEvent | TouchEvent) => void;
7
+ children: React.ReactNode;
8
+ };
9
+ declare const Dialog: React.FC<DialogProps>;
10
+ export { Dialog };
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __rest = (this && this.__rest) || function (s, e) {
26
+ var t = {};
27
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
28
+ t[p] = s[p];
29
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
30
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
31
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
32
+ t[p[i]] = s[p[i]];
33
+ }
34
+ return t;
35
+ };
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.Dialog = void 0;
38
+ const jsx_runtime_1 = require("react/jsx-runtime");
39
+ const React = __importStar(require("react"));
40
+ const use_on_click_outside_1 = require("../../hooks/use-on-click-outside");
41
+ const Dialog = function Dialog(_a) {
42
+ var { children, type, onClose } = _a, props = __rest(_a, ["children", "type", "onClose"]);
43
+ const [dialog, setDialog] = React.useState(null);
44
+ const onDialog = React.useCallback((node) => {
45
+ setDialog(node);
46
+ }, []);
47
+ (0, use_on_click_outside_1.useOnClickOutside)(dialog, onClose);
48
+ // Make HTMLElements with `role=link` accessible to be triggered by the
49
+ // keyboard, i.e. [Enter].
50
+ React.useEffect(() => {
51
+ if (dialog == null) {
52
+ return;
53
+ }
54
+ const root = dialog.getRootNode();
55
+ // Always true, but we do this for TypeScript:
56
+ if (!(root instanceof ShadowRoot)) {
57
+ return;
58
+ }
59
+ const shadowRoot = root;
60
+ function handler(e) {
61
+ const el = shadowRoot.activeElement;
62
+ if (e.key === 'Enter' &&
63
+ el instanceof HTMLElement &&
64
+ el.getAttribute('role') === 'link') {
65
+ e.preventDefault();
66
+ e.stopPropagation();
67
+ el.click();
68
+ }
69
+ }
70
+ shadowRoot.addEventListener('keydown', handler);
71
+ return () => shadowRoot.removeEventListener('keydown', handler);
72
+ }, [dialog]);
73
+ return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ ref: onDialog, "data-dialog": true, tabIndex: -1, role: "dialog", "aria-labelledby": props['aria-labelledby'], "aria-describedby": props['aria-describedby'], "aria-modal": "true" }, { children: [(0, jsx_runtime_1.jsx)("div", { "data-dialog-banner": true, className: `banner-${type}` }), children] })));
74
+ };
75
+ exports.Dialog = Dialog;
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ export declare type DialogBodyProps = {
3
+ className?: string;
4
+ children: React.ReactNode;
5
+ };
6
+ declare const DialogBody: React.FC<DialogBodyProps>;
7
+ export { DialogBody };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DialogBody = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const DialogBody = function DialogBody({ children, className }) {
6
+ return ((0, jsx_runtime_1.jsx)("div", Object.assign({ "data-dialog-body": true, className: className }, { children: children })));
7
+ };
8
+ exports.DialogBody = DialogBody;
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ export declare type DialogContentProps = {
3
+ className?: string;
4
+ children: React.ReactNode;
5
+ };
6
+ declare const DialogContent: React.FC<DialogContentProps>;
7
+ export { DialogContent };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DialogContent = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const DialogContent = function DialogContent({ children, className }) {
6
+ return ((0, jsx_runtime_1.jsx)("div", Object.assign({ "data-dialog-content": true, className: className }, { children: children })));
7
+ };
8
+ exports.DialogContent = DialogContent;
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ export declare type DialogHeaderProps = {
3
+ className?: string;
4
+ children: React.ReactNode;
5
+ };
6
+ declare const DialogHeader: React.FC<DialogHeaderProps>;
7
+ export { DialogHeader };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DialogHeader = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const DialogHeader = function DialogHeader({ children, className }) {
6
+ return ((0, jsx_runtime_1.jsx)("div", Object.assign({ "data-dialog-header": true, className: className }, { children: children })));
7
+ };
8
+ exports.DialogHeader = DialogHeader;
@@ -0,0 +1,5 @@
1
+ export { Dialog } from './Dialog';
2
+ export { DialogBody } from './DialogBody';
3
+ export { DialogContent } from './DialogContent';
4
+ export { DialogHeader } from './DialogHeader';
5
+ export { styles } from './styles';
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.styles = exports.DialogHeader = exports.DialogContent = exports.DialogBody = exports.Dialog = void 0;
4
+ var Dialog_1 = require("./Dialog");
5
+ Object.defineProperty(exports, "Dialog", { enumerable: true, get: function () { return Dialog_1.Dialog; } });
6
+ var DialogBody_1 = require("./DialogBody");
7
+ Object.defineProperty(exports, "DialogBody", { enumerable: true, get: function () { return DialogBody_1.DialogBody; } });
8
+ var DialogContent_1 = require("./DialogContent");
9
+ Object.defineProperty(exports, "DialogContent", { enumerable: true, get: function () { return DialogContent_1.DialogContent; } });
10
+ var DialogHeader_1 = require("./DialogHeader");
11
+ Object.defineProperty(exports, "DialogHeader", { enumerable: true, get: function () { return DialogHeader_1.DialogHeader; } });
12
+ var styles_1 = require("./styles");
13
+ Object.defineProperty(exports, "styles", { enumerable: true, get: function () { return styles_1.styles; } });
@@ -0,0 +1,2 @@
1
+ declare const styles: string;
2
+ export { styles };
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.styles = void 0;
4
+ const noop_template_1 = require("../../helpers/noop-template");
5
+ const styles = (0, noop_template_1.noop) `
6
+ [data-dialog] {
7
+ display: flex;
8
+ flex-direction: column;
9
+ width: 100%;
10
+ margin-right: auto;
11
+ margin-left: auto;
12
+ outline: none;
13
+ background: white;
14
+ border-radius: var(--size-gap);
15
+ box-shadow: 0 var(--size-gap-half) var(--size-gap-double)
16
+ rgba(0, 0, 0, 0.25);
17
+ max-height: calc(100% - 56px);
18
+ overflow-y: hidden;
19
+ }
20
+
21
+ @media (max-height: 812px) {
22
+ [data-dialog-overlay] {
23
+ max-height: calc(100% - 15px);
24
+ }
25
+ }
26
+
27
+ @media (min-width: 576px) {
28
+ [data-dialog] {
29
+ max-width: 540px;
30
+ box-shadow: 0 var(--size-gap) var(--size-gap-quad) rgba(0, 0, 0, 0.25);
31
+ }
32
+ }
33
+
34
+ @media (min-width: 768px) {
35
+ [data-dialog] {
36
+ max-width: 720px;
37
+ }
38
+ }
39
+
40
+ @media (min-width: 992px) {
41
+ [data-dialog] {
42
+ max-width: 960px;
43
+ }
44
+ }
45
+
46
+ [data-dialog-banner] {
47
+ position: relative;
48
+ }
49
+ [data-dialog-banner].banner-warning {
50
+ border-color: var(--color-ansi-yellow);
51
+ }
52
+ [data-dialog-banner].banner-error {
53
+ border-color: var(--color-ansi-red);
54
+ }
55
+
56
+ [data-dialog-banner]::after {
57
+ z-index: 2;
58
+ content: '';
59
+ position: absolute;
60
+ top: 0;
61
+ right: 0;
62
+ width: 100%;
63
+ /* banner width: */
64
+ border-top-width: var(--size-gap-half);
65
+ border-bottom-width: 0;
66
+ border-top-style: solid;
67
+ border-bottom-style: solid;
68
+ border-top-color: inherit;
69
+ border-bottom-color: transparent;
70
+ }
71
+
72
+ [data-dialog-content] {
73
+ overflow-y: auto;
74
+ border: none;
75
+ margin: 0;
76
+ /* calc(padding + banner width offset) */
77
+ padding: calc(var(--size-gap-double) + var(--size-gap-half))
78
+ var(--size-gap-double);
79
+ height: 100%;
80
+ display: flex;
81
+ flex-direction: column;
82
+ }
83
+ [data-dialog-content] > [data-dialog-header] {
84
+ flex-shrink: 0;
85
+ margin-bottom: var(--size-gap-double);
86
+ }
87
+ [data-dialog-content] > [data-dialog-body] {
88
+ position: relative;
89
+ flex: 1 1 auto;
90
+ }
91
+ `;
92
+ exports.styles = styles;
@@ -0,0 +1,10 @@
1
+ import * as React from 'react';
2
+ import { StackFrame } from 'stacktrace-parser';
3
+ import { OriginalStackFrame } from '../../../helpers/stack-frame';
4
+ export declare type CallStackFrameProps = {
5
+ stackFrame: StackFrame;
6
+ codeFrame: string;
7
+ };
8
+ export declare const CallStackFrame: React.FC<{
9
+ frame: OriginalStackFrame;
10
+ }>;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.CallStackFrame = void 0;
27
+ const jsx_runtime_1 = require("react/jsx-runtime");
28
+ const React = __importStar(require("react"));
29
+ const constants_1 = require("@shuvi/shared/esm/constants");
30
+ const Icons_1 = require("../../Icons");
31
+ const stack_frame_1 = require("../../../helpers/stack-frame");
32
+ const CallStackFrame = function CallStackFrame({ frame }) {
33
+ var _a;
34
+ const f = (_a = frame.originalStackFrame) !== null && _a !== void 0 ? _a : frame.sourceStackFrame;
35
+ const hasSource = Boolean(frame.originalCodeFrame);
36
+ const open = React.useCallback(() => {
37
+ var _a;
38
+ if (!hasSource)
39
+ return;
40
+ const params = new URLSearchParams();
41
+ for (const key in f) {
42
+ params.append(key, ((_a = f[key]) !== null && _a !== void 0 ? _a : '').toString());
43
+ }
44
+ fetch(`${constants_1.DEV_HOT_LAUNCH_EDITOR_ENDPOINT}?${params.toString()}`).then(() => { }, () => {
45
+ console.error('There was an issue opening this code in your editor.');
46
+ });
47
+ }, [hasSource, f]);
48
+ return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ "data-call-stack-frame": true }, { children: [(0, jsx_runtime_1.jsx)("h6", Object.assign({ "data-frame-expanded": Boolean(frame.expanded) }, { children: f.methodName })), (0, jsx_runtime_1.jsxs)("div", Object.assign({ "data-has-source": hasSource ? 'true' : undefined, tabIndex: hasSource ? 10 : undefined, role: hasSource ? 'link' : undefined, onClick: open, title: hasSource ? 'Click to open in your editor' : undefined }, { children: [(0, jsx_runtime_1.jsx)("span", { children: (0, stack_frame_1.getFrameSource)(f) }), (0, jsx_runtime_1.jsx)(Icons_1.ExternalLinkIcon, {})] }))] })));
49
+ };
50
+ exports.CallStackFrame = CallStackFrame;
@@ -0,0 +1 @@
1
+ export { CallStackFrame } from './CallStackFrame';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CallStackFrame = void 0;
4
+ var CallStackFrame_1 = require("./CallStackFrame");
5
+ Object.defineProperty(exports, "CallStackFrame", { enumerable: true, get: function () { return CallStackFrame_1.CallStackFrame; } });
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ import { StackFrame } from 'stacktrace-parser';
3
+ export declare type CodeFrameProps = {
4
+ stackFrame: StackFrame;
5
+ codeFrame: string;
6
+ };
7
+ export declare const CodeFrame: React.FC<CodeFrameProps>;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.CodeFrame = void 0;
30
+ const jsx_runtime_1 = require("react/jsx-runtime");
31
+ const anser_1 = __importDefault(require("anser"));
32
+ const React = __importStar(require("react"));
33
+ const strip_ansi_1 = __importDefault(require("strip-ansi"));
34
+ const constants_1 = require("@shuvi/shared/esm/constants");
35
+ const Icons_1 = require("../../Icons");
36
+ const stack_frame_1 = require("../../../helpers/stack-frame");
37
+ const CodeFrame = function CodeFrame({ stackFrame, codeFrame }) {
38
+ // Strip leading spaces out of the code frame:
39
+ const formattedFrame = React.useMemo(() => {
40
+ const lines = codeFrame.split(/\r?\n/g);
41
+ const prefixLength = lines
42
+ .map(line => /^>? +\d+ +\| ( *)/.exec((0, strip_ansi_1.default)(line)))
43
+ .filter(Boolean)
44
+ .map(v => v.pop())
45
+ .reduce((c, n) => (isNaN(c) ? n.length : Math.min(c, n.length)), NaN);
46
+ if (prefixLength > 1) {
47
+ const p = ' '.repeat(prefixLength);
48
+ return lines
49
+ .map((line, a) => ~(a = line.indexOf('|'))
50
+ ? line.substring(0, a) + line.substring(a).replace(p, '')
51
+ : line)
52
+ .join('\n');
53
+ }
54
+ return lines.join('\n');
55
+ }, [codeFrame]);
56
+ const decoded = React.useMemo(() => {
57
+ return anser_1.default.ansiToJson(formattedFrame, {
58
+ json: true,
59
+ use_classes: true,
60
+ remove_empty: true
61
+ });
62
+ }, [formattedFrame]);
63
+ const open = React.useCallback(() => {
64
+ var _a;
65
+ const params = new URLSearchParams();
66
+ for (const key in stackFrame) {
67
+ params.append(key, ((_a = stackFrame[key]) !== null && _a !== void 0 ? _a : '').toString());
68
+ }
69
+ fetch(`${constants_1.DEV_HOT_LAUNCH_EDITOR_ENDPOINT}?${params.toString()}`).then(() => { }, () => {
70
+ console.error('There was an issue opening this code in your editor.');
71
+ });
72
+ }, [stackFrame]);
73
+ return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ "data-codeframe": true }, { children: [(0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsxs)("p", Object.assign({ role: "link", onClick: open, tabIndex: 1, title: "Click to open in your editor" }, { children: [(0, jsx_runtime_1.jsxs)("span", { children: [(0, stack_frame_1.getFrameSource)(stackFrame), " @ ", stackFrame.methodName] }), (0, jsx_runtime_1.jsx)(Icons_1.ExternalLinkIcon, {})] })) }), (0, jsx_runtime_1.jsx)("pre", { children: decoded.map((entry, index) => ((0, jsx_runtime_1.jsx)("span", Object.assign({ style: Object.assign({ color: entry.fg ? `var(--color-${entry.fg})` : undefined }, (entry.decoration === 'bold'
74
+ ? { fontWeight: 800 }
75
+ : entry.decoration === 'italic'
76
+ ? { fontStyle: 'italic' }
77
+ : undefined)) }, { children: entry.content }), `frame-${index}`))) })] })));
78
+ };
79
+ exports.CodeFrame = CodeFrame;
@@ -0,0 +1 @@
1
+ export { CodeFrame } from './CodeFrame';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CodeFrame = void 0;
4
+ var CodeFrame_1 = require("./CodeFrame");
5
+ Object.defineProperty(exports, "CodeFrame", { enumerable: true, get: function () { return CodeFrame_1.CodeFrame; } });
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ import { ReadyRuntimeError } from '../../helpers/getErrorByType';
3
+ export declare type ErrorsProps = {
4
+ error: ReadyRuntimeError;
5
+ };
6
+ declare const Errors: React.FC<ErrorsProps>;
7
+ export { Errors };