@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.
Files changed (57) hide show
  1. package/dist/es6/docgen/createTraversals.js +41 -22
  2. package/dist/es6/docgen/docParser.js +285 -257
  3. package/dist/es6/docgen/getExternalSymbol.js +2 -2
  4. package/dist/es6/docgen/plugins/componentParser.js +28 -33
  5. package/dist/es6/docgen/plugins/enhancedComponentParser.js +211 -150
  6. package/dist/es6/docgen/plugins/modelParser.js +139 -79
  7. package/dist/es6/docgen/traversals.js +396 -397
  8. package/dist/es6/docgen/traverse.js +8 -9
  9. package/dist/es6/lib/DescriptionTooltip.js +1 -1
  10. package/dist/es6/lib/MDXElements.js +13 -39
  11. package/dist/es6/lib/MoreTooltip.js +21 -41
  12. package/dist/es6/lib/Specifications.js +30 -34
  13. package/dist/es6/lib/StylePropsTable.js +8 -9
  14. package/dist/es6/lib/Table.js +19 -30
  15. package/dist/es6/lib/Value.js +13 -17
  16. package/dist/es6/lib/docs.js +701 -397
  17. package/dist/es6/lib/widgetUtils.js +44 -76
  18. package/dist/es6/lib/widgets/array.js +1 -2
  19. package/dist/es6/lib/widgets/callExpression.js +4 -5
  20. package/dist/es6/lib/widgets/canvasColor.js +2 -2
  21. package/dist/es6/lib/widgets/component.js +1 -2
  22. package/dist/es6/lib/widgets/conditional.js +1 -2
  23. package/dist/es6/lib/widgets/enhancedComponent.js +19 -24
  24. package/dist/es6/lib/widgets/external.js +1 -4
  25. package/dist/es6/lib/widgets/function.js +5 -7
  26. package/dist/es6/lib/widgets/intersection.js +3 -4
  27. package/dist/es6/lib/widgets/model.js +4 -6
  28. package/dist/es6/lib/widgets/object.js +2 -3
  29. package/dist/es6/lib/widgets/parenthesis.js +1 -2
  30. package/dist/es6/lib/widgets/primitives.js +17 -39
  31. package/dist/es6/lib/widgets/qualifiedName.js +1 -2
  32. package/dist/es6/lib/widgets/symbol.js +1 -2
  33. package/dist/es6/lib/widgets/tuple.js +2 -3
  34. package/dist/es6/lib/widgets/typeParameter.js +1 -2
  35. package/dist/es6/lib/widgets/union.js +3 -4
  36. package/dist/es6/mdx/installBlock.js +6 -7
  37. package/dist/es6/mdx/style-props/examples/Background.js +5 -16
  38. package/dist/es6/mdx/style-props/examples/Border.js +5 -16
  39. package/dist/es6/mdx/style-props/examples/Color.js +5 -16
  40. package/dist/es6/mdx/style-props/examples/Depth.js +5 -16
  41. package/dist/es6/mdx/style-props/examples/Flex.js +11 -22
  42. package/dist/es6/mdx/style-props/examples/FlexItem.js +10 -21
  43. package/dist/es6/mdx/style-props/examples/Grid.js +6 -17
  44. package/dist/es6/mdx/style-props/examples/GridItem.js +6 -17
  45. package/dist/es6/mdx/style-props/examples/Layout.js +5 -16
  46. package/dist/es6/mdx/style-props/examples/Other.js +5 -16
  47. package/dist/es6/mdx/style-props/examples/Position.js +5 -16
  48. package/dist/es6/mdx/style-props/examples/Space.js +6 -17
  49. package/dist/es6/mdx/style-props/examples/Text.js +2 -2
  50. package/dist/es6/mdx/welcomePage.js +3 -3
  51. package/dist/mdx/9.0-UPGRADE-GUIDE.mdx +30 -3
  52. package/dist/mdx/preview-react/text-area/examples/Alert.tsx +1 -1
  53. package/dist/mdx/preview-react/text-input/examples/Alert.tsx +1 -1
  54. package/dist/mdx/preview-react/text-input/examples/ThemedAlert.tsx +5 -2
  55. package/dist/mdx/react/banner/examples/StickyAnimation.tsx +7 -5
  56. package/dist/mdx/react/common/examples/ResponsiveViewport.tsx +2 -3
  57. package/package.json +5 -5
@@ -1,42 +1,26 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
13
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
14
- to[j] = from[i];
15
- return to;
16
- };
17
1
  import ts from 'typescript';
18
2
  import { createParserPlugin, defaultJSDoc, findDocComment, getDefaultsFromObjectBindingParameter, getSymbolFromNode, getValueDeclaration, unknownValue, filterObjectProperties, getDefaultFromTags, getValidDefaultFromNode, } from '../docParser';
19
3
  import t from '../traverse';
20
4
  /** Track if we've set a custom color symbol yet */
21
- var shouldCreateColorSymbol = true;
5
+ let shouldCreateColorSymbol = true;
22
6
  function dashCase(value) {
23
7
  return value
24
- .replace(/^([A-Z])/, function (s, l) { return l.toLowerCase(); })
25
- .replace(/([A-Z])/g, function (s, l) { return "-" + l.toLowerCase(); });
8
+ .replace(/^([A-Z])/, (s, l) => l.toLowerCase())
9
+ .replace(/([A-Z])/g, (s, l) => `-${l.toLowerCase()}`);
26
10
  }
27
11
  function isElemPropsJSXElement(node) {
28
12
  return (t.isJsxAttributes(node.attributes) &&
29
- node.attributes.properties.some(function (at) {
30
- return t.isJsxSpreadAttribute(at) &&
31
- t.isIdentifier(at.expression) &&
32
- at.expression.text === 'elemProps';
33
- }));
13
+ node.attributes.properties.some(at => t.isJsxSpreadAttribute(at) &&
14
+ t.isIdentifier(at.expression) &&
15
+ at.expression.text === 'elemProps'));
34
16
  }
35
17
  function getDefaultFromJSX(parser, node, propName) {
36
- var JSXElement = __spreadArray(__spreadArray([], t(node).find('JsxSelfClosingElement')), t(node).find('JsxOpeningElement')).find(isElemPropsJSXElement);
18
+ const JSXElement = [
19
+ ...t(node).find('JsxSelfClosingElement'),
20
+ ...t(node).find('JsxOpeningElement'),
21
+ ].find(isElemPropsJSXElement);
37
22
  if (JSXElement) {
38
- for (var _i = 0, _a = JSXElement.attributes.properties; _i < _a.length; _i++) {
39
- var attribute = _a[_i];
23
+ for (const attribute of JSXElement.attributes.properties) {
40
24
  /**
41
25
  * A JSXAttribute is the attribute and initializer
42
26
  *
@@ -100,7 +84,7 @@ expression) {
100
84
  return {
101
85
  kind: 'external',
102
86
  name: expression.text,
103
- url: "https://developer.mozilla.org/en-US/docs/Web/HTML/Element/" + expression.text,
87
+ url: `https://developer.mozilla.org/en-US/docs/Web/HTML/Element/${expression.text}`,
104
88
  };
105
89
  }
106
90
  else if (expression && t.isIdentifier(expression)) {
@@ -108,14 +92,14 @@ expression) {
108
92
  }
109
93
  return undefined;
110
94
  }
111
- export var enhancedComponentParser = createParserPlugin(function (node, parser) {
95
+ export const enhancedComponentParser = createParserPlugin((node, parser) => {
112
96
  var _a;
113
97
  /**
114
98
  * Filter out props from `@types/react`
115
99
  */
116
100
  if (t.isPropertySignature(node)) {
117
- var symbol = getSymbolFromNode(parser.checker, node);
118
- var declaration = getValueDeclaration(symbol);
101
+ const symbol = getSymbolFromNode(parser.checker, node);
102
+ const declaration = getValueDeclaration(symbol);
119
103
  if (declaration && declaration.getSourceFile().fileName.includes('@types/react')) {
120
104
  return { kind: 'unknown', value: 'unknown', text: 'empty' };
121
105
  }
@@ -130,12 +114,17 @@ export var enhancedComponentParser = createParserPlugin(function (node, parser)
130
114
  t.isLiteralType(node.indexType) &&
131
115
  t.isStringLiteral(node.indexType.literal) &&
132
116
  node.indexType.literal.text === 'color') {
133
- var fileName = ((_a = node.getSourceFile()) === null || _a === void 0 ? void 0 : _a.fileName) || '';
117
+ const fileName = ((_a = node.getSourceFile()) === null || _a === void 0 ? void 0 : _a.fileName) || '';
134
118
  if (shouldCreateColorSymbol) {
135
119
  shouldCreateColorSymbol = false;
136
- parser.symbols.push(__assign(__assign({ name: 'CanvasColorTokens', fileName: fileName }, defaultJSDoc), { type: {
120
+ parser.symbols.push({
121
+ name: 'CanvasColorTokens',
122
+ fileName,
123
+ ...defaultJSDoc,
124
+ type: {
137
125
  kind: 'canvasColor',
138
- } }));
126
+ },
127
+ });
139
128
  }
140
129
  return { kind: 'symbol', name: 'CanvasColorTokens' };
141
130
  }
@@ -149,8 +138,8 @@ export var enhancedComponentParser = createParserPlugin(function (node, parser)
149
138
  t.isIdentifier(node.typeName.right)) {
150
139
  return {
151
140
  kind: 'external',
152
- name: node.typeName.left.text + "." + node.typeName.right.text,
153
- url: "https://developer.mozilla.org/en-US/docs/Web/CSS/" + dashCase(node.typeName.right.text),
141
+ name: `${node.typeName.left.text}.${node.typeName.right.text}`,
142
+ url: `https://developer.mozilla.org/en-US/docs/Web/CSS/${dashCase(node.typeName.right.text)}`,
154
143
  };
155
144
  }
156
145
  /**
@@ -165,14 +154,14 @@ export var enhancedComponentParser = createParserPlugin(function (node, parser)
165
154
  t.isIdentifier(node.expression.expression) &&
166
155
  node.expression.expression.text === 'createSubModelElemPropsHook') {
167
156
  // first argument in `subModel`
168
- var modelArgument = node.expression.arguments[0];
169
- var otherElemPropsHook = node.arguments[1];
157
+ const modelArgument = node.expression.arguments[0];
158
+ const otherElemPropsHook = node.arguments[1];
170
159
  if (modelArgument &&
171
160
  otherElemPropsHook &&
172
161
  t.isIdentifier(modelArgument) &&
173
162
  t.isIdentifier(otherElemPropsHook)) {
174
- var modelName = modelArgument.text.replace('use', '');
175
- var otherElemPropsHookName = otherElemPropsHook.text;
163
+ const modelName = modelArgument.text.replace('use', '');
164
+ const otherElemPropsHookName = otherElemPropsHook.text;
176
165
  return {
177
166
  kind: 'callExpression',
178
167
  name: { kind: 'symbol', name: node.expression.expression.text },
@@ -180,10 +169,15 @@ export var enhancedComponentParser = createParserPlugin(function (node, parser)
180
169
  {
181
170
  kind: 'function',
182
171
  parameters: [
183
- __assign(__assign({ kind: 'parameter', name: 'model' }, defaultJSDoc), { type: {
172
+ {
173
+ kind: 'parameter',
174
+ name: 'model',
175
+ ...defaultJSDoc,
176
+ type: {
184
177
  kind: 'symbol',
185
178
  name: modelName,
186
- } }),
179
+ },
180
+ },
187
181
  ],
188
182
  returnType: {
189
183
  kind: 'symbol',
@@ -208,31 +202,49 @@ export var enhancedComponentParser = createParserPlugin(function (node, parser)
208
202
  t.isIdentifier(node.expression.expression) &&
209
203
  node.expression.expression.text === 'createElemPropsHook') {
210
204
  // first argument in `createElemPropsHook`
211
- var modelArgument = node.expression.arguments[0];
205
+ const modelArgument = node.expression.arguments[0];
212
206
  // first argument in the curried function of `createElemPropsHook`
213
207
  if (modelArgument && t.isIdentifier(modelArgument)) {
214
- var modelName = modelArgument.text.replace('use', '');
215
- var type = parser.checker.getTypeAtLocation(node.arguments[0]);
216
- var signature = type.getCallSignatures()[0];
217
- var elemProps = getElemPropsFromElemPropsHook(parser, signature);
218
- var returnType = getReturnTypeFromElemPropsHook(parser, signature);
219
- var parameters = [
220
- __assign(__assign({ kind: 'parameter', name: 'model' }, defaultJSDoc), { type: {
208
+ const modelName = modelArgument.text.replace('use', '');
209
+ const type = parser.checker.getTypeAtLocation(node.arguments[0]);
210
+ const signature = type.getCallSignatures()[0];
211
+ const elemProps = getElemPropsFromElemPropsHook(parser, signature);
212
+ const returnType = getReturnTypeFromElemPropsHook(parser, signature);
213
+ const parameters = [
214
+ {
215
+ kind: 'parameter',
216
+ name: 'model',
217
+ ...defaultJSDoc,
218
+ type: {
221
219
  kind: 'symbol',
222
220
  name: modelName,
223
- }, required: true }),
224
- __assign(__assign({ kind: 'parameter', name: 'elemProps' }, defaultJSDoc), { type: elemProps, required: false }),
225
- __assign(__assign({ kind: 'parameter', name: 'ref' }, defaultJSDoc), { type: {
221
+ },
222
+ required: true,
223
+ },
224
+ {
225
+ kind: 'parameter',
226
+ name: 'elemProps',
227
+ ...defaultJSDoc,
228
+ type: elemProps,
229
+ required: false,
230
+ },
231
+ {
232
+ kind: 'parameter',
233
+ name: 'ref',
234
+ ...defaultJSDoc,
235
+ type: {
226
236
  kind: 'external',
227
237
  name: 'React.Ref',
228
238
  url: 'https://reactjs.org/docs/refs-and-the-dom.html',
229
- }, required: false }),
239
+ },
240
+ required: false,
241
+ },
230
242
  ];
231
243
  return {
232
244
  kind: 'function',
233
245
  name: { kind: 'symbol', name: node.expression.expression.text },
234
- parameters: parameters,
235
- returnType: returnType,
246
+ parameters,
247
+ returnType,
236
248
  // model: modelName,
237
249
  // elemProps,
238
250
  // returnProps,
@@ -250,7 +262,7 @@ export var enhancedComponentParser = createParserPlugin(function (node, parser)
250
262
  return {
251
263
  kind: 'callExpression',
252
264
  name: { kind: 'symbol', name: node.initializer.expression.text },
253
- parameters: node.initializer.arguments.map(function (value) { return parser.getValueFromNode(value); }),
265
+ parameters: node.initializer.arguments.map(value => parser.getValueFromNode(value)),
254
266
  };
255
267
  }
256
268
  /**
@@ -275,13 +287,13 @@ export var enhancedComponentParser = createParserPlugin(function (node, parser)
275
287
  t.isIdentifier(node.name) &&
276
288
  node.initializer &&
277
289
  t.isCallExpression(node.initializer)) {
278
- var name_1 = node.name.text;
279
- var elemPropsHookValue_1 = getElemPropsHookValue(node.initializer, name_1);
280
- if (elemPropsHookValue_1) {
281
- return elemPropsHookValue_1;
290
+ const name = node.name.text;
291
+ const elemPropsHookValue = getElemPropsHookValue(node.initializer, name);
292
+ if (elemPropsHookValue) {
293
+ return elemPropsHookValue;
282
294
  }
283
295
  }
284
- var elemPropsHookValue = getElemPropsHookValue(node);
296
+ const elemPropsHookValue = getElemPropsHookValue(node);
285
297
  if (elemPropsHookValue) {
286
298
  return elemPropsHookValue;
287
299
  }
@@ -307,7 +319,7 @@ export var enhancedComponentParser = createParserPlugin(function (node, parser)
307
319
  t.isCallExpression(node.initializer.expression) &&
308
320
  t.isIdentifier(node.initializer.expression.expression) &&
309
321
  node.initializer.expression.expression.text === 'createComponent') {
310
- var baseElement = getBaseElement(parser, node.initializer.expression.arguments[0]);
322
+ const baseElement = getBaseElement(parser, node.initializer.expression.arguments[0]);
311
323
  /**
312
324
  * options is the object containing the `Component` function
313
325
  * ```ts
@@ -317,29 +329,29 @@ export var enhancedComponentParser = createParserPlugin(function (node, parser)
317
329
  * })
318
330
  * ```
319
331
  */
320
- var options = node.initializer.arguments[0];
332
+ const options = node.initializer.arguments[0];
321
333
  if (options && t.isObjectLiteralExpression(options)) {
322
- var signature = options.properties.find(function (n) { return n.name && t.isIdentifier(n.name) && n.name.text === 'Component'; });
323
- var displayName = getDisplayName(parser, options);
324
- var subComponents = getSubcomponents(parser, options);
334
+ const signature = options.properties.find(n => n.name && t.isIdentifier(n.name) && n.name.text === 'Component');
335
+ const displayName = getDisplayName(parser, options);
336
+ const subComponents = getSubcomponents(parser, options);
325
337
  if (signature) {
326
- var componentExpression = t.isMethodDeclaration(signature)
338
+ const componentExpression = t.isMethodDeclaration(signature)
327
339
  ? signature
328
340
  : t.isPropertyAssignment(signature)
329
341
  ? signature.initializer
330
342
  : undefined;
331
343
  if (componentExpression && ts.isFunctionLike(componentExpression)) {
332
- var type = parser.checker.getTypeAtLocation(componentExpression.parameters[0]);
333
- var props = getComponentProps(parser, componentExpression, type, baseElement);
334
- var styleComponent = getStyleComponent(displayName, props);
344
+ const type = parser.checker.getTypeAtLocation(componentExpression.parameters[0]);
345
+ const props = getComponentProps(parser, componentExpression, type, baseElement);
346
+ const styleComponent = getStyleComponent(displayName, props);
335
347
  return {
336
348
  kind: 'enhancedComponent',
337
349
  componentType: 'regular',
338
- displayName: displayName,
350
+ displayName,
339
351
  props: getNonDefaultNonLayoutProps(displayName, props),
340
- baseElement: baseElement,
341
- subComponents: subComponents,
342
- styleComponent: styleComponent,
352
+ baseElement,
353
+ subComponents,
354
+ styleComponent,
343
355
  };
344
356
  }
345
357
  }
@@ -352,35 +364,35 @@ export var enhancedComponentParser = createParserPlugin(function (node, parser)
352
364
  t.isCallExpression(node.initializer.expression.expression) &&
353
365
  t.isIdentifier(node.initializer.expression.expression.expression) &&
354
366
  node.initializer.expression.expression.expression.text === 'createContainer') {
355
- var baseElement = getBaseElement(parser, node.initializer.expression.expression.arguments[0]);
356
- var options = node.initializer.expression.arguments[0];
357
- var modelName = getModelName(parser, options);
358
- var displayName = getDisplayName(parser, options);
359
- var subComponents = getSubcomponents(parser, options);
360
- var elemPropsHook = getElemPropsHook(parser, options);
361
- var signature = node.initializer.arguments[0];
367
+ const baseElement = getBaseElement(parser, node.initializer.expression.expression.arguments[0]);
368
+ const options = node.initializer.expression.arguments[0];
369
+ const modelName = getModelName(parser, options);
370
+ const displayName = getDisplayName(parser, options);
371
+ const subComponents = getSubcomponents(parser, options);
372
+ const elemPropsHook = getElemPropsHook(parser, options);
373
+ const signature = node.initializer.arguments[0];
362
374
  if (ts.isFunctionLike(signature) && modelName) {
363
- var type = node.initializer.typeArguments
375
+ const type = node.initializer.typeArguments
364
376
  ? parser.checker.getTypeAtLocation(node.initializer.typeArguments[0])
365
377
  : undefined;
366
- var props = (type ? getComponentProps(parser, signature, type, baseElement) : [])
378
+ const props = (type ? getComponentProps(parser, signature, type, baseElement) : [])
367
379
  .filter(
368
380
  // Filter out `model` and `elemPropsHook` that might come if we extend an interface
369
- function (p) { return !['model', 'elemPropsHook'].includes(p.name); })
381
+ p => !['model', 'elemPropsHook'].includes(p.name))
370
382
  .filter(filterOutModelProps);
371
383
  props.push(getModelProp(parser, modelName));
372
384
  props.push(getElemProp(parser, modelName));
373
- var styleComponent = getStyleComponent(displayName, props);
385
+ const styleComponent = getStyleComponent(displayName, props);
374
386
  return {
375
387
  kind: 'enhancedComponent',
376
388
  componentType: 'container',
377
- displayName: displayName,
378
- elemPropsHook: elemPropsHook,
389
+ displayName,
390
+ elemPropsHook,
379
391
  props: getNonDefaultNonLayoutProps(displayName, props),
380
- baseElement: baseElement,
392
+ baseElement,
381
393
  model: modelName,
382
- styleComponent: styleComponent,
383
- subComponents: subComponents,
394
+ styleComponent,
395
+ subComponents,
384
396
  };
385
397
  }
386
398
  }
@@ -391,32 +403,32 @@ export var enhancedComponentParser = createParserPlugin(function (node, parser)
391
403
  t.isCallExpression(node.initializer.expression.expression) &&
392
404
  t.isIdentifier(node.initializer.expression.expression.expression) &&
393
405
  node.initializer.expression.expression.expression.text === 'createSubcomponent') {
394
- var baseElement = getBaseElement(parser, node.initializer.expression.expression.arguments[0]);
395
- var options = node.initializer.expression.arguments[0];
396
- var modelName = getModelName(parser, options);
397
- var subComponents = getSubcomponents(parser, options);
398
- var elemPropsHook = getElemPropsHook(parser, options);
399
- var displayName = getDisplayName(parser, options);
400
- var signature = node.initializer.arguments[0];
406
+ const baseElement = getBaseElement(parser, node.initializer.expression.expression.arguments[0]);
407
+ const options = node.initializer.expression.arguments[0];
408
+ const modelName = getModelName(parser, options);
409
+ const subComponents = getSubcomponents(parser, options);
410
+ const elemPropsHook = getElemPropsHook(parser, options);
411
+ const displayName = getDisplayName(parser, options);
412
+ const signature = node.initializer.arguments[0];
401
413
  if (ts.isFunctionLike(signature) && modelName) {
402
- var type = node.initializer.typeArguments
414
+ const type = node.initializer.typeArguments
403
415
  ? parser.checker.getTypeAtLocation(node.initializer.typeArguments[0])
404
416
  : undefined;
405
- var props = (type ? getComponentProps(parser, signature, type, baseElement) : []).filter(
417
+ const props = (type ? getComponentProps(parser, signature, type, baseElement) : []).filter(
406
418
  // Filter out `model` and `elemPropsHook` that might come if we extend an interface
407
- function (p) { return !['model', 'elemPropsHook'].includes(p.name); });
419
+ p => !['model', 'elemPropsHook'].includes(p.name));
408
420
  props.push(getModelProp(parser, modelName));
409
421
  props.push(getElemProp(parser, modelName));
410
- var styleComponent = getStyleComponent(displayName, props);
422
+ const styleComponent = getStyleComponent(displayName, props);
411
423
  return {
412
424
  kind: 'enhancedComponent',
413
425
  componentType: 'subcomponent',
414
- elemPropsHook: elemPropsHook,
415
- displayName: displayName,
426
+ elemPropsHook,
427
+ displayName,
416
428
  props: getNonDefaultNonLayoutProps(displayName, props),
417
- baseElement: baseElement,
418
- subComponents: subComponents,
419
- styleComponent: styleComponent,
429
+ baseElement,
430
+ subComponents,
431
+ styleComponent,
420
432
  model: modelName,
421
433
  };
422
434
  }
@@ -429,7 +441,7 @@ function filterOutModelProps(prop) {
429
441
  }
430
442
  function getDisplayName(parser, node) {
431
443
  if (t.isObjectLiteralExpression(node)) {
432
- var displayProperty = node.properties.find(function (p) { return p.name && t.isIdentifier(p.name) && p.name.text === 'displayName'; });
444
+ const displayProperty = node.properties.find(p => p.name && t.isIdentifier(p.name) && p.name.text === 'displayName');
433
445
  if (displayProperty &&
434
446
  t.isPropertyAssignment(displayProperty) &&
435
447
  t.isStringLiteral(displayProperty.initializer)) {
@@ -442,7 +454,7 @@ function getNonDefaultNonLayoutProps(displayName, props) {
442
454
  if (displayName && ['Flex', 'Box', 'Grid'].includes(displayName)) {
443
455
  return props;
444
456
  }
445
- return props.filter(function (p) {
457
+ return props.filter(p => {
446
458
  if (!p.declarations[0]) {
447
459
  // No declaration is found, we'll include this prop
448
460
  return true;
@@ -452,11 +464,11 @@ function getNonDefaultNonLayoutProps(displayName, props) {
452
464
  }
453
465
  function getReturnTypeFromElemPropsHook(parser, signature) {
454
466
  if (signature) {
455
- var type = signature.getReturnType();
467
+ const type = signature.getReturnType();
456
468
  // A TypeNode is a synthetic AST representation of a type. No truncation removes the `... 12 more ...`
457
- var typeNode = parser.checker.typeToTypeNode(type, undefined, ts.NodeBuilderFlags.NoTruncation);
469
+ const typeNode = parser.checker.typeToTypeNode(type, undefined, ts.NodeBuilderFlags.NoTruncation);
458
470
  if (typeNode) {
459
- var value = parser.getValueFromNode(typeNode);
471
+ const value = parser.getValueFromNode(typeNode);
460
472
  if (value.kind === 'object') {
461
473
  value.properties;
462
474
  }
@@ -467,11 +479,11 @@ function getReturnTypeFromElemPropsHook(parser, signature) {
467
479
  }
468
480
  function getElemPropsFromElemPropsHook(parser, signature) {
469
481
  if (signature) {
470
- var elemPropsParam = signature.getParameters()[2];
482
+ const elemPropsParam = signature.getParameters()[2];
471
483
  if (!elemPropsParam) {
472
484
  return { kind: 'object', properties: [] };
473
485
  }
474
- var elemPropsNode = getValueDeclaration(elemPropsParam);
486
+ const elemPropsNode = getValueDeclaration(elemPropsParam);
475
487
  if (elemPropsNode && t.isParameter(elemPropsNode)) {
476
488
  return parser.getValueFromNode(elemPropsNode).type;
477
489
  }
@@ -480,14 +492,14 @@ function getElemPropsFromElemPropsHook(parser, signature) {
480
492
  }
481
493
  function getElemPropsHook(parser, node) {
482
494
  if (t.isObjectLiteralExpression(node)) {
483
- var subComponentProperty = node.properties.find(function (p) { return p.name && t.isIdentifier(p.name) && p.name.text === 'elemPropsHook'; });
495
+ const subComponentProperty = node.properties.find(p => p.name && t.isIdentifier(p.name) && p.name.text === 'elemPropsHook');
484
496
  if (subComponentProperty &&
485
497
  t.isPropertyAssignment(subComponentProperty) &&
486
498
  t.isIdentifier(subComponentProperty.initializer)) {
487
499
  // Check if the elemProps is aliased to another hook
488
500
  // for example, `const useMyComponent = useMyOtherComponent`
489
- var symbol = getSymbolFromNode(parser.checker, subComponentProperty.initializer);
490
- var declaration = getValueDeclaration(symbol);
501
+ const symbol = getSymbolFromNode(parser.checker, subComponentProperty.initializer);
502
+ const declaration = getValueDeclaration(symbol);
491
503
  if (declaration &&
492
504
  t.isVariableDeclaration(declaration) &&
493
505
  declaration.initializer &&
@@ -501,61 +513,92 @@ function getElemPropsHook(parser, node) {
501
513
  }
502
514
  function getSubcomponents(parser, node) {
503
515
  if (t.isObjectLiteralExpression(node)) {
504
- var subComponentProperty = node.properties.find(function (p) { return p.name && t.isIdentifier(p.name) && p.name.text === 'subComponents'; });
516
+ const subComponentProperty = node.properties.find(p => p.name && t.isIdentifier(p.name) && p.name.text === 'subComponents');
505
517
  if (subComponentProperty &&
506
518
  t.isPropertyAssignment(subComponentProperty) &&
507
519
  t.isObjectLiteralExpression(subComponentProperty.initializer)) {
508
520
  return subComponentProperty.initializer.properties
509
- .map(function (p) {
521
+ .map(p => {
510
522
  if (t.isPropertyAssignment(p) &&
511
523
  t.isIdentifier(p.name) &&
512
524
  t.isIdentifier(p.initializer)) {
513
- var symbol = getSymbolFromNode(parser.checker, p.name);
514
- var jsDoc = findDocComment(parser.checker, symbol);
515
- return __assign({ name: p.name.text, symbol: p.initializer.text }, jsDoc);
525
+ const symbol = getSymbolFromNode(parser.checker, p.name);
526
+ const jsDoc = findDocComment(parser.checker, symbol);
527
+ return {
528
+ name: p.name.text,
529
+ symbol: p.initializer.text,
530
+ ...jsDoc,
531
+ };
516
532
  }
517
533
  if (t.isShorthandPropertyAssignment(p) && t.isIdentifier(p.name)) {
518
- var symbol = getSymbolFromNode(parser.checker, p.name);
519
- var jsDoc = findDocComment(parser.checker, symbol);
520
- return __assign({ name: p.name.text, symbol: p.name.text }, jsDoc);
534
+ const symbol = getSymbolFromNode(parser.checker, p.name);
535
+ const jsDoc = findDocComment(parser.checker, symbol);
536
+ return {
537
+ name: p.name.text,
538
+ symbol: p.name.text,
539
+ ...jsDoc,
540
+ };
521
541
  }
522
542
  return;
523
543
  })
524
- .filter(function (v) { return !!v; });
544
+ .filter((v) => !!v);
525
545
  }
526
546
  return;
527
547
  }
528
548
  return undefined;
529
549
  }
530
550
  function getModelProp(parser, modelName) {
531
- return __assign(__assign({ kind: 'property', name: 'model' }, defaultJSDoc), { description: 'Optional model to pass to the component. This will override the default model created for the component. This can be useful if you want to access to the state and events of the model, or if you have nested components of the same type and you need to override the model provided by React Context.', type: {
551
+ return {
552
+ kind: 'property',
553
+ name: 'model',
554
+ ...defaultJSDoc,
555
+ description: 'Optional model to pass to the component. This will override the default model created for the component. This can be useful if you want to access to the state and events of the model, or if you have nested components of the same type and you need to override the model provided by React Context.',
556
+ type: {
532
557
  kind: 'symbol',
533
558
  name: modelName,
534
- } });
559
+ },
560
+ };
535
561
  }
536
562
  function getElemProp(parser, modelName) {
537
- return __assign(__assign({ kind: 'property', name: 'elemPropsHook' }, defaultJSDoc), { description: 'Optional hook that receives the model and all props to be applied to the element. If you use this, it is your responsibility to return props, merging as appropriate. For example, returning an empty object will disable all elemProps hooks associated with this component. This allows finer control over a component without creating a new one.', type: {
563
+ return {
564
+ kind: 'property',
565
+ name: 'elemPropsHook',
566
+ ...defaultJSDoc,
567
+ description: 'Optional hook that receives the model and all props to be applied to the element. If you use this, it is your responsibility to return props, merging as appropriate. For example, returning an empty object will disable all elemProps hooks associated with this component. This allows finer control over a component without creating a new one.',
568
+ type: {
538
569
  kind: 'function',
539
570
  parameters: [
540
- __assign(__assign({ kind: 'parameter' }, defaultJSDoc), { name: 'model', type: {
571
+ {
572
+ kind: 'parameter',
573
+ ...defaultJSDoc,
574
+ name: 'model',
575
+ type: {
541
576
  kind: 'symbol',
542
577
  name: modelName,
543
- }, required: true }),
544
- __assign(__assign({ kind: 'parameter' }, defaultJSDoc), { name: 'elemProps', type: {
578
+ },
579
+ required: true,
580
+ },
581
+ {
582
+ kind: 'parameter',
583
+ ...defaultJSDoc,
584
+ name: 'elemProps',
585
+ type: {
545
586
  kind: 'generic',
546
587
  name: 'TProps',
547
- } }),
588
+ },
589
+ },
548
590
  ],
549
591
  returnType: {
550
592
  kind: 'external',
551
593
  name: 'HTML Attributes',
552
594
  url: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes',
553
595
  },
554
- } });
596
+ },
597
+ };
555
598
  }
556
599
  function getModelName(parser, node) {
557
600
  if (t.isObjectLiteralExpression(node)) {
558
- var modelProperty = node.properties.find(function (property) {
601
+ const modelProperty = node.properties.find(property => {
559
602
  return (t.isPropertyAssignment(property) &&
560
603
  t.isIdentifier(property.name) &&
561
604
  property.name.text === 'modelHook');
@@ -576,14 +619,14 @@ function getModelName(parser, node) {
576
619
  * @returns
577
620
  */
578
621
  function getComponentProps(parser, signature, type, baseElement) {
579
- var parameterDefaults = getDefaultsFromObjectBindingParameter(parser, signature.parameters[0]);
580
- var props = type
622
+ const parameterDefaults = getDefaultsFromObjectBindingParameter(parser, signature.parameters[0]);
623
+ const props = type
581
624
  .getProperties()
582
- .map(function (symbol) {
583
- var defaultValue = parameterDefaults[symbol.name] ||
625
+ .map(symbol => {
626
+ const defaultValue = parameterDefaults[symbol.name] ||
584
627
  getDefaultFromTags(symbol.getJsDocTags()) ||
585
628
  getDefaultFromJSX(parser, signature, symbol.name);
586
- var value = parser.getValueFromNode(getValueDeclaration(symbol));
629
+ const value = parser.getValueFromNode(getValueDeclaration(symbol));
587
630
  if (value.kind === 'property') {
588
631
  // @ts-ignore Not sure why this only fails in typecheck
589
632
  value.defaultValue = defaultValue;
@@ -591,21 +634,38 @@ function getComponentProps(parser, signature, type, baseElement) {
591
634
  return value;
592
635
  })
593
636
  .filter(filterObjectProperties);
594
- if (!props.find(function (p) { return p.name === 'children'; })) {
595
- props.push(__assign(__assign({ kind: 'property', name: 'children' }, defaultJSDoc), { type: {
637
+ if (!props.find(p => p.name === 'children')) {
638
+ props.push({
639
+ kind: 'property',
640
+ name: 'children',
641
+ ...defaultJSDoc,
642
+ type: {
596
643
  kind: 'external',
597
644
  name: 'React.ReactNode',
598
645
  url: 'https://reactjs.org/docs/rendering-elements.html',
599
- } }));
646
+ },
647
+ });
600
648
  }
601
649
  if (baseElement) {
602
650
  // Make it the first prop
603
- props.push(__assign(__assign({ kind: 'property', name: 'as' }, defaultJSDoc), { description: 'Optional override of the default element used by the component. Any valid tag or Component. If you provided a Component, this component should forward the ref using `React.forwardRef`and spread extra props to a root element.\n\n**Note:** Not all elements make sense and some elements may cause accessibility issues. Change this value with care.', type: {
651
+ props.push({
652
+ kind: 'property',
653
+ name: 'as',
654
+ ...defaultJSDoc,
655
+ description: 'Optional override of the default element used by the component. Any valid tag or Component. If you provided a Component, this component should forward the ref using `React.forwardRef`and spread extra props to a root element.\n\n**Note:** Not all elements make sense and some elements may cause accessibility issues. Change this value with care.',
656
+ type: {
604
657
  kind: 'external',
605
658
  name: 'React.ElementType',
606
659
  url: 'https://developer.mozilla.org/en-US/docs/Web/API/element',
607
- }, defaultValue: baseElement }));
608
- props.push(__assign(__assign({ kind: 'property', name: 'ref' }, defaultJSDoc), { description: 'Optional ref. If the component represents an element, this ref will be a reference to the real DOM element of the component. If `as` is set to an element, it will be that element. If `as` is a component, the reference will be to that component (or element if the component uses `React.forwardRef`).', type: {
660
+ },
661
+ defaultValue: baseElement,
662
+ });
663
+ props.push({
664
+ kind: 'property',
665
+ name: 'ref',
666
+ ...defaultJSDoc,
667
+ description: 'Optional ref. If the component represents an element, this ref will be a reference to the real DOM element of the component. If `as` is set to an element, it will be that element. If `as` is a component, the reference will be to that component (or element if the component uses `React.forwardRef`).',
668
+ type: {
609
669
  kind: 'external',
610
670
  name: 'React.Ref',
611
671
  url: 'https://reactjs.org/docs/refs-and-the-dom.html',
@@ -617,26 +677,27 @@ function getComponentProps(parser, signature, type, baseElement) {
617
677
  defaultValue: baseElement,
618
678
  },
619
679
  ],
620
- } }));
680
+ },
681
+ });
621
682
  }
622
683
  return props;
623
684
  }
624
685
  function getStyleComponent(displayName, props) {
625
- if (props.some(function (p) { var _a; return (_a = p.declarations[0]) === null || _a === void 0 ? void 0 : _a.filePath.includes('utils/grid.ts'); }) &&
686
+ if (props.some(p => { var _a; return (_a = p.declarations[0]) === null || _a === void 0 ? void 0 : _a.filePath.includes('utils/grid.ts'); }) &&
626
687
  displayName !== 'Grid') {
627
688
  return {
628
689
  kind: 'symbol',
629
690
  name: 'Grid',
630
691
  };
631
692
  }
632
- if (props.some(function (p) { var _a; return (_a = p.declarations[0]) === null || _a === void 0 ? void 0 : _a.filePath.includes('utils/flex.ts'); }) &&
693
+ if (props.some(p => { var _a; return (_a = p.declarations[0]) === null || _a === void 0 ? void 0 : _a.filePath.includes('utils/flex.ts'); }) &&
633
694
  displayName !== 'Flex') {
634
695
  return {
635
696
  kind: 'symbol',
636
697
  name: 'Flex',
637
698
  };
638
699
  }
639
- if (props.some(function (p) { var _a; return (_a = p.declarations[0]) === null || _a === void 0 ? void 0 : _a.filePath.includes('utils/layout.ts'); }) &&
700
+ if (props.some(p => { var _a; return (_a = p.declarations[0]) === null || _a === void 0 ? void 0 : _a.filePath.includes('utils/layout.ts'); }) &&
640
701
  displayName !== 'Box') {
641
702
  return {
642
703
  kind: 'symbol',