@tamagui/collection 1.61.3 → 1.62.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.js +19 -50
- package/dist/cjs/Collection.js.map +1 -1
- package/dist/cjs/Collection.native.js +79 -0
- package/dist/cjs/Collection.native.js.map +6 -0
- package/dist/cjs/index.js +4 -8
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.native.js +20 -0
- package/dist/cjs/index.native.js.map +6 -0
- package/dist/esm/Collection.js +12 -33
- package/dist/esm/Collection.js.map +1 -1
- package/dist/jsx/Collection.js +11 -32
- package/dist/jsx/Collection.js.map +1 -1
- package/dist/jsx/Collection.native.js +53 -0
- package/dist/jsx/Collection.native.js.map +6 -0
- package/dist/jsx/index.native.js +2 -0
- package/dist/jsx/index.native.js.map +6 -0
- package/package.json +8 -8
package/dist/cjs/Collection.js
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable:
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
14
11
|
for (let key of __getOwnPropNames(from))
|
|
15
|
-
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
12
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
13
|
return to;
|
|
19
14
|
};
|
|
20
15
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
@@ -22,79 +17,53 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
17
|
// file that has been converted to a CommonJS file using a Babel-
|
|
23
18
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
19
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable:
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
26
21
|
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
29
23
|
var Collection_exports = {};
|
|
30
24
|
__export(Collection_exports, {
|
|
31
25
|
createCollection: () => createCollection
|
|
32
26
|
});
|
|
33
27
|
module.exports = __toCommonJS(Collection_exports);
|
|
34
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
35
|
-
var import_compose_refs = require("@tamagui/compose-refs");
|
|
36
|
-
var import_core = require("@tamagui/core");
|
|
37
|
-
var import_create_context = require("@tamagui/create-context");
|
|
38
|
-
var import_react = __toESM(require("react"));
|
|
28
|
+
var import_compose_refs = require("@tamagui/compose-refs"), import_core = require("@tamagui/core"), import_create_context = require("@tamagui/create-context"), import_react = __toESM(require("react")), import_jsx_runtime = require("react/jsx-runtime");
|
|
39
29
|
function createCollection(name) {
|
|
40
|
-
const PROVIDER_NAME = name + "CollectionProvider"
|
|
41
|
-
const [createCollectionContext, createCollectionScope] = (0, import_create_context.createContextScope)(PROVIDER_NAME);
|
|
42
|
-
const [CollectionProviderImpl, useCollectionContext] = createCollectionContext(PROVIDER_NAME, {
|
|
30
|
+
const PROVIDER_NAME = name + "CollectionProvider", [createCollectionContext, createCollectionScope] = (0, import_create_context.createContextScope)(PROVIDER_NAME), [CollectionProviderImpl, useCollectionContext] = createCollectionContext(PROVIDER_NAME, {
|
|
43
31
|
collectionRef: { current: null },
|
|
44
32
|
itemMap: /* @__PURE__ */ new Map()
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
const { scope, children } = props;
|
|
48
|
-
const ref = import_react.default.useRef(null);
|
|
49
|
-
const itemMap = import_react.default.useRef(/* @__PURE__ */ new Map()).current;
|
|
33
|
+
}), CollectionProvider = (props) => {
|
|
34
|
+
const { scope, children } = props, ref = import_react.default.useRef(null), itemMap = import_react.default.useRef(/* @__PURE__ */ new Map()).current;
|
|
50
35
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CollectionProviderImpl, { scope, itemMap, collectionRef: ref, children });
|
|
51
36
|
};
|
|
52
37
|
CollectionProvider.displayName = PROVIDER_NAME;
|
|
53
|
-
const COLLECTION_SLOT_NAME = name + "CollectionSlot"
|
|
54
|
-
const CollectionSlot = import_react.default.forwardRef(
|
|
38
|
+
const COLLECTION_SLOT_NAME = name + "CollectionSlot", CollectionSlot = import_react.default.forwardRef(
|
|
55
39
|
(props, forwardedRef) => {
|
|
56
|
-
const { scope, children } = props;
|
|
57
|
-
const context = useCollectionContext(COLLECTION_SLOT_NAME, scope);
|
|
58
|
-
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, context.collectionRef);
|
|
40
|
+
const { scope, children } = props, context = useCollectionContext(COLLECTION_SLOT_NAME, scope), composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, context.collectionRef);
|
|
59
41
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Slot, { ref: composedRefs, children });
|
|
60
42
|
}
|
|
61
43
|
);
|
|
62
44
|
CollectionSlot.displayName = COLLECTION_SLOT_NAME;
|
|
63
|
-
const ITEM_SLOT_NAME = name + "CollectionItemSlot"
|
|
64
|
-
const ITEM_DATA_ATTR = "data-collection-item";
|
|
65
|
-
const CollectionItemSlot = import_react.default.forwardRef(
|
|
45
|
+
const ITEM_SLOT_NAME = name + "CollectionItemSlot", ITEM_DATA_ATTR = "data-collection-item", CollectionItemSlot = import_react.default.forwardRef(
|
|
66
46
|
(props, forwardedRef) => {
|
|
67
|
-
const { scope, children, ...itemData } = props;
|
|
68
|
-
|
|
69
|
-
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref);
|
|
70
|
-
const context = useCollectionContext(ITEM_SLOT_NAME, scope);
|
|
71
|
-
import_react.default.useEffect(() => {
|
|
72
|
-
context.itemMap.set(ref, { ref, ...itemData });
|
|
73
|
-
return () => void context.itemMap.delete(ref);
|
|
74
|
-
});
|
|
75
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Slot, { ...{ [ITEM_DATA_ATTR]: "" }, ref: composedRefs, children });
|
|
47
|
+
const { scope, children, ...itemData } = props, ref = import_react.default.useRef(null), composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref), context = useCollectionContext(ITEM_SLOT_NAME, scope);
|
|
48
|
+
return import_react.default.useEffect(() => (context.itemMap.set(ref, { ref, ...itemData }), () => void context.itemMap.delete(ref))), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Slot, { [ITEM_DATA_ATTR]: "", ref: composedRefs, children });
|
|
76
49
|
}
|
|
77
50
|
);
|
|
78
51
|
CollectionItemSlot.displayName = ITEM_SLOT_NAME;
|
|
79
52
|
function useCollection(scope) {
|
|
80
53
|
const context = useCollectionContext(name + "CollectionConsumer", scope);
|
|
81
|
-
|
|
82
|
-
if (!import_core.isWeb)
|
|
54
|
+
return import_react.default.useCallback(() => {
|
|
55
|
+
if (!import_core.isWeb)
|
|
83
56
|
return [];
|
|
84
|
-
}
|
|
85
57
|
const collectionNode = context.collectionRef.current;
|
|
86
58
|
if (!collectionNode)
|
|
87
59
|
return [];
|
|
88
60
|
const orderedNodes = Array.from(
|
|
89
61
|
collectionNode.querySelectorAll(`[${ITEM_DATA_ATTR}]`)
|
|
90
62
|
);
|
|
91
|
-
|
|
92
|
-
const orderedItems = items.sort(
|
|
63
|
+
return Array.from(context.itemMap.values()).sort(
|
|
93
64
|
(a, b) => orderedNodes.indexOf(a.ref.current) - orderedNodes.indexOf(b.ref.current)
|
|
94
65
|
);
|
|
95
|
-
return orderedItems;
|
|
96
66
|
}, [context.collectionRef, context.itemMap]);
|
|
97
|
-
return getItems;
|
|
98
67
|
}
|
|
99
68
|
return [
|
|
100
69
|
{ Provider: CollectionProvider, Slot: CollectionSlot, ItemSlot: CollectionItemSlot },
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Collection.tsx"],
|
|
4
|
-
"mappings": "
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAgC,kCAChC,cAA4C,0BAC5C,wBAAmC,oCACnC,eAAkB,2BA6CZ;AAhCN,SAAS,iBACP,MACA;AAKA,QAAM,gBAAgB,OAAO,sBACvB,CAAC,yBAAyB,qBAAqB,QACnD,0CAAmB,aAAa,GAU5B,CAAC,wBAAwB,oBAAoB,IACjD,wBAAsC,eAAe;AAAA,IACnD,eAAe,EAAE,SAAS,KAAK;AAAA,IAC/B,SAAS,oBAAI,IAAI;AAAA,EACnB,CAAC,GAEG,qBAA2E,CAC/E,UACG;AACH,UAAM,EAAE,OAAO,SAAS,IAAI,OACtB,MAAM,aAAAA,QAAM,OAA0B,IAAI,GAC1C,UAAU,aAAAA,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vD;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": ["React"]
|
|
6
6
|
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
10
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
22
|
+
mod
|
|
23
|
+
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
24
|
+
var Collection_exports = {};
|
|
25
|
+
__export(Collection_exports, {
|
|
26
|
+
createCollection: () => createCollection
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(Collection_exports);
|
|
29
|
+
var import_compose_refs = require("@tamagui/compose-refs"), import_core = require("@tamagui/core"), import_create_context = require("@tamagui/create-context"), import_react = __toESM(require("react")), import_jsx_runtime = require("react/jsx-runtime");
|
|
30
|
+
function createCollection(name) {
|
|
31
|
+
const PROVIDER_NAME = name + "CollectionProvider", [createCollectionContext, createCollectionScope] = (0, import_create_context.createContextScope)(PROVIDER_NAME), [CollectionProviderImpl, useCollectionContext] = createCollectionContext(PROVIDER_NAME, {
|
|
32
|
+
collectionRef: { current: null },
|
|
33
|
+
itemMap: /* @__PURE__ */ new Map()
|
|
34
|
+
}), CollectionProvider = (props) => {
|
|
35
|
+
const { scope, children } = props, ref = import_react.default.useRef(null), itemMap = import_react.default.useRef(/* @__PURE__ */ new Map()).current;
|
|
36
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CollectionProviderImpl, { scope, itemMap, collectionRef: ref, children });
|
|
37
|
+
};
|
|
38
|
+
CollectionProvider.displayName = PROVIDER_NAME;
|
|
39
|
+
const COLLECTION_SLOT_NAME = name + "CollectionSlot", CollectionSlot = import_react.default.forwardRef(
|
|
40
|
+
(props, forwardedRef) => {
|
|
41
|
+
const { scope, children } = props, context = useCollectionContext(COLLECTION_SLOT_NAME, scope), composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, context.collectionRef);
|
|
42
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Slot, { ref: composedRefs, children });
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
CollectionSlot.displayName = COLLECTION_SLOT_NAME;
|
|
46
|
+
const ITEM_SLOT_NAME = name + "CollectionItemSlot", ITEM_DATA_ATTR = "data-collection-item", CollectionItemSlot = import_react.default.forwardRef(
|
|
47
|
+
(props, forwardedRef) => {
|
|
48
|
+
const { scope, children, ...itemData } = props, ref = import_react.default.useRef(null), composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref), context = useCollectionContext(ITEM_SLOT_NAME, scope);
|
|
49
|
+
return import_react.default.useEffect(() => (context.itemMap.set(ref, { ref, ...itemData }), () => void context.itemMap.delete(ref))), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Slot, { [ITEM_DATA_ATTR]: "", ref: composedRefs, children });
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
CollectionItemSlot.displayName = ITEM_SLOT_NAME;
|
|
53
|
+
function useCollection(scope) {
|
|
54
|
+
const context = useCollectionContext(name + "CollectionConsumer", scope);
|
|
55
|
+
return import_react.default.useCallback(() => {
|
|
56
|
+
if (!import_core.isWeb)
|
|
57
|
+
return [];
|
|
58
|
+
const collectionNode = context.collectionRef.current;
|
|
59
|
+
if (!collectionNode)
|
|
60
|
+
return [];
|
|
61
|
+
const orderedNodes = Array.from(
|
|
62
|
+
collectionNode.querySelectorAll(`[${ITEM_DATA_ATTR}]`)
|
|
63
|
+
);
|
|
64
|
+
return Array.from(context.itemMap.values()).sort(
|
|
65
|
+
(a, b) => orderedNodes.indexOf(a.ref.current) - orderedNodes.indexOf(b.ref.current)
|
|
66
|
+
);
|
|
67
|
+
}, [context.collectionRef, context.itemMap]);
|
|
68
|
+
}
|
|
69
|
+
return [
|
|
70
|
+
{ Provider: CollectionProvider, Slot: CollectionSlot, ItemSlot: CollectionItemSlot },
|
|
71
|
+
useCollection,
|
|
72
|
+
createCollectionScope
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
76
|
+
0 && (module.exports = {
|
|
77
|
+
createCollection
|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,MAAM,aAAAA,QAAM,OAAoB,IAAI,GACpC,mBAAe,qCAAgB,cAAc,GAAG,GAChD,UAAU,qBAAqB,gBAAgB,KAAK;AAE1D,0BAAAA,QAAM,UAAU,OACd,QAAQ,QAAQ,IAAI,KAAK,EAAE,KAAK,GAAI,SAAiC,CAAC,GAC/D,MAAM,KAAK,QAAQ,QAAQ,OAAO,GAAG,EAC7C,GAGC,4CAAC,oBAAW,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,aAAAA,QAAM,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
|
+
"names": ["React"]
|
|
6
|
+
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
5
|
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from
|
|
6
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
8
7
|
for (let key of __getOwnPropNames(from))
|
|
9
|
-
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
8
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
9
|
return to;
|
|
13
|
-
};
|
|
14
|
-
var
|
|
15
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
10
|
+
}, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
11
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
16
12
|
var src_exports = {};
|
|
17
13
|
module.exports = __toCommonJS(src_exports);
|
|
18
14
|
__reExport(src_exports, require("./Collection"), module.exports);
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
return to;
|
|
11
|
+
}, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
12
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
13
|
+
var src_exports = {};
|
|
14
|
+
module.exports = __toCommonJS(src_exports);
|
|
15
|
+
__reExport(src_exports, require("./Collection"), module.exports);
|
|
16
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
17
|
+
0 && (module.exports = {
|
|
18
|
+
...require("./Collection")
|
|
19
|
+
});
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
package/dist/esm/Collection.js
CHANGED
|
@@ -1,67 +1,46 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
1
|
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
3
2
|
import { Slot, isWeb } from "@tamagui/core";
|
|
4
3
|
import { createContextScope } from "@tamagui/create-context";
|
|
5
4
|
import React from "react";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
6
|
function createCollection(name) {
|
|
7
|
-
const PROVIDER_NAME = name + "CollectionProvider"
|
|
8
|
-
const [createCollectionContext, createCollectionScope] = createContextScope(PROVIDER_NAME);
|
|
9
|
-
const [CollectionProviderImpl, useCollectionContext] = createCollectionContext(PROVIDER_NAME, {
|
|
7
|
+
const PROVIDER_NAME = name + "CollectionProvider", [createCollectionContext, createCollectionScope] = createContextScope(PROVIDER_NAME), [CollectionProviderImpl, useCollectionContext] = createCollectionContext(PROVIDER_NAME, {
|
|
10
8
|
collectionRef: { current: null },
|
|
11
9
|
itemMap: /* @__PURE__ */ new Map()
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
const { scope, children } = props;
|
|
15
|
-
const ref = React.useRef(null);
|
|
16
|
-
const itemMap = React.useRef(/* @__PURE__ */ new Map()).current;
|
|
10
|
+
}), CollectionProvider = (props) => {
|
|
11
|
+
const { scope, children } = props, ref = React.useRef(null), itemMap = React.useRef(/* @__PURE__ */ new Map()).current;
|
|
17
12
|
return /* @__PURE__ */ jsx(CollectionProviderImpl, { scope, itemMap, collectionRef: ref, children });
|
|
18
13
|
};
|
|
19
14
|
CollectionProvider.displayName = PROVIDER_NAME;
|
|
20
|
-
const COLLECTION_SLOT_NAME = name + "CollectionSlot"
|
|
21
|
-
const CollectionSlot = React.forwardRef(
|
|
15
|
+
const COLLECTION_SLOT_NAME = name + "CollectionSlot", CollectionSlot = React.forwardRef(
|
|
22
16
|
(props, forwardedRef) => {
|
|
23
|
-
const { scope, children } = props;
|
|
24
|
-
const context = useCollectionContext(COLLECTION_SLOT_NAME, scope);
|
|
25
|
-
const composedRefs = useComposedRefs(forwardedRef, context.collectionRef);
|
|
17
|
+
const { scope, children } = props, context = useCollectionContext(COLLECTION_SLOT_NAME, scope), composedRefs = useComposedRefs(forwardedRef, context.collectionRef);
|
|
26
18
|
return /* @__PURE__ */ jsx(Slot, { ref: composedRefs, children });
|
|
27
19
|
}
|
|
28
20
|
);
|
|
29
21
|
CollectionSlot.displayName = COLLECTION_SLOT_NAME;
|
|
30
|
-
const ITEM_SLOT_NAME = name + "CollectionItemSlot"
|
|
31
|
-
const ITEM_DATA_ATTR = "data-collection-item";
|
|
32
|
-
const CollectionItemSlot = React.forwardRef(
|
|
22
|
+
const ITEM_SLOT_NAME = name + "CollectionItemSlot", ITEM_DATA_ATTR = "data-collection-item", CollectionItemSlot = React.forwardRef(
|
|
33
23
|
(props, forwardedRef) => {
|
|
34
|
-
const { scope, children, ...itemData } = props;
|
|
35
|
-
|
|
36
|
-
const composedRefs = useComposedRefs(forwardedRef, ref);
|
|
37
|
-
const context = useCollectionContext(ITEM_SLOT_NAME, scope);
|
|
38
|
-
React.useEffect(() => {
|
|
39
|
-
context.itemMap.set(ref, { ref, ...itemData });
|
|
40
|
-
return () => void context.itemMap.delete(ref);
|
|
41
|
-
});
|
|
42
|
-
return /* @__PURE__ */ jsx(Slot, { ...{ [ITEM_DATA_ATTR]: "" }, ref: composedRefs, children });
|
|
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 });
|
|
43
26
|
}
|
|
44
27
|
);
|
|
45
28
|
CollectionItemSlot.displayName = ITEM_SLOT_NAME;
|
|
46
29
|
function useCollection(scope) {
|
|
47
30
|
const context = useCollectionContext(name + "CollectionConsumer", scope);
|
|
48
|
-
|
|
49
|
-
if (!isWeb)
|
|
31
|
+
return React.useCallback(() => {
|
|
32
|
+
if (!isWeb)
|
|
50
33
|
return [];
|
|
51
|
-
}
|
|
52
34
|
const collectionNode = context.collectionRef.current;
|
|
53
35
|
if (!collectionNode)
|
|
54
36
|
return [];
|
|
55
37
|
const orderedNodes = Array.from(
|
|
56
38
|
collectionNode.querySelectorAll(`[${ITEM_DATA_ATTR}]`)
|
|
57
39
|
);
|
|
58
|
-
|
|
59
|
-
const orderedItems = items.sort(
|
|
40
|
+
return Array.from(context.itemMap.values()).sort(
|
|
60
41
|
(a, b) => orderedNodes.indexOf(a.ref.current) - orderedNodes.indexOf(b.ref.current)
|
|
61
42
|
);
|
|
62
|
-
return orderedItems;
|
|
63
43
|
}, [context.collectionRef, context.itemMap]);
|
|
64
|
-
return getItems;
|
|
65
44
|
}
|
|
66
45
|
return [
|
|
67
46
|
{ Provider: CollectionProvider, Slot: CollectionSlot, ItemSlot: CollectionItemSlot },
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Collection.tsx"],
|
|
4
|
-
"mappings": "
|
|
4
|
+
"mappings": "AAAA,SAAS,uBAAuB;AAChC,SAAS,MAAsB,aAAa;AAC5C,SAAS,0BAA0B;AACnC,OAAO,WAAW;AA6CZ;AA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B,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/dist/jsx/Collection.js
CHANGED
|
@@ -3,64 +3,43 @@ import { Slot, isWeb } from "@tamagui/core";
|
|
|
3
3
|
import { createContextScope } from "@tamagui/create-context";
|
|
4
4
|
import React from "react";
|
|
5
5
|
function createCollection(name) {
|
|
6
|
-
const PROVIDER_NAME = name + "CollectionProvider"
|
|
7
|
-
const [createCollectionContext, createCollectionScope] = createContextScope(PROVIDER_NAME);
|
|
8
|
-
const [CollectionProviderImpl, useCollectionContext] = createCollectionContext(PROVIDER_NAME, {
|
|
6
|
+
const PROVIDER_NAME = name + "CollectionProvider", [createCollectionContext, createCollectionScope] = createContextScope(PROVIDER_NAME), [CollectionProviderImpl, useCollectionContext] = createCollectionContext(PROVIDER_NAME, {
|
|
9
7
|
collectionRef: { current: null },
|
|
10
8
|
itemMap: /* @__PURE__ */ new Map()
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
const { scope, children } = props;
|
|
14
|
-
const ref = React.useRef(null);
|
|
15
|
-
const itemMap = React.useRef(/* @__PURE__ */ new Map()).current;
|
|
9
|
+
}), CollectionProvider = (props) => {
|
|
10
|
+
const { scope, children } = props, ref = React.useRef(null), itemMap = React.useRef(/* @__PURE__ */ new Map()).current;
|
|
16
11
|
return <CollectionProviderImpl scope={scope} itemMap={itemMap} collectionRef={ref}>{children}</CollectionProviderImpl>;
|
|
17
12
|
};
|
|
18
13
|
CollectionProvider.displayName = PROVIDER_NAME;
|
|
19
|
-
const COLLECTION_SLOT_NAME = name + "CollectionSlot"
|
|
20
|
-
const CollectionSlot = React.forwardRef(
|
|
14
|
+
const COLLECTION_SLOT_NAME = name + "CollectionSlot", CollectionSlot = React.forwardRef(
|
|
21
15
|
(props, forwardedRef) => {
|
|
22
|
-
const { scope, children } = props;
|
|
23
|
-
const context = useCollectionContext(COLLECTION_SLOT_NAME, scope);
|
|
24
|
-
const composedRefs = useComposedRefs(forwardedRef, context.collectionRef);
|
|
16
|
+
const { scope, children } = props, context = useCollectionContext(COLLECTION_SLOT_NAME, scope), composedRefs = useComposedRefs(forwardedRef, context.collectionRef);
|
|
25
17
|
return <Slot ref={composedRefs}>{children}</Slot>;
|
|
26
18
|
}
|
|
27
19
|
);
|
|
28
20
|
CollectionSlot.displayName = COLLECTION_SLOT_NAME;
|
|
29
|
-
const ITEM_SLOT_NAME = name + "CollectionItemSlot"
|
|
30
|
-
const ITEM_DATA_ATTR = "data-collection-item";
|
|
31
|
-
const CollectionItemSlot = React.forwardRef(
|
|
21
|
+
const ITEM_SLOT_NAME = name + "CollectionItemSlot", ITEM_DATA_ATTR = "data-collection-item", CollectionItemSlot = React.forwardRef(
|
|
32
22
|
(props, forwardedRef) => {
|
|
33
|
-
const { scope, children, ...itemData } = props;
|
|
34
|
-
|
|
35
|
-
const composedRefs = useComposedRefs(forwardedRef, ref);
|
|
36
|
-
const context = useCollectionContext(ITEM_SLOT_NAME, scope);
|
|
37
|
-
React.useEffect(() => {
|
|
38
|
-
context.itemMap.set(ref, { ref, ...itemData });
|
|
39
|
-
return () => void context.itemMap.delete(ref);
|
|
40
|
-
});
|
|
41
|
-
return <Slot {...{ [ITEM_DATA_ATTR]: "" }} ref={composedRefs}>{children}</Slot>;
|
|
23
|
+
const { scope, children, ...itemData } = props, ref = React.useRef(null), composedRefs = useComposedRefs(forwardedRef, ref), context = useCollectionContext(ITEM_SLOT_NAME, scope);
|
|
24
|
+
return React.useEffect(() => (context.itemMap.set(ref, { ref, ...itemData }), () => void context.itemMap.delete(ref))), <Slot {...{ [ITEM_DATA_ATTR]: "" }} ref={composedRefs}>{children}</Slot>;
|
|
42
25
|
}
|
|
43
26
|
);
|
|
44
27
|
CollectionItemSlot.displayName = ITEM_SLOT_NAME;
|
|
45
28
|
function useCollection(scope) {
|
|
46
29
|
const context = useCollectionContext(name + "CollectionConsumer", scope);
|
|
47
|
-
|
|
48
|
-
if (!isWeb)
|
|
30
|
+
return React.useCallback(() => {
|
|
31
|
+
if (!isWeb)
|
|
49
32
|
return [];
|
|
50
|
-
}
|
|
51
33
|
const collectionNode = context.collectionRef.current;
|
|
52
34
|
if (!collectionNode)
|
|
53
35
|
return [];
|
|
54
36
|
const orderedNodes = Array.from(
|
|
55
37
|
collectionNode.querySelectorAll(`[${ITEM_DATA_ATTR}]`)
|
|
56
38
|
);
|
|
57
|
-
|
|
58
|
-
const orderedItems = items.sort(
|
|
39
|
+
return Array.from(context.itemMap.values()).sort(
|
|
59
40
|
(a, b) => orderedNodes.indexOf(a.ref.current) - orderedNodes.indexOf(b.ref.current)
|
|
60
41
|
);
|
|
61
|
-
return orderedItems;
|
|
62
42
|
}, [context.collectionRef, context.itemMap]);
|
|
63
|
-
return getItems;
|
|
64
43
|
}
|
|
65
44
|
return [
|
|
66
45
|
{ Provider: CollectionProvider, Slot: CollectionSlot, ItemSlot: CollectionItemSlot },
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2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nC,MAAM,MAAM,OAAoB,IAAI,GACpC,eAAe,gBAAgB,cAAc,GAAG,GAChD,UAAU,qBAAqB,gBAAgB,KAAK;AAE1D,mBAAM,UAAU,OACd,QAAQ,QAAQ,IAAI,KAAK,EAAE,KAAK,GAAI,SAAiC,CAAC,GAC/D,MAAM,KAAK,QAAQ,QAAQ,OAAO,GAAG,EAC7C,GAGC,CAAC,YAAY,iBAAiB,MAAM,KAAK,eACtC,SACH,EAFC;AAAA,IAIL;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
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
function createCollection(name) {
|
|
6
|
+
const PROVIDER_NAME = name + "CollectionProvider", [createCollectionContext, createCollectionScope] = createContextScope(PROVIDER_NAME), [CollectionProviderImpl, useCollectionContext] = createCollectionContext(PROVIDER_NAME, {
|
|
7
|
+
collectionRef: { current: null },
|
|
8
|
+
itemMap: /* @__PURE__ */ new Map()
|
|
9
|
+
}), CollectionProvider = (props) => {
|
|
10
|
+
const { scope, children } = props, ref = React.useRef(null), itemMap = React.useRef(/* @__PURE__ */ new Map()).current;
|
|
11
|
+
return <CollectionProviderImpl scope={scope} itemMap={itemMap} collectionRef={ref}>{children}</CollectionProviderImpl>;
|
|
12
|
+
};
|
|
13
|
+
CollectionProvider.displayName = PROVIDER_NAME;
|
|
14
|
+
const COLLECTION_SLOT_NAME = name + "CollectionSlot", CollectionSlot = React.forwardRef(
|
|
15
|
+
(props, forwardedRef) => {
|
|
16
|
+
const { scope, children } = props, context = useCollectionContext(COLLECTION_SLOT_NAME, scope), composedRefs = useComposedRefs(forwardedRef, context.collectionRef);
|
|
17
|
+
return <Slot ref={composedRefs}>{children}</Slot>;
|
|
18
|
+
}
|
|
19
|
+
);
|
|
20
|
+
CollectionSlot.displayName = COLLECTION_SLOT_NAME;
|
|
21
|
+
const ITEM_SLOT_NAME = name + "CollectionItemSlot", ITEM_DATA_ATTR = "data-collection-item", CollectionItemSlot = React.forwardRef(
|
|
22
|
+
(props, forwardedRef) => {
|
|
23
|
+
const { scope, children, ...itemData } = props, ref = React.useRef(null), composedRefs = useComposedRefs(forwardedRef, ref), context = useCollectionContext(ITEM_SLOT_NAME, scope);
|
|
24
|
+
return React.useEffect(() => (context.itemMap.set(ref, { ref, ...itemData }), () => void context.itemMap.delete(ref))), <Slot {...{ [ITEM_DATA_ATTR]: "" }} ref={composedRefs}>{children}</Slot>;
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
CollectionItemSlot.displayName = ITEM_SLOT_NAME;
|
|
28
|
+
function useCollection(scope) {
|
|
29
|
+
const context = useCollectionContext(name + "CollectionConsumer", scope);
|
|
30
|
+
return React.useCallback(() => {
|
|
31
|
+
if (!isWeb)
|
|
32
|
+
return [];
|
|
33
|
+
const collectionNode = context.collectionRef.current;
|
|
34
|
+
if (!collectionNode)
|
|
35
|
+
return [];
|
|
36
|
+
const orderedNodes = Array.from(
|
|
37
|
+
collectionNode.querySelectorAll(`[${ITEM_DATA_ATTR}]`)
|
|
38
|
+
);
|
|
39
|
+
return Array.from(context.itemMap.values()).sort(
|
|
40
|
+
(a, b) => orderedNodes.indexOf(a.ref.current) - orderedNodes.indexOf(b.ref.current)
|
|
41
|
+
);
|
|
42
|
+
}, [context.collectionRef, context.itemMap]);
|
|
43
|
+
}
|
|
44
|
+
return [
|
|
45
|
+
{ Provider: CollectionProvider, Slot: CollectionSlot, ItemSlot: CollectionItemSlot },
|
|
46
|
+
useCollection,
|
|
47
|
+
createCollectionScope
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
createCollection
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=Collection.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Collection.tsx"],
|
|
4
|
+
"mappings": "AAAA,SAAS,uBAAuB;AAChC,SAAS,MAAsB,aAAa;AAC5C,SAAS,0BAA0B;AACnC,OAAO,WAAW;AAalB,SAAS,iBACP,MACA;AAKA,QAAM,gBAAgB,OAAO,sBACvB,CAAC,yBAAyB,qBAAqB,IACnD,mBAAmB,aAAa,GAU5B,CAAC,wBAAwB,oBAAoB,IACjD,wBAAsC,eAAe;AAAA,IACnD,eAAe,EAAE,SAAS,KAAK;AAAA,IAC/B,SAAS,oBAAI,IAAI;AAAA,EACnB,CAAC,GAEG,qBAA2E,CAC/E,UACG;AACH,UAAM,EAAE,OAAO,SAAS,IAAI,OACtB,MAAM,MAAM,OAA0B,IAAI,GAC1C,UAAU,MAAM,OAAgC,oBAAI,IAAI,CAAC,EAAE;AACjE,WACE,CAAC,uBAAuB,O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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
|
+
"names": []
|
|
6
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/collection",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.62.1",
|
|
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.62.1",
|
|
31
|
+
"@tamagui/core": "1.62.1",
|
|
32
|
+
"@tamagui/create-context": "1.62.1",
|
|
33
|
+
"@tamagui/polyfill-dev": "1.62.1",
|
|
34
|
+
"@tamagui/stacks": "1.62.1",
|
|
35
|
+
"@tamagui/use-controllable-state": "1.62.1"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"react": "*"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@tamagui/build": "1.
|
|
41
|
+
"@tamagui/build": "1.62.1",
|
|
42
42
|
"react": "^18.2.0"
|
|
43
43
|
},
|
|
44
44
|
"publishConfig": {
|