-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consolidate/simplify component dependencies (#810)
Co-authored-by: cpsievert <[email protected]>
- Loading branch information
Showing
59 changed files
with
1,114 additions
and
1,302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,71 @@ | ||
web_component <- function(tagName, ...) { | ||
js_dep <- component_dependency_js("webComponents", type = "module") | ||
args <- c(list(js_dep), rlang::list2(...)) | ||
tag(tagName, args) | ||
component_dependencies <- function() { | ||
list( | ||
component_dependency_js(), | ||
bs_dependency_defer(component_dependency_sass) | ||
) | ||
} | ||
|
||
component_dependency_js <- function(name, ...) { | ||
component_dependency_js <- function() { | ||
minified <- get_shiny_devmode_option("shiny.minified", default = TRUE) | ||
|
||
htmlDependency( | ||
name = paste0("bslib-", name, "-js"), | ||
name = "bslib-component-js", | ||
version = get_package_version("bslib"), | ||
package = "bslib", | ||
src = file.path("components", "dist", name), | ||
src = "components/dist", | ||
script = list( | ||
src = paste0(name, if (minified) ".min", ".js"), | ||
... | ||
), | ||
all_files = TRUE | ||
list(src = paste0("components", if (minified) ".min", ".js")), | ||
list( | ||
src = paste0("web-components", if (minified) ".min", ".js"), | ||
type = "module" | ||
) | ||
) | ||
) | ||
} | ||
|
||
# Pre-compiled component styles | ||
component_dependency_css <- function(name) { | ||
component_dependency_css <- function() { | ||
htmlDependency( | ||
name = paste0("bslib-", name, "-styles"), | ||
name = "bslib-component-css", | ||
version = get_package_version("bslib"), | ||
package = "bslib", | ||
src = file.path("components", "dist", name), | ||
stylesheet = paste0(name, ".css") | ||
src = "components/dist", | ||
stylesheet = "components.css" | ||
) | ||
} | ||
|
||
# Run-time (Sass) component styles | ||
component_dependency_sass <- function(theme, name) { | ||
component_dependency_sass <- function(theme) { | ||
precompiled <- isTRUE(get_precompiled_option()) | ||
default_theme <- !is_bs_theme(theme) || identical(theme, bs_theme()) | ||
if (precompiled && default_theme) { | ||
component_dependency_css(name) | ||
component_dependency_css() | ||
} else { | ||
component_dependency_sass_(theme, name) | ||
component_dependency_sass_(theme) | ||
} | ||
} | ||
|
||
component_dependency_sass_ <- function(theme, name) { | ||
scss_files <- list( | ||
path_components("scss", "mixins", "_mixins.scss"), | ||
path_components("scss", paste0(name, ".scss")) | ||
component_dependency_sass_ <- function(theme) { | ||
scss_dir <- path_inst("components", "scss") | ||
scss_files <- c( | ||
file.path(scss_dir, "mixins", "_mixins.scss"), | ||
dir(scss_dir, pattern = "\\.scss$", full.names = TRUE) | ||
) | ||
|
||
bs_dependency( | ||
input = lapply(scss_files, sass_file), | ||
# At least currently, when statically rendering a component, | ||
# bs_dependency_defer() passes along a NULL theme. We should | ||
# At least currently, when statically rendering a component, | ||
# bs_dependency_defer() passes along a NULL theme. We should | ||
# eventually fix that, but for now, fall back to the default theme | ||
theme = theme %||% bs_theme(), | ||
name = paste0("bslib-", name, "-styles"), | ||
name = "bslib-component-css", | ||
version = get_package_version("bslib"), | ||
cache_key_extra = get_package_version("bslib"), | ||
.sass_args = list(options = sass_options(output_style = "compressed")) | ||
) | ||
} | ||
|
||
|
||
web_component <- function(tagName, ...) { | ||
htmltools::tag(tagName, rlang::list2(...)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.