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