@tamagui/collection 1.62.3 → 1.64.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/esm/Collection.mjs +54 -0
- package/dist/esm/Collection.mjs.map +1 -1
- package/dist/esm/index.mjs +2 -0
- package/package.json +8 -8
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
2
|
+
import { Slot, isWeb } from "@tamagui/core";
|
|
3
|
+
import { createContextScope } from "@tamagui/create-context";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
function createCollection(name) {
|
|
7
|
+
const PROVIDER_NAME = name + "CollectionProvider", [createCollectionContext, createCollectionScope] = createContextScope(PROVIDER_NAME), [CollectionProviderImpl, useCollectionContext] = createCollectionContext(PROVIDER_NAME, {
|
|
8
|
+
collectionRef: { current: null },
|
|
9
|
+
itemMap: /* @__PURE__ */ new Map()
|
|
10
|
+
}), CollectionProvider = (props) => {
|
|
11
|
+
const { scope, children } = props, ref = React.useRef(null), itemMap = React.useRef(/* @__PURE__ */ new Map()).current;
|
|
12
|
+
return /* @__PURE__ */ jsx(CollectionProviderImpl, { scope, itemMap, collectionRef: ref, children });
|
|
13
|
+
};
|
|
14
|
+
CollectionProvider.displayName = PROVIDER_NAME;
|
|
15
|
+
const COLLECTION_SLOT_NAME = name + "CollectionSlot", CollectionSlot = React.forwardRef(
|
|
16
|
+
(props, forwardedRef) => {
|
|
17
|
+
const { scope, children } = props, context = useCollectionContext(COLLECTION_SLOT_NAME, scope), composedRefs = useComposedRefs(forwardedRef, context.collectionRef);
|
|
18
|
+
return /* @__PURE__ */ jsx(Slot, { ref: composedRefs, children });
|
|
19
|
+
}
|
|
20
|
+
);
|
|
21
|
+
CollectionSlot.displayName = COLLECTION_SLOT_NAME;
|
|
22
|
+
const ITEM_SLOT_NAME = name + "CollectionItemSlot", ITEM_DATA_ATTR = "data-collection-item", CollectionItemSlot = React.forwardRef(
|
|
23
|
+
(props, forwardedRef) => {
|
|
24
|
+
const { scope, children, ...itemData } = props, ref = React.useRef(null), composedRefs = useComposedRefs(forwardedRef, ref), context = useCollectionContext(ITEM_SLOT_NAME, scope);
|
|
25
|
+
return React.useEffect(() => (context.itemMap.set(ref, { ref, ...itemData }), () => void context.itemMap.delete(ref))), /* @__PURE__ */ jsx(Slot, { [ITEM_DATA_ATTR]: "", ref: composedRefs, children });
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
CollectionItemSlot.displayName = ITEM_SLOT_NAME;
|
|
29
|
+
function useCollection(scope) {
|
|
30
|
+
const context = useCollectionContext(name + "CollectionConsumer", scope);
|
|
31
|
+
return React.useCallback(() => {
|
|
32
|
+
if (!isWeb)
|
|
33
|
+
return [];
|
|
34
|
+
const collectionNode = context.collectionRef.current;
|
|
35
|
+
if (!collectionNode)
|
|
36
|
+
return [];
|
|
37
|
+
const orderedNodes = Array.from(
|
|
38
|
+
collectionNode.querySelectorAll(`[${ITEM_DATA_ATTR}]`)
|
|
39
|
+
);
|
|
40
|
+
return Array.from(context.itemMap.values()).sort(
|
|
41
|
+
(a, b) => orderedNodes.indexOf(a.ref.current) - orderedNodes.indexOf(b.ref.current)
|
|
42
|
+
);
|
|
43
|
+
}, [context.collectionRef, context.itemMap]);
|
|
44
|
+
}
|
|
45
|
+
return [
|
|
46
|
+
{ Provider: CollectionProvider, Slot: CollectionSlot, ItemSlot: CollectionItemSlot },
|
|
47
|
+
useCollection,
|
|
48
|
+
createCollectionScope
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
createCollection
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=Collection.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Collection.tsx"],
|
|
4
|
-
"mappings": "
|
|
4
|
+
"mappings": "AAAA,S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BAAC,QAAW,CAAC,cAAc,GAAG,IAAM,KAAK,cACtC,UACH;AAAA,IAEJ;AAAA,EACF;AAEA,qBAAmB,cAAc;AAMjC,WAAS,cAAc,OAAY;AACjC,UAAM,UAAU,qBAAqB,OAAO,sBAAsB,KAAK;AAqBvE,WAnBiB,MAAM,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,IACA;AAAA,EACF;AACF;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/collection",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.64.0",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"*.css"
|
|
6
6
|
],
|
|
@@ -27,18 +27,18 @@
|
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@tamagui/compose-refs": "1.
|
|
31
|
-
"@tamagui/core": "1.
|
|
32
|
-
"@tamagui/create-context": "1.
|
|
33
|
-
"@tamagui/polyfill-dev": "1.
|
|
34
|
-
"@tamagui/stacks": "1.
|
|
35
|
-
"@tamagui/use-controllable-state": "1.
|
|
30
|
+
"@tamagui/compose-refs": "1.64.0",
|
|
31
|
+
"@tamagui/core": "1.64.0",
|
|
32
|
+
"@tamagui/create-context": "1.64.0",
|
|
33
|
+
"@tamagui/polyfill-dev": "1.64.0",
|
|
34
|
+
"@tamagui/stacks": "1.64.0",
|
|
35
|
+
"@tamagui/use-controllable-state": "1.64.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"react": "*"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@tamagui/build": "1.
|
|
41
|
+
"@tamagui/build": "1.64.0",
|
|
42
42
|
"react": "^18.2.0"
|
|
43
43
|
},
|
|
44
44
|
"publishConfig": {
|