@whoa-chat/react 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/locales/bg.json +790 -0
- package/dist/locales/da.json +790 -0
- package/dist/locales/de.json +790 -0
- package/dist/locales/en.json +790 -0
- package/dist/locales/es.json +790 -0
- package/dist/locales/fr.json +821 -0
- package/dist/locales/index.d.ts +11975 -0
- package/dist/locales/index.js +1 -0
- package/dist/locales/it.json +790 -0
- package/dist/locales/ja.json +790 -0
- package/dist/locales/loaders.d.ts +3 -0
- package/dist/locales/loaders.js +1 -0
- package/dist/locales/nl.json +790 -0
- package/dist/locales/pl.json +852 -0
- package/dist/locales/pt-BR.json +790 -0
- package/dist/locales/pt-PT.json +790 -0
- package/dist/locales/sv.json +790 -0
- package/dist/locales/zh-CN.json +790 -0
- package/dist/locales/zh-TW.json +790 -0
- package/dist/src/ActionGroup.d.ts +12 -0
- package/dist/src/ActionGroup.js +1 -0
- package/dist/src/AiChoices.d.ts +10 -0
- package/dist/src/AiChoices.js +1 -0
- package/dist/src/AssistantNote.d.ts +8 -0
- package/dist/src/AssistantNote.js +1 -0
- package/dist/src/Attachments.d.ts +56 -0
- package/dist/src/Attachments.js +1 -0
- package/dist/src/AvailabilityCard.d.ts +19 -0
- package/dist/src/AvailabilityCard.js +1 -0
- package/dist/src/CardOutcome.d.ts +6 -0
- package/dist/src/CardOutcome.js +1 -0
- package/dist/src/ChatThread.d.ts +149 -0
- package/dist/src/ChatThread.js +8 -0
- package/dist/src/ComposerTools.d.ts +29 -0
- package/dist/src/ComposerTools.js +1 -0
- package/dist/src/CustomCard.d.ts +5 -0
- package/dist/src/CustomCard.js +1 -0
- package/dist/src/DraftCard.d.ts +10 -0
- package/dist/src/DraftCard.js +1 -0
- package/dist/src/EmailTranscript.d.ts +6 -0
- package/dist/src/EmailTranscript.js +1 -0
- package/dist/src/EventRow.d.ts +5 -0
- package/dist/src/EventRow.js +2 -0
- package/dist/src/FormattedText.d.ts +45 -0
- package/dist/src/FormattedText.js +5 -0
- package/dist/src/HelpOfferCard.d.ts +10 -0
- package/dist/src/HelpOfferCard.js +1 -0
- package/dist/src/InboxTools.d.ts +53 -0
- package/dist/src/InboxTools.js +1 -0
- package/dist/src/MerchantPanel.d.ts +10 -0
- package/dist/src/MerchantPanel.js +1 -0
- package/dist/src/MessageActions.d.ts +15 -0
- package/dist/src/MessageActions.js +1 -0
- package/dist/src/MessagePreview.d.ts +20 -0
- package/dist/src/MessagePreview.js +1 -0
- package/dist/src/PasswordCard.d.ts +6 -0
- package/dist/src/PasswordCard.js +1 -0
- package/dist/src/RequestCards.d.ts +8 -0
- package/dist/src/RequestCards.js +1 -0
- package/dist/src/ReviewCard.d.ts +15 -0
- package/dist/src/ReviewCard.js +1 -0
- package/dist/src/RichCards.d.ts +37 -0
- package/dist/src/RichCards.js +1 -0
- package/dist/src/RichInput.d.ts +41 -0
- package/dist/src/RichInput.js +12 -0
- package/dist/src/StoreAvatar.d.ts +35 -0
- package/dist/src/StoreAvatar.js +1 -0
- package/dist/src/WorldMap.d.ts +10 -0
- package/dist/src/WorldMap.js +1 -0
- package/dist/src/agents.d.ts +9 -0
- package/dist/src/agents.js +1 -0
- package/dist/src/appearance.d.ts +17 -0
- package/dist/src/appearance.js +1 -0
- package/dist/src/chatApi.d.ts +182 -0
- package/dist/src/chatApi.js +1 -0
- package/dist/src/chatEnv.d.ts +16 -0
- package/dist/src/chatEnv.js +1 -0
- package/dist/src/chime.d.ts +7 -0
- package/dist/src/chime.js +1 -0
- package/dist/src/clock.d.ts +5 -0
- package/dist/src/clock.js +1 -0
- package/dist/src/copyToClipboard.d.ts +10 -0
- package/dist/src/copyToClipboard.js +1 -0
- package/dist/src/emojis.d.ts +6 -0
- package/dist/src/emojis.js +1 -0
- package/dist/src/flags.d.ts +5 -0
- package/dist/src/flags.js +1 -0
- package/dist/src/highlight.d.ts +8 -0
- package/dist/src/highlight.js +1 -0
- package/dist/src/host.d.ts +40 -0
- package/dist/src/host.js +1 -0
- package/dist/src/i18n.d.ts +2 -0
- package/dist/src/i18n.js +1 -0
- package/dist/src/refLinks.d.ts +7 -0
- package/dist/src/refLinks.js +1 -0
- package/dist/src/supportChat.css +2522 -0
- package/dist/src/useLive.d.ts +51 -0
- package/dist/src/useLive.js +1 -0
- package/dist/src/worldDots.d.ts +7 -0
- package/dist/src/worldDots.js +1 -0
- package/package.json +212 -4
- package/README.md +0 -3
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ShopAction } from "@whoa-chat/core/types";
|
|
2
|
+
import { type StoreLook } from "./StoreAvatar";
|
|
3
|
+
type Store = {
|
|
4
|
+
shop: string;
|
|
5
|
+
name: string;
|
|
6
|
+
look?: StoreLook | null;
|
|
7
|
+
};
|
|
8
|
+
export declare const ActionGroup: ({ actions, store }: {
|
|
9
|
+
actions: ShopAction[];
|
|
10
|
+
store?: Store;
|
|
11
|
+
}) => import("react").JSX.Element;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Fragment as D,jsx as o,jsxs as s}from"react/jsx-runtime";import{useState as k}from"react";import{useTranslation as v}from"./i18n.js";import{AgentAvatar as C}from"./agents.js";import{StoreAvatar as L}from"./StoreAvatar.js";import{timeOpts as f}from"./clock.js";import{brandVars as N,chatHost as d}from"./host.js";const l=e=>new Date(e).toLocaleTimeString([],f()),S=(e,a)=>{const n=new Date(a);if(l(e)===l(a))return l(e);const r=new Date(e).toDateString()===n.toDateString();return`${l(e)} to ${r?l(a):n.toLocaleString([],f({weekday:"short"}))}`},b=({open:e})=>o("svg",{className:`ag-chev${e?" ag-chev--open":""}`,viewBox:"0 0 20 20",width:"12",height:"12","aria-hidden":!0,children:o("path",{d:"M7.5 5l5 5-5 5",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})}),A=({kind:e})=>o("svg",{className:"ag-kind",viewBox:"0 0 20 20",width:"14",height:"14","aria-hidden":!0,children:e==="visit"?o("path",{d:"M4 4.5h12v9H4zM8 16.5h4M10 13.5v3",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinejoin:"round",strokeLinecap:"round"}):o("path",{d:"M12.5 4.5l3 3-8 8H4.5v-3zM11 6l3 3",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinejoin:"round",strokeLinecap:"round"})}),w=({action:e,store:a,size:n})=>e.actor==="support"&&e.agentName&&d().team&&e.agentName in d().team?o(C,{name:e.agentName,size:n}):e.actor==="support"?o("img",{className:"ag-logo",src:d().brand.logo,alt:"",width:n,height:n}):o(L,{shop:a?.shop??null,name:a?.name??"",look:a?.look,size:n}),y=({action:e,store:a,showWho:n})=>{const{t:r}=v("home"),[i,m]=k(!1),h=e.actor==="support"?e.agentName??r("supportChat.actions.supportTeam",N()):e.actor==="merchant"?null:r(`supportChat.actions.actor.${e.actor}`,{...N(),defaultValue:e.actor}),p=e.kind==="visit"?r("supportChat.actions.opened",{count:e.pages?.length??1}):e.title,g=e.kind==="visit"?!!e.pages?.length:e.changes.length>0,c=e.kind==="visit"&&e.until?S(e.at,e.until):l(e.at);return s("li",{className:"ag-step",children:[s("button",{type:"button",className:"ag-line","aria-expanded":g?i:void 0,disabled:!g,onClick:()=>m(t=>!t),children:[n?o(w,{action:e,store:a,size:16}):o(A,{kind:e.kind}),s("span",{className:"ag-text",children:[h&&s("strong",{children:[h," "]}),p]}),g&&o(b,{open:i}),o("time",{children:c})]}),i&&e.kind==="visit"&&s("ol",{className:"ag-leaves",children:[e.morePages?o("li",{className:"ag-more",children:r("supportChat.actions.morePages",{count:e.morePages})}):null,e.pages.map(t=>s("li",{title:t.path,children:[o("span",{children:t.label}),o("time",{children:l(t.at)})]},t.path+t.at))]}),i&&e.kind==="change"&&o("ul",{className:"ag-leaves",children:e.changes.map((t,u)=>s("li",{children:[o("span",{children:t.field}),s("span",{className:"ag-diff",children:[t.from&&o("s",{children:t.from}),o("b",{children:t.to})]})]},u))})]})},O=({actions:e,store:a})=>{const{t:n}=v("home"),[r,i]=k(!1),m=e.filter(t=>t.kind==="change").length,h=e.filter(t=>t.kind==="visit").reduce((t,u)=>t+(u.pages?.length??0),0),p=[...new Map(e.map(t=>[t.actor==="support"?`s:${t.agentName??""}`:t.actor,t])).values()],g=[m&&n("supportChat.actions.changes",{count:m}),h&&n("supportChat.actions.pagesOpened",{count:h})].filter(Boolean).join(", "),c=e.length===1;return o("div",{className:"ag",children:c?o("ul",{className:"ag-tree ag-tree--flat",children:o(y,{action:e[0],store:a,showWho:!0})}):s(D,{children:[s("button",{type:"button",className:"ag-line ag-head","aria-expanded":r,onClick:()=>i(t=>!t),children:[o("span",{className:"ag-people",children:p.slice(0,3).map(t=>o(w,{action:t,store:a,size:16},t.id))}),s("span",{className:"ag-text",children:[p.length===1&&p[0].actor==="merchant"&&s("strong",{children:[a?.name," "]}),g]}),o(b,{open:r}),o("time",{children:S(e[0].at,e.map(t=>t.until??t.at).sort().pop())})]}),r&&o("ul",{className:"ag-tree",children:e.map(t=>o(y,{action:t,store:a,showWho:p.length>1&&t.actor!=="merchant"},t.id))})]})})};export{O as ActionGroup};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AiChoice, AiProgressStep } from "@whoa-chat/core/types";
|
|
2
|
+
export declare const AiProgress: ({ steps }: {
|
|
3
|
+
steps: AiProgressStep[];
|
|
4
|
+
}) => import("react").JSX.Element;
|
|
5
|
+
export declare const AiChoices: ({ choices, active, picked, onPick }: {
|
|
6
|
+
choices: AiChoice[];
|
|
7
|
+
active: boolean;
|
|
8
|
+
picked?: string | null;
|
|
9
|
+
onPick: (label: string) => void;
|
|
10
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Fragment as m,jsx as e,jsxs as o}from"react/jsx-runtime";import{useTranslation as d}from"./i18n.js";const c={quantity:"M4 15h3V9H4zM8.5 15h3V6h-3zM13 15h3V3.5h-3z",fixed:"M3.5 7.5 10 4l6.5 3.5v6L10 17l-6.5-3.5zM3.5 7.5 10 11l6.5-3.5M10 11v6",box:"M3.5 6.5h13v10h-13zM3.5 6.5 5.5 3.5h9l2 3M8 10h4",gift:"M3.5 8h13v3h-13zM4.5 11h11v5.5h-11zM10 8v8.5M10 8C8 4 5.5 5 6.5 7c.4.7 2 1 3.5 1Zm0 0c2-4 4.5-3 3.5-1-.4.7-2 1-3.5 1Z",embed:"M3.5 4.5h13v11h-13zM3.5 8h13M7 11.5l-1.5 1.5L7 14.5M13 11.5l1.5 1.5-1.5 1.5",offer:"M10.5 3.5h6v6l-7 7-6-6zM13.5 6.5h.01",widget:"M3.5 3.5h13v13h-13zM6.5 7h7M6.5 10h7M6.5 13h4",portal:"M10 9.5a3 3 0 1 0 0-6 3 3 0 0 0 0 6ZM4 16.5c.8-3 3.2-4.5 6-4.5s5.2 1.5 6 4.5",design:"M10 3.5a6.5 6.5 0 1 0 0 13c1 0 1.5-.7 1.2-1.5-.4-1 .3-2 1.3-2h1.5a2.5 2.5 0 0 0 2.5-2.5c0-3.9-2.9-7-6.5-7ZM6.5 10h.01M8 6.5h.01M12 6.5h.01",email:"M3.5 5.5h13v9h-13zM3.5 5.5 10 11l6.5-5.5",person:"M7 8.5a3 3 0 1 0 6 0 3 3 0 0 0-6 0ZM4 17c.7-2.6 3-4 6-4s5.3 1.4 6 4M15 3.5l1.5 1.5L19 2.5",done:"m4.5 10.5 3.5 3.5 7.5-8",help:"M7.5 7.5a2.5 2.5 0 1 1 3.5 2.3c-.6.3-1 .8-1 1.5v.7M10 15h.01",link:"M8 5.5H5.5v9h9V12M11 4.5h4.5V9M15.5 4.5 9 11"},p=({name:s})=>e("svg",{viewBox:"0 0 20 20",width:"18",height:"18","aria-hidden":!0,children:e("path",{d:c[s]??c.help,fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})}),g=({steps:s})=>{const{t:l}=d("home"),n=s.filter(t=>t.state==="done").length;return o("div",{className:"sc-aip",children:[o("div",{className:"sc-aip-head",children:[e("span",{children:l("supportChat.ai.progress",{done:n,total:s.length})}),e("span",{className:"sc-aip-bar","aria-hidden":!0,children:e("span",{style:{width:`${n/Math.max(s.length,1)*100}%`}})})]}),e("ol",{children:s.map((t,i)=>o("li",{className:`sc-aip-step sc-aip-step--${t.state}`,children:[e("span",{className:"sc-aip-dot","aria-hidden":!0,children:t.state==="done"?e(p,{name:"done"}):i+1}),t.label]},i))})]})},b=({choices:s,active:l,picked:n,onPick:t})=>{const i=s.some(a=>a.detail);return e("div",{className:`sc-aic${i?" sc-aic--tiles":""}${l?"":" sc-aic--past"}`,children:s.map((a,r)=>{const M=n!=null&&n.trim()===a.label.trim(),h=o(m,{children:[(a.icon||a.url)&&e("span",{className:"sc-aic-icon",children:e(p,{name:a.url?"link":a.icon})}),o("span",{className:"sc-aic-text",children:[e("strong",{children:a.label}),i&&a.detail&&e("small",{children:a.detail})]})]});return a.url?e("a",{className:"sc-aic-btn sc-aic-btn--link",href:a.url,target:"_top",rel:"noopener noreferrer",children:h},r):e("button",{type:"button",className:`sc-aic-btn${M?" sc-aic-btn--chosen":""}`,disabled:!l,onClick:()=>t(a.label),children:h},r)})})};export{b as AiChoices,g as AiProgress};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SupportMessageView } from "@whoa-chat/core/types";
|
|
2
|
+
type Run = NonNullable<SupportMessageView["ai"]>;
|
|
3
|
+
export declare const AiSteps: ({ run, detail, since }: {
|
|
4
|
+
run: Run;
|
|
5
|
+
detail?: boolean;
|
|
6
|
+
since?: string;
|
|
7
|
+
}) => import("react").JSX.Element | null;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Fragment as k,jsx as o,jsxs as c}from"react/jsx-runtime";import{useEffect as m,useState as h}from"react";const b={shop_overview:{now:"Looking at the store",done:"Looked at the store",icon:"store"},check_store_setup:{now:"Checking the store setup",done:"Checked the store setup",icon:"search"},get_subscription:{now:"Opening a subscription",done:"Opened a subscription",icon:"doc"},search_subscriptions:{now:"Searching subscriptions",done:"Searched subscriptions",icon:"search"},get_billing_issues:{now:"Checking billing issues",done:"Checked billing issues",icon:"search"},bundle_config:{now:"Reading the bundle setup",done:"Read the bundle setup",icon:"doc"},get_offer:{now:"Opening an offer",done:"Opened an offer",icon:"doc"},search_offers:{now:"Searching offers",done:"Searched offers",icon:"search"},get_offer_performance:{now:"Checking offer performance",done:"Checked offer performance",icon:"chart"},get_subscription_metrics:{now:"Checking subscription numbers",done:"Checked subscription numbers",icon:"chart"},get_retention_insights:{now:"Checking retention",done:"Checked retention",icon:"chart"},search_loyalty_programs:{now:"Searching loyalty programs",done:"Searched loyalty programs",icon:"search"},product_facts:{now:"Checking a product",done:"Checked a product",icon:"search"},storefront_errors:{now:"Checking storefront errors",done:"Checked storefront errors",icon:"search"},search_help_center:{now:"Searching the help center",done:"Searched the help center",icon:"search"},get_help_article:{now:"Reading a help article",done:"Read a help article",icon:"doc"},admin_links:{now:"Finding admin links",done:"Found admin links",icon:"link"},setting_link:{now:"Finding a settings link",done:"Found a settings link",icon:"link"}},v={get:["Getting","Got"],fetch:["Getting","Got"],read:["Reading","Read"],list:["Listing","Listed"],search:["Searching","Searched"],find:["Finding","Found"],lookup:["Looking up","Looked up"],check:["Checking","Checked"],count:["Counting","Counted"],create:["Creating","Created"],update:["Updating","Updated"],verify:["Verifying","Verified"],open:["Opening","Opened"],load:["Loading","Loaded"]},_=e=>{const t=e.replace(/^.*__/,"").split(/[_\s-]+/).filter(Boolean).map(r=>r.toLowerCase()),n=v[t[0]],s=(n?t.slice(1):t).join(" "),i=s?n?`the ${s}`:s:"";return{now:n?`${n[0]} ${i}`.trim():`Using ${i}`,done:n?`${n[1]} ${i}`.trim():`Used ${i}`,icon:"search"}},g=e=>b[e]??_(e),u=e=>{if(!e)return null;try{const t=JSON.parse(e),n=[t.query,t.q,t.search,t.title,t.term].find(s=>typeof s=="string"&&s.trim());return n?n.trim().length>42?`${n.trim().slice(0,40)}...`:n.trim():null}catch{return null}},f=e=>{const t=g(e.tool),n=u(e.input);return n?`${t.now} for "${n}"`:t.now},w={search:"M9 15a6 6 0 1 0 0-12 6 6 0 0 0 0 12zM13.5 13.5 17 17",store:"M3.5 8 5 3.5h10L16.5 8M3.5 8a2.2 2.2 0 0 0 4.4 0 2.1 2.1 0 0 0 4.2 0 2.2 2.2 0 0 0 4.4 0M5 10.5V16.5h10v-6",doc:"M5.5 2.5h6l3.5 3.5v11h-9.5zM11.5 2.5V6H15M8 10h5M8 13h5",link:"M8.5 11.5l3-3M7 9 5.5 10.5a2.5 2.5 0 0 0 3.5 3.5L10.5 12.5M13 11l1.5-1.5a2.5 2.5 0 0 0-3.5-3.5L9.5 7.5",chart:"M3.5 16.5h13M6 13.5V9M10 13.5V5.5M14 13.5v-3"},C=({kind:e})=>o("svg",{viewBox:"0 0 20 20",width:"15",height:"15","aria-hidden":!0,children:o("path",{d:w[e]??w.search,fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})}),S=({step:e,detail:t})=>{const[n,s]=h(!1),i=g(e.tool),r=u(e.input),p=e.status==="running"?`${f(e)}...`:e.status==="error"?`${i.now} (could not)`:r?`${i.done}: "${r}"`:i.done,d=c(k,{children:[e.status==="running"?o("i",{className:"ai-spin","aria-hidden":!0}):o(C,{kind:i.icon}),o("span",{children:p})]});return c("li",{className:`ai-step ai-step--${e.status}`,children:[t?o("button",{type:"button",className:"ai-step-row","aria-expanded":n,onClick:()=>s(l=>!l),children:d}):o("div",{className:"ai-step-row",children:d}),t&&n&&c("div",{className:"ai-step-detail",children:[o("code",{className:"ai-step-tool",children:e.tool}),o("span",{children:"Asked"}),o("pre",{children:e.input||"{}"}),e.output!==void 0&&c(k,{children:[o("span",{children:"Got"}),o("pre",{children:e.output||"(nothing)"})]})]})]})},L=(e,t)=>{const[n,s]=h(()=>Date.now());return m(()=>{if(!t)return;const i=window.setInterval(()=>s(Date.now()),1e3);return()=>window.clearInterval(i)},[t]),e?Math.max(0,Math.round((n-Date.parse(e))/1e3)):null},y=({run:e,detail:t=!1,since:n})=>{const[s,i]=h(!1),r=e.status==="running",p=L(n,r);if(!r&&!e.steps.length)return null;const d=e.steps.filter(a=>a.status!=="running").length,l=[...e.steps].reverse().find(a=>a.status==="running");return c("div",{className:"ai-steps-wrap",children:[r?c("div",{className:"ai-toggle ai-toggle--live",role:"status",children:[o("span",{className:"ai-shimmer",children:l?f(l):e.steps.length?"Writing an answer":"Looking into it"},l?.id??e.steps.length),p!==null&&c("span",{className:"ai-seconds",children:[p,"s"]})]}):c("button",{type:"button",className:"ai-toggle","aria-expanded":s,onClick:()=>i(a=>!a),children:[o("svg",{viewBox:"0 0 20 20",width:"14",height:"14","aria-hidden":!0,children:o("path",{d:"M5 10.5l3.2 3.2L15 7",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})}),d===1?"1 step completed":`${d} steps completed`,o("svg",{className:"ai-toggle-caret",viewBox:"0 0 20 20",width:"12",height:"12","aria-hidden":!0,children:o("path",{d:"M6 8l4 4 4-4",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})})]}),(s||r)&&e.steps.length>0&&o("ul",{className:"ai-steps",children:e.steps.map(a=>o(S,{step:a,detail:t},a.id))})]})};export{y as AiSteps};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { FileRef } from "@whoa-chat/core/types";
|
|
3
|
+
type Fetch = (url: string) => Promise<Response>;
|
|
4
|
+
type Resolved = {
|
|
5
|
+
src: string;
|
|
6
|
+
link: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare const resolveFile: (url: string, load?: Fetch) => Promise<Resolved | null>;
|
|
9
|
+
export declare const formatSize: (bytes: number) => string;
|
|
10
|
+
/** One image or video the viewer can show. url: the host's address for it (resolved like any file). */
|
|
11
|
+
export type MediaItem = {
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
type: string;
|
|
15
|
+
url: string;
|
|
16
|
+
};
|
|
17
|
+
/** Images and videos opened in place over the chat (a new tab breaks inside the Shopify admin's frame). */
|
|
18
|
+
export declare const Lightbox: ({ items, start, load, onClose }: {
|
|
19
|
+
items: MediaItem[];
|
|
20
|
+
start: number;
|
|
21
|
+
load?: Fetch;
|
|
22
|
+
onClose: () => void;
|
|
23
|
+
}) => import("react").ReactPortal | null;
|
|
24
|
+
export declare const MediaProvider: ({ items, load, children }: {
|
|
25
|
+
items: MediaItem[];
|
|
26
|
+
load?: Fetch;
|
|
27
|
+
children: ReactNode;
|
|
28
|
+
}) => import("react").JSX.Element;
|
|
29
|
+
/** An image placed in a message's text, drawn where it stands. */
|
|
30
|
+
export declare const InlineImage: ({ id, name, url, load }: {
|
|
31
|
+
id: string;
|
|
32
|
+
name: string;
|
|
33
|
+
url: string;
|
|
34
|
+
load?: Fetch;
|
|
35
|
+
}) => import("react").JSX.Element;
|
|
36
|
+
export declare const MessageFiles: ({ files, fileUrl, fetchFile }: {
|
|
37
|
+
files: FileRef[];
|
|
38
|
+
fileUrl: (id: string) => string;
|
|
39
|
+
fetchFile?: Fetch;
|
|
40
|
+
}) => import("react").JSX.Element;
|
|
41
|
+
export type PendingFile = {
|
|
42
|
+
key: string;
|
|
43
|
+
name: string;
|
|
44
|
+
size: number;
|
|
45
|
+
type: string;
|
|
46
|
+
preview: string | null;
|
|
47
|
+
ref?: FileRef;
|
|
48
|
+
error?: string;
|
|
49
|
+
inline?: boolean;
|
|
50
|
+
};
|
|
51
|
+
export declare const PendingFiles: ({ files, onRemove, removeLabel }: {
|
|
52
|
+
files: PendingFile[];
|
|
53
|
+
onRemove: (key: string) => void;
|
|
54
|
+
removeLabel: string;
|
|
55
|
+
}) => import("react").JSX.Element;
|
|
56
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Fragment as w,jsx as n,jsxs as c}from"react/jsx-runtime";import{createContext as S,useCallback as A,useContext as T,useEffect as F,useMemo as K,useRef as M,useState as h}from"react";import{createPortal as O}from"react-dom";import{useTranslation as N}from"./i18n.js";const H=10*6e4,L=new Map,E=(e,r=s=>fetch(s))=>{const s=L.get(e);if(s&&Date.now()-s.at<H)return s.value;const t=r(e).then(async a=>{if(!a.ok)return null;if((a.headers.get("content-type")??"").includes("application/json")){const i=await a.json();return typeof i.url=="string"&&/^https:\/\//.test(i.url)?{src:i.url,link:!0}:null}return{src:URL.createObjectURL(await a.blob()),link:!1}}).catch(()=>null);return t.then(a=>a===null&&L.delete(e)),L.set(e,{at:Date.now(),value:t}),t},R=(e,r)=>{const[s,t]=h({url:null,src:null,failed:!1});return F(()=>{if(!e)return;let a=!0;return E(e,r).then(i=>a&&t({url:e,src:i?.src??null,failed:!i})),()=>{a=!1}},[e]),s.url===e?s:{url:e,src:null,failed:!1}},W=(e,r,s)=>{const t=new URL(e,"https://x.invalid");return t.searchParams.set(r,s),/^https?:\/\//.test(e)?t.toString():`${t.pathname}${t.search}`},$=async(e,r,s)=>{const t=await E(W(e,"download","1"),s)??await E(e,s);if(!t)return;const a=document.createElement("a");a.href=t.src,t.link||(a.download=r),a.rel="noopener",document.body.appendChild(a),a.click(),a.remove()},z=e=>e>=1e6?`${(e/1e6).toFixed(1)} MB`:`${Math.max(1,Math.round(e/1e3))} KB`,B=e=>(e.match(/\.([a-z0-9]{2,5})$/i)?.[1]??"file").toUpperCase(),x=e=>e.startsWith("video/"),f=({d:e,size:r=18})=>n("svg",{viewBox:"0 0 20 20",width:r,height:r,"aria-hidden":!0,children:n("path",{d:e,fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round"})}),C="M5.5 2.5h6l4 4v11h-10zM11.5 2.5v4h4",V="M10 3v9m-4-4 4 4 4-4M4 16h12",U='button:not([disabled]), a[href], video[controls], [tabindex]:not([tabindex="-1"])',j=({item:e,load:r})=>{const{t:s}=N("home"),{src:t,failed:a}=R(e.url,r),[i,o]=h(!1),[u,m]=h(!1);return F(()=>{o(!1),m(!1)},[t]),a||u?c("div",{className:"sc-lb-missing",children:[n(f,{d:C,size:32}),n("p",{children:s("supportChat.media.failed")}),t&&n("a",{className:"sc-lb-open",href:t,target:"_blank",rel:"noopener noreferrer",children:s("supportChat.media.openFile")})]}):c(w,{children:[!i&&n("span",{className:`sc-lb-spinner${x(e.type)&&t?" sc-lb-spinner--over":""}`,"aria-hidden":!0}),t&&(x(e.type)?n("video",{className:"sc-lb-video",src:t,controls:!0,autoPlay:!0,playsInline:!0,onLoadedMetadata:()=>o(!0),onError:()=>m(!0)}):n("img",{className:`sc-lb-img${i?"":" sc-lb-hidden"}`,src:t,alt:e.name,onLoad:()=>o(!0),onError:()=>m(!0)}))]})},I=({items:e,start:r,load:s,onClose:t})=>{const{t:a}=N("home"),[i,o]=h(Math.min(Math.max(r,0),e.length-1)),u=M(null),m=M(null),g=M(null),p=e[i],v=e.length>1,y=A(l=>o(d=>(d+l+e.length)%e.length),[e.length]);F(()=>{const l=document.activeElement,d=document.documentElement,b=d.style.overflow;return d.style.overflow="hidden",m.current?.focus(),()=>{d.style.overflow=b,l?.focus?.()}},[]);const D=l=>{if(l.key==="Escape")l.stopPropagation(),t();else if(l.key==="ArrowRight"&&v&&!(l.target instanceof HTMLVideoElement))y(1);else if(l.key==="ArrowLeft"&&v&&!(l.target instanceof HTMLVideoElement))y(-1);else if(l.key==="Tab"){const d=[...u.current?.querySelectorAll(U)??[]];if(!d.length)return;const b=d[0],k=d[d.length-1];l.shiftKey&&document.activeElement===b?(l.preventDefault(),k.focus()):!l.shiftKey&&document.activeElement===k&&(l.preventDefault(),b.focus())}};return p?O(c("div",{ref:u,className:"sc-lb",role:"dialog","aria-modal":"true","aria-label":p.name,onKeyDown:D,onClick:l=>l.target===l.currentTarget&&t(),onTouchStart:l=>g.current={x:l.touches[0].clientX,y:l.touches[0].clientY},onTouchEnd:l=>{const d=g.current;if(g.current=null,!d)return;const b=l.changedTouches[0].clientX-d.x,k=l.changedTouches[0].clientY-d.y;k>90&&Math.abs(k)>Math.abs(b)?t():v&&Math.abs(b)>60&&Math.abs(b)>Math.abs(k)&&y(b<0?1:-1)},children:[c("div",{className:"sc-lb-bar",children:[c("span",{className:"sc-lb-name",title:p.name,children:[p.name,v&&n("span",{className:"sc-lb-count",children:a("supportChat.media.count",{n:i+1,total:e.length})})]}),n("button",{type:"button",className:"sc-lb-btn",onClick:()=>{$(p.url,p.name,s)},"aria-label":a("supportChat.media.download"),title:a("supportChat.media.download"),children:n(f,{d:V})}),n("button",{ref:m,type:"button",className:"sc-lb-btn",onClick:t,"aria-label":a("supportChat.media.close"),title:a("supportChat.media.close"),children:n(f,{d:"M5 5l10 10M15 5L5 15"})})]}),n("div",{className:"sc-lb-stage",onClick:l=>l.target===l.currentTarget&&t(),children:n(j,{item:p,load:s},p.id)}),v&&c(w,{children:[n("button",{type:"button",className:"sc-lb-nav sc-lb-nav--prev",onClick:()=>y(-1),"aria-label":a("supportChat.media.previous"),children:n(f,{d:"M12.5 4.5 7 10l5.5 5.5",size:22})}),n("button",{type:"button",className:"sc-lb-nav sc-lb-nav--next",onClick:()=>y(1),"aria-label":a("supportChat.media.next"),children:n(f,{d:"M7.5 4.5 13 10l-5.5 5.5",size:22})})]})]}),document.body):null},P=S(null),J=({items:e,load:r,children:s})=>{const[t,a]=h(null),i=M(e);i.current=e;const o=K(()=>({open:u=>{const m=i.current.findIndex(g=>g.id===u);return m<0?!1:(a(m),!0)}}),[]);return c(P.Provider,{value:o,children:[s,t!==null&&n(I,{items:e,start:t,load:r,onClose:()=>a(null)})]})},_=({file:e,url:r,load:s})=>{const{t}=N("home"),a=T(P),[i,o]=h(!1),{src:u,failed:m}=R(r,s),[g,p]=h(!1),[v,y]=h(!1);return m||v?c("span",{className:"sc-file-img sc-file-img--missing",title:e.name,children:[n(f,{d:C}),n("span",{children:t("supportChat.media.failed")})]}):c(w,{children:[c("button",{type:"button",className:`sc-file-img${g?"":" sc-file-img--loading"}`,onClick:()=>a?.open(e.id)||o(!0),"aria-label":e.name,children:[!g&&n("span",{className:"rc-skel"}),u&&n("img",{src:u,alt:e.name,onLoad:()=>p(!0),onError:()=>y(!0)})]}),i&&n(I,{items:[{id:e.id,name:e.name,type:e.type,url:r}],start:0,load:s,onClose:()=>o(!1)})]})},X=({file:e,url:r,load:s})=>{const{t}=N("home"),a=T(P),[i,o]=h(!1),{src:u,failed:m}=R(r,s),[g,p]=h(!1);return m||g?c("span",{className:"sc-file-video sc-file-img--missing",title:e.name,children:[n(f,{d:C}),n("span",{children:t("supportChat.media.failed")})]}):c(w,{children:[c("button",{type:"button",className:"sc-file-video",onClick:()=>a?.open(e.id)||o(!0),"aria-label":t("supportChat.media.play",{name:e.name}),children:[u?n("video",{src:`${u}${u.includes("#")?"":"#t=0.1"}`,preload:"metadata",muted:!0,playsInline:!0,onError:()=>p(!0)}):n("span",{className:"rc-skel"}),n("span",{className:"sc-file-play","aria-hidden":!0,children:n("svg",{viewBox:"0 0 20 20",width:"22",height:"22",children:n("path",{d:"M7 5.5v9l7.5-4.5z",fill:"currentColor"})})})]}),i&&n(I,{items:[{id:e.id,name:e.name,type:e.type,url:r}],start:0,load:s,onClose:()=>o(!1)})]})},Q=({id:e,name:r,url:s,load:t})=>n(_,{file:{id:e,name:r||"Image",type:"image/png",size:0},url:s,load:t}),Z=({files:e,fileUrl:r,fetchFile:s})=>{const t=e.filter(o=>o.type.startsWith("image/")),a=e.filter(o=>x(o.type)),i=e.filter(o=>!o.type.startsWith("image/")&&!x(o.type));return c("div",{className:"sc-files",children:[t.length>0&&n("div",{className:`sc-file-grid sc-file-grid--${Math.min(t.length,3)}`,children:t.map(o=>n(_,{file:o,url:r(o.id),load:s},o.id))}),a.map(o=>n(X,{file:o,url:r(o.id),load:s},o.id)),i.map(o=>c("button",{type:"button",className:"sc-file-chip",onClick:()=>{$(r(o.id),o.name,s)},children:[n("span",{className:"sc-file-badge",children:B(o.name)}),c("span",{className:"sc-file-text",children:[n("strong",{children:o.name}),n("span",{children:z(o.size)})]}),n(f,{d:C})]},o.id))]})},ee=({files:e,onRemove:r,removeLabel:s})=>n("div",{className:"sc-pending",children:e.map(t=>c("div",{className:`sc-pending-item${t.error?" sc-pending-item--error":""}${!t.ref&&!t.error?" sc-pending-item--busy":""}`,title:t.error??t.name,children:[t.preview?n("img",{src:t.preview,alt:""}):n("span",{className:"sc-file-badge",children:B(t.name)}),c("span",{className:"sc-pending-text",children:[n("strong",{children:t.name}),n("span",{children:t.error??z(t.size)})]}),n("button",{type:"button","aria-label":s,onClick:()=>r(t.key),children:n("svg",{viewBox:"0 0 20 20",width:"12",height:"12","aria-hidden":!0,children:n("path",{d:"M5 5l10 10M15 5L5 15",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})})]},t.key))});export{Q as InlineImage,I as Lightbox,J as MediaProvider,Z as MessageFiles,ee as PendingFiles,z as formatSize,E as resolveFile};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Availability } from "@whoa-chat/core/types";
|
|
2
|
+
export declare const useAvailabilityText: () => {
|
|
3
|
+
when: (iso: string, now: number) => string;
|
|
4
|
+
until: (iso: string, now: number) => string;
|
|
5
|
+
};
|
|
6
|
+
/** Who is here, under the merchant's last message; nothing while the team is away (AwayBar says so at the top). */
|
|
7
|
+
export declare const AvailabilityCard: ({ availability }: {
|
|
8
|
+
availability: Availability;
|
|
9
|
+
}) => import("react").JSX.Element | null;
|
|
10
|
+
/** While the team is online: a slim bar at the top of the chat. Hidden once one of us wrote in the last half hour, and the
|
|
11
|
+
* merchant can close it (for this session). */
|
|
12
|
+
export declare const OnlineBar: ({ availability, recentReply }: {
|
|
13
|
+
availability: Availability;
|
|
14
|
+
recentReply: boolean;
|
|
15
|
+
}) => import("react").JSX.Element | null;
|
|
16
|
+
/** While the team is away: one line pinned at the top of the chat, when we are back and that the reply comes here. */
|
|
17
|
+
export declare const AwayBar: ({ availability }: {
|
|
18
|
+
availability: Availability;
|
|
19
|
+
}) => import("react").JSX.Element | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as e,jsxs as c}from"react/jsx-runtime";import{useEffect as y,useState as m}from"react";import{useTranslation as u}from"./i18n.js";import{AgentAvatar as d}from"./agents.js";const g=864e5,b=a=>{const[t,s]=m(()=>Date.parse(a));return y(()=>{s(Date.now());const n=window.setInterval(()=>s(Date.now()),6e4);return()=>window.clearInterval(n)},[]),t},w=()=>{const{t:a,i18n:t}=u("home");return{when:(r,o)=>{const i=new Date(r),p=i.toLocaleTimeString(t.language,{hour:"2-digit",minute:"2-digit"}),l=new Date(o).toDateString()===i.toDateString(),h=new Date(o+g).toDateString()===i.toDateString();return l?a("supportChat.availability.todayAt",{time:p}):h?a("supportChat.availability.tomorrowAt",{time:p}):a("supportChat.availability.dayAt",{day:i.toLocaleDateString(t.language,{weekday:"long"}),time:p})},until:(r,o)=>{const i=Math.max(1,Math.round((Date.parse(r)-o)/6e4)),p=Math.floor(i/60),l=i%60;return p?a("supportChat.availability.inHours",{h:p,m:l}):a("supportChat.availability.inMinutes",{count:l})}}},v=a=>{const t=b(a.now),s=a.agents.map(n=>({...n,online:n.status?n.status==="online":n.online?!n.until||Date.parse(n.until)>t:!!(n.next&&Date.parse(n.next)<=t)}));return{now:t,agents:s,online:s.some(n=>n.online)}},N=({availability:a})=>{const{t}=u("home"),{agents:s,online:n}=v(a);if(!n)return null;const r=s.filter(o=>o.online).map(o=>o.name);return c("div",{className:"av-card av-card--online",role:"status",children:[e("span",{className:"av-faces",children:r.map(o=>c("span",{className:"av-face",children:[e(d,{name:o,size:30}),e("i",{})]},o))}),c("div",{className:"av-online-text",children:[e("strong",{children:t("supportChat.availability.onlineTitle",{names:r.join(` ${t("supportChat.note.and")} `)})}),e("span",{children:t("supportChat.availability.onlineBody")})]})]})},D=({availability:a,recentReply:t})=>{const{t:s}=u("home"),{agents:n,online:r}=v(a),[o,i]=m(()=>{try{return sessionStorage.getItem("whoa-online-bar")==="closed"}catch{return!1}});if(!r||t||o)return null;const p=n.filter(l=>l.online).map(l=>l.name);return c("div",{className:"av-card av-card--online av-card--top",role:"status",children:[e("span",{className:"av-faces",children:p.map(l=>c("span",{className:"av-face",children:[e(d,{name:l,size:30}),e("i",{})]},l))}),c("div",{className:"av-online-text",children:[e("strong",{children:s("supportChat.availability.onlineTitle",{names:p.join(` ${s("supportChat.note.and")} `)})}),e("span",{children:s("supportChat.availability.onlineBody")})]}),e("button",{type:"button",className:"av-line-close","aria-label":s("supportChat.preview.dismiss"),onClick:()=>{i(!0);try{sessionStorage.setItem("whoa-online-bar","closed")}catch{}},children:"\xD7"})]})},x=({availability:a})=>{const{t}=u("home"),{when:s}=w(),{now:n,online:r}=v(a);if(r)return null;const o=a.nextAt;return e("div",{className:"av-line av-line--top",role:"status","aria-label":t("supportChat.availability.label"),children:c("div",{className:"av-line-row",children:[e("span",{className:"av-line-moon","aria-hidden":!0,children:e("svg",{viewBox:"0 0 24 24",width:"13",height:"13",children:e("path",{d:"M20 14.5A8 8 0 0 1 9.5 4a8 8 0 1 0 10.5 10.5z",fill:"currentColor"})})}),c("span",{className:"av-line-text",children:[e("strong",{children:a.onBreak?t("supportChat.availability.onBreak",{names:a.agents.filter(i=>i.status==="break").map(i=>i.name).join(` ${t("supportChat.note.and")} `)}):o?t("supportChat.availability.awayBack",{when:s(o,n)}):t("supportChat.availability.backSoon")}),e("span",{children:t("supportChat.availability.weReply")})]})]})})};export{N as AvailabilityCard,x as AwayBar,D as OnlineBar,w as useAvailabilityText};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as n,jsxs as u}from"react/jsx-runtime";import{useEffect as g,useRef as y}from"react";import{useTranslation as v}from"./i18n.js";import{awayClock as _,awayGuess as k,parseAway as S}from"@whoa-chat/core/reviewAway";import{timeOpts as $}from"./clock.js";const m={review_clicked:"review_clicked",preview_review:"review_clicked",review_issue:"review_issue",review_dismissed:"review_dismissed",help_yes:"help_yes",help_no:"help_no",open:"open",preview_go:"open"},C=new Set(["review_dismissed","preview_dismiss"]),T=c=>new Date(c).toLocaleTimeString([],$()),E=({message:c,children:d})=>{const{t:o}=v("home"),l=y(null),a=c.clicks??[],i=a[a.length-1],p=i?m[i.action]:void 0,w=new Set(a.map(e=>m[e.action]).filter(Boolean)),h=a.map(e=>e.action+e.at).join();g(()=>{l.current?.querySelectorAll("[data-card-action]").forEach(e=>{const t=e.dataset.cardAction;e.classList.toggle("co-hit",w.has(t)&&t!==p),e.classList.toggle("co-hit--final",t===p)})},[h]);const f=(e,t)=>{const s=e==="review_away"?S(t):null;return s?o(`supportChat.outcome.away.${s.how}${s.left?"Left":""}`,{time:_(s.ms),guess:o(`supportChat.outcome.away.${k(s)}`)}):null},r=a.filter((e,t)=>t===0||e.action!==a[t-1].action);return u("div",{ref:l,className:`co-card${i&&C.has(i.action)?" co-card--dismissed":""}`,children:[d,r.length>0&&n("ol",{className:"co-journey","aria-label":o("supportChat.outcome.label"),children:r.map((e,t)=>n("li",{className:t===r.length-1?"co-step co-step--last":"co-step",title:o(`supportChat.outcome.actions.${e.action}`,{defaultValue:e.action}),children:u("span",{children:[o(`supportChat.outcome.short.${e.action}`,{defaultValue:e.action}),e.detail&&n("em",{children:f(e.action,e.detail)??o(`supportChat.outcome.details.${e.detail}`,{defaultValue:e.detail})}),n("time",{dateTime:e.at,children:T(e.at)})]})},`${e.action}-${e.at}`))})]})};export{E as CardOutcome};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { ShortcutCard, Availability, FileRef, ListingStats, MessageRef, ReviewState, ShopAction, SupportMessageView } from "@whoa-chat/core/types";
|
|
3
|
+
import { type LinkShortcut } from "@whoa-chat/core/links";
|
|
4
|
+
import { type RefLink } from "./refLinks";
|
|
5
|
+
import { type StoreLook } from "./StoreAvatar";
|
|
6
|
+
export type RefSearch = {
|
|
7
|
+
offers: {
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
label: string;
|
|
11
|
+
}[];
|
|
12
|
+
products: {
|
|
13
|
+
id: string;
|
|
14
|
+
title: string;
|
|
15
|
+
status: string;
|
|
16
|
+
image: string | null;
|
|
17
|
+
variants: {
|
|
18
|
+
id: string;
|
|
19
|
+
title: string;
|
|
20
|
+
sku: string | null;
|
|
21
|
+
}[];
|
|
22
|
+
}[];
|
|
23
|
+
customers?: {
|
|
24
|
+
id: string;
|
|
25
|
+
name: string;
|
|
26
|
+
email: string | null;
|
|
27
|
+
active: number;
|
|
28
|
+
subscriptions: number;
|
|
29
|
+
}[];
|
|
30
|
+
subscriptions?: {
|
|
31
|
+
id: string;
|
|
32
|
+
customer: string;
|
|
33
|
+
status: string;
|
|
34
|
+
product: string | null;
|
|
35
|
+
next: string | null;
|
|
36
|
+
}[];
|
|
37
|
+
orders?: {
|
|
38
|
+
name: string;
|
|
39
|
+
customer: string | null;
|
|
40
|
+
createdAt: string;
|
|
41
|
+
total: number;
|
|
42
|
+
currency: string;
|
|
43
|
+
}[];
|
|
44
|
+
};
|
|
45
|
+
type Props = {
|
|
46
|
+
messages: SupportMessageView[];
|
|
47
|
+
viewer: "merchant" | "agent";
|
|
48
|
+
shopOwnerName?: string | null;
|
|
49
|
+
listing?: ListingStats | null;
|
|
50
|
+
onSend: (body: string, fileIds: string[], refs?: MessageRef[], replyTo?: string) => void | Promise<unknown>;
|
|
51
|
+
onReviewState?: (messageId: string, state: ReviewState, outcome?: string) => void;
|
|
52
|
+
sending?: boolean;
|
|
53
|
+
previewUrl?: (ref: string) => string;
|
|
54
|
+
open?: (path: string) => void;
|
|
55
|
+
agents?: string[];
|
|
56
|
+
onSendNote?: (body: string, fileIds: string[], replyTo?: string) => void | Promise<unknown>;
|
|
57
|
+
onReact?: (id: string, emoji: string) => Promise<unknown>;
|
|
58
|
+
/** The team inbox: send or discard a draft reply. */
|
|
59
|
+
onDraft?: (id: string, action: "send" | "discard" | "update", body?: string, opts?: {
|
|
60
|
+
card: boolean;
|
|
61
|
+
}) => Promise<unknown>;
|
|
62
|
+
uploadUrl?: string;
|
|
63
|
+
uploadFields?: Record<string, string>;
|
|
64
|
+
fileUrl?: (id: string) => string;
|
|
65
|
+
uploadFile?: (file: File) => Promise<FileRef>;
|
|
66
|
+
pickGif?: (id: string) => Promise<FileRef>;
|
|
67
|
+
fetchFile?: (url: string) => Promise<Response>;
|
|
68
|
+
availability?: Availability | null;
|
|
69
|
+
shortcuts?: {
|
|
70
|
+
key: string;
|
|
71
|
+
title: string;
|
|
72
|
+
body: string;
|
|
73
|
+
card?: ShortcutCard;
|
|
74
|
+
}[];
|
|
75
|
+
composerTop?: ReactNode;
|
|
76
|
+
composerFill?: {
|
|
77
|
+
text: string;
|
|
78
|
+
key: number;
|
|
79
|
+
replace?: boolean;
|
|
80
|
+
} | null;
|
|
81
|
+
onComposerEscape?: () => void;
|
|
82
|
+
composerSend?: {
|
|
83
|
+
blocked: boolean;
|
|
84
|
+
send: (text: string) => void;
|
|
85
|
+
text?: {
|
|
86
|
+
placeholder: string;
|
|
87
|
+
};
|
|
88
|
+
label?: string;
|
|
89
|
+
} | null;
|
|
90
|
+
onSendCard?: (card: ShortcutCard) => Promise<unknown>;
|
|
91
|
+
shortcutVars?: Record<string, string>;
|
|
92
|
+
gifSearchUrl?: string;
|
|
93
|
+
gifPickUrl?: string;
|
|
94
|
+
otherReadAt?: string | null;
|
|
95
|
+
otherDeliveredAt?: string | null;
|
|
96
|
+
emailedAt?: string | null;
|
|
97
|
+
email?: {
|
|
98
|
+
at: string;
|
|
99
|
+
status: "sent" | "held" | "failed" | "retried";
|
|
100
|
+
openedAt?: string;
|
|
101
|
+
clickedAt?: string;
|
|
102
|
+
} | null;
|
|
103
|
+
menu?: {
|
|
104
|
+
key: string;
|
|
105
|
+
label: string;
|
|
106
|
+
icon: ReactNode;
|
|
107
|
+
onSelect: () => void;
|
|
108
|
+
}[];
|
|
109
|
+
plusOnDesktop?: boolean;
|
|
110
|
+
rich?: boolean;
|
|
111
|
+
onDraftChange?: (text: string, note: boolean) => void;
|
|
112
|
+
typingNow?: {
|
|
113
|
+
name: string;
|
|
114
|
+
text?: string;
|
|
115
|
+
agent?: boolean;
|
|
116
|
+
note?: boolean;
|
|
117
|
+
} | null;
|
|
118
|
+
me?: string | null;
|
|
119
|
+
merchantCountry?: string | null;
|
|
120
|
+
onEdit?: (id: string, body: string) => void;
|
|
121
|
+
onDelete?: (id: string) => Promise<unknown>;
|
|
122
|
+
/** Undoes a delete (the team's view only). */
|
|
123
|
+
onRestore?: (id: string) => Promise<unknown>;
|
|
124
|
+
onSaveReply?: (key: string, body: string) => Promise<unknown>;
|
|
125
|
+
onSlash?: () => void;
|
|
126
|
+
onResendEmail?: () => Promise<unknown>;
|
|
127
|
+
visitorCta?: boolean;
|
|
128
|
+
searchRefs?: (q: string) => Promise<RefSearch>;
|
|
129
|
+
/** The team composer's link button: saved links, the app's pages and Shopify admin pages (loaded when opened). */
|
|
130
|
+
linkShortcuts?: () => Promise<LinkShortcut[]>;
|
|
131
|
+
onTrack?: (messageId: string, action: string, detail?: string) => void;
|
|
132
|
+
onAddFeature?: (messageId: string) => Promise<boolean>;
|
|
133
|
+
actions?: ShopAction[] | null;
|
|
134
|
+
store?: {
|
|
135
|
+
shop: string;
|
|
136
|
+
name: string;
|
|
137
|
+
look?: StoreLook | null;
|
|
138
|
+
};
|
|
139
|
+
onActionsBefore?: (at: string) => void;
|
|
140
|
+
actionsStatus?: string | null;
|
|
141
|
+
/** Team inbox only: subscription and offer ids in messages and notes link here. */
|
|
142
|
+
refLink?: RefLink;
|
|
143
|
+
linkNames?: Record<string, string>;
|
|
144
|
+
};
|
|
145
|
+
export declare const MenuIcon: ({ d }: {
|
|
146
|
+
d: string;
|
|
147
|
+
}) => import("react").JSX.Element;
|
|
148
|
+
export declare const ChatThread: ({ messages, viewer, shopOwnerName, listing, onSend, onReviewState, sending, previewUrl, open, agents, onSendNote, onDraft, uploadUrl, uploadFields, fileUrl, uploadFile, pickGif, fetchFile, availability, shortcuts, onSendCard, composerTop, composerFill, onComposerEscape, composerSend, shortcutVars, gifSearchUrl, gifPickUrl, otherReadAt, otherDeliveredAt, emailedAt, email, menu, plusOnDesktop, me, merchantCountry, rich, onDraftChange, typingNow, onEdit, onDelete, onRestore, onSaveReply: _onSaveReply, onSlash, onReact, visitorCta, onResendEmail, searchRefs, linkShortcuts, onTrack, onAddFeature, actions, store, onActionsBefore, actionsStatus, refLink, linkNames, }: Props) => import("react").JSX.Element;
|
|
149
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import{Fragment as k,jsx as s,jsxs as o}from"react/jsx-runtime";import{Fragment as He,useEffect as T,useLayoutEffect as Hn,useRef as y,useState as f}from"react";import{mentionsIn as Ps,noteTarget as Es,splitMentions as zn,typingMention as Is}from"@whoa-chat/core/mentions";import{ALLOWED_TYPES as ze,fileTypeOf as Bs,maxBytesFor as Fs,maxLabelFor as js}from"@whoa-chat/core/fileTypes";import{InlineImage as Hs,MediaProvider as zs,MessageFiles as Wn,PendingFiles as Ws}from"./Attachments.js";import{AvailabilityCard as Vs,AwayBar as Vn,OnlineBar as qs}from"./AvailabilityCard.js";import{HelpOfferCard as _s,VerifiedIcon as Ks}from"./HelpOfferCard.js";import{PasswordCard as Gs}from"./PasswordCard.js";import{FeatureRequestCard as Zs,TicketCard as Qs}from"./RequestCards.js";import{CardOutcome as Us}from"./CardOutcome.js";import{EmojiPicker as Ys,LinkPicker as Js}from"./ComposerTools.js";import{useTranslation as Xs}from"./i18n.js";import{TEAM_FLAG as We,languageFlag as qn,languageName as _n}from"./flags.js";import{FILE_IMG as ta,FormattedText as Ve,inlineFileIds as ea}from"./FormattedText.js";import{isUrl as na,linkToken as qe}from"@whoa-chat/core/links";import{splitRefs as sa}from"./refLinks.js";import{RichInput as aa}from"./RichInput.js";import{AiSteps as ra}from"./AssistantNote.js";import{AiChoices as oa,AiProgress as ia}from"./AiChoices.js";import{MessageActions as _e}from"./MessageActions.js";import{ActionGroup as la}from"./ActionGroup.js";import{EventRow as ca}from"./EventRow.js";import{DraftCard as da}from"./DraftCard.js";import{StoreAvatar as ua}from"./StoreAvatar.js";import{AgentAvatar as Ct}from"./agents.js";import{ReviewCard as pa}from"./ReviewCard.js";import{CustomCard as ga}from"./CustomCard.js";import{ChatEnvProvider as Kn,DeepLinkCard as ma,Mention as ha,MessageWithReferences as fa,PricingCard as ka,ReferenceCard as Gn}from"./RichCards.js";import{timeOpts as ba}from"./clock.js";import{LinkNamesContext as ya,OpenedLinksContext as va}from"./chatEnv.js";import{useAppearance as Ca}from"./appearance.js";import{brandVars as $a,chatHost as Zn}from"./host.js";const It=({viewer:p,message:c,children:it})=>p==="agent"?s(Us,{message:c,children:it}):s(k,{children:it}),Y=p=>new Date(p).toDateString(),te=({d:p})=>s("svg",{viewBox:"0 0 20 20",width:"20",height:"20","aria-hidden":!0,children:s("path",{d:p,fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})}),F=p=>new Date(p).toLocaleTimeString([],ba()),Na=30*6e4,Qn=(p,c)=>c==="agent"&&p.translation&&p.from==="merchant"?{kind:"from",lang:p.translation.from,main:p.translation.text,alt:p.body}:c==="agent"&&p.translation&&p.from==="agent"?{kind:"to",lang:p.translation.to,main:p.body,alt:p.translation.text}:c==="merchant"&&p.original?{kind:"merchant",lang:p.original.lang,main:p.body,alt:p.original.body}:null,Ke=(p,c,it)=>{const $t=Qn(p,c);return $t?it?$t.alt:$t.main:p.body},sr=({messages:p,viewer:c,shopOwnerName:it,listing:$t,onSend:Ge,onReviewState:Un,sending:Yn,previewUrl:ee,open:Jn,agents:K=[],onSendNote:Bt,onDraft:Nt,uploadUrl:Ze,uploadFields:Qe,fileUrl:z,uploadFile:Ft,pickGif:ne,fetchFile:jt,availability:G,shortcuts:lt=[],onSendCard:se,composerTop:ae=null,composerFill:wt=null,onComposerEscape:Ue,composerSend:M=null,shortcutVars:Xn={},gifSearchUrl:re,gifPickUrl:oe,otherReadAt:xt=null,otherDeliveredAt:Ye=null,emailedAt:Je=null,email:ie=null,menu:Ht,plusOnDesktop:ts,me:W=null,merchantCountry:Xe=null,rich:S=!1,onDraftChange:tn,typingNow:C=null,onEdit:ct,onDelete:J,onRestore:en,onSaveReply:wa,onSlash:nn,onReact:dt,visitorCta:es=!1,onResendEmail:sn,searchRefs:ut,linkShortcuts:pt,onTrack:Mt,onAddFeature:an,actions:le=null,store:X,onActionsBefore:ce,actionsStatus:rn=null,refLink:on,linkNames:ns})=>{const{t:r,i18n:de}=Xs("home"),ss=t=>{const n=new Map,a=(t.clicks??[]).filter(i=>i.action==="link"&&/^https?:/.test(i.detail??""));for(const i of a){const e=a.filter(l=>l.detail===i.detail);n.has(i.detail)||n.set(i.detail,r("supportChat.msg.linkClicked",{time:F(e[0].at),count:e.length}))}return n},ln=Ca(de,c==="merchant"),cn=(t,n)=>on?sa(t,on).map((a,i)=>a.href?s("a",{href:a.href,target:"_blank",rel:"noopener noreferrer",children:a.text},`${n}-r${i}`):s(He,{children:a.text},`${n}-r${i}`)):t,[g,A]=f(""),[D,zt]=f(null),[L,ue]=f(null),[Lt,pe]=f(null),[dn,ge]=f([]),Wt=t=>{ge(i=>i.some(e=>e.key===t.key)?i.map(e=>e.key===t.key?{...t,status:"sending"}:e):[...i,t]);const n=t.card&&se?se(t.card):t.note&&Bt?Bt(t.body,t.files,t.replyTo):Ge(t.body,t.files,t.refs,t.replyTo),a=()=>ge(i=>i.filter(e=>e.key!==t.key));if(!n)return a();n.then(a,()=>ge(i=>i.map(e=>e.key===t.key?{...e,status:"failed"}:e)))},as=t=>Number(t.key.split("-")[0])||0,rs=t=>!t.card&&!!t.body&&p.some(n=>n.from===c&&n.kind==="note"===t.note&&n.body?.trim()===t.body.trim()&&Date.parse(n.at)>=as(t)-12e4),[Rt,os]=f(()=>new Set),is=t=>os(n=>{const a=new Set(n);return a.delete(t)||a.add(t),a}),Vt=y(null),[me,ls]=f(!1),he=y(null),qt=t=>{const n=Vt.current;n&&t!==me&&(he.current=new Map([n,...Array.from(n.children)].map(a=>[a,a.getBoundingClientRect()]))),ls(t)},un=y(qt);un.current=qt,T(()=>{g?g.includes(`
|
|
2
|
+
`)&&qt(!0):qt(!1)},[g]),T(()=>{const t=Vt.current;if(!t||typeof ResizeObserver>"u")return;const n=new ResizeObserver(()=>{const a=t.querySelector(".sc-rich-input, textarea");a&&a.scrollHeight>44&&un.current(!0)});return n.observe(t),()=>n.disconnect()},[]),Hn(()=>{const t=he.current;he.current=null;const n=Vt.current;if(!t||!n||window.matchMedia("(prefers-reduced-motion: reduce)").matches)return;const a={duration:220,easing:"cubic-bezier(0.2, 0.8, 0.2, 1)"};for(const[i,e]of t){if(!i.isConnected)continue;const l=i.getBoundingClientRect();if(i===n){Math.abs(e.height-l.height)>1&&n.animate([{height:`${e.height}px`},{height:`${l.height}px`}],a);continue}const d=e.left-l.left,m=e.top-l.top;(Math.abs(d)>1||Math.abs(m)>1)&&i.animate([{transform:`translate(${d}px, ${m}px)`},{transform:"none"}],a)}},[me]);const pn=y(!1),fe=y(tn);fe.current=tn,T(()=>{D||fe.current?.(g,pn.current)},[g,D]);const w=y(null),gn=y(g);gn.current=g,T(()=>{if(!wt)return;if(wt.replace){j(wt.text);return}if(g.trim())return;let t=0,n;const a=()=>{j(wt.text),n=setTimeout(()=>{!gn.current.trim()&&++t<30&&a()},100)};return a(),()=>clearTimeout(n)},[wt?.key]);const[cs,ds]=f(""),$=S?cs:g,j=(t,n)=>{S&&(t?w.current?.setText(t,n):w.current?.clear()),A(t)},ke=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"\u2318 Enter":"Ctrl Enter",V=[];for(const t of[...p.map(n=>({at:n.at,message:n})),...c==="agent"&&le?le.map(n=>({at:n.at,action:n})):[]].sort((n,a)=>Date.parse(n.at)-Date.parse(a.at))){const n=V[V.length-1];"action"in t&&t.action?n?.group&&Y(n.at)===Y(t.at)?n.group.push(t.action):V.push({at:t.at,group:[t.action]}):"message"in t&&t.message&&V.push({at:t.at,message:t.message})}const be=t=>t?.message&&(!t.message.kind||t.message.kind==="text")?`${t.message.from}:${t.message.agentName??""}`:null,mn=(t,n)=>!!(t&&n&&be(t)&&be(t)===be(n)&&Y(t.at)===Y(n.at)&&Date.parse(n.at)-Date.parse(t.at)<5*6e4),us=y(null),tt=y(null),hn=y(null),gt=y(!0),fn=()=>{const t=tt.current;if(!t||!ce)return;if(t.scrollTop<60)return ce(new Date(0).toISOString());const n=t.getBoundingClientRect().top,a=t.querySelectorAll("[data-at]"),i=[...a].find(e=>e.getBoundingClientRect().bottom>=n)??a[0];i?.dataset.at&&ce(i.dataset.at)},_t=y(0),ps=le?.length??0;Hn(()=>{const t=tt.current;t&&(!gt.current&&_t.current&&(t.scrollTop+=t.scrollHeight-_t.current),_t.current=t.scrollHeight,fn())},[ps]),T(()=>{const t=tt.current,n=hn.current;if(!t||!n)return;const a=()=>gt.current&&(t.scrollTop=t.scrollHeight),i=new ResizeObserver(a);return i.observe(n),i.observe(t),a(),()=>i.disconnect()},[]);const mt=p[p.length-1],[kn,ye]=f(!1),bn=y(null),yn=()=>{gt.current=!0,ye(!1),tt.current&&(tt.current.scrollTop=tt.current.scrollHeight)};T(()=>{const t=bn.current===null;if(bn.current=mt?.id??"",!mt)return;const n=mt.from===c||c==="agent"&&mt.from==="agent"&&mt.agentName===W;t||n||gt.current?yn():ye(!0)},[mt?.id]);const[Kt,et]=f(!1),[Tt,St]=f(!1),O=y(null),q=c==="agent"&&!!Bt&&K.length>0,ht=q?Es(g,K):null,Gt=q&&/^\s*@/.test(g),x=q&&(Tt||(!!ht||Gt)&&!Kt);pn.current=x,T(()=>{!D&&g.trim()&&fe.current?.(g,x)},[x]);const Zt=y(!1);T(()=>{q&&!Tt&&!Kt&&(Gt||ht)&&(Zt.current=!0,St(!0))},[q,Tt,Kt,Gt,ht]),T(()=>{c==="agent"&&nn&&g==="/"&&(j(""),nn())},[g]);const vn=x?Ps(g,K):[],ve=q?Is($):null,_=ve===null?[]:K.filter(t=>t.toLowerCase().startsWith(ve.toLowerCase())),[gs,Ce]=f(0);T(()=>Ce(0),[ve]);const $e=_[Math.min(gs,_.length-1)];T(()=>{g.trim()||et(!1);const t=O.current;t&&(t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,160)}px`)},[g]);const Ne=lt.length?$.match(/(?:^|\s)!([a-z0-9-]*)$/i)?.[1]??null:null,ft=Ne===null?[]:lt.filter(t=>t.key.startsWith(Ne.toLowerCase())||t.title.toLowerCase().includes(Ne.toLowerCase())).slice(0,6),we=t=>t.replace(/\{\{\s*(\w+)\s*\}\}/g,(n,a)=>Xn[a]??n),Cn=t=>{const n=t.body;t.card&&se&&pe(t.card),S?w.current?.replaceBefore($.match(/![a-z0-9-]*$/i)?.[0].length??0,we(n)):A(a=>a.replace(/![a-z0-9-]*$/i,we(n))),O.current?.focus()},[xe,$n]=f(null),[Me,ms]=f(null),Nn=c==="agent"&&pt?$.match(/(?:^|\s)\[([^[\]\n]{0,40})$/)?.[1]??null:null,Z=Nn!==null&&Me!==null&&$.startsWith(Me)&&$.lastIndexOf("[")===Me.lastIndexOf("[")?null:Nn;T(()=>{Z!==null&&xe===null&&pt&&pt().then($n,()=>$n([]))},[Z!==null]);const hs=(Z??"").toLowerCase().split(/\s+/).filter(Boolean),P=Z===null||!xe?[]:xe.filter(t=>hs.every(n=>`${t.label} ${t.url}`.toLowerCase().includes(n))).slice(0,6),[Le,Re]=f(0);T(()=>Re(0),[Z]);const wn=t=>{const n=$.match(/\[[^[\]\n]*$/)?.[0].length??0;S?w.current?.insertLink(t.url,void 0,n):(A(a=>a.replace(/\[[^[\]\n]*$/,`${qe(t.url,"")} `)),O.current?.focus())},[Te,fs]=f(null),ks=ut?$.match(/(?:^|\s)#((?:[^\s#\d][^#\n]{0,39})?|\d[^\s#]{0,19})$/)?.[1]??null:null,H=Te!==null&&$.startsWith(Te)&&$.lastIndexOf("#")===Te.lastIndexOf("#")?null:ks,[nt,xn]=f({q:"",data:null}),[Q,At]=f(null),[Se,Qt]=f([]);T(()=>{if(H===null||!ut)return At(null);let t=!0;const n=window.setTimeout(()=>{ut(H.trim()).then(a=>t&&xn({q:H,data:a}),()=>t&&xn({q:H,data:{offers:[],products:[]}}))},350);return()=>{t=!1,window.clearTimeout(n)}},[H,ut]);const st=(t,n)=>{if(S){w.current?.replaceBefore($.match(/#[^#\n]*$/)?.[0].length??0,t,{text:t,ref:n??t.replace(/^#/,"")}),At(null);return}A(a=>a.replace(/#[^#\n]*$/,`${t} `)),n&&Qt(a=>[...a.filter(i=>i.text!==t),{text:t,ref:n}]),At(null),O.current?.focus()},Ut=H===null||!nt.data?[]:Q?[{key:"any",label:r("supportChat.refPick.anyVariant"),sub:Q.title,image:Q.image,pick:()=>st(Q.title,`product-${Q.id}`)},...Q.variants.map(t=>({key:t.id,label:t.title,sub:t.sku?`SKU ${t.sku}`:void 0,pick:()=>st(`${Q.title}, ${t.title}`,`variant-${t.id}`)}))]:[...nt.data.offers.slice(0,3).map((t,n)=>({key:`o${t.id}`,section:n===0?r("supportChat.refPick.offers"):void 0,label:t.name,sub:t.label,pick:()=>st(t.name,`offer-${t.id}`)})),...nt.data.products.slice(0,4).map((t,n)=>({key:`p${t.id}`,section:n===0?r("supportChat.refPick.products"):void 0,label:t.title,sub:t.variants.length>1?r("supportChat.product.variants",{count:t.variants.length}):t.status!=="active"?r(`supportChat.product.status.${t.status}`,{defaultValue:t.status}):void 0,image:t.image,pick:()=>t.variants.length>1?At(t):st(t.title,`product-${t.id}`)})),...(nt.data.customers??[]).slice(0,3).map((t,n)=>({key:`c${t.id}`,section:n===0?r("supportChat.refPick.customers"):void 0,label:t.name,sub:[t.email,t.active?r("supportChat.customer.active",{count:t.active}):t.subscriptions?r("supportChat.customer.noneActive",{count:t.subscriptions}):null].filter(Boolean).join(" \xB7 "),pick:()=>st(t.name,`customer-${t.id}`)})),...(nt.data.subscriptions??[]).slice(0,3).map((t,n)=>({key:`s${t.id}`,section:n===0?r("supportChat.refPick.subscriptions"):void 0,label:t.customer,sub:[`#${t.id}`,t.product,t.status].filter(Boolean).join(" \xB7 "),pick:()=>st(`#${t.id}`,null)})),...(nt.data.orders??[]).slice(0,3).map((t,n)=>({key:`r${t.name}`,section:n===0?r("supportChat.refPick.orders"):void 0,label:t.name,sub:[t.customer,new Date(t.createdAt).toLocaleDateString(void 0,{day:"numeric",month:"short"})].filter(Boolean).join(" \xB7 "),pick:()=>st(t.name.startsWith("#")?t.name:`#${t.name}`,null)}))],Ae=y(null),bs=(()=>{const t=Se.filter(d=>g.includes(d.text)).sort((d,m)=>m.text.length-d.text.length),n=new Map(t.map(d=>[d.text,d.ref.startsWith("offer-")?"offer":d.ref.startsWith("customer-")?"customer":"product"])),a=[...t.map(d=>d.text.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")),"#[A-Za-z]{0,6}\\d{3,20}[A-Za-z]{0,6}\\b","`[^`\\n]+`"],i=new RegExp(`(${a.join("|")})`,"g"),e=(d,m)=>x?zn(d,K).map((h,v)=>h.agent?s("mark",{className:"sc-hl sc-hl--mention",children:h.text},`${m}-m${v}`):h.text):d,l=(d,m)=>d.split(i).map((h,v)=>v%2===1?s("mark",{className:`sc-hl sc-hl--${h.startsWith("`")?"code":n.get(h)??"order"}`,children:h},`${m}-${v}`):e(h,`${m}-${v}`));return o(k,{children:[g.split(/(```[\s\S]*?(?:```|$))/).map((d,m)=>m%2===1?s("mark",{className:"sc-hl sc-hl--block",children:d},`f${m}`):l(d,`t${m}`)),`
|
|
3
|
+
`]})})(),Yt=t=>{if(S)return w.current?.insertText(`${$&&!/\s$/.test($)?" ":""}${t}`);A(n=>`${n}${n&&!/\s$/.test(n)?" ":""}${t}`),window.requestAnimationFrame(()=>{const n=O.current;n&&(n.focus(),n.setSelectionRange(n.value.length,n.value.length))})},Mn=t=>{if(t.key==="Escape"&&Tt&&!D&&!L&&!ft.length&&Z===null)return Zt.current=!1,St(!1),et(!0),!0;if(t.key==="Escape"&&M&&Ue&&H===null&&Z===null&&!ft.length)return Ue(),!0;if((t.key==="Tab"||t.key==="Enter")&&H!==null&&Ut.length&&!t.metaKey&&!t.ctrlKey)return Ut[0].pick(),!0;if(t.key==="Escape"&&H!==null)return fs($),!0;if((t.key==="ArrowDown"||t.key==="ArrowUp")&&P.length>1){const a=t.key==="ArrowDown"?1:-1;return Re(i=>(Math.min(i,P.length-1)+a+P.length)%P.length),!0}if((t.key==="Tab"||t.key==="Enter")&&P.length)return wn(P[Math.min(Le,P.length-1)]),!0;if(t.key==="Escape"&&Z!==null)return ms($),!0;if((t.key==="Tab"||t.key==="Enter")&&ft.length)return Cn(ft[0]),!0;if((t.key==="ArrowDown"||t.key==="ArrowUp")&&_.length>1){const a=t.key==="ArrowDown"?1:-1;return Ce(i=>(Math.min(i,_.length-1)+a+_.length)%_.length),!0}if((t.key==="Tab"||t.key==="Enter")&&$e)return Sn($e),!0;if(t.key==="ArrowUp"&&!g&&ct&&W){const a=Ns();return a?(zt(a.id),j(a.body,a.refs),!0):!1}return t.key==="Escape"&&D?(Be(),!0):t.key==="Escape"&&L?(Jt(),!0):t.key!=="Enter"||t.isComposing?!1:(c==="agent"?t.metaKey||t.ctrlKey:!t.shiftKey)?(Bn(),!0):!1},ys=t=>{const n=t.currentTarget;if(n.selectionStart!==n.selectionEnd)return;const a=n.selectionStart,i=g.lastIndexOf(`
|
|
4
|
+
`,a-1)+1,e=/^(\s*)(?:([-*•])|(\d{1,3})([.)]))\s+/.exec(g.slice(i,a));if(!e)return;t.preventDefault();const l=g.slice(i,a).trim()===e[0].trim(),d=e[3]?`${e[1]}${Number(e[3])+1}${e[4]} `:`${e[1]}${e[2]} `,m=l?g.slice(0,i)+g.slice(a):`${g.slice(0,a)}
|
|
5
|
+
${d}${g.slice(a)}`,h=l?i:a+1+d.length;A(m),requestAnimationFrame(()=>n.setSelectionRange(h,h))},[at,kt]=f(null),[Ln,De]=f(!1),Rn=y(null),Tn=t=>{if(S)return w.current?.insertText(t);const n=O.current,a=n?.selectionStart??g.length,i=n?.selectionEnd??a;A(e=>e.slice(0,a)+t+e.slice(i)),window.requestAnimationFrame(()=>{n?.focus(),n?.setSelectionRange(a+t.length,a+t.length)})},Sn=t=>{S?w.current?.replaceBefore($.match(/@[\p{L}]*$/u)?.[0].length??0,`@${t} `):A(n=>n.replace(/@[\p{L}]*$/u,`@${t} `)),O.current?.focus()},[Dt,E]=f([]),[An,Oe]=f(!1),Pe=y(null),Dn=Dt.some(t=>!t.ref&&!t.error),vs=Dt.filter(t=>t.ref).map(t=>t.ref.id),Cs=t=>Dt.filter(n=>n.ref&&(!n.inline||t.includes(`file:${n.ref.id}`))).map(n=>n.ref.id),U=!!(Ze||Ft),Ot=(t,n=!1)=>{if(U)for(const a of Array.from(t).slice(0,10)){const i=`${Date.now()}-${Math.random().toString(36).slice(2)}`,e=Bs(a.name,a.type),l=e===a.type?a:new File([a],a.name,{type:e}),d=ze[l.type]?l.size>Fs(l.type)?r("supportChat.files.tooBig",{max:js(l.type)}):void 0:r("supportChat.files.notAllowed"),m=!d&&l.type.startsWith("image/")?URL.createObjectURL(l):null,h=!!(n&&S&&m&&Ft&&w.current),v=l.name||"screenshot.png";if(E(b=>[...b,{key:i,name:v,size:l.size,type:l.type,preview:m,error:d,...h?{inline:!0}:{}}]),d)continue;h&&w.current.insertImage(i,v,m);const I=(b,R)=>{h&&(b?w.current?.setImageId(i,b.id):w.current?.removeImage(i)),E(vt=>vt.map(u=>u.key===i?b?{...u,ref:b}:{...u,error:R??r("supportChat.files.failed")}:u))};if(Ft){Ft(l).then(b=>I(b),()=>I());continue}const B=new FormData;for(const[b,R]of Object.entries(Qe??{}))B.append(b,R);B.append("file",l,l.name||"screenshot.png"),fetch(Ze,{method:"POST",body:B}).then(async b=>({ok:b.ok,body:await b.json().catch(()=>({}))})).then(({ok:b,body:R})=>E(vt=>vt.map(u=>u.key===i?b&&R.file?{...u,ref:R.file}:{...u,error:R.error??r("supportChat.files.failed")}:u))).catch(()=>E(b=>b.map(R=>R.key===i?{...R,error:r("supportChat.files.failed")}:R)))}},$s=t=>{if(!oe&&!ne)return;kt(null);const n=`gif-${t.id}-${Date.now()}`;if(E(i=>[...i,{key:n,name:t.title||"GIF",size:0,type:"image/gif",preview:t.preview}]),ne){ne(t.id).then(i=>E(e=>e.map(l=>l.key===n?{...l,ref:i,size:i.size}:l)),()=>E(i=>i.map(e=>e.key===n?{...e,error:r("supportChat.files.failed")}:e)));return}if(!oe)return;const a=new FormData;for(const[i,e]of Object.entries(Qe??{}))a.append(i,e);a.append("id",t.id),fetch(oe,{method:"POST",body:a}).then(async i=>({ok:i.ok,body:await i.json().catch(()=>({}))})).then(({ok:i,body:e})=>E(l=>l.map(d=>d.key===n?i&&e.file?{...d,ref:e.file,size:e.file.size}:{...d,error:e.error??r("supportChat.files.failed")}:d))).catch(()=>E(i=>i.map(e=>e.key===n?{...e,error:r("supportChat.files.failed")}:e)))},Ns=()=>[...p].reverse().find(t=>t.from==="agent"&&t.agentName===W&&(t.kind==="text"||t.kind==="note")&&t.id!=="pending")??null,[Pt,Ee]=f(null),[ws,On]=f(!1),Ie=t=>{Ee(t),S?w.current?.focus?.():O.current?.focus()},rt=(t,n)=>c==="agent"&&t.from==="agent"?s(_e,{inline:!0,side:n,onReply:()=>Ie(t),onDelete:J?()=>J(t.id):void 0}):null,Pn=t=>t.from==="merchant"?c==="merchant"?r("supportChat.msg.you"):X?.name??r("supportChat.msg.merchant"):t.bot?Zn().brand.bot:t.author??t.agentName??Zn().brand.team,En=t=>t.replyTo?o("button",{type:"button",className:"sc-quote",onClick:()=>document.querySelector(`[data-msg="${CSS.escape(t.replyTo.id)}"]`)?.nextElementSibling?.scrollIntoView({behavior:"smooth",block:"center"}),children:[s("strong",{children:Pn({from:t.replyTo.from,author:t.replyTo.author==="merchant"?void 0:t.replyTo.author})}),s("span",{children:t.replyTo.excerpt})]}):null,In=t=>{ue(null),zt(t.id),j(t.body,t.refs),O.current?.focus()},Be=()=>{zt(null),j("")},Jt=()=>{ue(null),j("")},Bn=()=>{const t=g.trim();if(M){if(M.blocked)return;M.send(t),j("");return}if(D){t&&ct&&ct(D,t),Be();return}if(L){t&&Nt&&Nt(L.id,"send",t),Jt();return}const n=Cs(t);if(!t&&!n.length&&!Lt||Dn)return;const a=Lt;pe(null),(t||n.length)&&Wt({key:`${Date.now()}-${Math.random()}`,body:t,files:n,refs:Se.filter(i=>t.includes(i.text)),note:!!(x&&Bt),...Pt?{replyTo:Pt.id}:{},status:"sending"}),Ee(null),a&&Wt({key:`${Date.now()}-card`,body:"",files:[],note:!1,card:a,status:"sending"}),Qt([]),j(""),et(!1),Zt.current&&(Zt.current=!1,St(!1)),E([])},xs=p.find(t=>t.from==="agent"&&!t.bot&&!t.deletedAt&&t.kind!=="note"&&t.kind!=="draft"&&t.kind!=="event")?.id??null,Xt=z?(t,n,a)=>s(Hs,{id:t,name:n,url:z(t),load:jt},a):void 0,Et=t=>{const n=ea(t.body);return(t.files??[]).filter(a=>!n.has(a.id))},Fe=[];if(z){for(const t of p)if(!(t.deletedAt||t.kind==="event")){for(const n of(t.body??"").matchAll(ta))Fe.push({id:n[2],name:n[1]||"Image",type:"image/png",url:z(n[2])});for(const n of Et(t))(n.type.startsWith("image/")||n.type.startsWith("video/"))&&Fe.push({id:n.id,name:n.name,type:n.type,url:z(n.id)})}}const Ms=t=>t==="system"?"system":t===c?"merchant":"agent",ot=ee?{previewUrl:ee,open:Jn}:null,bt=p.filter(t=>t.kind!=="note").filter(t=>t.kind!=="event"&&t.kind!=="draft"),Ls=bt[bt.length-1]?.id??null,Rs=t=>{const n=bt.findIndex(a=>a.id===t);return bt.slice(n+1).find(a=>a.from==="merchant")?.body??null},Ts=t=>Wt({key:`${Date.now()}-choice`,body:t,files:[],note:!1,status:"sending"}),Fn=c==="merchant"?"merchant":"agent",jn=[...bt].reverse().find(t=>t.from===Fn)?.id??null,Ss=xt?Date.parse(xt):NaN,As=[...bt].reverse().find(t=>t.from===Fn&&t.id!=="pending"&&Date.parse(t.at)<=Ss)?.id??null,Ds=t=>{if(t.id===As&&t.id!==jn){const B=r("supportChat.receipts.seen");return o("span",{className:"sc-receipt sc-receipt--seen","data-tip":`${B} ${F(xt)}`,children:[o("svg",{viewBox:"0 0 18 14",width:"17",height:"13","aria-hidden":!0,children:[s("path",{d:"M1.5 7.5l3.2 3.2L11 4.2",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"}),s("path",{d:"M8.2 10.7L14.6 4.2",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round"})]}),s("span",{className:"sc-receipt-label",children:B})]})}if(t.id!==jn||t.id==="pending")return null;const n=B=>!!(B&&Date.parse(B)>=Date.parse(t.at)),a=c==="agent"&&ie&&n(ie.at)?ie:null,i=a?a.clickedAt??a.openedAt??null:null,e=c==="agent"&&!a&&n(Je)?Je:null,l=n(xt)?{kind:"seen",at:xt}:i?{kind:"emailOpened",at:i}:n(Ye)?{kind:"delivered",at:Ye}:a?.status==="sent"||e?{kind:"emailed",at:a?.at??e}:{kind:a?.status==="held"||a?.status==="failed"?"held":"sent",at:t.at},d=l.kind==="held"&&a?.status==="failed",m=r(`supportChat.receipts.${l.kind==="held"?a?.status==="failed"?"emailFailed":"emailHeld":l.kind}`),h=l.kind!=="sent"&&l.kind!=="held",v=o("svg",{viewBox:"0 0 18 14",width:"17",height:"13","aria-hidden":!0,children:[s("path",{d:h?"M1.5 7.5l3.2 3.2L11 4.2":"M3.5 7.5l3.2 3.2L13 4.2",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"}),h&&s("path",{d:"M8.2 10.7L14.6 4.2",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round"})]}),I=l.kind==="seen"||l.kind==="emailOpened"?`${m} ${F(l.at)}`:void 0;return o("span",{className:`sc-receipt sc-receipt--${l.kind}${d?" sc-receipt--failed":""}`,"data-tip":l.kind==="emailOpened"?`${I}. ${r("supportChat.receipts.openNote")}`:I,children:[v,s("span",{className:"sc-receipt-label",children:m}),d&&sn&&s("button",{type:"button",className:"sc-resend",disabled:ws,onClick:()=>{On(!0),sn().finally(()=>On(!1))},children:r("supportChat.receipts.resend")})]})},je=t=>{const n=Ds(t);return n?o(k,{children:[n," \xB7 "]}):null},yt=(t,n)=>o("div",{className:"sc-meta",style:{textAlign:n==="merchant"?"right":"left"},children:[je(t),t.from==="agent"&&t.agentName?`${t.agentName} \xB7 `:"",F(t.at)]}),Os=t=>{if(!ot)return null;const n=ot.open;return{...ot,open:n?a=>{Mt?.(t,"open"),n(a)}:void 0}};return s(zs,{items:Fe,load:jt,children:s(ya.Provider,{value:ns,children:s(Kn,{value:ot,children:o("div",{className:`sc-shell sc-shell--${c}${An?" sc-shell--drop":""}${ln.className}`,style:ln.style,onDragOver:t=>{!U||!t.dataTransfer.types.includes("Files")||(t.preventDefault(),Oe(!0))},onDragLeave:t=>{t.currentTarget.contains(t.relatedTarget)||Oe(!1)},onDrop:t=>{U&&(t.preventDefault(),Oe(!1),Ot(t.dataTransfer.files,!0))},children:[An&&s("div",{className:"sc-drop",children:r("supportChat.files.drop")}),o("div",{className:"sc-thread","aria-live":"polite",ref:tt,onScroll:t=>{const n=t.currentTarget;gt.current=n.scrollHeight-n.scrollTop-n.clientHeight<40,gt.current&&kn&&ye(!1),_t.current=n.scrollHeight,fn()},children:[s("div",{className:"sc-newbelow-wrap",children:kn&&o("button",{type:"button",className:"sc-newbelow",onClick:yn,children:[r("supportChat.msg.newBelow")," \u2193"]})}),o("div",{className:"sc-content",ref:hn,children:[c==="merchant"&&G&&p.length>0&&s(Vn,{availability:G}),c==="merchant"&&G&&p.length>0&&s(qs,{availability:G,recentReply:p.some(t=>t.from==="agent"&&!t.bot&&Date.now()-Date.parse(t.at)<30*6e4)}),rn&&s("div",{className:"sc-actions-status",children:rn}),p.length===0&&o("div",{className:"sc-empty",children:[s("strong",{children:r("supportChat.emptyTitle")}),r(G?"supportChat.emptyBodyShort":"supportChat.emptyBody"),G&&o("div",{className:"sc-empty-card",children:[s(Vn,{availability:G}),s(Vs,{availability:G})]})]}),V.map((t,n)=>{const a=V[n-1]?.at,i=(!a||Y(a)!==Y(t.at))&&s("div",{className:"sc-day",children:new Date(t.at).toLocaleDateString([],{weekday:"short",day:"numeric",month:"short"})});if(t.group)return o("div",{style:{display:"contents"},children:[i,s("i",{className:"sc-at","data-at":t.at}),s(la,{actions:t.group,store:X})]},`a-${t.group[0].id}`);const e=t.message,l=Ms(e.from);return o("div",{style:{display:"contents"},onClickCapture:c==="merchant"&&e.from==="agent"&&e.kind==="text"?d=>{const m=d.target.closest?.("a[href]");m&&/^https?:/.test(m.href)&&Mt?.(e.id,"link",m.href.slice(0,300))}:void 0,children:[i,s("i",{className:"sc-at","data-at":e.at,"data-msg":e.id}),e.deletedAt?c==="agent"?o("div",{className:`sc-deleted sc-deleted--${l}`,children:[s("s",{children:e.body.length>120?`${e.body.slice(0,117)}...`:e.body}),s("span",{children:r("supportChat.msg.deletedBy",{name:e.deletedBy??""})}),en&&s("button",{type:"button",className:"sc-deleted-undo",onClick:()=>{en(e.id)},children:r("supportChat.msg.undoDelete")})]}):null:e.kind==="draft"?c==="agent"?s(da,{message:e,time:F(e.at),onDraft:Nt,editing:L?.id===e.id,onEdit:()=>{zt(null),ue({id:e.id,name:e.agentName??"Claude"}),j(e.body)}}):null:e.kind==="event"?c==="agent"?s(ca,{message:e,time:F(e.at)}):null:e.kind==="note"?c==="agent"?o("div",{className:`sc-note${e.reminder?" sc-note--reminder":""}`,"aria-label":r(e.reminder?"supportChat.reminders.noteLabel":"supportChat.note.label"),children:[o("div",{className:"sc-note-head",children:[s("svg",{viewBox:"0 0 20 20",width:"13",height:"13","aria-hidden":!0,children:s("path",{d:"M4.5 3.5h11v8l-4 4.5h-7zM11.5 16v-4.5h4M7.5 7.5h5M7.5 10.5h2.5",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})}),r(e.reminder?"supportChat.reminders.noteTitle":"supportChat.note.title",{name:e.agentName??""}),e.from==="agent"&&!e.reminder&&(J||ct)?s(_e,{inline:!0,side:"agent",onReply:()=>Ie(e),onEdit:ct&&e.agentName===W?()=>In(e):void 0,onDelete:J?()=>J(e.id):void 0,copyText:e.body}):null,o("span",{children:[F(e.at),e.editedAt?` \xB7 ${r("supportChat.edit.edited")}`:""]})]}),s("div",{className:"sc-note-body",children:s(Ve,{text:e.body,image:Xt,inline:(d,m)=>zn(d,K.length?K:e.mentions??[]).map((h,v)=>h.agent?o("span",{className:"sc-mention",children:["@",h.agent]},`${m}-${v}`):s(He,{children:cn(h.text,`${m}-${v}`)},`${m}-${v}`))})}),Et(e).length&&z?s(Wn,{files:Et(e),fileUrl:z,fetchFile:jt}):null]}):null:l==="system"?s("div",{className:"sc-system",children:e.body}):e.kind==="password_request"?o(k,{children:[o("div",{className:`sc-row sc-row--${l} sc-row--card`,children:[rt(e,l),s(It,{viewer:c,message:e,children:s(Gs,{message:e,onOpen:c==="merchant"?()=>Mt?.(e.id,"open"):void 0})})]}),yt(e,l)]}):e.kind==="feature_request"?o(k,{children:[o("div",{className:`sc-row sc-row--${l} sc-row--card`,children:[rt(e,l),s(It,{viewer:c,message:e,children:s(Zs,{message:e,onAdd:c==="merchant"&&an?()=>an(e.id):void 0})})]}),yt(e,l)]}):e.kind==="ticket"?o(k,{children:[o("div",{className:`sc-row sc-row--${l} sc-row--card`,children:[rt(e,l),s(Qs,{message:e})]}),yt(e,l)]}):e.kind==="custom"&&e.card?o(k,{children:[o("div",{className:`sc-row sc-row--${l} sc-row--card`,children:[rt(e,l),s(ga,{tree:e.card.tree,name:e.card.name})]}),yt(e,l)]}):e.kind==="help_offer"?o(k,{children:[o("div",{className:`sc-row sc-row--${l} sc-row--card`,children:[rt(e,l),s(It,{viewer:c,message:e,children:s(_s,{message:e,answered:p.slice(p.indexOf(e)+1).some(d=>d.from==="merchant"),onAnswer:c==="merchant"?d=>{Mt?.(e.id,d===r("supportChat.helpOffer.yesMessage")?"help_yes":"help_no"),Ge(d,[])}:void 0})})]}),yt(e,l)]}):e.kind==="review_request"&&e.review?o(k,{children:[o("div",{className:`sc-row sc-row--${l}`,children:[rt(e,l),s(It,{viewer:c,message:e,children:s(pa,{message:e,shopOwnerName:it,listing:$t,preview:c==="agent",onState:(d,m)=>Un?.(e.id,d,m),onAway:c==="merchant"?d=>Mt?.(e.id,"review_away",d):void 0})})]}),yt(e,l)]}):e.kind==="subscription"&&e.subscriptionId&&ot||e.kind==="link"&&e.link||e.kind==="pricing"&&e.pricing||e.kind==="offer"&&e.offerId&&ot?o(k,{children:[o("div",{className:`sc-row sc-row--${l} sc-row--card`,children:[rt(e,l),l==="agent"&&e.from==="agent"&&s(Ct,{name:e.agentName??"Stefan",size:28}),c==="agent"&&e.from==="agent"&&s("span",{className:"sc-own-avatar",children:s(Ct,{name:e.agentName??"Stefan",size:28})}),s(It,{viewer:c,message:e,children:s(Kn,{value:Os(e.id),children:e.kind==="link"&&e.link?s(ma,{link:e.link}):e.kind==="pricing"&&e.pricing?s(ka,{pricing:e.pricing}):e.kind==="offer"&&e.offerId?s(Gn,{refId:`offer-${e.offerId}`}):s(Gn,{refId:e.subscriptionId})})})]}),o("div",{className:"sc-meta",style:{textAlign:l==="merchant"?"right":"left",paddingLeft:l==="agent"&&e.from==="agent"?36:0,paddingRight:c==="agent"&&e.from==="agent"?36:0},children:[je(e),e.from==="agent"&&e.agentName?`${e.agentName} \xB7 `:"",F(e.at)]})]}):(()=>{const d=mn(V[n-1],t),m=mn(t,V[n+1]),h=e.from==="agent",v=`sc-bubble${h?" sc-bubble--card":""}${e.bot?" sc-bubble--ai":""}${d?" sc-bubble--after":""}${m?" sc-bubble--before":""}`,I=(()=>{for(let u=n-1;u>=0;u--){const N=V[u].message;if(N&&N.kind!=="note")return N}return null})(),B=!!(I&&I.from==="agent"&&I.agentName===e.agentName&&Date.parse(e.at)-Date.parse(I.at)<Na&&Y(I.at)===Y(e.at)),b=h&&!B?o("header",{className:"ho-head sc-card-head",children:[s(Ct,{name:e.agentName??"Stefan",size:30}),o("div",{children:[o("strong",{children:[e.agentName??"Stefan",e.bot&&s("em",{className:"sc-ai-label",children:"AI"})]}),s("span",{children:r(e.bot?"supportChat.ai.byline":"supportChat.preview.fromTeam",$a())})]})]}):null,R=c==="agent"&&e.bot&&e.verified?s("div",{className:"sc-verified",children:r("supportChat.verified.checked",{text:e.verified})}):null,vt=e.bot&&(e.ai||R)?o(k,{children:[b,e.ai?s(ra,{run:e.ai,detail:c==="agent",since:e.at}):null,R]}):b;return o(k,{children:[o("div",{className:`sc-row sc-row--${l}${d?" sc-row--cont":""}${e.bot?" sc-row--ai":""}`,children:[c==="agent"&&e.from==="merchant"&&X?s("span",{className:"sc-row-av","aria-hidden":!0,children:!m&&s(ua,{shop:X.shop,name:X.name,look:X.look,size:28})}):null,o("div",{className:"sc-msg-stack",children:[(()=>{const u=Qn(e,c);if(!u&&!(c==="agent"&&e.translating))return null;const N=u?.lang??null;return o("div",{className:`sc-translated sc-translated--${l}`,children:[N&&s("span",{className:"sc-translated-flags","aria-hidden":!0,children:u?.kind==="from"?`${qn(N,Xe)} \u203A ${We}`:u?.kind==="to"?`${We} \u203A ${qn(N,Xe)}`:We}),u?u.kind==="from"?r("supportChat.translate.from",{language:_n(u.lang,de.language)}):u.kind==="to"?r("supportChat.translate.sentIn",{language:_n(u.lang,de.language)}):r("supportChat.translate.translated"):r("supportChat.translate.translating"),u&&s("button",{type:"button",onClick:()=>is(e.id),"aria-pressed":Rt.has(e.id),children:r(u.kind==="to"!==Rt.has(e.id)?"supportChat.translate.showTranslation":"supportChat.translate.showOriginal")})]})})(),(e.body||e.bot&&e.ai)&&o("div",{className:"sc-bubble-anchor",children:[(c==="agent"||dt)&&e.kind==="text"&&e.body&&s(_e,{side:l,onReply:()=>Ie(e),onReact:dt?u=>dt(e.id,u):void 0,onEdit:c==="agent"&&ct&&e.from==="agent"&&e.agentName===W?()=>In(e):void 0,onDelete:c==="agent"&&J&&e.from==="agent"&&!e.bot?()=>J(e.id):void 0,copyText:Ke(e,c,Rt.has(e.id)),reacted:e.reactions?.filter(u=>c==="merchant"?u.by.includes("merchant"):W&&u.by.includes(W)).map(u=>u.emoji)}),s(va.Provider,{value:c==="agent"?ss(e):null,children:ot?s(fa,{text:Ke(e,c,Rt.has(e.id)),bubbleClass:v,head:o(k,{children:[vt,En(e)]}),links:e.refs,image:Xt}):o("div",{className:v,children:[vt,En(e),s(Ve,{text:Ke(e,c,Rt.has(e.id)),inline:cn,image:Xt})]})})]}),e.id===xs&&o("div",{className:"sc-human",children:[s(Ks,{size:15}),r("supportChat.preview.helpPerks")]}),e.reactions?.length?s("div",{className:"sc-reacts",children:e.reactions.map(u=>o("button",{type:"button",className:`sc-react${(c==="merchant"?u.by.includes("merchant"):W&&u.by.includes(W))?" sc-react--mine":""}`,title:u.by.map(N=>N==="merchant"?c==="merchant"?r("supportChat.msg.you"):X?.name??r("supportChat.msg.merchant"):N).join(", "),disabled:!dt,onClick:()=>dt&&void dt(e.id,u.emoji),children:[u.emoji,u.by.length>1&&s("span",{children:u.by.length})]},u.emoji))}):null,e.bot&&e.progress?.length?s(ia,{steps:e.progress}):null,es&&e.bot&&c==="agent"?s("div",{className:"sc-visitor-cta",children:s("span",{children:r("supportChat.visitor.ctaShown")})}):null,e.bot&&e.assigned?o("div",{className:"sc-assigned",children:[s(Ct,{name:e.assigned,size:20}),s("span",{children:r("supportChat.ai.assigned",{name:e.assigned})})]}):null,e.choices?.length?s(oa,{choices:e.choices,active:c==="merchant"&&e.id===Ls&&dn.length===0,picked:Rs(e.id),onPick:Ts}):null,Et(e).length&&z?s(Wn,{files:Et(e),fileUrl:z,fetchFile:jt}):null]})]}),c==="agent"&&e.clicks?.some(u=>u.action==="link"&&!/^https?:/.test(u.detail??""))&&(()=>{const u=e.clicks.filter(N=>N.action==="link"&&!/^https?:/.test(N.detail??""));return s("div",{className:"sc-link-opened",title:u.map(N=>`${F(N.at)} ${N.detail??""}`).join(`
|
|
6
|
+
`),children:r("supportChat.msg.linkOpened",{time:F(u[0].at),count:u.length})})})(),!m&&o("div",{className:"sc-meta",style:{textAlign:l==="merchant"?"right":"left"},children:[je(e),e.email?`${r("supportChat.email.via")} \xB7 `:"",F(e.at),e.editedAt?` \xB7 ${r("supportChat.edit.edited")}`:"",e.email&&!e.email.verified&&c==="agent"?s("span",{className:"sc-meta-warn",children:` \xB7 ${r("supportChat.email.unverified")}`}):null]})]})})()]},e.id)}),dn.filter(t=>!(t.status==="sending"&&rs(t))).map(t=>o("div",{className:`sc-out${t.status==="failed"?" sc-out--failed":""}`,children:[s("div",{className:"sc-row sc-row--merchant",children:s("div",{className:"sc-msg-stack",children:s("div",{className:t.note?"sc-note":"sc-bubble",children:s(Ve,{image:Xt,text:t.card?r("supportChat.outbox.card",{card:r(`supportChat.inbox.tabs.${t.card.kind}`)}):t.body||r("supportChat.outbox.files",{count:t.files.length})})})})}),s("div",{className:`sc-meta sc-out-meta${t.status==="sending"?" sc-out-meta--sending":""}`,role:t.status==="failed"?"alert":void 0,children:t.status==="sending"?r("supportChat.outbox.sending"):o(k,{children:[r("supportChat.outbox.failed"),s("button",{type:"button",onClick:()=>Wt(t),children:r("supportChat.outbox.resend")})]})})]},t.key)),C&&o("div",{className:"sc-row sc-row--agent sc-typing-row",role:"status","aria-live":"polite",children:[C.agent&&s(Ct,{name:C.name,size:28}),o("div",{className:`sc-typing${C.text?" sc-typing--peek":""}`,children:[C.text?o(k,{children:[o("span",{className:"sc-typing-label",children:[r("supportChat.typing.peek",{name:C.name}),C.agent&&s("em",{className:`sc-typing-kind${C.note?" sc-typing-kind--note":""}`,children:r(C.note?"supportChat.typing.note":"supportChat.typing.reply")})]}),s("span",{className:"sc-typing-text",children:C.text.length>400?`...${C.text.slice(-400)}`:C.text})]}):o("span",{className:"sc-typing-label",children:[r("supportChat.typing.dots",{name:C.name}),C.agent&&s("em",{className:`sc-typing-kind${C.note?" sc-typing-kind--note":""}`,children:r(C.note?"supportChat.typing.note":"supportChat.typing.reply")})]}),o("span",{className:"sc-dots","aria-hidden":!0,children:[s("i",{}),s("i",{}),s("i",{})]})]})]}),s("div",{ref:us})]})]}),D&&o("div",{className:"sc-note-bar sc-edit-bar",role:"status",children:[s("span",{children:r(c==="agent"?"supportChat.edit.modeAgent":"supportChat.edit.mode",{key:ke})}),s("button",{type:"button",onClick:Be,children:r("supportChat.edit.cancel")})]}),L&&o("div",{className:"sc-note-bar sc-edit-bar sc-draft-bar",role:"status",children:[s("span",{children:r("supportChat.draft.editing",{name:L.name,key:ke})}),o("span",{className:"sc-draft-bar-actions",children:[s("button",{type:"button",onClick:Jt,children:r("supportChat.draft.cancelEdits")}),s("button",{type:"button",className:"sc-draft-update",disabled:!g.trim(),onClick:()=>{const t=g.trim();t&&Nt&&L&&Nt(L.id,"update",t),Jt()},children:r("supportChat.draft.update")})]})]}),Pt&&!D&&!L&&o("div",{className:"sc-replying",role:"status",children:[s("span",{className:"sc-replying-bar","aria-hidden":!0}),o("span",{className:"sc-replying-text",children:[s("strong",{children:r("supportChat.msg.replyingTo",{name:Pn(Pt)})}),s("span",{children:Pt.body.replace(/\s+/g," ").slice(0,140)})]}),s("button",{type:"button","aria-label":r("supportChat.msg.cancelReply"),onClick:()=>Ee(null),children:"\xD7"})]}),q&&!D&&!L&&o("div",{className:"sc-mode",role:"tablist","aria-label":r("supportChat.note.label"),children:[s("button",{type:"button",role:"tab","aria-selected":!x,onClick:()=>{St(!1),et(!0)},children:r("supportChat.note.tabReply")}),s("button",{type:"button",role:"tab","aria-selected":x,className:"sc-mode-note",onClick:()=>{St(!0),et(!1)},children:r("supportChat.note.tabNote")})]}),!D&&!L&&!Tt&&(x||(ht||Gt)&&Kt)&&s("div",{className:`sc-note-bar${x?"":" sc-note-bar--reply"}`,role:"status",children:x?o(k,{children:[s("svg",{viewBox:"0 0 20 20",width:"13",height:"13","aria-hidden":!0,children:s("path",{d:"M6 9V7a4 4 0 1 1 8 0v2M5 9h10v8H5z",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinejoin:"round"})}),s("span",{children:vn.length||ht?r("supportChat.note.mode",{names:vn.join(` ${r("supportChat.note.and")} `)||ht}):r("supportChat.note.modeTeam")}),s("button",{type:"button",onClick:()=>et(!0),children:r("supportChat.note.sendAsReply")})]}):o(k,{children:[s("span",{children:r("supportChat.note.replyMode")}),s("button",{type:"button",onClick:()=>et(!1),children:r("supportChat.note.makeNote")})]})}),H!==null&&o("div",{className:"sc-shortcuts sc-refpick",role:"listbox","aria-label":r("supportChat.refPick.hint"),children:[Q&&s("button",{type:"button",className:"sc-refpick-back",onMouseDown:t=>t.preventDefault(),onClick:()=>At(null),children:r("supportChat.refPick.back")}),nt.data?Ut.length===0?s("p",{className:"sc-refpick-note",children:r("supportChat.refPick.none")}):Ut.map(t=>o(He,{children:[t.section&&s("span",{className:"sc-refpick-section",children:t.section}),o("button",{type:"button",role:"option","aria-selected":!1,onMouseDown:n=>n.preventDefault(),onClick:t.pick,children:[s("span",{className:"sc-refpick-thumb",children:t.image?s("img",{src:t.image,alt:""}):null}),o("span",{className:"sc-shortcut-text",children:[s("strong",{children:t.label}),t.sub&&s("span",{children:t.sub})]})]})]},t.key)):s("p",{className:"sc-refpick-note",children:r("supportChat.refPick.searching")})]}),P.length>0&&s("div",{className:"sc-shortcuts sc-link-suggest",role:"listbox","aria-label":r("supportChat.links.button"),children:P.map((t,n)=>s("button",{type:"button",role:"option","aria-selected":n===Math.min(Le,P.length-1),className:n===Math.min(Le,P.length-1)?"sc-shortcut--on":void 0,onMouseDown:a=>a.preventDefault(),onMouseEnter:()=>Re(n),onClick:()=>wn(t),children:o("span",{className:"sc-shortcut-text",children:[s("strong",{children:t.label}),s("span",{children:t.url.replace(/^https:\/\//,"")})]})},`${t.group}-${t.url}`))}),ft.length>0&&s("div",{className:"sc-shortcuts",role:"listbox","aria-label":r("supportChat.tools.shortcuts"),children:ft.map(t=>o("button",{type:"button",role:"option","aria-selected":!1,onMouseDown:n=>n.preventDefault(),onClick:()=>Cn(t),children:[o("span",{className:"sc-shortcut-key",children:["!",t.key]}),o("span",{className:"sc-shortcut-text",children:[o("strong",{children:[t.title,t.card&&s("em",{className:"sc-shortcut-card",children:r(`supportChat.inbox.tabs.${t.card.kind}`)})]}),s("span",{children:we(t.body)})]})]},t.key))}),_.length>0&&s("div",{className:"sc-suggest",role:"listbox","aria-label":r("supportChat.note.suggest"),children:_.map(t=>o("button",{type:"button",role:"option","aria-selected":t===$e,onMouseDown:n=>n.preventDefault(),onMouseEnter:()=>Ce(_.indexOf(t)),onClick:()=>Sn(t),children:[s(Ct,{name:t,size:22}),t]},t))}),(()=>{const t=[...Se.filter(n=>g.includes(n.text)).map(n=>({text:n.text,ref:n.ref})),...[...new Set(g.match(/#[A-Za-z]{0,6}\d{3,20}[A-Za-z]{0,6}\b/g)??[])].map(n=>({text:n,ref:n.slice(1)}))];return t.length&&ee&&!S?s("div",{className:"sc-draft-refs",children:t.map(n=>o("span",{className:"sc-draft-ref",children:[s(ha,{refId:n.ref,text:n.text}),s("button",{type:"button","aria-label":r("supportChat.files.remove"),onClick:()=>{A(a=>a.split(n.text).join("").replace(/ {2,}/g," ")),Qt(a=>a.filter(i=>i.ref!==n.ref))},children:s("svg",{viewBox:"0 0 20 20",width:"9",height:"9","aria-hidden":!0,children:s("path",{d:"M5 5l10 10M15 5L5 15",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round"})})})]},n.ref))}):null})(),Dt.some(t=>!t.inline||t.error)&&s(Ws,{files:Dt.filter(t=>!t.inline||t.error),removeLabel:r("supportChat.files.remove"),onRemove:t=>E(n=>n.filter(a=>a.key!==t))}),Lt&&o("div",{className:"sc-attached-card",children:[s("span",{children:r("supportChat.outbox.card",{card:r(`supportChat.inbox.tabs.${Lt.kind}`)})}),s("button",{type:"button","aria-label":r("supportChat.outbox.removeCard"),onClick:()=>pe(null),children:s("svg",{viewBox:"0 0 20 20",width:"10",height:"10","aria-hidden":!0,children:s("path",{d:"M5 5l10 10M15 5L5 15",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round"})})})]}),o("div",{ref:Vt,className:`sc-composer${ae?" sc-composer--top":""}${M?M.text?" sc-composer--cardtext":" sc-composer--card":""}${x&&!L?" sc-composer--note":""}${L?" sc-composer--draft":""}${Ht?" sc-composer--menu":""}${Ht&&ts?" sc-composer--plus":""}${me&&!M?" sc-composer--multi":""}`,children:[ae&&s("div",{className:"sc-composer-top",children:ae}),M&&!M.text&&M.label&&s("span",{className:"sc-composer-cardnote",children:M.label}),Ht&&o(k,{children:[s("button",{type:"button",className:"sc-plus","aria-label":r("supportChat.menu.open"),"aria-expanded":Ln,onClick:()=>De(t=>!t),children:s("svg",{viewBox:"0 0 20 20",width:"20",height:"20","aria-hidden":!0,children:s("path",{d:"M10 4v12M4 10h12",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round"})})}),Ln&&o(k,{children:[s("div",{className:"sc-menu-scrim",onClick:()=>De(!1),"aria-hidden":!0}),s("div",{className:"sc-menu",role:"menu",children:[...U?[{key:"camera",label:r("supportChat.menu.camera"),icon:s(te,{d:"M4 7.5h2.6l1.4-2h4l1.4 2H16a1 1 0 0 1 1 1V15a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V8.5a1 1 0 0 1 1-1z M10 13.6a2.6 2.6 0 1 0 0-5.2 2.6 2.6 0 0 0 0 5.2z"}),onSelect:()=>Rn.current?.click()},{key:"files",label:r("supportChat.menu.files"),icon:s(te,{d:"M13.5 6.5l-6 6a1.8 1.8 0 0 0 2.5 2.5l6.2-6.2a3.3 3.3 0 0 0-4.7-4.7L5.3 10.3a4.8 4.8 0 0 0 6.8 6.8l5.4-5.4"}),onSelect:()=>Pe.current?.click()}]:[],...ut?[{key:"hash",label:r("supportChat.tools.hash"),icon:s(te,{d:"M8 3.5 6.5 16.5M13.5 3.5 12 16.5M4 7.5h12.5M3.5 12.5H16"}),onSelect:()=>Yt("#")}]:[],...lt.length?[{key:"slash",label:r("supportChat.tools.slash"),icon:s(te,{d:"M11.8 6.5 8.2 13.5 M6.5 3h7a3.5 3.5 0 0 1 3.5 3.5v7a3.5 3.5 0 0 1-3.5 3.5h-7A3.5 3.5 0 0 1 3 13.5v-7A3.5 3.5 0 0 1 6.5 3z"}),onSelect:()=>Yt("!")}]:[],...Ht].map(t=>o("button",{type:"button",role:"menuitem","data-key":t.key,onClick:()=>{De(!1),t.onSelect()},children:[s("span",{className:"sc-menu-icon",children:t.icon}),t.label]},t.key))})]}),U&&s("input",{ref:Rn,type:"file",accept:"image/*",capture:"environment",hidden:!0,onChange:t=>{t.target.files&&Ot(t.target.files),t.target.value=""}})]}),at==="link"&&pt&&s(Js,{load:pt,onClose:()=>kt(null),onPick:t=>{if(kt(null),S)w.current?.insertLink(t.url);else{const n=O.current,a=n?g.slice(n.selectionStart,n.selectionEnd):"";Tn(`${qe(t.url,a.includes(`
|
|
7
|
+
`)?"":a)} `)}}}),(at==="emoji"||at==="gif"&&re)&&s(Ys,{onPick:t=>Tn(t),onClose:()=>kt(null),gif:re?{searchUrl:re,onPick:$s}:void 0,startOn:at==="gif"?"gif":"emoji"}),s("button",{type:"button","data-popover-toggle":!0,className:"sc-attach sc-emoji-btn","aria-label":r("supportChat.tools.emoji"),"aria-expanded":at==="emoji"||at==="gif",onClick:()=>kt(t=>t==="emoji"||t==="gif"?null:"emoji"),children:o("svg",{viewBox:"0 0 20 20",width:"18",height:"18","aria-hidden":!0,children:[s("circle",{cx:"10",cy:"10",r:"7.25",fill:"none",stroke:"currentColor",strokeWidth:"1.6"}),s("path",{d:"M7 11.5a3.6 3.6 0 0 0 6 0",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"}),s("circle",{cx:"7.6",cy:"8.2",r:"1",fill:"currentColor"}),s("circle",{cx:"12.4",cy:"8.2",r:"1",fill:"currentColor"})]})}),c==="agent"&&pt&&s("button",{type:"button","data-popover-toggle":!0,className:"sc-attach sc-link-btn","aria-label":r("supportChat.links.button"),title:r("supportChat.links.button"),"aria-expanded":at==="link",onClick:()=>kt(t=>t==="link"?null:"link"),children:s("svg",{viewBox:"0 0 20 20",width:"17",height:"17","aria-hidden":!0,children:s("path",{d:"M8.6 11.4a3 3 0 0 0 4.2 0l2.6-2.6a3 3 0 0 0-4.2-4.2l-1 1M11.4 8.6a3 3 0 0 0-4.2 0l-2.6 2.6a3 3 0 0 0 4.2 4.2l1-1",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"})})}),ut&&s("button",{type:"button",className:"sc-attach sc-tok-btn","aria-label":r("supportChat.tools.hash"),title:r("supportChat.tools.hash"),onClick:()=>Yt("#"),children:s("svg",{viewBox:"0 0 20 20",width:"17",height:"17","aria-hidden":!0,children:s("path",{d:"M8 3.5 6.5 16.5M13.5 3.5 12 16.5M4 7.5h12.5M3.5 12.5H16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"})})}),lt.length>0&&s("button",{type:"button",className:"sc-attach sc-tok-btn","aria-label":r("supportChat.tools.slash"),title:r("supportChat.tools.slash"),onClick:()=>Yt("!"),children:o("svg",{viewBox:"0 0 20 20",width:"17",height:"17","aria-hidden":!0,children:[s("rect",{x:"3",y:"3",width:"14",height:"14",rx:"3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.6"}),s("path",{d:"M11.8 6.5 8.2 13.5",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"})]})}),U&&o(k,{children:[s("button",{type:"button",className:"sc-attach","aria-label":r("supportChat.files.add"),onClick:()=>Pe.current?.click(),children:s("svg",{viewBox:"0 0 20 20",width:"18",height:"18","aria-hidden":!0,children:s("path",{d:"M13.5 6.5l-6 6a1.8 1.8 0 0 0 2.5 2.5l6.2-6.2a3.3 3.3 0 0 0-4.7-4.7L5.3 10.3a4.8 4.8 0 0 0 6.8 6.8l5.4-5.4",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"})})}),s("input",{ref:Pe,type:"file",multiple:!0,hidden:!0,accept:[...Object.keys(ze),...Object.values(ze).map(t=>`.${t}`)].join(","),onChange:t=>{t.target.files&&Ot(t.target.files),t.target.value=""}})]}),S?s(aa,{ref:w,placeholder:M?.text?.placeholder??r(x?"supportChat.note.notePlaceholder":lt.length?"supportChat.tools.placeholder":q?"supportChat.note.placeholder":"supportChat.agentPlaceholder"),onChange:({text:t,refs:n,before:a})=>{A(t),Qt(n),ds(a)},onKey:Mn,onPasteFiles:U?t=>Ot(t,!0):void 0,mentions:x?K:[]}):s(k,{children:o("div",{className:"sc-input",children:[s("div",{className:"sc-mirror",ref:Ae,"aria-hidden":!0,children:bs}),s("textarea",{onPaste:t=>{if(U&&t.clipboardData.files.length){t.preventDefault(),Ot(t.clipboardData.files);return}const n=t.currentTarget,a=t.clipboardData.getData("text/plain").trim(),i=n.value.slice(n.selectionStart,n.selectionEnd);if(!na(a)||!i.trim()||i.includes(`
|
|
8
|
+
`))return;t.preventDefault();const e=qe(a,i),l=n.selectionStart,d=`${n.value.slice(0,l)}${e}${n.value.slice(n.selectionEnd)}`;A(d.slice(0,4e3)),requestAnimationFrame(()=>n.setSelectionRange(l+e.length,l+e.length))},ref:O,onScroll:t=>Ae.current&&(Ae.current.scrollTop=t.currentTarget.scrollTop),rows:1,value:g,maxLength:4e3,placeholder:r(c==="merchant"?"supportChat.placeholder":x?"supportChat.note.notePlaceholder":lt.length?"supportChat.tools.placeholder":q?"supportChat.note.placeholder":"supportChat.agentPlaceholder"),onChange:t=>A(t.target.value),onKeyDown:t=>{Mn(t.nativeEvent)?t.preventDefault():t.key==="Enter"&&!t.nativeEvent.isComposing&&ys(t)}})]})}),s("button",{type:"button",className:"sc-send",title:c==="agent"?r("supportChat.sendWith",{key:ke}):void 0,onClick:Bn,disabled:M?M.blocked:!g.trim()&&!vs.length&&!Lt||Yn||Dn,"aria-label":r("supportChat.send"),children:s("svg",{viewBox:"0 0 20 20",width:"18",height:"18","aria-hidden":!0,children:s("path",{d:"M10 15.5v-11M5 9l5-5 5 5",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]})})})})};export{sr as ChatThread,te as MenuIcon};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { LinkShortcut } from "@whoa-chat/core/links";
|
|
2
|
+
type Gif = {
|
|
3
|
+
id: string;
|
|
4
|
+
title: string;
|
|
5
|
+
preview: string;
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
};
|
|
9
|
+
export declare const EmojiPicker: ({ onPick, onClose, gif, startOn, }: {
|
|
10
|
+
onPick: (emoji: string) => void;
|
|
11
|
+
onClose: () => void;
|
|
12
|
+
gif?: {
|
|
13
|
+
searchUrl: string;
|
|
14
|
+
onPick: (gif: Gif) => void;
|
|
15
|
+
};
|
|
16
|
+
startOn?: "emoji" | "gif";
|
|
17
|
+
}) => import("react").JSX.Element;
|
|
18
|
+
export declare const GifPicker: ({ searchUrl, onPick, onClose, embedded }: {
|
|
19
|
+
searchUrl: string;
|
|
20
|
+
onPick: (gif: Gif) => void;
|
|
21
|
+
onClose: () => void;
|
|
22
|
+
embedded?: boolean;
|
|
23
|
+
}) => import("react").JSX.Element;
|
|
24
|
+
export declare const LinkPicker: ({ load, onPick, onClose }: {
|
|
25
|
+
load: () => Promise<LinkShortcut[]>;
|
|
26
|
+
onPick: (link: LinkShortcut) => void;
|
|
27
|
+
onClose: () => void;
|
|
28
|
+
}) => import("react").JSX.Element;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Fragment as M,jsx as i,jsxs as v}from"react/jsx-runtime";import{useEffect as w,useRef as P,useState as g}from"react";import{useTranslation as N}from"./i18n.js";import{EMOJI_GROUPS as E,searchEmojis as G}from"./emojis.js";import{brandVars as S}from"./host.js";const L=p=>{const m=P(null);return w(()=>{const a=r=>m.current&&!m.current.contains(r.target)&&!r.target.closest?.("[data-popover-toggle]")&&p(),o=r=>r.key==="Escape"&&p(),n=window.setTimeout(()=>document.addEventListener("mousedown",a),0);return document.addEventListener("keydown",o),()=>{window.clearTimeout(n),document.removeEventListener("mousedown",a),document.removeEventListener("keydown",o)}},[p]),m},q=({onPick:p,onClose:m,gif:a,startOn:o="emoji"})=>{const{t:n}=N("home"),r=L(m),[l,b]=g(a?o:"emoji"),[u,h]=g(""),[s,y]=g(E[0].id),d=u?G(u):E.find(e=>e.id===s).emojis;return v("div",{className:`ct-pop ${l==="gif"?"ct-gif":"ct-emoji"}`,ref:r,role:"dialog","aria-label":n(l==="gif"?"supportChat.tools.gif":"supportChat.tools.emoji"),children:[a&&i("div",{className:"ct-panes",role:"tablist",children:["emoji","gif"].map(e=>i("button",{type:"button",role:"tab","aria-selected":l===e,className:l===e?"ct-pane ct-pane--on":"ct-pane",onClick:()=>b(e),children:n(e==="gif"?"supportChat.tools.gifs":"supportChat.tools.emoji")},e))}),l==="gif"&&a?i($,{searchUrl:a.searchUrl,onPick:a.onPick,onClose:m,embedded:!0}):v(M,{children:[i("input",{className:"ct-search",autoFocus:!0,value:u,placeholder:n("supportChat.tools.searchEmoji"),onChange:e=>h(e.target.value)}),!u&&i("div",{className:"ct-tabs",children:E.map(e=>i("button",{type:"button",className:e.id===s?"ct-tab ct-tab--on":"ct-tab",onClick:()=>y(e.id),"aria-label":n(`supportChat.tools.groups.${e.id}`),children:e.emojis[0][0]},e.id))}),v("div",{className:"ct-grid",children:[d.map(([e,k])=>i("button",{type:"button",title:k.split(" ")[0],onClick:()=>p(e),children:e},e)),d.length===0&&i("p",{className:"ct-empty",children:n("supportChat.tools.noEmoji")})]})]})]})},$=({searchUrl:p,onPick:m,onClose:a,embedded:o})=>{const{t:n}=N("home"),r=L(o?()=>{}:a),[l,b]=g(""),[u,h]=g({loading:!0,gifs:[]});return w(()=>{let s=!0;const y=window.setTimeout(()=>{h(d=>({...d,loading:!0})),fetch(`${p}?q=${encodeURIComponent(l)}`).then(d=>d.json()).then(d=>s&&h({loading:!1,gifs:d.gifs??[],error:d.error})).catch(()=>s&&h({loading:!1,gifs:[],error:"failed"}))},250);return()=>{s=!1,window.clearTimeout(y)}},[l,p]),v("div",{className:o?"ct-gif-pane":"ct-pop ct-gif",ref:o?void 0:r,role:o?void 0:"dialog","aria-label":n("supportChat.tools.gif"),children:[i("input",{className:"ct-search",autoFocus:!0,value:l,placeholder:n("supportChat.tools.searchGif"),onChange:s=>b(s.target.value)}),u.error==="no-key"?i("p",{className:"ct-empty",children:n("supportChat.tools.gifNoKey")}):v("div",{className:"ct-gifs",children:[u.gifs.map(s=>i("button",{type:"button",title:s.title,onClick:()=>m(s),children:i("img",{src:s.preview,alt:s.title,loading:"lazy"})},s.id)),!u.loading&&!u.gifs.length&&i("p",{className:"ct-empty",children:n("supportChat.tools.noGif")})]}),i("span",{className:"ct-credit",children:n("supportChat.tools.poweredByGiphy")})]})},A=({load:p,onPick:m,onClose:a})=>{const{t:o}=N("home"),n=L(a),[r,l]=g(null),[b,u]=g(""),[h,s]=g(0);w(()=>{let t=!0;return p().then(c=>t&&l(c),()=>t&&l([])),()=>{t=!1}},[p]);const y=b.toLowerCase().split(/\s+/).filter(Boolean),d=(r??[]).filter(t=>y.every(c=>`${t.label} ${t.url}`.toLowerCase().includes(c))).slice(0,60),e=[{id:"saved",label:o("supportChat.links.saved")},{id:"app",label:o("supportChat.links.app",S())},{id:"shopify",label:o("supportChat.links.shopify")}],k=e.flatMap(t=>d.filter(c=>c.group===t.id)),j=t=>t&&m(t);return v("div",{className:"ct-pop ct-links",ref:n,role:"dialog","aria-label":o("supportChat.links.button"),children:[i("input",{className:"ct-search",autoFocus:!0,value:b,placeholder:o("supportChat.links.search"),"aria-label":o("supportChat.links.search"),onChange:t=>{u(t.target.value),s(0)},onKeyDown:t=>{t.key==="ArrowDown"?(t.preventDefault(),s(c=>Math.min(c+1,k.length-1))):t.key==="ArrowUp"?(t.preventDefault(),s(c=>Math.max(c-1,0))):t.key==="Enter"&&(t.preventDefault(),j(k[h]))}}),v("div",{className:"ct-links-list",role:"listbox","aria-label":o("supportChat.links.button"),children:[r===null&&i("p",{className:"ct-links-empty",children:o("supportChat.links.loading")}),r!==null&&!k.length&&i("p",{className:"ct-links-empty",children:o("supportChat.links.empty")}),e.map(t=>{const c=k.filter(f=>f.group===t.id);return c.length?v("div",{className:"ct-links-group",children:[i("p",{className:"ct-links-head",children:t.label}),c.map(f=>{const C=k.indexOf(f);return i("button",{type:"button",role:"option","aria-selected":C===h,className:`ct-link${C===h?" ct-link--on":""}`,title:f.url,onMouseEnter:()=>s(C),onClick:()=>j(f),children:f.label},`${f.group}-${f.url}`)})]},t.id):null})]})]})};export{q as EmojiPicker,$ as GifPicker,A as LinkPicker};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as t,jsxs as i}from"react/jsx-runtime";const l={neutral:"var(--sc-ink)",strong:"var(--sc-ink)",soft:"var(--sc-ink-2)",muted:"var(--sc-ink-3)",good:"var(--cc-good)",warn:"var(--cc-warn)",bad:"var(--cc-bad)",accent:"var(--cc-accent)"},d={neutral:"var(--sc-surface)",strong:"var(--sc-ink)",soft:"var(--sc-soft)",muted:"var(--sc-soft)",good:"var(--cc-good-bg)",warn:"var(--cc-warn-bg)",bad:"var(--cc-bad-bg)",accent:"var(--cc-accent-bg)",gradient:"var(--cc-gradient-soft)"},g={...l,neutral:"var(--sc-line)",soft:"var(--sc-line)",muted:"var(--sc-line)"},u={xs:11.5,sm:12.5,md:14,lg:16,xl:20,"2xl":26},f={regular:400,medium:550,bold:700},m={start:"flex-start",center:"center",end:"flex-end",between:"space-between"},v={start:"flex-start",center:"center",end:"flex-end",stretch:"stretch"},r=e=>{if(!e)return;const a={};e.color&&(a.color=l[e.color]??e.color);const c=e.background?d[e.background]??e.background:void 0;return e.border==="gradient"?(a.border="1.5px solid transparent",a.background=`linear-gradient(${c??"var(--sc-surface)"}, ${c??"var(--sc-surface)"}) padding-box, var(--cc-gradient) border-box`):(c&&(a.background=c),e.border&&(a.boxShadow=`inset 0 0 0 1.5px ${g[e.border]??e.border}`)),e.size&&(a.fontSize=u[e.size]),e.weight&&(a.fontWeight=f[e.weight]),e.align&&(a.textAlign=e.align==="start"?"left":e.align==="end"?"right":"center"),e.padding!==void 0&&(a.padding=e.padding),e.radius!==void 0&&(a.borderRadius=e.radius),e.gap!==void 0&&(a.gap=e.gap),e.direction&&(a.flexDirection=e.direction),e.justify&&(a.justifyContent=m[e.justify]),e.items&&(a.alignItems=v[e.items]),e.grow&&Object.assign(a,{flex:"1 1 0",minWidth:0}),e.width!==void 0&&(a.width=e.width),e.height!==void 0&&(a.height=e.height),a},s=e=>e.tone&&e.tone!=="neutral"?` cc-tone--${e.tone}`:"",o=({n:e})=>{const a=e.children?.map((c,n)=>t(o,{n:c},n));switch(e.t){case"title":return t("h3",{className:"cc-title",style:r(e.style),children:e.text});case"text":return t("p",{className:`cc-text${s(e)}`,style:r(e.style),children:e.text});case"stat":return i("div",{className:`cc-stat${s(e)}`,style:r(e.style),children:[t("span",{className:"cc-stat-label",children:e.text}),t("strong",{className:"cc-stat-value",children:e.value}),e.hint&&t("span",{className:"cc-hint",children:e.hint})]});case"row":return t("div",{className:"cc-row",style:r(e.style),children:a});case"list":return t("ul",{className:`cc-list${e.style?.gap!==void 0?" cc-list--spaced":""}`,style:r(e.style),children:a});case"item":return i("li",{className:`cc-item${s(e)}`,style:r(e.style),children:[i("span",{className:"cc-item-main",children:[e.text,e.hint&&t("span",{className:"cc-hint",children:e.hint})]}),a,e.value&&t("strong",{children:e.value})]});case"image":return t("img",{className:`cc-image${e.style?.width?" cc-image--sized":""}`,src:e.src,alt:e.alt??"",loading:"lazy",referrerPolicy:"no-referrer",style:r(e.style)});case"badge":return t("span",{className:`cc-badge${s(e)}`,style:r(e.style),children:e.text});case"button":return t("a",{className:`cc-button${e.tone==="accent"||e.tone==="gradient"?` cc-button--${e.tone}`:""}`,href:e.href,target:"_blank",rel:"noopener noreferrer",style:r(e.style),children:e.text});case"divider":return t("hr",{className:"cc-divider",style:r(e.style)});case"box":return t("div",{className:"cc-box",style:r(e.style),children:a});case"meter":return i("div",{className:`cc-meter${s(e)}`,style:r(e.style),role:"meter","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":e.fill??0,"aria-label":e.text,children:[t("span",{className:"cc-meter-fill",style:{width:`${Math.max(2,e.fill??0)}%`}}),t("span",{className:"cc-meter-dot",style:{left:`${Math.max(2,Math.min(98,e.fill??0))}%`}})]});default:return null}},b=({tree:e,name:a})=>t("article",{className:"cc-card","aria-label":a,children:e.children?.map((c,n)=>t(o,{n:c},n))});export{b as CustomCard};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SupportMessageView } from "@whoa-chat/core/types";
|
|
2
|
+
export declare const DraftCard: ({ message, time, onDraft, onEdit, editing }: {
|
|
3
|
+
message: SupportMessageView;
|
|
4
|
+
time: string;
|
|
5
|
+
onDraft?: (id: string, action: "send" | "discard" | "update", body?: string, opts?: {
|
|
6
|
+
card: boolean;
|
|
7
|
+
}) => Promise<unknown>;
|
|
8
|
+
onEdit?: () => void;
|
|
9
|
+
editing?: boolean;
|
|
10
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as t,jsxs as d}from"react/jsx-runtime";import{useState as p}from"react";import{useTranslation as k}from"./i18n.js";import{FormattedText as g}from"./FormattedText.js";import{EditIcon as x}from"./MessageActions.js";import{asksForReview as O,withoutReviewLink as S}from"@whoa-chat/core/reviewLink";import{ReviewCard as E}from"./ReviewCard.js";const q=({message:r,time:c,onDraft:e,onEdit:f,editing:o=!1})=>{const{t:a}=k("home"),u=O(r.body),[l,w]=p(!0),s=u&&l,b=s&&S(r.body)||r.body,[i,m]=p(!1),[v,C]=p(null),h=r.draft?.state??"open",y=async n=>{if(e){m(!0),C(null);try{await e(r.id,n,n==="send"?r.body:void 0,n==="send"?{card:s}:void 0)}catch(N){C(N.message)}finally{m(!1)}}};return h!=="open"?d("div",{className:"sc-draft sc-draft--done",children:[a(h==="sent"?"supportChat.draft.sent":"supportChat.draft.discarded",{name:r.draft?.by??""}),t("time",{children:c})]}):d("div",{className:"sc-draft","aria-label":a("supportChat.draft.label"),children:[d("div",{className:"sc-draft-head",children:[t(x,{size:13}),a("supportChat.draft.title",{name:r.agentName??"Claude"}),t("time",{children:c})]}),o?t("p",{className:"sc-draft-editing",children:a("supportChat.draft.editingBelow")}):t("div",{className:"sc-draft-body",children:t(g,{text:b})}),u&&d("div",{className:"sc-draft-cardrow",children:[s&&t("div",{className:"sc-draft-peek","aria-label":a("supportChat.draft.withCard"),children:t(E,{message:{...r,kind:"review_request",body:"",review:{fixed:"",state:"sent"}},shopOwnerName:null,listing:null,preview:!0})}),d("p",{className:"sc-draft-card",children:[a(s?"supportChat.draft.linkOut":"supportChat.draft.noCard")," ",t("button",{type:"button",onClick:()=>w(!l),children:a(s?"supportChat.draft.cardOff":"supportChat.draft.cardOn")})]})]}),r.draft?.note&&d("div",{className:"sc-draft-before",children:[t("strong",{children:a("supportChat.draft.before")}),r.draft.note]}),v&&t("p",{className:"sc-draft-error",children:v}),d("div",{className:"sc-draft-actions",children:[t("button",{type:"button",className:"sc-draft-send",disabled:i||o||!b.trim()||!e,onClick:()=>{y("send")},children:a("supportChat.draft.send")}),!o&&f&&t("button",{type:"button",disabled:i,onClick:f,children:a("supportChat.draft.edit")}),t("button",{type:"button",className:"sc-draft-discard",disabled:i||!e,onClick:()=>{y("discard")},children:a("supportChat.draft.discard")})]})]})};export{q as DraftCard};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Fragment as d,jsx as s,jsxs as a}from"react/jsx-runtime";import{useState as p}from"react";import{useTranslation as b}from"./i18n.js";const g=({send:c,className:l})=>{const{t}=b("home"),[e,i]=p(!1),[r,n]=p({kind:"idle"}),u=async()=>{n({kind:"busy"});try{n({kind:"sent",to:(await c()).to})}catch(o){const h=o.message;n({kind:"error",text:/no email address/i.test(h)?t("supportChat.transcript.noEmail"):t("supportChat.transcript.failed")})}};return a("span",{className:"sc-tr",children:[s("button",{type:"button",className:l??"sc-tr-btn","aria-label":t("supportChat.transcript.button"),title:t("supportChat.transcript.button"),"aria-expanded":e,onClick:()=>{i(o=>!o),n({kind:"idle"})},children:s("svg",{viewBox:"0 0 20 20",width:"17",height:"17","aria-hidden":!0,children:s("path",{d:"M5 2.8h6.5L15 6.3v10.9H5z M11.5 2.8v3.5H15 M7.5 10h5 M7.5 13h5",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})})}),e&&a(d,{children:[s("div",{className:"sc-tr-scrim",onClick:()=>i(!1),"aria-hidden":!0}),a("div",{className:"sc-tr-pop",role:"dialog","aria-label":t("supportChat.transcript.button"),children:[s("strong",{children:t("supportChat.transcript.button")}),r.kind==="sent"?s("p",{className:"sc-tr-done",children:t("supportChat.transcript.sent",{to:r.to})}):a(d,{children:[s("p",{children:t("supportChat.transcript.about")}),r.kind==="error"&&s("p",{className:"sc-tr-err",children:r.text}),s("button",{type:"button",className:"sc-tr-send",disabled:r.kind==="busy",onClick:()=>{u()},children:t(r.kind==="busy"?"supportChat.transcript.sending":"supportChat.transcript.send")})]})]})]})]})};export{g as EmailTranscriptButton};
|