fumadocs-core 16.7.6 → 16.7.7

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,7 +1,7 @@
1
1
  import { t as RehypeCodeOptions } from "../../rehype-code-DFx-xacR.js";
2
2
  import { t as RemarkImageOptions } from "../../remark-image-DQlJevNY.js";
3
3
  import { r as StructureOptions } from "../../remark-structure-c-gm2PCy.js";
4
- import { t as RemarkHeadingOptions } from "../../remark-heading-cvYRraso.js";
4
+ import { t as RemarkHeadingOptions } from "../../remark-heading-BVc1nYW5.js";
5
5
  import { t as RemarkCodeTabOptions } from "../../remark-code-tab-Dk79zZwn.js";
6
6
  import { t as RemarkNpmOptions } from "../../remark-npm-7SDuqMc6.js";
7
7
  import { t as ResolvePlugins } from "../../util-D2LMvKsn.js";
@@ -1,7 +1,7 @@
1
1
  import { t as RehypeCodeOptions } from "../../rehype-code-DFx-xacR.js";
2
2
  import { t as RemarkImageOptions } from "../../remark-image-DQlJevNY.js";
3
3
  import { r as StructureOptions } from "../../remark-structure-c-gm2PCy.js";
4
- import { t as RemarkHeadingOptions } from "../../remark-heading-cvYRraso.js";
4
+ import { t as RemarkHeadingOptions } from "../../remark-heading-BVc1nYW5.js";
5
5
  import { t as RemarkCodeTabOptions } from "../../remark-code-tab-Dk79zZwn.js";
6
6
  import { t as RemarkNpmOptions } from "../../remark-npm-7SDuqMc6.js";
7
7
  import { t as ResolvePlugins } from "../../util-D2LMvKsn.js";
@@ -1,4 +1,4 @@
1
- import { c as TOCItemType } from "../toc-DjyooJ0-.js";
1
+ import { c as TOCItemType } from "../toc-Bw56X0rx.js";
2
2
  import { Compatible } from "vfile";
3
3
  import { PluggableList } from "unified";
4
4
 
@@ -3,10 +3,10 @@ import { a as CodeBlockIcon, i as transformerTab, o as transformerIcon } from ".
3
3
  import { n as rehypeCode, r as rehypeCodeDefaultOptions, t as RehypeCodeOptions } from "../rehype-code-DFx-xacR.js";
4
4
  import { n as remarkImage, t as RemarkImageOptions } from "../remark-image-DQlJevNY.js";
5
5
  import { a as defaultStringifier, c as structure, i as StructuredData, n as StringifyOptions, o as remarkStructure, r as StructureOptions, s as remarkStructureDefaultOptions, t as Stringifier } from "../remark-structure-c-gm2PCy.js";
6
- import { n as remarkHeading, t as RemarkHeadingOptions } from "../remark-heading-cvYRraso.js";
6
+ import { n as remarkHeading, t as RemarkHeadingOptions } from "../remark-heading-BVc1nYW5.js";
7
7
  import { n as remarkAdmonition, t as RemarkAdmonitionOptions } from "../remark-admonition-0gZM40ZU.js";
8
8
  import { n as remarkDirectiveAdmonition, t as RemarkDirectiveAdmonitionOptions } from "../remark-directive-admonition-CxFIkQ_i.js";
9
- import { n as RehypeTocOptions, r as rehypeToc, t as RehypeTOCItemType } from "../rehype-toc-DPrrpvXd.js";
9
+ import { n as RehypeTocOptions, r as rehypeToc, t as RehypeTOCItemType } from "../rehype-toc-iWxg6ELI.js";
10
10
  import { n as remarkCodeTab, t as RemarkCodeTabOptions } from "../remark-code-tab-Dk79zZwn.js";
11
11
  import { n as remarkSteps, t as RemarkStepsOptions } from "../remark-steps-DsnXM6Xj.js";
12
12
  import { n as remarkNpm, t as RemarkNpmOptions } from "../remark-npm-7SDuqMc6.js";
@@ -1,2 +1,2 @@
1
- import { n as RehypeTocOptions, r as rehypeToc, t as RehypeTOCItemType } from "../rehype-toc-DPrrpvXd.js";
1
+ import { n as RehypeTocOptions, r as rehypeToc, t as RehypeTOCItemType } from "../rehype-toc-iWxg6ELI.js";
2
2
  export { RehypeTOCItemType, RehypeTocOptions, rehypeToc };
@@ -1,4 +1,4 @@
1
- import { r as toMdxExportRaw } from "../mdast-utils-9tJwoVTq.js";
1
+ import { i as toMdxExportRaw, n as handleTag } from "../utils-C73VXFR0.js";
2
2
  import { visit } from "unist-util-visit";
3
3
  import { toEstree } from "hast-util-to-estree";
4
4
  //#region src/mdx-plugins/rehype-toc.ts
@@ -27,19 +27,22 @@ function rehypeToc({ exportToc = true } = {}) {
27
27
  let isTocOnly = false;
28
28
  const last = element.children[element.children.length - 1];
29
29
  if (last.type === "text") {
30
- if (last.value.endsWith(NoTocTag)) {
31
- last.value = last.value.substring(0, last.value.length - 6).trimEnd();
30
+ const noToc = handleTag(last.value, NoTocTag);
31
+ if (noToc !== false) {
32
+ last.value = noToc;
32
33
  return "skip";
33
34
  }
34
- if (last.value.endsWith(TocOnlyTag)) {
35
+ const tocOnly = handleTag(last.value, TocOnlyTag);
36
+ if (tocOnly !== false) {
35
37
  isTocOnly = true;
36
- last.value = last.value.substring(0, last.value.length - 5).trimEnd();
38
+ last.value = tocOnly;
37
39
  }
38
40
  }
39
41
  items.push({
40
42
  title: element,
41
43
  depth: Number(element.tagName[1]),
42
- url: `#${id}`
44
+ url: `#${id}`,
45
+ _step: typeof element.properties["data-fd-step"] === "number" ? element.properties["data-fd-step"] : void 0
43
46
  });
44
47
  if (isTocOnly && parent && typeof idx === "number") parent.children.splice(idx, 1);
45
48
  return "skip";
@@ -58,58 +61,76 @@ function rehypeToc({ exportToc = true } = {}) {
58
61
  }
59
62
  tree.children.push(toMdxExportRaw(exportToc.name, {
60
63
  type: "ArrayExpression",
61
- elements: esmItems.map((item) => ({
62
- type: "ObjectExpression",
63
- properties: [
64
- {
65
- type: "Property",
66
- method: false,
67
- shorthand: false,
68
- computed: false,
69
- key: {
70
- type: "Identifier",
71
- name: "depth"
64
+ elements: esmItems.map((item) => {
65
+ const obj = {
66
+ type: "ObjectExpression",
67
+ properties: [
68
+ {
69
+ type: "Property",
70
+ method: false,
71
+ shorthand: false,
72
+ computed: false,
73
+ key: {
74
+ type: "Identifier",
75
+ name: "depth"
76
+ },
77
+ value: {
78
+ type: "Literal",
79
+ value: item.depth
80
+ },
81
+ kind: "init"
72
82
  },
73
- value: {
74
- type: "Literal",
75
- value: item.depth
83
+ {
84
+ type: "Property",
85
+ method: false,
86
+ shorthand: false,
87
+ computed: false,
88
+ key: {
89
+ type: "Identifier",
90
+ name: "url"
91
+ },
92
+ value: {
93
+ type: "Literal",
94
+ value: item.url
95
+ },
96
+ kind: "init"
76
97
  },
77
- kind: "init"
98
+ {
99
+ type: "Property",
100
+ method: false,
101
+ shorthand: false,
102
+ computed: false,
103
+ key: {
104
+ type: "Identifier",
105
+ name: "title"
106
+ },
107
+ value: {
108
+ type: "JSXFragment",
109
+ openingFragment: { type: "JSXOpeningFragment" },
110
+ closingFragment: { type: "JSXClosingFragment" },
111
+ children: item.title.children
112
+ },
113
+ kind: "init"
114
+ }
115
+ ]
116
+ };
117
+ if (typeof item._step === "number") obj.properties.push({
118
+ type: "Property",
119
+ method: false,
120
+ shorthand: false,
121
+ computed: false,
122
+ key: {
123
+ type: "Identifier",
124
+ name: "_step"
78
125
  },
79
- {
80
- type: "Property",
81
- method: false,
82
- shorthand: false,
83
- computed: false,
84
- key: {
85
- type: "Identifier",
86
- name: "url"
87
- },
88
- value: {
89
- type: "Literal",
90
- value: item.url
91
- },
92
- kind: "init"
126
+ value: {
127
+ type: "Literal",
128
+ value: item._step
93
129
  },
94
- {
95
- type: "Property",
96
- method: false,
97
- shorthand: false,
98
- computed: false,
99
- key: {
100
- type: "Identifier",
101
- name: "title"
102
- },
103
- value: {
104
- type: "JSXFragment",
105
- openingFragment: { type: "JSXOpeningFragment" },
106
- closingFragment: { type: "JSXClosingFragment" },
107
- children: item.title.children
108
- },
109
- kind: "init"
110
- }
111
- ]
112
- }))
130
+ kind: "init"
131
+ });
132
+ return obj;
133
+ })
113
134
  }));
114
135
  } else file.data.rehypeToc = items;
115
136
  };
@@ -1,4 +1,4 @@
1
- import { t as flattenNode } from "../mdast-utils-9tJwoVTq.js";
1
+ import { t as flattenNode } from "../utils-C73VXFR0.js";
2
2
  import { visit } from "unist-util-visit";
3
3
  //#region src/mdx-plugins/remark-admonition.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { t as flattenNode } from "../mdast-utils-9tJwoVTq.js";
1
+ import { t as flattenNode } from "../utils-C73VXFR0.js";
2
2
  import { visit } from "unist-util-visit";
3
3
  import { createHash } from "node:crypto";
4
4
  //#region src/mdx-plugins/remark-feedback-block.ts
@@ -1,2 +1,2 @@
1
- import { n as remarkHeading, t as RemarkHeadingOptions } from "../remark-heading-cvYRraso.js";
1
+ import { n as remarkHeading, t as RemarkHeadingOptions } from "../remark-heading-BVc1nYW5.js";
2
2
  export { RemarkHeadingOptions, remarkHeading };
@@ -1,4 +1,4 @@
1
- import { t as flattenNode } from "../mdast-utils-9tJwoVTq.js";
1
+ import { t as flattenNode } from "../utils-C73VXFR0.js";
2
2
  import Slugger from "github-slugger";
3
3
  import { visit } from "unist-util-visit";
4
4
  //#region src/mdx-plugins/remark-heading.ts
@@ -1,4 +1,4 @@
1
- import { n as toMdxExport } from "../mdast-utils-9tJwoVTq.js";
1
+ import { r as toMdxExport } from "../utils-C73VXFR0.js";
2
2
  import { defaultStringifier } from "./stringifier.js";
3
3
  //#region src/mdx-plugins/remark-llms.ts
4
4
  /**
@@ -1,6 +1,8 @@
1
+ import { n as handleTag } from "../utils-C73VXFR0.js";
1
2
  import { visit } from "unist-util-visit";
2
3
  //#region src/mdx-plugins/remark-steps.ts
3
4
  const StepRegex = /^(\d+)\.\s(.+)$/;
5
+ const StepTag = "[step]";
4
6
  /**
5
7
  * Convert headings in the format of `1. Hello World` into steps.
6
8
  */
@@ -27,16 +29,34 @@ function remarkSteps({ steps = "fd-steps", step = "fd-step" } = {}) {
27
29
  name: "className",
28
30
  value: steps
29
31
  }],
30
- data: { _fd_step: true },
31
32
  children
32
33
  };
33
34
  }
35
+ function handleHeadingStep(node) {
36
+ const head = node.children[0];
37
+ if (head && head.type === "text") {
38
+ const match = StepRegex.exec(head.value);
39
+ if (match) {
40
+ head.value = match[2];
41
+ return true;
42
+ }
43
+ }
44
+ const tail = node.children[node.children.length - 1];
45
+ if (tail && tail.type === "text") {
46
+ const step = handleTag(tail.value, StepTag);
47
+ if (step !== false) {
48
+ tail.value = step;
49
+ return true;
50
+ }
51
+ }
52
+ return false;
53
+ }
34
54
  return (tree) => {
35
55
  visit(tree, (parent) => {
36
- if (!("children" in parent) || parent.type === "heading") return;
37
- if (parent.data && "_fd_step" in parent.data) return "skip";
56
+ if (!("children" in parent) || parent.type === "heading") return "skip";
38
57
  let startIdx = -1;
39
58
  let i = 0;
59
+ let currentStep = 1;
40
60
  const onEnd = () => {
41
61
  if (startIdx === -1) return;
42
62
  const item = {};
@@ -44,26 +64,25 @@ function remarkSteps({ steps = "fd-steps", step = "fd-step" } = {}) {
44
64
  Object.assign(item, convertToSteps(nodes));
45
65
  i = startIdx + 1;
46
66
  startIdx = -1;
67
+ currentStep = 1;
47
68
  };
48
69
  for (; i < parent.children.length; i++) {
49
70
  const node = parent.children[i];
50
- if (node.type !== "heading") continue;
71
+ if (node.type !== "heading" || node.data?.hProperties?.["data-fd-step"] !== void 0) continue;
51
72
  if (startIdx !== -1) {
52
73
  const startDepth = parent.children[startIdx].depth;
53
- if (node.depth > startDepth) continue;
54
- else if (node.depth < startDepth) onEnd();
74
+ if (node.depth !== startDepth) {
75
+ if (node.depth < startDepth) onEnd();
76
+ continue;
77
+ }
55
78
  }
56
- const head = node.children.filter((c) => c.type === "text").at(0);
57
- if (!head) {
79
+ if (!handleHeadingStep(node)) {
58
80
  onEnd();
59
81
  continue;
60
82
  }
61
- const match = StepRegex.exec(head.value);
62
- if (!match) {
63
- onEnd();
64
- continue;
65
- }
66
- head.value = match[2];
83
+ node.data ??= {};
84
+ node.data.hProperties ??= {};
85
+ node.data.hProperties["data-fd-step"] = currentStep++;
67
86
  if (startIdx === -1) startIdx = i;
68
87
  }
69
88
  onEnd();
@@ -1,4 +1,4 @@
1
- import { n as toMdxExport } from "../mdast-utils-9tJwoVTq.js";
1
+ import { r as toMdxExport } from "../utils-C73VXFR0.js";
2
2
  import { remarkHeading } from "./remark-heading.js";
3
3
  import { defaultStringifier as defaultStringifier$1 } from "./stringifier.js";
4
4
  import { remark } from "remark";
@@ -37,6 +37,7 @@ interface RehypeTOCItemType {
37
37
  title: Element;
38
38
  url: string;
39
39
  depth: number;
40
+ _step?: number;
40
41
  }
41
42
  declare function rehypeToc(this: Processor, {
42
43
  exportToc
@@ -1,4 +1,4 @@
1
- import { c as TOCItemType } from "./toc-DjyooJ0-.js";
1
+ import { c as TOCItemType } from "./toc-Bw56X0rx.js";
2
2
  import { Transformer } from "unified";
3
3
  import { Heading, Root } from "mdast";
4
4
 
@@ -7,7 +7,7 @@ declare module 'mdast' {
7
7
  interface HeadingData extends Data {
8
8
  hProperties?: {
9
9
  id?: string;
10
- };
10
+ } & Record<string, unknown>;
11
11
  }
12
12
  }
13
13
  interface RemarkHeadingOptions {
@@ -6,6 +6,8 @@ interface TOCItemType {
6
6
  title: ReactNode;
7
7
  url: string;
8
8
  depth: number;
9
+ /** [remark-steps] the step number */
10
+ _step?: number;
9
11
  }
10
12
  type TableOfContents = TOCItemType[];
11
13
  interface TOCItemInfo {
package/dist/toc.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as TOCItem, c as TOCItemType, d as useActiveAnchors, f as useItems, i as ScrollProviderProps, l as TableOfContents, n as AnchorProviderProps, o as TOCItemInfo, r as ScrollProvider, s as TOCItemProps, t as AnchorProvider, u as useActiveAnchor } from "./toc-DjyooJ0-.js";
1
+ import { a as TOCItem, c as TOCItemType, d as useActiveAnchors, f as useItems, i as ScrollProviderProps, l as TableOfContents, n as AnchorProviderProps, o as TOCItemInfo, r as ScrollProvider, s as TOCItemProps, t as AnchorProvider, u as useActiveAnchor } from "./toc-Bw56X0rx.js";
2
2
  export { AnchorProvider, AnchorProviderProps, ScrollProvider, ScrollProviderProps, TOCItem, TOCItemInfo, TOCItemProps, TOCItemType, TableOfContents, useActiveAnchor, useActiveAnchors, useItems };
package/dist/toc.js CHANGED
@@ -51,10 +51,11 @@ function TOCItem({ ref, onActiveChange = () => null, ...props }) {
51
51
  const id = props.href ? getItemId(props.href) : null;
52
52
  const anchorRef = useRef(null);
53
53
  const [active, setActive] = useState(() => id && items.some((item) => item.active && item.id === id));
54
- const initialShouldScroll = useMemo(() => {
54
+ const initialShouldScrollRef = useRef(null);
55
+ if (initialShouldScrollRef.current === null) {
55
56
  const lastActive = items.findLast((item) => item.active);
56
- return lastActive && lastActive.id === id;
57
- }, []);
57
+ initialShouldScrollRef.current = lastActive !== void 0 && lastActive.id === id;
58
+ }
58
59
  useOnChange(items, () => {
59
60
  if (id === null) return;
60
61
  const currentItem = items.find((item) => item.id === id);
@@ -74,14 +75,14 @@ function TOCItem({ ref, onActiveChange = () => null, ...props }) {
74
75
  useEffect(() => {
75
76
  const anchor = anchorRef.current;
76
77
  const container = containerRef?.current;
77
- if (initialShouldScroll && container && anchor) scrollIntoView(anchor, {
78
+ if (initialShouldScrollRef.current && container && anchor) scrollIntoView(anchor, {
78
79
  behavior: "instant",
79
80
  block: "center",
80
81
  inline: "center",
81
82
  scrollMode: "always",
82
83
  boundary: container
83
84
  });
84
- }, [containerRef, initialShouldScroll]);
85
+ }, [containerRef]);
85
86
  return /* @__PURE__ */ jsx("a", {
86
87
  ref: mergeRefs(anchorRef, ref),
87
88
  "data-active": active,
@@ -1,5 +1,5 @@
1
1
  import { valueToEstree } from "estree-util-value-to-estree";
2
- //#region src/mdx-plugins/mdast-utils.ts
2
+ //#region src/mdx-plugins/utils.ts
3
3
  function flattenNode(node) {
4
4
  if ("children" in node) return node.children.map((child) => flattenNode(child)).join("");
5
5
  if ("value" in node && typeof node.value === "string") return node.value;
@@ -35,5 +35,10 @@ function toMdxExportRaw(name, expression) {
35
35
  } }
36
36
  };
37
37
  }
38
+ function handleTag(value, tag) {
39
+ const idx = value.indexOf(tag);
40
+ if (idx !== -1) return value.slice(0, idx).trimEnd() + value.slice(idx + tag.length);
41
+ return false;
42
+ }
38
43
  //#endregion
39
- export { toMdxExport as n, toMdxExportRaw as r, flattenNode as t };
44
+ export { toMdxExportRaw as i, handleTag as n, toMdxExport as r, flattenNode as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "16.7.6",
3
+ "version": "16.7.7",
4
4
  "description": "The React.js library for building a documentation website",
5
5
  "keywords": [
6
6
  "Docs",