formtress-js 0.2.1 → 0.2.2

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/README.md CHANGED
@@ -19,7 +19,7 @@
19
19
  Add the following script to your Webflow project settings before the closing `</body>` tag (change `latest` to the version you want to use):
20
20
 
21
21
  ```html
22
- <script src="https://cdn.jsdelivr.net/npm/formtress-js@0.2.0/dist/js/webflow.js"></script>
22
+ <script src="https://cdn.jsdelivr.net/npm/formtress-js@latest/dist/js/webflow.js"></script>
23
23
  ```
24
24
 
25
25
  > Note: It's recommended to pin to a specific version in production for stability. Check the version badge above for the current release.
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Core Formtress module.
3
+ * Use this when you want to manually call the submit function from your own code.
4
+ *
5
+ * Set the form `action` to your Formtress endpoint for progressive enhancement
6
+ * (works without JS), then intercept the submit to enhance the UX:
7
+ *
8
+ * @example
9
+ * ```html
10
+ * <form id="my-form" action="https://app.formtress.com/api/f/your-form-id" method="POST">
11
+ * ```
12
+ * ```js
13
+ * import { submitForm } from 'formtress-js'
14
+ *
15
+ * const form = document.querySelector('#my-form')
16
+ * form.addEventListener('submit', async (e) => {
17
+ * e.preventDefault()
18
+ * const result = await submitForm({
19
+ * url: form.action,
20
+ * data: new FormData(form),
21
+ * })
22
+ * if (result.ok) {
23
+ * // show success state
24
+ * } else {
25
+ * // show error state: result.message, result.status
26
+ * }
27
+ * })
28
+ * ```
29
+ */
30
+ export { submitForm, type SubmitOptions, type SubmitResult } from './shared/submit';
@@ -0,0 +1,21 @@
1
+ export interface SubmitOptions {
2
+ /** The full Formtress endpoint URL (e.g. https://app.formtress.com/api/f/your-form-id) */
3
+ url: string;
4
+ /** The form data to send */
5
+ data: FormData;
6
+ /** HTTP method (defaults to POST) */
7
+ method?: string;
8
+ /** Additional headers to include */
9
+ headers?: Record<string, string>;
10
+ }
11
+ export interface SubmitResult {
12
+ ok: boolean;
13
+ status: number;
14
+ message: string;
15
+ /** Optional redirect URL returned by the API */
16
+ redirect?: string;
17
+ }
18
+ /**
19
+ * Submit form data to Formtress.
20
+ */
21
+ export declare function submitForm(options: SubmitOptions): Promise<SubmitResult>;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Webflow integration for Formtress — v0.2.0
3
+ * Progressive enhancement — no imports — works as a standalone CDN script.
4
+ *
5
+ * Set your Webflow form's `action` attribute to your Formtress endpoint:
6
+ * https://app.formtress.com/api/f/{your-form-id}
7
+ *
8
+ * Without JavaScript: the form submits natively to the Formtress endpoint.
9
+ * With JavaScript: submission is intercepted and Webflow's UX flow is applied
10
+ * (loading state, success/fail panels) without a page reload.
11
+ *
12
+ * Relies on Webflow's native .w-form, .w-form-done, and .w-form-fail classes.
13
+ *
14
+ * Submit button detection (in order):
15
+ * 1. input.w-button (native Webflow input)
16
+ * 2. button:not([type="button"]), input[type="submit"] (custom buttons)
17
+ *
18
+ * Loading text: add `data-ft-loading-text="Loading..."` to any text element inside
19
+ * the form. Its textContent is swapped to the attribute value during submission.
20
+ * Falls back to `data-wait` (on the element or submit button), then "Please wait...".
21
+ * Native .w-button: uses `data-wait` as Webflow does.
22
+ */
23
+ export {};
package/package.json CHANGED
@@ -3,23 +3,28 @@
3
3
  "description": "A tiny library for managing Formtress forms",
4
4
  "private": false,
5
5
  "license": "MIT",
6
- "version": "0.2.1",
6
+ "version": "0.2.2",
7
7
  "type": "module",
8
8
  "main": "dist/js/core.js",
9
9
  "module": "dist/js/core.js",
10
+ "types": "dist/types/core.d.ts",
10
11
  "exports": {
11
12
  ".": {
13
+ "types": "./dist/types/core.d.ts",
12
14
  "import": "./dist/js/core.js"
13
15
  },
14
16
  "./core": {
17
+ "types": "./dist/types/core.d.ts",
15
18
  "import": "./dist/js/core.js"
16
19
  },
17
20
  "./webflow": {
21
+ "types": "./dist/types/webflow.d.ts",
18
22
  "import": "./dist/js/webflow.js"
19
23
  }
20
24
  },
21
25
  "files": [
22
- "dist"
26
+ "dist",
27
+ "dist/types"
23
28
  ],
24
29
  "homepage": "https://formtress.com",
25
30
  "author": "Christos Soulaki",