streamlit-plugins 0.7.16__tar.gz → 0.7.19__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.19/MANIFEST.in +4 -0
- {streamlit_plugins-0.7.16/streamlit_plugins.egg-info → streamlit_plugins-0.7.19}/PKG-INFO +1 -1
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/document_blocks/__init__.py +34 -12
- streamlit_plugins-0.7.19/streamlit_plugins/components/markdown_editor/__init__.py +210 -0
- streamlit_plugins-0.7.19/streamlit_plugins/components/markdown_editor/frontend/build/THIRD_PARTY_LICENSES.txt +2020 -0
- streamlit_plugins-0.7.19/streamlit_plugins/components/markdown_editor/frontend/build/editor.css +338 -0
- streamlit_plugins-0.7.19/streamlit_plugins/components/markdown_editor/frontend/build/editor.html +183 -0
- streamlit_plugins-0.7.19/streamlit_plugins/components/markdown_editor/frontend/build/editor.js +2720 -0
- streamlit_plugins-0.7.19/streamlit_plugins/components/markdown_editor/frontend/build/renderers.bundle.js +3653 -0
- streamlit_plugins-0.7.19/streamlit_plugins/components/navbar/__init__.py +11 -0
- streamlit_plugins-0.7.19/streamlit_plugins/components/navbar/pyproject.toml +36 -0
- {streamlit_plugins-0.7.16/streamlit_plugins/components/navbar → streamlit_plugins-0.7.19/streamlit_plugins/components/navbar/v1}/__init__.py +56 -30
- streamlit_plugins-0.7.19/streamlit_plugins/components/navbar/v1/frontend/build/asset-manifest.json +10 -0
- streamlit_plugins-0.7.19/streamlit_plugins/components/navbar/v1/frontend/build/index.html +1 -0
- streamlit_plugins-0.7.19/streamlit_plugins/components/navbar/v1/frontend/build/material-fonts.css +23 -0
- {streamlit_plugins-0.7.16/streamlit_plugins/components/navbar → streamlit_plugins-0.7.19/streamlit_plugins/components/navbar/v1}/frontend/build/st-styles.css +29 -29
- streamlit_plugins-0.7.19/streamlit_plugins/components/navbar/v1/frontend/build/static/js/main.8e1dc380.js +3 -0
- streamlit_plugins-0.7.19/streamlit_plugins/components/navbar/v1/frontend/build/static/js/main.8e1dc380.js.map +1 -0
- streamlit_plugins-0.7.19/streamlit_plugins/components/navbar/v2/__init__.py +684 -0
- streamlit_plugins-0.7.19/streamlit_plugins/components/navbar/v2/frontend/build/CrossOriginInterface.js +623 -0
- streamlit_plugins-0.7.19/streamlit_plugins/components/navbar/v2/frontend/build/bootstrap.min.css +7 -0
- streamlit_plugins-0.7.19/streamlit_plugins/components/navbar/v2/frontend/build/bootstrap.min.css.map +1 -0
- streamlit_plugins-0.7.19/streamlit_plugins/components/navbar/v2/frontend/build/index-_hash_.css +40 -0
- streamlit_plugins-0.7.19/streamlit_plugins/components/navbar/v2/frontend/build/index.html +24 -0
- streamlit_plugins-0.7.19/streamlit_plugins/components/navbar/v2/frontend/build/material.woff2 +0 -0
- streamlit_plugins-0.7.19/streamlit_plugins/components/navbar/v2/frontend/build/st-styles.css +411 -0
- streamlit_plugins-0.7.19/streamlit_plugins/components/navbar/v2/frontend/build/style.css +536 -0
- streamlit_plugins-0.7.19/streamlit_plugins/components/navbar/v2/pyproject.toml +8 -0
- streamlit_plugins-0.7.19/streamlit_plugins/components/navbar/v2/utils.py +28 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/framework/multilit/multilit.py +8 -8
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19/streamlit_plugins.egg-info}/PKG-INFO +1 -1
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins.egg-info/SOURCES.txt +35 -14
- streamlit_plugins-0.7.16/streamlit_plugins/components/navbar/frontend/build/asset-manifest.json +0 -10
- streamlit_plugins-0.7.16/streamlit_plugins/components/navbar/frontend/build/index.html +0 -1
- streamlit_plugins-0.7.16/streamlit_plugins/components/navbar/frontend/build/static/js/main.8bc23bfa.js +0 -3
- streamlit_plugins-0.7.16/streamlit_plugins/components/navbar/frontend/build/static/js/main.8bc23bfa.js.map +0 -1
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/LICENSE +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/README.md +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/setup.cfg +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/setup.py +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/__init__.py +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/__init__.py +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/annotated_text/__init__.py +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/input_chat_advance/__init__.py +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/label_studio/__init__.py +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/label_studio/frontend/build/asset-manifest.json +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/label_studio/frontend/build/bootstrap.min.css +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/label_studio/frontend/build/custom.css +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/label_studio/frontend/build/index.html +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/label_studio/frontend/build/static/css/2.4f758a59.chunk.css +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/label_studio/frontend/build/static/css/2.4f758a59.chunk.css.map +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/label_studio/frontend/build/static/js/2.524324ba.chunk.js +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/label_studio/frontend/build/static/js/2.524324ba.chunk.js.LICENSE.txt +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/label_studio/frontend/build/static/js/2.524324ba.chunk.js.map +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/label_studio/frontend/build/static/js/main.34b82d10.chunk.js +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/label_studio/frontend/build/static/js/main.34b82d10.chunk.js.map +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/label_studio/frontend/build/static/js/runtime-main.65660c44.js +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/label_studio/frontend/build/static/js/runtime-main.65660c44.js.map +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/loader/__init__.py +0 -0
- {streamlit_plugins-0.7.16/streamlit_plugins/components/navbar → streamlit_plugins-0.7.19/streamlit_plugins/components/navbar/v1}/config.py +0 -0
- {streamlit_plugins-0.7.16/streamlit_plugins/components/navbar → streamlit_plugins-0.7.19/streamlit_plugins/components/navbar/v1}/frontend/build/CrossOriginInterface.js +0 -0
- {streamlit_plugins-0.7.16/streamlit_plugins/components/navbar → streamlit_plugins-0.7.19/streamlit_plugins/components/navbar/v1}/frontend/build/bootstrap.min.css +0 -0
- {streamlit_plugins-0.7.16/streamlit_plugins/components/navbar → streamlit_plugins-0.7.19/streamlit_plugins/components/navbar/v1}/frontend/build/bootstrap.min.css.map +0 -0
- {streamlit_plugins-0.7.16/streamlit_plugins/components/navbar → streamlit_plugins-0.7.19/streamlit_plugins/components/navbar/v1}/frontend/build/material.woff2 +0 -0
- /streamlit_plugins-0.7.16/streamlit_plugins/components/navbar/frontend/build/static/js/main.8bc23bfa.js.LICENSE.txt → /streamlit_plugins-0.7.19/streamlit_plugins/components/navbar/v1/frontend/build/static/js/main.8e1dc380.js.LICENSE.txt +0 -0
- {streamlit_plugins-0.7.16/streamlit_plugins/components/navbar → streamlit_plugins-0.7.19/streamlit_plugins/components/navbar/v1}/frontend/build/style.css +0 -0
- {streamlit_plugins-0.7.16/streamlit_plugins/components/navbar → streamlit_plugins-0.7.19/streamlit_plugins/components/navbar/v1}/inject_script.py +0 -0
- {streamlit_plugins-0.7.16/streamlit_plugins/components/navbar → streamlit_plugins-0.7.19/streamlit_plugins/components/navbar/v2}/frontend/build/material-fonts.css +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/sankey_input/__init__.py +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/selectbox_enrich/__init__.py +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/skeleton/__init__.py +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/skeleton/template_builder.py +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/snakeviz/__init__.py +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/snakeviz/frontend/build/asset-manifest.json +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/snakeviz/frontend/build/index.html +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/snakeviz/frontend/build/static/drawsvg.js +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/snakeviz/frontend/build/static/drawsvg.v7.js +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/snakeviz/frontend/build/static/favicon.ico +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/snakeviz/frontend/build/static/images/sort_asc.png +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/snakeviz/frontend/build/static/images/sort_both.png +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/snakeviz/frontend/build/static/images/sort_desc.png +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/snakeviz/frontend/build/static/js/2.9cedfdc4.chunk.js +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/snakeviz/frontend/build/static/js/2.9cedfdc4.chunk.js.LICENSE.txt +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/snakeviz/frontend/build/static/js/2.9cedfdc4.chunk.js.map +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/snakeviz/frontend/build/static/js/main.1dfd8582.chunk.js +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/snakeviz/frontend/build/static/js/main.1dfd8582.chunk.js.map +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/snakeviz/frontend/build/static/js/runtime-main.8efd821a.js +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/snakeviz/frontend/build/static/js/runtime-main.8efd821a.js.map +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/snakeviz/frontend/build/static/snakeviz.css +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/snakeviz/frontend/build/static/snakeviz.js +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/snakeviz/frontend/build/static/vendor/d3.v3.min.js +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/snakeviz/frontend/build/static/vendor/immutable.min.js +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/snakeviz/frontend/build/static/vendor/jquery-3.2.1.min.js +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/snakeviz/frontend/build/static/vendor/jquery.dataTables.min.css +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/snakeviz/frontend/build/static/vendor/jquery.dataTables.min.js +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/snakeviz/frontend/build/static/vendor/lodash.min.js +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/snakeviz/frontend/build/templates/dir.html +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/snakeviz/frontend/build/templates/viz.html +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/theme_changer/__init__.py +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/theme_changer/config.py +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/theme_changer/entity.py +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/theme_changer/frontend/build/CrossOriginInterface.js +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/components/theme_changer/inject_script.py +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/extension/__init__.py +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/extension/button_group/__init__.py +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/extension/dynamic_container/__init__.py +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/framework/__init__.py +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/framework/multilit/__init__.py +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/framework/multilit/app_wrapper.py +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/framework/multilit/loading_engine.py +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/framework/reactlit/__init__.py +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/framework/reactlit/advanced_patterns.py +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/framework/reactlit/lab.py +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/framework/reactlit/reactive.py +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/framework/reactlit/reactlit.py +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins/framework/reactlit/test_reactive.py +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins.egg-info/dependency_links.txt +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins.egg-info/requires.txt +0 -0
- {streamlit_plugins-0.7.16 → streamlit_plugins-0.7.19}/streamlit_plugins.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
recursive-include streamlit_plugins/components/navbar/v1/frontend/build *
|
|
2
|
+
recursive-include streamlit_plugins/components/navbar/v2/frontend/build *
|
|
3
|
+
include streamlit_plugins/components/navbar/pyproject.toml
|
|
4
|
+
include streamlit_plugins/components/navbar/v2/pyproject.toml
|
|
@@ -64,7 +64,7 @@ __CSS = """
|
|
|
64
64
|
flex: 1;
|
|
65
65
|
max-width: 550px;
|
|
66
66
|
background: #fff;
|
|
67
|
-
padding:
|
|
67
|
+
padding: 0;
|
|
68
68
|
border-radius: 8px;
|
|
69
69
|
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
|
|
70
70
|
}
|
|
@@ -952,8 +952,31 @@ def st_documents_blocks_info(
|
|
|
952
952
|
tab_order: Optional[list[Literal["Blocks", "JSON", "HTML", "Markdown"] | str]] = None,
|
|
953
953
|
custom_tabs: Optional[list[str]] = None,
|
|
954
954
|
format_raw_code: bool = False,
|
|
955
|
+
set_state_on: Literal["hover", "click"] = "hover",
|
|
956
|
+
right_col_width: int | str = "100%",
|
|
955
957
|
) -> Generator[tuple[list[dict], list[TabContainer]], Any, None]:
|
|
956
|
-
|
|
958
|
+
st.write(
|
|
959
|
+
f"""
|
|
960
|
+
<style>
|
|
961
|
+
.st-key-documents_blocks_container {{
|
|
962
|
+
display: flex;
|
|
963
|
+
flex-direction: row;
|
|
964
|
+
flex-wrap: nowrap;
|
|
965
|
+
}}
|
|
966
|
+
.st-key-documents_blocks_container > div:first-child {{
|
|
967
|
+
flex: 0 0 fit-content;
|
|
968
|
+
}}
|
|
969
|
+
.st-key-documents_blocks_container > div:last-child {{
|
|
970
|
+
width: {right_col_width};
|
|
971
|
+
flex: 1 1 auto;
|
|
972
|
+
max-width: 100%;
|
|
973
|
+
overflow: auto;
|
|
974
|
+
}}
|
|
975
|
+
</style>
|
|
976
|
+
""",
|
|
977
|
+
unsafe_allow_html=True
|
|
978
|
+
)
|
|
979
|
+
main_container = st.container(horizontal=True, key="documents_blocks_container", gap="xxsmall")
|
|
957
980
|
page_selected = 1
|
|
958
981
|
if document.pages > 1:
|
|
959
982
|
with st.container(horizontal_alignment="right"):
|
|
@@ -988,7 +1011,7 @@ def st_documents_blocks_info(
|
|
|
988
1011
|
reading_order=reading_order,
|
|
989
1012
|
custom_styles=custom_styles,
|
|
990
1013
|
default_selected=dynamic_selected_block_id,
|
|
991
|
-
set_state_on=
|
|
1014
|
+
set_state_on=set_state_on,
|
|
992
1015
|
width="content",
|
|
993
1016
|
height=600,
|
|
994
1017
|
key="document_blocks"
|
|
@@ -1135,22 +1158,21 @@ def st_documents_blocks_info(
|
|
|
1135
1158
|
elif json_col and json_col.open:
|
|
1136
1159
|
with json_col:
|
|
1137
1160
|
with st_dynamic_container(
|
|
1138
|
-
|
|
1139
|
-
|
|
1161
|
+
container_source_key="document_blocks",
|
|
1162
|
+
key="view-container", border=True
|
|
1140
1163
|
):
|
|
1141
1164
|
st.json(blocks_page)
|
|
1142
1165
|
|
|
1143
1166
|
elif html_col and html_col.open:
|
|
1144
1167
|
with html_col:
|
|
1145
|
-
render_col, raw_col = st.tabs(
|
|
1146
|
-
["Renderer", "Raw"],
|
|
1147
|
-
on_change=on_tab_change
|
|
1148
|
-
)
|
|
1149
1168
|
with st_dynamic_container(
|
|
1150
1169
|
container_source_key="document_blocks",
|
|
1151
|
-
key="view-container",
|
|
1170
|
+
key="view-container", border=True
|
|
1152
1171
|
):
|
|
1153
|
-
|
|
1172
|
+
render_col, raw_col = st.tabs(
|
|
1173
|
+
["Renderer", "Raw"],
|
|
1174
|
+
on_change=on_tab_change
|
|
1175
|
+
)
|
|
1154
1176
|
html_content = _concat_content(blocks_normalized, content_type="html", parent_content_has_children=parent_content_has_children)
|
|
1155
1177
|
if not html_content:
|
|
1156
1178
|
st.warning("HTML content is empty. Please ensure that the blocks contain valid HTML content.")
|
|
@@ -1167,7 +1189,7 @@ def st_documents_blocks_info(
|
|
|
1167
1189
|
with markdown_col:
|
|
1168
1190
|
with st_dynamic_container(
|
|
1169
1191
|
container_source_key="document_blocks",
|
|
1170
|
-
key="view-container",
|
|
1192
|
+
key="view-container", border=True
|
|
1171
1193
|
):
|
|
1172
1194
|
render_col, raw_col = st.tabs(
|
|
1173
1195
|
["Renderer", "Raw"],
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
from collections.abc import Mapping, Sequence
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from streamlit.components.v2 import component as create_component
|
|
6
|
+
from streamlit.elements.lib.layout_utils import Height
|
|
7
|
+
|
|
8
|
+
_ASSET_DIR = Path(__file__).with_name("frontend") / "build"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _normalize_blocks(
|
|
12
|
+
blocks: Sequence[Mapping[str, Any]], *, for_review: bool = False
|
|
13
|
+
) -> list[dict[str, str]]:
|
|
14
|
+
normalized: list[dict[str, str]] = []
|
|
15
|
+
seen_ids: set[str] = set()
|
|
16
|
+
for index, block in enumerate(blocks):
|
|
17
|
+
if not isinstance(block, Mapping):
|
|
18
|
+
raise TypeError(f"El bloque {index} debe ser un mapping")
|
|
19
|
+
markdown = block.get("markdown", block.get("text"))
|
|
20
|
+
if not isinstance(markdown, str):
|
|
21
|
+
raise TypeError(f"El bloque {index} debe incluir markdown de tipo str")
|
|
22
|
+
block_id = block.get("id") if for_review else block.get("id", f"block-{index}")
|
|
23
|
+
block_id = str(block_id) if block_id is not None or not for_review else None
|
|
24
|
+
if block_id is not None and block_id in seen_ids:
|
|
25
|
+
raise ValueError(f"ID de bloque duplicado: {block_id}")
|
|
26
|
+
item = {"markdown": markdown}
|
|
27
|
+
if block_id is not None:
|
|
28
|
+
seen_ids.add(block_id)
|
|
29
|
+
item["id"] = block_id
|
|
30
|
+
normalized.append(item)
|
|
31
|
+
if not normalized and not for_review:
|
|
32
|
+
normalized.append({"id": "block-0", "markdown": ""})
|
|
33
|
+
return normalized
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _normalize_diff(diff: Mapping[str, Any] | None) -> dict[str, Any] | None:
|
|
37
|
+
if diff is None:
|
|
38
|
+
return None
|
|
39
|
+
if not isinstance(diff, Mapping):
|
|
40
|
+
raise TypeError("diff debe ser un mapping con before y after o sus bloques")
|
|
41
|
+
has_blocks = "before_blocks" in diff or "after_blocks" in diff
|
|
42
|
+
if has_blocks and not ("before_blocks" in diff and "after_blocks" in diff):
|
|
43
|
+
raise ValueError("diff debe incluir before_blocks y after_blocks juntos")
|
|
44
|
+
normalized: dict[str, Any] = {}
|
|
45
|
+
for version in ("before", "after"):
|
|
46
|
+
source = diff.get(version)
|
|
47
|
+
if has_blocks:
|
|
48
|
+
blocks = diff[f"{version}_blocks"]
|
|
49
|
+
if not isinstance(blocks, Sequence) or isinstance(blocks, (str, bytes)):
|
|
50
|
+
raise TypeError(f"{version}_blocks debe ser una secuencia de bloques")
|
|
51
|
+
blocks = _normalize_blocks(blocks, for_review=True)
|
|
52
|
+
normalized[f"{version}_blocks"] = blocks
|
|
53
|
+
markdown = "\n\n".join(block["markdown"] for block in blocks)
|
|
54
|
+
if source is None:
|
|
55
|
+
source = markdown
|
|
56
|
+
elif source != markdown:
|
|
57
|
+
raise ValueError(f"{version} debe coincidir con el Markdown de {version}_blocks")
|
|
58
|
+
if not isinstance(source, str):
|
|
59
|
+
raise ValueError("diff debe incluir before y after de tipo str o sus bloques")
|
|
60
|
+
normalized[version] = source
|
|
61
|
+
return normalized
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _document_from_state(
|
|
65
|
+
state: Any,
|
|
66
|
+
initial_blocks: list[dict[str, str]],
|
|
67
|
+
*,
|
|
68
|
+
mode: str,
|
|
69
|
+
save_mode: str,
|
|
70
|
+
) -> dict[str, Any]:
|
|
71
|
+
if state is None:
|
|
72
|
+
blocks = initial_blocks
|
|
73
|
+
return {
|
|
74
|
+
"blocks": blocks,
|
|
75
|
+
"markdown": "\n\n".join(block["markdown"] for block in blocks),
|
|
76
|
+
"mode": mode,
|
|
77
|
+
"save_mode": save_mode,
|
|
78
|
+
}
|
|
79
|
+
if not isinstance(state, Mapping):
|
|
80
|
+
raise TypeError("El estado devuelto por el editor debe ser un mapping")
|
|
81
|
+
state_blocks = state.get("blocks")
|
|
82
|
+
state_markdown = state.get("markdown")
|
|
83
|
+
if not isinstance(state_blocks, list) or not isinstance(state_markdown, str):
|
|
84
|
+
raise ValueError("El editor devolvió un estado incompleto")
|
|
85
|
+
state_mode = state.get("mode", mode)
|
|
86
|
+
if state_mode not in {"raw_visual", "visual"}:
|
|
87
|
+
raise ValueError("El editor devolvió un modo desconocido")
|
|
88
|
+
return {
|
|
89
|
+
"blocks": state_blocks,
|
|
90
|
+
"markdown": state_markdown,
|
|
91
|
+
"mode": state_mode,
|
|
92
|
+
"save_mode": save_mode,
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def st_markdown_block_editor(
|
|
97
|
+
initial_blocks: Sequence[Mapping[str, Any]],
|
|
98
|
+
*,
|
|
99
|
+
key: str,
|
|
100
|
+
revision: int = 0,
|
|
101
|
+
height: Height | None = "stretch",
|
|
102
|
+
mode: str = "raw_visual",
|
|
103
|
+
save_mode: str = "auto",
|
|
104
|
+
only_view: bool = False,
|
|
105
|
+
debug_blocks: bool = False,
|
|
106
|
+
diff: Mapping[str, Any] | None = None,
|
|
107
|
+
editor_modes: Sequence[str] = ("raw_visual", "visual"),
|
|
108
|
+
review_modes: Sequence[str] = ("visual", "markdown"),
|
|
109
|
+
review_layouts: Sequence[str] = ("before", "after", "split", "blocks"),
|
|
110
|
+
block_diff_style: str = "content",
|
|
111
|
+
placeholder: str = "Escribe aquí…",
|
|
112
|
+
show_copy_button: bool = True,
|
|
113
|
+
show_status_bar: bool = True,
|
|
114
|
+
toolbar_sections: Sequence[str] = ("view", "format", "block", "history", "changes"),
|
|
115
|
+
) -> dict[str, Any]:
|
|
116
|
+
"""Edit Markdown blocks or review visual, source and block-level changes.
|
|
117
|
+
|
|
118
|
+
With button saving, review compares the saved document with the local draft.
|
|
119
|
+
External diffs accept before/after strings or paired before_blocks/after_blocks.
|
|
120
|
+
Stable block IDs improve movement and content-change identification.
|
|
121
|
+
toolbar_sections controls header visibility, not editing permissions.
|
|
122
|
+
"""
|
|
123
|
+
if not key:
|
|
124
|
+
raise ValueError("key no puede estar vacía")
|
|
125
|
+
if revision < 0:
|
|
126
|
+
raise ValueError("revision no puede ser negativa")
|
|
127
|
+
if height is not None and (isinstance(height, bool) or not isinstance(height, (int, str))):
|
|
128
|
+
raise TypeError("height debe ser un entero, 'stretch', 'content' o None")
|
|
129
|
+
if isinstance(height, int) and height < 240:
|
|
130
|
+
raise ValueError("height debe ser al menos 240 px")
|
|
131
|
+
if isinstance(height, str) and height not in {"stretch", "content"}:
|
|
132
|
+
raise ValueError("height debe ser 'stretch' o 'content'")
|
|
133
|
+
if mode not in {"raw_visual", "visual"}:
|
|
134
|
+
raise ValueError("mode debe ser 'raw_visual' o 'visual'")
|
|
135
|
+
if save_mode not in {"auto", "button"}:
|
|
136
|
+
raise ValueError("save_mode debe ser 'auto' o 'button'")
|
|
137
|
+
if not isinstance(only_view, bool):
|
|
138
|
+
raise TypeError("only_view debe ser bool")
|
|
139
|
+
if not isinstance(debug_blocks, bool):
|
|
140
|
+
raise TypeError("debug_blocks debe ser bool")
|
|
141
|
+
choices = {
|
|
142
|
+
"editor_modes": (editor_modes, {"raw_visual", "visual"}, True),
|
|
143
|
+
"review_modes": (review_modes, {"visual", "markdown"}, True),
|
|
144
|
+
"review_layouts": (review_layouts, {"before", "after", "split", "blocks"}, True),
|
|
145
|
+
"toolbar_sections": (toolbar_sections, {"view", "format", "block", "history", "changes"}, False),
|
|
146
|
+
}
|
|
147
|
+
for name, (values, allowed, required) in choices.items():
|
|
148
|
+
if not isinstance(values, Sequence) or isinstance(values, (str, bytes)):
|
|
149
|
+
raise TypeError(f"{name} debe ser una secuencia de opciones")
|
|
150
|
+
if (required and not values) or any(not isinstance(value, str) or value not in allowed for value in values):
|
|
151
|
+
raise ValueError(f"{name}: opciones válidas {sorted(allowed)}" + ("; elige al menos una" if required else ""))
|
|
152
|
+
if len(set(values)) != len(values):
|
|
153
|
+
raise ValueError(f"{name} no puede incluir opciones duplicadas")
|
|
154
|
+
if mode not in editor_modes:
|
|
155
|
+
raise ValueError("mode debe estar incluido en editor_modes")
|
|
156
|
+
if block_diff_style not in {"content", "inline"}:
|
|
157
|
+
raise ValueError("block_diff_style debe ser 'content' o 'inline'")
|
|
158
|
+
if not isinstance(placeholder, str):
|
|
159
|
+
raise TypeError("placeholder debe ser str")
|
|
160
|
+
if not isinstance(show_copy_button, bool):
|
|
161
|
+
raise TypeError("show_copy_button debe ser bool")
|
|
162
|
+
if not isinstance(show_status_bar, bool):
|
|
163
|
+
raise TypeError("show_status_bar debe ser bool")
|
|
164
|
+
normalized_diff = _normalize_diff(diff)
|
|
165
|
+
|
|
166
|
+
blocks = _normalize_blocks(initial_blocks)
|
|
167
|
+
renderer_bundle = _ASSET_DIR / "renderers.bundle.js"
|
|
168
|
+
if not renderer_bundle.is_file():
|
|
169
|
+
raise RuntimeError(
|
|
170
|
+
"Falta el bundle de renderizadores: ejecuta npm install y npm run build "
|
|
171
|
+
"en markdown_editor\\frontend"
|
|
172
|
+
)
|
|
173
|
+
editor = create_component(
|
|
174
|
+
name="markdown_block_editor",
|
|
175
|
+
html=(_ASSET_DIR / "editor.html").read_text(encoding="utf-8"),
|
|
176
|
+
css=(_ASSET_DIR / "editor.css").read_text(encoding="utf-8"),
|
|
177
|
+
js=(
|
|
178
|
+
renderer_bundle.read_text(encoding="utf-8")
|
|
179
|
+
+ "\n"
|
|
180
|
+
+ (_ASSET_DIR / "editor.js").read_text(encoding="utf-8")
|
|
181
|
+
),
|
|
182
|
+
isolate_styles=False,
|
|
183
|
+
)
|
|
184
|
+
state = editor(
|
|
185
|
+
key=key,
|
|
186
|
+
data={
|
|
187
|
+
"blocks": blocks,
|
|
188
|
+
"revision": revision,
|
|
189
|
+
"mode": mode,
|
|
190
|
+
"save_mode": save_mode,
|
|
191
|
+
"only_view": only_view,
|
|
192
|
+
"debug_blocks": debug_blocks,
|
|
193
|
+
"height": height,
|
|
194
|
+
"diff": normalized_diff,
|
|
195
|
+
"editor_modes": list(editor_modes),
|
|
196
|
+
"review_modes": list(review_modes),
|
|
197
|
+
"review_layouts": list(review_layouts),
|
|
198
|
+
"block_diff_style": block_diff_style,
|
|
199
|
+
"placeholder": placeholder,
|
|
200
|
+
"show_copy_button": show_copy_button,
|
|
201
|
+
"show_status_bar": show_status_bar,
|
|
202
|
+
"toolbar_sections": list(toolbar_sections),
|
|
203
|
+
},
|
|
204
|
+
width="stretch",
|
|
205
|
+
height=height if height is not None else 760,
|
|
206
|
+
).get("value")
|
|
207
|
+
return _document_from_state(state, blocks, mode=mode, save_mode=save_mode)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
__all__ = ["st_markdown_block_editor"]
|