@devexpress/dx-grid-core
Advanced tools
Comparing version 1.0.0-alpha.11 to 1.0.0-alpha.12
/** | ||
* Bundle of @devexpress/dx-grid-core | ||
* Generated: 2017-10-04 | ||
* Version: 1.0.0-alpha.11 | ||
* Generated: 2017-10-19 | ||
* Version: 1.0.0-alpha.12 | ||
* License: https://js.devexpress.com/Licensing | ||
@@ -10,2 +10,178 @@ */ | ||
var rowIdGetter = function rowIdGetter(getRowId, rows) { | ||
if (!getRowId) { | ||
var map = new Map(rows.map(function (row, rowIndex) { | ||
return [row, rowIndex]; | ||
})); | ||
return function (row) { | ||
return map.get(row); | ||
}; | ||
} | ||
return getRowId; | ||
}; | ||
var cellValueGetter = function cellValueGetter(getCellValue, columns) { | ||
if (getCellValue) { | ||
return getCellValue; | ||
} | ||
var useFastAccessor = true; | ||
var map = columns.reduce(function (acc, column) { | ||
if (column.getCellValue) { | ||
useFastAccessor = false; | ||
acc[column.name] = column.getCellValue; | ||
} | ||
return acc; | ||
}, {}); | ||
return useFastAccessor ? function (row, columnName) { | ||
return row[columnName]; | ||
} : function (row, columnName) { | ||
return map[columnName] ? map[columnName](row, columnName) : row[columnName]; | ||
}; | ||
}; | ||
var setColumnSorting = function setColumnSorting(state, _ref) { | ||
var columnName = _ref.columnName, | ||
direction = _ref.direction, | ||
keepOther = _ref.keepOther, | ||
cancel = _ref.cancel, | ||
sortIndex = _ref.sortIndex; | ||
var sorting = state.sorting; | ||
var nextSorting = []; | ||
if (keepOther === true) { | ||
nextSorting = Array.from(sorting).slice(); | ||
} | ||
if (Array.isArray(keepOther)) { | ||
nextSorting = Array.from(sorting).filter(function (columnSorting) { | ||
return keepOther.indexOf(columnSorting.columnName) > -1; | ||
}); | ||
} | ||
var columnSortingIndex = sorting.findIndex(function (columnSorting) { | ||
return columnSorting.columnName === columnName; | ||
}); | ||
var columnSorting = sorting[columnSortingIndex]; | ||
var newColumnSorting = { | ||
columnName: columnName, | ||
direction: direction || (!columnSorting || columnSorting.direction === 'desc' ? 'asc' : 'desc') | ||
}; | ||
if (columnSortingIndex > -1) { | ||
nextSorting.splice(columnSortingIndex, 1); | ||
} | ||
if (!cancel) { | ||
var newIndexFallback = columnSortingIndex > -1 ? columnSortingIndex : nextSorting.length; | ||
var newIndex = sortIndex !== undefined ? sortIndex : newIndexFallback; | ||
nextSorting.splice(newIndex, 0, newColumnSorting); | ||
} | ||
return { | ||
sorting: nextSorting | ||
}; | ||
}; | ||
var getColumnSortingDirection = function getColumnSortingDirection(sorting, columnName) { | ||
var columnSorting = sorting.filter(function (s) { | ||
return s.columnName === columnName; | ||
})[0]; | ||
return columnSorting ? columnSorting.direction : null; | ||
}; | ||
/* eslint-disable no-plusplus, no-param-reassign, no-use-before-define, no-constant-condition */ | ||
var merge = function merge(array, auxiliary, lo, mid, hi, compare) { | ||
var i = lo; | ||
var j = mid + 1; | ||
var k = lo; | ||
while (true) { | ||
var cmp = compare(array[i], array[j]); | ||
if (cmp <= 0) { | ||
auxiliary[k++] = array[i++]; | ||
if (i > mid) { | ||
do { | ||
auxiliary[k++] = array[j++]; | ||
} while (j <= hi); | ||
break; | ||
} | ||
} else { | ||
auxiliary[k++] = array[j++]; | ||
if (j > hi) { | ||
do { | ||
auxiliary[k++] = array[i++]; | ||
} while (i <= mid); | ||
break; | ||
} | ||
} | ||
} | ||
}; | ||
var sortArrayToAuxiliary = function sortArrayToAuxiliary(array, auxiliary, lo, hi, compare) { | ||
if (hi < lo) return; | ||
if (hi === lo) { | ||
auxiliary[lo] = array[lo]; | ||
return; | ||
} | ||
var mid = Math.floor(lo + (hi - lo) / 2); | ||
sortAuxiliaryToArray(array, auxiliary, lo, mid, compare); | ||
sortAuxiliaryToArray(array, auxiliary, mid + 1, hi, compare); | ||
merge(array, auxiliary, lo, mid, hi, compare); | ||
}; | ||
var sortAuxiliaryToArray = function sortAuxiliaryToArray(array, auxiliary, lo, hi, compare) { | ||
if (hi <= lo) return; | ||
var mid = Math.floor(lo + (hi - lo) / 2); | ||
sortArrayToAuxiliary(array, auxiliary, lo, mid, compare); | ||
sortArrayToAuxiliary(array, auxiliary, mid + 1, hi, compare); | ||
merge(auxiliary, array, lo, mid, hi, compare); | ||
}; | ||
var mergeSort = (function (array) { | ||
var compare = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (a, b) { | ||
if (a < b) return -1; | ||
if (a > b) return 1; | ||
return 0; | ||
}; | ||
var result = array.slice(); | ||
var auxiliary = array.slice(); | ||
sortAuxiliaryToArray(result, auxiliary, 0, result.length - 1, compare); | ||
return result; | ||
}); | ||
var defaultCompare = function defaultCompare(a, b) { | ||
if (a < b) return -1; | ||
if (a > b) return 1; | ||
return 0; | ||
}; | ||
var sortedRows = function sortedRows(rows, sorting, getCellValue, getColumnCompare) { | ||
if (!sorting.length) return rows; | ||
var compare = Array.from(sorting).reverse().reduce(function (prevCompare, columnSorting) { | ||
var columnName = columnSorting.columnName; | ||
var inverse = columnSorting.direction === 'desc'; | ||
var columnCompare = getColumnCompare && getColumnCompare(columnName) || defaultCompare; | ||
return function (aRow, bRow) { | ||
var a = getCellValue(aRow, columnName); | ||
var b = getCellValue(bRow, columnName); | ||
var result = columnCompare(a, b); | ||
if (result !== 0) { | ||
return inverse ? -result : result; | ||
} | ||
return prevCompare(aRow, bRow); | ||
}; | ||
}, function () { | ||
return 0; | ||
}); | ||
return mergeSort(Array.from(rows), compare); | ||
}; | ||
var asyncGenerator = function () { | ||
@@ -255,144 +431,2 @@ function AwaitValue(value) { | ||
var setColumnSorting = function setColumnSorting(sorting, _ref) { | ||
var columnName = _ref.columnName, | ||
direction = _ref.direction, | ||
keepOther = _ref.keepOther, | ||
cancel = _ref.cancel, | ||
scope = _ref.scope; | ||
var sortingIndex = sorting.findIndex(function (s) { | ||
return s.columnName === columnName; | ||
}); | ||
var columnSorting = sorting[sortingIndex]; | ||
var nextSorting = keepOther ? sorting.slice() : []; | ||
if (scope) { | ||
nextSorting = [].concat(toConsumableArray(nextSorting), toConsumableArray(sorting.filter(function (sort) { | ||
return scope.indexOf(sort.columnName) === -1 && sort.columnName !== columnName; | ||
}))); | ||
} | ||
if (columnSorting) { | ||
var updatedSorting = _extends({}, columnSorting, { | ||
direction: columnSorting.direction === 'asc' ? 'desc' : 'asc' | ||
}); | ||
if (keepOther && cancel) { | ||
nextSorting.splice(sortingIndex, 1); | ||
} else if (keepOther && !cancel) { | ||
nextSorting.splice(sortingIndex, 1, updatedSorting); | ||
} else if (!keepOther && cancel) { | ||
nextSorting.length = 0; | ||
} else { | ||
nextSorting.push(updatedSorting); | ||
} | ||
} else if (!cancel) { | ||
nextSorting.push({ | ||
columnName: columnName, | ||
direction: direction || 'asc' | ||
}); | ||
} | ||
return nextSorting; | ||
}; | ||
var getColumnSortingDirection = function getColumnSortingDirection(sorting, columnName) { | ||
var columnSorting = sorting.filter(function (s) { | ||
return s.columnName === columnName; | ||
})[0]; | ||
return columnSorting ? columnSorting.direction : null; | ||
}; | ||
/* eslint-disable no-plusplus, no-param-reassign, no-use-before-define, no-constant-condition */ | ||
var merge = function merge(array, auxiliary, lo, mid, hi, compare) { | ||
var i = lo; | ||
var j = mid + 1; | ||
var k = lo; | ||
while (true) { | ||
var cmp = compare(array[i], array[j]); | ||
if (cmp <= 0) { | ||
auxiliary[k++] = array[i++]; | ||
if (i > mid) { | ||
do { | ||
auxiliary[k++] = array[j++]; | ||
} while (j <= hi); | ||
break; | ||
} | ||
} else { | ||
auxiliary[k++] = array[j++]; | ||
if (j > hi) { | ||
do { | ||
auxiliary[k++] = array[i++]; | ||
} while (i <= mid); | ||
break; | ||
} | ||
} | ||
} | ||
}; | ||
var sortArrayToAuxiliary = function sortArrayToAuxiliary(array, auxiliary, lo, hi, compare) { | ||
if (hi < lo) return; | ||
if (hi === lo) { | ||
auxiliary[lo] = array[lo]; | ||
return; | ||
} | ||
var mid = Math.floor(lo + (hi - lo) / 2); | ||
sortAuxiliaryToArray(array, auxiliary, lo, mid, compare); | ||
sortAuxiliaryToArray(array, auxiliary, mid + 1, hi, compare); | ||
merge(array, auxiliary, lo, mid, hi, compare); | ||
}; | ||
var sortAuxiliaryToArray = function sortAuxiliaryToArray(array, auxiliary, lo, hi, compare) { | ||
if (hi <= lo) return; | ||
var mid = Math.floor(lo + (hi - lo) / 2); | ||
sortArrayToAuxiliary(array, auxiliary, lo, mid, compare); | ||
sortArrayToAuxiliary(array, auxiliary, mid + 1, hi, compare); | ||
merge(auxiliary, array, lo, mid, hi, compare); | ||
}; | ||
var mergeSort = (function (array) { | ||
var compare = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (a, b) { | ||
if (a < b) return -1; | ||
if (a > b) return 1; | ||
return 0; | ||
}; | ||
var result = array.slice(); | ||
var auxiliary = array.slice(); | ||
sortAuxiliaryToArray(result, auxiliary, 0, result.length - 1, compare); | ||
return result; | ||
}); | ||
var defaultCompare = function defaultCompare(a, b) { | ||
if (a < b) return -1; | ||
if (a > b) return 1; | ||
return 0; | ||
}; | ||
var sortedRows = function sortedRows(rows, sorting, getCellValue, getColumnCompare) { | ||
if (!sorting.length) return rows; | ||
var compare = Array.from(sorting).reverse().reduce(function (prevCompare, columnSorting) { | ||
var columnName = columnSorting.columnName; | ||
var inverse = columnSorting.direction === 'desc'; | ||
var columnCompare = getColumnCompare && getColumnCompare(columnName) || defaultCompare; | ||
return function (aRow, bRow) { | ||
var a = getCellValue(aRow, columnName); | ||
var b = getCellValue(bRow, columnName); | ||
var result = columnCompare(a, b); | ||
if (result !== 0) { | ||
return inverse ? -result : result; | ||
} | ||
return prevCompare(aRow, bRow); | ||
}; | ||
}, function () { | ||
return 0; | ||
}); | ||
return mergeSort(Array.from(rows), compare); | ||
}; | ||
var setColumnFilter = function setColumnFilter(filters, _ref) { | ||
@@ -448,4 +482,4 @@ var columnName = _ref.columnName, | ||
return rows.filter(function (row) { | ||
return filters.reduce(function (acc, filter) { | ||
var compoundPredicate = filters.reduce(function (prevCompare, filter) { | ||
return function (row) { | ||
var columnName = filter.columnName, | ||
@@ -456,5 +490,9 @@ filterConfig = objectWithoutProperties(filter, ["columnName"]); | ||
return acc && predicate(getCellValue(row, columnName), filterConfig, row); | ||
}, true); | ||
return prevCompare(row) && predicate(getCellValue(row, columnName), filterConfig, row); | ||
}; | ||
}, function () { | ||
return true; | ||
}); | ||
return rows.filter(compoundPredicate); | ||
}; | ||
@@ -464,2 +502,113 @@ | ||
var groupByColumn = function groupByColumn(state, _ref) { | ||
var columnName = _ref.columnName, | ||
groupIndex = _ref.groupIndex; | ||
var grouping = Array.from(state.grouping); | ||
var groupingIndex = grouping.findIndex(function (g) { | ||
return g.columnName === columnName; | ||
}); | ||
var targetIndex = groupIndex; | ||
if (groupingIndex > -1) { | ||
grouping.splice(groupingIndex, 1); | ||
} else if (groupIndex === undefined) { | ||
targetIndex = grouping.length; | ||
} | ||
if (targetIndex > -1) { | ||
grouping.splice(targetIndex, 0, { | ||
columnName: columnName | ||
}); | ||
} | ||
var ungroupedColumnIndex = state.grouping.findIndex(function (group, index) { | ||
return !grouping[index] || group.columnName !== grouping[index].columnName; | ||
}); | ||
if (ungroupedColumnIndex === -1) { | ||
return { | ||
grouping: grouping | ||
}; | ||
} | ||
var filteredExpandedGroups = state.expandedGroups.filter(function (group) { | ||
return group.split(GROUP_KEY_SEPARATOR).length <= ungroupedColumnIndex; | ||
}); | ||
if (filteredExpandedGroups.length === state.expandedGroups.length) { | ||
return { | ||
grouping: grouping | ||
}; | ||
} | ||
return { | ||
grouping: grouping, | ||
expandedGroups: filteredExpandedGroups | ||
}; | ||
}; | ||
var toggleExpandedGroups = function toggleExpandedGroups(state, _ref2) { | ||
var groupKey = _ref2.groupKey; | ||
var expandedGroups = Array.from(state.expandedGroups); | ||
var groupKeyIndex = expandedGroups.indexOf(groupKey); | ||
if (groupKeyIndex > -1) { | ||
expandedGroups.splice(groupKeyIndex, 1); | ||
} else { | ||
expandedGroups.push(groupKey); | ||
} | ||
return { | ||
expandedGroups: expandedGroups | ||
}; | ||
}; | ||
var draftGroupingChange = function draftGroupingChange(state, _ref3) { | ||
var columnName = _ref3.columnName, | ||
groupIndex = _ref3.groupIndex; | ||
return { groupingChange: { columnName: columnName, groupIndex: groupIndex } }; | ||
}; | ||
var cancelGroupingChange = function cancelGroupingChange() { | ||
return { groupingChange: null }; | ||
}; | ||
var draftGrouping = function draftGrouping(grouping, groupingChange) { | ||
if (!groupingChange) return grouping; | ||
var columnName = groupingChange.columnName, | ||
groupIndex = groupingChange.groupIndex; | ||
var result = Array.from(grouping); | ||
if (groupIndex !== -1) { | ||
result = result.filter(function (g) { | ||
return g.columnName !== columnName; | ||
}); | ||
result.splice(groupIndex, 0, { | ||
columnName: columnName, | ||
draft: true, | ||
mode: grouping.length > result.length ? 'reorder' : 'add' | ||
}); | ||
} else { | ||
result = result.map(function (g) { | ||
return g.columnName === columnName ? { columnName: columnName, draft: true, mode: 'remove' } : g; | ||
}); | ||
} | ||
return result; | ||
}; | ||
var GRID_GROUP_TYPE = 'group'; | ||
var GRID_GROUP_CHECK = Symbol(GRID_GROUP_TYPE + '_check'); | ||
var GRID_GROUP_LEVEL_KEY = Symbol(GRID_GROUP_TYPE + '_levelKey'); | ||
var groupRowChecker = function groupRowChecker(row) { | ||
return row[GRID_GROUP_CHECK]; | ||
}; | ||
var groupRowLevelKeyGetter = function groupRowLevelKeyGetter(row) { | ||
return row[GRID_GROUP_LEVEL_KEY]; | ||
}; | ||
var defaultColumnIdentity = function defaultColumnIdentity(value) { | ||
@@ -475,18 +624,11 @@ return { | ||
var columnGrouping = grouping[0]; | ||
var columnName = columnGrouping.columnName; | ||
var columnName = grouping[0].columnName; | ||
var groupIdentity = getColumnIdentity && getColumnIdentity(columnName) || defaultColumnIdentity; | ||
var groups = rows.reduce(function (acc, row) { | ||
var cellValue = getCellValue(row, columnName); | ||
var group = groupIdentity(cellValue, row); | ||
var _groupIdentity = groupIdentity(getCellValue(row, columnName), row), | ||
key = _groupIdentity.key, | ||
_groupIdentity$value = _groupIdentity.value, | ||
value = _groupIdentity$value === undefined ? key : _groupIdentity$value; | ||
var key = group.key; | ||
var value = group.value; | ||
if (!value) { | ||
value = key; | ||
} | ||
var sameKeyItems = acc.get(key); | ||
@@ -524,2 +666,4 @@ | ||
return rows.reduce(function (acc, _ref3) { | ||
var _ref4; | ||
var value = _ref3.value, | ||
@@ -532,9 +676,3 @@ groupKey = _ref3.key, | ||
var expanded = expandedGroups.has(key); | ||
return [].concat(toConsumableArray(acc), [{ | ||
_headerKey: 'groupRow_' + groupedBy, | ||
type: 'groupRow', | ||
groupedBy: groupedBy, | ||
key: key, | ||
value: value | ||
}], toConsumableArray(expanded ? expandedGroupRows(items, nestedGrouping, expandedGroups, '' + key + GROUP_KEY_SEPARATOR) : [])); | ||
return [].concat(toConsumableArray(acc), [(_ref4 = {}, defineProperty(_ref4, GRID_GROUP_CHECK, true), defineProperty(_ref4, GRID_GROUP_LEVEL_KEY, GRID_GROUP_TYPE + '_' + groupedBy), defineProperty(_ref4, 'groupedBy', groupedBy), defineProperty(_ref4, 'key', key), defineProperty(_ref4, 'value', value), _ref4)], toConsumableArray(expanded ? expandedGroupRows(items, nestedGrouping, expandedGroups, '' + key + GROUP_KEY_SEPARATOR) : [])); | ||
}, []); | ||
@@ -558,102 +696,2 @@ }; | ||
var getFirstChangedGropingIndex = function getFirstChangedGropingIndex(prevGrouping, nextGrouping) { | ||
if (prevGrouping.length <= nextGrouping.length) { | ||
return -1; | ||
} | ||
return prevGrouping.findIndex(function (group, index) { | ||
return !nextGrouping[index] || group.columnName !== nextGrouping[index].columnName; | ||
}); | ||
}; | ||
var groupByColumn = function groupByColumn(prevGrouping, _ref) { | ||
var columnName = _ref.columnName, | ||
groupIndex = _ref.groupIndex; | ||
var grouping = Array.from(prevGrouping); | ||
var index = grouping.findIndex(function (g) { | ||
return g.columnName === columnName; | ||
}); | ||
var targetIndex = groupIndex; | ||
if (index > -1) { | ||
grouping.splice(index, 1); | ||
} else if (groupIndex === undefined) { | ||
targetIndex = grouping.length; | ||
} | ||
if (targetIndex > -1) { | ||
grouping.splice(targetIndex, 0, { | ||
columnName: columnName | ||
}); | ||
} | ||
return grouping; | ||
}; | ||
var draftGroupingChange = function draftGroupingChange(prevGroupingChange, _ref2) { | ||
var columnName = _ref2.columnName, | ||
groupIndex = _ref2.groupIndex; | ||
return { columnName: columnName, groupIndex: groupIndex }; | ||
}; | ||
var cancelGroupingChange = function cancelGroupingChange() { | ||
return null; | ||
}; | ||
var removeOutdatedExpandedGroups = function removeOutdatedExpandedGroups(prevExpandedGroups, _ref3) { | ||
var prevGrouping = _ref3.prevGrouping, | ||
grouping = _ref3.grouping; | ||
var ungroupedColumnIndex = getFirstChangedGropingIndex(prevGrouping, grouping); | ||
if (ungroupedColumnIndex === -1) { | ||
return prevExpandedGroups; | ||
} | ||
return prevExpandedGroups.filter(function (group) { | ||
return group.split(GROUP_KEY_SEPARATOR).length <= ungroupedColumnIndex; | ||
}); | ||
}; | ||
var toggleExpandedGroups = function toggleExpandedGroups(prevExpandedGroups, _ref4) { | ||
var groupKey = _ref4.groupKey; | ||
var expandedGroups = Array.from(prevExpandedGroups); | ||
var groupKeyIndex = expandedGroups.indexOf(groupKey); | ||
if (groupKeyIndex > -1) { | ||
expandedGroups.splice(groupKeyIndex, 1); | ||
} else { | ||
expandedGroups.push(groupKey); | ||
} | ||
return expandedGroups; | ||
}; | ||
var draftGrouping = function draftGrouping(grouping, groupingChange) { | ||
if (!groupingChange) return grouping; | ||
var columnName = groupingChange.columnName, | ||
groupIndex = groupingChange.groupIndex; | ||
var result = Array.from(grouping); | ||
if (groupIndex !== -1) { | ||
result = result.filter(function (g) { | ||
return g.columnName !== columnName; | ||
}); | ||
result.splice(groupIndex, 0, { | ||
columnName: columnName, | ||
draft: true, | ||
mode: grouping.length > result.length ? 'reorder' : 'add' | ||
}); | ||
} else { | ||
result = result.map(function (g) { | ||
return g.columnName === columnName ? { columnName: columnName, draft: true, mode: 'remove' } : g; | ||
}); | ||
} | ||
return result; | ||
}; | ||
var setCurrentPage = function setCurrentPage(prevPage, page) { | ||
@@ -666,16 +704,14 @@ return page; | ||
var PAGE_HEADERS_OVERFLOW_ERROR = ['The count of title rows exceeds the page size. Consider increasing the page size.', 'Typically, title rows are group headers.'].join('\n'); | ||
var PAGE_HEADERS_OVERFLOW_ERROR = 'Max row level exceeds the page size. Consider increasing the page size.'; | ||
var paginate = function paginate(rows, pageSize, page) { | ||
var paginatedRows = function paginatedRows(rows, pageSize, page) { | ||
return pageSize ? rows.slice(pageSize * page, pageSize * (page + 1)) : rows; | ||
}; | ||
var ensurePageHeaders = function ensurePageHeaders(rows, pageSize) { | ||
if (!pageSize) { | ||
return rows; | ||
} | ||
var rowsWithPageHeaders = function rowsWithPageHeaders(rows, pageSize, getRowLevelKey) { | ||
if (!pageSize) return rows; | ||
var result = rows.slice(); | ||
var headers = []; | ||
var headerRows = []; | ||
var currentIndex = 0; | ||
@@ -685,13 +721,13 @@ | ||
var row = result[currentIndex]; | ||
var headerKey = row._headerKey; | ||
if (headerKey) { | ||
var headerIndex = headers.findIndex(function (header) { | ||
return header._headerKey === headerKey; | ||
var header = getRowLevelKey ? getRowLevelKey(row) : row._headerKey; | ||
if (header) { | ||
var headerIndex = headerRows.findIndex(function (headerRow) { | ||
return (getRowLevelKey ? getRowLevelKey(headerRow) : row._headerKey) === header; | ||
}); | ||
if (headerIndex === -1) { | ||
headers = [].concat(toConsumableArray(headers), [row]); | ||
headerRows = [].concat(toConsumableArray(headerRows), [row]); | ||
} else { | ||
headers = [].concat(toConsumableArray(headers.slice(0, headerIndex)), [row]); | ||
headerRows = [].concat(toConsumableArray(headerRows.slice(0, headerIndex)), [row]); | ||
} | ||
if (headers.length >= pageSize) { | ||
if (headerRows.length >= pageSize) { | ||
throw new Error(PAGE_HEADERS_OVERFLOW_ERROR); | ||
@@ -701,4 +737,4 @@ } | ||
var indexInPage = currentIndex % pageSize; | ||
if (indexInPage < headers.length && row !== headers[indexInPage]) { | ||
result = [].concat(toConsumableArray(result.slice(0, currentIndex)), [headers[indexInPage]], toConsumableArray(result.slice(currentIndex))); | ||
if (indexInPage < headerRows.length && row !== headerRows[indexInPage]) { | ||
result = [].concat(toConsumableArray(result.slice(0, currentIndex)), [headerRows[indexInPage]], toConsumableArray(result.slice(currentIndex))); | ||
} | ||
@@ -792,5 +828,5 @@ currentIndex += 1; | ||
var getAvailableToSelect = function getAvailableToSelect(rows, getRowId) { | ||
var getAvailableToSelect = function getAvailableToSelect(rows, getRowId, isGroupRow) { | ||
return rows.filter(function (row) { | ||
return !row.type; | ||
return (!isGroupRow || !isGroupRow(row)) && !row.type; | ||
}).map(function (row) { | ||
@@ -1106,5 +1142,7 @@ return getRowId(row); | ||
var tableRowsWithGrouping = function tableRowsWithGrouping(tableRows) { | ||
var tableRowsWithGrouping = function tableRowsWithGrouping(tableRows, isGroupRow) { | ||
return tableRows.map(function (tableRow) { | ||
if (tableRow.type !== TABLE_DATA_TYPE || tableRow.row.type !== 'groupRow') return tableRow; | ||
if (tableRow.type !== TABLE_DATA_TYPE || !isGroupRow(tableRow.row) && tableRow.row.type !== 'groupRow') { | ||
return tableRow; | ||
} | ||
return _extends({}, tableRow, { | ||
@@ -1200,10 +1238,2 @@ key: TABLE_GROUP_TYPE + '_' + tableRow.row.key, | ||
var tableRowsWithSelection = function tableRowsWithSelection(tableRows, selection) { | ||
var selectionSet = new Set(selection); | ||
return tableRows.map(function (tableRow) { | ||
if (tableRow.type !== TABLE_DATA_TYPE || !selectionSet.has(tableRow.rowId)) return tableRow; | ||
return _extends({ selected: true }, tableRow); | ||
}); | ||
}; | ||
var isNoDataTableRow = function isNoDataTableRow(tableRow) { | ||
@@ -1237,6 +1267,6 @@ return tableRow.type === TABLE_NODATA_TYPE; | ||
return { | ||
key: TABLE_DATA_TYPE + '_' + rowId, | ||
row: row, | ||
rowId: rowId, | ||
type: TABLE_DATA_TYPE, | ||
rowId: rowId, | ||
row: row | ||
key: TABLE_DATA_TYPE + '_' + rowId | ||
}; | ||
@@ -1246,2 +1276,20 @@ }); | ||
var visibleTableColumns = function visibleTableColumns(tableColumns, hiddenColumns) { | ||
return tableColumns.filter(function (tableColumn) { | ||
return hiddenColumns.indexOf(tableColumn.column.name) === -1; | ||
}); | ||
}; | ||
var columnChooserItems = function columnChooserItems(columns, hiddenColumns) { | ||
return columns.map(function (column) { | ||
return { column: column, hidden: hiddenColumns.indexOf(column.name) !== -1 }; | ||
}); | ||
}; | ||
var toggleColumn = function toggleColumn(hiddenColumns, columnName) { | ||
return hiddenColumns.indexOf(columnName) === -1 ? [].concat(toConsumableArray(hiddenColumns), [columnName]) : hiddenColumns.filter(function (hiddenColumn) { | ||
return hiddenColumn !== columnName; | ||
}); | ||
}; | ||
var getTargetColumnGeometries = function getTargetColumnGeometries(columnGeometries, sourceIndex) { | ||
@@ -1428,3 +1476,3 @@ var sourceWidth = columnGeometries[sourceIndex].right - columnGeometries[sourceIndex].left; | ||
export { getTableRowColumnsWithColSpan, getTableColumnGeometries, getTableTargetColumnIndex, getAnimations, filterActiveAnimations, evalAnimations, getGroupCellTargetIndex, setColumnSorting, getColumnSortingDirection, sortedRows, setColumnFilter, getColumnFilterConfig, filteredRows, groupedRows, expandedGroupRows, groupingPanelItems, groupByColumn, draftGroupingChange, cancelGroupingChange, removeOutdatedExpandedGroups, toggleExpandedGroups, getFirstChangedGropingIndex, draftGrouping, setCurrentPage, setPageSize, paginate, ensurePageHeaders, pageCount, rowCount, firstRowOnPage, lastRowOnPage, setRowsSelection, getAvailableToSelect, getAvailableSelection, startEditRows, stopEditRows, addRow, changeAddedRow, cancelAddedRows, changeRow, cancelChanges, deleteRows, cancelDeletedRows, changedRowsByIds, addedRowsByIds, computedCreateRowChange, getRowChange, setColumnOrder, orderedColumns, tableColumnsWithWidths, changeTableColumnWidths, changeDraftTableColumnWidths, TABLE_EDIT_COMMAND_TYPE, isHeadingEditCommandsTableCell, isEditCommandsTableCell, tableColumnsWithEditing, TABLE_ADDED_TYPE, TABLE_EDIT_TYPE, isEditTableCell, isAddedTableRow, isEditTableRow, tableRowsWithEditing, TABLE_FILTER_TYPE, isFilterTableCell, isFilterTableRow, tableHeaderRowsWithFilter, TABLE_GROUP_TYPE, isGroupTableCell, isGroupIndentTableCell, isGroupTableRow, tableColumnsWithGrouping, tableRowsWithGrouping, TABLE_HEADING_TYPE, isHeadingTableCell, isHeadingTableRow, tableRowsWithHeading, TABLE_DETAIL_TYPE, isDetailRowExpanded, isDetailToggleTableCell, isDetailTableRow, setDetailRowExpanded, tableRowsWithExpandedDetail, tableColumnsWithDetail, TABLE_SELECT_TYPE, isSelectTableCell, isSelectAllTableCell, tableColumnsWithSelection, tableRowsWithSelection, TABLE_DATA_TYPE, TABLE_NODATA_TYPE, isNoDataTableRow, isDataTableCell, isHeaderStubTableCell, isDataTableRow, tableColumnsWithDataRows, tableRowsWithDataRows }; | ||
export { getTableRowColumnsWithColSpan, getTableColumnGeometries, getTableTargetColumnIndex, getAnimations, filterActiveAnimations, evalAnimations, getGroupCellTargetIndex, rowIdGetter, cellValueGetter, setColumnSorting, getColumnSortingDirection, sortedRows, setColumnFilter, getColumnFilterConfig, filteredRows, groupByColumn, toggleExpandedGroups, draftGroupingChange, cancelGroupingChange, draftGrouping, groupRowChecker, groupRowLevelKeyGetter, groupedRows, expandedGroupRows, groupingPanelItems, setCurrentPage, setPageSize, paginatedRows, rowsWithPageHeaders, pageCount, rowCount, firstRowOnPage, lastRowOnPage, setRowsSelection, getAvailableToSelect, getAvailableSelection, startEditRows, stopEditRows, addRow, changeAddedRow, cancelAddedRows, changeRow, cancelChanges, deleteRows, cancelDeletedRows, changedRowsByIds, addedRowsByIds, computedCreateRowChange, getRowChange, setColumnOrder, orderedColumns, tableColumnsWithWidths, changeTableColumnWidths, changeDraftTableColumnWidths, TABLE_EDIT_COMMAND_TYPE, isHeadingEditCommandsTableCell, isEditCommandsTableCell, tableColumnsWithEditing, TABLE_ADDED_TYPE, TABLE_EDIT_TYPE, isEditTableCell, isAddedTableRow, isEditTableRow, tableRowsWithEditing, TABLE_FILTER_TYPE, isFilterTableCell, isFilterTableRow, tableHeaderRowsWithFilter, TABLE_GROUP_TYPE, isGroupTableCell, isGroupIndentTableCell, isGroupTableRow, tableColumnsWithGrouping, tableRowsWithGrouping, TABLE_HEADING_TYPE, isHeadingTableCell, isHeadingTableRow, tableRowsWithHeading, TABLE_DETAIL_TYPE, isDetailRowExpanded, isDetailToggleTableCell, isDetailTableRow, setDetailRowExpanded, tableRowsWithExpandedDetail, tableColumnsWithDetail, TABLE_SELECT_TYPE, isSelectTableCell, isSelectAllTableCell, tableColumnsWithSelection, TABLE_DATA_TYPE, TABLE_NODATA_TYPE, isNoDataTableRow, isDataTableCell, isHeaderStubTableCell, isDataTableRow, tableColumnsWithDataRows, tableRowsWithDataRows, visibleTableColumns, columnChooserItems, toggleColumn }; | ||
//# sourceMappingURL=dx-grid-core.es.js.map |
/** | ||
* Bundle of @devexpress/dx-grid-core | ||
* Generated: 2017-10-04 | ||
* Version: 1.0.0-alpha.11 | ||
* Generated: 2017-10-19 | ||
* Version: 1.0.0-alpha.12 | ||
* License: https://js.devexpress.com/Licensing | ||
@@ -14,2 +14,178 @@ */ | ||
var rowIdGetter = function rowIdGetter(getRowId, rows) { | ||
if (!getRowId) { | ||
var map = new Map(rows.map(function (row, rowIndex) { | ||
return [row, rowIndex]; | ||
})); | ||
return function (row) { | ||
return map.get(row); | ||
}; | ||
} | ||
return getRowId; | ||
}; | ||
var cellValueGetter = function cellValueGetter(getCellValue, columns) { | ||
if (getCellValue) { | ||
return getCellValue; | ||
} | ||
var useFastAccessor = true; | ||
var map = columns.reduce(function (acc, column) { | ||
if (column.getCellValue) { | ||
useFastAccessor = false; | ||
acc[column.name] = column.getCellValue; | ||
} | ||
return acc; | ||
}, {}); | ||
return useFastAccessor ? function (row, columnName) { | ||
return row[columnName]; | ||
} : function (row, columnName) { | ||
return map[columnName] ? map[columnName](row, columnName) : row[columnName]; | ||
}; | ||
}; | ||
var setColumnSorting = function setColumnSorting(state, _ref) { | ||
var columnName = _ref.columnName, | ||
direction = _ref.direction, | ||
keepOther = _ref.keepOther, | ||
cancel = _ref.cancel, | ||
sortIndex = _ref.sortIndex; | ||
var sorting = state.sorting; | ||
var nextSorting = []; | ||
if (keepOther === true) { | ||
nextSorting = Array.from(sorting).slice(); | ||
} | ||
if (Array.isArray(keepOther)) { | ||
nextSorting = Array.from(sorting).filter(function (columnSorting) { | ||
return keepOther.indexOf(columnSorting.columnName) > -1; | ||
}); | ||
} | ||
var columnSortingIndex = sorting.findIndex(function (columnSorting) { | ||
return columnSorting.columnName === columnName; | ||
}); | ||
var columnSorting = sorting[columnSortingIndex]; | ||
var newColumnSorting = { | ||
columnName: columnName, | ||
direction: direction || (!columnSorting || columnSorting.direction === 'desc' ? 'asc' : 'desc') | ||
}; | ||
if (columnSortingIndex > -1) { | ||
nextSorting.splice(columnSortingIndex, 1); | ||
} | ||
if (!cancel) { | ||
var newIndexFallback = columnSortingIndex > -1 ? columnSortingIndex : nextSorting.length; | ||
var newIndex = sortIndex !== undefined ? sortIndex : newIndexFallback; | ||
nextSorting.splice(newIndex, 0, newColumnSorting); | ||
} | ||
return { | ||
sorting: nextSorting | ||
}; | ||
}; | ||
var getColumnSortingDirection = function getColumnSortingDirection(sorting, columnName) { | ||
var columnSorting = sorting.filter(function (s) { | ||
return s.columnName === columnName; | ||
})[0]; | ||
return columnSorting ? columnSorting.direction : null; | ||
}; | ||
/* eslint-disable no-plusplus, no-param-reassign, no-use-before-define, no-constant-condition */ | ||
var merge = function merge(array, auxiliary, lo, mid, hi, compare) { | ||
var i = lo; | ||
var j = mid + 1; | ||
var k = lo; | ||
while (true) { | ||
var cmp = compare(array[i], array[j]); | ||
if (cmp <= 0) { | ||
auxiliary[k++] = array[i++]; | ||
if (i > mid) { | ||
do { | ||
auxiliary[k++] = array[j++]; | ||
} while (j <= hi); | ||
break; | ||
} | ||
} else { | ||
auxiliary[k++] = array[j++]; | ||
if (j > hi) { | ||
do { | ||
auxiliary[k++] = array[i++]; | ||
} while (i <= mid); | ||
break; | ||
} | ||
} | ||
} | ||
}; | ||
var sortArrayToAuxiliary = function sortArrayToAuxiliary(array, auxiliary, lo, hi, compare) { | ||
if (hi < lo) return; | ||
if (hi === lo) { | ||
auxiliary[lo] = array[lo]; | ||
return; | ||
} | ||
var mid = Math.floor(lo + (hi - lo) / 2); | ||
sortAuxiliaryToArray(array, auxiliary, lo, mid, compare); | ||
sortAuxiliaryToArray(array, auxiliary, mid + 1, hi, compare); | ||
merge(array, auxiliary, lo, mid, hi, compare); | ||
}; | ||
var sortAuxiliaryToArray = function sortAuxiliaryToArray(array, auxiliary, lo, hi, compare) { | ||
if (hi <= lo) return; | ||
var mid = Math.floor(lo + (hi - lo) / 2); | ||
sortArrayToAuxiliary(array, auxiliary, lo, mid, compare); | ||
sortArrayToAuxiliary(array, auxiliary, mid + 1, hi, compare); | ||
merge(auxiliary, array, lo, mid, hi, compare); | ||
}; | ||
var mergeSort = (function (array) { | ||
var compare = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (a, b) { | ||
if (a < b) return -1; | ||
if (a > b) return 1; | ||
return 0; | ||
}; | ||
var result = array.slice(); | ||
var auxiliary = array.slice(); | ||
sortAuxiliaryToArray(result, auxiliary, 0, result.length - 1, compare); | ||
return result; | ||
}); | ||
var defaultCompare = function defaultCompare(a, b) { | ||
if (a < b) return -1; | ||
if (a > b) return 1; | ||
return 0; | ||
}; | ||
var sortedRows = function sortedRows(rows, sorting, getCellValue, getColumnCompare) { | ||
if (!sorting.length) return rows; | ||
var compare = Array.from(sorting).reverse().reduce(function (prevCompare, columnSorting) { | ||
var columnName = columnSorting.columnName; | ||
var inverse = columnSorting.direction === 'desc'; | ||
var columnCompare = getColumnCompare && getColumnCompare(columnName) || defaultCompare; | ||
return function (aRow, bRow) { | ||
var a = getCellValue(aRow, columnName); | ||
var b = getCellValue(bRow, columnName); | ||
var result = columnCompare(a, b); | ||
if (result !== 0) { | ||
return inverse ? -result : result; | ||
} | ||
return prevCompare(aRow, bRow); | ||
}; | ||
}, function () { | ||
return 0; | ||
}); | ||
return mergeSort(Array.from(rows), compare); | ||
}; | ||
var asyncGenerator = function () { | ||
@@ -259,144 +435,2 @@ function AwaitValue(value) { | ||
var setColumnSorting = function setColumnSorting(sorting, _ref) { | ||
var columnName = _ref.columnName, | ||
direction = _ref.direction, | ||
keepOther = _ref.keepOther, | ||
cancel = _ref.cancel, | ||
scope = _ref.scope; | ||
var sortingIndex = sorting.findIndex(function (s) { | ||
return s.columnName === columnName; | ||
}); | ||
var columnSorting = sorting[sortingIndex]; | ||
var nextSorting = keepOther ? sorting.slice() : []; | ||
if (scope) { | ||
nextSorting = [].concat(toConsumableArray(nextSorting), toConsumableArray(sorting.filter(function (sort) { | ||
return scope.indexOf(sort.columnName) === -1 && sort.columnName !== columnName; | ||
}))); | ||
} | ||
if (columnSorting) { | ||
var updatedSorting = _extends({}, columnSorting, { | ||
direction: columnSorting.direction === 'asc' ? 'desc' : 'asc' | ||
}); | ||
if (keepOther && cancel) { | ||
nextSorting.splice(sortingIndex, 1); | ||
} else if (keepOther && !cancel) { | ||
nextSorting.splice(sortingIndex, 1, updatedSorting); | ||
} else if (!keepOther && cancel) { | ||
nextSorting.length = 0; | ||
} else { | ||
nextSorting.push(updatedSorting); | ||
} | ||
} else if (!cancel) { | ||
nextSorting.push({ | ||
columnName: columnName, | ||
direction: direction || 'asc' | ||
}); | ||
} | ||
return nextSorting; | ||
}; | ||
var getColumnSortingDirection = function getColumnSortingDirection(sorting, columnName) { | ||
var columnSorting = sorting.filter(function (s) { | ||
return s.columnName === columnName; | ||
})[0]; | ||
return columnSorting ? columnSorting.direction : null; | ||
}; | ||
/* eslint-disable no-plusplus, no-param-reassign, no-use-before-define, no-constant-condition */ | ||
var merge = function merge(array, auxiliary, lo, mid, hi, compare) { | ||
var i = lo; | ||
var j = mid + 1; | ||
var k = lo; | ||
while (true) { | ||
var cmp = compare(array[i], array[j]); | ||
if (cmp <= 0) { | ||
auxiliary[k++] = array[i++]; | ||
if (i > mid) { | ||
do { | ||
auxiliary[k++] = array[j++]; | ||
} while (j <= hi); | ||
break; | ||
} | ||
} else { | ||
auxiliary[k++] = array[j++]; | ||
if (j > hi) { | ||
do { | ||
auxiliary[k++] = array[i++]; | ||
} while (i <= mid); | ||
break; | ||
} | ||
} | ||
} | ||
}; | ||
var sortArrayToAuxiliary = function sortArrayToAuxiliary(array, auxiliary, lo, hi, compare) { | ||
if (hi < lo) return; | ||
if (hi === lo) { | ||
auxiliary[lo] = array[lo]; | ||
return; | ||
} | ||
var mid = Math.floor(lo + (hi - lo) / 2); | ||
sortAuxiliaryToArray(array, auxiliary, lo, mid, compare); | ||
sortAuxiliaryToArray(array, auxiliary, mid + 1, hi, compare); | ||
merge(array, auxiliary, lo, mid, hi, compare); | ||
}; | ||
var sortAuxiliaryToArray = function sortAuxiliaryToArray(array, auxiliary, lo, hi, compare) { | ||
if (hi <= lo) return; | ||
var mid = Math.floor(lo + (hi - lo) / 2); | ||
sortArrayToAuxiliary(array, auxiliary, lo, mid, compare); | ||
sortArrayToAuxiliary(array, auxiliary, mid + 1, hi, compare); | ||
merge(auxiliary, array, lo, mid, hi, compare); | ||
}; | ||
var mergeSort = (function (array) { | ||
var compare = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (a, b) { | ||
if (a < b) return -1; | ||
if (a > b) return 1; | ||
return 0; | ||
}; | ||
var result = array.slice(); | ||
var auxiliary = array.slice(); | ||
sortAuxiliaryToArray(result, auxiliary, 0, result.length - 1, compare); | ||
return result; | ||
}); | ||
var defaultCompare = function defaultCompare(a, b) { | ||
if (a < b) return -1; | ||
if (a > b) return 1; | ||
return 0; | ||
}; | ||
var sortedRows = function sortedRows(rows, sorting, getCellValue, getColumnCompare) { | ||
if (!sorting.length) return rows; | ||
var compare = Array.from(sorting).reverse().reduce(function (prevCompare, columnSorting) { | ||
var columnName = columnSorting.columnName; | ||
var inverse = columnSorting.direction === 'desc'; | ||
var columnCompare = getColumnCompare && getColumnCompare(columnName) || defaultCompare; | ||
return function (aRow, bRow) { | ||
var a = getCellValue(aRow, columnName); | ||
var b = getCellValue(bRow, columnName); | ||
var result = columnCompare(a, b); | ||
if (result !== 0) { | ||
return inverse ? -result : result; | ||
} | ||
return prevCompare(aRow, bRow); | ||
}; | ||
}, function () { | ||
return 0; | ||
}); | ||
return mergeSort(Array.from(rows), compare); | ||
}; | ||
var setColumnFilter = function setColumnFilter(filters, _ref) { | ||
@@ -452,4 +486,4 @@ var columnName = _ref.columnName, | ||
return rows.filter(function (row) { | ||
return filters.reduce(function (acc, filter) { | ||
var compoundPredicate = filters.reduce(function (prevCompare, filter) { | ||
return function (row) { | ||
var columnName = filter.columnName, | ||
@@ -460,5 +494,9 @@ filterConfig = objectWithoutProperties(filter, ["columnName"]); | ||
return acc && predicate(getCellValue(row, columnName), filterConfig, row); | ||
}, true); | ||
return prevCompare(row) && predicate(getCellValue(row, columnName), filterConfig, row); | ||
}; | ||
}, function () { | ||
return true; | ||
}); | ||
return rows.filter(compoundPredicate); | ||
}; | ||
@@ -468,2 +506,113 @@ | ||
var groupByColumn = function groupByColumn(state, _ref) { | ||
var columnName = _ref.columnName, | ||
groupIndex = _ref.groupIndex; | ||
var grouping = Array.from(state.grouping); | ||
var groupingIndex = grouping.findIndex(function (g) { | ||
return g.columnName === columnName; | ||
}); | ||
var targetIndex = groupIndex; | ||
if (groupingIndex > -1) { | ||
grouping.splice(groupingIndex, 1); | ||
} else if (groupIndex === undefined) { | ||
targetIndex = grouping.length; | ||
} | ||
if (targetIndex > -1) { | ||
grouping.splice(targetIndex, 0, { | ||
columnName: columnName | ||
}); | ||
} | ||
var ungroupedColumnIndex = state.grouping.findIndex(function (group, index) { | ||
return !grouping[index] || group.columnName !== grouping[index].columnName; | ||
}); | ||
if (ungroupedColumnIndex === -1) { | ||
return { | ||
grouping: grouping | ||
}; | ||
} | ||
var filteredExpandedGroups = state.expandedGroups.filter(function (group) { | ||
return group.split(GROUP_KEY_SEPARATOR).length <= ungroupedColumnIndex; | ||
}); | ||
if (filteredExpandedGroups.length === state.expandedGroups.length) { | ||
return { | ||
grouping: grouping | ||
}; | ||
} | ||
return { | ||
grouping: grouping, | ||
expandedGroups: filteredExpandedGroups | ||
}; | ||
}; | ||
var toggleExpandedGroups = function toggleExpandedGroups(state, _ref2) { | ||
var groupKey = _ref2.groupKey; | ||
var expandedGroups = Array.from(state.expandedGroups); | ||
var groupKeyIndex = expandedGroups.indexOf(groupKey); | ||
if (groupKeyIndex > -1) { | ||
expandedGroups.splice(groupKeyIndex, 1); | ||
} else { | ||
expandedGroups.push(groupKey); | ||
} | ||
return { | ||
expandedGroups: expandedGroups | ||
}; | ||
}; | ||
var draftGroupingChange = function draftGroupingChange(state, _ref3) { | ||
var columnName = _ref3.columnName, | ||
groupIndex = _ref3.groupIndex; | ||
return { groupingChange: { columnName: columnName, groupIndex: groupIndex } }; | ||
}; | ||
var cancelGroupingChange = function cancelGroupingChange() { | ||
return { groupingChange: null }; | ||
}; | ||
var draftGrouping = function draftGrouping(grouping, groupingChange) { | ||
if (!groupingChange) return grouping; | ||
var columnName = groupingChange.columnName, | ||
groupIndex = groupingChange.groupIndex; | ||
var result = Array.from(grouping); | ||
if (groupIndex !== -1) { | ||
result = result.filter(function (g) { | ||
return g.columnName !== columnName; | ||
}); | ||
result.splice(groupIndex, 0, { | ||
columnName: columnName, | ||
draft: true, | ||
mode: grouping.length > result.length ? 'reorder' : 'add' | ||
}); | ||
} else { | ||
result = result.map(function (g) { | ||
return g.columnName === columnName ? { columnName: columnName, draft: true, mode: 'remove' } : g; | ||
}); | ||
} | ||
return result; | ||
}; | ||
var GRID_GROUP_TYPE = 'group'; | ||
var GRID_GROUP_CHECK = Symbol(GRID_GROUP_TYPE + '_check'); | ||
var GRID_GROUP_LEVEL_KEY = Symbol(GRID_GROUP_TYPE + '_levelKey'); | ||
var groupRowChecker = function groupRowChecker(row) { | ||
return row[GRID_GROUP_CHECK]; | ||
}; | ||
var groupRowLevelKeyGetter = function groupRowLevelKeyGetter(row) { | ||
return row[GRID_GROUP_LEVEL_KEY]; | ||
}; | ||
var defaultColumnIdentity = function defaultColumnIdentity(value) { | ||
@@ -479,18 +628,11 @@ return { | ||
var columnGrouping = grouping[0]; | ||
var columnName = columnGrouping.columnName; | ||
var columnName = grouping[0].columnName; | ||
var groupIdentity = getColumnIdentity && getColumnIdentity(columnName) || defaultColumnIdentity; | ||
var groups = rows.reduce(function (acc, row) { | ||
var cellValue = getCellValue(row, columnName); | ||
var group = groupIdentity(cellValue, row); | ||
var _groupIdentity = groupIdentity(getCellValue(row, columnName), row), | ||
key = _groupIdentity.key, | ||
_groupIdentity$value = _groupIdentity.value, | ||
value = _groupIdentity$value === undefined ? key : _groupIdentity$value; | ||
var key = group.key; | ||
var value = group.value; | ||
if (!value) { | ||
value = key; | ||
} | ||
var sameKeyItems = acc.get(key); | ||
@@ -528,2 +670,4 @@ | ||
return rows.reduce(function (acc, _ref3) { | ||
var _ref4; | ||
var value = _ref3.value, | ||
@@ -536,9 +680,3 @@ groupKey = _ref3.key, | ||
var expanded = expandedGroups.has(key); | ||
return [].concat(toConsumableArray(acc), [{ | ||
_headerKey: 'groupRow_' + groupedBy, | ||
type: 'groupRow', | ||
groupedBy: groupedBy, | ||
key: key, | ||
value: value | ||
}], toConsumableArray(expanded ? expandedGroupRows(items, nestedGrouping, expandedGroups, '' + key + GROUP_KEY_SEPARATOR) : [])); | ||
return [].concat(toConsumableArray(acc), [(_ref4 = {}, defineProperty(_ref4, GRID_GROUP_CHECK, true), defineProperty(_ref4, GRID_GROUP_LEVEL_KEY, GRID_GROUP_TYPE + '_' + groupedBy), defineProperty(_ref4, 'groupedBy', groupedBy), defineProperty(_ref4, 'key', key), defineProperty(_ref4, 'value', value), _ref4)], toConsumableArray(expanded ? expandedGroupRows(items, nestedGrouping, expandedGroups, '' + key + GROUP_KEY_SEPARATOR) : [])); | ||
}, []); | ||
@@ -562,102 +700,2 @@ }; | ||
var getFirstChangedGropingIndex = function getFirstChangedGropingIndex(prevGrouping, nextGrouping) { | ||
if (prevGrouping.length <= nextGrouping.length) { | ||
return -1; | ||
} | ||
return prevGrouping.findIndex(function (group, index) { | ||
return !nextGrouping[index] || group.columnName !== nextGrouping[index].columnName; | ||
}); | ||
}; | ||
var groupByColumn = function groupByColumn(prevGrouping, _ref) { | ||
var columnName = _ref.columnName, | ||
groupIndex = _ref.groupIndex; | ||
var grouping = Array.from(prevGrouping); | ||
var index = grouping.findIndex(function (g) { | ||
return g.columnName === columnName; | ||
}); | ||
var targetIndex = groupIndex; | ||
if (index > -1) { | ||
grouping.splice(index, 1); | ||
} else if (groupIndex === undefined) { | ||
targetIndex = grouping.length; | ||
} | ||
if (targetIndex > -1) { | ||
grouping.splice(targetIndex, 0, { | ||
columnName: columnName | ||
}); | ||
} | ||
return grouping; | ||
}; | ||
var draftGroupingChange = function draftGroupingChange(prevGroupingChange, _ref2) { | ||
var columnName = _ref2.columnName, | ||
groupIndex = _ref2.groupIndex; | ||
return { columnName: columnName, groupIndex: groupIndex }; | ||
}; | ||
var cancelGroupingChange = function cancelGroupingChange() { | ||
return null; | ||
}; | ||
var removeOutdatedExpandedGroups = function removeOutdatedExpandedGroups(prevExpandedGroups, _ref3) { | ||
var prevGrouping = _ref3.prevGrouping, | ||
grouping = _ref3.grouping; | ||
var ungroupedColumnIndex = getFirstChangedGropingIndex(prevGrouping, grouping); | ||
if (ungroupedColumnIndex === -1) { | ||
return prevExpandedGroups; | ||
} | ||
return prevExpandedGroups.filter(function (group) { | ||
return group.split(GROUP_KEY_SEPARATOR).length <= ungroupedColumnIndex; | ||
}); | ||
}; | ||
var toggleExpandedGroups = function toggleExpandedGroups(prevExpandedGroups, _ref4) { | ||
var groupKey = _ref4.groupKey; | ||
var expandedGroups = Array.from(prevExpandedGroups); | ||
var groupKeyIndex = expandedGroups.indexOf(groupKey); | ||
if (groupKeyIndex > -1) { | ||
expandedGroups.splice(groupKeyIndex, 1); | ||
} else { | ||
expandedGroups.push(groupKey); | ||
} | ||
return expandedGroups; | ||
}; | ||
var draftGrouping = function draftGrouping(grouping, groupingChange) { | ||
if (!groupingChange) return grouping; | ||
var columnName = groupingChange.columnName, | ||
groupIndex = groupingChange.groupIndex; | ||
var result = Array.from(grouping); | ||
if (groupIndex !== -1) { | ||
result = result.filter(function (g) { | ||
return g.columnName !== columnName; | ||
}); | ||
result.splice(groupIndex, 0, { | ||
columnName: columnName, | ||
draft: true, | ||
mode: grouping.length > result.length ? 'reorder' : 'add' | ||
}); | ||
} else { | ||
result = result.map(function (g) { | ||
return g.columnName === columnName ? { columnName: columnName, draft: true, mode: 'remove' } : g; | ||
}); | ||
} | ||
return result; | ||
}; | ||
var setCurrentPage = function setCurrentPage(prevPage, page) { | ||
@@ -670,16 +708,14 @@ return page; | ||
var PAGE_HEADERS_OVERFLOW_ERROR = ['The count of title rows exceeds the page size. Consider increasing the page size.', 'Typically, title rows are group headers.'].join('\n'); | ||
var PAGE_HEADERS_OVERFLOW_ERROR = 'Max row level exceeds the page size. Consider increasing the page size.'; | ||
var paginate = function paginate(rows, pageSize, page) { | ||
var paginatedRows = function paginatedRows(rows, pageSize, page) { | ||
return pageSize ? rows.slice(pageSize * page, pageSize * (page + 1)) : rows; | ||
}; | ||
var ensurePageHeaders = function ensurePageHeaders(rows, pageSize) { | ||
if (!pageSize) { | ||
return rows; | ||
} | ||
var rowsWithPageHeaders = function rowsWithPageHeaders(rows, pageSize, getRowLevelKey) { | ||
if (!pageSize) return rows; | ||
var result = rows.slice(); | ||
var headers = []; | ||
var headerRows = []; | ||
var currentIndex = 0; | ||
@@ -689,13 +725,13 @@ | ||
var row = result[currentIndex]; | ||
var headerKey = row._headerKey; | ||
if (headerKey) { | ||
var headerIndex = headers.findIndex(function (header) { | ||
return header._headerKey === headerKey; | ||
var header = getRowLevelKey ? getRowLevelKey(row) : row._headerKey; | ||
if (header) { | ||
var headerIndex = headerRows.findIndex(function (headerRow) { | ||
return (getRowLevelKey ? getRowLevelKey(headerRow) : row._headerKey) === header; | ||
}); | ||
if (headerIndex === -1) { | ||
headers = [].concat(toConsumableArray(headers), [row]); | ||
headerRows = [].concat(toConsumableArray(headerRows), [row]); | ||
} else { | ||
headers = [].concat(toConsumableArray(headers.slice(0, headerIndex)), [row]); | ||
headerRows = [].concat(toConsumableArray(headerRows.slice(0, headerIndex)), [row]); | ||
} | ||
if (headers.length >= pageSize) { | ||
if (headerRows.length >= pageSize) { | ||
throw new Error(PAGE_HEADERS_OVERFLOW_ERROR); | ||
@@ -705,4 +741,4 @@ } | ||
var indexInPage = currentIndex % pageSize; | ||
if (indexInPage < headers.length && row !== headers[indexInPage]) { | ||
result = [].concat(toConsumableArray(result.slice(0, currentIndex)), [headers[indexInPage]], toConsumableArray(result.slice(currentIndex))); | ||
if (indexInPage < headerRows.length && row !== headerRows[indexInPage]) { | ||
result = [].concat(toConsumableArray(result.slice(0, currentIndex)), [headerRows[indexInPage]], toConsumableArray(result.slice(currentIndex))); | ||
} | ||
@@ -796,5 +832,5 @@ currentIndex += 1; | ||
var getAvailableToSelect = function getAvailableToSelect(rows, getRowId) { | ||
var getAvailableToSelect = function getAvailableToSelect(rows, getRowId, isGroupRow) { | ||
return rows.filter(function (row) { | ||
return !row.type; | ||
return (!isGroupRow || !isGroupRow(row)) && !row.type; | ||
}).map(function (row) { | ||
@@ -1110,5 +1146,7 @@ return getRowId(row); | ||
var tableRowsWithGrouping = function tableRowsWithGrouping(tableRows) { | ||
var tableRowsWithGrouping = function tableRowsWithGrouping(tableRows, isGroupRow) { | ||
return tableRows.map(function (tableRow) { | ||
if (tableRow.type !== TABLE_DATA_TYPE || tableRow.row.type !== 'groupRow') return tableRow; | ||
if (tableRow.type !== TABLE_DATA_TYPE || !isGroupRow(tableRow.row) && tableRow.row.type !== 'groupRow') { | ||
return tableRow; | ||
} | ||
return _extends({}, tableRow, { | ||
@@ -1204,10 +1242,2 @@ key: TABLE_GROUP_TYPE + '_' + tableRow.row.key, | ||
var tableRowsWithSelection = function tableRowsWithSelection(tableRows, selection) { | ||
var selectionSet = new Set(selection); | ||
return tableRows.map(function (tableRow) { | ||
if (tableRow.type !== TABLE_DATA_TYPE || !selectionSet.has(tableRow.rowId)) return tableRow; | ||
return _extends({ selected: true }, tableRow); | ||
}); | ||
}; | ||
var isNoDataTableRow = function isNoDataTableRow(tableRow) { | ||
@@ -1241,6 +1271,6 @@ return tableRow.type === TABLE_NODATA_TYPE; | ||
return { | ||
key: TABLE_DATA_TYPE + '_' + rowId, | ||
row: row, | ||
rowId: rowId, | ||
type: TABLE_DATA_TYPE, | ||
rowId: rowId, | ||
row: row | ||
key: TABLE_DATA_TYPE + '_' + rowId | ||
}; | ||
@@ -1250,2 +1280,20 @@ }); | ||
var visibleTableColumns = function visibleTableColumns(tableColumns, hiddenColumns) { | ||
return tableColumns.filter(function (tableColumn) { | ||
return hiddenColumns.indexOf(tableColumn.column.name) === -1; | ||
}); | ||
}; | ||
var columnChooserItems = function columnChooserItems(columns, hiddenColumns) { | ||
return columns.map(function (column) { | ||
return { column: column, hidden: hiddenColumns.indexOf(column.name) !== -1 }; | ||
}); | ||
}; | ||
var toggleColumn = function toggleColumn(hiddenColumns, columnName) { | ||
return hiddenColumns.indexOf(columnName) === -1 ? [].concat(toConsumableArray(hiddenColumns), [columnName]) : hiddenColumns.filter(function (hiddenColumn) { | ||
return hiddenColumn !== columnName; | ||
}); | ||
}; | ||
var getTargetColumnGeometries = function getTargetColumnGeometries(columnGeometries, sourceIndex) { | ||
@@ -1439,2 +1487,4 @@ var sourceWidth = columnGeometries[sourceIndex].right - columnGeometries[sourceIndex].left; | ||
exports.getGroupCellTargetIndex = getGroupCellTargetIndex; | ||
exports.rowIdGetter = rowIdGetter; | ||
exports.cellValueGetter = cellValueGetter; | ||
exports.setColumnSorting = setColumnSorting; | ||
@@ -1446,16 +1496,16 @@ exports.getColumnSortingDirection = getColumnSortingDirection; | ||
exports.filteredRows = filteredRows; | ||
exports.groupedRows = groupedRows; | ||
exports.expandedGroupRows = expandedGroupRows; | ||
exports.groupingPanelItems = groupingPanelItems; | ||
exports.groupByColumn = groupByColumn; | ||
exports.toggleExpandedGroups = toggleExpandedGroups; | ||
exports.draftGroupingChange = draftGroupingChange; | ||
exports.cancelGroupingChange = cancelGroupingChange; | ||
exports.removeOutdatedExpandedGroups = removeOutdatedExpandedGroups; | ||
exports.toggleExpandedGroups = toggleExpandedGroups; | ||
exports.getFirstChangedGropingIndex = getFirstChangedGropingIndex; | ||
exports.draftGrouping = draftGrouping; | ||
exports.groupRowChecker = groupRowChecker; | ||
exports.groupRowLevelKeyGetter = groupRowLevelKeyGetter; | ||
exports.groupedRows = groupedRows; | ||
exports.expandedGroupRows = expandedGroupRows; | ||
exports.groupingPanelItems = groupingPanelItems; | ||
exports.setCurrentPage = setCurrentPage; | ||
exports.setPageSize = setPageSize; | ||
exports.paginate = paginate; | ||
exports.ensurePageHeaders = ensurePageHeaders; | ||
exports.paginatedRows = paginatedRows; | ||
exports.rowsWithPageHeaders = rowsWithPageHeaders; | ||
exports.pageCount = pageCount; | ||
@@ -1521,3 +1571,2 @@ exports.rowCount = rowCount; | ||
exports.tableColumnsWithSelection = tableColumnsWithSelection; | ||
exports.tableRowsWithSelection = tableRowsWithSelection; | ||
exports.TABLE_DATA_TYPE = TABLE_DATA_TYPE; | ||
@@ -1531,2 +1580,5 @@ exports.TABLE_NODATA_TYPE = TABLE_NODATA_TYPE; | ||
exports.tableRowsWithDataRows = tableRowsWithDataRows; | ||
exports.visibleTableColumns = visibleTableColumns; | ||
exports.columnChooserItems = columnChooserItems; | ||
exports.toggleColumn = toggleColumn; | ||
@@ -1533,0 +1585,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
{ | ||
"name": "@devexpress/dx-grid-core", | ||
"version": "1.0.0-alpha.11", | ||
"version": "1.0.0-alpha.12", | ||
"description": "Core library for the DevExtreme Reactive Grid component", | ||
@@ -42,3 +42,3 @@ "author": { | ||
"devDependencies": { | ||
"@devexpress/dx-core": "1.0.0-alpha.11", | ||
"@devexpress/dx-core": "1.0.0-alpha.12", | ||
"babel-core": "^6.26.0", | ||
@@ -51,4 +51,4 @@ "babel-jest": "^21.2.0", | ||
"core-js": "^2.5.1", | ||
"eslint": "^4.8.0", | ||
"eslint-config-airbnb-base": "^12.0.1", | ||
"eslint": "^4.9.0", | ||
"eslint-config-airbnb-base": "^12.1.0", | ||
"eslint-plugin-filenames": "^1.2.0", | ||
@@ -64,4 +64,4 @@ "eslint-plugin-import": "^2.7.0", | ||
"peerDependencies": { | ||
"@devexpress/dx-core": "1.0.0-alpha.11" | ||
"@devexpress/dx-core": "1.0.0-alpha.12" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
246826
2468