@storybook/addon-docs 7.0.0-alpha.5 → 7.0.0-alpha.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/README.md +14 -77
  2. package/angular/index.js +1 -1
  3. package/dist/DocsRenderer-MHI45CTG.mjs +1 -0
  4. package/dist/chunk-HKSD7XQF.mjs +1 -0
  5. package/dist/chunk-WMY67HY3.mjs +1 -0
  6. package/dist/index.d.ts +11 -0
  7. package/dist/index.js +1 -0
  8. package/dist/index.mjs +1 -0
  9. package/dist/preset.d.ts +5 -0
  10. package/dist/preset.js +7 -0
  11. package/dist/preset.mjs +7 -0
  12. package/dist/preview.d.ts +3 -0
  13. package/dist/preview.js +1 -0
  14. package/dist/preview.mjs +1 -0
  15. package/jest-transform-mdx.js +4 -3
  16. package/jest.config.js +7 -0
  17. package/package.json +65 -38
  18. package/preset.js +1 -1
  19. package/preview.js +1 -1
  20. package/web-components/README.md +1 -0
  21. package/LICENSE +0 -21
  22. package/blocks.d.ts +0 -2
  23. package/blocks.js +0 -14
  24. package/dist/cjs/blocks/Anchor.js +0 -23
  25. package/dist/cjs/blocks/ArgsTable.js +0 -329
  26. package/dist/cjs/blocks/Canvas.js +0 -109
  27. package/dist/cjs/blocks/Description.js +0 -126
  28. package/dist/cjs/blocks/DocsContainer.js +0 -127
  29. package/dist/cjs/blocks/DocsContext.js +0 -25
  30. package/dist/cjs/blocks/DocsPage.js +0 -30
  31. package/dist/cjs/blocks/DocsStory.js +0 -68
  32. package/dist/cjs/blocks/Heading.js +0 -31
  33. package/dist/cjs/blocks/Meta.js +0 -50
  34. package/dist/cjs/blocks/Preview.js +0 -23
  35. package/dist/cjs/blocks/Primary.js +0 -39
  36. package/dist/cjs/blocks/Props.js +0 -29
  37. package/dist/cjs/blocks/Source.js +0 -179
  38. package/dist/cjs/blocks/SourceContainer.js +0 -67
  39. package/dist/cjs/blocks/Stories.js +0 -51
  40. package/dist/cjs/blocks/Story.js +0 -143
  41. package/dist/cjs/blocks/Subheading.js +0 -31
  42. package/dist/cjs/blocks/Subtitle.js +0 -39
  43. package/dist/cjs/blocks/Title.js +0 -44
  44. package/dist/cjs/blocks/Wrapper.js +0 -20
  45. package/dist/cjs/blocks/enhanceSource.js +0 -92
  46. package/dist/cjs/blocks/index.js +0 -366
  47. package/dist/cjs/blocks/mdx.js +0 -234
  48. package/dist/cjs/blocks/types.js +0 -10
  49. package/dist/cjs/blocks/useStory.js +0 -37
  50. package/dist/cjs/blocks/utils.js +0 -40
  51. package/dist/cjs/index.js +0 -18
  52. package/dist/cjs/manager.js +0 -20
  53. package/dist/cjs/preset.js +0 -162
  54. package/dist/cjs/preview.js +0 -18
  55. package/dist/cjs/shared.js +0 -22
  56. package/dist/esm/blocks/Anchor.js +0 -8
  57. package/dist/esm/blocks/ArgsTable.js +0 -292
  58. package/dist/esm/blocks/Canvas.js +0 -83
  59. package/dist/esm/blocks/Description.js +0 -107
  60. package/dist/esm/blocks/DocsContainer.js +0 -98
  61. package/dist/esm/blocks/DocsContext.js +0 -16
  62. package/dist/esm/blocks/DocsPage.js +0 -11
  63. package/dist/esm/blocks/DocsStory.js +0 -46
  64. package/dist/esm/blocks/Heading.js +0 -17
  65. package/dist/esm/blocks/Meta.js +0 -31
  66. package/dist/esm/blocks/Preview.js +0 -9
  67. package/dist/esm/blocks/Primary.js +0 -23
  68. package/dist/esm/blocks/Props.js +0 -14
  69. package/dist/esm/blocks/Source.js +0 -144
  70. package/dist/esm/blocks/SourceContainer.js +0 -44
  71. package/dist/esm/blocks/Stories.js +0 -30
  72. package/dist/esm/blocks/Story.js +0 -114
  73. package/dist/esm/blocks/Subheading.js +0 -17
  74. package/dist/esm/blocks/Subtitle.js +0 -23
  75. package/dist/esm/blocks/Title.js +0 -24
  76. package/dist/esm/blocks/Wrapper.js +0 -8
  77. package/dist/esm/blocks/enhanceSource.js +0 -87
  78. package/dist/esm/blocks/index.js +0 -24
  79. package/dist/esm/blocks/mdx.js +0 -203
  80. package/dist/esm/blocks/types.js +0 -2
  81. package/dist/esm/blocks/useStory.js +0 -27
  82. package/dist/esm/blocks/utils.js +0 -29
  83. package/dist/esm/index.js +0 -1
  84. package/dist/esm/manager.js +0 -16
  85. package/dist/esm/preset.js +0 -132
  86. package/dist/esm/preview.js +0 -6
  87. package/dist/esm/shared.js +0 -11
  88. package/dist/types/blocks/Anchor.d.ts +0 -6
  89. package/dist/types/blocks/ArgsTable.d.ts +0 -33
  90. package/dist/types/blocks/Canvas.d.ts +0 -9
  91. package/dist/types/blocks/Description.d.ts +0 -20
  92. package/dist/types/blocks/DocsContainer.d.ts +0 -7
  93. package/dist/types/blocks/DocsContext.d.ts +0 -5
  94. package/dist/types/blocks/DocsPage.d.ts +0 -2
  95. package/dist/types/blocks/DocsStory.d.ts +0 -3
  96. package/dist/types/blocks/Heading.d.ts +0 -6
  97. package/dist/types/blocks/Meta.d.ts +0 -9
  98. package/dist/types/blocks/Preview.d.ts +0 -3
  99. package/dist/types/blocks/Primary.d.ts +0 -6
  100. package/dist/types/blocks/Props.d.ts +0 -3
  101. package/dist/types/blocks/Source.d.ts +0 -38
  102. package/dist/types/blocks/SourceContainer.d.ts +0 -14
  103. package/dist/types/blocks/Stories.d.ts +0 -7
  104. package/dist/types/blocks/Story.d.ts +0 -28
  105. package/dist/types/blocks/Subheading.d.ts +0 -3
  106. package/dist/types/blocks/Subtitle.d.ts +0 -6
  107. package/dist/types/blocks/Title.d.ts +0 -8
  108. package/dist/types/blocks/Wrapper.d.ts +0 -2
  109. package/dist/types/blocks/enhanceSource.d.ts +0 -3
  110. package/dist/types/blocks/index.d.ts +0 -24
  111. package/dist/types/blocks/mdx.d.ts +0 -20
  112. package/dist/types/blocks/types.d.ts +0 -13
  113. package/dist/types/blocks/useStory.d.ts +0 -5
  114. package/dist/types/blocks/utils.d.ts +0 -3
  115. package/dist/types/index.d.ts +0 -1
  116. package/dist/types/manager.d.ts +0 -1
  117. package/dist/types/preset.d.ts +0 -12
  118. package/dist/types/preview.d.ts +0 -6
  119. package/dist/types/shared.d.ts +0 -24
  120. package/manager.js +0 -1
  121. package/mdx-compiler-plugin.js +0 -1
  122. package/register.js +0 -6
@@ -1,143 +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
- } = props;
41
- const {
42
- name
43
- } = props;
44
- const inputId = id === _types.CURRENT_SELECTION ? context.id : id;
45
- return inputId || lookupStoryId(name, context);
46
- };
47
-
48
- exports.getStoryId = getStoryId;
49
-
50
- const getStoryProps = ({
51
- height,
52
- inline
53
- }, story) => {
54
- const {
55
- name: storyName,
56
- parameters
57
- } = story;
58
- const {
59
- docs = {}
60
- } = parameters;
61
-
62
- if (docs.disable) {
63
- return null;
64
- } // prefer block props, then story parameters defined by the framework-specific settings and optionally overridden by users
65
-
66
-
67
- const {
68
- inlineStories = false,
69
- iframeHeight = 100
70
- } = docs;
71
- const storyIsInline = typeof inline === 'boolean' ? inline : inlineStories;
72
- return Object.assign({
73
- inline: storyIsInline,
74
- id: story.id,
75
- height: height || (storyIsInline ? undefined : iframeHeight),
76
- title: storyName
77
- }, storyIsInline && {
78
- parameters
79
- });
80
- };
81
-
82
- exports.getStoryProps = getStoryProps;
83
-
84
- const Story = props => {
85
- const context = (0, _react.useContext)(_DocsContext.DocsContext);
86
- const storyRef = (0, _react.useRef)();
87
- const storyId = getStoryId(props, context);
88
- const story = (0, _useStory.useStory)(storyId, context);
89
- const [showLoader, setShowLoader] = (0, _react.useState)(true);
90
- (0, _react.useEffect)(() => {
91
- let cleanup;
92
-
93
- if (story && storyRef.current) {
94
- const element = storyRef.current;
95
- cleanup = context.renderStoryToElement(story, element);
96
- setShowLoader(false);
97
- }
98
-
99
- return () => cleanup && cleanup();
100
- }, [story]);
101
-
102
- if (!story) {
103
- return /*#__PURE__*/_react.default.createElement(_components.StorySkeleton, null);
104
- }
105
-
106
- const storyProps = getStoryProps(props, story);
107
-
108
- if (!storyProps) {
109
- return null;
110
- }
111
-
112
- if (storyProps.inline) {
113
- // We do this so React doesn't complain when we replace the span in a secondary render
114
- const htmlContents = `<span></span>`; // FIXME: height/style/etc. lifted from PureStory
115
-
116
- const {
117
- height
118
- } = storyProps;
119
- return /*#__PURE__*/_react.default.createElement("div", {
120
- id: storyBlockIdFromId(story.id)
121
- }, /*#__PURE__*/_react.default.createElement(_react2.MDXProvider, {
122
- components: _components.resetComponents
123
- }, height ? /*#__PURE__*/_react.default.createElement("style", null, `#story--${story.id} { min-height: ${height}; transform: translateZ(0); overflow: auto }`) : null, showLoader && /*#__PURE__*/_react.default.createElement(_components.StorySkeleton, null), /*#__PURE__*/_react.default.createElement("div", {
124
- ref: storyRef,
125
- "data-name": story.name,
126
- dangerouslySetInnerHTML: {
127
- __html: htmlContents
128
- }
129
- })));
130
- }
131
-
132
- return /*#__PURE__*/_react.default.createElement("div", {
133
- id: storyBlockIdFromId(story.id)
134
- }, /*#__PURE__*/_react.default.createElement(_react2.MDXProvider, {
135
- components: _components.resetComponents
136
- }, /*#__PURE__*/_react.default.createElement(_components.Story, storyProps)));
137
- };
138
-
139
- exports.Story = Story;
140
- Story.defaultProps = {
141
- children: null,
142
- name: null
143
- };
@@ -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 === null || parameters === void 0 ? void 0 : 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,92 +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
- var _docs$source;
64
-
65
- const {
66
- id,
67
- parameters
68
- } = story;
69
- const {
70
- storySource,
71
- docs = {}
72
- } = parameters;
73
- const {
74
- transformSource
75
- } = docs; // no input or user has manually overridden the output
76
-
77
- if (!(storySource !== null && storySource !== void 0 && storySource.source) || (_docs$source = docs.source) !== null && _docs$source !== void 0 && _docs$source.code) {
78
- return null;
79
- }
80
-
81
- const input = extract(id, storySource);
82
- const code = transformSource ? transformSource(input, story) : input;
83
- return {
84
- docs: (0, _store.combineParameters)(docs, {
85
- source: {
86
- code
87
- }
88
- })
89
- };
90
- };
91
-
92
- exports.enhanceSource = enhanceSource;