@instructure/ui-tree-browser 8.14.1-snapshot.7 → 8.15.1-snapshot.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 (44) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/es/TreeBrowser/TreeBrowserLocator.js +2 -1
  3. package/es/TreeBrowser/TreeButton/index.js +14 -15
  4. package/es/TreeBrowser/TreeCollection/index.js +18 -31
  5. package/es/TreeBrowser/TreeCollection/props.js +1 -9
  6. package/es/TreeBrowser/TreeNode/index.js +10 -13
  7. package/es/TreeBrowser/TreeNode/props.js +0 -8
  8. package/es/TreeBrowser/index.js +36 -32
  9. package/es/TreeBrowser/props.js +0 -55
  10. package/lib/TreeBrowser/TreeBrowserLocator.js +2 -1
  11. package/lib/TreeBrowser/TreeButton/index.js +14 -14
  12. package/lib/TreeBrowser/TreeCollection/index.js +17 -30
  13. package/lib/TreeBrowser/TreeCollection/props.js +1 -9
  14. package/lib/TreeBrowser/TreeNode/index.js +10 -12
  15. package/lib/TreeBrowser/TreeNode/props.js +0 -8
  16. package/lib/TreeBrowser/index.js +37 -33
  17. package/lib/TreeBrowser/props.js +0 -55
  18. package/package.json +15 -15
  19. package/src/TreeBrowser/TreeButton/index.tsx +21 -36
  20. package/src/TreeBrowser/TreeButton/props.ts +11 -10
  21. package/src/TreeBrowser/TreeCollection/index.tsx +57 -108
  22. package/src/TreeBrowser/TreeCollection/props.ts +17 -32
  23. package/src/TreeBrowser/TreeNode/index.tsx +10 -21
  24. package/src/TreeBrowser/TreeNode/props.ts +5 -7
  25. package/src/TreeBrowser/index.tsx +81 -108
  26. package/src/TreeBrowser/props.ts +133 -59
  27. package/tsconfig.build.tsbuildinfo +1 -1
  28. package/types/TreeBrowser/TreeBrowserLocator.d.ts +14 -14
  29. package/types/TreeBrowser/TreeButton/index.d.ts +5 -51
  30. package/types/TreeBrowser/TreeButton/index.d.ts.map +1 -1
  31. package/types/TreeBrowser/TreeButton/props.d.ts +11 -10
  32. package/types/TreeBrowser/TreeButton/props.d.ts.map +1 -1
  33. package/types/TreeBrowser/TreeCollection/index.d.ts +33 -85
  34. package/types/TreeBrowser/TreeCollection/index.d.ts.map +1 -1
  35. package/types/TreeBrowser/TreeCollection/props.d.ts +11 -25
  36. package/types/TreeBrowser/TreeCollection/props.d.ts.map +1 -1
  37. package/types/TreeBrowser/TreeNode/index.d.ts +4 -12
  38. package/types/TreeBrowser/TreeNode/index.d.ts.map +1 -1
  39. package/types/TreeBrowser/TreeNode/props.d.ts +5 -1
  40. package/types/TreeBrowser/TreeNode/props.d.ts.map +1 -1
  41. package/types/TreeBrowser/index.d.ts +35 -73
  42. package/types/TreeBrowser/index.d.ts.map +1 -1
  43. package/types/TreeBrowser/props.d.ts +113 -16
  44. package/types/TreeBrowser/props.d.ts.map +1 -1
package/CHANGELOG.md CHANGED
@@ -3,6 +3,10 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [8.15.0](https://github.com/instructure/instructure-ui/compare/v8.14.0...v8.15.0) (2022-01-26)
7
+
8
+ **Note:** Version bump only for package @instructure/ui-tree-browser
9
+
6
10
  # [8.14.0](https://github.com/instructure/instructure-ui/compare/v8.13.0...v8.14.0) (2021-12-16)
7
11
 
8
12
  **Note:** Version bump only for package @instructure/ui-tree-browser
@@ -24,7 +24,8 @@
24
24
  import { locator } from '@instructure/ui-test-locator';
25
25
  import { TreeBrowser } from './index'; // TODO: if we make a TreeBrowserItem component + locator we could use it here.
26
26
 
27
- const TreeBrowserItemLocator = locator('[role="treeitem"]');
27
+ const TreeBrowserItemLocator = locator('[role="treeitem"]'); // @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
28
+
28
29
  export const TreeBrowserLocator = locator(TreeBrowser.selector, {
29
30
  findAllItems: function () {
30
31
  return TreeBrowserItemLocator.findAll(...arguments);
@@ -32,14 +32,15 @@ import { callRenderProp } from '@instructure/ui-react-utils';
32
32
  import { withStyle, jsx } from '@instructure/emotion';
33
33
  import generateStyles from './styles';
34
34
  import generateComponentTheme from './theme';
35
- import { allowedProps, propTypes } from './props';
35
+ import { allowedProps, propTypes } from './props'; // Todo: merge TreeButton and TreeNode: TreeButton should be a special type of TreeNode
36
+
36
37
  /**
37
38
  ---
38
39
  parent: TreeBrowser
39
40
  id: TreeBrowser.Button
40
41
  ---
42
+ @tsProps
41
43
  **/
42
- // Todo: merge TreeButton and TreeNode: TreeButton should be a special type of TreeNode
43
44
 
44
45
  let TreeButton = (_dec = withStyle(generateStyles, generateComponentTheme), _dec2 = testable(), _dec(_class = _dec2(_class = (_temp = _class2 = class TreeButton extends Component {
45
46
  constructor() {
@@ -47,7 +48,10 @@ let TreeButton = (_dec = withStyle(generateStyles, generateComponentTheme), _dec
47
48
  this.ref = null;
48
49
 
49
50
  this.handleRef = el => {
50
- el && this.props.containerRef(el.parentElement);
51
+ if (el && typeof this.props.containerRef === 'function') {
52
+ this.props.containerRef(el.parentElement);
53
+ }
54
+
51
55
  this.ref = el;
52
56
  };
53
57
  }
@@ -93,6 +97,8 @@ let TreeButton = (_dec = withStyle(generateStyles, generateComponentTheme), _dec
93
97
  default:
94
98
  break;
95
99
  }
100
+
101
+ return void 0;
96
102
  }
97
103
 
98
104
  renderCollectionIcon() {
@@ -107,6 +113,8 @@ let TreeButton = (_dec = withStyle(generateStyles, generateComponentTheme), _dec
107
113
  css: styles === null || styles === void 0 ? void 0 : styles.icon
108
114
  }, callRenderProp(expanded ? collectionIconExpanded : collectionIcon));
109
115
  }
116
+
117
+ return void 0;
110
118
  }
111
119
 
112
120
  renderItemImage() {
@@ -132,6 +140,8 @@ let TreeButton = (_dec = withStyle(generateStyles, generateComponentTheme), _dec
132
140
  css: styles === null || styles === void 0 ? void 0 : styles.icon
133
141
  }, callRenderProp(itemIcon));
134
142
  }
143
+
144
+ return void 0;
135
145
  }
136
146
 
137
147
  render() {
@@ -154,18 +164,7 @@ let TreeButton = (_dec = withStyle(generateStyles, generateComponentTheme), _dec
154
164
  variant: 'folderTree',
155
165
  selected: false,
156
166
  focused: false,
157
- onClick: function () {},
158
- id: void 0,
159
- name: void 0,
160
- collectionIcon: void 0,
161
- collectionIconExpanded: void 0,
162
- itemIcon: void 0,
163
- thumbnail: void 0,
164
- expanded: false,
165
- descriptor: void 0,
166
- level: void 0,
167
- containerRef: function () {},
168
- renderContent: void 0
167
+ expanded: false
169
168
  }, _temp)) || _class) || _class);
170
169
  export default TreeButton;
171
170
  export { TreeButton };
@@ -36,13 +36,14 @@ import { TreeButton } from '../TreeButton';
36
36
  import generateStyles from './styles';
37
37
  import generateComponentTheme from './theme';
38
38
  import { allowedProps, propTypes } from './props';
39
+
39
40
  /**
40
41
  ---
41
42
  parent: TreeBrowser
42
43
  id: TreeBrowser.Collection
43
44
  ---
45
+ @tsProps
44
46
  **/
45
-
46
47
  let TreeCollection = (_dec = withStyle(generateStyles, generateComponentTheme), _dec2 = testable(), _dec(_class = _dec2(_class = (_temp = _class2 = class TreeCollection extends Component {
47
48
  constructor(props) {
48
49
  super(props);
@@ -55,7 +56,7 @@ let TreeCollection = (_dec = withStyle(generateStyles, generateComponentTheme),
55
56
  });
56
57
  };
57
58
 
58
- this.handleBlur = (e, item) => {
59
+ this.handleBlur = (e, _item) => {
59
60
  e.stopPropagation();
60
61
  this.setState({
61
62
  focused: ''
@@ -174,12 +175,13 @@ let TreeCollection = (_dec = withStyle(generateStyles, generateComponentTheme),
174
175
  id: key,
175
176
  role: "treeitem",
176
177
  css: styles === null || styles === void 0 ? void 0 : styles.item,
177
- tabIndex: "-1",
178
+ tabIndex: -1,
178
179
  key: key,
179
180
  "aria-posinset": position,
180
181
  "aria-setsize": this.childCount,
181
182
  "aria-level": this.itemsLevel
182
183
  }, ariaSelected, {
184
+ // @ts-expect-error ts-migrate(2322) FIXME: Type '(e: any, n: any) => void' is not assignable ... Remove this comment to see the full error message
183
185
  onClick: (e, n) => {
184
186
  if (typeof child.props.onClick === 'function') {
185
187
  child.props.onClick(e, n);
@@ -187,15 +189,16 @@ let TreeCollection = (_dec = withStyle(generateStyles, generateComponentTheme),
187
189
  e.stopPropagation();
188
190
  }
189
191
  },
190
- onFocus: (e, n) => this.handleFocus(e, itemHash),
192
+ onFocus: e => this.handleFocus(e, itemHash) // @ts-expect-error ts-migrate(2322) FIXME: Type '(e: any, n: any) => void' is not assignable ... Remove this comment to see the full error message
193
+ ,
191
194
  onKeyDown: (e, n) => {
192
195
  if (typeof child.props.onKeyDown === 'function') {
193
196
  child.props.onKeyDown(e, n);
194
197
  } else {
195
- onKeyDown(e, itemHash);
198
+ onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e, itemHash);
196
199
  }
197
200
  },
198
- onBlur: (e, n) => this.handleBlur(e, itemHash)
201
+ onBlur: e => this.handleBlur(e, itemHash)
199
202
  }), safeCloneElement(child, itemProps));
200
203
  }
201
204
 
@@ -247,17 +250,17 @@ let TreeCollection = (_dec = withStyle(generateStyles, generateComponentTheme),
247
250
  });
248
251
  return jsx("li", Object.assign({
249
252
  key: `i${position}`,
250
- tabIndex: "-1",
253
+ tabIndex: -1,
251
254
  role: "treeitem",
252
255
  "aria-label": item.name,
253
256
  css: styles === null || styles === void 0 ? void 0 : styles.item,
254
257
  "aria-level": this.itemsLevel,
255
258
  "aria-posinset": position,
256
259
  "aria-setsize": this.childCount,
257
- onClick: (e, n) => onItemClick(e, itemHash),
258
- onKeyDown: (e, n) => onKeyDown(e, itemHash),
259
- onFocus: (e, n) => this.handleFocus(e, itemHash),
260
- onBlur: (e, n) => this.handleBlur(e, itemHash)
260
+ onClick: e => onItemClick === null || onItemClick === void 0 ? void 0 : onItemClick(e, itemHash),
261
+ onKeyDown: e => onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e, itemHash),
262
+ onFocus: e => this.handleFocus(e, itemHash),
263
+ onBlur: e => this.handleBlur(e, itemHash)
261
264
  }, ariaSelected), jsx(TreeButton, itemProps));
262
265
  }
263
266
 
@@ -303,7 +306,7 @@ let TreeCollection = (_dec = withStyle(generateStyles, generateComponentTheme),
303
306
  this.ref = el;
304
307
  },
305
308
  css: styles === null || styles === void 0 ? void 0 : styles.treeCollection,
306
- tabIndex: "-1",
309
+ tabIndex: -1,
307
310
  role: "treeitem",
308
311
  "aria-label": this.props.name,
309
312
  "aria-level": level,
@@ -312,11 +315,11 @@ let TreeCollection = (_dec = withStyle(generateStyles, generateComponentTheme),
312
315
  "aria-expanded": expanded,
313
316
  onClick: this.handleCollectionClick,
314
317
  onKeyDown: this.handleCollectionKeyDown,
315
- onFocus: (e, n) => this.handleFocus(e, {
318
+ onFocus: e => this.handleFocus(e, {
316
319
  id: id,
317
320
  type: 'collection'
318
321
  }),
319
- onBlur: (e, n) => this.handleBlur(e, {
322
+ onBlur: e => this.handleBlur(e, {
320
323
  id: id,
321
324
  type: 'collection'
322
325
  })
@@ -334,25 +337,9 @@ let TreeCollection = (_dec = withStyle(generateStyles, generateComponentTheme),
334
337
  selection: '',
335
338
  size: 'medium',
336
339
  variant: 'folderTree',
337
- onItemClick: function () {},
338
- onCollectionClick: function () {},
339
- onKeyDown: function () {},
340
- id: void 0,
341
- name: void 0,
342
- descriptor: void 0,
343
- collectionIconExpanded: void 0,
344
- collectionIcon: void 0,
345
- itemIcon: void 0,
346
340
  getItemProps: props => props,
347
341
  getCollectionProps: props => props,
348
- numChildren: void 0,
349
- level: void 0,
350
- position: void 0,
351
- renderBeforeItems: null,
352
- renderAfterItems: null,
353
- containerRef: function () {},
354
- isCollectionFlattened: false,
355
- renderContent: void 0
342
+ isCollectionFlattened: false
356
343
  }, _temp)) || _class) || _class);
357
344
  export default TreeCollection;
358
345
  export { TreeCollection };
@@ -43,17 +43,9 @@ const propTypes = {
43
43
  onCollectionClick: PropTypes.func,
44
44
  onKeyDown: PropTypes.func,
45
45
  numChildren: PropTypes.number,
46
- level: PropTypes.number,
46
+ level: PropTypes.number.isRequired,
47
47
  position: PropTypes.number,
48
-
49
- /**
50
- * children of type TreeNode
51
- */
52
48
  renderBeforeItems: Children.oneOf([TreeNode]),
53
-
54
- /**
55
- * children of type TreeNode
56
- */
57
49
  renderAfterItems: Children.oneOf([TreeNode]),
58
50
  containerRef: PropTypes.func,
59
51
  isCollectionFlattened: PropTypes.bool,
@@ -33,16 +33,17 @@ import { testable } from '@instructure/ui-testable';
33
33
  import { withStyle, jsx } from '@instructure/emotion';
34
34
  import generateStyles from '../TreeButton/styles';
35
35
  import generateComponentTheme from '../TreeButton/theme';
36
- import { allowedProps, propTypes } from './props';
36
+ import { allowedProps, propTypes } from './props'; // Todo: merge TreeButton and TreeNode: TreeButton should be a special type of TreeNode
37
+
37
38
  /**
38
39
  ---
39
40
  parent: TreeBrowser
40
41
  id: TreeBrowser.Node
41
42
  ---
43
+ @tsProps
42
44
  A helper class used to render the :renderBeforeItems and :renderAfterItems
43
45
  in the TreeBrowser.
44
46
  **/
45
- // Todo: merge TreeButton and TreeNode: TreeButton should be a special type of TreeNode
46
47
 
47
48
  let TreeNode = (_dec = withStyle(generateStyles, generateComponentTheme), _dec2 = testable(), _dec(_class = _dec2(_class = (_temp = _class2 = class TreeNode extends Component {
48
49
  constructor() {
@@ -50,7 +51,10 @@ let TreeNode = (_dec = withStyle(generateStyles, generateComponentTheme), _dec2
50
51
  this.ref = null;
51
52
 
52
53
  this.handleRef = el => {
53
- el && this.props.containerRef(el.parentElement);
54
+ if (el && typeof this.props.containerRef === 'function') {
55
+ this.props.containerRef(el.parentElement);
56
+ }
57
+
54
58
  this.ref = el;
55
59
  };
56
60
  }
@@ -90,6 +94,8 @@ let TreeNode = (_dec = withStyle(generateStyles, generateComponentTheme), _dec2
90
94
  css: styles === null || styles === void 0 ? void 0 : styles.icon
91
95
  }, callRenderProp(itemIcon));
92
96
  }
97
+
98
+ return void 0;
93
99
  }
94
100
 
95
101
  render() {
@@ -108,19 +114,10 @@ let TreeNode = (_dec = withStyle(generateStyles, generateComponentTheme), _dec2
108
114
  }
109
115
 
110
116
  }, _class2.displayName = "TreeNode", _class2.componentId = 'TreeBrowser.Node', _class2.allowedProps = allowedProps, _class2.propTypes = propTypes, _class2.defaultProps = {
111
- id: void 0,
112
117
  size: 'medium',
113
118
  variant: 'folderTree',
114
119
  selected: false,
115
- focused: false,
116
- children: void 0,
117
- itemIcon: void 0,
118
- thumbnail: void 0,
119
- level: void 0,
120
- containerRef: function () {},
121
- parentRef: void 0,
122
- onKeyDown: void 0,
123
- onClick: void 0
120
+ focused: false
124
121
  }, _temp)) || _class) || _class);
125
122
  export default TreeNode;
126
123
  export { TreeNode };
@@ -31,15 +31,7 @@ const propTypes = {
31
31
  itemIcon: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
32
32
  thumbnail: PropTypes.string,
33
33
  level: PropTypes.number,
34
-
35
- /**
36
- * The children to be rendered within the `<TreeNode />`
37
- */
38
34
  children: PropTypes.node,
39
-
40
- /**
41
- * A function that returns a reference to the parent li element
42
- */
43
35
  containerRef: PropTypes.func,
44
36
  onKeyDown: PropTypes.func,
45
37
  onClick: PropTypes.func
@@ -28,7 +28,7 @@ var _dec, _dec2, _class, _class2, _temp;
28
28
  import { Component } from 'react';
29
29
  import keycode from 'keycode';
30
30
  import { IconFolderLine, IconDocumentLine } from '@instructure/ui-icons';
31
- import { pickProps, omitProps } from '@instructure/ui-react-utils';
31
+ import { omitProps, pickProps } from '@instructure/ui-react-utils';
32
32
  import { testable } from '@instructure/ui-testable';
33
33
  import { withStyle, jsx } from '@instructure/emotion';
34
34
  import { TreeCollection } from './TreeCollection';
@@ -41,6 +41,7 @@ import { allowedProps, propTypes } from './props';
41
41
  ---
42
42
  category: components
43
43
  ---
44
+ @tsProps
44
45
  **/
45
46
 
46
47
  let TreeBrowser = (_dec = withStyle(generateStyles, generateComponentTheme), _dec2 = testable(), _dec(_class = _dec2(_class = (_temp = _class2 = class TreeBrowser extends Component {
@@ -56,16 +57,17 @@ let TreeBrowser = (_dec = withStyle(generateStyles, generateComponentTheme), _de
56
57
  e.stopPropagation();
57
58
  const onCollectionClick = _this.props.onCollectionClick;
58
59
  if (expand) _this.expandOrCollapseNode(collection);
59
- onCollectionClick(collection.id, collection); // TODO: this should pass the event as the first arg
60
+ onCollectionClick === null || onCollectionClick === void 0 ? void 0 : onCollectionClick(collection.id, collection); // TODO: this should pass the event as the first arg
60
61
 
61
62
  _this.handleSelection(collection.id, 'collection');
62
63
  };
63
64
 
64
65
  this.handleItemClick = (e, item) => {
66
+ var _this$props$onItemCli, _this$props;
67
+
65
68
  e.stopPropagation();
66
- const onItemClick = this.props.onItemClick;
67
- onItemClick(item);
68
- this.handleSelection(item.id, 'item'); // TODO: this should pass the event as the first arg
69
+ (_this$props$onItemCli = (_this$props = this.props).onItemClick) === null || _this$props$onItemCli === void 0 ? void 0 : _this$props$onItemCli.call(_this$props, item);
70
+ this.handleSelection(item.id, 'item');
69
71
  };
70
72
 
71
73
  this.handleKeyDown = (event, node) => {
@@ -105,31 +107,34 @@ let TreeBrowser = (_dec = withStyle(generateStyles, generateComponentTheme), _de
105
107
  };
106
108
 
107
109
  this.getIsFlattened = collection => {
108
- const _this$props = this.props,
109
- rootId = _this$props.rootId,
110
- showRootCollection = _this$props.showRootCollection;
110
+ const _this$props2 = this.props,
111
+ rootId = _this$props2.rootId,
112
+ showRootCollection = _this$props2.showRootCollection;
111
113
  return !showRootCollection && typeof rootId !== 'undefined' && collection.id === rootId;
112
114
  };
113
115
 
114
- this.state = {
115
- selection: ''
116
- };
117
-
118
116
  if (typeof this.props.expanded === 'undefined') {
119
- this.state.expanded = props.defaultExpanded;
117
+ this.state = {
118
+ expanded: this.props.defaultExpanded,
119
+ selection: ''
120
+ };
121
+ } else {
122
+ this.state = {
123
+ selection: ''
124
+ };
120
125
  }
121
126
  }
122
127
 
123
128
  componentDidMount() {
124
- var _this$props$makeStyle, _this$props2;
129
+ var _this$props$makeStyle, _this$props3;
125
130
 
126
- (_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
131
+ (_this$props$makeStyle = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props3);
127
132
  }
128
133
 
129
134
  componentDidUpdate() {
130
- var _this$props$makeStyle2, _this$props3;
135
+ var _this$props$makeStyle2, _this$props4;
131
136
 
132
- (_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
137
+ (_this$props$makeStyle2 = (_this$props4 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props4);
133
138
  }
134
139
 
135
140
  get _root() {
@@ -137,9 +142,9 @@ let TreeBrowser = (_dec = withStyle(generateStyles, generateComponentTheme), _de
137
142
  }
138
143
 
139
144
  get collections() {
140
- const _this$props4 = this.props,
141
- collections = _this$props4.collections,
142
- rootId = _this$props4.rootId;
145
+ const _this$props5 = this.props,
146
+ collections = _this$props5.collections,
147
+ rootId = _this$props5.rootId;
143
148
 
144
149
  if (typeof rootId !== 'undefined') {
145
150
  return [collections[rootId]];
@@ -157,11 +162,13 @@ let TreeBrowser = (_dec = withStyle(generateStyles, generateComponentTheme), _de
157
162
  }
158
163
 
159
164
  expandOrCollapseNode(collection) {
160
- this.props.onCollectionToggle(collection);
165
+ var _this$props$onCollect, _this$props6;
166
+
167
+ (_this$props$onCollect = (_this$props6 = this.props).onCollectionToggle) === null || _this$props$onCollect === void 0 ? void 0 : _this$props$onCollect.call(_this$props6, collection);
161
168
 
162
169
  if (typeof this.props.expanded === 'undefined') {
163
170
  this.setState((state, props) => {
164
- const expanded = [].concat(this.getExpanded(state, props));
171
+ const expanded = [...this.getExpanded(state, props)];
165
172
  const expandedIndex = this.getExpandedIndex(expanded, collection.id);
166
173
 
167
174
  if (collection.expanded && expandedIndex < 0) {
@@ -262,13 +269,13 @@ let TreeBrowser = (_dec = withStyle(generateStyles, generateComponentTheme), _de
262
269
  }
263
270
 
264
271
  getSubCollections(collection) {
265
- const collections = [].concat(collection.collections || []);
272
+ const collections = collection.collections ? [...collection.collections] : [];
266
273
  return collections.map(id => this.getCollectionProps(this.props.collections[id])).filter(collection => collection != null).sort(this.props.sortOrder);
267
274
  }
268
275
 
269
276
  getItems(collection) {
270
277
  if (collection.items) {
271
- const items = [].concat(collection.items);
278
+ const items = collection.items ? [...collection.items] : [];
272
279
  return items.map(id => {
273
280
  return { ...this.props.items[id]
274
281
  };
@@ -282,13 +289,13 @@ let TreeBrowser = (_dec = withStyle(generateStyles, generateComponentTheme), _de
282
289
  return {
283
290
  id: collection.id,
284
291
  name: collection.name,
285
- descriptor: collection.descriptor,
286
- expanded: this.getExpandedIndex(this.expanded, collection.id) >= 0,
287
- items: this.getItems(collection),
288
292
  collections: this.getSubCollections(collection),
293
+ items: this.getItems(collection),
294
+ descriptor: collection.descriptor,
295
+ containerRef: collection.containerRef,
289
296
  renderBeforeItems: collection.renderBeforeItems,
290
297
  renderAfterItems: collection.renderAfterItems,
291
- containerRef: collection.containerRef,
298
+ expanded: this.getExpandedIndex(this.expanded, collection.id) >= 0,
292
299
  isCollectionFlattened: this.getIsFlattened(collection)
293
300
  };
294
301
  }
@@ -337,10 +344,7 @@ let TreeBrowser = (_dec = withStyle(generateStyles, generateComponentTheme), _de
337
344
  getCollectionProps: props => props,
338
345
  defaultExpanded: [],
339
346
  selectionType: 'none',
340
- onItemClick: function (item) {},
341
- onCollectionClick: function (id, collection) {},
342
- onCollectionToggle: function (collection) {},
343
- sortOrder: function (obj1, obj2) {
347
+ sortOrder: function () {
344
348
  return 0;
345
349
  }
346
350
  }, _class2.Node = TreeNode, _class2.Collection = TreeCollection, _class2.Button = TreeButton, _temp)) || _class) || _class);
@@ -24,80 +24,25 @@
24
24
  import PropTypes from 'prop-types';
25
25
  import { controllable } from '@instructure/ui-prop-types';
26
26
  const propTypes = {
27
- /**
28
- * a normalized hash of collections, keyed by id, that contain an
29
- * :id, :name, :items (an array of item ids), :collections (an array of
30
- * collection ids), optional :descriptor text, optional :containerRef function,
31
- * an optional :renderBeforeItems TreeNode, and an optional :renderAfterItems TreeNode.
32
- * Each collection must have a unique id.
33
- */
34
27
  collections: PropTypes.object.isRequired,
35
-
36
- /**
37
- * a hash of items, keyed by id, that contain an :id, :name,
38
- * optional :descriptor text, and optional :thumbnail url
39
- */
40
28
  items: PropTypes.object.isRequired,
41
-
42
- /**
43
- * specifies the id of the root level collection, if present.
44
- * if no root is specified, all collections will be rendered
45
- * at the top level
46
- **/
47
29
  rootId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
48
-
49
- /**
50
- * an array of expanded collection ids, must be accompanied by an 'onCollectionToggle' prop
51
- */
52
30
  expanded: controllable(PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])), 'onCollectionToggle'),
53
-
54
- /**
55
- * an array of collection ids to expand by default
56
- */
57
31
  defaultExpanded: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])),
58
- // There are 2 types of tree selection: single and multi.
59
- // This is set up to allow for "multi" in the future without having to deprecate the old API.
60
32
  selectionType: PropTypes.oneOf(['none', 'single']),
61
33
  size: PropTypes.oneOf(['small', 'medium', 'large']),
62
34
  variant: PropTypes.oneOf(['folderTree', 'indent']),
63
35
  collectionIcon: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
64
36
  collectionIconExpanded: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
65
37
  itemIcon: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
66
-
67
- /**
68
- * A function called with each item's props as an argument. The return value of this function is a
69
- * props object which will be passed to the item when it is rendered. This is useful for situations where
70
- * you need to render the item differently depending on it's props. For example, if you would like to
71
- * display a different icon for items with a certain name.
72
- */
73
38
  getItemProps: PropTypes.func,
74
-
75
- /**
76
- * A function called with each collection's props as an argument. The return value of this function is a
77
- * props object which will be passed to the collection when it is rendered. This is useful for situations where
78
- * you need to render the collection differently depending on it's props. For example, if you would like to
79
- * display a different icon for collections with a certain name.
80
- */
81
39
  getCollectionProps: PropTypes.func,
82
-
83
- /**
84
- * whether or not to show the root collection specified in rootId prop or
85
- * to begin with its immediate subcollections and items instead
86
- */
87
40
  showRootCollection: PropTypes.bool,
88
41
  onCollectionClick: PropTypes.func,
89
42
  onCollectionToggle: PropTypes.func,
90
43
  onItemClick: PropTypes.func,
91
-
92
- /**
93
- * An optional label to assist visually impaired users
94
- */
95
44
  treeLabel: PropTypes.string,
96
45
  renderContent: PropTypes.func,
97
-
98
- /**
99
- * An optional compare function to specify order of the collections and the items
100
- */
101
46
  sortOrder: PropTypes.func
102
47
  };
103
48
  const allowedProps = ['collections', 'items', 'rootId', 'expanded', 'defaultExpanded', 'selectionType', 'size', 'variant', 'collectionIcon', 'collectionIconExpanded', 'itemIcon', 'getItemProps', 'getCollectionProps', 'showRootCollection', 'onCollectionClick', 'onCollectionToggle', 'onItemClick', 'treeLabel', 'renderContent', 'sortOrder'];
@@ -33,7 +33,8 @@ var _index = require("./index");
33
33
  * SOFTWARE.
34
34
  */
35
35
  // TODO: if we make a TreeBrowserItem component + locator we could use it here.
36
- const TreeBrowserItemLocator = (0, _locator.locator)('[role="treeitem"]');
36
+ const TreeBrowserItemLocator = (0, _locator.locator)('[role="treeitem"]'); // @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
37
+
37
38
  const TreeBrowserLocator = (0, _locator.locator)(_index.TreeBrowser.selector, {
38
39
  findAllItems: function () {
39
40
  return TreeBrowserItemLocator.findAll(...arguments);
@@ -25,20 +25,25 @@ var _props = require("./props");
25
25
 
26
26
  var _dec, _dec2, _class, _class2, _temp;
27
27
 
28
+ // Todo: merge TreeButton and TreeNode: TreeButton should be a special type of TreeNode
29
+
28
30
  /**
29
31
  ---
30
32
  parent: TreeBrowser
31
33
  id: TreeBrowser.Button
32
34
  ---
35
+ @tsProps
33
36
  **/
34
- // Todo: merge TreeButton and TreeNode: TreeButton should be a special type of TreeNode
35
37
  let TreeButton = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = (_temp = _class2 = class TreeButton extends _react.Component {
36
38
  constructor() {
37
39
  super(...arguments);
38
40
  this.ref = null;
39
41
 
40
42
  this.handleRef = el => {
41
- el && this.props.containerRef(el.parentElement);
43
+ if (el && typeof this.props.containerRef === 'function') {
44
+ this.props.containerRef(el.parentElement);
45
+ }
46
+
42
47
  this.ref = el;
43
48
  };
44
49
  }
@@ -84,6 +89,8 @@ let TreeButton = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default
84
89
  default:
85
90
  break;
86
91
  }
92
+
93
+ return void 0;
87
94
  }
88
95
 
89
96
  renderCollectionIcon() {
@@ -98,6 +105,8 @@ let TreeButton = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default
98
105
  css: styles === null || styles === void 0 ? void 0 : styles.icon
99
106
  }, (0, _callRenderProp.callRenderProp)(expanded ? collectionIconExpanded : collectionIcon));
100
107
  }
108
+
109
+ return void 0;
101
110
  }
102
111
 
103
112
  renderItemImage() {
@@ -123,6 +132,8 @@ let TreeButton = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default
123
132
  css: styles === null || styles === void 0 ? void 0 : styles.icon
124
133
  }, (0, _callRenderProp.callRenderProp)(itemIcon));
125
134
  }
135
+
136
+ return void 0;
126
137
  }
127
138
 
128
139
  render() {
@@ -145,18 +156,7 @@ let TreeButton = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default
145
156
  variant: 'folderTree',
146
157
  selected: false,
147
158
  focused: false,
148
- onClick: function () {},
149
- id: void 0,
150
- name: void 0,
151
- collectionIcon: void 0,
152
- collectionIconExpanded: void 0,
153
- itemIcon: void 0,
154
- thumbnail: void 0,
155
- expanded: false,
156
- descriptor: void 0,
157
- level: void 0,
158
- containerRef: function () {},
159
- renderContent: void 0
159
+ expanded: false
160
160
  }, _temp)) || _class) || _class);
161
161
  exports.TreeButton = TreeButton;
162
162
  var _default = TreeButton;