umberto 3.0.0 → 3.1.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "umberto",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "CKSource Documentation builder",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -56,10 +56,10 @@
56
56
  "webpack": "^5.74.0"
57
57
  },
58
58
  "devDependencies": {
59
- "@ckeditor/ckeditor5-dev-bump-year": "^35.0.0",
60
- "@ckeditor/ckeditor5-dev-ci": "^35.0.0",
61
- "@ckeditor/ckeditor5-dev-docs": "^35.0.0",
62
- "@ckeditor/ckeditor5-dev-release-tools": "^35.0.0",
59
+ "@ckeditor/ckeditor5-dev-bump-year": "^37.0.0",
60
+ "@ckeditor/ckeditor5-dev-ci": "^37.0.0",
61
+ "@ckeditor/ckeditor5-dev-docs": "^37.0.0",
62
+ "@ckeditor/ckeditor5-dev-release-tools": "^37.0.0",
63
63
  "browser-sync": "^2.27.10",
64
64
  "chai": "^4.3.6",
65
65
  "chokidar": "^3.5.3",
@@ -513,20 +513,26 @@ module.exports = class DocDataFactory {
513
513
  */
514
514
  _processParams( data = [] ) {
515
515
  const resultParams = data.slice(); // copy data array
516
- const parentParams = []; // params which have sub-params; e.g. options
517
516
 
518
- for ( const item of resultParams ) {
517
+ // Find properties that may contain nested properties.
518
+ const parentParams = resultParams.filter( item => {
519
519
  if ( item.params ) {
520
- continue;
520
+ return true;
521
521
  }
522
522
 
523
- // Parent params are of type 'Object'.
524
- for ( const type of item.types ) {
525
- if ( type === 'Object' ) {
526
- parentParams.push( item );
523
+ return item.types.some( type => {
524
+ // An inline callback.
525
+ if ( type.type && type.type === 'function' ) {
526
+ return true;
527
527
  }
528
- }
529
- }
528
+
529
+ if ( typeof type !== 'string' ) {
530
+ return false;
531
+ }
532
+
533
+ return type.toLowerCase() === 'object';
534
+ } );
535
+ } );
530
536
 
531
537
  // For every parentParam gather its subparams.
532
538
  for ( const parent of parentParams ) {
@@ -535,7 +541,7 @@ module.exports = class DocDataFactory {
535
541
  for ( let i = 0; i < resultParams.length; i++ ) {
536
542
  const item = resultParams[ i ];
537
543
 
538
- if ( item.name && item.name.indexOf( `${ parent.name }.` ) !== -1 ) {
544
+ if ( item.name && item.name.includes( `${ parent.name }.` ) ) {
539
545
  subParams.push( item );
540
546
  // remove sub-params from main array, they will be kept under parentParam
541
547
  resultParams.splice( i--, 1 );
@@ -549,6 +555,14 @@ module.exports = class DocDataFactory {
549
555
  if ( parent.params.length > 0 ) {
550
556
  parent.subParamsString = ' = { ';
551
557
 
558
+ if ( parent.types.length === 1 && parent.types[ 0 ].type === 'function' ) {
559
+ parent.subParamsString += renderInlineCallbackAsObjectProperty( parent.types[ 0 ] );
560
+
561
+ if ( subParams.length ) {
562
+ parent.subParamsString += ', ';
563
+ }
564
+ }
565
+
552
566
  subParams.forEach( ( sub, index ) => {
553
567
  parent.subParamsString += sub.optional ? `[${ sub.name }]` : sub.name;
554
568
 
@@ -752,3 +766,49 @@ function sortPartsAlphabetically( arr, criteria = [ {} ] ) {
752
766
 
753
767
  return result;
754
768
  }
769
+
770
+ /**
771
+ * This is a JavaScript version of the `renderInlineFunction()` pug mixin.
772
+ *
773
+ * See: themes/umberto/layout/_api-docs/_mixin/_type.pug.
774
+ *
775
+ * The goal is to render an inline object describing a callable type.
776
+ *
777
+ * @param {Object} type
778
+ * @param {Array.<String>} type.params
779
+ * @param {Array.<String>|String} type.returns
780
+ * @param {Boolean} type.isClass
781
+ * @returns {String}
782
+ */
783
+ function renderInlineCallbackAsObjectProperty( type ) {
784
+ const { params, returns, isClass } = type;
785
+
786
+ return [
787
+ // Indicate if a function returns a class.
788
+ isClass ? 'new' : '',
789
+
790
+ // Parameters section.
791
+ '(',
792
+ params.map( mapToDocletCallback ).join( ', ' ),
793
+ ')',
794
+
795
+ // Returns section.
796
+ ' =&gt; ',
797
+
798
+ // Wraps an union in brackets.
799
+ Array.isArray( returns ) ? '(' : '',
800
+ Array.isArray( returns ) ? returns.map( mapToDocletCallback ).join( ' | ' ) : mapToDocletCallback( returns ),
801
+ Array.isArray( returns ) ? ')' : ''
802
+ ].join( '' );
803
+
804
+ function mapToDocletCallback( param ) {
805
+ if ( !param.startsWith( 'module:' ) ) {
806
+ return param;
807
+ }
808
+
809
+ const href = param.replace( /:|\//g, '_' ).replace( '~', '-' ) + '.html';
810
+ const value = param.split( '~' )[ 1 ];
811
+
812
+ return `<a href="${ href }">${ value }</a>`;
813
+ }
814
+ }
@@ -25,7 +25,8 @@ module.exports = class ModuleParser extends AbstractParser {
25
25
  name: item.name,
26
26
  longname: this.getLongName( item ),
27
27
  kind: this.getKind( item ),
28
- extraId: this.getExtraId( item )
28
+ extraId: this.getExtraId( item ),
29
+ file: this.getFile( item )
29
30
  };
30
31
  }
31
32
  };
@@ -127,7 +127,7 @@ class TypedocConverter {
127
127
  }
128
128
 
129
129
  if ( 'properties' in doclet ) {
130
- doclet.properties = this._convertProperties( doclet, setSignature );
130
+ doclet.properties = this._convertProperties( setSignature );
131
131
  }
132
132
 
133
133
  if ( 'typeParameters' in doclet ) {
@@ -202,7 +202,7 @@ class TypedocConverter {
202
202
  }
203
203
 
204
204
  return signature.parameters
205
- .map( item => {
205
+ .flatMap( item => {
206
206
  const response = this._convertTypeToJsDoc( item );
207
207
 
208
208
  response.name = item.name;
@@ -219,17 +219,29 @@ class TypedocConverter {
219
219
  response.defaultvalue = item.defaultValue;
220
220
  }
221
221
 
222
- return response;
222
+ const nestedProperties = this._convertProperties( item );
223
+
224
+ if ( !nestedProperties ) {
225
+ return response;
226
+ }
227
+
228
+ return [
229
+ response,
230
+ ...nestedProperties.map( nestedProperty => {
231
+ nestedProperty.name = `${ item.name }.${ nestedProperty.name }`;
232
+
233
+ return nestedProperty;
234
+ } )
235
+ ];
223
236
  } );
224
237
  }
225
238
 
226
239
  /**
227
240
  * @protected
228
- * @param {Object} doclet
229
241
  * @param {TypedocCallSignature} signature
230
242
  * @returns {Array|null}
231
243
  */
232
- _convertProperties( doclet, signature ) {
244
+ _convertProperties( signature ) {
233
245
  const types = signature.type.type === 'union' ? signature.type.types : [ signature.type ];
234
246
  const type = types.find( type => type.declaration && type.declaration.children );
235
247
 
@@ -238,28 +250,30 @@ class TypedocConverter {
238
250
  }
239
251
 
240
252
  return type.declaration.children.map( child => {
241
- const response = this._convertTypeToJsDoc( child );
253
+ // Nested properties cannot be duplicated so we can take the first signature when processing functions.
254
+ const childSignature = child.kindString === 'Method' ? child.signatures[ 0 ] : child;
255
+ const response = this._convertTypeToJsDoc( childSignature );
242
256
 
243
- response.name = child.name;
257
+ response.name = childSignature.name;
244
258
 
245
259
  if ( signature.comment && signature.comment.blockTags ) {
246
260
  const atProperty = signature.comment.blockTags.find( blockTag => {
247
- return blockTag.tag === '@property' && blockTag.name === child.name;
261
+ return blockTag.tag === '@property' && blockTag.name === childSignature.name;
248
262
  } );
249
263
 
250
264
  if ( atProperty ) {
251
265
  response.description = TypedocConverter.convertComment( atProperty.content );
252
266
  }
253
- } else if ( child.comment && child.comment.summary ) {
254
- response.description = TypedocConverter.convertComment( child.comment.summary );
267
+ } else if ( childSignature.comment && childSignature.comment.summary ) {
268
+ response.description = TypedocConverter.convertComment( childSignature.comment.summary );
255
269
  }
256
270
 
257
- if ( child.flags.isOptional ) {
271
+ if ( childSignature.flags.isOptional ) {
258
272
  response.optional = true;
259
273
  }
260
274
 
261
- if ( child.defaultValue ) {
262
- response.defaultvalue = child.defaultValue;
275
+ if ( childSignature.defaultValue ) {
276
+ response.defaultvalue = childSignature.defaultValue;
263
277
  }
264
278
 
265
279
  return response;
@@ -436,7 +450,7 @@ class TypeConverter {
436
450
  };
437
451
  }
438
452
 
439
- const type = this.convert( parameter.type );
453
+ let type = this.convert( parameter.type );
440
454
 
441
455
  // To avoid complex type parameters (they are available in typings provided by TypeScript),
442
456
  // let's ignore unions.
@@ -447,6 +461,10 @@ class TypeConverter {
447
461
  };
448
462
  }
449
463
 
464
+ if ( parameter.default ) {
465
+ type += ` = ${ this.convertIntrinsicType( parameter.default ) }`;
466
+ }
467
+
450
468
  return {
451
469
  name: parameter.name,
452
470
  isExtending: true,
@@ -35,7 +35,8 @@ mixin method( met )
35
35
  else
36
36
  | #{ param.name }
37
37
  if ( param.subParamsString )
38
- | #{ param.subParamsString }
38
+ //- Allow rendering HTML from the `subParamsString` as it may contain links to other pages.
39
+ | !{ param.subParamsString }
39
40
  if index < met.params.length - 1
40
41
  |,
41
42
  else
@@ -5,7 +5,7 @@ mixin typeParameter( type )
5
5
  code
6
6
  span !{ type.name }
7
7
 
8
- //- Most TypeScript types we mark as `object`, as they structure is complex.
8
+ //- We mark most TypeScript types as `object`, as their structure is complex.
9
9
  //- Hence, it does not really make sense to show that a type extends an unknown `object`.
10
10
  if ( type.value && type.value[ 0 ] !== 'object' )
11
11
  | !{' : '}
@@ -12,7 +12,7 @@ if isNonEmptyArray( data.typeParameters )
12
12
  code
13
13
  span( class="member-name" ) #{ type.name }
14
14
 
15
- //- Most TypeScript types we mark as `object`, as they structure is complex.
15
+ //- We mark most TypeScript types as `object`, as their structure is complex.
16
16
  //- Hence, it does not really make sense to show that a type extends an unknown `object`.
17
17
  if ( type.value && type.value[ 0 ] !== 'object' )
18
18
  | !{' : '}