@react-stately/collections 3.12.9 → 3.13.0
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/dist/import.mjs +7 -7
- package/dist/main.js +16 -16
- package/dist/main.js.map +1 -1
- package/dist/module.js +7 -7
- package/dist/module.js.map +1 -1
- package/dist/types/src/index.d.ts +7 -0
- package/package.json +17 -13
- package/src/index.ts +8 -7
- package/dist/CollectionBuilder.main.js +0 -223
- package/dist/CollectionBuilder.main.js.map +0 -1
- package/dist/CollectionBuilder.mjs +0 -214
- package/dist/CollectionBuilder.module.js +0 -214
- package/dist/CollectionBuilder.module.js.map +0 -1
- package/dist/Item.main.js +0 -68
- package/dist/Item.main.js.map +0 -1
- package/dist/Item.mjs +0 -59
- package/dist/Item.module.js +0 -59
- package/dist/Item.module.js.map +0 -1
- package/dist/Section.main.js +0 -60
- package/dist/Section.main.js.map +0 -1
- package/dist/Section.mjs +0 -51
- package/dist/Section.module.js +0 -51
- package/dist/Section.module.js.map +0 -1
- package/dist/getChildNodes.main.js +0 -81
- package/dist/getChildNodes.main.js.map +0 -1
- package/dist/getChildNodes.mjs +0 -72
- package/dist/getChildNodes.module.js +0 -72
- package/dist/getChildNodes.module.js.map +0 -1
- package/dist/getItemCount.main.js +0 -38
- package/dist/getItemCount.main.js.map +0 -1
- package/dist/getItemCount.mjs +0 -33
- package/dist/getItemCount.module.js +0 -33
- package/dist/getItemCount.module.js.map +0 -1
- package/dist/types.d.ts +0 -36
- package/dist/types.d.ts.map +0 -1
- package/dist/useCollection.main.js +0 -44
- package/dist/useCollection.main.js.map +0 -1
- package/dist/useCollection.mjs +0 -39
- package/dist/useCollection.module.js +0 -39
- package/dist/useCollection.module.js.map +0 -1
- package/src/CollectionBuilder.ts +0 -283
- package/src/Item.ts +0 -80
- package/src/Section.ts +0 -59
- package/src/getChildNodes.ts +0 -95
- package/src/getItemCount.ts +0 -39
- package/src/types.ts +0 -31
- package/src/useCollection.ts +0 -34
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
import $fzaAv$react from "react";
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
5
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
7
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
*
|
|
9
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
10
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
11
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
|
-
* governing permissions and limitations under the License.
|
|
13
|
-
*/
|
|
14
|
-
class $eb2240fc39a57fa5$export$bf788dd355e3a401 {
|
|
15
|
-
build(props, context) {
|
|
16
|
-
this.context = context;
|
|
17
|
-
return $eb2240fc39a57fa5$var$iterable(()=>this.iterateCollection(props));
|
|
18
|
-
}
|
|
19
|
-
*iterateCollection(props) {
|
|
20
|
-
let { children: children, items: items } = props;
|
|
21
|
-
if ((0, $fzaAv$react).isValidElement(children) && children.type === (0, $fzaAv$react).Fragment) yield* this.iterateCollection({
|
|
22
|
-
children: children.props.children,
|
|
23
|
-
items: items
|
|
24
|
-
});
|
|
25
|
-
else if (typeof children === 'function') {
|
|
26
|
-
if (!items) throw new Error('props.children was a function but props.items is missing');
|
|
27
|
-
let index = 0;
|
|
28
|
-
for (let item of items){
|
|
29
|
-
yield* this.getFullNode({
|
|
30
|
-
value: item,
|
|
31
|
-
index: index
|
|
32
|
-
}, {
|
|
33
|
-
renderer: children
|
|
34
|
-
});
|
|
35
|
-
index++;
|
|
36
|
-
}
|
|
37
|
-
} else {
|
|
38
|
-
let items = [];
|
|
39
|
-
(0, $fzaAv$react).Children.forEach(children, (child)=>{
|
|
40
|
-
if (child) items.push(child);
|
|
41
|
-
});
|
|
42
|
-
let index = 0;
|
|
43
|
-
for (let item of items){
|
|
44
|
-
let nodes = this.getFullNode({
|
|
45
|
-
element: item,
|
|
46
|
-
index: index
|
|
47
|
-
}, {});
|
|
48
|
-
for (let node of nodes){
|
|
49
|
-
index++;
|
|
50
|
-
yield node;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
getKey(item, partialNode, state, parentKey) {
|
|
56
|
-
if (item.key != null) return item.key;
|
|
57
|
-
if (partialNode.type === 'cell' && partialNode.key != null) return `${parentKey}${partialNode.key}`;
|
|
58
|
-
let v = partialNode.value;
|
|
59
|
-
if (v != null) {
|
|
60
|
-
var _v_key;
|
|
61
|
-
let key = (_v_key = v.key) !== null && _v_key !== void 0 ? _v_key : v.id;
|
|
62
|
-
if (key == null) throw new Error('No key found for item');
|
|
63
|
-
return key;
|
|
64
|
-
}
|
|
65
|
-
return parentKey ? `${parentKey}.${partialNode.index}` : `$.${partialNode.index}`;
|
|
66
|
-
}
|
|
67
|
-
getChildState(state, partialNode) {
|
|
68
|
-
return {
|
|
69
|
-
renderer: partialNode.renderer || state.renderer
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
*getFullNode(partialNode, state, parentKey, parentNode) {
|
|
73
|
-
if ((0, $fzaAv$react).isValidElement(partialNode.element) && partialNode.element.type === (0, $fzaAv$react).Fragment) {
|
|
74
|
-
let children = [];
|
|
75
|
-
(0, $fzaAv$react).Children.forEach(partialNode.element.props.children, (child)=>{
|
|
76
|
-
children.push(child);
|
|
77
|
-
});
|
|
78
|
-
var _partialNode_index;
|
|
79
|
-
let index = (_partialNode_index = partialNode.index) !== null && _partialNode_index !== void 0 ? _partialNode_index : 0;
|
|
80
|
-
for (const child of children)yield* this.getFullNode({
|
|
81
|
-
element: child,
|
|
82
|
-
index: index++
|
|
83
|
-
}, state, parentKey, parentNode);
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
// If there's a value instead of an element on the node, and a parent renderer function is available,
|
|
87
|
-
// use it to render an element for the value.
|
|
88
|
-
let element = partialNode.element;
|
|
89
|
-
if (!element && partialNode.value && state && state.renderer) {
|
|
90
|
-
let cached = this.cache.get(partialNode.value);
|
|
91
|
-
if (cached && (!cached.shouldInvalidate || !cached.shouldInvalidate(this.context))) {
|
|
92
|
-
cached.index = partialNode.index;
|
|
93
|
-
cached.parentKey = parentNode ? parentNode.key : null;
|
|
94
|
-
yield cached;
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
element = state.renderer(partialNode.value);
|
|
98
|
-
}
|
|
99
|
-
// If there's an element with a getCollectionNode function on its type, then it's a supported component.
|
|
100
|
-
// Call this function to get a partial node, and recursively build a full node from there.
|
|
101
|
-
if ((0, $fzaAv$react).isValidElement(element)) {
|
|
102
|
-
let type = element.type;
|
|
103
|
-
if (typeof type !== 'function' && typeof type.getCollectionNode !== 'function') {
|
|
104
|
-
let name = element.type;
|
|
105
|
-
throw new Error(`Unknown element <${name}> in collection.`);
|
|
106
|
-
}
|
|
107
|
-
let childNodes = type.getCollectionNode(element.props, this.context);
|
|
108
|
-
var _partialNode_index1;
|
|
109
|
-
let index = (_partialNode_index1 = partialNode.index) !== null && _partialNode_index1 !== void 0 ? _partialNode_index1 : 0;
|
|
110
|
-
let result = childNodes.next();
|
|
111
|
-
while(!result.done && result.value){
|
|
112
|
-
let childNode = result.value;
|
|
113
|
-
partialNode.index = index;
|
|
114
|
-
var _childNode_key;
|
|
115
|
-
let nodeKey = (_childNode_key = childNode.key) !== null && _childNode_key !== void 0 ? _childNode_key : null;
|
|
116
|
-
if (nodeKey == null) nodeKey = childNode.element ? null : this.getKey(element, partialNode, state, parentKey);
|
|
117
|
-
let nodes = this.getFullNode({
|
|
118
|
-
...childNode,
|
|
119
|
-
key: nodeKey,
|
|
120
|
-
index: index,
|
|
121
|
-
wrapper: $eb2240fc39a57fa5$var$compose(partialNode.wrapper, childNode.wrapper)
|
|
122
|
-
}, this.getChildState(state, childNode), parentKey ? `${parentKey}${element.key}` : element.key, parentNode);
|
|
123
|
-
let children = [
|
|
124
|
-
...nodes
|
|
125
|
-
];
|
|
126
|
-
for (let node of children){
|
|
127
|
-
var _childNode_value, _ref;
|
|
128
|
-
// Cache the node based on its value
|
|
129
|
-
node.value = (_ref = (_childNode_value = childNode.value) !== null && _childNode_value !== void 0 ? _childNode_value : partialNode.value) !== null && _ref !== void 0 ? _ref : null;
|
|
130
|
-
if (node.value) this.cache.set(node.value, node);
|
|
131
|
-
var _parentNode_type;
|
|
132
|
-
// The partial node may have specified a type for the child in order to specify a constraint.
|
|
133
|
-
// Verify that the full node that was built recursively matches this type.
|
|
134
|
-
if (partialNode.type && node.type !== partialNode.type) throw new Error(`Unsupported type <${$eb2240fc39a57fa5$var$capitalize(node.type)}> in <${$eb2240fc39a57fa5$var$capitalize((_parentNode_type = parentNode === null || parentNode === void 0 ? void 0 : parentNode.type) !== null && _parentNode_type !== void 0 ? _parentNode_type : 'unknown parent type')}>. Only <${$eb2240fc39a57fa5$var$capitalize(partialNode.type)}> is supported.`);
|
|
135
|
-
index++;
|
|
136
|
-
yield node;
|
|
137
|
-
}
|
|
138
|
-
result = childNodes.next(children);
|
|
139
|
-
}
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
// Ignore invalid elements
|
|
143
|
-
if (partialNode.key == null || partialNode.type == null) return;
|
|
144
|
-
// Create full node
|
|
145
|
-
let builder = this;
|
|
146
|
-
var _partialNode_value, _partialNode_textValue;
|
|
147
|
-
let node = {
|
|
148
|
-
type: partialNode.type,
|
|
149
|
-
props: partialNode.props,
|
|
150
|
-
key: partialNode.key,
|
|
151
|
-
parentKey: parentNode ? parentNode.key : null,
|
|
152
|
-
value: (_partialNode_value = partialNode.value) !== null && _partialNode_value !== void 0 ? _partialNode_value : null,
|
|
153
|
-
level: parentNode ? parentNode.level + 1 : 0,
|
|
154
|
-
index: partialNode.index,
|
|
155
|
-
rendered: partialNode.rendered,
|
|
156
|
-
textValue: (_partialNode_textValue = partialNode.textValue) !== null && _partialNode_textValue !== void 0 ? _partialNode_textValue : '',
|
|
157
|
-
'aria-label': partialNode['aria-label'],
|
|
158
|
-
wrapper: partialNode.wrapper,
|
|
159
|
-
shouldInvalidate: partialNode.shouldInvalidate,
|
|
160
|
-
hasChildNodes: partialNode.hasChildNodes || false,
|
|
161
|
-
childNodes: $eb2240fc39a57fa5$var$iterable(function*() {
|
|
162
|
-
if (!partialNode.hasChildNodes || !partialNode.childNodes) return;
|
|
163
|
-
let index = 0;
|
|
164
|
-
for (let child of partialNode.childNodes()){
|
|
165
|
-
// Ensure child keys are globally unique by prepending the parent node's key
|
|
166
|
-
if (child.key != null) // TODO: Remove this line entirely and enforce that users always provide unique keys.
|
|
167
|
-
// Currently this line will have issues when a parent has a key `a` and a child with key `bc`
|
|
168
|
-
// but another parent has key `ab` and its child has a key `c`. The combined keys would result in both
|
|
169
|
-
// children having a key of `abc`.
|
|
170
|
-
child.key = `${node.key}${child.key}`;
|
|
171
|
-
let nodes = builder.getFullNode({
|
|
172
|
-
...child,
|
|
173
|
-
index: index
|
|
174
|
-
}, builder.getChildState(state, child), node.key, node);
|
|
175
|
-
for (let node of nodes){
|
|
176
|
-
index++;
|
|
177
|
-
yield node;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
})
|
|
181
|
-
};
|
|
182
|
-
yield node;
|
|
183
|
-
}
|
|
184
|
-
constructor(){
|
|
185
|
-
this.cache = new WeakMap();
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
// Wraps an iterator function as an iterable object, and caches the results.
|
|
189
|
-
function $eb2240fc39a57fa5$var$iterable(iterator) {
|
|
190
|
-
let cache = [];
|
|
191
|
-
let iterable = null;
|
|
192
|
-
return {
|
|
193
|
-
*[Symbol.iterator] () {
|
|
194
|
-
for (let item of cache)yield item;
|
|
195
|
-
if (!iterable) iterable = iterator();
|
|
196
|
-
for (let item of iterable){
|
|
197
|
-
cache.push(item);
|
|
198
|
-
yield item;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
function $eb2240fc39a57fa5$var$compose(outer, inner) {
|
|
204
|
-
if (outer && inner) return (element)=>outer(inner(element));
|
|
205
|
-
if (outer) return outer;
|
|
206
|
-
if (inner) return inner;
|
|
207
|
-
}
|
|
208
|
-
function $eb2240fc39a57fa5$var$capitalize(str) {
|
|
209
|
-
return str[0].toUpperCase() + str.slice(1);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
export {$eb2240fc39a57fa5$export$bf788dd355e3a401 as CollectionBuilder};
|
|
214
|
-
//# sourceMappingURL=CollectionBuilder.module.js.map
|
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
import $fzaAv$react from "react";
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
5
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
7
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
*
|
|
9
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
10
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
11
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
|
-
* governing permissions and limitations under the License.
|
|
13
|
-
*/
|
|
14
|
-
class $eb2240fc39a57fa5$export$bf788dd355e3a401 {
|
|
15
|
-
build(props, context) {
|
|
16
|
-
this.context = context;
|
|
17
|
-
return $eb2240fc39a57fa5$var$iterable(()=>this.iterateCollection(props));
|
|
18
|
-
}
|
|
19
|
-
*iterateCollection(props) {
|
|
20
|
-
let { children: children, items: items } = props;
|
|
21
|
-
if ((0, $fzaAv$react).isValidElement(children) && children.type === (0, $fzaAv$react).Fragment) yield* this.iterateCollection({
|
|
22
|
-
children: children.props.children,
|
|
23
|
-
items: items
|
|
24
|
-
});
|
|
25
|
-
else if (typeof children === 'function') {
|
|
26
|
-
if (!items) throw new Error('props.children was a function but props.items is missing');
|
|
27
|
-
let index = 0;
|
|
28
|
-
for (let item of items){
|
|
29
|
-
yield* this.getFullNode({
|
|
30
|
-
value: item,
|
|
31
|
-
index: index
|
|
32
|
-
}, {
|
|
33
|
-
renderer: children
|
|
34
|
-
});
|
|
35
|
-
index++;
|
|
36
|
-
}
|
|
37
|
-
} else {
|
|
38
|
-
let items = [];
|
|
39
|
-
(0, $fzaAv$react).Children.forEach(children, (child)=>{
|
|
40
|
-
if (child) items.push(child);
|
|
41
|
-
});
|
|
42
|
-
let index = 0;
|
|
43
|
-
for (let item of items){
|
|
44
|
-
let nodes = this.getFullNode({
|
|
45
|
-
element: item,
|
|
46
|
-
index: index
|
|
47
|
-
}, {});
|
|
48
|
-
for (let node of nodes){
|
|
49
|
-
index++;
|
|
50
|
-
yield node;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
getKey(item, partialNode, state, parentKey) {
|
|
56
|
-
if (item.key != null) return item.key;
|
|
57
|
-
if (partialNode.type === 'cell' && partialNode.key != null) return `${parentKey}${partialNode.key}`;
|
|
58
|
-
let v = partialNode.value;
|
|
59
|
-
if (v != null) {
|
|
60
|
-
var _v_key;
|
|
61
|
-
let key = (_v_key = v.key) !== null && _v_key !== void 0 ? _v_key : v.id;
|
|
62
|
-
if (key == null) throw new Error('No key found for item');
|
|
63
|
-
return key;
|
|
64
|
-
}
|
|
65
|
-
return parentKey ? `${parentKey}.${partialNode.index}` : `$.${partialNode.index}`;
|
|
66
|
-
}
|
|
67
|
-
getChildState(state, partialNode) {
|
|
68
|
-
return {
|
|
69
|
-
renderer: partialNode.renderer || state.renderer
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
*getFullNode(partialNode, state, parentKey, parentNode) {
|
|
73
|
-
if ((0, $fzaAv$react).isValidElement(partialNode.element) && partialNode.element.type === (0, $fzaAv$react).Fragment) {
|
|
74
|
-
let children = [];
|
|
75
|
-
(0, $fzaAv$react).Children.forEach(partialNode.element.props.children, (child)=>{
|
|
76
|
-
children.push(child);
|
|
77
|
-
});
|
|
78
|
-
var _partialNode_index;
|
|
79
|
-
let index = (_partialNode_index = partialNode.index) !== null && _partialNode_index !== void 0 ? _partialNode_index : 0;
|
|
80
|
-
for (const child of children)yield* this.getFullNode({
|
|
81
|
-
element: child,
|
|
82
|
-
index: index++
|
|
83
|
-
}, state, parentKey, parentNode);
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
// If there's a value instead of an element on the node, and a parent renderer function is available,
|
|
87
|
-
// use it to render an element for the value.
|
|
88
|
-
let element = partialNode.element;
|
|
89
|
-
if (!element && partialNode.value && state && state.renderer) {
|
|
90
|
-
let cached = this.cache.get(partialNode.value);
|
|
91
|
-
if (cached && (!cached.shouldInvalidate || !cached.shouldInvalidate(this.context))) {
|
|
92
|
-
cached.index = partialNode.index;
|
|
93
|
-
cached.parentKey = parentNode ? parentNode.key : null;
|
|
94
|
-
yield cached;
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
element = state.renderer(partialNode.value);
|
|
98
|
-
}
|
|
99
|
-
// If there's an element with a getCollectionNode function on its type, then it's a supported component.
|
|
100
|
-
// Call this function to get a partial node, and recursively build a full node from there.
|
|
101
|
-
if ((0, $fzaAv$react).isValidElement(element)) {
|
|
102
|
-
let type = element.type;
|
|
103
|
-
if (typeof type !== 'function' && typeof type.getCollectionNode !== 'function') {
|
|
104
|
-
let name = element.type;
|
|
105
|
-
throw new Error(`Unknown element <${name}> in collection.`);
|
|
106
|
-
}
|
|
107
|
-
let childNodes = type.getCollectionNode(element.props, this.context);
|
|
108
|
-
var _partialNode_index1;
|
|
109
|
-
let index = (_partialNode_index1 = partialNode.index) !== null && _partialNode_index1 !== void 0 ? _partialNode_index1 : 0;
|
|
110
|
-
let result = childNodes.next();
|
|
111
|
-
while(!result.done && result.value){
|
|
112
|
-
let childNode = result.value;
|
|
113
|
-
partialNode.index = index;
|
|
114
|
-
var _childNode_key;
|
|
115
|
-
let nodeKey = (_childNode_key = childNode.key) !== null && _childNode_key !== void 0 ? _childNode_key : null;
|
|
116
|
-
if (nodeKey == null) nodeKey = childNode.element ? null : this.getKey(element, partialNode, state, parentKey);
|
|
117
|
-
let nodes = this.getFullNode({
|
|
118
|
-
...childNode,
|
|
119
|
-
key: nodeKey,
|
|
120
|
-
index: index,
|
|
121
|
-
wrapper: $eb2240fc39a57fa5$var$compose(partialNode.wrapper, childNode.wrapper)
|
|
122
|
-
}, this.getChildState(state, childNode), parentKey ? `${parentKey}${element.key}` : element.key, parentNode);
|
|
123
|
-
let children = [
|
|
124
|
-
...nodes
|
|
125
|
-
];
|
|
126
|
-
for (let node of children){
|
|
127
|
-
var _childNode_value, _ref;
|
|
128
|
-
// Cache the node based on its value
|
|
129
|
-
node.value = (_ref = (_childNode_value = childNode.value) !== null && _childNode_value !== void 0 ? _childNode_value : partialNode.value) !== null && _ref !== void 0 ? _ref : null;
|
|
130
|
-
if (node.value) this.cache.set(node.value, node);
|
|
131
|
-
var _parentNode_type;
|
|
132
|
-
// The partial node may have specified a type for the child in order to specify a constraint.
|
|
133
|
-
// Verify that the full node that was built recursively matches this type.
|
|
134
|
-
if (partialNode.type && node.type !== partialNode.type) throw new Error(`Unsupported type <${$eb2240fc39a57fa5$var$capitalize(node.type)}> in <${$eb2240fc39a57fa5$var$capitalize((_parentNode_type = parentNode === null || parentNode === void 0 ? void 0 : parentNode.type) !== null && _parentNode_type !== void 0 ? _parentNode_type : 'unknown parent type')}>. Only <${$eb2240fc39a57fa5$var$capitalize(partialNode.type)}> is supported.`);
|
|
135
|
-
index++;
|
|
136
|
-
yield node;
|
|
137
|
-
}
|
|
138
|
-
result = childNodes.next(children);
|
|
139
|
-
}
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
// Ignore invalid elements
|
|
143
|
-
if (partialNode.key == null || partialNode.type == null) return;
|
|
144
|
-
// Create full node
|
|
145
|
-
let builder = this;
|
|
146
|
-
var _partialNode_value, _partialNode_textValue;
|
|
147
|
-
let node = {
|
|
148
|
-
type: partialNode.type,
|
|
149
|
-
props: partialNode.props,
|
|
150
|
-
key: partialNode.key,
|
|
151
|
-
parentKey: parentNode ? parentNode.key : null,
|
|
152
|
-
value: (_partialNode_value = partialNode.value) !== null && _partialNode_value !== void 0 ? _partialNode_value : null,
|
|
153
|
-
level: parentNode ? parentNode.level + 1 : 0,
|
|
154
|
-
index: partialNode.index,
|
|
155
|
-
rendered: partialNode.rendered,
|
|
156
|
-
textValue: (_partialNode_textValue = partialNode.textValue) !== null && _partialNode_textValue !== void 0 ? _partialNode_textValue : '',
|
|
157
|
-
'aria-label': partialNode['aria-label'],
|
|
158
|
-
wrapper: partialNode.wrapper,
|
|
159
|
-
shouldInvalidate: partialNode.shouldInvalidate,
|
|
160
|
-
hasChildNodes: partialNode.hasChildNodes || false,
|
|
161
|
-
childNodes: $eb2240fc39a57fa5$var$iterable(function*() {
|
|
162
|
-
if (!partialNode.hasChildNodes || !partialNode.childNodes) return;
|
|
163
|
-
let index = 0;
|
|
164
|
-
for (let child of partialNode.childNodes()){
|
|
165
|
-
// Ensure child keys are globally unique by prepending the parent node's key
|
|
166
|
-
if (child.key != null) // TODO: Remove this line entirely and enforce that users always provide unique keys.
|
|
167
|
-
// Currently this line will have issues when a parent has a key `a` and a child with key `bc`
|
|
168
|
-
// but another parent has key `ab` and its child has a key `c`. The combined keys would result in both
|
|
169
|
-
// children having a key of `abc`.
|
|
170
|
-
child.key = `${node.key}${child.key}`;
|
|
171
|
-
let nodes = builder.getFullNode({
|
|
172
|
-
...child,
|
|
173
|
-
index: index
|
|
174
|
-
}, builder.getChildState(state, child), node.key, node);
|
|
175
|
-
for (let node of nodes){
|
|
176
|
-
index++;
|
|
177
|
-
yield node;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
})
|
|
181
|
-
};
|
|
182
|
-
yield node;
|
|
183
|
-
}
|
|
184
|
-
constructor(){
|
|
185
|
-
this.cache = new WeakMap();
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
// Wraps an iterator function as an iterable object, and caches the results.
|
|
189
|
-
function $eb2240fc39a57fa5$var$iterable(iterator) {
|
|
190
|
-
let cache = [];
|
|
191
|
-
let iterable = null;
|
|
192
|
-
return {
|
|
193
|
-
*[Symbol.iterator] () {
|
|
194
|
-
for (let item of cache)yield item;
|
|
195
|
-
if (!iterable) iterable = iterator();
|
|
196
|
-
for (let item of iterable){
|
|
197
|
-
cache.push(item);
|
|
198
|
-
yield item;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
function $eb2240fc39a57fa5$var$compose(outer, inner) {
|
|
204
|
-
if (outer && inner) return (element)=>outer(inner(element));
|
|
205
|
-
if (outer) return outer;
|
|
206
|
-
if (inner) return inner;
|
|
207
|
-
}
|
|
208
|
-
function $eb2240fc39a57fa5$var$capitalize(str) {
|
|
209
|
-
return str[0].toUpperCase() + str.slice(1);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
export {$eb2240fc39a57fa5$export$bf788dd355e3a401 as CollectionBuilder};
|
|
214
|
-
//# sourceMappingURL=CollectionBuilder.module.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;AAAA;;;;;;;;;;CAUC;AAcM,MAAM;IAIX,MAAM,KAAiC,EAAE,OAAiB,EAAqB;QAC7E,IAAI,CAAC,OAAO,GAAG;QACf,OAAO,+BAAS,IAAM,IAAI,CAAC,iBAAiB,CAAC;IAC/C;IAEA,CAAS,kBAAkB,KAAiC,EAAsB;QAChF,IAAI,YAAC,QAAQ,SAAE,KAAK,EAAC,GAAG;QAExB,IAAI,CAAA,GAAA,YAAI,EAAE,cAAc,CAAmC,aAAa,SAAS,IAAI,KAAK,CAAA,GAAA,YAAI,EAAE,QAAQ,EACtG,OAAO,IAAI,CAAC,iBAAiB,C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AAC;wBAAC,GAAG,KAAK;+BAAE;oBAAK,GAAG,QAAQ,aAAa,CAAC,OAAO,QAAQ,KAAK,GAAG,EAAE;oBAClG,KAAK,IAAI,QAAQ,MAAO;wBACtB;wBACA,MAAM;oBACR;gBACF;YACF;QACF;QAEA,MAAM;IACR;;aAtNQ,QAA6B,IAAI;;AAuN3C;AAEA,4EAA4E;AAC5E,SAAS,+BAAY,QAAyC;IAC5D,IAAI,QAAwB,EAAE;IAC9B,IAAI,WAA6C;IACjD,OAAO;QACL,CAAC,CAAC,OAAO,QAAQ,CAAC;YAChB,KAAK,IAAI,QAAQ,MACf,MAAM;YAGR,IAAI,CAAC,UACH,WAAW;YAGb,KAAK,IAAI,QAAQ,SAAU;gBACzB,MAAM,IAAI,CAAC;gBACX,MAAM;YACR;QACF;IACF;AACF;AAGA,SAAS,8BAAQ,KAAqB,EAAE,KAAqB;IAC3D,IAAI,SAAS,OACX,OAAO,CAAC,UAAY,MAAM,MAAM;IAGlC,IAAI,OACF,OAAO;IAGT,IAAI,OACF,OAAO;AAEX;AAEA,SAAS,iCAAW,GAAW;IAC7B,OAAO,GAAG,CAAC,EAAE,CAAC,WAAW,KAAK,IAAI,KAAK,CAAC;AAC1C","sources":["packages/@react-stately/collections/src/CollectionBuilder.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {CollectionBase, CollectionElement, Key, Node} from '@react-types/shared';\nimport {PartialNode} from './types';\nimport React, {ReactElement} from 'react';\n\ninterface CollectionBuilderState {\n renderer?: (value: any) => ReactElement | null\n}\n\ninterface CollectReactElement<T> extends ReactElement {\n getCollectionNode(props: any, context: any): Generator<PartialNode<T>, void, Node<T>[]>\n}\n\nexport class CollectionBuilder<T extends object> {\n private context?: unknown;\n private cache: WeakMap<T, Node<T>> = new WeakMap();\n\n build(props: Partial<CollectionBase<T>>, context?: unknown): Iterable<Node<T>> {\n this.context = context;\n return iterable(() => this.iterateCollection(props));\n }\n\n private *iterateCollection(props: Partial<CollectionBase<T>>): Generator<Node<T>> {\n let {children, items} = props;\n\n if (React.isValidElement<{children: CollectionElement<T>}>(children) && children.type === React.Fragment) {\n yield* this.iterateCollection({\n children: children.props.children,\n items\n });\n } else if (typeof children === 'function') {\n if (!items) {\n throw new Error('props.children was a function but props.items is missing');\n }\n\n let index = 0;\n for (let item of items) {\n yield* this.getFullNode({\n value: item,\n index\n }, {renderer: children});\n index++;\n }\n } else {\n let items: CollectionElement<T>[] = [];\n React.Children.forEach(children, child => {\n if (child) {\n items.push(child);\n }\n });\n\n let index = 0;\n for (let item of items) {\n let nodes = this.getFullNode({\n element: item,\n index: index\n }, {});\n\n for (let node of nodes) {\n index++;\n yield node;\n }\n }\n }\n }\n\n private getKey(item: NonNullable<CollectionElement<T>>, partialNode: PartialNode<T>, state: CollectionBuilderState, parentKey?: Key | null): Key {\n if (item.key != null) {\n return item.key;\n }\n\n if (partialNode.type === 'cell' && partialNode.key != null) {\n return `${parentKey}${partialNode.key}`;\n }\n\n let v = partialNode.value as any;\n if (v != null) {\n let key = v.key ?? v.id;\n if (key == null) {\n throw new Error('No key found for item');\n }\n\n return key;\n }\n\n return parentKey ? `${parentKey}.${partialNode.index}` : `$.${partialNode.index}`;\n }\n\n private getChildState(state: CollectionBuilderState, partialNode: PartialNode<T>) {\n return {\n renderer: partialNode.renderer || state.renderer\n };\n }\n\n private *getFullNode(partialNode: PartialNode<T> & {index: number}, state: CollectionBuilderState, parentKey?: Key | null, parentNode?: Node<T>): Generator<Node<T>> {\n if (React.isValidElement<{children: CollectionElement<T>}>(partialNode.element) && partialNode.element.type === React.Fragment) {\n let children: CollectionElement<T>[] = [];\n\n React.Children.forEach(partialNode.element.props.children, child => {\n children.push(child);\n });\n\n let index = partialNode.index ?? 0;\n\n for (const child of children) {\n yield* this.getFullNode({\n element: child,\n index: index++\n }, state, parentKey, parentNode);\n }\n\n return;\n }\n\n // If there's a value instead of an element on the node, and a parent renderer function is available,\n // use it to render an element for the value.\n let element = partialNode.element;\n if (!element && partialNode.value && state && state.renderer) {\n let cached = this.cache.get(partialNode.value);\n if (cached && (!cached.shouldInvalidate || !cached.shouldInvalidate(this.context))) {\n cached.index = partialNode.index;\n cached.parentKey = parentNode ? parentNode.key : null;\n yield cached;\n return;\n }\n\n element = state.renderer(partialNode.value);\n }\n\n // If there's an element with a getCollectionNode function on its type, then it's a supported component.\n // Call this function to get a partial node, and recursively build a full node from there.\n if (React.isValidElement(element)) {\n let type = element.type as unknown as CollectReactElement<T>;\n if (typeof type !== 'function' && typeof type.getCollectionNode !== 'function') {\n let name = element.type;\n throw new Error(`Unknown element <${name}> in collection.`);\n }\n\n let childNodes = type.getCollectionNode(element.props, this.context) as Generator<PartialNode<T>, void, Node<T>[]>;\n let index = partialNode.index ?? 0;\n let result = childNodes.next();\n while (!result.done && result.value) {\n let childNode = result.value;\n\n partialNode.index = index;\n\n let nodeKey = childNode.key ?? null;\n if (nodeKey == null) {\n nodeKey = childNode.element ? null : this.getKey(element as NonNullable<CollectionElement<T>>, partialNode, state, parentKey);\n }\n\n let nodes = this.getFullNode({\n ...childNode,\n key: nodeKey,\n index,\n wrapper: compose(partialNode.wrapper, childNode.wrapper)\n }, this.getChildState(state, childNode), parentKey ? `${parentKey}${element.key}` : element.key, parentNode);\n\n let children = [...nodes];\n for (let node of children) {\n // Cache the node based on its value\n node.value = childNode.value ?? partialNode.value ?? null;\n if (node.value) {\n this.cache.set(node.value, node);\n }\n\n // The partial node may have specified a type for the child in order to specify a constraint.\n // Verify that the full node that was built recursively matches this type.\n if (partialNode.type && node.type !== partialNode.type) {\n throw new Error(`Unsupported type <${capitalize(node.type)}> in <${capitalize(parentNode?.type ?? 'unknown parent type')}>. Only <${capitalize(partialNode.type)}> is supported.`);\n }\n\n index++;\n yield node;\n }\n\n result = childNodes.next(children);\n }\n\n return;\n }\n\n // Ignore invalid elements\n if (partialNode.key == null || partialNode.type == null) {\n return;\n }\n\n // Create full node\n let builder = this;\n let node: Node<T> = {\n type: partialNode.type,\n props: partialNode.props,\n key: partialNode.key,\n parentKey: parentNode ? parentNode.key : null,\n value: partialNode.value ?? null,\n level: parentNode ? parentNode.level + 1 : 0,\n index: partialNode.index,\n rendered: partialNode.rendered,\n textValue: partialNode.textValue ?? '',\n 'aria-label': partialNode['aria-label'],\n wrapper: partialNode.wrapper,\n shouldInvalidate: partialNode.shouldInvalidate,\n hasChildNodes: partialNode.hasChildNodes || false,\n childNodes: iterable(function *() {\n if (!partialNode.hasChildNodes || !partialNode.childNodes) {\n return;\n }\n\n let index = 0;\n for (let child of partialNode.childNodes()) {\n // Ensure child keys are globally unique by prepending the parent node's key\n if (child.key != null) {\n // TODO: Remove this line entirely and enforce that users always provide unique keys.\n // Currently this line will have issues when a parent has a key `a` and a child with key `bc`\n // but another parent has key `ab` and its child has a key `c`. The combined keys would result in both\n // children having a key of `abc`.\n child.key = `${node.key}${child.key}`;\n }\n\n let nodes = builder.getFullNode({...child, index}, builder.getChildState(state, child), node.key, node);\n for (let node of nodes) {\n index++;\n yield node;\n }\n }\n })\n };\n\n yield node;\n }\n}\n\n// Wraps an iterator function as an iterable object, and caches the results.\nfunction iterable<T>(iterator: () => IterableIterator<Node<T>>): Iterable<Node<T>> {\n let cache: Array<Node<T>> = [];\n let iterable: null | IterableIterator<Node<T>> = null;\n return {\n *[Symbol.iterator]() {\n for (let item of cache) {\n yield item;\n }\n\n if (!iterable) {\n iterable = iterator();\n }\n\n for (let item of iterable) {\n cache.push(item);\n yield item;\n }\n }\n };\n}\n\ntype Wrapper = (element: ReactElement) => ReactElement;\nfunction compose(outer: Wrapper | void, inner: Wrapper | void): Wrapper | undefined {\n if (outer && inner) {\n return (element) => outer(inner(element));\n }\n\n if (outer) {\n return outer;\n }\n\n if (inner) {\n return inner;\n }\n}\n\nfunction capitalize(str: string) {\n return str[0].toUpperCase() + str.slice(1);\n}\n"],"names":[],"version":3,"file":"CollectionBuilder.module.js.map"}
|
package/dist/Item.main.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
var $5Zch8$react = require("react");
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function $parcel$interopDefault(a) {
|
|
5
|
-
return a && a.__esModule ? a.default : a;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function $parcel$export(e, n, v, s) {
|
|
9
|
-
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
$parcel$export(module.exports, "Item", () => $c870f3b549c61b6b$export$6d08773d2e66f8f2);
|
|
13
|
-
/*
|
|
14
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
15
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
16
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
17
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
18
|
-
*
|
|
19
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
20
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
21
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
22
|
-
* governing permissions and limitations under the License.
|
|
23
|
-
*/
|
|
24
|
-
function $c870f3b549c61b6b$var$Item(props) {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
$c870f3b549c61b6b$var$Item.getCollectionNode = function* getCollectionNode(props, context) {
|
|
28
|
-
let { childItems: childItems, title: title, children: children } = props;
|
|
29
|
-
let rendered = props.title || props.children;
|
|
30
|
-
let textValue = props.textValue || (typeof rendered === 'string' ? rendered : '') || props['aria-label'] || '';
|
|
31
|
-
// suppressTextValueWarning is used in components like Tabs, which don't have type to select support.
|
|
32
|
-
if (!textValue && !(context === null || context === void 0 ? void 0 : context.suppressTextValueWarning) && process.env.NODE_ENV !== 'production') console.warn('<Item> with non-plain text contents is unsupported by type to select for accessibility. Please add a `textValue` prop.');
|
|
33
|
-
yield {
|
|
34
|
-
type: 'item',
|
|
35
|
-
props: props,
|
|
36
|
-
rendered: rendered,
|
|
37
|
-
textValue: textValue,
|
|
38
|
-
'aria-label': props['aria-label'],
|
|
39
|
-
hasChildNodes: $c870f3b549c61b6b$var$hasChildItems(props),
|
|
40
|
-
*childNodes () {
|
|
41
|
-
if (childItems) for (let child of childItems)yield {
|
|
42
|
-
type: 'item',
|
|
43
|
-
value: child
|
|
44
|
-
};
|
|
45
|
-
else if (title) {
|
|
46
|
-
let items = [];
|
|
47
|
-
(0, ($parcel$interopDefault($5Zch8$react))).Children.forEach(children, (child)=>{
|
|
48
|
-
items.push({
|
|
49
|
-
type: 'item',
|
|
50
|
-
element: child
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
yield* items;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
function $c870f3b549c61b6b$var$hasChildItems(props) {
|
|
59
|
-
if (props.hasChildItems != null) return props.hasChildItems;
|
|
60
|
-
if (props.childItems) return true;
|
|
61
|
-
if (props.title && (0, ($parcel$interopDefault($5Zch8$react))).Children.count(props.children) > 0) return true;
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
// We don't want getCollectionNode to show up in the type definition
|
|
65
|
-
let $c870f3b549c61b6b$export$6d08773d2e66f8f2 = $c870f3b549c61b6b$var$Item;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
//# sourceMappingURL=Item.main.js.map
|
package/dist/Item.main.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;AAMD,SAAS,2BAAQ,KAAmB;IAClC,OAAO;AACT;AAEA,2BAAK,iBAAiB,GAAG,UAAU,kBAAqB,KAAmB,EAAE,OAAY;IACvF,IAAI,cAAC,UAAU,SAAE,KAAK,YAAE,QAAQ,EAAC,GAAG;IAEpC,IAAI,WAAW,MAAM,KAAK,IAAI,MAAM,QAAQ;IAC5C,IAAI,YAAY,MAAM,SAAS,IAAK,CAAA,OAAO,aAAa,WAAW,WAAW,EAAC,KAAM,KAAK,CAAC,aAAa,IAAI;IAE5G,qGAAqG;IACrG,IAAI,CAAC,aAAa,EAAC,oBAAA,8BAAA,QAAS,wBAAwB,KAAI,QAAQ,GAAG,CAAC,QAAQ,KAAK,cAC/E,QAAQ,IAAI,CAAC;IAGf,MAAM;QACJ,MAAM;QACN,OAAO;kBACP;mBACA;QACA,cAAc,KAAK,CAAC,aAAa;QACjC,eAAe,oCAAc;QAC7B,CAAC;YACC,IAAI,YACF,KAAK,IAAI,SAAS,WAChB,MAAM;gBACJ,MAAM;gBACN,OAAO;YACT;iBAEG,IAAI,OAAO;gBAChB,IAAI,QAA0B,EAAE;gBAChC,CAAA,GAAA,sCAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAA;oBAC/B,MAAM,IAAI,CAAC;wBACT,MAAM;wBACN,SAAS;oBACX;gBACF;gBAEA,OAAO;YACT;QACF;IACF;AACF;AAEA,SAAS,oCAAiB,KAAmB;IAC3C,IAAI,MAAM,aAAa,IAAI,MACzB,OAAO,MAAM,aAAa;IAG5B,IAAI,MAAM,UAAU,EAClB,OAAO;IAGT,IAAI,MAAM,KAAK,IAAI,CAAA,GAAA,sCAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,MAAM,QAAQ,IAAI,GACxD,OAAO;IAGT,OAAO;AACT;AAEA,oEAAoE;AACpE,IAAI,4CAAQ","sources":["packages/@react-stately/collections/src/Item.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {ItemElement, ItemProps} from '@react-types/shared';\nimport {PartialNode} from './types';\nimport React, {JSX, ReactElement} from 'react';\n\nfunction Item<T>(props: ItemProps<T>): ReactElement | null { // eslint-disable-line @typescript-eslint/no-unused-vars\n return null;\n}\n\nItem.getCollectionNode = function* getCollectionNode<T>(props: ItemProps<T>, context: any): Generator<PartialNode<T>> {\n let {childItems, title, children} = props;\n\n let rendered = props.title || props.children;\n let textValue = props.textValue || (typeof rendered === 'string' ? rendered : '') || props['aria-label'] || '';\n\n // suppressTextValueWarning is used in components like Tabs, which don't have type to select support.\n if (!textValue && !context?.suppressTextValueWarning && process.env.NODE_ENV !== 'production') {\n console.warn('<Item> with non-plain text contents is unsupported by type to select for accessibility. Please add a `textValue` prop.');\n }\n\n yield {\n type: 'item',\n props: props,\n rendered,\n textValue,\n 'aria-label': props['aria-label'],\n hasChildNodes: hasChildItems(props),\n *childNodes() {\n if (childItems) {\n for (let child of childItems) {\n yield {\n type: 'item',\n value: child\n };\n }\n } else if (title) {\n let items: PartialNode<T>[] = [];\n React.Children.forEach(children, child => {\n items.push({\n type: 'item',\n element: child as ItemElement<T>\n });\n });\n\n yield* items;\n }\n }\n };\n};\n\nfunction hasChildItems<T>(props: ItemProps<T>) {\n if (props.hasChildItems != null) {\n return props.hasChildItems;\n }\n\n if (props.childItems) {\n return true;\n }\n\n if (props.title && React.Children.count(props.children) > 0) {\n return true;\n }\n\n return false;\n}\n\n// We don't want getCollectionNode to show up in the type definition\nlet _Item = Item as <T>(props: ItemProps<T>) => JSX.Element;\nexport {_Item as Item};\n"],"names":[],"version":3,"file":"Item.main.js.map"}
|
package/dist/Item.mjs
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import $6Fm0V$react from "react";
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
5
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
7
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
*
|
|
9
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
10
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
11
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
|
-
* governing permissions and limitations under the License.
|
|
13
|
-
*/
|
|
14
|
-
function $c1d7fb2ec91bae71$var$Item(props) {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
$c1d7fb2ec91bae71$var$Item.getCollectionNode = function* getCollectionNode(props, context) {
|
|
18
|
-
let { childItems: childItems, title: title, children: children } = props;
|
|
19
|
-
let rendered = props.title || props.children;
|
|
20
|
-
let textValue = props.textValue || (typeof rendered === 'string' ? rendered : '') || props['aria-label'] || '';
|
|
21
|
-
// suppressTextValueWarning is used in components like Tabs, which don't have type to select support.
|
|
22
|
-
if (!textValue && !(context === null || context === void 0 ? void 0 : context.suppressTextValueWarning) && process.env.NODE_ENV !== 'production') console.warn('<Item> with non-plain text contents is unsupported by type to select for accessibility. Please add a `textValue` prop.');
|
|
23
|
-
yield {
|
|
24
|
-
type: 'item',
|
|
25
|
-
props: props,
|
|
26
|
-
rendered: rendered,
|
|
27
|
-
textValue: textValue,
|
|
28
|
-
'aria-label': props['aria-label'],
|
|
29
|
-
hasChildNodes: $c1d7fb2ec91bae71$var$hasChildItems(props),
|
|
30
|
-
*childNodes () {
|
|
31
|
-
if (childItems) for (let child of childItems)yield {
|
|
32
|
-
type: 'item',
|
|
33
|
-
value: child
|
|
34
|
-
};
|
|
35
|
-
else if (title) {
|
|
36
|
-
let items = [];
|
|
37
|
-
(0, $6Fm0V$react).Children.forEach(children, (child)=>{
|
|
38
|
-
items.push({
|
|
39
|
-
type: 'item',
|
|
40
|
-
element: child
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
yield* items;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
function $c1d7fb2ec91bae71$var$hasChildItems(props) {
|
|
49
|
-
if (props.hasChildItems != null) return props.hasChildItems;
|
|
50
|
-
if (props.childItems) return true;
|
|
51
|
-
if (props.title && (0, $6Fm0V$react).Children.count(props.children) > 0) return true;
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
// We don't want getCollectionNode to show up in the type definition
|
|
55
|
-
let $c1d7fb2ec91bae71$export$6d08773d2e66f8f2 = $c1d7fb2ec91bae71$var$Item;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
export {$c1d7fb2ec91bae71$export$6d08773d2e66f8f2 as Item};
|
|
59
|
-
//# sourceMappingURL=Item.module.js.map
|
package/dist/Item.module.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import $6Fm0V$react from "react";
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
5
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
7
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
*
|
|
9
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
10
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
11
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
|
-
* governing permissions and limitations under the License.
|
|
13
|
-
*/
|
|
14
|
-
function $c1d7fb2ec91bae71$var$Item(props) {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
$c1d7fb2ec91bae71$var$Item.getCollectionNode = function* getCollectionNode(props, context) {
|
|
18
|
-
let { childItems: childItems, title: title, children: children } = props;
|
|
19
|
-
let rendered = props.title || props.children;
|
|
20
|
-
let textValue = props.textValue || (typeof rendered === 'string' ? rendered : '') || props['aria-label'] || '';
|
|
21
|
-
// suppressTextValueWarning is used in components like Tabs, which don't have type to select support.
|
|
22
|
-
if (!textValue && !(context === null || context === void 0 ? void 0 : context.suppressTextValueWarning) && process.env.NODE_ENV !== 'production') console.warn('<Item> with non-plain text contents is unsupported by type to select for accessibility. Please add a `textValue` prop.');
|
|
23
|
-
yield {
|
|
24
|
-
type: 'item',
|
|
25
|
-
props: props,
|
|
26
|
-
rendered: rendered,
|
|
27
|
-
textValue: textValue,
|
|
28
|
-
'aria-label': props['aria-label'],
|
|
29
|
-
hasChildNodes: $c1d7fb2ec91bae71$var$hasChildItems(props),
|
|
30
|
-
*childNodes () {
|
|
31
|
-
if (childItems) for (let child of childItems)yield {
|
|
32
|
-
type: 'item',
|
|
33
|
-
value: child
|
|
34
|
-
};
|
|
35
|
-
else if (title) {
|
|
36
|
-
let items = [];
|
|
37
|
-
(0, $6Fm0V$react).Children.forEach(children, (child)=>{
|
|
38
|
-
items.push({
|
|
39
|
-
type: 'item',
|
|
40
|
-
element: child
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
yield* items;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
function $c1d7fb2ec91bae71$var$hasChildItems(props) {
|
|
49
|
-
if (props.hasChildItems != null) return props.hasChildItems;
|
|
50
|
-
if (props.childItems) return true;
|
|
51
|
-
if (props.title && (0, $6Fm0V$react).Children.count(props.children) > 0) return true;
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
// We don't want getCollectionNode to show up in the type definition
|
|
55
|
-
let $c1d7fb2ec91bae71$export$6d08773d2e66f8f2 = $c1d7fb2ec91bae71$var$Item;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
export {$c1d7fb2ec91bae71$export$6d08773d2e66f8f2 as Item};
|
|
59
|
-
//# sourceMappingURL=Item.module.js.map
|