@brightspace-ui/core 2.58.0 → 2.59.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.
@@ -28,9 +28,14 @@ export const SelectionObserverMixin = superclass => class extends superclass {
28
28
 
29
29
  connectedCallback() {
30
30
  super.connectedCallback();
31
+ this.addEventListener('d2l-selection-observer-subscribe', this._handleSelectionObserverSubscribe);
32
+
31
33
  // delay subscription otherwise import/upgrade order can cause selection mixin to miss event
32
34
  requestAnimationFrame(() => {
33
- if (this.selectionFor) return;
35
+ if (this.selectionFor) {
36
+ this._handleSelectionFor();
37
+ return this._provider?.subscribeObserver(this);
38
+ }
34
39
 
35
40
  const evt = new CustomEvent('d2l-selection-observer-subscribe', {
36
41
  bubbles: true,
@@ -44,34 +49,57 @@ export const SelectionObserverMixin = superclass => class extends superclass {
44
49
 
45
50
  disconnectedCallback() {
46
51
  super.disconnectedCallback();
47
- if (this._selectionForObserver) this._selectionForObserver.disconnect();
48
- if (this._provider) this._provider.unsubscribeObserver(this);
52
+ this._disconnectSelectionForObserver();
53
+ this._disconnectProvider();
54
+ this.removeEventListener('d2l-selection-observer-subscribe', this._handleSelectionObserverSubscribe);
49
55
  }
50
56
 
51
57
  updated(changedProperties) {
52
58
  super.updated(changedProperties);
53
59
 
54
- if (!changedProperties.has('selectionFor')) return;
60
+ if (changedProperties.has('selectionFor')) this._handleSelectionFor();
61
+ }
62
+
63
+ _disconnectProvider() {
64
+ if (!this._provider) return;
65
+ this._provider.unsubscribeObserver(this);
66
+ this._provider = undefined;
67
+ }
55
68
 
56
- if (this._selectionForObserver) this._selectionForObserver.disconnect();
57
- if (this._provider) this._provider.unsubscribeObserver(this);
69
+ _disconnectSelectionForObserver() {
70
+ if (!this._selectionForObserver) return;
71
+ this._selectionForObserver.disconnect();
72
+ this._selectionForObserver = undefined;
73
+ }
58
74
 
75
+ _handleSelectionFor() {
76
+ this._disconnectSelectionForObserver();
59
77
  this._updateProvider();
60
78
 
61
- this._selectionForObserver = new MutationObserver(() => {
62
- this._updateProvider();
63
- });
79
+ if (this.selectionFor) {
80
+ this._selectionForObserver = new MutationObserver(() => this._updateProvider());
64
81
 
65
- this._selectionForObserver.observe(this.getRootNode(), {
66
- childList: true,
67
- subtree: true
68
- });
82
+ this._selectionForObserver.observe(this.getRootNode(), {
83
+ childList: true,
84
+ subtree: true
85
+ });
86
+ }
87
+ }
88
+
89
+ _handleSelectionObserverSubscribe(e) {
90
+ if (e.target !== this && this._provider) {
91
+ e.stopPropagation();
92
+ e.detail.provider = this._provider;
93
+ const target = e.composedPath()[0];
94
+ this._provider.subscribeObserver(target);
95
+ }
69
96
  }
70
97
 
71
98
  _updateProvider() {
72
- const selectionComponent = this.getRootNode().querySelector(`#${cssEscape(this.selectionFor)}`);
99
+ const selectionComponent = this.selectionFor ? this.getRootNode().querySelector(`#${cssEscape(this.selectionFor)}`) : undefined;
73
100
  if (this._provider === selectionComponent) return;
74
101
 
102
+ this._disconnectProvider();
75
103
  this._provider = selectionComponent;
76
104
  if (this._provider) {
77
105
  this._provider.subscribeObserver(this);
@@ -10001,6 +10001,37 @@
10001
10001
  }
10002
10002
  ]
10003
10003
  },
10004
+ {
10005
+ "name": "d2l-test-selection-observer",
10006
+ "path": "./components/selection/test/selection-component.js",
10007
+ "attributes": [
10008
+ {
10009
+ "name": "selection-for",
10010
+ "description": "Id of the `SelectionMixin` component this component wants to observe (if not located within that component)",
10011
+ "type": "string"
10012
+ }
10013
+ ],
10014
+ "properties": [
10015
+ {
10016
+ "name": "selectionFor",
10017
+ "attribute": "selection-for",
10018
+ "description": "Id of the `SelectionMixin` component this component wants to observe (if not located within that component)",
10019
+ "type": "string"
10020
+ },
10021
+ {
10022
+ "name": "selectionInfo"
10023
+ }
10024
+ ],
10025
+ "events": [
10026
+ {
10027
+ "name": "d2l-selection-observer-subscribe"
10028
+ }
10029
+ ]
10030
+ },
10031
+ {
10032
+ "name": "d2l-test-selection-observer-shadow",
10033
+ "path": "./components/selection/test/selection-component.js"
10034
+ },
10004
10035
  {
10005
10036
  "name": "d2l-test-skeleton-box",
10006
10037
  "path": "./components/skeleton/demo/skeleton-test-box.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/core",
3
- "version": "2.58.0",
3
+ "version": "2.59.0",
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",