refactor: split document slash positioning runtime
This commit is contained in:
@@ -146,6 +146,10 @@ pub fn build_router(state: AppState) -> Router {
|
||||
"/api/mnote-browser-runtime/document-pane-runtime.js",
|
||||
get(web_shell::document_pane_runtime_asset),
|
||||
)
|
||||
.route(
|
||||
"/api/mnote-browser-runtime/document-slash-position-runtime.js",
|
||||
get(web_shell::document_slash_position_runtime_asset),
|
||||
)
|
||||
.route(
|
||||
"/api/mnote-browser-runtime/document-tiptap-conversion-runtime.js",
|
||||
get(web_shell::document_tiptap_conversion_runtime_asset),
|
||||
@@ -568,6 +572,7 @@ mod tests {
|
||||
"/api/mnote-browser-runtime/tree-shell-runtime.js",
|
||||
"/api/mnote-browser-runtime/document-conflict-panel-runtime.js",
|
||||
"/api/mnote-browser-runtime/document-pane-runtime.js",
|
||||
"/api/mnote-browser-runtime/document-slash-position-runtime.js",
|
||||
"/api/mnote-browser-runtime/document-tiptap-conversion-runtime.js",
|
||||
"/api/mnote-browser-runtime/document-editor-adapter-runtime.js",
|
||||
] {
|
||||
|
||||
@@ -869,6 +869,20 @@ pub async fn document_pane_runtime_asset() -> Response {
|
||||
.unwrap_or_else(|_| Response::new(Body::empty()))
|
||||
}
|
||||
|
||||
pub async fn document_slash_position_runtime_asset() -> Response {
|
||||
const JS: &str = include_str!("../../browser/document-slash-position-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 document_tiptap_conversion_runtime_asset() -> Response {
|
||||
const JS: &str = include_str!("../../browser/document-tiptap-conversion-runtime.js");
|
||||
Response::builder()
|
||||
@@ -1307,6 +1321,8 @@ mod tests {
|
||||
const DOCUMENT_EDITOR_ADAPTER_RUNTIME_JS: &str =
|
||||
include_str!("../../browser/document-editor-adapter-runtime.js");
|
||||
const DOCUMENT_PANE_RUNTIME_JS: &str = include_str!("../../browser/document-pane-runtime.js");
|
||||
const DOCUMENT_SLASH_POSITION_RUNTIME_JS: &str =
|
||||
include_str!("../../browser/document-slash-position-runtime.js");
|
||||
const DOCUMENT_TIPTAP_CONVERSION_RUNTIME_JS: &str =
|
||||
include_str!("../../browser/document-tiptap-conversion-runtime.js");
|
||||
|
||||
@@ -1565,21 +1581,24 @@ mod tests {
|
||||
assert!(!html
|
||||
.contains("nodes.pageTab?.getAttribute?.('data-document-id') || currentDocumentId()"));
|
||||
assert!(runtime.contains("runtime.default({ module_or_path: wasmUrl })"));
|
||||
assert!(runtime.contains("positionSlashMenuForRoot"));
|
||||
assert!(runtime.contains("setSlashMenuStyle(menu, 'position', 'fixed');"));
|
||||
let slash_runtime = DOCUMENT_SLASH_POSITION_RUNTIME_JS;
|
||||
assert!(slash_runtime.contains("positionSlashMenuForRoot"));
|
||||
assert!(slash_runtime.contains("setSlashMenuStyle(menu, 'position', 'fixed');"));
|
||||
assert!(runtime.contains("installGlobalSlashMenuPositioning();"));
|
||||
assert!(runtime.contains("data-mnote-slash-positioned', 'host'"));
|
||||
assert!(runtime.contains(
|
||||
assert!(slash_runtime.contains("data-mnote-slash-positioned', 'host'"));
|
||||
assert!(slash_runtime.contains(
|
||||
"const menu = root.querySelector('[data-testid=\"mnote-leptos-tiptap-slash-menu\"]');"
|
||||
));
|
||||
assert!(runtime.contains("const setSlashMenuInactive = (menu, inactive) =>"));
|
||||
assert!(runtime.contains("const hideSlashMenusOutsideRoot = (activeRoot) =>"));
|
||||
assert!(runtime.contains("data-mnote-slash-inactive"));
|
||||
assert!(runtime.contains("if (activeRoot instanceof HTMLElement && root !== activeRoot)"));
|
||||
assert!(slash_runtime.contains("const setSlashMenuInactive = (menu, inactive) =>"));
|
||||
assert!(slash_runtime.contains("const hideSlashMenusOutsideRoot = (activeRoot) =>"));
|
||||
assert!(slash_runtime.contains("data-mnote-slash-inactive"));
|
||||
assert!(
|
||||
slash_runtime.contains("if (activeRoot instanceof HTMLElement && root !== activeRoot)")
|
||||
);
|
||||
assert!(!runtime.contains(
|
||||
"|| document.querySelector('[data-testid=\"mnote-leptos-tiptap-slash-menu\"]')"
|
||||
));
|
||||
assert!(runtime.contains("data-mnote-side-target-unsupported') !== 'true'"));
|
||||
assert!(slash_runtime.contains("data-mnote-side-target-unsupported') !== 'true'"));
|
||||
assert!(
|
||||
runtime.contains("runtimeDescriptor.root.addEventListener(STATE_EVENT, view.onState);")
|
||||
);
|
||||
@@ -2059,6 +2078,9 @@ mod tests {
|
||||
assert!(DOCUMENT_EDITOR_ADAPTER_RUNTIME_JS.contains("document-pane-runtime.js"));
|
||||
assert!(DOCUMENT_PANE_RUNTIME_JS.contains("openDocumentInSecondaryPane"));
|
||||
assert!(DOCUMENT_PANE_RUNTIME_JS.contains("buildPaneRuntime"));
|
||||
assert!(DOCUMENT_EDITOR_ADAPTER_RUNTIME_JS.contains("document-slash-position-runtime.js"));
|
||||
assert!(DOCUMENT_SLASH_POSITION_RUNTIME_JS.contains("observeSlashMenuPosition"));
|
||||
assert!(DOCUMENT_SLASH_POSITION_RUNTIME_JS.contains("scheduleSlashMenuPosition"));
|
||||
assert!(
|
||||
DOCUMENT_EDITOR_ADAPTER_RUNTIME_JS.contains("document-tiptap-conversion-runtime.js")
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user