@formspree/react
Advanced tools
Comparing version 2.4.4 to 2.5.0
@@ -1,20 +0,27 @@ | ||
import React from 'react'; | ||
import * as Forms from '@formspree/core'; | ||
import { Client, SubmissionResponse, FormError as FormError$1, SubmissionData } from '@formspree/core'; | ||
export { isFieldError } from '@formspree/core'; | ||
export { CardElement } from '@stripe/react-stripe-js'; | ||
import React$1, { ComponentPropsWithoutRef, ReactNode } from 'react'; | ||
import { FieldValues, SubmissionError, Client, SubmissionSuccess, SubmissionData } from '@formspree/core'; | ||
type FromspreeContextType = { | ||
type ValidationErrorProps<T extends FieldValues> = { | ||
errors: SubmissionError<T> | null; | ||
field?: keyof T; | ||
prefix?: string; | ||
} & ComponentPropsWithoutRef<'div'>; | ||
declare function ValidationError<T extends FieldValues>(props: ValidationErrorProps<T>): React$1.JSX.Element | null; | ||
type FormspreeContextType = { | ||
client: Client; | ||
}; | ||
type FormspreeProviderProps = { | ||
children: ReactNode; | ||
project?: string; | ||
children: React.ReactNode; | ||
stripePK?: string; | ||
}; | ||
declare const FormspreeProvider: (props: FormspreeProviderProps) => React.JSX.Element; | ||
declare function useFormspree(): FromspreeContextType; | ||
/** | ||
* FormspreeProvider creates Formspree Client based on the given props | ||
* and makes the client available via context. | ||
*/ | ||
declare function FormspreeProvider(props: FormspreeProviderProps): React$1.JSX.Element; | ||
declare function useFormspree(): FormspreeContextType; | ||
type FormError = Forms.FormError; | ||
type FieldError = Forms.FieldError; | ||
/** | ||
@@ -29,32 +36,31 @@ * ExtraData values can be strings or functions that return a string, or a | ||
}; | ||
type ErrorPayload = Forms.FormError; | ||
type Options<T extends FieldValues> = { | ||
client?: Client; | ||
extraData?: ExtraData; | ||
onError?: (error: SubmissionError<T>) => void; | ||
onSuccess?: (data: SubmissionSuccess) => void; | ||
origin?: string; | ||
}; | ||
type FormEvent = React.FormEvent<HTMLFormElement>; | ||
type SubmitHandler = (submissionData: FormEvent | SubmissionData) => Promise<SubmissionResponse>; | ||
type SubmitHandler<T extends FieldValues> = (submission: FormEvent | SubmissionData<T>) => Promise<void>; | ||
declare function useSubmit<T extends FieldValues>(formKey: string, options?: Options<T>): SubmitHandler<T>; | ||
type ResetFunction = () => void; | ||
type TUseForm = [ | ||
type TUseForm<T extends FieldValues> = [ | ||
{ | ||
result: SubmissionResponse | null; | ||
errors: SubmissionError<T> | null; | ||
result: SubmissionSuccess | null; | ||
submitting: boolean; | ||
succeeded: boolean; | ||
errors: FormError$1[]; | ||
}, | ||
SubmitHandler, | ||
SubmitHandler<T>, | ||
ResetFunction | ||
]; | ||
declare const useForm: (formKey: string, args?: { | ||
declare function useForm<T extends FieldValues>(formKey: string, args?: { | ||
client?: Client; | ||
data?: ExtraData; | ||
endpoint?: string; | ||
debug?: boolean; | ||
}) => TUseForm; | ||
}): TUseForm<T>; | ||
type ValidationErrorProps = { | ||
prefix?: string; | ||
field?: string; | ||
errors: FormError$1[]; | ||
[x: string]: any; | ||
}; | ||
declare const ValidationError: React.FC<ValidationErrorProps>; | ||
export { ErrorPayload, ExtraData, ExtraDataValue, FieldError, FormError, FormspreeProvider, FormspreeProviderProps, FromspreeContextType, TUseForm, ValidationError, ValidationErrorProps, useForm, useFormspree }; | ||
export { ExtraData, ExtraDataValue, FormspreeContextType, FormspreeProvider, FormspreeProviderProps, TUseForm, ValidationError, ValidationErrorProps, useForm, useFormspree, useSubmit }; |
@@ -1,1 +0,1 @@ | ||
function e(e,r){if(r==null||r>e.length)r=e.length;for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function r(e){if(Array.isArray(e))return e}function t(e,r,t,n,o,u,a){try{var i=e[u](a);var l=i.value}catch(e){t(e);return}if(i.done){r(l)}else{Promise.resolve(l).then(n,o)}}function n(e){return function(){var r=this,n=arguments;return new Promise(function(o,u){var a=e.apply(r,n);function i(e){t(a,o,u,i,l,"next",e)}function l(e){t(a,o,u,i,l,"throw",e)}i(undefined)})}}function o(e,r,t){if(r in e){Object.defineProperty(e,r,{value:t,enumerable:true,configurable:true,writable:true})}else{e[r]=t}return e}function u(e,r){if(r!=null&&typeof Symbol!=="undefined"&&r[Symbol.hasInstance]){return!!r[Symbol.hasInstance](e)}else{return e instanceof r}}function a(e,r){var t=e==null?null:typeof Symbol!=="undefined"&&e[Symbol.iterator]||e["@@iterator"];if(t==null)return;var n=[];var o=true;var u=false;var a,i;try{for(t=t.call(e);!(o=(a=t.next()).done);o=true){n.push(a.value);if(r&&n.length===r)break}}catch(e){u=true;i=e}finally{try{if(!o&&t["return"]!=null)t["return"]()}finally{if(u)throw i}}return n}function i(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function l(e){for(var r=1;r<arguments.length;r++){var t=arguments[r]!=null?arguments[r]:{};var n=Object.keys(t);if(typeof Object.getOwnPropertySymbols==="function"){n=n.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))}n.forEach(function(r){o(e,r,t[r])})}return e}function c(e,r){if(e==null)return{};var t=s(e,r);var n,o;if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(e);for(o=0;o<u.length;o++){n=u[o];if(r.indexOf(n)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(e,n))continue;t[n]=e[n]}}return t}function s(e,r){if(e==null)return{};var t={};var n=Object.keys(e);var o,u;for(u=0;u<n.length;u++){o=n[u];if(r.indexOf(o)>=0)continue;t[o]=e[o]}return t}function f(e,t){return r(e)||a(e,t)||d(e,t)||i()}function d(r,t){if(!r)return;if(typeof r==="string")return e(r,t);var n=Object.prototype.toString.call(r).slice(8,-1);if(n==="Object"&&r.constructor)n=r.constructor.name;if(n==="Map"||n==="Set")return Array.from(n);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return e(r,t)}function p(e,r){var t,n,o,u,a={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]};return u={next:i(0),"throw":i(1),"return":i(2)},typeof Symbol==="function"&&(u[Symbol.iterator]=function(){return this}),u;function i(e){return function(r){return l([e,r])}}function l(u){if(t)throw new TypeError("Generator is already executing.");while(a)try{if(t=1,n&&(o=u[0]&2?n["return"]:u[0]?n["throw"]||((o=n["return"])&&o.call(n),0):n.next)&&!(o=o.call(n,u[1])).done)return o;if(n=0,o)u=[u[0]&2,o.value];switch(u[0]){case 0:case 1:o=u;break;case 4:a.label++;return{value:u[1],done:false};case 5:a.label++;n=u[1];u=[0];continue;case 7:u=a.ops.pop();a.trys.pop();continue;default:if(!(o=a.trys,o=o.length>0&&o[o.length-1])&&(u[0]===6||u[0]===2)){a=0;continue}if(u[0]===3&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(u[0]===6&&a.label<o[1]){a.label=o[1];o=u;break}if(o&&a.label<o[2]){a.label=o[2];a.ops.push(u);break}if(o[2])a.ops.pop();a.trys.pop();continue}u=r.call(e,a)}catch(e){u=[6,e];n=0}finally{t=o=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:true}}}var m=Object.create;var v=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var w=function(e,r){for(var t in r)v(e,t,{get:r[t],enumerable:!0})},E=function(e,r,t,n){var o=true,u=false,a=undefined;if(r&&typeof r=="object"||typeof r=="function")try{var i=function(){var o=c.value;!g.call(e,o)&&o!==t&&v(e,o,{get:function(){return r[o]},enumerable:!(n=y(r,o))||n.enumerable})};for(var l=b(r)[Symbol.iterator](),c;!(o=(c=l.next()).done);o=true)i()}catch(e){u=true;a=e}finally{try{if(!o&&l.return!=null){l.return()}}finally{if(u){throw a}}}return e};var O=function(e,r,t){return t=e!=null?m(h(e)):{},E(r||!e||!e.__esModule?v(t,"default",{value:e,enumerable:!0}):t,e)},j=function(e){return E(v({},"__esModule",{value:!0}),e)};var F={};w(F,{CardElement:function(){return K.CardElement},FormspreeProvider:function(){return A},ValidationError:function(){return T},isFieldError:function(){return Y.isFieldError},useForm:function(){return V},useFormspree:function(){return I}});module.exports=j(F);var P=O(require("react")),S=require("@formspree/core"),_=require("@stripe/stripe-js/pure.js"),x=(0,P.lazy)(function(){return import("@stripe/react-stripe-js").then(function(e){return{default:e.Elements}})}),C=P.default.createContext(null);C.displayName="Formspree";var k,q=function(e){return k||(k=(0,_.loadStripe)(e)),k},D=function(e,r){var t={};return e&&(t.stripePromise=e),r&&(t.project=r),(0,S.createClient)(t)},A=function(e){var r=f((0,P.useState)(void 0),2),t=r[0],o=r[1],u=f((0,P.useState)(D(t,e.project)),2),a=u[0],i=u[1];return(0,P.useEffect)(function(){return a.startBrowserSession(),function(){a.teardown()}},[]),(0,P.useEffect)(function(){var r=function(){var e=n(function(e){var r;return p(this,function(t){switch(t.label){case 0:return[4,q(e)];case 1:r=t.sent();r&&o(r);return[2]}})});return function r(r){return e.apply(this,arguments)}}();e.stripePK&&r(e.stripePK)},[e.stripePK]),(0,P.useEffect)(function(){t&&i(D(t,e.project))},[t]),P.default.createElement(C.Provider,{value:{client:a}},e.stripePK?P.default.createElement(P.default.Fragment,null,t&&P.default.createElement(P.Suspense,{fallback:P.default.createElement("p",null,"....")},P.default.createElement(x,{stripe:t},P.default.createElement(P.default.Fragment,null,e.children)))):P.default.createElement(P.default.Fragment,null,e.children))};function I(){var e;return(e=(0,P.useContext)(C))!==null&&e!==void 0?e:{client:(0,S.getDefaultClient)()}}var M=require("react"),K=require("@stripe/react-stripe-js");var N="2.4.4";var U=function(e){return e.preventDefault!==void 0},V=function(e){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};var t=f((0,M.useState)(null),2),a=t[0],i=t[1],c=f((0,M.useState)(!1),2),s=c[0],d=c[1],m=f((0,M.useState)(!1),2),v=m[0],y=m[1],b=f((0,M.useState)([]),2),h=b[0],g=b[1],w=I(),E=r.client||w,O,j;if(!E)throw new Error("You must provide a Formspree client");if(!e)throw new Error('You must provide a form key or hashid (e.g. useForm("myForm") or useForm("123xyz")');w.client&&w.client.stripePromise&&(O=(0,K.useStripe)(),j=(0,K.useElements)());var F=!!r.debug,P=r.data;return[{result:a,submitting:s,succeeded:v,errors:h},function(){var t=n(function(t){var a,c,s,m,v,b,h,E,S,_,x,C,k,q,D,A;return p(this,function(I){switch(I.label){case 0:a=function(){var e=n(function(e){var r;return p(this,function(t){e.preventDefault();r=e.target;if(r.tagName!="FORM")throw new Error("submit was triggered for a non-form element");return[2,new FormData(r)]})});return function r(r){return e.apply(this,arguments)}}();if(!U(t))return[3,2];return[4,a(t)];case 1:m=I.sent();return[3,3];case 2:m=t;I.label=3;case 3:c=m,s=function(e,r){u(c,FormData)?c.append(e,r):c=Object.assign(c,o({},e,r))};v=true,b=false,h=undefined;if(!(typeof P=="object"))return[3,13];I.label=4;case 4:I.trys.push([4,11,12,13]);E=Object.entries(P)[Symbol.iterator]();I.label=5;case 5:if(!!(v=(S=E.next()).done))return[3,10];_=f(S.value,2),x=_[0],C=_[1];k=void 0;if(!(typeof C=="function"))return[3,7];return[4,C()];case 6:q=k=I.sent();return[3,8];case 7:q=k=C;I.label=8;case 8:q,k!==void 0&&s(x,k);I.label=9;case 9:v=true;return[3,5];case 10:return[3,13];case 11:D=I.sent();b=true;h=D;return[3,13];case 12:try{if(!v&&E.return!=null){E.return()}}finally{if(b){throw h}}return[7];case 13:A=function(){var e=n(function(){var e;return p(this,function(r){switch(r.label){case 0:e=l({},c.address_line1&&{line1:c.address_line1},c.address_line2&&{line2:c.address_line2},c.address_city&&{city:c.address_city},c.address_country&&{country:c.address_country},c.address_state&&{state:c.address_state},c.address_postal_code&&{postal_code:c.address_postal_code});return[4,O.createPaymentMethod({type:"card",card:j.getElement(K.CardElement),billing_details:l({},c.name&&{name:c.name},c.email&&{email:c.email},c.phone&&{phone:c.phone},e&&{address:e})})];case 1:return[2,r.sent()]}})});return function r(){return e.apply(this,arguments)}}();return[2,(d(!0),w.client.submitForm(e,c,{endpoint:r.endpoint,clientName:"@formspree/react@".concat(N),createPaymentMethod:w.client&&w.client.stripePromise?A:void 0}).then(function(e){var r=e.response.status,t;return r===200?(F&&console.log("Form submitted",e),y(!0),i(e),g([])):r>=400&&(t=e.body,t.errors?(g(t.errors),F&&console.log("Error",e)):(g([{message:"Unexpected error"}]),F&&console.log("Unexpected error",e)),y(!1)),e}).catch(function(e){throw F&&console.log("Unexpected error",e),y(!1),e}).finally(function(){d(!1)}))]}})});return function(e){return t.apply(this,arguments)}}(),function(){d(!1),y(!1),g([])}]};var z=O(require("react")),T=function(e){var r=e.prefix,t=e.field,n=e.errors,o=c(e,["prefix","field","errors"]),u=(n||[]).find(function(e){return e.field===t});return u?z.default.createElement("div",l({},o),r," ",u.message):null};var Y=require("@formspree/core");0&&(module.exports={CardElement:CardElement,FormspreeProvider:FormspreeProvider,ValidationError:ValidationError,isFieldError:isFieldError,useForm:useForm,useFormspree:useFormspree}); | ||
function e(e,r){if(r==null||r>e.length)r=e.length;for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function r(e){if(Array.isArray(e))return e}function t(e,r,t,n,o,u,i){try{var a=e[u](i);var l=a.value}catch(e){t(e);return}if(a.done){r(l)}else{Promise.resolve(l).then(n,o)}}function n(e){return function(){var r=this,n=arguments;return new Promise(function(o,u){var i=e.apply(r,n);function a(e){t(i,o,u,a,l,"next",e)}function l(e){t(i,o,u,a,l,"throw",e)}a(undefined)})}}function o(e,r,t){if(r in e){Object.defineProperty(e,r,{value:t,enumerable:true,configurable:true,writable:true})}else{e[r]=t}return e}function u(e,r){if(r!=null&&typeof Symbol!=="undefined"&&r[Symbol.hasInstance]){return!!r[Symbol.hasInstance](e)}else{return e instanceof r}}function i(e,r){var t=e==null?null:typeof Symbol!=="undefined"&&e[Symbol.iterator]||e["@@iterator"];if(t==null)return;var n=[];var o=true;var u=false;var i,a;try{for(t=t.call(e);!(o=(i=t.next()).done);o=true){n.push(i.value);if(r&&n.length===r)break}}catch(e){u=true;a=e}finally{try{if(!o&&t["return"]!=null)t["return"]()}finally{if(u)throw a}}return n}function a(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function l(e){for(var r=1;r<arguments.length;r++){var t=arguments[r]!=null?arguments[r]:{};var n=Object.keys(t);if(typeof Object.getOwnPropertySymbols==="function"){n=n.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))}n.forEach(function(r){o(e,r,t[r])})}return e}function c(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);if(r){n=n.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})}t.push.apply(t,n)}return t}function f(e,r){r=r!=null?r:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(e,Object.getOwnPropertyDescriptors(r))}else{c(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function s(e,r){if(e==null)return{};var t=p(e,r);var n,o;if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(e);for(o=0;o<u.length;o++){n=u[o];if(r.indexOf(n)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(e,n))continue;t[n]=e[n]}}return t}function p(e,r){if(e==null)return{};var t={};var n=Object.keys(e);var o,u;for(u=0;u<n.length;u++){o=n[u];if(r.indexOf(o)>=0)continue;t[o]=e[o]}return t}function v(e,t){return r(e)||i(e,t)||d(e,t)||a()}function d(r,t){if(!r)return;if(typeof r==="string")return e(r,t);var n=Object.prototype.toString.call(r).slice(8,-1);if(n==="Object"&&r.constructor)n=r.constructor.name;if(n==="Map"||n==="Set")return Array.from(n);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return e(r,t)}function y(e,r){var t,n,o,u,i={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]};return u={next:a(0),"throw":a(1),"return":a(2)},typeof Symbol==="function"&&(u[Symbol.iterator]=function(){return this}),u;function a(e){return function(r){return l([e,r])}}function l(u){if(t)throw new TypeError("Generator is already executing.");while(i)try{if(t=1,n&&(o=u[0]&2?n["return"]:u[0]?n["throw"]||((o=n["return"])&&o.call(n),0):n.next)&&!(o=o.call(n,u[1])).done)return o;if(n=0,o)u=[u[0]&2,o.value];switch(u[0]){case 0:case 1:o=u;break;case 4:i.label++;return{value:u[1],done:false};case 5:i.label++;n=u[1];u=[0];continue;case 7:u=i.ops.pop();i.trys.pop();continue;default:if(!(o=i.trys,o=o.length>0&&o[o.length-1])&&(u[0]===6||u[0]===2)){i=0;continue}if(u[0]===3&&(!o||u[1]>o[0]&&u[1]<o[3])){i.label=u[1];break}if(u[0]===6&&i.label<o[1]){i.label=o[1];o=u;break}if(o&&i.label<o[2]){i.label=o[2];i.ops.push(u);break}if(o[2])i.ops.pop();i.trys.pop();continue}u=r.call(e,i)}catch(e){u=[6,e];n=0}finally{t=o=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:true}}}var m=Object.create;var b=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var O=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var w=function(e,r){for(var t in r)b(e,t,{get:r[t],enumerable:!0})},S=function(e,r,t,n){var o=true,u=false,i=undefined;if(r&&typeof r=="object"||typeof r=="function")try{var a=function(){var o=c.value;!j.call(e,o)&&o!==t&&b(e,o,{get:function(){return r[o]},enumerable:!(n=h(r,o))||n.enumerable})};for(var l=g(r)[Symbol.iterator](),c;!(o=(c=l.next()).done);o=true)a()}catch(e){u=true;i=e}finally{try{if(!o&&l.return!=null){l.return()}}finally{if(u){throw i}}}return e};var E=function(e,r,t){return t=e!=null?m(O(e)):{},S(r||!e||!e.__esModule?b(t,"default",{value:e,enumerable:!0}):t,e)},P=function(e){return S(b({},"__esModule",{value:!0}),e)};var x={};w(x,{CardElement:function(){return F.CardElement},FormspreeProvider:function(){return I},ValidationError:function(){return _},useForm:function(){return J},useFormspree:function(){return N},useSubmit:function(){return U}});module.exports=P(x);var F=require("@stripe/react-stripe-js");var D=E(require("react"));function _(e){var r=e.prefix,t=e.field,n=e.errors,o=s(e,["prefix","field","errors"]);if(n==null)return null;var u=t?n.getFieldErrors(t):n.getFormErrors();return u.length===0?null:D.default.createElement("div",l({},o),r?"".concat(r," "):null,u.map(function(e){return e.message}).join(", "))}var C=require("@formspree/core"),q=require("@stripe/react-stripe-js"),k=require("@stripe/stripe-js/pure.js"),M=E(require("react")),A=M.default.createContext(null);function I(e){var r=e.children,t=e.project,n=e.stripePK,o=v((0,M.useState)((0,C.createClient)({project:t})),2),u=o[0],i=o[1],a=(0,M.useMemo)(function(){return n?(0,k.loadStripe)(n):null},[n]);return(0,M.useEffect)(function(){var e=!0;return e&&i(function(e){return e.project!==t?(0,C.createClient)(f(l({},e),{project:t})):e}),function(){e=!1}},[t]),(0,M.useEffect)(function(){var e=!0;return a===null||a===void 0?void 0:a.then(function(r){e&&r&&i(function(e){return(0,C.createClient)(f(l({},e),{stripe:r}))})}),function(){e=!1}},[a]),M.default.createElement(A.Provider,{value:{client:u}},a?M.default.createElement(q.Elements,{stripe:a},r):r)}function N(){var e;return(e=(0,M.useContext)(A))!==null&&e!==void 0?e:{client:(0,C.getDefaultClient)()}}var T=require("react");var V=require("@formspree/core"),z=require("@stripe/react-stripe-js"),G=require("react");var K="2.5.0";var R="@formspree/react@".concat(K);function U(e){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};var t=N(),o=r.client,u=o===void 0?t.client:o,i=r.extraData,a=r.onError,l=r.onSuccess,c=r.origin,f=u.stripe,s=(0,G.useMemo)(function(){return f===null||f===void 0?void 0:f.elements().getElement(z.CardElement)},[f]);return function(){var r=n(function(r){var t,n,o,p,d,m,b,h,g,O,j,w,S;return y(this,function(y){switch(y.label){case 0:t=Y(r)?$(r):r;n=true,o=false,p=undefined;if(!(typeof i=="object"))return[3,10];y.label=1;case 1:y.trys.push([1,8,9,10]);d=Object.entries(i)[Symbol.iterator]();y.label=2;case 2:if(!!(n=(m=d.next()).done))return[3,7];b=v(m.value,2),h=b[0],g=b[1];O=void 0;if(!(typeof g=="function"))return[3,4];return[4,g()];case 3:j=O=y.sent();return[3,5];case 4:j=O=g;y.label=5;case 5:j,O!==void 0&&(0,V.appendExtraData)(t,h,O);y.label=6;case 6:n=true;return[3,2];case 7:return[3,10];case 8:w=y.sent();o=true;p=w;return[3,10];case 9:try{if(!n&&d.return!=null){d.return()}}finally{if(o){throw p}}return[7];case 10:return[4,u.submitForm(e,t,{endpoint:c,clientName:R,createPaymentMethod:f&&s?function(){return f.createPaymentMethod({type:"card",card:s,billing_details:B(t)})}:void 0})];case 11:S=y.sent();(0,V.isSubmissionError)(S)?a===null||a===void 0?void 0:a(S):l===null||l===void 0?void 0:l(S);return[2]}})});return function(e){return r.apply(this,arguments)}}()}function Y(e){return"preventDefault"in e&&typeof e.preventDefault=="function"}function $(e){e.preventDefault();var r=e.currentTarget;if(r.tagName!="FORM")throw new Error("submit was triggered for a non-form element");return new FormData(r)}function B(e){var r={address:H(e)};for(var t=0,n=["name","email","phone"];t<n.length;t++){var o=n[t];var i=u(e,FormData)?e.get(o):e[o];i&&typeof i=="string"&&(r[o]=i)}return r}function H(e){var r={};for(var t=0,n=[["address_line1","line1"],["address_line2","line2"],["address_city","city"],["address_country","country"],["address_state","state"],["address_postal_code","postal_code"]];t<n.length;t++){var o=v(n[t],2),i=o[0],a=o[1];var l=u(e,FormData)?e.get(i):e[i];l&&typeof l=="string"&&(r[a]=l)}return r}function J(e){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};var t=v((0,T.useState)(null),2),o=t[0],u=t[1],i=v((0,T.useState)(null),2),a=i[0],l=i[1],c=v((0,T.useState)(!1),2),f=c[0],s=c[1],p=v((0,T.useState)(!1),2),d=p[0],m=p[1];if(!e)throw new Error('You must provide a form key or hashid (e.g. useForm("myForm") or useForm("123xyz")');var b=U(e,{client:r.client,extraData:r.data,onError:function e(e){u(e),s(!1),m(!1)},onSuccess:function e(e){u(null),l(e),s(!1),m(!0)},origin:r.endpoint});return[{errors:o,result:a,submitting:f,succeeded:d},function(){var e=n(function(e){return y(this,function(r){switch(r.label){case 0:s(!0);return[4,b(e)];case 1:r.sent();return[2]}})});return function(r){return e.apply(this,arguments)}}(),function(){u(null),l(null),s(!1),m(!1)}]}0&&(module.exports={CardElement:CardElement,FormspreeProvider:FormspreeProvider,ValidationError:ValidationError,useForm:useForm,useFormspree:useFormspree,useSubmit:useSubmit}); |
{ | ||
"name": "@formspree/react", | ||
"version": "2.4.4", | ||
"version": "2.5.0", | ||
"private": false, | ||
@@ -29,4 +29,4 @@ "description": "The React component library for Formspree", | ||
"clean": "rm -rf dist && rm -rf node_modules", | ||
"dev": "tsup src/index.ts --format esm,cjs --dts --external react --sourcemap", | ||
"lint": "eslint src/*.ts*", | ||
"dev": "tsup src/index.ts --format esm,cjs --dts --external react --sourcemap --watch", | ||
"lint": "eslint ./src ./test", | ||
"test": "jest", | ||
@@ -36,3 +36,3 @@ "typecheck": "tsc --noEmit" | ||
"dependencies": { | ||
"@formspree/core": "^2.8.3", | ||
"@formspree/core": "^3.0.0", | ||
"@stripe/react-stripe-js": "^1.7.1", | ||
@@ -49,6 +49,5 @@ "@stripe/stripe-js": "^1.35.0" | ||
"@types/react-dom": "^18.0.6", | ||
"np": "^6.4.0", | ||
"eslint-plugin-react-hooks": "^4.3.0", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"tsup": "^6.2.2" | ||
"react-dom": "^18.2.0" | ||
}, | ||
@@ -62,6 +61,3 @@ "peerDependencies": { | ||
"registry": "https://registry.npmjs.org/" | ||
}, | ||
"np": { | ||
"yarn": false | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17852
10
71
+ Added@formspree/core@3.0.1(transitive)
- Removed@formspree/core@2.8.3(transitive)
Updated@formspree/core@^3.0.0