Skip to content

Commit 8b9918c

Browse files
chore(all): prepare release 0.4.2
1 parent 6f2958b commit 8b9918c

22 files changed

+672
-432
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aurelia-ui-virtualization",
3-
"version": "0.4.1",
3+
"version": "0.4.2",
44
"description": "A plugin that provides a virtualized repeater and other virtualization services.",
55
"keywords": [
66
"aurelia",

dist/amd/aurelia-ui-virtualization.d.ts

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ declare module 'aurelia-ui-virtualization' {
1010
import {
1111
ArrayRepeatStrategy
1212
} from 'aurelia-templating-resources/array-repeat-strategy';
13+
import {
14+
DOM
15+
} from 'aurelia-pal';
1316
import {
1417
RepeatStrategyLocator
1518
} from 'aurelia-templating-resources/repeat-strategy-locator';
@@ -33,60 +36,72 @@ declare module 'aurelia-ui-virtualization' {
3336
import {
3437
viewsRequireLifecycle
3538
} from 'aurelia-templating-resources/analyze-view-factory';
36-
export function calcOuterHeight(element: any): any;
37-
export function insertBeforeNode(view: any, bottomBuffer: any): any;
39+
export interface ViewStrategy {
40+
getScrollContainer(element: Element): Element;
41+
moveViewFirst(view: View, topBuffer: Element): void;
42+
moveViewLast(view: View, bottomBuffer: Element): void;
43+
createTopBufferElement(element: Element): Element;
44+
createBottomBufferElement(element: Element): Element;
45+
removeBufferElements(element: Element, topBuffer: Element, bottomBuffer: Element): void;
46+
}
47+
export class DomHelper {
48+
getElementDistanceToTopViewPort(element: Element): number;
49+
hasOverflowScroll(element: Element): boolean;
50+
}
51+
export function calcOuterHeight(element: Element): number;
52+
export function insertBeforeNode(view: View, bottomBuffer: number): void;
3853

3954
/**
4055
* Update the override context.
4156
* @param startIndex index in collection where to start updating.
4257
*/
43-
export function updateVirtualOverrideContexts(repeat: any, startIndex: any): any;
58+
export function updateVirtualOverrideContexts(repeat: VirtualRepeat, startIndex: number): void;
4459
export function rebindAndMoveView(repeat: VirtualRepeat, view: View, index: number, moveToBottom: boolean): void;
45-
export function getStyleValue(element: any, style: any): any;
46-
export function getElementDistanceToBottomViewPort(element: any): any;
47-
export function getElementDistanceToTopViewPort(element: any): any;
60+
export function getStyleValue(element: Element, style: string): any;
61+
export function getElementDistanceToBottomViewPort(element: Element): number;
62+
export function getElementDistanceToTopViewPort(element: Element): number;
4863

4964
/**
5065
* A strategy for repeating a template over an array.
5166
*/
5267
export class ArrayVirtualRepeatStrategy extends ArrayRepeatStrategy {
5368

5469
// create first item to calculate the heights
55-
createFirstItem(repeat: any): any;
70+
createFirstItem(repeat: VirtualRepeat): void;
5671

5772
/**
5873
* Handle the repeat's collection instance changing.
5974
* @param repeat The repeater instance.
6075
* @param items The new array instance.
6176
*/
62-
instanceChanged(repeat: any, items: any): any;
77+
instanceChanged(repeat: VirtualRepeat, items: Array<any>): void;
6378

6479
/**
6580
* Handle the repeat's collection instance mutating.
6681
* @param repeat The repeat instance.
6782
* @param array The modified array.
6883
* @param splices Records of array changes.
6984
*/
70-
instanceMutated(repeat: any, array: any, splices: any): any;
85+
instanceMutated(repeat: VirtualRepeat, array: Array<any>, splices: any): void;
7186
}
7287
export class ViewStrategyLocator {
73-
getStrategy(element: any): any;
88+
getStrategy(element: Element): ViewStrategy;
7489
}
7590
export class TableStrategy {
76-
getScrollContainer(element: any): any;
77-
moveViewFirst(view: any, topBuffer: any): any;
78-
moveViewLast(view: any, bottomBuffer: any): any;
79-
createTopBufferElement(element: any): any;
80-
createBottomBufferElement(element: any): any;
81-
removeBufferElements(element: any, topBuffer: any, bottomBuffer: any): any;
91+
getScrollContainer(element: Element): Element;
92+
moveViewFirst(view: View, topBuffer: Element): void;
93+
moveViewLast(view: View, bottomBuffer: Element): void;
94+
createTopBufferElement(element: Element): Element;
95+
createBottomBufferElement(element: Element): Element;
96+
removeBufferElements(element: Element, topBuffer: Element, bottomBuffer: Element): void;
8297
}
83-
export class DefaultStrategy {
84-
getScrollContainer(element: any): any;
85-
moveViewFirst(view: any, topBuffer: any): any;
86-
moveViewLast(view: any, bottomBuffer: any): any;
87-
createTopBufferElement(element: any): any;
88-
createBottomBufferElement(element: any): any;
89-
removeBufferElements(element: any, topBuffer: any, bottomBuffer: any): any;
98+
export class DefaultViewStrategy {
99+
getScrollContainer(element: Element): Element;
100+
moveViewFirst(view: View, topBuffer: Element): void;
101+
moveViewLast(view: View, bottomBuffer: Element): void;
102+
createTopBufferElement(element: Element): Element;
103+
createBottomBufferElement(element: Element): Element;
104+
removeBufferElements(element: Element, topBuffer: Element, bottomBuffer: Element): void;
90105
}
91106
export class VirtualRepeatStrategyLocator extends RepeatStrategyLocator {
92107
constructor();
@@ -109,15 +124,15 @@ declare module 'aurelia-ui-virtualization' {
109124
_isAtTop: any;
110125
items: any;
111126
local: any;
112-
constructor(element: any, viewFactory: any, instruction: any, viewSlot: any, observerLocator: any, strategyLocator: any, viewStrategyLocator: any);
113-
attached(): any;
114-
bind(bindingContext: any, overrideContext: any): any;
115-
call(context: any, changes: any): any;
116-
detached(): any;
117-
itemsChanged(): any;
118-
unbind(): any;
119-
handleCollectionMutated(collection: any, changes: any): any;
120-
handleInnerCollectionMutated(collection: any, changes: any): any;
127+
constructor(element: Element, viewFactory: BoundViewFactory, instruction: TargetInstruction, viewSlot: ViewSlot, observerLocator: ObserverLocator, strategyLocator: VirtualRepeatStrategyLocator, viewStrategyLocator: ViewStrategyLocator, domHelper: DomHelper);
128+
attached(): void;
129+
bind(bindingContext: any, overrideContext: any): void;
130+
call(context: any, changes: any): void;
131+
detached(): void;
132+
itemsChanged(): void;
133+
unbind(): void;
134+
handleCollectionMutated(collection: any, changes: any): void;
135+
handleInnerCollectionMutated(collection: any, changes: any): void;
121136

122137
// @override AbstractRepeater
123138
viewCount(): any;

dist/amd/dom-helper.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
define(['exports'], function (exports) {
2+
'use strict';
3+
4+
Object.defineProperty(exports, "__esModule", {
5+
value: true
6+
});
7+
8+
function _classCallCheck(instance, Constructor) {
9+
if (!(instance instanceof Constructor)) {
10+
throw new TypeError("Cannot call a class as a function");
11+
}
12+
}
13+
14+
var DomHelper = exports.DomHelper = function () {
15+
function DomHelper() {
16+
_classCallCheck(this, DomHelper);
17+
}
18+
19+
DomHelper.prototype.getElementDistanceToTopViewPort = function getElementDistanceToTopViewPort(element) {
20+
return element.getBoundingClientRect().top;
21+
};
22+
23+
DomHelper.prototype.hasOverflowScroll = function hasOverflowScroll(element) {
24+
var style = element.style;
25+
return style.overflowY === 'scroll' || style.overflow === 'scroll' || style.overflowY === 'auto' || style.overflow === 'auto';
26+
};
27+
28+
return DomHelper;
29+
}();
30+
});

dist/amd/view-strategy.js

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
define(['exports', './utilities'], function (exports, _utilities) {
1+
define(['exports', 'aurelia-pal', './utilities'], function (exports, _aureliaPal, _utilities) {
22
'use strict';
33

44
Object.defineProperty(exports, "__esModule", {
55
value: true
66
});
7-
exports.DefaultStrategy = exports.TableStrategy = exports.ViewStrategyLocator = undefined;
7+
exports.DefaultViewStrategy = exports.TableStrategy = exports.ViewStrategyLocator = undefined;
88

99
function _classCallCheck(instance, Constructor) {
1010
if (!(instance instanceof Constructor)) {
@@ -18,10 +18,10 @@ define(['exports', './utilities'], function (exports, _utilities) {
1818
}
1919

2020
ViewStrategyLocator.prototype.getStrategy = function getStrategy(element) {
21-
if (element.parentNode.localName === 'tbody') {
21+
if (element.parentNode && element.parentNode.localName === 'tbody') {
2222
return new TableStrategy();
2323
}
24-
return new DefaultStrategy();
24+
return new DefaultViewStrategy();
2525
};
2626

2727
return ViewStrategyLocator;
@@ -37,79 +37,79 @@ define(['exports', './utilities'], function (exports, _utilities) {
3737
};
3838

3939
TableStrategy.prototype.moveViewFirst = function moveViewFirst(view, topBuffer) {
40-
(0, _utilities.insertBeforeNode)(view, topBuffer.parentElement.nextElementSibling.previousSibling);
40+
(0, _utilities.insertBeforeNode)(view, _aureliaPal.DOM.nextElementSibling(topBuffer.parentNode).previousSibling);
4141
};
4242

4343
TableStrategy.prototype.moveViewLast = function moveViewLast(view, bottomBuffer) {
44-
(0, _utilities.insertBeforeNode)(view, bottomBuffer.parentElement);
44+
(0, _utilities.insertBeforeNode)(view, bottomBuffer.parentNode);
4545
};
4646

4747
TableStrategy.prototype.createTopBufferElement = function createTopBufferElement(element) {
48-
var tr = document.createElement('tr');
49-
var buffer = document.createElement('td');
48+
var tr = _aureliaPal.DOM.createElement('tr');
49+
var buffer = _aureliaPal.DOM.createElement('td');
5050
buffer.setAttribute('style', 'height: 0px');
5151
tr.appendChild(buffer);
52-
element.parentElement.insertBefore(tr, element);
52+
element.parentNode.insertBefore(tr, element);
5353
return buffer;
5454
};
5555

5656
TableStrategy.prototype.createBottomBufferElement = function createBottomBufferElement(element) {
57-
var tr = document.createElement('tr');
58-
var buffer = document.createElement('td');
57+
var tr = _aureliaPal.DOM.createElement('tr');
58+
var buffer = _aureliaPal.DOM.createElement('td');
5959
buffer.setAttribute('style', 'height: 0px');
6060
tr.appendChild(buffer);
6161
element.parentNode.insertBefore(tr, element.nextSibling);
6262
return buffer;
6363
};
6464

6565
TableStrategy.prototype.removeBufferElements = function removeBufferElements(element, topBuffer, bottomBuffer) {
66-
element.parentElement.removeChild(topBuffer.parentElement);
67-
element.parentElement.removeChild(bottomBuffer.parentElement);
66+
element.parentNode.removeChild(topBuffer.parentNode);
67+
element.parentNode.removeChild(bottomBuffer.parentNode);
6868
};
6969

7070
return TableStrategy;
7171
}();
7272

73-
var DefaultStrategy = exports.DefaultStrategy = function () {
74-
function DefaultStrategy() {
75-
_classCallCheck(this, DefaultStrategy);
73+
var DefaultViewStrategy = exports.DefaultViewStrategy = function () {
74+
function DefaultViewStrategy() {
75+
_classCallCheck(this, DefaultViewStrategy);
7676
}
7777

78-
DefaultStrategy.prototype.getScrollContainer = function getScrollContainer(element) {
78+
DefaultViewStrategy.prototype.getScrollContainer = function getScrollContainer(element) {
7979
return element.parentNode;
8080
};
8181

82-
DefaultStrategy.prototype.moveViewFirst = function moveViewFirst(view, topBuffer) {
83-
(0, _utilities.insertBeforeNode)(view, topBuffer.nextElementSibling.previousSibling);
82+
DefaultViewStrategy.prototype.moveViewFirst = function moveViewFirst(view, topBuffer) {
83+
(0, _utilities.insertBeforeNode)(view, _aureliaPal.DOM.nextElementSibling(topBuffer).previousSibling);
8484
};
8585

86-
DefaultStrategy.prototype.moveViewLast = function moveViewLast(view, bottomBuffer) {
86+
DefaultViewStrategy.prototype.moveViewLast = function moveViewLast(view, bottomBuffer) {
8787
var previousSibling = bottomBuffer.previousSibling;
8888
var referenceNode = previousSibling.nodeType === 8 && previousSibling.data === 'anchor' ? previousSibling : bottomBuffer;
8989
(0, _utilities.insertBeforeNode)(view, referenceNode);
9090
};
9191

92-
DefaultStrategy.prototype.createTopBufferElement = function createTopBufferElement(element) {
93-
var elementName = element.parentElement.localName === 'ul' ? 'li' : 'div';
94-
var buffer = document.createElement(elementName);
92+
DefaultViewStrategy.prototype.createTopBufferElement = function createTopBufferElement(element) {
93+
var elementName = element.parentNode.localName === 'ul' ? 'li' : 'div';
94+
var buffer = _aureliaPal.DOM.createElement(elementName);
9595
buffer.setAttribute('style', 'height: 0px');
96-
element.parentElement.insertBefore(buffer, element);
96+
element.parentNode.insertBefore(buffer, element);
9797
return buffer;
9898
};
9999

100-
DefaultStrategy.prototype.createBottomBufferElement = function createBottomBufferElement(element) {
101-
var elementName = element.parentElement.localName === 'ul' ? 'li' : 'div';
102-
var buffer = document.createElement(elementName);
100+
DefaultViewStrategy.prototype.createBottomBufferElement = function createBottomBufferElement(element) {
101+
var elementName = element.parentNode.localName === 'ul' ? 'li' : 'div';
102+
var buffer = _aureliaPal.DOM.createElement(elementName);
103103
buffer.setAttribute('style', 'height: 0px');
104104
element.parentNode.insertBefore(buffer, element.nextSibling);
105105
return buffer;
106106
};
107107

108-
DefaultStrategy.prototype.removeBufferElements = function removeBufferElements(element, topBuffer, bottomBuffer) {
109-
element.parentElement.removeChild(topBuffer);
110-
element.parentElement.removeChild(bottomBuffer);
108+
DefaultViewStrategy.prototype.removeBufferElements = function removeBufferElements(element, topBuffer, bottomBuffer) {
109+
element.parentNode.removeChild(topBuffer);
110+
element.parentNode.removeChild(bottomBuffer);
111111
};
112112

113-
return DefaultStrategy;
113+
return DefaultViewStrategy;
114114
}();
115115
});

dist/amd/virtual-repeat.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
define(['exports', 'aurelia-dependency-injection', 'aurelia-binding', 'aurelia-templating', 'aurelia-templating-resources', 'aurelia-templating-resources/repeat-utilities', 'aurelia-templating-resources/analyze-view-factory', './utilities', './virtual-repeat-strategy-locator', './view-strategy'], function (exports, _aureliaDependencyInjection, _aureliaBinding, _aureliaTemplating, _aureliaTemplatingResources, _repeatUtilities, _analyzeViewFactory, _utilities, _virtualRepeatStrategyLocator, _viewStrategy) {
1+
define(['exports', 'aurelia-dependency-injection', 'aurelia-binding', 'aurelia-templating', 'aurelia-templating-resources', 'aurelia-templating-resources/repeat-utilities', 'aurelia-templating-resources/analyze-view-factory', 'aurelia-pal', './utilities', './dom-helper', './virtual-repeat-strategy-locator', './view-strategy'], function (exports, _aureliaDependencyInjection, _aureliaBinding, _aureliaTemplating, _aureliaTemplatingResources, _repeatUtilities, _analyzeViewFactory, _aureliaPal, _utilities, _domHelper, _virtualRepeatStrategyLocator, _viewStrategy) {
22
'use strict';
33

44
Object.defineProperty(exports, "__esModule", {
@@ -81,10 +81,10 @@ define(['exports', 'aurelia-dependency-injection', 'aurelia-binding', 'aurelia-t
8181

8282
var _dec, _dec2, _class, _desc, _value, _class2, _descriptor, _descriptor2;
8383

84-
var VirtualRepeat = exports.VirtualRepeat = (_dec = (0, _aureliaTemplating.customAttribute)('virtual-repeat'), _dec2 = (0, _aureliaDependencyInjection.inject)(Element, _aureliaTemplating.BoundViewFactory, _aureliaTemplating.TargetInstruction, _aureliaTemplating.ViewSlot, _aureliaBinding.ObserverLocator, _virtualRepeatStrategyLocator.VirtualRepeatStrategyLocator, _viewStrategy.ViewStrategyLocator), _dec(_class = (0, _aureliaTemplating.templateController)(_class = _dec2(_class = (_class2 = function (_AbstractRepeater) {
84+
var VirtualRepeat = exports.VirtualRepeat = (_dec = (0, _aureliaTemplating.customAttribute)('virtual-repeat'), _dec2 = (0, _aureliaDependencyInjection.inject)(_aureliaPal.DOM.Element, _aureliaTemplating.BoundViewFactory, _aureliaTemplating.TargetInstruction, _aureliaTemplating.ViewSlot, _aureliaBinding.ObserverLocator, _virtualRepeatStrategyLocator.VirtualRepeatStrategyLocator, _viewStrategy.ViewStrategyLocator, _domHelper.DomHelper), _dec(_class = (0, _aureliaTemplating.templateController)(_class = _dec2(_class = (_class2 = function (_AbstractRepeater) {
8585
_inherits(VirtualRepeat, _AbstractRepeater);
8686

87-
function VirtualRepeat(element, viewFactory, instruction, viewSlot, observerLocator, strategyLocator, viewStrategyLocator) {
87+
function VirtualRepeat(element, viewFactory, instruction, viewSlot, observerLocator, strategyLocator, viewStrategyLocator, domHelper) {
8888
_classCallCheck(this, VirtualRepeat);
8989

9090
var _this = _possibleConstructorReturn(this, _AbstractRepeater.call(this, {
@@ -121,6 +121,7 @@ define(['exports', 'aurelia-dependency-injection', 'aurelia-binding', 'aurelia-t
121121
_this.viewStrategyLocator = viewStrategyLocator;
122122
_this.sourceExpression = (0, _repeatUtilities.getItemsSourceExpression)(_this.instruction, 'virtual-repeat.for');
123123
_this.isOneTime = (0, _repeatUtilities.isOneTime)(_this.sourceExpression);
124+
_this.domHelper = domHelper;
124125
return _this;
125126
}
126127

@@ -129,6 +130,7 @@ define(['exports', 'aurelia-dependency-injection', 'aurelia-binding', 'aurelia-t
129130

130131
this._isAttached = true;
131132
var element = this.element;
133+
this._itemsLength = this.items.length;
132134
this.viewStrategy = this.viewStrategyLocator.getStrategy(element);
133135
this.scrollContainer = this.viewStrategy.getScrollContainer(element);
134136
this.topBuffer = this.viewStrategy.createTopBufferElement(element);
@@ -137,9 +139,8 @@ define(['exports', 'aurelia-dependency-injection', 'aurelia-binding', 'aurelia-t
137139
this.scrollListener = function () {
138140
return _this2._onScroll();
139141
};
140-
this.distanceToTop = (0, _utilities.getElementDistanceToTopViewPort)(this.topBuffer.nextElementSibling);
141-
var containerStyle = this.scrollContainer.style;
142-
if (containerStyle.overflowY === 'scroll' || containerStyle.overflow === 'scroll' || containerStyle.overflowY === 'auto' || containerStyle.overflow === 'auto') {
142+
this.distanceToTop = this.domHelper.getElementDistanceToTopViewPort(_aureliaPal.DOM.nextElementSibling(this.topBuffer));
143+
if (this.domHelper.hasOverflowScroll(this.scrollContainer)) {
143144
this._fixedHeightContainer = true;
144145
this.scrollContainer.addEventListener('scroll', this.scrollListener);
145146
} else {
@@ -149,7 +150,6 @@ define(['exports', 'aurelia-dependency-injection', 'aurelia-binding', 'aurelia-t
149150

150151
VirtualRepeat.prototype.bind = function bind(bindingContext, overrideContext) {
151152
this.scope = { bindingContext: bindingContext, overrideContext: overrideContext };
152-
this._itemsLength = this.items.length;
153153
};
154154

155155
VirtualRepeat.prototype.call = function call(context, changes) {
@@ -384,7 +384,7 @@ define(['exports', 'aurelia-dependency-injection', 'aurelia-binding', 'aurelia-t
384384
}
385385
this._hasCalculatedSizes = true;
386386
this._itemsLength = itemsLength;
387-
var firstViewElement = this.view(0).firstChild.nextElementSibling;
387+
var firstViewElement = _aureliaPal.DOM.nextElementSibling(this.view(0).firstChild);
388388
this.itemHeight = (0, _utilities.calcOuterHeight)(firstViewElement);
389389
if (this.itemHeight <= 0) {
390390
throw new Error('Could not calculate item height');

0 commit comments

Comments
 (0)