@jupyterlab/toc 5.4.3 → 6.0.0-alpha.11

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 (150) hide show
  1. package/lib/factory.d.ts +42 -0
  2. package/lib/factory.js +73 -0
  3. package/lib/factory.js.map +1 -0
  4. package/lib/index.d.ts +9 -4
  5. package/lib/index.js +10 -5
  6. package/lib/index.js.map +1 -1
  7. package/lib/model.d.ts +123 -0
  8. package/lib/model.js +226 -0
  9. package/lib/model.js.map +1 -0
  10. package/lib/panel.d.ts +26 -0
  11. package/lib/panel.js +89 -0
  12. package/lib/panel.js.map +1 -0
  13. package/lib/registry.d.ts +11 -119
  14. package/lib/registry.js +17 -32
  15. package/lib/registry.js.map +1 -1
  16. package/lib/tocitem.d.ts +34 -0
  17. package/lib/tocitem.js +34 -0
  18. package/lib/tocitem.js.map +1 -0
  19. package/lib/toctree.d.ts +40 -0
  20. package/lib/toctree.js +43 -0
  21. package/lib/toctree.js.map +1 -0
  22. package/lib/tokens.d.ts +235 -0
  23. package/lib/tokens.js +29 -0
  24. package/lib/tokens.js.map +1 -0
  25. package/lib/tracker.d.ts +26 -0
  26. package/lib/tracker.js +33 -0
  27. package/lib/tracker.js.map +1 -0
  28. package/lib/treeview.d.ts +20 -0
  29. package/lib/treeview.js +35 -0
  30. package/lib/treeview.js.map +1 -0
  31. package/lib/utils/common.d.ts +65 -0
  32. package/lib/utils/common.js +158 -0
  33. package/lib/utils/common.js.map +1 -0
  34. package/lib/utils/index.d.ts +2 -0
  35. package/lib/utils/{numbering_dictionary.js → index.js} +3 -2
  36. package/lib/utils/index.js.map +1 -0
  37. package/lib/utils/markdown.d.ts +46 -0
  38. package/lib/utils/markdown.js +200 -0
  39. package/lib/utils/markdown.js.map +1 -0
  40. package/package.json +17 -24
  41. package/style/base.css +45 -383
  42. package/style/index.css +0 -5
  43. package/style/index.js +0 -5
  44. package/lib/generators/index.d.ts +0 -4
  45. package/lib/generators/index.js +0 -8
  46. package/lib/generators/index.js.map +0 -1
  47. package/lib/generators/latex/index.d.ts +0 -15
  48. package/lib/generators/latex/index.js +0 -111
  49. package/lib/generators/latex/index.js.map +0 -1
  50. package/lib/generators/markdown/get_headings.d.ts +0 -25
  51. package/lib/generators/markdown/get_headings.js +0 -51
  52. package/lib/generators/markdown/get_headings.js.map +0 -1
  53. package/lib/generators/markdown/get_rendered_headings.d.ts +0 -19
  54. package/lib/generators/markdown/get_rendered_headings.js +0 -68
  55. package/lib/generators/markdown/get_rendered_headings.js.map +0 -1
  56. package/lib/generators/markdown/index.d.ts +0 -34
  57. package/lib/generators/markdown/index.js +0 -176
  58. package/lib/generators/markdown/index.js.map +0 -1
  59. package/lib/generators/markdown/options_manager.d.ts +0 -74
  60. package/lib/generators/markdown/options_manager.js +0 -65
  61. package/lib/generators/markdown/options_manager.js.map +0 -1
  62. package/lib/generators/markdown/render.d.ts +0 -16
  63. package/lib/generators/markdown/render.js +0 -34
  64. package/lib/generators/markdown/render.js.map +0 -1
  65. package/lib/generators/markdown/toolbar_generator.d.ts +0 -66
  66. package/lib/generators/markdown/toolbar_generator.js +0 -49
  67. package/lib/generators/markdown/toolbar_generator.js.map +0 -1
  68. package/lib/generators/notebook/append_collapsible_heading.d.ts +0 -19
  69. package/lib/generators/notebook/append_collapsible_heading.js +0 -63
  70. package/lib/generators/notebook/append_collapsible_heading.js.map +0 -1
  71. package/lib/generators/notebook/append_heading.d.ts +0 -13
  72. package/lib/generators/notebook/append_heading.js +0 -33
  73. package/lib/generators/notebook/append_heading.js.map +0 -1
  74. package/lib/generators/notebook/append_markdown_heading.d.ts +0 -20
  75. package/lib/generators/notebook/append_markdown_heading.js +0 -33
  76. package/lib/generators/notebook/append_markdown_heading.js.map +0 -1
  77. package/lib/generators/notebook/codemirror.d.ts +0 -57
  78. package/lib/generators/notebook/codemirror.js +0 -46
  79. package/lib/generators/notebook/codemirror.js.map +0 -1
  80. package/lib/generators/notebook/get_code_cell_heading.d.ts +0 -27
  81. package/lib/generators/notebook/get_code_cell_heading.js +0 -48
  82. package/lib/generators/notebook/get_code_cell_heading.js.map +0 -1
  83. package/lib/generators/notebook/get_last_heading_level.d.ts +0 -13
  84. package/lib/generators/notebook/get_last_heading_level.js +0 -26
  85. package/lib/generators/notebook/get_last_heading_level.js.map +0 -1
  86. package/lib/generators/notebook/get_markdown_heading.d.ts +0 -27
  87. package/lib/generators/notebook/get_markdown_heading.js +0 -60
  88. package/lib/generators/notebook/get_markdown_heading.js.map +0 -1
  89. package/lib/generators/notebook/get_rendered_html_heading.d.ts +0 -31
  90. package/lib/generators/notebook/get_rendered_html_heading.js +0 -83
  91. package/lib/generators/notebook/get_rendered_html_heading.js.map +0 -1
  92. package/lib/generators/notebook/index.d.ts +0 -17
  93. package/lib/generators/notebook/index.js +0 -225
  94. package/lib/generators/notebook/index.js.map +0 -1
  95. package/lib/generators/notebook/is_heading_filtered.d.ts +0 -14
  96. package/lib/generators/notebook/is_heading_filtered.js +0 -35
  97. package/lib/generators/notebook/is_heading_filtered.js.map +0 -1
  98. package/lib/generators/notebook/options_manager.d.ts +0 -163
  99. package/lib/generators/notebook/options_manager.js +0 -210
  100. package/lib/generators/notebook/options_manager.js.map +0 -1
  101. package/lib/generators/notebook/render.d.ts +0 -15
  102. package/lib/generators/notebook/render.js +0 -161
  103. package/lib/generators/notebook/render.js.map +0 -1
  104. package/lib/generators/notebook/tagstool/index.d.ts +0 -111
  105. package/lib/generators/notebook/tagstool/index.js +0 -189
  106. package/lib/generators/notebook/tagstool/index.js.map +0 -1
  107. package/lib/generators/notebook/tagstool/tag.d.ts +0 -47
  108. package/lib/generators/notebook/tagstool/tag.js +0 -34
  109. package/lib/generators/notebook/tagstool/tag.js.map +0 -1
  110. package/lib/generators/notebook/tagstool/tag_list.d.ts +0 -70
  111. package/lib/generators/notebook/tagstool/tag_list.js +0 -70
  112. package/lib/generators/notebook/tagstool/tag_list.js.map +0 -1
  113. package/lib/generators/notebook/toolbar_generator.d.ts +0 -112
  114. package/lib/generators/notebook/toolbar_generator.js +0 -151
  115. package/lib/generators/notebook/toolbar_generator.js.map +0 -1
  116. package/lib/generators/python/index.d.ts +0 -15
  117. package/lib/generators/python/index.js +0 -91
  118. package/lib/generators/python/index.js.map +0 -1
  119. package/lib/generators/python/render.d.ts +0 -14
  120. package/lib/generators/python/render.js +0 -25
  121. package/lib/generators/python/render.js.map +0 -1
  122. package/lib/toc.d.ts +0 -100
  123. package/lib/toc.js +0 -163
  124. package/lib/toc.js.map +0 -1
  125. package/lib/toc_item.d.ts +0 -55
  126. package/lib/toc_item.js +0 -41
  127. package/lib/toc_item.js.map +0 -1
  128. package/lib/toc_tree.d.ts +0 -61
  129. package/lib/toc_tree.js +0 -31
  130. package/lib/toc_tree.js.map +0 -1
  131. package/lib/utils/generate_numbering.d.ts +0 -14
  132. package/lib/utils/generate_numbering.js +0 -57
  133. package/lib/utils/generate_numbering.js.map +0 -1
  134. package/lib/utils/headings.d.ts +0 -93
  135. package/lib/utils/headings.js +0 -30
  136. package/lib/utils/headings.js.map +0 -1
  137. package/lib/utils/is_dom.d.ts +0 -20
  138. package/lib/utils/is_dom.js +0 -25
  139. package/lib/utils/is_dom.js.map +0 -1
  140. package/lib/utils/is_markdown.d.ts +0 -20
  141. package/lib/utils/is_markdown.js +0 -28
  142. package/lib/utils/is_markdown.js.map +0 -1
  143. package/lib/utils/numbering_dictionary.d.ts +0 -15
  144. package/lib/utils/numbering_dictionary.js.map +0 -1
  145. package/lib/utils/parse_heading.d.ts +0 -75
  146. package/lib/utils/parse_heading.js +0 -91
  147. package/lib/utils/parse_heading.js.map +0 -1
  148. package/lib/utils/sanitizer_options.d.ts +0 -23
  149. package/lib/utils/sanitizer_options.js +0 -45
  150. package/lib/utils/sanitizer_options.js.map +0 -1
package/lib/registry.d.ts CHANGED
@@ -1,136 +1,28 @@
1
- /// <reference types="react" />
2
- import { IWidgetTracker } from '@jupyterlab/apputils';
3
- import { Token } from '@lumino/coreutils';
4
- import { ISignal } from '@lumino/signaling';
1
+ import { IDisposable } from '@lumino/disposable';
5
2
  import { Widget } from '@lumino/widgets';
6
- import { IHeading, INotebookHeading } from './utils/headings';
3
+ import { ITableOfContentsRegistry, TableOfContents } from './tokens';
7
4
  /**
8
- * Interface describing the table of contents registry.
9
- *
10
- * @private
5
+ * Class for registering table of contents generators.
11
6
  */
12
- export interface ITableOfContentsRegistry extends TableOfContentsRegistry {
13
- }
14
- /**
15
- * Table of contents registry token.
16
- */
17
- export declare const ITableOfContentsRegistry: Token<TableOfContentsRegistry>;
18
- /**
19
- * Class for registering widgets for which we can generate a table of contents.
20
- */
21
- export declare class TableOfContentsRegistry {
7
+ export declare class TableOfContentsRegistry implements ITableOfContentsRegistry {
22
8
  /**
23
- * Finds a table of contents generator for a widget.
9
+ * Finds a table of contents model for a widget.
24
10
  *
25
11
  * ## Notes
26
12
  *
27
- * - If unable to find a table of contents generator, the method return `undefined`.
13
+ * - If unable to find a table of contents model, the method return `undefined`.
28
14
  *
29
15
  * @param widget - widget
30
- * @returns table of contents generator
16
+ * @param configuration - Default model configuration
17
+ * @returns Table of contents model
31
18
  */
32
- find(widget: Widget): TableOfContentsRegistry.IGenerator | undefined;
19
+ getModel(widget: Widget, configuration?: TableOfContents.IConfig): TableOfContents.Model | undefined;
33
20
  /**
34
21
  * Adds a table of contents generator to the registry.
35
22
  *
36
23
  * @param generator - table of contents generator
37
24
  */
38
- add(generator: TableOfContentsRegistry.IGenerator): void;
39
- get collapseChanged(): ISignal<this, TableOfContentsRegistry.ICollapseChangedArgs>;
40
- private _collapseChanged;
25
+ add(generator: TableOfContents.IFactory): IDisposable;
41
26
  private _generators;
42
- }
43
- /**
44
- * Static registry methods.
45
- */
46
- export declare namespace TableOfContentsRegistry {
47
- /**
48
- * Abstract class for managing options affecting how a table of contents is generated for a particular widget type.
49
- */
50
- interface IOptionsManager {
51
- }
52
- /**
53
- * Interface for the arguments needed in the collapse signal of a generator
54
- */
55
- interface ICollapseChangedArgs {
56
- /**
57
- * Boolean indicating whether the given heading is collapsed in ToC
58
- */
59
- collapsedState: boolean;
60
- /**
61
- * Heading that was involved in the collapse event
62
- */
63
- heading: IHeading;
64
- /**
65
- * Type of file that the given heading was produced from
66
- */
67
- tocType: string;
68
- }
69
- /**
70
- * Interface describing a widget table of contents generator.
71
- */
72
- interface IGenerator<W extends Widget = Widget> {
73
- /**
74
- * Widget instance tracker.
75
- */
76
- tracker: IWidgetTracker<W>;
77
- /**
78
- * Returns a boolean indicating whether we can generate a ToC for a widget.
79
- *
80
- * ## Notes
81
- *
82
- * - By default, we assume ToC generation is enabled if the widget is hosted in `tracker`.
83
- * - However, a user may want to add additional checks (e.g., only generate a ToC for text files only if they have a given MIME type).
84
- *
85
- * @param widget - widget
86
- * @returns boolean indicating whether we can generate a ToC for a widget
87
- */
88
- isEnabled?: (widget: W) => boolean;
89
- /**
90
- * Boolean indicating whether a document uses LaTeX typesetting.
91
- *
92
- * @default false
93
- */
94
- usesLatex?: boolean;
95
- /**
96
- * Options manager.
97
- *
98
- * @default undefined
99
- */
100
- options?: IOptionsManager;
101
- /**
102
- * Signal to indicate that a collapse event happened to this heading
103
- * within the ToC.
104
- */
105
- collapseChanged?: ISignal<IOptionsManager, ICollapseChangedArgs>;
106
- /**
107
- * Returns a JSX element for each heading.
108
- *
109
- * ## Notes
110
- *
111
- * - If not present, a default renderer will be used.
112
- *
113
- * @param item - heading
114
- * @param toc - list of headings
115
- * @returns JSX element
116
- */
117
- itemRenderer?: (item: IHeading, toc: INotebookHeading[]) => JSX.Element | null;
118
- /**
119
- * Returns a toolbar component.
120
- *
121
- * ## Notes
122
- *
123
- * - If not present, no toolbar is generated.
124
- *
125
- * @returns toolbar component
126
- */
127
- toolbarGenerator?: () => any;
128
- /**
129
- * Returns a list of headings.
130
- *
131
- * @param widget - widget
132
- * @returns list of headings
133
- */
134
- generate(widget: W, options?: IOptionsManager): IHeading[];
135
- }
27
+ private _idCounter;
136
28
  }
package/lib/registry.js CHANGED
@@ -1,39 +1,29 @@
1
1
  // Copyright (c) Jupyter Development Team.
2
2
  // Distributed under the terms of the Modified BSD License.
3
- import { Token } from '@lumino/coreutils';
4
- import { Signal } from '@lumino/signaling';
5
- /* tslint:disable */
3
+ import { DisposableDelegate } from '@lumino/disposable';
6
4
  /**
7
- * Table of contents registry token.
8
- */
9
- export const ITableOfContentsRegistry = new Token('@jupyterlab/toc:ITableOfContentsRegistry');
10
- /* tslint:enable */
11
- /**
12
- * Class for registering widgets for which we can generate a table of contents.
5
+ * Class for registering table of contents generators.
13
6
  */
14
7
  export class TableOfContentsRegistry {
15
8
  constructor() {
16
- this._collapseChanged = new Signal(this);
17
- this._generators = [];
9
+ this._generators = new Map();
10
+ this._idCounter = 0;
18
11
  }
19
12
  /**
20
- * Finds a table of contents generator for a widget.
13
+ * Finds a table of contents model for a widget.
21
14
  *
22
15
  * ## Notes
23
16
  *
24
- * - If unable to find a table of contents generator, the method return `undefined`.
17
+ * - If unable to find a table of contents model, the method return `undefined`.
25
18
  *
26
19
  * @param widget - widget
27
- * @returns table of contents generator
20
+ * @param configuration - Default model configuration
21
+ * @returns Table of contents model
28
22
  */
29
- find(widget) {
30
- for (let i = 0; i < this._generators.length; i++) {
31
- const gen = this._generators[i];
32
- if (gen.tracker.has(widget)) {
33
- if (gen.isEnabled && !gen.isEnabled(widget)) {
34
- continue;
35
- }
36
- return gen;
23
+ getModel(widget, configuration) {
24
+ for (const generator of this._generators.values()) {
25
+ if (generator.isApplicable(widget)) {
26
+ return generator.createNew(widget, configuration);
37
27
  }
38
28
  }
39
29
  }
@@ -43,16 +33,11 @@ export class TableOfContentsRegistry {
43
33
  * @param generator - table of contents generator
44
34
  */
45
35
  add(generator) {
46
- if (generator.collapseChanged) {
47
- // If there is a collapseChanged for a given generator, propagate the arguments through the registry's signal
48
- generator.collapseChanged.connect((sender, args) => {
49
- this._collapseChanged.emit(args);
50
- });
51
- }
52
- this._generators.push(generator);
53
- }
54
- get collapseChanged() {
55
- return this._collapseChanged;
36
+ const id = this._idCounter++;
37
+ this._generators.set(id, generator);
38
+ return new DisposableDelegate(() => {
39
+ this._generators.delete(id);
40
+ });
56
41
  }
57
42
  }
58
43
  //# sourceMappingURL=registry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAG3D,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAW,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAWpD,oBAAoB;AACpB;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,KAAK,CAC/C,0CAA0C,CAC3C,CAAC;AACF,mBAAmB;AAEnB;;GAEG;AACH,MAAM,OAAO,uBAAuB;IAApC;QAkDU,qBAAgB,GAGpB,IAAI,MAAM,CAAqD,IAAI,CAAC,CAAC;QACjE,gBAAW,GAAyC,EAAE,CAAC;IACjE,CAAC;IAtDC;;;;;;;;;OASG;IACH,IAAI,CAAC,MAAc;QACjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAChD,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;YAChC,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;gBAC3B,IAAI,GAAG,CAAC,SAAS,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE;oBAC3C,SAAS;iBACV;gBACD,OAAO,GAAG,CAAC;aACZ;SACF;IACH,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,SAA6C;QAC/C,IAAI,SAAS,CAAC,eAAe,EAAE;YAC7B,6GAA6G;YAC7G,SAAS,CAAC,eAAe,CAAC,OAAO,CAC/B,CACE,MAAkD,EAClD,IAAkD,EAClD,EAAE;gBACF,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACnC,CAAC,CACF,CAAC;SACH;QACD,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACnC,CAAC;IAED,IAAI,eAAe;QAIjB,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC/B,CAAC;CAOF"}
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAE3D,OAAO,EAAE,kBAAkB,EAAe,MAAM,oBAAoB,CAAC;AAIrE;;GAEG;AACH,MAAM,OAAO,uBAAuB;IAApC;QAqCU,gBAAW,GAAG,IAAI,GAAG,EAAoC,CAAC;QAC1D,eAAU,GAAG,CAAC,CAAC;IACzB,CAAC;IAtCC;;;;;;;;;;OAUG;IACH,QAAQ,CACN,MAAc,EACd,aAAuC;QAEvC,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE;YACjD,IAAI,SAAS,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE;gBAClC,OAAO,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;aACnD;SACF;IACH,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,SAAmC;QACrC,MAAM,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAC7B,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC;QAEpC,OAAO,IAAI,kBAAkB,CAAC,GAAG,EAAE;YACjC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC9B,CAAC,CAAC,CAAC;IACL,CAAC;CAIF"}
@@ -0,0 +1,34 @@
1
+ import * as React from 'react';
2
+ import { TableOfContents } from './tokens';
3
+ /**
4
+ * Interface describing component properties.
5
+ */
6
+ export interface ITableOfContentsItemsProps {
7
+ /**
8
+ * Whether this item is active or not.
9
+ */
10
+ isActive: boolean;
11
+ /**
12
+ * Heading to render.
13
+ */
14
+ heading: TableOfContents.IHeading;
15
+ /**
16
+ * On `mouse-down` event callback.
17
+ */
18
+ onMouseDown: (heading: TableOfContents.IHeading) => void;
19
+ /**
20
+ * Collapse event callback.
21
+ */
22
+ onCollapse: (heading: TableOfContents.IHeading) => void;
23
+ }
24
+ /**
25
+ * React component for a table of contents entry.
26
+ */
27
+ export declare class TableOfContentsItem extends React.PureComponent<React.PropsWithChildren<ITableOfContentsItemsProps>> {
28
+ /**
29
+ * Renders a table of contents entry.
30
+ *
31
+ * @returns rendered entry
32
+ */
33
+ render(): JSX.Element | null;
34
+ }
package/lib/tocitem.js ADDED
@@ -0,0 +1,34 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+ import { caretDownIcon, caretRightIcon } from '@jupyterlab/ui-components';
4
+ import * as React from 'react';
5
+ /**
6
+ * React component for a table of contents entry.
7
+ */
8
+ export class TableOfContentsItem extends React.PureComponent {
9
+ /**
10
+ * Renders a table of contents entry.
11
+ *
12
+ * @returns rendered entry
13
+ */
14
+ render() {
15
+ const { children, isActive, heading, onCollapse, onMouseDown } = this.props;
16
+ return (React.createElement("li", { className: "jp-tocItem", key: `${heading.level}-${heading.text}` },
17
+ React.createElement("div", { className: `jp-tocItem-heading ${isActive ? 'jp-tocItem-active' : ''}`, onMouseDown: (event) => {
18
+ // React only on deepest item
19
+ if (!event.defaultPrevented) {
20
+ event.preventDefault();
21
+ onMouseDown(heading);
22
+ }
23
+ } },
24
+ React.createElement("button", { className: "jp-tocItem-collapser", onClick: (event) => {
25
+ event.preventDefault();
26
+ onCollapse(heading);
27
+ }, style: { visibility: children ? 'visible' : 'hidden' } }, heading.collapsed ? (React.createElement(caretRightIcon.react, { tag: "span", width: "20px" })) : (React.createElement(caretDownIcon.react, { tag: "span", width: "20px" }))),
28
+ React.createElement("span", Object.assign({ className: "jp-tocItem-content", title: heading.text }, heading.dataset),
29
+ heading.prefix,
30
+ heading.text)),
31
+ children && !heading.collapsed && React.createElement("ol", null, children)));
32
+ }
33
+ }
34
+ //# sourceMappingURL=tocitem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tocitem.js","sourceRoot":"","sources":["../src/tocitem.tsx"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAE3D,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AA2B/B;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,KAAK,CAAC,aAE9C;IACC;;;;OAIG;IACH,MAAM;QACJ,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAE5E,OAAO,CACL,4BAAI,SAAS,EAAC,YAAY,EAAC,GAAG,EAAE,GAAG,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,IAAI,EAAE;YAChE,6BACE,SAAS,EAAE,sBACT,QAAQ,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,EACnC,EAAE,EACF,WAAW,EAAE,CAAC,KAA2C,EAAE,EAAE;oBAC3D,6BAA6B;oBAC7B,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE;wBAC3B,KAAK,CAAC,cAAc,EAAE,CAAC;wBACvB,WAAW,CAAC,OAAO,CAAC,CAAC;qBACtB;gBACH,CAAC;gBAED,gCACE,SAAS,EAAC,sBAAsB,EAChC,OAAO,EAAE,CAAC,KAAuB,EAAE,EAAE;wBACnC,KAAK,CAAC,cAAc,EAAE,CAAC;wBACvB,UAAU,CAAC,OAAO,CAAC,CAAC;oBACtB,CAAC,EACD,KAAK,EAAE,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,EAAE,IAErD,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CACnB,oBAAC,cAAc,CAAC,KAAK,IAAC,GAAG,EAAC,MAAM,EAAC,KAAK,EAAC,MAAM,GAAG,CACjD,CAAC,CAAC,CAAC,CACF,oBAAC,aAAa,CAAC,KAAK,IAAC,GAAG,EAAC,MAAM,EAAC,KAAK,EAAC,MAAM,GAAG,CAChD,CACM;gBACT,4CACE,SAAS,EAAC,oBAAoB,EAC9B,KAAK,EAAE,OAAO,CAAC,IAAI,IACf,OAAO,CAAC,OAAO;oBAElB,OAAO,CAAC,MAAM;oBACd,OAAO,CAAC,IAAI,CACR,CACH;YACL,QAAQ,IAAI,CAAC,OAAO,CAAC,SAAS,IAAI,gCAAK,QAAQ,CAAM,CACnD,CACN,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,40 @@
1
+ import * as React from 'react';
2
+ import { TableOfContents } from './tokens';
3
+ /**
4
+ * Interface describing component properties.
5
+ */
6
+ export interface ITableOfContentsTreeProps {
7
+ /**
8
+ * Currently active heading.
9
+ */
10
+ activeHeading: TableOfContents.IHeading | null;
11
+ /**
12
+ * Type of document supported by the model.
13
+ */
14
+ documentType: string;
15
+ /**
16
+ * List of headings to render.
17
+ */
18
+ headings: TableOfContents.IHeading[];
19
+ /**
20
+ * Set active heading.
21
+ */
22
+ setActiveHeading: (heading: TableOfContents.IHeading) => void;
23
+ /**
24
+ * Collapse heading callback.
25
+ */
26
+ onCollapseChange: (heading: TableOfContents.IHeading) => void;
27
+ }
28
+ /**
29
+ * React component for a table of contents tree.
30
+ */
31
+ export declare class TableOfContentsTree extends React.PureComponent<ITableOfContentsTreeProps> {
32
+ /**
33
+ * Renders a table of contents tree.
34
+ */
35
+ render(): JSX.Element;
36
+ /**
37
+ * Convert the flat headings list to a nested tree list
38
+ */
39
+ protected buildTree(): JSX.Element[];
40
+ }
package/lib/toctree.js ADDED
@@ -0,0 +1,43 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+ import * as React from 'react';
4
+ import { TableOfContentsItem } from './tocitem';
5
+ /**
6
+ * React component for a table of contents tree.
7
+ */
8
+ export class TableOfContentsTree extends React.PureComponent {
9
+ /**
10
+ * Renders a table of contents tree.
11
+ */
12
+ render() {
13
+ const { documentType } = this.props;
14
+ return (React.createElement("ol", Object.assign({ className: "jp-TableOfContents-content" }, { 'data-document-type': documentType }), this.buildTree()));
15
+ }
16
+ /**
17
+ * Convert the flat headings list to a nested tree list
18
+ */
19
+ buildTree() {
20
+ if (this.props.headings.length === 0) {
21
+ return [];
22
+ }
23
+ let globalIndex = 0;
24
+ const getChildren = (items, level) => {
25
+ const nested = new Array();
26
+ while (globalIndex < items.length) {
27
+ const current = items[globalIndex];
28
+ if (current.level >= level) {
29
+ globalIndex += 1;
30
+ const next = items[globalIndex];
31
+ nested.push(React.createElement(TableOfContentsItem, { key: `${current.level}-${current.text}`, isActive: !!this.props.activeHeading &&
32
+ current === this.props.activeHeading, heading: current, onMouseDown: this.props.setActiveHeading, onCollapse: this.props.onCollapseChange }, next && next.level > level && getChildren(items, level + 1)));
33
+ }
34
+ else {
35
+ break;
36
+ }
37
+ }
38
+ return nested;
39
+ };
40
+ return getChildren(this.props.headings, this.props.headings[0].level);
41
+ }
42
+ }
43
+ //# sourceMappingURL=toctree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toctree.js","sourceRoot":"","sources":["../src/toctree.tsx"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAE3D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AA6BhD;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,KAAK,CAAC,aAAwC;IACrF;;OAEG;IACH,MAAM;QACJ,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QACpC,OAAO,CACL,0CACE,SAAS,EAAC,4BAA4B,IAClC,EAAE,oBAAoB,EAAE,YAAY,EAAE,GAEzC,IAAI,CAAC,SAAS,EAAE,CACd,CACN,CAAC;IACJ,CAAC;IAED;;OAEG;IACO,SAAS;QACjB,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;YACpC,OAAO,EAAE,CAAC;SACX;QAED,IAAI,WAAW,GAAG,CAAC,CAAC;QAEpB,MAAM,WAAW,GAAG,CAClB,KAAiC,EACjC,KAAa,EACE,EAAE;YACjB,MAAM,MAAM,GAAG,IAAI,KAAK,EAAe,CAAC;YACxC,OAAO,WAAW,GAAG,KAAK,CAAC,MAAM,EAAE;gBACjC,MAAM,OAAO,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC;gBACnC,IAAI,OAAO,CAAC,KAAK,IAAI,KAAK,EAAE;oBAC1B,WAAW,IAAI,CAAC,CAAC;oBACjB,MAAM,IAAI,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC;oBAEhC,MAAM,CAAC,IAAI,CACT,oBAAC,mBAAmB,IAClB,GAAG,EAAE,GAAG,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,IAAI,EAAE,EACvC,QAAQ,EACN,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa;4BAC1B,OAAO,KAAK,IAAI,CAAC,KAAK,CAAC,aAAa,EAEtC,OAAO,EAAE,OAAO,EAChB,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,gBAAgB,EACxC,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,gBAAgB,IAEtC,IAAI,IAAI,IAAI,CAAC,KAAK,GAAG,KAAK,IAAI,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,CACxC,CACvB,CAAC;iBACH;qBAAM;oBACL,MAAM;iBACP;aACF;YAED,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC;QAEF,OAAO,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACxE,CAAC;CACF"}
@@ -0,0 +1,235 @@
1
+ import type { ToolbarRegistry } from '@jupyterlab/apputils';
2
+ import type { IObservableList } from '@jupyterlab/observables';
3
+ import type { VDomRenderer } from '@jupyterlab/ui-components';
4
+ import type { JSONObject } from '@lumino/coreutils';
5
+ import { Token } from '@lumino/coreutils';
6
+ import type { IDisposable } from '@lumino/disposable';
7
+ import type { ISignal } from '@lumino/signaling';
8
+ import type { Widget } from '@lumino/widgets';
9
+ /**
10
+ * Interface describing the table of contents registry.
11
+ */
12
+ export interface ITableOfContentsRegistry {
13
+ /**
14
+ * Finds a table of contents model for a widget.
15
+ *
16
+ * ## Notes
17
+ *
18
+ * - If unable to find a table of contents model, the method return `undefined`.
19
+ *
20
+ * @param widget - widget
21
+ * @param configuration - Table of contents configuration
22
+ * @returns Table of contents model or undefined if not found
23
+ */
24
+ getModel(widget: Widget, configuration?: TableOfContents.IConfig): TableOfContents.Model | undefined;
25
+ /**
26
+ * Adds a table of contents factory to the registry.
27
+ *
28
+ * @param factory - table of contents factory
29
+ */
30
+ add(factory: TableOfContents.IFactory): IDisposable;
31
+ }
32
+ /**
33
+ * Table of contents registry token.
34
+ */
35
+ export declare const ITableOfContentsRegistry: Token<ITableOfContentsRegistry>;
36
+ /**
37
+ * Interface for the table of contents tracker
38
+ */
39
+ export interface ITableOfContentsTracker {
40
+ /**
41
+ * Get the model associated with a given widget.
42
+ *
43
+ * @param widget Widget
44
+ */
45
+ get(widget: Widget): TableOfContents.IModel<TableOfContents.IHeading> | null;
46
+ }
47
+ /**
48
+ * Table of contents tracker token.
49
+ */
50
+ export declare const ITableOfContentsTracker: Token<ITableOfContentsTracker>;
51
+ /**
52
+ * Namespace for table of contents interface
53
+ */
54
+ export declare namespace TableOfContents {
55
+ /**
56
+ * Table of content model factory interface
57
+ */
58
+ interface IFactory<W extends Widget = Widget> {
59
+ /**
60
+ * Whether the factory can handle the widget or not.
61
+ *
62
+ * @param widget - widget
63
+ * @returns boolean indicating a ToC can be generated
64
+ */
65
+ isApplicable: (widget: W) => boolean;
66
+ /**
67
+ * Create a new table of contents model for the widget
68
+ *
69
+ * @param widget - widget
70
+ * @param configuration - Table of contents configuration
71
+ * @returns The table of contents model
72
+ */
73
+ createNew: (widget: W, configuration?: TableOfContents.IConfig) => IModel<IHeading>;
74
+ }
75
+ /**
76
+ * Table of Contents configuration
77
+ *
78
+ * #### Notes
79
+ * A document model may ignore some of those options.
80
+ */
81
+ interface IConfig extends JSONObject {
82
+ /**
83
+ * Base level for the highest headings
84
+ */
85
+ baseNumbering: number;
86
+ /**
87
+ * Maximal depth of headings to display
88
+ */
89
+ maximalDepth: number;
90
+ /**
91
+ * Whether to number first-level headings or not.
92
+ */
93
+ numberingH1: boolean;
94
+ /**
95
+ * Whether to number headings in document or not.
96
+ */
97
+ numberHeaders: boolean;
98
+ /**
99
+ * Whether to include cell outputs in headings or not.
100
+ */
101
+ includeOutput: boolean;
102
+ /**
103
+ * Whether to synchronize heading collapse state between the ToC and the document or not.
104
+ */
105
+ syncCollapseState: boolean;
106
+ }
107
+ /**
108
+ * Default table of content configuration
109
+ */
110
+ const defaultConfig: IConfig;
111
+ /**
112
+ * Interface describing a heading.
113
+ */
114
+ interface IHeading {
115
+ /**
116
+ * Heading text.
117
+ */
118
+ text: string;
119
+ /**
120
+ * HTML heading level.
121
+ */
122
+ level: number;
123
+ /**
124
+ * Heading prefix.
125
+ */
126
+ prefix?: string | null;
127
+ /**
128
+ * Dataset to add to the item node
129
+ */
130
+ dataset?: Record<string, string>;
131
+ /**
132
+ * Whether the heading is collapsed or not
133
+ */
134
+ collapsed?: boolean;
135
+ }
136
+ /**
137
+ * Interface describing a widget table of contents model.
138
+ */
139
+ interface IModel<H extends IHeading> extends VDomRenderer.IModel {
140
+ /**
141
+ * Active heading
142
+ */
143
+ readonly activeHeading: H | null;
144
+ /**
145
+ * Signal emitted when the active heading changes.
146
+ */
147
+ readonly activeHeadingChanged: ISignal<IModel<H>, H | null>;
148
+ /**
149
+ * Signal emitted when a table of content section collapse state changes.
150
+ *
151
+ * If all headings state are set at the same time, the argument is null.
152
+ */
153
+ readonly collapseChanged: ISignal<IModel<H>, H | null>;
154
+ /**
155
+ * Model configuration
156
+ */
157
+ readonly configuration: IConfig;
158
+ /**
159
+ * Type of document supported by the model.
160
+ *
161
+ * #### Notes
162
+ * A `data-document-type` attribute with this value will be set
163
+ * on the tree view `.jp-TableOfContents-content[data-document-type="..."]`
164
+ */
165
+ readonly documentType: string;
166
+ /**
167
+ * Returns the list of headings.
168
+ *
169
+ * @returns list of headings
170
+ */
171
+ readonly headings: H[];
172
+ /**
173
+ * Signal emitted when the headings changes.
174
+ */
175
+ readonly headingsChanged: ISignal<IModel<H>, void>;
176
+ /**
177
+ * Whether the model needs to be kept up to date or not.
178
+ *
179
+ * ### Notes
180
+ * This is set to `true` if the ToC panel is visible and
181
+ * to `false` if it is hidden. But some models may require
182
+ * to be always active; e.g. to add numbering in the document.
183
+ */
184
+ isActive: boolean;
185
+ /**
186
+ * Set a new active heading.
187
+ *
188
+ * @param heading The new active heading
189
+ * @param emitSignal Whether to emit the activeHeadingChanged signal or not.
190
+ */
191
+ setActiveHeading(heading: H | null, emitSignal?: boolean): void;
192
+ /**
193
+ * Model configuration setter.
194
+ *
195
+ * @param c New configuration
196
+ */
197
+ setConfiguration(c: Partial<IConfig>): void;
198
+ /**
199
+ * List of configuration options supported by the model.
200
+ */
201
+ readonly supportedOptions: (keyof IConfig)[];
202
+ /**
203
+ * Document title
204
+ */
205
+ title?: string;
206
+ /**
207
+ * Callback on heading collapse.
208
+ *
209
+ * @param options.heading The heading to change state (all headings if not provided)
210
+ * @param options.collapsed The new collapsed status (toggle existing status if not provided)
211
+ */
212
+ toggleCollapse: (options: {
213
+ heading?: H;
214
+ collapsed?: boolean;
215
+ }) => void;
216
+ }
217
+ /**
218
+ * Generic table of contents type
219
+ */
220
+ type Model = IModel<IHeading>;
221
+ /**
222
+ * Interface describing table of contents widget options.
223
+ */
224
+ interface IOptions {
225
+ /**
226
+ * Table of contents model.
227
+ */
228
+ model?: IModel<IHeading>;
229
+ }
230
+ /**
231
+ * Interface describing a toolbar item list
232
+ */
233
+ interface IToolbarItems extends IObservableList<ToolbarRegistry.IToolbarItem> {
234
+ }
235
+ }
package/lib/tokens.js ADDED
@@ -0,0 +1,29 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+ import { Token } from '@lumino/coreutils';
4
+ /**
5
+ * Table of contents registry token.
6
+ */
7
+ export const ITableOfContentsRegistry = new Token('@jupyterlab/toc:ITableOfContentsRegistry');
8
+ /**
9
+ * Table of contents tracker token.
10
+ */
11
+ export const ITableOfContentsTracker = new Token('@jupyterlab/toc:ITableOfContentsTracker');
12
+ /**
13
+ * Namespace for table of contents interface
14
+ */
15
+ export var TableOfContents;
16
+ (function (TableOfContents) {
17
+ /**
18
+ * Default table of content configuration
19
+ */
20
+ TableOfContents.defaultConfig = {
21
+ baseNumbering: 1,
22
+ maximalDepth: 4,
23
+ numberingH1: true,
24
+ numberHeaders: false,
25
+ includeOutput: true,
26
+ syncCollapseState: false
27
+ };
28
+ })(TableOfContents || (TableOfContents = {}));
29
+ //# sourceMappingURL=tokens.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokens.js","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAM3D,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAiC1C;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,KAAK,CAC/C,0CAA0C,CAC3C,CAAC;AAcF;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,KAAK,CAC9C,yCAAyC,CAC1C,CAAC;AAEF;;GAEG;AACH,MAAM,KAAW,eAAe,CAoN/B;AApND,WAAiB,eAAe;IA2D9B;;OAEG;IACU,6BAAa,GAAY;QACpC,aAAa,EAAE,CAAC;QAChB,YAAY,EAAE,CAAC;QACf,WAAW,EAAE,IAAI;QACjB,aAAa,EAAE,KAAK;QACpB,aAAa,EAAE,IAAI;QACnB,iBAAiB,EAAE,KAAK;KACzB,CAAC;AA+IJ,CAAC,EApNgB,eAAe,KAAf,eAAe,QAoN/B"}