@@ -11,8 +11,6 @@ import {
11
11
WidgetTracker
12
12
} from '@jupyterlab/apputils' ;
13
13
14
- import { PageConfig , URLExt } from '@jupyterlab/coreutils' ;
15
-
16
14
import { DocumentRegistry } from '@jupyterlab/docregistry' ;
17
15
18
16
import {
@@ -24,21 +22,19 @@ import {
24
22
25
23
import { ISettingRegistry } from '@jupyterlab/settingregistry' ;
26
24
27
- import { ITranslator } from '@jupyterlab/translation' ;
25
+ import { ITranslator , nullTranslator } from '@jupyterlab/translation' ;
28
26
29
27
import { toArray } from '@lumino/algorithm' ;
30
28
31
29
import { ReadonlyPartialJSONObject } from '@lumino/coreutils' ;
32
30
33
31
import { fullScreenIcon , RISEIcon } from './icons' ;
34
32
35
- import {
36
- RisePreview ,
37
- IRisePreviewTracker ,
38
- RisePreviewFactory
39
- } from './preview' ;
33
+ import { RisePreview } from './preview' ;
40
34
41
- export { IRisePreviewTracker } from './preview' ;
35
+ import { IRisePreviewFactory , IRisePreviewTracker } from './tokens' ;
36
+
37
+ export { IRisePreviewFactory , IRisePreviewTracker } from './tokens' ;
42
38
43
39
/**
44
40
* Command IDs namespace for JupyterLab RISE extension
@@ -59,27 +55,46 @@ namespace CommandIDs {
59
55
export const riseSetSlideType = 'RISE:set-slide-type' ;
60
56
}
61
57
58
+ const factory : JupyterFrontEndPlugin < IRisePreviewFactory > = {
59
+ id : 'jupyterlab-rise:factory' ,
60
+ provides : IRisePreviewFactory ,
61
+ optional : [ ITranslator ] ,
62
+ activate : (
63
+ app : JupyterFrontEnd ,
64
+ translator : ITranslator | null
65
+ ) : IRisePreviewFactory => {
66
+ const { commands, docRegistry } = app ;
67
+ return new RisePreview . FactoryToken ( {
68
+ commands,
69
+ docRegistry,
70
+ translator : translator ?? undefined
71
+ } ) ;
72
+ }
73
+ } ;
74
+
62
75
/**
63
76
* Open the notebook with RISE.
64
77
*/
65
78
const plugin : JupyterFrontEndPlugin < IRisePreviewTracker > = {
66
79
id : 'jupyterlab-rise:plugin' ,
67
80
autoStart : true ,
68
- requires : [ ITranslator ] ,
81
+ requires : [ IRisePreviewFactory ] ,
69
82
optional : [
70
83
INotebookTracker ,
71
84
ICommandPalette ,
72
85
ILayoutRestorer ,
73
- ISettingRegistry
86
+ ISettingRegistry ,
87
+ ITranslator
74
88
] ,
75
89
provides : IRisePreviewTracker ,
76
90
activate : (
77
91
app : JupyterFrontEnd ,
78
- translator : ITranslator ,
92
+ factory : IRisePreviewFactory ,
79
93
notebookTracker : INotebookTracker | null ,
80
94
palette : ICommandPalette | null ,
81
95
restorer : ILayoutRestorer | null ,
82
- settingRegistry : ISettingRegistry | null
96
+ settingRegistry : ISettingRegistry | null ,
97
+ translator : ITranslator | null
83
98
) : IRisePreviewTracker => {
84
99
console . log ( 'JupyterLab extension jupyterlab-rise is activated!' ) ;
85
100
@@ -92,8 +107,8 @@ const plugin: JupyterFrontEndPlugin<IRisePreviewTracker> = {
92
107
return tracker ;
93
108
}
94
109
95
- const { commands, docRegistry , shell } = app ;
96
- const trans = translator . load ( 'rise' ) ;
110
+ const { commands, shell } = app ;
111
+ const trans = ( translator ?? nullTranslator ) . load ( 'rise' ) ;
97
112
98
113
let settings : ISettingRegistry . ISettings | null = null ;
99
114
if ( settingRegistry ) {
@@ -102,27 +117,19 @@ const plugin: JupyterFrontEndPlugin<IRisePreviewTracker> = {
102
117
} ) ;
103
118
}
104
119
105
- const factory = new RisePreviewFactory ( getRiseUrl , commands , {
106
- name : 'rise' ,
107
- fileTypes : [ 'notebook' ] ,
108
- modelName : 'notebook'
109
- } ) ;
110
-
111
120
if ( restorer ) {
112
121
restorer . restore ( tracker , {
113
122
// Need to modify to handle auto full screen
114
123
command : 'docmanager:open' ,
115
124
args : panel => ( {
116
125
path : panel . context . path ,
117
- factory : factory . name
126
+ factory : RisePreview . FACTORY_NAME
118
127
} ) ,
119
128
name : panel => panel . context . path ,
120
129
when : app . serviceManager . ready
121
130
} ) ;
122
131
}
123
132
124
- docRegistry . addWidgetFactory ( factory ) ;
125
-
126
133
function getCurrent ( args : ReadonlyPartialJSONObject ) : NotebookPanel | null {
127
134
const widget = notebookTracker ?. currentWidget ?? null ;
128
135
const activate = args [ 'activate' ] !== false ;
@@ -141,15 +148,6 @@ const plugin: JupyterFrontEndPlugin<IRisePreviewTracker> = {
141
148
) ;
142
149
}
143
150
144
- function getRiseUrl ( path : string , activeCellIndex ?: number ) : string {
145
- const baseUrl = PageConfig . getBaseUrl ( ) ;
146
- let url = `${ baseUrl } rise/${ path } ` ;
147
- if ( typeof activeCellIndex === 'number' ) {
148
- url += URLExt . objectToQueryString ( { activeCellIndex } ) ;
149
- }
150
- return url ;
151
- }
152
-
153
151
factory . widgetCreated . connect ( ( sender , widget ) => {
154
152
// Notify the widget tracker if restore data needs to update.
155
153
widget . context . pathChanged . connect ( ( ) => {
@@ -175,7 +173,10 @@ const plugin: JupyterFrontEndPlugin<IRisePreviewTracker> = {
175
173
}
176
174
await current . context . save ( ) ;
177
175
window . open (
178
- getRiseUrl ( current . context . path , current . content . activeCellIndex )
176
+ RisePreview . getRiseUrl (
177
+ current . context . path ,
178
+ current . content . activeCellIndex
179
+ )
179
180
) ;
180
181
} ,
181
182
isEnabled
@@ -197,7 +198,7 @@ const plugin: JupyterFrontEndPlugin<IRisePreviewTracker> = {
197
198
'docmanager:open' ,
198
199
{
199
200
path : context . path ,
200
- factory : 'rise' ,
201
+ factory : RisePreview . FACTORY_NAME ,
201
202
options : {
202
203
mode : 'split-right'
203
204
}
@@ -378,4 +379,4 @@ const plugin: JupyterFrontEndPlugin<IRisePreviewTracker> = {
378
379
}
379
380
} ;
380
381
381
- export default plugin ;
382
+ export default [ factory , plugin ] ;
0 commit comments