rift-ds 1.32.0 → 1.33.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.
Files changed (96) hide show
  1. package/README.md +4 -4
  2. package/behaviors/clipboard.d.ts +7 -0
  3. package/behaviors/clipboard.js +35 -0
  4. package/behaviors/headingSlug.d.ts +8 -0
  5. package/behaviors/headingSlug.js +4 -0
  6. package/behaviors/shell.css +64 -0
  7. package/behaviors/syncedChoice.d.ts +2 -0
  8. package/behaviors/syncedChoice.js +48 -0
  9. package/behaviors/useLayer.d.ts +15 -2
  10. package/behaviors/useLayer.js +3 -2
  11. package/bin/templates/blocks/app/guide/PageFeedback.tsx +55 -0
  12. package/bin/templates/blocks/app/guide/page.module.css +94 -0
  13. package/bin/templates/blocks/app/guide/page.tsx +168 -0
  14. package/bin/templates/blocks/components/blocks/AppShell.module.css +3 -1
  15. package/bin/templates/blocks/components/blocks/AppShell.tsx +8 -0
  16. package/bin/templates/blocks/components/blocks/DocsShell.module.css +18 -0
  17. package/bin/templates/blocks/components/blocks/DocsShell.tsx +179 -0
  18. package/bin/templates/blocks/registry.json +13 -0
  19. package/code/highlight.d.ts +4 -0
  20. package/code/highlight.js +34 -0
  21. package/code/index.d.ts +16 -0
  22. package/code/index.js +23 -0
  23. package/components/AnchorNav/AnchorNav.d.ts +29 -3
  24. package/components/AnchorNav/AnchorNav.js +69 -5
  25. package/components/AppLayout/AppLayout.css +8 -4
  26. package/components/AppLayout/AppLayout.d.ts +13 -3
  27. package/components/AppLayout/AppLayout.js +2 -0
  28. package/components/ArtifactPanel/ArtifactPanel.css +46 -0
  29. package/components/ArtifactPanel/ArtifactPanel.d.ts +14 -4
  30. package/components/ArtifactPanel/ArtifactPanel.js +8 -5
  31. package/components/BackToTop/BackToTop.css +28 -0
  32. package/components/BackToTop/BackToTop.d.ts +28 -0
  33. package/components/BackToTop/BackToTop.js +47 -0
  34. package/components/BentoTile/BentoTile.css +3 -0
  35. package/components/CodeBlock/CodeBlock.css +63 -24
  36. package/components/CodeBlock/CodeBlock.d.ts +62 -6
  37. package/components/CodeBlock/CodeBlock.js +90 -48
  38. package/components/CopyButton/CopyButton.d.ts +42 -0
  39. package/components/CopyButton/CopyButton.js +72 -0
  40. package/components/DescriptionList/DescriptionListCopy.d.ts +2 -2
  41. package/components/DescriptionList/DescriptionListCopy.js +7 -35
  42. package/components/Figure/Figure.css +26 -0
  43. package/components/Figure/Figure.d.ts +10 -1
  44. package/components/Figure/Figure.js +15 -3
  45. package/components/Heading/Heading.css +43 -0
  46. package/components/Heading/Heading.d.ts +14 -3
  47. package/components/Heading/Heading.js +22 -4
  48. package/components/HoverCard/HoverCard.js +1 -0
  49. package/components/Link/Link.css +38 -0
  50. package/components/Link/Link.d.ts +3 -3
  51. package/components/Link/Link.js +1 -1
  52. package/components/Menubar/Menubar.css +82 -0
  53. package/components/Menubar/Menubar.d.ts +40 -0
  54. package/components/Menubar/Menubar.js +97 -0
  55. package/components/NavList/NavList.css +197 -0
  56. package/components/NavList/NavList.d.ts +54 -6
  57. package/components/NavList/NavList.js +136 -8
  58. package/components/Pagination/Pagination.css +80 -0
  59. package/components/Pagination/Pagination.d.ts +29 -3
  60. package/components/Pagination/Pagination.js +49 -5
  61. package/components/Rating/Rating.css +26 -0
  62. package/components/Rating/Rating.d.ts +18 -5
  63. package/components/Rating/Rating.js +16 -7
  64. package/components/SectionTitle/SectionTitle.css +36 -0
  65. package/components/SectionTitle/SectionTitle.d.ts +10 -1
  66. package/components/SectionTitle/SectionTitle.js +7 -2
  67. package/components/ShaderScene/ShaderScene.d.ts +2 -1
  68. package/components/ShaderScene/ShaderScene.js +20 -2
  69. package/components/SiteFooter/SiteFooter.css +157 -0
  70. package/components/SiteFooter/SiteFooter.d.ts +53 -0
  71. package/components/SiteFooter/SiteFooter.js +61 -0
  72. package/components/SiteHeader/SiteHeader.css +106 -4
  73. package/components/SiteHeader/SiteHeader.d.ts +25 -2
  74. package/components/SiteHeader/SiteHeader.js +46 -8
  75. package/components/SiteLayout/SiteLayout.css +361 -0
  76. package/components/SiteLayout/SiteLayout.d.ts +103 -0
  77. package/components/SiteLayout/SiteLayout.js +68 -0
  78. package/components/Table/Table.css +14 -0
  79. package/components/Table/Table.d.ts +2 -0
  80. package/components/Table/Table.js +1 -1
  81. package/components/Tooltip/Tooltip.js +1 -0
  82. package/components/keyboard-patterns.json.d.ts +57 -0
  83. package/components/keyboard-patterns.json.js +1 -1
  84. package/components/registry.json +89 -19
  85. package/components/registry.json.d.ts +89 -19
  86. package/components/registry.json.js +1 -1
  87. package/index.d.ts +5 -0
  88. package/index.js +14 -1
  89. package/package.json +14 -2
  90. package/tokens/breakpoints.js +3 -3
  91. package/tokens/registry.json +5 -0
  92. package/tokens/registry.json.d.ts +5 -0
  93. package/tokens/registry.json.js +1 -1
  94. package/tokens/tokens-dark.css +12 -0
  95. package/tokens/tokens-light.css +12 -0
  96. package/tokens/values.json.js +1 -1
@@ -0,0 +1,18 @@
1
+ /*
2
+ * The docs shell's own touches. SiteLayout owns the columns, the sticky
3
+ * sidebar, the widths, the reading measure and the fold; every value here
4
+ * is a rift-ds token.
5
+ */
6
+
7
+ .brand {
8
+ font-family: var(--font-title-body-family);
9
+ font-size: var(--font-title-body-size);
10
+ font-weight: var(--font-title-body-weight);
11
+ color: var(--color-text-primary);
12
+ }
13
+
14
+ .article {
15
+ display: flex;
16
+ flex-direction: column;
17
+ gap: var(--gap-500);
18
+ }
@@ -0,0 +1,179 @@
1
+ 'use client';
2
+ /**
3
+ * The documentation shell the docs block sits in: rift-ds's SiteLayout
4
+ * holding a site header (search and colour mode), a long sidebar of pages,
5
+ * the article with its breadcrumb, an on-this-page rail read from the
6
+ * article's headings, and a sitemap footer. This file is yours: rename the
7
+ * product, replace the navigation and the footer with your own, and wire
8
+ * the search to your command palette.
9
+ *
10
+ * Two settings below lay it out: PAGE_WIDTH (the columns contained at
11
+ * 1440px or full width) and SIDEBAR_DOCK, which moves the header, the
12
+ * sidebar and the footer as one frame: docked to the window's edge, the
13
+ * header and the footer run full width with it; beside the content, all
14
+ * three follow the page. SiteLayout's readingWidth holds the article to a
15
+ * reading measure while the page is contained.
16
+ *
17
+ * Responsive by construction: below 1152px the on-this-page rail gives
18
+ * way, and below 960px the sidebar leaves the page and the header's menu
19
+ * carries its pages (each section's drawerItems), so there is one menu.
20
+ */
21
+
22
+ import type { ReactNode } from 'react';
23
+ import { AnchorNav } from 'rift-ds/components/AnchorNav/AnchorNav';
24
+ import { BackToTop } from 'rift-ds/components/BackToTop/BackToTop';
25
+ import { Breadcrumb, type BreadcrumbItem } from 'rift-ds/components/Breadcrumb/Breadcrumb';
26
+ import { CommandPaletteTrigger } from 'rift-ds/components/CommandPaletteTrigger/CommandPaletteTrigger';
27
+ import { NavList, type NavListEntry } from 'rift-ds/components/NavList/NavList';
28
+ import { SiteFooter, type SiteFooterColumn } from 'rift-ds/components/SiteFooter/SiteFooter';
29
+ import { SiteHeader, type SiteHeaderSection } from 'rift-ds/components/SiteHeader/SiteHeader';
30
+ import { SiteLayout } from 'rift-ds/components/SiteLayout/SiteLayout';
31
+ import { ThemeToggle } from 'rift-ds/components/ThemeToggle/ThemeToggle';
32
+ import styles from './DocsShell.module.css';
33
+
34
+ /** How wide the page's columns run: centred at 1440px, or the full window. */
35
+ const PAGE_WIDTH: 'contained' | 'full' = 'full';
36
+
37
+ /** Where the sidebar sits, the header and the footer moving with it: docked to the window's start edge, or beside the content in the page's row. */
38
+ const SIDEBAR_DOCK: 'edge' | 'content' = 'edge';
39
+
40
+ /** The product's name, shown in the header and the footer. */
41
+ const PRODUCT_NAME = 'Acme';
42
+
43
+
44
+ /** Every page of the docs, in sections; a long list scrolls inside the sidebar. */
45
+ const COMPONENT_PAGES = [
46
+ 'Accordion', 'Alert', 'Avatar', 'Badge', 'Breadcrumb', 'Button', 'Calendar', 'Card', 'Checkbox', 'Code block',
47
+ 'Combobox', 'Dialog', 'Drawer', 'Dropdown menu', 'Field', 'Input', 'Menubar', 'Pagination', 'Popover', 'Select',
48
+ 'Slider', 'Switch', 'Table', 'Tabs', 'Toast', 'Tooltip',
49
+ ];
50
+ const NAV: NavListEntry[] = [
51
+ {
52
+ type: 'section',
53
+ label: 'Getting started',
54
+ items: [
55
+ { label: 'Introduction', href: '#introduction' },
56
+ { label: 'Installation', href: '#installation' },
57
+ {
58
+ label: 'Theming',
59
+ href: '#theming',
60
+ items: [
61
+ { label: 'Colours', href: '#theming-colours' },
62
+ { label: 'Dark mode', href: '#theming-dark-mode' },
63
+ ],
64
+ },
65
+ { label: 'CLI', href: '#cli', badge: 'New' },
66
+ ],
67
+ },
68
+ {
69
+ type: 'section',
70
+ label: 'Components',
71
+ items: COMPONENT_PAGES.map((label) => ({ label, href: `#${label.toLowerCase().replace(/ /g, '-')}` })),
72
+ },
73
+ {
74
+ type: 'section',
75
+ label: 'Guides',
76
+ collapsible: true,
77
+ items: [
78
+ { label: 'Forms', href: '#guide-forms' },
79
+ { label: 'Server rendering', href: '#guide-server-rendering' },
80
+ ],
81
+ },
82
+ ];
83
+
84
+ /**
85
+ * The header's top-level sections. Each lists its pages as drawerItems: on a
86
+ * phone the sidebar leaves the page and the header's one menu carries them.
87
+ */
88
+ const SECTIONS: SiteHeaderSection[] = [
89
+ {
90
+ id: 'docs',
91
+ label: 'Docs',
92
+ href: '#docs',
93
+ drawerItems: [
94
+ { label: 'Introduction', href: '#introduction' },
95
+ { label: 'Installation', href: '#installation' },
96
+ { label: 'Theming', href: '#theming' },
97
+ { label: 'CLI', href: '#cli' },
98
+ ],
99
+ },
100
+ {
101
+ id: 'components',
102
+ label: 'Components',
103
+ href: '#components',
104
+ drawerItems: COMPONENT_PAGES.map((label) => ({ label, href: `#${label.toLowerCase().replace(/ /g, '-')}` })),
105
+ },
106
+ { id: 'changelog', label: 'Changelog', href: '#changelog' },
107
+ ];
108
+
109
+ /** The footer's sitemap. */
110
+ const FOOTER_COLUMNS: SiteFooterColumn[] = [
111
+ { label: 'Docs', links: [{ label: 'Introduction', href: '#introduction' }, { label: 'Installation', href: '#installation' }] },
112
+ { label: 'Components', links: [{ label: 'Button', href: '#button' }, { label: 'Table', href: '#table' }] },
113
+ { label: 'Community', links: [{ label: 'Discussions', href: 'https://example.com/discussions', external: true }] },
114
+ ];
115
+
116
+ export interface DocsShellProps {
117
+ /** The href of this page, which the sidebar marks as current. */
118
+ currentHref: string;
119
+ /** The page's place in the docs, ending with the page itself. */
120
+ breadcrumb: BreadcrumbItem[];
121
+ /** The article: its h1, then its sections, each opened by an h2. */
122
+ children: ReactNode;
123
+ }
124
+
125
+ export function DocsShell({ currentHref, breadcrumb, children }: DocsShellProps) {
126
+ return (
127
+ <SiteLayout
128
+ width={PAGE_WIDTH}
129
+ readingWidth
130
+ sidebarDock={SIDEBAR_DOCK}
131
+ mainId="docs-article"
132
+ header={
133
+ <SiteHeader
134
+ brand={<span className={styles.brand}>{PRODUCT_NAME}</span>}
135
+ sections={SECTIONS}
136
+ currentHref="#docs"
137
+ foldBelow="tablet"
138
+ actions={
139
+ <>
140
+ {/* Wire it to your command palette: CommandPalette from rift-ds,
141
+ opened from here and from Cmd+K. */}
142
+ <CommandPaletteTrigger label="Search the docs" size="compact" />
143
+ <ThemeToggle showLabels={false} size="compact" />
144
+ </>
145
+ }
146
+ condensedActions={
147
+ <>
148
+ {/* The same two at their narrowest, for a phone: the bar uses
149
+ these before it folds. */}
150
+ <CommandPaletteTrigger label="Search the docs" size="compact" iconOnly />
151
+ <ThemeToggle size="compact" cycle />
152
+ </>
153
+ }
154
+ />
155
+ }
156
+ sidebar={
157
+ <NavList
158
+ items={NAV}
159
+ size="compact"
160
+ scrollable
161
+ currentHref={currentHref}
162
+ />
163
+ }
164
+ aside={<AnchorNav fromHeadings={{ root: '#docs-article' }} />}
165
+ footer={
166
+ <SiteFooter
167
+ brand={PRODUCT_NAME}
168
+ description="Components and guides for building the Acme app."
169
+ columns={FOOTER_COLUMNS}
170
+ legal={`© ${new Date().getFullYear()} ${PRODUCT_NAME}.`}
171
+ />
172
+ }
173
+ >
174
+ <Breadcrumb items={breadcrumb} />
175
+ <div className={styles.article}>{children}</div>
176
+ <BackToTop focusTarget="docs-article" />
177
+ </SiteLayout>
178
+ );
179
+ }
@@ -72,6 +72,19 @@
72
72
  "app/shader/page.tsx",
73
73
  "app/shader/page.module.css"
74
74
  ]
75
+ },
76
+ {
77
+ "name": "docs",
78
+ "label": "Docs",
79
+ "description": "A documentation page: a site header, a long sidebar of pages, an article with tabbed install commands and live examples, an on-this-page rail and a footer.",
80
+ "route": "/guide",
81
+ "files": [
82
+ "components/blocks/DocsShell.tsx",
83
+ "components/blocks/DocsShell.module.css",
84
+ "app/guide/page.tsx",
85
+ "app/guide/page.module.css",
86
+ "app/guide/PageFeedback.tsx"
87
+ ]
75
88
  }
76
89
  ]
77
90
  }
@@ -0,0 +1,4 @@
1
+ import { CodeLine } from '../components/CodeBlock/CodeBlock';
2
+ export type { CodeLine, CodeToken, CodeTokenRole } from '../components/CodeBlock/CodeBlock';
3
+ /** Highlight `code` as `lang` (any language shiki bundles: "tsx", "css", "bash", "json" and the rest). */
4
+ export declare function highlight(code: string, lang: string): Promise<CodeLine[]>;
@@ -0,0 +1,34 @@
1
+ import { createCssVariablesTheme, createHighlighter } from "shiki";
2
+ const PREFIX = "--rift-code-";
3
+ const theme = createCssVariablesTheme({ name: "rift", variablePrefix: PREFIX, variableDefaults: {}, fontStyle: false });
4
+ const ROLES = {
5
+ "token-keyword": "keyword",
6
+ "token-string": "string",
7
+ "token-string-expression": "string",
8
+ "token-link": "string",
9
+ "token-function": "function",
10
+ "token-constant": "constant",
11
+ "token-comment": "comment"
12
+ };
13
+ let highlighter;
14
+ const plain = (code) => code.split("\n").map((text) => [{ content: text }]);
15
+ async function highlight(code, lang) {
16
+ highlighter ??= createHighlighter({ themes: [theme], langs: [] });
17
+ const h = await highlighter;
18
+ try {
19
+ if (!h.getLoadedLanguages().includes(lang)) await h.loadLanguage(lang);
20
+ } catch {
21
+ return plain(code);
22
+ }
23
+ const { tokens } = h.codeToTokens(code, { lang, theme: "rift" });
24
+ return tokens.map(
25
+ (line) => line.map((token) => {
26
+ const match = token.color?.match(/var\(--rift-code-([a-z-]+)\)/);
27
+ const role = match ? ROLES[match[1]] : void 0;
28
+ return role ? { content: token.content, role } : { content: token.content };
29
+ })
30
+ );
31
+ }
32
+ export {
33
+ highlight
34
+ };
@@ -0,0 +1,16 @@
1
+ import { CodeBlockTab } from '../components/CodeBlock/CodeBlock';
2
+ export type { CodeBlockTab, CodeLine, CodeToken, CodeTokenRole } from '../components/CodeBlock/CodeBlock';
3
+ /** A package manager `packageManagerTabs` can write a command for. */
4
+ export type PackageManager = 'npm' | 'pnpm' | 'yarn' | 'bun';
5
+ /** What to write: packages to install, or a package binary to run once. */
6
+ export type PackageCommand = {
7
+ /** Packages to add, e.g. `'rift-ds'` or `['rift-ds', 'shiki']`. */
8
+ install: string | string[];
9
+ /** Add them as development dependencies. */
10
+ dev?: boolean;
11
+ } | {
12
+ /** A package binary and its arguments to run without installing, e.g. `'rift-ds init'`. */
13
+ run: string;
14
+ };
15
+ /** The same command for each package manager, as CodeBlock tabs (npm, pnpm, yarn and bun unless `managers` narrows them). */
16
+ export declare function packageManagerTabs(command: PackageCommand, managers?: PackageManager[]): CodeBlockTab[];
package/code/index.js ADDED
@@ -0,0 +1,23 @@
1
+ const INSTALL = {
2
+ npm: "npm install",
3
+ pnpm: "pnpm add",
4
+ yarn: "yarn add",
5
+ bun: "bun add"
6
+ };
7
+ const DEV_FLAG = { npm: "--save-dev", pnpm: "-D", yarn: "-D", bun: "-d" };
8
+ const RUN = { npm: "npx", pnpm: "pnpm dlx", yarn: "yarn dlx", bun: "bunx" };
9
+ function packageManagerTabs(command, managers = ["npm", "pnpm", "yarn", "bun"]) {
10
+ return managers.map((manager) => {
11
+ let code;
12
+ if ("run" in command) {
13
+ code = `${RUN[manager]} ${command.run}`;
14
+ } else {
15
+ const packages = Array.isArray(command.install) ? command.install.join(" ") : command.install;
16
+ code = [INSTALL[manager], command.dev ? DEV_FLAG[manager] : "", packages].filter(Boolean).join(" ");
17
+ }
18
+ return { value: manager, label: manager, code };
19
+ });
20
+ }
21
+ export {
22
+ packageManagerTabs
23
+ };
@@ -5,9 +5,35 @@ export interface AnchorNavItem {
5
5
  /** Link text */
6
6
  label: string;
7
7
  }
8
+ /** Where `fromHeadings` (and `useHeadingItems`) look for the page's sections. */
9
+ export interface AnchorNavHeadingSource {
10
+ /** A selector for the element whose headings are listed. Defaults to `main`. */
11
+ root?: string;
12
+ /** Which headings count as sections. Defaults to `h2`. */
13
+ selector?: string;
14
+ /** List nothing until at least this many sections are found, since a rail of one link is no help. Defaults to 2. */
15
+ minItems?: number;
16
+ }
17
+ /**
18
+ * The sections of the page, read from its headings: every match of
19
+ * `selector` under `root`, in document order, skipping any inside an
20
+ * `aside` or a `[data-anchor-ignore]` region (a sidebar's headings, or a
21
+ * demo's). A heading's id is its own, else its enclosing section's, else
22
+ * one made from its text and written onto it. Re-reads when the content
23
+ * under `root` changes, so streamed or late content joins the list.
24
+ * Returns an empty list until `minItems` sections are found.
25
+ */
26
+ export declare function useHeadingItems(source: AnchorNavHeadingSource | undefined): AnchorNavItem[];
8
27
  type AnchorNavOwnProps = {
9
- /** The on-page sections to list, in document order */
10
- items: AnchorNavItem[];
28
+ /** The on-page sections to list, in document order. Leave it out and pass `fromHeadings` to read them from the page. */
29
+ items?: AnchorNavItem[];
30
+ /**
31
+ * Read the sections from the page's headings instead of listing them:
32
+ * `{}` lists every `h2` in `main`, and `root`, `selector` and `minItems`
33
+ * narrow it. Ignored when `items` is passed. Renders nothing until enough
34
+ * sections are found.
35
+ */
36
+ fromHeadings?: AnchorNavHeadingSource;
11
37
  /** Visual form: `list` renders the inline "On this page" rail; `floating` collapses to a stack of short lines that expands into a panel on hover, keyboard focus, or tap, so it can ride a page edge without taking column width */
12
38
  variant?: 'list' | 'floating';
13
39
  /**
@@ -21,7 +47,7 @@ type AnchorNavOwnProps = {
21
47
  activeId?: string;
22
48
  /** Fires when the tracked (or clicked) active item changes */
23
49
  onActiveChange?: (id: string) => void;
24
- /** Distance in px from the viewport top at which a section counts as current, e.g. a sticky header's height */
50
+ /** Distance in px from the viewport top at which a section counts as current, e.g. a sticky header's height. A heading with a larger `scroll-margin-top` counts from there, so a jump to it always marks it. */
25
51
  offset?: number;
26
52
  };
27
53
  export interface AnchorNavProps extends AnchorNavOwnProps, Omit<React.ComponentPropsWithoutRef<'nav'>, keyof AnchorNavOwnProps> {
@@ -1,13 +1,62 @@
1
1
  "use client";
2
2
  import { jsxs, jsx, Fragment } from "react/jsx-runtime";
3
- import React, { useRef, useImperativeHandle, useState, useCallback, useEffect } from "react";
3
+ import React, { useRef, useImperativeHandle, useState, useEffect, useCallback } from "react";
4
4
  import { useLayer } from "../../behaviors/useLayer.js";
5
+ import { headingSlug } from "../../behaviors/headingSlug.js";
5
6
  import "./AnchorNav.css";
6
7
  import "../../behaviors/direction.css";
7
8
  import { mirrorClass } from "../../behaviors/direction.js";
9
+ const headingText = (heading) => {
10
+ const copy = heading.cloneNode(true);
11
+ copy.querySelectorAll('.ds-heading__anchor, .ds-section-title__anchor, [aria-hidden="true"]').forEach((el) => el.remove());
12
+ return (copy.textContent ?? "").trim();
13
+ };
14
+ const slug = (text) => headingSlug(text);
15
+ function useHeadingItems(source) {
16
+ const [items, setItems] = useState([]);
17
+ const root = source?.root ?? "main";
18
+ const selector = source?.selector ?? "h2";
19
+ const minItems = source?.minItems ?? 2;
20
+ const enabled = source !== void 0;
21
+ useEffect(() => {
22
+ if (!enabled) return;
23
+ const container = document.querySelector(root);
24
+ const scan = () => {
25
+ const used = /* @__PURE__ */ new Set();
26
+ const found = [];
27
+ for (const heading of container?.querySelectorAll(selector) ?? []) {
28
+ if (heading.closest("aside, [data-anchor-ignore]")) continue;
29
+ const label = headingText(heading);
30
+ if (!label) continue;
31
+ let id = heading.id || heading.closest("section[id]")?.id || "";
32
+ if (!id) {
33
+ const base = slug(label) || "section";
34
+ id = base;
35
+ let n = 2;
36
+ while (used.has(id) || document.getElementById(id)) id = `${base}-${n++}`;
37
+ heading.id = id;
38
+ }
39
+ if (used.has(id)) continue;
40
+ used.add(id);
41
+ found.push({ id, label });
42
+ }
43
+ const next = found.length >= minItems ? found : [];
44
+ setItems(
45
+ (prev) => prev.length === next.length && prev.every((p, i) => p.id === next[i].id && p.label === next[i].label) ? prev : next
46
+ );
47
+ };
48
+ scan();
49
+ if (!container) return;
50
+ const observer = new MutationObserver(scan);
51
+ observer.observe(container, { childList: true, subtree: true, characterData: true });
52
+ return () => observer.disconnect();
53
+ }, [enabled, root, selector, minItems]);
54
+ return items;
55
+ }
8
56
  const AnchorNav = React.forwardRef(
9
57
  ({
10
- items,
58
+ items: itemsProp,
59
+ fromHeadings,
11
60
  variant = "list",
12
61
  title = "On this page",
13
62
  icon = "toc",
@@ -20,13 +69,17 @@ const AnchorNav = React.forwardRef(
20
69
  }, ref) => {
21
70
  const navRef = useRef(null);
22
71
  useImperativeHandle(ref, () => navRef.current);
72
+ const discovered = useHeadingItems(itemsProp ? void 0 : fromHeadings);
73
+ const items = itemsProp ?? discovered;
23
74
  const floating = variant === "floating";
24
75
  const [open, setOpen] = useState(false);
25
76
  const isControlled = activeId !== void 0;
26
77
  const [trackedId, setTrackedId] = useState(void 0);
27
78
  const currentId = isControlled ? activeId : trackedId;
28
79
  const onActiveChangeRef = useRef(onActiveChange);
29
- onActiveChangeRef.current = onActiveChange;
80
+ useEffect(() => {
81
+ onActiveChangeRef.current = onActiveChange;
82
+ });
30
83
  const setActive = useCallback(
31
84
  (id) => {
32
85
  setTrackedId((prev) => {
@@ -36,6 +89,7 @@ const AnchorNav = React.forwardRef(
36
89
  },
37
90
  []
38
91
  );
92
+ const pressedRef = useRef(void 0);
39
93
  useEffect(() => {
40
94
  if (isControlled || items.length === 0) return;
41
95
  let frame = 0;
@@ -45,7 +99,14 @@ const AnchorNav = React.forwardRef(
45
99
  for (const item of items) {
46
100
  const el = document.getElementById(item.id);
47
101
  if (!el) continue;
48
- if (el.getBoundingClientRect().top <= offset + 1) current = item.id;
102
+ const margin = parseFloat(getComputedStyle(el).scrollMarginTop) || 0;
103
+ if (el.getBoundingClientRect().top <= Math.max(offset, margin) + 1) current = item.id;
104
+ }
105
+ const root = document.documentElement;
106
+ if (window.innerHeight + window.scrollY >= root.scrollHeight - 2) {
107
+ const pressed = pressedRef.current ? document.getElementById(pressedRef.current) : null;
108
+ const top = pressed?.getBoundingClientRect().top;
109
+ current = pressed && top !== void 0 && top >= 0 && top < window.innerHeight ? pressedRef.current : items[items.length - 1].id;
49
110
  }
50
111
  setActive(current);
51
112
  };
@@ -93,6 +154,7 @@ const AnchorNav = React.forwardRef(
93
154
  className: item.id === currentId ? "ds-anchor-nav__link ds-anchor-nav__link--active" : "ds-anchor-nav__link",
94
155
  "aria-current": item.id === currentId ? "location" : void 0,
95
156
  onClick: (event) => {
157
+ pressedRef.current = item.id;
96
158
  if (!isControlled) setActive(item.id);
97
159
  else onActiveChangeRef.current?.(item.id);
98
160
  if (floating) {
@@ -103,6 +165,7 @@ const AnchorNav = React.forwardRef(
103
165
  children: item.label
104
166
  }
105
167
  ) }, item.id)) });
168
+ if (!itemsProp && items.length === 0) return null;
106
169
  return /* @__PURE__ */ jsx(
107
170
  "nav",
108
171
  {
@@ -133,5 +196,6 @@ const AnchorNav = React.forwardRef(
133
196
  );
134
197
  AnchorNav.displayName = "AnchorNav";
135
198
  export {
136
- AnchorNav
199
+ AnchorNav,
200
+ useHeadingItems
137
201
  };
@@ -4,6 +4,8 @@
4
4
  ============================================ */
5
5
 
6
6
  .ds-app-layout {
7
+ /* The contained width, AppLayout's own: an app's working column. */
8
+ --ds-shell-contained-width: 1120px;
7
9
  display: flex;
8
10
  min-height: 100vh;
9
11
  /* The shell recipe's plane (src/behaviors/shell.css), set per layout by
@@ -49,7 +51,9 @@
49
51
  ============================================ */
50
52
  .ds-app-layout__content {
51
53
  width: 100%;
52
- max-width: 1120px;
54
+ /* The shell recipe's width axis: the contained width, or none when full. */
55
+ max-width: var(--ds-shell-content-max, var(--ds-shell-contained-width));
56
+ margin-inline: auto;
53
57
  display: flex;
54
58
  flex-direction: column;
55
59
  gap: var(--gap-1000);
@@ -69,7 +73,7 @@
69
73
 
70
74
  /* ============================================
71
75
  INSET LAYOUT — the rail flush on the shell
72
- colour, the content full width in a surface
76
+ colour, the content in a surface
73
77
  inset from the other three edges. The page
74
78
  holds the viewport and the surface scrolls.
75
79
  The rail's own item inset is the gap on its
@@ -115,12 +119,12 @@
115
119
  scrollbar-color: var(--color-bg-container-border) transparent;
116
120
  }
117
121
 
118
- /* Full width in the surface, and a size container: content inside can
122
+ /* A size container, centred in the surface or its full width by the
123
+ width axis like every mode: content inside can
119
124
  restack by the room the surface gives it (an open chat panel or an
120
125
  expanded rail narrows it without the viewport changing) with
121
126
  @container ds-app-layout-content queries. */
122
127
  .ds-app-layout--inset .ds-app-layout__content {
123
- max-width: none;
124
128
  container: ds-app-layout-content / inline-size;
125
129
  }
126
130
 
@@ -29,11 +29,21 @@ type AppLayoutOwnProps = {
29
29
  * colour behind a hairline, the content centred beside it on the crisp
30
30
  * app surface, nothing raised. `floating` floats the rail as a glass card,
31
31
  * the content still centred. `inset` runs the rail flush on the shell
32
- * colour and sets the content full width in a raised surface (hairline
33
- * and floating shadow) inset from the other edges, which scrolls inside
34
- * itself.
32
+ * colour and sets the content in a raised surface (hairline and floating
33
+ * shadow) inset from the other edges, which scrolls inside itself. How
34
+ * wide the content runs is `width`, apart from the mode.
35
35
  */
36
36
  layout?: AppSidebarLayout;
37
+ /**
38
+ * How wide the content runs, in any `layout`: `contained` centres it at
39
+ * the contained width (1120px here, or `--ds-shell-contained-width` set
40
+ * on the layout); `full` runs it the whole width the mode leaves it. An
41
+ * app's working column, so it takes none of SiteLayout's site-scale
42
+ * `containedWidth` steps. `inset` no longer forces full width, as it did
43
+ * up to 1.32: pass `width="full"` for that edge-to-edge inset.
44
+ * @default 'contained'
45
+ */
46
+ width?: 'contained' | 'full';
37
47
  /**
38
48
  * Colour scheme: 'dark' pins the layout to the dark theme (the historical
39
49
  * behaviour and the default); 'inherit' drops the pin so the layout
@@ -18,6 +18,7 @@ const AppLayout = React.forwardRef(
18
18
  logo,
19
19
  children,
20
20
  layout = "flush",
21
+ width = "contained",
21
22
  theme = "dark",
22
23
  linkComponent,
23
24
  className = "",
@@ -52,6 +53,7 @@ const AppLayout = React.forwardRef(
52
53
  className: classes,
53
54
  ...theme === "dark" ? { "data-theme": "dark" } : {},
54
55
  "data-ds-shell": layout,
56
+ "data-ds-width": width,
55
57
  children: [
56
58
  /* @__PURE__ */ jsx(
57
59
  AppSidebar,
@@ -157,3 +157,49 @@
157
157
  min-height: 0;
158
158
  border: none;
159
159
  }
160
+
161
+ /* ============================================
162
+ INLINE (layout="inline")
163
+ A live example in the flow of a page: its own card on the
164
+ container fill, sized by what it shows. The preview is a stage
165
+ with the content centred and room around it; the code view is
166
+ the CodeBlock flush against the card, its own border dropped so
167
+ the two edges never double.
168
+ ============================================ */
169
+
170
+ .ds-artifact-panel--inline {
171
+ height: auto;
172
+ border: var(--border-025) solid var(--color-bg-container-border);
173
+ border-radius: var(--radius-300);
174
+ background-color: var(--color-bg-container-primary);
175
+ overflow: hidden;
176
+ }
177
+
178
+ .ds-artifact-panel--inline .ds-artifact-panel__header {
179
+ border-block-end: var(--border-025) solid var(--color-bg-container-border);
180
+ }
181
+
182
+ .ds-artifact-panel--inline .ds-artifact-panel__content {
183
+ display: flex;
184
+ flex-wrap: wrap;
185
+ align-items: center;
186
+ justify-content: center;
187
+ gap: var(--gap-400);
188
+ min-height: var(--ds-artifact-panel-stage-height, calc(6 * var(--control-height-default)));
189
+ padding: var(--padding-1000) var(--padding-500);
190
+ box-sizing: border-box;
191
+ }
192
+
193
+ .ds-artifact-panel--inline .ds-artifact-panel__code {
194
+ padding: 0;
195
+ max-height: var(--ds-artifact-panel-code-height, calc(12 * var(--control-height-default)));
196
+ }
197
+
198
+ .ds-artifact-panel--inline .ds-code-block {
199
+ border: none;
200
+ border-radius: 0;
201
+ }
202
+
203
+ .ds-artifact-panel--inline .ds-artifact-panel__frame {
204
+ min-height: var(--ds-artifact-panel-stage-height, calc(6 * var(--control-height-default)));
205
+ }
@@ -1,11 +1,21 @@
1
1
  import { default as React } from 'react';
2
- import { CodeBlockProps } from '../CodeBlock/CodeBlock';
2
+ import { CodeBlockProps, CodeLine } from '../CodeBlock/CodeBlock';
3
3
  /** Which face of the artifact is on stage. */
4
4
  export type ArtifactPanelView = 'preview' | 'code';
5
5
  /** Props owned by ArtifactPanel itself — everything else falls through to the root `<section>`. */
6
6
  type ArtifactPanelOwnProps = {
7
- /** The artifact's name, shown in the header and used as the panel's accessible name. Collides with the native `title` tooltip attribute on purpose: a panel has a heading, not a tooltip. */
8
- title: React.ReactNode;
7
+ /** The artifact's name, shown in the header and used as the panel's accessible name. Collides with the native `title` tooltip attribute on purpose: a panel has a heading, not a tooltip. Required for the `panel` layout; an `inline` example may leave it out, and is then named by `viewLabel`. */
8
+ title?: React.ReactNode;
9
+ /**
10
+ * Where it sits. `panel` (the default) fills the box a host gives it,
11
+ * beside a conversation, and the host paints the card. `inline` is a
12
+ * self-contained frame in the flow of a page, sized by its content: its
13
+ * own card, a centred preview stage, and the source a switch away, the
14
+ * live example of a component's documentation.
15
+ */
16
+ layout?: 'panel' | 'inline';
17
+ /** The source highlighted, as `highlight()` from `rift-ds/code/highlight` returns it, passed to the code view's CodeBlock. Offers the Code view on its own; `code`, when also given, is the text the copy button copies. */
18
+ lines?: CodeLine[];
9
19
  /** A quiet line beside the name: what kind of thing this is, or which version. */
10
20
  meta?: React.ReactNode;
11
21
  /** Leading mark in the header — Material Symbol name (string) or custom element (ReactNode). */
@@ -42,7 +52,7 @@ type ArtifactPanelOwnProps = {
42
52
  previewLabel?: string;
43
53
  /** Label for the code segment of the view switch. */
44
54
  codeLabel?: string;
45
- /** Accessible name for the view switch. */
55
+ /** Accessible name for the view switch, and for the panel itself when `title` is left out (an untitled `inline` example). */
46
56
  viewLabel?: string;
47
57
  /** Accessible name for the expand toggle while the panel is at its resting size. */
48
58
  expandLabel?: string;