@refraction-ui/react 0.23.1 → 0.23.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.cjs CHANGED
@@ -872,8 +872,6 @@ var Keys = {
872
872
  ArrowDown: "ArrowDown",
873
873
  ArrowLeft: "ArrowLeft",
874
874
  ArrowRight: "ArrowRight",
875
- Home: "Home",
876
- End: "End",
877
875
  Backspace: "Backspace"};
878
876
  function createKeyboardHandler(handlers) {
879
877
  return (event) => {
@@ -10714,14 +10712,14 @@ function createCookieConsent(config3 = {}) {
10714
10712
  const categories = config3.categories ?? DEFAULT_CATEGORIES;
10715
10713
  const storage = config3.storage;
10716
10714
  const key = config3.storageKey ?? DEFAULT_KEY;
10717
- const version = config3.version;
10715
+ const version2 = config3.version;
10718
10716
  let preferences = baseline(categories);
10719
10717
  let consented = false;
10720
10718
  const raw = storage?.get(key) ?? null;
10721
10719
  if (raw) {
10722
10720
  try {
10723
10721
  const parsed = JSON.parse(raw);
10724
- if ((parsed.version ?? void 0) === version) {
10722
+ if ((parsed.version ?? void 0) === version2) {
10725
10723
  preferences = { ...baseline(categories), ...parsed.preferences };
10726
10724
  for (const c of categories) if (c.required) preferences[c.id] = true;
10727
10725
  consented = true;
@@ -10740,7 +10738,7 @@ function createCookieConsent(config3 = {}) {
10740
10738
  for (const l2 of listeners) l2();
10741
10739
  }
10742
10740
  function persist() {
10743
- storage?.set(key, JSON.stringify({ version, preferences }));
10741
+ storage?.set(key, JSON.stringify({ version: version2, preferences }));
10744
10742
  config3.onChange?.({ ...preferences });
10745
10743
  }
10746
10744
  function save(next) {
@@ -11514,11 +11512,10 @@ function Dialog({
11514
11512
  },
11515
11513
  [isControlled, onOpenChange]
11516
11514
  );
11517
- const apiRef = React52__namespace.useRef(null);
11518
- if (apiRef.current === null) {
11519
- apiRef.current = createDialog({ open, modal });
11520
- }
11521
- const api = apiRef.current;
11515
+ const id = React52__namespace.useId();
11516
+ const contentId = `rfr-dialog-content-${id}`;
11517
+ const titleId = `rfr-dialog-title-${id}`;
11518
+ const descriptionId = `rfr-dialog-desc-${id}`;
11522
11519
  const [hasTitle, setHasTitle] = React52__namespace.useState(false);
11523
11520
  const [hasDescription, setHasDescription] = React52__namespace.useState(false);
11524
11521
  const ctx = React52__namespace.useMemo(
@@ -11526,38 +11523,66 @@ function Dialog({
11526
11523
  open,
11527
11524
  onOpenChange: handleOpenChange,
11528
11525
  modal,
11529
- contentId: api.ids.content,
11530
- titleId: api.ids.title,
11531
- descriptionId: api.ids.description,
11526
+ contentId,
11527
+ titleId,
11528
+ descriptionId,
11532
11529
  hasTitle,
11533
11530
  hasDescription,
11534
11531
  setHasTitle,
11535
11532
  setHasDescription
11536
11533
  }),
11537
- [open, handleOpenChange, modal, api.ids.content, api.ids.title, api.ids.description, hasTitle, hasDescription]
11534
+ [open, handleOpenChange, modal, contentId, titleId, descriptionId, hasTitle, hasDescription]
11538
11535
  );
11539
11536
  return React52__namespace.createElement(DialogContext.Provider, { value: ctx }, children);
11540
11537
  }
11541
11538
  var DialogTrigger = React52__namespace.forwardRef(
11542
- function DialogTrigger2({ onClick, children, ...props }, ref) {
11539
+ function DialogTrigger2({ asChild = false, onClick, children, ...props }, ref) {
11543
11540
  const { open, onOpenChange, contentId } = useDialogContext();
11544
- const handleClick = (e) => {
11545
- onOpenChange(!open);
11546
- onClick?.(e);
11541
+ const handleClick = (event) => {
11542
+ onClick?.(event);
11543
+ if (!event.defaultPrevented) onOpenChange(!open);
11547
11544
  };
11548
- return React52__namespace.createElement(
11549
- "button",
11550
- {
11551
- ref,
11552
- type: "button",
11553
- "aria-expanded": open,
11554
- "aria-controls": contentId,
11555
- "aria-haspopup": "dialog",
11556
- onClick: handleClick,
11557
- ...props
11558
- },
11559
- children
11560
- );
11545
+ const triggerProps = {
11546
+ type: "button",
11547
+ "aria-expanded": open,
11548
+ "aria-controls": contentId,
11549
+ "aria-haspopup": "dialog",
11550
+ ...props,
11551
+ onClick: handleClick
11552
+ };
11553
+ if (asChild) {
11554
+ if (!React52__namespace.isValidElement(children)) {
11555
+ devWarn("dialog-trigger-asChild-child", "DialogTrigger: `asChild` expects a single React element child; rendering nothing.");
11556
+ return null;
11557
+ }
11558
+ const child = children;
11559
+ const childRef = React52__namespace.version.startsWith("18.") ? child.ref : child.props.ref;
11560
+ return React52__namespace.cloneElement(child, {
11561
+ ...triggerProps,
11562
+ className: cn(props.className, child.props.className),
11563
+ onClick: (event) => {
11564
+ child.props.onClick?.(event);
11565
+ if (!event.defaultPrevented) handleClick(event);
11566
+ },
11567
+ ref: (node) => {
11568
+ const outerCleanup = typeof ref === "function" ? ref(node) : void 0;
11569
+ if (ref && typeof ref !== "function") ref.current = node;
11570
+ const childCleanup = typeof childRef === "function" ? childRef(node) : void 0;
11571
+ if (childRef && typeof childRef !== "function") childRef.current = node;
11572
+ if (typeof outerCleanup === "function" || typeof childCleanup === "function") {
11573
+ return () => {
11574
+ if (typeof outerCleanup === "function") outerCleanup();
11575
+ else if (typeof ref === "function") ref(null);
11576
+ else if (ref) ref.current = null;
11577
+ if (typeof childCleanup === "function") childCleanup();
11578
+ else if (typeof childRef === "function") childRef(null);
11579
+ else if (childRef) childRef.current = null;
11580
+ };
11581
+ }
11582
+ }
11583
+ });
11584
+ }
11585
+ return React52__namespace.createElement("button", { ref, ...triggerProps }, children);
11561
11586
  }
11562
11587
  );
11563
11588
  var DialogOverlay = React52__namespace.forwardRef(
@@ -11590,10 +11615,6 @@ function containsElement(node, type) {
11590
11615
  var DialogContent = React52__namespace.forwardRef(
11591
11616
  function DialogContent2({ className, children, onKeyDown, ...props }, ref) {
11592
11617
  const { open, onOpenChange, modal, contentId, titleId, descriptionId, hasTitle, hasDescription } = useDialogContext();
11593
- React52__namespace.useMemo(
11594
- () => createDialog({ open, modal }),
11595
- [open, modal]
11596
- );
11597
11618
  const handleKeyDown = (e) => {
11598
11619
  const handler = createKeyboardHandler({
11599
11620
  Escape: (ev) => {
@@ -11699,88 +11720,6 @@ var DialogClose = React52__namespace.forwardRef(
11699
11720
  );
11700
11721
 
11701
11722
  // ../dropdown-menu/dist/index.js
11702
- function createDropdownMenu(props = {}) {
11703
- const { open: controlledOpen, defaultOpen = false, onOpenChange } = props;
11704
- const machine = createMachine({
11705
- initial: controlledOpen ?? defaultOpen ? "open" : "closed",
11706
- states: {
11707
- closed: { on: { OPEN: "open" } },
11708
- open: { on: { CLOSE: "closed" } }
11709
- }
11710
- });
11711
- const contentId = generateId("rfr-dropdown-menu");
11712
- function isOpen() {
11713
- if (controlledOpen !== void 0) return controlledOpen;
11714
- return machine.matches("open");
11715
- }
11716
- function openMenu() {
11717
- machine.send("OPEN");
11718
- onOpenChange?.(true);
11719
- }
11720
- function closeMenu() {
11721
- machine.send("CLOSE");
11722
- onOpenChange?.(false);
11723
- }
11724
- function toggleMenu() {
11725
- if (isOpen()) {
11726
- closeMenu();
11727
- } else {
11728
- openMenu();
11729
- }
11730
- }
11731
- function getItemProps(item) {
11732
- return {
11733
- role: "menuitem",
11734
- tabIndex: item.disabled ? -1 : 0,
11735
- "data-disabled": item.disabled ? "" : void 0,
11736
- "aria-disabled": item.disabled || void 0
11737
- };
11738
- }
11739
- const keyboardHandlers = {
11740
- [Keys.Escape]: (e) => {
11741
- e.preventDefault();
11742
- closeMenu();
11743
- },
11744
- [Keys.ArrowDown]: (e) => {
11745
- e.preventDefault();
11746
- },
11747
- [Keys.ArrowUp]: (e) => {
11748
- e.preventDefault();
11749
- },
11750
- [Keys.Enter]: (e) => {
11751
- e.preventDefault();
11752
- },
11753
- [Keys.Home]: (e) => {
11754
- e.preventDefault();
11755
- },
11756
- [Keys.End]: (e) => {
11757
- e.preventDefault();
11758
- }
11759
- };
11760
- const triggerProps = {
11761
- "aria-expanded": isOpen(),
11762
- "aria-controls": contentId,
11763
- "aria-haspopup": "menu"
11764
- };
11765
- const contentProps = {
11766
- role: "menu",
11767
- id: contentId,
11768
- "data-state": isOpen() ? "open" : "closed"
11769
- };
11770
- return {
11771
- state: { open: isOpen() },
11772
- triggerProps,
11773
- contentProps,
11774
- getItemProps,
11775
- open: openMenu,
11776
- close: closeMenu,
11777
- toggle: toggleMenu,
11778
- keyboardHandlers,
11779
- ids: {
11780
- content: contentId
11781
- }
11782
- };
11783
- }
11784
11723
  var menuContentVariants = cva({
11785
11724
  base: "z-50 rounded-md border bg-popover shadow-md"
11786
11725
  });
@@ -11819,20 +11758,16 @@ function DropdownMenu({
11819
11758
  },
11820
11759
  [isControlled, onOpenChange]
11821
11760
  );
11822
- const apiRef = React52__namespace.useRef(null);
11823
- if (apiRef.current === null) {
11824
- apiRef.current = createDropdownMenu({ open });
11825
- }
11826
- const api = apiRef.current;
11761
+ const contentId = `rfr-dropdown-menu-${React52__namespace.useId()}`;
11827
11762
  const triggerRef = React52__namespace.useRef(null);
11828
11763
  const ctx = React52__namespace.useMemo(
11829
11764
  () => ({
11830
11765
  open,
11831
11766
  onOpenChange: handleOpenChange,
11832
- contentId: api.ids.content,
11767
+ contentId,
11833
11768
  triggerRef
11834
11769
  }),
11835
- [open, handleOpenChange, api.ids.content]
11770
+ [open, handleOpenChange, contentId]
11836
11771
  );
11837
11772
  return React52__namespace.createElement(DropdownMenuContext.Provider, { value: ctx }, children);
11838
11773
  }
@@ -14643,92 +14578,6 @@ var SkeletonText = React52__namespace.forwardRef(
14643
14578
  );
14644
14579
 
14645
14580
  // ../tabs/dist/index.js
14646
- function createTabs(props = {}) {
14647
- const {
14648
- value: controlledValue,
14649
- defaultValue = "",
14650
- onValueChange,
14651
- orientation = "horizontal"
14652
- } = props;
14653
- let uncontrolledValue = controlledValue ?? defaultValue;
14654
- const idPrefix = generateId("rfr-tabs");
14655
- function getActiveValue() {
14656
- if (controlledValue !== void 0) return controlledValue;
14657
- return uncontrolledValue;
14658
- }
14659
- function select(value) {
14660
- uncontrolledValue = value;
14661
- onValueChange?.(value);
14662
- }
14663
- function getTabId(value) {
14664
- return `${idPrefix}-tab-${value}`;
14665
- }
14666
- function getPanelId(value) {
14667
- return `${idPrefix}-panel-${value}`;
14668
- }
14669
- function getTabProps(value) {
14670
- const isSelected = getActiveValue() === value;
14671
- return {
14672
- role: "tab",
14673
- "aria-selected": isSelected,
14674
- "aria-controls": getPanelId(value),
14675
- tabIndex: isSelected ? 0 : -1,
14676
- id: getTabId(value),
14677
- "data-state": isSelected ? "active" : "inactive"
14678
- };
14679
- }
14680
- function getPanelProps(value) {
14681
- const isSelected = getActiveValue() === value;
14682
- return {
14683
- role: "tabpanel",
14684
- "aria-labelledby": getTabId(value),
14685
- id: getPanelId(value),
14686
- hidden: !isSelected || void 0,
14687
- tabIndex: 0,
14688
- "data-state": isSelected ? "active" : "inactive"
14689
- };
14690
- }
14691
- const listProps = {
14692
- role: "tablist",
14693
- "aria-orientation": orientation
14694
- };
14695
- const keyboardHandlers = orientation === "horizontal" ? {
14696
- [Keys.ArrowLeft]: (e) => {
14697
- e.preventDefault();
14698
- },
14699
- [Keys.ArrowRight]: (e) => {
14700
- e.preventDefault();
14701
- },
14702
- [Keys.Home]: (e) => {
14703
- e.preventDefault();
14704
- },
14705
- [Keys.End]: (e) => {
14706
- e.preventDefault();
14707
- }
14708
- } : {
14709
- [Keys.ArrowUp]: (e) => {
14710
- e.preventDefault();
14711
- },
14712
- [Keys.ArrowDown]: (e) => {
14713
- e.preventDefault();
14714
- },
14715
- [Keys.Home]: (e) => {
14716
- e.preventDefault();
14717
- },
14718
- [Keys.End]: (e) => {
14719
- e.preventDefault();
14720
- }
14721
- };
14722
- return {
14723
- state: { activeValue: getActiveValue() },
14724
- listProps,
14725
- getTabProps,
14726
- getPanelProps,
14727
- select,
14728
- keyboardHandlers,
14729
- idPrefix
14730
- };
14731
- }
14732
14581
  function getNextTabIndex(current, key, count, orientation = "horizontal") {
14733
14582
  if (count === 0) return null;
14734
14583
  const prev = orientation === "horizontal" ? "ArrowLeft" : "ArrowUp";
@@ -14780,11 +14629,7 @@ var Tabs = React52__namespace.forwardRef(
14780
14629
  },
14781
14630
  [isControlled, onValueChange]
14782
14631
  );
14783
- const apiRef = React52__namespace.useRef(null);
14784
- if (apiRef.current === null) {
14785
- apiRef.current = createTabs({ value, orientation });
14786
- }
14787
- const api = apiRef.current;
14632
+ const idPrefix = `rfr-tabs-${React52__namespace.useId()}`;
14788
14633
  const [panels, setPanels] = React52__namespace.useState(() => /* @__PURE__ */ new Set());
14789
14634
  const registerPanel = React52__namespace.useCallback((panelValue) => {
14790
14635
  setPanels((prev) => prev.has(panelValue) ? prev : new Set(prev).add(panelValue));
@@ -14805,11 +14650,11 @@ var Tabs = React52__namespace.forwardRef(
14805
14650
  value,
14806
14651
  onValueChange: handleValueChange,
14807
14652
  orientation,
14808
- idPrefix: api.idPrefix,
14653
+ idPrefix,
14809
14654
  panels: allPanels,
14810
14655
  registerPanel
14811
14656
  }),
14812
- [value, handleValueChange, orientation, api.idPrefix, allPanels, registerPanel]
14657
+ [value, handleValueChange, orientation, idPrefix, allPanels, registerPanel]
14813
14658
  );
14814
14659
  return React52__namespace.createElement(
14815
14660
  "div",
@@ -17170,13 +17015,13 @@ function createVersionSelector(props) {
17170
17015
  id: contentId
17171
17016
  };
17172
17017
  function getOptionProps(value) {
17173
- const version = versions.find((v2) => v2.value === value);
17018
+ const version2 = versions.find((v2) => v2.value === value);
17174
17019
  const base = {
17175
17020
  role: "option",
17176
17021
  "aria-selected": selectedVersion === value,
17177
17022
  "data-value": value
17178
17023
  };
17179
- if (version?.isLatest) {
17024
+ if (version2?.isLatest) {
17180
17025
  return { ...base, "data-latest": "true" };
17181
17026
  }
17182
17027
  return base;
@@ -18829,9 +18674,23 @@ var Avatar2 = React52__namespace.forwardRef(
18829
18674
  var AvatarImage = React52__namespace.forwardRef(
18830
18675
  function AvatarImage2({ className, src, alt = "", onLoad, onError, ...props }, ref) {
18831
18676
  const { imageError, setImageLoaded, setImageError } = React52__namespace.useContext(AvatarContext);
18677
+ const imageRef = React52__namespace.useRef(null);
18678
+ const mergedRef = React52__namespace.useCallback((node) => {
18679
+ imageRef.current = node;
18680
+ if (typeof ref === "function") {
18681
+ const cleanup = ref(node);
18682
+ if (typeof cleanup === "function") {
18683
+ return () => {
18684
+ imageRef.current = null;
18685
+ cleanup();
18686
+ };
18687
+ }
18688
+ } else if (ref) ref.current = node;
18689
+ }, [ref]);
18832
18690
  React52__namespace.useEffect(() => {
18833
- setImageLoaded(false);
18834
- setImageError(false);
18691
+ const image = imageRef.current;
18692
+ setImageLoaded(!!image?.complete && image.naturalWidth > 0);
18693
+ setImageError(!!image?.complete && image.naturalWidth === 0);
18835
18694
  }, [src, setImageLoaded, setImageError]);
18836
18695
  const handleLoad = (e) => {
18837
18696
  setImageLoaded(true);
@@ -18845,7 +18704,7 @@ var AvatarImage = React52__namespace.forwardRef(
18845
18704
  return /* @__PURE__ */ jsxRuntime.jsx(
18846
18705
  "img",
18847
18706
  {
18848
- ref,
18707
+ ref: mergedRef,
18849
18708
  className: cn(avatarImageVariants(), className),
18850
18709
  src,
18851
18710
  alt,
@@ -30475,7 +30334,7 @@ function createPageHeader(props = {}) {
30475
30334
  };
30476
30335
  }
30477
30336
  var pageHeaderClass = "flex flex-wrap items-start justify-between gap-4";
30478
- var pageHeaderTextClass = "flex min-w-0 flex-1 flex-col gap-1";
30337
+ var pageHeaderTextClass = "flex min-w-0 basis-64 grow flex-col gap-1";
30479
30338
  var pageHeaderKickerClass = "break-words text-[11px] uppercase tracking-wider text-muted-foreground";
30480
30339
  var pageHeaderTitleClass = "break-words text-xl font-semibold text-foreground";
30481
30340
  var pageHeaderDescriptionClass = "max-w-prose text-sm text-muted-foreground";