@brightspace-ui/core 3.184.1 → 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.
@@ -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.1",
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",