fumadocs-core 12.5.2 → 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,6 +1,4 @@
1
- import {
2
- __objRest
3
- } from "./chunk-CWMXXUWU.js";
1
+ import "./chunk-MLKGABMK.js";
4
2
 
5
3
  // src/breadcrumb.tsx
6
4
  import { useMemo } from "react";
@@ -11,9 +9,8 @@ function useBreadcrumb(url, tree, options) {
11
9
  );
12
10
  }
13
11
  function getBreadcrumbItems(url, tree, options = {}) {
14
- var _b;
15
- const _a = options, { includeRoot } = _a, rest = __objRest(_a, ["includeRoot"]);
16
- const path = (_b = searchPath(tree.children, url, rest)) != null ? _b : [];
12
+ const { includeRoot, ...rest } = options;
13
+ const path = searchPath(tree.children, url, rest) ?? [];
17
14
  if (includeRoot) {
18
15
  path.unshift({
19
16
  name: tree.name,
@@ -23,13 +20,12 @@ function getBreadcrumbItems(url, tree, options = {}) {
23
20
  return path;
24
21
  }
25
22
  function searchPath(nodes, url, options) {
26
- var _a, _b;
27
23
  const { includePage = true, includeSeparator = false } = options;
28
24
  let separator;
29
25
  for (const node of nodes) {
30
26
  if (includeSeparator && node.type === "separator") separator = node.name;
31
27
  if (node.type === "folder") {
32
- if (((_a = node.index) == null ? void 0 : _a.url) === url) {
28
+ if (node.index?.url === url) {
33
29
  const items2 = [];
34
30
  if (separator) items2.push({ name: separator });
35
31
  if (options.includePage)
@@ -43,7 +39,7 @@ function searchPath(nodes, url, options) {
43
39
  if (items) {
44
40
  items.unshift({
45
41
  name: node.name,
46
- url: (_b = node.index) == null ? void 0 : _b.url
42
+ url: node.index?.url
47
43
  });
48
44
  if (separator) items.unshift({ name: separator });
49
45
  return items;
@@ -0,0 +1,42 @@
1
+ // src/link.tsx
2
+ import Original from "next/link";
3
+ import { forwardRef } from "react";
4
+ import { jsx } from "react/jsx-runtime";
5
+ var Link = forwardRef(
6
+ ({
7
+ href = "#",
8
+ external = !(href.startsWith("/") || href.startsWith("#") || href.startsWith(".")),
9
+ prefetch,
10
+ replace,
11
+ ...props
12
+ }, ref) => {
13
+ if (external) {
14
+ return /* @__PURE__ */ jsx(
15
+ "a",
16
+ {
17
+ ref,
18
+ href,
19
+ rel: "noreferrer noopener",
20
+ target: "_blank",
21
+ ...props,
22
+ children: props.children
23
+ }
24
+ );
25
+ }
26
+ return /* @__PURE__ */ jsx(
27
+ Original,
28
+ {
29
+ ref,
30
+ href,
31
+ prefetch,
32
+ replace,
33
+ ...props
34
+ }
35
+ );
36
+ }
37
+ );
38
+ Link.displayName = "Link";
39
+
40
+ export {
41
+ Link
42
+ };
@@ -0,0 +1,13 @@
1
+ // src/utils/use-on-change.ts
2
+ import { useState } from "react";
3
+ function useOnChange(value, onChange) {
4
+ const [prev, setPrev] = useState(value);
5
+ if (prev !== value) {
6
+ onChange(value, prev);
7
+ setPrev(value);
8
+ }
9
+ }
10
+
11
+ export {
12
+ useOnChange
13
+ };
@@ -0,0 +1,9 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ export {
8
+ __export
9
+ };
@@ -26,7 +26,7 @@ function useAnchorObserver(watch) {
26
26
  return entry.target.id;
27
27
  }
28
28
  }
29
- return f != null ? f : watch[0];
29
+ return f ?? watch[0];
30
30
  });
31
31
  },
32
32
  { rootMargin: `0% 0% -80% 0%` }
@@ -12,7 +12,7 @@ function flattenNode(node) {
12
12
 
13
13
  // src/mdx-plugins/remark-heading.ts
14
14
  var slugger = new Slugger();
15
- var regex = new RegExp("\\s*\\[#(?<slug>[^]+?)]\\s*$");
15
+ var regex = /\s*\[#(?<slug>[^]+?)]\s*$/;
16
16
  function remarkHeading({
17
17
  slug: defaultSlug,
18
18
  customId = true
@@ -21,13 +21,12 @@ function remarkHeading({
21
21
  const toc = [];
22
22
  slugger.reset();
23
23
  visit(root, "heading", (heading) => {
24
- var _a;
25
- heading.data || (heading.data = {});
26
- (_a = heading.data).hProperties || (_a.hProperties = {});
24
+ heading.data ||= {};
25
+ heading.data.hProperties ||= {};
27
26
  const lastNode = heading.children.at(-1);
28
- if (!heading.data.hProperties.id && (lastNode == null ? void 0 : lastNode.type) === "text" && customId) {
27
+ if (!heading.data.hProperties.id && lastNode?.type === "text" && customId) {
29
28
  const match = regex.exec(lastNode.value);
30
- if (match == null ? void 0 : match[1]) {
29
+ if (match?.[1]) {
31
30
  heading.data.hProperties.id = match[1];
32
31
  lastNode.value = lastNode.value.slice(0, match.index);
33
32
  }
@@ -1,5 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { LinkProps } from './link.js';
3
+ import 'next/link';
3
4
 
4
5
  type DynamicLinkProps = LinkProps;
5
6
  /**
@@ -7,8 +8,6 @@ type DynamicLinkProps = LinkProps;
7
8
  *
8
9
  * It supports dynamic hrefs, which means you can use `/[lang]/my-page` with `dynamicHrefs` enabled
9
10
  */
10
- declare const DynamicLink: react.ForwardRefExoticComponent<react.AnchorHTMLAttributes<HTMLAnchorElement> & {
11
- external?: boolean;
12
- } & react.RefAttributes<HTMLAnchorElement>>;
11
+ declare const DynamicLink: react.ForwardRefExoticComponent<LinkProps & react.RefAttributes<HTMLAnchorElement>>;
13
12
 
14
13
  export { DynamicLink, type DynamicLinkProps, DynamicLink as default };
@@ -1,28 +1,24 @@
1
1
  "use client";
2
2
  import {
3
3
  Link
4
- } from "./chunk-XB7CNOKH.js";
5
- import {
6
- __objRest,
7
- __spreadValues
8
- } from "./chunk-CWMXXUWU.js";
4
+ } from "./chunk-DVOZJZGH.js";
5
+ import "./chunk-MLKGABMK.js";
9
6
 
10
7
  // src/dynamic-link.tsx
11
8
  import { useParams } from "next/navigation";
12
9
  import { forwardRef, useMemo } from "react";
13
10
  import { jsx } from "react/jsx-runtime";
14
11
  var DynamicLink = forwardRef(
15
- (_a, ref) => {
16
- var _b = _a, { href } = _b, props = __objRest(_b, ["href"]);
12
+ ({ href, ...props }, ref) => {
17
13
  const params = useParams();
18
14
  const url = useMemo(() => {
19
- return href == null ? void 0 : href.replace(/\[.*\]/, (key) => {
15
+ return href?.replace(/\[.*\]/, (key) => {
20
16
  const mappedKey = key.slice(1, -1);
21
17
  const value = mappedKey in params ? params[mappedKey] : "undefined";
22
18
  return typeof value === "string" ? value : value.join("/");
23
19
  });
24
20
  }, [params, href]);
25
- return /* @__PURE__ */ jsx(Link, __spreadValues({ ref, href: url }, props));
21
+ return /* @__PURE__ */ jsx(Link, { ref, href: url, ...props });
26
22
  }
27
23
  );
28
24
  DynamicLink.displayName = "DynamicLink";
package/dist/link.d.ts CHANGED
@@ -1,24 +1,18 @@
1
1
  import * as react from 'react';
2
2
  import { AnchorHTMLAttributes } from 'react';
3
+ import { LinkProps as LinkProps$1 } from 'next/link';
3
4
 
4
- type LinkProps = AnchorHTMLAttributes<HTMLAnchorElement> & {
5
+ interface LinkProps extends Pick<LinkProps$1, 'prefetch' | 'replace'>, AnchorHTMLAttributes<HTMLAnchorElement> {
5
6
  /**
6
7
  * If the href is an external URL
7
8
  *
8
9
  * automatically determined by default
9
10
  */
10
11
  external?: boolean;
11
- };
12
+ }
12
13
  /**
13
- * Wraps `next/link` and safe to use in mdx documents
14
+ * Wraps `next/link` and safe to use in MDX documents
14
15
  */
15
- declare const Link: react.ForwardRefExoticComponent<AnchorHTMLAttributes<HTMLAnchorElement> & {
16
- /**
17
- * If the href is an external URL
18
- *
19
- * automatically determined by default
20
- */
21
- external?: boolean;
22
- } & react.RefAttributes<HTMLAnchorElement>>;
16
+ declare const Link: react.ForwardRefExoticComponent<LinkProps & react.RefAttributes<HTMLAnchorElement>>;
23
17
 
24
18
  export { type LinkProps, Link as default };
package/dist/link.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  Link
3
- } from "./chunk-XB7CNOKH.js";
4
- import "./chunk-CWMXXUWU.js";
3
+ } from "./chunk-DVOZJZGH.js";
4
+ import "./chunk-MLKGABMK.js";
5
5
  export {
6
6
  Link as default
7
7
  };
@@ -1,13 +1,11 @@
1
1
  import {
2
2
  flattenNode,
3
3
  remarkHeading
4
- } from "../chunk-QRNTLL6S.js";
4
+ } from "../chunk-YKIM647L.js";
5
5
  import {
6
6
  slash
7
7
  } from "../chunk-UWEEHUJV.js";
8
- import {
9
- __spreadValues
10
- } from "../chunk-CWMXXUWU.js";
8
+ import "../chunk-MLKGABMK.js";
11
9
 
12
10
  // src/mdx-plugins/index.ts
13
11
  import {
@@ -140,8 +138,14 @@ var defaultIcons = {
140
138
  }
141
139
  };
142
140
  function transformerIcon(options = {}) {
143
- const shortcuts = __spreadValues(__spreadValues({}, defaultShortcuts), options.shortcuts);
144
- const icons = __spreadValues(__spreadValues({}, defaultIcons), options.extend);
141
+ const shortcuts = {
142
+ ...defaultShortcuts,
143
+ ...options.shortcuts
144
+ };
145
+ const icons = {
146
+ ...defaultIcons,
147
+ ...options.extend
148
+ };
145
149
  const defaultIcon = "default" in icons ? icons.default : void 0;
146
150
  return {
147
151
  name: "rehype-code:icon",
@@ -162,15 +166,15 @@ function transformerIcon(options = {}) {
162
166
  var metaValues = [
163
167
  {
164
168
  name: "title",
165
- regex: new RegExp('title="(?<value>[^"]*)"')
169
+ regex: /title="(?<value>[^"]*)"/
166
170
  },
167
171
  {
168
172
  name: "custom",
169
- regex: new RegExp('custom="(?<value>[^"]+)"')
173
+ regex: /custom="(?<value>[^"]+)"/
170
174
  },
171
175
  {
172
176
  name: "tab",
173
- regex: new RegExp('tab="(?<value>[^"]+)"')
177
+ regex: /tab="(?<value>[^"]+)"/
174
178
  }
175
179
  ];
176
180
  var rehypeCodeDefaultOptions = {
@@ -203,15 +207,17 @@ var rehypeCodeDefaultOptions = {
203
207
  }
204
208
  };
205
209
  function rehypeCode(options = {}) {
206
- const codeOptions = __spreadValues(__spreadValues({}, rehypeCodeDefaultOptions), options);
207
- codeOptions.transformers || (codeOptions.transformers = []);
210
+ const codeOptions = {
211
+ ...rehypeCodeDefaultOptions,
212
+ ...options
213
+ };
214
+ codeOptions.transformers ||= [];
208
215
  codeOptions.transformers = [
209
216
  {
210
217
  name: "rehype-code:pre-process",
211
218
  preprocess(code, { meta }) {
212
- var _a;
213
219
  if (meta && codeOptions.filterMetaString) {
214
- meta.__raw = codeOptions.filterMetaString((_a = meta.__raw) != null ? _a : "");
220
+ meta.__raw = codeOptions.filterMetaString(meta.__raw ?? "");
215
221
  }
216
222
  return code.replace(/\n$/, "");
217
223
  },
@@ -245,7 +251,7 @@ function transformerTab() {
245
251
  name: "rehype-code:tab",
246
252
  root(root) {
247
253
  const meta = this.options.meta;
248
- if (typeof (meta == null ? void 0 : meta.tab) !== "string") return root;
254
+ if (typeof meta?.tab !== "string") return root;
249
255
  return {
250
256
  type: "root",
251
257
  children: [
@@ -279,7 +285,6 @@ function remarkImage({
279
285
  return (tree, _file, done) => {
280
286
  const importsToInject = [];
281
287
  visit(tree, "image", (node) => {
282
- var _a;
283
288
  let url = decodeURI(node.url);
284
289
  if (!url || EXTERNAL_URL_REGEX.test(url)) {
285
290
  return;
@@ -301,7 +306,7 @@ function remarkImage({
301
306
  {
302
307
  type: "mdxJsxAttribute",
303
308
  name: "alt",
304
- value: (_a = node.alt) != null ? _a : "image"
309
+ value: node.alt ?? "image"
305
310
  },
306
311
  hasBlur && {
307
312
  type: "mdxJsxAttribute",
@@ -372,14 +377,13 @@ function remarkStructure({
372
377
  const data = { contents: [], headings: [] };
373
378
  let lastHeading = "";
374
379
  visit2(node, types, (element) => {
375
- var _a, _b;
376
380
  if (element.type === "root") return;
377
381
  const content = flattenNode(element).trim();
378
382
  if (element.type === "heading") {
379
- element.data || (element.data = {});
380
- (_a = element.data).hProperties || (_a.hProperties = {});
383
+ element.data ||= {};
384
+ element.data.hProperties ||= {};
381
385
  const properties = element.data.hProperties;
382
- const id = (_b = properties.id) != null ? _b : slugger.slug(content);
386
+ const id = properties.id ?? slugger.slug(content);
383
387
  data.headings.push({
384
388
  id,
385
389
  content
@@ -1,4 +1,4 @@
1
- import "./chunk-CWMXXUWU.js";
1
+ import "./chunk-MLKGABMK.js";
2
2
 
3
3
  // src/middleware.ts
4
4
  import { match as matchLocale } from "@formatjs/intl-localematcher";
@@ -1,21 +1,17 @@
1
- import {
2
- __async
3
- } from "../chunk-CWMXXUWU.js";
1
+ import "../chunk-MLKGABMK.js";
4
2
 
5
3
  // src/search/client.ts
6
4
  import { useEffect, useState } from "react";
7
5
  import useSWR from "swr";
8
- function fetchDocs(api, query, locale, tag) {
9
- return __async(this, null, function* () {
10
- if (query.length === 0) return "empty";
11
- const params = new URLSearchParams();
12
- params.set("query", query);
13
- if (locale) params.set("locale", locale);
14
- if (tag) params.set("tag", tag);
15
- const res = yield fetch(`${api}?${params.toString()}`);
16
- if (!res.ok) throw new Error(yield res.text());
17
- return yield res.json();
18
- });
6
+ async function fetchDocs(api, query, locale, tag) {
7
+ if (query.length === 0) return "empty";
8
+ const params = new URLSearchParams();
9
+ params.set("query", query);
10
+ if (locale) params.set("locale", locale);
11
+ if (tag) params.set("tag", tag);
12
+ const res = await fetch(`${api}?${params.toString()}`);
13
+ if (!res.ok) throw new Error(await res.text());
14
+ return await res.json();
19
15
  }
20
16
  function useDocsSearch(locale, tag, api = "/api/search", delayMs = 100) {
21
17
  const [search, setSearch] = useState("");