Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Voila IFrame renderer #1469

Merged
merged 6 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions packages/jupyterlab-preview/src/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,14 @@ export class VoilaPreview extends DocumentWidget<IFrame, INotebookModel> {
constructor(options: VoilaPreview.IOptions) {
super({
...options,
content: new IFrame({
sandbox: [
'allow-same-origin',
'allow-scripts',
'allow-downloads',
'allow-modals',
'allow-popups'
]
})
content: new IFrame()
});

const iframe = this.content.node.querySelector('iframe');
if (iframe) {
iframe.removeAttribute('sandbox');
}

window.onmessage = (event: any) => {
//console.log("EVENT: ", event);
const level = event?.data?.level;
Expand Down
48 changes: 44 additions & 4 deletions voila/server_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@
from jupyter_server.base.handlers import FileFindHandler, path_regex
from jupyter_server.utils import url_path_join
from jupyterlab_server.themes_handler import ThemesHandler

from jupyter_core.paths import jupyter_config_path
from jupyter_server.serverapp import ServerApp
from .tornado.contentshandler import VoilaContentsHandler

from traitlets.config import (
JSONFileConfigLoader,
PyFileConfigLoader,
Config,
ConfigFileNotFound,
)
from .configuration import VoilaConfiguration
from .tornado.handler import TornadoVoilaHandler
from .paths import ROOT, collect_static_paths, collect_template_paths, jupyter_path
Expand All @@ -38,10 +44,44 @@ def _jupyter_server_extension_points():
return [{"module": "voila.server_extension"}]


def _load_jupyter_server_extension(server_app):
def load_config_file() -> Config:
"""
Loads voila.json and voila.py config file from current working
directory and other Jupyter paths
"""

new_config = Config()
base_file_name = "voila"
config_file_paths = [*jupyter_config_path(), os.getcwd()]

for current in config_file_paths:
py_loader = PyFileConfigLoader(filename=f"{base_file_name}.py", path=current)
try:
py_config = py_loader.load_config()
new_config.merge(py_config)
except ConfigFileNotFound:
pass

json_loader = JSONFileConfigLoader(
filename=f"{base_file_name}.json", path=current
)
try:
json_config = json_loader.load_config()
new_config.merge(json_config)
except ConfigFileNotFound:
pass

return new_config


def _load_jupyter_server_extension(server_app: ServerApp):
web_app = server_app.web_app
# common configuration options between the server extension and the application
voila_configuration = VoilaConfiguration(parent=server_app)

voila_configuration = VoilaConfiguration(
parent=server_app, config=load_config_file()
)

template_name = voila_configuration.template
template_paths = collect_template_paths(["voila", "nbconvert"], template_name)
static_paths = collect_static_paths(["voila", "nbconvert"], template_name)
Expand Down
Loading