@veluai/velu 0.1.13 → 0.1.14

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 +80 -80
  2. package/dist/cli.js +18 -18
  3. package/package.json +3 -2
  4. package/runtime/velu-ui/components/Accordion.jsx +64 -64
  5. package/runtime/velu-ui/components/ApiClient.jsx +121 -121
  6. package/runtime/velu-ui/components/ApiField.jsx +87 -87
  7. package/runtime/velu-ui/components/ApiPath.jsx +63 -63
  8. package/runtime/velu-ui/components/ApiSidebar.jsx +122 -122
  9. package/runtime/velu-ui/components/AskBar.jsx +71 -71
  10. package/runtime/velu-ui/components/Callout.jsx +114 -114
  11. package/runtime/velu-ui/components/Card.jsx +131 -131
  12. package/runtime/velu-ui/components/Chatbot.jsx +596 -596
  13. package/runtime/velu-ui/components/CodeBlock.jsx +375 -375
  14. package/runtime/velu-ui/components/Columns.jsx +56 -56
  15. package/runtime/velu-ui/components/ErrorCard.jsx +138 -138
  16. package/runtime/velu-ui/components/Field.jsx +81 -81
  17. package/runtime/velu-ui/components/Image.jsx +163 -163
  18. package/runtime/velu-ui/components/MethodBadge.jsx +31 -31
  19. package/runtime/velu-ui/components/NavSelect.jsx +108 -108
  20. package/runtime/velu-ui/components/PageFeedback.jsx +219 -219
  21. package/runtime/velu-ui/components/PageFooter.jsx +213 -213
  22. package/runtime/velu-ui/components/PageHeader.jsx +414 -414
  23. package/runtime/velu-ui/components/PageNav.jsx +77 -77
  24. package/runtime/velu-ui/components/PoweredBy.jsx +51 -51
  25. package/runtime/velu-ui/components/Prompt.jsx +115 -115
  26. package/runtime/velu-ui/components/Search.jsx +411 -366
  27. package/runtime/velu-ui/components/Sidebar.jsx +191 -191
  28. package/runtime/velu-ui/components/Steps.jsx +65 -65
  29. package/runtime/velu-ui/components/ThemeToggle.jsx +48 -48
  30. package/runtime/velu-ui/components/Toc.jsx +537 -537
  31. package/runtime/velu-ui/components/TocBar.jsx +195 -195
  32. package/runtime/velu-ui/components/Tree.jsx +87 -87
  33. package/runtime/velu-ui/components/TryItBar.jsx +90 -90
  34. package/runtime/velu-ui/components/accordion.css +92 -92
  35. package/runtime/velu-ui/components/api.css +479 -479
  36. package/runtime/velu-ui/components/ask-bar.css +94 -94
  37. package/runtime/velu-ui/components/card.css +105 -105
  38. package/runtime/velu-ui/components/chatbot.css +617 -617
  39. package/runtime/velu-ui/components/code-block.css +263 -263
  40. package/runtime/velu-ui/components/docs-layout.css +784 -775
  41. package/runtime/velu-ui/components/field.css +82 -82
  42. package/runtime/velu-ui/components/image.css +237 -237
  43. package/runtime/velu-ui/components/nav-select.css +157 -157
  44. package/runtime/velu-ui/components/page-feedback.css +241 -241
  45. package/runtime/velu-ui/components/page-footer.css +130 -130
  46. package/runtime/velu-ui/components/page-header.css +520 -520
  47. package/runtime/velu-ui/components/page-nav.css +50 -50
  48. package/runtime/velu-ui/components/powered-by.css +66 -66
  49. package/runtime/velu-ui/components/prompt.css +99 -99
  50. package/runtime/velu-ui/components/search.css +307 -307
  51. package/runtime/velu-ui/components/sidebar.css +144 -144
  52. package/runtime/velu-ui/components/steps.css +77 -77
  53. package/runtime/velu-ui/components/theme-toggle.css +101 -101
  54. package/runtime/velu-ui/components/toc-bar.css +234 -234
  55. package/runtime/velu-ui/components/tree.css +49 -49
  56. package/runtime/velu-ui/index.js +46 -46
  57. package/runtime/velu-ui/lib/component-schemas.js +100 -100
  58. package/runtime/velu-ui/lib/copyText.js +64 -64
  59. package/runtime/velu-ui/lib/lang-icons.jsx +147 -147
  60. package/runtime/velu-ui/lib/prism-langs.js +957 -957
  61. package/runtime/velu-ui/lib/prism-loader.js +74 -74
  62. package/runtime/velu-ui/lib/resolveIcon.jsx +29 -29
  63. package/runtime/velu-ui/lib/scrollIntoNearestView.js +66 -66
  64. package/runtime/velu-ui/mdx-components.jsx +105 -105
  65. package/runtime/velu-ui/primitives/Cluster.jsx +49 -49
  66. package/runtime/velu-ui/primitives/Stack.jsx +63 -63
  67. package/runtime/velu-ui/primitives/Switcher.jsx +57 -57
  68. package/runtime/velu-ui/primitives/stack.css +3 -3
  69. package/runtime/velu-ui/primitives/switcher.css +25 -25
  70. package/runtime/velu-ui/styles.css +43 -43
  71. package/runtime/velu-ui/tokens.css +4 -4
  72. package/schema/velu.schema.json +167 -167
  73. package/src/lib/extract-mdx-error.js +170 -170
  74. package/src/lib/issues.js +159 -159
  75. package/src/lib/known-components.js +34 -34
  76. package/src/navigation.js +434 -434
  77. package/src/runtime/App.jsx +1490 -1476
  78. package/src/runtime/ErrorBoundary.jsx +54 -54
  79. package/src/runtime/client-entry.jsx +22 -22
  80. package/src/runtime/server-entry.jsx +16 -16
  81. package/src/template.html +48 -48
  82. package/templates/starter/ai-tools/claude-code.mdx +26 -26
  83. package/templates/starter/ai-tools/cursor.mdx +17 -17
  84. package/templates/starter/api-reference/endpoint/create.mdx +24 -24
  85. package/templates/starter/api-reference/endpoint/get.mdx +27 -27
  86. package/templates/starter/api-reference/introduction.mdx +28 -28
  87. package/templates/starter/development.mdx +19 -19
  88. package/templates/starter/essentials/code.mdx +29 -29
  89. package/templates/starter/essentials/images.mdx +29 -29
  90. package/templates/starter/essentials/markdown.mdx +25 -25
  91. package/templates/starter/essentials/navigation.mdx +39 -39
  92. package/templates/starter/essentials/settings.mdx +30 -30
  93. package/templates/starter/favicon.svg +6 -6
  94. package/templates/starter/index.mdx +31 -31
  95. package/templates/starter/quickstart.mdx +31 -31
  96. package/templates/starter/velu.json +33 -33
@@ -1,74 +1,74 @@
1
- import { Prism } from 'prism-react-renderer';
2
- import { LANG_DEPS, LANG_ALIASES, PRISM_LOADERS } from './prism-langs.js';
3
-
4
- /**
5
- * Lazy prism language loader — fetches grammars on demand based on the
6
- * actual `language` props rendered, never bundles all 297 upfront.
7
- *
8
- * - `Prism` is exposed on globalThis so prismjs/components/*.js files
9
- * (which look it up globally) find it when they register grammars.
10
- * - `ensureLang(id)` walks the LANG_DEPS map to load every prerequisite
11
- * in correct order before the target, then resolves once everything is
12
- * registered. Subsequent calls for the same id share the cached promise.
13
- * - Aliases (e.g. `rb` → `ruby`) are resolved up front via LANG_ALIASES.
14
- * - `hasLang(id)` is a sync check used by render to gate highlighting:
15
- * true once `Prism.languages[id]` exists OR the bundled fallback covers
16
- * it. The CodeBlock kicks off ensureLang in an effect, then re-renders
17
- * once `hasLang` flips true.
18
- */
19
-
20
- if (typeof globalThis !== 'undefined' && !globalThis.Prism) {
21
- globalThis.Prism = Prism;
22
- } else if (typeof window !== 'undefined' && !window.Prism) {
23
- window.Prism = Prism;
24
- }
25
-
26
- const loadPromises = new Map();
27
-
28
- export function resolveLang(idOrAlias) {
29
- if (!idOrAlias) return null;
30
- if (LANG_ALIASES[idOrAlias]) return LANG_ALIASES[idOrAlias];
31
- return idOrAlias;
32
- }
33
-
34
- export function hasLang(id) {
35
- if (!id) return true;
36
- const canonical = resolveLang(id);
37
- return Boolean(Prism.languages[canonical]);
38
- }
39
-
40
- async function loadOne(id) {
41
- const loader = PRISM_LOADERS[id];
42
- if (!loader) return;
43
- try {
44
- await loader();
45
- } catch (e) {
46
- console.warn(`[velu-ui] failed to load prism lang: ${id}`, e?.message ?? e);
47
- }
48
- }
49
-
50
- export function ensureLang(idOrAlias) {
51
- const id = resolveLang(idOrAlias);
52
- if (!id) return Promise.resolve();
53
- if (Prism.languages[id]) return Promise.resolve();
54
- let p = loadPromises.get(id);
55
- if (p) return p;
56
-
57
- p = (async () => {
58
- // Load all dependencies first (recursive, sequential at each level).
59
- const deps = LANG_DEPS[id] ?? [];
60
- for (const dep of deps) {
61
- const depId = resolveLang(dep);
62
- if (depId && !Prism.languages[depId]) {
63
- await ensureLang(depId);
64
- }
65
- }
66
- // Load the target language itself.
67
- if (!Prism.languages[id]) {
68
- await loadOne(id);
69
- }
70
- })();
71
-
72
- loadPromises.set(id, p);
73
- return p;
74
- }
1
+ import { Prism } from 'prism-react-renderer';
2
+ import { LANG_DEPS, LANG_ALIASES, PRISM_LOADERS } from './prism-langs.js';
3
+
4
+ /**
5
+ * Lazy prism language loader — fetches grammars on demand based on the
6
+ * actual `language` props rendered, never bundles all 297 upfront.
7
+ *
8
+ * - `Prism` is exposed on globalThis so prismjs/components/*.js files
9
+ * (which look it up globally) find it when they register grammars.
10
+ * - `ensureLang(id)` walks the LANG_DEPS map to load every prerequisite
11
+ * in correct order before the target, then resolves once everything is
12
+ * registered. Subsequent calls for the same id share the cached promise.
13
+ * - Aliases (e.g. `rb` → `ruby`) are resolved up front via LANG_ALIASES.
14
+ * - `hasLang(id)` is a sync check used by render to gate highlighting:
15
+ * true once `Prism.languages[id]` exists OR the bundled fallback covers
16
+ * it. The CodeBlock kicks off ensureLang in an effect, then re-renders
17
+ * once `hasLang` flips true.
18
+ */
19
+
20
+ if (typeof globalThis !== 'undefined' && !globalThis.Prism) {
21
+ globalThis.Prism = Prism;
22
+ } else if (typeof window !== 'undefined' && !window.Prism) {
23
+ window.Prism = Prism;
24
+ }
25
+
26
+ const loadPromises = new Map();
27
+
28
+ export function resolveLang(idOrAlias) {
29
+ if (!idOrAlias) return null;
30
+ if (LANG_ALIASES[idOrAlias]) return LANG_ALIASES[idOrAlias];
31
+ return idOrAlias;
32
+ }
33
+
34
+ export function hasLang(id) {
35
+ if (!id) return true;
36
+ const canonical = resolveLang(id);
37
+ return Boolean(Prism.languages[canonical]);
38
+ }
39
+
40
+ async function loadOne(id) {
41
+ const loader = PRISM_LOADERS[id];
42
+ if (!loader) return;
43
+ try {
44
+ await loader();
45
+ } catch (e) {
46
+ console.warn(`[velu-ui] failed to load prism lang: ${id}`, e?.message ?? e);
47
+ }
48
+ }
49
+
50
+ export function ensureLang(idOrAlias) {
51
+ const id = resolveLang(idOrAlias);
52
+ if (!id) return Promise.resolve();
53
+ if (Prism.languages[id]) return Promise.resolve();
54
+ let p = loadPromises.get(id);
55
+ if (p) return p;
56
+
57
+ p = (async () => {
58
+ // Load all dependencies first (recursive, sequential at each level).
59
+ const deps = LANG_DEPS[id] ?? [];
60
+ for (const dep of deps) {
61
+ const depId = resolveLang(dep);
62
+ if (depId && !Prism.languages[depId]) {
63
+ await ensureLang(depId);
64
+ }
65
+ }
66
+ // Load the target language itself.
67
+ if (!Prism.languages[id]) {
68
+ await loadOne(id);
69
+ }
70
+ })();
71
+
72
+ loadPromises.set(id, p);
73
+ return p;
74
+ }
@@ -1,29 +1,29 @@
1
- import React from 'react';
2
- import { icons as lucideIcons } from 'lucide-react';
3
-
4
- /**
5
- * Resolve an icon prop to a renderable node — shared by Callout, Sidebar, etc.
6
- *
7
- * lucide convention: an icon's id is kebab-case; its component / `icons`-map
8
- * key is the PascalCase form. So "triangle-alert" → "TriangleAlert" →
9
- * lucideIcons.TriangleAlert.
10
- *
11
- * - string → resolved as a lucide id (content-driven; serializable)
12
- * - node → returned as-is (power users / custom elements)
13
- * - nullish or unknown id → null
14
- *
15
- * `iconProps` is spread onto the resolved lucide component (e.g. size,
16
- * strokeWidth). Callers that style the icon via a CSS wrapper (Sidebar) can
17
- * omit it; callers that size inline (Callout) pass it.
18
- */
19
- export default function resolveIcon(icon, iconProps = {}) {
20
- if (icon == null) return null;
21
- if (typeof icon !== 'string') return icon;
22
- const key = icon
23
- .split(/[-_\s]+/)
24
- .filter(Boolean)
25
- .map((s) => s.charAt(0).toUpperCase() + s.slice(1))
26
- .join('');
27
- const Cmp = lucideIcons[key];
28
- return Cmp ? <Cmp {...iconProps} /> : null;
29
- }
1
+ import React from 'react';
2
+ import { icons as lucideIcons } from 'lucide-react';
3
+
4
+ /**
5
+ * Resolve an icon prop to a renderable node — shared by Callout, Sidebar, etc.
6
+ *
7
+ * lucide convention: an icon's id is kebab-case; its component / `icons`-map
8
+ * key is the PascalCase form. So "triangle-alert" → "TriangleAlert" →
9
+ * lucideIcons.TriangleAlert.
10
+ *
11
+ * - string → resolved as a lucide id (content-driven; serializable)
12
+ * - node → returned as-is (power users / custom elements)
13
+ * - nullish or unknown id → null
14
+ *
15
+ * `iconProps` is spread onto the resolved lucide component (e.g. size,
16
+ * strokeWidth). Callers that style the icon via a CSS wrapper (Sidebar) can
17
+ * omit it; callers that size inline (Callout) pass it.
18
+ */
19
+ export default function resolveIcon(icon, iconProps = {}) {
20
+ if (icon == null) return null;
21
+ if (typeof icon !== 'string') return icon;
22
+ const key = icon
23
+ .split(/[-_\s]+/)
24
+ .filter(Boolean)
25
+ .map((s) => s.charAt(0).toUpperCase() + s.slice(1))
26
+ .join('');
27
+ const Cmp = lucideIcons[key];
28
+ return Cmp ? <Cmp {...iconProps} /> : null;
29
+ }
@@ -1,66 +1,66 @@
1
- /**
2
- * scrollIntoNearestView — programmatic "scroll so this element is visible"
3
- * that reliably honours `scroll-padding-top` / `scroll-padding-bottom` on
4
- * the nearest scrollable ancestor.
5
- *
6
- * Why not `el.scrollIntoView({ block: 'nearest' })`?
7
- * Both Chrome and Firefox implement that opt sporadically with respect
8
- * to scroll-padding-* — sometimes treating the full scrollport as the
9
- * target instead of the scroll-padded inset. That matters here because
10
- * docs sidebars + TOC live behind a footer that visually eclipses their
11
- * bottoms; we use `scroll-padding-bottom` to mark that band as off-limits.
12
- * Computing the delta manually guarantees we always pull the element
13
- * above the footer's eclipsed band, on every engine.
14
- *
15
- * The optional `padBottom` (and `padTop`) override the values read from
16
- * the parent's computed style. This is needed when the visible region's
17
- * bottom is driven by a *live* DOM measurement (e.g. a fixed/sticky
18
- * footer's getBoundingClientRect) — that value tracks the user's actual
19
- * scroll position synchronously, whereas CSS scroll-padding-* driven by
20
- * React state lags behind committed renders and can leave the active
21
- * item flush against the footer on fast scrolls.
22
- *
23
- * Behaviour:
24
- * - finds the nearest ancestor with `overflow-y: auto | scroll`
25
- * - does nothing if `el` is already inside that ancestor's
26
- * (effective) scroll-padded visible region — no jitter when the
27
- * active item is already on-screen
28
- * - otherwise scrolls the ancestor by the minimum delta (matching the
29
- * `block: 'nearest'` contract)
30
- *
31
- * @param {HTMLElement} el target element
32
- * @param {{ padTop?: number, padBottom?: number }} [opts]
33
- */
34
- export default function scrollIntoNearestView(el, opts = {}) {
35
- if (!el) return;
36
- let parent = el.parentElement;
37
- while (parent && parent !== document.body) {
38
- const overflowY = getComputedStyle(parent).overflowY;
39
- if (overflowY === 'auto' || overflowY === 'scroll') break;
40
- parent = parent.parentElement;
41
- }
42
- if (!parent || parent === document.body) return;
43
-
44
- const elRect = el.getBoundingClientRect();
45
- const parentRect = parent.getBoundingClientRect();
46
- const cs = getComputedStyle(parent);
47
- const padTop = opts.padTop ?? (parseFloat(cs.scrollPaddingTop) || 0);
48
- const padBottom =
49
- opts.padBottom ?? (parseFloat(cs.scrollPaddingBottom) || 0);
50
-
51
- const visibleTop = parentRect.top + padTop;
52
- const visibleBottom = parentRect.bottom - padBottom;
53
-
54
- let delta = 0;
55
- if (elRect.top < visibleTop) delta = elRect.top - visibleTop;
56
- else if (elRect.bottom > visibleBottom) delta = elRect.bottom - visibleBottom;
57
- if (delta === 0) return;
58
-
59
- // Direct `scrollTop` assignment (not scrollBy/scrollTo with options):
60
- // - universally supported (no behavior:'instant' compat concerns),
61
- // - synchronous,
62
- // - can't be cancelled by a subsequent scroll event,
63
- // which matters because we're often called many times in quick
64
- // succession from scroll-spy updates while the user is mid-scroll.
65
- parent.scrollTop = parent.scrollTop + delta;
66
- }
1
+ /**
2
+ * scrollIntoNearestView — programmatic "scroll so this element is visible"
3
+ * that reliably honours `scroll-padding-top` / `scroll-padding-bottom` on
4
+ * the nearest scrollable ancestor.
5
+ *
6
+ * Why not `el.scrollIntoView({ block: 'nearest' })`?
7
+ * Both Chrome and Firefox implement that opt sporadically with respect
8
+ * to scroll-padding-* — sometimes treating the full scrollport as the
9
+ * target instead of the scroll-padded inset. That matters here because
10
+ * docs sidebars + TOC live behind a footer that visually eclipses their
11
+ * bottoms; we use `scroll-padding-bottom` to mark that band as off-limits.
12
+ * Computing the delta manually guarantees we always pull the element
13
+ * above the footer's eclipsed band, on every engine.
14
+ *
15
+ * The optional `padBottom` (and `padTop`) override the values read from
16
+ * the parent's computed style. This is needed when the visible region's
17
+ * bottom is driven by a *live* DOM measurement (e.g. a fixed/sticky
18
+ * footer's getBoundingClientRect) — that value tracks the user's actual
19
+ * scroll position synchronously, whereas CSS scroll-padding-* driven by
20
+ * React state lags behind committed renders and can leave the active
21
+ * item flush against the footer on fast scrolls.
22
+ *
23
+ * Behaviour:
24
+ * - finds the nearest ancestor with `overflow-y: auto | scroll`
25
+ * - does nothing if `el` is already inside that ancestor's
26
+ * (effective) scroll-padded visible region — no jitter when the
27
+ * active item is already on-screen
28
+ * - otherwise scrolls the ancestor by the minimum delta (matching the
29
+ * `block: 'nearest'` contract)
30
+ *
31
+ * @param {HTMLElement} el target element
32
+ * @param {{ padTop?: number, padBottom?: number }} [opts]
33
+ */
34
+ export default function scrollIntoNearestView(el, opts = {}) {
35
+ if (!el) return;
36
+ let parent = el.parentElement;
37
+ while (parent && parent !== document.body) {
38
+ const overflowY = getComputedStyle(parent).overflowY;
39
+ if (overflowY === 'auto' || overflowY === 'scroll') break;
40
+ parent = parent.parentElement;
41
+ }
42
+ if (!parent || parent === document.body) return;
43
+
44
+ const elRect = el.getBoundingClientRect();
45
+ const parentRect = parent.getBoundingClientRect();
46
+ const cs = getComputedStyle(parent);
47
+ const padTop = opts.padTop ?? (parseFloat(cs.scrollPaddingTop) || 0);
48
+ const padBottom =
49
+ opts.padBottom ?? (parseFloat(cs.scrollPaddingBottom) || 0);
50
+
51
+ const visibleTop = parentRect.top + padTop;
52
+ const visibleBottom = parentRect.bottom - padBottom;
53
+
54
+ let delta = 0;
55
+ if (elRect.top < visibleTop) delta = elRect.top - visibleTop;
56
+ else if (elRect.bottom > visibleBottom) delta = elRect.bottom - visibleBottom;
57
+ if (delta === 0) return;
58
+
59
+ // Direct `scrollTop` assignment (not scrollBy/scrollTo with options):
60
+ // - universally supported (no behavior:'instant' compat concerns),
61
+ // - synchronous,
62
+ // - can't be cancelled by a subsequent scroll event,
63
+ // which matters because we're often called many times in quick
64
+ // succession from scroll-spy updates while the user is mid-scroll.
65
+ parent.scrollTop = parent.scrollTop + delta;
66
+ }
@@ -1,105 +1,105 @@
1
- import React from 'react';
2
- import Callout from './components/Callout.jsx';
3
- import Card, { CardGroup } from './components/Card.jsx';
4
- import Accordion, { AccordionGroup } from './components/Accordion.jsx';
5
- import Columns from './components/Columns.jsx';
6
- import Field from './components/Field.jsx';
7
- import Prompt from './components/Prompt.jsx';
8
- import Steps, { Step } from './components/Steps.jsx';
9
- import Tree, { Folder, File } from './components/Tree.jsx';
10
- import Image from './components/Image.jsx';
11
- import CodeBlock, { CodeGroup } from './components/CodeBlock.jsx';
12
- import MethodBadge from './components/MethodBadge.jsx';
13
- import ApiPath from './components/ApiPath.jsx';
14
- import TryItBar from './components/TryItBar.jsx';
15
- import ApiField from './components/ApiField.jsx';
16
- import ApiClient from './components/ApiClient.jsx';
17
- import ApiSidebar from './components/ApiSidebar.jsx';
18
- import { validateProps } from './lib/component-schemas.js';
19
-
20
- /**
21
- * defaultMdxComponents — the registry the MDXProvider consumes.
22
- *
23
- * Two kinds of entries:
24
- *
25
- * 1. Lowercase keys ('pre', 'h1', …) override the HTML tags that
26
- * Markdown produces. We use these to upgrade plain ``` fenced
27
- * code blocks into our CodeBlock component, etc.
28
- *
29
- * 2. Capitalised keys ('Callout', 'Card', …) match the exact tag
30
- * names authors write in their .mdx, e.g. `<Callout type="warn">`.
31
- * MDX looks up the name in this map and renders our component
32
- * instead of treating it as an unknown HTML element.
33
- *
34
- * Tag-name → component is the only contract here. SSR-safe by
35
- * construction: identical map on server + client → identical render.
36
- */
37
-
38
- /* `pre > code` is how Markdown renders ``` blocks. We pull the
39
- language out of the code-element's className ("language-js" → "js")
40
- and forward children verbatim to CodeBlock. */
41
- function PreOverride({ children }) {
42
- const child = React.Children.only(children);
43
- const className = child?.props?.className || '';
44
- const m = /language-(\S+)/.exec(className);
45
- const language = m ? m[1] : undefined;
46
- const code =
47
- typeof child?.props?.children === 'string'
48
- ? child.props.children.replace(/\n$/, '')
49
- : child?.props?.children;
50
- return (
51
- <CodeBlock language={language}>
52
- {code}
53
- </CodeBlock>
54
- );
55
- }
56
-
57
- /* Wrap a component so its constrained options (see component-schemas.js)
58
- are validated at render time. An invalid option throws a marked error
59
- (`err.veluIssue`) that the dev server turns into a friendly card on the
60
- page AND a clean block in the terminal — the same surface as an unknown
61
- component. Components without a schema pass straight through. */
62
- function checked(name, Comp) {
63
- function Checked(props) {
64
- const issue = validateProps(name, props);
65
- if (issue) {
66
- const err = new Error(issue.title);
67
- err.veluIssue = issue;
68
- throw err;
69
- }
70
- return <Comp {...props} />;
71
- }
72
- Checked.displayName = `Checked(${name})`;
73
- return Checked;
74
- }
75
-
76
- export const defaultMdxComponents = {
77
- /* HTML-tag overrides (lowercase keys). */
78
- pre: PreOverride,
79
-
80
- /* Authored component tags (capitalised keys). */
81
- Callout: checked('Callout', Callout),
82
- Card,
83
- CardGroup,
84
- Accordion,
85
- AccordionGroup,
86
- Columns,
87
- Field,
88
- Prompt,
89
- Steps,
90
- Step,
91
- Tree,
92
- Folder,
93
- File,
94
- Image: checked('Image', Image),
95
- CodeBlock,
96
- CodeGroup,
97
- MethodBadge: checked('MethodBadge', MethodBadge),
98
- ApiPath: checked('ApiPath', ApiPath),
99
- TryItBar,
100
- ApiField,
101
- ApiClient,
102
- ApiSidebar,
103
- };
104
-
105
- export default defaultMdxComponents;
1
+ import React from 'react';
2
+ import Callout from './components/Callout.jsx';
3
+ import Card, { CardGroup } from './components/Card.jsx';
4
+ import Accordion, { AccordionGroup } from './components/Accordion.jsx';
5
+ import Columns from './components/Columns.jsx';
6
+ import Field from './components/Field.jsx';
7
+ import Prompt from './components/Prompt.jsx';
8
+ import Steps, { Step } from './components/Steps.jsx';
9
+ import Tree, { Folder, File } from './components/Tree.jsx';
10
+ import Image from './components/Image.jsx';
11
+ import CodeBlock, { CodeGroup } from './components/CodeBlock.jsx';
12
+ import MethodBadge from './components/MethodBadge.jsx';
13
+ import ApiPath from './components/ApiPath.jsx';
14
+ import TryItBar from './components/TryItBar.jsx';
15
+ import ApiField from './components/ApiField.jsx';
16
+ import ApiClient from './components/ApiClient.jsx';
17
+ import ApiSidebar from './components/ApiSidebar.jsx';
18
+ import { validateProps } from './lib/component-schemas.js';
19
+
20
+ /**
21
+ * defaultMdxComponents — the registry the MDXProvider consumes.
22
+ *
23
+ * Two kinds of entries:
24
+ *
25
+ * 1. Lowercase keys ('pre', 'h1', …) override the HTML tags that
26
+ * Markdown produces. We use these to upgrade plain ``` fenced
27
+ * code blocks into our CodeBlock component, etc.
28
+ *
29
+ * 2. Capitalised keys ('Callout', 'Card', …) match the exact tag
30
+ * names authors write in their .mdx, e.g. `<Callout type="warn">`.
31
+ * MDX looks up the name in this map and renders our component
32
+ * instead of treating it as an unknown HTML element.
33
+ *
34
+ * Tag-name → component is the only contract here. SSR-safe by
35
+ * construction: identical map on server + client → identical render.
36
+ */
37
+
38
+ /* `pre > code` is how Markdown renders ``` blocks. We pull the
39
+ language out of the code-element's className ("language-js" → "js")
40
+ and forward children verbatim to CodeBlock. */
41
+ function PreOverride({ children }) {
42
+ const child = React.Children.only(children);
43
+ const className = child?.props?.className || '';
44
+ const m = /language-(\S+)/.exec(className);
45
+ const language = m ? m[1] : undefined;
46
+ const code =
47
+ typeof child?.props?.children === 'string'
48
+ ? child.props.children.replace(/\n$/, '')
49
+ : child?.props?.children;
50
+ return (
51
+ <CodeBlock language={language}>
52
+ {code}
53
+ </CodeBlock>
54
+ );
55
+ }
56
+
57
+ /* Wrap a component so its constrained options (see component-schemas.js)
58
+ are validated at render time. An invalid option throws a marked error
59
+ (`err.veluIssue`) that the dev server turns into a friendly card on the
60
+ page AND a clean block in the terminal — the same surface as an unknown
61
+ component. Components without a schema pass straight through. */
62
+ function checked(name, Comp) {
63
+ function Checked(props) {
64
+ const issue = validateProps(name, props);
65
+ if (issue) {
66
+ const err = new Error(issue.title);
67
+ err.veluIssue = issue;
68
+ throw err;
69
+ }
70
+ return <Comp {...props} />;
71
+ }
72
+ Checked.displayName = `Checked(${name})`;
73
+ return Checked;
74
+ }
75
+
76
+ export const defaultMdxComponents = {
77
+ /* HTML-tag overrides (lowercase keys). */
78
+ pre: PreOverride,
79
+
80
+ /* Authored component tags (capitalised keys). */
81
+ Callout: checked('Callout', Callout),
82
+ Card,
83
+ CardGroup,
84
+ Accordion,
85
+ AccordionGroup,
86
+ Columns,
87
+ Field,
88
+ Prompt,
89
+ Steps,
90
+ Step,
91
+ Tree,
92
+ Folder,
93
+ File,
94
+ Image: checked('Image', Image),
95
+ CodeBlock,
96
+ CodeGroup,
97
+ MethodBadge: checked('MethodBadge', MethodBadge),
98
+ ApiPath: checked('ApiPath', ApiPath),
99
+ TryItBar,
100
+ ApiField,
101
+ ApiClient,
102
+ ApiSidebar,
103
+ };
104
+
105
+ export default defaultMdxComponents;
@@ -1,49 +1,49 @@
1
- import React from 'react';
2
-
3
- /**
4
- * Cluster — Every Layout primitive. Inline group that wraps onto
5
- * multiple lines when it runs out of horizontal room. Use for chips,
6
- * tags, action button rows, nav links, badge groups — any horizontal
7
- * row of inline-ish items that should break gracefully.
8
- *
9
- * Like Stack, this is pure inline styles (no CSS file needed since
10
- * there's no `> *` selector) — React-native, SSR-safe, tokenized.
11
- * Mirrors the Every Layout custom element but as React with the same
12
- * three knobs.
13
- *
14
- * - `space` gap between items (default --s1)
15
- * - `justify` justify-content (default flex-start)
16
- * - `align` align-items (default flex-start)
17
- * - `as` element tag (default 'div')
18
- *
19
- * @param {object} props
20
- * @param {React.ElementType} [props.as='div']
21
- * @param {string} [props.space='var(--s1)']
22
- * @param {string} [props.justify='flex-start']
23
- * @param {string} [props.align='flex-start']
24
- */
25
- export default function Cluster({
26
- as: Tag = 'div',
27
- space = 'var(--s1)',
28
- justify = 'flex-start',
29
- align = 'flex-start',
30
- style,
31
- children,
32
- ...rest
33
- }) {
34
- return (
35
- <Tag
36
- style={{
37
- display: 'flex',
38
- flexWrap: 'wrap',
39
- justifyContent: justify,
40
- alignItems: align,
41
- gap: space,
42
- ...style,
43
- }}
44
- {...rest}
45
- >
46
- {children}
47
- </Tag>
48
- );
49
- }
1
+ import React from 'react';
2
+
3
+ /**
4
+ * Cluster — Every Layout primitive. Inline group that wraps onto
5
+ * multiple lines when it runs out of horizontal room. Use for chips,
6
+ * tags, action button rows, nav links, badge groups — any horizontal
7
+ * row of inline-ish items that should break gracefully.
8
+ *
9
+ * Like Stack, this is pure inline styles (no CSS file needed since
10
+ * there's no `> *` selector) — React-native, SSR-safe, tokenized.
11
+ * Mirrors the Every Layout custom element but as React with the same
12
+ * three knobs.
13
+ *
14
+ * - `space` gap between items (default --s1)
15
+ * - `justify` justify-content (default flex-start)
16
+ * - `align` align-items (default flex-start)
17
+ * - `as` element tag (default 'div')
18
+ *
19
+ * @param {object} props
20
+ * @param {React.ElementType} [props.as='div']
21
+ * @param {string} [props.space='var(--s1)']
22
+ * @param {string} [props.justify='flex-start']
23
+ * @param {string} [props.align='flex-start']
24
+ */
25
+ export default function Cluster({
26
+ as: Tag = 'div',
27
+ space = 'var(--s1)',
28
+ justify = 'flex-start',
29
+ align = 'flex-start',
30
+ style,
31
+ children,
32
+ ...rest
33
+ }) {
34
+ return (
35
+ <Tag
36
+ style={{
37
+ display: 'flex',
38
+ flexWrap: 'wrap',
39
+ justifyContent: justify,
40
+ alignItems: align,
41
+ gap: space,
42
+ ...style,
43
+ }}
44
+ {...rest}
45
+ >
46
+ {children}
47
+ </Tag>
48
+ );
49
+ }