@html-next/vertical-collection 2.0.1 → 3.0.0-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,16 +6,17 @@ on:
6
6
  jobs:
7
7
  test:
8
8
  name: Run Tests
9
- runs-on: ubuntu-18.04
9
+ runs-on: ubuntu-latest
10
+ timeout-minutes: 12
10
11
 
11
12
  steps:
12
13
  - name: Checkout
13
14
  uses: actions/checkout@v2
14
15
 
15
- - name: Use Node 12
16
+ - name: Use Node 14
16
17
  uses: actions/setup-node@v2-beta
17
18
  with:
18
- node-version: 12.x
19
+ node-version: 14.x
19
20
 
20
21
  - name: Node Modules Cache
21
22
  uses: actions/cache@v2
@@ -30,25 +31,28 @@ jobs:
30
31
  run: yarn lint
31
32
 
32
33
  - name: Run Tests
33
- run: yarn test:ember
34
+ run: bin/run-tests-with-retry.sh
34
35
  env:
35
36
  CI: true
36
37
 
37
38
  test-ember-try:
38
39
  name: Run Tests
39
- runs-on: ubuntu-18.04
40
+ runs-on: ubuntu-latest
41
+ timeout-minutes: 14
42
+
40
43
  strategy:
44
+ fail-fast: false
41
45
  matrix:
42
46
  ember-version:
43
47
  [
44
- ember-lts-2.8,
45
- ember-lts-2.12,
46
48
  ember-lts-2.18,
47
49
  ember-lts-3.4,
48
50
  ember-lts-3.8,
49
51
  ember-lts-3.12,
50
52
  ember-lts-3.16,
51
53
  ember-lts-3.20,
54
+ ember-lts-3.24,
55
+ ember-lts-3.28,
52
56
  ember-release,
53
57
  ember-beta,
54
58
  ember-canary,
@@ -58,10 +62,10 @@ jobs:
58
62
  - name: Checkout
59
63
  uses: actions/checkout@v2
60
64
 
61
- - name: Use Node 12
65
+ - name: Use Node 14
62
66
  uses: actions/setup-node@v2-beta
63
67
  with:
64
- node-version: 12.x
68
+ node-version: 14.x
65
69
 
66
70
  - name: Node Modules Cache
67
71
  uses: actions/cache@v2
@@ -73,4 +77,4 @@ jobs:
73
77
  run: yarn install --frozen-lockfile --ignore-engines
74
78
 
75
79
  - name: Run Tests
76
- run: node_modules/.bin/ember try:one ${{ matrix.ember-version }} --skip-cleanup
80
+ run: node_modules/.bin/ember try:one ${{ matrix.ember-version }} --skip-cleanup --- bin/run-tests-with-retry.sh
package/CHANGELOG.md CHANGED
@@ -1,6 +1,31 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ ## v3.0.0-1 (2022-03-01)
5
+
6
+
7
+ ## v3.0.0-0 (2021-12-09)
8
+
9
+ #### What's new
10
+
11
+ * Drop support for Ember < 2.18, add support for Ember 4.0+ (#343) (3343ecc)
12
+ * 4 retries on CI, 1s sleep (#352) (4a75d99)
13
+ * Extend timeout for base tests, tweak retry (#351) (8fff4c7)
14
+ * Remove implicit this in tests (#349) (5f58de6)
15
+
16
+
17
+ ## v2.1.0 (2021-12-09)
18
+
19
+ Changelog:
20
+
21
+ * Upgrade ember-cli and dev deps (#348) (e8924e9)
22
+ * Drop Ember global use in favor of native API (#347) (d101d8a)
23
+ * Proper runloop imports (#346) (a765241)
24
+ * Remove property fallback lookup (no implicit this) (#345) (506d798)
25
+ * Modernize `htmlSafe` module imports / More cleanup (#344) (32e9460)
26
+ * Update CI for vertical-collection v2 (#342) (5613faa)
27
+
28
+
4
29
  ## v2.0.1 (2021-12-07)
5
30
 
6
31
  #### :bug: Bug Fix
package/README.md CHANGED
@@ -62,10 +62,11 @@ ember install @html-next/vertical-collection
62
62
 
63
63
  ## Support Matrix
64
64
 
65
- | `vertical-collection` version | Supported Ember versions |
66
- | ----------------------------- | ------------------------ |
67
- | `^v1.0.0` | `v1.12.0 - v3.8.0` |
68
- | `^v2.0.0` | `v2.8.0+` |
65
+ | `vertical-collection` version | Supported Ember versions | Supported Node versions |
66
+ | ----------------------------- | ------------------------ | ----------------------- |
67
+ | `^v1.x.x` | `v1.12.0 - v3.8.x` | `?` |
68
+ | `^v2.x.x` | `v2.8.0 - v3.26.x` | `v12 - ?` |
69
+ | `^v3.x.x` | `v2.18.0+` | `v14+` |
69
70
 
70
71
  ## Support, Questions, Collaboration
71
72
 
@@ -1,4 +1,3 @@
1
- /* global document */
2
1
  import { ViewportContainer } from '../../-private';
3
2
 
4
3
  function applyVerticalStyles(element, geography) {
@@ -22,7 +22,7 @@ export function ViewportContainer() {
22
22
  || document.documentElement.scrollTop;
23
23
  },
24
24
  set(v) {
25
- return document.body.scrollTop = document.documentElement.scrollTop = v;
25
+ document.body.scrollTop = document.documentElement.scrollTop = v;
26
26
  }
27
27
  });
28
28
 
@@ -34,7 +34,7 @@ export function ViewportContainer() {
34
34
  || document.documentElement.scrollLeft;
35
35
  },
36
36
  set(v) {
37
- return window.scrollX
37
+ window.scrollX
38
38
  = window.pageXOffset
39
39
  = document.body.scrollLeft
40
40
  = document.documentElement.scrollLeft = v;
@@ -32,14 +32,14 @@ export default class DynamicRadar extends Radar {
32
32
  this.skipList = null;
33
33
  }
34
34
 
35
- scheduleUpdate(didUpdateItems) {
35
+ scheduleUpdate(didUpdateItems, promiseResolve) {
36
36
  // Cancel incremental render check, since we'll be remeasuring anyways
37
37
  if (this._nextIncrementalRender !== null) {
38
38
  this._nextIncrementalRender.cancel();
39
39
  this._nextIncrementalRender = null;
40
40
  }
41
41
 
42
- super.scheduleUpdate(didUpdateItems);
42
+ super.scheduleUpdate(didUpdateItems, promiseResolve);
43
43
  }
44
44
 
45
45
  afterUpdate() {
@@ -105,6 +105,7 @@ export default class Radar {
105
105
 
106
106
  this._componentPool = [];
107
107
  this._prependComponentPool = [];
108
+ this._appendComponentPool = []; // https://github.com/html-next/vertical-collection/issues/296
108
109
 
109
110
  // Boundaries
110
111
  this._occludedContentBefore = new OccludedContent(occlusionTagName);
@@ -223,7 +224,7 @@ export default class Radar {
223
224
  *
224
225
  * @private
225
226
  */
226
- scheduleUpdate(didUpdateItems) {
227
+ scheduleUpdate(didUpdateItems, promiseResolve) {
227
228
  if (didUpdateItems === true) {
228
229
  // Set the update items flag first, in case scheduleUpdate has already been called
229
230
  // but the RAF hasn't yet run
@@ -238,11 +239,11 @@ export default class Radar {
238
239
  this._nextUpdate = null;
239
240
  this._scrollTop = this._scrollContainer.scrollTop;
240
241
 
241
- this.update();
242
+ this.update(promiseResolve);
242
243
  });
243
244
  }
244
245
 
245
- update() {
246
+ update(promiseResolve) {
246
247
  if (this._didUpdateItems === true) {
247
248
  this._determineUpdateType();
248
249
  this._didUpdateItems = false;
@@ -252,7 +253,12 @@ export default class Radar {
252
253
  this._updateIndexes();
253
254
  this._updateVirtualComponents();
254
255
 
255
- this.schedule('measure', this.afterUpdate.bind(this));
256
+ this.schedule('measure', () => {
257
+ if (promiseResolve) {
258
+ promiseResolve();
259
+ }
260
+ this.afterUpdate();
261
+ });
256
262
  }
257
263
 
258
264
  afterUpdate() {
@@ -554,6 +560,8 @@ export default class Radar {
554
560
  const {
555
561
  virtualComponents,
556
562
  _occludedContentAfter,
563
+ _appendComponentPool,
564
+ shouldRecycle,
557
565
  _itemContainer
558
566
  } = this;
559
567
 
@@ -564,6 +572,29 @@ export default class Radar {
564
572
  } else {
565
573
  virtualComponents.insertAt(virtualComponents.get('length') - 1, component);
566
574
  component.rendered = true;
575
+
576
+ // shouldRecycle=false breaks UI when scrolling the elements fast.
577
+ // Reference https://github.com/html-next/vertical-collection/issues/296
578
+ // Components that are both new and appended still need to be rendered at the end because Glimmer.
579
+ // We have to move them _after_ they render, so we schedule that if they exist
580
+ if(!shouldRecycle) {
581
+ _appendComponentPool.unshift(component);
582
+
583
+ if (this._nextLayout === null) {
584
+ this._nextLayout = this.schedule('layout', () => {
585
+ this._nextLayout = null;
586
+
587
+ while (_appendComponentPool.length > 0) {
588
+ const component = _appendComponentPool.pop();
589
+
590
+ // Changes with each inserted component
591
+ const relativeNode = _occludedContentAfter.realUpperBound;
592
+
593
+ insertRangeBefore(this._itemContainer, relativeNode, component.realUpperBound, component.realLowerBound);
594
+ }
595
+ });
596
+ }
597
+ }
567
598
  }
568
599
  }
569
600
 
@@ -1,4 +1,4 @@
1
- import { run } from '@ember/runloop';
1
+ import { begin, end } from '@ember/runloop';
2
2
  import { scheduler } from 'ember-raf-scheduler';
3
3
  import SUPPORTS_PASSIVE from './supports-passive';
4
4
  const DEFAULT_ARRAY_SIZE = 10;
@@ -110,11 +110,11 @@ export class ScrollHandler {
110
110
 
111
111
  // TODO add explicit test
112
112
  if (topChanged || leftChanged) {
113
- run.begin();
113
+ begin();
114
114
  for (let j = 0; j < meta.handlers.length; j++) {
115
115
  meta.handlers[j](event);
116
116
  }
117
- run.end();
117
+ end();
118
118
  }
119
119
  }
120
120
 
@@ -22,7 +22,7 @@ export function ViewportContainer() {
22
22
  || document.documentElement.scrollTop;
23
23
  },
24
24
  set(v) {
25
- return document.body.scrollTop = document.documentElement.scrollTop = v;
25
+ document.body.scrollTop = document.documentElement.scrollTop = v;
26
26
  }
27
27
  });
28
28
 
@@ -34,7 +34,7 @@ export function ViewportContainer() {
34
34
  || document.documentElement.scrollLeft;
35
35
  },
36
36
  set(v) {
37
- return window.scrollX
37
+ window.scrollX
38
38
  = window.pageXOffset
39
39
  = document.body.scrollLeft
40
40
  = document.documentElement.scrollLeft = v;
@@ -200,6 +200,24 @@ const VerticalCollection = Component.extend({
200
200
  }
201
201
  },
202
202
 
203
+ /* Public API Methods
204
+ @index => number
205
+ This will return offset height of the indexed item.
206
+ */
207
+ scrollToItem(index) {
208
+ const { _radar } = this;
209
+ // Getting the offset height from Radar
210
+ let scrollTop = _radar.getOffsetForIndex(index);
211
+ _radar._scrollContainer.scrollTop = scrollTop;
212
+ // To scroll exactly to specified index, we are changing the prevIndex values to specified index
213
+ _radar._prevFirstVisibleIndex = _radar._prevFirstItemIndex = index;
214
+ // Components will be rendered after schedule 'measure' inside 'update' method.
215
+ // In our case, we need to focus the element after component is rendered. So passing the promise.
216
+ return new Promise ((resolve) => {
217
+ _radar.scheduleUpdate(false, resolve);
218
+ });
219
+ },
220
+
203
221
  // –––––––––––––– Setup/Teardown
204
222
  didInsertElement() {
205
223
  this.schedule('sync', () => {
@@ -210,6 +228,10 @@ const VerticalCollection = Component.extend({
210
228
  willDestroy() {
211
229
  this.token.cancel();
212
230
  this._radar.destroy();
231
+ let registerAPI = this.get('registerAPI');
232
+ if (registerAPI) {
233
+ registerAPI(null);
234
+ }
213
235
  clearTimeout(this._nextSendActions);
214
236
  },
215
237
 
@@ -280,6 +302,43 @@ const VerticalCollection = Component.extend({
280
302
  }
281
303
  };
282
304
  }
305
+
306
+ /* Public methods to Expose to parent
307
+
308
+ Usage:
309
+
310
+ Template:
311
+
312
+ {{vertical-collection registerAPI=(action "registerAPI")}}
313
+
314
+ Component:
315
+
316
+ export default Component.extend({
317
+ actions: {
318
+ registerAPI(api) {
319
+ this.set('collectionAPI', api);
320
+ }
321
+ },
322
+ scrollToItem() {
323
+ let collectionAPI = this.get('collectionAPI');
324
+ collectionAPI.scrollToItem(index);
325
+ }
326
+ });
327
+
328
+ Need to pass this property in the vertical-collection template
329
+ Listen in the component actions and do your custom logic
330
+ This API will have below methods.
331
+ 1. scrollToItem
332
+ */
333
+
334
+ let registerAPI = get(this, 'registerAPI');
335
+ if (registerAPI) {
336
+ /* List of methods to be exposed to public should be added here */
337
+ let publicAPI = {
338
+ scrollToItem: this.scrollToItem.bind(this)
339
+ };
340
+ registerAPI(publicAPI);
341
+ }
283
342
  }
284
343
  });
285
344
 
@@ -307,4 +366,4 @@ function calculateStartingIndex(items, idForFirstItem, key, renderFromLast) {
307
366
  return startingIndex;
308
367
  }
309
368
 
310
- export default VerticalCollection;
369
+ export default VerticalCollection;
@@ -1,4 +1,4 @@
1
- {{#each virtualComponents key="id" as |virtualComponent| ~}}
1
+ {{#each this.virtualComponents key="id" as |virtualComponent| ~}}
2
2
  {{~unbound virtualComponent.upperBound~}}
3
3
  {{~#if virtualComponent.isOccludedContent ~}}
4
4
  {{{unbound virtualComponent.element}}}
@@ -8,6 +8,6 @@
8
8
  {{~unbound virtualComponent.lowerBound~}}
9
9
  {{~/each}}
10
10
 
11
- {{#if shouldYieldToInverse}}
11
+ {{#if this.shouldYieldToInverse}}
12
12
  {{yield to="inverse"}}
13
13
  {{/if}}
@@ -0,0 +1,27 @@
1
+ #!/bin/bash
2
+
3
+ function retry {
4
+ command="$*"
5
+ retval=1
6
+ attempt=1
7
+ until [[ $retval -eq 0 ]] || [[ $attempt -gt 4 ]]; do
8
+ # Execute inside of a subshell in case parent
9
+ # script is running with "set -e"
10
+ (
11
+ set +e
12
+ $command
13
+ )
14
+ retval=$?
15
+ attempt=$(( $attempt + 1 ))
16
+ if [[ $retval -ne 0 ]]; then
17
+ # If there was an error wait 10 seconds
18
+ sleep 1
19
+ fi
20
+ done
21
+ if [[ $retval -ne 0 ]] && [[ $attempt -gt 4 ]]; then
22
+ # Something is fubar, go ahead and exit
23
+ exit $retval
24
+ fi
25
+ }
26
+
27
+ retry yarn test:ember
package/index.js CHANGED
@@ -32,6 +32,17 @@ module.exports = {
32
32
  return requiresModulesDir ? 'modules' : '';
33
33
  },
34
34
 
35
+ // Borrowed from ember-cli-babel
36
+ _emberVersionRequiresModulesAPIPolyfill() {
37
+ let checker = this.checker.for('ember-source', 'npm');
38
+
39
+ if (!checker.exists()) {
40
+ return true;
41
+ }
42
+
43
+ return checker.lt('3.27.0-alpha.1');
44
+ },
45
+
35
46
  treeForAddon(tree) {
36
47
  let babel = this.addons.find((addon) => addon.name === 'ember-cli-babel');
37
48
  let withPrivate = new Funnel(tree, { include: ['-private/**'] });
@@ -45,11 +56,39 @@ module.exports = {
45
56
  destDir: '@html-next/vertical-collection'
46
57
  });
47
58
 
59
+ // When compiling with `compileModules: false`, ember-cli-babel defaults to
60
+ // using the modules polyfill, since it assumes we are concatenating the
61
+ // output script using `app.import` without an AMD wrapper.
62
+ //
63
+ // This does not apply to us, since we are compiling the `-private` modules
64
+ // into a single AMD module (via rollup below), which can in fact have
65
+ // external dependencies.
66
+ //
67
+ // We can opt-out of this with `disableEmberModulesAPIPolyfill: true`. In
68
+ // Ember versions with "real modules", that is what we want in order to
69
+ // avoid the Ember global deprecation (or just completely not working in
70
+ // 4.0+).
71
+ //
72
+ // It seems like the intent may have been that we should be able to set
73
+ // this to `true` unconditionally, and `ember-cli-babel` will ignore this
74
+ // setting if the Ember verion requires the modules API polyfill. However,
75
+ // presumably due to a bug, ember-cli-babel actually checks for this value
76
+ // first and return out of the function early if its value is truthy. This
77
+ // means that if we set this to true unconditionally, then we would have
78
+ // disabled the modules polyfill for Ember versions that needs it, which
79
+ // would be incorrect. Therefore, we have to duplicate the detection logic
80
+ // here in order to set this value appropriately.
81
+ //
82
+ // Ideally, we should just stop trying to rollup the -private modules and
83
+ // let the modern build pipeline optimizes things for us, then none of this
84
+ // would have been necessary.
48
85
  let privateTree = babel.transpileTree(withPrivate, {
49
86
  babel: this.options.babel,
50
87
  'ember-cli-babel': {
51
- compileModules: false
52
- }
88
+ compileModules: false,
89
+ disableEmberModulesAPIPolyfill:
90
+ !this._emberVersionRequiresModulesAPIPolyfill(),
91
+ },
53
92
  });
54
93
 
55
94
  const templateTree = new Funnel(tree, {
@@ -72,8 +111,13 @@ module.exports = {
72
111
  }
73
112
  }
74
113
  ],
75
- external: ['ember', 'ember-raf-scheduler']
76
- }
114
+ external(id) {
115
+ return (
116
+ id.startsWith('@ember/') ||
117
+ ['ember', 'ember-raf-scheduler'].includes(id)
118
+ );
119
+ },
120
+ },
77
121
  });
78
122
 
79
123
  let destDir = this.getOutputDirForVersion();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@html-next/vertical-collection",
3
- "version": "2.0.1",
3
+ "version": "3.0.0-1",
4
4
  "description": "infinite-scroll, done right. done.",
5
5
  "keywords": [
6
6
  "occlusion",
@@ -40,12 +40,13 @@
40
40
  "test": "tests"
41
41
  },
42
42
  "scripts": {
43
- "build": "ember build",
44
- "lint": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*",
45
- "lint:hbs": "ember-template-lint .",
46
- "lint:js": "eslint .",
43
+ "build": "ember build --environment=production",
44
+ "lint": "npm-run-all --aggregate-output --continue-on-error --parallel \"lint:!(fix)\"",
45
+ "lint:fix": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*:fix",
46
+ "lint:js": "eslint . --cache",
47
+ "lint:js:fix": "eslint . --fix",
47
48
  "start": "ember serve",
48
- "test": "npm-run-all lint:* test:*",
49
+ "test": "npm-run-all lint test:*",
49
50
  "test:ember": "ember test",
50
51
  "test:ember-compatibility": "ember try:each"
51
52
  },
@@ -55,48 +56,50 @@
55
56
  "broccoli-merge-trees": "^3.0.1",
56
57
  "broccoli-rollup": "^4.1.1",
57
58
  "ember-cli-babel": "^7.12.0",
58
- "ember-cli-htmlbars": "^3.0.1",
59
+ "ember-cli-htmlbars": "^5.0.0",
59
60
  "ember-cli-version-checker": "^3.1.3",
60
61
  "ember-compatibility-helpers": "^1.2.1",
61
- "ember-raf-scheduler": "0.2.0"
62
+ "ember-raf-scheduler": "^0.3.0"
62
63
  },
63
64
  "devDependencies": {
64
- "@ember/optional-features": "^0.7.0",
65
+ "@ember/optional-features": "^2.0.0",
66
+ "@ember/test-helpers": "^2.4.0",
67
+ "babel-eslint": "^10.1.0",
65
68
  "bootstrap": "~3.3.5",
66
69
  "broccoli-asset-rev": "^3.0.0",
67
- "ember-cli": "~3.12.0",
68
- "ember-cli-app-version": "^3.2.0",
69
- "ember-cli-dependency-checker": "^3.1.0",
70
+ "ember-auto-import": "^2.0.0",
71
+ "ember-cli": "~3.28.0",
72
+ "ember-cli-dependency-checker": "^3.2.0",
70
73
  "ember-cli-eslint": "^5.1.0",
71
74
  "ember-cli-fastboot": "^2.1.3",
72
75
  "ember-cli-github-pages": "^0.2.2",
73
- "ember-cli-htmlbars-inline-precompile": "^2.1.0",
74
- "ember-cli-inject-live-reload": "^2.0.1",
76
+ "ember-cli-inject-live-reload": "^2.1.0",
75
77
  "ember-cli-sri": "^2.1.1",
76
- "ember-cli-template-lint": "^1.0.0-beta.1",
77
- "ember-cli-uglify": "^3.0.0",
78
+ "ember-cli-terser": "^4.0.2",
78
79
  "ember-code-snippet": "^2.4.1",
79
- "ember-data": "3.11.5",
80
+ "ember-data": "~3.12.0",
80
81
  "ember-disable-prototype-extensions": "^1.1.3",
81
- "ember-export-application-global": "^2.0.0",
82
- "ember-load-initializers": "^2.0.0",
83
- "ember-native-dom-helpers": "^0.7.0",
84
- "ember-perf-timeline": "^1.2.1",
85
- "ember-qunit": "^4.5.1",
86
- "ember-resolver": "^5.0.1",
82
+ "ember-export-application-global": "^2.0.1",
83
+ "ember-load-initializers": "^2.1.2",
84
+ "ember-perf-timeline": "^2.0.0",
85
+ "ember-qunit": "^5.0.0",
86
+ "ember-resolver": "^8.0.2",
87
87
  "ember-source": "~3.12.0",
88
- "ember-source-channel-url": "^2.0.1",
89
- "ember-try": "^1.2.1",
88
+ "ember-source-channel-url": "^3.0.0",
89
+ "ember-try": "^1.4.0",
90
+ "eslint": "^7.32.0",
90
91
  "eslint-plugin-ember": "^6.7.1",
91
92
  "eslint-plugin-node": "^9.1.0",
92
93
  "loader.js": "^4.7.0",
93
94
  "npm-run-all": "^4.1.5",
94
- "qunit-dom": "^0.9.0",
95
+ "qunit": "^2.0.0",
96
+ "qunit-dom": "^1.0.0",
95
97
  "release-it": "^14.2.1",
96
- "release-it-lerna-changelog": "^3.1.0"
98
+ "release-it-lerna-changelog": "^3.1.0",
99
+ "webpack": "^5.0.0"
97
100
  },
98
101
  "engines": {
99
- "node": ">= 10.*"
102
+ "node": ">= 14.*"
100
103
  },
101
104
  "publishConfig": {
102
105
  "registry": "https://registry.npmjs.org"
@@ -118,5 +121,9 @@
118
121
  "release": true,
119
122
  "tokenRef": "GITHUB_AUTH"
120
123
  }
124
+ },
125
+ "volta": {
126
+ "node": "14.18.2",
127
+ "yarn": "1.22.17"
121
128
  }
122
129
  }