@tamagui/collection 2.7.7 → 3.0.0-beta.643.1
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/cjs/Collection.cjs +88 -112
- package/dist/cjs/Collection.native.cjs +112 -0
- package/dist/cjs/Collection.native.js +92 -113
- package/dist/cjs/Collection.native.js.map +1 -1
- package/dist/cjs/index.cjs +10 -11
- package/dist/cjs/index.native.cjs +21 -0
- package/dist/cjs/index.native.js +10 -10
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/Collection.mjs +71 -86
- package/dist/esm/Collection.mjs.map +1 -1
- package/dist/esm/Collection.native.js +76 -89
- package/dist/esm/Collection.native.js.map +1 -1
- package/dist/esm/index.js +1 -2
- package/dist/esm/index.mjs +1 -2
- package/dist/esm/index.native.js +1 -2
- package/dist/jsx/Collection.mjs +71 -86
- package/dist/jsx/Collection.mjs.map +1 -1
- package/dist/jsx/Collection.native.cjs +112 -0
- package/dist/jsx/Collection.native.js +92 -113
- package/dist/jsx/Collection.native.js.map +1 -1
- package/dist/jsx/index.js +1 -2
- package/dist/jsx/index.mjs +1 -2
- package/dist/jsx/index.native.cjs +21 -0
- package/dist/jsx/index.native.js +10 -10
- package/dist/jsx/index.native.js.map +1 -1
- package/package.json +9 -9
- package/src/Collection.tsx +3 -2
- package/types/Collection.d.ts +4 -4
- package/types/Collection.d.ts.map +1 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js.map +0 -1
- package/dist/jsx/index.js.map +0 -1
- package/dist/jsx/index.mjs.map +0 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
11
|
+
get: () => from[key],
|
|
12
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var index_exports = {};
|
|
20
|
+
module.exports = __toCommonJS(index_exports);
|
|
21
|
+
__reExport(index_exports, require("./Collection.native.js"), module.exports);
|
package/dist/cjs/index.native.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
8
|
var __copyProps = (to, from, except, desc) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
11
|
+
get: () => from[key],
|
|
12
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
15
16
|
};
|
|
16
17
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
17
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
18
|
-
value: true
|
|
19
|
-
}), mod);
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
19
|
var index_exports = {};
|
|
21
20
|
module.exports = __toCommonJS(index_exports);
|
|
22
21
|
__reExport(index_exports, require("./Collection.native.js"), module.exports);
|
|
22
|
+
|
|
23
23
|
//# sourceMappingURL=index.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.native.js","names":[],"sources":["cjs/index.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, \"default\"), secondTarget && __copyProps(secondTarget, mod, \"default\"));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar index_exports = {};\nmodule.exports = __toCommonJS(index_exports);\n__reExport(index_exports, require(\"./Collection\"), module.exports);\n//# sourceMappingURL=index.js.map\n"],"mappings":";;;;AACA,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EAClE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QACzC,UAAU,IAAI,KAAK;GAAE,WAAW,KAAK;GAAM,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK;EAAW,CAAC;CACvH;CACA,OAAO;AACT;AACA,IAAI,cAAc,QAAQ,KAAK,kBAAkB,YAAY,QAAQ,KAAK,SAAS,GAAG,gBAAgB,YAAY,cAAc,KAAK,SAAS;AAC9I,IAAI,gBAAgB,QAAQ,YAAY,UAAU,CAAC,GAAG,cAAc,EAAE,OAAO,KAAK,CAAC,GAAG,GAAG;AACzF,IAAI,gBAAgB,CAAC;AACrB,OAAO,UAAU,aAAa,aAAa;AAC3C,WAAW,eAAe,QAAQ,wBAAc,GAAG,OAAO,OAAO"}
|
package/dist/esm/Collection.mjs
CHANGED
|
@@ -1,94 +1,79 @@
|
|
|
1
|
+
import { Slot, createRefComponent, createStyledContext } from "@tamagui/core";
|
|
1
2
|
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
2
3
|
import { isWeb } from "@tamagui/constants";
|
|
3
|
-
import { Slot, createStyledContext } from "@tamagui/core";
|
|
4
4
|
import React from "react";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
|
|
6
7
|
function createCollection(name) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (!isWeb) {
|
|
76
|
-
return [];
|
|
77
|
-
}
|
|
78
|
-
const collectionNode = context.collectionRef.current;
|
|
79
|
-
if (!collectionNode) return [];
|
|
80
|
-
const orderedNodes = Array.from(collectionNode.querySelectorAll(`[${ITEM_DATA_ATTR}]`));
|
|
81
|
-
const items = Array.from(context.itemMap.values());
|
|
82
|
-
const orderedItems = items.sort((a, b) => orderedNodes.indexOf(a.ref.current) - orderedNodes.indexOf(b.ref.current));
|
|
83
|
-
return orderedItems;
|
|
84
|
-
}, [context.collectionRef, context.itemMap]);
|
|
85
|
-
return getItems;
|
|
86
|
-
}
|
|
87
|
-
return [{
|
|
88
|
-
Provider: CollectionProvider,
|
|
89
|
-
Slot: CollectionSlot,
|
|
90
|
-
ItemSlot: CollectionItemSlot
|
|
91
|
-
}, useCollection];
|
|
8
|
+
const { Provider: CollectionProviderImpl, useStyledContext: useCollectionContext } = createStyledContext({
|
|
9
|
+
collectionRef: { current: void 0 },
|
|
10
|
+
itemMap: /* @__PURE__ */ new Map()
|
|
11
|
+
}, "Toast");
|
|
12
|
+
const CollectionProvider = (props) => {
|
|
13
|
+
const { scope, children } = props;
|
|
14
|
+
const ref = React.useRef(void 0);
|
|
15
|
+
const itemMap = React.useRef(/* @__PURE__ */ new Map()).current;
|
|
16
|
+
return /* @__PURE__ */ jsx(CollectionProviderImpl, {
|
|
17
|
+
scope,
|
|
18
|
+
itemMap,
|
|
19
|
+
collectionRef: ref,
|
|
20
|
+
children
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
CollectionProvider.displayName = "CollectionProvider";
|
|
24
|
+
const COLLECTION_SLOT_NAME = name + "CollectionSlot";
|
|
25
|
+
const CollectionSlot = createRefComponent((props, forwardedRef) => {
|
|
26
|
+
const { scope, children } = props;
|
|
27
|
+
const context = useCollectionContext(scope);
|
|
28
|
+
const composedRefs = useComposedRefs(forwardedRef, context.collectionRef);
|
|
29
|
+
return /* @__PURE__ */ jsx(Slot, {
|
|
30
|
+
ref: composedRefs,
|
|
31
|
+
children
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
CollectionSlot.displayName = COLLECTION_SLOT_NAME;
|
|
35
|
+
const ITEM_SLOT_NAME = name + "CollectionItemSlot";
|
|
36
|
+
const ITEM_DATA_ATTR = "data-collection-item";
|
|
37
|
+
const CollectionItemSlot = createRefComponent((props, forwardedRef) => {
|
|
38
|
+
const { scope, children, ...itemData } = props;
|
|
39
|
+
const ref = React.useRef(void 0);
|
|
40
|
+
const composedRefs = useComposedRefs(forwardedRef, ref);
|
|
41
|
+
const context = useCollectionContext(scope);
|
|
42
|
+
React.useEffect(() => {
|
|
43
|
+
context.itemMap.set(ref, {
|
|
44
|
+
ref,
|
|
45
|
+
...itemData
|
|
46
|
+
});
|
|
47
|
+
return () => void context.itemMap.delete(ref);
|
|
48
|
+
});
|
|
49
|
+
return /* @__PURE__ */ jsx(Slot, {
|
|
50
|
+
...{ [ITEM_DATA_ATTR]: "" },
|
|
51
|
+
ref: composedRefs,
|
|
52
|
+
children
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
CollectionItemSlot.displayName = ITEM_SLOT_NAME;
|
|
56
|
+
function useCollection(scope) {
|
|
57
|
+
const context = useCollectionContext(scope);
|
|
58
|
+
const getItems = React.useCallback(() => {
|
|
59
|
+
if (!isWeb) {
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
const collectionNode = context.collectionRef.current;
|
|
63
|
+
if (!collectionNode) return [];
|
|
64
|
+
const orderedNodes = Array.from(collectionNode.querySelectorAll(`[${ITEM_DATA_ATTR}]`));
|
|
65
|
+
const items = Array.from(context.itemMap.values());
|
|
66
|
+
const orderedItems = items.sort((a, b) => orderedNodes.indexOf(a.ref.current) - orderedNodes.indexOf(b.ref.current));
|
|
67
|
+
return orderedItems;
|
|
68
|
+
}, [context.collectionRef, context.itemMap]);
|
|
69
|
+
return getItems;
|
|
70
|
+
}
|
|
71
|
+
return [{
|
|
72
|
+
Provider: CollectionProvider,
|
|
73
|
+
Slot: CollectionSlot,
|
|
74
|
+
ItemSlot: CollectionItemSlot
|
|
75
|
+
}, useCollection];
|
|
92
76
|
}
|
|
77
|
+
|
|
93
78
|
export { createCollection };
|
|
94
79
|
//# sourceMappingURL=Collection.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"Collection.js","names":[],"sources":["esm/Collection.js"],"sourcesContent":["import { createRefComponent } from \"@tamagui/core\";\nimport { useComposedRefs } from \"@tamagui/compose-refs\";\nimport { isWeb } from \"@tamagui/constants\";\nimport { Slot, createStyledContext } from \"@tamagui/core\";\nimport React from \"react\";\nimport { jsx } from \"react/jsx-runtime\";\nfunction createCollection(name) {\n const { Provider: CollectionProviderImpl, useStyledContext: useCollectionContext } = createStyledContext(\n {\n collectionRef: { current: void 0 },\n itemMap: /* @__PURE__ */ new Map()\n },\n \"Toast\"\n );\n const CollectionProvider = (props) => {\n const { scope, children } = props;\n const ref = React.useRef(void 0);\n const itemMap = React.useRef(/* @__PURE__ */ new Map()).current;\n return /* @__PURE__ */ jsx(CollectionProviderImpl, { scope, itemMap, collectionRef: ref, children });\n };\n CollectionProvider.displayName = \"CollectionProvider\";\n const COLLECTION_SLOT_NAME = name + \"CollectionSlot\";\n const CollectionSlot = createRefComponent((props, forwardedRef) => {\n const { scope, children } = props;\n const context = useCollectionContext(scope);\n const composedRefs = useComposedRefs(forwardedRef, context.collectionRef);\n return /* @__PURE__ */ jsx(Slot, { ref: composedRefs, children });\n });\n CollectionSlot.displayName = COLLECTION_SLOT_NAME;\n const ITEM_SLOT_NAME = name + \"CollectionItemSlot\";\n const ITEM_DATA_ATTR = \"data-collection-item\";\n const CollectionItemSlot = createRefComponent((props, forwardedRef) => {\n const { scope, children, ...itemData } = props;\n const ref = React.useRef(void 0);\n const composedRefs = useComposedRefs(forwardedRef, ref);\n const context = useCollectionContext(scope);\n React.useEffect(() => {\n context.itemMap.set(ref, { ref, ...itemData });\n return () => void context.itemMap.delete(ref);\n });\n return /* @__PURE__ */ jsx(Slot, { ...{ [ITEM_DATA_ATTR]: \"\" }, ref: composedRefs, children });\n });\n CollectionItemSlot.displayName = ITEM_SLOT_NAME;\n function useCollection(scope) {\n const context = useCollectionContext(scope);\n const getItems = React.useCallback(() => {\n if (!isWeb) {\n return [];\n }\n const collectionNode = context.collectionRef.current;\n if (!collectionNode) return [];\n const orderedNodes = Array.from(\n collectionNode.querySelectorAll(`[${ITEM_DATA_ATTR}]`)\n );\n const items = Array.from(context.itemMap.values());\n const orderedItems = items.sort(\n (a, b) => orderedNodes.indexOf(a.ref.current) - orderedNodes.indexOf(b.ref.current)\n );\n return orderedItems;\n }, [context.collectionRef, context.itemMap]);\n return getItems;\n }\n return [\n { Provider: CollectionProvider, Slot: CollectionSlot, ItemSlot: CollectionItemSlot },\n useCollection\n ];\n}\nexport {\n createCollection\n};\n//# sourceMappingURL=Collection.js.map\n"],"mappings":";;;;;;;AAMA,SAAS,iBAAiB,MAAM;CAC9B,MAAM,EAAE,UAAU,wBAAwB,kBAAkB,yBAAyB,oBACnF;EACE,eAAe,EAAE,SAAS,KAAK,EAAE;EACjC,yBAAyB,IAAI,IAAI;CACnC,GACA,OACF;CACA,MAAM,sBAAs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AAM,eAAe,MAAM,KACzB,eAAe,iBAAiB,IAAI,eAAe,EAAE,CACvD;GACA,MAAM,QAAQ,MAAM,KAAK,QAAQ,QAAQ,OAAO,CAAC;GACjD,MAAM,eAAe,MAAM,MACxB,GAAG,MAAM,aAAa,QAAQ,EAAE,IAAI,OAAO,IAAI,aAAa,QAAQ,EAAE,IAAI,OAAO,CACpF;GACA,OAAO;EACT,GAAG,CAAC,QAAQ,eAAe,QAAQ,OAAO,CAAC;EAC3C,OAAO;CACT;CACA,OAAO,CACL;EAAE,UAAU;EAAoB,MAAM;EAAgB,UAAU;CAAmB,GACnF,aACF;AACF"}
|
|
@@ -1,96 +1,83 @@
|
|
|
1
|
-
import { jsx
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Slot, createRefComponent, createStyledContext } from "@tamagui/core";
|
|
2
3
|
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
3
4
|
import { isWeb } from "@tamagui/constants";
|
|
4
|
-
import { Slot, createStyledContext } from "@tamagui/core";
|
|
5
5
|
import React from "react";
|
|
6
|
+
|
|
6
7
|
function createCollection(name) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (!collectionNode) return [];
|
|
80
|
-
var orderedNodes = Array.from(collectionNode.querySelectorAll(`[${ITEM_DATA_ATTR}]`));
|
|
81
|
-
var items = Array.from(context.itemMap.values());
|
|
82
|
-
var orderedItems = items.sort(function (a, b) {
|
|
83
|
-
return orderedNodes.indexOf(a.ref.current) - orderedNodes.indexOf(b.ref.current);
|
|
84
|
-
});
|
|
85
|
-
return orderedItems;
|
|
86
|
-
}, [context.collectionRef, context.itemMap]);
|
|
87
|
-
return getItems;
|
|
88
|
-
}
|
|
89
|
-
return [{
|
|
90
|
-
Provider: CollectionProvider,
|
|
91
|
-
Slot: CollectionSlot,
|
|
92
|
-
ItemSlot: CollectionItemSlot
|
|
93
|
-
}, useCollection];
|
|
8
|
+
var { Provider: CollectionProviderImpl, useStyledContext: useCollectionContext } = createStyledContext({
|
|
9
|
+
collectionRef: { current: void 0 },
|
|
10
|
+
itemMap: /* @__PURE__ */ new Map()
|
|
11
|
+
}, "Toast");
|
|
12
|
+
var CollectionProvider = function(props) {
|
|
13
|
+
var { scope, children } = props;
|
|
14
|
+
var ref = React.useRef(void 0);
|
|
15
|
+
var itemMap = React.useRef(/* @__PURE__ */ new Map()).current;
|
|
16
|
+
return /* @__PURE__ */ jsx(CollectionProviderImpl, {
|
|
17
|
+
scope,
|
|
18
|
+
itemMap,
|
|
19
|
+
collectionRef: ref,
|
|
20
|
+
children
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
CollectionProvider.displayName = "CollectionProvider";
|
|
24
|
+
var COLLECTION_SLOT_NAME = name + "CollectionSlot";
|
|
25
|
+
var CollectionSlot = createRefComponent(function(props, forwardedRef) {
|
|
26
|
+
var { scope, children } = props;
|
|
27
|
+
var context = useCollectionContext(scope);
|
|
28
|
+
var composedRefs = useComposedRefs(forwardedRef, context.collectionRef);
|
|
29
|
+
return /* @__PURE__ */ jsx(Slot, {
|
|
30
|
+
ref: composedRefs,
|
|
31
|
+
children
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
CollectionSlot.displayName = COLLECTION_SLOT_NAME;
|
|
35
|
+
var ITEM_SLOT_NAME = name + "CollectionItemSlot";
|
|
36
|
+
var ITEM_DATA_ATTR = "data-collection-item";
|
|
37
|
+
var CollectionItemSlot = createRefComponent(function(props, forwardedRef) {
|
|
38
|
+
var { scope, children, ...itemData } = props;
|
|
39
|
+
var ref = React.useRef(void 0);
|
|
40
|
+
var composedRefs = useComposedRefs(forwardedRef, ref);
|
|
41
|
+
var context = useCollectionContext(scope);
|
|
42
|
+
React.useEffect(function() {
|
|
43
|
+
context.itemMap.set(ref, {
|
|
44
|
+
ref,
|
|
45
|
+
...itemData
|
|
46
|
+
});
|
|
47
|
+
return function() {
|
|
48
|
+
return void context.itemMap.delete(ref);
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
return /* @__PURE__ */ jsx(Slot, {
|
|
52
|
+
[ITEM_DATA_ATTR]: "",
|
|
53
|
+
ref: composedRefs,
|
|
54
|
+
children
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
CollectionItemSlot.displayName = ITEM_SLOT_NAME;
|
|
58
|
+
function useCollection(scope) {
|
|
59
|
+
var context = useCollectionContext(scope);
|
|
60
|
+
var getItems = React.useCallback(function() {
|
|
61
|
+
if (!isWeb) {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
var collectionNode = context.collectionRef.current;
|
|
65
|
+
if (!collectionNode) return [];
|
|
66
|
+
var orderedNodes = Array.from(collectionNode.querySelectorAll(`[${ITEM_DATA_ATTR}]`));
|
|
67
|
+
var items = Array.from(context.itemMap.values());
|
|
68
|
+
var orderedItems = items.sort(function(a, b) {
|
|
69
|
+
return orderedNodes.indexOf(a.ref.current) - orderedNodes.indexOf(b.ref.current);
|
|
70
|
+
});
|
|
71
|
+
return orderedItems;
|
|
72
|
+
}, [context.collectionRef, context.itemMap]);
|
|
73
|
+
return getItems;
|
|
74
|
+
}
|
|
75
|
+
return [{
|
|
76
|
+
Provider: CollectionProvider,
|
|
77
|
+
Slot: CollectionSlot,
|
|
78
|
+
ItemSlot: CollectionItemSlot
|
|
79
|
+
}, useCollection];
|
|
94
80
|
}
|
|
81
|
+
|
|
95
82
|
export { createCollection };
|
|
96
83
|
//# sourceMappingURL=Collection.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"file":"Collection.native.js","names":[],"sources":["esm/Collection.native.js"],"sourcesContent":["import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { createRefComponent } from \"@tamagui/core\";\nimport { useComposedRefs } from \"@tamagui/compose-refs\";\nimport { isWeb } from \"@tamagui/constants\";\nimport { Slot, createStyledContext } from \"@tamagui/core\";\nimport React from \"react\";\nfunction createCollection(name) {\n var { Provider: CollectionProviderImpl, useStyledContext: useCollectionContext } = createStyledContext({\n collectionRef: {\n current: void 0\n },\n itemMap: /* @__PURE__ */ new Map()\n }, \"Toast\");\n var CollectionProvider = function(props) {\n var { scope, children } = props;\n var ref = React.useRef(void 0);\n var itemMap = React.useRef(/* @__PURE__ */ new Map()).current;\n return /* @__PURE__ */ _jsx(CollectionProviderImpl, {\n scope,\n itemMap,\n collectionRef: ref,\n children\n });\n };\n CollectionProvider.displayName = \"CollectionProvider\";\n var COLLECTION_SLOT_NAME = name + \"CollectionSlot\";\n var CollectionSlot = createRefComponent(function(props, forwardedRef) {\n var { scope, children } = props;\n var context = useCollectionContext(scope);\n var composedRefs = useComposedRefs(forwardedRef, context.collectionRef);\n return /* @__PURE__ */ _jsx(Slot, {\n ref: composedRefs,\n children\n });\n });\n CollectionSlot.displayName = COLLECTION_SLOT_NAME;\n var ITEM_SLOT_NAME = name + \"CollectionItemSlot\";\n var ITEM_DATA_ATTR = \"data-collection-item\";\n var CollectionItemSlot = createRefComponent(function(props, forwardedRef) {\n var { scope, children, ...itemData } = props;\n var ref = React.useRef(void 0);\n var composedRefs = useComposedRefs(forwardedRef, ref);\n var context = useCollectionContext(scope);\n React.useEffect(function() {\n context.itemMap.set(ref, {\n ref,\n ...itemData\n });\n return function() {\n return void context.itemMap.delete(ref);\n };\n });\n return /* @__PURE__ */ _jsx(Slot, {\n [ITEM_DATA_ATTR]: \"\",\n ref: composedRefs,\n children\n });\n });\n CollectionItemSlot.displayName = ITEM_SLOT_NAME;\n function useCollection(scope) {\n var context = useCollectionContext(scope);\n var getItems = React.useCallback(function() {\n if (!isWeb) {\n return [];\n }\n var collectionNode = context.collectionRef.current;\n if (!collectionNode) return [];\n var orderedNodes = Array.from(collectionNode.querySelectorAll(`[${ITEM_DATA_ATTR}]`));\n var items = Array.from(context.itemMap.values());\n var orderedItems = items.sort(function(a, b) {\n return orderedNodes.indexOf(a.ref.current) - orderedNodes.indexOf(b.ref.current);\n });\n return orderedItems;\n }, [\n context.collectionRef,\n context.itemMap\n ]);\n return getItems;\n }\n return [\n {\n Provider: CollectionProvider,\n Slot: CollectionSlot,\n ItemSlot: CollectionItemSlot\n },\n useCollection\n ];\n}\nexport {\n createCollection\n};\n//# sourceMappingURL=Collection.js.map\n"],"mappings":";;;;;;;AAMA,SAAS,iBAAiB,MAAM;CAC9B,IAAI,EAAE,UAAU,wBAAwB,kBAAkB,yBAAyB,oBAAoB;EACrG,eAAe,EACb,SAAS,KAAK,EAChB;EACA,yBAAyB,IAAI,IAAI;CACnC,GAAG,OAAO;CACV,IAAI,qBAAqB,SAAS,OAAO;EACvC,IAAI,EAAE,OAAO,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B,IAAI,eAAe,EAAE,CAAC;GACpF,IAAI,QAAQ,MAAM,KAAK,QAAQ,QAAQ,OAAO,CAAC;GAC/C,IAAI,eAAe,MAAM,KAAK,SAAS,GAAG,GAAG;IAC3C,OAAO,aAAa,QAAQ,EAAE,IAAI,OAAO,IAAI,aAAa,QAAQ,EAAE,IAAI,OAAO;GACjF,CAAC;GACD,OAAO;EACT,GAAG,CACD,QAAQ,eACR,QAAQ,OACV,CAAC;EACD,OAAO;CACT;CACA,OAAO,CACL;EACE,UAAU;EACV,MAAM;EACN,UAAU;CACZ,GACA,aACF;AACF"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export * from "./Collection.mjs"
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export * from "./Collection.mjs"
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export * from "./Collection.mjs"
|
|
2
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
export * from "./Collection.mjs"
|
package/dist/esm/index.native.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export * from "./Collection.native.js"
|
|
2
|
-
//# sourceMappingURL=index.native.js.map
|
|
1
|
+
export * from "./Collection.native.js"
|