Skip to content

Commit f8e5a20

Browse files
committed
Updates from rstudio/bslib#557
1 parent f596575 commit f8e5a20

File tree

13 files changed

+26
-77
lines changed

13 files changed

+26
-77
lines changed

shiny/experimental/ui/_card.py

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from ._card_item import CardItem, WrapperCallable, card_body, wrap_children_in_card
1111
from ._css import CssUnit, validate_css_unit
1212
from ._fill import bind_fill_role
13+
from ._htmldeps import card_dependency
1314
from ._utils import consolidate_attrs
1415

1516

@@ -90,10 +91,12 @@ def card(
9091
height=validate_css_unit(height),
9192
max_height=validate_css_unit(max_height),
9293
),
94+
"data-bslib-card-init": True,
9395
},
9496
*children,
9597
*attrs,
9698
full_screen_toggle() if full_screen else None,
99+
card_dependency(),
97100
card_js_init(),
98101
)
99102

@@ -102,44 +105,6 @@ def card(
102105

103106
def card_js_init() -> Tag:
104107
return tags.script(
105-
{"data-bslib-card-needs-init": True},
106-
"""\
107-
var thisScript = document.querySelector('script[data-bslib-card-needs-init]');
108-
if (!thisScript) throw new Error('Failed to register card() resize observer');
109-
110-
thisScript.removeAttribute('data-bslib-card-needs-init');
111-
112-
var card = $(thisScript).parents('.card').last();
113-
if (!card) throw new Error('Failed to register card() resize observer');
114-
115-
// Let Shiny know to trigger resize when the card size changes
116-
// TODO: shiny could/should do this itself (rstudio/shiny#3682)
117-
var resizeEvent = window.document.createEvent('UIEvents');
118-
resizeEvent.initUIEvent('resize', true, false, window, 0);
119-
var ro = new ResizeObserver(() => { window.dispatchEvent(resizeEvent); });
120-
ro.observe(card[0]);
121-
122-
// Enable tooltips (for the expand icon)
123-
var tooltipList = card[0].querySelectorAll('[data-bs-toggle=\"tooltip\"]');
124-
tooltipList.forEach(function(x) { new bootstrap.Tooltip(x); });
125-
126-
// In some complex fill-based layouts with multiple outputs (e.g., plotly),
127-
// shiny initializes with the correct sizing, but in-between the 1st and last
128-
// renderValue(), the size of the output containers can change, meaning every
129-
// output but the 1st gets initialized with the wrong size during their
130-
// renderValue(); and then after the render phase, shiny won't know trigger a
131-
// resize since all the widgets will return to their original size
132-
// (and thus, Shiny thinks there isn't any resizing to do).
133-
// We workaround that situation by manually triggering a resize on the binding
134-
// when the output container changes (this way, if the size is different during
135-
// the render phase, Shiny will know about it)
136-
$(document).on('shiny:value', function(x) {
137-
var el = x.binding.el;
138-
if (card[0].contains(el) && !$(el).data('bslib-output-observer')) {
139-
var roo = new ResizeObserver(x.binding.onResize);
140-
roo.observe(el);
141-
$(el).data('bslib-output-observer', true);
142-
}
143-
});
144-
""",
108+
{"data-bslib-card-init": True},
109+
"window.bslib.Card.initializeAllCards();",
145110
)

shiny/experimental/ui/_card_full_screen.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from htmltools import HTML, Tag, tags
44

5-
from ._htmldeps import card_full_screen_dependency
6-
75

86
def full_screen_toggle() -> Tag:
97
return tags.span(
@@ -14,7 +12,6 @@ def full_screen_toggle() -> Tag:
1412
"title": "Expand",
1513
},
1614
full_screen_toggle_icon(),
17-
card_full_screen_dependency(),
1815
)
1916

2017

shiny/experimental/ui/_htmldeps.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
x_fill_path = x_www / "htmltools" / "fill"
1313

1414

15-
def card_full_screen_dependency() -> HTMLDependency:
15+
def card_dependency() -> HTMLDependency:
1616
return HTMLDependency(
17-
name="shiny-card-full-screen",
17+
name="bslib-card",
1818
version=bslib_version,
1919
source={
2020
"package": "shiny",
2121
"subdir": str(x_components_path),
2222
},
23-
script={"src": "card-full-screen.js"},
23+
script={"src": "card.min.js"},
2424
)
2525

2626

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"note!": "This file is auto-generated by scripts/htmlDependencies.R",
33
"package": "bslib",
4-
"version": "Github (rstudio/bslib@4a2276d3c9502e814d5f245967afa1e8dd3367f1)"
4+
"version": "Github (rstudio/bslib@d3c3ad3203c5b6d7ff5d2e75018a4f90d97d3b3a)"
55
}

shiny/experimental/www/bslib/components/accordion.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shiny/experimental/www/bslib/components/accordion.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shiny/experimental/www/bslib/components/card-full-screen.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

shiny/experimental/www/bslib/components/card.min.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shiny/experimental/www/bslib/components/card.min.js.map

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shiny/experimental/www/bslib/components/sidebar.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"note!": "This file is auto-generated by scripts/htmlDependencies.R",
33
"package": "htmltools",
4-
"version": "Github (rstudio/htmltools@eaaf3afd80882608826e82592b8963412fa90f88)"
4+
"version": "Github (rstudio/htmltools@73fd307d5603f5eb9d2fe3be820335b7db0cf5bb)"
55
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"note!": "This file is auto-generated by scripts/htmlDependencies.R",
33
"shiny_version": "Github (rstudio/shiny@62bb21d5b6eb34a5701f849c78a04ff5efd5b46d)",
4-
"bslib_version": "Github (rstudio/bslib@4a2276d3c9502e814d5f245967afa1e8dd3367f1)",
5-
"htmltools_version": "Github (rstudio/htmltools@eaaf3afd80882608826e82592b8963412fa90f88)",
4+
"bslib_version": "Github (rstudio/bslib@d3c3ad3203c5b6d7ff5d2e75018a4f90d97d3b3a)",
5+
"htmltools_version": "Github (rstudio/htmltools@73fd307d5603f5eb9d2fe3be820335b7db0cf5bb)",
66
"bootstrap_version": "5.2.2"
77
}

shiny/www/shared/bootstrap/bootstrap.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)