@jupyterlab/htmlviewer 4.0.4 → 4.1.0-alpha.1
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/widget.d.ts +1 -1
- package/lib/widget.js +44 -6
- package/lib/widget.js.map +1 -1
- package/package.json +9 -9
- package/src/widget.tsx +49 -6
package/lib/widget.d.ts
CHANGED
|
@@ -47,7 +47,7 @@ export declare class HTMLViewer extends DocumentWidget<IFrame> implements IDocum
|
|
|
47
47
|
* Set a <base> element in the HTML string so that the iframe
|
|
48
48
|
* can correctly dereference relative links.
|
|
49
49
|
*/
|
|
50
|
-
private
|
|
50
|
+
private _setupDocument;
|
|
51
51
|
protected translator: ITranslator;
|
|
52
52
|
private _renderPending;
|
|
53
53
|
private _parser;
|
package/lib/widget.js
CHANGED
|
@@ -16,6 +16,35 @@ const RENDER_TIMEOUT = 1000;
|
|
|
16
16
|
* The CSS class to add to the HTMLViewer Widget.
|
|
17
17
|
*/
|
|
18
18
|
const CSS_CLASS = 'jp-HTMLViewer';
|
|
19
|
+
const UNTRUSTED_LINK_STYLE = (options) => `<style>
|
|
20
|
+
a[target="_blank"],
|
|
21
|
+
area[target="_blank"],
|
|
22
|
+
form[target="_blank"],
|
|
23
|
+
button[formtarget="_blank"],
|
|
24
|
+
input[formtarget="_blank"][type="image"],
|
|
25
|
+
input[formtarget="_blank"][type="submit"] {
|
|
26
|
+
cursor: not-allowed !important;
|
|
27
|
+
}
|
|
28
|
+
a[target="_blank"]:hover::after,
|
|
29
|
+
area[target="_blank"]:hover::after,
|
|
30
|
+
form[target="_blank"]:hover::after,
|
|
31
|
+
button[formtarget="_blank"]:hover::after,
|
|
32
|
+
input[formtarget="_blank"][type="image"]:hover::after,
|
|
33
|
+
input[formtarget="_blank"][type="submit"]:hover::after {
|
|
34
|
+
content: "${options.warning}";
|
|
35
|
+
box-sizing: border-box;
|
|
36
|
+
position: fixed;
|
|
37
|
+
top: 0;
|
|
38
|
+
left: 0;
|
|
39
|
+
width: 100%;
|
|
40
|
+
z-index: 1000;
|
|
41
|
+
border: 2px solid #e65100;
|
|
42
|
+
background-color: #ffb74d;
|
|
43
|
+
color: black;
|
|
44
|
+
font-family: system-ui, -apple-system, blinkmacsystemfont, 'Segoe UI', helvetica, arial, sans-serif;
|
|
45
|
+
text-align: center;
|
|
46
|
+
}
|
|
47
|
+
</style>`;
|
|
19
48
|
/**
|
|
20
49
|
* A viewer widget for HTML documents.
|
|
21
50
|
*
|
|
@@ -72,8 +101,7 @@ export class HTMLViewer extends DocumentWidget {
|
|
|
72
101
|
else {
|
|
73
102
|
this.content.sandbox = Private.untrusted;
|
|
74
103
|
}
|
|
75
|
-
//
|
|
76
|
-
this.content.url = this.content.url; // Force a refresh.
|
|
104
|
+
this.update(); // Force a refresh.
|
|
77
105
|
this._trustedChanged.emit(value);
|
|
78
106
|
}
|
|
79
107
|
/**
|
|
@@ -111,7 +139,7 @@ export class HTMLViewer extends DocumentWidget {
|
|
|
111
139
|
*/
|
|
112
140
|
async _renderModel() {
|
|
113
141
|
let data = this.context.model.toString();
|
|
114
|
-
data = await this.
|
|
142
|
+
data = await this._setupDocument(data);
|
|
115
143
|
// Set the new iframe url.
|
|
116
144
|
const blob = new Blob([data], { type: 'text/html' });
|
|
117
145
|
const oldUrl = this._objectUrl;
|
|
@@ -132,7 +160,7 @@ export class HTMLViewer extends DocumentWidget {
|
|
|
132
160
|
* Set a <base> element in the HTML string so that the iframe
|
|
133
161
|
* can correctly dereference relative links.
|
|
134
162
|
*/
|
|
135
|
-
async
|
|
163
|
+
async _setupDocument(data) {
|
|
136
164
|
const doc = this._parser.parseFromString(data, 'text/html');
|
|
137
165
|
let base = doc.querySelector('base');
|
|
138
166
|
if (!base) {
|
|
@@ -147,6 +175,13 @@ export class HTMLViewer extends DocumentWidget {
|
|
|
147
175
|
// (e.g. CSS and scripts).
|
|
148
176
|
base.href = baseUrl;
|
|
149
177
|
base.target = '_self';
|
|
178
|
+
// Inject dynamic style for links if the document is not trusted
|
|
179
|
+
if (!this.trusted) {
|
|
180
|
+
const warning = this.translator
|
|
181
|
+
.load('jupyterlab')
|
|
182
|
+
.__('Action disabled as the file is not trusted.');
|
|
183
|
+
doc.body.insertAdjacentHTML('beforeend', UNTRUSTED_LINK_STYLE({ warning }));
|
|
184
|
+
}
|
|
150
185
|
return doc.documentElement.innerHTML;
|
|
151
186
|
}
|
|
152
187
|
}
|
|
@@ -228,7 +263,10 @@ var Private;
|
|
|
228
263
|
/**
|
|
229
264
|
* Sandbox exceptions for trusted HTML.
|
|
230
265
|
*/
|
|
231
|
-
Private.trusted = [
|
|
266
|
+
Private.trusted = [
|
|
267
|
+
'allow-scripts',
|
|
268
|
+
'allow-popups'
|
|
269
|
+
];
|
|
232
270
|
/**
|
|
233
271
|
* React component for a trusted button.
|
|
234
272
|
*
|
|
@@ -238,7 +276,7 @@ var Private;
|
|
|
238
276
|
const translator = props.translator || nullTranslator;
|
|
239
277
|
const trans = translator.load('jupyterlab');
|
|
240
278
|
return (React.createElement(UseSignal, { signal: props.htmlDocument.trustedChanged, initialSender: props.htmlDocument }, () => (React.createElement(ToolbarButtonComponent, { className: "", onClick: () => (props.htmlDocument.trusted = !props.htmlDocument.trusted), tooltip: trans.__(`Whether the HTML file is trusted.
|
|
241
|
-
Trusting the file allows
|
|
279
|
+
Trusting the file allows opening pop-ups and running scripts
|
|
242
280
|
which may result in security risks.
|
|
243
281
|
Only enable for files you trust.`), label: props.htmlDocument.trusted
|
|
244
282
|
? trans.__('Distrust HTML')
|
package/lib/widget.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widget.js","sourceRoot":"","sources":["../src/widget.tsx"],"names":[],"mappings":"AAAA;;;+EAG+E;AAE/E,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EACL,gBAAgB,EAEhB,cAAc,EAEf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAe,cAAc,EAAE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kEhB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyterlab/htmlviewer",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.1.0-alpha.1",
|
|
4
4
|
"description": "A viewer for HTML documents.",
|
|
5
5
|
"homepage": "https://github.com/jupyterlab/jupyterlab",
|
|
6
6
|
"bugs": {
|
|
@@ -33,14 +33,14 @@
|
|
|
33
33
|
"watch": "tsc -w --listEmittedFiles"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@jupyterlab/apputils": "^4.1
|
|
37
|
-
"@jupyterlab/coreutils": "^6.0.
|
|
38
|
-
"@jupyterlab/docregistry": "^4.0.
|
|
39
|
-
"@jupyterlab/translation": "^4.0.
|
|
40
|
-
"@jupyterlab/ui-components": "^4.0.
|
|
41
|
-
"@lumino/coreutils": "^2.1.
|
|
42
|
-
"@lumino/signaling": "^2.1.
|
|
43
|
-
"@lumino/widgets": "^2.
|
|
36
|
+
"@jupyterlab/apputils": "^4.2.0-alpha.1",
|
|
37
|
+
"@jupyterlab/coreutils": "^6.1.0-alpha.1",
|
|
38
|
+
"@jupyterlab/docregistry": "^4.1.0-alpha.1",
|
|
39
|
+
"@jupyterlab/translation": "^4.1.0-alpha.1",
|
|
40
|
+
"@jupyterlab/ui-components": "^4.1.0-alpha.1",
|
|
41
|
+
"@lumino/coreutils": "^2.1.2",
|
|
42
|
+
"@lumino/signaling": "^2.1.2",
|
|
43
|
+
"@lumino/widgets": "^2.3.0",
|
|
44
44
|
"react": "^18.2.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
package/src/widget.tsx
CHANGED
|
@@ -33,6 +33,36 @@ const RENDER_TIMEOUT = 1000;
|
|
|
33
33
|
*/
|
|
34
34
|
const CSS_CLASS = 'jp-HTMLViewer';
|
|
35
35
|
|
|
36
|
+
const UNTRUSTED_LINK_STYLE = (options: { warning: string }) => `<style>
|
|
37
|
+
a[target="_blank"],
|
|
38
|
+
area[target="_blank"],
|
|
39
|
+
form[target="_blank"],
|
|
40
|
+
button[formtarget="_blank"],
|
|
41
|
+
input[formtarget="_blank"][type="image"],
|
|
42
|
+
input[formtarget="_blank"][type="submit"] {
|
|
43
|
+
cursor: not-allowed !important;
|
|
44
|
+
}
|
|
45
|
+
a[target="_blank"]:hover::after,
|
|
46
|
+
area[target="_blank"]:hover::after,
|
|
47
|
+
form[target="_blank"]:hover::after,
|
|
48
|
+
button[formtarget="_blank"]:hover::after,
|
|
49
|
+
input[formtarget="_blank"][type="image"]:hover::after,
|
|
50
|
+
input[formtarget="_blank"][type="submit"]:hover::after {
|
|
51
|
+
content: "${options.warning}";
|
|
52
|
+
box-sizing: border-box;
|
|
53
|
+
position: fixed;
|
|
54
|
+
top: 0;
|
|
55
|
+
left: 0;
|
|
56
|
+
width: 100%;
|
|
57
|
+
z-index: 1000;
|
|
58
|
+
border: 2px solid #e65100;
|
|
59
|
+
background-color: #ffb74d;
|
|
60
|
+
color: black;
|
|
61
|
+
font-family: system-ui, -apple-system, blinkmacsystemfont, 'Segoe UI', helvetica, arial, sans-serif;
|
|
62
|
+
text-align: center;
|
|
63
|
+
}
|
|
64
|
+
</style>`;
|
|
65
|
+
|
|
36
66
|
/**
|
|
37
67
|
* A viewer widget for HTML documents.
|
|
38
68
|
*
|
|
@@ -88,8 +118,7 @@ export class HTMLViewer
|
|
|
88
118
|
} else {
|
|
89
119
|
this.content.sandbox = Private.untrusted;
|
|
90
120
|
}
|
|
91
|
-
//
|
|
92
|
-
this.content.url = this.content.url; // Force a refresh.
|
|
121
|
+
this.update(); // Force a refresh.
|
|
93
122
|
this._trustedChanged.emit(value);
|
|
94
123
|
}
|
|
95
124
|
|
|
@@ -130,7 +159,7 @@ export class HTMLViewer
|
|
|
130
159
|
*/
|
|
131
160
|
private async _renderModel(): Promise<void> {
|
|
132
161
|
let data = this.context.model.toString();
|
|
133
|
-
data = await this.
|
|
162
|
+
data = await this._setupDocument(data);
|
|
134
163
|
|
|
135
164
|
// Set the new iframe url.
|
|
136
165
|
const blob = new Blob([data], { type: 'text/html' });
|
|
@@ -153,7 +182,7 @@ export class HTMLViewer
|
|
|
153
182
|
* Set a <base> element in the HTML string so that the iframe
|
|
154
183
|
* can correctly dereference relative links.
|
|
155
184
|
*/
|
|
156
|
-
private async
|
|
185
|
+
private async _setupDocument(data: string): Promise<string> {
|
|
157
186
|
const doc = this._parser.parseFromString(data, 'text/html');
|
|
158
187
|
let base = doc.querySelector('base');
|
|
159
188
|
if (!base) {
|
|
@@ -169,6 +198,17 @@ export class HTMLViewer
|
|
|
169
198
|
// (e.g. CSS and scripts).
|
|
170
199
|
base.href = baseUrl;
|
|
171
200
|
base.target = '_self';
|
|
201
|
+
|
|
202
|
+
// Inject dynamic style for links if the document is not trusted
|
|
203
|
+
if (!this.trusted) {
|
|
204
|
+
const warning = this.translator
|
|
205
|
+
.load('jupyterlab')
|
|
206
|
+
.__('Action disabled as the file is not trusted.');
|
|
207
|
+
doc.body.insertAdjacentHTML(
|
|
208
|
+
'beforeend',
|
|
209
|
+
UNTRUSTED_LINK_STYLE({ warning })
|
|
210
|
+
);
|
|
211
|
+
}
|
|
172
212
|
return doc.documentElement.innerHTML;
|
|
173
213
|
}
|
|
174
214
|
|
|
@@ -272,7 +312,10 @@ namespace Private {
|
|
|
272
312
|
/**
|
|
273
313
|
* Sandbox exceptions for trusted HTML.
|
|
274
314
|
*/
|
|
275
|
-
export const trusted: IFrame.SandboxExceptions[] = [
|
|
315
|
+
export const trusted: IFrame.SandboxExceptions[] = [
|
|
316
|
+
'allow-scripts',
|
|
317
|
+
'allow-popups'
|
|
318
|
+
];
|
|
276
319
|
|
|
277
320
|
/**
|
|
278
321
|
* Namespace for TrustedButton.
|
|
@@ -313,7 +356,7 @@ namespace Private {
|
|
|
313
356
|
(props.htmlDocument.trusted = !props.htmlDocument.trusted)
|
|
314
357
|
}
|
|
315
358
|
tooltip={trans.__(`Whether the HTML file is trusted.
|
|
316
|
-
Trusting the file allows
|
|
359
|
+
Trusting the file allows opening pop-ups and running scripts
|
|
317
360
|
which may result in security risks.
|
|
318
361
|
Only enable for files you trust.`)}
|
|
319
362
|
label={
|