@storybook/addon-docs 7.0.0-alpha.7 → 7.0.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.
Files changed (94) hide show
  1. package/dist/cjs/blocks/index.js +4 -380
  2. package/dist/cjs/preview.js +1 -1
  3. package/dist/esm/blocks/index.js +1 -27
  4. package/dist/esm/preview.js +1 -1
  5. package/dist/types/blocks/index.d.ts +1 -26
  6. package/dist/types/preview.d.ts +1 -5
  7. package/package.json +16 -15
  8. package/dist/cjs/blocks/Anchor.js +0 -23
  9. package/dist/cjs/blocks/ArgsTable.js +0 -329
  10. package/dist/cjs/blocks/Canvas.js +0 -119
  11. package/dist/cjs/blocks/Description.js +0 -126
  12. package/dist/cjs/blocks/DocsContainer.js +0 -134
  13. package/dist/cjs/blocks/DocsContext.js +0 -25
  14. package/dist/cjs/blocks/DocsPage.js +0 -30
  15. package/dist/cjs/blocks/DocsRenderer.js +0 -48
  16. package/dist/cjs/blocks/DocsStory.js +0 -66
  17. package/dist/cjs/blocks/ExternalDocsContainer.js +0 -64
  18. package/dist/cjs/blocks/ExternalPreview.js +0 -99
  19. package/dist/cjs/blocks/Heading.js +0 -31
  20. package/dist/cjs/blocks/Meta.js +0 -64
  21. package/dist/cjs/blocks/Preview.js +0 -23
  22. package/dist/cjs/blocks/Primary.js +0 -39
  23. package/dist/cjs/blocks/Props.js +0 -29
  24. package/dist/cjs/blocks/Source.js +0 -175
  25. package/dist/cjs/blocks/SourceContainer.js +0 -67
  26. package/dist/cjs/blocks/Stories.js +0 -47
  27. package/dist/cjs/blocks/Story.js +0 -152
  28. package/dist/cjs/blocks/Subheading.js +0 -31
  29. package/dist/cjs/blocks/Subtitle.js +0 -39
  30. package/dist/cjs/blocks/Title.js +0 -44
  31. package/dist/cjs/blocks/Wrapper.js +0 -20
  32. package/dist/cjs/blocks/enhanceSource.js +0 -90
  33. package/dist/cjs/blocks/mdx.js +0 -234
  34. package/dist/cjs/blocks/types.js +0 -10
  35. package/dist/cjs/blocks/useStory.js +0 -44
  36. package/dist/cjs/blocks/utils.js +0 -40
  37. package/dist/esm/blocks/Anchor.js +0 -8
  38. package/dist/esm/blocks/ArgsTable.js +0 -292
  39. package/dist/esm/blocks/Canvas.js +0 -93
  40. package/dist/esm/blocks/Description.js +0 -107
  41. package/dist/esm/blocks/DocsContainer.js +0 -105
  42. package/dist/esm/blocks/DocsContext.js +0 -16
  43. package/dist/esm/blocks/DocsPage.js +0 -11
  44. package/dist/esm/blocks/DocsRenderer.js +0 -32
  45. package/dist/esm/blocks/DocsStory.js +0 -46
  46. package/dist/esm/blocks/ExternalDocsContainer.js +0 -48
  47. package/dist/esm/blocks/ExternalPreview.js +0 -89
  48. package/dist/esm/blocks/Heading.js +0 -17
  49. package/dist/esm/blocks/Meta.js +0 -45
  50. package/dist/esm/blocks/Preview.js +0 -9
  51. package/dist/esm/blocks/Primary.js +0 -23
  52. package/dist/esm/blocks/Props.js +0 -14
  53. package/dist/esm/blocks/Source.js +0 -150
  54. package/dist/esm/blocks/SourceContainer.js +0 -44
  55. package/dist/esm/blocks/Stories.js +0 -30
  56. package/dist/esm/blocks/Story.js +0 -123
  57. package/dist/esm/blocks/Subheading.js +0 -17
  58. package/dist/esm/blocks/Subtitle.js +0 -23
  59. package/dist/esm/blocks/Title.js +0 -24
  60. package/dist/esm/blocks/Wrapper.js +0 -8
  61. package/dist/esm/blocks/enhanceSource.js +0 -87
  62. package/dist/esm/blocks/mdx.js +0 -203
  63. package/dist/esm/blocks/types.js +0 -2
  64. package/dist/esm/blocks/useStory.js +0 -34
  65. package/dist/esm/blocks/utils.js +0 -29
  66. package/dist/types/blocks/Anchor.d.ts +0 -6
  67. package/dist/types/blocks/ArgsTable.d.ts +0 -33
  68. package/dist/types/blocks/Canvas.d.ts +0 -9
  69. package/dist/types/blocks/Description.d.ts +0 -20
  70. package/dist/types/blocks/DocsContainer.d.ts +0 -7
  71. package/dist/types/blocks/DocsContext.d.ts +0 -5
  72. package/dist/types/blocks/DocsPage.d.ts +0 -2
  73. package/dist/types/blocks/DocsRenderer.d.ts +0 -7
  74. package/dist/types/blocks/DocsStory.d.ts +0 -3
  75. package/dist/types/blocks/ExternalDocsContainer.d.ts +0 -4
  76. package/dist/types/blocks/ExternalPreview.d.ts +0 -19
  77. package/dist/types/blocks/Heading.d.ts +0 -6
  78. package/dist/types/blocks/Meta.d.ts +0 -12
  79. package/dist/types/blocks/Preview.d.ts +0 -3
  80. package/dist/types/blocks/Primary.d.ts +0 -6
  81. package/dist/types/blocks/Props.d.ts +0 -3
  82. package/dist/types/blocks/Source.d.ts +0 -38
  83. package/dist/types/blocks/SourceContainer.d.ts +0 -14
  84. package/dist/types/blocks/Stories.d.ts +0 -7
  85. package/dist/types/blocks/Story.d.ts +0 -30
  86. package/dist/types/blocks/Subheading.d.ts +0 -3
  87. package/dist/types/blocks/Subtitle.d.ts +0 -6
  88. package/dist/types/blocks/Title.d.ts +0 -8
  89. package/dist/types/blocks/Wrapper.d.ts +0 -2
  90. package/dist/types/blocks/enhanceSource.d.ts +0 -3
  91. package/dist/types/blocks/mdx.d.ts +0 -20
  92. package/dist/types/blocks/types.d.ts +0 -13
  93. package/dist/types/blocks/useStory.d.ts +0 -5
  94. package/dist/types/blocks/utils.d.ts +0 -3
@@ -1,175 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getSourceProps = exports.SourceState = exports.Source = void 0;
7
-
8
- var _react = _interopRequireWildcard(require("react"));
9
-
10
- var _components = require("@storybook/components");
11
-
12
- var _DocsContext = require("./DocsContext");
13
-
14
- var _SourceContainer = require("./SourceContainer");
15
-
16
- var _types = require("./types");
17
-
18
- var _shared = require("../shared");
19
-
20
- var _enhanceSource = require("./enhanceSource");
21
-
22
- var _useStory = require("./useStory");
23
-
24
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
25
-
26
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
27
-
28
- let SourceState;
29
- exports.SourceState = SourceState;
30
-
31
- (function (SourceState) {
32
- SourceState["OPEN"] = "open";
33
- SourceState["CLOSED"] = "closed";
34
- SourceState["NONE"] = "none";
35
- })(SourceState || (exports.SourceState = SourceState = {}));
36
-
37
- const getSourceState = stories => {
38
- const states = stories.map(story => story.parameters.docs?.source?.state).filter(Boolean);
39
- if (states.length === 0) return SourceState.CLOSED; // FIXME: handling multiple stories is a pain
40
-
41
- return states[0];
42
- };
43
-
44
- const getStorySource = (storyId, sourceContext) => {
45
- const {
46
- sources
47
- } = sourceContext; // source rendering is async so source is unavailable at the start of the render cycle,
48
- // so we fail gracefully here without warning
49
-
50
- return sources?.[storyId] || {
51
- code: '',
52
- format: false
53
- };
54
- };
55
-
56
- const getSnippet = (snippet, story) => {
57
- if (!story) {
58
- return snippet;
59
- }
60
-
61
- const {
62
- parameters
63
- } = story; // eslint-disable-next-line no-underscore-dangle
64
-
65
- const isArgsStory = parameters.__isArgsStory;
66
- const type = parameters.docs?.source?.type || _shared.SourceType.AUTO; // if user has hard-coded the snippet, that takes precedence
67
-
68
- const userCode = parameters.docs?.source?.code;
69
-
70
- if (userCode !== undefined) {
71
- return userCode;
72
- } // if user has explicitly set this as dynamic, use snippet
73
-
74
-
75
- if (type === _shared.SourceType.DYNAMIC) {
76
- return parameters.docs?.transformSource?.(snippet, story) || snippet;
77
- } // if this is an args story and there's a snippet
78
-
79
-
80
- if (type === _shared.SourceType.AUTO && snippet && isArgsStory) {
81
- return parameters.docs?.transformSource?.(snippet, story) || snippet;
82
- } // otherwise, use the source code logic
83
-
84
-
85
- const enhanced = (0, _enhanceSource.enhanceSource)(story) || parameters;
86
- return enhanced?.docs?.source?.code || '';
87
- };
88
-
89
- const getSourceProps = (props, docsContext, sourceContext) => {
90
- const {
91
- id: currentId,
92
- storyById
93
- } = docsContext;
94
- let parameters = {};
95
-
96
- try {
97
- ({
98
- parameters
99
- } = storyById(currentId));
100
- } catch (err) {// TODO: in external mode, there is no "current"
101
- }
102
-
103
- const codeProps = props;
104
- const singleProps = props;
105
- const multiProps = props;
106
- let source = codeProps.code; // prefer user-specified code
107
-
108
- let {
109
- format
110
- } = codeProps; // prefer user-specified code
111
-
112
- const targetIds = multiProps.ids || [singleProps.id || currentId];
113
- const storyIds = targetIds.map(targetId => targetId === _types.CURRENT_SELECTION ? currentId : targetId);
114
- const stories = (0, _useStory.useStories)(storyIds, docsContext);
115
-
116
- if (!stories.every(Boolean)) {
117
- return {
118
- error: _components.SourceError.SOURCE_UNAVAILABLE,
119
- state: SourceState.NONE
120
- };
121
- }
122
-
123
- if (!source) {
124
- // just take the format from the first story, given how they're all concatinated together...
125
- // TODO: we should consider sending an event with all the sources separately, instead of concatenating them here
126
- ({
127
- format
128
- } = getStorySource(storyIds[0], sourceContext));
129
- source = storyIds.map((storyId, idx) => {
130
- const {
131
- code: storySource
132
- } = getStorySource(storyId, sourceContext);
133
- const storyObj = stories[idx];
134
- return getSnippet(storySource, storyObj);
135
- }).join('\n\n');
136
- }
137
-
138
- const state = getSourceState(stories);
139
- const {
140
- docs: docsParameters = {}
141
- } = parameters;
142
- const {
143
- source: sourceParameters = {}
144
- } = docsParameters;
145
- const {
146
- language: docsLanguage = null
147
- } = sourceParameters;
148
- return source ? {
149
- code: source,
150
- state,
151
- format,
152
- language: props.language || docsLanguage || 'jsx',
153
- dark: props.dark || false
154
- } : {
155
- error: _components.SourceError.SOURCE_UNAVAILABLE,
156
- state
157
- };
158
- };
159
- /**
160
- * Story source doc block renders source code if provided,
161
- * or the source for a story if `storyId` is provided, or
162
- * the source for the current story if nothing is provided.
163
- */
164
-
165
-
166
- exports.getSourceProps = getSourceProps;
167
-
168
- const Source = props => {
169
- const sourceContext = (0, _react.useContext)(_SourceContainer.SourceContext);
170
- const docsContext = (0, _react.useContext)(_DocsContext.DocsContext);
171
- const sourceProps = getSourceProps(props, docsContext, sourceContext);
172
- return /*#__PURE__*/_react.default.createElement(_components.Source, sourceProps);
173
- };
174
-
175
- exports.Source = Source;
@@ -1,67 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.SourceContext = exports.SourceContainer = void 0;
7
-
8
- var _react = _interopRequireWildcard(require("react"));
9
-
10
- var _fastDeepEqual = _interopRequireDefault(require("fast-deep-equal"));
11
-
12
- var _addons = require("@storybook/addons");
13
-
14
- var _shared = require("../shared");
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
-
20
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
-
22
- const SourceContext = /*#__PURE__*/(0, _react.createContext)({
23
- sources: {}
24
- });
25
- exports.SourceContext = SourceContext;
26
-
27
- const SourceContainer = ({
28
- children
29
- }) => {
30
- const [sources, setSources] = (0, _react.useState)({});
31
-
32
- const channel = _addons.addons.getChannel();
33
-
34
- (0, _react.useEffect)(() => {
35
- const handleSnippetRendered = (id, newSource, format = false) => {
36
- // optimization: if the source is the same, ignore the incoming event
37
- if (sources[id] && sources[id].code === newSource) {
38
- return;
39
- }
40
-
41
- setSources(current => {
42
- const newSources = Object.assign({}, current, {
43
- [id]: {
44
- code: newSource,
45
- format
46
- }
47
- });
48
-
49
- if (!(0, _fastDeepEqual.default)(current, newSources)) {
50
- return newSources;
51
- }
52
-
53
- return current;
54
- });
55
- };
56
-
57
- channel.on(_shared.SNIPPET_RENDERED, handleSnippetRendered);
58
- return () => channel.off(_shared.SNIPPET_RENDERED, handleSnippetRendered);
59
- }, []);
60
- return /*#__PURE__*/_react.default.createElement(SourceContext.Provider, {
61
- value: {
62
- sources
63
- }
64
- }, children);
65
- };
66
-
67
- exports.SourceContainer = SourceContainer;
@@ -1,47 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Stories = void 0;
7
-
8
- var _react = _interopRequireWildcard(require("react"));
9
-
10
- var _DocsContext = require("./DocsContext");
11
-
12
- var _DocsStory = require("./DocsStory");
13
-
14
- var _Heading = require("./Heading");
15
-
16
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
-
18
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
-
20
- 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); }
21
-
22
- const Stories = ({
23
- title,
24
- includePrimary = false
25
- }) => {
26
- const {
27
- componentStories
28
- } = (0, _react.useContext)(_DocsContext.DocsContext);
29
- let stories = componentStories();
30
- stories = stories.filter(story => !story.parameters?.docs?.disable);
31
- if (!includePrimary) stories = stories.slice(1);
32
-
33
- if (!stories || stories.length === 0) {
34
- return null;
35
- }
36
-
37
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_Heading.Heading, null, title), stories.map(story => story && /*#__PURE__*/_react.default.createElement(_DocsStory.DocsStory, _extends({
38
- key: story.id
39
- }, story, {
40
- expanded: true
41
- }))));
42
- };
43
-
44
- exports.Stories = Stories;
45
- Stories.defaultProps = {
46
- title: 'Stories'
47
- };
@@ -1,152 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.storyBlockIdFromId = exports.lookupStoryId = exports.getStoryProps = exports.getStoryId = exports.Story = void 0;
7
-
8
- var _react = _interopRequireWildcard(require("react"));
9
-
10
- var _react2 = require("@mdx-js/react");
11
-
12
- var _components = require("@storybook/components");
13
-
14
- var _csf = require("@storybook/csf");
15
-
16
- var _types = require("./types");
17
-
18
- var _DocsContext = require("./DocsContext");
19
-
20
- var _useStory = require("./useStory");
21
-
22
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
23
-
24
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
25
-
26
- const storyBlockIdFromId = storyId => `story--${storyId}`;
27
-
28
- exports.storyBlockIdFromId = storyBlockIdFromId;
29
-
30
- const lookupStoryId = (storyName, {
31
- mdxStoryNameToKey,
32
- mdxComponentAnnotations
33
- }) => (0, _csf.toId)(mdxComponentAnnotations.id || mdxComponentAnnotations.title, (0, _csf.storyNameFromExport)(mdxStoryNameToKey[storyName]));
34
-
35
- exports.lookupStoryId = lookupStoryId;
36
-
37
- const getStoryId = (props, context) => {
38
- const {
39
- id,
40
- of,
41
- meta
42
- } = props;
43
-
44
- if (of) {
45
- return context.storyIdByModuleExport(of, meta);
46
- }
47
-
48
- const {
49
- name
50
- } = props;
51
- const inputId = id === _types.CURRENT_SELECTION ? context.id : id;
52
- return inputId || lookupStoryId(name, context);
53
- };
54
-
55
- exports.getStoryId = getStoryId;
56
-
57
- const getStoryProps = ({
58
- height,
59
- inline
60
- }, story) => {
61
- const {
62
- name: storyName,
63
- parameters = {}
64
- } = story || {};
65
- const {
66
- docs = {}
67
- } = parameters;
68
-
69
- if (docs.disable) {
70
- return null;
71
- } // prefer block props, then story parameters defined by the framework-specific settings and optionally overridden by users
72
-
73
-
74
- const {
75
- inlineStories = false,
76
- iframeHeight = 100
77
- } = docs;
78
- const storyIsInline = typeof inline === 'boolean' ? inline : inlineStories;
79
- return Object.assign({
80
- inline: storyIsInline,
81
- id: story?.id,
82
- height: height || (storyIsInline ? undefined : iframeHeight),
83
- title: storyName
84
- }, storyIsInline && {
85
- parameters
86
- });
87
- };
88
-
89
- exports.getStoryProps = getStoryProps;
90
-
91
- const Story = props => {
92
- const context = (0, _react.useContext)(_DocsContext.DocsContext);
93
- const storyRef = (0, _react.useRef)();
94
- const storyId = getStoryId(props, context);
95
- const story = (0, _useStory.useStory)(storyId, context);
96
- const [showLoader, setShowLoader] = (0, _react.useState)(true);
97
- (0, _react.useEffect)(() => {
98
- let cleanup;
99
-
100
- if (story && storyRef.current) {
101
- const element = storyRef.current;
102
- cleanup = context.renderStoryToElement(story, element);
103
- setShowLoader(false);
104
- }
105
-
106
- return () => cleanup && cleanup();
107
- }, [story]);
108
-
109
- if (!story) {
110
- return /*#__PURE__*/_react.default.createElement(_components.StorySkeleton, null);
111
- }
112
-
113
- const storyProps = getStoryProps(props, story);
114
-
115
- if (!storyProps) {
116
- return null;
117
- }
118
-
119
- const inline = context.type === 'external' || storyProps.inline;
120
-
121
- if (inline) {
122
- // We do this so React doesn't complain when we replace the span in a secondary render
123
- const htmlContents = `<span></span>`; // FIXME: height/style/etc. lifted from PureStory
124
-
125
- const {
126
- height
127
- } = storyProps;
128
- return /*#__PURE__*/_react.default.createElement("div", {
129
- id: storyBlockIdFromId(story.id)
130
- }, /*#__PURE__*/_react.default.createElement(_react2.MDXProvider, {
131
- components: _components.resetComponents
132
- }, height ? /*#__PURE__*/_react.default.createElement("style", null, `#story--${story.id} { min-height: ${height}px; transform: translateZ(0); overflow: auto }`) : null, showLoader && /*#__PURE__*/_react.default.createElement(_components.StorySkeleton, null), /*#__PURE__*/_react.default.createElement("div", {
133
- ref: storyRef,
134
- "data-name": story.name,
135
- dangerouslySetInnerHTML: {
136
- __html: htmlContents
137
- }
138
- })));
139
- }
140
-
141
- return /*#__PURE__*/_react.default.createElement("div", {
142
- id: storyBlockIdFromId(story.id)
143
- }, /*#__PURE__*/_react.default.createElement(_react2.MDXProvider, {
144
- components: _components.resetComponents
145
- }, /*#__PURE__*/_react.default.createElement(_components.Story, storyProps)));
146
- };
147
-
148
- exports.Story = Story;
149
- Story.defaultProps = {
150
- children: null,
151
- name: null
152
- };
@@ -1,31 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Subheading = void 0;
7
-
8
- var _react = _interopRequireDefault(require("react"));
9
-
10
- var _components = require("@storybook/components");
11
-
12
- var _mdx = require("./mdx");
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- const Subheading = ({
17
- children,
18
- disableAnchor
19
- }) => {
20
- if (disableAnchor || typeof children !== 'string') {
21
- return /*#__PURE__*/_react.default.createElement(_components.H3, null, children);
22
- }
23
-
24
- const tagID = children.toLowerCase().replace(/[^a-z0-9]/gi, '-');
25
- return /*#__PURE__*/_react.default.createElement(_mdx.HeaderMdx, {
26
- as: "h3",
27
- id: tagID
28
- }, children);
29
- };
30
-
31
- exports.Subheading = Subheading;
@@ -1,39 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Subtitle = void 0;
7
-
8
- var _react = _interopRequireWildcard(require("react"));
9
-
10
- var _components = require("@storybook/components");
11
-
12
- var _DocsContext = require("./DocsContext");
13
-
14
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
-
16
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
-
18
- const Subtitle = ({
19
- children
20
- }) => {
21
- const {
22
- id,
23
- storyById
24
- } = (0, _react.useContext)(_DocsContext.DocsContext);
25
- const {
26
- parameters
27
- } = storyById(id);
28
- let text = children;
29
-
30
- if (!text) {
31
- text = parameters?.componentSubtitle;
32
- }
33
-
34
- return text ? /*#__PURE__*/_react.default.createElement(_components.Subtitle, {
35
- className: "sbdocs-subtitle"
36
- }, text) : null;
37
- };
38
-
39
- exports.Subtitle = Subtitle;
@@ -1,44 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.extractTitle = exports.Title = void 0;
7
-
8
- var _react = _interopRequireWildcard(require("react"));
9
-
10
- var _components = require("@storybook/components");
11
-
12
- var _DocsContext = require("./DocsContext");
13
-
14
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
-
16
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
-
18
- const STORY_KIND_PATH_SEPARATOR = /\s*\/\s*/;
19
-
20
- const extractTitle = ({
21
- title
22
- }) => {
23
- const groups = title.trim().split(STORY_KIND_PATH_SEPARATOR);
24
- return groups && groups[groups.length - 1] || title;
25
- };
26
-
27
- exports.extractTitle = extractTitle;
28
-
29
- const Title = ({
30
- children
31
- }) => {
32
- const context = (0, _react.useContext)(_DocsContext.DocsContext);
33
- let text = children;
34
-
35
- if (!text) {
36
- text = extractTitle(context);
37
- }
38
-
39
- return text ? /*#__PURE__*/_react.default.createElement(_components.Title, {
40
- className: "sbdocs-title"
41
- }, text) : null;
42
- };
43
-
44
- exports.Title = Title;
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Wrapper = void 0;
7
-
8
- var _react = _interopRequireDefault(require("react"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- const Wrapper = ({
13
- children
14
- }) => /*#__PURE__*/_react.default.createElement("div", {
15
- style: {
16
- fontFamily: 'sans-serif'
17
- }
18
- }, children);
19
-
20
- exports.Wrapper = Wrapper;
@@ -1,90 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.enhanceSource = void 0;
7
-
8
- var _store = require("@storybook/store");
9
-
10
- /**
11
- * given a location, extract the text from the full source
12
- */
13
- function extractSource(location, lines) {
14
- const {
15
- startBody: start,
16
- endBody: end
17
- } = location;
18
-
19
- if (start.line === end.line && lines[start.line - 1] !== undefined) {
20
- return lines[start.line - 1].substring(start.col, end.col);
21
- } // NOTE: storysource locations are 1-based not 0-based!
22
-
23
-
24
- const startLine = lines[start.line - 1];
25
- const endLine = lines[end.line - 1];
26
-
27
- if (startLine === undefined || endLine === undefined) {
28
- return null;
29
- }
30
-
31
- return [startLine.substring(start.col), ...lines.slice(start.line, end.line - 1), endLine.substring(0, end.col)].join('\n');
32
- } // ============================================================
33
- // END @storybook/source-loader/extract-source
34
- // ============================================================
35
-
36
-
37
- /**
38
- * Replaces full story id name like: story-kind--story-name -> story-name
39
- * @param id
40
- */
41
- const storyIdToSanitizedStoryName = id => id.replace(/^.*?--/, '');
42
-
43
- const extract = (targetId, {
44
- source,
45
- locationsMap
46
- }) => {
47
- if (!locationsMap) {
48
- return source;
49
- }
50
-
51
- const sanitizedStoryName = storyIdToSanitizedStoryName(targetId);
52
- const location = locationsMap[sanitizedStoryName];
53
-
54
- if (!location) {
55
- return source;
56
- }
57
-
58
- const lines = source.split('\n');
59
- return extractSource(location, lines);
60
- };
61
-
62
- const enhanceSource = story => {
63
- const {
64
- id,
65
- parameters
66
- } = story;
67
- const {
68
- storySource,
69
- docs = {}
70
- } = parameters;
71
- const {
72
- transformSource
73
- } = docs; // no input or user has manually overridden the output
74
-
75
- if (!storySource?.source || docs.source?.code) {
76
- return null;
77
- }
78
-
79
- const input = extract(id, storySource);
80
- const code = transformSource ? transformSource(input, story) : input;
81
- return {
82
- docs: (0, _store.combineParameters)(docs, {
83
- source: {
84
- code
85
- }
86
- })
87
- };
88
- };
89
-
90
- exports.enhanceSource = enhanceSource;