Izmjenjena struktura, dodan backand

This commit is contained in:
GotPPay
2017-10-16 11:19:46 +02:00
parent 1ec88afacb
commit 048e32c4aa
37153 changed files with 2975854 additions and 1 deletions

View File

@@ -0,0 +1,58 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { applyStyles } from '../utils/dom/css';
import { additionalChildStyle, groupStyle, groupElemLeft, groupElemRight } from '../styles';
import { consumeEvent } from '../utils/dom/consumeEvent';
import { enableTabClick } from '../utils/dom/enableTabClick';
function updateAdditional(document, additionalReference, currentError, totalErrors, switchCallback) {
if (additionalReference.lastChild) {
additionalReference.removeChild(additionalReference.lastChild);
}
if (totalErrors <= 1) {
return;
}
var div = document.createElement('div');
applyStyles(div, additionalChildStyle);
var group = document.createElement('span');
applyStyles(group, groupStyle);
var left = document.createElement('button');
applyStyles(left, groupElemLeft);
left.addEventListener('click', function (e) {
consumeEvent(e);
switchCallback(-1);
});
left.appendChild(document.createTextNode('←'));
enableTabClick(left);
var right = document.createElement('button');
applyStyles(right, groupElemRight);
right.addEventListener('click', function (e) {
consumeEvent(e);
switchCallback(1);
});
right.appendChild(document.createTextNode('→'));
enableTabClick(right);
group.appendChild(left);
group.appendChild(right);
div.appendChild(group);
var text = currentError + ' of ' + totalErrors + ' errors on the page';
div.appendChild(document.createTextNode(text));
additionalReference.appendChild(div);
}
export { updateAdditional };

View File

@@ -0,0 +1,34 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { applyStyles } from '../utils/dom/css';
import { hintsStyle, hintStyle, closeButtonStyle } from '../styles';
function createHint(document, hint, title) {
var span = document.createElement('span');
span.appendChild(document.createTextNode(hint));
span.setAttribute('title', title);
applyStyles(span, hintStyle);
return span;
}
function createClose(document, callback) {
var hints = document.createElement('div');
applyStyles(hints, hintsStyle);
var close = createHint(document, '×', 'Click or press Escape to dismiss.');
close.addEventListener('click', function () {
return callback();
});
applyStyles(close, closeButtonStyle);
hints.appendChild(close);
return hints;
}
export { createClose };

View File

@@ -0,0 +1,90 @@
import { applyStyles } from '../utils/dom/css'; /**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { absolutifyCaret } from '../utils/dom/absolutifyCaret';
import { codeStyle, primaryErrorStyle, primaryPreStyle, secondaryErrorStyle, secondaryPreStyle } from '../styles';
import generateAnsiHtml from 'react-dev-utils/ansiHTML';
import codeFrame from 'babel-code-frame';
function createCode(document, sourceLines, lineNum, columnNum, contextSize, main, onSourceClick) {
var sourceCode = [];
var whiteSpace = Infinity;
sourceLines.forEach(function (e) {
var text = e.content;
var m = text.match(/^\s*/);
if (text === '') {
return;
}
if (m && m[0]) {
whiteSpace = Math.min(whiteSpace, m[0].length);
} else {
whiteSpace = 0;
}
});
sourceLines.forEach(function (e) {
var text = e.content;
var line = e.lineNumber;
if (isFinite(whiteSpace)) {
text = text.substring(whiteSpace);
}
sourceCode[line - 1] = text;
});
var ansiHighlight = codeFrame(sourceCode.join('\n'), lineNum, columnNum == null ? 0 : columnNum - (isFinite(whiteSpace) ? whiteSpace : 0), {
forceColor: true,
linesAbove: contextSize,
linesBelow: contextSize
});
var htmlHighlight = generateAnsiHtml(ansiHighlight);
var code = document.createElement('code');
code.innerHTML = htmlHighlight;
absolutifyCaret(code);
applyStyles(code, codeStyle);
var ccn = code.childNodes;
// eslint-disable-next-line
oLoop: for (var index = 0; index < ccn.length; ++index) {
var node = ccn[index];
var ccn2 = node.childNodes;
for (var index2 = 0; index2 < ccn2.length; ++index2) {
var lineNode = ccn2[index2];
var text = lineNode.innerText;
if (text == null) {
continue;
}
if (text.indexOf(' ' + lineNum + ' |') === -1) {
continue;
}
// $FlowFixMe
applyStyles(node, main ? primaryErrorStyle : secondaryErrorStyle);
// eslint-disable-next-line
break oLoop;
}
}
var pre = document.createElement('pre');
applyStyles(pre, main ? primaryPreStyle : secondaryPreStyle);
pre.appendChild(code);
if (typeof onSourceClick === 'function') {
var handler = onSourceClick;
pre.style.cursor = 'pointer';
pre.addEventListener('click', function () {
handler();
});
}
return pre;
}
export { createCode };

View File

@@ -0,0 +1,22 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { applyStyles } from '../utils/dom/css';
import { footerStyle } from '../styles';
function createFooter(document) {
var div = document.createElement('div');
applyStyles(div, footerStyle);
div.appendChild(document.createTextNode('This screen is visible only in development. It will not appear if the app crashes in production.'));
div.appendChild(document.createElement('br'));
div.appendChild(document.createTextNode('Open your browsers developer console to further inspect this error.'));
return div;
}
export { createFooter };

View File

@@ -0,0 +1,241 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { enableTabClick } from '../utils/dom/enableTabClick';
import { createCode } from './code';
import { isInternalFile } from '../utils/isInternalFile';
import { applyStyles } from '../utils/dom/css';
import { omittedFramesExpandedStyle, omittedFramesCollapsedStyle, functionNameStyle, depStyle, linkStyle, anchorStyle, hiddenStyle } from '../styles';
function getGroupToggle(document, omitsCount, omitBundle) {
var omittedFrames = document.createElement('div');
enableTabClick(omittedFrames);
var text1 = document.createTextNode('\u25B6 ' + omitsCount + ' stack frames were collapsed.');
omittedFrames.appendChild(text1);
omittedFrames.addEventListener('click', function () {
var hide = text1.textContent.match(/▲/);
var list = document.getElementsByName('bundle-' + omitBundle);
for (var index = 0; index < list.length; ++index) {
var n = list[index];
if (hide) {
n.style.display = 'none';
} else {
n.style.display = '';
}
}
if (hide) {
text1.textContent = text1.textContent.replace(/▲/, '▶');
text1.textContent = text1.textContent.replace(/expanded/, 'collapsed');
applyStyles(omittedFrames, omittedFramesCollapsedStyle);
} else {
text1.textContent = text1.textContent.replace(/▶/, '▲');
text1.textContent = text1.textContent.replace(/collapsed/, 'expanded');
applyStyles(omittedFrames, omittedFramesExpandedStyle);
}
});
applyStyles(omittedFrames, omittedFramesCollapsedStyle);
return omittedFrames;
}
function insertBeforeBundle(document, parent, omitsCount, omitBundle, actionElement) {
var children = document.getElementsByName('bundle-' + omitBundle);
if (children.length < 1) {
return;
}
var first = children[0];
while (first != null && first.parentNode !== parent) {
first = first.parentNode;
}
var div = document.createElement('div');
enableTabClick(div);
div.setAttribute('name', 'bundle-' + omitBundle);
var text = document.createTextNode('\u25BC ' + omitsCount + ' stack frames were expanded.');
div.appendChild(text);
div.addEventListener('click', function () {
return actionElement.click();
});
applyStyles(div, omittedFramesExpandedStyle);
div.style.display = 'none';
parent.insertBefore(div, first);
}
function frameDiv(document, functionName, url, internalUrl, onSourceClick) {
var frame = document.createElement('div');
var frameFunctionName = document.createElement('div');
var cleanedFunctionName = void 0;
if (!functionName || functionName === 'Object.<anonymous>') {
cleanedFunctionName = '(anonymous function)';
} else {
cleanedFunctionName = functionName;
}
var cleanedUrl = url.replace('webpack://', '.');
if (internalUrl) {
applyStyles(frameFunctionName, Object.assign({}, functionNameStyle, depStyle));
} else {
applyStyles(frameFunctionName, functionNameStyle);
}
frameFunctionName.appendChild(document.createTextNode(cleanedFunctionName));
frame.appendChild(frameFunctionName);
var frameLink = document.createElement('div');
applyStyles(frameLink, linkStyle);
var frameAnchor = document.createElement('a');
applyStyles(frameAnchor, anchorStyle);
frameAnchor.appendChild(document.createTextNode(cleanedUrl));
frameLink.appendChild(frameAnchor);
frame.appendChild(frameLink);
if (typeof onSourceClick === 'function') {
var handler = onSourceClick;
enableTabClick(frameAnchor);
frameAnchor.style.cursor = 'pointer';
frameAnchor.addEventListener('click', function () {
handler();
});
}
return frame;
}
function isBultinErrorName(errorName) {
switch (errorName) {
case 'EvalError':
case 'InternalError':
case 'RangeError':
case 'ReferenceError':
case 'SyntaxError':
case 'TypeError':
case 'URIError':
return true;
default:
return false;
}
}
function getPrettyURL(sourceFileName, sourceLineNumber, sourceColumnNumber, fileName, lineNumber, columnNumber, compiled) {
var prettyURL = void 0;
if (!compiled && sourceFileName && typeof sourceLineNumber === 'number') {
// Remove everything up to the first /src/ or /node_modules/
var trimMatch = /^[/|\\].*?[/|\\]((src|node_modules)[/|\\].*)/.exec(sourceFileName);
if (trimMatch && trimMatch[1]) {
prettyURL = trimMatch[1];
} else {
prettyURL = sourceFileName;
}
prettyURL += ':' + sourceLineNumber;
// Note: we intentionally skip 0's because they're produced by cheap Webpack maps
if (sourceColumnNumber) {
prettyURL += ':' + sourceColumnNumber;
}
} else if (fileName && typeof lineNumber === 'number') {
prettyURL = fileName + ':' + lineNumber;
// Note: we intentionally skip 0's because they're produced by cheap Webpack maps
if (columnNumber) {
prettyURL += ':' + columnNumber;
}
} else {
prettyURL = 'unknown';
}
return prettyURL;
}
function createFrame(document, frameSetting, frame, contextSize, critical, omits, omitBundle, parentContainer, lastElement, errorName) {
var compiled = frameSetting.compiled;
var functionName = frame.functionName,
sourceFileName = frame._originalFileName;
var fileName = frame.fileName,
lineNumber = frame.lineNumber,
columnNumber = frame.columnNumber,
scriptLines = frame._scriptCode,
sourceLineNumber = frame._originalLineNumber,
sourceColumnNumber = frame._originalColumnNumber,
sourceLines = frame._originalScriptCode;
// TODO: find a better place for this.
// Chrome has a bug with inferring function.name:
// https://github.com/facebookincubator/create-react-app/issues/2097
// Let's ignore a meaningless name we get for top-level modules.
if (functionName === 'Object.friendlySyntaxErrorLabel' || functionName === 'Object.exports.__esModule') {
functionName = '(anonymous function)';
}
var prettyURL = getPrettyURL(sourceFileName, sourceLineNumber, sourceColumnNumber, fileName, lineNumber, columnNumber, compiled);
var needsHidden = false;
var isInternalUrl = isInternalFile(sourceFileName, fileName);
var isThrownIntentionally = !isBultinErrorName(errorName);
var shouldCollapse = isInternalUrl && (isThrownIntentionally || omits.hasReachedAppCode);
if (!isInternalUrl) {
omits.hasReachedAppCode = true;
}
if (shouldCollapse) {
++omits.value;
needsHidden = true;
}
var collapseElement = null;
if (!shouldCollapse || lastElement) {
if (omits.value > 0) {
var capV = omits.value;
var omittedFrames = getGroupToggle(document, capV, omitBundle);
window.requestAnimationFrame(function () {
insertBeforeBundle(document, parentContainer, capV, omitBundle, omittedFrames);
});
if (lastElement && shouldCollapse) {
collapseElement = omittedFrames;
} else {
parentContainer.appendChild(omittedFrames);
}
++omits.bundle;
}
omits.value = 0;
}
var onSourceClick = null;
if (sourceFileName) {
// e.g. "/path-to-my-app/webpack/bootstrap eaddeb46b67d75e4dfc1"
var isInternalWebpackBootstrapCode = sourceFileName.trim().indexOf(' ') !== -1;
if (!isInternalWebpackBootstrapCode) {
onSourceClick = function onSourceClick() {
// Keep this in sync with react-error-overlay/middleware.js
fetch('/__open-stack-frame-in-editor?fileName=' + window.encodeURIComponent(sourceFileName) + '&lineNumber=' + window.encodeURIComponent(sourceLineNumber || 1)).then(function () {}, function () {});
};
}
}
var elem = frameDiv(document, functionName, prettyURL, shouldCollapse, onSourceClick);
if (needsHidden) {
applyStyles(elem, hiddenStyle);
elem.setAttribute('name', 'bundle-' + omitBundle);
}
var hasSource = false;
if (!shouldCollapse) {
if (compiled && scriptLines && scriptLines.length !== 0 && lineNumber != null) {
elem.appendChild(createCode(document, scriptLines, lineNumber, columnNumber, contextSize, critical, onSourceClick));
hasSource = true;
} else if (!compiled && sourceLines && sourceLines.length !== 0 && sourceLineNumber != null) {
elem.appendChild(createCode(document, sourceLines, sourceLineNumber, sourceColumnNumber, contextSize, critical, onSourceClick));
hasSource = true;
}
}
return { elem: elem, hasSource: hasSource, collapseElement: collapseElement };
}
export { createFrame };

View File

@@ -0,0 +1,82 @@
import { applyStyles } from '../utils/dom/css'; /**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { traceStyle, toggleStyle } from '../styles';
import { enableTabClick } from '../utils/dom/enableTabClick';
import { createFrame } from './frame';
function createFrameWrapper(document, parent, factory, lIndex, frameSettings, contextSize) {
var fac = factory();
if (fac == null) {
return;
}
var hasSource = fac.hasSource,
elem = fac.elem,
collapseElement = fac.collapseElement;
var elemWrapper = document.createElement('div');
elemWrapper.appendChild(elem);
if (hasSource) {
var compiledDiv = document.createElement('div');
enableTabClick(compiledDiv);
applyStyles(compiledDiv, toggleStyle);
var o = frameSettings[lIndex];
var compiledText = document.createTextNode('View ' + (o && o.compiled ? 'source' : 'compiled'));
compiledDiv.addEventListener('click', function () {
if (o) {
o.compiled = !o.compiled;
}
var next = createFrameWrapper(document, parent, factory, lIndex, frameSettings, contextSize);
if (next != null) {
parent.insertBefore(next, elemWrapper);
parent.removeChild(elemWrapper);
}
});
compiledDiv.appendChild(compiledText);
elemWrapper.appendChild(compiledDiv);
}
if (collapseElement != null) {
elemWrapper.appendChild(collapseElement);
}
return elemWrapper;
}
function createFrames(document, resolvedFrames, frameSettings, contextSize, errorName) {
if (resolvedFrames.length !== frameSettings.length) {
throw new Error('You must give a frame settings array of identical length to resolved frames.');
}
var trace = document.createElement('div');
applyStyles(trace, traceStyle);
var index = 0;
var critical = true;
var omits = { value: 0, bundle: 1, hasReachedAppCode: false };
resolvedFrames.forEach(function (frame) {
var lIndex = index++;
var elem = createFrameWrapper(document, trace, createFrame.bind(undefined, document, frameSettings[lIndex], frame, contextSize, critical, omits, omits.bundle, trace, index === resolvedFrames.length, errorName), lIndex, frameSettings, contextSize);
if (elem == null) {
return;
}
critical = false;
trace.appendChild(elem);
});
//TODO: fix this
omits.value = 0;
return trace;
}
export { createFrames };

View File

@@ -0,0 +1,71 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { applyStyles } from '../utils/dom/css';
import { containerStyle, overlayStyle, headerStyle } from '../styles';
import { createClose } from './close';
import { createFrames } from './frames';
import { createFooter } from './footer';
import { updateAdditional } from './additional';
function createOverlay(document, name, message, frames, contextSize, currentError, totalErrors, switchCallback, closeCallback) {
var frameSettings = frames.map(function () {
return { compiled: false };
});
// Create overlay
var overlay = document.createElement('div');
applyStyles(overlay, overlayStyle);
// Create container
var container = document.createElement('div');
applyStyles(container, containerStyle);
overlay.appendChild(container);
container.appendChild(createClose(document, closeCallback));
// Create "Errors X of Y" in case of multiple errors
var additional = document.createElement('div');
updateAdditional(document, additional, currentError, totalErrors, switchCallback);
container.appendChild(additional);
// Create header
var header = document.createElement('div');
applyStyles(header, headerStyle);
// Make message prettier
var finalMessage = message.match(/^\w*:/) || !name ? message : name + ': ' + message;
finalMessage = finalMessage
// TODO: maybe remove this prefix from fbjs?
// It's just scaring people
.replace(/^Invariant Violation:\s*/, '')
// This is not helpful either:
.replace(/^Warning:\s*/, '')
// Break the actionable part to the next line.
// AFAIK React 16+ should already do this.
.replace(' Check the render method', '\n\nCheck the render method').replace(' Check your code at', '\n\nCheck your code at');
// Put it in the DOM
header.appendChild(document.createTextNode(finalMessage));
container.appendChild(header);
// Create trace
container.appendChild(createFrames(document, frames, frameSettings, contextSize, name));
// Show message
container.appendChild(createFooter(document));
return {
overlay: overlay,
additional: additional
};
}
export { createOverlay };