flipper-plugin
Version:
Flipper Desktop plugin SDK and components
133 lines • 5.46 kB
JavaScript
/**
* 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.
*
* @format
*/
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.renderColumnValue = exports.TableRow = exports.DEFAULT_ROW_HEIGHT = void 0;
const react_1 = __importStar(require("react"));
const styled_1 = __importDefault(require("@emotion/styled"));
const theme_1 = require("../theme");
const DataFormatter_1 = require("../DataFormatter");
const antd_1 = require("antd");
const DataTableManager_1 = require("./DataTableManager");
const Highlight_1 = require("../Highlight");
// heuristic for row estimation, should match any future styling updates
exports.DEFAULT_ROW_HEIGHT = 24;
const backgroundColor = (props) => {
if (props.highlighted) {
return theme_1.theme.selectionBackgroundColor;
}
return undefined;
};
const CircleMargin = 4;
const RowContextMenuWrapper = styled_1.default.div({
position: 'absolute',
top: 0,
right: 0,
paddingRight: CircleMargin,
fontSize: exports.DEFAULT_ROW_HEIGHT - CircleMargin * 2,
color: theme_1.theme.primaryColor,
cursor: 'pointer',
visibility: 'hidden',
});
const TableBodyRowContainer = styled_1.default.div((props) => ({
display: 'flex',
flexDirection: 'row',
backgroundColor: backgroundColor(props),
borderLeft: props.highlighted
? `4px solid ${theme_1.theme.primaryColor}`
: `4px solid transparent`,
borderBottom: `1px solid ${theme_1.theme.dividerColor}`,
paddingTop: 1,
minHeight: exports.DEFAULT_ROW_HEIGHT,
lineHeight: `${exports.DEFAULT_ROW_HEIGHT - 2}px`,
'& .anticon': {
lineHeight: `${exports.DEFAULT_ROW_HEIGHT - 2}px`,
},
overflow: 'hidden',
width: '100%',
flexShrink: 0,
[`&:hover ${RowContextMenuWrapper}`]: {
visibility: 'visible',
},
}));
TableBodyRowContainer.displayName = 'TableRow:TableBodyRowContainer';
const TableBodyColumnContainer = styled_1.default.div((props) => ({
flexShrink: props.width === undefined ? 1 : 0,
flexGrow: props.width === undefined ? 1 : 0,
overflow: 'hidden',
padding: `0 ${theme_1.theme.space.small}px`,
verticalAlign: 'top',
// pre-wrap preserves explicit newlines and whitespace, and wraps as well when needed
whiteSpace: props.multiline ? 'pre-wrap' : 'nowrap',
wordWrap: props.multiline ? 'break-word' : 'normal',
width: props.width,
minWidth: 25,
textAlign: props.justifyContent,
justifyContent: props.justifyContent,
'&::selection': {
color: 'inherit',
backgroundColor: theme_1.theme.buttonDefaultBackground,
},
'& p': {
margin: 0,
},
}));
TableBodyColumnContainer.displayName = 'TableRow:TableBodyColumnContainer';
exports.TableRow = (0, react_1.memo)(function TableRow({ record, itemIndex, highlighted, config, }) {
const highlighter = (0, Highlight_1.useHighlighter)();
const row = (react_1.default.createElement(TableBodyRowContainer, { highlighted: highlighted, onMouseDown: (e) => {
config.onMouseDown(e, record, itemIndex);
}, onMouseEnter: (e) => {
config.onMouseEnter(e, record, itemIndex);
}, style: config.onRowStyle?.(record) }, config.columns
.filter((col) => col.visible)
.map((col) => {
const value = renderColumnValue(col, record, highlighted, itemIndex, highlighter);
return (react_1.default.createElement(TableBodyColumnContainer, { key: col.key, multiline: col.wrap, justifyContent: col.align ? col.align : 'left', width: col.width }, value));
})));
if (config.onContextMenu) {
return (react_1.default.createElement(antd_1.Dropdown, { overlay: config.onContextMenu, trigger: ['contextMenu'] }, row));
}
else {
return row;
}
});
function renderColumnValue(col, record, highlighted, itemIndex, highlighter) {
return col.onRender
? col.onRender(record, highlighted, itemIndex)
: DataFormatter_1.DataFormatter.format((0, DataTableManager_1.getValueAtPath)(record, col.key), col.formatters, highlighter);
}
exports.renderColumnValue = renderColumnValue;
//# sourceMappingURL=TableRow.js.map
;