@react-stately/collections 3.3.4 → 3.3.7
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/main.js +288 -389
- package/dist/main.js.map +1 -1
- package/dist/module.js +272 -377
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/CollectionBuilder.ts +4 -0
package/dist/main.js
CHANGED
|
@@ -1,436 +1,335 @@
|
|
|
1
|
-
var
|
|
1
|
+
var $4aZkW$react = require("react");
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
function $parcel$exportWildcard(dest, source) {
|
|
4
|
+
Object.keys(source).forEach(function(key) {
|
|
5
|
+
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
Object.defineProperty(dest, key, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function get() {
|
|
12
|
+
return source[key];
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
});
|
|
11
16
|
|
|
17
|
+
return dest;
|
|
18
|
+
}
|
|
12
19
|
function $parcel$interopDefault(a) {
|
|
13
20
|
return a && a.__esModule ? a.default : a;
|
|
14
21
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
18
|
-
return null;
|
|
22
|
+
function $parcel$export(e, n, v, s) {
|
|
23
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
19
24
|
}
|
|
25
|
+
var $c870f3b549c61b6b$exports = {};
|
|
20
26
|
|
|
21
|
-
$
|
|
22
|
-
let {
|
|
23
|
-
childItems,
|
|
24
|
-
title,
|
|
25
|
-
children
|
|
26
|
-
} = props;
|
|
27
|
-
let rendered = props.title || props.children;
|
|
28
|
-
let textValue = props.textValue || (typeof rendered === 'string' ? rendered : '') || props['aria-label'] || ''; // suppressTextValueWarning is used in components like Tabs, which don't have type to select support.
|
|
29
|
-
|
|
30
|
-
if (!textValue && !(context != null && context.suppressTextValueWarning)) {
|
|
31
|
-
console.warn('<Item> with non-plain text contents is unsupported by type to select for accessibility. Please add a `textValue` prop.');
|
|
32
|
-
}
|
|
27
|
+
$parcel$export($c870f3b549c61b6b$exports, "Item", () => $c870f3b549c61b6b$export$6d08773d2e66f8f2);
|
|
33
28
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
29
|
+
function $c870f3b549c61b6b$var$Item(props) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
$c870f3b549c61b6b$var$Item.getCollectionNode = function* getCollectionNode(props, context) {
|
|
33
|
+
let { childItems: childItems , title: title , children: children } = props;
|
|
34
|
+
let rendered = props.title || props.children;
|
|
35
|
+
let textValue = props.textValue || (typeof rendered === 'string' ? rendered : '') || props['aria-label'] || '';
|
|
36
|
+
// suppressTextValueWarning is used in components like Tabs, which don't have type to select support.
|
|
37
|
+
if (!textValue && !(context === null || context === void 0 ? void 0 : context.suppressTextValueWarning)) console.warn('<Item> with non-plain text contents is unsupported by type to select for accessibility. Please add a `textValue` prop.');
|
|
38
|
+
yield {
|
|
39
|
+
type: 'item',
|
|
40
|
+
props: props,
|
|
41
|
+
rendered: rendered,
|
|
42
|
+
textValue: textValue,
|
|
43
|
+
'aria-label': props['aria-label'],
|
|
44
|
+
hasChildNodes: $c870f3b549c61b6b$var$hasChildItems(props),
|
|
45
|
+
*childNodes () {
|
|
46
|
+
if (childItems) for (let child1 of childItems)yield {
|
|
47
|
+
type: 'item',
|
|
48
|
+
value: child1
|
|
49
|
+
};
|
|
50
|
+
else if (title) {
|
|
51
|
+
let items = [];
|
|
52
|
+
($parcel$interopDefault($4aZkW$react)).Children.forEach(children, (child)=>{
|
|
53
|
+
items.push({
|
|
54
|
+
type: 'item',
|
|
55
|
+
element: child
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
yield* items;
|
|
59
|
+
}
|
|
49
60
|
}
|
|
50
|
-
|
|
51
|
-
let items = [];
|
|
52
|
-
|
|
53
|
-
_react.Children.forEach(children, child => {
|
|
54
|
-
items.push({
|
|
55
|
-
type: 'item',
|
|
56
|
-
element: child
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
yield* items;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
};
|
|
61
|
+
};
|
|
65
62
|
};
|
|
63
|
+
function $c870f3b549c61b6b$var$hasChildItems(props) {
|
|
64
|
+
if (props.hasChildItems != null) return props.hasChildItems;
|
|
65
|
+
if (props.childItems) return true;
|
|
66
|
+
if (props.title && ($parcel$interopDefault($4aZkW$react)).Children.count(props.children) > 0) return true;
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
// We don't want getCollectionNode to show up in the type definition
|
|
70
|
+
let $c870f3b549c61b6b$export$6d08773d2e66f8f2 = $c870f3b549c61b6b$var$Item;
|
|
66
71
|
|
|
67
|
-
function $de85adf0b38f4f13e9cffd2f21$var$hasChildItems(props) {
|
|
68
|
-
if (props.hasChildItems != null) {
|
|
69
|
-
return props.hasChildItems;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (props.childItems) {
|
|
73
|
-
return true;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (props.title && _react.Children.count(props.children) > 0) {
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return false;
|
|
81
|
-
} // We don't want getCollectionNode to show up in the type definition
|
|
82
72
|
|
|
73
|
+
var $350f13aa4d8b327c$exports = {};
|
|
83
74
|
|
|
84
|
-
|
|
85
|
-
exports.Item = Item;
|
|
75
|
+
$parcel$export($350f13aa4d8b327c$exports, "Section", () => $350f13aa4d8b327c$export$6e2c8f0811a474ce);
|
|
86
76
|
|
|
87
|
-
function $
|
|
88
|
-
|
|
89
|
-
return null;
|
|
77
|
+
function $350f13aa4d8b327c$var$Section(props) {
|
|
78
|
+
return null;
|
|
90
79
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
80
|
+
$350f13aa4d8b327c$var$Section.getCollectionNode = function* getCollectionNode(props) {
|
|
81
|
+
let { children: children , title: title , items: items1 } = props;
|
|
82
|
+
yield {
|
|
83
|
+
type: 'section',
|
|
84
|
+
hasChildNodes: true,
|
|
85
|
+
rendered: title,
|
|
86
|
+
'aria-label': props['aria-label'],
|
|
87
|
+
*childNodes () {
|
|
88
|
+
if (typeof children === 'function') {
|
|
89
|
+
if (!items1) throw new Error('props.children was a function but props.items is missing');
|
|
90
|
+
for (let item of items1)yield {
|
|
91
|
+
type: 'item',
|
|
92
|
+
value: item,
|
|
93
|
+
renderer: children
|
|
94
|
+
};
|
|
95
|
+
} else {
|
|
96
|
+
let items = [];
|
|
97
|
+
($parcel$interopDefault($4aZkW$react)).Children.forEach(children, (child)=>{
|
|
98
|
+
items.push({
|
|
99
|
+
type: 'item',
|
|
100
|
+
element: child
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
yield* items;
|
|
104
|
+
}
|
|
108
105
|
}
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
// We don't want getCollectionNode to show up in the type definition
|
|
109
|
+
let $350f13aa4d8b327c$export$6e2c8f0811a474ce = $350f13aa4d8b327c$var$Section;
|
|
109
110
|
|
|
110
|
-
for (let item of items) {
|
|
111
|
-
yield {
|
|
112
|
-
type: 'item',
|
|
113
|
-
value: item,
|
|
114
|
-
renderer: children
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
} else {
|
|
118
|
-
let items = [];
|
|
119
|
-
|
|
120
|
-
_react.Children.forEach(children, child => {
|
|
121
|
-
items.push({
|
|
122
|
-
type: 'item',
|
|
123
|
-
element: child
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
yield* items;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
};
|
|
132
|
-
}; // We don't want getCollectionNode to show up in the type definition
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
let Section = $fce9f2c25e6e4c6ae9d7b8458177776c$var$Section;
|
|
136
|
-
exports.Section = Section;
|
|
137
|
-
|
|
138
|
-
class $f9fc6bc72d334a59f09d47517f9a056a$export$CollectionBuilder {
|
|
139
|
-
constructor() {
|
|
140
|
-
this.context = void 0;
|
|
141
|
-
this.cache = new WeakMap();
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
build(props, context) {
|
|
145
|
-
this.context = context;
|
|
146
|
-
return $f9fc6bc72d334a59f09d47517f9a056a$var$iterable(() => this.iterateCollection(props));
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
*iterateCollection(props) {
|
|
150
|
-
let {
|
|
151
|
-
children,
|
|
152
|
-
items
|
|
153
|
-
} = props;
|
|
154
|
-
|
|
155
|
-
if (typeof children === 'function') {
|
|
156
|
-
if (!items) {
|
|
157
|
-
throw new Error('props.children was a function but props.items is missing');
|
|
158
|
-
}
|
|
159
111
|
|
|
160
|
-
|
|
161
|
-
yield* this.getFullNode({
|
|
162
|
-
value: item
|
|
163
|
-
}, {
|
|
164
|
-
renderer: children
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
} else {
|
|
168
|
-
let items = [];
|
|
112
|
+
var $cade2c06f59a1baa$exports = {};
|
|
169
113
|
|
|
170
|
-
_react.Children.forEach(children, child => {
|
|
171
|
-
items.push(child);
|
|
172
|
-
});
|
|
173
114
|
|
|
174
|
-
|
|
115
|
+
var $98fc0fafaca75b6a$exports = {};
|
|
175
116
|
|
|
176
|
-
|
|
177
|
-
let nodes = this.getFullNode({
|
|
178
|
-
element: item,
|
|
179
|
-
index: index
|
|
180
|
-
}, {});
|
|
117
|
+
$parcel$export($98fc0fafaca75b6a$exports, "useCollection", () => $98fc0fafaca75b6a$export$6cd28814d92fa9c9);
|
|
181
118
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
119
|
+
class $51588fd411aace25$export$bf788dd355e3a401 {
|
|
120
|
+
build(props, context) {
|
|
121
|
+
this.context = context;
|
|
122
|
+
return $51588fd411aace25$var$iterable(()=>this.iterateCollection(props)
|
|
123
|
+
);
|
|
187
124
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
125
|
+
*iterateCollection(props) {
|
|
126
|
+
let { children: children , items: items } = props;
|
|
127
|
+
if (typeof children === 'function') {
|
|
128
|
+
if (!items) throw new Error('props.children was a function but props.items is missing');
|
|
129
|
+
for (let item of props.items)yield* this.getFullNode({
|
|
130
|
+
value: item
|
|
131
|
+
}, {
|
|
132
|
+
renderer: children
|
|
133
|
+
});
|
|
134
|
+
} else {
|
|
135
|
+
let items = [];
|
|
136
|
+
($parcel$interopDefault($4aZkW$react)).Children.forEach(children, (child)=>{
|
|
137
|
+
items.push(child);
|
|
138
|
+
});
|
|
139
|
+
let index = 0;
|
|
140
|
+
for (let item of items){
|
|
141
|
+
let nodes = this.getFullNode({
|
|
142
|
+
element: item,
|
|
143
|
+
index: index
|
|
144
|
+
}, {
|
|
145
|
+
});
|
|
146
|
+
for (let node of nodes){
|
|
147
|
+
index++;
|
|
148
|
+
yield node;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
193
152
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
153
|
+
getKey(item, partialNode, state, parentKey) {
|
|
154
|
+
if (item.key != null) return item.key;
|
|
155
|
+
if (partialNode.type === 'cell' && partialNode.key != null) return `${parentKey}${partialNode.key}`;
|
|
156
|
+
let v = partialNode.value;
|
|
157
|
+
if (v != null) {
|
|
158
|
+
var _key;
|
|
159
|
+
let key = (_key = v.key) !== null && _key !== void 0 ? _key : v.id;
|
|
160
|
+
if (key == null) throw new Error('No key found for item');
|
|
161
|
+
return key;
|
|
162
|
+
}
|
|
163
|
+
return parentKey ? `${parentKey}.${partialNode.index}` : `$.${partialNode.index}`;
|
|
197
164
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
var _v$key;
|
|
203
|
-
|
|
204
|
-
let key = (_v$key = v.key) != null ? _v$key : v.id;
|
|
205
|
-
|
|
206
|
-
if (key == null) {
|
|
207
|
-
throw new Error('No key found for item');
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
return key;
|
|
165
|
+
getChildState(state, partialNode) {
|
|
166
|
+
return {
|
|
167
|
+
renderer: partialNode.renderer || state.renderer
|
|
168
|
+
};
|
|
211
169
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
let element = partialNode.element;
|
|
226
|
-
|
|
227
|
-
if (!element && partialNode.value && state && state.renderer) {
|
|
228
|
-
let cached = this.cache.get(partialNode.value);
|
|
229
|
-
|
|
230
|
-
if (cached && (!cached.shouldInvalidate || !cached.shouldInvalidate(this.context))) {
|
|
231
|
-
cached.index = partialNode.index;
|
|
232
|
-
cached.parentKey = parentNode ? parentNode.key : null;
|
|
233
|
-
yield cached;
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
element = state.renderer(partialNode.value);
|
|
238
|
-
} // If there's an element with a getCollectionNode function on its type, then it's a supported component.
|
|
239
|
-
// Call this function to get a partial node, and recursively build a full node from there.
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
if ( /*#__PURE__*/_react.isValidElement(element)) {
|
|
243
|
-
let type = element.type;
|
|
244
|
-
|
|
245
|
-
if (typeof type !== 'function' && typeof type.getCollectionNode !== 'function') {
|
|
246
|
-
let name = typeof element.type === 'function' ? element.type.name : element.type;
|
|
247
|
-
throw new Error("Unknown element <" + name + "> in collection.");
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
let childNodes = type.getCollectionNode(element.props, this.context);
|
|
251
|
-
let index = partialNode.index;
|
|
252
|
-
let result = childNodes.next();
|
|
253
|
-
|
|
254
|
-
while (!result.done && result.value) {
|
|
255
|
-
let childNode = result.value;
|
|
256
|
-
partialNode.index = index;
|
|
257
|
-
let nodeKey = childNode.key;
|
|
258
|
-
|
|
259
|
-
if (!nodeKey) {
|
|
260
|
-
nodeKey = childNode.element ? null : this.getKey(element, partialNode, state, parentKey);
|
|
170
|
+
*getFullNode(partialNode, state, parentKey, parentNode) {
|
|
171
|
+
// If there's a value instead of an element on the node, and a parent renderer function is available,
|
|
172
|
+
// use it to render an element for the value.
|
|
173
|
+
let element = partialNode.element;
|
|
174
|
+
if (!element && partialNode.value && state && state.renderer) {
|
|
175
|
+
let cached = this.cache.get(partialNode.value);
|
|
176
|
+
if (cached && (!cached.shouldInvalidate || !cached.shouldInvalidate(this.context))) {
|
|
177
|
+
cached.index = partialNode.index;
|
|
178
|
+
cached.parentKey = parentNode ? parentNode.key : null;
|
|
179
|
+
yield cached;
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
element = state.renderer(partialNode.value);
|
|
261
183
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
let builder = this;
|
|
301
|
-
let node = {
|
|
302
|
-
type: partialNode.type,
|
|
303
|
-
props: partialNode.props,
|
|
304
|
-
key: partialNode.key,
|
|
305
|
-
parentKey: parentNode ? parentNode.key : null,
|
|
306
|
-
value: partialNode.value,
|
|
307
|
-
level: parentNode ? parentNode.level + 1 : 0,
|
|
308
|
-
index: partialNode.index,
|
|
309
|
-
rendered: partialNode.rendered,
|
|
310
|
-
textValue: partialNode.textValue,
|
|
311
|
-
'aria-label': partialNode['aria-label'],
|
|
312
|
-
wrapper: partialNode.wrapper,
|
|
313
|
-
shouldInvalidate: partialNode.shouldInvalidate,
|
|
314
|
-
hasChildNodes: partialNode.hasChildNodes,
|
|
315
|
-
childNodes: $f9fc6bc72d334a59f09d47517f9a056a$var$iterable(function* () {
|
|
316
|
-
if (!partialNode.hasChildNodes) {
|
|
317
|
-
return;
|
|
184
|
+
// If there's an element with a getCollectionNode function on its type, then it's a supported component.
|
|
185
|
+
// Call this function to get a partial node, and recursively build a full node from there.
|
|
186
|
+
if (($parcel$interopDefault($4aZkW$react)).isValidElement(element)) {
|
|
187
|
+
let type = element.type;
|
|
188
|
+
if (typeof type !== 'function' && typeof type.getCollectionNode !== 'function') {
|
|
189
|
+
let name = typeof element.type === 'function' ? element.type.name : element.type;
|
|
190
|
+
throw new Error(`Unknown element <${name}> in collection.`);
|
|
191
|
+
}
|
|
192
|
+
let childNodes = type.getCollectionNode(element.props, this.context);
|
|
193
|
+
let index = partialNode.index;
|
|
194
|
+
let result = childNodes.next();
|
|
195
|
+
while(!result.done && result.value){
|
|
196
|
+
let childNode = result.value;
|
|
197
|
+
partialNode.index = index;
|
|
198
|
+
let nodeKey = childNode.key;
|
|
199
|
+
if (!nodeKey) nodeKey = childNode.element ? null : this.getKey(element, partialNode, state, parentKey);
|
|
200
|
+
let nodes = this.getFullNode({
|
|
201
|
+
...childNode,
|
|
202
|
+
key: nodeKey,
|
|
203
|
+
index: index,
|
|
204
|
+
wrapper: $51588fd411aace25$var$compose(partialNode.wrapper, childNode.wrapper)
|
|
205
|
+
}, this.getChildState(state, childNode), parentKey ? `${parentKey}${element.key}` : element.key, parentNode);
|
|
206
|
+
let children = [
|
|
207
|
+
...nodes
|
|
208
|
+
];
|
|
209
|
+
for (let node of children){
|
|
210
|
+
// Cache the node based on its value
|
|
211
|
+
node.value = childNode.value || partialNode.value;
|
|
212
|
+
if (node.value) this.cache.set(node.value, node);
|
|
213
|
+
// The partial node may have specified a type for the child in order to specify a constraint.
|
|
214
|
+
// Verify that the full node that was built recursively matches this type.
|
|
215
|
+
if (partialNode.type && node.type !== partialNode.type) throw new Error(`Unsupported type <${$51588fd411aace25$var$capitalize(node.type)}> in <${$51588fd411aace25$var$capitalize(parentNode.type)}>. Only <${$51588fd411aace25$var$capitalize(partialNode.type)}> is supported.`);
|
|
216
|
+
index++;
|
|
217
|
+
yield node;
|
|
218
|
+
}
|
|
219
|
+
result = childNodes.next(children);
|
|
220
|
+
}
|
|
221
|
+
return;
|
|
318
222
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
223
|
+
// Ignore invalid elements
|
|
224
|
+
if (partialNode.key == null) return;
|
|
225
|
+
// Create full node
|
|
226
|
+
let builder = this;
|
|
227
|
+
let node = {
|
|
228
|
+
type: partialNode.type,
|
|
229
|
+
props: partialNode.props,
|
|
230
|
+
key: partialNode.key,
|
|
231
|
+
parentKey: parentNode ? parentNode.key : null,
|
|
232
|
+
value: partialNode.value,
|
|
233
|
+
level: parentNode ? parentNode.level + 1 : 0,
|
|
234
|
+
index: partialNode.index,
|
|
235
|
+
rendered: partialNode.rendered,
|
|
236
|
+
textValue: partialNode.textValue,
|
|
237
|
+
'aria-label': partialNode['aria-label'],
|
|
238
|
+
wrapper: partialNode.wrapper,
|
|
239
|
+
shouldInvalidate: partialNode.shouldInvalidate,
|
|
240
|
+
hasChildNodes: partialNode.hasChildNodes,
|
|
241
|
+
childNodes: $51588fd411aace25$var$iterable(function*() {
|
|
242
|
+
if (!partialNode.hasChildNodes) return;
|
|
243
|
+
let index = 0;
|
|
244
|
+
for (let child of partialNode.childNodes()){
|
|
245
|
+
// Ensure child keys are globally unique by prepending the parent node's key
|
|
246
|
+
if (child.key != null) // TODO: Remove this line entirely and enforce that users always provide unique keys.
|
|
247
|
+
// Currently this line will have issues when a parent has a key `a` and a child with key `bc`
|
|
248
|
+
// but another parent has key `ab` and its child has a key `c`. The combined keys would result in both
|
|
249
|
+
// children having a key of `abc`.
|
|
250
|
+
child.key = `${node.key}${child.key}`;
|
|
251
|
+
child.index = index;
|
|
252
|
+
let nodes = builder.getFullNode(child, builder.getChildState(state, child), node.key, node);
|
|
253
|
+
for (let node1 of nodes){
|
|
254
|
+
index++;
|
|
255
|
+
yield node1;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
})
|
|
259
|
+
};
|
|
260
|
+
yield node;
|
|
261
|
+
}
|
|
262
|
+
constructor(){
|
|
263
|
+
this.cache = new WeakMap();
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
// Wraps an iterator function as an iterable object, and caches the results.
|
|
267
|
+
function $51588fd411aace25$var$iterable(iterator) {
|
|
268
|
+
let cache = [];
|
|
269
|
+
let iterable = null;
|
|
270
|
+
return {
|
|
271
|
+
*[Symbol.iterator] () {
|
|
272
|
+
for (let item of cache)yield item;
|
|
273
|
+
if (!iterable) iterable = iterator();
|
|
274
|
+
for (let item1 of iterable){
|
|
275
|
+
cache.push(item1);
|
|
276
|
+
yield item1;
|
|
277
|
+
}
|
|
335
278
|
}
|
|
336
|
-
})
|
|
337
279
|
};
|
|
338
|
-
yield node;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
} // Wraps an iterator function as an iterable object, and caches the results.
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
function $f9fc6bc72d334a59f09d47517f9a056a$var$iterable(iterator) {
|
|
345
|
-
let cache = [];
|
|
346
|
-
let iterable = null;
|
|
347
|
-
return {
|
|
348
|
-
*[Symbol.iterator]() {
|
|
349
|
-
for (let item of cache) {
|
|
350
|
-
yield item;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
if (!iterable) {
|
|
354
|
-
iterable = iterator();
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
for (let item of iterable) {
|
|
358
|
-
cache.push(item);
|
|
359
|
-
yield item;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
};
|
|
364
280
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
if (outer) {
|
|
372
|
-
return outer;
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
if (inner) {
|
|
376
|
-
return inner;
|
|
377
|
-
}
|
|
281
|
+
function $51588fd411aace25$var$compose(outer, inner) {
|
|
282
|
+
if (outer && inner) return (element)=>outer(inner(element))
|
|
283
|
+
;
|
|
284
|
+
if (outer) return outer;
|
|
285
|
+
if (inner) return inner;
|
|
378
286
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
return str[0].toUpperCase() + str.slice(1);
|
|
287
|
+
function $51588fd411aace25$var$capitalize(str) {
|
|
288
|
+
return str[0].toUpperCase() + str.slice(1);
|
|
382
289
|
}
|
|
383
290
|
|
|
384
|
-
function useCollection(props, factory, context, invalidators) {
|
|
385
|
-
if (invalidators === void 0) {
|
|
386
|
-
invalidators = [];
|
|
387
|
-
}
|
|
388
291
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
prev
|
|
394
|
-
return
|
|
292
|
+
|
|
293
|
+
function $98fc0fafaca75b6a$export$6cd28814d92fa9c9(props, factory, context, invalidators = []) {
|
|
294
|
+
let builder = $4aZkW$react.useMemo(()=>new $51588fd411aace25$export$bf788dd355e3a401()
|
|
295
|
+
, []);
|
|
296
|
+
let prev = $4aZkW$react.useRef(null);
|
|
297
|
+
return $4aZkW$react.useMemo(()=>{
|
|
298
|
+
let nodes = builder.build(props, context);
|
|
299
|
+
prev.current = factory(nodes, prev.current);
|
|
300
|
+
return prev.current;
|
|
301
|
+
// Don't invalidate when any prop changes, just the two we care about.
|
|
395
302
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
396
|
-
|
|
303
|
+
}, [
|
|
304
|
+
builder,
|
|
305
|
+
props.children,
|
|
306
|
+
props.items,
|
|
307
|
+
context,
|
|
308
|
+
...invalidators
|
|
309
|
+
]);
|
|
397
310
|
}
|
|
398
311
|
|
|
399
|
-
exports.useCollection = useCollection;
|
|
400
|
-
|
|
401
|
-
/*
|
|
402
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
403
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
404
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
405
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
406
|
-
*
|
|
407
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
408
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
409
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
410
|
-
* governing permissions and limitations under the License.
|
|
411
|
-
*/
|
|
412
|
-
const $f87be1a9afd2842b9b36ca75398a185$var$cache = new WeakMap();
|
|
413
312
|
|
|
414
|
-
|
|
415
|
-
let count = $f87be1a9afd2842b9b36ca75398a185$var$cache.get(collection);
|
|
313
|
+
var $e749fe52977fe2c2$exports = {};
|
|
416
314
|
|
|
417
|
-
|
|
315
|
+
$parcel$export($e749fe52977fe2c2$exports, "getItemCount", () => $e749fe52977fe2c2$export$77d5aafae4e095b2);
|
|
316
|
+
const $e749fe52977fe2c2$var$cache = new WeakMap();
|
|
317
|
+
function $e749fe52977fe2c2$export$77d5aafae4e095b2(collection) {
|
|
318
|
+
let count = $e749fe52977fe2c2$var$cache.get(collection);
|
|
319
|
+
if (count != null) return count;
|
|
320
|
+
count = 0;
|
|
321
|
+
for (let item of collection)if (item.type === 'section') count += $e749fe52977fe2c2$export$77d5aafae4e095b2(item.childNodes);
|
|
322
|
+
else count++;
|
|
323
|
+
$e749fe52977fe2c2$var$cache.set(collection, count);
|
|
418
324
|
return count;
|
|
419
|
-
|
|
325
|
+
}
|
|
420
326
|
|
|
421
|
-
count = 0;
|
|
422
327
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
}
|
|
429
|
-
}
|
|
328
|
+
$parcel$exportWildcard(module.exports, $c870f3b549c61b6b$exports);
|
|
329
|
+
$parcel$exportWildcard(module.exports, $350f13aa4d8b327c$exports);
|
|
330
|
+
$parcel$exportWildcard(module.exports, $cade2c06f59a1baa$exports);
|
|
331
|
+
$parcel$exportWildcard(module.exports, $98fc0fafaca75b6a$exports);
|
|
332
|
+
$parcel$exportWildcard(module.exports, $e749fe52977fe2c2$exports);
|
|
430
333
|
|
|
431
|
-
$f87be1a9afd2842b9b36ca75398a185$var$cache.set(collection, count);
|
|
432
|
-
return count;
|
|
433
|
-
}
|
|
434
334
|
|
|
435
|
-
exports.getItemCount = getItemCount;
|
|
436
335
|
//# sourceMappingURL=main.js.map
|