@component-anatomy/storybook 0.0.2 → 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 CHANGED
@@ -4,6 +4,7 @@ Storybook addon that adds an **Anatomy** panel — an interactive part list sync
4
4
 
5
5
  - Hover a part in the panel → the element is highlighted in the canvas
6
6
  - Hover a `data-part` element in the canvas → the panel entry activates
7
+ - The same table renders **inside MDX** via `@component-anatomy/storybook/blocks`
7
8
  - Works with **Storybook 9 and 10**, any renderer (React, Vue, HTML, Web Components…)
8
9
 
9
10
  ## Install
@@ -47,11 +48,53 @@ export const Anatomy: Story = {
47
48
 
48
49
  Omit `parts` (pass `{}`) and the panel lists parts auto-discovered from `data-part` attributes, with names derived from the ids.
49
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
+
50
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`.
51
54
 
55
+ ## In MDX
56
+
57
+ The panel's table also renders inline in a docs page, so anatomy can sit in the
58
+ prose next to the preview. Requires `@storybook/addon-docs` (the addon that
59
+ renders MDX), which stays an optional peer dependency — the panel above works
60
+ without it.
61
+
62
+ ```mdx
63
+ import { Canvas, Meta } from '@storybook/addon-docs/blocks';
64
+ import { Anatomy } from '@component-anatomy/storybook/blocks';
65
+
66
+ import * as ButtonStories from './Button.stories';
67
+
68
+ <Meta of={ButtonStories} />
69
+
70
+ <Canvas of={ButtonStories.Anatomy} />
71
+ <Anatomy of={ButtonStories.Anatomy} />
72
+ ```
73
+
74
+ Hover sync works both ways, exactly as in the panel.
75
+
76
+ | Prop | Type | Description |
77
+ |---|---|---|
78
+ | `of` | CSF export | The story to document, or a whole CSF module to read the meta's parameters. Omit on an attached docs page (one with `<Meta of={…} />`) to fall back to the page's current story. |
79
+ | `parts` | `AnatomyPartDefinition[]` | Curated list, overriding both `parameters.anatomy.parts` and auto-discovery. |
80
+ | `sync` | `boolean` | Two-way hover sync with the rendered story. Default `true`. `false` gives a purely static table. |
81
+
82
+ Two things worth knowing:
83
+
84
+ - **Auto-discovery needs the story on the page.** Parts are read from the story's
85
+ `data-part` attributes as it renders, so a block that relies on discovery needs
86
+ a `<Canvas of={…} />` (or `<Story of={…} />`) on the same page. A block with an
87
+ explicit `parts` list stands on its own.
88
+ - **A meta has no canvas.** `of={ButtonStories}` reads `meta.parameters.anatomy`,
89
+ but there is nothing to discover parts from or to sync hover with — give it
90
+ `parts` explicitly.
91
+
92
+ Several blocks can share one page; each talks only to the story it names.
93
+
52
94
  ## Example
53
95
 
54
- A complete Storybook 10 setup with Button/Slider/Tabs stories lives in [`examples/storybook`](https://github.com/julien-deramond/component-anatomy/tree/main/examples/storybook), deployed at https://julien-deramond.github.io/component-anatomy/storybook/.
96
+ A complete Storybook 10 setup with Button/Slider/Tabs stories and two MDX
97
+ pages using the `<Anatomy>` block — lives in [`examples/storybook`](https://github.com/julien-deramond/component-anatomy/tree/main/examples/storybook), deployed at https://julien-deramond.github.io/component-anatomy/storybook/.
55
98
 
56
99
  ## Docs
57
100
 
@@ -0,0 +1,39 @@
1
+ /**
2
+ * The anatomy part table — pure presentation, no Storybook imports.
3
+ *
4
+ * This module is deliberately free of `storybook/manager-api` and
5
+ * `storybook/preview-api`: it is bundled into *both* the manager entry (the
6
+ * addon panel) and the blocks entry (the `<Anatomy>` MDX doc block), which
7
+ * run in different runtimes and cannot share either of those APIs. Only the
8
+ * data acquisition differs between the two; the markup must not.
9
+ */
10
+ import React from 'react';
11
+ import type { AnatomyPartDefinition, AnatomyPresetName, AnatomyTheme } from '@component-anatomy/core';
12
+ /**
13
+ * An inline `<code>` styled for the surrounding message text. Exported so
14
+ * both runtimes can compose their own empty-state copy without duplicating
15
+ * the style object.
16
+ */
17
+ export declare const AnatomyCode: React.FC<{
18
+ children: React.ReactNode;
19
+ }>;
20
+ /** A padded, muted paragraph — used for every "nothing to show" state. */
21
+ export declare const AnatomyMessage: React.FC<{
22
+ children: React.ReactNode;
23
+ }>;
24
+ export type AnatomyTableProps = {
25
+ /** Parts to list, in the order they should be shown. */
26
+ parts: AnatomyPartDefinition[];
27
+ /** Id of the part currently highlighted in the canvas, if any. */
28
+ activeId?: string | null;
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
+ /** Called when the user hovers or focuses an entry. */
34
+ onItemEnter?: (partId: string) => void;
35
+ /** Called when the user leaves or blurs an entry. */
36
+ onItemLeave?: () => void;
37
+ };
38
+ export declare const AnatomyTable: React.FC<AnatomyTableProps>;
39
+ //# sourceMappingURL=AnatomyTable.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -1 +1 @@
1
- {"version":3,"file":"Panel.d.ts","sourceRoot":"","sources":["../src/Panel.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AA6EnD,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,EA0FzB,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"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Docs blocks entry — the `<Anatomy>` block for MDX pages.
3
+ *
4
+ * Unlike the addon panel, this runs in the **preview iframe**, where
5
+ * `storybook/manager-api` does not exist. It reaches the story's controller
6
+ * over the addon channel instead: `Channel.emit` dispatches to local
7
+ * listeners as well as across transports, so a block and the decorator that
8
+ * mounted the story talk to each other directly, in-frame, with no extra
9
+ * plumbing.
10
+ *
11
+ * ```mdx
12
+ * import { Meta, Canvas } from '@storybook/addon-docs/blocks';
13
+ * import { Anatomy } from '@component-anatomy/storybook/blocks';
14
+ * import * as ButtonStories from './Button.stories';
15
+ *
16
+ * <Meta of={ButtonStories} />
17
+ *
18
+ * <Canvas of={ButtonStories.Anatomy} />
19
+ * <Anatomy of={ButtonStories.Anatomy} />
20
+ * ```
21
+ */
22
+ import React from 'react';
23
+ import type { Of } from '@storybook/addon-docs/blocks';
24
+ import type { AnatomyPartDefinition } from '@component-anatomy/core';
25
+ export type AnatomyBlockProps = {
26
+ /**
27
+ * The CSF export to document — a story export, or the whole module export
28
+ * of a CSF file to read the meta's parameters.
29
+ *
30
+ * Omit it on an attached docs page (one with `<Meta of={...} />`, or an
31
+ * autodocs page) to fall back to the page's current story, mirroring how
32
+ * the other docs blocks resolve `of`.
33
+ */
34
+ of?: Of;
35
+ /**
36
+ * Part list override. Skips both `parameters.anatomy.parts` and
37
+ * auto-discovery — useful for a hand-curated subset in prose.
38
+ */
39
+ parts?: AnatomyPartDefinition[];
40
+ /**
41
+ * Two-way hover sync with the rendered story. Default: `true`. Set to
42
+ * `false` for a purely static table (also skips auto-discovery, since that
43
+ * arrives over the channel).
44
+ */
45
+ sync?: boolean;
46
+ };
47
+ export declare const Anatomy: React.FC<AnatomyBlockProps>;
48
+ //# sourceMappingURL=blocks.d.ts.map
@@ -0,0 +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,CA6H/C,CAAC"}
package/dist/blocks.js ADDED
@@ -0,0 +1,252 @@
1
+ // src/blocks.tsx
2
+ import React2, { useEffect, useState } from "react";
3
+ import { addons } from "storybook/preview-api";
4
+ import { Unstyled, useOf } from "@storybook/addon-docs/blocks";
5
+
6
+ // src/constants.ts
7
+ var ADDON_ID = "component-anatomy";
8
+ var PANEL_ID = `${ADDON_ID}/panel`;
9
+ var PARAM_KEY = "anatomy";
10
+ var EVENTS = {
11
+ /** preview → consumers: a part became active in the canvas (hover/programmatic). */
12
+ PART_ENTER: `${ADDON_ID}/part-enter`,
13
+ /** preview → consumers: no part is active anymore. */
14
+ PART_LEAVE: `${ADDON_ID}/part-leave`,
15
+ /** preview → consumers: resolved part list for a story. */
16
+ PARTS: `${ADDON_ID}/parts`,
17
+ /** consumers → preview: the user hovers/focuses a panel entry. */
18
+ HOVER_ITEM: `${ADDON_ID}/hover-item`,
19
+ /** consumers → preview: the user left a panel entry. */
20
+ LEAVE_ITEM: `${ADDON_ID}/leave-item`,
21
+ /** consumers → preview: a panel/block mounted and wants the current part list. */
22
+ PARTS_REQUEST: `${ADDON_ID}/parts-request`
23
+ };
24
+
25
+ // src/channel.ts
26
+ var matchesStory = (eventStoryId, storyId) => !eventStoryId || !storyId || eventStoryId === storyId;
27
+
28
+ // src/AnatomyTable.tsx
29
+ import React from "react";
30
+ import { useTheme } from "storybook/theming";
31
+ import { resolvePanelAccent } from "@component-anatomy/core";
32
+ var FONT_BASE_FALLBACK = '"Nunito Sans", -apple-system, ".SFNSText-Regular", "San Francisco", BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif';
33
+ var FONT_MONO_FALLBACK = 'ui-monospace, "Cascadia Code", "Fira Mono", monospace';
34
+ function usePalette() {
35
+ const theme = useTheme();
36
+ return {
37
+ text: theme.fgColor?.default,
38
+ muted: theme.fgColor?.muted ?? "#6b7280",
39
+ mutedBg: theme.bgColor?.muted ?? "rgba(0,0,0,0.06)",
40
+ border: theme.borderColor?.default ?? "rgba(0,0,0,0.08)",
41
+ surfaceBg: theme.bgColor?.default ?? "#ffffff",
42
+ surfaceFg: theme.fgColor?.default ?? "#2e3438",
43
+ fontBase: theme.typography?.fonts?.base ?? FONT_BASE_FALLBACK,
44
+ fontMono: theme.typography?.fonts?.mono ?? FONT_MONO_FALLBACK
45
+ };
46
+ }
47
+ function useAccent(palette, preset, theme) {
48
+ return resolvePanelAccent(preset, theme, {
49
+ background: palette.surfaceBg,
50
+ foreground: palette.surfaceFg
51
+ });
52
+ }
53
+ var makeStyles = (p) => ({
54
+ container: {
55
+ padding: "12px 16px",
56
+ fontFamily: p.fontBase,
57
+ fontSize: 13,
58
+ lineHeight: 1.5,
59
+ color: p.text
60
+ },
61
+ empty: {
62
+ color: p.muted,
63
+ margin: 0
64
+ },
65
+ code: {
66
+ fontFamily: p.fontMono,
67
+ fontSize: "0.85em",
68
+ background: p.mutedBg,
69
+ borderRadius: 3,
70
+ padding: "1px 5px"
71
+ },
72
+ list: {
73
+ display: "flex",
74
+ flexDirection: "column",
75
+ gap: 2,
76
+ margin: 0,
77
+ padding: 0,
78
+ listStyle: "none"
79
+ },
80
+ entry: {
81
+ padding: "8px 10px",
82
+ borderRadius: 6,
83
+ border: "1px solid transparent",
84
+ cursor: "default",
85
+ outline: "none",
86
+ transition: "background 120ms ease, border-color 120ms ease"
87
+ },
88
+ header: {
89
+ display: "flex",
90
+ alignItems: "center",
91
+ gap: 8
92
+ },
93
+ indicator: {
94
+ width: 8,
95
+ height: 8,
96
+ borderRadius: "50%",
97
+ border: `2px solid ${p.border}`,
98
+ flexShrink: 0,
99
+ transition: "background 120ms ease, border-color 120ms ease"
100
+ },
101
+ name: {
102
+ fontWeight: 700,
103
+ flex: 1
104
+ },
105
+ id: {
106
+ fontFamily: p.fontMono,
107
+ fontSize: 10,
108
+ padding: "1px 6px",
109
+ borderRadius: 4,
110
+ background: p.mutedBg,
111
+ border: `1px solid ${p.border}`,
112
+ color: p.muted,
113
+ flexShrink: 0
114
+ },
115
+ description: {
116
+ margin: "4px 0 0",
117
+ paddingLeft: 16,
118
+ color: p.muted
119
+ }
120
+ });
121
+ var AnatomyCode = ({ children }) => {
122
+ const styles = makeStyles(usePalette());
123
+ return /* @__PURE__ */ React.createElement("code", { style: styles.code }, children);
124
+ };
125
+ var AnatomyMessage = ({ children }) => {
126
+ const styles = makeStyles(usePalette());
127
+ return /* @__PURE__ */ React.createElement("div", { style: styles.container }, /* @__PURE__ */ React.createElement("p", { style: styles.empty }, children));
128
+ };
129
+ var AnatomyTable = ({
130
+ parts,
131
+ activeId = null,
132
+ preset,
133
+ theme,
134
+ onItemEnter,
135
+ onItemLeave
136
+ }) => {
137
+ const palette = usePalette();
138
+ const styles = makeStyles(palette);
139
+ const accent = useAccent(palette, preset, theme);
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) => {
141
+ const active = activeId === part.id;
142
+ return /* @__PURE__ */ React.createElement(
143
+ "li",
144
+ {
145
+ key: part.id,
146
+ role: "listitem",
147
+ tabIndex: 0,
148
+ "aria-label": part.name,
149
+ style: {
150
+ ...styles.entry,
151
+ background: active ? `color-mix(in srgb, ${accent} 7%, transparent)` : void 0,
152
+ borderColor: active ? `color-mix(in srgb, ${accent} 20%, transparent)` : "transparent"
153
+ },
154
+ onMouseEnter: () => onItemEnter?.(part.id),
155
+ onMouseLeave: () => onItemLeave?.(),
156
+ onFocus: () => onItemEnter?.(part.id),
157
+ onBlur: () => onItemLeave?.()
158
+ },
159
+ /* @__PURE__ */ React.createElement("div", { style: styles.header }, /* @__PURE__ */ React.createElement(
160
+ "span",
161
+ {
162
+ "aria-hidden": "true",
163
+ style: {
164
+ ...styles.indicator,
165
+ background: active ? accent : void 0,
166
+ borderColor: active ? accent : palette.border
167
+ }
168
+ }
169
+ ), /* @__PURE__ */ React.createElement("span", { style: { ...styles.name, color: active ? accent : void 0 } }, part.name), /* @__PURE__ */ React.createElement("code", { style: styles.id }, part.id)),
170
+ part.description && /* @__PURE__ */ React.createElement("p", { style: styles.description }, part.description)
171
+ );
172
+ })));
173
+ };
174
+
175
+ // src/blocks.tsx
176
+ function getChannelSafely() {
177
+ try {
178
+ return addons.getChannel();
179
+ } catch {
180
+ return null;
181
+ }
182
+ }
183
+ var Anatomy = ({ of, parts: partsProp, sync = true }) => {
184
+ const resolved = useOf(of ?? "story", ["story", "meta"]);
185
+ const params = resolved.type === "meta" ? resolved.preparedMeta.parameters?.[PARAM_KEY] : resolved.story.parameters?.[PARAM_KEY];
186
+ const storyId = resolved.type === "story" ? resolved.story.id : void 0;
187
+ const [discovered, setDiscovered] = useState([]);
188
+ const [activeId, setActiveId] = useState(null);
189
+ const staticParts = partsProp ?? params?.parts;
190
+ const wired = sync && !!storyId;
191
+ useEffect(() => {
192
+ setDiscovered([]);
193
+ setActiveId(null);
194
+ if (!wired) return;
195
+ const channel = getChannelSafely();
196
+ if (!channel) return;
197
+ const onParts = (event) => {
198
+ if (!matchesStory(event?.storyId, storyId)) return;
199
+ setDiscovered(event.parts);
200
+ };
201
+ const onEnter = (event) => {
202
+ if (!matchesStory(event?.storyId, storyId)) return;
203
+ setActiveId(event.partId);
204
+ };
205
+ const onLeave = (event = {}) => {
206
+ if (!matchesStory(event?.storyId, storyId)) return;
207
+ setActiveId(null);
208
+ };
209
+ channel.on(EVENTS.PARTS, onParts);
210
+ channel.on(EVENTS.PART_ENTER, onEnter);
211
+ channel.on(EVENTS.PART_LEAVE, onLeave);
212
+ channel.emit(EVENTS.PARTS_REQUEST, { storyId });
213
+ return () => {
214
+ channel.off(EVENTS.PARTS, onParts);
215
+ channel.off(EVENTS.PART_ENTER, onEnter);
216
+ channel.off(EVENTS.PART_LEAVE, onLeave);
217
+ };
218
+ }, [wired, storyId]);
219
+ const parts = staticParts ?? discovered;
220
+ const emitHover = (partId) => {
221
+ if (!wired) return;
222
+ getChannelSafely()?.emit(EVENTS.HOVER_ITEM, { storyId, partId });
223
+ };
224
+ const emitLeave = () => {
225
+ if (!wired) return;
226
+ getChannelSafely()?.emit(EVENTS.LEAVE_ITEM, { storyId });
227
+ };
228
+ if (!params && !partsProp) {
229
+ return /* @__PURE__ */ React2.createElement(Unstyled, null, /* @__PURE__ */ React2.createElement(AnatomyMessage, null, "No anatomy configured. Add ", /* @__PURE__ */ React2.createElement(AnatomyCode, null, "parameters.anatomy"), " to the story you pass to ", /* @__PURE__ */ React2.createElement(AnatomyCode, null, "of"), ", or pass a", " ", /* @__PURE__ */ React2.createElement(AnatomyCode, null, "parts"), " list to this block."));
230
+ }
231
+ if (params?.disable && !partsProp) {
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"), ")."));
233
+ }
234
+ if (parts.length === 0) {
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.")));
236
+ }
237
+ return /* @__PURE__ */ React2.createElement(Unstyled, null, /* @__PURE__ */ React2.createElement(
238
+ AnatomyTable,
239
+ {
240
+ parts,
241
+ activeId,
242
+ preset: params?.preset,
243
+ theme: params?.theme,
244
+ onItemEnter: emitHover,
245
+ onItemLeave: emitLeave
246
+ }
247
+ ));
248
+ };
249
+ export {
250
+ Anatomy
251
+ };
252
+ //# sourceMappingURL=blocks.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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 { 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,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,WAAW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AAA,cAAC,mBAAY,IAAE,GAAc,eAAY,KACjD,gBAAAA,OAAA,cAAC,mBAAY,OAAK,GAAc,sBAClC,CACF;AAAA,EAEJ;AAEA,MAAI,QAAQ,WAAW,CAAC,WAAW;AACjC,WACE,gBAAAA,OAAA,cAAC,gBACC,gBAAAA,OAAA,cAAC,sBAAe,wCACsB,gBAAAA,OAAA,cAAC,mBAAY,iBAAe,GAAc,IAChF,CACF;AAAA,EAEJ;AAEA,MAAI,MAAM,WAAW,GAAG;AACtB,WACE,gBAAAA,OAAA,cAAC,gBACC,gBAAAA,OAAA,cAAC,sBACE,SAAS,SAAS,SACjB,gBAAAA,OAAA,cAAAA,OAAA,gBAAE,sFAC8E,KAC9E,gBAAAA,OAAA,cAAC,mBAAY,IAAE,GAAc,cAAU,gBAAAA,OAAA,cAAC,mBAAY,OAAK,GAAc,cACzE,IAEA,gBAAAA,OAAA,cAAAA,OAAA,gBAAE,0GAEkB,gBAAAA,OAAA,cAAC,mBAAa,wBAAoB,GAAc,2BAC7D,gBAAAA,OAAA,cAAC,mBAAY,OAAK,GAAc,cACvC,CAEJ,CACF;AAAA,EAEJ;AAEA,SACE,gBAAAA,OAAA,cAAC,gBACC,gBAAAA,OAAA;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA,QAAQ,QAAQ;AAAA,MAChB,OAAO,QAAQ;AAAA,MACf,aAAa;AAAA,MACb,aAAa;AAAA;AAAA,EACf,CACF;AAEJ;",
6
+ "names": ["React", "React"]
7
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Shared channel payload contract between the preview decorator, the manager
3
+ * panel, and the MDX doc block.
4
+ *
5
+ * Every payload carries the `storyId` it refers to. In story view this is
6
+ * redundant — only one story is mounted — but a docs page mounts *many*
7
+ * stories at once, each with its own controller, and each `<Anatomy>` block
8
+ * must talk to exactly one of them. Without addressing, hovering a part in
9
+ * one block highlights the matching part in every other story on the page.
10
+ */
11
+ import type { AnatomyPartDefinition } from '@component-anatomy/core';
12
+ /** preview → consumers: the resolved part list for one story. */
13
+ export type PartsEvent = {
14
+ storyId?: string;
15
+ parts: AnatomyPartDefinition[];
16
+ };
17
+ /** preview → consumers: a part became active in that story's canvas. */
18
+ export type PartEnterEvent = {
19
+ storyId?: string;
20
+ partId: string;
21
+ };
22
+ /** consumer → preview: highlight this part in that story's canvas. */
23
+ export type HoverItemEvent = {
24
+ storyId?: string;
25
+ partId: string;
26
+ };
27
+ /** Payload for the events that only need to name a story. */
28
+ export type StoryScopedEvent = {
29
+ storyId?: string;
30
+ };
31
+ /**
32
+ * Whether an event addressed to `eventStoryId` concerns `storyId`.
33
+ *
34
+ * A missing id on *either* side matches everything. That keeps the protocol
35
+ * backward compatible: a manager panel from a newer build still understands
36
+ * an older preview bundle that emits unaddressed events, and vice versa.
37
+ */
38
+ export declare const matchesStory: (eventStoryId: string | undefined, storyId: string | undefined) => boolean;
39
+ //# sourceMappingURL=channel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAErE,iEAAiE;AACjE,MAAM,MAAM,UAAU,GAAG;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,qBAAqB,EAAE,CAAA;CAAE,CAAC;AAE9E,wEAAwE;AACxE,MAAM,MAAM,cAAc,GAAG;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAElE,sEAAsE;AACtE,MAAM,MAAM,cAAc,GAAG;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAElE,6DAA6D;AAC7D,MAAM,MAAM,gBAAgB,GAAG;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpD;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,iBACT,MAAM,GAAG,SAAS,WACvB,MAAM,GAAG,SAAS,KAC1B,OAAgE,CAAC"}
@@ -2,19 +2,25 @@ export declare const ADDON_ID = "component-anatomy";
2
2
  export declare const PANEL_ID = "component-anatomy/panel";
3
3
  /** Story parameter key: `parameters.anatomy = { ... }` */
4
4
  export declare const PARAM_KEY = "anatomy";
5
- /** Channel events used to sync the manager panel with the preview iframe. */
5
+ /**
6
+ * Channel events used to sync the manager panel — and the `<Anatomy>` MDX doc
7
+ * block, which runs in the preview iframe — with the story canvas.
8
+ *
9
+ * Every payload carries the `storyId` it concerns; see `channel.ts` for the
10
+ * payload types and the `matchesStory` filter each listener applies.
11
+ */
6
12
  export declare const EVENTS: {
7
- /** preview → manager: a part became active in the canvas (hover/programmatic). */
13
+ /** preview → consumers: a part became active in the canvas (hover/programmatic). */
8
14
  readonly PART_ENTER: "component-anatomy/part-enter";
9
- /** preview → manager: no part is active anymore. */
15
+ /** preview → consumers: no part is active anymore. */
10
16
  readonly PART_LEAVE: "component-anatomy/part-leave";
11
- /** preview → manager: resolved part list for the current story. */
17
+ /** preview → consumers: resolved part list for a story. */
12
18
  readonly PARTS: "component-anatomy/parts";
13
- /** manager → preview: the user hovers/focuses a panel entry. */
19
+ /** consumers → preview: the user hovers/focuses a panel entry. */
14
20
  readonly HOVER_ITEM: "component-anatomy/hover-item";
15
- /** manager → preview: the user left a panel entry. */
21
+ /** consumers → preview: the user left a panel entry. */
16
22
  readonly LEAVE_ITEM: "component-anatomy/leave-item";
17
- /** manager → preview: the panel mounted and wants the current part list. */
23
+ /** consumers → preview: a panel/block mounted and wants the current part list. */
18
24
  readonly PARTS_REQUEST: "component-anatomy/parts-request";
19
25
  };
20
26
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,sBAAsB,CAAC;AAC5C,eAAO,MAAM,QAAQ,4BAAsB,CAAC;AAE5C,0DAA0D;AAC1D,eAAO,MAAM,SAAS,YAAY,CAAC;AAEnC,6EAA6E;AAC7E,eAAO,MAAM,MAAM;IACjB,kFAAkF;aAClF,UAAU;IACV,oDAAoD;aACpD,UAAU;IACV,mEAAmE;aACnE,KAAK;IACL,gEAAgE;aAChE,UAAU;IACV,sDAAsD;aACtD,UAAU;IACV,4EAA4E;aAC5E,aAAa;CACL,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,sBAAsB,CAAC;AAC5C,eAAO,MAAM,QAAQ,4BAAsB,CAAC;AAE5C,0DAA0D;AAC1D,eAAO,MAAM,SAAS,YAAY,CAAC;AAEnC;;;;;;GAMG;AACH,eAAO,MAAM,MAAM;IACjB,oFAAoF;aACpF,UAAU;IACV,sDAAsD;aACtD,UAAU;IACV,2DAA2D;aAC3D,KAAK;IACL,kEAAkE;aAClE,UAAU;IACV,wDAAwD;aACxD,UAAU;IACV,kFAAkF;aAClF,aAAa;CACL,CAAC"}
package/dist/index.cjs CHANGED
@@ -32,17 +32,17 @@ var ADDON_ID = "component-anatomy";
32
32
  var PANEL_ID = `${ADDON_ID}/panel`;
33
33
  var PARAM_KEY = "anatomy";
34
34
  var EVENTS = {
35
- /** preview → manager: a part became active in the canvas (hover/programmatic). */
35
+ /** preview → consumers: a part became active in the canvas (hover/programmatic). */
36
36
  PART_ENTER: `${ADDON_ID}/part-enter`,
37
- /** preview → manager: no part is active anymore. */
37
+ /** preview → consumers: no part is active anymore. */
38
38
  PART_LEAVE: `${ADDON_ID}/part-leave`,
39
- /** preview → manager: resolved part list for the current story. */
39
+ /** preview → consumers: resolved part list for a story. */
40
40
  PARTS: `${ADDON_ID}/parts`,
41
- /** manager → preview: the user hovers/focuses a panel entry. */
41
+ /** consumers → preview: the user hovers/focuses a panel entry. */
42
42
  HOVER_ITEM: `${ADDON_ID}/hover-item`,
43
- /** manager → preview: the user left a panel entry. */
43
+ /** consumers → preview: the user left a panel entry. */
44
44
  LEAVE_ITEM: `${ADDON_ID}/leave-item`,
45
- /** manager → preview: the panel mounted and wants the current part list. */
45
+ /** consumers → preview: a panel/block mounted and wants the current part list. */
46
46
  PARTS_REQUEST: `${ADDON_ID}/parts-request`
47
47
  };
48
48
  //# sourceMappingURL=index.cjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts", "../src/constants.ts"],
4
- "sourcesContent": ["export { ADDON_ID, PANEL_ID, PARAM_KEY, EVENTS } from './constants.js';\nexport type { AnatomyParameters } from './types.js';\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/** Channel events used to sync the manager panel with the preview iframe. */\nexport const EVENTS = {\n /** preview \u2192 manager: a part became active in the canvas (hover/programmatic). */\n PART_ENTER: `${ADDON_ID}/part-enter`,\n /** preview \u2192 manager: no part is active anymore. */\n PART_LEAVE: `${ADDON_ID}/part-leave`,\n /** preview \u2192 manager: resolved part list for the current story. */\n PARTS: `${ADDON_ID}/parts`,\n /** manager \u2192 preview: the user hovers/focuses a panel entry. */\n HOVER_ITEM: `${ADDON_ID}/hover-item`,\n /** manager \u2192 preview: the user left a panel entry. */\n LEAVE_ITEM: `${ADDON_ID}/leave-item`,\n /** manager \u2192 preview: the panel mounted and wants the current part list. */\n PARTS_REQUEST: `${ADDON_ID}/parts-request`,\n} as const;\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,WAAW;AACjB,IAAM,WAAW,GAAG,QAAQ;AAG5B,IAAM,YAAY;AAGlB,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;",
4
+ "sourcesContent": ["export { ADDON_ID, PANEL_ID, PARAM_KEY, EVENTS } from './constants.js';\nexport type { AnatomyParameters } from './types.js';\n\n// The `<Anatomy>` doc block lives in the `./blocks` subpath, not here: this\n// entry is loaded at config time by `.storybook/main.ts` (and built to CJS),\n// while the block needs React and `@storybook/addon-docs`, both optional\n// peers that must not become load-bearing for `addons: ['...']` to work.\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"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,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;",
6
6
  "names": []
7
7
  }
package/dist/index.js CHANGED
@@ -3,17 +3,17 @@ var ADDON_ID = "component-anatomy";
3
3
  var PANEL_ID = `${ADDON_ID}/panel`;
4
4
  var PARAM_KEY = "anatomy";
5
5
  var EVENTS = {
6
- /** preview → manager: a part became active in the canvas (hover/programmatic). */
6
+ /** preview → consumers: a part became active in the canvas (hover/programmatic). */
7
7
  PART_ENTER: `${ADDON_ID}/part-enter`,
8
- /** preview → manager: no part is active anymore. */
8
+ /** preview → consumers: no part is active anymore. */
9
9
  PART_LEAVE: `${ADDON_ID}/part-leave`,
10
- /** preview → manager: resolved part list for the current story. */
10
+ /** preview → consumers: resolved part list for a story. */
11
11
  PARTS: `${ADDON_ID}/parts`,
12
- /** manager → preview: the user hovers/focuses a panel entry. */
12
+ /** consumers → preview: the user hovers/focuses a panel entry. */
13
13
  HOVER_ITEM: `${ADDON_ID}/hover-item`,
14
- /** manager → preview: the user left a panel entry. */
14
+ /** consumers → preview: the user left a panel entry. */
15
15
  LEAVE_ITEM: `${ADDON_ID}/leave-item`,
16
- /** manager → preview: the panel mounted and wants the current part list. */
16
+ /** consumers → preview: a panel/block mounted and wants the current part list. */
17
17
  PARTS_REQUEST: `${ADDON_ID}/parts-request`
18
18
  };
19
19
  export {