@opengovsg/confetti 0.1.1 → 0.1.3
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/README.md +1 -1
- package/build/index.d.ts +18 -19
- package/build/index.js +6 -1393
- package/build/internals.d.ts +1 -2
- package/build/internals.js +1 -3
- package/build/routing-ZHrE7mgA.js +1 -0
- package/build/types-BnnL5f51.d.ts +1 -2
- package/package.json +7 -6
- package/build/routing-DjtQKwsR.js +0 -59
package/build/index.js
CHANGED
|
@@ -1,1394 +1,7 @@
|
|
|
1
|
-
import { n as isVisible, t as evaluateCondition } from "./routing-DjtQKwsR.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import ky from "ky";
|
|
7
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
-
import clsx from "clsx";
|
|
9
|
-
import { Button, Checkbox, CheckboxGroup, FieldError, Input, Label, Radio, RadioGroup, Text, TextArea, TextField, composeRenderProps } from "react-aria-components";
|
|
10
|
-
|
|
11
|
-
//#region src/utils.ts
|
|
12
|
-
function prettifyError(error) {
|
|
13
|
-
return error.issues[0]?.message ?? "Invalid input";
|
|
1
|
+
import{n as e,t}from"./routing-ZHrE7mgA.js";import{ErrorBoundary as n}from"react-error-boundary";import r,{createContext as i,forwardRef as a,useCallback as o,useContext as s,useEffect as c,useMemo as l,useReducer as u,useRef as d,useState as f}from"react";import{useLocalStorage as p,useSessionStorage as m,useTimeout as h}from"usehooks-ts";import{z as g}from"zod/v4/mini";import _ from"ky";import{Fragment as v,jsx as y,jsxs as b}from"react/jsx-runtime";import x from"clsx";import"react-dom";function S(e){return e.issues[0]?.message??`Invalid input`}const C=g.object({type:g.literal(`next`)}),w=g.object({type:g.literal(`end`)}),T=g.object({type:g.literal(`jump`),target:g.number({error:`Target question is required`})}),E=g.discriminatedUnion(`type`,[C,T,w]),D=g.object({type:g.literal(`value`),value:g.union([g.string().check(g.trim(),g.minLength(1,{error:`Value is required`})),g.number({error:`Value is required`})])}),O=g.object({type:g.literal(`binary-operator`),operator:g.union([g.literal(`equal`),g.literal(`not-equal`),g.literal(`greater`),g.literal(`greater-or-equal`),g.literal(`less`),g.literal(`less-or-equal`),g.literal(`contains`),g.literal(`not-contains`)]),value:D,target:E}),ee=g.object({type:g.literal(`switch`),cases:g.array(O),default:E}),k=g.object({type:g.literal(`always`),target:E}),A=g.discriminatedUnion(`type`,[k,ee]),te=g.string().check(g.trim(),g.url({protocol:/^(https|mailto)/,error:`Link must start with https:// or mailto:`})),j=g.optional(g.string().check(g.trim(),g.maxLength(50))),ne=g.object({value:g.string().check(g.trim(),g.minLength(1,{error:`Value is required`})),description:g.optional(g.string().check(g.trim()))}),re=g.nullable(g.object({label:g.string().check(g.trim(),g.minLength(1,{error:`Value is required`})),max:g.number(),description:g.optional(g.string().check(g.trim()))})),ie=g.object({type:g.literal(`rating`),buttonLabel:j,scale:g.number().check(g.minimum(2),g.maximum(10)),labels:g.optional(g.object({lower:g.optional(g.pipe(g.string().check(g.trim()),g.transform(e=>e===``?void 0:e))),upper:g.optional(g.pipe(g.string().check(g.trim()),g.transform(e=>e===``?void 0:e)))})),display:g.optional(g.literal([`star`,`emoji`,`number`]))}),ae=g.object({type:g.literal(`open-ended`),placeholder:g.optional(g.string()),buttonLabel:j,max:g.number()}),oe=g.object({type:g.literal(`single-select`),options:g.array(ne),buttonLabel:j,editable:re}),se=g.object({type:g.literal(`multi-select`),buttonLabel:j,options:g.array(ne),editable:re,max:g.optional(g.number()),display:g.optional(g.literal([`checkbox`,`tag`]))}),ce=g.object({type:g.literal(`statement`),buttonLabel:j,buttonUrl:g.optional(te)}),le=g.discriminatedUnion(`type`,[ie,oe,ae,se,ce]),M=`__CONFETTI_CHECKBOX_Others`,ue=`__CONFETTI_RADIO_Others`,de=e=>g.number().check(g.int(),g.minimum(1),g.maximum(e)),fe=({scale:e},{required:t})=>{let n=de(e);return t?n:g.optional(n)},pe=({maxLength:e},{required:t})=>g.string().check(g.trim(),...t?[g.minLength(1,{error:`This field is required`})]:[],g.maxLength(e??2048,{error:({maximum:e})=>`Please enter less than ${e} characters`})),me=(e,t)=>g.string().check(g.trim(),...t?[g.minLength(1,{error:`This field is required`})]:[],g.maxLength(e??1024,{error:({maximum:e})=>`Please enter less than ${e} characters`}),g.refine(e=>e!==ue,{error:`Please fill out the free text field`})),he=({maxLength:e},{required:t})=>{let n=me(e,t);return t?n:g.optional(n)},ge=({maxSelected:e,maxLength:t},{required:n})=>g.array(g.string().check(g.trim(),...n?[g.minLength(1,{error:`This field is required`})]:[],g.maxLength(t??1024,{error:({maximum:e})=>`Please enter less than ${e} characters`}),g.refine(e=>e!==M,{error:`Please fill out the free text field`}))).check(...n?[g.minLength(1,{error:`Please select at least one option`})]:[],g.maxLength(e??1024,{error:({maximum:e})=>`Please select less than ${e} options`})),_e=()=>g.optional(g.string()),ve=g.object({title:g.string().check(g.trim()),description:g.string().check(g.trim()),buttonText:g.string().check(g.trim())}),ye=g.object({title:g.string(),description:g.nullable(g.string()),questions:g.array(g.object({id:g.string(),title:g.string(),description:g.nullable(g.string()),position:g.number(),required:g.boolean(),properties:le,routingLogic:A})),confirmation:ve});g.object({respondent:g.string().check(g.trim(),g.minLength(1),g.maxLength(2048)),data:g.record(g.string(),g.union([g.string().check(g.trim(),g.maxLength(2048)),g.number(),g.array(g.string().check(g.trim(),g.maxLength(2048))).check(g.maxLength(1024))])),metadata:g.record(g.string().check(g.trim(),g.maxLength(1e3)),g.string().check(g.trim(),g.maxLength(1e3)))});const be=g.object({lastRespondedAt:g.nullable(g.union([g.iso.datetime(),g.date()])),lastViewedAt:g.nullable(g.union([g.iso.datetime(),g.date()])),lastDismissedAt:g.nullable(g.union([g.iso.datetime(),g.date()]))});g.object({type:g.enum([`view`,`dismiss`])});const xe=_.create({prefixUrl:`https://confetti.gov.sg/api`,retry:{limit:3,methods:[`get`]},timeout:6e4}),Se=i(null),Ce=({children:e,surveyId:t,publishableKey:n,respondent:r,metadata:i={},isSurveyVisible:a,apiBaseUrl:s})=>{let u=d(!1),[m,h]=f(),[g,_]=f(!1),[v,b]=f(null),[x,S]=f(null),C=l(()=>crypto.randomUUID(),[]),[w,T]=p(`cfti:${t}:respondent`,``);c(()=>{w||T(crypto.randomUUID())},[w,T]);let E=l(()=>r||w,[r,w]),D=l(()=>{let e={headers:{"x-cfti-pk":n}};return s&&(e.prefixUrl=s),xe.extend(e)},[s,n]),O=o(async()=>{if(!E)return;let e=await D.get(`v1/cfti/${t}/respondent/${E}`).json(),n=be.safeParse(e);n.success&&(b(n.data.lastRespondedAt?new Date(n.data.lastRespondedAt):null),S(n.data.lastDismissedAt?new Date(n.data.lastDismissedAt):null))},[D,E,t]);c(()=>{if(typeof window>`u`||typeof document>`u`)return;let e=()=>{document.visibilityState===`visible`&&O()};return document.addEventListener(`visibilitychange`,e),()=>{document.removeEventListener(`visibilitychange`,e)}},[O]),c(()=>{(async()=>{u.current=!1,_(!1),h(void 0),b(null),S(null);try{let e=await D.get(`v1/cfti/${t}`).json(),n=ye.safeParse(e);if(!n.success)return;h(n.data),await O()}catch{}finally{_(!0)}})()},[D,O,t]);let ee=o(async({answers:e})=>{await D.put(`v1/cfti/${t}/response/${C}`,{json:{respondent:E,data:e,metadata:i}})},[D,i,E,C,t]),k=o(()=>{h(void 0),D.post(`v1/cfti/${t}/respondent/${E}/event`,{json:{type:`dismiss`}}).catch(()=>{})},[D,E,t]),A=l(()=>g?a===void 0?!0:typeof a==`boolean`?a:a({lastRespondedAt:v,lastDismissedAt:x}):!1,[g,a,v,x]);return c(()=>{u.current||A&&m&&E&&(u.current=!0,D.post(`v1/cfti/${t}/respondent/${E}/event`,{json:{type:`view`}}).catch(()=>{}))},[D,A,E,m,t]),!A||!m?null:y(Se.Provider,{value:{submit:ee,dismiss:k,surveyId:t,survey:m,metadata:i},children:e})},we=()=>{let e=s(Se);if(!e)throw Error(`useConfetti must be used within a ConfettiProvider`);return e},Te={rating:({scale:e},t)=>fe({scale:e},t),"open-ended":({max:e},t)=>pe({maxLength:e},t),"single-select":({editable:e},t)=>he({maxLength:e?.max},t),"multi-select":({editable:e,max:t},n)=>ge({maxLength:e?.max,maxSelected:t},n),statement:(e,t)=>_e()},Ee=(e,t)=>{let n=e.type;switch(n){case`rating`:{let r=Te[n];return r(e,t)}case`open-ended`:{let r=Te[n];return r(e,t)}case`single-select`:{let r=Te[n];return r(e,t)}case`multi-select`:{let r=Te[n];return r(e,t)}case`statement`:{let r=Te[n];return r(e,t)}default:throw Error(`Unsupported question type`)}},De=({originalQuestions:t,answers:n,errors:r,pointer:i=-1})=>{if(!t)return{questions:[],currentIndex:-1};let a=t.sort((e,t)=>e.position-t.position).map(e=>{let t={...e},n=r[e.id];return n&&(t.error=n),{...t,visible:!1}});for(let t=0;t<a.length;t++){let r=a[t];if(!r)continue;let o=e({index:t,questions:a,answers:n});r.visible=i===t||o}let o=a.findIndex((e,t)=>t>i&&e.visible&&n[e.id]===void 0);return o===-1&&(o=a.findLastIndex(e=>!!e.visible)),{questions:a,currentIndex:o}},Oe=({questions:e,answers:t})=>Object.fromEntries(Object.entries(t).filter(([t])=>!!e.find(e=>e.id===t)?.visible).filter(([,e])=>e!==null)),ke=({current:e,shouldAutoSubmit:t,onFinished:n,children:r})=>{let{survey:i,submit:a}=we(),[s,c]=f({}),[u,d]=f({}),p=l(()=>De({originalQuestions:i?.questions,answers:s,errors:u,pointer:e}),[i?.questions,s,u,e]),m=l(()=>!!p.questions.filter(({required:e,visible:t})=>!!e&&!!t).every(({id:e})=>s[e]!==void 0),[s,p.questions]),[h,g]=f(!1),_=o(({answers:e})=>{a({answers:e}).finally(()=>{n?.()})},[n,a]),b=o(()=>{_({answers:Oe({questions:p.questions,answers:s})}),g(!0)},[s,p.questions,_]),x=o(({question:n,answer:r})=>{let a=p.questions.at(n);if(!a)return{error:`Question index is invalid`};let o=Ee(a.properties,{required:a.required}).safeParse(r);if(!o.success){let e=S(o.error);return d(t=>{if(t[a.id]===e)return t;let n={...t};return n[a.id]=e,n}),{error:e}}let l=!a.required&&!r?null:r,f={...s};if(f[a.id]===l)return{next:De({originalQuestions:i?.questions,answers:f,errors:u,pointer:e}).currentIndex};f[a.id]=l,c(f);let m=De({originalQuestions:i?.questions,answers:f,errors:u,pointer:e});return m.questions.filter(({visible:e})=>!!e).every(({id:e})=>f[e]!==void 0)&&t&&(_({answers:Oe({questions:m.questions,answers:f})}),g(!0)),{next:m.currentIndex}},[p.questions,s,i?.questions,u,t,e,_]);return p.questions.length===0?y(v,{}):y(`div`,{className:`confetti`,children:r({questions:p.questions,current:e??p.currentIndex,update:x,isCompleted:m,submit:b,isSubmitted:h,errors:u})})},Ae=({children:e,onFinished:t,shouldAutoSubmit:r,...i})=>y(n,{fallback:y(v,{}),children:y(Ce,{...i,children:y(ke,{shouldAutoSubmit:r,onFinished:t,children:e})})}),je=i(null);i(null),i(null),i(null),i(null),i({}),i(null);const Me=i(null),N=typeof document<`u`?r.useLayoutEffect:()=>{};function Ne(e){let[t,n]=f(e),r=d(t),i=d(null),a=d(()=>{if(!i.current)return;let e=i.current.next();if(e.done){i.current=null;return}r.current===e.value?a.current():n(e.value)});return N(()=>{r.current=t,i.current&&a.current()}),[t,o(e=>{i.current=e(r.current),a.current()},[a])]}const Pe={prefix:String(Math.round(Math.random()*1e10)),current:0},Fe=r.createContext(Pe),Ie=r.createContext(!1);typeof window<`u`&&window.document&&window.document.createElement;let Le=new WeakMap;function Re(e=!1){let t=s(Fe),n=d(null);if(n.current===null&&!e){let e=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED?.ReactCurrentOwner?.current;if(e){let n=Le.get(e);n==null?Le.set(e,{id:t.current,state:e.memoizedState}):e.memoizedState!==n.state&&(t.current=n.id,Le.delete(e))}n.current=++t.current}return n.current}function ze(e){let t=s(Fe),n=Re(!!e),r=`react-aria${t.prefix}`;return e||`${r}-${n}`}function Be(e){let t=r.useId(),[n]=f(Ge()),i=n?`react-aria`:`react-aria${Pe.prefix}`;return e||`${i}-${t}`}const Ve=typeof r.useId==`function`?Be:ze;function He(){return!1}function Ue(){return!0}function We(e){return()=>{}}function Ge(){return typeof r.useSyncExternalStore==`function`?r.useSyncExternalStore(We,He,Ue):s(Ie)}let Ke=!!(typeof window<`u`&&window.document&&window.document.createElement),P=new Map,qe;typeof FinalizationRegistry<`u`&&(qe=new FinalizationRegistry(e=>{P.delete(e)}));function F(e){let[t,n]=f(e),r=d(null),i=Ve(t),a=d(null);if(qe&&qe.register(a,i),Ke){let e=P.get(i);e&&!e.includes(r)?e.push(r):P.set(i,[r])}return N(()=>{let e=i;return()=>{qe&&qe.unregister(a),P.delete(e)}},[i]),c(()=>{let e=r.current;return e&&n(e),()=>{e&&(r.current=null)}}),i}function Je(e,t){if(e===t)return e;let n=P.get(e);if(n)return n.forEach(e=>e.current=t),t;let r=P.get(t);return r?(r.forEach(t=>t.current=e),e):t}function Ye(e=[]){let t=F(),[n,r]=Ne(t),i=o(()=>{r(function*(){yield t,yield document.getElementById(t)?t:void 0})},[t,r]);return N(i,[t,i,...e]),n}function Xe(...e){return(...t)=>{for(let n of e)typeof n==`function`&&n(...t)}}const I=e=>e?.ownerDocument??document,L=e=>e&&`window`in e&&e.window===e?e:I(e).defaultView||window;function Ze(e){return typeof e==`object`&&!!e&&`nodeType`in e&&typeof e.nodeType==`number`}function Qe(e){return Ze(e)&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&`host`in e}function $e(){return!1}function R(e,t){if(!$e())return t&&e?e.contains(t):!1;if(!e||!t)return!1;let n=t;for(;n!==null;){if(n===e)return!0;n=n.tagName===`SLOT`&&n.assignedSlot?n.assignedSlot.parentNode:Qe(n)?n.host:n.parentNode}return!1}const et=(e=document)=>{if(!$e())return e.activeElement;let t=e.activeElement;for(;t&&`shadowRoot`in t&&t.shadowRoot?.activeElement;)t=t.shadowRoot.activeElement;return t};function z(e){return $e()&&e.target.shadowRoot&&e.composedPath?e.composedPath()[0]:e.target}var tt=class{get currentNode(){return this._currentNode}set currentNode(e){if(!R(this.root,e))throw Error(`Cannot set currentNode to a node that is not contained by the root node.`);let t=[],n=e,r=e;for(this._currentNode=e;n&&n!==this.root;)if(n.nodeType===Node.DOCUMENT_FRAGMENT_NODE){let e=n,i=this._doc.createTreeWalker(e,this.whatToShow,{acceptNode:this._acceptNode});t.push(i),i.currentNode=r,this._currentSetFor.add(i),n=r=e.host}else n=n.parentNode;let i=this._doc.createTreeWalker(this.root,this.whatToShow,{acceptNode:this._acceptNode});t.push(i),i.currentNode=r,this._currentSetFor.add(i),this._walkerStack=t}get doc(){return this._doc}firstChild(){let e=this.currentNode,t=this.nextNode();return R(e,t)?(t&&(this.currentNode=t),t):(this.currentNode=e,null)}lastChild(){let e=this._walkerStack[0].lastChild();return e&&(this.currentNode=e),e}nextNode(){let e=this._walkerStack[0].nextNode();if(e){if(e.shadowRoot){let t;if(typeof this.filter==`function`?t=this.filter(e):this.filter?.acceptNode&&(t=this.filter.acceptNode(e)),t===NodeFilter.FILTER_ACCEPT)return this.currentNode=e,e;let n=this.nextNode();return n&&(this.currentNode=n),n}return e&&(this.currentNode=e),e}else if(this._walkerStack.length>1){this._walkerStack.shift();let e=this.nextNode();return e&&(this.currentNode=e),e}else return null}previousNode(){let e=this._walkerStack[0];if(e.currentNode===e.root){if(this._currentSetFor.has(e))if(this._currentSetFor.delete(e),this._walkerStack.length>1){this._walkerStack.shift();let e=this.previousNode();return e&&(this.currentNode=e),e}else return null;return null}let t=e.previousNode();if(t){if(t.shadowRoot){let e;if(typeof this.filter==`function`?e=this.filter(t):this.filter?.acceptNode&&(e=this.filter.acceptNode(t)),e===NodeFilter.FILTER_ACCEPT)return t&&(this.currentNode=t),t;let n=this.lastChild();return n&&(this.currentNode=n),n}return t&&(this.currentNode=t),t}else if(this._walkerStack.length>1){this._walkerStack.shift();let e=this.previousNode();return e&&(this.currentNode=e),e}else return null}nextSibling(){return null}previousSibling(){return null}parentNode(){return null}constructor(e,t,n,r){this._walkerStack=[],this._currentSetFor=new Set,this._acceptNode=e=>{if(e.nodeType===Node.ELEMENT_NODE){let t=e.shadowRoot;if(t){let e=this._doc.createTreeWalker(t,this.whatToShow,{acceptNode:this._acceptNode});return this._walkerStack.unshift(e),NodeFilter.FILTER_ACCEPT}else{if(typeof this.filter==`function`)return this.filter(e);if(this.filter?.acceptNode)return this.filter.acceptNode(e);if(this.filter===null)return NodeFilter.FILTER_ACCEPT}}return NodeFilter.FILTER_SKIP},this._doc=e,this.root=t,this.filter=r??null,this.whatToShow=n??NodeFilter.SHOW_ALL,this._currentNode=t,this._walkerStack.unshift(e.createTreeWalker(t,n,this._acceptNode));let i=t.shadowRoot;if(i){let e=this._doc.createTreeWalker(i,this.whatToShow,{acceptNode:this._acceptNode});this._walkerStack.unshift(e)}}};function nt(e,t,n,r){return $e()?new tt(e,t,n,r):e.createTreeWalker(t,n,r)}function B(...e){let t={...e[0]};for(let n=1;n<e.length;n++){let r=e[n];for(let e in r){let n=t[e],i=r[e];typeof n==`function`&&typeof i==`function`&&e[0]===`o`&&e[1]===`n`&&e.charCodeAt(2)>=65&&e.charCodeAt(2)<=90?t[e]=Xe(n,i):(e===`className`||e===`UNSAFE_className`)&&typeof n==`string`&&typeof i==`string`?t[e]=x(n,i):e===`id`&&n&&i?t.id=Je(n,i):t[e]=i===void 0?n:i}}return t}function rt(...e){return e.length===1&&e[0]?e[0]:t=>{let n=!1,r=e.map(e=>{let r=it(e,t);return n||=typeof r==`function`,r});if(n)return()=>{r.forEach((t,n)=>{typeof t==`function`?t():it(e[n],null)})}}}function it(e,t){if(typeof e==`function`)return e(t);e!=null&&(e.current=t)}const at=new Set([`id`]),ot=new Set([`aria-label`,`aria-labelledby`,`aria-describedby`,`aria-details`]),st=new Set([`href`,`hrefLang`,`target`,`rel`,`download`,`ping`,`referrerPolicy`]),ct=new Set([`dir`,`lang`,`hidden`,`inert`,`translate`]),lt=new Set(`onClick.onAuxClick.onContextMenu.onDoubleClick.onMouseDown.onMouseEnter.onMouseLeave.onMouseMove.onMouseOut.onMouseOver.onMouseUp.onTouchCancel.onTouchEnd.onTouchMove.onTouchStart.onPointerDown.onPointerMove.onPointerUp.onPointerCancel.onPointerEnter.onPointerLeave.onPointerOver.onPointerOut.onGotPointerCapture.onLostPointerCapture.onScroll.onWheel.onAnimationStart.onAnimationEnd.onAnimationIteration.onTransitionCancel.onTransitionEnd.onTransitionRun.onTransitionStart`.split(`.`)),ut=/^(data-.*)$/;function V(e,t={}){let{labelable:n,isLink:r,global:i,events:a=i,propNames:o}=t,s={};for(let t in e)Object.prototype.hasOwnProperty.call(e,t)&&(at.has(t)||n&&ot.has(t)||r&&st.has(t)||i&&ct.has(t)||a&&(lt.has(t)||t.endsWith(`Capture`)&<.has(t.slice(0,-7)))||o?.has(t)||ut.test(t))&&(s[t]=e[t]);return s}function dt(e){if(pt())e.focus({preventScroll:!0});else{let t=mt(e);e.focus(),ht(t)}}let ft=null;function pt(){if(ft==null){ft=!1;try{document.createElement(`div`).focus({get preventScroll(){return ft=!0,!0}})}catch{}}return ft}function mt(e){let t=e.parentNode,n=[],r=document.scrollingElement||document.documentElement;for(;t instanceof HTMLElement&&t!==r;)(t.offsetHeight<t.scrollHeight||t.offsetWidth<t.scrollWidth)&&n.push({element:t,scrollTop:t.scrollTop,scrollLeft:t.scrollLeft}),t=t.parentNode;return r instanceof HTMLElement&&n.push({element:r,scrollTop:r.scrollTop,scrollLeft:r.scrollLeft}),n}function ht(e){for(let{element:t,scrollTop:n,scrollLeft:r}of e)t.scrollTop=n,t.scrollLeft=r}function gt(e){if(typeof window>`u`||window.navigator==null)return!1;let t=window.navigator.userAgentData?.brands;return Array.isArray(t)&&t.some(t=>e.test(t.brand))||e.test(window.navigator.userAgent)}function _t(e){return typeof window<`u`&&window.navigator!=null?e.test(window.navigator.userAgentData?.platform||window.navigator.platform):!1}function H(e){let t=null;return()=>(t??=e(),t)}const vt=H(function(){return _t(/^Mac/i)}),yt=H(function(){return _t(/^iPhone/i)}),bt=H(function(){return _t(/^iPad/i)||vt()&&navigator.maxTouchPoints>1}),xt=H(function(){return yt()||bt()}),St=H(function(){return gt(/AppleWebKit/i)&&!Ct()}),Ct=H(function(){return gt(/Chrome/i)}),wt=H(function(){return gt(/Android/i)}),Tt=H(function(){return gt(/Firefox/i)});function U(e,t,n=!0){var r;let{metaKey:i,ctrlKey:a,altKey:o,shiftKey:s}=t;Tt()&&(r=window.event)!=null&&r.type?.startsWith(`key`)&&e.target===`_blank`&&(vt()?i=!0:a=!0);let c=St()&&vt()&&!bt()?new KeyboardEvent(`keydown`,{keyIdentifier:`Enter`,metaKey:i,ctrlKey:a,altKey:o,shiftKey:s}):new MouseEvent(`click`,{metaKey:i,ctrlKey:a,altKey:o,shiftKey:s,detail:1,bubbles:!0,cancelable:!0});U.isOpening=n,dt(e),e.dispatchEvent(c),U.isOpening=!1}U.isOpening=!1;let W=new Map,Et=new Set;function Dt(){if(typeof window>`u`)return;function e(e){return`propertyName`in e}let t=t=>{if(!e(t)||!t.target)return;let r=W.get(t.target);r||(r=new Set,W.set(t.target,r),t.target.addEventListener(`transitioncancel`,n,{once:!0})),r.add(t.propertyName)},n=t=>{if(!e(t)||!t.target)return;let r=W.get(t.target);if(r&&(r.delete(t.propertyName),r.size===0&&(t.target.removeEventListener(`transitioncancel`,n),W.delete(t.target)),W.size===0)){for(let e of Et)e();Et.clear()}};document.body.addEventListener(`transitionrun`,t),document.body.addEventListener(`transitionend`,n)}typeof document<`u`&&(document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,Dt):Dt());function Ot(){for(let[e]of W)`isConnected`in e&&!e.isConnected&&W.delete(e)}function kt(e){requestAnimationFrame(()=>{Ot(),W.size===0?e():Et.add(e)})}function At(){let e=d(new Map),t=o((t,n,r,i)=>{let a=i?.once?(...t)=>{e.current.delete(r),r(...t)}:r;e.current.set(r,{type:n,eventTarget:t,fn:a,options:i}),t.addEventListener(n,a,i)},[]),n=o((t,n,r,i)=>{let a=e.current.get(r)?.fn||r;t.removeEventListener(n,a,i),e.current.delete(r)},[]),r=o(()=>{e.current.forEach((e,t)=>{n(e.eventTarget,e.type,t,e.options)})},[n]);return c(()=>r,[r]),{addGlobalListener:t,removeGlobalListener:n,removeAllGlobalListeners:r}}function jt(e,t){let{id:n,"aria-label":r,"aria-labelledby":i}=e;return n=F(n),i&&r?i=[...new Set([n,...i.trim().split(/\s+/)])].join(` `):i&&=i.trim().split(/\s+/).join(` `),!r&&!i&&t&&(r=t),{id:n,"aria-label":r,"aria-labelledby":i}}function Mt(e){let t=d(null),n=d(void 0),r=o(t=>{if(typeof e==`function`){let n=e,r=n(t);return()=>{typeof r==`function`?r():n(null)}}else if(e)return e.current=t,()=>{e.current=null}},[e]);return l(()=>({get current(){return t.current},set current(e){t.current=e,n.current&&=(n.current(),void 0),e!=null&&(n.current=r(e))}}),[r])}const Nt=r.useInsertionEffect??N;function G(e){let t=d(null);return Nt(()=>{t.current=e},[e]),o((...e)=>{let n=t.current;return n?.(...e)},[])}function Pt(e,t){N(()=>{if(e&&e.ref&&t)return e.ref.current=t.current,()=>{e.ref&&(e.ref.current=null)}})}function Ft(e){return e.pointerType===``&&e.isTrusted?!0:wt()&&e.pointerType?e.type===`click`&&e.buttons===1:e.detail===0&&!e.pointerType}function It(e){return!wt()&&e.width===0&&e.height===0||e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType===`mouse`}function Lt(e,t,n){let r=G(()=>{n&&n(t)});c(()=>{let t=e?.current?.form;return t?.addEventListener(`reset`,r),()=>{t?.removeEventListener(`reset`,r)}},[e])}const Rt=typeof Element<`u`&&`checkVisibility`in Element.prototype;function zt(e){let t=L(e);if(!(e instanceof t.HTMLElement)&&!(e instanceof t.SVGElement))return!1;let{display:n,visibility:r}=e.style,i=n!==`none`&&r!==`hidden`&&r!==`collapse`;if(i){let{getComputedStyle:t}=e.ownerDocument.defaultView,{display:n,visibility:r}=t(e);i=n!==`none`&&r!==`hidden`&&r!==`collapse`}return i}function Bt(e,t){return!e.hasAttribute(`hidden`)&&!e.hasAttribute(`data-react-aria-prevent-focus`)&&(e.nodeName===`DETAILS`&&t&&t.nodeName!==`SUMMARY`?e.hasAttribute(`open`):!0)}function Vt(e,t){return Rt?e.checkVisibility({visibilityProperty:!0})&&!e.closest(`[data-react-aria-prevent-focus]`):e.nodeName!==`#comment`&&zt(e)&&Bt(e,t)&&(!e.parentElement||Vt(e.parentElement,e))}const Ht=[`input:not([disabled]):not([type=hidden])`,`select:not([disabled])`,`textarea:not([disabled])`,`button:not([disabled])`,`a[href]`,`area[href]`,`summary`,`iframe`,`object`,`embed`,`audio[controls]`,`video[controls]`,`[contenteditable]:not([contenteditable^="false"])`,`permission`],Ut=Ht.join(`:not([hidden]),`)+`,[tabindex]:not([disabled]):not([hidden])`;Ht.push(`[tabindex]:not([tabindex="-1"]):not([disabled])`);const Wt=Ht.join(`:not([hidden]):not([tabindex="-1"]),`);function Gt(e){return e.matches(Ut)&&Vt(e)&&!qt(e)}function Kt(e){return e.matches(Wt)&&Vt(e)&&!qt(e)}function qt(e){let t=e;for(;t!=null;){if(t instanceof t.ownerDocument.defaultView.HTMLElement&&t.inert)return!0;t=t.parentElement}return!1}const Jt=typeof document<`u`?r.useInsertionEffect??r.useLayoutEffect:()=>{};function Yt(e,t,n){let[r,i]=f(e||t),a=d(r),s=d(e!==void 0),l=e!==void 0;c(()=>{s.current,s.current=l},[l]);let p=l?e:r;Jt(()=>{a.current=p});let[,m]=u(()=>({}),{});return[p,o((e,...t)=>{let r=typeof e==`function`?e(a.current):e;Object.is(a.current,r)||(a.current=r,i(r),m(),n?.(r,...t))},[n])]}const Xt=Symbol(`default`);function Zt({values:e,children:t}){for(let[n,i]of e)t=r.createElement(n.Provider,{value:i},t);return t}function K(e){let{className:t,style:n,children:r,defaultClassName:i,defaultChildren:a,defaultStyle:o,values:s}=e;return l(()=>{let e,c,l;return e=typeof t==`function`?t({...s,defaultClassName:i}):t,c=typeof n==`function`?n({...s,defaultStyle:o||{}}):n,l=typeof r==`function`?r({...s,defaultChildren:a}):r??a,{className:e??i,style:c||o?{...o,...c}:void 0,children:l??a,"data-rac":``}},[t,n,r,i,a,o,s])}function Qt(e,t){return n=>t(typeof e==`function`?e(n):e,n)}function $t(e,t){let n=s(e);if(t===null)return null;if(n&&typeof n==`object`&&`slots`in n&&n.slots){let e=t||Xt;if(!n.slots[e]){let e=new Intl.ListFormat().format(Object.keys(n.slots).map(e=>`"${e}"`)),r=t?`Invalid slot "${t}".`:`A slot prop is required.`;throw Error(`${r} Valid slot names are ${e}.`)}return n.slots[e]}return n}function q(e,t,n){let{ref:r,...i}=$t(n,e.slot)||{},a=Mt(l(()=>rt(t,r),[t,r])),o=B(i,e);return`style`in i&&i.style&&`style`in e&&e.style&&(typeof i.style==`function`||typeof e.style==`function`?o.style=t=>{let n=typeof i.style==`function`?i.style(t):i.style,r={...t.defaultStyle,...n},a=typeof e.style==`function`?e.style({...t,defaultStyle:r}):e.style;return{...r,...a}}:o.style={...i.style,...e.style}),[o,a]}function en(e=!0){let[t,n]=f(e),r=d(!1),i=o(e=>{r.current=!0,n(!!e)},[]);return N(()=>{r.current||n(!1)},[]),[i,t]}function tn(e){let t=/^(data-.*)$/,n={};for(let r in e)t.test(r)||(n[r]=e[r]);return n}const nn=7e3;let J=null;function rn(e,t=`assertive`,n=nn){J?J.announce(e,t,n):(J=new an,(typeof IS_REACT_ACT_ENVIRONMENT==`boolean`?IS_REACT_ACT_ENVIRONMENT:typeof jest<`u`)?J.announce(e,t,n):setTimeout(()=>{J?.isAttached()&&J?.announce(e,t,n)},100))}var an=class{isAttached(){return this.node?.isConnected}createLog(e){let t=document.createElement(`div`);return t.setAttribute(`role`,`log`),t.setAttribute(`aria-live`,e),t.setAttribute(`aria-relevant`,`additions`),t}destroy(){this.node&&=(document.body.removeChild(this.node),null)}announce(e,t=`assertive`,n=nn){var r,i;if(!this.node)return;let a=document.createElement(`div`);typeof e==`object`?(a.setAttribute(`role`,`img`),a.setAttribute(`aria-labelledby`,e[`aria-labelledby`])):a.textContent=e,t===`assertive`?(r=this.assertiveLog)==null||r.appendChild(a):(i=this.politeLog)==null||i.appendChild(a),e!==``&&setTimeout(()=>{a.remove()},n)}clear(e){this.node&&((!e||e===`assertive`)&&this.assertiveLog&&(this.assertiveLog.innerHTML=``),(!e||e===`polite`)&&this.politeLog&&(this.politeLog.innerHTML=``))}constructor(){this.node=null,this.assertiveLog=null,this.politeLog=null,typeof document<`u`&&(this.node=document.createElement(`div`),this.node.dataset.liveAnnouncer=`true`,Object.assign(this.node.style,{border:0,clip:`rect(0 0 0 0)`,clipPath:`inset(50%)`,height:`1px`,margin:`-1px`,overflow:`hidden`,padding:0,position:`absolute`,width:`1px`,whiteSpace:`nowrap`}),this.assertiveLog=this.createLog(`assertive`),this.node.appendChild(this.assertiveLog),this.politeLog=this.createLog(`polite`),this.node.appendChild(this.politeLog),document.body.prepend(this.node))}};const on=new Set([`Arab`,`Syrc`,`Samr`,`Mand`,`Thaa`,`Mend`,`Nkoo`,`Adlm`,`Rohg`,`Hebr`]),sn=new Set([`ae`,`ar`,`arc`,`bcc`,`bqi`,`ckb`,`dv`,`fa`,`glk`,`he`,`ku`,`mzn`,`nqo`,`pnb`,`ps`,`sd`,`ug`,`ur`,`yi`]);function cn(e){if(Intl.Locale){let t=new Intl.Locale(e).maximize(),n=typeof t.getTextInfo==`function`?t.getTextInfo():t.textInfo;if(n)return n.direction===`rtl`;if(t.script)return on.has(t.script)}let t=e.split(`-`)[0];return sn.has(t)}const ln=Symbol.for(`react-aria.i18n.locale`);function un(){let e=typeof window<`u`&&window[ln]||typeof navigator<`u`&&(navigator.language||navigator.userLanguage)||`en-US`;try{Intl.DateTimeFormat.supportedLocalesOf([e])}catch{e=`en-US`}return{locale:e,direction:cn(e)?`rtl`:`ltr`}}let dn=un(),fn=new Set;function pn(){dn=un();for(let e of fn)e(dn)}function mn(){let e=Ge(),[t,n]=f(dn);return c(()=>(fn.size===0&&window.addEventListener(`languagechange`,pn),fn.add(n),()=>{fn.delete(n),fn.size===0&&window.removeEventListener(`languagechange`,pn)}),[]),e?{locale:typeof window<`u`&&window[ln]||`en-US`,direction:`ltr`}:t}const hn=r.createContext(null);function gn(){let e=mn();return s(hn)||e}function _n(e,t){if(t.has(e))throw TypeError(`Cannot initialize the same private elements twice on an object`)}function vn(e,t,n){_n(e,t),t.set(e,n)}function yn(e){let t=e;return t.nativeEvent=e,t.isDefaultPrevented=()=>t.defaultPrevented,t.isPropagationStopped=()=>t.cancelBubble,t.persist=()=>{},t}function bn(e,t){Object.defineProperty(e,`target`,{value:t}),Object.defineProperty(e,`currentTarget`,{value:t})}function xn(e){let t=d({isFocused:!1,observer:null});return N(()=>{let e=t.current;return()=>{e.observer&&=(e.observer.disconnect(),null)}},[]),o(n=>{if(n.target instanceof HTMLButtonElement||n.target instanceof HTMLInputElement||n.target instanceof HTMLTextAreaElement||n.target instanceof HTMLSelectElement){t.current.isFocused=!0;let r=n.target;r.addEventListener(`focusout`,n=>{if(t.current.isFocused=!1,r.disabled){let t=yn(n);e?.(t)}t.current.observer&&(t.current.observer.disconnect(),t.current.observer=null)},{once:!0}),t.current.observer=new MutationObserver(()=>{if(t.current.isFocused&&r.disabled){var e;(e=t.current.observer)==null||e.disconnect();let n=r===document.activeElement?null:document.activeElement;r.dispatchEvent(new FocusEvent(`blur`,{relatedTarget:n})),r.dispatchEvent(new FocusEvent(`focusout`,{bubbles:!0,relatedTarget:n}))}}),t.current.observer.observe(r,{attributes:!0,attributeFilter:[`disabled`]})}},[e])}let Sn=!1;function Cn(e){for(;e&&!Gt(e);)e=e.parentElement;let t=L(e),n=t.document.activeElement;if(!n||n===e)return;Sn=!0;let r=!1,i=e=>{(e.target===n||r)&&e.stopImmediatePropagation()},a=t=>{(t.target===n||r)&&(t.stopImmediatePropagation(),!e&&!r&&(r=!0,dt(n),c()))},o=t=>{(t.target===e||r)&&t.stopImmediatePropagation()},s=t=>{(t.target===e||r)&&(t.stopImmediatePropagation(),r||(r=!0,dt(n),c()))};t.addEventListener(`blur`,i,!0),t.addEventListener(`focusout`,a,!0),t.addEventListener(`focusin`,s,!0),t.addEventListener(`focus`,o,!0);let c=()=>{cancelAnimationFrame(l),t.removeEventListener(`blur`,i,!0),t.removeEventListener(`focusout`,a,!0),t.removeEventListener(`focusin`,s,!0),t.removeEventListener(`focus`,o,!0),Sn=!1,r=!1},l=requestAnimationFrame(c);return c}let Y=`default`,wn=``,Tn=new WeakMap;function En(e){if(xt()){if(Y===`default`){let t=I(e);wn=t.documentElement.style.webkitUserSelect,t.documentElement.style.webkitUserSelect=`none`}Y=`disabled`}else if(e instanceof HTMLElement||e instanceof SVGElement){let t=`userSelect`in e.style?`userSelect`:`webkitUserSelect`;Tn.set(e,e.style[t]),e.style[t]=`none`}}function Dn(e){if(xt()){if(Y!==`disabled`)return;Y=`restoring`,setTimeout(()=>{kt(()=>{if(Y===`restoring`){let t=I(e);t.documentElement.style.webkitUserSelect===`none`&&(t.documentElement.style.webkitUserSelect=wn||``),wn=``,Y=`default`}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&e&&Tn.has(e)){let t=Tn.get(e),n=`userSelect`in e.style?`userSelect`:`webkitUserSelect`;e.style[n]===`none`&&(e.style[n]=t),e.getAttribute(`style`)===``&&e.removeAttribute(`style`),Tn.delete(e)}}const On=r.createContext({register:()=>{}});On.displayName=`PressResponderContext`;function kn(e,t){return t.get?t.get.call(e):t.value}function An(e,t,n){if(!t.has(e))throw TypeError(`attempted to `+n+` private field on non-instance`);return t.get(e)}function jn(e,t){return kn(e,An(e,t,`get`))}function Mn(e,t,n){if(t.set)t.set.call(e,n);else{if(!t.writable)throw TypeError(`attempted to set read only private field`);t.value=n}}function Nn(e,t,n){return Mn(e,An(e,t,`set`),n),n}function Pn(e){let t=s(On);if(t){let{register:n,...r}=t;e=B(r,e),n()}return Pt(t,e.ref),e}var Fn=new WeakMap,In=class{continuePropagation(){Nn(this,Fn,!1)}get shouldStopPropagation(){return jn(this,Fn)}constructor(e,t,n,r){vn(this,Fn,{writable:!0,value:void 0}),Nn(this,Fn,!0);let i=(r?.target??n.currentTarget)?.getBoundingClientRect(),a,o=0,s,c=null;n.clientX!=null&&n.clientY!=null&&(s=n.clientX,c=n.clientY),i&&(s!=null&&c!=null?(a=s-i.left,o=c-i.top):(a=i.width/2,o=i.height/2)),this.type=e,this.pointerType=t,this.target=n.currentTarget,this.shiftKey=n.shiftKey,this.metaKey=n.metaKey,this.ctrlKey=n.ctrlKey,this.altKey=n.altKey,this.x=a,this.y=o}};const Ln=Symbol(`linkClicked`),Rn=`react-aria-pressable-style`,zn=`data-react-aria-pressable`;function X(e){let{onPress:t,onPressChange:n,onPressStart:r,onPressEnd:i,onPressUp:a,onClick:s,isDisabled:u,isPressed:p,preventFocusOnPress:m,shouldCancelOnPointerExit:h,allowTextSelectionOnPress:g,ref:_,...v}=Pn(e),[y,b]=f(!1),x=d({isPressed:!1,ignoreEmulatedMouseEvents:!1,didFirePressStart:!1,isTriggeringEvent:!1,activePointerId:null,target:null,isOverTarget:!1,pointerType:null,disposables:[]}),{addGlobalListener:S,removeAllGlobalListeners:C,removeGlobalListener:w}=At(),T=o((e,t)=>{let i=x.current;if(u||i.didFirePressStart)return!1;let a=!0;if(i.isTriggeringEvent=!0,r){let n=new In(`pressstart`,t,e);r(n),a=n.shouldStopPropagation}return n&&n(!0),i.isTriggeringEvent=!1,i.didFirePressStart=!0,b(!0),a},[u,r,n]),E=o((e,r,a=!0)=>{let o=x.current;if(!o.didFirePressStart)return!1;o.didFirePressStart=!1,o.isTriggeringEvent=!0;let s=!0;if(i){let t=new In(`pressend`,r,e);i(t),s=t.shouldStopPropagation}if(n&&n(!1),b(!1),t&&a&&!u){let n=new In(`press`,r,e);t(n),s&&=n.shouldStopPropagation}return o.isTriggeringEvent=!1,s},[u,i,n,t]),D=G(E),O=o((e,t)=>{let n=x.current;if(u)return!1;if(a){n.isTriggeringEvent=!0;let r=new In(`pressup`,t,e);return a(r),n.isTriggeringEvent=!1,r.shouldStopPropagation}return!0},[u,a]),ee=G(O),k=o(e=>{let t=x.current;if(t.isPressed&&t.target){t.didFirePressStart&&t.pointerType!=null&&E(Z(t.target,e),t.pointerType,!1),t.isPressed=!1,se(null),t.isOverTarget=!1,t.activePointerId=null,t.pointerType=null,C(),g||Dn(t.target);for(let e of t.disposables)e();t.disposables=[]}},[g,C,E]),A=G(k),te=o(e=>{h&&k(e)},[h,k]),j=o(e=>{u||s?.(e)},[u,s]),ne=o((e,t)=>{if(!u&&s){let n=new MouseEvent(`click`,e);bn(n,t),s(yn(n))}},[u,s]),re=G(ne),[ie,ae]=f(!1);N(()=>{let e=x.current;if(ie){let t=t=>{if(e.isPressed&&e.target&&Vn(t,e.target)){var n;Un(z(t),t.key)&&t.preventDefault();let r=z(t),i=R(e.target,z(t));D(Z(e.target,t),`keyboard`,i),i&&re(t,e.target),C(),t.key!==`Enter`&&Bn(e.target)&&R(e.target,r)&&!t[Ln]&&(t[Ln]=!0,U(e.target,t,!1)),e.isPressed=!1,ae(!1),(n=e.metaKeyEvents)==null||n.delete(t.key)}else if(t.key===`Meta`&&e.metaKeyEvents?.size){var r;let t=e.metaKeyEvents;e.metaKeyEvents=void 0;for(let n of t.values())(r=e.target)==null||r.dispatchEvent(new KeyboardEvent(`keyup`,n))}},n=e.target,r=Xe(t=>{n&&Vn(t,n)&&!t.repeat&&R(n,z(t))&&e.target&&ee(Z(e.target,t),`keyboard`)},t);return S(I(e.target),`keyup`,r,!0),()=>{w(I(e.target),`keyup`,r,!0)}}},[ie,S,C,w]);let[oe,se]=f(null);N(()=>{let e=x.current;if(oe===`pointer`){let t=t=>{if(t.pointerId===e.activePointerId&&e.isPressed&&t.button===0&&e.target){if(R(e.target,z(t))&&e.pointerType!=null){let n=!1,r=setTimeout(()=>{e.isPressed&&e.target instanceof HTMLElement&&(n?A(t):(dt(e.target),e.target.click()))},80);S(t.currentTarget,`click`,()=>n=!0,!0),e.disposables.push(()=>clearTimeout(r))}else A(t);e.isOverTarget=!1}},n=e=>{A(e)};return S(I(e.target),`pointerup`,t,!1),S(I(e.target),`pointercancel`,n,!1),()=>{w(I(e.target),`pointerup`,t,!1),w(I(e.target),`pointercancel`,n,!1)}}},[oe,S,w]);let ce=l(()=>{let e=x.current,t={onKeyDown(t){if(Vn(t.nativeEvent,t.currentTarget)&&R(t.currentTarget,z(t.nativeEvent))){var n;Un(z(t.nativeEvent),t.key)&&t.preventDefault();let r=!0;!e.isPressed&&!t.repeat&&(e.target=t.currentTarget,e.isPressed=!0,ae(!0),e.pointerType=`keyboard`,r=T(t,`keyboard`)),r&&t.stopPropagation(),t.metaKey&&vt()&&((n=e.metaKeyEvents)==null||n.set(t.key,t.nativeEvent))}else t.key===`Meta`&&(e.metaKeyEvents=new Map)},onClick(t){if(!(t&&!R(t.currentTarget,z(t.nativeEvent)))&&t&&t.button===0&&!e.isTriggeringEvent&&!U.isOpening){let n=!0;if(u&&t.preventDefault(),!e.ignoreEmulatedMouseEvents&&!e.isPressed&&(e.pointerType===`virtual`||Ft(t.nativeEvent))){let e=T(t,`virtual`),r=O(t,`virtual`),i=E(t,`virtual`);j(t),n=e&&r&&i}else if(e.isPressed&&e.pointerType!==`keyboard`){let r=e.pointerType||t.nativeEvent.pointerType||`virtual`,i=O(Z(t.currentTarget,t),r),a=E(Z(t.currentTarget,t),r,!0);n=i&&a,e.isOverTarget=!1,j(t),k(t)}e.ignoreEmulatedMouseEvents=!1,n&&t.stopPropagation()}}};return typeof PointerEvent<`u`&&(t.onPointerDown=t=>{if(t.button!==0||!R(t.currentTarget,z(t.nativeEvent)))return;if(It(t.nativeEvent)){e.pointerType=`virtual`;return}e.pointerType=t.pointerType;let n=!0;if(!e.isPressed){e.isPressed=!0,se(`pointer`),e.isOverTarget=!0,e.activePointerId=t.pointerId,e.target=t.currentTarget,g||En(e.target),n=T(t,e.pointerType);let r=z(t.nativeEvent);`releasePointerCapture`in r&&r.releasePointerCapture(t.pointerId)}n&&t.stopPropagation()},t.onMouseDown=t=>{if(R(t.currentTarget,z(t.nativeEvent))&&t.button===0){if(m){let n=Cn(t.target);n&&e.disposables.push(n)}t.stopPropagation()}},t.onPointerUp=t=>{!R(t.currentTarget,z(t.nativeEvent))||e.pointerType===`virtual`||t.button===0&&!e.isPressed&&O(t,e.pointerType||t.pointerType)},t.onPointerEnter=t=>{t.pointerId===e.activePointerId&&e.target&&!e.isOverTarget&&e.pointerType!=null&&(e.isOverTarget=!0,T(Z(e.target,t),e.pointerType))},t.onPointerLeave=t=>{t.pointerId===e.activePointerId&&e.target&&e.isOverTarget&&e.pointerType!=null&&(e.isOverTarget=!1,E(Z(e.target,t),e.pointerType,!1),te(t))},t.onDragStart=e=>{R(e.currentTarget,z(e.nativeEvent))&&k(e)}),t},[u,m,C,g,k,te,E,T,O,j,ne]);return c(()=>{if(!_)return;let e=I(_.current);if(!e||!e.head||e.getElementById(Rn))return;let t=e.createElement(`style`);t.id=Rn,t.textContent=`
|
|
2
|
+
@layer {
|
|
3
|
+
[${zn}] {
|
|
4
|
+
touch-action: pan-x pan-y pinch-zoom;
|
|
5
|
+
}
|
|
14
6
|
}
|
|
15
|
-
|
|
16
|
-
//#endregion
|
|
17
|
-
//#region ../validators/src/questions/routing.ts
|
|
18
|
-
const nextTargetSchema = z.object({ type: z.literal("next") });
|
|
19
|
-
const endTargetSchema = z.object({ type: z.literal("end") });
|
|
20
|
-
const jumpTargetSchema = z.object({
|
|
21
|
-
type: z.literal("jump"),
|
|
22
|
-
target: z.number({ error: "Target question is required" })
|
|
23
|
-
});
|
|
24
|
-
const conditionTargetSchema = z.discriminatedUnion("type", [
|
|
25
|
-
nextTargetSchema,
|
|
26
|
-
jumpTargetSchema,
|
|
27
|
-
endTargetSchema
|
|
28
|
-
]);
|
|
29
|
-
const valueNode = z.object({
|
|
30
|
-
type: z.literal("value"),
|
|
31
|
-
value: z.union([z.string().check(z.trim(), z.minLength(1, { error: "Value is required" })), z.number({ error: "Value is required" })])
|
|
32
|
-
});
|
|
33
|
-
const binaryOperatorConditionSchema = z.object({
|
|
34
|
-
type: z.literal("binary-operator"),
|
|
35
|
-
operator: z.union([
|
|
36
|
-
z.literal("equal"),
|
|
37
|
-
z.literal("not-equal"),
|
|
38
|
-
z.literal("greater"),
|
|
39
|
-
z.literal("greater-or-equal"),
|
|
40
|
-
z.literal("less"),
|
|
41
|
-
z.literal("less-or-equal"),
|
|
42
|
-
z.literal("contains"),
|
|
43
|
-
z.literal("not-contains")
|
|
44
|
-
]),
|
|
45
|
-
value: valueNode,
|
|
46
|
-
target: conditionTargetSchema
|
|
47
|
-
});
|
|
48
|
-
const switchConditionSchema = z.object({
|
|
49
|
-
type: z.literal("switch"),
|
|
50
|
-
cases: z.array(binaryOperatorConditionSchema),
|
|
51
|
-
default: conditionTargetSchema
|
|
52
|
-
});
|
|
53
|
-
const alwaysConditionSchema = z.object({
|
|
54
|
-
type: z.literal("always"),
|
|
55
|
-
target: conditionTargetSchema
|
|
56
|
-
});
|
|
57
|
-
const routingLogicSchema = z.discriminatedUnion("type", [alwaysConditionSchema, switchConditionSchema]);
|
|
58
|
-
|
|
59
|
-
//#endregion
|
|
60
|
-
//#region ../validators/src/url.ts
|
|
61
|
-
const urlSchema = z.string().check(z.trim(), z.url({
|
|
62
|
-
protocol: /^(https|mailto)/,
|
|
63
|
-
error: "Link must start with https:// or mailto:"
|
|
64
|
-
}));
|
|
65
|
-
|
|
66
|
-
//#endregion
|
|
67
|
-
//#region ../validators/src/questions/properties.ts
|
|
68
|
-
const buttonLabelSchema = z.optional(z.string().check(z.trim(), z.maxLength(50)));
|
|
69
|
-
const optionSchema = z.object({
|
|
70
|
-
value: z.string().check(z.trim(), z.minLength(1, { error: "Value is required" })),
|
|
71
|
-
description: z.optional(z.string().check(z.trim()))
|
|
72
|
-
});
|
|
73
|
-
const editableSchema = z.nullable(z.object({
|
|
74
|
-
label: z.string().check(z.trim(), z.minLength(1, { error: "Value is required" })),
|
|
75
|
-
max: z.number(),
|
|
76
|
-
description: z.optional(z.string().check(z.trim()))
|
|
77
|
-
}));
|
|
78
|
-
const ratingQuestionPropertiesSchema = z.object({
|
|
79
|
-
type: z.literal("rating"),
|
|
80
|
-
buttonLabel: buttonLabelSchema,
|
|
81
|
-
scale: z.number().check(z.minimum(2), z.maximum(10)),
|
|
82
|
-
labels: z.optional(z.object({
|
|
83
|
-
lower: z.optional(z.pipe(z.string().check(z.trim()), z.transform((val) => val === "" ? void 0 : val))),
|
|
84
|
-
upper: z.optional(z.pipe(z.string().check(z.trim()), z.transform((val) => val === "" ? void 0 : val)))
|
|
85
|
-
})),
|
|
86
|
-
display: z.optional(z.literal([
|
|
87
|
-
"star",
|
|
88
|
-
"emoji",
|
|
89
|
-
"number"
|
|
90
|
-
]))
|
|
91
|
-
});
|
|
92
|
-
const textQuestionPropertiesSchema = z.object({
|
|
93
|
-
type: z.literal("open-ended"),
|
|
94
|
-
placeholder: z.optional(z.string()),
|
|
95
|
-
buttonLabel: buttonLabelSchema,
|
|
96
|
-
max: z.number()
|
|
97
|
-
});
|
|
98
|
-
const singleSelectQuestionPropertiesSchema = z.object({
|
|
99
|
-
type: z.literal("single-select"),
|
|
100
|
-
options: z.array(optionSchema),
|
|
101
|
-
buttonLabel: buttonLabelSchema,
|
|
102
|
-
editable: editableSchema
|
|
103
|
-
});
|
|
104
|
-
const multiSelectQuestionPropertiesSchema = z.object({
|
|
105
|
-
type: z.literal("multi-select"),
|
|
106
|
-
buttonLabel: buttonLabelSchema,
|
|
107
|
-
options: z.array(optionSchema),
|
|
108
|
-
editable: editableSchema,
|
|
109
|
-
max: z.optional(z.number()),
|
|
110
|
-
display: z.optional(z.literal(["checkbox", "tag"]))
|
|
111
|
-
});
|
|
112
|
-
const statementQuestionPropertiesSchema = z.object({
|
|
113
|
-
type: z.literal("statement"),
|
|
114
|
-
buttonLabel: buttonLabelSchema,
|
|
115
|
-
buttonUrl: z.optional(urlSchema)
|
|
116
|
-
});
|
|
117
|
-
const questionPropertiesSchema = z.discriminatedUnion("type", [
|
|
118
|
-
ratingQuestionPropertiesSchema,
|
|
119
|
-
singleSelectQuestionPropertiesSchema,
|
|
120
|
-
textQuestionPropertiesSchema,
|
|
121
|
-
multiSelectQuestionPropertiesSchema,
|
|
122
|
-
statementQuestionPropertiesSchema
|
|
123
|
-
]);
|
|
124
|
-
|
|
125
|
-
//#endregion
|
|
126
|
-
//#region ../validators/src/questions/constants.ts
|
|
127
|
-
const CHECKBOX_OTHERS_VALUE = "__CONFETTI_CHECKBOX_Others";
|
|
128
|
-
const RADIO_OTHERS_VALUE = "__CONFETTI_RADIO_Others";
|
|
129
|
-
|
|
130
|
-
//#endregion
|
|
131
|
-
//#region ../validators/src/questions/answers.ts
|
|
132
|
-
const baseRatingAnswerSchema = (scale) => z.number().check(z.int(), z.minimum(1), z.maximum(scale));
|
|
133
|
-
const ratingAnswerSchemaFactory = ({ scale }, { required }) => {
|
|
134
|
-
const baseSchema = baseRatingAnswerSchema(scale);
|
|
135
|
-
return required ? baseSchema : z.optional(baseSchema);
|
|
136
|
-
};
|
|
137
|
-
const openEndedAnswerSchemaFactory = ({ maxLength }, { required }) => z.string().check(z.trim(), ...required ? [z.minLength(1, { error: "This field is required" })] : [], z.maxLength(maxLength ?? 2048, { error: ({ maximum }) => `Please enter less than ${maximum} characters` }));
|
|
138
|
-
const baseSingleSelectAnswerSchema = (maxLength, required) => z.string().check(z.trim(), ...required ? [z.minLength(1, { error: "This field is required" })] : [], z.maxLength(maxLength ?? 1024, { error: ({ maximum }) => `Please enter less than ${maximum} characters` }), z.refine((val) => val !== RADIO_OTHERS_VALUE, { error: "Please fill out the free text field" }));
|
|
139
|
-
const singleSelectAnswerSchemaFactory = ({ maxLength }, { required }) => {
|
|
140
|
-
const baseSchema = baseSingleSelectAnswerSchema(maxLength, required);
|
|
141
|
-
return required ? baseSchema : z.optional(baseSchema);
|
|
142
|
-
};
|
|
143
|
-
const multiSelectAnswerSchemaFactory = ({ maxSelected, maxLength }, { required }) => z.array(z.string().check(z.trim(), ...required ? [z.minLength(1, { error: "This field is required" })] : [], z.maxLength(maxLength ?? 1024, { error: ({ maximum }) => `Please enter less than ${maximum} characters` }), z.refine((val) => val !== CHECKBOX_OTHERS_VALUE, { error: "Please fill out the free text field" }))).check(...required ? [z.minLength(1, { error: "Please select at least one option" })] : [], z.maxLength(maxSelected ?? 1024, { error: ({ maximum }) => `Please select less than ${maximum} options` }));
|
|
144
|
-
const statementAnswerSchemaFactory = () => z.optional(z.string());
|
|
145
|
-
|
|
146
|
-
//#endregion
|
|
147
|
-
//#region ../validators/src/survey.ts
|
|
148
|
-
const surveyConfirmationSchema = z.object({
|
|
149
|
-
title: z.string().check(z.trim()),
|
|
150
|
-
description: z.string().check(z.trim()),
|
|
151
|
-
buttonText: z.string().check(z.trim())
|
|
152
|
-
});
|
|
153
|
-
const publicGetSurveyOutputSchema = z.object({
|
|
154
|
-
title: z.string(),
|
|
155
|
-
description: z.nullable(z.string()),
|
|
156
|
-
questions: z.array(z.object({
|
|
157
|
-
id: z.string(),
|
|
158
|
-
title: z.string(),
|
|
159
|
-
description: z.nullable(z.string()),
|
|
160
|
-
position: z.number(),
|
|
161
|
-
required: z.boolean(),
|
|
162
|
-
properties: questionPropertiesSchema,
|
|
163
|
-
routingLogic: routingLogicSchema
|
|
164
|
-
})),
|
|
165
|
-
confirmation: surveyConfirmationSchema
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
//#endregion
|
|
169
|
-
//#region ../validators/src/response.ts
|
|
170
|
-
const publicPutResponseInputSchema = z.object({
|
|
171
|
-
respondent: z.string().check(z.trim(), z.minLength(1), z.maxLength(2048)),
|
|
172
|
-
data: z.record(z.string(), z.union([
|
|
173
|
-
z.string().check(z.trim(), z.maxLength(2048)),
|
|
174
|
-
z.number(),
|
|
175
|
-
z.array(z.string().check(z.trim(), z.maxLength(2048))).check(z.maxLength(1024))
|
|
176
|
-
])),
|
|
177
|
-
metadata: z.record(z.string().check(z.trim(), z.maxLength(1e3)), z.string().check(z.trim(), z.maxLength(1e3)))
|
|
178
|
-
});
|
|
179
|
-
const publicGetRespondentOutputSchema = z.object({
|
|
180
|
-
lastRespondedAt: z.nullable(z.union([z.iso.datetime(), z.date()])),
|
|
181
|
-
lastViewedAt: z.nullable(z.union([z.iso.datetime(), z.date()])),
|
|
182
|
-
lastDismissedAt: z.nullable(z.union([z.iso.datetime(), z.date()]))
|
|
183
|
-
});
|
|
184
|
-
const publicPostRespondentEventInputSchema = z.object({ type: z.enum(["view", "dismiss"]) });
|
|
185
|
-
|
|
186
|
-
//#endregion
|
|
187
|
-
//#region src/core/logic/api.ts
|
|
188
|
-
const API_HOST = "https://confetti.gov.sg/api";
|
|
189
|
-
const client = ky.create({
|
|
190
|
-
prefixUrl: API_HOST,
|
|
191
|
-
retry: {
|
|
192
|
-
limit: 3,
|
|
193
|
-
methods: ["get"]
|
|
194
|
-
},
|
|
195
|
-
timeout: 6e4
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
//#endregion
|
|
199
|
-
//#region src/core/ConfettiProvider.tsx
|
|
200
|
-
const ConfettiContext = createContext(null);
|
|
201
|
-
const ConfettiProvider = ({ children, surveyId, publishableKey, respondent: respondentInput, metadata = {}, isSurveyVisible: isSurveyVisibleInput, apiBaseUrl }) => {
|
|
202
|
-
const hasTrackedViewRef = useRef(false);
|
|
203
|
-
const [survey, setSurvey] = useState();
|
|
204
|
-
const [lastRespondedAt, setLastRespondedAt] = useState();
|
|
205
|
-
const [lastDismissedAt, setLastDismissedAt] = useState();
|
|
206
|
-
const responseId = useMemo(() => crypto.randomUUID(), []);
|
|
207
|
-
const [internalRespondentId, setInternalRespondentId] = useLocalStorage(`cfti:${surveyId}:respondent`, "");
|
|
208
|
-
useEffect(() => {
|
|
209
|
-
if (internalRespondentId) return;
|
|
210
|
-
setInternalRespondentId(crypto.randomUUID());
|
|
211
|
-
}, [internalRespondentId, setInternalRespondentId]);
|
|
212
|
-
const respondent = useMemo(() => respondentInput || internalRespondentId, [respondentInput, internalRespondentId]);
|
|
213
|
-
const client$1 = useMemo(() => {
|
|
214
|
-
const properties = { headers: { "x-cfti-pk": publishableKey } };
|
|
215
|
-
if (apiBaseUrl) properties.prefixUrl = apiBaseUrl;
|
|
216
|
-
return client.extend(properties);
|
|
217
|
-
}, [apiBaseUrl, publishableKey]);
|
|
218
|
-
useEffect(() => {
|
|
219
|
-
client$1.get(`v1/cfti/${surveyId}`).json().then((data) => {
|
|
220
|
-
const parseResult = publicGetSurveyOutputSchema.safeParse(data);
|
|
221
|
-
if (!parseResult.success) return;
|
|
222
|
-
setSurvey(parseResult.data);
|
|
223
|
-
});
|
|
224
|
-
if (!respondent) return;
|
|
225
|
-
client$1.get(`v1/cfti/${surveyId}/respondent/${respondent}`).json().then((data) => {
|
|
226
|
-
const parseResult = publicGetRespondentOutputSchema.safeParse(data);
|
|
227
|
-
if (!parseResult.success) {
|
|
228
|
-
setLastRespondedAt(null);
|
|
229
|
-
setLastDismissedAt(null);
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
setLastRespondedAt(parseResult.data.lastRespondedAt ? new Date(parseResult.data.lastRespondedAt) : null);
|
|
233
|
-
setLastDismissedAt(parseResult.data.lastDismissedAt ? new Date(parseResult.data.lastDismissedAt) : null);
|
|
234
|
-
});
|
|
235
|
-
}, [
|
|
236
|
-
apiBaseUrl,
|
|
237
|
-
client$1,
|
|
238
|
-
internalRespondentId,
|
|
239
|
-
respondent,
|
|
240
|
-
surveyId
|
|
241
|
-
]);
|
|
242
|
-
const submit = useCallback(async ({ answers }) => {
|
|
243
|
-
await client$1.put(`v1/cfti/${surveyId}/response/${responseId}`, { json: {
|
|
244
|
-
respondent,
|
|
245
|
-
data: answers,
|
|
246
|
-
metadata
|
|
247
|
-
} });
|
|
248
|
-
}, [
|
|
249
|
-
client$1,
|
|
250
|
-
metadata,
|
|
251
|
-
respondent,
|
|
252
|
-
responseId,
|
|
253
|
-
surveyId
|
|
254
|
-
]);
|
|
255
|
-
const dismiss = useCallback(() => {
|
|
256
|
-
setSurvey(void 0);
|
|
257
|
-
client$1.post(`v1/cfti/${surveyId}/respondent/${respondent}/event`, { json: { type: "dismiss" } }).catch(() => {});
|
|
258
|
-
}, [
|
|
259
|
-
client$1,
|
|
260
|
-
respondent,
|
|
261
|
-
surveyId
|
|
262
|
-
]);
|
|
263
|
-
const isSurveyVisible = useMemo(() => {
|
|
264
|
-
if (isSurveyVisibleInput === void 0) return true;
|
|
265
|
-
if (typeof isSurveyVisibleInput === "boolean") return isSurveyVisibleInput;
|
|
266
|
-
if (lastRespondedAt === void 0 || lastDismissedAt === void 0) return false;
|
|
267
|
-
return isSurveyVisibleInput({
|
|
268
|
-
lastRespondedAt,
|
|
269
|
-
lastDismissedAt
|
|
270
|
-
});
|
|
271
|
-
}, [
|
|
272
|
-
isSurveyVisibleInput,
|
|
273
|
-
lastRespondedAt,
|
|
274
|
-
lastDismissedAt
|
|
275
|
-
]);
|
|
276
|
-
useEffect(() => {
|
|
277
|
-
if (hasTrackedViewRef.current) return;
|
|
278
|
-
if (isSurveyVisible) {
|
|
279
|
-
hasTrackedViewRef.current = true;
|
|
280
|
-
client$1.post(`v1/cfti/${surveyId}/respondent/${respondent}/event`, { json: { type: "view" } }).catch(() => {});
|
|
281
|
-
}
|
|
282
|
-
}, [
|
|
283
|
-
client$1,
|
|
284
|
-
isSurveyVisible,
|
|
285
|
-
respondent,
|
|
286
|
-
surveyId
|
|
287
|
-
]);
|
|
288
|
-
if (!isSurveyVisible || !survey) return null;
|
|
289
|
-
return /* @__PURE__ */ jsx(ConfettiContext.Provider, {
|
|
290
|
-
value: {
|
|
291
|
-
submit,
|
|
292
|
-
dismiss,
|
|
293
|
-
surveyId,
|
|
294
|
-
survey,
|
|
295
|
-
metadata
|
|
296
|
-
},
|
|
297
|
-
children
|
|
298
|
-
});
|
|
299
|
-
};
|
|
300
|
-
const useConfetti = () => {
|
|
301
|
-
const context = useContext(ConfettiContext);
|
|
302
|
-
if (!context) throw new Error("useConfetti must be used within a ConfettiProvider");
|
|
303
|
-
return context;
|
|
304
|
-
};
|
|
305
|
-
|
|
306
|
-
//#endregion
|
|
307
|
-
//#region src/core/logic/validate.ts
|
|
308
|
-
const VALIDATOR_FACTORY_MAP = {
|
|
309
|
-
rating: ({ scale }, meta) => ratingAnswerSchemaFactory({ scale }, meta),
|
|
310
|
-
"open-ended": ({ max }, meta) => openEndedAnswerSchemaFactory({ maxLength: max }, meta),
|
|
311
|
-
"single-select": ({ editable }, meta) => singleSelectAnswerSchemaFactory({ maxLength: editable?.max }, meta),
|
|
312
|
-
"multi-select": ({ editable, max }, meta) => multiSelectAnswerSchemaFactory({
|
|
313
|
-
maxLength: editable?.max,
|
|
314
|
-
maxSelected: max
|
|
315
|
-
}, meta),
|
|
316
|
-
statement: (_properties, _meta) => statementAnswerSchemaFactory()
|
|
317
|
-
};
|
|
318
|
-
const getAnswerValidator = (properties, meta) => {
|
|
319
|
-
const type = properties.type;
|
|
320
|
-
switch (type) {
|
|
321
|
-
case "rating": {
|
|
322
|
-
const validator = VALIDATOR_FACTORY_MAP[type];
|
|
323
|
-
return validator(properties, meta);
|
|
324
|
-
}
|
|
325
|
-
case "open-ended": {
|
|
326
|
-
const validator = VALIDATOR_FACTORY_MAP[type];
|
|
327
|
-
return validator(properties, meta);
|
|
328
|
-
}
|
|
329
|
-
case "single-select": {
|
|
330
|
-
const validator = VALIDATOR_FACTORY_MAP[type];
|
|
331
|
-
return validator(properties, meta);
|
|
332
|
-
}
|
|
333
|
-
case "multi-select": {
|
|
334
|
-
const validator = VALIDATOR_FACTORY_MAP[type];
|
|
335
|
-
return validator(properties, meta);
|
|
336
|
-
}
|
|
337
|
-
case "statement": {
|
|
338
|
-
const validator = VALIDATOR_FACTORY_MAP[type];
|
|
339
|
-
return validator(properties, meta);
|
|
340
|
-
}
|
|
341
|
-
default: throw new Error("Unsupported question type");
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
|
|
345
|
-
//#endregion
|
|
346
|
-
//#region src/core/ConfettiController.tsx
|
|
347
|
-
const getNextQuestionState = ({ originalQuestions, answers, errors, pointer = -1 }) => {
|
|
348
|
-
if (!originalQuestions) return {
|
|
349
|
-
questions: [],
|
|
350
|
-
currentIndex: -1
|
|
351
|
-
};
|
|
352
|
-
const questions = originalQuestions.sort((a, b) => a.position - b.position).map((question) => {
|
|
353
|
-
const obj = { ...question };
|
|
354
|
-
const error = errors[question.id];
|
|
355
|
-
if (error) obj.error = error;
|
|
356
|
-
return {
|
|
357
|
-
...obj,
|
|
358
|
-
visible: false
|
|
359
|
-
};
|
|
360
|
-
});
|
|
361
|
-
for (let i = 0; i < questions.length; i++) {
|
|
362
|
-
const question = questions[i];
|
|
363
|
-
if (!question) continue;
|
|
364
|
-
const visible = isVisible({
|
|
365
|
-
index: i,
|
|
366
|
-
questions,
|
|
367
|
-
answers
|
|
368
|
-
});
|
|
369
|
-
question.visible = pointer === i || visible;
|
|
370
|
-
}
|
|
371
|
-
let nextIndex = questions.findIndex((q, i) => i > pointer && q.visible && answers[q.id] === void 0);
|
|
372
|
-
if (nextIndex === -1) nextIndex = questions.findLastIndex((q) => !!q.visible);
|
|
373
|
-
return {
|
|
374
|
-
questions,
|
|
375
|
-
currentIndex: nextIndex
|
|
376
|
-
};
|
|
377
|
-
};
|
|
378
|
-
const getSubmittableAnswers = ({ questions, answers }) => {
|
|
379
|
-
return Object.fromEntries(Object.entries(answers).filter(([id]) => !!questions.find((question) => question.id === id)?.visible).filter(([, answer]) => answer !== null));
|
|
380
|
-
};
|
|
381
|
-
const ConfettiController = ({ current: currentProp, shouldAutoSubmit, onFinished, children }) => {
|
|
382
|
-
const { survey, submit } = useConfetti();
|
|
383
|
-
const [answers, setAnswers] = useState({});
|
|
384
|
-
const [errors, setErrors] = useState({});
|
|
385
|
-
const state = useMemo(() => getNextQuestionState({
|
|
386
|
-
originalQuestions: survey?.questions,
|
|
387
|
-
answers,
|
|
388
|
-
errors,
|
|
389
|
-
pointer: currentProp
|
|
390
|
-
}), [
|
|
391
|
-
survey?.questions,
|
|
392
|
-
answers,
|
|
393
|
-
errors,
|
|
394
|
-
currentProp
|
|
395
|
-
]);
|
|
396
|
-
const isCompleted = useMemo(() => {
|
|
397
|
-
return !!state.questions.filter(({ required, visible }) => !!required && !!visible).every(({ id }) => answers[id] !== void 0);
|
|
398
|
-
}, [answers, state.questions]);
|
|
399
|
-
const [isSubmitted, setIsSubmitted] = useState(false);
|
|
400
|
-
const handleSubmitWithFinish = useCallback(({ answers: answers$1 }) => {
|
|
401
|
-
submit({ answers: answers$1 }).finally(() => {
|
|
402
|
-
onFinished?.();
|
|
403
|
-
});
|
|
404
|
-
}, [onFinished, submit]);
|
|
405
|
-
const handleSubmit = useCallback(() => {
|
|
406
|
-
handleSubmitWithFinish({ answers: getSubmittableAnswers({
|
|
407
|
-
questions: state.questions,
|
|
408
|
-
answers
|
|
409
|
-
}) });
|
|
410
|
-
setIsSubmitted(true);
|
|
411
|
-
}, [
|
|
412
|
-
answers,
|
|
413
|
-
state.questions,
|
|
414
|
-
handleSubmitWithFinish
|
|
415
|
-
]);
|
|
416
|
-
const update = useCallback(({ question: index, answer }) => {
|
|
417
|
-
const question = state.questions.at(index);
|
|
418
|
-
if (!question) return { error: "Question index is invalid" };
|
|
419
|
-
const parseResult = getAnswerValidator(question.properties, { required: question.required }).safeParse(answer);
|
|
420
|
-
if (!parseResult.success) {
|
|
421
|
-
const prettifiedError = prettifyError(parseResult.error);
|
|
422
|
-
setErrors((prev) => {
|
|
423
|
-
if (prev[question.id] === prettifiedError) return prev;
|
|
424
|
-
const copy = { ...prev };
|
|
425
|
-
copy[question.id] = prettifiedError;
|
|
426
|
-
return copy;
|
|
427
|
-
});
|
|
428
|
-
return { error: prettifiedError };
|
|
429
|
-
}
|
|
430
|
-
const internalAnswer = !question.required && !answer ? null : answer;
|
|
431
|
-
const next = { ...answers };
|
|
432
|
-
if (next[question.id] === internalAnswer) return { next: getNextQuestionState({
|
|
433
|
-
originalQuestions: survey?.questions,
|
|
434
|
-
answers: next,
|
|
435
|
-
errors,
|
|
436
|
-
pointer: currentProp
|
|
437
|
-
}).currentIndex };
|
|
438
|
-
next[question.id] = internalAnswer;
|
|
439
|
-
setAnswers(next);
|
|
440
|
-
const nextQuestionState = getNextQuestionState({
|
|
441
|
-
originalQuestions: survey?.questions,
|
|
442
|
-
answers: next,
|
|
443
|
-
errors,
|
|
444
|
-
pointer: currentProp
|
|
445
|
-
});
|
|
446
|
-
if (nextQuestionState.questions.filter(({ visible }) => !!visible).every(({ id }) => next[id] !== void 0) && shouldAutoSubmit) {
|
|
447
|
-
handleSubmitWithFinish({ answers: getSubmittableAnswers({
|
|
448
|
-
questions: nextQuestionState.questions,
|
|
449
|
-
answers: next
|
|
450
|
-
}) });
|
|
451
|
-
setIsSubmitted(true);
|
|
452
|
-
}
|
|
453
|
-
return { next: nextQuestionState.currentIndex };
|
|
454
|
-
}, [
|
|
455
|
-
state.questions,
|
|
456
|
-
answers,
|
|
457
|
-
survey?.questions,
|
|
458
|
-
errors,
|
|
459
|
-
shouldAutoSubmit,
|
|
460
|
-
currentProp,
|
|
461
|
-
handleSubmitWithFinish
|
|
462
|
-
]);
|
|
463
|
-
if (state.questions.length === 0) return /* @__PURE__ */ jsx(Fragment, {});
|
|
464
|
-
return /* @__PURE__ */ jsx("div", {
|
|
465
|
-
className: "confetti",
|
|
466
|
-
children: children({
|
|
467
|
-
questions: state.questions,
|
|
468
|
-
current: currentProp ?? state.currentIndex,
|
|
469
|
-
update,
|
|
470
|
-
isCompleted,
|
|
471
|
-
submit: handleSubmit,
|
|
472
|
-
isSubmitted,
|
|
473
|
-
errors
|
|
474
|
-
})
|
|
475
|
-
});
|
|
476
|
-
};
|
|
477
|
-
|
|
478
|
-
//#endregion
|
|
479
|
-
//#region src/components/Confetti.tsx
|
|
480
|
-
const Confetti = ({ children, onFinished, shouldAutoSubmit, ...props }) => {
|
|
481
|
-
return /* @__PURE__ */ jsx(ErrorBoundary, {
|
|
482
|
-
fallback: /* @__PURE__ */ jsx(Fragment, {}),
|
|
483
|
-
children: /* @__PURE__ */ jsx(ConfettiProvider, {
|
|
484
|
-
...props,
|
|
485
|
-
children: /* @__PURE__ */ jsx(ConfettiController, {
|
|
486
|
-
shouldAutoSubmit,
|
|
487
|
-
onFinished,
|
|
488
|
-
children
|
|
489
|
-
})
|
|
490
|
-
})
|
|
491
|
-
});
|
|
492
|
-
};
|
|
493
|
-
|
|
494
|
-
//#endregion
|
|
495
|
-
//#region src/components/ThankYouMessage.tsx
|
|
496
|
-
const ThankYouMessage = ({ title, description, classNames }) => {
|
|
497
|
-
const { survey, dismiss } = useConfetti();
|
|
498
|
-
if (!survey) return null;
|
|
499
|
-
const descriptionText = description || survey.confirmation.description;
|
|
500
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
|
|
501
|
-
className: clsx("cf-question", classNames?.question),
|
|
502
|
-
children: /* @__PURE__ */ jsxs("div", {
|
|
503
|
-
className: clsx("cf-header", classNames?.header),
|
|
504
|
-
children: [/* @__PURE__ */ jsx(Label, {
|
|
505
|
-
className: clsx("cf-title", classNames?.title),
|
|
506
|
-
children: title || survey.confirmation.title || "Feedback submitted!"
|
|
507
|
-
}), descriptionText && /* @__PURE__ */ jsx(Text, {
|
|
508
|
-
slot: "description",
|
|
509
|
-
className: clsx("cf-description", classNames?.description),
|
|
510
|
-
children: descriptionText
|
|
511
|
-
})]
|
|
512
|
-
})
|
|
513
|
-
}), /* @__PURE__ */ jsx(Button, {
|
|
514
|
-
className: "cf-submit-button",
|
|
515
|
-
onPress: dismiss,
|
|
516
|
-
children: survey.confirmation.buttonText || "Close"
|
|
517
|
-
})] });
|
|
518
|
-
};
|
|
519
|
-
|
|
520
|
-
//#endregion
|
|
521
|
-
//#region src/components/container/PopoverContainer.tsx
|
|
522
|
-
const PopoverContainer = ({ children, classNames, containerProps, onDismiss, closeOnFinishMs = 3e3 }) => {
|
|
523
|
-
const { surveyId, survey, dismiss } = useConfetti();
|
|
524
|
-
const [isFinished, setIsFinished] = useState(false);
|
|
525
|
-
useTimeout(() => {
|
|
526
|
-
if (survey) dismiss();
|
|
527
|
-
}, isFinished ? closeOnFinishMs : null);
|
|
528
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
529
|
-
className: clsx("confetti-dialog", classNames?.dialog),
|
|
530
|
-
id: `${surveyId}-popover`,
|
|
531
|
-
...containerProps,
|
|
532
|
-
children: [/* @__PURE__ */ jsx("button", {
|
|
533
|
-
type: "button",
|
|
534
|
-
className: clsx("confetti-dialog-close", classNames?.closeButton),
|
|
535
|
-
"aria-label": "Dismiss",
|
|
536
|
-
onClick: async () => {
|
|
537
|
-
await dismiss();
|
|
538
|
-
onDismiss?.();
|
|
539
|
-
},
|
|
540
|
-
children: /* @__PURE__ */ jsx("svg", {
|
|
541
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
542
|
-
viewBox: "0 0 16 16",
|
|
543
|
-
fill: "none",
|
|
544
|
-
className: clsx(classNames?.icon),
|
|
545
|
-
children: /* @__PURE__ */ jsx("path", {
|
|
546
|
-
fill: "currentColor",
|
|
547
|
-
fillRule: "evenodd",
|
|
548
|
-
d: "M3.53 3.529c.26-.26.682-.26.942 0l3.529 3.528 3.528-3.528a.667.667 0 0 1 .943.942L8.943 8l3.53 3.528a.667.667 0 0 1-.944.943L8.001 8.943 4.472 12.47a.667.667 0 1 1-.943-.943L7.058 8 3.529 4.47a.667.667 0 0 1 0-.942Z",
|
|
549
|
-
clipRule: "evenodd"
|
|
550
|
-
})
|
|
551
|
-
})
|
|
552
|
-
}), typeof children === "function" ? children({ setIsFinished: () => setIsFinished(true) }) : children]
|
|
553
|
-
});
|
|
554
|
-
};
|
|
555
|
-
|
|
556
|
-
//#endregion
|
|
557
|
-
//#region src/components/questions/FreeText.tsx
|
|
558
|
-
const FreeText = ({ id, title, description, properties, onChange, classNames, required, error }) => {
|
|
559
|
-
const [value, setValue] = useState("");
|
|
560
|
-
useEffect(() => {
|
|
561
|
-
onChange(value);
|
|
562
|
-
}, [onChange, value]);
|
|
563
|
-
return /* @__PURE__ */ jsxs(TextField, {
|
|
564
|
-
isRequired: required,
|
|
565
|
-
isInvalid: !!error,
|
|
566
|
-
name: id,
|
|
567
|
-
className: clsx("cf-question", classNames?.question),
|
|
568
|
-
value,
|
|
569
|
-
onChange: (v) => {
|
|
570
|
-
setValue(v);
|
|
571
|
-
onChange(v);
|
|
572
|
-
},
|
|
573
|
-
children: [
|
|
574
|
-
/* @__PURE__ */ jsxs("div", {
|
|
575
|
-
className: clsx("cf-header", classNames?.header),
|
|
576
|
-
children: [/* @__PURE__ */ jsxs(Label, {
|
|
577
|
-
className: clsx("cf-title", classNames?.title),
|
|
578
|
-
children: [title, !required && /* @__PURE__ */ jsxs("span", {
|
|
579
|
-
className: clsx("cf-label-optional", classNames?.optionalLabel),
|
|
580
|
-
children: [" ", "(optional)"]
|
|
581
|
-
})]
|
|
582
|
-
}), description && /* @__PURE__ */ jsx(Text, {
|
|
583
|
-
slot: "description",
|
|
584
|
-
className: clsx("cf-description", classNames?.description),
|
|
585
|
-
children: description
|
|
586
|
-
})]
|
|
587
|
-
}),
|
|
588
|
-
/* @__PURE__ */ jsx(TextArea, {
|
|
589
|
-
className: clsx("cf-textarea", classNames?.textarea),
|
|
590
|
-
maxLength: properties.max,
|
|
591
|
-
rows: 4,
|
|
592
|
-
placeholder: properties.placeholder || "Start typing..."
|
|
593
|
-
}),
|
|
594
|
-
/* @__PURE__ */ jsx(FieldError, {
|
|
595
|
-
className: clsx("cf-error", classNames?.error),
|
|
596
|
-
children: error
|
|
597
|
-
})
|
|
598
|
-
]
|
|
599
|
-
});
|
|
600
|
-
};
|
|
601
|
-
|
|
602
|
-
//#endregion
|
|
603
|
-
//#region src/components/questions/MultiChoice.tsx
|
|
604
|
-
const MultiChoiceCheckbox = ({ children, classNames, description, ...props }) => {
|
|
605
|
-
return /* @__PURE__ */ jsx(Checkbox, {
|
|
606
|
-
...props,
|
|
607
|
-
children: ({ isIndeterminate }) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
|
|
608
|
-
className: clsx("cf-choice-label", classNames?.label),
|
|
609
|
-
children: [/* @__PURE__ */ jsx("div", {
|
|
610
|
-
className: clsx("cf-checkbox-indicator", classNames?.indicator),
|
|
611
|
-
children: /* @__PURE__ */ jsx("svg", {
|
|
612
|
-
viewBox: "0 0 18 18",
|
|
613
|
-
"aria-hidden": "true",
|
|
614
|
-
className: clsx("cf-checkbox-indicator-svg", classNames?.svg),
|
|
615
|
-
children: isIndeterminate ? /* @__PURE__ */ jsx("rect", {
|
|
616
|
-
x: 1,
|
|
617
|
-
y: 7.5,
|
|
618
|
-
width: 16,
|
|
619
|
-
height: 3
|
|
620
|
-
}) : /* @__PURE__ */ jsx("polyline", { points: "2 9 7 14 16 4" })
|
|
621
|
-
}, isIndeterminate ? "indeterminate" : "check")
|
|
622
|
-
}), children]
|
|
623
|
-
}), description && /* @__PURE__ */ jsx("span", {
|
|
624
|
-
className: clsx("cf-choice-description", classNames?.choiceDescription),
|
|
625
|
-
children: description
|
|
626
|
-
})] })
|
|
627
|
-
});
|
|
628
|
-
};
|
|
629
|
-
const MultiChoiceTag = ({ children, classNames, ...props }) => {
|
|
630
|
-
return /* @__PURE__ */ jsx(Checkbox, {
|
|
631
|
-
...props,
|
|
632
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
633
|
-
className: clsx("cf-tag-label", classNames?.tagLabel),
|
|
634
|
-
children
|
|
635
|
-
})
|
|
636
|
-
});
|
|
637
|
-
};
|
|
638
|
-
const MultiChoice = ({ title, description, properties, classNames, onChange, id, required, error }) => {
|
|
639
|
-
const hasEditable = !!properties.editable;
|
|
640
|
-
const display = properties.display ?? "checkbox";
|
|
641
|
-
const [value, setValue] = useState([]);
|
|
642
|
-
const [othersValue, setOthersValue] = useState("");
|
|
643
|
-
const othersRef = useRef(null);
|
|
644
|
-
const othersInputRef = useRef(null);
|
|
645
|
-
const submissionValue = useMemo(() => {
|
|
646
|
-
const othersValueIndex = value.indexOf(CHECKBOX_OTHERS_VALUE);
|
|
647
|
-
if (othersValueIndex === -1) return value;
|
|
648
|
-
const submissionValue$1 = [...value];
|
|
649
|
-
submissionValue$1[othersValueIndex] = othersValue || CHECKBOX_OTHERS_VALUE;
|
|
650
|
-
return submissionValue$1;
|
|
651
|
-
}, [othersValue, value]);
|
|
652
|
-
const isTag = display === "tag";
|
|
653
|
-
useEffect(() => {
|
|
654
|
-
onChange(submissionValue);
|
|
655
|
-
}, [onChange, submissionValue]);
|
|
656
|
-
return /* @__PURE__ */ jsx(CheckboxGroup, {
|
|
657
|
-
isRequired: required,
|
|
658
|
-
isInvalid: !!error,
|
|
659
|
-
name: id,
|
|
660
|
-
value,
|
|
661
|
-
onChange: setValue,
|
|
662
|
-
className: clsx("cf-question", classNames?.question),
|
|
663
|
-
children: ({ state }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
664
|
-
/* @__PURE__ */ jsxs("div", {
|
|
665
|
-
className: clsx("cf-header", classNames?.header),
|
|
666
|
-
children: [/* @__PURE__ */ jsxs(Label, {
|
|
667
|
-
className: clsx("cf-title", classNames?.title),
|
|
668
|
-
children: [title, !required && /* @__PURE__ */ jsxs("span", {
|
|
669
|
-
className: clsx("cf-label-optional", classNames?.optionalLabel),
|
|
670
|
-
children: [" ", "(optional)"]
|
|
671
|
-
})]
|
|
672
|
-
}), description && /* @__PURE__ */ jsx(Text, {
|
|
673
|
-
slot: "description",
|
|
674
|
-
className: clsx("cf-description", classNames?.description),
|
|
675
|
-
children: description
|
|
676
|
-
})]
|
|
677
|
-
}),
|
|
678
|
-
/* @__PURE__ */ jsxs("div", {
|
|
679
|
-
className: clsx("cf-response-choices", display === "tag" && "cf-response-choices-tag", classNames?.group),
|
|
680
|
-
children: [properties.options.map((option, index) => {
|
|
681
|
-
return /* @__PURE__ */ jsx(isTag ? MultiChoiceTag : MultiChoiceCheckbox, {
|
|
682
|
-
className: clsx("cf-choice", isTag && ["cf-tag", classNames?.tag], !isTag && ["cf-checkbox", classNames?.checkbox]),
|
|
683
|
-
description: option.description,
|
|
684
|
-
value: option.value,
|
|
685
|
-
classNames: {
|
|
686
|
-
tag: classNames?.tag,
|
|
687
|
-
tagLabel: classNames?.tagLabel,
|
|
688
|
-
choiceDescription: classNames?.choiceDescription,
|
|
689
|
-
label: classNames?.label,
|
|
690
|
-
indicator: classNames?.indicator,
|
|
691
|
-
svg: classNames?.svg
|
|
692
|
-
},
|
|
693
|
-
children: option.value
|
|
694
|
-
}, index);
|
|
695
|
-
}), hasEditable && (isTag ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(MultiChoiceTag, {
|
|
696
|
-
inputRef: othersRef,
|
|
697
|
-
onChange: (isSelected) => {
|
|
698
|
-
console.log("hehe", isSelected);
|
|
699
|
-
if (!othersInputRef.current) return;
|
|
700
|
-
if (isSelected) requestAnimationFrame(() => {
|
|
701
|
-
if (!othersInputRef.current) return;
|
|
702
|
-
othersInputRef.current.focus();
|
|
703
|
-
});
|
|
704
|
-
},
|
|
705
|
-
className: clsx("cf-choice cf-tag", classNames?.tag),
|
|
706
|
-
value: CHECKBOX_OTHERS_VALUE,
|
|
707
|
-
children: properties.editable?.label
|
|
708
|
-
}), /* @__PURE__ */ jsx(Input, {
|
|
709
|
-
"data-visible": state.value.includes(CHECKBOX_OTHERS_VALUE) || void 0,
|
|
710
|
-
value: othersValue,
|
|
711
|
-
onChange: (e) => {
|
|
712
|
-
setOthersValue(e.target.value);
|
|
713
|
-
},
|
|
714
|
-
ref: othersInputRef,
|
|
715
|
-
className: clsx("cf-input cf-tag-input", classNames?.othersInput)
|
|
716
|
-
})] }) : /* @__PURE__ */ jsxs("div", {
|
|
717
|
-
className: clsx("cf-choice cf-others-choice", classNames?.othersChoice),
|
|
718
|
-
children: [/* @__PURE__ */ jsx(MultiChoiceCheckbox, {
|
|
719
|
-
inputRef: othersRef,
|
|
720
|
-
onChange: (isSelected) => {
|
|
721
|
-
if (!othersInputRef.current) return;
|
|
722
|
-
if (isSelected) requestAnimationFrame(() => {
|
|
723
|
-
if (!othersInputRef.current) return;
|
|
724
|
-
othersInputRef.current.focus();
|
|
725
|
-
});
|
|
726
|
-
},
|
|
727
|
-
className: clsx("cf-checkbox", classNames?.checkbox),
|
|
728
|
-
value: CHECKBOX_OTHERS_VALUE,
|
|
729
|
-
classNames: {
|
|
730
|
-
indicator: classNames?.indicator,
|
|
731
|
-
svg: classNames?.svg
|
|
732
|
-
},
|
|
733
|
-
description: properties.editable?.description,
|
|
734
|
-
children: properties.editable?.label
|
|
735
|
-
}), /* @__PURE__ */ jsx(Input, {
|
|
736
|
-
value: othersValue,
|
|
737
|
-
onChange: (e) => {
|
|
738
|
-
setOthersValue(e.target.value);
|
|
739
|
-
},
|
|
740
|
-
tabIndex: state.value.includes(CHECKBOX_OTHERS_VALUE) ? 0 : -1,
|
|
741
|
-
ref: othersInputRef,
|
|
742
|
-
onFocus: () => {
|
|
743
|
-
if (othersRef.current?.checked === false) othersRef.current.click();
|
|
744
|
-
},
|
|
745
|
-
className: clsx("cf-input", classNames?.othersInput)
|
|
746
|
-
})]
|
|
747
|
-
}))]
|
|
748
|
-
}),
|
|
749
|
-
/* @__PURE__ */ jsx(FieldError, {
|
|
750
|
-
className: clsx("cf-error", classNames?.error),
|
|
751
|
-
children: error
|
|
752
|
-
})
|
|
753
|
-
] })
|
|
754
|
-
});
|
|
755
|
-
};
|
|
756
|
-
|
|
757
|
-
//#endregion
|
|
758
|
-
//#region src/components/svgr/EmojiAngry.tsx
|
|
759
|
-
const EmojiAngry = (props) => /* @__PURE__ */ jsxs("svg", {
|
|
760
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
761
|
-
width: 40,
|
|
762
|
-
height: 40,
|
|
763
|
-
viewBox: "0 0 24 24",
|
|
764
|
-
fill: "none",
|
|
765
|
-
stroke: "currentColor",
|
|
766
|
-
strokeLinecap: "round",
|
|
767
|
-
strokeLinejoin: "round",
|
|
768
|
-
strokeWidth: 2,
|
|
769
|
-
...props,
|
|
770
|
-
children: [/* @__PURE__ */ jsx("circle", {
|
|
771
|
-
cx: 12,
|
|
772
|
-
cy: 12,
|
|
773
|
-
r: 10
|
|
774
|
-
}), /* @__PURE__ */ jsx("path", { d: "M16 16s-1.5-2-4-2-4 2-4 2M7.5 8 10 9M14 9l2.5-1M9 10h.01M15 10h.01" })]
|
|
775
|
-
});
|
|
776
|
-
|
|
777
|
-
//#endregion
|
|
778
|
-
//#region src/components/svgr/EmojiBeaming.tsx
|
|
779
|
-
const EmojiBeaming = (props) => /* @__PURE__ */ jsxs("svg", {
|
|
780
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
781
|
-
width: 40,
|
|
782
|
-
height: 40,
|
|
783
|
-
viewBox: "0 0 24 24",
|
|
784
|
-
fill: "none",
|
|
785
|
-
stroke: "currentColor",
|
|
786
|
-
strokeLinecap: "round",
|
|
787
|
-
strokeLinejoin: "round",
|
|
788
|
-
strokeWidth: 2,
|
|
789
|
-
...props,
|
|
790
|
-
children: [/* @__PURE__ */ jsx("circle", {
|
|
791
|
-
cx: 12,
|
|
792
|
-
cy: 12,
|
|
793
|
-
r: 10
|
|
794
|
-
}), /* @__PURE__ */ jsx("path", { d: "M18 13a6 6 0 0 1-6 5 6 6 0 0 1-6-5h12ZM9 9h.01M15 9h.01" })]
|
|
795
|
-
});
|
|
796
|
-
|
|
797
|
-
//#endregion
|
|
798
|
-
//#region src/components/svgr/EmojiFrown.tsx
|
|
799
|
-
const EmojiFrown = (props) => /* @__PURE__ */ jsxs("svg", {
|
|
800
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
801
|
-
width: 40,
|
|
802
|
-
height: 40,
|
|
803
|
-
viewBox: "0 0 24 24",
|
|
804
|
-
fill: "none",
|
|
805
|
-
stroke: "currentColor",
|
|
806
|
-
strokeLinecap: "round",
|
|
807
|
-
strokeLinejoin: "round",
|
|
808
|
-
strokeWidth: 2,
|
|
809
|
-
...props,
|
|
810
|
-
children: [/* @__PURE__ */ jsx("circle", {
|
|
811
|
-
cx: 12,
|
|
812
|
-
cy: 12,
|
|
813
|
-
r: 10
|
|
814
|
-
}), /* @__PURE__ */ jsx("path", { d: "M16 16s-1.5-2-4-2-4 2-4 2M9 9h.01M15 9h.01" })]
|
|
815
|
-
});
|
|
816
|
-
|
|
817
|
-
//#endregion
|
|
818
|
-
//#region src/components/svgr/EmojiMeh.tsx
|
|
819
|
-
const EmojiMeh = (props) => /* @__PURE__ */ jsxs("svg", {
|
|
820
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
821
|
-
width: 40,
|
|
822
|
-
height: 40,
|
|
823
|
-
viewBox: "0 0 24 24",
|
|
824
|
-
fill: "none",
|
|
825
|
-
stroke: "currentColor",
|
|
826
|
-
strokeLinecap: "round",
|
|
827
|
-
strokeLinejoin: "round",
|
|
828
|
-
strokeWidth: 2,
|
|
829
|
-
...props,
|
|
830
|
-
children: [/* @__PURE__ */ jsx("circle", {
|
|
831
|
-
cx: 12,
|
|
832
|
-
cy: 12,
|
|
833
|
-
r: 10
|
|
834
|
-
}), /* @__PURE__ */ jsx("path", { d: "M8 15h8M9 9h.01M15 9h.01" })]
|
|
835
|
-
});
|
|
836
|
-
|
|
837
|
-
//#endregion
|
|
838
|
-
//#region src/components/svgr/EmojiSmile.tsx
|
|
839
|
-
const EmojiSmile = (props) => /* @__PURE__ */ jsxs("svg", {
|
|
840
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
841
|
-
width: 40,
|
|
842
|
-
height: 40,
|
|
843
|
-
viewBox: "0 0 24 24",
|
|
844
|
-
fill: "none",
|
|
845
|
-
stroke: "currentColor",
|
|
846
|
-
strokeLinecap: "round",
|
|
847
|
-
strokeLinejoin: "round",
|
|
848
|
-
strokeWidth: 2,
|
|
849
|
-
...props,
|
|
850
|
-
children: [/* @__PURE__ */ jsx("circle", {
|
|
851
|
-
cx: 12,
|
|
852
|
-
cy: 12,
|
|
853
|
-
r: 10
|
|
854
|
-
}), /* @__PURE__ */ jsx("path", { d: "M8 14s1.5 2 4 2 4-2 4-2M9 9h.01M15 9h.01" })]
|
|
855
|
-
});
|
|
856
|
-
|
|
857
|
-
//#endregion
|
|
858
|
-
//#region src/components/svgr/Star.tsx
|
|
859
|
-
const Star = (props) => /* @__PURE__ */ jsx("svg", {
|
|
860
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
861
|
-
viewBox: "0 0 24 24",
|
|
862
|
-
width: 40,
|
|
863
|
-
height: 40,
|
|
864
|
-
fill: "none",
|
|
865
|
-
...props,
|
|
866
|
-
children: /* @__PURE__ */ jsx("path", {
|
|
867
|
-
fill: "currentColor",
|
|
868
|
-
d: "m6.516 14.323-1.49 6.452a.998.998 0 0 0 1.529 1.057L12 18.202l5.445 3.63a1.001 1.001 0 0 0 1.517-1.106l-1.829-6.4 4.536-4.082a1 1 0 0 0-.59-1.74l-5.701-.454-2.467-5.461a.998.998 0 0 0-1.822 0L8.622 8.05l-5.701.453a1 1 0 0 0-.619 1.713l4.214 4.107zm2.853-4.326a.998.998 0 0 0 .832-.586L12 5.43l1.799 3.981a.998.998 0 0 0 .832.586l3.972.315-3.271 2.944c-.284.256-.397.65-.293 1.018l1.253 4.385-3.736-2.491a.995.995 0 0 0-1.109 0l-3.904 2.603 1.05-4.546a1 1 0 0 0-.276-.94l-3.038-2.962 4.09-.326z"
|
|
869
|
-
})
|
|
870
|
-
});
|
|
871
|
-
|
|
872
|
-
//#endregion
|
|
873
|
-
//#region src/components/svgr/StarSolid.tsx
|
|
874
|
-
const StarSolid = (props) => {
|
|
875
|
-
return /* @__PURE__ */ jsx("svg", {
|
|
876
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
877
|
-
width: 40,
|
|
878
|
-
height: 40,
|
|
879
|
-
viewBox: "0 0 24 24",
|
|
880
|
-
...props,
|
|
881
|
-
children: /* @__PURE__ */ jsx("path", {
|
|
882
|
-
fill: "currentColor",
|
|
883
|
-
d: "M21.947 9.179a1.001 1.001 0 0 0-.868-.676l-5.701-.453-2.467-5.461a.998.998 0 0 0-1.822-.001L8.622 8.05l-5.701.453a1 1 0 0 0-.619 1.713l4.213 4.107-1.49 6.452a1 1 0 0 0 1.53 1.057L12 18.202l5.445 3.63a1.001 1.001 0 0 0 1.517-1.106l-1.829-6.4 4.536-4.082c.297-.268.406-.686.278-1.065z"
|
|
884
|
-
})
|
|
885
|
-
});
|
|
886
|
-
};
|
|
887
|
-
|
|
888
|
-
//#endregion
|
|
889
|
-
//#region src/components/questions/Rating.tsx
|
|
890
|
-
const StarRatingDisplay = ({ state, properties, classNames }) => {
|
|
891
|
-
const selectedValue = state.selectedValue ? Number(state.selectedValue) : null;
|
|
892
|
-
return /* @__PURE__ */ jsx("div", {
|
|
893
|
-
className: clsx("cf-rating-display-star", classNames?.ratingDisplayStar),
|
|
894
|
-
children: Array.from({ length: properties.scale }, (_, index) => {
|
|
895
|
-
const value = index + 1;
|
|
896
|
-
const radioValue = String(value);
|
|
897
|
-
const isFilled = selectedValue && value <= selectedValue;
|
|
898
|
-
return /* @__PURE__ */ jsx(Radio, {
|
|
899
|
-
className: clsx("cf-rating-star", classNames?.ratingStar),
|
|
900
|
-
value: radioValue,
|
|
901
|
-
"data-filled": isFilled ? "true" : void 0,
|
|
902
|
-
children: isFilled ? /* @__PURE__ */ jsx(StarSolid, {}) : /* @__PURE__ */ jsx(Star, {})
|
|
903
|
-
}, index);
|
|
904
|
-
})
|
|
905
|
-
});
|
|
906
|
-
};
|
|
907
|
-
const NumberRatingDisplay = ({ properties, classNames }) => {
|
|
908
|
-
return /* @__PURE__ */ jsx("div", {
|
|
909
|
-
className: clsx("cf-rating-display-number", classNames?.ratingDisplayNumber),
|
|
910
|
-
children: Array.from({ length: properties.scale }, (_, index) => {
|
|
911
|
-
const value = index + 1;
|
|
912
|
-
const radioValue = String(value);
|
|
913
|
-
return /* @__PURE__ */ jsx(Radio, {
|
|
914
|
-
className: clsx("cf-rating-number", classNames?.ratingNumber),
|
|
915
|
-
value: radioValue,
|
|
916
|
-
children: value
|
|
917
|
-
}, index);
|
|
918
|
-
})
|
|
919
|
-
});
|
|
920
|
-
};
|
|
921
|
-
const EmojiRatingDisplay = ({ properties, classNames, state }) => {
|
|
922
|
-
const EMOJI_FIVE = useMemo(() => [
|
|
923
|
-
EmojiAngry,
|
|
924
|
-
EmojiFrown,
|
|
925
|
-
EmojiMeh,
|
|
926
|
-
EmojiSmile,
|
|
927
|
-
EmojiBeaming
|
|
928
|
-
], []);
|
|
929
|
-
const EMOJI_THREE = useMemo(() => [
|
|
930
|
-
EmojiFrown,
|
|
931
|
-
EmojiMeh,
|
|
932
|
-
EmojiSmile
|
|
933
|
-
], []);
|
|
934
|
-
if (!useMemo(() => {
|
|
935
|
-
return properties.scale === 3 || properties.scale === 5;
|
|
936
|
-
}, [properties.scale])) return /* @__PURE__ */ jsx(NumberRatingDisplay, {
|
|
937
|
-
properties,
|
|
938
|
-
classNames,
|
|
939
|
-
state
|
|
940
|
-
});
|
|
941
|
-
return /* @__PURE__ */ jsx("div", {
|
|
942
|
-
className: clsx("cf-rating-display-emoji", classNames?.ratingDisplayEmoji),
|
|
943
|
-
children: Array.from({ length: properties.scale }, (_, index) => {
|
|
944
|
-
const value = index + 1;
|
|
945
|
-
const radioValue = String(value);
|
|
946
|
-
const Emoji = properties.scale === 5 ? EMOJI_FIVE[index] : EMOJI_THREE[index];
|
|
947
|
-
return /* @__PURE__ */ jsx(Radio, {
|
|
948
|
-
className: clsx("cf-rating-emoji", classNames?.ratingEmoji),
|
|
949
|
-
value: radioValue,
|
|
950
|
-
children: Emoji && /* @__PURE__ */ jsx(Emoji, {})
|
|
951
|
-
}, index);
|
|
952
|
-
})
|
|
953
|
-
});
|
|
954
|
-
};
|
|
955
|
-
const RatingDisplay = (props) => {
|
|
956
|
-
switch (props.properties.display ?? "star") {
|
|
957
|
-
case "emoji": return /* @__PURE__ */ jsx(EmojiRatingDisplay, { ...props });
|
|
958
|
-
case "number": return /* @__PURE__ */ jsx(NumberRatingDisplay, { ...props });
|
|
959
|
-
case "star": return /* @__PURE__ */ jsx(StarRatingDisplay, { ...props });
|
|
960
|
-
}
|
|
961
|
-
};
|
|
962
|
-
const Rating = ({ properties, title, description, classNames, onChange, id, error, required }) => {
|
|
963
|
-
const [selected, setSelected] = useState(null);
|
|
964
|
-
const submissionValue = useMemo(() => {
|
|
965
|
-
return selected ? Number(selected) : void 0;
|
|
966
|
-
}, [selected]);
|
|
967
|
-
useEffect(() => {
|
|
968
|
-
onChange(submissionValue);
|
|
969
|
-
}, [onChange, submissionValue]);
|
|
970
|
-
return /* @__PURE__ */ jsx(RadioGroup, {
|
|
971
|
-
isRequired: required,
|
|
972
|
-
isInvalid: !!error,
|
|
973
|
-
name: id,
|
|
974
|
-
className: clsx("cf-question", classNames?.question),
|
|
975
|
-
value: selected,
|
|
976
|
-
onChange: setSelected,
|
|
977
|
-
children: ({ state }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
978
|
-
/* @__PURE__ */ jsxs("div", {
|
|
979
|
-
className: clsx("cf-header", classNames?.header),
|
|
980
|
-
children: [/* @__PURE__ */ jsxs(Label, {
|
|
981
|
-
className: clsx("cf-title", classNames?.title),
|
|
982
|
-
children: [title, !required && /* @__PURE__ */ jsxs("span", {
|
|
983
|
-
className: clsx("cf-label-optional", classNames?.optionalLabel),
|
|
984
|
-
children: [" ", "(optional)"]
|
|
985
|
-
})]
|
|
986
|
-
}), description && /* @__PURE__ */ jsx(Text, {
|
|
987
|
-
slot: "description",
|
|
988
|
-
className: clsx("cf-description", classNames?.description),
|
|
989
|
-
children: description
|
|
990
|
-
})]
|
|
991
|
-
}),
|
|
992
|
-
/* @__PURE__ */ jsxs("div", {
|
|
993
|
-
className: clsx("cf-rating-section", classNames?.ratingSection),
|
|
994
|
-
children: [/* @__PURE__ */ jsx(RatingDisplay, {
|
|
995
|
-
state,
|
|
996
|
-
properties,
|
|
997
|
-
classNames
|
|
998
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
999
|
-
className: clsx("cf-rating-text", classNames?.ratingText),
|
|
1000
|
-
children: [/* @__PURE__ */ jsx("span", {
|
|
1001
|
-
className: clsx("cf-rating-text-lower", classNames?.ratingTextLower),
|
|
1002
|
-
children: properties.labels?.lower
|
|
1003
|
-
}), /* @__PURE__ */ jsx("span", {
|
|
1004
|
-
className: clsx("cf-rating-text-upper", classNames?.ratingTextUpper),
|
|
1005
|
-
children: properties.labels?.upper
|
|
1006
|
-
})]
|
|
1007
|
-
})]
|
|
1008
|
-
}),
|
|
1009
|
-
/* @__PURE__ */ jsx(FieldError, {
|
|
1010
|
-
className: clsx("cf-error", classNames?.error),
|
|
1011
|
-
children: error
|
|
1012
|
-
})
|
|
1013
|
-
] })
|
|
1014
|
-
});
|
|
1015
|
-
};
|
|
1016
|
-
|
|
1017
|
-
//#endregion
|
|
1018
|
-
//#region src/components/questions/SingleChoice.tsx
|
|
1019
|
-
const SingleChoiceRadio = ({ classNames, className, description, ...props }) => {
|
|
1020
|
-
return /* @__PURE__ */ jsx(Radio, {
|
|
1021
|
-
...props,
|
|
1022
|
-
className: clsx(className, classNames?.radio),
|
|
1023
|
-
children: composeRenderProps(props.children, (children) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
|
|
1024
|
-
className: clsx("cf-choice-label", classNames?.label),
|
|
1025
|
-
children: [/* @__PURE__ */ jsx("div", { className: clsx("cf-radio-indicator", classNames?.indicator) }), children]
|
|
1026
|
-
}), description && /* @__PURE__ */ jsx("span", {
|
|
1027
|
-
className: clsx("cf-choice-description", classNames?.choiceDescription),
|
|
1028
|
-
children: description
|
|
1029
|
-
})] }))
|
|
1030
|
-
});
|
|
1031
|
-
};
|
|
1032
|
-
const SingleChoice = ({ title, description, properties, classNames, onChange, id, required, error }) => {
|
|
1033
|
-
const [value, setValue] = useState(null);
|
|
1034
|
-
const [othersValue, setOthersValue] = useState("");
|
|
1035
|
-
const hasEditable = !!properties.editable;
|
|
1036
|
-
const othersRef = useRef(null);
|
|
1037
|
-
const othersInputRef = useRef(null);
|
|
1038
|
-
const submissionValue = useMemo(() => {
|
|
1039
|
-
if (value === RADIO_OTHERS_VALUE) return othersValue || RADIO_OTHERS_VALUE;
|
|
1040
|
-
return value ?? void 0;
|
|
1041
|
-
}, [othersValue, value]);
|
|
1042
|
-
useEffect(() => {
|
|
1043
|
-
onChange(submissionValue);
|
|
1044
|
-
}, [onChange, submissionValue]);
|
|
1045
|
-
return /* @__PURE__ */ jsx(RadioGroup, {
|
|
1046
|
-
isRequired: required,
|
|
1047
|
-
isInvalid: !!error,
|
|
1048
|
-
name: id,
|
|
1049
|
-
onChange: (key) => {
|
|
1050
|
-
setValue(key);
|
|
1051
|
-
if (key === RADIO_OTHERS_VALUE) requestAnimationFrame(() => {
|
|
1052
|
-
if (!othersInputRef.current) return;
|
|
1053
|
-
othersInputRef.current.focus();
|
|
1054
|
-
});
|
|
1055
|
-
},
|
|
1056
|
-
value,
|
|
1057
|
-
className: clsx("cf-question", classNames?.question),
|
|
1058
|
-
children: ({ state }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1059
|
-
/* @__PURE__ */ jsxs("div", {
|
|
1060
|
-
className: clsx("cf-header", classNames?.header),
|
|
1061
|
-
children: [/* @__PURE__ */ jsxs(Label, {
|
|
1062
|
-
className: clsx("cf-title", classNames?.title),
|
|
1063
|
-
children: [title, !required && /* @__PURE__ */ jsxs("span", {
|
|
1064
|
-
className: clsx("cf-label-optional", classNames?.optionalLabel),
|
|
1065
|
-
children: [" ", "(optional)"]
|
|
1066
|
-
})]
|
|
1067
|
-
}), description && /* @__PURE__ */ jsx(Text, {
|
|
1068
|
-
slot: "description",
|
|
1069
|
-
className: clsx("cf-description", classNames?.description),
|
|
1070
|
-
children: description
|
|
1071
|
-
})]
|
|
1072
|
-
}),
|
|
1073
|
-
/* @__PURE__ */ jsxs("div", {
|
|
1074
|
-
className: clsx("cf-response-choices", classNames?.group),
|
|
1075
|
-
children: [properties.options.map((option, index) => /* @__PURE__ */ jsx(SingleChoiceRadio, {
|
|
1076
|
-
classNames: {
|
|
1077
|
-
indicator: classNames?.indicator,
|
|
1078
|
-
radio: clsx("cf-choice cf-radio", classNames?.radio)
|
|
1079
|
-
},
|
|
1080
|
-
value: option.value,
|
|
1081
|
-
description: option.description,
|
|
1082
|
-
children: option.value
|
|
1083
|
-
}, index)), hasEditable && /* @__PURE__ */ jsxs("div", {
|
|
1084
|
-
className: clsx("cf-choice cf-others-choice", classNames?.othersChoice),
|
|
1085
|
-
children: [/* @__PURE__ */ jsx(SingleChoiceRadio, {
|
|
1086
|
-
inputRef: othersRef,
|
|
1087
|
-
value: RADIO_OTHERS_VALUE,
|
|
1088
|
-
classNames: {
|
|
1089
|
-
indicator: classNames?.indicator,
|
|
1090
|
-
radio: clsx("cf-radio", classNames?.radio)
|
|
1091
|
-
},
|
|
1092
|
-
description: properties.editable?.description,
|
|
1093
|
-
children: properties.editable?.label
|
|
1094
|
-
}), /* @__PURE__ */ jsx(Input, {
|
|
1095
|
-
tabIndex: state.selectedValue === RADIO_OTHERS_VALUE ? 0 : -1,
|
|
1096
|
-
ref: othersInputRef,
|
|
1097
|
-
value: othersValue,
|
|
1098
|
-
onChange: (e) => setOthersValue(e.target.value),
|
|
1099
|
-
onFocus: () => {
|
|
1100
|
-
if (othersRef.current?.checked === false) othersRef.current.click();
|
|
1101
|
-
},
|
|
1102
|
-
className: clsx("cf-input", classNames?.othersInput)
|
|
1103
|
-
})]
|
|
1104
|
-
})]
|
|
1105
|
-
}),
|
|
1106
|
-
/* @__PURE__ */ jsx(FieldError, {
|
|
1107
|
-
className: clsx("cf-error", classNames?.error),
|
|
1108
|
-
children: error
|
|
1109
|
-
})
|
|
1110
|
-
] })
|
|
1111
|
-
});
|
|
1112
|
-
};
|
|
1113
|
-
|
|
1114
|
-
//#endregion
|
|
1115
|
-
//#region src/components/questions/Statement.tsx
|
|
1116
|
-
const Statement = ({ properties: _properties, title, description, classNames }) => {
|
|
1117
|
-
return /* @__PURE__ */ jsx("div", {
|
|
1118
|
-
className: clsx("cf-question", classNames?.question),
|
|
1119
|
-
children: /* @__PURE__ */ jsxs("div", {
|
|
1120
|
-
className: clsx("cf-header", classNames?.header),
|
|
1121
|
-
children: [title && /* @__PURE__ */ jsx("div", {
|
|
1122
|
-
className: clsx("cf-title", classNames?.title),
|
|
1123
|
-
children: title
|
|
1124
|
-
}), description && /* @__PURE__ */ jsx("div", {
|
|
1125
|
-
className: clsx("cf-description", classNames?.description),
|
|
1126
|
-
children: description
|
|
1127
|
-
})]
|
|
1128
|
-
})
|
|
1129
|
-
});
|
|
1130
|
-
};
|
|
1131
|
-
|
|
1132
|
-
//#endregion
|
|
1133
|
-
//#region src/components/questions/factory.tsx
|
|
1134
|
-
const SurveyQuestionFactory = ({ question, onChange, error }) => {
|
|
1135
|
-
switch (question.properties.type) {
|
|
1136
|
-
case "rating": return /* @__PURE__ */ jsx(Rating, {
|
|
1137
|
-
...question,
|
|
1138
|
-
properties: question.properties,
|
|
1139
|
-
onChange,
|
|
1140
|
-
error
|
|
1141
|
-
}, question.id);
|
|
1142
|
-
case "open-ended": return /* @__PURE__ */ jsx(FreeText, {
|
|
1143
|
-
...question,
|
|
1144
|
-
properties: question.properties,
|
|
1145
|
-
onChange,
|
|
1146
|
-
error
|
|
1147
|
-
}, question.id);
|
|
1148
|
-
case "single-select": return /* @__PURE__ */ jsx(SingleChoice, {
|
|
1149
|
-
...question,
|
|
1150
|
-
properties: question.properties,
|
|
1151
|
-
onChange,
|
|
1152
|
-
error
|
|
1153
|
-
}, question.id);
|
|
1154
|
-
case "multi-select": return /* @__PURE__ */ jsx(MultiChoice, {
|
|
1155
|
-
...question,
|
|
1156
|
-
properties: question.properties,
|
|
1157
|
-
onChange,
|
|
1158
|
-
error
|
|
1159
|
-
}, question.id);
|
|
1160
|
-
case "statement": return /* @__PURE__ */ jsx(Statement, {
|
|
1161
|
-
...question,
|
|
1162
|
-
properties: question.properties,
|
|
1163
|
-
onChange,
|
|
1164
|
-
error
|
|
1165
|
-
}, question.id);
|
|
1166
|
-
}
|
|
1167
|
-
return /* @__PURE__ */ jsx("div", { children: "Unsupported question type" }, question.id);
|
|
1168
|
-
};
|
|
1169
|
-
|
|
1170
|
-
//#endregion
|
|
1171
|
-
//#region src/components/SubmitButton.tsx
|
|
1172
|
-
const SubmitButton = ({ onPress, isDisabled, children = "Submit" }) => {
|
|
1173
|
-
return /* @__PURE__ */ jsx(Button, {
|
|
1174
|
-
isDisabled,
|
|
1175
|
-
className: "cf-submit-button",
|
|
1176
|
-
onPress,
|
|
1177
|
-
children
|
|
1178
|
-
});
|
|
1179
|
-
};
|
|
1180
|
-
|
|
1181
|
-
//#endregion
|
|
1182
|
-
//#region src/components/presentation/Flow.tsx
|
|
1183
|
-
const getInitialState = (type) => {
|
|
1184
|
-
switch (type) {
|
|
1185
|
-
case "multi-select": return [];
|
|
1186
|
-
case "statement": return;
|
|
1187
|
-
default: return "";
|
|
1188
|
-
}
|
|
1189
|
-
};
|
|
1190
|
-
const Flow = ({ onSubmit, children, question, isLastQuestion }) => {
|
|
1191
|
-
const [answer, setAnswer] = useState(getInitialState(question.properties.type));
|
|
1192
|
-
const validator = useMemo(() => getAnswerValidator(question.properties, { required: question.required }), [question.properties, question.required]);
|
|
1193
|
-
const error = useMemo(() => {
|
|
1194
|
-
const parseResult = validator.safeParse(answer);
|
|
1195
|
-
if (parseResult.success) return;
|
|
1196
|
-
return prettifyError(parseResult.error);
|
|
1197
|
-
}, [answer, validator]);
|
|
1198
|
-
const hasNextQuestion = useMemo(() => {
|
|
1199
|
-
const rule = question.routingLogic;
|
|
1200
|
-
if (rule.type !== "always" && (answer === "" || Array.isArray(answer) && answer.length === 0) && question.required) return true;
|
|
1201
|
-
const match = rule.type === "always" ? rule.target : rule.cases.find((condition) => evaluateCondition({
|
|
1202
|
-
answer,
|
|
1203
|
-
condition
|
|
1204
|
-
}))?.target ?? rule.default;
|
|
1205
|
-
if (match.type === "end") return false;
|
|
1206
|
-
if (match.type === "next") return !isLastQuestion;
|
|
1207
|
-
return true;
|
|
1208
|
-
}, [
|
|
1209
|
-
answer,
|
|
1210
|
-
isLastQuestion,
|
|
1211
|
-
question.required,
|
|
1212
|
-
question.routingLogic
|
|
1213
|
-
]);
|
|
1214
|
-
const buttonLabel = useMemo(() => {
|
|
1215
|
-
if (question.properties.buttonLabel) return question.properties.buttonLabel;
|
|
1216
|
-
return hasNextQuestion ? "Next" : "Submit";
|
|
1217
|
-
}, [hasNextQuestion, question.properties.buttonLabel]);
|
|
1218
|
-
const handleSubmitPressed = useCallback(() => {
|
|
1219
|
-
switch (question.properties.type) {
|
|
1220
|
-
case "statement":
|
|
1221
|
-
if (question.properties.buttonUrl && typeof window !== "undefined") {
|
|
1222
|
-
const validatedUrl = urlSchema.safeParse(question.properties.buttonUrl).data;
|
|
1223
|
-
if (validatedUrl) window.open(validatedUrl, "_blank");
|
|
1224
|
-
}
|
|
1225
|
-
return onSubmit(void 0);
|
|
1226
|
-
default: return onSubmit(answer);
|
|
1227
|
-
}
|
|
1228
|
-
}, [
|
|
1229
|
-
answer,
|
|
1230
|
-
onSubmit,
|
|
1231
|
-
question.properties
|
|
1232
|
-
]);
|
|
1233
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [children({
|
|
1234
|
-
onChange: setAnswer,
|
|
1235
|
-
question,
|
|
1236
|
-
error
|
|
1237
|
-
}), /* @__PURE__ */ jsx(SubmitButton, {
|
|
1238
|
-
isDisabled: !!error,
|
|
1239
|
-
onPress: handleSubmitPressed,
|
|
1240
|
-
children: buttonLabel
|
|
1241
|
-
})] });
|
|
1242
|
-
};
|
|
1243
|
-
|
|
1244
|
-
//#endregion
|
|
1245
|
-
//#region src/components/presentation/Embed.tsx
|
|
1246
|
-
const Embed = ({ isCompleted, onSubmit, children }) => {
|
|
1247
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [children, isCompleted && /* @__PURE__ */ jsx(SubmitButton, { onPress: onSubmit })] });
|
|
1248
|
-
};
|
|
1249
|
-
|
|
1250
|
-
//#endregion
|
|
1251
|
-
//#region src/templates/EmbeddedConfetti.tsx
|
|
1252
|
-
const EmbeddedConfetti = (props) => {
|
|
1253
|
-
return /* @__PURE__ */ jsx(Confetti, {
|
|
1254
|
-
...props,
|
|
1255
|
-
shouldAutoSubmit: false,
|
|
1256
|
-
children: ({ questions, update, isCompleted, submit, isSubmitted }) => {
|
|
1257
|
-
if (isSubmitted) return /* @__PURE__ */ jsx(ThankYouMessage, {});
|
|
1258
|
-
return /* @__PURE__ */ jsx(Embed, {
|
|
1259
|
-
onSubmit: submit,
|
|
1260
|
-
isCompleted,
|
|
1261
|
-
children: questions.filter(({ visible }) => !!visible).map((question) => {
|
|
1262
|
-
return /* @__PURE__ */ jsx(SurveyQuestionFactory, {
|
|
1263
|
-
question,
|
|
1264
|
-
onChange: (answer) => answer && update({
|
|
1265
|
-
question: question.position,
|
|
1266
|
-
answer
|
|
1267
|
-
})
|
|
1268
|
-
}, question.position);
|
|
1269
|
-
})
|
|
1270
|
-
});
|
|
1271
|
-
}
|
|
1272
|
-
});
|
|
1273
|
-
};
|
|
1274
|
-
|
|
1275
|
-
//#endregion
|
|
1276
|
-
//#region src/templates/PopoverConfetti.tsx
|
|
1277
|
-
const PopoverConfetti = ({ onDismiss, closeOnFinishMs, ...props }) => {
|
|
1278
|
-
return /* @__PURE__ */ jsx(ConfettiProvider, {
|
|
1279
|
-
...props,
|
|
1280
|
-
children: /* @__PURE__ */ jsx(PopoverContainer, {
|
|
1281
|
-
onDismiss,
|
|
1282
|
-
closeOnFinishMs,
|
|
1283
|
-
children: ({ setIsFinished }) => /* @__PURE__ */ jsx(ConfettiController, {
|
|
1284
|
-
shouldAutoSubmit: true,
|
|
1285
|
-
...props,
|
|
1286
|
-
onFinished: () => {
|
|
1287
|
-
setIsFinished();
|
|
1288
|
-
props.onFinished?.();
|
|
1289
|
-
},
|
|
1290
|
-
children: ({ current, questions, update, isSubmitted }) => {
|
|
1291
|
-
const isLastQuestion = current === questions.length - 1;
|
|
1292
|
-
if (isSubmitted) return /* @__PURE__ */ jsx(ThankYouMessage, {});
|
|
1293
|
-
const currentQuestion = questions[current];
|
|
1294
|
-
if (!currentQuestion) return /* @__PURE__ */ jsx(Fragment, {});
|
|
1295
|
-
return /* @__PURE__ */ jsx(Flow, {
|
|
1296
|
-
isLastQuestion,
|
|
1297
|
-
question: currentQuestion,
|
|
1298
|
-
onSubmit: (answer) => {
|
|
1299
|
-
return update({
|
|
1300
|
-
question: current,
|
|
1301
|
-
answer
|
|
1302
|
-
});
|
|
1303
|
-
},
|
|
1304
|
-
children: (flowProps) => /* @__PURE__ */ jsx(SurveyQuestionFactory, { ...flowProps })
|
|
1305
|
-
});
|
|
1306
|
-
}
|
|
1307
|
-
})
|
|
1308
|
-
})
|
|
1309
|
-
});
|
|
1310
|
-
};
|
|
1311
|
-
|
|
1312
|
-
//#endregion
|
|
1313
|
-
//#region src/templates/StepperConfetti.tsx
|
|
1314
|
-
const StepperConfetti = (props) => {
|
|
1315
|
-
return /* @__PURE__ */ jsx(Confetti, {
|
|
1316
|
-
...props,
|
|
1317
|
-
shouldAutoSubmit: true,
|
|
1318
|
-
children: ({ current, questions, update, isSubmitted }) => {
|
|
1319
|
-
const isLastQuestion = current === questions.length - 1;
|
|
1320
|
-
if (isSubmitted) return /* @__PURE__ */ jsx(ThankYouMessage, {});
|
|
1321
|
-
const currentQuestion = questions[current];
|
|
1322
|
-
if (!currentQuestion) return /* @__PURE__ */ jsx(Fragment, {});
|
|
1323
|
-
return /* @__PURE__ */ jsx(Flow, {
|
|
1324
|
-
isLastQuestion,
|
|
1325
|
-
question: currentQuestion,
|
|
1326
|
-
onSubmit: (answer) => {
|
|
1327
|
-
return update({
|
|
1328
|
-
question: current,
|
|
1329
|
-
answer
|
|
1330
|
-
});
|
|
1331
|
-
},
|
|
1332
|
-
children: (flowProps) => /* @__PURE__ */ jsx(SurveyQuestionFactory, { ...flowProps })
|
|
1333
|
-
});
|
|
1334
|
-
}
|
|
1335
|
-
});
|
|
1336
|
-
};
|
|
1337
|
-
|
|
1338
|
-
//#endregion
|
|
1339
|
-
//#region src/hooks/useVisibleAfterDelay.ts
|
|
1340
|
-
const useVisibleAfterDelay = ({ delay }) => {
|
|
1341
|
-
const [isVisible$1, setIsVisible] = useState(false);
|
|
1342
|
-
const initialDelay = useMemo(() => delay, []);
|
|
1343
|
-
useEffect(() => {
|
|
1344
|
-
const timeoutId = setTimeout(() => {
|
|
1345
|
-
setIsVisible(true);
|
|
1346
|
-
}, initialDelay);
|
|
1347
|
-
return () => clearTimeout(timeoutId);
|
|
1348
|
-
}, []);
|
|
1349
|
-
return { isVisible: isVisible$1 };
|
|
1350
|
-
};
|
|
1351
|
-
|
|
1352
|
-
//#endregion
|
|
1353
|
-
//#region src/hooks/useVisibleAfterPageVisits.ts
|
|
1354
|
-
const useVisibleAfterPageVisits = ({ visits, respondent }) => {
|
|
1355
|
-
const [visitCount, setVisitCount] = useLocalStorage(`cfti:${useMemo(() => window.location.pathname, [])}:visits:${respondent ?? ""}`, 0);
|
|
1356
|
-
useEffect(() => {
|
|
1357
|
-
setVisitCount((prev) => prev + 1);
|
|
1358
|
-
}, [setVisitCount]);
|
|
1359
|
-
return {
|
|
1360
|
-
isVisible: visitCount >= visits,
|
|
1361
|
-
reset: useCallback(() => setVisitCount(0), [setVisitCount])
|
|
1362
|
-
};
|
|
1363
|
-
};
|
|
1364
|
-
const useVisibleAfterSessionPageVisits = ({ visits, respondent }) => {
|
|
1365
|
-
const [visitCount, setVisitCount] = useSessionStorage(`cfti:${useMemo(() => window.location.pathname, [])}:visits:${respondent ?? ""}`, 0);
|
|
1366
|
-
useEffect(() => {
|
|
1367
|
-
setVisitCount((prev) => prev + 1);
|
|
1368
|
-
}, [setVisitCount]);
|
|
1369
|
-
return {
|
|
1370
|
-
isVisible: visitCount >= visits,
|
|
1371
|
-
reset: useCallback(() => setVisitCount(0), [setVisitCount])
|
|
1372
|
-
};
|
|
1373
|
-
};
|
|
1374
|
-
|
|
1375
|
-
//#endregion
|
|
1376
|
-
//#region src/hooks/useVisibleAfterScroll.ts
|
|
1377
|
-
const useVisibleAfterScroll = ({ threshold }) => {
|
|
1378
|
-
const [isVisible$1, setIsVisible] = useState(() => {
|
|
1379
|
-
if (typeof window === "undefined") return false;
|
|
1380
|
-
return window.scrollY >= threshold;
|
|
1381
|
-
});
|
|
1382
|
-
useEffect(() => {
|
|
1383
|
-
const handleScroll = () => {
|
|
1384
|
-
if (window.scrollY >= threshold) setIsVisible(true);
|
|
1385
|
-
};
|
|
1386
|
-
window.addEventListener("scroll", handleScroll, { passive: true });
|
|
1387
|
-
return () => window.removeEventListener("scroll", handleScroll);
|
|
1388
|
-
}, [threshold]);
|
|
1389
|
-
return { isVisible: isVisible$1 };
|
|
1390
|
-
};
|
|
1391
|
-
|
|
1392
|
-
//#endregion
|
|
1393
|
-
export { Confetti, ConfettiContext, ConfettiController, ConfettiProvider, Embed, EmbeddedConfetti, Flow, FreeText, MultiChoice, PopoverConfetti, PopoverContainer, Rating, SingleChoice, Statement, StepperConfetti, SurveyQuestionFactory, ThankYouMessage, useConfetti, useVisibleAfterDelay, useVisibleAfterPageVisits, useVisibleAfterScroll, useVisibleAfterSessionPageVisits };
|
|
1394
|
-
//# sourceMappingURL=index.js.map
|
|
7
|
+
`.trim(),e.head.prepend(t)},[_]),c(()=>{let e=x.current;return()=>{g||Dn(e.target??void 0);for(let t of e.disposables)t();e.disposables=[]}},[g]),{isPressed:p||y,pressProps:B(v,ce,{[zn]:!0})}}function Bn(e){return e.tagName===`A`&&e.hasAttribute(`href`)}function Vn(e,t){let{key:n,code:r}=e,i=t,a=i.getAttribute(`role`);return(n===`Enter`||n===` `||n===`Spacebar`||r===`Space`)&&!(i instanceof L(i).HTMLInputElement&&!Gn(i,n)||i instanceof L(i).HTMLTextAreaElement||i.isContentEditable)&&!((a===`link`||!a&&Bn(i))&&n!==`Enter`)}function Z(e,t){let n=t.clientX,r=t.clientY;return{currentTarget:e,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,altKey:t.altKey,clientX:n,clientY:r}}function Hn(e){return e instanceof HTMLInputElement?!1:e instanceof HTMLButtonElement?e.type!==`submit`&&e.type!==`reset`:!Bn(e)}function Un(e,t){return e instanceof HTMLInputElement?!Gn(e,t):Hn(e)}const Wn=new Set([`checkbox`,`radio`,`range`,`color`,`file`,`image`,`button`,`submit`,`reset`]);function Gn(e,t){return e.type===`checkbox`||e.type===`radio`?t===` `:Wn.has(e.type)}let Q=null,Kn=new Set,qn=new Map,$=!1,Jn=!1;const Yn={Tab:!0,Escape:!0};function Xn(e,t){for(let n of Kn)n(e,t)}function Zn(e){return!(e.metaKey||!vt()&&e.altKey||e.ctrlKey||e.key===`Control`||e.key===`Shift`||e.key===`Meta`)}function Qn(e){$=!0,!U.isOpening&&Zn(e)&&(Q=`keyboard`,Xn(`keyboard`,e))}function $n(e){Q=`pointer`,`pointerType`in e&&e.pointerType,(e.type===`mousedown`||e.type===`pointerdown`)&&($=!0,Xn(`pointer`,e))}function er(e){!U.isOpening&&Ft(e)&&($=!0,Q=`virtual`)}function tr(e){e.target===window||e.target===document||Sn||!e.isTrusted||(!$&&!Jn&&(Q=`virtual`,Xn(`virtual`,e)),$=!1,Jn=!1)}function nr(){Sn||($=!1,Jn=!0)}function rr(e){if(typeof window>`u`||typeof document>`u`||qn.get(L(e)))return;let t=L(e),n=I(e),r=t.HTMLElement.prototype.focus;t.HTMLElement.prototype.focus=function(){$=!0,r.apply(this,arguments)},n.addEventListener(`keydown`,Qn,!0),n.addEventListener(`keyup`,Qn,!0),n.addEventListener(`click`,er,!0),t.addEventListener(`focus`,tr,!0),t.addEventListener(`blur`,nr,!1),typeof PointerEvent<`u`&&(n.addEventListener(`pointerdown`,$n,!0),n.addEventListener(`pointermove`,$n,!0),n.addEventListener(`pointerup`,$n,!0)),t.addEventListener(`beforeunload`,()=>{ir(e)},{once:!0}),qn.set(t,{focus:r})}const ir=(e,t)=>{let n=L(e),r=I(e);t&&r.removeEventListener(`DOMContentLoaded`,t),qn.has(n)&&(n.HTMLElement.prototype.focus=qn.get(n).focus,r.removeEventListener(`keydown`,Qn,!0),r.removeEventListener(`keyup`,Qn,!0),r.removeEventListener(`click`,er,!0),n.removeEventListener(`focus`,tr,!0),n.removeEventListener(`blur`,nr,!1),typeof PointerEvent<`u`&&(r.removeEventListener(`pointerdown`,$n,!0),r.removeEventListener(`pointermove`,$n,!0),r.removeEventListener(`pointerup`,$n,!0)),qn.delete(n))};function ar(e){let t=I(e),n;return t.readyState===`loading`?(n=()=>{rr(e)},t.addEventListener(`DOMContentLoaded`,n)):rr(e),()=>ir(e,n)}typeof document<`u`&&ar();function or(){return Q!==`pointer`}function sr(){return Q}function cr(e){Q=e,Xn(e,null)}const lr=new Set([`checkbox`,`radio`,`range`,`color`,`file`,`image`,`button`,`submit`,`reset`]);function ur(e,t,n){let r=I(n?.target),i=typeof window<`u`?L(n?.target).HTMLInputElement:HTMLInputElement,a=typeof window<`u`?L(n?.target).HTMLTextAreaElement:HTMLTextAreaElement,o=typeof window<`u`?L(n?.target).HTMLElement:HTMLElement,s=typeof window<`u`?L(n?.target).KeyboardEvent:KeyboardEvent;return e=e||r.activeElement instanceof i&&!lr.has(r.activeElement.type)||r.activeElement instanceof a||r.activeElement instanceof o&&r.activeElement.isContentEditable,!(e&&t===`keyboard`&&n instanceof s&&!Yn[n.key])}function dr(e,t,n){rr(),c(()=>{let t=(t,r)=>{ur(!!n?.isTextInput,t,r)&&e(or())};return Kn.add(t),()=>{Kn.delete(t)}},t)}function fr(e){let t=I(e);if(sr()===`virtual`){let n=et(t);kt(()=>{let r=et(t);(r===n||r===t.body)&&e.isConnected&&dt(e)})}else dt(e)}function pr(e){let{isDisabled:t,onFocus:n,onBlur:r,onFocusChange:i}=e,a=o(e=>{if(e.target===e.currentTarget)return r&&r(e),i&&i(!1),!0},[r,i]),s=xn(a),c=o(e=>{let t=I(e.target),r=t?et(t):et();e.target===e.currentTarget&&r===z(e.nativeEvent)&&(n&&n(e),i&&i(!0),s(e))},[i,n,s]);return{focusProps:{onFocus:!t&&(n||i||r)?c:void 0,onBlur:!t&&(r||i)?a:void 0}}}function mr(e){if(!e)return;let t=!0;return n=>{e({...n,preventDefault(){n.preventDefault()},isDefaultPrevented(){return n.isDefaultPrevented()},stopPropagation(){t=!0},continuePropagation(){t=!1},isPropagationStopped(){return t}}),t&&n.stopPropagation()}}function hr(e){return{keyboardProps:e.isDisabled?{}:{onKeyDown:mr(e.onKeyDown),onKeyUp:mr(e.onKeyUp)}}}let gr=r.createContext(null);function _r(e){let t=s(gr)||{};Pt(t,e);let{ref:n,...r}=t;return r}function vr(e,t){let{focusProps:n}=pr(e),{keyboardProps:r}=hr(e),i=B(n,r),a=_r(t),o=e.isDisabled?{}:a,s=d(e.autoFocus);c(()=>{s.current&&t.current&&fr(t.current),s.current=!1},[t]);let l=e.excludeFromTabOrder?-1:0;return e.isDisabled&&(l=void 0),{focusableProps:B({...i,tabIndex:l},o)}}function yr(e){let{isDisabled:t,onBlurWithin:n,onFocusWithin:r,onFocusWithinChange:i}=e,a=d({isFocusWithin:!1}),{addGlobalListener:s,removeAllGlobalListeners:c}=At(),l=o(e=>{e.currentTarget.contains(e.target)&&a.current.isFocusWithin&&!e.currentTarget.contains(e.relatedTarget)&&(a.current.isFocusWithin=!1,c(),n&&n(e),i&&i(!1))},[n,i,a,c]),u=xn(l),f=o(e=>{if(!e.currentTarget.contains(e.target))return;let t=I(e.target),n=et(t);if(!a.current.isFocusWithin&&n===z(e.nativeEvent)){r&&r(e),i&&i(!0),a.current.isFocusWithin=!0,u(e);let n=e.currentTarget;s(t,`focus`,e=>{if(a.current.isFocusWithin&&!R(n,e.target)){let r=new t.defaultView.FocusEvent(`blur`,{relatedTarget:e.target});bn(r,n),l(yn(r))}},{capture:!0})}},[r,i,u,s,l]);return t?{focusWithinProps:{onFocus:void 0,onBlur:void 0}}:{focusWithinProps:{onFocus:f,onBlur:l}}}let br=!1,xr=0;function Sr(){br=!0,setTimeout(()=>{br=!1},50)}function Cr(e){e.pointerType===`touch`&&Sr()}function wr(){if(!(typeof document>`u`))return xr===0&&typeof PointerEvent<`u`&&document.addEventListener(`pointerup`,Cr),xr++,()=>{xr--,!(xr>0)&&typeof PointerEvent<`u`&&document.removeEventListener(`pointerup`,Cr)}}function Tr(e){let{onHoverStart:t,onHoverChange:n,onHoverEnd:r,isDisabled:i}=e,[a,o]=f(!1),s=d({isHovered:!1,ignoreEmulatedMouseEvents:!1,pointerType:``,target:null}).current;c(wr,[]);let{addGlobalListener:u,removeAllGlobalListeners:p}=At(),{hoverProps:m,triggerHoverEnd:h}=l(()=>{let e=(e,r)=>{if(s.pointerType=r,i||r===`touch`||s.isHovered||!e.currentTarget.contains(e.target))return;s.isHovered=!0;let c=e.currentTarget;s.target=c,u(I(e.target),`pointerover`,e=>{s.isHovered&&s.target&&!R(s.target,e.target)&&a(e,e.pointerType)},{capture:!0}),t&&t({type:`hoverstart`,target:c,pointerType:r}),n&&n(!0),o(!0)},a=(e,t)=>{let i=s.target;s.pointerType=``,s.target=null,!(t===`touch`||!s.isHovered||!i)&&(s.isHovered=!1,p(),r&&r({type:`hoverend`,target:i,pointerType:t}),n&&n(!1),o(!1))},c={};return typeof PointerEvent<`u`&&(c.onPointerEnter=t=>{br&&t.pointerType===`mouse`||e(t,t.pointerType)},c.onPointerLeave=e=>{!i&&e.currentTarget.contains(e.target)&&a(e,e.pointerType)}),{hoverProps:c,triggerHoverEnd:a}},[t,n,r,i,s,u,p]);return c(()=>{i&&h({currentTarget:s.target},s.pointerType)},[i]),{hoverProps:m,isHovered:a}}function Er(e){if(e.checked)return!0;let t=[];return t=e.form?[...e.form?.elements?.namedItem(e.name)??[]]:[...I(e).querySelectorAll(`input[type="radio"][name="${CSS.escape(e.name)}"]`)].filter(e=>!e.form),t?!t.some(e=>e.checked):!1}function Dr(e,t){return!e||!t?!1:t.some(t=>t.contains(e))}function Or(e,t,n){let r=t?.tabbable?Kt:Gt,i=I(e?.nodeType===Node.ELEMENT_NODE?e:null),a=nt(i,e||i,NodeFilter.SHOW_ELEMENT,{acceptNode(e){return t!=null&&t.from?.contains(e)||t?.tabbable&&e.tagName===`INPUT`&&e.getAttribute(`type`)===`radio`&&(!Er(e)||a.currentNode.tagName===`INPUT`&&a.currentNode.type===`radio`&&a.currentNode.name===e.name)?NodeFilter.FILTER_REJECT:r(e)&&(!n||Dr(e,n))&&(!t?.accept||t.accept(e))?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});return t?.from&&(a.currentNode=t.from),a}var kr=class e{get size(){return this.fastMap.size}getTreeNode(e){return this.fastMap.get(e)}addTreeNode(e,t,n){let r=this.fastMap.get(t??null);if(!r)return;let i=new Ar({scopeRef:e});r.addChild(i),i.parent=r,this.fastMap.set(e,i),n&&(i.nodeToRestore=n)}addNode(e){this.fastMap.set(e.scopeRef,e)}removeTreeNode(e){if(e===null)return;let t=this.fastMap.get(e);if(!t)return;let n=t.parent;for(let e of this.traverse())e!==t&&t.nodeToRestore&&e.nodeToRestore&&t.scopeRef&&t.scopeRef.current&&Dr(e.nodeToRestore,t.scopeRef.current)&&(e.nodeToRestore=t.nodeToRestore);let r=t.children;n&&(n.removeChild(t),r.size>0&&r.forEach(e=>n&&n.addChild(e))),this.fastMap.delete(t.scopeRef)}*traverse(e=this.root){if(e.scopeRef!=null&&(yield e),e.children.size>0)for(let t of e.children)yield*this.traverse(t)}clone(){let t=new e;for(let e of this.traverse())t.addTreeNode(e.scopeRef,e.parent?.scopeRef??null,e.nodeToRestore);return t}constructor(){this.fastMap=new Map,this.root=new Ar({scopeRef:null}),this.fastMap.set(null,this.root)}},Ar=class{addChild(e){this.children.add(e),e.parent=this}removeChild(e){this.children.delete(e),e.parent=void 0}constructor(e){this.children=new Set,this.contain=!1,this.scopeRef=e.scopeRef}};new kr;function jr(e={}){let{autoFocus:t=!1,isTextInput:n,within:r}=e,i=d({isFocused:!1,isFocusVisible:t||or()}),[a,s]=f(!1),[c,l]=f(()=>i.current.isFocused&&i.current.isFocusVisible),u=o(()=>l(i.current.isFocused&&i.current.isFocusVisible),[]),p=o(e=>{i.current.isFocused=e,s(e),u()},[u]);dr(e=>{i.current.isFocusVisible=e,u()},[],{isTextInput:n});let{focusProps:m}=pr({isDisabled:r,onFocusChange:p}),{focusWithinProps:h}=yr({isDisabled:!r,onFocusWithinChange:p});return{isFocused:a,isFocusVisible:c,focusProps:r?h:m}}const Mr={border:0,clip:`rect(0 0 0 0)`,clipPath:`inset(50%)`,height:`1px`,margin:`-1px`,overflow:`hidden`,padding:0,position:`absolute`,width:`1px`,whiteSpace:`nowrap`};function Nr(e={}){let{style:t,isFocusable:n}=e,[r,i]=f(!1),{focusWithinProps:a}=yr({isDisabled:!n,onFocusWithinChange:e=>i(e)}),o=l(()=>r?t:t?{...Mr,...t}:Mr,[r]);return{visuallyHiddenProps:{...a,style:o}}}function Pr(e){let{children:t,elementType:n=`div`,isFocusable:i,style:a,...o}=e,{visuallyHiddenProps:s}=Nr(e);return r.createElement(n,B(o,s),t)}function Fr(e){let{id:t,label:n,"aria-labelledby":r,"aria-label":i,labelElementType:a=`label`}=e;t=F(t);let o=F(),s={};n&&(r=r?`${o} ${r}`:o,s={id:o,htmlFor:a===`label`?t:void 0});let c=jt({id:t,"aria-label":i,"aria-labelledby":r});return{labelProps:s,fieldProps:c}}function Ir(e){let{description:t,errorMessage:n,isInvalid:r,validationState:i}=e,{labelProps:a,fieldProps:o}=Fr(e),s=Ye([!!t,!!n,r,i]),c=Ye([!!t,!!n,r,i]);return o=B(o,{"aria-describedby":[s,c,e[`aria-describedby`]].filter(Boolean).join(` `)||void 0}),{labelProps:a,fieldProps:o,descriptionProps:{id:s},errorMessageProps:{id:c}}}const Lr={badInput:!1,customError:!1,patternMismatch:!1,rangeOverflow:!1,rangeUnderflow:!1,stepMismatch:!1,tooLong:!1,tooShort:!1,typeMismatch:!1,valueMissing:!1,valid:!0},Rr={...Lr,customError:!0,valid:!1},zr={isInvalid:!1,validationDetails:Lr,validationErrors:[]},Br=i({}),Vr=`__formValidationState`+Date.now();function Hr(e){if(e[Vr]){let{realtimeValidation:t,displayValidation:n,updateValidation:r,resetValidation:i,commitValidation:a}=e[Vr];return{realtimeValidation:t,displayValidation:n,updateValidation:r,resetValidation:i,commitValidation:a}}return Ur(e)}function Ur(e){let{isInvalid:t,validationState:n,name:r,value:i,builtinValidation:a,validate:o,validationBehavior:u=`aria`}=e;n&&(t||=n===`invalid`);let p=t===void 0?null:{isInvalid:t,validationErrors:[],validationDetails:Rr},m=l(()=>!o||i==null?null:Kr(Gr(o,i)),[o,i]);a?.validationDetails.valid&&(a=void 0);let h=s(Br),g=l(()=>r?Array.isArray(r)?r.flatMap(e=>Wr(h[e])):Wr(h[r]):[],[h,r]),[_,v]=f(h),[y,b]=f(!1);h!==_&&(v(h),b(!1));let x=l(()=>Kr(y?[]:g),[y,g]),S=d(zr),[C,w]=f(zr),T=d(zr),E=()=>{if(!D)return;O(!1);let e=m||a||S.current;qr(e,T.current)||(T.current=e,w(e))},[D,O]=f(!1);return c(E),{realtimeValidation:p||x||m||a||zr,displayValidation:u===`native`?p||x||C:p||x||m||a||C,updateValidation(e){u===`aria`&&!qr(C,e)?w(e):S.current=e},resetValidation(){let e=zr;qr(e,T.current)||(T.current=e,w(e)),u===`native`&&O(!1),b(!0)},commitValidation(){u===`native`&&O(!0),b(!0)}}}function Wr(e){return e?Array.isArray(e)?e:[e]:[]}function Gr(e,t){if(typeof e==`function`){let n=e(t);if(n&&typeof n!=`boolean`)return Wr(n)}return[]}function Kr(e){return e.length?{isInvalid:!0,validationErrors:e,validationDetails:Rr}:null}function qr(e,t){return e===t?!0:!!e&&!!t&&e.isInvalid===t.isInvalid&&e.validationErrors.length===t.validationErrors.length&&e.validationErrors.every((e,n)=>e===t.validationErrors[n])&&Object.entries(e.validationDetails).every(([e,n])=>t.validationDetails[e]===n)}function Jr(...e){let t=new Set,n=!1,r={...Lr};for(let o of e){var i,a;for(let e of o.validationErrors)t.add(e);for(let e in n||=o.isInvalid,r)(i=r)[a=e]||(i[a]=o.validationDetails[e])}return r.valid=!n,{isInvalid:n,validationErrors:[...t],validationDetails:r}}function Yr(e,t,n){let{validationBehavior:r,focus:i}=e;N(()=>{if(r===`native`&&n?.current&&!n.current.disabled){let e=t.realtimeValidation.isInvalid?t.realtimeValidation.validationErrors.join(` `)||`Invalid value.`:``;n.current.setCustomValidity(e),n.current.hasAttribute(`title`)||(n.current.title=``),t.realtimeValidation.isInvalid||t.updateValidation(Zr(n.current))}});let a=d(!1),o=G(()=>{a.current||t.resetValidation()}),s=G(e=>{t.displayValidation.isInvalid||t.commitValidation();let r=n?.current?.form;if(!e.defaultPrevented&&n&&r&&Qr(r)===n.current){var a;i?i():(a=n.current)==null||a.focus(),cr(`keyboard`)}e.preventDefault()}),l=G(()=>{t.commitValidation()});c(()=>{let e=n?.current;if(!e)return;let t=e.form,r=t?.reset;return t&&(t.reset=()=>{a.current=!window.event||window.event.type===`message`&&window.event.target instanceof MessagePort,r?.call(t),a.current=!1}),e.addEventListener(`invalid`,s),e.addEventListener(`change`,l),t?.addEventListener(`reset`,o),()=>{e.removeEventListener(`invalid`,s),e.removeEventListener(`change`,l),t?.removeEventListener(`reset`,o),t&&(t.reset=r)}},[n,r])}function Xr(e){let t=e.validity;return{badInput:t.badInput,customError:t.customError,patternMismatch:t.patternMismatch,rangeOverflow:t.rangeOverflow,rangeUnderflow:t.rangeUnderflow,stepMismatch:t.stepMismatch,tooLong:t.tooLong,tooShort:t.tooShort,typeMismatch:t.typeMismatch,valueMissing:t.valueMissing,valid:t.valid}}function Zr(e){return{isInvalid:!e.validity.valid,validationDetails:Xr(e),validationErrors:e.validationMessage?[e.validationMessage]:[]}}function Qr(e){for(let t=0;t<e.elements.length;t++){let n=e.elements[t];if(!n.validity.valid)return n}return null}function $r(e,t){let{inputElementType:n=`input`,isDisabled:i=!1,isRequired:a=!1,isReadOnly:o=!1,type:s=`text`,validationBehavior:c=`aria`}=e,[l,u]=Yt(e.value,e.defaultValue||``,e.onChange),{focusableProps:d}=vr(e,t),p=Hr({...e,value:l}),{isInvalid:m,validationErrors:h,validationDetails:g}=p.displayValidation,{labelProps:_,fieldProps:v,descriptionProps:y,errorMessageProps:b}=Ir({...e,isInvalid:m,errorMessage:e.errorMessage||h}),x=V(e,{labelable:!0}),S={type:s,pattern:e.pattern},[C]=f(l);return Lt(t,e.defaultValue??C,u),Yr(e,p,t),{labelProps:_,inputProps:B(x,n===`input`?S:void 0,{disabled:i,readOnly:o,required:a&&c===`native`,"aria-required":a&&c===`aria`||void 0,"aria-invalid":m||void 0,"aria-errormessage":e[`aria-errormessage`],"aria-activedescendant":e[`aria-activedescendant`],"aria-autocomplete":e[`aria-autocomplete`],"aria-haspopup":e[`aria-haspopup`],"aria-controls":e[`aria-controls`],value:l,onChange:e=>u(e.target.value),autoComplete:e.autoComplete,autoCapitalize:e.autoCapitalize,maxLength:e.maxLength,minLength:e.minLength,name:e.name,form:e.form,placeholder:e.placeholder,inputMode:e.inputMode,autoCorrect:e.autoCorrect,spellCheck:e.spellCheck,[parseInt(r.version,10)>=17?`enterKeyHint`:`enterkeyhint`]:e.enterKeyHint,onCopy:e.onCopy,onCut:e.onCut,onPaste:e.onPaste,onCompositionEnd:e.onCompositionEnd,onCompositionStart:e.onCompositionStart,onCompositionUpdate:e.onCompositionUpdate,onSelect:e.onSelect,onBeforeInput:e.onBeforeInput,onInput:e.onInput,...d,...v}),descriptionProps:y,errorMessageProps:b,isInvalid:m,validationErrors:h,validationDetails:g}}if(typeof HTMLTemplateElement<`u`){let e=Object.getOwnPropertyDescriptor(Node.prototype,`firstChild`).get;Object.defineProperty(HTMLTemplateElement.prototype,`firstChild`,{configurable:!0,enumerable:!0,get:function(){return this.dataset.reactAriaHidden?this.content.firstChild:e.call(this)}})}const ei=i(!1);function ti(e){let t=(t,n)=>s(ei)?null:e(t,n);return t.displayName=e.displayName||e.name,a(t)}function ni(e,t){let{elementType:n=`button`,isDisabled:r,onPress:i,onPressStart:a,onPressEnd:o,onPressUp:s,onPressChange:c,preventFocusOnPress:l,allowFocusWhenDisabled:u,onClick:d,href:f,target:p,rel:m,type:h=`button`}=e,g;g=n===`button`?{type:h,disabled:r,form:e.form,formAction:e.formAction,formEncType:e.formEncType,formMethod:e.formMethod,formNoValidate:e.formNoValidate,formTarget:e.formTarget,name:e.name,value:e.value}:{role:`button`,href:n===`a`&&!r?f:void 0,target:n===`a`?p:void 0,type:n===`input`?h:void 0,disabled:n===`input`?r:void 0,"aria-disabled":!r||n===`input`?void 0:r,rel:n===`a`?m:void 0};let{pressProps:_,isPressed:v}=X({onPressStart:a,onPressEnd:o,onPressChange:c,onPress:i,onPressUp:s,onClick:d,isDisabled:r,preventFocusOnPress:l,ref:t}),{focusableProps:y}=vr(e,t);u&&(y.tabIndex=r?-1:y.tabIndex);let b=B(y,_,V(e,{labelable:!0}));return{isPressed:v,buttonProps:B(g,b,{"aria-haspopup":e[`aria-haspopup`],"aria-expanded":e[`aria-expanded`],"aria-controls":e[`aria-controls`],"aria-pressed":e[`aria-pressed`],"aria-current":e[`aria-current`],"aria-disabled":e[`aria-disabled`]})}}function ri(e,t,n){let{isDisabled:r=!1,isReadOnly:i=!1,value:a,name:o,form:s,children:c,"aria-label":l,"aria-labelledby":u,validationState:d=`valid`,isInvalid:f,onPressStart:p,onPressEnd:m,onPressChange:h,onPress:g,onPressUp:_,onClick:v}=e,y=e=>{e.stopPropagation(),t.setSelected(e.target.checked)},{pressProps:b,isPressed:x}=X({onPressStart:p,onPressEnd:m,onPressChange:h,onPress:g,onPressUp:_,onClick:v,isDisabled:r}),{pressProps:S,isPressed:C}=X({onPressStart:p,onPressEnd:m,onPressChange:h,onPressUp:_,onClick:v,onPress(e){var r;g?.(e),t.toggle(),(r=n.current)==null||r.focus()},isDisabled:r||i}),{focusableProps:w}=vr(e,n),T=B(b,w),E=V(e,{labelable:!0});return Lt(n,t.defaultSelected,t.setSelected),{labelProps:B(S,{onClick:e=>e.preventDefault()}),inputProps:B(E,{"aria-invalid":f||d===`invalid`||void 0,"aria-errormessage":e[`aria-errormessage`],"aria-controls":e[`aria-controls`],"aria-readonly":i||void 0,onChange:y,disabled:r,...a==null?{}:{value:a},name:o,form:s,type:`checkbox`,...T}),isSelected:t.isSelected,isPressed:x||C,isDisabled:r,isReadOnly:i,isInvalid:f||d===`invalid`}}function ii(e,t,n){let r=Hr({...e,value:t.isSelected}),{isInvalid:i,validationErrors:a,validationDetails:o}=r.displayValidation,{labelProps:s,inputProps:u,isSelected:d,isPressed:f,isDisabled:p,isReadOnly:m}=ri({...e,isInvalid:i},t,n);Yr(e,r,n);let{isIndeterminate:h,isRequired:g,validationBehavior:_=`aria`}=e;c(()=>{n.current&&(n.current.indeterminate=!!h)});let{pressProps:v}=X({isDisabled:p||m,onPress(){let{[Vr]:t}=e,{commitValidation:n}=t||r;n()}});return{labelProps:B(s,v,l(()=>({onMouseDown:e=>e.preventDefault()}),[])),inputProps:{...u,checked:d,"aria-required":g&&_===`aria`||void 0,required:g&&_===`native`},isSelected:d,isPressed:f,isDisabled:p,isReadOnly:m,isInvalid:i,validationErrors:a,validationDetails:o}}const ai=new WeakMap;function oi(e,t){let{isDisabled:n,name:r,form:i,validationBehavior:a=`aria`}=e,{isInvalid:o,validationErrors:s,validationDetails:c}=t.displayValidation,{labelProps:l,fieldProps:u,descriptionProps:d,errorMessageProps:f}=Ir({...e,labelElementType:`span`,isInvalid:o,errorMessage:e.errorMessage||s});ai.set(t,{name:r,form:i,descriptionId:d.id,errorMessageId:f.id,validationBehavior:a});let p=V(e,{labelable:!0}),{focusWithinProps:m}=yr({onBlurWithin:e.onBlur,onFocusWithin:e.onFocus,onFocusWithinChange:e.onFocusChange});return{groupProps:B(p,{role:`group`,"aria-disabled":n||void 0,...u,...m}),labelProps:l,descriptionProps:d,errorMessageProps:f,isInvalid:o,validationErrors:s,validationDetails:c}}function si(e={}){let{isReadOnly:t}=e,[n,r]=Yt(e.isSelected,e.defaultSelected||!1,e.onChange),[i]=f(n);function a(e){t||r(e)}function o(){t||r(!n)}return{isSelected:n,defaultSelected:e.defaultSelected??i,setSelected:a,toggle:o}}function ci(e,t,n){let r=si({isReadOnly:e.isReadOnly||t.isReadOnly,isSelected:t.isSelected(e.value),defaultSelected:t.defaultValue.includes(e.value),onChange(n){n?t.addValue(e.value):t.removeValue(e.value),e.onChange&&e.onChange(n)}}),{name:i,form:a,descriptionId:o,errorMessageId:s,validationBehavior:l}=ai.get(t);l=e.validationBehavior??l;let{realtimeValidation:u}=Hr({...e,value:r.isSelected,name:void 0,validationBehavior:`aria`}),f=d(zr),p=()=>{t.setInvalid(e.value,u.isInvalid?u:f.current)};c(p);let m=t.realtimeValidation.isInvalid?t.realtimeValidation:u,h=l===`native`?t.displayValidation:m,g=ii({...e,isReadOnly:e.isReadOnly||t.isReadOnly,isDisabled:e.isDisabled||t.isDisabled,name:e.name||i,form:e.form||a,isRequired:e.isRequired??t.isRequired,validationBehavior:l,[Vr]:{realtimeValidation:m,displayValidation:h,resetValidation:t.resetValidation,commitValidation:t.commitValidation,updateValidation(e){f.current=e,p()}}},r,n);return{...g,inputProps:{...g.inputProps,"aria-describedby":[e[`aria-describedby`],t.isInvalid?s:null,o].filter(Boolean).join(` `)||void 0}}}const li=new WeakMap;function ui(e,t,n){let{value:r,children:i,"aria-label":a,"aria-labelledby":o,onPressStart:s,onPressEnd:c,onPressChange:u,onPress:d,onPressUp:f,onClick:p}=e,m=e.isDisabled||t.isDisabled,h=t.selectedValue===r,g=e=>{e.stopPropagation(),t.setSelectedValue(r)},{pressProps:_,isPressed:v}=X({onPressStart:s,onPressEnd:c,onPressChange:u,onPress:d,onPressUp:f,onClick:p,isDisabled:m}),{pressProps:y,isPressed:b}=X({onPressStart:s,onPressEnd:c,onPressChange:u,onPressUp:f,onClick:p,isDisabled:m,onPress(e){var i;d?.(e),t.setSelectedValue(r),(i=n.current)==null||i.focus()}}),{focusableProps:x}=vr(B(e,{onFocus:()=>t.setLastFocusedValue(r)}),n),S=B(_,x),C=V(e,{labelable:!0}),w=-1;t.selectedValue==null?(t.lastFocusedValue===r||t.lastFocusedValue==null)&&(w=0):t.selectedValue===r&&(w=0),m&&(w=void 0);let{name:T,form:E,descriptionId:D,errorMessageId:O,validationBehavior:ee}=li.get(t);return Lt(n,t.defaultSelectedValue,t.setSelectedValue),Yr({validationBehavior:ee},t,n),{labelProps:B(y,l(()=>({onClick:e=>e.preventDefault(),onMouseDown:e=>e.preventDefault()}),[])),inputProps:B(C,{...S,type:`radio`,name:T,form:E,tabIndex:w,disabled:m,required:t.isRequired&&ee===`native`,checked:h,value:r,onChange:g,"aria-describedby":[e[`aria-describedby`],t.isInvalid?O:null,D].filter(Boolean).join(` `)||void 0}),isDisabled:m,isSelected:h,isPressed:v||b}}function di(e,t){let{name:n,form:r,isReadOnly:i,isRequired:a,isDisabled:o,orientation:s=`vertical`,validationBehavior:c=`aria`}=e,{direction:l}=gn(),{isInvalid:u,validationErrors:d,validationDetails:f}=t.displayValidation,{labelProps:p,fieldProps:m,descriptionProps:h,errorMessageProps:g}=Ir({...e,labelElementType:`span`,isInvalid:t.isInvalid,errorMessage:e.errorMessage||d}),_=V(e,{labelable:!0}),{focusWithinProps:v}=yr({onBlurWithin(n){var r;(r=e.onBlur)==null||r.call(e,n),t.selectedValue||t.setLastFocusedValue(null)},onFocusWithin:e.onFocus,onFocusWithinChange:e.onFocusChange}),y=e=>{let n;switch(e.key){case`ArrowRight`:n=l===`rtl`&&s!==`vertical`?`prev`:`next`;break;case`ArrowLeft`:n=l===`rtl`&&s!==`vertical`?`next`:`prev`;break;case`ArrowDown`:n=`next`;break;case`ArrowUp`:n=`prev`;break;default:return}e.preventDefault();let r=Or(e.currentTarget,{from:e.target,accept:e=>e instanceof L(e).HTMLInputElement&&e.type===`radio`}),i;n===`next`?(i=r.nextNode(),i||=(r.currentNode=e.currentTarget,r.firstChild())):(i=r.previousNode(),i||=(r.currentNode=e.currentTarget,r.lastChild())),i&&(i.focus(),t.setSelectedValue(i.value))},b=F(n);return li.set(t,{name:b,form:r,descriptionId:h.id,errorMessageId:g.id,validationBehavior:c}),{radioGroupProps:B(_,{role:`radiogroup`,onKeyDown:y,"aria-invalid":t.isInvalid||void 0,"aria-errormessage":e[`aria-errormessage`],"aria-readonly":i||void 0,"aria-required":a||void 0,"aria-disabled":o||void 0,"aria-orientation":s,...m,...v}),labelProps:p,descriptionProps:h,errorMessageProps:g,isInvalid:u,validationErrors:d,validationDetails:f}}const fi=i({}),pi=ti(function(e,t){[e,t]=q(e,t,fi);let{elementType:n=`label`,...i}=e;return r.createElement(n,{className:`react-aria-Label`,...i,ref:t})}),mi=i(null),hi=i({}),gi=ti(function(e,t){[e,t]=q(e,t,hi);let n=e,{isPending:i}=n,{buttonProps:a,isPressed:o}=ni(e,t);a=_i(a,i);let{focusProps:s,isFocused:l,isFocusVisible:u}=jr(e),{hoverProps:f,isHovered:p}=Tr({...e,isDisabled:e.isDisabled||i}),m={isHovered:p,isPressed:(n.isPressed||o)&&!i,isFocused:l,isFocusVisible:u,isDisabled:e.isDisabled||!1,isPending:i??!1},h=K({...e,values:m,defaultClassName:`react-aria-Button`}),g=F(a.id),_=F(),v=a[`aria-labelledby`];i&&(v?v=`${v} ${_}`:a[`aria-label`]&&(v=`${g} ${_}`));let y=d(i);c(()=>{let e={"aria-labelledby":v||g};(!y.current&&l&&i||y.current&&l&&!i)&&rn(e,`assertive`),y.current=i},[i,l,v,g]);let b=V(e,{global:!0});return delete b.onClick,r.createElement(`button`,{...B(b,h,a,s,f),type:a.type===`submit`&&i?`button`:a.type,id:g,ref:t,"aria-labelledby":v,slot:e.slot||void 0,"aria-disabled":i?`true`:a[`aria-disabled`],"data-disabled":e.isDisabled||void 0,"data-pressed":m.isPressed||void 0,"data-hovered":p||void 0,"data-focused":l||void 0,"data-pending":i||void 0,"data-focus-visible":u||void 0},r.createElement(mi.Provider,{value:{id:_}},h.children))});function _i(e,t){if(t){for(let t in e)t.startsWith(`on`)&&!(t.includes(`Focus`)||t.includes(`Blur`))&&(e[t]=void 0);e.href=void 0,e.target=void 0}return e}const vi=i({}),yi=a(function(e,t){[e,t]=q(e,t,vi);let{elementType:n=`span`,...i}=e;return r.createElement(n,{className:`react-aria-Text`,...i,ref:t})});function bi(e={}){let[t,n]=Yt(e.value,e.defaultValue||[],e.onChange),[r]=f(t),i=!!e.isRequired&&t.length===0,a=d(new Map),o=Hr({...e,value:t}),s=o.displayValidation.isInvalid;return{...o,value:t,defaultValue:e.defaultValue??r,setValue(t){e.isReadOnly||e.isDisabled||n(t)},isDisabled:e.isDisabled||!1,isReadOnly:e.isReadOnly||!1,isSelected(e){return t.includes(e)},addValue(t){e.isReadOnly||e.isDisabled||n(e=>e.includes(t)?e:e.concat(t))},removeValue(r){e.isReadOnly||e.isDisabled||t.includes(r)&&n(t.filter(e=>e!==r))},toggleValue(r){e.isReadOnly||e.isDisabled||(t.includes(r)?n(t.filter(e=>e!==r)):n(t.concat(r)))},setInvalid(e,t){let n=new Map(a.current);t.isInvalid?n.set(e,t):n.delete(e),a.current=n,o.updateValidation(Jr(...n.values()))},validationState:e.validationState??(s?`invalid`:null),isInvalid:s,isRequired:i}}let xi=Math.round(Math.random()*1e10),Si=0;function Ci(e){let t=l(()=>e.name||`radio-group-${xi}-${++Si}`,[e.name]),[n,r]=Yt(e.value,e.defaultValue??null,e.onChange),[i]=f(n),[a,o]=f(null),s=Hr({...e,value:n}),c=t=>{!e.isReadOnly&&!e.isDisabled&&(r(t),s.commitValidation())},u=s.displayValidation.isInvalid;return{...s,name:t,selectedValue:n,defaultSelectedValue:e.value===void 0?e.defaultValue??null:i,setSelectedValue:c,lastFocusedValue:a,setLastFocusedValue:o,isDisabled:e.isDisabled||!1,isReadOnly:e.isReadOnly||!1,isRequired:e.isRequired||!1,validationState:e.validationState||(u?`invalid`:null),isInvalid:u}}const wi=i(null),Ti=a(function(e,t){return s(wi)?.isInvalid?r.createElement(Ei,{...e,ref:t}):null}),Ei=a((e,t)=>{let n=s(wi),i=V(e,{global:!0}),a=K({...e,defaultClassName:`react-aria-FieldError`,defaultChildren:n.validationErrors.length===0?void 0:n.validationErrors.join(` `),values:n});return a.children==null?null:r.createElement(yi,{slot:`errorMessage`,...i,...a,ref:t})}),Di=i(null),Oi=i(null),ki=i(null),Ai=a(function(e,t){[e,t]=q(e,t,Oi);let{validationBehavior:n}=$t(Di)||{},i=e.validationBehavior??n??`native`,a=bi({...e,validationBehavior:i}),[o,s]=en(!e[`aria-label`]&&!e[`aria-labelledby`]),{groupProps:c,labelProps:l,descriptionProps:u,errorMessageProps:d,...f}=oi({...e,label:s,validationBehavior:i},a),p=K({...e,values:{isDisabled:a.isDisabled,isReadOnly:a.isReadOnly,isRequired:e.isRequired||!1,isInvalid:a.isInvalid,state:a},defaultClassName:`react-aria-CheckboxGroup`}),m=V(e,{global:!0});return r.createElement(`div`,{...B(m,p,c),ref:t,slot:e.slot||void 0,"data-readonly":a.isReadOnly||void 0,"data-required":e.isRequired||void 0,"data-invalid":a.isInvalid||void 0,"data-disabled":e.isDisabled||void 0},r.createElement(Zt,{values:[[ki,a],[fi,{...l,ref:o,elementType:`span`}],[vi,{slots:{description:u,errorMessage:d}}],[wi,f]]},p.children))}),ji=a(function(e,t){let{inputRef:n=null,...i}=e;[e,t]=q(i,t,je);let{validationBehavior:a}=$t(Di)||{},o=e.validationBehavior??a??`native`,c=s(ki),u=Mt(l(()=>rt(n,e.inputRef===void 0?null:e.inputRef),[n,e.inputRef])),{labelProps:d,inputProps:f,isSelected:p,isDisabled:m,isReadOnly:h,isPressed:g,isInvalid:_}=c?ci({...tn(e),value:e.value,children:typeof e.children==`function`?!0:e.children},c,u):ii({...tn(e),children:typeof e.children==`function`?!0:e.children,validationBehavior:o},si(e),u),{isFocused:v,isFocusVisible:y,focusProps:b}=jr(),x=m||h,{hoverProps:S,isHovered:C}=Tr({...e,isDisabled:x}),w=K({...e,defaultClassName:`react-aria-Checkbox`,values:{isSelected:p,isIndeterminate:e.isIndeterminate||!1,isPressed:g,isHovered:C,isFocused:v,isFocusVisible:y,isDisabled:m,isReadOnly:h,isInvalid:_,isRequired:e.isRequired||!1}}),T=V(e,{global:!0});return delete T.id,delete T.onClick,r.createElement(`label`,{...B(T,d,S,w),ref:t,slot:e.slot||void 0,"data-selected":p||void 0,"data-indeterminate":e.isIndeterminate||void 0,"data-pressed":g||void 0,"data-hovered":C||void 0,"data-focused":v||void 0,"data-focus-visible":y||void 0,"data-disabled":m||void 0,"data-readonly":h||void 0,"data-invalid":_||void 0,"data-required":e.isRequired||void 0},r.createElement(Pr,{elementType:`span`},r.createElement(`input`,{...B(f,b),ref:u})),w.children)}),Mi=i({}),Ni=i({});let Pi=e=>{let{onHoverStart:t,onHoverChange:n,onHoverEnd:r,...i}=e;return i};const Fi=ti(function(e,t){[e,t]=q(e,t,Ni);let{hoverProps:n,isHovered:i}=Tr({...e,isDisabled:e.disabled}),{isFocused:a,isFocusVisible:o,focusProps:s}=jr({isTextInput:!0,autoFocus:e.autoFocus}),c=!!e[`aria-invalid`]&&e[`aria-invalid`]!==`false`,l=K({...e,values:{isHovered:i,isFocused:a,isFocusVisible:o,isDisabled:e.disabled||!1,isInvalid:c},defaultClassName:`react-aria-Input`});return r.createElement(`input`,{...B(Pi(e),s,n),...l,ref:t,"data-focused":a||void 0,"data-disabled":e.disabled||void 0,"data-hovered":i||void 0,"data-focus-visible":o||void 0,"data-invalid":c||void 0})}),Ii=i(null);function Li(e){let t=d({});return r.createElement(Ii.Provider,{value:t},e.children)}const Ri=i({isSelected:!1}),zi=i(null),Bi=i(null),Vi=i(null),Hi=a(function(e,t){[e,t]=q(e,t,zi);let{validationBehavior:n}=$t(Di)||{},i=e.validationBehavior??n??`native`,a=Ci({...e,validationBehavior:i}),[o,s]=en(!e[`aria-label`]&&!e[`aria-labelledby`]),{radioGroupProps:c,labelProps:l,descriptionProps:u,errorMessageProps:d,...f}=di({...e,label:s,validationBehavior:i},a),p=K({...e,values:{orientation:e.orientation||`vertical`,isDisabled:a.isDisabled,isReadOnly:a.isReadOnly,isRequired:a.isRequired,isInvalid:a.isInvalid,state:a},defaultClassName:`react-aria-RadioGroup`}),m=V(e,{global:!0});return r.createElement(`div`,{...B(m,p,c),ref:t,slot:e.slot||void 0,"data-orientation":e.orientation||`vertical`,"data-invalid":a.isInvalid||void 0,"data-disabled":a.isDisabled||void 0,"data-readonly":a.isReadOnly||void 0,"data-required":a.isRequired||void 0},r.createElement(Zt,{values:[[Vi,a],[fi,{...l,ref:o,elementType:`span`}],[vi,{slots:{description:u,errorMessage:d}}],[wi,f]]},r.createElement(Li,null,p.children)))}),Ui=a(function(e,t){let{inputRef:n=null,...i}=e;[e,t]=q(i,t,Bi);let a=r.useContext(Vi),o=Mt(l(()=>rt(n,e.inputRef===void 0?null:e.inputRef),[n,e.inputRef])),{labelProps:s,inputProps:c,isSelected:u,isDisabled:d,isPressed:f}=ui({...tn(e),children:typeof e.children==`function`?!0:e.children},a,o),{isFocused:p,isFocusVisible:m,focusProps:h}=jr(),g=d||a.isReadOnly,{hoverProps:_,isHovered:v}=Tr({...e,isDisabled:g}),y=K({...e,defaultClassName:`react-aria-Radio`,values:{isSelected:u,isPressed:f,isHovered:v,isFocused:p,isFocusVisible:m,isDisabled:d,isReadOnly:a.isReadOnly,isInvalid:a.isInvalid,isRequired:a.isRequired}}),b=V(e,{global:!0});return delete b.id,delete b.onClick,r.createElement(`label`,{...B(b,s,_,y),ref:t,"data-selected":u||void 0,"data-pressed":f||void 0,"data-hovered":v||void 0,"data-focused":p||void 0,"data-focus-visible":m||void 0,"data-disabled":d||void 0,"data-readonly":a.isReadOnly||void 0,"data-invalid":a.isInvalid||void 0,"data-required":a.isRequired||void 0},r.createElement(Pr,{elementType:`span`},r.createElement(`input`,{...B(c,h),ref:o})),r.createElement(Ri.Provider,{value:{isSelected:u}},y.children))}),Wi=i({});let Gi=e=>{let{onHoverStart:t,onHoverChange:n,onHoverEnd:r,...i}=e;return i};const Ki=a(function(e,t){[e,t]=q(e,t,Wi);let{hoverProps:n,isHovered:i}=Tr(e),{isFocused:a,isFocusVisible:o,focusProps:s}=jr({isTextInput:!0,autoFocus:e.autoFocus}),c=!!e[`aria-invalid`]&&e[`aria-invalid`]!==`false`,l=K({...e,values:{isHovered:i,isFocused:a,isFocusVisible:o,isDisabled:e.disabled||!1,isInvalid:c},defaultClassName:`react-aria-TextArea`});return r.createElement(`textarea`,{...B(Gi(e),s,n),...l,ref:t,"data-focused":a||void 0,"data-disabled":e.disabled||void 0,"data-hovered":i||void 0,"data-focus-visible":o||void 0,"data-invalid":c||void 0})}),qi=i(null),Ji=ti(function(e,t){[e,t]=q(e,t,qi);let{validationBehavior:n}=$t(Di)||{},i=e.validationBehavior??n??`native`,a=d(null);[e,a]=q(e,a,Me);let[s,c]=en(!e[`aria-label`]&&!e[`aria-labelledby`]),[l,u]=f(`input`),{labelProps:p,inputProps:m,descriptionProps:h,errorMessageProps:g,..._}=$r({...tn(e),inputElementType:l,label:c,validationBehavior:i},a),v=o(e=>{a.current=e,e&&u(e instanceof HTMLTextAreaElement?`textarea`:`input`)},[a]),y=K({...e,values:{isDisabled:e.isDisabled||!1,isInvalid:_.isInvalid,isReadOnly:e.isReadOnly||!1,isRequired:e.isRequired||!1},defaultClassName:`react-aria-TextField`}),b=V(e,{global:!0});return delete b.id,r.createElement(`div`,{...b,...y,ref:t,slot:e.slot||void 0,"data-disabled":e.isDisabled||void 0,"data-invalid":_.isInvalid||void 0,"data-readonly":e.isReadOnly||void 0,"data-required":e.isRequired||void 0},r.createElement(Zt,{values:[[fi,{...p,ref:s}],[Ni,{...m,ref:v}],[Wi,{...m,ref:v}],[Mi,{role:`presentation`,isInvalid:_.isInvalid,isDisabled:e.isDisabled||!1}],[vi,{slots:{description:h,errorMessage:g}}],[wi,_]]},y.children))}),Yi=({title:e,description:t,classNames:n})=>{let{survey:r,dismiss:i}=we();if(!r)return null;let a=t||r.confirmation.description;return b(v,{children:[y(`div`,{className:x(`cf-question`,n?.question),children:b(`div`,{className:x(`cf-header`,n?.header),children:[y(pi,{className:x(`cf-title`,n?.title),children:e||r.confirmation.title||`Feedback submitted!`}),a&&y(yi,{slot:`description`,className:x(`cf-description`,n?.description),children:a})]})}),y(gi,{className:`cf-submit-button`,onPress:i,children:r.confirmation.buttonText||`Close`})]})},Xi=({children:e,classNames:t,containerProps:n,onDismiss:r,closeOnFinishMs:i=3e3})=>{let{surveyId:a,survey:o,dismiss:s}=we(),[c,l]=f(!1);return h(()=>{o&&s()},c?i:null),b(`div`,{className:x(`confetti-dialog`,t?.dialog),id:`${a}-popover`,...n,children:[y(`button`,{type:`button`,className:x(`confetti-dialog-close`,t?.closeButton),"aria-label":`Dismiss`,onClick:async()=>{await s(),r?.()},children:y(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 16 16`,fill:`none`,className:x(t?.icon),children:y(`path`,{fill:`currentColor`,fillRule:`evenodd`,d:`M3.53 3.529c.26-.26.682-.26.942 0l3.529 3.528 3.528-3.528a.667.667 0 0 1 .943.942L8.943 8l3.53 3.528a.667.667 0 0 1-.944.943L8.001 8.943 4.472 12.47a.667.667 0 1 1-.943-.943L7.058 8 3.529 4.47a.667.667 0 0 1 0-.942Z`,clipRule:`evenodd`})})}),typeof e==`function`?e({setIsFinished:()=>l(!0)}):e]})},Zi=({id:e,title:t,description:n,properties:r,onChange:i,classNames:a,required:o,error:s})=>{let[l,u]=f(``);return c(()=>{i(l)},[i,l]),b(Ji,{isRequired:o,isInvalid:!!s,name:e,className:x(`cf-question`,a?.question),value:l,onChange:e=>{u(e),i(e)},children:[b(`div`,{className:x(`cf-header`,a?.header),children:[b(pi,{className:x(`cf-title`,a?.title),children:[t,!o&&b(`span`,{className:x(`cf-label-optional`,a?.optionalLabel),children:[` `,`(optional)`]})]}),n&&y(yi,{slot:`description`,className:x(`cf-description`,a?.description),children:n})]}),y(Ki,{className:x(`cf-textarea`,a?.textarea),maxLength:r.max,rows:4,placeholder:r.placeholder||`Start typing...`}),y(Ti,{className:x(`cf-error`,a?.error),children:s})]})},Qi=({children:e,classNames:t,description:n,...r})=>y(ji,{...r,children:({isIndeterminate:r})=>b(v,{children:[b(`div`,{className:x(`cf-choice-label`,t?.label),children:[y(`div`,{className:x(`cf-checkbox-indicator`,t?.indicator),children:y(`svg`,{viewBox:`0 0 18 18`,"aria-hidden":`true`,className:x(`cf-checkbox-indicator-svg`,t?.svg),children:r?y(`rect`,{x:1,y:7.5,width:16,height:3}):y(`polyline`,{points:`2 9 7 14 16 4`})},r?`indeterminate`:`check`)}),e]}),n&&y(`span`,{className:x(`cf-choice-description`,t?.choiceDescription),children:n})]})}),$i=({children:e,classNames:t,...n})=>y(ji,{...n,children:y(`div`,{className:x(`cf-tag-label`,t?.tagLabel),children:e})}),ea=({title:e,description:t,properties:n,classNames:r,onChange:i,id:a,required:o,error:s})=>{let u=!!n.editable,p=n.display??`checkbox`,[m,h]=f([]),[g,_]=f(``),S=d(null),C=d(null),w=l(()=>{let e=m.indexOf(M);if(e===-1)return m;let t=[...m];return t[e]=g||M,t},[g,m]),T=p===`tag`;return c(()=>{i(w)},[i,w]),y(Ai,{isRequired:o,isInvalid:!!s,name:a,value:m,onChange:h,className:x(`cf-question`,r?.question),children:({state:i})=>b(v,{children:[b(`div`,{className:x(`cf-header`,r?.header),children:[b(pi,{className:x(`cf-title`,r?.title),children:[e,!o&&b(`span`,{className:x(`cf-label-optional`,r?.optionalLabel),children:[` `,`(optional)`]})]}),t&&y(yi,{slot:`description`,className:x(`cf-description`,r?.description),children:t})]}),b(`div`,{className:x(`cf-response-choices`,p===`tag`&&`cf-response-choices-tag`,r?.group),children:[n.options.map((e,t)=>y(T?$i:Qi,{className:x(`cf-choice`,T&&[`cf-tag`,r?.tag],!T&&[`cf-checkbox`,r?.checkbox]),description:e.description,value:e.value,classNames:{tag:r?.tag,tagLabel:r?.tagLabel,choiceDescription:r?.choiceDescription,label:r?.label,indicator:r?.indicator,svg:r?.svg},children:e.value},t)),u&&(T?b(v,{children:[y($i,{inputRef:S,onChange:e=>{console.log(`hehe`,e),C.current&&e&&requestAnimationFrame(()=>{C.current&&C.current.focus()})},className:x(`cf-choice cf-tag`,r?.tag),value:M,children:n.editable?.label}),y(Fi,{"data-visible":i.value.includes(M)||void 0,value:g,onChange:e=>{_(e.target.value)},ref:C,className:x(`cf-input cf-tag-input`,r?.othersInput)})]}):b(`div`,{className:x(`cf-choice cf-others-choice`,r?.othersChoice),children:[y(Qi,{inputRef:S,onChange:e=>{C.current&&e&&requestAnimationFrame(()=>{C.current&&C.current.focus()})},className:x(`cf-checkbox`,r?.checkbox),value:M,classNames:{indicator:r?.indicator,svg:r?.svg},description:n.editable?.description,children:n.editable?.label}),y(Fi,{value:g,onChange:e=>{_(e.target.value)},tabIndex:i.value.includes(M)?0:-1,ref:C,onFocus:()=>{S.current?.checked===!1&&S.current.click()},className:x(`cf-input`,r?.othersInput)})]}))]}),y(Ti,{className:x(`cf-error`,r?.error),children:s})]})})},ta=e=>b(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:40,height:40,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,...e,children:[y(`circle`,{cx:12,cy:12,r:10}),y(`path`,{d:`M16 16s-1.5-2-4-2-4 2-4 2M7.5 8 10 9M14 9l2.5-1M9 10h.01M15 10h.01`})]}),na=e=>b(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:40,height:40,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,...e,children:[y(`circle`,{cx:12,cy:12,r:10}),y(`path`,{d:`M18 13a6 6 0 0 1-6 5 6 6 0 0 1-6-5h12ZM9 9h.01M15 9h.01`})]}),ra=e=>b(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:40,height:40,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,...e,children:[y(`circle`,{cx:12,cy:12,r:10}),y(`path`,{d:`M16 16s-1.5-2-4-2-4 2-4 2M9 9h.01M15 9h.01`})]}),ia=e=>b(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:40,height:40,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,...e,children:[y(`circle`,{cx:12,cy:12,r:10}),y(`path`,{d:`M8 15h8M9 9h.01M15 9h.01`})]}),aa=e=>b(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:40,height:40,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,...e,children:[y(`circle`,{cx:12,cy:12,r:10}),y(`path`,{d:`M8 14s1.5 2 4 2 4-2 4-2M9 9h.01M15 9h.01`})]}),oa=e=>y(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,width:40,height:40,fill:`none`,...e,children:y(`path`,{fill:`currentColor`,d:`m6.516 14.323-1.49 6.452a.998.998 0 0 0 1.529 1.057L12 18.202l5.445 3.63a1.001 1.001 0 0 0 1.517-1.106l-1.829-6.4 4.536-4.082a1 1 0 0 0-.59-1.74l-5.701-.454-2.467-5.461a.998.998 0 0 0-1.822 0L8.622 8.05l-5.701.453a1 1 0 0 0-.619 1.713l4.214 4.107zm2.853-4.326a.998.998 0 0 0 .832-.586L12 5.43l1.799 3.981a.998.998 0 0 0 .832.586l3.972.315-3.271 2.944c-.284.256-.397.65-.293 1.018l1.253 4.385-3.736-2.491a.995.995 0 0 0-1.109 0l-3.904 2.603 1.05-4.546a1 1 0 0 0-.276-.94l-3.038-2.962 4.09-.326z`})}),sa=e=>y(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:40,height:40,viewBox:`0 0 24 24`,...e,children:y(`path`,{fill:`currentColor`,d:`M21.947 9.179a1.001 1.001 0 0 0-.868-.676l-5.701-.453-2.467-5.461a.998.998 0 0 0-1.822-.001L8.622 8.05l-5.701.453a1 1 0 0 0-.619 1.713l4.213 4.107-1.49 6.452a1 1 0 0 0 1.53 1.057L12 18.202l5.445 3.63a1.001 1.001 0 0 0 1.517-1.106l-1.829-6.4 4.536-4.082c.297-.268.406-.686.278-1.065z`})}),ca=({state:e,properties:t,classNames:n})=>{let r=e.selectedValue?Number(e.selectedValue):null;return y(`div`,{className:x(`cf-rating-display-star`,n?.ratingDisplayStar),children:Array.from({length:t.scale},(e,t)=>{let i=t+1,a=String(i),o=r&&i<=r;return y(Ui,{className:x(`cf-rating-star`,n?.ratingStar),value:a,"data-filled":o?`true`:void 0,children:y(o?sa:oa,{})},t)})})},la=({properties:e,classNames:t})=>y(`div`,{className:x(`cf-rating-display-number`,t?.ratingDisplayNumber),children:Array.from({length:e.scale},(e,n)=>{let r=n+1,i=String(r);return y(Ui,{className:x(`cf-rating-number`,t?.ratingNumber),value:i,children:r},n)})}),ua=({properties:e,classNames:t,state:n})=>{let r=l(()=>[ta,ra,ia,aa,na],[]),i=l(()=>[ra,ia,aa],[]);return l(()=>e.scale===3||e.scale===5,[e.scale])?y(`div`,{className:x(`cf-rating-display-emoji`,t?.ratingDisplayEmoji),children:Array.from({length:e.scale},(n,a)=>{let o=a+1,s=String(o),c=e.scale===5?r[a]:i[a];return y(Ui,{className:x(`cf-rating-emoji`,t?.ratingEmoji),value:s,children:c&&y(c,{})},a)})}):y(la,{properties:e,classNames:t,state:n})},da=e=>{switch(e.properties.display??`star`){case`emoji`:return y(ua,{...e});case`number`:return y(la,{...e});case`star`:return y(ca,{...e})}},fa=({properties:e,title:t,description:n,classNames:r,onChange:i,id:a,error:o,required:s})=>{let[u,d]=f(null),p=l(()=>u?Number(u):void 0,[u]);return c(()=>{i(p)},[i,p]),y(Hi,{isRequired:s,isInvalid:!!o,name:a,className:x(`cf-question`,r?.question),value:u,onChange:d,children:({state:i})=>b(v,{children:[b(`div`,{className:x(`cf-header`,r?.header),children:[b(pi,{className:x(`cf-title`,r?.title),children:[t,!s&&b(`span`,{className:x(`cf-label-optional`,r?.optionalLabel),children:[` `,`(optional)`]})]}),n&&y(yi,{slot:`description`,className:x(`cf-description`,r?.description),children:n})]}),b(`div`,{className:x(`cf-rating-section`,r?.ratingSection),children:[y(da,{state:i,properties:e,classNames:r}),b(`div`,{className:x(`cf-rating-text`,r?.ratingText),children:[y(`span`,{className:x(`cf-rating-text-lower`,r?.ratingTextLower),children:e.labels?.lower}),y(`span`,{className:x(`cf-rating-text-upper`,r?.ratingTextUpper),children:e.labels?.upper})]})]}),y(Ti,{className:x(`cf-error`,r?.error),children:o})]})})},pa=({classNames:e,className:t,description:n,...r})=>y(Ui,{...r,className:x(t,e?.radio),children:Qt(r.children,t=>b(v,{children:[b(`div`,{className:x(`cf-choice-label`,e?.label),children:[y(`div`,{className:x(`cf-radio-indicator`,e?.indicator)}),t]}),n&&y(`span`,{className:x(`cf-choice-description`,e?.choiceDescription),children:n})]}))}),ma=({title:e,description:t,properties:n,classNames:r,onChange:i,id:a,required:o,error:s})=>{let[u,p]=f(null),[m,h]=f(``),g=!!n.editable,_=d(null),S=d(null),C=l(()=>u===ue?m||ue:u??void 0,[m,u]);return c(()=>{i(C)},[i,C]),y(Hi,{isRequired:o,isInvalid:!!s,name:a,onChange:e=>{p(e),e===ue&&requestAnimationFrame(()=>{S.current&&S.current.focus()})},value:u,className:x(`cf-question`,r?.question),children:({state:i})=>b(v,{children:[b(`div`,{className:x(`cf-header`,r?.header),children:[b(pi,{className:x(`cf-title`,r?.title),children:[e,!o&&b(`span`,{className:x(`cf-label-optional`,r?.optionalLabel),children:[` `,`(optional)`]})]}),t&&y(yi,{slot:`description`,className:x(`cf-description`,r?.description),children:t})]}),b(`div`,{className:x(`cf-response-choices`,r?.group),children:[n.options.map((e,t)=>y(pa,{classNames:{indicator:r?.indicator,radio:x(`cf-choice cf-radio`,r?.radio)},value:e.value,description:e.description,children:e.value},t)),g&&b(`div`,{className:x(`cf-choice cf-others-choice`,r?.othersChoice),children:[y(pa,{inputRef:_,value:ue,classNames:{indicator:r?.indicator,radio:x(`cf-radio`,r?.radio)},description:n.editable?.description,children:n.editable?.label}),y(Fi,{tabIndex:i.selectedValue===ue?0:-1,ref:S,value:m,onChange:e=>h(e.target.value),onFocus:()=>{_.current?.checked===!1&&_.current.click()},className:x(`cf-input`,r?.othersInput)})]})]}),y(Ti,{className:x(`cf-error`,r?.error),children:s})]})})},ha=({properties:e,title:t,description:n,classNames:r})=>y(`div`,{className:x(`cf-question`,r?.question),children:b(`div`,{className:x(`cf-header`,r?.header),children:[t&&y(`div`,{className:x(`cf-title`,r?.title),children:t}),n&&y(`div`,{className:x(`cf-description`,r?.description),children:n})]})}),ga=({question:e,onChange:t,error:n})=>{switch(e.properties.type){case`rating`:return y(fa,{...e,properties:e.properties,onChange:t,error:n},e.id);case`open-ended`:return y(Zi,{...e,properties:e.properties,onChange:t,error:n},e.id);case`single-select`:return y(ma,{...e,properties:e.properties,onChange:t,error:n},e.id);case`multi-select`:return y(ea,{...e,properties:e.properties,onChange:t,error:n},e.id);case`statement`:return y(ha,{...e,properties:e.properties,onChange:t,error:n},e.id)}return y(`div`,{children:`Unsupported question type`},e.id)},_a=({onPress:e,isDisabled:t,children:n=`Submit`})=>y(gi,{isDisabled:t,className:`cf-submit-button`,onPress:e,children:n}),va=e=>{switch(e){case`multi-select`:return[];case`statement`:return;default:return``}},ya=({onSubmit:e,children:n,question:r,isLastQuestion:i})=>{let[a,s]=f(va(r.properties.type)),c=l(()=>Ee(r.properties,{required:r.required}),[r.properties,r.required]),u=l(()=>{let e=c.safeParse(a);if(!e.success)return S(e.error)},[a,c]),d=l(()=>{let e=r.routingLogic;if(e.type!==`always`&&(a===``||Array.isArray(a)&&a.length===0)&&r.required)return!0;let n=e.type===`always`?e.target:e.cases.find(e=>t({answer:a,condition:e}))?.target??e.default;return n.type===`end`?!1:n.type===`next`?!i:!0},[a,i,r.required,r.routingLogic]),p=l(()=>r.properties.buttonLabel?r.properties.buttonLabel:d?`Next`:`Submit`,[d,r.properties.buttonLabel]),m=o(()=>{switch(r.properties.type){case`statement`:if(r.properties.buttonUrl&&typeof window<`u`){let e=te.safeParse(r.properties.buttonUrl).data;e&&window.open(e,`_blank`)}return e(void 0);default:return e(a)}},[a,e,r.properties]);return b(v,{children:[n({onChange:s,question:r,error:u}),y(_a,{isDisabled:!!u,onPress:m,children:p})]})},ba=({isCompleted:e,onSubmit:t,children:n})=>b(v,{children:[n,e&&y(_a,{onPress:t})]}),xa=e=>y(Ae,{...e,shouldAutoSubmit:!1,children:({questions:e,update:t,isCompleted:n,submit:r,isSubmitted:i})=>i?y(Yi,{}):y(ba,{onSubmit:r,isCompleted:n,children:e.filter(({visible:e})=>!!e).map(e=>y(ga,{question:e,onChange:n=>n&&t({question:e.position,answer:n})},e.position))})}),Sa=({onDismiss:e,closeOnFinishMs:t,...n})=>y(Ce,{...n,children:y(Xi,{onDismiss:e,closeOnFinishMs:t,children:({setIsFinished:e})=>y(ke,{shouldAutoSubmit:!0,...n,onFinished:()=>{e(),n.onFinished?.()},children:({current:e,questions:t,update:n,isSubmitted:r})=>{let i=e===t.length-1;if(r)return y(Yi,{});let a=t[e];return a?y(ya,{isLastQuestion:i,question:a,onSubmit:t=>n({question:e,answer:t}),children:e=>y(ga,{...e})}):y(v,{})}})})}),Ca=e=>y(Ae,{...e,shouldAutoSubmit:!0,children:({current:e,questions:t,update:n,isSubmitted:r})=>{let i=e===t.length-1;if(r)return y(Yi,{});let a=t[e];return a?y(ya,{isLastQuestion:i,question:a,onSubmit:t=>n({question:e,answer:t}),children:e=>y(ga,{...e})}):y(v,{})}}),wa=({delay:e})=>{let[t,n]=f(!1),r=l(()=>e,[]);return c(()=>{let e=setTimeout(()=>{n(!0)},r);return()=>clearTimeout(e)},[]),{isVisible:t}},Ta=({visits:e,respondent:t})=>{let[n,r]=p(`cfti:${l(()=>window.location.pathname,[])}:visits:${t??``}`,0);return c(()=>{r(e=>e+1)},[r]),{isVisible:n>=e,reset:o(()=>r(0),[r])}},Ea=({visits:e,respondent:t})=>{let[n,r]=m(`cfti:${l(()=>window.location.pathname,[])}:visits:${t??``}`,0);return c(()=>{r(e=>e+1)},[r]),{isVisible:n>=e,reset:o(()=>r(0),[r])}},Da=({threshold:e})=>{let[t,n]=f(()=>typeof window>`u`?!1:window.scrollY>=e);return c(()=>{let t=()=>{window.scrollY>=e&&n(!0)};return window.addEventListener(`scroll`,t,{passive:!0}),()=>window.removeEventListener(`scroll`,t)},[e]),{isVisible:t}};export{Ae as Confetti,Se as ConfettiContext,ke as ConfettiController,Ce as ConfettiProvider,ba as Embed,xa as EmbeddedConfetti,ya as Flow,Zi as FreeText,ea as MultiChoice,Sa as PopoverConfetti,Xi as PopoverContainer,fa as Rating,ma as SingleChoice,ha as Statement,Ca as StepperConfetti,ga as SurveyQuestionFactory,Yi as ThankYouMessage,we as useConfetti,wa as useVisibleAfterDelay,Ta as useVisibleAfterPageVisits,Da as useVisibleAfterScroll,Ea as useVisibleAfterSessionPageVisits};
|