@tamagui/collection 1.88.13 → 1.89.0-1706308641099
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 +82 -0
- package/dist/esm/index.mjs +1 -0
- package/dist/jsx/Collection.mjs +82 -0
- package/dist/jsx/index.mjs +1 -0
- package/package.json +9 -9
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
2
|
+
import { isWeb } from "@tamagui/constants";
|
|
3
|
+
import { Slot, createStyledContext } from "@tamagui/core";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
function createCollection(name) {
|
|
7
|
+
const {
|
|
8
|
+
Provider: CollectionProviderImpl,
|
|
9
|
+
useStyledContext: useCollectionContext
|
|
10
|
+
} = createStyledContext({
|
|
11
|
+
collectionRef: {
|
|
12
|
+
current: null
|
|
13
|
+
},
|
|
14
|
+
itemMap: /* @__PURE__ */new Map()
|
|
15
|
+
}),
|
|
16
|
+
CollectionProvider = props => {
|
|
17
|
+
const {
|
|
18
|
+
__scopeCollection,
|
|
19
|
+
children
|
|
20
|
+
} = props,
|
|
21
|
+
ref = React.useRef(null),
|
|
22
|
+
itemMap = React.useRef( /* @__PURE__ */new Map()).current;
|
|
23
|
+
return /* @__PURE__ */jsx(CollectionProviderImpl, {
|
|
24
|
+
scope: __scopeCollection,
|
|
25
|
+
itemMap,
|
|
26
|
+
collectionRef: ref,
|
|
27
|
+
children
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
CollectionProvider.displayName = "CollectionProvider";
|
|
31
|
+
const COLLECTION_SLOT_NAME = name + "CollectionSlot",
|
|
32
|
+
CollectionSlot = React.forwardRef((props, forwardedRef) => {
|
|
33
|
+
const {
|
|
34
|
+
__scopeCollection,
|
|
35
|
+
children
|
|
36
|
+
} = props,
|
|
37
|
+
context = useCollectionContext(__scopeCollection),
|
|
38
|
+
composedRefs = useComposedRefs(forwardedRef, context.collectionRef);
|
|
39
|
+
return /* @__PURE__ */jsx(Slot, {
|
|
40
|
+
ref: composedRefs,
|
|
41
|
+
children
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
CollectionSlot.displayName = COLLECTION_SLOT_NAME;
|
|
45
|
+
const ITEM_SLOT_NAME = name + "CollectionItemSlot",
|
|
46
|
+
ITEM_DATA_ATTR = "data-collection-item",
|
|
47
|
+
CollectionItemSlot = React.forwardRef((props, forwardedRef) => {
|
|
48
|
+
const {
|
|
49
|
+
__scopeCollection,
|
|
50
|
+
children,
|
|
51
|
+
...itemData
|
|
52
|
+
} = props,
|
|
53
|
+
ref = React.useRef(null),
|
|
54
|
+
composedRefs = useComposedRefs(forwardedRef, ref),
|
|
55
|
+
context = useCollectionContext(__scopeCollection);
|
|
56
|
+
return React.useEffect(() => (context.itemMap.set(ref, {
|
|
57
|
+
ref,
|
|
58
|
+
...itemData
|
|
59
|
+
}), () => void context.itemMap.delete(ref))), /* @__PURE__ */jsx(Slot, {
|
|
60
|
+
[ITEM_DATA_ATTR]: "",
|
|
61
|
+
ref: composedRefs,
|
|
62
|
+
children
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
CollectionItemSlot.displayName = ITEM_SLOT_NAME;
|
|
66
|
+
function useCollection(__scopeCollection) {
|
|
67
|
+
const context = useCollectionContext(__scopeCollection);
|
|
68
|
+
return React.useCallback(() => {
|
|
69
|
+
if (!isWeb) return [];
|
|
70
|
+
const collectionNode = context.collectionRef.current;
|
|
71
|
+
if (!collectionNode) return [];
|
|
72
|
+
const orderedNodes = Array.from(collectionNode.querySelectorAll(`[${ITEM_DATA_ATTR}]`));
|
|
73
|
+
return Array.from(context.itemMap.values()).sort((a, b) => orderedNodes.indexOf(a.ref.current) - orderedNodes.indexOf(b.ref.current));
|
|
74
|
+
}, [context.collectionRef, context.itemMap]);
|
|
75
|
+
}
|
|
76
|
+
return [{
|
|
77
|
+
Provider: CollectionProvider,
|
|
78
|
+
Slot: CollectionSlot,
|
|
79
|
+
ItemSlot: CollectionItemSlot
|
|
80
|
+
}, useCollection];
|
|
81
|
+
}
|
|
82
|
+
export { createCollection };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Collection.mjs";
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
2
|
+
import { isWeb } from "@tamagui/constants";
|
|
3
|
+
import { Slot, createStyledContext } from "@tamagui/core";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
function createCollection(name) {
|
|
7
|
+
const {
|
|
8
|
+
Provider: CollectionProviderImpl,
|
|
9
|
+
useStyledContext: useCollectionContext
|
|
10
|
+
} = createStyledContext({
|
|
11
|
+
collectionRef: {
|
|
12
|
+
current: null
|
|
13
|
+
},
|
|
14
|
+
itemMap: /* @__PURE__ */new Map()
|
|
15
|
+
}),
|
|
16
|
+
CollectionProvider = props => {
|
|
17
|
+
const {
|
|
18
|
+
__scopeCollection,
|
|
19
|
+
children
|
|
20
|
+
} = props,
|
|
21
|
+
ref = React.useRef(null),
|
|
22
|
+
itemMap = React.useRef( /* @__PURE__ */new Map()).current;
|
|
23
|
+
return /* @__PURE__ */jsx(CollectionProviderImpl, {
|
|
24
|
+
scope: __scopeCollection,
|
|
25
|
+
itemMap,
|
|
26
|
+
collectionRef: ref,
|
|
27
|
+
children
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
CollectionProvider.displayName = "CollectionProvider";
|
|
31
|
+
const COLLECTION_SLOT_NAME = name + "CollectionSlot",
|
|
32
|
+
CollectionSlot = React.forwardRef((props, forwardedRef) => {
|
|
33
|
+
const {
|
|
34
|
+
__scopeCollection,
|
|
35
|
+
children
|
|
36
|
+
} = props,
|
|
37
|
+
context = useCollectionContext(__scopeCollection),
|
|
38
|
+
composedRefs = useComposedRefs(forwardedRef, context.collectionRef);
|
|
39
|
+
return /* @__PURE__ */jsx(Slot, {
|
|
40
|
+
ref: composedRefs,
|
|
41
|
+
children
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
CollectionSlot.displayName = COLLECTION_SLOT_NAME;
|
|
45
|
+
const ITEM_SLOT_NAME = name + "CollectionItemSlot",
|
|
46
|
+
ITEM_DATA_ATTR = "data-collection-item",
|
|
47
|
+
CollectionItemSlot = React.forwardRef((props, forwardedRef) => {
|
|
48
|
+
const {
|
|
49
|
+
__scopeCollection,
|
|
50
|
+
children,
|
|
51
|
+
...itemData
|
|
52
|
+
} = props,
|
|
53
|
+
ref = React.useRef(null),
|
|
54
|
+
composedRefs = useComposedRefs(forwardedRef, ref),
|
|
55
|
+
context = useCollectionContext(__scopeCollection);
|
|
56
|
+
return React.useEffect(() => (context.itemMap.set(ref, {
|
|
57
|
+
ref,
|
|
58
|
+
...itemData
|
|
59
|
+
}), () => void context.itemMap.delete(ref))), /* @__PURE__ */jsx(Slot, {
|
|
60
|
+
[ITEM_DATA_ATTR]: "",
|
|
61
|
+
ref: composedRefs,
|
|
62
|
+
children
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
CollectionItemSlot.displayName = ITEM_SLOT_NAME;
|
|
66
|
+
function useCollection(__scopeCollection) {
|
|
67
|
+
const context = useCollectionContext(__scopeCollection);
|
|
68
|
+
return React.useCallback(() => {
|
|
69
|
+
if (!isWeb) return [];
|
|
70
|
+
const collectionNode = context.collectionRef.current;
|
|
71
|
+
if (!collectionNode) return [];
|
|
72
|
+
const orderedNodes = Array.from(collectionNode.querySelectorAll(`[${ITEM_DATA_ATTR}]`));
|
|
73
|
+
return Array.from(context.itemMap.values()).sort((a, b) => orderedNodes.indexOf(a.ref.current) - orderedNodes.indexOf(b.ref.current));
|
|
74
|
+
}, [context.collectionRef, context.itemMap]);
|
|
75
|
+
}
|
|
76
|
+
return [{
|
|
77
|
+
Provider: CollectionProvider,
|
|
78
|
+
Slot: CollectionSlot,
|
|
79
|
+
ItemSlot: CollectionItemSlot
|
|
80
|
+
}, useCollection];
|
|
81
|
+
}
|
|
82
|
+
export { createCollection };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Collection.mjs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/collection",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.89.0-1706308641099",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"*.css"
|
|
6
6
|
],
|
|
@@ -32,19 +32,19 @@
|
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@tamagui/compose-refs": "1.
|
|
36
|
-
"@tamagui/constants": "1.
|
|
37
|
-
"@tamagui/core": "1.
|
|
38
|
-
"@tamagui/create-context": "1.
|
|
39
|
-
"@tamagui/polyfill-dev": "1.
|
|
40
|
-
"@tamagui/stacks": "1.
|
|
41
|
-
"@tamagui/use-controllable-state": "1.
|
|
35
|
+
"@tamagui/compose-refs": "1.89.0-1706308641099",
|
|
36
|
+
"@tamagui/constants": "1.89.0-1706308641099",
|
|
37
|
+
"@tamagui/core": "1.89.0-1706308641099",
|
|
38
|
+
"@tamagui/create-context": "1.89.0-1706308641099",
|
|
39
|
+
"@tamagui/polyfill-dev": "1.89.0-1706308641099",
|
|
40
|
+
"@tamagui/stacks": "1.89.0-1706308641099",
|
|
41
|
+
"@tamagui/use-controllable-state": "1.89.0-1706308641099"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"react": "*"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@tamagui/build": "1.
|
|
47
|
+
"@tamagui/build": "1.89.0-1706308641099",
|
|
48
48
|
"react": "^18.2.0"
|
|
49
49
|
},
|
|
50
50
|
"publishConfig": {
|