@ember-joinery/file-upload 0.0.0-stage → 1.0.1

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 (44) hide show
  1. package/CHANGELOG.md +154 -0
  2. package/LICENSE.md +9 -0
  3. package/NOTICE +532 -0
  4. package/README.md +63 -2
  5. package/addon-main.cjs +4 -0
  6. package/declarations/-private/upload-actor.d.ts +46 -0
  7. package/declarations/-private/upload-actor.d.ts.map +1 -0
  8. package/declarations/components/file-upload/context.d.ts +21 -0
  9. package/declarations/components/file-upload/context.d.ts.map +1 -0
  10. package/declarations/components/file-upload/dropzone.d.ts +48 -0
  11. package/declarations/components/file-upload/dropzone.d.ts.map +1 -0
  12. package/declarations/components/file-upload/index.d.ts +137 -0
  13. package/declarations/components/file-upload/index.d.ts.map +1 -0
  14. package/declarations/components/file-upload/labels.d.ts +25 -0
  15. package/declarations/components/file-upload/labels.d.ts.map +1 -0
  16. package/declarations/components/file-upload/list.d.ts +18 -0
  17. package/declarations/components/file-upload/list.d.ts.map +1 -0
  18. package/declarations/components/file-upload/queue.d.ts +23 -0
  19. package/declarations/components/file-upload/queue.d.ts.map +1 -0
  20. package/declarations/components/file-upload/state.d.ts +156 -0
  21. package/declarations/components/file-upload/state.d.ts.map +1 -0
  22. package/declarations/components/file-upload.d.ts +3 -0
  23. package/declarations/index.d.ts +5 -0
  24. package/declarations/index.d.ts.map +1 -0
  25. package/declarations/messages.d.ts +55 -0
  26. package/declarations/messages.d.ts.map +1 -0
  27. package/declarations/test-support/file-upload.d.ts +112 -0
  28. package/declarations/test-support/file-upload.d.ts.map +1 -0
  29. package/declarations/test-support/index.d.ts +2 -0
  30. package/declarations/test-support/index.d.ts.map +1 -0
  31. package/declarations/test-support.d.ts +2 -0
  32. package/declarations/utils.d.ts +25 -0
  33. package/declarations/utils.d.ts.map +1 -0
  34. package/dist/components/file-upload.js +722 -0
  35. package/dist/components/file-upload.js.map +1 -0
  36. package/dist/index.js +4 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/messages.js +57 -0
  39. package/dist/messages.js.map +1 -0
  40. package/dist/test-support.js +266 -0
  41. package/dist/test-support.js.map +1 -0
  42. package/dist/utils.js +60 -0
  43. package/dist/utils.js.map +1 -0
  44. package/package.json +120 -3
@@ -0,0 +1,112 @@
1
+ import { ButtonHarness, Harness, ItemHarness, ProgressHarness } from '@ember-joinery/test-support';
2
+ /**
3
+ * Drives one row of a `<FileUpload>`'s file list or upload queue: a shadcn Item, so everything
4
+ * `ItemHarness` reads it reads too. Find one by its file's name:
5
+ *
6
+ * const cv = upload.file('cv.pdf')
7
+ * assert.strictEqual(cv.details, 'PDF · 184.3 kB')
8
+ * await cv.remove()
9
+ */
10
+ export declare class FileUploadItemHarness extends ItemHarness {
11
+ /** The file's name. */
12
+ get fileName(): string;
13
+ /** `done` (in the list), `uploading` or `error` (in the queue): its `data-state`. */
14
+ get state(): string | null;
15
+ /** What it says under the name: its kind and size (`PDF · 184.3 kB`), or a failed upload's error. */
16
+ get details(): string;
17
+ /** The preview's image URL, or `null` when it shows an icon for its kind. */
18
+ get preview(): string | null;
19
+ /** Whether it shows a preview of the image rather than an icon. */
20
+ get hasPreview(): boolean;
21
+ /** Whether it has a remove button: a disabled `<FileUpload>` shows none. */
22
+ get canRemove(): boolean;
23
+ /** Its remove button. */
24
+ get removeButton(): ButtonHarness;
25
+ /** A failed upload's retry button. */
26
+ get retryButton(): ButtonHarness;
27
+ /** While it uploads, its progress bar (a `ProgressHarness`). */
28
+ get progressBar(): ProgressHarness;
29
+ /** While it uploads, how much has gone, from 0 to 100. `null` once it isn't uploading. */
30
+ get progress(): number | null;
31
+ /** Presses its remove button. */
32
+ remove(): Promise<void>;
33
+ /** Presses a failed upload's retry button. */
34
+ retry(): Promise<void>;
35
+ }
36
+ /**
37
+ * Drives a `<FileUpload>` from `@ember-joinery/file-upload`: chooses files as the file picker
38
+ * does, drags and drops them on its zone, and reads and removes what its list and upload queue
39
+ * show.
40
+ *
41
+ * const resume = new FileUploadHarness('resume') // <FileUpload @name="resume">
42
+ * await resume.select(new File(['%PDF'], 'cv.pdf', { type: 'application/pdf' }))
43
+ * assert.deepEqual(resume.files, ['cv.pdf'])
44
+ * await resume.remove('cv.pdf')
45
+ *
46
+ * `select` and `drop` don't wait for `@upload`; `waitForUploads()` does.
47
+ */
48
+ export declare class FileUploadHarness extends Harness {
49
+ #private;
50
+ static component: string;
51
+ /** The zone files are dropped on. */
52
+ get dropzone(): HTMLElement;
53
+ /** The zone's visually hidden `<input type="file">`. */
54
+ get input(): HTMLInputElement;
55
+ /** What the zone says, which names its input unless `@label` does. */
56
+ get text(): string;
57
+ /** The input's accessible name: its `aria-label`, else the zone's text. */
58
+ get label(): string;
59
+ /** Which files it takes (`accept`), or `''` for any. */
60
+ get accept(): string;
61
+ /** Whether it takes more than one file. */
62
+ get isMultiple(): boolean;
63
+ /** Whether it takes no files (its input is disabled). */
64
+ get isDisabled(): boolean;
65
+ /** Whether files are dragged over its zone (`data-dragging`). */
66
+ get isDragging(): boolean;
67
+ /** Whether its input has focus, which is how a keyboard user reaches the zone. */
68
+ get isFocused(): boolean;
69
+ /** Whether an upload is running: its upload queue is `aria-busy`. */
70
+ get isUploading(): boolean;
71
+ /** The zone's status region (`role="status"`), which names the files turned away. */
72
+ get status(): HTMLElement;
73
+ /**
74
+ * What the zone says about the files the last choice or drop turned away, as `@accept`
75
+ * doesn't take them, or `undefined`.
76
+ */
77
+ get rejected(): string | undefined;
78
+ /**
79
+ * What the zone says about the files the last drop left out, without `@multiple` (all but the
80
+ * first), or `undefined`.
81
+ */
82
+ get leftOut(): string | undefined;
83
+ /** The file list, or `null` while it holds nothing. */
84
+ get list(): HTMLElement | null;
85
+ /** The upload queue, or `null` while nothing uploads or has failed. */
86
+ get queue(): HTMLElement | null;
87
+ /** Every row, the list's and the queue's, in the order they show. */
88
+ get items(): FileUploadItemHarness[];
89
+ /** The names in the file list: the files the value holds. */
90
+ get files(): string[];
91
+ /** The names of the files uploading. */
92
+ get uploading(): string[];
93
+ /** The names of the files whose upload failed. */
94
+ get failed(): string[];
95
+ /** The row of the file with this name. */
96
+ file(name: string): FileUploadItemHarness;
97
+ /** Chooses files in the file picker: its input's `change`. Doesn't wait for `@upload`. */
98
+ select(...files: File[]): Promise<void>;
99
+ /** Drags files from the desktop over the zone. */
100
+ drag(...files: File[]): Promise<void>;
101
+ /** Drags them away again. */
102
+ leave(): Promise<void>;
103
+ /** Drags files from the desktop and drops them on the zone. Doesn't wait for `@upload`. */
104
+ drop(...files: File[]): Promise<void>;
105
+ /** Presses the remove button of the file with this name. */
106
+ remove(name: string): Promise<void>;
107
+ /** Presses Retry on the failed upload with this name. */
108
+ retry(name: string): Promise<void>;
109
+ /** Waits until no file is uploading: each is in the list, or has failed. */
110
+ waitForUploads(): Promise<void>;
111
+ }
112
+ //# sourceMappingURL=file-upload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-upload.d.ts","sourceRoot":"","sources":["../../src/test-support/file-upload.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAkBlG;;;;;;;GAOG;AACH,qBAAa,qBAAsB,SAAQ,WAAW;IACpD,uBAAuB;IACvB,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,qFAAqF;IACrF,IAAI,KAAK,IAAI,MAAM,GAAG,IAAI,CAEzB;IAED,qGAAqG;IACrG,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,6EAA6E;IAC7E,IAAI,OAAO,IAAI,MAAM,GAAG,IAAI,CAE3B;IAED,mEAAmE;IACnE,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,4EAA4E;IAC5E,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,yBAAyB;IACzB,IAAI,YAAY,IAAI,aAAa,CAEhC;IAED,sCAAsC;IACtC,IAAI,WAAW,IAAI,aAAa,CAE/B;IAED,gEA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AEpB;IAED,wCAAwC;IACxC,IAAI,SAAS,IAAI,MAAM,EAAE,CAExB;IAED,kDAAkD;IAClD,IAAI,MAAM,IAAI,MAAM,EAAE,CAErB;IAMD,0CAA0C;IAC1C,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,qBAAqB;IAIzC,0FAA0F;IACpF,MAAM,CAAC,GAAG,KAAK,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7C,kDAAkD;IAC5C,IAAI,CAAC,GAAG,KAAK,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAM3C,6BAA6B;IACvB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAK5B,2FAA2F;IACrF,IAAI,CAAC,GAAG,KAAK,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAO3C,4DAA4D;IACtD,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzC,yDAAyD;IACnD,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxC,4EAA4E;IACtE,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;CAMtC"}
@@ -0,0 +1,2 @@
1
+ export * from './file-upload.ts';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test-support/index.ts"],"names":[],"mappings":"AAGA,cAAc,kBAAkB,CAAA"}
@@ -0,0 +1,2 @@
1
+ // Generated by scripts/entrypoints.mjs: the types of a folder feature, for its subpath.
2
+ export * from './test-support/index.js'
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Whether `file` matches an `accept` list, as a file picker filters it: extensions (`.pdf`),
3
+ * MIME types (`text/csv`) and wildcards (`image/*`), comma-separated. An empty list takes
4
+ * every file.
5
+ *
6
+ * acceptsFile(new File([], 'cv.pdf', { type: 'application/pdf' }), '.pdf,image/*') // true
7
+ */
8
+ export declare function acceptsFile(file: File, accept: string | undefined): boolean;
9
+ /**
10
+ * A file's kind, from its name's extension, in capitals: `PDF`, `PNG`… (at most four letters),
11
+ * or `unknown` (`FILE` by default) when it has none.
12
+ *
13
+ * fileKind('cv.pdf') // 'PDF'
14
+ * fileKind('README', 'ملف') // 'ملف'
15
+ */
16
+ export declare function fileKind(name: string, unknown?: string): string;
17
+ /**
18
+ * A size in bytes as people read it, in decimal units and the locale's words: `920 bytes`,
19
+ * `184.3 kB`, `1.2 MB`.
20
+ *
21
+ * formatFileSize(1_240_000) // '1.2 MB'
22
+ * formatFileSize(1_240_000, 'de') // '1,2 MB'
23
+ */
24
+ export declare function formatFileSize(bytes: number, locale?: string): string;
25
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAW3E;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,SAA+B,GAAG,MAAM,CAGrF;AAID;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAarE"}