refactor: extract block hover state types
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
//! Block hover / block menu / drop indicator 共享状态类型定义。
|
||||
//!
|
||||
//! 本模块只承接共享状态类型,不承接 Leptos signal、DOM listener、host bridge
|
||||
//! 或 editor command。类型字段使用 `pub(crate)` 以支持跨模块访问,保持结构
|
||||
//! 和语义同构。
|
||||
|
||||
/// Hovered block 的共享状态:索引、类型标签、位置和高度。
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub(crate) struct HoveredBlockState {
|
||||
pub(crate) index: usize,
|
||||
pub(crate) label: String,
|
||||
pub(crate) top: f64,
|
||||
pub(crate) height: f64,
|
||||
}
|
||||
|
||||
/// Block menu 弹出面板的布局参数:最大高度、展开方向、位置。
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub(crate) struct BlockMenuLayout {
|
||||
pub(crate) max_height: f64,
|
||||
pub(crate) open_upward: bool,
|
||||
pub(crate) top: f64,
|
||||
pub(crate) left: f64,
|
||||
}
|
||||
|
||||
/// 拖拽放置方向:目标块之前或之后。
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum DropPlacement {
|
||||
Before,
|
||||
After,
|
||||
}
|
||||
|
||||
/// 拖拽指示器的显示状态:目标索引、位置和放置方向。
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub(crate) struct DropIndicatorState {
|
||||
pub(crate) index: usize,
|
||||
pub(crate) top: f64,
|
||||
pub(crate) placement: DropPlacement,
|
||||
}
|
||||
|
||||
/// 拖拽待确认状态:记录开始拖拽时的索引、锚点和起始坐标。
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub(crate) struct PendingDragState {
|
||||
pub(crate) index: usize,
|
||||
pub(crate) anchor: HoveredBlockState,
|
||||
pub(crate) start_x: i32,
|
||||
pub(crate) start_y: i32,
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use serde_json::{json, Value};
|
||||
|
||||
use crate::DropPlacement;
|
||||
use crate::editor_runtime::block_hover_state::DropPlacement;
|
||||
|
||||
fn document_content_mut(document: &mut Value) -> Result<&mut Vec<Value>, String> {
|
||||
document
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
use wasm_bindgen::JsCast;
|
||||
use web_sys::{window, Element};
|
||||
|
||||
use crate::DropPlacement;
|
||||
use crate::editor_runtime::block_hover_state::DropPlacement;
|
||||
|
||||
/// 复制第 `index` 个顶层 HTML 块并插入其后。
|
||||
///
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
pub(crate) mod attachment_links;
|
||||
pub(crate) mod attachment_upload;
|
||||
pub(crate) mod block_hover_state;
|
||||
pub(crate) mod block_menu_document;
|
||||
pub(crate) mod block_menu_legacy_html;
|
||||
pub(crate) mod command_sync;
|
||||
|
||||
@@ -24,6 +24,9 @@ use editor_runtime::attachment_upload::dispatch_editor_upload_request;
|
||||
use editor_runtime::block_menu_legacy_html::{
|
||||
duplicate_top_level_block_html, reorder_top_level_block_html,
|
||||
};
|
||||
use editor_runtime::block_hover_state::{
|
||||
BlockMenuLayout, DropIndicatorState, DropPlacement, HoveredBlockState, PendingDragState,
|
||||
};
|
||||
use editor_runtime::command_sync::{
|
||||
read_editor_snapshot, sync_editor_outputs, sync_persisted_editor_command,
|
||||
};
|
||||
@@ -4783,14 +4786,6 @@ fn build_command_listener(mount_id: u32) -> Closure<dyn FnMut(Event)> {
|
||||
}))
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
struct HoveredBlockState {
|
||||
index: usize,
|
||||
label: String,
|
||||
top: f64,
|
||||
height: f64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
struct ImageToolbarAnchor {
|
||||
top: f64,
|
||||
@@ -4829,35 +4824,6 @@ struct TableSelectionOverlayState {
|
||||
index: usize,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
struct BlockMenuLayout {
|
||||
max_height: f64,
|
||||
open_upward: bool,
|
||||
top: f64,
|
||||
left: f64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum DropPlacement {
|
||||
Before,
|
||||
After,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
struct DropIndicatorState {
|
||||
index: usize,
|
||||
top: f64,
|
||||
placement: DropPlacement,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
struct PendingDragState {
|
||||
index: usize,
|
||||
anchor: HoveredBlockState,
|
||||
start_x: i32,
|
||||
start_y: i32,
|
||||
}
|
||||
|
||||
fn default_title() -> String {
|
||||
"Leptos Tiptap 主编辑器 P0".to_string()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user