text_description.rs 895 B

1234567891011121314151617181920212223242526272829
  1. use crate::impl_from_and_to_type_option;
  2. use crate::services::row::CellDataSerde;
  3. use flowy_derive::ProtoBuf;
  4. use flowy_error::FlowyError;
  5. use flowy_grid_data_model::entities::{FieldMeta, FieldType};
  6. use serde::{Deserialize, Serialize};
  7. #[derive(Debug, Clone, Default, Serialize, Deserialize, ProtoBuf)]
  8. pub struct RichTextDescription {
  9. #[pb(index = 1)]
  10. pub format: String,
  11. }
  12. impl_from_and_to_type_option!(RichTextDescription, FieldType::RichText);
  13. impl CellDataSerde for RichTextDescription {
  14. fn deserialize_cell_data(&self, data: String) -> String {
  15. data
  16. }
  17. fn serialize_cell_data(&self, data: &str) -> Result<String, FlowyError> {
  18. let data = data.to_owned();
  19. if data.len() > 10000 {
  20. Err(FlowyError::text_too_long().context("The len of the text should not be more than 10000"))
  21. } else {
  22. Ok(data)
  23. }
  24. }
  25. }