@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
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = exports.TreeBrowser = void 0;
8
+ require("core-js/modules/es.array.includes.js");
8
9
  var _react = require("react");
9
10
  var _keycode = _interopRequireDefault(require("keycode"));
10
11
  var _uiIcons = require("@instructure/ui-icons");
@@ -18,7 +19,7 @@ var _styles = _interopRequireDefault(require("./styles"));
18
19
  var _props = require("./props");
19
20
  var _TreeBrowserContext = _interopRequireDefault(require("./TreeBrowserContext"));
20
21
  var _jsxRuntime = require("@emotion/react/jsx-runtime");
21
- var _dec, _class, _TreeBrowser;
22
+ var _dec, _class;
22
23
  /*
23
24
  * The MIT License (MIT)
24
25
  *
@@ -47,76 +48,32 @@ var _dec, _class, _TreeBrowser;
47
48
  category: components
48
49
  ---
49
50
  **/
50
- let TreeBrowser = exports.TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.default), _dec(_class = (_TreeBrowser = class TreeBrowser extends _react.Component {
51
+ let TreeBrowser = exports.TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.default), _dec(_class = class TreeBrowser extends _react.Component {
52
+ static displayName = "TreeBrowser";
53
+ static componentId = 'TreeBrowser';
54
+ static allowedProps = _props.allowedProps;
55
+ static defaultProps = {
56
+ size: 'medium',
57
+ variant: 'folderTree',
58
+ showRootCollection: true,
59
+ collectionIcon: _uiIcons.FolderClosedInstUIIcon,
60
+ collectionIconExpanded: _uiIcons.FolderClosedInstUIIcon,
61
+ itemIcon: _uiIcons.FileTextInstUIIcon,
62
+ getItemProps: props => props,
63
+ getCollectionProps: props => props,
64
+ defaultExpanded: [],
65
+ selectionType: 'none',
66
+ sortOrder: function () {
67
+ return 0;
68
+ },
69
+ animation: true
70
+ };
71
+ static Node = _TreeNode.TreeNode;
72
+ static Collection = _TreeCollection.TreeCollection;
73
+ static Button = _TreeButton.TreeButton;
74
+ ref = null;
51
75
  constructor(props) {
52
76
  super(props);
53
- this.ref = null;
54
- this.handleCollectionClick = (e, collection, expand = true) => {
55
- e.stopPropagation();
56
- const onCollectionClick = this.props.onCollectionClick;
57
- if (expand) this.expandOrCollapseNode(collection);
58
- onCollectionClick === null || onCollectionClick === void 0 ? void 0 : onCollectionClick(collection.id, collection); // TODO: this should pass the event as the first arg
59
- this.handleSelection(collection.id, 'collection');
60
- };
61
- this.handleItemClick = (e, item) => {
62
- var _this$props$onItemCli, _this$props;
63
- e.stopPropagation();
64
- (_this$props$onItemCli = (_this$props = this.props).onItemClick) === null || _this$props$onItemCli === void 0 ? void 0 : _this$props$onItemCli.call(_this$props, item);
65
- this.handleSelection(item.id, 'item');
66
- };
67
- this.handleKeyDown = (event, node) => {
68
- switch (event.keyCode) {
69
- case _keycode.default.codes.down:
70
- case _keycode.default.codes.j:
71
- event.stopPropagation();
72
- this.moveFocus(1);
73
- break;
74
- case _keycode.default.codes.up:
75
- case _keycode.default.codes.k:
76
- event.stopPropagation();
77
- this.moveFocus(-1);
78
- break;
79
- case _keycode.default.codes.home:
80
- case _keycode.default.codes.end:
81
- event.stopPropagation();
82
- this.homeOrEnd(event.keyCode);
83
- break;
84
- case _keycode.default.codes.left:
85
- case _keycode.default.codes.right:
86
- event.stopPropagation();
87
- this.handleLeftOrRightArrow(event.keyCode, node);
88
- break;
89
- case _keycode.default.codes.enter:
90
- case _keycode.default.codes.space:
91
- event.stopPropagation();
92
- this.handleActivation(event, node);
93
- break;
94
- default:
95
- return;
96
- }
97
- event.preventDefault();
98
- };
99
- this.clearSelection = () => {
100
- const onSelectionChange = this.props.onSelectionChange;
101
-
102
- // Call the callback if provided (for controlled selection)
103
- if (onSelectionChange) {
104
- onSelectionChange('', 'item', void 0);
105
- }
106
-
107
- // Update internal state only if uncontrolled
108
- if (typeof this.props.selection === 'undefined') {
109
- this.setState({
110
- selection: ''
111
- });
112
- }
113
- };
114
- this.getIsFlattened = collection => {
115
- const _this$props2 = this.props,
116
- rootId = _this$props2.rootId,
117
- showRootCollection = _this$props2.showRootCollection;
118
- return !showRootCollection && typeof rootId !== 'undefined' && collection.id === rootId;
119
- };
120
77
  const initialState = {
121
78
  selection: ''
122
79
  };
@@ -133,20 +90,65 @@ let TreeBrowser = exports.TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.
133
90
  this.state = initialState;
134
91
  }
135
92
  componentDidMount() {
136
- var _this$props$makeStyle, _this$props3;
137
- (_this$props$makeStyle = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props3);
93
+ this.props.makeStyles?.();
138
94
  }
139
95
  componentDidUpdate() {
140
- var _this$props$makeStyle2, _this$props4;
141
- (_this$props$makeStyle2 = (_this$props4 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props4);
96
+ this.props.makeStyles?.();
142
97
  }
143
98
  get _root() {
144
99
  return this.ref;
145
100
  }
101
+ handleCollectionClick = (e, collection, expand = true) => {
102
+ e.stopPropagation();
103
+ const {
104
+ onCollectionClick
105
+ } = this.props;
106
+ if (expand) this.expandOrCollapseNode(collection);
107
+ onCollectionClick?.(collection.id, collection); // TODO: this should pass the event as the first arg
108
+ this.handleSelection(collection.id, 'collection');
109
+ };
110
+ handleItemClick = (e, item) => {
111
+ e.stopPropagation();
112
+ this.props.onItemClick?.(item);
113
+ this.handleSelection(item.id, 'item');
114
+ };
115
+ handleKeyDown = (event, node) => {
116
+ switch (event.keyCode) {
117
+ case _keycode.default.codes.down:
118
+ case _keycode.default.codes.j:
119
+ event.stopPropagation();
120
+ this.moveFocus(1);
121
+ break;
122
+ case _keycode.default.codes.up:
123
+ case _keycode.default.codes.k:
124
+ event.stopPropagation();
125
+ this.moveFocus(-1);
126
+ break;
127
+ case _keycode.default.codes.home:
128
+ case _keycode.default.codes.end:
129
+ event.stopPropagation();
130
+ this.homeOrEnd(event.keyCode);
131
+ break;
132
+ case _keycode.default.codes.left:
133
+ case _keycode.default.codes.right:
134
+ event.stopPropagation();
135
+ this.handleLeftOrRightArrow(event.keyCode, node);
136
+ break;
137
+ case _keycode.default.codes.enter:
138
+ case _keycode.default.codes.space:
139
+ event.stopPropagation();
140
+ this.handleActivation(event, node);
141
+ break;
142
+ default:
143
+ return;
144
+ }
145
+ event.preventDefault();
146
+ };
146
147
  get collections() {
147
- const _this$props5 = this.props,
148
- collections = _this$props5.collections,
149
- rootId = _this$props5.rootId;
148
+ const {
149
+ collections,
150
+ rootId
151
+ } = this.props;
150
152
  if (typeof rootId !== 'undefined') {
151
153
  return [collections[rootId]];
152
154
  } else {
@@ -166,8 +168,7 @@ let TreeBrowser = exports.TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.
166
168
  return typeof props.selection === 'undefined' ? state.selection : props.selection;
167
169
  }
168
170
  expandOrCollapseNode(collection) {
169
- var _this$props$onCollect, _this$props6;
170
- (_this$props$onCollect = (_this$props6 = this.props).onCollectionToggle) === null || _this$props$onCollect === void 0 ? void 0 : _this$props$onCollect.call(_this$props6, collection);
171
+ this.props.onCollectionToggle?.(collection);
171
172
  if (typeof this.props.expanded === 'undefined') {
172
173
  this.setState((state, props) => {
173
174
  const expanded = [...this.getExpanded(state, props)];
@@ -184,9 +185,10 @@ let TreeBrowser = exports.TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.
184
185
  }
185
186
  }
186
187
  handleSelection(id, type) {
187
- const _this$props7 = this.props,
188
- selectionType = _this$props7.selectionType,
189
- onSelectionChange = _this$props7.onSelectionChange;
188
+ const {
189
+ selectionType,
190
+ onSelectionChange
191
+ } = this.props;
190
192
  if (selectionType !== 'single') return;
191
193
  const selection = `${type}_${id}`;
192
194
 
@@ -208,6 +210,23 @@ let TreeBrowser = exports.TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.
208
210
  });
209
211
  }
210
212
  }
213
+ clearSelection = () => {
214
+ const {
215
+ onSelectionChange
216
+ } = this.props;
217
+
218
+ // Call the callback if provided (for controlled selection)
219
+ if (onSelectionChange) {
220
+ onSelectionChange('', 'item', undefined);
221
+ }
222
+
223
+ // Update internal state only if uncontrolled
224
+ if (typeof this.props.selection === 'undefined') {
225
+ this.setState({
226
+ selection: ''
227
+ });
228
+ }
229
+ };
211
230
  getNavigableNodes() {
212
231
  return Array.from(this.ref.querySelectorAll('[role="treeitem"]'));
213
232
  }
@@ -281,6 +300,13 @@ let TreeBrowser = exports.TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.
281
300
  return [];
282
301
  }
283
302
  }
303
+ getIsFlattened = collection => {
304
+ const {
305
+ rootId,
306
+ showRootCollection
307
+ } = this.props;
308
+ return !showRootCollection && typeof rootId !== 'undefined' && collection.id === rootId;
309
+ };
284
310
  getCollectionProps(collection) {
285
311
  return {
286
312
  id: collection.id,
@@ -314,14 +340,16 @@ let TreeBrowser = exports.TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.
314
340
  }, i));
315
341
  }
316
342
  render() {
317
- const styles = this.props.styles;
343
+ const {
344
+ styles
345
+ } = this.props;
318
346
  return (0, _jsxRuntime.jsx)(_TreeBrowserContext.default.Provider, {
319
347
  value: {
320
348
  animation: this.props.animation,
321
349
  clearSelection: this.clearSelection
322
350
  },
323
351
  children: (0, _jsxRuntime.jsx)("ul", {
324
- css: styles === null || styles === void 0 ? void 0 : styles.treeBrowser,
352
+ css: styles?.treeBrowser,
325
353
  tabIndex: 0,
326
354
  role: "tree",
327
355
  onKeyDown: this.handleKeyDown,
@@ -334,20 +362,5 @@ let TreeBrowser = exports.TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.
334
362
  })
335
363
  });
336
364
  }
337
- }, _TreeBrowser.displayName = "TreeBrowser", _TreeBrowser.componentId = 'TreeBrowser', _TreeBrowser.allowedProps = _props.allowedProps, _TreeBrowser.defaultProps = {
338
- size: 'medium',
339
- variant: 'folderTree',
340
- showRootCollection: true,
341
- collectionIcon: _uiIcons.FolderClosedInstUIIcon,
342
- collectionIconExpanded: _uiIcons.FolderClosedInstUIIcon,
343
- itemIcon: _uiIcons.FileTextInstUIIcon,
344
- getItemProps: props => props,
345
- getCollectionProps: props => props,
346
- defaultExpanded: [],
347
- selectionType: 'none',
348
- sortOrder: function () {
349
- return 0;
350
- },
351
- animation: true
352
- }, _TreeBrowser.Node = _TreeNode.TreeNode, _TreeBrowser.Collection = _TreeCollection.TreeCollection, _TreeBrowser.Button = _TreeButton.TreeButton, _TreeBrowser)) || _class);
365
+ }) || _class);
353
366
  var _default = exports.default = TreeBrowser;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-tree-browser",
3
- "version": "11.7.3-snapshot-7",
3
+ "version": "11.7.3-snapshot-26",
4
4
  "description": "A component for displaying a hierarchical view of information",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -14,23 +14,23 @@
14
14
  "bugs": "https://github.com/instructure/instructure-ui/issues",
15
15
  "license": "MIT",
16
16
  "dependencies": {
17
- "@babel/runtime": "^7.27.6",
17
+ "@babel/runtime": "^7.29.2",
18
18
  "keycode": "^2",
19
- "@instructure/emotion": "11.7.3-snapshot-7",
20
- "@instructure/shared-types": "11.7.3-snapshot-7",
21
- "@instructure/ui-icons": "11.7.3-snapshot-7",
22
- "@instructure/ui-react-utils": "11.7.3-snapshot-7",
23
- "@instructure/ui-img": "11.7.3-snapshot-7",
24
- "@instructure/ui-themes": "11.7.3-snapshot-7",
25
- "@instructure/ui-utils": "11.7.3-snapshot-7"
19
+ "@instructure/emotion": "11.7.3-snapshot-26",
20
+ "@instructure/shared-types": "11.7.3-snapshot-26",
21
+ "@instructure/ui-icons": "11.7.3-snapshot-26",
22
+ "@instructure/ui-img": "11.7.3-snapshot-26",
23
+ "@instructure/ui-react-utils": "11.7.3-snapshot-26",
24
+ "@instructure/ui-themes": "11.7.3-snapshot-26",
25
+ "@instructure/ui-utils": "11.7.3-snapshot-26"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@testing-library/jest-dom": "^6.6.3",
29
29
  "@testing-library/react": "15.0.7",
30
30
  "vitest": "^3.2.2",
31
- "@instructure/ui-babel-preset": "11.7.3-snapshot-7",
32
- "@instructure/ui-color-utils": "11.7.3-snapshot-7",
33
- "@instructure/ui-axe-check": "11.7.3-snapshot-7"
31
+ "@instructure/ui-axe-check": "11.7.3-snapshot-26",
32
+ "@instructure/ui-babel-preset": "11.7.3-snapshot-26",
33
+ "@instructure/ui-color-utils": "11.7.3-snapshot-26"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "react": ">=18 <=19"