@customgform-lib/react-customgform
Version:
Simple [React](http://facebook.github.io/react/) component acting as a thin layer over the [CustomGForm - Google Form Customizer](https://customgform.com/)
31 lines (28 loc) • 16.3 kB
JavaScript
(function(P,A){typeof exports=="object"&&typeof module<"u"?module.exports=A(require("react")):typeof define=="function"&&define.amd?define(["react"],A):(P=typeof globalThis<"u"?globalThis:P||self,P["react-customgform"]=A(P.React))})(this,function(P){"use strict";function A(s){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const p in s)if(p!=="default"){const b=Object.getOwnPropertyDescriptor(s,p);Object.defineProperty(o,p,b.get?b:{enumerable:!0,get:()=>s[p]})}}return o.default=s,Object.freeze(o)}const B=A(P);var J={exports:{}},I={};/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var ne;function xe(){if(ne)return I;ne=1;var s=P,o=Symbol.for("react.element"),p=Symbol.for("react.fragment"),b=Object.prototype.hasOwnProperty,O=s.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,C={key:!0,ref:!0,__self:!0,__source:!0};function f(m,c,_){var y,T={},R=null,U=null;_!==void 0&&(R=""+_),c.key!==void 0&&(R=""+c.key),c.ref!==void 0&&(U=c.ref);for(y in c)b.call(c,y)&&!C.hasOwnProperty(y)&&(T[y]=c[y]);if(m&&m.defaultProps)for(y in c=m.defaultProps,c)T[y]===void 0&&(T[y]=c[y]);return{$$typeof:o,type:m,key:R,ref:U,props:T,_owner:O.current}}return I.Fragment=p,I.jsx=f,I.jsxs=f,I}var L={};/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var ae;function ke(){return ae||(ae=1,process.env.NODE_ENV!=="production"&&function(){var s=P,o=Symbol.for("react.element"),p=Symbol.for("react.portal"),b=Symbol.for("react.fragment"),O=Symbol.for("react.strict_mode"),C=Symbol.for("react.profiler"),f=Symbol.for("react.provider"),m=Symbol.for("react.context"),c=Symbol.for("react.forward_ref"),_=Symbol.for("react.suspense"),y=Symbol.for("react.suspense_list"),T=Symbol.for("react.memo"),R=Symbol.for("react.lazy"),U=Symbol.for("react.offscreen"),oe=Symbol.iterator,$e="@@iterator";function We(e){if(e===null||typeof e!="object")return null;var r=oe&&e[oe]||e[$e];return typeof r=="function"?r:null}var k=s.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function g(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];Ye("error",e,t)}}function Ye(e,r,t){{var n=k.ReactDebugCurrentFrame,u=n.getStackAddendum();u!==""&&(r+="%s",t=t.concat([u]));var l=t.map(function(i){return String(i)});l.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,l)}}var Ue=!1,Ve=!1,Me=!1,Ne=!1,Ge=!1,ie;ie=Symbol.for("react.module.reference");function Be(e){return!!(typeof e=="string"||typeof e=="function"||e===b||e===C||Ge||e===O||e===_||e===y||Ne||e===U||Ue||Ve||Me||typeof e=="object"&&e!==null&&(e.$$typeof===R||e.$$typeof===T||e.$$typeof===f||e.$$typeof===m||e.$$typeof===c||e.$$typeof===ie||e.getModuleId!==void 0))}function Je(e,r,t){var n=e.displayName;if(n)return n;var u=r.displayName||r.name||"";return u!==""?t+"("+u+")":t}function ue(e){return e.displayName||"Context"}function w(e){if(e==null)return null;if(typeof e.tag=="number"&&g("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case b:return"Fragment";case p:return"Portal";case C:return"Profiler";case O:return"StrictMode";case _:return"Suspense";case y:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case m:var r=e;return ue(r)+".Consumer";case f:var t=e;return ue(t._context)+".Provider";case c:return Je(e,e.render,"ForwardRef");case T:var n=e.displayName||null;return n!==null?n:w(e.type)||"Memo";case R:{var u=e,l=u._payload,i=u._init;try{return w(i(l))}catch{return null}}}return null}var j=Object.assign,$=0,se,fe,le,ce,de,ve,pe;function me(){}me.__reactDisabledLog=!0;function qe(){{if($===0){se=console.log,fe=console.info,le=console.warn,ce=console.error,de=console.group,ve=console.groupCollapsed,pe=console.groupEnd;var e={configurable:!0,enumerable:!0,value:me,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}$++}}function Ke(){{if($--,$===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:j({},e,{value:se}),info:j({},e,{value:fe}),warn:j({},e,{value:le}),error:j({},e,{value:ce}),group:j({},e,{value:de}),groupCollapsed:j({},e,{value:ve}),groupEnd:j({},e,{value:pe})})}$<0&&g("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var K=k.ReactCurrentDispatcher,z;function V(e,r,t){{if(z===void 0)try{throw Error()}catch(u){var n=u.stack.trim().match(/\n( *(at )?)/);z=n&&n[1]||""}return`
`+z+e}}var X=!1,M;{var ze=typeof WeakMap=="function"?WeakMap:Map;M=new ze}function ye(e,r){if(!e||X)return"";{var t=M.get(e);if(t!==void 0)return t}var n;X=!0;var u=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var l;l=K.current,K.current=null,qe();try{if(r){var i=function(){throw Error()};if(Object.defineProperty(i.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(i,[])}catch(E){n=E}Reflect.construct(e,[],i)}else{try{i.call()}catch(E){n=E}e.call(i.prototype)}}else{try{throw Error()}catch(E){n=E}e()}}catch(E){if(E&&n&&typeof E.stack=="string"){for(var a=E.stack.split(`
`),h=n.stack.split(`
`),d=a.length-1,v=h.length-1;d>=1&&v>=0&&a[d]!==h[v];)v--;for(;d>=1&&v>=0;d--,v--)if(a[d]!==h[v]){if(d!==1||v!==1)do if(d--,v--,v<0||a[d]!==h[v]){var S=`
`+a[d].replace(" at new "," at ");return e.displayName&&S.includes("<anonymous>")&&(S=S.replace("<anonymous>",e.displayName)),typeof e=="function"&&M.set(e,S),S}while(d>=1&&v>=0);break}}}finally{X=!1,K.current=l,Ke(),Error.prepareStackTrace=u}var D=e?e.displayName||e.name:"",x=D?V(D):"";return typeof e=="function"&&M.set(e,x),x}function Xe(e,r,t){return ye(e,!1)}function He(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function N(e,r,t){if(e==null)return"";if(typeof e=="function")return ye(e,He(e));if(typeof e=="string")return V(e);switch(e){case _:return V("Suspense");case y:return V("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case c:return Xe(e.render);case T:return N(e.type,r,t);case R:{var n=e,u=n._payload,l=n._init;try{return N(l(u),r,t)}catch{}}}return""}var W=Object.prototype.hasOwnProperty,ge={},be=k.ReactDebugCurrentFrame;function G(e){if(e){var r=e._owner,t=N(e.type,e._source,r?r.type:null);be.setExtraStackFrame(t)}else be.setExtraStackFrame(null)}function Ze(e,r,t,n,u){{var l=Function.call.bind(W);for(var i in e)if(l(e,i)){var a=void 0;try{if(typeof e[i]!="function"){var h=Error((n||"React class")+": "+t+" type `"+i+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[i]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw h.name="Invariant Violation",h}a=e[i](r,i,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(d){a=d}a&&!(a instanceof Error)&&(G(u),g("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",t,i,typeof a),G(null)),a instanceof Error&&!(a.message in ge)&&(ge[a.message]=!0,G(u),g("Failed %s type: %s",t,a.message),G(null))}}}var Qe=Array.isArray;function H(e){return Qe(e)}function er(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function rr(e){try{return he(e),!1}catch{return!0}}function he(e){return""+e}function Ee(e){if(rr(e))return g("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",er(e)),he(e)}var Y=k.ReactCurrentOwner,tr={key:!0,ref:!0,__self:!0,__source:!0},_e,Re,Z;Z={};function nr(e){if(W.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function ar(e){if(W.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function or(e,r){if(typeof e.ref=="string"&&Y.current&&r&&Y.current.stateNode!==r){var t=w(Y.current.type);Z[t]||(g('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',w(Y.current.type),e.ref),Z[t]=!0)}}function ir(e,r){{var t=function(){_e||(_e=!0,g("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}}function ur(e,r){{var t=function(){Re||(Re=!0,g("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}}var sr=function(e,r,t,n,u,l,i){var a={$$typeof:o,type:e,key:r,ref:t,props:i,_owner:l};return a._store={},Object.defineProperty(a._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(a,"_self",{configurable:!1,enumerable:!1,writable:!1,value:n}),Object.defineProperty(a,"_source",{configurable:!1,enumerable:!1,writable:!1,value:u}),Object.freeze&&(Object.freeze(a.props),Object.freeze(a)),a};function fr(e,r,t,n,u){{var l,i={},a=null,h=null;t!==void 0&&(Ee(t),a=""+t),ar(r)&&(Ee(r.key),a=""+r.key),nr(r)&&(h=r.ref,or(r,u));for(l in r)W.call(r,l)&&!tr.hasOwnProperty(l)&&(i[l]=r[l]);if(e&&e.defaultProps){var d=e.defaultProps;for(l in d)i[l]===void 0&&(i[l]=d[l])}if(a||h){var v=typeof e=="function"?e.displayName||e.name||"Unknown":e;a&&ir(i,v),h&&ur(i,v)}return sr(e,a,h,u,n,Y.current,i)}}var Q=k.ReactCurrentOwner,Se=k.ReactDebugCurrentFrame;function F(e){if(e){var r=e._owner,t=N(e.type,e._source,r?r.type:null);Se.setExtraStackFrame(t)}else Se.setExtraStackFrame(null)}var ee;ee=!1;function re(e){return typeof e=="object"&&e!==null&&e.$$typeof===o}function Oe(){{if(Q.current){var e=w(Q.current.type);if(e)return`
Check the render method of \``+e+"`."}return""}}function lr(e){return""}var Te={};function cr(e){{var r=Oe();if(!r){var t=typeof e=="string"?e:e.displayName||e.name;t&&(r=`
Check the top-level render call using <`+t+">.")}return r}}function we(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=cr(r);if(Te[t])return;Te[t]=!0;var n="";e&&e._owner&&e._owner!==Q.current&&(n=" It was passed a child from "+w(e._owner.type)+"."),F(e),g('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),F(null)}}function Ce(e,r){{if(typeof e!="object")return;if(H(e))for(var t=0;t<e.length;t++){var n=e[t];re(n)&&we(n,r)}else if(re(e))e._store&&(e._store.validated=!0);else if(e){var u=We(e);if(typeof u=="function"&&u!==e.entries)for(var l=u.call(e),i;!(i=l.next()).done;)re(i.value)&&we(i.value,r)}}}function dr(e){{var r=e.type;if(r==null||typeof r=="string")return;var t;if(typeof r=="function")t=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===c||r.$$typeof===T))t=r.propTypes;else return;if(t){var n=w(r);Ze(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!ee){ee=!0;var u=w(r);g("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",u||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&g("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function vr(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if(n!=="children"&&n!=="key"){F(e),g("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),F(null);break}}e.ref!==null&&(F(e),g("Invalid attribute `ref` supplied to `React.Fragment`."),F(null))}}var Pe={};function je(e,r,t,n,u,l){{var i=Be(e);if(!i){var a="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(a+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var h=lr();h?a+=h:a+=Oe();var d;e===null?d="null":H(e)?d="array":e!==void 0&&e.$$typeof===o?(d="<"+(w(e.type)||"Unknown")+" />",a=" Did you accidentally export a JSX literal instead of a component?"):d=typeof e,g("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",d,a)}var v=fr(e,r,t,u,l);if(v==null)return v;if(i){var S=r.children;if(S!==void 0)if(n)if(H(S)){for(var D=0;D<S.length;D++)Ce(S[D],e);Object.freeze&&Object.freeze(S)}else g("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Ce(S,e)}if(W.call(r,"key")){var x=w(e),E=Object.keys(r).filter(function(hr){return hr!=="key"}),te=E.length>0?"{key: someKey, "+E.join(": ..., ")+": ...}":"{key: someKey}";if(!Pe[x+te]){var br=E.length>0?"{"+E.join(": ..., ")+": ...}":"{}";g(`A props object containing a "key" prop is being spread into JSX:
let props = %s;
<%s {...props} />
React keys must be passed directly to JSX without using spread:
let props = %s;
<%s key={someKey} {...props} />`,te,x,br,x),Pe[x+te]=!0}}return e===b?vr(v):dr(v),v}}function pr(e,r,t){return je(e,r,t,!0)}function mr(e,r,t){return je(e,r,t,!1)}var yr=mr,gr=pr;L.Fragment=b,L.jsx=yr,L.jsxs=gr}()),L}process.env.NODE_ENV==="production"?J.exports=xe():J.exports=ke();var Fe=J.exports;const De="https://cdn.customgform.com/cgf.js",q={};function Ae(s){const o=document.querySelector(`script[src="${s}"]`),p=o==null?void 0:o.getAttribute("data-status");return{node:o,status:p}}function Ie(s,o){const[p,b]=B.useState(()=>!s||o!=null&&o.shouldPreventLoad?"idle":typeof window>"u"?"loading":q[s]??"loading");return B.useEffect(()=>{if(!s||o!=null&&o.shouldPreventLoad)return;const O=q[s];if(O==="ready"||O==="error"){b(O);return}const C=Ae(s);let f=C.node;if(f)b(C.status??O??"loading");else{f=document.createElement("script"),f.src=s,f.async=!0,f.setAttribute("data-status","loading"),document.body.appendChild(f);const c=_=>{const y=_.type==="load"?"ready":"error";f==null||f.setAttribute("data-status",y)};f.addEventListener("load",c),f.addEventListener("error",c)}const m=c=>{const _=c.type==="load"?"ready":"error";b(_),q[s]=_};return f.addEventListener("load",m),f.addEventListener("error",m),()=>{f&&(f.removeEventListener("load",m),f.removeEventListener("error",m)),f&&(o!=null&&o.removeOnUnmount)&&f.remove()}},[s,o==null?void 0:o.shouldPreventLoad,o==null?void 0:o.removeOnUnmount]),p}function Le(s){const o=[];if(!s)return"";for(const p in s)s.hasOwnProperty(p)&&o.push(`${p}=${s[p]}`);return o.join(";")}return s=>{const{formId:o,mode:p="standard",label:b="",inlineStyles:O="",buttonClassName:C="",prefillFields:f=null,hiddenFields:m=null,__formConfig:c=null,__cdnUrl:_,...y}=s,T=Ie(_??De,{removeOnUnmount:!1}),R=p==="popup"?{"data-mode":p,"data-label":b,"data-style":O,"data-button_class":C}:{};try{c&&(R["data-customgform-config"]=JSON.stringify(c))}catch{}return f&&(R["data-prefill_fields"]=Le(f)),m&&(R["data-hidden_fields"]=m==null?void 0:m.join(";")),B.useEffect(()=>{typeof window.CustomGForm<"u"&&(window.CustomGForm.destroy(),window.CustomGForm.render())},[T]),Fe.jsx("div",{"data-customgform":o,...R,...y})}});