Skip to content

Commit

Permalink
npm build
Browse files Browse the repository at this point in the history
  • Loading branch information
6pac committed Jun 13, 2017
1 parent 29af692 commit 8ff6814
Show file tree
Hide file tree
Showing 3 changed files with 395 additions and 156 deletions.
70 changes: 39 additions & 31 deletions npm/slick.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,30 @@
"EditorLock": EditorLock,

/***
* A global singleton editor lock.
* @class GlobalEditorLock
* @static
* @constructor
*/
"GlobalEditorLock": new EditorLock(),

"keyCode": {
BACKSPACE: 8,
DELETE: 46,
DOWN: 40,
END: 35,
ENTER: 13,
ESCAPE: 27,
HOME: 36,
INSERT: 45,
LEFT: 37,
PAGE_DOWN: 34,
PAGE_UP: 33,
RIGHT: 39,
TAB: 9,
UP: 38
}
};
* A global singleton editor lock.
* @class GlobalEditorLock
* @static
* @constructor
*/
"GlobalEditorLock": new EditorLock(),

"keyCode": {
BACKSPACE: 8,
DELETE: 46,
DOWN: 40,
END: 35,
ENTER: 13,
ESCAPE: 27,
HOME: 36,
INSERT: 45,
LEFT: 37,
PAGE_DOWN: 34,
PAGE_UP: 33,
RIGHT: 39,
TAB: 9,
UP: 38
}
};

// register namespace
$.extend(true, window, {
Expand Down Expand Up @@ -76,7 +76,8 @@
RIGHT: 39,
TAB: 9,
UP: 38
}
},
"preClickClassName" : "slick-edit-preclick"
}
});

Expand Down Expand Up @@ -360,6 +361,13 @@
*/
this.collapsed = false;

/***
* Whether a group selection checkbox is checked.
* @property selectChecked
* @type {Boolean}
*/
this.selectChecked = false;

/***
* GroupTotals, if any.
* @property totals
Expand Down Expand Up @@ -459,7 +467,7 @@

/***
* Sets the specified edit controller as the active edit controller (acquire edit lock).
* If another edit controller is already active, and exception will be thrown.
* If another edit controller is already active, and exception will be throw new Error(.
* @method activate
* @param editController {EditController} edit controller acquiring the lock
*/
Expand All @@ -468,26 +476,26 @@
return;
}
if (activeEditController !== null) {
throw "SlickGrid.EditorLock.activate: an editController is still active, can't activate another editController";
throw new Error("SlickGrid.EditorLock.activate: an editController is still active, can't activate another editController");
}
if (!editController.commitCurrentEdit) {
throw "SlickGrid.EditorLock.activate: editController must implement .commitCurrentEdit()";
throw new Error("SlickGrid.EditorLock.activate: editController must implement .commitCurrentEdit()");
}
if (!editController.cancelCurrentEdit) {
throw "SlickGrid.EditorLock.activate: editController must implement .cancelCurrentEdit()";
throw new Error("SlickGrid.EditorLock.activate: editController must implement .cancelCurrentEdit()");
}
activeEditController = editController;
};

/***
* Unsets the specified edit controller as the active edit controller (release edit lock).
* If the specified edit controller is not the active one, an exception will be thrown.
* If the specified edit controller is not the active one, an exception will be throw new Error(.
* @method deactivate
* @param editController {EditController} edit controller releasing the lock
*/
this.deactivate = function (editController) {
if (activeEditController !== editController) {
throw "SlickGrid.EditorLock.deactivate: specified editController is not the currently active one";
throw new Error("SlickGrid.EditorLock.deactivate: specified editController is not the currently active one");
}
activeEditController = null;
};
Expand Down
98 changes: 86 additions & 12 deletions npm/slick.dataview.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
(function ($) {

module.exports = {
module.exports = {
DataView: DataView,
Aggregators: {
Avg: AvgAggregator,
Min: MinAggregator,
Max: MaxAggregator,
Sum: SumAggregator
}
};
};

$.extend(true, window, {
Slick: {
Expand Down Expand Up @@ -118,7 +117,7 @@ module.exports = {
for (var i = startingIndex, l = items.length; i < l; i++) {
id = items[i][idProperty];
if (id === undefined) {
throw "Each data element must implement a unique 'id' property";
throw new Error("Each data element must implement a unique 'id' property");
}
idxById[id] = i;
}
Expand All @@ -129,7 +128,7 @@ module.exports = {
for (var i = 0, l = items.length; i < l; i++) {
id = items[i][idProperty];
if (id === undefined || idxById[id] !== i) {
throw "Each data element must implement a unique 'id' property";
throw new Error("Each data element must implement a unique 'id' property");
}
}
}
Expand Down Expand Up @@ -221,6 +220,15 @@ module.exports = {
}
}

function getFilteredItems(){
return filteredItems;
}


function getFilter(){
return filter;
}

function setFilter(filterFn) {
filter = filterFn;
if (options.inlineFilters) {
Expand Down Expand Up @@ -308,6 +316,11 @@ module.exports = {
}
}

function getRowByItem(item) {
ensureRowsByIdCache();
return rowsById[item[idProperty]];
}

function getRowById(id) {
ensureRowsByIdCache();
return rowsById[id];
Expand All @@ -317,6 +330,18 @@ module.exports = {
return items[idxById[id]];
}

function mapItemsToRows(itemArray) {
var rows = [];
ensureRowsByIdCache();
for (var i = 0, l = itemArray.length; i < l; i++) {
var row = rowsById[itemArray[i][idProperty]];
if (row != null) {
rows[rows.length] = row;
}
}
return rows;
}

function mapIdsToRows(idArray) {
var rows = [];
ensureRowsByIdCache();
Expand All @@ -341,7 +366,7 @@ module.exports = {

function updateItem(id, item) {
if (idxById[id] === undefined || id !== item[idProperty]) {
throw "Invalid or non-matching id";
throw new Error("Invalid or non-matching id");
}
items[idxById[id]] = item;
if (!updated) {
Expand All @@ -357,6 +382,45 @@ module.exports = {
refresh();
}

function sortedAddItem(item) {
// NOTE: assumes 'items' are sorted!
if(!sortComparer) {
throw new Error("sortedAddItem() requires a sort comparer, use sort()");
}
insertItem(sortedIndex(item), item);
}

function sortedUpdateItem(item) {
// NOTE: assumes 'items' are sorted!
if(!sortComparer) {
throw new Error("sortedUpdateItem() requires a sort comparer, use sort()");
}
var old_item = getItemById(item.id);
if(sortComparer(old_item, item) !== 0) {
// item affects sorting -> must use sorted add
deleteItem(item.id);
sortedAddItem(item);
}
else { // update does not affect sorting -> regular update works fine
updateItem(item.id, item);
}
}

function sortedIndex(searchItem) {
var low = 0, high = items.length;

while (low < high) {
var mid = low + high >>> 1;
if (sortComparer(items[mid], searchItem) === -1) {
low = mid + 1;
}
else {
high = mid;
}
}
return low;
}

function addItem(item) {
items.push(item);
updateIdxById(items.length - 1);
Expand All @@ -366,7 +430,7 @@ module.exports = {
function deleteItem(id) {
var idx = idxById[id];
if (idx === undefined) {
throw "Invalid id";
throw new Error("Invalid id");
}
delete idxById[id];
items.splice(idx, 1);
Expand Down Expand Up @@ -774,11 +838,11 @@ module.exports = {
var paged;
if (pagesize) {
if (filteredItems.length <= pagenum * pagesize) {
if (filteredItems.length === 0) {
pagenum = 0;
} else {
pagenum = Math.floor((filteredItems.length - 1) / pagesize);
}
if (filteredItems.length === 0) {
pagenum = 0;
} else {
pagenum = Math.floor((filteredItems.length - 1) / pagesize);
}
}
paged = filteredItems.slice(pagesize * pagenum, pagesize * pagenum + pagesize);
} else {
Expand Down Expand Up @@ -994,6 +1058,10 @@ module.exports = {
if (key != args.key) { return; }
if (args.hash) {
storeCellCssStyles(args.hash);
} else {
grid.onCellCssStylesChanged.unsubscribe(styleChanged);
self.onRowsChanged.unsubscribe(update);
self.onRowCountChanged.unsubscribe(update);
}
});

Expand All @@ -1011,6 +1079,8 @@ module.exports = {
"getItems": getItems,
"setItems": setItems,
"setFilter": setFilter,
"getFilter": getFilter,
"getFilteredItems": getFilteredItems,
"sort": sort,
"fastSort": fastSort,
"reSort": reSort,
Expand All @@ -1024,9 +1094,11 @@ module.exports = {
"expandGroup": expandGroup,
"getGroups": getGroups,
"getIdxById": getIdxById,
"getRowByItem": getRowByItem,
"getRowById": getRowById,
"getItemById": getItemById,
"getItemByIdx": getItemByIdx,
"mapItemsToRows": mapItemsToRows,
"mapRowsToIds": mapRowsToIds,
"mapIdsToRows": mapIdsToRows,
"setRefreshHints": setRefreshHints,
Expand All @@ -1035,6 +1107,8 @@ module.exports = {
"updateItem": updateItem,
"insertItem": insertItem,
"addItem": addItem,
"sortedAddItem": sortedAddItem,
"sortedUpdateItem": sortedUpdateItem,
"deleteItem": deleteItem,
"syncGridSelection": syncGridSelection,
"syncGridCellCssStyles": syncGridCellCssStyles,
Expand Down
Loading

0 comments on commit 8ff6814

Please sign in to comment.