Skip to content

Commit

Permalink
Updates from rstudio/bslib#557
Browse files Browse the repository at this point in the history
  • Loading branch information
schloerke committed May 15, 2023
1 parent f596575 commit f8e5a20
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 77 deletions.
45 changes: 5 additions & 40 deletions shiny/experimental/ui/_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from ._card_item import CardItem, WrapperCallable, card_body, wrap_children_in_card
from ._css import CssUnit, validate_css_unit
from ._fill import bind_fill_role
from ._htmldeps import card_dependency
from ._utils import consolidate_attrs


Expand Down Expand Up @@ -90,10 +91,12 @@ def card(
height=validate_css_unit(height),
max_height=validate_css_unit(max_height),
),
"data-bslib-card-init": True,
},
*children,
*attrs,
full_screen_toggle() if full_screen else None,
card_dependency(),
card_js_init(),
)

Expand All @@ -102,44 +105,6 @@ def card(

def card_js_init() -> Tag:
return tags.script(
{"data-bslib-card-needs-init": True},
"""\
var thisScript = document.querySelector('script[data-bslib-card-needs-init]');
if (!thisScript) throw new Error('Failed to register card() resize observer');
thisScript.removeAttribute('data-bslib-card-needs-init');
var card = $(thisScript).parents('.card').last();
if (!card) throw new Error('Failed to register card() resize observer');
// Let Shiny know to trigger resize when the card size changes
// TODO: shiny could/should do this itself (rstudio/shiny#3682)
var resizeEvent = window.document.createEvent('UIEvents');
resizeEvent.initUIEvent('resize', true, false, window, 0);
var ro = new ResizeObserver(() => { window.dispatchEvent(resizeEvent); });
ro.observe(card[0]);
// Enable tooltips (for the expand icon)
var tooltipList = card[0].querySelectorAll('[data-bs-toggle=\"tooltip\"]');
tooltipList.forEach(function(x) { new bootstrap.Tooltip(x); });
// In some complex fill-based layouts with multiple outputs (e.g., plotly),
// shiny initializes with the correct sizing, but in-between the 1st and last
// renderValue(), the size of the output containers can change, meaning every
// output but the 1st gets initialized with the wrong size during their
// renderValue(); and then after the render phase, shiny won't know trigger a
// resize since all the widgets will return to their original size
// (and thus, Shiny thinks there isn't any resizing to do).
// We workaround that situation by manually triggering a resize on the binding
// when the output container changes (this way, if the size is different during
// the render phase, Shiny will know about it)
$(document).on('shiny:value', function(x) {
var el = x.binding.el;
if (card[0].contains(el) && !$(el).data('bslib-output-observer')) {
var roo = new ResizeObserver(x.binding.onResize);
roo.observe(el);
$(el).data('bslib-output-observer', true);
}
});
""",
{"data-bslib-card-init": True},
"window.bslib.Card.initializeAllCards();",
)
3 changes: 0 additions & 3 deletions shiny/experimental/ui/_card_full_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from htmltools import HTML, Tag, tags

from ._htmldeps import card_full_screen_dependency


def full_screen_toggle() -> Tag:
return tags.span(
Expand All @@ -14,7 +12,6 @@ def full_screen_toggle() -> Tag:
"title": "Expand",
},
full_screen_toggle_icon(),
card_full_screen_dependency(),
)


Expand Down
6 changes: 3 additions & 3 deletions shiny/experimental/ui/_htmldeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
x_fill_path = x_www / "htmltools" / "fill"


def card_full_screen_dependency() -> HTMLDependency:
def card_dependency() -> HTMLDependency:
return HTMLDependency(
name="shiny-card-full-screen",
name="bslib-card",
version=bslib_version,
source={
"package": "shiny",
"subdir": str(x_components_path),
},
script={"src": "card-full-screen.js"},
script={"src": "card.min.js"},
)


Expand Down
2 changes: 1 addition & 1 deletion shiny/experimental/www/bslib/components/_versions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"note!": "This file is auto-generated by scripts/htmlDependencies.R",
"package": "bslib",
"version": "Github (rstudio/bslib@4a2276d3c9502e814d5f245967afa1e8dd3367f1)"
"version": "Github (rstudio/bslib@d3c3ad3203c5b6d7ff5d2e75018a4f90d97d3b3a)"
}
2 changes: 1 addition & 1 deletion shiny/experimental/www/bslib/components/accordion.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

23 changes: 0 additions & 23 deletions shiny/experimental/www/bslib/components/card-full-screen.js

This file was deleted.

3 changes: 3 additions & 0 deletions shiny/experimental/www/bslib/components/card.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions shiny/experimental/www/bslib/components/card.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion shiny/experimental/www/bslib/components/sidebar.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion shiny/experimental/www/htmltools/fill/_versions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"note!": "This file is auto-generated by scripts/htmlDependencies.R",
"package": "htmltools",
"version": "Github (rstudio/htmltools@eaaf3afd80882608826e82592b8963412fa90f88)"
"version": "Github (rstudio/htmltools@73fd307d5603f5eb9d2fe3be820335b7db0cf5bb)"
}
4 changes: 2 additions & 2 deletions shiny/www/shared/bootstrap/_version.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"note!": "This file is auto-generated by scripts/htmlDependencies.R",
"shiny_version": "Github (rstudio/shiny@62bb21d5b6eb34a5701f849c78a04ff5efd5b46d)",
"bslib_version": "Github (rstudio/bslib@4a2276d3c9502e814d5f245967afa1e8dd3367f1)",
"htmltools_version": "Github (rstudio/htmltools@eaaf3afd80882608826e82592b8963412fa90f88)",
"bslib_version": "Github (rstudio/bslib@d3c3ad3203c5b6d7ff5d2e75018a4f90d97d3b3a)",
"htmltools_version": "Github (rstudio/htmltools@73fd307d5603f5eb9d2fe3be820335b7db0cf5bb)",
"bootstrap_version": "5.2.2"
}
2 changes: 1 addition & 1 deletion shiny/www/shared/bootstrap/bootstrap.min.css

Large diffs are not rendered by default.

0 comments on commit f8e5a20

Please sign in to comment.