fix(bridge): read window.TiptapEditor via Reflect.get, not function call
The extern 'fn get_module() -> TiptapEditorModule' was compiled by wasm-bindgen to 'window.TiptapEditor()' — a function call. But TiptapEditor is the IIFE module object, not a function, so this threw 'window.TiptapEditor is not a function'. Replace with js_sys::Reflect::get(&window, "TiptapEditor") + dyn_into, which reads the property without invoking it. This bug predated the Vite 8 upgrade but only surfaced after the EditorOptions fix let initialization progress further.
This commit is contained in:
parent
fb31ecb5ae
commit
410d594ac0
@ -35,14 +35,15 @@ pub mod wasm {
|
|||||||
use wasm_bindgen::JsCast;
|
use wasm_bindgen::JsCast;
|
||||||
|
|
||||||
// —— window.TiptapEditor 模块对象 ——
|
// —— window.TiptapEditor 模块对象 ——
|
||||||
|
//
|
||||||
|
// TiptapEditor 是 IIFE 产物挂在 window 上的模块对象(含 create 等方法),
|
||||||
|
// 不是函数。wasm-bindgen 对 `fn get_module() -> T` 形式的 extern 会生成
|
||||||
|
// `window.TiptapEditor()`(函数调用),会因"not a function"失败。
|
||||||
|
// 因此用 js_sys::Reflect::get 做属性访问拿到模块对象,再 dyn_into。
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub type TiptapEditorModule;
|
pub type TiptapEditorModule;
|
||||||
|
|
||||||
/// 读取 `window.TiptapEditor`(IIFE 默认导出,顶层 var 即 window 属性)。
|
|
||||||
#[wasm_bindgen(js_namespace = window, js_name = TiptapEditor)]
|
|
||||||
pub fn get_module() -> TiptapEditorModule;
|
|
||||||
|
|
||||||
/// 调用 `TiptapEditor.create(containerId, options)`。
|
/// 调用 `TiptapEditor.create(containerId, options)`。
|
||||||
/// 找不到容器返回 null(被 Option 捕获);构造失败抛异常(被 catch 捕获)。
|
/// 找不到容器返回 null(被 Option 捕获);构造失败抛异常(被 catch 捕获)。
|
||||||
#[wasm_bindgen(method, catch)]
|
#[wasm_bindgen(method, catch)]
|
||||||
@ -53,6 +54,15 @@ pub mod wasm {
|
|||||||
) -> Result<Option<EditorInstance>, JsValue>;
|
) -> Result<Option<EditorInstance>, JsValue>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 读取 `window.TiptapEditor`(IIFE 默认导出,顶层 var 即 window 属性)。
|
||||||
|
/// 用 Reflect::get 做属性访问——extern fn 形式会被 wasm-bindgen 编成函数调用。
|
||||||
|
pub fn get_module() -> TiptapEditorModule {
|
||||||
|
let window = web_sys::window().expect("no window");
|
||||||
|
let val = js_sys::Reflect::get(&window, &"TiptapEditor".into()).expect("window.TiptapEditor missing");
|
||||||
|
val.dyn_into::<TiptapEditorModule>()
|
||||||
|
.expect("window.TiptapEditor is not TiptapEditorModule")
|
||||||
|
}
|
||||||
|
|
||||||
// —— 编辑器实例(TiptapEditorInstance)——
|
// —— 编辑器实例(TiptapEditorInstance)——
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user