@formspree/react
Advanced tools
Comparing version 2.2.2 to 2.2.3
@@ -25,2 +25,17 @@ 'use strict'; | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
@@ -136,4 +151,8 @@ if (source == null) return {}; | ||
var version = "2.2.2"; | ||
var version = "2.2.3"; | ||
function isEvent(data) { | ||
return data.preventDefault !== undefined; | ||
} | ||
function useForm(formKey) { | ||
@@ -171,18 +190,31 @@ var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var handleSubmit = function handleSubmit(event) { | ||
event.preventDefault(); | ||
var form = event.target; | ||
var handleSubmit = function handleSubmit(submissionData) { | ||
var getFormData = function getFormData(event) { | ||
event.preventDefault(); | ||
var form = event.target; | ||
if (form.tagName != 'FORM') { | ||
throw new Error('submit was triggered for a non-form element'); | ||
} | ||
if (form.tagName != 'FORM') { | ||
throw new Error('submit was triggered for a non-form element'); | ||
} | ||
var formData = new FormData(form); // Append extra data from config | ||
return new FormData(form); | ||
}; | ||
var formData = isEvent(submissionData) ? getFormData(submissionData) : submissionData; | ||
var appendExtraData = function appendExtraData(prop, value) { | ||
if (formData instanceof FormData) { | ||
formData.append(prop, value); | ||
} else { | ||
formData = Object.assign(formData, _defineProperty({}, prop, value)); | ||
} | ||
}; // Append extra data from config | ||
if (_typeof(extraData) === 'object') { | ||
for (var prop in extraData) { | ||
if (typeof extraData[prop] === 'function') { | ||
formData.append(prop, extraData[prop].call(null)); | ||
appendExtraData(prop, extraData[prop].call(null)); | ||
} else { | ||
formData.append(prop, extraData[prop]); | ||
appendExtraData(prop, extraData[prop]); | ||
} | ||
@@ -189,0 +221,0 @@ } |
@@ -18,2 +18,17 @@ import React, { useState, useEffect, useContext } from 'react'; | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
@@ -129,4 +144,8 @@ if (source == null) return {}; | ||
var version = "2.2.2"; | ||
var version = "2.2.3"; | ||
function isEvent(data) { | ||
return data.preventDefault !== undefined; | ||
} | ||
function useForm(formKey) { | ||
@@ -164,18 +183,31 @@ var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var handleSubmit = function handleSubmit(event) { | ||
event.preventDefault(); | ||
var form = event.target; | ||
var handleSubmit = function handleSubmit(submissionData) { | ||
var getFormData = function getFormData(event) { | ||
event.preventDefault(); | ||
var form = event.target; | ||
if (form.tagName != 'FORM') { | ||
throw new Error('submit was triggered for a non-form element'); | ||
} | ||
if (form.tagName != 'FORM') { | ||
throw new Error('submit was triggered for a non-form element'); | ||
} | ||
var formData = new FormData(form); // Append extra data from config | ||
return new FormData(form); | ||
}; | ||
var formData = isEvent(submissionData) ? getFormData(submissionData) : submissionData; | ||
var appendExtraData = function appendExtraData(prop, value) { | ||
if (formData instanceof FormData) { | ||
formData.append(prop, value); | ||
} else { | ||
formData = Object.assign(formData, _defineProperty({}, prop, value)); | ||
} | ||
}; // Append extra data from config | ||
if (_typeof(extraData) === 'object') { | ||
for (var prop in extraData) { | ||
if (typeof extraData[prop] === 'function') { | ||
formData.append(prop, extraData[prop].call(null)); | ||
appendExtraData(prop, extraData[prop].call(null)); | ||
} else { | ||
formData.append(prop, extraData[prop]); | ||
appendExtraData(prop, extraData[prop]); | ||
} | ||
@@ -182,0 +214,0 @@ } |
@@ -20,2 +20,17 @@ var FormspreeReact = (function (exports, React) { | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
@@ -1144,4 +1159,8 @@ if (source == null) return {}; | ||
var version$1 = "2.2.2"; | ||
var version$1 = "2.2.3"; | ||
function isEvent(data) { | ||
return data.preventDefault !== undefined; | ||
} | ||
function useForm(formKey) { | ||
@@ -1179,18 +1198,31 @@ var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var handleSubmit = function handleSubmit(event) { | ||
event.preventDefault(); | ||
var form = event.target; | ||
var handleSubmit = function handleSubmit(submissionData) { | ||
var getFormData = function getFormData(event) { | ||
event.preventDefault(); | ||
var form = event.target; | ||
if (form.tagName != 'FORM') { | ||
throw new Error('submit was triggered for a non-form element'); | ||
} | ||
if (form.tagName != 'FORM') { | ||
throw new Error('submit was triggered for a non-form element'); | ||
} | ||
var formData = new FormData(form); // Append extra data from config | ||
return new FormData(form); | ||
}; | ||
var formData = isEvent(submissionData) ? getFormData(submissionData) : submissionData; | ||
var appendExtraData = function appendExtraData(prop, value) { | ||
if (formData instanceof FormData) { | ||
formData.append(prop, value); | ||
} else { | ||
formData = Object.assign(formData, _defineProperty({}, prop, value)); | ||
} | ||
}; // Append extra data from config | ||
if (_typeof(extraData) === 'object') { | ||
for (var prop in extraData) { | ||
if (typeof extraData[prop] === 'function') { | ||
formData.append(prop, extraData[prop].call(null)); | ||
appendExtraData(prop, extraData[prop].call(null)); | ||
} else { | ||
formData.append(prop, extraData[prop]); | ||
appendExtraData(prop, extraData[prop]); | ||
} | ||
@@ -1197,0 +1229,0 @@ } |
import React from 'react'; | ||
import { Client } from '@formspree/core'; | ||
import { SubmissionResponse } from '@formspree/core/forms'; | ||
import { SubmissionResponse, SubmissionData } from '@formspree/core/forms'; | ||
interface ErrorPayload { | ||
@@ -9,8 +9,10 @@ field?: string; | ||
} | ||
declare type SubmitHandler = (event: React.FormEvent<HTMLFormElement>) => Promise<SubmissionResponse>; | ||
declare type FormEvent = React.FormEvent<HTMLFormElement>; | ||
declare type ExtraData = { | ||
[key: string]: string | (() => string); | ||
}; | ||
declare type SubmitHandler = (submissionData: FormEvent | SubmissionData) => Promise<SubmissionResponse>; | ||
export declare function useForm(formKey: string, args?: { | ||
client?: Client; | ||
data?: { | ||
[key: string]: string | (() => string); | ||
}; | ||
data?: ExtraData; | ||
endpoint?: string; | ||
@@ -17,0 +19,0 @@ debug?: boolean; |
{ | ||
"name": "@formspree/react", | ||
"version": "2.2.2", | ||
"version": "2.2.3", | ||
"description": "The React component library for Formspree", | ||
@@ -5,0 +5,0 @@ "bugs": { |
@@ -5,8 +5,4 @@ # Formspree React | ||
## Releasing | ||
## Help and Support | ||
Run the following to publish a new version: | ||
``` | ||
npm run release | ||
``` | ||
For help and support please see [the Formspree React docs](https://help.formspree.io/hc/en-us/articles/360055613373). |
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
61717
1671
8