refactor: split document resource tab runtime
This commit is contained in:
@@ -2806,7 +2806,7 @@ mod tests {
|
||||
r#"<script type="module" src="/api/mnote-browser-runtime/document-editor-adapter-runtime.js"></script>"#
|
||||
));
|
||||
assert!(
|
||||
include_str!("../../browser/document-editor-adapter-runtime.js")
|
||||
include_str!("../../browser/document-resource-tab-runtime.js")
|
||||
.contains("openResourceInActiveTab")
|
||||
);
|
||||
assert!(!html.contains(r#"<script id="__MNOTE_PAGE_AGGREGATE__""#));
|
||||
|
||||
@@ -150,6 +150,10 @@ pub fn build_router(state: AppState) -> Router {
|
||||
"/api/mnote-browser-runtime/document-mindmap-host-runtime.js",
|
||||
get(web_shell::document_mindmap_host_runtime_asset),
|
||||
)
|
||||
.route(
|
||||
"/api/mnote-browser-runtime/document-resource-tab-runtime.js",
|
||||
get(web_shell::document_resource_tab_runtime_asset),
|
||||
)
|
||||
.route(
|
||||
"/api/mnote-browser-runtime/document-slash-position-runtime.js",
|
||||
get(web_shell::document_slash_position_runtime_asset),
|
||||
@@ -577,6 +581,7 @@ mod tests {
|
||||
"/api/mnote-browser-runtime/document-conflict-panel-runtime.js",
|
||||
"/api/mnote-browser-runtime/document-pane-runtime.js",
|
||||
"/api/mnote-browser-runtime/document-mindmap-host-runtime.js",
|
||||
"/api/mnote-browser-runtime/document-resource-tab-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",
|
||||
|
||||
@@ -883,6 +883,20 @@ pub async fn document_mindmap_host_runtime_asset() -> Response {
|
||||
.unwrap_or_else(|_| Response::new(Body::empty()))
|
||||
}
|
||||
|
||||
pub async fn document_resource_tab_runtime_asset() -> Response {
|
||||
const JS: &str = include_str!("../../browser/document-resource-tab-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_slash_position_runtime_asset() -> Response {
|
||||
const JS: &str = include_str!("../../browser/document-slash-position-runtime.js");
|
||||
Response::builder()
|
||||
@@ -1337,6 +1351,8 @@ mod tests {
|
||||
const DOCUMENT_MINDMAP_HOST_RUNTIME_JS: &str =
|
||||
include_str!("../../browser/document-mindmap-host-runtime.js");
|
||||
const DOCUMENT_PANE_RUNTIME_JS: &str = include_str!("../../browser/document-pane-runtime.js");
|
||||
const DOCUMENT_RESOURCE_TAB_RUNTIME_JS: &str =
|
||||
include_str!("../../browser/document-resource-tab-runtime.js");
|
||||
const DOCUMENT_SLASH_POSITION_RUNTIME_JS: &str =
|
||||
include_str!("../../browser/document-slash-position-runtime.js");
|
||||
const DOCUMENT_TIPTAP_CONVERSION_RUNTIME_JS: &str =
|
||||
@@ -1581,17 +1597,18 @@ mod tests {
|
||||
assert!(runtime.contains("pageTab.setAttribute('data-document-id', documentId);"));
|
||||
assert!(html.contains("data-mnote-tab-badge-kind"));
|
||||
assert!(html.contains(r#"<script type="module" src="/api/mnote-browser-runtime/document-editor-adapter-runtime.js"></script>"#));
|
||||
let runtime = DOCUMENT_EDITOR_ADAPTER_RUNTIME_JS;
|
||||
assert!(runtime.contains("resourceTabBadgeKind(input, kind)"));
|
||||
assert!(runtime.contains("mnote.open_editors_snapshot.v1"));
|
||||
let resource_runtime = DOCUMENT_RESOURCE_TAB_RUNTIME_JS;
|
||||
assert!(runtime.contains("document-resource-tab-runtime.js"));
|
||||
assert!(resource_runtime.contains("resourceTabBadgeKind(input, kind)"));
|
||||
assert!(resource_runtime.contains("mnote.open_editors_snapshot.v1"));
|
||||
assert!(runtime.contains("getOpenEditorsSnapshot"));
|
||||
assert!(runtime.contains("bindMainEditorTabStrip"));
|
||||
assert!(runtime.contains("data-mnote-tab-strip-bound"));
|
||||
assert!(resource_runtime.contains("bindMainEditorTabStrip"));
|
||||
assert!(resource_runtime.contains("data-mnote-tab-strip-bound"));
|
||||
assert!(runtime.contains("currentWebShellDocumentId"));
|
||||
assert!(runtime.contains(
|
||||
assert!(resource_runtime.contains(
|
||||
"const documentId = String(entry?.ownerDocumentId || entry?.documentId || '').trim();"
|
||||
));
|
||||
assert!(runtime.contains(
|
||||
assert!(resource_runtime.contains(
|
||||
"if (documentId) url.pathname = `/documents/${encodeURIComponent(documentId)}`;"
|
||||
));
|
||||
assert!(!html
|
||||
@@ -1618,11 +1635,11 @@ mod tests {
|
||||
assert!(
|
||||
runtime.contains("runtimeDescriptor.root.addEventListener(STATE_EVENT, view.onState);")
|
||||
);
|
||||
assert!(runtime.contains("data-mnote-resource-tab-host"));
|
||||
assert!(html.contains("data-mnote-resource-tab-host"));
|
||||
assert!(runtime.contains("openPrimaryMindmap"));
|
||||
assert!(runtime.contains("openResourceInActiveTab"));
|
||||
assert!(runtime.contains("/api/local-folder/resource/read"));
|
||||
assert!(runtime.contains("/api/local-folder/resource/write"));
|
||||
assert!(resource_runtime.contains("/api/local-folder/resource/read"));
|
||||
assert!(resource_runtime.contains("/api/local-folder/resource/write"));
|
||||
let mindmap_runtime = DOCUMENT_MINDMAP_HOST_RUNTIME_JS;
|
||||
assert!(mindmap_runtime.contains("replacePrimaryPaneMindmap"));
|
||||
assert!(mindmap_runtime.contains("__MNOTE_MINDMAP_EDITOR_BOOTSTRAP__"));
|
||||
@@ -1655,29 +1672,30 @@ mod tests {
|
||||
assert!(!runtime.contains("mnote-web-document-shell"));
|
||||
|
||||
// Resource open resolver contract
|
||||
assert!(runtime.contains("normalizeResourceTabKind"));
|
||||
assert!(runtime.contains("data-resource-tab-error"));
|
||||
assert!(runtime.contains("resourceTabCloseGuardReason"));
|
||||
assert!(runtime.contains("closeResourceTab"));
|
||||
assert!(runtime.contains("resourceTabRegistry.delete(key)"));
|
||||
assert!(resource_runtime.contains("normalizeResourceTabKind"));
|
||||
assert!(resource_runtime.contains("data-resource-tab-error"));
|
||||
assert!(resource_runtime.contains("resourceTabCloseGuardReason"));
|
||||
assert!(resource_runtime.contains("closeResourceTab"));
|
||||
assert!(resource_runtime.contains("resourceTabRegistry.delete(key)"));
|
||||
assert!(runtime.contains("data-testid=\"mnote-secondary-editor-tab-host\""));
|
||||
assert!(html.contains("data-testid=\"mnote-secondary-resource-tab-host\""));
|
||||
assert!(runtime.contains("resourceTabRegistryKey(paneRole, objectIdentity)"));
|
||||
assert!(resource_runtime.contains("resourceTabRegistryKey(paneRole, objectIdentity)"));
|
||||
assert!(runtime.contains("openResourceInActiveTab({ ...input, paneRole: 'secondary'"));
|
||||
assert!(runtime.contains("data-mnote-editor-kind=\"resource\""));
|
||||
assert!(runtime.contains("const paneRole = normalizePaneRole(entry.paneRole);"));
|
||||
assert!(runtime.contains("paneRole,"));
|
||||
assert!(runtime.contains("markIntendedSlashRoot(entry);"));
|
||||
assert!(runtime.contains("if (activeEntry) markIntendedSlashRoot(activeEntry);"));
|
||||
assert!(runtime.contains("const nextKey = lastActiveResourceTabKey(role);"));
|
||||
assert!(runtime.contains("if (nextTab instanceof HTMLElement) nextTab.focus();"));
|
||||
assert!(runtime.contains("resourceTabBadgeKind(input, kind)"));
|
||||
assert!(runtime.contains("const refreshExistingOfficeResourceTab = (entry, input) =>"));
|
||||
assert!(runtime.contains("if (!entry || entry.kind !== 'office') return false;"));
|
||||
assert!(resource_runtime.contains("data-mnote-editor-kind=\"resource\""));
|
||||
assert!(resource_runtime.contains("const paneRole = normalizePaneRole(entry.paneRole);"));
|
||||
assert!(resource_runtime.contains("paneRole,"));
|
||||
assert!(resource_runtime.contains("markIntendedSlashRoot(entry);"));
|
||||
assert!(resource_runtime.contains("if (activeEntry) markIntendedSlashRoot(activeEntry);"));
|
||||
assert!(resource_runtime.contains("const nextKey = lastActiveResourceTabKey(role);"));
|
||||
assert!(resource_runtime.contains("if (nextTab instanceof HTMLElement) nextTab.focus();"));
|
||||
assert!(resource_runtime.contains("resourceTabBadgeKind(input, kind)"));
|
||||
assert!(
|
||||
runtime.contains("if (currentHref !== nextHref) openPassiveResourceTab(entry, input);")
|
||||
resource_runtime.contains("const refreshExistingOfficeResourceTab = (entry, input) =>")
|
||||
);
|
||||
assert!(runtime.contains("refreshExistingOfficeResourceTab(existing, input);"));
|
||||
assert!(resource_runtime.contains("if (!entry || entry.kind !== 'office') return false;"));
|
||||
assert!(resource_runtime
|
||||
.contains("if (currentHref !== nextHref) openPassiveResourceTab(entry, input);"));
|
||||
assert!(resource_runtime.contains("refreshExistingOfficeResourceTab(existing, input);"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -2098,6 +2116,10 @@ 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-resource-tab-runtime.js"));
|
||||
assert!(DOCUMENT_RESOURCE_TAB_RUNTIME_JS.contains("openResourceInActiveTab"));
|
||||
assert!(DOCUMENT_RESOURCE_TAB_RUNTIME_JS.contains("buildOpenEditorsSnapshot"));
|
||||
assert!(DOCUMENT_RESOURCE_TAB_RUNTIME_JS.contains("bindMainEditorTabStrip"));
|
||||
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"));
|
||||
|
||||
Reference in New Issue
Block a user