@react-stately/collections 3.10.5 → 3.10.6

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.
@@ -0,0 +1,194 @@
1
+ var $ioO2y$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, "CollectionBuilder", () => $51588fd411aace25$export$bf788dd355e3a401);
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
+ class $51588fd411aace25$export$bf788dd355e3a401 {
25
+ build(props, context) {
26
+ this.context = context;
27
+ return $51588fd411aace25$var$iterable(()=>this.iterateCollection(props));
28
+ }
29
+ *iterateCollection(props) {
30
+ let { children: children, items: items } = props;
31
+ if (typeof children === "function") {
32
+ if (!items) throw new Error("props.children was a function but props.items is missing");
33
+ for (let item of props.items)yield* this.getFullNode({
34
+ value: item
35
+ }, {
36
+ renderer: children
37
+ });
38
+ } else {
39
+ let items = [];
40
+ (0, ($parcel$interopDefault($ioO2y$react))).Children.forEach(children, (child)=>{
41
+ items.push(child);
42
+ });
43
+ let index = 0;
44
+ for (let item of items){
45
+ let nodes = this.getFullNode({
46
+ element: item,
47
+ index: index
48
+ }, {});
49
+ for (let node of nodes){
50
+ index++;
51
+ yield node;
52
+ }
53
+ }
54
+ }
55
+ }
56
+ getKey(item, partialNode, state, parentKey) {
57
+ if (item.key != null) return item.key;
58
+ if (partialNode.type === "cell" && partialNode.key != null) return `${parentKey}${partialNode.key}`;
59
+ let v = partialNode.value;
60
+ if (v != null) {
61
+ var _v_key;
62
+ let key = (_v_key = v.key) !== null && _v_key !== void 0 ? _v_key : v.id;
63
+ if (key == null) throw new Error("No key found for item");
64
+ return key;
65
+ }
66
+ return parentKey ? `${parentKey}.${partialNode.index}` : `$.${partialNode.index}`;
67
+ }
68
+ getChildState(state, partialNode) {
69
+ return {
70
+ renderer: partialNode.renderer || state.renderer
71
+ };
72
+ }
73
+ *getFullNode(partialNode, state, parentKey, parentNode) {
74
+ // If there's a value instead of an element on the node, and a parent renderer function is available,
75
+ // use it to render an element for the value.
76
+ let element = partialNode.element;
77
+ if (!element && partialNode.value && state && state.renderer) {
78
+ let cached = this.cache.get(partialNode.value);
79
+ if (cached && (!cached.shouldInvalidate || !cached.shouldInvalidate(this.context))) {
80
+ cached.index = partialNode.index;
81
+ cached.parentKey = parentNode ? parentNode.key : null;
82
+ yield cached;
83
+ return;
84
+ }
85
+ element = state.renderer(partialNode.value);
86
+ }
87
+ // If there's an element with a getCollectionNode function on its type, then it's a supported component.
88
+ // Call this function to get a partial node, and recursively build a full node from there.
89
+ if ((0, ($parcel$interopDefault($ioO2y$react))).isValidElement(element)) {
90
+ let type = element.type;
91
+ if (typeof type !== "function" && typeof type.getCollectionNode !== "function") {
92
+ let name = typeof element.type === "function" ? element.type.name : element.type;
93
+ throw new Error(`Unknown element <${name}> in collection.`);
94
+ }
95
+ let childNodes = type.getCollectionNode(element.props, this.context);
96
+ let index = partialNode.index;
97
+ let result = childNodes.next();
98
+ while(!result.done && result.value){
99
+ let childNode = result.value;
100
+ partialNode.index = index;
101
+ let nodeKey = childNode.key;
102
+ if (!nodeKey) nodeKey = childNode.element ? null : this.getKey(element, partialNode, state, parentKey);
103
+ let nodes = this.getFullNode({
104
+ ...childNode,
105
+ key: nodeKey,
106
+ index: index,
107
+ wrapper: $51588fd411aace25$var$compose(partialNode.wrapper, childNode.wrapper)
108
+ }, this.getChildState(state, childNode), parentKey ? `${parentKey}${element.key}` : element.key, parentNode);
109
+ let children = [
110
+ ...nodes
111
+ ];
112
+ for (let node of children){
113
+ // Cache the node based on its value
114
+ node.value = childNode.value || partialNode.value;
115
+ if (node.value) this.cache.set(node.value, node);
116
+ // The partial node may have specified a type for the child in order to specify a constraint.
117
+ // Verify that the full node that was built recursively matches this type.
118
+ 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.`);
119
+ index++;
120
+ yield node;
121
+ }
122
+ result = childNodes.next(children);
123
+ }
124
+ return;
125
+ }
126
+ // Ignore invalid elements
127
+ if (partialNode.key == null) return;
128
+ // Create full node
129
+ let builder = this;
130
+ let node = {
131
+ type: partialNode.type,
132
+ props: partialNode.props,
133
+ key: partialNode.key,
134
+ parentKey: parentNode ? parentNode.key : null,
135
+ value: partialNode.value,
136
+ level: parentNode ? parentNode.level + 1 : 0,
137
+ index: partialNode.index,
138
+ rendered: partialNode.rendered,
139
+ textValue: partialNode.textValue,
140
+ "aria-label": partialNode["aria-label"],
141
+ wrapper: partialNode.wrapper,
142
+ shouldInvalidate: partialNode.shouldInvalidate,
143
+ hasChildNodes: partialNode.hasChildNodes,
144
+ childNodes: $51588fd411aace25$var$iterable(function*() {
145
+ if (!partialNode.hasChildNodes) return;
146
+ let index = 0;
147
+ for (let child of partialNode.childNodes()){
148
+ // Ensure child keys are globally unique by prepending the parent node's key
149
+ if (child.key != null) // TODO: Remove this line entirely and enforce that users always provide unique keys.
150
+ // Currently this line will have issues when a parent has a key `a` and a child with key `bc`
151
+ // but another parent has key `ab` and its child has a key `c`. The combined keys would result in both
152
+ // children having a key of `abc`.
153
+ child.key = `${node.key}${child.key}`;
154
+ child.index = index;
155
+ let nodes = builder.getFullNode(child, builder.getChildState(state, child), node.key, node);
156
+ for (let node of nodes){
157
+ index++;
158
+ yield node;
159
+ }
160
+ }
161
+ })
162
+ };
163
+ yield node;
164
+ }
165
+ constructor(){
166
+ this.cache = new WeakMap();
167
+ }
168
+ }
169
+ // Wraps an iterator function as an iterable object, and caches the results.
170
+ function $51588fd411aace25$var$iterable(iterator) {
171
+ let cache = [];
172
+ let iterable = null;
173
+ return {
174
+ *[Symbol.iterator] () {
175
+ for (let item of cache)yield item;
176
+ if (!iterable) iterable = iterator();
177
+ for (let item of iterable){
178
+ cache.push(item);
179
+ yield item;
180
+ }
181
+ }
182
+ };
183
+ }
184
+ function $51588fd411aace25$var$compose(outer, inner) {
185
+ if (outer && inner) return (element)=>outer(inner(element));
186
+ if (outer) return outer;
187
+ if (inner) return inner;
188
+ }
189
+ function $51588fd411aace25$var$capitalize(str) {
190
+ return str[0].toUpperCase() + str.slice(1);
191
+ }
192
+
193
+
194
+ //# sourceMappingURL=CollectionBuilder.main.js.map
@@ -0,0 +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,EAAE;QACnD,IAAI,YAAC,QAAQ,SAAE,KAAK,EAAC,GAAG;QAExB,IAAI,OAAO,aAAa,YAAY;YAClC,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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AC,EAAE,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC;oBAGvC,MAAM,KAAK,GAAG;oBACd,IAAI,QAAQ,QAAQ,WAAW,CAAC,OAAO,QAAQ,aAAa,CAAC,OAAO,QAAQ,KAAK,GAAG,EAAE;oBACtF,KAAK,IAAI,QAAQ,MAAO;wBACtB;wBACA,MAAM;oBACR;gBACF;YACF;QACF;QAEA,MAAM;IACR;;aA1LQ,QAA6B,IAAI;;AA2L3C;AAEA,4EAA4E;AAC5E,SAAS,+BAAY,QAAyC;IAC5D,IAAI,QAAQ,EAAE;IACd,IAAI,WAAW;IACf,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\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>) {\n let {children, items} = props;\n\n 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 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"}
@@ -0,0 +1,185 @@
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 (typeof children === "function") {
22
+ if (!items) throw new Error("props.children was a function but props.items is missing");
23
+ for (let item of props.items)yield* this.getFullNode({
24
+ value: item
25
+ }, {
26
+ renderer: children
27
+ });
28
+ } else {
29
+ let items = [];
30
+ (0, $fzaAv$react).Children.forEach(children, (child)=>{
31
+ items.push(child);
32
+ });
33
+ let index = 0;
34
+ for (let item of items){
35
+ let nodes = this.getFullNode({
36
+ element: item,
37
+ index: index
38
+ }, {});
39
+ for (let node of nodes){
40
+ index++;
41
+ yield node;
42
+ }
43
+ }
44
+ }
45
+ }
46
+ getKey(item, partialNode, state, parentKey) {
47
+ if (item.key != null) return item.key;
48
+ if (partialNode.type === "cell" && partialNode.key != null) return `${parentKey}${partialNode.key}`;
49
+ let v = partialNode.value;
50
+ if (v != null) {
51
+ var _v_key;
52
+ let key = (_v_key = v.key) !== null && _v_key !== void 0 ? _v_key : v.id;
53
+ if (key == null) throw new Error("No key found for item");
54
+ return key;
55
+ }
56
+ return parentKey ? `${parentKey}.${partialNode.index}` : `$.${partialNode.index}`;
57
+ }
58
+ getChildState(state, partialNode) {
59
+ return {
60
+ renderer: partialNode.renderer || state.renderer
61
+ };
62
+ }
63
+ *getFullNode(partialNode, state, parentKey, parentNode) {
64
+ // If there's a value instead of an element on the node, and a parent renderer function is available,
65
+ // use it to render an element for the value.
66
+ let element = partialNode.element;
67
+ if (!element && partialNode.value && state && state.renderer) {
68
+ let cached = this.cache.get(partialNode.value);
69
+ if (cached && (!cached.shouldInvalidate || !cached.shouldInvalidate(this.context))) {
70
+ cached.index = partialNode.index;
71
+ cached.parentKey = parentNode ? parentNode.key : null;
72
+ yield cached;
73
+ return;
74
+ }
75
+ element = state.renderer(partialNode.value);
76
+ }
77
+ // If there's an element with a getCollectionNode function on its type, then it's a supported component.
78
+ // Call this function to get a partial node, and recursively build a full node from there.
79
+ if ((0, $fzaAv$react).isValidElement(element)) {
80
+ let type = element.type;
81
+ if (typeof type !== "function" && typeof type.getCollectionNode !== "function") {
82
+ let name = typeof element.type === "function" ? element.type.name : element.type;
83
+ throw new Error(`Unknown element <${name}> in collection.`);
84
+ }
85
+ let childNodes = type.getCollectionNode(element.props, this.context);
86
+ let index = partialNode.index;
87
+ let result = childNodes.next();
88
+ while(!result.done && result.value){
89
+ let childNode = result.value;
90
+ partialNode.index = index;
91
+ let nodeKey = childNode.key;
92
+ if (!nodeKey) nodeKey = childNode.element ? null : this.getKey(element, partialNode, state, parentKey);
93
+ let nodes = this.getFullNode({
94
+ ...childNode,
95
+ key: nodeKey,
96
+ index: index,
97
+ wrapper: $eb2240fc39a57fa5$var$compose(partialNode.wrapper, childNode.wrapper)
98
+ }, this.getChildState(state, childNode), parentKey ? `${parentKey}${element.key}` : element.key, parentNode);
99
+ let children = [
100
+ ...nodes
101
+ ];
102
+ for (let node of children){
103
+ // Cache the node based on its value
104
+ node.value = childNode.value || partialNode.value;
105
+ if (node.value) this.cache.set(node.value, node);
106
+ // The partial node may have specified a type for the child in order to specify a constraint.
107
+ // Verify that the full node that was built recursively matches this type.
108
+ 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.`);
109
+ index++;
110
+ yield node;
111
+ }
112
+ result = childNodes.next(children);
113
+ }
114
+ return;
115
+ }
116
+ // Ignore invalid elements
117
+ if (partialNode.key == null) return;
118
+ // Create full node
119
+ let builder = this;
120
+ let node = {
121
+ type: partialNode.type,
122
+ props: partialNode.props,
123
+ key: partialNode.key,
124
+ parentKey: parentNode ? parentNode.key : null,
125
+ value: partialNode.value,
126
+ level: parentNode ? parentNode.level + 1 : 0,
127
+ index: partialNode.index,
128
+ rendered: partialNode.rendered,
129
+ textValue: partialNode.textValue,
130
+ "aria-label": partialNode["aria-label"],
131
+ wrapper: partialNode.wrapper,
132
+ shouldInvalidate: partialNode.shouldInvalidate,
133
+ hasChildNodes: partialNode.hasChildNodes,
134
+ childNodes: $eb2240fc39a57fa5$var$iterable(function*() {
135
+ if (!partialNode.hasChildNodes) return;
136
+ let index = 0;
137
+ for (let child of partialNode.childNodes()){
138
+ // Ensure child keys are globally unique by prepending the parent node's key
139
+ if (child.key != null) // TODO: Remove this line entirely and enforce that users always provide unique keys.
140
+ // Currently this line will have issues when a parent has a key `a` and a child with key `bc`
141
+ // but another parent has key `ab` and its child has a key `c`. The combined keys would result in both
142
+ // children having a key of `abc`.
143
+ child.key = `${node.key}${child.key}`;
144
+ child.index = index;
145
+ let nodes = builder.getFullNode(child, builder.getChildState(state, child), node.key, node);
146
+ for (let node of nodes){
147
+ index++;
148
+ yield node;
149
+ }
150
+ }
151
+ })
152
+ };
153
+ yield node;
154
+ }
155
+ constructor(){
156
+ this.cache = new WeakMap();
157
+ }
158
+ }
159
+ // Wraps an iterator function as an iterable object, and caches the results.
160
+ function $eb2240fc39a57fa5$var$iterable(iterator) {
161
+ let cache = [];
162
+ let iterable = null;
163
+ return {
164
+ *[Symbol.iterator] () {
165
+ for (let item of cache)yield item;
166
+ if (!iterable) iterable = iterator();
167
+ for (let item of iterable){
168
+ cache.push(item);
169
+ yield item;
170
+ }
171
+ }
172
+ };
173
+ }
174
+ function $eb2240fc39a57fa5$var$compose(outer, inner) {
175
+ if (outer && inner) return (element)=>outer(inner(element));
176
+ if (outer) return outer;
177
+ if (inner) return inner;
178
+ }
179
+ function $eb2240fc39a57fa5$var$capitalize(str) {
180
+ return str[0].toUpperCase() + str.slice(1);
181
+ }
182
+
183
+
184
+ export {$eb2240fc39a57fa5$export$bf788dd355e3a401 as CollectionBuilder};
185
+ //# sourceMappingURL=CollectionBuilder.mjs.map
@@ -0,0 +1,185 @@
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 (typeof children === "function") {
22
+ if (!items) throw new Error("props.children was a function but props.items is missing");
23
+ for (let item of props.items)yield* this.getFullNode({
24
+ value: item
25
+ }, {
26
+ renderer: children
27
+ });
28
+ } else {
29
+ let items = [];
30
+ (0, $fzaAv$react).Children.forEach(children, (child)=>{
31
+ items.push(child);
32
+ });
33
+ let index = 0;
34
+ for (let item of items){
35
+ let nodes = this.getFullNode({
36
+ element: item,
37
+ index: index
38
+ }, {});
39
+ for (let node of nodes){
40
+ index++;
41
+ yield node;
42
+ }
43
+ }
44
+ }
45
+ }
46
+ getKey(item, partialNode, state, parentKey) {
47
+ if (item.key != null) return item.key;
48
+ if (partialNode.type === "cell" && partialNode.key != null) return `${parentKey}${partialNode.key}`;
49
+ let v = partialNode.value;
50
+ if (v != null) {
51
+ var _v_key;
52
+ let key = (_v_key = v.key) !== null && _v_key !== void 0 ? _v_key : v.id;
53
+ if (key == null) throw new Error("No key found for item");
54
+ return key;
55
+ }
56
+ return parentKey ? `${parentKey}.${partialNode.index}` : `$.${partialNode.index}`;
57
+ }
58
+ getChildState(state, partialNode) {
59
+ return {
60
+ renderer: partialNode.renderer || state.renderer
61
+ };
62
+ }
63
+ *getFullNode(partialNode, state, parentKey, parentNode) {
64
+ // If there's a value instead of an element on the node, and a parent renderer function is available,
65
+ // use it to render an element for the value.
66
+ let element = partialNode.element;
67
+ if (!element && partialNode.value && state && state.renderer) {
68
+ let cached = this.cache.get(partialNode.value);
69
+ if (cached && (!cached.shouldInvalidate || !cached.shouldInvalidate(this.context))) {
70
+ cached.index = partialNode.index;
71
+ cached.parentKey = parentNode ? parentNode.key : null;
72
+ yield cached;
73
+ return;
74
+ }
75
+ element = state.renderer(partialNode.value);
76
+ }
77
+ // If there's an element with a getCollectionNode function on its type, then it's a supported component.
78
+ // Call this function to get a partial node, and recursively build a full node from there.
79
+ if ((0, $fzaAv$react).isValidElement(element)) {
80
+ let type = element.type;
81
+ if (typeof type !== "function" && typeof type.getCollectionNode !== "function") {
82
+ let name = typeof element.type === "function" ? element.type.name : element.type;
83
+ throw new Error(`Unknown element <${name}> in collection.`);
84
+ }
85
+ let childNodes = type.getCollectionNode(element.props, this.context);
86
+ let index = partialNode.index;
87
+ let result = childNodes.next();
88
+ while(!result.done && result.value){
89
+ let childNode = result.value;
90
+ partialNode.index = index;
91
+ let nodeKey = childNode.key;
92
+ if (!nodeKey) nodeKey = childNode.element ? null : this.getKey(element, partialNode, state, parentKey);
93
+ let nodes = this.getFullNode({
94
+ ...childNode,
95
+ key: nodeKey,
96
+ index: index,
97
+ wrapper: $eb2240fc39a57fa5$var$compose(partialNode.wrapper, childNode.wrapper)
98
+ }, this.getChildState(state, childNode), parentKey ? `${parentKey}${element.key}` : element.key, parentNode);
99
+ let children = [
100
+ ...nodes
101
+ ];
102
+ for (let node of children){
103
+ // Cache the node based on its value
104
+ node.value = childNode.value || partialNode.value;
105
+ if (node.value) this.cache.set(node.value, node);
106
+ // The partial node may have specified a type for the child in order to specify a constraint.
107
+ // Verify that the full node that was built recursively matches this type.
108
+ 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.`);
109
+ index++;
110
+ yield node;
111
+ }
112
+ result = childNodes.next(children);
113
+ }
114
+ return;
115
+ }
116
+ // Ignore invalid elements
117
+ if (partialNode.key == null) return;
118
+ // Create full node
119
+ let builder = this;
120
+ let node = {
121
+ type: partialNode.type,
122
+ props: partialNode.props,
123
+ key: partialNode.key,
124
+ parentKey: parentNode ? parentNode.key : null,
125
+ value: partialNode.value,
126
+ level: parentNode ? parentNode.level + 1 : 0,
127
+ index: partialNode.index,
128
+ rendered: partialNode.rendered,
129
+ textValue: partialNode.textValue,
130
+ "aria-label": partialNode["aria-label"],
131
+ wrapper: partialNode.wrapper,
132
+ shouldInvalidate: partialNode.shouldInvalidate,
133
+ hasChildNodes: partialNode.hasChildNodes,
134
+ childNodes: $eb2240fc39a57fa5$var$iterable(function*() {
135
+ if (!partialNode.hasChildNodes) return;
136
+ let index = 0;
137
+ for (let child of partialNode.childNodes()){
138
+ // Ensure child keys are globally unique by prepending the parent node's key
139
+ if (child.key != null) // TODO: Remove this line entirely and enforce that users always provide unique keys.
140
+ // Currently this line will have issues when a parent has a key `a` and a child with key `bc`
141
+ // but another parent has key `ab` and its child has a key `c`. The combined keys would result in both
142
+ // children having a key of `abc`.
143
+ child.key = `${node.key}${child.key}`;
144
+ child.index = index;
145
+ let nodes = builder.getFullNode(child, builder.getChildState(state, child), node.key, node);
146
+ for (let node of nodes){
147
+ index++;
148
+ yield node;
149
+ }
150
+ }
151
+ })
152
+ };
153
+ yield node;
154
+ }
155
+ constructor(){
156
+ this.cache = new WeakMap();
157
+ }
158
+ }
159
+ // Wraps an iterator function as an iterable object, and caches the results.
160
+ function $eb2240fc39a57fa5$var$iterable(iterator) {
161
+ let cache = [];
162
+ let iterable = null;
163
+ return {
164
+ *[Symbol.iterator] () {
165
+ for (let item of cache)yield item;
166
+ if (!iterable) iterable = iterator();
167
+ for (let item of iterable){
168
+ cache.push(item);
169
+ yield item;
170
+ }
171
+ }
172
+ };
173
+ }
174
+ function $eb2240fc39a57fa5$var$compose(outer, inner) {
175
+ if (outer && inner) return (element)=>outer(inner(element));
176
+ if (outer) return outer;
177
+ if (inner) return inner;
178
+ }
179
+ function $eb2240fc39a57fa5$var$capitalize(str) {
180
+ return str[0].toUpperCase() + str.slice(1);
181
+ }
182
+
183
+
184
+ export {$eb2240fc39a57fa5$export$bf788dd355e3a401 as CollectionBuilder};
185
+ //# sourceMappingURL=CollectionBuilder.module.js.map
@@ -0,0 +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,EAAE;QACnD,IAAI,YAAC,QAAQ,SAAE,KAAK,EAAC,GAAG;QAExB,IAAI,OAAO,aAAa,YAAY;YAClC,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,YAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAA;gBAC/B,MAAM,IAAI,CAAC;YACb;YAEA,IAAI,QAAQ;YACZ,KAAK,IAAI,QAAQ,MAAO;gBACtB,IAAI,QAAQ,IAAI,CAAC,WAAW,CAAC;oBAC3B,SAAS;oBACT,OAAO;gBACT,GAAG,CAAC;gBAEJ,KAAK,IAAI,QAAQ,MAAO;oBACtB;oBACA,MAAM;gBACR;YACF;QACF;IACF;IAE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,MAAM;oBACR;gBACF;YACF;QACF;QAEA,MAAM;IACR;;aA1LQ,QAA6B,IAAI;;AA2L3C;AAEA,4EAA4E;AAC5E,SAAS,+BAAY,QAAyC;IAC5D,IAAI,QAAQ,EAAE;IACd,IAAI,WAAW;IACf,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\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>) {\n let {children, items} = props;\n\n 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 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.module.js.map"}