fumadocs-core 12.5.3 → 12.5.4

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,22 +1,14 @@
1
+ import {
2
+ useOnChange
3
+ } from "./chunk-KGMG4N3Y.js";
1
4
  import {
2
5
  mergeRefs,
3
6
  useAnchorObserver
4
- } from "./chunk-EP2HYVJS.js";
5
- import {
6
- __objRest,
7
- __spreadProps,
8
- __spreadValues
9
- } from "./chunk-CWMXXUWU.js";
7
+ } from "./chunk-V6DBK6TW.js";
8
+ import "./chunk-MLKGABMK.js";
10
9
 
11
10
  // src/toc-internal.tsx
12
- import {
13
- createContext,
14
- forwardRef,
15
- useContext,
16
- useEffect,
17
- useMemo,
18
- useRef
19
- } from "react";
11
+ import { createContext, forwardRef, useContext, useMemo, useRef } from "react";
20
12
  import scrollIntoView from "scroll-into-view-if-needed";
21
13
  import { jsx } from "react/jsx-runtime";
22
14
  var ActiveAnchorContext = createContext(void 0);
@@ -41,18 +33,16 @@ function AnchorProvider({
41
33
  return /* @__PURE__ */ jsx(ActiveAnchorContext.Provider, { value: activeAnchor, children });
42
34
  }
43
35
  var TOCItem = forwardRef(
44
- (_a, ref) => {
45
- var _b = _a, { onActiveChange } = _b, props = __objRest(_b, ["onActiveChange"]);
36
+ ({ onActiveChange, ...props }, ref) => {
46
37
  const containerRef = useContext(ScrollContext);
47
38
  const activeAnchor = useActiveAnchor();
48
39
  const anchorRef = useRef(null);
49
40
  const mergedRef = mergeRefs(anchorRef, ref);
50
41
  const isActive = activeAnchor === props.href.split("#")[1];
51
- const onActiveRef = useRef();
52
- onActiveRef.current = (active) => {
42
+ useOnChange(isActive, (v) => {
53
43
  const element = anchorRef.current;
54
44
  if (!element) return;
55
- if (active && containerRef.current) {
45
+ if (v && containerRef.current) {
56
46
  scrollIntoView(element, {
57
47
  behavior: "smooth",
58
48
  block: "center",
@@ -61,13 +51,9 @@ var TOCItem = forwardRef(
61
51
  boundary: containerRef.current
62
52
  });
63
53
  }
64
- onActiveChange == null ? void 0 : onActiveChange(active);
65
- };
66
- useEffect(() => {
67
- var _a2;
68
- (_a2 = onActiveRef.current) == null ? void 0 : _a2.call(onActiveRef, isActive);
69
- }, [isActive]);
70
- return /* @__PURE__ */ jsx("a", __spreadProps(__spreadValues({ ref: mergedRef, "data-active": isActive }, props), { children: props.children }));
54
+ onActiveChange?.(v);
55
+ });
56
+ return /* @__PURE__ */ jsx("a", { ref: mergedRef, "data-active": isActive, ...props, children: props.children });
71
57
  }
72
58
  );
73
59
  TOCItem.displayName = "TOCItem";
package/dist/toc.js CHANGED
@@ -1,12 +1,8 @@
1
1
  import {
2
2
  mergeRefs,
3
3
  useAnchorObserver
4
- } from "./chunk-EP2HYVJS.js";
5
- import {
6
- __objRest,
7
- __spreadProps,
8
- __spreadValues
9
- } from "./chunk-CWMXXUWU.js";
4
+ } from "./chunk-V6DBK6TW.js";
5
+ import "./chunk-MLKGABMK.js";
10
6
 
11
7
  // src/toc.tsx
12
8
  import {
@@ -25,11 +21,10 @@ var useActiveAnchor = (url) => {
25
21
  return activeAnchor === url.split("#")[1];
26
22
  };
27
23
  var TOCProvider = forwardRef(
28
- (_a, ref) => {
29
- var _b = _a, { toc } = _b, props = __objRest(_b, ["toc"]);
24
+ ({ toc, ...props }, ref) => {
30
25
  const containerRef = useRef(null);
31
26
  const mergedRef = mergeRefs(containerRef, ref);
32
- return /* @__PURE__ */ jsx("div", __spreadProps(__spreadValues({ ref: mergedRef }, props), { children: /* @__PURE__ */ jsx(TOCScrollProvider, { toc, containerRef, children: props.children }) }));
27
+ return /* @__PURE__ */ jsx("div", { ref: mergedRef, ...props, children: /* @__PURE__ */ jsx(TOCScrollProvider, { toc, containerRef, children: props.children }) });
33
28
  }
34
29
  );
35
30
  TOCProvider.displayName = "TOCProvider";
@@ -45,8 +40,7 @@ function TOCScrollProvider({
45
40
  return /* @__PURE__ */ jsx(ActiveAnchorContext.Provider, { value: { containerRef, activeAnchor }, children });
46
41
  }
47
42
  var TOCItem = forwardRef(
48
- (_a, ref) => {
49
- var _b = _a, { containerRef: container } = _b, props = __objRest(_b, ["containerRef"]);
43
+ ({ containerRef: container, ...props }, ref) => {
50
44
  const { containerRef = container } = useContext(ActiveAnchorContext);
51
45
  const active = useActiveAnchor(props.href);
52
46
  const anchorRef = useRef(null);
@@ -63,7 +57,7 @@ var TOCItem = forwardRef(
63
57
  });
64
58
  }
65
59
  }, [active, containerRef]);
66
- return /* @__PURE__ */ jsx("a", __spreadProps(__spreadValues({ ref: mergedRef, "data-active": active }, props), { children: props.children }));
60
+ return /* @__PURE__ */ jsx("a", { ref: mergedRef, "data-active": active, ...props, children: props.children });
67
61
  }
68
62
  );
69
63
  TOCItem.displayName = "TOCItem";
@@ -0,0 +1,3 @@
1
+ declare function useOnChange<T>(value: T, onChange: (current: T, previous: T) => void): void;
2
+
3
+ export { useOnChange };
@@ -0,0 +1,7 @@
1
+ import {
2
+ useOnChange
3
+ } from "../chunk-KGMG4N3Y.js";
4
+ import "../chunk-MLKGABMK.js";
5
+ export {
6
+ useOnChange
7
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "12.5.3",
3
+ "version": "12.5.4",
4
4
  "description": "The library for building a documentation website in Next.js",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -48,6 +48,10 @@
48
48
  "import": "./dist/source/index.js",
49
49
  "types": "./dist/source/index.d.ts"
50
50
  },
51
+ "./utils/use-on-change": {
52
+ "import": "./dist/utils/use-on-change.js",
53
+ "types": "./dist/utils/use-on-change.d.ts"
54
+ },
51
55
  "./link": {
52
56
  "import": "./dist/link.js",
53
57
  "types": "./dist/link.d.ts"
@@ -104,6 +108,9 @@
104
108
  "middleware": [
105
109
  "./dist/middleware.d.ts"
106
110
  ],
111
+ "utils/use-on-change": [
112
+ "./dist/utils/use-on-change.d.ts"
113
+ ],
107
114
  "mdx-plugins": [
108
115
  "./dist/mdx-plugins/index.d.ts"
109
116
  ],
@@ -143,7 +150,7 @@
143
150
  "@types/hast": "^3.0.4",
144
151
  "@types/mdast": "^4.0.3",
145
152
  "@types/negotiator": "^0.6.3",
146
- "@types/node": "20.14.10",
153
+ "@types/node": "20.14.11",
147
154
  "@types/react": "^18.3.3",
148
155
  "@types/react-dom": "^18.3.0",
149
156
  "algoliasearch": "^4.24.0",
@@ -1,63 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __objRest = (source, exclude) => {
21
- var target = {};
22
- for (var prop in source)
23
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
- target[prop] = source[prop];
25
- if (source != null && __getOwnPropSymbols)
26
- for (var prop of __getOwnPropSymbols(source)) {
27
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
- target[prop] = source[prop];
29
- }
30
- return target;
31
- };
32
- var __export = (target, all) => {
33
- for (var name in all)
34
- __defProp(target, name, { get: all[name], enumerable: true });
35
- };
36
- var __async = (__this, __arguments, generator) => {
37
- return new Promise((resolve, reject) => {
38
- var fulfilled = (value) => {
39
- try {
40
- step(generator.next(value));
41
- } catch (e) {
42
- reject(e);
43
- }
44
- };
45
- var rejected = (value) => {
46
- try {
47
- step(generator.throw(value));
48
- } catch (e) {
49
- reject(e);
50
- }
51
- };
52
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
53
- step((generator = generator.apply(__this, __arguments)).next());
54
- });
55
- };
56
-
57
- export {
58
- __spreadValues,
59
- __spreadProps,
60
- __objRest,
61
- __export,
62
- __async
63
- };
@@ -1,52 +0,0 @@
1
- import {
2
- __objRest,
3
- __spreadProps,
4
- __spreadValues
5
- } from "./chunk-CWMXXUWU.js";
6
-
7
- // src/link.tsx
8
- import Original from "next/link";
9
- import { forwardRef } from "react";
10
- import { jsx } from "react/jsx-runtime";
11
- var Link = forwardRef(
12
- (_a, ref) => {
13
- var _b = _a, {
14
- href = "#",
15
- external = !(href.startsWith("/") || href.startsWith("#") || href.startsWith(".")),
16
- prefetch,
17
- replace
18
- } = _b, props = __objRest(_b, [
19
- "href",
20
- "external",
21
- "prefetch",
22
- "replace"
23
- ]);
24
- if (external) {
25
- return /* @__PURE__ */ jsx(
26
- "a",
27
- __spreadProps(__spreadValues({
28
- ref,
29
- href,
30
- rel: "noreferrer noopener",
31
- target: "_blank"
32
- }, props), {
33
- children: props.children
34
- })
35
- );
36
- }
37
- return /* @__PURE__ */ jsx(
38
- Original,
39
- __spreadValues({
40
- ref,
41
- href,
42
- prefetch,
43
- replace
44
- }, props)
45
- );
46
- }
47
- );
48
- Link.displayName = "Link";
49
-
50
- export {
51
- Link
52
- };