@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,32 +1,20 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
-
5
4
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
6
-
7
5
  Object.defineProperty(exports, "__esModule", {
8
6
  value: true
9
7
  });
10
8
  exports.default = exports.TreeCollection = void 0;
11
-
12
9
  var _react = _interopRequireWildcard(require("react"));
13
-
14
10
  var _testable = require("@instructure/ui-testable/lib/testable.js");
15
-
16
11
  var _emotion = require("@instructure/emotion");
17
-
18
12
  var _safeCloneElement = require("@instructure/ui-react-utils/lib/safeCloneElement.js");
19
-
20
13
  var _TreeButton = require("../TreeButton");
21
-
22
14
  var _styles = _interopRequireDefault(require("./styles"));
23
-
24
15
  var _theme = _interopRequireDefault(require("./theme"));
25
-
26
16
  var _props = require("./props");
27
-
28
17
  var _dec, _dec2, _class, _class2;
29
-
30
18
  /**
31
19
  ---
32
20
  parent: TreeBrowser
@@ -38,104 +26,90 @@ let TreeCollection = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.def
38
26
  constructor(props) {
39
27
  super(props);
40
28
  this.ref = null;
41
-
42
29
  this.handleFocus = (e, item) => {
43
30
  e.stopPropagation();
44
31
  this.setState({
45
32
  focused: `${item.type}_${item.id}`
46
33
  });
47
34
  };
48
-
49
35
  this.handleBlur = (e, _item) => {
50
36
  e.stopPropagation();
51
37
  this.setState({
52
38
  focused: ''
53
39
  });
54
40
  };
55
-
56
41
  this.handleCollectionClick = e => {
57
42
  const _this$props = this.props,
58
- id = _this$props.id,
59
- onCollectionClick = _this$props.onCollectionClick,
60
- expanded = _this$props.expanded;
43
+ id = _this$props.id,
44
+ onCollectionClick = _this$props.onCollectionClick,
45
+ expanded = _this$props.expanded;
61
46
  const collection = {
62
47
  id,
63
48
  expanded: !expanded,
64
49
  type: 'collection'
65
50
  };
66
-
67
51
  if (onCollectionClick && typeof onCollectionClick === 'function') {
68
52
  onCollectionClick(e, collection);
69
53
  }
70
54
  };
71
-
72
55
  this.handleCollectionKeyDown = e => {
73
56
  const _this$props2 = this.props,
74
- id = _this$props2.id,
75
- onKeyDown = _this$props2.onKeyDown,
76
- expanded = _this$props2.expanded;
57
+ id = _this$props2.id,
58
+ onKeyDown = _this$props2.onKeyDown,
59
+ expanded = _this$props2.expanded;
77
60
  const collection = {
78
61
  id,
79
62
  expanded: !expanded,
80
63
  type: 'collection'
81
64
  };
82
-
83
65
  if (onKeyDown && typeof onKeyDown === 'function') {
84
66
  onKeyDown(e, collection);
85
67
  }
86
68
  };
87
-
88
69
  this.state = {
89
70
  focused: ''
90
71
  };
91
72
  }
92
-
93
73
  componentDidMount() {
94
74
  var _this$props$makeStyle, _this$props3;
95
-
96
75
  (_this$props$makeStyle = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props3);
97
76
  }
98
-
99
77
  componentDidUpdate() {
100
78
  var _this$props$makeStyle2, _this$props4;
101
-
102
79
  (_this$props$makeStyle2 = (_this$props4 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props4);
103
80
  }
104
-
105
81
  get itemsLevel() {
106
82
  const _this$props5 = this.props,
107
- level = _this$props5.level,
108
- isCollectionFlattened = _this$props5.isCollectionFlattened;
83
+ level = _this$props5.level,
84
+ isCollectionFlattened = _this$props5.isCollectionFlattened;
109
85
  return isCollectionFlattened ? level : level + 1;
110
86
  }
111
-
112
87
  get collectionsCount() {
113
88
  const collections = this.props.collections;
114
89
  return collections && collections.length > 0 ? collections.length : 0;
115
90
  }
116
-
117
91
  get itemsCount() {
118
92
  const items = this.props.items;
119
93
  return items && items.length > 0 ? items.length : 0;
120
94
  }
121
-
122
95
  get childCount() {
123
96
  return this.collectionsCount + this.itemsCount + (this.props.renderBeforeItems ? 1 : 0) + (this.props.renderAfterItems ? 1 : 0);
124
97
  }
125
-
126
98
  sortChildren() {
127
99
  const _this$props6 = this.props,
128
- collections = _this$props6.collections,
129
- items = _this$props6.items,
130
- compareFunc = _this$props6.compareFunc;
100
+ collections = _this$props6.collections,
101
+ items = _this$props6.items,
102
+ compareFunc = _this$props6.compareFunc;
131
103
  if (!compareFunc) return [];
132
104
  const collections_ = collections ? collections.map(collection => {
133
- return { ...collection,
105
+ return {
106
+ ...collection,
134
107
  type: 'collection'
135
108
  };
136
109
  }) : [];
137
110
  const items_ = items ? items.map(item => {
138
- return { ...item,
111
+ return {
112
+ ...item,
139
113
  type: 'item'
140
114
  };
141
115
  }) : [];
@@ -143,15 +117,14 @@ let TreeCollection = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.def
143
117
  renderQueue.sort(compareFunc);
144
118
  return renderQueue;
145
119
  }
146
-
147
120
  renderChildren() {
148
121
  const _this$props7 = this.props,
149
- collections = _this$props7.collections,
150
- items = _this$props7.items,
151
- id = _this$props7.id,
152
- renderBeforeItems = _this$props7.renderBeforeItems,
153
- renderAfterItems = _this$props7.renderAfterItems,
154
- compareFunc = _this$props7.compareFunc;
122
+ collections = _this$props7.collections,
123
+ items = _this$props7.items,
124
+ id = _this$props7.id,
125
+ renderBeforeItems = _this$props7.renderBeforeItems,
126
+ renderAfterItems = _this$props7.renderAfterItems,
127
+ compareFunc = _this$props7.compareFunc;
155
128
  let position = 1;
156
129
  const sortedChildren = this.sortChildren();
157
130
  return (0, _emotion.jsx)(_react.default.Fragment, null, renderBeforeItems && this.renderCollectionChildren(id, renderBeforeItems, position++, 'before'), !compareFunc && collections.map(collection => {
@@ -166,20 +139,17 @@ let TreeCollection = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.def
166
139
  }
167
140
  }), renderAfterItems && this.renderCollectionChildren(id, renderAfterItems, position++, 'after'));
168
141
  }
169
-
170
142
  renderCollectionChildren(collectionId, child, position, keyword) {
171
143
  const _this$props8 = this.props,
172
- selection = _this$props8.selection,
173
- onKeyDown = _this$props8.onKeyDown,
174
- getItemProps = _this$props8.getItemProps,
175
- styles = _this$props8.styles;
144
+ selection = _this$props8.selection,
145
+ onKeyDown = _this$props8.onKeyDown,
146
+ getItemProps = _this$props8.getItemProps,
147
+ styles = _this$props8.styles;
176
148
  const key = `${collectionId}_${keyword}`;
177
149
  const ariaSelected = {};
178
-
179
150
  if (selection) {
180
151
  ariaSelected['aria-selected'] = selection === `child_${key}`;
181
152
  }
182
-
183
153
  const itemHash = {
184
154
  id: key,
185
155
  type: 'child'
@@ -218,7 +188,6 @@ let TreeCollection = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.def
218
188
  onBlur: e => this.handleBlur(e, itemHash)
219
189
  }), (0, _safeCloneElement.safeCloneElement)(child, itemProps));
220
190
  }
221
-
222
191
  renderCollectionNode(collection, position) {
223
192
  return (0, _emotion.jsx)(TreeCollection, Object.assign({}, this.props, {
224
193
  key: `c${position}`,
@@ -239,25 +208,23 @@ let TreeCollection = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.def
239
208
  compareFunc: collection.compareFunc
240
209
  }));
241
210
  }
242
-
243
211
  renderItemNode(item, position) {
244
212
  const _this$props9 = this.props,
245
- selection = _this$props9.selection,
246
- onItemClick = _this$props9.onItemClick,
247
- onKeyDown = _this$props9.onKeyDown,
248
- getItemProps = _this$props9.getItemProps,
249
- styles = _this$props9.styles;
213
+ selection = _this$props9.selection,
214
+ onItemClick = _this$props9.onItemClick,
215
+ onKeyDown = _this$props9.onKeyDown,
216
+ getItemProps = _this$props9.getItemProps,
217
+ styles = _this$props9.styles;
250
218
  const ariaSelected = {};
251
-
252
219
  if (selection) {
253
220
  ariaSelected['aria-selected'] = selection === `item_${item.id}`;
254
221
  }
255
-
256
222
  const itemHash = {
257
223
  id: item.id,
258
224
  type: 'item'
259
225
  };
260
- const itemProps = getItemProps({ ...this.getCommonButtonProps(),
226
+ const itemProps = getItemProps({
227
+ ...this.getCommonButtonProps(),
261
228
  id: item.id,
262
229
  name: item.name,
263
230
  descriptor: item.descriptor,
@@ -281,7 +248,6 @@ let TreeCollection = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.def
281
248
  onBlur: e => this.handleBlur(e, itemHash)
282
249
  }, ariaSelected), (0, _emotion.jsx)(_TreeButton.TreeButton, itemProps));
283
250
  }
284
-
285
251
  getCommonButtonProps() {
286
252
  return {
287
253
  id: this.props.id,
@@ -294,20 +260,20 @@ let TreeCollection = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.def
294
260
  renderContent: this.props.renderContent
295
261
  };
296
262
  }
297
-
298
263
  render() {
299
264
  const _this$props10 = this.props,
300
- id = _this$props10.id,
301
- name = _this$props10.name,
302
- expanded = _this$props10.expanded,
303
- collectionIcon = _this$props10.collectionIcon,
304
- collectionIconExpanded = _this$props10.collectionIconExpanded,
305
- isCollectionFlattened = _this$props10.isCollectionFlattened,
306
- getCollectionProps = _this$props10.getCollectionProps,
307
- level = _this$props10.level,
308
- position = _this$props10.position,
309
- styles = _this$props10.styles;
310
- const collectionProps = getCollectionProps({ ...this.getCommonButtonProps(),
265
+ id = _this$props10.id,
266
+ name = _this$props10.name,
267
+ expanded = _this$props10.expanded,
268
+ collectionIcon = _this$props10.collectionIcon,
269
+ collectionIconExpanded = _this$props10.collectionIconExpanded,
270
+ isCollectionFlattened = _this$props10.isCollectionFlattened,
271
+ getCollectionProps = _this$props10.getCollectionProps,
272
+ level = _this$props10.level,
273
+ position = _this$props10.position,
274
+ styles = _this$props10.styles;
275
+ const collectionProps = getCollectionProps({
276
+ ...this.getCommonButtonProps(),
311
277
  expanded: expanded,
312
278
  collectionIcon: collectionIcon,
313
279
  collectionIconExpanded: collectionIconExpanded,
@@ -347,7 +313,6 @@ let TreeCollection = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.def
347
313
  role: "group"
348
314
  }, this.renderChildren()));
349
315
  }
350
-
351
316
  }, _class2.displayName = "TreeCollection", _class2.componentId = 'TreeBrowser.Collection', _class2.allowedProps = _props.allowedProps, _class2.propTypes = _props.propTypes, _class2.defaultProps = {
352
317
  collections: [],
353
318
  items: [],
@@ -1,18 +1,13 @@
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 _Children = require("@instructure/ui-prop-types/lib/Children.js");
13
-
14
10
  var _TreeNode = require("../TreeNode");
15
-
16
11
  /*
17
12
  * The MIT License (MIT)
18
13
  *
@@ -36,6 +31,7 @@ var _TreeNode = require("../TreeNode");
36
31
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37
32
  * SOFTWARE.
38
33
  */
34
+
39
35
  const propTypes = {
40
36
  id: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
41
37
  name: _propTypes.default.string,
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _emotion = require("@instructure/emotion");
9
-
10
8
  /*
11
9
  * The MIT License (MIT)
12
10
  *
@@ -30,10 +28,12 @@ var _emotion = require("@instructure/emotion");
30
28
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
29
  * SOFTWARE.
32
30
  */
31
+
33
32
  const list = (0, _emotion.keyframes)`
34
33
  to {
35
34
  transform: scaleY(1);
36
35
  }`;
36
+
37
37
  /**
38
38
  * ---
39
39
  * private: true
@@ -47,7 +47,7 @@ const list = (0, _emotion.keyframes)`
47
47
 
48
48
  const generateStyles = (componentTheme, props) => {
49
49
  const size = props.size,
50
- variant = props.variant;
50
+ variant = props.variant;
51
51
  const sizeMap = {
52
52
  small: {
53
53
  indent: {
@@ -133,6 +133,5 @@ const generateStyles = (componentTheme, props) => {
133
133
  }
134
134
  };
135
135
  };
136
-
137
136
  var _default = generateStyles;
138
137
  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,9 +35,9 @@ exports.default = void 0;
36
35
  */
37
36
  const generateComponentTheme = theme => {
38
37
  const colors = theme.colors,
39
- spacing = theme.spacing,
40
- typography = theme.typography,
41
- borders = theme.borders;
38
+ spacing = theme.spacing,
39
+ typography = theme.typography,
40
+ borders = theme.borders;
42
41
  const componentVariables = {
43
42
  fontFamily: typography === null || typography === void 0 ? void 0 : typography.fontFamily,
44
43
  baseSpacingSmall: spacing === null || spacing === void 0 ? void 0 : spacing.xSmall,
@@ -47,9 +46,9 @@ const generateComponentTheme = theme => {
47
46
  borderWidth: borders === null || borders === void 0 ? void 0 : borders.widthSmall,
48
47
  borderColor: colors === null || colors === void 0 ? void 0 : colors.borderDark
49
48
  };
50
- return { ...componentVariables
49
+ return {
50
+ ...componentVariables
51
51
  };
52
52
  };
53
-
54
53
  var _default = generateComponentTheme;
55
54
  exports.default = _default;
@@ -1,32 +1,20 @@
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.TreeNode = void 0;
9
-
10
8
  var _react = require("react");
11
-
12
9
  var _Img = require("@instructure/ui-img/lib/Img");
13
-
14
10
  var _callRenderProp = require("@instructure/ui-react-utils/lib/callRenderProp.js");
15
-
16
11
  var _testable = require("@instructure/ui-testable/lib/testable.js");
17
-
18
12
  var _emotion = require("@instructure/emotion");
19
-
20
13
  var _styles = _interopRequireDefault(require("../TreeButton/styles"));
21
-
22
14
  var _theme = _interopRequireDefault(require("../TreeButton/theme"));
23
-
24
15
  var _props = require("./props");
25
-
26
16
  var _dec, _dec2, _class, _class2;
27
-
28
17
  // Todo: merge TreeButton and TreeNode: TreeButton should be a special type of TreeNode
29
-
30
18
  /**
31
19
  ---
32
20
  parent: TreeBrowser
@@ -40,34 +28,26 @@ let TreeNode = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default),
40
28
  constructor() {
41
29
  super(...arguments);
42
30
  this.ref = null;
43
-
44
31
  this.handleRef = el => {
45
32
  if (el && typeof this.props.containerRef === 'function') {
46
33
  this.props.containerRef(el.parentElement);
47
34
  }
48
-
49
35
  this.ref = el;
50
36
  };
51
37
  }
52
-
53
38
  componentDidMount() {
54
39
  var _this$props$makeStyle, _this$props;
55
-
56
40
  (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
57
41
  }
58
-
59
42
  componentDidUpdate() {
60
43
  var _this$props$makeStyle2, _this$props2;
61
-
62
44
  (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
63
45
  }
64
-
65
46
  renderItemImage() {
66
47
  const _this$props3 = this.props,
67
- thumbnail = _this$props3.thumbnail,
68
- itemIcon = _this$props3.itemIcon,
69
- styles = _this$props3.styles;
70
-
48
+ thumbnail = _this$props3.thumbnail,
49
+ itemIcon = _this$props3.itemIcon,
50
+ styles = _this$props3.styles;
71
51
  if (thumbnail) {
72
52
  return (0, _emotion.jsx)("div", {
73
53
  css: styles === null || styles === void 0 ? void 0 : styles.thumbnail
@@ -77,20 +57,17 @@ let TreeNode = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default),
77
57
  alt: ""
78
58
  }));
79
59
  }
80
-
81
60
  if (itemIcon) {
82
61
  return (0, _emotion.jsx)("div", {
83
62
  css: styles === null || styles === void 0 ? void 0 : styles.icon
84
63
  }, (0, _callRenderProp.callRenderProp)(itemIcon));
85
64
  }
86
-
87
65
  return void 0;
88
66
  }
89
-
90
67
  render() {
91
68
  const _this$props4 = this.props,
92
- children = _this$props4.children,
93
- styles = _this$props4.styles;
69
+ children = _this$props4.children,
70
+ styles = _this$props4.styles;
94
71
  return (0, _emotion.jsx)("div", {
95
72
  ref: this.handleRef,
96
73
  tabIndex: -1,
@@ -101,7 +78,6 @@ let TreeNode = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default),
101
78
  css: styles === null || styles === void 0 ? void 0 : styles.node
102
79
  }, children)));
103
80
  }
104
-
105
81
  }, _class2.displayName = "TreeNode", _class2.componentId = 'TreeBrowser.Node', _class2.allowedProps = _props.allowedProps, _class2.propTypes = _props.propTypes, _class2.defaultProps = {
106
82
  size: 'medium',
107
83
  variant: 'folderTree',
@@ -1,14 +1,11 @@
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
  /*
13
10
  * The MIT License (MIT)
14
11
  *
@@ -32,6 +29,7 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
32
29
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
30
  * SOFTWARE.
34
31
  */
32
+
35
33
  const propTypes = {
36
34
  id: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
37
35
  size: _propTypes.default.oneOf(['small', 'medium', 'large']),