@storybook/react 6.5.0-alpha.46 → 6.5.0-alpha.49
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/dist/cjs/client/docs/config.js +29 -0
- package/dist/cjs/client/docs/extractArgTypes.js +54 -0
- package/dist/cjs/client/docs/extractProps.js +77 -0
- package/dist/cjs/client/docs/jsxDecorator.js +277 -0
- package/dist/cjs/client/docs/lib/captions.js +18 -0
- package/dist/cjs/client/docs/lib/componentTypes.js +24 -0
- package/dist/cjs/client/docs/lib/defaultValues/createDefaultValue.js +81 -0
- package/dist/cjs/client/docs/lib/defaultValues/createFromRawDefaultProp.js +225 -0
- package/dist/cjs/client/docs/lib/defaultValues/generateArray.js +29 -0
- package/dist/cjs/client/docs/lib/defaultValues/generateObject.js +29 -0
- package/dist/cjs/client/docs/lib/defaultValues/index.js +37 -0
- package/dist/cjs/client/docs/lib/defaultValues/prettyIdentifier.js +34 -0
- package/dist/cjs/client/docs/lib/generateCode.js +89 -0
- package/dist/cjs/client/docs/lib/index.js +63 -0
- package/dist/cjs/client/docs/lib/inspection/acornParser.js +254 -0
- package/dist/cjs/client/docs/lib/inspection/index.js +37 -0
- package/dist/cjs/client/docs/lib/inspection/inspectValue.js +26 -0
- package/dist/cjs/client/docs/lib/inspection/types.js +19 -0
- package/dist/cjs/client/docs/lib/isHtmlTag.js +18 -0
- package/dist/cjs/client/docs/propTypes/createType.js +469 -0
- package/dist/cjs/client/docs/propTypes/generateFuncSignature.js +78 -0
- package/dist/cjs/client/docs/propTypes/handleProp.js +54 -0
- package/dist/cjs/client/docs/propTypes/rawDefaultPropResolvers.js +47 -0
- package/dist/cjs/client/docs/propTypes/sortProps.js +37 -0
- package/dist/cjs/client/docs/react-argtypes.stories.js +129 -0
- package/dist/cjs/client/docs/typeScript/handleProp.js +38 -0
- package/dist/cjs/server/{framework-preset-react-docgen.js → framework-preset-react-docs.js} +19 -9
- package/dist/cjs/server/preset.js +1 -1
- package/dist/esm/client/docs/config.js +16 -0
- package/dist/esm/client/docs/extractArgTypes.js +39 -0
- package/dist/esm/client/docs/extractProps.js +54 -0
- package/dist/esm/client/docs/jsxDecorator.js +218 -0
- package/dist/esm/client/docs/lib/captions.js +6 -0
- package/dist/esm/client/docs/lib/componentTypes.js +9 -0
- package/dist/esm/client/docs/lib/defaultValues/createDefaultValue.js +67 -0
- package/dist/esm/client/docs/lib/defaultValues/createFromRawDefaultProp.js +191 -0
- package/dist/esm/client/docs/lib/defaultValues/generateArray.js +19 -0
- package/dist/esm/client/docs/lib/defaultValues/generateObject.js +19 -0
- package/dist/esm/client/docs/lib/defaultValues/index.js +2 -0
- package/dist/esm/client/docs/lib/defaultValues/prettyIdentifier.js +22 -0
- package/dist/esm/client/docs/lib/generateCode.js +68 -0
- package/dist/esm/client/docs/lib/index.js +4 -0
- package/dist/esm/client/docs/lib/inspection/acornParser.js +213 -0
- package/dist/esm/client/docs/lib/inspection/index.js +2 -0
- package/dist/esm/client/docs/lib/inspection/inspectValue.js +16 -0
- package/dist/esm/client/docs/lib/inspection/types.js +12 -0
- package/dist/esm/client/docs/lib/isHtmlTag.js +6 -0
- package/dist/esm/client/docs/propTypes/createType.js +449 -0
- package/dist/esm/client/docs/propTypes/generateFuncSignature.js +62 -0
- package/dist/esm/client/docs/propTypes/handleProp.js +39 -0
- package/dist/esm/client/docs/propTypes/rawDefaultPropResolvers.js +32 -0
- package/dist/esm/client/docs/propTypes/sortProps.js +24 -0
- package/dist/esm/client/docs/react-argtypes.stories.js +97 -0
- package/dist/esm/client/docs/typeScript/handleProp.js +27 -0
- package/dist/esm/server/{framework-preset-react-docgen.js → framework-preset-react-docs.js} +13 -9
- package/dist/esm/server/preset.js +1 -1
- package/dist/modern/client/docs/config.js +14 -0
- package/dist/modern/client/docs/extractArgTypes.js +38 -0
- package/dist/modern/client/docs/extractProps.js +42 -0
- package/dist/modern/client/docs/jsxDecorator.js +177 -0
- package/dist/modern/client/docs/lib/captions.js +6 -0
- package/dist/modern/client/docs/lib/componentTypes.js +2 -0
- package/dist/modern/client/docs/lib/defaultValues/createDefaultValue.js +72 -0
- package/dist/modern/client/docs/lib/defaultValues/createFromRawDefaultProp.js +181 -0
- package/dist/modern/client/docs/lib/defaultValues/generateArray.js +21 -0
- package/dist/modern/client/docs/lib/defaultValues/generateObject.js +21 -0
- package/dist/modern/client/docs/lib/defaultValues/index.js +2 -0
- package/dist/modern/client/docs/lib/defaultValues/prettyIdentifier.js +24 -0
- package/dist/modern/client/docs/lib/generateCode.js +59 -0
- package/dist/modern/client/docs/lib/index.js +4 -0
- package/dist/modern/client/docs/lib/inspection/acornParser.js +211 -0
- package/dist/modern/client/docs/lib/inspection/index.js +2 -0
- package/dist/modern/client/docs/lib/inspection/inspectValue.js +15 -0
- package/dist/modern/client/docs/lib/inspection/types.js +12 -0
- package/dist/modern/client/docs/lib/isHtmlTag.js +4 -0
- package/dist/modern/client/docs/propTypes/createType.js +446 -0
- package/dist/modern/client/docs/propTypes/generateFuncSignature.js +57 -0
- package/dist/modern/client/docs/propTypes/handleProp.js +39 -0
- package/dist/modern/client/docs/propTypes/rawDefaultPropResolvers.js +31 -0
- package/dist/modern/client/docs/propTypes/sortProps.js +14 -0
- package/dist/modern/client/docs/react-argtypes.stories.js +54 -0
- package/dist/modern/client/docs/typeScript/handleProp.js +28 -0
- package/dist/modern/server/{framework-preset-react-docgen.js → framework-preset-react-docs.js} +13 -9
- package/dist/modern/server/preset.js +1 -1
- package/dist/ts3.4/client/docs/config.d.ts +13 -0
- package/dist/ts3.4/client/docs/extractArgTypes.d.ts +2 -0
- package/dist/ts3.4/client/docs/extractProps.d.ts +5 -0
- package/dist/ts3.4/client/docs/jsxDecorator.d.ts +23 -0
- package/dist/ts3.4/client/docs/lib/captions.d.ts +6 -0
- package/dist/ts3.4/client/docs/lib/componentTypes.d.ts +2 -0
- package/dist/ts3.4/client/docs/lib/defaultValues/createDefaultValue.d.ts +2 -0
- package/dist/ts3.4/client/docs/lib/defaultValues/createFromRawDefaultProp.d.ts +11 -0
- package/dist/ts3.4/client/docs/lib/defaultValues/generateArray.d.ts +3 -0
- package/dist/ts3.4/client/docs/lib/defaultValues/generateObject.d.ts +3 -0
- package/dist/ts3.4/client/docs/lib/defaultValues/index.d.ts +2 -0
- package/dist/ts3.4/client/docs/lib/defaultValues/prettyIdentifier.d.ts +4 -0
- package/dist/ts3.4/client/docs/lib/generateCode.d.ts +3 -0
- package/dist/ts3.4/client/docs/lib/index.d.ts +4 -0
- package/dist/ts3.4/client/docs/lib/inspection/acornParser.d.ts +7 -0
- package/dist/ts3.4/client/docs/lib/inspection/index.d.ts +2 -0
- package/dist/ts3.4/client/docs/lib/inspection/inspectValue.d.ts +2 -0
- package/dist/ts3.4/client/docs/lib/inspection/types.d.ts +50 -0
- package/dist/ts3.4/client/docs/lib/isHtmlTag.d.ts +1 -0
- package/dist/ts3.4/client/docs/propTypes/createType.d.ts +2 -0
- package/dist/ts3.4/client/docs/propTypes/generateFuncSignature.d.ts +4 -0
- package/dist/ts3.4/client/docs/propTypes/handleProp.d.ts +5 -0
- package/dist/ts3.4/client/docs/propTypes/rawDefaultPropResolvers.d.ts +1 -0
- package/dist/ts3.4/client/docs/propTypes/sortProps.d.ts +4 -0
- package/dist/ts3.4/client/docs/react-argtypes.stories.d.ts +1 -0
- package/dist/ts3.4/client/docs/typeScript/handleProp.d.ts +3 -0
- package/dist/ts3.4/server/framework-preset-react-docs.d.ts +6 -0
- package/dist/ts3.9/client/docs/config.d.ts +13 -0
- package/dist/ts3.9/client/docs/extractArgTypes.d.ts +2 -0
- package/dist/ts3.9/client/docs/extractProps.d.ts +5 -0
- package/dist/ts3.9/client/docs/jsxDecorator.d.ts +23 -0
- package/dist/ts3.9/client/docs/lib/captions.d.ts +6 -0
- package/dist/ts3.9/client/docs/lib/componentTypes.d.ts +2 -0
- package/dist/ts3.9/client/docs/lib/defaultValues/createDefaultValue.d.ts +2 -0
- package/dist/ts3.9/client/docs/lib/defaultValues/createFromRawDefaultProp.d.ts +11 -0
- package/dist/ts3.9/client/docs/lib/defaultValues/generateArray.d.ts +3 -0
- package/dist/ts3.9/client/docs/lib/defaultValues/generateObject.d.ts +3 -0
- package/dist/ts3.9/client/docs/lib/defaultValues/index.d.ts +2 -0
- package/dist/ts3.9/client/docs/lib/defaultValues/prettyIdentifier.d.ts +4 -0
- package/dist/ts3.9/client/docs/lib/generateCode.d.ts +3 -0
- package/dist/ts3.9/client/docs/lib/index.d.ts +4 -0
- package/dist/ts3.9/client/docs/lib/inspection/acornParser.d.ts +7 -0
- package/dist/ts3.9/client/docs/lib/inspection/index.d.ts +2 -0
- package/dist/ts3.9/client/docs/lib/inspection/inspectValue.d.ts +2 -0
- package/dist/ts3.9/client/docs/lib/inspection/types.d.ts +50 -0
- package/dist/ts3.9/client/docs/lib/isHtmlTag.d.ts +1 -0
- package/dist/ts3.9/client/docs/propTypes/createType.d.ts +2 -0
- package/dist/ts3.9/client/docs/propTypes/generateFuncSignature.d.ts +4 -0
- package/dist/ts3.9/client/docs/propTypes/handleProp.d.ts +5 -0
- package/dist/ts3.9/client/docs/propTypes/rawDefaultPropResolvers.d.ts +1 -0
- package/dist/ts3.9/client/docs/propTypes/sortProps.d.ts +4 -0
- package/dist/ts3.9/client/docs/react-argtypes.stories.d.ts +1 -0
- package/dist/ts3.9/client/docs/typeScript/handleProp.d.ts +3 -0
- package/dist/ts3.9/client/preview/types-6-0.d.ts +3 -3
- package/dist/ts3.9/client/preview/types-7-0.d.ts +2 -2
- package/dist/ts3.9/server/framework-preset-react-docs.d.ts +6 -0
- package/dist/ts3.9/server/options.d.ts +1 -1
- package/dist/ts3.9/server/preset.d.ts +1 -1
- package/package.json +21 -11
- package/types/index.ts +1 -1
- package/dist/ts3.4/server/framework-preset-react-docgen.d.ts +0 -5
- package/dist/ts3.9/server/framework-preset-react-docgen.d.ts +0 -5
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
require("core-js/modules/es.symbol.js");
|
|
6
|
+
|
|
7
|
+
require("core-js/modules/es.symbol.description.js");
|
|
8
|
+
|
|
9
|
+
require("core-js/modules/es.symbol.iterator.js");
|
|
10
|
+
|
|
11
|
+
require("core-js/modules/es.array.iterator.js");
|
|
12
|
+
|
|
13
|
+
require("core-js/modules/es.string.iterator.js");
|
|
14
|
+
|
|
15
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
16
|
+
|
|
17
|
+
require("core-js/modules/es.array.slice.js");
|
|
18
|
+
|
|
19
|
+
require("core-js/modules/es.function.name.js");
|
|
20
|
+
|
|
21
|
+
require("core-js/modules/es.array.from.js");
|
|
22
|
+
|
|
23
|
+
require("core-js/modules/es.regexp.exec.js");
|
|
24
|
+
|
|
25
|
+
require("core-js/modules/es.weak-map.js");
|
|
26
|
+
|
|
27
|
+
require("core-js/modules/es.object.get-own-property-descriptor.js");
|
|
28
|
+
|
|
29
|
+
require("core-js/modules/es.object.assign.js");
|
|
30
|
+
|
|
31
|
+
require("core-js/modules/es.array.map.js");
|
|
32
|
+
|
|
33
|
+
require("core-js/modules/es.object.entries.js");
|
|
34
|
+
|
|
35
|
+
require("core-js/modules/es.object.to-string.js");
|
|
36
|
+
|
|
37
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
38
|
+
|
|
39
|
+
var _mapValues = _interopRequireDefault(require("lodash/mapValues"));
|
|
40
|
+
|
|
41
|
+
var _components = require("@storybook/components");
|
|
42
|
+
|
|
43
|
+
var _store = require("@storybook/store");
|
|
44
|
+
|
|
45
|
+
var _ = require("..");
|
|
46
|
+
|
|
47
|
+
var _extractArgTypes = require("./extractArgTypes");
|
|
48
|
+
|
|
49
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
50
|
+
|
|
51
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
52
|
+
|
|
53
|
+
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; }
|
|
54
|
+
|
|
55
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
56
|
+
|
|
57
|
+
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."); }
|
|
58
|
+
|
|
59
|
+
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); }
|
|
60
|
+
|
|
61
|
+
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; }
|
|
62
|
+
|
|
63
|
+
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; }
|
|
64
|
+
|
|
65
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
66
|
+
|
|
67
|
+
var argsTableProps = function argsTableProps(component) {
|
|
68
|
+
var argTypes = (0, _extractArgTypes.extractArgTypes)(component);
|
|
69
|
+
var parameters = {
|
|
70
|
+
__isArgsStory: true
|
|
71
|
+
};
|
|
72
|
+
var rows = (0, _store.inferControls)({
|
|
73
|
+
argTypes: argTypes,
|
|
74
|
+
parameters: parameters
|
|
75
|
+
});
|
|
76
|
+
return {
|
|
77
|
+
rows: rows
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
var ArgsStory = function ArgsStory(_ref) {
|
|
82
|
+
var component = _ref.component;
|
|
83
|
+
|
|
84
|
+
var _argsTableProps = argsTableProps(component),
|
|
85
|
+
rows = _argsTableProps.rows;
|
|
86
|
+
|
|
87
|
+
var initialArgs = (0, _mapValues.default)(rows, function (argType) {
|
|
88
|
+
return argType.defaultValue;
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
var _useState = (0, _react.useState)(initialArgs),
|
|
92
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
93
|
+
args = _useState2[0],
|
|
94
|
+
setArgs = _useState2[1];
|
|
95
|
+
|
|
96
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("p", null, /*#__PURE__*/_react.default.createElement("b", null, "NOTE:"), " these stories are to help visualise the snapshot tests in", ' ', /*#__PURE__*/_react.default.createElement("code", null, "./react-properties.test.js"), "."), /*#__PURE__*/_react.default.createElement(_components.ArgsTable, {
|
|
97
|
+
rows: rows,
|
|
98
|
+
args: args,
|
|
99
|
+
updateArgs: function updateArgs(val) {
|
|
100
|
+
return setArgs(Object.assign({}, args, val));
|
|
101
|
+
}
|
|
102
|
+
}), /*#__PURE__*/_react.default.createElement("table", null, /*#__PURE__*/_react.default.createElement("thead", null, /*#__PURE__*/_react.default.createElement("tr", null, /*#__PURE__*/_react.default.createElement("th", null, "arg name"), /*#__PURE__*/_react.default.createElement("th", null, "argType"))), /*#__PURE__*/_react.default.createElement("tbody", null, Object.entries(args).map(function (_ref2) {
|
|
103
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
104
|
+
key = _ref3[0],
|
|
105
|
+
val = _ref3[1];
|
|
106
|
+
|
|
107
|
+
return /*#__PURE__*/_react.default.createElement("tr", {
|
|
108
|
+
key: key
|
|
109
|
+
}, /*#__PURE__*/_react.default.createElement("td", null, /*#__PURE__*/_react.default.createElement("code", null, key)), /*#__PURE__*/_react.default.createElement("td", null, /*#__PURE__*/_react.default.createElement("pre", null, JSON.stringify(rows[key]))));
|
|
110
|
+
}))));
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
var issuesFixtures = ['js-class-component', 'js-function-component', 'js-function-component-inline-defaults', 'js-function-component-inline-defaults-no-propTypes', 'ts-function-component', 'ts-function-component-inline-defaults', '9399-js-proptypes-shape', '8663-js-styled-components', '9626-js-default-values', '9668-js-proptypes-no-jsdoc', '8143-ts-react-fc-generics', '8143-ts-imported-types', '8279-js-styled-docgen', '8140-js-prop-types-oneof', '9023-js-hoc', '8740-ts-multi-props', '9556-ts-react-default-exports', '9592-ts-styled-props', '9591-ts-import-types', '9721-ts-deprecated-jsdoc', '9827-ts-default-values', '9586-js-react-memo', '9575-ts-camel-case', '9493-ts-display-name', '8894-9511-ts-forward-ref', '9465-ts-type-props', '8428-js-static-prop-types', '9764-ts-extend-props', '9922-ts-component-props'];
|
|
114
|
+
var issuesStories = (0, _.storiesOf)('ArgTypes/Issues', module);
|
|
115
|
+
issuesFixtures.forEach(function (fixture) {
|
|
116
|
+
// eslint-disable-next-line import/no-dynamic-require, global-require
|
|
117
|
+
var _require = require("./__testfixtures__/".concat(fixture, "/input")),
|
|
118
|
+
component = _require.component;
|
|
119
|
+
|
|
120
|
+
issuesStories.add(fixture, function () {
|
|
121
|
+
return /*#__PURE__*/_react.default.createElement(ArgsStory, {
|
|
122
|
+
component: component
|
|
123
|
+
});
|
|
124
|
+
}, {
|
|
125
|
+
chromatic: {
|
|
126
|
+
disable: true
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.enhanceTypeScriptProp = enhanceTypeScriptProp;
|
|
7
|
+
exports.enhanceTypeScriptProps = enhanceTypeScriptProps;
|
|
8
|
+
|
|
9
|
+
require("core-js/modules/es.array.map.js");
|
|
10
|
+
|
|
11
|
+
var _defaultValues = require("../lib/defaultValues");
|
|
12
|
+
|
|
13
|
+
function enhanceTypeScriptProp(extractedProp, rawDefaultProp) {
|
|
14
|
+
var propDef = extractedProp.propDef;
|
|
15
|
+
var defaultValue = extractedProp.docgenInfo.defaultValue;
|
|
16
|
+
|
|
17
|
+
if (defaultValue != null && defaultValue.value != null) {
|
|
18
|
+
var newDefaultValue = (0, _defaultValues.createDefaultValue)(defaultValue.value);
|
|
19
|
+
|
|
20
|
+
if (newDefaultValue != null) {
|
|
21
|
+
propDef.defaultValue = newDefaultValue;
|
|
22
|
+
}
|
|
23
|
+
} else if (rawDefaultProp != null) {
|
|
24
|
+
var _newDefaultValue = (0, _defaultValues.createDefaultValueFromRawDefaultProp)(rawDefaultProp, propDef);
|
|
25
|
+
|
|
26
|
+
if (_newDefaultValue != null) {
|
|
27
|
+
propDef.defaultValue = _newDefaultValue;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return propDef;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function enhanceTypeScriptProps(extractedProps) {
|
|
35
|
+
return extractedProps.map(function (prop) {
|
|
36
|
+
return enhanceTypeScriptProp(prop);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
@@ -4,12 +4,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.babel = babel;
|
|
7
|
+
exports.config = void 0;
|
|
7
8
|
exports.webpackFinal = webpackFinal;
|
|
8
9
|
|
|
9
10
|
require("core-js/modules/es.promise.js");
|
|
10
11
|
|
|
12
|
+
var _coreCommon = require("@storybook/core-common");
|
|
13
|
+
|
|
11
14
|
var _reactDocgenTypescriptPlugin = _interopRequireDefault(require("@storybook/react-docgen-typescript-plugin"));
|
|
12
15
|
|
|
16
|
+
var _docsTools = require("@storybook/docs-tools");
|
|
17
|
+
|
|
13
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
19
|
|
|
15
20
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
@@ -18,10 +23,9 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
18
23
|
|
|
19
24
|
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; }
|
|
20
25
|
|
|
21
|
-
async function babel(config, {
|
|
22
|
-
|
|
23
|
-
})
|
|
24
|
-
var typescriptOptions = await presets.apply('typescript', {});
|
|
26
|
+
async function babel(config, options) {
|
|
27
|
+
if (!(0, _docsTools.hasDocsOrControls)(options)) return config;
|
|
28
|
+
var typescriptOptions = await options.presets.apply('typescript', {});
|
|
25
29
|
var reactDocgen = typescriptOptions.reactDocgen;
|
|
26
30
|
|
|
27
31
|
if (typeof reactDocgen !== 'string') {
|
|
@@ -38,10 +42,9 @@ async function babel(config, {
|
|
|
38
42
|
});
|
|
39
43
|
}
|
|
40
44
|
|
|
41
|
-
async function webpackFinal(config, {
|
|
42
|
-
|
|
43
|
-
})
|
|
44
|
-
var typescriptOptions = await presets.apply('typescript', {});
|
|
45
|
+
async function webpackFinal(config, options) {
|
|
46
|
+
if (!(0, _docsTools.hasDocsOrControls)(options)) return config;
|
|
47
|
+
var typescriptOptions = await options.presets.apply('typescript', {});
|
|
45
48
|
var reactDocgen = typescriptOptions.reactDocgen,
|
|
46
49
|
reactDocgenTypescriptOptions = typescriptOptions.reactDocgenTypescriptOptions;
|
|
47
50
|
|
|
@@ -55,4 +58,11 @@ async function webpackFinal(config, {
|
|
|
55
58
|
savePropValueAsString: true
|
|
56
59
|
}))]
|
|
57
60
|
});
|
|
58
|
-
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
var config = function (entry = [], options) {
|
|
64
|
+
if (!(0, _docsTools.hasDocsOrControls)(options)) return entry;
|
|
65
|
+
return [...entry, (0, _coreCommon.findDistEsm)(__dirname, 'client/docs/config')];
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
exports.config = config;
|
|
@@ -12,5 +12,5 @@ var config = function (entries = []) {
|
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
exports.config = config;
|
|
15
|
-
var addons = [require.resolve('./framework-preset-react'), require.resolve('./framework-preset-cra'), require.resolve('./framework-preset-react-
|
|
15
|
+
var addons = [require.resolve('./framework-preset-react'), require.resolve('./framework-preset-cra'), require.resolve('./framework-preset-react-docs')];
|
|
16
16
|
exports.addons = addons;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { extractComponentDescription, enhanceArgTypes } from '@storybook/docs-tools';
|
|
2
|
+
import { extractArgTypes } from './extractArgTypes';
|
|
3
|
+
import { jsxDecorator } from './jsxDecorator';
|
|
4
|
+
export var parameters = {
|
|
5
|
+
docs: {
|
|
6
|
+
inlineStories: true,
|
|
7
|
+
// NOTE: that the result is a react element. Hooks support is provided by the outer code.
|
|
8
|
+
prepareForInline: function prepareForInline(storyFn) {
|
|
9
|
+
return storyFn();
|
|
10
|
+
},
|
|
11
|
+
extractArgTypes: extractArgTypes,
|
|
12
|
+
extractComponentDescription: extractComponentDescription
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
export var decorators = [jsxDecorator];
|
|
16
|
+
export var argTypesEnhancers = [enhanceArgTypes];
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import "core-js/modules/es.object.to-string.js";
|
|
2
|
+
import "core-js/modules/es.function.name.js";
|
|
3
|
+
import "core-js/modules/es.symbol.js";
|
|
4
|
+
import "core-js/modules/es.symbol.description.js";
|
|
5
|
+
import "core-js/modules/es.object.assign.js";
|
|
6
|
+
import { extractProps } from './extractProps';
|
|
7
|
+
export var extractArgTypes = function extractArgTypes(component) {
|
|
8
|
+
if (component) {
|
|
9
|
+
var _extractProps = extractProps(component),
|
|
10
|
+
rows = _extractProps.rows;
|
|
11
|
+
|
|
12
|
+
if (rows) {
|
|
13
|
+
return rows.reduce(function (acc, row) {
|
|
14
|
+
var name = row.name,
|
|
15
|
+
description = row.description,
|
|
16
|
+
type = row.type,
|
|
17
|
+
sbType = row.sbType,
|
|
18
|
+
defaultSummary = row.defaultValue,
|
|
19
|
+
jsDocTags = row.jsDocTags,
|
|
20
|
+
required = row.required;
|
|
21
|
+
acc[name] = {
|
|
22
|
+
name: name,
|
|
23
|
+
description: description,
|
|
24
|
+
type: Object.assign({
|
|
25
|
+
required: required
|
|
26
|
+
}, sbType),
|
|
27
|
+
table: {
|
|
28
|
+
type: type,
|
|
29
|
+
jsDocTags: jsDocTags,
|
|
30
|
+
defaultValue: defaultSummary
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
return acc;
|
|
34
|
+
}, {});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return null;
|
|
39
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import "core-js/modules/es.array.iterator.js";
|
|
2
|
+
import "core-js/modules/es.map.js";
|
|
3
|
+
import "core-js/modules/es.object.to-string.js";
|
|
4
|
+
import "core-js/modules/es.string.iterator.js";
|
|
5
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
6
|
+
import "core-js/modules/web.dom-collections.for-each.js";
|
|
7
|
+
import "core-js/modules/es.object.keys.js";
|
|
8
|
+
import "core-js/modules/es.array.map.js";
|
|
9
|
+
import PropTypes from 'prop-types';
|
|
10
|
+
import { hasDocgen, extractComponentProps, TypeSystem } from '@storybook/docs-tools';
|
|
11
|
+
import { enhancePropTypesProps } from './propTypes/handleProp';
|
|
12
|
+
import { enhanceTypeScriptProps } from './typeScript/handleProp';
|
|
13
|
+
import { isMemo } from './lib'; // FIXME
|
|
14
|
+
|
|
15
|
+
var propTypesMap = new Map();
|
|
16
|
+
Object.keys(PropTypes).forEach(function (typeName) {
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
var type = PropTypes[typeName];
|
|
19
|
+
propTypesMap.set(type, typeName);
|
|
20
|
+
propTypesMap.set(type.isRequired, typeName);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
function getPropDefs(component, section) {
|
|
24
|
+
var processedComponent = component; // eslint-disable-next-line react/forbid-foreign-prop-types
|
|
25
|
+
|
|
26
|
+
if (!hasDocgen(component) && !component.propTypes && isMemo(component)) {
|
|
27
|
+
processedComponent = component.type;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
var extractedProps = extractComponentProps(processedComponent, section);
|
|
31
|
+
|
|
32
|
+
if (extractedProps.length === 0) {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
switch (extractedProps[0].typeSystem) {
|
|
37
|
+
case TypeSystem.JAVASCRIPT:
|
|
38
|
+
return enhancePropTypesProps(extractedProps, component);
|
|
39
|
+
|
|
40
|
+
case TypeSystem.TYPESCRIPT:
|
|
41
|
+
return enhanceTypeScriptProps(extractedProps);
|
|
42
|
+
|
|
43
|
+
default:
|
|
44
|
+
return extractedProps.map(function (x) {
|
|
45
|
+
return x.propDef;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export var extractProps = function extractProps(component) {
|
|
51
|
+
return {
|
|
52
|
+
rows: getPropDefs(component, 'props')
|
|
53
|
+
};
|
|
54
|
+
};
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import "core-js/modules/es.array.slice.js";
|
|
2
|
+
import "core-js/modules/es.object.freeze.js";
|
|
3
|
+
import "core-js/modules/es.object.keys.js";
|
|
4
|
+
import "core-js/modules/es.symbol.js";
|
|
5
|
+
import "core-js/modules/es.symbol.description.js";
|
|
6
|
+
import "core-js/modules/es.symbol.iterator.js";
|
|
7
|
+
import "core-js/modules/es.array.iterator.js";
|
|
8
|
+
import "core-js/modules/es.string.iterator.js";
|
|
9
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
10
|
+
import "core-js/modules/es.array.from.js";
|
|
11
|
+
var _excluded = ["mdxType", "originalType", "children"];
|
|
12
|
+
|
|
13
|
+
var _templateObject;
|
|
14
|
+
|
|
15
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
16
|
+
|
|
17
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
18
|
+
|
|
19
|
+
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); }
|
|
20
|
+
|
|
21
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
22
|
+
|
|
23
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
24
|
+
|
|
25
|
+
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; }
|
|
26
|
+
|
|
27
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
28
|
+
|
|
29
|
+
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; }
|
|
30
|
+
|
|
31
|
+
import "core-js/modules/es.function.name.js";
|
|
32
|
+
import "core-js/modules/es.object.assign.js";
|
|
33
|
+
import "core-js/modules/es.array.join.js";
|
|
34
|
+
import "core-js/modules/es.array.map.js";
|
|
35
|
+
import "core-js/modules/es.object.to-string.js";
|
|
36
|
+
import "core-js/modules/es.regexp.to-string.js";
|
|
37
|
+
import "core-js/modules/es.regexp.exec.js";
|
|
38
|
+
import "core-js/modules/es.string.match.js";
|
|
39
|
+
import "core-js/modules/web.dom-collections.for-each.js";
|
|
40
|
+
import "core-js/modules/es.string.replace.js";
|
|
41
|
+
import "core-js/modules/es.array.concat.js";
|
|
42
|
+
|
|
43
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
44
|
+
|
|
45
|
+
import React, { createElement } from 'react';
|
|
46
|
+
import reactElementToJSXString from 'react-element-to-jsx-string';
|
|
47
|
+
import dedent from 'ts-dedent';
|
|
48
|
+
import deprecate from 'util-deprecate';
|
|
49
|
+
import { addons, useEffect } from '@storybook/addons';
|
|
50
|
+
import { SourceType, SNIPPET_RENDERED, getDocgenSection } from '@storybook/docs-tools';
|
|
51
|
+
import { logger } from '@storybook/client-logger';
|
|
52
|
+
import { isMemo, isForwardRef } from './lib';
|
|
53
|
+
|
|
54
|
+
/** Run the user supplied onBeforeRender function if it exists */
|
|
55
|
+
var applyBeforeRender = function applyBeforeRender(domString, options) {
|
|
56
|
+
if (typeof options.onBeforeRender !== 'function') {
|
|
57
|
+
return domString;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
var deprecatedOnBeforeRender = deprecate(options.onBeforeRender, dedent(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n StoryFn.parameters.jsx.onBeforeRender was deprecated.\n Prefer StoryFn.parameters.jsx.transformSource instead.\n See https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-onbeforerender for details.\n "]))));
|
|
61
|
+
return deprecatedOnBeforeRender(domString);
|
|
62
|
+
};
|
|
63
|
+
/** Run the user supplied transformSource function if it exists */
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
var applyTransformSource = function applyTransformSource(domString, options, context) {
|
|
67
|
+
if (typeof options.transformSource !== 'function') {
|
|
68
|
+
return domString;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return options.transformSource(domString, context);
|
|
72
|
+
};
|
|
73
|
+
/** Apply the users parameters and render the jsx for a story */
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
export var renderJsx = function renderJsx(code, options) {
|
|
77
|
+
if (typeof code === 'undefined') {
|
|
78
|
+
logger.warn('Too many skip or undefined component');
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
var renderedJSX = code;
|
|
83
|
+
var Type = renderedJSX.type;
|
|
84
|
+
|
|
85
|
+
for (var i = 0; i < options.skip; i += 1) {
|
|
86
|
+
if (typeof renderedJSX === 'undefined') {
|
|
87
|
+
logger.warn('Cannot skip undefined element');
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (React.Children.count(renderedJSX) > 1) {
|
|
92
|
+
logger.warn('Trying to skip an array of elements');
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (typeof renderedJSX.props.children === 'undefined') {
|
|
97
|
+
logger.warn('Not enough children to skip elements.');
|
|
98
|
+
|
|
99
|
+
if (typeof renderedJSX.type === 'function' && renderedJSX.type.name === '') {
|
|
100
|
+
renderedJSX = /*#__PURE__*/React.createElement(Type, renderedJSX.props);
|
|
101
|
+
}
|
|
102
|
+
} else if (typeof renderedJSX.props.children === 'function') {
|
|
103
|
+
renderedJSX = renderedJSX.props.children();
|
|
104
|
+
} else {
|
|
105
|
+
renderedJSX = renderedJSX.props.children;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
var displayNameDefaults = typeof options.displayName === 'string' ? {
|
|
110
|
+
showFunctions: true,
|
|
111
|
+
displayName: function displayName() {
|
|
112
|
+
return options.displayName;
|
|
113
|
+
}
|
|
114
|
+
} : {
|
|
115
|
+
// To get exotic component names resolving properly
|
|
116
|
+
displayName: function displayName(el) {
|
|
117
|
+
return el.type.displayName || getDocgenSection(el.type, 'displayName') || (el.type.name !== '_default' ? el.type.name : null) || (typeof el.type === 'function' ? 'No Display Name' : null) || (isForwardRef(el.type) ? el.type.render.name : null) || (isMemo(el.type) ? el.type.type.name : null) || el.type;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
var filterDefaults = {
|
|
121
|
+
filterProps: function filterProps(value, key) {
|
|
122
|
+
return value !== undefined;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
var opts = Object.assign({}, displayNameDefaults, filterDefaults, options);
|
|
126
|
+
var result = React.Children.map(code, function (c) {
|
|
127
|
+
// @ts-ignore FIXME: workaround react-element-to-jsx-string
|
|
128
|
+
var child = typeof c === 'number' ? c.toString() : c;
|
|
129
|
+
var string = applyBeforeRender(reactElementToJSXString(child, opts), options);
|
|
130
|
+
|
|
131
|
+
if (string.indexOf('"') > -1) {
|
|
132
|
+
var matches = string.match(/\S+=\\"([^"]*)\\"/g);
|
|
133
|
+
|
|
134
|
+
if (matches) {
|
|
135
|
+
matches.forEach(function (match) {
|
|
136
|
+
string = string.replace(match, match.replace(/"/g, "'"));
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return string;
|
|
142
|
+
}).join('\n');
|
|
143
|
+
return result.replace(/function\s+noRefCheck\(\)\s+\{\}/, '() => {}');
|
|
144
|
+
};
|
|
145
|
+
var defaultOpts = {
|
|
146
|
+
skip: 0,
|
|
147
|
+
showFunctions: false,
|
|
148
|
+
enableBeautify: true,
|
|
149
|
+
showDefaultProps: false
|
|
150
|
+
};
|
|
151
|
+
export var skipJsxRender = function skipJsxRender(context) {
|
|
152
|
+
var _context$parameters$d;
|
|
153
|
+
|
|
154
|
+
var sourceParams = context === null || context === void 0 ? void 0 : (_context$parameters$d = context.parameters.docs) === null || _context$parameters$d === void 0 ? void 0 : _context$parameters$d.source;
|
|
155
|
+
var isArgsStory = context === null || context === void 0 ? void 0 : context.parameters.__isArgsStory; // always render if the user forces it
|
|
156
|
+
|
|
157
|
+
if ((sourceParams === null || sourceParams === void 0 ? void 0 : sourceParams.type) === SourceType.DYNAMIC) {
|
|
158
|
+
return false;
|
|
159
|
+
} // never render if the user is forcing the block to render code, or
|
|
160
|
+
// if the user provides code, or if it's not an args story.
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
return !isArgsStory || (sourceParams === null || sourceParams === void 0 ? void 0 : sourceParams.code) || (sourceParams === null || sourceParams === void 0 ? void 0 : sourceParams.type) === SourceType.CODE;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
var isMdx = function isMdx(node) {
|
|
167
|
+
var _node$type, _node$props;
|
|
168
|
+
|
|
169
|
+
return ((_node$type = node.type) === null || _node$type === void 0 ? void 0 : _node$type.displayName) === 'MDXCreateElement' && !!((_node$props = node.props) !== null && _node$props !== void 0 && _node$props.mdxType);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
var mdxToJsx = function mdxToJsx(node) {
|
|
173
|
+
if (!isMdx(node)) return node;
|
|
174
|
+
|
|
175
|
+
var _node$props2 = node.props,
|
|
176
|
+
mdxType = _node$props2.mdxType,
|
|
177
|
+
originalType = _node$props2.originalType,
|
|
178
|
+
children = _node$props2.children,
|
|
179
|
+
rest = _objectWithoutProperties(_node$props2, _excluded);
|
|
180
|
+
|
|
181
|
+
var jsxChildren = [];
|
|
182
|
+
|
|
183
|
+
if (children) {
|
|
184
|
+
var array = Array.isArray(children) ? children : [children];
|
|
185
|
+
jsxChildren = array.map(mdxToJsx);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return /*#__PURE__*/createElement.apply(void 0, [originalType, rest].concat(_toConsumableArray(jsxChildren)));
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
export var jsxDecorator = function jsxDecorator(storyFn, context) {
|
|
192
|
+
var _context$parameters$d2, _context$parameters$d3;
|
|
193
|
+
|
|
194
|
+
var channel = addons.getChannel();
|
|
195
|
+
var skip = skipJsxRender(context);
|
|
196
|
+
var story = storyFn();
|
|
197
|
+
var jsx = '';
|
|
198
|
+
useEffect(function () {
|
|
199
|
+
if (!skip) channel.emit(SNIPPET_RENDERED, (context || {}).id, jsx);
|
|
200
|
+
}); // We only need to render JSX if the source block is actually going to
|
|
201
|
+
// consume it. Otherwise it's just slowing us down.
|
|
202
|
+
|
|
203
|
+
if (skip) {
|
|
204
|
+
return story;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
var options = Object.assign({}, defaultOpts, (context === null || context === void 0 ? void 0 : context.parameters.jsx) || {}); // Exclude decorators from source code snippet by default
|
|
208
|
+
|
|
209
|
+
var storyJsx = context !== null && context !== void 0 && (_context$parameters$d2 = context.parameters.docs) !== null && _context$parameters$d2 !== void 0 && (_context$parameters$d3 = _context$parameters$d2.source) !== null && _context$parameters$d3 !== void 0 && _context$parameters$d3.excludeDecorators ? context.originalStoryFn(context.args, context) : story;
|
|
210
|
+
var sourceJsx = mdxToJsx(storyJsx);
|
|
211
|
+
var rendered = renderJsx(sourceJsx, options);
|
|
212
|
+
|
|
213
|
+
if (rendered) {
|
|
214
|
+
jsx = applyTransformSource(rendered, options, context);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return story;
|
|
218
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import "core-js/modules/es.symbol.js";
|
|
2
|
+
import "core-js/modules/es.symbol.description.js";
|
|
3
|
+
import "core-js/modules/es.object.to-string.js";
|
|
4
|
+
export var isMemo = function isMemo(component) {
|
|
5
|
+
return component.$$typeof === Symbol.for('react.memo');
|
|
6
|
+
};
|
|
7
|
+
export var isForwardRef = function isForwardRef(component) {
|
|
8
|
+
return component.$$typeof === Symbol.for('react.forward_ref');
|
|
9
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { createSummaryValue, isTooLongForDefaultValueSummary } from '@storybook/docs-tools';
|
|
2
|
+
import { FUNCTION_CAPTION, ELEMENT_CAPTION } from '../captions';
|
|
3
|
+
import { InspectionType, inspectValue } from '../inspection';
|
|
4
|
+
import { isHtmlTag } from '../isHtmlTag';
|
|
5
|
+
import { generateCode } from '../generateCode';
|
|
6
|
+
import { generateObject } from './generateObject';
|
|
7
|
+
import { generateArray } from './generateArray';
|
|
8
|
+
import { getPrettyIdentifier } from './prettyIdentifier';
|
|
9
|
+
|
|
10
|
+
function generateFunc(_ref) {
|
|
11
|
+
var inferredType = _ref.inferredType,
|
|
12
|
+
ast = _ref.ast;
|
|
13
|
+
var _ref2 = inferredType,
|
|
14
|
+
identifier = _ref2.identifier;
|
|
15
|
+
|
|
16
|
+
if (identifier != null) {
|
|
17
|
+
return createSummaryValue(getPrettyIdentifier(inferredType), generateCode(ast));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
var prettyCaption = generateCode(ast, true);
|
|
21
|
+
return !isTooLongForDefaultValueSummary(prettyCaption) ? createSummaryValue(prettyCaption) : createSummaryValue(FUNCTION_CAPTION, generateCode(ast));
|
|
22
|
+
} // All elements are JSX elements.
|
|
23
|
+
// JSX elements are not supported by escodegen.
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
function generateElement(defaultValue, inspectionResult) {
|
|
27
|
+
var inferredType = inspectionResult.inferredType;
|
|
28
|
+
var _ref3 = inferredType,
|
|
29
|
+
identifier = _ref3.identifier;
|
|
30
|
+
|
|
31
|
+
if (identifier != null) {
|
|
32
|
+
if (!isHtmlTag(identifier)) {
|
|
33
|
+
var prettyIdentifier = getPrettyIdentifier(inferredType);
|
|
34
|
+
return createSummaryValue(prettyIdentifier, defaultValue);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return !isTooLongForDefaultValueSummary(defaultValue) ? createSummaryValue(defaultValue) : createSummaryValue(ELEMENT_CAPTION, defaultValue);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function createDefaultValue(defaultValue) {
|
|
42
|
+
try {
|
|
43
|
+
var inspectionResult = inspectValue(defaultValue);
|
|
44
|
+
|
|
45
|
+
switch (inspectionResult.inferredType.type) {
|
|
46
|
+
case InspectionType.OBJECT:
|
|
47
|
+
return generateObject(inspectionResult);
|
|
48
|
+
|
|
49
|
+
case InspectionType.FUNCTION:
|
|
50
|
+
return generateFunc(inspectionResult);
|
|
51
|
+
|
|
52
|
+
case InspectionType.ELEMENT:
|
|
53
|
+
return generateElement(defaultValue, inspectionResult);
|
|
54
|
+
|
|
55
|
+
case InspectionType.ARRAY:
|
|
56
|
+
return generateArray(inspectionResult);
|
|
57
|
+
|
|
58
|
+
default:
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
} catch (e) {
|
|
62
|
+
// eslint-disable-next-line no-console
|
|
63
|
+
console.error(e);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return null;
|
|
67
|
+
}
|