@ember-formwright/file-upload 0.0.0-stage → 2.0.0
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.
- package/CHANGELOG.md +53 -0
- package/LICENSE.md +9 -0
- package/README.md +83 -2
- package/addon-main.cjs +4 -0
- package/declarations/index.d.ts +122 -0
- package/declarations/index.d.ts.map +1 -0
- package/declarations/messages.d.ts +49 -0
- package/declarations/messages.d.ts.map +1 -0
- package/declarations/test-support/index.d.ts +38 -0
- package/declarations/test-support/index.d.ts.map +1 -0
- package/dist/index.js +237 -0
- package/dist/index.js.map +1 -0
- package/dist/messages.js +51 -0
- package/dist/messages.js.map +1 -0
- package/dist/test-support/index.js +102 -0
- package/dist/test-support/index.js.map +1 -0
- package/dist/theme.css +226 -0
- package/package.json +112 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# @ember-formwright/file-upload
|
|
2
|
+
|
|
3
|
+
## 2.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 199233b: Fields type their control against their path. `@control` must be a control that stores what the
|
|
8
|
+
path holds, and a field takes only its control's args, typed for that path. `ControlSignature`
|
|
9
|
+
is split into the wiring every control gets and its own args, and registered names are declared
|
|
10
|
+
in `FormwrightControls` (or `FormwrightChoiceControls<T>`, for controls whose value follows the
|
|
11
|
+
path). The add-ons declare their default names. See MIGRATION.md.
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- 332f045: Built-in strings are translatable. Register a translator as `translator:main` (an object with
|
|
16
|
+
`locale` and `t(message, values)`) and Submit, Reset, the ✔ and ✘ buttons' names, the file
|
|
17
|
+
upload's prompts, the rich-text toolbar and the date picker's trigger name all go through it;
|
|
18
|
+
without one they stay English. Each package exports its messages at `./messages`, with ids
|
|
19
|
+
`formwright.<component>.<name>`, and `@ember-formwright/ember` exports `translate`, `format` and
|
|
20
|
+
the `Message` and `Translator` types.
|
|
21
|
+
|
|
22
|
+
Strings that couldn't be changed before take arguments, which win over the translator:
|
|
23
|
+
`@applyLabel` and `@cancelLabel` on fields; `@dropLabel`, `@dropHint`, `@retryLabel`,
|
|
24
|
+
`@removeLabel`, `@uploadingLabel` and `@rejectedLabel` on the file upload control;
|
|
25
|
+
`@toolbarLabel` and `@toolLabels` on the rich-text control.
|
|
26
|
+
|
|
27
|
+
`@ember-formwright/test-support` adds `registerTranslator` and `pseudoTranslator`, to check in a
|
|
28
|
+
test that every string goes through the translator.
|
|
29
|
+
|
|
30
|
+
### Patch Changes
|
|
31
|
+
|
|
32
|
+
- Updated dependencies [332f045]
|
|
33
|
+
- Updated dependencies [199233b]
|
|
34
|
+
- @ember-formwright/ember@2.0.0
|
|
35
|
+
- @ember-formwright/test-support@2.0.0
|
|
36
|
+
|
|
37
|
+
## 1.3.0
|
|
38
|
+
|
|
39
|
+
### Minor Changes
|
|
40
|
+
|
|
41
|
+
- 5db314e: New package: `file` and `files` controls on ember-file-upload 10. A drop zone around a native
|
|
42
|
+
file input, with the chosen files listed by name and size. Without `@upload` the field stores
|
|
43
|
+
`File`s; with it, each file uploads as it is chosen, with progress, and the field stores what
|
|
44
|
+
the upload resolves to. `@accept` filters the picker and drops. `FileUploadHarness` (from
|
|
45
|
+
`@ember-formwright/file-upload/test-support`) selects, drops, removes and waits for uploads,
|
|
46
|
+
and `theme.css` follows the Formwright theme.
|
|
47
|
+
|
|
48
|
+
### Patch Changes
|
|
49
|
+
|
|
50
|
+
- Updated dependencies [aad9026]
|
|
51
|
+
- Updated dependencies [abc6560]
|
|
52
|
+
- @ember-formwright/ember@1.3.0
|
|
53
|
+
- @ember-formwright/test-support@1.3.0
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,84 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ember-formwright/file-upload
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
File inputs and drop zones for Formwright, powered by
|
|
4
|
+
[ember-file-upload](https://ember-file-upload.pages.dev) 10.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
npm install @ember-formwright/ember @ember-formwright/file-upload ember-file-upload
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
// app/app.ts
|
|
12
|
+
import { registerFileUploadControls } from '@ember-formwright/file-upload'
|
|
13
|
+
import '@ember-formwright/file-upload/theme.css' // optional; after the Formwright theme
|
|
14
|
+
|
|
15
|
+
registerFileUploadControls() // @control="file" and @control="files"
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The package types these names for Glint: which paths each fits, and which args it takes. If
|
|
19
|
+
you register under other names, [declare them](https://joegaudet.com/ember-formwright/guide/controls/custom-controls.md).
|
|
20
|
+
|
|
21
|
+
```gts
|
|
22
|
+
{{! stores a File }}
|
|
23
|
+
<f.Field @for="resume" @control="file" @label="Résumé" as |field|>
|
|
24
|
+
<field.Control @accept=".pdf" />
|
|
25
|
+
</f.Field>
|
|
26
|
+
|
|
27
|
+
{{! uploads straight away, and stores what @upload resolves to }}
|
|
28
|
+
<f.Field @for="attachments" @control="files" @label="Attachments" @optionLabel="name" as |field|>
|
|
29
|
+
<field.Control @upload={{this.upload}} />
|
|
30
|
+
</f.Field>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
upload: UploadFn = async file => {
|
|
35
|
+
const response = await file.upload('/api/attachments') // file is ember-file-upload's UploadFile
|
|
36
|
+
return response.json()
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`file` stores one value (or `null`), `files` an array. Without `@upload` the value is the
|
|
41
|
+
native `File`; with it, whatever the promise resolves to. Each control renders a drop zone
|
|
42
|
+
around a native `<input type="file">` and lists the stored files with their size and a remove
|
|
43
|
+
button. The list is drawn from the field's value, so reset and rollback just work; a stored
|
|
44
|
+
value is named by `@optionLabel` (else its `label` or `name`). `field.Control` also takes
|
|
45
|
+
`@accept` (applied to the picker and to drops) and `@prompt` (the zone's call to action).
|
|
46
|
+
Its other strings go through the app's translator (`./messages` lists them), or take
|
|
47
|
+
`@dropLabel`, `@dropHint`, `@retryLabel`, and the functions `@removeLabel`, `@uploadingLabel`
|
|
48
|
+
and `@rejectedLabel`.
|
|
49
|
+
|
|
50
|
+
## Testing
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import { FileUploadHarness } from '@ember-formwright/file-upload/test-support'
|
|
54
|
+
|
|
55
|
+
class ApplicationForm extends FormHarness {
|
|
56
|
+
@field(FileUploadHarness) declare resume: FileUploadHarness
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
await form.resume.select(new File(['%PDF'], 'cv.pdf', { type: 'application/pdf' }))
|
|
60
|
+
await form.resume.drop(photo)
|
|
61
|
+
await form.resume.waitForUploads() // select and drop don't wait for @upload
|
|
62
|
+
assert.deepEqual(form.resume.files, ['cv.pdf'])
|
|
63
|
+
await form.resume.remove('cv.pdf')
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
It also has `retry(name)`, `uploading`, `failed`, `rejected`, `input` and `dropzone`.
|
|
67
|
+
|
|
68
|
+
## Behaviour and known limits
|
|
69
|
+
|
|
70
|
+
- **Labels and focus.** The input carries the field's id, so `<label for>` names it and inline
|
|
71
|
+
editing focuses it. It is visually hidden; the zone shows its focus ring, and is itself a
|
|
72
|
+
label for the input, so a click on it opens the picker. The input also gets `@label` as
|
|
73
|
+
`aria-label`, so the zone's text doesn't join its name.
|
|
74
|
+
- **`@accept`.** Applied by the picker, and by the drop zone, which names what it turned away.
|
|
75
|
+
- **Uploads.** A file is in the value once its upload succeeds. A failed upload stores nothing
|
|
76
|
+
and shows the error's message with Retry and remove buttons. The form doesn't wait for
|
|
77
|
+
uploads on submit; the control has `data-uploading` and `aria-busy="true"` while any runs.
|
|
78
|
+
Uploads aren't cancelled when the field is torn down; their results are dropped.
|
|
79
|
+
- **Disabled and readonly.** Both disable the input, ignore drops and hide the remove buttons.
|
|
80
|
+
- **Queues.** Each control uses its own ember-file-upload queue, destroyed with the control.
|
|
81
|
+
- **Drops.** Only files dragged from the desktop are taken, as ember-file-upload does by default.
|
|
82
|
+
- **Native submit.** The input is cleared after each choice (so the same file can be picked
|
|
83
|
+
again), so it doesn't submit with a native `<form>`. The wrapper carries `data-fw-name`.
|
|
84
|
+
- **Versions.** Ember 6.12+ and ember-file-upload 10.
|
package/addon-main.cjs
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import type Owner from '@ember/owner';
|
|
3
|
+
import type { Queue, UploadFile } from 'ember-file-upload';
|
|
4
|
+
import type FileQueueService from 'ember-file-upload/services/file-queue';
|
|
5
|
+
import { type ControlSignature, type OwnArgs, type ItemOf, type OptionAccessor } from '@ember-formwright/ember';
|
|
6
|
+
/** Uploads a file the user chose, and resolves with what the field stores (an id, a URL, ...). */
|
|
7
|
+
export type UploadFn = (file: UploadFile) => Promise<unknown>;
|
|
8
|
+
export interface FileUploadControlSignature {
|
|
9
|
+
/** A wrapper around the drop zone and the file list, carrying the control's hooks. */
|
|
10
|
+
Element: HTMLDivElement;
|
|
11
|
+
Args: ControlSignature['Args'] & {
|
|
12
|
+
/** Names a stored value that isn't a `File` (what `@upload` resolved to). */
|
|
13
|
+
optionLabel?: OptionAccessor;
|
|
14
|
+
/** Formats file sizes. Default the browser's locale. */
|
|
15
|
+
locale?: string;
|
|
16
|
+
/** The file types to offer, as for `<input accept>`: `.pdf`, `image/*`, `text/csv`, ... */
|
|
17
|
+
accept?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Uploads each chosen file straight away; the field stores what it resolves to. Without it,
|
|
20
|
+
* the field stores the `File` itself.
|
|
21
|
+
*/
|
|
22
|
+
upload?: UploadFn;
|
|
23
|
+
/** The drop zone's call to action. Default "Choose a file" or "Choose files". */
|
|
24
|
+
prompt?: string;
|
|
25
|
+
/** Shown while files are dragged over the drop zone. Default "Drop to add". */
|
|
26
|
+
dropLabel?: string;
|
|
27
|
+
/** Follows the prompt where files can be dropped. Default "or drop here". */
|
|
28
|
+
dropHint?: string;
|
|
29
|
+
/** The message for dropped files `@accept` turned away. Default "Not an accepted type: …". */
|
|
30
|
+
rejectedLabel?: (names: string) => string;
|
|
31
|
+
/** A file's remove button's accessible name. Default "Remove <name>". */
|
|
32
|
+
removeLabel?: (name: string) => string;
|
|
33
|
+
/** An upload's progress bar's accessible name. Default "Uploading <name>". */
|
|
34
|
+
uploadingLabel?: (name: string) => string;
|
|
35
|
+
/** The button that retries a failed upload. Default "Retry". */
|
|
36
|
+
retryLabel?: string;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** A chosen file that is uploading, or whose upload failed. */
|
|
40
|
+
declare class Upload {
|
|
41
|
+
failed: boolean;
|
|
42
|
+
error: string | undefined;
|
|
43
|
+
readonly file: UploadFile;
|
|
44
|
+
constructor(file: UploadFile);
|
|
45
|
+
}
|
|
46
|
+
interface Item {
|
|
47
|
+
value: unknown;
|
|
48
|
+
name: string;
|
|
49
|
+
size: string | undefined;
|
|
50
|
+
kind: string;
|
|
51
|
+
}
|
|
52
|
+
/** Whether `file` matches an `accept` list, as the browser's file picker would filter it. */
|
|
53
|
+
export declare function accepts(file: File, accept: string | undefined): boolean;
|
|
54
|
+
/** "PDF", "PNG", ... from a file name; "FILE" when there is no extension. */
|
|
55
|
+
declare function kindOf(name: string): string;
|
|
56
|
+
export declare function formatSize(bytes: number, locale?: string): string;
|
|
57
|
+
/**
|
|
58
|
+
* A Formwright control for choosing files: a native file input inside an ember-file-upload drop
|
|
59
|
+
* zone, and the list of chosen files with a remove button each. `file` stores one, `files` an
|
|
60
|
+
* array. With `@upload`, each file is uploaded as it is chosen and the field stores the result.
|
|
61
|
+
*/
|
|
62
|
+
export declare class FileUploadControl extends Component<FileUploadControlSignature> {
|
|
63
|
+
fileQueue: FileQueueService;
|
|
64
|
+
uploads: readonly Upload[];
|
|
65
|
+
/** Dropped files that `@accept` turned away, so the user knows why nothing happened. */
|
|
66
|
+
rejected: readonly string[];
|
|
67
|
+
readonly queue: Queue;
|
|
68
|
+
constructor(owner: Owner, args: FileUploadControlSignature['Args']);
|
|
69
|
+
get multiple(): boolean;
|
|
70
|
+
get locked(): boolean;
|
|
71
|
+
get prompt(): string;
|
|
72
|
+
get dropLabel(): string;
|
|
73
|
+
get dropHint(): string;
|
|
74
|
+
get retryLabel(): string;
|
|
75
|
+
get rejectedText(): string;
|
|
76
|
+
removeLabel: (name: string) => string;
|
|
77
|
+
uploadingLabel: (name: string) => string;
|
|
78
|
+
get isUploading(): boolean;
|
|
79
|
+
/** What the field stores, as list items: name, size and a short type badge. */
|
|
80
|
+
get items(): Item[];
|
|
81
|
+
get hasList(): boolean;
|
|
82
|
+
nameOf: (value: unknown) => string;
|
|
83
|
+
kindOf: typeof kindOf;
|
|
84
|
+
sizeOf: (file: UploadFile) => string;
|
|
85
|
+
/** Runs for both the picker and the drop zone: what the queue may take. */
|
|
86
|
+
filter: (file: File, _files: File[], index: number) => boolean;
|
|
87
|
+
onDrop: (files: UploadFile[], transfer: {
|
|
88
|
+
files: File[];
|
|
89
|
+
}) => void;
|
|
90
|
+
onSelect: (files: UploadFile[]) => void;
|
|
91
|
+
take(files: UploadFile[]): void;
|
|
92
|
+
send(entry: Upload, upload: UploadFn): Promise<void>;
|
|
93
|
+
store(values: unknown[]): void;
|
|
94
|
+
remove: (value: unknown) => void;
|
|
95
|
+
retry: (entry: Upload) => void;
|
|
96
|
+
dismiss: (entry: Upload) => void;
|
|
97
|
+
}
|
|
98
|
+
/** The same control, storing an array: of `File`s, or of what `@upload` resolves to. */
|
|
99
|
+
export declare class FileUploadMultipleControl extends FileUploadControl {
|
|
100
|
+
get multiple(): boolean;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Makes `@control="file"` and `@control="files"` available to every form. Call once, e.g. in
|
|
104
|
+
* app.ts.
|
|
105
|
+
*/
|
|
106
|
+
export declare function registerFileUploadControls({ single, multiple, }?: {
|
|
107
|
+
single?: string;
|
|
108
|
+
multiple?: string;
|
|
109
|
+
}): void;
|
|
110
|
+
type FileUploadArgs = OwnArgs<FileUploadControlSignature>;
|
|
111
|
+
declare module '@ember-formwright/ember' {
|
|
112
|
+
interface FormwrightChoiceControls<T> {
|
|
113
|
+
/**
|
|
114
|
+
* `registerFileUploadControls()`'s default names; declare yours if you pass others. A
|
|
115
|
+
* file field stores a `File`, or what `@upload` resolves to, so it follows its path.
|
|
116
|
+
*/
|
|
117
|
+
file: ControlSignature<NonNullable<T> | null, FileUploadArgs, HTMLDivElement>;
|
|
118
|
+
files: ControlSignature<ItemOf<T>[], FileUploadArgs, HTMLDivElement>;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
export {};
|
|
122
|
+
//# sourceMappingURL=index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,EAAE,MAAM,CAAA;CAAO,GAAG,IAAI,CAGpD;AAED,KAAK,cAAc,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAA;AAEzD,OAAO,QAAQ,yBAAyB,CAAC;IACvC,UAAU,wBAAwB,CAAC,CAAC;QAClC;;;WAGG;QAGH,IAAI,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,cAAc,EAAE,cAAc,CAAC,CAAA;QAC7E,KAAK,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,cAAc,EAAE,cAAc,CAAC,CAAA;KACrE;CACF"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** Every built-in string of @ember-formwright/file-upload, for translation catalogs. */
|
|
2
|
+
export declare const messages: {
|
|
3
|
+
chooseFile: {
|
|
4
|
+
id: string;
|
|
5
|
+
message: string;
|
|
6
|
+
description: string;
|
|
7
|
+
};
|
|
8
|
+
chooseFiles: {
|
|
9
|
+
id: string;
|
|
10
|
+
message: string;
|
|
11
|
+
description: string;
|
|
12
|
+
};
|
|
13
|
+
dropToAdd: {
|
|
14
|
+
id: string;
|
|
15
|
+
message: string;
|
|
16
|
+
description: string;
|
|
17
|
+
};
|
|
18
|
+
orDropHere: {
|
|
19
|
+
id: string;
|
|
20
|
+
message: string;
|
|
21
|
+
description: string;
|
|
22
|
+
};
|
|
23
|
+
notAccepted: {
|
|
24
|
+
id: string;
|
|
25
|
+
message: string;
|
|
26
|
+
description: string;
|
|
27
|
+
};
|
|
28
|
+
remove: {
|
|
29
|
+
id: string;
|
|
30
|
+
message: string;
|
|
31
|
+
description: string;
|
|
32
|
+
};
|
|
33
|
+
retry: {
|
|
34
|
+
id: string;
|
|
35
|
+
message: string;
|
|
36
|
+
description: string;
|
|
37
|
+
};
|
|
38
|
+
uploading: {
|
|
39
|
+
id: string;
|
|
40
|
+
message: string;
|
|
41
|
+
description: string;
|
|
42
|
+
};
|
|
43
|
+
uploadFailed: {
|
|
44
|
+
id: string;
|
|
45
|
+
message: string;
|
|
46
|
+
description: string;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AAEA,wFAAwF;AACxF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8Cc,CAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { FieldHarness } from '@ember-formwright/test-support';
|
|
2
|
+
/**
|
|
3
|
+
* Drives a `file` or `files` field:
|
|
4
|
+
*
|
|
5
|
+
* class ApplicationForm extends FormHarness {
|
|
6
|
+
* @field(FileUploadHarness) declare resume: FileUploadHarness
|
|
7
|
+
* }
|
|
8
|
+
*
|
|
9
|
+
* await form.resume.select(new File(['...'], 'cv.pdf', { type: 'application/pdf' }))
|
|
10
|
+
* assert.deepEqual(form.resume.files, ['cv.pdf'])
|
|
11
|
+
*/
|
|
12
|
+
export declare class FileUploadHarness extends FieldHarness {
|
|
13
|
+
static controls: string[];
|
|
14
|
+
/** The native file input the field's label points at. */
|
|
15
|
+
get input(): HTMLInputElement;
|
|
16
|
+
/** The drop zone around the input. */
|
|
17
|
+
get dropzone(): HTMLElement;
|
|
18
|
+
/** The names in the file list: stored files, then uploading or failed ones. */
|
|
19
|
+
get files(): string[];
|
|
20
|
+
/** Names of the files still uploading. */
|
|
21
|
+
get uploading(): string[];
|
|
22
|
+
/** Names of the files whose upload failed. */
|
|
23
|
+
get failed(): string[];
|
|
24
|
+
/** The names `@accept` turned away on the last drop. */
|
|
25
|
+
get rejected(): string | undefined;
|
|
26
|
+
private withState;
|
|
27
|
+
/** Chooses files with the file picker. Doesn't wait for `@upload`; see `waitForUploads`. */
|
|
28
|
+
select(...files: File[]): Promise<void>;
|
|
29
|
+
/** Drags files from the desktop and drops them on the drop zone. */
|
|
30
|
+
drop(...files: File[]): Promise<void>;
|
|
31
|
+
/** Clicks the remove button of the file with this name. */
|
|
32
|
+
remove(name: string): Promise<void>;
|
|
33
|
+
/** Clicks Retry on a failed upload. */
|
|
34
|
+
retry(name: string): Promise<void>;
|
|
35
|
+
/** Waits until no file is uploading: each has been stored, or has failed. */
|
|
36
|
+
waitForUploads(): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test-support/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAA;AAG7D;;;;;;;;;GASG;AACH,qBAAa,iBAAkB,SAAQ,YAAY;IACjD,OAAgB,QAAQ,WAAoB;IAE5C,yDAAyD;IACzD,IAAI,KAAK,IAAI,gBAAgB,CAE5B;IAED,sCAAsC;IACtC,IAAI,QAAQ,IAAI,WAAW,CAI1B;IAED,+EAA+E;IAC/E,IAAI,KAAK,IAAI,MAAM,EAAE,CAIpB;IAED,0CAA0C;IAC1C,IAAI,SAAS,IAAI,MAAM,EAAE,CAExB;IAED,8CAA8C;IAC9C,IAAI,MAAM,IAAI,MAAM,EAAE,CAErB;IAED,wDAAwD;IACxD,IAAI,QAAQ,IAAI,MAAM,GAAG,SAAS,CAKjC;IAED,OAAO,CAAC,SAAS;IAMjB,4FAA4F;IACtF,MAAM,CAAC,GAAG,KAAK,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7C,oEAAoE;IAC9D,IAAI,CAAC,GAAG,KAAK,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAW3C,2DAA2D;IACrD,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAMzC,uCAAuC;IACjC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAMxC,6EAA6E;IACvE,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;CAKtC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { tracked } from '@glimmer/tracking';
|
|
3
|
+
import { on } from '@ember/modifier';
|
|
4
|
+
import { fn } from '@ember/helper';
|
|
5
|
+
import { service } from '@ember/service';
|
|
6
|
+
import { associateDestroyableChild } from '@ember/destroyable';
|
|
7
|
+
import { guidFor } from '@ember/object/internals';
|
|
8
|
+
import FileDropzone from 'ember-file-upload/components/file-dropzone';
|
|
9
|
+
import { translate, labelOf, registerControl } from '@ember-formwright/ember';
|
|
10
|
+
import { messages } from './messages.js';
|
|
11
|
+
import { precompileTemplate } from '@ember/template-compilation';
|
|
12
|
+
import { setComponentTemplate } from '@ember/component';
|
|
13
|
+
import { g, i } from 'decorator-transforms/runtime';
|
|
14
|
+
|
|
15
|
+
/** A chosen file that is uploading, or whose upload failed. */class Upload {
|
|
16
|
+
static {
|
|
17
|
+
g(this.prototype, "failed", [tracked], function () {
|
|
18
|
+
return false;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
#failed = (i(this, "failed"), void 0);
|
|
22
|
+
static {
|
|
23
|
+
g(this.prototype, "error", [tracked]);
|
|
24
|
+
}
|
|
25
|
+
#error = (i(this, "error"), void 0);
|
|
26
|
+
file;
|
|
27
|
+
constructor(file) {
|
|
28
|
+
this.file = file;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function asArray(value) {
|
|
32
|
+
if (Array.isArray(value)) return value;
|
|
33
|
+
return value === null || value === undefined ? [] : [value];
|
|
34
|
+
}
|
|
35
|
+
/** Whether `file` matches an `accept` list, as the browser's file picker would filter it. */
|
|
36
|
+
function accepts(file, accept) {
|
|
37
|
+
if (!accept?.trim()) return true;
|
|
38
|
+
const name = file.name.toLowerCase();
|
|
39
|
+
const type = file.type.toLowerCase();
|
|
40
|
+
return accept.split(',').some(raw => {
|
|
41
|
+
const pattern = raw.trim().toLowerCase();
|
|
42
|
+
if (!pattern) return false;
|
|
43
|
+
if (pattern.startsWith('.')) return name.endsWith(pattern);
|
|
44
|
+
if (pattern.endsWith('/*')) return type.startsWith(pattern.slice(0, -1));
|
|
45
|
+
return type === pattern;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/** "PDF", "PNG", ... from a file name; "FILE" when there is no extension. */
|
|
49
|
+
function kindOf(name) {
|
|
50
|
+
const dot = name.lastIndexOf('.');
|
|
51
|
+
return dot > 0 && dot < name.length - 1 ? name.slice(dot + 1, dot + 5).toUpperCase() : 'FILE';
|
|
52
|
+
}
|
|
53
|
+
const UNITS = ['byte', 'kilobyte', 'megabyte', 'gigabyte'];
|
|
54
|
+
function formatSize(bytes, locale) {
|
|
55
|
+
let size = bytes;
|
|
56
|
+
let unit = 0;
|
|
57
|
+
while (size >= 1000 && unit < UNITS.length - 1) {
|
|
58
|
+
size /= 1000;
|
|
59
|
+
unit++;
|
|
60
|
+
}
|
|
61
|
+
return new Intl.NumberFormat(locale, {
|
|
62
|
+
style: 'unit',
|
|
63
|
+
unit: UNITS[unit],
|
|
64
|
+
unitDisplay: unit ? 'short' : 'long',
|
|
65
|
+
maximumFractionDigits: unit ? 1 : 0
|
|
66
|
+
}).format(size);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A Formwright control for choosing files: a native file input inside an ember-file-upload drop
|
|
70
|
+
* zone, and the list of chosen files with a remove button each. `file` stores one, `files` an
|
|
71
|
+
* array. With `@upload`, each file is uploaded as it is chosen and the field stores the result.
|
|
72
|
+
*/
|
|
73
|
+
class FileUploadControl extends Component {
|
|
74
|
+
static {
|
|
75
|
+
g(this.prototype, "fileQueue", [service('file-queue')]);
|
|
76
|
+
}
|
|
77
|
+
#fileQueue = (i(this, "fileQueue"), void 0);
|
|
78
|
+
static {
|
|
79
|
+
g(this.prototype, "uploads", [tracked], function () {
|
|
80
|
+
return [];
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
#uploads = (i(this, "uploads"), void 0);
|
|
84
|
+
static {
|
|
85
|
+
g(this.prototype, "rejected", [tracked], function () {
|
|
86
|
+
return [];
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
#rejected = (i(this, "rejected"), void 0);
|
|
90
|
+
/** Dropped files that `@accept` turned away, so the user knows why nothing happened. */
|
|
91
|
+
queue;
|
|
92
|
+
constructor(owner, args) {
|
|
93
|
+
super(owner, args);
|
|
94
|
+
// A queue per control, so files never mix with another field's (or the app's own).
|
|
95
|
+
this.queue = this.fileQueue.findOrCreate(`formwright:${guidFor(this)}`);
|
|
96
|
+
associateDestroyableChild(this, this.queue);
|
|
97
|
+
}
|
|
98
|
+
get multiple() {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
get locked() {
|
|
102
|
+
return Boolean(this.args.disabled || this.args.readonly);
|
|
103
|
+
}
|
|
104
|
+
get prompt() {
|
|
105
|
+
return this.args.prompt ?? translate(this, this.multiple ? messages.chooseFiles : messages.chooseFile);
|
|
106
|
+
}
|
|
107
|
+
get dropLabel() {
|
|
108
|
+
return this.args.dropLabel ?? translate(this, messages.dropToAdd);
|
|
109
|
+
}
|
|
110
|
+
get dropHint() {
|
|
111
|
+
return this.args.dropHint ?? translate(this, messages.orDropHere);
|
|
112
|
+
}
|
|
113
|
+
get retryLabel() {
|
|
114
|
+
return this.args.retryLabel ?? translate(this, messages.retry);
|
|
115
|
+
}
|
|
116
|
+
get rejectedText() {
|
|
117
|
+
const names = this.rejected.join(', ');
|
|
118
|
+
return this.args.rejectedLabel?.(names) ?? translate(this, messages.notAccepted, {
|
|
119
|
+
names
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
removeLabel = name => this.args.removeLabel?.(name) ?? translate(this, messages.remove, {
|
|
123
|
+
name
|
|
124
|
+
});
|
|
125
|
+
uploadingLabel = name => this.args.uploadingLabel?.(name) ?? translate(this, messages.uploading, {
|
|
126
|
+
name
|
|
127
|
+
});
|
|
128
|
+
get isUploading() {
|
|
129
|
+
return this.uploads.some(upload => !upload.failed);
|
|
130
|
+
}
|
|
131
|
+
/** What the field stores, as list items: name, size and a short type badge. */
|
|
132
|
+
get items() {
|
|
133
|
+
return asArray(this.args.value).map(value => {
|
|
134
|
+
const name = this.nameOf(value);
|
|
135
|
+
const size = value?.size;
|
|
136
|
+
return {
|
|
137
|
+
value,
|
|
138
|
+
name,
|
|
139
|
+
size: typeof size === 'number' ? formatSize(size, this.args.locale) : undefined,
|
|
140
|
+
kind: kindOf(name)
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
get hasList() {
|
|
145
|
+
return this.items.length > 0 || this.uploads.length > 0;
|
|
146
|
+
}
|
|
147
|
+
nameOf = value => value instanceof File ? value.name : labelOf(value, this.args.optionLabel);
|
|
148
|
+
kindOf = kindOf;
|
|
149
|
+
sizeOf = file => formatSize(file.size, this.args.locale);
|
|
150
|
+
/** Runs for both the picker and the drop zone: what the queue may take. */
|
|
151
|
+
filter = (file, _files, index) => {
|
|
152
|
+
if (this.locked) return false;
|
|
153
|
+
if (!this.multiple && index > 0) return false;
|
|
154
|
+
return accepts(file, this.args.accept);
|
|
155
|
+
};
|
|
156
|
+
onDrop = (files, transfer) => {
|
|
157
|
+
// The drop zone hands over what passed the filter; tell the user about the rest.
|
|
158
|
+
const taken = new Set(files.map(file => file.file));
|
|
159
|
+
this.rejected = this.locked ? [] : transfer.files.filter((file, i) => !taken.has(file) && (this.multiple || i === 0)).map(file => file.name);
|
|
160
|
+
this.take(files);
|
|
161
|
+
};
|
|
162
|
+
onSelect = files => {
|
|
163
|
+
this.rejected = [];
|
|
164
|
+
this.take(files);
|
|
165
|
+
};
|
|
166
|
+
take(files) {
|
|
167
|
+
if (!files.length) return;
|
|
168
|
+
const upload = this.args.upload;
|
|
169
|
+
if (!upload) {
|
|
170
|
+
for (const file of files) this.queue.remove(file);
|
|
171
|
+
this.store(files.map(file => file.file));
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const fresh = files.map(file => new Upload(file));
|
|
175
|
+
this.uploads = [...this.uploads, ...fresh];
|
|
176
|
+
for (const entry of fresh) void this.send(entry, upload);
|
|
177
|
+
}
|
|
178
|
+
async send(entry, upload) {
|
|
179
|
+
entry.failed = false;
|
|
180
|
+
entry.error = undefined;
|
|
181
|
+
try {
|
|
182
|
+
const result = await upload(entry.file);
|
|
183
|
+
if (this.isDestroying) return;
|
|
184
|
+
this.uploads = this.uploads.filter(u => u !== entry);
|
|
185
|
+
this.queue.remove(entry.file);
|
|
186
|
+
this.store([result]);
|
|
187
|
+
} catch (error) {
|
|
188
|
+
if (this.isDestroying) return;
|
|
189
|
+
entry.failed = true;
|
|
190
|
+
entry.error = error instanceof Error ? error.message : String(error ?? translate(this, messages.uploadFailed));
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
store(values) {
|
|
194
|
+
if (this.multiple) this.args.onChange([...asArray(this.args.value), ...values]);else this.args.onChange(values[values.length - 1] ?? null);
|
|
195
|
+
}
|
|
196
|
+
remove = value => {
|
|
197
|
+
if (this.locked) return;
|
|
198
|
+
if (this.multiple) this.args.onChange(asArray(this.args.value).filter(v => v !== value));else this.args.onChange(null);
|
|
199
|
+
};
|
|
200
|
+
retry = entry => {
|
|
201
|
+
if (this.args.upload) void this.send(entry, this.args.upload);
|
|
202
|
+
};
|
|
203
|
+
dismiss = entry => {
|
|
204
|
+
this.uploads = this.uploads.filter(u => u !== entry);
|
|
205
|
+
this.queue.remove(entry.file);
|
|
206
|
+
};
|
|
207
|
+
static {
|
|
208
|
+
setComponentTemplate(precompileTemplate("<div class=\"fw-file-control{{if this.multiple \" fw-file-control--multiple\"}}\" data-test-fw-control={{@type}} data-fw-name={{@name}} data-uploading={{if this.isUploading \"\"}} aria-busy={{if this.isUploading \"true\"}} ...attributes>\n <FileDropzone class=\"fw-dropzone\" @queue={{this.queue}} @multiple={{this.multiple}} @filter={{this.filter}} @onDrop={{this.onDrop}} data-test-fw-dropzone as |dropzone|>\n <div class=\"fw-dropzone-body\" data-active={{if dropzone.active \"\"}} data-disabled={{if this.locked \"\"}}>\n <input id={{@id}} class=\"fw-control fw-file-input\" type=\"file\" name={{@name}} accept={{@accept}} multiple={{this.multiple}} disabled={{this.locked}} required={{@required}} aria-label={{@label}} aria-invalid={{if @invalid \"true\"}} aria-describedby={{@describedBy}} {{this.queue.selectFile filter=this.filter onFilesSelected=this.onSelect}} />\n {{!-- A second way to open the picker; the input above is named by the field's label. --}}\n <label class=\"fw-dropzone-label\" for={{@id}}>\n <svg class=\"fw-dropzone-icon\" viewBox=\"0 0 24 24\" width=\"22\" height=\"22\" aria-hidden=\"true\">\n <path d=\"M12 16V4m0 0-4.5 4.5M12 4l4.5 4.5M4 15v3a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-3\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.8\" stroke-linecap=\"round\" stroke-linejoin=\"round\" />\n </svg>\n <span class=\"fw-dropzone-text\">\n {{#if dropzone.active}}\n <strong>{{this.dropLabel}}</strong>\n {{else}}\n <strong class=\"fw-dropzone-prompt\">{{this.prompt}}</strong>\n {{#if dropzone.supported}}<span> {{this.dropHint}}</span>{{/if}}\n {{/if}}\n </span>\n {{#if @accept}}\n <span class=\"fw-dropzone-accept\">{{@accept}}</span>\n {{/if}}\n </label>\n </div>\n </FileDropzone>\n\n {{#if this.rejected.length}}\n <p class=\"fw-file-rejected\" role=\"status\" data-test-fw-file-rejected>\n {{this.rejectedText}}\n </p>\n {{/if}}\n\n {{#if this.hasList}}\n <ul class=\"fw-file-list\">\n {{#each this.items as |item|}}\n <li class=\"fw-file\" data-test-fw-file={{item.name}}>\n <span class=\"fw-file-kind\" aria-hidden=\"true\">{{item.kind}}</span>\n <span class=\"fw-file-name\">{{item.name}}</span>\n {{#if item.size}}<span class=\"fw-file-size\">{{item.size}}</span>{{/if}}\n {{#unless this.locked}}\n <button type=\"button\" class=\"fw-file-remove\" aria-label={{this.removeLabel item.name}} data-test-fw-remove={{item.name}} {{on \"click\" (fn this.remove item.value)}}>\xD7</button>\n {{/unless}}\n </li>\n {{/each}}\n {{#each this.uploads as |upload|}}\n <li class=\"fw-file fw-file--{{if upload.failed \"failed\" \"uploading\"}}\" data-test-fw-file={{upload.file.name}} data-test-fw-upload-state={{if upload.failed \"failed\" \"uploading\"}}>\n <span class=\"fw-file-kind\" aria-hidden=\"true\">{{this.kindOf upload.file.name}}</span>\n <span class=\"fw-file-name\">{{upload.file.name}}</span>\n {{#if upload.failed}}\n <span class=\"fw-file-error\" data-test-fw-upload-error>{{upload.error}}</span>\n <button type=\"button\" class=\"fw-file-retry\" data-test-fw-retry={{upload.file.name}} {{on \"click\" (fn this.retry upload)}}>{{this.retryLabel}}</button>\n <button type=\"button\" class=\"fw-file-remove\" aria-label={{this.removeLabel upload.file.name}} data-test-fw-remove={{upload.file.name}} {{on \"click\" (fn this.dismiss upload)}}>\xD7</button>\n {{else}}\n <span class=\"fw-file-size\">{{this.sizeOf upload.file}}</span>\n <progress class=\"fw-file-progress\" max=\"100\" value={{upload.file.progress}} aria-label={{this.uploadingLabel upload.file.name}}></progress>\n {{/if}}\n </li>\n {{/each}}\n </ul>\n {{/if}}\n</div>", {
|
|
209
|
+
strictMode: true,
|
|
210
|
+
scope: () => ({
|
|
211
|
+
FileDropzone,
|
|
212
|
+
on,
|
|
213
|
+
fn
|
|
214
|
+
})
|
|
215
|
+
}), this);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
/** The same control, storing an array: of `File`s, or of what `@upload` resolves to. */
|
|
219
|
+
class FileUploadMultipleControl extends FileUploadControl {
|
|
220
|
+
get multiple() {
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Makes `@control="file"` and `@control="files"` available to every form. Call once, e.g. in
|
|
226
|
+
* app.ts.
|
|
227
|
+
*/
|
|
228
|
+
function registerFileUploadControls({
|
|
229
|
+
single = 'file',
|
|
230
|
+
multiple = 'files'
|
|
231
|
+
} = {}) {
|
|
232
|
+
registerControl(single, FileUploadControl);
|
|
233
|
+
registerControl(multiple, FileUploadMultipleControl);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export { FileUploadControl, FileUploadMultipleControl, accepts, formatSize, registerFileUploadControls };
|
|
237
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.gts"],"sourcesContent":["import Component from '@glimmer/component'\nimport type Owner from '@ember/owner'\nimport { tracked } from '@glimmer/tracking'\nimport { on } from '@ember/modifier'\nimport { fn } from '@ember/helper'\nimport { service } from '@ember/service'\nimport { associateDestroyableChild } from '@ember/destroyable'\nimport { guidFor } from '@ember/object/internals'\nimport FileDropzone from 'ember-file-upload/components/file-dropzone'\nimport type { Queue, UploadFile } from 'ember-file-upload'\nimport type FileQueueService from 'ember-file-upload/services/file-queue'\nimport {\n registerControl,\n labelOf,\n translate,\n type ControlSignature,\n type OwnArgs,\n type ItemOf,\n type OptionAccessor,\n} from '@ember-formwright/ember'\nimport { messages } from './messages.ts'\n\n/** Uploads a file the user chose, and resolves with what the field stores (an id, a URL, ...). */\nexport type UploadFn = (file: UploadFile) => Promise<unknown>\n\nexport interface FileUploadControlSignature {\n /** A wrapper around the drop zone and the file list, carrying the control's hooks. */\n Element: HTMLDivElement\n Args: ControlSignature['Args'] & {\n /** Names a stored value that isn't a `File` (what `@upload` resolved to). */\n optionLabel?: OptionAccessor\n /** Formats file sizes. Default the browser's locale. */\n locale?: string\n /** The file types to offer, as for `<input accept>`: `.pdf`, `image/*`, `text/csv`, ... */\n accept?: string\n /**\n * Uploads each chosen file straight away; the field stores what it resolves to. Without it,\n * the field stores the `File` itself.\n */\n upload?: UploadFn\n /** The drop zone's call to action. Default \"Choose a file\" or \"Choose files\". */\n prompt?: string\n /** Shown while files are dragged over the drop zone. Default \"Drop to add\". */\n dropLabel?: string\n /** Follows the prompt where files can be dropped. Default \"or drop here\". */\n dropHint?: string\n /** The message for dropped files `@accept` turned away. Default \"Not an accepted type: …\". */\n rejectedLabel?: (names: string) => string\n /** A file's remove button's accessible name. Default \"Remove <name>\". */\n removeLabel?: (name: string) => string\n /** An upload's progress bar's accessible name. Default \"Uploading <name>\". */\n uploadingLabel?: (name: string) => string\n /** The button that retries a failed upload. Default \"Retry\". */\n retryLabel?: string\n }\n}\n\n/** A chosen file that is uploading, or whose upload failed. */\nclass Upload {\n @tracked failed = false\n @tracked error: string | undefined\n readonly file: UploadFile\n\n constructor(file: UploadFile) {\n this.file = file\n }\n}\n\ninterface Item {\n value: unknown\n name: string\n size: string | undefined\n kind: string\n}\n\nfunction asArray(value: unknown): unknown[] {\n if (Array.isArray(value)) return value\n return value === null || value === undefined ? [] : [value]\n}\n\n/** Whether `file` matches an `accept` list, as the browser's file picker would filter it. */\nexport function accepts(file: File, accept: string | undefined): boolean {\n if (!accept?.trim()) return true\n const name = file.name.toLowerCase()\n const type = file.type.toLowerCase()\n return accept.split(',').some(raw => {\n const pattern = raw.trim().toLowerCase()\n if (!pattern) return false\n if (pattern.startsWith('.')) return name.endsWith(pattern)\n if (pattern.endsWith('/*')) return type.startsWith(pattern.slice(0, -1))\n return type === pattern\n })\n}\n\n/** \"PDF\", \"PNG\", ... from a file name; \"FILE\" when there is no extension. */\nfunction kindOf(name: string): string {\n const dot = name.lastIndexOf('.')\n return dot > 0 && dot < name.length - 1 ? name.slice(dot + 1, dot + 5).toUpperCase() : 'FILE'\n}\n\nconst UNITS = ['byte', 'kilobyte', 'megabyte', 'gigabyte'] as const\n\nexport function formatSize(bytes: number, locale?: string): string {\n let size = bytes\n let unit = 0\n while (size >= 1000 && unit < UNITS.length - 1) {\n size /= 1000\n unit++\n }\n return new Intl.NumberFormat(locale, {\n style: 'unit',\n unit: UNITS[unit],\n unitDisplay: unit ? 'short' : 'long',\n maximumFractionDigits: unit ? 1 : 0,\n }).format(size)\n}\n\n/**\n * A Formwright control for choosing files: a native file input inside an ember-file-upload drop\n * zone, and the list of chosen files with a remove button each. `file` stores one, `files` an\n * array. With `@upload`, each file is uploaded as it is chosen and the field stores the result.\n */\nexport class FileUploadControl extends Component<FileUploadControlSignature> {\n @service('file-queue') declare fileQueue: FileQueueService\n\n @tracked uploads: readonly Upload[] = []\n /** Dropped files that `@accept` turned away, so the user knows why nothing happened. */\n @tracked rejected: readonly string[] = []\n\n readonly queue: Queue\n\n constructor(owner: Owner, args: FileUploadControlSignature['Args']) {\n super(owner, args)\n // A queue per control, so files never mix with another field's (or the app's own).\n this.queue = this.fileQueue.findOrCreate(`formwright:${guidFor(this)}`)\n associateDestroyableChild(this, this.queue)\n }\n\n get multiple(): boolean {\n return false\n }\n\n get locked(): boolean {\n return Boolean(this.args.disabled || this.args.readonly)\n }\n\n get prompt(): string {\n return (\n this.args.prompt ??\n translate(this, this.multiple ? messages.chooseFiles : messages.chooseFile)\n )\n }\n\n get dropLabel(): string {\n return this.args.dropLabel ?? translate(this, messages.dropToAdd)\n }\n\n get dropHint(): string {\n return this.args.dropHint ?? translate(this, messages.orDropHere)\n }\n\n get retryLabel(): string {\n return this.args.retryLabel ?? translate(this, messages.retry)\n }\n\n get rejectedText(): string {\n const names = this.rejected.join(', ')\n return this.args.rejectedLabel?.(names) ?? translate(this, messages.notAccepted, { names })\n }\n\n removeLabel = (name: string): string =>\n this.args.removeLabel?.(name) ?? translate(this, messages.remove, { name })\n\n uploadingLabel = (name: string): string =>\n this.args.uploadingLabel?.(name) ?? translate(this, messages.uploading, { name })\n\n get isUploading(): boolean {\n return this.uploads.some(upload => !upload.failed)\n }\n\n /** What the field stores, as list items: name, size and a short type badge. */\n get items(): Item[] {\n return asArray(this.args.value).map(value => {\n const name = this.nameOf(value)\n const size = (value as { size?: unknown } | null)?.size\n return {\n value,\n name,\n size: typeof size === 'number' ? formatSize(size, this.args.locale) : undefined,\n kind: kindOf(name),\n }\n })\n }\n\n get hasList(): boolean {\n return this.items.length > 0 || this.uploads.length > 0\n }\n\n nameOf = (value: unknown): string =>\n value instanceof File ? value.name : labelOf(value, this.args.optionLabel)\n\n kindOf = kindOf\n\n sizeOf = (file: UploadFile): string => formatSize(file.size, this.args.locale)\n\n /** Runs for both the picker and the drop zone: what the queue may take. */\n filter = (file: File, _files: File[], index: number): boolean => {\n if (this.locked) return false\n if (!this.multiple && index > 0) return false\n return accepts(file, this.args.accept)\n }\n\n onDrop = (files: UploadFile[], transfer: { files: File[] }): void => {\n // The drop zone hands over what passed the filter; tell the user about the rest.\n const taken = new Set(files.map(file => file.file))\n this.rejected = this.locked\n ? []\n : transfer.files\n .filter((file, i) => !taken.has(file) && (this.multiple || i === 0))\n .map(file => file.name)\n this.take(files)\n }\n\n onSelect = (files: UploadFile[]): void => {\n this.rejected = []\n this.take(files)\n }\n\n take(files: UploadFile[]): void {\n if (!files.length) return\n const upload = this.args.upload\n if (!upload) {\n for (const file of files) this.queue.remove(file)\n this.store(files.map(file => file.file))\n return\n }\n const fresh = files.map(file => new Upload(file))\n this.uploads = [...this.uploads, ...fresh]\n for (const entry of fresh) void this.send(entry, upload)\n }\n\n async send(entry: Upload, upload: UploadFn): Promise<void> {\n entry.failed = false\n entry.error = undefined\n try {\n const result = await upload(entry.file)\n if (this.isDestroying) return\n this.uploads = this.uploads.filter(u => u !== entry)\n this.queue.remove(entry.file)\n this.store([result])\n } catch (error) {\n if (this.isDestroying) return\n entry.failed = true\n entry.error =\n error instanceof Error\n ? error.message\n : String(error ?? translate(this, messages.uploadFailed))\n }\n }\n\n store(values: unknown[]): void {\n if (this.multiple) this.args.onChange([...asArray(this.args.value), ...values])\n else this.args.onChange(values[values.length - 1] ?? null)\n }\n\n remove = (value: unknown): void => {\n if (this.locked) return\n if (this.multiple) this.args.onChange(asArray(this.args.value).filter(v => v !== value))\n else this.args.onChange(null)\n }\n\n retry = (entry: Upload): void => {\n if (this.args.upload) void this.send(entry, this.args.upload)\n }\n\n dismiss = (entry: Upload): void => {\n this.uploads = this.uploads.filter(u => u !== entry)\n this.queue.remove(entry.file)\n }\n\n <template>\n <div\n class=\"fw-file-control{{if this.multiple ' fw-file-control--multiple'}}\"\n data-test-fw-control={{@type}}\n data-fw-name={{@name}}\n data-uploading={{if this.isUploading \"\"}}\n aria-busy={{if this.isUploading \"true\"}}\n ...attributes\n >\n <FileDropzone\n class=\"fw-dropzone\"\n @queue={{this.queue}}\n @multiple={{this.multiple}}\n @filter={{this.filter}}\n @onDrop={{this.onDrop}}\n data-test-fw-dropzone\n as |dropzone|\n >\n <div\n class=\"fw-dropzone-body\"\n data-active={{if dropzone.active \"\"}}\n data-disabled={{if this.locked \"\"}}\n >\n <input\n id={{@id}}\n class=\"fw-control fw-file-input\"\n type=\"file\"\n name={{@name}}\n accept={{@accept}}\n multiple={{this.multiple}}\n disabled={{this.locked}}\n required={{@required}}\n aria-label={{@label}}\n aria-invalid={{if @invalid \"true\"}}\n aria-describedby={{@describedBy}}\n {{this.queue.selectFile filter=this.filter onFilesSelected=this.onSelect}}\n />\n {{! A second way to open the picker; the input above is named by the field's label. }}\n <label class=\"fw-dropzone-label\" for={{@id}}>\n <svg\n class=\"fw-dropzone-icon\"\n viewBox=\"0 0 24 24\"\n width=\"22\"\n height=\"22\"\n aria-hidden=\"true\"\n >\n <path\n d=\"M12 16V4m0 0-4.5 4.5M12 4l4.5 4.5M4 15v3a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-3\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"1.8\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n />\n </svg>\n <span class=\"fw-dropzone-text\">\n {{#if dropzone.active}}\n <strong>{{this.dropLabel}}</strong>\n {{else}}\n <strong class=\"fw-dropzone-prompt\">{{this.prompt}}</strong>\n {{#if dropzone.supported}}<span> {{this.dropHint}}</span>{{/if}}\n {{/if}}\n </span>\n {{#if @accept}}\n <span class=\"fw-dropzone-accept\">{{@accept}}</span>\n {{/if}}\n </label>\n </div>\n </FileDropzone>\n\n {{#if this.rejected.length}}\n <p class=\"fw-file-rejected\" role=\"status\" data-test-fw-file-rejected>\n {{this.rejectedText}}\n </p>\n {{/if}}\n\n {{#if this.hasList}}\n <ul class=\"fw-file-list\">\n {{#each this.items as |item|}}\n <li class=\"fw-file\" data-test-fw-file={{item.name}}>\n <span class=\"fw-file-kind\" aria-hidden=\"true\">{{item.kind}}</span>\n <span class=\"fw-file-name\">{{item.name}}</span>\n {{#if item.size}}<span class=\"fw-file-size\">{{item.size}}</span>{{/if}}\n {{#unless this.locked}}\n <button\n type=\"button\"\n class=\"fw-file-remove\"\n aria-label={{this.removeLabel item.name}}\n data-test-fw-remove={{item.name}}\n {{on \"click\" (fn this.remove item.value)}}\n >×</button>\n {{/unless}}\n </li>\n {{/each}}\n {{#each this.uploads as |upload|}}\n <li\n class=\"fw-file fw-file--{{if upload.failed 'failed' 'uploading'}}\"\n data-test-fw-file={{upload.file.name}}\n data-test-fw-upload-state={{if upload.failed \"failed\" \"uploading\"}}\n >\n <span class=\"fw-file-kind\" aria-hidden=\"true\">{{this.kindOf upload.file.name}}</span>\n <span class=\"fw-file-name\">{{upload.file.name}}</span>\n {{#if upload.failed}}\n <span class=\"fw-file-error\" data-test-fw-upload-error>{{upload.error}}</span>\n <button\n type=\"button\"\n class=\"fw-file-retry\"\n data-test-fw-retry={{upload.file.name}}\n {{on \"click\" (fn this.retry upload)}}\n >{{this.retryLabel}}</button>\n <button\n type=\"button\"\n class=\"fw-file-remove\"\n aria-label={{this.removeLabel upload.file.name}}\n data-test-fw-remove={{upload.file.name}}\n {{on \"click\" (fn this.dismiss upload)}}\n >×</button>\n {{else}}\n <span class=\"fw-file-size\">{{this.sizeOf upload.file}}</span>\n <progress\n class=\"fw-file-progress\"\n max=\"100\"\n value={{upload.file.progress}}\n aria-label={{this.uploadingLabel upload.file.name}}\n ></progress>\n {{/if}}\n </li>\n {{/each}}\n </ul>\n {{/if}}\n </div>\n </template>\n}\n\n/** The same control, storing an array: of `File`s, or of what `@upload` resolves to. */\nexport class FileUploadMultipleControl extends FileUploadControl {\n override get multiple(): boolean {\n return true\n }\n}\n\n/**\n * Makes `@control=\"file\"` and `@control=\"files\"` available to every form. Call once, e.g. in\n * app.ts.\n */\nexport function registerFileUploadControls({\n single = 'file',\n multiple = 'files',\n}: { single?: string; multiple?: string } = {}): void {\n registerControl(single, FileUploadControl)\n registerControl(multiple, FileUploadMultipleControl)\n}\n\ntype FileUploadArgs = OwnArgs<FileUploadControlSignature>\n\ndeclare module '@ember-formwright/ember' {\n interface FormwrightChoiceControls<T> {\n /**\n * `registerFileUploadControls()`'s default names; declare yours if you pass others. A\n * file field stores a `File`, or what `@upload` resolves to, so it follows its path.\n */\n // shortcut: `@upload`'s result isn't checked against the path; type `UploadFn` by it if\n // the field ever forwards `@upload`.\n file: ControlSignature<NonNullable<T> | null, FileUploadArgs, HTMLDivElement>\n files: ControlSignature<ItemOf<T>[], FileUploadArgs, HTMLDivElement>\n }\n}\n"],"names":["Upload","g","prototype","tracked","i","file","constructor","asArray","value","Array","isArray","undefined","accepts","accept","trim","name","toLowerCase","type","split","some","raw","pattern","startsWith","endsWith","slice","kindOf","dot","lastIndexOf","length","toUpperCase","UNITS","formatSize","bytes","locale","size","unit","Intl","NumberFormat","style","unitDisplay","maximumFractionDigits","format","FileUploadControl","Component","service","queue","owner","args","fileQueue","findOrCreate","guidFor","associateDestroyableChild","multiple","locked","Boolean","disabled","readonly","prompt","translate","messages","chooseFiles","chooseFile","dropLabel","dropToAdd","dropHint","orDropHere","retryLabel","retry","rejectedText","names","rejected","join","rejectedLabel","notAccepted","removeLabel","remove","uploadingLabel","uploading","isUploading","uploads","upload","failed","items","map","nameOf","kind","hasList","File","labelOf","optionLabel","sizeOf","filter","_files","index","onDrop","files","transfer","taken","Set","has","take","onSelect","store","fresh","entry","send","error","result","isDestroying","u","Error","message","String","uploadFailed","values","onChange","v","dismiss","setComponentTemplate","precompileTemplate","strictMode","scope","FileDropzone","on","fn","FileUploadMultipleControl","registerFileUploadControls","single","registerControl"],"mappings":";;;;;;;;;;;;;;AAyDA,+DACA,MAAMA,MAAA,CAAA;AAAA,EAAA;IAAAC,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,QAAA,EAAA,CACHC,OAAA,CAAA,EAAA,YAAA;AAAA,MAAA,OAAiB,KAAA;AAAA,IAAA,CAAA,CAAA;AAAA;EAAA,OAAA,IAAAC,CAAA,CAAA,IAAA,EAAA,QAAA,CAAA,EAAA,MAAA;AAAA,EAAA;IAAAH,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,OAAA,EAAA,CACjBC,OAAA,CAAA,CAAA;AAAA;EAAA,MAAA,IAAAC,CAAA,CAAA,IAAA,EAAA,OAAA,CAAA,EAAA,MAAA;EACQC;EAETC,WAAAA,CAAYD,IAAgB,EAAE;IAC5B,IAAI,CAACA,IAAI,GAAGA,IAAA;AACd,EAAA;AACF;AASA,SAASE,OAAAA,CAAQC,KAAc,EAAU;EACvC,IAAIC,KAAA,CAAMC,OAAO,CAACF,KAAA,CAAA,EAAQ,OAAOA,KAAA;AACjC,EAAA,OAAOA,KAAA,KAAU,IAAA,IAAQA,KAAA,KAAUG,SAAA,GAAY,EAAE,GAAG,CAACH,KAAA,CAAM;AAC7D;AAEA;AACO,SAASI,OAAAA,CAAQP,IAAU,EAAEQ,MAA0B,EAAU;EACtE,IAAI,CAACA,MAAA,EAAQC,IAAA,EAAA,EAAQ,OAAO,IAAA;EAC5B,MAAMC,IAAA,GAAOV,IAAA,CAAKU,IAAI,CAACC,WAAW,EAAA;EAClC,MAAMC,IAAA,GAAOZ,IAAA,CAAKY,IAAI,CAACD,WAAW,EAAA;EAClC,OAAOH,OAAOK,KAAK,CAAC,GAAA,CAAA,CAAKC,IAAI,CAACC,GAAA,IAAA;IAC5B,MAAMC,OAAA,GAAUD,GAAA,CAAIN,IAAI,EAAA,CAAGE,WAAW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AAC,UAAA,EAAA,IAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;QAAAC,YAAA;QAAAC,EAAA;AAAAC,QAAAA;AAAA,OAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;AAEA;AACO,MAAMC,yBAAA,SAAkCnF,iBAAA,CAAA;EAC7C,IAAaU,QAAAA,GAAoB;AAC/B,IAAA,OAAO,IAAA;AACT,EAAA;AACF;AAEA;;;;AAIO,SAAS0E,0BAAAA,CAA2B;AACzCC,EAAAA,SAAS,MAAM;AACf3E,EAAAA,WAAW;CAC4B,GAAG,EAAE,EAAO;AACnD4E,EAAAA,eAAA,CAAgBD,MAAA,EAAQrF,iBAAA,CAAA;AACxBsF,EAAAA,eAAA,CAAgB5E,QAAA,EAAUyE,yBAAA,CAAA;AAC5B;;"}
|
package/dist/messages.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** Every built-in string of @ember-formwright/file-upload, for translation catalogs. */
|
|
2
|
+
const messages = {
|
|
3
|
+
chooseFile: {
|
|
4
|
+
id: 'formwright.fileUpload.chooseFile',
|
|
5
|
+
message: 'Choose a file',
|
|
6
|
+
description: "The drop zone's call to action, for one file"
|
|
7
|
+
},
|
|
8
|
+
chooseFiles: {
|
|
9
|
+
id: 'formwright.fileUpload.chooseFiles',
|
|
10
|
+
message: 'Choose files',
|
|
11
|
+
description: "The drop zone's call to action, for several files"
|
|
12
|
+
},
|
|
13
|
+
dropToAdd: {
|
|
14
|
+
id: 'formwright.fileUpload.dropToAdd',
|
|
15
|
+
message: 'Drop to add',
|
|
16
|
+
description: 'Shown while files are dragged over the drop zone'
|
|
17
|
+
},
|
|
18
|
+
orDropHere: {
|
|
19
|
+
id: 'formwright.fileUpload.orDropHere',
|
|
20
|
+
message: 'or drop here',
|
|
21
|
+
description: 'Follows "Choose a file" when files can be dropped'
|
|
22
|
+
},
|
|
23
|
+
notAccepted: {
|
|
24
|
+
id: 'formwright.fileUpload.notAccepted',
|
|
25
|
+
message: 'Not an accepted type: {names}',
|
|
26
|
+
description: 'Dropped files that were turned away; {names} is a comma-separated list'
|
|
27
|
+
},
|
|
28
|
+
remove: {
|
|
29
|
+
id: 'formwright.fileUpload.remove',
|
|
30
|
+
message: 'Remove {name}',
|
|
31
|
+
description: "Accessible name of a file's remove button; {name} is the file name"
|
|
32
|
+
},
|
|
33
|
+
retry: {
|
|
34
|
+
id: 'formwright.fileUpload.retry',
|
|
35
|
+
message: 'Retry',
|
|
36
|
+
description: 'Button that retries a failed upload'
|
|
37
|
+
},
|
|
38
|
+
uploading: {
|
|
39
|
+
id: 'formwright.fileUpload.uploading',
|
|
40
|
+
message: 'Uploading {name}',
|
|
41
|
+
description: "Accessible name of an upload's progress bar; {name} is the file name"
|
|
42
|
+
},
|
|
43
|
+
uploadFailed: {
|
|
44
|
+
id: 'formwright.fileUpload.uploadFailed',
|
|
45
|
+
message: 'Upload failed',
|
|
46
|
+
description: 'Shown when an upload fails without an error message'
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export { messages };
|
|
51
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","sources":["../src/messages.ts"],"sourcesContent":["import type { Message } from '@ember-formwright/ember'\n\n/** Every built-in string of @ember-formwright/file-upload, for translation catalogs. */\nexport const messages = {\n chooseFile: {\n id: 'formwright.fileUpload.chooseFile',\n message: 'Choose a file',\n description: \"The drop zone's call to action, for one file\",\n },\n chooseFiles: {\n id: 'formwright.fileUpload.chooseFiles',\n message: 'Choose files',\n description: \"The drop zone's call to action, for several files\",\n },\n dropToAdd: {\n id: 'formwright.fileUpload.dropToAdd',\n message: 'Drop to add',\n description: 'Shown while files are dragged over the drop zone',\n },\n orDropHere: {\n id: 'formwright.fileUpload.orDropHere',\n message: 'or drop here',\n description: 'Follows \"Choose a file\" when files can be dropped',\n },\n notAccepted: {\n id: 'formwright.fileUpload.notAccepted',\n message: 'Not an accepted type: {names}',\n description: 'Dropped files that were turned away; {names} is a comma-separated list',\n },\n remove: {\n id: 'formwright.fileUpload.remove',\n message: 'Remove {name}',\n description: \"Accessible name of a file's remove button; {name} is the file name\",\n },\n retry: {\n id: 'formwright.fileUpload.retry',\n message: 'Retry',\n description: 'Button that retries a failed upload',\n },\n uploading: {\n id: 'formwright.fileUpload.uploading',\n message: 'Uploading {name}',\n description: \"Accessible name of an upload's progress bar; {name} is the file name\",\n },\n uploadFailed: {\n id: 'formwright.fileUpload.uploadFailed',\n message: 'Upload failed',\n description: 'Shown when an upload fails without an error message',\n },\n} satisfies Record<string, Message>\n"],"names":["messages","chooseFile","id","message","description","chooseFiles","dropToAdd","orDropHere","notAccepted","remove","retry","uploading","uploadFailed"],"mappings":"AAEA;AACO,MAAMA,QAAQ,GAAG;AACtBC,EAAAA,UAAU,EAAE;AACVC,IAAAA,EAAE,EAAE,kCAAkC;AACtCC,IAAAA,OAAO,EAAE,eAAe;AACxBC,IAAAA,WAAW,EAAE;GACd;AACDC,EAAAA,WAAW,EAAE;AACXH,IAAAA,EAAE,EAAE,mCAAmC;AACvCC,IAAAA,OAAO,EAAE,cAAc;AACvBC,IAAAA,WAAW,EAAE;GACd;AACDE,EAAAA,SAAS,EAAE;AACTJ,IAAAA,EAAE,EAAE,iCAAiC;AACrCC,IAAAA,OAAO,EAAE,aAAa;AACtBC,IAAAA,WAAW,EAAE;GACd;AACDG,EAAAA,UAAU,EAAE;AACVL,IAAAA,EAAE,EAAE,kCAAkC;AACtCC,IAAAA,OAAO,EAAE,cAAc;AACvBC,IAAAA,WAAW,EAAE;GACd;AACDI,EAAAA,WAAW,EAAE;AACXN,IAAAA,EAAE,EAAE,mCAAmC;AACvCC,IAAAA,OAAO,EAAE,+BAA+B;AACxCC,IAAAA,WAAW,EAAE;GACd;AACDK,EAAAA,MAAM,EAAE;AACNP,IAAAA,EAAE,EAAE,8BAA8B;AAClCC,IAAAA,OAAO,EAAE,eAAe;AACxBC,IAAAA,WAAW,EAAE;GACd;AACDM,EAAAA,KAAK,EAAE;AACLR,IAAAA,EAAE,EAAE,6BAA6B;AACjCC,IAAAA,OAAO,EAAE,OAAO;AAChBC,IAAAA,WAAW,EAAE;GACd;AACDO,EAAAA,SAAS,EAAE;AACTT,IAAAA,EAAE,EAAE,iCAAiC;AACrCC,IAAAA,OAAO,EAAE,kBAAkB;AAC3BC,IAAAA,WAAW,EAAE;GACd;AACDQ,EAAAA,YAAY,EAAE;AACZV,IAAAA,EAAE,EAAE,oCAAoC;AACxCC,IAAAA,OAAO,EAAE,eAAe;AACxBC,IAAAA,WAAW,EAAE;AACf;AACF;;"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { triggerEvent, click, waitUntil } from '@ember/test-helpers';
|
|
2
|
+
import { FieldHarness } from '@ember-formwright/test-support';
|
|
3
|
+
import { selectFiles } from 'ember-file-upload/test-support';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Drives a `file` or `files` field:
|
|
7
|
+
*
|
|
8
|
+
* class ApplicationForm extends FormHarness {
|
|
9
|
+
* @field(FileUploadHarness) declare resume: FileUploadHarness
|
|
10
|
+
* }
|
|
11
|
+
*
|
|
12
|
+
* await form.resume.select(new File(['...'], 'cv.pdf', { type: 'application/pdf' }))
|
|
13
|
+
* assert.deepEqual(form.resume.files, ['cv.pdf'])
|
|
14
|
+
*/
|
|
15
|
+
class FileUploadHarness extends FieldHarness {
|
|
16
|
+
static controls = ['file', 'files'];
|
|
17
|
+
|
|
18
|
+
/** The native file input the field's label points at. */
|
|
19
|
+
get input() {
|
|
20
|
+
return this.control;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The drop zone around the input. */
|
|
24
|
+
get dropzone() {
|
|
25
|
+
const zone = this.element.querySelector('[data-test-fw-dropzone]');
|
|
26
|
+
if (!zone) throw new Error(`Formwright harness: no drop zone in field "${this.path}"`);
|
|
27
|
+
return zone;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The names in the file list: stored files, then uploading or failed ones. */
|
|
31
|
+
get files() {
|
|
32
|
+
return [...this.element.querySelectorAll('[data-test-fw-file]')].map(item => item.getAttribute('data-test-fw-file'));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Names of the files still uploading. */
|
|
36
|
+
get uploading() {
|
|
37
|
+
return this.withState('uploading');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Names of the files whose upload failed. */
|
|
41
|
+
get failed() {
|
|
42
|
+
return this.withState('failed');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The names `@accept` turned away on the last drop. */
|
|
46
|
+
get rejected() {
|
|
47
|
+
return this.element.querySelector('[data-test-fw-file-rejected]')?.textContent?.replace(/\s+/g, ' ').trim();
|
|
48
|
+
}
|
|
49
|
+
withState(state) {
|
|
50
|
+
return [...this.element.querySelectorAll(`[data-test-fw-upload-state="${state}"]`)].map(item => item.getAttribute('data-test-fw-file'));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Chooses files with the file picker. Doesn't wait for `@upload`; see `waitForUploads`. */
|
|
54
|
+
async select(...files) {
|
|
55
|
+
await selectFiles(this.input, ...files);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Drags files from the desktop and drops them on the drop zone. */
|
|
59
|
+
async drop(...files) {
|
|
60
|
+
const dataTransfer = {
|
|
61
|
+
files,
|
|
62
|
+
types: ['Files'],
|
|
63
|
+
items: files.map(file => ({
|
|
64
|
+
kind: 'file',
|
|
65
|
+
type: file.type
|
|
66
|
+
}))
|
|
67
|
+
};
|
|
68
|
+
await triggerEvent(this.dropzone, 'dragenter', {
|
|
69
|
+
dataTransfer
|
|
70
|
+
});
|
|
71
|
+
await triggerEvent(this.dropzone, 'dragover', {
|
|
72
|
+
dataTransfer
|
|
73
|
+
});
|
|
74
|
+
await triggerEvent(this.dropzone, 'drop', {
|
|
75
|
+
dataTransfer
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Clicks the remove button of the file with this name. */
|
|
80
|
+
async remove(name) {
|
|
81
|
+
const button = this.element.querySelector(`[data-test-fw-remove="${CSS.escape(name)}"]`);
|
|
82
|
+
if (!button) throw new Error(`Formwright harness: no remove button for "${name}"`);
|
|
83
|
+
await click(button);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Clicks Retry on a failed upload. */
|
|
87
|
+
async retry(name) {
|
|
88
|
+
const button = this.element.querySelector(`[data-test-fw-retry="${CSS.escape(name)}"]`);
|
|
89
|
+
if (!button) throw new Error(`Formwright harness: no failed upload named "${name}"`);
|
|
90
|
+
await click(button);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Waits until no file is uploading: each has been stored, or has failed. */
|
|
94
|
+
async waitForUploads() {
|
|
95
|
+
await waitUntil(() => this.uploading.length === 0, {
|
|
96
|
+
timeoutMessage: `Formwright harness: uploads in "${this.path}" never finished`
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export { FileUploadHarness };
|
|
102
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/test-support/index.ts"],"sourcesContent":["import { triggerEvent, click, waitUntil } from '@ember/test-helpers'\nimport { FieldHarness } from '@ember-formwright/test-support'\nimport { selectFiles } from 'ember-file-upload/test-support'\n\n/**\n * Drives a `file` or `files` field:\n *\n * class ApplicationForm extends FormHarness {\n * @field(FileUploadHarness) declare resume: FileUploadHarness\n * }\n *\n * await form.resume.select(new File(['...'], 'cv.pdf', { type: 'application/pdf' }))\n * assert.deepEqual(form.resume.files, ['cv.pdf'])\n */\nexport class FileUploadHarness extends FieldHarness {\n static override controls = ['file', 'files']\n\n /** The native file input the field's label points at. */\n get input(): HTMLInputElement {\n return this.control as HTMLInputElement\n }\n\n /** The drop zone around the input. */\n get dropzone(): HTMLElement {\n const zone = this.element.querySelector<HTMLElement>('[data-test-fw-dropzone]')\n if (!zone) throw new Error(`Formwright harness: no drop zone in field \"${this.path}\"`)\n return zone\n }\n\n /** The names in the file list: stored files, then uploading or failed ones. */\n get files(): string[] {\n return [...this.element.querySelectorAll('[data-test-fw-file]')].map(item =>\n item.getAttribute('data-test-fw-file')!,\n )\n }\n\n /** Names of the files still uploading. */\n get uploading(): string[] {\n return this.withState('uploading')\n }\n\n /** Names of the files whose upload failed. */\n get failed(): string[] {\n return this.withState('failed')\n }\n\n /** The names `@accept` turned away on the last drop. */\n get rejected(): string | undefined {\n return this.element\n .querySelector('[data-test-fw-file-rejected]')\n ?.textContent?.replace(/\\s+/g, ' ')\n .trim()\n }\n\n private withState(state: string): string[] {\n return [...this.element.querySelectorAll(`[data-test-fw-upload-state=\"${state}\"]`)].map(item =>\n item.getAttribute('data-test-fw-file')!,\n )\n }\n\n /** Chooses files with the file picker. Doesn't wait for `@upload`; see `waitForUploads`. */\n async select(...files: File[]): Promise<void> {\n await selectFiles(this.input, ...files)\n }\n\n /** Drags files from the desktop and drops them on the drop zone. */\n async drop(...files: File[]): Promise<void> {\n const dataTransfer = {\n files,\n types: ['Files'],\n items: files.map(file => ({ kind: 'file', type: file.type })),\n }\n await triggerEvent(this.dropzone, 'dragenter', { dataTransfer })\n await triggerEvent(this.dropzone, 'dragover', { dataTransfer })\n await triggerEvent(this.dropzone, 'drop', { dataTransfer })\n }\n\n /** Clicks the remove button of the file with this name. */\n async remove(name: string): Promise<void> {\n const button = this.element.querySelector(`[data-test-fw-remove=\"${CSS.escape(name)}\"]`)\n if (!button) throw new Error(`Formwright harness: no remove button for \"${name}\"`)\n await click(button)\n }\n\n /** Clicks Retry on a failed upload. */\n async retry(name: string): Promise<void> {\n const button = this.element.querySelector(`[data-test-fw-retry=\"${CSS.escape(name)}\"]`)\n if (!button) throw new Error(`Formwright harness: no failed upload named \"${name}\"`)\n await click(button)\n }\n\n /** Waits until no file is uploading: each has been stored, or has failed. */\n async waitForUploads(): Promise<void> {\n await waitUntil(() => this.uploading.length === 0, {\n timeoutMessage: `Formwright harness: uploads in \"${this.path}\" never finished`,\n })\n }\n}\n"],"names":["FileUploadHarness","FieldHarness","controls","input","control","dropzone","zone","element","querySelector","Error","path","files","querySelectorAll","map","item","getAttribute","uploading","withState","failed","rejected","textContent","replace","trim","state","select","selectFiles","drop","dataTransfer","types","items","file","kind","type","triggerEvent","remove","name","button","CSS","escape","click","retry","waitForUploads","waitUntil","length","timeoutMessage"],"mappings":";;;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,iBAAiB,SAASC,YAAY,CAAC;AAClD,EAAA,OAAgBC,QAAQ,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;;AAE5C;EACA,IAAIC,KAAKA,GAAqB;IAC5B,OAAO,IAAI,CAACC,OAAO;AACrB,EAAA;;AAEA;EACA,IAAIC,QAAQA,GAAgB;IAC1B,MAAMC,IAAI,GAAG,IAAI,CAACC,OAAO,CAACC,aAAa,CAAc,yBAAyB,CAAC;AAC/E,IAAA,IAAI,CAACF,IAAI,EAAE,MAAM,IAAIG,KAAK,CAAC,CAAA,2CAAA,EAA8C,IAAI,CAACC,IAAI,CAAA,CAAA,CAAG,CAAC;AACtF,IAAA,OAAOJ,IAAI;AACb,EAAA;;AAEA;EACA,IAAIK,KAAKA,GAAa;IACpB,OAAO,CAAC,GAAG,IAAI,CAACJ,OAAO,CAACK,gBAAgB,CAAC,qBAAqB,CAAC,CAAC,CAACC,GAAG,CAACC,IAAI,IACvEA,IAAI,CAACC,YAAY,CAAC,mBAAmB,CACvC,CAAC;AACH,EAAA;;AAEA;EACA,IAAIC,SAASA,GAAa;AACxB,IAAA,OAAO,IAAI,CAACC,SAAS,CAAC,WAAW,CAAC;AACpC,EAAA;;AAEA;EACA,IAAIC,MAAMA,GAAa;AACrB,IAAA,OAAO,IAAI,CAACD,SAAS,CAAC,QAAQ,CAAC;AACjC,EAAA;;AAEA;EACA,IAAIE,Q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A,MAAMC,MAAM,GAAG,IAAI,CAAC7B,OAAO,CAACC,aAAa,CAAC,CAAA,sBAAA,EAAyB6B,GAAG,CAACC,MAAM,CAACH,IAAI,CAAC,IAAI,CAAC;IACxF,IAAI,CAACC,MAAM,EAAE,MAAM,IAAI3B,KAAK,CAAC,CAAA,0CAAA,EAA6C0B,IAAI,CAAA,CAAA,CAAG,CAAC;IAClF,MAAMI,KAAK,CAACH,MAAM,CAAC;AACrB,EAAA;;AAEA;EACA,MAAMI,KAAKA,CAACL,IAAY,EAAiB;AACvC,IAAA,MAAMC,MAAM,GAAG,IAAI,CAAC7B,OAAO,CAACC,aAAa,CAAC,CAAA,qBAAA,EAAwB6B,GAAG,CAACC,MAAM,CAACH,IAAI,CAAC,IAAI,CAAC;IACvF,IAAI,CAACC,MAAM,EAAE,MAAM,IAAI3B,KAAK,CAAC,CAAA,4CAAA,EAA+C0B,IAAI,CAAA,CAAA,CAAG,CAAC;IACpF,MAAMI,KAAK,CAACH,MAAM,CAAC;AACrB,EAAA;;AAEA;EACA,MAAMK,cAAcA,GAAkB;IACpC,MAAMC,SAAS,CAAC,MAAM,IAAI,CAAC1B,SAAS,CAAC2B,MAAM,KAAK,CAAC,EAAE;AACjDC,MAAAA,cAAc,EAAE,CAAA,gCAAA,EAAmC,IAAI,CAAClC,IAAI,CAAA,gBAAA;AAC9D,KAAC,CAAC;AACJ,EAAA;AACF;;"}
|
package/dist/theme.css
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Formwright styles for the file controls. Import after the Formwright theme:
|
|
3
|
+
*
|
|
4
|
+
* import '@ember-formwright/ember/theme.css'
|
|
5
|
+
* import '@ember-formwright/file-upload/theme.css'
|
|
6
|
+
*
|
|
7
|
+
* Everything follows the theme's custom properties (--fw-border, --fw-accent, --fw-radius, ...).
|
|
8
|
+
*/
|
|
9
|
+
.fw-file-control {
|
|
10
|
+
flex: 1;
|
|
11
|
+
min-width: 0;
|
|
12
|
+
display: grid;
|
|
13
|
+
gap: 0.5rem;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.fw-dropzone-body {
|
|
17
|
+
position: relative;
|
|
18
|
+
border: 1.5px dashed var(--fw-border);
|
|
19
|
+
border-radius: var(--fw-radius);
|
|
20
|
+
background: color-mix(in srgb, var(--fw-accent) 3%, var(--fw-bg));
|
|
21
|
+
transition:
|
|
22
|
+
border-color 0.15s,
|
|
23
|
+
background-color 0.15s,
|
|
24
|
+
box-shadow 0.15s;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.fw-dropzone-body:hover:not([data-disabled]) {
|
|
28
|
+
border-color: color-mix(in srgb, var(--fw-accent) 55%, var(--fw-border));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.fw-dropzone-body[data-active] {
|
|
32
|
+
border-style: solid;
|
|
33
|
+
border-color: var(--fw-accent);
|
|
34
|
+
background: color-mix(in srgb, var(--fw-accent) 10%, var(--fw-bg));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.fw-dropzone-body:has(.fw-file-input:focus-visible) {
|
|
38
|
+
border-style: solid;
|
|
39
|
+
border-color: var(--fw-border-focus);
|
|
40
|
+
box-shadow: var(--fw-ring);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.fw-field[data-invalid] .fw-dropzone-body,
|
|
44
|
+
.fw-dropzone-body:has(.fw-file-input[aria-invalid='true']) {
|
|
45
|
+
border-color: var(--fw-error);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.fw-dropzone-body[data-disabled] {
|
|
49
|
+
opacity: 0.6;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/* The input stays focusable and named by the field's label; the zone is what shows. */
|
|
53
|
+
.fw-file-input {
|
|
54
|
+
position: absolute;
|
|
55
|
+
width: 1px;
|
|
56
|
+
height: 1px;
|
|
57
|
+
margin: -1px;
|
|
58
|
+
padding: 0;
|
|
59
|
+
overflow: hidden;
|
|
60
|
+
clip-path: inset(50%);
|
|
61
|
+
white-space: nowrap;
|
|
62
|
+
border: 0;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.fw-dropzone-label {
|
|
66
|
+
display: flex;
|
|
67
|
+
flex-wrap: wrap;
|
|
68
|
+
align-items: center;
|
|
69
|
+
justify-content: center;
|
|
70
|
+
gap: 0.4rem 0.6rem;
|
|
71
|
+
padding: 1.1rem 1rem;
|
|
72
|
+
text-align: center;
|
|
73
|
+
color: var(--fw-muted);
|
|
74
|
+
cursor: pointer;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.fw-dropzone-body[data-disabled] .fw-dropzone-label {
|
|
78
|
+
cursor: not-allowed;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.fw-dropzone-icon {
|
|
82
|
+
color: var(--fw-accent);
|
|
83
|
+
flex: none;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.fw-dropzone-text strong {
|
|
87
|
+
color: var(--fw-accent);
|
|
88
|
+
font-weight: 600;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.fw-dropzone-accept {
|
|
92
|
+
flex-basis: 100%;
|
|
93
|
+
font-size: 0.8rem;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.fw-file-rejected {
|
|
97
|
+
margin: 0;
|
|
98
|
+
color: var(--fw-error);
|
|
99
|
+
font-size: 0.85rem;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.fw-file-list {
|
|
103
|
+
list-style: none;
|
|
104
|
+
margin: 0;
|
|
105
|
+
padding: 0;
|
|
106
|
+
display: grid;
|
|
107
|
+
gap: 0.4rem;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.fw-file {
|
|
111
|
+
display: flex;
|
|
112
|
+
align-items: center;
|
|
113
|
+
flex-wrap: wrap;
|
|
114
|
+
gap: 0.35rem 0.6rem;
|
|
115
|
+
padding: 0.45rem 0.5rem 0.45rem 0.55rem;
|
|
116
|
+
border: 1px solid var(--fw-border);
|
|
117
|
+
border-radius: var(--fw-radius);
|
|
118
|
+
background: var(--fw-bg);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.fw-file-kind {
|
|
122
|
+
flex: none;
|
|
123
|
+
min-width: 2.6rem;
|
|
124
|
+
padding: 0.2rem 0.3rem;
|
|
125
|
+
border-radius: calc(var(--fw-radius) * 0.6);
|
|
126
|
+
background: color-mix(in srgb, var(--fw-accent) 12%, var(--fw-bg));
|
|
127
|
+
color: var(--fw-accent);
|
|
128
|
+
font-size: 0.68rem;
|
|
129
|
+
font-weight: 700;
|
|
130
|
+
letter-spacing: 0.04em;
|
|
131
|
+
text-align: center;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.fw-file-name {
|
|
135
|
+
flex: 1;
|
|
136
|
+
min-width: 0;
|
|
137
|
+
overflow: hidden;
|
|
138
|
+
text-overflow: ellipsis;
|
|
139
|
+
white-space: nowrap;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.fw-file-size {
|
|
143
|
+
color: var(--fw-muted);
|
|
144
|
+
font-size: 0.8rem;
|
|
145
|
+
white-space: nowrap;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.fw-file-remove,
|
|
149
|
+
.fw-file-retry {
|
|
150
|
+
flex: none;
|
|
151
|
+
font: inherit;
|
|
152
|
+
color: var(--fw-muted);
|
|
153
|
+
background: transparent;
|
|
154
|
+
border: 1px solid transparent;
|
|
155
|
+
border-radius: calc(var(--fw-radius) * 0.6);
|
|
156
|
+
cursor: pointer;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
.fw-file-remove {
|
|
160
|
+
width: 1.8rem;
|
|
161
|
+
height: 1.8rem;
|
|
162
|
+
font-size: 1.15rem;
|
|
163
|
+
line-height: 1;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
.fw-file-retry {
|
|
167
|
+
padding: 0.15rem 0.5rem;
|
|
168
|
+
font-size: 0.85rem;
|
|
169
|
+
color: var(--fw-accent);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.fw-file-remove:hover,
|
|
173
|
+
.fw-file-retry:hover {
|
|
174
|
+
color: var(--fw-fg);
|
|
175
|
+
background: color-mix(in srgb, var(--fw-fg) 7%, transparent);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.fw-file-remove:focus-visible,
|
|
179
|
+
.fw-file-retry:focus-visible {
|
|
180
|
+
outline: none;
|
|
181
|
+
border-color: var(--fw-border-focus);
|
|
182
|
+
box-shadow: var(--fw-ring);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.fw-file-progress {
|
|
186
|
+
flex-basis: 100%;
|
|
187
|
+
height: 0.3rem;
|
|
188
|
+
appearance: none;
|
|
189
|
+
border: 0;
|
|
190
|
+
border-radius: 999px;
|
|
191
|
+
overflow: hidden;
|
|
192
|
+
background: color-mix(in srgb, var(--fw-border) 60%, transparent);
|
|
193
|
+
accent-color: var(--fw-accent);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.fw-file-progress::-webkit-progress-bar {
|
|
197
|
+
background: transparent;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
.fw-file-progress::-webkit-progress-value {
|
|
201
|
+
background: var(--fw-accent);
|
|
202
|
+
border-radius: 999px;
|
|
203
|
+
transition: width 0.2s;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
.fw-file-progress::-moz-progress-bar {
|
|
207
|
+
background: var(--fw-accent);
|
|
208
|
+
border-radius: 999px;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.fw-file--failed {
|
|
212
|
+
border-color: color-mix(in srgb, var(--fw-error) 50%, var(--fw-border));
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.fw-file--failed .fw-file-kind {
|
|
216
|
+
background: color-mix(in srgb, var(--fw-error) 12%, var(--fw-bg));
|
|
217
|
+
color: var(--fw-error);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/* Its own line under the name, like the progress bar it replaces. */
|
|
221
|
+
.fw-file-error {
|
|
222
|
+
order: 1;
|
|
223
|
+
flex-basis: 100%;
|
|
224
|
+
color: var(--fw-error);
|
|
225
|
+
font-size: 0.8rem;
|
|
226
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,115 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ember-formwright/file-upload",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "File inputs and drop zones for Formwright, powered by ember-file-upload.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ember-addon",
|
|
7
|
+
"ember",
|
|
8
|
+
"forms",
|
|
9
|
+
"formwright",
|
|
10
|
+
"file-upload",
|
|
11
|
+
"dropzone",
|
|
12
|
+
"upload"
|
|
13
|
+
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"author": "Joe Gaudet <joe@joegaudet.com>",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/joegaudet/ember-formwright.git",
|
|
19
|
+
"directory": "packages/file-upload"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://joegaudet.com/ember-formwright/",
|
|
22
|
+
"bugs": "https://github.com/joegaudet/ember-formwright/issues",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./declarations/index.d.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./messages": {
|
|
29
|
+
"types": "./declarations/messages.d.ts",
|
|
30
|
+
"default": "./dist/messages.js"
|
|
31
|
+
},
|
|
32
|
+
"./test-support": {
|
|
33
|
+
"types": "./declarations/test-support/index.d.ts",
|
|
34
|
+
"default": "./dist/test-support/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./theme.css": "./dist/theme.css",
|
|
37
|
+
"./addon-main.js": "./addon-main.cjs"
|
|
38
|
+
},
|
|
39
|
+
"typesVersions": {
|
|
40
|
+
"*": {
|
|
41
|
+
"*": [
|
|
42
|
+
"declarations/*"
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"addon-main.cjs",
|
|
48
|
+
"declarations",
|
|
49
|
+
"dist",
|
|
50
|
+
"README.md",
|
|
51
|
+
"CHANGELOG.md"
|
|
52
|
+
],
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@embroider/addon-shim": "^1.10.3",
|
|
55
|
+
"decorator-transforms": "^2.4.0",
|
|
56
|
+
"ember-modifier": "^4.3.0"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"@ember/test-helpers": ">= 5.0.0",
|
|
60
|
+
"ember-file-upload": ">= 10.0.0",
|
|
61
|
+
"ember-source": ">= 6.12.0",
|
|
62
|
+
"@ember-formwright/ember": "^2.0.0",
|
|
63
|
+
"@ember-formwright/test-support": "^2.0.0"
|
|
64
|
+
},
|
|
65
|
+
"peerDependenciesMeta": {
|
|
66
|
+
"@ember-formwright/test-support": {
|
|
67
|
+
"optional": true
|
|
68
|
+
},
|
|
69
|
+
"@ember/test-helpers": {
|
|
70
|
+
"optional": true
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"devDependencies": {
|
|
74
|
+
"@babel/core": "^7.29.7",
|
|
75
|
+
"@babel/plugin-transform-typescript": "^7.29.7",
|
|
76
|
+
"@babel/runtime": "^7.29.7",
|
|
77
|
+
"@ember/library-tsconfig": "^3.0.0",
|
|
78
|
+
"@ember/test-helpers": "^5.7.0",
|
|
79
|
+
"@embroider/addon-dev": "^8.4.2",
|
|
80
|
+
"@embroider/macros": "^1.21.1",
|
|
81
|
+
"@glimmer/component": "^2.2.1",
|
|
82
|
+
"@glimmer/tracking": "^1.1.2",
|
|
83
|
+
"@glint/ember-tsc": "^1.14.2",
|
|
84
|
+
"@glint/template": "^1.9.0",
|
|
85
|
+
"@rollup/plugin-babel": "^7.1.0",
|
|
86
|
+
"babel-plugin-ember-template-compilation": "^4.0.1",
|
|
87
|
+
"ember-file-upload": "^10.1.0",
|
|
88
|
+
"ember-modifier": "^4.3.0",
|
|
89
|
+
"ember-source": "~7.3.0",
|
|
90
|
+
"rollup": "^4.64.6",
|
|
91
|
+
"tracked-built-ins": "^4.0.0",
|
|
92
|
+
"typescript": "~6.0.3",
|
|
93
|
+
"@ember-formwright/ember": "2.0.0",
|
|
94
|
+
"@ember-formwright/test-support": "2.0.0"
|
|
95
|
+
},
|
|
96
|
+
"publishConfig": {
|
|
97
|
+
"access": "public"
|
|
98
|
+
},
|
|
99
|
+
"engines": {
|
|
100
|
+
"node": ">=22.12.0"
|
|
101
|
+
},
|
|
102
|
+
"ember": {
|
|
103
|
+
"edition": "octane"
|
|
104
|
+
},
|
|
105
|
+
"ember-addon": {
|
|
106
|
+
"version": 2,
|
|
107
|
+
"type": "addon",
|
|
108
|
+
"main": "addon-main.cjs"
|
|
109
|
+
},
|
|
110
|
+
"scripts": {
|
|
111
|
+
"build": "rollup --config",
|
|
112
|
+
"start": "rollup --config --watch",
|
|
113
|
+
"typecheck": "ember-tsc --noEmit"
|
|
114
|
+
}
|
|
6
115
|
}
|