@html-next/vertical-collection 2.1.0 → 3.0.0

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.
@@ -7,16 +7,16 @@ jobs:
7
7
  test:
8
8
  name: Run Tests
9
9
  runs-on: ubuntu-latest
10
- timeout-minutes: 6
10
+ timeout-minutes: 12
11
11
 
12
12
  steps:
13
13
  - name: Checkout
14
14
  uses: actions/checkout@v2
15
15
 
16
- - name: Use Node 12
16
+ - name: Use Node 14
17
17
  uses: actions/setup-node@v2-beta
18
18
  with:
19
- node-version: 12.x
19
+ node-version: 14.x
20
20
 
21
21
  - name: Node Modules Cache
22
22
  uses: actions/cache@v2
@@ -31,22 +31,20 @@ jobs:
31
31
  run: yarn lint
32
32
 
33
33
  - name: Run Tests
34
- run: yarn test:ember
34
+ run: bin/run-tests-with-retry.sh
35
35
  env:
36
36
  CI: true
37
37
 
38
38
  test-ember-try:
39
39
  name: Run Tests
40
40
  runs-on: ubuntu-latest
41
- timeout-minutes: 10
41
+ timeout-minutes: 14
42
42
 
43
43
  strategy:
44
44
  fail-fast: false
45
45
  matrix:
46
46
  ember-version:
47
47
  [
48
- ember-lts-2.8,
49
- ember-lts-2.12,
50
48
  ember-lts-2.18,
51
49
  ember-lts-3.4,
52
50
  ember-lts-3.8,
@@ -54,17 +52,20 @@ jobs:
54
52
  ember-lts-3.16,
55
53
  ember-lts-3.20,
56
54
  ember-lts-3.24,
57
- ember-lts-3.26,
55
+ ember-lts-3.28,
56
+ ember-release,
57
+ ember-beta,
58
+ ember-canary,
58
59
  ]
59
60
 
60
61
  steps:
61
62
  - name: Checkout
62
63
  uses: actions/checkout@v2
63
64
 
64
- - name: Use Node 12
65
+ - name: Use Node 14
65
66
  uses: actions/setup-node@v2-beta
66
67
  with:
67
- node-version: 12.x
68
+ node-version: 14.x
68
69
 
69
70
  - name: Node Modules Cache
70
71
  uses: actions/cache@v2
package/CHANGELOG.md CHANGED
@@ -1,6 +1,22 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ ## v3.0.0 (2022-05-03)
5
+
6
+
7
+ ## v3.0.0-1 (2022-03-01)
8
+
9
+
10
+ ## v3.0.0-0 (2021-12-09)
11
+
12
+ #### What's new
13
+
14
+ * Drop support for Ember < 2.18, add support for Ember 4.0+ (#343) (3343ecc)
15
+ * 4 retries on CI, 1s sleep (#352) (4a75d99)
16
+ * Extend timeout for base tests, tweak retry (#351) (8fff4c7)
17
+ * Remove implicit this in tests (#349) (5f58de6)
18
+
19
+
4
20
  ## v2.1.0 (2021-12-09)
5
21
 
6
22
  Changelog:
package/README.md CHANGED
@@ -66,6 +66,7 @@ ember install @html-next/vertical-collection
66
66
  | ----------------------------- | ------------------------ | ----------------------- |
67
67
  | `^v1.x.x` | `v1.12.0 - v3.8.x` | `?` |
68
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
 
@@ -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
 
@@ -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;
@@ -4,7 +4,7 @@ function retry {
4
4
  command="$*"
5
5
  retval=1
6
6
  attempt=1
7
- until [[ $retval -eq 0 ]] || [[ $attempt -gt 5 ]]; do
7
+ until [[ $retval -eq 0 ]] || [[ $attempt -gt 4 ]]; do
8
8
  # Execute inside of a subshell in case parent
9
9
  # script is running with "set -e"
10
10
  (
@@ -15,13 +15,13 @@ function retry {
15
15
  attempt=$(( $attempt + 1 ))
16
16
  if [[ $retval -ne 0 ]]; then
17
17
  # If there was an error wait 10 seconds
18
- sleep 10
18
+ sleep 1
19
19
  fi
20
20
  done
21
- if [[ $retval -ne 0 ]] && [[ $attempt -gt 2 ]]; then
21
+ if [[ $retval -ne 0 ]] && [[ $attempt -gt 4 ]]; then
22
22
  # Something is fubar, go ahead and exit
23
23
  exit $retval
24
24
  fi
25
25
  }
26
26
 
27
- retry ember test
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.1.0",
3
+ "version": "3.0.0",
4
4
  "description": "infinite-scroll, done right. done.",
5
5
  "keywords": [
6
6
  "occlusion",
@@ -43,8 +43,6 @@
43
43
  "build": "ember build --environment=production",
44
44
  "lint": "npm-run-all --aggregate-output --continue-on-error --parallel \"lint:!(fix)\"",
45
45
  "lint:fix": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*:fix",
46
- "lint:hbs": "ember-template-lint .",
47
- "lint:hbs:fix": "ember-template-lint . --fix",
48
46
  "lint:js": "eslint . --cache",
49
47
  "lint:js:fix": "eslint . --fix",
50
48
  "start": "ember serve",
@@ -58,34 +56,33 @@
58
56
  "broccoli-merge-trees": "^3.0.1",
59
57
  "broccoli-rollup": "^4.1.1",
60
58
  "ember-cli-babel": "^7.12.0",
61
- "ember-cli-htmlbars": "^3.0.0",
59
+ "ember-cli-htmlbars": "^5.0.0",
62
60
  "ember-cli-version-checker": "^3.1.3",
63
61
  "ember-compatibility-helpers": "^1.2.1",
64
- "ember-raf-scheduler": "0.2.0"
62
+ "ember-raf-scheduler": "^0.3.0"
65
63
  },
66
64
  "devDependencies": {
67
65
  "@ember/optional-features": "^2.0.0",
66
+ "@ember/test-helpers": "^2.4.0",
68
67
  "babel-eslint": "^10.1.0",
69
68
  "bootstrap": "~3.3.5",
70
69
  "broccoli-asset-rev": "^3.0.0",
70
+ "ember-auto-import": "^2.0.0",
71
71
  "ember-cli": "~3.28.0",
72
72
  "ember-cli-dependency-checker": "^3.2.0",
73
73
  "ember-cli-eslint": "^5.1.0",
74
74
  "ember-cli-fastboot": "^2.1.3",
75
75
  "ember-cli-github-pages": "^0.2.2",
76
- "ember-cli-htmlbars-inline-precompile": "^3.0.0",
77
76
  "ember-cli-inject-live-reload": "^2.1.0",
78
77
  "ember-cli-sri": "^2.1.1",
79
78
  "ember-cli-terser": "^4.0.2",
80
- "ember-cli-template-lint": "^1.0.0",
81
79
  "ember-code-snippet": "^2.4.1",
82
80
  "ember-data": "~3.12.0",
83
81
  "ember-disable-prototype-extensions": "^1.1.3",
84
82
  "ember-export-application-global": "^2.0.1",
85
83
  "ember-load-initializers": "^2.1.2",
86
- "ember-native-dom-helpers": "^0.7.0",
87
- "ember-perf-timeline": "^1.2.1",
88
- "ember-qunit": "^4.5.1",
84
+ "ember-perf-timeline": "^2.0.0",
85
+ "ember-qunit": "^5.0.0",
89
86
  "ember-resolver": "^8.0.2",
90
87
  "ember-source": "~3.12.0",
91
88
  "ember-source-channel-url": "^3.0.0",
@@ -95,12 +92,14 @@
95
92
  "eslint-plugin-node": "^9.1.0",
96
93
  "loader.js": "^4.7.0",
97
94
  "npm-run-all": "^4.1.5",
98
- "qunit-dom": "^0.9.0",
95
+ "qunit": "^2.0.0",
96
+ "qunit-dom": "^1.0.0",
99
97
  "release-it": "^14.2.1",
100
- "release-it-lerna-changelog": "^3.1.0"
98
+ "release-it-lerna-changelog": "^3.1.0",
99
+ "webpack": "^5.0.0"
101
100
  },
102
101
  "engines": {
103
- "node": ">= 10.*"
102
+ "node": ">= 14.*"
104
103
  },
105
104
  "publishConfig": {
106
105
  "registry": "https://registry.npmjs.org"
@@ -124,7 +123,7 @@
124
123
  }
125
124
  },
126
125
  "volta": {
127
- "node": "12.22.7",
126
+ "node": "14.18.2",
128
127
  "yarn": "1.22.17"
129
128
  }
130
129
  }