formsync 0.1.1 → 0.1.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/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -10
- package/dist/index.d.ts +3 -10
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";var a=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var h=(o,t)=>{for(var e in t)a(o,e,{get:t[e],enumerable:!0})},P=(o,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of C(t))!b.call(o,r)&&r!==e&&a(o,r,{get:()=>t[r],enumerable:!(n=v(t,r))||n.enumerable});return o};var g=o=>P(a({},"__esModule",{value:!0}),o);var L={};h(L,{FormSyncButton:()=>
|
|
2
|
+
"use strict";var a=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var h=(o,t)=>{for(var e in t)a(o,e,{get:t[e],enumerable:!0})},P=(o,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of C(t))!b.call(o,r)&&r!==e&&a(o,r,{get:()=>t[r],enumerable:!(n=v(t,r))||n.enumerable});return o};var g=o=>P(a({},"__esModule",{value:!0}),o);var L={};h(L,{FormSyncButton:()=>w,FormSyncForm:()=>T});module.exports=g(L);var m=require("react"),S=require("react/jsx-runtime"),F=(0,m.createContext)(void 0),f=({children:o})=>{let[t,e]=(0,m.useState)(!1);return(0,S.jsx)(F.Provider,{value:{loading:t,setLoading:e},children:o})},i=()=>{let o=(0,m.useContext)(F);if(!o)throw new Error("useFormSyncContext must be used within FormSyncContextProvider");return o};var c=require("react/jsx-runtime");function R({formId:o,onSuccess:t,onSubmitError:e,children:n,...r}){let{setLoading:d}=i();return(0,c.jsxs)("form",{onSubmit:async p=>{p.preventDefault();let u=p.currentTarget,x=new FormData(u);try{d(!0);let s=await fetch(`https://api.formsync.app/v1/s/${o}`,{method:"POST",body:x,headers:{Accept:"application/json"}}),y=await s.json();s.ok?t?.(y):e?.(y),s.ok&&u.reset()}catch(s){e?.(s?.response?.data)}finally{d(!1)}},...r,children:[n,(0,c.jsx)("input",{type:"text",name:"_fs_hp",hidden:!0})]})}function T({...o}){return(0,c.jsx)(f,{children:(0,c.jsx)(R,{...o})})}var l=require("react/jsx-runtime");function w({loadingText:o,children:t,...e}){let{loading:n}=i();return(0,l.jsx)("button",{type:"submit",disabled:n,...e,children:n?o||"Submitting...":t})}0&&(module.exports={FormSyncButton,FormSyncForm});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import React$1, { ButtonHTMLAttributes } from 'react';
|
|
3
3
|
|
|
4
|
-
type
|
|
5
|
-
success:
|
|
6
|
-
submissionId: string;
|
|
7
|
-
message?: string;
|
|
8
|
-
};
|
|
9
|
-
type FormSyncError = {
|
|
10
|
-
success: false;
|
|
4
|
+
type FormSyncResponse = {
|
|
5
|
+
success: boolean;
|
|
11
6
|
message: string;
|
|
12
|
-
fieldErrors?: Record<string, string>;
|
|
13
7
|
};
|
|
14
|
-
type FormSyncResponse = FormSyncSuccess | FormSyncError;
|
|
15
8
|
interface FormSyncButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
16
9
|
loadingText?: string;
|
|
17
10
|
children: React.ReactNode;
|
|
@@ -26,4 +19,4 @@ declare function FormSyncForm({ ...props }: FormSyncFormProps): react_jsx_runtim
|
|
|
26
19
|
|
|
27
20
|
declare function FormSyncButton({ loadingText, children, ...props }: FormSyncButtonProps): react_jsx_runtime.JSX.Element;
|
|
28
21
|
|
|
29
|
-
export { FormSyncButton, type FormSyncButtonProps,
|
|
22
|
+
export { FormSyncButton, type FormSyncButtonProps, FormSyncForm, type FormSyncResponse };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import React$1, { ButtonHTMLAttributes } from 'react';
|
|
3
3
|
|
|
4
|
-
type
|
|
5
|
-
success:
|
|
6
|
-
submissionId: string;
|
|
7
|
-
message?: string;
|
|
8
|
-
};
|
|
9
|
-
type FormSyncError = {
|
|
10
|
-
success: false;
|
|
4
|
+
type FormSyncResponse = {
|
|
5
|
+
success: boolean;
|
|
11
6
|
message: string;
|
|
12
|
-
fieldErrors?: Record<string, string>;
|
|
13
7
|
};
|
|
14
|
-
type FormSyncResponse = FormSyncSuccess | FormSyncError;
|
|
15
8
|
interface FormSyncButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
16
9
|
loadingText?: string;
|
|
17
10
|
children: React.ReactNode;
|
|
@@ -26,4 +19,4 @@ declare function FormSyncForm({ ...props }: FormSyncFormProps): react_jsx_runtim
|
|
|
26
19
|
|
|
27
20
|
declare function FormSyncButton({ loadingText, children, ...props }: FormSyncButtonProps): react_jsx_runtime.JSX.Element;
|
|
28
21
|
|
|
29
|
-
export { FormSyncButton, type FormSyncButtonProps,
|
|
22
|
+
export { FormSyncButton, type FormSyncButtonProps, FormSyncForm, type FormSyncResponse };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{createContext as f,useContext as S,useState as l}from"react";import{jsx as x}from"react/jsx-runtime";var
|
|
2
|
+
import{createContext as f,useContext as S,useState as l}from"react";import{jsx as x}from"react/jsx-runtime";var p=f(void 0),u=({children:o})=>{let[e,t]=l(!1);return x(p.Provider,{value:{loading:e,setLoading:t},children:o})},m=()=>{let o=S(p);if(!o)throw new Error("useFormSyncContext must be used within FormSyncContextProvider");return o};import{jsx as c,jsxs as C}from"react/jsx-runtime";function v({formId:o,onSuccess:e,onSubmitError:t,children:r,...y}){let{setLoading:s}=m();return C("form",{onSubmit:async i=>{i.preventDefault();let a=i.currentTarget,F=new FormData(a);try{s(!0);let n=await fetch(`https://api.formsync.app/v1/s/${o}`,{method:"POST",body:F,headers:{Accept:"application/json"}}),d=await n.json();n.ok?e?.(d):t?.(d),n.ok&&a.reset()}catch(n){t?.(n?.response?.data)}finally{s(!1)}},...y,children:[r,c("input",{type:"text",name:"_fs_hp",hidden:!0})]})}function L({...o}){return c(u,{children:c(v,{...o})})}import{jsx as b}from"react/jsx-runtime";function H({loadingText:o,children:e,...t}){let{loading:r}=m();return b("button",{type:"submit",disabled:r,...t,children:r?o||"Submitting...":e})}export{H as FormSyncButton,L as FormSyncForm};
|