@component-anatomy/storybook 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/AnatomyTable.d.ts +5 -5
- package/dist/AnatomyTable.d.ts.map +1 -1
- package/dist/Panel.d.ts.map +1 -1
- package/dist/blocks.d.ts.map +1 -1
- package/dist/blocks.js +15 -5
- package/dist/blocks.js.map +2 -2
- package/dist/manager.js +18 -5
- package/dist/manager.js.map +2 -2
- package/package.json +3 -3
- package/src/AnatomyTable.tsx +38 -10
- package/src/Panel.tsx +16 -4
- package/src/blocks.tsx +15 -6
package/README.md
CHANGED
|
@@ -48,6 +48,8 @@ export const Anatomy: Story = {
|
|
|
48
48
|
|
|
49
49
|
Omit `parts` (pass `{}`) and the panel lists parts auto-discovered from `data-part` attributes, with names derived from the ids.
|
|
50
50
|
|
|
51
|
+
`preset` and `theme` reach the panel and the `<Anatomy>` block too, not just the canvas overlays: the active row is accented with the same color the overlay paints. Where that color would be illegible on Storybook's own panel — `contrast` is black, the manager is dark by default — the table falls back to the most colorful alternative that meets WCAG AA, so `contrast` accents with its yellow on a dark panel and with black on a light one.
|
|
52
|
+
|
|
51
53
|
Parameters follow Storybook's normal inheritance — project-wide defaults in `.storybook/preview.ts`, per-component in `meta.parameters`, per-story overrides in `story.parameters`.
|
|
52
54
|
|
|
53
55
|
## In MDX
|
package/dist/AnatomyTable.d.ts
CHANGED
|
@@ -8,9 +8,7 @@
|
|
|
8
8
|
* data acquisition differs between the two; the markup must not.
|
|
9
9
|
*/
|
|
10
10
|
import React from 'react';
|
|
11
|
-
import type { AnatomyPartDefinition } from '@component-anatomy/core';
|
|
12
|
-
/** Fallback accent when the story sets no `anatomy.theme.accent`. */
|
|
13
|
-
export declare const ACCENT_FALLBACK = "#4f46e5";
|
|
11
|
+
import type { AnatomyPartDefinition, AnatomyPresetName, AnatomyTheme } from '@component-anatomy/core';
|
|
14
12
|
/**
|
|
15
13
|
* An inline `<code>` styled for the surrounding message text. Exported so
|
|
16
14
|
* both runtimes can compose their own empty-state copy without duplicating
|
|
@@ -28,8 +26,10 @@ export type AnatomyTableProps = {
|
|
|
28
26
|
parts: AnatomyPartDefinition[];
|
|
29
27
|
/** Id of the part currently highlighted in the canvas, if any. */
|
|
30
28
|
activeId?: string | null;
|
|
31
|
-
/**
|
|
32
|
-
|
|
29
|
+
/** The story's `anatomy.preset` — the active row follows it. */
|
|
30
|
+
preset?: AnatomyPresetName;
|
|
31
|
+
/** The story's `anatomy.theme` — token overrides on top of the preset. */
|
|
32
|
+
theme?: AnatomyTheme;
|
|
33
33
|
/** Called when the user hovers or focuses an entry. */
|
|
34
34
|
onItemEnter?: (partId: string) => void;
|
|
35
35
|
/** Called when the user leaves or blurs an entry. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnatomyTable.d.ts","sourceRoot":"","sources":["../src/AnatomyTable.tsx"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"AnatomyTable.d.ts","sourceRoot":"","sources":["../src/AnatomyTable.tsx"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,KAAK,EACV,qBAAqB,EACrB,iBAAiB,EACjB,YAAY,EACb,MAAM,yBAAyB,CAAC;AAkIjC;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC;IAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,CAG/D,CAAC;AAEF,0EAA0E;AAC1E,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC;IAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,CAOlE,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,wDAAwD;IACxD,KAAK,EAAE,qBAAqB,EAAE,CAAC;IAC/B,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,gEAAgE;IAChE,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,0EAA0E;IAC1E,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,uDAAuD;IACvD,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,qDAAqD;IACrD,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;CAC1B,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAwDpD,CAAC"}
|
package/dist/Panel.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Panel.d.ts","sourceRoot":"","sources":["../src/Panel.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAUnD,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"Panel.d.ts","sourceRoot":"","sources":["../src/Panel.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAUnD,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,EA8EzB,CAAC"}
|
package/dist/blocks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../src/blocks.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAA8B,MAAM,OAAO,CAAC;AAGnD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,8BAA8B,CAAC;AACvD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAQrE,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;;;;;OAOG;IACH,EAAE,CAAC,EAAE,EAAE,CAAC;IACR;;;OAGG;IACH,KAAK,CAAC,EAAE,qBAAqB,EAAE,CAAC;IAChC;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AAgBF,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,
|
|
1
|
+
{"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../src/blocks.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAA8B,MAAM,OAAO,CAAC;AAGnD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,8BAA8B,CAAC;AACvD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAQrE,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;;;;;OAOG;IACH,EAAE,CAAC,EAAE,EAAE,CAAC;IACR;;;OAGG;IACH,KAAK,CAAC,EAAE,qBAAqB,EAAE,CAAC;IAChC;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AAgBF,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CA6H/C,CAAC"}
|
package/dist/blocks.js
CHANGED
|
@@ -28,7 +28,7 @@ var matchesStory = (eventStoryId, storyId) => !eventStoryId || !storyId || event
|
|
|
28
28
|
// src/AnatomyTable.tsx
|
|
29
29
|
import React from "react";
|
|
30
30
|
import { useTheme } from "storybook/theming";
|
|
31
|
-
|
|
31
|
+
import { resolvePanelAccent } from "@component-anatomy/core";
|
|
32
32
|
var FONT_BASE_FALLBACK = '"Nunito Sans", -apple-system, ".SFNSText-Regular", "San Francisco", BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif';
|
|
33
33
|
var FONT_MONO_FALLBACK = 'ui-monospace, "Cascadia Code", "Fira Mono", monospace';
|
|
34
34
|
function usePalette() {
|
|
@@ -38,10 +38,18 @@ function usePalette() {
|
|
|
38
38
|
muted: theme.fgColor?.muted ?? "#6b7280",
|
|
39
39
|
mutedBg: theme.bgColor?.muted ?? "rgba(0,0,0,0.06)",
|
|
40
40
|
border: theme.borderColor?.default ?? "rgba(0,0,0,0.08)",
|
|
41
|
+
surfaceBg: theme.bgColor?.default ?? "#ffffff",
|
|
42
|
+
surfaceFg: theme.fgColor?.default ?? "#2e3438",
|
|
41
43
|
fontBase: theme.typography?.fonts?.base ?? FONT_BASE_FALLBACK,
|
|
42
44
|
fontMono: theme.typography?.fonts?.mono ?? FONT_MONO_FALLBACK
|
|
43
45
|
};
|
|
44
46
|
}
|
|
47
|
+
function useAccent(palette, preset, theme) {
|
|
48
|
+
return resolvePanelAccent(preset, theme, {
|
|
49
|
+
background: palette.surfaceBg,
|
|
50
|
+
foreground: palette.surfaceFg
|
|
51
|
+
});
|
|
52
|
+
}
|
|
45
53
|
var makeStyles = (p) => ({
|
|
46
54
|
container: {
|
|
47
55
|
padding: "12px 16px",
|
|
@@ -121,12 +129,14 @@ var AnatomyMessage = ({ children }) => {
|
|
|
121
129
|
var AnatomyTable = ({
|
|
122
130
|
parts,
|
|
123
131
|
activeId = null,
|
|
124
|
-
|
|
132
|
+
preset,
|
|
133
|
+
theme,
|
|
125
134
|
onItemEnter,
|
|
126
135
|
onItemLeave
|
|
127
136
|
}) => {
|
|
128
137
|
const palette = usePalette();
|
|
129
138
|
const styles = makeStyles(palette);
|
|
139
|
+
const accent = useAccent(palette, preset, theme);
|
|
130
140
|
return /* @__PURE__ */ React.createElement("div", { style: styles.container }, /* @__PURE__ */ React.createElement("ul", { style: styles.list, role: "list", "aria-label": "Anatomy parts" }, parts.map((part) => {
|
|
131
141
|
const active = activeId === part.id;
|
|
132
142
|
return /* @__PURE__ */ React.createElement(
|
|
@@ -207,7 +217,6 @@ var Anatomy = ({ of, parts: partsProp, sync = true }) => {
|
|
|
207
217
|
};
|
|
208
218
|
}, [wired, storyId]);
|
|
209
219
|
const parts = staticParts ?? discovered;
|
|
210
|
-
const accent = params?.theme?.accent ?? ACCENT_FALLBACK;
|
|
211
220
|
const emitHover = (partId) => {
|
|
212
221
|
if (!wired) return;
|
|
213
222
|
getChannelSafely()?.emit(EVENTS.HOVER_ITEM, { storyId, partId });
|
|
@@ -223,14 +232,15 @@ var Anatomy = ({ of, parts: partsProp, sync = true }) => {
|
|
|
223
232
|
return /* @__PURE__ */ React2.createElement(Unstyled, null, /* @__PURE__ */ React2.createElement(AnatomyMessage, null, "Anatomy is disabled for this story (", /* @__PURE__ */ React2.createElement(AnatomyCode, null, "anatomy.disable"), ")."));
|
|
224
233
|
}
|
|
225
234
|
if (parts.length === 0) {
|
|
226
|
-
return /* @__PURE__ */ React2.createElement(Unstyled, null, /* @__PURE__ */ React2.createElement(AnatomyMessage, null, resolved.type === "meta" ? "No parts found. A meta has no canvas to discover parts from \u2014 pass a story to
|
|
235
|
+
return /* @__PURE__ */ React2.createElement(Unstyled, null, /* @__PURE__ */ React2.createElement(AnatomyMessage, null, resolved.type === "meta" ? /* @__PURE__ */ React2.createElement(React2.Fragment, null, "No parts found. A meta has no canvas to discover parts from \u2014 pass a story to", " ", /* @__PURE__ */ React2.createElement(AnatomyCode, null, "of"), ", or list ", /* @__PURE__ */ React2.createElement(AnatomyCode, null, "parts"), " explicitly.") : /* @__PURE__ */ React2.createElement(React2.Fragment, null, "No parts found. Auto-discovery reads the rendered story, so make sure it is on this page (e.g. with a ", /* @__PURE__ */ React2.createElement(AnatomyCode, null, "<Canvas of={\u2026} />"), " block above), or list ", /* @__PURE__ */ React2.createElement(AnatomyCode, null, "parts"), " explicitly.")));
|
|
227
236
|
}
|
|
228
237
|
return /* @__PURE__ */ React2.createElement(Unstyled, null, /* @__PURE__ */ React2.createElement(
|
|
229
238
|
AnatomyTable,
|
|
230
239
|
{
|
|
231
240
|
parts,
|
|
232
241
|
activeId,
|
|
233
|
-
|
|
242
|
+
preset: params?.preset,
|
|
243
|
+
theme: params?.theme,
|
|
234
244
|
onItemEnter: emitHover,
|
|
235
245
|
onItemLeave: emitLeave
|
|
236
246
|
}
|
package/dist/blocks.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/blocks.tsx", "../src/constants.ts", "../src/channel.ts", "../src/AnatomyTable.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * Docs blocks entry \u2014 the `<Anatomy>` block for MDX pages.\n *\n * Unlike the addon panel, this runs in the **preview iframe**, where\n * `storybook/manager-api` does not exist. It reaches the story's controller\n * over the addon channel instead: `Channel.emit` dispatches to local\n * listeners as well as across transports, so a block and the decorator that\n * mounted the story talk to each other directly, in-frame, with no extra\n * plumbing.\n *\n * ```mdx\n * import { Meta, Canvas } from '@storybook/addon-docs/blocks';\n * import { Anatomy } from '@component-anatomy/storybook/blocks';\n * import * as ButtonStories from './Button.stories';\n *\n * <Meta of={ButtonStories} />\n *\n * <Canvas of={ButtonStories.Anatomy} />\n * <Anatomy of={ButtonStories.Anatomy} />\n * ```\n */\nimport React, { useEffect, useState } from 'react';\nimport { addons } from 'storybook/preview-api';\nimport { Unstyled, useOf } from '@storybook/addon-docs/blocks';\nimport type { Of } from '@storybook/addon-docs/blocks';\nimport type { AnatomyPartDefinition } from '@component-anatomy/core';\n\nimport { EVENTS, PARAM_KEY } from './constants.js';\nimport { matchesStory } from './channel.js';\nimport type { PartEnterEvent, PartsEvent, StoryScopedEvent } from './channel.js';\nimport { ACCENT_FALLBACK, AnatomyCode, AnatomyMessage, AnatomyTable } from './AnatomyTable.js';\nimport type { AnatomyParameters } from './types.js';\n\nexport type AnatomyBlockProps = {\n /**\n * The CSF export to document \u2014 a story export, or the whole module export\n * of a CSF file to read the meta's parameters.\n *\n * Omit it on an attached docs page (one with `<Meta of={...} />`, or an\n * autodocs page) to fall back to the page's current story, mirroring how\n * the other docs blocks resolve `of`.\n */\n of?: Of;\n /**\n * Part list override. Skips both `parameters.anatomy.parts` and\n * auto-discovery \u2014 useful for a hand-curated subset in prose.\n */\n parts?: AnatomyPartDefinition[];\n /**\n * Two-way hover sync with the rendered story. Default: `true`. Set to\n * `false` for a purely static table (also skips auto-discovery, since that\n * arrives over the channel).\n */\n sync?: boolean;\n};\n\n/**\n * `addons.getChannel()` throws when no channel is installed. That should not\n * happen inside a rendered docs page, but an MDX page is user-authored\n * content and a throw here would blank the whole page \u2014 degrade to a static\n * table instead.\n */\nfunction getChannelSafely() {\n try {\n return addons.getChannel();\n } catch {\n return null;\n }\n}\n\nexport const Anatomy: React.FC<AnatomyBlockProps> = ({ of, parts: partsProp, sync = true }) => {\n const resolved = useOf(of ?? 'story', ['story', 'meta']);\n\n const params = (\n resolved.type === 'meta'\n ? resolved.preparedMeta.parameters?.[PARAM_KEY]\n : resolved.story.parameters?.[PARAM_KEY]\n ) as AnatomyParameters | undefined;\n\n // Only a story has a canvas to sync with. `of={SomeStories}` (a meta)\n // documents the component as a whole and can render static parts only.\n const storyId = resolved.type === 'story' ? resolved.story.id : undefined;\n\n const [discovered, setDiscovered] = useState<AnatomyPartDefinition[]>([]);\n const [activeId, setActiveId] = useState<string | null>(null);\n\n const staticParts = partsProp ?? params?.parts;\n // Hover sync is wired even when the parts are static \u2014 an explicit list\n // still wants the canvas to light up. Only discovery depends on the channel.\n const wired = sync && !!storyId;\n\n useEffect(() => {\n setDiscovered([]);\n setActiveId(null);\n if (!wired) return;\n\n const channel = getChannelSafely();\n if (!channel) return;\n\n const onParts = (event: PartsEvent) => {\n if (!matchesStory(event?.storyId, storyId)) return;\n setDiscovered(event.parts);\n };\n const onEnter = (event: PartEnterEvent) => {\n if (!matchesStory(event?.storyId, storyId)) return;\n setActiveId(event.partId);\n };\n const onLeave = (event: StoryScopedEvent = {}) => {\n if (!matchesStory(event?.storyId, storyId)) return;\n setActiveId(null);\n };\n\n channel.on(EVENTS.PARTS, onParts);\n channel.on(EVENTS.PART_ENTER, onEnter);\n channel.on(EVENTS.PART_LEAVE, onLeave);\n\n // The block usually mounts before the story below it finishes rendering;\n // the request covers the other order.\n channel.emit(EVENTS.PARTS_REQUEST, { storyId } satisfies StoryScopedEvent);\n\n return () => {\n channel.off(EVENTS.PARTS, onParts);\n channel.off(EVENTS.PART_ENTER, onEnter);\n channel.off(EVENTS.PART_LEAVE, onLeave);\n };\n }, [wired, storyId]);\n\n const parts = staticParts ?? discovered;\n const accent = params?.theme?.accent ?? ACCENT_FALLBACK;\n\n const emitHover = (partId: string) => {\n if (!wired) return;\n getChannelSafely()?.emit(EVENTS.HOVER_ITEM, { storyId, partId });\n };\n const emitLeave = () => {\n if (!wired) return;\n getChannelSafely()?.emit(EVENTS.LEAVE_ITEM, { storyId } satisfies StoryScopedEvent);\n };\n\n // `Unstyled` keeps the docs page's prose CSS (`.sbdocs` restyles ul/li/p/\n // code) from reaching the table.\n if (!params && !partsProp) {\n return (\n <Unstyled>\n <AnatomyMessage>\n No anatomy configured. Add <AnatomyCode>parameters.anatomy</AnatomyCode> to the story you\n pass to <AnatomyCode>of</AnatomyCode>, or pass a{' '}\n <AnatomyCode>parts</AnatomyCode> list to this block.\n </AnatomyMessage>\n </Unstyled>\n );\n }\n\n if (params?.disable && !partsProp) {\n return (\n <Unstyled>\n <AnatomyMessage>\n Anatomy is disabled for this story (<AnatomyCode>anatomy.disable</AnatomyCode>).\n </AnatomyMessage>\n </Unstyled>\n );\n }\n\n if (parts.length === 0) {\n return (\n <Unstyled>\n <AnatomyMessage>\n {resolved.type === 'meta'\n ? 'No parts found. A meta has no canvas to discover parts from \u2014 pass a story to `of`, or list `parts` explicitly.'\n : 'No parts found. Auto-discovery reads the rendered story, so make sure it is on this page (e.g. with a `<Canvas of={\u2026} />` block above), or list `parts` explicitly.'}\n </AnatomyMessage>\n </Unstyled>\n );\n }\n\n return (\n <Unstyled>\n <AnatomyTable\n parts={parts}\n activeId={activeId}\n accent={accent}\n onItemEnter={emitHover}\n onItemLeave={emitLeave}\n />\n </Unstyled>\n );\n};\n", "export const ADDON_ID = 'component-anatomy';\nexport const PANEL_ID = `${ADDON_ID}/panel`;\n\n/** Story parameter key: `parameters.anatomy = { ... }` */\nexport const PARAM_KEY = 'anatomy';\n\n/**\n * Channel events used to sync the manager panel \u2014 and the `<Anatomy>` MDX doc\n * block, which runs in the preview iframe \u2014 with the story canvas.\n *\n * Every payload carries the `storyId` it concerns; see `channel.ts` for the\n * payload types and the `matchesStory` filter each listener applies.\n */\nexport const EVENTS = {\n /** preview \u2192 consumers: a part became active in the canvas (hover/programmatic). */\n PART_ENTER: `${ADDON_ID}/part-enter`,\n /** preview \u2192 consumers: no part is active anymore. */\n PART_LEAVE: `${ADDON_ID}/part-leave`,\n /** preview \u2192 consumers: resolved part list for a story. */\n PARTS: `${ADDON_ID}/parts`,\n /** consumers \u2192 preview: the user hovers/focuses a panel entry. */\n HOVER_ITEM: `${ADDON_ID}/hover-item`,\n /** consumers \u2192 preview: the user left a panel entry. */\n LEAVE_ITEM: `${ADDON_ID}/leave-item`,\n /** consumers \u2192 preview: a panel/block mounted and wants the current part list. */\n PARTS_REQUEST: `${ADDON_ID}/parts-request`,\n} as const;\n", "/**\n * Shared channel payload contract between the preview decorator, the manager\n * panel, and the MDX doc block.\n *\n * Every payload carries the `storyId` it refers to. In story view this is\n * redundant \u2014 only one story is mounted \u2014 but a docs page mounts *many*\n * stories at once, each with its own controller, and each `<Anatomy>` block\n * must talk to exactly one of them. Without addressing, hovering a part in\n * one block highlights the matching part in every other story on the page.\n */\nimport type { AnatomyPartDefinition } from '@component-anatomy/core';\n\n/** preview \u2192 consumers: the resolved part list for one story. */\nexport type PartsEvent = { storyId?: string; parts: AnatomyPartDefinition[] };\n\n/** preview \u2192 consumers: a part became active in that story's canvas. */\nexport type PartEnterEvent = { storyId?: string; partId: string };\n\n/** consumer \u2192 preview: highlight this part in that story's canvas. */\nexport type HoverItemEvent = { storyId?: string; partId: string };\n\n/** Payload for the events that only need to name a story. */\nexport type StoryScopedEvent = { storyId?: string };\n\n/**\n * Whether an event addressed to `eventStoryId` concerns `storyId`.\n *\n * A missing id on *either* side matches everything. That keeps the protocol\n * backward compatible: a manager panel from a newer build still understands\n * an older preview bundle that emits unaddressed events, and vice versa.\n */\nexport const matchesStory = (\n eventStoryId: string | undefined,\n storyId: string | undefined\n): boolean => !eventStoryId || !storyId || eventStoryId === storyId;\n", "/**\n * The anatomy part table \u2014 pure presentation, no Storybook imports.\n *\n * This module is deliberately free of `storybook/manager-api` and\n * `storybook/preview-api`: it is bundled into *both* the manager entry (the\n * addon panel) and the blocks entry (the `<Anatomy>` MDX doc block), which\n * run in different runtimes and cannot share either of those APIs. Only the\n * data acquisition differs between the two; the markup must not.\n */\nimport React from 'react';\nimport { useTheme } from 'storybook/theming';\nimport type { AnatomyPartDefinition } from '@component-anatomy/core';\n\n/** Fallback accent when the story sets no `anatomy.theme.accent`. */\nexport const ACCENT_FALLBACK = '#4f46e5';\n\n/**\n * The subset of Storybook's theme this table reads. Typed loosely on purpose:\n * `useTheme()` resolves to an empty `Theme` interface (Emotion augmentation),\n * and outside a ThemeProvider it returns `{}` \u2014 so every read is optional and\n * every value has a literal fallback below.\n */\ntype PartialStorybookTheme = {\n fgColor?: { default?: string; muted?: string };\n bgColor?: { muted?: string };\n borderColor?: { default?: string };\n typography?: { fonts?: { base?: string; mono?: string } };\n};\n\nconst FONT_BASE_FALLBACK =\n '\"Nunito Sans\", -apple-system, \".SFNSText-Regular\", \"San Francisco\", BlinkMacSystemFont, \"Segoe UI\", \"Helvetica Neue\", Helvetica, Arial, sans-serif';\nconst FONT_MONO_FALLBACK = 'ui-monospace, \"Cascadia Code\", \"Fira Mono\", monospace';\n\n/**\n * Resolves the table's chrome colors from Storybook's theme so the same\n * markup reads correctly in the manager panel *and* in a docs page under a\n * dark theme. The accent is intentionally not theme-derived \u2014 it is the\n * addon's identity color and stays stable unless a story overrides it.\n */\nfunction usePalette() {\n const theme = useTheme() as PartialStorybookTheme;\n return {\n text: theme.fgColor?.default,\n muted: theme.fgColor?.muted ?? '#6b7280',\n mutedBg: theme.bgColor?.muted ?? 'rgba(0,0,0,0.06)',\n border: theme.borderColor?.default ?? 'rgba(0,0,0,0.08)',\n fontBase: theme.typography?.fonts?.base ?? FONT_BASE_FALLBACK,\n fontMono: theme.typography?.fonts?.mono ?? FONT_MONO_FALLBACK,\n };\n}\n\ntype Palette = ReturnType<typeof usePalette>;\n\nconst makeStyles = (p: Palette): Record<string, React.CSSProperties> => ({\n container: {\n padding: '12px 16px',\n fontFamily: p.fontBase,\n fontSize: 13,\n lineHeight: 1.5,\n color: p.text,\n },\n empty: {\n color: p.muted,\n margin: 0,\n },\n code: {\n fontFamily: p.fontMono,\n fontSize: '0.85em',\n background: p.mutedBg,\n borderRadius: 3,\n padding: '1px 5px',\n },\n list: {\n display: 'flex',\n flexDirection: 'column',\n gap: 2,\n margin: 0,\n padding: 0,\n listStyle: 'none',\n },\n entry: {\n padding: '8px 10px',\n borderRadius: 6,\n border: '1px solid transparent',\n cursor: 'default',\n outline: 'none',\n transition: 'background 120ms ease, border-color 120ms ease',\n },\n header: {\n display: 'flex',\n alignItems: 'center',\n gap: 8,\n },\n indicator: {\n width: 8,\n height: 8,\n borderRadius: '50%',\n border: `2px solid ${p.border}`,\n flexShrink: 0,\n transition: 'background 120ms ease, border-color 120ms ease',\n },\n name: {\n fontWeight: 700,\n flex: 1,\n },\n id: {\n fontFamily: p.fontMono,\n fontSize: 10,\n padding: '1px 6px',\n borderRadius: 4,\n background: p.mutedBg,\n border: `1px solid ${p.border}`,\n color: p.muted,\n flexShrink: 0,\n },\n description: {\n margin: '4px 0 0',\n paddingLeft: 16,\n color: p.muted,\n },\n});\n\n/**\n * An inline `<code>` styled for the surrounding message text. Exported so\n * both runtimes can compose their own empty-state copy without duplicating\n * the style object.\n */\nexport const AnatomyCode: React.FC<{ children: React.ReactNode }> = ({ children }) => {\n const styles = makeStyles(usePalette());\n return <code style={styles.code}>{children}</code>;\n};\n\n/** A padded, muted paragraph \u2014 used for every \"nothing to show\" state. */\nexport const AnatomyMessage: React.FC<{ children: React.ReactNode }> = ({ children }) => {\n const styles = makeStyles(usePalette());\n return (\n <div style={styles.container}>\n <p style={styles.empty}>{children}</p>\n </div>\n );\n};\n\nexport type AnatomyTableProps = {\n /** Parts to list, in the order they should be shown. */\n parts: AnatomyPartDefinition[];\n /** Id of the part currently highlighted in the canvas, if any. */\n activeId?: string | null;\n /** Accent color for the active state. Defaults to {@link ACCENT_FALLBACK}. */\n accent?: string;\n /** Called when the user hovers or focuses an entry. */\n onItemEnter?: (partId: string) => void;\n /** Called when the user leaves or blurs an entry. */\n onItemLeave?: () => void;\n};\n\nexport const AnatomyTable: React.FC<AnatomyTableProps> = ({\n parts,\n activeId = null,\n accent = ACCENT_FALLBACK,\n onItemEnter,\n onItemLeave,\n}) => {\n const palette = usePalette();\n const styles = makeStyles(palette);\n\n return (\n <div style={styles.container}>\n <ul style={styles.list} role=\"list\" aria-label=\"Anatomy parts\">\n {parts.map((part) => {\n const active = activeId === part.id;\n return (\n <li\n key={part.id}\n role=\"listitem\"\n tabIndex={0}\n aria-label={part.name}\n style={{\n ...styles.entry,\n background: active ? `color-mix(in srgb, ${accent} 7%, transparent)` : undefined,\n borderColor: active\n ? `color-mix(in srgb, ${accent} 20%, transparent)`\n : 'transparent',\n }}\n onMouseEnter={() => onItemEnter?.(part.id)}\n onMouseLeave={() => onItemLeave?.()}\n onFocus={() => onItemEnter?.(part.id)}\n onBlur={() => onItemLeave?.()}\n >\n <div style={styles.header}>\n <span\n aria-hidden=\"true\"\n style={{\n ...styles.indicator,\n background: active ? accent : undefined,\n borderColor: active ? accent : palette.border,\n }}\n />\n <span style={{ ...styles.name, color: active ? accent : undefined }}>\n {part.name}\n </span>\n <code style={styles.id}>{part.id}</code>\n </div>\n {part.description && <p style={styles.description}>{part.description}</p>}\n </li>\n );\n })}\n </ul>\n </div>\n );\n};\n"],
|
|
5
|
-
"mappings": ";AAqBA,OAAOA,UAAS,WAAW,gBAAgB;AAC3C,SAAS,cAAc;AACvB,SAAS,UAAU,aAAa;;;ACvBzB,IAAM,WAAW;AACjB,IAAM,WAAW,GAAG,QAAQ;AAG5B,IAAM,YAAY;AASlB,IAAM,SAAS;AAAA;AAAA,EAEpB,YAAY,GAAG,QAAQ;AAAA;AAAA,EAEvB,YAAY,GAAG,QAAQ;AAAA;AAAA,EAEvB,OAAO,GAAG,QAAQ;AAAA;AAAA,EAElB,YAAY,GAAG,QAAQ;AAAA;AAAA,EAEvB,YAAY,GAAG,QAAQ;AAAA;AAAA,EAEvB,eAAe,GAAG,QAAQ;AAC5B;;;ACKO,IAAM,eAAe,CAC1B,cACA,YACY,CAAC,gBAAgB,CAAC,WAAW,iBAAiB;;;ACzB5D,OAAO,WAAW;AAClB,SAAS,gBAAgB;
|
|
4
|
+
"sourcesContent": ["/**\n * Docs blocks entry \u2014 the `<Anatomy>` block for MDX pages.\n *\n * Unlike the addon panel, this runs in the **preview iframe**, where\n * `storybook/manager-api` does not exist. It reaches the story's controller\n * over the addon channel instead: `Channel.emit` dispatches to local\n * listeners as well as across transports, so a block and the decorator that\n * mounted the story talk to each other directly, in-frame, with no extra\n * plumbing.\n *\n * ```mdx\n * import { Meta, Canvas } from '@storybook/addon-docs/blocks';\n * import { Anatomy } from '@component-anatomy/storybook/blocks';\n * import * as ButtonStories from './Button.stories';\n *\n * <Meta of={ButtonStories} />\n *\n * <Canvas of={ButtonStories.Anatomy} />\n * <Anatomy of={ButtonStories.Anatomy} />\n * ```\n */\nimport React, { useEffect, useState } from 'react';\nimport { addons } from 'storybook/preview-api';\nimport { Unstyled, useOf } from '@storybook/addon-docs/blocks';\nimport type { Of } from '@storybook/addon-docs/blocks';\nimport type { AnatomyPartDefinition } from '@component-anatomy/core';\n\nimport { EVENTS, PARAM_KEY } from './constants.js';\nimport { matchesStory } from './channel.js';\nimport type { PartEnterEvent, PartsEvent, StoryScopedEvent } from './channel.js';\nimport { AnatomyCode, AnatomyMessage, AnatomyTable } from './AnatomyTable.js';\nimport type { AnatomyParameters } from './types.js';\n\nexport type AnatomyBlockProps = {\n /**\n * The CSF export to document \u2014 a story export, or the whole module export\n * of a CSF file to read the meta's parameters.\n *\n * Omit it on an attached docs page (one with `<Meta of={...} />`, or an\n * autodocs page) to fall back to the page's current story, mirroring how\n * the other docs blocks resolve `of`.\n */\n of?: Of;\n /**\n * Part list override. Skips both `parameters.anatomy.parts` and\n * auto-discovery \u2014 useful for a hand-curated subset in prose.\n */\n parts?: AnatomyPartDefinition[];\n /**\n * Two-way hover sync with the rendered story. Default: `true`. Set to\n * `false` for a purely static table (also skips auto-discovery, since that\n * arrives over the channel).\n */\n sync?: boolean;\n};\n\n/**\n * `addons.getChannel()` throws when no channel is installed. That should not\n * happen inside a rendered docs page, but an MDX page is user-authored\n * content and a throw here would blank the whole page \u2014 degrade to a static\n * table instead.\n */\nfunction getChannelSafely() {\n try {\n return addons.getChannel();\n } catch {\n return null;\n }\n}\n\nexport const Anatomy: React.FC<AnatomyBlockProps> = ({ of, parts: partsProp, sync = true }) => {\n const resolved = useOf(of ?? 'story', ['story', 'meta']);\n\n const params = (\n resolved.type === 'meta'\n ? resolved.preparedMeta.parameters?.[PARAM_KEY]\n : resolved.story.parameters?.[PARAM_KEY]\n ) as AnatomyParameters | undefined;\n\n // Only a story has a canvas to sync with. `of={SomeStories}` (a meta)\n // documents the component as a whole and can render static parts only.\n const storyId = resolved.type === 'story' ? resolved.story.id : undefined;\n\n const [discovered, setDiscovered] = useState<AnatomyPartDefinition[]>([]);\n const [activeId, setActiveId] = useState<string | null>(null);\n\n const staticParts = partsProp ?? params?.parts;\n // Hover sync is wired even when the parts are static \u2014 an explicit list\n // still wants the canvas to light up. Only discovery depends on the channel.\n const wired = sync && !!storyId;\n\n useEffect(() => {\n setDiscovered([]);\n setActiveId(null);\n if (!wired) return;\n\n const channel = getChannelSafely();\n if (!channel) return;\n\n const onParts = (event: PartsEvent) => {\n if (!matchesStory(event?.storyId, storyId)) return;\n setDiscovered(event.parts);\n };\n const onEnter = (event: PartEnterEvent) => {\n if (!matchesStory(event?.storyId, storyId)) return;\n setActiveId(event.partId);\n };\n const onLeave = (event: StoryScopedEvent = {}) => {\n if (!matchesStory(event?.storyId, storyId)) return;\n setActiveId(null);\n };\n\n channel.on(EVENTS.PARTS, onParts);\n channel.on(EVENTS.PART_ENTER, onEnter);\n channel.on(EVENTS.PART_LEAVE, onLeave);\n\n // The block usually mounts before the story below it finishes rendering;\n // the request covers the other order.\n channel.emit(EVENTS.PARTS_REQUEST, { storyId } satisfies StoryScopedEvent);\n\n return () => {\n channel.off(EVENTS.PARTS, onParts);\n channel.off(EVENTS.PART_ENTER, onEnter);\n channel.off(EVENTS.PART_LEAVE, onLeave);\n };\n }, [wired, storyId]);\n\n const parts = staticParts ?? discovered;\n\n const emitHover = (partId: string) => {\n if (!wired) return;\n getChannelSafely()?.emit(EVENTS.HOVER_ITEM, { storyId, partId });\n };\n const emitLeave = () => {\n if (!wired) return;\n getChannelSafely()?.emit(EVENTS.LEAVE_ITEM, { storyId } satisfies StoryScopedEvent);\n };\n\n // `Unstyled` keeps the docs page's prose CSS (`.sbdocs` restyles ul/li/p/\n // code) from reaching the table.\n if (!params && !partsProp) {\n return (\n <Unstyled>\n <AnatomyMessage>\n No anatomy configured. Add <AnatomyCode>parameters.anatomy</AnatomyCode> to the story you\n pass to <AnatomyCode>of</AnatomyCode>, or pass a{' '}\n <AnatomyCode>parts</AnatomyCode> list to this block.\n </AnatomyMessage>\n </Unstyled>\n );\n }\n\n if (params?.disable && !partsProp) {\n return (\n <Unstyled>\n <AnatomyMessage>\n Anatomy is disabled for this story (<AnatomyCode>anatomy.disable</AnatomyCode>).\n </AnatomyMessage>\n </Unstyled>\n );\n }\n\n if (parts.length === 0) {\n return (\n <Unstyled>\n <AnatomyMessage>\n {resolved.type === 'meta' ? (\n <>\n No parts found. A meta has no canvas to discover parts from \u2014 pass a story to{' '}\n <AnatomyCode>of</AnatomyCode>, or list <AnatomyCode>parts</AnatomyCode> explicitly.\n </>\n ) : (\n <>\n No parts found. Auto-discovery reads the rendered story, so make sure it is on this\n page (e.g. with a <AnatomyCode>{'<Canvas of={\u2026} />'}</AnatomyCode> block above), or\n list <AnatomyCode>parts</AnatomyCode> explicitly.\n </>\n )}\n </AnatomyMessage>\n </Unstyled>\n );\n }\n\n return (\n <Unstyled>\n <AnatomyTable\n parts={parts}\n activeId={activeId}\n preset={params?.preset}\n theme={params?.theme}\n onItemEnter={emitHover}\n onItemLeave={emitLeave}\n />\n </Unstyled>\n );\n};\n", "export const ADDON_ID = 'component-anatomy';\nexport const PANEL_ID = `${ADDON_ID}/panel`;\n\n/** Story parameter key: `parameters.anatomy = { ... }` */\nexport const PARAM_KEY = 'anatomy';\n\n/**\n * Channel events used to sync the manager panel \u2014 and the `<Anatomy>` MDX doc\n * block, which runs in the preview iframe \u2014 with the story canvas.\n *\n * Every payload carries the `storyId` it concerns; see `channel.ts` for the\n * payload types and the `matchesStory` filter each listener applies.\n */\nexport const EVENTS = {\n /** preview \u2192 consumers: a part became active in the canvas (hover/programmatic). */\n PART_ENTER: `${ADDON_ID}/part-enter`,\n /** preview \u2192 consumers: no part is active anymore. */\n PART_LEAVE: `${ADDON_ID}/part-leave`,\n /** preview \u2192 consumers: resolved part list for a story. */\n PARTS: `${ADDON_ID}/parts`,\n /** consumers \u2192 preview: the user hovers/focuses a panel entry. */\n HOVER_ITEM: `${ADDON_ID}/hover-item`,\n /** consumers \u2192 preview: the user left a panel entry. */\n LEAVE_ITEM: `${ADDON_ID}/leave-item`,\n /** consumers \u2192 preview: a panel/block mounted and wants the current part list. */\n PARTS_REQUEST: `${ADDON_ID}/parts-request`,\n} as const;\n", "/**\n * Shared channel payload contract between the preview decorator, the manager\n * panel, and the MDX doc block.\n *\n * Every payload carries the `storyId` it refers to. In story view this is\n * redundant \u2014 only one story is mounted \u2014 but a docs page mounts *many*\n * stories at once, each with its own controller, and each `<Anatomy>` block\n * must talk to exactly one of them. Without addressing, hovering a part in\n * one block highlights the matching part in every other story on the page.\n */\nimport type { AnatomyPartDefinition } from '@component-anatomy/core';\n\n/** preview \u2192 consumers: the resolved part list for one story. */\nexport type PartsEvent = { storyId?: string; parts: AnatomyPartDefinition[] };\n\n/** preview \u2192 consumers: a part became active in that story's canvas. */\nexport type PartEnterEvent = { storyId?: string; partId: string };\n\n/** consumer \u2192 preview: highlight this part in that story's canvas. */\nexport type HoverItemEvent = { storyId?: string; partId: string };\n\n/** Payload for the events that only need to name a story. */\nexport type StoryScopedEvent = { storyId?: string };\n\n/**\n * Whether an event addressed to `eventStoryId` concerns `storyId`.\n *\n * A missing id on *either* side matches everything. That keeps the protocol\n * backward compatible: a manager panel from a newer build still understands\n * an older preview bundle that emits unaddressed events, and vice versa.\n */\nexport const matchesStory = (\n eventStoryId: string | undefined,\n storyId: string | undefined\n): boolean => !eventStoryId || !storyId || eventStoryId === storyId;\n", "/**\n * The anatomy part table \u2014 pure presentation, no Storybook imports.\n *\n * This module is deliberately free of `storybook/manager-api` and\n * `storybook/preview-api`: it is bundled into *both* the manager entry (the\n * addon panel) and the blocks entry (the `<Anatomy>` MDX doc block), which\n * run in different runtimes and cannot share either of those APIs. Only the\n * data acquisition differs between the two; the markup must not.\n */\nimport React from 'react';\nimport { useTheme } from 'storybook/theming';\nimport { resolvePanelAccent } from '@component-anatomy/core';\nimport type {\n AnatomyPartDefinition,\n AnatomyPresetName,\n AnatomyTheme,\n} from '@component-anatomy/core';\n\n/**\n * The subset of Storybook's theme this table reads. Typed loosely on purpose:\n * `useTheme()` resolves to an empty `Theme` interface (Emotion augmentation),\n * and outside a ThemeProvider it returns `{}` \u2014 so every read is optional and\n * every value has a literal fallback below.\n */\ntype PartialStorybookTheme = {\n fgColor?: { default?: string; muted?: string };\n bgColor?: { default?: string; muted?: string };\n borderColor?: { default?: string };\n typography?: { fonts?: { base?: string; mono?: string } };\n};\n\nconst FONT_BASE_FALLBACK =\n '\"Nunito Sans\", -apple-system, \".SFNSText-Regular\", \"San Francisco\", BlinkMacSystemFont, \"Segoe UI\", \"Helvetica Neue\", Helvetica, Arial, sans-serif';\nconst FONT_MONO_FALLBACK = 'ui-monospace, \"Cascadia Code\", \"Fira Mono\", monospace';\n\n/**\n * Resolves the table's chrome colors from Storybook's theme so the same\n * markup reads correctly in the manager panel *and* in a docs page under a\n * dark theme.\n *\n * `surfaceBg`/`surfaceFg` are not painted anywhere \u2014 they are what the accent\n * is measured against in {@link useAccent}. They carry Storybook's own light\n * defaults as fallbacks so the measurement stays meaningful outside a\n * ThemeProvider, where `useTheme()` returns `{}`.\n */\nfunction usePalette() {\n const theme = useTheme() as PartialStorybookTheme;\n return {\n text: theme.fgColor?.default,\n muted: theme.fgColor?.muted ?? '#6b7280',\n mutedBg: theme.bgColor?.muted ?? 'rgba(0,0,0,0.06)',\n border: theme.borderColor?.default ?? 'rgba(0,0,0,0.08)',\n surfaceBg: theme.bgColor?.default ?? '#ffffff',\n surfaceFg: theme.fgColor?.default ?? '#2e3438',\n fontBase: theme.typography?.fonts?.base ?? FONT_BASE_FALLBACK,\n fontMono: theme.typography?.fonts?.mono ?? FONT_MONO_FALLBACK,\n };\n}\n\ntype Palette = ReturnType<typeof usePalette>;\n\n/**\n * The accent for the active row \u2014 the story's own `{ preset, theme }`, so the\n * table agrees with the overlays it describes, lifted to WCAG AA against the\n * surface it is painted on when the two disagree.\n *\n * The check is not optional polish: `preset: 'contrast'` is black on yellow\n * and the Storybook manager is dark by default, so the preset that exists for\n * users who need contrast is exactly the one that would land at 1.3:1 here.\n */\nfunction useAccent(palette: Palette, preset?: AnatomyPresetName, theme?: AnatomyTheme): string {\n return resolvePanelAccent(preset, theme, {\n background: palette.surfaceBg,\n foreground: palette.surfaceFg,\n });\n}\n\nconst makeStyles = (p: Palette): Record<string, React.CSSProperties> => ({\n container: {\n padding: '12px 16px',\n fontFamily: p.fontBase,\n fontSize: 13,\n lineHeight: 1.5,\n color: p.text,\n },\n empty: {\n color: p.muted,\n margin: 0,\n },\n code: {\n fontFamily: p.fontMono,\n fontSize: '0.85em',\n background: p.mutedBg,\n borderRadius: 3,\n padding: '1px 5px',\n },\n list: {\n display: 'flex',\n flexDirection: 'column',\n gap: 2,\n margin: 0,\n padding: 0,\n listStyle: 'none',\n },\n entry: {\n padding: '8px 10px',\n borderRadius: 6,\n border: '1px solid transparent',\n cursor: 'default',\n outline: 'none',\n transition: 'background 120ms ease, border-color 120ms ease',\n },\n header: {\n display: 'flex',\n alignItems: 'center',\n gap: 8,\n },\n indicator: {\n width: 8,\n height: 8,\n borderRadius: '50%',\n border: `2px solid ${p.border}`,\n flexShrink: 0,\n transition: 'background 120ms ease, border-color 120ms ease',\n },\n name: {\n fontWeight: 700,\n flex: 1,\n },\n id: {\n fontFamily: p.fontMono,\n fontSize: 10,\n padding: '1px 6px',\n borderRadius: 4,\n background: p.mutedBg,\n border: `1px solid ${p.border}`,\n color: p.muted,\n flexShrink: 0,\n },\n description: {\n margin: '4px 0 0',\n paddingLeft: 16,\n color: p.muted,\n },\n});\n\n/**\n * An inline `<code>` styled for the surrounding message text. Exported so\n * both runtimes can compose their own empty-state copy without duplicating\n * the style object.\n */\nexport const AnatomyCode: React.FC<{ children: React.ReactNode }> = ({ children }) => {\n const styles = makeStyles(usePalette());\n return <code style={styles.code}>{children}</code>;\n};\n\n/** A padded, muted paragraph \u2014 used for every \"nothing to show\" state. */\nexport const AnatomyMessage: React.FC<{ children: React.ReactNode }> = ({ children }) => {\n const styles = makeStyles(usePalette());\n return (\n <div style={styles.container}>\n <p style={styles.empty}>{children}</p>\n </div>\n );\n};\n\nexport type AnatomyTableProps = {\n /** Parts to list, in the order they should be shown. */\n parts: AnatomyPartDefinition[];\n /** Id of the part currently highlighted in the canvas, if any. */\n activeId?: string | null;\n /** The story's `anatomy.preset` \u2014 the active row follows it. */\n preset?: AnatomyPresetName;\n /** The story's `anatomy.theme` \u2014 token overrides on top of the preset. */\n theme?: AnatomyTheme;\n /** Called when the user hovers or focuses an entry. */\n onItemEnter?: (partId: string) => void;\n /** Called when the user leaves or blurs an entry. */\n onItemLeave?: () => void;\n};\n\nexport const AnatomyTable: React.FC<AnatomyTableProps> = ({\n parts,\n activeId = null,\n preset,\n theme,\n onItemEnter,\n onItemLeave,\n}) => {\n const palette = usePalette();\n const styles = makeStyles(palette);\n const accent = useAccent(palette, preset, theme);\n\n return (\n <div style={styles.container}>\n <ul style={styles.list} role=\"list\" aria-label=\"Anatomy parts\">\n {parts.map((part) => {\n const active = activeId === part.id;\n return (\n <li\n key={part.id}\n role=\"listitem\"\n tabIndex={0}\n aria-label={part.name}\n style={{\n ...styles.entry,\n background: active ? `color-mix(in srgb, ${accent} 7%, transparent)` : undefined,\n borderColor: active\n ? `color-mix(in srgb, ${accent} 20%, transparent)`\n : 'transparent',\n }}\n onMouseEnter={() => onItemEnter?.(part.id)}\n onMouseLeave={() => onItemLeave?.()}\n onFocus={() => onItemEnter?.(part.id)}\n onBlur={() => onItemLeave?.()}\n >\n <div style={styles.header}>\n <span\n aria-hidden=\"true\"\n style={{\n ...styles.indicator,\n background: active ? accent : undefined,\n borderColor: active ? accent : palette.border,\n }}\n />\n <span style={{ ...styles.name, color: active ? accent : undefined }}>\n {part.name}\n </span>\n <code style={styles.id}>{part.id}</code>\n </div>\n {part.description && <p style={styles.description}>{part.description}</p>}\n </li>\n );\n })}\n </ul>\n </div>\n );\n};\n"],
|
|
5
|
+
"mappings": ";AAqBA,OAAOA,UAAS,WAAW,gBAAgB;AAC3C,SAAS,cAAc;AACvB,SAAS,UAAU,aAAa;;;ACvBzB,IAAM,WAAW;AACjB,IAAM,WAAW,GAAG,QAAQ;AAG5B,IAAM,YAAY;AASlB,IAAM,SAAS;AAAA;AAAA,EAEpB,YAAY,GAAG,QAAQ;AAAA;AAAA,EAEvB,YAAY,GAAG,QAAQ;AAAA;AAAA,EAEvB,OAAO,GAAG,QAAQ;AAAA;AAAA,EAElB,YAAY,GAAG,QAAQ;AAAA;AAAA,EAEvB,YAAY,GAAG,QAAQ;AAAA;AAAA,EAEvB,eAAe,GAAG,QAAQ;AAC5B;;;ACKO,IAAM,eAAe,CAC1B,cACA,YACY,CA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ACF;AAEJ;",
|
|
6
6
|
"names": ["React", "React"]
|
|
7
7
|
}
|
package/dist/manager.js
CHANGED
|
@@ -32,7 +32,7 @@ var matchesStory = (eventStoryId, storyId) => !eventStoryId || !storyId || event
|
|
|
32
32
|
// src/AnatomyTable.tsx
|
|
33
33
|
import React from "react";
|
|
34
34
|
import { useTheme } from "storybook/theming";
|
|
35
|
-
|
|
35
|
+
import { resolvePanelAccent } from "@component-anatomy/core";
|
|
36
36
|
var FONT_BASE_FALLBACK = '"Nunito Sans", -apple-system, ".SFNSText-Regular", "San Francisco", BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif';
|
|
37
37
|
var FONT_MONO_FALLBACK = 'ui-monospace, "Cascadia Code", "Fira Mono", monospace';
|
|
38
38
|
function usePalette() {
|
|
@@ -42,10 +42,18 @@ function usePalette() {
|
|
|
42
42
|
muted: theme.fgColor?.muted ?? "#6b7280",
|
|
43
43
|
mutedBg: theme.bgColor?.muted ?? "rgba(0,0,0,0.06)",
|
|
44
44
|
border: theme.borderColor?.default ?? "rgba(0,0,0,0.08)",
|
|
45
|
+
surfaceBg: theme.bgColor?.default ?? "#ffffff",
|
|
46
|
+
surfaceFg: theme.fgColor?.default ?? "#2e3438",
|
|
45
47
|
fontBase: theme.typography?.fonts?.base ?? FONT_BASE_FALLBACK,
|
|
46
48
|
fontMono: theme.typography?.fonts?.mono ?? FONT_MONO_FALLBACK
|
|
47
49
|
};
|
|
48
50
|
}
|
|
51
|
+
function useAccent(palette, preset, theme) {
|
|
52
|
+
return resolvePanelAccent(preset, theme, {
|
|
53
|
+
background: palette.surfaceBg,
|
|
54
|
+
foreground: palette.surfaceFg
|
|
55
|
+
});
|
|
56
|
+
}
|
|
49
57
|
var makeStyles = (p) => ({
|
|
50
58
|
container: {
|
|
51
59
|
padding: "12px 16px",
|
|
@@ -125,12 +133,14 @@ var AnatomyMessage = ({ children }) => {
|
|
|
125
133
|
var AnatomyTable = ({
|
|
126
134
|
parts,
|
|
127
135
|
activeId = null,
|
|
128
|
-
|
|
136
|
+
preset,
|
|
137
|
+
theme,
|
|
129
138
|
onItemEnter,
|
|
130
139
|
onItemLeave
|
|
131
140
|
}) => {
|
|
132
141
|
const palette = usePalette();
|
|
133
142
|
const styles = makeStyles(palette);
|
|
143
|
+
const accent = useAccent(palette, preset, theme);
|
|
134
144
|
return /* @__PURE__ */ React.createElement("div", { style: styles.container }, /* @__PURE__ */ React.createElement("ul", { style: styles.list, role: "list", "aria-label": "Anatomy parts" }, parts.map((part) => {
|
|
135
145
|
const active = activeId === part.id;
|
|
136
146
|
return /* @__PURE__ */ React.createElement(
|
|
@@ -196,10 +206,12 @@ var Panel = () => {
|
|
|
196
206
|
emit(EVENTS.PARTS_REQUEST, { storyId });
|
|
197
207
|
}, [storyId]);
|
|
198
208
|
const parts = params?.parts ?? discovered;
|
|
199
|
-
|
|
200
|
-
if (!params || params.disable) {
|
|
209
|
+
if (!params) {
|
|
201
210
|
return /* @__PURE__ */ React2.createElement(AnatomyMessage, null, "No anatomy configured for this story. Add ", /* @__PURE__ */ React2.createElement(AnatomyCode, null, "parameters.anatomy"), " and annotate elements with ", /* @__PURE__ */ React2.createElement(AnatomyCode, null, 'data-part="name"'), ".");
|
|
202
211
|
}
|
|
212
|
+
if (params.disable) {
|
|
213
|
+
return /* @__PURE__ */ React2.createElement(AnatomyMessage, null, "Anatomy is disabled for this story (", /* @__PURE__ */ React2.createElement(AnatomyCode, null, "anatomy.disable"), ").");
|
|
214
|
+
}
|
|
203
215
|
if (parts.length === 0) {
|
|
204
216
|
return /* @__PURE__ */ React2.createElement(AnatomyMessage, null, "No parts found. Annotate elements in your story with", " ", /* @__PURE__ */ React2.createElement(AnatomyCode, null, 'data-part="name"'), " or pass", " ", /* @__PURE__ */ React2.createElement(AnatomyCode, null, "parameters.anatomy.parts"), ".");
|
|
205
217
|
}
|
|
@@ -208,7 +220,8 @@ var Panel = () => {
|
|
|
208
220
|
{
|
|
209
221
|
parts,
|
|
210
222
|
activeId,
|
|
211
|
-
|
|
223
|
+
preset: params.preset,
|
|
224
|
+
theme: params.theme,
|
|
212
225
|
onItemEnter: (partId) => emit(EVENTS.HOVER_ITEM, { storyId, partId }),
|
|
213
226
|
onItemLeave: () => emit(EVENTS.LEAVE_ITEM, { storyId })
|
|
214
227
|
}
|
package/dist/manager.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/manager.tsx", "../src/constants.ts", "../src/Panel.tsx", "../src/channel.ts", "../src/AnatomyTable.tsx"],
|
|
4
|
-
"sourcesContent": ["import React from 'react';\nimport { addons, types } from 'storybook/manager-api';\nimport { AddonPanel } from 'storybook/internal/components';\n\nimport { ADDON_ID, PANEL_ID, PARAM_KEY } from './constants.js';\nimport { Panel } from './Panel.js';\n\naddons.register(ADDON_ID, () => {\n addons.add(PANEL_ID, {\n type: types.PANEL,\n title: 'Anatomy',\n paramKey: PARAM_KEY,\n match: ({ viewMode }) => viewMode === 'story',\n render: ({ active }) => (\n <AddonPanel active={!!active}>\n <Panel />\n </AddonPanel>\n ),\n });\n});\n", "export const ADDON_ID = 'component-anatomy';\nexport const PANEL_ID = `${ADDON_ID}/panel`;\n\n/** Story parameter key: `parameters.anatomy = { ... }` */\nexport const PARAM_KEY = 'anatomy';\n\n/**\n * Channel events used to sync the manager panel \u2014 and the `<Anatomy>` MDX doc\n * block, which runs in the preview iframe \u2014 with the story canvas.\n *\n * Every payload carries the `storyId` it concerns; see `channel.ts` for the\n * payload types and the `matchesStory` filter each listener applies.\n */\nexport const EVENTS = {\n /** preview \u2192 consumers: a part became active in the canvas (hover/programmatic). */\n PART_ENTER: `${ADDON_ID}/part-enter`,\n /** preview \u2192 consumers: no part is active anymore. */\n PART_LEAVE: `${ADDON_ID}/part-leave`,\n /** preview \u2192 consumers: resolved part list for a story. */\n PARTS: `${ADDON_ID}/parts`,\n /** consumers \u2192 preview: the user hovers/focuses a panel entry. */\n HOVER_ITEM: `${ADDON_ID}/hover-item`,\n /** consumers \u2192 preview: the user left a panel entry. */\n LEAVE_ITEM: `${ADDON_ID}/leave-item`,\n /** consumers \u2192 preview: a panel/block mounted and wants the current part list. */\n PARTS_REQUEST: `${ADDON_ID}/parts-request`,\n} as const;\n", "import React, { useEffect, useState } from 'react';\nimport { useChannel, useParameter, useStorybookApi } from 'storybook/manager-api';\nimport type { AnatomyPartDefinition } from '@component-anatomy/core';\n\nimport { EVENTS, PARAM_KEY } from './constants.js';\nimport { matchesStory } from './channel.js';\nimport type { PartEnterEvent, PartsEvent, StoryScopedEvent } from './channel.js';\nimport { ACCENT_FALLBACK, AnatomyCode, AnatomyMessage, AnatomyTable } from './AnatomyTable.js';\nimport type { AnatomyParameters } from './types.js';\n\nexport const Panel: React.FC = () => {\n const params = useParameter<AnatomyParameters | undefined>(PARAM_KEY, undefined);\n const api = useStorybookApi();\n const storyId = api.getUrlState().storyId;\n\n const [discovered, setDiscovered] = useState<AnatomyPartDefinition[]>([]);\n const [activeId, setActiveId] = useState<string | null>(null);\n\n // `useChannel` captures its handlers on the given deps \u2014 `storyId` has to be\n // listed or the filters below would close over a stale story.\n const emit = useChannel(\n {\n [EVENTS.PARTS]: (event: PartsEvent) => {\n if (!matchesStory(event?.storyId, storyId)) return;\n setDiscovered(event.parts);\n },\n [EVENTS.PART_ENTER]: (event: PartEnterEvent) => {\n if (!matchesStory(event?.storyId, storyId)) return;\n setActiveId(event.partId);\n },\n [EVENTS.PART_LEAVE]: (event: StoryScopedEvent = {}) => {\n if (!matchesStory(event?.storyId, storyId)) return;\n setActiveId(null);\n },\n },\n [storyId]\n );\n\n // Ask the preview for the current part list on mount / story change.\n useEffect(() => {\n setDiscovered([]);\n setActiveId(null);\n emit(EVENTS.PARTS_REQUEST, { storyId } satisfies StoryScopedEvent);\n }, [storyId]);\n\n const parts = params?.parts ?? discovered;\n const accent = params?.theme?.accent ?? ACCENT_FALLBACK;\n\n if (!params || params.disable) {\n return (\n <AnatomyMessage>\n No anatomy configured for this story. Add <AnatomyCode>parameters.anatomy</AnatomyCode> and\n annotate elements with <AnatomyCode>data-part=\"name\"</AnatomyCode>.\n </AnatomyMessage>\n );\n }\n\n if (parts.length === 0) {\n return (\n <AnatomyMessage>\n No parts found. Annotate elements in your story with{' '}\n <AnatomyCode>data-part=\"name\"</AnatomyCode> or pass{' '}\n <AnatomyCode>parameters.anatomy.parts</AnatomyCode>.\n </AnatomyMessage>\n );\n }\n\n return (\n <AnatomyTable\n parts={parts}\n activeId={activeId}\n accent={accent}\n onItemEnter={(partId) => emit(EVENTS.HOVER_ITEM, { storyId, partId })}\n onItemLeave={() => emit(EVENTS.LEAVE_ITEM, { storyId })}\n />\n );\n};\n", "/**\n * Shared channel payload contract between the preview decorator, the manager\n * panel, and the MDX doc block.\n *\n * Every payload carries the `storyId` it refers to. In story view this is\n * redundant \u2014 only one story is mounted \u2014 but a docs page mounts *many*\n * stories at once, each with its own controller, and each `<Anatomy>` block\n * must talk to exactly one of them. Without addressing, hovering a part in\n * one block highlights the matching part in every other story on the page.\n */\nimport type { AnatomyPartDefinition } from '@component-anatomy/core';\n\n/** preview \u2192 consumers: the resolved part list for one story. */\nexport type PartsEvent = { storyId?: string; parts: AnatomyPartDefinition[] };\n\n/** preview \u2192 consumers: a part became active in that story's canvas. */\nexport type PartEnterEvent = { storyId?: string; partId: string };\n\n/** consumer \u2192 preview: highlight this part in that story's canvas. */\nexport type HoverItemEvent = { storyId?: string; partId: string };\n\n/** Payload for the events that only need to name a story. */\nexport type StoryScopedEvent = { storyId?: string };\n\n/**\n * Whether an event addressed to `eventStoryId` concerns `storyId`.\n *\n * A missing id on *either* side matches everything. That keeps the protocol\n * backward compatible: a manager panel from a newer build still understands\n * an older preview bundle that emits unaddressed events, and vice versa.\n */\nexport const matchesStory = (\n eventStoryId: string | undefined,\n storyId: string | undefined\n): boolean => !eventStoryId || !storyId || eventStoryId === storyId;\n", "/**\n * The anatomy part table \u2014 pure presentation, no Storybook imports.\n *\n * This module is deliberately free of `storybook/manager-api` and\n * `storybook/preview-api`: it is bundled into *both* the manager entry (the\n * addon panel) and the blocks entry (the `<Anatomy>` MDX doc block), which\n * run in different runtimes and cannot share either of those APIs. Only the\n * data acquisition differs between the two; the markup must not.\n */\nimport React from 'react';\nimport { useTheme } from 'storybook/theming';\nimport type { AnatomyPartDefinition } from '@component-anatomy/core';\n\n/** Fallback accent when the story sets no `anatomy.theme.accent`. */\nexport const ACCENT_FALLBACK = '#4f46e5';\n\n/**\n * The subset of Storybook's theme this table reads. Typed loosely on purpose:\n * `useTheme()` resolves to an empty `Theme` interface (Emotion augmentation),\n * and outside a ThemeProvider it returns `{}` \u2014 so every read is optional and\n * every value has a literal fallback below.\n */\ntype PartialStorybookTheme = {\n fgColor?: { default?: string; muted?: string };\n bgColor?: { muted?: string };\n borderColor?: { default?: string };\n typography?: { fonts?: { base?: string; mono?: string } };\n};\n\nconst FONT_BASE_FALLBACK =\n '\"Nunito Sans\", -apple-system, \".SFNSText-Regular\", \"San Francisco\", BlinkMacSystemFont, \"Segoe UI\", \"Helvetica Neue\", Helvetica, Arial, sans-serif';\nconst FONT_MONO_FALLBACK = 'ui-monospace, \"Cascadia Code\", \"Fira Mono\", monospace';\n\n/**\n * Resolves the table's chrome colors from Storybook's theme so the same\n * markup reads correctly in the manager panel *and* in a docs page under a\n * dark theme. The accent is intentionally not theme-derived \u2014 it is the\n * addon's identity color and stays stable unless a story overrides it.\n */\nfunction usePalette() {\n const theme = useTheme() as PartialStorybookTheme;\n return {\n text: theme.fgColor?.default,\n muted: theme.fgColor?.muted ?? '#6b7280',\n mutedBg: theme.bgColor?.muted ?? 'rgba(0,0,0,0.06)',\n border: theme.borderColor?.default ?? 'rgba(0,0,0,0.08)',\n fontBase: theme.typography?.fonts?.base ?? FONT_BASE_FALLBACK,\n fontMono: theme.typography?.fonts?.mono ?? FONT_MONO_FALLBACK,\n };\n}\n\ntype Palette = ReturnType<typeof usePalette>;\n\nconst makeStyles = (p: Palette): Record<string, React.CSSProperties> => ({\n container: {\n padding: '12px 16px',\n fontFamily: p.fontBase,\n fontSize: 13,\n lineHeight: 1.5,\n color: p.text,\n },\n empty: {\n color: p.muted,\n margin: 0,\n },\n code: {\n fontFamily: p.fontMono,\n fontSize: '0.85em',\n background: p.mutedBg,\n borderRadius: 3,\n padding: '1px 5px',\n },\n list: {\n display: 'flex',\n flexDirection: 'column',\n gap: 2,\n margin: 0,\n padding: 0,\n listStyle: 'none',\n },\n entry: {\n padding: '8px 10px',\n borderRadius: 6,\n border: '1px solid transparent',\n cursor: 'default',\n outline: 'none',\n transition: 'background 120ms ease, border-color 120ms ease',\n },\n header: {\n display: 'flex',\n alignItems: 'center',\n gap: 8,\n },\n indicator: {\n width: 8,\n height: 8,\n borderRadius: '50%',\n border: `2px solid ${p.border}`,\n flexShrink: 0,\n transition: 'background 120ms ease, border-color 120ms ease',\n },\n name: {\n fontWeight: 700,\n flex: 1,\n },\n id: {\n fontFamily: p.fontMono,\n fontSize: 10,\n padding: '1px 6px',\n borderRadius: 4,\n background: p.mutedBg,\n border: `1px solid ${p.border}`,\n color: p.muted,\n flexShrink: 0,\n },\n description: {\n margin: '4px 0 0',\n paddingLeft: 16,\n color: p.muted,\n },\n});\n\n/**\n * An inline `<code>` styled for the surrounding message text. Exported so\n * both runtimes can compose their own empty-state copy without duplicating\n * the style object.\n */\nexport const AnatomyCode: React.FC<{ children: React.ReactNode }> = ({ children }) => {\n const styles = makeStyles(usePalette());\n return <code style={styles.code}>{children}</code>;\n};\n\n/** A padded, muted paragraph \u2014 used for every \"nothing to show\" state. */\nexport const AnatomyMessage: React.FC<{ children: React.ReactNode }> = ({ children }) => {\n const styles = makeStyles(usePalette());\n return (\n <div style={styles.container}>\n <p style={styles.empty}>{children}</p>\n </div>\n );\n};\n\nexport type AnatomyTableProps = {\n /** Parts to list, in the order they should be shown. */\n parts: AnatomyPartDefinition[];\n /** Id of the part currently highlighted in the canvas, if any. */\n activeId?: string | null;\n /** Accent color for the active state. Defaults to {@link ACCENT_FALLBACK}. */\n accent?: string;\n /** Called when the user hovers or focuses an entry. */\n onItemEnter?: (partId: string) => void;\n /** Called when the user leaves or blurs an entry. */\n onItemLeave?: () => void;\n};\n\nexport const AnatomyTable: React.FC<AnatomyTableProps> = ({\n parts,\n activeId = null,\n accent = ACCENT_FALLBACK,\n onItemEnter,\n onItemLeave,\n}) => {\n const palette = usePalette();\n const styles = makeStyles(palette);\n\n return (\n <div style={styles.container}>\n <ul style={styles.list} role=\"list\" aria-label=\"Anatomy parts\">\n {parts.map((part) => {\n const active = activeId === part.id;\n return (\n <li\n key={part.id}\n role=\"listitem\"\n tabIndex={0}\n aria-label={part.name}\n style={{\n ...styles.entry,\n background: active ? `color-mix(in srgb, ${accent} 7%, transparent)` : undefined,\n borderColor: active\n ? `color-mix(in srgb, ${accent} 20%, transparent)`\n : 'transparent',\n }}\n onMouseEnter={() => onItemEnter?.(part.id)}\n onMouseLeave={() => onItemLeave?.()}\n onFocus={() => onItemEnter?.(part.id)}\n onBlur={() => onItemLeave?.()}\n >\n <div style={styles.header}>\n <span\n aria-hidden=\"true\"\n style={{\n ...styles.indicator,\n background: active ? accent : undefined,\n borderColor: active ? accent : palette.border,\n }}\n />\n <span style={{ ...styles.name, color: active ? accent : undefined }}>\n {part.name}\n </span>\n <code style={styles.id}>{part.id}</code>\n </div>\n {part.description && <p style={styles.description}>{part.description}</p>}\n </li>\n );\n })}\n </ul>\n </div>\n );\n};\n"],
|
|
5
|
-
"mappings": ";AAAA,OAAOA,YAAW;AAClB,SAAS,QAAQ,aAAa;AAC9B,SAAS,kBAAkB;;;ACFpB,IAAM,WAAW;AACjB,IAAM,WAAW,GAAG,QAAQ;AAG5B,IAAM,YAAY;AASlB,IAAM,SAAS;AAAA;AAAA,EAEpB,YAAY,GAAG,QAAQ;AAAA;AAAA,EAEvB,YAAY,GAAG,QAAQ;AAAA;AAAA,EAEvB,OAAO,GAAG,QAAQ;AAAA;AAAA,EAElB,YAAY,GAAG,QAAQ;AAAA;AAAA,EAEvB,YAAY,GAAG,QAAQ;AAAA;AAAA,EAEvB,eAAe,GAAG,QAAQ;AAC5B;;;AC1BA,OAAOC,UAAS,WAAW,gBAAgB;AAC3C,SAAS,YAAY,cAAc,uBAAuB;;;AC8BnD,IAAM,eAAe,CAC1B,cACA,YACY,CAAC,gBAAgB,CAAC,WAAW,iBAAiB;;;ACzB5D,OAAO,WAAW;AAClB,SAAS,gBAAgB;
|
|
4
|
+
"sourcesContent": ["import React from 'react';\nimport { addons, types } from 'storybook/manager-api';\nimport { AddonPanel } from 'storybook/internal/components';\n\nimport { ADDON_ID, PANEL_ID, PARAM_KEY } from './constants.js';\nimport { Panel } from './Panel.js';\n\naddons.register(ADDON_ID, () => {\n addons.add(PANEL_ID, {\n type: types.PANEL,\n title: 'Anatomy',\n paramKey: PARAM_KEY,\n match: ({ viewMode }) => viewMode === 'story',\n render: ({ active }) => (\n <AddonPanel active={!!active}>\n <Panel />\n </AddonPanel>\n ),\n });\n});\n", "export const ADDON_ID = 'component-anatomy';\nexport const PANEL_ID = `${ADDON_ID}/panel`;\n\n/** Story parameter key: `parameters.anatomy = { ... }` */\nexport const PARAM_KEY = 'anatomy';\n\n/**\n * Channel events used to sync the manager panel \u2014 and the `<Anatomy>` MDX doc\n * block, which runs in the preview iframe \u2014 with the story canvas.\n *\n * Every payload carries the `storyId` it concerns; see `channel.ts` for the\n * payload types and the `matchesStory` filter each listener applies.\n */\nexport const EVENTS = {\n /** preview \u2192 consumers: a part became active in the canvas (hover/programmatic). */\n PART_ENTER: `${ADDON_ID}/part-enter`,\n /** preview \u2192 consumers: no part is active anymore. */\n PART_LEAVE: `${ADDON_ID}/part-leave`,\n /** preview \u2192 consumers: resolved part list for a story. */\n PARTS: `${ADDON_ID}/parts`,\n /** consumers \u2192 preview: the user hovers/focuses a panel entry. */\n HOVER_ITEM: `${ADDON_ID}/hover-item`,\n /** consumers \u2192 preview: the user left a panel entry. */\n LEAVE_ITEM: `${ADDON_ID}/leave-item`,\n /** consumers \u2192 preview: a panel/block mounted and wants the current part list. */\n PARTS_REQUEST: `${ADDON_ID}/parts-request`,\n} as const;\n", "import React, { useEffect, useState } from 'react';\nimport { useChannel, useParameter, useStorybookApi } from 'storybook/manager-api';\nimport type { AnatomyPartDefinition } from '@component-anatomy/core';\n\nimport { EVENTS, PARAM_KEY } from './constants.js';\nimport { matchesStory } from './channel.js';\nimport type { PartEnterEvent, PartsEvent, StoryScopedEvent } from './channel.js';\nimport { AnatomyCode, AnatomyMessage, AnatomyTable } from './AnatomyTable.js';\nimport type { AnatomyParameters } from './types.js';\n\nexport const Panel: React.FC = () => {\n const params = useParameter<AnatomyParameters | undefined>(PARAM_KEY, undefined);\n const api = useStorybookApi();\n const storyId = api.getUrlState().storyId;\n\n const [discovered, setDiscovered] = useState<AnatomyPartDefinition[]>([]);\n const [activeId, setActiveId] = useState<string | null>(null);\n\n // `useChannel` captures its handlers on the given deps \u2014 `storyId` has to be\n // listed or the filters below would close over a stale story.\n const emit = useChannel(\n {\n [EVENTS.PARTS]: (event: PartsEvent) => {\n if (!matchesStory(event?.storyId, storyId)) return;\n setDiscovered(event.parts);\n },\n [EVENTS.PART_ENTER]: (event: PartEnterEvent) => {\n if (!matchesStory(event?.storyId, storyId)) return;\n setActiveId(event.partId);\n },\n [EVENTS.PART_LEAVE]: (event: StoryScopedEvent = {}) => {\n if (!matchesStory(event?.storyId, storyId)) return;\n setActiveId(null);\n },\n },\n [storyId]\n );\n\n // Ask the preview for the current part list on mount / story change.\n useEffect(() => {\n setDiscovered([]);\n setActiveId(null);\n emit(EVENTS.PARTS_REQUEST, { storyId } satisfies StoryScopedEvent);\n }, [storyId]);\n\n const parts = params?.parts ?? discovered;\n\n if (!params) {\n return (\n <AnatomyMessage>\n No anatomy configured for this story. Add <AnatomyCode>parameters.anatomy</AnatomyCode> and\n annotate elements with <AnatomyCode>data-part=\"name\"</AnatomyCode>.\n </AnatomyMessage>\n );\n }\n\n // Defence in depth: Storybook removes a panel from the tab bar entirely when\n // `parameters[paramKey].disable` is set, so this normally never renders. If\n // it ever does, say the right thing \u2014 a disabled story *has* an anatomy, and\n // telling its author to add one sends them the wrong way.\n if (params.disable) {\n return (\n <AnatomyMessage>\n Anatomy is disabled for this story (<AnatomyCode>anatomy.disable</AnatomyCode>).\n </AnatomyMessage>\n );\n }\n\n if (parts.length === 0) {\n return (\n <AnatomyMessage>\n No parts found. Annotate elements in your story with{' '}\n <AnatomyCode>data-part=\"name\"</AnatomyCode> or pass{' '}\n <AnatomyCode>parameters.anatomy.parts</AnatomyCode>.\n </AnatomyMessage>\n );\n }\n\n return (\n <AnatomyTable\n parts={parts}\n activeId={activeId}\n preset={params.preset}\n theme={params.theme}\n onItemEnter={(partId) => emit(EVENTS.HOVER_ITEM, { storyId, partId })}\n onItemLeave={() => emit(EVENTS.LEAVE_ITEM, { storyId })}\n />\n );\n};\n", "/**\n * Shared channel payload contract between the preview decorator, the manager\n * panel, and the MDX doc block.\n *\n * Every payload carries the `storyId` it refers to. In story view this is\n * redundant \u2014 only one story is mounted \u2014 but a docs page mounts *many*\n * stories at once, each with its own controller, and each `<Anatomy>` block\n * must talk to exactly one of them. Without addressing, hovering a part in\n * one block highlights the matching part in every other story on the page.\n */\nimport type { AnatomyPartDefinition } from '@component-anatomy/core';\n\n/** preview \u2192 consumers: the resolved part list for one story. */\nexport type PartsEvent = { storyId?: string; parts: AnatomyPartDefinition[] };\n\n/** preview \u2192 consumers: a part became active in that story's canvas. */\nexport type PartEnterEvent = { storyId?: string; partId: string };\n\n/** consumer \u2192 preview: highlight this part in that story's canvas. */\nexport type HoverItemEvent = { storyId?: string; partId: string };\n\n/** Payload for the events that only need to name a story. */\nexport type StoryScopedEvent = { storyId?: string };\n\n/**\n * Whether an event addressed to `eventStoryId` concerns `storyId`.\n *\n * A missing id on *either* side matches everything. That keeps the protocol\n * backward compatible: a manager panel from a newer build still understands\n * an older preview bundle that emits unaddressed events, and vice versa.\n */\nexport const matchesStory = (\n eventStoryId: string | undefined,\n storyId: string | undefined\n): boolean => !eventStoryId || !storyId || eventStoryId === storyId;\n", "/**\n * The anatomy part table \u2014 pure presentation, no Storybook imports.\n *\n * This module is deliberately free of `storybook/manager-api` and\n * `storybook/preview-api`: it is bundled into *both* the manager entry (the\n * addon panel) and the blocks entry (the `<Anatomy>` MDX doc block), which\n * run in different runtimes and cannot share either of those APIs. Only the\n * data acquisition differs between the two; the markup must not.\n */\nimport React from 'react';\nimport { useTheme } from 'storybook/theming';\nimport { resolvePanelAccent } from '@component-anatomy/core';\nimport type {\n AnatomyPartDefinition,\n AnatomyPresetName,\n AnatomyTheme,\n} from '@component-anatomy/core';\n\n/**\n * The subset of Storybook's theme this table reads. Typed loosely on purpose:\n * `useTheme()` resolves to an empty `Theme` interface (Emotion augmentation),\n * and outside a ThemeProvider it returns `{}` \u2014 so every read is optional and\n * every value has a literal fallback below.\n */\ntype PartialStorybookTheme = {\n fgColor?: { default?: string; muted?: string };\n bgColor?: { default?: string; muted?: string };\n borderColor?: { default?: string };\n typography?: { fonts?: { base?: string; mono?: string } };\n};\n\nconst FONT_BASE_FALLBACK =\n '\"Nunito Sans\", -apple-system, \".SFNSText-Regular\", \"San Francisco\", BlinkMacSystemFont, \"Segoe UI\", \"Helvetica Neue\", Helvetica, Arial, sans-serif';\nconst FONT_MONO_FALLBACK = 'ui-monospace, \"Cascadia Code\", \"Fira Mono\", monospace';\n\n/**\n * Resolves the table's chrome colors from Storybook's theme so the same\n * markup reads correctly in the manager panel *and* in a docs page under a\n * dark theme.\n *\n * `surfaceBg`/`surfaceFg` are not painted anywhere \u2014 they are what the accent\n * is measured against in {@link useAccent}. They carry Storybook's own light\n * defaults as fallbacks so the measurement stays meaningful outside a\n * ThemeProvider, where `useTheme()` returns `{}`.\n */\nfunction usePalette() {\n const theme = useTheme() as PartialStorybookTheme;\n return {\n text: theme.fgColor?.default,\n muted: theme.fgColor?.muted ?? '#6b7280',\n mutedBg: theme.bgColor?.muted ?? 'rgba(0,0,0,0.06)',\n border: theme.borderColor?.default ?? 'rgba(0,0,0,0.08)',\n surfaceBg: theme.bgColor?.default ?? '#ffffff',\n surfaceFg: theme.fgColor?.default ?? '#2e3438',\n fontBase: theme.typography?.fonts?.base ?? FONT_BASE_FALLBACK,\n fontMono: theme.typography?.fonts?.mono ?? FONT_MONO_FALLBACK,\n };\n}\n\ntype Palette = ReturnType<typeof usePalette>;\n\n/**\n * The accent for the active row \u2014 the story's own `{ preset, theme }`, so the\n * table agrees with the overlays it describes, lifted to WCAG AA against the\n * surface it is painted on when the two disagree.\n *\n * The check is not optional polish: `preset: 'contrast'` is black on yellow\n * and the Storybook manager is dark by default, so the preset that exists for\n * users who need contrast is exactly the one that would land at 1.3:1 here.\n */\nfunction useAccent(palette: Palette, preset?: AnatomyPresetName, theme?: AnatomyTheme): string {\n return resolvePanelAccent(preset, theme, {\n background: palette.surfaceBg,\n foreground: palette.surfaceFg,\n });\n}\n\nconst makeStyles = (p: Palette): Record<string, React.CSSProperties> => ({\n container: {\n padding: '12px 16px',\n fontFamily: p.fontBase,\n fontSize: 13,\n lineHeight: 1.5,\n color: p.text,\n },\n empty: {\n color: p.muted,\n margin: 0,\n },\n code: {\n fontFamily: p.fontMono,\n fontSize: '0.85em',\n background: p.mutedBg,\n borderRadius: 3,\n padding: '1px 5px',\n },\n list: {\n display: 'flex',\n flexDirection: 'column',\n gap: 2,\n margin: 0,\n padding: 0,\n listStyle: 'none',\n },\n entry: {\n padding: '8px 10px',\n borderRadius: 6,\n border: '1px solid transparent',\n cursor: 'default',\n outline: 'none',\n transition: 'background 120ms ease, border-color 120ms ease',\n },\n header: {\n display: 'flex',\n alignItems: 'center',\n gap: 8,\n },\n indicator: {\n width: 8,\n height: 8,\n borderRadius: '50%',\n border: `2px solid ${p.border}`,\n flexShrink: 0,\n transition: 'background 120ms ease, border-color 120ms ease',\n },\n name: {\n fontWeight: 700,\n flex: 1,\n },\n id: {\n fontFamily: p.fontMono,\n fontSize: 10,\n padding: '1px 6px',\n borderRadius: 4,\n background: p.mutedBg,\n border: `1px solid ${p.border}`,\n color: p.muted,\n flexShrink: 0,\n },\n description: {\n margin: '4px 0 0',\n paddingLeft: 16,\n color: p.muted,\n },\n});\n\n/**\n * An inline `<code>` styled for the surrounding message text. Exported so\n * both runtimes can compose their own empty-state copy without duplicating\n * the style object.\n */\nexport const AnatomyCode: React.FC<{ children: React.ReactNode }> = ({ children }) => {\n const styles = makeStyles(usePalette());\n return <code style={styles.code}>{children}</code>;\n};\n\n/** A padded, muted paragraph \u2014 used for every \"nothing to show\" state. */\nexport const AnatomyMessage: React.FC<{ children: React.ReactNode }> = ({ children }) => {\n const styles = makeStyles(usePalette());\n return (\n <div style={styles.container}>\n <p style={styles.empty}>{children}</p>\n </div>\n );\n};\n\nexport type AnatomyTableProps = {\n /** Parts to list, in the order they should be shown. */\n parts: AnatomyPartDefinition[];\n /** Id of the part currently highlighted in the canvas, if any. */\n activeId?: string | null;\n /** The story's `anatomy.preset` \u2014 the active row follows it. */\n preset?: AnatomyPresetName;\n /** The story's `anatomy.theme` \u2014 token overrides on top of the preset. */\n theme?: AnatomyTheme;\n /** Called when the user hovers or focuses an entry. */\n onItemEnter?: (partId: string) => void;\n /** Called when the user leaves or blurs an entry. */\n onItemLeave?: () => void;\n};\n\nexport const AnatomyTable: React.FC<AnatomyTableProps> = ({\n parts,\n activeId = null,\n preset,\n theme,\n onItemEnter,\n onItemLeave,\n}) => {\n const palette = usePalette();\n const styles = makeStyles(palette);\n const accent = useAccent(palette, preset, theme);\n\n return (\n <div style={styles.container}>\n <ul style={styles.list} role=\"list\" aria-label=\"Anatomy parts\">\n {parts.map((part) => {\n const active = activeId === part.id;\n return (\n <li\n key={part.id}\n role=\"listitem\"\n tabIndex={0}\n aria-label={part.name}\n style={{\n ...styles.entry,\n background: active ? `color-mix(in srgb, ${accent} 7%, transparent)` : undefined,\n borderColor: active\n ? `color-mix(in srgb, ${accent} 20%, transparent)`\n : 'transparent',\n }}\n onMouseEnter={() => onItemEnter?.(part.id)}\n onMouseLeave={() => onItemLeave?.()}\n onFocus={() => onItemEnter?.(part.id)}\n onBlur={() => onItemLeave?.()}\n >\n <div style={styles.header}>\n <span\n aria-hidden=\"true\"\n style={{\n ...styles.indicator,\n background: active ? accent : undefined,\n borderColor: active ? accent : palette.border,\n }}\n />\n <span style={{ ...styles.name, color: active ? accent : undefined }}>\n {part.name}\n </span>\n <code style={styles.id}>{part.id}</code>\n </div>\n {part.description && <p style={styles.description}>{part.description}</p>}\n </li>\n );\n })}\n </ul>\n </div>\n );\n};\n"],
|
|
5
|
+
"mappings": ";AAAA,OAAOA,YAAW;AAClB,SAAS,QAAQ,aAAa;AAC9B,SAAS,kBAAkB;;;ACFpB,IAAM,WAAW;AACjB,IAAM,WAAW,GAAG,QAAQ;AAG5B,IAAM,YAAY;AASlB,IAAM,SAAS;AAAA;AAAA,EAEpB,YAAY,GAAG,QAAQ;AAAA;AAAA,EAEvB,YAAY,GAAG,QAAQ;AAAA;AAAA,EAEvB,OAAO,GAAG,QAAQ;AAAA;AAAA,EAElB,YAAY,GAAG,QAAQ;AAAA;AAAA,EAEvB,YAAY,GAAG,QAAQ;AAAA;AAAA,EAEvB,eAAe,GAAG,QAAQ;AAC5B;;;AC1BA,OAAOC,UAAS,WAAW,gBAAgB;AAC3C,SAAS,YAAY,cAAc,uBAAuB;;;AC8BnD,IAAM,eAAe,CAC1B,cACA,YACY,CAAC,gBAAgB,CAAC,WAAW,iBAAiB;;;ACzB5D,OAAO,WAAW;AAClB,SAAS,gBAAgB;AACzB,SAAS,0BAA0B;AAoBnC,IAAM,qBACJ;AACF,IAAM,qBAAqB;AAY3B,SAAS,aAAa;AACpB,QAAM,QAAQ,SAAS;AACvB,SAAO;AAAA,IACL,MAAM,MAAM,SAAS;AAAA,IACrB,OAAO,MAAM,SAAS,SAAS;AAAA,IAC/B,SAAS,MAAM,SAAS,SAAS;AAAA,IACjC,QAAQ,MAAM,aAAa,WAA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AAA,IACtC,QAAQ,CAAC,EAAE,OAAO,MAChB,gBAAAC,OAAA,cAAC,cAAW,QAAQ,CAAC,CAAC,UACpB,gBAAAA,OAAA,cAAC,WAAM,CACT;AAAA,EAEJ,CAAC;AACH,CAAC;",
|
|
6
6
|
"names": ["React", "React", "React", "React"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@component-anatomy/storybook",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Storybook addon — interactive component anatomy panel synced with the story canvas",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Julien Déramond",
|
|
@@ -60,12 +60,12 @@
|
|
|
60
60
|
"access": "public"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@component-anatomy/core": "^0.0
|
|
63
|
+
"@component-anatomy/core": "^0.1.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@storybook/addon-docs": "^10.5.2",
|
|
67
67
|
"@types/react": "^19.2.18",
|
|
68
|
-
"esbuild": "^0.28.
|
|
68
|
+
"esbuild": "^0.28.2",
|
|
69
69
|
"react": "^19.2.8",
|
|
70
70
|
"react-dom": "^19.2.8",
|
|
71
71
|
"storybook": "^10.5.10",
|
package/src/AnatomyTable.tsx
CHANGED
|
@@ -9,10 +9,12 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import React from 'react';
|
|
11
11
|
import { useTheme } from 'storybook/theming';
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
import { resolvePanelAccent } from '@component-anatomy/core';
|
|
13
|
+
import type {
|
|
14
|
+
AnatomyPartDefinition,
|
|
15
|
+
AnatomyPresetName,
|
|
16
|
+
AnatomyTheme,
|
|
17
|
+
} from '@component-anatomy/core';
|
|
16
18
|
|
|
17
19
|
/**
|
|
18
20
|
* The subset of Storybook's theme this table reads. Typed loosely on purpose:
|
|
@@ -22,7 +24,7 @@ export const ACCENT_FALLBACK = '#4f46e5';
|
|
|
22
24
|
*/
|
|
23
25
|
type PartialStorybookTheme = {
|
|
24
26
|
fgColor?: { default?: string; muted?: string };
|
|
25
|
-
bgColor?: { muted?: string };
|
|
27
|
+
bgColor?: { default?: string; muted?: string };
|
|
26
28
|
borderColor?: { default?: string };
|
|
27
29
|
typography?: { fonts?: { base?: string; mono?: string } };
|
|
28
30
|
};
|
|
@@ -34,8 +36,12 @@ const FONT_MONO_FALLBACK = 'ui-monospace, "Cascadia Code", "Fira Mono", monospac
|
|
|
34
36
|
/**
|
|
35
37
|
* Resolves the table's chrome colors from Storybook's theme so the same
|
|
36
38
|
* markup reads correctly in the manager panel *and* in a docs page under a
|
|
37
|
-
* dark theme.
|
|
38
|
-
*
|
|
39
|
+
* dark theme.
|
|
40
|
+
*
|
|
41
|
+
* `surfaceBg`/`surfaceFg` are not painted anywhere — they are what the accent
|
|
42
|
+
* is measured against in {@link useAccent}. They carry Storybook's own light
|
|
43
|
+
* defaults as fallbacks so the measurement stays meaningful outside a
|
|
44
|
+
* ThemeProvider, where `useTheme()` returns `{}`.
|
|
39
45
|
*/
|
|
40
46
|
function usePalette() {
|
|
41
47
|
const theme = useTheme() as PartialStorybookTheme;
|
|
@@ -44,6 +50,8 @@ function usePalette() {
|
|
|
44
50
|
muted: theme.fgColor?.muted ?? '#6b7280',
|
|
45
51
|
mutedBg: theme.bgColor?.muted ?? 'rgba(0,0,0,0.06)',
|
|
46
52
|
border: theme.borderColor?.default ?? 'rgba(0,0,0,0.08)',
|
|
53
|
+
surfaceBg: theme.bgColor?.default ?? '#ffffff',
|
|
54
|
+
surfaceFg: theme.fgColor?.default ?? '#2e3438',
|
|
47
55
|
fontBase: theme.typography?.fonts?.base ?? FONT_BASE_FALLBACK,
|
|
48
56
|
fontMono: theme.typography?.fonts?.mono ?? FONT_MONO_FALLBACK,
|
|
49
57
|
};
|
|
@@ -51,6 +59,22 @@ function usePalette() {
|
|
|
51
59
|
|
|
52
60
|
type Palette = ReturnType<typeof usePalette>;
|
|
53
61
|
|
|
62
|
+
/**
|
|
63
|
+
* The accent for the active row — the story's own `{ preset, theme }`, so the
|
|
64
|
+
* table agrees with the overlays it describes, lifted to WCAG AA against the
|
|
65
|
+
* surface it is painted on when the two disagree.
|
|
66
|
+
*
|
|
67
|
+
* The check is not optional polish: `preset: 'contrast'` is black on yellow
|
|
68
|
+
* and the Storybook manager is dark by default, so the preset that exists for
|
|
69
|
+
* users who need contrast is exactly the one that would land at 1.3:1 here.
|
|
70
|
+
*/
|
|
71
|
+
function useAccent(palette: Palette, preset?: AnatomyPresetName, theme?: AnatomyTheme): string {
|
|
72
|
+
return resolvePanelAccent(preset, theme, {
|
|
73
|
+
background: palette.surfaceBg,
|
|
74
|
+
foreground: palette.surfaceFg,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
54
78
|
const makeStyles = (p: Palette): Record<string, React.CSSProperties> => ({
|
|
55
79
|
container: {
|
|
56
80
|
padding: '12px 16px',
|
|
@@ -145,8 +169,10 @@ export type AnatomyTableProps = {
|
|
|
145
169
|
parts: AnatomyPartDefinition[];
|
|
146
170
|
/** Id of the part currently highlighted in the canvas, if any. */
|
|
147
171
|
activeId?: string | null;
|
|
148
|
-
/**
|
|
149
|
-
|
|
172
|
+
/** The story's `anatomy.preset` — the active row follows it. */
|
|
173
|
+
preset?: AnatomyPresetName;
|
|
174
|
+
/** The story's `anatomy.theme` — token overrides on top of the preset. */
|
|
175
|
+
theme?: AnatomyTheme;
|
|
150
176
|
/** Called when the user hovers or focuses an entry. */
|
|
151
177
|
onItemEnter?: (partId: string) => void;
|
|
152
178
|
/** Called when the user leaves or blurs an entry. */
|
|
@@ -156,12 +182,14 @@ export type AnatomyTableProps = {
|
|
|
156
182
|
export const AnatomyTable: React.FC<AnatomyTableProps> = ({
|
|
157
183
|
parts,
|
|
158
184
|
activeId = null,
|
|
159
|
-
|
|
185
|
+
preset,
|
|
186
|
+
theme,
|
|
160
187
|
onItemEnter,
|
|
161
188
|
onItemLeave,
|
|
162
189
|
}) => {
|
|
163
190
|
const palette = usePalette();
|
|
164
191
|
const styles = makeStyles(palette);
|
|
192
|
+
const accent = useAccent(palette, preset, theme);
|
|
165
193
|
|
|
166
194
|
return (
|
|
167
195
|
<div style={styles.container}>
|
package/src/Panel.tsx
CHANGED
|
@@ -5,7 +5,7 @@ import type { AnatomyPartDefinition } from '@component-anatomy/core';
|
|
|
5
5
|
import { EVENTS, PARAM_KEY } from './constants.js';
|
|
6
6
|
import { matchesStory } from './channel.js';
|
|
7
7
|
import type { PartEnterEvent, PartsEvent, StoryScopedEvent } from './channel.js';
|
|
8
|
-
import {
|
|
8
|
+
import { AnatomyCode, AnatomyMessage, AnatomyTable } from './AnatomyTable.js';
|
|
9
9
|
import type { AnatomyParameters } from './types.js';
|
|
10
10
|
|
|
11
11
|
export const Panel: React.FC = () => {
|
|
@@ -44,9 +44,8 @@ export const Panel: React.FC = () => {
|
|
|
44
44
|
}, [storyId]);
|
|
45
45
|
|
|
46
46
|
const parts = params?.parts ?? discovered;
|
|
47
|
-
const accent = params?.theme?.accent ?? ACCENT_FALLBACK;
|
|
48
47
|
|
|
49
|
-
if (!params
|
|
48
|
+
if (!params) {
|
|
50
49
|
return (
|
|
51
50
|
<AnatomyMessage>
|
|
52
51
|
No anatomy configured for this story. Add <AnatomyCode>parameters.anatomy</AnatomyCode> and
|
|
@@ -55,6 +54,18 @@ export const Panel: React.FC = () => {
|
|
|
55
54
|
);
|
|
56
55
|
}
|
|
57
56
|
|
|
57
|
+
// Defence in depth: Storybook removes a panel from the tab bar entirely when
|
|
58
|
+
// `parameters[paramKey].disable` is set, so this normally never renders. If
|
|
59
|
+
// it ever does, say the right thing — a disabled story *has* an anatomy, and
|
|
60
|
+
// telling its author to add one sends them the wrong way.
|
|
61
|
+
if (params.disable) {
|
|
62
|
+
return (
|
|
63
|
+
<AnatomyMessage>
|
|
64
|
+
Anatomy is disabled for this story (<AnatomyCode>anatomy.disable</AnatomyCode>).
|
|
65
|
+
</AnatomyMessage>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
58
69
|
if (parts.length === 0) {
|
|
59
70
|
return (
|
|
60
71
|
<AnatomyMessage>
|
|
@@ -69,7 +80,8 @@ export const Panel: React.FC = () => {
|
|
|
69
80
|
<AnatomyTable
|
|
70
81
|
parts={parts}
|
|
71
82
|
activeId={activeId}
|
|
72
|
-
|
|
83
|
+
preset={params.preset}
|
|
84
|
+
theme={params.theme}
|
|
73
85
|
onItemEnter={(partId) => emit(EVENTS.HOVER_ITEM, { storyId, partId })}
|
|
74
86
|
onItemLeave={() => emit(EVENTS.LEAVE_ITEM, { storyId })}
|
|
75
87
|
/>
|
package/src/blocks.tsx
CHANGED
|
@@ -28,7 +28,7 @@ import type { AnatomyPartDefinition } from '@component-anatomy/core';
|
|
|
28
28
|
import { EVENTS, PARAM_KEY } from './constants.js';
|
|
29
29
|
import { matchesStory } from './channel.js';
|
|
30
30
|
import type { PartEnterEvent, PartsEvent, StoryScopedEvent } from './channel.js';
|
|
31
|
-
import {
|
|
31
|
+
import { AnatomyCode, AnatomyMessage, AnatomyTable } from './AnatomyTable.js';
|
|
32
32
|
import type { AnatomyParameters } from './types.js';
|
|
33
33
|
|
|
34
34
|
export type AnatomyBlockProps = {
|
|
@@ -126,7 +126,6 @@ export const Anatomy: React.FC<AnatomyBlockProps> = ({ of, parts: partsProp, syn
|
|
|
126
126
|
}, [wired, storyId]);
|
|
127
127
|
|
|
128
128
|
const parts = staticParts ?? discovered;
|
|
129
|
-
const accent = params?.theme?.accent ?? ACCENT_FALLBACK;
|
|
130
129
|
|
|
131
130
|
const emitHover = (partId: string) => {
|
|
132
131
|
if (!wired) return;
|
|
@@ -165,9 +164,18 @@ export const Anatomy: React.FC<AnatomyBlockProps> = ({ of, parts: partsProp, syn
|
|
|
165
164
|
return (
|
|
166
165
|
<Unstyled>
|
|
167
166
|
<AnatomyMessage>
|
|
168
|
-
{resolved.type === 'meta'
|
|
169
|
-
|
|
170
|
-
|
|
167
|
+
{resolved.type === 'meta' ? (
|
|
168
|
+
<>
|
|
169
|
+
No parts found. A meta has no canvas to discover parts from — pass a story to{' '}
|
|
170
|
+
<AnatomyCode>of</AnatomyCode>, or list <AnatomyCode>parts</AnatomyCode> explicitly.
|
|
171
|
+
</>
|
|
172
|
+
) : (
|
|
173
|
+
<>
|
|
174
|
+
No parts found. Auto-discovery reads the rendered story, so make sure it is on this
|
|
175
|
+
page (e.g. with a <AnatomyCode>{'<Canvas of={…} />'}</AnatomyCode> block above), or
|
|
176
|
+
list <AnatomyCode>parts</AnatomyCode> explicitly.
|
|
177
|
+
</>
|
|
178
|
+
)}
|
|
171
179
|
</AnatomyMessage>
|
|
172
180
|
</Unstyled>
|
|
173
181
|
);
|
|
@@ -178,7 +186,8 @@ export const Anatomy: React.FC<AnatomyBlockProps> = ({ of, parts: partsProp, syn
|
|
|
178
186
|
<AnatomyTable
|
|
179
187
|
parts={parts}
|
|
180
188
|
activeId={activeId}
|
|
181
|
-
|
|
189
|
+
preset={params?.preset}
|
|
190
|
+
theme={params?.theme}
|
|
182
191
|
onItemEnter={emitHover}
|
|
183
192
|
onItemLeave={emitLeave}
|
|
184
193
|
/>
|