Skip to content

Commit c44416b

Browse files
Merge pull request #3765 from opral/upgrade-to-rspress-v2
Upgrade-to-rspress-v2
2 parents 4f77420 + f9c138a commit c44416b

File tree

18 files changed

+1473
-480
lines changed

18 files changed

+1473
-480
lines changed

.changeset/bright-rspack-ignore.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@lix-js/sdk": patch
3+
---
4+
5+
Add webpack/rspack ignore hints to dynamic inline plugin imports and document usage with a JSDoc example.

packages/lix/docs/package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,23 @@
1717
"@lix-js/plugin-json": "workspace:*",
1818
"@lix-js/sdk": "workspace:*",
1919
"@monaco-editor/react": "^4.7.0",
20-
"@rspress/shared": "^1.44.0",
20+
"@rspress/core": "2.0.0-rc.1",
21+
"@rspress/plugin-llms": "2.0.0-rc.1",
22+
"@rspress/plugin-sitemap": "2.0.0-rc.1",
2123
"@tailwindcss/postcss": "^4.1.10",
24+
"@types/mdast": "^4.0.4",
2225
"@types/react": "^19.0.12",
2326
"@types/react-dom": "^19.0.4",
2427
"dayjs": "^1.11.11",
2528
"debug": "^4.3.4",
26-
"mermaid": "^11.7.0",
29+
"prettier": "^3.6.2",
2730
"react": "^19.1.0",
2831
"react-dom": "^19.1.0",
29-
"rspress": "^1.40.2",
30-
"rspress-plugin-mermaid": "^0.3.0",
31-
"prettier": "^3.6.2",
3232
"tailwindcss": "^4.1.11",
3333
"typedoc": "0.28.12",
3434
"typedoc-plugin-markdown": "4.7.0",
3535
"typescript": "5.8.3",
36+
"unist-util-visit": "^5.0.0",
3637
"vitest": "^3.2.4"
3738
},
3839
"keywords": [
@@ -46,6 +47,7 @@
4647
"author": "Opral, Inc.",
4748
"license": "MIT",
4849
"dependencies": {
50+
"mermaid": "^11.7.0",
4951
"shiki": "^3.7.0"
5052
}
5153
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import path from "node:path";
2+
import { visit } from "unist-util-visit";
3+
import type { Code, Parent } from "mdast";
4+
import type { RspressPlugin } from "@rspress/core";
5+
6+
type MdxJsxFlowElement = {
7+
type: "mdxJsxFlowElement";
8+
name: string;
9+
attributes: Array<{
10+
type: "mdxJsxAttribute";
11+
name: string;
12+
value: string;
13+
}>;
14+
children: [];
15+
data?: Record<string, unknown>;
16+
};
17+
18+
export const mermaidComponentPath = path.join(
19+
__dirname,
20+
"../src/docs/components/Mermaid.tsx",
21+
);
22+
23+
/**
24+
* Remark plugin that converts mermaid code fences into MDX components.
25+
*
26+
* @example
27+
* remarkMermaid();
28+
*/
29+
export const remarkMermaid = () => (tree: unknown) => {
30+
visit(tree, "code", (node: Code, index, parent) => {
31+
if (
32+
node.lang !== "mermaid" ||
33+
parent === null ||
34+
parent === undefined ||
35+
typeof index !== "number"
36+
) {
37+
return;
38+
}
39+
40+
const mermaidNode: MdxJsxFlowElement = {
41+
type: "mdxJsxFlowElement",
42+
name: "Mermaid",
43+
attributes: [
44+
{
45+
type: "mdxJsxAttribute",
46+
name: "code",
47+
value: node.value,
48+
},
49+
],
50+
children: [],
51+
data: {
52+
_mdxExplicitJsx: true,
53+
},
54+
};
55+
56+
(parent as Parent).children.splice(index, 1, mermaidNode);
57+
});
58+
};
59+
60+
/**
61+
* Transforms ```mermaid code fences into a Mermaid React component so diagrams render at runtime.
62+
*
63+
* @example
64+
* mermaidPlugin();
65+
*/
66+
export function mermaidPlugin(): RspressPlugin {
67+
return {
68+
name: "local-mermaid",
69+
markdown: {
70+
globalComponents: [mermaidComponentPath],
71+
remarkPlugins: [remarkMermaid],
72+
},
73+
};
74+
}

packages/lix/docs/rspress-plugins/sync-react-utils-readme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from "node:path";
22
import fs from "node:fs/promises";
3-
import type { RspressPlugin } from "@rspress/shared";
3+
import type { RspressPlugin } from "@rspress/core";
44

55
export function syncReactUtilsReadmePlugin(): RspressPlugin {
66
return {

packages/lix/docs/rspress-plugins/typedoc-plugin.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from "node:path";
22
import fs from "node:fs/promises";
33
import * as fsSync from "node:fs";
4-
import type { RspressPlugin } from "@rspress/shared";
4+
import type { RspressPlugin } from "@rspress/core";
55
import { Application, TypeDocOptions } from "typedoc";
66

77
export interface CustomTypeDocOptions {
@@ -25,7 +25,7 @@ async function patchLinks(outputDir: string) {
2525
(_match, p1, p2) => {
2626
if (
2727
// 2. [foo](./bar) -> [foo](./bar) no change
28-
["/", "."].includes(p2[0]) ||
28+
["/", ".", "#"].includes(p2[0]) ||
2929
// 3. [foo](http(s)://...) -> [foo](http(s)://...) no change
3030
p2.startsWith("http://") ||
3131
p2.startsWith("https://")
@@ -130,7 +130,7 @@ Welcome to the comprehensive Lix SDK API documentation. This reference provides
130130
131131
## Need Help?
132132
133-
If you're new to Lix, consider starting with our [Getting Started Guide](/docs/quick-start) before diving into the API reference.
133+
If you're new to Lix, consider starting with our [Getting Started Guide](/docs/getting-started) before diving into the API reference.
134134
135135
Browse the API documentation using the sidebar to find the specific functionality you need.`,
136136
);

packages/lix/docs/rspress.config.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import * as path from "node:path";
2-
import { defineConfig } from "rspress/config";
3-
import mermaid from "rspress-plugin-mermaid";
2+
import { defineConfig } from "@rspress/core";
3+
import { pluginLlms } from "@rspress/plugin-llms";
44
import { syncReactUtilsReadmePlugin } from "./rspress-plugins/sync-react-utils-readme";
55
import {
66
generateApiDocs,
77
generateApiSidebar,
88
} from "./rspress-plugins/typedoc-plugin";
9+
import {
10+
mermaidComponentPath,
11+
remarkMermaid,
12+
} from "./rspress-plugins/remark-mermaid";
13+
import { pluginSitemap } from "@rspress/plugin-sitemap";
914

1015
// Generate API docs before creating the config
1116
// We need to generate the API docs at the top level (before defineConfig) because
@@ -30,18 +35,33 @@ export default defineConfig({
3035
"Official documentation for the Lix SDK - a change control system that runs in the browser",
3136
icon: "/logo.svg",
3237
globalStyles: path.join(__dirname, "src/styles/index.css"),
38+
// Use the shared theme directory (not inside src) so custom MDX components load, including the LLM copy button.
39+
themeDir: path.join(__dirname, "theme"),
3340
route: {
3441
cleanUrls: true,
35-
exclude: ["**/*.test.ts", "**/*.test.tsx", "**/*.spec.ts", "**/*.spec.tsx"],
42+
exclude: [
43+
"**/*.test.ts",
44+
"**/*.test.tsx",
45+
"**/*.spec.ts",
46+
"**/*.spec.tsx",
47+
"**/examples/**/*.ts",
48+
"**/components/**/*.{ts,tsx}",
49+
],
3650
},
3751
markdown: {
3852
// Disable Rust MDX compiler to support global components
3953
mdxRs: false,
4054
globalComponents: [
4155
path.join(__dirname, "src/docs/components/InteractiveExampleCard.tsx"),
56+
mermaidComponentPath,
4257
],
58+
remarkPlugins: [remarkMermaid],
4359
},
4460
builderConfig: {
61+
dev: {
62+
// Disable lazy compilation to avoid giant dev proxy requests from Shiki/highlighter
63+
lazyCompilation: false,
64+
},
4565
tools: {
4666
rspack: {
4767
module: {
@@ -62,7 +82,13 @@ export default defineConfig({
6282
},
6383
},
6484
},
65-
plugins: [mermaid(), syncReactUtilsReadmePlugin()],
85+
plugins: [
86+
pluginLlms(),
87+
pluginSitemap({
88+
siteUrl: "https://lix.dev",
89+
}),
90+
syncReactUtilsReadmePlugin(),
91+
],
6692
themeConfig: {
6793
darkMode: false,
6894
nav: [
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { useEffect, useId, useRef, useState } from "react";
2+
import mermaid, { type MermaidConfig } from "mermaid";
3+
4+
interface MermaidProps {
5+
code: string;
6+
config?: MermaidConfig;
7+
}
8+
9+
let mermaidInitialized = false;
10+
let mermaidInitPromise: Promise<void> | null = null;
11+
12+
const ensureMermaidInitialized = () => {
13+
if (mermaidInitialized) return mermaidInitPromise as Promise<void>;
14+
15+
mermaidInitialized = true;
16+
mermaidInitPromise = Promise.resolve().then(() =>
17+
mermaid.initialize({ startOnLoad: false, securityLevel: "loose" })
18+
);
19+
20+
return mermaidInitPromise;
21+
};
22+
23+
/**
24+
* Renders a Mermaid diagram from fenced code blocks.
25+
*
26+
* @example
27+
* <Mermaid code="graph TD; A-->B;" />
28+
*/
29+
export default function Mermaid({ code, config }: MermaidProps) {
30+
const [svg, setSvg] = useState("");
31+
const [hasError, setHasError] = useState(false);
32+
const id = useId().replace(/:/g, "");
33+
const renderRequestRef = useRef(0);
34+
35+
useEffect(() => {
36+
ensureMermaidInitialized();
37+
}, []);
38+
39+
useEffect(() => {
40+
const theme = document.documentElement.classList.contains("dark")
41+
? "dark"
42+
: "default";
43+
44+
const mergedConfig: MermaidConfig = {
45+
startOnLoad: false,
46+
securityLevel: "loose",
47+
theme,
48+
...config,
49+
};
50+
51+
const definition = `%%{init: ${JSON.stringify(mergedConfig)}}%%\n${code}`;
52+
let isCancelled = false;
53+
const renderId = renderRequestRef.current + 1;
54+
renderRequestRef.current = renderId;
55+
56+
ensureMermaidInitialized()
57+
?.then(() => mermaid.render(id, definition))
58+
.then(({ svg }) => {
59+
if (isCancelled || renderId !== renderRequestRef.current) return;
60+
61+
setSvg(svg);
62+
setHasError(false);
63+
})
64+
.catch(() => {
65+
if (isCancelled || renderId !== renderRequestRef.current) return;
66+
67+
setHasError(true);
68+
});
69+
70+
return () => {
71+
isCancelled = true;
72+
};
73+
}, [code, config, id]);
74+
75+
if (hasError) {
76+
return null;
77+
}
78+
79+
return <div dangerouslySetInnerHTML={{ __html: svg }} />;
80+
}

packages/lix/docs/src/docs/components/landing-page.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,9 @@ function LandingPage() {
439439
</h1>
440440

441441
<p className="text-gray-600 text-base sm:text-xl max-w-3xl mx-auto leading-relaxed mt-12">
442-
Lix is a JavaScript SDK that enables Git-like capabilities for
443-
apps and agents:
444-
<br />
445-
Change proposals, versions (branches), history, blame, etc.
442+
Lix is a change control system that enables Git-like features for
443+
applications and AI agents such as change proposals, versions
444+
(branching), history, and blame.
446445
</p>
447446

448447
<div className="flex flex-col sm:flex-row items-center justify-center gap-4 mb-16 mt-8">

packages/lix/docs/src/docs/deterministic-mode.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ The following functions provide deterministic behavior when `lix_deterministic_m
187187

188188
| Function | Purpose | Docs |
189189
| ----------------------------- | -------------------------------- | ---------------------------------------------------------- |
190-
| `getTimestamp({ lix })` | Logical clock timestamps | [API docs](/api/functions/timestamp) |
191-
| `random({ lix })` | Reproducible random numbers | [API docs](/api/functions/random) |
192-
| `uuidV7({ lix })` | Deterministic UUID v7 generation | [API docs](/api/functions/uuidV7) |
193-
| `nanoId({ lix })` | Deterministic nano ID generation | [API docs](/api/functions/nanoId) |
194-
| `nextSequenceNumber({ lix })` | Monotonic counter (advanced) | [API docs](/api/functions/nextDeterministicSequenceNumber) |
190+
| `getTimestamp({ lix })` | Logical clock timestamps | [API docs](/docs/api/functions/getTimestamp) |
191+
| `random({ lix })` | Reproducible random numbers | [API docs](/docs/api/functions/random) |
192+
| `uuidV7({ lix })` | Deterministic UUID v7 generation | [API docs](/docs/api/functions/uuidV7) |
193+
| `nanoId({ lix })` | Deterministic nano ID generation | [API docs](/docs/api/functions/nanoId) |
194+
| `nextSequenceNumber({ lix })` | Monotonic counter (advanced) | [API docs](/docs/api/functions/nextSequenceNumber) |

packages/lix/docs/src/docs/metadata.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ In Lix, **metadata** refers to arbitrary, structured data that you can attach to
44

55
## When to Use Metadata
66

7-
The answer is simple: Use metadata when an [entity](./entity) is not owned by your application, but for interoperability reasons, you need to use that entity or its schema. In such cases, you can attach metadata to add your application's specific information without altering the original entity's schema.
7+
The answer is simple: Use metadata when an [entity](/docs/data-model#entities-meaningful-units-of-data) is not owned by your application, but for interoperability reasons, you need to use that entity or its schema. In such cases, you can attach metadata to add your application's specific information without altering the original entity's schema.
88

99
Here are some examples:
1010

0 commit comments

Comments
 (0)