refactor: extract editor upload intent

This commit is contained in:
lix-2026
2026-05-24 23:24:38 +08:00
parent b4c74bbb81
commit 5a96ea9eba
7 changed files with 74 additions and 23 deletions
@@ -1284,7 +1284,7 @@ function __wbg_get_imports() {
return ret;
},
__wbindgen_cast_0000000000000006: function(arg0, arg1) {
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("KeyboardEvent")], shim_idx: 758, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("KeyboardEvent")], shim_idx: 745, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__hd90af689bc3e71bf);
return ret;
},
@@ -0,0 +1,21 @@
use serde_json::json;
use web_sys::{window, CustomEvent, CustomEventInit};
pub(crate) fn dispatch_editor_upload_request(kind: &str, accept: &str) -> Result<(), String> {
let win = window().ok_or_else(|| "当前浏览器窗口不可用".to_string())?;
let detail = json!({
"kind": kind,
"accept": accept,
"multiple": true,
"insertIntoEditor": true,
});
let detail =
serde_wasm_bindgen::to_value(&detail).map_err(|err| format!("构造上传请求失败:{err}"))?;
let init = CustomEventInit::new();
init.set_detail(&detail);
let event = CustomEvent::new_with_event_init_dict("mnote:editor-upload-request", &init)
.map_err(|_| "构造上传事件失败".to_string())?;
win.dispatch_event(&event)
.map(|_| ())
.map_err(|_| "派发上传事件失败".to_string())
}
@@ -1,4 +1,5 @@
pub(crate) mod attachment_links;
pub(crate) mod attachment_upload;
pub(crate) mod command_sync;
pub(crate) mod history_safe_commands;
pub(crate) mod persistence;
+1 -19
View File
@@ -20,6 +20,7 @@ use web_sys::{
HtmlInputElement, MouseEvent, Node, RequestInit, RequestMode, Response, WheelEvent,
};
use editor_runtime::attachment_upload::dispatch_editor_upload_request;
use editor_runtime::command_sync::{
read_editor_snapshot, sync_editor_outputs, sync_persisted_editor_command,
};
@@ -7134,25 +7135,6 @@ fn table_option_checked(document: &Value, action: TableOptionAction) -> bool {
}
}
fn dispatch_editor_upload_request(kind: &str, accept: &str) -> Result<(), String> {
let win = window().ok_or_else(|| "当前浏览器窗口不可用".to_string())?;
let detail = json!({
"kind": kind,
"accept": accept,
"multiple": true,
"insertIntoEditor": true,
});
let detail =
serde_wasm_bindgen::to_value(&detail).map_err(|err| format!("构造上传请求失败:{err}"))?;
let init = CustomEventInit::new();
init.set_detail(&detail);
let event = CustomEvent::new_with_event_init_dict("mnote:editor-upload-request", &init)
.map_err(|_| "构造上传事件失败".to_string())?;
win.dispatch_event(&event)
.map(|_| ())
.map_err(|_| "派发上传事件失败".to_string())
}
fn run_slash_action(
editor: TiptapEditorHandle,
action: SlashActionKind,