@bacons/expo-metro-runtime
Version:
Tools for making experimental Metro bundler features work
146 lines • 5.96 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LogBoxInspectorCodeFrame = void 0;
/**
* Copyright (c) Evan Bacon.
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const react_1 = __importDefault(require("react"));
const react_native_1 = require("react-native");
const openFileInEditor_1 = __importDefault(require("../modules/openFileInEditor"));
const LogBoxData = __importStar(require("../Data/LogBoxData"));
const AnsiHighlight_1 = require("../UI/AnsiHighlight");
const constants_1 = require("../UI/constants");
const LogBoxButton_1 = require("../UI/LogBoxButton");
const LogBoxInspectorSection_1 = require("./LogBoxInspectorSection");
const LogBoxStyle = __importStar(require("../UI/LogBoxStyle"));
const formatProjectFilePath_1 = require("../formatProjectFilePath");
function LogBoxInspectorCodeFrame(props) {
const codeFrame = props.codeFrame;
if (codeFrame == null) {
return null;
}
function getFileName() {
return (0, formatProjectFilePath_1.formatProjectFileName)(codeFrame === null || codeFrame === void 0 ? void 0 : codeFrame.fileName);
}
function getLocation() {
const location = codeFrame === null || codeFrame === void 0 ? void 0 : codeFrame.location;
if (location != null) {
return ` (${location.row}:${location.column + 1 /* Code frame columns are zero indexed */})`;
}
return null;
}
return (react_1.default.createElement(LogBoxInspectorSection_1.LogBoxInspectorSection, { heading: "Source", action: react_1.default.createElement(AppInfo, null) },
react_1.default.createElement(react_native_1.View, { style: styles.box },
react_1.default.createElement(react_native_1.View, { style: styles.frame },
react_1.default.createElement(react_native_1.ScrollView, { horizontal: true },
react_1.default.createElement(AnsiHighlight_1.Ansi, { style: styles.content, text: codeFrame.content }))),
react_1.default.createElement(LogBoxButton_1.LogBoxButton, { backgroundColor: {
default: 'transparent',
pressed: LogBoxStyle.getBackgroundDarkColor(1),
}, style: styles.button, onPress: () => {
var _a, _b;
(0, openFileInEditor_1.default)(codeFrame.fileName, (_b = (_a = codeFrame.location) === null || _a === void 0 ? void 0 : _a.row) !== null && _b !== void 0 ? _b : 0);
} },
react_1.default.createElement(react_native_1.Text, { selectable: false, style: styles.fileText },
getFileName(),
getLocation())))));
}
exports.LogBoxInspectorCodeFrame = LogBoxInspectorCodeFrame;
function AppInfo() {
const appInfo = LogBoxData.getAppInfo();
if (appInfo == null) {
return null;
}
return (react_1.default.createElement(LogBoxButton_1.LogBoxButton, { backgroundColor: {
default: 'transparent',
pressed: appInfo.onPress
? LogBoxStyle.getBackgroundColor(1)
: 'transparent',
}, style: appInfoStyles.buildButton, onPress: appInfo.onPress },
react_1.default.createElement(react_native_1.Text, { style: appInfoStyles.text },
appInfo.appVersion,
" (",
appInfo.engine,
")")));
}
const appInfoStyles = react_native_1.StyleSheet.create({
text: {
color: LogBoxStyle.getTextColor(0.4),
fontSize: 12,
lineHeight: 12,
},
buildButton: {
flex: 0,
flexGrow: 0,
paddingVertical: 4,
paddingHorizontal: 5,
borderRadius: 5,
marginRight: -8,
},
});
const styles = react_native_1.StyleSheet.create({
box: {
backgroundColor: LogBoxStyle.getBackgroundColor(),
borderWidth: 1,
borderColor: "#323232",
marginLeft: 10,
marginRight: 10,
marginTop: 5,
borderRadius: 3,
},
frame: {
padding: 10,
borderBottomColor: LogBoxStyle.getTextColor(0.1),
borderBottomWidth: 1,
},
button: {
paddingTop: 10,
paddingBottom: 10,
},
content: {
color: LogBoxStyle.getTextColor(1),
fontSize: 12,
includeFontPadding: false,
lineHeight: 20,
fontFamily: constants_1.CODE_FONT,
},
fileText: {
color: LogBoxStyle.getTextColor(0.5),
textAlign: 'center',
flex: 1,
fontSize: 16,
includeFontPadding: false,
fontFamily: constants_1.CODE_FONT,
},
});
//# sourceMappingURL=LogBoxInspectorCodeFrame.js.map