1 | "use strict";
|
2 |
|
3 | function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
4 |
|
5 | require("core-js/modules/es.weak-map.js");
|
6 |
|
7 | require("core-js/modules/es.object.to-string.js");
|
8 |
|
9 | require("core-js/modules/es.string.iterator.js");
|
10 |
|
11 | require("core-js/modules/es.array.iterator.js");
|
12 |
|
13 | require("core-js/modules/web.dom-collections.iterator.js");
|
14 |
|
15 | require("core-js/modules/es.object.get-own-property-descriptor.js");
|
16 |
|
17 | require("core-js/modules/es.symbol.iterator.js");
|
18 |
|
19 | Object.defineProperty(exports, "__esModule", {
|
20 | value: true
|
21 | });
|
22 | exports.Description = exports.getDescriptionProps = exports.DescriptionType = void 0;
|
23 |
|
24 | require("core-js/modules/es.symbol.js");
|
25 |
|
26 | require("core-js/modules/es.symbol.description.js");
|
27 |
|
28 | require("core-js/modules/es.string.trim.js");
|
29 |
|
30 | require("core-js/modules/es.array.concat.js");
|
31 |
|
32 | require("core-js/modules/es.object.assign.js");
|
33 |
|
34 | var _react = _interopRequireWildcard(require("react"));
|
35 |
|
36 | var _components = require("@storybook/components");
|
37 |
|
38 | var _DocsContext = require("./DocsContext");
|
39 |
|
40 | var _types = require("./types");
|
41 |
|
42 | var _docgen = require("../lib/docgen");
|
43 |
|
44 | function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
|
45 |
|
46 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }
|
47 |
|
48 | var DescriptionType;
|
49 | exports.DescriptionType = DescriptionType;
|
50 |
|
51 | (function (DescriptionType) {
|
52 | DescriptionType["INFO"] = "info";
|
53 | DescriptionType["NOTES"] = "notes";
|
54 | DescriptionType["DOCGEN"] = "docgen";
|
55 | DescriptionType["LEGACY_5_2"] = "legacy-5.2";
|
56 | DescriptionType["AUTO"] = "auto";
|
57 | })(DescriptionType || (exports.DescriptionType = DescriptionType = {}));
|
58 |
|
59 | var getNotes = function getNotes(notes) {
|
60 | return notes && (typeof notes === 'string' ? notes : (0, _docgen.str)(notes.markdown) || (0, _docgen.str)(notes.text));
|
61 | };
|
62 |
|
63 | var getInfo = function getInfo(info) {
|
64 | return info && (typeof info === 'string' ? info : (0, _docgen.str)(info.text));
|
65 | };
|
66 |
|
67 | var noDescription = function noDescription(component) {
|
68 | return null;
|
69 | };
|
70 |
|
71 | var getDescriptionProps = function getDescriptionProps(_ref, _ref2) {
|
72 | var of = _ref.of,
|
73 | type = _ref.type,
|
74 | markdown = _ref.markdown,
|
75 | children = _ref.children;
|
76 | var id = _ref2.id,
|
77 | storyById = _ref2.storyById;
|
78 |
|
79 | var _storyById = storyById(id),
|
80 | component = _storyById.component,
|
81 | parameters = _storyById.parameters;
|
82 |
|
83 | if (children || markdown) {
|
84 | return {
|
85 | markdown: children || markdown
|
86 | };
|
87 | }
|
88 |
|
89 | var notes = parameters.notes,
|
90 | info = parameters.info,
|
91 | docs = parameters.docs;
|
92 |
|
93 | var _ref3 = docs || {},
|
94 | _ref3$extractComponen = _ref3.extractComponentDescription,
|
95 | extractComponentDescription = _ref3$extractComponen === void 0 ? noDescription : _ref3$extractComponen,
|
96 | description = _ref3.description;
|
97 |
|
98 | var target = of === _types.CURRENT_SELECTION ? component : of;
|
99 |
|
100 | var componentDescriptionParameter = description === null || description === void 0 ? void 0 : description.component;
|
101 |
|
102 | if (componentDescriptionParameter) {
|
103 | return {
|
104 | markdown: componentDescriptionParameter
|
105 | };
|
106 | }
|
107 |
|
108 | switch (type) {
|
109 | case DescriptionType.INFO:
|
110 | return {
|
111 | markdown: getInfo(info)
|
112 | };
|
113 |
|
114 | case DescriptionType.NOTES:
|
115 | return {
|
116 | markdown: getNotes(notes)
|
117 | };
|
118 |
|
119 |
|
120 | case DescriptionType.LEGACY_5_2:
|
121 | return {
|
122 | markdown: "\n".concat(getNotes(notes) || getInfo(info) || '', "\n\n").concat(extractComponentDescription(target) || '', "\n").trim()
|
123 | };
|
124 |
|
125 | case DescriptionType.DOCGEN:
|
126 | case DescriptionType.AUTO:
|
127 | default:
|
128 | return {
|
129 | markdown: extractComponentDescription(target, Object.assign({
|
130 | component: component
|
131 | }, parameters))
|
132 | };
|
133 | }
|
134 | };
|
135 |
|
136 | exports.getDescriptionProps = getDescriptionProps;
|
137 |
|
138 | var DescriptionContainer = function DescriptionContainer(props) {
|
139 | var context = (0, _react.useContext)(_DocsContext.DocsContext);
|
140 |
|
141 | var _getDescriptionProps = getDescriptionProps(props, context),
|
142 | markdown = _getDescriptionProps.markdown;
|
143 |
|
144 | return markdown ? _react.default.createElement(_components.Description, {
|
145 | markdown: markdown
|
146 | }) : null;
|
147 | };
|
148 |
|
149 |
|
150 | exports.Description = DescriptionContainer;
|
151 | DescriptionContainer.defaultProps = {
|
152 | of: '.'
|
153 | }; |
\ | No newline at end of file |