v1.0 with SW PWA enabled

This commit is contained in:
Blomios
2026-01-01 17:40:53 +01:00
parent 1c0e22aac1
commit 3c8bebb2ad
29775 changed files with 2197201 additions and 119080 deletions

View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 WorkOS
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,3 @@
# `react-collection`
This is an internal utility, not intended for public usage.

View File

@ -0,0 +1,98 @@
import * as _radix_ui_react_context from '@radix-ui/react-context';
import React from 'react';
import { Slot } from '@radix-ui/react-slot';
type SlotProps$1 = React.ComponentPropsWithoutRef<typeof Slot>;
interface CollectionProps$1 extends SlotProps$1 {
scope: any;
}
declare function createCollection$1<ItemElement extends HTMLElement, ItemData = {}>(name: string): readonly [{
readonly Provider: React.FC<{
children?: React.ReactNode;
scope: any;
}>;
readonly Slot: React.ForwardRefExoticComponent<CollectionProps$1 & React.RefAttributes<HTMLElement>>;
readonly ItemSlot: React.ForwardRefExoticComponent<React.PropsWithoutRef<ItemData & {
children: React.ReactNode;
scope: any;
}> & React.RefAttributes<ItemElement>>;
}, (scope: any) => () => ({
ref: React.RefObject<ItemElement | null>;
} & ItemData)[], _radix_ui_react_context.CreateScope];
declare class OrderedDict<K, V> extends Map<K, V> {
#private;
constructor(iterable?: Iterable<readonly [K, V]> | null | undefined);
set(key: K, value: V): this;
insert(index: number, key: K, value: V): this;
with(index: number, key: K, value: V): OrderedDict<K, V>;
before(key: K): [K, V] | undefined;
/**
* Sets a new key-value pair at the position before the given key.
*/
setBefore(key: K, newKey: K, value: V): this;
after(key: K): [K, V] | undefined;
/**
* Sets a new key-value pair at the position after the given key.
*/
setAfter(key: K, newKey: K, value: V): this;
first(): [K, V] | undefined;
last(): [K, V] | undefined;
clear(): void;
delete(key: K): boolean;
deleteAt(index: number): boolean;
at(index: number): V | undefined;
entryAt(index: number): [K, V] | undefined;
indexOf(key: K): number;
keyAt(index: number): K | undefined;
from(key: K, offset: number): V | undefined;
keyFrom(key: K, offset: number): K | undefined;
find(predicate: (entry: [K, V], index: number, dictionary: OrderedDict<K, V>) => boolean, thisArg?: any): [K, V] | undefined;
findIndex(predicate: (entry: [K, V], index: number, dictionary: OrderedDict<K, V>) => boolean, thisArg?: any): number;
filter<KK extends K, VV extends V>(predicate: (entry: [K, V], index: number, dict: OrderedDict<K, V>) => entry is [KK, VV], thisArg?: any): OrderedDict<KK, VV>;
filter(predicate: (entry: [K, V], index: number, dictionary: OrderedDict<K, V>) => unknown, thisArg?: any): OrderedDict<K, V>;
map<U>(callbackfn: (entry: [K, V], index: number, dictionary: OrderedDict<K, V>) => U, thisArg?: any): OrderedDict<K, U>;
reduce(callbackfn: (previousValue: [K, V], currentEntry: [K, V], currentIndex: number, dictionary: OrderedDict<K, V>) => [K, V]): [K, V];
reduce(callbackfn: (previousValue: [K, V], currentEntry: [K, V], currentIndex: number, dictionary: OrderedDict<K, V>) => [K, V], initialValue: [K, V]): [K, V];
reduce<U>(callbackfn: (previousValue: U, currentEntry: [K, V], currentIndex: number, dictionary: OrderedDict<K, V>) => U, initialValue: U): U;
reduceRight(callbackfn: (previousValue: [K, V], currentEntry: [K, V], currentIndex: number, dictionary: OrderedDict<K, V>) => [K, V]): [K, V];
reduceRight(callbackfn: (previousValue: [K, V], currentEntry: [K, V], currentIndex: number, dictionary: OrderedDict<K, V>) => [K, V], initialValue: [K, V]): [K, V];
reduceRight<U>(callbackfn: (previousValue: [K, V], currentValue: U, currentIndex: number, dictionary: OrderedDict<K, V>) => U, initialValue: U): U;
toSorted(compareFn?: (a: [K, V], b: [K, V]) => number): OrderedDict<K, V>;
toReversed(): OrderedDict<K, V>;
toSpliced(start: number, deleteCount?: number): OrderedDict<K, V>;
toSpliced(start: number, deleteCount: number, ...items: [K, V][]): OrderedDict<K, V>;
slice(start?: number, end?: number): OrderedDict<K, V>;
every(predicate: (entry: [K, V], index: number, dictionary: OrderedDict<K, V>) => unknown, thisArg?: any): boolean;
some(predicate: (entry: [K, V], index: number, dictionary: OrderedDict<K, V>) => unknown, thisArg?: any): boolean;
}
type SlotProps = React.ComponentPropsWithoutRef<typeof Slot>;
interface CollectionProps extends SlotProps {
scope: any;
}
interface BaseItemData {
id?: string;
}
type ItemDataWithElement<ItemData extends BaseItemData, ItemElement extends HTMLElement> = ItemData & {
element: ItemElement;
};
type ItemMap<ItemElement extends HTMLElement, ItemData extends BaseItemData> = OrderedDict<ItemElement, ItemDataWithElement<ItemData, ItemElement>>;
declare function createCollection<ItemElement extends HTMLElement, ItemData extends BaseItemData = BaseItemData>(name: string): readonly [{
readonly Provider: React.FC<{
children?: React.ReactNode;
scope: any;
state?: [ItemMap: ItemMap<ItemElement, ItemData>, SetItemMap: React.Dispatch<React.SetStateAction<ItemMap<ItemElement, ItemData>>>];
}>;
readonly Slot: React.ForwardRefExoticComponent<CollectionProps & React.RefAttributes<HTMLElement>>;
readonly ItemSlot: React.ForwardRefExoticComponent<React.PropsWithoutRef<ItemData & {
children: React.ReactNode;
scope: any;
}> & React.RefAttributes<ItemElement>>;
}, {
createCollectionScope: _radix_ui_react_context.CreateScope;
useCollection: (scope: any) => ItemMap<ItemElement, ItemData>;
useInitCollection: () => [ItemMap<ItemElement, ItemData>, React.Dispatch<React.SetStateAction<ItemMap<ItemElement, ItemData>>>];
}];
export { type CollectionProps$1 as CollectionProps, createCollection$1 as createCollection, type CollectionProps$1 as unstable_CollectionProps, createCollection as unstable_createCollection };

View File

@ -0,0 +1,98 @@
import * as _radix_ui_react_context from '@radix-ui/react-context';
import React from 'react';
import { Slot } from '@radix-ui/react-slot';
type SlotProps$1 = React.ComponentPropsWithoutRef<typeof Slot>;
interface CollectionProps$1 extends SlotProps$1 {
scope: any;
}
declare function createCollection$1<ItemElement extends HTMLElement, ItemData = {}>(name: string): readonly [{
readonly Provider: React.FC<{
children?: React.ReactNode;
scope: any;
}>;
readonly Slot: React.ForwardRefExoticComponent<CollectionProps$1 & React.RefAttributes<HTMLElement>>;
readonly ItemSlot: React.ForwardRefExoticComponent<React.PropsWithoutRef<ItemData & {
children: React.ReactNode;
scope: any;
}> & React.RefAttributes<ItemElement>>;
}, (scope: any) => () => ({
ref: React.RefObject<ItemElement | null>;
} & ItemData)[], _radix_ui_react_context.CreateScope];
declare class OrderedDict<K, V> extends Map<K, V> {
#private;
constructor(iterable?: Iterable<readonly [K, V]> | null | undefined);
set(key: K, value: V): this;
insert(index: number, key: K, value: V): this;
with(index: number, key: K, value: V): OrderedDict<K, V>;
before(key: K): [K, V] | undefined;
/**
* Sets a new key-value pair at the position before the given key.
*/
setBefore(key: K, newKey: K, value: V): this;
after(key: K): [K, V] | undefined;
/**
* Sets a new key-value pair at the position after the given key.
*/
setAfter(key: K, newKey: K, value: V): this;
first(): [K, V] | undefined;
last(): [K, V] | undefined;
clear(): void;
delete(key: K): boolean;
deleteAt(index: number): boolean;
at(index: number): V | undefined;
entryAt(index: number): [K, V] | undefined;
indexOf(key: K): number;
keyAt(index: number): K | undefined;
from(key: K, offset: number): V | undefined;
keyFrom(key: K, offset: number): K | undefined;
find(predicate: (entry: [K, V], index: number, dictionary: OrderedDict<K, V>) => boolean, thisArg?: any): [K, V] | undefined;
findIndex(predicate: (entry: [K, V], index: number, dictionary: OrderedDict<K, V>) => boolean, thisArg?: any): number;
filter<KK extends K, VV extends V>(predicate: (entry: [K, V], index: number, dict: OrderedDict<K, V>) => entry is [KK, VV], thisArg?: any): OrderedDict<KK, VV>;
filter(predicate: (entry: [K, V], index: number, dictionary: OrderedDict<K, V>) => unknown, thisArg?: any): OrderedDict<K, V>;
map<U>(callbackfn: (entry: [K, V], index: number, dictionary: OrderedDict<K, V>) => U, thisArg?: any): OrderedDict<K, U>;
reduce(callbackfn: (previousValue: [K, V], currentEntry: [K, V], currentIndex: number, dictionary: OrderedDict<K, V>) => [K, V]): [K, V];
reduce(callbackfn: (previousValue: [K, V], currentEntry: [K, V], currentIndex: number, dictionary: OrderedDict<K, V>) => [K, V], initialValue: [K, V]): [K, V];
reduce<U>(callbackfn: (previousValue: U, currentEntry: [K, V], currentIndex: number, dictionary: OrderedDict<K, V>) => U, initialValue: U): U;
reduceRight(callbackfn: (previousValue: [K, V], currentEntry: [K, V], currentIndex: number, dictionary: OrderedDict<K, V>) => [K, V]): [K, V];
reduceRight(callbackfn: (previousValue: [K, V], currentEntry: [K, V], currentIndex: number, dictionary: OrderedDict<K, V>) => [K, V], initialValue: [K, V]): [K, V];
reduceRight<U>(callbackfn: (previousValue: [K, V], currentValue: U, currentIndex: number, dictionary: OrderedDict<K, V>) => U, initialValue: U): U;
toSorted(compareFn?: (a: [K, V], b: [K, V]) => number): OrderedDict<K, V>;
toReversed(): OrderedDict<K, V>;
toSpliced(start: number, deleteCount?: number): OrderedDict<K, V>;
toSpliced(start: number, deleteCount: number, ...items: [K, V][]): OrderedDict<K, V>;
slice(start?: number, end?: number): OrderedDict<K, V>;
every(predicate: (entry: [K, V], index: number, dictionary: OrderedDict<K, V>) => unknown, thisArg?: any): boolean;
some(predicate: (entry: [K, V], index: number, dictionary: OrderedDict<K, V>) => unknown, thisArg?: any): boolean;
}
type SlotProps = React.ComponentPropsWithoutRef<typeof Slot>;
interface CollectionProps extends SlotProps {
scope: any;
}
interface BaseItemData {
id?: string;
}
type ItemDataWithElement<ItemData extends BaseItemData, ItemElement extends HTMLElement> = ItemData & {
element: ItemElement;
};
type ItemMap<ItemElement extends HTMLElement, ItemData extends BaseItemData> = OrderedDict<ItemElement, ItemDataWithElement<ItemData, ItemElement>>;
declare function createCollection<ItemElement extends HTMLElement, ItemData extends BaseItemData = BaseItemData>(name: string): readonly [{
readonly Provider: React.FC<{
children?: React.ReactNode;
scope: any;
state?: [ItemMap: ItemMap<ItemElement, ItemData>, SetItemMap: React.Dispatch<React.SetStateAction<ItemMap<ItemElement, ItemData>>>];
}>;
readonly Slot: React.ForwardRefExoticComponent<CollectionProps & React.RefAttributes<HTMLElement>>;
readonly ItemSlot: React.ForwardRefExoticComponent<React.PropsWithoutRef<ItemData & {
children: React.ReactNode;
scope: any;
}> & React.RefAttributes<ItemElement>>;
}, {
createCollectionScope: _radix_ui_react_context.CreateScope;
useCollection: (scope: any) => ItemMap<ItemElement, ItemData>;
useInitCollection: () => [ItemMap<ItemElement, ItemData>, React.Dispatch<React.SetStateAction<ItemMap<ItemElement, ItemData>>>];
}];
export { type CollectionProps$1 as CollectionProps, createCollection$1 as createCollection, type CollectionProps$1 as unstable_CollectionProps, createCollection as unstable_createCollection };

View File

@ -0,0 +1,577 @@
"use strict";
"use client";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var index_exports = {};
__export(index_exports, {
createCollection: () => createCollection,
unstable_createCollection: () => createCollection2
});
module.exports = __toCommonJS(index_exports);
// src/collection-legacy.tsx
var import_react = __toESM(require("react"));
var import_react_context = require("@radix-ui/react-context");
var import_react_compose_refs = require("@radix-ui/react-compose-refs");
var import_react_slot = require("@radix-ui/react-slot");
var import_jsx_runtime = require("react/jsx-runtime");
function createCollection(name) {
const PROVIDER_NAME = name + "CollectionProvider";
const [createCollectionContext, createCollectionScope] = (0, import_react_context.createContextScope)(PROVIDER_NAME);
const [CollectionProviderImpl, useCollectionContext] = createCollectionContext(
PROVIDER_NAME,
{ collectionRef: { current: null }, itemMap: /* @__PURE__ */ new Map() }
);
const CollectionProvider = (props) => {
const { scope, children } = props;
const ref = import_react.default.useRef(null);
const itemMap = import_react.default.useRef(/* @__PURE__ */ new Map()).current;
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CollectionProviderImpl, { scope, itemMap, collectionRef: ref, children });
};
CollectionProvider.displayName = PROVIDER_NAME;
const COLLECTION_SLOT_NAME = name + "CollectionSlot";
const CollectionSlotImpl = (0, import_react_slot.createSlot)(COLLECTION_SLOT_NAME);
const CollectionSlot = import_react.default.forwardRef(
(props, forwardedRef) => {
const { scope, children } = props;
const context = useCollectionContext(COLLECTION_SLOT_NAME, scope);
const composedRefs = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, context.collectionRef);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CollectionSlotImpl, { ref: composedRefs, children });
}
);
CollectionSlot.displayName = COLLECTION_SLOT_NAME;
const ITEM_SLOT_NAME = name + "CollectionItemSlot";
const ITEM_DATA_ATTR = "data-radix-collection-item";
const CollectionItemSlotImpl = (0, import_react_slot.createSlot)(ITEM_SLOT_NAME);
const CollectionItemSlot = import_react.default.forwardRef(
(props, forwardedRef) => {
const { scope, children, ...itemData } = props;
const ref = import_react.default.useRef(null);
const composedRefs = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, ref);
const context = useCollectionContext(ITEM_SLOT_NAME, scope);
import_react.default.useEffect(() => {
context.itemMap.set(ref, { ref, ...itemData });
return () => void context.itemMap.delete(ref);
});
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CollectionItemSlotImpl, { ...{ [ITEM_DATA_ATTR]: "" }, ref: composedRefs, children });
}
);
CollectionItemSlot.displayName = ITEM_SLOT_NAME;
function useCollection(scope) {
const context = useCollectionContext(name + "CollectionConsumer", scope);
const getItems = import_react.default.useCallback(() => {
const collectionNode = context.collectionRef.current;
if (!collectionNode) return [];
const orderedNodes = Array.from(collectionNode.querySelectorAll(`[${ITEM_DATA_ATTR}]`));
const items = Array.from(context.itemMap.values());
const orderedItems = items.sort(
(a, b) => orderedNodes.indexOf(a.ref.current) - orderedNodes.indexOf(b.ref.current)
);
return orderedItems;
}, [context.collectionRef, context.itemMap]);
return getItems;
}
return [
{ Provider: CollectionProvider, Slot: CollectionSlot, ItemSlot: CollectionItemSlot },
useCollection,
createCollectionScope
];
}
// src/collection.tsx
var import_react2 = __toESM(require("react"));
var import_react_context2 = require("@radix-ui/react-context");
var import_react_compose_refs2 = require("@radix-ui/react-compose-refs");
var import_react_slot2 = require("@radix-ui/react-slot");
// src/ordered-dictionary.ts
var __instanciated = /* @__PURE__ */ new WeakMap();
var OrderedDict = class _OrderedDict extends Map {
#keys;
constructor(entries) {
super(entries);
this.#keys = [...super.keys()];
__instanciated.set(this, true);
}
set(key, value) {
if (__instanciated.get(this)) {
if (this.has(key)) {
this.#keys[this.#keys.indexOf(key)] = key;
} else {
this.#keys.push(key);
}
}
super.set(key, value);
return this;
}
insert(index, key, value) {
const has = this.has(key);
const length = this.#keys.length;
const relativeIndex = toSafeInteger(index);
let actualIndex = relativeIndex >= 0 ? relativeIndex : length + relativeIndex;
const safeIndex = actualIndex < 0 || actualIndex >= length ? -1 : actualIndex;
if (safeIndex === this.size || has && safeIndex === this.size - 1 || safeIndex === -1) {
this.set(key, value);
return this;
}
const size = this.size + (has ? 0 : 1);
if (relativeIndex < 0) {
actualIndex++;
}
const keys = [...this.#keys];
let nextValue;
let shouldSkip = false;
for (let i = actualIndex; i < size; i++) {
if (actualIndex === i) {
let nextKey = keys[i];
if (keys[i] === key) {
nextKey = keys[i + 1];
}
if (has) {
this.delete(key);
}
nextValue = this.get(nextKey);
this.set(key, value);
} else {
if (!shouldSkip && keys[i - 1] === key) {
shouldSkip = true;
}
const currentKey = keys[shouldSkip ? i : i - 1];
const currentValue = nextValue;
nextValue = this.get(currentKey);
this.delete(currentKey);
this.set(currentKey, currentValue);
}
}
return this;
}
with(index, key, value) {
const copy = new _OrderedDict(this);
copy.insert(index, key, value);
return copy;
}
before(key) {
const index = this.#keys.indexOf(key) - 1;
if (index < 0) {
return void 0;
}
return this.entryAt(index);
}
/**
* Sets a new key-value pair at the position before the given key.
*/
setBefore(key, newKey, value) {
const index = this.#keys.indexOf(key);
if (index === -1) {
return this;
}
return this.insert(index, newKey, value);
}
after(key) {
let index = this.#keys.indexOf(key);
index = index === -1 || index === this.size - 1 ? -1 : index + 1;
if (index === -1) {
return void 0;
}
return this.entryAt(index);
}
/**
* Sets a new key-value pair at the position after the given key.
*/
setAfter(key, newKey, value) {
const index = this.#keys.indexOf(key);
if (index === -1) {
return this;
}
return this.insert(index + 1, newKey, value);
}
first() {
return this.entryAt(0);
}
last() {
return this.entryAt(-1);
}
clear() {
this.#keys = [];
return super.clear();
}
delete(key) {
const deleted = super.delete(key);
if (deleted) {
this.#keys.splice(this.#keys.indexOf(key), 1);
}
return deleted;
}
deleteAt(index) {
const key = this.keyAt(index);
if (key !== void 0) {
return this.delete(key);
}
return false;
}
at(index) {
const key = at(this.#keys, index);
if (key !== void 0) {
return this.get(key);
}
}
entryAt(index) {
const key = at(this.#keys, index);
if (key !== void 0) {
return [key, this.get(key)];
}
}
indexOf(key) {
return this.#keys.indexOf(key);
}
keyAt(index) {
return at(this.#keys, index);
}
from(key, offset) {
const index = this.indexOf(key);
if (index === -1) {
return void 0;
}
let dest = index + offset;
if (dest < 0) dest = 0;
if (dest >= this.size) dest = this.size - 1;
return this.at(dest);
}
keyFrom(key, offset) {
const index = this.indexOf(key);
if (index === -1) {
return void 0;
}
let dest = index + offset;
if (dest < 0) dest = 0;
if (dest >= this.size) dest = this.size - 1;
return this.keyAt(dest);
}
find(predicate, thisArg) {
let index = 0;
for (const entry of this) {
if (Reflect.apply(predicate, thisArg, [entry, index, this])) {
return entry;
}
index++;
}
return void 0;
}
findIndex(predicate, thisArg) {
let index = 0;
for (const entry of this) {
if (Reflect.apply(predicate, thisArg, [entry, index, this])) {
return index;
}
index++;
}
return -1;
}
filter(predicate, thisArg) {
const entries = [];
let index = 0;
for (const entry of this) {
if (Reflect.apply(predicate, thisArg, [entry, index, this])) {
entries.push(entry);
}
index++;
}
return new _OrderedDict(entries);
}
map(callbackfn, thisArg) {
const entries = [];
let index = 0;
for (const entry of this) {
entries.push([entry[0], Reflect.apply(callbackfn, thisArg, [entry, index, this])]);
index++;
}
return new _OrderedDict(entries);
}
reduce(...args) {
const [callbackfn, initialValue] = args;
let index = 0;
let accumulator = initialValue ?? this.at(0);
for (const entry of this) {
if (index === 0 && args.length === 1) {
accumulator = entry;
} else {
accumulator = Reflect.apply(callbackfn, this, [accumulator, entry, index, this]);
}
index++;
}
return accumulator;
}
reduceRight(...args) {
const [callbackfn, initialValue] = args;
let accumulator = initialValue ?? this.at(-1);
for (let index = this.size - 1; index >= 0; index--) {
const entry = this.at(index);
if (index === this.size - 1 && args.length === 1) {
accumulator = entry;
} else {
accumulator = Reflect.apply(callbackfn, this, [accumulator, entry, index, this]);
}
}
return accumulator;
}
toSorted(compareFn) {
const entries = [...this.entries()].sort(compareFn);
return new _OrderedDict(entries);
}
toReversed() {
const reversed = new _OrderedDict();
for (let index = this.size - 1; index >= 0; index--) {
const key = this.keyAt(index);
const element = this.get(key);
reversed.set(key, element);
}
return reversed;
}
toSpliced(...args) {
const entries = [...this.entries()];
entries.splice(...args);
return new _OrderedDict(entries);
}
slice(start, end) {
const result = new _OrderedDict();
let stop = this.size - 1;
if (start === void 0) {
return result;
}
if (start < 0) {
start = start + this.size;
}
if (end !== void 0 && end > 0) {
stop = end - 1;
}
for (let index = start; index <= stop; index++) {
const key = this.keyAt(index);
const element = this.get(key);
result.set(key, element);
}
return result;
}
every(predicate, thisArg) {
let index = 0;
for (const entry of this) {
if (!Reflect.apply(predicate, thisArg, [entry, index, this])) {
return false;
}
index++;
}
return true;
}
some(predicate, thisArg) {
let index = 0;
for (const entry of this) {
if (Reflect.apply(predicate, thisArg, [entry, index, this])) {
return true;
}
index++;
}
return false;
}
};
function at(array, index) {
if ("at" in Array.prototype) {
return Array.prototype.at.call(array, index);
}
const actualIndex = toSafeIndex(array, index);
return actualIndex === -1 ? void 0 : array[actualIndex];
}
function toSafeIndex(array, index) {
const length = array.length;
const relativeIndex = toSafeInteger(index);
const actualIndex = relativeIndex >= 0 ? relativeIndex : length + relativeIndex;
return actualIndex < 0 || actualIndex >= length ? -1 : actualIndex;
}
function toSafeInteger(number) {
return number !== number || number === 0 ? 0 : Math.trunc(number);
}
// src/collection.tsx
var import_jsx_runtime2 = require("react/jsx-runtime");
function createCollection2(name) {
const PROVIDER_NAME = name + "CollectionProvider";
const [createCollectionContext, createCollectionScope] = (0, import_react_context2.createContextScope)(PROVIDER_NAME);
const [CollectionContextProvider, useCollectionContext] = createCollectionContext(
PROVIDER_NAME,
{
collectionElement: null,
collectionRef: { current: null },
collectionRefObject: { current: null },
itemMap: new OrderedDict(),
setItemMap: () => void 0
}
);
const CollectionProvider = ({ state, ...props }) => {
return state ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CollectionProviderImpl, { ...props, state }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CollectionInit, { ...props });
};
CollectionProvider.displayName = PROVIDER_NAME;
const CollectionInit = (props) => {
const state = useInitCollection();
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CollectionProviderImpl, { ...props, state });
};
CollectionInit.displayName = PROVIDER_NAME + "Init";
const CollectionProviderImpl = (props) => {
const { scope, children, state } = props;
const ref = import_react2.default.useRef(null);
const [collectionElement, setCollectionElement] = import_react2.default.useState(
null
);
const composeRefs = (0, import_react_compose_refs2.useComposedRefs)(ref, setCollectionElement);
const [itemMap, setItemMap] = state;
import_react2.default.useEffect(() => {
if (!collectionElement) return;
const observer = getChildListObserver(() => {
});
observer.observe(collectionElement, {
childList: true,
subtree: true
});
return () => {
observer.disconnect();
};
}, [collectionElement]);
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
CollectionContextProvider,
{
scope,
itemMap,
setItemMap,
collectionRef: composeRefs,
collectionRefObject: ref,
collectionElement,
children
}
);
};
CollectionProviderImpl.displayName = PROVIDER_NAME + "Impl";
const COLLECTION_SLOT_NAME = name + "CollectionSlot";
const CollectionSlotImpl = (0, import_react_slot2.createSlot)(COLLECTION_SLOT_NAME);
const CollectionSlot = import_react2.default.forwardRef(
(props, forwardedRef) => {
const { scope, children } = props;
const context = useCollectionContext(COLLECTION_SLOT_NAME, scope);
const composedRefs = (0, import_react_compose_refs2.useComposedRefs)(forwardedRef, context.collectionRef);
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CollectionSlotImpl, { ref: composedRefs, children });
}
);
CollectionSlot.displayName = COLLECTION_SLOT_NAME;
const ITEM_SLOT_NAME = name + "CollectionItemSlot";
const ITEM_DATA_ATTR = "data-radix-collection-item";
const CollectionItemSlotImpl = (0, import_react_slot2.createSlot)(ITEM_SLOT_NAME);
const CollectionItemSlot = import_react2.default.forwardRef(
(props, forwardedRef) => {
const { scope, children, ...itemData } = props;
const ref = import_react2.default.useRef(null);
const [element, setElement] = import_react2.default.useState(null);
const composedRefs = (0, import_react_compose_refs2.useComposedRefs)(forwardedRef, ref, setElement);
const context = useCollectionContext(ITEM_SLOT_NAME, scope);
const { setItemMap } = context;
const itemDataRef = import_react2.default.useRef(itemData);
if (!shallowEqual(itemDataRef.current, itemData)) {
itemDataRef.current = itemData;
}
const memoizedItemData = itemDataRef.current;
import_react2.default.useEffect(() => {
const itemData2 = memoizedItemData;
setItemMap((map) => {
if (!element) {
return map;
}
if (!map.has(element)) {
map.set(element, { ...itemData2, element });
return map.toSorted(sortByDocumentPosition);
}
return map.set(element, { ...itemData2, element }).toSorted(sortByDocumentPosition);
});
return () => {
setItemMap((map) => {
if (!element || !map.has(element)) {
return map;
}
map.delete(element);
return new OrderedDict(map);
});
};
}, [element, memoizedItemData, setItemMap]);
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CollectionItemSlotImpl, { ...{ [ITEM_DATA_ATTR]: "" }, ref: composedRefs, children });
}
);
CollectionItemSlot.displayName = ITEM_SLOT_NAME;
function useInitCollection() {
return import_react2.default.useState(new OrderedDict());
}
function useCollection(scope) {
const { itemMap } = useCollectionContext(name + "CollectionConsumer", scope);
return itemMap;
}
const functions = {
createCollectionScope,
useCollection,
useInitCollection
};
return [
{ Provider: CollectionProvider, Slot: CollectionSlot, ItemSlot: CollectionItemSlot },
functions
];
}
function shallowEqual(a, b) {
if (a === b) return true;
if (typeof a !== "object" || typeof b !== "object") return false;
if (a == null || b == null) return false;
const keysA = Object.keys(a);
const keysB = Object.keys(b);
if (keysA.length !== keysB.length) return false;
for (const key of keysA) {
if (!Object.prototype.hasOwnProperty.call(b, key)) return false;
if (a[key] !== b[key]) return false;
}
return true;
}
function isElementPreceding(a, b) {
return !!(b.compareDocumentPosition(a) & Node.DOCUMENT_POSITION_PRECEDING);
}
function sortByDocumentPosition(a, b) {
return !a[1].element || !b[1].element ? 0 : isElementPreceding(a[1].element, b[1].element) ? -1 : 1;
}
function getChildListObserver(callback) {
const observer = new MutationObserver((mutationsList) => {
for (const mutation of mutationsList) {
if (mutation.type === "childList") {
callback();
return;
}
}
});
return observer;
}
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,545 @@
"use client";
// src/collection-legacy.tsx
import React from "react";
import { createContextScope } from "@radix-ui/react-context";
import { useComposedRefs } from "@radix-ui/react-compose-refs";
import { createSlot } from "@radix-ui/react-slot";
import { jsx } from "react/jsx-runtime";
function createCollection(name) {
const PROVIDER_NAME = name + "CollectionProvider";
const [createCollectionContext, createCollectionScope] = createContextScope(PROVIDER_NAME);
const [CollectionProviderImpl, useCollectionContext] = createCollectionContext(
PROVIDER_NAME,
{ collectionRef: { current: null }, itemMap: /* @__PURE__ */ new Map() }
);
const CollectionProvider = (props) => {
const { scope, children } = props;
const ref = React.useRef(null);
const itemMap = React.useRef(/* @__PURE__ */ new Map()).current;
return /* @__PURE__ */ jsx(CollectionProviderImpl, { scope, itemMap, collectionRef: ref, children });
};
CollectionProvider.displayName = PROVIDER_NAME;
const COLLECTION_SLOT_NAME = name + "CollectionSlot";
const CollectionSlotImpl = createSlot(COLLECTION_SLOT_NAME);
const CollectionSlot = React.forwardRef(
(props, forwardedRef) => {
const { scope, children } = props;
const context = useCollectionContext(COLLECTION_SLOT_NAME, scope);
const composedRefs = useComposedRefs(forwardedRef, context.collectionRef);
return /* @__PURE__ */ jsx(CollectionSlotImpl, { ref: composedRefs, children });
}
);
CollectionSlot.displayName = COLLECTION_SLOT_NAME;
const ITEM_SLOT_NAME = name + "CollectionItemSlot";
const ITEM_DATA_ATTR = "data-radix-collection-item";
const CollectionItemSlotImpl = createSlot(ITEM_SLOT_NAME);
const CollectionItemSlot = React.forwardRef(
(props, forwardedRef) => {
const { scope, children, ...itemData } = props;
const ref = React.useRef(null);
const composedRefs = useComposedRefs(forwardedRef, ref);
const context = useCollectionContext(ITEM_SLOT_NAME, scope);
React.useEffect(() => {
context.itemMap.set(ref, { ref, ...itemData });
return () => void context.itemMap.delete(ref);
});
return /* @__PURE__ */ jsx(CollectionItemSlotImpl, { ...{ [ITEM_DATA_ATTR]: "" }, ref: composedRefs, children });
}
);
CollectionItemSlot.displayName = ITEM_SLOT_NAME;
function useCollection(scope) {
const context = useCollectionContext(name + "CollectionConsumer", scope);
const getItems = React.useCallback(() => {
const collectionNode = context.collectionRef.current;
if (!collectionNode) return [];
const orderedNodes = Array.from(collectionNode.querySelectorAll(`[${ITEM_DATA_ATTR}]`));
const items = Array.from(context.itemMap.values());
const orderedItems = items.sort(
(a, b) => orderedNodes.indexOf(a.ref.current) - orderedNodes.indexOf(b.ref.current)
);
return orderedItems;
}, [context.collectionRef, context.itemMap]);
return getItems;
}
return [
{ Provider: CollectionProvider, Slot: CollectionSlot, ItemSlot: CollectionItemSlot },
useCollection,
createCollectionScope
];
}
// src/collection.tsx
import React2 from "react";
import { createContextScope as createContextScope2 } from "@radix-ui/react-context";
import { useComposedRefs as useComposedRefs2 } from "@radix-ui/react-compose-refs";
import { createSlot as createSlot2 } from "@radix-ui/react-slot";
// src/ordered-dictionary.ts
var __instanciated = /* @__PURE__ */ new WeakMap();
var OrderedDict = class _OrderedDict extends Map {
#keys;
constructor(entries) {
super(entries);
this.#keys = [...super.keys()];
__instanciated.set(this, true);
}
set(key, value) {
if (__instanciated.get(this)) {
if (this.has(key)) {
this.#keys[this.#keys.indexOf(key)] = key;
} else {
this.#keys.push(key);
}
}
super.set(key, value);
return this;
}
insert(index, key, value) {
const has = this.has(key);
const length = this.#keys.length;
const relativeIndex = toSafeInteger(index);
let actualIndex = relativeIndex >= 0 ? relativeIndex : length + relativeIndex;
const safeIndex = actualIndex < 0 || actualIndex >= length ? -1 : actualIndex;
if (safeIndex === this.size || has && safeIndex === this.size - 1 || safeIndex === -1) {
this.set(key, value);
return this;
}
const size = this.size + (has ? 0 : 1);
if (relativeIndex < 0) {
actualIndex++;
}
const keys = [...this.#keys];
let nextValue;
let shouldSkip = false;
for (let i = actualIndex; i < size; i++) {
if (actualIndex === i) {
let nextKey = keys[i];
if (keys[i] === key) {
nextKey = keys[i + 1];
}
if (has) {
this.delete(key);
}
nextValue = this.get(nextKey);
this.set(key, value);
} else {
if (!shouldSkip && keys[i - 1] === key) {
shouldSkip = true;
}
const currentKey = keys[shouldSkip ? i : i - 1];
const currentValue = nextValue;
nextValue = this.get(currentKey);
this.delete(currentKey);
this.set(currentKey, currentValue);
}
}
return this;
}
with(index, key, value) {
const copy = new _OrderedDict(this);
copy.insert(index, key, value);
return copy;
}
before(key) {
const index = this.#keys.indexOf(key) - 1;
if (index < 0) {
return void 0;
}
return this.entryAt(index);
}
/**
* Sets a new key-value pair at the position before the given key.
*/
setBefore(key, newKey, value) {
const index = this.#keys.indexOf(key);
if (index === -1) {
return this;
}
return this.insert(index, newKey, value);
}
after(key) {
let index = this.#keys.indexOf(key);
index = index === -1 || index === this.size - 1 ? -1 : index + 1;
if (index === -1) {
return void 0;
}
return this.entryAt(index);
}
/**
* Sets a new key-value pair at the position after the given key.
*/
setAfter(key, newKey, value) {
const index = this.#keys.indexOf(key);
if (index === -1) {
return this;
}
return this.insert(index + 1, newKey, value);
}
first() {
return this.entryAt(0);
}
last() {
return this.entryAt(-1);
}
clear() {
this.#keys = [];
return super.clear();
}
delete(key) {
const deleted = super.delete(key);
if (deleted) {
this.#keys.splice(this.#keys.indexOf(key), 1);
}
return deleted;
}
deleteAt(index) {
const key = this.keyAt(index);
if (key !== void 0) {
return this.delete(key);
}
return false;
}
at(index) {
const key = at(this.#keys, index);
if (key !== void 0) {
return this.get(key);
}
}
entryAt(index) {
const key = at(this.#keys, index);
if (key !== void 0) {
return [key, this.get(key)];
}
}
indexOf(key) {
return this.#keys.indexOf(key);
}
keyAt(index) {
return at(this.#keys, index);
}
from(key, offset) {
const index = this.indexOf(key);
if (index === -1) {
return void 0;
}
let dest = index + offset;
if (dest < 0) dest = 0;
if (dest >= this.size) dest = this.size - 1;
return this.at(dest);
}
keyFrom(key, offset) {
const index = this.indexOf(key);
if (index === -1) {
return void 0;
}
let dest = index + offset;
if (dest < 0) dest = 0;
if (dest >= this.size) dest = this.size - 1;
return this.keyAt(dest);
}
find(predicate, thisArg) {
let index = 0;
for (const entry of this) {
if (Reflect.apply(predicate, thisArg, [entry, index, this])) {
return entry;
}
index++;
}
return void 0;
}
findIndex(predicate, thisArg) {
let index = 0;
for (const entry of this) {
if (Reflect.apply(predicate, thisArg, [entry, index, this])) {
return index;
}
index++;
}
return -1;
}
filter(predicate, thisArg) {
const entries = [];
let index = 0;
for (const entry of this) {
if (Reflect.apply(predicate, thisArg, [entry, index, this])) {
entries.push(entry);
}
index++;
}
return new _OrderedDict(entries);
}
map(callbackfn, thisArg) {
const entries = [];
let index = 0;
for (const entry of this) {
entries.push([entry[0], Reflect.apply(callbackfn, thisArg, [entry, index, this])]);
index++;
}
return new _OrderedDict(entries);
}
reduce(...args) {
const [callbackfn, initialValue] = args;
let index = 0;
let accumulator = initialValue ?? this.at(0);
for (const entry of this) {
if (index === 0 && args.length === 1) {
accumulator = entry;
} else {
accumulator = Reflect.apply(callbackfn, this, [accumulator, entry, index, this]);
}
index++;
}
return accumulator;
}
reduceRight(...args) {
const [callbackfn, initialValue] = args;
let accumulator = initialValue ?? this.at(-1);
for (let index = this.size - 1; index >= 0; index--) {
const entry = this.at(index);
if (index === this.size - 1 && args.length === 1) {
accumulator = entry;
} else {
accumulator = Reflect.apply(callbackfn, this, [accumulator, entry, index, this]);
}
}
return accumulator;
}
toSorted(compareFn) {
const entries = [...this.entries()].sort(compareFn);
return new _OrderedDict(entries);
}
toReversed() {
const reversed = new _OrderedDict();
for (let index = this.size - 1; index >= 0; index--) {
const key = this.keyAt(index);
const element = this.get(key);
reversed.set(key, element);
}
return reversed;
}
toSpliced(...args) {
const entries = [...this.entries()];
entries.splice(...args);
return new _OrderedDict(entries);
}
slice(start, end) {
const result = new _OrderedDict();
let stop = this.size - 1;
if (start === void 0) {
return result;
}
if (start < 0) {
start = start + this.size;
}
if (end !== void 0 && end > 0) {
stop = end - 1;
}
for (let index = start; index <= stop; index++) {
const key = this.keyAt(index);
const element = this.get(key);
result.set(key, element);
}
return result;
}
every(predicate, thisArg) {
let index = 0;
for (const entry of this) {
if (!Reflect.apply(predicate, thisArg, [entry, index, this])) {
return false;
}
index++;
}
return true;
}
some(predicate, thisArg) {
let index = 0;
for (const entry of this) {
if (Reflect.apply(predicate, thisArg, [entry, index, this])) {
return true;
}
index++;
}
return false;
}
};
function at(array, index) {
if ("at" in Array.prototype) {
return Array.prototype.at.call(array, index);
}
const actualIndex = toSafeIndex(array, index);
return actualIndex === -1 ? void 0 : array[actualIndex];
}
function toSafeIndex(array, index) {
const length = array.length;
const relativeIndex = toSafeInteger(index);
const actualIndex = relativeIndex >= 0 ? relativeIndex : length + relativeIndex;
return actualIndex < 0 || actualIndex >= length ? -1 : actualIndex;
}
function toSafeInteger(number) {
return number !== number || number === 0 ? 0 : Math.trunc(number);
}
// src/collection.tsx
import { jsx as jsx2 } from "react/jsx-runtime";
function createCollection2(name) {
const PROVIDER_NAME = name + "CollectionProvider";
const [createCollectionContext, createCollectionScope] = createContextScope2(PROVIDER_NAME);
const [CollectionContextProvider, useCollectionContext] = createCollectionContext(
PROVIDER_NAME,
{
collectionElement: null,
collectionRef: { current: null },
collectionRefObject: { current: null },
itemMap: new OrderedDict(),
setItemMap: () => void 0
}
);
const CollectionProvider = ({ state, ...props }) => {
return state ? /* @__PURE__ */ jsx2(CollectionProviderImpl, { ...props, state }) : /* @__PURE__ */ jsx2(CollectionInit, { ...props });
};
CollectionProvider.displayName = PROVIDER_NAME;
const CollectionInit = (props) => {
const state = useInitCollection();
return /* @__PURE__ */ jsx2(CollectionProviderImpl, { ...props, state });
};
CollectionInit.displayName = PROVIDER_NAME + "Init";
const CollectionProviderImpl = (props) => {
const { scope, children, state } = props;
const ref = React2.useRef(null);
const [collectionElement, setCollectionElement] = React2.useState(
null
);
const composeRefs = useComposedRefs2(ref, setCollectionElement);
const [itemMap, setItemMap] = state;
React2.useEffect(() => {
if (!collectionElement) return;
const observer = getChildListObserver(() => {
});
observer.observe(collectionElement, {
childList: true,
subtree: true
});
return () => {
observer.disconnect();
};
}, [collectionElement]);
return /* @__PURE__ */ jsx2(
CollectionContextProvider,
{
scope,
itemMap,
setItemMap,
collectionRef: composeRefs,
collectionRefObject: ref,
collectionElement,
children
}
);
};
CollectionProviderImpl.displayName = PROVIDER_NAME + "Impl";
const COLLECTION_SLOT_NAME = name + "CollectionSlot";
const CollectionSlotImpl = createSlot2(COLLECTION_SLOT_NAME);
const CollectionSlot = React2.forwardRef(
(props, forwardedRef) => {
const { scope, children } = props;
const context = useCollectionContext(COLLECTION_SLOT_NAME, scope);
const composedRefs = useComposedRefs2(forwardedRef, context.collectionRef);
return /* @__PURE__ */ jsx2(CollectionSlotImpl, { ref: composedRefs, children });
}
);
CollectionSlot.displayName = COLLECTION_SLOT_NAME;
const ITEM_SLOT_NAME = name + "CollectionItemSlot";
const ITEM_DATA_ATTR = "data-radix-collection-item";
const CollectionItemSlotImpl = createSlot2(ITEM_SLOT_NAME);
const CollectionItemSlot = React2.forwardRef(
(props, forwardedRef) => {
const { scope, children, ...itemData } = props;
const ref = React2.useRef(null);
const [element, setElement] = React2.useState(null);
const composedRefs = useComposedRefs2(forwardedRef, ref, setElement);
const context = useCollectionContext(ITEM_SLOT_NAME, scope);
const { setItemMap } = context;
const itemDataRef = React2.useRef(itemData);
if (!shallowEqual(itemDataRef.current, itemData)) {
itemDataRef.current = itemData;
}
const memoizedItemData = itemDataRef.current;
React2.useEffect(() => {
const itemData2 = memoizedItemData;
setItemMap((map) => {
if (!element) {
return map;
}
if (!map.has(element)) {
map.set(element, { ...itemData2, element });
return map.toSorted(sortByDocumentPosition);
}
return map.set(element, { ...itemData2, element }).toSorted(sortByDocumentPosition);
});
return () => {
setItemMap((map) => {
if (!element || !map.has(element)) {
return map;
}
map.delete(element);
return new OrderedDict(map);
});
};
}, [element, memoizedItemData, setItemMap]);
return /* @__PURE__ */ jsx2(CollectionItemSlotImpl, { ...{ [ITEM_DATA_ATTR]: "" }, ref: composedRefs, children });
}
);
CollectionItemSlot.displayName = ITEM_SLOT_NAME;
function useInitCollection() {
return React2.useState(new OrderedDict());
}
function useCollection(scope) {
const { itemMap } = useCollectionContext(name + "CollectionConsumer", scope);
return itemMap;
}
const functions = {
createCollectionScope,
useCollection,
useInitCollection
};
return [
{ Provider: CollectionProvider, Slot: CollectionSlot, ItemSlot: CollectionItemSlot },
functions
];
}
function shallowEqual(a, b) {
if (a === b) return true;
if (typeof a !== "object" || typeof b !== "object") return false;
if (a == null || b == null) return false;
const keysA = Object.keys(a);
const keysB = Object.keys(b);
if (keysA.length !== keysB.length) return false;
for (const key of keysA) {
if (!Object.prototype.hasOwnProperty.call(b, key)) return false;
if (a[key] !== b[key]) return false;
}
return true;
}
function isElementPreceding(a, b) {
return !!(b.compareDocumentPosition(a) & Node.DOCUMENT_POSITION_PRECEDING);
}
function sortByDocumentPosition(a, b) {
return !a[1].element || !b[1].element ? 0 : isElementPreceding(a[1].element, b[1].element) ? -1 : 1;
}
function getChildListObserver(callback) {
const observer = new MutationObserver((mutationsList) => {
for (const mutation of mutationsList) {
if (mutation.type === "childList") {
callback();
return;
}
}
});
return observer;
}
export {
createCollection,
createCollection2 as unstable_createCollection
};
//# sourceMappingURL=index.mjs.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 WorkOS
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,3 @@
# `react-slot`
View docs [here](https://radix-ui.com/primitives/docs/utilities/slot).

View File

@ -0,0 +1,17 @@
import * as React from 'react';
interface SlotProps extends React.HTMLAttributes<HTMLElement> {
children?: React.ReactNode;
}
declare function createSlot(ownerName: string): React.ForwardRefExoticComponent<SlotProps & React.RefAttributes<HTMLElement>>;
declare const Slot: React.ForwardRefExoticComponent<SlotProps & React.RefAttributes<HTMLElement>>;
interface SlottableProps {
children: React.ReactNode;
}
interface SlottableComponent extends React.FC<SlottableProps> {
__radixId: symbol;
}
declare function createSlottable(ownerName: string): SlottableComponent;
declare const Slottable: SlottableComponent;
export { Slot as Root, Slot, type SlotProps, Slottable, createSlot, createSlottable };

View File

@ -0,0 +1,17 @@
import * as React from 'react';
interface SlotProps extends React.HTMLAttributes<HTMLElement> {
children?: React.ReactNode;
}
declare function createSlot(ownerName: string): React.ForwardRefExoticComponent<SlotProps & React.RefAttributes<HTMLElement>>;
declare const Slot: React.ForwardRefExoticComponent<SlotProps & React.RefAttributes<HTMLElement>>;
interface SlottableProps {
children: React.ReactNode;
}
interface SlottableComponent extends React.FC<SlottableProps> {
__radixId: symbol;
}
declare function createSlottable(ownerName: string): SlottableComponent;
declare const Slottable: SlottableComponent;
export { Slot as Root, Slot, type SlotProps, Slottable, createSlot, createSlottable };

View File

@ -0,0 +1,138 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var index_exports = {};
__export(index_exports, {
Root: () => Slot,
Slot: () => Slot,
Slottable: () => Slottable,
createSlot: () => createSlot,
createSlottable: () => createSlottable
});
module.exports = __toCommonJS(index_exports);
// src/slot.tsx
var React = __toESM(require("react"));
var import_react_compose_refs = require("@radix-ui/react-compose-refs");
var import_jsx_runtime = require("react/jsx-runtime");
// @__NO_SIDE_EFFECTS__
function createSlot(ownerName) {
const SlotClone = /* @__PURE__ */ createSlotClone(ownerName);
const Slot2 = React.forwardRef((props, forwardedRef) => {
const { children, ...slotProps } = props;
const childrenArray = React.Children.toArray(children);
const slottable = childrenArray.find(isSlottable);
if (slottable) {
const newElement = slottable.props.children;
const newChildren = childrenArray.map((child) => {
if (child === slottable) {
if (React.Children.count(newElement) > 1) return React.Children.only(null);
return React.isValidElement(newElement) ? newElement.props.children : null;
} else {
return child;
}
});
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SlotClone, { ...slotProps, ref: forwardedRef, children: React.isValidElement(newElement) ? React.cloneElement(newElement, void 0, newChildren) : null });
}
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SlotClone, { ...slotProps, ref: forwardedRef, children });
});
Slot2.displayName = `${ownerName}.Slot`;
return Slot2;
}
var Slot = /* @__PURE__ */ createSlot("Slot");
// @__NO_SIDE_EFFECTS__
function createSlotClone(ownerName) {
const SlotClone = React.forwardRef((props, forwardedRef) => {
const { children, ...slotProps } = props;
if (React.isValidElement(children)) {
const childrenRef = getElementRef(children);
const props2 = mergeProps(slotProps, children.props);
if (children.type !== React.Fragment) {
props2.ref = forwardedRef ? (0, import_react_compose_refs.composeRefs)(forwardedRef, childrenRef) : childrenRef;
}
return React.cloneElement(children, props2);
}
return React.Children.count(children) > 1 ? React.Children.only(null) : null;
});
SlotClone.displayName = `${ownerName}.SlotClone`;
return SlotClone;
}
var SLOTTABLE_IDENTIFIER = Symbol("radix.slottable");
// @__NO_SIDE_EFFECTS__
function createSlottable(ownerName) {
const Slottable2 = ({ children }) => {
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children });
};
Slottable2.displayName = `${ownerName}.Slottable`;
Slottable2.__radixId = SLOTTABLE_IDENTIFIER;
return Slottable2;
}
var Slottable = /* @__PURE__ */ createSlottable("Slottable");
function isSlottable(child) {
return React.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER;
}
function mergeProps(slotProps, childProps) {
const overrideProps = { ...childProps };
for (const propName in childProps) {
const slotPropValue = slotProps[propName];
const childPropValue = childProps[propName];
const isHandler = /^on[A-Z]/.test(propName);
if (isHandler) {
if (slotPropValue && childPropValue) {
overrideProps[propName] = (...args) => {
const result = childPropValue(...args);
slotPropValue(...args);
return result;
};
} else if (slotPropValue) {
overrideProps[propName] = slotPropValue;
}
} else if (propName === "style") {
overrideProps[propName] = { ...slotPropValue, ...childPropValue };
} else if (propName === "className") {
overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
}
}
return { ...slotProps, ...overrideProps };
}
function getElementRef(element) {
let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;
let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
if (mayWarn) {
return element.ref;
}
getter = Object.getOwnPropertyDescriptor(element, "ref")?.get;
mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
if (mayWarn) {
return element.props.ref;
}
return element.props.ref || element.ref;
}
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,105 @@
// src/slot.tsx
import * as React from "react";
import { composeRefs } from "@radix-ui/react-compose-refs";
import { Fragment as Fragment2, jsx } from "react/jsx-runtime";
// @__NO_SIDE_EFFECTS__
function createSlot(ownerName) {
const SlotClone = /* @__PURE__ */ createSlotClone(ownerName);
const Slot2 = React.forwardRef((props, forwardedRef) => {
const { children, ...slotProps } = props;
const childrenArray = React.Children.toArray(children);
const slottable = childrenArray.find(isSlottable);
if (slottable) {
const newElement = slottable.props.children;
const newChildren = childrenArray.map((child) => {
if (child === slottable) {
if (React.Children.count(newElement) > 1) return React.Children.only(null);
return React.isValidElement(newElement) ? newElement.props.children : null;
} else {
return child;
}
});
return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: React.isValidElement(newElement) ? React.cloneElement(newElement, void 0, newChildren) : null });
}
return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
});
Slot2.displayName = `${ownerName}.Slot`;
return Slot2;
}
var Slot = /* @__PURE__ */ createSlot("Slot");
// @__NO_SIDE_EFFECTS__
function createSlotClone(ownerName) {
const SlotClone = React.forwardRef((props, forwardedRef) => {
const { children, ...slotProps } = props;
if (React.isValidElement(children)) {
const childrenRef = getElementRef(children);
const props2 = mergeProps(slotProps, children.props);
if (children.type !== React.Fragment) {
props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
}
return React.cloneElement(children, props2);
}
return React.Children.count(children) > 1 ? React.Children.only(null) : null;
});
SlotClone.displayName = `${ownerName}.SlotClone`;
return SlotClone;
}
var SLOTTABLE_IDENTIFIER = Symbol("radix.slottable");
// @__NO_SIDE_EFFECTS__
function createSlottable(ownerName) {
const Slottable2 = ({ children }) => {
return /* @__PURE__ */ jsx(Fragment2, { children });
};
Slottable2.displayName = `${ownerName}.Slottable`;
Slottable2.__radixId = SLOTTABLE_IDENTIFIER;
return Slottable2;
}
var Slottable = /* @__PURE__ */ createSlottable("Slottable");
function isSlottable(child) {
return React.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER;
}
function mergeProps(slotProps, childProps) {
const overrideProps = { ...childProps };
for (const propName in childProps) {
const slotPropValue = slotProps[propName];
const childPropValue = childProps[propName];
const isHandler = /^on[A-Z]/.test(propName);
if (isHandler) {
if (slotPropValue && childPropValue) {
overrideProps[propName] = (...args) => {
const result = childPropValue(...args);
slotPropValue(...args);
return result;
};
} else if (slotPropValue) {
overrideProps[propName] = slotPropValue;
}
} else if (propName === "style") {
overrideProps[propName] = { ...slotPropValue, ...childPropValue };
} else if (propName === "className") {
overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
}
}
return { ...slotProps, ...overrideProps };
}
function getElementRef(element) {
let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;
let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
if (mayWarn) {
return element.ref;
}
getter = Object.getOwnPropertyDescriptor(element, "ref")?.get;
mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
if (mayWarn) {
return element.props.ref;
}
return element.props.ref || element.ref;
}
export {
Slot as Root,
Slot,
Slottable,
createSlot,
createSlottable
};
//# sourceMappingURL=index.mjs.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,63 @@
{
"name": "@radix-ui/react-slot",
"version": "1.2.3",
"license": "MIT",
"source": "./src/index.ts",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"files": [
"dist",
"README.md"
],
"sideEffects": false,
"dependencies": {
"@radix-ui/react-compose-refs": "1.1.2"
},
"devDependencies": {
"@types/react": "^19.0.7",
"@types/react-dom": "^19.0.3",
"eslint": "^9.18.0",
"react": "^19.1.0",
"react-dom": "^19.1.0",
"typescript": "^5.7.3",
"@repo/eslint-config": "0.0.0",
"@repo/typescript-config": "0.0.0",
"@repo/builder": "0.0.0"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
},
"homepage": "https://radix-ui.com/primitives",
"repository": {
"type": "git",
"url": "git+https://github.com/radix-ui/primitives.git"
},
"bugs": {
"url": "https://github.com/radix-ui/primitives/issues"
},
"scripts": {
"lint": "eslint --max-warnings 0 src",
"clean": "rm -rf dist",
"typecheck": "tsc --noEmit",
"build": "radix-build"
},
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
}
}
}

View File

@ -0,0 +1,71 @@
{
"name": "@radix-ui/react-collection",
"version": "1.1.7",
"license": "MIT",
"source": "./src/index.ts",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"files": [
"dist",
"README.md"
],
"sideEffects": false,
"dependencies": {
"@radix-ui/react-compose-refs": "1.1.2",
"@radix-ui/react-context": "1.1.2",
"@radix-ui/react-primitive": "2.1.3",
"@radix-ui/react-slot": "1.2.3"
},
"devDependencies": {
"@types/react": "^19.0.7",
"@types/react-dom": "^19.0.3",
"eslint": "^9.18.0",
"react": "^19.1.0",
"react-dom": "^19.1.0",
"typescript": "^5.7.3",
"@repo/builder": "0.0.0",
"@repo/typescript-config": "0.0.0",
"@repo/eslint-config": "0.0.0"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
},
"homepage": "https://radix-ui.com/primitives",
"repository": {
"type": "git",
"url": "git+https://github.com/radix-ui/primitives.git"
},
"bugs": {
"url": "https://github.com/radix-ui/primitives/issues"
},
"scripts": {
"lint": "eslint --max-warnings 0 src",
"clean": "rm -rf dist",
"typecheck": "tsc --noEmit",
"build": "radix-build"
},
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
}
}
}