neo.mjs 3.2.0 → 3.2.4

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.
Files changed (47) hide show
  1. package/apps/covid/view/TableContainerController.mjs +16 -10
  2. package/apps/covid/view/country/Gallery.mjs +11 -11
  3. package/apps/realworld2/view/article/Gallery.mjs +8 -8
  4. package/apps/sharedcovid/view/TableContainerController.mjs +16 -10
  5. package/apps/sharedcovid/view/country/Gallery.mjs +11 -11
  6. package/buildScripts/webpack/development/webpack.config.appworker.mjs +4 -4
  7. package/buildScripts/webpack/development/webpack.config.myapps.mjs +4 -4
  8. package/buildScripts/webpack/production/webpack.config.appworker.mjs +3 -3
  9. package/buildScripts/webpack/production/webpack.config.myapps.mjs +3 -3
  10. package/examples/ConfigurationViewport.mjs +1 -1
  11. package/examples/component/coronaGallery/CountryGallery.mjs +12 -12
  12. package/examples/component/coronaGallery/CountryModel.mjs +8 -2
  13. package/examples/component/coronaGallery/CountryStore.mjs +12 -2
  14. package/examples/component/coronaGallery/MainContainer.mjs +3 -6
  15. package/examples/component/gallery/ImageModel.mjs +38 -0
  16. package/examples/component/gallery/ImageStore.mjs +32 -0
  17. package/examples/component/gallery/MainContainer.mjs +2 -0
  18. package/examples/list/animate/List.mjs +11 -1
  19. package/examples/list/animate/MainStore.mjs +4 -5
  20. package/examples/list/circle/MainContainer.mjs +142 -0
  21. package/examples/list/circle/MainModel.mjs +33 -0
  22. package/examples/list/circle/MainStore.mjs +42 -0
  23. package/examples/list/circle/app.mjs +7 -0
  24. package/examples/list/circle/index.html +11 -0
  25. package/examples/list/circle/neo-config.json +7 -0
  26. package/package.json +5 -5
  27. package/resources/examples/data/{circleContacts.json → circles/group1.json} +0 -0
  28. package/resources/examples/data/circles/group2.json +18 -0
  29. package/resources/examples/data/circles/group3.json +20 -0
  30. package/resources/examples/data/circles/group4.json +28 -0
  31. package/resources/scss/src/apps/covid/country/Gallery.scss +2 -1
  32. package/resources/scss/src/component/Gallery.scss +2 -1
  33. package/resources/scss/src/examples/component/coronaGallery/CountryGallery.scss +2 -1
  34. package/resources/scss/src/list/Circle.scss +25 -0
  35. package/src/calendar/view/calendars/List.mjs +2 -2
  36. package/src/component/Circle.mjs +51 -30
  37. package/src/component/Gallery.mjs +83 -108
  38. package/src/core/Base.mjs +1 -1
  39. package/src/data/Store.mjs +2 -2
  40. package/src/list/Base.mjs +51 -14
  41. package/src/list/Chip.mjs +2 -3
  42. package/src/list/Circle.mjs +87 -0
  43. package/src/list/Component.mjs +37 -6
  44. package/src/list/plugin/Animate.mjs +79 -37
  45. package/src/selection/CircleModel.mjs +3 -3
  46. package/src/selection/ListModel.mjs +2 -2
  47. package/test/siesta/tests/CollectionBase.mjs +4 -4
@@ -30,11 +30,9 @@ class Component extends Base {
30
30
  * @protected
31
31
  */
32
32
  afterSetAppName(value, oldValue) {
33
- let me = this;
34
-
35
33
  super.afterSetAppName(value, oldValue);
36
34
 
37
- value && me.items?.forEach(item => {
35
+ value && this.items?.forEach(item => {
38
36
  item.appName = value;
39
37
  });
40
38
  }
@@ -73,10 +71,43 @@ class Component extends Base {
73
71
  * @returns {String|Number} itemId
74
72
  */
75
73
  getItemRecordId(vnodeId) {
76
- let itemId = vnodeId.split('__')[1],
77
- store = this.store;
74
+ let itemId = vnodeId.split('__')[1];
75
+ return this.store.getAt(parseInt(itemId))[this.getKeyProperty()];
76
+ }
77
+
78
+ /**
79
+ * @param {Object} data
80
+ * @param {Object[]} data.items
81
+ * @param {Object[]} data.previousItems
82
+ * @param {Neo.data.Store} data.scope
83
+ */
84
+ onStoreSort(data) {
85
+ this.sortItems(data);
86
+ super.onStoreSort(data);
87
+ }
88
+
89
+ /**
90
+ * @param {Object} data
91
+ * @param {Object[]} data.items
92
+ * @param {Object[]} data.previousItems
93
+ * @param {Neo.data.Store} data.scope
94
+ */
95
+ sortItems(data) {
96
+ let me = this,
97
+ newItems = [],
98
+ fromIndex, key, previousKeys;
99
+
100
+ if (me.items) {
101
+ key = me.getKeyProperty();
102
+ previousKeys = data.previousItems.map(e => e[key]);
103
+
104
+ data.items.forEach(item => {
105
+ fromIndex = previousKeys.indexOf(item[key]);
106
+ newItems.push(me.items[fromIndex]);
107
+ });
78
108
 
79
- return store.getAt(parseInt(itemId))[store.model.keyProperty];
109
+ me.items = newItems;
110
+ }
80
111
  }
81
112
  }
82
113
 
@@ -27,21 +27,11 @@ class Animate extends Base {
27
27
  * @member {Number|null} columns=null
28
28
  */
29
29
  columns: null,
30
- /**
31
- * Value in px
32
- * @member {Number} itemHeight=200
33
- */
34
- itemHeight: 200,
35
30
  /**
36
31
  * Value in px
37
32
  * @member {Number} itemMargin=10
38
33
  */
39
34
  itemMargin: 10,
40
- /**
41
- * Value in px
42
- * @member {Number} itemWidth=300
43
- */
44
- itemWidth: 300,
45
35
  /**
46
36
  * @member {DOMRect|null} ownerRect=null
47
37
  */
@@ -78,14 +68,14 @@ class Animate extends Base {
78
68
  let me = this,
79
69
  owner = me.owner;
80
70
 
71
+ if (!owner.itemHeight || !owner.itemWidth) {
72
+ console.error('list.plugin.Animate requires fixed itemHeight and itemWidth values', owner);
73
+ }
74
+
81
75
  me.adjustCreateItem();
82
76
 
83
77
  owner.onStoreFilter = me.onStoreFilter.bind(me);
84
-
85
- owner.store.on({
86
- sort : me.onStoreSort,
87
- scope: me
88
- });
78
+ owner.onStoreSort = me.onStoreSort .bind(me);
89
79
 
90
80
  this.updateTransitionDetails(false);
91
81
  }
@@ -139,6 +129,7 @@ class Animate extends Base {
139
129
  */
140
130
  createItem(me, record, index) {
141
131
  let item = me.ownerCreateItem(record, index),
132
+ owner = me.owner,
142
133
  position = me.getItemPosition(record, index),
143
134
  style = item.style || {};
144
135
 
@@ -147,10 +138,10 @@ class Animate extends Base {
147
138
  }
148
139
 
149
140
  Object.assign(style, {
150
- height : `${me.itemHeight}px`,
141
+ height : `${owner.itemHeight}px`,
151
142
  position : 'absolute',
152
143
  transform: `translate(${position.x}px, ${position.y}px)`,
153
- width : `${me.itemWidth}px`
144
+ width : `${owner.itemWidth}px`
154
145
  });
155
146
 
156
147
  item.style = style;
@@ -167,9 +158,10 @@ class Animate extends Base {
167
158
  let me = this,
168
159
  column = index % me.columns,
169
160
  margin = me.itemMargin,
161
+ owner = me.owner,
170
162
  row = Math.floor(index / me.columns),
171
- x = column * (margin + me.itemWidth) + margin,
172
- y = row * (margin + me.itemHeight) + margin;
163
+ x = column * (margin + owner.itemWidth) + margin,
164
+ y = row * (margin + owner.itemHeight) + margin;
173
165
 
174
166
  return {x, y};
175
167
  }
@@ -186,7 +178,7 @@ class Animate extends Base {
186
178
  }
187
179
 
188
180
  let owner = this.owner,
189
- key = owner.store.keyProperty;
181
+ key = owner.getKeyProperty();
190
182
 
191
183
  return map.indexOf(owner.getItemId(obj.record[key]));
192
184
  }
@@ -195,14 +187,18 @@ class Animate extends Base {
195
187
  *
196
188
  */
197
189
  onOwnerMounted() {
198
- let me = this;
190
+ let me = this,
191
+ owner = me.owner;
199
192
 
200
- me.owner.getDomRect().then(rect => {
193
+ owner.getDomRect().then(rect => {
201
194
  Object.assign(me, {
202
- columns : Math.floor(rect.width / me.itemWidth),
195
+ columns : Math.floor(rect.width / owner.itemWidth),
203
196
  ownerRect: rect,
204
- rows : Math.floor(rect.height / me.itemHeight)
197
+ rows : Math.floor(rect.height / owner.itemHeight)
205
198
  });
199
+
200
+ // if the store got loaded before this plugin is ready, create the items now
201
+ owner.store.getCount() > 0 && owner.createItems();
206
202
  });
207
203
  }
208
204
 
@@ -216,7 +212,7 @@ class Animate extends Base {
216
212
  onStoreFilter(data) {
217
213
  let me = this,
218
214
  owner = me.owner,
219
- key = owner.store.keyProperty,
215
+ key = owner.getKeyProperty(),
220
216
  hasAddedItems = false,
221
217
  addedItems = [],
222
218
  movedItems = [],
@@ -326,19 +322,34 @@ class Animate extends Base {
326
322
  * @param {Neo.data.Store} data.scope
327
323
  */
328
324
  onStoreSort(data) {
329
- let me = this,
330
- hasChange = false,
331
- keyProperty = data.scope.keyProperty,
332
- owner = me.owner,
333
- newVdomCn = [],
334
- vdom = owner.vdom,
335
- vdomMap = vdom.cn.map(e => e.id),
336
- fromIndex, itemId;
337
-
338
- if (vdomMap.length > 0) {
325
+ let me = this;
326
+
327
+ if (Neo.list.Component && me.owner instanceof Neo.list.Component) {
328
+ me.sortComponentList(data);
329
+ } else {
330
+ me.sortBaseList(data);
331
+ }
332
+ }
333
+
334
+ /**
335
+ * @param {Object} data
336
+ * @param {Object[]} data.items
337
+ * @param {Object[]} data.previousItems
338
+ * @param {Neo.data.Store} data.scope
339
+ */
340
+ sortBaseList(data) {
341
+ let me = this,
342
+ hasChange = false,
343
+ owner = me.owner,
344
+ key = owner.getKeyProperty(),
345
+ newVdomCn = [],
346
+ previousKeys = data.previousItems.map(e => e[key]),
347
+ vdom = owner.vdom,
348
+ fromIndex;
349
+
350
+ if (vdom.cn.length > 0) {
339
351
  data.items.forEach((item, index) => {
340
- itemId = owner.getItemId(item[keyProperty]);
341
- fromIndex = vdomMap.indexOf(itemId);
352
+ fromIndex = previousKeys.indexOf(item[key]);
342
353
 
343
354
  newVdomCn.push(vdom.cn[fromIndex]);
344
355
 
@@ -360,6 +371,37 @@ class Animate extends Base {
360
371
  }
361
372
  }
362
373
 
374
+ /**
375
+ * @param {Object} data
376
+ * @param {Object[]} data.items
377
+ * @param {Object[]} data.previousItems
378
+ * @param {Neo.data.Store} data.scope
379
+ */
380
+ sortComponentList(data) {
381
+ let me = this,
382
+ owner = me.owner,
383
+ key = owner.getKeyProperty(),
384
+ previousKeys = data.previousItems.map(e => e[key]),
385
+ vdom = owner.vdom,
386
+ fromIndex, item, position;
387
+
388
+ owner.sortItems(data);
389
+
390
+ previousKeys = owner.items.map(e => owner.getItemRecordId(e[key]));
391
+
392
+ if (vdom.cn.length > 0) {
393
+ data.items.forEach((record, index) => {
394
+ fromIndex = previousKeys.indexOf(record[key]);
395
+ item = vdom.cn[fromIndex];
396
+ position = me.getItemPosition(record, index);
397
+
398
+ item.style.transform = `translate(${position.x}px, ${position.y}px)`;
399
+ });
400
+
401
+ owner.vdom = vdom;
402
+ }
403
+ }
404
+
363
405
  /**
364
406
  *
365
407
  */
@@ -41,15 +41,15 @@ class CircleModel extends Model {
41
41
  item = data.path[0],
42
42
  view = me.view,
43
43
  store = view.store,
44
- maxItems = Math.min(store.getCount(), view.maxItems - 1),
44
+ maxIndex = Math.min(store.getCount(), view.maxItems) - 1,
45
45
  index, itemId, recordId;
46
46
 
47
47
  if (item.cls.includes('neo-circle-item')) {
48
48
  recordId = parseInt(view.getItemRecordId(item.id));
49
49
  index = store.indexOf(recordId) + step;
50
50
 
51
- if (index < 0) {index = maxItems;}
52
- else if (index > maxItems) {index = 0;}
51
+ if (index < 0) {index = maxIndex;}
52
+ else if (index > maxIndex) {index = 0;}
53
53
  } else {
54
54
  index = 0;
55
55
  }
@@ -125,7 +125,7 @@ class ListModel extends Model {
125
125
  id = me.id,
126
126
  view = me.view;
127
127
 
128
- view.keys && view.keys._keys.push(
128
+ view.keys?._keys.push(
129
129
  {fn: 'onKeyDownDown' ,key: 'Down' ,scope: id},
130
130
  {fn: 'onKeyDownEnter' ,key: 'Enter' ,scope: id},
131
131
  {fn: 'onKeyDownLeft' ,key: 'Left' ,scope: id},
@@ -156,7 +156,7 @@ class ListModel extends Model {
156
156
  id = me.id,
157
157
  view = me.view;
158
158
 
159
- view.keys && view.keys.removeKeys([
159
+ view.keys?.removeKeys([
160
160
  {fn: 'onKeyDownDown' ,key: 'Down' ,scope: id},
161
161
  {fn: 'onKeyDownEnter' ,key: 'Enter' ,scope: id},
162
162
  {fn: 'onKeyDownLeft' ,key: 'Left' ,scope: id},
@@ -160,11 +160,11 @@ StartTest(t => {
160
160
  {country: 'Croatia', firstname: 'Grgur', githubId: 'grgur', lastname: 'Grisogono'},
161
161
  {country: 'Slovakia', firstname: 'Jozef', githubId: 'jsakalos', lastname: 'Sakalos'},
162
162
  {country: 'Argentina', firstname: 'Max', githubId: 'elmasse', lastname: 'Fierro'},
163
+ {country: 'France', firstname: 'Nigel', githubId: 'NigeWhite', lastname: 'White'},
163
164
  {country: 'Germany', firstname: 'Nils', githubId: 'mrsunshine', lastname: 'Dehl'},
164
165
  {country: 'USA', firstname: 'Rich', githubId: 'rwaters', lastname: 'Waters'},
165
166
  {country: 'Germany', firstname: 'Tobias', githubId: 'tobiu2', lastname: 'Uhlig2'},
166
- {country: 'Germany', firstname: 'Tobias', githubId: 'tobiu', lastname: 'Uhlig'},
167
- {country: 'France', firstname: 'Nigel', githubId: 'NigeWhite', lastname: 'White'}
167
+ {country: 'Germany', firstname: 'Tobias', githubId: 'tobiu', lastname: 'Uhlig'}
168
168
  ], 'collection2.getRange()');
169
169
 
170
170
  t.notOk(collection2.isFiltered(), 'collection2.isFiltered()');
@@ -186,11 +186,11 @@ StartTest(t => {
186
186
  {country: 'Croatia', firstname: 'Grgur', githubId: 'grgur', lastname: 'Grisogono'},
187
187
  {country: 'Slovakia', firstname: 'Jozef', githubId: 'jsakalos', lastname: 'Sakalos'},
188
188
  {country: 'Argentina', firstname: 'Max', githubId: 'elmasse', lastname: 'Fierro'},
189
+ {country: 'France', firstname: 'Nigel', githubId: 'NigeWhite', lastname: 'White'},
189
190
  {country: 'Germany', firstname: 'Nils', githubId: 'mrsunshine', lastname: 'Dehl'},
190
191
  {country: 'USA', firstname: 'Rich', githubId: 'rwaters', lastname: 'Waters'},
191
192
  {country: 'Germany', firstname: 'Tobias', githubId: 'tobiu2', lastname: 'Uhlig2'},
192
193
  {country: 'Germany', firstname: 'Tobias', githubId: 'tobiu', lastname: 'Uhlig'},
193
- {country: 'France', firstname: 'Nigel', githubId: 'NigeWhite', lastname: 'White'}
194
194
  ], 'collection2.getRange()');
195
195
 
196
196
  collection2.clearSorters(true);
@@ -251,4 +251,4 @@ StartTest(t => {
251
251
  t.isStrict(collection3.getCount(), 5, 'collection3 count is 5');
252
252
  t.isStrict(collection3.allItems.getCount(), 9, 'collection3 allItems count is 9');
253
253
  });
254
- });
254
+ });