@radix-ui/react-collection 1.1.0-rc.2 → 1.1.0-rc.3

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/index.js CHANGED
@@ -1,100 +1,104 @@
1
1
  "use strict";
2
2
  "use client";
3
- (() => {
4
- var __create = Object.create;
5
- var __defProp = Object.defineProperty;
6
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
- var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getProtoOf = Object.getPrototypeOf;
9
- var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
11
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
12
- }) : x)(function(x) {
13
- if (typeof require !== "undefined") return require.apply(this, arguments);
14
- throw Error('Dynamic require of "' + x + '" is not supported');
15
- });
16
- var __copyProps = (to, from, except, desc) => {
17
- if (from && typeof from === "object" || typeof from === "function") {
18
- for (let key of __getOwnPropNames(from))
19
- if (!__hasOwnProp.call(to, key) && key !== except)
20
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
- }
22
- return to;
23
- };
24
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25
- // If the importer is in node compatibility mode or this is not an ESM
26
- // file that has been converted to a CommonJS file using a Babel-
27
- // compatible transform (i.e. "__esModule" has not been set), then set
28
- // "default" to the CommonJS "module.exports" for node compatibility.
29
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
30
- mod
31
- ));
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
30
 
33
- // packages/react/collection/src/Collection.tsx
34
- var import_react = __toESM(__require("react"));
35
- var import_react_context = __require("@radix-ui/react-context");
36
- var import_react_compose_refs = __require("@radix-ui/react-compose-refs");
37
- var import_react_slot = __require("@radix-ui/react-slot");
38
- var import_jsx_runtime = __require("react/jsx-runtime");
39
- function createCollection(name) {
40
- const PROVIDER_NAME = name + "CollectionProvider";
41
- const [createCollectionContext, createCollectionScope] = (0, import_react_context.createContextScope)(PROVIDER_NAME);
42
- const [CollectionProviderImpl, useCollectionContext] = createCollectionContext(
43
- PROVIDER_NAME,
44
- { collectionRef: { current: null }, itemMap: /* @__PURE__ */ new Map() }
45
- );
46
- const CollectionProvider = (props) => {
31
+ // packages/react/collection/src/index.ts
32
+ var src_exports = {};
33
+ __export(src_exports, {
34
+ createCollection: () => createCollection
35
+ });
36
+ module.exports = __toCommonJS(src_exports);
37
+
38
+ // packages/react/collection/src/Collection.tsx
39
+ var import_react = __toESM(require("react"));
40
+ var import_react_context = require("@radix-ui/react-context");
41
+ var import_react_compose_refs = require("@radix-ui/react-compose-refs");
42
+ var import_react_slot = require("@radix-ui/react-slot");
43
+ var import_jsx_runtime = require("react/jsx-runtime");
44
+ function createCollection(name) {
45
+ const PROVIDER_NAME = name + "CollectionProvider";
46
+ const [createCollectionContext, createCollectionScope] = (0, import_react_context.createContextScope)(PROVIDER_NAME);
47
+ const [CollectionProviderImpl, useCollectionContext] = createCollectionContext(
48
+ PROVIDER_NAME,
49
+ { collectionRef: { current: null }, itemMap: /* @__PURE__ */ new Map() }
50
+ );
51
+ const CollectionProvider = (props) => {
52
+ const { scope, children } = props;
53
+ const ref = import_react.default.useRef(null);
54
+ const itemMap = import_react.default.useRef(/* @__PURE__ */ new Map()).current;
55
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CollectionProviderImpl, { scope, itemMap, collectionRef: ref, children });
56
+ };
57
+ CollectionProvider.displayName = PROVIDER_NAME;
58
+ const COLLECTION_SLOT_NAME = name + "CollectionSlot";
59
+ const CollectionSlot = import_react.default.forwardRef(
60
+ (props, forwardedRef) => {
47
61
  const { scope, children } = props;
62
+ const context = useCollectionContext(COLLECTION_SLOT_NAME, scope);
63
+ const composedRefs = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, context.collectionRef);
64
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_slot.Slot, { ref: composedRefs, children });
65
+ }
66
+ );
67
+ CollectionSlot.displayName = COLLECTION_SLOT_NAME;
68
+ const ITEM_SLOT_NAME = name + "CollectionItemSlot";
69
+ const ITEM_DATA_ATTR = "data-radix-collection-item";
70
+ const CollectionItemSlot = import_react.default.forwardRef(
71
+ (props, forwardedRef) => {
72
+ const { scope, children, ...itemData } = props;
48
73
  const ref = import_react.default.useRef(null);
49
- const itemMap = import_react.default.useRef(/* @__PURE__ */ new Map()).current;
50
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CollectionProviderImpl, { scope, itemMap, collectionRef: ref, children });
51
- };
52
- CollectionProvider.displayName = PROVIDER_NAME;
53
- const COLLECTION_SLOT_NAME = name + "CollectionSlot";
54
- const CollectionSlot = import_react.default.forwardRef(
55
- (props, forwardedRef) => {
56
- const { scope, children } = props;
57
- const context = useCollectionContext(COLLECTION_SLOT_NAME, scope);
58
- const composedRefs = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, context.collectionRef);
59
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_slot.Slot, { ref: composedRefs, children });
60
- }
61
- );
62
- CollectionSlot.displayName = COLLECTION_SLOT_NAME;
63
- const ITEM_SLOT_NAME = name + "CollectionItemSlot";
64
- const ITEM_DATA_ATTR = "data-radix-collection-item";
65
- const CollectionItemSlot = import_react.default.forwardRef(
66
- (props, forwardedRef) => {
67
- const { scope, children, ...itemData } = props;
68
- const ref = import_react.default.useRef(null);
69
- const composedRefs = (0, import_react_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_react_slot.Slot, { ...{ [ITEM_DATA_ATTR]: "" }, ref: composedRefs, children });
76
- }
77
- );
78
- CollectionItemSlot.displayName = ITEM_SLOT_NAME;
79
- function useCollection(scope) {
80
- const context = useCollectionContext(name + "CollectionConsumer", scope);
81
- const getItems = import_react.default.useCallback(() => {
82
- const collectionNode = context.collectionRef.current;
83
- if (!collectionNode) return [];
84
- const orderedNodes = Array.from(collectionNode.querySelectorAll(`[${ITEM_DATA_ATTR}]`));
85
- const items = Array.from(context.itemMap.values());
86
- const orderedItems = items.sort(
87
- (a, b) => orderedNodes.indexOf(a.ref.current) - orderedNodes.indexOf(b.ref.current)
88
- );
89
- return orderedItems;
90
- }, [context.collectionRef, context.itemMap]);
91
- return getItems;
74
+ const composedRefs = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, ref);
75
+ const context = useCollectionContext(ITEM_SLOT_NAME, scope);
76
+ import_react.default.useEffect(() => {
77
+ context.itemMap.set(ref, { ref, ...itemData });
78
+ return () => void context.itemMap.delete(ref);
79
+ });
80
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_slot.Slot, { ...{ [ITEM_DATA_ATTR]: "" }, ref: composedRefs, children });
92
81
  }
93
- return [
94
- { Provider: CollectionProvider, Slot: CollectionSlot, ItemSlot: CollectionItemSlot },
95
- useCollection,
96
- createCollectionScope
97
- ];
82
+ );
83
+ CollectionItemSlot.displayName = ITEM_SLOT_NAME;
84
+ function useCollection(scope) {
85
+ const context = useCollectionContext(name + "CollectionConsumer", scope);
86
+ const getItems = import_react.default.useCallback(() => {
87
+ const collectionNode = context.collectionRef.current;
88
+ if (!collectionNode) return [];
89
+ const orderedNodes = Array.from(collectionNode.querySelectorAll(`[${ITEM_DATA_ATTR}]`));
90
+ const items = Array.from(context.itemMap.values());
91
+ const orderedItems = items.sort(
92
+ (a, b) => orderedNodes.indexOf(a.ref.current) - orderedNodes.indexOf(b.ref.current)
93
+ );
94
+ return orderedItems;
95
+ }, [context.collectionRef, context.itemMap]);
96
+ return getItems;
98
97
  }
99
- })();
98
+ return [
99
+ { Provider: CollectionProvider, Slot: CollectionSlot, ItemSlot: CollectionItemSlot },
100
+ useCollection,
101
+ createCollectionScope
102
+ ];
103
+ }
100
104
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/Collection.tsx"],
4
- "sourcesContent": ["import React from 'react';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { Slot } from '@radix-ui/react-slot';\n\nimport type * as Radix from '@radix-ui/react-primitive';\n\ntype SlotProps = Radix.ComponentPropsWithoutRef<typeof Slot>;\ntype CollectionElement = HTMLElement;\ninterface CollectionProps extends SlotProps {\n scope: any;\n}\n\n// We have resorted to returning slots directly rather than exposing primitives that can then\n// be slotted like `<CollectionItem as={Slot}>\u2026</CollectionItem>`.\n// This is because we encountered issues with generic types that cannot be statically analysed\n// due to creating them dynamically via createCollection.\n\nfunction createCollection<ItemElement extends HTMLElement, ItemData = {}>(name: string) {\n /* -----------------------------------------------------------------------------------------------\n * CollectionProvider\n * ---------------------------------------------------------------------------------------------*/\n\n const PROVIDER_NAME = name + 'CollectionProvider';\n const [createCollectionContext, createCollectionScope] = createContextScope(PROVIDER_NAME);\n\n type ContextValue = {\n collectionRef: React.RefObject<CollectionElement>;\n itemMap: Map<React.RefObject<ItemElement>, { ref: React.RefObject<ItemElement> } & ItemData>;\n };\n\n const [CollectionProviderImpl, useCollectionContext] = createCollectionContext<ContextValue>(\n PROVIDER_NAME,\n { collectionRef: { current: null }, itemMap: new Map() }\n );\n\n const CollectionProvider: React.FC<{ children?: React.ReactNode; scope: any }> = (props) => {\n const { scope, children } = props;\n const ref = React.useRef<CollectionElement>(null);\n const itemMap = React.useRef<ContextValue['itemMap']>(new Map()).current;\n return (\n <CollectionProviderImpl scope={scope} itemMap={itemMap} collectionRef={ref}>\n {children}\n </CollectionProviderImpl>\n );\n };\n\n CollectionProvider.displayName = PROVIDER_NAME;\n\n /* -----------------------------------------------------------------------------------------------\n * CollectionSlot\n * ---------------------------------------------------------------------------------------------*/\n\n const COLLECTION_SLOT_NAME = name + 'CollectionSlot';\n\n const CollectionSlot = React.forwardRef<CollectionElement, CollectionProps>(\n (props, forwardedRef) => {\n const { scope, children } = props;\n const context = useCollectionContext(COLLECTION_SLOT_NAME, scope);\n const composedRefs = useComposedRefs(forwardedRef, context.collectionRef);\n return <Slot ref={composedRefs}>{children}</Slot>;\n }\n );\n\n CollectionSlot.displayName = COLLECTION_SLOT_NAME;\n\n /* -----------------------------------------------------------------------------------------------\n * CollectionItem\n * ---------------------------------------------------------------------------------------------*/\n\n const ITEM_SLOT_NAME = name + 'CollectionItemSlot';\n const ITEM_DATA_ATTR = 'data-radix-collection-item';\n\n type CollectionItemSlotProps = ItemData & {\n children: React.ReactNode;\n scope: any;\n };\n\n const CollectionItemSlot = React.forwardRef<ItemElement, CollectionItemSlotProps>(\n (props, forwardedRef) => {\n const { scope, children, ...itemData } = props;\n const ref = React.useRef<ItemElement>(null);\n const composedRefs = useComposedRefs(forwardedRef, ref);\n const context = useCollectionContext(ITEM_SLOT_NAME, scope);\n\n React.useEffect(() => {\n context.itemMap.set(ref, { ref, ...(itemData as unknown as ItemData) });\n return () => void context.itemMap.delete(ref);\n });\n\n return (\n <Slot {...{ [ITEM_DATA_ATTR]: '' }} ref={composedRefs}>\n {children}\n </Slot>\n );\n }\n );\n\n CollectionItemSlot.displayName = ITEM_SLOT_NAME;\n\n /* -----------------------------------------------------------------------------------------------\n * useCollection\n * ---------------------------------------------------------------------------------------------*/\n\n function useCollection(scope: any) {\n const context = useCollectionContext(name + 'CollectionConsumer', scope);\n\n const getItems = React.useCallback(() => {\n const collectionNode = context.collectionRef.current;\n if (!collectionNode) return [];\n const orderedNodes = Array.from(collectionNode.querySelectorAll(`[${ITEM_DATA_ATTR}]`));\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\n return getItems;\n }\n\n return [\n { Provider: CollectionProvider, Slot: CollectionSlot, ItemSlot: CollectionItemSlot },\n useCollection,\n createCollectionScope,\n ] as const;\n}\n\nexport { createCollection };\nexport type { CollectionProps };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qBAAkB;AAClB,6BAAmC;AACnC,kCAAgC;AAChC,0BAAqB;AAsCf;AAvBN,WAAS,iBAAiE,MAAc;AAKtF,UAAM,gBAAgB,OAAO;AAC7B,UAAM,CAAC,yBAAyB,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GAAG,EAAE,CAAC,cAAc,GAAG,GAAG,GAAG,KAAK,cACtC,UACH;AAAA,MAEJ;AAAA,IACF;AAEA,uBAAmB,cAAc;AAMjC,aAAS,cAAc,OAAY;AACjC,YAAM,UAAU,qBAAqB,OAAO,sBAAsB,KAAK;AAEvE,YAAM,WAAW,aAAAA,QAAM,YAAY,MAAM;AACvC,cAAM,iBAAiB,QAAQ,cAAc;AAC7C,YAAI,CAAC,eAAgB,QAAO,CAAC;AAC7B,cAAM,eAAe,MAAM,KAAK,eAAe,iBAAiB,IAAI,cAAc,GAAG,CAAC;AACtF,cAAM,QAAQ,MAAM,KAAK,QAAQ,QAAQ,OAAO,CAAC;AACjD,cAAM,eAAe,MAAM;AAAA,UACzB,CAAC,GAAG,MAAM,aAAa,QAAQ,EAAE,IAAI,OAAQ,IAAI,aAAa,QAAQ,EAAE,IAAI,OAAQ;AAAA,QACtF;AACA,eAAO;AAAA,MACT,GAAG,CAAC,QAAQ,eAAe,QAAQ,OAAO,CAAC;AAE3C,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,MACL,EAAE,UAAU,oBAAoB,MAAM,gBAAgB,UAAU,mBAAmB;AAAA,MACnF;AAAA,MACA;AAAA,IACF;AAAA,EACF;",
3
+ "sources": ["../src/index.ts", "../src/Collection.tsx"],
4
+ "sourcesContent": ["'use client';\nexport { createCollection } from './Collection';\nexport type { CollectionProps } from './Collection';\n", "import React from 'react';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { Slot } from '@radix-ui/react-slot';\n\nimport type * as Radix from '@radix-ui/react-primitive';\n\ntype SlotProps = Radix.ComponentPropsWithoutRef<typeof Slot>;\ntype CollectionElement = HTMLElement;\ninterface CollectionProps extends SlotProps {\n scope: any;\n}\n\n// We have resorted to returning slots directly rather than exposing primitives that can then\n// be slotted like `<CollectionItem as={Slot}>\u2026</CollectionItem>`.\n// This is because we encountered issues with generic types that cannot be statically analysed\n// due to creating them dynamically via createCollection.\n\nfunction createCollection<ItemElement extends HTMLElement, ItemData = {}>(name: string) {\n /* -----------------------------------------------------------------------------------------------\n * CollectionProvider\n * ---------------------------------------------------------------------------------------------*/\n\n const PROVIDER_NAME = name + 'CollectionProvider';\n const [createCollectionContext, createCollectionScope] = createContextScope(PROVIDER_NAME);\n\n type ContextValue = {\n collectionRef: React.RefObject<CollectionElement>;\n itemMap: Map<React.RefObject<ItemElement>, { ref: React.RefObject<ItemElement> } & ItemData>;\n };\n\n const [CollectionProviderImpl, useCollectionContext] = createCollectionContext<ContextValue>(\n PROVIDER_NAME,\n { collectionRef: { current: null }, itemMap: new Map() }\n );\n\n const CollectionProvider: React.FC<{ children?: React.ReactNode; scope: any }> = (props) => {\n const { scope, children } = props;\n const ref = React.useRef<CollectionElement>(null);\n const itemMap = React.useRef<ContextValue['itemMap']>(new Map()).current;\n return (\n <CollectionProviderImpl scope={scope} itemMap={itemMap} collectionRef={ref}>\n {children}\n </CollectionProviderImpl>\n );\n };\n\n CollectionProvider.displayName = PROVIDER_NAME;\n\n /* -----------------------------------------------------------------------------------------------\n * CollectionSlot\n * ---------------------------------------------------------------------------------------------*/\n\n const COLLECTION_SLOT_NAME = name + 'CollectionSlot';\n\n const CollectionSlot = React.forwardRef<CollectionElement, CollectionProps>(\n (props, forwardedRef) => {\n const { scope, children } = props;\n const context = useCollectionContext(COLLECTION_SLOT_NAME, scope);\n const composedRefs = useComposedRefs(forwardedRef, context.collectionRef);\n return <Slot ref={composedRefs}>{children}</Slot>;\n }\n );\n\n CollectionSlot.displayName = COLLECTION_SLOT_NAME;\n\n /* -----------------------------------------------------------------------------------------------\n * CollectionItem\n * ---------------------------------------------------------------------------------------------*/\n\n const ITEM_SLOT_NAME = name + 'CollectionItemSlot';\n const ITEM_DATA_ATTR = 'data-radix-collection-item';\n\n type CollectionItemSlotProps = ItemData & {\n children: React.ReactNode;\n scope: any;\n };\n\n const CollectionItemSlot = React.forwardRef<ItemElement, CollectionItemSlotProps>(\n (props, forwardedRef) => {\n const { scope, children, ...itemData } = props;\n const ref = React.useRef<ItemElement>(null);\n const composedRefs = useComposedRefs(forwardedRef, ref);\n const context = useCollectionContext(ITEM_SLOT_NAME, scope);\n\n React.useEffect(() => {\n context.itemMap.set(ref, { ref, ...(itemData as unknown as ItemData) });\n return () => void context.itemMap.delete(ref);\n });\n\n return (\n <Slot {...{ [ITEM_DATA_ATTR]: '' }} ref={composedRefs}>\n {children}\n </Slot>\n );\n }\n );\n\n CollectionItemSlot.displayName = ITEM_SLOT_NAME;\n\n /* -----------------------------------------------------------------------------------------------\n * useCollection\n * ---------------------------------------------------------------------------------------------*/\n\n function useCollection(scope: any) {\n const context = useCollectionContext(name + 'CollectionConsumer', scope);\n\n const getItems = React.useCallback(() => {\n const collectionNode = context.collectionRef.current;\n if (!collectionNode) return [];\n const orderedNodes = Array.from(collectionNode.querySelectorAll(`[${ITEM_DATA_ATTR}]`));\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\n return getItems;\n }\n\n return [\n { Provider: CollectionProvider, Slot: CollectionSlot, ItemSlot: CollectionItemSlot },\n useCollection,\n createCollectionScope,\n ] as const;\n}\n\nexport { createCollection };\nexport type { CollectionProps };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAkB;AAClB,2BAAmC;AACnC,gCAAgC;AAChC,wBAAqB;AAsCf;AAvBN,SAAS,iBAAiE,MAAc;AAKtF,QAAM,gBAAgB,OAAO;AAC7B,QAAM,CAAC,yBAAyB,qBAAqB,QAAI,yCAAmB,aAAa;AAOzF,QAAM,CAAC,wBAAwB,oBAAoB,IAAI;AAAA,IACrD;AAAA,IACA,EAAE,eAAe,EAAE,SAAS,KAAK,GAAG,SAAS,oBAAI,IAA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BAAqB,OAAO,sBAAsB,KAAK;AAEvE,UAAM,WAAW,aAAAA,QAAM,YAAY,MAAM;AACvC,YAAM,iBAAiB,QAAQ,cAAc;AAC7C,UAAI,CAAC,eAAgB,QAAO,CAAC;AAC7B,YAAM,eAAe,MAAM,KAAK,eAAe,iBAAiB,IAAI,cAAc,GAAG,CAAC;AACtF,YAAM,QAAQ,MAAM,KAAK,QAAQ,QAAQ,OAAO,CAAC;AACjD,YAAM,eAAe,MAAM;AAAA,QACzB,CAAC,GAAG,MAAM,aAAa,QAAQ,EAAE,IAAI,OAAQ,IAAI,aAAa,QAAQ,EAAE,IAAI,OAAQ;AAAA,MACtF;AACA,aAAO;AAAA,IACT,GAAG,CAAC,QAAQ,eAAe,QAAQ,OAAO,CAAC;AAE3C,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL,EAAE,UAAU,oBAAoB,MAAM,gBAAgB,UAAU,mBAAmB;AAAA,IACnF;AAAA,IACA;AAAA,EACF;AACF;",
6
6
  "names": ["React"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radix-ui/react-collection",
3
- "version": "1.1.0-rc.2",
3
+ "version": "1.1.0-rc.3",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": {
@@ -28,10 +28,10 @@
28
28
  "version": "yarn version"
29
29
  },
30
30
  "dependencies": {
31
- "@radix-ui/react-compose-refs": "1.1.0-rc.2",
32
- "@radix-ui/react-context": "1.1.0-rc.2",
33
- "@radix-ui/react-primitive": "1.1.0-rc.2",
34
- "@radix-ui/react-slot": "1.1.0-rc.2"
31
+ "@radix-ui/react-compose-refs": "1.1.0-rc.3",
32
+ "@radix-ui/react-context": "1.1.0-rc.3",
33
+ "@radix-ui/react-primitive": "1.1.0-rc.3",
34
+ "@radix-ui/react-slot": "1.1.0-rc.3"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "@types/react": "*",