@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
@@ -1,4 +1,4 @@
1
- var _dec, _class, _TreeCollection;
1
+ var _dec, _class;
2
2
  /*
3
3
  * The MIT License (MIT)
4
4
  *
@@ -38,72 +38,88 @@ parent: TreeBrowser
38
38
  id: TreeBrowser.Collection
39
39
  ---
40
40
  **/
41
- let TreeCollection = (_dec = withStyle(generateStyles, 'TreeBrowserTreeCollection'), _dec(_class = (_TreeCollection = class TreeCollection extends Component {
41
+ let TreeCollection = (_dec = withStyle(generateStyles, 'TreeBrowserTreeCollection'), _dec(_class = class TreeCollection extends Component {
42
+ static displayName = "TreeCollection";
43
+ static componentId = 'TreeBrowser.Collection';
44
+ static allowedProps = allowedProps;
45
+ static contextType = TreeBrowserContext;
46
+ static defaultProps = {
47
+ collections: [],
48
+ items: [],
49
+ expanded: false,
50
+ selection: '',
51
+ size: 'medium',
52
+ variant: 'folderTree',
53
+ getItemProps: props => props,
54
+ getCollectionProps: props => props,
55
+ isCollectionFlattened: false
56
+ };
57
+ ref = null;
42
58
  constructor(props) {
43
59
  super(props);
44
- this.ref = null;
45
- this.handleFocus = (e, item) => {
46
- e.stopPropagation();
47
- this.setState({
48
- focused: `${item.type}_${item.id}`
49
- });
50
- };
51
- this.handleBlur = (e, _item) => {
52
- e.stopPropagation();
53
- this.setState({
54
- focused: ''
55
- });
56
- };
57
- this.handleCollectionClick = e => {
58
- const _this$props = this.props,
59
- id = _this$props.id,
60
- onCollectionClick = _this$props.onCollectionClick,
61
- expanded = _this$props.expanded;
62
- const collection = {
63
- id,
64
- expanded: !expanded,
65
- type: 'collection'
66
- };
67
- if (onCollectionClick && typeof onCollectionClick === 'function') {
68
- onCollectionClick(e, collection);
69
- }
70
- };
71
- this.handleCollectionKeyDown = e => {
72
- const _this$props2 = this.props,
73
- id = _this$props2.id,
74
- onKeyDown = _this$props2.onKeyDown,
75
- expanded = _this$props2.expanded;
76
- const collection = {
77
- id,
78
- expanded: !expanded,
79
- type: 'collection'
80
- };
81
- if (onKeyDown && typeof onKeyDown === 'function') {
82
- onKeyDown(e, collection);
83
- }
84
- };
85
60
  this.state = {
86
61
  focused: ''
87
62
  };
88
63
  }
89
64
  componentDidMount() {
90
- var _this$props$makeStyle, _this$props3, _this$context;
91
- (_this$props$makeStyle = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props3, {
92
- animation: (_this$context = this.context) === null || _this$context === void 0 ? void 0 : _this$context.animation
65
+ this.props.makeStyles?.({
66
+ animation: this.context?.animation
93
67
  });
94
68
  }
95
69
  componentDidUpdate() {
96
- var _this$props$makeStyle2, _this$props4, _this$context2;
97
- (_this$props$makeStyle2 = (_this$props4 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props4, {
98
- animation: (_this$context2 = this.context) === null || _this$context2 === void 0 ? void 0 : _this$context2.animation
70
+ this.props.makeStyles?.({
71
+ animation: this.context?.animation
99
72
  });
100
73
  }
101
74
  get itemsLevel() {
102
- const _this$props5 = this.props,
103
- level = _this$props5.level,
104
- isCollectionFlattened = _this$props5.isCollectionFlattened;
75
+ const {
76
+ level,
77
+ isCollectionFlattened
78
+ } = this.props;
105
79
  return isCollectionFlattened ? level : level + 1;
106
80
  }
81
+ handleFocus = (e, item) => {
82
+ e.stopPropagation();
83
+ this.setState({
84
+ focused: `${item.type}_${item.id}`
85
+ });
86
+ };
87
+ handleBlur = (e, _item) => {
88
+ e.stopPropagation();
89
+ this.setState({
90
+ focused: ''
91
+ });
92
+ };
93
+ handleCollectionClick = e => {
94
+ const {
95
+ id,
96
+ onCollectionClick,
97
+ expanded
98
+ } = this.props;
99
+ const collection = {
100
+ id,
101
+ expanded: !expanded,
102
+ type: 'collection'
103
+ };
104
+ if (onCollectionClick && typeof onCollectionClick === 'function') {
105
+ onCollectionClick(e, collection);
106
+ }
107
+ };
108
+ handleCollectionKeyDown = e => {
109
+ const {
110
+ id,
111
+ onKeyDown,
112
+ expanded
113
+ } = this.props;
114
+ const collection = {
115
+ id,
116
+ expanded: !expanded,
117
+ type: 'collection'
118
+ };
119
+ if (onKeyDown && typeof onKeyDown === 'function') {
120
+ onKeyDown(e, collection);
121
+ }
122
+ };
107
123
  get collectionsCount() {
108
124
  const collections = this.props.collections;
109
125
  return collections && collections.length > 0 ? collections.length : 0;
@@ -116,10 +132,11 @@ let TreeCollection = (_dec = withStyle(generateStyles, 'TreeBrowserTreeCollectio
116
132
  return this.collectionsCount + this.itemsCount + (this.props.renderBeforeItems ? 1 : 0) + (this.props.renderAfterItems ? 1 : 0);
117
133
  }
118
134
  sortChildren() {
119
- const _this$props6 = this.props,
120
- collections = _this$props6.collections,
121
- items = _this$props6.items,
122
- compareFunc = _this$props6.compareFunc;
135
+ const {
136
+ collections,
137
+ items,
138
+ compareFunc
139
+ } = this.props;
123
140
  if (!compareFunc) return [];
124
141
  const collections_ = collections ? collections.map(collection => {
125
142
  return {
@@ -138,13 +155,14 @@ let TreeCollection = (_dec = withStyle(generateStyles, 'TreeBrowserTreeCollectio
138
155
  return renderQueue;
139
156
  }
140
157
  renderChildren() {
141
- const _this$props7 = this.props,
142
- collections = _this$props7.collections,
143
- items = _this$props7.items,
144
- id = _this$props7.id,
145
- renderBeforeItems = _this$props7.renderBeforeItems,
146
- renderAfterItems = _this$props7.renderAfterItems,
147
- compareFunc = _this$props7.compareFunc;
158
+ const {
159
+ collections,
160
+ items,
161
+ id,
162
+ renderBeforeItems,
163
+ renderAfterItems,
164
+ compareFunc
165
+ } = this.props;
148
166
  let position = 1;
149
167
  const sortedChildren = this.sortChildren();
150
168
  return _jsxs(_Fragment, {
@@ -162,11 +180,12 @@ let TreeCollection = (_dec = withStyle(generateStyles, 'TreeBrowserTreeCollectio
162
180
  });
163
181
  }
164
182
  renderCollectionChildren(collectionId, child, position, keyword) {
165
- const _this$props8 = this.props,
166
- selection = _this$props8.selection,
167
- onKeyDown = _this$props8.onKeyDown,
168
- getItemProps = _this$props8.getItemProps,
169
- styles = _this$props8.styles;
183
+ const {
184
+ selection,
185
+ onKeyDown,
186
+ getItemProps,
187
+ styles
188
+ } = this.props;
170
189
  const key = `${collectionId}_${keyword}`;
171
190
  const ariaSelected = {};
172
191
  if (selection) {
@@ -188,7 +207,7 @@ let TreeCollection = (_dec = withStyle(generateStyles, 'TreeBrowserTreeCollectio
188
207
  id: key
189
208
  /* eslint-disable-next-line jsx-a11y/role-has-required-aria-props */,
190
209
  role: "treeitem",
191
- css: styles === null || styles === void 0 ? void 0 : styles.item,
210
+ css: styles?.item,
192
211
  tabIndex: -1,
193
212
  "aria-posinset": position,
194
213
  "aria-setsize": this.childCount,
@@ -206,7 +225,7 @@ let TreeCollection = (_dec = withStyle(generateStyles, 'TreeBrowserTreeCollectio
206
225
  if (typeof child.props.onKeyDown === 'function') {
207
226
  child.props.onKeyDown(e);
208
227
  } else {
209
- onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e, itemHash);
228
+ onKeyDown?.(e, itemHash);
210
229
  }
211
230
  },
212
231
  onBlur: e => this.handleBlur(e, itemHash),
@@ -235,12 +254,13 @@ let TreeCollection = (_dec = withStyle(generateStyles, 'TreeBrowserTreeCollectio
235
254
  });
236
255
  }
237
256
  renderItemNode(item, position) {
238
- const _this$props9 = this.props,
239
- selection = _this$props9.selection,
240
- onItemClick = _this$props9.onItemClick,
241
- onKeyDown = _this$props9.onKeyDown,
242
- getItemProps = _this$props9.getItemProps,
243
- styles = _this$props9.styles;
257
+ const {
258
+ selection,
259
+ onItemClick,
260
+ onKeyDown,
261
+ getItemProps,
262
+ styles
263
+ } = this.props;
244
264
  const ariaSelected = {};
245
265
  if (selection) {
246
266
  ariaSelected['aria-selected'] = selection === `item_${item.id}`;
@@ -264,12 +284,12 @@ let TreeCollection = (_dec = withStyle(generateStyles, 'TreeBrowserTreeCollectio
264
284
  /* eslint-disable-next-line jsx-a11y/role-has-required-aria-props */,
265
285
  role: "treeitem",
266
286
  "aria-label": item.name,
267
- css: styles === null || styles === void 0 ? void 0 : styles.item,
287
+ css: styles?.item,
268
288
  "aria-level": this.itemsLevel,
269
289
  "aria-posinset": position,
270
290
  "aria-setsize": this.childCount,
271
- onClick: e => onItemClick === null || onItemClick === void 0 ? void 0 : onItemClick(e, itemHash),
272
- onKeyDown: e => onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e, itemHash),
291
+ onClick: e => onItemClick?.(e, itemHash),
292
+ onKeyDown: e => onKeyDown?.(e, itemHash),
273
293
  onFocus: e => this.handleFocus(e, itemHash),
274
294
  onBlur: e => this.handleBlur(e, itemHash),
275
295
  ...ariaSelected,
@@ -291,17 +311,18 @@ let TreeCollection = (_dec = withStyle(generateStyles, 'TreeBrowserTreeCollectio
291
311
  };
292
312
  }
293
313
  render() {
294
- const _this$props0 = this.props,
295
- id = _this$props0.id,
296
- name = _this$props0.name,
297
- expanded = _this$props0.expanded,
298
- collectionIcon = _this$props0.collectionIcon,
299
- collectionIconExpanded = _this$props0.collectionIconExpanded,
300
- isCollectionFlattened = _this$props0.isCollectionFlattened,
301
- getCollectionProps = _this$props0.getCollectionProps,
302
- level = _this$props0.level,
303
- position = _this$props0.position,
304
- styles = _this$props0.styles;
314
+ const {
315
+ id,
316
+ name,
317
+ expanded,
318
+ collectionIcon,
319
+ collectionIconExpanded,
320
+ isCollectionFlattened,
321
+ getCollectionProps,
322
+ level,
323
+ position,
324
+ styles
325
+ } = this.props;
305
326
  const collectionProps = getCollectionProps({
306
327
  ...this.getCommonButtonProps(),
307
328
  expanded: expanded,
@@ -314,14 +335,14 @@ let TreeCollection = (_dec = withStyle(generateStyles, 'TreeBrowserTreeCollectio
314
335
  level
315
336
  });
316
337
  const ariaSelected = {
317
- 'aria-selected': void 0
338
+ 'aria-selected': undefined
318
339
  };
319
340
  if (this.props.selection) ariaSelected['aria-selected'] = this.props.selection === `collection_${id}`;
320
341
  return isCollectionFlattened ? this.renderChildren() : _jsxs("li", {
321
342
  ref: el => {
322
343
  this.ref = el;
323
344
  },
324
- css: styles === null || styles === void 0 ? void 0 : styles.treeCollection,
345
+ css: styles?.treeCollection,
325
346
  tabIndex: -1
326
347
  /* eslint-disable-next-line jsx-a11y/role-has-required-aria-props */,
327
348
  role: "treeitem",
@@ -346,22 +367,12 @@ let TreeCollection = (_dec = withStyle(generateStyles, 'TreeBrowserTreeCollectio
346
367
  ...collectionProps
347
368
  }), expanded && this.childCount > 0 && _jsx("ul", {
348
369
  "aria-label": name,
349
- css: styles === null || styles === void 0 ? void 0 : styles.list,
370
+ css: styles?.list,
350
371
  role: "group",
351
372
  children: this.renderChildren()
352
373
  })]
353
374
  });
354
375
  }
355
- }, _TreeCollection.displayName = "TreeCollection", _TreeCollection.componentId = 'TreeBrowser.Collection', _TreeCollection.allowedProps = allowedProps, _TreeCollection.contextType = TreeBrowserContext, _TreeCollection.defaultProps = {
356
- collections: [],
357
- items: [],
358
- expanded: false,
359
- selection: '',
360
- size: 'medium',
361
- variant: 'folderTree',
362
- getItemProps: props => props,
363
- getCollectionProps: props => props,
364
- isCollectionFlattened: false
365
- }, _TreeCollection)) || _class);
376
+ }) || _class);
366
377
  export default TreeCollection;
367
378
  export { TreeCollection };
@@ -41,8 +41,10 @@ const list = keyframes`
41
41
  */
42
42
 
43
43
  const generateStyles = (componentTheme, props, sharedTokens, state) => {
44
- const size = props.size,
45
- variant = props.variant;
44
+ const {
45
+ size,
46
+ variant
47
+ } = props;
46
48
  const sizeMap = {
47
49
  small: {
48
50
  indent: {
@@ -1,4 +1,4 @@
1
- var _dec, _class, _TreeNode;
1
+ var _dec, _class;
2
2
  /*
3
3
  * The MIT License (MIT)
4
4
  *
@@ -47,51 +47,61 @@ 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 = (_dec = withStyle(generateStyles, 'TreeBrowserTreeButton'), _dec(_class = (_TreeNode = class TreeNode extends Component {
51
- constructor(...args) {
52
- super(...args);
53
- this.ref = null;
54
- this.state = {
55
- isHovered: false
56
- };
57
- this.handleRef = el => {
58
- if (el && typeof this.props.containerRef === 'function') {
59
- this.props.containerRef(el.parentElement);
60
- }
61
- this.ref = el;
62
- };
63
- this.handleMouseEnter = () => {
64
- if (this.props.hoverable) {
65
- this.setState({
66
- isHovered: true
67
- });
68
- }
69
- };
70
- this.handleMouseLeave = () => {
71
- if (this.props.hoverable) {
72
- this.setState({
73
- isHovered: false
74
- });
75
- }
76
- };
77
- }
50
+ let TreeNode = (_dec = withStyle(generateStyles, 'TreeBrowserTreeButton'), _dec(_class = class TreeNode extends Component {
51
+ static displayName = "TreeNode";
52
+ static componentId = 'TreeBrowser.Node';
53
+ static allowedProps = allowedProps;
54
+ static contextType = TreeBrowserContext;
55
+ static defaultProps = {
56
+ size: 'medium',
57
+ variant: 'folderTree',
58
+ selected: false,
59
+ focused: false,
60
+ hoverable: true
61
+ };
62
+ ref = null;
63
+ state = {
64
+ isHovered: false
65
+ };
78
66
  componentDidMount() {
79
- var _this$props$makeStyle, _this$props, _this$context;
80
- (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props, {
81
- animation: (_this$context = this.context) === null || _this$context === void 0 ? void 0 : _this$context.animation,
67
+ this.props.makeStyles?.({
68
+ animation: this.context?.animation,
82
69
  hoverable: this.props.hoverable
83
70
  });
84
71
  }
85
72
  componentDidUpdate() {
86
- var _this$props$makeStyle2, _this$props2, _this$context2;
87
- (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2, {
88
- animation: (_this$context2 = this.context) === null || _this$context2 === void 0 ? void 0 : _this$context2.animation,
73
+ this.props.makeStyles?.({
74
+ animation: this.context?.animation,
89
75
  hoverable: this.props.hoverable
90
76
  });
91
77
  }
78
+ handleRef = el => {
79
+ if (el && typeof this.props.containerRef === 'function') {
80
+ this.props.containerRef(el.parentElement);
81
+ }
82
+ this.ref = el;
83
+ };
84
+ handleMouseEnter = () => {
85
+ if (this.props.hoverable) {
86
+ this.setState({
87
+ isHovered: true
88
+ });
89
+ }
90
+ };
91
+ handleMouseLeave = () => {
92
+ if (this.props.hoverable) {
93
+ this.setState({
94
+ isHovered: false
95
+ });
96
+ }
97
+ };
92
98
  getIconColor() {
93
- const selected = this.props.selected;
94
- const isHovered = this.state.isHovered;
99
+ const {
100
+ selected
101
+ } = this.props;
102
+ const {
103
+ isHovered
104
+ } = this.state;
95
105
 
96
106
  // Priority: selected > hover > default
97
107
  if (selected) return 'onColor';
@@ -99,14 +109,15 @@ let TreeNode = (_dec = withStyle(generateStyles, 'TreeBrowserTreeButton'), _dec(
99
109
  return 'baseColor';
100
110
  }
101
111
  renderItemImage() {
102
- const _this$props3 = this.props,
103
- thumbnail = _this$props3.thumbnail,
104
- itemIcon = _this$props3.itemIcon,
105
- styles = _this$props3.styles,
106
- size = _this$props3.size;
112
+ const {
113
+ thumbnail,
114
+ itemIcon,
115
+ styles,
116
+ size
117
+ } = this.props;
107
118
  if (thumbnail) {
108
119
  return _jsx("div", {
109
- css: styles === null || styles === void 0 ? void 0 : styles.thumbnail,
120
+ css: styles?.thumbnail,
110
121
  children: _jsx(Img, {
111
122
  src: thumbnail,
112
123
  constrain: "cover",
@@ -119,38 +130,33 @@ let TreeNode = (_dec = withStyle(generateStyles, 'TreeBrowserTreeButton'), _dec(
119
130
  const iconColor = this.getIconColor();
120
131
  const iconElement = renderIconWithProps(itemIcon, iconSize, iconColor);
121
132
  return _jsx("div", {
122
- css: styles === null || styles === void 0 ? void 0 : styles.icon,
133
+ css: styles?.icon,
123
134
  children: iconElement
124
135
  });
125
136
  }
126
- return void 0;
137
+ return undefined;
127
138
  }
128
139
  render() {
129
- const _this$props4 = this.props,
130
- children = _this$props4.children,
131
- styles = _this$props4.styles;
140
+ const {
141
+ children,
142
+ styles
143
+ } = this.props;
132
144
  return _jsx("div", {
133
145
  ref: this.handleRef,
134
146
  tabIndex: -1,
135
- css: styles === null || styles === void 0 ? void 0 : styles.treeButton,
147
+ css: styles?.treeButton,
136
148
  "data-cid": "TreeNode",
137
149
  onMouseEnter: this.handleMouseEnter,
138
150
  onMouseLeave: this.handleMouseLeave,
139
151
  children: _jsxs("span", {
140
- css: styles === null || styles === void 0 ? void 0 : styles.layout,
152
+ css: styles?.layout,
141
153
  children: [this.renderItemImage(), _jsx("span", {
142
- css: styles === null || styles === void 0 ? void 0 : styles.node,
154
+ css: styles?.node,
143
155
  children: children
144
156
  })]
145
157
  })
146
158
  });
147
159
  }
148
- }, _TreeNode.displayName = "TreeNode", _TreeNode.componentId = 'TreeBrowser.Node', _TreeNode.allowedProps = allowedProps, _TreeNode.contextType = TreeBrowserContext, _TreeNode.defaultProps = {
149
- size: 'medium',
150
- variant: 'folderTree',
151
- selected: false,
152
- focused: false,
153
- hoverable: true
154
- }, _TreeNode)) || _class);
160
+ }) || _class);
155
161
  export default TreeNode;
156
162
  export { TreeNode };