@react-stately/collections 3.12.10 → 3.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/import.mjs +7 -7
- package/dist/main.js +16 -16
- package/dist/main.js.map +1 -1
- package/dist/module.js +7 -7
- package/dist/module.js.map +1 -1
- package/dist/types/src/index.d.ts +7 -0
- package/package.json +17 -13
- package/src/index.ts +8 -7
- package/dist/CollectionBuilder.main.js +0 -223
- package/dist/CollectionBuilder.main.js.map +0 -1
- package/dist/CollectionBuilder.mjs +0 -214
- package/dist/CollectionBuilder.module.js +0 -214
- package/dist/CollectionBuilder.module.js.map +0 -1
- package/dist/Item.main.js +0 -68
- package/dist/Item.main.js.map +0 -1
- package/dist/Item.mjs +0 -59
- package/dist/Item.module.js +0 -59
- package/dist/Item.module.js.map +0 -1
- package/dist/Section.main.js +0 -60
- package/dist/Section.main.js.map +0 -1
- package/dist/Section.mjs +0 -51
- package/dist/Section.module.js +0 -51
- package/dist/Section.module.js.map +0 -1
- package/dist/getChildNodes.main.js +0 -81
- package/dist/getChildNodes.main.js.map +0 -1
- package/dist/getChildNodes.mjs +0 -72
- package/dist/getChildNodes.module.js +0 -72
- package/dist/getChildNodes.module.js.map +0 -1
- package/dist/getItemCount.main.js +0 -38
- package/dist/getItemCount.main.js.map +0 -1
- package/dist/getItemCount.mjs +0 -33
- package/dist/getItemCount.module.js +0 -33
- package/dist/getItemCount.module.js.map +0 -1
- package/dist/types.d.ts +0 -36
- package/dist/types.d.ts.map +0 -1
- package/dist/useCollection.main.js +0 -44
- package/dist/useCollection.main.js.map +0 -1
- package/dist/useCollection.mjs +0 -39
- package/dist/useCollection.module.js +0 -39
- package/dist/useCollection.module.js.map +0 -1
- package/src/CollectionBuilder.ts +0 -283
- package/src/Item.ts +0 -80
- package/src/Section.ts +0 -59
- package/src/getChildNodes.ts +0 -95
- package/src/getItemCount.ts +0 -39
- package/src/types.ts +0 -31
- package/src/useCollection.ts +0 -34
package/dist/import.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {Item as $
|
|
2
|
-
import {Section as $
|
|
3
|
-
import {useCollection as $
|
|
4
|
-
import {getItemCount as $
|
|
5
|
-
import {
|
|
6
|
-
import {CollectionBuilder as $
|
|
1
|
+
import {Item as $01b8880fa11acb83$re_export$Item} from "react-stately/Item";
|
|
2
|
+
import {Section as $01b8880fa11acb83$re_export$Section} from "react-stately/Section";
|
|
3
|
+
import {useCollection as $01b8880fa11acb83$re_export$useCollection} from "react-stately/private/collections/useCollection";
|
|
4
|
+
import {getItemCount as $01b8880fa11acb83$re_export$getItemCount} from "react-stately/private/collections/getItemCount";
|
|
5
|
+
import {getChildNodes as $01b8880fa11acb83$re_export$getChildNodes, getFirstItem as $01b8880fa11acb83$re_export$getFirstItem, getLastItem as $01b8880fa11acb83$re_export$getLastItem, getNthItem as $01b8880fa11acb83$re_export$getNthItem, compareNodeOrder as $01b8880fa11acb83$re_export$compareNodeOrder} from "react-stately/private/collections/getChildNodes";
|
|
6
|
+
import {CollectionBuilder as $01b8880fa11acb83$re_export$CollectionBuilder} from "react-stately/private/collections/CollectionBuilder";
|
|
7
7
|
|
|
8
8
|
/*
|
|
9
9
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -23,5 +23,5 @@ import {CollectionBuilder as $eb2240fc39a57fa5$export$bf788dd355e3a401} from "./
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
export {$
|
|
26
|
+
export {$01b8880fa11acb83$re_export$Item as Item, $01b8880fa11acb83$re_export$Section as Section, $01b8880fa11acb83$re_export$useCollection as useCollection, $01b8880fa11acb83$re_export$getItemCount as getItemCount, $01b8880fa11acb83$re_export$getChildNodes as getChildNodes, $01b8880fa11acb83$re_export$getFirstItem as getFirstItem, $01b8880fa11acb83$re_export$getLastItem as getLastItem, $01b8880fa11acb83$re_export$getNthItem as getNthItem, $01b8880fa11acb83$re_export$compareNodeOrder as compareNodeOrder, $01b8880fa11acb83$re_export$CollectionBuilder as CollectionBuilder};
|
|
27
27
|
//# sourceMappingURL=module.js.map
|
package/dist/main.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
var $
|
|
2
|
-
var $
|
|
3
|
-
var $
|
|
4
|
-
var $
|
|
5
|
-
var $
|
|
6
|
-
var $
|
|
1
|
+
var $dUhIo$reactstatelyItem = require("react-stately/Item");
|
|
2
|
+
var $dUhIo$reactstatelySection = require("react-stately/Section");
|
|
3
|
+
var $dUhIo$reactstatelyprivatecollectionsuseCollection = require("react-stately/private/collections/useCollection");
|
|
4
|
+
var $dUhIo$reactstatelyprivatecollectionsgetItemCount = require("react-stately/private/collections/getItemCount");
|
|
5
|
+
var $dUhIo$reactstatelyprivatecollectionsgetChildNodes = require("react-stately/private/collections/getChildNodes");
|
|
6
|
+
var $dUhIo$reactstatelyprivatecollectionsCollectionBuilder = require("react-stately/private/collections/CollectionBuilder");
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
function $parcel$export(e, n, v, s) {
|
|
10
10
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
$parcel$export(module.exports, "Item", ()
|
|
14
|
-
$parcel$export(module.exports, "Section", ()
|
|
15
|
-
$parcel$export(module.exports, "useCollection", ()
|
|
16
|
-
$parcel$export(module.exports, "getItemCount", ()
|
|
17
|
-
$parcel$export(module.exports, "getChildNodes", ()
|
|
18
|
-
$parcel$export(module.exports, "getFirstItem", ()
|
|
19
|
-
$parcel$export(module.exports, "getLastItem", ()
|
|
20
|
-
$parcel$export(module.exports, "getNthItem", ()
|
|
21
|
-
$parcel$export(module.exports, "compareNodeOrder", ()
|
|
22
|
-
$parcel$export(module.exports, "CollectionBuilder", ()
|
|
13
|
+
$parcel$export(module.exports, "Item", function () { return $dUhIo$reactstatelyItem.Item; });
|
|
14
|
+
$parcel$export(module.exports, "Section", function () { return $dUhIo$reactstatelySection.Section; });
|
|
15
|
+
$parcel$export(module.exports, "useCollection", function () { return $dUhIo$reactstatelyprivatecollectionsuseCollection.useCollection; });
|
|
16
|
+
$parcel$export(module.exports, "getItemCount", function () { return $dUhIo$reactstatelyprivatecollectionsgetItemCount.getItemCount; });
|
|
17
|
+
$parcel$export(module.exports, "getChildNodes", function () { return $dUhIo$reactstatelyprivatecollectionsgetChildNodes.getChildNodes; });
|
|
18
|
+
$parcel$export(module.exports, "getFirstItem", function () { return $dUhIo$reactstatelyprivatecollectionsgetChildNodes.getFirstItem; });
|
|
19
|
+
$parcel$export(module.exports, "getLastItem", function () { return $dUhIo$reactstatelyprivatecollectionsgetChildNodes.getLastItem; });
|
|
20
|
+
$parcel$export(module.exports, "getNthItem", function () { return $dUhIo$reactstatelyprivatecollectionsgetChildNodes.getNthItem; });
|
|
21
|
+
$parcel$export(module.exports, "compareNodeOrder", function () { return $dUhIo$reactstatelyprivatecollectionsgetChildNodes.compareNodeOrder; });
|
|
22
|
+
$parcel$export(module.exports, "CollectionBuilder", function () { return $dUhIo$reactstatelyprivatecollectionsCollectionBuilder.CollectionBuilder; });
|
|
23
23
|
/*
|
|
24
24
|
* Copyright 2020 Adobe. All rights reserved.
|
|
25
25
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/collections/src/index.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\nexport
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/collections/src/index.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\nexport {Item} from 'react-stately/Item';\n\nexport {Section} from 'react-stately/Section';\nexport {useCollection} from 'react-stately/private/collections/useCollection';\nexport {getItemCount} from 'react-stately/private/collections/getItemCount';\nexport {getChildNodes, getFirstItem, getLastItem, getNthItem, compareNodeOrder} from 'react-stately/private/collections/getChildNodes';\nexport {CollectionBuilder} from 'react-stately/private/collections/CollectionBuilder';\nexport type {PartialNode} from 'react-stately/private/collections/types';\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {Item as $
|
|
2
|
-
import {Section as $
|
|
3
|
-
import {useCollection as $
|
|
4
|
-
import {getItemCount as $
|
|
5
|
-
import {
|
|
6
|
-
import {CollectionBuilder as $
|
|
1
|
+
import {Item as $01b8880fa11acb83$re_export$Item} from "react-stately/Item";
|
|
2
|
+
import {Section as $01b8880fa11acb83$re_export$Section} from "react-stately/Section";
|
|
3
|
+
import {useCollection as $01b8880fa11acb83$re_export$useCollection} from "react-stately/private/collections/useCollection";
|
|
4
|
+
import {getItemCount as $01b8880fa11acb83$re_export$getItemCount} from "react-stately/private/collections/getItemCount";
|
|
5
|
+
import {getChildNodes as $01b8880fa11acb83$re_export$getChildNodes, getFirstItem as $01b8880fa11acb83$re_export$getFirstItem, getLastItem as $01b8880fa11acb83$re_export$getLastItem, getNthItem as $01b8880fa11acb83$re_export$getNthItem, compareNodeOrder as $01b8880fa11acb83$re_export$compareNodeOrder} from "react-stately/private/collections/getChildNodes";
|
|
6
|
+
import {CollectionBuilder as $01b8880fa11acb83$re_export$CollectionBuilder} from "react-stately/private/collections/CollectionBuilder";
|
|
7
7
|
|
|
8
8
|
/*
|
|
9
9
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -23,5 +23,5 @@ import {CollectionBuilder as $eb2240fc39a57fa5$export$bf788dd355e3a401} from "./
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
export {$
|
|
26
|
+
export {$01b8880fa11acb83$re_export$Item as Item, $01b8880fa11acb83$re_export$Section as Section, $01b8880fa11acb83$re_export$useCollection as useCollection, $01b8880fa11acb83$re_export$getItemCount as getItemCount, $01b8880fa11acb83$re_export$getChildNodes as getChildNodes, $01b8880fa11acb83$re_export$getFirstItem as getFirstItem, $01b8880fa11acb83$re_export$getLastItem as getLastItem, $01b8880fa11acb83$re_export$getNthItem as getNthItem, $01b8880fa11acb83$re_export$compareNodeOrder as compareNodeOrder, $01b8880fa11acb83$re_export$CollectionBuilder as CollectionBuilder};
|
|
27
27
|
//# sourceMappingURL=module.js.map
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/collections/src/index.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\nexport
|
|
1
|
+
{"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/collections/src/index.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\nexport {Item} from 'react-stately/Item';\n\nexport {Section} from 'react-stately/Section';\nexport {useCollection} from 'react-stately/private/collections/useCollection';\nexport {getItemCount} from 'react-stately/private/collections/getItemCount';\nexport {getChildNodes, getFirstItem, getLastItem, getNthItem, compareNodeOrder} from 'react-stately/private/collections/getChildNodes';\nexport {CollectionBuilder} from 'react-stately/private/collections/CollectionBuilder';\nexport type {PartialNode} from 'react-stately/private/collections/types';\n"],"names":[],"version":3,"file":"module.js.map"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Item } from 'react-stately/Item';
|
|
2
|
+
export { Section } from 'react-stately/Section';
|
|
3
|
+
export { useCollection } from 'react-stately/private/collections/useCollection';
|
|
4
|
+
export { getItemCount } from 'react-stately/private/collections/getItemCount';
|
|
5
|
+
export { getChildNodes, getFirstItem, getLastItem, getNthItem, compareNodeOrder } from 'react-stately/private/collections/getChildNodes';
|
|
6
|
+
export { CollectionBuilder } from 'react-stately/private/collections/CollectionBuilder';
|
|
7
|
+
export type { PartialNode } from 'react-stately/private/collections/types';
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/collections",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.13.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
7
7
|
"module": "dist/module.js",
|
|
8
8
|
"exports": {
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
"./dist/types.d.ts",
|
|
12
|
-
"./
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
9
|
+
".": {
|
|
10
|
+
"source": "./src/index.ts",
|
|
11
|
+
"types": "./dist/types/src/index.d.ts",
|
|
12
|
+
"import": "./dist/import.mjs",
|
|
13
|
+
"require": "./dist/main.js"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
16
|
},
|
|
17
|
-
"types": "dist/types.d.ts",
|
|
17
|
+
"types": "dist/types/src/index.d.ts",
|
|
18
18
|
"source": "src/index.ts",
|
|
19
19
|
"files": [
|
|
20
20
|
"dist",
|
|
@@ -26,14 +26,18 @@
|
|
|
26
26
|
"url": "https://github.com/adobe/react-spectrum"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@
|
|
30
|
-
"
|
|
29
|
+
"@swc/helpers": "^0.5.0",
|
|
30
|
+
"react-stately": "3.46.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
|
|
33
|
+
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
|
|
34
|
+
"react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
|
|
34
35
|
},
|
|
35
36
|
"publishConfig": {
|
|
36
37
|
"access": "public"
|
|
37
38
|
},
|
|
38
|
-
"
|
|
39
|
+
"targets": {
|
|
40
|
+
"types": false
|
|
41
|
+
},
|
|
42
|
+
"gitHead": "a6999bdf494a2e9c0381a5881908328bdd22ddae"
|
|
39
43
|
}
|
package/src/index.ts
CHANGED
|
@@ -10,10 +10,11 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
export {Section} from '
|
|
16
|
-
export {useCollection} from '
|
|
17
|
-
export {getItemCount} from '
|
|
18
|
-
export {getChildNodes, getFirstItem, getLastItem, getNthItem, compareNodeOrder} from '
|
|
19
|
-
export {CollectionBuilder} from '
|
|
13
|
+
export {Item} from 'react-stately/Item';
|
|
14
|
+
|
|
15
|
+
export {Section} from 'react-stately/Section';
|
|
16
|
+
export {useCollection} from 'react-stately/private/collections/useCollection';
|
|
17
|
+
export {getItemCount} from 'react-stately/private/collections/getItemCount';
|
|
18
|
+
export {getChildNodes, getFirstItem, getLastItem, getNthItem, compareNodeOrder} from 'react-stately/private/collections/getChildNodes';
|
|
19
|
+
export {CollectionBuilder} from 'react-stately/private/collections/CollectionBuilder';
|
|
20
|
+
export type {PartialNode} from 'react-stately/private/collections/types';
|
|
@@ -1,223 +0,0 @@
|
|
|
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 ((0, ($parcel$interopDefault($ioO2y$react))).isValidElement(children) && children.type === (0, ($parcel$interopDefault($ioO2y$react))).Fragment) yield* this.iterateCollection({
|
|
32
|
-
children: children.props.children,
|
|
33
|
-
items: items
|
|
34
|
-
});
|
|
35
|
-
else if (typeof children === 'function') {
|
|
36
|
-
if (!items) throw new Error('props.children was a function but props.items is missing');
|
|
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
|
-
}
|
|
47
|
-
} else {
|
|
48
|
-
let items = [];
|
|
49
|
-
(0, ($parcel$interopDefault($ioO2y$react))).Children.forEach(children, (child)=>{
|
|
50
|
-
if (child) items.push(child);
|
|
51
|
-
});
|
|
52
|
-
let index = 0;
|
|
53
|
-
for (let item of items){
|
|
54
|
-
let nodes = this.getFullNode({
|
|
55
|
-
element: item,
|
|
56
|
-
index: index
|
|
57
|
-
}, {});
|
|
58
|
-
for (let node of nodes){
|
|
59
|
-
index++;
|
|
60
|
-
yield node;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
getKey(item, partialNode, state, parentKey) {
|
|
66
|
-
if (item.key != null) return item.key;
|
|
67
|
-
if (partialNode.type === 'cell' && partialNode.key != null) return `${parentKey}${partialNode.key}`;
|
|
68
|
-
let v = partialNode.value;
|
|
69
|
-
if (v != null) {
|
|
70
|
-
var _v_key;
|
|
71
|
-
let key = (_v_key = v.key) !== null && _v_key !== void 0 ? _v_key : v.id;
|
|
72
|
-
if (key == null) throw new Error('No key found for item');
|
|
73
|
-
return key;
|
|
74
|
-
}
|
|
75
|
-
return parentKey ? `${parentKey}.${partialNode.index}` : `$.${partialNode.index}`;
|
|
76
|
-
}
|
|
77
|
-
getChildState(state, partialNode) {
|
|
78
|
-
return {
|
|
79
|
-
renderer: partialNode.renderer || state.renderer
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
*getFullNode(partialNode, state, parentKey, parentNode) {
|
|
83
|
-
if ((0, ($parcel$interopDefault($ioO2y$react))).isValidElement(partialNode.element) && partialNode.element.type === (0, ($parcel$interopDefault($ioO2y$react))).Fragment) {
|
|
84
|
-
let children = [];
|
|
85
|
-
(0, ($parcel$interopDefault($ioO2y$react))).Children.forEach(partialNode.element.props.children, (child)=>{
|
|
86
|
-
children.push(child);
|
|
87
|
-
});
|
|
88
|
-
var _partialNode_index;
|
|
89
|
-
let index = (_partialNode_index = partialNode.index) !== null && _partialNode_index !== void 0 ? _partialNode_index : 0;
|
|
90
|
-
for (const child of children)yield* this.getFullNode({
|
|
91
|
-
element: child,
|
|
92
|
-
index: index++
|
|
93
|
-
}, state, parentKey, parentNode);
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
// If there's a value instead of an element on the node, and a parent renderer function is available,
|
|
97
|
-
// use it to render an element for the value.
|
|
98
|
-
let element = partialNode.element;
|
|
99
|
-
if (!element && partialNode.value && state && state.renderer) {
|
|
100
|
-
let cached = this.cache.get(partialNode.value);
|
|
101
|
-
if (cached && (!cached.shouldInvalidate || !cached.shouldInvalidate(this.context))) {
|
|
102
|
-
cached.index = partialNode.index;
|
|
103
|
-
cached.parentKey = parentNode ? parentNode.key : null;
|
|
104
|
-
yield cached;
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
element = state.renderer(partialNode.value);
|
|
108
|
-
}
|
|
109
|
-
// If there's an element with a getCollectionNode function on its type, then it's a supported component.
|
|
110
|
-
// Call this function to get a partial node, and recursively build a full node from there.
|
|
111
|
-
if ((0, ($parcel$interopDefault($ioO2y$react))).isValidElement(element)) {
|
|
112
|
-
let type = element.type;
|
|
113
|
-
if (typeof type !== 'function' && typeof type.getCollectionNode !== 'function') {
|
|
114
|
-
let name = element.type;
|
|
115
|
-
throw new Error(`Unknown element <${name}> in collection.`);
|
|
116
|
-
}
|
|
117
|
-
let childNodes = type.getCollectionNode(element.props, this.context);
|
|
118
|
-
var _partialNode_index1;
|
|
119
|
-
let index = (_partialNode_index1 = partialNode.index) !== null && _partialNode_index1 !== void 0 ? _partialNode_index1 : 0;
|
|
120
|
-
let result = childNodes.next();
|
|
121
|
-
while(!result.done && result.value){
|
|
122
|
-
let childNode = result.value;
|
|
123
|
-
partialNode.index = index;
|
|
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);
|
|
127
|
-
let nodes = this.getFullNode({
|
|
128
|
-
...childNode,
|
|
129
|
-
key: nodeKey,
|
|
130
|
-
index: index,
|
|
131
|
-
wrapper: $51588fd411aace25$var$compose(partialNode.wrapper, childNode.wrapper)
|
|
132
|
-
}, this.getChildState(state, childNode), parentKey ? `${parentKey}${element.key}` : element.key, parentNode);
|
|
133
|
-
let children = [
|
|
134
|
-
...nodes
|
|
135
|
-
];
|
|
136
|
-
for (let node of children){
|
|
137
|
-
var _childNode_value, _ref;
|
|
138
|
-
// Cache the node based on its value
|
|
139
|
-
node.value = (_ref = (_childNode_value = childNode.value) !== null && _childNode_value !== void 0 ? _childNode_value : partialNode.value) !== null && _ref !== void 0 ? _ref : null;
|
|
140
|
-
if (node.value) this.cache.set(node.value, node);
|
|
141
|
-
var _parentNode_type;
|
|
142
|
-
// The partial node may have specified a type for the child in order to specify a constraint.
|
|
143
|
-
// Verify that the full node that was built recursively matches this type.
|
|
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.`);
|
|
145
|
-
index++;
|
|
146
|
-
yield node;
|
|
147
|
-
}
|
|
148
|
-
result = childNodes.next(children);
|
|
149
|
-
}
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
// Ignore invalid elements
|
|
153
|
-
if (partialNode.key == null || partialNode.type == null) return;
|
|
154
|
-
// Create full node
|
|
155
|
-
let builder = this;
|
|
156
|
-
var _partialNode_value, _partialNode_textValue;
|
|
157
|
-
let node = {
|
|
158
|
-
type: partialNode.type,
|
|
159
|
-
props: partialNode.props,
|
|
160
|
-
key: partialNode.key,
|
|
161
|
-
parentKey: parentNode ? parentNode.key : null,
|
|
162
|
-
value: (_partialNode_value = partialNode.value) !== null && _partialNode_value !== void 0 ? _partialNode_value : null,
|
|
163
|
-
level: parentNode ? parentNode.level + 1 : 0,
|
|
164
|
-
index: partialNode.index,
|
|
165
|
-
rendered: partialNode.rendered,
|
|
166
|
-
textValue: (_partialNode_textValue = partialNode.textValue) !== null && _partialNode_textValue !== void 0 ? _partialNode_textValue : '',
|
|
167
|
-
'aria-label': partialNode['aria-label'],
|
|
168
|
-
wrapper: partialNode.wrapper,
|
|
169
|
-
shouldInvalidate: partialNode.shouldInvalidate,
|
|
170
|
-
hasChildNodes: partialNode.hasChildNodes || false,
|
|
171
|
-
childNodes: $51588fd411aace25$var$iterable(function*() {
|
|
172
|
-
if (!partialNode.hasChildNodes || !partialNode.childNodes) return;
|
|
173
|
-
let index = 0;
|
|
174
|
-
for (let child of partialNode.childNodes()){
|
|
175
|
-
// Ensure child keys are globally unique by prepending the parent node's key
|
|
176
|
-
if (child.key != null) // TODO: Remove this line entirely and enforce that users always provide unique keys.
|
|
177
|
-
// Currently this line will have issues when a parent has a key `a` and a child with key `bc`
|
|
178
|
-
// but another parent has key `ab` and its child has a key `c`. The combined keys would result in both
|
|
179
|
-
// children having a key of `abc`.
|
|
180
|
-
child.key = `${node.key}${child.key}`;
|
|
181
|
-
let nodes = builder.getFullNode({
|
|
182
|
-
...child,
|
|
183
|
-
index: index
|
|
184
|
-
}, builder.getChildState(state, child), node.key, node);
|
|
185
|
-
for (let node of nodes){
|
|
186
|
-
index++;
|
|
187
|
-
yield node;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
})
|
|
191
|
-
};
|
|
192
|
-
yield node;
|
|
193
|
-
}
|
|
194
|
-
constructor(){
|
|
195
|
-
this.cache = new WeakMap();
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
// Wraps an iterator function as an iterable object, and caches the results.
|
|
199
|
-
function $51588fd411aace25$var$iterable(iterator) {
|
|
200
|
-
let cache = [];
|
|
201
|
-
let iterable = null;
|
|
202
|
-
return {
|
|
203
|
-
*[Symbol.iterator] () {
|
|
204
|
-
for (let item of cache)yield item;
|
|
205
|
-
if (!iterable) iterable = iterator();
|
|
206
|
-
for (let item of iterable){
|
|
207
|
-
cache.push(item);
|
|
208
|
-
yield item;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
function $51588fd411aace25$var$compose(outer, inner) {
|
|
214
|
-
if (outer && inner) return (element)=>outer(inner(element));
|
|
215
|
-
if (outer) return outer;
|
|
216
|
-
if (inner) return inner;
|
|
217
|
-
}
|
|
218
|
-
function $51588fd411aace25$var$capitalize(str) {
|
|
219
|
-
return str[0].toUpperCase() + str.slice(1);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
//# sourceMappingURL=CollectionBuilder.main.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":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e. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {CollectionBase, CollectionElement, Key, Node} from '@react-types/shared';\nimport {PartialNode} from './types';\nimport React, {ReactElement} from 'react';\n\ninterface CollectionBuilderState {\n renderer?: (value: any) => ReactElement | null\n}\n\ninterface CollectReactElement<T> extends ReactElement {\n getCollectionNode(props: any, context: any): Generator<PartialNode<T>, void, Node<T>[]>\n}\n\nexport class CollectionBuilder<T extends object> {\n private context?: unknown;\n private cache: WeakMap<T, Node<T>> = new WeakMap();\n\n build(props: Partial<CollectionBase<T>>, context?: unknown): Iterable<Node<T>> {\n this.context = context;\n return iterable(() => this.iterateCollection(props));\n }\n\n private *iterateCollection(props: Partial<CollectionBase<T>>): Generator<Node<T>> {\n let {children, items} = props;\n\n if (React.isValidElement<{children: CollectionElement<T>}>(children) && children.type === React.Fragment) {\n yield* this.iterateCollection({\n children: children.props.children,\n items\n });\n } else if (typeof children === 'function') {\n if (!items) {\n throw new Error('props.children was a function but props.items is missing');\n }\n\n let index = 0;\n for (let item of items) {\n yield* this.getFullNode({\n value: item,\n index\n }, {renderer: children});\n index++;\n }\n } else {\n let items: CollectionElement<T>[] = [];\n React.Children.forEach(children, child => {\n if (child) {\n items.push(child);\n }\n });\n\n let index = 0;\n for (let item of items) {\n let nodes = this.getFullNode({\n element: item,\n index: index\n }, {});\n\n for (let node of nodes) {\n index++;\n yield node;\n }\n }\n }\n }\n\n private getKey(item: NonNullable<CollectionElement<T>>, partialNode: PartialNode<T>, state: CollectionBuilderState, parentKey?: Key | null): Key {\n if (item.key != null) {\n return item.key;\n }\n\n if (partialNode.type === 'cell' && partialNode.key != null) {\n return `${parentKey}${partialNode.key}`;\n }\n\n let v = partialNode.value as any;\n if (v != null) {\n let key = v.key ?? v.id;\n if (key == null) {\n throw new Error('No key found for item');\n }\n\n return key;\n }\n\n return parentKey ? `${parentKey}.${partialNode.index}` : `$.${partialNode.index}`;\n }\n\n private getChildState(state: CollectionBuilderState, partialNode: PartialNode<T>) {\n return {\n renderer: partialNode.renderer || state.renderer\n };\n }\n\n private *getFullNode(partialNode: PartialNode<T> & {index: number}, state: CollectionBuilderState, parentKey?: Key | null, parentNode?: Node<T>): Generator<Node<T>> {\n if (React.isValidElement<{children: CollectionElement<T>}>(partialNode.element) && partialNode.element.type === React.Fragment) {\n let children: CollectionElement<T>[] = [];\n\n React.Children.forEach(partialNode.element.props.children, child => {\n children.push(child);\n });\n\n let index = partialNode.index ?? 0;\n\n for (const child of children) {\n yield* this.getFullNode({\n element: child,\n index: index++\n }, state, parentKey, parentNode);\n }\n\n return;\n }\n\n // If there's a value instead of an element on the node, and a parent renderer function is available,\n // use it to render an element for the value.\n let element = partialNode.element;\n if (!element && partialNode.value && state && state.renderer) {\n let cached = this.cache.get(partialNode.value);\n if (cached && (!cached.shouldInvalidate || !cached.shouldInvalidate(this.context))) {\n cached.index = partialNode.index;\n cached.parentKey = parentNode ? parentNode.key : null;\n yield cached;\n return;\n }\n\n element = state.renderer(partialNode.value);\n }\n\n // If there's an element with a getCollectionNode function on its type, then it's a supported component.\n // Call this function to get a partial node, and recursively build a full node from there.\n if (React.isValidElement(element)) {\n let type = element.type as unknown as CollectReactElement<T>;\n if (typeof type !== 'function' && typeof type.getCollectionNode !== 'function') {\n let name = element.type;\n throw new Error(`Unknown element <${name}> in collection.`);\n }\n\n let childNodes = type.getCollectionNode(element.props, this.context) as Generator<PartialNode<T>, void, Node<T>[]>;\n let index = partialNode.index ?? 0;\n let result = childNodes.next();\n while (!result.done && result.value) {\n let childNode = result.value;\n\n partialNode.index = index;\n\n let nodeKey = childNode.key ?? null;\n if (nodeKey == null) {\n nodeKey = childNode.element ? null : this.getKey(element as NonNullable<CollectionElement<T>>, partialNode, state, parentKey);\n }\n\n let nodes = this.getFullNode({\n ...childNode,\n key: nodeKey,\n index,\n wrapper: compose(partialNode.wrapper, childNode.wrapper)\n }, this.getChildState(state, childNode), parentKey ? `${parentKey}${element.key}` : element.key, parentNode);\n\n let children = [...nodes];\n for (let node of children) {\n // Cache the node based on its value\n node.value = childNode.value ?? partialNode.value ?? null;\n if (node.value) {\n this.cache.set(node.value, node);\n }\n\n // The partial node may have specified a type for the child in order to specify a constraint.\n // Verify that the full node that was built recursively matches this type.\n if (partialNode.type && node.type !== partialNode.type) {\n throw new Error(`Unsupported type <${capitalize(node.type)}> in <${capitalize(parentNode?.type ?? 'unknown parent type')}>. Only <${capitalize(partialNode.type)}> is supported.`);\n }\n\n index++;\n yield node;\n }\n\n result = childNodes.next(children);\n }\n\n return;\n }\n\n // Ignore invalid elements\n if (partialNode.key == null || partialNode.type == null) {\n return;\n }\n\n // Create full node\n let builder = this;\n let node: Node<T> = {\n type: partialNode.type,\n props: partialNode.props,\n key: partialNode.key,\n parentKey: parentNode ? parentNode.key : null,\n value: partialNode.value ?? null,\n level: parentNode ? parentNode.level + 1 : 0,\n index: partialNode.index,\n rendered: partialNode.rendered,\n textValue: partialNode.textValue ?? '',\n 'aria-label': partialNode['aria-label'],\n wrapper: partialNode.wrapper,\n shouldInvalidate: partialNode.shouldInvalidate,\n hasChildNodes: partialNode.hasChildNodes || false,\n childNodes: iterable(function *() {\n if (!partialNode.hasChildNodes || !partialNode.childNodes) {\n return;\n }\n\n let index = 0;\n for (let child of partialNode.childNodes()) {\n // Ensure child keys are globally unique by prepending the parent node's key\n if (child.key != null) {\n // TODO: Remove this line entirely and enforce that users always provide unique keys.\n // Currently this line will have issues when a parent has a key `a` and a child with key `bc`\n // but another parent has key `ab` and its child has a key `c`. The combined keys would result in both\n // children having a key of `abc`.\n child.key = `${node.key}${child.key}`;\n }\n\n let nodes = builder.getFullNode({...child, index}, builder.getChildState(state, child), node.key, node);\n for (let node of nodes) {\n index++;\n yield node;\n }\n }\n })\n };\n\n yield node;\n }\n}\n\n// Wraps an iterator function as an iterable object, and caches the results.\nfunction iterable<T>(iterator: () => IterableIterator<Node<T>>): Iterable<Node<T>> {\n let cache: Array<Node<T>> = [];\n let iterable: null | IterableIterator<Node<T>> = null;\n return {\n *[Symbol.iterator]() {\n for (let item of cache) {\n yield item;\n }\n\n if (!iterable) {\n iterable = iterator();\n }\n\n for (let item of iterable) {\n cache.push(item);\n yield item;\n }\n }\n };\n}\n\ntype Wrapper = (element: ReactElement) => ReactElement;\nfunction compose(outer: Wrapper | void, inner: Wrapper | void): Wrapper | undefined {\n if (outer && inner) {\n return (element) => outer(inner(element));\n }\n\n if (outer) {\n return outer;\n }\n\n if (inner) {\n return inner;\n }\n}\n\nfunction capitalize(str: string) {\n return str[0].toUpperCase() + str.slice(1);\n}\n"],"names":[],"version":3,"file":"CollectionBuilder.main.js.map"}
|