@storybook/addon-docs 7.0.0-alpha.5 → 7.0.0-alpha.51
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 +14 -77
- package/angular/index.js +1 -1
- package/dist/DocsRenderer-MHI45CTG.mjs +1 -0
- package/dist/chunk-HKSD7XQF.mjs +1 -0
- package/dist/chunk-WMY67HY3.mjs +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/preset.d.ts +5 -0
- package/dist/preset.js +7 -0
- package/dist/preset.mjs +7 -0
- package/dist/preview.d.ts +3 -0
- package/dist/preview.js +1 -0
- package/dist/preview.mjs +1 -0
- package/jest-transform-mdx.js +4 -3
- package/jest.config.js +7 -0
- package/package.json +65 -38
- package/preset.js +1 -1
- package/preview.js +1 -1
- package/web-components/README.md +1 -0
- package/LICENSE +0 -21
- package/blocks.d.ts +0 -2
- package/blocks.js +0 -14
- package/dist/cjs/blocks/Anchor.js +0 -23
- package/dist/cjs/blocks/ArgsTable.js +0 -329
- package/dist/cjs/blocks/Canvas.js +0 -109
- package/dist/cjs/blocks/Description.js +0 -126
- package/dist/cjs/blocks/DocsContainer.js +0 -127
- package/dist/cjs/blocks/DocsContext.js +0 -25
- package/dist/cjs/blocks/DocsPage.js +0 -30
- package/dist/cjs/blocks/DocsStory.js +0 -68
- package/dist/cjs/blocks/Heading.js +0 -31
- package/dist/cjs/blocks/Meta.js +0 -50
- package/dist/cjs/blocks/Preview.js +0 -23
- package/dist/cjs/blocks/Primary.js +0 -39
- package/dist/cjs/blocks/Props.js +0 -29
- package/dist/cjs/blocks/Source.js +0 -179
- package/dist/cjs/blocks/SourceContainer.js +0 -67
- package/dist/cjs/blocks/Stories.js +0 -51
- package/dist/cjs/blocks/Story.js +0 -143
- package/dist/cjs/blocks/Subheading.js +0 -31
- package/dist/cjs/blocks/Subtitle.js +0 -39
- package/dist/cjs/blocks/Title.js +0 -44
- package/dist/cjs/blocks/Wrapper.js +0 -20
- package/dist/cjs/blocks/enhanceSource.js +0 -92
- package/dist/cjs/blocks/index.js +0 -366
- package/dist/cjs/blocks/mdx.js +0 -234
- package/dist/cjs/blocks/types.js +0 -10
- package/dist/cjs/blocks/useStory.js +0 -37
- package/dist/cjs/blocks/utils.js +0 -40
- package/dist/cjs/index.js +0 -18
- package/dist/cjs/manager.js +0 -20
- package/dist/cjs/preset.js +0 -162
- package/dist/cjs/preview.js +0 -18
- package/dist/cjs/shared.js +0 -22
- package/dist/esm/blocks/Anchor.js +0 -8
- package/dist/esm/blocks/ArgsTable.js +0 -292
- package/dist/esm/blocks/Canvas.js +0 -83
- package/dist/esm/blocks/Description.js +0 -107
- package/dist/esm/blocks/DocsContainer.js +0 -98
- package/dist/esm/blocks/DocsContext.js +0 -16
- package/dist/esm/blocks/DocsPage.js +0 -11
- package/dist/esm/blocks/DocsStory.js +0 -46
- package/dist/esm/blocks/Heading.js +0 -17
- package/dist/esm/blocks/Meta.js +0 -31
- package/dist/esm/blocks/Preview.js +0 -9
- package/dist/esm/blocks/Primary.js +0 -23
- package/dist/esm/blocks/Props.js +0 -14
- package/dist/esm/blocks/Source.js +0 -144
- package/dist/esm/blocks/SourceContainer.js +0 -44
- package/dist/esm/blocks/Stories.js +0 -30
- package/dist/esm/blocks/Story.js +0 -114
- package/dist/esm/blocks/Subheading.js +0 -17
- package/dist/esm/blocks/Subtitle.js +0 -23
- package/dist/esm/blocks/Title.js +0 -24
- package/dist/esm/blocks/Wrapper.js +0 -8
- package/dist/esm/blocks/enhanceSource.js +0 -87
- package/dist/esm/blocks/index.js +0 -24
- package/dist/esm/blocks/mdx.js +0 -203
- package/dist/esm/blocks/types.js +0 -2
- package/dist/esm/blocks/useStory.js +0 -27
- package/dist/esm/blocks/utils.js +0 -29
- package/dist/esm/index.js +0 -1
- package/dist/esm/manager.js +0 -16
- package/dist/esm/preset.js +0 -132
- package/dist/esm/preview.js +0 -6
- package/dist/esm/shared.js +0 -11
- package/dist/types/blocks/Anchor.d.ts +0 -6
- package/dist/types/blocks/ArgsTable.d.ts +0 -33
- package/dist/types/blocks/Canvas.d.ts +0 -9
- package/dist/types/blocks/Description.d.ts +0 -20
- package/dist/types/blocks/DocsContainer.d.ts +0 -7
- package/dist/types/blocks/DocsContext.d.ts +0 -5
- package/dist/types/blocks/DocsPage.d.ts +0 -2
- package/dist/types/blocks/DocsStory.d.ts +0 -3
- package/dist/types/blocks/Heading.d.ts +0 -6
- package/dist/types/blocks/Meta.d.ts +0 -9
- package/dist/types/blocks/Preview.d.ts +0 -3
- package/dist/types/blocks/Primary.d.ts +0 -6
- package/dist/types/blocks/Props.d.ts +0 -3
- package/dist/types/blocks/Source.d.ts +0 -38
- package/dist/types/blocks/SourceContainer.d.ts +0 -14
- package/dist/types/blocks/Stories.d.ts +0 -7
- package/dist/types/blocks/Story.d.ts +0 -28
- package/dist/types/blocks/Subheading.d.ts +0 -3
- package/dist/types/blocks/Subtitle.d.ts +0 -6
- package/dist/types/blocks/Title.d.ts +0 -8
- package/dist/types/blocks/Wrapper.d.ts +0 -2
- package/dist/types/blocks/enhanceSource.d.ts +0 -3
- package/dist/types/blocks/index.d.ts +0 -24
- package/dist/types/blocks/mdx.d.ts +0 -20
- package/dist/types/blocks/types.d.ts +0 -13
- package/dist/types/blocks/useStory.d.ts +0 -5
- package/dist/types/blocks/utils.d.ts +0 -3
- package/dist/types/index.d.ts +0 -1
- package/dist/types/manager.d.ts +0 -1
- package/dist/types/preset.d.ts +0 -12
- package/dist/types/preview.d.ts +0 -6
- package/dist/types/shared.d.ts +0 -24
- package/manager.js +0 -1
- package/mdx-compiler-plugin.js +0 -1
- package/register.js +0 -6
package/dist/esm/blocks/Story.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import React, { useContext, useRef, useEffect, useState } from 'react';
|
|
2
|
-
import { MDXProvider } from '@mdx-js/react';
|
|
3
|
-
import { resetComponents, Story as PureStory, StorySkeleton } from '@storybook/components';
|
|
4
|
-
import { toId, storyNameFromExport } from '@storybook/csf';
|
|
5
|
-
import { CURRENT_SELECTION } from './types';
|
|
6
|
-
import { DocsContext } from './DocsContext';
|
|
7
|
-
import { useStory } from './useStory';
|
|
8
|
-
export const storyBlockIdFromId = storyId => `story--${storyId}`;
|
|
9
|
-
export const lookupStoryId = (storyName, {
|
|
10
|
-
mdxStoryNameToKey,
|
|
11
|
-
mdxComponentAnnotations
|
|
12
|
-
}) => toId(mdxComponentAnnotations.id || mdxComponentAnnotations.title, storyNameFromExport(mdxStoryNameToKey[storyName]));
|
|
13
|
-
export const getStoryId = (props, context) => {
|
|
14
|
-
const {
|
|
15
|
-
id
|
|
16
|
-
} = props;
|
|
17
|
-
const {
|
|
18
|
-
name
|
|
19
|
-
} = props;
|
|
20
|
-
const inputId = id === CURRENT_SELECTION ? context.id : id;
|
|
21
|
-
return inputId || lookupStoryId(name, context);
|
|
22
|
-
};
|
|
23
|
-
export const getStoryProps = ({
|
|
24
|
-
height,
|
|
25
|
-
inline
|
|
26
|
-
}, story) => {
|
|
27
|
-
const {
|
|
28
|
-
name: storyName,
|
|
29
|
-
parameters
|
|
30
|
-
} = story;
|
|
31
|
-
const {
|
|
32
|
-
docs = {}
|
|
33
|
-
} = parameters;
|
|
34
|
-
|
|
35
|
-
if (docs.disable) {
|
|
36
|
-
return null;
|
|
37
|
-
} // prefer block props, then story parameters defined by the framework-specific settings and optionally overridden by users
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const {
|
|
41
|
-
inlineStories = false,
|
|
42
|
-
iframeHeight = 100
|
|
43
|
-
} = docs;
|
|
44
|
-
const storyIsInline = typeof inline === 'boolean' ? inline : inlineStories;
|
|
45
|
-
return Object.assign({
|
|
46
|
-
inline: storyIsInline,
|
|
47
|
-
id: story.id,
|
|
48
|
-
height: height || (storyIsInline ? undefined : iframeHeight),
|
|
49
|
-
title: storyName
|
|
50
|
-
}, storyIsInline && {
|
|
51
|
-
parameters
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const Story = props => {
|
|
56
|
-
const context = useContext(DocsContext);
|
|
57
|
-
const storyRef = useRef();
|
|
58
|
-
const storyId = getStoryId(props, context);
|
|
59
|
-
const story = useStory(storyId, context);
|
|
60
|
-
const [showLoader, setShowLoader] = useState(true);
|
|
61
|
-
useEffect(() => {
|
|
62
|
-
let cleanup;
|
|
63
|
-
|
|
64
|
-
if (story && storyRef.current) {
|
|
65
|
-
const element = storyRef.current;
|
|
66
|
-
cleanup = context.renderStoryToElement(story, element);
|
|
67
|
-
setShowLoader(false);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return () => cleanup && cleanup();
|
|
71
|
-
}, [story]);
|
|
72
|
-
|
|
73
|
-
if (!story) {
|
|
74
|
-
return /*#__PURE__*/React.createElement(StorySkeleton, null);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const storyProps = getStoryProps(props, story);
|
|
78
|
-
|
|
79
|
-
if (!storyProps) {
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (storyProps.inline) {
|
|
84
|
-
// We do this so React doesn't complain when we replace the span in a secondary render
|
|
85
|
-
const htmlContents = `<span></span>`; // FIXME: height/style/etc. lifted from PureStory
|
|
86
|
-
|
|
87
|
-
const {
|
|
88
|
-
height
|
|
89
|
-
} = storyProps;
|
|
90
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
91
|
-
id: storyBlockIdFromId(story.id)
|
|
92
|
-
}, /*#__PURE__*/React.createElement(MDXProvider, {
|
|
93
|
-
components: resetComponents
|
|
94
|
-
}, height ? /*#__PURE__*/React.createElement("style", null, `#story--${story.id} { min-height: ${height}; transform: translateZ(0); overflow: auto }`) : null, showLoader && /*#__PURE__*/React.createElement(StorySkeleton, null), /*#__PURE__*/React.createElement("div", {
|
|
95
|
-
ref: storyRef,
|
|
96
|
-
"data-name": story.name,
|
|
97
|
-
dangerouslySetInnerHTML: {
|
|
98
|
-
__html: htmlContents
|
|
99
|
-
}
|
|
100
|
-
})));
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
104
|
-
id: storyBlockIdFromId(story.id)
|
|
105
|
-
}, /*#__PURE__*/React.createElement(MDXProvider, {
|
|
106
|
-
components: resetComponents
|
|
107
|
-
}, /*#__PURE__*/React.createElement(PureStory, storyProps)));
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
Story.defaultProps = {
|
|
111
|
-
children: null,
|
|
112
|
-
name: null
|
|
113
|
-
};
|
|
114
|
-
export { Story };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { H3 } from '@storybook/components';
|
|
3
|
-
import { HeaderMdx } from './mdx';
|
|
4
|
-
export const Subheading = ({
|
|
5
|
-
children,
|
|
6
|
-
disableAnchor
|
|
7
|
-
}) => {
|
|
8
|
-
if (disableAnchor || typeof children !== 'string') {
|
|
9
|
-
return /*#__PURE__*/React.createElement(H3, null, children);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const tagID = children.toLowerCase().replace(/[^a-z0-9]/gi, '-');
|
|
13
|
-
return /*#__PURE__*/React.createElement(HeaderMdx, {
|
|
14
|
-
as: "h3",
|
|
15
|
-
id: tagID
|
|
16
|
-
}, children);
|
|
17
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import React, { useContext } from 'react';
|
|
2
|
-
import { Subtitle as PureSubtitle } from '@storybook/components';
|
|
3
|
-
import { DocsContext } from './DocsContext';
|
|
4
|
-
export const Subtitle = ({
|
|
5
|
-
children
|
|
6
|
-
}) => {
|
|
7
|
-
const {
|
|
8
|
-
id,
|
|
9
|
-
storyById
|
|
10
|
-
} = useContext(DocsContext);
|
|
11
|
-
const {
|
|
12
|
-
parameters
|
|
13
|
-
} = storyById(id);
|
|
14
|
-
let text = children;
|
|
15
|
-
|
|
16
|
-
if (!text) {
|
|
17
|
-
text = parameters?.componentSubtitle;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return text ? /*#__PURE__*/React.createElement(PureSubtitle, {
|
|
21
|
-
className: "sbdocs-subtitle"
|
|
22
|
-
}, text) : null;
|
|
23
|
-
};
|
package/dist/esm/blocks/Title.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import React, { useContext } from 'react';
|
|
2
|
-
import { Title as PureTitle } from '@storybook/components';
|
|
3
|
-
import { DocsContext } from './DocsContext';
|
|
4
|
-
const STORY_KIND_PATH_SEPARATOR = /\s*\/\s*/;
|
|
5
|
-
export const extractTitle = ({
|
|
6
|
-
title
|
|
7
|
-
}) => {
|
|
8
|
-
const groups = title.trim().split(STORY_KIND_PATH_SEPARATOR);
|
|
9
|
-
return groups && groups[groups.length - 1] || title;
|
|
10
|
-
};
|
|
11
|
-
export const Title = ({
|
|
12
|
-
children
|
|
13
|
-
}) => {
|
|
14
|
-
const context = useContext(DocsContext);
|
|
15
|
-
let text = children;
|
|
16
|
-
|
|
17
|
-
if (!text) {
|
|
18
|
-
text = extractTitle(context);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return text ? /*#__PURE__*/React.createElement(PureTitle, {
|
|
22
|
-
className: "sbdocs-title"
|
|
23
|
-
}, text) : null;
|
|
24
|
-
};
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { combineParameters } from '@storybook/store'; // ============================================================
|
|
2
|
-
// START @storybook/source-loader/extract-source
|
|
3
|
-
//
|
|
4
|
-
// This code duplicated because tree-shaking isn't working.
|
|
5
|
-
// It's not DRY, but source-loader is on the chopping block for
|
|
6
|
-
// the next version of addon-docs, so it's not the worst sin.
|
|
7
|
-
// ============================================================
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* given a location, extract the text from the full source
|
|
11
|
-
*/
|
|
12
|
-
function extractSource(location, lines) {
|
|
13
|
-
const {
|
|
14
|
-
startBody: start,
|
|
15
|
-
endBody: end
|
|
16
|
-
} = location;
|
|
17
|
-
|
|
18
|
-
if (start.line === end.line && lines[start.line - 1] !== undefined) {
|
|
19
|
-
return lines[start.line - 1].substring(start.col, end.col);
|
|
20
|
-
} // NOTE: storysource locations are 1-based not 0-based!
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const startLine = lines[start.line - 1];
|
|
24
|
-
const endLine = lines[end.line - 1];
|
|
25
|
-
|
|
26
|
-
if (startLine === undefined || endLine === undefined) {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return [startLine.substring(start.col), ...lines.slice(start.line, end.line - 1), endLine.substring(0, end.col)].join('\n');
|
|
31
|
-
} // ============================================================
|
|
32
|
-
// END @storybook/source-loader/extract-source
|
|
33
|
-
// ============================================================
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Replaces full story id name like: story-kind--story-name -> story-name
|
|
38
|
-
* @param id
|
|
39
|
-
*/
|
|
40
|
-
const storyIdToSanitizedStoryName = id => id.replace(/^.*?--/, '');
|
|
41
|
-
|
|
42
|
-
const extract = (targetId, {
|
|
43
|
-
source,
|
|
44
|
-
locationsMap
|
|
45
|
-
}) => {
|
|
46
|
-
if (!locationsMap) {
|
|
47
|
-
return source;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const sanitizedStoryName = storyIdToSanitizedStoryName(targetId);
|
|
51
|
-
const location = locationsMap[sanitizedStoryName];
|
|
52
|
-
|
|
53
|
-
if (!location) {
|
|
54
|
-
return source;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const lines = source.split('\n');
|
|
58
|
-
return extractSource(location, lines);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export const enhanceSource = story => {
|
|
62
|
-
const {
|
|
63
|
-
id,
|
|
64
|
-
parameters
|
|
65
|
-
} = story;
|
|
66
|
-
const {
|
|
67
|
-
storySource,
|
|
68
|
-
docs = {}
|
|
69
|
-
} = parameters;
|
|
70
|
-
const {
|
|
71
|
-
transformSource
|
|
72
|
-
} = docs; // no input or user has manually overridden the output
|
|
73
|
-
|
|
74
|
-
if (!storySource?.source || docs.source?.code) {
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const input = extract(id, storySource);
|
|
79
|
-
const code = transformSource ? transformSource(input, story) : input;
|
|
80
|
-
return {
|
|
81
|
-
docs: combineParameters(docs, {
|
|
82
|
-
source: {
|
|
83
|
-
code
|
|
84
|
-
}
|
|
85
|
-
})
|
|
86
|
-
};
|
|
87
|
-
};
|
package/dist/esm/blocks/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export { ColorPalette, ColorItem, IconGallery, IconItem, Typeset } from '@storybook/components';
|
|
2
|
-
export * from './Anchor';
|
|
3
|
-
export * from './ArgsTable';
|
|
4
|
-
export * from './Canvas';
|
|
5
|
-
export * from './Description';
|
|
6
|
-
export * from './DocsContext';
|
|
7
|
-
export * from './DocsPage';
|
|
8
|
-
export * from './DocsContainer';
|
|
9
|
-
export * from './DocsStory';
|
|
10
|
-
export * from './Heading';
|
|
11
|
-
export * from './Meta';
|
|
12
|
-
export * from './Preview';
|
|
13
|
-
export * from './Primary';
|
|
14
|
-
export * from './Props';
|
|
15
|
-
export * from './Source';
|
|
16
|
-
export * from './SourceContainer';
|
|
17
|
-
export * from './Stories';
|
|
18
|
-
export * from './Story';
|
|
19
|
-
export * from './Subheading';
|
|
20
|
-
export * from './Subtitle';
|
|
21
|
-
export * from './Title';
|
|
22
|
-
export * from './Wrapper';
|
|
23
|
-
export * from './types';
|
|
24
|
-
export * from './mdx';
|
package/dist/esm/blocks/mdx.js
DELETED
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
const _excluded = ["children"],
|
|
2
|
-
_excluded2 = ["className", "children"],
|
|
3
|
-
_excluded3 = ["href", "target", "children"],
|
|
4
|
-
_excluded4 = ["as", "id", "children"],
|
|
5
|
-
_excluded5 = ["as", "id", "children"];
|
|
6
|
-
|
|
7
|
-
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
8
|
-
|
|
9
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
10
|
-
|
|
11
|
-
import React from 'react';
|
|
12
|
-
import { addons } from '@storybook/addons';
|
|
13
|
-
import { NAVIGATE_URL } from '@storybook/core-events';
|
|
14
|
-
import { Source, Code, components } from '@storybook/components';
|
|
15
|
-
import global from 'global';
|
|
16
|
-
import { styled } from '@storybook/theming';
|
|
17
|
-
import { DocsContext } from './DocsContext';
|
|
18
|
-
const {
|
|
19
|
-
document
|
|
20
|
-
} = global; // Hacky utility for asserting identifiers in MDX Story elements
|
|
21
|
-
|
|
22
|
-
export const assertIsFn = val => {
|
|
23
|
-
if (typeof val !== 'function') {
|
|
24
|
-
throw new Error(`Expected story function, got: ${val}`);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return val;
|
|
28
|
-
}; // Hacky utility for adding mdxStoryToId to the default context
|
|
29
|
-
|
|
30
|
-
export const AddContext = props => {
|
|
31
|
-
const {
|
|
32
|
-
children
|
|
33
|
-
} = props,
|
|
34
|
-
rest = _objectWithoutPropertiesLoose(props, _excluded);
|
|
35
|
-
|
|
36
|
-
const parentContext = React.useContext(DocsContext);
|
|
37
|
-
return /*#__PURE__*/React.createElement(DocsContext.Provider, {
|
|
38
|
-
value: Object.assign({}, parentContext, rest)
|
|
39
|
-
}, children);
|
|
40
|
-
};
|
|
41
|
-
export const CodeOrSourceMdx = _ref => {
|
|
42
|
-
let {
|
|
43
|
-
className,
|
|
44
|
-
children
|
|
45
|
-
} = _ref,
|
|
46
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded2);
|
|
47
|
-
|
|
48
|
-
// markdown-to-jsx does not add className to inline code
|
|
49
|
-
if (typeof className !== 'string' && (typeof children !== 'string' || !children.match(/[\n\r]/g))) {
|
|
50
|
-
return /*#__PURE__*/React.createElement(Code, null, children);
|
|
51
|
-
} // className: "lang-jsx"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const language = className && className.split('-');
|
|
55
|
-
return /*#__PURE__*/React.createElement(Source, _extends({
|
|
56
|
-
language: language && language[1] || 'plaintext',
|
|
57
|
-
format: false,
|
|
58
|
-
code: children
|
|
59
|
-
}, rest));
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
function navigate(url) {
|
|
63
|
-
addons.getChannel().emit(NAVIGATE_URL, url);
|
|
64
|
-
} // @ts-ignore
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const A = components.a;
|
|
68
|
-
|
|
69
|
-
const AnchorInPage = ({
|
|
70
|
-
hash,
|
|
71
|
-
children
|
|
72
|
-
}) => /*#__PURE__*/React.createElement(A, {
|
|
73
|
-
href: hash,
|
|
74
|
-
target: "_self",
|
|
75
|
-
onClick: event => {
|
|
76
|
-
const id = hash.substring(1);
|
|
77
|
-
const element = document.getElementById(id);
|
|
78
|
-
|
|
79
|
-
if (element) {
|
|
80
|
-
navigate(hash);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}, children);
|
|
84
|
-
|
|
85
|
-
export const AnchorMdx = props => {
|
|
86
|
-
const {
|
|
87
|
-
href,
|
|
88
|
-
target,
|
|
89
|
-
children
|
|
90
|
-
} = props,
|
|
91
|
-
rest = _objectWithoutPropertiesLoose(props, _excluded3);
|
|
92
|
-
|
|
93
|
-
if (href) {
|
|
94
|
-
// Enable scrolling for in-page anchors.
|
|
95
|
-
if (href.startsWith('#')) {
|
|
96
|
-
return /*#__PURE__*/React.createElement(AnchorInPage, {
|
|
97
|
-
hash: href
|
|
98
|
-
}, children);
|
|
99
|
-
} // Links to other pages of SB should use the base URL of the top level iframe instead of the base URL of the preview iframe.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (target !== '_blank' && !href.startsWith('https://')) {
|
|
103
|
-
return /*#__PURE__*/React.createElement(A, _extends({
|
|
104
|
-
href: href,
|
|
105
|
-
onClick: event => {
|
|
106
|
-
event.preventDefault(); // use the A element's href, which has been modified for
|
|
107
|
-
// local paths without a `?path=` query param prefix
|
|
108
|
-
|
|
109
|
-
navigate(event.currentTarget.getAttribute('href'));
|
|
110
|
-
},
|
|
111
|
-
target: target
|
|
112
|
-
}, rest), children);
|
|
113
|
-
}
|
|
114
|
-
} // External URL dont need any modification.
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return /*#__PURE__*/React.createElement(A, props);
|
|
118
|
-
};
|
|
119
|
-
const SUPPORTED_MDX_HEADERS = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
|
|
120
|
-
const OcticonHeaders = SUPPORTED_MDX_HEADERS.reduce((acc, headerType) => Object.assign({}, acc, {
|
|
121
|
-
// @ts-ignore
|
|
122
|
-
[headerType]: styled(components[headerType])({
|
|
123
|
-
'& svg': {
|
|
124
|
-
visibility: 'hidden'
|
|
125
|
-
},
|
|
126
|
-
'&:hover svg': {
|
|
127
|
-
visibility: 'visible'
|
|
128
|
-
}
|
|
129
|
-
})
|
|
130
|
-
}), {});
|
|
131
|
-
const OcticonAnchor = styled.a(() => ({
|
|
132
|
-
float: 'left',
|
|
133
|
-
paddingRight: '4px',
|
|
134
|
-
marginLeft: '-20px',
|
|
135
|
-
// Allow the theme's text color to override the default link color.
|
|
136
|
-
color: 'inherit'
|
|
137
|
-
}));
|
|
138
|
-
|
|
139
|
-
const HeaderWithOcticonAnchor = _ref2 => {
|
|
140
|
-
let {
|
|
141
|
-
as,
|
|
142
|
-
id,
|
|
143
|
-
children
|
|
144
|
-
} = _ref2,
|
|
145
|
-
rest = _objectWithoutPropertiesLoose(_ref2, _excluded4);
|
|
146
|
-
|
|
147
|
-
// @ts-ignore
|
|
148
|
-
const OcticonHeader = OcticonHeaders[as];
|
|
149
|
-
const hash = `#${id}`;
|
|
150
|
-
return /*#__PURE__*/React.createElement(OcticonHeader, _extends({
|
|
151
|
-
id: id
|
|
152
|
-
}, rest), /*#__PURE__*/React.createElement(OcticonAnchor, {
|
|
153
|
-
"aria-hidden": "true",
|
|
154
|
-
href: hash,
|
|
155
|
-
tabIndex: -1,
|
|
156
|
-
target: "_self",
|
|
157
|
-
onClick: event => {
|
|
158
|
-
const element = document.getElementById(id);
|
|
159
|
-
|
|
160
|
-
if (element) {
|
|
161
|
-
navigate(hash);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}, /*#__PURE__*/React.createElement("svg", {
|
|
165
|
-
viewBox: "0 0 16 16",
|
|
166
|
-
version: "1.1",
|
|
167
|
-
width: "16",
|
|
168
|
-
height: "16",
|
|
169
|
-
"aria-hidden": "true",
|
|
170
|
-
fill: "currentColor"
|
|
171
|
-
}, /*#__PURE__*/React.createElement("path", {
|
|
172
|
-
fillRule: "evenodd",
|
|
173
|
-
d: "M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"
|
|
174
|
-
}))), children);
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
export const HeaderMdx = props => {
|
|
178
|
-
const {
|
|
179
|
-
as,
|
|
180
|
-
id,
|
|
181
|
-
children
|
|
182
|
-
} = props,
|
|
183
|
-
rest = _objectWithoutPropertiesLoose(props, _excluded5); // An id should have been added on every header by the "remark-slug" plugin.
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
if (id) {
|
|
187
|
-
return /*#__PURE__*/React.createElement(HeaderWithOcticonAnchor, _extends({
|
|
188
|
-
as: as,
|
|
189
|
-
id: id
|
|
190
|
-
}, rest), children);
|
|
191
|
-
} // @ts-ignore
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const Header = components[as]; // Make sure it still work if "remark-slug" plugin is not present.
|
|
195
|
-
|
|
196
|
-
return /*#__PURE__*/React.createElement(Header, props);
|
|
197
|
-
};
|
|
198
|
-
export const HeadersMdx = SUPPORTED_MDX_HEADERS.reduce((acc, headerType) => Object.assign({}, acc, {
|
|
199
|
-
// @ts-ignore
|
|
200
|
-
[headerType]: props => /*#__PURE__*/React.createElement(HeaderMdx, _extends({
|
|
201
|
-
as: headerType
|
|
202
|
-
}, props))
|
|
203
|
-
}), {});
|
package/dist/esm/blocks/types.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect } from 'react';
|
|
2
|
-
export function useStory(storyId, context) {
|
|
3
|
-
const stories = useStories([storyId], context);
|
|
4
|
-
return stories && stories[0];
|
|
5
|
-
}
|
|
6
|
-
export function useStories(storyIds, context) {
|
|
7
|
-
const initialStoriesById = context.componentStories().reduce((acc, story) => {
|
|
8
|
-
acc[story.id] = story;
|
|
9
|
-
return acc;
|
|
10
|
-
}, {});
|
|
11
|
-
const [storiesById, setStories] = useState(initialStoriesById);
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
Promise.all(storyIds.map(async storyId => {
|
|
14
|
-
// loadStory will be called every single time useStory is called
|
|
15
|
-
// because useEffect does not use storyIds as an input. This is because
|
|
16
|
-
// HMR can change the story even when the storyId hasn't changed. However, it
|
|
17
|
-
// will be a no-op once the story has loaded. Furthermore, the `story` will
|
|
18
|
-
// have an exact equality when the story hasn't changed, so it won't trigger
|
|
19
|
-
// any unnecessary re-renders
|
|
20
|
-
const story = await context.loadStory(storyId);
|
|
21
|
-
setStories(current => current[storyId] === story ? current : Object.assign({}, current, {
|
|
22
|
-
[storyId]: story
|
|
23
|
-
}));
|
|
24
|
-
}));
|
|
25
|
-
});
|
|
26
|
-
return storyIds.map(storyId => storiesById[storyId]);
|
|
27
|
-
}
|
package/dist/esm/blocks/utils.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-underscore-dangle */
|
|
2
|
-
const titleCase = str => str.split('-').map(part => part.charAt(0).toUpperCase() + part.slice(1)).join('');
|
|
3
|
-
|
|
4
|
-
export const getComponentName = component => {
|
|
5
|
-
if (!component) {
|
|
6
|
-
return undefined;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
if (typeof component === 'string') {
|
|
10
|
-
if (component.includes('-')) {
|
|
11
|
-
return titleCase(component);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return component;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (component.__docgenInfo && component.__docgenInfo.displayName) {
|
|
18
|
-
return component.__docgenInfo.displayName;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return component.name;
|
|
22
|
-
};
|
|
23
|
-
export function scrollToElement(element, block = 'start') {
|
|
24
|
-
element.scrollIntoView({
|
|
25
|
-
behavior: 'smooth',
|
|
26
|
-
block,
|
|
27
|
-
inline: 'nearest'
|
|
28
|
-
});
|
|
29
|
-
}
|
package/dist/esm/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './blocks';
|
package/dist/esm/manager.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { addons, types } from '@storybook/addons';
|
|
2
|
-
import { ADDON_ID, PANEL_ID } from './shared';
|
|
3
|
-
addons.register(ADDON_ID, () => {
|
|
4
|
-
addons.add(PANEL_ID, {
|
|
5
|
-
type: types.TAB,
|
|
6
|
-
title: 'Docs',
|
|
7
|
-
route: ({
|
|
8
|
-
storyId,
|
|
9
|
-
refId
|
|
10
|
-
}) => refId ? `/docs/${refId}_${storyId}` : `/docs/${storyId}`,
|
|
11
|
-
match: ({
|
|
12
|
-
viewMode
|
|
13
|
-
}) => viewMode === 'docs',
|
|
14
|
-
render: () => null
|
|
15
|
-
});
|
|
16
|
-
});
|