@vite-hub/docs 0.4.1 → 0.5.0
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.
- package/README.md +164 -6
- package/dist/{assistant-pages-BN7hNsSZ.js → assistant-pages-CqNlHsx-.js} +1 -1
- package/dist/{assistant-shared-WzButktj.js → assistant-shared-DhiLHKSl.js} +2 -2
- package/dist/assistant-worker.js +1 -1
- package/dist/assistant.js +1 -1
- package/dist/{content-CPZGnn3S.js → content-BQVlMshL.js} +55 -15
- package/dist/{draft-BjWmaiLn.js → draft-CSsTYSeb.js} +2 -2
- package/dist/{error-diagnostics-B_ZOy7kF.js → error-diagnostics-CmgtG9xa.js} +64 -0
- package/dist/index.d.ts +7 -6
- package/dist/index.js +4 -4
- package/dist/link-checker-redirects.js +1 -1
- package/dist/{manifest-CMoxcwPm.d.ts → manifest-Drbdw1us.d.ts} +1 -1
- package/dist/{manifest-ZdxLrcvt.js → manifest-DvECmwX-.js} +62 -26
- package/dist/{markdown-DUWnEMPp.js → markdown-1M1FbjCw.js} +1 -1
- package/dist/{page-Dx2JD3y1.d.ts → markdown-BiKrT08O.d.ts} +2 -25
- package/dist/navigation.d.ts +9 -3
- package/dist/navigation.js +22 -8
- package/dist/{nuxt-CAGpKl_-.d.ts → nuxt-8O2OB_hI.d.ts} +80 -4
- package/dist/nuxt.d.ts +2 -2
- package/dist/nuxt.js +1269 -58
- package/dist/{page-GPt09oex.js → page-Bb0TfRKi.js} +19 -3
- package/dist/page-BryUCmYf.d.ts +26 -0
- package/dist/primitive-rail.d.ts +1 -4
- package/dist/primitive-rail.js +1 -4
- package/dist/{redirects-CmR1yu5A.js → redirects-BJj58IsY.js} +34 -21
- package/dist/runnable.d.ts +37 -0
- package/dist/runnable.js +105 -0
- package/dist/runtime/app/components/DocsAsideLeftBody.vue +2 -8
- package/dist/runtime/app/components/DocsLearn.vue +215 -0
- package/dist/runtime/app/components/DocsLearnCodePre.vue +98 -0
- package/dist/runtime/app/components/DocsLearnFile.vue +21 -0
- package/dist/runtime/app/components/DocsPage.vue +11 -5
- package/dist/runtime/app/components/DocsPlayground.vue +117 -0
- package/dist/runtime/app/components/content/Example.vue +18 -49
- package/dist/runtime/app/components/content/PageList.vue +1 -5
- package/dist/runtime/app/layouts/docs.vue +36 -8
- package/dist/runtime/app/middleware/docs-layout.ts +2 -2
- package/dist/runtime/app/utils/docs-learn.ts +31 -0
- package/dist/runtime/app/utils/docs-playground.ts +3 -0
- package/dist/runtime/server/llms.js +1 -1
- package/dist/runtime/server/markdown.d.ts +0 -5
- package/dist/runtime/server/markdown.js +10 -1
- package/dist/runtime/server/mcp.js +1 -1
- package/dist/runtime/server/page.d.ts +1 -1
- package/dist/runtime/server/page.js +3 -3
- package/dist/runtime/server/raw.js +2 -9
- package/dist/runtime/server/search.d.ts +1 -1
- package/dist/runtime/server/search.js +3 -2
- package/dist/runtime/server/sitemap.js +1 -1
- package/dist/{schema-DwpXW0VZ.js → schema-DcWZ3Q3M.js} +97 -5
- package/dist/server.d.ts +3 -2
- package/dist/server.js +3 -3
- package/dist/snapshot-worker.mjs +40 -0
- package/dist/steps-DBlkJwtD.d.ts +105 -0
- package/dist/steps-DF-11dJn.js +32 -0
- package/dist/{types-BhG6vGfG.d.ts → types-CHU_fy9l.d.ts} +69 -4
- package/package.json +17 -10
|
@@ -3,13 +3,23 @@ import { z } from "zod";
|
|
|
3
3
|
/**
|
|
4
4
|
* How a page renders. `article` is prose with an outline, `tutorial` numbers its steps, `landing` is a wide Overview,
|
|
5
5
|
* and `home` is the page's own blocks at full width under the site header, without the docs sidebar, such as a
|
|
6
|
-
* product home page.
|
|
6
|
+
* product home page. `playground` and `learn` fill the page with a code workspace: `playground` opens the apps of
|
|
7
|
+
* `examples`, and `learn` runs the `::tutorial-step` blocks of a lesson on its `fixture`.
|
|
7
8
|
*/
|
|
8
9
|
const docsLayouts = [
|
|
9
10
|
"article",
|
|
10
11
|
"tutorial",
|
|
11
12
|
"landing",
|
|
12
|
-
"home"
|
|
13
|
+
"home",
|
|
14
|
+
"playground",
|
|
15
|
+
"learn"
|
|
16
|
+
];
|
|
17
|
+
const connectProviders = [
|
|
18
|
+
"anthropic",
|
|
19
|
+
"github",
|
|
20
|
+
"netlify",
|
|
21
|
+
"openai",
|
|
22
|
+
"vercel"
|
|
13
23
|
];
|
|
14
24
|
const navigationFields = {
|
|
15
25
|
title: z.string().optional(),
|
|
@@ -24,6 +34,16 @@ const seoFields = {
|
|
|
24
34
|
image: z.union([z.string(), z.literal(false)]).optional(),
|
|
25
35
|
index: z.boolean().optional()
|
|
26
36
|
};
|
|
37
|
+
const exampleFields = {
|
|
38
|
+
id: z.string().regex(/^[\w-]+$/, "Use letters, digits, `-`, or `_`"),
|
|
39
|
+
label: z.string(),
|
|
40
|
+
group: z.string().optional(),
|
|
41
|
+
description: z.string().optional(),
|
|
42
|
+
dir: z.string(),
|
|
43
|
+
open: z.string().optional(),
|
|
44
|
+
preview: z.string().startsWith("/").optional(),
|
|
45
|
+
readonly: z.array(z.string()).optional()
|
|
46
|
+
};
|
|
27
47
|
const pageFields = {
|
|
28
48
|
title: z.string(),
|
|
29
49
|
description: z.string().optional(),
|
|
@@ -38,8 +58,77 @@ const pageFields = {
|
|
|
38
58
|
sidebar: z.union([z.boolean(), z.literal("collapsed")]).optional(),
|
|
39
59
|
toc: z.boolean().optional(),
|
|
40
60
|
navigation: z.union([z.literal(false), z.strictObject(navigationFields)]).optional(),
|
|
41
|
-
seo: z.strictObject(seoFields).optional()
|
|
61
|
+
seo: z.strictObject(seoFields).optional(),
|
|
62
|
+
examples: z.array(z.strictObject(exampleFields)).optional(),
|
|
63
|
+
tabs: z.array(z.strictObject({
|
|
64
|
+
value: z.string().regex(/^[a-z][\w-]*$/i, "Use letters, digits, `-`, or `_`, starting with a letter"),
|
|
65
|
+
label: z.string()
|
|
66
|
+
})).optional(),
|
|
67
|
+
render: z.string().optional(),
|
|
68
|
+
connect: z.array(z.enum(connectProviders)).min(1).optional(),
|
|
69
|
+
port: z.number().int().min(1).max(65535).optional(),
|
|
70
|
+
fixture: z.string().optional(),
|
|
71
|
+
guide: z.enum(["top", "side"]).optional(),
|
|
72
|
+
lesson: z.string().startsWith("/").optional(),
|
|
73
|
+
preview: z.string().startsWith("/").optional()
|
|
74
|
+
};
|
|
75
|
+
const layoutFields = {
|
|
76
|
+
examples: ["playground"],
|
|
77
|
+
tabs: ["playground"],
|
|
78
|
+
render: ["playground"],
|
|
79
|
+
connect: ["playground"],
|
|
80
|
+
port: ["playground", "learn"],
|
|
81
|
+
fixture: ["learn"],
|
|
82
|
+
guide: ["learn"],
|
|
83
|
+
lesson: ["learn"],
|
|
84
|
+
preview: ["learn"]
|
|
42
85
|
};
|
|
86
|
+
function checkLayoutFields(page, context) {
|
|
87
|
+
const layout = page.layout ?? "article";
|
|
88
|
+
for (const [field, layouts] of Object.entries(layoutFields)) {
|
|
89
|
+
if (page[field] === void 0 || layouts.includes(layout)) continue;
|
|
90
|
+
context.addIssue({
|
|
91
|
+
code: "custom",
|
|
92
|
+
path: [field],
|
|
93
|
+
message: `Only a page with \`layout: ${layouts.join("` or `layout: ")}\` reads \`${field}\``
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
if (layout === "playground") {
|
|
97
|
+
if (!page.examples?.length) context.addIssue({
|
|
98
|
+
code: "custom",
|
|
99
|
+
path: ["examples"],
|
|
100
|
+
message: "A playground page needs at least one example"
|
|
101
|
+
});
|
|
102
|
+
const ids = /* @__PURE__ */ new Set();
|
|
103
|
+
for (const [index, example] of (page.examples ?? []).entries()) {
|
|
104
|
+
if (ids.has(example.id)) context.addIssue({
|
|
105
|
+
code: "custom",
|
|
106
|
+
path: [
|
|
107
|
+
"examples",
|
|
108
|
+
index,
|
|
109
|
+
"id"
|
|
110
|
+
],
|
|
111
|
+
message: `Two examples have the id \`${example.id}\``
|
|
112
|
+
});
|
|
113
|
+
ids.add(example.id);
|
|
114
|
+
}
|
|
115
|
+
if (page.render !== void 0 && page.port !== void 0) context.addIssue({
|
|
116
|
+
code: "custom",
|
|
117
|
+
path: ["port"],
|
|
118
|
+
message: "A `render` page runs in the browser page and has no dev server port"
|
|
119
|
+
});
|
|
120
|
+
if (page.render !== void 0 && page.connect !== void 0) context.addIssue({
|
|
121
|
+
code: "custom",
|
|
122
|
+
path: ["connect"],
|
|
123
|
+
message: "A `render` page runs no app, so it has no accounts to connect"
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
if (layout === "learn" && page.fixture === void 0) context.addIssue({
|
|
127
|
+
code: "custom",
|
|
128
|
+
path: ["fixture"],
|
|
129
|
+
message: "A learn page needs the `fixture` folder of its app"
|
|
130
|
+
});
|
|
131
|
+
}
|
|
43
132
|
/**
|
|
44
133
|
* Frontmatter fields of a docs page as files store them, one Standard Schema per field. `docsCollection()` passes them
|
|
45
134
|
* to `documents()`, so the Console editor validates the same values that the build validates, and a save writes
|
|
@@ -57,8 +146,11 @@ const docsPageFields = {
|
|
|
57
146
|
"seo.image": seoFields.image,
|
|
58
147
|
"seo.index": seoFields.index
|
|
59
148
|
};
|
|
60
|
-
/**
|
|
61
|
-
|
|
149
|
+
/**
|
|
150
|
+
* The build validates frontmatter with this schema after `docsFrontmatter()` expanded its dotted keys. It also checks
|
|
151
|
+
* that the workspace fields sit on the layouts that read them.
|
|
152
|
+
*/
|
|
153
|
+
const docsPageSchema = z.strictObject(pageFields).superRefine(checkLayoutFields);
|
|
62
154
|
const docsSectionSchema = z.strictObject({
|
|
63
155
|
title: z.string().optional(),
|
|
64
156
|
icon: z.string().optional(),
|
package/dist/server.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import {
|
|
1
|
+
import { a as docsSearchSections, i as docsMarkdown, n as DocsParserOptions, r as createDocsParser, t as DocsDocument } from "./markdown-BiKrT08O.js";
|
|
2
|
+
import { n as DocsPageResponse, r as docsPageResponse, t as DocsPageLink } from "./page-BryUCmYf.js";
|
|
3
|
+
import { a as createDocsContent, c as checkDocsLinks, i as DocsSourceInput, n as DocsManifestOptions, o as createDocsManifest, r as DocsSource, s as DocsLinkCheckOptions, t as DocsContentSource } from "./manifest-Drbdw1us.js";
|
|
3
4
|
//#region src/raw.d.ts
|
|
4
5
|
type RawMarkdownOptions = {
|
|
5
6
|
/** Origin that site-relative links point to, such as `https://vitehub.dev`. Empty keeps them relative. */
|
package/dist/server.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as docsPageResponse } from "./page-
|
|
2
|
-
import { l as checkDocsLinks, n as createDocsContent, r as createDocsManifest } from "./manifest-
|
|
1
|
+
import { i as docsPageResponse } from "./page-Bb0TfRKi.js";
|
|
2
|
+
import { l as checkDocsLinks, n as createDocsContent, r as createDocsManifest } from "./manifest-DvECmwX-.js";
|
|
3
3
|
import { t as toRawMarkdown } from "./raw-BChwipz_.js";
|
|
4
|
-
import { a as docsSearchSections, i as docsMarkdown, t as createDocsParser } from "./markdown-
|
|
4
|
+
import { a as docsSearchSections, i as docsMarkdown, t as createDocsParser } from "./markdown-1M1FbjCw.js";
|
|
5
5
|
export { checkDocsLinks, createDocsContent, createDocsManifest, createDocsParser, docsMarkdown, docsPageResponse, docsSearchSections, toRawMarkdown };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Runs in its own Node process, so the snapshot (hundreds of MiB in memory) does not share the heap of the docs build.
|
|
2
|
+
// node snapshot-worker.mjs <app dir> <out dir> <file prefix> <lockfile>
|
|
3
|
+
// Prints the written file names as JSON, with the SHA-256 of the joined parts and the sizes.
|
|
4
|
+
import { createHash } from "node:crypto"
|
|
5
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises"
|
|
6
|
+
import { dirname, resolve } from "node:path"
|
|
7
|
+
import { createNodeModulesSnapshot, packSnapshot } from "@vite-hub/web-container/snapshot"
|
|
8
|
+
|
|
9
|
+
const [dir, outDir, prefix, lockPath] = process.argv.slice(2)
|
|
10
|
+
// The lockfile pins every version, so two builds of one commit give the same bytes.
|
|
11
|
+
const lockfile = await readFile(lockPath, "utf8").catch((error) => {
|
|
12
|
+
if (error.code === "ENOENT") return undefined
|
|
13
|
+
throw error
|
|
14
|
+
})
|
|
15
|
+
let result
|
|
16
|
+
try {
|
|
17
|
+
result = await createNodeModulesSnapshot({ dir, lockfile })
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
if (lockfile === undefined || error?.code !== "WEB_CONTAINER_SNAPSHOT_LOCKFILE_MISMATCH") throw error
|
|
21
|
+
// The dependencies changed since the lockfile was written. Update it, keeping the versions that still fit.
|
|
22
|
+
console.warn(`[docs] ${lockPath} does not match the dependencies (${error.message.split("\n")[0]}). Updating it; commit the change.`)
|
|
23
|
+
result = await createNodeModulesSnapshot({ dir, lockfile, frozenLockfile: false })
|
|
24
|
+
}
|
|
25
|
+
if (result.lockfile !== lockfile) {
|
|
26
|
+
await mkdir(dirname(lockPath), { recursive: true })
|
|
27
|
+
await writeFile(lockPath, result.lockfile)
|
|
28
|
+
console.warn(`[docs] Wrote ${lockPath}. Commit it, so the next build installs the same versions.`)
|
|
29
|
+
}
|
|
30
|
+
const parts = packSnapshot(result.snapshot)
|
|
31
|
+
const hash = createHash("sha256")
|
|
32
|
+
for (const part of parts) hash.update(part)
|
|
33
|
+
const sha256 = hash.digest("hex")
|
|
34
|
+
const files = []
|
|
35
|
+
for (const [index, part] of parts.entries()) {
|
|
36
|
+
const file = `${prefix}.${sha256.slice(0, 12)}.${index}.bin`
|
|
37
|
+
await writeFile(resolve(outDir, file), part)
|
|
38
|
+
files.push(file)
|
|
39
|
+
}
|
|
40
|
+
console.log(JSON.stringify({ files, sha256, bytes: result.snapshot.byteLength, compressed: parts.reduce((total, part) => total + part.byteLength, 0) }))
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { c as DocsConnectProvider } from "./types-CHU_fy9l.js";
|
|
2
|
+
import { WorkspaceRenderContext, WorkspaceRenderResult } from "@vite-hub/ui/workspace";
|
|
3
|
+
import { Component } from "vue";
|
|
4
|
+
//#region src/runnable/steps.d.ts
|
|
5
|
+
/** Text files of an app, keyed by a relative path such as `server/api/greet.post.ts`. */
|
|
6
|
+
type TutorialFiles = Record<string, string>;
|
|
7
|
+
/** Binary files of an app, such as model weights, keyed by a relative path. */
|
|
8
|
+
type TutorialAssets = Record<string, Uint8Array>;
|
|
9
|
+
interface RunnableTutorialStep {
|
|
10
|
+
/** The `::tutorial-step` title. */
|
|
11
|
+
title: string;
|
|
12
|
+
/** The files that this step writes, with their final contents from the fixture. */
|
|
13
|
+
files: TutorialFiles;
|
|
14
|
+
}
|
|
15
|
+
/** What the workspace of one tutorial mounts, built from its lesson page and its fixture. */
|
|
16
|
+
interface RunnableTutorialData {
|
|
17
|
+
slug: string;
|
|
18
|
+
/** The docs page that holds the lesson prose. */
|
|
19
|
+
page: string;
|
|
20
|
+
title: string;
|
|
21
|
+
description: string;
|
|
22
|
+
/** The files before step 1: the fixture without the files that the steps write, with the fixture's dependencies. */
|
|
23
|
+
files: TutorialFiles;
|
|
24
|
+
steps: RunnableTutorialStep[];
|
|
25
|
+
/** The parts of the `node_modules` snapshot and their SHA-256, for `fetchSnapshot()`. Without it, the workspace runs `npm install`. */
|
|
26
|
+
snapshot?: {
|
|
27
|
+
parts: string[];
|
|
28
|
+
sha256: string;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** A starting app of `/playground`, read from a fixture. */
|
|
32
|
+
interface PlaygroundTemplate {
|
|
33
|
+
id: string;
|
|
34
|
+
label: string;
|
|
35
|
+
description?: string;
|
|
36
|
+
/** The heading of the example in the examples menu. */
|
|
37
|
+
group?: string;
|
|
38
|
+
/** The file that the editor opens first. */
|
|
39
|
+
open?: string;
|
|
40
|
+
/** The path that the preview opens when the dev server is ready. */
|
|
41
|
+
preview?: string;
|
|
42
|
+
/** The paths of `files` that the editor does not let the reader change. */
|
|
43
|
+
readonly?: string[];
|
|
44
|
+
files: TutorialFiles;
|
|
45
|
+
/**
|
|
46
|
+
* The files that are not valid UTF-8, such as model weights. The page module of a `playground` page carries them.
|
|
47
|
+
* `#build/playground-templates.mjs` leaves them out.
|
|
48
|
+
*/
|
|
49
|
+
assets?: TutorialAssets;
|
|
50
|
+
/** The slug of the snapshot that this template mounts. Templates with the same dependencies share one. */
|
|
51
|
+
snapshotOf: string;
|
|
52
|
+
/** The parts of that snapshot and their SHA-256, for `fetchSnapshot()`. Without it, the workspace runs `npm install`. */
|
|
53
|
+
snapshot?: RunnableTutorialData["snapshot"];
|
|
54
|
+
}
|
|
55
|
+
/** An example of a `playground` page. Examples with the same `snapshotOf` mount one snapshot. A `render` page has none. */
|
|
56
|
+
type DocsPlaygroundExampleData = Omit<PlaygroundTemplate, "snapshotOf"> & {
|
|
57
|
+
snapshotOf?: string;
|
|
58
|
+
};
|
|
59
|
+
/** What the page module of a `playground` page holds, besides its loaders. */
|
|
60
|
+
interface DocsPlaygroundData {
|
|
61
|
+
layout: "playground";
|
|
62
|
+
examples: DocsPlaygroundExampleData[];
|
|
63
|
+
/** Without `render`: the port of the dev server. */
|
|
64
|
+
port: number;
|
|
65
|
+
/** Without `render`: the accounts that the reader can connect. */
|
|
66
|
+
connect?: DocsConnectProvider[];
|
|
67
|
+
}
|
|
68
|
+
/** What the page module of a `learn` page holds. */
|
|
69
|
+
interface DocsLearnData {
|
|
70
|
+
layout: "learn";
|
|
71
|
+
tutorial: RunnableTutorialData;
|
|
72
|
+
guide: "top" | "side";
|
|
73
|
+
port: number;
|
|
74
|
+
preview?: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The default export of the `render` module of a `layout: playground` page. It gets the text files, and the open
|
|
78
|
+
* example with its binary files in `example.assets`.
|
|
79
|
+
*/
|
|
80
|
+
type DocsRenderFunction = (files: TutorialFiles, context: WorkspaceRenderContext) => WorkspaceRenderResult | Promise<WorkspaceRenderResult>;
|
|
81
|
+
/** An output tab of a `layout: playground` page, with the component that draws it. */
|
|
82
|
+
interface DocsWorkspaceTab {
|
|
83
|
+
value: string;
|
|
84
|
+
label: string;
|
|
85
|
+
component: () => Promise<{
|
|
86
|
+
default: Component;
|
|
87
|
+
}>;
|
|
88
|
+
}
|
|
89
|
+
/** The workspace of a `playground` or `learn` page, as `#build/docs/workspaces.mjs` loads it by page path. */
|
|
90
|
+
type DocsWorkspaceData = (DocsPlaygroundData & {
|
|
91
|
+
render?: () => Promise<{
|
|
92
|
+
default: DocsRenderFunction;
|
|
93
|
+
}>;
|
|
94
|
+
tabs?: DocsWorkspaceTab[];
|
|
95
|
+
}) | DocsLearnData;
|
|
96
|
+
/** The files at the start of step `index` (from 0), or at its end with `solution`. Each step builds on the one before. */
|
|
97
|
+
declare function tutorialStepFiles(tutorial: Pick<RunnableTutorialData, "files" | "steps">, index: number, state: "start" | "solution"): TutorialFiles;
|
|
98
|
+
/** Loads a lesson state, removing absent tutorial files while keeping unrelated reader additions. */
|
|
99
|
+
declare function tutorialWorkspaceFiles(tutorial: Pick<RunnableTutorialData, "files" | "steps">, current: TutorialFiles, target: TutorialFiles): TutorialFiles;
|
|
100
|
+
/** Whether going from `before` to `after` adds or removes a file that the dev server reads only when its process starts. */
|
|
101
|
+
declare function restartsDevServer(before: TutorialFiles, after: TutorialFiles): boolean;
|
|
102
|
+
/** The `dependencies` of a `package.json`, sorted, so two apps with the same install compare equal. Invalid JSON has its own key. */
|
|
103
|
+
declare function dependencyKey(packageJson: string | undefined): string;
|
|
104
|
+
//#endregion
|
|
105
|
+
export { DocsWorkspaceData as a, RunnableTutorialData as c, dependencyKey as d, restartsDevServer as f, DocsRenderFunction as i, RunnableTutorialStep as l, tutorialWorkspaceFiles as m, DocsPlaygroundData as n, DocsWorkspaceTab as o, tutorialStepFiles as p, DocsPlaygroundExampleData as r, PlaygroundTemplate as s, DocsLearnData as t, TutorialFiles as u };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//#region src/runnable/steps.ts
|
|
2
|
+
/** The files at the start of step `index` (from 0), or at its end with `solution`. Each step builds on the one before. */
|
|
3
|
+
function tutorialStepFiles(tutorial, index, state) {
|
|
4
|
+
const last = state === "solution" ? index : index - 1;
|
|
5
|
+
const files = { ...tutorial.files };
|
|
6
|
+
for (let step = 0; step <= last && step < tutorial.steps.length; step++) Object.assign(files, tutorial.steps[step].files);
|
|
7
|
+
return files;
|
|
8
|
+
}
|
|
9
|
+
/** Loads a lesson state, removing absent tutorial files while keeping unrelated reader additions. */
|
|
10
|
+
function tutorialWorkspaceFiles(tutorial, current, target) {
|
|
11
|
+
const owned = /* @__PURE__ */ new Set([...Object.keys(tutorial.files), ...tutorial.steps.flatMap((step) => Object.keys(step.files))]);
|
|
12
|
+
const next = { ...current };
|
|
13
|
+
for (const path of owned) if (!(path in target)) delete next[path];
|
|
14
|
+
return Object.assign(next, target);
|
|
15
|
+
}
|
|
16
|
+
const startFiles = ["index.html"];
|
|
17
|
+
/** Whether going from `before` to `after` adds or removes a file that the dev server reads only when its process starts. */
|
|
18
|
+
function restartsDevServer(before, after) {
|
|
19
|
+
return startFiles.some((path) => path in before !== path in after);
|
|
20
|
+
}
|
|
21
|
+
/** The `dependencies` of a `package.json`, sorted, so two apps with the same install compare equal. Invalid JSON has its own key. */
|
|
22
|
+
function dependencyKey(packageJson) {
|
|
23
|
+
try {
|
|
24
|
+
const dependencies = packageJson ? JSON.parse(packageJson).dependencies : void 0;
|
|
25
|
+
const entries = dependencies && typeof dependencies === "object" ? Object.entries(dependencies) : [];
|
|
26
|
+
return JSON.stringify(entries.sort(([a], [b]) => a.localeCompare(b)));
|
|
27
|
+
} catch {
|
|
28
|
+
return "invalid";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { tutorialWorkspaceFiles as i, restartsDevServer as n, tutorialStepFiles as r, dependencyKey as t };
|
|
@@ -1,12 +1,43 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { ConnectProviderName } from "@vite-hub/web-container/connect";
|
|
2
3
|
//#region src/schema.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* How a page renders. `article` is prose with an outline, `tutorial` numbers its steps, `landing` is a wide Overview,
|
|
5
6
|
* and `home` is the page's own blocks at full width under the site header, without the docs sidebar, such as a
|
|
6
|
-
* product home page.
|
|
7
|
+
* product home page. `playground` and `learn` fill the page with a code workspace: `playground` opens the apps of
|
|
8
|
+
* `examples`, and `learn` runs the `::tutorial-step` blocks of a lesson on its `fixture`.
|
|
7
9
|
*/
|
|
8
|
-
declare const docsLayouts: readonly ["article", "tutorial", "landing", "home"];
|
|
10
|
+
declare const docsLayouts: readonly ["article", "tutorial", "landing", "home", "playground", "learn"];
|
|
9
11
|
type DocsLayout = (typeof docsLayouts)[number];
|
|
12
|
+
/** An app of a `layout: playground` page. */
|
|
13
|
+
interface DocsPlaygroundExample {
|
|
14
|
+
/** The `?example=` value and the id in share links. */
|
|
15
|
+
id: string;
|
|
16
|
+
label: string;
|
|
17
|
+
/** The heading of the example in the examples menu. */
|
|
18
|
+
group?: string;
|
|
19
|
+
/** One line under the label in the examples menu and on the start screen. */
|
|
20
|
+
description?: string;
|
|
21
|
+
/** The folder of the app, relative to the app root, such as `examples/hello`. */
|
|
22
|
+
dir: string;
|
|
23
|
+
/** The file that the editor opens first. Defaults to the first file. */
|
|
24
|
+
open?: string;
|
|
25
|
+
/** The path that the preview opens when the dev server is ready. Defaults to `/`. */
|
|
26
|
+
preview?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Text files of `dir` that the editor does not let the reader change, such as `["model.ts"]`. Code can still change
|
|
29
|
+
* them. A path that is not a text file of `dir` fails the build with `DOCS_WORKSPACE_READONLY_MISSING`.
|
|
30
|
+
*/
|
|
31
|
+
readonly?: string[];
|
|
32
|
+
}
|
|
33
|
+
/** An output tab of a `layout: playground` page. */
|
|
34
|
+
interface DocsPlaygroundTab {
|
|
35
|
+
/** Names the component that draws the tab: `messages` is `app/components/playground/PlaygroundTabMessages.vue`. */
|
|
36
|
+
value: string;
|
|
37
|
+
label: string;
|
|
38
|
+
}
|
|
39
|
+
/** An account that a playground page can connect: each one takes a token in its Connect tab. */
|
|
40
|
+
type DocsConnectProvider = Exclude<ConnectProviderName, "cloudflare">;
|
|
10
41
|
/** Navigation fields of a page. `false` keeps the page out of the sidebar. */
|
|
11
42
|
type DocsPageNavigation = false | {
|
|
12
43
|
/** Label in the sidebar. Defaults to the page title. */
|
|
@@ -49,6 +80,33 @@ interface DocsPageFrontmatter {
|
|
|
49
80
|
/** `false` hides the "On this page" outline. */
|
|
50
81
|
toc?: boolean;
|
|
51
82
|
navigation?: DocsPageNavigation;
|
|
83
|
+
/** `layout: playground` only. The apps that the workspace opens, in menu order. */
|
|
84
|
+
examples?: DocsPlaygroundExample[];
|
|
85
|
+
/** `layout: playground` only. More output tabs after the tabs of the runner. */
|
|
86
|
+
tabs?: DocsPlaygroundTab[];
|
|
87
|
+
/**
|
|
88
|
+
* `layout: playground` only. A module, relative to the app root, such as `app/playground/render.ts`, whose default
|
|
89
|
+
* export renders the files to HTML in the page. Without it, the examples run in a WebContainer.
|
|
90
|
+
*/
|
|
91
|
+
render?: string;
|
|
92
|
+
/**
|
|
93
|
+
* `layout: playground` without `render`. The accounts that the reader can connect in a Connect tab, such as
|
|
94
|
+
* `[github, vercel]`. A credential stays in the browser tab and reaches the app as an environment variable.
|
|
95
|
+
*/
|
|
96
|
+
connect?: DocsConnectProvider[];
|
|
97
|
+
/** `playground` and `learn` without `render`. The port of the dev server of the app. Defaults to `3000`. */
|
|
98
|
+
port?: number;
|
|
99
|
+
/** `layout: learn` only. The folder of the app after the last step, in the `docs.runnable.fixtures` folder. */
|
|
100
|
+
fixture?: string;
|
|
101
|
+
/** `layout: learn` only. Where the step text goes: `side` in a column beside the code (the default), or `top` over it. */
|
|
102
|
+
guide?: "top" | "side";
|
|
103
|
+
/**
|
|
104
|
+
* `layout: learn` only. The URL of the docs page whose `::tutorial-step` blocks are the steps, such as
|
|
105
|
+
* `/docs/getting-started/first-agent`. Defaults to this page, so the steps can live in the page itself.
|
|
106
|
+
*/
|
|
107
|
+
lesson?: string;
|
|
108
|
+
/** `layout: learn` only. The path that the preview opens when the dev server is ready. Defaults to `/`. */
|
|
109
|
+
preview?: string;
|
|
52
110
|
/**
|
|
53
111
|
* Search and share fields, when they differ from the page's own. `image` is the share image: a path in `public/` or a
|
|
54
112
|
* URL, or `false` for none. Without it the build renders one from the title and description. `index: false` asks
|
|
@@ -98,13 +156,18 @@ type Fields<T> = { [K in keyof T]-?: z.ZodType<T[K]>; };
|
|
|
98
156
|
* dotted keys back as dotted keys.
|
|
99
157
|
*/
|
|
100
158
|
declare const docsPageFields: Fields<DocsPageFile>;
|
|
101
|
-
/**
|
|
159
|
+
/**
|
|
160
|
+
* The build validates frontmatter with this schema after `docsFrontmatter()` expanded its dotted keys. It also checks
|
|
161
|
+
* that the workspace fields sit on the layouts that read them.
|
|
162
|
+
*/
|
|
102
163
|
declare const docsPageSchema: z.ZodType<DocsPageFrontmatter>;
|
|
103
164
|
declare const docsSectionSchema: z.ZodType<DocsSectionFile>;
|
|
104
165
|
/** YAML keys such as `navigation.order: 2` become nested objects, as Markdown frontmatter writers expect. */
|
|
105
166
|
declare function expandDottedKeys(input: Record<string, unknown>): Record<string, unknown>;
|
|
106
167
|
//#endregion
|
|
107
168
|
//#region src/types.d.ts
|
|
169
|
+
/** The workspace fields of a `layout: playground` or `layout: learn` page, as its frontmatter sets them. */
|
|
170
|
+
type DocsPageWorkspace = Pick<DocsPageFrontmatter, "examples" | "tabs" | "render" | "connect" | "port" | "fixture" | "guide" | "lesson" | "preview">;
|
|
108
171
|
/**
|
|
109
172
|
* The fields of a page that the app reads. `useDocsManifest()` returns pages with only these fields, so every page of
|
|
110
173
|
* the site does not carry the text and SEO options of every other page. The page route returns the whole `DocsPage`.
|
|
@@ -161,6 +224,8 @@ interface DocsPage extends DocsAppPage {
|
|
|
161
224
|
image?: string | false;
|
|
162
225
|
index?: boolean;
|
|
163
226
|
};
|
|
227
|
+
/** On a `playground` or `learn` page: the fields that set up its workspace. */
|
|
228
|
+
workspace?: DocsPageWorkspace;
|
|
164
229
|
}
|
|
165
230
|
/** A folder under the docs base: one rail entry with its own page list. */
|
|
166
231
|
interface DocsSection<Page extends DocsAppPage = DocsPage> {
|
|
@@ -209,4 +274,4 @@ interface DocsSearchSection {
|
|
|
209
274
|
indexed?: false;
|
|
210
275
|
}
|
|
211
276
|
//#endregion
|
|
212
|
-
export {
|
|
277
|
+
export { docsPageFields as _, DocsSearchSection as a, expandDottedKeys as b, DocsConnectProvider as c, DocsPageFrontmatter as d, DocsPageNavigation as f, docsLayouts as g, DocsSectionFile as h, DocsPageWorkspace as i, DocsLayout as l, DocsPlaygroundTab as m, DocsManifest as n, DocsSection as o, DocsPlaygroundExample as p, DocsPage as r, DocsTocLink as s, DocsAppPage as t, DocsPageFile as u, docsPageSchema as v, docsSectionSchema as y };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/docs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "A documentation site on ViteHub primitives: typed Markdown pages, navigation, tutorials, search, agent resources, Console editing, and a docs assistant.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"content",
|
|
@@ -50,6 +50,11 @@
|
|
|
50
50
|
"import": "./dist/nuxt.js",
|
|
51
51
|
"default": "./dist/nuxt.js"
|
|
52
52
|
},
|
|
53
|
+
"./runnable": {
|
|
54
|
+
"types": "./dist/runnable.d.ts",
|
|
55
|
+
"import": "./dist/runnable.js",
|
|
56
|
+
"default": "./dist/runnable.js"
|
|
57
|
+
},
|
|
53
58
|
"./server": {
|
|
54
59
|
"types": "./dist/server.d.ts",
|
|
55
60
|
"import": "./dist/server.js",
|
|
@@ -66,11 +71,12 @@
|
|
|
66
71
|
"@nuxt/fonts": "^1.2.0",
|
|
67
72
|
"@nuxt/kit": "4.6.2",
|
|
68
73
|
"@takumi-rs/core": "2.19.0",
|
|
69
|
-
"@vite-hub/content": "0.
|
|
70
|
-
"@vite-hub/rate-limit": "0.
|
|
71
|
-
"@vite-hub/source": "0.
|
|
72
|
-
"@vite-hub/ui": "0.
|
|
73
|
-
"@vite-hub/
|
|
74
|
+
"@vite-hub/content": "0.5.0",
|
|
75
|
+
"@vite-hub/rate-limit": "0.5.0",
|
|
76
|
+
"@vite-hub/source": "0.5.0",
|
|
77
|
+
"@vite-hub/ui": "0.5.0",
|
|
78
|
+
"@vite-hub/web-container": "0.5.0",
|
|
79
|
+
"@vite-hub/workspace": "0.5.0",
|
|
74
80
|
"@vueuse/core": "^14.4.0",
|
|
75
81
|
"comark-content": "0.5.1",
|
|
76
82
|
"comark-zoom": "^0.12.0",
|
|
@@ -94,8 +100,8 @@
|
|
|
94
100
|
"@nuxt/ui": "^4.12.0",
|
|
95
101
|
"@types/node": "^24.19.1",
|
|
96
102
|
"@vue/test-utils": "2.5.1",
|
|
97
|
-
"@vite-hub/agent": "0.
|
|
98
|
-
"@vite-hub/gateways": "0.
|
|
103
|
+
"@vite-hub/agent": "0.5.0",
|
|
104
|
+
"@vite-hub/gateways": "0.5.0",
|
|
99
105
|
"@vite-hub/icons": "0.1.0",
|
|
100
106
|
"@vite-hub/internal": "0.0.1",
|
|
101
107
|
"comark": "^0.9.0",
|
|
@@ -105,6 +111,7 @@
|
|
|
105
111
|
"linkedom": "^0.18.13",
|
|
106
112
|
"nitro": "^3.0.261103-rc",
|
|
107
113
|
"nuxt": "npm:nuxt-nightly@5.0.0-2611052317-a04317f",
|
|
114
|
+
"playwright-core": "^1.63.0",
|
|
108
115
|
"publint": "^0.3.25",
|
|
109
116
|
"tailwindcss": "^4.3.3",
|
|
110
117
|
"typescript": "^6.0.3",
|
|
@@ -117,8 +124,8 @@
|
|
|
117
124
|
"@comark/html": "^0.8.1 || ^0.9.0",
|
|
118
125
|
"@comark/vue": "^0.8.1 || ^0.9.0",
|
|
119
126
|
"@nuxt/ui": "^4.11.0",
|
|
120
|
-
"@vite-hub/agent": "0.
|
|
121
|
-
"@vite-hub/gateways": "0.
|
|
127
|
+
"@vite-hub/agent": "0.5.0",
|
|
128
|
+
"@vite-hub/gateways": "0.5.0",
|
|
122
129
|
"comark": "^0.8.1 || ^0.9.0",
|
|
123
130
|
"comark-ui": "^0.12.0",
|
|
124
131
|
"nuxt": ">=5.0.0-0",
|