@@ -11,11 +11,39 @@ interface Clipboard {
11
11
write ?( notes : Array < ClipboardItem > ) : Promise < void > ;
12
12
}
13
13
14
- const resetHeight = ( noteWrapper : HTMLElement , noteDom : HTMLElement , rowGap : number , rowHeight : number ) => {
14
+ export const removeGridBeforeNotesCreated = ( noteWrapper : HTMLElement ) => {
15
+ noteWrapper . classList . add ( "invisible" ) ;
15
16
noteWrapper . style . display = "unset" ;
17
+ } ;
18
+
19
+ export const makeGridAfterNoteCreated = ( noteWrapper : HTMLElement , noteDom : HTMLElement ) => {
20
+ setTimeout ( ( ) => {
21
+ noteDom . style . gridRowEnd = `span ${ noteDom . dataset . span } ` ;
22
+ noteWrapper . style . display = "grid" ;
23
+ noteWrapper . classList . remove ( "invisible" ) ;
24
+ } ) ;
25
+ } ;
26
+
27
+ export const makeGridAfterNotesCreated = ( noteWrapper : HTMLElement , noteDoms : NodeListOf < HTMLElement > ) => {
28
+ setTimeout ( ( ) => {
29
+ noteDoms . forEach ( ( noteDom ) => {
30
+ noteDom . style . gridRowEnd = `span ${ noteDom . dataset . span } ` ;
31
+ } ) ;
32
+ noteWrapper . style . display = "grid" ;
33
+ noteWrapper . classList . remove ( "invisible" ) ;
34
+ } , 0 ) ;
35
+ } ;
36
+
37
+ const setHeight = ( noteDom : HTMLElement , rowGap : number , rowHeight : number ) => {
16
38
const noteHieght = noteDom . getBoundingClientRect ( ) . height ;
17
39
const rowSpan = Math . ceil ( ( noteHieght + rowGap ) / ( rowHeight + rowGap ) ) ;
40
+ noteDom . dataset . span = "" + rowSpan ;
18
41
noteDom . style . gridRowEnd = `span ${ rowSpan } ` ;
42
+ } ;
43
+
44
+ const resetHeight = ( noteWrapper : HTMLElement , noteDom : HTMLElement , rowGap : number , rowHeight : number ) => {
45
+ noteWrapper . style . display = "unset" ;
46
+ setHeight ( noteDom , rowGap , rowHeight ) ;
19
47
noteWrapper . style . display = "grid" ;
20
48
} ;
21
49
@@ -60,7 +88,9 @@ export const createNote = (note: NerorenClipboardType, settings: Settings) => {
60
88
const imageContent = document . createElement ( "img" ) as HTMLImageElement ;
61
89
imageContent . className = "image" ;
62
90
imageContent . onload = ( ) => {
63
- resetHeight ( noteWrapper , noteDom , rowGap , rowHeight ) ;
91
+ setTimeout ( ( ) => {
92
+ resetHeight ( noteWrapper , noteDom , rowGap , rowHeight ) ;
93
+ } , 0 ) ;
64
94
} ;
65
95
imageContent . src = content ;
66
96
contentDom . appendChild ( imageContent ) ;
@@ -109,7 +139,7 @@ export const createNote = (note: NerorenClipboardType, settings: Settings) => {
109
139
}
110
140
111
141
// set height for grid
112
- resetHeight ( noteWrapper , noteDom , rowGap , rowHeight ) ;
142
+ setHeight ( noteDom , rowGap , rowHeight ) ;
113
143
} , 0 ) ;
114
144
115
145
const buttonWrapper = document . createElement ( "div" ) ;
@@ -240,14 +270,13 @@ export const createNote = (note: NerorenClipboardType, settings: Settings) => {
240
270
timeDom . className = "time" ;
241
271
bottomWrapper . appendChild ( timeDom ) ;
242
272
243
- setTimeout ( ( ) => {
244
- noteWrapper . style . display = "unset" ;
245
- const noteHieght = noteDom . getBoundingClientRect ( ) . height ;
246
- const rowSpan = Math . ceil ( ( noteHieght + rowGap ) / ( rowHeight + rowGap ) ) ;
247
- noteDom . style . gridRowEnd = `span ${ rowSpan } ` ;
248
- noteWrapper . style . display = "grid" ;
249
- } , 0 ) ;
250
273
noteWrapper ?. insertBefore ( noteDom , noteWrapper . firstChild ) ;
274
+
275
+ const noteHieght = noteDom . getBoundingClientRect ( ) . height ;
276
+ const rowSpan = Math . ceil ( ( noteHieght + rowGap ) / ( rowHeight + rowGap ) ) ;
277
+ noteDom . dataset . span = `${ rowSpan } ` ;
278
+
279
+ return noteDom ;
251
280
}
252
281
} ;
253
282
0 commit comments