@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,372 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = exports.TreeCollection = void 0;
8
+ var _react = require("react");
9
+ var _emotion = require("@instructure/emotion");
10
+ var _safeCloneElement = require("@instructure/ui-react-utils/lib/safeCloneElement.js");
11
+ var _TreeButton = require("../TreeButton");
12
+ var _styles = _interopRequireDefault(require("./styles"));
13
+ var _props = require("./props");
14
+ var _TreeBrowserContext = _interopRequireDefault(require("../TreeBrowserContext"));
15
+ var _jsxRuntime = require("@emotion/react/jsx-runtime");
16
+ var _react2 = require("@emotion/react");
17
+ var _dec, _class, _TreeCollection;
18
+ /*
19
+ * The MIT License (MIT)
20
+ *
21
+ * Copyright (c) 2015 - present Instructure, Inc.
22
+ *
23
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
24
+ * of this software and associated documentation files (the "Software"), to deal
25
+ * in the Software without restriction, including without limitation the rights
26
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27
+ * copies of the Software, and to permit persons to whom the Software is
28
+ * furnished to do so, subject to the following conditions:
29
+ *
30
+ * The above copyright notice and this permission notice shall be included in all
31
+ * copies or substantial portions of the Software.
32
+ *
33
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39
+ * SOFTWARE.
40
+ */
41
+ /**
42
+ ---
43
+ parent: TreeBrowser
44
+ id: TreeBrowser.Collection
45
+ ---
46
+ **/
47
+ let TreeCollection = exports.TreeCollection = (_dec = (0, _emotion.withStyle)(_styles.default, 'TreeBrowserTreeCollection'), _dec(_class = (_TreeCollection = class TreeCollection extends _react.Component {
48
+ constructor(props) {
49
+ super(props);
50
+ this.ref = null;
51
+ this.handleFocus = (e, item) => {
52
+ e.stopPropagation();
53
+ this.setState({
54
+ focused: `${item.type}_${item.id}`
55
+ });
56
+ };
57
+ this.handleBlur = (e, _item) => {
58
+ e.stopPropagation();
59
+ this.setState({
60
+ focused: ''
61
+ });
62
+ };
63
+ this.handleCollectionClick = e => {
64
+ const _this$props = this.props,
65
+ id = _this$props.id,
66
+ onCollectionClick = _this$props.onCollectionClick,
67
+ expanded = _this$props.expanded;
68
+ const collection = {
69
+ id,
70
+ expanded: !expanded,
71
+ type: 'collection'
72
+ };
73
+ if (onCollectionClick && typeof onCollectionClick === 'function') {
74
+ onCollectionClick(e, collection);
75
+ }
76
+ };
77
+ this.handleCollectionKeyDown = e => {
78
+ const _this$props2 = this.props,
79
+ id = _this$props2.id,
80
+ onKeyDown = _this$props2.onKeyDown,
81
+ expanded = _this$props2.expanded;
82
+ const collection = {
83
+ id,
84
+ expanded: !expanded,
85
+ type: 'collection'
86
+ };
87
+ if (onKeyDown && typeof onKeyDown === 'function') {
88
+ onKeyDown(e, collection);
89
+ }
90
+ };
91
+ this.state = {
92
+ focused: ''
93
+ };
94
+ }
95
+ componentDidMount() {
96
+ var _this$props$makeStyle, _this$props3, _this$context;
97
+ (_this$props$makeStyle = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props3, {
98
+ animation: (_this$context = this.context) === null || _this$context === void 0 ? void 0 : _this$context.animation
99
+ });
100
+ }
101
+ componentDidUpdate() {
102
+ var _this$props$makeStyle2, _this$props4, _this$context2;
103
+ (_this$props$makeStyle2 = (_this$props4 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props4, {
104
+ animation: (_this$context2 = this.context) === null || _this$context2 === void 0 ? void 0 : _this$context2.animation
105
+ });
106
+ }
107
+ get itemsLevel() {
108
+ const _this$props5 = this.props,
109
+ level = _this$props5.level,
110
+ isCollectionFlattened = _this$props5.isCollectionFlattened;
111
+ return isCollectionFlattened ? level : level + 1;
112
+ }
113
+ get collectionsCount() {
114
+ const collections = this.props.collections;
115
+ return collections && collections.length > 0 ? collections.length : 0;
116
+ }
117
+ get itemsCount() {
118
+ const items = this.props.items;
119
+ return items && items.length > 0 ? items.length : 0;
120
+ }
121
+ get childCount() {
122
+ return this.collectionsCount + this.itemsCount + (this.props.renderBeforeItems ? 1 : 0) + (this.props.renderAfterItems ? 1 : 0);
123
+ }
124
+ sortChildren() {
125
+ const _this$props6 = this.props,
126
+ collections = _this$props6.collections,
127
+ items = _this$props6.items,
128
+ compareFunc = _this$props6.compareFunc;
129
+ if (!compareFunc) return [];
130
+ const collections_ = collections ? collections.map(collection => {
131
+ return {
132
+ ...collection,
133
+ type: 'collection'
134
+ };
135
+ }) : [];
136
+ const items_ = items ? items.map(item => {
137
+ return {
138
+ ...item,
139
+ type: 'item'
140
+ };
141
+ }) : [];
142
+ const renderQueue = collections_.concat(items_);
143
+ renderQueue.sort(compareFunc);
144
+ return renderQueue;
145
+ }
146
+ renderChildren() {
147
+ const _this$props7 = this.props,
148
+ collections = _this$props7.collections,
149
+ items = _this$props7.items,
150
+ id = _this$props7.id,
151
+ renderBeforeItems = _this$props7.renderBeforeItems,
152
+ renderAfterItems = _this$props7.renderAfterItems,
153
+ compareFunc = _this$props7.compareFunc;
154
+ let position = 1;
155
+ const sortedChildren = this.sortChildren();
156
+ return (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
157
+ children: [renderBeforeItems && this.renderCollectionChildren(id, renderBeforeItems, position++, 'before'), !compareFunc && collections.map(collection => {
158
+ return this.renderCollectionNode(collection, position++);
159
+ }), !compareFunc && items.map(item => {
160
+ return this.renderItemNode(item, position++);
161
+ }), compareFunc && sortedChildren.map(child => {
162
+ if (child.type === 'collection') {
163
+ return this.renderCollectionNode(child, position++);
164
+ } else {
165
+ return this.renderItemNode(child, position++);
166
+ }
167
+ }), renderAfterItems && this.renderCollectionChildren(id, renderAfterItems, position++, 'after')]
168
+ });
169
+ }
170
+ renderCollectionChildren(collectionId, child, position, keyword) {
171
+ const _this$props8 = this.props,
172
+ selection = _this$props8.selection,
173
+ onKeyDown = _this$props8.onKeyDown,
174
+ getItemProps = _this$props8.getItemProps,
175
+ styles = _this$props8.styles;
176
+ const key = `${collectionId}_${keyword}`;
177
+ const ariaSelected = {};
178
+ if (selection) {
179
+ ariaSelected['aria-selected'] = selection === `child_${key}`;
180
+ }
181
+ const itemHash = {
182
+ id: key,
183
+ type: 'child'
184
+ };
185
+ const itemProps = getItemProps({
186
+ key: key,
187
+ selected: selection === `child_${key}`,
188
+ focused: this.state.focused === `child_${key}`,
189
+ level: this.itemsLevel,
190
+ size: this.props.size,
191
+ variant: this.props.variant
192
+ });
193
+ return (0, _jsxRuntime.jsx)("li", {
194
+ id: key
195
+ /* eslint-disable-next-line jsx-a11y/role-has-required-aria-props */,
196
+ role: "treeitem",
197
+ css: styles === null || styles === void 0 ? void 0 : styles.item,
198
+ tabIndex: -1,
199
+ "aria-posinset": position,
200
+ "aria-setsize": this.childCount,
201
+ "aria-level": this.itemsLevel,
202
+ ...ariaSelected,
203
+ onClick: e => {
204
+ if (typeof child.props.onClick === 'function') {
205
+ child.props.onClick(e);
206
+ } else {
207
+ e.stopPropagation();
208
+ }
209
+ },
210
+ onFocus: e => this.handleFocus(e, itemHash),
211
+ onKeyDown: e => {
212
+ if (typeof child.props.onKeyDown === 'function') {
213
+ child.props.onKeyDown(e);
214
+ } else {
215
+ onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e, itemHash);
216
+ }
217
+ },
218
+ onBlur: e => this.handleBlur(e, itemHash),
219
+ children: (0, _safeCloneElement.safeCloneElement)(child, itemProps)
220
+ }, key);
221
+ }
222
+ renderCollectionNode(collection, position) {
223
+ return (0, _react2.createElement)(TreeCollection, {
224
+ ...this.props,
225
+ key: `c${position}`,
226
+ id: collection.id,
227
+ name: collection.name,
228
+ descriptor: collection.descriptor,
229
+ expanded: collection.expanded,
230
+ items: collection.items,
231
+ collections: collection.collections,
232
+ numChildren: this.childCount,
233
+ level: this.itemsLevel,
234
+ containerRef: collection.containerRef,
235
+ position: position,
236
+ renderBeforeItems: collection.renderBeforeItems,
237
+ renderAfterItems: collection.renderAfterItems,
238
+ isCollectionFlattened: false // only the root needs to be flattened
239
+ ,
240
+ compareFunc: collection.compareFunc
241
+ });
242
+ }
243
+ renderItemNode(item, position) {
244
+ const _this$props9 = this.props,
245
+ selection = _this$props9.selection,
246
+ onItemClick = _this$props9.onItemClick,
247
+ onKeyDown = _this$props9.onKeyDown,
248
+ getItemProps = _this$props9.getItemProps,
249
+ styles = _this$props9.styles;
250
+ const ariaSelected = {};
251
+ if (selection) {
252
+ ariaSelected['aria-selected'] = selection === `item_${item.id}`;
253
+ }
254
+ const itemHash = {
255
+ id: item.id,
256
+ type: 'item'
257
+ };
258
+ const itemProps = getItemProps({
259
+ ...this.getCommonButtonProps(),
260
+ id: item.id,
261
+ name: item.name,
262
+ descriptor: item.descriptor,
263
+ thumbnail: item.thumbnail,
264
+ selected: selection === `item_${item.id}`,
265
+ focused: this.state.focused === `item_${item.id}`,
266
+ type: 'item'
267
+ });
268
+ return (0, _jsxRuntime.jsx)("li", {
269
+ tabIndex: -1
270
+ /* eslint-disable-next-line jsx-a11y/role-has-required-aria-props */,
271
+ role: "treeitem",
272
+ "aria-label": item.name,
273
+ css: styles === null || styles === void 0 ? void 0 : styles.item,
274
+ "aria-level": this.itemsLevel,
275
+ "aria-posinset": position,
276
+ "aria-setsize": this.childCount,
277
+ onClick: e => onItemClick === null || onItemClick === void 0 ? void 0 : onItemClick(e, itemHash),
278
+ onKeyDown: e => onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e, itemHash),
279
+ onFocus: e => this.handleFocus(e, itemHash),
280
+ onBlur: e => this.handleBlur(e, itemHash),
281
+ ...ariaSelected,
282
+ children: (0, _jsxRuntime.jsx)(_TreeButton.TreeButton, {
283
+ ...itemProps
284
+ })
285
+ }, `i${position}`);
286
+ }
287
+ getCommonButtonProps() {
288
+ return {
289
+ id: this.props.id,
290
+ name: this.props.name,
291
+ descriptor: this.props.descriptor,
292
+ size: this.props.size,
293
+ variant: this.props.variant,
294
+ itemIcon: this.props.itemIcon,
295
+ level: this.itemsLevel,
296
+ renderContent: this.props.renderContent
297
+ };
298
+ }
299
+ render() {
300
+ const _this$props0 = this.props,
301
+ id = _this$props0.id,
302
+ name = _this$props0.name,
303
+ expanded = _this$props0.expanded,
304
+ collectionIcon = _this$props0.collectionIcon,
305
+ collectionIconExpanded = _this$props0.collectionIconExpanded,
306
+ isCollectionFlattened = _this$props0.isCollectionFlattened,
307
+ getCollectionProps = _this$props0.getCollectionProps,
308
+ level = _this$props0.level,
309
+ position = _this$props0.position,
310
+ styles = _this$props0.styles;
311
+ const collectionProps = getCollectionProps({
312
+ ...this.getCommonButtonProps(),
313
+ expanded: expanded,
314
+ collectionIcon: collectionIcon,
315
+ collectionIconExpanded: collectionIconExpanded,
316
+ type: 'collection',
317
+ containerRef: this.props.containerRef,
318
+ selected: this.props.selection === `collection_${id}`,
319
+ focused: this.state.focused === `collection_${id}`,
320
+ level
321
+ });
322
+ const ariaSelected = {
323
+ 'aria-selected': void 0
324
+ };
325
+ if (this.props.selection) ariaSelected['aria-selected'] = this.props.selection === `collection_${id}`;
326
+ return isCollectionFlattened ? this.renderChildren() : (0, _jsxRuntime.jsxs)("li", {
327
+ ref: el => {
328
+ this.ref = el;
329
+ },
330
+ css: styles === null || styles === void 0 ? void 0 : styles.treeCollection,
331
+ tabIndex: -1
332
+ /* eslint-disable-next-line jsx-a11y/role-has-required-aria-props */,
333
+ role: "treeitem",
334
+ "aria-label": `${this.props.name}${this.props.descriptor ? ` ${this.props.descriptor}` : ''}`,
335
+ "aria-level": level,
336
+ "aria-posinset": position,
337
+ "aria-setsize": this.props.numChildren,
338
+ "aria-expanded": expanded,
339
+ onClick: this.handleCollectionClick,
340
+ onKeyDown: this.handleCollectionKeyDown,
341
+ onFocus: e => this.handleFocus(e, {
342
+ id: id,
343
+ type: 'collection'
344
+ }),
345
+ onBlur: e => this.handleBlur(e, {
346
+ id: id,
347
+ type: 'collection'
348
+ }),
349
+ ...ariaSelected,
350
+ "data-cid": "TreeCollection",
351
+ children: [(0, _jsxRuntime.jsx)(_TreeButton.TreeButton, {
352
+ ...collectionProps
353
+ }), expanded && this.childCount > 0 && (0, _jsxRuntime.jsx)("ul", {
354
+ "aria-label": name,
355
+ css: styles === null || styles === void 0 ? void 0 : styles.list,
356
+ role: "group",
357
+ children: this.renderChildren()
358
+ })]
359
+ });
360
+ }
361
+ }, _TreeCollection.displayName = "TreeCollection", _TreeCollection.componentId = 'TreeBrowser.Collection', _TreeCollection.allowedProps = _props.allowedProps, _TreeCollection.contextType = _TreeBrowserContext.default, _TreeCollection.defaultProps = {
362
+ collections: [],
363
+ items: [],
364
+ expanded: false,
365
+ selection: '',
366
+ size: 'medium',
367
+ variant: 'folderTree',
368
+ getItemProps: props => props,
369
+ getCollectionProps: props => props,
370
+ isCollectionFlattened: false
371
+ }, _TreeCollection)) || _class);
372
+ var _default = exports.default = TreeCollection;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.allowedProps = void 0;
7
+ /*
8
+ * The MIT License (MIT)
9
+ *
10
+ * Copyright (c) 2015 - present Instructure, Inc.
11
+ *
12
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ * of this software and associated documentation files (the "Software"), to deal
14
+ * in the Software without restriction, including without limitation the rights
15
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ * copies of the Software, and to permit persons to whom the Software is
17
+ * furnished to do so, subject to the following conditions:
18
+ *
19
+ * The above copyright notice and this permission notice shall be included in all
20
+ * copies or substantial portions of the Software.
21
+ *
22
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ * SOFTWARE.
29
+ */
30
+
31
+ const allowedProps = exports.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'];
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _emotion = require("@instructure/emotion");
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
+ const list = (0, _emotion.keyframes)`
33
+ to {
34
+ transform: scaleY(1);
35
+ }`;
36
+
37
+ /**
38
+ * ---
39
+ * private: true
40
+ * ---
41
+ * Generates the style object from the theme and provided additional information
42
+ * @param {Object} componentTheme The theme variable object.
43
+ * @param {Object} props the props of the component, the style is applied to
44
+ * @param {Object} sharedTokens Shared token object that stores common values for the theme.
45
+ * @param {Object} state the state of the component, the style is applied to
46
+ * @return {Object} The final style object, which will be used in the component
47
+ */
48
+
49
+ const generateStyles = (componentTheme, props, sharedTokens, state) => {
50
+ const size = props.size,
51
+ variant = props.variant;
52
+ const sizeMap = {
53
+ small: {
54
+ indent: {
55
+ marginInlineStart: `calc(${componentTheme.baseSpacingSmall} * 3)`,
56
+ marginInlineEnd: 0
57
+ },
58
+ folderTree: {
59
+ marginInlineStart: `calc(${componentTheme.baseSpacingSmall} * 2)`,
60
+ marginInlineEnd: 0,
61
+ paddingTop: `calc(1.75 * ${componentTheme.baseSpacingSmall})`,
62
+ marginTop: `calc(-1.75 * ${componentTheme.baseSpacingSmall})`
63
+ }
64
+ },
65
+ medium: {
66
+ indent: {
67
+ marginInlineStart: `calc(${componentTheme.baseSpacingMedium} * 3)`,
68
+ marginInlineEnd: 0
69
+ },
70
+ folderTree: {
71
+ marginInlineStart: `calc(${componentTheme.baseSpacingMedium} * 2)`,
72
+ marginInlineEnd: 0,
73
+ paddingTop: componentTheme.baseSpacingMedium,
74
+ marginTop: `calc(-1 * ${componentTheme.baseSpacingMedium})`
75
+ }
76
+ },
77
+ large: {
78
+ indent: {
79
+ marginInlineStart: `calc(${componentTheme.baseSpacingLarge} * 3)`,
80
+ marginInlineEnd: 0
81
+ },
82
+ folderTree: {
83
+ marginInlineStart: `calc(${componentTheme.baseSpacingLarge} * 2)`,
84
+ marginInlineEnd: 0,
85
+ paddingTop: `calc(0.875 * ${componentTheme.baseSpacingMedium})`,
86
+ marginTop: `calc(-0.875 * ${componentTheme.baseSpacingMedium})`
87
+ }
88
+ }
89
+ };
90
+ return {
91
+ treeCollection: {
92
+ label: 'treeCollection',
93
+ fontFamily: componentTheme.fontFamily,
94
+ margin: 0,
95
+ padding: 0,
96
+ '&:focus': {
97
+ outline: 0,
98
+ '> button, > div': {
99
+ ...(0, _emotion.calcFocusOutlineStyles)(sharedTokens.focusOutline, {
100
+ withFocusOutline: true
101
+ })
102
+ }
103
+ }
104
+ },
105
+ list: {
106
+ label: 'treeCollection__list',
107
+ fontFamily: 'inherit',
108
+ boxSizing: 'border-box',
109
+ margin: 0,
110
+ padding: 0,
111
+ listStyleType: 'none',
112
+ position: 'relative',
113
+ ...(variant === 'folderTree' && {
114
+ '&::before': {
115
+ content: '""',
116
+ position: 'absolute',
117
+ top: '0.25rem',
118
+ bottom: '1.1875rem',
119
+ insetInlineStart: '0',
120
+ insetInlineEnd: 'auto',
121
+ ...(state.animation ? {
122
+ transform: 'scaleY(0.01)',
123
+ transformOrigin: 'center top',
124
+ animationName: list,
125
+ animationDuration: '0.2s',
126
+ animationFillMode: 'forwards',
127
+ animationTimingFunction: 'ease-out'
128
+ } : {}),
129
+ pointerEvents: 'none',
130
+ width: componentTheme.borderWidth,
131
+ background: componentTheme.borderColor // Tree vertical lines
132
+ }
133
+ }),
134
+ ...sizeMap[size][variant]
135
+ },
136
+ item: {
137
+ label: 'treeCollection__label',
138
+ '&:focus': {
139
+ outline: 0,
140
+ '> button, > div': {
141
+ ...(0, _emotion.calcFocusOutlineStyles)(sharedTokens.focusOutline, {
142
+ withFocusOutline: true
143
+ })
144
+ }
145
+ }
146
+ }
147
+ };
148
+ };
149
+ var _default = exports.default = generateStyles;