formsync 0.1.1 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -139
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +20 -22
- package/dist/index.d.ts +20 -22
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,139 +1,5 @@
|
|
|
1
|
-
# FormSync
|
|
2
|
-
|
|
3
|
-
**FormSync is the easiest way to accept and manage form submissions without building a backend.**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
👉 **[https://formsync.app](https://formsync.app)**
|
|
8
|
-
|
|
9
|
-
## Installation
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
npm install formsync
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
or
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
yarn add formsync
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
---
|
|
22
|
-
|
|
23
|
-
## Create a Form on FormSync
|
|
24
|
-
|
|
25
|
-
1. Go to **[https://formsync.app](https://formsync.app)**
|
|
26
|
-
2. Create a new form
|
|
27
|
-
3. Copy your **Form ID**
|
|
28
|
-
|
|
29
|
-
You’ll need this `formId` to submit data.
|
|
30
|
-
|
|
31
|
-
---
|
|
32
|
-
|
|
33
|
-
## Basic Usage
|
|
34
|
-
|
|
35
|
-
```tsx
|
|
36
|
-
import { FormSyncForm } from "formsync";
|
|
37
|
-
|
|
38
|
-
<FormSyncForm formId="YOUR_FORM_ID">
|
|
39
|
-
<input name="email" />
|
|
40
|
-
<button type="submit">Submit</button>
|
|
41
|
-
</FormSyncForm>
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
That’s it.
|
|
45
|
-
No backend. No API routes.
|
|
46
|
-
|
|
47
|
-
---
|
|
48
|
-
|
|
49
|
-
## With Success & Error Handling
|
|
50
|
-
|
|
51
|
-
```tsx
|
|
52
|
-
import { FormSyncForm } from "formsync";
|
|
53
|
-
|
|
54
|
-
<FormSyncForm
|
|
55
|
-
formId="YOUR_FORM_ID"
|
|
56
|
-
onSuccess={(res) => console.log("Success:", res)}
|
|
57
|
-
onSubmitError={(err) => console.error("Error:", err)}
|
|
58
|
-
>
|
|
59
|
-
<input name="email" />
|
|
60
|
-
<button type="submit">Submit</button>
|
|
61
|
-
</FormSyncForm>
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
---
|
|
65
|
-
|
|
66
|
-
## Using the FormSync Button (Recommended)
|
|
67
|
-
|
|
68
|
-
FormSync provides a **special submit button** that automatically shows loading state.
|
|
69
|
-
|
|
70
|
-
```tsx
|
|
71
|
-
import { FormSyncForm, FormSyncButton } from "formsync";
|
|
72
|
-
|
|
73
|
-
<FormSyncForm formId="YOUR_FORM_ID">
|
|
74
|
-
<input name="email" />
|
|
75
|
-
|
|
76
|
-
<FormSyncButton>
|
|
77
|
-
Submit
|
|
78
|
-
</FormSyncButton>
|
|
79
|
-
</FormSyncForm>
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
### Default behavior
|
|
83
|
-
|
|
84
|
-
* Shows **“Submit”**
|
|
85
|
-
* On submit → shows **“Submitting…”**
|
|
86
|
-
* Button auto-disables while submitting
|
|
87
|
-
|
|
88
|
-
---
|
|
89
|
-
|
|
90
|
-
## Spam Protection
|
|
91
|
-
|
|
92
|
-
FormSync automatically injects a hidden honeypot field:
|
|
93
|
-
|
|
94
|
-
```html
|
|
95
|
-
<input type="text" name="_fs_hp" hidden />
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
Bots fill it → submissions are ignored.
|
|
99
|
-
Humans never see it.
|
|
100
|
-
|
|
101
|
-
---
|
|
102
|
-
|
|
103
|
-
## 🧩 Works With
|
|
104
|
-
|
|
105
|
-
* React
|
|
106
|
-
* Next.js (App Router & Pages Router)
|
|
107
|
-
* Vite
|
|
108
|
-
* CRA
|
|
109
|
-
* Remix (client side)
|
|
110
|
-
|
|
111
|
-
---
|
|
112
|
-
|
|
113
|
-
## API Reference
|
|
114
|
-
|
|
115
|
-
### `<FormSyncForm />`
|
|
116
|
-
|
|
117
|
-
| Prop | Type | Description |
|
|
118
|
-
| --------------- | --------------- | -------------------------------------- |
|
|
119
|
-
| `formId` | `string` | **Required** Form ID from formsync.app |
|
|
120
|
-
| `onSuccess` | `(res) => void` | Called on successful submission |
|
|
121
|
-
| `onSubmitError` | `(err) => void` | Called on failed submission |
|
|
122
|
-
| `...props` | `form props` | All native `<form>` attributes |
|
|
123
|
-
|
|
124
|
-
---
|
|
125
|
-
|
|
126
|
-
### `<FormSyncButton />`
|
|
127
|
-
|
|
128
|
-
| Feature | Supported |
|
|
129
|
-
| ------------------ | --------- |
|
|
130
|
-
| Loading state | yes |
|
|
131
|
-
| Disabled on submit | yes |
|
|
132
|
-
| Custom UI | yes |
|
|
133
|
-
| Optional usage | yes |
|
|
134
|
-
|
|
135
|
-
---
|
|
136
|
-
|
|
137
|
-
## Links
|
|
138
|
-
|
|
139
|
-
Website: [https://formsync.app](https://formsync.app)
|
|
1
|
+
# FormSync
|
|
2
|
+
|
|
3
|
+
**FormSync is the easiest way to accept and manage form submissions without building a backend.**
|
|
4
|
+
|
|
5
|
+
👉 Create your first form at [https://formsync.app](https://formsync.app)
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";var
|
|
2
|
+
"use strict";var m=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var L=(n,e)=>{for(var o in e)m(n,o,{get:e[o],enumerable:!0})},g=(n,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of E(e))!b.call(n,s)&&s!==o&&m(n,s,{get:()=>e[s],enumerable:!(r=R(e,s))||r.enumerable});return n};var h=n=>g(m({},"__esModule",{value:!0}),n);var k={};L(k,{useFormSync:()=>u});module.exports=h(k);var t=require("react"),I="https://api.formsync.app";function u(n){let[e,o]=(0,t.useState)(!1),r=(0,t.useRef)(n);return r.current=n,{submit:(0,t.useCallback)(async p=>{p.preventDefault();let{formId:y,onSuccess:l,onError:f,baseURL:F}=r.current,S=(F??I).replace(/\/$/,""),i=p.currentTarget,d=new FormData(i);o(!0);try{let c=await fetch(`${S}/v1/s/${y}`,{method:"POST",body:d,headers:{Accept:"application/json"}}),a=await c.json();c.ok?(i.reset(),l?.(a)):f?.(a)}catch(c){let a={success:!1,message:c instanceof Error?c.message:"An unexpected error occurred."};f?.(a)}finally{o(!1)}},[]),isLoading:e}}0&&(module.exports={useFormSync});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,29 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type FormSyncSuccess = {
|
|
5
|
-
success: true;
|
|
6
|
-
submissionId: string;
|
|
7
|
-
message?: string;
|
|
8
|
-
};
|
|
9
|
-
type FormSyncError = {
|
|
10
|
-
success: false;
|
|
1
|
+
type FormSyncResponse = {
|
|
2
|
+
success: boolean;
|
|
11
3
|
message: string;
|
|
12
|
-
fieldErrors?: Record<string, string>;
|
|
13
4
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
loadingText?: string;
|
|
17
|
-
children: React.ReactNode;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
interface FormSyncFormProps extends React$1.FormHTMLAttributes<HTMLFormElement> {
|
|
5
|
+
interface FormSyncOptions {
|
|
6
|
+
/** Your FormSync form ID */
|
|
21
7
|
formId: string;
|
|
8
|
+
/** Called when the form is submitted successfully */
|
|
22
9
|
onSuccess?: (res: FormSyncResponse) => void;
|
|
23
|
-
|
|
10
|
+
/** Called when the form submission fails */
|
|
11
|
+
onError?: (err: FormSyncResponse) => void;
|
|
12
|
+
/**
|
|
13
|
+
* Base URL for the FormSync API.
|
|
14
|
+
* @default "https://api.formsync.app"
|
|
15
|
+
*/
|
|
16
|
+
baseURL?: string;
|
|
17
|
+
}
|
|
18
|
+
interface FormSyncInstance {
|
|
19
|
+
/** Attach directly to a form's onSubmit prop */
|
|
20
|
+
submit: (e: React.FormEvent<HTMLFormElement>) => void;
|
|
21
|
+
/** Reactive loading state — true while the request is in flight */
|
|
22
|
+
isLoading: boolean;
|
|
24
23
|
}
|
|
25
|
-
declare function FormSyncForm({ ...props }: FormSyncFormProps): react_jsx_runtime.JSX.Element;
|
|
26
24
|
|
|
27
|
-
declare function
|
|
25
|
+
declare function useFormSync(options: FormSyncOptions): FormSyncInstance;
|
|
28
26
|
|
|
29
|
-
export {
|
|
27
|
+
export { type FormSyncInstance, type FormSyncOptions, type FormSyncResponse, useFormSync };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,29 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type FormSyncSuccess = {
|
|
5
|
-
success: true;
|
|
6
|
-
submissionId: string;
|
|
7
|
-
message?: string;
|
|
8
|
-
};
|
|
9
|
-
type FormSyncError = {
|
|
10
|
-
success: false;
|
|
1
|
+
type FormSyncResponse = {
|
|
2
|
+
success: boolean;
|
|
11
3
|
message: string;
|
|
12
|
-
fieldErrors?: Record<string, string>;
|
|
13
4
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
loadingText?: string;
|
|
17
|
-
children: React.ReactNode;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
interface FormSyncFormProps extends React$1.FormHTMLAttributes<HTMLFormElement> {
|
|
5
|
+
interface FormSyncOptions {
|
|
6
|
+
/** Your FormSync form ID */
|
|
21
7
|
formId: string;
|
|
8
|
+
/** Called when the form is submitted successfully */
|
|
22
9
|
onSuccess?: (res: FormSyncResponse) => void;
|
|
23
|
-
|
|
10
|
+
/** Called when the form submission fails */
|
|
11
|
+
onError?: (err: FormSyncResponse) => void;
|
|
12
|
+
/**
|
|
13
|
+
* Base URL for the FormSync API.
|
|
14
|
+
* @default "https://api.formsync.app"
|
|
15
|
+
*/
|
|
16
|
+
baseURL?: string;
|
|
17
|
+
}
|
|
18
|
+
interface FormSyncInstance {
|
|
19
|
+
/** Attach directly to a form's onSubmit prop */
|
|
20
|
+
submit: (e: React.FormEvent<HTMLFormElement>) => void;
|
|
21
|
+
/** Reactive loading state — true while the request is in flight */
|
|
22
|
+
isLoading: boolean;
|
|
24
23
|
}
|
|
25
|
-
declare function FormSyncForm({ ...props }: FormSyncFormProps): react_jsx_runtime.JSX.Element;
|
|
26
24
|
|
|
27
|
-
declare function
|
|
25
|
+
declare function useFormSync(options: FormSyncOptions): FormSyncInstance;
|
|
28
26
|
|
|
29
|
-
export {
|
|
27
|
+
export { type FormSyncInstance, type FormSyncOptions, type FormSyncResponse, useFormSync };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{
|
|
2
|
+
import{useState as l,useCallback as F,useRef as S}from"react";var d="https://api.formsync.app";function R(o){let[m,s]=l(!1),t=S(o);return t.current=o,{submit:F(async r=>{r.preventDefault();let{formId:p,onSuccess:f,onError:c,baseURL:i}=t.current,u=(i??d).replace(/\/$/,""),a=r.currentTarget,y=new FormData(a);s(!0);try{let e=await fetch(`${u}/v1/s/${p}`,{method:"POST",body:y,headers:{Accept:"application/json"}}),n=await e.json();e.ok?(a.reset(),f?.(n)):c?.(n)}catch(e){let n={success:!1,message:e instanceof Error?e.message:"An unexpected error occurred."};c?.(n)}finally{s(!1)}},[]),isLoading:m}}export{R as useFormSync};
|