-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add heading links to markdown parser
- Loading branch information
Showing
4 changed files
with
88 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
|
||
import dash | ||
import dash_bootstrap_components as dbc | ||
from dash import html | ||
from dash import ClientsideFunction, Input, Output, html | ||
from jinja2 import Environment, FileSystemLoader | ||
|
||
from .components.table.simple import table_body, table_header # noqa | ||
|
@@ -18,6 +18,22 @@ | |
|
||
LOREM = (COMPONENTS / "modal" / "lorem.txt").read_text().strip() | ||
|
||
CLIENTSIDE_CALLBACK = """ | ||
if (!window.dash_clientside) { | ||
window.dash_clientside = {}; | ||
} | ||
window.dash_clientside.clientside = { | ||
make_draggable: function(id) { | ||
setTimeout(function() { | ||
var el = document.getElementById(id) | ||
window.console.log(el) | ||
dragula([el]) | ||
}, 1) | ||
return window.dash_clientside.no_update | ||
} | ||
} | ||
""" | ||
|
||
HIGHLIGHT_JS_CSS = ( | ||
"https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/" | ||
"build/styles/monokai-sublime.min.css" | ||
|
@@ -149,6 +165,7 @@ def register_apps(): | |
) | ||
app = dash.Dash( | ||
external_stylesheets=["/static/loading.css"], | ||
external_scripts=["/static/js/clientside.js"], | ||
requests_pathname_prefix=requests_pathname_prefix, | ||
suppress_callback_exceptions=True, | ||
serve_locally=SERVE_LOCALLY, | ||
|
@@ -171,6 +188,17 @@ def register_apps(): | |
) | ||
else: | ||
app.layout = parse(app, **kwargs) | ||
|
||
app.clientside_callback( | ||
ClientsideFunction( | ||
namespace="clientside", function_name="scrollAfterLoad" | ||
), | ||
# id won't actually be updated, we just want the callback to run | ||
# once Dash has initialised and hydrated the page | ||
Output("url", "id"), | ||
Input("url", "hash"), | ||
) | ||
|
||
if slug == "index": | ||
routes["/docs/components"] = app | ||
else: | ||
|
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,22 @@ | ||
const delays = [100, 100, 300, 500, 1000, 2000]; | ||
|
||
function scrollWithRetry(id, idx) { | ||
const targetElement = document.getElementById(id); | ||
if (targetElement) { | ||
targetElement.scrollIntoView(); | ||
} else if (idx < delays.length) { | ||
setTimeout(() => scrollWithRetry(id, idx + 1), delays[idx]); | ||
} | ||
} | ||
|
||
if (!window.dash_clientside) { | ||
window.dash_clientside = {}; | ||
} | ||
window.dash_clientside.clientside = { | ||
scrollAfterLoad: function(hash) { | ||
if (hash) { | ||
scrollWithRetry(hash.slice(1), 0); | ||
} | ||
return window.dash_clientside.no_update; | ||
} | ||
}; |