use canvist_model::BlockTypeId;
use canvist_model::EmbedTypeId;
use canvist_model::MarkTypeId;
use canvist_model::Schema;
use canvist_model::SchemaBuilder;
use crate::Adornment;
use crate::Command;
use crate::CommandResult;
use crate::CommandSpec;
use crate::EditorError;
use crate::EditorState;
use crate::InputRule;
use crate::NodeMeta;
use crate::PasteRule;
use crate::Platform;
use crate::QuerySpec;
use crate::Update;
pub type Binding = (&'static str, Command);
pub type UpdateFilter = Box<dyn Fn(&EditorState, &Update) -> bool + Send + Sync>;
pub trait Extension: Send + Sync {
fn name(&self) -> &'static str;
fn priority(&self) -> i32 {
100
}
fn schema(&self, schema: SchemaBuilder) -> SchemaBuilder {
schema
}
fn commands(&self, _schema: &Schema) -> Result<Vec<CommandSpec>, EditorError> {
Ok(Vec::new())
}
fn queries(&self, _schema: &Schema) -> Result<Vec<QuerySpec>, EditorError> {
Ok(Vec::new())
}
fn nodes(&self) -> Vec<NodeMeta> {
Vec::new()
}
fn keymap(&self, _schema: &Schema, _platform: Platform) -> Result<Vec<Binding>, EditorError> {
Ok(Vec::new())
}
fn input_rules(&self, _schema: &Schema) -> Result<Vec<InputRule>, EditorError> {
Ok(Vec::new())
}
fn paste_rules(&self, _schema: &Schema) -> Result<Vec<PasteRule>, EditorError> {
Ok(Vec::new())
}
fn code_blocks(&self, _schema: &Schema) -> Result<Vec<BlockTypeId>, EditorError> {
Ok(Vec::new())
}
fn after_update(&self, _state: &mut EditorState, _update: &Update) -> CommandResult {
Ok(None)
}
fn update_filters(&self, _schema: &Schema) -> Result<Vec<UpdateFilter>, EditorError> {
Ok(Vec::new())
}
fn adornments(&self, _state: &EditorState) -> Vec<Adornment> {
Vec::new()
}
fn adorns(&self) -> bool {
false
}
}
pub fn block_type(
schema: &Schema,
extension: &'static str,
name: &'static str,
) -> Result<BlockTypeId, EditorError> {
schema.block_type(name).ok_or(EditorError::MissingType {
extension,
kind: "block",
name,
})
}
pub fn mark_type(
schema: &Schema,
extension: &'static str,
name: &'static str,
) -> Result<MarkTypeId, EditorError> {
schema.mark_type(name).ok_or(EditorError::MissingType {
extension,
kind: "mark",
name,
})
}
pub fn embed_type(
schema: &Schema,
extension: &'static str,
name: &'static str,
) -> Result<EmbedTypeId, EditorError> {
schema.embed_type(name).ok_or(EditorError::MissingType {
extension,
kind: "embed",
name,
})
}