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

Allow bundling and loading JS and CSS for ReactiveHTML components #2373

Merged
merged 1 commit into from
Jun 11, 2021
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
8 changes: 7 additions & 1 deletion panel/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def write_bundled_tarball(name, tarball, bundle_dir, module=False):

def bundle_resources():
from .config import panel_extension
from .reactive import ReactiveHTML
from .template.base import BasicTemplate
from .template.theme import Theme

Expand All @@ -150,7 +151,12 @@ def bundle_resources():
# Extract Model dependencies
js_files = {}
css_files = {}
for name, model in Model.model_class_reverse_map.items():
reactive = param.concrete_descendents(ReactiveHTML).values()
models = (
list(Model.model_class_reverse_map.items()) +
[(f'{m.__module__}.{m.__name__}', m) for m in reactive]
)
for name, model in models:
if not name.startswith('panel.'):
continue
prev_jsfiles = getattr(model, '__javascript_raw__', None)
Expand Down
15 changes: 15 additions & 0 deletions panel/io/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from collections import OrderedDict
from pathlib import Path

import param

from bokeh.embed.bundle import (
Bundle as BkBundle, _bundle_extensions, extension_dirs,
bundle_models
Expand Down Expand Up @@ -159,7 +161,14 @@ def css_raw(self):
@property
def js_files(self):
from ..config import config
from ..reactive import ReactiveHTML

files = super(Resources, self).js_files

for model in param.concrete_descendents(ReactiveHTML).values():
if hasattr(model, '__javascript__'):
files += model.__javascript__

js_files = []
for js_file in files:
if (js_file.startswith(state.base_url) or js_file.startswith('static/')):
Expand Down Expand Up @@ -196,8 +205,14 @@ def js_modules(self):
@property
def css_files(self):
from ..config import config
from ..reactive import ReactiveHTML

files = super(Resources, self).css_files

for model in param.concrete_descendents(ReactiveHTML).values():
if hasattr(model, '__css__'):
files += model.__css__

for cssf in config.css_files:
if os.path.isfile(cssf) or cssf in files:
continue
Expand Down