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 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:()=>T,FormSyncForm:()=>w});module.exports=g(L);var c=require("react"),S=require("react/jsx-runtime"),y=(0,c.createContext)(void 0),f=({children:o})=>{let[t,e]=(0,c.useState)(!1);return(0,S.jsx)(y.Provider,{value:{loading:t,setLoading:e},children:o})},s=()=>{let o=(0,c.useContext)(y);if(!o)throw new Error("useFormSyncContext must be used within FormSyncContextProvider");return o};var m=require("react/jsx-runtime");function R({formId:o,onSuccess:t,onSubmitError:e,children:n,...r}){let{setLoading:u}=s();return(0,m.jsxs)("form",{onSubmit:async d=>{d.preventDefault();let F=d.currentTarget,x=new FormData(F);try{u(!0);let i=await fetch(`http://localhost:8000/v1/s/${o}`,{method:"POST",body:x,headers:{Accept:"application/json"}}),p=await i.json();i.ok?t?.(p):e?.(p),i.ok&&F.reset()}catch{e?.({success:!1,message:"Network error"})}finally{u(!1)}},...r,children:[n,(0,m.jsx)("input",{type:"text",name:"_fs_hp",hidden:!0})]})}function w({...o}){return(0,m.jsx)(f,{children:(0,m.jsx)(R,{...o})})}var l=require("react/jsx-runtime");function T({loadingText:o,children:t,...e}){let{loading:n}=s();return(0,l.jsx)("button",{type:"submit",disabled:n,...e,children:n?o||"Submitting...":t})}0&&(module.exports={FormSyncButton,FormSyncForm});
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 FormSyncSuccess = {
5
- success: true;
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, type FormSyncError, FormSyncForm, type FormSyncResponse, type FormSyncSuccess };
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 FormSyncSuccess = {
5
- success: true;
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, type FormSyncError, FormSyncForm, type FormSyncResponse, type FormSyncSuccess };
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 d=f(void 0),F=({children:o})=>{let[e,t]=l(!1);return x(d.Provider,{value:{loading:e,setLoading:t},children:o})},r=()=>{let o=S(d);if(!o)throw new Error("useFormSyncContext must be used within FormSyncContextProvider");return o};import{jsx as m,jsxs as C}from"react/jsx-runtime";function v({formId:o,onSuccess:e,onSubmitError:t,children:n,...p}){let{setLoading:s}=r();return C("form",{onSubmit:async i=>{i.preventDefault();let a=i.currentTarget,y=new FormData(a);try{s(!0);let c=await fetch(`http://localhost:8000/v1/s/${o}`,{method:"POST",body:y,headers:{Accept:"application/json"}}),u=await c.json();c.ok?e?.(u):t?.(u),c.ok&&a.reset()}catch{t?.({success:!1,message:"Network error"})}finally{s(!1)}},...p,children:[n,m("input",{type:"text",name:"_fs_hp",hidden:!0})]})}function L({...o}){return m(F,{children:m(v,{...o})})}import{jsx as b}from"react/jsx-runtime";function D({loadingText:o,children:e,...t}){let{loading:n}=r();return b("button",{type:"submit",disabled:n,...t,children:n?o||"Submitting...":e})}export{D as FormSyncButton,L as FormSyncForm};
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "formsync",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "The Easiest Way to Accept Form Submissions",
5
5
  "keywords": [
6
6
  "formsync",