@takazudo/zudo-sg 0.3.6 → 0.4.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 (54) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/README.md +2 -2
  3. package/dist/catalog/catalog-thumb.d.ts +19 -0
  4. package/dist/catalog/catalog-thumb.js +11 -0
  5. package/dist/catalog/descriptor-thumb.d.ts +20 -0
  6. package/dist/catalog/descriptor-thumb.js +31 -0
  7. package/dist/catalog/index.d.ts +4 -0
  8. package/dist/catalog/index.js +5 -0
  9. package/dist/code-panel/code-panel.d.ts +8 -1
  10. package/dist/code-panel/code-panel.js +76 -24
  11. package/dist/code-panel/editor-setup.d.ts +2 -0
  12. package/dist/code-panel/editor-setup.js +3 -0
  13. package/dist/code-panel/source-editor.d.ts +3 -1
  14. package/dist/code-panel/source-editor.js +10 -1
  15. package/dist/config/index.d.ts +54 -5
  16. package/dist/config/index.js +72 -12
  17. package/dist/host-paths.d.ts +2 -0
  18. package/dist/host-paths.js +5 -0
  19. package/dist/plugins/routes.d.ts +60 -11
  20. package/dist/plugins/routes.js +135 -23
  21. package/dist/preview/detail-workbench.d.ts +63 -1
  22. package/dist/preview/detail-workbench.js +112 -22
  23. package/dist/preview/index.d.ts +3 -3
  24. package/dist/preview/index.js +7 -1
  25. package/dist/preview/messages.d.ts +34 -5
  26. package/dist/preview/messages.js +34 -6
  27. package/dist/preview/preview-app.js +22 -10
  28. package/dist/preview/variant-frame.d.ts +50 -2
  29. package/dist/preview/variant-frame.js +64 -23
  30. package/dist/registry/catalog.d.ts +64 -0
  31. package/dist/registry/catalog.js +79 -0
  32. package/dist/registry/descriptors.d.ts +46 -0
  33. package/dist/registry/descriptors.js +148 -0
  34. package/dist/registry/index.d.ts +5 -1
  35. package/dist/registry/index.js +7 -1
  36. package/dist/registry/nav-nodes.d.ts +4 -1
  37. package/dist/registry/nav-nodes.js +4 -1
  38. package/dist/registry/registry.d.ts +15 -0
  39. package/dist/registry/registry.js +18 -9
  40. package/dist/safelist.css +1 -1
  41. package/dist/sg-context.d.ts +29 -0
  42. package/dist/sg-routes.d.ts +49 -1
  43. package/dist/sg-routes.js +15 -1
  44. package/dist/shared/tablist-keyboard.d.ts +14 -0
  45. package/dist/shared/tablist-keyboard.js +19 -0
  46. package/package.json +9 -4
  47. package/routes-src/_preview-app.tsx +2 -2
  48. package/routes-src/_registry.ts +31 -6
  49. package/routes-src/components-index.tsx +15 -8
  50. package/routes-src/components-preview.tsx +5 -0
  51. package/routes-src/components-slug.tsx +63 -31
  52. package/routes-src/tokens.tsx +9 -4
  53. package/styles.css +10 -0
  54. package/virtual-modules.d.ts +6 -0
package/CHANGELOG.md CHANGED
@@ -4,6 +4,71 @@ All notable changes to `@takazudo/zudo-sg` are documented in this file.
4
4
 
5
5
  The format is based on Keep a Changelog, and release notes are generated from the changelog MDX pages.
6
6
 
7
+ ## [0.4.0] - 2026-09-27
8
+
9
+ This release lets a non-Preact host adopt the catalog, nav, search, and
10
+ detail-page chrome while keeping full ownership of the preview document, and
11
+ carries two behavior changes to defaults set by earlier releases. It also
12
+ makes the detail page's code panel keyboard- and screen-reader-operable and
13
+ requires the zdtp release that keeps the preview token panel working across
14
+ SPA navigation.
15
+
16
+ ### Features
17
+
18
+ - Add a second registry source, `registry: { mode: "descriptor", module }`:
19
+ plain-data `StoryDescriptor`/`ThumbnailDescriptor` metadata in place of
20
+ `*.stories.tsx` files with `render` functions, validated at build time with
21
+ named, indexed error messages.
22
+ - Add `externalPreview: { url, trailingSlash? }`, a host-served preview
23
+ document that replaces the in-engine `/components/preview` route. Required
24
+ in descriptor mode; optional in module mode.
25
+ - Version the preview iframe postMessage contract as protocol v1 (`v: 1`,
26
+ legacy messages with no `v` still accepted) and publish it as the
27
+ framework-free leaf module `@takazudo/zudo-sg/preview/messages`, so an
28
+ `externalPreview` document can implement it without depending on Preact.
29
+ - Add `routes.componentsPreview: false` and `routes.tokens: false` opt-outs,
30
+ plus an implied `tokens` opt-out in descriptor mode when no token manifest
31
+ is configured.
32
+ - Extend `DetailWorkbench` with host-controlled props (`selection`, `theme`,
33
+ `previewParams`, `sizing`, `toolbar`) so a foreign host can drive the
34
+ detail-page chrome directly instead of only reaching it through the
35
+ engine's own detail route.
36
+ - Make the code panel accessible: the variant tablist is named
37
+ "Source variant", uses a roving tabindex, and moves and activates the
38
+ selection with the arrow keys, Home and End. The source region is a labelled
39
+ tabpanel, and both CodeMirror editors are named (`Source code for {story}: {variant}`,
40
+ `Live CSS for {story}`). `SourceEditor` gains an optional
41
+ `label` prop, and the regions carry stable `data-sg-code-region` hooks.
42
+
43
+ ### Bug Fixes
44
+
45
+ - Raise the `@takazudo/zdtp` peer floor to `^0.8.5`. It picks up the upstream
46
+ fixes for a panel root left empty by an SPA remount and for a fresh mount
47
+ that briefly persisted a closed state, so the preview token panel keeps
48
+ working across host and engine navigation and reloads.
49
+ - Skip preview posts from an opaque origin.
50
+ - Reserve the external preview slug and align tokens-route detection.
51
+ - Keep the code panel's tab selection and tabpanel labelling on the variant
52
+ actually shown when the stored variant no longer matches a tab.
53
+
54
+ ### Breaking Changes
55
+
56
+ - `withZudoSg()`'s `headerTokenTrigger` option now defaults to whether the
57
+ preview token panel is actually wired (`zdtpApplyProxy.tabsModule` set),
58
+ rather than defaulting to `true` unconditionally. A host that never wired
59
+ the apply proxy's tabs module no longer gets a header button that opened
60
+ nothing; setting `headerTokenTrigger: true` explicitly still forces it on
61
+ (with a one-time console warning when the panel isn't wired).
62
+ - A standalone `DetailWorkbench` (driven directly, outside the engine's own
63
+ detail route) now defaults `toolbar.codePanel` and `toolbar.tokenPanel` to
64
+ `false`. The engine's own detail route is unaffected — it opts both back
65
+ in explicitly — but existing direct consumers of `DetailWorkbench` that
66
+ relied on those controls appearing by default must now pass
67
+ `toolbar: { codePanel: true, tokenPanel: true }`.
68
+
69
+ See [Descriptor mode & external preview](/docs/reference/descriptor-mode) for
70
+ the full contract and a minimal framework-free preview-frame example.
71
+
7
72
  ## [0.3.6] - 2026-09-25
8
73
 
9
74
  This release updates the supported zfb toolchain to 2.20.3 so staged
package/README.md CHANGED
@@ -130,11 +130,11 @@ output as drift and never writes it.
130
130
  ## Installation
131
131
 
132
132
  ```sh
133
- pnpm add @takazudo/zudo-sg@latest @takazudo/zfb@^2.20.3 @takazudo/zfb-md-wasm@^2.20.3 @takazudo/zfb-runtime@^2.20.3 @takazudo/zudo-doc@^5.27.0 @takazudo/zdtp@^0.8.2 diff@^8.0.4 katex@^0.16.38 preact@^10.29.8 preact-render-to-string@^6.6.6 tailwindcss@^4.2.0 zod@^4.3.6
133
+ pnpm add @takazudo/zudo-sg@latest @takazudo/zfb@^2.20.3 @takazudo/zfb-md-wasm@^2.20.3 @takazudo/zfb-runtime@^2.20.3 @takazudo/zudo-doc@^5.27.0 @takazudo/zdtp@^0.8.5 diff@^8.0.4 katex@^0.16.38 preact@^10.29.8 preact-render-to-string@^6.6.6 tailwindcss@^4.2.0 zod@^4.3.6
134
134
  ```
135
135
 
136
136
  The engine peers are `@takazudo/zfb ^2.20.3`, `@takazudo/zudo-doc ^5.27.0`,
137
- `@takazudo/zdtp ^0.8.2`, and `preact ^10.29.8`. `@takazudo/zdtp` is required:
137
+ `@takazudo/zdtp ^0.8.5`, and `preact ^10.29.8`. `@takazudo/zdtp` is required:
138
138
  the injected `/tokens` route imports its dashboard at build time. The
139
139
  `@takazudo/zfb-md-wasm`, `@takazudo/zfb-runtime`, `diff`, `katex`, and `zod`
140
140
  entries are prerequisites inherited from zfb/zudo-doc; zudo-doc's published
@@ -0,0 +1,19 @@
1
+ /** @jsxRuntime automatic */
2
+ /** @jsxImportSource preact */
3
+ import type { JSX } from "preact";
4
+ import type { CatalogEntry } from "../registry/catalog.js";
5
+ export interface CatalogThumbProps {
6
+ entry: CatalogEntry;
7
+ /** Site base, forwarded to `DescriptorThumb` to prefix a root-absolute `src`. Ignored for module entries. */
8
+ base?: string;
9
+ }
10
+ /**
11
+ * Catalog tile thumbnail for either registry mode. A module entry renders its
12
+ * story inline through `ComponentThumb`; a descriptor entry renders its
13
+ * `ThumbnailDescriptor` (image, placeholder, or a labelled "missing" note)
14
+ * through `DescriptorThumb`.
15
+ */
16
+ export declare function CatalogThumb({ entry, base }: CatalogThumbProps): JSX.Element;
17
+ export declare namespace CatalogThumb {
18
+ var displayName: string;
19
+ }
@@ -0,0 +1,11 @@
1
+ import { jsx } from "preact/jsx-runtime";
2
+ import { ComponentThumb } from "./component-thumb.js";
3
+ import { DescriptorThumb } from "./descriptor-thumb.js";
4
+ function CatalogThumb({ entry, base }) {
5
+ if (entry.source === "module") return /* @__PURE__ */ jsx(ComponentThumb, { entry: entry.storyEntry });
6
+ return /* @__PURE__ */ jsx(DescriptorThumb, { entry, base });
7
+ }
8
+ CatalogThumb.displayName = "CatalogThumb";
9
+ export {
10
+ CatalogThumb
11
+ };
@@ -0,0 +1,20 @@
1
+ /** @jsxRuntime automatic */
2
+ /** @jsxImportSource preact */
3
+ import type { JSX } from "preact";
4
+ import type { DescriptorCatalogEntry } from "../registry/catalog.js";
5
+ /** Note shown when a descriptor declares no `thumbnail` at all. */
6
+ export declare const DESCRIPTOR_THUMB_MISSING_NOTE = "No thumbnail provided";
7
+ export interface DescriptorThumbProps {
8
+ entry: DescriptorCatalogEntry;
9
+ /** Site base to prefix a root-absolute image `src` with. Defaults to no prefix. */
10
+ base?: string;
11
+ }
12
+ /**
13
+ * One descriptor-mode tile's thumbnail slot. Mirrors `ComponentThumb`'s
14
+ * `aria-hidden` + `inert` wrapper so both registry modes keep decorative
15
+ * snapshots out of the tab order and the accessibility tree the same way.
16
+ */
17
+ export declare function DescriptorThumb({ entry, base }: DescriptorThumbProps): JSX.Element;
18
+ export declare namespace DescriptorThumb {
19
+ var displayName: string;
20
+ }
@@ -0,0 +1,31 @@
1
+ import { jsx } from "preact/jsx-runtime";
2
+ const DESCRIPTOR_THUMB_MISSING_NOTE = "No thumbnail provided";
3
+ function withThumbBase(base, src) {
4
+ if (!src.startsWith("/")) return src;
5
+ return base.replace(/\/+$/, "") + src;
6
+ }
7
+ function DescriptorThumbNote({ note }) {
8
+ return /* @__PURE__ */ jsx("div", { class: "sg-thumb", "data-sg-preview-scope": true, "data-sg-thumb-note": true, "aria-hidden": "true", inert: true, children: /* @__PURE__ */ jsx("p", { class: "sg-thumb-note", children: note }) });
9
+ }
10
+ function DescriptorThumb({ entry, base = "" }) {
11
+ const thumbnail = entry.thumbnail;
12
+ if (!thumbnail) return /* @__PURE__ */ jsx(DescriptorThumbNote, { note: DESCRIPTOR_THUMB_MISSING_NOTE });
13
+ if (thumbnail.kind === "placeholder") return /* @__PURE__ */ jsx(DescriptorThumbNote, { note: thumbnail.note });
14
+ return /* @__PURE__ */ jsx("div", { class: "sg-thumb", "data-sg-preview-scope": true, "data-sg-thumb-image": true, "aria-hidden": "true", inert: true, children: /* @__PURE__ */ jsx(
15
+ "img",
16
+ {
17
+ class: "sg-thumb-img",
18
+ src: withThumbBase(base, thumbnail.src),
19
+ width: thumbnail.width,
20
+ height: thumbnail.height,
21
+ alt: thumbnail.alt ?? "",
22
+ loading: "lazy",
23
+ decoding: "async"
24
+ }
25
+ ) });
26
+ }
27
+ DescriptorThumb.displayName = "DescriptorThumb";
28
+ export {
29
+ DESCRIPTOR_THUMB_MISSING_NOTE,
30
+ DescriptorThumb
31
+ };
@@ -1,4 +1,8 @@
1
1
  export { ATOM_SCALE_CATEGORIES, ComponentThumb, THUMB_OPT_OUTS, THUMB_VIEWPORT_W, THUMB_VIEWPORT_W_ATOM, scopeThumbHtml, thumbIdPrefix, thumbScale, thumbViewportWidth, } from "./component-thumb.js";
2
2
  export type { ComponentThumbProps } from "./component-thumb.js";
3
+ export { DESCRIPTOR_THUMB_MISSING_NOTE, DescriptorThumb } from "./descriptor-thumb.js";
4
+ export type { DescriptorThumbProps } from "./descriptor-thumb.js";
5
+ export { CatalogThumb } from "./catalog-thumb.js";
6
+ export type { CatalogThumbProps } from "./catalog-thumb.js";
3
7
  export { ATTR_TILE_SIZE, DEFAULT_TILE_SIZE, LS_TILE_SIZE, TILE_SIZES, TILE_SIZE_RESTORE_SCRIPT, applyTileSize, isTileSize, readTileSize, } from "./tile-size.js";
4
8
  export type { TileSize, TileSizeOption } from "./tile-size.js";
@@ -9,6 +9,8 @@ import {
9
9
  thumbScale,
10
10
  thumbViewportWidth
11
11
  } from "./component-thumb.js";
12
+ import { DESCRIPTOR_THUMB_MISSING_NOTE, DescriptorThumb } from "./descriptor-thumb.js";
13
+ import { CatalogThumb } from "./catalog-thumb.js";
12
14
  import {
13
15
  ATTR_TILE_SIZE,
14
16
  DEFAULT_TILE_SIZE,
@@ -22,8 +24,11 @@ import {
22
24
  export {
23
25
  ATOM_SCALE_CATEGORIES,
24
26
  ATTR_TILE_SIZE,
27
+ CatalogThumb,
25
28
  ComponentThumb,
26
29
  DEFAULT_TILE_SIZE,
30
+ DESCRIPTOR_THUMB_MISSING_NOTE,
31
+ DescriptorThumb,
27
32
  LS_TILE_SIZE,
28
33
  THUMB_OPT_OUTS,
29
34
  THUMB_VIEWPORT_W,
@@ -10,8 +10,15 @@ export interface CodePanelProps {
10
10
  variants: CodePanelVariant[];
11
11
  /** Base-prefixed preview route URL — the same value DetailWorkbench receives. */
12
12
  previewUrl?: string;
13
+ /**
14
+ * Story slug, used to build stable variant-tab/tabpanel ids that match
15
+ * SSR output (mirrors `DetailWorkbench`'s `tabsId`). Falls back to
16
+ * `useId()` when the host doesn't pass one — still unique per page, just
17
+ * not stable across an SSR/hydration boundary.
18
+ */
19
+ slug?: string;
13
20
  }
14
- declare function CodePanel({ storyTitle, variants, previewUrl, }: CodePanelProps): JSX.Element;
21
+ declare function CodePanel({ storyTitle, variants, previewUrl, slug, }: CodePanelProps): JSX.Element;
15
22
  declare namespace CodePanel {
16
23
  var displayName: string;
17
24
  }
@@ -1,9 +1,10 @@
1
1
  "use client";
2
2
  import { jsx, jsxs } from "preact/jsx-runtime";
3
- import { useRef, useState } from "preact/hooks";
3
+ import { useId, useRef, useState } from "preact/hooks";
4
4
  import SourceEditor from "./source-editor.js";
5
5
  import CopyButton from "./copy-button.js";
6
6
  import { injectCssToAllPreviews } from "./css-injection.js";
7
+ import { handleTablistKeyDown } from "../shared/tablist-keyboard.js";
7
8
  const STARTER_CSS = `/* Live CSS \u2014 edits inject into every preview above.
8
9
  Try overriding a component utility, e.g.:
9
10
  .btn { letter-spacing: 0.04em; } */
@@ -11,48 +12,98 @@ const STARTER_CSS = `/* Live CSS \u2014 edits inject into every preview above.
11
12
  function CodePanel({
12
13
  storyTitle,
13
14
  variants,
14
- previewUrl
15
+ previewUrl,
16
+ slug
15
17
  }) {
16
18
  const [activeVariant, setActiveVariant] = useState(
17
19
  variants[0]?.exportName ?? ""
18
20
  );
19
21
  const debounceRef = useRef(void 0);
20
- const active = variants.find((v) => v.exportName === activeVariant) ?? variants[0];
22
+ const reactId = useId();
23
+ const tabsId = `sg-code-panel-${slug ?? reactId}`;
24
+ const foundIndex = variants.findIndex((v) => v.exportName === activeVariant);
25
+ const activeIndex = foundIndex >= 0 ? foundIndex : 0;
26
+ const active = variants[activeIndex];
27
+ const tabId = (index) => `${tabsId}-tab-${index}`;
28
+ const panelId = `${tabsId}-panel`;
21
29
  function handleCssChange(css) {
22
30
  window.clearTimeout(debounceRef.current);
23
31
  debounceRef.current = window.setTimeout(() => {
24
32
  injectCssToAllPreviews("live", css, previewUrl);
25
33
  }, 250);
26
34
  }
35
+ function onTabKeyDown(e, index) {
36
+ handleTablistKeyDown(
37
+ e,
38
+ index,
39
+ variants.length,
40
+ (next) => {
41
+ const target = variants[next];
42
+ if (target) setActiveVariant(target.exportName);
43
+ },
44
+ (next) => {
45
+ const tablist = e.currentTarget.parentElement;
46
+ tablist?.children[next]?.focus();
47
+ }
48
+ );
49
+ }
27
50
  return /* @__PURE__ */ jsxs("div", { class: "flex h-full flex-col gap-vsp-md p-hsp-md", children: [
28
51
  /* @__PURE__ */ jsxs("div", { children: [
29
52
  /* @__PURE__ */ jsxs("div", { class: "flex items-center justify-between gap-hsp-sm", children: [
30
53
  /* @__PURE__ */ jsx("h2", { class: "text-small font-semibold uppercase tracking-wide text-[color:var(--sg-muted)]", children: "Source" }),
31
54
  active && /* @__PURE__ */ jsx(CopyButton, { text: active.source, label: "Copy source" })
32
55
  ] }),
33
- variants.length > 1 && /* @__PURE__ */ jsx("div", { role: "tablist", class: "mt-vsp-2xs flex flex-wrap gap-hsp-3xs", children: variants.map((v) => /* @__PURE__ */ jsx(
34
- "button",
56
+ variants.length > 1 && /* @__PURE__ */ jsx(
57
+ "div",
35
58
  {
36
- type: "button",
37
- role: "tab",
38
- "aria-selected": v.exportName === activeVariant,
39
- onClick: () => setActiveVariant(v.exportName),
40
- class: "px-hsp-xs py-vsp-3xs text-xs rounded-sm border transition-colors " + (v.exportName === activeVariant ? "border-[color:var(--sg-accent)] bg-[var(--sg-accent)] text-[color:var(--sg-on-accent)]" : "border-[color:var(--sg-border)] text-[color:var(--sg-muted)] hover:text-[color:var(--sg-fg)]"),
41
- children: v.name
42
- },
43
- v.exportName
44
- )) }),
45
- active && /* @__PURE__ */ jsx("div", { class: "mt-vsp-xs", children: /* @__PURE__ */ jsx(
46
- SourceEditor,
59
+ role: "tablist",
60
+ "aria-label": "Source variant",
61
+ class: "mt-vsp-2xs flex flex-wrap gap-hsp-3xs",
62
+ children: variants.map((v, index) => {
63
+ const selected = index === activeIndex;
64
+ return /* @__PURE__ */ jsx(
65
+ "button",
66
+ {
67
+ id: tabId(index),
68
+ type: "button",
69
+ role: "tab",
70
+ "aria-selected": selected,
71
+ "aria-controls": panelId,
72
+ tabIndex: selected ? 0 : -1,
73
+ onClick: () => setActiveVariant(v.exportName),
74
+ onKeyDown: (e) => onTabKeyDown(e, index),
75
+ class: "px-hsp-xs py-vsp-3xs text-xs rounded-sm border transition-colors " + (selected ? "border-[color:var(--sg-accent)] bg-[var(--sg-accent)] text-[color:var(--sg-on-accent)]" : "border-[color:var(--sg-border)] text-[color:var(--sg-muted)] hover:text-[color:var(--sg-fg)]"),
76
+ children: v.name
77
+ },
78
+ v.exportName
79
+ );
80
+ })
81
+ }
82
+ ),
83
+ active && /* @__PURE__ */ jsx(
84
+ "div",
47
85
  {
48
- value: active.source,
49
- language: "tsx",
50
- editable: false
51
- },
52
- active.exportName
53
- ) })
86
+ class: "sg-code-source mt-vsp-xs",
87
+ "data-sg-code-region": "source",
88
+ ...variants.length > 1 ? {
89
+ id: panelId,
90
+ role: "tabpanel",
91
+ "aria-labelledby": tabId(activeIndex)
92
+ } : {},
93
+ children: /* @__PURE__ */ jsx(
94
+ SourceEditor,
95
+ {
96
+ value: active.source,
97
+ language: "tsx",
98
+ editable: false,
99
+ label: `Source code for ${storyTitle}: ${active.name}`
100
+ },
101
+ active.exportName
102
+ )
103
+ }
104
+ )
54
105
  ] }),
55
- /* @__PURE__ */ jsxs("div", { class: "flex min-h-0 flex-1 flex-col", children: [
106
+ /* @__PURE__ */ jsxs("div", { class: "sg-code-live-css flex min-h-0 flex-1 flex-col", "data-sg-code-region": "live-css", children: [
56
107
  /* @__PURE__ */ jsx("h2", { class: "text-small font-semibold uppercase tracking-wide text-[color:var(--sg-muted)]", children: "Live CSS" }),
57
108
  /* @__PURE__ */ jsxs("p", { class: "mt-vsp-3xs text-xs text-[color:var(--sg-muted)]", children: [
58
109
  "Injected into the previews above. ",
@@ -64,7 +115,8 @@ function CodePanel({
64
115
  value: STARTER_CSS,
65
116
  language: "css",
66
117
  editable: true,
67
- onChange: handleCssChange
118
+ onChange: handleCssChange,
119
+ label: `Live CSS for ${storyTitle}`
68
120
  }
69
121
  ) })
70
122
  ] })
@@ -4,6 +4,8 @@ export interface CreateEditorOptions {
4
4
  language: "css" | "tsx";
5
5
  /** Whether the editor is editable (false = read-only source view). */
6
6
  editable: boolean;
7
+ /** Accessible name for the editor's `.cm-content` (role="textbox"). */
8
+ label?: string;
7
9
  /** Fired on every document change with the full text. */
8
10
  onChange?: (value: string) => void;
9
11
  }
@@ -16,6 +16,9 @@ function createEditorView(doc, parent, opts) {
16
16
  EditorState.readOnly.of(!opts.editable),
17
17
  EditorView.editable.of(opts.editable)
18
18
  ];
19
+ if (opts.label) {
20
+ extensions.push(EditorView.contentAttributes.of({ "aria-label": opts.label }));
21
+ }
19
22
  if (opts.onChange) {
20
23
  extensions.push(
21
24
  EditorView.updateListener.of((update) => {
@@ -3,6 +3,8 @@ export interface SourceEditorProps {
3
3
  value: string;
4
4
  language: "css" | "tsx";
5
5
  editable?: boolean;
6
+ /** Accessible name for the editor (and its <pre> fallback before it mounts). */
7
+ label?: string;
6
8
  onChange?: (value: string) => void;
7
9
  }
8
- export default function SourceEditor({ value, language, editable, onChange, }: SourceEditorProps): JSX.Element;
10
+ export default function SourceEditor({ value, language, editable, label, onChange, }: SourceEditorProps): JSX.Element;
@@ -5,6 +5,7 @@ function SourceEditor({
5
5
  value,
6
6
  language,
7
7
  editable = false,
8
+ label,
8
9
  onChange
9
10
  }) {
10
11
  const containerRef = useRef(null);
@@ -19,6 +20,7 @@ function SourceEditor({
19
20
  viewRef.current = createEditorView(value, containerRef.current, {
20
21
  language,
21
22
  editable,
23
+ label,
22
24
  onChange: (v) => onChangeRef.current?.(v)
23
25
  });
24
26
  setLoaded(true);
@@ -30,7 +32,14 @@ function SourceEditor({
30
32
  };
31
33
  }, []);
32
34
  return /* @__PURE__ */ jsxs("div", { class: "relative text-small", children: [
33
- !loaded && /* @__PURE__ */ jsx("pre", { class: "m-0 overflow-auto rounded-md bg-[var(--sg-surface-2)] p-hsp-sm text-xs text-[color:var(--sg-muted)]", children: /* @__PURE__ */ jsx("code", { children: value }) }),
35
+ !loaded && /* @__PURE__ */ jsx(
36
+ "pre",
37
+ {
38
+ class: "m-0 overflow-auto rounded-md bg-[var(--sg-surface-2)] p-hsp-sm text-xs text-[color:var(--sg-muted)]",
39
+ "aria-label": label,
40
+ children: /* @__PURE__ */ jsx("code", { children: value })
41
+ }
42
+ ),
34
43
  /* @__PURE__ */ jsx("div", { ref: containerRef, class: loaded ? "" : "hidden" })
35
44
  ] });
36
45
  }
@@ -1,5 +1,5 @@
1
1
  import { componentDocsCollectionName } from "../registry/component-docs.js";
2
- import { type SgRoutes } from "../sg-routes.js";
2
+ import { type SgRoutesOption } from "../sg-routes.js";
3
3
  import type { HostTokensSpec } from "../token-spec.js";
4
4
  export type { HostTokensSpec, HostTokenGroupSpec, HostTokenSpec, TokenPreview, TokenControl, GeneratedTokenGroups, GeneratedTokenGroup } from "../token-spec.js";
5
5
  export declare const ROUTES_PLUGIN_NAME = "@takazudo/zudo-sg/plugins/routes";
@@ -17,7 +17,22 @@ export interface ZudoSgCollection {
17
17
  path: string;
18
18
  include: string[];
19
19
  }
20
- export interface ZudoSgComposeOptions {
20
+ /** Module mode (default): stories come from the generated StoryModule registry (`registryOut`). */
21
+ export interface ZudoSgModuleRegistry {
22
+ mode: "module";
23
+ }
24
+ /**
25
+ * Descriptor mode: stories come from plain-data `StoryDescriptor`s exported by
26
+ * `module` (project-root-relative, inside the project) as the named export
27
+ * `storyDescriptors`, or as the default export when that name is absent.
28
+ */
29
+ export interface ZudoSgDescriptorRegistry {
30
+ mode: "descriptor";
31
+ module: string;
32
+ }
33
+ export type ZudoSgRegistryOption = ZudoSgModuleRegistry | ZudoSgDescriptorRegistry;
34
+ interface ZudoSgModuleSourceOptions {
35
+ registry?: ZudoSgModuleRegistry;
21
36
  /** Story corpora; one `componentDocs*` collection is registered per `dir`. */
22
37
  componentsRoots: ReadonlyArray<{
23
38
  dir: string;
@@ -25,13 +40,39 @@ export interface ZudoSgComposeOptions {
25
40
  }>;
26
41
  /** Project-root-relative generated registry (the routes plugin's `registryModule`). */
27
42
  registryOut: string;
43
+ }
44
+ interface ZudoSgDescriptorSourceOptions {
45
+ registry: ZudoSgDescriptorRegistry;
46
+ /** Ignored by the engine in descriptor mode (no component-doc collections); CLI-only. */
47
+ componentsRoots?: ReadonlyArray<{
48
+ dir: string;
49
+ importBase?: string;
50
+ }>;
51
+ /** Ignored by the engine in descriptor mode; CLI-only. */
52
+ registryOut?: string;
53
+ }
54
+ export type ZudoSgComposeOptions = ZudoSgComposeBaseOptions & (ZudoSgModuleSourceOptions | ZudoSgDescriptorSourceOptions);
55
+ export interface ZudoSgComposeBaseOptions {
28
56
  categoryOrder?: string[];
29
57
  uiPackageName?: string;
30
58
  /** Project-root-relative preview stylesheet entry (the preview-css plugin's input). */
31
59
  previewStyles: string;
32
60
  /** Default `/_zudo-sg/preview.css`. */
33
61
  previewCssUrl?: string;
34
- routes?: Partial<SgRoutes>;
62
+ routes?: SgRoutesOption;
63
+ /**
64
+ * A host-served preview document that replaces the in-engine
65
+ * `componentsPreview` route (implied disabled once this is set). `url` must
66
+ * be root-absolute; `previewStyles`'s compiled CSS and the code panel both
67
+ * still apply — only the document that hosts the preview iframe moves.
68
+ * Required in descriptor mode (descriptors carry no render functions).
69
+ * Forwarded verbatim to the routes plugin's `externalPreview` option, which
70
+ * validates and normalizes it.
71
+ */
72
+ externalPreview?: {
73
+ url: string;
74
+ trailingSlash?: "never" | "always";
75
+ };
35
76
  catalog?: {
36
77
  title?: string;
37
78
  intro?: string;
@@ -67,9 +108,15 @@ export interface ZudoSgComposeOptions {
67
108
  };
68
109
  /**
69
110
  * Append the engine's header trigger for the preview token panel to the
70
- * zudo-doc routes plugin's `headerRightItems`. Defaults to true. Unlike
111
+ * zudo-doc routes plugin's `headerRightItems`. Defaults to whether the panel
112
+ * is wired at all (`isPreviewTokenPanelWired(zdtpApplyProxy)`, issue #872) —
113
+ * `true` when `zdtpApplyProxy.tabsModule` is set, `false` otherwise, so an
114
+ * unwired host no longer ships a dead button by default. Unlike
71
115
  * `chromeDefaults` this is unconditional: a host with its own `headerNav`
72
- * still gets the trigger.
116
+ * still gets the trigger. An explicit `true` always injects the trigger,
117
+ * even when unwired — `withZudoSg` then emits a one-time `console.warn`
118
+ * naming `zdtpApplyProxy.tabsModule`, since the button would otherwise be
119
+ * dead with no signal. An explicit `false` always stays off.
73
120
  */
74
121
  headerTokenTrigger?: boolean;
75
122
  /** Extra keys of `zudo-sg.config.mjs` (e.g. `barrelIndex`) are CLI-only and ignored here. */
@@ -95,6 +142,8 @@ export declare const HEADER_TOKEN_TRIGGER_ITEM: {
95
142
  type: "html";
96
143
  html: string;
97
144
  };
145
+ /** Test seam: re-arms the one-shot "trigger forced on while unwired" warning (issue #872). */
146
+ export declare function __resetHeaderTokenTriggerWarningForTests(): void;
98
147
  /** Returns the engine's zfb plugin descriptors and content collections. */
99
148
  export declare function zudoSg(options: ZudoSgComposeOptions): ZudoSgFragment;
100
149
  /**