@jupyterlab/toc 5.4.1 → 6.0.0-alpha.10
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/lib/factory.d.ts +42 -0
- package/lib/factory.js +73 -0
- package/lib/factory.js.map +1 -0
- package/lib/index.d.ts +9 -4
- package/lib/index.js +10 -5
- package/lib/index.js.map +1 -1
- package/lib/model.d.ts +117 -0
- package/lib/model.js +218 -0
- package/lib/model.js.map +1 -0
- package/lib/panel.d.ts +26 -0
- package/lib/panel.js +89 -0
- package/lib/panel.js.map +1 -0
- package/lib/registry.d.ts +11 -119
- package/lib/registry.js +17 -32
- package/lib/registry.js.map +1 -1
- package/lib/tocitem.d.ts +34 -0
- package/lib/tocitem.js +34 -0
- package/lib/tocitem.js.map +1 -0
- package/lib/toctree.d.ts +40 -0
- package/lib/toctree.js +43 -0
- package/lib/toctree.js.map +1 -0
- package/lib/tokens.d.ts +228 -0
- package/lib/tokens.js +29 -0
- package/lib/tokens.js.map +1 -0
- package/lib/tracker.d.ts +26 -0
- package/lib/tracker.js +33 -0
- package/lib/tracker.js.map +1 -0
- package/lib/treeview.d.ts +20 -0
- package/lib/treeview.js +35 -0
- package/lib/treeview.js.map +1 -0
- package/lib/utils/common.d.ts +65 -0
- package/lib/utils/common.js +158 -0
- package/lib/utils/common.js.map +1 -0
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/{numbering_dictionary.js → index.js} +3 -2
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/markdown.d.ts +46 -0
- package/lib/utils/markdown.js +200 -0
- package/lib/utils/markdown.js.map +1 -0
- package/package.json +17 -24
- package/style/base.css +45 -383
- package/style/index.css +0 -5
- package/style/index.js +0 -5
- package/lib/generators/index.d.ts +0 -4
- package/lib/generators/index.js +0 -8
- package/lib/generators/index.js.map +0 -1
- package/lib/generators/latex/index.d.ts +0 -15
- package/lib/generators/latex/index.js +0 -111
- package/lib/generators/latex/index.js.map +0 -1
- package/lib/generators/markdown/get_headings.d.ts +0 -25
- package/lib/generators/markdown/get_headings.js +0 -51
- package/lib/generators/markdown/get_headings.js.map +0 -1
- package/lib/generators/markdown/get_rendered_headings.d.ts +0 -19
- package/lib/generators/markdown/get_rendered_headings.js +0 -68
- package/lib/generators/markdown/get_rendered_headings.js.map +0 -1
- package/lib/generators/markdown/index.d.ts +0 -34
- package/lib/generators/markdown/index.js +0 -176
- package/lib/generators/markdown/index.js.map +0 -1
- package/lib/generators/markdown/options_manager.d.ts +0 -74
- package/lib/generators/markdown/options_manager.js +0 -65
- package/lib/generators/markdown/options_manager.js.map +0 -1
- package/lib/generators/markdown/render.d.ts +0 -16
- package/lib/generators/markdown/render.js +0 -34
- package/lib/generators/markdown/render.js.map +0 -1
- package/lib/generators/markdown/toolbar_generator.d.ts +0 -66
- package/lib/generators/markdown/toolbar_generator.js +0 -49
- package/lib/generators/markdown/toolbar_generator.js.map +0 -1
- package/lib/generators/notebook/append_collapsible_heading.d.ts +0 -19
- package/lib/generators/notebook/append_collapsible_heading.js +0 -63
- package/lib/generators/notebook/append_collapsible_heading.js.map +0 -1
- package/lib/generators/notebook/append_heading.d.ts +0 -13
- package/lib/generators/notebook/append_heading.js +0 -33
- package/lib/generators/notebook/append_heading.js.map +0 -1
- package/lib/generators/notebook/append_markdown_heading.d.ts +0 -20
- package/lib/generators/notebook/append_markdown_heading.js +0 -33
- package/lib/generators/notebook/append_markdown_heading.js.map +0 -1
- package/lib/generators/notebook/codemirror.d.ts +0 -57
- package/lib/generators/notebook/codemirror.js +0 -46
- package/lib/generators/notebook/codemirror.js.map +0 -1
- package/lib/generators/notebook/get_code_cell_heading.d.ts +0 -27
- package/lib/generators/notebook/get_code_cell_heading.js +0 -48
- package/lib/generators/notebook/get_code_cell_heading.js.map +0 -1
- package/lib/generators/notebook/get_last_heading_level.d.ts +0 -13
- package/lib/generators/notebook/get_last_heading_level.js +0 -26
- package/lib/generators/notebook/get_last_heading_level.js.map +0 -1
- package/lib/generators/notebook/get_markdown_heading.d.ts +0 -27
- package/lib/generators/notebook/get_markdown_heading.js +0 -60
- package/lib/generators/notebook/get_markdown_heading.js.map +0 -1
- package/lib/generators/notebook/get_rendered_html_heading.d.ts +0 -31
- package/lib/generators/notebook/get_rendered_html_heading.js +0 -83
- package/lib/generators/notebook/get_rendered_html_heading.js.map +0 -1
- package/lib/generators/notebook/index.d.ts +0 -17
- package/lib/generators/notebook/index.js +0 -225
- package/lib/generators/notebook/index.js.map +0 -1
- package/lib/generators/notebook/is_heading_filtered.d.ts +0 -14
- package/lib/generators/notebook/is_heading_filtered.js +0 -35
- package/lib/generators/notebook/is_heading_filtered.js.map +0 -1
- package/lib/generators/notebook/options_manager.d.ts +0 -163
- package/lib/generators/notebook/options_manager.js +0 -210
- package/lib/generators/notebook/options_manager.js.map +0 -1
- package/lib/generators/notebook/render.d.ts +0 -15
- package/lib/generators/notebook/render.js +0 -161
- package/lib/generators/notebook/render.js.map +0 -1
- package/lib/generators/notebook/tagstool/index.d.ts +0 -111
- package/lib/generators/notebook/tagstool/index.js +0 -189
- package/lib/generators/notebook/tagstool/index.js.map +0 -1
- package/lib/generators/notebook/tagstool/tag.d.ts +0 -47
- package/lib/generators/notebook/tagstool/tag.js +0 -34
- package/lib/generators/notebook/tagstool/tag.js.map +0 -1
- package/lib/generators/notebook/tagstool/tag_list.d.ts +0 -70
- package/lib/generators/notebook/tagstool/tag_list.js +0 -70
- package/lib/generators/notebook/tagstool/tag_list.js.map +0 -1
- package/lib/generators/notebook/toolbar_generator.d.ts +0 -112
- package/lib/generators/notebook/toolbar_generator.js +0 -151
- package/lib/generators/notebook/toolbar_generator.js.map +0 -1
- package/lib/generators/python/index.d.ts +0 -15
- package/lib/generators/python/index.js +0 -91
- package/lib/generators/python/index.js.map +0 -1
- package/lib/generators/python/render.d.ts +0 -14
- package/lib/generators/python/render.js +0 -25
- package/lib/generators/python/render.js.map +0 -1
- package/lib/toc.d.ts +0 -100
- package/lib/toc.js +0 -163
- package/lib/toc.js.map +0 -1
- package/lib/toc_item.d.ts +0 -55
- package/lib/toc_item.js +0 -41
- package/lib/toc_item.js.map +0 -1
- package/lib/toc_tree.d.ts +0 -61
- package/lib/toc_tree.js +0 -31
- package/lib/toc_tree.js.map +0 -1
- package/lib/utils/generate_numbering.d.ts +0 -14
- package/lib/utils/generate_numbering.js +0 -57
- package/lib/utils/generate_numbering.js.map +0 -1
- package/lib/utils/headings.d.ts +0 -93
- package/lib/utils/headings.js +0 -30
- package/lib/utils/headings.js.map +0 -1
- package/lib/utils/is_dom.d.ts +0 -20
- package/lib/utils/is_dom.js +0 -25
- package/lib/utils/is_dom.js.map +0 -1
- package/lib/utils/is_markdown.d.ts +0 -20
- package/lib/utils/is_markdown.js +0 -28
- package/lib/utils/is_markdown.js.map +0 -1
- package/lib/utils/numbering_dictionary.d.ts +0 -15
- package/lib/utils/numbering_dictionary.js.map +0 -1
- package/lib/utils/parse_heading.d.ts +0 -75
- package/lib/utils/parse_heading.js +0 -91
- package/lib/utils/parse_heading.js.map +0 -1
- package/lib/utils/sanitizer_options.d.ts +0 -23
- package/lib/utils/sanitizer_options.js +0 -45
- package/lib/utils/sanitizer_options.js.map +0 -1
package/lib/factory.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { IWidgetTracker } from '@jupyterlab/apputils';
|
|
2
|
+
import { IDocumentWidget } from '@jupyterlab/docregistry';
|
|
3
|
+
import { Widget } from '@lumino/widgets';
|
|
4
|
+
import { TableOfContentsModel } from './model';
|
|
5
|
+
import { TableOfContents } from './tokens';
|
|
6
|
+
/**
|
|
7
|
+
* Abstract table of contents model factory for IDocumentWidget.
|
|
8
|
+
*/
|
|
9
|
+
export declare abstract class TableOfContentsFactory<W extends IDocumentWidget> implements TableOfContents.IFactory<W> {
|
|
10
|
+
protected tracker: IWidgetTracker<W>;
|
|
11
|
+
/**
|
|
12
|
+
* Constructor
|
|
13
|
+
*
|
|
14
|
+
* @param tracker Widget tracker
|
|
15
|
+
*/
|
|
16
|
+
constructor(tracker: IWidgetTracker<W>);
|
|
17
|
+
/**
|
|
18
|
+
* Whether the factory can handle the widget or not.
|
|
19
|
+
*
|
|
20
|
+
* @param widget - widget
|
|
21
|
+
* @returns boolean indicating a ToC can be generated
|
|
22
|
+
*/
|
|
23
|
+
isApplicable(widget: Widget): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Create a new table of contents model for the widget
|
|
26
|
+
*
|
|
27
|
+
* @param widget - widget
|
|
28
|
+
* @param configuration - Table of contents configuration
|
|
29
|
+
* @returns The table of contents model
|
|
30
|
+
*/
|
|
31
|
+
createNew(widget: W, configuration?: TableOfContents.IConfig): TableOfContentsModel<TableOfContents.IHeading, W>;
|
|
32
|
+
/**
|
|
33
|
+
* Abstract table of contents model instantiation to allow
|
|
34
|
+
* override by real implementation to customize it. The public
|
|
35
|
+
* `createNew` contains the signal connections standards for IDocumentWidget
|
|
36
|
+
* when the model has been instantiated.
|
|
37
|
+
*
|
|
38
|
+
* @param widget
|
|
39
|
+
* @param configuration
|
|
40
|
+
*/
|
|
41
|
+
protected abstract _createNew(widget: W, configuration?: TableOfContents.IConfig): TableOfContentsModel<TableOfContents.IHeading, W>;
|
|
42
|
+
}
|
package/lib/factory.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
import { ActivityMonitor, PathExt } from '@jupyterlab/coreutils';
|
|
4
|
+
/**
|
|
5
|
+
* Timeout for throttling ToC rendering following model changes.
|
|
6
|
+
*
|
|
7
|
+
* @private
|
|
8
|
+
*/
|
|
9
|
+
const RENDER_TIMEOUT = 1000;
|
|
10
|
+
/**
|
|
11
|
+
* Abstract table of contents model factory for IDocumentWidget.
|
|
12
|
+
*/
|
|
13
|
+
export class TableOfContentsFactory {
|
|
14
|
+
/**
|
|
15
|
+
* Constructor
|
|
16
|
+
*
|
|
17
|
+
* @param tracker Widget tracker
|
|
18
|
+
*/
|
|
19
|
+
constructor(tracker) {
|
|
20
|
+
this.tracker = tracker;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Whether the factory can handle the widget or not.
|
|
24
|
+
*
|
|
25
|
+
* @param widget - widget
|
|
26
|
+
* @returns boolean indicating a ToC can be generated
|
|
27
|
+
*/
|
|
28
|
+
isApplicable(widget) {
|
|
29
|
+
if (!this.tracker.has(widget)) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Create a new table of contents model for the widget
|
|
36
|
+
*
|
|
37
|
+
* @param widget - widget
|
|
38
|
+
* @param configuration - Table of contents configuration
|
|
39
|
+
* @returns The table of contents model
|
|
40
|
+
*/
|
|
41
|
+
createNew(widget, configuration) {
|
|
42
|
+
const model = this._createNew(widget, configuration);
|
|
43
|
+
const context = widget.context;
|
|
44
|
+
const updateHeadings = () => {
|
|
45
|
+
model.refresh().catch(reason => {
|
|
46
|
+
console.error('Failed to update the table of contents.', reason);
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
const monitor = new ActivityMonitor({
|
|
50
|
+
signal: context.model.contentChanged,
|
|
51
|
+
timeout: RENDER_TIMEOUT
|
|
52
|
+
});
|
|
53
|
+
monitor.activityStopped.connect(updateHeadings);
|
|
54
|
+
const updateTitle = () => {
|
|
55
|
+
model.title = PathExt.basename(context.localPath);
|
|
56
|
+
};
|
|
57
|
+
context.pathChanged.connect(updateTitle);
|
|
58
|
+
context.ready
|
|
59
|
+
.then(() => {
|
|
60
|
+
updateTitle();
|
|
61
|
+
updateHeadings();
|
|
62
|
+
})
|
|
63
|
+
.catch(reason => {
|
|
64
|
+
console.error(`Failed to initiate headings for ${context.localPath}.`);
|
|
65
|
+
});
|
|
66
|
+
widget.disposed.connect(() => {
|
|
67
|
+
monitor.activityStopped.disconnect(updateHeadings);
|
|
68
|
+
context.pathChanged.disconnect(updateTitle);
|
|
69
|
+
});
|
|
70
|
+
return model;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAG3D,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAMjE;;;;GAIG;AACH,MAAM,cAAc,GAAG,IAAI,CAAC;AAE5B;;GAEG;AACH,MAAM,OAAgB,sBAAsB;IAG1C;;;;OAIG;IACH,YAAsB,OAA0B;QAA1B,YAAO,GAAP,OAAO,CAAmB;IAAG,CAAC;IAEpD;;;;;OAKG;IACH,YAAY,CAAC,MAAc;QACzB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;YAC7B,OAAO,KAAK,CAAC;SACd;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;OAMG;IACH,SAAS,CACP,MAAS,EACT,aAAuC;QAEvC,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;QAErD,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAE/B,MAAM,cAAc,GAAG,GAAG,EAAE;YAC1B,KAAK,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;gBAC7B,OAAO,CAAC,KAAK,CAAC,yCAAyC,EAAE,MAAM,CAAC,CAAC;YACnE,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;QACF,MAAM,OAAO,GAAG,IAAI,eAAe,CAAC;YAClC,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,cAAc;YACpC,OAAO,EAAE,cAAc;SACxB,CAAC,CAAC;QACH,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QAEhD,MAAM,WAAW,GAAG,GAAG,EAAE;YACvB,KAAK,CAAC,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACpD,CAAC,CAAC;QACF,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAEzC,OAAO,CAAC,KAAK;aACV,IAAI,CAAC,GAAG,EAAE;YACT,WAAW,EAAE,CAAC;YACd,cAAc,EAAE,CAAC;QACnB,CAAC,CAAC;aACD,KAAK,CAAC,MAAM,CAAC,EAAE;YACd,OAAO,CAAC,KAAK,CAAC,mCAAmC,OAAO,CAAC,SAAS,GAAG,CAAC,CAAC;QACzE,CAAC,CAAC,CAAC;QAEL,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE;YAC3B,OAAO,CAAC,eAAe,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;YACnD,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;CAeF"}
|
package/lib/index.d.ts
CHANGED
|
@@ -2,8 +2,13 @@
|
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
* @module toc
|
|
4
4
|
*/
|
|
5
|
-
export * from './
|
|
5
|
+
export * from './factory';
|
|
6
|
+
export * from './model';
|
|
7
|
+
export * from './panel';
|
|
6
8
|
export * from './registry';
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './
|
|
9
|
+
export * from './treeview';
|
|
10
|
+
export * from './tocitem';
|
|
11
|
+
export * from './toctree';
|
|
12
|
+
export * from './tokens';
|
|
13
|
+
export * from './tracker';
|
|
14
|
+
export * as TableOfContentsUtils from './utils';
|
package/lib/index.js
CHANGED
|
@@ -4,10 +4,15 @@
|
|
|
4
4
|
* @packageDocumentation
|
|
5
5
|
* @module toc
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
export * from './
|
|
7
|
+
export * from './factory';
|
|
8
|
+
export * from './model';
|
|
9
|
+
export * from './panel';
|
|
9
10
|
export * from './registry';
|
|
10
|
-
export * from './
|
|
11
|
-
export * from './
|
|
12
|
-
export * from './
|
|
11
|
+
export * from './treeview';
|
|
12
|
+
export * from './tocitem';
|
|
13
|
+
export * from './toctree';
|
|
14
|
+
export * from './tokens';
|
|
15
|
+
export * from './tracker';
|
|
16
|
+
// Namespace the utils
|
|
17
|
+
export * as TableOfContentsUtils from './utils';
|
|
13
18
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAC3D;;;GAGG;AAEH,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAC3D;;;GAGG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,sBAAsB;AACtB,OAAO,KAAK,oBAAoB,MAAM,SAAS,CAAC"}
|
package/lib/model.d.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { VDomModel } from '@jupyterlab/ui-components';
|
|
2
|
+
import { ISignal } from '@lumino/signaling';
|
|
3
|
+
import { Widget } from '@lumino/widgets';
|
|
4
|
+
import { TableOfContents } from './tokens';
|
|
5
|
+
/**
|
|
6
|
+
* Abstract table of contents model.
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class TableOfContentsModel<H extends TableOfContents.IHeading, T extends Widget = Widget> extends VDomModel implements TableOfContents.IModel<H> {
|
|
9
|
+
protected widget: T;
|
|
10
|
+
/**
|
|
11
|
+
* Constructor
|
|
12
|
+
*
|
|
13
|
+
* @param widget The widget to search in
|
|
14
|
+
* @param configuration Default model configuration
|
|
15
|
+
*/
|
|
16
|
+
constructor(widget: T, configuration?: TableOfContents.IConfig);
|
|
17
|
+
/**
|
|
18
|
+
* Current active entry.
|
|
19
|
+
*
|
|
20
|
+
* @returns table of contents active entry
|
|
21
|
+
*/
|
|
22
|
+
get activeHeading(): H | null;
|
|
23
|
+
set activeHeading(heading: H | null);
|
|
24
|
+
/**
|
|
25
|
+
* Signal emitted when the active heading changes.
|
|
26
|
+
*/
|
|
27
|
+
get activeHeadingChanged(): ISignal<TableOfContents.IModel<H>, H | null>;
|
|
28
|
+
/**
|
|
29
|
+
* Signal emitted when a table of content section collapse state changes.
|
|
30
|
+
*/
|
|
31
|
+
get collapseChanged(): ISignal<TableOfContents.IModel<H>, H | null>;
|
|
32
|
+
/**
|
|
33
|
+
* Model configuration
|
|
34
|
+
*/
|
|
35
|
+
get configuration(): TableOfContents.IConfig;
|
|
36
|
+
/**
|
|
37
|
+
* Type of document supported by the model.
|
|
38
|
+
*
|
|
39
|
+
* #### Notes
|
|
40
|
+
* A `data-document-type` attribute with this value will be set
|
|
41
|
+
* on the tree view `.jp-TableOfContents-content[data-document-type="..."]`
|
|
42
|
+
*/
|
|
43
|
+
abstract readonly documentType: string;
|
|
44
|
+
/**
|
|
45
|
+
* List of headings.
|
|
46
|
+
*
|
|
47
|
+
* @returns table of contents list of headings
|
|
48
|
+
*/
|
|
49
|
+
get headings(): H[];
|
|
50
|
+
/**
|
|
51
|
+
* Signal emitted when the headings changes.
|
|
52
|
+
*/
|
|
53
|
+
get headingsChanged(): ISignal<TableOfContents.IModel<H>, void>;
|
|
54
|
+
/**
|
|
55
|
+
* Whether the model is active or not.
|
|
56
|
+
*
|
|
57
|
+
* #### Notes
|
|
58
|
+
* An active model means it is displayed in the table of contents.
|
|
59
|
+
* This can be used by subclass to limit updating the headings.
|
|
60
|
+
*/
|
|
61
|
+
get isActive(): boolean;
|
|
62
|
+
set isActive(v: boolean);
|
|
63
|
+
/**
|
|
64
|
+
* Whether the model gets updated even if the table of contents panel
|
|
65
|
+
* is hidden or not.
|
|
66
|
+
*
|
|
67
|
+
* #### Notes
|
|
68
|
+
* For example, ToC models use to add title numbering will
|
|
69
|
+
* set this to true.
|
|
70
|
+
*/
|
|
71
|
+
protected get isAlwaysActive(): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Model configuration setter.
|
|
74
|
+
*
|
|
75
|
+
* @param c New configuration
|
|
76
|
+
*/
|
|
77
|
+
setConfiguration(c: Partial<TableOfContents.IConfig>): void;
|
|
78
|
+
/**
|
|
79
|
+
* List of configuration options supported by the model.
|
|
80
|
+
*/
|
|
81
|
+
get supportedOptions(): (keyof TableOfContents.IConfig)[];
|
|
82
|
+
/**
|
|
83
|
+
* Document title
|
|
84
|
+
*/
|
|
85
|
+
get title(): string | undefined;
|
|
86
|
+
set title(v: string | undefined);
|
|
87
|
+
/**
|
|
88
|
+
* Abstract function that will produce the headings for a document.
|
|
89
|
+
*
|
|
90
|
+
* @returns The list of new headings or `null` if nothing needs to be updated.
|
|
91
|
+
*/
|
|
92
|
+
protected abstract getHeadings(): Promise<H[] | null>;
|
|
93
|
+
/**
|
|
94
|
+
* Refresh the headings list.
|
|
95
|
+
*/
|
|
96
|
+
refresh(): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Callback on heading collapse.
|
|
99
|
+
*
|
|
100
|
+
* @param options.heading The heading to change state (all headings if not provided)
|
|
101
|
+
* @param options.collapsed The new collapsed status (toggle existing status if not provided)
|
|
102
|
+
*/
|
|
103
|
+
toggleCollapse(options: {
|
|
104
|
+
heading?: H;
|
|
105
|
+
collapsed?: boolean;
|
|
106
|
+
}): void;
|
|
107
|
+
private _activeHeading;
|
|
108
|
+
private _activeHeadingChanged;
|
|
109
|
+
private _collapseChanged;
|
|
110
|
+
private _configuration;
|
|
111
|
+
private _headings;
|
|
112
|
+
private _headingsChanged;
|
|
113
|
+
private _isActive;
|
|
114
|
+
private _isRefreshing;
|
|
115
|
+
private _needsRefreshing;
|
|
116
|
+
private _title?;
|
|
117
|
+
}
|
package/lib/model.js
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
import { VDomModel } from '@jupyterlab/ui-components';
|
|
4
|
+
import { JSONExt } from '@lumino/coreutils';
|
|
5
|
+
import { Signal } from '@lumino/signaling';
|
|
6
|
+
import { TableOfContents } from './tokens';
|
|
7
|
+
/**
|
|
8
|
+
* Abstract table of contents model.
|
|
9
|
+
*/
|
|
10
|
+
export class TableOfContentsModel extends VDomModel {
|
|
11
|
+
/**
|
|
12
|
+
* Constructor
|
|
13
|
+
*
|
|
14
|
+
* @param widget The widget to search in
|
|
15
|
+
* @param configuration Default model configuration
|
|
16
|
+
*/
|
|
17
|
+
constructor(widget, configuration) {
|
|
18
|
+
super();
|
|
19
|
+
this.widget = widget;
|
|
20
|
+
this._activeHeading = null;
|
|
21
|
+
this._activeHeadingChanged = new Signal(this);
|
|
22
|
+
this._collapseChanged = new Signal(this);
|
|
23
|
+
this._configuration = configuration !== null && configuration !== void 0 ? configuration : Object.assign({}, TableOfContents.defaultConfig);
|
|
24
|
+
this._headings = new Array();
|
|
25
|
+
this._headingsChanged = new Signal(this);
|
|
26
|
+
this._isActive = false;
|
|
27
|
+
this._isRefreshing = false;
|
|
28
|
+
this._needsRefreshing = false;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Current active entry.
|
|
32
|
+
*
|
|
33
|
+
* @returns table of contents active entry
|
|
34
|
+
*/
|
|
35
|
+
get activeHeading() {
|
|
36
|
+
return this._activeHeading;
|
|
37
|
+
}
|
|
38
|
+
set activeHeading(heading) {
|
|
39
|
+
if (this._activeHeading !== heading) {
|
|
40
|
+
this._activeHeading = heading;
|
|
41
|
+
this.stateChanged.emit();
|
|
42
|
+
this._activeHeadingChanged.emit(heading);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Signal emitted when the active heading changes.
|
|
47
|
+
*/
|
|
48
|
+
get activeHeadingChanged() {
|
|
49
|
+
return this._activeHeadingChanged;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Signal emitted when a table of content section collapse state changes.
|
|
53
|
+
*/
|
|
54
|
+
get collapseChanged() {
|
|
55
|
+
return this._collapseChanged;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Model configuration
|
|
59
|
+
*/
|
|
60
|
+
get configuration() {
|
|
61
|
+
return this._configuration;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* List of headings.
|
|
65
|
+
*
|
|
66
|
+
* @returns table of contents list of headings
|
|
67
|
+
*/
|
|
68
|
+
get headings() {
|
|
69
|
+
return this._headings;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Signal emitted when the headings changes.
|
|
73
|
+
*/
|
|
74
|
+
get headingsChanged() {
|
|
75
|
+
return this._headingsChanged;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Whether the model is active or not.
|
|
79
|
+
*
|
|
80
|
+
* #### Notes
|
|
81
|
+
* An active model means it is displayed in the table of contents.
|
|
82
|
+
* This can be used by subclass to limit updating the headings.
|
|
83
|
+
*/
|
|
84
|
+
get isActive() {
|
|
85
|
+
return this._isActive;
|
|
86
|
+
}
|
|
87
|
+
set isActive(v) {
|
|
88
|
+
this._isActive = v;
|
|
89
|
+
// Refresh on activation expect if it is always active
|
|
90
|
+
// => a ToC model is always active e.g. when displaying numbering in the document
|
|
91
|
+
if (this._isActive && !this.isAlwaysActive) {
|
|
92
|
+
this.refresh().catch(reason => {
|
|
93
|
+
console.error('Failed to refresh ToC model.', reason);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Whether the model gets updated even if the table of contents panel
|
|
99
|
+
* is hidden or not.
|
|
100
|
+
*
|
|
101
|
+
* #### Notes
|
|
102
|
+
* For example, ToC models use to add title numbering will
|
|
103
|
+
* set this to true.
|
|
104
|
+
*/
|
|
105
|
+
get isAlwaysActive() {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Model configuration setter.
|
|
110
|
+
*
|
|
111
|
+
* @param c New configuration
|
|
112
|
+
*/
|
|
113
|
+
setConfiguration(c) {
|
|
114
|
+
const newConfiguration = Object.assign(Object.assign({}, this._configuration), c);
|
|
115
|
+
if (!JSONExt.deepEqual(this._configuration, newConfiguration)) {
|
|
116
|
+
this._configuration = newConfiguration;
|
|
117
|
+
this.refresh().catch(reason => {
|
|
118
|
+
console.error('Failed to update the table of contents.', reason);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* List of configuration options supported by the model.
|
|
124
|
+
*/
|
|
125
|
+
get supportedOptions() {
|
|
126
|
+
return ['maximalDepth'];
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Document title
|
|
130
|
+
*/
|
|
131
|
+
get title() {
|
|
132
|
+
return this._title;
|
|
133
|
+
}
|
|
134
|
+
set title(v) {
|
|
135
|
+
if (v !== this._title) {
|
|
136
|
+
this._title = v;
|
|
137
|
+
this.stateChanged.emit();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Refresh the headings list.
|
|
142
|
+
*/
|
|
143
|
+
async refresh() {
|
|
144
|
+
if (this._isRefreshing) {
|
|
145
|
+
// Schedule a refresh if one is in progress
|
|
146
|
+
this._needsRefreshing = true;
|
|
147
|
+
return Promise.resolve();
|
|
148
|
+
}
|
|
149
|
+
this._isRefreshing = true;
|
|
150
|
+
try {
|
|
151
|
+
const newHeadings = await this.getHeadings();
|
|
152
|
+
if (this._needsRefreshing) {
|
|
153
|
+
this._needsRefreshing = false;
|
|
154
|
+
this._isRefreshing = false;
|
|
155
|
+
return this.refresh();
|
|
156
|
+
}
|
|
157
|
+
if (newHeadings &&
|
|
158
|
+
!Private.areHeadingsEqual(newHeadings, this._headings)) {
|
|
159
|
+
this._headings = newHeadings;
|
|
160
|
+
this.stateChanged.emit();
|
|
161
|
+
this._headingsChanged.emit();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
finally {
|
|
165
|
+
this._isRefreshing = false;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Callback on heading collapse.
|
|
170
|
+
*
|
|
171
|
+
* @param options.heading The heading to change state (all headings if not provided)
|
|
172
|
+
* @param options.collapsed The new collapsed status (toggle existing status if not provided)
|
|
173
|
+
*/
|
|
174
|
+
toggleCollapse(options) {
|
|
175
|
+
var _a, _b;
|
|
176
|
+
if (options.heading) {
|
|
177
|
+
options.heading.collapsed =
|
|
178
|
+
(_a = options.collapsed) !== null && _a !== void 0 ? _a : !options.heading.collapsed;
|
|
179
|
+
this.stateChanged.emit();
|
|
180
|
+
this._collapseChanged.emit(options.heading);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
// Use the provided state or collapsed all except if all are collapsed
|
|
184
|
+
const newState = (_b = options.collapsed) !== null && _b !== void 0 ? _b : !this.headings.some(h => { var _a; return !((_a = h.collapsed) !== null && _a !== void 0 ? _a : false); });
|
|
185
|
+
this.headings.forEach(h => (h.collapsed = newState));
|
|
186
|
+
this.stateChanged.emit();
|
|
187
|
+
this._collapseChanged.emit(null);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Private functions namespace
|
|
193
|
+
*/
|
|
194
|
+
var Private;
|
|
195
|
+
(function (Private) {
|
|
196
|
+
/**
|
|
197
|
+
* Test if two list of headings are equal or not.
|
|
198
|
+
*
|
|
199
|
+
* @param headings1 First list of headings
|
|
200
|
+
* @param headings2 Second list of headings
|
|
201
|
+
* @returns Whether the array are identical or not.
|
|
202
|
+
*/
|
|
203
|
+
function areHeadingsEqual(headings1, headings2) {
|
|
204
|
+
if (headings1.length === headings2.length) {
|
|
205
|
+
for (let i = 0; i < headings1.length; i++) {
|
|
206
|
+
if (headings1[i].level !== headings2[i].level ||
|
|
207
|
+
headings1[i].text !== headings2[i].text ||
|
|
208
|
+
headings1[i].prefix !== headings2[i].prefix) {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
Private.areHeadingsEqual = areHeadingsEqual;
|
|
217
|
+
})(Private || (Private = {}));
|
|
218
|
+
//# sourceMappingURL=model.js.map
|
package/lib/model.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAE3D,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAW,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C;;GAEG;AACH,MAAM,OAAgB,oBAIpB,SAAQ,SAAS;IAGjB;;;;;OAKG;IACH,YAAsB,MAAS,EAAE,aAAuC;QACtE,KAAK,EAAE,CAAC;QADY,WAAM,GAAN,MAAM,CAAG;QAE7B,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;QAC3B,IAAI,CAAC,qBAAqB,GAAG,IAAI,MAAM,CAGrC,IAAI,CAAC,CAAC;QACR,IAAI,CAAC,gBAAgB,GAAG,IAAI,MAAM,CAAgC,IAAI,CAAC,CAAC;QACxE,IAAI,CAAC,cAAc,GAAG,aAAa,aAAb,aAAa,cAAb,aA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EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,GAAG,QAAQ,CAAC,CAAC,CAAC;YACrD,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;YACzB,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SAClC;IACH,CAAC;CAYF;AAED;;GAEG;AACH,IAAU,OAAO,CA2BhB;AA3BD,WAAU,OAAO;IACf;;;;;;OAMG;IACH,SAAgB,gBAAgB,CAC9B,SAAqC,EACrC,SAAqC;QAErC,IAAI,SAAS,CAAC,MAAM,KAAK,SAAS,CAAC,MAAM,EAAE;YACzC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBACzC,IACE,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK;oBACzC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI;oBACvC,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,EAC3C;oBACA,OAAO,KAAK,CAAC;iBACd;aACF;YACD,OAAO,IAAI,CAAC;SACb;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAlBe,wBAAgB,mBAkB/B,CAAA;AACH,CAAC,EA3BS,OAAO,KAAP,OAAO,QA2BhB"}
|
package/lib/panel.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ITranslator } from '@jupyterlab/translation';
|
|
2
|
+
import { SidePanel } from '@jupyterlab/ui-components';
|
|
3
|
+
import { TableOfContents } from './tokens';
|
|
4
|
+
import { Message } from '@lumino/messaging';
|
|
5
|
+
/**
|
|
6
|
+
* Table of contents sidebar panel.
|
|
7
|
+
*/
|
|
8
|
+
export declare class TableOfContentsPanel extends SidePanel {
|
|
9
|
+
/**
|
|
10
|
+
* Constructor
|
|
11
|
+
*
|
|
12
|
+
* @param translator - Translator tool
|
|
13
|
+
*/
|
|
14
|
+
constructor(translator?: ITranslator);
|
|
15
|
+
/**
|
|
16
|
+
* Get the current model.
|
|
17
|
+
*/
|
|
18
|
+
get model(): TableOfContents.Model | null;
|
|
19
|
+
set model(newValue: TableOfContents.Model | null);
|
|
20
|
+
protected onAfterHide(msg: Message): void;
|
|
21
|
+
protected onBeforeShow(msg: Message): void;
|
|
22
|
+
private _onTitleChanged;
|
|
23
|
+
private _model;
|
|
24
|
+
private _title;
|
|
25
|
+
private _treeview;
|
|
26
|
+
}
|
package/lib/panel.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { SidePanel } from '@jupyterlab/ui-components';
|
|
2
|
+
import { Panel, Widget } from '@lumino/widgets';
|
|
3
|
+
import { TableOfContentsWidget } from './treeview';
|
|
4
|
+
/**
|
|
5
|
+
* Table of contents sidebar panel.
|
|
6
|
+
*/
|
|
7
|
+
export class TableOfContentsPanel extends SidePanel {
|
|
8
|
+
/**
|
|
9
|
+
* Constructor
|
|
10
|
+
*
|
|
11
|
+
* @param translator - Translator tool
|
|
12
|
+
*/
|
|
13
|
+
constructor(translator) {
|
|
14
|
+
super({ content: new Panel(), translator });
|
|
15
|
+
this._model = null;
|
|
16
|
+
this.addClass('jp-TableOfContents');
|
|
17
|
+
this._title = new Private.Header(this._trans.__('Table of Contents'));
|
|
18
|
+
this.header.addWidget(this._title);
|
|
19
|
+
this._treeview = new TableOfContentsWidget();
|
|
20
|
+
this._treeview.addClass('jp-TableOfContents-tree');
|
|
21
|
+
this.content.addWidget(this._treeview);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get the current model.
|
|
25
|
+
*/
|
|
26
|
+
get model() {
|
|
27
|
+
return this._model;
|
|
28
|
+
}
|
|
29
|
+
set model(newValue) {
|
|
30
|
+
var _a, _b;
|
|
31
|
+
if (this._model !== newValue) {
|
|
32
|
+
(_a = this._model) === null || _a === void 0 ? void 0 : _a.stateChanged.disconnect(this._onTitleChanged, this);
|
|
33
|
+
this._model = newValue;
|
|
34
|
+
if (this._model) {
|
|
35
|
+
this._model.isActive = this.isVisible;
|
|
36
|
+
}
|
|
37
|
+
(_b = this._model) === null || _b === void 0 ? void 0 : _b.stateChanged.connect(this._onTitleChanged, this);
|
|
38
|
+
this._onTitleChanged();
|
|
39
|
+
this._treeview.model = this._model;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
onAfterHide(msg) {
|
|
43
|
+
super.onAfterHide(msg);
|
|
44
|
+
if (this._model) {
|
|
45
|
+
this._model.isActive = false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
onBeforeShow(msg) {
|
|
49
|
+
super.onBeforeShow(msg);
|
|
50
|
+
if (this._model) {
|
|
51
|
+
this._model.isActive = true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
_onTitleChanged() {
|
|
55
|
+
var _a, _b;
|
|
56
|
+
this._title.setTitle((_b = (_a = this._model) === null || _a === void 0 ? void 0 : _a.title) !== null && _b !== void 0 ? _b : this._trans.__('Table of Contents'));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Private helpers namespace
|
|
61
|
+
*/
|
|
62
|
+
var Private;
|
|
63
|
+
(function (Private) {
|
|
64
|
+
/**
|
|
65
|
+
* Panel header
|
|
66
|
+
*/
|
|
67
|
+
class Header extends Widget {
|
|
68
|
+
/**
|
|
69
|
+
* Constructor
|
|
70
|
+
*
|
|
71
|
+
* @param title - Title text
|
|
72
|
+
*/
|
|
73
|
+
constructor(title) {
|
|
74
|
+
const node = document.createElement('h2');
|
|
75
|
+
node.textContent = title;
|
|
76
|
+
node.classList.add('jp-text-truncated');
|
|
77
|
+
super({ node });
|
|
78
|
+
this._title = node;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Set the header title.
|
|
82
|
+
*/
|
|
83
|
+
setTitle(title) {
|
|
84
|
+
this._title.textContent = title;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
Private.Header = Header;
|
|
88
|
+
})(Private || (Private = {}));
|
|
89
|
+
//# sourceMappingURL=panel.js.map
|
package/lib/panel.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"panel.js","sourceRoot":"","sources":["../src/panel.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAInD;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,SAAS;IACjD;;;;OAIG;IACH,YAAY,UAAwB;QAClC,KAAK,CAAC,EAAE,OAAO,EAAE,IAAI,KAAK,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;QAC5C,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QAEnB,IAAI,CAAC,QAAQ,CAAC,oBAAoB,CAAC,CAAC;QAEpC,IAAI,CAAC,MAAM,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,mBAAmB,CAAC,CAAC,CAAC;QACtE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAEnC,IAAI,CAAC,SAAS,GAAG,IAAI,qBAAqB,EAAE,CAAC;QAC7C,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,yBAAyB,CAAC,CAAC;QACnD,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IACD,IAAI,KAAK,CAAC,QAAsC;;QAC9C,IAAI,IAAI,CAAC,MAAM,KAAK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