Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@uppy/form: migrate to TS #4937

Merged
merged 11 commits into from Feb 28, 2024
Merged

@uppy/form: migrate to TS #4937

merged 11 commits into from Feb 28, 2024

Conversation

Murderlon
Copy link
Member

No description provided.

@Murderlon Murderlon self-assigned this Feb 20, 2024
Copy link
Contributor

github-actions bot commented Feb 20, 2024

Diff output files
diff --git a/packages/@uppy/form/lib/index.js b/packages/@uppy/form/lib/index.js
index db0e390..a68da4d 100644
--- a/packages/@uppy/form/lib/index.js
+++ b/packages/@uppy/form/lib/index.js
@@ -5,25 +5,29 @@ import getFormData from "get-form-data";
 const packageJson = {
   "version": "3.1.1",
 };
+const defaultOptions = {
+  resultName: "uppyResult",
+  getMetaFromForm: true,
+  addResultToForm: true,
+  submitOnSuccess: false,
+  triggerUploadOnSubmit: false,
+};
+function assertHTMLFormElement(input) {
+  if (input == null || input.nodeName !== "FORM") {
+    throw new Error("ASSERTION FAILED: the target is not a <form> element", {
+      cause: input,
+    });
+  }
+  return input;
+}
 export default class Form extends BasePlugin {
   constructor(uppy, opts) {
-    super(uppy, opts);
-    this.form = void 0;
-    this.type = "acquirer";
-    this.id = this.opts.id || "Form";
-    this.title = "Form";
-    const defaultOptions = {
-      target: null,
-      resultName: "uppyResult",
-      getMetaFromForm: true,
-      addResultToForm: true,
-      submitOnSuccess: false,
-      triggerUploadOnSubmit: false,
-    };
-    this.opts = {
+    super(uppy, {
       ...defaultOptions,
       ...opts,
-    };
+    });
+    this.type = "acquirer";
+    this.id = this.opts.id || "Form";
     this.handleFormSubmit = this.handleFormSubmit.bind(this);
     this.handleUploadStart = this.handleUploadStart.bind(this);
     this.handleSuccess = this.handleSuccess.bind(this);
@@ -97,14 +101,7 @@ export default class Form extends BasePlugin {
     this.uppy.setMeta(formMeta);
   }
   install() {
-    this.form = findDOMElement(this.opts.target);
-    if (!this.form || this.form.nodeName !== "FORM") {
-      this.uppy.log(
-        "Form plugin requires a <form> target element passed in options to operate, none was found",
-        "error",
-      );
-      return;
-    }
+    this.form = assertHTMLFormElement(findDOMElement(this.opts.target));
     this.form.addEventListener("submit", this.handleFormSubmit);
     this.uppy.on("upload", this.handleUploadStart);
     this.uppy.on("complete", this.handleSuccess);

packages/@uppy/form/.npmignore Outdated Show resolved Hide resolved
packages/@uppy/utils/src/findDOMElement.ts Outdated Show resolved Hide resolved
Murderlon and others added 7 commits February 21, 2024 13:01
Co-authored-by: Antoine du Hamel <antoine@transloadit.com>
* main:
  MetaEditor + ImageEditor - new state machine logic (#4939)
  meta: disable `@typescript-eslint/no-non-null-assertion` lint rule (#4945)
  remove unnecessary `'use strict'` directives (#4943)
  @uppy/companion-client: type changes for provider-views (#4938)
  meta: bump ip from 1.1.8 to 1.1.9 (#4941)
  @uppy/companion-client: update types (#4927)
  Release: uppy@3.22.1 (#4935)
  update vi_VN translation (#4930)
  bump `@transloadit/prettier-bytes` (#4933)
  Release: uppy@3.22.0 (#4929)
  update `UppyFile` objects before emitting events (#4928)
  @uppy/transloadit: add `clientName` option (#4920)
  Fix broken previews after cropping (#4926)
  @uppy/compressor: upgrade compressorjs (#4924)
  Fix companion dns and allow redirects from http->https again (#4895)
  autoOpenFileEditor - rename "Edit file" to "Edit image" (#4925)
* main:
  Introduce `ValidateableFile` & move `MinimalRequiredUppyFile` into utils (#4944)
  uppy: fix bundle builder (#4950)
  @uppy/core: improve `UIPluginOptions` types (#4946)
  @uppy/companion-client: fix body/url on upload-success (#4922)
  @uppy/utils: remove EventManager circular reference (#4949)
packages/@uppy/form/src/index.ts Show resolved Hide resolved
packages/@uppy/form/src/index.ts Outdated Show resolved Hide resolved
packages/@uppy/core/src/UIPlugin.ts Outdated Show resolved Hide resolved
packages/@uppy/form/src/index.ts Outdated Show resolved Hide resolved
Murderlon and others added 2 commits February 28, 2024 10:15
Co-authored-by: Mikael Finstad <finstaden@gmail.com>
@Murderlon Murderlon merged commit 10c0853 into main Feb 28, 2024
16 checks passed
@Murderlon Murderlon deleted the form-ts branch February 28, 2024 09:36
@github-actions github-actions bot mentioned this pull request Feb 28, 2024
github-actions bot added a commit that referenced this pull request Feb 28, 2024
| Package                | Version | Package                | Version |
| ---------------------- | ------- | ---------------------- | ------- |
| @uppy/box              |   2.2.1 | @uppy/onedrive         |   3.2.1 |
| @uppy/companion-client |   3.7.4 | @uppy/progress-bar     |   3.1.0 |
| @uppy/core             |   3.9.3 | @uppy/provider-views   |  3.10.0 |
| @uppy/dashboard        |   3.7.5 | @uppy/status-bar       |   3.3.0 |
| @uppy/file-input       |   3.1.0 | @uppy/utils            |   5.7.4 |
| @uppy/form             |   3.2.0 | @uppy/xhr-upload       |   3.6.4 |
| @uppy/image-editor     |   2.4.4 | uppy                   |  3.23.0 |
| @uppy/informer         |   3.1.0 |                        |         |

- @uppy/form: migrate to TS (Merlijn Vos / #4937)
- @uppy/box: fetchPreAuthToken in box too (Mikael Finstad / #4969)
- @uppy/progress-bar: refactor to TypeScript (Mikael Finstad / #4921)
- @uppy/onedrive: fix custom oauth2 credentials for onedrive (Mikael Finstad / #4968)
- @uppy/companion-client,@uppy/utils,@uppy/xhr-upload: improvements for #4922 (Mikael Finstad / #4960)
- @uppy/utils: fix various type issues (Mikael Finstad / #4958)
- @uppy/provider-views: migrate to TS (Merlijn Vos / #4919)
- @uppy/utils: simplify `findDOMElements` (Mikael Finstad / #4957)
- @uppy/xhr-upload: fix getResponseData regression (Merlijn Vos / #4964)
- @uppy/informer: migrate to TS (Merlijn Vos / #4967)
- @uppy/core: remove unused import (Antoine du Hamel / #4972)
- @uppy/image-editor: remove default target (Merlijn Vos / #4966)
- @uppy/angular: Build fixes (Mikael Finstad / #4959)
- meta: Fix flaky e2e test (Murderlon)
- meta: fix e2e flake (Mikael Finstad / #4961)
- meta: add support for `Fragment` short syntax (Antoine du Hamel / #4953)
- @uppy/file-input: refactor to TypeScript (Antoine du Hamel / #4954)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants