react-google-forms-hooks
Advanced tools
Comparing version 1.0.4 to 1.1.0
import { GoogleForm, UseGoogleFormReturn } from '../types'; | ||
export declare const GOOGLE_FORMS_URL = "https://docs.google.com/forms/d"; | ||
export declare const formatQuestionName: (id: string) => string; | ||
export declare const useGoogleForm: ({ form }: { | ||
form: GoogleForm; | ||
}) => UseGoogleFormReturn; |
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var reactHookForm = require('react-hook-form'); | ||
var queryString = _interopDefault(require('query-string')); | ||
var axios = _interopDefault(require('axios')); | ||
var fetch = _interopDefault(require('isomorphic-unfetch')); | ||
var React = require('react'); | ||
@@ -10,21 +9,2 @@ var slugify = _interopDefault(require('slugify')); | ||
// A type of promise-like that resolves synchronously and supports only one observer | ||
const _iteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator"))) : "@@iterator"; | ||
const _asyncIteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.asyncIterator || (Symbol.asyncIterator = Symbol("Symbol.asyncIterator"))) : "@@asyncIterator"; | ||
// Asynchronously call a function and send errors to recovery continuation | ||
function _catch(body, recover) { | ||
try { | ||
var result = body(); | ||
} catch(e) { | ||
return recover(e); | ||
} | ||
if (result && result.then) { | ||
return result.then(void 0, recover); | ||
} | ||
return result; | ||
} | ||
function _extends() { | ||
@@ -200,3 +180,33 @@ _extends = Object.assign || function (target) { | ||
var GOOGLE_FORMS_URL = 'https://docs.google.com/forms/d'; | ||
var formatQuestionName = function formatQuestionName(id) { | ||
if (id.includes(OTHER_OPTION_RESPONSE)) { | ||
return "entry." + id.replace("-" + OTHER_OPTION + "-" + OTHER_OPTION_RESPONSE, '') + "." + OTHER_OPTION_RESPONSE; | ||
} | ||
return "entry." + id; | ||
}; | ||
var submitToGoogleForms = function submitToGoogleForms(form, formData) { | ||
try { | ||
var urlParams = new URLSearchParams(); | ||
Object.keys(formData).forEach(function (key) { | ||
if (formData[key]) { | ||
urlParams.append(formatQuestionName(key), formData[key]); | ||
} | ||
}); | ||
return Promise.resolve(fetch(GOOGLE_FORMS_URL + "/" + form.action + "/formResponse?submit=Submit&" + urlParams.toString(), { | ||
method: 'GET', | ||
mode: 'no-cors', | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
} | ||
})).then(function (fetchedResult) { | ||
if (!fetchedResult.ok || fetchedResult.status >= 300) { | ||
console.warn('the result of GoogleForm is not correct.', fetchedResult); | ||
} | ||
}); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
var resolveField = function resolveField(id, form) { | ||
@@ -213,9 +223,2 @@ var fieldIndex = form.fieldsOrder[id]; | ||
var formatQuestionName = function formatQuestionName(id) { | ||
if (id.includes(OTHER_OPTION_RESPONSE)) { | ||
return "entry." + id.replace("-" + OTHER_OPTION + "-" + OTHER_OPTION_RESPONSE, '') + "." + OTHER_OPTION_RESPONSE; | ||
} | ||
return "entry." + id; | ||
}; | ||
var useGoogleForm = function useGoogleForm(_ref) { | ||
@@ -229,28 +232,6 @@ var form = _ref.form; | ||
var submitToGoogleForms = function submitToGoogleForms(formData) { | ||
try { | ||
var fields = {}; | ||
Object.keys(formData).forEach(function (key) { | ||
fields[formatQuestionName(key)] = formData[key]; | ||
}); | ||
var params = queryString.stringify(fields, { | ||
skipNull: true, | ||
skipEmptyString: true | ||
}); | ||
var _temp2 = _catch(function () { | ||
return Promise.resolve(axios.get(GOOGLE_FORMS_URL + "/" + form.action + "/formResponse?" + params + "&submit=Submit", { | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
} | ||
})).then(function () {}); | ||
}, function () {}); | ||
return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(function () {}) : void 0); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
methods.submitToGoogleForms = function (formData) { | ||
return submitToGoogleForms(form, formData); | ||
}; | ||
methods.submitToGoogleForms = submitToGoogleForms; | ||
return methods; | ||
@@ -432,2 +413,21 @@ }; | ||
// A type of promise-like that resolves synchronously and supports only one observer | ||
const _iteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator"))) : "@@iterator"; | ||
const _asyncIteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.asyncIterator || (Symbol.asyncIterator = Symbol("Symbol.asyncIterator"))) : "@@asyncIterator"; | ||
// Asynchronously call a function and send errors to recovery continuation | ||
function _catch(body, recover) { | ||
try { | ||
var result = body(); | ||
} catch(e) { | ||
return recover(e); | ||
} | ||
if (result && result.then) { | ||
return result.then(void 0, recover); | ||
} | ||
return result; | ||
} | ||
var toBool = function toBool(n) { | ||
@@ -456,4 +456,4 @@ return n === 1; | ||
try { | ||
return Promise.resolve(axios.get(formUrl)).then(function (html) { | ||
return html.data; | ||
return Promise.resolve(fetch(formUrl)).then(function (response) { | ||
return Promise.resolve(response.text()); | ||
}); | ||
@@ -508,2 +508,6 @@ } catch (e) { | ||
if (fieldId === 9) { | ||
return 'DATE'; | ||
} | ||
return fieldTypes[fieldId]; | ||
@@ -606,2 +610,10 @@ }; | ||
} | ||
case 'DATE': | ||
{ | ||
var _fieldInfo4 = rawField[4][0]; | ||
field.id = toString(_fieldInfo4[0]); | ||
field.required = toBool(rawField[4][0][2]); | ||
break; | ||
} | ||
} | ||
@@ -670,22 +682,2 @@ | ||
var submitToGoogleForms = function submitToGoogleForms(form, formData) { | ||
try { | ||
var fields = {}; | ||
Object.keys(formData).forEach(function (key) { | ||
fields[formatQuestionName(key)] = formData[key]; | ||
}); | ||
var params = queryString.stringify(fields, { | ||
skipNull: true, | ||
skipEmptyString: true | ||
}); | ||
return Promise.resolve(axios.get(GOOGLE_FORMS_URL + "/" + form.action + "/formResponse?" + params + "&submit=Submit", { | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
} | ||
})); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
exports.GOOGLE_FORMS_URL = GOOGLE_FORMS_URL; | ||
@@ -692,0 +684,0 @@ exports.GoogleFormProvider = GoogleFormProvider; |
import { useForm } from 'react-hook-form'; | ||
import queryString from 'query-string'; | ||
import axios from 'axios'; | ||
import fetch from 'isomorphic-unfetch'; | ||
import { createContext, useContext, createElement, useState, useEffect } from 'react'; | ||
@@ -8,21 +7,2 @@ import slugify from 'slugify'; | ||
// A type of promise-like that resolves synchronously and supports only one observer | ||
const _iteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator"))) : "@@iterator"; | ||
const _asyncIteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.asyncIterator || (Symbol.asyncIterator = Symbol("Symbol.asyncIterator"))) : "@@asyncIterator"; | ||
// Asynchronously call a function and send errors to recovery continuation | ||
function _catch(body, recover) { | ||
try { | ||
var result = body(); | ||
} catch(e) { | ||
return recover(e); | ||
} | ||
if (result && result.then) { | ||
return result.then(void 0, recover); | ||
} | ||
return result; | ||
} | ||
function _extends() { | ||
@@ -198,3 +178,33 @@ _extends = Object.assign || function (target) { | ||
var GOOGLE_FORMS_URL = 'https://docs.google.com/forms/d'; | ||
var formatQuestionName = function formatQuestionName(id) { | ||
if (id.includes(OTHER_OPTION_RESPONSE)) { | ||
return "entry." + id.replace("-" + OTHER_OPTION + "-" + OTHER_OPTION_RESPONSE, '') + "." + OTHER_OPTION_RESPONSE; | ||
} | ||
return "entry." + id; | ||
}; | ||
var submitToGoogleForms = function submitToGoogleForms(form, formData) { | ||
try { | ||
var urlParams = new URLSearchParams(); | ||
Object.keys(formData).forEach(function (key) { | ||
if (formData[key]) { | ||
urlParams.append(formatQuestionName(key), formData[key]); | ||
} | ||
}); | ||
return Promise.resolve(fetch(GOOGLE_FORMS_URL + "/" + form.action + "/formResponse?submit=Submit&" + urlParams.toString(), { | ||
method: 'GET', | ||
mode: 'no-cors', | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
} | ||
})).then(function (fetchedResult) { | ||
if (!fetchedResult.ok || fetchedResult.status >= 300) { | ||
console.warn('the result of GoogleForm is not correct.', fetchedResult); | ||
} | ||
}); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
var resolveField = function resolveField(id, form) { | ||
@@ -211,9 +221,2 @@ var fieldIndex = form.fieldsOrder[id]; | ||
var formatQuestionName = function formatQuestionName(id) { | ||
if (id.includes(OTHER_OPTION_RESPONSE)) { | ||
return "entry." + id.replace("-" + OTHER_OPTION + "-" + OTHER_OPTION_RESPONSE, '') + "." + OTHER_OPTION_RESPONSE; | ||
} | ||
return "entry." + id; | ||
}; | ||
var useGoogleForm = function useGoogleForm(_ref) { | ||
@@ -227,28 +230,6 @@ var form = _ref.form; | ||
var submitToGoogleForms = function submitToGoogleForms(formData) { | ||
try { | ||
var fields = {}; | ||
Object.keys(formData).forEach(function (key) { | ||
fields[formatQuestionName(key)] = formData[key]; | ||
}); | ||
var params = queryString.stringify(fields, { | ||
skipNull: true, | ||
skipEmptyString: true | ||
}); | ||
var _temp2 = _catch(function () { | ||
return Promise.resolve(axios.get(GOOGLE_FORMS_URL + "/" + form.action + "/formResponse?" + params + "&submit=Submit", { | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
} | ||
})).then(function () {}); | ||
}, function () {}); | ||
return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(function () {}) : void 0); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
methods.submitToGoogleForms = function (formData) { | ||
return submitToGoogleForms(form, formData); | ||
}; | ||
methods.submitToGoogleForms = submitToGoogleForms; | ||
return methods; | ||
@@ -430,2 +411,21 @@ }; | ||
// A type of promise-like that resolves synchronously and supports only one observer | ||
const _iteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator"))) : "@@iterator"; | ||
const _asyncIteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.asyncIterator || (Symbol.asyncIterator = Symbol("Symbol.asyncIterator"))) : "@@asyncIterator"; | ||
// Asynchronously call a function and send errors to recovery continuation | ||
function _catch(body, recover) { | ||
try { | ||
var result = body(); | ||
} catch(e) { | ||
return recover(e); | ||
} | ||
if (result && result.then) { | ||
return result.then(void 0, recover); | ||
} | ||
return result; | ||
} | ||
var toBool = function toBool(n) { | ||
@@ -454,4 +454,4 @@ return n === 1; | ||
try { | ||
return Promise.resolve(axios.get(formUrl)).then(function (html) { | ||
return html.data; | ||
return Promise.resolve(fetch(formUrl)).then(function (response) { | ||
return Promise.resolve(response.text()); | ||
}); | ||
@@ -506,2 +506,6 @@ } catch (e) { | ||
if (fieldId === 9) { | ||
return 'DATE'; | ||
} | ||
return fieldTypes[fieldId]; | ||
@@ -604,2 +608,10 @@ }; | ||
} | ||
case 'DATE': | ||
{ | ||
var _fieldInfo4 = rawField[4][0]; | ||
field.id = toString(_fieldInfo4[0]); | ||
field.required = toBool(rawField[4][0][2]); | ||
break; | ||
} | ||
} | ||
@@ -668,23 +680,3 @@ | ||
var submitToGoogleForms = function submitToGoogleForms(form, formData) { | ||
try { | ||
var fields = {}; | ||
Object.keys(formData).forEach(function (key) { | ||
fields[formatQuestionName(key)] = formData[key]; | ||
}); | ||
var params = queryString.stringify(fields, { | ||
skipNull: true, | ||
skipEmptyString: true | ||
}); | ||
return Promise.resolve(axios.get(GOOGLE_FORMS_URL + "/" + form.action + "/formResponse?" + params + "&submit=Submit", { | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
} | ||
})); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
export { GOOGLE_FORMS_URL, GoogleFormProvider, formatQuestionName, googleFormsToJson, submitToGoogleForms, useCheckboxGridInput, useCheckboxInput, useDropdownInput, useGoogleForm, useGoogleFormContext, useLinearInput, useLongAnswerInput, useRadioGridInput, useRadioInput, useShortAnswerInput }; | ||
//# sourceMappingURL=index.modern.js.map |
import { GoogleForm } from '../types'; | ||
export declare const submitToGoogleForms: (form: GoogleForm, formData: object) => Promise<import("axios").AxiosResponse<any>>; | ||
export declare const GOOGLE_FORMS_URL = "https://docs.google.com/forms/d"; | ||
export declare const formatQuestionName: (id: string) => string; | ||
export declare const submitToGoogleForms: (form: GoogleForm, formData: object) => Promise<void>; |
@@ -15,2 +15,5 @@ export interface Option { | ||
} | ||
export interface DateField extends BaseField { | ||
type: 'DATE'; | ||
} | ||
export interface CustomOptionField extends BaseField { | ||
@@ -45,3 +48,3 @@ type: 'CHECKBOX' | 'RADIO'; | ||
} | ||
export declare type Field = TextField | CustomOptionField | DropdownField | GridField | LinearField; | ||
export declare type Field = TextField | DateField | CustomOptionField | DropdownField | GridField | LinearField; | ||
export declare type FieldTypes = Field['type']; | ||
@@ -48,0 +51,0 @@ export declare type FieldsOrder = { |
{ | ||
"name": "react-google-forms-hooks", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"description": "Library to create forms using React backed by Google Forms.", | ||
@@ -70,5 +70,4 @@ "author": "francisconeves97", | ||
"@testing-library/react": "^12.0.0", | ||
"axios": "^0.21.1", | ||
"cheerio": "^1.0.0-rc.10", | ||
"query-string": "^7.0.1", | ||
"isomorphic-unfetch": "^3.1.0", | ||
"react-hook-form": "^7.10.1", | ||
@@ -75,0 +74,0 @@ "slugify": "^1.5.3" |
# React Google Forms Hooks | ||
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section --> | ||
[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors-) | ||
[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors-) | ||
<!-- ALL-CONTRIBUTORS-BADGE:END --> | ||
@@ -117,2 +117,3 @@ | ||
<td align="center"><a href="https://github.com/juliangsibecas"><img src="https://avatars.githubusercontent.com/u/25715495?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Julián Gómez Sibecas</b></sub></a><br /><a href="https://github.com/francisconeves97/react-google-forms-hooks/commits?author=juliangsibecas" title="Code">💻</a></td> | ||
<td align="center"><a href="https://lumen.media"><img src="https://avatars.githubusercontent.com/u/489221?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Dominic Garms</b></sub></a><br /><a href="#ideas-dohomi" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/francisconeves97/react-google-forms-hooks/commits?author=dohomi" title="Code">💻</a></td> | ||
</tr> | ||
@@ -119,0 +120,0 @@ </table> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
181597
7
43
1423
126
4
+ Addedisomorphic-unfetch@^3.1.0
+ Addedisomorphic-unfetch@3.1.0(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedunfetch@4.2.0(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
- Removedaxios@^0.21.1
- Removedquery-string@^7.0.1
- Removedaxios@0.21.4(transitive)
- Removeddecode-uri-component@0.2.2(transitive)
- Removedfilter-obj@1.1.0(transitive)
- Removedfollow-redirects@1.15.6(transitive)
- Removedquery-string@7.1.3(transitive)
- Removedsplit-on-first@1.1.0(transitive)
- Removedstrict-uri-encode@2.0.0(transitive)