@storybook/addon-docs 6.5.6 → 7.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/blocks.d.ts +1 -1
- package/dist/cjs/blocks/ArgsTable.js +1 -1
- package/dist/cjs/blocks/Primary.js +1 -1
- package/dist/cjs/blocks/Stories.js +1 -1
- package/dist/cjs/blocks/mdx.js +1 -1
- package/dist/cjs/blocks/useStory.js +18 -4
- package/dist/cjs/preset.js +137 -33
- package/dist/cjs/preview.js +22 -6
- package/dist/esm/blocks/Anchor.js +7 -10
- package/dist/esm/blocks/ArgsTable.js +133 -182
- package/dist/esm/blocks/Canvas.js +34 -46
- package/dist/esm/blocks/Description.js +39 -45
- package/dist/esm/blocks/DocsContainer.js +36 -44
- package/dist/esm/blocks/DocsContext.js +1 -1
- package/dist/esm/blocks/DocsPage.js +3 -5
- package/dist/esm/blocks/DocsStory.js +18 -27
- package/dist/esm/blocks/Heading.js +5 -7
- package/dist/esm/blocks/Meta.js +9 -13
- package/dist/esm/blocks/Preview.js +5 -10
- package/dist/esm/blocks/Primary.js +10 -16
- package/dist/esm/blocks/Props.js +5 -10
- package/dist/esm/blocks/Source.js +64 -70
- package/dist/esm/blocks/SourceContainer.js +17 -50
- package/dist/esm/blocks/Stories.js +15 -27
- package/dist/esm/blocks/Story.js +58 -99
- package/dist/esm/blocks/Subheading.js +5 -7
- package/dist/esm/blocks/Subtitle.js +12 -12
- package/dist/esm/blocks/Title.js +10 -11
- package/dist/esm/blocks/Wrapper.js +7 -8
- package/dist/esm/blocks/enhanceSource.js +32 -56
- package/dist/esm/blocks/mdx.js +85 -89
- package/dist/esm/blocks/types.js +2 -2
- package/dist/esm/blocks/useStory.js +16 -73
- package/dist/esm/blocks/utils.js +4 -18
- package/dist/esm/manager.js +9 -14
- package/dist/esm/preset.js +114 -179
- package/dist/esm/preview.js +3 -61
- package/dist/esm/shared.js +5 -5
- package/dist/{ts3.9 → types}/blocks/Anchor.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/ArgsTable.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/Canvas.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/Description.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/DocsContainer.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/DocsContext.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/DocsPage.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/DocsStory.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/Heading.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/Meta.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/Preview.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/Primary.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/Props.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/Source.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/SourceContainer.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/Stories.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/Story.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/Subheading.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/Subtitle.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/Title.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/Wrapper.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/enhanceSource.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/index.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/mdx.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/types.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/useStory.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/utils.d.ts +0 -0
- package/dist/{ts3.9 → types}/index.d.ts +0 -0
- package/dist/{ts3.9 → types}/manager.d.ts +0 -0
- package/dist/{ts3.9 → types}/preset.d.ts +2 -1
- package/dist/{ts3.9 → types}/preview.d.ts +0 -0
- package/dist/{ts3.9 → types}/shared.d.ts +0 -0
- package/package.json +16 -24
- package/dist/modern/blocks/Anchor.js +0 -8
- package/dist/modern/blocks/ArgsTable.js +0 -292
- package/dist/modern/blocks/Canvas.js +0 -83
- package/dist/modern/blocks/Description.js +0 -107
- package/dist/modern/blocks/DocsContainer.js +0 -98
- package/dist/modern/blocks/DocsContext.js +0 -16
- package/dist/modern/blocks/DocsPage.js +0 -11
- package/dist/modern/blocks/DocsStory.js +0 -48
- package/dist/modern/blocks/Heading.js +0 -17
- package/dist/modern/blocks/Meta.js +0 -31
- package/dist/modern/blocks/Preview.js +0 -9
- package/dist/modern/blocks/Primary.js +0 -23
- package/dist/modern/blocks/Props.js +0 -14
- package/dist/modern/blocks/Source.js +0 -154
- package/dist/modern/blocks/SourceContainer.js +0 -44
- package/dist/modern/blocks/Stories.js +0 -34
- package/dist/modern/blocks/Story.js +0 -168
- package/dist/modern/blocks/Subheading.js +0 -17
- package/dist/modern/blocks/Subtitle.js +0 -23
- package/dist/modern/blocks/Title.js +0 -24
- package/dist/modern/blocks/Wrapper.js +0 -8
- package/dist/modern/blocks/enhanceSource.js +0 -89
- package/dist/modern/blocks/index.js +0 -24
- package/dist/modern/blocks/mdx.js +0 -204
- package/dist/modern/blocks/types.js +0 -2
- package/dist/modern/blocks/useStory.js +0 -28
- package/dist/modern/blocks/utils.js +0 -29
- package/dist/modern/index.js +0 -1
- package/dist/modern/manager.js +0 -16
- package/dist/modern/preset.js +0 -130
- package/dist/modern/preview.js +0 -6
- package/dist/modern/shared.js +0 -11
- package/dist/ts3.4/blocks/Anchor.d.ts +0 -6
- package/dist/ts3.4/blocks/ArgsTable.d.ts +0 -33
- package/dist/ts3.4/blocks/Canvas.d.ts +0 -9
- package/dist/ts3.4/blocks/Description.d.ts +0 -20
- package/dist/ts3.4/blocks/DocsContainer.d.ts +0 -7
- package/dist/ts3.4/blocks/DocsContext.d.ts +0 -5
- package/dist/ts3.4/blocks/DocsPage.d.ts +0 -2
- package/dist/ts3.4/blocks/DocsStory.d.ts +0 -3
- package/dist/ts3.4/blocks/Heading.d.ts +0 -6
- package/dist/ts3.4/blocks/Meta.d.ts +0 -9
- package/dist/ts3.4/blocks/Preview.d.ts +0 -3
- package/dist/ts3.4/blocks/Primary.d.ts +0 -6
- package/dist/ts3.4/blocks/Props.d.ts +0 -3
- package/dist/ts3.4/blocks/Source.d.ts +0 -38
- package/dist/ts3.4/blocks/SourceContainer.d.ts +0 -14
- package/dist/ts3.4/blocks/Stories.d.ts +0 -7
- package/dist/ts3.4/blocks/Story.d.ts +0 -28
- package/dist/ts3.4/blocks/Subheading.d.ts +0 -3
- package/dist/ts3.4/blocks/Subtitle.d.ts +0 -6
- package/dist/ts3.4/blocks/Title.d.ts +0 -8
- package/dist/ts3.4/blocks/Wrapper.d.ts +0 -2
- package/dist/ts3.4/blocks/enhanceSource.d.ts +0 -3
- package/dist/ts3.4/blocks/index.d.ts +0 -24
- package/dist/ts3.4/blocks/mdx.d.ts +0 -20
- package/dist/ts3.4/blocks/types.d.ts +0 -13
- package/dist/ts3.4/blocks/useStory.d.ts +0 -5
- package/dist/ts3.4/blocks/utils.d.ts +0 -3
- package/dist/ts3.4/index.d.ts +0 -1
- package/dist/ts3.4/manager.d.ts +0 -1
- package/dist/ts3.4/preset.d.ts +0 -11
- package/dist/ts3.4/preview.d.ts +0 -6
- package/dist/ts3.4/shared.d.ts +0 -24
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import "core-js/modules/es.array.filter.js";
|
|
2
|
-
import "core-js/modules/es.object.to-string.js";
|
|
3
|
-
import "core-js/modules/es.array.map.js";
|
|
4
|
-
import "core-js/modules/es.array.join.js";
|
|
5
1
|
import React, { useContext } from 'react';
|
|
6
2
|
import { Source as PureSource, SourceError } from '@storybook/components';
|
|
7
3
|
import { DocsContext } from './DocsContext';
|
|
@@ -10,7 +6,7 @@ import { CURRENT_SELECTION } from './types';
|
|
|
10
6
|
import { SourceType } from '../shared';
|
|
11
7
|
import { enhanceSource } from './enhanceSource';
|
|
12
8
|
import { useStories } from './useStory';
|
|
13
|
-
export
|
|
9
|
+
export let SourceState;
|
|
14
10
|
|
|
15
11
|
(function (SourceState) {
|
|
16
12
|
SourceState["OPEN"] = "open";
|
|
@@ -18,40 +14,38 @@ export var SourceState;
|
|
|
18
14
|
SourceState["NONE"] = "none";
|
|
19
15
|
})(SourceState || (SourceState = {}));
|
|
20
16
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
var _story$parameters$doc, _story$parameters$doc2;
|
|
24
|
-
|
|
25
|
-
return (_story$parameters$doc = story.parameters.docs) === null || _story$parameters$doc === void 0 ? void 0 : (_story$parameters$doc2 = _story$parameters$doc.source) === null || _story$parameters$doc2 === void 0 ? void 0 : _story$parameters$doc2.state;
|
|
26
|
-
}).filter(Boolean);
|
|
17
|
+
const getSourceState = stories => {
|
|
18
|
+
const states = stories.map(story => story.parameters.docs?.source?.state).filter(Boolean);
|
|
27
19
|
if (states.length === 0) return SourceState.CLOSED; // FIXME: handling multiple stories is a pain
|
|
28
20
|
|
|
29
21
|
return states[0];
|
|
30
22
|
};
|
|
31
23
|
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
const getStorySource = (storyId, sourceContext) => {
|
|
25
|
+
const {
|
|
26
|
+
sources
|
|
27
|
+
} = sourceContext; // source rendering is async so source is unavailable at the start of the render cycle,
|
|
34
28
|
// so we fail gracefully here without warning
|
|
35
29
|
|
|
36
|
-
return
|
|
30
|
+
return sources?.[storyId] || {
|
|
37
31
|
code: '',
|
|
38
32
|
format: false
|
|
39
33
|
};
|
|
40
34
|
};
|
|
41
35
|
|
|
42
|
-
|
|
43
|
-
var _parameters$docs, _parameters$docs$sour, _parameters$docs2, _parameters$docs2$sou, _enhanced$docs, _enhanced$docs$source;
|
|
44
|
-
|
|
36
|
+
const getSnippet = (snippet, story) => {
|
|
45
37
|
if (!story) {
|
|
46
38
|
return snippet;
|
|
47
39
|
}
|
|
48
40
|
|
|
49
|
-
|
|
41
|
+
const {
|
|
42
|
+
parameters
|
|
43
|
+
} = story; // eslint-disable-next-line no-underscore-dangle
|
|
50
44
|
|
|
51
|
-
|
|
52
|
-
|
|
45
|
+
const isArgsStory = parameters.__isArgsStory;
|
|
46
|
+
const type = parameters.docs?.source?.type || SourceType.AUTO; // if user has hard-coded the snippet, that takes precedence
|
|
53
47
|
|
|
54
|
-
|
|
48
|
+
const userCode = parameters.docs?.source?.code;
|
|
55
49
|
|
|
56
50
|
if (userCode !== undefined) {
|
|
57
51
|
return userCode;
|
|
@@ -59,42 +53,39 @@ var getSnippet = function getSnippet(snippet, story) {
|
|
|
59
53
|
|
|
60
54
|
|
|
61
55
|
if (type === SourceType.DYNAMIC) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return ((_parameters$docs3 = parameters.docs) === null || _parameters$docs3 === void 0 ? void 0 : (_parameters$docs3$tra = _parameters$docs3.transformSource) === null || _parameters$docs3$tra === void 0 ? void 0 : _parameters$docs3$tra.call(_parameters$docs3, snippet, story)) || snippet;
|
|
56
|
+
return parameters.docs?.transformSource?.(snippet, story) || snippet;
|
|
65
57
|
} // if this is an args story and there's a snippet
|
|
66
58
|
|
|
67
59
|
|
|
68
60
|
if (type === SourceType.AUTO && snippet && isArgsStory) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return ((_parameters$docs4 = parameters.docs) === null || _parameters$docs4 === void 0 ? void 0 : (_parameters$docs4$tra = _parameters$docs4.transformSource) === null || _parameters$docs4$tra === void 0 ? void 0 : _parameters$docs4$tra.call(_parameters$docs4, snippet, story)) || snippet;
|
|
61
|
+
return parameters.docs?.transformSource?.(snippet, story) || snippet;
|
|
72
62
|
} // otherwise, use the source code logic
|
|
73
63
|
|
|
74
64
|
|
|
75
|
-
|
|
76
|
-
return
|
|
65
|
+
const enhanced = enhanceSource(story) || parameters;
|
|
66
|
+
return enhanced?.docs?.source?.code || '';
|
|
77
67
|
};
|
|
78
68
|
|
|
79
|
-
export
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
69
|
+
export const getSourceProps = (props, docsContext, sourceContext) => {
|
|
70
|
+
const {
|
|
71
|
+
id: currentId,
|
|
72
|
+
storyById
|
|
73
|
+
} = docsContext;
|
|
74
|
+
const {
|
|
75
|
+
parameters
|
|
76
|
+
} = storyById(currentId);
|
|
77
|
+
const codeProps = props;
|
|
78
|
+
const singleProps = props;
|
|
79
|
+
const multiProps = props;
|
|
80
|
+
let source = codeProps.code; // prefer user-specified code
|
|
81
|
+
|
|
82
|
+
let {
|
|
83
|
+
format
|
|
84
|
+
} = codeProps; // prefer user-specified code
|
|
85
|
+
|
|
86
|
+
const targetIds = multiProps.ids || [singleProps.id || currentId];
|
|
87
|
+
const storyIds = targetIds.map(targetId => targetId === CURRENT_SELECTION ? currentId : targetId);
|
|
88
|
+
const stories = useStories(storyIds, docsContext);
|
|
98
89
|
|
|
99
90
|
if (!stories.every(Boolean)) {
|
|
100
91
|
return {
|
|
@@ -106,34 +97,37 @@ export var getSourceProps = function getSourceProps(props, docsContext, sourceCo
|
|
|
106
97
|
if (!source) {
|
|
107
98
|
// just take the format from the first story, given how they're all concatinated together...
|
|
108
99
|
// TODO: we should consider sending an event with all the sources separately, instead of concatenating them here
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
source = storyIds.map(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
100
|
+
({
|
|
101
|
+
format
|
|
102
|
+
} = getStorySource(storyIds[0], sourceContext));
|
|
103
|
+
source = storyIds.map((storyId, idx) => {
|
|
104
|
+
const {
|
|
105
|
+
code: storySource
|
|
106
|
+
} = getStorySource(storyId, sourceContext);
|
|
107
|
+
const storyObj = stories[idx];
|
|
117
108
|
return getSnippet(storySource, storyObj);
|
|
118
109
|
}).join('\n\n');
|
|
119
110
|
}
|
|
120
111
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
112
|
+
const state = getSourceState(stories);
|
|
113
|
+
const {
|
|
114
|
+
docs: docsParameters = {}
|
|
115
|
+
} = parameters;
|
|
116
|
+
const {
|
|
117
|
+
source: sourceParameters = {}
|
|
118
|
+
} = docsParameters;
|
|
119
|
+
const {
|
|
120
|
+
language: docsLanguage = null
|
|
121
|
+
} = sourceParameters;
|
|
128
122
|
return source ? {
|
|
129
123
|
code: source,
|
|
130
|
-
state
|
|
131
|
-
format
|
|
124
|
+
state,
|
|
125
|
+
format,
|
|
132
126
|
language: props.language || docsLanguage || 'jsx',
|
|
133
127
|
dark: props.dark || false
|
|
134
128
|
} : {
|
|
135
129
|
error: SourceError.SOURCE_UNAVAILABLE,
|
|
136
|
-
state
|
|
130
|
+
state
|
|
137
131
|
};
|
|
138
132
|
};
|
|
139
133
|
/**
|
|
@@ -142,9 +136,9 @@ export var getSourceProps = function getSourceProps(props, docsContext, sourceCo
|
|
|
142
136
|
* the source for the current story if nothing is provided.
|
|
143
137
|
*/
|
|
144
138
|
|
|
145
|
-
export
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
139
|
+
export const Source = props => {
|
|
140
|
+
const sourceContext = useContext(SourceContext);
|
|
141
|
+
const docsContext = useContext(DocsContext);
|
|
142
|
+
const sourceProps = getSourceProps(props, docsContext, sourceContext);
|
|
149
143
|
return /*#__PURE__*/React.createElement(PureSource, sourceProps);
|
|
150
144
|
};
|
|
@@ -1,60 +1,29 @@
|
|
|
1
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
-
|
|
3
|
-
import "core-js/modules/es.object.assign.js";
|
|
4
|
-
import "core-js/modules/es.symbol.js";
|
|
5
|
-
import "core-js/modules/es.symbol.description.js";
|
|
6
|
-
import "core-js/modules/es.object.to-string.js";
|
|
7
|
-
import "core-js/modules/es.symbol.iterator.js";
|
|
8
|
-
import "core-js/modules/es.array.iterator.js";
|
|
9
|
-
import "core-js/modules/es.string.iterator.js";
|
|
10
|
-
import "core-js/modules/web.dom-collections.iterator.js";
|
|
11
|
-
import "core-js/modules/es.array.slice.js";
|
|
12
|
-
import "core-js/modules/es.function.name.js";
|
|
13
|
-
import "core-js/modules/es.array.from.js";
|
|
14
|
-
import "core-js/modules/es.regexp.exec.js";
|
|
15
|
-
|
|
16
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
17
|
-
|
|
18
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
19
|
-
|
|
20
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
21
|
-
|
|
22
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
23
|
-
|
|
24
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
25
|
-
|
|
26
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
27
|
-
|
|
28
1
|
import React, { createContext, useEffect, useState } from 'react';
|
|
29
2
|
import deepEqual from 'fast-deep-equal';
|
|
30
3
|
import { addons } from '@storybook/addons';
|
|
31
4
|
import { SNIPPET_RENDERED } from '../shared';
|
|
32
|
-
export
|
|
5
|
+
export const SourceContext = /*#__PURE__*/createContext({
|
|
33
6
|
sources: {}
|
|
34
7
|
});
|
|
35
|
-
export
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var channel = addons.getChannel();
|
|
44
|
-
useEffect(function () {
|
|
45
|
-
var handleSnippetRendered = function handleSnippetRendered(id, newSource) {
|
|
46
|
-
var format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
47
|
-
|
|
8
|
+
export const SourceContainer = ({
|
|
9
|
+
children
|
|
10
|
+
}) => {
|
|
11
|
+
const [sources, setSources] = useState({});
|
|
12
|
+
const channel = addons.getChannel();
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const handleSnippetRendered = (id, newSource, format = false) => {
|
|
48
15
|
// optimization: if the source is the same, ignore the incoming event
|
|
49
16
|
if (sources[id] && sources[id].code === newSource) {
|
|
50
17
|
return;
|
|
51
18
|
}
|
|
52
19
|
|
|
53
|
-
setSources(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
20
|
+
setSources(current => {
|
|
21
|
+
const newSources = Object.assign({}, current, {
|
|
22
|
+
[id]: {
|
|
23
|
+
code: newSource,
|
|
24
|
+
format
|
|
25
|
+
}
|
|
26
|
+
});
|
|
58
27
|
|
|
59
28
|
if (!deepEqual(current, newSources)) {
|
|
60
29
|
return newSources;
|
|
@@ -65,13 +34,11 @@ export var SourceContainer = function SourceContainer(_ref) {
|
|
|
65
34
|
};
|
|
66
35
|
|
|
67
36
|
channel.on(SNIPPET_RENDERED, handleSnippetRendered);
|
|
68
|
-
return
|
|
69
|
-
return channel.off(SNIPPET_RENDERED, handleSnippetRendered);
|
|
70
|
-
};
|
|
37
|
+
return () => channel.off(SNIPPET_RENDERED, handleSnippetRendered);
|
|
71
38
|
}, []);
|
|
72
39
|
return /*#__PURE__*/React.createElement(SourceContext.Provider, {
|
|
73
40
|
value: {
|
|
74
|
-
sources
|
|
41
|
+
sources
|
|
75
42
|
}
|
|
76
43
|
}, children);
|
|
77
44
|
};
|
|
@@ -1,41 +1,29 @@
|
|
|
1
|
-
function _extends() { _extends = Object.assign
|
|
1
|
+
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); }
|
|
2
2
|
|
|
3
|
-
import "core-js/modules/es.array.filter.js";
|
|
4
|
-
import "core-js/modules/es.object.to-string.js";
|
|
5
|
-
import "core-js/modules/es.array.slice.js";
|
|
6
|
-
import "core-js/modules/es.array.map.js";
|
|
7
|
-
import "core-js/modules/es.object.assign.js";
|
|
8
3
|
import React, { useContext } from 'react';
|
|
9
4
|
import { DocsContext } from './DocsContext';
|
|
10
5
|
import { DocsStory } from './DocsStory';
|
|
11
6
|
import { Heading } from './Heading';
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
stories = stories.filter(function (story) {
|
|
22
|
-
var _story$parameters, _story$parameters$doc;
|
|
23
|
-
|
|
24
|
-
return !((_story$parameters = story.parameters) !== null && _story$parameters !== void 0 && (_story$parameters$doc = _story$parameters.docs) !== null && _story$parameters$doc !== void 0 && _story$parameters$doc.disable);
|
|
25
|
-
});
|
|
7
|
+
export const Stories = ({
|
|
8
|
+
title,
|
|
9
|
+
includePrimary = false
|
|
10
|
+
}) => {
|
|
11
|
+
const {
|
|
12
|
+
componentStories
|
|
13
|
+
} = useContext(DocsContext);
|
|
14
|
+
let stories = componentStories();
|
|
15
|
+
stories = stories.filter(story => !story.parameters?.docs?.disable);
|
|
26
16
|
if (!includePrimary) stories = stories.slice(1);
|
|
27
17
|
|
|
28
18
|
if (!stories || stories.length === 0) {
|
|
29
19
|
return null;
|
|
30
20
|
}
|
|
31
21
|
|
|
32
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Heading, null, title), stories.map(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}));
|
|
38
|
-
}));
|
|
22
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Heading, null, title), stories.map(story => story && /*#__PURE__*/React.createElement(DocsStory, _extends({
|
|
23
|
+
key: story.id
|
|
24
|
+
}, story, {
|
|
25
|
+
expanded: true
|
|
26
|
+
}))));
|
|
39
27
|
};
|
|
40
28
|
Stories.defaultProps = {
|
|
41
29
|
title: 'Stories'
|
package/dist/esm/blocks/Story.js
CHANGED
|
@@ -1,29 +1,3 @@
|
|
|
1
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
-
|
|
3
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
-
|
|
5
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
-
|
|
7
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
8
|
-
|
|
9
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
10
|
-
|
|
11
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
-
|
|
13
|
-
import "core-js/modules/es.function.name.js";
|
|
14
|
-
import "core-js/modules/es.object.assign.js";
|
|
15
|
-
import "core-js/modules/es.object.to-string.js";
|
|
16
|
-
import "core-js/modules/es.promise.js";
|
|
17
|
-
import "core-js/modules/es.array.iterator.js";
|
|
18
|
-
import "core-js/modules/es.string.iterator.js";
|
|
19
|
-
import "core-js/modules/web.dom-collections.iterator.js";
|
|
20
|
-
import "core-js/modules/es.array.concat.js";
|
|
21
|
-
import "core-js/modules/es.symbol.js";
|
|
22
|
-
import "core-js/modules/es.symbol.description.js";
|
|
23
|
-
import "core-js/modules/es.symbol.iterator.js";
|
|
24
|
-
import "core-js/modules/es.array.slice.js";
|
|
25
|
-
import "core-js/modules/es.array.from.js";
|
|
26
|
-
import "core-js/modules/es.regexp.exec.js";
|
|
27
1
|
import React, { useContext, useRef, useEffect, useState } from 'react';
|
|
28
2
|
import { MDXProvider } from '@mdx-js/react';
|
|
29
3
|
import global from 'global';
|
|
@@ -34,48 +8,51 @@ import Events from '@storybook/core-events';
|
|
|
34
8
|
import { CURRENT_SELECTION } from './types';
|
|
35
9
|
import { DocsContext } from './DocsContext';
|
|
36
10
|
import { useStory } from './useStory';
|
|
37
|
-
export
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
var inputId = id === CURRENT_SELECTION ? context.id : id;
|
|
11
|
+
export const storyBlockIdFromId = storyId => `story--${storyId}`;
|
|
12
|
+
export const lookupStoryId = (storyName, {
|
|
13
|
+
mdxStoryNameToKey,
|
|
14
|
+
mdxComponentAnnotations
|
|
15
|
+
}) => toId(mdxComponentAnnotations.id || mdxComponentAnnotations.title, storyNameFromExport(mdxStoryNameToKey[storyName]));
|
|
16
|
+
export const getStoryId = (props, context) => {
|
|
17
|
+
const {
|
|
18
|
+
id
|
|
19
|
+
} = props;
|
|
20
|
+
const {
|
|
21
|
+
name
|
|
22
|
+
} = props;
|
|
23
|
+
const inputId = id === CURRENT_SELECTION ? context.id : id;
|
|
51
24
|
return inputId || lookupStoryId(name, context);
|
|
52
25
|
};
|
|
53
|
-
export
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
26
|
+
export const getStoryProps = ({
|
|
27
|
+
height,
|
|
28
|
+
inline
|
|
29
|
+
}, story, context, onStoryFnCalled) => {
|
|
30
|
+
const {
|
|
31
|
+
name: storyName,
|
|
32
|
+
parameters
|
|
33
|
+
} = story;
|
|
34
|
+
const {
|
|
35
|
+
docs = {}
|
|
36
|
+
} = parameters;
|
|
60
37
|
|
|
61
38
|
if (docs.disable) {
|
|
62
39
|
return null;
|
|
63
40
|
} // prefer block props, then story parameters defined by the framework-specific settings and optionally overridden by users
|
|
64
41
|
|
|
65
42
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
43
|
+
const {
|
|
44
|
+
inlineStories = false,
|
|
45
|
+
iframeHeight = 100,
|
|
46
|
+
prepareForInline
|
|
47
|
+
} = docs;
|
|
48
|
+
const storyIsInline = typeof inline === 'boolean' ? inline : inlineStories;
|
|
72
49
|
|
|
73
50
|
if (storyIsInline && !prepareForInline) {
|
|
74
|
-
throw new Error(
|
|
51
|
+
throw new Error(`Story '${storyName}' is set to render inline, but no 'prepareForInline' function is implemented in your docs configuration!`);
|
|
75
52
|
}
|
|
76
53
|
|
|
77
|
-
|
|
78
|
-
|
|
54
|
+
const boundStoryFn = () => {
|
|
55
|
+
const storyResult = story.unboundStoryFn(Object.assign({}, context.getStoryContext(story), {
|
|
79
56
|
loaded: {},
|
|
80
57
|
abortSignal: undefined,
|
|
81
58
|
canvasElement: undefined
|
|
@@ -94,76 +71,56 @@ export var getStoryProps = function getStoryProps(_ref4, story, context, onStory
|
|
|
94
71
|
height: height || (storyIsInline ? undefined : iframeHeight),
|
|
95
72
|
title: storyName
|
|
96
73
|
}, storyIsInline && {
|
|
97
|
-
parameters
|
|
98
|
-
storyFn:
|
|
99
|
-
return prepareForInline(boundStoryFn, context.getStoryContext(story));
|
|
100
|
-
}
|
|
74
|
+
parameters,
|
|
75
|
+
storyFn: () => prepareForInline(boundStoryFn, context.getStoryContext(story))
|
|
101
76
|
});
|
|
102
77
|
};
|
|
103
78
|
|
|
104
79
|
function makeGate() {
|
|
105
|
-
|
|
106
|
-
|
|
80
|
+
let open;
|
|
81
|
+
const gate = new Promise(r => {
|
|
107
82
|
open = r;
|
|
108
83
|
});
|
|
109
84
|
return [gate, open];
|
|
110
85
|
}
|
|
111
86
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
showLoader = _useState2[0],
|
|
122
|
-
setShowLoader = _useState2[1];
|
|
123
|
-
|
|
124
|
-
useEffect(function () {
|
|
125
|
-
var cleanup;
|
|
87
|
+
const Story = props => {
|
|
88
|
+
const context = useContext(DocsContext);
|
|
89
|
+
const channel = addons.getChannel();
|
|
90
|
+
const storyRef = useRef();
|
|
91
|
+
const storyId = getStoryId(props, context);
|
|
92
|
+
const story = useStory(storyId, context);
|
|
93
|
+
const [showLoader, setShowLoader] = useState(true);
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
let cleanup;
|
|
126
96
|
|
|
127
97
|
if (story && storyRef.current) {
|
|
128
|
-
|
|
98
|
+
const element = storyRef.current;
|
|
129
99
|
cleanup = context.renderStoryToElement(story, element);
|
|
130
100
|
setShowLoader(false);
|
|
131
101
|
}
|
|
132
102
|
|
|
133
|
-
return
|
|
134
|
-
return cleanup && cleanup();
|
|
135
|
-
};
|
|
103
|
+
return () => cleanup && cleanup();
|
|
136
104
|
}, [story]);
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
_makeGate2 = _slicedToArray(_makeGate, 2),
|
|
140
|
-
storyFnRan = _makeGate2[0],
|
|
141
|
-
onStoryFnRan = _makeGate2[1];
|
|
142
|
-
|
|
143
|
-
var _makeGate3 = makeGate(),
|
|
144
|
-
_makeGate4 = _slicedToArray(_makeGate3, 2),
|
|
145
|
-
rendered = _makeGate4[0],
|
|
146
|
-
onRendered = _makeGate4[1];
|
|
147
|
-
|
|
105
|
+
const [storyFnRan, onStoryFnRan] = makeGate();
|
|
106
|
+
const [rendered, onRendered] = makeGate();
|
|
148
107
|
useEffect(onRendered);
|
|
149
108
|
|
|
150
109
|
if (!story) {
|
|
151
110
|
return /*#__PURE__*/React.createElement(StorySkeleton, null);
|
|
152
111
|
}
|
|
153
112
|
|
|
154
|
-
|
|
113
|
+
const storyProps = getStoryProps(props, story, context, onStoryFnRan);
|
|
155
114
|
|
|
156
115
|
if (!storyProps) {
|
|
157
116
|
return null;
|
|
158
117
|
}
|
|
159
118
|
|
|
160
119
|
if (storyProps.inline) {
|
|
161
|
-
var _global$FEATURES;
|
|
162
|
-
|
|
163
120
|
// If we are rendering a old-style inline Story via `PureStory` below, we want to emit
|
|
164
121
|
// the `STORY_RENDERED` event when it renders. The modern mode below calls out to
|
|
165
122
|
// `Preview.renderStoryToDom()` which itself emits the event.
|
|
166
|
-
if (!
|
|
123
|
+
if (!global?.FEATURES?.modernInlineRender) {
|
|
167
124
|
// We need to wait for two things before we can consider the story rendered:
|
|
168
125
|
// (a) React's `useEffect` hook needs to fire. This is needed for React stories, as
|
|
169
126
|
// decorators of the form `<A><B/></A>` will not actually execute `B` in the first
|
|
@@ -171,19 +128,21 @@ var Story = function Story(props) {
|
|
|
171
128
|
// (b) The story function needs to actually have been called.
|
|
172
129
|
// Certain frameworks (i.e.angular) don't actually render the component in the very first
|
|
173
130
|
// React render cycle, so we need to wait for the framework to actually do that
|
|
174
|
-
Promise.all([storyFnRan, rendered]).then(
|
|
131
|
+
Promise.all([storyFnRan, rendered]).then(() => {
|
|
175
132
|
channel.emit(Events.STORY_RENDERED, storyId);
|
|
176
133
|
});
|
|
177
134
|
} else {
|
|
178
135
|
// We do this so React doesn't complain when we replace the span in a secondary render
|
|
179
|
-
|
|
136
|
+
const htmlContents = `<span></span>`; // FIXME: height/style/etc. lifted from PureStory
|
|
180
137
|
|
|
181
|
-
|
|
138
|
+
const {
|
|
139
|
+
height
|
|
140
|
+
} = storyProps;
|
|
182
141
|
return /*#__PURE__*/React.createElement("div", {
|
|
183
142
|
id: storyBlockIdFromId(story.id)
|
|
184
143
|
}, /*#__PURE__*/React.createElement(MDXProvider, {
|
|
185
144
|
components: resetComponents
|
|
186
|
-
}, height ? /*#__PURE__*/React.createElement("style", null,
|
|
145
|
+
}, 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", {
|
|
187
146
|
ref: storyRef,
|
|
188
147
|
"data-name": story.name,
|
|
189
148
|
dangerouslySetInnerHTML: {
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import "core-js/modules/es.regexp.exec.js";
|
|
2
|
-
import "core-js/modules/es.string.replace.js";
|
|
3
1
|
import React from 'react';
|
|
4
2
|
import { H3 } from '@storybook/components';
|
|
5
3
|
import { HeaderMdx } from './mdx';
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
export const Subheading = ({
|
|
5
|
+
children,
|
|
6
|
+
disableAnchor
|
|
7
|
+
}) => {
|
|
10
8
|
if (disableAnchor || typeof children !== 'string') {
|
|
11
9
|
return /*#__PURE__*/React.createElement(H3, null, children);
|
|
12
10
|
}
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
const tagID = children.toLowerCase().replace(/[^a-z0-9]/gi, '-');
|
|
15
13
|
return /*#__PURE__*/React.createElement(HeaderMdx, {
|
|
16
14
|
as: "h3",
|
|
17
15
|
id: tagID
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import React, { useContext } from 'react';
|
|
2
2
|
import { Subtitle as PureSubtitle } from '@storybook/components';
|
|
3
3
|
import { DocsContext } from './DocsContext';
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
15
|
|
|
16
16
|
if (!text) {
|
|
17
|
-
text = parameters
|
|
17
|
+
text = parameters?.componentSubtitle;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
return text ? /*#__PURE__*/React.createElement(PureSubtitle, {
|