@brightspace-ui/core 3.184.0 → 3.184.2

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.
@@ -22,7 +22,7 @@ const FullData = [
22
22
  { key: 'stats', selected:false, text: 'Statistics' },
23
23
  { key: 'writerscraft', selected:true, text: 'Writer\'s Craft' },
24
24
  ],
25
- initialCount: 6
25
+ loadCount: 6
26
26
  },
27
27
  {
28
28
  key: 'role',
@@ -32,7 +32,7 @@ const FullData = [
32
32
  { key: 'instructor', selected:false, text: 'Instructor' },
33
33
  { key: 'student', selected:false, text: 'Student' }
34
34
  ],
35
- initialCount: 2
35
+ loadCount: 2
36
36
  },
37
37
  {
38
38
  key: 'dep',
@@ -42,7 +42,7 @@ const FullData = [
42
42
  { key: 'spanish', selected:false, text: 'Spanish' },
43
43
  { key: 'science', selected:false, text: 'Science' }
44
44
  ],
45
- initialCount: 2
45
+ loadCount: 2
46
46
  },
47
47
  {
48
48
  key: 'grad',
@@ -52,7 +52,7 @@ const FullData = [
52
52
  { key: '2', selected:false, text: '2nd Grade' },
53
53
  { key: '3', selected:false, text: '3rd Grade' }
54
54
  ],
55
- initialCount: 2
55
+ loadCount: 2
56
56
  }
57
57
  ,
58
58
  {
@@ -63,7 +63,7 @@ const FullData = [
63
63
  { key: '2', selected:false, text: '2nd City' },
64
64
  { key: '3', selected:false, text: '3rd City' }
65
65
  ],
66
- initialCount: 2
66
+ loadCount: 2
67
67
  }
68
68
  ];
69
69
 
@@ -77,24 +77,7 @@ class FilterLoadMoreDemo extends LitElement {
77
77
 
78
78
  constructor() {
79
79
  super();
80
- const dimensions = [];
81
- for (const dim of FullData) {
82
- const values = {};
83
- let selectedCount = 0;
84
- for (const v of dim.values) {
85
- if (!v.selected) continue;
86
- values[v.key] = { ...v };
87
- selectedCount++;
88
- }
89
- const data = {
90
- key: dim.key,
91
- text: dim.text,
92
- values
93
- };
94
- this._addKeys(data, dim.initialCount - selectedCount);
95
- dimensions.push(data);
96
- }
97
- this._dimensions = dimensions;
80
+ this._dimensions = FullData.map(dim => ({ ...dim }));
98
81
  }
99
82
 
100
83
  render() {
@@ -117,26 +100,22 @@ class FilterLoadMoreDemo extends LitElement {
117
100
  }
118
101
 
119
102
  _addKeys(dimension, addCount, searchValue = '') {
120
- const dimData = FullData.find(dim => dim.key === dimension.key);
121
-
122
- const keys = [];
123
- for (const valKey in dimension.values) {
124
- if (this._textIsInSearch(searchValue, dimension.values[valKey].text)) {
125
- keys.push(valKey);
126
- }
127
- }
128
- const total = keys.length + addCount;
129
- dimension.hasMore = false;
130
- for (const v of dimData.values) {
131
- if (v.key in dimension.values || !this._textIsInSearch(searchValue, v.text)) continue;
132
- if (total <= keys.length) {
133
- dimension.hasMore = true;
134
- break;
103
+ dimension.loadCount += addCount;
104
+ const keys = dimension.values.filter(val => this._textIsInSearch(searchValue, val.text));
105
+ const selectedKeys = [];
106
+ const unselectedKeys = [];
107
+ for (const val of keys) {
108
+ if (val.selected) {
109
+ selectedKeys.push(val.key);
110
+ } else {
111
+ unselectedKeys.push(val.key);
135
112
  }
136
- dimension.values[v.key] = { ...v };
137
- keys.push(v.key);
138
113
  }
139
- return keys;
114
+
115
+ dimension.loadCount = Math.max(selectedKeys.length, dimension.loadCount);
116
+ dimension.hasMore = keys.length > dimension.loadCount;
117
+
118
+ return selectedKeys.concat(unselectedKeys).slice(0, dimension.loadCount);
140
119
  }
141
120
 
142
121
  _handleFilterChange(e) {
@@ -171,12 +150,8 @@ class FilterLoadMoreDemo extends LitElement {
171
150
  const dimension = this._dimensions.find(dim => dim.key === dimensionKey);
172
151
  const dimData = FullData.find(dim => dim.key === dimensionKey);
173
152
 
174
- let selectedCount = 0;
175
- for (const valKey in dimension.values) {
176
- if (!dimension.values[valKey].selected) delete dimension.values[valKey];
177
- else if (this._textIsInSearch(e.detail.value, dimension.values[valKey].text)) selectedCount++;
178
- }
179
- const keysToDisplay = this._addKeys(dimension, dimData.initialCount - selectedCount, e.detail.value);
153
+ dimension.loadCount = 0;
154
+ const keysToDisplay = this._addKeys(dimension, dimData.loadCount, e.detail.value);
180
155
 
181
156
  this.requestUpdate();
182
157
  await this.updateComplete;
@@ -887,7 +887,7 @@ class Filter extends FocusMixin(LocalizeCoreElement(LitElement)) {
887
887
  const dimensionKey = e.target.parentNode.id.slice(SET_DIMENSION_ID_PREFIX.length);
888
888
  const dimension = this._getDimensionByKey(dimensionKey);
889
889
 
890
- this.requestFilterLoadMoreEvent(dimensionKey, dimension.value, () => {
890
+ this.requestFilterLoadMoreEvent(dimensionKey, dimension.searchValue, () => {
891
891
  const menu = this.shadowRoot.querySelector('d2l-dropdown-menu');
892
892
  menu ? menu.addEventListener('d2l-dropdown-position', e.detail.complete, { once: true }) : e.detail.complete();
893
893
  });
@@ -97,38 +97,22 @@ class MoreLess extends LocalizeCoreElement(LitElement) {
97
97
 
98
98
  this.__baseHeight = 0;
99
99
  this.__contentId = getUniqueId();
100
- this.__resizeObserver = null;
101
100
  this.__content = null;
102
101
  this.__contentSlot = null;
103
102
  this.__autoExpanded = false;
104
103
  this.__shift = false;
105
- this.__bound_reactToChanges = null;
106
- this.__bound_reactToMutationChanges = null;
107
104
  this.__bound_transitionEvents = null;
105
+
106
+ this._mutationObserver = new MutationObserver(this.__reactToMutationChanges.bind(this));
107
+ this._resizeObserver = new ResizeObserver(this.__reactToChanges.bind(this));
108
108
  }
109
109
 
110
110
  disconnectedCallback() {
111
111
  super.disconnectedCallback();
112
112
 
113
- if (this.__resizeObserver) {
114
- this.__resizeObserver.disconnect();
115
- this.__resizeObserver = null;
116
- }
117
- if (this.__mutationObserver) {
118
- this.__mutationObserver.disconnect();
119
- this.__mutationObserver = null;
120
- }
121
-
122
- this.__content && this.__content.removeEventListener('load', this.__bound_reactToChanges, true);
123
- this.__bound_reactToChanges = null;
124
- this.__bound_reactToMutationChanges = null;
113
+ this._resizeObserver.disconnect();
114
+ this._mutationObserver.disconnect();
125
115
 
126
- if (this.__contentSlot) {
127
- this.__contentSlot.removeEventListener('slotchange', this.__reactToChanges.bind(this));
128
- this.__contentSlot.removeEventListener('slotchange', this.__startObserving.bind(this));
129
- }
130
- this.__content && this.__content.removeEventListener('focusin', this.__focusIn.bind(this));
131
- this.__content && this.__content.removeEventListener('focusout', this.__focusOut.bind(this));
132
116
  this.shadowRoot.removeEventListener('transitionstart', this.__bound_transitionEvents);
133
117
  this.shadowRoot.removeEventListener('transitionend', this.__bound_transitionEvents);
134
118
  this.shadowRoot.removeEventListener('transitioncancel', this.__bound_transitionEvents);
@@ -140,7 +124,7 @@ class MoreLess extends LocalizeCoreElement(LitElement) {
140
124
 
141
125
  this.__content = this.shadowRoot.querySelector('.d2l-more-less-content');
142
126
  this.__contentSlot = this.shadowRoot.querySelector('.d2l-more-less-content slot');
143
- this.__init_setupListeners();
127
+ this.__startObserving();
144
128
 
145
129
  this.__bound_transitionEvents = this.__transitionEvents.bind(this);
146
130
  this.shadowRoot.addEventListener('transitionstart', this.__bound_transitionEvents);
@@ -155,7 +139,14 @@ class MoreLess extends LocalizeCoreElement(LitElement) {
155
139
  'd2l-more-less-transition': this.__transitionAdded
156
140
  };
157
141
  return html`
158
- <div id="${this.__contentId}" class=${classMap(contentClasses)} style=${styleMap({ maxHeight: `${this.__maxHeight}` })}>
142
+ <div
143
+ id="${this.__contentId}"
144
+ class=${classMap(contentClasses)}
145
+ style=${styleMap({ maxHeight: `${this.__maxHeight}` })}
146
+ @focusin="${this.__focusIn}"
147
+ @focusout="${this.__focusOut}"
148
+ @load=${this.__reactToChanges}
149
+ @slotchange=${this.#handleSlotChange}>
159
150
  <slot></slot>
160
151
  </div>
161
152
  <d2l-button-subtle
@@ -288,10 +279,6 @@ class MoreLess extends LocalizeCoreElement(LitElement) {
288
279
  __init_measureBaseHeight() {
289
280
  this.__baseHeight = this.__content.offsetHeight;
290
281
  this.__adjustToContent();
291
-
292
- // react to images and whatnot loading
293
- this.__bound_reactToChanges = this.__bound_reactToChanges || this.__reactToChanges.bind(this);
294
- this.__content.addEventListener('load', this.__bound_reactToChanges, true);
295
282
  }
296
283
 
297
284
  __init_setBaseHeight() {
@@ -302,16 +289,6 @@ class MoreLess extends LocalizeCoreElement(LitElement) {
302
289
  });
303
290
  }
304
291
 
305
- __init_setupListeners() {
306
- this.__startObserving();
307
- if (this.__contentSlot) {
308
- this.__contentSlot.addEventListener('slotchange', this.__reactToChanges.bind(this));
309
- this.__contentSlot.addEventListener('slotchange', this.__startObserving.bind(this));
310
- }
311
- this.__content.addEventListener('focusin', this.__focusIn.bind(this));
312
- this.__content.addEventListener('focusout', this.__focusOut.bind(this));
313
- }
314
-
315
292
  __isOwnMutation(mutation) {
316
293
  return mutation.target === this.__content
317
294
  && (mutation.type === 'style' || mutation.type === 'attributes');
@@ -341,18 +318,14 @@ class MoreLess extends LocalizeCoreElement(LitElement) {
341
318
  }
342
319
 
343
320
  __startObserving() {
344
- this.__bound_reactToChanges = this.__bound_reactToChanges || this.__reactToChanges.bind(this);
345
- this.__bound_reactToMutationChanges = this.__bound_reactToMutationChanges || this.__reactToMutationChanges.bind(this);
346
- this.__resizeObserver = this.__resizeObserver || new ResizeObserver(this.__bound_reactToChanges);
347
- this.__resizeObserver.disconnect();
348
- this.__mutationObserver = this.__mutationObserver || new MutationObserver(this.__bound_reactToMutationChanges);
349
- this.__mutationObserver.disconnect();
321
+ this._resizeObserver.disconnect();
322
+ this._mutationObserver.disconnect();
350
323
 
351
324
  if (this.__contentSlot) {
352
325
  const children = getComposedChildren(this.__contentSlot);
353
326
  for (let i = 0; i < children.length; ++i) {
354
- this.__resizeObserver.observe(children[i]);
355
- this.__mutationObserver.observe(children[i], {
327
+ this._resizeObserver.observe(children[i]);
328
+ this._mutationObserver.observe(children[i], {
356
329
  childList: true,
357
330
  subtree: true,
358
331
  characterData: true,
@@ -360,8 +333,8 @@ class MoreLess extends LocalizeCoreElement(LitElement) {
360
333
  });
361
334
  }
362
335
  }
363
- this.__resizeObserver.observe(this.__content);
364
- this.__mutationObserver.observe(this.__content, {
336
+ this._resizeObserver.observe(this.__content);
337
+ this._mutationObserver.observe(this.__content, {
365
338
  childList: true,
366
339
  subtree: true,
367
340
  characterData: true,
@@ -383,6 +356,10 @@ class MoreLess extends LocalizeCoreElement(LitElement) {
383
356
  this.dispatchEvent(new CustomEvent(e.type, { bubbles: true, composed: true, detail: e.detail }));
384
357
  }
385
358
 
359
+ #handleSlotChange() {
360
+ this.__reactToChanges();
361
+ this.__startObserving();
362
+ }
386
363
  }
387
364
 
388
365
  customElements.define('d2l-more-less', MoreLess);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/core",
3
- "version": "3.184.0",
3
+ "version": "3.184.2",
4
4
  "description": "A collection of accessible, free, open-source web components for building Brightspace applications",
5
5
  "type": "module",
6
6
  "repository": "https://github.com/BrightspaceUI/core.git",