Skip to content

Commit 1fd2573

Browse files
authored
enh: Add option to disable FileDropper previews (#7944)
1 parent 3d5b353 commit 1fd2573

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

examples/reference/widgets/FileDropper.ipynb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
"* **`max_files`** (int): Maximum number of files that can be uploaded if `multiple=True`.\n",
3333
"* **`max_total_file_size`** (str): Maximum size of all uploaded files, as a string with units given in KB or MB, e.g. 5MB or 750KB.\n",
3434
"* **`mime_type`** (dict[str, str]): A dictionary containing the mimetypes for each of the uploaded files indexed by their filename.\n",
35+
"* **`previews`** (list[str]): List of previews to enable in the FileDropper. The following previews are available:\n",
36+
" * `image`: Adds support for image previews.\n",
37+
" * `pdf`: Adds support for PDF previews.\n",
3538
"* **`multiple`** (bool): Whether to allow uploading multiple files.\n",
3639
"* **`value`** (dict[str, str | bytes]): A dictionary containing the uploaded file(s) as bytes or string objects indexed by the filename. Files that have a `text/*` mimetype will automatically be decoded as `utf-8`.\n",
3740
"\n",

panel/models/file_dropper.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class FileDropper(InputWidget):
4444

4545
layout = Nullable(Enum("integrated", "compact", "circle", default="compact"))
4646

47+
previews = List(String)
48+
4749
__javascript_raw__ = [
4850
f"{config.npm_cdn}/filepond-plugin-image-preview/dist/filepond-plugin-image-preview.js",
4951
f"{config.npm_cdn}/filepond-plugin-file-validate-size/dist/filepond-plugin-file-validate-size.js",

panel/models/file_dropper.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,14 @@ export class FileDropperView extends InputWidgetView {
4444
_transfer_in_process: string | null = null
4545

4646
override initialize(): void {
47-
super.initialize();
48-
(window as any).FilePond.registerPlugin((window as any).FilePondPluginImagePreview);
49-
(window as any).FilePond.registerPlugin((window as any).FilePondPluginPdfPreview);
47+
super.initialize()
48+
const {previews} = this.model
49+
if (previews.includes("image")) {
50+
(window as any).FilePond.registerPlugin((window as any).FilePondPluginImagePreview)
51+
}
52+
if (previews.includes("pdf")) {
53+
(window as any).FilePond.registerPlugin((window as any).FilePondPluginPdfPreview)
54+
}
5055
(window as any).FilePond.registerPlugin((window as any).FilePondPluginFileValidateType);
5156
(window as any).FilePond.registerPlugin((window as any).FilePondPluginFileValidateSize)
5257
}
@@ -165,6 +170,7 @@ export namespace FileDropper {
165170
max_total_file_size: p.Property<string | null>
166171
mime_type: p.Property<any>
167172
multiple: p.Property<boolean>
173+
previews: p.Property<string[]>
168174
}
169175
}
170176

@@ -190,6 +196,7 @@ export class FileDropper extends InputWidget {
190196
mime_type: [ Any, {} ],
191197
multiple: [ Bool, true ],
192198
layout: [ Nullable(DropperLayout), null ],
199+
previews: [ List(Str), [ "image", "pdf" ]],
193200
}))
194201
}
195202
}

panel/widgets/input.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,13 @@ class FileDropper(Widget):
364364
multiple = param.Boolean(default=False, doc="""
365365
Whether to allow uploading multiple files.""")
366366

367+
previews = param.ListSelector(default=["image", "pdf"],
368+
objects=["image", "pdf"], doc="""
369+
List of previews to enable in the FileDropper.
370+
The following previews are available:
371+
- image: Adds support for image previews.
372+
- pdf: Adds support for PDF previews.""")
373+
367374
value = param.Dict(default={}, doc="""
368375
A dictionary containing the uploaded file(s) as bytes or string
369376
objects indexed by the filename. Files that have a text/* mimetype

0 commit comments

Comments
 (0)