@workday/canvas-kit-docs 9.0.0-alpha.368-next.6 → 9.0.0-alpha.382-next.2
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/es6/docgen/createTraversals.js +41 -22
- package/dist/es6/docgen/docParser.js +285 -257
- package/dist/es6/docgen/getExternalSymbol.js +2 -2
- package/dist/es6/docgen/plugins/componentParser.js +28 -33
- package/dist/es6/docgen/plugins/enhancedComponentParser.js +211 -150
- package/dist/es6/docgen/plugins/modelParser.js +139 -79
- package/dist/es6/docgen/traversals.js +396 -397
- package/dist/es6/docgen/traverse.js +8 -9
- package/dist/es6/lib/DescriptionTooltip.js +1 -1
- package/dist/es6/lib/MDXElements.js +13 -39
- package/dist/es6/lib/MoreTooltip.js +21 -41
- package/dist/es6/lib/Specifications.js +30 -34
- package/dist/es6/lib/StylePropsTable.js +8 -9
- package/dist/es6/lib/Table.js +19 -30
- package/dist/es6/lib/Value.js +13 -17
- package/dist/es6/lib/docs.js +701 -397
- package/dist/es6/lib/widgetUtils.js +44 -76
- package/dist/es6/lib/widgets/array.js +1 -2
- package/dist/es6/lib/widgets/callExpression.js +4 -5
- package/dist/es6/lib/widgets/canvasColor.js +2 -2
- package/dist/es6/lib/widgets/component.js +1 -2
- package/dist/es6/lib/widgets/conditional.js +1 -2
- package/dist/es6/lib/widgets/enhancedComponent.js +19 -24
- package/dist/es6/lib/widgets/external.js +1 -4
- package/dist/es6/lib/widgets/function.js +5 -7
- package/dist/es6/lib/widgets/intersection.js +3 -4
- package/dist/es6/lib/widgets/model.js +4 -6
- package/dist/es6/lib/widgets/object.js +2 -3
- package/dist/es6/lib/widgets/parenthesis.js +1 -2
- package/dist/es6/lib/widgets/primitives.js +17 -39
- package/dist/es6/lib/widgets/qualifiedName.js +1 -2
- package/dist/es6/lib/widgets/symbol.js +1 -2
- package/dist/es6/lib/widgets/tuple.js +2 -3
- package/dist/es6/lib/widgets/typeParameter.js +1 -2
- package/dist/es6/lib/widgets/union.js +3 -4
- package/dist/es6/mdx/installBlock.js +6 -7
- package/dist/es6/mdx/style-props/examples/Background.js +5 -16
- package/dist/es6/mdx/style-props/examples/Border.js +5 -16
- package/dist/es6/mdx/style-props/examples/Color.js +5 -16
- package/dist/es6/mdx/style-props/examples/Depth.js +5 -16
- package/dist/es6/mdx/style-props/examples/Flex.js +11 -22
- package/dist/es6/mdx/style-props/examples/FlexItem.js +10 -21
- package/dist/es6/mdx/style-props/examples/Grid.js +6 -17
- package/dist/es6/mdx/style-props/examples/GridItem.js +6 -17
- package/dist/es6/mdx/style-props/examples/Layout.js +5 -16
- package/dist/es6/mdx/style-props/examples/Other.js +5 -16
- package/dist/es6/mdx/style-props/examples/Position.js +5 -16
- package/dist/es6/mdx/style-props/examples/Space.js +6 -17
- package/dist/es6/mdx/style-props/examples/Text.js +2 -2
- package/dist/es6/mdx/welcomePage.js +3 -3
- package/dist/mdx/9.0-UPGRADE-GUIDE.mdx +30 -3
- package/dist/mdx/preview-react/text-area/examples/Alert.tsx +1 -1
- package/dist/mdx/preview-react/text-input/examples/Alert.tsx +1 -1
- package/dist/mdx/preview-react/text-input/examples/ThemedAlert.tsx +5 -2
- package/dist/mdx/react/banner/examples/StickyAnimation.tsx +7 -5
- package/dist/mdx/react/common/examples/ResponsiveViewport.tsx +2 -3
- package/package.json +5 -5
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// prettier-ignore
|
|
2
|
-
|
|
2
|
+
const externalSymbols = {
|
|
3
3
|
lib: {
|
|
4
4
|
Promise: 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise',
|
|
5
5
|
Function: 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function',
|
|
@@ -25,6 +25,6 @@ var externalSymbols = {
|
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
27
|
export function getExternalSymbol(key, declarationFile) {
|
|
28
|
-
|
|
28
|
+
const lib = (declarationFile === null || declarationFile === void 0 ? void 0 : declarationFile.includes('react')) ? 'react' : 'lib';
|
|
29
29
|
return externalSymbols[lib][key] || undefined;
|
|
30
30
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
import { createParserPlugin, filterObjectProperties, getValueDeclaration, getDefaultFromTags, isObject, isExportedSymbol, getValidDefaultFromNode, } from '../docParser';
|
|
3
3
|
import t from '../traverse';
|
|
4
|
-
export
|
|
4
|
+
export const componentParser = createParserPlugin((node, parser) => {
|
|
5
5
|
var _a, _b;
|
|
6
6
|
/**
|
|
7
7
|
* We'll look for class components that extend from `React.Component` or `Component`
|
|
@@ -17,7 +17,7 @@ export var componentParser = createParserPlugin(function (node, parser) {
|
|
|
17
17
|
node.heritageClauses[0] &&
|
|
18
18
|
t.isHeritageClause(node.heritageClauses[0]) &&
|
|
19
19
|
node.heritageClauses[0].types[0]) {
|
|
20
|
-
|
|
20
|
+
const clause = node.heritageClauses[0].types[0];
|
|
21
21
|
if ((clause &&
|
|
22
22
|
// `class A extends Component`
|
|
23
23
|
t.isExpressionWithTypeArguments(clause) &&
|
|
@@ -33,23 +33,19 @@ export var componentParser = createParserPlugin(function (node, parser) {
|
|
|
33
33
|
if (clause.typeArguments &&
|
|
34
34
|
clause.typeArguments[0] &&
|
|
35
35
|
t.isTypeReference(clause.typeArguments[0])) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
var defaultProps = getDefaultsFromDefaultProps(parser, defaultPropNode);
|
|
41
|
-
var props = getComponentProps(parser, type, defaultProps);
|
|
36
|
+
const type = parser.checker.getTypeAtLocation(clause.typeArguments[0]);
|
|
37
|
+
const defaultPropNode = (_a = node.members.find(m => t.isPropertyDeclaration(m) && t.isIdentifier(m.name) && m.name.text === 'defaultProps')) === null || _a === void 0 ? void 0 : _a.initializer;
|
|
38
|
+
const defaultProps = getDefaultsFromDefaultProps(parser, defaultPropNode);
|
|
39
|
+
const props = getComponentProps(parser, type, defaultProps);
|
|
42
40
|
/**
|
|
43
41
|
* Get a displayName if there is one
|
|
44
42
|
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
})) === null || _b === void 0 ? void 0 : _b.initializer.text;
|
|
52
|
-
return { kind: 'component', props: props, displayName: displayName };
|
|
43
|
+
const displayName = (_b = node.members.find(m => t.isPropertyDeclaration(m) &&
|
|
44
|
+
t.isIdentifier(m.name) &&
|
|
45
|
+
m.name.text === 'displayName' &&
|
|
46
|
+
m.initializer &&
|
|
47
|
+
t.isStringLiteral(m.initializer))) === null || _b === void 0 ? void 0 : _b.initializer.text;
|
|
48
|
+
return { kind: 'component', props, displayName };
|
|
53
49
|
}
|
|
54
50
|
// We couldn't find any props
|
|
55
51
|
return {
|
|
@@ -127,7 +123,7 @@ export function isComponent(returnType) {
|
|
|
127
123
|
return returnType.types.some(isComponent);
|
|
128
124
|
}
|
|
129
125
|
if (isObject(returnType)) {
|
|
130
|
-
return returnType.getProperties().some(
|
|
126
|
+
return returnType.getProperties().some(s => s.name === 'props');
|
|
131
127
|
}
|
|
132
128
|
return false;
|
|
133
129
|
}
|
|
@@ -141,13 +137,12 @@ export function isComponent(returnType) {
|
|
|
141
137
|
* @param type The type of the props. We use a type because there are many ways the prop interface
|
|
142
138
|
* @param defaultProps Optional record of found default props could be created
|
|
143
139
|
*/
|
|
144
|
-
export function getComponentProps(parser, type, defaultProps) {
|
|
145
|
-
|
|
146
|
-
var props = type
|
|
140
|
+
export function getComponentProps(parser, type, defaultProps = {}) {
|
|
141
|
+
const props = type
|
|
147
142
|
.getProperties()
|
|
148
|
-
.map(
|
|
149
|
-
|
|
150
|
-
|
|
143
|
+
.map(symbol => {
|
|
144
|
+
const defaultValue = defaultProps[symbol.name] || getDefaultFromTags(symbol.getJsDocTags());
|
|
145
|
+
const value = parser.getValueFromNode(getValueDeclaration(symbol));
|
|
151
146
|
if (value.kind === 'property') {
|
|
152
147
|
value.defaultValue = defaultValue;
|
|
153
148
|
}
|
|
@@ -162,7 +157,7 @@ export function getComponentProps(parser, type, defaultProps) {
|
|
|
162
157
|
*/
|
|
163
158
|
export function getDefaultsFromDefaultProps(parser, node) {
|
|
164
159
|
if (node && t.isObjectLiteralExpression(node)) {
|
|
165
|
-
return node.properties.reduce(
|
|
160
|
+
return node.properties.reduce((result, property) => {
|
|
166
161
|
if (t.isPropertyAssignment(property) && t.isIdentifier(property.name)) {
|
|
167
162
|
result[property.name.text] = parser.getValueFromNode(property.initializer);
|
|
168
163
|
}
|
|
@@ -179,9 +174,9 @@ export function getDefaultsFromDefaultProps(parser, node) {
|
|
|
179
174
|
*/
|
|
180
175
|
export function getDefaultsFromObjectBindingPattern(parser, node) {
|
|
181
176
|
if (t.isObjectBindingPattern(node)) {
|
|
182
|
-
return node.elements.reduce(
|
|
177
|
+
return node.elements.reduce((result, element) => {
|
|
183
178
|
if (t.isBindingElement(element) && t.isIdentifier(element.name) && element.initializer) {
|
|
184
|
-
|
|
179
|
+
const defaultValue = getValidDefaultFromNode(parser, element.initializer);
|
|
185
180
|
if (defaultValue) {
|
|
186
181
|
result[element.name.text] = defaultValue;
|
|
187
182
|
}
|
|
@@ -197,24 +192,24 @@ function getComponentFromFunction(parser, node) {
|
|
|
197
192
|
*/
|
|
198
193
|
if (ts.isFunctionLike(node)) {
|
|
199
194
|
// Get a signature and test the return type for JSX props
|
|
200
|
-
|
|
195
|
+
const signature = parser.checker.getSignatureFromDeclaration(node);
|
|
201
196
|
if (signature) {
|
|
202
|
-
|
|
197
|
+
const returnType = signature.getReturnType();
|
|
203
198
|
if (isComponent(returnType)) {
|
|
204
199
|
if (signature.parameters[0]) {
|
|
205
|
-
|
|
200
|
+
const declaration = getValueDeclaration(signature.parameters[0]);
|
|
206
201
|
if (declaration && t.isParameter(declaration)) {
|
|
207
|
-
|
|
202
|
+
const type = parser.checker.getTypeAtLocation(declaration);
|
|
208
203
|
if (!isObject(type) && !type.isIntersection()) {
|
|
209
204
|
// This is not a component. We may still get some false positives, but this decreases
|
|
210
205
|
// the likelihood
|
|
211
206
|
return undefined;
|
|
212
207
|
}
|
|
213
|
-
|
|
214
|
-
|
|
208
|
+
const defaults = getDefaultsFromObjectBindingPattern(parser, declaration.name);
|
|
209
|
+
const props = getComponentProps(parser, type, defaults);
|
|
215
210
|
return {
|
|
216
211
|
kind: 'component',
|
|
217
|
-
props
|
|
212
|
+
props,
|
|
218
213
|
};
|
|
219
214
|
}
|
|
220
215
|
}
|