Skip to content

Commit 8ff6814

Browse files
committed
npm build
1 parent 29af692 commit 8ff6814

File tree

3 files changed

+395
-156
lines changed

3 files changed

+395
-156
lines changed

npm/slick.core.js

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,30 @@
1616
"EditorLock": EditorLock,
1717

1818
/***
19-
* A global singleton editor lock.
20-
* @class GlobalEditorLock
21-
* @static
22-
* @constructor
23-
*/
24-
"GlobalEditorLock": new EditorLock(),
25-
26-
"keyCode": {
27-
BACKSPACE: 8,
28-
DELETE: 46,
29-
DOWN: 40,
30-
END: 35,
31-
ENTER: 13,
32-
ESCAPE: 27,
33-
HOME: 36,
34-
INSERT: 45,
35-
LEFT: 37,
36-
PAGE_DOWN: 34,
37-
PAGE_UP: 33,
38-
RIGHT: 39,
39-
TAB: 9,
40-
UP: 38
41-
}
42-
};
19+
* A global singleton editor lock.
20+
* @class GlobalEditorLock
21+
* @static
22+
* @constructor
23+
*/
24+
"GlobalEditorLock": new EditorLock(),
25+
26+
"keyCode": {
27+
BACKSPACE: 8,
28+
DELETE: 46,
29+
DOWN: 40,
30+
END: 35,
31+
ENTER: 13,
32+
ESCAPE: 27,
33+
HOME: 36,
34+
INSERT: 45,
35+
LEFT: 37,
36+
PAGE_DOWN: 34,
37+
PAGE_UP: 33,
38+
RIGHT: 39,
39+
TAB: 9,
40+
UP: 38
41+
}
42+
};
4343

4444
// register namespace
4545
$.extend(true, window, {
@@ -76,7 +76,8 @@
7676
RIGHT: 39,
7777
TAB: 9,
7878
UP: 38
79-
}
79+
},
80+
"preClickClassName" : "slick-edit-preclick"
8081
}
8182
});
8283

@@ -360,6 +361,13 @@
360361
*/
361362
this.collapsed = false;
362363

364+
/***
365+
* Whether a group selection checkbox is checked.
366+
* @property selectChecked
367+
* @type {Boolean}
368+
*/
369+
this.selectChecked = false;
370+
363371
/***
364372
* GroupTotals, if any.
365373
* @property totals
@@ -459,7 +467,7 @@
459467

460468
/***
461469
* Sets the specified edit controller as the active edit controller (acquire edit lock).
462-
* If another edit controller is already active, and exception will be thrown.
470+
* If another edit controller is already active, and exception will be throw new Error(.
463471
* @method activate
464472
* @param editController {EditController} edit controller acquiring the lock
465473
*/
@@ -468,26 +476,26 @@
468476
return;
469477
}
470478
if (activeEditController !== null) {
471-
throw "SlickGrid.EditorLock.activate: an editController is still active, can't activate another editController";
479+
throw new Error("SlickGrid.EditorLock.activate: an editController is still active, can't activate another editController");
472480
}
473481
if (!editController.commitCurrentEdit) {
474-
throw "SlickGrid.EditorLock.activate: editController must implement .commitCurrentEdit()";
482+
throw new Error("SlickGrid.EditorLock.activate: editController must implement .commitCurrentEdit()");
475483
}
476484
if (!editController.cancelCurrentEdit) {
477-
throw "SlickGrid.EditorLock.activate: editController must implement .cancelCurrentEdit()";
485+
throw new Error("SlickGrid.EditorLock.activate: editController must implement .cancelCurrentEdit()");
478486
}
479487
activeEditController = editController;
480488
};
481489

482490
/***
483491
* Unsets the specified edit controller as the active edit controller (release edit lock).
484-
* If the specified edit controller is not the active one, an exception will be thrown.
492+
* If the specified edit controller is not the active one, an exception will be throw new Error(.
485493
* @method deactivate
486494
* @param editController {EditController} edit controller releasing the lock
487495
*/
488496
this.deactivate = function (editController) {
489497
if (activeEditController !== editController) {
490-
throw "SlickGrid.EditorLock.deactivate: specified editController is not the currently active one";
498+
throw new Error("SlickGrid.EditorLock.deactivate: specified editController is not the currently active one");
491499
}
492500
activeEditController = null;
493501
};

npm/slick.dataview.js

Lines changed: 86 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
(function ($) {
2-
3-
module.exports = {
2+
module.exports = {
43
DataView: DataView,
54
Aggregators: {
65
Avg: AvgAggregator,
76
Min: MinAggregator,
87
Max: MaxAggregator,
98
Sum: SumAggregator
109
}
11-
};
10+
};
1211

1312
$.extend(true, window, {
1413
Slick: {
@@ -118,7 +117,7 @@ module.exports = {
118117
for (var i = startingIndex, l = items.length; i < l; i++) {
119118
id = items[i][idProperty];
120119
if (id === undefined) {
121-
throw "Each data element must implement a unique 'id' property";
120+
throw new Error("Each data element must implement a unique 'id' property");
122121
}
123122
idxById[id] = i;
124123
}
@@ -129,7 +128,7 @@ module.exports = {
129128
for (var i = 0, l = items.length; i < l; i++) {
130129
id = items[i][idProperty];
131130
if (id === undefined || idxById[id] !== i) {
132-
throw "Each data element must implement a unique 'id' property";
131+
throw new Error("Each data element must implement a unique 'id' property");
133132
}
134133
}
135134
}
@@ -221,6 +220,15 @@ module.exports = {
221220
}
222221
}
223222

223+
function getFilteredItems(){
224+
return filteredItems;
225+
}
226+
227+
228+
function getFilter(){
229+
return filter;
230+
}
231+
224232
function setFilter(filterFn) {
225233
filter = filterFn;
226234
if (options.inlineFilters) {
@@ -308,6 +316,11 @@ module.exports = {
308316
}
309317
}
310318

319+
function getRowByItem(item) {
320+
ensureRowsByIdCache();
321+
return rowsById[item[idProperty]];
322+
}
323+
311324
function getRowById(id) {
312325
ensureRowsByIdCache();
313326
return rowsById[id];
@@ -317,6 +330,18 @@ module.exports = {
317330
return items[idxById[id]];
318331
}
319332

333+
function mapItemsToRows(itemArray) {
334+
var rows = [];
335+
ensureRowsByIdCache();
336+
for (var i = 0, l = itemArray.length; i < l; i++) {
337+
var row = rowsById[itemArray[i][idProperty]];
338+
if (row != null) {
339+
rows[rows.length] = row;
340+
}
341+
}
342+
return rows;
343+
}
344+
320345
function mapIdsToRows(idArray) {
321346
var rows = [];
322347
ensureRowsByIdCache();
@@ -341,7 +366,7 @@ module.exports = {
341366

342367
function updateItem(id, item) {
343368
if (idxById[id] === undefined || id !== item[idProperty]) {
344-
throw "Invalid or non-matching id";
369+
throw new Error("Invalid or non-matching id");
345370
}
346371
items[idxById[id]] = item;
347372
if (!updated) {
@@ -357,6 +382,45 @@ module.exports = {
357382
refresh();
358383
}
359384

385+
function sortedAddItem(item) {
386+
// NOTE: assumes 'items' are sorted!
387+
if(!sortComparer) {
388+
throw new Error("sortedAddItem() requires a sort comparer, use sort()");
389+
}
390+
insertItem(sortedIndex(item), item);
391+
}
392+
393+
function sortedUpdateItem(item) {
394+
// NOTE: assumes 'items' are sorted!
395+
if(!sortComparer) {
396+
throw new Error("sortedUpdateItem() requires a sort comparer, use sort()");
397+
}
398+
var old_item = getItemById(item.id);
399+
if(sortComparer(old_item, item) !== 0) {
400+
// item affects sorting -> must use sorted add
401+
deleteItem(item.id);
402+
sortedAddItem(item);
403+
}
404+
else { // update does not affect sorting -> regular update works fine
405+
updateItem(item.id, item);
406+
}
407+
}
408+
409+
function sortedIndex(searchItem) {
410+
var low = 0, high = items.length;
411+
412+
while (low < high) {
413+
var mid = low + high >>> 1;
414+
if (sortComparer(items[mid], searchItem) === -1) {
415+
low = mid + 1;
416+
}
417+
else {
418+
high = mid;
419+
}
420+
}
421+
return low;
422+
}
423+
360424
function addItem(item) {
361425
items.push(item);
362426
updateIdxById(items.length - 1);
@@ -366,7 +430,7 @@ module.exports = {
366430
function deleteItem(id) {
367431
var idx = idxById[id];
368432
if (idx === undefined) {
369-
throw "Invalid id";
433+
throw new Error("Invalid id");
370434
}
371435
delete idxById[id];
372436
items.splice(idx, 1);
@@ -774,11 +838,11 @@ module.exports = {
774838
var paged;
775839
if (pagesize) {
776840
if (filteredItems.length <= pagenum * pagesize) {
777-
if (filteredItems.length === 0) {
778-
pagenum = 0;
779-
} else {
780-
pagenum = Math.floor((filteredItems.length - 1) / pagesize);
781-
}
841+
if (filteredItems.length === 0) {
842+
pagenum = 0;
843+
} else {
844+
pagenum = Math.floor((filteredItems.length - 1) / pagesize);
845+
}
782846
}
783847
paged = filteredItems.slice(pagesize * pagenum, pagesize * pagenum + pagesize);
784848
} else {
@@ -994,6 +1058,10 @@ module.exports = {
9941058
if (key != args.key) { return; }
9951059
if (args.hash) {
9961060
storeCellCssStyles(args.hash);
1061+
} else {
1062+
grid.onCellCssStylesChanged.unsubscribe(styleChanged);
1063+
self.onRowsChanged.unsubscribe(update);
1064+
self.onRowCountChanged.unsubscribe(update);
9971065
}
9981066
});
9991067

@@ -1011,6 +1079,8 @@ module.exports = {
10111079
"getItems": getItems,
10121080
"setItems": setItems,
10131081
"setFilter": setFilter,
1082+
"getFilter": getFilter,
1083+
"getFilteredItems": getFilteredItems,
10141084
"sort": sort,
10151085
"fastSort": fastSort,
10161086
"reSort": reSort,
@@ -1024,9 +1094,11 @@ module.exports = {
10241094
"expandGroup": expandGroup,
10251095
"getGroups": getGroups,
10261096
"getIdxById": getIdxById,
1097+
"getRowByItem": getRowByItem,
10271098
"getRowById": getRowById,
10281099
"getItemById": getItemById,
10291100
"getItemByIdx": getItemByIdx,
1101+
"mapItemsToRows": mapItemsToRows,
10301102
"mapRowsToIds": mapRowsToIds,
10311103
"mapIdsToRows": mapIdsToRows,
10321104
"setRefreshHints": setRefreshHints,
@@ -1035,6 +1107,8 @@ module.exports = {
10351107
"updateItem": updateItem,
10361108
"insertItem": insertItem,
10371109
"addItem": addItem,
1110+
"sortedAddItem": sortedAddItem,
1111+
"sortedUpdateItem": sortedUpdateItem,
10381112
"deleteItem": deleteItem,
10391113
"syncGridSelection": syncGridSelection,
10401114
"syncGridCellCssStyles": syncGridCellCssStyles,

0 commit comments

Comments
 (0)