@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,2 @@
|
|
|
1
|
+
import{jsx as e,jsxs as s}from"react/jsx-runtime";import{useState as m}from"react";import{useTranslation as f}from"./i18n.js";import{AgentAvatar as h}from"./agents.js";const b={install:"good",reinstall:"good",uninstall:"bad",billing_activated:"good",review:"good",review_low:"warn",access_granted:"good",billing_cancelled:"bad",failed:"bad",widget_enable_fail:"bad",customer_portal_enable_fail:"bad",attempt:"quiet",resolved:"quiet",reopened:"quiet",ai_handover:"quiet",ai_takeback:"quiet",assigned:"quiet",widget_enable_click:"quiet",customer_portal_enable_click:"quiet",subscription_plan_create_click:"quiet",quickstart_skipped:"quiet"},M=n=>b[n]??(/uninstall|fail/.test(n)?"bad":/install|enable_success|_enabled$/.test(n)?"good":/click|attempt/.test(n)?"quiet":"info"),_={good:"M10 4v8m-4-4 4 4 4-4M5 16h10",bad:"M5 6h10M8 6V4.5h4V6m-6 0 .7 9.5h6.6L14 6",warn:"M10 4.5 17 16H3zM10 9v3m0 2v.5",fail:"M6 6l8 8M14 6l-8 8",info:"m5 10.5 3 3 7-7",quiet:"M6 10h.01M10 10h.01M14 10h.01"},k=[[/portal/,"M10 10a3 3 0 1 0 0-6 3 3 0 0 0 0 6zM4.5 16c.8-2.6 3-4 5.5-4s4.7 1.4 5.5 4"],[/widget/,"M4 4.5h12v11H4zM7 8.5h.01M9.5 8.5H13M7 11.5h.01M9.5 11.5H13"],[/offer/,"M3.5 10.2V4.5a1 1 0 0 1 1-1h5.7l6.3 6.3-6.7 6.7zM7 7h.01"]],w=(n,i)=>k.find(([o])=>o.test(n))?.[1]??_[/fail/.test(n)?"fail":i],N=/^(plan|country|name|type|installed for|setting up|rating|targeting)$/i,T=({message:n,time:i})=>{const{t:o}=f("home"),[l,g]=m(!1),a=n.event?.fields??[],d=M(n.event?.type??"other"),p=a.filter(t=>N.test(t.label)&&!t.url&&t.value.length<=40&&!t.value.includes(`
|
|
2
|
+
`)).slice(0,3),r=n.event?.type;if((r==="resolved"||r==="reopened")&&n.agentName)return s("div",{className:`sc-event-status sc-event-status--${r}`,children:[e(h,{name:n.agentName,size:22}),e("span",{children:n.body}),e("time",{children:i})]});const u=r==="assigned"?a.find(t=>t.label==="Assigned to")?.value:void 0;if(u)return s("div",{className:"sc-event-status sc-event-status--assigned",children:[e(h,{name:u,size:22}),e("span",{children:n.body}),e("time",{children:i})]});if(r==="access_granted"){const t=a.find(v=>v.url),c=a.find(v=>v.label==="Name")?.value??t?.value??"";return s("div",{className:"sc-event-access",children:[e("span",{className:"sc-event-access-icon","aria-hidden":!0,children:e("svg",{viewBox:"0 0 20 20",width:"18",height:"18",children:e("path",{d:"M12.5 3.5a4 4 0 1 1-3.9 4.9L3.5 13.5v3h3v-2h2v-2h2l.9-.9A4 4 0 0 1 12.5 3.5zM13.5 6.5h.01",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round"})})}),s("div",{className:"sc-event-access-text",children:[e("strong",{children:o("supportChat.event.accessTitle")}),c&&e("span",{children:o("supportChat.event.accessBody",{name:c})})]}),e("time",{children:i}),t?.url&&e("a",{className:"sc-event-access-open",href:t.url,target:"_blank",rel:"noopener noreferrer",children:o("supportChat.event.accessOpen")})]})}return d==="quiet"?s("div",{className:"sc-event sc-event--quiet",children:[e("span",{children:n.body}),e("time",{children:i})]}):s("div",{className:`sc-event sc-event--${d}${l?" sc-event--open":""}`,children:[s("button",{type:"button",className:"sc-event-head",onClick:()=>a.length&&g(t=>!t),"aria-expanded":a.length?l:void 0,disabled:!a.length,children:[e("span",{className:"sc-event-icon","aria-hidden":!0,children:e("svg",{viewBox:"0 0 20 20",width:"13",height:"13",children:e("path",{d:w(n.event?.type??"",d),fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round"})})}),e("span",{className:"sc-event-title",children:n.body}),p.length>0&&e("span",{className:"sc-event-summary",children:p.map(t=>t.value).join(" \xB7 ")}),e("time",{children:i}),a.length>0&&e("svg",{className:"sc-event-caret",viewBox:"0 0 20 20",width:"12",height:"12","aria-label":o(l?"supportChat.event.hide":"supportChat.event.show"),children:e("path",{d:"m6 8 4 4 4-4",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})})]}),l&&e("dl",{className:"sc-event-fields",children:a.map((t,c)=>s("div",{children:[e("dt",{children:t.label}),e("dd",{children:t.url?e("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",children:t.value.replace(/^https:\/\/(www\.)?/,"")}):t.value})]},c))})]})};export{T as EventRow};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export declare const adminPath: (url: string) => string[] | null;
|
|
3
|
+
export declare const appPage: (url: string) => {
|
|
4
|
+
path: string;
|
|
5
|
+
steps: string[];
|
|
6
|
+
app: {
|
|
7
|
+
name: string;
|
|
8
|
+
logo?: string;
|
|
9
|
+
};
|
|
10
|
+
} | null;
|
|
11
|
+
/** Whether a link shows as a badge (a page in the Shopify admin or in the app) rather than as plain words. */
|
|
12
|
+
export declare const isBadgeLink: (url: string) => boolean;
|
|
13
|
+
/** A link as the chat shows it: a badge for admin and app pages, else its label (or address) underlined.
|
|
14
|
+
* asText draws it without a working link (the composer). */
|
|
15
|
+
export declare const LinkBadge: ({ url, label, asText }: {
|
|
16
|
+
url: string;
|
|
17
|
+
label?: string;
|
|
18
|
+
asText?: boolean;
|
|
19
|
+
}) => import("react").JSX.Element;
|
|
20
|
+
export declare const CODE_LANGUAGES: readonly [{
|
|
21
|
+
readonly id: "javascript";
|
|
22
|
+
readonly label: "JavaScript";
|
|
23
|
+
readonly aliases: readonly ["js", "javascript", "jsx", "ts", "typescript"];
|
|
24
|
+
}, {
|
|
25
|
+
readonly id: "liquid";
|
|
26
|
+
readonly label: "Liquid";
|
|
27
|
+
readonly aliases: readonly ["liquid", "html", "htm", "xml", "svg"];
|
|
28
|
+
}, {
|
|
29
|
+
readonly id: "css";
|
|
30
|
+
readonly label: "CSS";
|
|
31
|
+
readonly aliases: readonly ["css", "scss"];
|
|
32
|
+
}];
|
|
33
|
+
export declare const codeLanguage: (raw: string) => "javascript" | "liquid" | "css" | null;
|
|
34
|
+
/** Our three languages, guessed from the code itself: Liquid's tags, then JavaScript's words, then CSS rules. */
|
|
35
|
+
export declare const detectLanguage: (code: string) => string | null;
|
|
36
|
+
export declare const LanguageIcon: ({ lang }: {
|
|
37
|
+
lang: string | null;
|
|
38
|
+
}) => import("react").JSX.Element | null;
|
|
39
|
+
export declare const FILE_IMG: RegExp;
|
|
40
|
+
export declare const inlineFileIds: (text?: string | null) => Set<string>;
|
|
41
|
+
export declare const FormattedText: ({ text, inline, image }: {
|
|
42
|
+
text: string;
|
|
43
|
+
inline?: (s: string, key: string) => ReactNode;
|
|
44
|
+
image?: (id: string, name: string, key: string) => ReactNode;
|
|
45
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{Fragment as k,jsx as i,jsxs as g}from"react/jsx-runtime";import{Fragment as $,useState as L}from"react";import{highlightCode as P}from"./highlight.js";import{useChatEnv as D,useLinkNames as q,useOpened as z}from"./chatEnv.js";import{chatHost as x}from"./host.js";import{MD_LINK as G}from"@whoa-chat/core/links";const C=/^\s*[-*•]\s+/,S=/^\s*\d{1,3}[.)]\s+/,U=/(https?:\/\/[^\s<>"']+[^\s<>"'.,;:!?)\]])/g,H=/(`[^`\n]+`)/g,K=/(\*\*[^*\n]+\*\*)/g,W=/```[^\S\n]*([\w+#.-]*)[^\S\n]*\n?([\s\S]*?)(?:```|$)/g,j=/^https:\/\/admin\.shopify\.com\/(?:store\/[^/]+\/?)?(.*)$/,h=e=>e.replace(/[-_]+/g," ").replace(/\b\w/g,t=>t.toUpperCase()),N=e=>{const t=j.exec(e);if(!t)return null;const[n,o=""]=t[1].split("?"),s=new URLSearchParams(o),r=n.split("/").filter(Boolean),[a,l,c]=r;if(!a)return["Home"];if(a==="themes")return r.includes("editor")?["Online Store","Themes","Customize",...s.get("context")==="apps"||s.has("appEmbed")?["App embeds"]:[]]:["Online Store","Themes"];if(a==="apps"){const u=r.slice(r.indexOf("app")+1).filter(d=>!/^[0-9a-f]{24}$|^\d+$/.test(d));return["Apps",x().brand.app,...u.slice(0,2).map(h)]}if(a==="settings")return["Settings",...l?[h(l)]:[],...c&&!/^\d+$/.test(c)?[h(c)]:[]];if(a==="online_store")return["Online Store",...l?[h(l)]:[]];const p={products:"Products",orders:"Orders",customers:"Customers",collections:"Collections",discounts:"Discounts",markets:"Markets",menus:"Online Store",pages:"Online Store",content:"Content"},m={products:"This product",orders:"This order",customers:"This customer",collections:"This collection",discounts:"This discount"};return p[a]?[p[a],...l&&!/^\d+$/.test(l)?[h(l)]:l?[m[a]??"Open"]:[]]:null},J=/^https:\/\/admin\.shopify\.com\/(?:store\/[^/]+\/)?apps\/([^/?#]+)(\/app(?:\/[^?#]*)?)(\?[^#]*)?/,A=/^[0-9a-f]{24}$|^\d+$/,b=e=>{const t=J.exec(e);if(!t)return null;const n=x().appLinks??[],o=n.find(d=>d.handle===t[1]),s=x().brand,r=o??(n.length<=1&&(!n.length||n[0].handle===t[1])?{name:s.app,logo:s.logo,pages:[]}:{name:h(t[1]),pages:[]}),a=`${t[2]}${t[3]??""}`,l=t[2].split("/").filter(Boolean).slice(1),c=l.filter(d=>!A.test(d)),p=c.length?r.pages.find(d=>d.segment===c[0].toLowerCase()):void 0,m=c.length?[p?.name??h(c[0]),...c.slice(1,2).map(h)]:["Home"];c.length===1&&l.length>1&&A.test(l[1])&&p?.item&&m.push(p.item.replace("{id}",l[1]));const u=new URLSearchParams(t[3]??"").get("highlight");return u&&m.push(...u.split(".").map(h)),{path:a,steps:m.slice(0,4),app:{name:r.name,logo:"logo"in r?r.logo:void 0}}},R=({url:e,page:t,label:n,asText:o})=>{const s=D(),r=n?[n]:t.steps,a=g(k,{children:[t.app.logo?i("img",{src:t.app.logo,alt:t.app.name,width:13,height:13}):null,r.map((l,c)=>g($,{children:[c>0&&i("i",{"aria-hidden":!0,children:"\u203A"}),i("span",{className:c===r.length-1?"sc-app-last":void 0,children:l})]},c))]});return o?i("span",{className:"sc-app-link",title:e,children:a}):i(k,{children:g("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"sc-app-link",title:e,onClick:l=>{s?.open&&(l.preventDefault(),s.open(t.path))},children:[a,i(y,{url:e,inBadge:!0})]})})},y=({url:e,inBadge:t})=>{const n=z(e);return n?i("span",{className:t?"sc-opened-mark sc-opened-mark--in":"sc-opened-mark",title:n,"aria-label":n,role:"img",children:i("svg",{viewBox:"0 0 16 16",width:"12",height:"12","aria-hidden":!0,children:i("path",{d:"M3.5 8.5l3 3 6-7",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}):null},T=({url:e,label:t})=>g(k,{children:[i("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"sc-link",title:e,children:t||e}),i(y,{url:e})]}),Q=/^https:\/\/admin\.shopify\.com\/(?:store\/[^/]+\/)?(products|orders)\/(\d+)/,I=({url:e,path:t,label:n,asText:o})=>{const s=Q.exec(e),r=q()?.[s?`${s[1]}/${s[2]}`:""],a=n?[n]:r?[t[0],r]:t,l=g(k,{children:[i("img",{src:"/support/shopify.svg",alt:"Shopify",width:13,height:13}),a.slice(0,-1).map((c,p)=>g("span",{className:"sc-admin-step",children:[c,i("i",{"aria-hidden":!0,children:"\u203A"})]},p)),i("u",{children:a[a.length-1]})]});return o?i("span",{className:"sc-admin-link",title:e,children:l}):i(k,{children:g("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"sc-admin-link",title:e,children:[l,i(y,{url:e,inBadge:!0})]})})},ct=e=>!!(b(e)||N(e)),V=({url:e,label:t,asText:n})=>{const o=b(e);if(o)return i(R,{url:e,page:o,label:t,asText:n});const s=N(e);return s?i(I,{url:e,path:s,label:t,asText:n}):n?i("span",{className:"sc-link",title:e,children:t||e}):i(T,{url:e,label:t})},B=(e,t,n)=>{const o=[];let s=0,r=0;for(const a of e.matchAll(G))o.push(...E(e.slice(s,a.index),t,`${n}-m${r}`)),o.push(i(V,{url:a[2],label:a[1]},`${n}-l${r}`)),s=a.index+a[0].length,r++;return o.push(...E(e.slice(s),t,`${n}-m${r}`)),o},E=(e,t,n)=>e.split(U).map((o,s)=>s%2===1&&b(o)?i(R,{url:o,page:b(o)},`${n}-${s}`):s%2===1&&N(o)?i(I,{url:o,path:N(o)},`${n}-${s}`):s%2===1?i(T,{url:o},`${n}-${s}`):i($,{children:t(o,`${n}-${s}`)},`${n}-${s}`)),X=({code:e})=>{const[t,n]=L(!1),o=()=>{navigator.clipboard?.writeText(e).then(()=>{n(!0),window.setTimeout(()=>n(!1),1400)})};return i("code",{className:"sc-icode sc-icode--copy",role:"button",tabIndex:0,"data-tip":t?"Copied":"Copy","aria-label":`${e}, ${t?"copied":"copy"}`,onClick:s=>{s.stopPropagation(),o()},onKeyDown:s=>{s.key!=="Enter"&&s.key!==" "||(s.preventDefault(),s.stopPropagation(),o())},children:e})},Y=/!\[[^\]\n]*\]\((https:\/\/media\d*\.giphy\.com\/media\/[^\s)<>"']+\.gif)\)/g,Z=(e,t,n)=>e.split(K).map((o,s)=>s%2===1?i("strong",{children:B(o.slice(2,-2),t,`${n}-b${s}`)},`${n}-b${s}`):i($,{children:B(o,t,`${n}-t${s}`)},`${n}-t${s}`)),F=(e,t,n)=>e.split(H).map((o,s)=>s%2===1?i(X,{code:o.slice(1,-1)},`${n}-c${s}`):i($,{children:o.split(Y).map((r,a)=>a%2===1?i("img",{className:"sc-md-gif",src:r,alt:"GIF",loading:"lazy",referrerPolicy:"no-referrer"},`${n}-g${a}`):i($,{children:Z(r,t,`${n}-g${a}`)},`${n}-g${a}`))},`${n}-c${s}`)),O=[{id:"javascript",label:"JavaScript",aliases:["js","javascript","jsx","ts","typescript"]},{id:"liquid",label:"Liquid",aliases:["liquid","html","htm","xml","svg"]},{id:"css",label:"CSS",aliases:["css","scss"]}],w=e=>O.find(t=>t.aliases.includes(e.toLowerCase()))?.id??null,tt=e=>O.find(t=>t.id===w(e))?.label??(e||"Code"),v=e=>{const t=e.trim();return t?/\{%-?\s*\w|\{\{-?\s*[\w'"]/.test(t)||/<\/?[a-z][\w-]*(\s[^<>]*)?\/?>/i.test(t)?"liquid":/\b(const|let|var|function|return|document\.|window\.|console\.|addEventListener|querySelector|async|await)\b|=>/.test(t)?"javascript":/[^{}]+\{[^{}]*[\w-]+\s*:\s*[^;{}]+;?[^{}]*\}/.test(t)||/^\s*[\w-]+\s*:\s*[^;{}]+;\s*$/m.test(t)||/@media|!important/.test(t)?"css":null:null},et=({lang:e})=>{const t=e?w(e):null;return t==="javascript"?g("svg",{className:"sc-lang-icon",viewBox:"0 0 16 16",width:"14",height:"14","aria-hidden":!0,children:[i("rect",{width:"16",height:"16",rx:"3",fill:"#f7df1e"}),i("text",{x:"14.2",y:"13.6",textAnchor:"end",fontFamily:"Arial, sans-serif",fontWeight:"700",fontSize:"7.6",fill:"#1b1b1b",children:"JS"})]}):t==="css"?g("svg",{className:"sc-lang-icon",viewBox:"0 0 16 16",width:"14",height:"14","aria-hidden":!0,children:[i("rect",{width:"16",height:"16",rx:"3",fill:"#2965f1"}),i("text",{x:"8",y:"11",textAnchor:"middle",fontFamily:"Arial, sans-serif",fontWeight:"700",fontSize:"5.6",fill:"#fff",children:"CSS"})]}):t==="liquid"?g("svg",{className:"sc-lang-icon",viewBox:"0 0 16 16",width:"14",height:"14","aria-hidden":!0,children:[i("path",{d:"M8 1.2C8 1.2 3 7 3 10.1A5 5 0 0 0 13 10.1C13 7 8 1.2 8 1.2z",fill:"#38bdf8"}),i("path",{d:"M6 10.6a2 2 0 0 0 2 2",fill:"none",stroke:"#fff",strokeWidth:"1.3",strokeLinecap:"round"})]}):null},st=({code:e,lang:t})=>{const[n,o]=L(!1),s=()=>navigator.clipboard?.writeText(e).then(()=>{o(!0),window.setTimeout(()=>o(!1),1500)},()=>{});return g("div",{className:"sc-code",children:[g("div",{className:"sc-code-bar",children:[g("span",{className:"sc-code-lang",children:[i(et,{lang:t||v(e)}),tt(t||v(e)||"")]}),i("button",{type:"button",onClick:s,children:n?"Copied":"Copy"})]}),i("pre",{children:(()=>{const r=P(e,w(t)??(t?null:v(e)));return r?i("code",{className:"sc-hl-code",dangerouslySetInnerHTML:{__html:r}}):i("code",{children:e})})()})]})},nt=e=>{const t=[];for(const n of e.split(`
|
|
2
|
+
`)){const o=C.test(n)?"ul":S.test(n)?"ol":"p",s=t[t.length-1];s&&s.kind===o?s.lines.push(n):t.push({kind:o,lines:[n]})}return t},_=(e,t,n)=>e.replace(/[ \t]+\n/g,`
|
|
3
|
+
`).replace(/^\n+|\n+$/g,"").split(/\n{2,}/).filter(o=>o.trim()).flatMap((o,s)=>nt(o).map((r,a)=>{const l=`${n}-${s}-${a}`;if(r.kind==="p")return i("p",{children:F(r.lines.join(`
|
|
4
|
+
`),t,l)},l);const c=r.kind,p=r.kind==="ol"?Number(/\d+/.exec(r.lines[0])?.[0]??1):void 0;return i(c,{start:p!==1?p:void 0,children:r.lines.map((m,u)=>i("li",{children:F(m.replace(r.kind==="ul"?C:S,""),t,`${l}-${u}`)},u))},l)})),M=/!\[([^\]\n]*)\]\(file:([^)\s]+)\)/g,pt=e=>new Set([...(e??"").matchAll(M)].map(t=>t[2])),dt=({text:e,inline:t=o=>o,image:n})=>{const o=e.replace(/\r\n?/g,`
|
|
5
|
+
`).trim(),s=[];let r=0,a=0;const l=(c,p)=>{const m=[];let u=0,d=0;for(const f of c.matchAll(M))m.push(..._(c.slice(u,f.index),t,`${p}i${d}`)),m.push(n?i("div",{className:"sc-inline-img",children:n(f[2],f[1],`${p}img${d}`)},`${p}img${d}`):g("p",{className:"sc-inline-img-name",children:["[",f[1]||"image","]"]},`${p}img${d}`)),u=f.index+f[0].length,d++;return m.push(..._(c.slice(u),t,`${p}i${d}`)),m};for(const c of o.matchAll(W)){s.push(...l(o.slice(r,c.index),`t${a}`));const p=c[2].replace(/\n$/,"");p.trim()&&s.push(i(st,{code:p,lang:c[1]},`code${a}`)),r=c.index+c[0].length,a++}return s.push(...l(o.slice(r),`t${a}`)),i("div",{className:"sc-text",children:s})};export{O as CODE_LANGUAGES,M as FILE_IMG,dt as FormattedText,et as LanguageIcon,V as LinkBadge,N as adminPath,b as appPage,w as codeLanguage,v as detectLanguage,pt as inlineFileIds,ct as isBadgeLink};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SupportMessageView } from "@whoa-chat/core/types";
|
|
2
|
+
export declare const VerifiedIcon: ({ size, check }: {
|
|
3
|
+
size?: number;
|
|
4
|
+
check?: string;
|
|
5
|
+
}) => import("react").JSX.Element;
|
|
6
|
+
export declare const HelpOfferCard: ({ message, answered, onAnswer }: {
|
|
7
|
+
message: SupportMessageView;
|
|
8
|
+
answered: boolean;
|
|
9
|
+
onAnswer?: (text: string) => void;
|
|
10
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as e,jsxs as a}from"react/jsx-runtime";import{useTranslation as n}from"./i18n.js";import{AgentAvatar as i}from"./agents.js";import{brandVars as d}from"./host.js";const h=({size:o=16,check:s="#fff"})=>a("svg",{viewBox:"0 0 24 24",width:o,height:o,"aria-hidden":!0,children:[e("path",{d:"M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z",fill:"currentColor"}),e("path",{d:"m9 12 2 2 4-4",fill:"none",stroke:s,strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round"})]}),f=({message:o,answered:s,onAnswer:r})=>{const{t}=n("home"),p=o.agentName??"Stefan";return a("article",{className:"ho-card","aria-label":t("supportChat.helpOffer.label"),children:[a("header",{className:"ho-head",children:[e(i,{name:p,size:30}),a("div",{children:[e("strong",{children:p}),e("span",{children:t("supportChat.preview.fromTeam",d())})]})]}),e("p",{className:"ho-body",children:o.body}),a("div",{className:"ho-perk",children:[e(h,{size:17}),t("supportChat.preview.helpPerks")]}),!s&&a("div",{className:"ho-actions",children:[e("button",{type:"button",className:"mp-btn mp-btn--brand","data-card-action":"help_yes",disabled:!r,onClick:()=>r?.(t("supportChat.helpOffer.yesMessage")),children:t("supportChat.helpOffer.yes")}),e("button",{type:"button",className:"mp-btn mp-btn--plain","data-card-action":"help_no",disabled:!r,onClick:()=>r?.(t("supportChat.helpOffer.noMessage")),children:t("supportChat.helpOffer.no")})]})]})};export{f as HelpOfferCard,h as VerifiedIcon};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { ShortcutCard } from "@whoa-chat/core/types";
|
|
2
|
+
export type Reminder = {
|
|
3
|
+
id: string;
|
|
4
|
+
at: string;
|
|
5
|
+
note: string;
|
|
6
|
+
by: string;
|
|
7
|
+
};
|
|
8
|
+
/** The instant a wall-clock time in a time zone falls on (two passes cover a DST change). */
|
|
9
|
+
export declare const zonedTime: (y: number, mo: number, d: number, h: number, mi: number, timeZone?: string | null) => Date;
|
|
10
|
+
export declare const formatWhen: (iso: string, lang?: string) => string;
|
|
11
|
+
export declare const ReminderControl: ({ reminders, error, busy, onAdd, onRemove, open: openProp, onOpenChange, hideButton, timeZone, }: {
|
|
12
|
+
timeZone?: string | null;
|
|
13
|
+
reminders: Reminder[];
|
|
14
|
+
error?: string;
|
|
15
|
+
busy?: boolean;
|
|
16
|
+
onAdd: (at: string, note: string) => void;
|
|
17
|
+
onRemove: (id: string) => void;
|
|
18
|
+
open?: boolean;
|
|
19
|
+
onOpenChange?: (open: boolean) => void;
|
|
20
|
+
hideButton?: boolean;
|
|
21
|
+
}) => import("react").JSX.Element;
|
|
22
|
+
type Shortcut = {
|
|
23
|
+
id: string;
|
|
24
|
+
key: string;
|
|
25
|
+
title: string;
|
|
26
|
+
body: string;
|
|
27
|
+
card?: ShortcutCard;
|
|
28
|
+
apps?: string[];
|
|
29
|
+
};
|
|
30
|
+
type Draft = {
|
|
31
|
+
id?: string;
|
|
32
|
+
key: string;
|
|
33
|
+
title: string;
|
|
34
|
+
body: string;
|
|
35
|
+
card?: ShortcutCard;
|
|
36
|
+
apps?: string[];
|
|
37
|
+
};
|
|
38
|
+
export declare const ShortcutsPanel: ({ shortcuts, error, onSave, onDelete, onClose, inline, apps, newFor, }: {
|
|
39
|
+
shortcuts: Shortcut[];
|
|
40
|
+
error?: string;
|
|
41
|
+
onSave: (s: Draft) => void;
|
|
42
|
+
onDelete: (id: string) => void;
|
|
43
|
+
onClose: () => void;
|
|
44
|
+
inline?: boolean;
|
|
45
|
+
/** The workspace's apps ("-" the first app's key); with two or more, a saved reply can be for some of them. */
|
|
46
|
+
apps?: {
|
|
47
|
+
key: string;
|
|
48
|
+
name: string;
|
|
49
|
+
}[];
|
|
50
|
+
/** A new saved reply starts as this app's (Settings with one app picked). */
|
|
51
|
+
newFor?: string;
|
|
52
|
+
}) => import("react").JSX.Element;
|
|
53
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Fragment as K,jsx as t,jsxs as l}from"react/jsx-runtime";import{useEffect as J,useRef as Q,useState as b}from"react";import{useTranslation as P}from"./i18n.js";import{chatHost as W}from"./host.js";import{timeOpts as v}from"./clock.js";const V=()=>l("svg",{viewBox:"0 0 20 20",width:"15",height:"15","aria-hidden":!0,children:[t("circle",{cx:"10",cy:"10.5",r:"6.5",fill:"none",stroke:"currentColor",strokeWidth:"1.7"}),t("path",{d:"M10 7v3.7l2.4 1.5M7 2.8l-2.2 1.7M13 2.8l2.2 1.7",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round"})]}),M=[{key:"tomorrow",days:1},{key:"in3Days",days:3},{key:"in1Week",days:7},{key:"in2Weeks",days:14},{key:"in1Month",months:1},{key:"in3Months",months:3}],B=s=>{const c=new Date(s);return c.setHours(0,0,0,0),c},X=(s,c=new Date)=>{const u=B(c);return s.days&&u.setDate(u.getDate()+s.days),s.months&&u.setMonth(u.getMonth()+s.months),u},_=(s,c)=>s.toDateString()===c.toDateString(),$=[{key:"morning",hour:9},{key:"afternoon",hour:13},{key:"evening",hour:18},{key:"night",hour:21}],Z=s=>{if(!s)return new Date;try{const[c,u,p]=new Intl.DateTimeFormat("en-CA",{timeZone:s,year:"numeric",month:"2-digit",day:"2-digit"}).format(new Date).split("-").map(Number);return new Date(c,u-1,p)}catch{return new Date}},tt=(s,c,u,p,m,h)=>{if(!h)return new Date(s,c,u,p,m);const g=Date.UTC(s,c,u,p,m);let d=g;try{const o=new Intl.DateTimeFormat("en-US",{timeZone:h,hourCycle:"h23",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"});for(let a=0;a<2;a++){const r=Object.fromEntries(o.formatToParts(new Date(d)).map(y=>[y.type,y.value]));d+=g-Date.UTC(Number(r.year),Number(r.month)-1,Number(r.day),Number(r.hour)%24,Number(r.minute))}}catch{return new Date(s,c,u,p,m)}return new Date(d)},et=({value:s,onPick:c,lang:u})=>{const p=B(new Date),[m,h]=b(()=>{const e=new Date(s??p);return e.setDate(1),e}),d=(new Date(m).getDay()+6)%7,o=new Date(m.getFullYear(),m.getMonth()+1,0).getDate(),a=[...Array.from({length:d},()=>null),...Array.from({length:o},(e,i)=>new Date(m.getFullYear(),m.getMonth(),i+1))],r=e=>h(i=>new Date(i.getFullYear(),i.getMonth()+e,1)),y=Array.from({length:7},(e,i)=>new Date(2024,0,1+i).toLocaleDateString(u,{weekday:"narrow"}));return l("div",{className:"rm-cal",children:[l("div",{className:"rm-cal-head",children:[t("button",{type:"button","aria-label":"Previous month",disabled:m<=new Date(p.getFullYear(),p.getMonth(),1),onClick:()=>r(-1),children:"\u2039"}),t("strong",{children:m.toLocaleDateString(u,{month:"long",year:"numeric"})}),t("button",{type:"button","aria-label":"Next month",onClick:()=>r(1),children:"\u203A"})]}),l("div",{className:"rm-cal-grid",children:[y.map((e,i)=>t("span",{className:"rm-cal-wd",children:e},`w${i}`)),a.map((e,i)=>e?t("button",{type:"button",disabled:e<p,"aria-pressed":!!(s&&_(s,e)),className:_(e,p)?"rm-cal-today":void 0,onClick:()=>c(e),children:e.getDate()},i):t("span",{},i))]})]})},Y=(s,c)=>{const u=new Date(s);return new Date().toDateString()===u.toDateString()?u.toLocaleTimeString(c,v()):u.toLocaleString(c,v({weekday:"short"}))},lt=({reminders:s,error:c,busy:u,onAdd:p,onRemove:m,open:h,onOpenChange:g,hideButton:d,timeZone:o})=>{const{t:a,i18n:r}=P("home"),[y,e]=b(!1),i=h??y,C=n=>{const S=typeof n=="function"?n(i):n;e(S),g?.(S)},[f,T]=b(""),[N,F]=b("tomorrow"),[O,A]=b(null),[D,H]=b("morning"),[R,U]=b("09:00"),L=Q(null);J(()=>{if(!i)return;const n=S=>L.current&&!L.current.contains(S.target)&&C(!1);return document.addEventListener("mousedown",n),()=>document.removeEventListener("mousedown",n)},[i]);const w=N==="custom"?O:X(M.find(n=>n.key===N)??M[0],Z(o)),[E,z]=D==="custom"?R.split(":").map(Number):[$.find(n=>n.key===D)?.hour??9,0],k=w&&Number.isFinite(E)?tt(w.getFullYear(),w.getMonth(),w.getDate(),E,z||0,o):null,j=Intl.DateTimeFormat().resolvedOptions().timeZone,q=!!(o&&o!==j),x=k&&k.getTime()>Date.now()?k.toISOString():null,G=()=>{!f.trim()||!x||(p(x,f.trim()),T(""),F("tomorrow"),A(null))},I=s[0];return l("div",{className:"rm-wrap",ref:L,children:[!d&&l("button",{type:"button",className:`ibx-pill rm-button${s.length?" rm-button--set":""}`,"aria-expanded":i,onClick:()=>C(n=>!n),children:[t(V,{}),I?Y(I.at,r.language):a("supportChat.reminders.remindMe"),s.length>1&&t("span",{className:"rm-count",children:s.length})]}),i&&l("div",{className:"rm-pop",role:"dialog","aria-label":a("supportChat.reminders.title"),children:[t("strong",{children:a("supportChat.reminders.title")}),s.length>0&&t("ul",{className:"rm-list",children:s.map(n=>l("li",{children:[t("span",{className:"rm-when",children:Y(n.at,r.language)}),l("span",{className:"rm-text",children:[t("span",{children:n.note}),t("em",{children:n.by})]}),t("button",{type:"button","aria-label":a("supportChat.reminders.clear"),onClick:()=>m(n.id),children:t("svg",{viewBox:"0 0 20 20",width:"10",height:"10","aria-hidden":!0,children:t("path",{d:"M5 5l10 10M15 5L5 15",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round"})})})]},n.id))}),t("textarea",{className:"rm-note",rows:2,autoFocus:!0,value:f,maxLength:300,placeholder:a("supportChat.reminders.notePlaceholder"),onChange:n=>T(n.target.value)}),t("div",{className:"rm-spans",role:"group","aria-label":a("supportChat.reminders.day"),children:[...M.map(n=>n.key),"custom"].map(n=>t("button",{type:"button","aria-pressed":N===n,onClick:()=>F(n),children:a(`supportChat.reminders.${n}`)},n))}),N==="custom"&&t(et,{value:O,onPick:A,lang:r.language}),t("div",{className:"rm-time rm-time--slots",role:"group","aria-label":a("supportChat.reminders.time"),children:[...$.map(n=>n.key),"custom"].map(n=>t("button",{type:"button","aria-pressed":D===n,onClick:()=>H(n),children:a(n==="custom"?"supportChat.reminders.customTime":`supportChat.reminders.${n}`)},n))}),D==="custom"&&t("input",{className:"rm-clock",type:"time",value:R,onChange:n=>U(n.target.value),"aria-label":a("supportChat.reminders.customTime")}),t("em",{className:"rm-summary",children:k?x?q?a("supportChat.reminders.theirTime",{time:k.toLocaleString(r.language,v({weekday:"long",day:"numeric",month:"long",timeZone:o})),zone:o.split("/").pop().replace(/_/g," "),yours:k.toLocaleString(r.language,v({weekday:"short"}))}):k.toLocaleString(r.language,v({weekday:"long",day:"numeric",month:"long"})):a("supportChat.reminders.past"):a("supportChat.reminders.pickDay")}),c&&t("p",{className:"ibx-error",children:c}),t("button",{type:"button",className:"mp-btn mp-btn--dark rm-set",disabled:!f.trim()||!x||u,onClick:G,children:a("supportChat.reminders.set")})]})]})},at=["review","help_offer","password","link","pricing"],it=({shortcuts:s,error:c,onSave:u,onDelete:p,onClose:m,inline:h,apps:g=[],newFor:d})=>{const{t:o}=P("home"),[a,r]=b(null);return(e=>h?t("section",{className:"sp-panel sp-panel--inline","aria-label":o("supportChat.shortcuts.title"),children:e}):t("div",{className:"sp-backdrop",onMouseDown:i=>i.target===i.currentTarget&&m(),children:t("section",{className:"sp-panel",role:"dialog","aria-label":o("supportChat.shortcuts.title"),children:e})}))(l(K,{children:[l("header",{className:"sp-head",children:[t("strong",{children:o("supportChat.shortcuts.title")}),t("span",{children:o("supportChat.shortcuts.hint")}),!h&&t("button",{type:"button",className:"mp-close","aria-label":o("supportChat.shortcuts.close"),onClick:m,children:t("svg",{viewBox:"0 0 20 20",width:"12",height:"12","aria-hidden":!0,children:t("path",{d:"M5 5l10 10M15 5L5 15",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})})]}),a?l("div",{className:"sp-form",children:[l("label",{className:"sci-field",children:[o("supportChat.shortcuts.key"),t("input",{value:a.key,maxLength:24,placeholder:"embed",onChange:e=>r({...a,key:e.target.value})})]}),l("label",{className:"sci-field",children:[o("supportChat.shortcuts.name"),t("input",{value:a.title,maxLength:60,onChange:e=>r({...a,title:e.target.value})})]}),l("label",{className:"sci-field",children:[o("supportChat.shortcuts.text"),t("textarea",{rows:5,value:a.body,maxLength:2e3,onChange:e=>r({...a,body:e.target.value})})]}),t("p",{className:"ibx-tip",children:o("supportChat.shortcuts.variables")}),l("label",{className:"sci-field",children:[o("supportChat.shortcuts.card"),l("select",{value:a.card?.kind??"",onChange:e=>{const i=e.target.value;r({...a,card:i?{kind:i,...i==="link"?{linkKey:W().deepLinkOptions()[0]?.key}:{}}:void 0})},children:[t("option",{value:"",children:o("supportChat.shortcuts.noCard")}),at.map(e=>t("option",{value:e,children:o(`supportChat.inbox.tabs.${e}`)},e))]})]}),g.length>1&&l("fieldset",{className:"sci-field sci-apps",children:[t("legend",{children:o("supportChat.shortcuts.apps")}),g.map(e=>l("label",{className:"sci-app",children:[t("input",{type:"checkbox",checked:(a.apps??[]).includes(e.key),onChange:i=>{const C=new Set(a.apps??[]);i.target.checked?C.add(e.key):C.delete(e.key),r({...a,apps:[...C]})}}),e.name]},e.key)),t("small",{children:o("supportChat.shortcuts.allApps")})]}),a.card?.kind==="review"&&l("label",{className:"sci-field",children:[o("supportChat.shortcuts.cardFixed"),t("input",{value:a.card.fixed??"",maxLength:300,onChange:e=>r({...a,card:{...a.card,fixed:e.target.value}})})]}),(a.card?.kind==="help_offer"||a.card?.kind==="password")&&l("label",{className:"sci-field",children:[o("supportChat.shortcuts.cardMessage"),t("textarea",{rows:3,value:a.card.body??"",maxLength:400,onChange:e=>r({...a,card:{...a.card,body:e.target.value}})})]}),a.card?.kind==="link"&&l("label",{className:"sci-field",children:[o("supportChat.shortcuts.cardLink"),t("select",{value:a.card.linkKey??"",onChange:e=>r({...a,card:{...a.card,linkKey:e.target.value}}),children:W().deepLinkOptions().map(e=>t("option",{value:e.key,children:e.label},e.key))})]}),c&&t("p",{className:"ibx-error",children:c}),l("div",{className:"ho-actions",children:[t("button",{type:"button",className:"mp-btn mp-btn--plain",onClick:()=>r(null),children:o("supportChat.shortcuts.cancel")}),t("button",{type:"button",className:"mp-btn mp-btn--dark",onClick:()=>{u(a),r(null)},children:o("supportChat.shortcuts.save")})]})]}):l(K,{children:[t("ul",{className:"sp-list",children:s.map(e=>l("li",{children:[l("span",{className:"sc-shortcut-key",children:["!",e.key]}),l("span",{className:"sc-shortcut-text",children:[l("strong",{children:[e.title,e.card&&t("em",{className:"sc-shortcut-card",children:o(`supportChat.inbox.tabs.${e.card.kind}`)})]}),t("span",{children:e.body})]}),t("button",{type:"button",className:"ibx-link",onClick:()=>r(e),children:o("supportChat.shortcuts.edit")}),t("button",{type:"button",className:"ibx-link",onClick:()=>p(e.id),children:o("supportChat.shortcuts.remove")})]},e.id))}),c&&t("p",{className:"ibx-error",children:c}),t("button",{type:"button",className:"mp-btn mp-btn--dark sp-add",onClick:()=>r({key:"",title:"",body:"",...d?{apps:[d]}:{}}),children:o("supportChat.shortcuts.add")})]})]}))};export{lt as ReminderControl,it as ShortcutsPanel,Y as formatWhen,tt as zonedTime};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MerchantInfo } from "@whoa-chat/core/types";
|
|
2
|
+
import { type StoreLook } from "./StoreAvatar";
|
|
3
|
+
export declare const MerchantPanel: ({ info, look, supportUrl, linksInHeader, onSaveEmail, onMarkReview }: {
|
|
4
|
+
info: MerchantInfo;
|
|
5
|
+
look?: StoreLook | null;
|
|
6
|
+
supportUrl?: string;
|
|
7
|
+
linksInHeader?: boolean;
|
|
8
|
+
onSaveEmail?: (email: string) => void;
|
|
9
|
+
onMarkReview?: (rating: number, body: string) => Promise<unknown>;
|
|
10
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Fragment as z,jsx as t,jsxs as n}from"react/jsx-runtime";import{useEffect as R,useState as c}from"react";import{useTranslation as A}from"./i18n.js";import{StoreAvatar as S}from"./StoreAvatar.js";import{EditIcon as I}from"./MessageActions.js";import{timeOpts as L}from"./clock.js";const T=e=>e&&/^[A-Z]{2}$/.test(e)?String.fromCodePoint(...[...e].map(o=>127462+o.charCodeAt(0)-65)):"",E=()=>{const[e,o]=c(()=>Date.now());return R(()=>{const l=window.setInterval(()=>o(Date.now()),3e4);return()=>window.clearInterval(l)},[]),e},x=({text:e})=>{const{t:o}=A("home"),[l,p]=c(!1);return t("button",{type:"button",className:"mi-copy","aria-label":o("supportChat.merchant.copy"),onClick:()=>{navigator.clipboard?.writeText(e),p(!0),window.setTimeout(()=>p(!1),1500)},children:l?t("svg",{viewBox:"0 0 20 20",width:"13",height:"13","aria-hidden":!0,children:t("path",{d:"M5 10.5l3.2 3.2L15 7",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round"})}):n("svg",{viewBox:"0 0 20 20",width:"13",height:"13","aria-hidden":!0,children:[t("rect",{x:"6.5",y:"6.5",width:"9",height:"9",rx:"2",fill:"none",stroke:"currentColor",strokeWidth:"1.6"}),t("path",{d:"M13.5 6.5V5a1.5 1.5 0 0 0-1.5-1.5H5A1.5 1.5 0 0 0 3.5 5v7A1.5 1.5 0 0 0 5 13.5h1.5",fill:"none",stroke:"currentColor",strokeWidth:"1.6"})]})})},V=({info:e,look:o,supportUrl:l,linksInHeader:p=!1,onSaveEmail:m,onMarkReview:h})=>{const{t:a,i18n:b}=A("home"),[g,d]=c(null),[s,i]=c(null),w=E(),D=e.timezone?new Date(w).toLocaleTimeString(b.language,L({timeZone:e.timezone,weekday:"short"})):null,v=e.timezone?Number(new Intl.DateTimeFormat("en-GB",{timeZone:e.timezone,hour:"2-digit"}).format(new Date(w))):null,k=v!==null&&(v>=22||v<7),y=[e.city,e.region,e.country].filter(Boolean).join(", "),N=e.firstInstallAt?new Date(e.firstInstallAt).toLocaleDateString(b.language,{day:"numeric",month:"short",year:"numeric"}):null;return n("aside",{className:"mi-panel","aria-label":a("supportChat.merchant.title"),children:[n("div",{className:"mi-hero",children:[t(S,{shop:e.shop,name:e.name??e.shop,look:{favicon:o?.favicon??e.logo??null,development:e.development,reviewed:!!e.reviewed,rating:e.reviewed?.rating??null,locked:e.passwordProtected??null,paying:!!e.paying},size:44}),n("div",{children:[t("strong",{children:e.name??e.shop}),e.owner&&t("span",{children:e.owner})]})]}),n("dl",{className:"mi-facts",children:[n("div",{children:[t("dt",{children:a("supportChat.merchant.domain")}),n("dd",{className:"mi-mono",children:[t("span",{children:e.shop}),t(x,{text:e.shop})]})]}),n("div",{children:[t("dt",{children:a("supportChat.merchant.location")}),t("dd",{children:y?n(z,{children:[t("span",{className:"mi-flag","aria-hidden":!0,children:T(e.countryCode)}),y]}):t("span",{className:"mi-muted",children:a("supportChat.merchant.unknown")})})]}),n("div",{children:[t("dt",{children:a("supportChat.merchant.timezone")}),t("dd",{children:e.timezone?n("span",{className:"mi-time",children:[t("b",{className:k?"mi-night":"mi-day",children:D}),t("span",{children:e.timezone.replace(/_/g," ")}),k&&t("em",{children:a("supportChat.merchant.night")})]}):t("span",{className:"mi-muted",children:a("supportChat.merchant.unknown")})})]}),n("div",{children:[t("dt",{children:a("supportChat.merchant.plan")}),n("dd",{children:[e.plan??t("span",{className:"mi-muted",children:a("supportChat.merchant.unknown")}),e.plus&&t("span",{className:"mi-tag mi-tag--plus",children:"Plus"}),e.development&&t("span",{className:"mi-tag",children:a("supportChat.merchant.dev")})]})]}),n("div",{children:[t("dt",{children:a("supportChat.merchant.app")}),t("dd",{children:e.installed?N?a("supportChat.merchant.since",{date:N}):a("supportChat.merchant.installed"):t("span",{className:"mi-tag mi-tag--gone",children:a("supportChat.merchant.uninstalled")})})]}),e.foundVia&&n("div",{children:[t("dt",{children:a("supportChat.merchant.foundVia")}),t("dd",{children:e.foundVia})]}),e.uninstallReason&&n("div",{children:[t("dt",{children:a("supportChat.merchant.uninstallReason")}),n("dd",{className:"mi-left",children:[e.uninstallReason.reason&&t("strong",{children:e.uninstallReason.reason}),e.uninstallReason.description&&t("span",{children:e.uninstallReason.description})]})]}),n("div",{children:[t("dt",{children:a("supportChat.merchant.review")}),t("dd",{children:e.reviewed?t("span",{className:"mi-tag mi-tag--ok",children:a("supportChat.merchant.reviewed",{rating:e.reviewed.rating??"?"})}):e.development?t("span",{className:"mi-muted",children:a("supportChat.merchant.cannotReview")}):s&&h?n("form",{className:"mi-review-mark",onSubmit:r=>{r.preventDefault(),s.rating&&(i({...s,busy:!0,error:null}),h(s.rating,s.body.trim()).then(()=>i(null),u=>i(C=>C&&{...C,busy:!1,error:u.message})))},children:[t("span",{className:"mi-stars",role:"radiogroup","aria-label":a("supportChat.merchant.markReviewed"),children:[1,2,3,4,5].map(r=>t("button",{type:"button",role:"radio","aria-checked":s.rating===r,"aria-label":`${r}`,className:r<=s.rating?"on":"",onClick:()=>i({...s,rating:r}),children:"\u2605"},r))}),t("textarea",{rows:2,value:s.body,placeholder:a("supportChat.merchant.reviewText"),onChange:r=>i({...s,body:r.target.value})}),s.error&&t("span",{className:"mi-review-error",children:s.error}),n("span",{className:"mi-review-actions",children:[t("button",{type:"button",onClick:()=>i(null),children:a("supportChat.msg.cancelReply")}),t("button",{type:"submit",disabled:!s.rating||s.busy,children:a("supportChat.msg.save")})]})]}):n(z,{children:[t("span",{className:"mi-muted",children:a("supportChat.merchant.notReviewed")}),h&&t("button",{type:"button",className:"mi-review-add",onClick:()=>i({rating:0,body:"",busy:!1,error:null}),children:a("supportChat.merchant.markReviewed")})]})})]}),e.otherApps&&n("div",{children:[t("dt",{children:a("supportChat.merchant.otherApps")}),t("dd",{className:"mi-apps",children:e.otherApps.length?e.otherApps.map(r=>n("span",{className:`mi-app${r.enabled?"":" mi-muted"}`,children:[r.icon?t("img",{className:"mi-app-icon",src:`${r.icon}?width=48&height=48`,alt:"",width:18,height:18,loading:"lazy"}):t("span",{className:"mi-app-icon mi-app-icon--letter","aria-hidden":!0,children:r.name.charAt(0).toUpperCase()}),t("span",{className:"mi-app-name",children:r.name})]},r.name)):t("span",{className:"mi-muted",children:a("supportChat.merchant.otherAppsNone")})})]}),(e.email||m)&&n("div",{children:[t("dt",{children:a("supportChat.merchant.email")}),g!==null&&m?t("dd",{children:n("form",{className:"mi-email-edit",onSubmit:r=>{r.preventDefault();const u=g.trim().toLowerCase();/^[^\s@<>",;]{1,64}@[^\s@<>",;]{1,190}\.[a-z]{2,}$/i.test(u)&&(m(u),d(null))},children:[t("input",{autoFocus:!0,type:"email",value:g,onChange:r=>d(r.target.value),onKeyDown:r=>r.key==="Escape"&&d(null)}),t("button",{type:"submit",children:a("supportChat.msg.save")})]})}):n("dd",{className:"mi-mono",children:[t("span",{children:e.email}),e.email&&t(x,{text:e.email}),m&&t("button",{type:"button",className:"mi-email-pen","aria-label":a("supportChat.msg.edit"),title:a("supportChat.msg.edit"),onClick:()=>d(e.email??""),children:t(I,{size:13})})]})]})]}),n("div",{className:"mi-links",children:[!p&&l&&t("a",{href:`${l}?${new URLSearchParams({switchTo:e.shop})}`,target:"_blank",rel:"noopener noreferrer",children:a("supportChat.merchant.openSupport")}),e.links.storefront&&t("a",{href:e.links.storefront,target:"_blank",rel:"noopener noreferrer",children:a("supportChat.merchant.openStore")}),t("a",{href:e.links.admin,target:"_blank",rel:"noopener noreferrer",children:a("supportChat.merchant.openAdmin")}),t("a",{href:e.links.posthog,target:"_blank",rel:"noopener noreferrer",children:a("supportChat.merchant.openPosthog")})]}),e.readError&&t("p",{className:"mi-muted mi-note",children:a("supportChat.merchant.readError")})]})};export{V as MerchantPanel};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type Props = {
|
|
2
|
+
side: "merchant" | "agent" | "system";
|
|
3
|
+
inline?: boolean;
|
|
4
|
+
onReply: () => void;
|
|
5
|
+
onReact?: (emoji: string) => Promise<unknown>;
|
|
6
|
+
onEdit?: () => void;
|
|
7
|
+
onDelete?: () => Promise<unknown>;
|
|
8
|
+
copyText?: string;
|
|
9
|
+
reacted?: string[];
|
|
10
|
+
};
|
|
11
|
+
export declare const EditIcon: ({ size }: {
|
|
12
|
+
size?: number;
|
|
13
|
+
}) => import("react").JSX.Element;
|
|
14
|
+
export declare const MessageActions: ({ side, inline, onReply, onReact, onEdit, onDelete, copyText, reacted }: Props) => import("react").JSX.Element;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Fragment as B,jsx as i,jsxs as v}from"react/jsx-runtime";import{useEffect as $,useLayoutEffect as we,useRef as A,useState as M}from"react";import{createPortal as Ce}from"react-dom";import{useTranslation as ce}from"./i18n.js";const de=["\u{1F44D}","\u2764\uFE0F","\u{1F602}","\u{1F62E}","\u{1F64F}","\u{1F389}"],Ee=450,Le=10,ue=()=>typeof window<"u"&&window.matchMedia("(hover: none), (pointer: coarse)").matches,xe=()=>window.matchMedia("(prefers-reduced-motion: reduce)").matches,U=e=>e.classList.contains("sc-bubble-anchor")?Array.from(e.children).find(s=>!s.classList.contains("sc-macts"))??e:e,Me=(e,s)=>{const m=A(s);m.current=s,$(()=>{const l=e.current,o=l?.closest(".sc-note")??l?.parentElement;if(!o)return;o.classList.add("sc-lp");let c=0,a=0,u=null;const n=()=>{window.clearTimeout(a),U(o).classList.remove("sc-pressing")},p=()=>{window.clearTimeout(c),n(),u=null,window.removeEventListener("scroll",p,!0)},w=d=>{d.preventDefault(),d.stopPropagation()},L=d=>{d.pointerType!=="touch"||!ue()||d.target.closest("button, input, textarea, .sc-macts")||(p(),u={x:d.clientX,y:d.clientY},window.addEventListener("scroll",p,!0),a=window.setTimeout(()=>U(o).classList.add("sc-pressing"),120),c=window.setTimeout(()=>{window.clearTimeout(a),u=null,window.removeEventListener("scroll",p,!0),o.addEventListener("click",w,!0),window.setTimeout(()=>o.removeEventListener("click",w,!0),600);try{typeof navigator.vibrate=="function"&&navigator.vibrate(10)}catch{}m.current(U(o))},Ee))},f=d=>{u&&Math.hypot(d.clientX-u.x,d.clientY-u.y)>Le&&p()},C=d=>{ue()&&d.preventDefault()};return o.addEventListener("pointerdown",L),o.addEventListener("pointermove",f),o.addEventListener("pointerup",p),o.addEventListener("pointercancel",p),o.addEventListener("contextmenu",C),()=>{p(),o.classList.remove("sc-lp"),o.removeEventListener("pointerdown",L),o.removeEventListener("pointermove",f),o.removeEventListener("pointerup",p),o.removeEventListener("pointercancel",p),o.removeEventListener("contextmenu",C),o.removeEventListener("click",w,!0)}},[e])},me=({size:e=16})=>i("svg",{viewBox:"0 0 24 24",width:e,height:e,"aria-hidden":!0,children:i("path",{d:"M21.17 6.81a2.82 2.82 0 0 0-3.99-3.99L3.84 16.17a2 2 0 0 0-.5.83l-1.32 4.35a.5.5 0 0 0 .62.62l4.35-1.32a2 2 0 0 0 .83-.5zM15 5l4 4",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),k=({d:e,size:s=16})=>i("svg",{viewBox:"0 0 20 20",width:s,height:s,"aria-hidden":!0,children:i("path",{d:e,fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round"})}),pe="M8 5 3.5 9.5 8 14M4 9.5h7a5 5 0 0 1 5 5v1",ke="M7 7V4.5A1.5 1.5 0 0 1 8.5 3h7A1.5 1.5 0 0 1 17 4.5v7a1.5 1.5 0 0 1-1.5 1.5H13M4.5 7h7A1.5 1.5 0 0 1 13 8.5v7a1.5 1.5 0 0 1-1.5 1.5h-7A1.5 1.5 0 0 1 3 15.5v-7A1.5 1.5 0 0 1 4.5 7Z",Te="M4.5 10.5 8 14l7.5-8",G="M5 6h10M8 6V4.5h4V6m-6 0 .7 9.5h6.6L14 6",$e="M5.5 5.5l9 9M14.5 5.5l-9 9",ze=({side:e,inline:s=!1,onReply:m,onReact:l,onEdit:o,onDelete:c,copyText:a,reacted:u})=>{const{t:n}=ce("home"),[p,w]=M(!1),[L,f]=M(!1),[C,d]=M(!1),z=A(null),[V,K]=M(null),[Y,F]=M(!1);Me(z,r=>{F(!1),K(r)});const T=async r=>{d(!0);try{await r()}finally{d(!1)}},t=()=>K(null);return v(B,{children:[i("div",{ref:z,className:`sc-macts sc-macts--${e}${s?" sc-macts--inline":""}${p||L?" sc-macts--on":""}`,children:p&&l?i("div",{className:"sc-macts-emoji",role:"menu","aria-label":n("supportChat.msg.react"),children:de.map(r=>i("button",{type:"button",role:"menuitem",disabled:C,onClick:()=>{T(()=>l(r)).finally(()=>{w(!1)})},children:r},r))}):L&&c?v(B,{children:[i("span",{children:n("supportChat.msg.confirmDelete")}),i("button",{type:"button",className:"sc-macts-danger",disabled:C,onClick:()=>{T(c).then(()=>f(!1))},children:n("supportChat.msg.delete")}),i("button",{type:"button","aria-label":n("supportChat.msg.cancelReply"),onClick:()=>f(!1),children:"\xD7"})]}):v(B,{children:[l&&i("button",{type:"button",title:n("supportChat.msg.react"),"aria-label":n("supportChat.msg.react"),onClick:()=>w(!0),children:i(k,{d:"M10 17.5a7.5 7.5 0 1 0 0-15 7.5 7.5 0 0 0 0 15ZM7 12c.8 1 1.8 1.5 3 1.5s2.2-.5 3-1.5M7.5 8h.01M12.5 8h.01"})}),i("button",{type:"button",title:n("supportChat.msg.reply"),"aria-label":n("supportChat.msg.reply"),onClick:m,children:i(k,{d:pe})}),o&&i("button",{type:"button",title:n("supportChat.msg.edit"),"aria-label":n("supportChat.msg.edit"),onClick:o,children:i(me,{size:15})}),c&&i("button",{type:"button",title:n("supportChat.msg.delete"),"aria-label":n("supportChat.msg.delete"),onClick:()=>f(!0),children:i(k,{d:G})})]})}),V&&i(Pe,{lifted:V,asking:Y,busy:C,reacted:u??[],onClose:t,onReact:l?r=>{T(()=>l(r)).finally(t)}:void 0,onReply:()=>{t(),m()},onCopy:a&&navigator.clipboard?()=>navigator.clipboard.writeText(a):void 0,onEdit:o?()=>{t(),o()}:void 0,onDelete:c?()=>F(!0):void 0,onConfirmDelete:c?()=>{T(c).then(t)}:void 0,onKeep:()=>F(!1)})]})},R=8,Ae=1.03;let I=null;const Re=()=>{if(I)return I;const e=document.createElement("div");e.style.cssText="position:fixed;visibility:hidden;pointer-events:none;padding:env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left)",document.body.appendChild(e);const s=getComputedStyle(e);return I={top:parseFloat(s.paddingTop)||0,right:parseFloat(s.paddingRight)||0,bottom:parseFloat(s.paddingBottom)||0,left:parseFloat(s.paddingLeft)||0},e.remove(),I},He=(e,s)=>{let m=s.y,l=s.y+s.h;for(let o=e.parentElement;o&&o!==document.body;o=o.parentElement){const c=getComputedStyle(o).overflowY;if(c==="auto"||c==="scroll"||c==="hidden"){const a=o.getBoundingClientRect(),u=getComputedStyle(o);m=Math.max(m,a.top+(parseFloat(u.paddingTop)||0)),l=Math.min(l,a.bottom-(parseFloat(u.paddingBottom)||0));break}}return{x:s.x,y:m,w:s.w,h:Math.max(0,l-m)}},De=({x:e,y:s,w:m,h:l},[o,c,a,u])=>`M${e+o} ${s}H${e+m-c}A${c} ${c} 0 0 1 ${e+m} ${s+c}V${s+l-a}A${a} ${a} 0 0 1 ${e+m-a} ${s+l}H${e+u}A${u} ${u} 0 0 1 ${e} ${s+l-u}V${s+o}A${o} ${o} 0 0 1 ${e+o} ${s}Z`,Pe=e=>{const{t:s}=ce("home"),m=A(null),l=A(null),[o,c]=M(!1),[a,u]=M(!1),[n,p]=M(null),w=A({dy:0,s:1}),L=A(!1),f=t=>{L.current||(L.current=!0,e.onClose(),t&&e.lifted.isConnected&&(e.lifted.hasAttribute("tabindex")||e.lifted.setAttribute("tabindex","-1"),e.lifted.focus({preventScroll:!0})))},C=()=>{const t=e.lifted,r=m.current,h=l.current;if(!t.isConnected||!h)return;const b=window.visualViewport,H=Re(),E={x:0,y:b?.offsetTop??0,w:document.documentElement.clientWidth,h:b?.height??window.innerHeight},J=E.y+H.top+R,Q=E.y+E.h-H.bottom-R,fe=H.left+R,he=E.w-H.right-R,{dy:be,s:ee}=w.current,D=t.getBoundingClientRect(),P=D.width/ee,x=D.height/ee,W=D.left+D.width/2,Z=D.top+D.height/2-be,te=r?.offsetWidth??0,ne=r?r.offsetHeight+R:0,oe=h.offsetWidth,se=h.offsetHeight,N=He(t,E),ie=Math.max(N.y,J+ne),re=Math.min(N.y+N.h,Q-se-R),ye=W>E.w/2,O=g=>Math.min(Math.max(ye?W+P*y/2-g:W-P*y/2,fe),he-g);let y=xe()?1:Ae,S=t;for(let g=0;g<3&&!parseFloat(getComputedStyle(S).borderTopLeftRadius)&&S.firstElementChild;g++)S=S.firstElementChild;const _=getComputedStyle(parseFloat(getComputedStyle(S).borderTopLeftRadius)?S:t),ae=[_.borderTopLeftRadius,_.borderTopRightRadius,_.borderBottomRightRadius,_.borderBottomLeftRadius].map(g=>parseFloat(g)||0);if(x<=E.h*.6&&x*y<=re-ie){const g=Z-x*y/2,j=Math.min(Math.max(g,ie),re-x*y),q={x:W-P*y/2,y:j,w:P*y,h:x*y};p({tall:!1,dy:j-g,s:y,hole:q,radii:ae.map(ge=>Math.min(ge*y,q.w/2,q.h/2)),bar:r?{x:O(te),y:j-ne,below:!1}:null,menu:{x:O(oe),y:j+x*y+R,above:!1}});return}y=1;const le=Math.max(Z-x/2,N.y),ve=Math.min(Z+x/2,N.y+N.h),X={x:W-P/2,y:le,w:P,h:Math.max(0,ve-le)};p({tall:!0,dy:0,s:y,hole:X,radii:ae.map(g=>Math.min(g,X.w/2,X.h/2)),bar:r?{x:O(te),y:J,below:!1}:null,menu:{x:O(oe),y:Q-se,above:!0}})},d=A(C);d.current=C,we(()=>{d.current()},[e.asking,a]),$(()=>{let t=0;const r=()=>{cancelAnimationFrame(t),t=requestAnimationFrame(()=>d.current())};return window.addEventListener("resize",r),window.addEventListener("scroll",r,!0),window.visualViewport?.addEventListener("resize",r),()=>{cancelAnimationFrame(t),window.removeEventListener("resize",r),window.removeEventListener("scroll",r,!0),window.visualViewport?.removeEventListener("resize",r)}},[]),$(()=>{if(!n)return;const t=e.lifted;t.classList.add("sc-lifted"),t.classList.remove("sc-pressing"),t.style.translate=n.dy?`0 ${n.dy}px`:"",t.style.scale=n.s!==1?String(n.s):"",w.current={dy:n.dy,s:n.s}},[n,e.lifted]),$(()=>{const t=e.lifted;return()=>{t.style.translate="",t.style.scale="",window.setTimeout(()=>t.classList.remove("sc-lifted"),280)}},[e.lifted]),$(()=>{const t=window.setTimeout(()=>c(!0),350);return()=>window.clearTimeout(t)},[]),$(()=>{n&&l.current?.focus({preventScroll:!0})},[e.asking,!n]),$(()=>{const t=b=>{b.key==="Escape"&&(b.stopPropagation(),b.preventDefault(),f(!0))};document.addEventListener("keydown",t,!0);const r=window.CloseWatcher;let h=null;try{r&&(h=new r,h.onclose=()=>f(!0))}catch{h=null}return()=>{document.removeEventListener("keydown",t,!0),h?.destroy()}},[]);const z=t=>{const r=t.currentTarget.getAttribute("aria-orientation")==="horizontal",h={ArrowDown:1,ArrowUp:-1,ArrowRight:1,ArrowLeft:-1,Home:-99,End:99}[t.key];if(h===void 0||(r?t.key==="ArrowDown"||t.key==="ArrowUp":t.key==="ArrowLeft"||t.key==="ArrowRight"))return;const b=Array.from(t.currentTarget.querySelectorAll("[role^=menuitem]:not(:disabled)"));if(!b.length)return;t.preventDefault();const H=b.indexOf(document.activeElement),E=Math.abs(h)>1?h<0?0:b.length-1:(H+h+b.length)%b.length;b[E].focus()},V=()=>{e.onCopy&&e.onCopy().then(()=>{u(!0),window.setTimeout(()=>f(!1),700)},()=>f(!1))},K=typeof document<"u"?document.documentElement.clientWidth:0,Y=typeof window<"u"?window.innerHeight:0,F=n&&n.hole.h>0?`path(evenodd, "M0 0H${K}V${Y}H0Z${De(n.hole,n.radii)}")`:void 0,T=n?void 0:{visibility:"hidden",left:0,top:0};return Ce(v("div",{className:`sc-ctx${o?"":" sc-ctx--arming"}`,onMouseDown:t=>!t.target.closest("button")&&t.preventDefault(),children:[i("div",{className:"sc-ctx-scrim",style:{clipPath:F},onPointerDown:()=>o&&f(!0)}),n&&n.hole.h>0&&i("div",{className:"sc-ctx-lift",style:{left:n.hole.x,top:n.hole.y,width:n.hole.w,height:n.hole.h,borderRadius:n.radii.map(t=>`${t}px`).join(" "),boxShadow:n.tall?"none":void 0},onPointerDown:()=>o&&f(!0)}),e.onReact&&i("div",{ref:m,className:"sc-ctx-bar",role:"menu","aria-orientation":"horizontal","aria-label":s("supportChat.msg.react"),style:T??{left:n?.bar?.x,top:n?.bar?.y},onKeyDown:z,children:de.map(t=>{const r=e.reacted.includes(t);return i("button",{type:"button",role:"menuitemcheckbox","aria-checked":r,"aria-label":t,disabled:e.busy,onClick:()=>e.onReact?.(t),children:t},t)})}),i("div",{ref:l,className:`sc-ctx-menu${n?.menu.above?" sc-ctx-menu--above":""}`,role:"menu",tabIndex:-1,"aria-label":s("supportChat.msg.actions"),style:T??{left:n?.menu.x,top:n?.menu.y},onKeyDown:z,children:e.asking?v(B,{children:[i("p",{className:"sc-ctx-ask",id:"sc-ctx-ask",children:s("supportChat.msg.confirmDelete")}),v("button",{type:"button",role:"menuitem",className:"sc-ctx-item sc-ctx-danger","aria-describedby":"sc-ctx-ask",disabled:e.busy,onClick:e.onConfirmDelete,children:[i(k,{d:G,size:20}),s("supportChat.msg.delete")]}),v("button",{type:"button",role:"menuitem",className:"sc-ctx-item",onClick:e.onKeep,children:[i(k,{d:$e,size:20}),s("supportChat.msg.keep")]})]}):v(B,{children:[v("button",{type:"button",role:"menuitem",className:"sc-ctx-item",disabled:a,onClick:e.onReply,children:[i(k,{d:pe,size:20}),s("supportChat.msg.reply")]}),e.onCopy&&v("button",{type:"button",role:"menuitem",className:`sc-ctx-item${a?" sc-ctx-item--done":""}`,"aria-live":"polite",onClick:V,children:[i(k,{d:a?Te:ke,size:20}),s(a?"supportChat.msg.copied":"supportChat.msg.copy")]}),e.onEdit&&v("button",{type:"button",role:"menuitem",className:"sc-ctx-item",disabled:a,onClick:e.onEdit,children:[i(me,{size:20}),s("supportChat.msg.edit")]}),e.onDelete&&v(B,{children:[i("div",{className:"sc-ctx-sep",role:"separator"}),v("button",{type:"button",role:"menuitem",className:"sc-ctx-item sc-ctx-danger",disabled:a,onClick:e.onDelete,children:[i(k,{d:G,size:20}),s("supportChat.msg.delete")]})]})]})})]}),document.body)};export{me as EditIcon,ze as MessageActions};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ListingStats, SupportMessageView } from "@whoa-chat/core/types";
|
|
2
|
+
export type PreviewAction = {
|
|
3
|
+
kind: "open";
|
|
4
|
+
} | {
|
|
5
|
+
kind: "reply";
|
|
6
|
+
text: string;
|
|
7
|
+
open?: boolean;
|
|
8
|
+
} | {
|
|
9
|
+
kind: "review";
|
|
10
|
+
messageId: string;
|
|
11
|
+
} | {
|
|
12
|
+
kind: "go";
|
|
13
|
+
path: string;
|
|
14
|
+
};
|
|
15
|
+
export declare const MessagePreview: ({ message, listing, onAction, onDismiss, }: {
|
|
16
|
+
message: SupportMessageView;
|
|
17
|
+
listing?: ListingStats | null;
|
|
18
|
+
onAction: (action: PreviewAction) => void;
|
|
19
|
+
onDismiss: () => void;
|
|
20
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as r,jsxs as a}from"react/jsx-runtime";import{CustomCard as N}from"./CustomCard.js";import{useState as x}from"react";import{PASSWORD_PAGE as M}from"./PasswordCard.js";import{useTranslation as I}from"./i18n.js";import{AgentAvatar as S}from"./agents.js";import{VerifiedIcon as L}from"./HelpOfferCard.js";import{brandVars as b,chatHost as k}from"./host.js";import{ReferenceMini as w,referencesIn as A}from"./RichCards.js";import{FILE_IMG as B,FormattedText as P}from"./FormattedText.js";import{linkLabels as R}from"@whoa-chat/core/links";const $=({label:e,placeholder:p,onOpen:s,onSend:h})=>{const[t,u]=x("");return a("form",{className:"mp-reply",onSubmit:c=>{c.preventDefault();const d=t.trim();d?h(d):s()},children:[r("input",{value:t,onChange:c=>u(c.target.value),placeholder:p,"aria-label":p,maxLength:4e3}),r("button",{type:"submit","aria-label":e,className:t.trim()?"mp-reply-send--on":void 0,children:r("svg",{viewBox:"0 0 20 20",width:"15",height:"15","aria-hidden":!0,children:r("path",{d:"M10 15.5v-11M5 9l5-5 5 5",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},g=(e,p=180)=>e.includes("```")||e.length<=p?e:`${e.slice(0,p-3).trimEnd()}...`,O="M11.128 4.123c-.453-.95-1.803-.95-2.256 0l-1.39 2.912-3.199.421c-1.042.138-1.46 1.422-.697 2.146l2.34 2.222-.587 3.172c-.192 1.034.901 1.828 1.825 1.327l2.836-1.54 2.836 1.54c.924.501 2.017-.293 1.825-1.327l-.587-3.172 2.34-2.222c.762-.724.345-2.008-.697-2.146l-3.2-.421-1.389-2.912Z",D=(e,p)=>{const s=Math.round((Date.now()-Date.parse(e))/6e4);if(s<1)return p("supportChat.preview.justNow");if(s<60)return p("supportChat.preview.minutesAgo",{count:s});const h=Math.round(s/60);return h<24?p("supportChat.preview.hoursAgo",{count:h}):new Date(e).toLocaleDateString(void 0,{day:"numeric",month:"short"})},G=({message:e,listing:p,onAction:s,onDismiss:h})=>{const{t}=I("home"),u=e.agentName??"Stefan",c=e.files?.length??0,d=(i,f=!1)=>({kind:"reply",text:i,open:f}),m=R((e.body??"").replace(B," ")).replace(/[ \t]{2,}/g," ").trim();let n=m?g(m):"",l=null,o=[];switch(e.kind){case"review_request":{n=e.review?.fixed?t("supportChat.preview.fixed",{fixed:e.review.fixed}):t("supportChat.preview.howItWent"),l=a("div",{className:"mp-rich mp-rich--review",children:[r("img",{src:k().brand.logo,alt:"",width:34,height:34}),a("div",{children:[r("strong",{children:t("supportChat.review.appName",b())}),p?a("span",{className:"mp-stars",children:[[1,2,3,4,5].map(i=>r("svg",{viewBox:"0 0 20 20",width:"12",height:"12","aria-hidden":!0,children:r("path",{d:O,fill:"#ffb21e"})},i)),r("b",{children:p.rating.toFixed(1)}),r("span",{children:t("supportChat.review.reviewCount",{count:p.reviewCount})})]}):r("span",{className:"mp-stars",children:t("supportChat.review.onAppStore")})]})]}),o=[{label:t("supportChat.preview.writeReview"),action:{kind:"review",messageId:e.id},tone:"brand"}];break}case"password_request":l=a("div",{className:"mp-rich mp-rich--help",children:[r("span",{className:"mp-help-icon","aria-hidden":!0,children:r("svg",{viewBox:"0 0 20 20",width:"18",height:"18",children:r("path",{d:"M5.5 9V6.8a4.5 4.5 0 0 1 9 0V9M4.5 9h11v8h-11zM10 12v2",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round"})})}),r("span",{children:t("supportChat.password.where")})]}),o=[{label:t("supportChat.password.open"),action:{kind:"go",path:M},tone:"brand"},{label:t("supportChat.preview.reply"),action:d(""),tone:"plain"}];break;case"feature_request":n=t("supportChat.featureCard.preview",{title:e.feature?.title??e.body}),o=[{label:t("supportChat.preview.openChat"),action:{kind:"open"},tone:"brand"}];break;case"ticket":n=t("supportChat.ticketCard.opened",{title:e.ticket?.title??e.body}),o=[{label:t("supportChat.preview.openChat"),action:{kind:"open"},tone:"dark"}];break;case"help_offer":l=a("div",{className:"mp-rich mp-rich--help",children:[r("span",{className:"mp-help-icon","aria-hidden":!0,children:r(L,{size:18,check:"#1a73e8"})}),r("span",{children:t("supportChat.preview.helpPerks")})]}),o=[{label:t("supportChat.helpOffer.yes"),action:d(t("supportChat.helpOffer.yesMessage"),!0),tone:"brand"},{label:t("supportChat.helpOffer.no"),action:d(t("supportChat.helpOffer.noMessage")),tone:"plain"}];break;case"link":e.link&&(l=r("div",{className:"mp-mini mp-mini--link",children:a("span",{className:"mp-mini-text",children:[r("strong",{children:e.link.title}),r("span",{children:e.link.crumb.join(" \u203A ")})]})})),n=n&&n!==e.link?.title?n:"",e.link&&(o=[{label:t("supportChat.preview.takeMe"),action:{kind:"go",path:e.link.path},tone:"brand"}]),o.push({label:t("supportChat.preview.reply"),action:{kind:"open"},tone:"plain"});break;case"offer":n="",e.offerId&&(l=r(w,{refId:`offer-${e.offerId}`})),o=[...e.offerId?[{label:t("supportChat.preview.openOffer"),action:{kind:"go",path:`/app/offers/${e.offerId}`},tone:"dark"}]:[],{label:t("supportChat.preview.reply"),action:{kind:"open"},tone:"plain"}];break;case"subscription":n="",e.subscriptionId&&(l=r(w,{refId:e.subscriptionId})),o=[{label:t("supportChat.preview.openChat"),action:{kind:"open"},tone:"dark"}];break;case"custom":n="",e.card&&(l=r("div",{className:"mp-rich mp-rich--custom",children:r(N,{tree:e.card.tree,name:e.card.name})})),o=[{label:t("supportChat.preview.reply"),action:{kind:"open"},tone:"dark"}];break;case"pricing":if(n="",e.pricing){const i=k().priceBook(e.pricing.priceBookId).tiers.find(f=>f.key===e.pricing.tierKey);l=a("div",{className:"mp-mini mp-mini--pricing",children:[r("span",{className:"mp-mini-pic",children:r("img",{src:k().brand.logo,alt:""})}),a("span",{className:"mp-mini-text",children:[r("strong",{children:t("supportChat.mini.pricing",b())}),r("span",{children:t("supportChat.mini.revenue",{revenue:`$${Math.round(e.pricing.revenueUsd).toLocaleString("en-US")}`,price:i&&i.priceUsd?`$${i.priceUsd}/mo`:t("supportChat.mini.noCharge")})})]})]})}o=[{label:t("supportChat.preview.seePlan"),action:{kind:"go",path:"/app/plan"},tone:"dark"},{label:t("supportChat.preview.reply"),action:{kind:"open"},tone:"plain"}];break;default:{!n&&c&&(n=t("supportChat.preview.files",{count:c}));const i=e.refs?.[0]?.ref??(e.body?A(e.body)[0]:void 0);i&&(l=r(w,{refId:i})),o=[{label:t("supportChat.preview.reply"),action:{kind:"open"},tone:"dark"}]}}const v=t("supportChat.preview.reply"),y=o.some(i=>i.label===v),C=o.filter(i=>i.label!==v);return a("article",{className:`mp-card mp-card--${e.kind}`,"aria-label":t("supportChat.preview.label",{name:u}),children:[a("header",{className:"mp-head",children:[r(S,{name:u,size:26}),a("span",{className:"mp-who",children:[r("strong",{children:u}),a("span",{children:["\xB7 ",t("supportChat.preview.fromTeam",b())]})]}),r("time",{children:D(e.at,t)}),r("button",{type:"button",className:"mp-close","aria-label":t("supportChat.preview.dismiss"),onClick:h,children:r("svg",{viewBox:"0 0 20 20",width:"12",height:"12","aria-hidden":!0,children:r("path",{d:"M5 5l10 10M15 5L5 15",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})})]}),(n||c>0)&&a("button",{type:"button",className:"mp-bubble",onClick:()=>s({kind:"open"}),children:[n&&m&&n===g(m)?r(P,{text:n}):n,c>0&&m&&r("span",{className:"mp-files",children:t("supportChat.preview.files",{count:c})})]}),l,C.length>0&&r("div",{className:"mp-actions",children:C.map(i=>r("button",{type:"button",className:`mp-btn mp-btn--${i.tone}`,onClick:()=>s(i.action),children:i.label},i.label))}),y&&r($,{label:v,placeholder:t("supportChat.preview.writeReply"),onOpen:()=>s({kind:"open"}),onSend:i=>s(d(i,!0))})]})};export{G as MessagePreview};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SupportMessageView } from "@whoa-chat/core/types";
|
|
2
|
+
export declare const PASSWORD_PAGE = "shopify://admin/online_store/preferences";
|
|
3
|
+
export declare const PasswordCard: ({ message, onOpen }: {
|
|
4
|
+
message: SupportMessageView;
|
|
5
|
+
onOpen?: () => void;
|
|
6
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as e,jsxs as a}from"react/jsx-runtime";import{useTranslation as p}from"./i18n.js";import{AgentAvatar as i}from"./agents.js";import{useChatEnv as d}from"./chatEnv.js";import{brandVars as h}from"./host.js";const c="shopify://admin/online_store/preferences",w=({message:t,onOpen:n})=>{const{t:o}=p("home"),r=d(),s=t.agentName??"Stefan";return a("article",{className:"ho-card pw-card","aria-label":o("supportChat.password.label"),children:[a("header",{className:"ho-head",children:[e(i,{name:s,size:30}),a("div",{children:[e("strong",{children:s}),e("span",{children:o("supportChat.preview.fromTeam",h())})]})]}),e("p",{className:"ho-body",children:t.body}),a("div",{className:"ho-perk pw-where",children:[e("svg",{viewBox:"0 0 20 20",width:"16",height:"16","aria-hidden":!0,children:e("path",{d:"M5.5 9V6.8a4.5 4.5 0 0 1 9 0V9M4.5 9h11v8h-11zM10 12v2",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})}),o("supportChat.password.where")]}),e("div",{className:"ho-actions",children:e("button",{type:"button",className:"mp-btn mp-btn--brand","data-card-action":"open",disabled:!r?.open,onClick:()=>{n?.(),r?.open?.(c)},children:o("supportChat.password.open")})})]})};export{c as PASSWORD_PAGE,w as PasswordCard};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SupportMessageView } from "@whoa-chat/core/types";
|
|
2
|
+
export declare const FeatureRequestCard: ({ message, onAdd }: {
|
|
3
|
+
message: SupportMessageView;
|
|
4
|
+
onAdd?: () => Promise<boolean>;
|
|
5
|
+
}) => import("react").JSX.Element;
|
|
6
|
+
export declare const TicketCard: ({ message }: {
|
|
7
|
+
message: SupportMessageView;
|
|
8
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as e,jsxs as d}from"react/jsx-runtime";import{useState as c}from"react";import{useTranslation as s}from"./i18n.js";import{AgentAvatar as l}from"./agents.js";import{brandVars as u,chatHost as h}from"./host.js";const n=({message:t})=>{const{t:r}=s("home"),a=t.agentName??h().brand.team;return d("header",{className:"ho-head",children:[e(l,{name:a,size:30}),d("div",{children:[e("strong",{children:a}),e("span",{children:r("supportChat.preview.fromTeam",u())})]})]})},g=({message:t,onAdd:r})=>{const{t:a}=s("home"),[o,i]=c(t.feature?.addedAt?"added":"idle"),p=o==="added"||!!t.feature?.addedAt;return d("article",{className:"ho-card fr-card","aria-label":a("supportChat.featureCard.label"),children:[e(n,{message:t}),d("div",{className:"ho-perk fr-title",children:[e("svg",{viewBox:"0 0 20 20",width:"16",height:"16","aria-hidden":!0,children:e("path",{d:"M10 3.5v13M3.5 10h13",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round"})}),d("span",{children:[e("em",{children:a("supportChat.featureCard.label")}),e("strong",{children:t.feature?.title??t.body})]})]}),e("div",{className:"ho-actions",children:p?d("span",{className:"fr-added",role:"status",children:[e("svg",{viewBox:"0 0 20 20",width:"16",height:"16","aria-hidden":!0,children:e("path",{d:"m5 10.5 3.2 3.2L15 7",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),a("supportChat.featureCard.added")]}):e("button",{type:"button",className:"mp-btn mp-btn--brand","data-card-action":"feature_add",disabled:!r||o==="adding","aria-busy":o==="adding",onClick:async()=>{r&&(i("adding"),i(await r().catch(()=>!1)?"added":"failed"))},children:a("supportChat.featureCard.add")})}),o==="failed"&&e("p",{className:"fr-error",children:a("supportChat.featureCard.failed")})]})},k=({message:t})=>{const{t:r}=s("home"),a=t.ticket?.state==="fixed";return d("article",{className:"ho-card tk-card","aria-label":r("supportChat.ticketCard.label"),children:[e(n,{message:t}),e("p",{className:"ho-body",children:r("supportChat.ticketCard.opened",{title:t.ticket?.title??t.body})}),e("div",{className:`tk-state${a?" tk-state--fixed":""}`,children:r(a?"supportChat.ticketCard.fixed":"supportChat.ticketCard.open")})]})};export{g as FeatureRequestCard,k as TicketCard};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ListingStats, type ReviewState, type SupportMessageView } from "@whoa-chat/core/types";
|
|
2
|
+
/** Shopify's review dialog, else the listing in a new tab. Null while a dialog is already on its way. */
|
|
3
|
+
export declare const requestReview: () => Promise<string | null>;
|
|
4
|
+
/** requestReview, then times how long they stay in the dialog or on the listing tab (reported once, as a card detail). */
|
|
5
|
+
export declare const requestReviewTimed: (onAway?: (detail: string) => void) => Promise<string | null>;
|
|
6
|
+
type Props = {
|
|
7
|
+
message: SupportMessageView;
|
|
8
|
+
shopOwnerName?: string | null;
|
|
9
|
+
listing?: ListingStats | null;
|
|
10
|
+
preview?: boolean;
|
|
11
|
+
onState?: (state: ReviewState, outcome?: string) => void;
|
|
12
|
+
onAway?: (detail: string) => void;
|
|
13
|
+
};
|
|
14
|
+
export declare const ReviewCard: ({ message, shopOwnerName, listing, preview, onState, onAway }: Props) => import("react").JSX.Element;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as e,jsxs as i}from"react/jsx-runtime";import{useEffect as b,useRef as I,useState as d,useMemo as O}from"react";import{useTranslation as q}from"./i18n.js";import{copyToClipboard as E}from"./copyToClipboard.js";import{APP_STORE_REVIEW_URL as u}from"@whoa-chat/core/types";import{awayDetail as U,watchReviewAway as B}from"@whoa-chat/core/reviewAway";import{AgentAvatar as F}from"./agents.js";import{brandVars as V,chatHost as C}from"./host.js";const W=new Set(["already-open","open-in-progress"]),k="M11.128 4.123c-.453-.95-1.803-.95-2.256 0l-1.39 2.912-3.199.421c-1.042.138-1.46 1.422-.697 2.146l2.34 2.222-.587 3.172c-.192 1.034.901 1.828 1.825 1.327l2.836-1.54 2.836 1.54c.924.501 2.017-.293 1.825-1.327l-.587-3.172 2.34-2.222c.762-.724.345-2.008-.697-2.146l-3.2-.421-1.389-2.912Z",j=async()=>{let r="error";try{r=(await shopify.reviews.request()).code}catch{}return W.has(r)?null:r!=="success"&&r!=="cancelled"?(window.open(u,"_blank","noopener"),"app-store"):r},z=async r=>{const a=Date.now(),s=await j();return r&&(s==="success"||s==="app-store")&&B(s==="app-store"?"tab":"dialog",c=>r(U(c)),{startedAt:a,answerMs:Date.now()-a}),s},H=()=>e("svg",{viewBox:"0 0 24 24",width:"10",height:"10","aria-hidden":!0,children:e("path",{className:"srv-check-path",d:"M5 12.5l4.2 4.2L19 7",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round"})}),G=({rating:r})=>e("span",{className:"srv-stars","aria-hidden":!0,children:[1,2,3,4,5].map(a=>i("svg",{viewBox:"0 0 20 20",width:"15",height:"15",style:{animationDelay:`${.25+a*.07}s`},children:[e("defs",{children:e("clipPath",{id:`srv-star-${a}`,children:e("rect",{x:"0",y:"0",width:20*Math.max(0,Math.min(1,r-a+1)),height:"20"})})}),e("path",{d:k,fill:"#e3e3e3",transform:"translate(-0.5 -0.6) scale(1.1)"}),e("path",{d:k,fill:"#ffb21e",clipPath:`url(#srv-star-${a})`,transform:"translate(-0.5 -0.6) scale(1.1)"})]},a))}),y=["#7c5cff","#29b6f6","#f5a623","#22c55e","#ff5c8a","#ffd23f"],Z=()=>{const r=O(()=>Array.from({length:70},(a,s)=>({left:Math.random()*100,drift:(Math.random()-.5)*140,spin:(Math.random()-.5)*900,delay:Math.random()*.35,duration:1.6+Math.random()*1.1,colour:y[s%y.length],round:s%3===0})),[]);return e("div",{className:"srv-confetti","aria-hidden":!0,children:r.map((a,s)=>e("i",{className:a.round?"srv-confetti-dot":void 0,style:{left:`${a.left}%`,background:a.colour,animationDelay:`${a.delay}s`,animationDuration:`${a.duration}s`,"--drift":`${a.drift}px`,"--spin":`${a.spin}deg`}},s))})},ae=({message:r,shopOwnerName:a,listing:s,preview:c,onState:v,onAway:S})=>{const{t,i18n:L}=q("home"),o=r.review,l=r.agentName??"Stefan",[m,h]=d(o.state),[x,f]=d(!1),[M,R]=d(!1),[A,P]=d(!1),w=I(!1);b(()=>h(o.state),[o.state]),b(()=>{c||w.current||o.state!=="sent"||(w.current=!0,v?.("seen"))},[c,o.state,v]);const g=(n,p)=>{h(n),v?.(n,p)},_=async()=>{if(c)return;const n=await z(S);n!==null&&(n==="app-store"&&R(!0),P(!0),g("clicked",n))},D=async()=>{c||(await E(u),f(!0),window.setTimeout(()=>f(!1),2500))},N=a?.split(" ")[0],T=s?new Intl.NumberFormat(L.language,{minimumFractionDigits:1,maximumFractionDigits:1}).format(s.rating):null;return m==="clicked"?i("div",{className:"srv-card srv-card--thanks",role:"status",children:[A&&e(Z,{}),e("img",{className:"srv-thanks-logo",src:C().brand.logo,alt:"",width:52,height:52}),e("p",{className:"srv-thanks-title",children:N?t("supportChat.review.thanksNamed",{name:N}):t("supportChat.review.thanks")}),e("p",{className:"srv-thanks-copy",children:t("supportChat.review.thanksCopy",{agent:l})}),e("a",{className:"srv-link",href:u,target:"_blank",rel:"noopener noreferrer",children:t(M?"supportChat.review.openListing":"supportChat.review.openAgain")})]}):m==="issue"?e("div",{className:"srv-card srv-card--quiet",role:"status",children:e("p",{className:"srv-quiet",children:t("supportChat.review.issueAck",{agent:l})})}):m==="dismissed"?e("div",{className:"srv-card srv-card--quiet",children:i("p",{className:"srv-quiet",children:[t("supportChat.review.dismissedAck")," ",e("button",{type:"button",className:"srv-link",onClick:()=>g("seen"),children:t("supportChat.review.showAgain")})]})}):i("article",{className:`srv-card${c?" srv-card--preview":""}`,"aria-label":t("supportChat.review.label"),children:[i("div",{className:"srv-hero",children:[e("span",{className:"srv-blob srv-blob--a","aria-hidden":!0}),e("span",{className:"srv-blob srv-blob--b","aria-hidden":!0}),e("img",{className:"srv-logo",src:C().brand.logo,alt:"",width:56,height:56}),i("div",{className:"srv-app",children:[e("strong",{children:t("supportChat.review.appName",V())}),s?i("span",{className:"srv-rating",children:[e(G,{rating:s.rating}),e("b",{children:T}),e("span",{children:t("supportChat.review.reviewCount",{count:s.reviewCount})})]}):e("span",{className:"srv-rating",children:t("supportChat.review.onAppStore")})]})]}),i("div",{className:"srv-body",children:[o.fixed&&i("div",{className:"srv-fixed",children:[i("span",{className:"srv-agent-ring",children:[e(F,{name:l,size:36}),e("span",{className:"srv-check",children:e(H,{})})]}),i("div",{className:"srv-fixed-main",children:[e("span",{className:"srv-eyebrow",children:t("supportChat.review.fixedBy",{agent:l})}),e("p",{className:"srv-fixed-text",children:o.fixed})]})]}),o.beforeImageUrl&&o.afterImageUrl&&e("div",{className:"srv-ba",children:[[o.beforeImageUrl,t("supportChat.review.before")],[o.afterImageUrl,t("supportChat.review.after")]].map(([n,p],$)=>i("a",{className:`srv-shot${$?" srv-shot--after":""}`,href:n,target:"_blank",rel:"noopener noreferrer",children:[e("img",{src:n,alt:p,loading:"lazy"}),e("span",{children:p})]},p))}),e("h3",{className:"srv-title",children:o?.title||t("supportChat.review.title")}),e("p",{className:"srv-copy",children:o?.ask||t("supportChat.review.body")}),i("button",{type:"button",className:"srv-primary","data-card-action":"review_clicked",onClick:_,disabled:c,children:[e("span",{children:t("supportChat.review.cta")}),e("span",{className:"srv-primary-icon","aria-hidden":!0,children:e("svg",{viewBox:"0 0 20 20",width:"12",height:"12",children:e("path",{d:"M7 13l6-6M8 7h5v5",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),e("p",{className:"srv-time",children:s?t("supportChat.review.joinOthers",{count:s.reviewCount}):t("supportChat.review.time")})]}),i("footer",{className:"srv-owner",children:[e("span",{children:t("supportChat.review.ownerOnly")}),e("button",{type:"button",className:"srv-link",onClick:D,children:t(x?"supportChat.review.copied":"supportChat.review.copyLink")})]})]})};export{ae as ReviewCard,j as requestReview,z as requestReviewTimed};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { DeepLink, MessageRef, PricingSnapshot } from "@whoa-chat/core/types";
|
|
3
|
+
import { ChatEnvProvider } from "./chatEnv";
|
|
4
|
+
export { ChatEnvProvider };
|
|
5
|
+
/** An order, subscription, offer, product or customer, full in the thread or compact in a hover card. */
|
|
6
|
+
export declare const ReferenceCard: ({ refId, compact }: {
|
|
7
|
+
refId: string;
|
|
8
|
+
compact?: boolean;
|
|
9
|
+
}) => import("react").JSX.Element;
|
|
10
|
+
/** Kept for subscription cards already sent. */
|
|
11
|
+
export declare const SubscriptionCard: ({ id }: {
|
|
12
|
+
id: string;
|
|
13
|
+
}) => import("react").JSX.Element;
|
|
14
|
+
export declare const Mention: ({ refId, text, active, onActive }: {
|
|
15
|
+
refId: string;
|
|
16
|
+
text: string;
|
|
17
|
+
active?: boolean;
|
|
18
|
+
onActive?: (ref: string | null) => void;
|
|
19
|
+
}) => import("react").JSX.Element;
|
|
20
|
+
export declare const referencesIn: (text: string) => string[];
|
|
21
|
+
export declare const MessageWithReferences: ({ text, bubbleClass, head, links, image }: {
|
|
22
|
+
text: string;
|
|
23
|
+
bubbleClass: string;
|
|
24
|
+
head?: ReactNode;
|
|
25
|
+
links?: MessageRef[];
|
|
26
|
+
image?: (id: string, name: string, key: string) => ReactNode;
|
|
27
|
+
}) => import("react").JSX.Element;
|
|
28
|
+
export declare const PricingCard: ({ pricing }: {
|
|
29
|
+
pricing: PricingSnapshot;
|
|
30
|
+
}) => import("react").JSX.Element;
|
|
31
|
+
export declare const DeepLinkCard: ({ link }: {
|
|
32
|
+
link: DeepLink;
|
|
33
|
+
}) => import("react").JSX.Element;
|
|
34
|
+
/** One row for the closed chat's preview: an icon or picture, the name, and the one fact that matters. */
|
|
35
|
+
export declare const ReferenceMini: ({ refId }: {
|
|
36
|
+
refId: string;
|
|
37
|
+
}) => import("react").JSX.Element | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Fragment as k,jsx as t,jsxs as n}from"react/jsx-runtime";import{useContext as $,useEffect as Y,useLayoutEffect as G,useRef as A,useState as z}from"react";import{createPortal as J}from"react-dom";import{useTranslation as m}from"./i18n.js";import{FormattedText as Q}from"./FormattedText.js";import{brandVars as L,chatHost as O}from"./host.js";import{ChatEnvContext as P,ChatEnvProvider as ee}from"./chatEnv.js";const T=/(#[A-Za-z]{0,6}\d{3,20}[A-Za-z]{0,6}\b)/g,B=new Map,te=e=>(B.has(e)||B.set(e,fetch(e,{headers:{Accept:"application/json"}}).then(s=>s.ok?s.json():null).then(s=>s?.reference??null).catch(()=>(B.delete(e),null))),B.get(e)),D=e=>{const s=$(P),[a,o]=z({loading:!0,data:null});return Y(()=>{if(!s)return;let i=!0;return te(s.previewUrl(e)).then(l=>i&&o({loading:!1,data:l})),()=>{i=!1}},[s,e]),a},j=e=>`shopify://admin/orders/${e.id}`,U=e=>`/app/contracts/${e.id}`,F=e=>`shopify://admin/products/${e.id}${e.variant?`/variants/${e.variant.id}`:""}`,V=e=>e.type==="order"?j(e.order):e.type==="subscription"?U(e.subscription):e.type==="product"?F(e.product):e.type==="customer"?`shopify://admin/customers/${e.customer.id}`:`/app/offers/${e.offer.id}`,v=()=>{const{t:e,i18n:s}=m("home");return{money:(r,p)=>new Intl.NumberFormat(s.language,{style:"currency",currency:p}).format(r),usd:r=>new Intl.NumberFormat(s.language,{style:"currency",currency:"USD",maximumFractionDigits:0}).format(r),date:r=>new Date(r).toLocaleDateString(s.language,{day:"numeric",month:"short",year:"numeric"}),inDays:r=>{const p=Math.round((Date.parse(r)-Date.now())/864e5);return p===0?e("supportChat.sub.today"):p>0?e("supportChat.sub.inDays",{count:p}):e("supportChat.sub.daysAgo",{count:-p})},every:r=>r?e(`supportChat.sub.every.${r.unit}`,{count:r.count,defaultValue:`${r.count} ${r.unit}`}):""}},se=e=>(e??"?").split(/\s+/).filter(Boolean).slice(0,2).map(s=>s[0].toUpperCase()).join(""),N=({size:e=13})=>t("svg",{viewBox:"0 0 20 20",width:e,height:e,"aria-hidden":!0,children:t("path",{d:"M4 9a5 5 0 0 1 8.6-3.5L14 7M16 11a5 5 0 0 1-8.6 3.5L6 13M14 3.5V7h-3.5M6 16.5V13h3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round"})}),I=({size:e=13})=>t("svg",{viewBox:"0 0 20 20",width:e,height:e,"aria-hidden":!0,children:t("path",{d:"M5 7h10l-.8 9.2a1 1 0 0 1-1 .8H6.8a1 1 0 0 1-1-.8zM7.5 7V6a2.5 2.5 0 0 1 5 0v1",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round"})}),S=({size:e=13})=>n("svg",{viewBox:"0 0 20 20",width:e,height:e,"aria-hidden":!0,children:[t("path",{d:"M3.5 10.2V4.5a1 1 0 0 1 1-1h5.7l6.3 6.3a1 1 0 0 1 0 1.4l-5.3 5.3a1 1 0 0 1-1.4 0z",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinejoin:"round"}),t("circle",{cx:"7.2",cy:"7.2",r:"1.3",fill:"currentColor"})]}),R=({size:e=13})=>n("svg",{viewBox:"0 0 20 20",width:e,height:e,"aria-hidden":!0,children:[t("circle",{cx:"10",cy:"7",r:"3.2",fill:"none",stroke:"currentColor",strokeWidth:"1.7"}),t("path",{d:"M4 16.5c.8-3 3.2-4.6 6-4.6s5.2 1.6 6 4.6",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round"})]}),re=({size:e=13})=>t("svg",{viewBox:"0 0 20 20",width:e,height:e,"aria-hidden":!0,children:t("path",{d:"M8 3L6.5 17M13.5 3L12 17M3.5 7.5h13M3 12.5h13",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round"})}),W=()=>t("svg",{viewBox:"0 0 20 20",width:"14",height:"14","aria-hidden":!0,children:t("path",{d:"M7 4l6 6-6 6",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),ne={ACTIVE:"active",PAUSED:"paused",CANCELLED:"cancelled",FAILED:"failed",EXPIRED:"cancelled"},E=({tone:e,children:s,live:a})=>n("span",{className:`rc-status rc-status--${e}${a?" rc-status--live":""}`,children:[t("i",{"aria-hidden":!0}),s]}),_=({status:e})=>{const{t:s}=m("home"),a=ne[e]??"cancelled";return t(E,{tone:a,live:a==="active",children:s(`supportChat.sub.status.${a}`,{defaultValue:e.toLowerCase()})})},ae={PAID:"active",PARTIALLY_PAID:"paused",PENDING:"paused",AUTHORIZED:"paused",REFUNDED:"cancelled",PARTIALLY_REFUNDED:"paused",VOIDED:"cancelled",EXPIRED:"failed"},H=({order:e})=>{const{t:s}=m("home");return e.cancelled?t(E,{tone:"cancelled",children:s("supportChat.order.cancelled")}):t(E,{tone:ae[e.financial]??"cancelled",children:s(`supportChat.order.financial.${e.financial}`,{defaultValue:e.financial.toLowerCase()})})},Z=({lines:e,currency:s,more:a,limit:o})=>{const{t:i}=m("home"),l=v(),c=a+Math.max(0,e.length-o);return n("ul",{className:"rc-lines",children:[e.slice(0,o).map((r,p)=>n("li",{children:[t("span",{className:"rc-thumb",children:r.image?t("img",{src:r.image,alt:"",loading:"lazy"}):null}),n("span",{className:"rc-line-text",children:[t("strong",{children:r.title}),r.variant&&t("span",{children:r.variant})]}),n("span",{className:"rc-line-price",children:[r.quantity>1&&n("span",{children:[r.quantity," \xD7 "]}),l.money(r.price,s)]})]},p)),c>0&&t("li",{className:"rc-more",children:i("supportChat.sub.more",{count:c})})]})},w=({path:e,label:s})=>{const{t:a}=m("home"),o=$(P);return n("button",{type:"button",className:"rc-open","data-card-action":"open",disabled:!o?.open,onClick:()=>o?.open?.(e),children:[o?.open?s:a("supportChat.sub.opensForThem"),t(W,{})]})},oe=({compact:e})=>n("div",{className:`rc-card rc-sub${e?" rc-sub--compact":""}`,"aria-busy":"true",children:[t("div",{className:"rc-skel rc-skel--line"}),t("div",{className:"rc-skel rc-skel--block"}),t("div",{className:"rc-skel rc-skel--line rc-skel--short"})]}),ce=({sub:e,compact:s})=>{const{t:a}=m("home"),o=v();return n("article",{className:`rc-card rc-sub${s?" rc-sub--compact":""}`,"aria-label":a("supportChat.sub.label",{id:e.id}),children:[n("header",{className:"rc-sub-head",children:[t("span",{className:"rc-sub-icon","aria-hidden":!0,children:t(N,{size:17})}),n("div",{className:"rc-sub-title",children:[t("strong",{children:a("supportChat.sub.title",{id:e.id})}),t("span",{children:o.every(e.interval)})]}),t(_,{status:e.status})]}),e.customerName&&n("div",{className:"rc-sub-customer",children:[t("span",{className:"rc-initials","aria-hidden":!0,children:se(e.customerName)}),n("div",{children:[t("strong",{children:e.customerName}),e.createdAt&&t("span",{children:a("supportChat.sub.since",{date:o.date(e.createdAt)})})]})]}),t(Z,{lines:e.lines,currency:e.currency,more:e.moreLines,limit:s?2:4}),n("div",{className:"rc-next",children:[e.nextBillingDate&&e.status==="ACTIVE"?n("div",{children:[t("span",{className:"rc-next-label",children:a("supportChat.sub.nextOrder")}),t("strong",{children:o.date(e.nextBillingDate)}),t("span",{className:"rc-next-rel",children:o.inDays(e.nextBillingDate)})]}):t("div",{children:t("span",{className:"rc-next-label",children:a("supportChat.sub.noNextOrder")})}),n("div",{className:"rc-total",children:[t("span",{className:"rc-next-label",children:a("supportChat.sub.perOrder")}),t("strong",{children:o.money(e.total,e.currency)})]})]}),!s&&t(w,{path:U(e),label:a("supportChat.sub.open")})]})},ie=({order:e,compact:s})=>{const{t:a}=m("home"),o=v(),i=e.fulfillment==="FULFILLED";return n("article",{className:`rc-card rc-sub rc-order${s?" rc-sub--compact":""}`,"aria-label":a("supportChat.order.label",{name:e.name}),children:[n("header",{className:"rc-sub-head",children:[t("span",{className:"rc-sub-icon rc-sub-icon--order","aria-hidden":!0,children:t(I,{size:17})}),n("div",{className:"rc-sub-title",children:[t("strong",{children:a("supportChat.order.title",{name:e.name})}),t("span",{children:o.date(e.createdAt)})]}),t(H,{order:e})]}),n("div",{className:"rc-order-tags",children:[t("span",{className:`rc-tag${i?" rc-tag--done":""}`,children:a(`supportChat.order.fulfillment.${e.fulfillment}`,{defaultValue:e.fulfillment.toLowerCase().replace(/_/g," ")})}),e.fromSubscription&&n("span",{className:"rc-tag rc-tag--sub",children:[t(N,{size:11}),a("supportChat.order.subscriptionOrder")]}),e.customerName&&t("span",{className:"rc-tag rc-tag--plain",children:e.customerName})]}),t(Z,{lines:e.lines,currency:e.currency,more:e.moreItems,limit:s?2:4}),n("div",{className:"rc-next",children:[n("div",{children:[t("span",{className:"rc-next-label",children:a("supportChat.order.placed")}),t("strong",{children:o.inDays(e.createdAt)})]}),n("div",{className:"rc-total",children:[t("span",{className:"rc-next-label",children:a("supportChat.order.total")}),t("strong",{children:o.money(e.total,e.currency)})]})]}),!s&&t(w,{path:j(e),label:a("supportChat.order.open")})]})},M=({size:e=17})=>n("svg",{viewBox:"0 0 20 20",width:e,height:e,"aria-hidden":!0,children:[t("path",{d:"M10 2.4l1.8 1.3 2.2-.2.8 2.1 1.9 1.1-.5 2.2.5 2.2-1.9 1.1-.8 2.1-2.2-.2L10 17.6l-1.8-1.3-2.2.2-.8-2.1-1.9-1.1.5-2.2-.5-2.2 1.9-1.1.8-2.1 2.2.2z",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinejoin:"round"}),t("path",{d:"M7.6 12.4l4.8-4.8",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"}),t("circle",{cx:"7.9",cy:"7.9",r:"1",fill:"currentColor"}),t("circle",{cx:"12.1",cy:"12.1",r:"1",fill:"currentColor"})]}),q=e=>{const s=[...e.options,...e.tiers].map(o=>o.badge).filter(o=>!!o),a=s.map(o=>Number(/^(\d+(?:\.\d+)?)% off$/.exec(o)?.[1])).filter(o=>o>0);return a.length?`${Math.max(...a)}% off`:s[0]??null},le=({offer:e})=>{const{t:s}=m("home"),a=q(e),o=e.products.length+e.moreProducts;return n("article",{className:"rc-card rc-sub rc-offer rc-offer--simple","aria-label":e.name,children:[n("header",{className:"rc-offer-head",children:[t("span",{className:"rc-sub-icon rc-sub-icon--offer","aria-hidden":!0,children:t(M,{size:15})}),t("strong",{children:e.name}),n("span",{className:`rc-offer-status rc-offer-status--${e.status}`,children:[t("i",{"aria-hidden":!0}),s(`supportChat.offer.status.${e.status}`)]})]}),n("p",{className:"rc-offer-summary",children:[s(`supportChat.offer.type.${e.type}`)," \xB7 ",a?e.options.length+e.tiers.length>1?s("supportChat.offer.upTo",{off:a}):a:s("supportChat.offer.optionsCount",{count:e.options.length+e.tiers.length})]}),t("div",{className:"rc-offer-products",title:e.products.map(i=>i.title).join(", "),children:e.grouping==="all"?t("span",{className:"rc-tag rc-tag--plain",children:s("supportChat.offer.allProducts")}):o?n(k,{children:[t("span",{className:"rc-offer-thumbs",children:e.products.map((i,l)=>t("span",{className:"rc-thumb rc-thumb--sm",children:i.image?t("img",{src:i.image,alt:"",loading:"lazy"}):t("span",{className:"rc-thumb-letter",children:i.title.slice(0,1)})},l))}),t("span",{className:"rc-offer-names",children:s("supportChat.offer.products",{count:o})})]}):t("span",{className:"rc-tag rc-tag--plain",children:s("supportChat.offer.noProducts")})}),t(w,{path:`/app/offers/${e.id}`,label:s("supportChat.offer.open")})]})},pe=({product:e})=>{const{t:s}=m("home"),a=v(),o=e.variant?a.money(e.variant.price,e.currency):e.priceMin===e.priceMax?a.money(e.priceMin,e.currency):`${a.money(e.priceMin,e.currency)} to ${a.money(e.priceMax,e.currency)}`,i=e.sellingPlans.length>0||e.offers.length>0;return n("article",{className:"rc-card rc-sub rc-product","aria-label":e.title,children:[n("header",{className:"rc-sub-head",children:[t("span",{className:"rc-thumb",children:e.image?t("img",{src:e.image,alt:"",loading:"lazy"}):t("span",{className:"rc-thumb-letter",children:e.title.slice(0,1)})}),n("div",{className:"rc-sub-title",children:[t("strong",{children:e.title}),t("span",{children:e.variant?[e.variant.title,e.variant.sku&&`SKU ${e.variant.sku}`].filter(Boolean).join(" \xB7 ")||s("supportChat.product.variant"):s("supportChat.product.variants",{count:e.variantsCount})})]}),t(E,{tone:e.status==="active"?"active":e.status==="draft"?"paused":"cancelled",children:s(`supportChat.product.status.${e.status}`)})]}),n("div",{className:"rc-product-facts",children:[n("span",{children:[t("small",{children:s("supportChat.product.price")}),t("b",{children:o})]}),e.tracksInventory&&e.inventory!==null&&n("span",{children:[t("small",{children:s("supportChat.product.stock")}),t("b",{className:e.inventory<=0?"rc-product-out":void 0,children:e.inventory})]})]}),n("div",{className:`rc-product-subs${i?"":" rc-product-subs--none"}`,children:[t(N,{}),t("span",{children:i?[e.subscriptionOnly?s("supportChat.product.subscriptionOnly"):s("supportChat.product.onSubscription"),...e.sellingPlans.slice(0,2)].join(" \xB7 "):s("supportChat.product.noPlans")})]}),e.offers.length>0&&t("div",{className:"rc-product-offers",children:e.offers.map(l=>n("span",{className:"rc-tag rc-tag--plain",children:[t(M,{size:12})," ",l.name]},l.id))}),t(w,{path:F(e),label:s("supportChat.product.open")}),e.storeUrl&&t("a",{className:"rc-store-link",href:e.storeUrl,target:"_blank",rel:"noopener noreferrer",children:s("supportChat.product.viewInStore")})]})},ue=({customer:e})=>{const{t:s}=m("home"),a=v(),o=e.subscriptions.filter(l=>l.status==="active"),i=o.map(l=>l.next).filter(l=>!!l).sort()[0]??null;return n("article",{className:"rc-card rc-sub rc-customer","aria-label":e.name,children:[n("header",{className:"rc-offer-head",children:[t("span",{className:"rc-sub-icon rc-sub-icon--customer","aria-hidden":!0,children:t(R,{size:15})}),t("strong",{children:e.name})]}),e.email&&t("p",{className:"rc-offer-summary",children:e.email}),n("div",{className:"rc-product-facts",children:[n("span",{children:[t("small",{children:s("supportChat.customer.orders")}),t("b",{children:e.orders})]}),n("span",{children:[t("small",{children:s("supportChat.customer.spent")}),t("b",{children:a.money(e.spent,e.currency)})]}),e.since&&n("span",{children:[t("small",{children:s("supportChat.customer.since")}),t("b",{children:a.date(e.since)})]})]}),n("div",{className:`rc-product-subs${o.length?"":" rc-product-subs--none"}`,children:[t(N,{}),t("span",{children:o.length?[s("supportChat.customer.active",{count:o.length}),i?s("supportChat.mini.next",{date:a.date(i)}):null].filter(Boolean).join(" \xB7 "):e.subscriptions.length?s("supportChat.customer.noneActive",{count:e.subscriptions.length}):s("supportChat.customer.noSubs")})]}),e.subscriptions.length>0&&t("ul",{className:"rc-customer-subs",children:e.subscriptions.slice(0,3).map(l=>n("li",{children:[t("span",{className:`rc-dot rc-dot--${l.status}`,"aria-hidden":!0}),t("span",{children:l.product??`#${l.id}`}),t("em",{children:l.status})]},l.id))}),e.tags.length>0&&t("div",{className:"rc-product-offers",children:e.tags.map(l=>t("span",{className:"rc-tag rc-tag--plain",children:l},l))}),t(w,{path:`shopify://admin/customers/${e.id}`,label:s("supportChat.customer.open")})]})},K=({refId:e,compact:s})=>{const{t:a}=m("home"),{loading:o,data:i}=D(e);return o?t(oe,{compact:s}):i?i.type==="offer"?t(le,{offer:i.offer}):i.type==="product"?t(pe,{product:i.product}):i.type==="customer"?t(ue,{customer:i.customer}):i.type==="order"?t(ie,{order:i.order,compact:s}):t(ce,{sub:i.subscription,compact:s}):t("div",{className:`rc-card rc-sub rc-sub--missing${s?" rc-sub--compact":""}`,children:a("supportChat.ref.notFound",{ref:`#${e}`})})},we=({id:e})=>t(K,{refId:e}),de=({data:e})=>e?e.type==="order"?t(I,{}):e.type==="offer"?t(M,{size:13}):e.type==="product"?t(S,{}):e.type==="customer"?t(R,{}):t(N,{}):t(re,{}),X=({refId:e,text:s,active:a,onActive:o})=>{const i=$(P),{loading:l,data:c}=D(e),r=A(null),[p,g]=z(null),d=A(),f=()=>{window.clearTimeout(d.current),o?.(e);const h=r.current?.getBoundingClientRect();if(!h)return;const C=320,x=h.bottom+330>window.innerHeight&&h.top>340;g({left:Math.max(8,Math.min(h.left,window.innerWidth-C-8)),top:x?h.top-8:h.bottom+8,above:x})},u=()=>{d.current=window.setTimeout(()=>{g(null),o?.(null)},160)},b=p!==null;G(()=>{if(!b)return;const h=()=>r.current?.isConnected?f():g(null);return window.addEventListener("scroll",h,!0),()=>window.removeEventListener("scroll",h,!0)},[b]);const y=c?V(c):null;return l||!c?t(k,{children:s}):n(k,{children:[n("button",{ref:r,type:"button",className:`rc-mention${c?` rc-mention--${c.type}`:""}${a?" rc-mention--active":""}`,onMouseEnter:f,onMouseLeave:u,onFocus:f,onBlur:u,onClick:()=>i?.open&&y?i.open(y):p?g(null):f(),children:[t(de,{data:c}),s]}),p&&J(t("div",{className:`rc-pop${p.above?" rc-pop--above":""}`,style:{left:p.left,top:p.top},onMouseEnter:()=>window.clearTimeout(d.current),onMouseLeave:u,role:"tooltip",children:t(K,{refId:e,compact:!0})}),document.body)]})},me=({refId:e,active:s,onActive:a})=>{const{t:o}=m("home"),i=$(P),l=v(),{loading:c,data:r}=D(e),p=r?V(r):null,g=r?.type==="order"?r.order.lines:r?.type==="subscription"?r.subscription.lines:[];return!c&&!r?null:t("button",{type:"button",className:`rc-strip-item${s?" rc-strip-item--active":""}`,onMouseEnter:()=>a(e),onMouseLeave:()=>a(null),onFocus:()=>a(e),onBlur:()=>a(null),onClick:()=>i?.open&&p&&i.open(p),disabled:!r,children:c?t("span",{className:"rc-skel rc-skel--line",style:{width:"100%"}}):r?r.type==="customer"?n(k,{children:[n("span",{className:"rc-strip-top",children:[t("span",{className:"rc-strip-icon",children:t(R,{size:12})}),t("strong",{children:r.customer.name})]}),n("span",{className:"rc-strip-bottom",children:[t("span",{children:o("supportChat.customer.active",{count:r.customer.subscriptions.filter(d=>d.status==="active").length})}),t("b",{children:l.money(r.customer.spent,r.customer.currency)})]})]}):r.type==="offer"||r.type==="product"?n(k,{children:[n("span",{className:"rc-strip-top",children:[t("span",{className:"rc-strip-icon",children:r.type==="offer"?t(M,{size:12}):t(S,{size:12})}),t("strong",{children:r.type==="offer"?r.offer.name:r.product.title})]}),t("span",{className:"rc-strip-thumbs",children:(r.type==="offer"?r.offer.products.map(d=>d.image):[r.product.image]).slice(0,3).map((d,f)=>t("span",{className:"rc-thumb rc-thumb--sm",children:d?t("img",{src:d,alt:"",loading:"lazy"}):null},f))}),n("span",{className:"rc-strip-bottom",children:[t("span",{children:r.type==="offer"?o(`supportChat.offer.status.${r.offer.status}`):o(`supportChat.product.status.${r.product.status}`)}),r.type==="product"&&t("b",{children:l.money(r.product.variant?.price??r.product.priceMin,r.product.currency)})]})]}):n(k,{children:[n("span",{className:"rc-strip-top",children:[t("span",{className:`rc-strip-icon${r.type==="order"?" rc-strip-icon--order":""}`,children:r.type==="order"?t(I,{size:12}):t(N,{size:12})}),t("strong",{children:r.type==="order"?r.order.name:`#${r.subscription.id}`}),r.type==="order"?t(H,{order:r.order}):t(_,{status:r.subscription.status})]}),t("span",{className:"rc-strip-thumbs",children:g.slice(0,3).map((d,f)=>t("span",{className:"rc-thumb rc-thumb--sm",children:d.image?t("img",{src:d.image,alt:"",loading:"lazy"}):null},f))}),n("span",{className:"rc-strip-bottom",children:[t("span",{children:r.type==="order"?l.date(r.order.createdAt):l.every(r.subscription.interval)}),t("b",{children:r.type==="order"?l.money(r.order.total,r.order.currency):l.money(r.subscription.total,r.subscription.currency)})]})]}):t("span",{className:"rc-strip-missing",children:o("supportChat.ref.notFound",{ref:`#${e}`})})})},he=e=>[...new Set((e.match(T)??[]).map(s=>s.slice(1)))],ge=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),ke=({text:e,bubbleClass:s,head:a,links:o=[],image:i})=>{const{t:l}=m("home"),c=o.filter(u=>u.text&&e.includes(u.text)).sort((u,b)=>b.text.length-u.text.length),r=new Map(c.map(u=>[u.text,u.ref])),p=c.length?new RegExp(`(${c.map(u=>ge(u.text)).join("|")})`,"g"):null,g=[...new Set([...c.map(u=>u.ref),...he(e)])],[d,f]=z(null);return n("div",{className:"rc-msg",children:[n("div",{className:s,children:[a,t(Q,{text:e,image:i,inline:(u,b)=>(p?u.split(p):[u]).map((y,h)=>p&&h%2===1?t(X,{refId:r.get(y),text:y,active:d===r.get(y),onActive:f},`${b}-n${h}`):y.split(T).map((C,x)=>x%2===0?C:t(X,{refId:C.slice(1),text:C,active:d===C.slice(1),onActive:f},`${b}-${h}-${x}`)))})]}),g.length>1&&n("div",{className:"rc-strip",children:[t("span",{className:"rc-strip-label",children:l("supportChat.ref.mentioned",{count:g.length})}),t("div",{className:"rc-strip-row",children:g.map(u=>t(me,{refId:u,active:d===u,onActive:f},u))})]})]})},xe=({pricing:e})=>{const{t:s}=m("home"),a=v(),o=O().priceBook(e.priceBookId).tiers,i=o.findIndex(r=>r.key===e.tierKey),l=o[o.length-2].upToUsd??1,c=Math.min(98,Math.max(2,Math.log10(Math.max(e.revenueUsd,10))/Math.log10(l*1.5)*100));return n("article",{className:"rc-card rc-pricing","aria-label":s("supportChat.pricing.title",L()),children:[n("header",{className:"rc-pricing-head",children:[t("img",{src:O().brand.logo,alt:"",width:36,height:36}),n("div",{children:[t("strong",{children:s("supportChat.pricing.title",L())}),t("span",{children:s("supportChat.pricing.everyFeature")})]})]}),n("div",{className:"rc-pricing-you",children:[t("span",{className:"rc-next-label",children:s("supportChat.pricing.yourRevenue",L())}),t("strong",{children:a.usd(e.revenueUsd)}),n("div",{className:"rc-meter","aria-hidden":!0,children:[t("span",{className:"rc-meter-fill",style:{width:`${c}%`}}),t("span",{className:"rc-meter-dot",style:{left:`${c}%`}})]}),t("span",{className:"rc-pricing-asof",children:s("supportChat.pricing.asOf",{date:a.date(e.at)})})]}),t("ul",{className:"rc-tiers",children:o.map((r,p)=>n("li",{className:p===i?"rc-tier rc-tier--you":p===i+1?"rc-tier rc-tier--next":"rc-tier",children:[t("span",{className:"rc-tier-name",children:r.upToUsd===null?s("supportChat.pricing.above",{amount:a.usd(o[p-1]?.upToUsd??0)}):s("supportChat.pricing.upTo",{amount:a.usd(r.upToUsd)})}),p===i&&t("span",{className:"rc-tier-badge",children:s("supportChat.pricing.yourPlan")}),p===i+1&&t("span",{className:"rc-tier-badge rc-tier-badge--next",children:s("supportChat.pricing.next")}),t("span",{className:"rc-tier-price",children:r.priceUsd===0?s("supportChat.pricing.noCharge"):s("supportChat.pricing.perMonth",{price:a.usd(r.priceUsd)})})]},r.key))}),t("p",{className:"rc-pricing-note",children:s("supportChat.pricing.whatCounts",L())}),t(w,{path:"/app/plan",label:s("supportChat.pricing.open")})]})},$e=({link:e})=>{const{t:s}=m("home"),a=$(P);return n("article",{className:"rc-card rc-link","aria-label":e.title,children:[n("div",{className:"rc-window","aria-hidden":!0,children:[n("div",{className:"rc-window-bar",children:[t("i",{}),t("i",{}),t("i",{}),t("span",{children:[...e.crumb,e.title].join(" \u203A ")})]}),n("div",{className:"rc-window-body",children:[n("div",{className:"rc-window-nav",children:[t("b",{}),t("b",{}),t("b",{className:"rc-on"}),t("b",{})]}),n("div",{className:"rc-window-main",children:[t("b",{className:"rc-w60"}),t("b",{className:"rc-w90"}),e.setting?n("div",{className:"rc-target",children:[t("span",{children:e.title}),t("em",{})]}):t("b",{className:"rc-w75"}),t("b",{className:"rc-w40"})]})]}),e.setting&&t("svg",{className:"rc-cursor",viewBox:"0 0 24 24",width:"22",height:"22",children:t("path",{d:"M5 3l14 8-6 1.6L10.5 19z",fill:"#0d0d0d",stroke:"#fff",strokeWidth:"1.5",strokeLinejoin:"round"})})]}),n("div",{className:"rc-link-body",children:[t("span",{className:"rc-crumb",children:e.crumb.length?e.crumb.join(" \u203A "):s("supportChat.link.inApp")}),t("strong",{children:e.title}),t("p",{children:e.about}),n("button",{type:"button",className:"rc-open rc-open--brand","data-card-action":"open",disabled:!a?.open,onClick:()=>a?.open?.(e.path),children:[a?.open?s(e.setting?"supportChat.link.openSetting":"supportChat.link.openPage",{title:e.title}):s("supportChat.sub.opensForThem"),t(W,{})]}),e.setting&&t("span",{className:"rc-hint",children:s("supportChat.link.highlightHint")})]})]})},Pe=({refId:e})=>{const{t:s}=m("home"),a=v(),{loading:o,data:i}=D(e);if(o)return t("div",{className:"mp-mini",children:t("span",{className:"rc-skel rc-skel--line",style:{width:"70%"}})});if(!i)return null;const l=(c,r,p,g,d)=>n("div",{className:`mp-mini mp-mini--${c}`,children:[t("span",{className:"mp-mini-pic",children:p?t("img",{src:p,alt:"",loading:"lazy"}):r}),n("span",{className:"mp-mini-text",children:[t("strong",{children:g}),t("span",{children:d})]})]});switch(i.type){case"order":{const c=i.order;return l("order",t(I,{size:15}),c.lines[0]?.image??null,s("supportChat.mini.order",{name:c.name}),[c.cancelled?s("supportChat.mini.cancelled"):c.financial.toLowerCase().replace(/_/g," "),a.money(c.total,c.currency)].join(" \xB7 "))}case"subscription":{const c=i.subscription;return l("subscription",t(N,{size:15}),c.lines[0]?.image??null,s("supportChat.mini.subscription",{id:c.id}),[c.status.toLowerCase(),c.nextBillingDate?s("supportChat.mini.next",{date:a.date(c.nextBillingDate)}):null].filter(Boolean).join(" \xB7 "))}case"offer":{const c=i.offer,r=q(c);return l("offer",t(M,{size:15}),null,c.name,[s(`supportChat.offer.type.${c.type}`),r].filter(Boolean).join(" \xB7 "))}case"customer":{const c=i.customer,r=c.subscriptions.filter(p=>p.status==="active").length;return l("customer",t(R,{size:15}),null,c.name,[s("supportChat.customer.active",{count:r}),s("supportChat.customer.ordersCount",{count:c.orders})].join(" \xB7 "))}case"product":{const c=i.product;return l("product",t(S,{size:15}),c.image,c.variant?.title?`${c.title}, ${c.variant.title}`:c.title,[a.money(c.variant?.price??c.priceMin,c.currency),c.sellingPlans.length||c.offers.length?s("supportChat.product.onSubscription"):null].filter(Boolean).join(" \xB7 "))}}};export{ee as ChatEnvProvider,$e as DeepLinkCard,X as Mention,ke as MessageWithReferences,xe as PricingCard,K as ReferenceCard,Pe as ReferenceMini,we as SubscriptionCard,he as referencesIn};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Node, type JSONContent } from "@tiptap/core";
|
|
2
|
+
import type { Node as PmNode } from "@tiptap/pm/model";
|
|
3
|
+
import type { MessageRef } from "@whoa-chat/core/types";
|
|
4
|
+
export type RichHandle = {
|
|
5
|
+
focus: () => void;
|
|
6
|
+
setText: (text: string, refs?: MessageRef[]) => void;
|
|
7
|
+
insertText: (text: string) => void;
|
|
8
|
+
/** Replaces the `count` characters before the caret with text, or with a chip and a space. */
|
|
9
|
+
replaceBefore: (count: number, text: string, chip?: MessageRef) => void;
|
|
10
|
+
clear: () => void;
|
|
11
|
+
/** Places an image at the cursor while it uploads (key), then gives it its file id, or takes it out. */
|
|
12
|
+
insertImage: (key: string, name: string, src: string) => void;
|
|
13
|
+
/** A link at the cursor as a chip; with no label given, the selected words become its label. */
|
|
14
|
+
/** before: how many characters before the caret it replaces (a typed "[query"). */
|
|
15
|
+
insertLink: (url: string, label?: string, before?: number) => void;
|
|
16
|
+
setImageId: (key: string, id: string) => void;
|
|
17
|
+
removeImage: (key: string) => void;
|
|
18
|
+
};
|
|
19
|
+
export type RichState = {
|
|
20
|
+
text: string;
|
|
21
|
+
refs: MessageRef[];
|
|
22
|
+
before: string;
|
|
23
|
+
};
|
|
24
|
+
/** The document as the plain text the chat stores (exported for the round-trip tests). */
|
|
25
|
+
export declare const toText: (doc: PmNode) => string;
|
|
26
|
+
export declare const asContent: (text: string, refs?: MessageRef[]) => JSONContent[];
|
|
27
|
+
export declare const hasChips: (text: string, refs?: MessageRef[]) => boolean;
|
|
28
|
+
/** Stored text as the editor's blocks: the reverse of toText. */
|
|
29
|
+
export declare const toBlocks: (text: string, refs?: MessageRef[]) => JSONContent[];
|
|
30
|
+
/** The editor's building blocks (also how the tests build its schema without a browser). */
|
|
31
|
+
export declare const richExtensions: () => (Node<import("@tiptap/extension-code-block").CodeBlockOptions, any> | Node<any, any> | import("@tiptap/core").Extension<import("@tiptap/starter-kit").StarterKitOptions, any>)[];
|
|
32
|
+
type Props = {
|
|
33
|
+
placeholder: string;
|
|
34
|
+
onChange: (state: RichState) => void;
|
|
35
|
+
onKey: (e: KeyboardEvent) => boolean;
|
|
36
|
+
onPasteFiles?: (files: FileList) => void;
|
|
37
|
+
/** Teammates to tint when named (a note); empty for a reply. */
|
|
38
|
+
mentions?: string[];
|
|
39
|
+
};
|
|
40
|
+
export declare const RichInput: import("react").ForwardRefExoticComponent<Props & import("react").RefAttributes<RichHandle>>;
|
|
41
|
+
export {};
|