import Deck , { DeckSchema } from "./entities/Deck" ; import ExcalidrawElement from "./entities/ExcalidrawElement" ; import PrintableArea , { PrintableAreaSchema } from "./entities/PrintableArea" ; import Slide from "./entities/Slide" ; import DeckNotValid from "./errors/DeckNotValid" ; import PrintableAreaNotValid from "./errors/PrintableAreaNotValid" ; import SlideOperations from "./SlideOperations" ; const DeckOperations = { parse ( source ) { try { return DeckSchema . parse ( source ) ; } catch ( error ) { throw new DeckNotValid ( ) ; } } , makeEmptyDeck ( printableArea ) { return { commonExcalidrawElements : [ ] , printableArea : printableArea , slides : SlideOperations . addEmpty ( [ ] ) , } ; } , updatePrintableArea ( deck , printableArea ) { try { PrintableAreaSchema . parse ( printableArea ) ; return { ... deck , printableArea } ; } catch ( error ) { throw new PrintableAreaNotValid ( ) ; } } , updateCommonExcalidrawElements ( deck , commonExcalidrawElements ) { return { ... deck , commonExcalidrawElements } ; } , addEmptySlide ( deck ) { return { ... deck , slides : SlideOperations . addEmpty ( deck . slides ) , } ; } , moveSlide ( deck , fromIndex , toIndex ) { return { ... deck , slides : SlideOperations . moveSlide ( deck . slides , fromIndex , toIndex ) , } ; } , deleteSlide ( deck , slideId ) { const slides = SlideOperations . removeById ( deck . slides , slideId ) ; return { ... deck , slides : slides . length === 0 ? SlideOperations . addEmpty ( [ ] ) : slides , } ; } , updateSlideShouldRender ( deck , slideId , shouldRender ) { return { ... deck , slides : SlideOperations . updateShouldRenderById ( deck . slides , slideId , shouldRender ) , } ; } , updateSlideShouldRenderWithCommonExcalidrawElements ( deck , slideId , shouldRenderWithCommonExcalidrawElements ) { return { ... deck , slides : SlideOperations . updateShouldRenderWithCommonExcalidrawElementsById ( deck . slides , slideId , shouldRenderWithCommonExcalidrawElements ) , } ; } , updateSlideExcalidrawElements ( deck , slideId , excalidrawElements ) { return { ... deck , slides : SlideOperations . updateExcalidrawElementsById ( deck . slides , slideId , excalidrawElements ) , } ; } , getSlide ( deck , slideId ) { return SlideOperations . getById ( deck . slides , slideId ) ; } , getSlideIndex ( deck , slideId ) { return SlideOperations . getIndexById ( deck . slides , slideId ) ; } , } ; export default DeckOperations ;