Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@formspree/react

Package Overview
Dependencies
Maintainers
3
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@formspree/react - npm Package Compare versions

Comparing version 2.4.2 to 2.4.3

679

dist/index.js

@@ -1,678 +0,1 @@

function _array_like_to_array(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
return arr2;
}
function _array_with_holes(arr) {
if (Array.isArray(arr)) return arr;
}
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _async_to_generator(fn) {
return function() {
var self = this, args = arguments;
return new Promise(function(resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
}
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(undefined);
});
};
}
function _define_property(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 _instanceof(left, right) {
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
return !!right[Symbol.hasInstance](left);
} else {
return left instanceof right;
}
}
function _iterable_to_array_limit(arr, i) {
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
if (_i == null) return;
var _arr = [];
var _n = true;
var _d = false;
var _s, _e;
try {
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally{
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally{
if (_d) throw _e;
}
}
return _arr;
}
function _non_iterable_rest() {
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 _object_spread(target) {
for(var i = 1; i < arguments.length; i++){
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === "function") {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function(key) {
_define_property(target, key, source[key]);
});
}
return target;
}
function _object_without_properties(source, excluded) {
if (source == null) return {};
var target = _object_without_properties_loose(source, excluded);
var key, i;
if (Object.getOwnPropertySymbols) {
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
for(i = 0; i < sourceSymbolKeys.length; i++){
key = sourceSymbolKeys[i];
if (excluded.indexOf(key) >= 0) continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
target[key] = source[key];
}
}
return target;
}
function _object_without_properties_loose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for(i = 0; i < sourceKeys.length; i++){
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
return target;
}
function _sliced_to_array(arr, i) {
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
}
function _unsupported_iterable_to_array(o, minLen) {
if (!o) return;
if (typeof o === "string") return _array_like_to_array(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.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 _array_like_to_array(o, minLen);
}
function _ts_generator(thisArg, body) {
var f, y, t, g, _ = {
label: 0,
sent: function() {
if (t[0] & 1) throw t[1];
return t[1];
},
trys: [],
ops: []
};
return(g = {
next: verb(0),
"throw": verb(1),
"return": verb(2)
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
return this;
}), g);
function verb(n) {
return function(v) {
return step([
n,
v
]);
};
}
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while(_)try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [
op[0] & 2,
t.value
];
switch(op[0]){
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return {
value: op[1],
done: false
};
case 5:
_.label++;
y = op[1];
op = [
0
];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2]) _.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
} catch (e) {
op = [
6,
e
];
y = 0;
} finally{
f = t = 0;
}
if (op[0] & 5) throw op[1];
return {
value: op[0] ? op[1] : void 0,
done: true
};
}
}
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = function(target, all) {
for(var name in all)__defProp(target, name, {
get: all[name],
enumerable: true
});
};
var __copyProps = function(to, from, except, desc) {
if (from && typeof from === "object" || typeof from === "function") {
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
try {
var _loop = function() {
var key = _step.value;
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: function() {
return from[key];
},
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
};
for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally{
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally{
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
return to;
};
var __toESM = function(mod, isNodeMode, target) {
return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
value: mod,
enumerable: true
}) : target, mod);
};
var __toCommonJS = function(mod) {
return __copyProps(__defProp({}, "__esModule", {
value: true
}), mod);
};
// src/index.ts
var src_exports = {};
__export(src_exports, {
CardElement: function() {
return import_react_stripe_js.CardElement;
},
FormspreeProvider: function() {
return FormspreeProvider;
},
ValidationError: function() {
return ValidationError;
},
isFieldError: function() {
return import_core2.isFieldError;
},
useForm: function() {
return useForm;
},
useFormspree: function() {
return useFormspree;
}
});
module.exports = __toCommonJS(src_exports);
// src/context.tsx
var import_react = __toESM(require("react"));
var import_core = require("@formspree/core");
var import_pure = require("@stripe/stripe-js/pure.js");
var Elements = (0, import_react.lazy)(function() {
return import("@stripe/react-stripe-js").then(function(module2) {
return {
default: module2.Elements
};
});
});
var FormspreeContext = import_react.default.createContext({
client: void 0
});
FormspreeContext.displayName = "Formspree";
var stripePromise;
var getStripe = function(stripeKey) {
if (!stripePromise) {
stripePromise = (0, import_pure.loadStripe)(stripeKey);
}
return stripePromise;
};
var handleCreateClient = function(promise, project) {
var config = {};
if (promise) {
config.stripePromise = promise;
}
if (project) {
config.project = project;
}
return (0, import_core.createClient)(config);
};
var FormspreeProvider = function(props) {
var _ref = _sliced_to_array((0, import_react.useState)(void 0), 2), stateStripePromise = _ref[0], setStateStripePromise = _ref[1];
var _ref1 = _sliced_to_array((0, import_react.useState)(handleCreateClient(stateStripePromise, props.project)), 2), client = _ref1[0], setClient = _ref1[1];
(0, import_react.useEffect)(function() {
client.startBrowserSession();
return function() {
client.teardown();
};
}, []);
(0, import_react.useEffect)(function() {
var getStripePromise = function() {
var _ref = _async_to_generator(function() {
var promiseStripe;
return _ts_generator(this, function(_state) {
switch(_state.label){
case 0:
return [
4,
getStripe(props.stripePK)
];
case 1:
promiseStripe = _state.sent();
setStateStripePromise(promiseStripe);
return [
2
];
}
});
});
return function getStripePromise() {
return _ref.apply(this, arguments);
};
}();
if (props.stripePK) {
getStripePromise();
}
}, [
props.stripePK
]);
(0, import_react.useEffect)(function() {
if (stateStripePromise) {
setClient(handleCreateClient(stateStripePromise, props.project));
}
}, [
stateStripePromise
]);
return /* @__PURE__ */ import_react.default.createElement(FormspreeContext.Provider, {
value: {
client: client
}
}, props.stripePK ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, stateStripePromise && /* @__PURE__ */ import_react.default.createElement(import_react.Suspense, {
fallback: /* @__PURE__ */ import_react.default.createElement("p", null, "....")
}, /* @__PURE__ */ import_react.default.createElement(Elements, {
stripe: stateStripePromise
}, /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, props.children)))) : /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, props.children));
};
function useFormspree() {
var context = (0, import_react.useContext)(FormspreeContext);
return context.client ? context : {
client: (0, import_core.getDefaultClient)()
};
}
// src/useForm.ts
var import_react2 = require("react");
var import_react_stripe_js = require("@stripe/react-stripe-js");
// package.json
var version = "2.4.2";
// src/useForm.ts
var isEvent = function(data) {
return data.preventDefault !== void 0;
};
var useForm = function(formKey) {
var args = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
var _ref = _sliced_to_array((0, import_react2.useState)(null), 2), result = _ref[0], setResult = _ref[1];
var _ref1 = _sliced_to_array((0, import_react2.useState)(false), 2), submitting = _ref1[0], setSubmitting = _ref1[1];
var _ref2 = _sliced_to_array((0, import_react2.useState)(false), 2), succeeded = _ref2[0], setSucceeded = _ref2[1];
var _ref3 = _sliced_to_array((0, import_react2.useState)([]), 2), errors = _ref3[0], setErrors = _ref3[1];
var formspreeContext = useFormspree();
var client = args.client || formspreeContext;
var stripe;
var elements;
if (!client) {
throw new Error("You must provide a Formspree client");
}
if (!formKey) {
throw new Error('You must provide a form key or hashid (e.g. useForm("myForm") or useForm("123xyz")');
}
if (formspreeContext.client && formspreeContext.client.stripePromise) {
stripe = (0, import_react_stripe_js.useStripe)();
elements = (0, import_react_stripe_js.useElements)();
}
var debug = !!args.debug;
var extraData = args.data;
var reset = function() {
setSubmitting(false);
setSucceeded(false);
setErrors([]);
};
var handleSubmit = function() {
var _ref = _async_to_generator(function(submissionData) {
var getFormData, formData, _tmp, appendExtraData, _tmp1, _tmp2, _i, prop, extraDataValue, createPaymentMethod;
return _ts_generator(this, function(_state) {
switch(_state.label){
case 0:
getFormData = function() {
var _ref = _async_to_generator(function(event) {
var form;
return _ts_generator(this, function(_state) {
event.preventDefault();
form = event.target;
if (form.tagName != "FORM") {
throw new Error("submit was triggered for a non-form element");
}
return [
2,
new FormData(form)
];
});
});
return function getFormData(event) {
return _ref.apply(this, arguments);
};
}();
if (!isEvent(submissionData)) return [
3,
2
];
return [
4,
getFormData(submissionData)
];
case 1:
_tmp = _state.sent();
return [
3,
3
];
case 2:
_tmp = submissionData;
_state.label = 3;
case 3:
formData = _tmp;
appendExtraData = function(prop, value) {
if (_instanceof(formData, FormData)) {
formData.append(prop, value);
} else {
formData = Object.assign(formData, _define_property({}, prop, value));
}
};
if (!(typeof extraData === "object")) return [
3,
10
];
_tmp1 = [];
for(_tmp2 in extraData)_tmp1.push(_tmp2);
_i = 0;
_state.label = 4;
case 4:
if (!(_i < _tmp1.length)) return [
3,
10
];
prop = _tmp1[_i];
extraDataValue = void 0;
if (!(typeof extraData[prop] === "function")) return [
3,
7
];
extraDataValue = extraData[prop].call(null);
if (!(typeof (extraDataValue === null || extraDataValue === void 0 ? void 0 : extraDataValue.then) === "function")) return [
3,
6
];
return [
4,
extraDataValue
];
case 5:
extraDataValue = _state.sent();
_state.label = 6;
case 6:
return [
3,
8
];
case 7:
extraDataValue = extraData[prop];
_state.label = 8;
case 8:
if (extraDataValue !== void 0) {
appendExtraData(prop, extraDataValue);
}
_state.label = 9;
case 9:
_i++;
return [
3,
4
];
case 10:
createPaymentMethod = function() {
var _ref = _async_to_generator(function() {
var address, payload;
return _ts_generator(this, function(_state) {
switch(_state.label){
case 0:
address = _object_spread({}, formData.address_line1 && {
line1: formData.address_line1
}, formData.address_line2 && {
line2: formData.address_line2
}, formData.address_city && {
city: formData.address_city
}, formData.address_country && {
country: formData.address_country
}, formData.address_state && {
state: formData.address_state
}, formData.address_postal_code && {
postal_code: formData.address_postal_code
});
return [
4,
stripe.createPaymentMethod({
type: "card",
card: elements.getElement(import_react_stripe_js.CardElement),
billing_details: _object_spread({}, formData.name && {
name: formData.name
}, formData.email && {
email: formData.email
}, formData.phone && {
phone: formData.phone
}, address && {
address: address
})
})
];
case 1:
payload = _state.sent();
return [
2,
payload
];
}
});
});
return function createPaymentMethod() {
return _ref.apply(this, arguments);
};
}();
setSubmitting(true);
return [
2,
formspreeContext.client.submitForm(formKey, formData, {
endpoint: args.endpoint,
clientName: "@formspree/react@".concat(version),
createPaymentMethod: formspreeContext.client && formspreeContext.client.stripePromise ? createPaymentMethod : void 0
}).then(function(result2) {
var status = result2.response.status;
var body;
if (status === 200) {
if (debug) console.log("Form submitted", result2);
setSucceeded(true);
setResult(result2);
setErrors([]);
} else if (status >= 400) {
body = result2.body;
if (body.errors) {
setErrors(body.errors);
if (debug) console.log("Error", result2);
} else {
setErrors([
{
message: "Unexpected error"
}
]);
if (debug) console.log("Unexpected error", result2);
}
setSucceeded(false);
}
return result2;
}).catch(function(error) {
if (debug) console.log("Unexpected error", error);
setSucceeded(false);
throw error;
}).finally(function() {
setSubmitting(false);
})
];
}
});
});
return function handleSubmit(submissionData) {
return _ref.apply(this, arguments);
};
}();
return [
{
result: result,
submitting: submitting,
succeeded: succeeded,
errors: errors
},
handleSubmit,
reset
];
};
// src/ValidationError.tsx
var import_react3 = __toESM(require("react"));
var ValidationError = function(props) {
var prefix = props.prefix, field = props.field, errors = props.errors, attrs = _object_without_properties(props, [
"prefix",
"field",
"errors"
]);
var error = (errors || []).find(function(error2) {
return error2.field === field;
});
if (!error) {
return null;
}
return /* @__PURE__ */ import_react3.default.createElement("div", _object_spread({}, attrs), prefix, " ", error.message);
};
// src/types.ts
var import_core2 = require("@formspree/core");
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
CardElement: CardElement,
FormspreeProvider: FormspreeProvider,
ValidationError: ValidationError,
isFieldError: isFieldError,
useForm: useForm,
useFormspree: useFormspree
});
//# sourceMappingURL=index.js.map
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.3";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});

39

package.json
{
"name": "@formspree/react",
"version": "2.4.2",
"version": "2.4.3",
"private": false,
"description": "The React component library for Formspree",
"private": false,
"bugs": {

@@ -19,5 +19,2 @@ "url": "https://github.com/formspree/formspree-react/issues"

],
"files": [
"dist/**"
],
"sideEffects": false,

@@ -27,26 +24,15 @@ "main": "./dist/index.js",

"types": "./dist/index.d.ts",
"files": [
"dist/**"
],
"scripts": {
"build": "tsup src/index.ts --format esm,cjs --dts --external react --minify",
"clean": "rm -rf dist && rm -rf node_modules",
"dev": "tsup src/index.ts --format esm,cjs --dts --external react --sourcemap",
"clean": "rm -rf dist && rm -rf node_modules",
"lint": "eslint src/*.ts*",
"test": "jest"
"test": "jest",
"typecheck": "tsc --noEmit"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,ts,tsx,css,json,md}": [
"npx prettier --write",
"git add"
],
"package.json": [
"npx sort-package-json",
"git add"
]
},
"dependencies": {
"@formspree/core": "^2.8.1",
"@formspree/core": "^2.8.2",
"@stripe/react-stripe-js": "^1.7.1",

@@ -65,12 +51,7 @@ "@stripe/stripe-js": "^1.35.0"

"babel-jest": "^26.3.0",
"husky": "^3.0.5",
"jest": "^26.4.2",
"lint-staged": "^9.2.5",
"np": "^6.4.0",
"prettier": "^1.18.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"sort-package-json": "^1.22.1",
"tsup": "^6.2.2",
"typescript": "^4.7.4"
"tsup": "^6.2.2"
},

@@ -77,0 +58,0 @@ "peerDependencies": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc