event_map.rs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. use crate::event_handler::*;
  2. use crate::manager::GridManager;
  3. use flowy_derive::{Flowy_Event, ProtoBuf_Enum};
  4. use lib_dispatch::prelude::*;
  5. use std::sync::Arc;
  6. use strum_macros::Display;
  7. pub fn create(grid_manager: Arc<GridManager>) -> Module {
  8. let mut module = Module::new().name(env!("CARGO_PKG_NAME")).data(grid_manager);
  9. module = module
  10. .event(GridEvent::GetGridData, get_grid_data_handler)
  11. .event(GridEvent::GetGridBlocks, get_grid_blocks_handler)
  12. // Field
  13. .event(GridEvent::GetFields, get_fields_handler)
  14. .event(GridEvent::UpdateField, update_field_handler)
  15. .event(GridEvent::InsertField, insert_field_handler)
  16. .event(GridEvent::DeleteField, delete_field_handler)
  17. .event(GridEvent::SwitchToField, switch_to_field_handler)
  18. .event(GridEvent::DuplicateField, duplicate_field_handler)
  19. .event(GridEvent::GetEditFieldContext, get_field_context_handler)
  20. .event(GridEvent::MoveItem, move_item_handler)
  21. // Row
  22. .event(GridEvent::CreateRow, create_row_handler)
  23. .event(GridEvent::GetRow, get_row_handler)
  24. .event(GridEvent::DeleteRow, delete_row_handler)
  25. .event(GridEvent::DuplicateRow, duplicate_row_handler)
  26. // Cell
  27. .event(GridEvent::GetCell, get_cell_handler)
  28. .event(GridEvent::UpdateCell, update_cell_handler)
  29. // SelectOption
  30. .event(GridEvent::NewSelectOption, new_select_option_handler)
  31. .event(GridEvent::UpdateSelectOption, update_select_option_handler)
  32. .event(GridEvent::GetSelectOptionContext, get_select_option_handler)
  33. .event(GridEvent::UpdateCellSelectOption, update_cell_select_option_handler);
  34. module
  35. }
  36. #[derive(Clone, Copy, PartialEq, Eq, Debug, Display, Hash, ProtoBuf_Enum, Flowy_Event)]
  37. #[event_err = "FlowyError"]
  38. pub enum GridEvent {
  39. #[event(input = "GridId", output = "Grid")]
  40. GetGridData = 0,
  41. #[event(input = "QueryGridBlocksPayload", output = "RepeatedGridBlock")]
  42. GetGridBlocks = 1,
  43. #[event(input = "QueryFieldPayload", output = "RepeatedField")]
  44. GetFields = 10,
  45. #[event(input = "FieldChangesetPayload")]
  46. UpdateField = 11,
  47. #[event(input = "InsertFieldPayload")]
  48. InsertField = 12,
  49. #[event(input = "FieldIdentifierPayload")]
  50. DeleteField = 13,
  51. #[event(input = "EditFieldPayload", output = "EditFieldContext")]
  52. SwitchToField = 14,
  53. #[event(input = "FieldIdentifierPayload")]
  54. DuplicateField = 15,
  55. #[event(input = "GetEditFieldContextPayload", output = "EditFieldContext")]
  56. GetEditFieldContext = 16,
  57. #[event(input = "MoveItemPayload")]
  58. MoveItem = 17,
  59. #[event(input = "CreateSelectOptionPayload", output = "SelectOption")]
  60. NewSelectOption = 30,
  61. #[event(input = "CellIdentifierPayload", output = "SelectOptionContext")]
  62. GetSelectOptionContext = 31,
  63. #[event(input = "SelectOptionChangesetPayload")]
  64. UpdateSelectOption = 32,
  65. #[event(input = "CreateRowPayload", output = "Row")]
  66. CreateRow = 50,
  67. #[event(input = "RowIdentifierPayload", output = "Row")]
  68. GetRow = 51,
  69. #[event(input = "RowIdentifierPayload")]
  70. DeleteRow = 52,
  71. #[event(input = "RowIdentifierPayload")]
  72. DuplicateRow = 53,
  73. #[event(input = "CellIdentifierPayload", output = "Cell")]
  74. GetCell = 70,
  75. #[event(input = "CellChangeset")]
  76. UpdateCell = 71,
  77. #[event(input = "SelectOptionCellChangesetPayload")]
  78. UpdateCellSelectOption = 72,
  79. }