@instructure/ui-tree-browser 11.7.3 → 11.7.4-pr-snapshot-1781695314229

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