forked from posit-dev/py-shiny
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First pass at integration. Still more work to do
- Loading branch information
Showing
10 changed files
with
337 additions
and
291 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING, Any, cast, overload | ||
|
||
from htmltools import HTML, MetadataNode, Tagifiable, TagNode | ||
|
||
from ..._typing_extensions import TypeGuard | ||
from ...types import Jsonifiable | ||
from ._types import CellHtml, ReprHtml, SeriesLike | ||
|
||
if TYPE_CHECKING: | ||
from ...session import Session | ||
|
||
|
||
@overload | ||
def wrap_shiny_html( # pyright: ignore[reportOverlappingOverload] | ||
x: TagNode, *, session: Session | ||
) -> CellHtml: ... | ||
@overload | ||
def wrap_shiny_html(x: Jsonifiable, *, session: Session) -> Jsonifiable: ... | ||
def wrap_shiny_html( | ||
x: Jsonifiable | TagNode, *, session: Session | ||
) -> Jsonifiable | CellHtml: | ||
if is_shiny_html(x): | ||
return {"isShinyHtml": True, "obj": session._process_ui(x)} | ||
return cast(Jsonifiable, x) | ||
|
||
|
||
def col_contains_shiny_html(col: SeriesLike) -> bool: | ||
return any(is_shiny_html(val) for _, val in enumerate(col)) | ||
|
||
|
||
# TODO-barret-test; Add test to assert the union type of `TagNode` contains `str` and (HTML | Tagifiable | MetadataNode | ReprHtml). Until a `is tag renderable` method is available in htmltools, we need to check for these types manually and must stay in sync with the `TagNode` union type. | ||
# TODO-barret-future; Use `TypeIs[HTML | Tagifiable | MetadataNode | ReprHtml]` when it is available from typing_extensions | ||
def is_shiny_html(val: Any) -> TypeGuard[HTML | Tagifiable | MetadataNode | ReprHtml]: | ||
return isinstance(val, (HTML, Tagifiable, MetadataNode, ReprHtml)) |
Oops, something went wrong.