1 | "use strict";
|
2 |
|
3 | require("core-js/modules/es.object.assign");
|
4 |
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports.setDefaults = setDefaults;
|
9 | Object.defineProperty(exports, "Story", {
|
10 | enumerable: true,
|
11 | get: function get() {
|
12 | return _Story["default"];
|
13 | }
|
14 | });
|
15 | exports.withInfo = void 0;
|
16 |
|
17 | var _react = _interopRequireDefault(require("react"));
|
18 |
|
19 | var _nestedObjectAssign = _interopRequireDefault(require("nested-object-assign"));
|
20 |
|
21 | var _utilDeprecate = _interopRequireDefault(require("util-deprecate"));
|
22 |
|
23 | var _addons = require("@storybook/addons");
|
24 |
|
25 | var _clientLogger = require("@storybook/client-logger");
|
26 |
|
27 | var _Story = _interopRequireDefault(require("./components/Story"));
|
28 |
|
29 | var _index = _interopRequireDefault(require("./components/PropTable/index"));
|
30 |
|
31 | var _makeTableComponent = _interopRequireDefault(require("./components/makeTableComponent"));
|
32 |
|
33 | var _markdown = require("./components/markdown");
|
34 |
|
35 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
36 |
|
37 | var defaultOptions = {
|
38 | inline: false,
|
39 | header: true,
|
40 | source: true,
|
41 | propTables: [],
|
42 | propTableCompare: function propTableCompare(element, Component) {
|
43 | return (
|
44 | typeof reactHotLoaderGlobal === 'undefined' ? element.type === Component :
|
45 | reactHotLoaderGlobal.areComponentsEqual(element.type, Component)
|
46 | );
|
47 | },
|
48 | TableComponent: _index["default"],
|
49 | maxPropsIntoLine: 3,
|
50 | maxPropObjectKeys: 3,
|
51 | maxPropArrayLength: 3,
|
52 | maxPropStringLength: 50
|
53 | };
|
54 | var defaultComponents = {
|
55 | h1: _markdown.H1,
|
56 | h2: _markdown.H2,
|
57 | h3: _markdown.H3,
|
58 | h4: _markdown.H4,
|
59 | h5: _markdown.H5,
|
60 | h6: _markdown.H6,
|
61 | code: _markdown.Code,
|
62 | p: _markdown.P,
|
63 | a: _markdown.A,
|
64 | li: _markdown.LI,
|
65 | ul: _markdown.UL
|
66 | };
|
67 | var hasWarned = false;
|
68 |
|
69 | function addInfo(storyFn, context, infoOptions) {
|
70 | var options = Object.assign({}, defaultOptions, {}, infoOptions);
|
71 |
|
72 |
|
73 |
|
74 | if (!options.propTables) {
|
75 | options.propTables = null;
|
76 | }
|
77 |
|
78 | var components = Object.assign({}, defaultComponents);
|
79 |
|
80 | if (options && options.components) {
|
81 | Object.assign(components, options.components);
|
82 | }
|
83 |
|
84 | if (options && options.marksyConf) {
|
85 | if (!hasWarned) {
|
86 | _clientLogger.logger.warn('@storybook/addon-info: "marksyConf" option has been renamed to "components"');
|
87 |
|
88 | hasWarned = true;
|
89 | }
|
90 |
|
91 | Object.assign(components, options.marksyConf);
|
92 | }
|
93 |
|
94 | var props = {
|
95 | info: options.text,
|
96 | context: context,
|
97 | showInline: Boolean(options.inline),
|
98 | showHeader: Boolean(options.header),
|
99 | showSource: Boolean(options.source),
|
100 | styles: typeof options.styles === 'function' ? options.styles : function (s) {
|
101 | return (0, _nestedObjectAssign["default"])({}, s, options.styles);
|
102 | },
|
103 | propTables: options.propTables,
|
104 | propTablesExclude: options.propTablesExclude,
|
105 | propTableCompare: options.propTableCompare,
|
106 | PropTable: (0, _makeTableComponent["default"])(options.TableComponent),
|
107 | components: components,
|
108 | maxPropObjectKeys: options.maxPropObjectKeys,
|
109 | maxPropArrayLength: options.maxPropArrayLength,
|
110 | maxPropsIntoLine: options.maxPropsIntoLine,
|
111 | maxPropStringLength: options.maxPropStringLength,
|
112 | excludedPropTypes: options.excludedPropTypes
|
113 | };
|
114 | return _react["default"].createElement(_Story["default"], props, storyFn(context));
|
115 | }
|
116 |
|
117 | var withInfo = (0, _addons.makeDecorator)({
|
118 | name: 'withInfo',
|
119 | parameterName: 'info',
|
120 | allowDeprecatedUsage: true,
|
121 | wrapper: function wrapper(getStory, context, _ref) {
|
122 | var options = _ref.options,
|
123 | parameters = _ref.parameters;
|
124 | var storyOptions = parameters || options;
|
125 | var infoOptions = typeof storyOptions === 'string' ? {
|
126 | text: storyOptions
|
127 | } : storyOptions;
|
128 | var mergedOptions = typeof infoOptions === 'string' ? infoOptions : Object.assign({}, options, {}, infoOptions);
|
129 | return addInfo(getStory, context, mergedOptions);
|
130 | }
|
131 | });
|
132 | exports.withInfo = withInfo;
|
133 |
|
134 | function setDefaults(newDefaults) {
|
135 | return (0, _utilDeprecate["default"])(function () {
|
136 | return Object.assign(defaultOptions, newDefaults);
|
137 | }, 'setDefaults is deprecated. Instead, you can pass options into withInfo(options) directly, or use the info parameter.')();
|
138 | } |
\ | No newline at end of file |