@storybook/react 7.0.0-alpha.2 → 7.0.0-alpha.20

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/dist/chunk-X53CQCCB.mjs +1 -0
  2. package/dist/config.d.ts +24 -0
  3. package/dist/config.js +7 -0
  4. package/dist/config.mjs +7 -0
  5. package/dist/index.d.ts +173 -0
  6. package/dist/index.js +1 -0
  7. package/dist/index.mjs +1 -0
  8. package/dist/types-9f8d440a.d.ts +17 -0
  9. package/package.json +39 -14
  10. package/preview.js +1 -1
  11. package/LICENSE +0 -21
  12. package/dist/cjs/config.js +0 -43
  13. package/dist/cjs/docs/config.js +0 -25
  14. package/dist/cjs/docs/extractArgTypes.js +0 -47
  15. package/dist/cjs/docs/extractProps.js +0 -57
  16. package/dist/cjs/docs/jsxDecorator.js +0 -210
  17. package/dist/cjs/docs/lib/captions.js +0 -18
  18. package/dist/cjs/docs/lib/componentTypes.js +0 -14
  19. package/dist/cjs/docs/lib/defaultValues/createDefaultValue.js +0 -86
  20. package/dist/cjs/docs/lib/defaultValues/createFromRawDefaultProp.js +0 -205
  21. package/dist/cjs/docs/lib/defaultValues/generateArray.js +0 -31
  22. package/dist/cjs/docs/lib/defaultValues/generateObject.js +0 -31
  23. package/dist/cjs/docs/lib/defaultValues/index.js +0 -31
  24. package/dist/cjs/docs/lib/defaultValues/prettyIdentifier.js +0 -36
  25. package/dist/cjs/docs/lib/generateCode.js +0 -74
  26. package/dist/cjs/docs/lib/index.js +0 -57
  27. package/dist/cjs/docs/lib/inspection/acornParser.js +0 -230
  28. package/dist/cjs/docs/lib/inspection/index.js +0 -31
  29. package/dist/cjs/docs/lib/inspection/inspectValue.js +0 -24
  30. package/dist/cjs/docs/lib/inspection/types.js +0 -19
  31. package/dist/cjs/docs/lib/isHtmlTag.js +0 -14
  32. package/dist/cjs/docs/propTypes/createType.js +0 -456
  33. package/dist/cjs/docs/propTypes/generateFuncSignature.js +0 -68
  34. package/dist/cjs/docs/propTypes/handleProp.js +0 -52
  35. package/dist/cjs/docs/propTypes/rawDefaultPropResolvers.js +0 -43
  36. package/dist/cjs/docs/propTypes/sortProps.js +0 -21
  37. package/dist/cjs/docs/react-argtypes.stories.js +0 -67
  38. package/dist/cjs/docs/typeScript/handleProp.js +0 -38
  39. package/dist/cjs/index.js +0 -98
  40. package/dist/cjs/preview/config.js +0 -19
  41. package/dist/cjs/preview/globals.js +0 -13
  42. package/dist/cjs/preview/index.js +0 -44
  43. package/dist/cjs/preview/render.js +0 -165
  44. package/dist/cjs/preview/types-6-0.js +0 -5
  45. package/dist/cjs/preview/types-6-3.js +0 -18
  46. package/dist/cjs/preview/types-7-0.js +0 -5
  47. package/dist/cjs/preview/types.js +0 -5
  48. package/dist/cjs/testing/index.js +0 -112
  49. package/dist/esm/config.js +0 -6
  50. package/dist/esm/docs/config.js +0 -12
  51. package/dist/esm/docs/extractArgTypes.js +0 -37
  52. package/dist/esm/docs/extractProps.js +0 -42
  53. package/dist/esm/docs/jsxDecorator.js +0 -170
  54. package/dist/esm/docs/lib/captions.js +0 -6
  55. package/dist/esm/docs/lib/componentTypes.js +0 -2
  56. package/dist/esm/docs/lib/defaultValues/createDefaultValue.js +0 -72
  57. package/dist/esm/docs/lib/defaultValues/createFromRawDefaultProp.js +0 -182
  58. package/dist/esm/docs/lib/defaultValues/generateArray.js +0 -21
  59. package/dist/esm/docs/lib/defaultValues/generateObject.js +0 -21
  60. package/dist/esm/docs/lib/defaultValues/index.js +0 -2
  61. package/dist/esm/docs/lib/defaultValues/prettyIdentifier.js +0 -24
  62. package/dist/esm/docs/lib/generateCode.js +0 -59
  63. package/dist/esm/docs/lib/index.js +0 -4
  64. package/dist/esm/docs/lib/inspection/acornParser.js +0 -211
  65. package/dist/esm/docs/lib/inspection/index.js +0 -2
  66. package/dist/esm/docs/lib/inspection/inspectValue.js +0 -15
  67. package/dist/esm/docs/lib/inspection/types.js +0 -12
  68. package/dist/esm/docs/lib/isHtmlTag.js +0 -4
  69. package/dist/esm/docs/propTypes/createType.js +0 -445
  70. package/dist/esm/docs/propTypes/generateFuncSignature.js +0 -57
  71. package/dist/esm/docs/propTypes/handleProp.js +0 -39
  72. package/dist/esm/docs/propTypes/rawDefaultPropResolvers.js +0 -31
  73. package/dist/esm/docs/propTypes/sortProps.js +0 -14
  74. package/dist/esm/docs/react-argtypes.stories.js +0 -54
  75. package/dist/esm/docs/typeScript/handleProp.js +0 -28
  76. package/dist/esm/index.js +0 -5
  77. package/dist/esm/preview/config.js +0 -1
  78. package/dist/esm/preview/globals.js +0 -8
  79. package/dist/esm/preview/index.js +0 -21
  80. package/dist/esm/preview/render.js +0 -141
  81. package/dist/esm/preview/types-6-0.js +0 -1
  82. package/dist/esm/preview/types-6-3.js +0 -10
  83. package/dist/esm/preview/types-7-0.js +0 -1
  84. package/dist/esm/preview/types.js +0 -1
  85. package/dist/esm/testing/index.js +0 -96
  86. package/dist/types/config.d.ts +0 -10
  87. package/dist/types/docs/config.d.ts +0 -10
  88. package/dist/types/docs/extractArgTypes.d.ts +0 -2
  89. package/dist/types/docs/extractProps.d.ts +0 -5
  90. package/dist/types/docs/jsxDecorator.d.ts +0 -23
  91. package/dist/types/docs/lib/captions.d.ts +0 -6
  92. package/dist/types/docs/lib/componentTypes.d.ts +0 -2
  93. package/dist/types/docs/lib/defaultValues/createDefaultValue.d.ts +0 -2
  94. package/dist/types/docs/lib/defaultValues/createFromRawDefaultProp.d.ts +0 -11
  95. package/dist/types/docs/lib/defaultValues/generateArray.d.ts +0 -3
  96. package/dist/types/docs/lib/defaultValues/generateObject.d.ts +0 -3
  97. package/dist/types/docs/lib/defaultValues/index.d.ts +0 -2
  98. package/dist/types/docs/lib/defaultValues/prettyIdentifier.d.ts +0 -4
  99. package/dist/types/docs/lib/generateCode.d.ts +0 -3
  100. package/dist/types/docs/lib/index.d.ts +0 -4
  101. package/dist/types/docs/lib/inspection/acornParser.d.ts +0 -7
  102. package/dist/types/docs/lib/inspection/index.d.ts +0 -2
  103. package/dist/types/docs/lib/inspection/inspectValue.d.ts +0 -2
  104. package/dist/types/docs/lib/inspection/types.d.ts +0 -50
  105. package/dist/types/docs/lib/isHtmlTag.d.ts +0 -1
  106. package/dist/types/docs/propTypes/createType.d.ts +0 -2
  107. package/dist/types/docs/propTypes/generateFuncSignature.d.ts +0 -4
  108. package/dist/types/docs/propTypes/handleProp.d.ts +0 -5
  109. package/dist/types/docs/propTypes/rawDefaultPropResolvers.d.ts +0 -1
  110. package/dist/types/docs/propTypes/sortProps.d.ts +0 -4
  111. package/dist/types/docs/react-argtypes.stories.d.ts +0 -1
  112. package/dist/types/docs/typeScript/handleProp.d.ts +0 -3
  113. package/dist/types/index.d.ts +0 -4
  114. package/dist/types/preview/config.d.ts +0 -1
  115. package/dist/types/preview/globals.d.ts +0 -1
  116. package/dist/types/preview/index.d.ts +0 -25
  117. package/dist/types/preview/render.d.ts +0 -5
  118. package/dist/types/preview/types-6-0.d.ts +0 -35
  119. package/dist/types/preview/types-6-3.d.ts +0 -40
  120. package/dist/types/preview/types-7-0.d.ts +0 -21
  121. package/dist/types/preview/types.d.ts +0 -16
  122. package/dist/types/testing/index.d.ts +0 -84
@@ -1,74 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.generateArrayCode = generateArrayCode;
7
- exports.generateCode = generateCode;
8
- exports.generateObjectCode = generateObjectCode;
9
-
10
- var _escodegen = require("escodegen");
11
-
12
- var _tsDedent = _interopRequireDefault(require("ts-dedent"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- const BASIC_OPTIONS = {
17
- format: {
18
- indent: {
19
- style: ' '
20
- },
21
- semicolons: false
22
- }
23
- };
24
- const COMPACT_OPTIONS = Object.assign({}, BASIC_OPTIONS, {
25
- format: {
26
- newline: ''
27
- }
28
- });
29
- const PRETTY_OPTIONS = Object.assign({}, BASIC_OPTIONS);
30
-
31
- function generateCode(ast, compact = false) {
32
- return (0, _escodegen.generate)(ast, compact ? COMPACT_OPTIONS : PRETTY_OPTIONS);
33
- }
34
-
35
- function generateObjectCode(ast, compact = false) {
36
- return !compact ? generateCode(ast) : generateCompactObjectCode(ast);
37
- }
38
-
39
- function generateCompactObjectCode(ast) {
40
- let result = generateCode(ast, true); // Cannot get escodegen to add a space before the last } with the compact mode settings.
41
- // Fix it until a better solution is found.
42
-
43
- if (!result.endsWith(' }')) {
44
- result = `${result.slice(0, -1)} }`;
45
- }
46
-
47
- return result;
48
- }
49
-
50
- function generateArrayCode(ast, compact = false) {
51
- return !compact ? generateMultilineArrayCode(ast) : generateCompactArrayCode(ast);
52
- }
53
-
54
- function generateMultilineArrayCode(ast) {
55
- let result = generateCode(ast); // escodegen add extra spacing before the closing bracket of a multiple line array with a nested object.
56
- // Fix it until a better solution is found.
57
-
58
- if (result.endsWith(' }]')) {
59
- result = (0, _tsDedent.default)(result);
60
- }
61
-
62
- return result;
63
- }
64
-
65
- function generateCompactArrayCode(ast) {
66
- let result = generateCode(ast, true); // escodegen add extra an extra before the opening bracket of a compact array that contains primitive values.
67
- // Fix it until a better solution is found.
68
-
69
- if (result.startsWith('[ ')) {
70
- result = result.replace('[ ', '[');
71
- }
72
-
73
- return result;
74
- }
@@ -1,57 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- var _captions = require("./captions");
8
-
9
- Object.keys(_captions).forEach(function (key) {
10
- if (key === "default" || key === "__esModule") return;
11
- if (key in exports && exports[key] === _captions[key]) return;
12
- Object.defineProperty(exports, key, {
13
- enumerable: true,
14
- get: function () {
15
- return _captions[key];
16
- }
17
- });
18
- });
19
-
20
- var _isHtmlTag = require("./isHtmlTag");
21
-
22
- Object.keys(_isHtmlTag).forEach(function (key) {
23
- if (key === "default" || key === "__esModule") return;
24
- if (key in exports && exports[key] === _isHtmlTag[key]) return;
25
- Object.defineProperty(exports, key, {
26
- enumerable: true,
27
- get: function () {
28
- return _isHtmlTag[key];
29
- }
30
- });
31
- });
32
-
33
- var _generateCode = require("./generateCode");
34
-
35
- Object.keys(_generateCode).forEach(function (key) {
36
- if (key === "default" || key === "__esModule") return;
37
- if (key in exports && exports[key] === _generateCode[key]) return;
38
- Object.defineProperty(exports, key, {
39
- enumerable: true,
40
- get: function () {
41
- return _generateCode[key];
42
- }
43
- });
44
- });
45
-
46
- var _componentTypes = require("./componentTypes");
47
-
48
- Object.keys(_componentTypes).forEach(function (key) {
49
- if (key === "default" || key === "__esModule") return;
50
- if (key in exports && exports[key] === _componentTypes[key]) return;
51
- Object.defineProperty(exports, key, {
52
- enumerable: true,
53
- get: function () {
54
- return _componentTypes[key];
55
- }
56
- });
57
- });
@@ -1,230 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.parse = parse;
7
-
8
- var _acorn = require("acorn");
9
-
10
- var _acornJsx = _interopRequireDefault(require("acorn-jsx"));
11
-
12
- var acornWalk = _interopRequireWildcard(require("acorn-walk"));
13
-
14
- var _types = require("./types");
15
-
16
- 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); }
17
-
18
- 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; }
19
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
- const ACORN_WALK_VISITORS = Object.assign({}, acornWalk.base, {
23
- JSXElement: () => {}
24
- });
25
-
26
- const acornParser = _acorn.Parser.extend((0, _acornJsx.default)()); // Cannot use "estree.Identifier" type because this function also support "JSXIdentifier".
27
-
28
-
29
- function extractIdentifierName(identifierNode) {
30
- return identifierNode != null ? identifierNode.name : null;
31
- }
32
-
33
- function filterAncestors(ancestors) {
34
- return ancestors.filter(x => x.type === 'ObjectExpression' || x.type === 'ArrayExpression');
35
- }
36
-
37
- function calculateNodeDepth(node) {
38
- const depths = [];
39
- acornWalk.ancestor( // @ts-ignore
40
- node, {
41
- ObjectExpression(_, ancestors) {
42
- depths.push(filterAncestors(ancestors).length);
43
- },
44
-
45
- ArrayExpression(_, ancestors) {
46
- depths.push(filterAncestors(ancestors).length);
47
- }
48
-
49
- }, ACORN_WALK_VISITORS);
50
- return Math.max(...depths);
51
- }
52
-
53
- function parseIdentifier(identifierNode) {
54
- return {
55
- inferredType: {
56
- type: _types.InspectionType.IDENTIFIER,
57
- identifier: extractIdentifierName(identifierNode)
58
- },
59
- ast: identifierNode
60
- };
61
- }
62
-
63
- function parseLiteral(literalNode) {
64
- return {
65
- inferredType: {
66
- type: _types.InspectionType.LITERAL
67
- },
68
- ast: literalNode
69
- };
70
- }
71
-
72
- function parseFunction(funcNode) {
73
- let innerJsxElementNode; // If there is at least a JSXElement in the body of the function, then it's a React component.
74
-
75
- acornWalk.simple( // @ts-ignore
76
- funcNode.body, {
77
- JSXElement(node) {
78
- innerJsxElementNode = node;
79
- }
80
-
81
- }, ACORN_WALK_VISITORS);
82
- const isJsx = innerJsxElementNode != null;
83
- const inferredType = {
84
- type: isJsx ? _types.InspectionType.ELEMENT : _types.InspectionType.FUNCTION,
85
- params: funcNode.params,
86
- hasParams: funcNode.params.length !== 0
87
- };
88
- const identifierName = extractIdentifierName(funcNode.id);
89
-
90
- if (identifierName != null) {
91
- inferredType.identifier = identifierName;
92
- }
93
-
94
- return {
95
- inferredType,
96
- ast: funcNode
97
- };
98
- }
99
-
100
- function parseClass(classNode) {
101
- let innerJsxElementNode; // If there is at least a JSXElement in the body of the class, then it's a React component.
102
-
103
- acornWalk.simple( // @ts-ignore
104
- classNode.body, {
105
- JSXElement(node) {
106
- innerJsxElementNode = node;
107
- }
108
-
109
- }, ACORN_WALK_VISITORS);
110
- const inferredType = {
111
- type: innerJsxElementNode != null ? _types.InspectionType.ELEMENT : _types.InspectionType.CLASS,
112
- identifier: extractIdentifierName(classNode.id)
113
- };
114
- return {
115
- inferredType,
116
- ast: classNode
117
- };
118
- }
119
-
120
- function parseJsxElement(jsxElementNode) {
121
- const inferredType = {
122
- type: _types.InspectionType.ELEMENT
123
- };
124
- const identifierName = extractIdentifierName(jsxElementNode.openingElement.name);
125
-
126
- if (identifierName != null) {
127
- inferredType.identifier = identifierName;
128
- }
129
-
130
- return {
131
- inferredType,
132
- ast: jsxElementNode
133
- };
134
- }
135
-
136
- function parseCall(callNode) {
137
- const identifierNode = callNode.callee.type === 'MemberExpression' ? callNode.callee.property : callNode.callee;
138
- const identifierName = extractIdentifierName(identifierNode);
139
-
140
- if (identifierName === 'shape') {
141
- return parseObject(callNode.arguments[0]);
142
- }
143
-
144
- return null;
145
- }
146
-
147
- function parseObject(objectNode) {
148
- return {
149
- inferredType: {
150
- type: _types.InspectionType.OBJECT,
151
- depth: calculateNodeDepth(objectNode)
152
- },
153
- ast: objectNode
154
- };
155
- }
156
-
157
- function parseArray(arrayNode) {
158
- return {
159
- inferredType: {
160
- type: _types.InspectionType.ARRAY,
161
- depth: calculateNodeDepth(arrayNode)
162
- },
163
- ast: arrayNode
164
- };
165
- } // Cannot set "expression" type to "estree.Expression" because the type doesn't include JSX.
166
-
167
-
168
- function parseExpression(expression) {
169
- switch (expression.type) {
170
- case 'Identifier':
171
- return parseIdentifier(expression);
172
-
173
- case 'Literal':
174
- return parseLiteral(expression);
175
-
176
- case 'FunctionExpression':
177
- case 'ArrowFunctionExpression':
178
- return parseFunction(expression);
179
-
180
- case 'ClassExpression':
181
- return parseClass(expression);
182
-
183
- case 'JSXElement':
184
- return parseJsxElement(expression);
185
-
186
- case 'CallExpression':
187
- return parseCall(expression);
188
-
189
- case 'ObjectExpression':
190
- return parseObject(expression);
191
-
192
- case 'ArrayExpression':
193
- return parseArray(expression);
194
-
195
- default:
196
- return null;
197
- }
198
- }
199
-
200
- function parse(value) {
201
- const ast = acornParser.parse(`(${value})`);
202
- let parsingResult = {
203
- inferredType: {
204
- type: _types.InspectionType.UNKNOWN
205
- },
206
- ast
207
- };
208
-
209
- if (ast.body[0] != null) {
210
- const rootNode = ast.body[0];
211
-
212
- switch (rootNode.type) {
213
- case 'ExpressionStatement':
214
- {
215
- const expressionResult = parseExpression(rootNode.expression);
216
-
217
- if (expressionResult != null) {
218
- parsingResult = expressionResult;
219
- }
220
-
221
- break;
222
- }
223
-
224
- default:
225
- break;
226
- }
227
- }
228
-
229
- return parsingResult;
230
- }
@@ -1,31 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- var _types = require("./types");
8
-
9
- Object.keys(_types).forEach(function (key) {
10
- if (key === "default" || key === "__esModule") return;
11
- if (key in exports && exports[key] === _types[key]) return;
12
- Object.defineProperty(exports, key, {
13
- enumerable: true,
14
- get: function () {
15
- return _types[key];
16
- }
17
- });
18
- });
19
-
20
- var _inspectValue = require("./inspectValue");
21
-
22
- Object.keys(_inspectValue).forEach(function (key) {
23
- if (key === "default" || key === "__esModule") return;
24
- if (key in exports && exports[key] === _inspectValue[key]) return;
25
- Object.defineProperty(exports, key, {
26
- enumerable: true,
27
- get: function () {
28
- return _inspectValue[key];
29
- }
30
- });
31
- });
@@ -1,24 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.inspectValue = inspectValue;
7
-
8
- var _acornParser = require("./acornParser");
9
-
10
- var _types = require("./types");
11
-
12
- function inspectValue(value) {
13
- try {
14
- const parsingResult = (0, _acornParser.parse)(value);
15
- return Object.assign({}, parsingResult);
16
- } catch (e) {// do nothing.
17
- }
18
-
19
- return {
20
- inferredType: {
21
- type: _types.InspectionType.UNKNOWN
22
- }
23
- };
24
- }
@@ -1,19 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.InspectionType = void 0;
7
- let InspectionType;
8
- exports.InspectionType = InspectionType;
9
-
10
- (function (InspectionType) {
11
- InspectionType["IDENTIFIER"] = "Identifier";
12
- InspectionType["LITERAL"] = "Literal";
13
- InspectionType["OBJECT"] = "Object";
14
- InspectionType["ARRAY"] = "Array";
15
- InspectionType["FUNCTION"] = "Function";
16
- InspectionType["CLASS"] = "Class";
17
- InspectionType["ELEMENT"] = "Element";
18
- InspectionType["UNKNOWN"] = "Unknown";
19
- })(InspectionType || (exports.InspectionType = InspectionType = {}));
@@ -1,14 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isHtmlTag = isHtmlTag;
7
-
8
- var _htmlTags = _interopRequireDefault(require("html-tags"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- function isHtmlTag(tagName) {
13
- return _htmlTags.default.includes(tagName.toLowerCase());
14
- }