@tamagui/collection 1.74.3 → 1.74.5
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,60 @@
|
|
|
1
|
+
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
2
|
+
import {
|
|
3
|
+
Slot,
|
|
4
|
+
createStyledContext,
|
|
5
|
+
isWeb
|
|
6
|
+
} from "@tamagui/core";
|
|
7
|
+
import React from "react";
|
|
8
|
+
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
function createCollection(name) {
|
|
10
|
+
const { Provider: CollectionProviderImpl, useStyledContext: useCollectionContext } = createStyledContext({
|
|
11
|
+
collectionRef: { current: null },
|
|
12
|
+
itemMap: /* @__PURE__ */ new Map()
|
|
13
|
+
}), CollectionProvider = (props) => {
|
|
14
|
+
const { __scopeCollection, children } = props, ref = React.useRef(null), itemMap = React.useRef(/* @__PURE__ */ new Map()).current;
|
|
15
|
+
return /* @__PURE__ */ jsx(
|
|
16
|
+
CollectionProviderImpl,
|
|
17
|
+
{
|
|
18
|
+
scope: __scopeCollection,
|
|
19
|
+
itemMap,
|
|
20
|
+
collectionRef: ref,
|
|
21
|
+
children
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
CollectionProvider.displayName = "CollectionProvider";
|
|
26
|
+
const COLLECTION_SLOT_NAME = name + "CollectionSlot", CollectionSlot = React.forwardRef((props, forwardedRef) => {
|
|
27
|
+
const { __scopeCollection, children } = props, context = useCollectionContext(__scopeCollection), composedRefs = useComposedRefs(forwardedRef, context.collectionRef);
|
|
28
|
+
return /* @__PURE__ */ jsx(Slot, { ref: composedRefs, children });
|
|
29
|
+
});
|
|
30
|
+
CollectionSlot.displayName = COLLECTION_SLOT_NAME;
|
|
31
|
+
const ITEM_SLOT_NAME = name + "CollectionItemSlot", ITEM_DATA_ATTR = "data-collection-item", CollectionItemSlot = React.forwardRef((props, forwardedRef) => {
|
|
32
|
+
const { __scopeCollection, children, ...itemData } = props, ref = React.useRef(null), composedRefs = useComposedRefs(forwardedRef, ref), context = useCollectionContext(__scopeCollection);
|
|
33
|
+
return React.useEffect(() => (context.itemMap.set(ref, { ref, ...itemData }), () => void context.itemMap.delete(ref))), /* @__PURE__ */ jsx(Slot, { [ITEM_DATA_ATTR]: "", ref: composedRefs, children });
|
|
34
|
+
});
|
|
35
|
+
CollectionItemSlot.displayName = ITEM_SLOT_NAME;
|
|
36
|
+
function useCollection(__scopeCollection) {
|
|
37
|
+
const context = useCollectionContext(__scopeCollection);
|
|
38
|
+
return React.useCallback(() => {
|
|
39
|
+
if (!isWeb)
|
|
40
|
+
return [];
|
|
41
|
+
const collectionNode = context.collectionRef.current;
|
|
42
|
+
if (!collectionNode)
|
|
43
|
+
return [];
|
|
44
|
+
const orderedNodes = Array.from(
|
|
45
|
+
collectionNode.querySelectorAll(`[${ITEM_DATA_ATTR}]`)
|
|
46
|
+
);
|
|
47
|
+
return Array.from(context.itemMap.values()).sort(
|
|
48
|
+
(a, b) => orderedNodes.indexOf(a.ref.current) - orderedNodes.indexOf(b.ref.current)
|
|
49
|
+
);
|
|
50
|
+
}, [context.collectionRef, context.itemMap]);
|
|
51
|
+
}
|
|
52
|
+
return [
|
|
53
|
+
{ Provider: CollectionProvider, Slot: CollectionSlot, ItemSlot: CollectionItemSlot },
|
|
54
|
+
useCollection
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
createCollection
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=Collection.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Collection.tsx"],
|
|
4
|
+
"mappings": "AAAA,SAAS,uBAAuB;AAChC;AAAA,EAEE;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AACP,OAAO,WAAW;AA8CZ;AAnCN,SAAS,iBACP,MACA;AAmBA,QAAM,EAAE,UAAU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AM,YAAY,MAAM;AACvC,UAAI,CAAC;AACH,eAAO,CAAC;AAGV,YAAM,iBAAiB,QAAQ,cAAc;AAC7C,UAAI,CAAC;AAAgB,eAAO,CAAC;AAC7B,YAAM,eAAe,MAAM;AAAA,QACzB,eAAe,iBAAiB,IAAI,cAAc,GAAG;AAAA,MACvD;AAOA,aANc,MAAM,KAAK,QAAQ,QAAQ,OAAO,CAAC,EACtB;AAAA,QACzB,CAAC,GAAG,MACF,aAAa,QAAQ,EAAE,IAAI,OAAuB,IAClD,aAAa,QAAQ,EAAE,IAAI,OAAuB;AAAA,MACtD;AAAA,IAEF,GAAG,CAAC,QAAQ,eAAe,QAAQ,OAAO,CAAC;AAAA,EAG7C;AAEA,SAAO;AAAA,IACL,EAAE,UAAU,oBAAoB,MAAM,gBAAgB,UAAU,mBAAmB;AAAA,IACnF;AAAA,EACF;AACF;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/collection",
|
|
3
|
-
"version": "1.74.
|
|
3
|
+
"version": "1.74.5",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"*.css"
|
|
6
6
|
],
|
|
@@ -31,18 +31,18 @@
|
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@tamagui/compose-refs": "1.74.
|
|
35
|
-
"@tamagui/core": "1.74.
|
|
36
|
-
"@tamagui/create-context": "1.74.
|
|
37
|
-
"@tamagui/polyfill-dev": "1.74.
|
|
38
|
-
"@tamagui/stacks": "1.74.
|
|
39
|
-
"@tamagui/use-controllable-state": "1.74.
|
|
34
|
+
"@tamagui/compose-refs": "1.74.5",
|
|
35
|
+
"@tamagui/core": "1.74.5",
|
|
36
|
+
"@tamagui/create-context": "1.74.5",
|
|
37
|
+
"@tamagui/polyfill-dev": "1.74.5",
|
|
38
|
+
"@tamagui/stacks": "1.74.5",
|
|
39
|
+
"@tamagui/use-controllable-state": "1.74.5"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"react": "*"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@tamagui/build": "1.74.
|
|
45
|
+
"@tamagui/build": "1.74.5",
|
|
46
46
|
"react": "^18.2.0"
|
|
47
47
|
},
|
|
48
48
|
"publishConfig": {
|