streamlit-plugins 0.7.15__tar.gz → 0.7.17__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {streamlit_plugins-0.7.15/streamlit_plugins.egg-info → streamlit_plugins-0.7.17}/PKG-INFO +1 -1
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/document_blocks/__init__.py +83 -15
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/navbar/__init__.py +56 -30
- streamlit_plugins-0.7.17/streamlit_plugins/components/navbar/frontend/build/asset-manifest.json +10 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/navbar/frontend/build/index.html +1 -1
- streamlit_plugins-0.7.17/streamlit_plugins/components/navbar/frontend/build/static/js/main.8e1dc380.js +3 -0
- streamlit_plugins-0.7.17/streamlit_plugins/components/navbar/frontend/build/static/js/main.8e1dc380.js.map +1 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17/streamlit_plugins.egg-info}/PKG-INFO +1 -1
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins.egg-info/SOURCES.txt +3 -3
- streamlit_plugins-0.7.15/streamlit_plugins/components/navbar/frontend/build/asset-manifest.json +0 -10
- streamlit_plugins-0.7.15/streamlit_plugins/components/navbar/frontend/build/static/js/main.8bc23bfa.js +0 -3
- streamlit_plugins-0.7.15/streamlit_plugins/components/navbar/frontend/build/static/js/main.8bc23bfa.js.map +0 -1
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/LICENSE +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/README.md +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/setup.cfg +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/setup.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/__init__.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/__init__.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/annotated_text/__init__.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/input_chat_advance/__init__.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/label_studio/__init__.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/label_studio/frontend/build/asset-manifest.json +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/label_studio/frontend/build/bootstrap.min.css +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/label_studio/frontend/build/custom.css +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/label_studio/frontend/build/index.html +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/label_studio/frontend/build/static/css/2.4f758a59.chunk.css +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/label_studio/frontend/build/static/css/2.4f758a59.chunk.css.map +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/label_studio/frontend/build/static/js/2.524324ba.chunk.js +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/label_studio/frontend/build/static/js/2.524324ba.chunk.js.LICENSE.txt +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/label_studio/frontend/build/static/js/2.524324ba.chunk.js.map +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/label_studio/frontend/build/static/js/main.34b82d10.chunk.js +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/label_studio/frontend/build/static/js/main.34b82d10.chunk.js.map +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/label_studio/frontend/build/static/js/runtime-main.65660c44.js +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/label_studio/frontend/build/static/js/runtime-main.65660c44.js.map +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/loader/__init__.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/navbar/config.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/navbar/frontend/build/CrossOriginInterface.js +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/navbar/frontend/build/bootstrap.min.css +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/navbar/frontend/build/bootstrap.min.css.map +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/navbar/frontend/build/material-fonts.css +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/navbar/frontend/build/material.woff2 +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/navbar/frontend/build/st-styles.css +0 -0
- /streamlit_plugins-0.7.15/streamlit_plugins/components/navbar/frontend/build/static/js/main.8bc23bfa.js.LICENSE.txt → /streamlit_plugins-0.7.17/streamlit_plugins/components/navbar/frontend/build/static/js/main.8e1dc380.js.LICENSE.txt +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/navbar/frontend/build/style.css +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/navbar/inject_script.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/sankey_input/__init__.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/selectbox_enrich/__init__.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/skeleton/__init__.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/skeleton/template_builder.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/snakeviz/__init__.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/snakeviz/frontend/build/asset-manifest.json +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/snakeviz/frontend/build/index.html +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/snakeviz/frontend/build/static/drawsvg.js +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/snakeviz/frontend/build/static/drawsvg.v7.js +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/snakeviz/frontend/build/static/favicon.ico +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/snakeviz/frontend/build/static/images/sort_asc.png +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/snakeviz/frontend/build/static/images/sort_both.png +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/snakeviz/frontend/build/static/images/sort_desc.png +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/snakeviz/frontend/build/static/js/2.9cedfdc4.chunk.js +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/snakeviz/frontend/build/static/js/2.9cedfdc4.chunk.js.LICENSE.txt +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/snakeviz/frontend/build/static/js/2.9cedfdc4.chunk.js.map +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/snakeviz/frontend/build/static/js/main.1dfd8582.chunk.js +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/snakeviz/frontend/build/static/js/main.1dfd8582.chunk.js.map +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/snakeviz/frontend/build/static/js/runtime-main.8efd821a.js +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/snakeviz/frontend/build/static/js/runtime-main.8efd821a.js.map +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/snakeviz/frontend/build/static/snakeviz.css +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/snakeviz/frontend/build/static/snakeviz.js +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/snakeviz/frontend/build/static/vendor/d3.v3.min.js +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/snakeviz/frontend/build/static/vendor/immutable.min.js +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/snakeviz/frontend/build/static/vendor/jquery-3.2.1.min.js +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/snakeviz/frontend/build/static/vendor/jquery.dataTables.min.css +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/snakeviz/frontend/build/static/vendor/jquery.dataTables.min.js +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/snakeviz/frontend/build/static/vendor/lodash.min.js +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/snakeviz/frontend/build/templates/dir.html +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/snakeviz/frontend/build/templates/viz.html +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/theme_changer/__init__.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/theme_changer/config.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/theme_changer/entity.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/theme_changer/frontend/build/CrossOriginInterface.js +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/components/theme_changer/inject_script.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/extension/__init__.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/extension/button_group/__init__.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/extension/dynamic_container/__init__.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/framework/__init__.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/framework/multilit/__init__.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/framework/multilit/app_wrapper.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/framework/multilit/loading_engine.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/framework/multilit/multilit.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/framework/reactlit/__init__.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/framework/reactlit/advanced_patterns.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/framework/reactlit/lab.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/framework/reactlit/reactive.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/framework/reactlit/reactlit.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins/framework/reactlit/test_reactive.py +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins.egg-info/dependency_links.txt +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins.egg-info/requires.txt +0 -0
- {streamlit_plugins-0.7.15 → streamlit_plugins-0.7.17}/streamlit_plugins.egg-info/top_level.txt +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import base64
|
|
2
|
+
import contextlib
|
|
2
3
|
import mimetypes
|
|
3
4
|
from dataclasses import dataclass
|
|
4
5
|
from io import BytesIO
|
|
@@ -12,6 +13,8 @@ from PIL import Image
|
|
|
12
13
|
from streamlit.components.v2 import component as create_component
|
|
13
14
|
from streamlit.delta_generator import DeltaGenerator
|
|
14
15
|
from streamlit.elements.lib.layout_utils import Width, Height
|
|
16
|
+
from streamlit.elements.lib.mutable_tab_container import TabContainer
|
|
17
|
+
|
|
15
18
|
from streamlit_plugins.extension.dynamic_container import st_dynamic_container
|
|
16
19
|
|
|
17
20
|
|
|
@@ -849,16 +852,70 @@ def st_document_blocks(
|
|
|
849
852
|
return blocks_normalized, result.get("selected_id")
|
|
850
853
|
|
|
851
854
|
|
|
852
|
-
def
|
|
855
|
+
def search_block_recursive(search_by: dict, _blocks: list[dict], any_match=False) -> tuple[dict | None, dict | None]:
|
|
853
856
|
for block in _blocks:
|
|
854
|
-
if
|
|
857
|
+
if (
|
|
858
|
+
any(block[key] == value if key in block else False for key, value in search_by.items()) if any_match
|
|
859
|
+
else all(block[key] == value if key in block else False for key, value in search_by.items())
|
|
860
|
+
):
|
|
855
861
|
return block, None
|
|
856
862
|
if "children" in block:
|
|
857
|
-
result, _ =
|
|
863
|
+
result, _ = search_block_recursive(search_by, block["children"], any_match=any_match)
|
|
858
864
|
if result:
|
|
859
865
|
return result, block
|
|
860
866
|
return None, None
|
|
861
867
|
|
|
868
|
+
def _format_raw_code(language: Literal["html", "markdown"], content: str):
|
|
869
|
+
if language == "html":
|
|
870
|
+
try:
|
|
871
|
+
from bs4 import BeautifulSoup
|
|
872
|
+
except ImportError:
|
|
873
|
+
raise ImportError("BeautifulSoup4 is required for HTML formatting. Please install it with `pip install beautifulsoup4`.")
|
|
874
|
+
|
|
875
|
+
soup = BeautifulSoup(content, "html.parser")
|
|
876
|
+
|
|
877
|
+
# Aplicar el beautifier
|
|
878
|
+
clean_html = soup.prettify()
|
|
879
|
+
return clean_html
|
|
880
|
+
|
|
881
|
+
elif language == "markdown":
|
|
882
|
+
try:
|
|
883
|
+
import mdformat
|
|
884
|
+
except ImportError:
|
|
885
|
+
raise ImportError("Markdown and Markdownify are required for Markdown formatting. Please install them with `pip install mdformat mdformat-gfm`.")
|
|
886
|
+
|
|
887
|
+
# Convertir a HTML y luego de vuelta a Markdown para formatear
|
|
888
|
+
clean_markdown = mdformat.text(content)
|
|
889
|
+
return clean_markdown
|
|
890
|
+
|
|
891
|
+
else:
|
|
892
|
+
raise ValueError("Unknown language {}".format(language))
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
def search_blocks_recursive(search_by: dict, _blocks: list[dict], any_match=False, level=0) -> list[tuple[dict, int]]:
|
|
897
|
+
"""
|
|
898
|
+
Devuelve unas tuplas con los bloques que cumplen los criterios pero de forma anidada incluyendo el nivel de recursividad
|
|
899
|
+
:param search_by:
|
|
900
|
+
:param _blocks:
|
|
901
|
+
:param any_match:
|
|
902
|
+
:return:
|
|
903
|
+
"""
|
|
904
|
+
|
|
905
|
+
results = []
|
|
906
|
+
for block in _blocks:
|
|
907
|
+
if (
|
|
908
|
+
any(block[key] == value if key in block else False for key, value in search_by.items()) if any_match
|
|
909
|
+
else all(block[key] == value if key in block else False for key, value in search_by.items())
|
|
910
|
+
):
|
|
911
|
+
results.append((block, level))
|
|
912
|
+
if "children" in block:
|
|
913
|
+
child_results = search_blocks_recursive(search_by, block["children"], any_match=any_match, level=level + 1)
|
|
914
|
+
for child_result, child_level in child_results:
|
|
915
|
+
results.append((child_result, child_level))
|
|
916
|
+
return results
|
|
917
|
+
|
|
918
|
+
|
|
862
919
|
|
|
863
920
|
def on_tab_change():
|
|
864
921
|
pass
|
|
@@ -879,6 +936,7 @@ if HOVER_BLOCK_RESULT_KEY not in st.session_state:
|
|
|
879
936
|
RESULT_ACTIVE_OBSERVED_KEY = "selected_id"
|
|
880
937
|
|
|
881
938
|
|
|
939
|
+
@contextlib.contextmanager
|
|
882
940
|
@st.fragment
|
|
883
941
|
def st_documents_blocks_info(
|
|
884
942
|
document: Document,
|
|
@@ -893,7 +951,8 @@ def st_documents_blocks_info(
|
|
|
893
951
|
show_markdown: bool | str = True,
|
|
894
952
|
tab_order: Optional[list[Literal["Blocks", "JSON", "HTML", "Markdown"] | str]] = None,
|
|
895
953
|
custom_tabs: Optional[list[str]] = None,
|
|
896
|
-
|
|
954
|
+
format_raw_code: bool = False,
|
|
955
|
+
) -> Generator[tuple[list[dict], list[TabContainer]], Any, None]:
|
|
897
956
|
main_container = st.container(horizontal=True)
|
|
898
957
|
page_selected = 1
|
|
899
958
|
if document.pages > 1:
|
|
@@ -988,10 +1047,15 @@ def st_documents_blocks_info(
|
|
|
988
1047
|
|
|
989
1048
|
block_selected = None
|
|
990
1049
|
if selected_block_id is not None:
|
|
991
|
-
block_selected, parent_block =
|
|
1050
|
+
block_selected, parent_block = search_block_recursive({"id": selected_block_id}, blocks_page)
|
|
992
1051
|
if parent_block is not None:
|
|
993
1052
|
block_selected = parent_block
|
|
994
1053
|
|
|
1054
|
+
if custom_tabs:
|
|
1055
|
+
# Return custom tabs
|
|
1056
|
+
st_custom_cols = [st_cols[tabs.index(tab)] for tab in tabs if tab in custom_tabs]
|
|
1057
|
+
yield blocks_normalized, st_custom_cols
|
|
1058
|
+
|
|
995
1059
|
if blocks_col and blocks_col.open:
|
|
996
1060
|
dynamic_container_css = """
|
|
997
1061
|
.st-key-view-container .stVerticalBlock:has( .article-block) {
|
|
@@ -1078,15 +1142,16 @@ def st_documents_blocks_info(
|
|
|
1078
1142
|
|
|
1079
1143
|
elif html_col and html_col.open:
|
|
1080
1144
|
with html_col:
|
|
1145
|
+
render_col, raw_col = st.tabs(
|
|
1146
|
+
["Renderer", "Raw"],
|
|
1147
|
+
on_change=on_tab_change
|
|
1148
|
+
)
|
|
1081
1149
|
with st_dynamic_container(
|
|
1082
1150
|
container_source_key="document_blocks",
|
|
1083
1151
|
key="view-container", mimic_vertical=True, border=True
|
|
1084
1152
|
):
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
on_change=on_tab_change
|
|
1088
|
-
)
|
|
1089
|
-
html_content = _concat_content(blocks_page, content_type="html", parent_content_has_children=parent_content_has_children)
|
|
1153
|
+
|
|
1154
|
+
html_content = _concat_content(blocks_normalized, content_type="html", parent_content_has_children=parent_content_has_children)
|
|
1090
1155
|
if not html_content:
|
|
1091
1156
|
st.warning("HTML content is empty. Please ensure that the blocks contain valid HTML content.")
|
|
1092
1157
|
if render_col.open:
|
|
@@ -1094,7 +1159,9 @@ def st_documents_blocks_info(
|
|
|
1094
1159
|
st.write(html_content, unsafe_allow_html=True)
|
|
1095
1160
|
elif raw_col.open:
|
|
1096
1161
|
with raw_col:
|
|
1097
|
-
|
|
1162
|
+
if format_raw_code:
|
|
1163
|
+
html_content = _format_raw_code("html", html_content)
|
|
1164
|
+
st.code(html_content, language="html", line_numbers=True, wrap_lines=True)
|
|
1098
1165
|
|
|
1099
1166
|
elif markdown_col and markdown_col.open:
|
|
1100
1167
|
with markdown_col:
|
|
@@ -1103,10 +1170,10 @@ def st_documents_blocks_info(
|
|
|
1103
1170
|
key="view-container", mimic_vertical=True, border=True
|
|
1104
1171
|
):
|
|
1105
1172
|
render_col, raw_col = st.tabs(
|
|
1106
|
-
["Renderer", "Raw"
|
|
1173
|
+
["Renderer", "Raw"],
|
|
1107
1174
|
on_change=on_tab_change
|
|
1108
1175
|
)
|
|
1109
|
-
markdown_content = _concat_content(
|
|
1176
|
+
markdown_content = _concat_content(blocks_normalized, content_type="markdown", parent_content_has_children=parent_content_has_children)
|
|
1110
1177
|
if not markdown_content:
|
|
1111
1178
|
st.warning("Markdown content is empty. Please ensure that the blocks contain valid Markdown content.")
|
|
1112
1179
|
if render_col.open:
|
|
@@ -1114,7 +1181,8 @@ def st_documents_blocks_info(
|
|
|
1114
1181
|
st.markdown(markdown_content, unsafe_allow_html=True)
|
|
1115
1182
|
elif raw_col.open:
|
|
1116
1183
|
with raw_col:
|
|
1117
|
-
|
|
1118
|
-
|
|
1184
|
+
if format_raw_code:
|
|
1185
|
+
markdown_content = _format_raw_code("markdown", markdown_content)
|
|
1186
|
+
st.code(markdown_content, language="markdown", line_numbers=True, wrap_lines=True)
|
|
1119
1187
|
|
|
1120
1188
|
__all__ = ["st_document_blocks", "st_documents_blocks_info"]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import inspect
|
|
2
2
|
import time
|
|
3
|
-
from typing import Literal
|
|
3
|
+
from typing import Literal, Optional, cast
|
|
4
4
|
import warnings
|
|
5
5
|
import logging
|
|
6
6
|
from urllib.parse import urlparse
|
|
@@ -624,6 +624,7 @@ def st_navbar(
|
|
|
624
624
|
option_menu=False,
|
|
625
625
|
default_page_selected_id=None,
|
|
626
626
|
override_page_selected_id=None,
|
|
627
|
+
override_first_page_load_id=None,
|
|
627
628
|
reclick_load=True,
|
|
628
629
|
input_styles: str | None = None,
|
|
629
630
|
themes_data: list[dict]| None = None,
|
|
@@ -633,7 +634,7 @@ def st_navbar(
|
|
|
633
634
|
prefix_url: str = "",
|
|
634
635
|
# url_navigation: bool = False,
|
|
635
636
|
key="NavBarComponent",
|
|
636
|
-
):
|
|
637
|
+
) -> str:
|
|
637
638
|
if home_definition is None:
|
|
638
639
|
home_definition = menu_definition.pop(0)
|
|
639
640
|
|
|
@@ -748,12 +749,13 @@ def st_navbar(
|
|
|
748
749
|
st.session_state[f"{NAVBAR_KEY_PREFIX}_coi_instance"] = True
|
|
749
750
|
|
|
750
751
|
with navbar_view:
|
|
751
|
-
component_value = _component_func(
|
|
752
|
+
component_value: Optional[str] = _component_func(
|
|
752
753
|
menu_definition=menu_definition, home=home_data or None, login=login_data or None,
|
|
753
754
|
override_theme=override_theme,
|
|
754
755
|
position_mode=position_mode, is_sticky=sticky_nav,
|
|
755
756
|
default_page_selected_id=default_page_selected_id,
|
|
756
757
|
override_page_selected_id=override_page_selected_id,
|
|
758
|
+
override_first_page_load_id=override_first_page_load_id,
|
|
757
759
|
reclick_load=reclick_load,
|
|
758
760
|
styles=styles, custom_styles=input_styles,
|
|
759
761
|
is_navigation=is_navigation,
|
|
@@ -762,7 +764,7 @@ def st_navbar(
|
|
|
762
764
|
collapsible=collapsible,
|
|
763
765
|
prefix_url=prefix_url,
|
|
764
766
|
# url_navigation=url_navigation and is_navigation,
|
|
765
|
-
default=
|
|
767
|
+
default=None,
|
|
766
768
|
is_visible=True,
|
|
767
769
|
key=key, fvalue=force_value,
|
|
768
770
|
)
|
|
@@ -774,14 +776,17 @@ def st_navbar(
|
|
|
774
776
|
# print(f"FROM Navbar: {component_value}")
|
|
775
777
|
|
|
776
778
|
if component_value is None:
|
|
777
|
-
|
|
779
|
+
if not is_navigation:
|
|
780
|
+
component_value = default_page_selected_id
|
|
781
|
+
else:
|
|
782
|
+
component_value = override_first_page_load_id or default_page_selected_id
|
|
778
783
|
|
|
779
784
|
if override_page_selected_id:
|
|
780
785
|
component_value = override_page_selected_id
|
|
781
786
|
|
|
782
787
|
# print(f"FROM Navbar FINAL: {component_value}")
|
|
783
788
|
# print()
|
|
784
|
-
return component_value
|
|
789
|
+
return cast(str, component_value)
|
|
785
790
|
|
|
786
791
|
def st_which_page() -> str:
|
|
787
792
|
return st.session_state[f"{NAVIGATION_KEY_PREFIX}_page_id"]
|
|
@@ -805,6 +810,9 @@ def st_navigation(
|
|
|
805
810
|
page_id_key = f"{NAVIGATION_KEY_PREFIX}_page_id"
|
|
806
811
|
force_page_id_key = f"{NAVIGATION_KEY_PREFIX}_force_page_id"
|
|
807
812
|
history_key = f"{NAVIGATION_KEY_PREFIX}_history"
|
|
813
|
+
default_page_id_key = f"{NAVIGATION_KEY_PREFIX}_default_page_id"
|
|
814
|
+
|
|
815
|
+
first_load = False
|
|
808
816
|
|
|
809
817
|
if prev_url_page_id_key not in st.session_state:
|
|
810
818
|
st.session_state[prev_url_page_id_key] = None
|
|
@@ -814,6 +822,7 @@ def st_navigation(
|
|
|
814
822
|
|
|
815
823
|
if page_id_key not in st.session_state:
|
|
816
824
|
st.session_state[page_id_key] = None
|
|
825
|
+
first_load = True
|
|
817
826
|
|
|
818
827
|
if force_page_id_key not in st.session_state:
|
|
819
828
|
st.session_state[force_page_id_key] = None
|
|
@@ -903,7 +912,7 @@ def st_navigation(
|
|
|
903
912
|
|
|
904
913
|
st.session_state[f"{NAVIGATION_KEY_PREFIX}_menu_pages"] = menu_pages
|
|
905
914
|
st.session_state[f"{NAVIGATION_KEY_PREFIX}_menu_account_pages"] = menu_account_pages
|
|
906
|
-
st.session_state[
|
|
915
|
+
st.session_state[default_page_id_key] = default_page._script_hash
|
|
907
916
|
|
|
908
917
|
logout_page_id, login_page_id = None, None
|
|
909
918
|
if login_page:
|
|
@@ -927,15 +936,34 @@ def st_navigation(
|
|
|
927
936
|
|
|
928
937
|
|
|
929
938
|
if st.session_state[page_id_key] is None:
|
|
930
|
-
st.session_state[page_id_key] = st.session_state[
|
|
939
|
+
st.session_state[page_id_key] = st.session_state[default_page_id_key]
|
|
940
|
+
|
|
941
|
+
initial_force_page_id = st.session_state[force_page_id_key]
|
|
931
942
|
|
|
932
|
-
|
|
943
|
+
if native_way:
|
|
944
|
+
# Si la url es el path igual al que devuelve el `next_page_id` quiere decir que la navegacion es por url
|
|
945
|
+
# En este punto el navigation de streamlit siempre devolvera la pagina actual
|
|
946
|
+
# ya que no se usara su navegacion frontal para seleccionar una pagina
|
|
947
|
+
# if url_navigation:
|
|
948
|
+
url_page_id = get_page_id_by_url_path(
|
|
949
|
+
pages_map, st.context.url, prefix_url=prefix_url
|
|
950
|
+
)
|
|
951
|
+
# print("URL PAGE", pages_map[url_page_id].title)
|
|
952
|
+
if url_page_id != st.session_state[prev_url_page_id_key]:
|
|
953
|
+
# Navegacion por url
|
|
954
|
+
st.session_state[prev_url_page_id_key] = url_page_id
|
|
955
|
+
# Solo si es la primera pagina, no hay variables de estado previas o se ha limpiado
|
|
956
|
+
if first_load:
|
|
957
|
+
initial_force_page_id = url_page_id
|
|
958
|
+
|
|
959
|
+
navbar_page_id = st_navbar(
|
|
933
960
|
menu_definition=menu_pages, # if st.session_state.logged_in else [],
|
|
934
961
|
home_definition=home_definition,
|
|
935
962
|
login_definition=menu_account_pages,
|
|
936
963
|
hide_streamlit_markers=False,
|
|
937
|
-
default_page_selected_id=st.session_state[page_id_key] or st.session_state[
|
|
964
|
+
default_page_selected_id=st.session_state[page_id_key] or st.session_state[default_page_id_key],
|
|
938
965
|
override_page_selected_id=st.session_state[force_page_id_key],
|
|
966
|
+
override_first_page_load_id=initial_force_page_id,
|
|
939
967
|
position_mode=position_mode,
|
|
940
968
|
sticky_nav=sticky_nav,
|
|
941
969
|
input_styles=input_styles,
|
|
@@ -947,42 +975,40 @@ def st_navigation(
|
|
|
947
975
|
hide_skeleton=True,
|
|
948
976
|
)
|
|
949
977
|
st.session_state[force_page_id_key] = None
|
|
950
|
-
|
|
951
|
-
st.session_state[page_id_key] =
|
|
978
|
+
streamlit_page_id = st.session_state[page_id_key]
|
|
979
|
+
st.session_state[page_id_key] = navbar_page_id or initial_force_page_id # Added to fix login/logout issue
|
|
952
980
|
# print("CUSTOM COMPONENT", pages_map[next_page_id].title)
|
|
953
981
|
if native_way:
|
|
954
982
|
# Si la url es el path igual al que devuelve el `next_page_id` quiere decir que la navegacion es por url
|
|
955
983
|
# En este punto el navigation de streamlit siempre devolvera la pagina actual
|
|
956
984
|
# ya que no se usara su navegacion frontal para seleccionar una pagina
|
|
957
985
|
# if url_navigation:
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
#
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
# st.session_state[f"{NAVIGATION_KEY_PREFIX}_prev_url_page_id"] = url_page_id
|
|
967
|
-
# next_page_id = url_page_id
|
|
986
|
+
url_page_id = get_page_id_by_url_path(
|
|
987
|
+
pages_map, st.context.url, prefix_url=prefix_url
|
|
988
|
+
)
|
|
989
|
+
# print("URL PAGE", pages_map[url_page_id].title)
|
|
990
|
+
if url_page_id != st.session_state[prev_url_page_id_key]:
|
|
991
|
+
# Navegacion por url
|
|
992
|
+
st.session_state[prev_url_page_id_key] = url_page_id
|
|
993
|
+
navbar_page_id = url_page_id
|
|
968
994
|
|
|
969
995
|
page = st.navigation(
|
|
970
996
|
st_pages,
|
|
971
997
|
position="hidden"
|
|
972
998
|
)
|
|
973
999
|
# print("ST PAGE", page.title)
|
|
974
|
-
|
|
1000
|
+
streamlit_page_id = page._script_hash
|
|
975
1001
|
else:
|
|
976
|
-
page = pages_map.get(
|
|
1002
|
+
page = pages_map.get(navbar_page_id, default_page)
|
|
977
1003
|
|
|
978
1004
|
# print("PAGE", pages_map[next_page_id].title)
|
|
979
1005
|
|
|
980
|
-
# Solo si se cambia de pagina
|
|
981
|
-
if
|
|
982
|
-
st.session_state[page_id_key] =
|
|
983
|
-
if
|
|
984
|
-
st.session_state[prev_page_id_key] =
|
|
985
|
-
st_switch_page(
|
|
1006
|
+
# Solo si se cambia de pagina desde el componente custom
|
|
1007
|
+
if streamlit_page_id != navbar_page_id:
|
|
1008
|
+
st.session_state[page_id_key] = navbar_page_id
|
|
1009
|
+
if streamlit_page_id not in [logout_page_id, login_page_id]:
|
|
1010
|
+
st.session_state[prev_page_id_key] = streamlit_page_id
|
|
1011
|
+
st_switch_page(navbar_page_id, native_way=native_way)
|
|
986
1012
|
|
|
987
1013
|
page._can_be_called = True
|
|
988
1014
|
add_page_to_history(page._script_hash)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<!doctype html><html lang="en"><head><title>Streamlit Component NavBar</title><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Streamlit Component NavBar"/><link rel="stylesheet" href="./bootstrap.min.css"/><link rel="stylesheet" href="./material-fonts.css"/><script defer="defer" src="./static/js/main.
|
|
1
|
+
<!doctype html><html lang="en"><head><title>Streamlit Component NavBar</title><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Streamlit Component NavBar"/><link rel="stylesheet" href="./bootstrap.min.css"/><link rel="stylesheet" href="./material-fonts.css"/><script defer="defer" src="./static/js/main.8e1dc380.js"></script></head><body><link rel="stylesheet" href="./style.css"/><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
|