@react-stately/collections 3.11.0 → 3.12.1
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/LICENSE +201 -0
- package/dist/CollectionBuilder.main.js +33 -20
- package/dist/CollectionBuilder.main.js.map +1 -1
- package/dist/CollectionBuilder.mjs +33 -20
- package/dist/CollectionBuilder.module.js +33 -20
- package/dist/CollectionBuilder.module.js.map +1 -1
- package/dist/Item.main.js.map +1 -1
- package/dist/Item.module.js.map +1 -1
- package/dist/Section.main.js.map +1 -1
- package/dist/Section.module.js.map +1 -1
- package/dist/getChildNodes.main.js +4 -3
- package/dist/getChildNodes.main.js.map +1 -1
- package/dist/getChildNodes.mjs +4 -3
- package/dist/getChildNodes.module.js +4 -3
- package/dist/getChildNodes.module.js.map +1 -1
- package/dist/getItemCount.main.js +5 -4
- package/dist/getItemCount.main.js.map +1 -1
- package/dist/getItemCount.mjs +5 -4
- package/dist/getItemCount.module.js +5 -4
- package/dist/getItemCount.module.js.map +1 -1
- package/dist/types.d.ts +6 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/useCollection.main.js.map +1 -1
- package/dist/useCollection.module.js.map +1 -1
- package/package.json +6 -5
- package/src/CollectionBuilder.ts +35 -27
- package/src/Item.ts +1 -1
- package/src/Section.ts +1 -1
- package/src/getChildNodes.ts +8 -5
- package/src/getItemCount.ts +5 -4
- package/src/types.ts +4 -4
- package/src/useCollection.ts +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2019 Adobe
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -34,15 +34,20 @@ class $51588fd411aace25$export$bf788dd355e3a401 {
|
|
|
34
34
|
});
|
|
35
35
|
else if (typeof children === 'function') {
|
|
36
36
|
if (!items) throw new Error('props.children was a function but props.items is missing');
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
let index = 0;
|
|
38
|
+
for (let item of items){
|
|
39
|
+
yield* this.getFullNode({
|
|
40
|
+
value: item,
|
|
41
|
+
index: index
|
|
42
|
+
}, {
|
|
43
|
+
renderer: children
|
|
44
|
+
});
|
|
45
|
+
index++;
|
|
46
|
+
}
|
|
42
47
|
} else {
|
|
43
48
|
let items = [];
|
|
44
49
|
(0, ($parcel$interopDefault($ioO2y$react))).Children.forEach(children, (child)=>{
|
|
45
|
-
items.push(child);
|
|
50
|
+
if (child) items.push(child);
|
|
46
51
|
});
|
|
47
52
|
let index = 0;
|
|
48
53
|
for (let item of items){
|
|
@@ -80,7 +85,8 @@ class $51588fd411aace25$export$bf788dd355e3a401 {
|
|
|
80
85
|
(0, ($parcel$interopDefault($ioO2y$react))).Children.forEach(partialNode.element.props.children, (child)=>{
|
|
81
86
|
children.push(child);
|
|
82
87
|
});
|
|
83
|
-
|
|
88
|
+
var _partialNode_index;
|
|
89
|
+
let index = (_partialNode_index = partialNode.index) !== null && _partialNode_index !== void 0 ? _partialNode_index : 0;
|
|
84
90
|
for (const child of children)yield* this.getFullNode({
|
|
85
91
|
element: child,
|
|
86
92
|
index: index++
|
|
@@ -105,17 +111,19 @@ class $51588fd411aace25$export$bf788dd355e3a401 {
|
|
|
105
111
|
if ((0, ($parcel$interopDefault($ioO2y$react))).isValidElement(element)) {
|
|
106
112
|
let type = element.type;
|
|
107
113
|
if (typeof type !== 'function' && typeof type.getCollectionNode !== 'function') {
|
|
108
|
-
let name =
|
|
114
|
+
let name = element.type;
|
|
109
115
|
throw new Error(`Unknown element <${name}> in collection.`);
|
|
110
116
|
}
|
|
111
117
|
let childNodes = type.getCollectionNode(element.props, this.context);
|
|
112
|
-
|
|
118
|
+
var _partialNode_index1;
|
|
119
|
+
let index = (_partialNode_index1 = partialNode.index) !== null && _partialNode_index1 !== void 0 ? _partialNode_index1 : 0;
|
|
113
120
|
let result = childNodes.next();
|
|
114
121
|
while(!result.done && result.value){
|
|
115
122
|
let childNode = result.value;
|
|
116
123
|
partialNode.index = index;
|
|
117
|
-
|
|
118
|
-
|
|
124
|
+
var _childNode_key;
|
|
125
|
+
let nodeKey = (_childNode_key = childNode.key) !== null && _childNode_key !== void 0 ? _childNode_key : null;
|
|
126
|
+
if (nodeKey == null) nodeKey = childNode.element ? null : this.getKey(element, partialNode, state, parentKey);
|
|
119
127
|
let nodes = this.getFullNode({
|
|
120
128
|
...childNode,
|
|
121
129
|
key: nodeKey,
|
|
@@ -126,12 +134,14 @@ class $51588fd411aace25$export$bf788dd355e3a401 {
|
|
|
126
134
|
...nodes
|
|
127
135
|
];
|
|
128
136
|
for (let node of children){
|
|
137
|
+
var _childNode_value, _ref;
|
|
129
138
|
// Cache the node based on its value
|
|
130
|
-
node.value = childNode.value
|
|
139
|
+
node.value = (_ref = (_childNode_value = childNode.value) !== null && _childNode_value !== void 0 ? _childNode_value : partialNode.value) !== null && _ref !== void 0 ? _ref : null;
|
|
131
140
|
if (node.value) this.cache.set(node.value, node);
|
|
141
|
+
var _parentNode_type;
|
|
132
142
|
// The partial node may have specified a type for the child in order to specify a constraint.
|
|
133
143
|
// 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 <${$51588fd411aace25$var$capitalize(node.type)}> in <${$51588fd411aace25$var$capitalize(parentNode.type)}>. Only <${$51588fd411aace25$var$capitalize(partialNode.type)}> is supported.`);
|
|
144
|
+
if (partialNode.type && node.type !== partialNode.type) throw new Error(`Unsupported type <${$51588fd411aace25$var$capitalize(node.type)}> in <${$51588fd411aace25$var$capitalize((_parentNode_type = parentNode === null || parentNode === void 0 ? void 0 : parentNode.type) !== null && _parentNode_type !== void 0 ? _parentNode_type : 'unknown parent type')}>. Only <${$51588fd411aace25$var$capitalize(partialNode.type)}> is supported.`);
|
|
135
145
|
index++;
|
|
136
146
|
yield node;
|
|
137
147
|
}
|
|
@@ -140,25 +150,26 @@ class $51588fd411aace25$export$bf788dd355e3a401 {
|
|
|
140
150
|
return;
|
|
141
151
|
}
|
|
142
152
|
// Ignore invalid elements
|
|
143
|
-
if (partialNode.key == null) return;
|
|
153
|
+
if (partialNode.key == null || partialNode.type == null) return;
|
|
144
154
|
// Create full node
|
|
145
155
|
let builder = this;
|
|
156
|
+
var _partialNode_value, _partialNode_textValue;
|
|
146
157
|
let node = {
|
|
147
158
|
type: partialNode.type,
|
|
148
159
|
props: partialNode.props,
|
|
149
160
|
key: partialNode.key,
|
|
150
161
|
parentKey: parentNode ? parentNode.key : null,
|
|
151
|
-
value: partialNode.value,
|
|
162
|
+
value: (_partialNode_value = partialNode.value) !== null && _partialNode_value !== void 0 ? _partialNode_value : null,
|
|
152
163
|
level: parentNode ? parentNode.level + 1 : 0,
|
|
153
164
|
index: partialNode.index,
|
|
154
165
|
rendered: partialNode.rendered,
|
|
155
|
-
textValue: partialNode.textValue,
|
|
166
|
+
textValue: (_partialNode_textValue = partialNode.textValue) !== null && _partialNode_textValue !== void 0 ? _partialNode_textValue : '',
|
|
156
167
|
'aria-label': partialNode['aria-label'],
|
|
157
168
|
wrapper: partialNode.wrapper,
|
|
158
169
|
shouldInvalidate: partialNode.shouldInvalidate,
|
|
159
|
-
hasChildNodes: partialNode.hasChildNodes,
|
|
170
|
+
hasChildNodes: partialNode.hasChildNodes || false,
|
|
160
171
|
childNodes: $51588fd411aace25$var$iterable(function*() {
|
|
161
|
-
if (!partialNode.hasChildNodes) return;
|
|
172
|
+
if (!partialNode.hasChildNodes || !partialNode.childNodes) return;
|
|
162
173
|
let index = 0;
|
|
163
174
|
for (let child of partialNode.childNodes()){
|
|
164
175
|
// Ensure child keys are globally unique by prepending the parent node's key
|
|
@@ -167,8 +178,10 @@ class $51588fd411aace25$export$bf788dd355e3a401 {
|
|
|
167
178
|
// but another parent has key `ab` and its child has a key `c`. The combined keys would result in both
|
|
168
179
|
// children having a key of `abc`.
|
|
169
180
|
child.key = `${node.key}${child.key}`;
|
|
170
|
-
|
|
171
|
-
|
|
181
|
+
let nodes = builder.getFullNode({
|
|
182
|
+
...child,
|
|
183
|
+
index: index
|
|
184
|
+
}, builder.getChildState(state, child), node.key, node);
|
|
172
185
|
for (let node of nodes){
|
|
173
186
|
index++;
|
|
174
187
|
yield node;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;AAUM,MAAM;IAIX,MAAM,KAAwB,EAAE,OAAiB,EAAE;QACjD,IAAI,CAAC,OAAO,GAAG;QACf,OAAO,+BAAS,IAAM,IAAI,CAAC,iBAAiB,CAAC;IAC/C;IAEA,CAAS,kBAAkB,KAAwB,EAAsB;QACvE,IAAI,YAAC,QAAQ,SAAE,KAAK,EAAC,GAAG;QAExB,IAAI,CAAA,GAAA,sCAAI,EAAE,cAAc,CAAmC,aAAa,SAAS,IAAI,KAAK,CAAA,GAAA,sCAAI,EAAE,QAAQ,EACtG,OAAO,IAAI,CAAC,iBAAiB,CAAC;YAC5B,UAAU,SAAS,KAAK,CAAC,QAAQ;mBACjC;QACF;aACK,IAAI,OAAO,aAAa,YAAY;YACzC,IAAI,CAAC,OACH,MAAM,IAAI,MAAM;YAGlB,KAAK,IAAI,QAAQ,MAAM,KAAK,CAC1B,OAAO,IAAI,CAAC,WAAW,CAAC;gBACtB,OAAO;YACT,GAAG;gBAAC,UAAU;YAAQ;QAE1B,OAAO;YACL,IAAI,QAAgC,EAAE;YACtC,CAAA,GAAA,sCAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAA;gBAC/B,MAAM,IAAI,CAAC;YACb;YAEA,IAAI,QAAQ;YACZ,KAAK,IAAI,QAAQ,MAAO;gBACtB,IAAI,QAAQ,IA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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\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: CollectionBase<T>, context?: unknown) {\n this.context = context;\n return iterable(() => this.iterateCollection(props));\n }\n\n private *iterateCollection(props: 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 for (let item of props.items) {\n yield* this.getFullNode({\n value: item\n }, {renderer: children});\n }\n } else {\n let items: CollectionElement<T>[] = [];\n React.Children.forEach(children, child => {\n items.push(child);\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: CollectionElement<T>, partialNode: PartialNode<T>, state: CollectionBuilderState, parentKey?: Key): 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>, state: CollectionBuilderState, parentKey?: Key, 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;\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 any;\n if (typeof type !== 'function' && typeof type.getCollectionNode !== 'function') {\n let name = typeof element.type === 'function' ? element.type.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;\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;\n if (!nodeKey) {\n nodeKey = childNode.element ? null : this.getKey(element as 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;\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)}>. 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) {\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,\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,\n childNodes: iterable(function *() {\n if (!partialNode.hasChildNodes) {\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 child.index = index;\n let nodes = builder.getFullNode(child, 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 = [];\n let iterable = 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 {\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.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;AAcM,MAAM;IAIX,MAAM,KAAiC,EAAE,OAAiB,EAAE;QAC1D,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,sCAAI,EAAE,cAAc,CAAmC,aAAa,SAAS,IAAI,KAAK,CAAA,GAAA,sCAAI,EAAE,QAAQ,EACtG,OAAO,IAAI,CAAC,iBAAiB,CAAC;YAC5B,UAAU,SAAS,KAAK,CAAC,QAAQ;mBACjC;QACF;aACK,IAAI,OAAO,aAAa,YAAY;YACzC,IAAI,CAAC,OACH,MAAM,IAAI,MAAM;YAGlB,IAAI,QAAQ;YACZ,KAAK,IAAI,QAAQ,MAAO;gBACtB,OAAO,IAAI,CAAC,WAAW,CAAC;oBACtB,OAAO;2BACP;gBACF,GAAG;oBAAC,UAAU;gBAAQ;gBACtB;YACF;QACF,OAAO;YACL,IAAI,QAAgC,EAAE;YACtC,CAAA,GAAA,sCAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAA;gBAC/B,IAAI,OACF,MAAM,IAAI,CAAC;YAEf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;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) {\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.main.js.map"}
|
|
@@ -24,15 +24,20 @@ class $eb2240fc39a57fa5$export$bf788dd355e3a401 {
|
|
|
24
24
|
});
|
|
25
25
|
else if (typeof children === 'function') {
|
|
26
26
|
if (!items) throw new Error('props.children was a function but props.items is missing');
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
+
}
|
|
32
37
|
} else {
|
|
33
38
|
let items = [];
|
|
34
39
|
(0, $fzaAv$react).Children.forEach(children, (child)=>{
|
|
35
|
-
items.push(child);
|
|
40
|
+
if (child) items.push(child);
|
|
36
41
|
});
|
|
37
42
|
let index = 0;
|
|
38
43
|
for (let item of items){
|
|
@@ -70,7 +75,8 @@ class $eb2240fc39a57fa5$export$bf788dd355e3a401 {
|
|
|
70
75
|
(0, $fzaAv$react).Children.forEach(partialNode.element.props.children, (child)=>{
|
|
71
76
|
children.push(child);
|
|
72
77
|
});
|
|
73
|
-
|
|
78
|
+
var _partialNode_index;
|
|
79
|
+
let index = (_partialNode_index = partialNode.index) !== null && _partialNode_index !== void 0 ? _partialNode_index : 0;
|
|
74
80
|
for (const child of children)yield* this.getFullNode({
|
|
75
81
|
element: child,
|
|
76
82
|
index: index++
|
|
@@ -95,17 +101,19 @@ class $eb2240fc39a57fa5$export$bf788dd355e3a401 {
|
|
|
95
101
|
if ((0, $fzaAv$react).isValidElement(element)) {
|
|
96
102
|
let type = element.type;
|
|
97
103
|
if (typeof type !== 'function' && typeof type.getCollectionNode !== 'function') {
|
|
98
|
-
let name =
|
|
104
|
+
let name = element.type;
|
|
99
105
|
throw new Error(`Unknown element <${name}> in collection.`);
|
|
100
106
|
}
|
|
101
107
|
let childNodes = type.getCollectionNode(element.props, this.context);
|
|
102
|
-
|
|
108
|
+
var _partialNode_index1;
|
|
109
|
+
let index = (_partialNode_index1 = partialNode.index) !== null && _partialNode_index1 !== void 0 ? _partialNode_index1 : 0;
|
|
103
110
|
let result = childNodes.next();
|
|
104
111
|
while(!result.done && result.value){
|
|
105
112
|
let childNode = result.value;
|
|
106
113
|
partialNode.index = index;
|
|
107
|
-
|
|
108
|
-
|
|
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);
|
|
109
117
|
let nodes = this.getFullNode({
|
|
110
118
|
...childNode,
|
|
111
119
|
key: nodeKey,
|
|
@@ -116,12 +124,14 @@ class $eb2240fc39a57fa5$export$bf788dd355e3a401 {
|
|
|
116
124
|
...nodes
|
|
117
125
|
];
|
|
118
126
|
for (let node of children){
|
|
127
|
+
var _childNode_value, _ref;
|
|
119
128
|
// Cache the node based on its value
|
|
120
|
-
node.value = childNode.value
|
|
129
|
+
node.value = (_ref = (_childNode_value = childNode.value) !== null && _childNode_value !== void 0 ? _childNode_value : partialNode.value) !== null && _ref !== void 0 ? _ref : null;
|
|
121
130
|
if (node.value) this.cache.set(node.value, node);
|
|
131
|
+
var _parentNode_type;
|
|
122
132
|
// The partial node may have specified a type for the child in order to specify a constraint.
|
|
123
133
|
// Verify that the full node that was built recursively matches this type.
|
|
124
|
-
if (partialNode.type && node.type !== partialNode.type) throw new Error(`Unsupported type <${$eb2240fc39a57fa5$var$capitalize(node.type)}> in <${$eb2240fc39a57fa5$var$capitalize(parentNode.type)}>. Only <${$eb2240fc39a57fa5$var$capitalize(partialNode.type)}> is supported.`);
|
|
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.`);
|
|
125
135
|
index++;
|
|
126
136
|
yield node;
|
|
127
137
|
}
|
|
@@ -130,25 +140,26 @@ class $eb2240fc39a57fa5$export$bf788dd355e3a401 {
|
|
|
130
140
|
return;
|
|
131
141
|
}
|
|
132
142
|
// Ignore invalid elements
|
|
133
|
-
if (partialNode.key == null) return;
|
|
143
|
+
if (partialNode.key == null || partialNode.type == null) return;
|
|
134
144
|
// Create full node
|
|
135
145
|
let builder = this;
|
|
146
|
+
var _partialNode_value, _partialNode_textValue;
|
|
136
147
|
let node = {
|
|
137
148
|
type: partialNode.type,
|
|
138
149
|
props: partialNode.props,
|
|
139
150
|
key: partialNode.key,
|
|
140
151
|
parentKey: parentNode ? parentNode.key : null,
|
|
141
|
-
value: partialNode.value,
|
|
152
|
+
value: (_partialNode_value = partialNode.value) !== null && _partialNode_value !== void 0 ? _partialNode_value : null,
|
|
142
153
|
level: parentNode ? parentNode.level + 1 : 0,
|
|
143
154
|
index: partialNode.index,
|
|
144
155
|
rendered: partialNode.rendered,
|
|
145
|
-
textValue: partialNode.textValue,
|
|
156
|
+
textValue: (_partialNode_textValue = partialNode.textValue) !== null && _partialNode_textValue !== void 0 ? _partialNode_textValue : '',
|
|
146
157
|
'aria-label': partialNode['aria-label'],
|
|
147
158
|
wrapper: partialNode.wrapper,
|
|
148
159
|
shouldInvalidate: partialNode.shouldInvalidate,
|
|
149
|
-
hasChildNodes: partialNode.hasChildNodes,
|
|
160
|
+
hasChildNodes: partialNode.hasChildNodes || false,
|
|
150
161
|
childNodes: $eb2240fc39a57fa5$var$iterable(function*() {
|
|
151
|
-
if (!partialNode.hasChildNodes) return;
|
|
162
|
+
if (!partialNode.hasChildNodes || !partialNode.childNodes) return;
|
|
152
163
|
let index = 0;
|
|
153
164
|
for (let child of partialNode.childNodes()){
|
|
154
165
|
// Ensure child keys are globally unique by prepending the parent node's key
|
|
@@ -157,8 +168,10 @@ class $eb2240fc39a57fa5$export$bf788dd355e3a401 {
|
|
|
157
168
|
// but another parent has key `ab` and its child has a key `c`. The combined keys would result in both
|
|
158
169
|
// children having a key of `abc`.
|
|
159
170
|
child.key = `${node.key}${child.key}`;
|
|
160
|
-
|
|
161
|
-
|
|
171
|
+
let nodes = builder.getFullNode({
|
|
172
|
+
...child,
|
|
173
|
+
index: index
|
|
174
|
+
}, builder.getChildState(state, child), node.key, node);
|
|
162
175
|
for (let node of nodes){
|
|
163
176
|
index++;
|
|
164
177
|
yield node;
|
|
@@ -24,15 +24,20 @@ class $eb2240fc39a57fa5$export$bf788dd355e3a401 {
|
|
|
24
24
|
});
|
|
25
25
|
else if (typeof children === 'function') {
|
|
26
26
|
if (!items) throw new Error('props.children was a function but props.items is missing');
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
+
}
|
|
32
37
|
} else {
|
|
33
38
|
let items = [];
|
|
34
39
|
(0, $fzaAv$react).Children.forEach(children, (child)=>{
|
|
35
|
-
items.push(child);
|
|
40
|
+
if (child) items.push(child);
|
|
36
41
|
});
|
|
37
42
|
let index = 0;
|
|
38
43
|
for (let item of items){
|
|
@@ -70,7 +75,8 @@ class $eb2240fc39a57fa5$export$bf788dd355e3a401 {
|
|
|
70
75
|
(0, $fzaAv$react).Children.forEach(partialNode.element.props.children, (child)=>{
|
|
71
76
|
children.push(child);
|
|
72
77
|
});
|
|
73
|
-
|
|
78
|
+
var _partialNode_index;
|
|
79
|
+
let index = (_partialNode_index = partialNode.index) !== null && _partialNode_index !== void 0 ? _partialNode_index : 0;
|
|
74
80
|
for (const child of children)yield* this.getFullNode({
|
|
75
81
|
element: child,
|
|
76
82
|
index: index++
|
|
@@ -95,17 +101,19 @@ class $eb2240fc39a57fa5$export$bf788dd355e3a401 {
|
|
|
95
101
|
if ((0, $fzaAv$react).isValidElement(element)) {
|
|
96
102
|
let type = element.type;
|
|
97
103
|
if (typeof type !== 'function' && typeof type.getCollectionNode !== 'function') {
|
|
98
|
-
let name =
|
|
104
|
+
let name = element.type;
|
|
99
105
|
throw new Error(`Unknown element <${name}> in collection.`);
|
|
100
106
|
}
|
|
101
107
|
let childNodes = type.getCollectionNode(element.props, this.context);
|
|
102
|
-
|
|
108
|
+
var _partialNode_index1;
|
|
109
|
+
let index = (_partialNode_index1 = partialNode.index) !== null && _partialNode_index1 !== void 0 ? _partialNode_index1 : 0;
|
|
103
110
|
let result = childNodes.next();
|
|
104
111
|
while(!result.done && result.value){
|
|
105
112
|
let childNode = result.value;
|
|
106
113
|
partialNode.index = index;
|
|
107
|
-
|
|
108
|
-
|
|
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);
|
|
109
117
|
let nodes = this.getFullNode({
|
|
110
118
|
...childNode,
|
|
111
119
|
key: nodeKey,
|
|
@@ -116,12 +124,14 @@ class $eb2240fc39a57fa5$export$bf788dd355e3a401 {
|
|
|
116
124
|
...nodes
|
|
117
125
|
];
|
|
118
126
|
for (let node of children){
|
|
127
|
+
var _childNode_value, _ref;
|
|
119
128
|
// Cache the node based on its value
|
|
120
|
-
node.value = childNode.value
|
|
129
|
+
node.value = (_ref = (_childNode_value = childNode.value) !== null && _childNode_value !== void 0 ? _childNode_value : partialNode.value) !== null && _ref !== void 0 ? _ref : null;
|
|
121
130
|
if (node.value) this.cache.set(node.value, node);
|
|
131
|
+
var _parentNode_type;
|
|
122
132
|
// The partial node may have specified a type for the child in order to specify a constraint.
|
|
123
133
|
// Verify that the full node that was built recursively matches this type.
|
|
124
|
-
if (partialNode.type && node.type !== partialNode.type) throw new Error(`Unsupported type <${$eb2240fc39a57fa5$var$capitalize(node.type)}> in <${$eb2240fc39a57fa5$var$capitalize(parentNode.type)}>. Only <${$eb2240fc39a57fa5$var$capitalize(partialNode.type)}> is supported.`);
|
|
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.`);
|
|
125
135
|
index++;
|
|
126
136
|
yield node;
|
|
127
137
|
}
|
|
@@ -130,25 +140,26 @@ class $eb2240fc39a57fa5$export$bf788dd355e3a401 {
|
|
|
130
140
|
return;
|
|
131
141
|
}
|
|
132
142
|
// Ignore invalid elements
|
|
133
|
-
if (partialNode.key == null) return;
|
|
143
|
+
if (partialNode.key == null || partialNode.type == null) return;
|
|
134
144
|
// Create full node
|
|
135
145
|
let builder = this;
|
|
146
|
+
var _partialNode_value, _partialNode_textValue;
|
|
136
147
|
let node = {
|
|
137
148
|
type: partialNode.type,
|
|
138
149
|
props: partialNode.props,
|
|
139
150
|
key: partialNode.key,
|
|
140
151
|
parentKey: parentNode ? parentNode.key : null,
|
|
141
|
-
value: partialNode.value,
|
|
152
|
+
value: (_partialNode_value = partialNode.value) !== null && _partialNode_value !== void 0 ? _partialNode_value : null,
|
|
142
153
|
level: parentNode ? parentNode.level + 1 : 0,
|
|
143
154
|
index: partialNode.index,
|
|
144
155
|
rendered: partialNode.rendered,
|
|
145
|
-
textValue: partialNode.textValue,
|
|
156
|
+
textValue: (_partialNode_textValue = partialNode.textValue) !== null && _partialNode_textValue !== void 0 ? _partialNode_textValue : '',
|
|
146
157
|
'aria-label': partialNode['aria-label'],
|
|
147
158
|
wrapper: partialNode.wrapper,
|
|
148
159
|
shouldInvalidate: partialNode.shouldInvalidate,
|
|
149
|
-
hasChildNodes: partialNode.hasChildNodes,
|
|
160
|
+
hasChildNodes: partialNode.hasChildNodes || false,
|
|
150
161
|
childNodes: $eb2240fc39a57fa5$var$iterable(function*() {
|
|
151
|
-
if (!partialNode.hasChildNodes) return;
|
|
162
|
+
if (!partialNode.hasChildNodes || !partialNode.childNodes) return;
|
|
152
163
|
let index = 0;
|
|
153
164
|
for (let child of partialNode.childNodes()){
|
|
154
165
|
// Ensure child keys are globally unique by prepending the parent node's key
|
|
@@ -157,8 +168,10 @@ class $eb2240fc39a57fa5$export$bf788dd355e3a401 {
|
|
|
157
168
|
// but another parent has key `ab` and its child has a key `c`. The combined keys would result in both
|
|
158
169
|
// children having a key of `abc`.
|
|
159
170
|
child.key = `${node.key}${child.key}`;
|
|
160
|
-
|
|
161
|
-
|
|
171
|
+
let nodes = builder.getFullNode({
|
|
172
|
+
...child,
|
|
173
|
+
index: index
|
|
174
|
+
}, builder.getChildState(state, child), node.key, node);
|
|
162
175
|
for (let node of nodes){
|
|
163
176
|
index++;
|
|
164
177
|
yield node;
|