@brightspace-ui/core 3.282.0 → 3.283.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.
package/helpers/README.md CHANGED
@@ -86,18 +86,25 @@ elemIdListRemoves(node, attrName, value);
86
86
  findComposedAncestor(node, predicate);
87
87
 
88
88
  // gets the composed children (including shadow children & distributed children)
89
- // includes a predicate which will add children nodes when predicate(node) is true
89
+ // includes optional predicate for filtering child elements
90
90
  getComposedChildren(element, predicate = () => true);
91
91
 
92
+ // gets the composed next element sibling considing how children are distributed into slots
93
+ // includes optional predicate for filtering elements
94
+ getComposedNextElementSibling(node, { predicate } = {}) {
95
+
92
96
  // gets the composed parent (including shadow host & insertion points)
93
97
  getComposedParent(node);
94
98
 
99
+ // returns the first visible ancestor of the given node
100
+ getFirstVisibleAncestor(node)
101
+
95
102
  // returns the next composed sibling at least one dom level up
96
- // includes a predicate which will return the node when predicate(node) is true
103
+ // includes optional predicate for filtering elements
97
104
  getNextAncestorSibling(node, predicate = () => true);
98
105
 
99
106
  // returns the previous composed sibling at least one dom level up
100
- // includes a predicate which will return the node when predicate(node) is true
107
+ // includes optional predicate for filtering elements
101
108
  getPreviousAncestorSibling(node, predicate = () => true);
102
109
 
103
110
  // browser consistent implementation of HTMLElement.offsetParent
@@ -109,9 +116,6 @@ isComposedAncestor(ancestorNode, node);
109
116
  // returns true/false whether the element is visible regardless of positioning
110
117
  isVisible(node, { checkAncestors: true });
111
118
 
112
- // returns the first visible ancestor of the given node
113
- getFirstVisibleAncestor(node)
114
-
115
119
  // similar to document.querySelector or element.querySelector,
116
120
  // except it queries not just the light DOM but also shadow DOM
117
121
  querySelectorComposed(node, selector)
package/helpers/dom.js CHANGED
@@ -79,40 +79,65 @@ export function getBoundingAncestor(node) {
79
79
  });
80
80
  }
81
81
 
82
- export function getComposedChildren(node, predicate = () => true) {
82
+ function getComposedChildNodes(node, { elementsOnly = false, predicate } = {}) {
83
83
 
84
- if (!node) {
85
- return null;
86
- }
87
- if (node.nodeType !== Node.ELEMENT_NODE && node.nodeType !== Node.DOCUMENT_NODE && node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) {
84
+ if (!node) return null;
85
+
86
+ if (node.nodeType !== Node.ELEMENT_NODE
87
+ && node.nodeType !== Node.DOCUMENT_NODE
88
+ && node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) {
88
89
  return null;
89
90
  }
90
91
 
91
92
  let nodes;
92
- const children = [];
93
+ const filteredNodes = [];
93
94
 
94
95
  if (node.tagName === 'CONTENT') {
95
96
  nodes = node.getDistributedNodes();
96
97
  } else if (node.tagName === 'SLOT') {
97
98
  // note: this is not handling default slot content
98
- nodes = node.assignedNodes({ flatten: true });
99
+ nodes = elementsOnly ? node.assignedElements({ flatten: true }) : node.assignedNodes({ flatten: true });
99
100
  } else {
100
- if (node.shadowRoot) {
101
- node = node.shadowRoot;
102
- }
103
- nodes = node.children || node.childNodes;
101
+ if (node.shadowRoot) node = node.shadowRoot;
102
+ nodes = elementsOnly ? node.children : node.childNodes;
104
103
  }
105
104
 
106
105
  for (let i = 0; i < nodes.length; i++) {
107
- if (nodes[i].nodeType === Node.ELEMENT_NODE) {
108
- if (predicate(nodes[i])) {
109
- children.push(nodes[i]);
110
- }
106
+ // need to check nodeType since old Polymer getDistributedNodes could return non-elements
107
+ if (!elementsOnly || nodes[i].nodeType === Node.ELEMENT_NODE) {
108
+ if (!predicate || predicate(nodes[i])) filteredNodes.push(nodes[i]);
111
109
  }
112
110
  }
113
111
 
114
- return children;
112
+ return filteredNodes;
113
+ }
114
+
115
+ export function getComposedChildren(node, predicate) {
116
+ return getComposedChildNodes(node, { elementsOnly: true, predicate });
117
+ }
118
+
119
+ export function getComposedNextElementSibling(node, { predicate } = {}) {
115
120
 
121
+ if (!node || node.nodeType === undefined) return null;
122
+
123
+ const parentNode = getComposedParent(node);
124
+ if (!parentNode) return null;
125
+
126
+ // for regular parents this is child elements; for SLOT this is distributed elements
127
+ const composedChildNodes = getComposedChildNodes(parentNode, { elementsOnly: (node.nodeType === Node.ELEMENT_NODE) });
128
+
129
+ if (!composedChildNodes || composedChildNodes.length === 0) return null;
130
+
131
+ const index = composedChildNodes.indexOf(node);
132
+ if (index === -1) return null;
133
+
134
+ for (let i = index + 1; i < composedChildNodes.length; i++) {
135
+ if (composedChildNodes[i].nodeType === Node.ELEMENT_NODE && (!predicate || predicate(composedChildNodes[i]))) {
136
+ return composedChildNodes[i];
137
+ }
138
+ }
139
+
140
+ return null;
116
141
  }
117
142
 
118
143
  export function getComposedParent(node) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/core",
3
- "version": "3.282.0",
3
+ "version": "3.283.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",