@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/_node-chunks/{chunk-BS47STAB.js → chunk-NDIMOQRQ.js} +6 -6
- package/dist/_node-chunks/{chunk-2WTY7RHL.js → chunk-Q33Y654V.js} +9 -9
- package/dist/_node-chunks/{chunk-ZM6M6OKB.js → chunk-RDCEJST6.js} +6 -6
- package/dist/_node-chunks/{chunk-AR7B7DGI.js → chunk-X327Z4QW.js} +6 -6
- package/dist/_node-chunks/{mdx-plugin-R2MYDMMD.js → mdx-plugin-XDOSSZCW.js} +11 -11
- package/dist/_node-chunks/{rehype-external-links-QE2YWBRR.js → rehype-external-links-2RDYL6C3.js} +9 -9
- package/dist/_node-chunks/{rehype-slug-EPMUVHIS.js → rehype-slug-D2I7KZ4I.js} +8 -8
- package/dist/blocks.d.ts +1 -1
- package/dist/blocks.js +203 -85
- package/dist/index.d.ts +14 -2
- package/dist/manager.js +32 -24
- package/dist/mdx-loader.js +10 -10
- package/dist/preset.js +456 -31
- package/package.json +4 -4
package/dist/blocks.js
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
import "./_browser-chunks/chunk-UAWMPV5J.js";
|
|
15
15
|
|
|
16
16
|
// src/blocks/components/ArgsTable/ArgsTable.tsx
|
|
17
|
-
import React23 from "react";
|
|
17
|
+
import React23, { useCallback as useCallback6, useEffect as useEffect8, useRef as useRef5, useState as useState11 } from "react";
|
|
18
18
|
import { once } from "storybook/internal/client-logger";
|
|
19
19
|
import { Button as Button5, Link as Link3, ResetWrapper } from "storybook/internal/components";
|
|
20
20
|
import { includeConditionalArg } from "storybook/internal/csf";
|
|
@@ -3442,14 +3442,20 @@ var sortFns = {
|
|
|
3442
3442
|
isLoading,
|
|
3443
3443
|
storyId,
|
|
3444
3444
|
controlsId
|
|
3445
|
-
} = props;
|
|
3445
|
+
} = props, { rows, args, globals } = "rows" in props ? props : { rows: void 0, args: void 0, globals: void 0 }, isResettingRef = useRef5(!1), [isResetting, setIsResetting] = useState11(!1);
|
|
3446
|
+
useEffect8(() => {
|
|
3447
|
+
isResettingRef.current = !1, setIsResetting(!1);
|
|
3448
|
+
}, [args]);
|
|
3449
|
+
let handleResetClick = useCallback6(() => {
|
|
3450
|
+
!isResettingRef.current && resetArgs && (isResettingRef.current = !0, setIsResetting(!0), resetArgs());
|
|
3451
|
+
}, [resetArgs]);
|
|
3446
3452
|
if ("error" in props) {
|
|
3447
3453
|
let { error } = props;
|
|
3448
3454
|
return React23.createElement(EmptyBlock, null, error, "\xA0", React23.createElement(Link3, { href: "http://storybook.js.org/docs/?ref=ui", target: "_blank", withArrow: !0 }, React23.createElement(DocumentIcon2, null), " Read the docs"));
|
|
3449
3455
|
}
|
|
3450
3456
|
if (isLoading)
|
|
3451
3457
|
return React23.createElement(Skeleton, null);
|
|
3452
|
-
let
|
|
3458
|
+
let groups = groupRows(
|
|
3453
3459
|
pickBy(
|
|
3454
3460
|
rows || {},
|
|
3455
3461
|
(row) => !row?.table?.disable && safeIncludeConditionalArg(row, args || {}, globals || {})
|
|
@@ -3473,8 +3479,9 @@ var sortFns = {
|
|
|
3473
3479
|
{
|
|
3474
3480
|
variant: "ghost",
|
|
3475
3481
|
padding: "small",
|
|
3476
|
-
onClick:
|
|
3477
|
-
|
|
3482
|
+
onClick: handleResetClick,
|
|
3483
|
+
disabled: isResetting,
|
|
3484
|
+
ariaLabel: isResetting ? "Resetting controls..." : "Reset controls"
|
|
3478
3485
|
},
|
|
3479
3486
|
React23.createElement(UndoIcon, null)
|
|
3480
3487
|
)), React23.createElement(
|
|
@@ -3921,7 +3928,7 @@ var toGlobalSelector = (element) => `& :where(${element}:not(.sb-anchor, .sb-uns
|
|
|
3921
3928
|
})), DocsPageWrapper = ({ children, toc }) => React24.createElement(DocsWrapper, { className: "sbdocs sbdocs-wrapper" }, toc, React24.createElement(DocsContent, { className: "sbdocs sbdocs-content" }, children));
|
|
3922
3929
|
|
|
3923
3930
|
// src/blocks/components/Preview.tsx
|
|
3924
|
-
import React30, { Children, useCallback as
|
|
3931
|
+
import React30, { Children, useCallback as useCallback7, useContext as useContext2, useMemo as useMemo3, useState as useState14 } from "react";
|
|
3925
3932
|
import { logger as logger4 } from "storybook/internal/client-logger";
|
|
3926
3933
|
import { Bar, Button as Button7, ToggleButton as ToggleButton2, Zoom } from "storybook/internal/components";
|
|
3927
3934
|
import { CopyIcon, MarkupIcon } from "@storybook/icons";
|
|
@@ -4251,14 +4258,14 @@ import React26, { useContext } from "react";
|
|
|
4251
4258
|
import { InvalidBlockOfPropError } from "storybook/internal/preview-errors";
|
|
4252
4259
|
|
|
4253
4260
|
// src/blocks/blocks/useStory.ts
|
|
4254
|
-
import { useEffect as
|
|
4261
|
+
import { useEffect as useEffect9, useState as useState12 } from "react";
|
|
4255
4262
|
function useStory(storyId, context) {
|
|
4256
4263
|
let stories = useStories([storyId], context);
|
|
4257
4264
|
return stories && stories[0];
|
|
4258
4265
|
}
|
|
4259
4266
|
function useStories(storyIds, context) {
|
|
4260
|
-
let [storiesById, setStories] =
|
|
4261
|
-
return
|
|
4267
|
+
let [storiesById, setStories] = useState12({});
|
|
4268
|
+
return useEffect9(() => {
|
|
4262
4269
|
Promise.all(
|
|
4263
4270
|
storyIds.map(async (storyId) => {
|
|
4264
4271
|
let story = await context.loadStory(storyId);
|
|
@@ -4341,7 +4348,7 @@ var getBlockBackgroundStyle = (theme) => ({
|
|
|
4341
4348
|
});
|
|
4342
4349
|
|
|
4343
4350
|
// src/blocks/components/Story.tsx
|
|
4344
|
-
import React28, { useEffect as
|
|
4351
|
+
import React28, { useEffect as useEffect10, useRef as useRef6, useState as useState13 } from "react";
|
|
4345
4352
|
import { ErrorFormatter, Loader } from "storybook/internal/components";
|
|
4346
4353
|
import { styled as styled20 } from "storybook/theming";
|
|
4347
4354
|
|
|
@@ -4400,8 +4407,8 @@ var ZoomContext = createContext2({
|
|
|
4400
4407
|
|
|
4401
4408
|
// src/blocks/components/Story.tsx
|
|
4402
4409
|
var storyBlockIdFromId = ({ story, primary }) => `story--${story.id}${primary ? "--primary" : ""}`, InlineStory = (props) => {
|
|
4403
|
-
let storyRef =
|
|
4404
|
-
return
|
|
4410
|
+
let storyRef = useRef6(), [showLoader, setShowLoader] = useState13(!0), [error, setError] = useState13(), { story, height, autoplay, forceInitialArgs, renderStoryToElement } = props;
|
|
4411
|
+
return useEffect10(() => {
|
|
4405
4412
|
if (!(story && storyRef.current))
|
|
4406
4413
|
return () => {
|
|
4407
4414
|
};
|
|
@@ -4620,13 +4627,13 @@ var PositionedToolbar = styled22(Toolbar)({
|
|
|
4620
4627
|
onReloadStory,
|
|
4621
4628
|
...props
|
|
4622
4629
|
}) => {
|
|
4623
|
-
let [expanded, setExpanded] =
|
|
4630
|
+
let [expanded, setExpanded] = useState14(isExpanded), [copied, setCopied] = useState14(null), [scale, setScale] = useState14(1), additionalActionItems = useMemo3(
|
|
4624
4631
|
() => additionalActions ? [...additionalActions] : [],
|
|
4625
4632
|
[additionalActions]
|
|
4626
|
-
), sourceId = $bdb11010cef70236$export$f680877a34711e37(), previewClasses = [className].concat(["sbdocs", "sbdocs-preview", "sb-unstyled"]), context = useContext2(DocsContext), copyToClipboard =
|
|
4633
|
+
), sourceId = $bdb11010cef70236$export$f680877a34711e37(), previewClasses = [className].concat(["sbdocs", "sbdocs-preview", "sb-unstyled"]), context = useContext2(DocsContext), copyToClipboard = useCallback7(async (text) => {
|
|
4627
4634
|
let { createCopyToClipboardFunction } = await import("storybook/internal/components");
|
|
4628
4635
|
await createCopyToClipboardFunction()(text);
|
|
4629
|
-
}, []), handleCopyCode =
|
|
4636
|
+
}, []), handleCopyCode = useCallback7(async () => {
|
|
4630
4637
|
try {
|
|
4631
4638
|
await copyToClipboard(withSource?.code ?? ""), setCopied("Copied!");
|
|
4632
4639
|
} catch (err) {
|
|
@@ -4918,7 +4925,7 @@ var ItemLabel = styled26.div(({ theme }) => ({
|
|
|
4918
4925
|
}), IconItem = ({ name, children }) => React34.createElement(Item2, null, React34.createElement(ItemSpecimen, null, children), React34.createElement(ItemLabel, null, name)), IconGallery = ({ children, ...props }) => React34.createElement(ResetWrapper3, null, React34.createElement(List2, { ...props, className: "docblock-icongallery sb-unstyled" }, children));
|
|
4919
4926
|
|
|
4920
4927
|
// src/blocks/components/TableOfContents.tsx
|
|
4921
|
-
import React35, { useEffect as
|
|
4928
|
+
import React35, { useEffect as useEffect11 } from "react";
|
|
4922
4929
|
import { NAVIGATE_URL } from "storybook/internal/core-events";
|
|
4923
4930
|
import { styled as styled27 } from "storybook/theming";
|
|
4924
4931
|
|
|
@@ -5516,7 +5523,7 @@ var Aside = styled27.aside(() => ({
|
|
|
5516
5523
|
channel,
|
|
5517
5524
|
className
|
|
5518
5525
|
}) => {
|
|
5519
|
-
|
|
5526
|
+
useEffect11(() => {
|
|
5520
5527
|
if (disable)
|
|
5521
5528
|
return () => {
|
|
5522
5529
|
};
|
|
@@ -5561,24 +5568,59 @@ import {
|
|
|
5561
5568
|
mergeServiceArgTypes
|
|
5562
5569
|
} from "storybook/internal/docs-tools";
|
|
5563
5570
|
|
|
5564
|
-
// src/blocks/blocks/
|
|
5565
|
-
import { useCallback as useCallback7, useMemo as useMemo4, useRef as useRef6, useSyncExternalStore } from "react";
|
|
5571
|
+
// src/blocks/blocks/use-service-docgen.ts
|
|
5566
5572
|
import { getService } from "storybook/preview-api";
|
|
5567
|
-
|
|
5568
|
-
|
|
5569
|
-
|
|
5570
|
-
|
|
5571
|
-
|
|
5572
|
-
|
|
5573
|
-
|
|
5574
|
-
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
|
|
5573
|
+
|
|
5574
|
+
// src/blocks/blocks/use-query-subscription.ts
|
|
5575
|
+
import { useCallback as useCallback8, useRef as useRef7 } from "react";
|
|
5576
|
+
import { seedQueryState } from "storybook/open-service";
|
|
5577
|
+
|
|
5578
|
+
// src/blocks/blocks/useSyncExternalStoreShim.ts
|
|
5579
|
+
import { useEffect as useEffect12, useLayoutEffect, useState as useState15 } from "react";
|
|
5580
|
+
function useSyncExternalStoreShim(subscribe, getSnapshot) {
|
|
5581
|
+
let value = getSnapshot(), [{ inst }, forceUpdate] = useState15({ inst: { value, getSnapshot } });
|
|
5582
|
+
return useLayoutEffect(() => {
|
|
5583
|
+
inst.value = value, inst.getSnapshot = getSnapshot, didSnapshotChange(inst) && forceUpdate({ inst });
|
|
5584
|
+
}, [subscribe, value, getSnapshot]), useEffect12(() => (didSnapshotChange(inst) && forceUpdate({ inst }), subscribe(() => {
|
|
5585
|
+
didSnapshotChange(inst) && forceUpdate({ inst });
|
|
5586
|
+
})), [subscribe]), value;
|
|
5587
|
+
}
|
|
5588
|
+
function didSnapshotChange(inst) {
|
|
5589
|
+
let latestGetSnapshot = inst.getSnapshot, prevValue = inst.value;
|
|
5590
|
+
try {
|
|
5591
|
+
let nextValue = latestGetSnapshot();
|
|
5592
|
+
return !Object.is(prevValue, nextValue);
|
|
5593
|
+
} catch {
|
|
5594
|
+
return !0;
|
|
5595
|
+
}
|
|
5596
|
+
}
|
|
5597
|
+
|
|
5598
|
+
// src/blocks/blocks/use-query-subscription.ts
|
|
5599
|
+
function useQuerySubscription(cacheKey, query, input, selector) {
|
|
5600
|
+
let cache = useRef7(void 0);
|
|
5601
|
+
(cache.current?.key !== cacheKey || cache.current.selector !== selector) && (cache.current = {
|
|
5602
|
+
key: cacheKey,
|
|
5603
|
+
selector,
|
|
5604
|
+
state: selector ? seedQueryState(query, input, selector) : seedQueryState(query, input)
|
|
5605
|
+
});
|
|
5606
|
+
let inputRef = useRef7(input);
|
|
5607
|
+
inputRef.current = input;
|
|
5608
|
+
let subscribe = useCallback8(
|
|
5609
|
+
(listener) => {
|
|
5610
|
+
let onQueryState = (state) => {
|
|
5611
|
+
cache.current = { key: cacheKey, selector, state }, listener();
|
|
5612
|
+
};
|
|
5613
|
+
return selector ? query.subscribe(inputRef.current, selector, onQueryState) : query.subscribe(inputRef.current, onQueryState);
|
|
5578
5614
|
},
|
|
5579
|
-
[
|
|
5580
|
-
);
|
|
5581
|
-
return
|
|
5615
|
+
[query, cacheKey, selector]
|
|
5616
|
+
), getSnapshot = useCallback8(() => cache.current.state, []);
|
|
5617
|
+
return useSyncExternalStoreShim(subscribe, getSnapshot);
|
|
5618
|
+
}
|
|
5619
|
+
|
|
5620
|
+
// src/blocks/blocks/use-service-docgen.ts
|
|
5621
|
+
function useServiceDocgen(id) {
|
|
5622
|
+
let service = getService("core/docgen");
|
|
5623
|
+
return useQuerySubscription(id, service.queries.docgen, { id });
|
|
5582
5624
|
}
|
|
5583
5625
|
|
|
5584
5626
|
// src/blocks/blocks/argTypesShared.ts
|
|
@@ -5603,18 +5645,21 @@ function useDocgenServiceRows({
|
|
|
5603
5645
|
initialArgs,
|
|
5604
5646
|
customArgTypes
|
|
5605
5647
|
}) {
|
|
5606
|
-
let servicePayload = useServiceDocgen(componentId);
|
|
5607
|
-
return
|
|
5608
|
-
|
|
5609
|
-
|
|
5610
|
-
|
|
5611
|
-
|
|
5612
|
-
|
|
5613
|
-
|
|
5614
|
-
|
|
5615
|
-
|
|
5616
|
-
|
|
5617
|
-
|
|
5648
|
+
let { data: servicePayload, isInitialLoading } = useServiceDocgen(componentId);
|
|
5649
|
+
return servicePayload ? {
|
|
5650
|
+
rows: {
|
|
5651
|
+
serviceComponentName: servicePayload.name,
|
|
5652
|
+
mainRows: mergeServiceArgTypes({
|
|
5653
|
+
payload: servicePayload,
|
|
5654
|
+
storyId: storyId ?? componentId,
|
|
5655
|
+
parameters,
|
|
5656
|
+
initialArgs,
|
|
5657
|
+
customArgTypes
|
|
5658
|
+
}),
|
|
5659
|
+
subcomponentRows: getServiceSubcomponentArgTypes(servicePayload)
|
|
5660
|
+
},
|
|
5661
|
+
isInitialLoading
|
|
5662
|
+
} : { rows: null, isInitialLoading };
|
|
5618
5663
|
}
|
|
5619
5664
|
|
|
5620
5665
|
// src/blocks/blocks/useOf.ts
|
|
@@ -5719,14 +5764,14 @@ var LegacyArgTypes = (props) => {
|
|
|
5719
5764
|
...filterProps
|
|
5720
5765
|
}) : null;
|
|
5721
5766
|
}, DocgenServiceArgTypes = (props) => {
|
|
5722
|
-
let { argTypes, parameters, componentId, storyId, initialArgs, filterProps, component } = useResolveArgTypes(props), serviceRows = useDocgenServiceRows({
|
|
5767
|
+
let { argTypes, parameters, componentId, storyId, initialArgs, filterProps, component } = useResolveArgTypes(props), { rows: serviceRows, isInitialLoading } = useDocgenServiceRows({
|
|
5723
5768
|
componentId,
|
|
5724
5769
|
storyId,
|
|
5725
5770
|
parameters,
|
|
5726
5771
|
initialArgs,
|
|
5727
5772
|
customArgTypes: argTypes
|
|
5728
5773
|
});
|
|
5729
|
-
return serviceRows ? renderArgTypesTables({
|
|
5774
|
+
return isInitialLoading ? React37.createElement(ArgsTable, { isLoading: !0 }) : serviceRows ? renderArgTypesTables({
|
|
5730
5775
|
mainName: getComponentName(component) ?? serviceRows.serviceComponentName,
|
|
5731
5776
|
mainRows: serviceRows.mainRows,
|
|
5732
5777
|
subcomponentRows: serviceRows.subcomponentRows,
|
|
@@ -5735,17 +5780,17 @@ var LegacyArgTypes = (props) => {
|
|
|
5735
5780
|
}, ArgTypesImpl = (props) => globalThis.FEATURES?.experimentalDocgenServer ? React37.createElement(DocgenServiceArgTypes, { ...props }) : React37.createElement(LegacyArgTypes, { ...props }), ArgTypes = withMdxComponentOverride("ArgTypes", ArgTypesImpl);
|
|
5736
5781
|
|
|
5737
5782
|
// src/blocks/blocks/Canvas.tsx
|
|
5738
|
-
import React40, { useCallback as
|
|
5783
|
+
import React40, { useCallback as useCallback10, useContext as useContext6 } from "react";
|
|
5739
5784
|
import { FORCE_REMOUNT } from "storybook/internal/core-events";
|
|
5740
5785
|
import { InvalidBlockOfPropError as InvalidBlockOfPropError4 } from "storybook/internal/preview-errors";
|
|
5741
5786
|
|
|
5742
5787
|
// src/blocks/blocks/Source.tsx
|
|
5743
|
-
import React39, { useContext as useContext5, useMemo as
|
|
5788
|
+
import React39, { useContext as useContext5, useMemo as useMemo4 } from "react";
|
|
5744
5789
|
import { SourceType } from "storybook/internal/docs-tools";
|
|
5745
5790
|
import { InvalidBlockOfPropError as InvalidBlockOfPropError3 } from "storybook/internal/preview-errors";
|
|
5746
5791
|
|
|
5747
5792
|
// src/blocks/blocks/SourceContainer.tsx
|
|
5748
|
-
import React38, { createContext as createContext3, useEffect as
|
|
5793
|
+
import React38, { createContext as createContext3, useEffect as useEffect13, useState as useState16 } from "react";
|
|
5749
5794
|
import { SNIPPET_RENDERED } from "storybook/internal/docs-tools";
|
|
5750
5795
|
|
|
5751
5796
|
// ../../../node_modules/telejson/dist/chunk-EAFQLD22.mjs
|
|
@@ -6776,8 +6821,8 @@ var SourceContext = createContext3({ sources: {} }), UNKNOWN_ARGS_HASH = "--unkn
|
|
|
6776
6821
|
children,
|
|
6777
6822
|
channel
|
|
6778
6823
|
}) => {
|
|
6779
|
-
let [sources, setSources] =
|
|
6780
|
-
return
|
|
6824
|
+
let [sources, setSources] = useState16({});
|
|
6825
|
+
return useEffect13(() => {
|
|
6781
6826
|
let handleSnippetRendered = (idOrEvent, inputSource = null, inputFormat = !1) => {
|
|
6782
6827
|
let {
|
|
6783
6828
|
id,
|
|
@@ -6801,11 +6846,34 @@ var SourceContext = createContext3({ sources: {} }), UNKNOWN_ARGS_HASH = "--unkn
|
|
|
6801
6846
|
}, []), React38.createElement(SourceContext.Provider, { value: { sources } }, children);
|
|
6802
6847
|
};
|
|
6803
6848
|
|
|
6849
|
+
// src/blocks/blocks/use-service-story-docs.ts
|
|
6850
|
+
import { useCallback as useCallback9 } from "react";
|
|
6851
|
+
import { selectSnippetForStory, selectStoryDoc } from "storybook/open-service";
|
|
6852
|
+
import { getService as getService2 } from "storybook/preview-api";
|
|
6853
|
+
function useServiceStory(storyId, selector) {
|
|
6854
|
+
let componentId = storyId.split("--")[0], service = getService2("core/story-docs"), boundSelector = useCallback9(
|
|
6855
|
+
(payload) => selector(payload, storyId),
|
|
6856
|
+
[selector, storyId]
|
|
6857
|
+
);
|
|
6858
|
+
return useQuerySubscription(
|
|
6859
|
+
storyId,
|
|
6860
|
+
service.queries.storyDocs,
|
|
6861
|
+
{ id: componentId },
|
|
6862
|
+
boundSelector
|
|
6863
|
+
);
|
|
6864
|
+
}
|
|
6865
|
+
function useServiceStoryDoc(storyId) {
|
|
6866
|
+
return useServiceStory(storyId, selectStoryDoc);
|
|
6867
|
+
}
|
|
6868
|
+
function useServiceStorySnippet(storyId) {
|
|
6869
|
+
return useServiceStory(storyId, selectSnippetForStory);
|
|
6870
|
+
}
|
|
6871
|
+
|
|
6804
6872
|
// src/blocks/blocks/useTransformCode.tsx
|
|
6805
|
-
import { useEffect as
|
|
6873
|
+
import { useEffect as useEffect14, useState as useState17 } from "react";
|
|
6806
6874
|
function useTransformCode(source, transform, storyContext) {
|
|
6807
|
-
let [transformedCode, setTransformedCode] =
|
|
6808
|
-
return
|
|
6875
|
+
let [transformedCode, setTransformedCode] = useState17("Transforming..."), transformed = transform ? transform?.(source, storyContext) : source;
|
|
6876
|
+
return useEffect14(() => {
|
|
6809
6877
|
async function getTransformedCode() {
|
|
6810
6878
|
let transformResult = await transformed;
|
|
6811
6879
|
transformResult !== transformedCode && setTransformedCode(transformResult);
|
|
@@ -6820,15 +6888,16 @@ var EMPTY_SOURCE_CONTEXT = { sources: {} }, getStorySource = (storyId, args, sou
|
|
|
6820
6888
|
return sourceMap?.[argsHash(args)] || sourceMap?.[UNKNOWN_ARGS_HASH] || { code: "" };
|
|
6821
6889
|
}, useCode = ({
|
|
6822
6890
|
snippet,
|
|
6891
|
+
serviceSnippet,
|
|
6823
6892
|
storyContext,
|
|
6824
6893
|
typeFromProps,
|
|
6825
6894
|
transformFromProps
|
|
6826
6895
|
}) => {
|
|
6827
|
-
let parameters = storyContext.parameters ?? {}, { __isArgsStory: isArgsStory } = parameters, sourceParameters = parameters.docs?.source || {}, type = typeFromProps || sourceParameters.type || SourceType.AUTO, code = /* if user has explicitly set this as dynamic, use snippet */ type === SourceType.DYNAMIC || // if this is an args story and there's a snippet
|
|
6828
|
-
type === SourceType.AUTO &&
|
|
6896
|
+
let parameters = storyContext.parameters ?? {}, { __isArgsStory: isArgsStory } = parameters, sourceParameters = parameters.docs?.source || {}, type = typeFromProps || sourceParameters.type || SourceType.AUTO, staticSnippet = serviceSnippet || snippet, code = /* if user has explicitly set this as dynamic, use snippet */ type === SourceType.DYNAMIC || // if this is an args story and there's a snippet
|
|
6897
|
+
type === SourceType.AUTO && staticSnippet && isArgsStory ? staticSnippet : sourceParameters.originalSource || "", transformer = transformFromProps ?? sourceParameters.transform, transformedCode = transformer ? useTransformCode(code, transformer, storyContext) : code;
|
|
6829
6898
|
return sourceParameters.code !== void 0 ? sourceParameters.code : transformedCode;
|
|
6830
|
-
}, useSourceProps = (props, docsContext, sourceContext) => {
|
|
6831
|
-
let { of } = props, story =
|
|
6899
|
+
}, useSourceProps = (props, docsContext, sourceContext, serviceSnippet = "") => {
|
|
6900
|
+
let { of } = props, story = useMemo4(() => {
|
|
6832
6901
|
if (of)
|
|
6833
6902
|
return docsContext.resolveOf(of, ["story"]).story;
|
|
6834
6903
|
try {
|
|
@@ -6837,6 +6906,7 @@ var EMPTY_SOURCE_CONTEXT = { sources: {} }, getStorySource = (storyId, args, sou
|
|
|
6837
6906
|
}
|
|
6838
6907
|
}, [docsContext, of]), storyContext = story ? docsContext.getStoryContext(story) : {}, argsForSource = props.__forceInitialArgs ? storyContext.initialArgs : storyContext.unmappedArgs, source = story ? getStorySource(story.id, argsForSource, sourceContext) : null, transformedCode = useCode({
|
|
6839
6908
|
snippet: source ? source.code : "",
|
|
6909
|
+
serviceSnippet,
|
|
6840
6910
|
storyContext: { ...storyContext, args: argsForSource },
|
|
6841
6911
|
typeFromProps: props.type,
|
|
6842
6912
|
transformFromProps: props.transform
|
|
@@ -6855,8 +6925,29 @@ var EMPTY_SOURCE_CONTEXT = { sources: {} }, getStorySource = (storyId, args, sou
|
|
|
6855
6925
|
language,
|
|
6856
6926
|
dark
|
|
6857
6927
|
});
|
|
6928
|
+
}, SourceWithStoryDocsSnippet = ({ storyId, docsContext, sourceContext, ...props }) => {
|
|
6929
|
+
let serviceSnippet = useServiceStorySnippet(storyId).data ?? "", sourceProps = useSourceProps(props, docsContext, sourceContext, serviceSnippet);
|
|
6930
|
+
return React39.createElement(Source, { ...sourceProps });
|
|
6858
6931
|
}, SourceWithStorySnippet = (props) => {
|
|
6859
|
-
let sourceContext = useContext5(SourceContext), docsContext = useContext5(DocsContext),
|
|
6932
|
+
let { of } = props, sourceContext = useContext5(SourceContext), docsContext = useContext5(DocsContext), story = useMemo4(() => {
|
|
6933
|
+
if (of)
|
|
6934
|
+
return docsContext.resolveOf(of, ["story"]).story;
|
|
6935
|
+
try {
|
|
6936
|
+
return docsContext.storyById();
|
|
6937
|
+
} catch {
|
|
6938
|
+
}
|
|
6939
|
+
}, [docsContext, of]);
|
|
6940
|
+
if (globalThis.FEATURES?.experimentalDocgenServer && story?.id)
|
|
6941
|
+
return React39.createElement(
|
|
6942
|
+
SourceWithStoryDocsSnippet,
|
|
6943
|
+
{
|
|
6944
|
+
...props,
|
|
6945
|
+
docsContext,
|
|
6946
|
+
sourceContext,
|
|
6947
|
+
storyId: story.id
|
|
6948
|
+
}
|
|
6949
|
+
);
|
|
6950
|
+
let sourceProps = useSourceProps(props, docsContext, sourceContext);
|
|
6860
6951
|
return React39.createElement(Source, { ...sourceProps });
|
|
6861
6952
|
}, SourceWithCode = (props) => {
|
|
6862
6953
|
let docsContext = useContext5(DocsContext), sourceProps = useSourceProps(props, docsContext, EMPTY_SOURCE_CONTEXT);
|
|
@@ -6868,7 +6959,7 @@ var CanvasImpl = (props) => {
|
|
|
6868
6959
|
let docsContext = useContext6(DocsContext), sourceContext = useContext6(SourceContext), { of, source } = props;
|
|
6869
6960
|
if ("of" in props && of === void 0)
|
|
6870
6961
|
throw new InvalidBlockOfPropError4();
|
|
6871
|
-
let { story } = useOf(of || "story", ["story"]), sourceProps = useSourceProps({ ...source, ...of && { of } }, docsContext, sourceContext), layout = props.layout ?? story.parameters.layout ?? story.parameters.docs?.canvas?.layout ?? "padded", withToolbar = props.withToolbar ?? story.parameters.docs?.canvas?.withToolbar ?? !1, additionalActions = props.additionalActions ?? story.parameters.docs?.canvas?.additionalActions, sourceState = props.sourceState ?? story.parameters.docs?.canvas?.sourceState ?? "hidden", className = props.className ?? story.parameters.docs?.canvas?.className, inline = props.story?.inline ?? story.parameters?.docs?.story?.inline ?? !1, handleReloadStory =
|
|
6962
|
+
let { story } = useOf(of || "story", ["story"]), sourceProps = useSourceProps({ ...source, ...of && { of } }, docsContext, sourceContext), layout = props.layout ?? story.parameters.layout ?? story.parameters.docs?.canvas?.layout ?? "padded", withToolbar = props.withToolbar ?? story.parameters.docs?.canvas?.withToolbar ?? !1, additionalActions = props.additionalActions ?? story.parameters.docs?.canvas?.additionalActions, sourceState = props.sourceState ?? story.parameters.docs?.canvas?.sourceState ?? "hidden", className = props.className ?? story.parameters.docs?.canvas?.className, inline = props.story?.inline ?? story.parameters?.docs?.story?.inline ?? !1, handleReloadStory = useCallback10(() => {
|
|
6872
6963
|
docsContext.channel.emit(FORCE_REMOUNT, { storyId: story.id });
|
|
6873
6964
|
}, [docsContext.channel, story.id]);
|
|
6874
6965
|
return React40.createElement(
|
|
@@ -6892,7 +6983,7 @@ import React41, { useContext as useContext8 } from "react";
|
|
|
6892
6983
|
import { filterArgTypes as filterArgTypes2 } from "storybook/preview-api";
|
|
6893
6984
|
|
|
6894
6985
|
// src/blocks/blocks/useArgs.ts
|
|
6895
|
-
import { useCallback as
|
|
6986
|
+
import { useCallback as useCallback11, useEffect as useEffect15, useState as useState18 } from "react";
|
|
6896
6987
|
import {
|
|
6897
6988
|
RESET_STORY_ARGS,
|
|
6898
6989
|
STORY_ARGS_UPDATED,
|
|
@@ -6904,17 +6995,17 @@ var useArgs = (story, context) => {
|
|
|
6904
6995
|
throw new Error("No result when story was defined");
|
|
6905
6996
|
return result;
|
|
6906
6997
|
}, useArgsIfDefined = (story, context) => {
|
|
6907
|
-
let storyContext = story ? context.getStoryContext(story) : { args: {} }, { id: storyId } = story || { id: "none" }, [args, setArgs] =
|
|
6908
|
-
|
|
6998
|
+
let storyContext = story ? context.getStoryContext(story) : { args: {} }, { id: storyId } = story || { id: "none" }, [args, setArgs] = useState18(storyContext.args);
|
|
6999
|
+
useEffect15(() => {
|
|
6909
7000
|
let onArgsUpdated = (changed) => {
|
|
6910
7001
|
changed.storyId === storyId && setArgs(changed.args);
|
|
6911
7002
|
};
|
|
6912
7003
|
return context.channel.on(STORY_ARGS_UPDATED, onArgsUpdated), () => context.channel.off(STORY_ARGS_UPDATED, onArgsUpdated);
|
|
6913
7004
|
}, [storyId, context.channel]);
|
|
6914
|
-
let updateArgs =
|
|
7005
|
+
let updateArgs = useCallback11(
|
|
6915
7006
|
(updatedArgs) => context.channel.emit(UPDATE_STORY_ARGS, { storyId, updatedArgs }),
|
|
6916
7007
|
[storyId, context.channel]
|
|
6917
|
-
), resetArgs =
|
|
7008
|
+
), resetArgs = useCallback11(
|
|
6918
7009
|
(argNames) => context.channel.emit(RESET_STORY_ARGS, { storyId, argNames }),
|
|
6919
7010
|
[storyId, context.channel]
|
|
6920
7011
|
);
|
|
@@ -6922,11 +7013,11 @@ var useArgs = (story, context) => {
|
|
|
6922
7013
|
};
|
|
6923
7014
|
|
|
6924
7015
|
// src/blocks/blocks/useGlobals.ts
|
|
6925
|
-
import { useEffect as
|
|
7016
|
+
import { useEffect as useEffect16, useState as useState19 } from "react";
|
|
6926
7017
|
import { GLOBALS_UPDATED } from "storybook/internal/core-events";
|
|
6927
7018
|
var useGlobals = (story, context) => {
|
|
6928
|
-
let storyContext = context.getStoryContext(story), [globals, setGlobals] =
|
|
6929
|
-
return
|
|
7019
|
+
let storyContext = context.getStoryContext(story), [globals, setGlobals] = useState19(storyContext.globals);
|
|
7020
|
+
return useEffect16(() => {
|
|
6930
7021
|
let onGlobalsUpdated = (changed) => {
|
|
6931
7022
|
setGlobals(changed.globals);
|
|
6932
7023
|
};
|
|
@@ -7023,14 +7114,14 @@ var ControlsTables = ({
|
|
|
7023
7114
|
}
|
|
7024
7115
|
) : null;
|
|
7025
7116
|
}, DocgenServiceControls = ({ story, context, ...props }) => {
|
|
7026
|
-
let { parameters, argTypes, component } = story, filterProps = getControlsFilterProps(story, props), interactiveState = useControlsInteractiveState(story, context), serviceRows = useDocgenServiceRows({
|
|
7117
|
+
let { parameters, argTypes, component } = story, filterProps = getControlsFilterProps(story, props), interactiveState = useControlsInteractiveState(story, context), { rows: serviceRows, isInitialLoading } = useDocgenServiceRows({
|
|
7027
7118
|
componentId: story.id.split("--")[0],
|
|
7028
7119
|
storyId: story.id,
|
|
7029
7120
|
parameters,
|
|
7030
7121
|
initialArgs: story.initialArgs,
|
|
7031
7122
|
customArgTypes: argTypes
|
|
7032
7123
|
});
|
|
7033
|
-
return serviceRows ? React41.createElement(
|
|
7124
|
+
return isInitialLoading ? React41.createElement(ArgsTable, { isLoading: !0 }) : serviceRows ? React41.createElement(
|
|
7034
7125
|
ControlsTables,
|
|
7035
7126
|
{
|
|
7036
7127
|
mainName: getComponentName(component) ?? serviceRows.serviceComponentName,
|
|
@@ -7243,10 +7334,12 @@ var MarkdownImpl = (props) => {
|
|
|
7243
7334
|
}, Markdown = withMdxComponentOverride("Markdown", MarkdownImpl);
|
|
7244
7335
|
|
|
7245
7336
|
// src/blocks/blocks/Description.tsx
|
|
7246
|
-
var DescriptionType = /* @__PURE__ */ ((DescriptionType2) => (DescriptionType2.INFO = "info", DescriptionType2.NOTES = "notes", DescriptionType2.DOCGEN = "docgen", DescriptionType2.AUTO = "auto", DescriptionType2))(DescriptionType || {}), getDescriptionFromResolvedOf = (resolvedOf, serviceComponentDescription) => {
|
|
7337
|
+
var DescriptionType = /* @__PURE__ */ ((DescriptionType2) => (DescriptionType2.INFO = "info", DescriptionType2.NOTES = "notes", DescriptionType2.DOCGEN = "docgen", DescriptionType2.AUTO = "auto", DescriptionType2))(DescriptionType || {}), getDescriptionFromResolvedOf = (resolvedOf, serviceComponentDescription, storyDocsDescription) => {
|
|
7247
7338
|
switch (resolvedOf.type) {
|
|
7248
|
-
case "story":
|
|
7249
|
-
|
|
7339
|
+
case "story": {
|
|
7340
|
+
let storyDescription = resolvedOf.story.parameters.docs?.description?.story;
|
|
7341
|
+
return storyDescription !== void 0 ? storyDescription : storyDocsDescription ?? null;
|
|
7342
|
+
}
|
|
7250
7343
|
case "meta": {
|
|
7251
7344
|
let { parameters, component } = resolvedOf.preparedMeta, metaDescription = parameters.docs?.description?.component;
|
|
7252
7345
|
return metaDescription || parameters.docs?.extractComponentDescription?.(component, {
|
|
@@ -7269,22 +7362,47 @@ var DescriptionType = /* @__PURE__ */ ((DescriptionType2) => (DescriptionType2.I
|
|
|
7269
7362
|
`Unrecognized module type resolved from 'useOf', got: ${resolvedOf.type}`
|
|
7270
7363
|
);
|
|
7271
7364
|
}
|
|
7272
|
-
},
|
|
7273
|
-
let
|
|
7274
|
-
|
|
7365
|
+
}, DescriptionBody = ({ resolvedOf, serviceComponentDescription, storyDocsDescription }) => {
|
|
7366
|
+
let markdown = getDescriptionFromResolvedOf(
|
|
7367
|
+
resolvedOf,
|
|
7368
|
+
serviceComponentDescription,
|
|
7369
|
+
storyDocsDescription
|
|
7370
|
+
);
|
|
7371
|
+
return markdown ? React44.createElement(Markdown, null, markdown) : null;
|
|
7372
|
+
}, DescriptionStoryWithServices = ({
|
|
7373
|
+
resolvedOf
|
|
7374
|
+
}) => {
|
|
7375
|
+
let storyDocsDescription = useServiceStoryDoc(resolvedOf.story.id).data?.description;
|
|
7376
|
+
return React44.createElement(DescriptionBody, { resolvedOf, storyDocsDescription });
|
|
7377
|
+
}, DescriptionComponentWithServices = ({ resolvedOf, componentId }) => {
|
|
7378
|
+
let serviceComponentDescription = useServiceDocgen(componentId).data?.description || void 0;
|
|
7379
|
+
return React44.createElement(
|
|
7380
|
+
DescriptionBody,
|
|
7381
|
+
{
|
|
7382
|
+
resolvedOf,
|
|
7383
|
+
serviceComponentDescription
|
|
7384
|
+
}
|
|
7385
|
+
);
|
|
7275
7386
|
}, DescriptionImpl = (props) => {
|
|
7276
7387
|
let { of } = props;
|
|
7277
7388
|
if ("of" in props && of === void 0)
|
|
7278
7389
|
throw new InvalidBlockOfPropError5();
|
|
7279
|
-
let resolvedOf = useOf(of || "meta"),
|
|
7280
|
-
|
|
7390
|
+
let resolvedOf = useOf(of || "meta"), context = useContext10(DocsContext);
|
|
7391
|
+
if (globalThis.FEATURES?.experimentalDocgenServer) {
|
|
7392
|
+
if (resolvedOf.type === "story")
|
|
7393
|
+
return React44.createElement(DescriptionStoryWithServices, { resolvedOf });
|
|
7394
|
+
let componentId = resolvedOf.type === "meta" ? resolvedOf.preparedMeta.componentId : context.getComponentId(resolvedOf.component);
|
|
7395
|
+
if (componentId)
|
|
7396
|
+
return React44.createElement(DescriptionComponentWithServices, { resolvedOf, componentId });
|
|
7397
|
+
}
|
|
7398
|
+
return React44.createElement(DescriptionBody, { resolvedOf });
|
|
7281
7399
|
}, Description2 = withMdxComponentOverride("Description", DescriptionImpl);
|
|
7282
7400
|
|
|
7283
7401
|
// src/blocks/blocks/Docs.tsx
|
|
7284
7402
|
import React54 from "react";
|
|
7285
7403
|
|
|
7286
7404
|
// src/blocks/blocks/DocsContainer.tsx
|
|
7287
|
-
import React45, { useEffect as
|
|
7405
|
+
import React45, { useEffect as useEffect17, useMemo as useMemo5 } from "react";
|
|
7288
7406
|
import { ThemeProvider, ensure as ensureTheme } from "storybook/theming";
|
|
7289
7407
|
|
|
7290
7408
|
// src/blocks/blocks/DocsSluggerContext.ts
|
|
@@ -7345,13 +7463,13 @@ var { document: document3, window: globalWindow3 } = globalThis, DocsContainer =
|
|
|
7345
7463
|
theme,
|
|
7346
7464
|
children
|
|
7347
7465
|
}) => {
|
|
7348
|
-
let slugger =
|
|
7466
|
+
let slugger = useMemo5(() => createDocsSlugger(), []), toc;
|
|
7349
7467
|
try {
|
|
7350
7468
|
toc = context.resolveOf("meta", ["meta"]).preparedMeta.parameters?.docs?.toc;
|
|
7351
7469
|
} catch {
|
|
7352
7470
|
toc = context?.projectAnnotations?.parameters?.docs?.toc;
|
|
7353
7471
|
}
|
|
7354
|
-
return
|
|
7472
|
+
return useEffect17(() => {
|
|
7355
7473
|
let url;
|
|
7356
7474
|
try {
|
|
7357
7475
|
if (url = new URL(globalWindow3.parent.location.toString()), url.hash) {
|
|
@@ -7457,7 +7575,7 @@ var StyledHeading = styled29(Heading2)(({ theme }) => ({
|
|
|
7457
7575
|
marginTop: "56px"
|
|
7458
7576
|
}
|
|
7459
7577
|
})), StoriesImpl = ({ title = "Stories", includePrimary = !0 }) => {
|
|
7460
|
-
let { componentStories, projectAnnotations, getStoryContext } = useContext11(DocsContext), stories = componentStories(),
|
|
7578
|
+
let { componentStories, projectAnnotations, getStoryContext } = useContext11(DocsContext), stories = componentStories(), filter = projectAnnotations.parameters?.docs?.stories?.filter;
|
|
7461
7579
|
return filter && (stories = stories.filter((story) => filter(story, getStoryContext(story)))), stories.some((story) => story.tags?.includes(Tag2.AUTODOCS)) && (stories = stories.filter((story) => story.tags?.includes(Tag2.AUTODOCS) && !story.usesMount)), includePrimary || (stories = stories.slice(1)), !stories || stories.length === 0 ? null : React50.createElement(React50.Fragment, null, typeof title == "string" ? React50.createElement(StyledHeading, null, title) : title, stories.map(
|
|
7462
7580
|
(story) => story && React50.createElement(DocsStory, { key: story.id, of: story.moduleExport, expanded: !0, __forceInitialArgs: !0 })
|
|
7463
7581
|
));
|
|
@@ -7523,7 +7641,7 @@ function Docs({
|
|
|
7523
7641
|
}
|
|
7524
7642
|
|
|
7525
7643
|
// src/blocks/blocks/external/ExternalDocs.tsx
|
|
7526
|
-
import React55, { useRef as
|
|
7644
|
+
import React55, { useRef as useRef8 } from "react";
|
|
7527
7645
|
import { deprecate as deprecate2 } from "storybook/internal/client-logger";
|
|
7528
7646
|
import { composeConfigs as composeConfigs2 } from "storybook/preview-api";
|
|
7529
7647
|
|
|
@@ -7606,7 +7724,7 @@ var ConstantMap = class {
|
|
|
7606
7724
|
|
|
7607
7725
|
// src/blocks/blocks/external/ExternalDocs.tsx
|
|
7608
7726
|
function usePreview(projectAnnotations) {
|
|
7609
|
-
let previewRef =
|
|
7727
|
+
let previewRef = useRef8();
|
|
7610
7728
|
return previewRef.current || (previewRef.current = new ExternalPreview(projectAnnotations)), previewRef.current;
|
|
7611
7729
|
}
|
|
7612
7730
|
function ExternalDocs({
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as storybook_internal_csf from 'storybook/internal/csf';
|
|
2
2
|
import React$1, { ReactElement, ComponentType } from 'react';
|
|
3
|
-
import { Renderer, DocsContextProps, ModuleExport, ModuleExports, DocsRenderFunction } from 'storybook/internal/types';
|
|
3
|
+
import { Renderer, DocsContextProps, ModuleExport, ModuleExports, Args, PreparedStory, DocsRenderFunction } from 'storybook/internal/types';
|
|
4
4
|
import { ThemeVars } from 'storybook/theming';
|
|
5
5
|
|
|
6
6
|
interface TocbotOptions {
|
|
@@ -65,6 +65,12 @@ type StoryBlockParameters = {
|
|
|
65
65
|
*/
|
|
66
66
|
of: ModuleExport;
|
|
67
67
|
};
|
|
68
|
+
type StoriesBlockParameters = {
|
|
69
|
+
/**
|
|
70
|
+
* Custom filter function for determining which stories to include in a <Stories> block
|
|
71
|
+
*/
|
|
72
|
+
filter?: <TRenderer extends Renderer = Renderer, TArgs = Args>(Story: PreparedStory<TRenderer>, Context: ReturnType<DocsContextProps['getStoryContext']>) => boolean;
|
|
73
|
+
};
|
|
68
74
|
type ControlsBlockParameters = {
|
|
69
75
|
/** Exclude specific properties from the Controls panel */
|
|
70
76
|
exclude?: string[] | RegExp;
|
|
@@ -218,11 +224,17 @@ interface DocsParameters {
|
|
|
218
224
|
*/
|
|
219
225
|
source?: Partial<SourceBlockParameters>;
|
|
220
226
|
/**
|
|
221
|
-
* Story configuration
|
|
227
|
+
* Story block configuration
|
|
222
228
|
*
|
|
223
229
|
* @see https://storybook.js.org/docs/api/doc-blocks/doc-block-story
|
|
224
230
|
*/
|
|
225
231
|
story?: Partial<StoryBlockParameters>;
|
|
232
|
+
/**
|
|
233
|
+
* Stories block configuration
|
|
234
|
+
*
|
|
235
|
+
* @see https://storybook.js.org/docs/api/doc-blocks/doc-block-stories
|
|
236
|
+
*/
|
|
237
|
+
stories?: Partial<StoriesBlockParameters>;
|
|
226
238
|
/**
|
|
227
239
|
* The subtitle displayed when shown in docs page
|
|
228
240
|
*
|