@storybook/addon-docs 10.5.0-alpha.7 → 10.5.0-alpha.8

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/dist/manager.js CHANGED
@@ -8,19 +8,23 @@ import React, { useEffect, useState } from "react";
8
8
  import { AddonPanel } from "storybook/internal/components";
9
9
  import { addons, types, useChannel, useParameter } from "storybook/manager-api";
10
10
  import { ignoreSsrWarning, styled, useTheme } from "storybook/theming";
11
-
12
- // ../../core/src/docs-tools/shared.ts
13
- var ADDON_ID = "storybook/docs", PANEL_ID = `${ADDON_ID}/panel`, PARAM_KEY = "docs", SNIPPET_RENDERED = `${ADDON_ID}/snippet-rendered`;
14
-
15
- // src/manager.tsx
11
+ import {
12
+ ADDON_ID,
13
+ PANEL_ID,
14
+ PARAM_KEY,
15
+ shouldWaitForServiceSnippet,
16
+ SNIPPET_RENDERED
17
+ } from "storybook/internal/docs-tools";
16
18
  var CodePanel = ({
17
19
  active,
18
20
  lastEvent,
19
- currentStoryId
21
+ currentStoryId,
22
+ storyParameters,
23
+ storyPrepared
20
24
  }) => {
21
- let [codeSnippet, setSourceCode] = useState({
22
- source: lastEvent?.source,
23
- format: lastEvent?.format ?? void 0
25
+ let lastEventMatchesCurrentStory = lastEvent?.id === currentStoryId, [codeSnippet, setSourceCode] = useState({
26
+ source: lastEventMatchesCurrentStory ? lastEvent?.source : void 0,
27
+ format: lastEventMatchesCurrentStory ? lastEvent?.format ?? void 0 : void 0
24
28
  }), parameter = useParameter(PARAM_KEY, {
25
29
  source: { code: "" },
26
30
  theme: "dark"
@@ -30,21 +34,16 @@ var CodePanel = ({
30
34
  source: void 0,
31
35
  format: void 0
32
36
  });
33
- }, [currentStoryId]), useChannel({
34
- [SNIPPET_RENDERED]: ({ source, format }) => {
35
- setSourceCode({ source, format });
36
- }
37
- });
38
- let isDark = useTheme().base !== "light";
39
- return React.createElement(AddonPanel, { active: !!active }, React.createElement(SourceStyles, null, React.createElement(
40
- Source,
37
+ }, [currentStoryId]), useChannel(
41
38
  {
42
- ...parameter.source,
43
- code: parameter.source?.code || codeSnippet.source || parameter.source?.originalSource,
44
- format: codeSnippet.format,
45
- dark: isDark
46
- }
47
- )));
39
+ [SNIPPET_RENDERED]: ({ id, source, format }) => {
40
+ id !== void 0 && id !== currentStoryId || setSourceCode({ source, format });
41
+ }
42
+ },
43
+ [currentStoryId]
44
+ );
45
+ let isDark = useTheme().base !== "light", awaitingServiceSnippet = shouldWaitForServiceSnippet(storyParameters, storyPrepared), code = parameter.source?.code || codeSnippet.source || (awaitingServiceSnippet ? "" : parameter.source?.originalSource);
46
+ return React.createElement(AddonPanel, { active: !!active }, React.createElement(SourceStyles, null, React.createElement(Source, { ...parameter.source, code, format: codeSnippet.format, dark: isDark })));
48
47
  };
49
48
  addons.register(ADDON_ID, (api) => {
50
49
  addons.add(PANEL_ID, {
@@ -68,7 +67,16 @@ addons.register(ADDON_ID, (api) => {
68
67
  match: ({ viewMode }) => viewMode === "story",
69
68
  render: ({ active }) => {
70
69
  let channel = api.getChannel(), currentStory = api.getCurrentStoryData(), lastEvent = channel?.last(SNIPPET_RENDERED)?.[0];
71
- return React.createElement(CodePanel, { currentStoryId: currentStory?.id, lastEvent, active });
70
+ return React.createElement(
71
+ CodePanel,
72
+ {
73
+ currentStoryId: currentStory?.id,
74
+ storyParameters: currentStory?.parameters,
75
+ storyPrepared: currentStory?.prepared,
76
+ lastEvent,
77
+ active
78
+ }
79
+ );
72
80
  }
73
81
  });
74
82
  });
@@ -1,20 +1,20 @@
1
- import CJS_COMPAT_NODE_URL_6gmdae9o5xc from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_6gmdae9o5xc from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_6gmdae9o5xc from "node:module";
1
+ import CJS_COMPAT_NODE_URL_3yfiy933z03 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_3yfiy933z03 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_3yfiy933z03 from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_6gmdae9o5xc.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_6gmdae9o5xc.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_6gmdae9o5xc.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_3yfiy933z03.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_3yfiy933z03.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_3yfiy933z03.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
11
  // ------------------------------------------------------------
12
12
  import {
13
13
  compile
14
- } from "./_node-chunks/chunk-2WTY7RHL.js";
15
- import "./_node-chunks/chunk-BS47STAB.js";
16
- import "./_node-chunks/chunk-ZM6M6OKB.js";
17
- import "./_node-chunks/chunk-AR7B7DGI.js";
14
+ } from "./_node-chunks/chunk-Q33Y654V.js";
15
+ import "./_node-chunks/chunk-NDIMOQRQ.js";
16
+ import "./_node-chunks/chunk-RDCEJST6.js";
17
+ import "./_node-chunks/chunk-X327Z4QW.js";
18
18
 
19
19
  // src/mdx-loader.ts
20
20
  var DEFAULT_RENDERER = `
package/dist/preset.js CHANGED
@@ -1,15 +1,15 @@
1
- import CJS_COMPAT_NODE_URL_6gmdae9o5xc from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_6gmdae9o5xc from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_6gmdae9o5xc from "node:module";
1
+ import CJS_COMPAT_NODE_URL_3yfiy933z03 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_3yfiy933z03 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_3yfiy933z03 from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_6gmdae9o5xc.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_6gmdae9o5xc.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_6gmdae9o5xc.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_3yfiy933z03.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_3yfiy933z03.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_3yfiy933z03.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
11
  // ------------------------------------------------------------
12
- import "./_node-chunks/chunk-AR7B7DGI.js";
12
+ import "./_node-chunks/chunk-X327Z4QW.js";
13
13
 
14
14
  // src/preset.ts
15
15
  import { isAbsolute as isAbsolute2 } from "node:path";
@@ -218,23 +218,46 @@ var importMetaResolve = (...args) => typeof import.meta.resolve != "function" &&
218
218
  }
219
219
  };
220
220
 
221
+ // src/mdx-service/server.ts
222
+ import { getComponentIdFromEntry as getComponentIdFromEntry2, groupBy as groupBy2, registerService } from "storybook/internal/common";
223
+ import { Tag as Tag2 } from "storybook/internal/core-server";
224
+
221
225
  // src/manifest.ts
222
226
  import * as fs from "node:fs/promises";
223
227
  import * as path2 from "node:path";
224
- import { groupBy } from "storybook/internal/common";
225
- import { Tag, analyzeMdx } from "storybook/internal/core-server";
228
+ import { getComponentIdFromEntry, groupBy } from "storybook/internal/common";
229
+ import {
230
+ Tag,
231
+ analyzeMdx,
232
+ mdxManifestRef
233
+ } from "storybook/internal/core-server";
226
234
  import { logger } from "storybook/internal/node-logger";
235
+
236
+ // src/extract-docs-summary.ts
237
+ function extractDocsSummary(content) {
238
+ let result = content;
239
+ result = result.replace(/^\s*import\s+(?:[\s\S]*?from\s+)?['"][^'"]+['"];?\s*$/gm, "");
240
+ let prevResult = "";
241
+ for (; prevResult !== result; )
242
+ prevResult = result, result = result.replace(/\{[^{}]*\}/g, "");
243
+ for (result = result.replace(/<[^>]+\/>/g, ""), prevResult = ""; prevResult !== result; )
244
+ prevResult = result, result = result.replace(/<(\w+)[^>]*>([\s\S]*?)<\/\1>/g, "$2");
245
+ if (result = result.replace(/<[^>]+>/g, ""), result = result.replace(/\s+/g, " ").trim(), !!result)
246
+ return result.length > 90 ? `${result.slice(0, 90)}...` : result;
247
+ }
248
+
249
+ // src/manifest.ts
227
250
  async function createDocsManifestEntry(entry) {
228
251
  let absolutePath = path2.join(process.cwd(), entry.importPath);
229
252
  try {
230
- let content = await fs.readFile(absolutePath, "utf-8"), { summary } = await analyzeMdx(content);
253
+ let content = await fs.readFile(absolutePath, "utf-8"), { summary } = await analyzeMdx(content), derivedSummary = summary ?? extractDocsSummary(content);
231
254
  return {
232
255
  id: entry.id,
233
256
  name: entry.name,
234
257
  path: entry.importPath,
235
258
  title: entry.title,
236
259
  content,
237
- ...summary && { summary }
260
+ ...derivedSummary !== void 0 && { summary: derivedSummary }
238
261
  };
239
262
  } catch (err) {
240
263
  return {
@@ -249,24 +272,39 @@ async function createDocsManifestEntry(entry) {
249
272
  };
250
273
  }
251
274
  }
252
- async function extractUnattachedDocsEntries(entries) {
253
- if (entries.length === 0)
254
- return {};
255
- let entriesWithContent = await Promise.all(entries.map(createDocsManifestEntry));
256
- return Object.fromEntries(entriesWithContent.map((entry) => [entry.id, entry]));
275
+ function createDocsManifestRefEntry(entry, componentId) {
276
+ return {
277
+ id: entry.id,
278
+ name: entry.name,
279
+ mdx: { $ref: mdxManifestRef(componentId, entry.id) }
280
+ };
281
+ }
282
+ async function buildUnattachedDocs(entries, build) {
283
+ let docs2 = await Promise.all(
284
+ entries.map(async (entry) => [entry.id, await build(entry, entry.id)])
285
+ );
286
+ return Object.fromEntries(docs2);
257
287
  }
258
- async function extractAttachedDocsEntries(entries, existingComponents) {
288
+ async function applyAttachedDocs(entries, existingComponents, build) {
259
289
  if (!existingComponents || entries.length === 0)
260
290
  return existingComponents;
261
- let entriesWithContent = await Promise.all(entries.map(createDocsManifestEntry));
262
- for (let docsEntry of entriesWithContent) {
263
- let componentId = docsEntry.id.split("--")[0], component = existingComponents.components[componentId];
264
- component && (component.docs || (component.docs = {}), component.docs[docsEntry.id] = docsEntry);
291
+ let docs2 = await Promise.all(
292
+ entries.map(async (entry) => {
293
+ let componentId = getComponentIdFromEntry(entry);
294
+ return { componentId, doc: await build(entry, componentId) };
295
+ })
296
+ ), components = { ...existingComponents.components };
297
+ for (let { componentId, doc } of docs2) {
298
+ let component = components[componentId] ?? { id: componentId, name: componentId };
299
+ components[componentId] = {
300
+ ...component,
301
+ docs: { ...component.docs, [doc.id]: doc }
302
+ };
265
303
  }
266
- return existingComponents;
304
+ return { ...existingComponents, components };
267
305
  }
268
- var manifests = async (existingManifests = {}, { manifestEntries }) => {
269
- let startPerformance = performance.now(), docsEntries = manifestEntries.filter(
306
+ var manifests = async (existingManifests = {}, { manifestEntries, presets }) => {
307
+ let startPerformance = performance.now(), features = await presets?.apply?.("features"), useMdxService = features?.experimentalDocgenServer === !0 && features?.componentsManifest === !0, docsEntries = manifestEntries.filter(
270
308
  (entry) => entry.type === "docs"
271
309
  );
272
310
  if (docsEntries.length === 0)
@@ -283,20 +321,398 @@ var manifests = async (existingManifests = {}, { manifestEntries }) => {
283
321
  });
284
322
  if (unattachedEntries.length === 0 && attachedEntries.length === 0)
285
323
  return existingManifests;
286
- let existingManifestsWithDocs = existingManifests, [unattachedDocs, updatedComponents] = await Promise.all([
287
- extractUnattachedDocsEntries(unattachedEntries),
288
- extractAttachedDocsEntries(attachedEntries, existingManifestsWithDocs.components)
324
+ let existingManifestsWithDocs = existingManifests, build = useMdxService ? createDocsManifestRefEntry : createDocsManifestEntry, [unattachedDocs, updatedComponents] = await Promise.all([
325
+ buildUnattachedDocs(unattachedEntries, build),
326
+ applyAttachedDocs(attachedEntries, existingManifestsWithDocs.components, build)
289
327
  ]), processedCount = unattachedEntries.length + attachedEntries.length;
290
328
  logger.verbose(
291
329
  `Docs manifest generation took ${performance.now() - startPerformance}ms for ${processedCount} entries (${unattachedEntries.length} unattached, ${attachedEntries.length} attached)`
292
330
  );
293
331
  let result = { ...existingManifestsWithDocs };
294
332
  return Object.keys(unattachedDocs).length > 0 && (result.docs = {
295
- v: 0,
333
+ v: useMdxService ? 1 : 0,
296
334
  docs: unattachedDocs
297
335
  }), updatedComponents && (result.components = updatedComponents), result;
298
336
  };
299
337
 
338
+ // src/mdx-service/definition.ts
339
+ import {
340
+ MDX_SERVICE_ID,
341
+ mdxQueryStaticPath
342
+ } from "storybook/internal/core-server";
343
+
344
+ // ../../../node_modules/valibot/dist/index.mjs
345
+ var store$4, DEFAULT_CONFIG = {
346
+ lang: void 0,
347
+ message: void 0,
348
+ abortEarly: void 0,
349
+ abortPipeEarly: void 0
350
+ };
351
+ function getGlobalConfig(config$1) {
352
+ return !config$1 && !store$4 ? DEFAULT_CONFIG : {
353
+ lang: config$1?.lang ?? store$4?.lang,
354
+ message: config$1?.message,
355
+ abortEarly: config$1?.abortEarly ?? store$4?.abortEarly,
356
+ abortPipeEarly: config$1?.abortPipeEarly ?? store$4?.abortPipeEarly
357
+ };
358
+ }
359
+ var store$3;
360
+ function getGlobalMessage(lang) {
361
+ return store$3?.get(lang);
362
+ }
363
+ var store$2;
364
+ function getSchemaMessage(lang) {
365
+ return store$2?.get(lang);
366
+ }
367
+ var store$1;
368
+ function getSpecificMessage(reference, lang) {
369
+ return store$1?.get(reference)?.get(lang);
370
+ }
371
+ function _stringify(input) {
372
+ let type = typeof input;
373
+ return type === "string" ? `"${input}"` : type === "number" || type === "bigint" || type === "boolean" ? `${input}` : type === "object" || type === "function" ? (input && Object.getPrototypeOf(input)?.constructor?.name) ?? "null" : type;
374
+ }
375
+ function _addIssue(context, label, dataset, config$1, other) {
376
+ let input = other && "input" in other ? other.input : dataset.value, expected = other?.expected ?? context.expects ?? null, received = other?.received ?? _stringify(input), issue = {
377
+ kind: context.kind,
378
+ type: context.type,
379
+ input,
380
+ expected,
381
+ received,
382
+ message: `Invalid ${label}: ${expected ? `Expected ${expected} but r` : "R"}eceived ${received}`,
383
+ requirement: context.requirement,
384
+ path: other?.path,
385
+ issues: other?.issues,
386
+ lang: config$1.lang,
387
+ abortEarly: config$1.abortEarly,
388
+ abortPipeEarly: config$1.abortPipeEarly
389
+ }, isSchema = context.kind === "schema", message$1 = other?.message ?? context.message ?? getSpecificMessage(context.reference, issue.lang) ?? (isSchema ? getSchemaMessage(issue.lang) : null) ?? config$1.message ?? getGlobalMessage(issue.lang);
390
+ message$1 !== void 0 && (issue.message = typeof message$1 == "function" ? message$1(issue) : message$1), isSchema && (dataset.typed = !1), dataset.issues ? dataset.issues.push(issue) : dataset.issues = [issue];
391
+ }
392
+ var _standardCache = /* @__PURE__ */ new WeakMap();
393
+ function _getStandardProps(context) {
394
+ let cached = _standardCache.get(context);
395
+ return cached || (cached = {
396
+ version: 1,
397
+ vendor: "valibot",
398
+ validate(value$1) {
399
+ return context["~run"]({ value: value$1 }, getGlobalConfig());
400
+ }
401
+ }, _standardCache.set(context, cached)), cached;
402
+ }
403
+ function _isValidObjectKey(object$1, key) {
404
+ return Object.prototype.hasOwnProperty.call(object$1, key) && key !== "__proto__" && key !== "prototype" && key !== "constructor";
405
+ }
406
+ var EMOJI_REGEX = new RegExp("^(?:[\\u{1F1E6}-\\u{1F1FF}]{2}|\\u{1F3F4}[\\u{E0061}-\\u{E007A}]{2}[\\u{E0030}-\\u{E0039}\\u{E0061}-\\u{E007A}]{1,3}\\u{E007F}|(?:\\p{Emoji}\\uFE0F\\u20E3?|\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|(?![\\p{Emoji_Modifier_Base}\\u{1F1E6}-\\u{1F1FF}])\\p{Emoji_Presentation})(?:\\u200D(?:\\p{Emoji}\\uFE0F\\u20E3?|\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|(?![\\p{Emoji_Modifier_Base}\\u{1F1E6}-\\u{1F1FF}])\\p{Emoji_Presentation}))*)+$", "u");
407
+ function getFallback(schema, dataset, config$1) {
408
+ return typeof schema.fallback == "function" ? schema.fallback(dataset, config$1) : schema.fallback;
409
+ }
410
+ function getDefault(schema, dataset, config$1) {
411
+ return typeof schema.default == "function" ? schema.default(dataset, config$1) : schema.default;
412
+ }
413
+ function object(entries$1, message$1) {
414
+ return {
415
+ kind: "schema",
416
+ type: "object",
417
+ reference: object,
418
+ expects: "Object",
419
+ async: !1,
420
+ entries: entries$1,
421
+ message: message$1,
422
+ get "~standard"() {
423
+ return _getStandardProps(this);
424
+ },
425
+ "~run"(dataset, config$1) {
426
+ let input = dataset.value;
427
+ if (input && typeof input == "object") {
428
+ dataset.typed = !0, dataset.value = {};
429
+ for (let key in this.entries) {
430
+ let valueSchema = this.entries[key];
431
+ if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && valueSchema.default !== void 0) {
432
+ let value$1 = key in input ? input[key] : getDefault(valueSchema), valueDataset = valueSchema["~run"]({ value: value$1 }, config$1);
433
+ if (valueDataset.issues) {
434
+ let pathItem = {
435
+ type: "object",
436
+ origin: "value",
437
+ input,
438
+ key,
439
+ value: value$1
440
+ };
441
+ for (let issue of valueDataset.issues)
442
+ issue.path ? issue.path.unshift(pathItem) : issue.path = [pathItem], dataset.issues?.push(issue);
443
+ if (dataset.issues || (dataset.issues = valueDataset.issues), config$1.abortEarly) {
444
+ dataset.typed = !1;
445
+ break;
446
+ }
447
+ }
448
+ valueDataset.typed || (dataset.typed = !1), dataset.value[key] = valueDataset.value;
449
+ } else if (valueSchema.fallback !== void 0) dataset.value[key] = getFallback(valueSchema);
450
+ else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish" && (_addIssue(this, "key", dataset, config$1, {
451
+ input: void 0,
452
+ expected: `"${key}"`,
453
+ path: [{
454
+ type: "object",
455
+ origin: "key",
456
+ input,
457
+ key,
458
+ value: input[key]
459
+ }]
460
+ }), config$1.abortEarly))
461
+ break;
462
+ }
463
+ } else _addIssue(this, "type", dataset, config$1);
464
+ return dataset;
465
+ }
466
+ };
467
+ }
468
+ function optional(wrapped, default_) {
469
+ return {
470
+ kind: "schema",
471
+ type: "optional",
472
+ reference: optional,
473
+ expects: `(${wrapped.expects} | undefined)`,
474
+ async: !1,
475
+ wrapped,
476
+ default: default_,
477
+ get "~standard"() {
478
+ return _getStandardProps(this);
479
+ },
480
+ "~run"(dataset, config$1) {
481
+ return dataset.value === void 0 && (this.default !== void 0 && (dataset.value = getDefault(this, dataset, config$1)), dataset.value === void 0) ? (dataset.typed = !0, dataset) : this.wrapped["~run"](dataset, config$1);
482
+ }
483
+ };
484
+ }
485
+ function record(key, value$1, message$1) {
486
+ return {
487
+ kind: "schema",
488
+ type: "record",
489
+ reference: record,
490
+ expects: "Object",
491
+ async: !1,
492
+ key,
493
+ value: value$1,
494
+ message: message$1,
495
+ get "~standard"() {
496
+ return _getStandardProps(this);
497
+ },
498
+ "~run"(dataset, config$1) {
499
+ let input = dataset.value;
500
+ if (input && typeof input == "object") {
501
+ dataset.typed = !0, dataset.value = {};
502
+ for (let entryKey in input) if (_isValidObjectKey(input, entryKey)) {
503
+ let entryValue = input[entryKey], keyDataset = this.key["~run"]({ value: entryKey }, config$1);
504
+ if (keyDataset.issues) {
505
+ let pathItem = {
506
+ type: "object",
507
+ origin: "key",
508
+ input,
509
+ key: entryKey,
510
+ value: entryValue
511
+ };
512
+ for (let issue of keyDataset.issues)
513
+ issue.path = [pathItem], dataset.issues?.push(issue);
514
+ if (dataset.issues || (dataset.issues = keyDataset.issues), config$1.abortEarly) {
515
+ dataset.typed = !1;
516
+ break;
517
+ }
518
+ }
519
+ let valueDataset = this.value["~run"]({ value: entryValue }, config$1);
520
+ if (valueDataset.issues) {
521
+ let pathItem = {
522
+ type: "object",
523
+ origin: "value",
524
+ input,
525
+ key: entryKey,
526
+ value: entryValue
527
+ };
528
+ for (let issue of valueDataset.issues)
529
+ issue.path ? issue.path.unshift(pathItem) : issue.path = [pathItem], dataset.issues?.push(issue);
530
+ if (dataset.issues || (dataset.issues = valueDataset.issues), config$1.abortEarly) {
531
+ dataset.typed = !1;
532
+ break;
533
+ }
534
+ }
535
+ (!keyDataset.typed || !valueDataset.typed) && (dataset.typed = !1), keyDataset.typed && (dataset.value[keyDataset.value] = valueDataset.value);
536
+ }
537
+ } else _addIssue(this, "type", dataset, config$1);
538
+ return dataset;
539
+ }
540
+ };
541
+ }
542
+ function string(message$1) {
543
+ return {
544
+ kind: "schema",
545
+ type: "string",
546
+ reference: string,
547
+ expects: "string",
548
+ async: !1,
549
+ message: message$1,
550
+ get "~standard"() {
551
+ return _getStandardProps(this);
552
+ },
553
+ "~run"(dataset, config$1) {
554
+ return typeof dataset.value == "string" ? dataset.typed = !0 : _addIssue(this, "type", dataset, config$1), dataset;
555
+ }
556
+ };
557
+ }
558
+ function undefined_(message$1) {
559
+ return {
560
+ kind: "schema",
561
+ type: "undefined",
562
+ reference: undefined_,
563
+ expects: "undefined",
564
+ async: !1,
565
+ message: message$1,
566
+ get "~standard"() {
567
+ return _getStandardProps(this);
568
+ },
569
+ "~run"(dataset, config$1) {
570
+ return dataset.value === void 0 ? dataset.typed = !0 : _addIssue(this, "type", dataset, config$1), dataset;
571
+ }
572
+ };
573
+ }
574
+ function void_(message$1) {
575
+ return {
576
+ kind: "schema",
577
+ type: "void",
578
+ reference: void_,
579
+ expects: "void",
580
+ async: !1,
581
+ message: message$1,
582
+ get "~standard"() {
583
+ return _getStandardProps(this);
584
+ },
585
+ "~run"(dataset, config$1) {
586
+ return dataset.value === void 0 ? dataset.typed = !0 : _addIssue(this, "type", dataset, config$1), dataset;
587
+ }
588
+ };
589
+ }
590
+
591
+ // src/mdx-service/definition.ts
592
+ import { defineService } from "storybook/open-service";
593
+ var mdxInputSchema = object({ id: string() }), mdxErrorSchema = object({
594
+ name: string(),
595
+ message: string()
596
+ }), mdxDocPayloadSchema = object({
597
+ id: string(),
598
+ name: string(),
599
+ path: string(),
600
+ title: string(),
601
+ content: optional(string()),
602
+ summary: optional(string()),
603
+ error: optional(mdxErrorSchema)
604
+ }), mdxPayloadSchema = object({
605
+ id: string(),
606
+ name: string(),
607
+ docs: record(string(), mdxDocPayloadSchema)
608
+ }), mdxOutputSchema = optional(mdxPayloadSchema), mdxServiceDef = defineService({
609
+ id: MDX_SERVICE_ID,
610
+ internal: !0,
611
+ // this service really only ensures that the MDX docs are available in manifests, so there is no need to expose it to the public API
612
+ initialState: { components: {} },
613
+ queries: {
614
+ mdxForComponent: {
615
+ input: mdxInputSchema,
616
+ output: mdxOutputSchema,
617
+ handler: (input, ctx) => ctx.self.state.components[input.id],
618
+ load: async (input, ctx) => {
619
+ await ctx.self.commands._extractMdxForComponent(input);
620
+ },
621
+ staticPath: (input) => mdxQueryStaticPath(input.id)
622
+ },
623
+ mdxForAllComponents: {
624
+ input: void_(),
625
+ output: record(string(), mdxPayloadSchema),
626
+ handler: (_input, ctx) => ctx.self.state.components,
627
+ load: async (_input, ctx) => {
628
+ await ctx.self.commands._extractAllMdx(void 0);
629
+ }
630
+ }
631
+ },
632
+ commands: {
633
+ _extractMdxForComponent: {
634
+ internal: !0,
635
+ input: mdxInputSchema,
636
+ output: mdxOutputSchema
637
+ },
638
+ _extractAllMdx: {
639
+ internal: !0,
640
+ input: undefined_(),
641
+ output: void_()
642
+ }
643
+ }
644
+ });
645
+
646
+ // src/mdx-service/server.ts
647
+ function groupMdxEntriesByComponent(index) {
648
+ return groupBy2(
649
+ Object.values(index.entries).filter(
650
+ (entry) => entry.type === "docs" && ((entry.tags?.includes(Tag2.ATTACHED_MDX) ?? !1) || (entry.tags?.includes(Tag2.UNATTACHED_MDX) ?? !1))
651
+ ),
652
+ (entry) => entry.tags?.includes(Tag2.ATTACHED_MDX) ? getComponentIdFromEntry2(entry) : entry.id
653
+ );
654
+ }
655
+ var defaultMdxProvider = async ({ componentId, entries }) => {
656
+ if (entries.length === 0)
657
+ return;
658
+ let docs2 = await Promise.all(entries.map(createDocsManifestEntry));
659
+ return {
660
+ id: componentId,
661
+ name: componentId,
662
+ docs: Object.fromEntries(docs2.map((doc) => [doc.id, doc]))
663
+ };
664
+ };
665
+ function registerMdxService({
666
+ getIndex,
667
+ provider = defaultMdxProvider
668
+ }) {
669
+ return registerService(mdxServiceDef, {
670
+ queries: {
671
+ mdxForComponent: {
672
+ staticInputs: async () => {
673
+ let index = await getIndex(), grouped = groupMdxEntriesByComponent(index);
674
+ return Object.keys(grouped).map((id) => ({ id }));
675
+ }
676
+ }
677
+ },
678
+ commands: {
679
+ _extractMdxForComponent: {
680
+ handler: async (input, ctx) => {
681
+ let index = await getIndex(), entries = groupMdxEntriesByComponent(index)[input.id] ?? [];
682
+ if (entries.length === 0)
683
+ return;
684
+ let payload = await provider({
685
+ componentId: input.id,
686
+ entries
687
+ });
688
+ if (payload)
689
+ return ctx.self.setState((state) => {
690
+ state.components[input.id] = payload;
691
+ }), payload;
692
+ }
693
+ },
694
+ _extractAllMdx: {
695
+ handler: async (_input, ctx) => {
696
+ let index = await getIndex(), grouped = groupMdxEntriesByComponent(index), extracted = await Promise.all(
697
+ Object.entries(grouped).map(async ([id, entries]) => {
698
+ let payload = await provider({ componentId: id, entries });
699
+ return payload ? [id, payload] : void 0;
700
+ })
701
+ );
702
+ ctx.self.setState((state) => {
703
+ for (let result of extracted) {
704
+ if (!result)
705
+ continue;
706
+ let [id, payload] = result;
707
+ state.components[id] = payload;
708
+ }
709
+ });
710
+ }
711
+ }
712
+ }
713
+ });
714
+ }
715
+
300
716
  // src/docgen.ts
301
717
  var experimental_docgenProvider = async (nextDocgen) => async (input) => {
302
718
  let downstream = await nextDocgen(input);
@@ -322,7 +738,7 @@ var getResolvedReact = async (options) => {
322
738
  };
323
739
  };
324
740
  async function webpack(webpackConfig = {}, options) {
325
- let { module = {} } = webpackConfig, { csfPluginOptions = {}, mdxPluginOptions = {} } = options, enrichCsf = await options.presets.apply("experimental_enrichCsf"), rehypeSlug = (await import("./_node-chunks/rehype-slug-EPMUVHIS.js")).default, rehypeExternalLinks = (await import("./_node-chunks/rehype-external-links-QE2YWBRR.js")).default, mdxLoaderOptions = await options.presets.apply("mdxLoaderOptions", {
741
+ let { module = {} } = webpackConfig, { csfPluginOptions = {}, mdxPluginOptions = {} } = options, enrichCsf = await options.presets.apply("experimental_enrichCsf"), rehypeSlug = (await import("./_node-chunks/rehype-slug-D2I7KZ4I.js")).default, rehypeExternalLinks = (await import("./_node-chunks/rehype-external-links-2RDYL6C3.js")).default, mdxLoaderOptions = await options.presets.apply("mdxLoaderOptions", {
326
742
  ...mdxPluginOptions,
327
743
  mdxCompileOptions: {
328
744
  providerImportSource: fileURLToPath2(
@@ -400,7 +816,7 @@ var docs = (input = {}, options) => {
400
816
  }, addons = [
401
817
  import.meta.resolve("@storybook/react-dom-shim/preset")
402
818
  ], viteFinal = async (config, options) => {
403
- let { plugins = [] } = config, { mdxPlugin } = await import("./_node-chunks/mdx-plugin-R2MYDMMD.js"), { react, reactDom, mdx } = await getResolvedReact(options), packageDeduplicationPlugin = {
819
+ let { plugins = [] } = config, { mdxPlugin } = await import("./_node-chunks/mdx-plugin-XDOSSZCW.js"), { react, reactDom, mdx } = await getResolvedReact(options), packageDeduplicationPlugin = {
404
820
  name: "storybook:package-deduplication",
405
821
  enforce: "pre",
406
822
  config: () => ({
@@ -423,7 +839,15 @@ var docs = (input = {}, options) => {
423
839
  react: existing?.react ?? resolvePackageDir("react"),
424
840
  reactDom: existing?.reactDom ?? resolvePackageDir("react-dom"),
425
841
  mdx: existing?.mdx ?? fileURLToPath2(import.meta.resolve("@mdx-js/react"))
426
- }), optimizeViteDeps = [
842
+ }), services = async (_value, options) => {
843
+ let features = await options.presets.apply("features");
844
+ if (features?.experimentalDocgenServer && features?.componentsManifest && !options.ignorePreview) {
845
+ let generator = await options.presets.apply("storyIndexGenerator");
846
+ registerMdxService({
847
+ getIndex: () => generator.getIndex()
848
+ });
849
+ }
850
+ }, optimizeViteDeps = [
427
851
  "@storybook/addon-docs",
428
852
  "@storybook/addon-docs/blocks",
429
853
  "@storybook/addon-docs > @mdx-js/react",
@@ -439,6 +863,7 @@ export {
439
863
  manifests as experimental_manifests,
440
864
  optimizeViteDeps,
441
865
  resolvedReact,
866
+ services,
442
867
  viteFinal,
443
868
  webpackX as webpack
444
869
  };