//! Document-level objects: diffing and applying the data that isn't a node (file name, styles, //! variables, comments, images, dev snapshots, library data…). use std::collections::{BTreeMap, BTreeSet}; use std::sync::Arc; use base64::Engine as _; use figcraft_doc::{Collection, Comment, DevSnapshot, Document, ImageData, Style, Variable}; use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; use crate::Error; use crate::change::{Change, DocProp, Entry, Family, Json}; /// An entry of a document-level list that has an id. trait Keyed: Clone + PartialEq + Serialize + DeserializeOwned { type Key: Ord + Clone + Serialize + DeserializeOwned; fn key(&self) -> Self::Key; } impl Keyed for Style { type Key = String; fn key(&self) -> String { self.id.clone() } } impl Keyed for Comment { type Key = u64; fn key(&self) -> u64 { self.id } } impl Keyed for Collection { type Key = String; fn key(&self) -> String { self.id.clone() } } impl Keyed for Variable { type Key = String; fn key(&self) -> String { self.id.clone() } } /// How one keyed list of the document syncs. struct List { whole: DocProp, order: DocProp, entry: fn(T::Key) -> Entry, get: fn(&Document) -> &Vec, get_mut: fn(&mut Document) -> &mut Vec, } const STYLES: List