@rspack/plugin-react-refresh 1.6.2 → 2.0.0-beta.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/README.md +19 -57
- package/client/reactRefresh.js +16 -28
- package/client/reactRefreshEntry.js +11 -12
- package/client/refreshUtils.js +116 -133
- package/dist/index.d.ts +1 -6
- package/dist/index.js +10 -176
- package/dist/options.d.ts +3 -20
- package/package.json +24 -40
- package/client/errorOverlayEntry.js +0 -101
- package/client/overlay/components/CompileErrorTrace.js +0 -68
- package/client/overlay/components/PageHeader.js +0 -60
- package/client/overlay/components/RuntimeErrorFooter.js +0 -93
- package/client/overlay/components/RuntimeErrorHeader.js +0 -38
- package/client/overlay/components/RuntimeErrorStack.js +0 -80
- package/client/overlay/components/Spacer.js +0 -19
- package/client/overlay/containers/CompileErrorContainer.js +0 -25
- package/client/overlay/containers/RuntimeErrorContainer.js +0 -29
- package/client/overlay/index.js +0 -351
- package/client/overlay/theme.js +0 -39
- package/client/overlay/utils.js +0 -74
- package/client/utils/ansi-html.js +0 -300
- package/client/utils/errorEventHandlers.js +0 -102
- package/client/utils/formatWebpackErrors.js +0 -106
- package/client/utils/retry.js +0 -23
- package/dist/sockets/WDSSocket.d.ts +0 -13
- package/dist/sockets/WDSSocket.js +0 -63
- package/dist/sockets/WHMEventSource.d.ts +0 -26
- package/dist/sockets/WHMEventSource.js +0 -52
- package/dist/sockets/utils/getCurrentScriptSource.d.ts +0 -1
- package/dist/sockets/utils/getCurrentScriptSource.js +0 -45
- package/dist/sockets/utils/getSocketUrlParts.d.ts +0 -9
- package/dist/sockets/utils/getSocketUrlParts.js +0 -87
- package/dist/sockets/utils/getUrlFromParts.d.ts +0 -9
- package/dist/sockets/utils/getUrlFromParts.js +0 -49
- package/dist/sockets/utils/getWDSMetadata.d.ts +0 -16
- package/dist/sockets/utils/getWDSMetadata.js +0 -45
- package/dist/utils/getAdditionalEntries.d.ts +0 -9
- package/dist/utils/getIntegrationEntry.d.ts +0 -7
- package/dist/utils/getSocketIntegration.d.ts +0 -2
- package/exports/index.cjs +0 -7
- package/exports/index.d.cts +0 -3
- package/exports/index.d.mts +0 -5
- package/exports/index.mjs +0 -11
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
const Spacer = require('./Spacer.js');
|
|
2
|
-
const theme = require('../theme.js');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @typedef {Object} RuntimeErrorFooterProps
|
|
6
|
-
* @property {string} [initialFocus]
|
|
7
|
-
* @property {boolean} multiple
|
|
8
|
-
* @property {function(MouseEvent): void} onClickCloseButton
|
|
9
|
-
* @property {function(MouseEvent): void} onClickNextButton
|
|
10
|
-
* @property {function(MouseEvent): void} onClickPrevButton
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* A fixed footer that handles pagination of runtime errors.
|
|
15
|
-
* @param {Document} document
|
|
16
|
-
* @param {HTMLElement} root
|
|
17
|
-
* @param {RuntimeErrorFooterProps} props
|
|
18
|
-
* @returns {void}
|
|
19
|
-
*/
|
|
20
|
-
function RuntimeErrorFooter(document, root, props) {
|
|
21
|
-
const footer = document.createElement('div');
|
|
22
|
-
footer.style.backgroundColor = '#' + theme.dimgrey;
|
|
23
|
-
footer.style.bottom = '0';
|
|
24
|
-
footer.style.boxShadow = '0 -1px 4px rgba(0, 0, 0, 0.3)';
|
|
25
|
-
footer.style.height = '2.5rem';
|
|
26
|
-
footer.style.left = '0';
|
|
27
|
-
footer.style.right = '0';
|
|
28
|
-
footer.style.lineHeight = '2.5rem';
|
|
29
|
-
footer.style.paddingBottom = '0';
|
|
30
|
-
footer.style.paddingBottom = 'env(safe-area-inset-bottom)';
|
|
31
|
-
footer.style.position = 'fixed';
|
|
32
|
-
footer.style.textAlign = 'center';
|
|
33
|
-
footer.style.zIndex = '2';
|
|
34
|
-
|
|
35
|
-
const BUTTON_CONFIGS = {
|
|
36
|
-
prev: {
|
|
37
|
-
id: 'prev',
|
|
38
|
-
label: '◀ Prev',
|
|
39
|
-
onClick: props.onClickPrevButton,
|
|
40
|
-
},
|
|
41
|
-
close: {
|
|
42
|
-
id: 'close',
|
|
43
|
-
label: '× Close',
|
|
44
|
-
onClick: props.onClickCloseButton,
|
|
45
|
-
},
|
|
46
|
-
next: {
|
|
47
|
-
id: 'next',
|
|
48
|
-
label: 'Next ▶',
|
|
49
|
-
onClick: props.onClickNextButton,
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
let buttons = [BUTTON_CONFIGS.close];
|
|
54
|
-
if (props.multiple) {
|
|
55
|
-
buttons = [BUTTON_CONFIGS.prev, BUTTON_CONFIGS.close, BUTTON_CONFIGS.next];
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** @type {HTMLButtonElement | undefined} */
|
|
59
|
-
let initialFocusButton;
|
|
60
|
-
for (let i = 0; i < buttons.length; i += 1) {
|
|
61
|
-
const buttonConfig = buttons[i];
|
|
62
|
-
|
|
63
|
-
const button = document.createElement('button');
|
|
64
|
-
button.id = buttonConfig.id;
|
|
65
|
-
button.innerHTML = buttonConfig.label;
|
|
66
|
-
button.tabIndex = 1;
|
|
67
|
-
button.style.backgroundColor = '#' + theme.dimgrey;
|
|
68
|
-
button.style.border = 'none';
|
|
69
|
-
button.style.color = '#' + theme.white;
|
|
70
|
-
button.style.cursor = 'pointer';
|
|
71
|
-
button.style.fontSize = 'inherit';
|
|
72
|
-
button.style.height = '100%';
|
|
73
|
-
button.style.padding = '0.5rem 0.75rem';
|
|
74
|
-
button.style.width = (100 / buttons.length).toString(10) + '%';
|
|
75
|
-
button.addEventListener('click', buttonConfig.onClick);
|
|
76
|
-
|
|
77
|
-
if (buttonConfig.id === props.initialFocus) {
|
|
78
|
-
initialFocusButton = button;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
footer.appendChild(button);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
root.appendChild(footer);
|
|
85
|
-
|
|
86
|
-
Spacer(document, root, { space: '2.5rem' });
|
|
87
|
-
|
|
88
|
-
if (initialFocusButton) {
|
|
89
|
-
initialFocusButton.focus();
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
module.exports = RuntimeErrorFooter;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
const Spacer = require('./Spacer.js');
|
|
2
|
-
const theme = require('../theme.js');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @typedef {Object} RuntimeErrorHeaderProps
|
|
6
|
-
* @property {number} currentErrorIndex
|
|
7
|
-
* @property {number} totalErrors
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* A fixed header that shows the total runtime error count.
|
|
12
|
-
* @param {Document} document
|
|
13
|
-
* @param {HTMLElement} root
|
|
14
|
-
* @param {RuntimeErrorHeaderProps} props
|
|
15
|
-
* @returns {void}
|
|
16
|
-
*/
|
|
17
|
-
function RuntimeErrorHeader(document, root, props) {
|
|
18
|
-
const header = document.createElement('div');
|
|
19
|
-
header.innerText =
|
|
20
|
-
'Error ' + (props.currentErrorIndex + 1) + ' of ' + props.totalErrors;
|
|
21
|
-
header.style.backgroundColor = '#' + theme.red;
|
|
22
|
-
header.style.color = '#' + theme.white;
|
|
23
|
-
header.style.fontWeight = '500';
|
|
24
|
-
header.style.height = '2.5rem';
|
|
25
|
-
header.style.left = '0';
|
|
26
|
-
header.style.lineHeight = '2.5rem';
|
|
27
|
-
header.style.position = 'fixed';
|
|
28
|
-
header.style.textAlign = 'center';
|
|
29
|
-
header.style.top = '0';
|
|
30
|
-
header.style.width = '100vw';
|
|
31
|
-
header.style.zIndex = '2';
|
|
32
|
-
|
|
33
|
-
root.appendChild(header);
|
|
34
|
-
|
|
35
|
-
Spacer(document, root, { space: '2.5rem' });
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
module.exports = RuntimeErrorHeader;
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
const ErrorStackParser = require('error-stack-parser');
|
|
2
|
-
const theme = require('../theme.js');
|
|
3
|
-
const utils = require('../utils.js');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @typedef {Object} RuntimeErrorStackProps
|
|
7
|
-
* @property {Error} error
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* A formatter that turns runtime error stacks into highlighted HTML stacks.
|
|
12
|
-
* @param {Document} document
|
|
13
|
-
* @param {HTMLElement} root
|
|
14
|
-
* @param {RuntimeErrorStackProps} props
|
|
15
|
-
* @returns {void}
|
|
16
|
-
*/
|
|
17
|
-
function RuntimeErrorStack(document, root, props) {
|
|
18
|
-
const stackTitle = document.createElement('h4');
|
|
19
|
-
stackTitle.innerText = 'Call Stack';
|
|
20
|
-
stackTitle.style.color = '#' + theme.white;
|
|
21
|
-
stackTitle.style.fontSize = '1.0625rem';
|
|
22
|
-
stackTitle.style.fontWeight = '500';
|
|
23
|
-
stackTitle.style.lineHeight = '1.3';
|
|
24
|
-
stackTitle.style.margin = '0 0 0.5rem';
|
|
25
|
-
|
|
26
|
-
const stackContainer = document.createElement('div');
|
|
27
|
-
stackContainer.style.fontSize = '0.8125rem';
|
|
28
|
-
stackContainer.style.lineHeight = '1.3';
|
|
29
|
-
stackContainer.style.whiteSpace = 'pre-wrap';
|
|
30
|
-
|
|
31
|
-
let errorStacks;
|
|
32
|
-
try {
|
|
33
|
-
errorStacks = ErrorStackParser.parse(props.error);
|
|
34
|
-
} catch (e) {
|
|
35
|
-
errorStacks = [];
|
|
36
|
-
stackContainer.innerHTML = 'No stack trace is available for this error!';
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
for (let i = 0; i < Math.min(errorStacks.length, 10); i += 1) {
|
|
40
|
-
const currentStack = errorStacks[i];
|
|
41
|
-
|
|
42
|
-
const functionName = document.createElement('code');
|
|
43
|
-
functionName.innerHTML =
|
|
44
|
-
' ' + currentStack.functionName || '(anonymous function)';
|
|
45
|
-
functionName.style.color = '#' + theme.yellow;
|
|
46
|
-
functionName.style.fontFamily = [
|
|
47
|
-
'"Operator Mono SSm"',
|
|
48
|
-
'"Operator Mono"',
|
|
49
|
-
'"Fira Code Retina"',
|
|
50
|
-
'"Fira Code"',
|
|
51
|
-
'"FiraCode-Retina"',
|
|
52
|
-
'"Andale Mono"',
|
|
53
|
-
'"Lucida Console"',
|
|
54
|
-
'Menlo',
|
|
55
|
-
'Consolas',
|
|
56
|
-
'Monaco',
|
|
57
|
-
'monospace',
|
|
58
|
-
].join(', ');
|
|
59
|
-
|
|
60
|
-
const fileName = document.createElement('div');
|
|
61
|
-
fileName.innerHTML =
|
|
62
|
-
'  ' +
|
|
63
|
-
utils.formatFilename(currentStack.fileName) +
|
|
64
|
-
':' +
|
|
65
|
-
currentStack.lineNumber +
|
|
66
|
-
':' +
|
|
67
|
-
currentStack.columnNumber;
|
|
68
|
-
fileName.style.color = '#' + theme.white;
|
|
69
|
-
fileName.style.fontSize = '0.6875rem';
|
|
70
|
-
fileName.style.marginBottom = '0.25rem';
|
|
71
|
-
|
|
72
|
-
stackContainer.appendChild(functionName);
|
|
73
|
-
stackContainer.appendChild(fileName);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
root.appendChild(stackTitle);
|
|
77
|
-
root.appendChild(stackContainer);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
module.exports = RuntimeErrorStack;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {Object} SpacerProps
|
|
3
|
-
* @property {string} space
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* An empty element to add spacing manually.
|
|
8
|
-
* @param {Document} document
|
|
9
|
-
* @param {HTMLElement} root
|
|
10
|
-
* @param {SpacerProps} props
|
|
11
|
-
* @returns {void}
|
|
12
|
-
*/
|
|
13
|
-
function Spacer(document, root, props) {
|
|
14
|
-
const spacer = document.createElement('div');
|
|
15
|
-
spacer.style.paddingBottom = props.space;
|
|
16
|
-
root.appendChild(spacer);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
module.exports = Spacer;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const CompileErrorTrace = require('../components/CompileErrorTrace.js');
|
|
2
|
-
const PageHeader = require('../components/PageHeader.js');
|
|
3
|
-
const Spacer = require('../components/Spacer.js');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @typedef {Object} CompileErrorContainerProps
|
|
7
|
-
* @property {string} errorMessage
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* A container to render Webpack compilation error messages with source trace.
|
|
12
|
-
* @param {Document} document
|
|
13
|
-
* @param {HTMLElement} root
|
|
14
|
-
* @param {CompileErrorContainerProps} props
|
|
15
|
-
* @returns {void}
|
|
16
|
-
*/
|
|
17
|
-
function CompileErrorContainer(document, root, props) {
|
|
18
|
-
PageHeader(document, root, {
|
|
19
|
-
title: 'Failed to compile.',
|
|
20
|
-
});
|
|
21
|
-
CompileErrorTrace(document, root, { errorMessage: props.errorMessage });
|
|
22
|
-
Spacer(document, root, { space: '1rem' });
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
module.exports = CompileErrorContainer;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
const PageHeader = require('../components/PageHeader.js');
|
|
2
|
-
const RuntimeErrorStack = require('../components/RuntimeErrorStack.js');
|
|
3
|
-
const Spacer = require('../components/Spacer.js');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @typedef {Object} RuntimeErrorContainerProps
|
|
7
|
-
* @property {Error} currentError
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* A container to render runtime error messages with stack trace.
|
|
12
|
-
* @param {Document} document
|
|
13
|
-
* @param {HTMLElement} root
|
|
14
|
-
* @param {RuntimeErrorContainerProps} props
|
|
15
|
-
* @returns {void}
|
|
16
|
-
*/
|
|
17
|
-
function RuntimeErrorContainer(document, root, props) {
|
|
18
|
-
PageHeader(document, root, {
|
|
19
|
-
message: props.currentError.message,
|
|
20
|
-
title: props.currentError.name,
|
|
21
|
-
topOffset: '2.5rem',
|
|
22
|
-
});
|
|
23
|
-
RuntimeErrorStack(document, root, {
|
|
24
|
-
error: props.currentError,
|
|
25
|
-
});
|
|
26
|
-
Spacer(document, root, { space: '1rem' });
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
module.exports = RuntimeErrorContainer;
|
package/client/overlay/index.js
DELETED
|
@@ -1,351 +0,0 @@
|
|
|
1
|
-
const RuntimeErrorFooter = require('./components/RuntimeErrorFooter.js');
|
|
2
|
-
const RuntimeErrorHeader = require('./components/RuntimeErrorHeader.js');
|
|
3
|
-
const CompileErrorContainer = require('./containers/CompileErrorContainer.js');
|
|
4
|
-
const RuntimeErrorContainer = require('./containers/RuntimeErrorContainer.js');
|
|
5
|
-
const theme = require('./theme.js');
|
|
6
|
-
const utils = require('./utils.js');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @callback RenderFn
|
|
10
|
-
* @returns {void}
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/* ===== Cached elements for DOM manipulations ===== */
|
|
14
|
-
/**
|
|
15
|
-
* The iframe that contains the overlay.
|
|
16
|
-
* @type {HTMLIFrameElement}
|
|
17
|
-
*/
|
|
18
|
-
let iframeRoot = null;
|
|
19
|
-
/**
|
|
20
|
-
* The document object from the iframe root, used to create and render elements.
|
|
21
|
-
* @type {Document}
|
|
22
|
-
*/
|
|
23
|
-
let rootDocument = null;
|
|
24
|
-
/**
|
|
25
|
-
* The root div elements will attach to.
|
|
26
|
-
* @type {HTMLDivElement}
|
|
27
|
-
*/
|
|
28
|
-
let root = null;
|
|
29
|
-
/**
|
|
30
|
-
* A Cached function to allow deferred render.
|
|
31
|
-
* @type {RenderFn | null}
|
|
32
|
-
*/
|
|
33
|
-
let scheduledRenderFn = null;
|
|
34
|
-
|
|
35
|
-
/* ===== Overlay State ===== */
|
|
36
|
-
/**
|
|
37
|
-
* The latest error message from Webpack compilation.
|
|
38
|
-
* @type {string}
|
|
39
|
-
*/
|
|
40
|
-
let currentCompileErrorMessage = '';
|
|
41
|
-
/**
|
|
42
|
-
* Index of the error currently shown by the overlay.
|
|
43
|
-
* @type {number}
|
|
44
|
-
*/
|
|
45
|
-
let currentRuntimeErrorIndex = 0;
|
|
46
|
-
/**
|
|
47
|
-
* The latest runtime error objects.
|
|
48
|
-
* @type {Error[]}
|
|
49
|
-
*/
|
|
50
|
-
let currentRuntimeErrors = [];
|
|
51
|
-
/**
|
|
52
|
-
* The render mode the overlay is currently in.
|
|
53
|
-
* @type {'compileError' | 'runtimeError' | null}
|
|
54
|
-
*/
|
|
55
|
-
let currentMode = null;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* @typedef {Object} IframeProps
|
|
59
|
-
* @property {function(): void} onIframeLoad
|
|
60
|
-
*/
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Creates the main `iframe` the overlay will attach to.
|
|
64
|
-
* Accepts a callback to be ran after iframe is initialized.
|
|
65
|
-
* @param {Document} document
|
|
66
|
-
* @param {HTMLElement} root
|
|
67
|
-
* @param {IframeProps} props
|
|
68
|
-
* @returns {HTMLIFrameElement}
|
|
69
|
-
*/
|
|
70
|
-
function IframeRoot(document, root, props) {
|
|
71
|
-
const iframe = document.createElement('iframe');
|
|
72
|
-
iframe.id = 'react-refresh-overlay';
|
|
73
|
-
iframe.src = 'about:blank';
|
|
74
|
-
|
|
75
|
-
iframe.style.border = 'none';
|
|
76
|
-
iframe.style.height = '100%';
|
|
77
|
-
iframe.style.left = '0';
|
|
78
|
-
iframe.style.minHeight = '100vh';
|
|
79
|
-
iframe.style.minHeight = '-webkit-fill-available';
|
|
80
|
-
iframe.style.position = 'fixed';
|
|
81
|
-
iframe.style.top = '0';
|
|
82
|
-
iframe.style.width = '100vw';
|
|
83
|
-
iframe.style.zIndex = '2147483647';
|
|
84
|
-
iframe.addEventListener('load', function onLoad() {
|
|
85
|
-
// Reset margin of iframe body
|
|
86
|
-
iframe.contentDocument.body.style.margin = '0';
|
|
87
|
-
props.onIframeLoad();
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
// We skip mounting and returns as we need to ensure
|
|
91
|
-
// the load event is fired after we setup the global variable
|
|
92
|
-
return iframe;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Creates the main `div` element for the overlay to render.
|
|
97
|
-
* @param {Document} document
|
|
98
|
-
* @param {HTMLElement} root
|
|
99
|
-
* @returns {HTMLDivElement}
|
|
100
|
-
*/
|
|
101
|
-
function OverlayRoot(document, root) {
|
|
102
|
-
const div = document.createElement('div');
|
|
103
|
-
div.id = 'react-refresh-overlay-error';
|
|
104
|
-
|
|
105
|
-
// Style the contents container
|
|
106
|
-
div.style.backgroundColor = '#' + theme.grey;
|
|
107
|
-
div.style.boxSizing = 'border-box';
|
|
108
|
-
div.style.color = '#' + theme.white;
|
|
109
|
-
div.style.fontFamily = [
|
|
110
|
-
'-apple-system',
|
|
111
|
-
'BlinkMacSystemFont',
|
|
112
|
-
'"Segoe UI"',
|
|
113
|
-
'"Helvetica Neue"',
|
|
114
|
-
'Helvetica',
|
|
115
|
-
'Arial',
|
|
116
|
-
'sans-serif',
|
|
117
|
-
'"Apple Color Emoji"',
|
|
118
|
-
'"Segoe UI Emoji"',
|
|
119
|
-
'Segoe UI Symbol',
|
|
120
|
-
].join(', ');
|
|
121
|
-
div.style.fontSize = '0.875rem';
|
|
122
|
-
div.style.height = '100%';
|
|
123
|
-
div.style.lineHeight = '1.3';
|
|
124
|
-
div.style.overflow = 'auto';
|
|
125
|
-
div.style.padding = '1rem 1.5rem 0';
|
|
126
|
-
div.style.paddingTop = 'max(1rem, env(safe-area-inset-top))';
|
|
127
|
-
div.style.paddingRight = 'max(1.5rem, env(safe-area-inset-right))';
|
|
128
|
-
div.style.paddingBottom = 'env(safe-area-inset-bottom)';
|
|
129
|
-
div.style.paddingLeft = 'max(1.5rem, env(safe-area-inset-left))';
|
|
130
|
-
div.style.width = '100vw';
|
|
131
|
-
|
|
132
|
-
root.appendChild(div);
|
|
133
|
-
return div;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Ensures the iframe root and the overlay root are both initialized before render.
|
|
138
|
-
* If check fails, render will be deferred until both roots are initialized.
|
|
139
|
-
* @param {RenderFn} renderFn A function that triggers a DOM render.
|
|
140
|
-
* @returns {void}
|
|
141
|
-
*/
|
|
142
|
-
function ensureRootExists(renderFn) {
|
|
143
|
-
if (root) {
|
|
144
|
-
// Overlay root is ready, we can render right away.
|
|
145
|
-
renderFn();
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Creating an iframe may be asynchronous so we'll defer render.
|
|
150
|
-
// In case of multiple calls, function from the last call will be used.
|
|
151
|
-
scheduledRenderFn = renderFn;
|
|
152
|
-
|
|
153
|
-
if (iframeRoot) {
|
|
154
|
-
// Iframe is already ready, it will fire the load event.
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// Create the iframe root, and, the overlay root inside it when it is ready.
|
|
159
|
-
iframeRoot = IframeRoot(document, document.body, {
|
|
160
|
-
onIframeLoad: function onIframeLoad() {
|
|
161
|
-
rootDocument = iframeRoot.contentDocument;
|
|
162
|
-
root = OverlayRoot(rootDocument, rootDocument.body);
|
|
163
|
-
scheduledRenderFn();
|
|
164
|
-
},
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
// We have to mount here to ensure `iframeRoot` is set when `onIframeLoad` fires.
|
|
168
|
-
// This is because onIframeLoad() will be called synchronously
|
|
169
|
-
// or asynchronously depending on the browser.
|
|
170
|
-
document.body.appendChild(iframeRoot);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Creates the main `div` element for the overlay to render.
|
|
175
|
-
* @returns {void}
|
|
176
|
-
*/
|
|
177
|
-
function render() {
|
|
178
|
-
ensureRootExists(function () {
|
|
179
|
-
const currentFocus = rootDocument.activeElement;
|
|
180
|
-
let currentFocusId;
|
|
181
|
-
if (currentFocus.localName === 'button' && currentFocus.id) {
|
|
182
|
-
currentFocusId = currentFocus.id;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
utils.removeAllChildren(root);
|
|
186
|
-
|
|
187
|
-
if (currentCompileErrorMessage) {
|
|
188
|
-
currentMode = 'compileError';
|
|
189
|
-
|
|
190
|
-
CompileErrorContainer(rootDocument, root, {
|
|
191
|
-
errorMessage: currentCompileErrorMessage,
|
|
192
|
-
});
|
|
193
|
-
} else if (currentRuntimeErrors.length) {
|
|
194
|
-
currentMode = 'runtimeError';
|
|
195
|
-
|
|
196
|
-
RuntimeErrorHeader(rootDocument, root, {
|
|
197
|
-
currentErrorIndex: currentRuntimeErrorIndex,
|
|
198
|
-
totalErrors: currentRuntimeErrors.length,
|
|
199
|
-
});
|
|
200
|
-
RuntimeErrorContainer(rootDocument, root, {
|
|
201
|
-
currentError: currentRuntimeErrors[currentRuntimeErrorIndex],
|
|
202
|
-
});
|
|
203
|
-
RuntimeErrorFooter(rootDocument, root, {
|
|
204
|
-
initialFocus: currentFocusId,
|
|
205
|
-
multiple: currentRuntimeErrors.length > 1,
|
|
206
|
-
onClickCloseButton: function onClose() {
|
|
207
|
-
clearRuntimeErrors();
|
|
208
|
-
},
|
|
209
|
-
onClickNextButton: function onNext() {
|
|
210
|
-
if (currentRuntimeErrorIndex === currentRuntimeErrors.length - 1) {
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
currentRuntimeErrorIndex += 1;
|
|
214
|
-
ensureRootExists(render);
|
|
215
|
-
},
|
|
216
|
-
onClickPrevButton: function onPrev() {
|
|
217
|
-
if (currentRuntimeErrorIndex === 0) {
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
currentRuntimeErrorIndex -= 1;
|
|
221
|
-
ensureRootExists(render);
|
|
222
|
-
},
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Destroys the state of the overlay.
|
|
230
|
-
* @returns {void}
|
|
231
|
-
*/
|
|
232
|
-
function cleanup() {
|
|
233
|
-
// Clean up and reset all internal state.
|
|
234
|
-
try {
|
|
235
|
-
document.body.removeChild(iframeRoot);
|
|
236
|
-
} catch (e) {
|
|
237
|
-
// In case user render react app directly to body, will trigger `NotFoundError` when recovery from an Error
|
|
238
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/Node/removeChild#exceptions
|
|
239
|
-
}
|
|
240
|
-
scheduledRenderFn = null;
|
|
241
|
-
root = null;
|
|
242
|
-
iframeRoot = null;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Clears Webpack compilation errors and dismisses the compile error overlay.
|
|
247
|
-
* @returns {void}
|
|
248
|
-
*/
|
|
249
|
-
function clearCompileError() {
|
|
250
|
-
if (!root || currentMode !== 'compileError') {
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
currentCompileErrorMessage = '';
|
|
255
|
-
currentMode = null;
|
|
256
|
-
cleanup();
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Clears runtime error records and dismisses the runtime error overlay.
|
|
261
|
-
* @param {boolean} [dismissOverlay] Whether to dismiss the overlay or not.
|
|
262
|
-
* @returns {void}
|
|
263
|
-
*/
|
|
264
|
-
function clearRuntimeErrors(dismissOverlay) {
|
|
265
|
-
if (!root || currentMode !== 'runtimeError') {
|
|
266
|
-
return;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
currentRuntimeErrorIndex = 0;
|
|
270
|
-
currentRuntimeErrors = [];
|
|
271
|
-
|
|
272
|
-
if (typeof dismissOverlay === 'undefined' || dismissOverlay) {
|
|
273
|
-
currentMode = null;
|
|
274
|
-
cleanup();
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Shows the compile error overlay with the specific Webpack error message.
|
|
280
|
-
* @param {string} message
|
|
281
|
-
* @returns {void}
|
|
282
|
-
*/
|
|
283
|
-
function showCompileError(message) {
|
|
284
|
-
if (!message) {
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
currentCompileErrorMessage = message;
|
|
289
|
-
|
|
290
|
-
render();
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* Shows the runtime error overlay with the specific error records.
|
|
295
|
-
* @param {Error[]} errors
|
|
296
|
-
* @returns {void}
|
|
297
|
-
*/
|
|
298
|
-
function showRuntimeErrors(errors) {
|
|
299
|
-
if (!errors || !errors.length) {
|
|
300
|
-
return;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
currentRuntimeErrors = errors;
|
|
304
|
-
|
|
305
|
-
render();
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* The debounced version of `showRuntimeErrors` to prevent frequent renders
|
|
310
|
-
* due to rapid firing listeners.
|
|
311
|
-
* @param {Error[]} errors
|
|
312
|
-
* @returns {void}
|
|
313
|
-
*/
|
|
314
|
-
const debouncedShowRuntimeErrors = utils.debounce(showRuntimeErrors, 30);
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* Detects if an error is a Webpack compilation error.
|
|
318
|
-
* @param {Error} error The error of interest.
|
|
319
|
-
* @returns {boolean} If the error is a Webpack compilation error.
|
|
320
|
-
*/
|
|
321
|
-
function isWebpackCompileError(error) {
|
|
322
|
-
return (
|
|
323
|
-
/Module [A-z ]+\(from/.test(error.message) ||
|
|
324
|
-
/Cannot find module/.test(error.message)
|
|
325
|
-
);
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
* Handles runtime error contexts captured with EventListeners.
|
|
330
|
-
* Integrates with a runtime error overlay.
|
|
331
|
-
* @param {Error} error A valid error object.
|
|
332
|
-
* @returns {void}
|
|
333
|
-
*/
|
|
334
|
-
function handleRuntimeError(error) {
|
|
335
|
-
if (
|
|
336
|
-
error &&
|
|
337
|
-
!isWebpackCompileError(error) &&
|
|
338
|
-
currentRuntimeErrors.indexOf(error) === -1
|
|
339
|
-
) {
|
|
340
|
-
currentRuntimeErrors = currentRuntimeErrors.concat(error);
|
|
341
|
-
}
|
|
342
|
-
debouncedShowRuntimeErrors(currentRuntimeErrors);
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
module.exports = Object.freeze({
|
|
346
|
-
clearCompileError: clearCompileError,
|
|
347
|
-
clearRuntimeErrors: clearRuntimeErrors,
|
|
348
|
-
handleRuntimeError: handleRuntimeError,
|
|
349
|
-
showCompileError: showCompileError,
|
|
350
|
-
showRuntimeErrors: showRuntimeErrors,
|
|
351
|
-
});
|
package/client/overlay/theme.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {Object} Theme
|
|
3
|
-
* @property {string[]} reset
|
|
4
|
-
* @property {string} black
|
|
5
|
-
* @property {string} red
|
|
6
|
-
* @property {string} green
|
|
7
|
-
* @property {string} yellow
|
|
8
|
-
* @property {string} blue
|
|
9
|
-
* @property {string} magenta
|
|
10
|
-
* @property {string} cyan
|
|
11
|
-
* @property {string} white
|
|
12
|
-
* @property {string} lightgrey
|
|
13
|
-
* @property {string} darkgrey
|
|
14
|
-
* @property {string} grey
|
|
15
|
-
* @property {string} dimgrey
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @type {Theme} theme
|
|
20
|
-
* A collection of colors to be used by the overlay.
|
|
21
|
-
* Partially adopted from Tomorrow Night Bright.
|
|
22
|
-
*/
|
|
23
|
-
const theme = {
|
|
24
|
-
reset: ['transparent', 'transparent'],
|
|
25
|
-
black: '000000',
|
|
26
|
-
red: 'D34F56',
|
|
27
|
-
green: 'B9C954',
|
|
28
|
-
yellow: 'E6C452',
|
|
29
|
-
blue: '7CA7D8',
|
|
30
|
-
magenta: 'C299D6',
|
|
31
|
-
cyan: '73BFB1',
|
|
32
|
-
white: 'FFFFFF',
|
|
33
|
-
lightgrey: 'C7C7C7',
|
|
34
|
-
darkgrey: 'A9A9A9',
|
|
35
|
-
grey: '474747',
|
|
36
|
-
dimgrey: '343434',
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
module.exports = theme;
|