@storybook/addon-docs 6.5.9 → 7.0.0-alpha.2
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/Anchor.js +7 -10
- package/dist/cjs/blocks/ArgsTable.js +135 -206
- package/dist/cjs/blocks/Canvas.js +38 -73
- package/dist/cjs/blocks/Description.js +41 -68
- package/dist/cjs/blocks/DocsContainer.js +40 -68
- package/dist/cjs/blocks/DocsContext.js +1 -1
- package/dist/cjs/blocks/DocsPage.js +3 -5
- package/dist/cjs/blocks/DocsStory.js +18 -28
- package/dist/cjs/blocks/Heading.js +5 -9
- package/dist/cjs/blocks/Meta.js +11 -33
- package/dist/cjs/blocks/Preview.js +4 -10
- package/dist/cjs/blocks/Primary.js +12 -40
- package/dist/cjs/blocks/Props.js +4 -10
- package/dist/cjs/blocks/Source.js +62 -80
- package/dist/cjs/blocks/SourceContainer.js +19 -68
- package/dist/cjs/blocks/Stories.js +17 -48
- package/dist/cjs/blocks/Story.js +60 -180
- package/dist/cjs/blocks/Subheading.js +5 -9
- package/dist/cjs/blocks/Subtitle.js +15 -35
- package/dist/cjs/blocks/Title.js +12 -36
- package/dist/cjs/blocks/Wrapper.js +7 -8
- package/dist/cjs/blocks/enhanceSource.js +30 -67
- package/dist/cjs/blocks/index.js +28 -34
- package/dist/cjs/blocks/mdx.js +86 -97
- package/dist/cjs/blocks/types.js +2 -2
- package/dist/cjs/blocks/useStory.js +16 -87
- package/dist/cjs/blocks/utils.js +4 -25
- package/dist/cjs/index.js +1 -7
- package/dist/cjs/manager.js +9 -15
- package/dist/cjs/preset.js +129 -193
- package/dist/cjs/preview.js +5 -87
- package/dist/cjs/shared.js +5 -5
- 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 -151
- 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 +2 -2
- 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 +17 -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,196 +1,103 @@
|
|
|
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
|
-
import global from 'global';
|
|
30
3
|
import { resetComponents, Story as PureStory, StorySkeleton } from '@storybook/components';
|
|
31
4
|
import { toId, storyNameFromExport } from '@storybook/csf';
|
|
32
|
-
import { addons } from '@storybook/addons';
|
|
33
|
-
import Events from '@storybook/core-events';
|
|
34
5
|
import { CURRENT_SELECTION } from './types';
|
|
35
6
|
import { DocsContext } from './DocsContext';
|
|
36
7
|
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;
|
|
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;
|
|
51
21
|
return inputId || lookupStoryId(name, context);
|
|
52
22
|
};
|
|
53
|
-
export
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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;
|
|
60
34
|
|
|
61
35
|
if (docs.disable) {
|
|
62
36
|
return null;
|
|
63
37
|
} // prefer block props, then story parameters defined by the framework-specific settings and optionally overridden by users
|
|
64
38
|
|
|
65
39
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
var storyIsInline = typeof inline === 'boolean' ? inline : inlineStories;
|
|
72
|
-
|
|
73
|
-
if (storyIsInline && !prepareForInline) {
|
|
74
|
-
throw new Error("Story '".concat(storyName, "' is set to render inline, but no 'prepareForInline' function is implemented in your docs configuration!"));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
var boundStoryFn = function boundStoryFn() {
|
|
78
|
-
var storyResult = story.unboundStoryFn(Object.assign({}, context.getStoryContext(story), {
|
|
79
|
-
loaded: {},
|
|
80
|
-
abortSignal: undefined,
|
|
81
|
-
canvasElement: undefined
|
|
82
|
-
})); // We need to wait until the bound story function has actually been called before we
|
|
83
|
-
// consider the story rendered. Certain frameworks (i.e. angular) don't actually render
|
|
84
|
-
// the component in the very first react render cycle, and so we can't just wait until the
|
|
85
|
-
// `PureStory` component has been rendered to consider the underlying story "rendered".
|
|
86
|
-
|
|
87
|
-
onStoryFnCalled();
|
|
88
|
-
return storyResult;
|
|
89
|
-
};
|
|
90
|
-
|
|
40
|
+
const {
|
|
41
|
+
inlineStories = false,
|
|
42
|
+
iframeHeight = 100
|
|
43
|
+
} = docs;
|
|
44
|
+
const storyIsInline = typeof inline === 'boolean' ? inline : inlineStories;
|
|
91
45
|
return Object.assign({
|
|
92
46
|
inline: storyIsInline,
|
|
93
47
|
id: story.id,
|
|
94
48
|
height: height || (storyIsInline ? undefined : iframeHeight),
|
|
95
49
|
title: storyName
|
|
96
50
|
}, storyIsInline && {
|
|
97
|
-
parameters
|
|
98
|
-
storyFn: function storyFn() {
|
|
99
|
-
return prepareForInline(boundStoryFn, context.getStoryContext(story));
|
|
100
|
-
}
|
|
51
|
+
parameters
|
|
101
52
|
});
|
|
102
53
|
};
|
|
103
54
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
var Story = function Story(props) {
|
|
113
|
-
var context = useContext(DocsContext);
|
|
114
|
-
var channel = addons.getChannel();
|
|
115
|
-
var storyRef = useRef();
|
|
116
|
-
var storyId = getStoryId(props, context);
|
|
117
|
-
var story = useStory(storyId, context);
|
|
118
|
-
|
|
119
|
-
var _useState = useState(true),
|
|
120
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
121
|
-
showLoader = _useState2[0],
|
|
122
|
-
setShowLoader = _useState2[1];
|
|
123
|
-
|
|
124
|
-
useEffect(function () {
|
|
125
|
-
var cleanup;
|
|
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;
|
|
126
63
|
|
|
127
64
|
if (story && storyRef.current) {
|
|
128
|
-
|
|
65
|
+
const element = storyRef.current;
|
|
129
66
|
cleanup = context.renderStoryToElement(story, element);
|
|
130
67
|
setShowLoader(false);
|
|
131
68
|
}
|
|
132
69
|
|
|
133
|
-
return
|
|
134
|
-
return cleanup && cleanup();
|
|
135
|
-
};
|
|
70
|
+
return () => cleanup && cleanup();
|
|
136
71
|
}, [story]);
|
|
137
72
|
|
|
138
|
-
var _makeGate = makeGate(),
|
|
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
|
-
|
|
148
|
-
useEffect(onRendered);
|
|
149
|
-
|
|
150
73
|
if (!story) {
|
|
151
74
|
return /*#__PURE__*/React.createElement(StorySkeleton, null);
|
|
152
75
|
}
|
|
153
76
|
|
|
154
|
-
|
|
77
|
+
const storyProps = getStoryProps(props, story);
|
|
155
78
|
|
|
156
79
|
if (!storyProps) {
|
|
157
80
|
return null;
|
|
158
81
|
}
|
|
159
82
|
|
|
160
83
|
if (storyProps.inline) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
// We do this so React doesn't complain when we replace the span in a secondary render
|
|
179
|
-
var htmlContents = "<span></span>"; // FIXME: height/style/etc. lifted from PureStory
|
|
180
|
-
|
|
181
|
-
var height = storyProps.height;
|
|
182
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
183
|
-
id: storyBlockIdFromId(story.id)
|
|
184
|
-
}, /*#__PURE__*/React.createElement(MDXProvider, {
|
|
185
|
-
components: resetComponents
|
|
186
|
-
}, height ? /*#__PURE__*/React.createElement("style", null, "#story--".concat(story.id, " { min-height: ").concat(height, "; transform: translateZ(0); overflow: auto }")) : null, showLoader && /*#__PURE__*/React.createElement(StorySkeleton, null), /*#__PURE__*/React.createElement("div", {
|
|
187
|
-
ref: storyRef,
|
|
188
|
-
"data-name": story.name,
|
|
189
|
-
dangerouslySetInnerHTML: {
|
|
190
|
-
__html: htmlContents
|
|
191
|
-
}
|
|
192
|
-
})));
|
|
193
|
-
}
|
|
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
|
+
})));
|
|
194
101
|
}
|
|
195
102
|
|
|
196
103
|
return /*#__PURE__*/React.createElement("div", {
|
|
@@ -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
|