UNPKG

@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/)

711 lines (708 loc) 23.9 kB
import * as Q from "react"; import Pe from "react"; var ee = { exports: {} }, L = {}; /** * @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 we; function dr() { if (we) return L; we = 1; var v = Pe, i = Symbol.for("react.element"), h = Symbol.for("react.fragment"), _ = Object.prototype.hasOwnProperty, S = v.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, O = { key: !0, ref: !0, __self: !0, __source: !0 }; function s(y, l, b) { var p, w = {}, C = null, W = null; b !== void 0 && (C = "" + b), l.key !== void 0 && (C = "" + l.key), l.ref !== void 0 && (W = l.ref); for (p in l) _.call(l, p) && !O.hasOwnProperty(p) && (w[p] = l[p]); if (y && y.defaultProps) for (p in l = y.defaultProps, l) w[p] === void 0 && (w[p] = l[p]); return { $$typeof: i, type: y, key: C, ref: W, props: w, _owner: S.current }; } return L.Fragment = h, L.jsx = s, L.jsxs = s, L; } var $ = {}; /** * @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 Ce; function vr() { return Ce || (Ce = 1, process.env.NODE_ENV !== "production" && function() { var v = Pe, i = Symbol.for("react.element"), h = Symbol.for("react.portal"), _ = Symbol.for("react.fragment"), S = Symbol.for("react.strict_mode"), O = Symbol.for("react.profiler"), s = Symbol.for("react.provider"), y = Symbol.for("react.context"), l = Symbol.for("react.forward_ref"), b = Symbol.for("react.suspense"), p = Symbol.for("react.suspense_list"), w = Symbol.for("react.memo"), C = Symbol.for("react.lazy"), W = Symbol.for("react.offscreen"), re = Symbol.iterator, je = "@@iterator"; function xe(e) { if (e === null || typeof e != "object") return null; var r = re && e[re] || e[je]; return typeof r == "function" ? r : null; } var x = v.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; function m(e) { { for (var r = arguments.length, t = new Array(r > 1 ? r - 1 : 0), n = 1; n < r; n++) t[n - 1] = arguments[n]; ke("error", e, t); } } function ke(e, r, t) { { var n = x.ReactDebugCurrentFrame, u = n.getStackAddendum(); u !== "" && (r += "%s", t = t.concat([u])); var f = t.map(function(o) { return String(o); }); f.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, f); } } var Fe = !1, Ae = !1, De = !1, Ie = !1, Le = !1, te; te = Symbol.for("react.module.reference"); function $e(e) { return !!(typeof e == "string" || typeof e == "function" || e === _ || e === O || Le || e === S || e === b || e === p || Ie || e === W || Fe || Ae || De || typeof e == "object" && e !== null && (e.$$typeof === C || e.$$typeof === w || e.$$typeof === s || e.$$typeof === y || e.$$typeof === l || // This needs to include all possible module reference object // types supported by any Flight configuration anywhere since // we don't know which Flight build this will end up being used // with. e.$$typeof === te || e.getModuleId !== void 0)); } function We(e, r, t) { var n = e.displayName; if (n) return n; var u = r.displayName || r.name || ""; return u !== "" ? t + "(" + u + ")" : t; } function ne(e) { return e.displayName || "Context"; } function T(e) { if (e == null) return null; if (typeof e.tag == "number" && m("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 _: return "Fragment"; case h: return "Portal"; case O: return "Profiler"; case S: return "StrictMode"; case b: return "Suspense"; case p: return "SuspenseList"; } if (typeof e == "object") switch (e.$$typeof) { case y: var r = e; return ne(r) + ".Consumer"; case s: var t = e; return ne(t._context) + ".Provider"; case l: return We(e, e.render, "ForwardRef"); case w: var n = e.displayName || null; return n !== null ? n : T(e.type) || "Memo"; case C: { var u = e, f = u._payload, o = u._init; try { return T(o(f)); } catch { return null; } } } return null; } var P = Object.assign, A = 0, ae, oe, ie, ue, se, fe, le; function ce() { } ce.__reactDisabledLog = !0; function Ye() { { if (A === 0) { ae = console.log, oe = console.info, ie = console.warn, ue = console.error, se = console.group, fe = console.groupCollapsed, le = console.groupEnd; var e = { configurable: !0, enumerable: !0, value: ce, writable: !0 }; Object.defineProperties(console, { info: e, log: e, warn: e, error: e, group: e, groupCollapsed: e, groupEnd: e }); } A++; } } function Ue() { { if (A--, A === 0) { var e = { configurable: !0, enumerable: !0, writable: !0 }; Object.defineProperties(console, { log: P({}, e, { value: ae }), info: P({}, e, { value: oe }), warn: P({}, e, { value: ie }), error: P({}, e, { value: ue }), group: P({}, e, { value: se }), groupCollapsed: P({}, e, { value: fe }), groupEnd: P({}, e, { value: le }) }); } A < 0 && m("disabledDepth fell below zero. This is a bug in React. Please file an issue."); } } var N = x.ReactCurrentDispatcher, B; function Y(e, r, t) { { if (B === void 0) try { throw Error(); } catch (u) { var n = u.stack.trim().match(/\n( *(at )?)/); B = n && n[1] || ""; } return ` ` + B + e; } } var G = !1, U; { var Ve = typeof WeakMap == "function" ? WeakMap : Map; U = new Ve(); } function de(e, r) { if (!e || G) return ""; { var t = U.get(e); if (t !== void 0) return t; } var n; G = !0; var u = Error.prepareStackTrace; Error.prepareStackTrace = void 0; var f; f = N.current, N.current = null, Ye(); try { if (r) { var o = function() { throw Error(); }; if (Object.defineProperty(o.prototype, "props", { set: function() { throw Error(); } }), typeof Reflect == "object" && Reflect.construct) { try { Reflect.construct(o, []); } catch (E) { n = E; } Reflect.construct(e, [], o); } else { try { o.call(); } catch (E) { n = E; } e.call(o.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(` `), g = n.stack.split(` `), c = a.length - 1, d = g.length - 1; c >= 1 && d >= 0 && a[c] !== g[d]; ) d--; for (; c >= 1 && d >= 0; c--, d--) if (a[c] !== g[d]) { if (c !== 1 || d !== 1) do if (c--, d--, d < 0 || a[c] !== g[d]) { var R = ` ` + a[c].replace(" at new ", " at "); return e.displayName && R.includes("<anonymous>") && (R = R.replace("<anonymous>", e.displayName)), typeof e == "function" && U.set(e, R), R; } while (c >= 1 && d >= 0); break; } } } finally { G = !1, N.current = f, Ue(), Error.prepareStackTrace = u; } var F = e ? e.displayName || e.name : "", j = F ? Y(F) : ""; return typeof e == "function" && U.set(e, j), j; } function Me(e, r, t) { return de(e, !1); } function Ne(e) { var r = e.prototype; return !!(r && r.isReactComponent); } function V(e, r, t) { if (e == null) return ""; if (typeof e == "function") return de(e, Ne(e)); if (typeof e == "string") return Y(e); switch (e) { case b: return Y("Suspense"); case p: return Y("SuspenseList"); } if (typeof e == "object") switch (e.$$typeof) { case l: return Me(e.render); case w: return V(e.type, r, t); case C: { var n = e, u = n._payload, f = n._init; try { return V(f(u), r, t); } catch { } } } return ""; } var D = Object.prototype.hasOwnProperty, ve = {}, pe = x.ReactDebugCurrentFrame; function M(e) { if (e) { var r = e._owner, t = V(e.type, e._source, r ? r.type : null); pe.setExtraStackFrame(t); } else pe.setExtraStackFrame(null); } function Be(e, r, t, n, u) { { var f = Function.call.bind(D); for (var o in e) if (f(e, o)) { var a = void 0; try { if (typeof e[o] != "function") { var g = Error((n || "React class") + ": " + t + " type `" + o + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[o] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`."); throw g.name = "Invariant Violation", g; } a = e[o](r, o, n, t, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"); } catch (c) { a = c; } a && !(a instanceof Error) && (M(u), m("%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, o, typeof a), M(null)), a instanceof Error && !(a.message in ve) && (ve[a.message] = !0, M(u), m("Failed %s type: %s", t, a.message), M(null)); } } } var Ge = Array.isArray; function J(e) { return Ge(e); } function Je(e) { { var r = typeof Symbol == "function" && Symbol.toStringTag, t = r && e[Symbol.toStringTag] || e.constructor.name || "Object"; return t; } } function qe(e) { try { return me(e), !1; } catch { return !0; } } function me(e) { return "" + e; } function ye(e) { if (qe(e)) return m("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", Je(e)), me(e); } var I = x.ReactCurrentOwner, Ke = { key: !0, ref: !0, __self: !0, __source: !0 }, ge, he, q; q = {}; function ze(e) { if (D.call(e, "ref")) { var r = Object.getOwnPropertyDescriptor(e, "ref").get; if (r && r.isReactWarning) return !1; } return e.ref !== void 0; } function Xe(e) { if (D.call(e, "key")) { var r = Object.getOwnPropertyDescriptor(e, "key").get; if (r && r.isReactWarning) return !1; } return e.key !== void 0; } function He(e, r) { if (typeof e.ref == "string" && I.current && r && I.current.stateNode !== r) { var t = T(I.current.type); q[t] || (m('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', T(I.current.type), e.ref), q[t] = !0); } } function Ze(e, r) { { var t = function() { ge || (ge = !0, m("%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 Qe(e, r) { { var t = function() { he || (he = !0, m("%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 er = function(e, r, t, n, u, f, o) { var a = { // This tag allows us to uniquely identify this as a React Element $$typeof: i, // Built-in properties that belong on the element type: e, key: r, ref: t, props: o, // Record the component responsible for creating this element. _owner: f }; 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 rr(e, r, t, n, u) { { var f, o = {}, a = null, g = null; t !== void 0 && (ye(t), a = "" + t), Xe(r) && (ye(r.key), a = "" + r.key), ze(r) && (g = r.ref, He(r, u)); for (f in r) D.call(r, f) && !Ke.hasOwnProperty(f) && (o[f] = r[f]); if (e && e.defaultProps) { var c = e.defaultProps; for (f in c) o[f] === void 0 && (o[f] = c[f]); } if (a || g) { var d = typeof e == "function" ? e.displayName || e.name || "Unknown" : e; a && Ze(o, d), g && Qe(o, d); } return er(e, a, g, u, n, I.current, o); } } var K = x.ReactCurrentOwner, Ee = x.ReactDebugCurrentFrame; function k(e) { if (e) { var r = e._owner, t = V(e.type, e._source, r ? r.type : null); Ee.setExtraStackFrame(t); } else Ee.setExtraStackFrame(null); } var z; z = !1; function X(e) { return typeof e == "object" && e !== null && e.$$typeof === i; } function be() { { if (K.current) { var e = T(K.current.type); if (e) return ` Check the render method of \`` + e + "`."; } return ""; } } function tr(e) { return ""; } var _e = {}; function nr(e) { { var r = be(); 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 Re(e, r) { { if (!e._store || e._store.validated || e.key != null) return; e._store.validated = !0; var t = nr(r); if (_e[t]) return; _e[t] = !0; var n = ""; e && e._owner && e._owner !== K.current && (n = " It was passed a child from " + T(e._owner.type) + "."), k(e), m('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), k(null); } } function Se(e, r) { { if (typeof e != "object") return; if (J(e)) for (var t = 0; t < e.length; t++) { var n = e[t]; X(n) && Re(n, r); } else if (X(e)) e._store && (e._store.validated = !0); else if (e) { var u = xe(e); if (typeof u == "function" && u !== e.entries) for (var f = u.call(e), o; !(o = f.next()).done; ) X(o.value) && Re(o.value, r); } } } function ar(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 === l || // Note: Memo only checks outer props here. // Inner props are checked in the reconciler. r.$$typeof === w)) t = r.propTypes; else return; if (t) { var n = T(r); Be(t, e.props, "prop", n, e); } else if (r.PropTypes !== void 0 && !z) { z = !0; var u = T(r); m("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", u || "Unknown"); } typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && m("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead."); } } function or(e) { { for (var r = Object.keys(e.props), t = 0; t < r.length; t++) { var n = r[t]; if (n !== "children" && n !== "key") { k(e), m("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", n), k(null); break; } } e.ref !== null && (k(e), m("Invalid attribute `ref` supplied to `React.Fragment`."), k(null)); } } var Te = {}; function Oe(e, r, t, n, u, f) { { var o = $e(e); if (!o) { 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 g = tr(); g ? a += g : a += be(); var c; e === null ? c = "null" : J(e) ? c = "array" : e !== void 0 && e.$$typeof === i ? (c = "<" + (T(e.type) || "Unknown") + " />", a = " Did you accidentally export a JSX literal instead of a component?") : c = typeof e, m("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", c, a); } var d = rr(e, r, t, u, f); if (d == null) return d; if (o) { var R = r.children; if (R !== void 0) if (n) if (J(R)) { for (var F = 0; F < R.length; F++) Se(R[F], e); Object.freeze && Object.freeze(R); } else m("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 Se(R, e); } if (D.call(r, "key")) { var j = T(e), E = Object.keys(r).filter(function(cr) { return cr !== "key"; }), H = E.length > 0 ? "{key: someKey, " + E.join(": ..., ") + ": ...}" : "{key: someKey}"; if (!Te[j + H]) { var lr = E.length > 0 ? "{" + E.join(": ..., ") + ": ...}" : "{}"; m(`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} />`, H, j, lr, j), Te[j + H] = !0; } } return e === _ ? or(d) : ar(d), d; } } function ir(e, r, t) { return Oe(e, r, t, !0); } function ur(e, r, t) { return Oe(e, r, t, !1); } var sr = ur, fr = ir; $.Fragment = _, $.jsx = sr, $.jsxs = fr; }()), $; } process.env.NODE_ENV === "production" ? ee.exports = dr() : ee.exports = vr(); var pr = ee.exports; const mr = "https://cdn.customgform.com/cgf.js", Z = {}; function yr(v) { const i = document.querySelector( `script[src="${v}"]` ), h = i == null ? void 0 : i.getAttribute("data-status"); return { node: i, status: h }; } function gr(v, i) { const [h, _] = Q.useState(() => i != null && i.shouldPreventLoad ? "idle" : typeof window > "u" ? "loading" : Z[v] ?? "loading"); return Q.useEffect(() => { if (i != null && i.shouldPreventLoad) return; const S = Z[v]; if (S === "ready" || S === "error") { _(S); return; } const O = yr(v); let s = O.node; if (s) _(O.status ?? S ?? "loading"); else { s = document.createElement("script"), s.src = v, s.async = !0, s.setAttribute("data-status", "loading"), document.body.appendChild(s); const l = (b) => { const p = b.type === "load" ? "ready" : "error"; s == null || s.setAttribute("data-status", p); }; s.addEventListener("load", l), s.addEventListener("error", l); } const y = (l) => { const b = l.type === "load" ? "ready" : "error"; _(b), Z[v] = b; }; return s.addEventListener("load", y), s.addEventListener("error", y), () => { s && (s.removeEventListener("load", y), s.removeEventListener("error", y)), s && (i != null && i.removeOnUnmount) && s.remove(); }; }, [v, i == null ? void 0 : i.shouldPreventLoad, i == null ? void 0 : i.removeOnUnmount]), h; } function hr(v) { const i = []; if (!v) return ""; for (const h in v) v.hasOwnProperty(h) && i.push(`${h}=${v[h]}`); return i.join(";"); } const br = (v) => { const { formId: i, mode: h = "standard", label: _ = "", inlineStyles: S = "", buttonClassName: O = "", prefillFields: s = null, __formConfig: y = null, ...l } = v, b = gr(mr, { removeOnUnmount: !1 }), p = h === "popup" ? { "data-mode": h, "data-label": _, "data-style": S, "data-button_class": O } : {}; try { y && (p["data-customgform-config"] = JSON.stringify(y)); } catch { } return s && (p["data-prefill_fields"] = hr(s)), Q.useEffect(() => { typeof window.CustomGForm < "u" && (window.CustomGForm.destroy(), window.CustomGForm.render()); }, [b]), /* @__PURE__ */ pr.jsx("div", { "data-customgform": i, ...p, ...l }); }; export { br as default };