@storybook/addon-docs 6.5.9 → 7.0.0-alpha.10
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/index.js +5 -359
- package/dist/cjs/index.js +1 -7
- package/dist/cjs/manager.js +9 -15
- package/dist/cjs/preset.js +121 -193
- package/dist/cjs/preview.js +9 -87
- package/dist/cjs/shared.js +5 -5
- package/dist/esm/blocks/index.js +1 -24
- package/dist/esm/manager.js +9 -14
- package/dist/esm/preset.js +114 -179
- package/dist/esm/preview.js +7 -61
- package/dist/esm/shared.js +5 -5
- package/dist/types/blocks/index.d.ts +1 -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/types/preview.d.ts +1 -0
- package/dist/{ts3.9 → types}/shared.d.ts +0 -0
- package/package.json +18 -25
- package/dist/cjs/blocks/Anchor.js +0 -26
- package/dist/cjs/blocks/ArgsTable.js +0 -400
- package/dist/cjs/blocks/Canvas.js +0 -144
- package/dist/cjs/blocks/Description.js +0 -153
- package/dist/cjs/blocks/DocsContainer.js +0 -155
- package/dist/cjs/blocks/DocsContext.js +0 -25
- package/dist/cjs/blocks/DocsPage.js +0 -32
- package/dist/cjs/blocks/DocsStory.js +0 -78
- package/dist/cjs/blocks/Heading.js +0 -35
- package/dist/cjs/blocks/Meta.js +0 -72
- package/dist/cjs/blocks/Preview.js +0 -29
- package/dist/cjs/blocks/Primary.js +0 -67
- package/dist/cjs/blocks/Props.js +0 -35
- package/dist/cjs/blocks/Source.js +0 -197
- package/dist/cjs/blocks/SourceContainer.js +0 -116
- package/dist/cjs/blocks/Stories.js +0 -82
- package/dist/cjs/blocks/Story.js +0 -263
- package/dist/cjs/blocks/Subheading.js +0 -35
- package/dist/cjs/blocks/Subtitle.js +0 -59
- package/dist/cjs/blocks/Title.js +0 -68
- package/dist/cjs/blocks/Wrapper.js +0 -21
- package/dist/cjs/blocks/enhanceSource.js +0 -129
- package/dist/cjs/blocks/mdx.js +0 -245
- package/dist/cjs/blocks/types.js +0 -10
- package/dist/cjs/blocks/useStory.js +0 -108
- package/dist/cjs/blocks/utils.js +0 -61
- package/dist/esm/blocks/Anchor.js +0 -11
- package/dist/esm/blocks/ArgsTable.js +0 -341
- package/dist/esm/blocks/Canvas.js +0 -95
- package/dist/esm/blocks/Description.js +0 -113
- package/dist/esm/blocks/DocsContainer.js +0 -106
- package/dist/esm/blocks/DocsContext.js +0 -16
- package/dist/esm/blocks/DocsPage.js +0 -13
- package/dist/esm/blocks/DocsStory.js +0 -55
- package/dist/esm/blocks/Heading.js +0 -19
- package/dist/esm/blocks/Meta.js +0 -35
- package/dist/esm/blocks/Preview.js +0 -14
- package/dist/esm/blocks/Primary.js +0 -29
- package/dist/esm/blocks/Props.js +0 -19
- package/dist/esm/blocks/Source.js +0 -150
- package/dist/esm/blocks/SourceContainer.js +0 -77
- package/dist/esm/blocks/Stories.js +0 -42
- package/dist/esm/blocks/Story.js +0 -207
- package/dist/esm/blocks/Subheading.js +0 -19
- package/dist/esm/blocks/Subtitle.js +0 -23
- package/dist/esm/blocks/Title.js +0 -25
- package/dist/esm/blocks/Wrapper.js +0 -9
- package/dist/esm/blocks/enhanceSource.js +0 -111
- package/dist/esm/blocks/mdx.js +0 -207
- package/dist/esm/blocks/types.js +0 -2
- package/dist/esm/blocks/useStory.js +0 -84
- package/dist/esm/blocks/utils.js +0 -43
- 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
- package/dist/ts3.9/blocks/Anchor.d.ts +0 -6
- package/dist/ts3.9/blocks/ArgsTable.d.ts +0 -33
- package/dist/ts3.9/blocks/Canvas.d.ts +0 -9
- package/dist/ts3.9/blocks/Description.d.ts +0 -20
- package/dist/ts3.9/blocks/DocsContainer.d.ts +0 -7
- package/dist/ts3.9/blocks/DocsContext.d.ts +0 -5
- package/dist/ts3.9/blocks/DocsPage.d.ts +0 -2
- package/dist/ts3.9/blocks/DocsStory.d.ts +0 -3
- package/dist/ts3.9/blocks/Heading.d.ts +0 -6
- package/dist/ts3.9/blocks/Meta.d.ts +0 -9
- package/dist/ts3.9/blocks/Preview.d.ts +0 -3
- package/dist/ts3.9/blocks/Primary.d.ts +0 -6
- package/dist/ts3.9/blocks/Props.d.ts +0 -3
- package/dist/ts3.9/blocks/Source.d.ts +0 -38
- package/dist/ts3.9/blocks/SourceContainer.d.ts +0 -14
- package/dist/ts3.9/blocks/Stories.d.ts +0 -7
- package/dist/ts3.9/blocks/Story.d.ts +0 -28
- package/dist/ts3.9/blocks/Subheading.d.ts +0 -3
- package/dist/ts3.9/blocks/Subtitle.d.ts +0 -6
- package/dist/ts3.9/blocks/Title.d.ts +0 -8
- package/dist/ts3.9/blocks/Wrapper.d.ts +0 -2
- package/dist/ts3.9/blocks/enhanceSource.d.ts +0 -3
- package/dist/ts3.9/blocks/index.d.ts +0 -24
- package/dist/ts3.9/blocks/mdx.d.ts +0 -20
- package/dist/ts3.9/blocks/types.d.ts +0 -13
- package/dist/ts3.9/blocks/useStory.d.ts +0 -5
- package/dist/ts3.9/blocks/utils.d.ts +0 -3
- package/dist/ts3.9/preview.d.ts +0 -6
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import "regenerator-runtime/runtime.js";
|
|
2
|
-
|
|
3
|
-
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; }
|
|
4
|
-
|
|
5
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
6
|
-
|
|
7
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
8
|
-
|
|
9
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
10
|
-
|
|
11
|
-
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."); }
|
|
12
|
-
|
|
13
|
-
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); }
|
|
14
|
-
|
|
15
|
-
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; }
|
|
16
|
-
|
|
17
|
-
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; }
|
|
18
|
-
|
|
19
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
20
|
-
|
|
21
|
-
import "core-js/modules/es.object.to-string.js";
|
|
22
|
-
import "core-js/modules/es.array.iterator.js";
|
|
23
|
-
import "core-js/modules/es.promise.js";
|
|
24
|
-
import "core-js/modules/es.string.iterator.js";
|
|
25
|
-
import "core-js/modules/web.dom-collections.iterator.js";
|
|
26
|
-
import "core-js/modules/es.array.map.js";
|
|
27
|
-
import "core-js/modules/es.object.assign.js";
|
|
28
|
-
import "core-js/modules/es.symbol.js";
|
|
29
|
-
import "core-js/modules/es.symbol.description.js";
|
|
30
|
-
import "core-js/modules/es.symbol.iterator.js";
|
|
31
|
-
import "core-js/modules/es.array.slice.js";
|
|
32
|
-
import "core-js/modules/es.function.name.js";
|
|
33
|
-
import "core-js/modules/es.array.from.js";
|
|
34
|
-
import "core-js/modules/es.regexp.exec.js";
|
|
35
|
-
import { useState, useEffect } from 'react';
|
|
36
|
-
export function useStory(storyId, context) {
|
|
37
|
-
var stories = useStories([storyId], context);
|
|
38
|
-
return stories && stories[0];
|
|
39
|
-
}
|
|
40
|
-
export function useStories(storyIds, context) {
|
|
41
|
-
var initialStoriesById = context.componentStories().reduce(function (acc, story) {
|
|
42
|
-
acc[story.id] = story;
|
|
43
|
-
return acc;
|
|
44
|
-
}, {});
|
|
45
|
-
|
|
46
|
-
var _useState = useState(initialStoriesById),
|
|
47
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
48
|
-
storiesById = _useState2[0],
|
|
49
|
-
setStories = _useState2[1];
|
|
50
|
-
|
|
51
|
-
useEffect(function () {
|
|
52
|
-
Promise.all(storyIds.map( /*#__PURE__*/function () {
|
|
53
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(storyId) {
|
|
54
|
-
var story;
|
|
55
|
-
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
56
|
-
while (1) {
|
|
57
|
-
switch (_context.prev = _context.next) {
|
|
58
|
-
case 0:
|
|
59
|
-
_context.next = 2;
|
|
60
|
-
return context.loadStory(storyId);
|
|
61
|
-
|
|
62
|
-
case 2:
|
|
63
|
-
story = _context.sent;
|
|
64
|
-
setStories(function (current) {
|
|
65
|
-
return current[storyId] === story ? current : Object.assign({}, current, _defineProperty({}, storyId, story));
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
case 4:
|
|
69
|
-
case "end":
|
|
70
|
-
return _context.stop();
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}, _callee);
|
|
74
|
-
}));
|
|
75
|
-
|
|
76
|
-
return function (_x) {
|
|
77
|
-
return _ref.apply(this, arguments);
|
|
78
|
-
};
|
|
79
|
-
}()));
|
|
80
|
-
});
|
|
81
|
-
return storyIds.map(function (storyId) {
|
|
82
|
-
return storiesById[storyId];
|
|
83
|
-
});
|
|
84
|
-
}
|
package/dist/esm/blocks/utils.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import "core-js/modules/es.array.join.js";
|
|
2
|
-
import "core-js/modules/es.array.map.js";
|
|
3
|
-
import "core-js/modules/es.regexp.exec.js";
|
|
4
|
-
import "core-js/modules/es.string.split.js";
|
|
5
|
-
import "core-js/modules/es.array.slice.js";
|
|
6
|
-
import "core-js/modules/es.array.includes.js";
|
|
7
|
-
import "core-js/modules/es.string.includes.js";
|
|
8
|
-
import "core-js/modules/es.function.name.js";
|
|
9
|
-
|
|
10
|
-
/* eslint-disable no-underscore-dangle */
|
|
11
|
-
var titleCase = function titleCase(str) {
|
|
12
|
-
return str.split('-').map(function (part) {
|
|
13
|
-
return part.charAt(0).toUpperCase() + part.slice(1);
|
|
14
|
-
}).join('');
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export var getComponentName = function getComponentName(component) {
|
|
18
|
-
if (!component) {
|
|
19
|
-
return undefined;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (typeof component === 'string') {
|
|
23
|
-
if (component.includes('-')) {
|
|
24
|
-
return titleCase(component);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return component;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (component.__docgenInfo && component.__docgenInfo.displayName) {
|
|
31
|
-
return component.__docgenInfo.displayName;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return component.name;
|
|
35
|
-
};
|
|
36
|
-
export function scrollToElement(element) {
|
|
37
|
-
var block = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'start';
|
|
38
|
-
element.scrollIntoView({
|
|
39
|
-
behavior: 'smooth',
|
|
40
|
-
block: block,
|
|
41
|
-
inline: 'nearest'
|
|
42
|
-
});
|
|
43
|
-
}
|
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
function _extends() { _extends = Object.assign || 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
|
-
|
|
3
|
-
import React, { useContext, useEffect, useState, useCallback } from 'react';
|
|
4
|
-
import mapValues from 'lodash/mapValues';
|
|
5
|
-
import { ArgsTable as PureArgsTable, ArgsTableError, TabbedArgsTable } from '@storybook/components';
|
|
6
|
-
import { addons } from '@storybook/addons';
|
|
7
|
-
import { filterArgTypes } from '@storybook/store';
|
|
8
|
-
import Events from '@storybook/core-events';
|
|
9
|
-
import { DocsContext } from './DocsContext';
|
|
10
|
-
import { CURRENT_SELECTION, PRIMARY_STORY } from './types';
|
|
11
|
-
import { getComponentName } from './utils';
|
|
12
|
-
import { lookupStoryId } from './Story';
|
|
13
|
-
import { useStory } from './useStory';
|
|
14
|
-
|
|
15
|
-
const getContext = (storyId, context) => {
|
|
16
|
-
const story = context.storyById(storyId);
|
|
17
|
-
|
|
18
|
-
if (!story) {
|
|
19
|
-
throw new Error(`Unknown story: ${storyId}`);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return context.getStoryContext(story);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const useArgs = (storyId, context) => {
|
|
26
|
-
const channel = addons.getChannel();
|
|
27
|
-
const storyContext = getContext(storyId, context);
|
|
28
|
-
const [args, setArgs] = useState(storyContext.args);
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
const cb = changed => {
|
|
31
|
-
if (changed.storyId === storyId) {
|
|
32
|
-
setArgs(changed.args);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
channel.on(Events.STORY_ARGS_UPDATED, cb);
|
|
37
|
-
return () => channel.off(Events.STORY_ARGS_UPDATED, cb);
|
|
38
|
-
}, [storyId]);
|
|
39
|
-
const updateArgs = useCallback(updatedArgs => channel.emit(Events.UPDATE_STORY_ARGS, {
|
|
40
|
-
storyId,
|
|
41
|
-
updatedArgs
|
|
42
|
-
}), [storyId]);
|
|
43
|
-
const resetArgs = useCallback(argNames => channel.emit(Events.RESET_STORY_ARGS, {
|
|
44
|
-
storyId,
|
|
45
|
-
argNames
|
|
46
|
-
}), [storyId]);
|
|
47
|
-
return [args, updateArgs, resetArgs];
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const useGlobals = (storyId, context) => {
|
|
51
|
-
const channel = addons.getChannel();
|
|
52
|
-
const storyContext = getContext(storyId, context);
|
|
53
|
-
const [globals, setGlobals] = useState(storyContext.globals);
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
const cb = changed => {
|
|
56
|
-
setGlobals(changed.globals);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
channel.on(Events.GLOBALS_UPDATED, cb);
|
|
60
|
-
return () => channel.off(Events.GLOBALS_UPDATED, cb);
|
|
61
|
-
}, []);
|
|
62
|
-
return [globals];
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export const extractComponentArgTypes = (component, {
|
|
66
|
-
id,
|
|
67
|
-
storyById
|
|
68
|
-
}, include, exclude) => {
|
|
69
|
-
const {
|
|
70
|
-
parameters
|
|
71
|
-
} = storyById(id);
|
|
72
|
-
const {
|
|
73
|
-
extractArgTypes
|
|
74
|
-
} = parameters.docs || {};
|
|
75
|
-
|
|
76
|
-
if (!extractArgTypes) {
|
|
77
|
-
throw new Error(ArgsTableError.ARGS_UNSUPPORTED);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
let argTypes = extractArgTypes(component);
|
|
81
|
-
argTypes = filterArgTypes(argTypes, include, exclude);
|
|
82
|
-
return argTypes;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const isShortcut = value => {
|
|
86
|
-
return value && [CURRENT_SELECTION, PRIMARY_STORY].includes(value);
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
export const getComponent = (props = {}, {
|
|
90
|
-
id,
|
|
91
|
-
storyById
|
|
92
|
-
}) => {
|
|
93
|
-
const {
|
|
94
|
-
of
|
|
95
|
-
} = props;
|
|
96
|
-
const {
|
|
97
|
-
story
|
|
98
|
-
} = props;
|
|
99
|
-
const {
|
|
100
|
-
component
|
|
101
|
-
} = storyById(id);
|
|
102
|
-
|
|
103
|
-
if (isShortcut(of) || isShortcut(story)) {
|
|
104
|
-
return component || null;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (!of) {
|
|
108
|
-
throw new Error(ArgsTableError.NO_COMPONENT);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return of;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
const addComponentTabs = (tabs, components, context, include, exclude, sort) => Object.assign({}, tabs, mapValues(components, comp => ({
|
|
115
|
-
rows: extractComponentArgTypes(comp, context, include, exclude),
|
|
116
|
-
sort
|
|
117
|
-
})));
|
|
118
|
-
|
|
119
|
-
export const StoryTable = props => {
|
|
120
|
-
const context = useContext(DocsContext);
|
|
121
|
-
const {
|
|
122
|
-
id: currentId,
|
|
123
|
-
componentStories
|
|
124
|
-
} = context;
|
|
125
|
-
const {
|
|
126
|
-
story: storyName,
|
|
127
|
-
component,
|
|
128
|
-
subcomponents,
|
|
129
|
-
showComponent,
|
|
130
|
-
include,
|
|
131
|
-
exclude,
|
|
132
|
-
sort
|
|
133
|
-
} = props;
|
|
134
|
-
|
|
135
|
-
try {
|
|
136
|
-
let storyId;
|
|
137
|
-
|
|
138
|
-
switch (storyName) {
|
|
139
|
-
case CURRENT_SELECTION:
|
|
140
|
-
{
|
|
141
|
-
storyId = currentId;
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
case PRIMARY_STORY:
|
|
146
|
-
{
|
|
147
|
-
const primaryStory = componentStories()[0];
|
|
148
|
-
storyId = primaryStory.id;
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
default:
|
|
153
|
-
{
|
|
154
|
-
storyId = lookupStoryId(storyName, context);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const story = useStory(storyId, context); // eslint-disable-next-line prefer-const
|
|
159
|
-
|
|
160
|
-
let [args, updateArgs, resetArgs] = useArgs(storyId, context);
|
|
161
|
-
const [globals] = useGlobals(storyId, context);
|
|
162
|
-
if (!story) return /*#__PURE__*/React.createElement(PureArgsTable, {
|
|
163
|
-
isLoading: true,
|
|
164
|
-
updateArgs: updateArgs,
|
|
165
|
-
resetArgs: resetArgs
|
|
166
|
-
});
|
|
167
|
-
const argTypes = filterArgTypes(story.argTypes, include, exclude);
|
|
168
|
-
const mainLabel = getComponentName(component) || 'Story';
|
|
169
|
-
let tabs = {
|
|
170
|
-
[mainLabel]: {
|
|
171
|
-
rows: argTypes,
|
|
172
|
-
args,
|
|
173
|
-
globals,
|
|
174
|
-
updateArgs,
|
|
175
|
-
resetArgs
|
|
176
|
-
}
|
|
177
|
-
}; // Use the dynamically generated component tabs if there are no controls
|
|
178
|
-
|
|
179
|
-
const storyHasArgsWithControls = argTypes && Object.values(argTypes).find(v => !!(v !== null && v !== void 0 && v.control));
|
|
180
|
-
|
|
181
|
-
if (!storyHasArgsWithControls) {
|
|
182
|
-
updateArgs = null;
|
|
183
|
-
resetArgs = null;
|
|
184
|
-
tabs = {};
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (component && (!storyHasArgsWithControls || showComponent)) {
|
|
188
|
-
tabs = addComponentTabs(tabs, {
|
|
189
|
-
[mainLabel]: component
|
|
190
|
-
}, context, include, exclude);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (subcomponents) {
|
|
194
|
-
if (Array.isArray(subcomponents)) {
|
|
195
|
-
throw new Error(`Unexpected subcomponents array. Expected an object whose keys are tab labels and whose values are components.`);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
tabs = addComponentTabs(tabs, subcomponents, context, include, exclude);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return /*#__PURE__*/React.createElement(TabbedArgsTable, {
|
|
202
|
-
tabs: tabs,
|
|
203
|
-
sort: sort
|
|
204
|
-
});
|
|
205
|
-
} catch (err) {
|
|
206
|
-
return /*#__PURE__*/React.createElement(PureArgsTable, {
|
|
207
|
-
error: err.message
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
export const ComponentsTable = props => {
|
|
212
|
-
const context = useContext(DocsContext);
|
|
213
|
-
const {
|
|
214
|
-
components,
|
|
215
|
-
include,
|
|
216
|
-
exclude,
|
|
217
|
-
sort
|
|
218
|
-
} = props;
|
|
219
|
-
const tabs = addComponentTabs({}, components, context, include, exclude);
|
|
220
|
-
return /*#__PURE__*/React.createElement(TabbedArgsTable, {
|
|
221
|
-
tabs: tabs,
|
|
222
|
-
sort: sort
|
|
223
|
-
});
|
|
224
|
-
};
|
|
225
|
-
export const ArgsTable = props => {
|
|
226
|
-
const context = useContext(DocsContext);
|
|
227
|
-
const {
|
|
228
|
-
id,
|
|
229
|
-
storyById
|
|
230
|
-
} = context;
|
|
231
|
-
const {
|
|
232
|
-
parameters: {
|
|
233
|
-
controls
|
|
234
|
-
},
|
|
235
|
-
subcomponents
|
|
236
|
-
} = storyById(id);
|
|
237
|
-
const {
|
|
238
|
-
include,
|
|
239
|
-
exclude,
|
|
240
|
-
components,
|
|
241
|
-
sort: sortProp
|
|
242
|
-
} = props;
|
|
243
|
-
const {
|
|
244
|
-
story: storyName
|
|
245
|
-
} = props;
|
|
246
|
-
const sort = sortProp || (controls === null || controls === void 0 ? void 0 : controls.sort);
|
|
247
|
-
const main = getComponent(props, context);
|
|
248
|
-
|
|
249
|
-
if (storyName) {
|
|
250
|
-
return /*#__PURE__*/React.createElement(StoryTable, _extends({}, props, {
|
|
251
|
-
component: main,
|
|
252
|
-
subcomponents,
|
|
253
|
-
sort
|
|
254
|
-
}));
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
if (!components && !subcomponents) {
|
|
258
|
-
let mainProps;
|
|
259
|
-
|
|
260
|
-
try {
|
|
261
|
-
mainProps = {
|
|
262
|
-
rows: extractComponentArgTypes(main, context, include, exclude)
|
|
263
|
-
};
|
|
264
|
-
} catch (err) {
|
|
265
|
-
mainProps = {
|
|
266
|
-
error: err.message
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
return /*#__PURE__*/React.createElement(PureArgsTable, _extends({}, mainProps, {
|
|
271
|
-
sort: sort
|
|
272
|
-
}));
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
if (components) {
|
|
276
|
-
return /*#__PURE__*/React.createElement(ComponentsTable, _extends({}, props, {
|
|
277
|
-
components,
|
|
278
|
-
sort
|
|
279
|
-
}));
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
const mainLabel = getComponentName(main);
|
|
283
|
-
return /*#__PURE__*/React.createElement(ComponentsTable, _extends({}, props, {
|
|
284
|
-
components: Object.assign({
|
|
285
|
-
[mainLabel]: main
|
|
286
|
-
}, subcomponents),
|
|
287
|
-
sort: sort
|
|
288
|
-
}));
|
|
289
|
-
};
|
|
290
|
-
ArgsTable.defaultProps = {
|
|
291
|
-
of: CURRENT_SELECTION
|
|
292
|
-
};
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
const _excluded = ["withSource", "mdxSource", "children"];
|
|
2
|
-
|
|
3
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
4
|
-
|
|
5
|
-
import React, { useContext } from 'react';
|
|
6
|
-
import { MDXProvider } from '@mdx-js/react';
|
|
7
|
-
import { toId, storyNameFromExport } from '@storybook/csf';
|
|
8
|
-
import { resetComponents, Preview as PurePreview, PreviewSkeleton } from '@storybook/components';
|
|
9
|
-
import { DocsContext } from './DocsContext';
|
|
10
|
-
import { SourceContext } from './SourceContainer';
|
|
11
|
-
import { getSourceProps, SourceState } from './Source';
|
|
12
|
-
import { useStories } from './useStory';
|
|
13
|
-
import { CURRENT_SELECTION } from './types';
|
|
14
|
-
export { SourceState };
|
|
15
|
-
|
|
16
|
-
const getPreviewProps = (_ref, docsContext, sourceContext) => {
|
|
17
|
-
let {
|
|
18
|
-
withSource,
|
|
19
|
-
mdxSource,
|
|
20
|
-
children
|
|
21
|
-
} = _ref,
|
|
22
|
-
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
23
|
-
|
|
24
|
-
const {
|
|
25
|
-
mdxComponentAnnotations,
|
|
26
|
-
mdxStoryNameToKey
|
|
27
|
-
} = docsContext;
|
|
28
|
-
let sourceState = withSource;
|
|
29
|
-
let isLoading = false;
|
|
30
|
-
|
|
31
|
-
if (sourceState === SourceState.NONE) {
|
|
32
|
-
return {
|
|
33
|
-
isLoading,
|
|
34
|
-
previewProps: props
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (mdxSource) {
|
|
39
|
-
return {
|
|
40
|
-
isLoading,
|
|
41
|
-
previewProps: Object.assign({}, props, {
|
|
42
|
-
withSource: getSourceProps({
|
|
43
|
-
code: decodeURI(mdxSource)
|
|
44
|
-
}, docsContext, sourceContext)
|
|
45
|
-
})
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const childArray = Array.isArray(children) ? children : [children];
|
|
50
|
-
const storyChildren = childArray.filter(c => c.props && (c.props.id || c.props.name));
|
|
51
|
-
const targetIds = storyChildren.map(s => s.props.id || toId(mdxComponentAnnotations.id || mdxComponentAnnotations.title, storyNameFromExport(mdxStoryNameToKey[s.props.name])));
|
|
52
|
-
const sourceProps = getSourceProps({
|
|
53
|
-
ids: targetIds
|
|
54
|
-
}, docsContext, sourceContext);
|
|
55
|
-
if (!sourceState) sourceState = sourceProps.state;
|
|
56
|
-
const storyIds = targetIds.map(targetId => targetId === CURRENT_SELECTION ? docsContext.id : targetId);
|
|
57
|
-
const stories = useStories(storyIds, docsContext);
|
|
58
|
-
isLoading = stories.some(s => !s);
|
|
59
|
-
return {
|
|
60
|
-
isLoading,
|
|
61
|
-
previewProps: Object.assign({}, props, {
|
|
62
|
-
// pass through columns etc.
|
|
63
|
-
withSource: sourceProps,
|
|
64
|
-
isExpanded: sourceState === SourceState.OPEN
|
|
65
|
-
})
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export const Canvas = props => {
|
|
70
|
-
const docsContext = useContext(DocsContext);
|
|
71
|
-
const sourceContext = useContext(SourceContext);
|
|
72
|
-
const {
|
|
73
|
-
isLoading,
|
|
74
|
-
previewProps
|
|
75
|
-
} = getPreviewProps(props, docsContext, sourceContext);
|
|
76
|
-
const {
|
|
77
|
-
children
|
|
78
|
-
} = props;
|
|
79
|
-
if (isLoading) return /*#__PURE__*/React.createElement(PreviewSkeleton, null);
|
|
80
|
-
return /*#__PURE__*/React.createElement(MDXProvider, {
|
|
81
|
-
components: resetComponents
|
|
82
|
-
}, /*#__PURE__*/React.createElement(PurePreview, previewProps, children));
|
|
83
|
-
};
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import React, { useContext } from 'react';
|
|
2
|
-
import { Description } from '@storybook/components';
|
|
3
|
-
import { str } from '@storybook/docs-tools';
|
|
4
|
-
import { DocsContext } from './DocsContext';
|
|
5
|
-
import { CURRENT_SELECTION } from './types';
|
|
6
|
-
export let DescriptionType;
|
|
7
|
-
|
|
8
|
-
(function (DescriptionType) {
|
|
9
|
-
DescriptionType["INFO"] = "info";
|
|
10
|
-
DescriptionType["NOTES"] = "notes";
|
|
11
|
-
DescriptionType["DOCGEN"] = "docgen";
|
|
12
|
-
DescriptionType["LEGACY_5_2"] = "legacy-5.2";
|
|
13
|
-
DescriptionType["AUTO"] = "auto";
|
|
14
|
-
})(DescriptionType || (DescriptionType = {}));
|
|
15
|
-
|
|
16
|
-
const getNotes = notes => notes && (typeof notes === 'string' ? notes : str(notes.markdown) || str(notes.text));
|
|
17
|
-
|
|
18
|
-
const getInfo = info => info && (typeof info === 'string' ? info : str(info.text));
|
|
19
|
-
|
|
20
|
-
const noDescription = component => null;
|
|
21
|
-
|
|
22
|
-
export const getDescriptionProps = ({
|
|
23
|
-
of,
|
|
24
|
-
type,
|
|
25
|
-
markdown,
|
|
26
|
-
children
|
|
27
|
-
}, {
|
|
28
|
-
id,
|
|
29
|
-
storyById
|
|
30
|
-
}) => {
|
|
31
|
-
const {
|
|
32
|
-
component,
|
|
33
|
-
parameters
|
|
34
|
-
} = storyById(id);
|
|
35
|
-
|
|
36
|
-
if (children || markdown) {
|
|
37
|
-
return {
|
|
38
|
-
markdown: children || markdown
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const {
|
|
43
|
-
notes,
|
|
44
|
-
info,
|
|
45
|
-
docs
|
|
46
|
-
} = parameters;
|
|
47
|
-
const {
|
|
48
|
-
extractComponentDescription = noDescription,
|
|
49
|
-
description
|
|
50
|
-
} = docs || {};
|
|
51
|
-
const target = of === CURRENT_SELECTION ? component : of; // override component description
|
|
52
|
-
|
|
53
|
-
const componentDescriptionParameter = description === null || description === void 0 ? void 0 : description.component;
|
|
54
|
-
|
|
55
|
-
if (componentDescriptionParameter) {
|
|
56
|
-
return {
|
|
57
|
-
markdown: componentDescriptionParameter
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
switch (type) {
|
|
62
|
-
case DescriptionType.INFO:
|
|
63
|
-
return {
|
|
64
|
-
markdown: getInfo(info)
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
case DescriptionType.NOTES:
|
|
68
|
-
return {
|
|
69
|
-
markdown: getNotes(notes)
|
|
70
|
-
};
|
|
71
|
-
// FIXME: remove in 6.0
|
|
72
|
-
|
|
73
|
-
case DescriptionType.LEGACY_5_2:
|
|
74
|
-
return {
|
|
75
|
-
markdown: `
|
|
76
|
-
${getNotes(notes) || getInfo(info) || ''}
|
|
77
|
-
|
|
78
|
-
${extractComponentDescription(target) || ''}
|
|
79
|
-
`.trim()
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
case DescriptionType.DOCGEN:
|
|
83
|
-
case DescriptionType.AUTO:
|
|
84
|
-
default:
|
|
85
|
-
return {
|
|
86
|
-
markdown: extractComponentDescription(target, Object.assign({
|
|
87
|
-
component
|
|
88
|
-
}, parameters))
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const DescriptionContainer = props => {
|
|
94
|
-
const context = useContext(DocsContext);
|
|
95
|
-
const {
|
|
96
|
-
markdown
|
|
97
|
-
} = getDescriptionProps(props, context);
|
|
98
|
-
return markdown ? /*#__PURE__*/React.createElement(Description, {
|
|
99
|
-
markdown: markdown
|
|
100
|
-
}) : null;
|
|
101
|
-
}; // since we are in the docs blocks, assume default description if for primary component story
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
DescriptionContainer.defaultProps = {
|
|
105
|
-
of: '.'
|
|
106
|
-
};
|
|
107
|
-
export { DescriptionContainer as Description };
|