@instructure/ui-tree-browser 11.6.0 → 11.6.1-snapshot-129

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 (168) hide show
  1. package/CHANGELOG.md +33 -288
  2. package/es/TreeBrowser/{TreeButton → v1/TreeButton}/index.js +2 -2
  3. package/es/TreeBrowser/{TreeCollection → v1/TreeCollection}/index.js +1 -1
  4. package/es/TreeBrowser/{TreeNode → v1/TreeNode}/index.js +2 -2
  5. package/es/TreeBrowser/{index.js → v1/index.js} +1 -1
  6. package/es/TreeBrowser/v2/TreeBrowserContext.js +39 -0
  7. package/es/TreeBrowser/v2/TreeButton/index.js +202 -0
  8. package/es/TreeBrowser/v2/TreeButton/props.js +26 -0
  9. package/es/TreeBrowser/v2/TreeButton/styles.js +306 -0
  10. package/es/TreeBrowser/v2/TreeCollection/index.js +367 -0
  11. package/es/TreeBrowser/v2/TreeCollection/props.js +26 -0
  12. package/es/TreeBrowser/v2/TreeCollection/styles.js +143 -0
  13. package/es/TreeBrowser/v2/TreeNode/index.js +156 -0
  14. package/es/{index.js → TreeBrowser/v2/TreeNode/props.js} +3 -4
  15. package/es/TreeBrowser/v2/index.js +347 -0
  16. package/es/TreeBrowser/v2/props.js +35 -0
  17. package/es/TreeBrowser/v2/styles.js +71 -0
  18. package/es/exports/a.js +27 -0
  19. package/es/exports/b.js +27 -0
  20. package/lib/TreeBrowser/{TreeButton → v1/TreeButton}/index.js +3 -3
  21. package/lib/TreeBrowser/{TreeCollection → v1/TreeCollection}/index.js +1 -1
  22. package/lib/TreeBrowser/{TreeNode → v1/TreeNode}/index.js +3 -3
  23. package/lib/TreeBrowser/{index.js → v1/index.js} +3 -3
  24. package/lib/TreeBrowser/v2/TreeBrowserContext.js +44 -0
  25. package/lib/TreeBrowser/v2/TreeButton/index.js +208 -0
  26. package/lib/TreeBrowser/v2/TreeButton/props.js +31 -0
  27. package/lib/TreeBrowser/v2/TreeButton/styles.js +312 -0
  28. package/lib/TreeBrowser/v2/TreeCollection/index.js +372 -0
  29. package/lib/TreeBrowser/v2/TreeCollection/props.js +31 -0
  30. package/lib/TreeBrowser/v2/TreeCollection/styles.js +149 -0
  31. package/lib/TreeBrowser/v2/TreeNode/index.js +162 -0
  32. package/lib/TreeBrowser/v2/TreeNode/props.js +31 -0
  33. package/lib/TreeBrowser/v2/index.js +353 -0
  34. package/lib/TreeBrowser/v2/props.js +40 -0
  35. package/lib/TreeBrowser/v2/styles.js +77 -0
  36. package/lib/{index.js → exports/a.js} +5 -5
  37. package/lib/exports/b.js +33 -0
  38. package/package.json +40 -18
  39. package/src/TreeBrowser/{TreeButton → v1/TreeButton}/index.tsx +2 -2
  40. package/src/TreeBrowser/{TreeCollection → v1/TreeCollection}/index.tsx +1 -1
  41. package/src/TreeBrowser/{TreeNode → v1/TreeNode}/index.tsx +2 -2
  42. package/src/TreeBrowser/{index.tsx → v1/index.tsx} +1 -1
  43. package/src/TreeBrowser/v2/README.md +712 -0
  44. package/src/TreeBrowser/v2/TreeBrowserContext.ts +53 -0
  45. package/src/TreeBrowser/v2/TreeButton/index.tsx +210 -0
  46. package/src/TreeBrowser/v2/TreeButton/props.ts +95 -0
  47. package/src/TreeBrowser/v2/TreeButton/styles.ts +331 -0
  48. package/src/TreeBrowser/v2/TreeCollection/index.tsx +416 -0
  49. package/src/TreeBrowser/v2/TreeCollection/props.ts +88 -0
  50. package/src/TreeBrowser/v2/TreeCollection/styles.ts +157 -0
  51. package/src/TreeBrowser/v2/TreeNode/index.tsx +158 -0
  52. package/src/TreeBrowser/v2/TreeNode/props.ts +84 -0
  53. package/src/TreeBrowser/v2/index.tsx +438 -0
  54. package/src/TreeBrowser/v2/props.ts +245 -0
  55. package/src/TreeBrowser/v2/styles.ts +79 -0
  56. package/src/exports/a.ts +32 -0
  57. package/src/exports/b.ts +32 -0
  58. package/tsconfig.build.tsbuildinfo +1 -1
  59. package/types/TreeBrowser/v1/TreeBrowserContext.d.ts.map +1 -0
  60. package/types/TreeBrowser/v1/TreeButton/index.d.ts.map +1 -0
  61. package/types/TreeBrowser/v1/TreeButton/props.d.ts.map +1 -0
  62. package/types/TreeBrowser/v1/TreeButton/styles.d.ts.map +1 -0
  63. package/types/TreeBrowser/v1/TreeButton/theme.d.ts.map +1 -0
  64. package/types/TreeBrowser/{TreeCollection → v1/TreeCollection}/index.d.ts +1 -1
  65. package/types/TreeBrowser/v1/TreeCollection/index.d.ts.map +1 -0
  66. package/types/TreeBrowser/v1/TreeCollection/props.d.ts.map +1 -0
  67. package/types/TreeBrowser/v1/TreeCollection/styles.d.ts.map +1 -0
  68. package/types/TreeBrowser/v1/TreeCollection/theme.d.ts.map +1 -0
  69. package/types/TreeBrowser/v1/TreeNode/index.d.ts.map +1 -0
  70. package/types/TreeBrowser/v1/TreeNode/props.d.ts.map +1 -0
  71. package/types/TreeBrowser/v1/index.d.ts.map +1 -0
  72. package/types/TreeBrowser/v1/props.d.ts.map +1 -0
  73. package/types/TreeBrowser/v1/styles.d.ts.map +1 -0
  74. package/types/TreeBrowser/v1/theme.d.ts.map +1 -0
  75. package/types/TreeBrowser/v2/TreeBrowserContext.d.ts +24 -0
  76. package/types/TreeBrowser/v2/TreeBrowserContext.d.ts.map +1 -0
  77. package/types/TreeBrowser/v2/TreeButton/index.d.ts +44 -0
  78. package/types/TreeBrowser/v2/TreeButton/index.d.ts.map +1 -0
  79. package/types/TreeBrowser/v2/TreeButton/props.d.ts +37 -0
  80. package/types/TreeBrowser/v2/TreeButton/props.d.ts.map +1 -0
  81. package/types/TreeBrowser/v2/TreeButton/styles.d.ts +19 -0
  82. package/types/TreeBrowser/v2/TreeButton/styles.d.ts.map +1 -0
  83. package/types/TreeBrowser/v2/TreeCollection/index.d.ts +66 -0
  84. package/types/TreeBrowser/v2/TreeCollection/index.d.ts.map +1 -0
  85. package/types/TreeBrowser/v2/TreeCollection/props.d.ts +24 -0
  86. package/types/TreeBrowser/v2/TreeCollection/props.d.ts.map +1 -0
  87. package/types/TreeBrowser/v2/TreeCollection/styles.d.ts +18 -0
  88. package/types/TreeBrowser/v2/TreeCollection/styles.d.ts.map +1 -0
  89. package/types/TreeBrowser/v2/TreeNode/index.d.ts +41 -0
  90. package/types/TreeBrowser/v2/TreeNode/index.d.ts.map +1 -0
  91. package/types/TreeBrowser/v2/TreeNode/props.d.ts +25 -0
  92. package/types/TreeBrowser/v2/TreeNode/props.d.ts.map +1 -0
  93. package/types/TreeBrowser/v2/index.d.ts +70 -0
  94. package/types/TreeBrowser/v2/index.d.ts.map +1 -0
  95. package/types/TreeBrowser/v2/props.d.ts +163 -0
  96. package/types/TreeBrowser/v2/props.d.ts.map +1 -0
  97. package/types/TreeBrowser/v2/styles.d.ts +16 -0
  98. package/types/TreeBrowser/v2/styles.d.ts.map +1 -0
  99. package/types/exports/a.d.ts +9 -0
  100. package/types/exports/a.d.ts.map +1 -0
  101. package/types/exports/b.d.ts +9 -0
  102. package/types/exports/b.d.ts.map +1 -0
  103. package/src/index.ts +0 -32
  104. package/types/TreeBrowser/TreeBrowserContext.d.ts.map +0 -1
  105. package/types/TreeBrowser/TreeButton/index.d.ts.map +0 -1
  106. package/types/TreeBrowser/TreeButton/props.d.ts.map +0 -1
  107. package/types/TreeBrowser/TreeButton/styles.d.ts.map +0 -1
  108. package/types/TreeBrowser/TreeButton/theme.d.ts.map +0 -1
  109. package/types/TreeBrowser/TreeCollection/index.d.ts.map +0 -1
  110. package/types/TreeBrowser/TreeCollection/props.d.ts.map +0 -1
  111. package/types/TreeBrowser/TreeCollection/styles.d.ts.map +0 -1
  112. package/types/TreeBrowser/TreeCollection/theme.d.ts.map +0 -1
  113. package/types/TreeBrowser/TreeNode/index.d.ts.map +0 -1
  114. package/types/TreeBrowser/TreeNode/props.d.ts.map +0 -1
  115. package/types/TreeBrowser/index.d.ts.map +0 -1
  116. package/types/TreeBrowser/props.d.ts.map +0 -1
  117. package/types/TreeBrowser/styles.d.ts.map +0 -1
  118. package/types/TreeBrowser/theme.d.ts.map +0 -1
  119. package/types/index.d.ts +0 -9
  120. package/types/index.d.ts.map +0 -1
  121. /package/es/TreeBrowser/{TreeBrowserContext.js → v1/TreeBrowserContext.js} +0 -0
  122. /package/es/TreeBrowser/{TreeButton → v1/TreeButton}/props.js +0 -0
  123. /package/es/TreeBrowser/{TreeButton → v1/TreeButton}/styles.js +0 -0
  124. /package/es/TreeBrowser/{TreeButton → v1/TreeButton}/theme.js +0 -0
  125. /package/es/TreeBrowser/{TreeCollection → v1/TreeCollection}/props.js +0 -0
  126. /package/es/TreeBrowser/{TreeCollection → v1/TreeCollection}/styles.js +0 -0
  127. /package/es/TreeBrowser/{TreeCollection → v1/TreeCollection}/theme.js +0 -0
  128. /package/es/TreeBrowser/{TreeNode → v1/TreeNode}/props.js +0 -0
  129. /package/es/TreeBrowser/{props.js → v1/props.js} +0 -0
  130. /package/es/TreeBrowser/{styles.js → v1/styles.js} +0 -0
  131. /package/es/TreeBrowser/{theme.js → v1/theme.js} +0 -0
  132. /package/lib/TreeBrowser/{TreeBrowserContext.js → v1/TreeBrowserContext.js} +0 -0
  133. /package/lib/TreeBrowser/{TreeButton → v1/TreeButton}/props.js +0 -0
  134. /package/lib/TreeBrowser/{TreeButton → v1/TreeButton}/styles.js +0 -0
  135. /package/lib/TreeBrowser/{TreeButton → v1/TreeButton}/theme.js +0 -0
  136. /package/lib/TreeBrowser/{TreeCollection → v1/TreeCollection}/props.js +0 -0
  137. /package/lib/TreeBrowser/{TreeCollection → v1/TreeCollection}/styles.js +0 -0
  138. /package/lib/TreeBrowser/{TreeCollection → v1/TreeCollection}/theme.js +0 -0
  139. /package/lib/TreeBrowser/{TreeNode → v1/TreeNode}/props.js +0 -0
  140. /package/lib/TreeBrowser/{props.js → v1/props.js} +0 -0
  141. /package/lib/TreeBrowser/{styles.js → v1/styles.js} +0 -0
  142. /package/lib/TreeBrowser/{theme.js → v1/theme.js} +0 -0
  143. /package/src/TreeBrowser/{README.md → v1/README.md} +0 -0
  144. /package/src/TreeBrowser/{TreeBrowserContext.ts → v1/TreeBrowserContext.ts} +0 -0
  145. /package/src/TreeBrowser/{TreeButton → v1/TreeButton}/props.ts +0 -0
  146. /package/src/TreeBrowser/{TreeButton → v1/TreeButton}/styles.ts +0 -0
  147. /package/src/TreeBrowser/{TreeButton → v1/TreeButton}/theme.ts +0 -0
  148. /package/src/TreeBrowser/{TreeCollection → v1/TreeCollection}/props.ts +0 -0
  149. /package/src/TreeBrowser/{TreeCollection → v1/TreeCollection}/styles.ts +0 -0
  150. /package/src/TreeBrowser/{TreeCollection → v1/TreeCollection}/theme.ts +0 -0
  151. /package/src/TreeBrowser/{TreeNode → v1/TreeNode}/props.ts +0 -0
  152. /package/src/TreeBrowser/{props.ts → v1/props.ts} +0 -0
  153. /package/src/TreeBrowser/{styles.ts → v1/styles.ts} +0 -0
  154. /package/src/TreeBrowser/{theme.ts → v1/theme.ts} +0 -0
  155. /package/types/TreeBrowser/{TreeBrowserContext.d.ts → v1/TreeBrowserContext.d.ts} +0 -0
  156. /package/types/TreeBrowser/{TreeButton → v1/TreeButton}/index.d.ts +0 -0
  157. /package/types/TreeBrowser/{TreeButton → v1/TreeButton}/props.d.ts +0 -0
  158. /package/types/TreeBrowser/{TreeButton → v1/TreeButton}/styles.d.ts +0 -0
  159. /package/types/TreeBrowser/{TreeButton → v1/TreeButton}/theme.d.ts +0 -0
  160. /package/types/TreeBrowser/{TreeCollection → v1/TreeCollection}/props.d.ts +0 -0
  161. /package/types/TreeBrowser/{TreeCollection → v1/TreeCollection}/styles.d.ts +0 -0
  162. /package/types/TreeBrowser/{TreeCollection → v1/TreeCollection}/theme.d.ts +0 -0
  163. /package/types/TreeBrowser/{TreeNode → v1/TreeNode}/index.d.ts +0 -0
  164. /package/types/TreeBrowser/{TreeNode → v1/TreeNode}/props.d.ts +0 -0
  165. /package/types/TreeBrowser/{index.d.ts → v1/index.d.ts} +0 -0
  166. /package/types/TreeBrowser/{props.d.ts → v1/props.d.ts} +0 -0
  167. /package/types/TreeBrowser/{styles.d.ts → v1/styles.d.ts} +0 -0
  168. /package/types/TreeBrowser/{theme.d.ts → v1/theme.d.ts} +0 -0
@@ -21,7 +21,6 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
- export { TreeBrowser } from "./TreeBrowser/index.js";
25
- export { TreeButton } from "./TreeBrowser/TreeButton/index.js";
26
- export { TreeCollection } from "./TreeBrowser/TreeCollection/index.js";
27
- export { TreeNode } from "./TreeBrowser/TreeNode/index.js";
24
+
25
+ const allowedProps = ['id', 'size', 'variant', 'selected', 'focused', 'itemIcon', 'thumbnail', 'level', 'children', 'containerRef', 'onKeyDown', 'onClick', 'hoverable'];
26
+ export { allowedProps };
@@ -0,0 +1,347 @@
1
+ var _dec, _class, _TreeBrowser;
2
+ /*
3
+ * The MIT License (MIT)
4
+ *
5
+ * Copyright (c) 2015 - present Instructure, Inc.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ import { Component } from 'react';
27
+ import keycode from 'keycode';
28
+ import { FolderClosedInstUIIcon, FileTextInstUIIcon } from '@instructure/ui-icons';
29
+ import { omitProps, pickProps } from '@instructure/ui-react-utils';
30
+ import { withStyle } from '@instructure/emotion';
31
+ import { TreeCollection } from "./TreeCollection/index.js";
32
+ import { TreeButton } from "./TreeButton/index.js";
33
+ import { TreeNode } from "./TreeNode/index.js";
34
+ import generateStyles from "./styles.js";
35
+ import { allowedProps } from "./props.js";
36
+ import TreeBrowserContext from "./TreeBrowserContext.js";
37
+ /**
38
+ ---
39
+ category: components
40
+ ---
41
+ **/
42
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
43
+ let TreeBrowser = (_dec = withStyle(generateStyles), _dec(_class = (_TreeBrowser = class TreeBrowser extends Component {
44
+ constructor(props) {
45
+ super(props);
46
+ this.ref = null;
47
+ this.handleCollectionClick = (e, collection, expand = true) => {
48
+ e.stopPropagation();
49
+ const onCollectionClick = this.props.onCollectionClick;
50
+ if (expand) this.expandOrCollapseNode(collection);
51
+ onCollectionClick === null || onCollectionClick === void 0 ? void 0 : onCollectionClick(collection.id, collection); // TODO: this should pass the event as the first arg
52
+ this.handleSelection(collection.id, 'collection');
53
+ };
54
+ this.handleItemClick = (e, item) => {
55
+ var _this$props$onItemCli, _this$props;
56
+ e.stopPropagation();
57
+ (_this$props$onItemCli = (_this$props = this.props).onItemClick) === null || _this$props$onItemCli === void 0 ? void 0 : _this$props$onItemCli.call(_this$props, item);
58
+ this.handleSelection(item.id, 'item');
59
+ };
60
+ this.handleKeyDown = (event, node) => {
61
+ switch (event.keyCode) {
62
+ case keycode.codes.down:
63
+ case keycode.codes.j:
64
+ event.stopPropagation();
65
+ this.moveFocus(1);
66
+ break;
67
+ case keycode.codes.up:
68
+ case keycode.codes.k:
69
+ event.stopPropagation();
70
+ this.moveFocus(-1);
71
+ break;
72
+ case keycode.codes.home:
73
+ case keycode.codes.end:
74
+ event.stopPropagation();
75
+ this.homeOrEnd(event.keyCode);
76
+ break;
77
+ case keycode.codes.left:
78
+ case keycode.codes.right:
79
+ event.stopPropagation();
80
+ this.handleLeftOrRightArrow(event.keyCode, node);
81
+ break;
82
+ case keycode.codes.enter:
83
+ case keycode.codes.space:
84
+ event.stopPropagation();
85
+ this.handleActivation(event, node);
86
+ break;
87
+ default:
88
+ return;
89
+ }
90
+ event.preventDefault();
91
+ };
92
+ this.clearSelection = () => {
93
+ const onSelectionChange = this.props.onSelectionChange;
94
+
95
+ // Call the callback if provided (for controlled selection)
96
+ if (onSelectionChange) {
97
+ onSelectionChange('', 'item', void 0);
98
+ }
99
+
100
+ // Update internal state only if uncontrolled
101
+ if (typeof this.props.selection === 'undefined') {
102
+ this.setState({
103
+ selection: ''
104
+ });
105
+ }
106
+ };
107
+ this.getIsFlattened = collection => {
108
+ const _this$props2 = this.props,
109
+ rootId = _this$props2.rootId,
110
+ showRootCollection = _this$props2.showRootCollection;
111
+ return !showRootCollection && typeof rootId !== 'undefined' && collection.id === rootId;
112
+ };
113
+ const initialState = {
114
+ selection: ''
115
+ };
116
+
117
+ // Handle expanded state (controlled vs uncontrolled)
118
+ if (typeof this.props.expanded === 'undefined') {
119
+ initialState.expanded = this.props.defaultExpanded;
120
+ }
121
+
122
+ // Handle selection state (controlled vs uncontrolled)
123
+ if (typeof this.props.selection === 'undefined') {
124
+ initialState.selection = this.props.defaultSelection || '';
125
+ }
126
+ this.state = initialState;
127
+ }
128
+ componentDidMount() {
129
+ var _this$props$makeStyle, _this$props3;
130
+ (_this$props$makeStyle = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props3);
131
+ }
132
+ componentDidUpdate() {
133
+ var _this$props$makeStyle2, _this$props4;
134
+ (_this$props$makeStyle2 = (_this$props4 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props4);
135
+ }
136
+ get _root() {
137
+ return this.ref;
138
+ }
139
+ get collections() {
140
+ const _this$props5 = this.props,
141
+ collections = _this$props5.collections,
142
+ rootId = _this$props5.rootId;
143
+ if (typeof rootId !== 'undefined') {
144
+ return [collections[rootId]];
145
+ } else {
146
+ return Object.keys(collections).map(id => collections[id]).filter(collection => collection != null);
147
+ }
148
+ }
149
+ get expanded() {
150
+ return this.getExpanded(this.state, this.props);
151
+ }
152
+ getExpanded(state, props) {
153
+ return typeof props.expanded === 'undefined' ? state.expanded : props.expanded;
154
+ }
155
+ get selection() {
156
+ return this.getSelection(this.state, this.props);
157
+ }
158
+ getSelection(state, props) {
159
+ return typeof props.selection === 'undefined' ? state.selection : props.selection;
160
+ }
161
+ expandOrCollapseNode(collection) {
162
+ var _this$props$onCollect, _this$props6;
163
+ (_this$props$onCollect = (_this$props6 = this.props).onCollectionToggle) === null || _this$props$onCollect === void 0 ? void 0 : _this$props$onCollect.call(_this$props6, collection);
164
+ if (typeof this.props.expanded === 'undefined') {
165
+ this.setState((state, props) => {
166
+ const expanded = [...this.getExpanded(state, props)];
167
+ const expandedIndex = this.getExpandedIndex(expanded, collection.id);
168
+ if (collection.expanded && expandedIndex < 0) {
169
+ expanded.push(collection.id);
170
+ } else if (expandedIndex >= 0) {
171
+ expanded.splice(expandedIndex, 1);
172
+ }
173
+ return {
174
+ expanded
175
+ };
176
+ });
177
+ }
178
+ }
179
+ handleSelection(id, type) {
180
+ const _this$props7 = this.props,
181
+ selectionType = _this$props7.selectionType,
182
+ onSelectionChange = _this$props7.onSelectionChange;
183
+ if (selectionType !== 'single') return;
184
+ const selection = `${type}_${id}`;
185
+
186
+ // Call the callback if provided (for controlled selection)
187
+ if (onSelectionChange) {
188
+ onSelectionChange(selection, type, id);
189
+ }
190
+
191
+ // Update internal state only if uncontrolled
192
+ if (typeof this.props.selection === 'undefined') {
193
+ this.setState(state => {
194
+ if (state.selection !== selection) {
195
+ return {
196
+ selection
197
+ };
198
+ } else {
199
+ return state;
200
+ }
201
+ });
202
+ }
203
+ }
204
+ getNavigableNodes() {
205
+ return Array.from(this.ref.querySelectorAll('[role="treeitem"]'));
206
+ }
207
+ moveFocus(delta) {
208
+ const nodes = this.getNavigableNodes();
209
+ const closest = window.document.activeElement.closest('[role="treeitem"]');
210
+ const active = nodes.indexOf(closest);
211
+ let next = active + delta;
212
+ if (next < 0) {
213
+ next = 0;
214
+ } else if (next >= nodes.length) {
215
+ next = nodes.length - 1;
216
+ }
217
+ nodes.forEach(n => {
218
+ n.setAttribute('tabindex', '-1');
219
+ });
220
+ nodes[next].setAttribute('tabindex', '0');
221
+ nodes[next].focus();
222
+ }
223
+ homeOrEnd(keyCode) {
224
+ const length = this.getNavigableNodes().length;
225
+ if (keyCode === keycode.codes.home) {
226
+ this.moveFocus(1 - length);
227
+ } else {
228
+ this.moveFocus(length - 1);
229
+ }
230
+ }
231
+ handleLeftOrRightArrow(keyCode, node) {
232
+ const ltr = !(this.ref.parentElement.dir === 'rtl' || document.dir === 'rtl');
233
+ if (ltr && keyCode === keycode.codes.left || !ltr && keyCode == keycode.codes.right) {
234
+ this.handleCloseOrPrevious(node);
235
+ } else {
236
+ this.handleOpenOrNext(node);
237
+ }
238
+ }
239
+ handleOpenOrNext(node) {
240
+ if (node && !this.expanded.includes(node.id) && node.type === 'collection') {
241
+ this.expandOrCollapseNode(node);
242
+ } else {
243
+ this.moveFocus(1);
244
+ }
245
+ }
246
+ handleCloseOrPrevious(node) {
247
+ if (node && this.expanded.includes(node.id) && node.type === 'collection') {
248
+ this.expandOrCollapseNode(node);
249
+ } else {
250
+ this.moveFocus(-1);
251
+ }
252
+ }
253
+ handleActivation(event, node) {
254
+ if (node == null) return;
255
+ if (node.type === 'collection') {
256
+ this.handleCollectionClick(event, node, this.props.selectionType === 'none');
257
+ } else {
258
+ this.handleItemClick(event, node);
259
+ }
260
+ }
261
+ getSubCollections(collection) {
262
+ const collections = collection.collections ? [...collection.collections] : [];
263
+ return collections.map(id => this.getCollectionProps(this.props.collections[id])).filter(collection => collection != null).sort(this.props.sortOrder);
264
+ }
265
+ getItems(collection) {
266
+ if (collection.items) {
267
+ const items = collection.items ? [...collection.items] : [];
268
+ return items.map(id => {
269
+ return {
270
+ ...this.props.items[id]
271
+ };
272
+ }).filter(item => item != null).sort(this.props.sortOrder);
273
+ } else {
274
+ return [];
275
+ }
276
+ }
277
+ getCollectionProps(collection) {
278
+ return {
279
+ id: collection.id,
280
+ name: collection.name,
281
+ collections: this.getSubCollections(collection),
282
+ items: this.getItems(collection),
283
+ descriptor: collection.descriptor,
284
+ containerRef: collection.containerRef,
285
+ renderBeforeItems: collection.renderBeforeItems,
286
+ renderAfterItems: collection.renderAfterItems,
287
+ expanded: this.getExpandedIndex(this.expanded, collection.id) >= 0,
288
+ isCollectionFlattened: this.getIsFlattened(collection),
289
+ compareFunc: collection.compareFunc
290
+ };
291
+ }
292
+ getExpandedIndex(expanded, id) {
293
+ return expanded.findIndex(expanded => String(expanded) === String(id));
294
+ }
295
+ renderRoot() {
296
+ return this.collections.sort(this.props.sortOrder).map((collection, i) => _jsx(TreeCollection, {
297
+ ...pickProps(omitProps(this.props), TreeCollection.allowedProps),
298
+ ...this.getCollectionProps(collection),
299
+ selection: this.selection,
300
+ onItemClick: this.handleItemClick,
301
+ onCollectionClick: this.handleCollectionClick,
302
+ onKeyDown: this.handleKeyDown,
303
+ numChildren: this.collections.length,
304
+ level: 1,
305
+ position: 1,
306
+ renderContent: this.props.renderContent
307
+ }, i));
308
+ }
309
+ render() {
310
+ const styles = this.props.styles;
311
+ return _jsx(TreeBrowserContext.Provider, {
312
+ value: {
313
+ animation: this.props.animation,
314
+ clearSelection: this.clearSelection
315
+ },
316
+ children: _jsx("ul", {
317
+ css: styles === null || styles === void 0 ? void 0 : styles.treeBrowser,
318
+ tabIndex: 0,
319
+ role: "tree",
320
+ onKeyDown: this.handleKeyDown,
321
+ ref: el => {
322
+ this.ref = el;
323
+ },
324
+ "aria-label": this.props.treeLabel,
325
+ "data-cid": "TreeBrowser",
326
+ children: this.renderRoot()
327
+ })
328
+ });
329
+ }
330
+ }, _TreeBrowser.displayName = "TreeBrowser", _TreeBrowser.componentId = 'TreeBrowser', _TreeBrowser.allowedProps = allowedProps, _TreeBrowser.defaultProps = {
331
+ size: 'medium',
332
+ variant: 'folderTree',
333
+ showRootCollection: true,
334
+ collectionIcon: FolderClosedInstUIIcon,
335
+ collectionIconExpanded: FolderClosedInstUIIcon,
336
+ itemIcon: FileTextInstUIIcon,
337
+ getItemProps: props => props,
338
+ getCollectionProps: props => props,
339
+ defaultExpanded: [],
340
+ selectionType: 'none',
341
+ sortOrder: function () {
342
+ return 0;
343
+ },
344
+ animation: true
345
+ }, _TreeBrowser.Node = TreeNode, _TreeBrowser.Collection = TreeCollection, _TreeBrowser.Button = TreeButton, _TreeBrowser)) || _class);
346
+ export default TreeBrowser;
347
+ export { TreeBrowser };
@@ -0,0 +1,35 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ // props shared between TreeBrowser, TreeCollection
26
+
27
+ // props shared between TreeBrowser, TreeCollection, TreeButton
28
+
29
+ // For now it doesn't need the OtherHTMLAttributes, because the extra props
30
+ // get passed to TreeCollection and it doesn't handle them
31
+
32
+ // this is a sum type, so CompareObject is one of CompareCollection OR CompareItem
33
+
34
+ const allowedProps = ['collections', 'items', 'rootId', 'expanded', 'defaultExpanded', 'selection', 'defaultSelection', 'onSelectionChange', 'selectionType', 'size', 'variant', 'collectionIcon', 'collectionIconExpanded', 'itemIcon', 'getItemProps', 'getCollectionProps', 'showRootCollection', 'onCollectionClick', 'onCollectionToggle', 'onItemClick', 'treeLabel', 'renderContent', 'sortOrder', 'animation'];
35
+ export { allowedProps };
@@ -0,0 +1,71 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import { calcFocusOutlineStyles } from '@instructure/emotion';
26
+ /**
27
+ * ---
28
+ * private: true
29
+ * ---
30
+ * Generates the style object from the theme and provided additional information
31
+ * @param {Object} componentTheme The theme variable object.
32
+ * @param {Object} _props the props of the component, the style is applied to
33
+ * @param {Object} sharedTokens Shared token object that stores common values for the theme.
34
+ * @param {Object} state the state of the component, the style is applied to
35
+ * @return {Object} The final style object, which will be used in the component
36
+ */
37
+
38
+ const generateStyles = (componentTheme, _props, sharedTokens) => {
39
+ return {
40
+ treeBrowser: {
41
+ label: 'treeBrowser',
42
+ boxSizing: 'border-box',
43
+ margin: '0',
44
+ padding: '0',
45
+ listStyleType: 'none',
46
+ position: 'relative',
47
+ outline: 'none',
48
+ borderRadius: componentTheme.borderRadius,
49
+ ...calcFocusOutlineStyles(sharedTokens.focusOutline),
50
+ '&::before': {
51
+ content: '""',
52
+ pointerEvents: 'none',
53
+ boxSizing: 'border-box',
54
+ display: 'block',
55
+ position: 'absolute',
56
+ top: '-0.25rem',
57
+ bottom: '-0.25rem',
58
+ left: '-0.25rem',
59
+ right: '-0.25rem',
60
+ transition: 'all 0.2s',
61
+ opacity: 0,
62
+ transform: 'scale(0.95)'
63
+ },
64
+ '&:focus::before': {
65
+ opacity: 1,
66
+ transform: 'scale(1)'
67
+ }
68
+ }
69
+ };
70
+ };
71
+ export default generateStyles;
@@ -0,0 +1,27 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ export { TreeBrowser } from "../TreeBrowser/v1/index.js";
25
+ export { TreeButton } from "../TreeBrowser/v1/TreeButton/index.js";
26
+ export { TreeCollection } from "../TreeBrowser/v1/TreeCollection/index.js";
27
+ export { TreeNode } from "../TreeBrowser/v1/TreeNode/index.js";
@@ -0,0 +1,27 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ export { TreeBrowser } from "../TreeBrowser/v2/index.js";
25
+ export { TreeButton } from "../TreeBrowser/v2/TreeButton/index.js";
26
+ export { TreeCollection } from "../TreeBrowser/v2/TreeCollection/index.js";
27
+ export { TreeNode } from "../TreeBrowser/v2/TreeNode/index.js";
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = exports.TreeButton = void 0;
8
8
  var _react = require("react");
9
- var _Img = require("@instructure/ui-img/lib/Img");
9
+ var _v11_ = require("@instructure/ui-img/v11_6");
10
10
  var _callRenderProp = require("@instructure/ui-react-utils/lib/callRenderProp.js");
11
11
  var _emotion = require("@instructure/emotion");
12
12
  var _styles = _interopRequireDefault(require("./styles"));
@@ -45,7 +45,7 @@ parent: TreeBrowser
45
45
  id: TreeBrowser.Button
46
46
  ---
47
47
  **/
48
- let TreeButton = exports.TreeButton = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec(_class = (_TreeButton = class TreeButton extends _react.Component {
48
+ let TreeButton = exports.TreeButton = (_dec = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = (_TreeButton = class TreeButton extends _react.Component {
49
49
  constructor(...args) {
50
50
  super(...args);
51
51
  this.ref = null;
@@ -121,7 +121,7 @@ let TreeButton = exports.TreeButton = (_dec = (0, _emotion.withStyle)(_styles.de
121
121
  if (thumbnail) {
122
122
  return (0, _jsxRuntime.jsx)("div", {
123
123
  css: styles === null || styles === void 0 ? void 0 : styles.thumbnail,
124
- children: (0, _jsxRuntime.jsx)(_Img.Img, {
124
+ children: (0, _jsxRuntime.jsx)(_v11_.Img, {
125
125
  src: thumbnail,
126
126
  constrain: "cover",
127
127
  alt: ""
@@ -45,7 +45,7 @@ parent: TreeBrowser
45
45
  id: TreeBrowser.Collection
46
46
  ---
47
47
  **/
48
- let TreeCollection = exports.TreeCollection = (_dec = (0, _emotion.withStyle)(_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 = (_TreeCollection = class TreeCollection extends _react.Component {
49
49
  constructor(props) {
50
50
  super(props);
51
51
  this.ref = null;
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = exports.TreeNode = void 0;
8
8
  var _react = require("react");
9
- var _Img = require("@instructure/ui-img/lib/Img");
9
+ var _v11_ = require("@instructure/ui-img/v11_6");
10
10
  var _callRenderProp = require("@instructure/ui-react-utils/lib/callRenderProp.js");
11
11
  var _emotion = require("@instructure/emotion");
12
12
  var _styles = _interopRequireDefault(require("../TreeButton/styles"));
@@ -47,7 +47,7 @@ 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.withStyle)(_styles.default, _theme.default), _dec(_class = (_TreeNode = class TreeNode extends _react.Component {
50
+ let TreeNode = exports.TreeNode = (_dec = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = (_TreeNode = class TreeNode extends _react.Component {
51
51
  constructor(...args) {
52
52
  super(...args);
53
53
  this.ref = null;
@@ -78,7 +78,7 @@ let TreeNode = exports.TreeNode = (_dec = (0, _emotion.withStyle)(_styles.defaul
78
78
  if (thumbnail) {
79
79
  return (0, _jsxRuntime.jsx)("div", {
80
80
  css: styles === null || styles === void 0 ? void 0 : styles.thumbnail,
81
- children: (0, _jsxRuntime.jsx)(_Img.Img, {
81
+ children: (0, _jsxRuntime.jsx)(_v11_.Img, {
82
82
  src: thumbnail,
83
83
  constrain: "cover",
84
84
  alt: ""
@@ -7,8 +7,8 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.default = exports.TreeBrowser = void 0;
8
8
  var _react = require("react");
9
9
  var _keycode = _interopRequireDefault(require("keycode"));
10
- var _IconFolderLine = require("@instructure/ui-icons/lib/IconFolderLine.js");
11
- var _IconDocumentLine = require("@instructure/ui-icons/lib/IconDocumentLine.js");
10
+ var _IconFolderLine = require("@instructure/ui-icons/lib/generated/IconFolderLine.js");
11
+ var _IconDocumentLine = require("@instructure/ui-icons/lib/generated/IconDocumentLine.js");
12
12
  var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js");
13
13
  var _pickProps = require("@instructure/ui-react-utils/lib/pickProps.js");
14
14
  var _emotion = require("@instructure/emotion");
@@ -49,7 +49,7 @@ var _dec, _class, _TreeBrowser;
49
49
  category: components
50
50
  ---
51
51
  **/
52
- let TreeBrowser = exports.TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec(_class = (_TreeBrowser = class TreeBrowser extends _react.Component {
52
+ let TreeBrowser = exports.TreeBrowser = (_dec = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = (_TreeBrowser = class TreeBrowser extends _react.Component {
53
53
  constructor(props) {
54
54
  super(props);
55
55
  this.ref = null;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.TreeBrowserContext = void 0;
7
+ var _react = require("react");
8
+ /*
9
+ * The MIT License (MIT)
10
+ *
11
+ * Copyright (c) 2015 - present Instructure, Inc.
12
+ *
13
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ * of this software and associated documentation files (the "Software"), to deal
15
+ * in the Software without restriction, including without limitation the rights
16
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ * copies of the Software, and to permit persons to whom the Software is
18
+ * furnished to do so, subject to the following conditions:
19
+ *
20
+ * The above copyright notice and this permission notice shall be included in all
21
+ * copies or substantial portions of the Software.
22
+ *
23
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ * SOFTWARE.
30
+ */
31
+
32
+ /**
33
+ * ---
34
+ * category: components/contexts
35
+ * ---
36
+ * React context created by the `TreeBrowser` component to hold its data which are
37
+ * read by its children.
38
+ *
39
+ * @module
40
+ */
41
+ const TreeBrowserContext = exports.TreeBrowserContext = /*#__PURE__*/(0, _react.createContext)({
42
+ animation: true
43
+ });
44
+ var _default = exports.default = TreeBrowserContext;