@revolist/revogrid
Version:
Virtual reactive data grid spreadsheet component - RevoGrid.
44 lines (43 loc) • 1.68 kB
JavaScript
/*!
* Built by Revolist OU ❤️
*/
import { h, Build } from "@stencil/core";
import { DRAGGABLE_CLASS, DRAG_ICON_CLASS, getCellDataParsed, } from "../../utils";
import { isRowDragService } from "./column.service";
function renderCell(v) {
var _a;
const els = [];
// #region Custom cell
const template = (_a = v.schemaModel.column) === null || _a === void 0 ? void 0 : _a.cellTemplate;
if (template) {
els.push(template(h, v.schemaModel, v.additionalData));
}
// #endregion
// #region Regular cell
else {
if (!v.schemaModel.column) {
// something is wrong with data
if (Build === null || Build === void 0 ? void 0 : Build.isDev) {
console.error('Investigate column problem.', v.schemaModel);
}
return '';
}
// Row drag
if (v.schemaModel.column.rowDrag &&
isRowDragService(v.schemaModel.column.rowDrag, v.schemaModel)) {
els.push(h("span", { class: DRAGGABLE_CLASS, onMouseDown: originalEvent => {
var _a;
return (_a = v.dragStartCell) === null || _a === void 0 ? void 0 : _a.emit({
originalEvent,
model: v.schemaModel,
});
} }, h("span", { class: DRAG_ICON_CLASS })));
}
els.push(`${getCellDataParsed(v.schemaModel.model, v.schemaModel.column)}`);
}
return els;
}
export const CellRenderer = ({ renderProps, cellProps, }) => {
const render = renderCell.bind(null, renderProps);
return (h("div", Object.assign({}, cellProps, { redraw: render }), render()));
};