@instructure/ui-tree-browser 11.7.3-snapshot-7 → 11.7.3-snapshot-26

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 (33) hide show
  1. package/CHANGELOG.md +5 -2
  2. package/es/TreeBrowser/v1/TreeButton/index.js +56 -49
  3. package/es/TreeBrowser/v1/TreeButton/styles.js +7 -5
  4. package/es/TreeBrowser/v1/TreeButton/theme.js +32 -31
  5. package/es/TreeBrowser/v1/TreeCollection/index.js +115 -104
  6. package/es/TreeBrowser/v1/TreeCollection/styles.js +4 -2
  7. package/es/TreeBrowser/v1/TreeCollection/theme.js +11 -10
  8. package/es/TreeBrowser/v1/TreeNode/index.js +39 -37
  9. package/es/TreeBrowser/v1/index.js +94 -82
  10. package/es/TreeBrowser/v1/theme.js +8 -7
  11. package/es/TreeBrowser/v2/TreeButton/index.js +82 -71
  12. package/es/TreeBrowser/v2/TreeButton/styles.js +10 -8
  13. package/es/TreeBrowser/v2/TreeCollection/index.js +115 -104
  14. package/es/TreeBrowser/v2/TreeCollection/styles.js +4 -2
  15. package/es/TreeBrowser/v2/TreeNode/index.js +64 -58
  16. package/es/TreeBrowser/v2/index.js +112 -99
  17. package/lib/TreeBrowser/v1/TreeButton/index.js +56 -49
  18. package/lib/TreeBrowser/v1/TreeButton/styles.js +7 -5
  19. package/lib/TreeBrowser/v1/TreeButton/theme.js +32 -31
  20. package/lib/TreeBrowser/v1/TreeCollection/index.js +115 -104
  21. package/lib/TreeBrowser/v1/TreeCollection/styles.js +4 -2
  22. package/lib/TreeBrowser/v1/TreeCollection/theme.js +11 -10
  23. package/lib/TreeBrowser/v1/TreeNode/index.js +39 -37
  24. package/lib/TreeBrowser/v1/index.js +94 -82
  25. package/lib/TreeBrowser/v1/theme.js +8 -7
  26. package/lib/TreeBrowser/v2/TreeButton/index.js +82 -71
  27. package/lib/TreeBrowser/v2/TreeButton/styles.js +10 -8
  28. package/lib/TreeBrowser/v2/TreeCollection/index.js +115 -104
  29. package/lib/TreeBrowser/v2/TreeCollection/styles.js +4 -2
  30. package/lib/TreeBrowser/v2/TreeNode/index.js +64 -58
  31. package/lib/TreeBrowser/v2/index.js +112 -99
  32. package/package.json +12 -12
  33. package/tsconfig.build.tsbuildinfo +1 -1
@@ -15,7 +15,7 @@ var _props = require("./props");
15
15
  var _TreeBrowserContext = _interopRequireDefault(require("../TreeBrowserContext"));
16
16
  var _jsxRuntime = require("@emotion/react/jsx-runtime");
17
17
  var _react2 = require("@emotion/react");
18
- var _dec, _class, _TreeCollection;
18
+ var _dec, _class;
19
19
  /*
20
20
  * The MIT License (MIT)
21
21
  *
@@ -45,72 +45,88 @@ parent: TreeBrowser
45
45
  id: TreeBrowser.Collection
46
46
  ---
47
47
  **/
48
- let TreeCollection = exports.TreeCollection = (_dec = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = (_TreeCollection = class TreeCollection extends _react.Component {
48
+ let TreeCollection = exports.TreeCollection = (_dec = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = class TreeCollection extends _react.Component {
49
+ static displayName = "TreeCollection";
50
+ static componentId = 'TreeBrowser.Collection';
51
+ static allowedProps = _props.allowedProps;
52
+ static contextType = _TreeBrowserContext.default;
53
+ static defaultProps = {
54
+ collections: [],
55
+ items: [],
56
+ expanded: false,
57
+ selection: '',
58
+ size: 'medium',
59
+ variant: 'folderTree',
60
+ getItemProps: props => props,
61
+ getCollectionProps: props => props,
62
+ isCollectionFlattened: false
63
+ };
64
+ ref = null;
49
65
  constructor(props) {
50
66
  super(props);
51
- this.ref = null;
52
- this.handleFocus = (e, item) => {
53
- e.stopPropagation();
54
- this.setState({
55
- focused: `${item.type}_${item.id}`
56
- });
57
- };
58
- this.handleBlur = (e, _item) => {
59
- e.stopPropagation();
60
- this.setState({
61
- focused: ''
62
- });
63
- };
64
- this.handleCollectionClick = e => {
65
- const _this$props = this.props,
66
- id = _this$props.id,
67
- onCollectionClick = _this$props.onCollectionClick,
68
- expanded = _this$props.expanded;
69
- const collection = {
70
- id,
71
- expanded: !expanded,
72
- type: 'collection'
73
- };
74
- if (onCollectionClick && typeof onCollectionClick === 'function') {
75
- onCollectionClick(e, collection);
76
- }
77
- };
78
- this.handleCollectionKeyDown = e => {
79
- const _this$props2 = this.props,
80
- id = _this$props2.id,
81
- onKeyDown = _this$props2.onKeyDown,
82
- expanded = _this$props2.expanded;
83
- const collection = {
84
- id,
85
- expanded: !expanded,
86
- type: 'collection'
87
- };
88
- if (onKeyDown && typeof onKeyDown === 'function') {
89
- onKeyDown(e, collection);
90
- }
91
- };
92
67
  this.state = {
93
68
  focused: ''
94
69
  };
95
70
  }
96
71
  componentDidMount() {
97
- var _this$props$makeStyle, _this$props3, _this$context;
98
- (_this$props$makeStyle = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props3, {
99
- animation: (_this$context = this.context) === null || _this$context === void 0 ? void 0 : _this$context.animation
72
+ this.props.makeStyles?.({
73
+ animation: this.context?.animation
100
74
  });
101
75
  }
102
76
  componentDidUpdate() {
103
- var _this$props$makeStyle2, _this$props4, _this$context2;
104
- (_this$props$makeStyle2 = (_this$props4 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props4, {
105
- animation: (_this$context2 = this.context) === null || _this$context2 === void 0 ? void 0 : _this$context2.animation
77
+ this.props.makeStyles?.({
78
+ animation: this.context?.animation
106
79
  });
107
80
  }
108
81
  get itemsLevel() {
109
- const _this$props5 = this.props,
110
- level = _this$props5.level,
111
- isCollectionFlattened = _this$props5.isCollectionFlattened;
82
+ const {
83
+ level,
84
+ isCollectionFlattened
85
+ } = this.props;
112
86
  return isCollectionFlattened ? level : level + 1;
113
87
  }
88
+ handleFocus = (e, item) => {
89
+ e.stopPropagation();
90
+ this.setState({
91
+ focused: `${item.type}_${item.id}`
92
+ });
93
+ };
94
+ handleBlur = (e, _item) => {
95
+ e.stopPropagation();
96
+ this.setState({
97
+ focused: ''
98
+ });
99
+ };
100
+ handleCollectionClick = e => {
101
+ const {
102
+ id,
103
+ onCollectionClick,
104
+ expanded
105
+ } = this.props;
106
+ const collection = {
107
+ id,
108
+ expanded: !expanded,
109
+ type: 'collection'
110
+ };
111
+ if (onCollectionClick && typeof onCollectionClick === 'function') {
112
+ onCollectionClick(e, collection);
113
+ }
114
+ };
115
+ handleCollectionKeyDown = e => {
116
+ const {
117
+ id,
118
+ onKeyDown,
119
+ expanded
120
+ } = this.props;
121
+ const collection = {
122
+ id,
123
+ expanded: !expanded,
124
+ type: 'collection'
125
+ };
126
+ if (onKeyDown && typeof onKeyDown === 'function') {
127
+ onKeyDown(e, collection);
128
+ }
129
+ };
114
130
  get collectionsCount() {
115
131
  const collections = this.props.collections;
116
132
  return collections && collections.length > 0 ? collections.length : 0;
@@ -123,10 +139,11 @@ let TreeCollection = exports.TreeCollection = (_dec = (0, _emotion.withStyleLega
123
139
  return this.collectionsCount + this.itemsCount + (this.props.renderBeforeItems ? 1 : 0) + (this.props.renderAfterItems ? 1 : 0);
124
140
  }
125
141
  sortChildren() {
126
- const _this$props6 = this.props,
127
- collections = _this$props6.collections,
128
- items = _this$props6.items,
129
- compareFunc = _this$props6.compareFunc;
142
+ const {
143
+ collections,
144
+ items,
145
+ compareFunc
146
+ } = this.props;
130
147
  if (!compareFunc) return [];
131
148
  const collections_ = collections ? collections.map(collection => {
132
149
  return {
@@ -145,13 +162,14 @@ let TreeCollection = exports.TreeCollection = (_dec = (0, _emotion.withStyleLega
145
162
  return renderQueue;
146
163
  }
147
164
  renderChildren() {
148
- 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;
165
+ const {
166
+ collections,
167
+ items,
168
+ id,
169
+ renderBeforeItems,
170
+ renderAfterItems,
171
+ compareFunc
172
+ } = this.props;
155
173
  let position = 1;
156
174
  const sortedChildren = this.sortChildren();
157
175
  return (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
@@ -169,11 +187,12 @@ let TreeCollection = exports.TreeCollection = (_dec = (0, _emotion.withStyleLega
169
187
  });
170
188
  }
171
189
  renderCollectionChildren(collectionId, child, position, keyword) {
172
- const _this$props8 = this.props,
173
- selection = _this$props8.selection,
174
- onKeyDown = _this$props8.onKeyDown,
175
- getItemProps = _this$props8.getItemProps,
176
- styles = _this$props8.styles;
190
+ const {
191
+ selection,
192
+ onKeyDown,
193
+ getItemProps,
194
+ styles
195
+ } = this.props;
177
196
  const key = `${collectionId}_${keyword}`;
178
197
  const ariaSelected = {};
179
198
  if (selection) {
@@ -193,7 +212,7 @@ let TreeCollection = exports.TreeCollection = (_dec = (0, _emotion.withStyleLega
193
212
  id: key
194
213
  /* eslint-disable-next-line jsx-a11y/role-has-required-aria-props */,
195
214
  role: "treeitem",
196
- css: styles === null || styles === void 0 ? void 0 : styles.item,
215
+ css: styles?.item,
197
216
  tabIndex: -1,
198
217
  "aria-posinset": position,
199
218
  "aria-setsize": this.childCount,
@@ -211,7 +230,7 @@ let TreeCollection = exports.TreeCollection = (_dec = (0, _emotion.withStyleLega
211
230
  if (typeof child.props.onKeyDown === 'function') {
212
231
  child.props.onKeyDown(e);
213
232
  } else {
214
- onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e, itemHash);
233
+ onKeyDown?.(e, itemHash);
215
234
  }
216
235
  },
217
236
  onBlur: e => this.handleBlur(e, itemHash),
@@ -240,12 +259,13 @@ let TreeCollection = exports.TreeCollection = (_dec = (0, _emotion.withStyleLega
240
259
  });
241
260
  }
242
261
  renderItemNode(item, position) {
243
- const _this$props9 = this.props,
244
- selection = _this$props9.selection,
245
- onItemClick = _this$props9.onItemClick,
246
- onKeyDown = _this$props9.onKeyDown,
247
- getItemProps = _this$props9.getItemProps,
248
- styles = _this$props9.styles;
262
+ const {
263
+ selection,
264
+ onItemClick,
265
+ onKeyDown,
266
+ getItemProps,
267
+ styles
268
+ } = this.props;
249
269
  const ariaSelected = {};
250
270
  if (selection) {
251
271
  ariaSelected['aria-selected'] = selection === `item_${item.id}`;
@@ -269,12 +289,12 @@ let TreeCollection = exports.TreeCollection = (_dec = (0, _emotion.withStyleLega
269
289
  /* eslint-disable-next-line jsx-a11y/role-has-required-aria-props */,
270
290
  role: "treeitem",
271
291
  "aria-label": item.name,
272
- css: styles === null || styles === void 0 ? void 0 : styles.item,
292
+ css: styles?.item,
273
293
  "aria-level": this.itemsLevel,
274
294
  "aria-posinset": position,
275
295
  "aria-setsize": this.childCount,
276
- onClick: e => onItemClick === null || onItemClick === void 0 ? void 0 : onItemClick(e, itemHash),
277
- onKeyDown: e => onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e, itemHash),
296
+ onClick: e => onItemClick?.(e, itemHash),
297
+ onKeyDown: e => onKeyDown?.(e, itemHash),
278
298
  onFocus: e => this.handleFocus(e, itemHash),
279
299
  onBlur: e => this.handleBlur(e, itemHash),
280
300
  ...ariaSelected,
@@ -296,17 +316,18 @@ let TreeCollection = exports.TreeCollection = (_dec = (0, _emotion.withStyleLega
296
316
  };
297
317
  }
298
318
  render() {
299
- const _this$props0 = this.props,
300
- id = _this$props0.id,
301
- name = _this$props0.name,
302
- expanded = _this$props0.expanded,
303
- collectionIcon = _this$props0.collectionIcon,
304
- collectionIconExpanded = _this$props0.collectionIconExpanded,
305
- isCollectionFlattened = _this$props0.isCollectionFlattened,
306
- getCollectionProps = _this$props0.getCollectionProps,
307
- level = _this$props0.level,
308
- position = _this$props0.position,
309
- styles = _this$props0.styles;
319
+ const {
320
+ id,
321
+ name,
322
+ expanded,
323
+ collectionIcon,
324
+ collectionIconExpanded,
325
+ isCollectionFlattened,
326
+ getCollectionProps,
327
+ level,
328
+ position,
329
+ styles
330
+ } = this.props;
310
331
  const collectionProps = getCollectionProps({
311
332
  ...this.getCommonButtonProps(),
312
333
  expanded: expanded,
@@ -319,14 +340,14 @@ let TreeCollection = exports.TreeCollection = (_dec = (0, _emotion.withStyleLega
319
340
  level
320
341
  });
321
342
  const ariaSelected = {
322
- 'aria-selected': void 0
343
+ 'aria-selected': undefined
323
344
  };
324
345
  if (this.props.selection) ariaSelected['aria-selected'] = this.props.selection === `collection_${id}`;
325
346
  return isCollectionFlattened ? this.renderChildren() : (0, _jsxRuntime.jsxs)("li", {
326
347
  ref: el => {
327
348
  this.ref = el;
328
349
  },
329
- css: styles === null || styles === void 0 ? void 0 : styles.treeCollection,
350
+ css: styles?.treeCollection,
330
351
  tabIndex: -1
331
352
  /* eslint-disable-next-line jsx-a11y/role-has-required-aria-props */,
332
353
  role: "treeitem",
@@ -351,21 +372,11 @@ let TreeCollection = exports.TreeCollection = (_dec = (0, _emotion.withStyleLega
351
372
  ...collectionProps
352
373
  }), expanded && this.childCount > 0 && (0, _jsxRuntime.jsx)("ul", {
353
374
  "aria-label": name,
354
- css: styles === null || styles === void 0 ? void 0 : styles.list,
375
+ css: styles?.list,
355
376
  role: "group",
356
377
  children: this.renderChildren()
357
378
  })]
358
379
  });
359
380
  }
360
- }, _TreeCollection.displayName = "TreeCollection", _TreeCollection.componentId = 'TreeBrowser.Collection', _TreeCollection.allowedProps = _props.allowedProps, _TreeCollection.contextType = _TreeBrowserContext.default, _TreeCollection.defaultProps = {
361
- collections: [],
362
- items: [],
363
- expanded: false,
364
- selection: '',
365
- size: 'medium',
366
- variant: 'folderTree',
367
- getItemProps: props => props,
368
- getCollectionProps: props => props,
369
- isCollectionFlattened: false
370
- }, _TreeCollection)) || _class);
381
+ }) || _class);
371
382
  var _default = exports.default = TreeCollection;
@@ -46,8 +46,10 @@ const list = (0, _emotion.keyframes)`
46
46
  */
47
47
 
48
48
  const generateStyles = (componentTheme, props, state) => {
49
- const size = props.size,
50
- variant = props.variant;
49
+ const {
50
+ size,
51
+ variant
52
+ } = props;
51
53
  const sizeMap = {
52
54
  small: {
53
55
  indent: {
@@ -34,18 +34,19 @@ exports.default = void 0;
34
34
  * @return {Object} The final theme object with the overrides and component variables
35
35
  */
36
36
  const generateComponentTheme = theme => {
37
- var _colors$contrasts;
38
- const colors = theme.colors,
39
- spacing = theme.spacing,
40
- typography = theme.typography,
41
- borders = theme.borders;
37
+ const {
38
+ colors,
39
+ spacing,
40
+ typography,
41
+ borders
42
+ } = theme;
42
43
  const componentVariables = {
43
- fontFamily: typography === null || typography === void 0 ? void 0 : typography.fontFamily,
44
- baseSpacingSmall: spacing === null || spacing === void 0 ? void 0 : spacing.xSmall,
45
- baseSpacingMedium: spacing === null || spacing === void 0 ? void 0 : spacing.small,
44
+ fontFamily: typography?.fontFamily,
45
+ baseSpacingSmall: spacing?.xSmall,
46
+ baseSpacingMedium: spacing?.small,
46
47
  baseSpacingLarge: '1rem',
47
- borderWidth: borders === null || borders === void 0 ? void 0 : borders.widthSmall,
48
- borderColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts = colors.contrasts) === null || _colors$contrasts === void 0 ? void 0 : _colors$contrasts.grey4570
48
+ borderWidth: borders?.widthSmall,
49
+ borderColor: colors?.contrasts?.grey4570
49
50
  };
50
51
  return {
51
52
  ...componentVariables
@@ -14,7 +14,7 @@ var _theme = _interopRequireDefault(require("../TreeButton/theme"));
14
14
  var _props = require("./props");
15
15
  var _TreeBrowserContext = _interopRequireDefault(require("../TreeBrowserContext"));
16
16
  var _jsxRuntime = require("@emotion/react/jsx-runtime");
17
- var _dec, _class, _TreeNode;
17
+ var _dec, _class;
18
18
  /*
19
19
  * The MIT License (MIT)
20
20
  *
@@ -47,37 +47,43 @@ id: TreeBrowser.Node
47
47
  A helper class used to render the :renderBeforeItems and :renderAfterItems
48
48
  in the TreeBrowser.
49
49
  **/
50
- let TreeNode = exports.TreeNode = (_dec = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = (_TreeNode = class TreeNode extends _react.Component {
51
- constructor(...args) {
52
- super(...args);
53
- this.ref = null;
54
- this.handleRef = el => {
55
- if (el && typeof this.props.containerRef === 'function') {
56
- this.props.containerRef(el.parentElement);
57
- }
58
- this.ref = el;
59
- };
60
- }
50
+ let TreeNode = exports.TreeNode = (_dec = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = class TreeNode extends _react.Component {
51
+ static displayName = "TreeNode";
52
+ static componentId = 'TreeBrowser.Node';
53
+ static allowedProps = _props.allowedProps;
54
+ static contextType = _TreeBrowserContext.default;
55
+ static defaultProps = {
56
+ size: 'medium',
57
+ variant: 'folderTree',
58
+ selected: false,
59
+ focused: false
60
+ };
61
+ ref = null;
61
62
  componentDidMount() {
62
- var _this$props$makeStyle, _this$props, _this$context;
63
- (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props, {
64
- animation: (_this$context = this.context) === null || _this$context === void 0 ? void 0 : _this$context.animation
63
+ this.props.makeStyles?.({
64
+ animation: this.context?.animation
65
65
  });
66
66
  }
67
67
  componentDidUpdate() {
68
- var _this$props$makeStyle2, _this$props2, _this$context2;
69
- (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2, {
70
- animation: (_this$context2 = this.context) === null || _this$context2 === void 0 ? void 0 : _this$context2.animation
68
+ this.props.makeStyles?.({
69
+ animation: this.context?.animation
71
70
  });
72
71
  }
72
+ handleRef = el => {
73
+ if (el && typeof this.props.containerRef === 'function') {
74
+ this.props.containerRef(el.parentElement);
75
+ }
76
+ this.ref = el;
77
+ };
73
78
  renderItemImage() {
74
- const _this$props3 = this.props,
75
- thumbnail = _this$props3.thumbnail,
76
- itemIcon = _this$props3.itemIcon,
77
- styles = _this$props3.styles;
79
+ const {
80
+ thumbnail,
81
+ itemIcon,
82
+ styles
83
+ } = this.props;
78
84
  if (thumbnail) {
79
85
  return (0, _jsxRuntime.jsx)("div", {
80
- css: styles === null || styles === void 0 ? void 0 : styles.thumbnail,
86
+ css: styles?.thumbnail,
81
87
  children: (0, _jsxRuntime.jsx)(_v11_.Img, {
82
88
  src: thumbnail,
83
89
  constrain: "cover",
@@ -87,34 +93,30 @@ let TreeNode = exports.TreeNode = (_dec = (0, _emotion.withStyleLegacy)(_styles.
87
93
  }
88
94
  if (itemIcon) {
89
95
  return (0, _jsxRuntime.jsx)("div", {
90
- css: styles === null || styles === void 0 ? void 0 : styles.icon,
96
+ css: styles?.icon,
91
97
  children: (0, _callRenderProp.callRenderProp)(itemIcon)
92
98
  });
93
99
  }
94
- return void 0;
100
+ return undefined;
95
101
  }
96
102
  render() {
97
- const _this$props4 = this.props,
98
- children = _this$props4.children,
99
- styles = _this$props4.styles;
103
+ const {
104
+ children,
105
+ styles
106
+ } = this.props;
100
107
  return (0, _jsxRuntime.jsx)("div", {
101
108
  ref: this.handleRef,
102
109
  tabIndex: -1,
103
- css: styles === null || styles === void 0 ? void 0 : styles.treeButton,
110
+ css: styles?.treeButton,
104
111
  "data-cid": "TreeNode",
105
112
  children: (0, _jsxRuntime.jsxs)("span", {
106
- css: styles === null || styles === void 0 ? void 0 : styles.layout,
113
+ css: styles?.layout,
107
114
  children: [this.renderItemImage(), (0, _jsxRuntime.jsx)("span", {
108
- css: styles === null || styles === void 0 ? void 0 : styles.node,
115
+ css: styles?.node,
109
116
  children: children
110
117
  })]
111
118
  })
112
119
  });
113
120
  }
114
- }, _TreeNode.displayName = "TreeNode", _TreeNode.componentId = 'TreeBrowser.Node', _TreeNode.allowedProps = _props.allowedProps, _TreeNode.contextType = _TreeBrowserContext.default, _TreeNode.defaultProps = {
115
- size: 'medium',
116
- variant: 'folderTree',
117
- selected: false,
118
- focused: false
119
- }, _TreeNode)) || _class);
121
+ }) || _class);
120
122
  var _default = exports.default = TreeNode;