@panneau/fields 5.0.0-alpha.2 → 5.0.0-alpha.4

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.
Files changed (62) hide show
  1. package/README.md +36 -1
  2. package/dist/file/FileField.css +54 -0
  3. package/dist/file/FileField.d.ts +50 -0
  4. package/dist/file/FileField.d.ts.map +1 -0
  5. package/dist/file/FileField.js +198 -0
  6. package/dist/file/FileField.js.map +1 -0
  7. package/dist/file/FileField.module.js +22 -0
  8. package/dist/file/FileField.module.js.map +1 -0
  9. package/dist/file/index.d.ts +3 -0
  10. package/dist/file/index.d.ts.map +1 -0
  11. package/dist/file/index.js +1 -0
  12. package/dist/index.d.ts +8 -1
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +8 -2
  15. package/dist/shared/builtIn.d.ts +3 -2
  16. package/dist/shared/builtIn.d.ts.map +1 -1
  17. package/dist/shared/builtIn.js +5 -2
  18. package/dist/shared/builtIn.js.map +1 -1
  19. package/dist/shared/context.d.ts +10 -2
  20. package/dist/shared/context.d.ts.map +1 -1
  21. package/dist/shared/context.js +22 -18
  22. package/dist/shared/context.js.map +1 -1
  23. package/dist/shared/entry.d.ts +4 -0
  24. package/dist/shared/entry.d.ts.map +1 -1
  25. package/dist/shared/entry.js +12 -1
  26. package/dist/shared/entry.js.map +1 -1
  27. package/dist/upload/FilePicker.css +24 -0
  28. package/dist/upload/FilePicker.d.ts +14 -0
  29. package/dist/upload/FilePicker.d.ts.map +1 -0
  30. package/dist/upload/FilePicker.js +47 -0
  31. package/dist/upload/FilePicker.js.map +1 -0
  32. package/dist/upload/FilePicker.module.js +12 -0
  33. package/dist/upload/FilePicker.module.js.map +1 -0
  34. package/dist/upload/UploadList.css +93 -0
  35. package/dist/upload/UploadList.d.ts +18 -0
  36. package/dist/upload/UploadList.d.ts.map +1 -0
  37. package/dist/upload/UploadList.js +144 -0
  38. package/dist/upload/UploadList.js.map +1 -0
  39. package/dist/upload/UploadList.module.js +32 -0
  40. package/dist/upload/UploadList.module.js.map +1 -0
  41. package/dist/upload/files.d.ts +5 -0
  42. package/dist/upload/files.d.ts.map +1 -0
  43. package/dist/upload/files.js +26 -0
  44. package/dist/upload/files.js.map +1 -0
  45. package/dist/upload/types.d.ts +58 -0
  46. package/dist/upload/types.d.ts.map +1 -0
  47. package/dist/upload/useRejectionMessage.d.ts +4 -0
  48. package/dist/upload/useRejectionMessage.d.ts.map +1 -0
  49. package/dist/upload/useRejectionMessage.js +25 -0
  50. package/dist/upload/useRejectionMessage.js.map +1 -0
  51. package/dist/upload/useUploads.d.ts +30 -0
  52. package/dist/upload/useUploads.d.ts.map +1 -0
  53. package/dist/upload/useUploads.js +115 -0
  54. package/dist/upload/useUploads.js.map +1 -0
  55. package/dist/uppy/index.d.ts +3 -0
  56. package/dist/uppy/index.d.ts.map +1 -0
  57. package/dist/uppy/index.js +1 -0
  58. package/dist/uppy/uploader.d.ts +44 -0
  59. package/dist/uppy/uploader.d.ts.map +1 -0
  60. package/dist/uppy/uploader.js +139 -0
  61. package/dist/uppy/uploader.js.map +1 -0
  62. package/package.json +30 -5
@@ -0,0 +1,26 @@
1
+ //#region src/upload/files.ts
2
+ /** Whether a MIME type matches one of the patterns of an `accept` rule (`image/*`, `application/pdf`). */
3
+ function matchesMime(mime, patterns) {
4
+ return patterns.some((pattern) => pattern.endsWith("/*") ? mime.startsWith(pattern.slice(0, -1)) : mime === pattern);
5
+ }
6
+ var UNITS = [
7
+ "B",
8
+ "KB",
9
+ "MB",
10
+ "GB",
11
+ "TB"
12
+ ];
13
+ /** A size in bytes, for people: `1.5 MB`. Uses the locale's number format. */
14
+ function formatSize(bytes, locale) {
15
+ let value = bytes;
16
+ let unit = 0;
17
+ while (value >= 1024 && unit < UNITS.length - 1) {
18
+ value /= 1024;
19
+ unit += 1;
20
+ }
21
+ return `${new Intl.NumberFormat(locale, { maximumFractionDigits: unit === 0 || value >= 10 ? 0 : 1 }).format(value)} ${UNITS[unit] ?? "B"}`;
22
+ }
23
+ //#endregion
24
+ export { formatSize, matchesMime };
25
+
26
+ //# sourceMappingURL=files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"files.js","names":[],"sources":["../../src/upload/files.ts"],"sourcesContent":["/** Whether a MIME type matches one of the patterns of an `accept` rule (`image/*`, `application/pdf`). */\nexport function matchesMime(mime: string, patterns: readonly string[]): boolean {\n return patterns.some((pattern) =>\n pattern.endsWith('/*') ? mime.startsWith(pattern.slice(0, -1)) : mime === pattern,\n );\n}\n\nconst UNITS = ['B', 'KB', 'MB', 'GB', 'TB'] as const;\n\n/** A size in bytes, for people: `1.5 MB`. Uses the locale's number format. */\nexport function formatSize(bytes: number, locale?: string): string {\n let value = bytes;\n let unit = 0;\n while (value >= 1024 && unit < UNITS.length - 1) {\n value /= 1024;\n unit += 1;\n }\n const number = new Intl.NumberFormat(locale, {\n maximumFractionDigits: unit === 0 || value >= 10 ? 0 : 1,\n }).format(value);\n return `${number} ${UNITS[unit] ?? 'B'}`;\n}\n"],"mappings":";;AACA,SAAgB,YAAY,MAAc,UAAsC;CAC5E,OAAO,SAAS,MAAM,YAClB,QAAQ,SAAS,IAAI,IAAI,KAAK,WAAW,QAAQ,MAAM,GAAG,EAAE,CAAC,IAAI,SAAS,OAC9E;AACJ;AAEA,IAAM,QAAQ;CAAC;CAAK;CAAM;CAAM;CAAM;AAAI;;AAG1C,SAAgB,WAAW,OAAe,QAAyB;CAC/D,IAAI,QAAQ;CACZ,IAAI,OAAO;CACX,OAAO,SAAS,QAAQ,OAAO,MAAM,SAAS,GAAG;EAC7C,SAAS;EACT,QAAQ;CACZ;CAIA,OAAO,GAHQ,IAAI,KAAK,aAAa,QAAQ,EACzC,uBAAuB,SAAS,KAAK,SAAS,KAAK,IAAI,EAC3D,CAAC,CAAC,CAAC,OAAO,KACA,EAAM,GAAI,MAAM,SAAS;AACvC"}
@@ -0,0 +1,58 @@
1
+ /** Where a file is: sent to storage, paused, completed with the backend, or failed. */
2
+ export type UploadItemStatus = 'uploading' | 'paused' | 'completing' | 'failed';
3
+ /** A file being uploaded, as an upload list shows it. */
4
+ export interface UploadItem {
5
+ id: string;
6
+ name: string;
7
+ size: number | null;
8
+ mime: string | null;
9
+ /** From 0 to 1, or null until the upload reports one. */
10
+ progress: number | null;
11
+ status: UploadItemStatus;
12
+ /** Why it failed. */
13
+ error: string | null;
14
+ /** Whether it can pause: only a file sent in parts can. */
15
+ canPause: boolean;
16
+ }
17
+ /**
18
+ * A file uploaded directly to storage: the reference that values send (`{ upload }`), with what
19
+ * the browser knows of the file, so that fields can show it and check it before saving. Backends
20
+ * only trust `upload`.
21
+ */
22
+ export interface UploadedFile {
23
+ upload: string;
24
+ name: string;
25
+ mime: string | null;
26
+ size: number | null;
27
+ }
28
+ /** Why a file was refused before it was sent. */
29
+ export type UploadRejection = 'accept' | 'maxSize';
30
+ /** Uploads files and keeps their state, for an upload list. */
31
+ export interface Uploader {
32
+ /** The files being uploaded, in the order they were added. Done files leave the list. */
33
+ getItems(): readonly UploadItem[];
34
+ /** Calls the listener when the items change. Returns a function that unsubscribes. */
35
+ subscribe(listener: () => void): () => void;
36
+ /** Sends files. */
37
+ add(files: Iterable<File>): void;
38
+ pause(id: string): void;
39
+ resume(id: string): void;
40
+ /** Stops a file and removes it from the list. */
41
+ cancel(id: string): void;
42
+ /** Sends a failed file again. */
43
+ retry(id: string): void;
44
+ /** Stops every upload. The uploader can't be used after. */
45
+ destroy(): void;
46
+ }
47
+ /**
48
+ * Where fields that take files upload them directly to storage (decision 0025):
49
+ * `createUppyUploadSource()` of `@panneau/fields/uppy`, with the signing routes of the backend.
50
+ * Without one, fields give the files themselves, which the adapter sends in `multipart/form-data`.
51
+ */
52
+ export interface UploadSource {
53
+ /** An uploader for a field, which calls `onUploaded` with each file once it is uploaded. */
54
+ createUploader(options: {
55
+ onUploaded: (file: UploadedFile) => void;
56
+ }): Uploader;
57
+ }
58
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
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GAAG,IAAI,CAAC;IACzB,iCAAiC;IACjC,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,4DAA4D;IAC5D,OAAO,IAAI,IAAI,CAAC;CACnB;AAED;;;;GAIG;AACH,MAAM,WAAW,YAAY;IACzB,4FAA4F;IAC5F,cAAc,CAAC,OAAO,EAAE;QAAE,UAAU,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,IAAI,CAAA;KAAE,GAAG,QAAQ,CAAC;CACnF"}
@@ -0,0 +1,4 @@
1
+ import type { UploadRejection } from './types';
2
+ /** The message of a file refused before it was sent, for a field's errors. */
3
+ export declare function useRejectionMessage(maxSize: number | null | undefined): (file: File, reason: UploadRejection) => string;
4
+ //# sourceMappingURL=useRejectionMessage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRejectionMessage.d.ts","sourceRoot":"","sources":["../../src/upload/useRejectionMessage.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,8EAA8E;AAC9E,wBAAgB,mBAAmB,CAC/B,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GACnC,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,eAAe,KAAK,MAAM,CASjD"}
@@ -0,0 +1,25 @@
1
+ import { messages } from "../shared/messages.js";
2
+ import { formatSize } from "./files.js";
3
+ import { c } from "react/compiler-runtime";
4
+ import { usePanneauIntl } from "@panneau/ui";
5
+ //#region src/upload/useRejectionMessage.ts
6
+ /** The message of a file refused before it was sent, for a field's errors. */
7
+ function useRejectionMessage(maxSize) {
8
+ const $ = c(3);
9
+ const intl = usePanneauIntl();
10
+ let t0;
11
+ if ($[0] !== intl || $[1] !== maxSize) {
12
+ t0 = (file, reason) => reason === "accept" ? intl.formatMessage(messages.rejectedType, { name: file.name }) : intl.formatMessage(messages.rejectedSize, {
13
+ name: file.name,
14
+ size: formatSize(maxSize ?? 0, intl.locale)
15
+ });
16
+ $[0] = intl;
17
+ $[1] = maxSize;
18
+ $[2] = t0;
19
+ } else t0 = $[2];
20
+ return t0;
21
+ }
22
+ //#endregion
23
+ export { useRejectionMessage };
24
+
25
+ //# sourceMappingURL=useRejectionMessage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRejectionMessage.js","names":["_c"],"sources":["../../src/upload/useRejectionMessage.ts"],"sourcesContent":["import { usePanneauIntl } from '@panneau/ui';\n\nimport { messages } from '../shared/messages';\nimport { formatSize } from './files';\nimport type { UploadRejection } from './types';\n\n/** The message of a file refused before it was sent, for a field's errors. */\nexport function useRejectionMessage(\n maxSize: number | null | undefined,\n): (file: File, reason: UploadRejection) => string {\n const intl = usePanneauIntl();\n return (file, reason) =>\n reason === 'accept'\n ? intl.formatMessage(messages.rejectedType, { name: file.name })\n : intl.formatMessage(messages.rejectedSize, {\n name: file.name,\n size: formatSize(maxSize ?? 0, intl.locale),\n });\n}\n"],"mappings":";;;;;;AAOA,SAAO,oBAAA,SAAA;CAAA,MAAA,IAAAA,EAAA,CAAA;CAGH,MAAA,OAAa,eAAe;CAAE,IAAA;CAAA,IAAA,EAAA,OAAA,QAAA,EAAA,OAAA,SAAA;EACvB,MAAA,MAAA,WACH,WAAW,WACL,KAAI,cAAe,SAAQ,cAAe,EAAA,MAAQ,KAAI,KAAM,CAI3D,IAHD,KAAI,cAAe,SAAQ,cAAe;GAAA,MAChC,KAAI;GAAK,MACT,WAAW,WAAA,GAAc,KAAI,MAAO;EAC9C,CAAC;EAAC,EAAA,KAAA;EAAA,EAAA,KAAA;EAAA,EAAA,KAAA;CAAA,OAAA,KAAA,EAAA;CAAA,OANL;AAMK"}
@@ -0,0 +1,30 @@
1
+ import type { UploadItem, UploadRejection, UploadSource, UploadedFile } from './types';
2
+ export interface UseUploadsOptions {
3
+ /** Where files are uploaded. Without one, `add()` gives the files themselves. */
4
+ source: UploadSource | null;
5
+ /** Accepted MIME types (`image/*`). Others are refused before they are sent. */
6
+ accept?: readonly string[] | null;
7
+ /** Largest file, in bytes. Larger ones are refused before they are sent. */
8
+ maxSize?: number | null;
9
+ /** Called with each file once it is uploaded: its upload, or the file itself without a source. */
10
+ onUploaded: (file: UploadedFile | File) => void;
11
+ /** Called with each file refused before it was sent. */
12
+ onRejected?: (file: File, reason: UploadRejection) => void;
13
+ }
14
+ export interface UseUploadsResult {
15
+ /** The files being uploaded. */
16
+ items: readonly UploadItem[];
17
+ add: (files: Iterable<File>) => void;
18
+ pause: (id: string) => void;
19
+ resume: (id: string) => void;
20
+ cancel: (id: string) => void;
21
+ retry: (id: string) => void;
22
+ }
23
+ /**
24
+ * Checks files against `accept` and `maxSize`, uploads them through an upload source, and gives
25
+ * the state of each file for an upload list. Without a source, files are given back as they are,
26
+ * to send in a multipart request. The uploader is made once per source, and stopped when the
27
+ * component unmounts.
28
+ */
29
+ export declare function useUploads(options: UseUploadsOptions): UseUploadsResult;
30
+ //# sourceMappingURL=useUploads.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useUploads.d.ts","sourceRoot":"","sources":["../../src/upload/useUploads.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,YAAY,EAAE,YAAY,EAAY,MAAM,SAAS,CAAC;AAEjG,MAAM,WAAW,iBAAiB;IAC9B,iFAAiF;IACjF,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAC5B,gFAAgF;IAChF,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;IAClC,4EAA4E;IAC5E,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,kGAAkG;IAClG,UAAU,EAAE,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,KAAK,IAAI,CAAC;IAChD,wDAAwD;IACxD,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,eAAe,KAAK,IAAI,CAAC;CAC9D;AAED,MAAM,WAAW,gBAAgB;IAC7B,gCAAgC;IAChC,KAAK,EAAE,SAAS,UAAU,EAAE,CAAC;IAC7B,GAAG,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;IACrC,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5B,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7B,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7B,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/B;AAmBD;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,gBAAgB,CA8CvE"}
@@ -0,0 +1,115 @@
1
+ import { matchesMime } from "./files.js";
2
+ import { c } from "react/compiler-runtime";
3
+ import { useEffect, useRef, useState, useSyncExternalStore } from "react";
4
+ //#region src/upload/useUploads.ts
5
+ var NO_ITEMS = [];
6
+ function rejects(file, { accept, maxSize }) {
7
+ if (accept !== null && accept !== void 0 && accept.length > 0 && !matchesMime(file.type, accept)) return "accept";
8
+ return maxSize !== null && maxSize !== void 0 && file.size > maxSize ? "maxSize" : null;
9
+ }
10
+ /**
11
+ * Checks files against `accept` and `maxSize`, uploads them through an upload source, and gives
12
+ * the state of each file for an upload list. Without a source, files are given back as they are,
13
+ * to send in a multipart request. The uploader is made once per source, and stopped when the
14
+ * component unmounts.
15
+ */
16
+ function useUploads(options) {
17
+ const $ = c(16);
18
+ const latest = useRef(options);
19
+ let t0;
20
+ if ($[0] !== options) {
21
+ t0 = () => {
22
+ latest.current = options;
23
+ };
24
+ $[0] = options;
25
+ $[1] = t0;
26
+ } else t0 = $[1];
27
+ useEffect(t0);
28
+ const { source } = options;
29
+ const [state, setState] = useState(null);
30
+ const uploader = state !== null && state.source === source ? state.uploader : null;
31
+ let t1;
32
+ let t2;
33
+ if ($[2] !== source) {
34
+ t1 = () => {
35
+ if (source === null) return;
36
+ const created = source.createUploader({ onUploaded: (file) => latest.current.onUploaded(file) });
37
+ setState({
38
+ source,
39
+ uploader: created
40
+ });
41
+ return () => created.destroy();
42
+ };
43
+ t2 = [source];
44
+ $[2] = source;
45
+ $[3] = t1;
46
+ $[4] = t2;
47
+ } else {
48
+ t1 = $[3];
49
+ t2 = $[4];
50
+ }
51
+ useEffect(t1, t2);
52
+ let t3;
53
+ let t4;
54
+ if ($[5] !== uploader) {
55
+ t3 = (listener) => uploader?.subscribe(listener) ?? _temp;
56
+ t4 = () => uploader?.getItems() ?? NO_ITEMS;
57
+ $[5] = uploader;
58
+ $[6] = t3;
59
+ $[7] = t4;
60
+ } else {
61
+ t3 = $[6];
62
+ t4 = $[7];
63
+ }
64
+ const items = useSyncExternalStore(t3, t4, _temp2);
65
+ let t5;
66
+ if ($[8] !== items || $[9] !== uploader) {
67
+ let t6;
68
+ let t7;
69
+ let t8;
70
+ let t9;
71
+ if ($[11] !== uploader) {
72
+ t6 = (id) => uploader?.pause(id);
73
+ t7 = (id_0) => uploader?.resume(id_0);
74
+ t8 = (id_1) => uploader?.cancel(id_1);
75
+ t9 = (id_2) => uploader?.retry(id_2);
76
+ $[11] = uploader;
77
+ $[12] = t6;
78
+ $[13] = t7;
79
+ $[14] = t8;
80
+ $[15] = t9;
81
+ } else {
82
+ t6 = $[12];
83
+ t7 = $[13];
84
+ t8 = $[14];
85
+ t9 = $[15];
86
+ }
87
+ t5 = {
88
+ items,
89
+ add(files) {
90
+ for (const file_0 of files) {
91
+ const rejection = rejects(file_0, latest.current);
92
+ if (rejection !== null) latest.current.onRejected?.(file_0, rejection);
93
+ else if (uploader === null) latest.current.onUploaded(file_0);
94
+ else uploader.add([file_0]);
95
+ }
96
+ },
97
+ pause: t6,
98
+ resume: t7,
99
+ cancel: t8,
100
+ retry: t9
101
+ };
102
+ $[8] = items;
103
+ $[9] = uploader;
104
+ $[10] = t5;
105
+ } else t5 = $[10];
106
+ return t5;
107
+ }
108
+ function _temp2() {
109
+ return NO_ITEMS;
110
+ }
111
+ function _temp() {}
112
+ //#endregion
113
+ export { useUploads };
114
+
115
+ //# sourceMappingURL=useUploads.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useUploads.js","names":["id","file","_c"],"sources":["../../src/upload/useUploads.ts"],"sourcesContent":["import { useEffect, useRef, useState, useSyncExternalStore } from 'react';\n\nimport { matchesMime } from './files';\nimport type { UploadItem, UploadRejection, UploadSource, UploadedFile, Uploader } from './types';\n\nexport interface UseUploadsOptions {\n /** Where files are uploaded. Without one, `add()` gives the files themselves. */\n source: UploadSource | null;\n /** Accepted MIME types (`image/*`). Others are refused before they are sent. */\n accept?: readonly string[] | null;\n /** Largest file, in bytes. Larger ones are refused before they are sent. */\n maxSize?: number | null;\n /** Called with each file once it is uploaded: its upload, or the file itself without a source. */\n onUploaded: (file: UploadedFile | File) => void;\n /** Called with each file refused before it was sent. */\n onRejected?: (file: File, reason: UploadRejection) => void;\n}\n\nexport interface UseUploadsResult {\n /** The files being uploaded. */\n items: readonly UploadItem[];\n add: (files: Iterable<File>) => void;\n pause: (id: string) => void;\n resume: (id: string) => void;\n cancel: (id: string) => void;\n retry: (id: string) => void;\n}\n\nconst NO_ITEMS: readonly UploadItem[] = [];\n\nfunction rejects(\n file: File,\n { accept, maxSize }: Pick<UseUploadsOptions, 'accept' | 'maxSize'>,\n): UploadRejection | null {\n if (\n accept !== null &&\n accept !== undefined &&\n accept.length > 0 &&\n !matchesMime(file.type, accept)\n ) {\n return 'accept';\n }\n return maxSize !== null && maxSize !== undefined && file.size > maxSize ? 'maxSize' : null;\n}\n\n/**\n * Checks files against `accept` and `maxSize`, uploads them through an upload source, and gives\n * the state of each file for an upload list. Without a source, files are given back as they are,\n * to send in a multipart request. The uploader is made once per source, and stopped when the\n * component unmounts.\n */\nexport function useUploads(options: UseUploadsOptions): UseUploadsResult {\n // The latest callbacks and limits, read when files are added or uploaded.\n const latest = useRef(options);\n useEffect(() => {\n latest.current = options;\n });\n const { source } = options;\n const [state, setState] = useState<{ source: UploadSource; uploader: Uploader } | null>(null);\n const uploader = state !== null && state.source === source ? state.uploader : null;\n\n useEffect(() => {\n if (source === null) {\n return undefined;\n }\n const created = source.createUploader({\n onUploaded: (file) => latest.current.onUploaded(file),\n });\n setState({ source, uploader: created });\n return () => created.destroy();\n }, [source]);\n\n const items = useSyncExternalStore(\n (listener) => uploader?.subscribe(listener) ?? (() => undefined),\n () => uploader?.getItems() ?? NO_ITEMS,\n () => NO_ITEMS,\n );\n\n return {\n items,\n add(files) {\n for (const file of files) {\n const rejection = rejects(file, latest.current);\n if (rejection !== null) {\n latest.current.onRejected?.(file, rejection);\n } else if (uploader === null) {\n latest.current.onUploaded(file);\n } else {\n uploader.add([file]);\n }\n }\n },\n pause: (id) => uploader?.pause(id),\n resume: (id) => uploader?.resume(id),\n cancel: (id) => uploader?.cancel(id),\n retry: (id) => uploader?.retry(id),\n };\n}\n"],"mappings":";;;;AA4BA,IAAM,WAAkC,CAAA;AAExC,SAAS,QACL,MACA,EAAE,QAAQ,WACY;CACtB,IACI,WAAW,QACX,WAAW,KAAA,KACX,OAAO,SAAS,KAChB,CAAC,YAAY,KAAK,MAAM,MAAM,GAE9B,OAAO;CAEX,OAAO,YAAY,QAAQ,YAAY,KAAA,KAAa,KAAK,OAAO,UAAU,YAAY;AAC1F;;;;;;;AAQA,SAAO,WAAA,SAAA;CAAA,MAAA,IAAAE,EAAA,EAAA;CAEH,MAAA,SAAe,OAAO,OAAO;CAAE,IAAA;CAAA,IAAA,EAAA,OAAA,SAAA;EACrB,WAAA;GACN,OAAM,UAAW;EAAH;EACjB,EAAA,KAAA;EAAA,EAAA,KAAA;CAAA,OAAA,KAAA,EAAA;CAFD,UAAU,EAET;CACD,MAAA,EAAA,WAAmB;CACnB,MAAA,CAAA,OAAA,YAA0B,SAA8D,IAAI;CAC5F,MAAA,WAAiB,UAAU,QAAQ,MAAK,WAAY,SAAS,MAAK,WAAjD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AAc,OAAK;KACpB,MAAA,YAAkB,QAAQC,QAAM,OAAM,OAAQ;KAC9C,IAAI,cAAc,MACd,OAAM,QAAQ,aAAcA,QAAM,SAAS;UACxC,IAAI,aAAa,MACpB,OAAM,QAAQ,WAAYA,MAAI;UAE9B,SAAQ,IAAK,CAACA,MAAI,CAAC;IACtB;GACJ;GAAA,OAEE;GAA2B,QAC1B;GAA4B,QAC5B;GAA4B,OAC7B;EACX;EAAC,EAAA,KAAA;EAAA,EAAA,KAAA;EAAA,EAAA,MAAA;CAAA,OAAA,KAAA,EAAA;CAAA,OAlBM;AAkBN;AA7CE,SAAA,SAAA;CAAA,OAwBO;AAAQ;AAxBf,SAAA,QAAA,CAAA"}
@@ -0,0 +1,3 @@
1
+ export { type PresignedUploadsLike, type UppyUploadSourceOptions, createUppyUploadSource, createUppyUploader, } from './uploader';
2
+ export type { UploadItem, UploadItemStatus, UploadSource, UploadedFile, Uploader, } from '../upload/types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/uppy/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,sBAAsB,EACtB,kBAAkB,GACrB,MAAM,YAAY,CAAC;AACpB,YAAY,EACR,UAAU,EACV,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,QAAQ,GACX,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1 @@
1
+ export { createUppyUploadSource, createUppyUploader } from "./uploader.js";
@@ -0,0 +1,44 @@
1
+ import Uppy, { type Body, type Meta } from '@uppy/core';
2
+ import type { Upload, UploadSignRequest } from '@panneau/protocol';
3
+ import type { UploadSource, UploadedFile, Uploader } from '../upload/types';
4
+ /**
5
+ * Signs and completes direct uploads: `adapter.presignedUploads()` of `@panneau/data` (or
6
+ * `createPresignedUploads()`) gives one.
7
+ */
8
+ export interface PresignedUploadsLike {
9
+ signRequest(request: UploadSignRequest): Promise<{
10
+ url: string;
11
+ key?: string;
12
+ headers?: Record<string, string>;
13
+ }>;
14
+ complete(key: string, options?: {
15
+ name?: string;
16
+ }): Promise<Upload>;
17
+ }
18
+ export interface UppyUploadSourceOptions {
19
+ /** Files larger than this, in bytes, are sent in parts, which can pause and resume. Defaults to 10 MB. */
20
+ multipartThreshold?: number;
21
+ /**
22
+ * Installs what sends files on each Uppy instance: `@uppy/aws-s3` with the backend's
23
+ * signatures by default. Tests install a fake one.
24
+ */
25
+ install?: (uppy: Uppy<Meta, Body>, uploads: PresignedUploadsLike) => void;
26
+ }
27
+ /**
28
+ * An uploader on Uppy 6: files go to S3-compatible storage with URLs that the backend signs, in
29
+ * parts when they are large, then each upload is completed with the backend.
30
+ */
31
+ export declare function createUppyUploader(uploads: PresignedUploadsLike, { onUploaded, multipartThreshold, install, }: UppyUploadSourceOptions & {
32
+ onUploaded: (file: UploadedFile, upload: Upload) => void;
33
+ }): Uploader;
34
+ /**
35
+ * The upload source of fields on Uppy 6 (`@uppy/core` and `@uppy/aws-s3`, optional peer
36
+ * dependencies of this entry point): pass it as `uploadSource` to `FieldsProvider` or
37
+ * `FormView`, with the signing routes of the backend.
38
+ *
39
+ * ```ts
40
+ * const uploadSource = createUppyUploadSource(adapter.presignedUploads());
41
+ * ```
42
+ */
43
+ export declare function createUppyUploadSource(uploads: PresignedUploadsLike, options?: UppyUploadSourceOptions): UploadSource;
44
+ //# sourceMappingURL=uploader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uploader.d.ts","sourceRoot":"","sources":["../../src/uppy/uploader.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,EAAE,EAAE,KAAK,IAAI,EAAE,KAAK,IAAI,EAAiB,MAAM,YAAY,CAAC;AAEvE,OAAO,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEnE,OAAO,KAAK,EAGR,YAAY,EACZ,YAAY,EACZ,QAAQ,EACX,MAAM,iBAAiB,CAAC;AAEzB;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACjC,WAAW,CACP,OAAO,EAAE,iBAAiB,GAC3B,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,CAAC,CAAC;IAC5E,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACvE;AAED,MAAM,WAAW,uBAAuB;IACpC,0GAA0G;IAC1G,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,oBAAoB,KAAK,IAAI,CAAC;CAC7E;AAgBD;;;GAGG;AACH,wBAAgB,kBAAkB,CAC9B,OAAO,EAAE,oBAAoB,EAC7B,EACI,UAAU,EACV,kBAA4B,EAC5B,OAAgF,GACnF,EAAE,uBAAuB,GAAG;IAAE,UAAU,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE,GAC1F,QAAQ,CA+HV;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAClC,OAAO,EAAE,oBAAoB,EAC7B,OAAO,GAAE,uBAA4B,GACtC,YAAY,CAId"}
@@ -0,0 +1,139 @@
1
+ import AwsS3 from "@uppy/aws-s3";
2
+ import Uppy from "@uppy/core";
3
+ //#region src/uppy/uploader.ts
4
+ var MB = 1048576;
5
+ function errorMessage(error) {
6
+ return error instanceof Error ? error.message : String(error);
7
+ }
8
+ function installAwsS3(uppy, uploads, threshold) {
9
+ uppy.use(AwsS3, {
10
+ signRequest: (request) => uploads.signRequest({ ...request }),
11
+ shouldUseMultipart: (file) => (file.size ?? 0) > threshold
12
+ });
13
+ }
14
+ /**
15
+ * An uploader on Uppy 6: files go to S3-compatible storage with URLs that the backend signs, in
16
+ * parts when they are large, then each upload is completed with the backend.
17
+ */
18
+ function createUppyUploader(uploads, { onUploaded, multipartThreshold = 10 * MB, install = (uppy, presigned) => installAwsS3(uppy, presigned, multipartThreshold) }) {
19
+ const uppy = new Uppy({
20
+ autoProceed: true,
21
+ allowMultipleUploadBatches: true
22
+ });
23
+ install(uppy, uploads);
24
+ const completing = /* @__PURE__ */ new Set();
25
+ const failures = /* @__PURE__ */ new Map();
26
+ const listeners = /* @__PURE__ */ new Set();
27
+ let items = [];
28
+ const toItem = (file) => {
29
+ const { bytesUploaded, bytesTotal } = file.progress;
30
+ const failure = failures.get(file.id) ?? null;
31
+ let status = "uploading";
32
+ if (failure !== null) status = "failed";
33
+ else if (completing.has(file.id)) status = "completing";
34
+ else if (file.isPaused === true) status = "paused";
35
+ return {
36
+ id: file.id,
37
+ name: file.name,
38
+ size: file.size,
39
+ mime: file.type !== "" ? file.type : null,
40
+ progress: typeof bytesUploaded === "number" && bytesTotal !== null && bytesTotal > 0 ? Math.min(1, bytesUploaded / bytesTotal) : null,
41
+ status,
42
+ error: failure,
43
+ canPause: (file.size ?? 0) > multipartThreshold
44
+ };
45
+ };
46
+ const update = () => {
47
+ items = uppy.getFiles().map(toItem);
48
+ listeners.forEach((listener) => listener());
49
+ };
50
+ const forget = (id) => {
51
+ completing.delete(id);
52
+ failures.delete(id);
53
+ if (uppy.getFile(id) !== void 0) uppy.removeFile(id);
54
+ };
55
+ uppy.on("state-update", update);
56
+ uppy.on("upload-error", (file, error) => {
57
+ if (file !== void 0) {
58
+ failures.set(file.id, errorMessage(error));
59
+ update();
60
+ }
61
+ });
62
+ uppy.on("upload-success", (file, response) => {
63
+ if (file === void 0) return;
64
+ const key = typeof response.body?.key === "string" ? response.body.key : null;
65
+ if (key === null) {
66
+ failures.set(file.id, "The storage gave no key for this file.");
67
+ update();
68
+ return;
69
+ }
70
+ completing.add(file.id);
71
+ update();
72
+ uploads.complete(key, { name: file.name }).then((upload) => {
73
+ forget(file.id);
74
+ onUploaded({
75
+ upload: upload.id,
76
+ name: upload.name ?? file.name,
77
+ mime: upload.mime ?? (file.type !== "" ? file.type : null),
78
+ size: upload.size ?? file.size
79
+ }, upload);
80
+ }).catch((error) => {
81
+ completing.delete(file.id);
82
+ failures.set(file.id, errorMessage(error));
83
+ update();
84
+ });
85
+ });
86
+ return {
87
+ getItems: () => items,
88
+ subscribe(listener) {
89
+ listeners.add(listener);
90
+ return () => listeners.delete(listener);
91
+ },
92
+ add(files) {
93
+ for (const file of files) uppy.addFile({
94
+ name: file.name,
95
+ type: file.type,
96
+ data: file
97
+ });
98
+ },
99
+ pause(id) {
100
+ if (uppy.getFile(id)?.isPaused !== true) uppy.pauseResume(id);
101
+ },
102
+ resume(id) {
103
+ if (uppy.getFile(id)?.isPaused === true) uppy.pauseResume(id);
104
+ },
105
+ cancel(id) {
106
+ forget(id);
107
+ update();
108
+ },
109
+ retry(id) {
110
+ if (!failures.has(id)) return;
111
+ failures.delete(id);
112
+ update();
113
+ uppy.retryUpload(id);
114
+ },
115
+ destroy() {
116
+ listeners.clear();
117
+ uppy.destroy();
118
+ }
119
+ };
120
+ }
121
+ /**
122
+ * The upload source of fields on Uppy 6 (`@uppy/core` and `@uppy/aws-s3`, optional peer
123
+ * dependencies of this entry point): pass it as `uploadSource` to `FieldsProvider` or
124
+ * `FormView`, with the signing routes of the backend.
125
+ *
126
+ * ```ts
127
+ * const uploadSource = createUppyUploadSource(adapter.presignedUploads());
128
+ * ```
129
+ */
130
+ function createUppyUploadSource(uploads, options = {}) {
131
+ return { createUploader: ({ onUploaded }) => createUppyUploader(uploads, {
132
+ ...options,
133
+ onUploaded
134
+ }) };
135
+ }
136
+ //#endregion
137
+ export { createUppyUploadSource, createUppyUploader };
138
+
139
+ //# sourceMappingURL=uploader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uploader.js","names":[],"sources":["../../src/uppy/uploader.ts"],"sourcesContent":["import AwsS3 from '@uppy/aws-s3';\nimport Uppy, { type Body, type Meta, type UppyFile } from '@uppy/core';\n\nimport type { Upload, UploadSignRequest } from '@panneau/protocol';\n\nimport type {\n UploadItem,\n UploadItemStatus,\n UploadSource,\n UploadedFile,\n Uploader,\n} from '../upload/types';\n\n/**\n * Signs and completes direct uploads: `adapter.presignedUploads()` of `@panneau/data` (or\n * `createPresignedUploads()`) gives one.\n */\nexport interface PresignedUploadsLike {\n signRequest(\n request: UploadSignRequest,\n ): Promise<{ url: string; key?: string; headers?: Record<string, string> }>;\n complete(key: string, options?: { name?: string }): Promise<Upload>;\n}\n\nexport interface UppyUploadSourceOptions {\n /** Files larger than this, in bytes, are sent in parts, which can pause and resume. Defaults to 10 MB. */\n multipartThreshold?: number;\n /**\n * Installs what sends files on each Uppy instance: `@uppy/aws-s3` with the backend's\n * signatures by default. Tests install a fake one.\n */\n install?: (uppy: Uppy<Meta, Body>, uploads: PresignedUploadsLike) => void;\n}\n\nconst MB = 1024 * 1024;\n\nfunction errorMessage(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n\nfunction installAwsS3(uppy: Uppy<Meta, Body>, uploads: PresignedUploadsLike, threshold: number) {\n uppy.use(AwsS3<Meta, Body>, {\n // Uppy's request types are interfaces; the protocol's schema is an open object.\n signRequest: (request) => uploads.signRequest({ ...request }),\n shouldUseMultipart: (file) => (file.size ?? 0) > threshold,\n });\n}\n\n/**\n * An uploader on Uppy 6: files go to S3-compatible storage with URLs that the backend signs, in\n * parts when they are large, then each upload is completed with the backend.\n */\nexport function createUppyUploader(\n uploads: PresignedUploadsLike,\n {\n onUploaded,\n multipartThreshold = 10 * MB,\n install = (uppy, presigned) => installAwsS3(uppy, presigned, multipartThreshold),\n }: UppyUploadSourceOptions & { onUploaded: (file: UploadedFile, upload: Upload) => void },\n): Uploader {\n const uppy = new Uppy<Meta, Body>({ autoProceed: true, allowMultipleUploadBatches: true });\n install(uppy, uploads);\n\n // What Uppy doesn't track: files being completed with the backend, and why one failed.\n const completing = new Set<string>();\n const failures = new Map<string, string>();\n const listeners = new Set<() => void>();\n let items: readonly UploadItem[] = [];\n\n const toItem = (file: UppyFile<Meta, Body>): UploadItem => {\n const { bytesUploaded, bytesTotal } = file.progress;\n const failure = failures.get(file.id) ?? null;\n let status: UploadItemStatus = 'uploading';\n if (failure !== null) {\n status = 'failed';\n } else if (completing.has(file.id)) {\n status = 'completing';\n } else if (file.isPaused === true) {\n status = 'paused';\n }\n return {\n id: file.id,\n name: file.name,\n size: file.size,\n mime: file.type !== '' ? file.type : null,\n progress:\n typeof bytesUploaded === 'number' && bytesTotal !== null && bytesTotal > 0\n ? Math.min(1, bytesUploaded / bytesTotal)\n : null,\n status,\n error: failure,\n canPause: (file.size ?? 0) > multipartThreshold,\n };\n };\n\n const update = () => {\n items = uppy.getFiles().map(toItem);\n listeners.forEach((listener) => listener());\n };\n\n const forget = (id: string) => {\n completing.delete(id);\n failures.delete(id);\n if (uppy.getFile(id) !== undefined) {\n uppy.removeFile(id);\n }\n };\n\n uppy.on('state-update', update);\n uppy.on('upload-error', (file, error) => {\n if (file !== undefined) {\n failures.set(file.id, errorMessage(error));\n update();\n }\n });\n uppy.on('upload-success', (file, response) => {\n if (file === undefined) {\n return;\n }\n const key = typeof response.body?.key === 'string' ? response.body.key : null;\n if (key === null) {\n failures.set(file.id, 'The storage gave no key for this file.');\n update();\n return;\n }\n completing.add(file.id);\n update();\n uploads\n .complete(key, { name: file.name })\n .then((upload) => {\n forget(file.id);\n onUploaded(\n {\n upload: upload.id,\n name: upload.name ?? file.name,\n mime: upload.mime ?? (file.type !== '' ? file.type : null),\n size: upload.size ?? file.size,\n },\n upload,\n );\n })\n .catch((error: unknown) => {\n completing.delete(file.id);\n failures.set(file.id, errorMessage(error));\n update();\n });\n });\n\n return {\n getItems: () => items,\n subscribe(listener) {\n listeners.add(listener);\n return () => listeners.delete(listener);\n },\n add(files) {\n for (const file of files) {\n uppy.addFile({ name: file.name, type: file.type, data: file });\n }\n },\n pause(id) {\n if (uppy.getFile(id)?.isPaused !== true) {\n uppy.pauseResume(id);\n }\n },\n resume(id) {\n if (uppy.getFile(id)?.isPaused === true) {\n uppy.pauseResume(id);\n }\n },\n cancel(id) {\n forget(id);\n update();\n },\n retry(id) {\n if (!failures.has(id)) {\n return;\n }\n failures.delete(id);\n update();\n void uppy.retryUpload(id);\n },\n destroy() {\n listeners.clear();\n uppy.destroy();\n },\n };\n}\n\n/**\n * The upload source of fields on Uppy 6 (`@uppy/core` and `@uppy/aws-s3`, optional peer\n * dependencies of this entry point): pass it as `uploadSource` to `FieldsProvider` or\n * `FormView`, with the signing routes of the backend.\n *\n * ```ts\n * const uploadSource = createUppyUploadSource(adapter.presignedUploads());\n * ```\n */\nexport function createUppyUploadSource(\n uploads: PresignedUploadsLike,\n options: UppyUploadSourceOptions = {},\n): UploadSource {\n return {\n createUploader: ({ onUploaded }) => createUppyUploader(uploads, { ...options, onUploaded }),\n };\n}\n"],"mappings":";;;AAkCA,IAAM,KAAK;AAEX,SAAS,aAAa,OAAwB;CAC1C,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAChE;AAEA,SAAS,aAAa,MAAwB,SAA+B,WAAmB;CAC5F,KAAK,IAAI,OAAmB;EAExB,cAAc,YAAY,QAAQ,YAAY,EAAE,GAAG,QAAQ,CAAC;EAC5D,qBAAqB,UAAU,KAAK,QAAQ,KAAK;CACrD,CAAC;AACL;;;;;AAMA,SAAgB,mBACZ,SACA,EACI,YACA,qBAAqB,KAAK,IAC1B,WAAW,MAAM,cAAc,aAAa,MAAM,WAAW,kBAAkB,KAE3E;CACR,MAAM,OAAO,IAAI,KAAiB;EAAE,aAAa;EAAM,4BAA4B;CAAK,CAAC;CACzF,QAAQ,MAAM,OAAO;CAGrB,MAAM,6BAAa,IAAI,IAAY;CACnC,MAAM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S;EAAE,GAAG;EAAS;CAAW,CAAC,EAC9F;AACJ"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@panneau/fields",
3
- "version": "5.0.0-alpha.2",
4
- "description": "Controlled field components of Panneau for the protocol's built-in field types, one subpath per field.",
3
+ "version": "5.0.0-alpha.4",
4
+ "description": "Controlled field components of Panneau for the protocol's built-in field types, one subpath per field, and uploads to storage (Uppy 6 in its own entry point).",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -98,11 +98,21 @@
98
98
  "types": "./dist/relation/index.d.ts",
99
99
  "default": "./dist/relation/index.js"
100
100
  },
101
+ "./file": {
102
+ "@panneau/source": "./src/file/index.ts",
103
+ "types": "./dist/file/index.d.ts",
104
+ "default": "./dist/file/index.js"
105
+ },
101
106
  "./locales": {
102
107
  "@panneau/source": "./src/locales/index.ts",
103
108
  "types": "./dist/locales/index.d.ts",
104
109
  "default": "./dist/locales/index.js"
105
110
  },
111
+ "./uppy": {
112
+ "@panneau/source": "./src/uppy/index.ts",
113
+ "types": "./dist/uppy/index.d.ts",
114
+ "default": "./dist/uppy/index.js"
115
+ },
106
116
  "./package.json": "./package.json"
107
117
  },
108
118
  "files": [
@@ -117,14 +127,29 @@
117
127
  "access": "public"
118
128
  },
119
129
  "peerDependencies": {
130
+ "@uppy/aws-s3": "^6.3.0",
131
+ "@uppy/core": "^6.3.0",
120
132
  "react": "^19.2.0",
133
+ "react-aria-components": "^1.22.0",
121
134
  "react-intl": "^12.0.0"
122
135
  },
136
+ "peerDependenciesMeta": {
137
+ "@uppy/aws-s3": {
138
+ "optional": true
139
+ },
140
+ "@uppy/core": {
141
+ "optional": true
142
+ }
143
+ },
123
144
  "dependencies": {
124
145
  "@internationalized/date": "^3.12.4",
125
- "@panneau/intl": "5.0.0-alpha.2",
126
- "@panneau/protocol": "5.0.0-alpha.2",
127
- "@panneau/ui": "5.0.0-alpha.2",
146
+ "@panneau/intl": "5.0.0-alpha.4",
147
+ "@panneau/protocol": "5.0.0-alpha.4",
148
+ "@panneau/ui": "5.0.0-alpha.4",
128
149
  "lucide-react": "^1.57.0"
150
+ },
151
+ "devDependencies": {
152
+ "@uppy/aws-s3": "^6.3.0",
153
+ "@uppy/core": "^6.3.0"
129
154
  }
130
155
  }