Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dynamic-virtual-scroller

Package Overview
Dependencies
Maintainers
1
Versions
98
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dynamic-virtual-scroller - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

3

package.json
{
"name": "dynamic-virtual-scroller",
"version": "1.0.1",
"version": "1.0.2",
"description": "A virtual scroller for the web that can handle dynamic row and column sizes.",

@@ -10,3 +10,2 @@ "main": "virtual-scroller.js",

"dependencies": {
"bluebird": "^3.3.4",
"lodash": "^4.9.0"

@@ -13,0 +12,0 @@ },

@@ -124,2 +124,28 @@ window.VirtualScroller = (function ($, _) {

var removeFromDom = function (params) {
params = validateParameters(params, {
item: {type: 'object', customCheck: function (item) {
return item instanceof jQuery;
}},
rowIndex: {type: 'number'},
columnIndex: {type: ['number', 'undefined'], default: undefined}
});
var shouldBeRemoved;
if (params.columnIndex === undefined) {
shouldBeRemoved = config.onBeforeRowRemoved({
row: params.item,
rowIndex: params.rowIndex
});
} else {
shouldBeRemoved = config.onBeforeColumnRemoved({
column: params.item,
rowIndex: params.rowIndex,
columnIndex: params.columnIndex
});
}
if (shouldBeRemoved !== false) {
params.item.remove();
}
};
var howManyItemsFitIn = function (params) {

@@ -533,14 +559,27 @@

var renderChildren = function (canvas, newChildren, oldChildren) {
oldChildren = oldChildren || [];
var oldStartIndex = oldChildren.length - _.compact(oldChildren).length;
var renderChildren = function (params) {
validateParameters(params, {
canvas: {type: 'object'},
newChildren: {type: 'array'},
oldChildren: {type: 'array', default: []},
/*
Required if you want to render columns. We need this information in removeFromDom.
*/
rowIndex: {type: ['number', 'undefined'], default: undefined}
});
var oldStartIndex = params.oldChildren.length - _.compact(params.oldChildren).length;
var removedIndices = [];
_.each(oldChildren, function (child, index) {
_.each(params.oldChildren, function (child, index) {
if (!child) {
return;
}
if (_.indexOf(newChildren, child) === -1) {
child.remove();
if (_.indexOf(params.newChildren, child) === -1) {
removeFromDom({
item: child,
rowIndex: params.rowIndex === undefined ? index : params.rowIndex,
columnIndex: params.rowIndex === undefined ? undefined : index
});
removedIndices.push(index);

@@ -553,7 +592,7 @@ }

_.each(newChildren, function (child, index) {
_.each(params.newChildren, function (child, index) {
if (!child) {
return;
}
if (_.indexOf(oldChildren, child) === -1) {
if (_.indexOf(params.oldChildren, child) === -1) {
if (index < oldStartIndex) {

@@ -567,3 +606,3 @@ prepend.push(child);

canvas.prepend(prepend).append(append);
params.canvas.prepend(prepend).append(append);
return removedIndices;

@@ -578,3 +617,7 @@ };

});
var removedIndices = renderChildren(canvas, state.children, oldState.children);
var removedIndices = renderChildren({
canvas: canvas,
newChildren: state.children,
oldChildren: oldState.children
});
_.each(removedIndices, function (index) {

@@ -586,3 +629,3 @@ renderManager.rowStates[index] = undefined;

var renderStateX = function (row, state, oldState) {
var renderStateX = function (row, state, oldState, rowIndex) {

@@ -595,3 +638,8 @@ row.css({

renderChildren(canvas, state.children, oldState.children);
renderChildren({
canvas: canvas,
newChildren: state.children,
oldChildren: oldState.children,
rowIndex: rowIndex
});

@@ -678,3 +726,3 @@ return row;

renderManager.sizeCache.columns = updateRowStateResult.sizeCache;
renderStateX(child, renderManager.rowStates[rowIndex], oldRowState);
renderStateX(child, renderManager.rowStates[rowIndex], oldRowState, rowIndex);
return child;

@@ -812,5 +860,8 @@ }

renderManager.resetState = function () {
_.each(renderManager.state.children, function (child) {
_.each(renderManager.state.children, function (child, index) {
if (child) {
child.remove();
removeFromDom({
item: child,
rowIndex: index
});
}

@@ -831,5 +882,8 @@ });

_.each(renderManager.state.children, function (child) {
_.each(renderManager.state.children, function (child, index) {
if (child) {
child.remove();
removeFromDom({
item: child,
rowIndex: index
});
}

@@ -913,3 +967,6 @@ });

if (renderManager.state.children[params.rowIndex]) {
renderManager.state.children[params.rowIndex].remove();
removeFromDom({
item: renderManager.state.children[params.rowIndex],
rowIndex: params.rowIndex
});
}

@@ -928,3 +985,3 @@ renderManager.state.children.splice(params.rowIndex, 1);

renderManager.rowStates = _.map(renderManager.rowStates, function (rowState) {
renderManager.rowStates = _.map(renderManager.rowStates, function (rowState, rowIndex) {
if (!rowState) {

@@ -934,3 +991,7 @@ return rowState;

if (rowState.children[params.columnIndex]) {
rowState.children[params.columnIndex].remove();
removeFromDom({
item: rowState.children[params.columnIndex],
rowIndex: rowIndex,
columnIndex: params.columnIndex
});
}

@@ -1003,3 +1064,3 @@ rowState.children.splice(params.columnIndex, 1);

renderManager.rowStates.splice(params.rowIndex, 0, rowState);
renderStateX(row, rowState, {});
renderStateX(row, rowState, {}, rowIndex);
}

@@ -1099,2 +1160,12 @@

/*
Callbacks
*/
onBeforeRowRemoved: {type: 'function', default: function (params) {
return true;
}},
onBeforeColumnRemoved: {type: 'function', default: function (params) {
return true;
}},
dynamicRowHeight: {type: 'boolean', default: false},

@@ -1314,3 +1385,3 @@ dynamicColumnWidth: {type: 'boolean', default: false},

return internalPromise.then(function (data) {
return (_.isArray(data) && data[params.index]) || undefined;
return (_.isArray(data) && data[params.index - range.start]) || undefined;
});

@@ -1317,0 +1388,0 @@ };

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc