-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
639 additions
and
806 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
__all__ = ( | ||
"nav_append", | ||
"nav_prepend", | ||
"nav_insert", | ||
"nav_remove", | ||
"nav_hide", | ||
"nav_show", | ||
) | ||
|
||
import sys | ||
from typing import Optional | ||
|
||
if sys.version_info >= (3, 8): | ||
from typing import Literal | ||
else: | ||
from typing_extensions import Literal | ||
|
||
from htmltools import JSXTag | ||
|
||
from ._input_update import update_navs | ||
from ._navs import navs_hidden | ||
from ..session import Session, require_active_session | ||
from .._utils import run_coro_sync | ||
|
||
|
||
def nav_append( | ||
id: str, | ||
nav: JSXTag, | ||
menu_title: Optional[str] = None, | ||
select: bool = False, | ||
session: Optional[Session] = None, | ||
) -> None: | ||
|
||
session = require_active_session(session) | ||
# TODO: do we need to namespace the id? | ||
# id = session.ns(id) | ||
|
||
# The currrent JSX implementation of nav items is not smart enough to | ||
# to render without a navs container (maybe it could?), so we need to | ||
# wrap in one and also notify the JSX logic to not select the nav | ||
# (shiny.js handles that part via the select parameter). | ||
jsx_tag = navs_hidden(nav, selected=False) | ||
|
||
msg = { | ||
"inputId": id, | ||
"menuName": menu_title, | ||
"target": None, | ||
"position": "after", | ||
"select": select, | ||
"jsxTag": session.process_ui(jsx_tag), | ||
} | ||
|
||
def callback() -> None: | ||
run_coro_sync(session.send_message({"shiny-insert-tab": msg})) | ||
|
||
session.on_flush(callback, once=True) | ||
|
||
|
||
def nav_prepend( | ||
id: str, | ||
nav: JSXTag, | ||
menu_title: Optional[str] = None, | ||
select: bool = False, | ||
session: Optional[Session] = None, | ||
) -> None: | ||
|
||
session = require_active_session(session) | ||
# TODO: do we need to namespace the id? | ||
# id = session.ns(id) | ||
|
||
# The currrent JSX implementation of nav items is not smart enough to | ||
# to render without a navs container (maybe it could?), so we need to | ||
# wrap in one and also notify the JSX logic to not select the nav | ||
# (shiny.js handles that part via the select parameter). | ||
jsx_tag = navs_hidden(nav, selected=False) | ||
|
||
msg = { | ||
"inputId": id, | ||
"menuName": menu_title, | ||
"target": None, | ||
"position": "before", | ||
"select": select, | ||
"jsxTag": session.process_ui(jsx_tag), | ||
} | ||
|
||
def callback() -> None: | ||
run_coro_sync(session.send_message({"shiny-insert-tab": msg})) | ||
|
||
session.on_flush(callback, once=True) | ||
|
||
|
||
def nav_insert( | ||
id: str, | ||
nav: JSXTag, | ||
target: Optional[str] = None, | ||
position: Literal["after", "before"] = "after", | ||
select: bool = False, | ||
session: Optional[Session] = None, | ||
) -> None: | ||
|
||
session = require_active_session(session) | ||
# TODO: do we need to namespace the id? | ||
# id = session.ns(id) | ||
|
||
# The currrent JSX implementation of nav items is not smart enough to | ||
# to render without a navs container (maybe it could?), so we need to | ||
# wrap in one and also notify the JSX logic to not select the nav | ||
# (shiny.js handles that part via the select parameter). | ||
jsx_tag = navs_hidden(nav, selected=False) | ||
|
||
msg = { | ||
"inputId": id, | ||
"menuName": None, | ||
"target": target, | ||
"position": position, | ||
"select": select, | ||
"jsxTag": session.process_ui(jsx_tag), | ||
} | ||
|
||
def callback() -> None: | ||
run_coro_sync(session.send_message({"shiny-insert-tab": msg})) | ||
|
||
session.on_flush(callback, once=True) | ||
|
||
|
||
def nav_remove(id: str, target: str, session: Optional[Session] = None) -> None: | ||
|
||
session = require_active_session(session) | ||
# TODO: do we need to namespace the id? | ||
# id = session.ns(id) | ||
|
||
msg = {"inputId": id, "target": target} | ||
|
||
def callback() -> None: | ||
run_coro_sync(session.send_message({"shiny-remove-tab": msg})) | ||
|
||
session.on_flush(callback, once=True) | ||
|
||
|
||
def nav_hide(id: str, target: str, session: Optional[Session] = None) -> None: | ||
|
||
session = require_active_session(session) | ||
# TODO: do we need to namespace the id? | ||
# id = session.ns(id) | ||
|
||
msg = {"inputId": id, "target": target, "type": "hide"} | ||
|
||
def callback() -> None: | ||
run_coro_sync(session.send_message({"shiny-change-tab-visibility": msg})) | ||
|
||
session.on_flush(callback, once=True) | ||
|
||
|
||
def nav_show( | ||
id: str, target: str, select: bool = False, session: Optional[Session] = None | ||
) -> None: | ||
""" | ||
Show a nav | ||
""" | ||
|
||
session = require_active_session(session) | ||
|
||
if select: | ||
update_navs(id, selected=target) | ||
|
||
# TODO: do we need to namespace the id? | ||
# id = session.ns(id) | ||
msg = {"inputId": id, "target": target, "type": "show"} | ||
|
||
def callback() -> None: | ||
run_coro_sync(session.send_message({"shiny-change-tab-visibility": msg})) | ||
|
||
session.on_flush(callback, once=True) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.