Skip to content

Commit f566443

Browse files
committed
Merge branch 'main' into 4.x
* main: @uppy/dashboard: add new `autoOpen` option (#5001) @uppy/core: fix some type errors (#5015) add missing exports (#5014) Bump webpack-dev-middleware from 5.3.3 to 5.3.4 (#5013)
2 parents 1aac94d + 01f2428 commit f566443

File tree

12 files changed

+49
-107
lines changed

12 files changed

+49
-107
lines changed

Diff for: packages/@uppy/audio/src/Audio.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import locale from './locale.ts'
1717
// @ts-ignore We don't want TS to generate types for the package.json
1818
import packageJson from '../package.json'
1919

20-
interface AudioOptions extends UIPluginOptions {
20+
export interface AudioOptions extends UIPluginOptions {
2121
showAudioSourceDropdown?: boolean
2222
}
2323
interface AudioState {

Diff for: packages/@uppy/audio/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export { default } from './Audio.tsx'
2+
export type { AudioOptions } from './Audio.tsx'

Diff for: packages/@uppy/core/src/BasePlugin.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ export default class BasePlugin<
4949

5050
opts: Opts
5151

52-
id: string
52+
id!: string
5353

5454
defaultLocale: OptionalPluralizeLocale
5555

56-
i18n: I18n
56+
i18n!: I18n
5757

58-
i18nArray: Translator['translateArray']
58+
i18nArray!: Translator['translateArray']
5959

60-
type: string
60+
type!: string
6161

62-
VERSION: string
62+
VERSION!: string
6363

6464
constructor(uppy: Uppy<M, B>, opts?: Opts) {
6565
this.uppy = uppy

Diff for: packages/@uppy/core/src/Restricter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const defaultOptions = {
4141
class RestrictionError<M extends Meta, B extends Body> extends Error {
4242
isUserFacing: boolean
4343

44-
file: UppyFile<M, B>
44+
file!: UppyFile<M, B>
4545

4646
constructor(
4747
message: string,

Diff for: packages/@uppy/core/src/Uppy.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -376,17 +376,17 @@ export class Uppy<M extends Meta, B extends Body> {
376376

377377
defaultLocale: Locale
378378

379-
locale: Locale
379+
locale!: Locale
380380

381381
// The user optionally passes in options, but we set defaults for missing options.
382382
// We consider all options present after the contructor has run.
383383
opts: NonNullableUppyOptions<M, B>
384384

385385
store: NonNullableUppyOptions<M, B>['store']
386386

387-
i18n: I18n
387+
i18n!: I18n
388388

389-
i18nArray: Translator['translateArray']
389+
i18nArray!: Translator['translateArray']
390390

391391
scheduledAutoProceed: ReturnType<typeof setTimeout> | null = null
392392

@@ -828,7 +828,7 @@ export class Uppy<M extends Meta, B extends Body> {
828828
try {
829829
this.#restricter.validate(files, [file])
830830
} catch (err) {
831-
return err
831+
return err as any
832832
}
833833
return null
834834
}
@@ -1019,7 +1019,7 @@ export class Uppy<M extends Meta, B extends Body> {
10191019
nextFilesState[newFile.id] = newFile
10201020
validFilesToAdd.push(newFile)
10211021
} catch (err) {
1022-
errors.push(err)
1022+
errors.push(err as any)
10231023
}
10241024
}
10251025

@@ -1031,7 +1031,7 @@ export class Uppy<M extends Meta, B extends Body> {
10311031
validFilesToAdd,
10321032
)
10331033
} catch (err) {
1034-
errors.push(err)
1034+
errors.push(err as any)
10351035

10361036
// If we have any aggregate error, don't allow adding this batch
10371037
return {
@@ -2135,7 +2135,7 @@ export class Uppy<M extends Meta, B extends Body> {
21352135
* Start an upload for all the files that are not currently being uploaded.
21362136
*/
21372137
upload(): Promise<NonNullable<UploadResult<M, B>> | undefined> {
2138-
if (!this.#plugins.uploader?.length) {
2138+
if (!this.#plugins['uploader']?.length) {
21392139
this.log('No uploader type plugins are used', 'warning')
21402140
}
21412141

Diff for: packages/@uppy/dashboard/src/Dashboard.tsx

+20-7
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ interface DashboardState<M extends Meta, B extends Body> {
112112
[key: string]: unknown
113113
}
114114

115-
interface DashboardOptions<M extends Meta, B extends Body>
115+
export interface DashboardOptions<M extends Meta, B extends Body>
116116
extends UIPluginOptions {
117117
animateOpenClose?: boolean
118118
browserBackButtonClose?: boolean
@@ -150,6 +150,8 @@ interface DashboardOptions<M extends Meta, B extends Body>
150150
theme?: 'auto' | 'dark' | 'light'
151151
trigger?: string
152152
width?: string | number
153+
autoOpen?: 'metaEditor' | 'imageEditor' | null
154+
/** @deprecated use option autoOpen instead */
153155
autoOpenFileEditor?: boolean
154156
disabled?: boolean
155157
disableLocalFiles?: boolean
@@ -195,6 +197,7 @@ const defaultOptions = {
195197
showNativePhotoCameraButton: false,
196198
showNativeVideoCameraButton: false,
197199
theme: 'light',
200+
autoOpen: null,
198201
autoOpenFileEditor: false,
199202
disabled: false,
200203
disableLocalFiles: false,
@@ -243,7 +246,17 @@ export default class Dashboard<M extends Meta, B extends Body> extends UIPlugin<
243246
private removeDragOverClassTimeout: ReturnType<typeof setTimeout>
244247

245248
constructor(uppy: Uppy<M, B>, opts?: DashboardOptions<M, B>) {
246-
super(uppy, { ...defaultOptions, ...opts })
249+
// support for the legacy `autoOpenFileEditor` option,
250+
// TODO: we can remove this code when we update the Uppy major version
251+
let autoOpen: DashboardOptions<M, B>['autoOpen']
252+
if (!opts) {
253+
autoOpen = null
254+
} else if (opts.autoOpen === undefined) {
255+
autoOpen = opts.autoOpenFileEditor ? 'imageEditor' : null
256+
} else {
257+
autoOpen = opts.autoOpen
258+
}
259+
super(uppy, { ...defaultOptions, ...opts, autoOpen })
247260
this.id = this.opts.id || 'Dashboard'
248261
this.title = 'Dashboard'
249262
this.type = 'orchestrator'
@@ -939,11 +952,11 @@ export default class Dashboard<M extends Meta, B extends Body> extends UIPlugin<
939952

940953
const { metaFields } = this.getPluginState()
941954
const isMetaEditorEnabled = metaFields && metaFields.length > 0
942-
const isFileEditorEnabled = this.canEditFile(firstFile)
955+
const isImageEditorEnabled = this.canEditFile(firstFile)
943956

944-
if (isMetaEditorEnabled) {
957+
if (isMetaEditorEnabled && this.opts.autoOpen === 'metaEditor') {
945958
this.toggleFileCard(true, firstFile.id)
946-
} else if (isFileEditorEnabled) {
959+
} else if (isImageEditorEnabled && this.opts.autoOpen === 'imageEditor') {
947960
this.openFileEditor(firstFile)
948961
}
949962
}
@@ -985,7 +998,7 @@ export default class Dashboard<M extends Meta, B extends Body> extends UIPlugin<
985998
this.el!.addEventListener('keydown', this.handleKeyDownInInline)
986999
}
9871000

988-
if (this.opts.autoOpenFileEditor) {
1001+
if (this.opts.autoOpen) {
9891002
this.uppy.on('files-added', this.#openFileEditorWhenFilesAdded)
9901003
}
9911004
}
@@ -1018,7 +1031,7 @@ export default class Dashboard<M extends Meta, B extends Body> extends UIPlugin<
10181031
this.el!.removeEventListener('keydown', this.handleKeyDownInInline)
10191032
}
10201033

1021-
if (this.opts.autoOpenFileEditor) {
1034+
if (this.opts.autoOpen) {
10221035
this.uppy.off('files-added', this.#openFileEditorWhenFilesAdded)
10231036
}
10241037
}

Diff for: packages/@uppy/dashboard/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export { default } from './Dashboard.tsx'
2+
export type { DashboardOptions } from './Dashboard.tsx'

Diff for: packages/@uppy/drop-target/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import toArray from '@uppy/utils/lib/toArray'
88
// @ts-ignore We don't want TS to generate types for the package.json
99
import packageJson from '../package.json'
1010

11-
interface DropTargetOptions extends PluginOpts {
11+
export interface DropTargetOptions extends PluginOpts {
1212
target?: HTMLElement | string | null
1313
onDrop?: (event: DragEvent) => void
1414
onDragOver?: (event: DragEvent) => void

Diff for: packages/@uppy/react/src/DashboardModal.js

+7-81
Original file line numberDiff line numberDiff line change
@@ -37,90 +37,15 @@ class DashboardModal extends Component {
3737
}
3838

3939
installPlugin () {
40-
const {
41-
id = 'react:DashboardModal',
42-
uppy,
43-
target,
44-
open,
45-
onRequestClose,
46-
closeModalOnClickOutside,
47-
disablePageScrollWhenModalOpen,
48-
inline,
49-
plugins, // eslint-disable-line no-shadow
50-
width,
51-
height,
52-
showProgressDetails,
53-
note,
54-
metaFields, // eslint-disable-line no-shadow
55-
proudlyDisplayPoweredByUppy,
56-
autoOpenFileEditor,
57-
animateOpenClose,
58-
browserBackButtonClose,
59-
closeAfterFinish,
60-
disableStatusBar,
61-
disableInformer,
62-
disableThumbnailGenerator,
63-
disableLocalFiles,
64-
disabled,
65-
hideCancelButton,
66-
hidePauseResumeButton,
67-
hideProgressAfterFinish,
68-
hideRetryButton,
69-
hideUploadButton,
70-
showLinkToFileUploadResult,
71-
showRemoveButtonAfterComplete,
72-
showSelectedFiles,
73-
waitForThumbnailsBeforeUpload,
74-
fileManagerSelectionType,
75-
theme,
76-
thumbnailType,
77-
thumbnailWidth,
78-
locale, // eslint-disable-line no-shadow
79-
} = this.props
40+
const { id='react:DashboardModal', target=this.container, open, onRequestClose, uppy } = this.props
8041
const options = {
42+
...this.props,
8143
id,
8244
target,
83-
closeModalOnClickOutside,
84-
disablePageScrollWhenModalOpen,
85-
inline,
86-
plugins,
87-
width,
88-
height,
89-
showProgressDetails,
90-
note,
91-
metaFields,
92-
proudlyDisplayPoweredByUppy,
93-
autoOpenFileEditor,
94-
animateOpenClose,
95-
browserBackButtonClose,
96-
closeAfterFinish,
97-
disableStatusBar,
98-
disableInformer,
99-
disableThumbnailGenerator,
100-
disableLocalFiles,
101-
disabled,
102-
hideCancelButton,
103-
hidePauseResumeButton,
104-
hideProgressAfterFinish,
105-
hideRetryButton,
106-
hideUploadButton,
107-
showLinkToFileUploadResult,
108-
showRemoveButtonAfterComplete,
109-
showSelectedFiles,
110-
waitForThumbnailsBeforeUpload,
111-
fileManagerSelectionType,
112-
theme,
113-
thumbnailType,
114-
thumbnailWidth,
115-
locale,
11645
onRequestCloseModal: onRequestClose,
11746
}
118-
119-
if (!options.target) {
120-
options.target = this.container
121-
}
122-
12347
delete options.uppy
48+
12449
uppy.use(DashboardPlugin, options)
12550

12651
this.plugin = uppy.getPlugin(options.id)
@@ -146,6 +71,7 @@ class DashboardModal extends Component {
14671
}
14772
}
14873

74+
/* eslint-disable react/no-unused-prop-types */
14975
DashboardModal.propTypes = {
15076
uppy: uppyPropType.isRequired,
15177
target: typeof window !== 'undefined' ? PropTypes.instanceOf(window.HTMLElement) : PropTypes.any,
@@ -161,7 +87,7 @@ DashboardModal.propTypes = {
16187
note: PropTypes.string,
16288
metaFields,
16389
proudlyDisplayPoweredByUppy: PropTypes.bool,
164-
autoOpenFileEditor: PropTypes.bool,
90+
autoOpen: PropTypes.oneOf(['imageEditor', 'metaEditor', null]),
16591
animateOpenClose: PropTypes.bool,
16692
browserBackButtonClose: PropTypes.bool,
16793
closeAfterFinish: PropTypes.bool,
@@ -186,7 +112,7 @@ DashboardModal.propTypes = {
186112
thumbnailWidth: PropTypes.number,
187113
locale,
188114
}
189-
// Must be kept in sync with @uppy/dashboard/src/Dashboard.jsx.
115+
// Must be kept in sync with @uppy/dashboard/src/Dashboard.tsx.
190116
DashboardModal.defaultProps = {
191117
metaFields: [],
192118
plugins: [],
@@ -217,7 +143,7 @@ DashboardModal.defaultProps = {
217143
showRemoveButtonAfterComplete: false,
218144
browserBackButtonClose: false,
219145
theme: 'light',
220-
autoOpenFileEditor: false,
146+
autoOpen: false,
221147
disabled: false,
222148
disableLocalFiles: false,
223149

Diff for: packages/@uppy/webcam/src/Webcam.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function isModeAvailable<T>(modes: T[], mode: unknown): mode is T {
5959
return modes.includes(mode as T)
6060
}
6161

62-
interface WebcamOptions<M extends Meta, B extends Body>
62+
export interface WebcamOptions<M extends Meta, B extends Body>
6363
extends UIPluginOptions {
6464
target?: PluginTarget<M, B>
6565
onBeforeSnapshot?: () => Promise<void>

Diff for: packages/@uppy/webcam/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export { default } from './Webcam.tsx'
2+
export type { WebcamOptions } from './Webcam.tsx'

Diff for: yarn.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -31756,8 +31756,8 @@ __metadata:
3175631756
linkType: hard
3175731757

3175831758
"webpack-dev-middleware@npm:^5.3.1":
31759-
version: 5.3.3
31760-
resolution: "webpack-dev-middleware@npm:5.3.3"
31759+
version: 5.3.4
31760+
resolution: "webpack-dev-middleware@npm:5.3.4"
3176131761
dependencies:
3176231762
colorette: ^2.0.10
3176331763
memfs: ^3.4.3
@@ -31766,7 +31766,7 @@ __metadata:
3176631766
schema-utils: ^4.0.0
3176731767
peerDependencies:
3176831768
webpack: ^4.0.0 || ^5.0.0
31769-
checksum: dd332cc6da61222c43d25e5a2155e23147b777ff32fdf1f1a0a8777020c072fbcef7756360ce2a13939c3f534c06b4992a4d659318c4a7fe2c0530b52a8a6621
31769+
checksum: 90cf3e27d0714c1a745454a1794f491b7076434939340605b9ee8718ba2b85385b120939754e9fdbd6569811e749dee53eec319e0d600e70e0b0baffd8e3fb13
3177031770
languageName: node
3177131771
linkType: hard
3177231772

0 commit comments

Comments
 (0)