UNPKG

wix-style-react

Version:
238 lines (234 loc) • 11.5 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); exports.__esModule = true; exports.dataTableUniDriverFactory = void 0; var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); var _unidriver = require("../../test-utils/utils/unidriver"); var _values = _interopRequireDefault(require("../../utils/operators/values")); function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } // const arbitraryEmptyElement = () => document.createElement('div'); var dataTableUniDriverFactory = base => { // Node is a DOM API which does not exist in jsdom. Using a constant instead: https://developer.mozilla.org/en-US/docs/Web/API/Node var COMMENT_NODE = 8; // When a React component renders null in React 15, a Comment-Element is rendered to the DOM. var isDisplayingNothing = /*#__PURE__*/function () { var _ref = (0, _asyncToGenerator2.default)(function* () { return !(yield base.exists()) || (yield base._prop('nodeType')) === COMMENT_NODE; }); return function isDisplayingNothing() { return _ref.apply(this, arguments); }; }(); /* Since a Comment-Element has no methods like querySelector(), * we replace (if needed) it with an arbitrary Element. * This allows simple implementation of methods like getRows(). */ // const base = () => await isDisplayingNothing() ? arbitraryEmptyElement() : base; var reactBase = (0, _unidriver.ReactBase)(base); var getHeader = () => base.$('thead'); var getHeaderRow = () => getHeader().$('tr'); var hasHeader = () => getHeader().exists(); var _isHeaderVisible = /*#__PURE__*/function () { var _ref2 = (0, _asyncToGenerator2.default)(function* () { var header = getHeader(); return (yield header.exists()) && (yield header._prop('style')).display !== 'none'; }); return function isHeaderVisible() { return _ref2.apply(this, arguments); }; }(); var getRows = () => base.$$('tbody tr[data-table-row="dataTableRow"]'); var getRowsCount = /*#__PURE__*/function () { var _ref3 = (0, _asyncToGenerator2.default)(function* () { return (yield isDisplayingNothing()) ? 0 : getRows().count(); }); return function getRowsCount() { return _ref3.apply(this, arguments); }; }(); var getRow = rowIndex => getRows().get(rowIndex); var _getCell = (rowIndex, cellIndex) => getRow(rowIndex).$$('td').get(cellIndex); var _getRowDetails = index => base.$("tbody tr td[data-hook=\"".concat(index, "_details\"]")); var _getHeaderCell = index => getHeader().$$('th').get(index); var getHeaderCellByDataHook = dataHook => getHeader().$("th[data-hook=\"".concat(dataHook, "\"]")); var getSortableTitle = index => base.$("th [data-hook=\"".concat(index, "_title\"]")); var getTitleInfoIcon = index => base.$("th [data-hook=\"".concat(index, "_info_tooltip\"]")); var getSortableTitleArrowDesc = index => base.$("th [data-hook=\"".concat(index, "_title\"] [data-hook=\"sort_arrow_dec\"]")); return _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(base)), {}, { getRow, getRowsCount, /** @deprecated Should be private */ getRowsWithClassCount: function () { var _getRowsWithClassCount = (0, _asyncToGenerator2.default)(function* (className) { return (yield isDisplayingNothing()) ? 0 : getRows().filter(elem => elem.hasClass(className)).count(); }); function getRowsWithClassCount(_x) { return _getRowsWithClassCount.apply(this, arguments); } return getRowsWithClassCount; }(), /** @deprecated Should be private */ getRowsWithDataHook: function () { var _getRowsWithDataHook = (0, _asyncToGenerator2.default)(function* (dataHookName) { return (yield isDisplayingNothing()) ? [] : base.$$("[data-hook=\"".concat(dataHookName, "\"]")).map(b => b.getNative()); }); function getRowsWithDataHook(_x2) { return _getRowsWithDataHook.apply(this, arguments); } return getRowsWithDataHook; }(), // eslint-disable-line no-restricted-properties /** @deprecated Should be private */ getRowWithDataHook: function () { var _getRowWithDataHook = (0, _asyncToGenerator2.default)(function* (dataHookName) { return (yield isDisplayingNothing()) ? null : base.$("[data-hook=\"".concat(dataHookName, "\"]")).getNative(); }); function getRowWithDataHook(_x3) { return _getRowWithDataHook.apply(this, arguments); } return getRowWithDataHook; }(), // eslint-disable-line no-restricted-properties /** Returns an array representing the text content of the cells in a given row `index`. */ getRowText: function () { var _getRowText = (0, _asyncToGenerator2.default)(function* (index) { return (yield isDisplayingNothing()) ? '' : getRows().get(index).$$('td').map(td => td.text()); }); function getRowText(_x4) { return _getRowText.apply(this, arguments); } return getRowText; }(), /** @deprecated Should be private */ getRowClasses: function () { var _getRowClasses = (0, _asyncToGenerator2.default)(function* (index) { return (0, _values.default)(yield (0, _unidriver.ReactBase)(getRows().get(index))._DEPRECATED_getClassList()); }); function getRowClasses(_x5) { return _getRowClasses.apply(this, arguments); } return getRowClasses; }(), getHeaderRowClasses: function () { var _getHeaderRowClasses = (0, _asyncToGenerator2.default)(function* () { return (0, _values.default)(yield (0, _unidriver.ReactBase)(getHeaderRow())._DEPRECATED_getClassList()); }); function getHeaderRowClasses() { return _getHeaderRowClasses.apply(this, arguments); } return getHeaderRowClasses; }(), getHeaderClasses: function () { var _getHeaderClasses = (0, _asyncToGenerator2.default)(function* () { return (0, _values.default)(yield (0, _unidriver.ReactBase)(getHeader())._DEPRECATED_getClassList()); }); function getHeaderClasses() { return _getHeaderClasses.apply(this, arguments); } return getHeaderClasses; }(), /** * Get header cell element: (columnIndex) => Element * @deprecated Should be private */ getHeaderCell: index => _getHeaderCell(index).getNative(), // eslint-disable-line no-restricted-properties getHeaderCellByDataHook, getHeaderCellStyle: index => _getHeaderCell(index)._prop('style'), getHeaderCellWidth: function () { var _getHeaderCellWidth = (0, _asyncToGenerator2.default)(function* (index) { return (yield _getHeaderCell(index)._prop('style')).width; }); function getHeaderCellWidth(_x6) { return _getHeaderCellWidth.apply(this, arguments); } return getHeaderCellWidth; }(), /** * Get cell element: (rowIndex, columnIndex) => Element * @deprecated Should be private */ getCell: (rowIndex, cellIndex) => _getCell(rowIndex, cellIndex).getNative(), // eslint-disable-line no-restricted-properties getCellStyle: (rowIndex, colIndex) => _getCell(rowIndex, colIndex)._prop('style'), getCellWidth: (rowIndex, colIndex) => _getCell(rowIndex, colIndex)._prop('width'), isRowClickable: function () { var _isRowClickable = (0, _asyncToGenerator2.default)(function* (index) { return !!(yield getRows().get(index).attr('data-clickable')); }); function isRowClickable(_x7) { return _isRowClickable.apply(this, arguments); } return isRowClickable; }(), isRowAnimated: function () { var _isRowAnimated = (0, _asyncToGenerator2.default)(function* (index) { return !!(yield getRows().get(index).attr('data-animated')); }); function isRowAnimated(_x8) { return _isRowAnimated.apply(this, arguments); } return isRowAnimated; }(), isRowHighlighted: function () { var _isRowHighlighted = (0, _asyncToGenerator2.default)(function* (index) { return !!(yield getRows().get(index).attr('data-highlighted')); }); function isRowHighlighted(_x9) { return _isRowHighlighted.apply(this, arguments); } return isRowHighlighted; }(), getTitles: () => getHeader().$$('th').map(th => th.text()), isDisplayingNothing, isDisplayingHeaderOnly: function () { var _isDisplayingHeaderOnly = (0, _asyncToGenerator2.default)(function* () { return (yield hasHeader()) && (yield getRowsCount()) === 0; }); function isDisplayingHeaderOnly() { return _isDisplayingHeaderOnly.apply(this, arguments); } return isDisplayingHeaderOnly; }(), isDisplayingHeader: () => hasHeader(), isHeaderVisible: () => _isHeaderVisible(), hasChildWithId: id => base.$("#".concat(id)).exists(), clickRow: (index, eventData) => getRow(index).click(eventData), clickColumn: (rowIndex, colIndex, eventData) => _getCell(rowIndex, colIndex).click(eventData), mouseEnterRow: (index, eventData) => (0, _unidriver.ReactBase)(getRow(index)).mouseEnter(eventData), mouseLeaveRow: (index, eventData) => (0, _unidriver.ReactBase)(getRow(index)).mouseLeave(eventData), hasRowDetails: index => _getRowDetails(index).exists(), getRowDetailsText: index => _getRowDetails(index).text(), hasSortableTitle: index => getSortableTitle(index).exists(), hasInfoIcon: index => getTitleInfoIcon(index).exists(), hasSortDescending: index => getSortableTitleArrowDesc(index).exists(), clickSort: (index, eventData) => _getHeaderCell(index).click(eventData), // /** @deprecated Should be private */ getRowDetails: index => _getRowDetails(index).getNative(), // eslint-disable-line no-restricted-properties exists: function () { var _exists = (0, _asyncToGenerator2.default)(function* () { return !(yield isDisplayingNothing()); }); function exists() { return _exists.apply(this, arguments); } return exists; }(), isCellMasked: function () { var _isCellMasked = (0, _asyncToGenerator2.default)(function* (rowIndex, colIndex) { return (yield _getCell(rowIndex, colIndex).attr('data-mask')) === 'true'; }); function isCellMasked(_x0, _x1) { return _isCellMasked.apply(this, arguments); } return isCellMasked; }(), getStickyColumnsCount: () => getHeader().$$("th[data-sticky=\"true\"]").count() }); }; exports.dataTableUniDriverFactory = dataTableUniDriverFactory; //# sourceMappingURL=DataTable.uni.driver.js.map