@panneau/field-upload 4.0.48 → 4.0.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- .panneau-field-upload-container{position:relative;width:100%}.panneau-field-upload-container .panneau-field-upload-dashboard{margin-bottom:10px;position:relative}.panneau-field-upload-container .panneau-field-upload-dashboardModal{position:relative;z-index:10001}.panneau-field-upload-container .panneau-field-upload-uppyDashboardContainer{margin-top:0}
1
+ .panneau-field-upload-dashboard{margin-bottom:10px;position:relative}.panneau-field-upload-dashboardModal{position:relative;z-index:10001}.panneau-field-upload-uppyDashboardContainer{margin-top:0}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { Label } from '@panneau/core';
2
+ import { MediaType, Label } from '@panneau/core';
3
3
 
4
- type MediaType = 'audio' | 'image' | 'video' | 'document';
5
4
  type MediaSource = 'webcam' | 'facebook' | 'instagram' | 'dropbox' | 'google-drive';
6
5
  interface Media$1 {
7
6
  filename?: string;
package/dist/index.js CHANGED
@@ -1,11 +1,10 @@
1
- import { c } from 'react/compiler-runtime';
2
1
  import { UppyContextProvider } from '@uppy/react';
3
2
  import Dashboard from '@uppy/react/dashboard';
4
3
  import DashboardModal from '@uppy/react/dashboard-modal';
5
4
  import classNames from 'classnames';
6
5
  import isArray from 'lodash/isArray';
7
6
  import isObject from 'lodash/isObject';
8
- import { useState, useRef, useEffect } from 'react';
7
+ import { useCallback, useMemo, useState, useRef, useEffect } from 'react';
9
8
  import { FormattedMessage } from 'react-intl';
10
9
  import { useQuery } from '@panneau/core/hooks';
11
10
  import Button from '@panneau/element-button';
@@ -16,516 +15,253 @@ import { useUppy } from '@panneau/uppy';
16
15
  import '@uppy/core/css/style.css';
17
16
  import '@uppy/dashboard/css/style.css';
18
17
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
18
+ import { c } from 'react/compiler-runtime';
19
19
 
20
- var styles = {"container":"panneau-field-upload-container","dashboard":"panneau-field-upload-dashboard","dashboardModal":"panneau-field-upload-dashboardModal"};
20
+ var styles = {"dashboard":"panneau-field-upload-dashboard","dashboardModal":"panneau-field-upload-dashboardModal"};
21
21
 
22
+ // import classNames from 'classnames';
22
23
  const DEFAULT_TYPES = ['audio', 'image', 'video'];
23
24
  const DEFAULT_SOURCES = ['webcam', 'facebook', 'instagram', 'dropbox', 'google-drive'];
24
- function UploadField(t0) {
25
- const $ = c(123);
26
- const {
27
- resource: t1,
28
- value: t2,
29
- name: t3,
30
- types: t4,
31
- fileTypes: t5,
32
- sources: t6,
33
- withButton: t7,
34
- withFind: t8,
35
- withClearButton: t9,
36
- withoutMedia: t10,
37
- addButtonLabel: t11,
38
- findButtonLabel: t12,
39
- clearButtonLabel: t13,
40
- allowMultipleUploads: t14,
41
- closeAfterFinish: t15,
42
- maxNumberOfFiles: t16,
43
- namePath: t17,
44
- thumbnailPath: t18,
45
- sizePath: t19,
46
- linkPath: t20,
47
- uppyProps: t21,
48
- width: t22,
49
- height: t23,
50
- disabled: t24,
51
- uploadDisabled: t25,
52
- outline: t26,
53
- loading: t27,
54
- onChange: t28,
55
- onClear: t29,
56
- onClickAdd: t30,
57
- onClickFind: t31,
58
- className: t32
59
- } = t0;
60
- const resource = t1 === undefined ? "medias" : t1;
61
- const value = t2 === undefined ? null : t2;
62
- const name = t3 === undefined ? null : t3;
63
- const types = t4 === undefined ? DEFAULT_TYPES : t4;
64
- const fileTypes = t5 === undefined ? null : t5;
65
- const sources = t6 === undefined ? DEFAULT_SOURCES : t6;
66
- const withButton = t7 === undefined ? false : t7;
67
- const withFind = t8 === undefined ? false : t8;
68
- const withClearButton = t9 === undefined ? false : t9;
69
- const withoutMedia = t10 === undefined ? false : t10;
70
- const initialAddButtonLabel = t11 === undefined ? null : t11;
71
- const initialFindButtonLabel = t12 === undefined ? null : t12;
72
- const initialCleanButtonLabel = t13 === undefined ? null : t13;
73
- const allowMultipleUploads = t14 === undefined ? false : t14;
74
- const closeAfterFinish = t15 === undefined ? true : t15;
75
- const maxNumberOfFiles = t16 === undefined ? 1 : t16;
76
- const namePath = t17 === undefined ? "name" : t17;
77
- const thumbnailPath = t18 === undefined ? "thumbnail_url" : t18;
78
- const sizePath = t19 === undefined ? "metadata.size" : t19;
79
- const linkPath = t20 === undefined ? null : t20;
80
- const uppyProps = t21 === undefined ? null : t21;
81
- const width = t22 === undefined ? null : t22;
82
- const height = t23 === undefined ? 300 : t23;
83
- const disabled = t24 === undefined ? false : t24;
84
- const uploadDisabled = t25 === undefined ? false : t25;
85
- const outline = t26 === undefined ? true : t26;
86
- const parentLoading = t27 === undefined ? false : t27;
87
- const onChange = t28 === undefined ? null : t28;
88
- const onClear = t29 === undefined ? null : t29;
89
- const onClickAdd = t30 === undefined ? null : t30;
90
- const onClickFind = t31 === undefined ? null : t31;
91
- const className = t32 === undefined ? null : t32;
92
- let t33;
93
- if ($[0] !== initialAddButtonLabel) {
94
- t33 = initialAddButtonLabel || /*#__PURE__*/jsx(FormattedMessage, {
95
- id: "BeKVq6"
96
- });
97
- $[0] = initialAddButtonLabel;
98
- $[1] = t33;
99
- } else {
100
- t33 = $[1];
101
- }
102
- const addButtonLabel = t33;
103
- let t34;
104
- if ($[2] !== initialFindButtonLabel) {
105
- t34 = initialFindButtonLabel || /*#__PURE__*/jsx(FormattedMessage, {
106
- id: "une5WQ"
107
- });
108
- $[2] = initialFindButtonLabel;
109
- $[3] = t34;
110
- } else {
111
- t34 = $[3];
112
- }
113
- const findButtonLabel = t34;
114
- let t35;
115
- if ($[4] !== initialCleanButtonLabel) {
116
- t35 = initialCleanButtonLabel || /*#__PURE__*/jsx(FormattedMessage, {
117
- id: "odaCUe"
118
- });
119
- $[4] = initialCleanButtonLabel;
120
- $[5] = t35;
121
- } else {
122
- t35 = $[5];
123
- }
124
- const clearButtonLabel = t35;
125
- const mergeData = _temp;
126
- let t36;
127
- if ($[6] !== allowMultipleUploads || $[7] !== onChange) {
128
- t36 = response => {
129
- let newValue_0 = null;
130
- if (isArray(response)) {
131
- if (allowMultipleUploads) {
132
- newValue_0 = response;
133
- } else {
134
- const [first] = response;
135
- newValue_0 = first;
136
- }
137
- } else {
138
- if (response && response.successful) {
139
- newValue_0 = response.successful.length > 0 ? response.successful[0].response.body : null;
140
- }
141
- }
142
- if (isArray(newValue_0)) {
143
- newValue_0 = newValue_0.map(val => mergeData(val));
25
+ function UploadField({
26
+ resource = 'medias',
27
+ value = null,
28
+ name = null,
29
+ types = DEFAULT_TYPES,
30
+ fileTypes = null,
31
+ sources = DEFAULT_SOURCES,
32
+ withButton = false,
33
+ withFind = false,
34
+ withClearButton = false,
35
+ withoutMedia = false,
36
+ addButtonLabel: initialAddButtonLabel = null,
37
+ findButtonLabel: initialFindButtonLabel = null,
38
+ clearButtonLabel: initialCleanButtonLabel = null,
39
+ allowMultipleUploads = false,
40
+ closeAfterFinish = true,
41
+ maxNumberOfFiles = 1,
42
+ namePath = 'name',
43
+ thumbnailPath = 'thumbnail_url',
44
+ sizePath = 'metadata.size',
45
+ linkPath = null,
46
+ uppyProps = null,
47
+ width = null,
48
+ height = 300,
49
+ disabled = false,
50
+ uploadDisabled = false,
51
+ outline = true,
52
+ loading: parentLoading = false,
53
+ onChange = null,
54
+ onClear = null,
55
+ onClickAdd = null,
56
+ onClickFind = null,
57
+ className = null
58
+ }) {
59
+ const addButtonLabel = initialAddButtonLabel || /*#__PURE__*/jsx(FormattedMessage, {
60
+ id: "BeKVq6"
61
+ });
62
+ const findButtonLabel = initialFindButtonLabel || /*#__PURE__*/jsx(FormattedMessage, {
63
+ id: "une5WQ"
64
+ });
65
+ const clearButtonLabel = initialCleanButtonLabel || /*#__PURE__*/jsx(FormattedMessage, {
66
+ id: "odaCUe"
67
+ });
68
+ const mergeData = useCallback(newValue => {
69
+ // Merge the response from our back-end
70
+ if (isObject(newValue) && isObject(newValue.response) && newValue.response.status === 200 && newValue.response.body !== null) {
71
+ return {
72
+ ...newValue,
73
+ ...(newValue.response.body || null)
74
+ };
75
+ }
76
+ return newValue;
77
+ }, []);
78
+ const onComplete = useCallback(response => {
79
+ let newValue_0 = null;
80
+ if (isArray(response)) {
81
+ if (allowMultipleUploads) {
82
+ newValue_0 = response;
144
83
  } else {
145
- if (newValue_0 !== null) {
146
- newValue_0 = mergeData(newValue_0);
147
- }
84
+ const [first] = response;
85
+ newValue_0 = first;
148
86
  }
149
- if (onChange !== null) {
150
- onChange(newValue_0);
151
- }
152
- };
153
- $[6] = allowMultipleUploads;
154
- $[7] = onChange;
155
- $[8] = t36;
156
- } else {
157
- t36 = $[8];
158
- }
159
- const onComplete = t36;
160
- let t37;
161
- if ($[9] !== types) {
162
- t37 = types !== null ? types.join(".") : ["audio", "image", "video"].join(".");
163
- $[9] = types;
164
- $[10] = t37;
165
- } else {
166
- t37 = $[10];
167
- }
168
- const typesString = t37;
169
- let t38;
170
- bb0: {
171
- if (fileTypes !== null) {
172
- t38 = fileTypes;
173
- break bb0;
87
+ } else if (response && response.successful) {
88
+ newValue_0 = response.successful.length > 0 ? response.successful[0].response.body : null;
174
89
  }
175
- let t39;
176
- if ($[11] !== typesString) {
177
- t39 = typesString.split(".").map(_temp2);
178
- $[11] = typesString;
179
- $[12] = t39;
180
- } else {
181
- t39 = $[12];
90
+ if (isArray(newValue_0)) {
91
+ newValue_0 = newValue_0.map(val => mergeData(val));
92
+ } else if (newValue_0 !== null) {
93
+ newValue_0 = mergeData(newValue_0);
182
94
  }
183
- t38 = t39;
184
- }
185
- const allowedFileTypes = t38;
186
- const t39 = allowMultipleUploads && maxNumberOfFiles === 1 ? 50 : maxNumberOfFiles;
187
- let t40;
188
- if ($[13] !== allowMultipleUploads || $[14] !== allowedFileTypes || $[15] !== onComplete || $[16] !== sources || $[17] !== t39 || $[18] !== uppyProps) {
189
- t40 = {
190
- maxNumberOfFiles: t39,
191
- allowedFileTypes,
192
- sources,
193
- ...uppyProps,
194
- allowMultipleUploads,
195
- autoProceed: true,
196
- onComplete
197
- };
198
- $[13] = allowMultipleUploads;
199
- $[14] = allowedFileTypes;
200
- $[15] = onComplete;
201
- $[16] = sources;
202
- $[17] = t39;
203
- $[18] = uppyProps;
204
- $[19] = t40;
205
- } else {
206
- t40 = $[19];
207
- }
208
- const uppyFinalProps = t40;
95
+ if (onChange !== null) {
96
+ onChange(newValue_0);
97
+ }
98
+ }, [onChange, allowMultipleUploads, mergeData]);
99
+ const typesString = useMemo(() => types !== null ? types.join('.') : ['audio', 'image', 'video'].join('.'), [types]);
100
+ const allowedFileTypes = useMemo(() => {
101
+ if (fileTypes !== null) {
102
+ return fileTypes;
103
+ }
104
+ return typesString.split('.').map(type => `${type}/*`);
105
+ }, [typesString, fileTypes]);
106
+ const uppyFinalProps = useMemo(() => ({
107
+ maxNumberOfFiles: allowMultipleUploads && maxNumberOfFiles === 1 ? 50 : maxNumberOfFiles,
108
+ allowedFileTypes,
109
+ sources,
110
+ ...uppyProps,
111
+ allowMultipleUploads,
112
+ autoProceed: true,
113
+ onComplete
114
+ }), [uppyProps, allowedFileTypes, allowMultipleUploads, maxNumberOfFiles, sources, onComplete]);
209
115
  const uppy = useUppy(uppyFinalProps);
210
116
  const [modalOpened, setModalOpened] = useState(false);
211
- let t41;
212
- if ($[20] !== modalOpened) {
213
- t41 = () => {
214
- setModalOpened(!modalOpened);
215
- };
216
- $[20] = modalOpened;
217
- $[21] = t41;
218
- } else {
219
- t41 = $[21];
220
- }
221
- const openModal = t41;
222
- let t42;
223
- if ($[22] !== uppy) {
224
- t42 = () => {
225
- setModalOpened(false);
226
- if (uppy !== null) {
227
- uppy.cancelAll({
228
- reason: "user"
229
- });
230
- }
231
- };
232
- $[22] = uppy;
233
- $[23] = t42;
234
- } else {
235
- t42 = $[23];
236
- }
237
- const closeModal = t42;
238
- let t43;
239
- if ($[24] !== onClear || $[25] !== uppy) {
240
- t43 = () => {
241
- if (onClear !== null) {
242
- onClear();
243
- }
244
- if (uppy !== null) {
245
- uppy.cancelAll({
246
- reason: "user"
247
- });
248
- }
249
- };
250
- $[24] = onClear;
251
- $[25] = uppy;
252
- $[26] = t43;
253
- } else {
254
- t43 = $[26];
255
- }
256
- const onClickClear = t43;
257
- let t44;
258
- if ($[27] !== onChange || $[28] !== value) {
259
- t44 = idx => {
260
- if (onChange !== null && isArray(value) && value.length > 1) {
261
- onChange(value.filter((v, i) => i !== idx));
262
- } else {
263
- if (onChange !== null) {
264
- onChange(null);
265
- }
266
- }
267
- };
268
- $[27] = onChange;
269
- $[28] = value;
270
- $[29] = t44;
271
- } else {
272
- t44 = $[29];
273
- }
274
- const onClickRemove = t44;
275
- let t45;
276
- bb1: {
277
- if (isArray(value)) {
278
- t45 = value;
279
- break bb1;
117
+ const openModal = useCallback(() => {
118
+ setModalOpened(!modalOpened);
119
+ }, [modalOpened, setModalOpened]);
120
+ const closeModal = useCallback(() => {
121
+ setModalOpened(false);
122
+ if (uppy !== null) {
123
+ uppy.cancelAll({
124
+ reason: 'user'
125
+ });
280
126
  }
281
- let t46;
282
- if ($[30] !== value) {
283
- t46 = value !== null ? [value] : null;
284
- $[30] = value;
285
- $[31] = t46;
286
- } else {
287
- t46 = $[31];
127
+ }, [uppy, setModalOpened]);
128
+ const onClickClear = useCallback(() => {
129
+ if (onClear !== null) {
130
+ onClear();
288
131
  }
289
- t45 = t46;
290
- }
291
- const values = t45;
132
+ if (onChange !== null) {
133
+ onChange(null);
134
+ }
135
+ if (uppy !== null) {
136
+ uppy.cancelAll({
137
+ reason: 'user'
138
+ });
139
+ }
140
+ }, [uppy, onClear]);
141
+ const onClickRemove = useCallback(idx => {
142
+ if (onChange !== null && isArray(value) && value.length > 1) {
143
+ onChange(value.filter((v, i) => i !== idx));
144
+ } else if (onChange !== null) {
145
+ onChange(null);
146
+ }
147
+ }, [value, onChange]);
148
+ const values = useMemo(() => {
149
+ if (isArray(value)) {
150
+ return value;
151
+ }
152
+ return value !== null ? [value] : null;
153
+ }, [value]);
154
+
155
+ // Resource-modal-picker
292
156
  const hasMedia = values !== null && values.length > 0;
293
157
  const [resourceModalOpen, setResourceModalOpen] = useState(false);
294
158
  const showResourceModal = resource !== null && withFind && resourceModalOpen;
295
- let t46;
296
- if ($[32] === Symbol.for("react.memo_cache_sentinel")) {
297
- t46 = () => {
298
- setResourceModalOpen(true);
299
- };
300
- $[32] = t46;
301
- } else {
302
- t46 = $[32];
303
- }
304
- const openResourceModal = t46;
305
- let t47;
306
- if ($[33] === Symbol.for("react.memo_cache_sentinel")) {
307
- t47 = [];
308
- $[33] = t47;
309
- } else {
310
- t47 = $[33];
311
- }
312
- const [modalItems, setModalItems] = useState(t47);
313
- let t48;
314
- if ($[34] === Symbol.for("react.memo_cache_sentinel")) {
315
- t48 = () => {
316
- setResourceModalOpen(false);
317
- setModalItems([]);
318
- };
319
- $[34] = t48;
320
- } else {
321
- t48 = $[34];
322
- }
323
- const closeResourceModal = t48;
324
- let t49;
325
- if ($[35] !== onClickFind) {
326
- t49 = () => {
327
- if (onClickFind !== null) {
328
- onClickFind();
329
- } else {
330
- openResourceModal();
331
- }
332
- };
333
- $[35] = onClickFind;
334
- $[36] = t49;
335
- } else {
336
- t49 = $[36];
337
- }
338
- const finalOnClickFind = t49;
339
- let t50;
340
- if ($[37] !== allowMultipleUploads || $[38] !== modalItems) {
341
- t50 = newValue_1 => {
342
- if (allowMultipleUploads) {
343
- if (newValue_1 !== null && !isArray(newValue_1)) {
344
- const {
345
- id: t51
346
- } = newValue_1 || {};
347
- const id = t51 === undefined ? null : t51;
348
- if (id !== null) {
349
- const previous = (modalItems || []).find(t52 => {
350
- const {
351
- id: t53
352
- } = t52 === undefined ? {} : t52;
353
- const itemId = t53 === undefined ? null : t53;
354
- return id === itemId;
355
- });
356
- if (previous) {
357
- setModalItems((modalItems || []).filter(t54 => {
358
- const {
359
- id: t55
360
- } = t54 === undefined ? {} : t54;
361
- const itemId_0 = t55 === undefined ? null : t55;
362
- return id !== itemId_0;
363
- }));
364
- } else {
365
- setModalItems([...(modalItems || []), newValue_1]);
366
- }
367
- }
368
- } else {
369
- if (newValue_1 !== null && isArray(newValue_1)) {
370
- setModalItems(newValue_1);
159
+ const openResourceModal = useCallback(() => {
160
+ setResourceModalOpen(true);
161
+ }, [resourceModalOpen, setResourceModalOpen]);
162
+ const [modalItems, setModalItems] = useState([]);
163
+ const closeResourceModal = useCallback(() => {
164
+ setResourceModalOpen(false);
165
+ setModalItems([]);
166
+ }, [resourceModalOpen, setResourceModalOpen, setModalItems]);
167
+ const finalOnClickFind = useCallback(() => {
168
+ if (onClickFind !== null) {
169
+ onClickFind();
170
+ } else {
171
+ openResourceModal();
172
+ }
173
+ }, [onClickFind, openResourceModal]);
174
+ const onSelectionChange = useCallback(newValue_1 => {
175
+ if (allowMultipleUploads) {
176
+ if (newValue_1 !== null && !isArray(newValue_1)) {
177
+ const {
178
+ id = null
179
+ } = newValue_1 || {};
180
+ if (id !== null) {
181
+ const previous = (modalItems || []).find(({
182
+ id: itemId = null
183
+ } = {}) => id === itemId);
184
+ if (previous) {
185
+ setModalItems((modalItems || []).filter(({
186
+ id: itemId_0 = null
187
+ } = {}) => id !== itemId_0));
188
+ } else {
189
+ setModalItems([...(modalItems || []), newValue_1]);
371
190
  }
372
191
  }
373
- } else {
192
+ } else if (newValue_1 !== null && isArray(newValue_1)) {
374
193
  setModalItems(newValue_1);
375
194
  }
376
- };
377
- $[37] = allowMultipleUploads;
378
- $[38] = modalItems;
379
- $[39] = t50;
380
- } else {
381
- t50 = $[39];
382
- }
383
- const onSelectionChange = t50;
384
- let t51;
385
- if ($[40] !== modalItems || $[41] !== onChange) {
386
- t51 = () => {
387
- if (onChange !== null) {
388
- onChange(modalItems);
389
- setResourceModalOpen(false);
390
- setModalItems([]);
391
- }
392
- };
393
- $[40] = modalItems;
394
- $[41] = onChange;
395
- $[42] = t51;
396
- } else {
397
- t51 = $[42];
398
- }
399
- const confirmResourceModal = t51;
400
- let t52;
401
- if ($[43] !== types) {
402
- t52 = {
403
- types
404
- };
405
- $[43] = types;
406
- $[44] = t52;
407
- } else {
408
- t52 = $[44];
409
- }
410
- const initialQuery = t52;
195
+ } else {
196
+ setModalItems(newValue_1);
197
+ }
198
+ }, [onChange, setResourceModalOpen, allowMultipleUploads, modalItems, setModalItems]);
199
+ const confirmResourceModal = useCallback(() => {
200
+ if (onChange !== null) {
201
+ // Always multiple onchange
202
+ onChange(modalItems);
203
+ setResourceModalOpen(false);
204
+ setModalItems([]);
205
+ }
206
+ }, [onChange, setResourceModalOpen, modalItems, allowMultipleUploads, setModalItems]);
207
+ const initialQuery = useMemo(() => ({
208
+ types
209
+ }), [types]);
411
210
  const {
412
211
  query: listQuery,
413
212
  onPageChange: onListPageChange,
414
213
  onQueryChange: onListQueryChange,
415
214
  onQueryReset: onListQueryReset
416
215
  } = useQuery(initialQuery, true);
417
- let t53;
418
- if ($[45] !== onListPageChange) {
419
- t53 = (e, t54) => {
420
- const pageNumber = t54 === undefined ? null : t54;
421
- e.preventDefault();
422
- e.stopPropagation();
423
- onListPageChange(pageNumber);
424
- };
425
- $[45] = onListPageChange;
426
- $[46] = t53;
427
- } else {
428
- t53 = $[46];
429
- }
430
- const finalOnPageChange = t53;
431
- let t54;
432
- if ($[47] !== onListQueryChange) {
433
- t54 = newQuery => {
434
- onListQueryChange(newQuery);
435
- };
436
- $[47] = onListQueryChange;
437
- $[48] = t54;
438
- } else {
439
- t54 = $[48];
440
- }
441
- const finalOnQueryChange = t54;
216
+ const finalOnPageChange = useCallback((e, pageNumber = null) => {
217
+ e.preventDefault();
218
+ e.stopPropagation();
219
+ onListPageChange(pageNumber);
220
+ }, [onListPageChange]);
221
+ const finalOnQueryChange = useCallback(newQuery => {
222
+ onListQueryChange(newQuery);
223
+ }, [onListQueryChange]);
442
224
  const containerRef = useRef(null);
225
+
226
+ // Keep this stable, uppy doesnt like changes
443
227
  const [finalUppy, setFinalUppy] = useState(null);
444
- let t55;
445
- let t56;
446
- if ($[49] !== finalUppy || $[50] !== uppy) {
447
- t55 = () => {
448
- if (uppy !== null && finalUppy === null) {
449
- setFinalUppy(uppy);
450
- }
451
- };
452
- t56 = [uppy, finalUppy];
453
- $[49] = finalUppy;
454
- $[50] = uppy;
455
- $[51] = t55;
456
- $[52] = t56;
457
- } else {
458
- t55 = $[51];
459
- t56 = $[52];
460
- }
461
- useEffect(t55, t56);
228
+ useEffect(() => {
229
+ if (uppy !== null && finalUppy === null) {
230
+ setFinalUppy(uppy);
231
+ }
232
+ }, [uppy, finalUppy]);
233
+
234
+ // Uppy state
462
235
  const [loading, setLoading] = useState(false);
463
- let t57;
464
- if ($[53] === Symbol.for("react.memo_cache_sentinel")) {
465
- t57 = () => {
466
- setLoading(true);
467
- };
468
- $[53] = t57;
469
- } else {
470
- t57 = $[53];
471
- }
472
- const startLoading = t57;
473
- let t58;
474
- if ($[54] === Symbol.for("react.memo_cache_sentinel")) {
475
- t58 = () => {
476
- setLoading(false);
477
- };
478
- $[54] = t58;
479
- } else {
480
- t58 = $[54];
481
- }
482
- const endLoading = t58;
483
- let t59;
484
- let t60;
485
- if ($[55] !== uppy) {
486
- t59 = () => {
236
+ const startLoading = useCallback(() => {
237
+ setLoading(true);
238
+ }, []);
239
+ const endLoading = useCallback(() => {
240
+ setLoading(false);
241
+ }, []);
242
+ useEffect(() => {
243
+ if (uppy !== null) {
244
+ uppy.on('upload', startLoading);
245
+ uppy.on('complete', endLoading);
246
+ uppy.on('upload-error', endLoading);
247
+ uppy.on('error', endLoading);
248
+ uppy.on('cancell-all', endLoading);
249
+ }
250
+ return () => {
487
251
  if (uppy !== null) {
488
- uppy.on("upload", startLoading);
489
- uppy.on("complete", endLoading);
490
- uppy.on("upload-error", endLoading);
491
- uppy.on("error", endLoading);
492
- uppy.on("cancell-all", endLoading);
252
+ uppy.off('upload', startLoading);
253
+ uppy.off('complete', endLoading);
254
+ uppy.off('upload-error', endLoading);
255
+ uppy.off('error', endLoading);
256
+ uppy.off('cancell-all', endLoading);
493
257
  }
494
- return () => {
495
- if (uppy !== null) {
496
- uppy.off("upload", startLoading);
497
- uppy.off("complete", endLoading);
498
- uppy.off("upload-error", endLoading);
499
- uppy.off("error", endLoading);
500
- uppy.off("cancell-all", endLoading);
501
- }
502
- };
503
258
  };
504
- t60 = [uppy, startLoading, endLoading];
505
- $[55] = uppy;
506
- $[56] = t59;
507
- $[57] = t60;
508
- } else {
509
- t59 = $[56];
510
- t60 = $[57];
511
- }
512
- useEffect(t59, t60);
259
+ }, [uppy, startLoading, endLoading]);
513
260
  const finalLoading = loading || parentLoading;
514
- const t61 = className !== null;
515
- let t62;
516
- if ($[58] !== className || $[59] !== t61) {
517
- t62 = classNames([styles.container, {
518
- [className]: t61
519
- }]);
520
- $[58] = className;
521
- $[59] = t61;
522
- $[60] = t62;
523
- } else {
524
- t62 = $[60];
525
- }
526
- let t63;
527
- if ($[61] !== disabled || $[62] !== hasMedia || $[63] !== linkPath || $[64] !== namePath || $[65] !== onClickRemove || $[66] !== sizePath || $[67] !== thumbnailPath || $[68] !== values || $[69] !== withoutMedia) {
528
- t63 = !withoutMedia && hasMedia ? /*#__PURE__*/jsx(MediaCards, {
261
+ return /*#__PURE__*/jsxs("div", {
262
+ className: className,
263
+ ref: containerRef,
264
+ children: [!withoutMedia && hasMedia ? /*#__PURE__*/jsx(MediaCards, {
529
265
  value: values,
530
266
  namePath: namePath,
531
267
  thumbnailPath: thumbnailPath,
@@ -533,59 +269,60 @@ function UploadField(t0) {
533
269
  linkPath: linkPath,
534
270
  disabled: disabled,
535
271
  onClickRemove: onClickRemove
536
- }) : null;
537
- $[61] = disabled;
538
- $[62] = hasMedia;
539
- $[63] = linkPath;
540
- $[64] = namePath;
541
- $[65] = onClickRemove;
542
- $[66] = sizePath;
543
- $[67] = thumbnailPath;
544
- $[68] = values;
545
- $[69] = withoutMedia;
546
- $[70] = t63;
547
- } else {
548
- t63 = $[70];
549
- }
550
- let t64;
551
- if ($[71] !== clearButtonLabel || $[72] !== hasMedia || $[73] !== onClickClear || $[74] !== withClearButton || $[75] !== withoutMedia) {
552
- t64 = !withoutMedia && hasMedia && withClearButton ? /*#__PURE__*/jsx("div", {
553
- className: "row mt-2",
554
- children: /*#__PURE__*/jsx("div", {
555
- className: "col-auto",
556
- children: /*#__PURE__*/jsx(Button, {
557
- type: "button",
558
- theme: "primary",
559
- onClick: onClickClear,
560
- children: /*#__PURE__*/jsx(Label, {
561
- children: clearButtonLabel
562
- })
272
+ }) : null, /*#__PURE__*/jsxs("div", {
273
+ className: classNames('d-flex'),
274
+ children: [withClearButton && !withoutMedia && hasMedia ? /*#__PURE__*/jsx(Button, {
275
+ type: "button",
276
+ theme: "primary",
277
+ onClick: onClickClear,
278
+ children: /*#__PURE__*/jsx(Label, {
279
+ children: clearButtonLabel
563
280
  })
564
- })
565
- }) : null;
566
- $[71] = clearButtonLabel;
567
- $[72] = hasMedia;
568
- $[73] = onClickClear;
569
- $[74] = withClearButton;
570
- $[75] = withoutMedia;
571
- $[76] = t64;
572
- } else {
573
- t64 = $[76];
574
- }
575
- let t65;
576
- if ($[77] !== closeAfterFinish || $[78] !== closeModal || $[79] !== finalUppy || $[80] !== hasMedia || $[81] !== height || $[82] !== modalOpened || $[83] !== showResourceModal || $[84] !== sources || $[85] !== uploadDisabled || $[86] !== width || $[87] !== withButton) {
577
- t65 = finalUppy !== null ? /*#__PURE__*/jsxs(UppyContextProvider, {
281
+ }) : null, withButton && (withoutMedia || !hasMedia || allowMultipleUploads) ? /*#__PURE__*/jsx(Button, {
282
+ type: "button",
283
+ theme: "primary",
284
+ icon: finalLoading ? 'loading' : 'upload',
285
+ iconPosition: "right",
286
+ onClick: onClickAdd || openModal,
287
+ disabled: finalLoading || disabled,
288
+ outline: outline,
289
+ className: classNames([{
290
+ 'me-2': withFind
291
+ }]),
292
+ children: /*#__PURE__*/jsx(Label, {
293
+ children: finalLoading ? /*#__PURE__*/jsx(FormattedMessage, {
294
+ id: "NozDYd"
295
+ }) : addButtonLabel
296
+ })
297
+ }) : null, withFind && (withoutMedia || !hasMedia || allowMultipleUploads) ? /*#__PURE__*/jsx(Button, {
298
+ type: "button",
299
+ theme: "primary",
300
+ icon: "search",
301
+ iconPosition: "right",
302
+ onClick: finalOnClickFind,
303
+ disabled: disabled,
304
+ outline: outline,
305
+ children: /*#__PURE__*/jsx(Label, {
306
+ children: findButtonLabel
307
+ })
308
+ }) : null]
309
+ }), finalUppy !== null ? /*#__PURE__*/jsxs(UppyContextProvider, {
578
310
  uppy: finalUppy,
579
311
  children: [!uploadDisabled && !hasMedia && !withButton && finalUppy !== null ? /*#__PURE__*/jsx("div", {
580
312
  className: styles.dashboard,
581
313
  children: /*#__PURE__*/jsx(Dashboard, {
582
- uppy: finalUppy,
314
+ uppy: finalUppy
315
+ // {...(containerWidth !== null && height !== null
316
+ // ? { width: containerWidth }
317
+ // : null)}
318
+ ,
583
319
  ...(width !== null ? {
584
320
  width
585
321
  } : null),
586
322
  ...(height !== null ? {
587
323
  height
588
324
  } : null),
325
+ disabled: disabled,
589
326
  plugins: sources,
590
327
  inline: true,
591
328
  showProgressDetails: true,
@@ -596,6 +333,7 @@ function UploadField(t0) {
596
333
  uppy: finalUppy,
597
334
  className: styles.dashboardModal,
598
335
  plugins: sources,
336
+ disabled: disabled,
599
337
  open: true,
600
338
  onRequestClose: closeModal,
601
339
  proudlyDisplayPoweredByUppy: false,
@@ -607,79 +345,7 @@ function UploadField(t0) {
607
345
  doneButtonHandler: closeModal,
608
346
  closeAfterFinish: closeAfterFinish
609
347
  }) : null]
610
- }) : null;
611
- $[77] = closeAfterFinish;
612
- $[78] = closeModal;
613
- $[79] = finalUppy;
614
- $[80] = hasMedia;
615
- $[81] = height;
616
- $[82] = modalOpened;
617
- $[83] = showResourceModal;
618
- $[84] = sources;
619
- $[85] = uploadDisabled;
620
- $[86] = width;
621
- $[87] = withButton;
622
- $[88] = t65;
623
- } else {
624
- t65 = $[88];
625
- }
626
- let t66;
627
- if ($[89] !== addButtonLabel || $[90] !== allowMultipleUploads || $[91] !== disabled || $[92] !== finalLoading || $[93] !== finalOnClickFind || $[94] !== findButtonLabel || $[95] !== hasMedia || $[96] !== onClickAdd || $[97] !== openModal || $[98] !== outline || $[99] !== withButton || $[100] !== withFind || $[101] !== withoutMedia) {
628
- t66 = withoutMedia || (!hasMedia || allowMultipleUploads) && (withButton || withFind) ? /*#__PURE__*/jsxs("div", {
629
- className: "row",
630
- children: [withButton ? /*#__PURE__*/jsx("div", {
631
- className: "col-auto mb-2 pe-0",
632
- children: /*#__PURE__*/jsx(Button, {
633
- id: "trigger-uppy",
634
- type: "button",
635
- theme: "primary",
636
- icon: finalLoading ? "loading" : "upload",
637
- iconPosition: "right",
638
- onClick: onClickAdd || openModal,
639
- disabled: finalLoading || disabled,
640
- outline: outline,
641
- children: /*#__PURE__*/jsx(Label, {
642
- children: finalLoading ? /*#__PURE__*/jsx(FormattedMessage, {
643
- id: "NozDYd"
644
- }) : addButtonLabel
645
- })
646
- })
647
- }) : null, withFind ? /*#__PURE__*/jsx("div", {
648
- className: "col-auto mb-2",
649
- children: /*#__PURE__*/jsx(Button, {
650
- type: "button",
651
- theme: "primary",
652
- icon: "search",
653
- iconPosition: "right",
654
- onClick: finalOnClickFind,
655
- disabled: disabled,
656
- outline: outline,
657
- children: /*#__PURE__*/jsx(Label, {
658
- children: findButtonLabel
659
- })
660
- })
661
- }) : null]
662
- }) : null;
663
- $[89] = addButtonLabel;
664
- $[90] = allowMultipleUploads;
665
- $[91] = disabled;
666
- $[92] = finalLoading;
667
- $[93] = finalOnClickFind;
668
- $[94] = findButtonLabel;
669
- $[95] = hasMedia;
670
- $[96] = onClickAdd;
671
- $[97] = openModal;
672
- $[98] = outline;
673
- $[99] = withButton;
674
- $[100] = withFind;
675
- $[101] = withoutMedia;
676
- $[102] = t66;
677
- } else {
678
- t66 = $[102];
679
- }
680
- let t67;
681
- if ($[103] !== allowMultipleUploads || $[104] !== confirmResourceModal || $[105] !== disabled || $[106] !== finalOnPageChange || $[107] !== finalOnQueryChange || $[108] !== listQuery || $[109] !== modalItems || $[110] !== name || $[111] !== onListQueryReset || $[112] !== onSelectionChange || $[113] !== resource || $[114] !== showResourceModal) {
682
- t67 = showResourceModal ? /*#__PURE__*/jsx(ModalResourceItems, {
348
+ }) : null, showResourceModal ? /*#__PURE__*/jsx(ModalResourceItems, {
683
349
  id: `upload-${name}`,
684
350
  resource: resource,
685
351
  query: listQuery,
@@ -721,53 +387,8 @@ function UploadField(t0) {
721
387
  })]
722
388
  })]
723
389
  })
724
- }) : null;
725
- $[103] = allowMultipleUploads;
726
- $[104] = confirmResourceModal;
727
- $[105] = disabled;
728
- $[106] = finalOnPageChange;
729
- $[107] = finalOnQueryChange;
730
- $[108] = listQuery;
731
- $[109] = modalItems;
732
- $[110] = name;
733
- $[111] = onListQueryReset;
734
- $[112] = onSelectionChange;
735
- $[113] = resource;
736
- $[114] = showResourceModal;
737
- $[115] = t67;
738
- } else {
739
- t67 = $[115];
740
- }
741
- let t68;
742
- if ($[116] !== t62 || $[117] !== t63 || $[118] !== t64 || $[119] !== t65 || $[120] !== t66 || $[121] !== t67) {
743
- t68 = /*#__PURE__*/jsxs("div", {
744
- className: t62,
745
- ref: containerRef,
746
- children: [t63, t64, t65, t66, t67]
747
- });
748
- $[116] = t62;
749
- $[117] = t63;
750
- $[118] = t64;
751
- $[119] = t65;
752
- $[120] = t66;
753
- $[121] = t67;
754
- $[122] = t68;
755
- } else {
756
- t68 = $[122];
757
- }
758
- return t68;
759
- }
760
- function _temp2(type) {
761
- return `${type}/*`;
762
- }
763
- function _temp(newValue) {
764
- if (isObject(newValue) && isObject(newValue.response) && newValue.response.status === 200 && newValue.response.body !== null) {
765
- return {
766
- ...newValue,
767
- ...(newValue.response.body || null)
768
- };
769
- }
770
- return newValue;
390
+ }) : null]
391
+ });
771
392
  }
772
393
 
773
394
  var definition = [{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panneau/field-upload",
3
- "version": "4.0.48",
3
+ "version": "4.0.55",
4
4
  "description": "An Upload field",
5
5
  "keywords": [
6
6
  "javascript"
@@ -67,13 +67,13 @@
67
67
  "@fortawesome/fontawesome-svg-core": "^6.5.1",
68
68
  "@fortawesome/free-solid-svg-icons": "^6.5.1",
69
69
  "@fortawesome/react-fontawesome": "^0.2.0",
70
- "@panneau/core": "^4.0.48",
71
- "@panneau/element-button": "^4.0.48",
72
- "@panneau/element-label": "^4.0.48",
73
- "@panneau/element-media-card": "^4.0.48",
74
- "@panneau/modal-resource-items": "^4.0.48",
75
- "@panneau/themes": "^4.0.48",
76
- "@panneau/uppy": "^4.0.48",
70
+ "@panneau/core": "^4.0.55",
71
+ "@panneau/element-button": "^4.0.55",
72
+ "@panneau/element-label": "^4.0.55",
73
+ "@panneau/element-media-card": "^4.0.55",
74
+ "@panneau/modal-resource-items": "^4.0.55",
75
+ "@panneau/themes": "^4.0.55",
76
+ "@panneau/uppy": "^4.0.55",
77
77
  "@uppy/core": "^5.1.1",
78
78
  "@uppy/dashboard": "^5.0.4",
79
79
  "@uppy/react": "^5.1.1",
@@ -86,5 +86,5 @@
86
86
  "publishConfig": {
87
87
  "access": "public"
88
88
  },
89
- "gitHead": "668d90a05a094fe55fcea760df3f9c294c6cbb31"
89
+ "gitHead": "1c9183567fc5bf98ba10fa57c63cf2ed2ae4a054"
90
90
  }