@opentf/web-docs 0.1.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.
@@ -0,0 +1,70 @@
1
+ // "On this page" table of contents. Built from the rendered content headings (so it
2
+ // works for both MDX and JSX pages), with scroll-spy highlighting via
3
+ // IntersectionObserver. Rebuilds on route change.
4
+ //
5
+ // The MDX front-end already emits stable heading ids (slugs); we read them from the
6
+ // DOM after mount. (SSG output ships the heading anchors statically; this nav chrome
7
+ // activates once the client bundle mounts.)
8
+
9
+ import { onMount, router } from "@opentf/web";
10
+
11
+ export default function Toc() {
12
+ let items = $state([]);
13
+ let activeId = $state("");
14
+ let observer = null;
15
+
16
+ const build = () => {
17
+ if (typeof document === "undefined") return;
18
+ const root = document.getElementById("otfw-content");
19
+ if (!root) return;
20
+ const hs = Array.from(root.querySelectorAll("h2[id], h3[id]"));
21
+ items = hs.map((h) => ({
22
+ id: h.id,
23
+ text: h.textContent || "",
24
+ sub: h.tagName === "H3",
25
+ }));
26
+ if (observer) observer.disconnect();
27
+ observer = new IntersectionObserver(
28
+ (entries) => {
29
+ for (const e of entries) if (e.isIntersecting) activeId = e.target.id;
30
+ },
31
+ { rootMargin: "-10% 0px -80% 0px", threshold: 0 },
32
+ );
33
+ for (const h of hs) observer.observe(h);
34
+ };
35
+
36
+ onMount(() => {
37
+ build();
38
+ return () => observer && observer.disconnect();
39
+ });
40
+
41
+ // Rebuild when the route changes (content swaps under the same layout).
42
+ $effect(() => {
43
+ router.pathname;
44
+ if (typeof requestAnimationFrame !== "undefined") requestAnimationFrame(build);
45
+ });
46
+
47
+ return (
48
+ <nav class="otfw-toc" aria-label="On this page">
49
+ {() =>
50
+ items.length > 0 ? (
51
+ <div class="otfw-toc-inner">
52
+ <div class="otfw-toc-heading">On this page</div>
53
+ <ul class="otfw-toc-list">
54
+ {items.map((h) => (
55
+ <li class={h.sub ? "otfw-toc-item otfw-toc-sub" : "otfw-toc-item"}>
56
+ <a
57
+ href={"#" + h.id}
58
+ class={activeId === h.id ? "otfw-toc-link otfw-active" : "otfw-toc-link"}
59
+ >
60
+ {h.text}
61
+ </a>
62
+ </li>
63
+ ))}
64
+ </ul>
65
+ </div>
66
+ ) : null
67
+ }
68
+ </nav>
69
+ );
70
+ }
package/config.js ADDED
@@ -0,0 +1,42 @@
1
+ // Site/docs configuration helper.
2
+ //
3
+ // `defineDocsConfig` is an identity function: it returns the config untouched, but
4
+ // gives authors editor type-hints (via the JSDoc typedef) and a stable import the
5
+ // toolchain can recognise. Used in `otfw.config.js`:
6
+ //
7
+ // import { defineDocsConfig } from "@opentf/web-docs/config";
8
+ // export default defineDocsConfig({ site: { url }, docs: { … } });
9
+
10
+ /**
11
+ * @typedef {Object} DocsNavLink
12
+ * @property {string} label
13
+ * @property {string} href
14
+ *
15
+ * @typedef {Object} DocsFooter
16
+ * @property {string} [text]
17
+ * @property {DocsNavLink[]} [links]
18
+ *
19
+ * @typedef {Object} DocsConfig
20
+ * @property {string} [title] Site/product name shown in the navbar.
21
+ * @property {string} [logo] URL of the navbar logo image.
22
+ * @property {string} [homeUrl] Where the navbar brand links to (default "/").
23
+ * @property {string} [github] GitHub URL (shown in the navbar).
24
+ * @property {string} [dir] Docs content folder under app/ (default "docs").
25
+ * @property {DocsNavLink[]} [nav] Top-level navbar links.
26
+ * @property {DocsFooter} [footer] Footer content.
27
+ * @property {{ provider?: string }} [search] Search provider (Phase 2: "pagefind").
28
+ *
29
+ * @typedef {Object} SiteConfig
30
+ * @property {{ url?: string }} [site] Canonical site origin (for SEO / sitemap).
31
+ * @property {DocsConfig} [docs] Documentation generator config.
32
+ */
33
+
34
+ /**
35
+ * @param {SiteConfig} config
36
+ * @returns {SiteConfig}
37
+ */
38
+ export function defineDocsConfig(config) {
39
+ return config;
40
+ }
41
+
42
+ export default defineDocsConfig;
package/index.js ADDED
@@ -0,0 +1,38 @@
1
+ // Public barrel for @opentf/web-docs.
2
+ //
3
+ // Components are shipped as JSX source and compiled by the consuming app's pipeline
4
+ // (the `@opentf/web` Link.jsx model) — each becomes a `web-*` Custom Element with
5
+ // CSR + SSG renderers for free. otfwc compiles JSX tags to element *strings*
6
+ // (`web-callout`), so the JS import of a component would be tree-shaken; the bare
7
+ // `import "./components/X.jsx"` retains its `customElements.define` side effect
8
+ // (the compiled modules are marked side-effectful), and the re-export lets authors
9
+ // pull a component in by name (`import { Callout } from "@opentf/web-docs"`).
10
+
11
+ import "./components/DocsLayout.jsx";
12
+ import "./components/Navbar.jsx";
13
+ import "./components/Sidebar.jsx";
14
+ import "./components/SidebarNode.jsx";
15
+ import "./components/Toc.jsx";
16
+ import "./components/Footer.jsx";
17
+ import "./components/Breadcrumbs.jsx";
18
+ import "./components/Pagination.jsx";
19
+ import "./components/ThemeToggle.jsx";
20
+ import "./components/SearchTrigger.jsx";
21
+ import "./components/Callout.jsx";
22
+ import "./components/Tabs.jsx";
23
+ import "./components/CodeGroup.jsx";
24
+ import "./components/Table.jsx";
25
+
26
+ export { default as DocsLayout } from "./components/DocsLayout.jsx";
27
+ export { default as Navbar } from "./components/Navbar.jsx";
28
+ export { default as Sidebar } from "./components/Sidebar.jsx";
29
+ export { default as Toc } from "./components/Toc.jsx";
30
+ export { default as Footer } from "./components/Footer.jsx";
31
+ export { default as Breadcrumbs } from "./components/Breadcrumbs.jsx";
32
+ export { default as Pagination } from "./components/Pagination.jsx";
33
+ export { default as ThemeToggle } from "./components/ThemeToggle.jsx";
34
+ export { default as SearchTrigger } from "./components/SearchTrigger.jsx";
35
+ export { default as Callout } from "./components/Callout.jsx";
36
+ export { default as Tabs } from "./components/Tabs.jsx";
37
+ export { default as CodeGroup } from "./components/CodeGroup.jsx";
38
+ export { default as Table } from "./components/Table.jsx";
package/nav-virtual.js ADDED
@@ -0,0 +1,16 @@
1
+ // Fallback for `@opentf/web-docs/nav`.
2
+ //
3
+ // When `docsNavPlugin` is active (the toolchain registers it whenever the project
4
+ // has a `docs` config), it intercepts this specifier and replaces it with a
5
+ // build-time-generated module exporting the real navigation tree. This file is only
6
+ // loaded when the plugin is NOT active (e.g. an editor, or a non-docs build), in
7
+ // which case the nav is simply empty.
8
+
9
+ if (typeof console !== "undefined") {
10
+ console.warn(
11
+ "[@opentf/web-docs] navigation requested but docsNavPlugin is not active — " +
12
+ "did you add a `docs` block to otfw.config.js? Returning an empty nav.",
13
+ );
14
+ }
15
+
16
+ export default [];
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@opentf/web-docs",
3
+ "version": "0.1.0",
4
+ "description": "Documentation-site generator for OTF Web — themed shell components (sidebar, TOC, callouts, tabs), a build-time nav generator, and a default light/dark theme.",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": "./index.js",
8
+ "./theme": "./theme/index.css",
9
+ "./config": "./config.js",
10
+ "./nav": "./nav-virtual.js",
11
+ "./build": "./build/index.js"
12
+ },
13
+ "files": [
14
+ "index.js",
15
+ "config.js",
16
+ "nav-virtual.js",
17
+ "components",
18
+ "theme",
19
+ "build",
20
+ "!**/*.test.js"
21
+ ],
22
+ "keywords": [
23
+ "opentf",
24
+ "documentation",
25
+ "docs",
26
+ "mdx",
27
+ "static-site-generator",
28
+ "ssg"
29
+ ],
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/Open-Tech-Foundation/Web-App-Framework.git",
33
+ "directory": "packages/web-docs"
34
+ },
35
+ "homepage": "https://github.com/Open-Tech-Foundation/Web-App-Framework#readme",
36
+ "bugs": "https://github.com/Open-Tech-Foundation/Web-App-Framework/issues",
37
+ "license": "MIT",
38
+ "peerDependencies": {
39
+ "@opentf/web": "*"
40
+ },
41
+ "publishConfig": {
42
+ "access": "public"
43
+ }
44
+ }