typedoc 0.23.21 → 0.23.22

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.
@@ -1,7 +1,6 @@
1
1
  import { ReflectionKind, DeclarationReflection } from "../../models/reflections/index";
2
2
  import { ReflectionGroup } from "../../models/ReflectionGroup";
3
3
  import { ConverterComponent } from "../components";
4
- import { SortStrategy } from "../../utils/sort";
5
4
  /**
6
5
  * A handler that sorts and groups the found reflections in the resolving phase.
7
6
  *
@@ -25,8 +24,7 @@ export declare class GroupPlugin extends ConverterComponent {
25
24
  16: string;
26
25
  4194304: string;
27
26
  };
28
- /** @internal */
29
- sortStrategies: SortStrategy[];
27
+ sortFunction: (reflections: DeclarationReflection[]) => void;
30
28
  boosts: Record<string, number>;
31
29
  usedBoosts: Set<string>;
32
30
  /**
@@ -30,6 +30,9 @@ let GroupPlugin = GroupPlugin_1 = class GroupPlugin extends components_1.Convert
30
30
  */
31
31
  initialize() {
32
32
  this.listenTo(this.owner, {
33
+ [converter_1.Converter.EVENT_RESOLVE_BEGIN]: () => {
34
+ this.sortFunction = (0, sort_1.getSortFunction)(this.application.options);
35
+ },
33
36
  [converter_1.Converter.EVENT_RESOLVE]: this.onResolve,
34
37
  [converter_1.Converter.EVENT_RESOLVE_END]: this.onEndResolve,
35
38
  });
@@ -68,7 +71,7 @@ let GroupPlugin = GroupPlugin_1 = class GroupPlugin extends components_1.Convert
68
71
  if (reflection.children &&
69
72
  reflection.children.length > 0 &&
70
73
  !reflection.groups) {
71
- (0, sort_1.sortReflections)(reflection.children, this.sortStrategies);
74
+ this.sortFunction(reflection.children);
72
75
  reflection.groups = this.getReflectionGroups(reflection.children);
73
76
  }
74
77
  }
@@ -193,9 +196,6 @@ GroupPlugin.PLURALS = {
193
196
  [index_1.ReflectionKind.EnumMember]: "Enumeration Members",
194
197
  [index_1.ReflectionKind.TypeAlias]: "Type Aliases",
195
198
  };
196
- __decorate([
197
- (0, utils_1.BindOption)("sort")
198
- ], GroupPlugin.prototype, "sortStrategies", void 0);
199
199
  __decorate([
200
200
  (0, utils_1.BindOption)("searchGroupBoosts")
201
201
  ], GroupPlugin.prototype, "boosts", void 0);
@@ -16,6 +16,7 @@ const fs_1 = require("../../utils/fs");
16
16
  const path_1 = require("path");
17
17
  const models_1 = require("../../models");
18
18
  const repository_1 = require("../utils/repository");
19
+ const base_path_1 = require("../utils/base-path");
19
20
  /**
20
21
  * A handler that attaches source file information to reflections.
21
22
  */
@@ -64,7 +65,7 @@ let SourcePlugin = class SourcePlugin extends components_1.ConverterComponent {
64
65
  const symbol = reflection.project.getSymbolFromReflection(reflection);
65
66
  for (const node of symbol?.declarations || []) {
66
67
  const sourceFile = node.getSourceFile();
67
- const fileName = sourceFile.fileName;
68
+ const fileName = base_path_1.BasePath.normalize(sourceFile.fileName);
68
69
  this.fileNames.add(fileName);
69
70
  let position;
70
71
  if ((0, nodes_1.isNamedNode)(node)) {
@@ -81,7 +82,7 @@ let SourcePlugin = class SourcePlugin extends components_1.ConverterComponent {
81
82
  if (this.disableSources || !sig)
82
83
  return;
83
84
  const sourceFile = sig.getSourceFile();
84
- const fileName = sourceFile.fileName;
85
+ const fileName = base_path_1.BasePath.normalize(sourceFile.fileName);
85
86
  this.fileNames.add(fileName);
86
87
  const position = ts.getLineAndCharacterOfPosition(sourceFile, sig.getStart());
87
88
  reflection.sources || (reflection.sources = []);
@@ -82,7 +82,7 @@ class BasePath {
82
82
  path = path.replace(/\\/g, "/");
83
83
  // Remove all surrounding quotes
84
84
  path = path.replace(/^["']+|["']+$/g, "");
85
- // Make Windows drive letters lower case
85
+ // Make Windows drive letters upper case
86
86
  return path.replace(/^([^:]+):\//, (_m, m1) => m1.toUpperCase() + ":/");
87
87
  }
88
88
  }
@@ -100,8 +100,8 @@ function displayPartsToMarkdown(parts, urlTo) {
100
100
  case "@linkplain": {
101
101
  if (part.target) {
102
102
  const url = typeof part.target === "string" ? part.target : urlTo(part.target);
103
- const wrap = part.tag === "@linkcode" ? "`" : "";
104
- result.push(url ? `[${wrap}${part.text}${wrap}](${url})` : part.text);
103
+ const text = part.tag === "@linkcode" ? `<code>${part.text}</code>` : part.text;
104
+ result.push(url ? `<a href="${url}">${text}</a>` : part.text);
105
105
  }
106
106
  else {
107
107
  result.push(part.text);
@@ -2,3 +2,4 @@ export declare function getEnumFlags<T extends number>(flags: T): T[];
2
2
  export declare function removeFlag<T extends number>(flag: T, remove: T & {}): T;
3
3
  export declare function hasAllFlags(flags: number, check: number): boolean;
4
4
  export declare function hasAnyFlag(flags: number, check: number): boolean;
5
+ export declare function getEnumKeys(Enum: Record<string, string | number>): string[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasAnyFlag = exports.hasAllFlags = exports.removeFlag = exports.getEnumFlags = void 0;
3
+ exports.getEnumKeys = exports.hasAnyFlag = exports.hasAllFlags = exports.removeFlag = exports.getEnumFlags = void 0;
4
4
  function getEnumFlags(flags) {
5
5
  const result = [];
6
6
  for (let i = 1; i <= flags; i <<= 1) {
@@ -24,3 +24,10 @@ function hasAnyFlag(flags, check) {
24
24
  return (flags & check) !== 0;
25
25
  }
26
26
  exports.hasAnyFlag = hasAnyFlag;
27
+ // Note: String enums are not handled.
28
+ function getEnumKeys(Enum) {
29
+ return Object.keys(Enum).filter((k) => {
30
+ return Enum[Enum[k]] === k;
31
+ });
32
+ }
33
+ exports.getEnumKeys = getEnumKeys;
@@ -9,7 +9,7 @@ export { DefaultMap } from "./map";
9
9
  export { ArgumentsReader, BindOption, CommentStyle, Options, ParameterHint, ParameterType, TSConfigReader, TypeDocReader, } from "./options";
10
10
  export type { ArrayDeclarationOption, BooleanDeclarationOption, DeclarationOption, DeclarationOptionBase, DeclarationOptionToOptionType, KeyToDeclaration, MapDeclarationOption, MixedDeclarationOption, NumberDeclarationOption, FlagsDeclarationOption, ObjectDeclarationOption, OptionsReader, StringDeclarationOption, TypeDocOptionMap, TypeDocOptions, ValidationOptions, TypeDocOptionValues, ParameterTypeToOptionTypeMap, ManuallyValidatedOption, } from "./options";
11
11
  export { discoverPlugins, loadPlugins } from "./plugins";
12
- export { sortReflections } from "./sort";
12
+ export { getSortFunction } from "./sort";
13
13
  export type { SortStrategy } from "./sort";
14
14
  export { EventHooks } from "./hooks";
15
15
  export * from "./entry-point";
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.MinimalSourceFile = exports.Validation = exports.renderElement = exports.Raw = exports.Fragment = exports.JSX = exports.EventHooks = exports.sortReflections = exports.loadPlugins = exports.discoverPlugins = exports.TypeDocReader = exports.TSConfigReader = exports.ParameterType = exports.ParameterHint = exports.Options = exports.CommentStyle = exports.BindOption = exports.ArgumentsReader = exports.DefaultMap = exports.LogLevel = exports.Logger = exports.ConsoleLogger = exports.CallbackLogger = exports.assertNever = exports.writeFileSync = exports.writeFile = exports.readFile = exports.normalizePath = exports.getCommonDirectory = exports.copySync = exports.copy = exports.EventDispatcher = exports.Event = exports.Component = exports.ChildableComponent = exports.AbstractComponent = exports.unique = exports.removeIfPresent = exports.removeIf = exports.partition = exports.insertPrioritySorted = exports.filterMap = void 0;
17
+ exports.MinimalSourceFile = exports.Validation = exports.renderElement = exports.Raw = exports.Fragment = exports.JSX = exports.EventHooks = exports.getSortFunction = exports.loadPlugins = exports.discoverPlugins = exports.TypeDocReader = exports.TSConfigReader = exports.ParameterType = exports.ParameterHint = exports.Options = exports.CommentStyle = exports.BindOption = exports.ArgumentsReader = exports.DefaultMap = exports.LogLevel = exports.Logger = exports.ConsoleLogger = exports.CallbackLogger = exports.assertNever = exports.writeFileSync = exports.writeFile = exports.readFile = exports.normalizePath = exports.getCommonDirectory = exports.copySync = exports.copy = exports.EventDispatcher = exports.Event = exports.Component = exports.ChildableComponent = exports.AbstractComponent = exports.unique = exports.removeIfPresent = exports.removeIf = exports.partition = exports.insertPrioritySorted = exports.filterMap = void 0;
18
18
  var array_1 = require("./array");
19
19
  Object.defineProperty(exports, "filterMap", { enumerable: true, get: function () { return array_1.filterMap; } });
20
20
  Object.defineProperty(exports, "insertPrioritySorted", { enumerable: true, get: function () { return array_1.insertPrioritySorted; } });
@@ -59,7 +59,7 @@ var plugins_1 = require("./plugins");
59
59
  Object.defineProperty(exports, "discoverPlugins", { enumerable: true, get: function () { return plugins_1.discoverPlugins; } });
60
60
  Object.defineProperty(exports, "loadPlugins", { enumerable: true, get: function () { return plugins_1.loadPlugins; } });
61
61
  var sort_1 = require("./sort");
62
- Object.defineProperty(exports, "sortReflections", { enumerable: true, get: function () { return sort_1.sortReflections; } });
62
+ Object.defineProperty(exports, "getSortFunction", { enumerable: true, get: function () { return sort_1.getSortFunction; } });
63
63
  var hooks_1 = require("./hooks");
64
64
  Object.defineProperty(exports, "EventHooks", { enumerable: true, get: function () { return hooks_1.EventHooks; } });
65
65
  __exportStar(require("./entry-point"), exports);
@@ -94,6 +94,7 @@ export interface TypeDocOptionMap {
94
94
  defaultCategory: string;
95
95
  categoryOrder: string[];
96
96
  sort: SortStrategy[];
97
+ kindSortOrder: Array<keyof typeof ReflectionKind>;
97
98
  visibilityFilters: ManuallyValidatedOption<{
98
99
  protected?: boolean;
99
100
  private?: boolean;
@@ -9,6 +9,7 @@ const entry_point_1 = require("../../entry-point");
9
9
  const kind_1 = require("../../../models/reflections/kind");
10
10
  const Validation = require("../../validation");
11
11
  const tsdoc_defaults_1 = require("../tsdoc-defaults");
12
+ const enum_1 = require("../../enum");
12
13
  // For convenience, added in the same order as they are documented on the website.
13
14
  function addTypeDocOptions(options) {
14
15
  ///////////////////////////
@@ -390,6 +391,22 @@ function addTypeDocOptions(options) {
390
391
  }
391
392
  },
392
393
  });
394
+ options.addDeclaration({
395
+ name: "kindSortOrder",
396
+ help: "Specify the sort order for reflections when 'kind' is specified.",
397
+ type: declaration_1.ParameterType.Array,
398
+ defaultValue: [],
399
+ validate(value) {
400
+ const invalid = new Set(value);
401
+ const valid = (0, enum_1.getEnumKeys)(kind_1.ReflectionKind);
402
+ for (const v of valid) {
403
+ invalid.delete(v);
404
+ }
405
+ if (invalid.size !== 0) {
406
+ throw new Error(`kindSortOrder may only specify known values, and invalid values were provided (${Array.from(invalid).join(", ")}). The valid kinds are:\n${valid.join(", ")}`);
407
+ }
408
+ },
409
+ });
393
410
  options.addDeclaration({
394
411
  name: "visibilityFilters",
395
412
  help: "Specify the default visibility for builtin filters and additional filters according to modifier tags.",
@@ -511,7 +528,7 @@ function addTypeDocOptions(options) {
511
528
  type: declaration_1.ParameterType.Array,
512
529
  validate(values) {
513
530
  // this is good enough because the values of the ReflectionKind enum are all numbers
514
- const validValues = Object.values(kind_1.ReflectionKind).filter((v) => typeof v === "string");
531
+ const validValues = (0, enum_1.getEnumKeys)(kind_1.ReflectionKind);
515
532
  for (const kind of values) {
516
533
  if (!validValues.includes(kind)) {
517
534
  throw new Error(`'${kind}' is an invalid value for 'requiredToBeDocumented'. Must be one of: ${validValues.join(", ")}`);
@@ -3,6 +3,7 @@
3
3
  * @module
4
4
  */
5
5
  import type { DeclarationReflection } from "../models/reflections/declaration";
6
+ import type { Options } from "./options";
6
7
  export declare const SORT_STRATEGIES: readonly ["source-order", "alphabetical", "enum-value-ascending", "enum-value-descending", "static-first", "instance-first", "visibility", "required-first", "kind"];
7
8
  export type SortStrategy = typeof SORT_STRATEGIES[number];
8
- export declare function sortReflections(reflections: DeclarationReflection[], strategies: readonly SortStrategy[]): void;
9
+ export declare function getSortFunction(opts: Options): (reflections: DeclarationReflection[]) => void;
@@ -4,7 +4,7 @@
4
4
  * @module
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.sortReflections = exports.SORT_STRATEGIES = void 0;
7
+ exports.getSortFunction = exports.SORT_STRATEGIES = void 0;
8
8
  const kind_1 = require("../models/reflections/kind");
9
9
  const types_1 = require("../models/types");
10
10
  exports.SORT_STRATEGIES = [
@@ -18,6 +18,32 @@ exports.SORT_STRATEGIES = [
18
18
  "required-first",
19
19
  "kind",
20
20
  ];
21
+ const defaultKindSortOrder = [
22
+ kind_1.ReflectionKind.Reference,
23
+ kind_1.ReflectionKind.Project,
24
+ kind_1.ReflectionKind.Module,
25
+ kind_1.ReflectionKind.Namespace,
26
+ kind_1.ReflectionKind.Enum,
27
+ kind_1.ReflectionKind.EnumMember,
28
+ kind_1.ReflectionKind.Class,
29
+ kind_1.ReflectionKind.Interface,
30
+ kind_1.ReflectionKind.TypeAlias,
31
+ kind_1.ReflectionKind.Constructor,
32
+ kind_1.ReflectionKind.Property,
33
+ kind_1.ReflectionKind.Variable,
34
+ kind_1.ReflectionKind.Function,
35
+ kind_1.ReflectionKind.Accessor,
36
+ kind_1.ReflectionKind.Method,
37
+ kind_1.ReflectionKind.ObjectLiteral,
38
+ kind_1.ReflectionKind.Parameter,
39
+ kind_1.ReflectionKind.TypeParameter,
40
+ kind_1.ReflectionKind.TypeLiteral,
41
+ kind_1.ReflectionKind.CallSignature,
42
+ kind_1.ReflectionKind.ConstructorSignature,
43
+ kind_1.ReflectionKind.IndexSignature,
44
+ kind_1.ReflectionKind.GetSignature,
45
+ kind_1.ReflectionKind.SetSignature,
46
+ ];
21
47
  // Return true if a < b
22
48
  const sorts = {
23
49
  "source-order"(a, b) {
@@ -87,47 +113,33 @@ const sorts = {
87
113
  "required-first"(a, b) {
88
114
  return !a.flags.isOptional && b.flags.isOptional;
89
115
  },
90
- kind(a, b) {
91
- const weights = [
92
- kind_1.ReflectionKind.Reference,
93
- kind_1.ReflectionKind.Project,
94
- kind_1.ReflectionKind.Module,
95
- kind_1.ReflectionKind.Namespace,
96
- kind_1.ReflectionKind.Enum,
97
- kind_1.ReflectionKind.EnumMember,
98
- kind_1.ReflectionKind.Class,
99
- kind_1.ReflectionKind.Interface,
100
- kind_1.ReflectionKind.TypeAlias,
101
- kind_1.ReflectionKind.Constructor,
102
- kind_1.ReflectionKind.Property,
103
- kind_1.ReflectionKind.Variable,
104
- kind_1.ReflectionKind.Function,
105
- kind_1.ReflectionKind.Accessor,
106
- kind_1.ReflectionKind.Method,
107
- kind_1.ReflectionKind.ObjectLiteral,
108
- kind_1.ReflectionKind.Parameter,
109
- kind_1.ReflectionKind.TypeParameter,
110
- kind_1.ReflectionKind.TypeLiteral,
111
- kind_1.ReflectionKind.CallSignature,
112
- kind_1.ReflectionKind.ConstructorSignature,
113
- kind_1.ReflectionKind.IndexSignature,
114
- kind_1.ReflectionKind.GetSignature,
115
- kind_1.ReflectionKind.SetSignature,
116
- ];
117
- return weights.indexOf(a.kind) < weights.indexOf(b.kind);
116
+ kind(a, b, { kindSortOrder }) {
117
+ return kindSortOrder.indexOf(a.kind) < kindSortOrder.indexOf(b.kind);
118
118
  },
119
119
  };
120
- function sortReflections(reflections, strategies) {
121
- reflections.sort((a, b) => {
122
- for (const s of strategies) {
123
- if (sorts[s](a, b)) {
124
- return -1;
125
- }
126
- if (sorts[s](b, a)) {
127
- return 1;
128
- }
120
+ function getSortFunction(opts) {
121
+ const kindSortOrder = opts
122
+ .getValue("kindSortOrder")
123
+ .map((k) => kind_1.ReflectionKind[k]);
124
+ for (const kind of defaultKindSortOrder) {
125
+ if (!kindSortOrder.includes(kind)) {
126
+ kindSortOrder.push(kind);
129
127
  }
130
- return 0;
131
- });
128
+ }
129
+ const strategies = opts.getValue("sort");
130
+ const data = { kindSortOrder };
131
+ return function sortReflections(reflections) {
132
+ reflections.sort((a, b) => {
133
+ for (const s of strategies) {
134
+ if (sorts[s](a, b, data)) {
135
+ return -1;
136
+ }
137
+ if (sorts[s](b, a, data)) {
138
+ return 1;
139
+ }
140
+ }
141
+ return 0;
142
+ });
143
+ };
132
144
  }
133
- exports.sortReflections = sortReflections;
145
+ exports.getSortFunction = getSortFunction;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "typedoc",
3
3
  "description": "Create api documentation for TypeScript projects.",
4
- "version": "0.23.21",
4
+ "version": "0.23.22",
5
5
  "homepage": "https://typedoc.org",
6
6
  "main": "./dist/index.js",
7
7
  "exports": {