refactor: split sidebar shell runtime
This commit is contained in:
@@ -122,6 +122,10 @@ pub fn build_router(state: AppState) -> Router {
|
||||
"/api/mnote-browser-runtime/filetree-keyboard-runtime.js",
|
||||
get(web_shell::filetree_keyboard_runtime_asset),
|
||||
)
|
||||
.route(
|
||||
"/api/mnote-browser-runtime/sidebar-shell-runtime.js",
|
||||
get(web_shell::sidebar_shell_runtime_asset),
|
||||
)
|
||||
.route(
|
||||
"/api/mnote-browser-runtime/sidebar-tree-runtime.js",
|
||||
get(web_shell::sidebar_tree_runtime_asset),
|
||||
@@ -544,6 +548,10 @@ mod tests {
|
||||
"/api/mnote-browser-runtime/filetree-runtime.js",
|
||||
"/api/mnote-browser-runtime/filetree-selection-runtime.js",
|
||||
"/api/mnote-browser-runtime/filetree-context-menu-runtime.js",
|
||||
"/api/mnote-browser-runtime/filetree-dnd-runtime.js",
|
||||
"/api/mnote-browser-runtime/filetree-keyboard-runtime.js",
|
||||
"/api/mnote-browser-runtime/sidebar-shell-runtime.js",
|
||||
"/api/mnote-browser-runtime/sidebar-tree-runtime.js",
|
||||
"/api/mnote-browser-runtime/tree-live-controller.js",
|
||||
"/api/mnote-browser-runtime/tree-shell-runtime.js",
|
||||
"/api/mnote-browser-runtime/document-conflict-panel-runtime.js",
|
||||
|
||||
@@ -4516,6 +4516,20 @@ pub async fn sidebar_tree_runtime_asset() -> Response {
|
||||
.unwrap_or_else(|_| Response::new(Body::empty()))
|
||||
}
|
||||
|
||||
pub async fn sidebar_shell_runtime_asset() -> Response {
|
||||
const JS: &str = include_str!("../../browser/sidebar-shell-runtime.js");
|
||||
Response::builder()
|
||||
.status(StatusCode::OK)
|
||||
.header(
|
||||
header::CONTENT_TYPE,
|
||||
"application/javascript; charset=utf-8",
|
||||
)
|
||||
.header(header::CACHE_CONTROL, "no-store")
|
||||
.header(HEADER_MNOTE_WEB_OWNER, "mnote-web")
|
||||
.body(Body::from(JS))
|
||||
.unwrap_or_else(|_| Response::new(Body::empty()))
|
||||
}
|
||||
|
||||
pub async fn filetree_keyboard_runtime_asset() -> Response {
|
||||
const JS: &str = include_str!("../../browser/filetree-keyboard-runtime.js");
|
||||
Response::builder()
|
||||
|
||||
@@ -157,6 +157,7 @@ pub fn PageLayout(
|
||||
<script type="module" src="/api/mnote-browser-runtime/filetree-context-menu-runtime.js"></script>
|
||||
<script type="module" src="/api/mnote-browser-runtime/filetree-dnd-runtime.js"></script>
|
||||
<script type="module" src="/api/mnote-browser-runtime/filetree-keyboard-runtime.js"></script>
|
||||
<script type="module" src="/api/mnote-browser-runtime/sidebar-shell-runtime.js"></script>
|
||||
<script type="module" src="/api/mnote-browser-runtime/sidebar-tree-runtime.js"></script>
|
||||
<script inner_html={SIDEBAR_TREE_JS.to_string()}></script>
|
||||
<script type="module" src="/api/mnote-browser-runtime/tree-live-controller.js"></script>
|
||||
@@ -198,6 +199,8 @@ pub fn PageLayout(
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
const SIDEBAR_TREE_RUNTIME_JS: &str = include_str!("../../../browser/sidebar-tree-runtime.js");
|
||||
const SIDEBAR_SHELL_RUNTIME_JS: &str =
|
||||
include_str!("../../../browser/sidebar-shell-runtime.js");
|
||||
const FILETREE_CONTEXT_MENU_RUNTIME_JS: &str =
|
||||
include_str!("../../../browser/filetree-context-menu-runtime.js");
|
||||
const FILETREE_DND_RUNTIME_JS: &str = include_str!("../../../browser/filetree-dnd-runtime.js");
|
||||
@@ -430,7 +433,12 @@ mod tests {
|
||||
#[test]
|
||||
fn page_layout_sidebar_toggle_is_wired_to_shell_state() {
|
||||
assert!(SIDEBAR_TREE_RUNTIME_JS.contains("function toggleWorkspaceSidebar"));
|
||||
assert!(SIDEBAR_TREE_RUNTIME_JS.contains("data-mnote-sidebar-collapsed"));
|
||||
assert!(SIDEBAR_TREE_RUNTIME_JS
|
||||
.contains("sidebarShellRuntimeFunction('toggleWorkspaceSidebar')"));
|
||||
assert!(SIDEBAR_SHELL_RUNTIME_JS.contains("function toggleWorkspaceSidebar"));
|
||||
assert!(SIDEBAR_SHELL_RUNTIME_JS.contains("data-mnote-sidebar-collapsed"));
|
||||
assert!(SIDEBAR_SHELL_RUNTIME_JS.contains("function installWorkspaceSidebarResizer"));
|
||||
assert!(SIDEBAR_SHELL_RUNTIME_JS.contains("function restoreSidebarTreeTab"));
|
||||
assert!(SIDEBAR_TREE_RUNTIME_JS.contains("[data-mnote-action=\"toggle-sidebar\"]"));
|
||||
}
|
||||
|
||||
@@ -805,9 +813,15 @@ mod tests {
|
||||
#[test]
|
||||
fn sidebar_runtime_supports_resizable_filetree_and_hover_titles() {
|
||||
assert!(SIDEBAR_TREE_RUNTIME_JS.contains("function installWorkspaceSidebarResizer()"));
|
||||
assert!(SIDEBAR_TREE_RUNTIME_JS.contains("data-mnote-sidebar-resizer"));
|
||||
assert!(SIDEBAR_TREE_RUNTIME_JS.contains("mnote.workspace.sidebarWidth.v1"));
|
||||
assert!(SIDEBAR_TREE_RUNTIME_JS.contains("shell.style.setProperty('--mnote-sidebar-width'"));
|
||||
assert!(SIDEBAR_TREE_RUNTIME_JS
|
||||
.contains("sidebarShellRuntimeFunction('installWorkspaceSidebarResizer')"));
|
||||
assert!(SIDEBAR_SHELL_RUNTIME_JS.contains("data-mnote-sidebar-resizer"));
|
||||
assert!(SIDEBAR_SHELL_RUNTIME_JS.contains("mnote.workspace.sidebarWidth.v1"));
|
||||
assert!(
|
||||
SIDEBAR_SHELL_RUNTIME_JS.contains("shell.style.setProperty('--mnote-sidebar-width'")
|
||||
);
|
||||
assert!(FILETREE_DND_RUNTIME_JS.contains("window.__mnoteFileTreeDndRuntime"));
|
||||
assert!(FILETREE_KEYBOARD_RUNTIME_JS.contains("window.__mnoteFileTreeKeyboardRuntime"));
|
||||
assert!(SIDEBAR_TREE_RUNTIME_JS.contains("installWorkspaceSidebarResizer();"));
|
||||
assert!(SIDEBAR_TREE_RUNTIME_JS.contains(r#"" title="' + escapeHtml(title) + '""#));
|
||||
assert!(SIDEBAR_TREE_RUNTIME_JS
|
||||
|
||||
Reference in New Issue
Block a user