@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
@@ -0,0 +1,367 @@
1
+ var _dec, _class, _TreeCollection;
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 { withStyle } from '@instructure/emotion';
28
+ import { safeCloneElement } from '@instructure/ui-react-utils';
29
+ import { TreeButton } from "../TreeButton/index.js";
30
+ import generateStyles from "./styles.js";
31
+ import { allowedProps } from "./props.js";
32
+ import TreeBrowserContext from "../TreeBrowserContext.js";
33
+ import { Fragment as _Fragment, jsxs as _jsxs, jsx as _jsx } from "@emotion/react/jsx-runtime";
34
+ import { createElement as _createElement } from "@emotion/react";
35
+ /**
36
+ ---
37
+ parent: TreeBrowser
38
+ id: TreeBrowser.Collection
39
+ ---
40
+ **/
41
+ let TreeCollection = (_dec = withStyle(generateStyles, 'TreeBrowserTreeCollection'), _dec(_class = (_TreeCollection = class TreeCollection extends Component {
42
+ constructor(props) {
43
+ 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
+ this.state = {
86
+ focused: ''
87
+ };
88
+ }
89
+ 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
93
+ });
94
+ }
95
+ 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
99
+ });
100
+ }
101
+ get itemsLevel() {
102
+ const _this$props5 = this.props,
103
+ level = _this$props5.level,
104
+ isCollectionFlattened = _this$props5.isCollectionFlattened;
105
+ return isCollectionFlattened ? level : level + 1;
106
+ }
107
+ get collectionsCount() {
108
+ const collections = this.props.collections;
109
+ return collections && collections.length > 0 ? collections.length : 0;
110
+ }
111
+ get itemsCount() {
112
+ const items = this.props.items;
113
+ return items && items.length > 0 ? items.length : 0;
114
+ }
115
+ get childCount() {
116
+ return this.collectionsCount + this.itemsCount + (this.props.renderBeforeItems ? 1 : 0) + (this.props.renderAfterItems ? 1 : 0);
117
+ }
118
+ sortChildren() {
119
+ const _this$props6 = this.props,
120
+ collections = _this$props6.collections,
121
+ items = _this$props6.items,
122
+ compareFunc = _this$props6.compareFunc;
123
+ if (!compareFunc) return [];
124
+ const collections_ = collections ? collections.map(collection => {
125
+ return {
126
+ ...collection,
127
+ type: 'collection'
128
+ };
129
+ }) : [];
130
+ const items_ = items ? items.map(item => {
131
+ return {
132
+ ...item,
133
+ type: 'item'
134
+ };
135
+ }) : [];
136
+ const renderQueue = collections_.concat(items_);
137
+ renderQueue.sort(compareFunc);
138
+ return renderQueue;
139
+ }
140
+ 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;
148
+ let position = 1;
149
+ const sortedChildren = this.sortChildren();
150
+ return _jsxs(_Fragment, {
151
+ children: [renderBeforeItems && this.renderCollectionChildren(id, renderBeforeItems, position++, 'before'), !compareFunc && collections.map(collection => {
152
+ return this.renderCollectionNode(collection, position++);
153
+ }), !compareFunc && items.map(item => {
154
+ return this.renderItemNode(item, position++);
155
+ }), compareFunc && sortedChildren.map(child => {
156
+ if (child.type === 'collection') {
157
+ return this.renderCollectionNode(child, position++);
158
+ } else {
159
+ return this.renderItemNode(child, position++);
160
+ }
161
+ }), renderAfterItems && this.renderCollectionChildren(id, renderAfterItems, position++, 'after')]
162
+ });
163
+ }
164
+ 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;
170
+ const key = `${collectionId}_${keyword}`;
171
+ const ariaSelected = {};
172
+ if (selection) {
173
+ ariaSelected['aria-selected'] = selection === `child_${key}`;
174
+ }
175
+ const itemHash = {
176
+ id: key,
177
+ type: 'child'
178
+ };
179
+ const itemProps = getItemProps({
180
+ key: key,
181
+ selected: selection === `child_${key}`,
182
+ focused: this.state.focused === `child_${key}`,
183
+ level: this.itemsLevel,
184
+ size: this.props.size,
185
+ variant: this.props.variant
186
+ });
187
+ return _jsx("li", {
188
+ id: key
189
+ /* eslint-disable-next-line jsx-a11y/role-has-required-aria-props */,
190
+ role: "treeitem",
191
+ css: styles === null || styles === void 0 ? void 0 : styles.item,
192
+ tabIndex: -1,
193
+ "aria-posinset": position,
194
+ "aria-setsize": this.childCount,
195
+ "aria-level": this.itemsLevel,
196
+ ...ariaSelected,
197
+ onClick: e => {
198
+ if (typeof child.props.onClick === 'function') {
199
+ child.props.onClick(e);
200
+ } else {
201
+ e.stopPropagation();
202
+ }
203
+ },
204
+ onFocus: e => this.handleFocus(e, itemHash),
205
+ onKeyDown: e => {
206
+ if (typeof child.props.onKeyDown === 'function') {
207
+ child.props.onKeyDown(e);
208
+ } else {
209
+ onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e, itemHash);
210
+ }
211
+ },
212
+ onBlur: e => this.handleBlur(e, itemHash),
213
+ children: safeCloneElement(child, itemProps)
214
+ }, key);
215
+ }
216
+ renderCollectionNode(collection, position) {
217
+ return _createElement(TreeCollection, {
218
+ ...this.props,
219
+ key: `c${position}`,
220
+ id: collection.id,
221
+ name: collection.name,
222
+ descriptor: collection.descriptor,
223
+ expanded: collection.expanded,
224
+ items: collection.items,
225
+ collections: collection.collections,
226
+ numChildren: this.childCount,
227
+ level: this.itemsLevel,
228
+ containerRef: collection.containerRef,
229
+ position: position,
230
+ renderBeforeItems: collection.renderBeforeItems,
231
+ renderAfterItems: collection.renderAfterItems,
232
+ isCollectionFlattened: false // only the root needs to be flattened
233
+ ,
234
+ compareFunc: collection.compareFunc
235
+ });
236
+ }
237
+ 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;
244
+ const ariaSelected = {};
245
+ if (selection) {
246
+ ariaSelected['aria-selected'] = selection === `item_${item.id}`;
247
+ }
248
+ const itemHash = {
249
+ id: item.id,
250
+ type: 'item'
251
+ };
252
+ const itemProps = getItemProps({
253
+ ...this.getCommonButtonProps(),
254
+ id: item.id,
255
+ name: item.name,
256
+ descriptor: item.descriptor,
257
+ thumbnail: item.thumbnail,
258
+ selected: selection === `item_${item.id}`,
259
+ focused: this.state.focused === `item_${item.id}`,
260
+ type: 'item'
261
+ });
262
+ return _jsx("li", {
263
+ tabIndex: -1
264
+ /* eslint-disable-next-line jsx-a11y/role-has-required-aria-props */,
265
+ role: "treeitem",
266
+ "aria-label": item.name,
267
+ css: styles === null || styles === void 0 ? void 0 : styles.item,
268
+ "aria-level": this.itemsLevel,
269
+ "aria-posinset": position,
270
+ "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),
273
+ onFocus: e => this.handleFocus(e, itemHash),
274
+ onBlur: e => this.handleBlur(e, itemHash),
275
+ ...ariaSelected,
276
+ children: _jsx(TreeButton, {
277
+ ...itemProps
278
+ })
279
+ }, `i${position}`);
280
+ }
281
+ getCommonButtonProps() {
282
+ return {
283
+ id: this.props.id,
284
+ name: this.props.name,
285
+ descriptor: this.props.descriptor,
286
+ size: this.props.size,
287
+ variant: this.props.variant,
288
+ itemIcon: this.props.itemIcon,
289
+ level: this.itemsLevel,
290
+ renderContent: this.props.renderContent
291
+ };
292
+ }
293
+ 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;
305
+ const collectionProps = getCollectionProps({
306
+ ...this.getCommonButtonProps(),
307
+ expanded: expanded,
308
+ collectionIcon: collectionIcon,
309
+ collectionIconExpanded: collectionIconExpanded,
310
+ type: 'collection',
311
+ containerRef: this.props.containerRef,
312
+ selected: this.props.selection === `collection_${id}`,
313
+ focused: this.state.focused === `collection_${id}`,
314
+ level
315
+ });
316
+ const ariaSelected = {
317
+ 'aria-selected': void 0
318
+ };
319
+ if (this.props.selection) ariaSelected['aria-selected'] = this.props.selection === `collection_${id}`;
320
+ return isCollectionFlattened ? this.renderChildren() : _jsxs("li", {
321
+ ref: el => {
322
+ this.ref = el;
323
+ },
324
+ css: styles === null || styles === void 0 ? void 0 : styles.treeCollection,
325
+ tabIndex: -1
326
+ /* eslint-disable-next-line jsx-a11y/role-has-required-aria-props */,
327
+ role: "treeitem",
328
+ "aria-label": `${this.props.name}${this.props.descriptor ? ` ${this.props.descriptor}` : ''}`,
329
+ "aria-level": level,
330
+ "aria-posinset": position,
331
+ "aria-setsize": this.props.numChildren,
332
+ "aria-expanded": expanded,
333
+ onClick: this.handleCollectionClick,
334
+ onKeyDown: this.handleCollectionKeyDown,
335
+ onFocus: e => this.handleFocus(e, {
336
+ id: id,
337
+ type: 'collection'
338
+ }),
339
+ onBlur: e => this.handleBlur(e, {
340
+ id: id,
341
+ type: 'collection'
342
+ }),
343
+ ...ariaSelected,
344
+ "data-cid": "TreeCollection",
345
+ children: [_jsx(TreeButton, {
346
+ ...collectionProps
347
+ }), expanded && this.childCount > 0 && _jsx("ul", {
348
+ "aria-label": name,
349
+ css: styles === null || styles === void 0 ? void 0 : styles.list,
350
+ role: "group",
351
+ children: this.renderChildren()
352
+ })]
353
+ });
354
+ }
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);
366
+ export default TreeCollection;
367
+ export { TreeCollection };
@@ -0,0 +1,26 @@
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
+ const allowedProps = ['id', 'name', 'descriptor', 'items', 'collections', 'expanded', 'selection', 'size', 'variant', 'collectionIcon', 'collectionIconExpanded', 'itemIcon', 'getItemProps', 'getCollectionProps', 'onItemClick', 'onCollectionClick', 'onKeyDown', 'numChildren', 'level', 'position', 'renderBeforeItems', 'renderAfterItems', 'containerRef', 'isCollectionFlattened', 'renderContent'];
26
+ export { allowedProps };
@@ -0,0 +1,143 @@
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 { keyframes, calcFocusOutlineStyles } from '@instructure/emotion';
26
+ const list = keyframes`
27
+ to {
28
+ transform: scaleY(1);
29
+ }`;
30
+
31
+ /**
32
+ * ---
33
+ * private: true
34
+ * ---
35
+ * Generates the style object from the theme and provided additional information
36
+ * @param {Object} componentTheme The theme variable object.
37
+ * @param {Object} props the props of the component, the style is applied to
38
+ * @param {Object} sharedTokens Shared token object that stores common values for the theme.
39
+ * @param {Object} state the state of the component, the style is applied to
40
+ * @return {Object} The final style object, which will be used in the component
41
+ */
42
+
43
+ const generateStyles = (componentTheme, props, sharedTokens, state) => {
44
+ const size = props.size,
45
+ variant = props.variant;
46
+ const sizeMap = {
47
+ small: {
48
+ indent: {
49
+ marginInlineStart: `calc(${componentTheme.baseSpacingSmall} * 3)`,
50
+ marginInlineEnd: 0
51
+ },
52
+ folderTree: {
53
+ marginInlineStart: `calc(${componentTheme.baseSpacingSmall} * 2)`,
54
+ marginInlineEnd: 0,
55
+ paddingTop: `calc(1.75 * ${componentTheme.baseSpacingSmall})`,
56
+ marginTop: `calc(-1.75 * ${componentTheme.baseSpacingSmall})`
57
+ }
58
+ },
59
+ medium: {
60
+ indent: {
61
+ marginInlineStart: `calc(${componentTheme.baseSpacingMedium} * 3)`,
62
+ marginInlineEnd: 0
63
+ },
64
+ folderTree: {
65
+ marginInlineStart: `calc(${componentTheme.baseSpacingMedium} * 2)`,
66
+ marginInlineEnd: 0,
67
+ paddingTop: componentTheme.baseSpacingMedium,
68
+ marginTop: `calc(-1 * ${componentTheme.baseSpacingMedium})`
69
+ }
70
+ },
71
+ large: {
72
+ indent: {
73
+ marginInlineStart: `calc(${componentTheme.baseSpacingLarge} * 3)`,
74
+ marginInlineEnd: 0
75
+ },
76
+ folderTree: {
77
+ marginInlineStart: `calc(${componentTheme.baseSpacingLarge} * 2)`,
78
+ marginInlineEnd: 0,
79
+ paddingTop: `calc(0.875 * ${componentTheme.baseSpacingMedium})`,
80
+ marginTop: `calc(-0.875 * ${componentTheme.baseSpacingMedium})`
81
+ }
82
+ }
83
+ };
84
+ return {
85
+ treeCollection: {
86
+ label: 'treeCollection',
87
+ fontFamily: componentTheme.fontFamily,
88
+ margin: 0,
89
+ padding: 0,
90
+ '&:focus': {
91
+ outline: 0,
92
+ '> button, > div': {
93
+ ...calcFocusOutlineStyles(sharedTokens.focusOutline, {
94
+ withFocusOutline: true
95
+ })
96
+ }
97
+ }
98
+ },
99
+ list: {
100
+ label: 'treeCollection__list',
101
+ fontFamily: 'inherit',
102
+ boxSizing: 'border-box',
103
+ margin: 0,
104
+ padding: 0,
105
+ listStyleType: 'none',
106
+ position: 'relative',
107
+ ...(variant === 'folderTree' && {
108
+ '&::before': {
109
+ content: '""',
110
+ position: 'absolute',
111
+ top: '0.25rem',
112
+ bottom: '1.1875rem',
113
+ insetInlineStart: '0',
114
+ insetInlineEnd: 'auto',
115
+ ...(state.animation ? {
116
+ transform: 'scaleY(0.01)',
117
+ transformOrigin: 'center top',
118
+ animationName: list,
119
+ animationDuration: '0.2s',
120
+ animationFillMode: 'forwards',
121
+ animationTimingFunction: 'ease-out'
122
+ } : {}),
123
+ pointerEvents: 'none',
124
+ width: componentTheme.borderWidth,
125
+ background: componentTheme.borderColor // Tree vertical lines
126
+ }
127
+ }),
128
+ ...sizeMap[size][variant]
129
+ },
130
+ item: {
131
+ label: 'treeCollection__label',
132
+ '&:focus': {
133
+ outline: 0,
134
+ '> button, > div': {
135
+ ...calcFocusOutlineStyles(sharedTokens.focusOutline, {
136
+ withFocusOutline: true
137
+ })
138
+ }
139
+ }
140
+ }
141
+ };
142
+ };
143
+ export default generateStyles;
@@ -0,0 +1,156 @@
1
+ var _dec, _class, _TreeNode;
2
+ /*
3
+ * The MIT License (MIT)
4
+ *
5
+ * Copyright (c) 2021 - 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 { Img } from '@instructure/ui-img/latest';
28
+ import { withStyle } from '@instructure/emotion';
29
+ import { renderIconWithProps } from '@instructure/ui-icons';
30
+ import generateStyles from "../TreeButton/styles.js";
31
+ import { allowedProps } from "./props.js";
32
+ import TreeBrowserContext from "../TreeBrowserContext.js"; // Map TreeBrowser size tokens to icon size tokens
33
+ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
34
+ const treeBrowserSizeToIconSize = {
35
+ small: 'md',
36
+ medium: 'lg',
37
+ large: 'xl'
38
+ };
39
+
40
+ // Todo: merge TreeButton and TreeNode: TreeButton should be a special type of TreeNode
41
+
42
+ /**
43
+ ---
44
+ parent: TreeBrowser
45
+ id: TreeBrowser.Node
46
+ ---
47
+ A helper class used to render the :renderBeforeItems and :renderAfterItems
48
+ in the TreeBrowser.
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
+ }
78
+ 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,
82
+ hoverable: this.props.hoverable
83
+ });
84
+ }
85
+ 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,
89
+ hoverable: this.props.hoverable
90
+ });
91
+ }
92
+ getIconColor() {
93
+ const selected = this.props.selected;
94
+ const isHovered = this.state.isHovered;
95
+
96
+ // Priority: selected > hover > default
97
+ if (selected) return 'onColor';
98
+ if (isHovered) return 'inverseColor';
99
+ return 'baseColor';
100
+ }
101
+ 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;
107
+ if (thumbnail) {
108
+ return _jsx("div", {
109
+ css: styles === null || styles === void 0 ? void 0 : styles.thumbnail,
110
+ children: _jsx(Img, {
111
+ src: thumbnail,
112
+ constrain: "cover",
113
+ alt: ""
114
+ })
115
+ });
116
+ }
117
+ if (itemIcon) {
118
+ const iconSize = treeBrowserSizeToIconSize[size];
119
+ const iconColor = this.getIconColor();
120
+ const iconElement = renderIconWithProps(itemIcon, iconSize, iconColor);
121
+ return _jsx("div", {
122
+ css: styles === null || styles === void 0 ? void 0 : styles.icon,
123
+ children: iconElement
124
+ });
125
+ }
126
+ return void 0;
127
+ }
128
+ render() {
129
+ const _this$props4 = this.props,
130
+ children = _this$props4.children,
131
+ styles = _this$props4.styles;
132
+ return _jsx("div", {
133
+ ref: this.handleRef,
134
+ tabIndex: -1,
135
+ css: styles === null || styles === void 0 ? void 0 : styles.treeButton,
136
+ "data-cid": "TreeNode",
137
+ onMouseEnter: this.handleMouseEnter,
138
+ onMouseLeave: this.handleMouseLeave,
139
+ children: _jsxs("span", {
140
+ css: styles === null || styles === void 0 ? void 0 : styles.layout,
141
+ children: [this.renderItemImage(), _jsx("span", {
142
+ css: styles === null || styles === void 0 ? void 0 : styles.node,
143
+ children: children
144
+ })]
145
+ })
146
+ });
147
+ }
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);
155
+ export default TreeNode;
156
+ export { TreeNode };