@@ -61,14 +61,18 @@ const handleStandaloneDrawing = (excalidrawState: ExcalidrawInitialDataState): E
6161 const standaloneDrawingIdx = excalidrawState . elements . findIndex (
6262 ( e ) => e . id === EXCALIDRAW_STANDALONE_DRAWING_ID
6363 ) ;
64- if ( standaloneDrawingIdx < 0 ) {
65- return excalidrawState ;
64+ const standaloneElement =
65+ standaloneDrawingIdx < 0
66+ ? EXCALIDRAW_STANDALONE_DRAWING_RECTANGLE
67+ : excalidrawState . elements [ standaloneDrawingIdx ] ;
68+ if ( standaloneDrawingIdx >= 0 ) {
69+ ( excalidrawState . elements as ExcalidrawElement [ ] ) . splice ( standaloneDrawingIdx , 1 ) ;
6670 }
6771 const elements = withoutMetaElements ( excalidrawState . elements ) ;
6872 const { x, y, width, height } = getBoundingRect ( elements ) ;
6973
70- ( excalidrawState . elements as ExcalidrawElement [ ] ) . splice ( standaloneDrawingIdx , 1 , {
71- ...excalidrawState . elements [ standaloneDrawingIdx ] ,
74+ ( excalidrawState . elements as ExcalidrawElement [ ] ) . splice ( 0 , 0 , {
75+ ...standaloneElement ,
7276 strokeWidth : EXCALIDRAW_STANDALONE_DRAWING_RECTANGLE . strokeWidth ,
7377 strokeColor : EXCALIDRAW_STANDALONE_DRAWING_RECTANGLE . strokeColor ,
7478 width,
@@ -87,15 +91,6 @@ export const updateRectangleDimensions = (
8791 }
8892 const backgroundImage = excalidrawState . elements . find ( ( e ) => e . id === EXCALIDRAW_BACKGROUND_IMAGE_ID ) ;
8993 if ( ! backgroundImage ) {
90- const isStandaloneDrawing = excalidrawState . elements . some (
91- ( e ) => e . id === EXCALIDRAW_STANDALONE_DRAWING_ID
92- ) ;
93- if ( ! isStandaloneDrawing ) {
94- // add standalone markup drawing rectangle
95- ( excalidrawState . elements as ExcalidrawElement [ ] ) . splice ( 0 , 0 , {
96- ...EXCALIDRAW_STANDALONE_DRAWING_RECTANGLE
97- } ) ;
98- }
9994 return handleStandaloneDrawing ( excalidrawState ) ;
10095 }
10196 if ( ! backgroundImage || backgroundImage . type !== 'image' ) {
0 commit comments