@instructure/ui-tree-browser 8.33.1 → 8.33.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.
Files changed (35) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/es/TreeBrowser/TreeBrowserLocator.js +4 -2
  3. package/es/TreeBrowser/TreeButton/index.js +16 -37
  4. package/es/TreeBrowser/TreeButton/props.js +1 -0
  5. package/es/TreeBrowser/TreeButton/styles.js +5 -6
  6. package/es/TreeBrowser/TreeButton/theme.js +6 -6
  7. package/es/TreeBrowser/TreeCollection/index.js +44 -70
  8. package/es/TreeBrowser/TreeCollection/props.js +1 -0
  9. package/es/TreeBrowser/TreeCollection/styles.js +3 -2
  10. package/es/TreeBrowser/TreeCollection/theme.js +5 -5
  11. package/es/TreeBrowser/TreeNode/index.js +8 -20
  12. package/es/TreeBrowser/TreeNode/props.js +1 -0
  13. package/es/TreeBrowser/index.js +8 -57
  14. package/es/TreeBrowser/props.js +1 -0
  15. package/es/TreeBrowser/styles.js +1 -1
  16. package/es/TreeBrowser/theme.js +3 -3
  17. package/lib/TreeBrowser/TreeBrowserLocator.js +3 -4
  18. package/lib/TreeBrowser/TreeButton/index.js +13 -46
  19. package/lib/TreeBrowser/TreeButton/props.js +1 -3
  20. package/lib/TreeBrowser/TreeButton/styles.js +5 -8
  21. package/lib/TreeBrowser/TreeButton/theme.js +6 -7
  22. package/lib/TreeBrowser/TreeCollection/index.js +44 -79
  23. package/lib/TreeBrowser/TreeCollection/props.js +1 -5
  24. package/lib/TreeBrowser/TreeCollection/styles.js +3 -4
  25. package/lib/TreeBrowser/TreeCollection/theme.js +5 -6
  26. package/lib/TreeBrowser/TreeNode/index.js +5 -29
  27. package/lib/TreeBrowser/TreeNode/props.js +1 -3
  28. package/lib/TreeBrowser/index.js +6 -72
  29. package/lib/TreeBrowser/locator.js +0 -2
  30. package/lib/TreeBrowser/props.js +1 -4
  31. package/lib/TreeBrowser/styles.js +1 -2
  32. package/lib/TreeBrowser/theme.js +3 -4
  33. package/lib/index.js +0 -1
  34. package/package.json +14 -14
  35. package/tsconfig.build.tsbuildinfo +1 -1
@@ -1,42 +1,25 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = exports.TreeBrowser = void 0;
9
-
10
8
  var _react = require("react");
11
-
12
9
  var _keycode = _interopRequireDefault(require("keycode"));
13
-
14
10
  var _IconFolderLine = require("@instructure/ui-icons/lib/IconFolderLine.js");
15
-
16
11
  var _IconDocumentLine = require("@instructure/ui-icons/lib/IconDocumentLine.js");
17
-
18
12
  var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js");
19
-
20
13
  var _pickProps = require("@instructure/ui-react-utils/lib/pickProps.js");
21
-
22
14
  var _testable = require("@instructure/ui-testable/lib/testable.js");
23
-
24
15
  var _emotion = require("@instructure/emotion");
25
-
26
16
  var _TreeCollection = require("./TreeCollection");
27
-
28
17
  var _TreeButton = require("./TreeButton");
29
-
30
18
  var _TreeNode = require("./TreeNode");
31
-
32
19
  var _styles = _interopRequireDefault(require("./styles"));
33
-
34
20
  var _theme = _interopRequireDefault(require("./theme"));
35
-
36
21
  var _props = require("./props");
37
-
38
22
  var _dec, _dec2, _class, _class2;
39
-
40
23
  /**
41
24
  ---
42
25
  category: components
@@ -46,72 +29,57 @@ category: components
46
29
  let TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = (_class2 = class TreeBrowser extends _react.Component {
47
30
  constructor(props) {
48
31
  var _this;
49
-
50
32
  super(props);
51
33
  _this = this;
52
34
  this.ref = null;
53
-
54
35
  this.handleCollectionClick = function (e, collection) {
55
36
  let expand = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : true;
56
37
  e.stopPropagation();
57
38
  const onCollectionClick = _this.props.onCollectionClick;
58
39
  if (expand) _this.expandOrCollapseNode(collection);
59
40
  onCollectionClick === null || onCollectionClick === void 0 ? void 0 : onCollectionClick(collection.id, collection); // TODO: this should pass the event as the first arg
60
-
61
41
  _this.handleSelection(collection.id, 'collection');
62
42
  };
63
-
64
43
  this.handleItemClick = (e, item) => {
65
44
  var _this$props$onItemCli, _this$props;
66
-
67
45
  e.stopPropagation();
68
46
  (_this$props$onItemCli = (_this$props = this.props).onItemClick) === null || _this$props$onItemCli === void 0 ? void 0 : _this$props$onItemCli.call(_this$props, item);
69
47
  this.handleSelection(item.id, 'item');
70
48
  };
71
-
72
49
  this.handleKeyDown = (event, node) => {
73
50
  event.stopPropagation();
74
-
75
51
  switch (event.keyCode) {
76
52
  case _keycode.default.codes.down:
77
53
  case _keycode.default.codes.j:
78
54
  this.moveFocus(1);
79
55
  break;
80
-
81
56
  case _keycode.default.codes.up:
82
57
  case _keycode.default.codes.k:
83
58
  this.moveFocus(-1);
84
59
  break;
85
-
86
60
  case _keycode.default.codes.home:
87
61
  case _keycode.default.codes.end:
88
62
  this.homeOrEnd(event.keyCode);
89
63
  break;
90
-
91
64
  case _keycode.default.codes.left:
92
65
  case _keycode.default.codes.right:
93
66
  this.handleLeftOrRightArrow(event.keyCode, node);
94
67
  break;
95
-
96
68
  case _keycode.default.codes.enter:
97
69
  case _keycode.default.codes.space:
98
70
  this.handleActivation(event, node);
99
71
  break;
100
-
101
72
  default:
102
73
  return;
103
74
  }
104
-
105
75
  event.preventDefault();
106
76
  };
107
-
108
77
  this.getIsFlattened = collection => {
109
78
  const _this$props2 = this.props,
110
- rootId = _this$props2.rootId,
111
- showRootCollection = _this$props2.showRootCollection;
79
+ rootId = _this$props2.rootId,
80
+ showRootCollection = _this$props2.showRootCollection;
112
81
  return !showRootCollection && typeof rootId !== 'undefined' && collection.id === rootId;
113
82
  };
114
-
115
83
  if (typeof this.props.expanded === 'undefined') {
116
84
  this.state = {
117
85
  expanded: this.props.defaultExpanded,
@@ -123,71 +91,55 @@ let TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.defaul
123
91
  };
124
92
  }
125
93
  }
126
-
127
94
  componentDidMount() {
128
95
  var _this$props$makeStyle, _this$props3;
129
-
130
96
  (_this$props$makeStyle = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props3);
131
97
  }
132
-
133
98
  componentDidUpdate() {
134
99
  var _this$props$makeStyle2, _this$props4;
135
-
136
100
  (_this$props$makeStyle2 = (_this$props4 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props4);
137
101
  }
138
-
139
102
  get _root() {
140
103
  return this.ref;
141
104
  }
142
-
143
105
  get collections() {
144
106
  const _this$props5 = this.props,
145
- collections = _this$props5.collections,
146
- rootId = _this$props5.rootId;
147
-
107
+ collections = _this$props5.collections,
108
+ rootId = _this$props5.rootId;
148
109
  if (typeof rootId !== 'undefined') {
149
110
  return [collections[rootId]];
150
111
  } else {
151
112
  return Object.keys(collections).map(id => collections[id]).filter(collection => collection != null);
152
113
  }
153
114
  }
154
-
155
115
  get expanded() {
156
116
  return this.getExpanded(this.state, this.props);
157
117
  }
158
-
159
118
  getExpanded(state, props) {
160
119
  return typeof props.expanded === 'undefined' ? state.expanded : props.expanded;
161
120
  }
162
-
163
121
  expandOrCollapseNode(collection) {
164
122
  var _this$props$onCollect, _this$props6;
165
-
166
123
  (_this$props$onCollect = (_this$props6 = this.props).onCollectionToggle) === null || _this$props$onCollect === void 0 ? void 0 : _this$props$onCollect.call(_this$props6, collection);
167
-
168
124
  if (typeof this.props.expanded === 'undefined') {
169
125
  this.setState((state, props) => {
170
126
  const expanded = [...this.getExpanded(state, props)];
171
127
  const expandedIndex = this.getExpandedIndex(expanded, collection.id);
172
-
173
128
  if (collection.expanded && expandedIndex < 0) {
174
129
  expanded.push(collection.id);
175
130
  } else if (expandedIndex >= 0) {
176
131
  expanded.splice(expandedIndex, 1);
177
132
  }
178
-
179
133
  return {
180
134
  expanded
181
135
  };
182
136
  });
183
137
  }
184
138
  }
185
-
186
139
  handleSelection(id, type) {
187
140
  const selectionType = this.props.selectionType;
188
141
  selectionType === 'single' && this.setState(state => {
189
142
  const selection = `${type}_${id}`;
190
-
191
143
  if (state.selection !== selection) {
192
144
  return {
193
145
  selection
@@ -197,50 +149,41 @@ let TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.defaul
197
149
  }
198
150
  });
199
151
  }
200
-
201
152
  getNavigableNodes() {
202
153
  return Array.from(this.ref.querySelectorAll('[role="treeitem"]'));
203
154
  }
204
-
205
155
  moveFocus(delta) {
206
156
  const nodes = this.getNavigableNodes();
207
157
  const closest = window.document.activeElement.closest('[role="treeitem"]');
208
158
  const active = nodes.indexOf(closest);
209
159
  let next = active + delta;
210
-
211
160
  if (next < 0) {
212
161
  next = 0;
213
162
  } else if (next >= nodes.length) {
214
163
  next = nodes.length - 1;
215
164
  }
216
-
217
165
  nodes.forEach(n => {
218
166
  n.setAttribute('tabindex', '-1');
219
167
  });
220
168
  nodes[next].setAttribute('tabindex', '0');
221
169
  nodes[next].focus();
222
170
  }
223
-
224
171
  homeOrEnd(keyCode) {
225
172
  const length = this.getNavigableNodes().length;
226
-
227
173
  if (keyCode === _keycode.default.codes.home) {
228
174
  this.moveFocus(1 - length);
229
175
  } else {
230
176
  this.moveFocus(length - 1);
231
177
  }
232
178
  }
233
-
234
179
  handleLeftOrRightArrow(keyCode, node) {
235
180
  const ltr = !(this.ref.parentElement.dir === 'rtl' || document.dir === 'rtl');
236
-
237
181
  if (ltr && keyCode === _keycode.default.codes.left || !ltr && keyCode == _keycode.default.codes.right) {
238
182
  this.handleCloseOrPrevious(node);
239
183
  } else {
240
184
  this.handleOpenOrNext(node);
241
185
  }
242
186
  }
243
-
244
187
  handleOpenOrNext(node) {
245
188
  if (node && !this.expanded.includes(node.id) && node.type === 'collection') {
246
189
  this.expandOrCollapseNode(node);
@@ -248,7 +191,6 @@ let TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.defaul
248
191
  this.moveFocus(1);
249
192
  }
250
193
  }
251
-
252
194
  handleCloseOrPrevious(node) {
253
195
  if (node && this.expanded.includes(node.id) && node.type === 'collection') {
254
196
  this.expandOrCollapseNode(node);
@@ -256,34 +198,30 @@ let TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.defaul
256
198
  this.moveFocus(-1);
257
199
  }
258
200
  }
259
-
260
201
  handleActivation(event, node) {
261
202
  if (node == null) return;
262
-
263
203
  if (node.type === 'collection') {
264
204
  this.handleCollectionClick(event, node, this.props.selectionType === 'none');
265
205
  } else {
266
206
  this.handleItemClick(event, node);
267
207
  }
268
208
  }
269
-
270
209
  getSubCollections(collection) {
271
210
  const collections = collection.collections ? [...collection.collections] : [];
272
211
  return collections.map(id => this.getCollectionProps(this.props.collections[id])).filter(collection => collection != null).sort(this.props.sortOrder);
273
212
  }
274
-
275
213
  getItems(collection) {
276
214
  if (collection.items) {
277
215
  const items = collection.items ? [...collection.items] : [];
278
216
  return items.map(id => {
279
- return { ...this.props.items[id]
217
+ return {
218
+ ...this.props.items[id]
280
219
  };
281
220
  }).filter(item => item != null).sort(this.props.sortOrder);
282
221
  } else {
283
222
  return [];
284
223
  }
285
224
  }
286
-
287
225
  getCollectionProps(collection) {
288
226
  return {
289
227
  id: collection.id,
@@ -299,11 +237,9 @@ let TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.defaul
299
237
  compareFunc: collection.compareFunc
300
238
  };
301
239
  }
302
-
303
240
  getExpandedIndex(expanded, id) {
304
241
  return expanded.findIndex(expanded => String(expanded) === String(id));
305
242
  }
306
-
307
243
  renderRoot() {
308
244
  return this.collections.sort(this.props.sortOrder).map((collection, i) => (0, _emotion.jsx)(_TreeCollection.TreeCollection, Object.assign({
309
245
  key: i
@@ -318,7 +254,6 @@ let TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.defaul
318
254
  renderContent: this.props.renderContent
319
255
  })));
320
256
  }
321
-
322
257
  render() {
323
258
  const styles = this.props.styles;
324
259
  return (0, _emotion.jsx)("ul", {
@@ -332,7 +267,6 @@ let TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.defaul
332
267
  "aria-label": this.props.treeLabel
333
268
  }, this.renderRoot());
334
269
  }
335
-
336
270
  }, _class2.displayName = "TreeBrowser", _class2.componentId = 'TreeBrowser', _class2.allowedProps = _props.allowedProps, _class2.propTypes = _props.propTypes, _class2.defaultProps = {
337
271
  size: 'medium',
338
272
  variant: 'folderTree',
@@ -10,9 +10,7 @@ Object.defineProperty(exports, "TreeBrowserLocator", {
10
10
  }
11
11
  });
12
12
  exports.default = void 0;
13
-
14
13
  var _TreeBrowserLocator = require("./TreeBrowserLocator");
15
-
16
14
  /*
17
15
  * The MIT License (MIT)
18
16
  *
@@ -1,16 +1,12 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.propTypes = exports.allowedProps = void 0;
9
-
10
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
-
12
9
  var _controllable = require("@instructure/ui-prop-types/lib/controllable.js");
13
-
14
10
  /*
15
11
  * The MIT License (MIT)
16
12
  *
@@ -34,6 +30,7 @@ var _controllable = require("@instructure/ui-prop-types/lib/controllable.js");
34
30
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35
31
  * SOFTWARE.
36
32
  */
33
+
37
34
  const propTypes = {
38
35
  collections: _propTypes.default.object.isRequired,
39
36
  items: _propTypes.default.object.isRequired,
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  /*
9
8
  * The MIT License (MIT)
10
9
  *
@@ -39,6 +38,7 @@ exports.default = void 0;
39
38
  * @param {Object} state the state of the component, the style is applied to
40
39
  * @return {Object} The final style object, which will be used in the component
41
40
  */
41
+
42
42
  const generateStyles = componentTheme => {
43
43
  return {
44
44
  treeBrowser: {
@@ -72,6 +72,5 @@ const generateStyles = componentTheme => {
72
72
  }
73
73
  };
74
74
  };
75
-
76
75
  var _default = generateStyles;
77
76
  exports.default = _default;
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  /*
9
8
  * The MIT License (MIT)
10
9
  *
@@ -36,16 +35,16 @@ exports.default = void 0;
36
35
  */
37
36
  const generateComponentTheme = theme => {
38
37
  const colors = theme.colors,
39
- borders = theme.borders;
38
+ borders = theme.borders;
40
39
  const componentVariables = {
41
40
  borderRadius: borders === null || borders === void 0 ? void 0 : borders.radiusMedium,
42
41
  focusOutlineWidth: borders === null || borders === void 0 ? void 0 : borders.widthMedium,
43
42
  focusOutlineColor: colors === null || colors === void 0 ? void 0 : colors.borderBrand,
44
43
  focusOutlineStyle: borders === null || borders === void 0 ? void 0 : borders.style
45
44
  };
46
- return { ...componentVariables
45
+ return {
46
+ ...componentVariables
47
47
  };
48
48
  };
49
-
50
49
  var _default = generateComponentTheme;
51
50
  exports.default = _default;
package/lib/index.js CHANGED
@@ -9,5 +9,4 @@ Object.defineProperty(exports, "TreeBrowser", {
9
9
  return _TreeBrowser.TreeBrowser;
10
10
  }
11
11
  });
12
-
13
12
  var _TreeBrowser = require("./TreeBrowser");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-tree-browser",
3
- "version": "8.33.1",
3
+ "version": "8.33.2",
4
4
  "description": "A component for displaying a hierarchical view of information",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -23,22 +23,22 @@
23
23
  },
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
- "@instructure/ui-babel-preset": "8.33.1",
27
- "@instructure/ui-color-utils": "8.33.1",
28
- "@instructure/ui-test-locator": "8.33.1",
29
- "@instructure/ui-test-utils": "8.33.1",
30
- "@instructure/ui-themes": "8.33.1"
26
+ "@instructure/ui-babel-preset": "8.33.2",
27
+ "@instructure/ui-color-utils": "8.33.2",
28
+ "@instructure/ui-test-locator": "8.33.2",
29
+ "@instructure/ui-test-utils": "8.33.2",
30
+ "@instructure/ui-themes": "8.33.2"
31
31
  },
32
32
  "dependencies": {
33
33
  "@babel/runtime": "^7.13.10",
34
- "@instructure/emotion": "8.33.1",
35
- "@instructure/shared-types": "8.33.1",
36
- "@instructure/ui-icons": "8.33.1",
37
- "@instructure/ui-img": "8.33.1",
38
- "@instructure/ui-prop-types": "8.33.1",
39
- "@instructure/ui-react-utils": "8.33.1",
40
- "@instructure/ui-testable": "8.33.1",
41
- "@instructure/ui-utils": "8.33.1",
34
+ "@instructure/emotion": "8.33.2",
35
+ "@instructure/shared-types": "8.33.2",
36
+ "@instructure/ui-icons": "8.33.2",
37
+ "@instructure/ui-img": "8.33.2",
38
+ "@instructure/ui-prop-types": "8.33.2",
39
+ "@instructure/ui-react-utils": "8.33.2",
40
+ "@instructure/ui-testable": "8.33.2",
41
+ "@instructure/ui-utils": "8.33.2",
42
42
  "keycode": "^2",
43
43
  "prop-types": "^15"
44
44
  },