@embeddable/sdk 1.0.10 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/EmbeddableProvider-74nyeXDc.cjs +10 -0
- package/dist/{useVoteAggregations-c6kqMEXe.js → EmbeddableProvider-OdbqzsmX.js} +272 -54
- package/dist/context/EmbeddableProvider.d.ts.map +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/useEventTracking.d.ts +43 -0
- package/dist/hooks/useEventTracking.d.ts.map +1 -0
- package/dist/hooks.cjs +1 -1
- package/dist/hooks.js +6 -5
- package/dist/index.cjs +1 -1
- package/dist/index.js +6 -5
- package/package.json +1 -1
- package/dist/useVoteAggregations-sKR_hMwZ.cjs +0 -10
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";const e=require("react"),t=require("./storage-EjA7Lhbb.cjs");var r,n={exports:{}},o={};var a,s={};
|
|
2
|
+
/**
|
|
3
|
+
* @license React
|
|
4
|
+
* react-jsx-runtime.development.js
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
7
|
+
*
|
|
8
|
+
* This source code is licensed under the MIT license found in the
|
|
9
|
+
* LICENSE file in the root directory of this source tree.
|
|
10
|
+
*/"production"===process.env.NODE_ENV?n.exports=function(){if(r)return o;r=1;var t=e,n=Symbol.for("react.element"),a=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,c=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};function u(e,t,r){var o,a={},u=null,l=null;for(o in void 0!==r&&(u=""+r),void 0!==t.key&&(u=""+t.key),void 0!==t.ref&&(l=t.ref),t)s.call(t,o)&&!i.hasOwnProperty(o)&&(a[o]=t[o]);if(e&&e.defaultProps)for(o in t=e.defaultProps)void 0===a[o]&&(a[o]=t[o]);return{$$typeof:n,type:e,key:u,ref:l,props:a,_owner:c.current}}return o.Fragment=a,o.jsx=u,o.jsxs=u,o}():n.exports=(a||(a=1,"production"!==process.env.NODE_ENV&&function(){var t,r=e,n=Symbol.for("react.element"),o=Symbol.for("react.portal"),a=Symbol.for("react.fragment"),c=Symbol.for("react.strict_mode"),i=Symbol.for("react.profiler"),u=Symbol.for("react.provider"),l=Symbol.for("react.context"),f=Symbol.for("react.forward_ref"),d=Symbol.for("react.suspense"),p=Symbol.for("react.suspense_list"),y=Symbol.for("react.memo"),m=Symbol.for("react.lazy"),g=Symbol.for("react.offscreen"),v=Symbol.iterator,b=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function h(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];!function(e,t,r){var n=b.ReactDebugCurrentFrame.getStackAddendum();""!==n&&(t+="%s",r=r.concat([n]));var o=r.map((function(e){return String(e)}));o.unshift("Warning: "+t),Function.prototype.apply.call(console[e],console,o)}("error",e,r)}function w(e){return e.displayName||"Context"}function _(e){if(null==e)return null;if("number"==typeof e.tag&&h("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),"function"==typeof e)return e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case a:return"Fragment";case o:return"Portal";case i:return"Profiler";case c:return"StrictMode";case d:return"Suspense";case p:return"SuspenseList"}if("object"==typeof e)switch(e.$$typeof){case l:return w(e)+".Consumer";case u:return w(e._context)+".Provider";case f:return function(e,t,r){var n=e.displayName;if(n)return n;var o=t.displayName||t.name||"";return""!==o?r+"("+o+")":r}(e,e.render,"ForwardRef");case y:var t=e.displayName||null;return null!==t?t:_(e.type)||"Memo";case m:var r=e,n=r._payload,s=r._init;try{return _(s(n))}catch(g){return null}}return null}t=Symbol.for("react.module.reference");var k,S,E,O,j,C,T,P=Object.assign,x=0;function R(){}R.__reactDisabledLog=!0;var I,$=b.ReactCurrentDispatcher;function N(e,t,r){if(void 0===I)try{throw Error()}catch(o){var n=o.stack.trim().match(/\n( *(at )?)/);I=n&&n[1]||""}return"\n"+I+e}var D,F=!1,L="function"==typeof WeakMap?WeakMap:Map;function A(e,t){if(!e||F)return"";var r,n=D.get(e);if(void 0!==n)return n;F=!0;var o,a=Error.prepareStackTrace;Error.prepareStackTrace=void 0,o=$.current,$.current=null,function(){if(0===x){k=console.log,S=console.info,E=console.warn,O=console.error,j=console.group,C=console.groupCollapsed,T=console.groupEnd;var e={configurable:!0,enumerable:!0,value:R,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}x++}();try{if(t){var s=function(){throw Error()};if(Object.defineProperty(s.prototype,"props",{set:function(){throw Error()}}),"object"==typeof Reflect&&Reflect.construct){try{Reflect.construct(s,[])}catch(y){r=y}Reflect.construct(e,[],s)}else{try{s.call()}catch(y){r=y}e.call(s.prototype)}}else{try{throw Error()}catch(y){r=y}e()}}catch(m){if(m&&r&&"string"==typeof m.stack){for(var c=m.stack.split("\n"),i=r.stack.split("\n"),u=c.length-1,l=i.length-1;u>=1&&l>=0&&c[u]!==i[l];)l--;for(;u>=1&&l>=0;u--,l--)if(c[u]!==i[l]){if(1!==u||1!==l)do{if(u--,--l<0||c[u]!==i[l]){var f="\n"+c[u].replace(" at new "," at ");return e.displayName&&f.includes("<anonymous>")&&(f=f.replace("<anonymous>",e.displayName)),"function"==typeof e&&D.set(e,f),f}}while(u>=1&&l>=0);break}}}finally{F=!1,$.current=o,function(){if(0===--x){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:P({},e,{value:k}),info:P({},e,{value:S}),warn:P({},e,{value:E}),error:P({},e,{value:O}),group:P({},e,{value:j}),groupCollapsed:P({},e,{value:C}),groupEnd:P({},e,{value:T})})}x<0&&h("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}(),Error.prepareStackTrace=a}var d=e?e.displayName||e.name:"",p=d?N(d):"";return"function"==typeof e&&D.set(e,p),p}function U(e,t,r){if(null==e)return"";if("function"==typeof e)return A(e,!(!(n=e.prototype)||!n.isReactComponent));var n;if("string"==typeof e)return N(e);switch(e){case d:return N("Suspense");case p:return N("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case f:return A(e.render,!1);case y:return U(e.type,t,r);case m:var o=e,a=o._payload,s=o._init;try{return U(s(a),t,r)}catch(c){}}return""}D=new L;var V=Object.prototype.hasOwnProperty,W={},z=b.ReactDebugCurrentFrame;function J(e){if(e){var t=e._owner,r=U(e.type,e._source,t?t.type:null);z.setExtraStackFrame(r)}else z.setExtraStackFrame(null)}var K=Array.isArray;function M(e){return K(e)}function B(e){return""+e}function Y(e){if(function(e){try{return B(e),!1}catch(t){return!0}}(e))return h("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",function(e){return"function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object"}(e)),B(e)}var q,H,X=b.ReactCurrentOwner,G={key:!0,ref:!0,__self:!0,__source:!0};function Q(e,t,r,o,a){var s,c={},i=null,u=null;for(s in void 0!==r&&(Y(r),i=""+r),function(e){if(V.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(t)&&(Y(t.key),i=""+t.key),function(e){if(V.call(e,"ref")){var t=Object.getOwnPropertyDescriptor(e,"ref").get;if(t&&t.isReactWarning)return!1}return void 0!==e.ref}(t)&&(u=t.ref,function(e){"string"==typeof e.ref&&X.current}(t)),t)V.call(t,s)&&!G.hasOwnProperty(s)&&(c[s]=t[s]);if(e&&e.defaultProps){var l=e.defaultProps;for(s in l)void 0===c[s]&&(c[s]=l[s])}if(i||u){var f="function"==typeof e?e.displayName||e.name||"Unknown":e;i&&function(e,t){var r=function(){q||(q=!0,h("%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)",t))};r.isReactWarning=!0,Object.defineProperty(e,"key",{get:r,configurable:!0})}(c,f),u&&function(e,t){var r=function(){H||(H=!0,h("%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)",t))};r.isReactWarning=!0,Object.defineProperty(e,"ref",{get:r,configurable:!0})}(c,f)}return function(e,t,r,o,a,s,c){var i={$$typeof:n,type:e,key:t,ref:r,props:c,_owner:s,_store:{}};return Object.defineProperty(i._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(i,"_self",{configurable:!1,enumerable:!1,writable:!1,value:o}),Object.defineProperty(i,"_source",{configurable:!1,enumerable:!1,writable:!1,value:a}),Object.freeze&&(Object.freeze(i.props),Object.freeze(i)),i}(e,i,u,a,o,X.current,c)}var Z,ee=b.ReactCurrentOwner,te=b.ReactDebugCurrentFrame;function re(e){if(e){var t=e._owner,r=U(e.type,e._source,t?t.type:null);te.setExtraStackFrame(r)}else te.setExtraStackFrame(null)}function ne(e){return"object"==typeof e&&null!==e&&e.$$typeof===n}function oe(){if(ee.current){var e=_(ee.current.type);if(e)return"\n\nCheck the render method of `"+e+"`."}return""}Z=!1;var ae={};function se(e,t){if(e._store&&!e._store.validated&&null==e.key){e._store.validated=!0;var r=function(e){var t=oe();if(!t){var r="string"==typeof e?e:e.displayName||e.name;r&&(t="\n\nCheck the top-level render call using <"+r+">.")}return t}(t);if(!ae[r]){ae[r]=!0;var n="";e&&e._owner&&e._owner!==ee.current&&(n=" It was passed a child from "+_(e._owner.type)+"."),re(e),h('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',r,n),re(null)}}}function ce(e,t){if("object"==typeof e)if(M(e))for(var r=0;r<e.length;r++){var n=e[r];ne(n)&&se(n,t)}else if(ne(e))e._store&&(e._store.validated=!0);else if(e){var o=function(e){if(null===e||"object"!=typeof e)return null;var t=v&&e[v]||e["@@iterator"];return"function"==typeof t?t:null}(e);if("function"==typeof o&&o!==e.entries)for(var a,s=o.call(e);!(a=s.next()).done;)ne(a.value)&&se(a.value,t)}}function ie(e){var t,r=e.type;if(null!=r&&"string"!=typeof r){if("function"==typeof r)t=r.propTypes;else{if("object"!=typeof r||r.$$typeof!==f&&r.$$typeof!==y)return;t=r.propTypes}if(t){var n=_(r);!function(e,t,r,n,o){var a=Function.call.bind(V);for(var s in e)if(a(e,s)){var c=void 0;try{if("function"!=typeof e[s]){var i=Error((n||"React class")+": "+r+" type `"+s+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[s]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw i.name="Invariant Violation",i}c=e[s](t,s,n,r,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(u){c=u}!c||c instanceof Error||(J(o),h("%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",r,s,typeof c),J(null)),c instanceof Error&&!(c.message in W)&&(W[c.message]=!0,J(o),h("Failed %s type: %s",r,c.message),J(null))}}(t,e.props,"prop",n,e)}else void 0===r.PropTypes||Z||(Z=!0,h("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",_(r)||"Unknown"));"function"!=typeof r.getDefaultProps||r.getDefaultProps.isReactClassApproved||h("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}var ue={};function le(e,r,o,s,v,b){var w=function(e){return"string"==typeof e||"function"==typeof e||e===a||e===i||e===c||e===d||e===p||e===g||"object"==typeof e&&null!==e&&(e.$$typeof===m||e.$$typeof===y||e.$$typeof===u||e.$$typeof===l||e.$$typeof===f||e.$$typeof===t||void 0!==e.getModuleId)}(e);if(!w){var k,S="";(void 0===e||"object"==typeof e&&null!==e&&0===Object.keys(e).length)&&(S+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports."),S+=oe(),null===e?k="null":M(e)?k="array":void 0!==e&&e.$$typeof===n?(k="<"+(_(e.type)||"Unknown")+" />",S=" Did you accidentally export a JSX literal instead of a component?"):k=typeof e,h("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",k,S)}var E=Q(e,r,o,v,b);if(null==E)return E;if(w){var O=r.children;if(void 0!==O)if(s)if(M(O)){for(var j=0;j<O.length;j++)ce(O[j],e);Object.freeze&&Object.freeze(O)}else h("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(O,e)}if(V.call(r,"key")){var C=_(e),T=Object.keys(r).filter((function(e){return"key"!==e})),P=T.length>0?"{key: someKey, "+T.join(": ..., ")+": ...}":"{key: someKey}";ue[C+P]||(h('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',P,C,T.length>0?"{"+T.join(": ..., ")+": ...}":"{}",C),ue[C+P]=!0)}return e===a?function(e){for(var t=Object.keys(e.props),r=0;r<t.length;r++){var n=t[r];if("children"!==n&&"key"!==n){re(e),h("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),re(null);break}}null!==e.ref&&(re(e),h("Invalid attribute `ref` supplied to `React.Fragment`."),re(null))}(E):ie(E),E}var fe=function(e,t,r){return le(e,t,r,!1)},de=function(e,t,r){return le(e,t,r,!0)};s.Fragment=a,s.jsx=fe,s.jsxs=de}()),s);var c=n.exports;const i="https://events.embeddable.co";function u(){const{config:e}=p();if(!e)throw new Error("No Embeddable configuration found. Make sure to wrap your app with EmbeddableProvider and provide a valid config.");return e}const l=()=>{const{widgetId:t}=u(),r=`${i}/api`,[n,o]=e.useState(!1),a=e.useCallback((async(e,n={})=>{const a=[];try{o(!0);const s=await fetch(`${r}/marketing/track`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify({widgetId:t,inputs:e,integrationKey:n.integrationKey})}),c=await s.json();c.success?c.results?c.results.forEach((e=>{a.push({success:e.success,integrationKey:e.integrationKey,data:e.data,error:e.error})})):a.push({success:!0,data:c.data}):a.push({success:!1,error:c.error||"Unknown error"})}catch(s){a.push({success:!1,error:s instanceof Error?s.message:"Network error"})}finally{o(!1)}return a}),[t,r]),s=e.useCallback((async(e={})=>a({event_name:"page_view",event_category:"engagement",custom_parameters:{page_url:window.location.href,page_title:document.title,referrer:document.referrer,...e}})),[a]),c=e.useCallback((async(e,t={})=>a({event_name:"form_submit",event_category:"conversion",custom_parameters:{form_data:e,...t}})),[a]),l=e.useCallback((async(e,t={})=>{let r={};return r="string"==typeof e?{element_selector:e}:{element_id:e.id,element_class:e.className,element_text:e.textContent||e.innerText,element_tag:e.tagName.toLowerCase()},a({event_name:"button_click",event_category:"interaction",custom_parameters:{...r,...t}})}),[a]),f=e.useCallback((async(e,t,r={})=>a({event_name:"conversion",event_category:"conversion",value:t,custom_parameters:{conversion_type:e,currency:r.currency||"USD",...r}})),[a]),d=e.useCallback((async(e,t={})=>a({event_name:"signup",event_category:"conversion",user_data:e,custom_parameters:t})),[a]),p=e.useCallback((async(e,t={})=>a({event_name:"purchase",event_category:"ecommerce",value:e.amount,custom_parameters:{transaction_id:e.id,currency:e.currency||"USD",items:e.items||[],...t}})),[a]),y=e.useCallback((()=>{s()}),[s]),m=e.useCallback((()=>{const e=async e=>{try{const t=e.target,r=new FormData(t),n=Object.fromEntries(r.entries());await c(n,{form_id:t.id,form_class:t.className,form_action:t.action,form_method:t.method})}catch(t){}};return document.addEventListener("submit",e),()=>{document.removeEventListener("submit",e)}}),[c]),g=e.useCallback(((e='button, .btn, [role="button"], a, input[type="submit"]')=>{const t=async t=>{const r=t.target.closest(e);if(r)try{await l(r)}catch(n){}};return document.addEventListener("click",t),()=>{document.removeEventListener("click",t)}}),[l]);return{isLoading:n,track:a,trackPageView:s,trackFormSubmit:c,trackClick:l,trackConversion:f,trackSignup:d,trackPurchase:p,enableAutoPageView:y,enableAutoFormTracking:m,enableAutoClickTracking:g}};const f={version:"latest",mode:"embeddable",ignoreCache:!1,lazyLoad:!1,loader:!0,widgetId:"",_containerId:"",_shadowRoot:void 0},d=e.createContext({config:{...f},setConfig:()=>{},data:{},setData:()=>{}});function p(){const t=e.useContext(d);if(!t)throw new Error("useEmbeddableContext must be used within an EmbeddableProvider");return t}exports.EmbeddableProvider=function({config:t,data:r,children:n}){const[o,a]=e.useState(f),[s,i]=e.useState(r||{}),{enableAutoPageView:u}=l();return e.useEffect((()=>{a({...f,...t})}),[t]),e.useEffect((()=>{o.widgetId&&"preview"!==o.mode&&u()}),[u,o.widgetId,o.mode]),e.useEffect((()=>{const e=e=>{("https://embeddable.co"===e.origin||e.origin.includes("localhost"))&&e.data&&"object"==typeof e.data&&"embeddable-update-data"===e.data.type&&i(e.data.data||{})};return window.addEventListener("message",e),()=>{window.removeEventListener("message",e)}}),[]),c.jsx(d.Provider,{value:{config:o,setConfig:a,data:s,setData:i},children:n})},exports.useAI=function(t){const{widgetId:r}=u(),[n,o]=e.useState({loading:!1,error:null,success:!1});return{...n,callAI:e.useCallback((async(e,n)=>{var a;o({loading:!0,error:null,success:!1});try{const s={widgetId:r,capabilityId:"ai_call",integrationKey:t.platform,prompt:e,history:n||[]},c=await fetch(`${i}/api/execute/ai`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify(s)}),u=await c.json();if(!c.ok){const e=u.message||u.error||`HTTP ${c.status}`;return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}if(u.success)return o({loading:!1,error:null,success:!0}),{success:!0,message:(null==(a=u.data)?void 0:a.response)||"AI call completed successfully",data:u.data,metadata:u.metadata};{const e=u.message||u.error||"AI call failed";return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}}catch(s){const e=s instanceof Error?s.message:"Unknown error occurred";return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}}),[t.platform,r]),reset:e.useCallback((()=>{o({loading:!1,error:null,success:!1})}),[])}},exports.useDebounce=function(t,r){const[n,o]=e.useState(t);return e.useEffect((()=>{const e=setTimeout((()=>{o(t)}),r);return()=>{clearTimeout(e)}}),[t,r]),n},exports.useEmbeddableConfig=u,exports.useEmbeddableContext=p,exports.useEmbeddableData=function(){const{data:e}=p();return{data:e}},exports.useEventTracking=l,exports.useFormSubmission=function(t){const{widgetId:r}=u(),[n,o]=e.useState({loading:!1,error:null,success:!1});return{...n,submit:e.useCallback((async e=>{var n,a,s;o({loading:!0,error:null,success:!1});try{if(null==t?void 0:t.validatePayload){const r=t.validatePayload(e);if(r)return o({loading:!1,error:r,success:!1}),{success:!1,message:r}}const c={payload:e,widgetId:r,collectionName:(null==t?void 0:t.collectionName)||"submissions"},u=await fetch(`${i}/api/submissions`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify(c)}),l=await u.json();if(!u.ok){const e=l.message||l.error||`HTTP ${u.status}`;return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}if(l.success)return o({loading:!1,error:null,success:!0}),{id:(null==(n=l.data)?void 0:n.id)||(null==(a=l.data)?void 0:a._id),success:!0,message:(null==(s=l.data)?void 0:s.message)||"Submission successful"};{const e=l.message||l.error||"Submission failed";return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}}catch(c){const e=c instanceof Error?c.message:"Unknown error occurred";return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}}),[t,r]),reset:e.useCallback((()=>{o({loading:!1,error:null,success:!1})}),[])}},exports.useLocalStorage=function(r,n,o={}){const{widgetId:a}=u(),s=e.useMemo((()=>({...o,prefix:`embd-${a}-${o.prefix||""}`})),[a,o]),[c,i]=e.useState((()=>{const e=t.storage.get(r,s);return null!==e?e:n})),l=e.useCallback((e=>{try{const n=e instanceof Function?e(c):e;i(n),t.storage.set(r,n,s)}catch(n){}}),[r,c,s]),f=e.useCallback((()=>{try{i(n),t.storage.remove(r,s)}catch(e){}}),[r,n,s]);return e.useEffect((()=>{const e=e=>{const t=s.prefix+r;if(e.key===t&&null!==e.newValue)try{const{deserialize:t=JSON.parse}=s,r=t(e.newValue);i(r)}catch(n){}};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)}),[r,s]),[c,l,f]},exports.useVote=function(t){const{widgetId:r}=u(),[n,o]=e.useState({loading:!1,error:null,success:!1});return{...n,vote:e.useCallback((async e=>{var n,a,s;o({loading:!0,error:null,success:!1});try{const c={voteFor:e,widgetId:r,collectionName:(null==t?void 0:t.collectionName)||"votes"},u=await fetch(`${i}/api/votes`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify(c)}),l=await u.json();if(!u.ok){const e=l.message||l.error||`HTTP ${u.status}`;return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}if(l.success)return o({loading:!1,error:null,success:!0}),{id:(null==(n=l.data)?void 0:n.id)||(null==(a=l.data)?void 0:a._id),success:!0,message:(null==(s=l.data)?void 0:s.message)||"Vote submitted successfully"};{const e=l.message||l.error||"Vote submission failed";return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}}catch(c){const e=c instanceof Error?c.message:"Unknown error occurred";return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}}),[t,r]),reset:e.useCallback((()=>{o({loading:!1,error:null,success:!1})}),[])}},exports.useVoteAggregations=function(t){const{widgetId:r}=u(),[n,o]=e.useState({data:null,loading:!1,error:null}),a=e.useCallback((async()=>{if(!r)return o({data:null,loading:!1,error:"Widget ID is required"}),{success:!1,data:{results:[],summary:{totalVotes:0,totalOptions:0,groupBy:""}}};o((e=>({...e,loading:!0,error:null})));try{const e=(null==t?void 0:t.collectionName)||"votes",n=new URL(`${i}/api/votes/aggregations`);n.searchParams.append("widgetId",r),n.searchParams.append("collectionName",e);const a=await fetch(n.toString(),{method:"GET",headers:{"Content-Type":"application/json"},credentials:"omit"}),s=await a.json();if(!a.ok){const e=s.message||s.error||`HTTP ${a.status}`;return o({data:null,loading:!1,error:e}),{success:!1,data:{results:[],summary:{totalVotes:0,totalOptions:0,groupBy:""}}}}return o({data:s.data,loading:!1,error:null}),s}catch(e){const t=e instanceof Error?e.message:"Unknown error occurred";return o({data:null,loading:!1,error:t}),{success:!1,data:{results:[],summary:{totalVotes:0,totalOptions:0,groupBy:""}}}}}),[r,null==t?void 0:t.collectionName]),s=e.useCallback((()=>a()),[a]),c=e.useCallback((()=>{o({data:null,loading:!1,error:null})}),[]);return e.useEffect((()=>{!1!==(null==t?void 0:t.autoFetch)&&r&&a()}),[a,null==t?void 0:t.autoFetch,r]),e.useEffect((()=>{if((null==t?void 0:t.refetchInterval)&&t.refetchInterval>0&&r){const e=setInterval((()=>{a()}),t.refetchInterval);return()=>clearInterval(e)}}),[a,null==t?void 0:t.refetchInterval,r]),{...n,fetch:a,refetch:s,reset:c}};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import require$$0, { useState,
|
|
1
|
+
import require$$0, { useState, useCallback, useEffect, useMemo, createContext, useContext } from "react";
|
|
2
2
|
import { s as storage } from "./storage-B4eeCFyo.js";
|
|
3
3
|
var jsxRuntime = { exports: {} };
|
|
4
4
|
var reactJsxRuntime_production_min = {};
|
|
@@ -922,55 +922,6 @@ if (process.env.NODE_ENV === "production") {
|
|
|
922
922
|
jsxRuntime.exports = requireReactJsxRuntime_development();
|
|
923
923
|
}
|
|
924
924
|
var jsxRuntimeExports = jsxRuntime.exports;
|
|
925
|
-
const defaultConfig = {
|
|
926
|
-
version: "latest",
|
|
927
|
-
mode: "embeddable",
|
|
928
|
-
ignoreCache: false,
|
|
929
|
-
lazyLoad: false,
|
|
930
|
-
loader: true,
|
|
931
|
-
widgetId: "",
|
|
932
|
-
_containerId: "",
|
|
933
|
-
_shadowRoot: void 0
|
|
934
|
-
};
|
|
935
|
-
const EmbeddableContext = createContext({
|
|
936
|
-
config: { ...defaultConfig },
|
|
937
|
-
setConfig: () => {
|
|
938
|
-
},
|
|
939
|
-
data: {},
|
|
940
|
-
setData: () => {
|
|
941
|
-
}
|
|
942
|
-
});
|
|
943
|
-
function EmbeddableProvider({
|
|
944
|
-
config: initialConfig,
|
|
945
|
-
data: initialData,
|
|
946
|
-
children
|
|
947
|
-
}) {
|
|
948
|
-
const [config, setConfig] = useState(defaultConfig);
|
|
949
|
-
const [data, setData] = useState(initialData || {});
|
|
950
|
-
useEffect(() => {
|
|
951
|
-
setConfig({ ...defaultConfig, ...initialConfig });
|
|
952
|
-
}, [initialConfig]);
|
|
953
|
-
useEffect(() => {
|
|
954
|
-
const handleMessage = (event) => {
|
|
955
|
-
if (event.origin !== "https://embeddable.co" && !event.origin.includes("localhost")) return;
|
|
956
|
-
if (event.data && typeof event.data === "object" && event.data.type === "embeddable-update-data") {
|
|
957
|
-
setData(event.data.data || {});
|
|
958
|
-
}
|
|
959
|
-
};
|
|
960
|
-
window.addEventListener("message", handleMessage);
|
|
961
|
-
return () => {
|
|
962
|
-
window.removeEventListener("message", handleMessage);
|
|
963
|
-
};
|
|
964
|
-
}, []);
|
|
965
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsx(EmbeddableContext.Provider, { value: { config, setConfig, data, setData }, children });
|
|
966
|
-
}
|
|
967
|
-
function useEmbeddableContext() {
|
|
968
|
-
const context = useContext(EmbeddableContext);
|
|
969
|
-
if (!context) {
|
|
970
|
-
throw new Error("useEmbeddableContext must be used within an EmbeddableProvider");
|
|
971
|
-
}
|
|
972
|
-
return context;
|
|
973
|
-
}
|
|
974
925
|
const EVENTS_BASE_URL = "https://events.embeddable.co";
|
|
975
926
|
function useEmbeddableConfig() {
|
|
976
927
|
const { config } = useEmbeddableContext();
|
|
@@ -1070,6 +1021,217 @@ function useEmbeddableData() {
|
|
|
1070
1021
|
const { data } = useEmbeddableContext();
|
|
1071
1022
|
return { data };
|
|
1072
1023
|
}
|
|
1024
|
+
const useEventTracking = () => {
|
|
1025
|
+
const { widgetId } = useEmbeddableConfig();
|
|
1026
|
+
const apiBaseUrl = `${EVENTS_BASE_URL}/api`;
|
|
1027
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
1028
|
+
const track = useCallback(
|
|
1029
|
+
async (eventData, options = {}) => {
|
|
1030
|
+
const results = [];
|
|
1031
|
+
try {
|
|
1032
|
+
setIsLoading(true);
|
|
1033
|
+
const response = await fetch(`${apiBaseUrl}/marketing/track`, {
|
|
1034
|
+
method: "POST",
|
|
1035
|
+
headers: {
|
|
1036
|
+
"Content-Type": "application/json"
|
|
1037
|
+
},
|
|
1038
|
+
credentials: "omit",
|
|
1039
|
+
body: JSON.stringify({
|
|
1040
|
+
widgetId,
|
|
1041
|
+
inputs: eventData,
|
|
1042
|
+
integrationKey: options.integrationKey
|
|
1043
|
+
})
|
|
1044
|
+
});
|
|
1045
|
+
const result = await response.json();
|
|
1046
|
+
if (result.success) {
|
|
1047
|
+
if (result.results) {
|
|
1048
|
+
result.results.forEach((integrationResult) => {
|
|
1049
|
+
results.push({
|
|
1050
|
+
success: integrationResult.success,
|
|
1051
|
+
integrationKey: integrationResult.integrationKey,
|
|
1052
|
+
data: integrationResult.data,
|
|
1053
|
+
error: integrationResult.error
|
|
1054
|
+
});
|
|
1055
|
+
});
|
|
1056
|
+
} else {
|
|
1057
|
+
results.push({
|
|
1058
|
+
success: true,
|
|
1059
|
+
data: result.data
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
} else {
|
|
1063
|
+
results.push({
|
|
1064
|
+
success: false,
|
|
1065
|
+
error: result.error || "Unknown error"
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
1068
|
+
} catch (error) {
|
|
1069
|
+
results.push({
|
|
1070
|
+
success: false,
|
|
1071
|
+
error: error instanceof Error ? error.message : "Network error"
|
|
1072
|
+
});
|
|
1073
|
+
} finally {
|
|
1074
|
+
setIsLoading(false);
|
|
1075
|
+
}
|
|
1076
|
+
return results;
|
|
1077
|
+
},
|
|
1078
|
+
[widgetId, apiBaseUrl]
|
|
1079
|
+
);
|
|
1080
|
+
const trackPageView = useCallback(
|
|
1081
|
+
async (properties = {}) => {
|
|
1082
|
+
return track({
|
|
1083
|
+
event_name: "page_view",
|
|
1084
|
+
event_category: "engagement",
|
|
1085
|
+
custom_parameters: {
|
|
1086
|
+
page_url: window.location.href,
|
|
1087
|
+
page_title: document.title,
|
|
1088
|
+
referrer: document.referrer,
|
|
1089
|
+
...properties
|
|
1090
|
+
}
|
|
1091
|
+
});
|
|
1092
|
+
},
|
|
1093
|
+
[track]
|
|
1094
|
+
);
|
|
1095
|
+
const trackFormSubmit = useCallback(
|
|
1096
|
+
async (formData, properties = {}) => {
|
|
1097
|
+
return track({
|
|
1098
|
+
event_name: "form_submit",
|
|
1099
|
+
event_category: "conversion",
|
|
1100
|
+
custom_parameters: {
|
|
1101
|
+
form_data: formData,
|
|
1102
|
+
...properties
|
|
1103
|
+
}
|
|
1104
|
+
});
|
|
1105
|
+
},
|
|
1106
|
+
[track]
|
|
1107
|
+
);
|
|
1108
|
+
const trackClick = useCallback(
|
|
1109
|
+
async (element, properties = {}) => {
|
|
1110
|
+
let elementData = {};
|
|
1111
|
+
if (typeof element === "string") {
|
|
1112
|
+
elementData = { element_selector: element };
|
|
1113
|
+
} else {
|
|
1114
|
+
elementData = {
|
|
1115
|
+
element_id: element.id,
|
|
1116
|
+
element_class: element.className,
|
|
1117
|
+
element_text: element.textContent || element.innerText,
|
|
1118
|
+
element_tag: element.tagName.toLowerCase()
|
|
1119
|
+
};
|
|
1120
|
+
}
|
|
1121
|
+
return track({
|
|
1122
|
+
event_name: "button_click",
|
|
1123
|
+
event_category: "interaction",
|
|
1124
|
+
custom_parameters: {
|
|
1125
|
+
...elementData,
|
|
1126
|
+
...properties
|
|
1127
|
+
}
|
|
1128
|
+
});
|
|
1129
|
+
},
|
|
1130
|
+
[track]
|
|
1131
|
+
);
|
|
1132
|
+
const trackConversion = useCallback(
|
|
1133
|
+
async (conversionType, value, properties = {}) => {
|
|
1134
|
+
return track({
|
|
1135
|
+
event_name: "conversion",
|
|
1136
|
+
event_category: "conversion",
|
|
1137
|
+
value,
|
|
1138
|
+
custom_parameters: {
|
|
1139
|
+
conversion_type: conversionType,
|
|
1140
|
+
currency: properties.currency || "USD",
|
|
1141
|
+
...properties
|
|
1142
|
+
}
|
|
1143
|
+
});
|
|
1144
|
+
},
|
|
1145
|
+
[track]
|
|
1146
|
+
);
|
|
1147
|
+
const trackSignup = useCallback(
|
|
1148
|
+
async (userData, properties = {}) => {
|
|
1149
|
+
return track({
|
|
1150
|
+
event_name: "signup",
|
|
1151
|
+
event_category: "conversion",
|
|
1152
|
+
user_data: userData,
|
|
1153
|
+
custom_parameters: properties
|
|
1154
|
+
});
|
|
1155
|
+
},
|
|
1156
|
+
[track]
|
|
1157
|
+
);
|
|
1158
|
+
const trackPurchase = useCallback(
|
|
1159
|
+
async (transactionData, properties = {}) => {
|
|
1160
|
+
return track({
|
|
1161
|
+
event_name: "purchase",
|
|
1162
|
+
event_category: "ecommerce",
|
|
1163
|
+
value: transactionData.amount,
|
|
1164
|
+
custom_parameters: {
|
|
1165
|
+
transaction_id: transactionData.id,
|
|
1166
|
+
currency: transactionData.currency || "USD",
|
|
1167
|
+
items: transactionData.items || [],
|
|
1168
|
+
...properties
|
|
1169
|
+
}
|
|
1170
|
+
});
|
|
1171
|
+
},
|
|
1172
|
+
[track]
|
|
1173
|
+
);
|
|
1174
|
+
const enableAutoPageView = useCallback(() => {
|
|
1175
|
+
trackPageView();
|
|
1176
|
+
}, [trackPageView]);
|
|
1177
|
+
const enableAutoFormTracking = useCallback(() => {
|
|
1178
|
+
const handleFormSubmit = async (event) => {
|
|
1179
|
+
try {
|
|
1180
|
+
const form = event.target;
|
|
1181
|
+
const formData = new FormData(form);
|
|
1182
|
+
const formObject = Object.fromEntries(formData.entries());
|
|
1183
|
+
await trackFormSubmit(formObject, {
|
|
1184
|
+
form_id: form.id,
|
|
1185
|
+
form_class: form.className,
|
|
1186
|
+
form_action: form.action,
|
|
1187
|
+
form_method: form.method
|
|
1188
|
+
});
|
|
1189
|
+
} catch (error) {
|
|
1190
|
+
console.error("[MarketingIntegration] Error auto-tracking form submission:", error);
|
|
1191
|
+
}
|
|
1192
|
+
};
|
|
1193
|
+
document.addEventListener("submit", handleFormSubmit);
|
|
1194
|
+
return () => {
|
|
1195
|
+
document.removeEventListener("submit", handleFormSubmit);
|
|
1196
|
+
};
|
|
1197
|
+
}, [trackFormSubmit]);
|
|
1198
|
+
const enableAutoClickTracking = useCallback(
|
|
1199
|
+
(selector = 'button, .btn, [role="button"], a, input[type="submit"]') => {
|
|
1200
|
+
const handleClick = async (event) => {
|
|
1201
|
+
const element = event.target.closest(selector);
|
|
1202
|
+
if (element) {
|
|
1203
|
+
try {
|
|
1204
|
+
await trackClick(element);
|
|
1205
|
+
} catch (error) {
|
|
1206
|
+
console.error("[MarketingIntegration] Error auto-tracking click:", error);
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
};
|
|
1210
|
+
document.addEventListener("click", handleClick);
|
|
1211
|
+
return () => {
|
|
1212
|
+
document.removeEventListener("click", handleClick);
|
|
1213
|
+
};
|
|
1214
|
+
},
|
|
1215
|
+
[trackClick]
|
|
1216
|
+
);
|
|
1217
|
+
return {
|
|
1218
|
+
// State
|
|
1219
|
+
isLoading,
|
|
1220
|
+
// Core methods
|
|
1221
|
+
track,
|
|
1222
|
+
// Convenience methods
|
|
1223
|
+
trackPageView,
|
|
1224
|
+
trackFormSubmit,
|
|
1225
|
+
trackClick,
|
|
1226
|
+
trackConversion,
|
|
1227
|
+
trackSignup,
|
|
1228
|
+
trackPurchase,
|
|
1229
|
+
// Auto-tracking
|
|
1230
|
+
enableAutoPageView,
|
|
1231
|
+
enableAutoFormTracking,
|
|
1232
|
+
enableAutoClickTracking
|
|
1233
|
+
};
|
|
1234
|
+
};
|
|
1073
1235
|
function useFormSubmission(options) {
|
|
1074
1236
|
const { widgetId } = useEmbeddableConfig();
|
|
1075
1237
|
const [state, setState] = useState({
|
|
@@ -1346,15 +1508,71 @@ function useVoteAggregations(options) {
|
|
|
1346
1508
|
reset
|
|
1347
1509
|
};
|
|
1348
1510
|
}
|
|
1511
|
+
const defaultConfig = {
|
|
1512
|
+
version: "latest",
|
|
1513
|
+
mode: "embeddable",
|
|
1514
|
+
ignoreCache: false,
|
|
1515
|
+
lazyLoad: false,
|
|
1516
|
+
loader: true,
|
|
1517
|
+
widgetId: "",
|
|
1518
|
+
_containerId: "",
|
|
1519
|
+
_shadowRoot: void 0
|
|
1520
|
+
};
|
|
1521
|
+
const EmbeddableContext = createContext({
|
|
1522
|
+
config: { ...defaultConfig },
|
|
1523
|
+
setConfig: () => {
|
|
1524
|
+
},
|
|
1525
|
+
data: {},
|
|
1526
|
+
setData: () => {
|
|
1527
|
+
}
|
|
1528
|
+
});
|
|
1529
|
+
function EmbeddableProvider({
|
|
1530
|
+
config: initialConfig,
|
|
1531
|
+
data: initialData,
|
|
1532
|
+
children
|
|
1533
|
+
}) {
|
|
1534
|
+
const [config, setConfig] = useState(defaultConfig);
|
|
1535
|
+
const [data, setData] = useState(initialData || {});
|
|
1536
|
+
const { enableAutoPageView } = useEventTracking();
|
|
1537
|
+
useEffect(() => {
|
|
1538
|
+
setConfig({ ...defaultConfig, ...initialConfig });
|
|
1539
|
+
}, [initialConfig]);
|
|
1540
|
+
useEffect(() => {
|
|
1541
|
+
if (config.widgetId && config.mode !== "preview") {
|
|
1542
|
+
enableAutoPageView();
|
|
1543
|
+
}
|
|
1544
|
+
}, [enableAutoPageView, config.widgetId, config.mode]);
|
|
1545
|
+
useEffect(() => {
|
|
1546
|
+
const handleMessage = (event) => {
|
|
1547
|
+
if (event.origin !== "https://embeddable.co" && !event.origin.includes("localhost")) return;
|
|
1548
|
+
if (event.data && typeof event.data === "object" && event.data.type === "embeddable-update-data") {
|
|
1549
|
+
setData(event.data.data || {});
|
|
1550
|
+
}
|
|
1551
|
+
};
|
|
1552
|
+
window.addEventListener("message", handleMessage);
|
|
1553
|
+
return () => {
|
|
1554
|
+
window.removeEventListener("message", handleMessage);
|
|
1555
|
+
};
|
|
1556
|
+
}, []);
|
|
1557
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(EmbeddableContext.Provider, { value: { config, setConfig, data, setData }, children });
|
|
1558
|
+
}
|
|
1559
|
+
function useEmbeddableContext() {
|
|
1560
|
+
const context = useContext(EmbeddableContext);
|
|
1561
|
+
if (!context) {
|
|
1562
|
+
throw new Error("useEmbeddableContext must be used within an EmbeddableProvider");
|
|
1563
|
+
}
|
|
1564
|
+
return context;
|
|
1565
|
+
}
|
|
1349
1566
|
export {
|
|
1350
1567
|
EmbeddableProvider as E,
|
|
1351
1568
|
useAI as a,
|
|
1352
1569
|
useDebounce as b,
|
|
1353
1570
|
useEmbeddableConfig as c,
|
|
1354
1571
|
useEmbeddableData as d,
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1572
|
+
useEventTracking as e,
|
|
1573
|
+
useFormSubmission as f,
|
|
1574
|
+
useLocalStorage as g,
|
|
1575
|
+
useVote as h,
|
|
1576
|
+
useVoteAggregations as i,
|
|
1359
1577
|
useEmbeddableContext as u
|
|
1360
1578
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EmbeddableProvider.d.ts","sourceRoot":"","sources":["../../src/context/EmbeddableProvider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAiB,SAAS,EAAmC,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"EmbeddableProvider.d.ts","sourceRoot":"","sources":["../../src/context/EmbeddableProvider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAiB,SAAS,EAAmC,MAAM,OAAO,CAAC;AAElF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD,UAAU,qBAAqB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IACrD,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAChC,SAAS,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAC9C,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;CAC5B;AAoBD,UAAU,uBAAuB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IACvD,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,wBAAgB,kBAAkB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,EAC1D,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,WAAW,EACjB,QAAQ,GACT,EAAE,uBAAuB,CAAC,CAAC,CAAC,2CAwC5B;AAED,wBAAgB,oBAAoB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,qBAAqB,CAAC,CAAC,CAAC,CAMxF"}
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { useAI } from './useAI';
|
|
|
2
2
|
export { useDebounce } from './useDebounce';
|
|
3
3
|
export { useEmbeddableConfig } from './useEmbeddableConfig';
|
|
4
4
|
export { useEmbeddableData } from './useEmbeddableData';
|
|
5
|
+
export { useEventTracking } from './useEventTracking';
|
|
5
6
|
export { useFormSubmission } from './useFormSubmission';
|
|
6
7
|
export { useLocalStorage } from './useLocalStorage';
|
|
7
8
|
export { useVote } from './useVote';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export interface MarketingEventData {
|
|
2
|
+
event_name: string;
|
|
3
|
+
event_category?: string;
|
|
4
|
+
event_action?: string;
|
|
5
|
+
event_label?: string;
|
|
6
|
+
value?: number;
|
|
7
|
+
custom_parameters?: Record<string, any>;
|
|
8
|
+
user_data?: {
|
|
9
|
+
email?: string;
|
|
10
|
+
phone?: string;
|
|
11
|
+
external_id?: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface TrackingOptions {
|
|
15
|
+
integrationKey?: string;
|
|
16
|
+
skipAutoTrigger?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface MarketingTrackingResult {
|
|
19
|
+
success: boolean;
|
|
20
|
+
integrationKey?: string;
|
|
21
|
+
data?: any;
|
|
22
|
+
error?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface useEventTrackingReturn {
|
|
25
|
+
isLoading: boolean;
|
|
26
|
+
track: (eventData: MarketingEventData, options?: TrackingOptions) => Promise<MarketingTrackingResult[]>;
|
|
27
|
+
trackPageView: (properties?: Record<string, any>) => Promise<MarketingTrackingResult[]>;
|
|
28
|
+
trackFormSubmit: (formData: Record<string, any>, properties?: Record<string, any>) => Promise<MarketingTrackingResult[]>;
|
|
29
|
+
trackClick: (element: string | HTMLElement, properties?: Record<string, any>) => Promise<MarketingTrackingResult[]>;
|
|
30
|
+
trackConversion: (conversionType: string, value: number, properties?: Record<string, any>) => Promise<MarketingTrackingResult[]>;
|
|
31
|
+
trackSignup: (userData: Record<string, any>, properties?: Record<string, any>) => Promise<MarketingTrackingResult[]>;
|
|
32
|
+
trackPurchase: (transactionData: {
|
|
33
|
+
id: string;
|
|
34
|
+
amount: number;
|
|
35
|
+
currency?: string;
|
|
36
|
+
items?: any[];
|
|
37
|
+
}, properties?: Record<string, any>) => Promise<MarketingTrackingResult[]>;
|
|
38
|
+
enableAutoPageView: () => void;
|
|
39
|
+
enableAutoFormTracking: () => void;
|
|
40
|
+
enableAutoClickTracking: (selector?: string) => void;
|
|
41
|
+
}
|
|
42
|
+
export declare const useEventTracking: () => useEventTrackingReturn;
|
|
43
|
+
//# sourceMappingURL=useEventTracking.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEventTracking.d.ts","sourceRoot":"","sources":["../../src/hooks/useEventTracking.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACxC,SAAS,CAAC,EAAE;QACV,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;CACH;AAED,MAAM,WAAW,eAAe;IAC9B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,OAAO,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,sBAAsB;IAErC,SAAS,EAAE,OAAO,CAAC;IAGnB,KAAK,EAAE,CACL,SAAS,EAAE,kBAAkB,EAC7B,OAAO,CAAC,EAAE,eAAe,KACtB,OAAO,CAAC,uBAAuB,EAAE,CAAC,CAAC;IAGxC,aAAa,EAAE,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,OAAO,CAAC,uBAAuB,EAAE,CAAC,CAAC;IACxF,eAAe,EAAE,CACf,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC7B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAC7B,OAAO,CAAC,uBAAuB,EAAE,CAAC,CAAC;IACxC,UAAU,EAAE,CACV,OAAO,EAAE,MAAM,GAAG,WAAW,EAC7B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAC7B,OAAO,CAAC,uBAAuB,EAAE,CAAC,CAAC;IACxC,eAAe,EAAE,CACf,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAC7B,OAAO,CAAC,uBAAuB,EAAE,CAAC,CAAC;IACxC,WAAW,EAAE,CACX,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC7B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAC7B,OAAO,CAAC,uBAAuB,EAAE,CAAC,CAAC;IACxC,aAAa,EAAE,CACb,eAAe,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,GAAG,EAAE,CAAA;KAAE,EACjF,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAC7B,OAAO,CAAC,uBAAuB,EAAE,CAAC,CAAC;IAGxC,kBAAkB,EAAE,MAAM,IAAI,CAAC;IAC/B,sBAAsB,EAAE,MAAM,IAAI,CAAC;IACnC,uBAAuB,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;CACtD;AAED,eAAO,MAAM,gBAAgB,QAAO,sBAqPnC,CAAC"}
|
package/dist/hooks.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./EmbeddableProvider-74nyeXDc.cjs");exports.useAI=e.useAI,exports.useDebounce=e.useDebounce,exports.useEmbeddableConfig=e.useEmbeddableConfig,exports.useEmbeddableData=e.useEmbeddableData,exports.useEventTracking=e.useEventTracking,exports.useFormSubmission=e.useFormSubmission,exports.useLocalStorage=e.useLocalStorage,exports.useVote=e.useVote,exports.useVoteAggregations=e.useVoteAggregations;
|
package/dist/hooks.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { a, b, c, d, e, f, g, h } from "./
|
|
1
|
+
import { a, b, c, d, e, f, g, h, i } from "./EmbeddableProvider-OdbqzsmX.js";
|
|
2
2
|
export {
|
|
3
3
|
a as useAI,
|
|
4
4
|
b as useDebounce,
|
|
5
5
|
c as useEmbeddableConfig,
|
|
6
6
|
d as useEmbeddableData,
|
|
7
|
-
e as
|
|
8
|
-
f as
|
|
9
|
-
g as
|
|
10
|
-
h as
|
|
7
|
+
e as useEventTracking,
|
|
8
|
+
f as useFormSubmission,
|
|
9
|
+
g as useLocalStorage,
|
|
10
|
+
h as useVote,
|
|
11
|
+
i as useVoteAggregations
|
|
11
12
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./EmbeddableProvider-74nyeXDc.cjs"),s=require("./utils.cjs"),o=require("./storage-EjA7Lhbb.cjs");exports.EmbeddableProvider=e.EmbeddableProvider,exports.useAI=e.useAI,exports.useDebounce=e.useDebounce,exports.useEmbeddableConfig=e.useEmbeddableConfig,exports.useEmbeddableContext=e.useEmbeddableContext,exports.useEmbeddableData=e.useEmbeddableData,exports.useEventTracking=e.useEventTracking,exports.useFormSubmission=e.useFormSubmission,exports.useLocalStorage=e.useLocalStorage,exports.useVote=e.useVote,exports.useVoteAggregations=e.useVoteAggregations,exports.createApiClient=s.createApiClient,exports.debounce=s.debounce,exports.storage=o.storage;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E, a, b, c, u, d, e, f, g, h } from "./
|
|
1
|
+
import { E, a, b, c, u, d, e, f, g, h, i } from "./EmbeddableProvider-OdbqzsmX.js";
|
|
2
2
|
import { createApiClient, debounce } from "./utils.js";
|
|
3
3
|
import { s } from "./storage-B4eeCFyo.js";
|
|
4
4
|
export {
|
|
@@ -11,8 +11,9 @@ export {
|
|
|
11
11
|
c as useEmbeddableConfig,
|
|
12
12
|
u as useEmbeddableContext,
|
|
13
13
|
d as useEmbeddableData,
|
|
14
|
-
e as
|
|
15
|
-
f as
|
|
16
|
-
g as
|
|
17
|
-
h as
|
|
14
|
+
e as useEventTracking,
|
|
15
|
+
f as useFormSubmission,
|
|
16
|
+
g as useLocalStorage,
|
|
17
|
+
h as useVote,
|
|
18
|
+
i as useVoteAggregations
|
|
18
19
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";const e=require("react"),r=require("./storage-EjA7Lhbb.cjs");var t,n={exports:{}},o={};var a,s={};
|
|
2
|
-
/**
|
|
3
|
-
* @license React
|
|
4
|
-
* react-jsx-runtime.development.js
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
7
|
-
*
|
|
8
|
-
* This source code is licensed under the MIT license found in the
|
|
9
|
-
* LICENSE file in the root directory of this source tree.
|
|
10
|
-
*/"production"===process.env.NODE_ENV?n.exports=function(){if(t)return o;t=1;var r=e,n=Symbol.for("react.element"),a=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,i=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,c={key:!0,ref:!0,__self:!0,__source:!0};function l(e,r,t){var o,a={},l=null,u=null;for(o in void 0!==t&&(l=""+t),void 0!==r.key&&(l=""+r.key),void 0!==r.ref&&(u=r.ref),r)s.call(r,o)&&!c.hasOwnProperty(o)&&(a[o]=r[o]);if(e&&e.defaultProps)for(o in r=e.defaultProps)void 0===a[o]&&(a[o]=r[o]);return{$$typeof:n,type:e,key:l,ref:u,props:a,_owner:i.current}}return o.Fragment=a,o.jsx=l,o.jsxs=l,o}():n.exports=(a||(a=1,"production"!==process.env.NODE_ENV&&function(){var r,t=e,n=Symbol.for("react.element"),o=Symbol.for("react.portal"),a=Symbol.for("react.fragment"),i=Symbol.for("react.strict_mode"),c=Symbol.for("react.profiler"),l=Symbol.for("react.provider"),u=Symbol.for("react.context"),f=Symbol.for("react.forward_ref"),d=Symbol.for("react.suspense"),p=Symbol.for("react.suspense_list"),y=Symbol.for("react.memo"),g=Symbol.for("react.lazy"),m=Symbol.for("react.offscreen"),v=Symbol.iterator,b=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function h(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];!function(e,r,t){var n=b.ReactDebugCurrentFrame.getStackAddendum();""!==n&&(r+="%s",t=t.concat([n]));var o=t.map((function(e){return String(e)}));o.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,o)}("error",e,t)}function w(e){return e.displayName||"Context"}function k(e){if(null==e)return null;if("number"==typeof e.tag&&h("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),"function"==typeof e)return e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case a:return"Fragment";case o:return"Portal";case c:return"Profiler";case i:return"StrictMode";case d:return"Suspense";case p:return"SuspenseList"}if("object"==typeof e)switch(e.$$typeof){case u:return w(e)+".Consumer";case l:return w(e._context)+".Provider";case f:return function(e,r,t){var n=e.displayName;if(n)return n;var o=r.displayName||r.name||"";return""!==o?t+"("+o+")":t}(e,e.render,"ForwardRef");case y:var r=e.displayName||null;return null!==r?r:k(e.type)||"Memo";case g:var t=e,n=t._payload,s=t._init;try{return k(s(n))}catch(m){return null}}return null}r=Symbol.for("react.module.reference");var _,S,E,O,j,T,P,x=Object.assign,C=0;function R(){}R.__reactDisabledLog=!0;var I,$=b.ReactCurrentDispatcher;function N(e,r,t){if(void 0===I)try{throw Error()}catch(o){var n=o.stack.trim().match(/\n( *(at )?)/);I=n&&n[1]||""}return"\n"+I+e}var D,F=!1,L="function"==typeof WeakMap?WeakMap:Map;function U(e,r){if(!e||F)return"";var t,n=D.get(e);if(void 0!==n)return n;F=!0;var o,a=Error.prepareStackTrace;Error.prepareStackTrace=void 0,o=$.current,$.current=null,function(){if(0===C){_=console.log,S=console.info,E=console.warn,O=console.error,j=console.group,T=console.groupCollapsed,P=console.groupEnd;var e={configurable:!0,enumerable:!0,value:R,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}C++}();try{if(r){var s=function(){throw Error()};if(Object.defineProperty(s.prototype,"props",{set:function(){throw Error()}}),"object"==typeof Reflect&&Reflect.construct){try{Reflect.construct(s,[])}catch(y){t=y}Reflect.construct(e,[],s)}else{try{s.call()}catch(y){t=y}e.call(s.prototype)}}else{try{throw Error()}catch(y){t=y}e()}}catch(g){if(g&&t&&"string"==typeof g.stack){for(var i=g.stack.split("\n"),c=t.stack.split("\n"),l=i.length-1,u=c.length-1;l>=1&&u>=0&&i[l]!==c[u];)u--;for(;l>=1&&u>=0;l--,u--)if(i[l]!==c[u]){if(1!==l||1!==u)do{if(l--,--u<0||i[l]!==c[u]){var f="\n"+i[l].replace(" at new "," at ");return e.displayName&&f.includes("<anonymous>")&&(f=f.replace("<anonymous>",e.displayName)),"function"==typeof e&&D.set(e,f),f}}while(l>=1&&u>=0);break}}}finally{F=!1,$.current=o,function(){if(0===--C){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:x({},e,{value:_}),info:x({},e,{value:S}),warn:x({},e,{value:E}),error:x({},e,{value:O}),group:x({},e,{value:j}),groupCollapsed:x({},e,{value:T}),groupEnd:x({},e,{value:P})})}C<0&&h("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}(),Error.prepareStackTrace=a}var d=e?e.displayName||e.name:"",p=d?N(d):"";return"function"==typeof e&&D.set(e,p),p}function A(e,r,t){if(null==e)return"";if("function"==typeof e)return U(e,!(!(n=e.prototype)||!n.isReactComponent));var n;if("string"==typeof e)return N(e);switch(e){case d:return N("Suspense");case p:return N("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case f:return U(e.render,!1);case y:return A(e.type,r,t);case g:var o=e,a=o._payload,s=o._init;try{return A(s(a),r,t)}catch(i){}}return""}D=new L;var V=Object.prototype.hasOwnProperty,W={},z=b.ReactDebugCurrentFrame;function M(e){if(e){var r=e._owner,t=A(e.type,e._source,r?r.type:null);z.setExtraStackFrame(t)}else z.setExtraStackFrame(null)}var B=Array.isArray;function J(e){return B(e)}function Y(e){return""+e}function q(e){if(function(e){try{return Y(e),!1}catch(r){return!0}}(e))return h("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",function(e){return"function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object"}(e)),Y(e)}var H,K,X=b.ReactCurrentOwner,G={key:!0,ref:!0,__self:!0,__source:!0};function Q(e,r,t,o,a){var s,i={},c=null,l=null;for(s in void 0!==t&&(q(t),c=""+t),function(e){if(V.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return void 0!==e.key}(r)&&(q(r.key),c=""+r.key),function(e){if(V.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return void 0!==e.ref}(r)&&(l=r.ref,function(e){"string"==typeof e.ref&&X.current}(r)),r)V.call(r,s)&&!G.hasOwnProperty(s)&&(i[s]=r[s]);if(e&&e.defaultProps){var u=e.defaultProps;for(s in u)void 0===i[s]&&(i[s]=u[s])}if(c||l){var f="function"==typeof e?e.displayName||e.name||"Unknown":e;c&&function(e,r){var t=function(){H||(H=!0,h("%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})}(i,f),l&&function(e,r){var t=function(){K||(K=!0,h("%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})}(i,f)}return function(e,r,t,o,a,s,i){var c={$$typeof:n,type:e,key:r,ref:t,props:i,_owner:s,_store:{}};return Object.defineProperty(c._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(c,"_self",{configurable:!1,enumerable:!1,writable:!1,value:o}),Object.defineProperty(c,"_source",{configurable:!1,enumerable:!1,writable:!1,value:a}),Object.freeze&&(Object.freeze(c.props),Object.freeze(c)),c}(e,c,l,a,o,X.current,i)}var Z,ee=b.ReactCurrentOwner,re=b.ReactDebugCurrentFrame;function te(e){if(e){var r=e._owner,t=A(e.type,e._source,r?r.type:null);re.setExtraStackFrame(t)}else re.setExtraStackFrame(null)}function ne(e){return"object"==typeof e&&null!==e&&e.$$typeof===n}function oe(){if(ee.current){var e=k(ee.current.type);if(e)return"\n\nCheck the render method of `"+e+"`."}return""}Z=!1;var ae={};function se(e,r){if(e._store&&!e._store.validated&&null==e.key){e._store.validated=!0;var t=function(e){var r=oe();if(!r){var t="string"==typeof e?e:e.displayName||e.name;t&&(r="\n\nCheck the top-level render call using <"+t+">.")}return r}(r);if(!ae[t]){ae[t]=!0;var n="";e&&e._owner&&e._owner!==ee.current&&(n=" It was passed a child from "+k(e._owner.type)+"."),te(e),h('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),te(null)}}}function ie(e,r){if("object"==typeof e)if(J(e))for(var t=0;t<e.length;t++){var n=e[t];ne(n)&&se(n,r)}else if(ne(e))e._store&&(e._store.validated=!0);else if(e){var o=function(e){if(null===e||"object"!=typeof e)return null;var r=v&&e[v]||e["@@iterator"];return"function"==typeof r?r:null}(e);if("function"==typeof o&&o!==e.entries)for(var a,s=o.call(e);!(a=s.next()).done;)ne(a.value)&&se(a.value,r)}}function ce(e){var r,t=e.type;if(null!=t&&"string"!=typeof t){if("function"==typeof t)r=t.propTypes;else{if("object"!=typeof t||t.$$typeof!==f&&t.$$typeof!==y)return;r=t.propTypes}if(r){var n=k(t);!function(e,r,t,n,o){var a=Function.call.bind(V);for(var s in e)if(a(e,s)){var i=void 0;try{if("function"!=typeof e[s]){var c=Error((n||"React class")+": "+t+" type `"+s+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[s]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw c.name="Invariant Violation",c}i=e[s](r,s,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(l){i=l}!i||i instanceof Error||(M(o),h("%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,s,typeof i),M(null)),i instanceof Error&&!(i.message in W)&&(W[i.message]=!0,M(o),h("Failed %s type: %s",t,i.message),M(null))}}(r,e.props,"prop",n,e)}else void 0===t.PropTypes||Z||(Z=!0,h("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",k(t)||"Unknown"));"function"!=typeof t.getDefaultProps||t.getDefaultProps.isReactClassApproved||h("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}var le={};function ue(e,t,o,s,v,b){var w=function(e){return"string"==typeof e||"function"==typeof e||e===a||e===c||e===i||e===d||e===p||e===m||"object"==typeof e&&null!==e&&(e.$$typeof===g||e.$$typeof===y||e.$$typeof===l||e.$$typeof===u||e.$$typeof===f||e.$$typeof===r||void 0!==e.getModuleId)}(e);if(!w){var _,S="";(void 0===e||"object"==typeof e&&null!==e&&0===Object.keys(e).length)&&(S+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports."),S+=oe(),null===e?_="null":J(e)?_="array":void 0!==e&&e.$$typeof===n?(_="<"+(k(e.type)||"Unknown")+" />",S=" Did you accidentally export a JSX literal instead of a component?"):_=typeof e,h("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",_,S)}var E=Q(e,t,o,v,b);if(null==E)return E;if(w){var O=t.children;if(void 0!==O)if(s)if(J(O)){for(var j=0;j<O.length;j++)ie(O[j],e);Object.freeze&&Object.freeze(O)}else h("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 ie(O,e)}if(V.call(t,"key")){var T=k(e),P=Object.keys(t).filter((function(e){return"key"!==e})),x=P.length>0?"{key: someKey, "+P.join(": ..., ")+": ...}":"{key: someKey}";le[T+x]||(h('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',x,T,P.length>0?"{"+P.join(": ..., ")+": ...}":"{}",T),le[T+x]=!0)}return e===a?function(e){for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if("children"!==n&&"key"!==n){te(e),h("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),te(null);break}}null!==e.ref&&(te(e),h("Invalid attribute `ref` supplied to `React.Fragment`."),te(null))}(E):ce(E),E}var fe=function(e,r,t){return ue(e,r,t,!1)},de=function(e,r,t){return ue(e,r,t,!0)};s.Fragment=a,s.jsx=fe,s.jsxs=de}()),s);var i=n.exports;const c={version:"latest",mode:"embeddable",ignoreCache:!1,lazyLoad:!1,loader:!0,widgetId:"",_containerId:"",_shadowRoot:void 0},l=e.createContext({config:{...c},setConfig:()=>{},data:{},setData:()=>{}});function u(){const r=e.useContext(l);if(!r)throw new Error("useEmbeddableContext must be used within an EmbeddableProvider");return r}const f="https://events.embeddable.co";function d(){const{config:e}=u();if(!e)throw new Error("No Embeddable configuration found. Make sure to wrap your app with EmbeddableProvider and provide a valid config.");return e}exports.EmbeddableProvider=function({config:r,data:t,children:n}){const[o,a]=e.useState(c),[s,u]=e.useState(t||{});return e.useEffect((()=>{a({...c,...r})}),[r]),e.useEffect((()=>{const e=e=>{("https://embeddable.co"===e.origin||e.origin.includes("localhost"))&&e.data&&"object"==typeof e.data&&"embeddable-update-data"===e.data.type&&u(e.data.data||{})};return window.addEventListener("message",e),()=>{window.removeEventListener("message",e)}}),[]),i.jsx(l.Provider,{value:{config:o,setConfig:a,data:s,setData:u},children:n})},exports.useAI=function(r){const{widgetId:t}=d(),[n,o]=e.useState({loading:!1,error:null,success:!1});return{...n,callAI:e.useCallback((async(e,n)=>{var a;o({loading:!0,error:null,success:!1});try{const s={widgetId:t,capabilityId:"ai_call",integrationKey:r.platform,prompt:e,history:n||[]},i=await fetch(`${f}/api/execute/ai`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify(s)}),c=await i.json();if(!i.ok){const e=c.message||c.error||`HTTP ${i.status}`;return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}if(c.success)return o({loading:!1,error:null,success:!0}),{success:!0,message:(null==(a=c.data)?void 0:a.response)||"AI call completed successfully",data:c.data,metadata:c.metadata};{const e=c.message||c.error||"AI call failed";return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}}catch(s){const e=s instanceof Error?s.message:"Unknown error occurred";return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}}),[r.platform,t]),reset:e.useCallback((()=>{o({loading:!1,error:null,success:!1})}),[])}},exports.useDebounce=function(r,t){const[n,o]=e.useState(r);return e.useEffect((()=>{const e=setTimeout((()=>{o(r)}),t);return()=>{clearTimeout(e)}}),[r,t]),n},exports.useEmbeddableConfig=d,exports.useEmbeddableContext=u,exports.useEmbeddableData=function(){const{data:e}=u();return{data:e}},exports.useFormSubmission=function(r){const{widgetId:t}=d(),[n,o]=e.useState({loading:!1,error:null,success:!1});return{...n,submit:e.useCallback((async e=>{var n,a,s;o({loading:!0,error:null,success:!1});try{if(null==r?void 0:r.validatePayload){const t=r.validatePayload(e);if(t)return o({loading:!1,error:t,success:!1}),{success:!1,message:t}}const i={payload:e,widgetId:t,collectionName:(null==r?void 0:r.collectionName)||"submissions"},c=await fetch(`${f}/api/submissions`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify(i)}),l=await c.json();if(!c.ok){const e=l.message||l.error||`HTTP ${c.status}`;return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}if(l.success)return o({loading:!1,error:null,success:!0}),{id:(null==(n=l.data)?void 0:n.id)||(null==(a=l.data)?void 0:a._id),success:!0,message:(null==(s=l.data)?void 0:s.message)||"Submission successful"};{const e=l.message||l.error||"Submission failed";return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}}catch(i){const e=i instanceof Error?i.message:"Unknown error occurred";return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}}),[r,t]),reset:e.useCallback((()=>{o({loading:!1,error:null,success:!1})}),[])}},exports.useLocalStorage=function(t,n,o={}){const{widgetId:a}=d(),s=e.useMemo((()=>({...o,prefix:`embd-${a}-${o.prefix||""}`})),[a,o]),[i,c]=e.useState((()=>{const e=r.storage.get(t,s);return null!==e?e:n})),l=e.useCallback((e=>{try{const n=e instanceof Function?e(i):e;c(n),r.storage.set(t,n,s)}catch(n){}}),[t,i,s]),u=e.useCallback((()=>{try{c(n),r.storage.remove(t,s)}catch(e){}}),[t,n,s]);return e.useEffect((()=>{const e=e=>{const r=s.prefix+t;if(e.key===r&&null!==e.newValue)try{const{deserialize:r=JSON.parse}=s,t=r(e.newValue);c(t)}catch(n){}};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)}),[t,s]),[i,l,u]},exports.useVote=function(r){const{widgetId:t}=d(),[n,o]=e.useState({loading:!1,error:null,success:!1});return{...n,vote:e.useCallback((async e=>{var n,a,s;o({loading:!0,error:null,success:!1});try{const i={voteFor:e,widgetId:t,collectionName:(null==r?void 0:r.collectionName)||"votes"},c=await fetch(`${f}/api/votes`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify(i)}),l=await c.json();if(!c.ok){const e=l.message||l.error||`HTTP ${c.status}`;return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}if(l.success)return o({loading:!1,error:null,success:!0}),{id:(null==(n=l.data)?void 0:n.id)||(null==(a=l.data)?void 0:a._id),success:!0,message:(null==(s=l.data)?void 0:s.message)||"Vote submitted successfully"};{const e=l.message||l.error||"Vote submission failed";return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}}catch(i){const e=i instanceof Error?i.message:"Unknown error occurred";return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}}),[r,t]),reset:e.useCallback((()=>{o({loading:!1,error:null,success:!1})}),[])}},exports.useVoteAggregations=function(r){const{widgetId:t}=d(),[n,o]=e.useState({data:null,loading:!1,error:null}),a=e.useCallback((async()=>{if(!t)return o({data:null,loading:!1,error:"Widget ID is required"}),{success:!1,data:{results:[],summary:{totalVotes:0,totalOptions:0,groupBy:""}}};o((e=>({...e,loading:!0,error:null})));try{const e=(null==r?void 0:r.collectionName)||"votes",n=new URL(`${f}/api/votes/aggregations`);n.searchParams.append("widgetId",t),n.searchParams.append("collectionName",e);const a=await fetch(n.toString(),{method:"GET",headers:{"Content-Type":"application/json"},credentials:"omit"}),s=await a.json();if(!a.ok){const e=s.message||s.error||`HTTP ${a.status}`;return o({data:null,loading:!1,error:e}),{success:!1,data:{results:[],summary:{totalVotes:0,totalOptions:0,groupBy:""}}}}return o({data:s.data,loading:!1,error:null}),s}catch(e){const r=e instanceof Error?e.message:"Unknown error occurred";return o({data:null,loading:!1,error:r}),{success:!1,data:{results:[],summary:{totalVotes:0,totalOptions:0,groupBy:""}}}}}),[t,null==r?void 0:r.collectionName]),s=e.useCallback((()=>a()),[a]),i=e.useCallback((()=>{o({data:null,loading:!1,error:null})}),[]);return e.useEffect((()=>{!1!==(null==r?void 0:r.autoFetch)&&t&&a()}),[a,null==r?void 0:r.autoFetch,t]),e.useEffect((()=>{if((null==r?void 0:r.refetchInterval)&&r.refetchInterval>0&&t){const e=setInterval((()=>{a()}),r.refetchInterval);return()=>clearInterval(e)}}),[a,null==r?void 0:r.refetchInterval,t]),{...n,fetch:a,refetch:s,reset:i}};
|