@@ -49,6 +49,16 @@ export interface FileDetails {
49
49
* license will take priority over the global license.
50
50
*/
51
51
license ?: string ;
52
+ /**
53
+ * A reference to the document that was used to create this File class. Used as an optimization
54
+ * where applicable. If passed, 'pageIndex' must also be passed
55
+ */
56
+ fullDocumentObj ?: CoreControls . Document ;
57
+ /**
58
+ * Used in conjunction with 'fullDocumentObj'. Represents the pageIndex of 'fullDocumentObj' that this
59
+ * file belongs too
60
+ */
61
+ pageIndex ?: number ;
52
62
}
53
63
54
64
export interface FileLike {
@@ -60,6 +70,8 @@ export interface FileLike {
60
70
fileObj : MemoizedPromise < Blob > ;
61
71
documentObj : MemoizedPromise < CoreControls . Document > ;
62
72
subscribe : ( ...args : any ) => ( ) => void ;
73
+ fullDocumentObj ?: CoreControls . Document ;
74
+ pageIndex ?: number ;
63
75
}
64
76
65
77
export type FileEventType =
@@ -96,19 +108,40 @@ export class File implements FileLike {
96
108
private _freezeThumbnail : boolean ;
97
109
private _subscribers : FileEventListenersObj ;
98
110
private _license ?: string ;
111
+ private _fullDocumentObj ?: CoreControls . Document ;
112
+ private _pageIndex ?: number ;
99
113
100
114
/**
101
115
* Initialize the `File`.
102
116
* @param fileDetails The file details object or file-like class to initialize
103
117
* this `File` with.
104
118
*/
105
119
constructor ( fileDetails : FileDetails ) {
106
- const { name, id, originalName, extension, fileObj, documentObj, thumbnail, license } = fileDetails ;
120
+ const {
121
+ name,
122
+ id,
123
+ originalName,
124
+ extension,
125
+ fileObj,
126
+ documentObj,
127
+ thumbnail,
128
+ license,
129
+ fullDocumentObj,
130
+ pageIndex,
131
+ } = fileDetails ;
107
132
108
133
if ( ! fileObj && ! documentObj ) {
109
134
throw new Error ( 'One of `fileObj` or `documentObj` is required to initialize File.' ) ;
110
135
}
111
136
137
+ if ( fullDocumentObj ) {
138
+ if ( typeof pageIndex !== 'number' ) {
139
+ throw new Error ( '"pageIndex" must be passed if using "fullDocumentObj"' ) ;
140
+ }
141
+ this . _fullDocumentObj = fullDocumentObj ;
142
+ this . _pageIndex = pageIndex ;
143
+ }
144
+
112
145
this . _id = id || getStringId ( 'file' ) ;
113
146
this . _name = name ;
114
147
this . _originalName = originalName || name ;
@@ -164,6 +197,16 @@ export class File implements FileLike {
164
197
return this . _documentObj ;
165
198
}
166
199
200
+ /** Gets the full document object if provided during initialization. */
201
+ get fullDocumentObj ( ) {
202
+ return this . _fullDocumentObj ;
203
+ }
204
+
205
+ /** Gets the page index if provided during initialization. */
206
+ get pageIndex ( ) {
207
+ return this . _pageIndex ;
208
+ }
209
+
167
210
/** The name of the file. */
168
211
get name ( ) {
169
212
return this . _name ;
@@ -299,7 +342,10 @@ export class File implements FileLike {
299
342
300
343
/** Generate a thumbnail from document object. */
301
344
private _generateThumbnail = ( ) => {
302
- return getThumbnail ( this . documentObj . get ( ) , this . extension ) ;
345
+ return getThumbnail ( this . fullDocumentObj || this . documentObj . get ( ) , {
346
+ extension : this . extension ,
347
+ pageIndex : this . pageIndex ,
348
+ } ) ;
303
349
} ;
304
350
305
351
/** Generate a file object from document object. */
0 commit comments