refactor: extract editor overlay close state
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use leptos::prelude::{Set, WriteSignal};
|
||||
|
||||
use crate::{
|
||||
editor_runtime::block_hover_state::HoveredBlockState,
|
||||
editor_runtime::dom_selection::active_editor_text_selection, editor_stage_element,
|
||||
};
|
||||
|
||||
@@ -10,6 +11,44 @@ pub(crate) struct FloatingToolbarAnchor {
|
||||
pub(crate) left: f64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub(crate) struct ImageToolbarAnchor {
|
||||
pub(crate) top: f64,
|
||||
pub(crate) left: f64,
|
||||
pub(crate) align: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub(crate) struct TableOverlayAnchor {
|
||||
pub(crate) top: f64,
|
||||
pub(crate) left: f64,
|
||||
pub(crate) width: f64,
|
||||
pub(crate) height: f64,
|
||||
pub(crate) rows: usize,
|
||||
pub(crate) cols: usize,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum TableSelectionKind {
|
||||
Row,
|
||||
Column,
|
||||
}
|
||||
|
||||
impl TableSelectionKind {
|
||||
pub(crate) fn id(self) -> &'static str {
|
||||
match self {
|
||||
Self::Row => "row",
|
||||
Self::Column => "column",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub(crate) struct TableSelectionOverlayState {
|
||||
pub(crate) kind: TableSelectionKind,
|
||||
pub(crate) index: usize,
|
||||
}
|
||||
|
||||
pub(crate) fn floating_toolbar_anchor_from_selection() -> Option<FloatingToolbarAnchor> {
|
||||
let selection = active_editor_text_selection()?;
|
||||
let range = selection.get_range_at(0).ok()?;
|
||||
@@ -37,3 +76,44 @@ pub(crate) fn sync_text_selection_overlay(
|
||||
set_floating_toolbar_anchor.set(toolbar_anchor);
|
||||
has_text_selection
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn close_editor_floating_overlays(
|
||||
set_slash_open: WriteSignal<bool>,
|
||||
set_slash_index: WriteSignal<usize>,
|
||||
set_slash_query: WriteSignal<String>,
|
||||
set_turn_into_open: WriteSignal<bool>,
|
||||
set_color_menu_open: WriteSignal<bool>,
|
||||
set_more_menu_open: WriteSignal<bool>,
|
||||
set_locked_toolbar_anchor: WriteSignal<Option<FloatingToolbarAnchor>>,
|
||||
set_text_selection_active: WriteSignal<bool>,
|
||||
set_floating_toolbar_anchor: WriteSignal<Option<FloatingToolbarAnchor>>,
|
||||
set_image_toolbar_anchor: WriteSignal<Option<ImageToolbarAnchor>>,
|
||||
set_table_toolbar_open: WriteSignal<bool>,
|
||||
set_table_options_open: WriteSignal<bool>,
|
||||
set_table_overlay_anchor: WriteSignal<Option<TableOverlayAnchor>>,
|
||||
set_table_selection_overlay: WriteSignal<Option<TableSelectionOverlayState>>,
|
||||
set_block_menu_open: WriteSignal<bool>,
|
||||
set_block_menu_anchor: WriteSignal<Option<HoveredBlockState>>,
|
||||
set_block_turn_into_open: WriteSignal<bool>,
|
||||
set_block_folded_title_open: WriteSignal<bool>,
|
||||
) {
|
||||
set_slash_open.set(false);
|
||||
set_slash_index.set(0);
|
||||
set_slash_query.set(String::new());
|
||||
set_turn_into_open.set(false);
|
||||
set_color_menu_open.set(false);
|
||||
set_more_menu_open.set(false);
|
||||
set_locked_toolbar_anchor.set(None);
|
||||
set_text_selection_active.set(false);
|
||||
set_floating_toolbar_anchor.set(None);
|
||||
set_image_toolbar_anchor.set(None);
|
||||
set_table_toolbar_open.set(false);
|
||||
set_table_options_open.set(false);
|
||||
set_table_overlay_anchor.set(None);
|
||||
set_table_selection_overlay.set(None);
|
||||
set_block_menu_open.set(false);
|
||||
set_block_menu_anchor.set(None);
|
||||
set_block_turn_into_open.set(false);
|
||||
set_block_folded_title_open.set(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user