fumadocs-ui 14.4.2 → 14.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1,78 @@
1
- [data-rmiz]{display:block;position:relative}[data-rmiz-ghost]{pointer-events:none;position:absolute}[data-rmiz-btn-zoom],[data-rmiz-btn-unzoom]{display:none}[data-rmiz-content=found] img{cursor:zoom-in}[data-rmiz-modal][open]{width:100vw;width:100dvw;height:100vh;background-color:transparent;max-width:none;height:100dvh;max-height:none;margin:0;padding:0;position:fixed;overflow:hidden}[data-rmiz-modal]:focus-visible{outline:none}[data-rmiz-modal-overlay]{transition:background-color .3s;position:absolute;top:0;bottom:0;left:0;right:0}[data-rmiz-modal-overlay=hidden]{background-color:transparent}[data-rmiz-modal-overlay=visible]{--tw-bg-opacity:1;background-color:hsl(var(--background)/var(--tw-bg-opacity))}[data-rmiz-modal-content]{width:100%;height:100%;position:relative}[data-rmiz-modal]::-ms-backdrop{display:none}[data-rmiz-modal]::backdrop{display:none}[data-rmiz-modal-img]{cursor:zoom-out;image-rendering:high-quality;transform-origin:0 0;transition:transform .3s;position:absolute}@media (prefers-reduced-motion:reduce){[data-rmiz-modal-overlay],[data-rmiz-modal-img]{transition-duration:.01ms!important}}
1
+ [data-rmiz] {
2
+ display: block;
3
+ position: relative;
4
+ }
5
+
6
+ [data-rmiz-ghost] {
7
+ pointer-events: none;
8
+ position: absolute;
9
+ }
10
+
11
+ [data-rmiz-btn-zoom],
12
+ [data-rmiz-btn-unzoom] {
13
+ display: none;
14
+ }
15
+
16
+ [data-rmiz-content='found'] img {
17
+ cursor: zoom-in;
18
+ }
19
+
20
+ [data-rmiz-modal][open] {
21
+ width: 100vw /* fallback */;
22
+ width: 100dvw;
23
+
24
+ height: 100vh /* fallback */;
25
+ height: 100dvh;
26
+
27
+ background-color: transparent;
28
+ max-width: none;
29
+ max-height: none;
30
+ margin: 0;
31
+ padding: 0;
32
+ position: fixed;
33
+ overflow: hidden;
34
+ }
35
+
36
+ [data-rmiz-modal]:focus-visible {
37
+ outline: none;
38
+ }
39
+
40
+ [data-rmiz-modal-overlay] {
41
+ transition: background-color 0.3s;
42
+ position: absolute;
43
+ inset: 0;
44
+ }
45
+
46
+ [data-rmiz-modal-overlay='hidden'] {
47
+ background-color: transparent;
48
+ }
49
+
50
+ [data-rmiz-modal-overlay='visible'] {
51
+ --tw-bg-opacity: 1;
52
+ background-color: hsl(var(--background) / var(--tw-bg-opacity, 1));
53
+ }
54
+
55
+ [data-rmiz-modal-content] {
56
+ width: 100%;
57
+ height: 100%;
58
+ position: relative;
59
+ }
60
+
61
+ [data-rmiz-modal]::backdrop {
62
+ display: none;
63
+ }
64
+
65
+ [data-rmiz-modal-img] {
66
+ cursor: zoom-out;
67
+ image-rendering: high-quality;
68
+ transform-origin: 0 0;
69
+ transition: transform 0.3s;
70
+ position: absolute;
71
+ }
72
+
73
+ @media (prefers-reduced-motion: reduce) {
74
+ [data-rmiz-modal-overlay],
75
+ [data-rmiz-modal-img] {
76
+ transition-duration: 0.01ms !important;
77
+ }
78
+ }
@@ -15,7 +15,11 @@ export interface TabsProps extends BaseProps {
15
15
  */
16
16
  defaultIndex?: number;
17
17
  items?: string[];
18
+ /**
19
+ * If true, updates the URL hash based on the tab's id
20
+ */
21
+ updateAnchor?: boolean;
18
22
  }
19
- export declare function Tabs({ groupId, items, persist, defaultIndex, ...props }: TabsProps): React.ReactElement;
20
- export declare function Tab({ value, className, ...props }: TabsContentProps): React.ReactElement;
23
+ export declare function Tabs({ groupId, items, persist, defaultIndex, updateAnchor, ...props }: TabsProps): import("react/jsx-runtime").JSX.Element;
24
+ export declare function Tab({ value, className, ...props }: TabsContentProps): import("react/jsx-runtime").JSX.Element;
21
25
  //# sourceMappingURL=tabs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tabs.d.ts","sourceRoot":"","sources":["../../src/components/tabs.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,E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EACpB,GAAG,KAAK,EACT,EAAE,SAAS,2CA+EX;AAMD,wBAAgB,GAAG,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,gBAAgB,2CAkBnE"}
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useMemo, useState, useCallback, createContext, useContext, useRef, useLayoutEffect, useEffect, } from 'react';
3
+ import { useMemo, useState, useCallback, createContext, useContext, useRef, useLayoutEffect, } from 'react';
4
4
  import { cn } from '../utils/cn';
5
5
  import * as Primitive from './ui/tabs';
6
6
  export { Primitive };
@@ -14,19 +14,20 @@ function removeChangeListener(id, listener) {
14
14
  const list = listeners.get(id) ?? [];
15
15
  listeners.set(id, list.filter((item) => item !== listener));
16
16
  }
17
- const ValueChangeContext = createContext(() => undefined);
18
- export function Tabs({ groupId, items = [], persist = false, defaultIndex = 0, ...props }) {
17
+ const ValueToMapContext = createContext(undefined);
18
+ export function Tabs({ groupId, items = [], persist = false, defaultIndex = 0, updateAnchor = false, ...props }) {
19
19
  const values = useMemo(() => items.map((item) => toValue(item)), [items]);
20
20
  const [value, setValue] = useState(values[defaultIndex]);
21
- const valuesRef = useRef(values);
22
- valuesRef.current = values;
21
+ const valueToIdMapRef = useRef(new Map());
22
+ const onChangeRef = useRef();
23
+ onChangeRef.current = (v) => {
24
+ if (values.includes(v))
25
+ setValue(v);
26
+ };
23
27
  useLayoutEffect(() => {
24
28
  if (!groupId)
25
29
  return;
26
- const onUpdate = (v) => {
27
- if (valuesRef.current.includes(v))
28
- setValue(v);
29
- };
30
+ const onUpdate = (v) => onChangeRef.current?.(v);
30
31
  const previous = persist
31
32
  ? localStorage.getItem(groupId)
32
33
  : sessionStorage.getItem(groupId);
@@ -37,7 +38,21 @@ export function Tabs({ groupId, items = [], persist = false, defaultIndex = 0, .
37
38
  removeChangeListener(groupId, onUpdate);
38
39
  };
39
40
  }, [groupId, persist]);
41
+ useLayoutEffect(() => {
42
+ const hash = window.location.hash.slice(1);
43
+ if (!hash)
44
+ return;
45
+ const entry = Array.from(valueToIdMapRef.current.entries()).find(([_, id]) => id === hash);
46
+ if (entry)
47
+ setValue(entry[0]);
48
+ }, []);
40
49
  const onValueChange = useCallback((v) => {
50
+ if (updateAnchor) {
51
+ const id = valueToIdMapRef.current.get(v);
52
+ if (id) {
53
+ window.history.replaceState(null, '', `#${id}`);
54
+ }
55
+ }
41
56
  if (groupId) {
42
57
  listeners.get(groupId)?.forEach((item) => {
43
58
  item(v);
@@ -50,20 +65,17 @@ export function Tabs({ groupId, items = [], persist = false, defaultIndex = 0, .
50
65
  else {
51
66
  setValue(v);
52
67
  }
53
- }, [groupId, persist]);
54
- return (_jsxs(Primitive.Tabs, { value: value, onValueChange: onValueChange, ...props, className: cn('my-4', props.className), children: [_jsx(Primitive.TabsList, { children: values.map((v, i) => (_jsx(Primitive.TabsTrigger, { value: v, children: items[i] }, v))) }), _jsx(ValueChangeContext.Provider, { value: onValueChange, children: props.children })] }));
68
+ }, [groupId, persist, updateAnchor]);
69
+ return (_jsxs(Primitive.Tabs, { value: value, onValueChange: onValueChange, ...props, className: cn('my-4', props.className), children: [_jsx(Primitive.TabsList, { children: values.map((v, i) => (_jsx(Primitive.TabsTrigger, { value: v, children: items[i] }, v))) }), _jsx(ValueToMapContext.Provider, { value: valueToIdMapRef.current, children: props.children })] }));
55
70
  }
56
71
  function toValue(v) {
57
72
  return v.toLowerCase().replace(/\s/, '-');
58
73
  }
59
74
  export function Tab({ value, className, ...props }) {
60
75
  const v = toValue(value);
61
- const onValueChange = useContext(ValueChangeContext);
62
- useEffect(() => {
63
- const hash = window.location.hash.slice(1);
64
- if (hash === props.id) {
65
- onValueChange(v);
66
- }
67
- }, [onValueChange, props.id, v]);
76
+ const valueToIdMap = useContext(ValueToMapContext);
77
+ if (props.id) {
78
+ valueToIdMap?.set(v, props.id);
79
+ }
68
80
  return (_jsx(Primitive.TabsContent, { value: v, className: cn('prose-no-margin [&>figure:only-child]:-m-4 [&>figure:only-child]:rounded-none [&>figure:only-child]:border-none', className), ...props }));
69
81
  }